cynix

x86 UNIX-like OS
git clone git://git.2f30.org/cynix
Log | Files | Refs | README | LICENSE

pci.h (1423B)


      1 #ifndef __PCI_H__
      2 #define __PCI_H__
      3 
      4 #include <stdint.h>
      5 #include <list.h>
      6 
      7 enum {
      8 	CONFIG_ADDRESS = 0xcf8,
      9 	CONFIG_DATA = 0xcfc,
     10 	PCI_NO_DEV = 0xffffffff
     11 };
     12 
     13 struct pci_config_addr_t {
     14 	uint8_t reg_num : 8;
     15 	uint8_t func_num : 3;
     16 	uint8_t dev_num : 5;
     17 	uint8_t bus_num : 8;
     18 	uint8_t reserved : 7;
     19 	uint8_t enable_bit : 1;
     20 } __attribute__ ((packed));
     21 
     22 union pci_config_space_t {
     23 	struct {
     24 		uint16_t vendor_id;
     25 		uint16_t device_id;
     26 		uint16_t command;
     27 		uint16_t status;
     28 		uint8_t rev_id;
     29 		uint8_t prog_if;
     30 		uint8_t subclass;
     31 		uint8_t class;
     32 		uint8_t cachelsz;
     33 		uint8_t latency_timer;
     34 		uint8_t header_type;
     35 		uint8_t bist;
     36 		uint32_t bar0, bar1, bar2, bar3, bar4, bar5;
     37 		uint32_t cardbus_cis_reg;
     38 		uint16_t sub_vendor_id;
     39 		uint16_t sub_id;
     40 		uint32_t exp_rom_addr;
     41 		uint16_t caps;
     42 		uint16_t reserved0;
     43 		uint32_t reserved1;
     44 		uint8_t irq;
     45 		uint8_t int_pin;
     46 		uint8_t min_grant;
     47 		uint8_t max_latency;
     48 	} __attribute__((packed)) type0;
     49 };
     50 
     51 struct pci_dev_t;
     52 
     53 struct pci_bus_t {
     54 	struct list_head pci_dev_list;
     55 	struct list_head pci_bus_list;
     56 };
     57 
     58 struct pci_dev_t {
     59 	union pci_config_space_t *cspace;
     60 	struct pci_bus_t *bus;
     61 	struct list_head list;
     62 	int busn;
     63 	int devn;
     64 };
     65 
     66 extern uint32_t pci_read32(struct pci_config_addr_t *addr);
     67 extern uint32_t pci_init(void);
     68 extern int pci_enumerate(void);
     69 extern void lspci(void);
     70 extern struct pci_dev_t * get_pci_dev(uint16_t vendor_id, uint16_t device_id);
     71 
     72 #endif
     73