~ubuntu-branches/ubuntu/oneiric/virtualbox-ose/oneiric

« back to all changes in this revision

Viewing changes to include/VBox/pci.h

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2011-01-30 23:27:25 UTC
  • mfrom: (0.3.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20110130232725-2ouajjd2ggdet0zd
Tags: 4.0.2-dfsg-1ubuntu1
* Merge from Debian unstable, remaining changes:
  - Add Apport hook.
    - debian/virtualbox-ose.files/source_virtualbox-ose.py
    - debian/virtualbox-ose.install
  - Drop *-source packages.
* Drop ubuntu-01-fix-build-gcc45.patch, fixed upstream.
* Drop ubuntu-02-as-needed.patch, added to the Debian package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
typedef enum PCICONFIGCOMMAND
45
45
{
46
46
    /** Supports/uses memory accesses. */
47
 
    PCI_COMMAND_IOACCESS = 0x0001,
 
47
    PCI_COMMAND_IOACCESS  = 0x0001,
48
48
    PCI_COMMAND_MEMACCESS = 0x0002,
49
49
    PCI_COMMAND_BUSMASTER = 0x0004
50
50
} PCICONFIGCOMMAND;
56
56
 */
57
57
/** Note: There are all sorts of dirty dependencies on the values in the
58
58
 *  pci device. Be careful when changing this.
59
 
 *  @todo we should introduce 32 & 64 bits physical address types
60
59
 */
61
60
typedef enum PCIADDRESSSPACE
62
61
{
64
63
    PCI_ADDRESS_SPACE_MEM = 0x00,
65
64
    /** I/O space. */
66
65
    PCI_ADDRESS_SPACE_IO = 0x01,
 
66
    /** 32-bit BAR. */
 
67
    PCI_ADDRESS_SPACE_BAR32 = 0x00,
 
68
    /** 64-bit BAR. */
 
69
    PCI_ADDRESS_SPACE_BAR64 = 0x04,
67
70
    /** Prefetch memory. */
68
71
    PCI_ADDRESS_SPACE_MEM_PREFETCH = 0x08
69
72
} PCIADDRESSSPACE;
93
96
 
94
97
/** @name PCI Configuration Space Registers
95
98
 * @{ */
96
 
#define VBOX_PCI_VENDOR_ID              0x00    /**< 16-bit RO */
97
 
#define VBOX_PCI_DEVICE_ID              0x02    /**< 16-bit RO */
98
 
#define VBOX_PCI_COMMAND                0x04    /**< 16-bit RW */
99
 
#define VBOX_PCI_STATUS                 0x06    /**< 16-bit RW */
100
 
#define VBOX_PCI_REVISION_ID            0x08    /**<  8-bit RO */
101
 
#define VBOX_PCI_CLASS_PROG             0x09    /**<  8-bit RO - - register-level programming class code (device specific). */
102
 
#define VBOX_PCI_CLASS_SUB              0x0a    /**<  8-bit RO - - sub-class code. */
 
99
/* Commented out values common for different header types */
 
100
/* Common part of the header */
 
101
#define VBOX_PCI_VENDOR_ID              0x00    /**< 16-bit  RO */
 
102
#define VBOX_PCI_DEVICE_ID              0x02    /**< 16-bit  RO */
 
103
#define VBOX_PCI_COMMAND                0x04    /**< 16-bit  RW, some bits RO */
 
104
#define VBOX_PCI_STATUS                 0x06    /**< 16-bit  RW, some bits RO */
 
105
#define VBOX_PCI_REVISION_ID            0x08    /**<  8-bit  RO  - - device revision */
 
106
#define VBOX_PCI_CLASS_PROG             0x09    /**<  8-bit  RO  - - register-level programming class code (device specific). */
 
107
#define VBOX_PCI_CLASS_SUB              0x0a    /**<  8-bit  RO  - - sub-class code. */
103
108
#define VBOX_PCI_CLASS_DEVICE           VBOX_PCI_CLASS_SUB
104
 
#define VBOX_PCI_CLASS_BASE             0x0b    /**<  8-bit RO - - base class code. */
105
 
#define VBOX_PCI_CACHE_LINE_SIZE        0x0c    /**<  8-bit ?? */
106
 
#define VBOX_PCI_LATENCY_TIMER          0x0d    /**<  8-bit ?? */
107
 
#define VBOX_PCI_HEADER_TYPE            0x0e    /**<  8-bit ?? */
108
 
#define VBOX_PCI_BIST                   0x0f    /**<  8-bit ?? */
109
 
#define VBOX_PCI_BASE_ADDRESS_0         0x10    /**< 32-bit RW */
110
 
#define VBOX_PCI_BASE_ADDRESS_1         0x14    /**< 32-bit RW */
111
 
#define VBOX_PCI_BASE_ADDRESS_2         0x18    /**< 32-bit RW */
112
 
#define VBOX_PCI_PRIMARY_BUS            0x18    /**<  8-bit ?? - bridge - primary bus number. */
113
 
#define VBOX_PCI_SECONDARY_BUS          0x19    /**<  8-bit ?? - bridge - secondary bus number. */
114
 
#define VBOX_PCI_SUBORDINATE_BUS        0x1a    /**<  8-bit ?? - bridge - highest subordinate bus number. (behind the bridge) */
115
 
#define VBOX_PCI_SEC_LATENCY_TIMER      0x1b    /**<  8-bit ?? - bridge - secondary latency timer. */
116
 
#define VBOX_PCI_BASE_ADDRESS_3         0x1c    /**< 32-bit RW */
117
 
#define VBOX_PCI_IO_BASE                0x1c    /**<  8-bit ?? - bridge - I/O range base. */
118
 
#define VBOX_PCI_IO_LIMIT               0x1d    /**<  8-bit ?? - bridge - I/O range limit. */
119
 
#define VBOX_PCI_SEC_STATUS             0x1e    /**< 16-bit ?? - bridge - secondary status register. */
120
 
#define VBOX_PCI_BASE_ADDRESS_4         0x20    /**< 32-bit RW */
121
 
#define VBOX_PCI_MEMORY_BASE            0x20    /**< 16-bit ?? - bridge - memory range base. */
122
 
#define VBOX_PCI_MEMORY_LIMIT           0x22    /**< 16-bit ?? - bridge - memory range limit. */
123
 
#define VBOX_PCI_BASE_ADDRESS_5         0x24    /**< 32-bit RW */
124
 
#define VBOX_PCI_PREF_MEMORY_BASE       0x24    /**< 16-bit ?? - bridge - Prefetchable memory range base. */
125
 
#define VBOX_PCI_PREF_MEMORY_LIMIT      0x26    /**< 16-bit ?? - bridge - Prefetchable memory range limit. */
126
 
#define VBOX_PCI_CARDBUS_CIS            0x28    /**< 32-bit ?? */
127
 
#define VBOX_PCI_PREF_BASE_UPPER32      0x28    /**< 32-bit ?? - bridge - Prefetchable memory range high base.*/
128
 
#define VBOX_PCI_PREF_LIMIT_UPPER32     0x2c    /**< 32-bit ?? - bridge - Prefetchable memory range high limit. */
129
 
#define VBOX_PCI_SUBSYSTEM_VENDOR_ID    0x2c    /**< 16-bit ?? */
130
 
#define VBOX_PCI_SUBSYSTEM_ID           0x2e    /**< 16-bit ?? */
131
 
#define VBOX_PCI_ROM_ADDRESS            0x30    /**< 32-bit ?? */
132
 
#define VBOX_PCI_IO_BASE_UPPER16        0x30    /**< 16-bit ?? - bridge - memory range high base. */
133
 
#define VBOX_PCI_IO_LIMIT_UPPER16       0x32    /**< 16-bit ?? - bridge - memory range high limit. */
134
 
#define VBOX_PCI_CAPABILITY_LIST        0x34    /**< 8-bit? ?? */
135
 
#define VBOX_PCI_ROM_ADDRESS_BR         0x38    /**< 32-bit ?? - bridge */
136
 
#define VBOX_PCI_INTERRUPT_LINE         0x3c    /**<  8-bit RW - Interrupt line. */
137
 
#define VBOX_PCI_INTERRUPT_PIN          0x3d    /**<  8-bit RO - Interrupt pin.  */
138
 
#define VBOX_PCI_MIN_GNT                0x3e    /**<  8-bit ?? */
139
 
#define VBOX_PCI_BRIDGE_CONTROL         0x3e    /**< 8-bit? ?? - bridge */
140
 
#define VBOX_PCI_MAX_LAT                0x3f    /**<  8-bit ?? */
 
109
#define VBOX_PCI_CLASS_BASE             0x0b    /**<  8-bit  RO  - - base class code. */
 
110
#define VBOX_PCI_CACHE_LINE_SIZE        0x0c    /**<  8-bit  RW  - - system cache line size */
 
111
#define VBOX_PCI_LATENCY_TIMER          0x0d    /**<  8-bit  RW  - - master latency timer, hardwired to 0 for PCIe */
 
112
#define VBOX_PCI_HEADER_TYPE            0x0e    /**<  8-bit  RO  - - header type (0 - device, 1 - bridge, 2  - CardBus bridge)  */
 
113
#define VBOX_PCI_BIST                   0x0f    /**<  8-bit  RW  - - built-in self test control */
 
114
#define VBOX_PCI_CAPABILITY_LIST        0x34    /**<  8-bit  RO? - - linked list of new capabilities implemented by the device, 2 bottom bits reserved */
 
115
#define VBOX_PCI_INTERRUPT_LINE         0x3c    /**<  8-bit  RW  - - interrupt line. */
 
116
#define VBOX_PCI_INTERRUPT_PIN          0x3d    /**<  8-bit  RO  - - interrupt pin.  */
 
117
 
 
118
/* Type 0 header, device */
 
119
#define VBOX_PCI_BASE_ADDRESS_0         0x10    /**< 32-bit  RW */
 
120
#define VBOX_PCI_BASE_ADDRESS_1         0x14    /**< 32-bit  RW */
 
121
#define VBOX_PCI_BASE_ADDRESS_2         0x18    /**< 32-bit  RW */
 
122
#define VBOX_PCI_BASE_ADDRESS_3         0x1c    /**< 32-bit  RW */
 
123
#define VBOX_PCI_BASE_ADDRESS_4         0x20    /**< 32-bit  RW */
 
124
#define VBOX_PCI_BASE_ADDRESS_5         0x24    /**< 32-bit  RW */
 
125
#define VBOX_PCI_CARDBUS_CIS            0x28    /**< 32-bit  ?? */
 
126
#define VBOX_PCI_SUBSYSTEM_VENDOR_ID    0x2c    /**< 16-bit  RO */
 
127
#define VBOX_PCI_SUBSYSTEM_ID           0x2e    /**< 16-bit  RO */
 
128
#define VBOX_PCI_ROM_ADDRESS            0x30    /**< 32-bit  ?? */
 
129
/* #define VBOX_PCI_CAPABILITY_LIST        0x34 */  /**<  8-bit? ?? */
 
130
#define VBOX_PCI_RESERVED_35            0x35    /**<  8-bit  ?? - - reserved */
 
131
#define VBOX_PCI_RESERVED_36            0x36    /**<  8-bit  ?? - - reserved */
 
132
#define VBOX_PCI_RESERVED_37            0x37    /**<  8-bit  ?? - - reserved */
 
133
#define VBOX_PCI_RESERVED_38            0x38    /**<  32-bit ?? - - reserved */
 
134
/* #define VBOX_PCI_INTERRUPT_LINE         0x3c */   /**<  8-bit  RW  - - interrupt line. */
 
135
/* #define VBOX_PCI_INTERRUPT_PIN          0x3d */   /**<  8-bit  RO  - - interrupt pin.  */
 
136
#define VBOX_PCI_MIN_GNT                0x3e    /**<  8-bit  RO - - burst period length (in 1/4 microsecond units)  */
 
137
#define VBOX_PCI_MAX_LAT                0x3f    /**<  8-bit  RO - - how often the device needs access to the PCI bus (in 1/4 microsecond units) */
 
138
 
 
139
/* Type 1 header, PCI-to-PCI bridge */
 
140
/* #define VBOX_PCI_BASE_ADDRESS_0         0x10 */    /**< 32-bit RW */
 
141
/* #define VBOX_PCI_BASE_ADDRESS_1         0x14 */    /**< 32-bit RW */
 
142
#define VBOX_PCI_PRIMARY_BUS            0x18    /**<  8-bit  ?? - - primary bus number. */
 
143
#define VBOX_PCI_SECONDARY_BUS          0x19    /**<  8-bit  ?? - - secondary bus number. */
 
144
#define VBOX_PCI_SUBORDINATE_BUS        0x1a    /**<  8-bit  ?? - - highest subordinate bus number. (behind the bridge) */
 
145
#define VBOX_PCI_SEC_LATENCY_TIMER      0x1b    /**<  8-bit  ?? - - secondary latency timer. */
 
146
#define VBOX_PCI_IO_BASE                0x1c    /**<  8-bit  ?? - - I/O range base. */
 
147
#define VBOX_PCI_IO_LIMIT               0x1d    /**<  8-bit  ?? - - I/O range limit. */
 
148
#define VBOX_PCI_SEC_STATUS             0x1e    /**< 16-bit  ?? - - secondary status register. */
 
149
#define VBOX_PCI_MEMORY_BASE            0x20    /**< 16-bit  ?? - - memory range base. */
 
150
#define VBOX_PCI_MEMORY_LIMIT           0x22    /**< 16-bit  ?? - - memory range limit. */
 
151
#define VBOX_PCI_PREF_MEMORY_BASE       0x24    /**< 16-bit  ?? - - prefetchable memory range base. */
 
152
#define VBOX_PCI_PREF_MEMORY_LIMIT      0x26    /**< 16-bit  ?? - - prefetchable memory range limit. */
 
153
#define VBOX_PCI_PREF_BASE_UPPER32      0x28    /**< 32-bit  ?? - - prefetchable memory range high base.*/
 
154
#define VBOX_PCI_PREF_LIMIT_UPPER32     0x2c    /**< 32-bit  ?? - - prefetchable memory range high limit. */
 
155
#define VBOX_PCI_IO_BASE_UPPER16        0x30    /**< 16-bit  ?? - - memory range high base. */
 
156
#define VBOX_PCI_IO_LIMIT_UPPER16       0x32    /**< 16-bit  ?? - - memory range high limit. */
 
157
/* #define VBOX_PCI_CAPABILITY_LIST        0x34 */   /**<  8-bit? ?? */
 
158
/* #define VBOX_PCI_RESERVED_35            0x35 */   /**<  8-bit ?? - - reserved */
 
159
/* #define VBOX_PCI_RESERVED_36            0x36 */   /**<  8-bit ?? - - reserved */
 
160
/* #define VBOX_PCI_RESERVED_37            0x37 */   /**<  8-bit ?? - - reserved */
 
161
#define VBOX_PCI_ROM_ADDRESS_BR         0x38    /**< 32-bit  ?? - - expansion ROM base address  */
 
162
#define VBOX_PCI_BRIDGE_CONTROL         0x3e    /**< 16-bit?  ?? - - bridge control  */
 
163
 
 
164
/* Type 2 header, PCI-to-CardBus bridge */
 
165
#define VBOX_PCI_CARDBUS_BASE_ADDRESS   0x10    /**< 32-bit  RW  - - CardBus Socket/ExCa base address */
 
166
#define VBOX_PCI_CARDBUS_CAPLIST        0x14    /**<  8-bit  RO? - - offset of capabilities list */
 
167
#define VBOX_PCI_CARDBUS_RESERVED_15    0x15    /**<  8-bit  ??  - - reserved */
 
168
#define VBOX_PCI_CARDBUS_SEC_STATUS     0x16    /**< 16-bit  ??  - - secondary status  */
 
169
#define VBOX_PCI_CARDBUS_PCIBUS_NUMBER  0x18    /**<  8-bit  ??  - - PCI bus number */
 
170
#define VBOX_PCI_CARDBUS_CARDBUS_NUMBER 0x19    /**<  8-bit  ??  - - CardBus bus number */
 
171
/* #define VBOX_PCI_SUBORDINATE_BUS        0x1a */    /**<  8-bit  ?? - - highest subordinate bus number. (behind the bridge) */
 
172
/* #define VBOX_PCI_SEC_LATENCY_TIMER      0x1b */    /**<  8-bit  ?? - - secondary latency timer. */
 
173
#define VBOX_PCI_CARDBUS_MEMORY_BASE0   0x1c     /**< 32-bit  RW  - - memory base address 0 */
 
174
#define VBOX_PCI_CARDBUS_MEMORY_LIMIT0  0x20     /**< 32-bit  RW  - - memory limit 0 */
 
175
#define VBOX_PCI_CARDBUS_MEMORY_BASE1   0x24     /**< 32-bit  RW  - - memory base address 1 */
 
176
#define VBOX_PCI_CARDBUS_MEMORY_LIMIT1  0x28     /**< 32-bit  RW  - - memory limit 1 */
 
177
#define VBOX_PCI_CARDBUS_IO_BASE0       0x2c     /**< 32-bit  RW  - - IO base address 0 */
 
178
#define VBOX_PCI_CARDBUS_IO_LIMIT0      0x30     /**< 32-bit  RW  - - IO limit 0 */
 
179
#define VBOX_PCI_CARDBUS_IO_BASE1       0x34     /**< 32-bit  RW  - - IO base address 1 */
 
180
#define VBOX_PCI_CARDBUS_IO_LIMIT1      0x38     /**< 32-bit  RW  - - IO limit 1 */
 
181
/* #define VBOX_PCI_INTERRUPT_LINE         0x3c */   /**<  8-bit  RW  - - interrupt line. */
 
182
/* #define VBOX_PCI_INTERRUPT_PIN          0x3d */   /**<  8-bit  RO  - - interrupt pin.  */
 
183
/* #define VBOX_PCI_BRIDGE_CONTROL         0x3e */   /**< 16-bit?  ?? - - bridge control  */
141
184
/** @} */
142
185
 
143
186
 
 
187
/* Possible values in status bitmask */
 
188
#define  VBOX_PCI_STATUS_CAP_LIST    0x10    /* Support Capability List */
 
189
#define  VBOX_PCI_STATUS_66MHZ       0x20    /* Support 66 Mhz PCI 2.1 bus */
 
190
#define  VBOX_PCI_STATUS_UDF         0x40    /* Support User Definable Features [obsolete] */
 
191
#define  VBOX_PCI_STATUS_FAST_BACK   0x80    /* Accept fast-back to back */
 
192
#define  VBOX_PCI_STATUS_PARITY      0x100   /* Detected parity error */
 
193
#define  VBOX_PCI_STATUS_DEVSEL_MASK 0x600   /* DEVSEL timing */
 
194
#define  VBOX_PCI_STATUS_DEVSEL_FAST         0x000
 
195
#define  VBOX_PCI_STATUS_DEVSEL_MEDIUM       0x200
 
196
#define  VBOX_PCI_STATUS_DEVSEL_SLOW         0x400
 
197
#define  VBOX_PCI_STATUS_SIG_TARGET_ABORT    0x800 /* Set on target abort */
 
198
#define  VBOX_PCI_STATUS_REC_TARGET_ABORT    0x1000 /* Master ack of " */
 
199
#define  VBOX_PCI_STATUS_REC_MASTER_ABORT    0x2000 /* Set on master abort */
 
200
#define  VBOX_PCI_STATUS_SIG_SYSTEM_ERROR    0x4000 /* Set when we drive SERR */
 
201
#define  VBOX_PCI_STATUS_DETECTED_PARITY     0x8000 /* Set on parity error */
 
202
 
 
203
 
 
204
/* Command bitmask */
 
205
#define  VBOX_PCI_COMMAND_IO           0x1     /* Enable response in I/O space */
 
206
#define  VBOX_PCI_COMMAND_MEMORY       0x2     /* Enable response in Memory space */
 
207
#define  VBOX_PCI_COMMAND_MASTER       0x4     /* Enable bus mastering */
 
208
#define  VBOX_PCI_COMMAND_SPECIAL      0x8     /* Enable response to special cycles */
 
209
#define  VBOX_PCI_COMMAND_INVALIDATE   0x10    /* Use memory write and invalidate */
 
210
#define  VBOX_PCI_COMMAND_VGA_PALETTE  0x20    /* Enable palette snooping */
 
211
#define  VBOX_PCI_COMMAND_PARITY       0x40    /* Enable parity checking */
 
212
#define  VBOX_PCI_COMMAND_WAIT         0x80    /* Enable address/data stepping */
 
213
#define  VBOX_PCI_COMMAND_SERR         0x100   /* Enable SERR */
 
214
#define  VBOX_PCI_COMMAND_FAST_BACK    0x200   /* Enable back-to-back writes */
 
215
#define  VBOX_PCI_COMMAND_INTX_DISABLE 0x400   /* INTx Emulation Disable */
 
216
 
 
217
 
 
218
/* Capability list values (capability offset 0) */
 
219
/* Next  value pointer in offset 1, or 0 if none */
 
220
#define  VBOX_PCI_CAP_ID_PM          0x01    /* Power Management */
 
221
#define  VBOX_PCI_CAP_ID_AGP         0x02    /* Accelerated Graphics Port */
 
222
#define  VBOX_PCI_CAP_ID_VPD         0x03    /* Vital Product Data */
 
223
#define  VBOX_PCI_CAP_ID_SLOTID      0x04    /* Slot Identification */
 
224
#define  VBOX_PCI_CAP_ID_MSI         0x05    /* Message Signalled Interrupts */
 
225
#define  VBOX_PCI_CAP_ID_CHSWP       0x06    /* CompactPCI HotSwap */
 
226
#define  VBOX_PCI_CAP_ID_PCIX        0x07    /* PCI-X */
 
227
#define  VBOX_PCI_CAP_ID_HT          0x08    /* HyperTransport */
 
228
#define  VBOX_PCI_CAP_ID_VNDR        0x09    /* Vendor specific */
 
229
#define  VBOX_PCI_CAP_ID_DBG         0x0A    /* Debug port */
 
230
#define  VBOX_PCI_CAP_ID_CCRC        0x0B    /* CompactPCI Central Resource Control */
 
231
#define  VBOX_PCI_CAP_ID_SHPC        0x0C    /* PCI Standard Hot-Plug Controller */
 
232
#define  VBOX_PCI_CAP_ID_SSVID       0x0D    /* Bridge subsystem vendor/device ID */
 
233
#define  VBOX_PCI_CAP_ID_AGP3        0x0E    /* AGP Target PCI-PCI bridge */
 
234
#define  VBOX_PCI_CAP_ID_SECURE      0x0F    /* Secure device (?) */
 
235
#define  VBOX_PCI_CAP_ID_EXP         0x10    /* PCI Express */
 
236
#define  VBOX_PCI_CAP_ID_MSIX        0x11    /* MSI-X */
 
237
#define  VBOX_PCI_CAP_ID_SATA        0x12    /* Serial-ATA HBA */
 
238
#define  VBOX_PCI_CAP_ID_AF          0x13    /* PCI Advanced Features */
 
239
 
 
240
/* Extended Capabilities (PCI-X 2.0 and Express), start at 0x100, next - bits [20..32] */
 
241
#define  VBOX_PCI_EXT_CAP_ID_ERR     0x01    /* Advanced Error Reporting */
 
242
#define  VBOX_PCI_EXT_CAP_ID_VC      0x02    /* Virtual Channel */
 
243
#define  VBOX_PCI_EXT_CAP_ID_DSN     0x03    /* Device Serial Number */
 
244
#define  VBOX_PCI_EXT_CAP_ID_PWR     0x04    /* Power Budgeting */
 
245
#define  VBOX_PCI_EXT_CAP_ID_RCLINK  0x05    /* Root Complex Link Declaration */
 
246
#define  VBOX_PCI_EXT_CAP_ID_RCILINK 0x06    /* Root Complex Internal Link Declaration */
 
247
#define  VBOX_PCI_EXT_CAP_ID_RCECOLL 0x07    /* Root Complex Event Collector */
 
248
#define  VBOX_PCI_EXT_CAP_ID_MFVC    0x08    /* Multi-Function Virtual Channel */
 
249
#define  VBOX_PCI_EXT_CAP_ID_RBCB    0x0a    /* Root Bridge Control Block */
 
250
#define  VBOX_PCI_EXT_CAP_ID_VNDR    0x0b    /* Vendor specific */
 
251
#define  VBOX_PCI_EXT_CAP_ID_ACS     0x0d    /* Access Controls */
 
252
#define  VBOX_PCI_EXT_CAP_ID_ARI     0x0e
 
253
#define  VBOX_PCI_EXT_CAP_ID_ATS     0x0f
 
254
#define  VBOX_PCI_EXT_CAP_ID_SRIOV   0x10
 
255
 
 
256
 
 
257
/* MSI flags, aka Message Control (2 bytes, capability offset 2) */
 
258
#define  VBOX_PCI_MSI_FLAGS_ENABLE   0x0001  /* MSI feature enabled */
 
259
#define  VBOX_PCI_MSI_FLAGS_64BIT    0x0080  /* 64-bit addresses allowed */
 
260
#define  VBOX_PCI_MSI_FLAGS_MASKBIT  0x0100  /* Per-vector masking support */
 
261
/* Encoding for 3-bit patterns for message queue (per chapter 6.8.1 of PCI spec),
 
262
   someone very similar to log_2().
 
263
   000 1
 
264
   001 2
 
265
   010 4
 
266
   011 8
 
267
   100 16
 
268
   101 32
 
269
   110 Reserved
 
270
   111 Reserved */
 
271
#define  VBOX_PCI_MSI_FLAGS_QSIZE    0x0070  /* Message queue size configured (i.e. vectors per device allocated) */
 
272
#define  VBOX_PCI_MSI_FLAGS_QMASK    0x000e  /* Maximum queue size available (i.e. vectors per device possible) */
 
273
 
 
274
/* MSI-X flags (2 bytes, capability offset 2) */
 
275
#define  VBOX_PCI_MSIX_FLAGS_ENABLE   0x8000  /* MSI-X enable */
 
276
#define  VBOX_PCI_MSIX_FLAGS_FUNCMASK 0x4000  /* Function mask */
 
277
 
 
278
/* Power management flags (2 bytes, capability offset 2) */
 
279
#define  VBOX_PCI_PM_CAP_VER_MASK    0x0007  /* Version mask */
 
280
#define  VBOX_PCI_PM_CAP_PME_CLOCK   0x0008  /* PME clock required */
 
281
#define  VBOX_PCI_PM_CAP_RESERVED    0x0010  /* Reserved field */
 
282
#define  VBOX_PCI_PM_CAP_DSI         0x0020  /* Device specific initialization */
 
283
#define  VBOX_PCI_PM_CAP_AUX_POWER   0x01C0  /* Auxilliary power support mask */
 
284
#define  VBOX_PCI_PM_CAP_D1          0x0200  /* D1 power state support */
 
285
#define  VBOX_PCI_PM_CAP_D2          0x0400  /* D2 power state support */
 
286
#define  VBOX_PCI_PM_CAP_PME         0x0800  /* PME pin supported */
 
287
#define  VBOX_PCI_PM_CAP_PME_MASK    0xF800  /* PME Mask of all supported states */
 
288
#define  VBOX_PCI_PM_CAP_PME_D0      0x0800  /* PME# from D0 */
 
289
#define  VBOX_PCI_PM_CAP_PME_D1      0x1000  /* PME# from D1 */
 
290
#define  VBOX_PCI_PM_CAP_PME_D2      0x2000  /* PME# from D2 */
 
291
#define  VBOX_PCI_PM_CAP_PME_D3      0x4000  /* PME# from D3 (hot) */
 
292
#define  VBOX_PCI_PM_CAP_PME_D3cold  0x8000  /* PME# from D3 (cold) */
 
293
 
 
294
/* Power management control flags (2 bytes, capability offset 4) */
 
295
#define  VBOX_PCI_PM_CTRL_STATE_MASK         0x0003  /* Current power state (D0 to D3) */
 
296
#define  VBOX_PCI_PM_CTRL_NO_SOFT_RESET      0x0008  /* No reset for D3hot->D0 */
 
297
#define  VBOX_PCI_PM_CTRL_PME_ENABLE         0x0100  /* PME pin enable */
 
298
#define  VBOX_PCI_PM_CTRL_DATA_SEL_MASK      0x1e00  /* Data select (??) */
 
299
#define  VBOX_PCI_PM_CTRL_DATA_SCALE_MASK    0x6000  /* Data scale (??) */
 
300
#define  VBOX_PCI_PM_CTRL_PME_STATUS         0x8000  /* PME pin status */
 
301
 
 
302
/* PCI-X config flags (2 bytes, capability offset 2) */
 
303
#define  VBOX_PCI_X_CMD_DPERR_E      0x0001  /* Data Parity Error Recovery Enable */
 
304
#define  VBOX_PCI_X_CMD_ERO          0x0002  /* Enable Relaxed Ordering */
 
305
#define  VBOX_PCI_X_CMD_MAX_OUTSTANDING_SPLIT_TRANS          0x0070
 
306
#define  VBOX_PCI_X_CMD_READ_512     0x0000  /* 512 byte maximum read byte count */
 
307
#define  VBOX_PCI_X_CMD_READ_1K      0x0004  /* 1Kbyte maximum read byte count */
 
308
#define  VBOX_PCI_X_CMD_READ_2K      0x0008  /* 2Kbyte maximum read byte count */
 
309
#define  VBOX_PCI_X_CMD_READ_4K      0x000c  /* 4Kbyte maximum read byte count */
 
310
#define  VBOX_PCI_X_CMD_MAX_READ     0x000c  /* Max Memory Read Byte Count */
 
311
 
 
312
/* PCI-X config flags (4 bytes, capability offset 4) */
 
313
#define  VBOX_PCI_X_STATUS_DEVFN     0x000000ff      /* A copy of devfn */
 
314
#define  VBOX_PCI_X_STATUS_BUS       0x0000ff00      /* A copy of bus nr */
 
315
#define  VBOX_PCI_X_STATUS_64BIT     0x00010000      /* 64-bit device */
 
316
#define  VBOX_PCI_X_STATUS_133MHZ    0x00020000      /* 133 MHz capable */
 
317
#define  VBOX_PCI_X_STATUS_SPL_DISC  0x00040000      /* Split Completion Discarded */
 
318
#define  VBOX_PCI_X_STATUS_UNX_SPL   0x00080000      /* Unexpected Split Completion */
 
319
#define  VBOX_PCI_X_STATUS_COMPLEX   0x00100000      /* Device Complexity, 0 = simple device, 1 = bridge device */
 
320
#define  VBOX_PCI_X_STATUS_MAX_READ  0x00600000      /* Designed Max Memory Read Count, 0 = 512 bytes, 1 = 1024, 2 = 2048, 3 = 4096 */
 
321
#define  VBOX_PCI_X_STATUS_MAX_SPLIT 0x03800000      /* Designed Max Outstanding Split Transactions */
 
322
#define  VBOX_PCI_X_STATUS_MAX_CUM   0x1c000000      /* Designed Max Cumulative Read Size */
 
323
#define  VBOX_PCI_X_STATUS_SPL_ERR   0x20000000      /* Rcvd Split Completion Error Msg */
 
324
#define  VBOX_PCI_X_STATUS_266MHZ    0x40000000      /* 266 MHz capable */
 
325
#define  VBOX_PCI_X_STATUS_533MHZ    0x80000000      /* 533 MHz capable */
 
326
 
 
327
/* PCI Express config flags (2 bytes, capability offset 2) */
 
328
#define  VBOX_PCI_EXP_FLAGS_VERS        0x000f  /* Capability version */
 
329
#define  VBOX_PCI_EXP_FLAGS_TYPE        0x00f0  /* Device/Port type */
 
330
#define  VBOX_PCI_EXP_TYPE_ENDPOINT     0x0     /* Express Endpoint */
 
331
#define  VBOX_PCI_EXP_TYPE_LEG_END      0x1     /* Legacy Endpoint */
 
332
#define  VBOX_PCI_EXP_TYPE_ROOT_PORT    0x4     /* Root Port */
 
333
#define  VBOX_PCI_EXP_TYPE_UPSTREAM     0x5     /* Upstream Port */
 
334
#define  VBOX_PCI_EXP_TYPE_DOWNSTREAM   0x6     /* Downstream Port */
 
335
#define  VBOX_PCI_EXP_TYPE_PCI_BRIDGE   0x7     /* PCI/PCI-X Bridge */
 
336
#define  VBOX_PCI_EXP_TYPE_PCIE_BRIDGE  0x8     /* PCI/PCI-X to PCIE Bridge */
 
337
#define  VBOX_PCI_EXP_TYPE_ROOT_INT_EP  0x9     /* Root Complex Integrated Endpoint */
 
338
#define  VBOX_PCI_EXP_TYPE_ROOT_EC      0xa     /* Root Complex Event Collector */
 
339
#define  VBOX_PCI_EXP_FLAGS_SLOT        0x0100  /* Slot implemented */
 
340
#define  VBOX_PCI_EXP_FLAGS_IRQ         0x3e00  /* Interrupt message number */
 
341
 
 
342
/* PCI Express device capabilities (4 bytes, capability offset 4) */
 
343
#define  VBOX_PCI_EXP_DEVCAP_PAYLOAD 0x07        /* Max_Payload_Size */
 
344
#define  VBOX_PCI_EXP_DEVCAP_PHANTOM 0x18        /* Phantom functions */
 
345
#define  VBOX_PCI_EXP_DEVCAP_EXT_TAG 0x20        /* Extended tags */
 
346
#define  VBOX_PCI_EXP_DEVCAP_L0S     0x1c0       /* L0s Acceptable Latency */
 
347
#define  VBOX_PCI_EXP_DEVCAP_L1      0xe00       /* L1 Acceptable Latency */
 
348
#define  VBOX_PCI_EXP_DEVCAP_ATN_BUT 0x1000      /* Attention Button Present */
 
349
#define  VBOX_PCI_EXP_DEVCAP_ATN_IND 0x2000      /* Attention Indicator Present */
 
350
#define  VBOX_PCI_EXP_DEVCAP_PWR_IND 0x4000      /* Power Indicator Present */
 
351
#define  VBOX_PCI_EXP_DEVCAP_RBE     0x8000      /* Role-Based Error Reporting */
 
352
#define  VBOX_PCI_EXP_DEVCAP_PWR_VAL 0x3fc0000   /* Slot Power Limit Value */
 
353
#define  VBOX_PCI_EXP_DEVCAP_PWR_SCL 0xc000000   /* Slot Power Limit Scale */
 
354
#define  VBOX_PCI_EXP_DEVCAP_FLRESET 0x10000000  /* Function-Level Reset */
 
355
 
 
356
/* PCI Express device control (2 bytes, capability offset 8) */
 
357
#define  VBOX_PCI_EXP_DEVCTL_CERE    0x0001      /* Correctable Error Reporting En. */
 
358
#define  VBOX_PCI_EXP_DEVCTL_NFERE   0x0002      /* Non-Fatal Error Reporting Enable */
 
359
#define  VBOX_PCI_EXP_DEVCTL_FERE    0x0004      /* Fatal Error Reporting Enable */
 
360
#define  VBOX_PCI_EXP_DEVCTL_URRE    0x0008      /* Unsupported Request Reporting En. */
 
361
#define  VBOX_PCI_EXP_DEVCTL_RELAXED 0x0010      /* Enable Relaxed Ordering */
 
362
#define  VBOX_PCI_EXP_DEVCTL_PAYLOAD 0x00e0      /* Max_Payload_Size */
 
363
#define  VBOX_PCI_EXP_DEVCTL_EXT_TAG 0x0100      /* Extended Tag Field Enable */
 
364
#define  VBOX_PCI_EXP_DEVCTL_PHANTOM 0x0200      /* Phantom Functions Enable */
 
365
#define  VBOX_PCI_EXP_DEVCTL_AUX_PME 0x0400      /* Auxiliary Power PM Enable */
 
366
#define  VBOX_PCI_EXP_DEVCTL_NOSNOOP 0x0800      /* Enable No Snoop */
 
367
#define  VBOX_PCI_EXP_DEVCTL_READRQ  0x7000      /* Max_Read_Request_Size */
 
368
#define  VBOX_PCI_EXP_DEVCTL_BCRE    0x8000      /* Bridge Configuration Retry Enable */
 
369
#define  VBOX_PCI_EXP_DEVCTL_FLRESET 0x8000      /* Function-Level Reset [bit shared with BCRE] */
 
370
 
 
371
/* PCI Express device status (2 bytes, capability offset 10) */
 
372
#define  VBOX_PCI_EXP_DEVSTA_CED     0x01         /* Correctable Error Detected */
 
373
#define  VBOX_PCI_EXP_DEVSTA_NFED    0x02         /* Non-Fatal Error Detected */
 
374
#define  VBOX_PCI_EXP_DEVSTA_FED     0x04         /* Fatal Error Detected */
 
375
#define  VBOX_PCI_EXP_DEVSTA_URD     0x08         /* Unsupported Request Detected */
 
376
#define  VBOX_PCI_EXP_DEVSTA_AUXPD   0x10         /* AUX Power Detected */
 
377
#define  VBOX_PCI_EXP_DEVSTA_TRPND   0x20         /* Transactions Pending */
 
378
 
 
379
/* PCI Express link capabilities (4 bytes, capability offset 12) */
 
380
#define  VBOX_PCI_EXP_LNKCAP_SPEED   0x0000f       /* Maximum Link Speed */
 
381
#define  VBOX_PCI_EXP_LNKCAP_WIDTH   0x003f0       /* Maximum Link Width */
 
382
#define  VBOX_PCI_EXP_LNKCAP_ASPM    0x00c00       /* Active State Power Management */
 
383
#define  VBOX_PCI_EXP_LNKCAP_L0S     0x07000       /* L0s Acceptable Latency */
 
384
#define  VBOX_PCI_EXP_LNKCAP_L1      0x38000       /* L1 Acceptable Latency */
 
385
#define  VBOX_PCI_EXP_LNKCAP_CLOCKPM 0x40000       /* Clock Power Management */
 
386
#define  VBOX_PCI_EXP_LNKCAP_SURPRISE 0x80000      /* Surprise Down Error Reporting */
 
387
#define  VBOX_PCI_EXP_LNKCAP_DLLA    0x100000      /* Data Link Layer Active Reporting */
 
388
#define  VBOX_PCI_EXP_LNKCAP_LBNC    0x200000      /* Link Bandwidth Notification Capability */
 
389
#define  VBOX_PCI_EXP_LNKCAP_PORT    0xff000000    /* Port Number */
 
390
 
 
391
/* PCI Express link control (2 bytes, capability offset 16) */
 
392
#define  VBOX_PCI_EXP_LNKCTL_ASPM    0x0003        /* ASPM Control */
 
393
#define  VBOX_PCI_EXP_LNKCTL_RCB     0x0008        /* Read Completion Boundary */
 
394
#define  VBOX_PCI_EXP_LNKCTL_DISABLE 0x0010        /* Link Disable */
 
395
#define  VBOX_PCI_EXP_LNKCTL_RETRAIN 0x0020        /* Retrain Link */
 
396
#define  VBOX_PCI_EXP_LNKCTL_CLOCK   0x0040        /* Common Clock Configuration */
 
397
#define  VBOX_PCI_EXP_LNKCTL_XSYNCH  0x0080        /* Extended Synch */
 
398
#define  VBOX_PCI_EXP_LNKCTL_CLOCKPM 0x0100        /* Clock Power Management */
 
399
#define  VBOX_PCI_EXP_LNKCTL_HWAUTWD 0x0200        /* Hardware Autonomous Width Disable */
 
400
#define  VBOX_PCI_EXP_LNKCTL_BWMIE   0x0400        /* Bandwidth Mgmt Interrupt Enable */
 
401
#define  VBOX_PCI_EXP_LNKCTL_AUTBWIE 0x0800        /* Autonomous Bandwidth Mgmt Interrupt Enable */
 
402
 
 
403
/* PCI Express link status (2 bytes, capability offset 18) */
 
404
#define  VBOX_PCI_EXP_LNKSTA_SPEED   0x000f        /* Negotiated Link Speed */
 
405
#define  VBOX_PCI_EXP_LNKSTA_WIDTH   0x03f0        /* Negotiated Link Width */
 
406
#define  VBOX_PCI_EXP_LNKSTA_TR_ERR  0x0400        /* Training Error (obsolete) */
 
407
#define  VBOX_PCI_EXP_LNKSTA_TRAIN   0x0800        /* Link Training */
 
408
#define  VBOX_PCI_EXP_LNKSTA_SL_CLK  0x1000        /* Slot Clock Configuration */
 
409
#define  VBOX_PCI_EXP_LNKSTA_DL_ACT  0x2000        /* Data Link Layer in DL_Active State */
 
410
#define  VBOX_PCI_EXP_LNKSTA_BWMGMT  0x4000        /* Bandwidth Mgmt Status */
 
411
#define  VBOX_PCI_EXP_LNKSTA_AUTBW   0x8000        /* Autonomous Bandwidth Mgmt Status */
 
412
 
 
413
/* PCI Express slot capabilities (4 bytes, capability offset 20) */
 
414
#define  VBOX_PCI_EXP_SLTCAP_ATNB    0x0001        /* Attention Button Present */
 
415
#define  VBOX_PCI_EXP_SLTCAP_PWRC    0x0002        /* Power Controller Present */
 
416
#define  VBOX_PCI_EXP_SLTCAP_MRL     0x0004        /* MRL Sensor Present */
 
417
#define  VBOX_PCI_EXP_SLTCAP_ATNI    0x0008        /* Attention Indicator Present */
 
418
#define  VBOX_PCI_EXP_SLTCAP_PWRI    0x0010        /* Power Indicator Present */
 
419
#define  VBOX_PCI_EXP_SLTCAP_HPS     0x0020        /* Hot-Plug Surprise */
 
420
#define  VBOX_PCI_EXP_SLTCAP_HPC     0x0040        /* Hot-Plug Capable */
 
421
#define  VBOX_PCI_EXP_SLTCAP_PWR_VAL 0x00007f80    /* Slot Power Limit Value */
 
422
#define  VBOX_PCI_EXP_SLTCAP_PWR_SCL 0x00018000    /* Slot Power Limit Scale */
 
423
#define  VBOX_PCI_EXP_SLTCAP_INTERLOCK 0x020000    /* Electromechanical Interlock Present */
 
424
#define  VBOX_PCI_EXP_SLTCAP_NOCMDCOMP 0x040000    /* No Command Completed Support */
 
425
#define  VBOX_PCI_EXP_SLTCAP_PSN     0xfff80000    /* Physical Slot Number */
 
426
 
 
427
/* PCI Express slot control (2 bytes, capability offset 24) */
 
428
#define  VBOX_PCI_EXP_SLTCTL_ATNB    0x0001        /* Attention Button Pressed Enable */
 
429
#define  VBOX_PCI_EXP_SLTCTL_PWRF    0x0002        /* Power Fault Detected Enable */
 
430
#define  VBOX_PCI_EXP_SLTCTL_MRLS    0x0004        /* MRL Sensor Changed Enable */
 
431
#define  VBOX_PCI_EXP_SLTCTL_PRSD    0x0008        /* Presence Detect Changed Enable */
 
432
#define  VBOX_PCI_EXP_SLTCTL_CMDC    0x0010        /* Command Completed Interrupt Enable */
 
433
#define  VBOX_PCI_EXP_SLTCTL_HPIE    0x0020        /* Hot-Plug Interrupt Enable */
 
434
#define  VBOX_PCI_EXP_SLTCTL_ATNI    0x00c0        /* Attention Indicator Control */
 
435
#define  VBOX_PCI_EXP_SLTCTL_PWRI    0x0300        /* Power Indicator Control */
 
436
#define  VBOX_PCI_EXP_SLTCTL_PWRC    0x0400        /* Power Controller Control */
 
437
#define  VBOX_PCI_EXP_SLTCTL_INTERLOCK 0x0800      /* Electromechanical Interlock Control */
 
438
#define  VBOX_PCI_EXP_SLTCTL_LLCHG   0x1000        /* Data Link Layer State Changed Enable */
 
439
 
 
440
/* PCI Express slot status (2 bytes, capability offset 26) */
 
441
#define  VBOX_PCI_EXP_SLTSTA_ATNB    0x0001        /* Attention Button Pressed */
 
442
#define  VBOX_PCI_EXP_SLTSTA_PWRF    0x0002        /* Power Fault Detected */
 
443
#define  VBOX_PCI_EXP_SLTSTA_MRLS    0x0004        /* MRL Sensor Changed */
 
444
#define  VBOX_PCI_EXP_SLTSTA_PRSD    0x0008        /* Presence Detect Changed */
 
445
#define  VBOX_PCI_EXP_SLTSTA_CMDC    0x0010        /* Command Completed */
 
446
#define  VBOX_PCI_EXP_SLTSTA_MRL_ST  0x0020        /* MRL Sensor State */
 
447
#define  VBOX_PCI_EXP_SLTSTA_PRES    0x0040        /* Presence Detect State */
 
448
#define  VBOX_PCI_EXP_SLTSTA_INTERLOCK 0x0080      /* Electromechanical Interlock Status */
 
449
#define  VBOX_PCI_EXP_SLTSTA_LLCHG   0x0100        /* Data Link Layer State Changed */
 
450
 
 
451
/* PCI Express root control (2 bytes, capability offset 28) */
 
452
#define  VBOX_PCI_EXP_RTCTL_SECEE    0x0001        /* System Error on Correctable Error */
 
453
#define  VBOX_PCI_EXP_RTCTL_SENFEE   0x0002        /* System Error on Non-Fatal Error */
 
454
#define  VBOX_PCI_EXP_RTCTL_SEFEE    0x0004        /* System Error on Fatal Error */
 
455
#define  VBOX_PCI_EXP_RTCTL_PMEIE    0x0008        /* PME Interrupt Enable */
 
456
#define  VBOX_PCI_EXP_RTCTL_CRSVIS   0x0010        /* Configuration Request Retry Status Visible to SW */
 
457
 
 
458
/* PCI Express root capabilities (2 bytes, capability offset 30) */
 
459
#define  VBOX_PCI_EXP_RTCAP_CRSVIS   0x0010        /* Configuration Request Retry Status Visible to SW */
 
460
 
 
461
/* PCI Express root status (4 bytes, capability offset 32) */
 
462
#define  VBOX_PCI_EXP_RTSTA_PME_REQID   0x0000ffff /* PME Requester ID */
 
463
#define  VBOX_PCI_EXP_RTSTA_PME_STATUS  0x00010000 /* PME Status */
 
464
#define  VBOX_PCI_EXP_RTSTA_PME_PENDING 0x00020000 /* PME is Pending */
 
465
 
 
466
 
144
467
/**
145
468
 * Callback function for reading from the PCI configuration space.
146
469
 *
147
470
 * @returns The register value.
148
471
 * @param   pPciDev         Pointer to PCI device. Use pPciDev->pDevIns to get the device instance.
149
 
 * @param   Address         The configuration space register address. [0..255]
 
472
 * @param   Address         The configuration space register address. [0..4096]
150
473
 * @param   cb              The register size. [1,2,4]
151
474
 */
152
475
typedef DECLCALLBACK(uint32_t) FNPCICONFIGREAD(PPCIDEVICE pPciDev, uint32_t Address, unsigned cb);
159
482
 * Callback function for writing to the PCI configuration space.
160
483
 *
161
484
 * @param   pPciDev         Pointer to PCI device. Use pPciDev->pDevIns to get the device instance.
162
 
 * @param   Address         The configuration space register address. [0..255]
 
485
 * @param   Address         The configuration space register address. [0..4096]
163
486
 * @param   u32Value        The value that's being written. The number of bits actually used from
164
487
 *                          this value is determined by the cb parameter.
165
488
 * @param   cb              The register size. [1,2,4]
171
494
typedef PFNPCICONFIGWRITE *PPFNPCICONFIGWRITE;
172
495
 
173
496
/** Fixed I/O region number for ROM. */
174
 
#define PCI_ROM_SLOT 6
 
497
#define PCI_ROM_SLOT    6
 
498
#define VBOX_PCI_ROM_SLOT    6
175
499
/** Max number of I/O regions. */
176
500
#define PCI_NUM_REGIONS 7
 
501
#define VBOX_PCI_NUM_REGIONS 7
177
502
 
178
503
/*
179
504
 * Hack to include the PCIDEVICEINT structure at the right place
197
522
#ifdef PCIDEVICEINT_DECLARED
198
523
        PCIDEVICEINT        s;
199
524
#endif
200
 
        char                padding[256];
 
525
        char                padding[288];
201
526
    } Int;
202
527
 
203
528
    /** Read only data.
213
538
    /**  @} */
214
539
} PCIDEVICE;
215
540
 
 
541
/* @todo: handle extended space access */
 
