RISC-V: Implement compile-time fixed mappings
This patch implements compile-time virtual to physical mappings. These compile-time fixed mappings can be used by earlycon, ACPI, and early ioremap for creating fixed mappings when FIX_EARLYCON_MEM=y. To start with, we have enabled compile-time fixed mappings for earlycon. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Palmer Dabbelt <palmer@sifive.com>
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
#include <linux/sizes.h>
|
||||
#include <linux/of_fdt.h>
|
||||
|
||||
#include <asm/fixmap.h>
|
||||
#include <asm/tlbflush.h>
|
||||
#include <asm/sections.h>
|
||||
#include <asm/pgtable.h>
|
||||
@@ -148,8 +149,28 @@ pgd_t trampoline_pg_dir[PTRS_PER_PGD] __initdata __aligned(PAGE_SIZE);
|
||||
#define NUM_SWAPPER_PMDS ((uintptr_t)-PAGE_OFFSET >> PGDIR_SHIFT)
|
||||
pmd_t swapper_pmd[PTRS_PER_PMD*((-PAGE_OFFSET)/PGDIR_SIZE)] __page_aligned_bss;
|
||||
pmd_t trampoline_pmd[PTRS_PER_PGD] __initdata __aligned(PAGE_SIZE);
|
||||
pmd_t fixmap_pmd[PTRS_PER_PMD] __page_aligned_bss;
|
||||
#endif
|
||||
|
||||
pte_t fixmap_pte[PTRS_PER_PTE] __page_aligned_bss;
|
||||
|
||||
void __set_fixmap(enum fixed_addresses idx, phys_addr_t phys, pgprot_t prot)
|
||||
{
|
||||
unsigned long addr = __fix_to_virt(idx);
|
||||
pte_t *ptep;
|
||||
|
||||
BUG_ON(idx <= FIX_HOLE || idx >= __end_of_fixed_addresses);
|
||||
|
||||
ptep = &fixmap_pte[pte_index(addr)];
|
||||
|
||||
if (pgprot_val(prot)) {
|
||||
set_pte(ptep, pfn_pte(phys >> PAGE_SHIFT, prot));
|
||||
} else {
|
||||
pte_clear(&init_mm, addr, ptep);
|
||||
local_flush_tlb_page(addr);
|
||||
}
|
||||
}
|
||||
|
||||
asmlinkage void __init setup_vm(void)
|
||||
{
|
||||
extern char _start;
|
||||
@@ -172,20 +193,33 @@ asmlinkage void __init setup_vm(void)
|
||||
|
||||
for (i = 0; i < (-PAGE_OFFSET)/PGDIR_SIZE; ++i) {
|
||||
size_t o = (PAGE_OFFSET >> PGDIR_SHIFT) % PTRS_PER_PGD + i;
|
||||
|
||||
swapper_pg_dir[o] =
|
||||
pfn_pgd(PFN_DOWN((uintptr_t)swapper_pmd) + i,
|
||||
__pgprot(_PAGE_TABLE));
|
||||
}
|
||||
for (i = 0; i < ARRAY_SIZE(swapper_pmd); i++)
|
||||
swapper_pmd[i] = pfn_pmd(PFN_DOWN(pa + i * PMD_SIZE), prot);
|
||||
|
||||
swapper_pg_dir[(FIXADDR_START >> PGDIR_SHIFT) % PTRS_PER_PGD] =
|
||||
pfn_pgd(PFN_DOWN((uintptr_t)fixmap_pmd),
|
||||
__pgprot(_PAGE_TABLE));
|
||||
fixmap_pmd[(FIXADDR_START >> PMD_SHIFT) % PTRS_PER_PMD] =
|
||||
pfn_pmd(PFN_DOWN((uintptr_t)fixmap_pte),
|
||||
__pgprot(_PAGE_TABLE));
|
||||
#else
|
||||
trampoline_pg_dir[(PAGE_OFFSET >> PGDIR_SHIFT) % PTRS_PER_PGD] =
|
||||
pfn_pgd(PFN_DOWN(pa), prot);
|
||||
|
||||
for (i = 0; i < (-PAGE_OFFSET)/PGDIR_SIZE; ++i) {
|
||||
size_t o = (PAGE_OFFSET >> PGDIR_SHIFT) % PTRS_PER_PGD + i;
|
||||
|
||||
swapper_pg_dir[o] =
|
||||
pfn_pgd(PFN_DOWN(pa + i * PGDIR_SIZE), prot);
|
||||
}
|
||||
|
||||
swapper_pg_dir[(FIXADDR_START >> PGDIR_SHIFT) % PTRS_PER_PGD] =
|
||||
pfn_pgd(PFN_DOWN((uintptr_t)fixmap_pte),
|
||||
__pgprot(_PAGE_TABLE));
|
||||
#endif
|
||||
}
|
||||
|
Reference in New Issue
Block a user