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_hpet.h> 21 22 #include <string.h> 23 24 25 //#define TRACE_HPET 26 #ifdef TRACE_HPET 27 # define TRACE(x...) dprintf(x) 28 #else 29 # define TRACE(x...) ; 30 #endif 31 32 33 void 34 hpet_init(void) 35 { 36 // Try to find the HPET ACPI table. 37 TRACE("hpet_init: Looking for HPET...\n"); 38 acpi_hpet *hpet = (acpi_hpet *)acpi_find_table(ACPI_HPET_SIGNATURE); 39 40 // Clear hpet kernel args to known invalid state; 41 gKernelArgs.arch_args.hpet_phys = 0; 42 gKernelArgs.arch_args.hpet = NULL; 43 44 if (hpet == NULL) { 45 // No HPET table in the RSDT. 46 // Since there are no other methods for finding it, 47 // assume we don't have one. 48 TRACE("hpet_init: HPET not found.\n"); 49 return; 50 } 51 52 TRACE("hpet_init: found HPET at 0x%" B_PRIx64 ".\n", 53 hpet->hpet_address.address); 54 gKernelArgs.arch_args.hpet_phys = hpet->hpet_address.address; 55 gKernelArgs.arch_args.hpet = (void *)mmu_map_physical_memory( 56 gKernelArgs.arch_args.hpet_phys, B_PAGE_SIZE, kDefaultPageFlags); 57 } 58