ReactOS 0.4.17-dev-1190-g4c812f4
misc.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Hardware Abstraction Layer (HAL)
3 * LICENSE: BSD - See COPYING.ARM in the top level directory
4 * PURPOSE: I/O Mapping and x86 Subs
5 * PROGRAMMERS: ReactOS Portable Systems Group
6 */
7
8/* INCLUDES *******************************************************************/
9
10#include <hal.h>
11#include <smp.h>
12
13#define NDEBUG
14#include <debug.h>
15
16/* GLOBALS *******************************************************************/
17
18/* Filled from the MADT by acpi/madt.c, which not every APIC HAL links */
20
23
24/* PRIVATE FUNCTIONS **********************************************************/
25
26#ifndef _MINIHAL_
27CODE_SEG("INIT")
28VOID
31{
33 UNICODE_STRING KeyString;
35
36 /* Make sure there is a serial number */
37 if (!HalpSerialLen) return;
38
39 /* Open the system key */
40 RtlInitUnicodeString(&KeyString, L"\\Registry\\Machine\\Hardware\\Description\\System");
42 if (NT_SUCCESS(Status))
43 {
44 /* Add the serial number */
45 RtlInitUnicodeString(&KeyString, L"Serial Number");
46 ZwSetValueKey(Handle,
47 &KeyString,
48 0,
52
53 /* Close the handle */
55 }
56}
57
58CODE_SEG("INIT")
62{
64 UNICODE_STRING KeyString;
68
69 /* Open the control set key */
70 RtlInitUnicodeString(&KeyString,
71 L"\\REGISTRY\\MACHINE\\SYSTEM\\CURRENTCONTROLSET");
73 if (NT_SUCCESS(Status))
74 {
75 /* Open the PNP key */
76 RtlInitUnicodeString(&KeyString, L"Control\\Pnp");
78 Handle,
79 &KeyString,
81 TRUE);
82 /* Close root key */
84
85 /* Check if PNP BIOS key exists */
86 if (NT_SUCCESS(Status))
87 {
88 /* Set the disable value to false -- we need the mapper */
89 RtlInitUnicodeString(&KeyString, L"DisableFirmwareMapper");
90 Status = ZwSetValueKey(KeyHandle,
91 &KeyString,
92 0,
94 &Value,
95 sizeof(Value));
96
97 /* Close subkey */
99 }
100 }
101
102 /* Return status */
103 return Status;
104}
105
107NTAPI
113{
117
118 /* Setup the attributes we received */
120 KeyName,
122 RootKey,
123 NULL);
124
125 /* What to do? */
126 if ( Create )
127 {
128 /* Create the key */
129 Status = ZwCreateKey(KeyHandle,
132 0,
133 NULL,
135 &Disposition);
136 }
137 else
138 {
139 /* Open the key */
141 }
142
143 /* We're done */
144 return Status;
145}
146#endif /* !_MINIHAL_ */
147
148VOID
149NTAPI
151{
152 //
153 // Nothing to do on non-ACPI
154 //
155 return;
156}
157
158VOID
159NTAPI
161{
162 ULONG_PTR Flags, Cr4;
163 INT CpuInfo[4];
164 ULONG_PTR PageDirectory;
165
166 //
167 // Disable interrupts
168 //
170 _disable();
171
172 //
173 // Get page table directory base
174 //
175 PageDirectory = __readcr3();
176
177 //
178 // Check for CPUID support
179 //
180 if (KeGetCurrentPrcb()->CpuID)
181 {
182 //
183 // Check for global bit in CPU features
184 //
185 __cpuid(CpuInfo, 1);
186 if (CpuInfo[3] & 0x2000)
187 {
188 //
189 // Get current CR4 value
190 //
191 Cr4 = __readcr4();
192
193 //
194 // Disable global bit
195 //
196 __writecr4(Cr4 & ~CR4_PGE);
197
198 //
199 // Flush TLB and re-enable global bit
200 //
201 __writecr3(PageDirectory);
202 __writecr4(Cr4);
203
204 //
205 // Restore interrupts
206 //
208 return;
209 }
210 }
211
212 //
213 // Legacy: just flush TLB
214 //
215 __writecr3(PageDirectory);
217}
218
219/* FUNCTIONS *****************************************************************/
220
221/*
222 * @implemented
223 */
224UCHAR
227 OUT PKINTERRUPT_ROUTINE **FlatDispatch,
228 OUT PKINTERRUPT_ROUTINE *NoConnection)
229{
230 //
231 // Not implemented on x86
232 //
233 return 0;
234}
235
236/*
237 * @implemented
238 */
239VOID
240NTAPI
242{
243 //
244 // Not implemented on x86
245 //
246 return;
247}
248
249#ifdef _M_IX86
250/* x86 fastcall wrappers */
251
252#undef KeRaiseIrql
253/*
254 * @implemented
255 */
256VOID
257NTAPI
260{
261 /* Call the fastcall function */
263}
264
265#undef KeLowerIrql
266/*
267 * @implemented
268 */
269VOID
270NTAPI
272{
273 /* Call the fastcall function */
275}
276
277#undef KeAcquireSpinLock
278/*
279 * @implemented
280 */
281VOID
282NTAPI
285{
286 /* Call the fastcall function */
288}
289
290#undef KeReleaseSpinLock
291/*
292 * @implemented
293 */
294VOID
295NTAPI
298{
299 /* Call the fastcall function */
301}
302
303#endif /* _M_IX86 */
#define CODE_SEG(...)
unsigned char BOOLEAN
Definition: actypes.h:127
LONG NTSTATUS
Definition: precomp.h:26
@ Create
Definition: registry.c:563
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
_In_ D3DDDI_VIDEO_PRESENT_TARGET_ID _In_ ULONG _In_ ULONG Flags
Definition: dispmprt.h:245
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define L(x)
Definition: resources.c:13
UCHAR KIRQL
Definition: env_spec_w32.h:591
#define KeRaiseIrql(irql, oldIrql)
Definition: env_spec_w32.h:597
KSPIN_LOCK * PKSPIN_LOCK
Definition: env_spec_w32.h:73
#define KeReleaseSpinLock(sl, irql)
Definition: env_spec_w32.h:627
#define KeLowerIrql(oldIrql)
Definition: env_spec_w32.h:602
#define KeAcquireSpinLock(sl, irql)
Definition: env_spec_w32.h:609
KIRQL * PKIRQL
Definition: env_spec_w32.h:592
ULONG Handle
Definition: gdb_input.c:15
Status
Definition: gdiplustypes.h:24
UCHAR FASTCALL HalSystemVectorDispatchEntry(IN ULONG Vector, OUT PKINTERRUPT_ROUTINE **FlatDispatch, OUT PKINTERRUPT_ROUTINE *NoConnection)
Definition: misc.c:24
VOID NTAPI KeFlushWriteBuffer(VOID)
Definition: misc.c:39
VOID FASTCALL KfLowerIrql(IN KIRQL NewIrql)
Definition: pic.c:232
KIRQL FASTCALL KfRaiseIrql(IN KIRQL NewIrql)
Definition: pic.c:187
KIRQL FASTCALL KfAcquireSpinLock(PKSPIN_LOCK SpinLock)
Definition: spinlock.c:85
VOID FASTCALL KfReleaseSpinLock(PKSPIN_LOCK SpinLock, KIRQL OldIrql)
Definition: spinlock.c:96
NTSTATUS NTAPI HalpMarkAcpiHal(VOID)
Definition: misc.c:61
VOID NTAPI HalpCheckPowerButton(VOID)
Definition: misc.c:150
VOID NTAPI HalpFlushTLB(VOID)
Definition: misc.c:160
NTSTATUS NTAPI HalpOpenRegistryKey(IN PHANDLE KeyHandle, IN HANDLE RootKey, IN PUNICODE_STRING KeyName, IN ACCESS_MASK DesiredAccess, IN BOOLEAN Create)
Definition: misc.c:108
CHAR HalpSerialNumber[31]
Definition: misc.c:22
UCHAR HalpSerialLen
Definition: misc.c:21
HALP_APIC_INFO_TABLE HalpApicInfoTable
Definition: misc.c:19
VOID NTAPI HalpReportSerialNumber(VOID)
Definition: misc.c:30
BOOLEAN HalDisableFirmwareMapper
Definition: halacpi.c:43
PPC_QUAL void __cpuid(int CPUInfo[], const int InfoType)
Definition: intrin_ppc.h:682
__INTRIN_INLINE unsigned long __readcr3(void)
Definition: intrin_x86.h:1850
__INTRIN_INLINE void __writeeflags(uintptr_t Value)
Definition: intrin_x86.h:1701
__INTRIN_INLINE unsigned long __readcr4(void)
Definition: intrin_x86.h:1857
__INTRIN_INLINE uintptr_t __readeflags(void)
Definition: intrin_x86.h:1706
__INTRIN_INLINE void __writecr3(unsigned int Data)
Definition: intrin_x86.h:1826
__INTRIN_INLINE void __writecr4(unsigned int Data)
Definition: intrin_x86.h:1831
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:115
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4715
#define CR4_PGE
Definition: ketypes.h:161
FORCEINLINE struct _KPRCB * KeGetCurrentPrcb(VOID)
Definition: ketypes.h:1197
_In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Reserved_ ULONG _In_opt_ PUNICODE_STRING _In_ ULONG _Out_opt_ PULONG Disposition
Definition: cmfuncs.h:56
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
#define REG_BINARY
Definition: nt_native.h:1499
#define KEY_ALL_ACCESS
Definition: nt_native.h:1044
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
ULONG ACCESS_MASK
Definition: nt_native.h:40
#define FASTCALL
Definition: nt_native.h:50
#define REG_OPTION_VOLATILE
Definition: nt_native.h:1063
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:455
char CHAR
Definition: pedump.c:57
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define REG_DWORD
Definition: sdbapi.c:615
void __cdecl _disable(void)
Definition: intrin_arm.h:365
_Requires_lock_held_ SpinLock _Releases_lock_ SpinLock _In_ _IRQL_restores_ KIRQL NewIrql
Definition: ke.h:114
static PMEMKEY RootKey
Definition: registry.c:55
unsigned char UCHAR
Definition: typedefs.h:53
#define NTAPI
Definition: typedefs.h:36
int32_t INT
Definition: typedefs.h:58
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
_Must_inspect_result_ _In_ WDFDEVICE _In_ ULONG _In_ ACCESS_MASK DesiredAccess
Definition: wdfdevice.h:2664
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2705
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413
_Must_inspect_result_ _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFSPINLOCK * SpinLock
Definition: wdfsync.h:228
_Requires_lock_held_ Interrupt _Releases_lock_ Interrupt _In_ _IRQL_restores_ KIRQL OldIrql
Definition: kefuncs.h:778
VOID(NTAPI * PKINTERRUPT_ROUTINE)(VOID)
Definition: ketypes.h:570