openblt

a hobby OS from the late 90s
git clone http://frotz.net/git/openblt.git
Log | Files | Refs | LICENSE

pci.c (975B)


      1 #include <blt/types.h>
      2 #include <i386/io.h>
      3 
      4 
      5 typedef struct confadd
      6 {
      7 	uchar reg:8;
      8 	uchar func:3;
      9 	uchar dev:5;
     10 	uchar bus:8;
     11 	uchar rsvd:7;
     12 	uchar enable:1;
     13 } confadd;
     14 
     15 uint32 pci_read(int bus, int dev, int func, int reg, int bytes)
     16 {
     17 	uint32 base;
     18 	
     19 	union {
     20 		confadd c;
     21 		uint32 n;
     22 	} u;
     23 	
     24 	u.c.enable = 1;
     25 	u.c.rsvd = 0;
     26 	u.c.bus = bus;
     27 	u.c.dev = dev;
     28 	u.c.func = func;
     29 	u.c.reg = reg & 0xFC;
     30 	
     31 	outl(u.n,0xCF8);
     32 	
     33 	base = 0xCFC + (reg & 0x03);
     34 		
     35 	switch(bytes){
     36 	case 1: return inb(base);
     37 	case 2: return inw(base);
     38 	case 4: return inl(base);
     39 	default: return 0;
     40 	}
     41 }
     42 
     43 void find_8390(int *addr)
     44 {
     45 	union {
     46 		struct {
     47 			uint16 vendor;
     48 			uint16 device;
     49 		} id;
     50 		uint32 n;
     51 	} u;
     52 	uint32 n;
     53 	int bus;
     54 	int dev;
     55 	
     56 	for(bus=0;bus<8;bus++){
     57 		for(dev=0;dev<32;dev++){
     58 			u.n = pci_read(bus, dev, 0, 0, 4);
     59 			if((u.id.vendor == 0x10ec) && (u.id.device == 0x8029)){
     60 				n = pci_read(bus, dev, 0, 0x10, 4);
     61 				n &= 0xFFF0;
     62 				*addr = (int) n;
     63 				return;
     64 			}
     65 		}
     66 	}
     67 }