ReactOS  0.4.14-dev-50-g13bb5e2
hookhal.c File Reference
#include <pci.h>
#include <debug.h>
Include dependency graph for hookhal.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

BOOLEAN NTAPI PciTranslateBusAddress (IN INTERFACE_TYPE InterfaceType, IN ULONG BusNumber, IN PHYSICAL_ADDRESS BusAddress, OUT PULONG AddressSpace, OUT PPHYSICAL_ADDRESS TranslatedAddress)
 
PPCI_PDO_EXTENSION NTAPI PciFindPdoByLocation (IN ULONG BusNumber, IN ULONG SlotNumber)
 
NTSTATUS NTAPI PciAssignSlotResources (IN PUNICODE_STRING RegistryPath, IN PUNICODE_STRING DriverClassName OPTIONAL, IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT DeviceObject, IN INTERFACE_TYPE BusType, IN ULONG BusNumber, IN ULONG SlotNumber, IN OUT PCM_RESOURCE_LIST *AllocatedResources)
 
VOID NTAPI PciHookHal (VOID)
 

Variables

pHalTranslateBusAddress PcipSavedTranslateBusAddress
 
pHalAssignSlotResources PcipSavedAssignSlotResources
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 13 of file hookhal.c.

Function Documentation

◆ PciAssignSlotResources()

NTSTATUS NTAPI PciAssignSlotResources ( IN PUNICODE_STRING  RegistryPath,
IN PUNICODE_STRING DriverClassName  OPTIONAL,
IN PDRIVER_OBJECT  DriverObject,
IN PDEVICE_OBJECT  DeviceObject,
IN INTERFACE_TYPE  BusType,
IN ULONG  BusNumber,
IN ULONG  SlotNumber,
IN OUT PCM_RESOURCE_LIST AllocatedResources 
)

Definition at line 121 of file hookhal.c.

129 {
130  PIO_RESOURCE_REQUIREMENTS_LIST RequirementsList = NULL;
132  PCI_COMMON_HEADER PciData;
135  PDEVICE_OBJECT ExistingDeviceObject;
136  PAGED_CODE();
138  ASSERT(BusType == PCIBus);
139 
140  /* Assume no resources */
142 
143  /* Find the PDO for this slot and make sure it exists and is started */
146  if (PdoExtension->DeviceState == PciNotStarted) return STATUS_INVALID_OWNER;
147 
148  /* Acquire the global lock while we attempt to assign resources */
151  do
152  {
153  /* Make sure we're not on the PDO for some reason */
154  ASSERT(DeviceObject != PdoExtension->PhysicalDeviceObject);
155 
156  /* Read the PCI header and cache the routing information */
159  BusNumber,
160  SlotNumber,
161  PciData.u.type0.InterruptLine,
162  PciData.u.type0.InterruptPin,
163  PciData.BaseClass,
164  PciData.SubClass,
165  PdoExtension->ParentFdoExtension->
167  PdoExtension,
168  &ExistingDeviceObject);
169  if (NT_SUCCESS(Status))
170  {
171  /* Manually build the requirements for this device, and mark it legacy */
173  &PciData,
174  &RequirementsList);
175  PdoExtension->LegacyDriver = TRUE;
176  if (NT_SUCCESS(Status))
177  {
178  /* Now call the legacy Pnp function to actually assign resources */
181  DriverObject,
182  DeviceObject,
183  RequirementsList,
184  &Resources);
185  if (NT_SUCCESS(Status))
186  {
187  /* Resources are ready, so enable all decodes */
188  PdoExtension->CommandEnables |= (PCI_ENABLE_IO_SPACE |
191 
192  /* Compute new resource settings based on what PnP assigned */
194 
195  /* Set these new resources on the device */
197  if (NT_SUCCESS(Status))
198  {
199  /* Some work needs to happen here to handle this */
200  ASSERT(Resources->Count == 1);
201  //ASSERT(PartialList->Count > 0);
202 
204 
205  /* Return the allocated resources, and success */
207  Resources = NULL;
209  }
210  }
211  else
212  {
213  /* If assignment failed, no resources should exist */
214  ASSERT(Resources == NULL);
215  }
216 
217  /* If assignment succeed, then we are done */
218  if (NT_SUCCESS(Status)) break;
219  }
220 
221  /* Otherwise, cache the new routing */
222  PciCacheLegacyDeviceRouting(ExistingDeviceObject,
223  BusNumber,
224  SlotNumber,
225  PciData.u.type0.InterruptLine,
226  PciData.u.type0.InterruptPin,
227  PciData.BaseClass,
228  PciData.SubClass,
229  PdoExtension->ParentFdoExtension->
231  PdoExtension,
232  NULL);
233  }
234  } while (0);
235 
236  /* Release the lock */
237  KeSetEvent(&PciGlobalLock, 0, 0);
239 
240  /* Free any temporary resource data and return the status */
241  if (RequirementsList) ExFreePoolWithTag(RequirementsList, 0);
243  return Status;
244 }
NTSTATUS NTAPI PciBuildRequirementsList(IN PPCI_PDO_EXTENSION PdoExtension, IN PPCI_COMMON_HEADER PciData, OUT PIO_RESOURCE_REQUIREMENTS_LIST *Buffer)
Definition: enum.c:551
#define STATUS_DEVICE_DOES_NOT_EXIST
Definition: ntstatus.h:414
BOOLEAN NTAPI PciComputeNewCurrentSettings(IN PPCI_PDO_EXTENSION PdoExtension, IN PCM_RESOURCE_LIST ResourceList)
Definition: enum.c:55
#define TRUE
Definition: types.h:120
KEVENT PciGlobalLock
Definition: init.c:20
#define PCI_ENABLE_IO_SPACE
Definition: iotypes.h:3260
_Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PDEVICE_OBJECT _Inout_opt_ PCM_RESOURCE_LIST * AllocatedResources
Definition: ndis.h:4640
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE BusType
Definition: halfuncs.h:156
LONG NTSTATUS
Definition: precomp.h:26
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1114
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
PPCI_PDO_EXTENSION NTAPI PciFindPdoByLocation(IN ULONG BusNumber, IN ULONG SlotNumber)
Definition: hookhal.c:43
#define PAGED_CODE()
Definition: video.h:57
_In_opt_ PUNICODE_STRING DriverClassName
Definition: halfuncs.h:156
NTSTATUS NTAPI PciSetResources(IN PPCI_PDO_EXTENSION PdoExtension, IN BOOLEAN DoReset, IN BOOLEAN SomethingSomethingDarkSide)
Definition: enum.c:2155
smooth NULL
Definition: ftsmooth.c:416
static PDRIVER_OBJECT DriverObject
Definition: template.c:42
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE _In_ ULONG BusNumber
Definition: halfuncs.h:156
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define PCI_ENABLE_BUS_MASTER
Definition: iotypes.h:3262
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE _In_ ULONG _In_ ULONG SlotNumber
Definition: halfuncs.h:156
#define KeEnterCriticalRegion()
Definition: ke_x.h:83
pHalAssignSlotResources PcipSavedAssignSlotResources
Definition: hookhal.c:19
Status
Definition: gdiplustypes.h:24
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
#define KeLeaveCriticalRegion()
Definition: ke_x.h:114
#define STATUS_INVALID_OWNER
Definition: ntstatus.h:312
#define PCI_ENABLE_MEMORY_SPACE
Definition: iotypes.h:3261
VOID NTAPI PciReadDeviceConfig(IN PPCI_PDO_EXTENSION DeviceExtension, IN PVOID Buffer, IN ULONG Offset, IN ULONG Length)
Definition: config.c:107
#define UNIMPLEMENTED
Definition: debug.h:114
_In_ PUNICODE_STRING RegistryPath
Definition: wmip.h:27
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
return STATUS_SUCCESS
Definition: btrfs.c:2966
NTSTATUS NTAPI IoAssignResources(IN PUNICODE_STRING RegistryPath, IN PUNICODE_STRING DriverClassName, IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT DeviceObject, IN PIO_RESOURCE_REQUIREMENTS_LIST RequestedResources, IN OUT PCM_RESOURCE_LIST *AllocatedResources)
Definition: iorsrce.c:944
#define PCI_COMMON_HDR_LENGTH
Definition: iotypes.h:3238
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:70

