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
18 PCHAR PciArbiterNames[] =
19 {
20 "I/O Port",
21 "Memory",
22 "Interrupt",
23 "Bus Number"
24 };
25
26 /* FUNCTIONS ******************************************************************/
27
28 VOID
29 NTAPI
PciArbiterDestructor(IN PPCI_ARBITER_INSTANCE Arbiter)30 PciArbiterDestructor(IN PPCI_ARBITER_INSTANCE Arbiter)
31 {
32 UNREFERENCED_PARAMETER(Arbiter);
33 /* This function is not yet implemented */
34 UNIMPLEMENTED;
35 while (TRUE);
36 }
37
38 NTSTATUS
39 NTAPI
PciInitializeArbiters(IN PPCI_FDO_EXTENSION FdoExtension)40 PciInitializeArbiters(IN PPCI_FDO_EXTENSION FdoExtension)
41 {
42 PPCI_INTERFACE CurrentInterface, *Interfaces;
43 PPCI_PDO_EXTENSION PdoExtension;
44 PPCI_ARBITER_INSTANCE ArbiterInterface;
45 NTSTATUS Status;
46 PCI_SIGNATURE ArbiterType;
47 ASSERT_FDO(FdoExtension);
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 */
53 if (!PCI_IS_ROOT_FDO(FdoExtension))
54 {
55 /* Get the PDO extension */
56 PdoExtension = FdoExtension->PhysicalDeviceObject->DeviceExtension;
57 ASSERT_PDO(PdoExtension);
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",
83 FdoExtension,
84 PciArbiterNames[ArbiterType - PciArb_Io]);
85 continue;
86 }
87
88 /* An arbiter was found, allocate an instance for it */
89 Status = STATUS_INSUFFICIENT_RESOURCES;
90 ArbiterInterface = ExAllocatePoolWithTag(PagedPool,
91 sizeof(PCI_ARBITER_INSTANCE),
92 PCI_POOL_TAG);
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,
112 PciArbiterDestructor);
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",
116 FdoExtension,
117 L"ARBITER HEADER MISSING", //ArbiterInterface->CommonInstance.Name,
118 ArbiterInterface);
119 Status = STATUS_SUCCESS;
120 }
121
122 /* Return to caller */
123 return Status;
124 }
125
126 NTSTATUS
127 NTAPI
PciInitializeArbiterRanges(IN PPCI_FDO_EXTENSION DeviceExtension,IN PCM_RESOURCE_LIST Resources)128 PciInitializeArbiterRanges(IN PPCI_FDO_EXTENSION DeviceExtension,
129 IN PCM_RESOURCE_LIST Resources)
130 {
131 PPCI_PDO_EXTENSION PdoExtension;
132 //CM_RESOURCE_TYPE DesiredType;
133 PVOID Instance;
134 PCI_SIGNATURE ArbiterType;
135
136 UNREFERENCED_PARAMETER(Resources);
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);
143 return STATUS_INVALID_DEVICE_REQUEST;
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;
151 ASSERT_PDO(PdoExtension);
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 */
191 UNIMPLEMENTED;
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 */
209