Skip to content

Commit a0ab366

Browse files
committed
sh: fixed PMB mode refactoring.
This introduces some much overdue chainsawing of the fixed PMB support. fixed PMB was introduced initially to work around the fact that dynamic PMB mode was relatively broken, though they were never intended to converge. The main areas where there are differences are whether the system is booted in 29-bit mode or 32-bit mode, and whether legacy mappings are to be preserved. Any system booting in true 32-bit mode will not care about legacy mappings, so these are roughly decoupled. Regardless of the entry point, PMB and 32BIT are directly related as far as the kernel is concerned, so we also switch back to having one select the other. With legacy mappings iterated through and applied in the initialization path it's now possible to finally merge the two implementations and permit dynamic remapping overtop of remaining entries regardless of whether boot mappings are crafted by hand or inherited from the boot loader. Signed-off-by: Paul Mundt <lethal@linux-sh.org>
1 parent 7f33306 commit a0ab366

11 files changed

Lines changed: 117 additions & 97 deletions

File tree

‎arch/sh/boot/Makefile‎

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,8 @@ $(obj)/romImage: $(obj)/romimage/vmlinux FORCE
4646
$(obj)/romimage/vmlinux: $(obj)/zImage FORCE
4747
$(Q)$(MAKE) $(build)=$(obj)/romimage $@
4848

