Skip to content

Commit f93e580

Browse files
stffrdhrngregkh
authored andcommitted
openrisc: Implement fixmap to fix earlycon
[ Upstream commit 1037d18 ] With commit 53c98e3 ("openrisc: mm: remove unneeded early ioremap code") it was commented that early ioremap was not used in OpenRISC. I acked this but was wrong, earlycon was using it. Earlycon setup now fails with the below trace: Kernel command line: earlycon ------------[ cut here ]------------ WARNING: CPU: 0 PID: 0 at mm/ioremap.c:23 generic_ioremap_prot+0x118/0x130 Modules linked in: CPU: 0 UID: 0 PID: 0 Comm: swapper Not tainted 6.11.0-rc5-00001-gce02fd891c38-dirty Rust-for-Linux#141 Call trace: [<(ptrval)>] dump_stack_lvl+0x7c/0x9c [<(ptrval)>] dump_stack+0x1c/0x2c [<(ptrval)>] __warn+0xb4/0x108 [<(ptrval)>] ? generic_ioremap_prot+0x118/0x130 [<(ptrval)>] warn_slowpath_fmt+0x60/0x98 [<(ptrval)>] generic_ioremap_prot+0x118/0x130 [<(ptrval)>] ioremap_prot+0x20/0x30 [<(ptrval)>] of_setup_earlycon+0xd4/0x2e0 [<(ptrval)>] early_init_dt_scan_chosen_stdout+0x18c/0x1c8 [<(ptrval)>] param_setup_earlycon+0x3c/0x60 [<(ptrval)>] do_early_param+0xb0/0x118 [<(ptrval)>] parse_args+0x184/0x4b8 [<(ptrval)>] ? start_kernel+0x0/0x78c [<(ptrval)>] parse_early_options+0x40/0x50 [<(ptrval)>] ? do_early_param+0x0/0x118 [<(ptrval)>] parse_early_param+0x48/0x68 [<(ptrval)>] ? start_kernel+0x318/0x78c [<(ptrval)>] ? start_kernel+0x0/0x78c ---[ end trace 0000000000000000 ]--- To fix this we could either implement early_ioremap again or implement fixmap. In this patch we choose the later option of implementing basic fixmap support. While fixing this we also remove the old FIX_IOREMAP slots that were used by early ioremap code. That code was also removed by commit 53c98e3 ("openrisc: mm: remove unneeded early ioremap code") but these definitions were not cleaned up. Fixes: 53c98e3 ("openrisc: mm: remove unneeded early ioremap code") Signed-off-by: Stafford Horne <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 76f9544 commit f93e580

File tree

3 files changed

+45
-16
lines changed

3 files changed

+45
-16
lines changed

arch/openrisc/Kconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ config STACKTRACE_SUPPORT
6565
config LOCKDEP_SUPPORT
6666
def_bool y
6767

68+
config FIX_EARLYCON_MEM
69+
def_bool y
70+
6871
menu "Processor type and features"
6972

7073
choice

arch/openrisc/include/asm/fixmap.h

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,18 @@
2626
#include <linux/bug.h>
2727
#include <asm/page.h>
2828

29-
/*
30-
* On OpenRISC we use these special fixed_addresses for doing ioremap
31-
* early in the boot process before memory initialization is complete.
32-
* This is used, in particular, by the early serial console code.
33-
*
34-
* It's not really 'fixmap', per se, but fits loosely into the same
35-
* paradigm.
36-
*/
3729
enum fixed_addresses {
38-
/*
39-
* FIX_IOREMAP entries are useful for mapping physical address
40-
* space before ioremap() is useable, e.g. really early in boot
41-
* before kmalloc() is working.
42-
*/
43-
#define FIX_N_IOREMAPS 32
44-
FIX_IOREMAP_BEGIN,
45-
FIX_IOREMAP_END = FIX_IOREMAP_BEGIN + FIX_N_IOREMAPS - 1,
30+
FIX_EARLYCON_MEM_BASE,
4631
__end_of_fixed_addresses
4732
};
4833

4934
#define FIXADDR_SIZE (__end_of_fixed_addresses << PAGE_SHIFT)
5035
/* FIXADDR_BOTTOM might be a better name here... */
5136
#define FIXADDR_START (FIXADDR_TOP - FIXADDR_SIZE)
37+
#define FIXMAP_PAGE_IO PAGE_KERNEL_NOCACHE
38+
39+
extern void __set_fixmap(enum fixed_addresses idx,
40+
phys_addr_t phys, pgprot_t flags);
5241

5342
#include <asm-generic/fixmap.h>
5443

arch/openrisc/mm/init.c

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,43 @@ void __init mem_init(void)
207207
return;
208208
}
209209

210+
static int __init map_page(unsigned long va, phys_addr_t pa, pgprot_t prot)
211+
{
212+
p4d_t *p4d;
213+
pud_t *pud;
214+
pmd_t *pmd;
215+
pte_t *pte;
216+
217+
p4d = p4d_offset(pgd_offset_k(va), va);
218+
pud = pud_offset(p4d, va);
219+
pmd = pmd_offset(pud, va);
220+
pte = pte_alloc_kernel(pmd, va);
221+
222+
if (pte == NULL)
223+
return -ENOMEM;
224+
225+
if (pgprot_val(prot))
226+
set_pte_at(&init_mm, va, pte, pfn_pte(pa >> PAGE_SHIFT, prot));
227+
else
228+
pte_clear(&init_mm, va, pte);
229+
230+
local_flush_tlb_page(NULL, va);
231+
return 0;
232+
}
233+
234+
void __init __set_fixmap(enum fixed_addresses idx,
235+
phys_addr_t phys, pgprot_t prot)
236+
{
237+
unsigned long address = __fix_to_virt(idx);
238+
239+
if (idx >= __end_of_fixed_addresses) {
240+
BUG();
241+
return;
242+
}
243+
244+
map_page(address, phys, prot);
245+
}
246+
210247
static const pgprot_t protection_map[16] = {
211248
[VM_NONE] = PAGE_NONE,
212249
[VM_READ] = PAGE_READONLY_X,

0 commit comments

Comments
 (0)