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.

402 lines
9.5 KiB

  1. /*++
  2. Copyright (c) 1997-2000 Microsoft Corporation
  3. Module Name:
  4. ar_busno.c
  5. Abstract:
  6. This module implements the PCI Bus Number Arbiter.
  7. Author:
  8. Andy Thornton (andrewth) 04/17/97
  9. Revision History:
  10. --*/
  11. #include "pcip.h"
  12. #define ARBUSNO_VERSION 0
  13. //
  14. // Prototypes for routines exposed only through the "interface"
  15. // mechanism.
  16. //
  17. NTSTATUS
  18. arbusno_Constructor(
  19. PVOID DeviceExtension,
  20. PVOID PciInterface,
  21. PVOID InterfaceSpecificData,
  22. USHORT Version,
  23. USHORT Size,
  24. PINTERFACE InterfaceReturn
  25. );
  26. NTSTATUS
  27. arbusno_Initializer(
  28. IN PPCI_ARBITER_INSTANCE Instance
  29. );
  30. PCI_INTERFACE ArbiterInterfaceBusNumber = {
  31. &GUID_ARBITER_INTERFACE_STANDARD, // InterfaceType
  32. sizeof(ARBITER_INTERFACE), // MinSize
  33. ARBUSNO_VERSION, // MinVersion
  34. ARBUSNO_VERSION, // MaxVersion
  35. PCIIF_FDO, // Flags
  36. 0, // ReferenceCount
  37. PciArb_BusNumber, // Signature
  38. arbusno_Constructor, // Constructor
  39. arbusno_Initializer // Instance Initializer
  40. };
  41. //
  42. // Arbiter helper functions.
  43. //
  44. NTSTATUS
  45. arbusno_UnpackRequirement(
  46. IN PIO_RESOURCE_DESCRIPTOR Descriptor,
  47. OUT PULONGLONG Minimum,
  48. OUT PULONGLONG Maximum,
  49. OUT PULONG Length,
  50. OUT PULONG Alignment
  51. );
  52. NTSTATUS
  53. arbusno_PackResource(
  54. IN PIO_RESOURCE_DESCRIPTOR Requirement,
  55. IN ULONGLONG Start,
  56. OUT PCM_PARTIAL_RESOURCE_DESCRIPTOR Descriptor
  57. );
  58. NTSTATUS
  59. arbusno_UnpackResource(
  60. IN PCM_PARTIAL_RESOURCE_DESCRIPTOR Descriptor,
  61. OUT PULONGLONG Start,
  62. OUT PULONG Length
  63. );
  64. LONG
  65. arbusno_ScoreRequirement(
  66. IN PIO_RESOURCE_DESCRIPTOR Descriptor
  67. );
  68. #ifdef ALLOC_PRAGMA
  69. #pragma alloc_text(PAGE, arbusno_Constructor)
  70. #pragma alloc_text(PAGE, arbusno_Initializer)
  71. #pragma alloc_text(PAGE, arbusno_UnpackRequirement)
  72. #pragma alloc_text(PAGE, arbusno_PackResource)
  73. #pragma alloc_text(PAGE, arbusno_UnpackResource)
  74. #pragma alloc_text(PAGE, arbusno_ScoreRequirement)
  75. #endif
  76. NTSTATUS
  77. arbusno_Constructor(
  78. PVOID DeviceExtension,
  79. PVOID PciInterface,
  80. PVOID InterfaceSpecificData,
  81. USHORT Version,
  82. USHORT Size,
  83. PINTERFACE InterfaceReturn
  84. )
  85. /*++
  86. Routine Description:
  87. Check the InterfaceSpecificData to see if this is the correct
  88. arbiter (we already know the required interface is an arbiter
  89. from the GUID) and if so, allocate (and reference) a context
  90. for this interface.
  91. Arguments:
  92. PciInterface Pointer to the PciInterface record for this
  93. interface type.
  94. InterfaceSpecificData
  95. A ULONG containing the resource type for which
  96. arbitration is required.
  97. InterfaceReturn
  98. Return Value:
  99. TRUE is this device is not known to cause problems, FALSE
  100. if the device should be skipped altogether.
  101. --*/
  102. {
  103. PARBITER_INTERFACE arbiterInterface;
  104. NTSTATUS status;
  105. PAGED_CODE();
  106. //
  107. // This arbiter handles bus numbers, is that what they want?
  108. //
  109. if ((ULONG_PTR)InterfaceSpecificData != CmResourceTypeBusNumber) {
  110. //
  111. // No, it's not us then.
  112. //
  113. return STATUS_INVALID_PARAMETER_5;
  114. }
  115. //
  116. // Have already verified that the InterfaceReturn variable
  117. // points to an area in memory large enough to contain an
  118. // ARBITER_INTERFACE. Fill it in for the caller.
  119. //
  120. arbiterInterface = (PARBITER_INTERFACE)InterfaceReturn;
  121. arbiterInterface->Size = sizeof(ARBITER_INTERFACE);
  122. arbiterInterface->Version = ARBUSNO_VERSION;
  123. arbiterInterface->InterfaceReference = PciReferenceArbiter;
  124. arbiterInterface->InterfaceDereference = PciDereferenceArbiter;
  125. arbiterInterface->ArbiterHandler = ArbArbiterHandler;
  126. arbiterInterface->Flags = 0;
  127. status = PciArbiterInitializeInterface(DeviceExtension,
  128. PciArb_BusNumber,
  129. arbiterInterface);
  130. return status;
  131. }
  132. NTSTATUS
  133. arbusno_Initializer(
  134. IN PPCI_ARBITER_INSTANCE Instance
  135. )
  136. /*++
  137. Routine Description:
  138. This routine is called once per instantiation of an arbiter.
  139. Performs initialization of this instantiation's context.
  140. Arguments:
  141. Instance Pointer to the arbiter context.
  142. Return Value:
  143. Returns the status of this operation.
  144. --*/
  145. {
  146. PAGED_CODE();
  147. RtlZeroMemory(&Instance->CommonInstance, sizeof(ARBITER_INSTANCE));
  148. //
  149. // Set the Action Handler entry points.
  150. //
  151. Instance->CommonInstance.UnpackRequirement = arbusno_UnpackRequirement;
  152. Instance->CommonInstance.PackResource = arbusno_PackResource;
  153. Instance->CommonInstance.UnpackResource = arbusno_UnpackResource;
  154. Instance->CommonInstance.ScoreRequirement = arbusno_ScoreRequirement;
  155. //
  156. // Initialize the rest of the common instance
  157. //
  158. return ArbInitializeArbiterInstance(&Instance->CommonInstance,
  159. Instance->BusFdoExtension->FunctionalDeviceObject,
  160. CmResourceTypeBusNumber,
  161. Instance->InstanceName,
  162. L"Pci",
  163. NULL // no translation of bus numbers
  164. );
  165. }
  166. NTSTATUS
  167. arbusno_UnpackRequirement(
  168. IN PIO_RESOURCE_DESCRIPTOR Descriptor,
  169. OUT PULONGLONG Minimum,
  170. OUT PULONGLONG Maximum,
  171. OUT PULONG Length,
  172. OUT PULONG Alignment
  173. )
  174. /*++
  175. Routine Description:
  176. This routine unpacks an resource requirement descriptor.
  177. Arguments:
  178. Descriptor - The descriptor describing the requirement to unpack.
  179. Minimum - Pointer to where the minimum acceptable start value should be
  180. unpacked to.
  181. Maximum - Pointer to where the maximum acceptable end value should be
  182. unpacked to.
  183. Length - Pointer to where the required length should be unpacked to.
  184. Minimum - Pointer to where the required alignment should be unpacked to.
  185. Return Value:
  186. Returns the status of this operation.
  187. --*/
  188. {
  189. PAGED_CODE();
  190. PCI_ASSERT(Descriptor);
  191. PCI_ASSERT(Descriptor->Type == CmResourceTypeBusNumber);
  192. *Minimum = (ULONGLONG)Descriptor->u.BusNumber.MinBusNumber;
  193. *Maximum = (ULONGLONG)Descriptor->u.BusNumber.MaxBusNumber;
  194. *Length = Descriptor->u.BusNumber.Length;
  195. *Alignment = 1;
  196. return STATUS_SUCCESS;
  197. }
  198. NTSTATUS
  199. arbusno_PackResource(
  200. IN PIO_RESOURCE_DESCRIPTOR Requirement,
  201. IN ULONGLONG Start,
  202. OUT PCM_PARTIAL_RESOURCE_DESCRIPTOR Descriptor
  203. )
  204. /*++
  205. Routine Description:
  206. This routine packs an resource descriptor.
  207. Arguments:
  208. Requirement - The requirement from which this resource was chosen.
  209. Start - The start value of the resource.
  210. Descriptor - Pointer to the descriptor to pack into.
  211. Return Value:
  212. Returns the status of this operation.
  213. --*/
  214. {
  215. PAGED_CODE();
  216. PCI_ASSERT(Descriptor);
  217. PCI_ASSERT(Requirement);
  218. PCI_ASSERT(Requirement->Type == CmResourceTypeBusNumber);
  219. PCI_ASSERT(Start < MAXULONG);
  220. Descriptor->Type = CmResourceTypeBusNumber;
  221. Descriptor->Flags = Requirement->Flags;
  222. Descriptor->ShareDisposition = Requirement->ShareDisposition;
  223. Descriptor->u.BusNumber.Start = (ULONG) Start;
  224. Descriptor->u.BusNumber.Length = Requirement->u.BusNumber.Length;
  225. return STATUS_SUCCESS;
  226. }
  227. NTSTATUS
  228. arbusno_UnpackResource(
  229. IN PCM_PARTIAL_RESOURCE_DESCRIPTOR Descriptor,
  230. OUT PULONGLONG Start,
  231. OUT PULONG Length
  232. )
  233. /*++
  234. Routine Description:
  235. This routine unpacks an resource descriptor.
  236. Arguments:
  237. Descriptor - The descriptor describing the resource to unpack.
  238. Start - Pointer to where the start value should be unpacked to.
  239. Length - Pointer to where the Length value should be unpacked to.
  240. Return Value:
  241. Returns the status of this operation.
  242. --*/
  243. {
  244. PAGED_CODE();
  245. PCI_ASSERT(Descriptor);
  246. PCI_ASSERT(Start);
  247. PCI_ASSERT(Length);
  248. PCI_ASSERT(Descriptor->Type == CmResourceTypeBusNumber);
  249. *Start = (ULONGLONG) Descriptor->u.BusNumber.Start;
  250. *Length = Descriptor->u.BusNumber.Length;
  251. return STATUS_SUCCESS;
  252. }
  253. LONG
  254. arbusno_ScoreRequirement(
  255. IN PIO_RESOURCE_DESCRIPTOR Descriptor
  256. )
  257. /*++
  258. Routine Description:
  259. This routine scores a requirement based on how flexible it is. The least
  260. flexible devices are scored the least and so when the arbitration list is
  261. sorted we try to allocate their resources first.
  262. Arguments:
  263. Descriptor - The descriptor describing the requirement to score.
  264. Return Value:
  265. The score.
  266. --*/
  267. {
  268. LONG score;
  269. PAGED_CODE();
  270. PCI_ASSERT(Descriptor);
  271. PCI_ASSERT(Descriptor->Type == CmResourceTypeBusNumber);
  272. score = (Descriptor->u.BusNumber.MaxBusNumber -
  273. Descriptor->u.BusNumber.MinBusNumber) /
  274. Descriptor->u.BusNumber.Length;
  275. PciDebugPrint(
  276. PciDbgObnoxious,
  277. "Scoring BusNumber resource %p => %i\n",
  278. Descriptor,
  279. score
  280. );
  281. return score;
  282. }