xref: /aosp_15_r20/external/coreboot/src/arch/arm64/tables.c (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <acpi/acpi.h>
4 #include <assert.h>
5 #include <boot/coreboot_tables.h>
6 #include <boot/tables.h>
7 #include <bootmem.h>
8 #include <cbmem.h>
9 #include <console/console.h>
10 #include <smbios.h>
11 #include <string.h>
12 #include <symbols.h>
13 
write_acpi_table(void)14 static void write_acpi_table(void)
15 {
16 	const size_t max_acpi_size = CONFIG_MAX_ACPI_TABLE_SIZE_KB * KiB;
17 	const uintptr_t acpi_start = (uintptr_t)cbmem_add(CBMEM_ID_ACPI, max_acpi_size);
18 	assert(IS_ALIGNED(acpi_start, 16));
19 	const uintptr_t acpi_end = write_acpi_tables(acpi_start);
20 	assert(acpi_end < acpi_start + max_acpi_size);
21 	printk(BIOS_DEBUG, "ACPI tables: %ld bytes.\n", acpi_end - acpi_start);
22 }
23 
write_smbios_table(void)24 static void write_smbios_table(void)
25 {
26 	unsigned long smbios_begin, smbios_end;
27 
28 #define MAX_SMBIOS_SIZE (32 * KiB)
29 
30 	smbios_begin = (unsigned long)cbmem_add(CBMEM_ID_SMBIOS, MAX_SMBIOS_SIZE);
31 	if (!smbios_begin) {
32 		printk(BIOS_ERR, "Out of memory for SMBIOS tables\n");
33 		return;
34 	}
35 
36 	/*
37 	 * Clear the entire region to ensure the unused space doesn't
38 	 * contain garbage from a previous boot, like stale table
39 	 * signatures that could be found by the OS.
40 	 */
41 	memset((void *)smbios_begin, 0, MAX_SMBIOS_SIZE);
42 
43 	smbios_end = smbios_write_tables(smbios_begin);
44 
45 	if (smbios_end > (smbios_begin + MAX_SMBIOS_SIZE))
46 		printk(BIOS_ERR, "Increase SMBIOS size\n");
47 
48 	printk(BIOS_DEBUG, "SMBIOS tables: %ld bytes.\n", smbios_end - smbios_begin);
49 }
50 
arch_write_tables(uintptr_t coreboot_table)51 void arch_write_tables(uintptr_t coreboot_table)
52 {
53 	if (CONFIG(HAVE_ACPI_TABLES))
54 		write_acpi_table();
55 
56 	if (CONFIG(GENERATE_SMBIOS_TABLES))
57 		write_smbios_table();
58 }
59 
bootmem_arch_add_ranges(void)60 void bootmem_arch_add_ranges(void)
61 {
62 	bootmem_add_range((uintptr_t)_ttb, REGION_SIZE(ttb), BM_MEM_RAMSTAGE);
63 
64 	if (CONFIG(ARM64_USE_ARM_TRUSTED_FIRMWARE) &&
65 	    REGION_SIZE(bl31) > 0)
66 		bootmem_add_range((uintptr_t)_bl31, REGION_SIZE(bl31),
67 				  BM_MEM_BL31);
68 
69 	if (!CONFIG(COMMON_CBFS_SPI_WRAPPER))
70 		return;
71 	bootmem_add_range((uintptr_t)_postram_cbfs_cache,
72 			  REGION_SIZE(postram_cbfs_cache), BM_MEM_RAMSTAGE);
73 }
74 
lb_arch_add_records(struct lb_header * header)75 void lb_arch_add_records(struct lb_header *header)
76 {
77 }
78