Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

463 lines
12 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. pmbus.c
  5. Abstract:
  6. Implements functions that were done in
  7. previous HALs by bus handlers. Basically,
  8. these will be somewhat simplified versions
  9. since much of the code in the bus handlers
  10. has effectively been moved into bus
  11. drivers in NT5.
  12. Author:
  13. Jake Oshins (jakeo) 1-Dec-1997
  14. Environment:
  15. Kernel mode only.
  16. Revision History:
  17. --*/
  18. #include "halp.h"
  19. #include "pci.h"
  20. #include "pcip.h"
  21. ULONG HalpGetCmosData (
  22. IN ULONG BusNumber,
  23. IN ULONG SlotNumber,
  24. IN PVOID Buffer,
  25. IN ULONG Length
  26. );
  27. ULONG HalpSetCmosData (
  28. IN ULONG BusNumber,
  29. IN ULONG SlotNumber,
  30. IN PVOID Buffer,
  31. IN ULONG Length
  32. );
  33. HalpGetEisaData (
  34. IN PVOID BusHandler,
  35. IN PVOID RootHandler,
  36. IN ULONG SlotNumber,
  37. IN PVOID Buffer,
  38. IN ULONG Offset,
  39. IN ULONG Length
  40. );
  41. NTSTATUS
  42. HalpAssignSlotResources (
  43. IN PUNICODE_STRING RegistryPath,
  44. IN PUNICODE_STRING DriverClassName OPTIONAL,
  45. IN PDRIVER_OBJECT DriverObject,
  46. IN PDEVICE_OBJECT DeviceObject OPTIONAL,
  47. IN INTERFACE_TYPE BusType,
  48. IN ULONG BusNumber,
  49. IN ULONG SlotNumber,
  50. IN OUT PCM_RESOURCE_LIST *AllocatedResources
  51. );
  52. BOOLEAN
  53. HalpTranslateBusAddress(
  54. IN INTERFACE_TYPE InterfaceType,
  55. IN ULONG BusNumber,
  56. IN PHYSICAL_ADDRESS BusAddress,
  57. IN OUT PULONG AddressSpace,
  58. OUT PPHYSICAL_ADDRESS TranslatedAddress
  59. );
  60. BOOLEAN
  61. HalpFindBusAddressTranslation(
  62. IN PHYSICAL_ADDRESS BusAddress,
  63. IN OUT PULONG AddressSpace,
  64. OUT PPHYSICAL_ADDRESS TranslatedAddress,
  65. IN OUT PULONG_PTR Context,
  66. IN BOOLEAN NextBus
  67. );
  68. extern BUS_HANDLER HalpFakePciBusHandler;
  69. extern ULONG HalpMinPciBus;
  70. extern ULONG HalpMaxPciBus;
  71. extern ULONG HalpPicVectorRedirect[];
  72. VOID
  73. HalpGetNMICrashFlag (
  74. VOID
  75. );
  76. #ifdef ALLOC_PRAGMA
  77. #pragma alloc_text(INIT,HalpInitNonBusHandler)
  78. #pragma alloc_text(INIT,HalpInitializePciBus)
  79. #pragma alloc_text(PAGE,HalAssignSlotResources)
  80. #pragma alloc_text(PAGE,HalpAssignSlotResources)
  81. #endif
  82. VOID
  83. HalpInitNonBusHandler (
  84. VOID
  85. )
  86. {
  87. HALPDISPATCH->HalPciTranslateBusAddress = HalpTranslateBusAddress;
  88. HALPDISPATCH->HalPciAssignSlotResources = HalpAssignSlotResources;
  89. HALPDISPATCH->HalFindBusAddressTranslation = HalpFindBusAddressTranslation;
  90. }
  91. VOID
  92. HalpInitializePciBus(
  93. VOID
  94. )
  95. {
  96. HalpInitializePciStubs();
  97. //
  98. // Check if we should crashdump on NMI.
  99. //
  100. HalpGetNMICrashFlag();
  101. }
  102. NTSTATUS
  103. HalAdjustResourceList (
  104. IN OUT PIO_RESOURCE_REQUIREMENTS_LIST *pResourceList
  105. )
  106. {
  107. return STATUS_SUCCESS;
  108. }
  109. ULONG
  110. HalGetBusData(
  111. IN BUS_DATA_TYPE BusDataType,
  112. IN ULONG BusNumber,
  113. IN ULONG SlotNumber,
  114. IN PVOID Buffer,
  115. IN ULONG Length
  116. )
  117. {
  118. return HalGetBusDataByOffset (BusDataType,BusNumber,SlotNumber,Buffer,0,Length);
  119. }
  120. ULONG
  121. HalGetBusDataByOffset (
  122. IN BUS_DATA_TYPE BusDataType,
  123. IN ULONG BusNumber,
  124. IN ULONG SlotNumber,
  125. IN PVOID Buffer,
  126. IN ULONG Offset,
  127. IN ULONG Length
  128. )
  129. /*++
  130. Routine Description:
  131. Dispatcher for GetBusData
  132. --*/
  133. {
  134. PCI_SLOT_NUMBER slot;
  135. BUS_HANDLER bus;
  136. ULONG length;
  137. switch (BusDataType) {
  138. case PCIConfiguration:
  139. //
  140. // Hack. If the bus is outside of the known PCI busses, return
  141. // a length of zero.
  142. //
  143. if ((BusNumber < HalpMinPciBus) || (BusNumber > HalpMaxPciBus)) {
  144. return 0;
  145. }
  146. RtlCopyMemory(&bus, &HalpFakePciBusHandler, sizeof(BUS_HANDLER));
  147. bus.BusNumber = BusNumber;
  148. slot.u.AsULONG = SlotNumber;
  149. length = HalpGetPCIData(&bus,
  150. &bus,
  151. slot,
  152. Buffer,
  153. Offset,
  154. Length
  155. );
  156. return length;
  157. case Cmos:
  158. return HalpGetCmosData(0, SlotNumber, Buffer, Length);
  159. case EisaConfiguration:
  160. //
  161. // Fake a bus handler.
  162. //
  163. bus.BusNumber = 0;
  164. return HalpGetEisaData(&bus,
  165. &bus,
  166. SlotNumber,
  167. Buffer,
  168. Offset,
  169. Length
  170. );
  171. default:
  172. return 0;
  173. }
  174. }
  175. ULONG
  176. HalSetBusData(
  177. IN BUS_DATA_TYPE BusDataType,
  178. IN ULONG BusNumber,
  179. IN ULONG SlotNumber,
  180. IN PVOID Buffer,
  181. IN ULONG Length
  182. )
  183. {
  184. return HalSetBusDataByOffset (BusDataType,BusNumber,SlotNumber,Buffer,0,Length);
  185. }
  186. ULONG
  187. HalSetBusDataByOffset(
  188. IN BUS_DATA_TYPE BusDataType,
  189. IN ULONG BusNumber,
  190. IN ULONG SlotNumber,
  191. IN PVOID Buffer,
  192. IN ULONG Offset,
  193. IN ULONG Length
  194. )
  195. /*++
  196. Routine Description:
  197. Dispatcher for SetBusData
  198. --*/
  199. {
  200. PCI_SLOT_NUMBER slot;
  201. BUS_HANDLER bus;
  202. switch (BusDataType) {
  203. case PCIConfiguration:
  204. RtlCopyMemory(&bus, &HalpFakePciBusHandler, sizeof(BUS_HANDLER));
  205. bus.BusNumber = BusNumber;
  206. slot.u.AsULONG = SlotNumber;
  207. return HalpSetPCIData(&bus,
  208. &bus,
  209. slot,
  210. Buffer,
  211. Offset,
  212. Length
  213. );
  214. case Cmos:
  215. return HalpSetCmosData(0, SlotNumber, Buffer, Length);
  216. default:
  217. return 0;
  218. }
  219. }
  220. NTSTATUS
  221. HalAssignSlotResources (
  222. IN PUNICODE_STRING RegistryPath,
  223. IN PUNICODE_STRING DriverClassName OPTIONAL,
  224. IN PDRIVER_OBJECT DriverObject,
  225. IN PDEVICE_OBJECT DeviceObject OPTIONAL,
  226. IN INTERFACE_TYPE BusType,
  227. IN ULONG BusNumber,
  228. IN ULONG SlotNumber,
  229. IN OUT PCM_RESOURCE_LIST *AllocatedResources
  230. )
  231. {
  232. if (BusType == PCIBus) {
  233. //
  234. // Call through the HAL private dispatch table
  235. // for PCI-related translations. This is part
  236. // of transitioning the HAL out of the bus
  237. // management business.
  238. //
  239. return HALPDISPATCH->HalPciAssignSlotResources(RegistryPath,
  240. DriverClassName,
  241. DriverObject,
  242. DeviceObject,
  243. BusType,
  244. BusNumber,
  245. SlotNumber,
  246. AllocatedResources);
  247. } else {
  248. return HalpAssignSlotResources(RegistryPath,
  249. DriverClassName,
  250. DriverObject,
  251. DeviceObject,
  252. BusType,
  253. BusNumber,
  254. SlotNumber,
  255. AllocatedResources);
  256. }
  257. }
  258. NTSTATUS
  259. HalpAssignSlotResources (
  260. IN PUNICODE_STRING RegistryPath,
  261. IN PUNICODE_STRING DriverClassName OPTIONAL,
  262. IN PDRIVER_OBJECT DriverObject,
  263. IN PDEVICE_OBJECT DeviceObject OPTIONAL,
  264. IN INTERFACE_TYPE BusType,
  265. IN ULONG BusNumber,
  266. IN ULONG SlotNumber,
  267. IN OUT PCM_RESOURCE_LIST *AllocatedResources
  268. )
  269. /*++
  270. Routine Description:
  271. Dispatcher for AssignSlotResources
  272. --*/
  273. {
  274. BUS_HANDLER busHand;
  275. PAGED_CODE();
  276. switch (BusType) {
  277. case PCIBus:
  278. //
  279. // Fake a bus handler.
  280. //
  281. RtlCopyMemory(&busHand, &HalpFakePciBusHandler, sizeof(BUS_HANDLER));
  282. busHand.BusNumber = BusNumber;
  283. return HalpAssignPCISlotResources(&busHand,
  284. &busHand,
  285. RegistryPath,
  286. DriverClassName,
  287. DriverObject,
  288. DeviceObject,
  289. SlotNumber,
  290. AllocatedResources);
  291. default:
  292. return STATUS_NOT_IMPLEMENTED;
  293. }
  294. }
  295. ULONG
  296. HalGetInterruptVector(
  297. IN INTERFACE_TYPE InterfaceType,
  298. IN ULONG BusNumber,
  299. IN ULONG BusInterruptLevel,
  300. IN ULONG BusInterruptVector,
  301. OUT PKIRQL Irql,
  302. OUT PKAFFINITY Affinity
  303. )
  304. /*++
  305. Routine Description:
  306. Dispatcher for GetInterruptVector
  307. --*/
  308. {
  309. BUS_HANDLER busHand;
  310. //
  311. // If this is an ISA vector, pass it through the ISA vector
  312. // redirection table.
  313. //
  314. if (InterfaceType == Isa) {
  315. ASSERT(BusInterruptVector < PIC_VECTORS);
  316. BusInterruptVector = HalpPicVectorRedirect[BusInterruptVector];
  317. BusInterruptLevel = HalpPicVectorRedirect[BusInterruptLevel];
  318. }
  319. //
  320. // Fake bus handlers.
  321. //
  322. RtlCopyMemory(&busHand, &HalpFakePciBusHandler, sizeof(BUS_HANDLER));
  323. busHand.BusNumber = BusNumber;
  324. busHand.InterfaceType = InterfaceType;
  325. busHand.ParentHandler = &busHand;
  326. return HalpGetSystemInterruptVector(&busHand,
  327. &busHand,
  328. BusInterruptLevel,
  329. BusInterruptVector,
  330. Irql,
  331. Affinity);
  332. }
  333. BOOLEAN
  334. HalTranslateBusAddress(
  335. IN INTERFACE_TYPE InterfaceType,
  336. IN ULONG BusNumber,
  337. IN PHYSICAL_ADDRESS BusAddress,
  338. IN OUT PULONG AddressSpace,
  339. OUT PPHYSICAL_ADDRESS TranslatedAddress
  340. )
  341. {
  342. if (InterfaceType == PCIBus) {
  343. //
  344. // Call through the HAL private dispatch table
  345. // for PCI-related translations. This is part
  346. // of transitioning the HAL out of the bus
  347. // management business.
  348. //
  349. return HALPDISPATCH->HalPciTranslateBusAddress(InterfaceType,
  350. BusNumber,
  351. BusAddress,
  352. AddressSpace,
  353. TranslatedAddress);
  354. } else {
  355. return HalpTranslateBusAddress(InterfaceType,
  356. BusNumber,
  357. BusAddress,
  358. AddressSpace,
  359. TranslatedAddress);
  360. }
  361. };
  362. BOOLEAN
  363. HalpTranslateBusAddress(
  364. IN INTERFACE_TYPE InterfaceType,
  365. IN ULONG BusNumber,
  366. IN PHYSICAL_ADDRESS BusAddress,
  367. IN OUT PULONG AddressSpace,
  368. OUT PPHYSICAL_ADDRESS TranslatedAddress
  369. )
  370. /*++
  371. Routine Description:
  372. Dispatcher for TranslateBusAddress
  373. --*/
  374. {
  375. *TranslatedAddress = BusAddress;
  376. return TRUE;
  377. }