pci.h
Go to the documentation of this file.00001 #ifndef _GPXE_PCI_H
00002 #define _GPXE_PCI_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 FILE_LICENCE ( GPL2_ONLY );
00020
00021 #include <stdint.h>
00022 #include <gpxe/device.h>
00023 #include <gpxe/tables.h>
00024 #include <gpxe/pci_io.h>
00025 #include "pci_ids.h"
00026
00027
00028
00029
00030
00031
00032 #define PCI_COMMAND_IO 0x1
00033 #define PCI_COMMAND_MEM 0x2
00034 #define PCI_COMMAND_MASTER 0x4
00035
00036 #define PCI_CACHE_LINE_SIZE 0x0c
00037 #define PCI_LATENCY_TIMER 0x0d
00038
00039 #define PCI_COMMAND_SPECIAL 0x8
00040 #define PCI_COMMAND_INVALIDATE 0x10
00041 #define PCI_COMMAND_VGA_PALETTE 0x20
00042 #define PCI_COMMAND_PARITY 0x40
00043 #define PCI_COMMAND_WAIT 0x80
00044 #define PCI_COMMAND_SERR 0x100
00045 #define PCI_COMMAND_FAST_BACK 0x200
00046 #define PCI_COMMAND_INTX_DISABLE 0x400
00047
00048
00049 #define PCI_VENDOR_ID 0x00
00050 #define PCI_DEVICE_ID 0x02
00051 #define PCI_COMMAND 0x04
00052
00053 #define PCI_STATUS 0x06
00054 #define PCI_STATUS_CAP_LIST 0x10
00055 #define PCI_STATUS_66MHZ 0x20
00056 #define PCI_STATUS_UDF 0x40
00057 #define PCI_STATUS_FAST_BACK 0x80
00058 #define PCI_STATUS_PARITY 0x100
00059 #define PCI_STATUS_DEVSEL_MASK 0x600
00060 #define PCI_STATUS_DEVSEL_FAST 0x000
00061 #define PCI_STATUS_DEVSEL_MEDIUM 0x200
00062 #define PCI_STATUS_DEVSEL_SLOW 0x400
00063 #define PCI_STATUS_SIG_TARGET_ABORT 0x800
00064 #define PCI_STATUS_REC_TARGET_ABORT 0x1000
00065 #define PCI_STATUS_REC_MASTER_ABORT 0x2000
00066 #define PCI_STATUS_SIG_SYSTEM_ERROR 0x4000
00067 #define PCI_STATUS_DETECTED_PARITY 0x8000
00068
00069 #define PCI_REVISION 0x08
00070 #define PCI_REVISION_ID 0x08
00071 #define PCI_CLASS_REVISION 0x08
00072 #define PCI_CLASS_CODE 0x0b
00073 #define PCI_SUBCLASS_CODE 0x0a
00074 #define PCI_HEADER_TYPE 0x0e
00075 #define PCI_HEADER_TYPE_NORMAL 0
00076 #define PCI_HEADER_TYPE_BRIDGE 1
00077 #define PCI_HEADER_TYPE_CARDBUS 2
00078
00079
00080
00081 #define PCI_CARDBUS_CIS 0x28
00082 #define PCI_SUBSYSTEM_VENDOR_ID 0x2c
00083 #define PCI_SUBSYSTEM_ID 0x2e
00084
00085 #define PCI_BASE_ADDRESS_0 0x10
00086 #define PCI_BASE_ADDRESS_1 0x14
00087 #define PCI_BASE_ADDRESS_2 0x18
00088 #define PCI_BASE_ADDRESS_3 0x1c
00089 #define PCI_BASE_ADDRESS_4 0x20
00090 #define PCI_BASE_ADDRESS_5 0x24
00091
00092 #define PCI_BASE_ADDRESS_SPACE 0x01
00093 #define PCI_BASE_ADDRESS_SPACE_IO 0x01
00094 #define PCI_BASE_ADDRESS_SPACE_MEMORY 0x00
00095
00096 #define PCI_BASE_ADDRESS_MEM_TYPE_MASK 0x06
00097 #define PCI_BASE_ADDRESS_MEM_TYPE_32 0x00
00098 #define PCI_BASE_ADDRESS_MEM_TYPE_1M 0x02
00099 #define PCI_BASE_ADDRESS_MEM_TYPE_64 0x04
00100 #define PCI_BASE_ADDRESS_MEM_MASK (~0x0f)
00101 #define PCI_BASE_ADDRESS_IO_MASK (~0x03)
00102 #define PCI_ROM_ADDRESS 0x30
00103 #define PCI_ROM_ADDRESS_ENABLE 0x01
00104
00105
00106
00107 #define PCI_CAPABILITY_LIST 0x34
00108
00109 #define PCI_INTERRUPT_LINE 0x3c
00110 #define PCI_INTERRUPT_PIN 0x3d
00111
00112
00113 #define PCI_PRIMARY_BUS 0x18
00114 #define PCI_SECONDARY_BUS 0x19
00115 #define PCI_SUBORDINATE_BUS 0x1a
00116 #define PCI_SEC_LATENCY_TIMER 0x1b
00117 #define PCI_IO_BASE 0x1c
00118 #define PCI_IO_LIMIT 0x1d
00119 #define PCI_IO_RANGE_TYPE_MASK 0x0f
00120 #define PCI_IO_RANGE_TYPE_16 0x00
00121 #define PCI_IO_RANGE_TYPE_32 0x01
00122 #define PCI_IO_RANGE_MASK ~0x0f
00123 #define PCI_SEC_STATUS 0x1e
00124 #define PCI_MEMORY_BASE 0x20
00125 #define PCI_MEMORY_LIMIT 0x22
00126 #define PCI_MEMORY_RANGE_TYPE_MASK 0x0f
00127 #define PCI_MEMORY_RANGE_MASK ~0x0f
00128 #define PCI_PREF_MEMORY_BASE 0x24
00129 #define PCI_PREF_MEMORY_LIMIT 0x26
00130 #define PCI_PREF_RANGE_TYPE_MASK 0x0f
00131 #define PCI_PREF_RANGE_TYPE_32 0x00
00132 #define PCI_PREF_RANGE_TYPE_64 0x01
00133 #define PCI_PREF_RANGE_MASK ~0x0f
00134 #define PCI_PREF_BASE_UPPER32 0x28
00135 #define PCI_PREF_LIMIT_UPPER32 0x2c
00136 #define PCI_IO_BASE_UPPER16 0x30
00137 #define PCI_IO_LIMIT_UPPER16 0x32
00138
00139
00140 #define PCI_ROM_ADDRESS1 0x38
00141
00142 #define PCI_BRIDGE_CONTROL 0x3e
00143 #define PCI_BRIDGE_CTL_PARITY 0x01
00144 #define PCI_BRIDGE_CTL_SERR 0x02
00145 #define PCI_BRIDGE_CTL_NO_ISA 0x04
00146 #define PCI_BRIDGE_CTL_VGA 0x08
00147 #define PCI_BRIDGE_CTL_MASTER_ABORT 0x20
00148 #define PCI_BRIDGE_CTL_BUS_RESET 0x40
00149 #define PCI_BRIDGE_CTL_FAST_BACK 0x80
00150
00151 #define PCI_CB_CAPABILITY_LIST 0x14
00152
00153
00154
00155 #define PCI_CAP_LIST_ID 0
00156 #define PCI_CAP_ID_PM 0x01
00157 #define PCI_CAP_ID_AGP 0x02
00158 #define PCI_CAP_ID_VPD 0x03
00159 #define PCI_CAP_ID_SLOTID 0x04
00160 #define PCI_CAP_ID_MSI 0x05
00161 #define PCI_CAP_ID_CHSWP 0x06
00162 #define PCI_CAP_ID_EXP 0x10
00163 #define PCI_CAP_LIST_NEXT 1
00164 #define PCI_CAP_FLAGS 2
00165 #define PCI_CAP_SIZEOF 4
00166
00167
00168
00169 #define PCI_PM_PMC 2
00170 #define PCI_PM_CAP_VER_MASK 0x0007
00171 #define PCI_PM_CAP_PME_CLOCK 0x0008
00172 #define PCI_PM_CAP_RESERVED 0x0010
00173 #define PCI_PM_CAP_DSI 0x0020
00174 #define PCI_PM_CAP_AUX_POWER 0x01C0
00175 #define PCI_PM_CAP_D1 0x0200
00176 #define PCI_PM_CAP_D2 0x0400
00177 #define PCI_PM_CAP_PME 0x0800
00178 #define PCI_PM_CAP_PME_MASK 0xF800
00179 #define PCI_PM_CAP_PME_D0 0x0800
00180 #define PCI_PM_CAP_PME_D1 0x1000
00181 #define PCI_PM_CAP_PME_D2 0x2000
00182 #define PCI_PM_CAP_PME_D3 0x4000
00183 #define PCI_PM_CAP_PME_D3cold 0x8000
00184 #define PCI_PM_CTRL 4
00185 #define PCI_PM_CTRL_STATE_MASK 0x0003
00186 #define PCI_PM_CTRL_PME_ENABLE 0x0100
00187 #define PCI_PM_CTRL_DATA_SEL_MASK 0x1e00
00188 #define PCI_PM_CTRL_DATA_SCALE_MASK 0x6000
00189 #define PCI_PM_CTRL_PME_STATUS 0x8000
00190 #define PCI_PM_PPB_EXTENSIONS 6
00191 #define PCI_PM_PPB_B2_B3 0x40
00192 #define PCI_PM_BPCC_ENABLE 0x80
00193 #define PCI_PM_DATA_REGISTER 7
00194 #define PCI_PM_SIZEOF 8
00195
00196
00197
00198 #define PCI_AGP_VERSION 2
00199 #define PCI_AGP_RFU 3
00200 #define PCI_AGP_STATUS 4
00201 #define PCI_AGP_STATUS_RQ_MASK 0xff000000
00202 #define PCI_AGP_STATUS_SBA 0x0200
00203 #define PCI_AGP_STATUS_64BIT 0x0020
00204 #define PCI_AGP_STATUS_FW 0x0010
00205 #define PCI_AGP_STATUS_RATE4 0x0004
00206 #define PCI_AGP_STATUS_RATE2 0x0002
00207 #define PCI_AGP_STATUS_RATE1 0x0001
00208 #define PCI_AGP_COMMAND 8
00209 #define PCI_AGP_COMMAND_RQ_MASK 0xff000000
00210 #define PCI_AGP_COMMAND_SBA 0x0200
00211 #define PCI_AGP_COMMAND_AGP 0x0100
00212 #define PCI_AGP_COMMAND_64BIT 0x0020
00213 #define PCI_AGP_COMMAND_FW 0x0010
00214 #define PCI_AGP_COMMAND_RATE4 0x0004
00215 #define PCI_AGP_COMMAND_RATE2 0x0002
00216 #define PCI_AGP_COMMAND_RATE1 0x0001
00217 #define PCI_AGP_SIZEOF 12
00218
00219
00220
00221 #define PCI_SID_ESR 2
00222 #define PCI_SID_ESR_NSLOTS 0x1f
00223 #define PCI_SID_ESR_FIC 0x20
00224 #define PCI_SID_CHASSIS_NR 3
00225
00226
00227
00228 #define PCI_MSI_FLAGS 2
00229 #define PCI_MSI_FLAGS_64BIT 0x80
00230 #define PCI_MSI_FLAGS_QSIZE 0x70
00231 #define PCI_MSI_FLAGS_QMASK 0x0e
00232 #define PCI_MSI_FLAGS_ENABLE 0x01
00233 #define PCI_MSI_RFU 3
00234 #define PCI_MSI_ADDRESS_LO 4
00235 #define PCI_MSI_ADDRESS_HI 8
00236 #define PCI_MSI_DATA_32 8
00237 #define PCI_MSI_DATA_64 12
00238
00239
00240
00241 #define PCI_ERR_UNCOR_STATUS 4
00242 #define PCI_ERR_UNC_TRAIN 0x00000001
00243 #define PCI_ERR_UNC_DLP 0x00000010
00244 #define PCI_ERR_UNC_POISON_TLP 0x00001000
00245 #define PCI_ERR_UNC_FCP 0x00002000
00246 #define PCI_ERR_UNC_COMP_TIME 0x00004000
00247 #define PCI_ERR_UNC_COMP_ABORT 0x00008000
00248 #define PCI_ERR_UNC_UNX_COMP 0x00010000
00249 #define PCI_ERR_UNC_RX_OVER 0x00020000
00250 #define PCI_ERR_UNC_MALF_TLP 0x00040000
00251 #define PCI_ERR_UNC_ECRC 0x00080000
00252 #define PCI_ERR_UNC_UNSUP 0x00100000
00253 #define PCI_ERR_UNCOR_MASK 8
00254
00255 #define PCI_ERR_UNCOR_SEVER 12
00256
00257 #define PCI_ERR_COR_STATUS 16
00258 #define PCI_ERR_COR_RCVR 0x00000001
00259 #define PCI_ERR_COR_BAD_TLP 0x00000040
00260 #define PCI_ERR_COR_BAD_DLLP 0x00000080
00261 #define PCI_ERR_COR_REP_ROLL 0x00000100
00262 #define PCI_ERR_COR_REP_TIMER 0x00001000
00263 #define PCI_ERR_COR_MASK 20
00264
00265
00266
00267 struct pci_device_id {
00268
00269 const char *name;
00270
00271 uint16_t vendor;
00272
00273 uint16_t device;
00274
00275 unsigned long driver_data;
00276 };
00277
00278
00279 #define PCI_ANY_ID 0xffff
00280
00281
00282 struct pci_device {
00283
00284 struct device dev;
00285
00286
00287
00288
00289 unsigned long membase;
00290
00291
00292
00293
00294
00295 unsigned long ioaddr;
00296
00297 uint16_t vendor;
00298
00299 uint16_t device;
00300
00301 uint32_t class;
00302
00303 uint8_t irq;
00304
00305 uint8_t bus;
00306
00307 uint8_t devfn;
00308
00309 struct pci_driver *driver;
00310
00311
00312
00313
00314
00315 void *priv;
00316
00317 const char *driver_name;
00318 };
00319
00320
00321 struct pci_driver {
00322
00323 struct pci_device_id *ids;
00324
00325 unsigned int id_count;
00326
00327
00328
00329
00330
00331
00332
00333 int ( * probe ) ( struct pci_device *pci,
00334 const struct pci_device_id *id );
00335
00336
00337
00338
00339
00340 void ( * remove ) ( struct pci_device *pci );
00341 };
00342
00343
00344 #define PCI_DRIVERS __table ( struct pci_driver, "pci_drivers" )
00345
00346
00347 #define __pci_driver __table_entry ( PCI_DRIVERS, 01 )
00348
00349 #define PCI_DEVFN( slot, func ) ( ( (slot) << 3 ) | (func) )
00350 #define PCI_SLOT( devfn ) ( ( (devfn) >> 3 ) & 0x1f )
00351 #define PCI_FUNC( devfn ) ( (devfn) & 0x07 )
00352 #define PCI_BUS( busdevfn ) ( (busdevfn) >> 8 )
00353 #define PCI_BUSDEVFN( bus, devfn ) ( ( (bus) << 8 ) | (devfn) )
00354
00355 #define PCI_BASE_CLASS( class ) ( (class) >> 16 )
00356 #define PCI_SUB_CLASS( class ) ( ( (class) >> 8 ) & 0xff )
00357 #define PCI_PROG_INTF( class ) ( (class) & 0xff )
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367 #define PCI_ID( _vendor, _device, _name, _description, _data ) { \
00368 .vendor = _vendor, \
00369 .device = _device, \
00370 .name = _name, \
00371 .driver_data = _data \
00372 }
00373 #define PCI_ROM( _vendor, _device, _name, _description, _data ) \
00374 PCI_ID( _vendor, _device, _name, _description, _data )
00375
00376 extern void adjust_pci_device ( struct pci_device *pci );
00377 extern unsigned long pci_bar_start ( struct pci_device *pci,
00378 unsigned int reg );
00379 extern int pci_find_capability ( struct pci_device *pci, int capability );
00380 extern unsigned long pci_bar_size ( struct pci_device *pci, unsigned int reg );
00381
00382
00383
00384
00385
00386
00387
00388 static inline void pci_set_drvdata ( struct pci_device *pci, void *priv ) {
00389 pci->priv = priv;
00390 }
00391
00392
00393
00394
00395
00396
00397
00398 static inline void * pci_get_drvdata ( struct pci_device *pci ) {
00399 return pci->priv;
00400 }
00401
00402 #endif