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.

451 lines
9.8 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. ixbusdat.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. Environment:
  11. Kernel mode
  12. Revision History:
  13. --*/
  14. #include "bootx86.h"
  15. #include "arc.h"
  16. #include "ixfwhal.h"
  17. #include "eisa.h"
  18. #include "ntconfig.h"
  19. ULONG
  20. HalpGetCmosData(
  21. IN ULONG BusNumber,
  22. IN ULONG SlotNumber,
  23. IN PVOID Buffer,
  24. IN ULONG Length
  25. );
  26. ULONG
  27. HalpGetEisaData(
  28. IN ULONG BusNumber,
  29. IN ULONG SlotNumber,
  30. IN PVOID Buffer,
  31. IN ULONG Offset,
  32. IN ULONG Length
  33. );
  34. ULONG
  35. HalpGetPCIData(
  36. IN ULONG BusNumber,
  37. IN ULONG SlotNumber,
  38. IN PVOID Buffer,
  39. IN ULONG Offset,
  40. IN ULONG Length
  41. );
  42. ULONG
  43. HalpSetPCIData(
  44. IN ULONG BusNumber,
  45. IN ULONG SlotNumber,
  46. IN PVOID Buffer,
  47. IN ULONG Offset,
  48. IN ULONG Length
  49. );
  50. NTSTATUS
  51. HalpAssignPCISlotResources (
  52. IN ULONG BusNumber,
  53. IN ULONG Slot,
  54. IN OUT PCM_RESOURCE_LIST *AllocatedResources
  55. );
  56. /*
  57. *
  58. * Router functions. Routes each call to specific handler
  59. *
  60. */
  61. ULONG
  62. HalGetBusData(
  63. IN BUS_DATA_TYPE BusDataType,
  64. IN ULONG BusNumber,
  65. IN ULONG SlotNumber,
  66. IN PVOID Buffer,
  67. IN ULONG Length
  68. )
  69. {
  70. return HalGetBusDataByOffset (BusDataType,BusNumber,SlotNumber,Buffer,0,Length);
  71. }
  72. ULONG
  73. HalGetBusDataByOffset (
  74. IN BUS_DATA_TYPE BusDataType,
  75. IN ULONG BusNumber,
  76. IN ULONG Slot,
  77. IN PVOID Buffer,
  78. IN ULONG Offset,
  79. IN ULONG Length
  80. )
  81. /*++
  82. Routine Description:
  83. Dispatcher for GetBusData
  84. --*/
  85. {
  86. switch (BusDataType) {
  87. case Cmos:
  88. if (Offset != 0) {
  89. return 0;
  90. }
  91. return HalpGetCmosData(BusNumber, Slot, Buffer, Length);
  92. case EisaConfiguration:
  93. return HalpGetEisaData(BusNumber, Slot, Buffer, Offset, Length);
  94. case PCIConfiguration:
  95. return HalpGetPCIData(BusNumber, Slot, Buffer, Offset, Length);
  96. }
  97. return 0;
  98. }
  99. ULONG
  100. HalSetBusData(
  101. IN BUS_DATA_TYPE BusDataType,
  102. IN ULONG BusNumber,
  103. IN ULONG SlotNumber,
  104. IN PVOID Buffer,
  105. IN ULONG Length
  106. )
  107. {
  108. return HalSetBusDataByOffset (BusDataType,BusNumber,SlotNumber,Buffer,0,Length);
  109. }
  110. ULONG
  111. HalSetBusDataByOffset(
  112. IN BUS_DATA_TYPE BusDataType,
  113. IN ULONG BusNumber,
  114. IN ULONG Slot,
  115. IN PVOID Buffer,
  116. IN ULONG Offset,
  117. IN ULONG Length
  118. )
  119. /*++
  120. Routine Description:
  121. Dispatcher for SetBusData
  122. --*/
  123. {
  124. switch (BusDataType) {
  125. case PCIConfiguration:
  126. return HalpSetPCIData(BusNumber, Slot, Buffer, Offset, Length);
  127. }
  128. return 0;
  129. }
  130. NTSTATUS
  131. HalAssignSlotResources (
  132. IN PUNICODE_STRING RegistryPath,
  133. IN PUNICODE_STRING DriverClassName OPTIONAL,
  134. IN PDRIVER_OBJECT DriverObject,
  135. IN PDEVICE_OBJECT DeviceObject OPTIONAL,
  136. IN INTERFACE_TYPE BusType,
  137. IN ULONG BusNumber,
  138. IN ULONG SlotNumber,
  139. IN OUT PCM_RESOURCE_LIST *AllocatedResources
  140. )
  141. /*++
  142. Routine Description:
  143. Dispatcher for AssignSlotResources
  144. --*/
  145. {
  146. UNREFERENCED_PARAMETER( DeviceObject );
  147. UNREFERENCED_PARAMETER( DriverObject );
  148. UNREFERENCED_PARAMETER( DriverClassName );
  149. UNREFERENCED_PARAMETER( RegistryPath );
  150. switch (BusType) {
  151. case PCIBus:
  152. return HalpAssignPCISlotResources (
  153. BusNumber,
  154. SlotNumber,
  155. AllocatedResources
  156. );
  157. default:
  158. break;
  159. }
  160. return STATUS_NOT_FOUND;
  161. }
  162. /**
  163. **
  164. ** Standard PC bus functions
  165. **
  166. **/
  167. BOOLEAN
  168. HalTranslateBusAddress(
  169. IN INTERFACE_TYPE InterfaceType,
  170. IN ULONG BusNumber,
  171. IN PHYSICAL_ADDRESS BusAddress,
  172. IN OUT PULONG AddressSpace,
  173. OUT PPHYSICAL_ADDRESS TranslatedAddress
  174. )
  175. /*++
  176. Routine Description:
  177. This function translates a bus-relative address space and address into
  178. a system physical address.
  179. Arguments:
  180. BusNumber - Supplies the bus number. This is ignored on
  181. standard x86 systems
  182. BusAddress - Supplies the bus-relative address
  183. AddressSpace - Supplies the address space number.
  184. Returns the host address space number.
  185. AddressSpace == 0 => I/O space
  186. AddressSpace == 1 => memory space
  187. TranslatedAddress - Pointer to a physical_address.
  188. Return Value:
  189. System physical address corresponding to the supplied bus relative
  190. address and bus address number.
  191. --*/
  192. {
  193. UNREFERENCED_PARAMETER( AddressSpace );
  194. UNREFERENCED_PARAMETER( BusNumber );
  195. UNREFERENCED_PARAMETER( InterfaceType );
  196. TranslatedAddress->HighPart = 0;
  197. TranslatedAddress->LowPart = BusAddress.LowPart;
  198. return(TRUE);
  199. }
  200. ULONG
  201. HalpGetEisaData (
  202. IN ULONG BusNumber,
  203. IN ULONG SlotNumber,
  204. IN PVOID Buffer,
  205. IN ULONG Offset,
  206. IN ULONG Length
  207. )
  208. /*--
  209. Arguments:
  210. BusDataType - Supplies the type of bus.
  211. BusNumber - Indicates which bus.
  212. Buffer - Supplies the space to store the data.
  213. Length - Supplies a count in bytes of the maximum amount to return.
  214. Return Value:
  215. Returns the amount of data stored into the buffer.
  216. --*/
  217. {
  218. ULONG DataLength = 0;
  219. ULONG i;
  220. ULONG TotalDataSize;
  221. ULONG SlotDataSize = 0;
  222. ULONG PartialCount;
  223. PCONFIGURATION_COMPONENT_DATA ConfigData;
  224. PCM_EISA_SLOT_INFORMATION SlotInformation = NULL;
  225. PCM_PARTIAL_RESOURCE_LIST Descriptor;
  226. PCM_PARTIAL_RESOURCE_DESCRIPTOR PartialResource;
  227. BOOLEAN Found = FALSE;
  228. UNREFERENCED_PARAMETER( BusNumber );
  229. if (MachineType != MACHINE_TYPE_EISA) {
  230. return 0;
  231. }
  232. ConfigData = KeFindConfigurationEntry(
  233. FwConfigurationTree,
  234. AdapterClass,
  235. EisaAdapter,
  236. NULL
  237. );
  238. if (ConfigData == NULL) {
  239. DbgPrint("HalGetBusData: KeFindConfigurationEntry failed\n");
  240. return(0);
  241. }
  242. Descriptor = ConfigData->ConfigurationData;
  243. PartialResource = Descriptor->PartialDescriptors;
  244. PartialCount = Descriptor->Count;
  245. for (i = 0; i < PartialCount; i++) {
  246. //
  247. // Do each partial Resource
  248. //
  249. switch (PartialResource->Type) {
  250. case CmResourceTypeNull:
  251. case CmResourceTypePort:
  252. case CmResourceTypeInterrupt:
  253. case CmResourceTypeMemory:
  254. case CmResourceTypeDma:
  255. //
  256. // We dont care about these.
  257. //
  258. PartialResource++;
  259. break;
  260. case CmResourceTypeDeviceSpecific:
  261. //
  262. // Bingo!
  263. //
  264. TotalDataSize = PartialResource->u.DeviceSpecificData.DataSize;
  265. SlotInformation = (PCM_EISA_SLOT_INFORMATION)
  266. ((PUCHAR)PartialResource +
  267. sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR));
  268. while (((LONG)TotalDataSize) > 0) {
  269. if (SlotInformation->ReturnCode == EISA_EMPTY_SLOT) {
  270. SlotDataSize = sizeof(CM_EISA_SLOT_INFORMATION);
  271. } else {
  272. SlotDataSize = sizeof(CM_EISA_SLOT_INFORMATION) +
  273. SlotInformation->NumberFunctions *
  274. sizeof(CM_EISA_FUNCTION_INFORMATION);
  275. }
  276. if (SlotDataSize > TotalDataSize) {
  277. //
  278. // Something is wrong again
  279. //
  280. DbgPrint("HalGetBusData: SlotDataSize > TotalDataSize\n");
  281. return(0);
  282. }
  283. if (SlotNumber != 0) {
  284. SlotNumber--;
  285. SlotInformation = (PCM_EISA_SLOT_INFORMATION)
  286. ((PUCHAR)SlotInformation + SlotDataSize);
  287. TotalDataSize -= SlotDataSize;
  288. continue;
  289. }
  290. //
  291. // This is our slot
  292. //
  293. Found = TRUE;
  294. break;
  295. }
  296. //
  297. // End loop
  298. //
  299. i = PartialCount;
  300. break;
  301. default:
  302. #if DBG
  303. DbgPrint("Bad Data in registry!\n");
  304. #endif
  305. return(0);
  306. }
  307. }
  308. if (Found) {
  309. //
  310. // As a hack if the length is zero then the buffer points to a
  311. // PVOID where the pointer to the data should be stored. This is
  312. // done in the loader because we quickly run out of heap scaning
  313. // all of the EISA configuration data.
  314. //
  315. if (Length == 0) {
  316. //
  317. // Return the pointer to the mini-port driver.
  318. //
  319. *((PVOID *)Buffer) = SlotInformation;
  320. return(SlotDataSize);
  321. }
  322. i = Length + Offset;
  323. if (i > SlotDataSize) {
  324. i = SlotDataSize;
  325. }
  326. DataLength = i - Offset;
  327. RtlMoveMemory(Buffer, ((PUCHAR) SlotInformation + Offset), DataLength);
  328. }
  329. return(DataLength);
  330. }