ReactOS 0.4.17-dev-934-g091855f
config.c File Reference
#include <pci.h>
#include <debug.h>
Include dependency graph for config.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

UCHAR NTAPI PciGetAdjustedInterruptLine (IN PPCI_PDO_EXTENSION PdoExtension)
 
VOID NTAPI PciReadWriteConfigSpace (IN PPCI_FDO_EXTENSION DeviceExtension, IN PCI_SLOT_NUMBER Slot, IN PVOID Buffer, IN ULONG Offset, IN ULONG Length, IN BOOLEAN Read)
 
VOID NTAPI PciWriteDeviceConfig (IN PPCI_PDO_EXTENSION DeviceExtension, IN PVOID Buffer, IN ULONG Offset, IN ULONG Length)
 
VOID NTAPI PciReadDeviceConfig (IN PPCI_PDO_EXTENSION DeviceExtension, IN PVOID Buffer, IN ULONG Offset, IN ULONG Length)
 
VOID NTAPI PciReadSlotConfig (IN PPCI_FDO_EXTENSION DeviceExtension, IN PCI_SLOT_NUMBER Slot, IN PVOID Buffer, IN ULONG Offset, IN ULONG Length)
 
NTSTATUS NTAPI PciQueryForPciBusInterface (IN PPCI_FDO_EXTENSION FdoExtension)
 
NTSTATUS NTAPI PciGetConfigHandlers (IN PPCI_FDO_EXTENSION FdoExtension)
 

Variables

BOOLEAN PciAssignBusNumbers
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file config.c.

Function Documentation

◆ PciGetAdjustedInterruptLine()

UCHAR NTAPI PciGetAdjustedInterruptLine ( IN PPCI_PDO_EXTENSION  PdoExtension)

Definition at line 24 of file config.c.

25{
26 UCHAR InterruptLine = 0, PciInterruptLine;
28
29 /* Does the device have an interrupt pin? */
30 if (PdoExtension->InterruptPin)
31 {
32 /* Find the associated line on the parent bus */
34 PdoExtension->ParentFdoExtension->BaseBus,
35 PdoExtension->Slot.u.AsULONG,
36 &PciInterruptLine,
38 u.type0.InterruptLine),
39 sizeof(UCHAR));
40 if (Length) InterruptLine = PciInterruptLine;
41 }
42
43 /* Either keep the original interrupt line, or the one on the master bus */
44 return InterruptLine ? PdoExtension->RawInterruptLine : InterruptLine;
45}
@ PdoExtension
Definition: precomp.h:49
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble * u
Definition: glfuncs.h:240
ULONG NTAPI HalGetBusDataByOffset(IN BUS_DATA_TYPE BusDataType, IN ULONG BusNumber, IN ULONG SlotNumber, IN PVOID Buffer, IN ULONG Offset, IN ULONG Length)
Definition: bus.c:73
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
@ PCIConfiguration
Definition: miniport.h:93
unsigned char UCHAR
Definition: typedefs.h:53
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
uint32_t ULONG
Definition: typedefs.h:59

Referenced by PciScanBus().

◆ PciGetConfigHandlers()

NTSTATUS NTAPI PciGetConfigHandlers ( IN PPCI_FDO_EXTENSION  FdoExtension)

Definition at line 266 of file config.c.