542
DECLINLINE(void)     PCIDevSetByte(PPCIDEVICE pPciDev, uint32_t uOffset, uint8_t u8Value)
 
543
{
 
544
    pPciDev->config[uOffset]   = u8Value;
 
545
}
 
546
 
 
547
DECLINLINE(uint8_t)  PCIDevGetByte(PPCIDEVICE pPciDev, uint32_t uOffset)
 
548
{
 
549
    return pPciDev->config[uOffset];
 
550
}
 
551
 
 
552
DECLINLINE(void)     PCIDevSetWord(PPCIDEVICE pPciDev, uint32_t uOffset, uint16_t u16Value)
 
553
{
 
554
    *(uint16_t*)&pPciDev->config[uOffset] = RT_H2LE_U16(u16Value);
 
555
}
 
556
 
 
557
DECLINLINE(uint16_t) PCIDevGetWord(PPCIDEVICE pPciDev, uint32_t uOffset)
 
558
{
 
559
    uint16_t u16Value = *(uint16_t*)&pPciDev->config[uOffset];
 
560
    return RT_H2LE_U16(u16Value);
 
561
}
 
562
 
 
563
DECLINLINE(void)     PCIDevSetDWord(PPCIDEVICE pPciDev, uint32_t uOffset, uint32_t u32Value)
 
