From: Philip Homburg Date: Fri, 2 Dec 2005 14:41:46 +0000 (+0000) Subject: Stubs for accessing the PCI driver X-Git-Tag: v3.1.2a~484 X-Git-Url: http://zhaoyanbai.com/repos/rndc.html?a=commitdiff_plain;h=3dd0a97049b426fc9872568a48dff9297a5bcd6d;p=minix.git Stubs for accessing the PCI driver --- diff --git a/lib/syslib/Makefile b/lib/syslib/Makefile index c48edafae..5c9fd86d3 100755 --- a/lib/syslib/Makefile +++ b/lib/syslib/Makefile @@ -41,5 +41,16 @@ libsys_OBJECTS = \ taskcall.o \ sys_vm_setbuf.o \ sys_vm_map.o \ + pci_attr_r8.o \ + pci_attr_r32.o \ + pci_attr_w32.o \ + pci_dev_name.o \ + pci_find_dev.o \ + pci_first_dev.o \ + pci_ids.o \ + pci_init.o \ + pci_next_dev.o \ + pci_reserve.o \ + pci_slot_name.o \ include ../Makefile.inc diff --git a/lib/syslib/pci_attr_r32.c b/lib/syslib/pci_attr_r32.c new file mode 100644 index 000000000..b9b53a679 --- /dev/null +++ b/lib/syslib/pci_attr_r32.c @@ -0,0 +1,31 @@ +/* +pci_attr_r32.c +*/ + +#include "syslib.h" +#include + +/*===========================================================================* + * pci_attr_r32 * + *===========================================================================*/ +PUBLIC u32_t pci_attr_r32(devind, port) +int devind; +int port; +{ + int r; + message m; + + m.m_type= BUSC_PCI_ATTR_R32; + m.m2_i1= devind; + m.m2_i2= port; + + r= sendrec(PCI_PROC_NR, &m); + if (r != 0) + panic("pci", "pci_attr_r32: can't talk to PCI", r); + + if (m.m_type != 0) + panic("pci", "pci_attr_r32: got bad reply from PCI", m.m_type); + + return m.m2_l1; +} + diff --git a/lib/syslib/pci_attr_r8.c b/lib/syslib/pci_attr_r8.c new file mode 100644 index 000000000..616390ab4 --- /dev/null +++ b/lib/syslib/pci_attr_r8.c @@ -0,0 +1,31 @@ +/* +pci_attr_r8.c +*/ + +#include "syslib.h" +#include + +/*===========================================================================* + * pci_attr_r8 * + *===========================================================================*/ +PUBLIC u8_t pci_attr_r8(devind, port) +int devind; +int port; +{ + int r; + message m; + + m.m_type= BUSC_PCI_ATTR_R8; + m.m2_i1= devind; + m.m2_i2= port; + + r= sendrec(PCI_PROC_NR, &m); + if (r != 0) + panic("pci", "pci_attr_r8: can't talk to PCI", r); + + if (m.m_type != 0) + panic("pci", "pci_attr_r8: got bad reply from PCI", m.m_type); + + return m.m2_l1; +} + diff --git a/lib/syslib/pci_attr_w32.c b/lib/syslib/pci_attr_w32.c new file mode 100644 index 000000000..bf1110ad2 --- /dev/null +++ b/lib/syslib/pci_attr_w32.c @@ -0,0 +1,31 @@ +/* +pci_attr_w32.c +*/ + +#include "syslib.h" +#include + +/*===========================================================================* + * pci_attr_w32 * + *===========================================================================*/ +PUBLIC void pci_attr_w32(devind, port, value) +int devind; +int port; +u32_t value; +{ + int r; + message m; + + m.m_type= BUSC_PCI_ATTR_W32; + m.m2_i1= devind; + m.m2_i2= port; + m.m2_l1= value; + + r= sendrec(PCI_PROC_NR, &m); + if (r != 0) + panic("pci", "pci_attr_w32: can't talk to PCI", r); + + if (m.m_type != 0) + panic("pci", "pci_attr_w32: got bad reply from PCI", m.m_type); +} + diff --git a/lib/syslib/pci_dev_name.c b/lib/syslib/pci_dev_name.c new file mode 100644 index 000000000..5200e9f1c --- /dev/null +++ b/lib/syslib/pci_dev_name.c @@ -0,0 +1,45 @@ +/* +pci_dev_name.c +*/ + +#include "syslib.h" +#include + +/*===========================================================================* + * pci_dev_name * + *===========================================================================*/ +PUBLIC char *pci_dev_name(vid, did) +u16_t vid; +u16_t did; +{ + static char name[80]; /* We need a better interface for this */ + + int r; + message m; + + m.m_type= BUSC_PCI_DEV_NAME; + m.m1_i1= vid; + m.m1_i2= did; + m.m1_i3= sizeof(name); + m.m1_p1= name; + + r= sendrec(PCI_PROC_NR, &m); + if (r != 0) + panic("pci", "pci_dev_name: can't talk to PCI", r); + + if (m.m_type == ENOENT) + { + printf("pci_dev_name: got no name\n"); + return NULL; /* No name for this device */ + } + if (m.m_type != 0) + panic("pci", "pci_dev_name: got bad reply from PCI", m.m_type); + + name[sizeof(name)-1]= '\0'; /* Make sure that the string is NUL + * terminated. + */ + + printf("pci_dev_name: got name %s\n", name); + return name; +} + diff --git a/lib/syslib/pci_find_dev.c b/lib/syslib/pci_find_dev.c new file mode 100644 index 000000000..0e6437631 --- /dev/null +++ b/lib/syslib/pci_find_dev.c @@ -0,0 +1,42 @@ +/* +pci_find_dev.c +*/ + +#include "syslib.h" +#include + +/*===========================================================================* + * pci_find_dev * + *===========================================================================*/ +PUBLIC int pci_find_dev(bus, dev, func, devindp) +u8_t bus; +u8_t dev; +u8_t func; +int *devindp; +{ + int r; + message m; + + m.m_type= BUSC_PCI_FIND_DEV; + m.m1_i1= bus; + m.m1_i2= dev; + m.m1_i3= func; + + r= sendrec(PCI_PROC_NR, &m); + if (r != 0) + panic("pci", "pci_find_dev: can't talk to PCI", r); + + if (m.m_type == 1) + { + *devindp= m.m1_i1; + printf("pci_find_dev: got device %d for %d.%d.%d\n", + *devindp, bus, dev, func); + return 1; + } + if (m.m_type != 0) + panic("pci", "pci_find_dev: got bad reply from PCI", m.m_type); + + printf("pci_find_dev: got nothing\n"); + return 0; +} + diff --git a/lib/syslib/pci_first_dev.c b/lib/syslib/pci_first_dev.c new file mode 100644 index 000000000..a6befe8a6 --- /dev/null +++ b/lib/syslib/pci_first_dev.c @@ -0,0 +1,37 @@ +/* +pci_first_dev.c +*/ + +#include "syslib.h" +#include + +/*===========================================================================* + * pci_first_dev * + *===========================================================================*/ +PUBLIC int pci_first_dev(devindp, vidp, didp) +int *devindp; +u16_t *vidp; +u16_t *didp; +{ + int r; + message m; + + m.m_type= BUSC_PCI_FIRST_DEV; + r= sendrec(PCI_PROC_NR, &m); + if (r != 0) + panic("pci", "pci_first_dev: can't talk to PCI", r); + if (m.m_type == 1) + { + *devindp= m.m1_i1; + *vidp= m.m1_i2; + *didp= m.m1_i3; + printf("pci_first_dev: got device %d, %04x/%04x\n", + *devindp, *vidp, *didp); + return 1; + } + if (m.m_type != 0) + panic("pci", "pci_first_dev: got bad reply from PCI", m.m_type); + + printf("pci_first_dev: got nothing\n"); + return 0; +} diff --git a/lib/syslib/pci_ids.c b/lib/syslib/pci_ids.c new file mode 100644 index 000000000..c05e05aaf --- /dev/null +++ b/lib/syslib/pci_ids.c @@ -0,0 +1,32 @@ +/* +pci_ids.c +*/ + +#include "syslib.h" +#include + +/*===========================================================================* + * pci_ids * + *===========================================================================*/ +PUBLIC void pci_ids(devind, vidp, didp) +int devind; +u16_t *vidp; +u16_t *didp; +{ + int r; + message m; + + m.m_type= BUSC_PCI_IDS; + m.m1_i1= devind; + + r= sendrec(PCI_PROC_NR, &m); + if (r != 0) + panic("pci", "pci_ids: can't talk to PCI", r); + + if (m.m_type != 0) + panic("pci", "pci_ids: got bad reply from PCI", m.m_type); + *vidp= m.m1_i1; + *didp= m.m1_i2; + printf("pci_ids: %04x/%04x\n", *vidp, *didp); +} + diff --git a/lib/syslib/pci_init.c b/lib/syslib/pci_init.c new file mode 100644 index 000000000..254975242 --- /dev/null +++ b/lib/syslib/pci_init.c @@ -0,0 +1,23 @@ +/* +pci_init.c +*/ + +#include "syslib.h" +#include + +/*===========================================================================* + * pci_init * + *===========================================================================*/ +PUBLIC void pci_init() +{ + int r; + message m; + + m.m_type= BUSC_PCI_INIT; + r= sendrec(PCI_PROC_NR, &m); + if (r != 0) + panic("pci", "pci_init: can't talk to PCI", r); + if (m.m_type != 0) + panic("pci", "pci_init: got bad reply from PCI", m.m_type); +} + diff --git a/lib/syslib/pci_next_dev.c b/lib/syslib/pci_next_dev.c new file mode 100644 index 000000000..2cb6d9fc0 --- /dev/null +++ b/lib/syslib/pci_next_dev.c @@ -0,0 +1,43 @@ +/* +pci_next_dev.c +*/ + +#include "syslib.h" +#include + +/*===========================================================================* + * pci_next_dev * + *===========================================================================*/ +PUBLIC int pci_next_dev(devindp, vidp, didp) +int *devindp; +u16_t *vidp; +u16_t *didp; +{ + int r; + message m; + + m.m_type= BUSC_PCI_NEXT_DEV; + m.m1_i1= *devindp; + + r= sendrec(PCI_PROC_NR, &m); + if (r != 0) + panic("pci", "pci_next_dev: can't talk to PCI", r); + + if (m.m_type == 1) + { + *devindp= m.m1_i1; + *vidp= m.m1_i2; + *didp= m.m1_i3; +#if 0 + printf("pci_next_dev: got device %d, %04x/%04x\n", + *devindp, *vidp, *didp); +#endif + return 1; + } + if (m.m_type != 0) + panic("pci", "pci_next_dev: got bad reply from PCI", m.m_type); + + printf("pci_next_dev: got nothing\n"); + return 0; +} + diff --git a/lib/syslib/pci_reserve.c b/lib/syslib/pci_reserve.c new file mode 100644 index 000000000..3cf638188 --- /dev/null +++ b/lib/syslib/pci_reserve.c @@ -0,0 +1,27 @@ +/* +pci_reserve.c +*/ + +#include "syslib.h" +#include + +/*===========================================================================* + * pci_reserve * + *===========================================================================*/ +PUBLIC void pci_reserve(devind) +int devind; +{ + int r; + message m; + + m.m_type= BUSC_PCI_RESERVE; + m.m1_i1= devind; + + r= sendrec(PCI_PROC_NR, &m); + if (r != 0) + panic("pci", "pci_reserve: can't talk to PCI", r); + + if (m.m_type != 0) + panic("pci", "pci_reserve: got bad reply from PCI", m.m_type); +} + diff --git a/lib/syslib/pci_slot_name.c b/lib/syslib/pci_slot_name.c new file mode 100644 index 000000000..0591d2572 --- /dev/null +++ b/lib/syslib/pci_slot_name.c @@ -0,0 +1,38 @@ +/* +pci_slot_name.c +*/ + +#include "syslib.h" +#include + +/*===========================================================================* + * pci_slot_name * + *===========================================================================*/ +PUBLIC char *pci_slot_name(devind) +int devind; +{ + static char name[80]; /* We need a better interface for this */ + + int r; + message m; + + m.m_type= BUSC_PCI_SLOT_NAME; + m.m1_i1= devind; + m.m1_i2= sizeof(name); + m.m1_p1= name; + + r= sendrec(PCI_PROC_NR, &m); + if (r != 0) + panic("pci", "pci_slot_name: can't talk to PCI", r); + + if (m.m_type != 0) + panic("pci", "pci_slot_name: got bad reply from PCI", m.m_type); + + name[sizeof(name)-1]= '\0'; /* Make sure that the string is NUL + * terminated. + */ + + printf("pci_slot_name: got name %s\n", name); + return name; +} +