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.

480 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. ULONG
  42. HalpGetSystemInterruptVector (
  43. IN PBUS_HANDLER BusHandler,
  44. IN PBUS_HANDLER RootHandler,
  45. IN ULONG InterruptLevel,
  46. IN ULONG InterruptVector,
  47. OUT PKIRQL Irql,
  48. OUT PKAFFINITY Affinity
  49. );
  50. NTSTATUS
  51. HalpAssignSlotResources (
  52. IN PUNICODE_STRING RegistryPath,
  53. IN PUNICODE_STRING DriverClassName OPTIONAL,
  54. IN PDRIVER_OBJECT DriverObject,
  55. IN PDEVICE_OBJECT DeviceObject OPTIONAL,
  56. IN INTERFACE_TYPE BusType,
  57. IN ULONG BusNumber,
  58. IN ULONG SlotNumber,
  59. IN OUT PCM_RESOURCE_LIST *AllocatedResources
  60. );
  61. BOOLEAN
  62. HalpTranslateBusAddress(
  63. IN INTERFACE_TYPE InterfaceType,
  64. IN ULONG BusNumber,
  65. IN PHYSICAL_ADDRESS BusAddress,
  66. IN OUT PULONG AddressSpace,
  67. OUT PPHYSICAL_ADDRESS TranslatedAddress
  68. );
  69. BOOLEAN
  70. HalpFindBusAddressTranslation(
  71. IN PHYSICAL_ADDRESS BusAddress,
  72. IN OUT PULONG AddressSpace,
  73. OUT PPHYSICAL_ADDRESS TranslatedAddress,
  74. IN OUT PULONG_PTR Context,
  75. IN BOOLEAN NextBus
  76. );
  77. extern BUS_HANDLER HalpFakePciBusHandler;
  78. extern ULONG HalpMinPciBus;
  79. extern ULONG HalpMaxPciBus;
  80. extern ULONG HalpPicVectorRedirect[];
  81. #ifdef ALLOC_PRAGMA
  82. #pragma alloc_text(INIT,HalpInitNonBusHandler)
  83. #pragma alloc_text(PAGE,HalpAssignSlotResources)
  84. #if !defined(NO_LEGACY_DRIVERS)
  85. #pragma alloc_text(PAGE,HalAssignSlotResources)
  86. #endif
  87. #endif
  88. VOID
  89. HalpInitNonBusHandler (
  90. VOID
  91. )
  92. {
  93. HALPDISPATCH->HalPciTranslateBusAddress = HalpTranslateBusAddress;
  94. HALPDISPATCH->HalPciAssignSlotResources = HalpAssignSlotResources;
  95. HALPDISPATCH->HalFindBusAddressTranslation = HalpFindBusAddressTranslation;
  96. }
  97. #if !defined(NO_LEGACY_DRIVERS)
  98. NTSTATUS
  99. HalAdjustResourceList (
  100. IN OUT PIO_RESOURCE_REQUIREMENTS_LIST *pResourceList
  101. )
  102. {
  103. return STATUS_SUCCESS;
  104. }
  105. ULONG
  106. HalGetBusData(
  107. IN BUS_DATA_TYPE BusDataType,
  108. IN ULONG BusNumber,
  109. IN ULONG SlotNumber,
  110. IN PVOID Buffer,
  111. IN ULONG Length
  112. )
  113. {
  114. return HalGetBusDataByOffset (BusDataType,BusNumber,SlotNumber,Buffer,0,Length);
  115. }
  116. #endif // NO_LEGACY_DRIVERS
  117. ULONG
  118. HalGetBusDataByOffset (
  119. IN BUS_DATA_TYPE BusDataType,
  120. IN ULONG BusNumber,
  121. IN ULONG SlotNumber,
  122. IN PVOID Buffer,
  123. IN ULONG Offset,
  124. IN ULONG Length
  125. )
  126. /*++
  127. Routine Description:
  128. Dispatcher for GetBusData
  129. --*/
  130. {
  131. PCI_SLOT_NUMBER slot;
  132. BUS_HANDLER bus;
  133. ULONG length;
  134. switch (BusDataType) {
  135. case PCIConfiguration:
  136. //
  137. // Hack. If the bus is outside of the known PCI busses, return
  138. // a length of zero.
  139. //
  140. if ((BusNumber < HalpMinPciBus) || (BusNumber > HalpMaxPciBus)) {
  141. return 0;
  142. }
  143. RtlCopyMemory(&bus, &HalpFakePciBusHandler, sizeof(BUS_HANDLER));
  144. bus.BusNumber = BusNumber;
  145. slot.u.AsULONG = SlotNumber;
  146. length = HalpGetPCIData(&bus,
  147. &bus,
  148. slot,
  149. Buffer,
  150. Offset,
  151. Length
  152. );
  153. return length;
  154. case Cmos:
  155. return HalpGetCmosData(0, SlotNumber, Buffer, Length);
  156. #ifdef EISA_SUPPORTED
  157. case EisaConfiguration:
  158. //
  159. // Fake a bus handler.
  160. //
  161. bus.BusNumber = 0;
  162. return HalpGetEisaData(&bus,
  163. &bus,
  164. SlotNumber,
  165. Buffer,
  166. Offset,
  167. Length
  168. );
  169. #endif
  170. default:
  171. return 0;
  172. }
  173. }
  174. #if !defined(NO_LEGACY_DRIVERS)
  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. #endif // NO_LEGACY_DRIVERS
  187. ULONG
  188. HalSetBusDataByOffset(
  189. 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. /*++
  197. Routine Description:
  198. Dispatcher for SetBusData
  199. --*/
  200. {
  201. PCI_SLOT_NUMBER slot;
  202. BUS_HANDLER bus;
  203. switch (BusDataType) {
  204. case PCIConfiguration:
  205. RtlCopyMemory(&bus, &HalpFakePciBusHandler, sizeof(BUS_HANDLER));
  206. bus.BusNumber = BusNumber;
  207. slot.u.AsULONG = SlotNumber;
  208. return HalpSetPCIData(&bus,
  209. &bus,
  210. slot,
  211. Buffer,
  212. Offset,
  213. Length
  214. );
  215. case Cmos:
  216. return HalpSetCmosData(0, SlotNumber, Buffer, Length);
  217. default:
  218. return 0;
  219. }
  220. }
  221. #if !defined(NO_LEGACY_DRIVERS)
  222. NTSTATUS
  223. HalAssignSlotResources (
  224. IN PUNICODE_STRING RegistryPath,
  225. IN PUNICODE_STRING DriverClassName OPTIONAL,
  226. IN PDRIVER_OBJECT DriverObject,
  227. IN PDEVICE_OBJECT DeviceObject OPTIONAL,
  228. IN INTERFACE_TYPE BusType,
  229. IN ULONG BusNumber,
  230. IN ULONG SlotNumber,
  231. IN OUT PCM_RESOURCE_LIST *AllocatedResources
  232. )
  233. {
  234. if (BusType == PCIBus) {
  235. //
  236. // Call through the HAL private dispatch table
  237. // for PCI-related translations. This is part
  238. // of transitioning the HAL out of the bus
  239. // management business.
  240. //
  241. return HALPDISPATCH->HalPciAssignSlotResources(RegistryPath,
  242. DriverClassName,
  243. DriverObject,
  244. DeviceObject,
  245. BusType,
  246. BusNumber,
  247. SlotNumber,
  248. AllocatedResources);
  249. } else {
  250. return HalpAssignSlotResources(RegistryPath,
  251. DriverClassName,
  252. DriverObject,
  253. DeviceObject,
  254. BusType,
  255. BusNumber,
  256. SlotNumber,
  257. AllocatedResources);
  258. }
  259. }
  260. #endif // NO_LEGACY_DRIVERS
  261. NTSTATUS
  262. HalpAssignSlotResources (
  263. IN PUNICODE_STRING RegistryPath,
  264. IN PUNICODE_STRING DriverClassName OPTIONAL,
  265. IN PDRIVER_OBJECT DriverObject,
  266. IN PDEVICE_OBJECT DeviceObject OPTIONAL,
  267. IN INTERFACE_TYPE BusType,
  268. IN ULONG BusNumber,
  269. IN ULONG SlotNumber,
  270. IN OUT PCM_RESOURCE_LIST *AllocatedResources
  271. )
  272. /*++
  273. Routine Description:
  274. Dispatcher for AssignSlotResources
  275. --*/
  276. {
  277. BUS_HANDLER busHand;
  278. PAGED_CODE();
  279. switch (BusType) {
  280. case PCIBus:
  281. //
  282. // Fake a bus handler.
  283. //
  284. RtlCopyMemory(&busHand, &HalpFakePciBusHandler, sizeof(BUS_HANDLER));
  285. busHand.BusNumber = BusNumber;
  286. return HalpAssignPCISlotResources(&busHand,
  287. &busHand,
  288. RegistryPath,
  289. DriverClassName,
  290. DriverObject,
  291. DeviceObject,
  292. SlotNumber,
  293. AllocatedResources);
  294. default:
  295. return STATUS_NOT_IMPLEMENTED;
  296. }
  297. }
  298. #if !defined(NO_LEGACY_DRIVERS)
  299. ULONG
  300. HalGetInterruptVector(
  301. IN INTERFACE_TYPE InterfaceType,
  302. IN ULONG BusNumber,
  303. IN ULONG BusInterruptLevel,
  304. IN ULONG BusInterruptVector,
  305. OUT PKIRQL Irql,
  306. OUT PKAFFINITY Affinity
  307. )
  308. /*++
  309. Routine Description:
  310. Dispatcher for GetInterruptVector
  311. --*/
  312. {
  313. BUS_HANDLER busHand;
  314. //
  315. // If this is an ISA vector, pass it through the ISA vector
  316. // redirection table.
  317. //
  318. if (InterfaceType == Isa) {
  319. ASSERT(BusInterruptVector < PIC_VECTORS);
  320. BusInterruptVector = HalpPicVectorRedirect[BusInterruptVector];
  321. BusInterruptLevel = HalpPicVectorRedirect[BusInterruptLevel];
  322. }
  323. //
  324. // Fake bus handlers.
  325. //
  326. RtlCopyMemory(&busHand, &HalpFakePciBusHandler, sizeof(BUS_HANDLER));
  327. busHand.BusNumber = BusNumber;
  328. busHand.InterfaceType = InterfaceType;
  329. busHand.ParentHandler = &busHand;
  330. return HalpGetSystemInterruptVector(&busHand,
  331. &busHand,
  332. BusInterruptLevel,
  333. BusInterruptVector,
  334. Irql,
  335. Affinity);
  336. }
  337. #endif // NO_LEGACY_DRIVERS
  338. BOOLEAN
  339. HalTranslateBusAddress(
  340. IN INTERFACE_TYPE InterfaceType,
  341. IN ULONG BusNumber,
  342. IN PHYSICAL_ADDRESS BusAddress,
  343. IN OUT PULONG AddressSpace,
  344. OUT PPHYSICAL_ADDRESS TranslatedAddress
  345. )
  346. {
  347. if (InterfaceType == PCIBus) {
  348. //
  349. // Call through the HAL private dispatch table
  350. // for PCI-related translations. This is part
  351. // of transitioning the HAL out of the bus
  352. // management business.
  353. //
  354. return HALPDISPATCH->HalPciTranslateBusAddress(InterfaceType,
  355. BusNumber,
  356. BusAddress,
  357. AddressSpace,
  358. TranslatedAddress);
  359. } else {
  360. return HalpTranslateBusAddress(InterfaceType,
  361. BusNumber,
  362. BusAddress,
  363. AddressSpace,
  364. TranslatedAddress);
  365. }
  366. };
  367. BOOLEAN
  368. HalpTranslateBusAddress(
  369. IN INTERFACE_TYPE InterfaceType,
  370. IN ULONG BusNumber,
  371. IN PHYSICAL_ADDRESS BusAddress,
  372. IN OUT PULONG AddressSpace,
  373. OUT PPHYSICAL_ADDRESS TranslatedAddress
  374. )
  375. /*++
  376. Routine Description:
  377. Dispatcher for TranslateBusAddress
  378. --*/
  379. {
  380. //*(&TranslatedAddress->QuadPart) = BusAddress.QuadPart;
  381. *(&TranslatedAddress->LowPart) = BusAddress.LowPart;
  382. *(&TranslatedAddress->HighPart) = BusAddress.HighPart;
  383. return TRUE;
  384. }