564
{
 
565
    *(uint32_t*)&pPciDev->config[uOffset] = RT_H2LE_U32(u32Value);
 
566
}
 
567
 
 
568
DECLINLINE(uint32_t) PCIDevGetDWord(PPCIDEVICE pPciDev, uint32_t uOffset)
 
569
{
 
570
    uint32_t u32Value = *(uint32_t*)&pPciDev->config[uOffset];
 
571
    return RT_H2LE_U32(u32Value);
 
572
}
 
573
 
 
574
DECLINLINE(void)     PCIDevSetQWord(PPCIDEVICE pPciDev, uint32_t uOffset, uint64_t u64Value)
 
575
{
 
576
    *(uint64_t*)&pPciDev->config[uOffset] = RT_H2LE_U64(u64Value);
 
577
}
 
578
 
 
579
DECLINLINE(uint64_t) PCIDevGetQWord(PPCIDEVICE pPciDev, uint32_t uOffset)
 
580
{
 
581
    uint64_t u64Value = *(uint64_t*)&pPciDev->config[uOffset];
 
582
    return RT_H2LE_U64(u64Value);
 
583
}
216
584
 
217
585
/**
218
586
 * Sets the vendor id config register.
221
589
 */
222
590
DECLINLINE(void) PCIDevSetVendorId(PPCIDEVICE pPciDev, uint16_t u16VendorId)
223
591
{
224
 
    u16VendorId = RT_H2LE_U16(u16VendorId);
225
 
    pPciDev->config[VBOX_PCI_VENDOR_ID]     = u16VendorId & 0xff;
226
 
    pPciDev->config[VBOX_PCI_VENDOR_ID + 1] = u16VendorId >> 8;
 
592
    PCIDevSetWord(pPciDev, VBOX_PCI_VENDOR_ID, u16VendorId);
227
593
}
228
594
 
