xref: /minix/minix/lib/libsys/pci_dev_name.c (revision 83133719)
1 /*
2 pci_dev_name.c
3 */
4 
5 #include "pci.h"
6 #include "syslib.h"
7 #include <minix/sysutil.h>
8 
9 /*===========================================================================*
10  *				pci_dev_name				     *
11  *===========================================================================*/
12 char *pci_dev_name(u16_t vid, u16_t did)
13 {
14 	static char name[80];	/* We need a better interface for this */
15 
16 	int r;
17 	cp_grant_id_t gid;
18 	message m;
19 
20 	gid= cpf_grant_direct(pci_procnr, (vir_bytes)name, sizeof(name),
21 		CPF_WRITE);
22 	if (gid == -1)
23 	{
24 		printf("pci_dev_name: cpf_grant_direct failed: %d\n",
25 			errno);
26 		return NULL;
27 	}
28 
29 	m.m_type= BUSC_PCI_DEV_NAME_S;
30 	m.m7_i1= vid;
31 	m.m7_i2= did;
32 	m.m7_i3= sizeof(name);
33 	m.m7_i4= gid;
34 
35 	r= ipc_sendrec(pci_procnr, &m);
36 	cpf_revoke(gid);
37 	if (r != 0)
38 		panic("pci_dev_name: can't talk to PCI: %d", r);
39 
40 	if (m.m_type == ENOENT)
41 	{
42 #if DEBUG
43 		printf("pci_dev_name: got no name\n");
44 #endif
45 		return NULL;	/* No name for this device */
46 	}
47 	if (m.m_type != 0)
48 		panic("pci_dev_name: got bad reply from PCI: %d", m.m_type);
49 
50 	name[sizeof(name)-1]= '\0';	/* Make sure that the string is NUL
51 					 * terminated.
52 					 */
53 
54 #if DEBUG
55 	printf("pci_dev_name: got name %s\n", name);
56 #endif
57 	return name;
58 }
59 
60