Skip to content

Commit d01447b

Browse files
committed
sh: Merge legacy and dynamic PMB modes.
This implements a bit of rework for the PMB code, which permits us to kill off the legacy PMB mode completely. Rather than trusting the boot loader to do the right thing, we do a quick verification of the PMB contents to determine whether to have the kernel setup the initial mappings or whether it needs to mangle them later on instead. If we're booting from legacy mappings, the kernel will now take control of them and make them match the kernel's initial mapping configuration. This is accomplished by breaking the initialization phase out in to multiple steps: synchronization, merging, and resizing. With the recent rework, the synchronization code establishes page links for compound mappings already, so we build on top of this for promoting mappings and reclaiming unused slots. At the same time, the changes introduced for the uncached helpers also permit us to dynamically resize the uncached mapping without any particular headaches. The smallest page size is more than sufficient for mapping all of kernel text, and as we're careful not to jump to any far off locations in the setup code the mapping can safely be resized regardless of whether we are executing from it or not. Signed-off-by: Paul Mundt <lethal@linux-sh.org>
1 parent 2e45064 commit d01447b

10 files changed

Lines changed: 276 additions & 71 deletions

File tree

‎arch/sh/boot/compressed/misc.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ void decompress_kernel(void)
117117
output_addr = (CONFIG_MEMORY_START + 0x2000);
118118
#else
119119
output_addr = __pa((unsigned long)&_text+PAGE_SIZE);
120-
#if defined(CONFIG_29BIT) || defined(CONFIG_PMB_LEGACY)
120+
#if defined(CONFIG_29BIT)
121121
output_addr |= P2SEG;
122122
#endif
123123
#endif