229
595
/**
233
599
 */
234
600
DECLINLINE(uint16_t) PCIDevGetVendorId(PPCIDEVICE pPciDev)
235
601
{
236
 
    return RT_LE2H_U16(RT_MAKE_U16(pPciDev->config[VBOX_PCI_VENDOR_ID], pPciDev->config[VBOX_PCI_VENDOR_ID + 1]));
 
602
    return PCIDevGetWord(pPciDev, VBOX_PCI_VENDOR_ID);
237
603
}
238
604
 
239
605
 
244
610
 */
245
611
DECLINLINE(void) PCIDevSetDeviceId(PPCIDEVICE pPciDev, uint16_t u16DeviceId)
246
612
{
247
 
    u16DeviceId = RT_H2LE_U16(u16DeviceId);
248
 
    pPciDev->config[VBOX_PCI_DEVICE_ID]     = u16DeviceId & 0xff;
249
 
    pPciDev->config[VBOX_PCI_DEVICE_ID + 1] = u16DeviceId >> 8;
 
613
    PCIDevSetWord(pPciDev, VBOX_PCI_DEVICE_ID, u16DeviceId);
250
614
}
251
615
 
252
616
/**
256
620
 */
257
621
DECLINLINE(uint16_t) PCIDevGetDeviceId(PPCIDEVICE pPciDev)
258
622
{
259
 
    return RT_LE2H_U16(RT_MAKE_U16(pPciDev->config[VBOX_PCI_DEVICE_ID], pPciDev->config[VBOX_PCI_DEVICE_ID + 1]));
 
623
    return PCIDevGetWord(pPciDev, VBOX_PCI_DEVICE_ID);
260
624
}
261
625
 
