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