‎arch/sh/include/asm/mmu.h‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ typedef struct {
5858
long pmb_remap(unsigned long virt, unsigned long phys,
5959
unsigned long size, pgprot_t prot);
6060
void pmb_unmap(unsigned long addr);
61-
int pmb_init(void);
61+
void pmb_init(void);
6262
bool __in_29bit_mode(void);
6363
#else
6464
static inline long pmb_remap(unsigned long virt, unsigned long phys,
@@ -67,14 +67,8 @@ static inline long pmb_remap(unsigned long virt, unsigned long phys,
6767
return -EINVAL;
6868
}
6969

70-
static inline void pmb_unmap(unsigned long addr)
71-
{
72-
}
73-
74-
static inline int pmb_init(void)
75-
{
76-
return -ENODEV;
77-
}
70+
#define pmb_unmap(addr) do { } while (0)
71+
#define pmb_init(addr) do { } while (0)
7872

7973
#ifdef CONFIG_29BIT
8074
#define __in_29bit_mode() (1)

‎arch/sh/include/asm/page.h‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,12 @@
4545
#endif
4646

4747
#ifndef __ASSEMBLY__
48+
#include <asm/uncached.h>
4849

4950
extern unsigned long shm_align_mask;
5051
extern unsigned long max_low_pfn, min_low_pfn;
5152
extern unsigned long memory_start, memory_end;
5253

53-
#ifdef CONFIG_UNCACHED_MAPPING
54-
extern unsigned long uncached_start, uncached_end;
55-
56-
extern int virt_addr_uncached(unsigned long kaddr);
57-
extern void uncached_init(void);
58-
#else
59-
#define virt_addr_uncached(kaddr) (0)
60-
#define uncached_init() do { } while (0)
61-
#endif
62-
6354
static inline unsigned long
6455
pages_do_alias(unsigned long addr1, unsigned long addr2)
6556
{

‎arch/sh/include/asm/uncached.h‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef __ASM_SH_UNCACHED_H
2+
#define __ASM_SH_UNCACHED_H
3+
4+
#include <linux/bug.h>
5+
6+
#ifdef CONFIG_UNCACHED_MAPPING
7+
extern unsigned long uncached_start, uncached_end;
8+
9+
extern int virt_addr_uncached(unsigned long kaddr);
10+
extern void uncached_init(void);
11+
extern void uncached_resize(unsigned long size);
12+
#else
13+
#define virt_addr_uncached(kaddr) (0)
14+
#define uncached_init() do { } while (0)
15+
#define uncached_resize(size) BUG()
16+
#endif
17+
18+
#endif /* __ASM_SH_UNCACHED_H */

‎arch/sh/kernel/head_32.S‎

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ ENTRY(_stext)
8585
ldc r0, r7_bank ! ... and initial thread_info
8686
#endif
8787

88-
#if defined(CONFIG_PMB) && !defined(CONFIG_PMB_LEGACY)
88+
#ifdef CONFIG_PMB
8989
/*
9090
* Reconfigure the initial PMB mappings setup by the hardware.
9191
*
@@ -139,7 +139,6 @@ ENTRY(_stext)
139139
mov.l r0, @r1
140140

141141
mov.l .LMEMORY_SIZE, r5
142-
mov r5, r7
143142

144143
mov #PMB_E_SHIFT, r0
145144
mov #0x1, r4
@@ -150,6 +149,40 @@ ENTRY(_stext)
150149
mov.l .LFIRST_ADDR_ENTRY, r2
151150
mov.l .LPMB_ADDR, r3
152151

152+
/*
153+
* First we need to walk the PMB and figure out if there are any
154+
* existing mappings that match the initial mappings VPN/PPN.
155+
* If these have already been established by the bootloader, we
156+
* don't bother setting up new entries here, and let the late PMB
157+
* initialization take care of things instead.
158+
*
159+
* Note that we may need to coalesce and merge entries in order
160+
* to reclaim more available PMB slots, which is much more than
161+
* we want to do at this early stage.
162+
*/
163+
mov #0, r10
164+
mov #NR_PMB_ENTRIES, r9
165+
166+
mov r1, r7 /* temporary PMB_DATA iter */
167+
168+
.Lvalidate_existing_mappings:
169+
170+
mov.l @r7, r8
171+
and r0, r8
172+
cmp/eq r0, r8 /* Check for valid __MEMORY_START mappings */
173+
bt .Lpmb_done
174+
175+
add #1, r10 /* Increment the loop counter */
176+
cmp/eq r9, r10
177+
bf/s .Lvalidate_existing_mappings
178+
add r4, r7 /* Increment to the next PMB_DATA entry */
179+
180+
/*
181+
* If we've fallen through, continue with setting up the initial
182+
* mappings.
183+
*/
184+
185+
mov r5, r7 /* cached_to_uncached */
153186
mov #0, r10
154187

155188
#ifdef CONFIG_UNCACHED_MAPPING
@@ -252,7 +285,8 @@ ENTRY(_stext)
252285
mov.l 6f, r0
253286
icbi @r0
254287

255-
#endif /* !CONFIG_PMB_LEGACY */
288+
.Lpmb_done:
289+
#endif /* CONFIG_PMB */
256290

257291
#ifndef CONFIG_SH_NO_BSS_INIT
258292
/*
@@ -304,7 +338,7 @@ ENTRY(stack_start)
304338
6: .long sh_cpu_init
305339
7: .long init_thread_union
306340

307-
#if defined(CONFIG_PMB) && !defined(CONFIG_PMB_LEGACY)
341+
#ifdef CONFIG_PMB
308342
.LPMB_ADDR: .long PMB_ADDR
309343
.LPMB_DATA: .long PMB_DATA
310344
.LFIRST_ADDR_ENTRY: .long PAGE_OFFSET | PMB_V

‎arch/sh/kernel/setup.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,8 @@ void __init setup_arch(char **cmdline_p)
421421

422422
parse_early_param();
423423

424+
uncached_init();
425+
424426
plat_early_device_setup();
425427

426428
/* Let earlyprintk output early console messages */

‎arch/sh/mm/Kconfig‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,6 @@ config PMB
9191
32-bits through the SH-4A PMB. If this is not set, legacy
9292
29-bit physical addressing will be used.
9393

94-
config PMB_LEGACY
95-
bool "Support legacy boot mappings for PMB"
96-
depends on PMB
97-
select 32BIT
98-
help
99-
If this option is enabled, fixed PMB mappings are inherited
100-
from the boot loader, and the kernel does not attempt dynamic
101-
management. This is the closest to legacy 29-bit physical mode,
102-
and allows systems to support up to 512MiB of system memory.
103-
10494
config X2TLB
10595
def_bool y
10696
depends on (CPU_SHX2 || CPU_SHX3) && MMU

‎arch/sh/mm/init.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,6 @@ void __init mem_init(void)
245245
memset(empty_zero_page, 0, PAGE_SIZE);
246246
__flush_wback_region(empty_zero_page, PAGE_SIZE);
247247

248-
uncached_init();
249248
vsyscall_init();
250249

251250
codesize = (unsigned long) &_etext - (unsigned long) &_text;

0 commit comments

Comments
 (0)