262
 
 
263
626
/**
264
627
 * Sets the command config register.
265
628
 *
268
631
 */
269
632
DECLINLINE(void) PCIDevSetCommand(PPCIDEVICE pPciDev, uint16_t u16Command)
270
633
{
271
 
    u16Command = RT_H2LE_U16(u16Command);
272
 
    pPciDev->config[VBOX_PCI_COMMAND]     = u16Command & 0xff;
273
 
    pPciDev->config[VBOX_PCI_COMMAND + 1] = u16Command >> 8;
 
634
    PCIDevSetWord(pPciDev, VBOX_PCI_COMMAND, u16Command);
274
635
}
275
636
 
276
637
 
281
642
 */
282
643
DECLINLINE(uint16_t) PCIDevGetCommand(PPCIDEVICE pPciDev)
283
644
{
284
 
    return RT_LE2H_U16(RT_MAKE_U16(pPciDev->config[VBOX_PCI_COMMAND], pPciDev->config[VBOX_PCI_COMMAND + 1]));
285
 
}
286
 
 
 
645
    return PCIDevGetWord(pPciDev, VBOX_PCI_COMMAND);
 
646
}
 
647
 
 
648
/**
 
649
 * Checks if INTx interrupts disabled in the command config register.
 
650
 * @returns true if disabled.
 
651
 * @param   pPciDev         The PCI device.
 
652
 */
 
