ARM: 9089/1: Define kernel physical section start and end
authorLinus Walleij <linus.walleij@linaro.org>
Thu, 3 Jun 2021 08:51:21 +0000 (09:51 +0100)
committerRussell King (Oracle) <rmk+kernel@armlinux.org.uk>
Sun, 13 Jun 2021 17:16:41 +0000 (18:16 +0100)
When we are mapping the initial sections in head.S we
know very well where the start and end of the kernel image
in physical memory is placed. Later on it gets hard
to determine this.

Save the information into two variables named
kernel_sec_start and kernel_sec_end for convenience
for later work involving the physical start and end
of the kernel. These variables are section-aligned
corresponding to the early section mappings set up
in head.S.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
arch/arm/include/asm/memory.h
arch/arm/kernel/head.S

index a5f1d18..ca213d7 100644 (file)
@@ -159,6 +159,13 @@ extern unsigned long vectors_base;
 #ifndef __ASSEMBLY__
 
 /*
+ * Physical start and end address of the kernel sections. These addresses are
+ * 2MB-aligned to match the section mappings placed over the kernel.
+ */
+extern phys_addr_t kernel_sec_start;
+extern phys_addr_t kernel_sec_end;
+
+/*
  * Physical vs virtual RAM address space conversion.  These are
  * private definitions which should NOT be used outside memory.h
  * files.  Use virt_to_phys/phys_to_virt/__pa/__va instead.
index 4e2daaa..9eb0b4d 100644 (file)
        .globl  swapper_pg_dir
        .equ    swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
 
+       /*
+        * This needs to be assigned at runtime when the linker symbols are
+        * resolved.
+        */
+       .pushsection .data
+       .align  2
+       .globl  kernel_sec_start
+       .globl  kernel_sec_end
+kernel_sec_start:
+       .long   0
+kernel_sec_end:
+       .long   0
+       .popsection
+
        .macro  pgtbl, rd, phys
        add     \rd, \phys, #TEXT_OFFSET
        sub     \rd, \rd, #PG_DIR_SIZE
@@ -229,16 +243,23 @@ __create_page_tables:
        blo     1b
 
        /*
-        * Map our RAM from the start to the end of the kernel .bss section.
+        * The main matter: map in the kernel using section mappings, and
+        * set two variables to indicate the physical start and end of the
+        * kernel.
         */
-       add     r0, r4, #PAGE_OFFSET >> (SECTION_SHIFT - PMD_ORDER)
+       add     r0, r4, #KERNEL_OFFSET >> (SECTION_SHIFT - PMD_ORDER)
        ldr     r6, =(_end - 1)
-       orr     r3, r8, r7
+       adr_l   r5, kernel_sec_start            @ _pa(kernel_sec_start)
+       str     r8, [r5]                        @ Save physical start of kernel
+       orr     r3, r8, r7                      @ Add the MMU flags
        add     r6, r4, r6, lsr #(SECTION_SHIFT - PMD_ORDER)
 1:     str     r3, [r0], #1 << PMD_ORDER
        add     r3, r3, #1 << SECTION_SHIFT
        cmp     r0, r6
        bls     1b
+       eor     r3, r3, r7                      @ Remove the MMU flags
+       adr_l   r5, kernel_sec_end              @ _pa(kernel_sec_end)
+       str     r3, [r5]                        @ Save physical end of kernel
 
 #ifdef CONFIG_XIP_KERNEL
        /*