Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenhookhal.c
Go to the documentation of this file.
00001 /* 00002 * PROJECT: ReactOS PCI Bus Driver 00003 * LICENSE: BSD - See COPYING.ARM in the top level directory 00004 * FILE: drivers/bus/pci/hookhal.c 00005 * PURPOSE: HAL Bus Handler Dispatch Routine Support 00006 * PROGRAMMERS: ReactOS Portable Systems Group 00007 */ 00008 00009 /* INCLUDES *******************************************************************/ 00010 00011 #include <pci.h> 00012 #define NDEBUG 00013 #include <debug.h> 00014 00015 /* GLOBALS ********************************************************************/ 00016 00017 pHalTranslateBusAddress PcipSavedTranslateBusAddress; 00018 pHalAssignSlotResources PcipSavedAssignSlotResources; 00019 00020 /* FUNCTIONS ******************************************************************/ 00021 00022 BOOLEAN 00023 NTAPI 00024 PciTranslateBusAddress(IN INTERFACE_TYPE InterfaceType, 00025 IN ULONG BusNumber, 00026 IN PHYSICAL_ADDRESS BusAddress, 00027 OUT PULONG AddressSpace, 00028 OUT PPHYSICAL_ADDRESS TranslatedAddress) 00029 { 00030 /* FIXME: Broken translation */ 00031 UNIMPLEMENTED; 00032 TranslatedAddress->QuadPart = BusAddress.QuadPart; 00033 return TRUE; 00034 } 00035 00036 PPCI_PDO_EXTENSION 00037 NTAPI 00038 PciFindPdoByLocation(IN ULONG BusNumber, 00039 IN ULONG SlotNumber) 00040 { 00041 PPCI_FDO_EXTENSION DeviceExtension; 00042 PPCI_PDO_EXTENSION PdoExtension; 00043 PCI_SLOT_NUMBER PciSlot; 00044 PciSlot.u.AsULONG = SlotNumber; 00045 00046 /* Acquire the global lock */ 00047 KeEnterCriticalRegion(); 00048 KeWaitForSingleObject(&PciGlobalLock, Executive, KernelMode, FALSE, NULL); 00049 00050 /* Now search for the extension */ 00051 DeviceExtension = (PPCI_FDO_EXTENSION)PciFdoExtensionListHead.Next; 00052 while (DeviceExtension) 00053 { 00054 /* If we found it, break out */ 00055 if (DeviceExtension->BaseBus == BusNumber) break; 00056 00057 /* Move to the next device */ 00058 DeviceExtension = (PPCI_FDO_EXTENSION)DeviceExtension->List.Next; 00059 } 00060 00061 /* Release the global lock */ 00062 KeSetEvent(&PciGlobalLock, IO_NO_INCREMENT, FALSE); 00063 KeLeaveCriticalRegion(); 00064 00065 /* Check if the device extension for the bus was found */ 00066 if (!DeviceExtension) 00067 { 00068 /* It wasn't, bail out */ 00069 DPRINT1("Pci: Could not find PCI bus FDO. Bus Number = 0x%x\n", BusNumber); 00070 return NULL; 00071 } 00072 00073 /* Acquire this device's lock */ 00074 KeEnterCriticalRegion(); 00075 KeWaitForSingleObject(&DeviceExtension->ChildListLock, 00076 Executive, 00077 KernelMode, 00078 FALSE, 00079 NULL); 00080 00081 /* Loop every child PDO */ 00082 for (PdoExtension = DeviceExtension->ChildPdoList; 00083 PdoExtension; 00084 PdoExtension = PdoExtension->Next) 00085 { 00086 /* Check if the function number and header data matches */ 00087 if ((PdoExtension->Slot.u.bits.FunctionNumber == PciSlot.u.bits.FunctionNumber) && 00088 (PdoExtension->Slot.u.bits.DeviceNumber == PciSlot.u.bits.DeviceNumber)) 00089 { 00090 /* This is considered to be the same PDO */ 00091 ASSERT(PdoExtension->Slot.u.AsULONG == PciSlot.u.AsULONG); 00092 break; 00093 } 00094 } 00095 00096 /* Release this device's lock */ 00097 KeSetEvent(&DeviceExtension->ChildListLock, IO_NO_INCREMENT, FALSE); 00098 KeLeaveCriticalRegion(); 00099 00100 /* Check if we found something */ 00101 if (!PdoExtension) 00102 { 00103 /* Let the debugger know */ 00104 DPRINT1("Pci: Could not find PDO for device @ %x.%x.%x\n", 00105 BusNumber, 00106 PciSlot.u.bits.DeviceNumber, 00107 PciSlot.u.bits.FunctionNumber); 00108 } 00109 00110 /* If the search found something, this is non-NULL, otherwise it's NULL */ 00111 return PdoExtension; 00112 } 00113 00114 NTSTATUS 00115 NTAPI 00116 PciAssignSlotResources(IN PUNICODE_STRING RegistryPath, 00117 IN PUNICODE_STRING DriverClassName OPTIONAL, 00118 IN PDRIVER_OBJECT DriverObject, 00119 IN PDEVICE_OBJECT DeviceObject, 00120 IN INTERFACE_TYPE BusType, 00121 IN ULONG BusNumber, 00122 IN ULONG SlotNumber, 00123 IN OUT PCM_RESOURCE_LIST *AllocatedResources) 00124 { 00125 PIO_RESOURCE_REQUIREMENTS_LIST RequirementsList = NULL; 00126 PCM_RESOURCE_LIST Resources = NULL; 00127 PCI_COMMON_HEADER PciData; 00128 PPCI_PDO_EXTENSION PdoExtension; 00129 NTSTATUS Status; 00130 PDEVICE_OBJECT ExistingDeviceObject; 00131 PAGED_CODE(); 00132 ASSERT(PcipSavedAssignSlotResources); 00133 ASSERT(BusType == PCIBus); 00134 00135 /* Assume no resources */ 00136 *AllocatedResources = NULL; 00137 00138 /* Find the PDO for this slot and make sure it exists and is started */ 00139 PdoExtension = PciFindPdoByLocation(BusNumber, SlotNumber); 00140 if (!PdoExtension) return STATUS_DEVICE_DOES_NOT_EXIST; 00141 if (PdoExtension->DeviceState == PciNotStarted) return STATUS_INVALID_OWNER; 00142 00143 /* Acquire the global lock while we attempt to assign resources */ 00144 KeEnterCriticalRegion(); 00145 KeWaitForSingleObject(&PciGlobalLock, Executive, KernelMode, FALSE, NULL); 00146 do 00147 { 00148 /* Make sure we're not on the PDO for some reason */ 00149 ASSERT(DeviceObject != PdoExtension->PhysicalDeviceObject); 00150 00151 /* Read the PCI header and cache the routing information */ 00152 PciReadDeviceConfig(PdoExtension, &PciData, 0, PCI_COMMON_HDR_LENGTH); 00153 Status = PciCacheLegacyDeviceRouting(DeviceObject, 00154 BusNumber, 00155 SlotNumber, 00156 PciData.u.type0.InterruptLine, 00157 PciData.u.type0.InterruptPin, 00158 PciData.BaseClass, 00159 PciData.SubClass, 00160 PdoExtension->ParentFdoExtension-> 00161 PhysicalDeviceObject, 00162 PdoExtension, 00163 &ExistingDeviceObject); 00164 if (NT_SUCCESS(Status)) 00165 { 00166 /* Manually build the requirements for this device, and mark it legacy */ 00167 Status = PciBuildRequirementsList(PdoExtension, 00168 &PciData, 00169 &RequirementsList); 00170 PdoExtension->LegacyDriver = TRUE; 00171 if (NT_SUCCESS(Status)) 00172 { 00173 /* Now call the legacy Pnp function to actually assign resources */ 00174 Status = IoAssignResources(RegistryPath, 00175 DriverClassName, 00176 DriverObject, 00177 DeviceObject, 00178 RequirementsList, 00179 &Resources); 00180 if (NT_SUCCESS(Status)) 00181 { 00182 /* Resources are ready, so enable all decodes */ 00183 PdoExtension->CommandEnables |= (PCI_ENABLE_IO_SPACE | 00184 PCI_ENABLE_MEMORY_SPACE | 00185 PCI_ENABLE_BUS_MASTER); 00186 00187 /* Compute new resource settings based on what PnP assigned */ 00188 PciComputeNewCurrentSettings(PdoExtension, Resources); 00189 00190 /* Set these new resources on the device */ 00191 Status = PciSetResources(PdoExtension, TRUE, TRUE); 00192 if (NT_SUCCESS(Status)) 00193 { 00194 /* Some work needs to happen here to handle this */ 00195 ASSERT(Resources->Count == 1); 00196 //ASSERT(PartialList->Count > 0); 00197 00198 UNIMPLEMENTED; 00199 00200 /* Return the allocated resources, and success */ 00201 *AllocatedResources = Resources; 00202 Resources = NULL; 00203 Status = STATUS_SUCCESS; 00204 } 00205 } 00206 else 00207 { 00208 /* If assignment failed, no resources should exist */ 00209 ASSERT(Resources == NULL); 00210 } 00211 00212 /* If assignment succeeed, then we are done */ 00213 if (NT_SUCCESS(Status)) break; 00214 } 00215 00216 /* Otherwise, cache the new routing */ 00217 PciCacheLegacyDeviceRouting(ExistingDeviceObject, 00218 BusNumber, 00219 SlotNumber, 00220 PciData.u.type0.InterruptLine, 00221 PciData.u.type0.InterruptPin, 00222 PciData.BaseClass, 00223 PciData.SubClass, 00224 PdoExtension->ParentFdoExtension-> 00225 PhysicalDeviceObject, 00226 PdoExtension, 00227 NULL); 00228 } 00229 } while (0); 00230 00231 /* Release the lock */ 00232 KeSetEvent(&PciGlobalLock, 0, 0); 00233 KeLeaveCriticalRegion(); 00234 00235 /* Free any temporary resource data and return the status */ 00236 if (RequirementsList) ExFreePoolWithTag(RequirementsList, 0); 00237 if (Resources) ExFreePoolWithTag(Resources, 0); 00238 return Status; 00239 } 00240 00241 VOID 00242 NTAPI 00243 PciHookHal(VOID) 00244 { 00245 /* Save the old HAL routines */ 00246 ASSERT(PcipSavedAssignSlotResources == NULL); 00247 ASSERT(PcipSavedTranslateBusAddress == NULL); 00248 PcipSavedAssignSlotResources = HalPciAssignSlotResources; 00249 PcipSavedTranslateBusAddress = HalPciTranslateBusAddress; 00250 00251 /* Take over the HAL's Bus Handler functions */ 00252 // HalPciAssignSlotResources = PciAssignSlotResources; 00253 HalPciTranslateBusAddress = PciTranslateBusAddress; 00254 } 00255 00256 /* EOF */ Generated on Sat May 26 2012 04:26:03 for ReactOS by
1.7.6.1
|