Debian Codegraph @

src/arch/x86/ebda.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <acpi/acpi.h>
4 #include <bootstate.h>
5 #include <commonlib/endian.h>
6 #include <types.h>
7
8 #define X86_BDA_SIZE 0x200
9 #define X86_BDA_BASE ((void *)0x400)
10 #define X86_EBDA_SEGMENT ((void *)0x40e)
11 #define X86_EBDA_LOWMEM ((void *)0x413)
12
13 static void *get_ebda_start(void)
14 {
15 return (void *)((uintptr_t)CONFIG_DEFAULT_EBDA_SEGMENT << 4);
16 }
17
18 /*
19 * EBDA area is representing a 1KB memory area just below
20 * the top of conventional memory (below 1MB)
21 */
22
23 static void setup_ebda(u32 low_memory_size, u16 ebda_segment, u16 ebda_size)
24 {
25 u16 low_memory_kb;
26 u16 ebda_kb;
27 void *ebda;
28
29 if (!low_memory_size || !ebda_segment || !ebda_size)
30 return;
31
32 low_memory_kb = low_memory_size >> 10;
33 ebda_kb = ebda_size >> 10;
34 ebda = get_ebda_start();
35
36 /* clear BIOS DATA AREA */
37 zero_n(X86_BDA_BASE, X86_BDA_SIZE);
38
39 /* Avoid unaligned write16() since it's undefined behavior */
40 write_le16(X86_EBDA_LOWMEM, low_memory_kb);
41 write_le16(X86_EBDA_SEGMENT, ebda_segment);
42
43 /* Set up EBDA */
44 zero_n(ebda, ebda_size);
45 write_le16(ebda, ebda_kb);
46 }
47
48 static void setup_default_ebda(void *unused)
49 {
50 if (acpi_is_wakeup_s3())
51 return;
52
53 setup_ebda(CONFIG_DEFAULT_EBDA_LOWMEM,
54 CONFIG_DEFAULT_EBDA_SEGMENT,
55 CONFIG_DEFAULT_EBDA_SIZE);
56 }
57
58 /* Ensure EBDA is prepared before Option ROMs. */
59 BOOT_STATE_INIT_ENTRY(BS_DEV_INIT, BS_ON_ENTRY, setup_default_ebda, NULL);