From 70a9d8184ccecf7a38848531fb4767a85134f464 Mon Sep 17 00:00:00 2001 From: Ingo Molnar Date: Fri, 27 Jan 2017 09:58:02 +0100 Subject: x86/boot/e820: Introduce arch/x86/include/asm/e820/types.h First baby steps towards saner e820 headers: create an exact copy of arch/x86/include/uapi/asm/e820.h and use it from the asm/e820.h file. No other changes - this is done to decouple the code from UAPI headers, plus to make sure that subsequent modifications to the file can be more clearly seen. The plan is to keep the old UAPI header in place but the kernel won't use it anymore - and after some time we'll try to remove it. (User-space tools better have local copies of headers anyway, instead of relying on kernel headers.) This gives the kernel the freedom to reorganize the e820 code. Cc: Alex Thorlton Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Brian Gerst Cc: Dan Williams Cc: Denys Vlasenko Cc: H. Peter Anvin Cc: Huang, Ying Cc: Josh Poimboeuf Cc: Juergen Gross Cc: Linus Torvalds Cc: Paul Jackson Cc: Peter Zijlstra Cc: Rafael J. Wysocki Cc: Tejun Heo Cc: Thomas Gleixner Cc: Wei Yang Cc: Yinghai Lu Cc: linux-kernel@vger.kernel.org Signed-off-by: Ingo Molnar --- arch/x86/include/asm/e820.h | 4 +- arch/x86/include/asm/e820/types.h | 81 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 arch/x86/include/asm/e820/types.h diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h index 67313f3a9874..55c1d76c169f 100644 --- a/arch/x86/include/asm/e820.h +++ b/arch/x86/include/asm/e820.h @@ -5,12 +5,12 @@ * E820_X_MAX is the maximum size of the extended E820 table. The extended * table may contain up to 3 extra E820 entries per possible NUMA node, so we * make room for 3 * MAX_NUMNODES possible entries, beyond the standard 128. - * Also note that E820_X_MAX *must* be defined before we include uapi/asm/e820.h. + * Also note that E820_X_MAX *must* be defined before we include asm/e820/types.h. */ #include #define E820_X_MAX (E820MAX + 3 * MAX_NUMNODES) -#include +#include #ifndef __ASSEMBLY__ /* see comment in arch/x86/kernel/e820.c */ diff --git a/arch/x86/include/asm/e820/types.h b/arch/x86/include/asm/e820/types.h new file mode 100644 index 000000000000..9dafe59cf6e2 --- /dev/null +++ b/arch/x86/include/asm/e820/types.h @@ -0,0 +1,81 @@ +#ifndef _UAPI_ASM_X86_E820_H +#define _UAPI_ASM_X86_E820_H +#define E820MAP 0x2d0 /* our map */ +#define E820MAX 128 /* number of entries in E820MAP */ + +/* + * Legacy E820 BIOS limits us to 128 (E820MAX) nodes due to the + * constrained space in the zeropage. If we have more nodes than + * that, and if we've booted off EFI firmware, then the EFI tables + * passed us from the EFI firmware can list more nodes. Size our + * internal memory map tables to have room for these additional + * nodes, based on up to three entries per node for which the + * kernel was built: MAX_NUMNODES == (1 << CONFIG_NODES_SHIFT), + * plus E820MAX, allowing space for the possible duplicate E820 + * entries that might need room in the same arrays, prior to the + * call to sanitize_e820_map() to remove duplicates. The allowance + * of three memory map entries per node is "enough" entries for + * the initial hardware platform motivating this mechanism to make + * use of additional EFI map entries. Future platforms may want + * to allow more than three entries per node or otherwise refine + * this size. + */ + +#ifndef __KERNEL__ +#define E820_X_MAX E820MAX +#endif + +#define E820NR 0x1e8 /* # entries in E820MAP */ + +#define E820_RAM 1 +#define E820_RESERVED 2 +#define E820_ACPI 3 +#define E820_NVS 4 +#define E820_UNUSABLE 5 +#define E820_PMEM 7 + +/* + * This is a non-standardized way to represent ADR or NVDIMM regions that + * persist over a reboot. The kernel will ignore their special capabilities + * unless the CONFIG_X86_PMEM_LEGACY option is set. + * + * ( Note that older platforms also used 6 for the same type of memory, + * but newer versions switched to 12 as 6 was assigned differently. Some + * time they will learn... ) + */ +#define E820_PRAM 12 + +/* + * reserved RAM used by kernel itself + * if CONFIG_INTEL_TXT is enabled, memory of this type will be + * included in the S3 integrity calculation and so should not include + * any memory that BIOS might alter over the S3 transition + */ +#define E820_RESERVED_KERN 128 + +#ifndef __ASSEMBLY__ +#include +struct e820entry { + __u64 addr; /* start of memory segment */ + __u64 size; /* size of memory segment */ + __u32 type; /* type of memory segment */ +} __attribute__((packed)); + +struct e820map { + __u32 nr_map; + struct e820entry map[E820_X_MAX]; +}; + +#define ISA_START_ADDRESS 0xa0000 +#define ISA_END_ADDRESS 0x100000 + +#define BIOS_BEGIN 0x000a0000 +#define BIOS_END 0x00100000 + +#define BIOS_ROM_BASE 0xffe00000 +#define BIOS_ROM_END 0xffffffff + +#endif /* __ASSEMBLY__ */ + + +#endif /* _UAPI_ASM_X86_E820_H */ -- cgit From 7b80ba55aa2919d5b26021659f025905aaea44ed Mon Sep 17 00:00:00 2001 From: Ingo Molnar Date: Fri, 27 Jan 2017 10:22:23 +0100 Subject: x86/boot/e820: Clean up and improve comments in asm/e820/types.h Do some common-sense cleanups: - standardize on the kernel coding style consistently - tabulate definitions consistently - extend and clarify various descriptions - fix speling - update the header guard name according to the new position - etc. No change in functionality. Cc: Alex Thorlton Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Brian Gerst Cc: Dan Williams Cc: Denys Vlasenko Cc: H. Peter Anvin Cc: Huang, Ying Cc: Josh Poimboeuf Cc: Juergen Gross Cc: Linus Torvalds Cc: Paul Jackson Cc: Peter Zijlstra Cc: Rafael J. Wysocki Cc: Tejun Heo Cc: Thomas Gleixner Cc: Wei Yang Cc: Yinghai Lu Cc: linux-kernel@vger.kernel.org Signed-off-by: Ingo Molnar --- arch/x86/include/asm/e820/types.h | 84 ++++++++++++++++++++++++--------------- 1 file changed, 53 insertions(+), 31 deletions(-) diff --git a/arch/x86/include/asm/e820/types.h b/arch/x86/include/asm/e820/types.h index 9dafe59cf6e2..cfa8f4a19b5d 100644 --- a/arch/x86/include/asm/e820/types.h +++ b/arch/x86/include/asm/e820/types.h @@ -1,18 +1,30 @@ -#ifndef _UAPI_ASM_X86_E820_H -#define _UAPI_ASM_X86_E820_H -#define E820MAP 0x2d0 /* our map */ -#define E820MAX 128 /* number of entries in E820MAP */ +#ifndef _ASM_E820_TYPES_H +#define _ASM_E820_TYPES_H + +/* Our map: */ +#define E820MAP 0x2d0 + +/* The maximum number of entries in E820MAP: */ +#define E820MAX 128 /* - * Legacy E820 BIOS limits us to 128 (E820MAX) nodes due to the - * constrained space in the zeropage. If we have more nodes than - * that, and if we've booted off EFI firmware, then the EFI tables - * passed us from the EFI firmware can list more nodes. Size our - * internal memory map tables to have room for these additional - * nodes, based on up to three entries per node for which the - * kernel was built: MAX_NUMNODES == (1 << CONFIG_NODES_SHIFT), - * plus E820MAX, allowing space for the possible duplicate E820 - * entries that might need room in the same arrays, prior to the + * The legacy E820 BIOS limits us to 128 (E820MAX) nodes due to the + * constrained space in the zeropage. + * + * On large systems we can easily have thousands of nodes with RAM, + * which cannot be fit into so few entries - so we have a mechanism + * to extend the e820 table size at build-time, via the E820_X_MAX + * define below. + * + * ( Those extra entries are enumerated via the EFI memory map, not + * via the legacy zeropage mechanism. ) + * + * Size our internal memory map tables to have room for these additional + * entries, based on a heuristic calculation: up to three entries per + * NUMA node, plus E820MAX for some extra space. + * + * This allows for bootstrap/firmware quirks such as possible duplicate + * E820 entries that might need room in the same arrays, prior to the * call to sanitize_e820_map() to remove duplicates. The allowance * of three memory map entries per node is "enough" entries for * the initial hardware platform motivating this mechanism to make @@ -20,19 +32,19 @@ * to allow more than three entries per node or otherwise refine * this size. */ - #ifndef __KERNEL__ -#define E820_X_MAX E820MAX +# define E820_X_MAX E820MAX #endif -#define E820NR 0x1e8 /* # entries in E820MAP */ +/* Number of entries in E820MAP: */ +#define E820NR 0x1e8 -#define E820_RAM 1 -#define E820_RESERVED 2 -#define E820_ACPI 3 -#define E820_NVS 4 -#define E820_UNUSABLE 5 -#define E820_PMEM 7 +#define E820_RAM 1 +#define E820_RESERVED 2 +#define E820_ACPI 3 +#define E820_NVS 4 +#define E820_UNUSABLE 5 +#define E820_PMEM 7 /* * This is a non-standardized way to represent ADR or NVDIMM regions that @@ -43,7 +55,7 @@ * but newer versions switched to 12 as 6 was assigned differently. Some * time they will learn... ) */ -#define E820_PRAM 12 +#define E820_PRAM 12 /* * reserved RAM used by kernel itself @@ -51,23 +63,34 @@ * included in the S3 integrity calculation and so should not include * any memory that BIOS might alter over the S3 transition */ -#define E820_RESERVED_KERN 128 +#define E820_RESERVED_KERN 128 #ifndef __ASSEMBLY__ #include + +/* + * A single E820 map entry, describing a memory range of [addr...addr+size-1], + * of 'type' memory type: + */ struct e820entry { - __u64 addr; /* start of memory segment */ - __u64 size; /* size of memory segment */ - __u32 type; /* type of memory segment */ + __u64 addr; + __u64 size; + __u32 type; } __attribute__((packed)); +/* + * The whole array of E820 entries: + */ struct e820map { __u32 nr_map; struct e820entry map[E820_X_MAX]; }; -#define ISA_START_ADDRESS 0xa0000 -#define ISA_END_ADDRESS 0x100000 +/* + * Various legacy ranges in physical memory: + */ +#define ISA_START_ADDRESS 0x000a0000 +#define ISA_END_ADDRESS 0x00100000 #define BIOS_BEGIN 0x000a0000 #define BIOS_END 0x00100000 @@ -77,5 +100,4 @@ struct e820map { #endif /* __ASSEMBLY__ */ - -#endif /* _UAPI_ASM_X86_E820_H */ +#endif /* _ASM_E820_TYPES_H */ -- cgit From 66441bd3cfdcc03816b7009a296c284d70f629e1 Mon Sep 17 00:00:00 2001 From: Ingo Molnar Date: Fri, 27 Jan 2017 10:27:10 +0100 Subject: x86/boot/e820: Move asm/e820.h to asm/e820/api.h In line with asm/e820/types.h, move the e820 API declarations to asm/e820/api.h and update all usage sites. This is just a mechanical, obviously correct move & replace patch, there will be subsequent changes to clean up the code and to make better use of the new header organization. Cc: Alex Thorlton Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Brian Gerst Cc: Dan Williams Cc: Denys Vlasenko Cc: H. Peter Anvin Cc: Huang, Ying Cc: Josh Poimboeuf Cc: Juergen Gross Cc: Linus Torvalds Cc: Paul Jackson Cc: Peter Zijlstra Cc: Rafael J. Wysocki Cc: Tejun Heo Cc: Thomas Gleixner Cc: Wei Yang Cc: Yinghai Lu Cc: linux-kernel@vger.kernel.org Signed-off-by: Ingo Molnar --- arch/x86/boot/header.S | 2 +- arch/x86/include/asm/e820.h | 73 ----------------------------------- arch/x86/include/asm/e820/api.h | 73 +++++++++++++++++++++++++++++++++++ arch/x86/include/asm/gart.h | 2 +- arch/x86/include/asm/pgtable.h | 2 +- arch/x86/include/uapi/asm/bootparam.h | 2 +- arch/x86/kernel/aperture_64.c | 2 +- arch/x86/kernel/apic/apic_noop.c | 2 +- arch/x86/kernel/apic/probe_32.c | 2 +- arch/x86/kernel/cpu/centaur.c | 2 +- arch/x86/kernel/cpu/mtrr/cleanup.c | 2 +- arch/x86/kernel/cpu/mtrr/main.c | 2 +- arch/x86/kernel/e820.c | 2 +- arch/x86/kernel/head32.c | 2 +- arch/x86/kernel/head64.c | 2 +- arch/x86/kernel/mpparse.c | 2 +- arch/x86/kernel/probe_roms.c | 2 +- arch/x86/kernel/resource.c | 2 +- arch/x86/kernel/setup.c | 2 +- arch/x86/kernel/tboot.c | 2 +- arch/x86/kernel/x86_init.c | 2 +- arch/x86/lguest/boot.c | 2 +- arch/x86/lib/kaslr.c | 2 +- arch/x86/mm/amdtopology.c | 2 +- arch/x86/mm/init.c | 2 +- arch/x86/mm/init_32.c | 2 +- arch/x86/mm/init_64.c | 2 +- arch/x86/mm/ioremap.c | 2 +- arch/x86/mm/mmio-mod.c | 2 +- arch/x86/mm/numa.c | 2 +- arch/x86/mm/pageattr.c | 2 +- arch/x86/mm/pat.c | 2 +- arch/x86/mm/pgtable_32.c | 2 +- arch/x86/mm/srat.c | 2 +- arch/x86/pci/i386.c | 2 +- arch/x86/pci/mmconfig-shared.c | 2 +- arch/x86/pci/mmconfig_32.c | 2 +- arch/x86/pci/mmconfig_64.c | 2 +- arch/x86/platform/efi/efi_64.c | 2 +- arch/x86/xen/mmu.c | 2 +- arch/x86/xen/setup.c | 2 +- drivers/char/agp/amd64-agp.c | 2 +- 42 files changed, 113 insertions(+), 113 deletions(-) delete mode 100644 arch/x86/include/asm/e820.h create mode 100644 arch/x86/include/asm/e820/api.h diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S index 3dd5be33aaa7..398b290c4c00 100644 --- a/arch/x86/boot/header.S +++ b/arch/x86/boot/header.S @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h deleted file mode 100644 index 55c1d76c169f..000000000000 --- a/arch/x86/include/asm/e820.h +++ /dev/null @@ -1,73 +0,0 @@ -#ifndef _ASM_X86_E820_H -#define _ASM_X86_E820_H - -/* - * E820_X_MAX is the maximum size of the extended E820 table. The extended - * table may contain up to 3 extra E820 entries per possible NUMA node, so we - * make room for 3 * MAX_NUMNODES possible entries, beyond the standard 128. - * Also note that E820_X_MAX *must* be defined before we include asm/e820/types.h. - */ -#include -#define E820_X_MAX (E820MAX + 3 * MAX_NUMNODES) - -#include - -#ifndef __ASSEMBLY__ -/* see comment in arch/x86/kernel/e820.c */ -extern struct e820map *e820; -extern struct e820map *e820_saved; - -extern unsigned long pci_mem_start; -extern int e820_any_mapped(u64 start, u64 end, unsigned type); -extern int e820_all_mapped(u64 start, u64 end, unsigned type); -extern void e820_add_region(u64 start, u64 size, int type); -extern void e820_print_map(char *who); -extern int -sanitize_e820_map(struct e820entry *biosmap, int max_nr_map, u32 *pnr_map); -extern u64 e820_update_range(u64 start, u64 size, unsigned old_type, - unsigned new_type); -extern u64 e820_remove_range(u64 start, u64 size, unsigned old_type, - int checktype); -extern void update_e820(void); -extern void e820_setup_gap(void); -struct setup_data; -extern void parse_e820_ext(u64 phys_addr, u32 data_len); - -#if defined(CONFIG_X86_64) || \ - (defined(CONFIG_X86_32) && defined(CONFIG_HIBERNATION)) -extern void e820_mark_nosave_regions(unsigned long limit_pfn); -#else -static inline void e820_mark_nosave_regions(unsigned long limit_pfn) -{ -} -#endif - -extern unsigned long e820_end_of_ram_pfn(void); -extern unsigned long e820_end_of_low_ram_pfn(void); -extern u64 early_reserve_e820(u64 sizet, u64 align); - -void memblock_x86_fill(void); -void memblock_find_dma_reserve(void); - -extern void finish_e820_parsing(void); -extern void e820_reserve_resources(void); -extern void e820_reserve_resources_late(void); -extern void setup_memory_map(void); -extern char *default_machine_specific_memory_setup(void); - -extern void e820_reallocate_tables(void); - -/* - * Returns true iff the specified range [s,e) is completely contained inside - * the ISA region. - */ -static inline bool is_ISA_range(u64 s, u64 e) -{ - return s >= ISA_START_ADDRESS && e <= ISA_END_ADDRESS; -} - -#endif /* __ASSEMBLY__ */ -#include - -#define HIGH_MEMORY (1024*1024) -#endif /* _ASM_X86_E820_H */ diff --git a/arch/x86/include/asm/e820/api.h b/arch/x86/include/asm/e820/api.h new file mode 100644 index 000000000000..010efbceb40c --- /dev/null +++ b/arch/x86/include/asm/e820/api.h @@ -0,0 +1,73 @@ +#ifndef _ASM_E820_API_H +#define _ASM_E820_API_H + +/* + * E820_X_MAX is the maximum size of the extended E820 table. The extended + * table may contain up to 3 extra E820 entries per possible NUMA node, so we + * make room for 3 * MAX_NUMNODES possible entries, beyond the standard 128. + * Also note that E820_X_MAX *must* be defined before we include asm/e820/types.h. + */ +#include +#define E820_X_MAX (E820MAX + 3 * MAX_NUMNODES) + +#include + +#ifndef __ASSEMBLY__ +/* see comment in arch/x86/kernel/e820.c */ +extern struct e820map *e820; +extern struct e820map *e820_saved; + +extern unsigned long pci_mem_start; +extern int e820_any_mapped(u64 start, u64 end, unsigned type); +extern int e820_all_mapped(u64 start, u64 end, unsigned type); +extern void e820_add_region(u64 start, u64 size, int type); +extern void e820_print_map(char *who); +extern int +sanitize_e820_map(struct e820entry *biosmap, int max_nr_map, u32 *pnr_map); +extern u64 e820_update_range(u64 start, u64 size, unsigned old_type, + unsigned new_type); +extern u64 e820_remove_range(u64 start, u64 size, unsigned old_type, + int checktype); +extern void update_e820(void); +extern void e820_setup_gap(void); +struct setup_data; +extern void parse_e820_ext(u64 phys_addr, u32 data_len); + +#if defined(CONFIG_X86_64) || \ + (defined(CONFIG_X86_32) && defined(CONFIG_HIBERNATION)) +extern void e820_mark_nosave_regions(unsigned long limit_pfn); +#else +static inline void e820_mark_nosave_regions(unsigned long limit_pfn) +{ +} +#endif + +extern unsigned long e820_end_of_ram_pfn(void); +extern unsigned long e820_end_of_low_ram_pfn(void); +extern u64 early_reserve_e820(u64 sizet, u64 align); + +void memblock_x86_fill(void); +void memblock_find_dma_reserve(void); + +extern void finish_e820_parsing(void); +extern void e820_reserve_resources(void); +extern void e820_reserve_resources_late(void); +extern void setup_memory_map(void); +extern char *default_machine_specific_memory_setup(void); + +extern void e820_reallocate_tables(void); + +/* + * Returns true iff the specified range [s,e) is completely contained inside + * the ISA region. + */ +static inline bool is_ISA_range(u64 s, u64 e) +{ + return s >= ISA_START_ADDRESS && e <= ISA_END_ADDRESS; +} + +#endif /* __ASSEMBLY__ */ +#include + +#define HIGH_MEMORY (1024*1024) +#endif /* _ASM_E820_API_H */ diff --git a/arch/x86/include/asm/gart.h b/arch/x86/include/asm/gart.h index 156cd5d18d2a..e26a5d7fc368 100644 --- a/arch/x86/include/asm/gart.h +++ b/arch/x86/include/asm/gart.h @@ -1,7 +1,7 @@ #ifndef _ASM_X86_GART_H #define _ASM_X86_GART_H -#include +#include extern void set_up_gart_resume(u32, u32); diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h index 437feb436efa..ae0b84d8ccb5 100644 --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h @@ -2,7 +2,7 @@ #define _ASM_X86_PGTABLE_H #include -#include +#include #include diff --git a/arch/x86/include/uapi/asm/bootparam.h b/arch/x86/include/uapi/asm/bootparam.h index b10bf319ed20..2214bfc65c66 100644 --- a/arch/x86/include/uapi/asm/bootparam.h +++ b/arch/x86/include/uapi/asm/bootparam.h @@ -34,7 +34,7 @@ #include #include #include -#include +#include #include #include