ReactOS 0.4.15-dev-7906-g1b85a5f
arb_comn.c
Go to the documentation of this file.
1/*
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
7 */
8
9/* INCLUDES *******************************************************************/
10
11#include <pci.h>
12
13#define NDEBUG
14#include <debug.h>
15
16/* GLOBALS ********************************************************************/
17
19{
20 "I/O Port",
21 "Memory",
22 "Interrupt",
23 "Bus Number"
24};
25
26/* FUNCTIONS ******************************************************************/
27
28VOID
31{
33 /* This function is not yet implemented */
35 while (TRUE);
36}
37
41{
42 PPCI_INTERFACE CurrentInterface, *Interfaces;
44 PPCI_ARBITER_INSTANCE ArbiterInterface;
46 PCI_SIGNATURE ArbiterType;
48
49 /* Loop all the arbiters */
50 for (ArbiterType = PciArb_Io; ArbiterType <= PciArb_BusNumber; ArbiterType++)
51 {
52 /* Check if this is the extension for the Root PCI Bus */
54 {
55 /* Get the PDO extension */
56 PdoExtension = FdoExtension->PhysicalDeviceObject->DeviceExtension;
58
59 /* Skip this bus if it does subtractive decode */
60 if (PdoExtension->Dependent.type1.SubtractiveDecode)
61 {
62 DPRINT1("PCI Not creating arbiters for subtractive bus %u\n",
63 PdoExtension->Dependent.type1.SubtractiveDecode);
64 continue;
65 }
66 }
67
68 /* Query all the registered arbiter interfaces */
69 Interfaces = PciInterfaces;
70 while (*Interfaces)
71 {
72 /* Find the one that matches the arbiter currently being setup */
73 CurrentInterface = *Interfaces;
74 if (CurrentInterface->Signature == ArbiterType) break;
75 Interfaces++;
76 }
77
78 /* Check if the required arbiter was not found in the list */
79 if (!*Interfaces)
80 {
81 /* Skip this arbiter and try the next one */
82 DPRINT1("PCI - FDO ext 0x%p no %s arbiter.\n",
84 PciArbiterNames[ArbiterType - PciArb_Io]);
85 continue;
86 }
87
88 /* An arbiter was found, allocate an instance for it */
90 ArbiterInterface = ExAllocatePoolWithTag(PagedPool,
93 if (!ArbiterInterface) break;
94
95 /* Setup the instance */
96 ArbiterInterface->BusFdoExtension = FdoExtension;
97 ArbiterInterface->Interface = CurrentInterface;
98 swprintf(ArbiterInterface->InstanceName,
99 L"PCI %S (b=%02x)",
100 PciArbiterNames[ArbiterType - PciArb_Io],
101 FdoExtension->BaseBus);
102
103 /* Call the interface initializer for it */
104 Status = CurrentInterface->Initializer(ArbiterInterface);
105 if (!NT_SUCCESS(Status)) break;
106
107 /* Link it with this FDO */
108 PcipLinkSecondaryExtension(&FdoExtension->SecondaryExtension,
109 &FdoExtension->SecondaryExtLock,
110 &ArbiterInterface->Header,
111 ArbiterType,
113
114 /* This arbiter is now initialized, move to the next one */
115 DPRINT1("PCI - FDO ext 0x%p %S arbiter initialized (context 0x%p).\n",
117 L"ARBITER HEADER MISSING", //ArbiterInterface->CommonInstance.Name,
118 ArbiterInterface);
120 }
121
122 /* Return to caller */
123 return Status;
124}
125
127NTAPI
130{
132 //CM_RESOURCE_TYPE DesiredType;
134 PCI_SIGNATURE ArbiterType;
135
137
138 /* Arbiters should not already be initialized */
139 if (DeviceExtension->ArbitersInitialized)
140 {
141 /* Duplicated start request, fail initialization */
142 DPRINT1("PCI Warning hot start FDOx %p, resource ranges not checked.\n", DeviceExtension);
144 }
145
146 /* Check for non-root FDO */
147 if (!PCI_IS_ROOT_FDO(DeviceExtension))
148 {
149 /* Grab the PDO */
150 PdoExtension = (PPCI_PDO_EXTENSION)DeviceExtension->PhysicalDeviceObject->DeviceExtension;
152
153 /* Check if this is a subtractive bus */
154 if (PdoExtension->Dependent.type1.SubtractiveDecode)
155 {
156 /* There is nothing to do regarding arbitration of resources */
157 DPRINT1("PCI Skipping arbiter initialization for subtractive bridge FDOX %p\n", DeviceExtension);
158 return STATUS_SUCCESS;
159 }
160 }
161
162 /* Loop all arbiters */
163 for (ArbiterType = PciArb_Io; ArbiterType <= PciArb_Memory; ArbiterType++)
164 {
165 /* Pick correct resource type for each arbiter */
166 if (ArbiterType == PciArb_Io)
167 {
168 /* I/O Port */
169 //DesiredType = CmResourceTypePort;
170 }
171 else if (ArbiterType == PciArb_Memory)
172 {
173 /* Device RAM */
174 //DesiredType = CmResourceTypeMemory;
175 }
176 else
177 {
178 /* Ignore anything else */
179 continue;
180 }
181
182 /* Find an arbiter of this type */
183 Instance = PciFindNextSecondaryExtension(&DeviceExtension->SecondaryExtension,
184 ArbiterType);
185 if (Instance)
186 {
187 /*
188 * Now we should initialize it, not yet implemented because Arb
189 * library isn't yet implemented, not even the headers.
190 */
192 //while (TRUE);
193 }
194 else
195 {
196 /* The arbiter was not found, this is an error! */
197 DPRINT1("PCI - FDO ext 0x%p %s arbiter (REQUIRED) is missing.\n",
198 DeviceExtension,
199 PciArbiterNames[ArbiterType - PciArb_Io]);
200 }
201 }
202
203 /* Arbiters are now initialized */
204 DeviceExtension->ArbitersInitialized = TRUE;
205 return STATUS_SUCCESS;
206}
207
208/* EOF */
NTSTATUS NTAPI PciInitializeArbiterRanges(IN PPCI_FDO_EXTENSION DeviceExtension, IN PCM_RESOURCE_LIST Resources)
Definition: arb_comn.c:128
PCHAR PciArbiterNames[]
Definition: arb_comn.c:18
NTSTATUS NTAPI PciInitializeArbiters(IN PPCI_FDO_EXTENSION FdoExtension)
Definition: arb_comn.c:40
VOID NTAPI PciArbiterDestructor(IN PPCI_ARBITER_INSTANCE Arbiter)
Definition: arb_comn.c:30
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
#define UNIMPLEMENTED
Definition: debug.h:115
#define TRUE
Definition: types.h:120
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define swprintf
Definition: precomp.h:40
PPCI_SECONDARY_EXTENSION NTAPI PciFindNextSecondaryExtension(IN PSINGLE_LIST_ENTRY ListHead, IN PCI_SIGNATURE ExtensionType)
Definition: utils.c:584
enum _PCI_SIGNATURE PCI_SIGNATURE
struct _PCI_PDO_EXTENSION * PPCI_PDO_EXTENSION
VOID NTAPI PcipLinkSecondaryExtension(IN PSINGLE_LIST_ENTRY List, IN PVOID Lock, IN PPCI_SECONDARY_EXTENSION SecondaryExtension, IN PCI_SIGNATURE ExtensionType, IN PVOID Destructor)
Definition: utils.c:459
#define PCI_IS_ROOT_FDO(x)
Definition: pci.h:32
#define PCI_POOL_TAG
Definition: pci.h:27
#define ASSERT_FDO(x)
Definition: pci.h:37
#define ASSERT_PDO(x)
Definition: pci.h:38
@ PciArb_BusNumber
Definition: pci.h:99
@ PciArb_Io
Definition: pci.h:96
@ PciArb_Memory
Definition: pci.h:97
@ PdoExtension
Definition: precomp.h:49
@ FdoExtension
Definition: precomp.h:48
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define PagedPool
Definition: env_spec_w32.h:308
Status
Definition: gdiplustypes.h:25
PPCI_INTERFACE PciInterfaces[]
Definition: intrface.c:18
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
#define L(x)
Definition: ntvdm.h:50
#define STATUS_SUCCESS
Definition: shellext.h:65
PPCI_FDO_EXTENSION BusFdoExtension
Definition: pci.h:405
PCI_SECONDARY_EXTENSION Header
Definition: pci.h:403
WCHAR InstanceName[24]
Definition: pci.h:406
PPCI_INTERFACE Interface
Definition: pci.h:404
PCI_SIGNATURE Signature
Definition: pci.h:383
PCI_INTERFACE_INITIALIZER Initializer
Definition: pci.h:385
#define NTAPI
Definition: typedefs.h:36
#define IN
Definition: typedefs.h:39
char * PCHAR
Definition: typedefs.h:51
#define STATUS_INVALID_DEVICE_REQUEST
Definition: udferr_usr.h:138
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_WMI_INSTANCE_CONFIG _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_opt_ WDFWMIINSTANCE * Instance
Definition: wdfwmi.h:481