Changeset 2008 for Whitix

Show
Ignore:
Timestamp:
04/02/09 21:13:07 (3 years ago)
Author:
mwhitworth
Message:

Rework PCI code to use generic resource layer, add defines and more prototypes, add module parameter to driver registration function.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • Whitix/trunk/include/pci.h

    r1887 r2008  
    2020#define PCI_H 
    2121 
     22#include <devices/bus.h> 
    2223#include <console.h> 
     24#include <module.h> 
    2325#include <typedefs.h> 
     26#include <resource.h> 
    2427 
    2528struct PciBus 
     
    2831        struct ListHead next; 
    2932        struct ListHead deviceList; 
     33        struct KeBus bus; 
    3034}; 
    3135 
     
    3438struct PciDevice 
    3539{ 
     40        /* PCI configuration information; cached. */ 
     41        BYTE dev, func, headerType; 
     42        DWORD vendorId, deviceId; 
     43        int irq; 
     44        DWORD devClass; 
     45        WORD subVendor, subDevice; 
     46 
     47        struct Resource spaces[6]; 
     48         
     49        /* PCI layer data. */ 
    3650        struct PciBus* bus; 
    37         BYTE dev,func; 
    38         WORD vendorId,deviceId; 
    39         BYTE devClass,subClass,irq; 
    40         WORD subVendor, subDevice; 
    41         DWORD spaces[6]; /* I/O or memory space */ 
     51        struct PciDriver* driver; 
     52        struct KeBusEntry entry; 
    4253         
    43         struct PciDriver* driver; 
    4454        void* driverData; 
    4555 
    4656        struct ListHead next; 
    4757}; 
     58 
     59#define PciSetData(driver, data) ((driver)->driverData = (data)) 
    4860 
    4961/* PCI BIOS structure. */ 
     
    6981#define PCI_INTERRUPT_PIN       0x3D 
    7082 
     83#define PCI_PRIMARY_BUS         0x18 
     84#define PCI_SECONDARY_BUS       0x19 
     85 
     86#define PCI_WRITE_TEST  0xFFFFFFFF 
     87#define PCI_BAR_BASE    0x10 
     88 
     89/* NUmber of I/O resource slots for each device. */ 
     90#define PCI_NUM_RESOURCES       6 
     91 
     92#define PCI_RESOURCE_IO         0x01 
     93 
    7194extern int (*PciRead)(int bus, int dev, int func, int reg, int bytes, DWORD* val); 
    7295extern int (*PciWrite)(int bus, int dev, int func, int reg, DWORD v, int bytes); 
     
    87110#define PciIdTableEnd() {0, 0, 0, 0, 0, 0, NULL} 
    88111 
     112#define PCI_ID_DATA(id) ((id)->data) 
     113 
    89114struct PciDeviceId 
    90115{ 
     
    94119        void* data; 
    95120}; 
     121 
     122/* PCI device classes. */ 
     123#define PCI_BASE_CLASS_DISPLAY          0x03 
    96124 
    97125struct PciDriver 
     
    104132 
    105133        /* Internal data */ 
     134        struct Module* module; 
    106135        struct ListHead next; 
    107136        void* data; 
     
    110139/* PCI library functions. Used by drivers. */ 
    111140int PciEnableDevice(struct PciDevice* device); 
    112 int PciRegisterDriver(struct PciDriver* pciDriver); 
    113 unsigned long PciResourceStart(struct PciDevice* device, int index); 
     141int PciDisableDevice(struct PciDevice* device); 
     142int PciSetMaster(struct PciDevice* device); 
     143int PciRegisterDriverMod(struct Module* module, struct PciDriver* pciDriver); 
     144#define PciRegisterDriver(driver) (PciRegisterDriverMod(THIS_MODULE, (driver))) 
     145 
    114146int PciWriteConfigByte(struct PciDevice* device, int reg, BYTE value); 
    115147int PciReadConfigByte(struct PciDevice* device, int reg, BYTE* value); 
    116148int PciReadConfigWord(struct PciDevice* device, int reg, WORD* value); 
     149int PciWriteConfigWord(struct PciDevice* device, int reg, WORD value); 
    117150 
    118151int PciReadConfigDword(struct PciDevice* device, int reg, DWORD* value); 
    119152int PciWriteConfigDword(struct PciDevice* device, int reg, DWORD value); 
    120153 
     154/* Inline library functions */ 
     155static inline unsigned long PciResourceStart(struct PciDevice* device, int index) 
     156{ 
     157        if (index < 0 || index >= 6) 
     158                return 0; 
     159                 
     160        return device->spaces[index].start; 
     161} 
     162 
     163static inline unsigned long PciResourceLen(struct PciDevice* device, int index) 
     164{ 
     165        if (index < 0 || index >= 6) 
     166                return 0; 
     167                 
     168        return device->spaces[index].len; 
     169} 
     170 
     171static inline unsigned long PciResourceFlags(struct PciDevice* device, int index) 
     172{ 
     173        if (index < 0 || index >= 6) 
     174                return 0; 
     175                 
     176        return device->spaces[index].flags; 
     177} 
     178 
    121179#endif