49-
KERNEL_MEMORY := 0x00000000
50-
ifeq ($(CONFIG_PMB_FIXED),y)
51-
KERNEL_MEMORY := $(shell /bin/bash -c 'printf "0x%08x" \
49+
KERNEL_MEMORY := $(shell /bin/bash -c 'printf "0x%08x" \
5250
$$[$(CONFIG_MEMORY_START) & 0x1fffffff]')
53-
endif
54-
ifeq ($(CONFIG_29BIT),y)
55-
KERNEL_MEMORY := $(shell /bin/bash -c 'printf "0x%08x" \
56-
$$[$(CONFIG_MEMORY_START)]')
57-
endif
5851

5952
KERNEL_LOAD := $(shell /bin/bash -c 'printf "0x%08x" \
6053
$$[$(CONFIG_PAGE_OFFSET) + \

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
/* Returns the privileged segment base of a given address */
2929
#define PXSEG(a) (((unsigned long)(a)) & 0xe0000000)
3030

31-
#if defined(CONFIG_29BIT) || defined(CONFIG_PMB_FIXED)
31+
#ifdef CONFIG_29BIT
3232
/*
3333
* Map an address to a certain privileged segment
3434
*/
@@ -40,7 +40,7 @@
4040
((__typeof__(a))(((unsigned long)(a) & 0x1fffffff) | P3SEG))
4141
#define P4SEGADDR(a) \
4242
((__typeof__(a))(((unsigned long)(a) & 0x1fffffff) | P4SEG))
43-
#endif /* 29BIT || PMB_FIXED */
43+
#endif /* 29BIT */
4444
#endif /* P1SEG */
4545

4646
/* Check if an address can be reached in 29 bits */

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

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -244,18 +244,11 @@ __ioremap(unsigned long offset, unsigned long size, unsigned long flags)
244244
}
245245

246246
static inline void __iomem *
247-
__ioremap_mode(unsigned long offset, unsigned long size, unsigned long flags)
247+
__ioremap_29bit(unsigned long offset, unsigned long size, unsigned long flags)
248248
{
249-
#if defined(CONFIG_SUPERH32) && !defined(CONFIG_PMB_FIXED) && !defined(CONFIG_PMB)
249+
#ifdef CONFIG_29BIT
250250
unsigned long last_addr = offset + size - 1;
251-
#endif
252-
void __iomem *ret;
253251

254-
ret = __ioremap_trapped(offset, size);
255-
if (ret)
256-
return ret;
257-
258-
#if defined(CONFIG_SUPERH32) && !defined(CONFIG_PMB_FIXED) && !defined(CONFIG_PMB)
259252
/*
260253
* For P1 and P2 space this is trivial, as everything is already
261254
* mapped. Uncached access for P1 addresses are done through P2.
@@ -274,6 +267,22 @@ __ioremap_mode(unsigned long offset, unsigned long size, unsigned long flags)
274267
return (void __iomem *)P4SEGADDR(offset);
275268
#endif
276269

270+
return NULL;
271+
}
272+
273+
static inline void __iomem *
274+
__ioremap_mode(unsigned long offset, unsigned long size, unsigned long flags)
275+
{
276+
void __iomem *ret;
277+
278+
ret = __ioremap_trapped(offset, size);
279+
if (ret)
280+
return ret;
281+
282+
ret = __ioremap_29bit(offset, size, flags);
283+
if (ret)
284+
return ret;
285+
277286
return __ioremap(offset, size, flags);
278287
}
279288
#else

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,29 @@ struct pmb_entry {
6565
struct pmb_entry *link;
6666
};
6767

68+
#ifdef CONFIG_PMB
6869
/* arch/sh/mm/pmb.c */
6970
long pmb_remap(unsigned long virt, unsigned long phys,
7071
unsigned long size, unsigned long flags);
7172
void pmb_unmap(unsigned long addr);
7273
int pmb_init(void);
74+
#else
75+
static inline long pmb_remap(unsigned long virt, unsigned long phys,
76+
unsigned long size, unsigned long flags)
77+
{
78+
return -EINVAL
79+
}
80+
81+
static inline void pmb_unmap(unsigned long addr)
82+
{
83+
}
84+
85+
static inline int pmb_init(void)
86+
{
87+
return -ENODEV;
88+
}
89+
#endif /* CONFIG_PMB */
90+
7391
#endif /* __ASSEMBLY__ */
7492

7593
#endif /* __MMU_H */

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ typedef struct page *pgtable_t;
127127
* is not visible (it is part of the PMB mapping) and so needs to be
128128
* added or subtracted as required.
129129
*/
130-
#if defined(CONFIG_PMB_FIXED)
130+
#if defined(CONFIG_PMB_LEGACY)
131131
/* phys = virt - PAGE_OFFSET - (__MEMORY_START & 0xe0000000) */
132132
#define PMB_OFFSET (PAGE_OFFSET - PXSEG(__MEMORY_START))
133133
#define __pa(x) ((unsigned long)(x) - PMB_OFFSET)

‎arch/sh/kernel/head_32.S‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include <linux/init.h>
1414
#include <linux/linkage.h>
1515
#include <asm/thread_info.h>
16+
#include <asm/mmu.h>
17+
#include <cpu/mmu_context.h>
1618

1719
#ifdef CONFIG_CPU_SH4A
1820
#define SYNCO() synco
@@ -33,7 +35,7 @@ ENTRY(empty_zero_page)
3335
.long 1 /* LOADER_TYPE */
3436
.long 0x00000000 /* INITRD_START */
3537
.long 0x00000000 /* INITRD_SIZE */
36-
#if defined(CONFIG_32BIT) && defined(CONFIG_PMB_FIXED)
38+
#ifdef CONFIG_32BIT
3739
.long 0x53453f00 + 32 /* "SE?" = 32 bit */
3840
#else
3941
.long 0x53453f00 + 29 /* "SE?" = 29 bit */

‎arch/sh/kernel/setup.c‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -455,10 +455,7 @@ void __init setup_arch(char **cmdline_p)
455455
sh_mv.mv_setup(cmdline_p);
456456

457457
paging_init();
458-
459-
#ifdef CONFIG_PMB_ENABLE
460458
pmb_init();
461-
#endif
462459

463460
#ifdef CONFIG_SMP
464461
plat_smp_setup();

‎arch/sh/kernel/vmlinux.lds.S‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,16 @@ OUTPUT_ARCH(sh)
1414
#include <asm/cache.h>
1515
#include <asm/vmlinux.lds.h>
1616

17+
#if defined(CONFIG_32BIT) && !defined(CONFIG_PMB_LEGACY)
18+
#define MEMORY_OFFSET 0
19+
#else
20+
#define MEMORY_OFFSET (CONFIG_MEMORY_START & 0x1fffffff)
21+
#endif
22+
1723
ENTRY(_start)
1824
SECTIONS
1925
{
20-
#ifdef CONFIG_PMB_FIXED
21-
. = CONFIG_PAGE_OFFSET + (CONFIG_MEMORY_START & 0x1fffffff) +
22-
CONFIG_ZERO_PAGE_OFFSET;
23-
#elif defined(CONFIG_32BIT)
24-
. = CONFIG_PAGE_OFFSET + CONFIG_ZERO_PAGE_OFFSET;
25-
#else
26-
. = CONFIG_PAGE_OFFSET + CONFIG_MEMORY_START + CONFIG_ZERO_PAGE_OFFSET;
27-
#endif
26+
. = CONFIG_PAGE_OFFSET + MEMORY_OFFSET + CONFIG_ZERO_PAGE_OFFSET;
2827

2928
_text = .; /* Text and read-only data */
3029

‎arch/sh/mm/Kconfig‎

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -80,39 +80,25 @@ config 32BIT
8080
bool
8181
default y if CPU_SH5
8282

83-
config PMB_ENABLE
84-
bool "Support 32-bit physical addressing through PMB"
85-
depends on MMU && EXPERIMENTAL && CPU_SH4A && !CPU_SH4AL_DSP
86-
help
87-
If you say Y here, physical addressing will be extended to
88-
32-bits through the SH-4A PMB. If this is not set, legacy
89-
29-bit physical addressing will be used.
90-
91-
choice
92-
prompt "PMB handling type"
93-
depends on PMB_ENABLE
94-
default PMB_FIXED
95-
9683
config PMB
97-
bool "PMB"
84+
bool "Support 32-bit physical addressing through PMB"
9885
depends on MMU && EXPERIMENTAL && CPU_SH4A && !CPU_SH4AL_DSP
86+
select 32BIT
9987
help
10088
If you say Y here, physical addressing will be extended to
10189
32-bits through the SH-4A PMB. If this is not set, legacy
10290
29-bit physical addressing will be used.
10391

104-
config PMB_FIXED
105-
bool "fixed PMB"
106-
depends on MMU && EXPERIMENTAL && CPU_SH4A && !CPU_SH4AL_DSP
92+
config PMB_LEGACY
93+
bool "Support legacy boot mappings for PMB"
94+
depends on PMB
10795
select 32BIT
10896
help
10997
If this option is enabled, fixed PMB mappings are inherited
11098
from the boot loader, and the kernel does not attempt dynamic
11199
management. This is the closest to legacy 29-bit physical mode,
112100
and allows systems to support up to 512MiB of system memory.
113101

114-
endchoice
115-
116102
config X2TLB
117103
bool "Enable extended TLB mode"
118104
depends on (CPU_SHX2 || CPU_SHX3) && MMU && EXPERIMENTAL

‎arch/sh/mm/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ obj-y += $(tlb-y)
3333
endif
3434

3535
obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o
36-
obj-$(CONFIG_PMB_ENABLE) += pmb.o
36+
obj-$(CONFIG_PMB) += pmb.o
3737
obj-$(CONFIG_NUMA) += numa.o
3838

3939
# Special flags for fault_64.o. This puts restrictions on the number of

0 commit comments

Comments
 (0)