* Comment out some unused but set variables, remove some others.
[reactos.git] / reactos / drivers / bus / pcix / arb / arb_comn.c
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 #define NDEBUG
13 #include <debug.h>
14
15 /* GLOBALS ********************************************************************/
16
17 PCHAR PciArbiterNames[] =
18 {
19 "I/O Port",
20 "Memory",
21 "Interrupt",
22 "Bus Number"
23 };
24
25 /* FUNCTIONS ******************************************************************/
26
27 VOID
28 NTAPI
29 PciArbiterDestructor(IN PPCI_ARBITER_INSTANCE Arbiter)
30 {
31 /* This function is not yet implemented */
32 UNIMPLEMENTED;
33 while (TRUE);
34 }
35
36 NTSTATUS
37 NTAPI
38 PciInitializeArbiters(IN PPCI_FDO_EXTENSION FdoExtension)
39 {
40 PPCI_INTERFACE CurrentInterface, *Interfaces;
41 PPCI_PDO_EXTENSION PdoExtension;
42 PPCI_ARBITER_INSTANCE ArbiterInterface;
43 NTSTATUS Status;
44 PCI_SIGNATURE ArbiterType;
45 ASSERT_FDO(FdoExtension);
46
47 /* Loop all the arbiters */
48 for (ArbiterType = PciArb_Io; ArbiterType <= PciArb_BusNumber; ArbiterType++)
49 {
50 /* Check if this is the extension for the Root PCI Bus */
51 if (!PCI_IS_ROOT_FDO(FdoExtension))
52 {
53 /* Get the PDO extension */
54 PdoExtension = FdoExtension->PhysicalDeviceObject->DeviceExtension;
55 ASSERT_PDO(PdoExtension);
56
57 /* Skip this bus if it does subtractive decode */
58 if (PdoExtension->Dependent.type1.SubtractiveDecode)
59 {
60 DPRINT1("PCI Not creating arbiters for subtractive bus %d\n",
61 PdoExtension->Dependent.type1.SubtractiveDecode);
62 continue;
63 }
64 }
65
66 /* Query all the registered arbiter interfaces */
67 Interfaces = PciInterfaces;
68 while (*Interfaces)
69 {
70 /* Find the one that matches the arbiter currently being setup */
71 CurrentInterface = *Interfaces;
72 if (CurrentInterface->Signature == ArbiterType) break;
73 Interfaces++;
74 }
75
76 /* Check if the required arbiter was not found in the list */
77 if (!*Interfaces)
78 {
79 /* Skip this arbiter and try the next one */
80 DPRINT1("PCI - FDO ext 0x%08x no %s arbiter.\n",
81 FdoExtension,
82 PciArbiterNames[ArbiterType - PciArb_Io]);
83 continue;
84 }
85
86 /* An arbiter was found, allocate an instance for it */
87 Status = STATUS_INSUFFICIENT_RESOURCES;
88 ArbiterInterface = ExAllocatePoolWithTag(PagedPool,
89 sizeof(PCI_ARBITER_INSTANCE),
90 PCI_POOL_TAG);
91 if (!ArbiterInterface) break;
92
93 /* Setup the instance */
94 ArbiterInterface->BusFdoExtension = FdoExtension;
95 ArbiterInterface->Interface = CurrentInterface;
96 swprintf(ArbiterInterface->InstanceName,
97 L"PCI %S (b=%02x)",
98 PciArbiterNames[ArbiterType - PciArb_Io],
99 FdoExtension->BaseBus);
100
101 /* Call the interface initializer for it */
102 Status = CurrentInterface->Initializer(ArbiterInterface);
103 if (!NT_SUCCESS(Status)) break;
104
105 /* Link it with this FDO */
106 PcipLinkSecondaryExtension(&FdoExtension->SecondaryExtension,
107 &FdoExtension->SecondaryExtLock,
108 &ArbiterInterface->Header,
109 ArbiterType,
110 PciArbiterDestructor);
111
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",
114 FdoExtension,
115 L"ARBITER HEADER MISSING", //ArbiterInterface->CommonInstance.Name,
116 ArbiterInterface);
117 Status = STATUS_SUCCESS;
118 }
119
120 /* Return to caller */
121 return Status;
122 }
123
124 NTSTATUS
125 NTAPI
126 PciInitializeArbiterRanges(IN PPCI_FDO_EXTENSION DeviceExtension,
127 IN PCM_RESOURCE_LIST Resources)
128 {
129 PPCI_PDO_EXTENSION PdoExtension;
130 //CM_RESOURCE_TYPE DesiredType;
131 PVOID Instance;
132 PCI_SIGNATURE ArbiterType;
133
134 /* Arbiters should not already be initialized */
135 if (DeviceExtension->ArbitersInitialized)
136 {
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;
140 }
141
142 /* Check for non-root FDO */
143 if (!PCI_IS_ROOT_FDO(DeviceExtension))
144 {
145 /* Grab the PDO */
146 PdoExtension = (PPCI_PDO_EXTENSION)DeviceExtension->PhysicalDeviceObject->DeviceExtension;
147 ASSERT_PDO(PdoExtension);
148
149 /* Check if this is a subtractive bus */
150 if (PdoExtension->Dependent.type1.SubtractiveDecode)
151 {
152 /* There is nothing to do regarding arbitration of resources */
153 DPRINT1("PCI Skipping arbiter initialization for subtractive bridge FDOX %p\n", DeviceExtension);
154 return STATUS_SUCCESS;
155 }
156 }
157
158 /* Loop all arbiters */
159 for (ArbiterType = PciArb_Io; ArbiterType <= PciArb_Memory; ArbiterType++)
160 {
161 /* Pick correct resource type for each arbiter */
162 if (ArbiterType == PciArb_Io)
163 {
164 /* I/O Port */
165 //DesiredType = CmResourceTypePort;
166 }
167 else if (ArbiterType == PciArb_Memory)
168 {
169 /* Device RAM */
170 //DesiredType = CmResourceTypeMemory;
171 }
172 else
173 {
174 /* Ignore anything else */
175 continue;
176 }
177
178 /* Find an arbiter of this type */
179 Instance = PciFindNextSecondaryExtension(&DeviceExtension->SecondaryExtension,
180 ArbiterType);
181 if (Instance)
182 {
183 /*
184 * Now we should initialize it, not yet implemented because Arb
185 * library isn't yet implemented, not even the headers.
186 */
187 UNIMPLEMENTED;
188 //while (TRUE);
189 }
190 else
191 {
192 /* The arbiter was not found, this is an error! */
193 DPRINT1("PCI - FDO ext 0x%08x %s arbiter (REQUIRED) is missing.\n",
194 DeviceExtension,
195 PciArbiterNames[ArbiterType - PciArb_Io]);
196 }
197 }
198
199 /* Arbiters are now initialized */
200 DeviceExtension->ArbitersInitialized = TRUE;
201 return STATUS_SUCCESS;
202 }
203
204 /* EOF */