ReactOS 0.4.17-dev-1190-g4c812f4
hookhal.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS PCI Bus Driver
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: drivers/bus/pci/hookhal.c
5 * PURPOSE: HAL Bus Handler Dispatch Routine Support
6 * PROGRAMMERS: ReactOS Portable Systems Group
7 */
8
9/* INCLUDES *******************************************************************/
10
11#include <pci.h>
12
13#define NDEBUG
14#include <debug.h>
15
16/* GLOBALS ********************************************************************/
17
20
21/* FUNCTIONS ******************************************************************/
22
30{
31 /* The HAL has the final say on any bus it registered */
37 {
38 return TRUE;
39 }
40
41 /* Buses the HAL never saw still map PCI addresses 1:1 to processor addresses */
42 if (InterfaceType != PCIBus)
43 return FALSE;
44
46 return TRUE;
47}
48
53static
56PciFindPdoByLocation(
59{
60 PPCI_FDO_EXTENSION DeviceExtension;
64
65 /* Now search for the extension */
67 while (DeviceExtension)
68 {
69 /* If we found it, break out */
70 if (DeviceExtension->BaseBus == BusNumber) break;
71
72 /* Move to the next device */
73 DeviceExtension = (PPCI_FDO_EXTENSION)DeviceExtension->List.Next;
74 }
75
76 /* Check if the device extension for the bus was found */
77 if (!DeviceExtension)
78 {
79 /* It wasn't, bail out */
80 DPRINT1("PCIX - Could not find PCI bus FDO. Bus Number = 0x%x\n", BusNumber);
81 return NULL;
82 }
83
84 /* Acquire this device's lock */
86 KeWaitForSingleObject(&DeviceExtension->ChildListLock,
89 FALSE,
90 NULL);
91
92 /* Loop every child PDO */
93 for (PdoExtension = DeviceExtension->ChildPdoList;
96 {
97 /* A function that left the slot keeps its PDO until PnP removes it */
98 if (PdoExtension->NotPresent || PdoExtension->ReportedMissing)
99 continue;
100
101 /* Check if the function number and header data matches */
102 if ((PdoExtension->Slot.u.bits.FunctionNumber == PciSlot.u.bits.FunctionNumber) &&
103 (PdoExtension->Slot.u.bits.DeviceNumber == PciSlot.u.bits.DeviceNumber))
104 {
105 /* This is considered to be the same PDO */
106 ASSERT(PdoExtension->Slot.u.AsULONG == PciSlot.u.AsULONG);
107 break;
108 }
109 }
110
111 /* Release this device's lock */
112 KeSetEvent(&DeviceExtension->ChildListLock, IO_NO_INCREMENT, FALSE);
114
115 /* Check if we found something */
116 if (!PdoExtension)
117 {
118 /* Let the debugger know */
119 DPRINT1("PCIX - Could not find PDO for device @ %x.%x.%x\n",
120 BusNumber,
121 PciSlot.u.bits.DeviceNumber,
122 PciSlot.u.bits.FunctionNumber);
123 }
124
125 /* If the search found something, this is non-NULL, otherwise it's NULL */
126 return PdoExtension;
127}
128
132static
133VOID
134NTAPI
137{
138 PCM_PARTIAL_RESOURCE_LIST PartialList;
140
141 ASSERT(ResourceList->Count == 1);
142 PartialList = &ResourceList->List[0].PartialResourceList;
143
144 Target = 0;
145 for (Source = 0; Source < PartialList->Count; Source++)
146 {
148 continue;
149
150 if (Target != Source)
151 PartialList->PartialDescriptors[Target] = PartialList->PartialDescriptors[Source];
152
153 Target++;
154 }
155
156 PartialList->Count = Target;
157}
158
163static
165NTAPI
168 _In_ PPCI_COMMON_HEADER PciData,
174{
176 PCM_RESOURCE_LIST Assigned = NULL;
178
179 *Resources = NULL;
180
182 if (!NT_SUCCESS(Status))
183 return Status;
184
185 /* The shared empty list asks for nothing and must not be freed */
188
189 PdoExtension->LegacyDriver = TRUE;
195 &Assigned);
198
199 if (!NT_SUCCESS(Status))
200 {
201 ASSERT(Assigned == NULL);
202 return Status;
203 }
204
205 /* Program the assignment the way a PnP start does */
206 PdoExtension->CommandEnables |= (PCI_ENABLE_IO_SPACE |
210
212 if (!NT_SUCCESS(Status))
213 {
214 if (Assigned)
215 ExFreePoolWithTag(Assigned, 0);
216 return Status;
217 }
218
219 /* The caller only gets the ranges and the interrupt */
220 if (Assigned)
222
223 *Resources = Assigned;
224 return STATUS_SUCCESS;
225}
226
231NTAPI
241{
242 PCI_COMMON_HEADER PciData;
244 PDEVICE_OBJECT ExistingDeviceObject;
246 PAGED_CODE();
248
250
251 if (BusType != PCIBus)
253
254 /* A removed bus is unlinked under this lock before its PDOs are deleted */
257
258 PdoExtension = PciFindPdoByLocation(BusNumber, SlotNumber);
259 if (!PdoExtension)
261 else if (PdoExtension->DeviceState != PciNotStarted)
263 else
265
266 if (NT_SUCCESS(Status))
267 {
268 ASSERT(DeviceObject != PdoExtension->PhysicalDeviceObject);
269
270 /* The routing goes to the cache first so interrupt arbitration can find it */
273 BusNumber,
275 PciData.u.type0.InterruptLine,
276 PciData.u.type0.InterruptPin,
277 PciData.BaseClass,
278 PciData.SubClass,
279 PdoExtension->ParentFdoExtension->
282 &ExistingDeviceObject);
283 }
284
285 if (NT_SUCCESS(Status))
286 {
288 &PciData,
294
295 /* Give the slot back to the device object cached for it before */
296 if (!NT_SUCCESS(Status))
297 {
298 PciCacheLegacyDeviceRouting(ExistingDeviceObject,
299 BusNumber,
301 PciData.u.type0.InterruptLine,
302 PciData.u.type0.InterruptPin,
303 PciData.BaseClass,
304 PciData.SubClass,
305 PdoExtension->ParentFdoExtension->
308 NULL);
309 }
310 }
311
314 return Status;
315}
316
317VOID
318NTAPI
320{
321 /* Save the old HAL routines */
326
327 /* Take over the HAL's Bus Handler functions */
330}
331
335VOID
336NTAPI
338{
339 PAGED_CODE();
342
343 /* Restore the HAL table before dropping the only copies of its routines */
346
349}
350
351/* EOF */
#define PAGED_CODE()
unsigned char BOOLEAN
Definition: actypes.h:127
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1157
SINGLE_LIST_ENTRY PciFdoExtensionListHead
Definition: fdo.c:18
while(CdLookupNextInitialFileDirent(IrpContext, Fcb, FileContext))
#define _Requires_lock_held_(lock)
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
NTSTATUS NTAPI PciSetResources(IN PPCI_PDO_EXTENSION PdoExtension, IN BOOLEAN DoReset, IN BOOLEAN SomethingSomethingDarkSide)
Definition: enum.c:2490
NTSTATUS NTAPI PciBuildRequirementsList(IN PPCI_PDO_EXTENSION PdoExtension, IN PPCI_COMMON_HEADER PciData, OUT PIO_RESOURCE_REQUIREMENTS_LIST *Buffer)
Definition: enum.c:756
PIO_RESOURCE_REQUIREMENTS_LIST PciZeroIoResourceRequirements
Definition: enum.c:18
BOOLEAN NTAPI PciComputeNewCurrentSettings(IN PPCI_PDO_EXTENSION PdoExtension, IN PCM_RESOURCE_LIST ResourceList)
Definition: enum.c:55
KEVENT PciGlobalLock
Definition: init.c:20
@ PciNotStarted
Definition: pci.h:168
VOID NTAPI PciReadDeviceConfig(IN PPCI_PDO_EXTENSION DeviceExtension, IN PVOID Buffer, IN ULONG Offset, IN ULONG Length)
Definition: config.c:149
struct _PCI_FDO_EXTENSION * PPCI_FDO_EXTENSION
@ PdoExtension
Definition: precomp.h:61
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KeSetEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:476
Status
Definition: gdiplustypes.h:24
pHalTranslateBusAddress PcipSavedTranslateBusAddress
Definition: hookhal.c:18
static VOID NTAPI PciStripPrivateDescriptors(_Inout_ PCM_RESOURCE_LIST ResourceList)
Removes the device private descriptors from an assigned resource list.
Definition: hookhal.c:135
NTSTATUS NTAPI PciAssignSlotResources(_In_ PUNICODE_STRING RegistryPath, _In_opt_ PUNICODE_STRING DriverClassName, _In_ PDRIVER_OBJECT DriverObject, _In_opt_ PDEVICE_OBJECT DeviceObject, _In_ INTERFACE_TYPE BusType, _In_ ULONG BusNumber, _In_ ULONG SlotNumber, _Inout_ PCM_RESOURCE_LIST *AllocatedResources)
Assigns resources to a function claimed by a driver outside of PnP.
Definition: hookhal.c:232
pHalAssignSlotResources PcipSavedAssignSlotResources
Definition: hookhal.c:19
BOOLEAN NTAPI PciTranslateBusAddress(IN INTERFACE_TYPE InterfaceType, IN ULONG BusNumber, IN PHYSICAL_ADDRESS BusAddress, OUT PULONG AddressSpace, OUT PPHYSICAL_ADDRESS TranslatedAddress)
Definition: hookhal.c:25
VOID NTAPI PciHookHal(VOID)
Definition: hookhal.c:319
static NTSTATUS NTAPI PciAssignAndProgramLegacy(_In_ PPCI_PDO_EXTENSION PdoExtension, _In_ PPCI_COMMON_HEADER PciData, _In_ PUNICODE_STRING RegistryPath, _In_opt_ PUNICODE_STRING DriverClassName, _In_ PDRIVER_OBJECT DriverObject, _In_opt_ PDEVICE_OBJECT DeviceObject, _Out_ PCM_RESOURCE_LIST *Resources)
Asks the PnP manager for the ranges of a legacy claimed function and programs them....
Definition: hookhal.c:166
VOID NTAPI PciRestoreHalHooks(VOID)
Gives the HAL back the routines PciHookHal replaced.
Definition: hookhal.c:337
NTSTATUS NTAPI IoAssignResources(_In_ PUNICODE_STRING RegistryPath, _In_opt_ PUNICODE_STRING DriverClassName, _In_ PDRIVER_OBJECT DriverObject, _In_opt_ PDEVICE_OBJECT DeviceObject, _In_opt_ PIO_RESOURCE_REQUIREMENTS_LIST RequestedResources, _Inout_ PCM_RESOURCE_LIST *AllocatedResources)
Definition: iorsrce.c:1134
#define KeLeaveCriticalRegion()
Definition: ke_x.h:119
#define KeEnterCriticalRegion()
Definition: ke_x.h:88
#define ASSERT(a)
Definition: mode.c:44
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1109
_Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PCM_RESOURCE_LIST * AllocatedResources
Definition: ndis.h:4643
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3169
#define HalPciTranslateBusAddress
Definition: halfuncs.h:41
#define HalPciAssignSlotResources
Definition: halfuncs.h:42
#define KernelMode
Definition: asm.h:38
#define _Inout_
Definition: no_sal2.h:162
#define _Out_
Definition: no_sal2.h:160
#define _In_
Definition: no_sal2.h:158
#define _In_opt_
Definition: no_sal2.h:212
#define STATUS_DEVICE_DOES_NOT_EXIST
Definition: ntstatus.h:522
#define STATUS_INVALID_OWNER
Definition: ntstatus.h:420
_In_ ULONG _In_ PCI_SLOT_NUMBER PciSlot
Definition: pciidex.h:66
_In_ ULONG BusNumber
Definition: pciidex.h:65
#define CmResourceTypeDevicePrivate
Definition: restypes.h:112
@ PCIBus
Definition: restypes.h:127
enum _INTERFACE_TYPE INTERFACE_TYPE
NTSTATUS NTAPI PciCacheLegacyDeviceRouting(IN PDEVICE_OBJECT DeviceObject, IN ULONG BusNumber, IN ULONG SlotNumber, IN UCHAR InterruptLine, IN UCHAR InterruptPin, IN UCHAR BaseClass, IN UCHAR SubClass, IN PDEVICE_OBJECT PhysicalDeviceObject, IN PPCI_PDO_EXTENSION PdoExtension, OUT PDEVICE_OBJECT *pFoundDeviceObject)
Definition: routintf.c:266
#define STATUS_SUCCESS
Definition: shellext.h:65
CM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptors[1]
Definition: restypes.h:100
SINGLE_LIST_ENTRY List
Definition: pci.h:243
struct _PCI_PDO_EXTENSION * ChildPdoList
Definition: pci.h:253
BOOLEAN BaseBus
Definition: pci.h:260
KEVENT ChildListLock
Definition: pci.h:252
struct _PCI_SLOT_NUMBER::@5064::@5065 bits
union _PCI_SLOT_NUMBER::@5064 u
struct _SINGLE_LIST_ENTRY * Next
Definition: ntbasedef.h:641
uint32_t * PULONG
Definition: typedefs.h:59
#define NTAPI
Definition: typedefs.h:36
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2061
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:215
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID InterfaceType
Definition: wdffdo.h:463
_In_ WDFIOTARGET Target
Definition: wdfrequest.h:306
_Must_inspect_result_ _In_ WDFIORESREQLIST _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFIORESLIST * ResourceList
Definition: wdfresource.h:309
_In_ WDFIORESREQLIST RequirementsList
Definition: wdfresource.h:65
_In_ WDFIORESREQLIST _In_ ULONG SlotNumber
Definition: wdfresource.h:68
_In_opt_ PUNICODE_STRING DriverClassName
Definition: halfuncs.h:156
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE BusType
Definition: halfuncs.h:159
NTSTATUS(NTAPI * pHalAssignSlotResources)(_In_ PUNICODE_STRING RegistryPath, _In_opt_ PUNICODE_STRING DriverClassName, _In_ PDRIVER_OBJECT DriverObject, _In_ PDEVICE_OBJECT DeviceObject, _In_ INTERFACE_TYPE BusType, _In_ ULONG BusNumber, _In_ ULONG SlotNumber, _Inout_ PCM_RESOURCE_LIST *AllocatedResources)
Definition: haltypes.h:179
BOOLEAN(NTAPI * pHalTranslateBusAddress)(_In_ INTERFACE_TYPE InterfaceType, _In_ ULONG BusNumber, _In_ PHYSICAL_ADDRESS BusAddress, _Inout_ PULONG AddressSpace, _Out_ PPHYSICAL_ADDRESS TranslatedAddress)
Definition: haltypes.h:171
_In_ ULONG _In_ PHYSICAL_ADDRESS BusAddress
Definition: iofuncs.h:2273
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG _Out_ PPHYSICAL_ADDRESS TranslatedAddress
Definition: iofuncs.h:2275
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2274
#define PCI_ENABLE_BUS_MASTER
Definition: iotypes.h:3633
#define IO_NO_INCREMENT
Definition: iotypes.h:598
#define PCI_ENABLE_IO_SPACE
Definition: iotypes.h:3631
#define PCI_ENABLE_MEMORY_SPACE
Definition: iotypes.h:3632
#define PCI_COMMON_HDR_LENGTH
Definition: iotypes.h:3609
@ Executive
Definition: ketypes.h:467