blob: a535818b2d5fae75e6fd13fdaa7cd69280881d09 [file] [log] [blame]
Graeme Russ1bab1042010-04-24 00:05:49 +10001#ifndef _ASM_X86_E820_H
2#define _ASM_X86_E820_H
Graeme Russ1bab1042010-04-24 00:05:49 +10003
Bin Meng27947c92015-04-21 12:21:35 +08004#define E820MAX 128 /* number of entries in E820MAP */
Graeme Russ1bab1042010-04-24 00:05:49 +10005
Simon Glassf92c54e2025-03-15 14:25:53 +00006#ifdef __ASSEMBLY__
7
Graeme Russ1bab1042010-04-24 00:05:49 +10008#define E820_RAM 1
9#define E820_RESERVED 2
10#define E820_ACPI 3
11#define E820_NVS 4
12#define E820_UNUSABLE 5
Simon Glassaad0d762020-09-05 14:50:50 -060013#define E820_COUNT 6 /* Number of types */
Graeme Russ1bab1042010-04-24 00:05:49 +100014
Simon Glassf92c54e2025-03-15 14:25:53 +000015#else
16
Graeme Russ1bab1042010-04-24 00:05:49 +100017#include <linux/types.h>
Bin Meng27947c92015-04-21 12:21:35 +080018
Simon Glassf92c54e2025-03-15 14:25:53 +000019/* Available e820 memory-region types */
20enum e820_type {
21 E820_RAM = 1,
22 E820_RESERVED,
23 E820_ACPI,
24 E820_NVS,
25 E820_UNUSABLE,
26
27 E820_COUNT,
28};
29
Bin Meng4b8fc742018-04-11 22:02:11 -070030struct e820_entry {
Graeme Russ1bab1042010-04-24 00:05:49 +100031 __u64 addr; /* start of memory segment */
32 __u64 size; /* size of memory segment */
33 __u32 type; /* type of memory segment */
34} __attribute__((packed));
35
Graeme Russ1bab1042010-04-24 00:05:49 +100036#define ISA_START_ADDRESS 0xa0000
37#define ISA_END_ADDRESS 0x100000
38
Simon Glassf92c54e2025-03-15 14:25:53 +000039/**
40 * Context to use for e820_add()
41 *
42 * @entries: Table being filled in
43 * @addr: Current address we are up to
44 * @count: Number of entries added to @entries so far
45 * @max_entries: Maximum number of entries allowed
46 */
47struct e820_ctx {
48 struct e820_entry *entries;
49 u64 addr;
50 int count;
51 int max_entries;
52};
53
54/**
55 * e820_init() - Start setting up an e820 table
56 *
57 * @ctx: Context to set up
58 * @entries: Place to put entries
59 * @max_entries: Maximum size of @entries
60 */
61void e820_init(struct e820_ctx *ctx, struct e820_entry *entries,
62 int max_entries);
63
64/**
65 * e820_add() - Add an entry to the table
66 *
67 * @ctx: Context
68 * @type: Type of entry
69 * @addr: Start address of entry
70 * @size Size of entry
71 */
72void e820_add(struct e820_ctx *ctx, enum e820_type type, u64 addr, u64 size);
73
74/**
75 * e820_to_addr() - Add an entry that covers the space up to a given address
76 *
77 * @ctx: Context
78 * @type: Type of entry
79 * @end_addr: Address where the entry should finish
80 */
81void e820_to_addr(struct e820_ctx *ctx, enum e820_type type, u64 end_addr);
82
83/**
84 * e820_next() - Add an entry that carries on from the last one
85 *
86 * @ctx: Context
87 * @type: Type of entry
88 * @size Size of entry
89 */
90void e820_next(struct e820_ctx *ctx, enum e820_type type, u64 size);
91
92/**
93 * e820_finish() - Finish the table
94 *
95 * Checks the table is not too large, panics if so
96 *
97 * @ctx: Context
98 * Returns: Number of entries
99 */
100int e820_finish(struct e820_ctx *ctx);
101
Simon Glass02c51202021-03-15 18:00:23 +1300102/* Implementation-defined function to install an e820 map */
Bin Meng3838d712018-04-11 22:02:10 -0700103unsigned int install_e820_map(unsigned int max_entries,
Bin Meng4b8fc742018-04-11 22:02:11 -0700104 struct e820_entry *);
Simon Glass02c51202021-03-15 18:00:23 +1300105
106/**
Simon Glassf92c54e2025-03-15 14:25:53 +0000107 * e820_dump() - Dump the e820 table
108 *
109 * @entries: Pointer to start of table
110 * @count: Number of entries in the table
111 */
112void e820_dump(struct e820_entry *entries, uint count);
113
114/**
Simon Glass02c51202021-03-15 18:00:23 +1300115 * cb_install_e820_map() - Install e820 map provided by coreboot sysinfo
116 *
117 * This should be used when booting from coreboot, since in that case the
118 * memory areas are provided by coreboot in its sysinfo.
119 *
120 * @max_entries: Maximum number of entries to write
121 * @entries: Place to put entires
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100122 * Return: number of entries written
Simon Glass02c51202021-03-15 18:00:23 +1300123 */
124unsigned int cb_install_e820_map(unsigned int max_entries,
125 struct e820_entry *entries);
126
Simon Glassb106f072025-03-15 14:25:52 +0000127/**
128 * e820_dump() - Dump an e820 table
129 *
130 * @entries: Pointer to first entry
131 * @count: Number of entries in the table
132 */
133void e820_dump(struct e820_entry *entries, uint count);
134
Simon Glassdd234462020-09-22 12:45:29 -0600135#endif /* __ASSEMBLY__ */
Bin Menga4899632015-10-07 20:19:10 -0700136
Graeme Russ1bab1042010-04-24 00:05:49 +1000137#endif /* _ASM_X86_E820_H */