VirtualBox

source: vbox/trunk/include/VBox/pci.h@ 6000

Last change on this file since 6000 was 5999, checked in by vboxsync, 17 years ago

The Giant CDDL Dual-License Header Change.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.4 KB
Line 
1/** @file
2 * PCI - The PCI Controller And Devices.
3 */
4
5/*
6 * Copyright (C) 2006-2007 innotek GmbH
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef ___VBox_pci_h
27#define ___VBox_pci_h
28
29#include <VBox/cdefs.h>
30#include <VBox/types.h>
31
32/** @defgroup grp_pci PCI - The PCI Controller.
33 * @{
34 */
35
36/** Pointer to a PCI device. */
37typedef struct PCIDevice *PPCIDEVICE;
38
39
40/**
41 * PCI configuration word 4 (command) and word 6 (status).
42 */
43typedef enum PCICONFIGCOMMAND
44{
45 /** Supports/uses memory accesses. */
46 PCI_COMMAND_IOACCESS = 0x0001,
47 PCI_COMMAND_MEMACCESS = 0x0002,
48 PCI_COMMAND_BUSMASTER = 0x0004
49} PCICONFIGCOMMAND;
50
51
52/**
53 * PCI Address space specification.
54 * This is used when registering a I/O region.
55 */
56typedef enum PCIADDRESSSPACE
57{
58 /** Memory. */
59 PCI_ADDRESS_SPACE_MEM = 0x00,
60 /** I/O space. */
61 PCI_ADDRESS_SPACE_IO = 0x01,
62 /** Prefetch memory. */
63 PCI_ADDRESS_SPACE_MEM_PREFETCH = 0x08
64} PCIADDRESSSPACE;
65
66
67/**
68 * Callback function for mapping an PCI I/O region.
69 *
70 * @return VBox status code.
71 * @param pPciDev Pointer to PCI device. Use pPciDev->pDevIns to get the device instance.
72 * @param iRegion The region number.
73 * @param GCPhysAddress Physical address of the region. If iType is PCI_ADDRESS_SPACE_IO, this is an
74 * I/O port, else it's a physical address.
75 * This address is *NOT* relative to pci_mem_base like earlier!
76 * @param enmType One of the PCI_ADDRESS_SPACE_* values.
77 */
78typedef DECLCALLBACK(int) FNPCIIOREGIONMAP(PPCIDEVICE pPciDev, /*unsigned*/ int iRegion, RTGCPHYS GCPhysAddress, uint32_t cb, PCIADDRESSSPACE enmType);
79/** Pointer to a FNPCIIOREGIONMAP() function. */
80typedef FNPCIIOREGIONMAP *PFNPCIIOREGIONMAP;
81
82
83/** @name PCI Configuration Space Registers
84 * @{ */
85#define VBOX_PCI_VENDOR_ID 0x00 /**< 16-bit RO */
86#define VBOX_PCI_DEVICE_ID 0x02 /**< 16-bit RO */
87#define VBOX_PCI_COMMAND 0x04 /**< 16-bit RW */
88#define VBOX_PCI_STATUS 0x06 /**< 16-bit RW */
89#define VBOX_PCI_REVISION_ID 0x08 /**< 8-bit RO */
90#define VBOX_PCI_CLASS_PROG 0x09 /**< 8-bit RO */
91#define VBOX_PCI_CLASS_DEVICE 0x0a /**< 8-bit ?? */
92#define VBOX_PCI_CACHE_LINE_SIZE 0x0c /**< 8-bit ?? */
93#define VBOX_PCI_LATENCY_TIMER 0x0d /**< 8-bit ?? */
94#define VBOX_PCI_HEADER_TYPE 0x0e /**< 8-bit ?? */
95#define VBOX_PCI_BIST 0x0f /**< 8-bit ?? */
96#define VBOX_PCI_BASE_ADDRESS_0 0x10 /**< 32-bit RW */
97#define VBOX_PCI_BASE_ADDRESS_1 0x14 /**< 32-bit RW */
98#define VBOX_PCI_BASE_ADDRESS_2 0x18 /**< 32-bit RW */
99#define VBOX_PCI_PRIMARY_BUS 0x18 /**< 8-bit ?? - bridge - primary bus number. */
100#define VBOX_PCI_SECONDARY_BUS 0x19 /**< 8-bit ?? - bridge - secondary bus number. */
101#define VBOX_PCI_SUBORDINATE_BUS 0x1a /**< 8-bit ?? - bridge - highest subordinate bus number. (behind the bridge) */
102#define VBOX_PCI_SEC_LATENCY_TIMER 0x1b /**< 8-bit ?? - bridge - secondary latency timer. */
103#define VBOX_PCI_BASE_ADDRESS_3 0x1c /**< 32-bit RW */
104#define VBOX_PCI_IO_BASE 0x1c /**< 8-bit ?? - bridge - I/O range base. */
105#define VBOX_PCI_IO_LIMIT 0x1d /**< 8-bit ?? - bridge - I/O range limit. */
106#define VBOX_PCI_SEC_STATUS 0x1e /**< 16-bit ?? - bridge - secondary status register. */
107#define VBOX_PCI_BASE_ADDRESS_4 0x20 /**< 32-bit RW */
108#define VBOX_PCI_MEMORY_BASE 0x20 /**< 16-bit ?? - bridge - memory range base. */
109#define VBOX_PCI_MEMORY_LIMIT 0x22 /**< 16-bit ?? - bridge - memory range limit. */
110#define VBOX_PCI_BASE_ADDRESS_5 0x24 /**< 32-bit RW */
111#define VBOX_PCI_PREF_MEMORY_BASE 0x24 /**< 16-bit ?? - bridge - Prefetchable memory range base. */
112#define VBOX_PCI_PREF_MEMORY_LIMIT 0x26 /**< 16-bit ?? - bridge - Prefetchable memory range limit. */
113#define VBOX_PCI_CARDBUS_CIS 0x28 /**< 32-bit ?? */
114#define VBOX_PCI_PREF_BASE_UPPER32 0x28 /**< 32-bit ?? - bridge - Prefetchable memory range high base.*/
115#define VBOX_PCI_PREF_LIMIT_UPPER32 0x2c /**< 32-bit ?? - bridge - Prefetchable memory range high limit. */
116#define VBOX_PCI_SUBSYSTEM_VENDOR_ID 0x2c /**< 16-bit ?? */
117#define VBOX_PCI_SUBSYSTEM_ID 0x2e /**< 16-bit ?? */
118#define VBOX_PCI_ROM_ADDRESS 0x30 /**< 32-bit ?? */
119#define VBOX_PCI_IO_BASE_UPPER16 0x30 /**< 16-bit ?? - bridge - memory range high base. */
120#define VBOX_PCI_IO_LIMIT_UPPER16 0x32 /**< 16-bit ?? - bridge - memory range high limit. */
121#define VBOX_PCI_CAPABILITY_LIST 0x34 /**< 8-bit? ?? */
122#define VBOX_PCI_ROM_ADDRESS_BR 0x38 /**< 32-bit ?? - bridge */
123#define VBOX_PCI_INTERRUPT_LINE 0x3c /**< 8-bit RW - Interrupt line. */
124#define VBOX_PCI_INTERRUPT_PIN 0x3d /**< 8-bit RO - Interrupt pin. */
125#define VBOX_PCI_MIN_GNT 0x3e /**< 8-bit ?? */
126#define VBOX_PCI_BRIDGE_CONTROL 0x3e /**< 8-bit? ?? - bridge */
127#define VBOX_PCI_MAX_LAT 0x3f /**< 8-bit ?? */
128/** @} */
129
130
131/**
132 * Callback function for reading from the PCI configuration space.
133 *
134 * @returns The register value.
135 * @param pPciDev Pointer to PCI device. Use pPciDev->pDevIns to get the device instance.
136 * @param Address The configuration space register address. [0..255]
137 * @param cb The register size. [1,2,4]
138 */
139typedef DECLCALLBACK(uint32_t) FNPCICONFIGREAD(PPCIDEVICE pPciDev, uint32_t Address, unsigned cb);
140/** Pointer to a FNPCICONFIGREAD() function. */
141typedef FNPCICONFIGREAD *PFNPCICONFIGREAD;
142/** Pointer to a PFNPCICONFIGREAD. */
143typedef PFNPCICONFIGREAD *PPFNPCICONFIGREAD;
144
145/**
146 * Callback function for writing to the PCI configuration space.
147 *
148 * @param pPciDev Pointer to PCI device. Use pPciDev->pDevIns to get the device instance.
149 * @param Address The configuration space register address. [0..255]
150 * @param u32Value The value that's being written. The number of bits actually used from
151 * this value is determined by the cb parameter.
152 * @param cb The register size. [1,2,4]
153 */
154typedef DECLCALLBACK(void) FNPCICONFIGWRITE(PPCIDEVICE pPciDev, uint32_t Address, uint32_t u32Value, unsigned cb);
155/** Pointer to a FNPCICONFIGWRITE() function. */
156typedef FNPCICONFIGWRITE *PFNPCICONFIGWRITE;
157/** Pointer to a PFNPCICONFIGWRITE. */
158typedef PFNPCICONFIGWRITE *PPFNPCICONFIGWRITE;
159
160/** Fixed I/O region number for ROM. */
161#define PCI_ROM_SLOT 6
162/** Max number of I/O regions. */
163#define PCI_NUM_REGIONS 7
164
165/*
166 * Hack to include the PCIDEVICEINT structure at the right place
167 * to avoid duplications of FNPCIIOREGIONMAP and PCI_NUM_REGIONS.
168 */
169#ifdef PCI_INCLUDE_PRIVATE
170# include "PCIInternal.h"
171#endif
172
173/**
174 * PCI Device structure.
175 */
176typedef struct PCIDevice
177{
178 /** PCI config space. */
179 uint8_t config[256];
180
181 /** Internal data. */
182 union
183 {
184#ifdef __PCIDEVICEINT_DECLARED__
185 PCIDEVICEINT s;
186#endif
187 char padding[224];
188 } Int;
189
190 /** Read only data.
191 * @{
192 */
193 /** PCI device number on the pci bus. */
194 int32_t devfn;
195 uint32_t Alignment0; /**< Alignment. */
196 /** Device name. */
197 R3PTRTYPE(const char *) name;
198 /** Pointer to the device instance which registered the device. */
199 PPDMDEVINSR3 pDevIns;
200 /** @} */
201} PCIDEVICE;
202
203
204/**
205 * Sets the vendor id config register.
206 * @param pPciDev The PCI device.
207 * @param u16VendorId The vendor id.
208 */
209DECLINLINE(void) PCIDevSetVendorId(PPCIDEVICE pPciDev, uint16_t u16VendorId)
210{
211 u16VendorId = RT_H2LE_U16(u16VendorId);
212 pPciDev->config[VBOX_PCI_VENDOR_ID] = u16VendorId & 0xff;
213 pPciDev->config[VBOX_PCI_VENDOR_ID + 1] = u16VendorId >> 8;
214}
215
216/**
217 * Gets the vendor id config register.
218 * @returns the vendor id.
219 * @param pPciDev The PCI device.
220 */
221DECLINLINE(uint16_t) PCIDevGetVendorId(PPCIDEVICE pPciDev)
222{
223 return RT_LE2H_U16(RT_MAKE_U16(pPciDev->config[VBOX_PCI_VENDOR_ID], pPciDev->config[VBOX_PCI_VENDOR_ID + 1]));
224}
225
226/**
227 * Sets the device id config register.
228 * @param pPciDev The PCI device.
229 * @param u16DeviceId The device id.
230 */
231DECLINLINE(void) PCIDevSetDeviceId(PPCIDEVICE pPciDev, uint16_t u16DeviceId)
232{
233 u16DeviceId = RT_H2LE_U16(u16DeviceId);
234 pPciDev->config[VBOX_PCI_DEVICE_ID] = u16DeviceId & 0xff;
235 pPciDev->config[VBOX_PCI_DEVICE_ID + 1] = u16DeviceId >> 8;
236}
237
238/**
239 * Gets the device id config register.
240 * @returns the device id.
241 * @param pPciDev The PCI device.
242 */
243DECLINLINE(uint16_t) PCIDevGetDeviceId(PPCIDEVICE pPciDev)
244{
245 return RT_LE2H_U16(RT_MAKE_U16(pPciDev->config[VBOX_PCI_DEVICE_ID], pPciDev->config[VBOX_PCI_DEVICE_ID + 1]));
246}
247
248/**
249 * Gets the sub-system vendor id config register.
250 * @returns the sub-system vendor id.
251 * @param pPciDev The PCI device.
252 */
253DECLINLINE(uint16_t) PCIDevGetSubSystemVendorId(PPCIDEVICE pPciDev)
254{
255 return RT_LE2H_U16(RT_MAKE_U16(pPciDev->config[VBOX_PCI_SUBSYSTEM_VENDOR_ID], pPciDev->config[VBOX_PCI_SUBSYSTEM_VENDOR_ID + 1]));
256}
257
258/**
259 * Gets the sub-system id config register.
260 * @returns the sub-system id.
261 * @param pPciDev The PCI device.
262 */
263DECLINLINE(uint16_t) PCIDevGetSubSystemId(PPCIDEVICE pPciDev)
264{
265 return RT_LE2H_U16(RT_MAKE_U16(pPciDev->config[VBOX_PCI_SUBSYSTEM_ID], pPciDev->config[VBOX_PCI_SUBSYSTEM_ID + 1]));
266}
267
268
269/** @} */
270
271#endif
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette