xref: /openbmc/u-boot/arch/x86/include/asm/e820.h (revision fea25720013f84427a0ba8833a38614fcaf488ba)
1*fea25720SGraeme Russ #ifndef _ASM_X86_E820_H
2*fea25720SGraeme Russ #define _ASM_X86_E820_H
3*fea25720SGraeme Russ #define E820MAP	0x2d0		/* our map */
4*fea25720SGraeme Russ #define E820MAX	128		/* number of entries in E820MAP */
5*fea25720SGraeme Russ 
6*fea25720SGraeme Russ /*
7*fea25720SGraeme Russ  * Legacy E820 BIOS limits us to 128 (E820MAX) nodes due to the
8*fea25720SGraeme Russ  * constrained space in the zeropage.  If we have more nodes than
9*fea25720SGraeme Russ  * that, and if we've booted off EFI firmware, then the EFI tables
10*fea25720SGraeme Russ  * passed us from the EFI firmware can list more nodes.  Size our
11*fea25720SGraeme Russ  * internal memory map tables to have room for these additional
12*fea25720SGraeme Russ  * nodes, based on up to three entries per node for which the
13*fea25720SGraeme Russ  * kernel was built: MAX_NUMNODES == (1 << CONFIG_NODES_SHIFT),
14*fea25720SGraeme Russ  * plus E820MAX, allowing space for the possible duplicate E820
15*fea25720SGraeme Russ  * entries that might need room in the same arrays, prior to the
16*fea25720SGraeme Russ  * call to sanitize_e820_map() to remove duplicates.  The allowance
17*fea25720SGraeme Russ  * of three memory map entries per node is "enough" entries for
18*fea25720SGraeme Russ  * the initial hardware platform motivating this mechanism to make
19*fea25720SGraeme Russ  * use of additional EFI map entries.  Future platforms may want
20*fea25720SGraeme Russ  * to allow more than three entries per node or otherwise refine
21*fea25720SGraeme Russ  * this size.
22*fea25720SGraeme Russ  */
23*fea25720SGraeme Russ 
24*fea25720SGraeme Russ /*
25*fea25720SGraeme Russ  * Odd: 'make headers_check' complains about numa.h if I try
26*fea25720SGraeme Russ  * to collapse the next two #ifdef lines to a single line:
27*fea25720SGraeme Russ  *	#if defined(__KERNEL__) && defined(CONFIG_EFI)
28*fea25720SGraeme Russ  */
29*fea25720SGraeme Russ #ifdef __KERNEL__
30*fea25720SGraeme Russ #ifdef CONFIG_EFI
31*fea25720SGraeme Russ #include <linux/numa.h>
32*fea25720SGraeme Russ #define E820_X_MAX (E820MAX + 3 * MAX_NUMNODES)
33*fea25720SGraeme Russ #else	/* ! CONFIG_EFI */
34*fea25720SGraeme Russ #define E820_X_MAX E820MAX
35*fea25720SGraeme Russ #endif
36*fea25720SGraeme Russ #else	/* ! __KERNEL__ */
37*fea25720SGraeme Russ #define E820_X_MAX E820MAX
38*fea25720SGraeme Russ #endif
39*fea25720SGraeme Russ 
40*fea25720SGraeme Russ #define E820NR	0x1e8		/* # entries in E820MAP */
41*fea25720SGraeme Russ 
42*fea25720SGraeme Russ #define E820_RAM	1
43*fea25720SGraeme Russ #define E820_RESERVED	2
44*fea25720SGraeme Russ #define E820_ACPI	3
45*fea25720SGraeme Russ #define E820_NVS	4
46*fea25720SGraeme Russ #define E820_UNUSABLE	5
47*fea25720SGraeme Russ 
48*fea25720SGraeme Russ /* reserved RAM used by kernel itself */
49*fea25720SGraeme Russ #define E820_RESERVED_KERN        128
50*fea25720SGraeme Russ 
51*fea25720SGraeme Russ #ifndef __ASSEMBLY__
52*fea25720SGraeme Russ #include <linux/types.h>
53*fea25720SGraeme Russ struct e820entry {
54*fea25720SGraeme Russ 	__u64 addr;	/* start of memory segment */
55*fea25720SGraeme Russ 	__u64 size;	/* size of memory segment */
56*fea25720SGraeme Russ 	__u32 type;	/* type of memory segment */
57*fea25720SGraeme Russ } __attribute__((packed));
58*fea25720SGraeme Russ 
59*fea25720SGraeme Russ struct e820map {
60*fea25720SGraeme Russ 	__u32 nr_map;
61*fea25720SGraeme Russ 	struct e820entry map[E820_X_MAX];
62*fea25720SGraeme Russ };
63*fea25720SGraeme Russ 
64*fea25720SGraeme Russ #define ISA_START_ADDRESS	0xa0000
65*fea25720SGraeme Russ #define ISA_END_ADDRESS		0x100000
66*fea25720SGraeme Russ 
67*fea25720SGraeme Russ #define BIOS_BEGIN		0x000a0000
68*fea25720SGraeme Russ #define BIOS_END		0x00100000
69*fea25720SGraeme Russ 
70*fea25720SGraeme Russ #ifdef __KERNEL__
71*fea25720SGraeme Russ /* see comment in arch/x86/kernel/e820.c */
72*fea25720SGraeme Russ extern struct e820map e820;
73*fea25720SGraeme Russ extern struct e820map e820_saved;
74*fea25720SGraeme Russ 
75*fea25720SGraeme Russ extern unsigned long pci_mem_start;
76*fea25720SGraeme Russ extern int e820_any_mapped(u64 start, u64 end, unsigned type);
77*fea25720SGraeme Russ extern int e820_all_mapped(u64 start, u64 end, unsigned type);
78*fea25720SGraeme Russ extern void e820_add_region(u64 start, u64 size, int type);
79*fea25720SGraeme Russ extern void e820_print_map(char *who);
80*fea25720SGraeme Russ extern int
81*fea25720SGraeme Russ sanitize_e820_map(struct e820entry *biosmap, int max_nr_map, u32 *pnr_map);
82*fea25720SGraeme Russ extern u64 e820_update_range(u64 start, u64 size, unsigned old_type,
83*fea25720SGraeme Russ 			       unsigned new_type);
84*fea25720SGraeme Russ extern u64 e820_remove_range(u64 start, u64 size, unsigned old_type,
85*fea25720SGraeme Russ 			     int checktype);
86*fea25720SGraeme Russ extern void update_e820(void);
87*fea25720SGraeme Russ extern void e820_setup_gap(void);
88*fea25720SGraeme Russ extern int e820_search_gap(unsigned long *gapstart, unsigned long *gapsize,
89*fea25720SGraeme Russ 			unsigned long start_addr, unsigned long long end_addr);
90*fea25720SGraeme Russ struct setup_data;
91*fea25720SGraeme Russ extern void parse_e820_ext(struct setup_data *data, unsigned long pa_data);
92*fea25720SGraeme Russ 
93*fea25720SGraeme Russ #if defined(CONFIG_X86_64) || \
94*fea25720SGraeme Russ 	(defined(CONFIG_X86_32) && defined(CONFIG_HIBERNATION))
95*fea25720SGraeme Russ extern void e820_mark_nosave_regions(unsigned long limit_pfn);
96*fea25720SGraeme Russ #else
97*fea25720SGraeme Russ static inline void e820_mark_nosave_regions(unsigned long limit_pfn)
98*fea25720SGraeme Russ {
99*fea25720SGraeme Russ }
100*fea25720SGraeme Russ #endif
101*fea25720SGraeme Russ 
102*fea25720SGraeme Russ #ifdef CONFIG_MEMTEST
103*fea25720SGraeme Russ extern void early_memtest(unsigned long start, unsigned long end);
104*fea25720SGraeme Russ #else
105*fea25720SGraeme Russ static inline void early_memtest(unsigned long start, unsigned long end)
106*fea25720SGraeme Russ {
107*fea25720SGraeme Russ }
108*fea25720SGraeme Russ #endif
109*fea25720SGraeme Russ 
110*fea25720SGraeme Russ extern unsigned long end_user_pfn;
111*fea25720SGraeme Russ 
112*fea25720SGraeme Russ extern u64 find_e820_area(u64 start, u64 end, u64 size, u64 align);
113*fea25720SGraeme Russ extern u64 find_e820_area_size(u64 start, u64 *sizep, u64 align);
114*fea25720SGraeme Russ extern void reserve_early(u64 start, u64 end, char *name);
115*fea25720SGraeme Russ extern void reserve_early_overlap_ok(u64 start, u64 end, char *name);
116*fea25720SGraeme Russ extern void free_early(u64 start, u64 end);
117*fea25720SGraeme Russ extern void early_res_to_bootmem(u64 start, u64 end);
118*fea25720SGraeme Russ extern u64 early_reserve_e820(u64 startt, u64 sizet, u64 align);
119*fea25720SGraeme Russ 
120*fea25720SGraeme Russ extern unsigned long e820_end_of_ram_pfn(void);
121*fea25720SGraeme Russ extern unsigned long e820_end_of_low_ram_pfn(void);
122*fea25720SGraeme Russ extern int e820_find_active_region(const struct e820entry *ei,
123*fea25720SGraeme Russ 				  unsigned long start_pfn,
124*fea25720SGraeme Russ 				  unsigned long last_pfn,
125*fea25720SGraeme Russ 				  unsigned long *ei_startpfn,
126*fea25720SGraeme Russ 				  unsigned long *ei_endpfn);
127*fea25720SGraeme Russ extern void e820_register_active_regions(int nid, unsigned long start_pfn,
128*fea25720SGraeme Russ 					 unsigned long end_pfn);
129*fea25720SGraeme Russ extern u64 e820_hole_size(u64 start, u64 end);
130*fea25720SGraeme Russ extern void finish_e820_parsing(void);
131*fea25720SGraeme Russ extern void e820_reserve_resources(void);
132*fea25720SGraeme Russ extern void e820_reserve_resources_late(void);
133*fea25720SGraeme Russ extern void setup_memory_map(void);
134*fea25720SGraeme Russ extern char *default_machine_specific_memory_setup(void);
135*fea25720SGraeme Russ 
136*fea25720SGraeme Russ /*
137*fea25720SGraeme Russ  * Returns true iff the specified range [s,e) is completely contained inside
138*fea25720SGraeme Russ  * the ISA region.
139*fea25720SGraeme Russ  */
140*fea25720SGraeme Russ /*
141*fea25720SGraeme Russ static inline bool is_ISA_range(u64 s, u64 e)
142*fea25720SGraeme Russ {
143*fea25720SGraeme Russ 	return s >= ISA_START_ADDRESS && e <= ISA_END_ADDRESS;
144*fea25720SGraeme Russ }
145*fea25720SGraeme Russ */
146*fea25720SGraeme Russ #endif /* __KERNEL__ */
147*fea25720SGraeme Russ #endif /* __ASSEMBLY__ */
148*fea25720SGraeme Russ 
149*fea25720SGraeme Russ #ifdef __KERNEL__
150*fea25720SGraeme Russ /* #include <linux/ioport.h> */
151*fea25720SGraeme Russ 
152*fea25720SGraeme Russ #define HIGH_MEMORY	(1024*1024)
153*fea25720SGraeme Russ #endif /* __KERNEL__ */
154*fea25720SGraeme Russ 
155*fea25720SGraeme Russ #endif /* _ASM_X86_E820_H */
156