Add an ARC Header for future purposes (PPC, ARM, etc, ARCLoader) and implement KeFind...
[reactos.git] / reactos / ntoskrnl / ke / device.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * FILE: ntoskrnl/ke/device.c
5 * PURPOSE: Kernel Device/Settings Functions
6 *
7 * PROGRAMMERS: Alex Ionescu (alex@relsoft.net)
8 */
9
10 #include <ntoskrnl.h>
11 #define NDEBUG
12 #include <internal/debug.h>
13
14 /*
15 * @implemented
16 */
17 PCONFIGURATION_COMPONENT_DATA
18 STDCALL
19 INIT_FUNCTION
20 KeFindConfigurationEntry(IN PCONFIGURATION_COMPONENT_DATA Child,
21 IN CONFIGURATION_CLASS Class,
22 IN CONFIGURATION_TYPE Type,
23 IN PULONG ComponentKey OPTIONAL)
24 {
25 /* Start Search at Root */
26 return KeFindConfigurationNextEntry(Child,
27 Class,
28 Type,
29 ComponentKey,
30 NULL);
31 }
32
33 /*
34 * @implemented
35 */
36 PCONFIGURATION_COMPONENT_DATA
37 STDCALL
38 INIT_FUNCTION
39 KeFindConfigurationNextEntry(IN PCONFIGURATION_COMPONENT_DATA Child,
40 IN CONFIGURATION_CLASS Class,
41 IN CONFIGURATION_TYPE Type,
42 IN PULONG ComponentKey OPTIONAL,
43 IN PCONFIGURATION_COMPONENT_DATA *NextLink)
44 {
45 ULONG Key = 0;
46 ULONG Mask = 0;
47 PCONFIGURATION_COMPONENT_DATA Sibling;
48 PCONFIGURATION_COMPONENT_DATA ReturnEntry;
49
50 /* If we did get a key, then use it instead */
51 if (ComponentKey)
52 {
53 Key = *ComponentKey;
54 Mask = -1;
55 }
56
57 /* Loop the Components until we find a a match */
58 while (Child)
59 {
60 /* Check if we are starting somewhere already */
61 if (*NextLink)
62 {
63 /* If we've found the place where we started, clear and continue */
64 if (Child == *NextLink) *NextLink = NULL;
65 }
66 else
67 {
68 /* Try to get a match */
69 if (Child->Component.Class == Class &&
70 Child->Component.Type == Type &&
71 (Child->Component.Key & Mask) == Key)
72 {
73 /* Match found */
74 return Child;
75 }
76 }
77
78 /* Now we've also got to lookup the siblings */
79 Sibling = Child->Sibling;
80 while (Sibling)
81 {
82 /* Check if we are starting somewhere already */
83 if (*NextLink)
84 {
85 /* If we've found the place where we started, clear and continue */
86 if (Sibling == *NextLink) *NextLink = NULL;
87 }
88 else
89 {
90 /* Try to get a match */
91 if (Sibling->Component.Class == Class &&
92 Sibling->Component.Type == Type &&
93 (Sibling->Component.Key & Mask) == Key)
94 {
95 /* Match found */
96 return Sibling;
97 }
98 }
99
100 /* We've got to check if the Sibling has a Child as well */
101 if (Sibling->Child)
102 {
103 /* We're just going to call ourselves again */
104 if ((ReturnEntry = KeFindConfigurationNextEntry(Sibling->Child,
105 Class,
106 Type,
107 ComponentKey,
108 NextLink)))
109 {
110 return ReturnEntry;
111 }
112 }
113
114 /* Next Sibling */
115 Sibling = Sibling->Sibling;
116 }
117
118 /* Next Child */
119 Child = Child->Child;
120 }
121
122 /* If we got here, nothign was found */
123 return NULL;
124 }
125
126 /*
127 * @implemented
128 */
129 VOID
130 STDCALL
131 KeFlushEntireTb(
132 IN BOOLEAN Unknown,
133 IN BOOLEAN CurrentCpuOnly
134 )
135 {
136 KIRQL OldIrql;
137 PKPROCESS Process = NULL;
138 PKPRCB Prcb = NULL;
139
140 /* Raise the IRQL for the TB Flush */
141 OldIrql = KeRaiseIrqlToSynchLevel();
142
143 /* All CPUs need to have the TB flushed. */
144 if (CurrentCpuOnly == FALSE) {
145 Prcb = KeGetCurrentPrcb();
146
147 /* How many CPUs is our caller using? */
148 Process = Prcb->CurrentThread->ApcState.Process;
149
150 /* More then one, so send an IPI */
151 if (Process->ActiveProcessors > 1) {
152 /* Send IPI Packet */
153 }
154 }
155
156 /* Flush the TB for the Current CPU */
157 KeFlushCurrentTb();
158
159 /* Clean up */
160 if (CurrentCpuOnly == FALSE) {
161 /* Did we send an IPI? If so, wait for completion */
162 if (Process->ActiveProcessors > 1) {
163 do {
164 } while (Prcb->TargetSet != 0);
165 }
166 }
167
168 /* FIXME: According to MSKB, we should increment a counter? */
169
170 /* Return to Original IRQL */
171 KeLowerIrql(OldIrql);
172 }
173
174
175 /*
176 * @implemented
177 */
178 VOID
179 STDCALL
180 KeSetDmaIoCoherency(
181 IN ULONG Coherency
182 )
183 {
184 KiDmaIoCoherency = Coherency;
185 }
186
187 /*
188 * @implemented
189 */
190 KAFFINITY
191 STDCALL
192 KeQueryActiveProcessors (
193 VOID
194 )
195 {
196 return KeActiveProcessors;
197 }
198
199
200 /*
201 * @unimplemented
202 */
203 VOID
204 __cdecl
205 KeSaveStateForHibernate(
206 IN PVOID State
207 )
208 {
209 UNIMPLEMENTED;
210 }