653
DECLINLINE(bool) PCIDevIsIntxDisabled(PPCIDEVICE pPciDev)
 
654
{
 
655
    return (PCIDevGetCommand(pPciDev) & VBOX_PCI_COMMAND_INTX_DISABLE) != 0;
 
656
}
 
657
 
 
658
/**
 
659
 * Gets the status config register.
 
660
 *
 
661
 * @returns status config register.
 
662
 * @param   pPciDev         The PCI device.
 
663
 */
 
664
DECLINLINE(uint16_t) PCIDevGetStatus(PPCIDEVICE pPciDev)
 
665
{
 
666
    return PCIDevGetWord(pPciDev, VBOX_PCI_STATUS);
 
667
}
287
668
 
288
669
/**
289
670
 * Sets the status config register.
293
674
 */
294
675
DECLINLINE(void) PCIDevSetStatus(PPCIDEVICE pPciDev, uint16_t u16Status)
295
676
{
296
 
    u16Status = RT_H2LE_U16(u16Status);
297
 
    pPciDev->config[VBOX_PCI_STATUS]     = u16Status & 0xff;
298
 
    pPciDev->config[VBOX_PCI_STATUS + 1] = u16Status >> 8;
 
677
    PCIDevSetWord(pPciDev, VBOX_PCI_STATUS, u16Status);
299
678
}
300
679
 
