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.

338 lines
7.1 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. pnpbusno.c
  5. Abstract:
  6. Root Bus Number arbiter
  7. Author:
  8. Andy Thornton (andrewth) 04/17/97
  9. Revision History:
  10. --*/
  11. #include "pnpmgrp.h"
  12. #pragma hdrstop
  13. //
  14. // Constants
  15. //
  16. #define MAX_ULONGLONG ((ULONGLONG) -1)
  17. //
  18. // Prototypes
  19. //
  20. NTSTATUS
  21. IopBusNumberInitialize(
  22. VOID
  23. );
  24. NTSTATUS
  25. IopBusNumberUnpackRequirement(
  26. IN PIO_RESOURCE_DESCRIPTOR Descriptor,
  27. OUT PULONGLONG Minimum,
  28. OUT PULONGLONG Maximum,
  29. OUT PULONG Length,
  30. OUT PULONG Alignment
  31. );
  32. NTSTATUS
  33. IopBusNumberPackResource(
  34. IN PIO_RESOURCE_DESCRIPTOR Requirement,
  35. IN ULONGLONG Start,
  36. OUT PCM_PARTIAL_RESOURCE_DESCRIPTOR Descriptor
  37. );
  38. LONG
  39. IopBusNumberScoreRequirement(
  40. IN PIO_RESOURCE_DESCRIPTOR Descriptor
  41. );
  42. NTSTATUS
  43. IopBusNumberUnpackResource(
  44. IN PCM_PARTIAL_RESOURCE_DESCRIPTOR Descriptor,
  45. OUT PULONGLONG Start,
  46. OUT PULONG Length
  47. );
  48. //
  49. // Make everything pageable
  50. //
  51. #ifdef ALLOC_PRAGMA
  52. #pragma alloc_text(PAGE, IopBusNumberInitialize)
  53. #pragma alloc_text(PAGE, IopBusNumberUnpackRequirement)
  54. #pragma alloc_text(PAGE, IopBusNumberPackResource)
  55. #pragma alloc_text(PAGE, IopBusNumberScoreRequirement)
  56. #pragma alloc_text(PAGE, IopBusNumberUnpackResource)
  57. #endif // ALLOC_PRAGMA
  58. //
  59. // Implementation
  60. //
  61. NTSTATUS
  62. IopBusNumberInitialize(
  63. VOID
  64. )
  65. /*++
  66. Routine Description:
  67. This routine initializes the arbiter
  68. Parameters:
  69. None
  70. Return Value:
  71. None
  72. --*/
  73. {
  74. NTSTATUS status;
  75. IopRootBusNumberArbiter.UnpackRequirement = IopBusNumberUnpackRequirement;
  76. IopRootBusNumberArbiter.PackResource = IopBusNumberPackResource;
  77. IopRootBusNumberArbiter.UnpackResource = IopBusNumberUnpackResource;
  78. IopRootBusNumberArbiter.ScoreRequirement = IopBusNumberScoreRequirement;
  79. status = ArbInitializeArbiterInstance(&IopRootBusNumberArbiter,
  80. NULL, // Indicates a root arbiter
  81. CmResourceTypeBusNumber,
  82. L"RootBusNumber",
  83. L"Root",
  84. NULL // no translation of BusNumber
  85. );
  86. if (NT_SUCCESS(status)) {
  87. //
  88. // Add the invalid range 100 - ffffffff ffffffff
  89. //
  90. RtlAddRange( IopRootBusNumberArbiter.Allocation,
  91. (ULONGLONG) 0x100,
  92. (ULONGLONG) -1,
  93. 0, // UserFlags
  94. 0, // Flag
  95. NULL,
  96. NULL
  97. );
  98. }
  99. return status;
  100. }
  101. //
  102. // Arbiter callbacks
  103. //
  104. NTSTATUS
  105. IopBusNumberUnpackRequirement(
  106. IN PIO_RESOURCE_DESCRIPTOR Descriptor,
  107. OUT PULONGLONG Minimum,
  108. OUT PULONGLONG Maximum,
  109. OUT PULONG Length,
  110. OUT PULONG Alignment
  111. )
  112. /*++
  113. Routine Description:
  114. This routine unpacks an resource requirement descriptor.
  115. Arguments:
  116. Descriptor - The descriptor describing the requirement to unpack.
  117. Minimum - Pointer to where the minimum acceptable start value should be
  118. unpacked to.
  119. Maximum - Pointer to where the maximum acceptable end value should be
  120. unpacked to.
  121. Length - Pointer to where the required length should be unpacked to.
  122. Minimum - Pointer to where the required alignment should be unpacked to.
  123. Return Value:
  124. Returns the status of this operation.
  125. --*/
  126. {
  127. ASSERT(Descriptor);
  128. ASSERT(Descriptor->Type == CmResourceTypeBusNumber);
  129. ARB_PRINT(2,
  130. ("Unpacking BusNumber requirement %p => 0x%I64x-0x%I64x\n",
  131. Descriptor,
  132. (ULONGLONG) Descriptor->u.BusNumber.MinBusNumber,
  133. (ULONGLONG) Descriptor->u.BusNumber.MaxBusNumber
  134. ));
  135. *Minimum = (ULONGLONG) Descriptor->u.BusNumber.MinBusNumber;
  136. *Maximum = (ULONGLONG) Descriptor->u.BusNumber.MaxBusNumber;
  137. *Length = Descriptor->u.BusNumber.Length;
  138. *Alignment = 1;
  139. return STATUS_SUCCESS;
  140. }
  141. LONG
  142. IopBusNumberScoreRequirement(
  143. IN PIO_RESOURCE_DESCRIPTOR Descriptor
  144. )
  145. /*++
  146. Routine Description:
  147. This routine scores a requirement based on how flexible it is. The least
  148. flexible devices are scored the least and so when the arbitration list is
  149. sorted we try to allocate their resources first.
  150. Arguments:
  151. Descriptor - The descriptor describing the requirement to score.
  152. Return Value:
  153. The score.
  154. --*/
  155. {
  156. LONG score;
  157. ASSERT(Descriptor);
  158. ASSERT(Descriptor->Type == CmResourceTypeBusNumber);
  159. score = (Descriptor->u.BusNumber.MaxBusNumber -
  160. Descriptor->u.BusNumber.MinBusNumber) /
  161. Descriptor->u.BusNumber.Length;
  162. ARB_PRINT(2,
  163. ("Scoring BusNumber resource %p => %i\n",
  164. Descriptor,
  165. score
  166. ));
  167. return score;
  168. }
  169. NTSTATUS
  170. IopBusNumberPackResource(
  171. IN PIO_RESOURCE_DESCRIPTOR Requirement,
  172. IN ULONGLONG Start,
  173. OUT PCM_PARTIAL_RESOURCE_DESCRIPTOR Descriptor
  174. )
  175. /*++
  176. Routine Description:
  177. This routine packs an resource descriptor.
  178. Arguments:
  179. Requirement - The requirement from which this resource was chosen.
  180. Start - The start value of the resource.
  181. Descriptor - Pointer to the descriptor to pack into.
  182. Return Value:
  183. Returns the status of this operation.
  184. --*/
  185. {
  186. ASSERT(Descriptor);
  187. ASSERT(Start < ((ULONG)-1));
  188. ASSERT(Requirement);
  189. ASSERT(Requirement->Type == CmResourceTypeBusNumber);
  190. ARB_PRINT(2,
  191. ("Packing BusNumber resource %p => 0x%I64x\n",
  192. Descriptor,
  193. Start
  194. ));
  195. Descriptor->Type = CmResourceTypeBusNumber;
  196. Descriptor->ShareDisposition = Requirement->ShareDisposition;
  197. Descriptor->Flags = Requirement->Flags;
  198. Descriptor->u.BusNumber.Start = (ULONG) Start;
  199. Descriptor->u.BusNumber.Length = Requirement->u.BusNumber.Length;
  200. return STATUS_SUCCESS;
  201. }
  202. NTSTATUS
  203. IopBusNumberUnpackResource(
  204. IN PCM_PARTIAL_RESOURCE_DESCRIPTOR Descriptor,
  205. OUT PULONGLONG Start,
  206. OUT PULONG Length
  207. )
  208. /*++
  209. Routine Description:
  210. This routine unpacks an resource descriptor.
  211. Arguments:
  212. Descriptor - The descriptor describing the resource to unpack.
  213. Start - Pointer to where the start value should be unpacked to.
  214. End - Pointer to where the end value should be unpacked to.
  215. Return Value:
  216. Returns the status of this operation.
  217. --*/
  218. {
  219. ASSERT(Descriptor);
  220. ASSERT(Start);
  221. ASSERT(Length);
  222. ASSERT(Descriptor->Type == CmResourceTypeBusNumber);
  223. *Start = (ULONGLONG) Descriptor->u.BusNumber.Start;
  224. *Length = Descriptor->u.BusNumber.Length;
  225. ARB_PRINT(2,
  226. ("Unpacking BusNumber resource %p => 0x%I64x\n",
  227. Descriptor,
  228. *Start
  229. ));
  230. return STATUS_SUCCESS;
  231. }