267{
268 PBUS_HANDLER BusHandler;
270 ASSERT(FdoExtension->BusHandler == NULL);
271
272 /* Check if this is the FDO for the root bus */
274 {
275 /* Query the PCI Bus Interface that ACPI exposes */
276 ASSERT(FdoExtension->PciBusInterface == NULL);
278 if (!NT_SUCCESS(Status))
279 {
280 /* No ACPI, so Bus Numbers should be maintained by BIOS */
282 }
283 else
284 {
285 /* ACPI detected, PCI Bus Driver will reconfigure bus numbers*/
287 }
288 }
289 else
290 {
291 /* Check if the root bus already has the interface set up */
292 if (FdoExtension->BusRootFdoExtension->PciBusInterface)
293 {
294 /* Nothing for this FDO to do */
295 return STATUS_SUCCESS;
296 }
297
298 /* Fail into case below so we can query the HAL interface */
300 }
301
302 /* If the ACPI PCI Bus Interface couldn't be obtained, try the HAL */
303 if (!NT_SUCCESS(Status))
304 {
305 /* Bus number assignment should be static */
308
309 /* Call the HAL to obtain the bus handler for PCI */
310 BusHandler = HalReferenceHandlerForBus(PCIBus, FdoExtension->BaseBus);
311 FdoExtension->BusHandler = BusHandler;
312
313 /* Fail if the HAL does not have a PCI Bus Handler for this bus */
314 if (!BusHandler) return STATUS_INVALID_DEVICE_REQUEST;
315 }
316
317 /* Appropriate interface was obtained */
318 return STATUS_SUCCESS;
319}
LONG NTSTATUS
Definition: precomp.h:26
#define STATUS_NOT_SUPPORTED
Definition: d3dkmdt.h:48
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
NTSTATUS NTAPI PciQueryForPciBusInterface(IN PPCI_FDO_EXTENSION FdoExtension)
Definition: config.c:177
BOOLEAN PciAssignBusNumbers
Definition: config.c:18
#define PCI_IS_ROOT_FDO(x)
Definition: pci.h:32
@ FdoExtension
Definition: precomp.h:48
Status
Definition: gdiplustypes.h:24
#define ASSERT(a)
Definition: mode.c:44
@ PCIBus
Definition: restypes.h:127
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define HalReferenceHandlerForBus
Definition: haltypes.h:307

Referenced by PciAddDevice().

◆ PciQueryForPciBusInterface()

NTSTATUS NTAPI PciQueryForPciBusInterface ( IN PPCI_FDO_EXTENSION  FdoExtension)

Definition at line 177 of file config.c.

