1 /*
2  * Copyright (c) 2019 Intel Corporation
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 
6 #ifndef ZEPHYR_INCLUDE_ARCH_X86_MEMMAP_H_
7 #define ZEPHYR_INCLUDE_ARCH_X86_MEMMAP_H_
8 
9 #ifndef _ASMLANGUAGE
10 
11 /*
12  * The "source" of the memory map refers to where we got the data to fill in
13  * the map. Order is important: if multiple sources are available, then the
14  * numerically HIGHEST source wins, a manually-provided map being the "best".
15  */
16 
17 enum x86_memmap_source {
18 	X86_MEMMAP_SOURCE_DEFAULT,
19 	X86_MEMMAP_SOURCE_MULTIBOOT_MEM,
20 	X86_MEMMAP_SOURCE_MULTIBOOT_MMAP,
21 	X86_MEMMAP_SOURCE_MANUAL
22 };
23 
24 extern enum x86_memmap_source x86_memmap_source;
25 
26 /*
27  * For simplicity, we maintain a fixed-sized array of memory regions.
28  *
29  * We don't only track available RAM -- we track unavailable regions, too:
30  * sometimes we'll be given a map with overlapping regions. We have to be
31  * pessimistic about what is considered "available RAM" and it's easier to
32  * keep all the regions around than it is to correct incorrect maps. It's
33  * also handy to have the entire map intact for diagnostic purposes.
34  */
35 
36 enum x86_memmap_entry_type {
37 	/*
38 	 * the UNUSED entry must have a numerical 0 value, so
39 	 * that partially-initialized arrays behave as expected.
40 	 */
41 
42 	X86_MEMMAP_ENTRY_UNUSED,	/* this entry is unused/invalid */
43 	X86_MEMMAP_ENTRY_RAM,		/* available RAM */
44 	X86_MEMMAP_ENTRY_ACPI,		/* reserved for ACPI */
45 	X86_MEMMAP_ENTRY_NVS,		/* preserve during hibernation */
46 	X86_MEMMAP_ENTRY_DEFECTIVE,	/* bad memory modules */
47 	X86_MEMMAP_ENTRY_UNKNOWN	/* unknown type, do not use */
48 };
49 
50 struct x86_memmap_entry {
51 	uint64_t base;
52 	uint64_t length;
53 	enum x86_memmap_entry_type type;
54 };
55 
56 extern struct x86_memmap_entry x86_memmap[];
57 
58 /*
59  * We keep track of kernel memory areas (text, data, etc.) in a table for
60  * ease of reference. There's really no reason to export this table, or to
61  * label the members, except for diagnostic purposes.
62  */
63 
64 struct x86_memmap_exclusion {
65 	char *name;
66 	void *start;		/* address of first byte of exclusion */
67 	void *end;		/* one byte past end of exclusion */
68 };
69 
70 extern struct x86_memmap_exclusion x86_memmap_exclusions[];
71 extern int x86_nr_memmap_exclusions;
72 
73 #endif /* _ASMLANGUAGE */
74 
75 #endif /* ZEPHYR_INCLUDE_ARCH_X86_MEMMAP_H_ */
76