◆ PciFindPdoByLocation()

PPCI_PDO_EXTENSION NTAPI PciFindPdoByLocation ( IN ULONG  BusNumber,
IN ULONG  SlotNumber 
)

Definition at line 43 of file hookhal.c.

45 {
46  PPCI_FDO_EXTENSION DeviceExtension;
48  PCI_SLOT_NUMBER PciSlot;
49  PciSlot.u.AsULONG = SlotNumber;
50 
51  /* Acquire the global lock */
54 
55  /* Now search for the extension */
57  while (DeviceExtension)
58  {
59  /* If we found it, break out */
60  if (DeviceExtension->BaseBus == BusNumber) break;
61 
62  /* Move to the next device */
63  DeviceExtension = (PPCI_FDO_EXTENSION)DeviceExtension->List.Next;
64  }
65 
66  /* Release the global lock */
69 
70  /* Check if the device extension for the bus was found */
71  if (!DeviceExtension)
72  {
73  /* It wasn't, bail out */
74  DPRINT1("Pci: Could not find PCI bus FDO. Bus Number = 0x%x\n", BusNumber);
75  return NULL;
76  }
77 
78  /* Acquire this device's lock */
80  KeWaitForSingleObject(&DeviceExtension->ChildListLock,
81  Executive,
82  KernelMode,
83  FALSE,
84  NULL);
85 
86  /* Loop every child PDO */
87  for (PdoExtension = DeviceExtension->ChildPdoList;
89  PdoExtension = PdoExtension->Next)
90  {
91  /* Check if the function number and header data matches */
92  if ((PdoExtension->Slot.u.bits.FunctionNumber == PciSlot.u.bits.FunctionNumber) &&
93  (PdoExtension->Slot.u.bits.DeviceNumber == PciSlot.u.bits.DeviceNumber))
94  {
95  /* This is considered to be the same PDO */
96  ASSERT(PdoExtension->Slot.u.AsULONG == PciSlot.u.AsULONG);
97  break;
98  }
99  }
100 
101  /* Release this device's lock */
102  KeSetEvent(&DeviceExtension->ChildListLock, IO_NO_INCREMENT, FALSE);
104 
105  /* Check if we found something */
106  if (!PdoExtension)
107  {
108  /* Let the debugger know */
109  DPRINT1("Pci: Could not find PDO for device @ %x.%x.%x\n",
110  BusNumber,
111  PciSlot.u.bits.DeviceNumber,
112  PciSlot.u.bits.FunctionNumber);
113  }
114 
115  /* If the search found something, this is non-NULL, otherwise it's NULL */
116  return PdoExtension;
117 }
KEVENT PciGlobalLock
Definition: init.c:20
LONG NTAPI KeSetEvent(IN PKEVENT Event, IN KPRIORITY Increment, IN BOOLEAN Wait)
Definition: eventobj.c:159
NTSTATUS NTAPI KeWaitForSingleObject(IN PVOID Object, IN KWAIT_REASON WaitReason, IN KPROCESSOR_MODE WaitMode, IN BOOLEAN Alertable, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: wait.c:416
while(1)
Definition: macro.lex.yy.c:740
struct _PCI_FDO_EXTENSION * PPCI_FDO_EXTENSION
KEVENT ChildListLock
Definition: pci.h:201
smooth NULL
Definition: ftsmooth.c:416
BOOLEAN BaseBus
Definition: pci.h:209
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE _In_ ULONG BusNumber
Definition: halfuncs.h:156
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE _In_ ULONG _In_ ULONG SlotNumber
Definition: halfuncs.h:156
struct _SINGLE_LIST_ENTRY * Next
Definition: ntbasedef.h:636
SINGLE_LIST_ENTRY PciFdoExtensionListHead
Definition: fdo.c:18
union _PCI_SLOT_NUMBER::@3636 u
#define KeEnterCriticalRegion()
Definition: ke_x.h:83
struct _PCI_SLOT_NUMBER::@3636::@3637 bits
SINGLE_LIST_ENTRY List
Definition: pci.h:192
#define KeLeaveCriticalRegion()
Definition: ke_x.h:114
struct _PCI_PDO_EXTENSION * ChildPdoList
Definition: pci.h:202
#define DPRINT1
Definition: precomp.h:8
#define IO_NO_INCREMENT
Definition: iotypes.h:566

Referenced by PciAssignSlotResources().

◆ PciHookHal()

VOID NTAPI PciHookHal ( VOID  )

Definition at line 248 of file hookhal.c.

249 {
250  /* Save the old HAL routines */
255 
256  /* Take over the HAL's Bus Handler functions */
257 // HalPciAssignSlotResources = PciAssignSlotResources;
259 }
pHalTranslateBusAddress PcipSavedTranslateBusAddress
Definition: hookhal.c:18
#define HalPciTranslateBusAddress
Definition: halfuncs.h:41
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
smooth NULL
Definition: ftsmooth.c:416
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
pHalAssignSlotResources PcipSavedAssignSlotResources
Definition: hookhal.c:19
#define HalPciAssignSlotResources
Definition: halfuncs.h:42

Referenced by DriverEntry().

◆ PciTranslateBusAddress()

BOOLEAN NTAPI PciTranslateBusAddress ( IN INTERFACE_TYPE  InterfaceType,
IN ULONG  BusNumber,
IN PHYSICAL_ADDRESS  BusAddress,
OUT PULONG  AddressSpace,
OUT PPHYSICAL_ADDRESS  TranslatedAddress 
)

Definition at line 25 of file hookhal.c.

30 {
31  UNREFERENCED_PARAMETER(InterfaceType);
34 
35  /* FIXME: Broken translation */
38  return TRUE;
39 }
#define TRUE
Definition: types.h:120
_In_ ULONG _In_ PHYSICAL_ADDRESS BusAddress
Definition: iofuncs.h:2268
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG AddressSpace
Definition: iofuncs.h:2268
_In_ ULONG _In_ PHYSICAL_ADDRESS _Inout_ PULONG _Out_ PPHYSICAL_ADDRESS TranslatedAddress
Definition: iofuncs.h:2268
_In_opt_ PUNICODE_STRING _In_ PDRIVER_OBJECT _In_ PDEVICE_OBJECT _In_ INTERFACE_TYPE _In_ ULONG BusNumber
Definition: halfuncs.h:156
#define UNIMPLEMENTED
Definition: debug.h:114
LONGLONG QuadPart
Definition: typedefs.h:112

Referenced by PciHookHal().

Variable Documentation

◆ PcipSavedAssignSlotResources

pHalAssignSlotResources PcipSavedAssignSlotResources

Definition at line 19 of file hookhal.c.

Referenced by PciAssignSlotResources(), and PciHookHal().

◆ PcipSavedTranslateBusAddress

pHalTranslateBusAddress PcipSavedTranslateBusAddress

Definition at line 18 of file hookhal.c.

Referenced by PciHookHal().