IRP_MN_START_DEVICE implement for ROOT FDO (PciFdoStartDevice)
[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_ARBITER_INSTANCE ArbiterInterface;
42 NTSTATUS Status;
43 PCI_SIGNATURE ArbiterType;
44 ASSERT_FDO(FdoExtension);
45
46 /* Loop all the arbiters */
47 for (ArbiterType = PciArb_Io; ArbiterType <= PciArb_BusNumber; ArbiterType++)
48 {
49 /* Check if this is the extension for the Root PCI Bus */
50 if (!PCI_IS_ROOT_FDO(FdoExtension))
51 {
52 #if 0 // at next sync when PDO add
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->Substractive)
59 {
60 DPRINT1("PCI Not creating arbiters for subtractive bus %d\n",
61 PdoExtension->Substractive);
62 continue;
63 }
64 #endif
65 }
66
67 /* Query all the registered arbiter interfaces */
68 Interfaces = PciInterfaces;
69 while (*Interfaces)
70 {
71 /* Find the one that matches the arbiter currently being setup */
72 CurrentInterface = *Interfaces;
73 if (CurrentInterface->Signature == ArbiterType) break;
74 Interfaces++;
75 }
76
77 /* Check if the required arbiter was not found in the list */
78 if (!*Interfaces)
79 {
80 /* Skip this arbiter and try the next one */
81 DPRINT1("PCI - FDO ext 0x%08x no %s arbiter.\n",
82 FdoExtension,
83 PciArbiterNames[ArbiterType - PciArb_Io]);
84 continue;
85 }
86
87 /* An arbiter was found, allocate an instance for it */
88 Status = STATUS_INSUFFICIENT_RESOURCES;
89 ArbiterInterface = ExAllocatePoolWithTag(PagedPool,
90 sizeof(PCI_ARBITER_INSTANCE),
91 PCI_POOL_TAG);
92 if (!ArbiterInterface) break;
93
94 /* Setup the instance */
95 ArbiterInterface->BusFdoExtension = FdoExtension;
96 ArbiterInterface->Interface = CurrentInterface;
97 swprintf(ArbiterInterface->InstanceName,
98 L"PCI %S (b=%02x)",
99 PciArbiterNames[ArbiterType - PciArb_Io],
100 FdoExtension->BaseBus);
101
102 /* Call the interface initializer for it */
103 Status = CurrentInterface->Initializer(ArbiterInterface);
104 if (!NT_SUCCESS(Status)) break;
105
106 /* Link it with this FDO */
107 PcipLinkSecondaryExtension(&FdoExtension->SecondaryExtension,
108 &FdoExtension->SecondaryExtLock,
109 &ArbiterInterface->Header,
110 ArbiterType,
111 PciArbiterDestructor);
112
113 /* This arbiter is now initialized, move to the next one */
114 DPRINT1("PCI - FDO ext 0x%08x %S arbiter initialized (context 0x%08x).\n",
115 FdoExtension,
116 L"ARBITER HEADER MISSING", //ArbiterInterface->CommonInstance.Name,
117 ArbiterInterface);
118 Status = STATUS_SUCCESS;
119 }
120
121 /* Return to caller */
122 return Status;
123 }
124
125 NTSTATUS
126 NTAPI
127 PciInitializeArbiterRanges(IN PPCI_FDO_EXTENSION DeviceExtension,
128 IN PCM_RESOURCE_LIST Resources)
129 {
130 //PPCI_PDO_EXTENSION PdoExtension;
131 CM_RESOURCE_TYPE DesiredType;
132 PVOID Instance;
133 PCI_SIGNATURE ArbiterType;
134
135 /* Arbiters should not already be initialized */
136 if (DeviceExtension->ArbitersInitialized)
137 {
138 /* Duplicated start request, fail initialization */
139 DPRINT1("PCI Warning hot start FDOx %08x, resource ranges not checked.\n", DeviceExtension);
140 return STATUS_INVALID_DEVICE_REQUEST;
141 }
142
143 /* Check for non-root FDO */
144 if (!PCI_IS_ROOT_FDO(DeviceExtension))
145 {
146 /* Grab the PDO */
147 #if 0 // when pdo support
148 PdoExtension = (PPCI_PDO_EXTENSION)DeviceExtension->PhysicalDeviceObject->DeviceExtension;
149 ASSERT(PdoExtension->ExtensionType == PciPdoExtensionType);
150 #endif
151 /* Multiple FDOs are not yet supported */
152 UNIMPLEMENTED;
153 while (TRUE);
154 return STATUS_SUCCESS;
155 }
156
157 /* Loop all arbiters */
158 for (ArbiterType = PciArb_Io; ArbiterType <= PciArb_Memory; ArbiterType++)
159 {
160 /* Pick correct resource type for each arbiter */
161 if (ArbiterType == PciArb_Io)
162 {
163 /* I/O Port */
164 DesiredType = CmResourceTypePort;
165 }
166 else if (ArbiterType == PciArb_Memory)
167 {
168 /* Device RAM */
169 DesiredType = CmResourceTypeMemory;
170 }
171 else
172 {
173 /* Ignore anything else */
174 continue;
175 }
176
177 /* Find an arbiter of this type */
178 Instance = PciFindNextSecondaryExtension(&DeviceExtension->SecondaryExtension,
179 ArbiterType);
180 if (Instance)
181 {
182 /*
183 * Now we should initialize it, not yet implemented because Arb
184 * library isn't yet implemented, not even the headers.
185 */
186 UNIMPLEMENTED;
187 //while (TRUE);
188 }
189 else
190 {
191 /* The arbiter was not found, this is an error! */
192 DPRINT1("PCI - FDO ext 0x%08x %s arbiter (REQUIRED) is missing.\n",
193 DeviceExtension,
194 PciArbiterNames[ArbiterType - PciArb_Io]);
195 }
196 }
197
198 /* Arbiters are now initialized */
199 DeviceExtension->ArbitersInitialized = TRUE;
200 return STATUS_SUCCESS;
201 }
202
203 /* EOF */