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.

407 lines
9.2 KiB

  1. /*++
  2. Copyright (c) 1997-2000 Microsoft Corporation
  3. Module Name:
  4. busintrf.c
  5. Abstract:
  6. This module implements the "bus handler" interfaces supported
  7. by the PCI driver.
  8. Author:
  9. Peter Johnston (peterj) 6-Jun-1997
  10. Revision History:
  11. --*/
  12. #include "pcip.h"
  13. #define BUSINTRF_VERSION 1
  14. //
  15. // Prototypes for routines exposed only thru the "interface"
  16. // mechanism.
  17. //
  18. NTSTATUS
  19. busintrf_Constructor(
  20. PVOID DeviceExtension,
  21. PVOID PciInterface,
  22. PVOID InterfaceSpecificData,
  23. USHORT Version,
  24. USHORT Size,
  25. PINTERFACE InterfaceReturn
  26. );
  27. VOID
  28. busintrf_Reference(
  29. IN PVOID Context
  30. );
  31. VOID
  32. busintrf_Dereference(
  33. IN PVOID Context
  34. );
  35. NTSTATUS
  36. busintrf_Initializer(
  37. IN PPCI_ARBITER_INSTANCE Instance
  38. );
  39. BOOLEAN
  40. PciPnpTranslateBusAddress(
  41. IN PVOID Context,
  42. IN PHYSICAL_ADDRESS BusAddress,
  43. IN ULONG Length,
  44. IN OUT PULONG AddressSpace,
  45. OUT PPHYSICAL_ADDRESS TranslatedAddress
  46. );
  47. struct _DMA_ADAPTER *
  48. PciPnpGetDmaAdapter(
  49. IN PVOID Context,
  50. IN struct _DEVICE_DESCRIPTION *DeviceDescriptor,
  51. OUT PULONG NumberOfMapRegisters
  52. );
  53. ULONG
  54. PciPnpReadConfig(
  55. IN PVOID Context,
  56. IN ULONG WhichSpace,
  57. IN PVOID Buffer,
  58. IN ULONG Offset,
  59. IN ULONG Length
  60. );
  61. ULONG
  62. PciPnpWriteConfig(
  63. IN PVOID Context,
  64. IN ULONG WhichSpace,
  65. IN PVOID Buffer,
  66. IN ULONG Offset,
  67. IN ULONG Length
  68. );
  69. //
  70. // Define the Bus Interface "Interface" structure.
  71. //
  72. PCI_INTERFACE BusHandlerInterface = {
  73. &GUID_BUS_INTERFACE_STANDARD, // InterfaceType
  74. sizeof(BUS_INTERFACE_STANDARD), // MinSize
  75. BUSINTRF_VERSION, // MinVersion
  76. BUSINTRF_VERSION, // MaxVersion
  77. PCIIF_PDO, // Flags
  78. 0, // ReferenceCount
  79. PciInterface_BusHandler, // Signature
  80. busintrf_Constructor, // Constructor
  81. busintrf_Initializer // Instance Initializer
  82. };
  83. #ifdef ALLOC_PRAGMA
  84. #pragma alloc_text(PAGE, busintrf_Constructor)
  85. #pragma alloc_text(PAGE, busintrf_Dereference)
  86. #pragma alloc_text(PAGE, busintrf_Initializer)
  87. #pragma alloc_text(PAGE, busintrf_Reference)
  88. #pragma alloc_text(PAGE, PciPnpTranslateBusAddress)
  89. #pragma alloc_text(PAGE, PciPnpGetDmaAdapter)
  90. #endif
  91. VOID
  92. busintrf_Reference(
  93. IN PVOID Context
  94. )
  95. {
  96. PPCI_PDO_EXTENSION pdoExtension = (PPCI_PDO_EXTENSION)Context;
  97. ASSERT_PCI_PDO_EXTENSION(pdoExtension);
  98. InterlockedIncrement(&pdoExtension->BusInterfaceReferenceCount);
  99. }
  100. VOID
  101. busintrf_Dereference(
  102. IN PVOID Context
  103. )
  104. {
  105. PPCI_PDO_EXTENSION pdoExtension = (PPCI_PDO_EXTENSION)Context;
  106. ASSERT_PCI_PDO_EXTENSION(pdoExtension);
  107. InterlockedDecrement(&pdoExtension->BusInterfaceReferenceCount);
  108. }
  109. NTSTATUS
  110. busintrf_Constructor(
  111. PVOID DeviceExtension,
  112. PVOID PciInterface,
  113. PVOID InterfaceSpecificData,
  114. USHORT Version,
  115. USHORT Size,
  116. PINTERFACE InterfaceReturn
  117. )
  118. /*++
  119. Routine Description:
  120. Initialize the BUS_INTERFACE_STANDARD fields.
  121. Arguments:
  122. PciInterface Pointer to the PciInterface record for this
  123. interface type.
  124. InterfaceSpecificData
  125. A ULONG containing the resource type for which
  126. arbitration is required.
  127. InterfaceReturn
  128. Return Value:
  129. TRUE is this device is not known to cause problems, FALSE
  130. if the device should be skipped altogether.
  131. --*/
  132. {
  133. PBUS_INTERFACE_STANDARD standard = (PBUS_INTERFACE_STANDARD)InterfaceReturn;
  134. standard->Size = sizeof( BUS_INTERFACE_STANDARD );
  135. standard->Version = BUSINTRF_VERSION;
  136. standard->Context = DeviceExtension;
  137. standard->InterfaceReference = busintrf_Reference;
  138. standard->InterfaceDereference = busintrf_Dereference;
  139. standard->TranslateBusAddress = PciPnpTranslateBusAddress;
  140. standard->GetDmaAdapter = PciPnpGetDmaAdapter;
  141. standard->SetBusData = PciPnpWriteConfig;
  142. standard->GetBusData = PciPnpReadConfig;
  143. return STATUS_SUCCESS;
  144. }
  145. NTSTATUS
  146. busintrf_Initializer(
  147. IN PPCI_ARBITER_INSTANCE Instance
  148. )
  149. /*++
  150. Routine Description:
  151. For bus interface, does nothing, shouldn't actually be called.
  152. Arguments:
  153. Instance Pointer to the PDO extension.
  154. Return Value:
  155. Returns the status of this operation.
  156. --*/
  157. {
  158. PCI_ASSERTMSG("PCI busintrf_Initializer, unexpected call.", 0);
  159. return STATUS_UNSUCCESSFUL;
  160. }
  161. BOOLEAN
  162. PciPnpTranslateBusAddress(
  163. IN PVOID Context,
  164. IN PHYSICAL_ADDRESS BusAddress,
  165. IN ULONG Length,
  166. IN OUT PULONG AddressSpace,
  167. OUT PPHYSICAL_ADDRESS TranslatedAddress
  168. )
  169. /*++
  170. Routine Description:
  171. This function is used to translate bus addresses from legacy drivers.
  172. Arguments:
  173. Context - Supplies a pointer to the interface context. This is actually
  174. the PDO for the root bus.
  175. BusAddress - Supplies the orginal address to be translated.
  176. Length - Supplies the length of the range to be translated.
  177. AddressSpace - Points to the location of of the address space type such as
  178. memory or I/O port. This value is updated by the translation.
  179. TranslatedAddress - Returns the translated address.
  180. Return Value:
  181. Returns a boolean indicating if the operations was a success.
  182. --*/
  183. {
  184. PPCI_PDO_EXTENSION pdoExtension = (PPCI_PDO_EXTENSION)Context;
  185. PAGED_CODE();
  186. ASSERT_PCI_PDO_EXTENSION(pdoExtension);
  187. return HalTranslateBusAddress(PCIBus,
  188. PCI_PARENT_FDOX(pdoExtension)->BaseBus,
  189. BusAddress,
  190. AddressSpace,
  191. TranslatedAddress);
  192. }
  193. ULONG
  194. PciPnpReadConfig(
  195. IN PVOID Context,
  196. IN ULONG WhichSpace,
  197. IN PVOID Buffer,
  198. IN ULONG Offset,
  199. IN ULONG Length
  200. )
  201. /*++
  202. Routine Description:
  203. This function reads the PCI configuration space.
  204. Arguments:
  205. Context - Supplies a pointer to the interface context. This is actually
  206. the PDO for the root bus.
  207. Buffer - Supplies a pointer to where the data should be placed.
  208. Offset - Indicates the offset into the data where the reading should begin.
  209. Length - Indicates the count of bytes which should be read.
  210. Return Value:
  211. Returns the number of bytes read.
  212. --*/
  213. {
  214. PPCI_PDO_EXTENSION pdoExtension = (PPCI_PDO_EXTENSION)Context;
  215. ULONG lengthRead;
  216. ASSERT_PCI_PDO_EXTENSION(pdoExtension);
  217. PciReadDeviceSpace(pdoExtension,
  218. WhichSpace,
  219. Buffer,
  220. Offset,
  221. Length,
  222. &lengthRead
  223. );
  224. return lengthRead;
  225. }
  226. ULONG
  227. PciPnpWriteConfig(
  228. IN PVOID Context,
  229. IN ULONG WhichSpace,
  230. IN PVOID Buffer,
  231. IN ULONG Offset,
  232. IN ULONG Length
  233. )
  234. /*++
  235. Routine Description:
  236. This function writes the PCI configuration space.
  237. Arguments:
  238. Context - Supplies a pointer to the interface context. This is actually
  239. the PDO for the root bus.
  240. Buffer - Supplies a pointer to where the data to be written is.
  241. Offset - Indicates the offset into the data where the writing should begin.
  242. Length - Indicates the count of bytes which should be written.
  243. Return Value:
  244. Returns the number of bytes read.
  245. --*/
  246. {
  247. PPCI_PDO_EXTENSION pdoExtension = (PPCI_PDO_EXTENSION)Context;
  248. ULONG lengthWritten;
  249. ASSERT_PCI_PDO_EXTENSION(pdoExtension);
  250. PciWriteDeviceSpace(pdoExtension,
  251. WhichSpace,
  252. Buffer,
  253. Offset,
  254. Length,
  255. &lengthWritten
  256. );
  257. return lengthWritten;
  258. }
  259. PDMA_ADAPTER
  260. PciPnpGetDmaAdapter(
  261. IN PVOID Context,
  262. IN struct _DEVICE_DESCRIPTION *DeviceDescriptor,
  263. OUT PULONG NumberOfMapRegisters
  264. )
  265. /*++
  266. Routine Description:
  267. This function writes the PCI configuration space.
  268. Arguments:
  269. Context - Supplies a pointer to the interface context. This is actually
  270. the PDO for the root bus.
  271. DeviceDescriptor - Supplies the device descriptor used to allocate the dma
  272. adapter object.
  273. NubmerOfMapRegisters - Returns the maximum number of map registers a device
  274. can allocate at one time.
  275. Return Value:
  276. Returns a DMA adapter or NULL.
  277. --*/
  278. {
  279. PPCI_PDO_EXTENSION pdoExtension = (PPCI_PDO_EXTENSION)Context;
  280. PAGED_CODE();
  281. ASSERT_PCI_PDO_EXTENSION(pdoExtension);
  282. //
  283. // If this is DMA on a PCI bus update the bus number, otherwise leave well
  284. // alone
  285. //
  286. if (DeviceDescriptor->InterfaceType == PCIBus) {
  287. DeviceDescriptor->BusNumber = PCI_PARENT_FDOX(pdoExtension)->BaseBus;
  288. }
  289. return IoGetDmaAdapter(
  290. pdoExtension->ParentFdoExtension->PhysicalDeviceObject,
  291. DeviceDescriptor,
  292. NumberOfMapRegisters);
  293. }