xref: /reactos/hal/halx86/include/halp.h (revision 447ef2aa)
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 CODE_SEG("INIT")
193 VOID
194 NTAPI
195 HalpRegisterVector(IN UCHAR Flags,
196                    IN ULONG BusVector,
197                    IN ULONG SystemVector,
198                    IN KIRQL Irql);
199 
200 CODE_SEG("INIT")
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 CODE_SEG("INIT") 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 CODE_SEG("INIT") 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 CODE_SEG("INIT")
260 VOID
261 NTAPI
262 HalpRegisterKdSupportFunctions(
263     VOID
264 );
265 
266 CODE_SEG("INIT")
267 NTSTATUS
268 NTAPI
269 HalpSetupPciDeviceForDebugging(
270     IN PVOID LoaderBlock,
271     IN OUT PDEBUG_DEVICE_DESCRIPTOR PciDevice
272 );
273 
274 CODE_SEG("INIT")
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 HaliHandlePCIConfigSpaceAccess(
327     _In_ BOOLEAN IsRead,
328     _In_ ULONG Port,
329     _In_ ULONG Length,
330     _Inout_ PULONG Buffer
331 );
332 
333 NTSTATUS
334 NTAPI
335 HaliQuerySystemInformation(
336     IN HAL_QUERY_INFORMATION_CLASS InformationClass,
337     IN ULONG BufferSize,
338     IN OUT PVOID Buffer,
339     OUT PULONG ReturnedLength
340 );
341 
342 NTSTATUS
343 NTAPI
344 HaliSetSystemInformation(
345     IN HAL_SET_INFORMATION_CLASS InformationClass,
346     IN ULONG BufferSize,
347     IN OUT PVOID Buffer
348 );
349 
350 //
351 // BIOS Routines
352 //
353 BOOLEAN
354 NTAPI
355 HalpBiosDisplayReset(
356     VOID
357 );
358 
359 VOID
360 FASTCALL
361 HalpExitToV86(
362     PKTRAP_FRAME TrapFrame
363 );
364 
365 VOID
366 __cdecl
367 HalpRealModeStart(
368     VOID
369 );
370 
371 //
372 // Processor Halt Routine
373 //
374 VOID
375 NTAPI
376 HaliHaltSystem(
377     VOID
378 );
379 
380 //
381 // CMOS Routines
382 //
383 CODE_SEG("INIT")
384 VOID
385 NTAPI
386 HalpInitializeCmos(
387     VOID
388 );
389 
390 _Requires_lock_held_(HalpSystemHardwareLock)
391 UCHAR
392 NTAPI
393 HalpReadCmos(
394     IN UCHAR Reg
395 );
396 
397 _Requires_lock_held_(HalpSystemHardwareLock)
398 VOID
399 NTAPI
400 HalpWriteCmos(
401     IN UCHAR Reg,
402     IN UCHAR Value
403 );
404 
405 //
406 // Spinlock for protecting CMOS access
407 //
408 _Acquires_lock_(HalpSystemHardwareLock)
409 VOID
410 NTAPI
411 HalpAcquireCmosSpinLock(
412     VOID
413 );
414 
415 _Releases_lock_(HalpSystemHardwareLock)
416 VOID
417 NTAPI
418 HalpReleaseCmosSpinLock(
419     VOID
420 );
421 
422 VOID
423 NTAPI
424 HalpInitializeLegacyPICs(
425     VOID
426 );
427 
428 NTSTATUS
429 NTAPI
430 HalpOpenRegistryKey(
431     IN PHANDLE KeyHandle,
432     IN HANDLE RootKey,
433     IN PUNICODE_STRING KeyName,
434     IN ACCESS_MASK DesiredAccess,
435     IN BOOLEAN Create
436 );
437 
438 CODE_SEG("INIT")
439 VOID
440 NTAPI
441 HalpGetNMICrashFlag(
442     VOID
443 );
444 
445 CODE_SEG("INIT")
446 BOOLEAN
447 NTAPI
448 HalpGetDebugPortTable(
449     VOID
450 );
451 
452 CODE_SEG("INIT")
453 VOID
454 NTAPI
455 HalpReportSerialNumber(
456     VOID
457 );
458 
459 CODE_SEG("INIT")
460 NTSTATUS
461 NTAPI
462 HalpMarkAcpiHal(
463     VOID
464 );
465 
466 CODE_SEG("INIT")
467 VOID
468 NTAPI
469 HalpBuildAddressMap(
470     VOID
471 );
472 
473 CODE_SEG("INIT")
474 VOID
475 NTAPI
476 HalpReportResourceUsage(
477     IN PUNICODE_STRING HalName,
478     IN INTERFACE_TYPE InterfaceType
479 );
480 
481 CODE_SEG("INIT")
482 ULONG
483 NTAPI
484 HalpIs16BitPortDecodeSupported(
485     VOID
486 );
487 
488 NTSTATUS
489 NTAPI
490 HalpQueryAcpiResourceRequirements(
491     OUT PIO_RESOURCE_REQUIREMENTS_LIST *Requirements
492 );
493 
494 VOID
495 FASTCALL
496 KeUpdateSystemTime(
497     IN PKTRAP_FRAME TrapFrame,
498     IN ULONG Increment,
499     IN KIRQL OldIrql
500 );
501 
502 CODE_SEG("INIT")
503 VOID
504 NTAPI
505 HalpInitBusHandlers(
506     VOID
507 );
508 
509 NTSTATUS
510 NTAPI
511 HaliInitPnpDriver(
512     VOID
513 );
514 
515 CODE_SEG("INIT")
516 VOID
517 NTAPI
518 HalpDebugPciDumpBus(
519     IN PBUS_HANDLER BusHandler,
520     IN PCI_SLOT_NUMBER PciSlot,
521     IN ULONG i,
522     IN ULONG j,
523     IN ULONG k,
524     IN PPCI_COMMON_CONFIG PciData
525 );
526 
527 VOID
528 NTAPI
529 HalpInitProcessor(
530     IN ULONG ProcessorNumber,
531     IN PLOADER_PARAMETER_BLOCK LoaderBlock
532 );
533 
534 #if defined(SARCH_PC98)
535 BOOLEAN
536 NTAPI
537 HalpDismissIrq08(
538     _In_ KIRQL Irql,
539     _In_ ULONG Irq,
540     _Out_ PKIRQL OldIrql
541 );
542 
543 BOOLEAN
544 NTAPI
545 HalpDismissIrq08Level(
546     _In_ KIRQL Irql,
547     _In_ ULONG Irq,
548     _Out_ PKIRQL OldIrql
549 );
550 
551 VOID
552 NTAPI
553 HalpInitializeClockPc98(VOID);
554 
555 extern ULONG PIT_FREQUENCY;
556 #endif /* SARCH_PC98 */
557 
558 #ifdef _M_AMD64
559 
560 VOID
561 NTAPI
562 HalInitializeBios(
563     _In_ ULONG Phase,
564     _In_ PLOADER_PARAMETER_BLOCK LoaderBlock
565 );
566 
567 #define KfLowerIrql KeLowerIrql
568 #define KiEnterInterruptTrap(TrapFrame) /* We do all neccessary in asm code */
569 #define KiEoiHelper(TrapFrame) return /* Just return to the caller */
570 #define HalBeginSystemInterrupt(Irql, Vector, OldIrql) ((*(OldIrql) = PASSIVE_LEVEL), TRUE)
571 #endif // _M_AMD64
572 
573 extern BOOLEAN HalpNMIInProgress;
574 
575 extern ADDRESS_USAGE HalpDefaultIoSpace;
576 
577 extern KSPIN_LOCK HalpSystemHardwareLock;
578 
579 extern PADDRESS_USAGE HalpAddressUsageList;
580 
581 extern LARGE_INTEGER HalpPerfCounter;
582 
583 extern KAFFINITY HalpActiveProcessors;
584 
585 extern BOOLEAN HalDisableFirmwareMapper;
586 extern PWCHAR HalHardwareIdString;
587 extern PWCHAR HalName;
588 
589 extern KAFFINITY HalpDefaultInterruptAffinity;
590 
591 extern IDTUsageFlags HalpIDTUsageFlags[MAXIMUM_IDTVECTOR+1];
592 
593 extern const USHORT HalpBuildType;
594