test: pnpbusno.c Source File

Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

# pnpbusno.c

Go to the documentation of this file.

    00001
    00002 /*++
    00003
    00004 Copyright (c) 1997  Microsoft Corporation
    00005
    00006 Module Name:
    00007
    00008     pnpbusno.c
    00009
    00010 Abstract:
    00011
    00012     Root Bus Number arbiter
    00013
    00014 Author:
    00015
    00016     Andy Thornton (andrewth) 04/17/97
    00017
    00018 Revision History:
    00019
    00020 --*/
    00021
    00022 #include "iop.h"
    00023 #pragma hdrstop
    00024
    00025 //
    00026 // Constants
    00027 //
    00028
    00029
    00030 #define MAX_ULONGLONG           ((ULONGLONG) -1)
    00031
    00032 //
    00033 // Prototypes
    00034 //
    00035
    00036 NTSTATUS
    00037 IopBusNumberInitialize(
    00038     VOID
    00039     );
    00040
    00041 NTSTATUS
    00042 IopBusNumberUnpackRequirement(
    00043     IN PIO_RESOURCE_DESCRIPTOR Descriptor,
    00044     OUT PULONGLONG Minimum,
    00045     OUT PULONGLONG Maximum,
    00046     OUT PULONG Length,
    00047     OUT PULONG Alignment
    00048     );
    00049
    00050 NTSTATUS
    00051 IopBusNumberPackResource(
    00052     IN PIO_RESOURCE_DESCRIPTOR Requirement,
    00053     IN ULONGLONG Start,
    00054     OUT PCM_PARTIAL_RESOURCE_DESCRIPTOR Descriptor
    00055     );
    00056
    00057 LONG
    00058 IopBusNumberScoreRequirement(
    00059     IN PIO_RESOURCE_DESCRIPTOR Descriptor
    00060     );
    00061
    00062 NTSTATUS
    00063 IopBusNumberUnpackResource(
    00064     IN PCM_PARTIAL_RESOURCE_DESCRIPTOR Descriptor,
    00065     OUT PULONGLONG Start,
    00066     OUT PULONG Length
    00067     );
    00068
    00069
    00070 //
    00071 // Make everything pageable
    00072 //
    00073
    00074 #ifdef ALLOC_PRAGMA
    00075
    00076 #pragma alloc_text(PAGE, IopBusNumberInitialize)
    00077 #pragma alloc_text(PAGE, IopBusNumberUnpackRequirement)
    00078 #pragma alloc_text(PAGE, IopBusNumberPackResource)
    00079 #pragma alloc_text(PAGE, IopBusNumberScoreRequirement)
    00080 #pragma alloc_text(PAGE, IopBusNumberUnpackResource)
    00081
    00082 #endif // ALLOC_PRAGMA
    00083
    00084 //
    00085 // Implementation
    00086 //
    00087
    00088 NTSTATUS
    00089 IopBusNumberInitialize(
    00090     VOID
    00091     )
    00092
    00093 /*++
    00094
    00095 Routine Description:
    00096
    00097     This routine initializes the arbiter
    00098
    00099 Parameters:
    00100
    00101     None
    00102
    00103 Return Value:
    00104
    00105     None
    00106
    00107 --*/
    00108
    00109 {
    00110     NTSTATUS    status;
    00111
    00112     IopRootBusNumberArbiter.UnpackRequirement = IopBusNumberUnpackRequirement;
    00113     IopRootBusNumberArbiter.PackResource = IopBusNumberPackResource;
    00114     IopRootBusNumberArbiter.UnpackResource = IopBusNumberUnpackResource;
    00115     IopRootBusNumberArbiter.ScoreRequirement = IopBusNumberScoreRequirement;
    00116
    00117     status = ArbInitializeArbiterInstance(&IopRootBusNumberArbiter,
    00118                                           NULL,  // Indicates a root arbiter
    00119                                           CmResourceTypeBusNumber,
    00120                                           L"RootBusNumber",
    00121                                           L"Root",
    00122                                           NULL    // no translation of BusNumber
    00123                                           );
    00124     if (NT_SUCCESS(status)) {
    00125
    00126         //
    00127         // Add the invalid range 100 - ffffffff ffffffff
    00128         //
    00129         RtlAddRange( IopRootBusNumberArbiter.Allocation,
    00130                      (ULONGLONG) 0x100,
    00131                      (ULONGLONG) -1,
    00132                      0, // UserFlags
    00133                      0, // Flag
    00134                      NULL,
    00135                      NULL
    00136                    );
    00137
    00138     }
    00139
    00140     return status;
    00141 }
    00142
    00143 //
    00144 // Arbiter callbacks
    00145 //
    00146
    00147 NTSTATUS
    00148 IopBusNumberUnpackRequirement(
    00149     IN PIO_RESOURCE_DESCRIPTOR Descriptor,
    00150     OUT PULONGLONG Minimum,
    00151     OUT PULONGLONG Maximum,
    00152     OUT PULONG Length,
    00153     OUT PULONG Alignment
    00154     )
    00155
    00156 /*++
    00157
    00158 Routine Description:
    00159
    00160     This routine unpacks an resource requirement descriptor.
    00161
    00162 Arguments:
    00163
    00164     Descriptor - The descriptor describing the requirement to unpack.
    00165
    00166     Minimum - Pointer to where the minimum acceptable start value should be
    00167         unpacked to.
    00168
    00169     Maximum - Pointer to where the maximum acceptable end value should be
    00170         unpacked to.
    00171
    00172     Length - Pointer to where the required length should be unpacked to.
    00173
    00174     Minimum - Pointer to where the required alignment should be unpacked to.
    00175
    00176 Return Value:
    00177
    00178     Returns the status of this operation.
    00179
    00180 --*/
    00181
    00182 {
    00183     ASSERT(Descriptor);
    00184     ASSERT(Descriptor->Type == CmResourceTypeBusNumber);
    00185
    00186     ARB_PRINT(2,
    00187                 ("Unpacking BusNumber requirement %p => 0x%I64x-0x%I64x\n",
    00188                 Descriptor,
    00189                 (ULONGLONG) Descriptor->u.BusNumber.MinBusNumber,
    00190                 (ULONGLONG) Descriptor->u.BusNumber.MaxBusNumber
    00191                 ));
    00192
    00193     *Minimum = (ULONGLONG) Descriptor->u.BusNumber.MinBusNumber;
    00194     *Maximum = (ULONGLONG) Descriptor->u.BusNumber.MaxBusNumber;
    00195     *Length = Descriptor->u.BusNumber.Length;
    00196     *Alignment = 1;
    00197
    00198     return STATUS_SUCCESS;
    00199
    00200 }
    00201
    00202 LONG
    00203 IopBusNumberScoreRequirement(
    00204     IN PIO_RESOURCE_DESCRIPTOR Descriptor
    00205     )
    00206
    00207 /*++
    00208
    00209 Routine Description:
    00210
    00211     This routine scores a requirement based on how flexible it is.  The least
    00212     flexible devices are scored the least and so when the arbitration list is
    00213     sorted we try to allocate their resources first.
    00214
    00215 Arguments:
    00216
    00217     Descriptor - The descriptor describing the requirement to score.
    00218
    00219
    00220 Return Value:
    00221
    00222     The score.
    00223
    00224 --*/
    00225
    00226 {
    00227     LONG score;
    00228
    00229     ASSERT(Descriptor);
    00230     ASSERT(Descriptor->Type == CmResourceTypeBusNumber);
    00231
    00232     score = (Descriptor->u.BusNumber.MaxBusNumber -
    00233                 Descriptor->u.BusNumber.MinBusNumber) /
    00234                 Descriptor->u.BusNumber.Length;
    00235
    00236     ARB_PRINT(2,
    00237                 ("Scoring BusNumber resource %p => %i\n",
    00238                 Descriptor,
    00239                 score
    00240                 ));
    00241
    00242     return score;
    00243 }
    00244
    00245 NTSTATUS
    00246 IopBusNumberPackResource(
    00247     IN PIO_RESOURCE_DESCRIPTOR Requirement,
    00248     IN ULONGLONG Start,
    00249     OUT PCM_PARTIAL_RESOURCE_DESCRIPTOR Descriptor
    00250     )
    00251
    00252 /*++
    00253
    00254 Routine Description:
    00255
    00256     This routine packs an resource descriptor.
    00257
    00258 Arguments:
    00259
    00260     Requirement - The requirement from which this resource was chosen.
    00261
    00262     Start - The start value of the resource.
    00263
    00264     Descriptor - Pointer to the descriptor to pack into.
    00265
    00266 Return Value:
    00267
    00268     Returns the status of this operation.
    00269
    00270 --*/
    00271
    00272 {
    00273     ASSERT(Descriptor);
    00274     ASSERT(Start < ((ULONG)-1));
    00275     ASSERT(Requirement);
    00276     ASSERT(Requirement->Type == CmResourceTypeBusNumber);
    00277
    00278     ARB_PRINT(2,
    00279                 ("Packing BusNumber resource %p => 0x%I64x\n",
    00280                 Descriptor,
    00281                 Start
    00282                 ));
    00283
    00284     Descriptor->Type = CmResourceTypeBusNumber;
    00285     Descriptor->ShareDisposition = Requirement->ShareDisposition;
    00286     Descriptor->Flags = Requirement->Flags;
    00287     Descriptor->u.BusNumber.Start = (ULONG) Start;
    00288     Descriptor->u.BusNumber.Length = Requirement->u.BusNumber.Length;
    00289
    00290     return STATUS_SUCCESS;
    00291 }
    00292
    00293 NTSTATUS
    00294 IopBusNumberUnpackResource(
    00295     IN PCM_PARTIAL_RESOURCE_DESCRIPTOR Descriptor,
    00296     OUT PULONGLONG Start,
    00297     OUT PULONG Length
    00298     )
    00299
    00300 /*++
    00301
    00302 Routine Description:
    00303
    00304     This routine unpacks an resource descriptor.
    00305
    00306 Arguments:
    00307
    00308     Descriptor - The descriptor describing the resource to unpack.
    00309
    00310     Start - Pointer to where the start value should be unpacked to.
    00311
    00312     End - Pointer to where the end value should be unpacked to.
    00313
    00314 Return Value:
    00315
    00316     Returns the status of this operation.
    00317
    00318 --*/
    00319
    00320 {
    00321     ASSERT(Descriptor);
    00322     ASSERT(Start);
    00323     ASSERT(Length);
    00324     ASSERT(Descriptor->Type == CmResourceTypeBusNumber);
    00325
    00326     *Start = (ULONGLONG) Descriptor->u.BusNumber.Start;
    00327     *Length = Descriptor->u.BusNumber.Length;
    00328
    00329     ARB_PRINT(2,
    00330                 ("Unpacking BusNumber resource %p => 0x%I64x\n",
    00331                 Descriptor,
    00332                 *Start
    00333                 ));
    00334
    00335     return STATUS_SUCCESS;
    00336
    00337 }
    00338