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