1 /* 2 * PROJECT: ReactOS HAL 3 * LICENSE: BSD - See COPYING.ARM in the top level directory 4 * FILE: hal/halx86/acpi/busemul.c 5 * PURPOSE: ACPI HAL Bus Handler Emulation Code 6 * PROGRAMMERS: ReactOS Portable Systems Group 7 */ 8 9 /* INCLUDES *******************************************************************/ 10 11 #include <hal.h> 12 #define NDEBUG 13 #include <debug.h> 14 15 /* GLOBALS ********************************************************************/ 16 17 /* PRIVATE FUNCTIONS **********************************************************/ 18 19 CODE_SEG("INIT") 20 VOID 21 NTAPI 22 HalpRegisterKdSupportFunctions(VOID) 23 { 24 /* Register PCI Device Functions */ 25 KdSetupPciDeviceForDebugging = HalpSetupPciDeviceForDebugging; 26 KdReleasePciDeviceforDebugging = HalpReleasePciDeviceForDebugging; 27 28 /* Register memory functions */ 29 #ifndef _MINIHAL_ 30 #if (NTDDI_VERSION >= NTDDI_VISTA) 31 KdMapPhysicalMemory64 = HalpMapPhysicalMemory64Vista; 32 KdUnmapVirtualAddress = HalpUnmapVirtualAddressVista; 33 #else 34 KdMapPhysicalMemory64 = HalpMapPhysicalMemory64; 35 KdUnmapVirtualAddress = HalpUnmapVirtualAddress; 36 #endif 37 #endif 38 39 /* Register ACPI stub */ 40 KdCheckPowerButton = HalpCheckPowerButton; 41 } 42 43 NTSTATUS 44 NTAPI 45 HalpAssignSlotResources(IN PUNICODE_STRING RegistryPath, 46 IN PUNICODE_STRING DriverClassName, 47 IN PDRIVER_OBJECT DriverObject, 48 IN PDEVICE_OBJECT DeviceObject, 49 IN INTERFACE_TYPE BusType, 50 IN ULONG BusNumber, 51 IN ULONG SlotNumber, 52 IN OUT PCM_RESOURCE_LIST *AllocatedResources) 53 { 54 BUS_HANDLER BusHandler; 55 PAGED_CODE(); 56 57 /* Only PCI is supported */ 58 if (BusType != PCIBus) return STATUS_NOT_IMPLEMENTED; 59 60 /* Setup fake PCI Bus handler */ 61 RtlCopyMemory(&BusHandler, &HalpFakePciBusHandler, sizeof(BUS_HANDLER)); 62 BusHandler.BusNumber = BusNumber; 63 64 /* Call the PCI function */ 65 return HalpAssignPCISlotResources(&BusHandler, 66 &BusHandler, 67 RegistryPath, 68 DriverClassName, 69 DriverObject, 70 DeviceObject, 71 SlotNumber, 72 AllocatedResources); 73 } 74 75 BOOLEAN 76 NTAPI 77 HalpTranslateBusAddress(IN INTERFACE_TYPE InterfaceType, 78 IN ULONG BusNumber, 79 IN PHYSICAL_ADDRESS BusAddress, 80 IN OUT PULONG AddressSpace, 81 OUT PPHYSICAL_ADDRESS TranslatedAddress) 82 { 83 /* Translation is easy */ 84 TranslatedAddress->QuadPart = BusAddress.QuadPart; 85 return TRUE; 86 } 87 88 BOOLEAN 89 NTAPI 90 HalpFindBusAddressTranslation(IN PHYSICAL_ADDRESS BusAddress, 91 IN OUT PULONG AddressSpace, 92 OUT PPHYSICAL_ADDRESS TranslatedAddress, 93 IN OUT PULONG_PTR Context, 94 IN BOOLEAN NextBus) 95 { 96 /* Make sure we have a context */ 97 if (!Context) return FALSE; 98 99 /* If we have data in the context, then this shouldn't be a new lookup */ 100 if ((*Context != 0) && (NextBus != FALSE)) return FALSE; 101 102 /* Return bus data */ 103 TranslatedAddress->QuadPart = BusAddress.QuadPart; 104 105 /* Set context value and return success */ 106 *Context = 1; 107 return TRUE; 108 } 109 110 /* PUBLIC FUNCTIONS **********************************************************/ 111 112 /* 113 * @implemented 114 */ 115 NTSTATUS 116 NTAPI 117 HalAdjustResourceList(IN OUT PIO_RESOURCE_REQUIREMENTS_LIST* pRequirementsList) 118 { 119 /* Deprecated, return success */ 120 return STATUS_SUCCESS; 121 } 122 123 /* 124 * @implemented 125 */ 126 NTSTATUS 127 NTAPI 128 HalAssignSlotResources(IN PUNICODE_STRING RegistryPath, 129 IN PUNICODE_STRING DriverClassName, 130 IN PDRIVER_OBJECT DriverObject, 131 IN PDEVICE_OBJECT DeviceObject, 132 IN INTERFACE_TYPE BusType, 133 IN ULONG BusNumber, 134 IN ULONG SlotNumber, 135 IN OUT PCM_RESOURCE_LIST *AllocatedResources) 136 { 137 /* Check the bus type */ 138 if (BusType != PCIBus) 139 { 140 /* Call our internal handler */ 141 return HalpAssignSlotResources(RegistryPath, 142 DriverClassName, 143 DriverObject, 144 DeviceObject, 145 BusType, 146 BusNumber, 147 SlotNumber, 148 AllocatedResources); 149 } 150 else 151 { 152 /* Call the PCI registered function */ 153 return HalPciAssignSlotResources(RegistryPath, 154 DriverClassName, 155 DriverObject, 156 DeviceObject, 157 PCIBus, 158 BusNumber, 159 SlotNumber, 160 AllocatedResources); 161 } 162 } 163 164 /* 165 * @implemented 166 */ 167 ULONG 168 NTAPI 169 HalGetBusData(IN BUS_DATA_TYPE BusDataType, 170 IN ULONG BusNumber, 171 IN ULONG SlotNumber, 172 IN PVOID Buffer, 173 IN ULONG Length) 174 { 175 /* Call the extended function */ 176 return HalGetBusDataByOffset(BusDataType, 177 BusNumber, 178 SlotNumber, 179 Buffer, 180 0, 181 Length); 182 } 183 184 /* 185 * @implemented 186 */ 187 ULONG 188 NTAPI 189 HalGetBusDataByOffset(IN BUS_DATA_TYPE BusDataType, 190 IN ULONG BusNumber, 191 IN ULONG SlotNumber, 192 IN PVOID Buffer, 193 IN ULONG Offset, 194 IN ULONG Length) 195 { 196 BUS_HANDLER BusHandler; 197 198 /* Look as the bus type */ 199 if (BusDataType == Cmos) 200 { 201 /* Call CMOS Function */ 202 return HalpGetCmosData(0, SlotNumber, Buffer, Length); 203 } 204 else if (BusDataType == EisaConfiguration) 205 { 206 /* FIXME: TODO */ 207 ASSERT(FALSE); 208 } 209 else if ((BusDataType == PCIConfiguration) && 210 (HalpPCIConfigInitialized) && 211 ((BusNumber >= HalpMinPciBus) && (BusNumber <= HalpMaxPciBus))) 212 { 213 /* Setup fake PCI Bus handler */ 214 RtlCopyMemory(&BusHandler, &HalpFakePciBusHandler, sizeof(BUS_HANDLER)); 215 BusHandler.BusNumber = BusNumber; 216 217 /* Call PCI function */ 218 return HalpGetPCIData(&BusHandler, 219 &BusHandler, 220 SlotNumber, 221 Buffer, 222 Offset, 223 Length); 224 } 225 226 /* Invalid bus */ 227 return 0; 228 } 229 230 /* 231 * @implemented 232 */ 233 ULONG 234 NTAPI 235 HalGetInterruptVector(IN INTERFACE_TYPE InterfaceType, 236 IN ULONG BusNumber, 237 IN ULONG BusInterruptLevel, 238 IN ULONG BusInterruptVector, 239 OUT PKIRQL Irql, 240 OUT PKAFFINITY Affinity) 241 { 242 /* Call the system bus translator */ 243 return HalpGetRootInterruptVector(BusInterruptLevel, 244 BusInterruptVector, 245 Irql, 246 Affinity); 247 } 248 249 /* 250 * @implemented 251 */ 252 ULONG 253 NTAPI 254 HalSetBusData(IN BUS_DATA_TYPE BusDataType, 255 IN ULONG BusNumber, 256 IN ULONG SlotNumber, 257 IN PVOID Buffer, 258 IN ULONG Length) 259 { 260 /* Call the extended function */ 261 return HalSetBusDataByOffset(BusDataType, 262 BusNumber, 263 SlotNumber, 264 Buffer, 265 0, 266 Length); 267 } 268 269 /* 270 * @implemented 271 */ 272 ULONG 273 NTAPI 274 HalSetBusDataByOffset(IN BUS_DATA_TYPE BusDataType, 275 IN ULONG BusNumber, 276 IN ULONG SlotNumber, 277 IN PVOID Buffer, 278 IN ULONG Offset, 279 IN ULONG Length) 280 { 281 BUS_HANDLER BusHandler; 282 283 /* Look as the bus type */ 284 if (BusDataType == Cmos) 285 { 286 /* Call CMOS Function */ 287 return HalpSetCmosData(0, SlotNumber, Buffer, Length); 288 } 289 else if ((BusDataType == PCIConfiguration) && (HalpPCIConfigInitialized)) 290 { 291 /* Setup fake PCI Bus handler */ 292 RtlCopyMemory(&BusHandler, &HalpFakePciBusHandler, sizeof(BUS_HANDLER)); 293 BusHandler.BusNumber = BusNumber; 294 295 /* Call PCI function */ 296 return HalpSetPCIData(&BusHandler, 297 &BusHandler, 298 SlotNumber, 299 Buffer, 300 Offset, 301 Length); 302 } 303 304 /* Invalid bus */ 305 return 0; 306 } 307 308 /* 309 * @implemented 310 */ 311 BOOLEAN 312 NTAPI 313 HalTranslateBusAddress(IN INTERFACE_TYPE InterfaceType, 314 IN ULONG BusNumber, 315 IN PHYSICAL_ADDRESS BusAddress, 316 IN OUT PULONG AddressSpace, 317 OUT PPHYSICAL_ADDRESS TranslatedAddress) 318 { 319 /* Look as the bus type */ 320 if (InterfaceType == PCIBus) 321 { 322 /* Call the PCI registered function */ 323 return HalPciTranslateBusAddress(PCIBus, 324 BusNumber, 325 BusAddress, 326 AddressSpace, 327 TranslatedAddress); 328 } 329 else 330 { 331 /* Translation is easy */ 332 TranslatedAddress->QuadPart = BusAddress.QuadPart; 333 return TRUE; 334 } 335 } 336 337 /* EOF */ 338