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