Arthur Heymans | 92a3b67 | 2023-06-22 21:30:58 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #include <acpi/acpi.h> |
| 4 | #include <arch/hpet.h> |
| 5 | #include <console/console.h> |
| 6 | #include <device/mmio.h> |
| 7 | #include <version.h> |
| 8 | |
| 9 | |
| 10 | /* http://www.intel.com/hardwaredesign/hpetspec_1.pdf */ |
| 11 | static void acpi_create_hpet(acpi_hpet_t *hpet) |
| 12 | { |
| 13 | acpi_header_t *header = &(hpet->header); |
| 14 | acpi_addr_t *addr = &(hpet->addr); |
| 15 | |
| 16 | memset((void *)hpet, 0, sizeof(acpi_hpet_t)); |
| 17 | |
| 18 | if (!header) |
| 19 | return; |
| 20 | |
| 21 | /* Fill out header fields. */ |
| 22 | memcpy(header->signature, "HPET", 4); |
| 23 | memcpy(header->oem_id, OEM_ID, 6); |
| 24 | memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8); |
| 25 | memcpy(header->asl_compiler_id, ASLC, 4); |
| 26 | |
| 27 | header->asl_compiler_revision = asl_revision; |
| 28 | header->length = sizeof(acpi_hpet_t); |
| 29 | header->revision = get_acpi_table_revision(HPET); |
| 30 | |
| 31 | /* Fill out HPET address. */ |
| 32 | addr->space_id = ACPI_ADDRESS_SPACE_MEMORY; |
| 33 | addr->bit_width = 64; |
| 34 | addr->bit_offset = 0; |
| 35 | addr->addrl = HPET_BASE_ADDRESS & 0xffffffff; |
| 36 | addr->addrh = ((unsigned long long)HPET_BASE_ADDRESS) >> 32; |
| 37 | |
| 38 | hpet->id = read32p(HPET_BASE_ADDRESS); |
| 39 | hpet->number = 0; |
| 40 | hpet->min_tick = CONFIG_HPET_MIN_TICKS; |
| 41 | |
| 42 | header->checksum = acpi_checksum((void *)hpet, sizeof(acpi_hpet_t)); |
| 43 | } |
| 44 | |
| 45 | unsigned long acpi_write_hpet(const struct device *device, unsigned long current, |
| 46 | acpi_rsdp_t *rsdp) |
| 47 | { |
| 48 | acpi_hpet_t *hpet; |
| 49 | |
| 50 | /* |
| 51 | * We explicitly add these tables later on: |
| 52 | */ |
| 53 | printk(BIOS_DEBUG, "ACPI: * HPET\n"); |
| 54 | |
| 55 | hpet = (acpi_hpet_t *)current; |
| 56 | current += sizeof(acpi_hpet_t); |
| 57 | current = ALIGN_UP(current, 16); |
| 58 | acpi_create_hpet(hpet); |
| 59 | acpi_add_table(rsdp, hpet); |
| 60 | |
| 61 | return current; |
| 62 | } |