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.

385 lines
8.5 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. ixhwsup.c
  5. Abstract:
  6. This module contains the IoXxx routines for the NT I/O system that
  7. are hardware dependent. Were these routines not hardware dependent,
  8. they would reside in the iosubs.c module.
  9. Author:
  10. Ken Reneris (kenr) July-28-1994
  11. Environment:
  12. Kernel mode
  13. Revision History:
  14. --*/
  15. #include "halp.h"
  16. #define DMALIMIT 7
  17. VOID HalpInitOtherBuses (VOID);
  18. ULONG
  19. HalpNoBusData (
  20. IN PVOID BusHandler,
  21. IN PVOID RootHandler,
  22. IN ULONG SlotNumber,
  23. IN PVOID Buffer,
  24. IN ULONG Offset,
  25. IN ULONG Length
  26. );
  27. ULONG HalpcGetCmosData (
  28. IN PVOID BusHandler,
  29. IN PVOID RootHandler,
  30. IN ULONG SlotNumber,
  31. IN PVOID Buffer,
  32. IN ULONG Offset,
  33. IN ULONG Length
  34. );
  35. ULONG HalpcSetCmosData (
  36. IN PVOID BusHandler,
  37. IN PVOID RootHandler,
  38. IN ULONG SlotNumber,
  39. IN PVOID Buffer,
  40. IN ULONG Offset,
  41. IN ULONG Length
  42. );
  43. ULONG HalpGetCmosData (
  44. IN ULONG BusNumber,
  45. IN ULONG SlotNumber,
  46. IN PVOID Buffer,
  47. IN ULONG Length
  48. );
  49. ULONG HalpSetCmosData (
  50. IN ULONG BusNumber,
  51. IN ULONG SlotNumber,
  52. IN PVOID Buffer,
  53. IN ULONG Length
  54. );
  55. HalpGetEisaData (
  56. IN PVOID BusHandler,
  57. IN PVOID RootHandler,
  58. IN ULONG SlotNumber,
  59. IN PVOID Buffer,
  60. IN ULONG Offset,
  61. IN ULONG Length
  62. );
  63. //
  64. // Prototype for system bus handlers
  65. //
  66. NTSTATUS
  67. HalpAdjustEisaResourceList (
  68. IN PVOID BusHandler,
  69. IN PVOID RootHandler,
  70. IN OUT PIO_RESOURCE_REQUIREMENTS_LIST *pResourceList
  71. );
  72. ULONG
  73. HalpGetEisaInterruptVector (
  74. IN PVOID BusHandler,
  75. IN PVOID RootHandler,
  76. IN ULONG BusInterruptLevel,
  77. IN ULONG BusInterruptVector,
  78. OUT PKIRQL Irql,
  79. OUT PKAFFINITY Affinity
  80. );
  81. BOOLEAN
  82. HalpTranslateIsaBusAddress (
  83. IN PVOID BusHandler,
  84. IN PVOID RootHandler,
  85. IN PHYSICAL_ADDRESS BusAddress,
  86. IN OUT PULONG AddressSpace,
  87. OUT PPHYSICAL_ADDRESS TranslatedAddress
  88. );
  89. BOOLEAN
  90. HalpTranslateEisaBusAddress (
  91. IN PVOID BusHandler,
  92. IN PVOID RootHandler,
  93. IN PHYSICAL_ADDRESS BusAddress,
  94. IN OUT PULONG AddressSpace,
  95. OUT PPHYSICAL_ADDRESS TranslatedAddress
  96. );
  97. VOID
  98. HalpRegisterInternalBusHandlers (
  99. VOID
  100. );
  101. NTSTATUS
  102. HalpHibernateHal (
  103. IN PBUS_HANDLER BusHandler,
  104. IN PBUS_HANDLER RootHandler
  105. );
  106. NTSTATUS
  107. HalpResumeHal (
  108. IN PBUS_HANDLER BusHandler,
  109. IN PBUS_HANDLER RootHandler
  110. );
  111. #ifdef MCA
  112. //
  113. // Default functionality of MCA handlers is the same as the Eisa handlers,
  114. // just use them
  115. //
  116. #define HalpGetMCAInterruptVector HalpGetEisaInterruptVector
  117. #define HalpAdjustMCAResourceList HalpAdjustEisaResourceList;
  118. HalpGetPosData (
  119. IN PVOID BusHandler,
  120. IN PVOID RootHandler,
  121. IN ULONG SlotNumber,
  122. IN PVOID Buffer,
  123. IN ULONG Offset,
  124. IN ULONG Length
  125. );
  126. #endif
  127. #ifdef ALLOC_PRAGMA
  128. #pragma alloc_text(INIT,HalpRegisterInternalBusHandlers)
  129. #pragma alloc_text(INIT,HalpAllocateBusHandler)
  130. #endif
  131. VOID
  132. HalpRegisterInternalBusHandlers (
  133. VOID
  134. )
  135. {
  136. PBUS_HANDLER Bus;
  137. if (KeGetCurrentPrcb()->Number) {
  138. // only need to do this once
  139. return ;
  140. }
  141. //
  142. // Initalize BusHandler data before registering any handlers
  143. //
  144. HalpInitBusHandler ();
  145. //
  146. // Build internal-bus 0, or system level bus
  147. //
  148. Bus = HalpAllocateBusHandler (
  149. Internal,
  150. ConfigurationSpaceUndefined,
  151. 0, // Internal BusNumber 0
  152. InterfaceTypeUndefined, // no parent bus
  153. 0,
  154. 0 // no bus specfic data
  155. );
  156. if (!Bus) {
  157. return;
  158. }
  159. Bus->GetInterruptVector = HalpGetSystemInterruptVector;
  160. Bus->TranslateBusAddress = HalpTranslateSystemBusAddress;
  161. #if 0
  162. //
  163. // Hibernate and resume the hal by getting notifications
  164. // for when this bus is hibernated or resumed. Since it's
  165. // the first bus to be added, it will be the last to hibernate
  166. // and the first to resume
  167. //
  168. Bus->HibernateBus = HalpHibernateHal;
  169. Bus->ResumeBus = HalpResumeHal;
  170. #endif
  171. #if defined(NEC_98)
  172. Bus = HalpAllocateBusHandler (Isa, ConfigurationSpaceUndefined, 0, Internal, 0, 0); // isa as child of Internal
  173. if (Bus) {
  174. Bus->GetBusData = HalpNoBusData;
  175. Bus->AdjustResourceList = HalpAdjustEisaResourceList;
  176. Bus->TranslateBusAddress = HalpTranslateEisaBusAddress;
  177. }
  178. #else //defined(NEC_98)
  179. //
  180. // Add handlers for Cmos config space.
  181. //
  182. Bus = HalpAllocateBusHandler (InterfaceTypeUndefined, Cmos, 0, -1, 0, 0);
  183. if (Bus) {
  184. Bus->GetBusData = HalpcGetCmosData;
  185. Bus->SetBusData = HalpcSetCmosData;
  186. }
  187. Bus = HalpAllocateBusHandler (InterfaceTypeUndefined, Cmos, 1, -1, 0, 0);
  188. if (Bus) {
  189. Bus->GetBusData = HalpcGetCmosData;
  190. Bus->SetBusData = HalpcSetCmosData;
  191. }
  192. #ifndef MCA
  193. //
  194. // Build Isa/Eisa bus #0
  195. //
  196. Bus = HalpAllocateBusHandler (Eisa, EisaConfiguration, 0, Internal, 0, 0);
  197. if (Bus) {
  198. Bus->GetBusData = HalpGetEisaData;
  199. Bus->GetInterruptVector = HalpGetEisaInterruptVector;
  200. Bus->AdjustResourceList = HalpAdjustEisaResourceList;
  201. Bus->TranslateBusAddress = HalpTranslateEisaBusAddress;
  202. }
  203. Bus = HalpAllocateBusHandler (Isa, ConfigurationSpaceUndefined, 0, Eisa, 0, 0);
  204. if (Bus) {
  205. Bus->GetBusData = HalpNoBusData;
  206. Bus->BusAddresses->Memory.Limit = 0xFFFFFF;
  207. Bus->TranslateBusAddress = HalpTranslateIsaBusAddress;
  208. }
  209. #else
  210. //
  211. // Build MCA bus #0
  212. //
  213. Bus = HalpAllocateBusHandler (MicroChannel, Pos, 0, Internal, 0, 0);
  214. if (Bus) {
  215. Bus->GetBusData = HalpGetPosData;
  216. Bus->GetInterruptVector = HalpGetMCAInterruptVector;
  217. Bus->AdjustResourceList = HalpAdjustMCAResourceList;
  218. }
  219. #endif
  220. #endif // defined(NEC_98)
  221. HalpInitOtherBuses ();
  222. }
  223. PBUS_HANDLER
  224. HalpAllocateBusHandler (
  225. IN INTERFACE_TYPE InterfaceType,
  226. IN BUS_DATA_TYPE BusDataType,
  227. IN ULONG BusNumber,
  228. IN INTERFACE_TYPE ParentBusInterfaceType,
  229. IN ULONG ParentBusNumber,
  230. IN ULONG BusSpecificData
  231. )
  232. /*++
  233. Routine Description:
  234. Stub function to map old style code into new HalRegisterBusHandler code.
  235. Note we can add our specific bus handler functions after this bus
  236. handler structure has been added since this is being done during
  237. hal initialization.
  238. --*/
  239. {
  240. PBUS_HANDLER Bus = NULL;
  241. //
  242. // Create bus handler - new style
  243. //
  244. HaliRegisterBusHandler (
  245. InterfaceType,
  246. BusDataType,
  247. BusNumber,
  248. ParentBusInterfaceType,
  249. ParentBusNumber,
  250. BusSpecificData,
  251. NULL,
  252. &Bus
  253. );
  254. if (!Bus) {
  255. return NULL;
  256. }
  257. if (InterfaceType != InterfaceTypeUndefined) {
  258. Bus->BusAddresses = ExAllocatePoolWithTag(SPRANGEPOOL,
  259. sizeof(SUPPORTED_RANGES),
  260. HAL_POOL_TAG);
  261. RtlZeroMemory(Bus->BusAddresses, sizeof(SUPPORTED_RANGES));
  262. Bus->BusAddresses->Version = BUS_SUPPORTED_RANGE_VERSION;
  263. Bus->BusAddresses->Dma.Limit = DMALIMIT;
  264. Bus->BusAddresses->Memory.Limit = 0xFFFFFFFF;
  265. Bus->BusAddresses->IO.Limit = 0xFFFF;
  266. Bus->BusAddresses->IO.SystemAddressSpace = 1;
  267. Bus->BusAddresses->PrefetchMemory.Base = 1;
  268. }
  269. return Bus;
  270. }
  271. //
  272. // C to Asm thunks for CMos
  273. //
  274. ULONG HalpcGetCmosData (
  275. IN PBUS_HANDLER BusHandler,
  276. IN PVOID RootHandler,
  277. IN ULONG SlotNumber,
  278. IN PVOID Buffer,
  279. IN ULONG Offset,
  280. IN ULONG Length
  281. )
  282. {
  283. // this interface should be rev'ed to support non-zero offsets
  284. if (Offset != 0) {
  285. return 0;
  286. }
  287. return HalpGetCmosData (BusHandler->BusNumber, SlotNumber, Buffer, Length);
  288. }
  289. ULONG HalpcSetCmosData (
  290. IN PBUS_HANDLER BusHandler,
  291. IN PVOID RootHandler,
  292. IN ULONG SlotNumber,
  293. IN PVOID Buffer,
  294. IN ULONG Offset,
  295. IN ULONG Length
  296. )
  297. {
  298. // this interface should be rev'ed to support non-zero offsets
  299. if (Offset != 0) {
  300. return 0;
  301. }
  302. return HalpSetCmosData (BusHandler->BusNumber, SlotNumber, Buffer, Length);
  303. }