178{
179 PDEVICE_OBJECT AttachedDevice;
183 PIRP Irp;
185 PPCI_BUS_INTERFACE_STANDARD PciInterface;
186 PAGED_CODE();
188
189 /* Allocate space for the interface */
190 PciInterface = ExAllocatePoolWithTag(NonPagedPool,
193 if (!PciInterface) return STATUS_INSUFFICIENT_RESOURCES;
194
195 /* Get the device the PDO is attached to, should be the Root (ACPI) */
196 AttachedDevice = IoGetAttachedDeviceReference(FdoExtension->PhysicalDeviceObject);
197
198 /* Build an IRP for this request */
201 AttachedDevice,
202 NULL,
203 0,
204 NULL,
205 &Event,
207 if (Irp)
208 {
209 /* Initialize the default PnP response */
210 Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
211 Irp->IoStatus.Information = 0;
212
213 /* Make it a Query Interface IRP */
217 IoStackLocation->Parameters.QueryInterface.InterfaceType = &GUID_PCI_BUS_INTERFACE_STANDARD;
220 IoStackLocation->Parameters.QueryInterface.Interface = (PINTERFACE)PciInterface;
221 IoStackLocation->Parameters.QueryInterface.InterfaceSpecificData = NULL;
222
223 /* Send it to the root PDO */
224 Status = IoCallDriver(AttachedDevice, Irp);
225 if (Status == STATUS_PENDING)
226 {
227 /* Wait for completion */
229 Executive,
231 FALSE,
232 NULL);
233 Status = Irp->IoStatus.Status;
234 }
235
236 /* Check if an interface was returned */
237 if (!NT_SUCCESS(Status))
238 {
239 /* No interface was returned by the root PDO */
240 FdoExtension->PciBusInterface = NULL;
241 ExFreePoolWithTag(PciInterface, 0);
242 }
243 else
244 {
245 /* An interface was returned, save it */
246 FdoExtension->PciBusInterface = PciInterface;
247 }
248
249 /* Dereference the device object because we took a reference earlier */
250 ObDereferenceObject(AttachedDevice);
251 }
252 else
253 {
254 /* Failure path, dereference the device object and set failure code */
255 if (AttachedDevice) ObDereferenceObject(AttachedDevice);
256 ExFreePoolWithTag(PciInterface, 0);
258 }
259
260 /* Return status code to caller */
261 return Status;
262}
#define PAGED_CODE()
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
_In_ PIRP Irp
Definition: csq.h:116
_In_ PIO_STATUS_BLOCK IoStatusBlock
Definition: dispmprt.h:608
_Check_return_ _In_ DXGK_EVENT_TYPE _In_ ULONG Event
Definition: dispmprt.h:1287
#define FALSE
Definition: types.h:117
#define PCI_POOL_TAG
Definition: pci.h:27
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define NonPagedPool
Definition: env_spec_w32.h:307
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
#define KernelMode
Definition: asm.h:38
@ SynchronizationEvent
PDEVICE_OBJECT NTAPI IoGetAttachedDeviceReference(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1414
PIRP NTAPI IoBuildSynchronousFsdRequest(IN ULONG MajorFunction, IN PDEVICE_OBJECT DeviceObject, IN PVOID Buffer, IN ULONG Length, IN PLARGE_INTEGER StartingOffset, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:1101
#define IoCallDriver
Definition: irp.c:1257
struct _INTERFACE * PINTERFACE
union _IO_STACK_LOCATION::@1803 Parameters
struct _IO_STACK_LOCATION::@4925::@4951 QueryInterface
#define STATUS_PENDING
Definition: telnetd.h:14
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ PIO_STACK_LOCATION IoStackLocation
Definition: usbdlib.h:265
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2695
#define PCI_BUS_INTERFACE_STANDARD_VERSION
Definition: iotypes.h:5339
struct _PCI_BUS_INTERFACE_STANDARD PCI_BUS_INTERFACE_STANDARD
#define IRP_MN_QUERY_INTERFACE
@ Executive
Definition: ketypes.h:467
#define ObDereferenceObject
Definition: obfuncs.h:203

Referenced by PciGetConfigHandlers().

◆ PciReadDeviceConfig()

VOID NTAPI PciReadDeviceConfig ( IN PPCI_PDO_EXTENSION  DeviceExtension,
IN PVOID  Buffer,
IN ULONG  Offset,
IN ULONG  Length 
)

Definition at line 149 of file config.c.

153{
154 /* Call the generic worker function */
155 PciReadWriteConfigSpace(DeviceExtension->ParentFdoExtension,
156 DeviceExtension->Slot,
157 Buffer,
158 Offset,
159 Length,
160 TRUE);
161}
Definition: bufpool.h:45
VOID NTAPI PciReadWriteConfigSpace(IN PPCI_FDO_EXTENSION DeviceExtension, IN PCI_SLOT_NUMBER Slot, IN PVOID Buffer, IN ULONG Offset, IN ULONG Length, IN BOOLEAN Read)
Definition: config.c:49
_In_ ULONG _In_ ULONG Offset
Definition: ntddpcm.h:101

Referenced by PciApplyHacks(), PciAssignSlotResources(), PciConfigureIdeController(), PciDecodeEnable(), PcipGetFunctionLimits(), PciQueryRequirements(), PciQueryResources(), PciReadDeviceCapability(), PciReadDeviceExtendedCapability(), PciScanBus(), PciSetResources(), PciStallForPowerChange(), and PciWriteLimitsAndRestoreCurrent().

◆ PciReadSlotConfig()

VOID NTAPI PciReadSlotConfig ( IN PPCI_FDO_EXTENSION  DeviceExtension,
IN PCI_SLOT_NUMBER  Slot,
IN PVOID  Buffer,
IN ULONG  Offset,
IN ULONG  Length 
)

Definition at line 165 of file config.c.

170{
171 /* Call the generic worker function */
172 PciReadWriteConfigSpace(DeviceExtension, Slot, Buffer, Offset, Length, TRUE);
173}

Referenced by PciEcamVerifyBus(), and PciScanBus().

◆ PciReadWriteConfigSpace()

VOID NTAPI PciReadWriteConfigSpace ( IN PPCI_FDO_EXTENSION  DeviceExtension,
IN PCI_SLOT_NUMBER  Slot,
IN PVOID  Buffer,
IN ULONG  Offset,
IN ULONG  Length,
IN BOOLEAN  Read 
)

Definition at line 49 of file config.c.

55{
56 PPCI_BUS_INTERFACE_STANDARD PciInterface;
57 PBUS_HANDLER BusHandler;
58 PPCIBUSDATA BusData;
59 PciReadWriteConfig HalFunction;
60 ULONG LengthProcessed;
61
62 /* Only the root FDO can access configuration space */
63 ASSERT(PCI_IS_ROOT_FDO(DeviceExtension->BusRootFdoExtension));
64
65 /* The legacy mechanism cannot reach extended configuration space */
67 (PciEcamReadWriteConfig(DeviceExtension->BaseBus,
68 Slot,
69 Buffer,
70 Offset,
71 Length,
72 Read)))
73 {
74 return;
75 }
76
77 /* Get the ACPI-compliant PCI interface from the root */
78 PciInterface = DeviceExtension->BusRootFdoExtension->PciBusInterface;
79 if (PciInterface)
80 {
81 /* Use the PCI interface to access configuration space */
82 if (Read)
83 {
84 LengthProcessed = PciInterface->ReadConfig(PciInterface->Context,
85 DeviceExtension->BaseBus,
86 Slot.u.AsULONG,
87 Buffer,
88 Offset,
89 Length);
90 }
91 else
92 {
93 LengthProcessed = PciInterface->WriteConfig(PciInterface->Context,
94 DeviceExtension->BaseBus,
95 Slot.u.AsULONG,
96 Buffer,
97 Offset,
98 Length);
99 }
100
101 /* Verify the operation succeeded */
102 if (LengthProcessed != Length)
103 {
104 DPRINT1("PCI: Config space %s failed - Bus %x, Slot %x, Offset %x, Expected %x bytes, got %x\n",
105 Read ? "read" : "write",
106 DeviceExtension->BaseBus,
107 Slot.u.AsULONG,
108 Offset,
109 Length,
110 LengthProcessed);
111 }
112 }
113 else
114 {
115 /* Make sure there's a registered HAL bus handler */
116 ASSERT(DeviceExtension->BusHandler);
117
118 /* PCI Bus Number assignment is only valid on ACPI systems */
120
121 /* Grab the HAL PCI Bus Handler data */
122 BusHandler = (PBUS_HANDLER)DeviceExtension->BusHandler;
123 BusData = (PPCIBUSDATA)BusHandler->BusData;
124
125 /* Choose the appropriate read or write function, and call it */
126 HalFunction = Read ? BusData->ReadConfig : BusData->WriteConfig;
127 HalFunction(BusHandler, Slot, Buffer, Offset, Length);
128 }
129}
#define DPRINT1
Definition: precomp.h:8
#define PCI_LEGACY_CONFIG_LENGTH
Definition: pci.h:77
BOOLEAN NTAPI PciEcamReadWriteConfig(_In_ ULONG Bus, _In_ PCI_SLOT_NUMBER Slot, _Inout_updates_bytes_(Length) PVOID Buffer, _In_ ULONG Offset, _In_ ULONG Length, _In_ BOOLEAN Read)
Performs a configuration space access through the ECAM window.
Definition: ecam.c:386
struct _BUS_HANDLER * PBUS_HANDLER
Definition: nt_native.h:37
_In_ BOOLEAN Read
Definition: strmini.h:479
PVOID BusData
Definition: haltypes.h:1997
PciReadWriteConfig WriteConfig
Definition: iotypes.h:5285
PciReadWriteConfig ReadConfig
Definition: iotypes.h:5284
PCI_READ_WRITE_CONFIG ReadConfig
Definition: iotypes.h:5331
PCI_READ_WRITE_CONFIG WriteConfig
Definition: iotypes.h:5332
VOID(NTAPI * PciReadWriteConfig)(_In_ struct _BUS_HANDLER *BusHandler, _In_ PCI_SLOT_NUMBER Slot, _In_reads_bytes_(Length) PVOID Buffer, _In_ ULONG Offset, _In_ ULONG Length)
Definition: iotypes.h:5271

Referenced by PciReadDeviceConfig(), PciReadSlotConfig(), and PciWriteDeviceConfig().

◆ PciWriteDeviceConfig()

VOID NTAPI PciWriteDeviceConfig ( IN PPCI_PDO_EXTENSION  DeviceExtension,
IN PVOID  Buffer,
IN ULONG  Offset,
IN ULONG  Length 
)

Definition at line 133 of file config.c.

137{
138 /* Call the generic worker function */
139 PciReadWriteConfigSpace(DeviceExtension->ParentFdoExtension,
140 DeviceExtension->Slot,
141 Buffer,
142 Offset,
143 Length,
144 FALSE);
145}

Referenced by PciApplyHacks(), PciConfigureIdeController(), PciDecodeEnable(), PcipUpdateHardware(), PciScanBus(), PciSetPowerManagedDevicePowerState(), and PciWriteLimitsAndRestoreCurrent().

Variable Documentation

◆ PciAssignBusNumbers

BOOLEAN PciAssignBusNumbers

Definition at line 18 of file config.c.

Referenced by PciGetConfigHandlers(), PciProcessBus(), and PciReadWriteConfigSpace().