301
680
 
307
686
 */
308
687
DECLINLINE(void) PCIDevSetRevisionId(PPCIDEVICE pPciDev, uint8_t u8RevisionId)
309
688
{
310
 
    pPciDev->config[VBOX_PCI_REVISION_ID] = u8RevisionId;
 
689
    PCIDevSetByte(pPciDev, VBOX_PCI_REVISION_ID, u8RevisionId);
311
690
}
312
691
 
313
692
 
319
698
 */
320
699
DECLINLINE(void) PCIDevSetClassProg(PPCIDEVICE pPciDev, uint8_t u8ClassProg)
321
700
{
322
 
    pPciDev->config[VBOX_PCI_CLASS_PROG] = u8ClassProg;
 
701
    PCIDevSetByte(pPciDev, VBOX_PCI_CLASS_PROG, u8ClassProg);
323
702
}
324
703
 
325
704
 
331
710
 */
332
711
DECLINLINE(void) PCIDevSetClassSub(PPCIDEVICE pPciDev, uint8_t u8SubClass)
333
712
{
334
 
    pPciDev->config[VBOX_PCI_CLASS_SUB] = u8SubClass;
 
713
    PCIDevSetByte(pPciDev, VBOX_PCI_CLASS_SUB, u8SubClass);
335
714
}
336
715
 
337
716
 
343
722
 */
344
723
DECLINLINE(void) PCIDevSetClassBase(PPCIDEVICE pPciDev, uint8_t u8BaseClass)
345
724
{
346
 
    pPciDev->config[VBOX_PCI_CLASS_BASE] = u8BaseClass;
 
725
    PCIDevSetByte(pPciDev, VBOX_PCI_CLASS_BASE, u8BaseClass);
347
726
}
348
727
 
349
 
 
350
728
/**
351
729
 * Sets the header type config register.
352
730
 *
355
733
 */
356
734
DECLINLINE(void) PCIDevSetHeaderType(PPCIDEVICE pPciDev, uint8_t u8HdrType)
357
735
{
358
 
    pPciDev->config[VBOX_PCI_HEADER_TYPE] = u8HdrType;
 
736
    PCIDevSetByte(pPciDev, VBOX_PCI_HEADER_TYPE, u8HdrType);
 
737
}
 
738
 
 
739
/**
 
740
 * Gets the header type config register.
 
741
 *
 
742
 * @param   pPciDev         The PCI device.
 
743
 * @returns u8HdrType       The header type.
 
744
 */
 
745
DECLINLINE(uint8_t) PCIDevGetHeaderType(PPCIDEVICE pPciDev)
 
746
{
 
747
    return PCIDevGetByte(pPciDev, VBOX_PCI_HEADER_TYPE);
 
748
}
 
749
 
 
750
/**
 
751
 * Sets the BIST (built-in self-test) config register.
 
752
 *
 
753
 * @param   pPciDev         The PCI device.
 
754
 * @param   u8Bist          The BIST value.
 
755
 */
 
756
DECLINLINE(void) PCIDevSetBIST(PPCIDEVICE pPciDev, uint8_t u8Bist)
 
757
{
 
758
    PCIDevSetByte(pPciDev, VBOX_PCI_BIST, u8Bist);
 
759
}
 
760
 
 
761
/**
 
762
 * Gets the BIST (built-in self-test) config register.
 
763
 *
 
764
 * @param   pPciDev         The PCI device.
 
765
 * @returns u8Bist          The BIST.
 
766
 */
 
767
DECLINLINE(uint8_t) PCIDevGetBIST(PPCIDEVICE pPciDev)
 
768
{
 
769
    return PCIDevGetByte(pPciDev, VBOX_PCI_BIST);
359
770
}
360
771
 
361
772
 
394
805
        default: AssertFailedReturnVoid();
395
806
    }
396
807
 
397
 
    u32Addr = RT_H2LE_U32(u32Addr);
398
 
    pPciDev->config[iReg]     = u32Addr         & 0xff;
399
 
    pPciDev->config[iReg + 1] = (u32Addr >>  8) & 0xff;
400
 
    pPciDev->config[iReg + 2] = (u32Addr >> 16) & 0xff;
401
 
    pPciDev->config[iReg + 3] = (u32Addr >> 24) & 0xff;
 
808
    PCIDevSetDWord(pPciDev, iReg, u32Addr);
402
809
}
403
810
 
404
811
 
410
817
 */
411
818
DECLINLINE(void) PCIDevSetSubSystemVendorId(PPCIDEVICE pPciDev, uint16_t u16SubSysVendorId)
412
819
{
413
 
    u16SubSysVendorId = RT_H2LE_U16(u16SubSysVendorId);
414
 
    pPciDev->config[VBOX_PCI_SUBSYSTEM_VENDOR_ID]     = u16SubSysVendorId & 0xff;
415
 
    pPciDev->config[VBOX_PCI_SUBSYSTEM_VENDOR_ID + 1] = u16SubSysVendorId >> 8;
 
820
    PCIDevSetWord(pPciDev, VBOX_PCI_SUBSYSTEM_VENDOR_ID, u16SubSysVendorId);
416
821
}
417
822
 
418
823
/**
422
827
 */
423
828
DECLINLINE(uint16_t) PCIDevGetSubSystemVendorId(PPCIDEVICE pPciDev)
424
829
{
425
 
    return RT_LE2H_U16(RT_MAKE_U16(pPciDev->config[VBOX_PCI_SUBSYSTEM_VENDOR_ID], pPciDev->config[VBOX_PCI_SUBSYSTEM_VENDOR_ID + 1]));
 
830
    return PCIDevGetWord(pPciDev, VBOX_PCI_SUBSYSTEM_VENDOR_ID);
426
831
}
427
832
 
428
833
 
434
839
 */
435
840
DECLINLINE(void) PCIDevSetSubSystemId(PPCIDEVICE pPciDev, uint16_t u16SubSystemId)
436
841
{
437
 
    u16SubSystemId = RT_H2LE_U16(u16SubSystemId);
438
 
    pPciDev->config[VBOX_PCI_SUBSYSTEM_ID]     = u16SubSystemId & 0xff;
439
 
    pPciDev->config[VBOX_PCI_SUBSYSTEM_ID + 1] = u16SubSystemId >> 8;
 
842
    PCIDevSetWord(pPciDev, VBOX_PCI_SUBSYSTEM_ID, u16SubSystemId);
440
843
}
441
844
 
442
845
/**
446
849
 */
447
850
DECLINLINE(uint16_t) PCIDevGetSubSystemId(PPCIDEVICE pPciDev)
448
851
{
449
 
    return RT_LE2H_U16(RT_MAKE_U16(pPciDev->config[VBOX_PCI_SUBSYSTEM_ID], pPciDev->config[VBOX_PCI_SUBSYSTEM_ID + 1]));
450
 
}
451
 
 
 
852
    return PCIDevGetWord(pPciDev, VBOX_PCI_SUBSYSTEM_ID);
 
853
}
 
854
 
 
855
/**
 
856
 * Sets offset to capability list.
 
857
 *
 
858
 * @param   pPciDev         The PCI device.
 
859
 * @param   u8Offset        The offset to capability list.
 
860
 */
 
861
DECLINLINE(void) PCIDevSetCapabilityList(PPCIDEVICE pPciDev, uint8_t u8Offset)
 
