xref: /reactos/hal/halx86/include/halp.h (revision 3051eb0e)
1 /*
2  *
3  */
4 
5 #pragma once
6 
7 #ifdef CONFIG_SMP
8 #define HAL_BUILD_TYPE (DBG ? PRCB_BUILD_DEBUG : 0)
9 #else
10 #define HAL_BUILD_TYPE ((DBG ? PRCB_BUILD_DEBUG : 0) | PRCB_BUILD_UNIPROCESSOR)
11 #endif
12 
13 typedef struct _HAL_BIOS_FRAME
14 {
15     ULONG SegSs;
16     ULONG Esp;
17     ULONG EFlags;
18     ULONG SegCs;
19     ULONG Eip;
20     PKTRAP_FRAME TrapFrame;
21     ULONG CsLimit;
22     ULONG CsBase;
23     ULONG CsFlags;
24     ULONG SsLimit;
25     ULONG SsBase;
26     ULONG SsFlags;
27     ULONG Prefix;
28 } HAL_BIOS_FRAME, *PHAL_BIOS_FRAME;
29 
30 typedef
31 VOID
32 (__cdecl *PHAL_SW_INTERRUPT_HANDLER)(
33     VOID
34 );
35 
36 typedef
37 VOID
38 (FASTCALL *PHAL_SW_INTERRUPT_HANDLER_2ND_ENTRY)(
39     IN PKTRAP_FRAME TrapFrame
40 );
41 
42 #define HAL_APC_REQUEST         0
43 #define HAL_DPC_REQUEST         1
44 
45 /* HAL profiling offsets in KeGetPcr()->HalReserved[] */
46 #define HAL_PROFILING_INTERVAL      0
47 #define HAL_PROFILING_MULTIPLIER    1
48 
49 /* Usage flags */
50 #define IDT_REGISTERED          0x01
51 #define IDT_LATCHED             0x02
52 #define IDT_READ_ONLY           0x04
53 #define IDT_INTERNAL            0x11
54 #define IDT_DEVICE              0x21
55 
56 /* Conversion functions */
57 #define BCD_INT(bcd)            \
58     (((bcd & 0xF0) >> 4) * 10 + (bcd & 0x0F))
59 #define INT_BCD(int)            \
60     (UCHAR)(((int / 10) << 4) + (int % 10))
61 
62 typedef
63 BOOLEAN
64 (NTAPI *PHAL_DISMISS_INTERRUPT)(
65     IN KIRQL Irql,
66     IN ULONG Irq,
67     OUT PKIRQL OldIrql
68 );
69 
70 BOOLEAN
71 NTAPI
72 HalpDismissIrqGeneric(
73     IN KIRQL Irql,
74     IN ULONG Irq,
75     OUT PKIRQL OldIrql
76 );
77 
78 BOOLEAN
79 NTAPI
80 HalpDismissIrq15(
81     IN KIRQL Irql,
82     IN ULONG Irq,
83     OUT PKIRQL OldIrql
84 );
85 
86 BOOLEAN
87 NTAPI
88 HalpDismissIrq13(
89     IN KIRQL Irql,
90     IN ULONG Irq,
91     OUT PKIRQL OldIrql
92 );
93 
94 BOOLEAN
95 NTAPI
96 HalpDismissIrq07(
97     IN KIRQL Irql,
98     IN ULONG Irq,
99     OUT PKIRQL OldIrql
100 );
101 
102 BOOLEAN
103 NTAPI
104 HalpDismissIrqLevel(
105     IN KIRQL Irql,
106     IN ULONG Irq,
107     OUT PKIRQL OldIrql
108 );
109 
110 BOOLEAN
111 NTAPI
112 HalpDismissIrq15Level(
113     IN KIRQL Irql,
114     IN ULONG Irq,
115     OUT PKIRQL OldIrql
116 );
117 
118 BOOLEAN
119 NTAPI
120 HalpDismissIrq13Level(
121     IN KIRQL Irql,
122     IN ULONG Irq,
123     OUT PKIRQL OldIrql
124 );
125 
126 BOOLEAN
127 NTAPI
128 HalpDismissIrq07Level(
129     IN KIRQL Irql,
130     IN ULONG Irq,
131     OUT PKIRQL OldIrql
132 );
133 
134 VOID
135 __cdecl
136 HalpHardwareInterruptLevel(
137     VOID
138 );
139 
140 //
141 // Hack Flags
142 //
143 #define HALP_REVISION_FROM_HACK_FLAGS(x)    ((x) >> 24)
144 #define HALP_REVISION_HACK_FLAGS(x)         ((x) >> 12)
145 #define HALP_HACK_FLAGS(x)                  ((x) & 0xFFF)
146 
147 //
148 // Feature flags
149 //
150 #define HALP_CARD_FEATURE_FULL_DECODE   0x0001
151 
152 //
153 // Match Flags
154 //
155 #define HALP_CHECK_CARD_REVISION_ID     0x10000
156 #define HALP_CHECK_CARD_SUBVENDOR_ID    0x20000
157 #define HALP_CHECK_CARD_SUBSYSTEM_ID    0x40000
158 
159 //
160 // Mm PTE/PDE to Hal PTE/PDE
161 //
162 #define HalAddressToPde(x) (PHARDWARE_PTE)MiAddressToPde(x)
163 #define HalAddressToPte(x) (PHARDWARE_PTE)MiAddressToPte(x)
164 
165 typedef struct _IDTUsageFlags
166 {
167     UCHAR Flags;
168 } IDTUsageFlags;
169 
170 typedef struct
171 {
172     KIRQL Irql;
173     UCHAR BusReleativeVector;
174 } IDTUsage;
175 
176 typedef struct _HalAddressUsage
177 {
178     struct _HalAddressUsage *Next;
179     CM_RESOURCE_TYPE Type;
180     UCHAR Flags;
181     struct
182     {
183         ULONG Start;
184         ULONG Length;
185     } Element[];
186 } ADDRESS_USAGE, *PADDRESS_USAGE;
187 
188 /* adapter.c */
189 PADAPTER_OBJECT NTAPI HalpAllocateAdapterEx(ULONG NumberOfMapRegisters,BOOLEAN IsMaster, BOOLEAN Dma32BitAddresses);
190 
191 /* sysinfo.c */
192 INIT_FUNCTION
193 VOID
194 NTAPI
195 HalpRegisterVector(IN UCHAR Flags,
196                    IN ULONG BusVector,
197                    IN ULONG SystemVector,
198                    IN KIRQL Irql);
199 
200 INIT_FUNCTION
201 VOID
202 NTAPI
203 HalpEnableInterruptHandler(IN UCHAR Flags,
204                            IN ULONG BusVector,
205                            IN ULONG SystemVector,
206                            IN KIRQL Irql,
207                            IN PVOID Handler,
208                            IN KINTERRUPT_MODE Mode);
209 
210 /* pic.c */
211 VOID NTAPI HalpInitializePICs(IN BOOLEAN EnableInterrupts);
212 VOID __cdecl HalpApcInterrupt(VOID);
213 VOID __cdecl HalpDispatchInterrupt(VOID);
214 PHAL_SW_INTERRUPT_HANDLER __cdecl HalpDispatchInterrupt2(VOID);
215 DECLSPEC_NORETURN VOID FASTCALL HalpApcInterrupt2ndEntry(IN PKTRAP_FRAME TrapFrame);
216 DECLSPEC_NORETURN VOID FASTCALL HalpDispatchInterrupt2ndEntry(IN PKTRAP_FRAME TrapFrame);
217 
218 /* profil.c */
219 extern BOOLEAN HalpProfilingStopped;
220 
221 /* timer.c */
222 INIT_FUNCTION VOID NTAPI HalpInitializeClock(VOID);
223 VOID __cdecl HalpClockInterrupt(VOID);
224 VOID __cdecl HalpProfileInterrupt(VOID);
225 
226 typedef struct _HALP_ROLLOVER
227 {
228     ULONG RollOver;
229     ULONG Increment;
230 } HALP_ROLLOVER, *PHALP_ROLLOVER;
231 
232 VOID
233 NTAPI
234 HalpCalibrateStallExecution(VOID);
235 
236 /* pci.c */
237 VOID HalpInitPciBus (VOID);
238 
239 /* dma.c */
240 INIT_FUNCTION VOID HalpInitDma (VOID);
241 
242 /* Non-generic initialization */
243 VOID HalpInitPhase0 (PLOADER_PARAMETER_BLOCK LoaderBlock);
244 VOID HalpInitPhase1(VOID);
245 
246 VOID
247 NTAPI
248 HalpFlushTLB(VOID);
249 
250 //
251 // KD Support
252 //
253 VOID
254 NTAPI
255 HalpCheckPowerButton(
256     VOID
257 );
258 
259 INIT_FUNCTION
260 VOID
261 NTAPI
262 HalpRegisterKdSupportFunctions(
263     VOID
264 );
265 
266 INIT_FUNCTION
267 NTSTATUS
268 NTAPI
269 HalpSetupPciDeviceForDebugging(
270     IN PVOID LoaderBlock,
271     IN OUT PDEBUG_DEVICE_DESCRIPTOR PciDevice
272 );
273 
274 INIT_FUNCTION
275 NTSTATUS
276 NTAPI
277 HalpReleasePciDeviceForDebugging(
278     IN OUT PDEBUG_DEVICE_DESCRIPTOR PciDevice
279 );
280 
281 //
282 // Memory routines
283 //
284 ULONG64
285 NTAPI
286 HalpAllocPhysicalMemory(
287     IN PLOADER_PARAMETER_BLOCK LoaderBlock,
288     IN ULONG64 MaxAddress,
289     IN PFN_NUMBER PageCount,
290     IN BOOLEAN Aligned
291 );
292 
293 PVOID
294 NTAPI
295 HalpMapPhysicalMemory64Vista(
296     IN PHYSICAL_ADDRESS PhysicalAddress,
297     IN PFN_COUNT PageCount,
298     IN BOOLEAN FlushCurrentTLB
299 );
300 
301 VOID
302 NTAPI
303 HalpUnmapVirtualAddressVista(
304     IN PVOID VirtualAddress,
305     IN PFN_COUNT NumberPages,
306     IN BOOLEAN FlushCurrentTLB
307 );
308 
309 PVOID
310 NTAPI
311 HalpMapPhysicalMemory64(
312     IN PHYSICAL_ADDRESS PhysicalAddress,
313     IN PFN_COUNT PageCount
314 );
315 
316 VOID
317 NTAPI
318 HalpUnmapVirtualAddress(
319     IN PVOID VirtualAddress,
320     IN PFN_COUNT NumberPages
321 );
322 
323 /* sysinfo.c */
324 NTSTATUS
325 NTAPI
326 HaliQuerySystemInformation(
327     IN HAL_QUERY_INFORMATION_CLASS InformationClass,
328     IN ULONG BufferSize,
329     IN OUT PVOID Buffer,
330     OUT PULONG ReturnedLength
331 );
332 
333 NTSTATUS
334 NTAPI
335 HaliSetSystemInformation(
336     IN HAL_SET_INFORMATION_CLASS InformationClass,
337     IN ULONG BufferSize,
338     IN OUT PVOID Buffer
339 );
340 
341 //
342 // BIOS Routines
343 //
344 BOOLEAN
345 NTAPI
346 HalpBiosDisplayReset(
347     VOID
348 );
349 
350 VOID
351 FASTCALL
352 HalpExitToV86(
353     PKTRAP_FRAME TrapFrame
354 );
355 
356 VOID
357 __cdecl
358 HalpRealModeStart(
359     VOID
360 );
361 
362 //
363 // Processor Halt Routine
364 //
365 VOID
366 NTAPI
367 HaliHaltSystem(
368     VOID
369 );
370 
371 //
372 // CMOS Routines
373 //
374 INIT_FUNCTION
375 VOID
376 NTAPI
377 HalpInitializeCmos(
378     VOID
379 );
380 
381 UCHAR
382 NTAPI
383 HalpReadCmos(
384     IN UCHAR Reg
385 );
386 
387 VOID
388 NTAPI
389 HalpWriteCmos(
390     IN UCHAR Reg,
391     IN UCHAR Value
392 );
393 
394 //
395 // Spinlock for protecting CMOS access
396 //
397 VOID
398 NTAPI
399 HalpAcquireCmosSpinLock(
400     VOID
401 );
402 
403 VOID
404 NTAPI
405 HalpReleaseCmosSpinLock(
406     VOID
407 );
408 
409 VOID
410 NTAPI
411 HalpInitializeLegacyPICs(
412     VOID
413 );
414 
415 NTSTATUS
416 NTAPI
417 HalpOpenRegistryKey(
418     IN PHANDLE KeyHandle,
419     IN HANDLE RootKey,
420     IN PUNICODE_STRING KeyName,
421     IN ACCESS_MASK DesiredAccess,
422     IN BOOLEAN Create
423 );
424 
425 INIT_FUNCTION
426 VOID
427 NTAPI
428 HalpGetNMICrashFlag(
429     VOID
430 );
431 
432 INIT_FUNCTION
433 BOOLEAN
434 NTAPI
435 HalpGetDebugPortTable(
436     VOID
437 );
438 
439 INIT_FUNCTION
440 VOID
441 NTAPI
442 HalpReportSerialNumber(
443     VOID
444 );
445 
446 INIT_FUNCTION
447 NTSTATUS
448 NTAPI
449 HalpMarkAcpiHal(
450     VOID
451 );
452 
453 INIT_FUNCTION
454 VOID
455 NTAPI
456 HalpBuildAddressMap(
457     VOID
458 );
459 
460 INIT_FUNCTION
461 VOID
462 NTAPI
463 HalpReportResourceUsage(
464     IN PUNICODE_STRING HalName,
465     IN INTERFACE_TYPE InterfaceType
466 );
467 
468 INIT_FUNCTION
469 ULONG
470 NTAPI
471 HalpIs16BitPortDecodeSupported(
472     VOID
473 );
474 
475 NTSTATUS
476 NTAPI
477 HalpQueryAcpiResourceRequirements(
478     OUT PIO_RESOURCE_REQUIREMENTS_LIST *Requirements
479 );
480 
481 VOID
482 FASTCALL
483 KeUpdateSystemTime(
484     IN PKTRAP_FRAME TrapFrame,
485     IN ULONG Increment,
486     IN KIRQL OldIrql
487 );
488 
489 INIT_FUNCTION
490 VOID
491 NTAPI
492 HalpInitBusHandlers(
493     VOID
494 );
495 
496 NTSTATUS
497 NTAPI
498 HaliInitPnpDriver(
499     VOID
500 );
501 
502 INIT_FUNCTION
503 VOID
504 NTAPI
505 HalpDebugPciDumpBus(
506     IN ULONG i,
507     IN ULONG j,
508     IN ULONG k,
509     IN PPCI_COMMON_CONFIG PciData
510 );
511 
512 VOID
513 NTAPI
514 HalpInitProcessor(
515     IN ULONG ProcessorNumber,
516     IN PLOADER_PARAMETER_BLOCK LoaderBlock
517 );
518 
519 #ifdef _M_AMD64
520 
521 VOID
522 NTAPI
523 HalInitializeBios(
524     _In_ ULONG Unknown,
525     _In_ PLOADER_PARAMETER_BLOCK LoaderBlock
526 );
527 
528 #define KfLowerIrql KeLowerIrql
529 #define KiEnterInterruptTrap(TrapFrame) /* We do all neccessary in asm code */
530 #define KiEoiHelper(TrapFrame) return /* Just return to the caller */
531 #define HalBeginSystemInterrupt(Irql, Vector, OldIrql) ((*(OldIrql) = PASSIVE_LEVEL), TRUE)
532 #ifndef CONFIG_SMP
533 /* On UP builds, spinlocks don't exist at IRQL >= DISPATCH */
534 #define KiAcquireSpinLock(SpinLock)
535 #define KiReleaseSpinLock(SpinLock)
536 #define KfAcquireSpinLock(SpinLock) KfRaiseIrql(DISPATCH_LEVEL);
537 #define KfReleaseSpinLock(SpinLock, OldIrql) KeLowerIrql(OldIrql);
538 #endif // !CONFIG_SMP
539 #endif // _M_AMD64
540 
541 extern BOOLEAN HalpNMIInProgress;
542 
543 extern ADDRESS_USAGE HalpDefaultIoSpace;
544 
545 extern KSPIN_LOCK HalpSystemHardwareLock;
546 
547 extern PADDRESS_USAGE HalpAddressUsageList;
548 
549 extern LARGE_INTEGER HalpPerfCounter;
550 
551 extern KAFFINITY HalpActiveProcessors;
552 
553 extern BOOLEAN HalDisableFirmwareMapper;
554 extern PWCHAR HalHardwareIdString;
555 extern PWCHAR HalName;
556 
557 extern KAFFINITY HalpDefaultInterruptAffinity;
558 
559 extern IDTUsageFlags HalpIDTUsageFlags[MAXIMUM_IDTVECTOR+1];
560 
561 extern const USHORT HalpBuildType;
562