root / Whitix / branches / hybrid / include / pci.h

Revision 487, 2.8 kB (checked in by mwhitworth, 5 months ago)

Add to and tidy up various header files.

Line 
1/*  This file is part of Whitix.
2 *
3 *  Whitix is free software; you can redistribute it and/or modify
4 *  it under the terms of the GNU General Public License as published by
5 *  the Free Software Foundation; either version 2 of the License, or
6 *  (at your option) any later version.
7 *
8 *  Whitix is distributed in the hope that it will be useful,
9 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 *  GNU General Public License for more details.
12 *
13 *  You should have received a copy of the GNU General Public License
14 *  along with Whitix; if not, write to the Free Software
15 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
16 *
17 */
18
19#ifndef PCI_H
20#define PCI_H
21
22#include <console.h>
23#include <typedefs.h>
24
25struct PciBus
26{
27        int index;
28        struct ListHead next;
29        struct ListHead deviceList;
30};
31
32struct PciDevice
33{
34        struct PciBus* bus;
35        BYTE dev,func;
36        WORD vendorId,deviceId;
37        BYTE devClass,subClass,irq;
38        WORD subVendor, subDevice;
39        DWORD spaces[6]; /* I/O or memory space */
40        void* driverData;
41
42        struct ListHead next;
43};
44
45/* PCI BIOS structure. */
46struct PciBios
47{
48        DWORD magicNumber;
49        DWORD physEntry;
50        BYTE version;
51        BYTE length;
52        BYTE crc;
53        BYTE reserved[5];
54}PACKED;
55
56/* PCI configuration space registers */
57#define PCI_VENDOR_ID           0x00
58#define PCI_DEVICE_ID           0x02
59#define PCI_COMMAND                     0x04
60#define         PCI_COMMAND_IO          0x01
61#define         PCI_COMMAND_MEM         0x02
62#define         PCI_COMMAND_MASTER      0x04
63#define PCI_SUBSYS_VENDOR_ID 0x2C
64#define PCI_SUBSYS_ID           0x2E
65
66extern int (*PciRead)(int bus, int dev, int func, int reg, int bytes, DWORD* val);
67extern int (*PciWrite)(int bus, int dev, int func, int reg, DWORD v, int bytes);
68
69/* Internal functions */
70int PciDetectBios();
71
72/* Internal defines */
73#define PCI_VENDOR_INVALID(vendorId) (((vendorId) == 0xFFFF) || ((vendorId) == 0x0000))
74#define PCI_RES_BEGIN_MASK(addressReg) ((addressReg) & 0xFFFFFFF0)
75
76/*** LIBRARY CODE ***/
77
78/* PCI library structures. Used by drivers. */
79
80#define PCI_ID_ANY      (~0)    /* Used if the driver doesn't care about a certain ID field. */
81
82struct PciDeviceId
83{
84        DWORD vendorId, deviceId;
85        DWORD subVendor, subDevice;
86        DWORD class, classMask;
87        void* data;
88};
89
90struct PciDriver
91{
92        char* name;
93        struct PciDeviceId* idTable;
94
95        /* Function pointers. */
96        int (*initOne)(struct PciDevice* device, struct PciDeviceId* devId);
97
98        /* Internal data */
99        struct ListHead next;
100};
101
102/* PCI library functions. Used by drivers. */
103int PciEnableDevice(struct PciDevice* device);
104int PciRegisterDriver(struct PciDriver* pciDriver);
105int PciResourceStart(struct PciDevice* device, int index);
106int PciWriteConfigByte(struct PciDevice* device, int reg, BYTE value);
107int PciReadConfigByte(struct PciDevice* device, int reg, BYTE* value);
108
109#endif
Note: See TracBrowser for help on using the browser.