1 /****************************************************************************
3 * SciTech OS Portability Manager Library
5 * ========================================================================
7 * The contents of this file are subject to the SciTech MGL Public
8 * License Version 1.0 (the "License"); you may not use this file
9 * except in compliance with the License. You may obtain a copy of
10 * the License at http://www.scitechsoft.com/mgl-license.txt
12 * Software distributed under the License is distributed on an
13 * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
14 * implied. See the License for the specific language governing
15 * rights and limitations under the License.
17 * The Original Code is Copyright (C) 1991-1998 SciTech Software, Inc.
19 * The Initial Developer of the Original Code is SciTech Software, Inc.
20 * All Rights Reserved.
22 * ========================================================================
27 * Description: Header file for interface routines to the PCI bus.
29 ****************************************************************************/
36 /*---------------------- Macros and type definitions ----------------------*/
40 /* Defines for PCIDeviceInfo.HeaderType */
43 PCI_deviceType = 0x00,
44 PCI_bridgeType = 0x01,
45 PCI_cardBusBridgeType = 0x02,
46 PCI_multiFunctionType = 0x80
49 /* Defines for PCIDeviceInfo.Command */
52 PCI_enableIOSpace = 0x0001,
53 PCI_enableMemorySpace = 0x0002,
54 PCI_enableBusMaster = 0x0004,
55 PCI_enableSpecialCylces = 0x0008,
56 PCI_enableWriteAndInvalidate = 0x0010,
57 PCI_enableVGACompatiblePalette = 0x0020,
58 PCI_enableParity = 0x0040,
59 PCI_enableWaitCycle = 0x0080,
60 PCI_enableSerr = 0x0100,
61 PCI_enableFastBackToBack = 0x0200
64 /* Defines for PCIDeviceInfo.Status */
67 PCI_statusCapabilitiesList = 0x0010,
68 PCI_status66MhzCapable = 0x0020,
69 PCI_statusUDFSupported = 0x0040,
70 PCI_statusFastBackToBack = 0x0080,
71 PCI_statusDataParityDetected = 0x0100,
72 PCI_statusDevSel = 0x0600,
73 PCI_statusSignaledTargetAbort = 0x0800,
74 PCI_statusRecievedTargetAbort = 0x1000,
75 PCI_statusRecievedMasterAbort = 0x2000,
76 PCI_statusSignaledSystemError = 0x4000,
77 PCI_statusDetectedParityError = 0x8000
80 /* PCI capability IDs */
83 PCI_capsPowerManagement = 0x01,
88 /* PCI AGP rate definitions */
96 /* NOTE: We define all bitfield's as uint's, specifically so that the IBM
97 * Visual Age C++ compiler does not complain. We need them to be
98 * 32-bits wide, and this is the width of an unsigned integer, but
99 * we can't use a ulong to make this explicit or we get errors.
102 /* Structure defining a PCI slot identifier */
117 /* Structure defining the regular (type 0) PCI configuration register
118 * layout. We use this in a union below so we can describe all types of
119 * PCI configuration spaces with a single structure.
129 ulong CardbusCISPointer;
130 ushort SubSystemVendorID;
132 ulong ROMBaseAddress;
133 uchar CapabilitiesPointer;
141 uchar MaximumLatency;
143 /* These are not in the actual config space, but we enumerate them */
144 ulong BaseAddress10Len;
145 ulong BaseAddress14Len;
146 ulong BaseAddress18Len;
147 ulong BaseAddress1CLen;
148 ulong BaseAddress20Len;
149 ulong BaseAddress24Len;
150 ulong ROMBaseAddressLen;
153 /* Structure defining PCI to PCI bridge (type 1) PCI configuration register
154 * layout. We use this in a union below so we can describe all types of
155 * PCI configuration spaces with a single structure.
161 uchar PrimaryBusNumber;
162 uchar SecondayBusNumber;
163 uchar SubordinateBusNumber;
164 uchar SecondaryLatencyTimer;
167 ushort SecondaryStatus;
170 ushort PrefetchableMemoryBase;
171 ushort PrefetchableMemoryLimit;
172 ulong PrefetchableBaseHi;
173 ulong PrefetchableLimitHi;
176 uchar CapabilitiesPointer;
180 ulong ROMBaseAddress;
183 ushort BridgeControl;
186 /* PCI to CardBus bridge (type 2) configuration information */
188 ulong SocketRegistersBaseAddress;
189 uchar CapabilitiesPointer;
191 ushort SecondaryStatus;
194 uchar SubordinateBus;
195 uchar SecondaryLatency;
202 ushort BridgeControl;
205 /* Structure defining the PCI configuration space information for a
206 * single PCI device on the PCI bus. We enumerate all this information
207 * for all PCI devices on the bus.
233 /* PCI Capability header structure. All PCI capabilities have the
236 * capsID is used to identify the type of the structure as define above.
238 * next is the offset in PCI configuration space (0x40-0xFC) of the
239 * next capability structure in the list, or 0x00 if there are no more
248 /* Structure defining the PCI AGP status register contents */
256 uint sideBandAddressing:1;
258 uint requestQueueDepthMaximum:8;
261 /* Structure defining the PCI AGP command register contents */
266 uint fastWriteEnable:1;
272 uint requestQueueDepth:8;
275 /* AGP Capability structure */
280 PCIAGPStatus AGPStatus;
281 PCIAGPCommand AGPCommand;
284 /* Structure for obtaining the PCI IRQ routing information */
303 PCIRouteInfo *DataBuffer;
304 } PCIRoutingOptionsBuffer;
306 #define NUM_PCI_REG (sizeof(PCIDeviceInfo) / 4) - 10
307 #define PCI_BRIDGE_CLASS 0x06
308 #define PCI_HOST_BRIDGE_SUBCLASS 0x00
309 #define PCI_EARLY_VGA_CLASS 0x00
310 #define PCI_EARLY_VGA_SUBCLASS 0x01
311 #define PCI_DISPLAY_CLASS 0x03
312 #define PCI_DISPLAY_VGA_SUBCLASS 0x00
313 #define PCI_DISPLAY_XGA_SUBCLASS 0x01
314 #define PCI_DISPLAY_OTHER_SUBCLASS 0x80
315 #define PCI_MM_CLASS 0x04
316 #define PCI_AUDIO_SUBCLASS 0x01
318 /* Macros to detect specific classes of devices */
320 #define PCI_IS_3DLABS_NONVGA_CLASS(pci) \
321 (((pci)->BaseClass == PCI_DISPLAY_CLASS && (pci)->SubClass == PCI_DISPLAY_OTHER_SUBCLASS) \
322 && ((pci)->VendorID == 0x3D3D || (pci)->VendorID == 0x104C))
324 #define PCI_IS_DISPLAY_CLASS(pci) \
325 (((pci)->BaseClass == PCI_DISPLAY_CLASS && (pci)->SubClass == PCI_DISPLAY_VGA_SUBCLASS) \
326 || ((pci)->BaseClass == PCI_DISPLAY_CLASS && (pci)->SubClass == PCI_DISPLAY_XGA_SUBCLASS) \
327 || ((pci)->BaseClass == PCI_EARLY_VGA_CLASS && (pci)->SubClass == PCI_EARLY_VGA_SUBCLASS) \
328 || PCI_IS_3DLABS_NONVGA_CLASS(pci))
330 /* Function codes to pass to PCI_accessReg */
332 #define PCI_READ_BYTE 0
333 #define PCI_READ_WORD 1
334 #define PCI_READ_DWORD 2
335 #define PCI_WRITE_BYTE 3
336 #define PCI_WRITE_WORD 4
337 #define PCI_WRITE_DWORD 5
339 /* Macros to read/write PCI registers. These assume a global PCI array
340 * of device information.
343 #define PCI_readPCIRegB(index,device) \
344 PCI_accessReg(index,0,0,&PCI[DeviceIndex[device]])
346 #define PCI_readPCIRegW(index,device) \
347 PCI_accessReg(index,0,1,&PCI[DeviceIndex[device]])
349 #define PCI_readPCIRegL(index,device) \
350 PCI_accessReg(index,0,2,&PCI[DeviceIndex[device]])
352 #define PCI_writePCIRegB(index,value,device) \
353 PCI_accessReg(index,value,3,&PCI[DeviceIndex[device]])
355 #define PCI_writePCIRegW(index,value,device) \
356 PCI_accessReg(index,value,4,&PCI[DeviceIndex[device]])
358 #define PCI_writePCIRegL(index,value,device) \
359 PCI_accessReg(index,value,5,&PCI[DeviceIndex[device]])
363 /*-------------------------- Function Prototypes --------------------------*/
366 extern "C" { /* Use "C" linkage when in C++ mode */
369 /* Function to determine the number of PCI devices in the system */
371 int _ASMAPI PCI_getNumDevices(void);
373 /* Function to enumerate all device on the PCI bus */
375 int _ASMAPI PCI_enumerate(PCIDeviceInfo info[]);
377 /* Function to access PCI configuration registers */
379 ulong _ASMAPI PCI_accessReg(int index,ulong value,int func,PCIDeviceInfo *info);
381 /* Function to get PCI IRQ routing options for a card */
383 int _ASMAPI PCI_getIRQRoutingOptions(int numDevices,PCIRouteInfo *buffer);
385 /* Function to re-route the PCI IRQ setting for a device */
387 ibool _ASMAPI PCI_setHardwareIRQ(PCIDeviceInfo *info,uint intPin,uint IRQ);
389 /* Function to generate a special cyle on the specified PCI bus */
391 void _ASMAPI PCI_generateSpecialCyle(uint bus,ulong specialCycleData);
393 /* Function to determine the size of a PCI base address register */
395 ulong _ASMAPI PCI_findBARSize(int bar,PCIDeviceInfo *pci);
397 /* Function to read a block of PCI configuration space registers */
399 void _ASMAPI PCI_readRegBlock(PCIDeviceInfo *info,int index,void *dst,int count);
401 /* Function to write a block of PCI configuration space registers */
403 void _ASMAPI PCI_writeRegBlock(PCIDeviceInfo *info,int index,void *src,int count);
405 /* Function to return the 32-bit PCI BIOS entry point */
407 ulong _ASMAPI PCIBIOS_getEntry(void);
410 } /* End of "C" linkage for C++ */
413 #endif /* __PCILIB_H */