Add config interface start (PciReadWriteConfigSpace, PciReadSlotConfig)
[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(PdoExtension->ExtensionType == PciPdoExtensionType);
148
149 /* Multiple FDOs are not yet supported */
150 UNIMPLEMENTED;
151 while (TRUE);
152 return STATUS_SUCCESS;
153 }
154
155 /* Loop all arbiters */
156 for (ArbiterType = PciArb_Io; ArbiterType <= PciArb_Memory; ArbiterType++)
157 {
158 /* Pick correct resource type for each arbiter */
159 if (ArbiterType == PciArb_Io)
160 {
161 /* I/O Port */
162 DesiredType = CmResourceTypePort;
163 }
164 else if (ArbiterType == PciArb_Memory)
165 {
166 /* Device RAM */
167 DesiredType = CmResourceTypeMemory;
168 }
169 else
170 {
171 /* Ignore anything else */
172 continue;
173 }
174
175 /* Find an arbiter of this type */
176 Instance = PciFindNextSecondaryExtension(&DeviceExtension->SecondaryExtension,
177 ArbiterType);
178 if (Instance)
179 {
180 /*
181 * Now we should initialize it, not yet implemented because Arb
182 * library isn't yet implemented, not even the headers.
183 */
184 UNIMPLEMENTED;
185 //while (TRUE);
186 }
187 else
188 {
189 /* The arbiter was not found, this is an error! */
190 DPRINT1("PCI - FDO ext 0x%08x %s arbiter (REQUIRED) is missing.\n",
191 DeviceExtension,
192 PciArbiterNames[ArbiterType - PciArb_Io]);
193 }
194 }
195
196 /* Arbiters are now initialized */
197 DeviceExtension->ArbitersInitialized = TRUE;
198 return STATUS_SUCCESS;
199 }
200
201 /* EOF */