2 * PROJECT: ReactOS PCI Bus Driver
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * FILE: drivers/bus/pci/arb/arb_comn.c
5 * PURPOSE: Common Arbitration Code
6 * PROGRAMMERS: ReactOS Portable Systems Group
9 /* INCLUDES *******************************************************************/
15 /* GLOBALS ********************************************************************/
17 PCHAR PciArbiterNames
[] =
25 /* FUNCTIONS ******************************************************************/
29 PciArbiterDestructor(IN PPCI_ARBITER_INSTANCE Arbiter
)
31 /* This function is not yet implemented */
38 PciInitializeArbiters(IN PPCI_FDO_EXTENSION FdoExtension
)
40 PPCI_INTERFACE CurrentInterface
, *Interfaces
;
41 PPCI_PDO_EXTENSION PdoExtension
;
42 PPCI_ARBITER_INSTANCE ArbiterInterface
;
44 PCI_SIGNATURE ArbiterType
;
45 ASSERT_FDO(FdoExtension
);
47 /* Loop all the arbiters */
48 for (ArbiterType
= PciArb_Io
; ArbiterType
<= PciArb_BusNumber
; ArbiterType
++)
50 /* Check if this is the extension for the Root PCI Bus */
51 if (!PCI_IS_ROOT_FDO(FdoExtension
))
53 /* Get the PDO extension */
54 PdoExtension
= FdoExtension
->PhysicalDeviceObject
->DeviceExtension
;
55 ASSERT_PDO(PdoExtension
);
57 /* Skip this bus if it does subtractive decode */
58 if (PdoExtension
->Dependent
.type1
.SubtractiveDecode
)
60 DPRINT1("PCI Not creating arbiters for subtractive bus %d\n",
61 PdoExtension
->Dependent
.type1
.SubtractiveDecode
);
66 /* Query all the registered arbiter interfaces */
67 Interfaces
= PciInterfaces
;
70 /* Find the one that matches the arbiter currently being setup */
71 CurrentInterface
= *Interfaces
;
72 if (CurrentInterface
->Signature
== ArbiterType
) break;
76 /* Check if the required arbiter was not found in the list */
79 /* Skip this arbiter and try the next one */
80 DPRINT1("PCI - FDO ext 0x%08x no %s arbiter.\n",
82 PciArbiterNames
[ArbiterType
- PciArb_Io
]);
86 /* An arbiter was found, allocate an instance for it */
87 Status
= STATUS_INSUFFICIENT_RESOURCES
;
88 ArbiterInterface
= ExAllocatePoolWithTag(PagedPool
,
89 sizeof(PCI_ARBITER_INSTANCE
),
91 if (!ArbiterInterface
) break;
93 /* Setup the instance */
94 ArbiterInterface
->BusFdoExtension
= FdoExtension
;
95 ArbiterInterface
->Interface
= CurrentInterface
;
96 swprintf(ArbiterInterface
->InstanceName
,
98 PciArbiterNames
[ArbiterType
- PciArb_Io
],
99 FdoExtension
->BaseBus
);
101 /* Call the interface initializer for it */
102 Status
= CurrentInterface
->Initializer(ArbiterInterface
);
103 if (!NT_SUCCESS(Status
)) break;
105 /* Link it with this FDO */
106 PcipLinkSecondaryExtension(&FdoExtension
->SecondaryExtension
,
107 &FdoExtension
->SecondaryExtLock
,
108 &ArbiterInterface
->Header
,
110 PciArbiterDestructor
);
112 /* This arbiter is now initialized, move to the next one */
113 DPRINT1("PCI - FDO ext 0x%08x %S arbiter initialized (context 0x%08x).\n",
115 L
"ARBITER HEADER MISSING", //ArbiterInterface->CommonInstance.Name,
117 Status
= STATUS_SUCCESS
;
120 /* Return to caller */
126 PciInitializeArbiterRanges(IN PPCI_FDO_EXTENSION DeviceExtension
,
127 IN PCM_RESOURCE_LIST Resources
)
129 PPCI_PDO_EXTENSION PdoExtension
;
130 CM_RESOURCE_TYPE DesiredType
;
132 PCI_SIGNATURE ArbiterType
;
134 /* Arbiters should not already be initialized */
135 if (DeviceExtension
->ArbitersInitialized
)
137 /* Duplicated start request, fail initialization */
138 DPRINT1("PCI Warning hot start FDOx %08x, resource ranges not checked.\n", DeviceExtension
);
139 return STATUS_INVALID_DEVICE_REQUEST
;
142 /* Check for non-root FDO */
143 if (!PCI_IS_ROOT_FDO(DeviceExtension
))
146 PdoExtension
= (PPCI_PDO_EXTENSION
)DeviceExtension
->PhysicalDeviceObject
->DeviceExtension
;
147 ASSERT(PdoExtension
->ExtensionType
== PciPdoExtensionType
);
149 /* Multiple FDOs are not yet supported */
152 return STATUS_SUCCESS
;
155 /* Loop all arbiters */
156 for (ArbiterType
= PciArb_Io
; ArbiterType
<= PciArb_Memory
; ArbiterType
++)
158 /* Pick correct resource type for each arbiter */
159 if (ArbiterType
== PciArb_Io
)
162 DesiredType
= CmResourceTypePort
;
164 else if (ArbiterType
== PciArb_Memory
)
167 DesiredType
= CmResourceTypeMemory
;
171 /* Ignore anything else */
175 /* Find an arbiter of this type */
176 Instance
= PciFindNextSecondaryExtension(&DeviceExtension
->SecondaryExtension
,
181 * Now we should initialize it, not yet implemented because Arb
182 * library isn't yet implemented, not even the headers.
189 /* The arbiter was not found, this is an error! */
190 DPRINT1("PCI - FDO ext 0x%08x %s arbiter (REQUIRED) is missing.\n",
192 PciArbiterNames
[ArbiterType
- PciArb_Io
]);
196 /* Arbiters are now initialized */
197 DeviceExtension
->ArbitersInitialized
= TRUE
;
198 return STATUS_SUCCESS
;