1 /* 2 * Copyright 2021 Haiku, Inc. All rights reserved. 3 * Released under the terms of the MIT License. 4 * 5 * Copyright 2008, Dustin Howett, dustin.howett@gmail.com. All rights reserved. 6 * Distributed under the terms of the MIT License. 7 * 8 * Copyright 2001, Travis Geiselbrecht. All rights reserved. 9 * Distributed under the terms of the NewOS License. 10 */ 11 12 13 #include "acpi.h" 14 #include "mmu.h" 15 16 17 #include <boot/stage2.h> 18 #include <boot/arch/x86/arch_cpu.h> 19 #include <boot/arch/x86/arch_hpet.h> 20 #include <kernel/arch/x86/arch_acpi.h> 21 #include <kernel/arch/x86/arch_hpet.h> 22 23 #include <string.h> 24 25 26 //#define TRACE_HPET 27 #ifdef TRACE_HPET 28 # define TRACE(x...) dprintf(x) 29 #else 30 # define TRACE(x...) ; 31 #endif 32 33 34 void 35 hpet_init(void) 36 { 37 // Try to find the HPET ACPI table. 38 TRACE("hpet_init: Looking for HPET...\n"); 39 acpi_hpet *hpet = (acpi_hpet *)acpi_find_table(ACPI_HPET_SIGNATURE); 40 41 // Clear hpet kernel args to known invalid state; 42 gKernelArgs.arch_args.hpet_phys = 0; 43 gKernelArgs.arch_args.hpet = NULL; 44 45 if (hpet == NULL) { 46 // No HPET table in the RSDT. 47 // Since there are no other methods for finding it, 48 // assume we don't have one. 49 TRACE("hpet_init: HPET not found.\n"); 50 return; 51 } 52 53 TRACE("hpet_init: found HPET at 0x%" B_PRIx64 ".\n", 54 hpet->hpet_address.address); 55 gKernelArgs.arch_args.hpet_phys = hpet->hpet_address.address; 56 gKernelArgs.arch_args.hpet = (void *)mmu_map_physical_memory( 57 gKernelArgs.arch_args.hpet_phys, B_PAGE_SIZE, kDefaultPageFlags); 58 } 59