862
{
 
863
    PCIDevSetByte(pPciDev, VBOX_PCI_CAPABILITY_LIST, u8Offset);
 
864
}
 
865
 
 
866
/**
 
867
 * Returns offset to capability list.
 
868
 *
 
869
 * @returns offset to capability list.
 
870
 * @param   pPciDev         The PCI device.
 
871
 */
 
872
DECLINLINE(uint8_t) PCIDevGetCapabilityList(PPCIDEVICE pPciDev)
 
873
{
 
874
    return PCIDevGetByte(pPciDev, VBOX_PCI_CAPABILITY_LIST);
 
875
}
452
876
 
453
877
/**
454
878
 * Sets the interrupt line config register.
458
882
 */
459
883
DECLINLINE(void) PCIDevSetInterruptLine(PPCIDEVICE pPciDev, uint8_t u8Line)
460
884
{
461
 
    pPciDev->config[VBOX_PCI_INTERRUPT_LINE] = u8Line;
 
885
    PCIDevSetByte(pPciDev, VBOX_PCI_INTERRUPT_LINE, u8Line);
462
886
}
463
887
 
 
888
/**
 
889
 * Gets the interrupt line config register.
 
890
 *
 
891
 * @returns The interrupt line.
 
892
 * @param   pPciDev         The PCI device.
 
893
 */
 
894
DECLINLINE(uint8_t) PCIDevGetInterruptLine(PPCIDEVICE pPciDev)
 
895
{
 
896
    return PCIDevGetByte(pPciDev, VBOX_PCI_INTERRUPT_LINE);
 
897
}
464
898
 
465
899
/**
466
900
 * Sets the interrupt pin config register.
470
904
 */
471
905
DECLINLINE(void) PCIDevSetInterruptPin(PPCIDEVICE pPciDev, uint8_t u8Pin)
472
906
{
473
 
    pPciDev->config[VBOX_PCI_INTERRUPT_PIN] = u8Pin;
474
 
}
475
 
 
 
907
    PCIDevSetByte(pPciDev, VBOX_PCI_INTERRUPT_PIN, u8Pin);
 
908
}
 
909
 
 
910
/**
 
911
 * Gets the interrupt pin config register.
 
912
 *
 
913
 * @returns The interrupt pin.
 
914
 * @param   pPciDev         The PCI device.
 
915
 */
 
916
DECLINLINE(uint8_t) PCIDevGetInterruptPin(PPCIDEVICE pPciDev)
 
917
{
 
918
    return PCIDevGetByte(pPciDev, VBOX_PCI_INTERRUPT_PIN);
 
919
}
 
920
 
 
921
#ifdef PCIDEVICEINT_DECLARED
 
922
DECLINLINE(void) PCISetRequestedDevfunc(PPCIDEVICE pDev)
 
923
{
 
924
    pDev->Int.s.uFlags |= PCIDEV_FLAG_REQUESTED_DEVFUNC;
 
925
}
 
926
 
 
927
DECLINLINE(void) PCIClearRequestedDevfunc(PPCIDEVICE pDev)
 
928
{
 
929
    pDev->Int.s.uFlags &= ~PCIDEV_FLAG_REQUESTED_DEVFUNC;
 
930
}
 
931
 
 
932
DECLINLINE(bool) PCIIsRequestedDevfunc(PPCIDEVICE pDev)
 
933
{
 
934
    return (pDev->Int.s.uFlags & PCIDEV_FLAG_REQUESTED_DEVFUNC) != 0;
 
935
}
 
936
 
 
937
DECLINLINE(void) PCISetPci2PciBridge(PPCIDEVICE pDev)
 
938
{
 
939
    pDev->Int.s.uFlags |= PCIDEV_FLAG_PCI_TO_PCI_BRIDGE;
 
940
}
 
941
 
 
942
DECLINLINE(bool) PCIIsPci2PciBridge(PPCIDEVICE pDev)
 
943
{
 
944
    return (pDev->Int.s.uFlags & PCIDEV_FLAG_PCI_TO_PCI_BRIDGE) != 0;
 
945
}
 
946
 
 
947
DECLINLINE(void) PCISetPciExpress(PPCIDEVICE pDev)
 
948
{
 
949
    pDev->Int.s.uFlags |= PCIDEV_FLAG_PCI_EXPRESS_DEVICE;
 
950
}
 
951
 
 
952
DECLINLINE(bool) PCIIsPciExpress(PPCIDEVICE pDev)
 
953
{
 
954
    return (pDev->Int.s.uFlags & PCIDEV_FLAG_PCI_EXPRESS_DEVICE) != 0;
 
955
}
 
956
 
 
957
DECLINLINE(void) PCISetMsiCapable(PPCIDEVICE pDev)
 
958
{
 
959
    pDev->Int.s.uFlags |= PCIDEV_FLAG_MSI_CAPABLE;
 
960
}
 
961
 
 
962
DECLINLINE(void) PCIClearMsiCapable(PPCIDEVICE pDev)
 
963
{
 
964
    pDev->Int.s.uFlags &= ~PCIDEV_FLAG_MSI_CAPABLE;
 
965
}
 
966
 
 
967
DECLINLINE(bool) PCIIsMsiCapable(PPCIDEVICE pDev)
 
968
{
 
969
    return (pDev->Int.s.uFlags & PCIDEV_FLAG_MSI_CAPABLE) != 0;
 
970
}
 
971
 
 
972
DECLINLINE(void) PCISetMsixCapable(PPCIDEVICE pDev)
 
973
{
 
974
    pDev->Int.s.uFlags |= PCIDEV_FLAG_MSIX_CAPABLE;
 
975
}
 
976
 
 
977
DECLINLINE(void) PCIClearMsixCapable(PPCIDEVICE pDev)
 
978
{
 
979
    pDev->Int.s.uFlags &= ~PCIDEV_FLAG_MSIX_CAPABLE;
 
980
}
 
981
 
 
982
DECLINLINE(bool) PCIIsMsixCapable(PPCIDEVICE pDev)
 
983
{
 
984
    return (pDev->Int.s.uFlags & PCIDEV_FLAG_MSIX_CAPABLE) != 0;
 
985
}
 
986
#endif
 
987
 
 
988
#ifdef __cplusplus
 
989
struct PciBusAddress
 
990
{
 
991
    int  iBus;
 
992
    int  iDevice;
 
993
    int  iFn;
 
994
 
 
995
    PciBusAddress()
 
996
    {
 
997
        clear();
 
998
    }
 
999
 
 
1000
    PciBusAddress(int bus, int device, int fn)
 
1001
    {
 
1002
        init(bus, device, fn);
 
1003
    }
 
1004
 
 
1005
    PciBusAddress& clear()
 
1006
    {
 
1007
        iBus = iDevice = iFn = -1;
 
1008
        return *this;
 
1009
    }
 
1010
 
 
1011
    void init(int bus, int device, int fn)
 
1012
    {
 
1013
        iBus = bus;
 
1014
        iDevice = device;
 
1015
        iFn = fn;
 
1016
    }
 
1017
 
 
1018
    void init(const PciBusAddress &a)
 
1019
    {
 
1020
        iBus = a.iBus;
 
1021
        iDevice = a.iDevice;
 
1022
        iFn = a.iFn;
 
1023
    }
 
1024
 
 
1025
    bool operator<(const PciBusAddress &a) const
 
1026
    {
 
1027
        if (iBus < a.iBus)
 
1028
            return true;
 
1029
 
 
1030
        if (iBus > a.iBus)
 
1031
            return false;
 
1032
 
 
1033
        if (iDevice < a.iDevice)
 
1034
            return true;
 
1035
 
 
1036
        if (iDevice > a.iDevice)
 
1037
            return false;
 
1038
 
 
1039
        if (iFn < a.iFn)
 
1040
            return true;
 
1041
 
 
1042
        if (iFn > a.iFn)
 
1043
            return false;
 
1044
 
 
1045
        return false;
 
1046
    }
 
1047
 
 
1048
    bool operator==(const PciBusAddress &a) const
 
1049
    {
 
1050
        return     (iBus == a.iBus)
 
1051
                && (iDevice == a.iDevice)
 
1052
                && (iFn == a.iFn);
 
1053
    }
 
1054
 
 
1055
    bool operator!=(const PciBusAddress &a) const
 
1056
    {
 
1057
        return     (iBus != a.iBus)
 
1058
                || (iDevice != a.iDevice)
 
1059
                || (iFn  != a.iFn);
 
1060
    }
 
1061
 
 
1062
    bool valid() const
 
1063
    {
 
1064
        return (iBus != -1) && (iDevice != -1) && (iFn != -1);
 
1065
    }
 
1066
 
 
1067
    int32_t asLong() const
 
1068
    {
 
1069
        Assert(valid());
 
1070
        return (iBus << 8) | (iDevice << 3) | iFn;
 
1071
    }
 
1072
 
 
1073
    void fromLong(int32_t value)
 
1074
    {
 
1075
        iBus = (value >> 8) & 0xff;
 
1076
        iDevice = (value & 0xff) >> 3;
 
1077
        iFn = (value & 7);
 
1078
    }
 
1079
};
 
1080
#endif /* __cplusplus */
476
1081
 
477
1082
/** @} */
478
1083