xref: /minix3/minix/lib/libsys/pci_dev_name.c (revision 6afe26749abc49c059b9b20284d55aaa3e3ef981)
1433d6423SLionel Sambuc /*
2433d6423SLionel Sambuc pci_dev_name.c
3433d6423SLionel Sambuc */
4433d6423SLionel Sambuc 
5433d6423SLionel Sambuc #include "pci.h"
6433d6423SLionel Sambuc #include "syslib.h"
7433d6423SLionel Sambuc #include <minix/sysutil.h>
8433d6423SLionel Sambuc 
9433d6423SLionel Sambuc /*===========================================================================*
10433d6423SLionel Sambuc  *				pci_dev_name				     *
11433d6423SLionel Sambuc  *===========================================================================*/
pci_dev_name(u16_t vid,u16_t did)12433d6423SLionel Sambuc char *pci_dev_name(u16_t vid, u16_t did)
13433d6423SLionel Sambuc {
14433d6423SLionel Sambuc 	static char name[80];	/* We need a better interface for this */
15433d6423SLionel Sambuc 
16433d6423SLionel Sambuc 	int r;
17433d6423SLionel Sambuc 	cp_grant_id_t gid;
18433d6423SLionel Sambuc 	message m;
19433d6423SLionel Sambuc 
20433d6423SLionel Sambuc 	gid= cpf_grant_direct(pci_procnr, (vir_bytes)name, sizeof(name),
21433d6423SLionel Sambuc 		CPF_WRITE);
22433d6423SLionel Sambuc 	if (gid == -1)
23433d6423SLionel Sambuc 	{
24433d6423SLionel Sambuc 		printf("pci_dev_name: cpf_grant_direct failed: %d\n",
25433d6423SLionel Sambuc 			errno);
26433d6423SLionel Sambuc 		return NULL;
27433d6423SLionel Sambuc 	}
28433d6423SLionel Sambuc 
29433d6423SLionel Sambuc 	m.m_type= BUSC_PCI_DEV_NAME_S;
30433d6423SLionel Sambuc 	m.m7_i1= vid;
31433d6423SLionel Sambuc 	m.m7_i2= did;
32433d6423SLionel Sambuc 	m.m7_i3= sizeof(name);
33433d6423SLionel Sambuc 	m.m7_i4= gid;
34433d6423SLionel Sambuc 
35433d6423SLionel Sambuc 	r= ipc_sendrec(pci_procnr, &m);
36433d6423SLionel Sambuc 	cpf_revoke(gid);
37433d6423SLionel Sambuc 	if (r != 0)
38433d6423SLionel Sambuc 		panic("pci_dev_name: can't talk to PCI: %d", r);
39433d6423SLionel Sambuc 
40433d6423SLionel Sambuc 	if (m.m_type == ENOENT)
41433d6423SLionel Sambuc 	{
42*6afe2674SJean-Baptiste Boric #ifdef DEBUG
43433d6423SLionel Sambuc 		printf("pci_dev_name: got no name\n");
44433d6423SLionel Sambuc #endif
45433d6423SLionel Sambuc 		return NULL;	/* No name for this device */
46433d6423SLionel Sambuc 	}
47433d6423SLionel Sambuc 	if (m.m_type != 0)
48433d6423SLionel Sambuc 		panic("pci_dev_name: got bad reply from PCI: %d", m.m_type);
49433d6423SLionel Sambuc 
50433d6423SLionel Sambuc 	name[sizeof(name)-1]= '\0';	/* Make sure that the string is NUL
51433d6423SLionel Sambuc 					 * terminated.
52433d6423SLionel Sambuc 					 */
53433d6423SLionel Sambuc 
54*6afe2674SJean-Baptiste Boric #ifdef DEBUG
55433d6423SLionel Sambuc 	printf("pci_dev_name: got name %s\n", name);
56433d6423SLionel Sambuc #endif
57433d6423SLionel Sambuc 	return name;
58433d6423SLionel Sambuc }
59433d6423SLionel Sambuc 
60