^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Provide common bits of early_ioremap() support for architectures needing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * temporary mappings during boot before ioremap() is available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * This is mostly a direct copy of the x86 early_ioremap implementation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * (C) Copyright 1995 1996, 2014 Linus Torvalds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/vmalloc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <asm/fixmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <asm/early_ioremap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #ifdef CONFIG_MMU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) static int early_ioremap_debug __initdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) static int __init early_ioremap_debug_setup(char *str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) early_ioremap_debug = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) early_param("early_ioremap_debug", early_ioremap_debug_setup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) static int after_paging_init __initdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) pgprot_t __init __weak early_memremap_pgprot_adjust(resource_size_t phys_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) unsigned long size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) pgprot_t prot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) return prot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) void __init __weak early_ioremap_shutdown(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) void __init early_ioremap_reset(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) early_ioremap_shutdown();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) after_paging_init = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * Generally, ioremap() is available after paging_init() has been called.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * Architectures wanting to allow early_ioremap after paging_init() can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * define __late_set_fixmap and __late_clear_fixmap to do the right thing.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #ifndef __late_set_fixmap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) static inline void __init __late_set_fixmap(enum fixed_addresses idx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) phys_addr_t phys, pgprot_t prot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) #ifndef __late_clear_fixmap
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) static inline void __init __late_clear_fixmap(enum fixed_addresses idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) static void __iomem *prev_map[FIX_BTMAPS_SLOTS] __initdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) static unsigned long prev_size[FIX_BTMAPS_SLOTS] __initdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) static unsigned long slot_virt[FIX_BTMAPS_SLOTS] __initdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) void __init early_ioremap_setup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) for (i = 0; i < FIX_BTMAPS_SLOTS; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) if (WARN_ON(prev_map[i]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) for (i = 0; i < FIX_BTMAPS_SLOTS; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) static int __init check_early_ioremap_leak(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) int count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) for (i = 0; i < FIX_BTMAPS_SLOTS; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) if (prev_map[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) if (WARN(count, KERN_WARNING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) "Debug warning: early ioremap leak of %d areas detected.\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) "please boot with early_ioremap_debug and report the dmesg.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) count))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) late_initcall(check_early_ioremap_leak);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) static void __init __iomem *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) __early_ioremap(resource_size_t phys_addr, unsigned long size, pgprot_t prot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) unsigned long offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) resource_size_t last_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) unsigned int nrpages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) enum fixed_addresses idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) int i, slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) WARN_ON(system_state >= SYSTEM_RUNNING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) slot = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) for (i = 0; i < FIX_BTMAPS_SLOTS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) if (!prev_map[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) slot = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) if (WARN(slot < 0, "%s(%pa, %08lx) not found slot\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) __func__, &phys_addr, size))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) /* Don't allow wraparound or zero size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) last_addr = phys_addr + size - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) if (WARN_ON(!size || last_addr < phys_addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) prev_size[slot] = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) * Mappings have to be page-aligned
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) offset = offset_in_page(phys_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) phys_addr &= PAGE_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) size = PAGE_ALIGN(last_addr + 1) - phys_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) * Mappings have to fit in the FIX_BTMAP area.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) nrpages = size >> PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) if (WARN_ON(nrpages > NR_FIX_BTMAPS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) * Ok, go for it..
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) idx = FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) while (nrpages > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) if (after_paging_init)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) __late_set_fixmap(idx, phys_addr, prot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) __early_set_fixmap(idx, phys_addr, prot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) phys_addr += PAGE_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) --idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) --nrpages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) WARN(early_ioremap_debug, "%s(%pa, %08lx) [%d] => %08lx + %08lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) __func__, &phys_addr, size, slot, offset, slot_virt[slot]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) prev_map[slot] = (void __iomem *)(offset + slot_virt[slot]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) return prev_map[slot];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) void __init early_iounmap(void __iomem *addr, unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) unsigned long virt_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) unsigned long offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) unsigned int nrpages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) enum fixed_addresses idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) int i, slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) slot = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) for (i = 0; i < FIX_BTMAPS_SLOTS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) if (prev_map[i] == addr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) slot = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) if (WARN(slot < 0, "early_iounmap(%p, %08lx) not found slot\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) addr, size))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) if (WARN(prev_size[slot] != size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) "early_iounmap(%p, %08lx) [%d] size not consistent %08lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) addr, size, slot, prev_size[slot]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) WARN(early_ioremap_debug, "early_iounmap(%p, %08lx) [%d]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) addr, size, slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) virt_addr = (unsigned long)addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) if (WARN_ON(virt_addr < fix_to_virt(FIX_BTMAP_BEGIN)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) offset = offset_in_page(virt_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) nrpages = PAGE_ALIGN(offset + size) >> PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) idx = FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) while (nrpages > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) if (after_paging_init)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) __late_clear_fixmap(idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) __early_set_fixmap(idx, 0, FIXMAP_PAGE_CLEAR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) --idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) --nrpages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) prev_map[slot] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) /* Remap an IO device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) void __init __iomem *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) early_ioremap(resource_size_t phys_addr, unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) return __early_ioremap(phys_addr, size, FIXMAP_PAGE_IO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) /* Remap memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) void __init *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) early_memremap(resource_size_t phys_addr, unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) pgprot_t prot = early_memremap_pgprot_adjust(phys_addr, size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) FIXMAP_PAGE_NORMAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) return (__force void *)__early_ioremap(phys_addr, size, prot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) #ifdef FIXMAP_PAGE_RO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) void __init *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) early_memremap_ro(resource_size_t phys_addr, unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) pgprot_t prot = early_memremap_pgprot_adjust(phys_addr, size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) FIXMAP_PAGE_RO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) return (__force void *)__early_ioremap(phys_addr, size, prot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) #ifdef CONFIG_ARCH_USE_MEMREMAP_PROT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) void __init *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) early_memremap_prot(resource_size_t phys_addr, unsigned long size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) unsigned long prot_val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) return (__force void *)__early_ioremap(phys_addr, size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) __pgprot(prot_val));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) #define MAX_MAP_CHUNK (NR_FIX_BTMAPS << PAGE_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) void __init copy_from_early_mem(void *dest, phys_addr_t src, unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) unsigned long slop, clen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) char *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) while (size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) slop = offset_in_page(src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) clen = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) if (clen > MAX_MAP_CHUNK - slop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) clen = MAX_MAP_CHUNK - slop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) p = early_memremap(src & PAGE_MASK, clen + slop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) memcpy(dest, p + slop, clen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) early_memunmap(p, clen + slop);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) dest += clen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) src += clen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) size -= clen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) #else /* CONFIG_MMU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) void __init __iomem *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) early_ioremap(resource_size_t phys_addr, unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) return (__force void __iomem *)phys_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) /* Remap memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) void __init *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) early_memremap(resource_size_t phys_addr, unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) return (void *)phys_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) void __init *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) early_memremap_ro(resource_size_t phys_addr, unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) return (void *)phys_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) void __init early_iounmap(void __iomem *addr, unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) #endif /* CONFIG_MMU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) void __init early_memunmap(void *addr, unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) early_iounmap((__force void __iomem *)addr, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) }