Commit d02b08f6e8b184ffef349e395210a5e82ff4f4bc

Authored by Stuart Menefy
Committed by Paul Mundt
1 parent cbaa118ecf

sh: Clean up places that make 29-bit physical assumptions.

Signed-off-by: Stuart Menefy <stuart.menefy@st.com>
Signed-off-by: Paul Mundt <lethal@linux-sh.org>

Showing 10 changed files with 71 additions and 36 deletions Side-by-side Diff

arch/sh/boot/compressed/misc_32.c
... ... @@ -230,7 +230,10 @@
230 230 void decompress_kernel(void)
231 231 {
232 232 output_data = 0;
233   - output_ptr = P2SEGADDR((unsigned long)&_text+PAGE_SIZE);
  233 + output_ptr = PHYSADDR((unsigned long)&_text+PAGE_SIZE);
  234 +#ifdef CONFIG_29BIT
  235 + output_ptr |= P2SEG;
  236 +#endif
234 237 free_mem_ptr = (unsigned long)&_end;
235 238 free_mem_end_ptr = free_mem_ptr + HEAP_SIZE;
236 239  
arch/sh/kernel/setup.c
... ... @@ -82,7 +82,7 @@
82 82 {
83 83 unsigned long size;
84 84  
85   - memory_start = (unsigned long)PAGE_OFFSET+__MEMORY_START;
  85 + memory_start = (unsigned long)__va(__MEMORY_START);
86 86 size = memparse(p, &p);
87 87  
88 88 if (size > __MEMORY_SIZE) {
... ... @@ -254,7 +254,7 @@
254 254 data_resource.start = virt_to_phys(_etext);
255 255 data_resource.end = virt_to_phys(_edata)-1;
256 256  
257   - memory_start = (unsigned long)PAGE_OFFSET+__MEMORY_START;
  257 + memory_start = (unsigned long)__va(__MEMORY_START);
258 258 if (!memory_end)
259 259 memory_end = memory_start + __MEMORY_SIZE;
260 260  
arch/sh/kernel/vmlinux_32.lds.S
... ... @@ -15,7 +15,12 @@
15 15 ENTRY(_start)
16 16 SECTIONS
17 17 {
  18 +#ifdef CONFIG_32BIT
  19 + . = CONFIG_PAGE_OFFSET + CONFIG_ZERO_PAGE_OFFSET;
  20 +#else
18 21 . = CONFIG_PAGE_OFFSET + CONFIG_MEMORY_START + CONFIG_ZERO_PAGE_OFFSET;
  22 +#endif
  23 +
19 24 _text = .; /* Text and read-only data */
20 25  
21 26 .empty_zero_page : {
include/asm-sh/addrspace.h
... ... @@ -31,6 +31,7 @@
31 31 /* Returns the physical address of a PnSEG (n=1,2) address */
32 32 #define PHYSADDR(a) (((unsigned long)(a)) & 0x1fffffff)
33 33  
  34 +#ifdef CONFIG_29BIT
34 35 /*
35 36 * Map an address to a certain privileged segment
36 37 */
37 38  
... ... @@ -42,8 +43,11 @@
42 43 ((__typeof__(a))(((unsigned long)(a) & 0x1fffffff) | P3SEG))
43 44 #define P4SEGADDR(a) \
44 45 ((__typeof__(a))(((unsigned long)(a) & 0x1fffffff) | P4SEG))
45   -
  46 +#endif /* 29BIT */
46 47 #endif /* P1SEG */
  48 +
  49 +/* Check if an address can be reached in 29 bits */
  50 +#define IS_29BIT(a) (((unsigned long)(a)) < 0x20000000)
47 51  
48 52 #endif /* __KERNEL__ */
49 53 #endif /* __ASM_SH_ADDRSPACE_H */
include/asm-sh/cpu-sh4/mmu_context.h
... ... @@ -30,6 +30,12 @@
30 30 #define MMUCR_ME (0)
31 31 #endif
32 32  
  33 +#if defined(CONFIG_32BIT) && defined(CONFIG_CPU_SUBTYPE_ST40)
  34 +#define MMUCR_SE (1 << 4)
  35 +#else
  36 +#define MMUCR_SE (0)
  37 +#endif
  38 +
33 39 #ifdef CONFIG_SH_STORE_QUEUES
34 40 #define MMUCR_SQMD (1 << 9)
35 41 #else
... ... @@ -37,7 +43,7 @@
37 43 #endif
38 44  
39 45 #define MMU_NTLB_ENTRIES 64
40   -#define MMU_CONTROL_INIT (0x05|MMUCR_SQMD|MMUCR_ME)
  46 +#define MMU_CONTROL_INIT (0x05|MMUCR_SQMD|MMUCR_ME|MMUCR_SE)
41 47  
42 48 #define MMU_ITLB_DATA_ARRAY 0xF3000000
43 49 #define MMU_UTLB_DATA_ARRAY 0xF7000000
... ... @@ -273,23 +273,9 @@
273 273 #if !defined(CONFIG_MMU)
274 274 #define virt_to_phys(address) ((unsigned long)(address))
275 275 #define phys_to_virt(address) ((void *)(address))
276   -#elif defined(CONFIG_SUPERH64)
  276 +#else
277 277 #define virt_to_phys(address) (__pa(address))
278 278 #define phys_to_virt(address) (__va(address))
279   -#else
280   -/*
281   - * Change virtual addresses to physical addresses and vv.
282   - * These are trivial on the 1:1 Linux/SuperH mapping
283   - */
284   -static inline unsigned long virt_to_phys(volatile void *address)
285   -{
286   - return PHYSADDR(address);
287   -}
288   -
289   -static inline void *phys_to_virt(unsigned long address)
290   -{
291   - return (void *)P1SEGADDR(address);
292   -}
293 279 #endif
294 280  
295 281 /*
include/asm-sh/page.h
... ... @@ -5,6 +5,8 @@
5 5 * Copyright (C) 1999 Niibe Yutaka
6 6 */
7 7  
  8 +#include <linux/const.h>
  9 +
8 10 #ifdef __KERNEL__
9 11  
10 12 /* PAGE_SHIFT determines the page size */
11 13  
... ... @@ -18,15 +20,13 @@
18 20 # error "Bogus kernel page size?"
19 21 #endif
20 22  
21   -#ifdef __ASSEMBLY__
22   -#define PAGE_SIZE (1 << PAGE_SHIFT)
23   -#else
24   -#define PAGE_SIZE (1UL << PAGE_SHIFT)
25   -#endif
26   -
  23 +#define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
27 24 #define PAGE_MASK (~(PAGE_SIZE-1))
28 25 #define PTE_MASK PAGE_MASK
29 26  
  27 +/* to align the pointer to the (next) page boundary */
  28 +#define PAGE_ALIGN(addr) (((addr)+PAGE_SIZE-1)&PAGE_MASK)
  29 +
30 30 #if defined(CONFIG_HUGETLB_PAGE_SIZE_64K)
31 31 #define HPAGE_SHIFT 16
32 32 #elif defined(CONFIG_HUGETLB_PAGE_SIZE_256K)
33 33  
34 34  
35 35  
36 36  
... ... @@ -104,20 +104,44 @@
104 104  
105 105 #endif /* !__ASSEMBLY__ */
106 106  
107   -/* to align the pointer to the (next) page boundary */
108   -#define PAGE_ALIGN(addr) (((addr)+PAGE_SIZE-1)&PAGE_MASK)
109   -
  107 +/*
  108 + * __MEMORY_START and SIZE are the physical addresses and size of RAM.
  109 + */
110 110 #define __MEMORY_START CONFIG_MEMORY_START
111 111 #define __MEMORY_SIZE CONFIG_MEMORY_SIZE
112 112  
  113 +/*
  114 + * PAGE_OFFSET is the virtual address of the start of kernel address
  115 + * space.
  116 + */
113 117 #define PAGE_OFFSET CONFIG_PAGE_OFFSET
114   -#define __pa(x) ((unsigned long)(x)-PAGE_OFFSET)
115   -#define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
116   -#define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
117 118  
  119 +/*
  120 + * Virtual to physical RAM address translation.
  121 + *
  122 + * In 29 bit mode, the physical offset of RAM from address 0 is visible in
  123 + * the kernel virtual address space, and thus we don't have to take
  124 + * this into account when translating. However in 32 bit mode this offset
  125 + * is not visible (it is part of the PMB mapping) and so needs to be
  126 + * added or subtracted as required.
  127 + */
  128 +#ifdef CONFIG_32BIT
  129 +#define __pa(x) ((unsigned long)(x)-PAGE_OFFSET+__MEMORY_START)
  130 +#define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET-__MEMORY_START))
  131 +#else
  132 +#define __pa(x) ((unsigned long)(x)-PAGE_OFFSET)
  133 +#define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
  134 +#endif
  135 +
  136 +#define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
118 137 #define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT)
119 138  
120   -/* PFN start number, because of __MEMORY_START */
  139 +/*
  140 + * PFN = physical frame number (ie PFN 0 == physical address 0)
  141 + * PFN_START is the PFN of the first page of RAM. By defining this we
  142 + * don't have struct page entries for the portion of address space
  143 + * between physical address 0 and the start of RAM.
  144 + */
121 145 #define PFN_START (__MEMORY_START >> PAGE_SHIFT)
122 146 #define ARCH_PFN_OFFSET (PFN_START)
123 147 #define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
include/asm-sh/pgtable.h
... ... @@ -69,7 +69,13 @@
69 69 #define USER_PTRS_PER_PGD (TASK_SIZE/PGDIR_SIZE)
70 70 #define FIRST_USER_ADDRESS 0
71 71  
72   -#define PTE_PHYS_MASK (0x20000000 - PAGE_SIZE)
  72 +#ifdef CONFIG_32BIT
  73 +#define PHYS_ADDR_MASK 0xffffffff
  74 +#else
  75 +#define PHYS_ADDR_MASK 0x1fffffff
  76 +#endif
  77 +
  78 +#define PTE_PHYS_MASK (PHYS_ADDR_MASK & PAGE_MASK)
73 79  
74 80 #ifdef CONFIG_SUPERH32
75 81 #define VMALLOC_START (P3SEG)
include/asm-sh/pgtable_32.h
... ... @@ -98,7 +98,7 @@
98 98 #define _PAGE_CLEAR_FLAGS (_PAGE_PROTNONE | _PAGE_ACCESSED | _PAGE_FILE)
99 99 #endif
100 100  
101   -#define _PAGE_FLAGS_HARDWARE_MASK (0x1fffffff & ~(_PAGE_CLEAR_FLAGS))
  101 +#define _PAGE_FLAGS_HARDWARE_MASK (PHYS_ADDR_MASK & ~(_PAGE_CLEAR_FLAGS))
102 102  
103 103 /* Hardware flags, page size encoding */
104 104 #if defined(CONFIG_X2TLB)
include/asm-sh/scatterlist.h
1 1 #ifndef __ASM_SH_SCATTERLIST_H
2 2 #define __ASM_SH_SCATTERLIST_H
3 3  
  4 +#include <asm/pgtable.h>
4 5 #include <asm/types.h>
5 6  
6 7 struct scatterlist {
... ... @@ -13,7 +14,7 @@
13 14 unsigned int length;
14 15 };
15 16  
16   -#define ISA_DMA_THRESHOLD (0x1fffffff)
  17 +#define ISA_DMA_THRESHOLD PHYS_ADDR_MASK
17 18  
18 19 /* These macros should be used after a pci_map_sg call has been done
19 20 * to get bus addresses of each of the SG entries and their lengths.