Meng-Huan Yu has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/48113 )
Change subject: mmu: Provide API to expose mmu memery ranges for all archs ......................................................................
mmu: Provide API to expose mmu memery ranges for all archs
Provide lib_get_mmu_ranges() to let payloads could get mmu information for all used memory regions.
* Move mmu related structure from arm64 mmu.h to new include/mmu_range.h * Provide empty API for x86 and arm.
BUG=b:171858277 TEST=Build in x86, arm, arm64. emerge-zork libpayload depthcharge emerge-nyan libpayload depthcharge emerge-asurada libpayload depthcharge
Signed-off-by: Meng-Huan Yu menghuan@google.com Change-Id: I39b24aefc9dbe530169b272e839d0e1e7c697742 --- M payloads/libpayload/arch/arm/Makefile.inc A payloads/libpayload/arch/arm/mmu.c M payloads/libpayload/arch/arm64/mmu.c M payloads/libpayload/arch/x86/Makefile.inc A payloads/libpayload/arch/x86/mmu.c M payloads/libpayload/include/arm64/arch/mmu.h M payloads/libpayload/include/libpayload.h A payloads/libpayload/include/mmu_range.h 8 files changed, 131 insertions(+), 19 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/13/48113/1
diff --git a/payloads/libpayload/arch/arm/Makefile.inc b/payloads/libpayload/arch/arm/Makefile.inc index c973601..6287641 100644 --- a/payloads/libpayload/arch/arm/Makefile.inc +++ b/payloads/libpayload/arch/arm/Makefile.inc @@ -37,6 +37,7 @@ libc-y += exception_asm.S exception.c libc-y += cache.c cpu.S libc-y += selfboot.c +libc-y += mmu.c
# Will fall back to default_memXXX() in libc/memory.c if GPL not allowed. libc-$(CONFIG_LP_GPL) += memcpy.S memset.S memmove.S diff --git a/payloads/libpayload/arch/arm/mmu.c b/payloads/libpayload/arch/arm/mmu.c new file mode 100644 index 0000000..e90426a --- /dev/null +++ b/payloads/libpayload/arch/arm/mmu.c @@ -0,0 +1,34 @@ +/* + * + * Copyright 2020 Google Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <libpayload.h> + +const struct mmu_ranges* lib_get_mmu_ranges(void) +{ + return NULL; +} diff --git a/payloads/libpayload/arch/arm64/mmu.c b/payloads/libpayload/arch/arm64/mmu.c index cb0081b..6caf912 100644 --- a/payloads/libpayload/arch/arm64/mmu.c +++ b/payloads/libpayload/arch/arm64/mmu.c @@ -705,3 +705,8 @@ mmu_init(&usedmem_ranges); mmu_enable(); } + +const struct mmu_ranges* lib_get_mmu_ranges(void) +{ + return &usedmem_ranges; +} diff --git a/payloads/libpayload/arch/x86/Makefile.inc b/payloads/libpayload/arch/x86/Makefile.inc index 41228f2..e373a2e 100644 --- a/payloads/libpayload/arch/x86/Makefile.inc +++ b/payloads/libpayload/arch/x86/Makefile.inc @@ -35,6 +35,7 @@ libc-y += selfboot.c libc-y += exception_asm.S exception.c libc-y += delay.c +libc-y += mmu.c
# Will fall back to default_memXXX() in libc/memory.c if GPL not allowed. libc-$(CONFIG_LP_GPL) += string.c diff --git a/payloads/libpayload/arch/x86/mmu.c b/payloads/libpayload/arch/x86/mmu.c new file mode 100644 index 0000000..e90426a --- /dev/null +++ b/payloads/libpayload/arch/x86/mmu.c @@ -0,0 +1,34 @@ +/* + * + * Copyright 2020 Google Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <libpayload.h> + +const struct mmu_ranges* lib_get_mmu_ranges(void) +{ + return NULL; +} diff --git a/payloads/libpayload/include/arm64/arch/mmu.h b/payloads/libpayload/include/arm64/arch/mmu.h index 5a1dd98..273e6e4 100644 --- a/payloads/libpayload/include/arm64/arch/mmu.h +++ b/payloads/libpayload/include/arm64/arch/mmu.h @@ -31,31 +31,12 @@
#include <libpayload.h>
-struct mmu_memrange { - uint64_t base; - uint64_t size; - uint64_t type; -}; - -struct mmu_ranges { - struct mmu_memrange entries[SYSINFO_MAX_MEM_RANGES]; - size_t used; -}; - /* * Symbols taken from linker script * They mark the start and end of the region used by payload */ extern char _start[], _end[];
-/* Memory attributes for mmap regions - * These attributes act as tag values for memrange regions - */ - -#define TYPE_NORMAL_MEM 1 -#define TYPE_DEV_MEM 2 -#define TYPE_DMA_MEM 3 - /* Descriptor attributes */
#define INVALID_DESC 0x0 diff --git a/payloads/libpayload/include/libpayload.h b/payloads/libpayload/include/libpayload.h index f206fea..83f3c25 100644 --- a/payloads/libpayload/include/libpayload.h +++ b/payloads/libpayload/include/libpayload.h @@ -64,6 +64,7 @@ #include <sysinfo.h> #include <pci.h> #include <archive.h> +#include <mmu_range.h>
/* Double-evaluation unsafe min/max, for bitfields and outside of functions */ #define __CMP_UNSAFE(a, b, op) ((a) op (b) ? (a) : (b)) @@ -526,6 +527,7 @@ int lib_get_sysinfo(void); void lib_sysinfo_get_memranges(struct memrange **ranges, uint64_t *nranges); +const struct mmu_ranges* lib_get_mmu_ranges(void);
/* Timer functions. */ /* Defined by each architecture. */ diff --git a/payloads/libpayload/include/mmu_range.h b/payloads/libpayload/include/mmu_range.h new file mode 100644 index 0000000..17aaec6 --- /dev/null +++ b/payloads/libpayload/include/mmu_range.h @@ -0,0 +1,54 @@ +/* + * + * Copyright 2020 Google Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef __MMU_MEMRANGE_H__ +#define __MMU_MEMRANGE_H__ + +#include <stddef.h> +#include <sysinfo.h> + +struct mmu_memrange { + uint64_t base; + uint64_t size; + uint64_t type; +}; + +struct mmu_ranges { + struct mmu_memrange entries[SYSINFO_MAX_MEM_RANGES]; + size_t used; +}; + +/* Memory attributes for mmap regions + * These attributes act as tag values for memrange regions + */ + +#define TYPE_NORMAL_MEM 1 +#define TYPE_DEV_MEM 2 +#define TYPE_DMA_MEM 3 + +#endif // __MMU_MEMRANGE_H__