blob: 8e76ebba29863ecd18dd2b9ba29147072f3c4518 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * srmmu.c: SRMMU specific routines for memory management.
3 *
4 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
5 * Copyright (C) 1995,2002 Pete Zaitcev (zaitcev@yahoo.com)
6 * Copyright (C) 1996 Eddie C. Dost (ecd@skynet.be)
7 * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
8 * Copyright (C) 1999,2000 Anton Blanchard (anton@samba.org)
9 */
10
Sam Ravnborg4a049b02012-07-26 11:02:12 +000011#include <linux/seq_file.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/spinlock.h>
13#include <linux/bootmem.h>
Sam Ravnborg4a049b02012-07-26 11:02:12 +000014#include <linux/pagemap.h>
15#include <linux/vmalloc.h>
Christoph Hellwig1eeb66a2007-05-08 00:27:03 -070016#include <linux/kdebug.h>
Paul Gortmakera56b0722014-02-13 16:15:01 -050017#include <linux/export.h>
Sam Ravnborg4a049b02012-07-26 11:02:12 +000018#include <linux/kernel.h>
19#include <linux/init.h>
Robert P. J. Day949e8272009-04-24 03:58:24 +000020#include <linux/log2.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090021#include <linux/gfp.h>
Sam Ravnborg4a049b02012-07-26 11:02:12 +000022#include <linux/fs.h>
23#include <linux/mm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <asm/mmu_context.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <asm/cacheflush.h>
27#include <asm/tlbflush.h>
Sam Ravnborg4a049b02012-07-26 11:02:12 +000028#include <asm/io-unit.h>
29#include <asm/pgalloc.h>
30#include <asm/pgtable.h>
31#include <asm/bitext.h>
32#include <asm/vaddrs.h>
33#include <asm/cache.h>
34#include <asm/traps.h>
35#include <asm/oplib.h>
36#include <asm/mbus.h>
37#include <asm/page.h>
38#include <asm/asi.h>
39#include <asm/msi.h>
40#include <asm/smp.h>
41#include <asm/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
43/* Now the cpu specific definitions. */
Sam Ravnborg4a049b02012-07-26 11:02:12 +000044#include <asm/turbosparc.h>
45#include <asm/tsunami.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include <asm/viking.h>
Sam Ravnborg4a049b02012-07-26 11:02:12 +000047#include <asm/swift.h>
48#include <asm/leon.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <asm/mxcc.h>
50#include <asm/ross.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Sam Ravnborgddb74172014-04-21 21:39:16 +020052#include "mm_32.h"
Sam Ravnborgaccf0322012-05-19 20:02:49 +000053
Linus Torvalds1da177e2005-04-16 15:20:36 -070054enum mbus_module srmmu_modtype;
Adrian Bunk50215d62008-06-05 11:41:51 -070055static unsigned int hwbug_bitmask;
Linus Torvalds1da177e2005-04-16 15:20:36 -070056int vac_cache_size;
Guenter Roeck9d262d92017-04-01 13:47:44 -070057EXPORT_SYMBOL(vac_cache_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058int vac_line_size;
59
60extern struct resource sparc_iomap;
61
62extern unsigned long last_valid_pfn;
63
Adrian Bunk50215d62008-06-05 11:41:51 -070064static pgd_t *srmmu_swapper_pg_dir;
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
David S. Miller5d83d662012-05-13 20:49:31 -070066const struct sparc32_cachetlb_ops *sparc32_cachetlb_ops;
Paul Gortmakera56b0722014-02-13 16:15:01 -050067EXPORT_SYMBOL(sparc32_cachetlb_ops);
David S. Miller5d83d662012-05-13 20:49:31 -070068
Linus Torvalds1da177e2005-04-16 15:20:36 -070069#ifdef CONFIG_SMP
David S. Miller5d83d662012-05-13 20:49:31 -070070const struct sparc32_cachetlb_ops *local_ops;
71
Linus Torvalds1da177e2005-04-16 15:20:36 -070072#define FLUSH_BEGIN(mm)
73#define FLUSH_END
74#else
David S. Miller5d83d662012-05-13 20:49:31 -070075#define FLUSH_BEGIN(mm) if ((mm)->context != NO_CONTEXT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070076#define FLUSH_END }
77#endif
78
Linus Torvalds1da177e2005-04-16 15:20:36 -070079int flush_page_for_dma_global = 1;
80
Linus Torvalds1da177e2005-04-16 15:20:36 -070081char *srmmu_name;
82
83ctxd_t *srmmu_ctx_table_phys;
Adrian Bunk50215d62008-06-05 11:41:51 -070084static ctxd_t *srmmu_context_table;
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
86int viking_mxcc_present;
87static DEFINE_SPINLOCK(srmmu_context_spinlock);
88
Adrian Bunk50215d62008-06-05 11:41:51 -070089static int is_hypersparc;
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
Adrian Bunk50215d62008-06-05 11:41:51 -070091static int srmmu_cache_pagetables;
Linus Torvalds1da177e2005-04-16 15:20:36 -070092
93/* these will be initialized in srmmu_nocache_calcsize() */
Adrian Bunk50215d62008-06-05 11:41:51 -070094static unsigned long srmmu_nocache_size;
95static unsigned long srmmu_nocache_end;
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
97/* 1 bit <=> 256 bytes of nocache <=> 64 PTEs */
98#define SRMMU_NOCACHE_BITMAP_SHIFT (PAGE_SHIFT - 4)
99
100/* The context table is a nocache user with the biggest alignment needs. */
101#define SRMMU_NOCACHE_ALIGN_MAX (sizeof(ctxd_t)*SRMMU_MAX_CONTEXTS)
102
103void *srmmu_nocache_pool;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104static struct bit_map srmmu_nocache_map;
105
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106static inline int srmmu_pmd_none(pmd_t pmd)
107{ return !(pmd_val(pmd) & 0xFFFFFFF); }
108
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109/* XXX should we hyper_flush_whole_icache here - Anton */
110static inline void srmmu_ctxd_set(ctxd_t *ctxp, pgd_t *pgdp)
Sam Ravnborg6e6e4182016-04-22 19:41:06 +0200111{
112 pte_t pte;
113
114 pte = __pte((SRMMU_ET_PTD | (__nocache_pa(pgdp) >> 4)));
115 set_pte((pte_t *)ctxp, pte);
116}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
Sam Ravnborg642ea3e2012-05-13 08:40:27 +0200118void pmd_set(pmd_t *pmdp, pte_t *ptep)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119{
120 unsigned long ptp; /* Physical address, shifted right by 4 */
121 int i;
122
Sam Ravnborg6b1cabe2016-04-22 19:41:07 +0200123 ptp = __nocache_pa(ptep) >> 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 for (i = 0; i < PTRS_PER_PTE/SRMMU_REAL_PTRS_PER_PTE; i++) {
Sam Ravnborg6e6e4182016-04-22 19:41:06 +0200125 set_pte((pte_t *)&pmdp->pmdv[i], __pte(SRMMU_ET_PTD | ptp));
126 ptp += (SRMMU_REAL_PTRS_PER_PTE * sizeof(pte_t) >> 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 }
128}
129
Sam Ravnborg642ea3e2012-05-13 08:40:27 +0200130void pmd_populate(struct mm_struct *mm, pmd_t *pmdp, struct page *ptep)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131{
132 unsigned long ptp; /* Physical address, shifted right by 4 */
133 int i;
134
135 ptp = page_to_pfn(ptep) << (PAGE_SHIFT-4); /* watch for overflow */
136 for (i = 0; i < PTRS_PER_PTE/SRMMU_REAL_PTRS_PER_PTE; i++) {
Sam Ravnborg6e6e4182016-04-22 19:41:06 +0200137 set_pte((pte_t *)&pmdp->pmdv[i], __pte(SRMMU_ET_PTD | ptp));
138 ptp += (SRMMU_REAL_PTRS_PER_PTE * sizeof(pte_t) >> 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 }
140}
141
Sam Ravnborg605ae962012-07-26 11:02:13 +0000142/* Find an entry in the third-level page table.. */
143pte_t *pte_offset_kernel(pmd_t *dir, unsigned long address)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144{
145 void *pte;
146
147 pte = __nocache_va((dir->pmdv[0] & SRMMU_PTD_PMASK) << 4);
148 return (pte_t *) pte +
149 ((address >> PAGE_SHIFT) & (PTRS_PER_PTE - 1));
150}
151
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152/*
153 * size: bytes to allocate in the nocache area.
154 * align: bytes, number to align at.
155 * Returns the virtual address of the allocated area.
156 */
Sam Ravnborgf71a2aa2012-07-26 11:02:14 +0000157static void *__srmmu_get_nocache(int size, int align)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158{
159 int offset;
Sam Ravnborgf71a2aa2012-07-26 11:02:14 +0000160 unsigned long addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
162 if (size < SRMMU_NOCACHE_BITMAP_SHIFT) {
Sam Ravnborgf71a2aa2012-07-26 11:02:14 +0000163 printk(KERN_ERR "Size 0x%x too small for nocache request\n",
164 size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 size = SRMMU_NOCACHE_BITMAP_SHIFT;
166 }
Sam Ravnborgf71a2aa2012-07-26 11:02:14 +0000167 if (size & (SRMMU_NOCACHE_BITMAP_SHIFT - 1)) {
168 printk(KERN_ERR "Size 0x%x unaligned int nocache request\n",
169 size);
170 size += SRMMU_NOCACHE_BITMAP_SHIFT - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 }
172 BUG_ON(align > SRMMU_NOCACHE_ALIGN_MAX);
173
174 offset = bit_map_string_get(&srmmu_nocache_map,
Sam Ravnborgf71a2aa2012-07-26 11:02:14 +0000175 size >> SRMMU_NOCACHE_BITMAP_SHIFT,
176 align >> SRMMU_NOCACHE_BITMAP_SHIFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 if (offset == -1) {
Sam Ravnborgf71a2aa2012-07-26 11:02:14 +0000178 printk(KERN_ERR "srmmu: out of nocache %d: %d/%d\n",
179 size, (int) srmmu_nocache_size,
180 srmmu_nocache_map.used << SRMMU_NOCACHE_BITMAP_SHIFT);
Sam Ravnborge8c29c82014-04-21 21:39:19 +0200181 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 }
183
Sam Ravnborgf71a2aa2012-07-26 11:02:14 +0000184 addr = SRMMU_NOCACHE_VADDR + (offset << SRMMU_NOCACHE_BITMAP_SHIFT);
185 return (void *)addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186}
187
Sam Ravnborgf71a2aa2012-07-26 11:02:14 +0000188void *srmmu_get_nocache(int size, int align)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189{
Sam Ravnborgf71a2aa2012-07-26 11:02:14 +0000190 void *tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
192 tmp = __srmmu_get_nocache(size, align);
193
194 if (tmp)
Sam Ravnborgf71a2aa2012-07-26 11:02:14 +0000195 memset(tmp, 0, size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
197 return tmp;
198}
199
Sam Ravnborgf71a2aa2012-07-26 11:02:14 +0000200void srmmu_free_nocache(void *addr, int size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201{
Sam Ravnborgf71a2aa2012-07-26 11:02:14 +0000202 unsigned long vaddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 int offset;
204
Sam Ravnborgf71a2aa2012-07-26 11:02:14 +0000205 vaddr = (unsigned long)addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 if (vaddr < SRMMU_NOCACHE_VADDR) {
207 printk("Vaddr %lx is smaller than nocache base 0x%lx\n",
208 vaddr, (unsigned long)SRMMU_NOCACHE_VADDR);
209 BUG();
210 }
Sam Ravnborg605ae962012-07-26 11:02:13 +0000211 if (vaddr + size > srmmu_nocache_end) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 printk("Vaddr %lx is bigger than nocache end 0x%lx\n",
213 vaddr, srmmu_nocache_end);
214 BUG();
215 }
Robert P. J. Day949e8272009-04-24 03:58:24 +0000216 if (!is_power_of_2(size)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 printk("Size 0x%x is not a power of 2\n", size);
218 BUG();
219 }
220 if (size < SRMMU_NOCACHE_BITMAP_SHIFT) {
221 printk("Size 0x%x is too small\n", size);
222 BUG();
223 }
Sam Ravnborg605ae962012-07-26 11:02:13 +0000224 if (vaddr & (size - 1)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 printk("Vaddr %lx is not aligned to size 0x%x\n", vaddr, size);
226 BUG();
227 }
228
229 offset = (vaddr - SRMMU_NOCACHE_VADDR) >> SRMMU_NOCACHE_BITMAP_SHIFT;
230 size = size >> SRMMU_NOCACHE_BITMAP_SHIFT;
231
232 bit_map_clear(&srmmu_nocache_map, offset, size);
233}
234
Adrian Bunk50215d62008-06-05 11:41:51 -0700235static void srmmu_early_allocate_ptable_skeleton(unsigned long start,
236 unsigned long end);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237
Sam Ravnborgd8a1b2b2012-07-26 11:02:26 +0000238/* Return how much physical memory we have. */
239static unsigned long __init probe_memory(void)
240{
241 unsigned long total = 0;
242 int i;
243
244 for (i = 0; sp_banks[i].num_bytes; i++)
245 total += sp_banks[i].num_bytes;
246
247 return total;
248}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249
250/*
251 * Reserve nocache dynamically proportionally to the amount of
252 * system RAM. -- Tomas Szepe <szepe@pinerecords.com>, June 2002
253 */
Sam Ravnborg32442462012-07-26 11:02:11 +0000254static void __init srmmu_nocache_calcsize(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255{
256 unsigned long sysmemavail = probe_memory() / 1024;
257 int srmmu_nocache_npages;
258
259 srmmu_nocache_npages =
260 sysmemavail / SRMMU_NOCACHE_ALCRATIO / 1024 * 256;
261
262 /* P3 XXX The 4x overuse: corroborated by /proc/meminfo. */
263 // if (srmmu_nocache_npages < 256) srmmu_nocache_npages = 256;
264 if (srmmu_nocache_npages < SRMMU_MIN_NOCACHE_PAGES)
265 srmmu_nocache_npages = SRMMU_MIN_NOCACHE_PAGES;
266
267 /* anything above 1280 blows up */
268 if (srmmu_nocache_npages > SRMMU_MAX_NOCACHE_PAGES)
269 srmmu_nocache_npages = SRMMU_MAX_NOCACHE_PAGES;
270
271 srmmu_nocache_size = srmmu_nocache_npages * PAGE_SIZE;
272 srmmu_nocache_end = SRMMU_NOCACHE_VADDR + srmmu_nocache_size;
273}
274
Adrian Bunk50215d62008-06-05 11:41:51 -0700275static void __init srmmu_nocache_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276{
Sam Ravnborge8c29c82014-04-21 21:39:19 +0200277 void *srmmu_nocache_bitmap;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 unsigned int bitmap_bits;
279 pgd_t *pgd;
280 pmd_t *pmd;
281 pte_t *pte;
282 unsigned long paddr, vaddr;
283 unsigned long pteval;
284
285 bitmap_bits = srmmu_nocache_size >> SRMMU_NOCACHE_BITMAP_SHIFT;
286
287 srmmu_nocache_pool = __alloc_bootmem(srmmu_nocache_size,
288 SRMMU_NOCACHE_ALIGN_MAX, 0UL);
289 memset(srmmu_nocache_pool, 0, srmmu_nocache_size);
290
Akinobu Mita54df2db2013-03-29 03:44:43 +0000291 srmmu_nocache_bitmap =
292 __alloc_bootmem(BITS_TO_LONGS(bitmap_bits) * sizeof(long),
293 SMP_CACHE_BYTES, 0UL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 bit_map_init(&srmmu_nocache_map, srmmu_nocache_bitmap, bitmap_bits);
295
Sam Ravnborgf71a2aa2012-07-26 11:02:14 +0000296 srmmu_swapper_pg_dir = __srmmu_get_nocache(SRMMU_PGD_TABLE_SIZE, SRMMU_PGD_TABLE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 memset(__nocache_fix(srmmu_swapper_pg_dir), 0, SRMMU_PGD_TABLE_SIZE);
298 init_mm.pgd = srmmu_swapper_pg_dir;
299
300 srmmu_early_allocate_ptable_skeleton(SRMMU_NOCACHE_VADDR, srmmu_nocache_end);
301
302 paddr = __pa((unsigned long)srmmu_nocache_pool);
303 vaddr = SRMMU_NOCACHE_VADDR;
304
305 while (vaddr < srmmu_nocache_end) {
306 pgd = pgd_offset_k(vaddr);
Sam Ravnborg9701b262012-05-13 10:21:25 +0200307 pmd = pmd_offset(__nocache_fix(pgd), vaddr);
308 pte = pte_offset_kernel(__nocache_fix(pmd), vaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309
310 pteval = ((paddr >> 4) | SRMMU_ET_PTE | SRMMU_PRIV);
311
312 if (srmmu_cache_pagetables)
313 pteval |= SRMMU_CACHE;
314
David S. Miller62875cf2012-05-12 13:39:23 -0700315 set_pte(__nocache_fix(pte), __pte(pteval));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316
317 vaddr += PAGE_SIZE;
318 paddr += PAGE_SIZE;
319 }
320
321 flush_cache_all();
322 flush_tlb_all();
323}
324
Sam Ravnborg642ea3e2012-05-13 08:40:27 +0200325pgd_t *get_pgd_fast(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326{
327 pgd_t *pgd = NULL;
328
Sam Ravnborgf71a2aa2012-07-26 11:02:14 +0000329 pgd = __srmmu_get_nocache(SRMMU_PGD_TABLE_SIZE, SRMMU_PGD_TABLE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 if (pgd) {
331 pgd_t *init = pgd_offset_k(0);
332 memset(pgd, 0, USER_PTRS_PER_PGD * sizeof(pgd_t));
333 memcpy(pgd + USER_PTRS_PER_PGD, init + USER_PTRS_PER_PGD,
334 (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t));
335 }
336
337 return pgd;
338}
339
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340/*
341 * Hardware needs alignment to 256 only, but we align to whole page size
342 * to reduce fragmentation problems due to the buddy principle.
343 * XXX Provide actual fragmentation statistics in /proc.
344 *
345 * Alignments up to the page size are the same for physical and virtual
346 * addresses of the nocache area.
347 */
Sam Ravnborg642ea3e2012-05-13 08:40:27 +0200348pgtable_t pte_alloc_one(struct mm_struct *mm, unsigned long address)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349{
350 unsigned long pte;
Martin Schwidefsky2f569af2008-02-08 04:22:04 -0800351 struct page *page;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352
Sam Ravnborg642ea3e2012-05-13 08:40:27 +0200353 if ((pte = (unsigned long)pte_alloc_one_kernel(mm, address)) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 return NULL;
Sam Ravnborg605ae962012-07-26 11:02:13 +0000355 page = pfn_to_page(__nocache_pa(pte) >> PAGE_SHIFT);
Kirill A. Shutemov1ae9ae52013-11-14 14:31:42 -0800356 if (!pgtable_page_ctor(page)) {
357 __free_page(page);
358 return NULL;
359 }
Martin Schwidefsky2f569af2008-02-08 04:22:04 -0800360 return page;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361}
362
Sam Ravnborg642ea3e2012-05-13 08:40:27 +0200363void pte_free(struct mm_struct *mm, pgtable_t pte)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364{
365 unsigned long p;
366
Martin Schwidefsky2f569af2008-02-08 04:22:04 -0800367 pgtable_page_dtor(pte);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 p = (unsigned long)page_address(pte); /* Cached address (for test) */
369 if (p == 0)
370 BUG();
371 p = page_to_pfn(pte) << PAGE_SHIFT; /* Physical address */
Sam Ravnborgf71a2aa2012-07-26 11:02:14 +0000372
373 /* free non cached virtual address*/
374 srmmu_free_nocache(__nocache_va(p), PTE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375}
376
Sam Ravnborgb585e852012-07-26 11:02:24 +0000377/* context handling - a dynamically sized pool is used */
378#define NO_CONTEXT -1
379
380struct ctx_list {
381 struct ctx_list *next;
382 struct ctx_list *prev;
383 unsigned int ctx_number;
384 struct mm_struct *ctx_mm;
385};
386
387static struct ctx_list *ctx_list_pool;
388static struct ctx_list ctx_free;
389static struct ctx_list ctx_used;
390
391/* At boot time we determine the number of contexts */
392static int num_contexts;
393
394static inline void remove_from_ctx_list(struct ctx_list *entry)
395{
396 entry->next->prev = entry->prev;
397 entry->prev->next = entry->next;
398}
399
400static inline void add_to_ctx_list(struct ctx_list *head, struct ctx_list *entry)
401{
402 entry->next = head;
403 (entry->prev = head->prev)->next = entry;
404 head->prev = entry;
405}
406#define add_to_free_ctxlist(entry) add_to_ctx_list(&ctx_free, entry)
407#define add_to_used_ctxlist(entry) add_to_ctx_list(&ctx_used, entry)
408
409
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410static inline void alloc_context(struct mm_struct *old_mm, struct mm_struct *mm)
411{
412 struct ctx_list *ctxp;
413
414 ctxp = ctx_free.next;
Sam Ravnborg605ae962012-07-26 11:02:13 +0000415 if (ctxp != &ctx_free) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 remove_from_ctx_list(ctxp);
417 add_to_used_ctxlist(ctxp);
418 mm->context = ctxp->ctx_number;
419 ctxp->ctx_mm = mm;
420 return;
421 }
422 ctxp = ctx_used.next;
Sam Ravnborg605ae962012-07-26 11:02:13 +0000423 if (ctxp->ctx_mm == old_mm)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 ctxp = ctxp->next;
Sam Ravnborg605ae962012-07-26 11:02:13 +0000425 if (ctxp == &ctx_used)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 panic("out of mmu contexts");
427 flush_cache_mm(ctxp->ctx_mm);
428 flush_tlb_mm(ctxp->ctx_mm);
429 remove_from_ctx_list(ctxp);
430 add_to_used_ctxlist(ctxp);
431 ctxp->ctx_mm->context = NO_CONTEXT;
432 ctxp->ctx_mm = mm;
433 mm->context = ctxp->ctx_number;
434}
435
436static inline void free_context(int context)
437{
438 struct ctx_list *ctx_old;
439
440 ctx_old = ctx_list_pool + context;
441 remove_from_ctx_list(ctx_old);
442 add_to_free_ctxlist(ctx_old);
443}
444
Sam Ravnborgb585e852012-07-26 11:02:24 +0000445static void __init sparc_context_init(int numctx)
446{
447 int ctx;
448 unsigned long size;
449
450 size = numctx * sizeof(struct ctx_list);
451 ctx_list_pool = __alloc_bootmem(size, SMP_CACHE_BYTES, 0UL);
452
453 for (ctx = 0; ctx < numctx; ctx++) {
454 struct ctx_list *clist;
455
456 clist = (ctx_list_pool + ctx);
457 clist->ctx_number = ctx;
458 clist->ctx_mm = NULL;
459 }
460 ctx_free.next = ctx_free.prev = &ctx_free;
461 ctx_used.next = ctx_used.prev = &ctx_used;
462 for (ctx = 0; ctx < numctx; ctx++)
463 add_to_free_ctxlist(ctx_list_pool + ctx);
464}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465
Sam Ravnborg34d4acc2012-05-12 08:04:11 +0000466void switch_mm(struct mm_struct *old_mm, struct mm_struct *mm,
467 struct task_struct *tsk)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468{
Andreas Larsson66d0f7e2014-12-18 13:23:23 +0100469 unsigned long flags;
470
Sam Ravnborg605ae962012-07-26 11:02:13 +0000471 if (mm->context == NO_CONTEXT) {
Andreas Larsson66d0f7e2014-12-18 13:23:23 +0100472 spin_lock_irqsave(&srmmu_context_spinlock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 alloc_context(old_mm, mm);
Andreas Larsson66d0f7e2014-12-18 13:23:23 +0100474 spin_unlock_irqrestore(&srmmu_context_spinlock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 srmmu_ctxd_set(&srmmu_context_table[mm->context], mm->pgd);
476 }
477
Konrad Eisele75d9e342009-08-17 00:13:33 +0000478 if (sparc_cpu_model == sparc_leon)
479 leon_switch_mm();
480
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 if (is_hypersparc)
482 hyper_flush_whole_icache();
483
484 srmmu_set_context(mm->context);
485}
486
487/* Low level IO area allocation on the SRMMU. */
488static inline void srmmu_mapioaddr(unsigned long physaddr,
Sam Ravnborg605ae962012-07-26 11:02:13 +0000489 unsigned long virt_addr, int bus_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490{
491 pgd_t *pgdp;
492 pmd_t *pmdp;
493 pte_t *ptep;
494 unsigned long tmp;
495
496 physaddr &= PAGE_MASK;
497 pgdp = pgd_offset_k(virt_addr);
Sam Ravnborg9701b262012-05-13 10:21:25 +0200498 pmdp = pmd_offset(pgdp, virt_addr);
499 ptep = pte_offset_kernel(pmdp, virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 tmp = (physaddr >> 4) | SRMMU_ET_PTE;
501
Sam Ravnborg605ae962012-07-26 11:02:13 +0000502 /* I need to test whether this is consistent over all
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 * sun4m's. The bus_type represents the upper 4 bits of
504 * 36-bit physical address on the I/O space lines...
505 */
506 tmp |= (bus_type << 28);
507 tmp |= SRMMU_PRIV;
508 __flush_page_to_ram(virt_addr);
David S. Miller62875cf2012-05-12 13:39:23 -0700509 set_pte(ptep, __pte(tmp));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510}
511
Sam Ravnborg9701b262012-05-13 10:21:25 +0200512void srmmu_mapiorange(unsigned int bus, unsigned long xpa,
513 unsigned long xva, unsigned int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514{
515 while (len != 0) {
516 len -= PAGE_SIZE;
517 srmmu_mapioaddr(xpa, xva, bus);
518 xva += PAGE_SIZE;
519 xpa += PAGE_SIZE;
520 }
521 flush_tlb_all();
522}
523
524static inline void srmmu_unmapioaddr(unsigned long virt_addr)
525{
526 pgd_t *pgdp;
527 pmd_t *pmdp;
528 pte_t *ptep;
529
530 pgdp = pgd_offset_k(virt_addr);
Sam Ravnborg9701b262012-05-13 10:21:25 +0200531 pmdp = pmd_offset(pgdp, virt_addr);
532 ptep = pte_offset_kernel(pmdp, virt_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533
534 /* No need to flush uncacheable page. */
David S. Millera46d6052012-05-12 12:26:47 -0700535 __pte_clear(ptep);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536}
537
Sam Ravnborg9701b262012-05-13 10:21:25 +0200538void srmmu_unmapiorange(unsigned long virt_addr, unsigned int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539{
540 while (len != 0) {
541 len -= PAGE_SIZE;
542 srmmu_unmapioaddr(virt_addr);
543 virt_addr += PAGE_SIZE;
544 }
545 flush_tlb_all();
546}
547
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548/* tsunami.S */
549extern void tsunami_flush_cache_all(void);
550extern void tsunami_flush_cache_mm(struct mm_struct *mm);
551extern void tsunami_flush_cache_range(struct vm_area_struct *vma, unsigned long start, unsigned long end);
552extern void tsunami_flush_cache_page(struct vm_area_struct *vma, unsigned long page);
553extern void tsunami_flush_page_to_ram(unsigned long page);
554extern void tsunami_flush_page_for_dma(unsigned long page);
555extern void tsunami_flush_sig_insns(struct mm_struct *mm, unsigned long insn_addr);
556extern void tsunami_flush_tlb_all(void);
557extern void tsunami_flush_tlb_mm(struct mm_struct *mm);
558extern void tsunami_flush_tlb_range(struct vm_area_struct *vma, unsigned long start, unsigned long end);
559extern void tsunami_flush_tlb_page(struct vm_area_struct *vma, unsigned long page);
560extern void tsunami_setup_blockops(void);
561
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562/* swift.S */
563extern void swift_flush_cache_all(void);
564extern void swift_flush_cache_mm(struct mm_struct *mm);
565extern void swift_flush_cache_range(struct vm_area_struct *vma,
566 unsigned long start, unsigned long end);
567extern void swift_flush_cache_page(struct vm_area_struct *vma, unsigned long page);
568extern void swift_flush_page_to_ram(unsigned long page);
569extern void swift_flush_page_for_dma(unsigned long page);
570extern void swift_flush_sig_insns(struct mm_struct *mm, unsigned long insn_addr);
571extern void swift_flush_tlb_all(void);
572extern void swift_flush_tlb_mm(struct mm_struct *mm);
573extern void swift_flush_tlb_range(struct vm_area_struct *vma,
574 unsigned long start, unsigned long end);
575extern void swift_flush_tlb_page(struct vm_area_struct *vma, unsigned long page);
576
577#if 0 /* P3: deadwood to debug precise flushes on Swift. */
578void swift_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
579{
580 int cctx, ctx1;
581
582 page &= PAGE_MASK;
583 if ((ctx1 = vma->vm_mm->context) != -1) {
584 cctx = srmmu_get_context();
585/* Is context # ever different from current context? P3 */
586 if (cctx != ctx1) {
587 printk("flush ctx %02x curr %02x\n", ctx1, cctx);
588 srmmu_set_context(ctx1);
589 swift_flush_page(page);
590 __asm__ __volatile__("sta %%g0, [%0] %1\n\t" : :
591 "r" (page), "i" (ASI_M_FLUSH_PROBE));
592 srmmu_set_context(cctx);
593 } else {
594 /* Rm. prot. bits from virt. c. */
595 /* swift_flush_cache_all(); */
596 /* swift_flush_cache_page(vma, page); */
597 swift_flush_page(page);
598
599 __asm__ __volatile__("sta %%g0, [%0] %1\n\t" : :
600 "r" (page), "i" (ASI_M_FLUSH_PROBE));
601 /* same as above: srmmu_flush_tlb_page() */
602 }
603 }
604}
605#endif
606
607/*
608 * The following are all MBUS based SRMMU modules, and therefore could
609 * be found in a multiprocessor configuration. On the whole, these
610 * chips seems to be much more touchy about DVMA and page tables
611 * with respect to cache coherency.
612 */
613
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614/* viking.S */
615extern void viking_flush_cache_all(void);
616extern void viking_flush_cache_mm(struct mm_struct *mm);
617extern void viking_flush_cache_range(struct vm_area_struct *vma, unsigned long start,
618 unsigned long end);
619extern void viking_flush_cache_page(struct vm_area_struct *vma, unsigned long page);
620extern void viking_flush_page_to_ram(unsigned long page);
621extern void viking_flush_page_for_dma(unsigned long page);
622extern void viking_flush_sig_insns(struct mm_struct *mm, unsigned long addr);
623extern void viking_flush_page(unsigned long page);
624extern void viking_mxcc_flush_page(unsigned long page);
625extern void viking_flush_tlb_all(void);
626extern void viking_flush_tlb_mm(struct mm_struct *mm);
627extern void viking_flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
628 unsigned long end);
629extern void viking_flush_tlb_page(struct vm_area_struct *vma,
630 unsigned long page);
631extern void sun4dsmp_flush_tlb_all(void);
632extern void sun4dsmp_flush_tlb_mm(struct mm_struct *mm);
633extern void sun4dsmp_flush_tlb_range(struct vm_area_struct *vma, unsigned long start,
634 unsigned long end);
635extern void sun4dsmp_flush_tlb_page(struct vm_area_struct *vma,
636 unsigned long page);
637
638/* hypersparc.S */
639extern void hypersparc_flush_cache_all(void);
640extern void hypersparc_flush_cache_mm(struct mm_struct *mm);
641extern void hypersparc_flush_cache_range(struct vm_area_struct *vma, unsigned long start, unsigned long end);
642extern void hypersparc_flush_cache_page(struct vm_area_struct *vma, unsigned long page);
643extern void hypersparc_flush_page_to_ram(unsigned long page);
644extern void hypersparc_flush_page_for_dma(unsigned long page);
645extern void hypersparc_flush_sig_insns(struct mm_struct *mm, unsigned long insn_addr);
646extern void hypersparc_flush_tlb_all(void);
647extern void hypersparc_flush_tlb_mm(struct mm_struct *mm);
648extern void hypersparc_flush_tlb_range(struct vm_area_struct *vma, unsigned long start, unsigned long end);
649extern void hypersparc_flush_tlb_page(struct vm_area_struct *vma, unsigned long page);
650extern void hypersparc_setup_blockops(void);
651
652/*
653 * NOTE: All of this startup code assumes the low 16mb (approx.) of
654 * kernel mappings are done with one single contiguous chunk of
655 * ram. On small ram machines (classics mainly) we only get
656 * around 8mb mapped for us.
657 */
658
Adrian Bunk50215d62008-06-05 11:41:51 -0700659static void __init early_pgtable_allocfail(char *type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660{
661 prom_printf("inherit_prom_mappings: Cannot alloc kernel %s.\n", type);
662 prom_halt();
663}
664
Adrian Bunk50215d62008-06-05 11:41:51 -0700665static void __init srmmu_early_allocate_ptable_skeleton(unsigned long start,
666 unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667{
668 pgd_t *pgdp;
669 pmd_t *pmdp;
670 pte_t *ptep;
671
Sam Ravnborg605ae962012-07-26 11:02:13 +0000672 while (start < end) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 pgdp = pgd_offset_k(start);
David S. Miller7d9fa4a2012-05-12 13:13:16 -0700674 if (pgd_none(*(pgd_t *)__nocache_fix(pgdp))) {
Sam Ravnborgf71a2aa2012-07-26 11:02:14 +0000675 pmdp = __srmmu_get_nocache(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 SRMMU_PMD_TABLE_SIZE, SRMMU_PMD_TABLE_SIZE);
677 if (pmdp == NULL)
678 early_pgtable_allocfail("pmd");
679 memset(__nocache_fix(pmdp), 0, SRMMU_PMD_TABLE_SIZE);
Sam Ravnborg642ea3e2012-05-13 08:40:27 +0200680 pgd_set(__nocache_fix(pgdp), pmdp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 }
Sam Ravnborg9701b262012-05-13 10:21:25 +0200682 pmdp = pmd_offset(__nocache_fix(pgdp), start);
Sam Ravnborg605ae962012-07-26 11:02:13 +0000683 if (srmmu_pmd_none(*(pmd_t *)__nocache_fix(pmdp))) {
Sam Ravnborgf71a2aa2012-07-26 11:02:14 +0000684 ptep = __srmmu_get_nocache(PTE_SIZE, PTE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 if (ptep == NULL)
686 early_pgtable_allocfail("pte");
687 memset(__nocache_fix(ptep), 0, PTE_SIZE);
Sam Ravnborg642ea3e2012-05-13 08:40:27 +0200688 pmd_set(__nocache_fix(pmdp), ptep);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 }
690 if (start > (0xffffffffUL - PMD_SIZE))
691 break;
692 start = (start + PMD_SIZE) & PMD_MASK;
693 }
694}
695
Adrian Bunk50215d62008-06-05 11:41:51 -0700696static void __init srmmu_allocate_ptable_skeleton(unsigned long start,
697 unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698{
699 pgd_t *pgdp;
700 pmd_t *pmdp;
701 pte_t *ptep;
702
Sam Ravnborg605ae962012-07-26 11:02:13 +0000703 while (start < end) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 pgdp = pgd_offset_k(start);
David S. Miller7d9fa4a2012-05-12 13:13:16 -0700705 if (pgd_none(*pgdp)) {
Sam Ravnborgf71a2aa2012-07-26 11:02:14 +0000706 pmdp = __srmmu_get_nocache(SRMMU_PMD_TABLE_SIZE, SRMMU_PMD_TABLE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 if (pmdp == NULL)
708 early_pgtable_allocfail("pmd");
709 memset(pmdp, 0, SRMMU_PMD_TABLE_SIZE);
Sam Ravnborg642ea3e2012-05-13 08:40:27 +0200710 pgd_set(pgdp, pmdp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 }
Sam Ravnborg9701b262012-05-13 10:21:25 +0200712 pmdp = pmd_offset(pgdp, start);
Sam Ravnborg605ae962012-07-26 11:02:13 +0000713 if (srmmu_pmd_none(*pmdp)) {
Sam Ravnborgf71a2aa2012-07-26 11:02:14 +0000714 ptep = __srmmu_get_nocache(PTE_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 PTE_SIZE);
716 if (ptep == NULL)
717 early_pgtable_allocfail("pte");
718 memset(ptep, 0, PTE_SIZE);
Sam Ravnborg642ea3e2012-05-13 08:40:27 +0200719 pmd_set(pmdp, ptep);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 }
721 if (start > (0xffffffffUL - PMD_SIZE))
722 break;
723 start = (start + PMD_SIZE) & PMD_MASK;
724 }
725}
726
Sam Ravnborg805918f2012-05-25 21:20:19 +0000727/* These flush types are not available on all chips... */
728static inline unsigned long srmmu_probe(unsigned long vaddr)
729{
730 unsigned long retval;
731
732 if (sparc_cpu_model != sparc_leon) {
733
734 vaddr &= PAGE_MASK;
735 __asm__ __volatile__("lda [%1] %2, %0\n\t" :
736 "=r" (retval) :
737 "r" (vaddr | 0x400), "i" (ASI_M_FLUSH_PROBE));
738 } else {
Sam Ravnborge8c29c82014-04-21 21:39:19 +0200739 retval = leon_swprobe(vaddr, NULL);
Sam Ravnborg805918f2012-05-25 21:20:19 +0000740 }
741 return retval;
742}
743
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744/*
745 * This is much cleaner than poking around physical address space
746 * looking at the prom's page table directly which is what most
747 * other OS's do. Yuck... this is much better.
748 */
Adrian Bunk50215d62008-06-05 11:41:51 -0700749static void __init srmmu_inherit_prom_mappings(unsigned long start,
750 unsigned long end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751{
Sam Ravnborg7cdfbc72012-07-26 11:02:15 +0000752 unsigned long probed;
753 unsigned long addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 pgd_t *pgdp;
755 pmd_t *pmdp;
756 pte_t *ptep;
Sam Ravnborg7cdfbc72012-07-26 11:02:15 +0000757 int what; /* 0 = normal-pte, 1 = pmd-level pte, 2 = pgd-level pte */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758
Sam Ravnborg605ae962012-07-26 11:02:13 +0000759 while (start <= end) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 if (start == 0)
761 break; /* probably wrap around */
Sam Ravnborg605ae962012-07-26 11:02:13 +0000762 if (start == 0xfef00000)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 start = KADB_DEBUGGER_BEGVM;
Sam Ravnborg7cdfbc72012-07-26 11:02:15 +0000764 probed = srmmu_probe(start);
765 if (!probed) {
766 /* continue probing until we find an entry */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 start += PAGE_SIZE;
768 continue;
769 }
Sam Ravnborg605ae962012-07-26 11:02:13 +0000770
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 /* A red snapper, see what it really is. */
772 what = 0;
Sam Ravnborg7cdfbc72012-07-26 11:02:15 +0000773 addr = start - PAGE_SIZE;
Sam Ravnborg605ae962012-07-26 11:02:13 +0000774
775 if (!(start & ~(SRMMU_REAL_PMD_MASK))) {
Sam Ravnborg7cdfbc72012-07-26 11:02:15 +0000776 if (srmmu_probe(addr + SRMMU_REAL_PMD_SIZE) == probed)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777 what = 1;
778 }
Sam Ravnborg605ae962012-07-26 11:02:13 +0000779
780 if (!(start & ~(SRMMU_PGDIR_MASK))) {
Sam Ravnborg7cdfbc72012-07-26 11:02:15 +0000781 if (srmmu_probe(addr + SRMMU_PGDIR_SIZE) == probed)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 what = 2;
783 }
Sam Ravnborg605ae962012-07-26 11:02:13 +0000784
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 pgdp = pgd_offset_k(start);
Sam Ravnborg605ae962012-07-26 11:02:13 +0000786 if (what == 2) {
Sam Ravnborg7cdfbc72012-07-26 11:02:15 +0000787 *(pgd_t *)__nocache_fix(pgdp) = __pgd(probed);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 start += SRMMU_PGDIR_SIZE;
789 continue;
790 }
David S. Miller7d9fa4a2012-05-12 13:13:16 -0700791 if (pgd_none(*(pgd_t *)__nocache_fix(pgdp))) {
Sam Ravnborg7cdfbc72012-07-26 11:02:15 +0000792 pmdp = __srmmu_get_nocache(SRMMU_PMD_TABLE_SIZE,
793 SRMMU_PMD_TABLE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 if (pmdp == NULL)
795 early_pgtable_allocfail("pmd");
796 memset(__nocache_fix(pmdp), 0, SRMMU_PMD_TABLE_SIZE);
Sam Ravnborg642ea3e2012-05-13 08:40:27 +0200797 pgd_set(__nocache_fix(pgdp), pmdp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 }
Sam Ravnborg9701b262012-05-13 10:21:25 +0200799 pmdp = pmd_offset(__nocache_fix(pgdp), start);
Sam Ravnborg605ae962012-07-26 11:02:13 +0000800 if (srmmu_pmd_none(*(pmd_t *)__nocache_fix(pmdp))) {
Sam Ravnborgf71a2aa2012-07-26 11:02:14 +0000801 ptep = __srmmu_get_nocache(PTE_SIZE, PTE_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 if (ptep == NULL)
803 early_pgtable_allocfail("pte");
804 memset(__nocache_fix(ptep), 0, PTE_SIZE);
Sam Ravnborg642ea3e2012-05-13 08:40:27 +0200805 pmd_set(__nocache_fix(pmdp), ptep);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 }
Sam Ravnborg605ae962012-07-26 11:02:13 +0000807 if (what == 1) {
808 /* We bend the rule where all 16 PTPs in a pmd_t point
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809 * inside the same PTE page, and we leak a perfectly
810 * good hardware PTE piece. Alternatives seem worse.
811 */
812 unsigned int x; /* Index of HW PMD in soft cluster */
Sam Ravnborg7cdfbc72012-07-26 11:02:15 +0000813 unsigned long *val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 x = (start >> PMD_SHIFT) & 15;
Sam Ravnborg7cdfbc72012-07-26 11:02:15 +0000815 val = &pmdp->pmdv[x];
816 *(unsigned long *)__nocache_fix(val) = probed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 start += SRMMU_REAL_PMD_SIZE;
818 continue;
819 }
Sam Ravnborg9701b262012-05-13 10:21:25 +0200820 ptep = pte_offset_kernel(__nocache_fix(pmdp), start);
Sam Ravnborg7cdfbc72012-07-26 11:02:15 +0000821 *(pte_t *)__nocache_fix(ptep) = __pte(probed);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 start += PAGE_SIZE;
823 }
824}
825
826#define KERNEL_PTE(page_shifted) ((page_shifted)|SRMMU_CACHE|SRMMU_PRIV|SRMMU_VALID)
827
828/* Create a third-level SRMMU 16MB page mapping. */
829static void __init do_large_mapping(unsigned long vaddr, unsigned long phys_base)
830{
831 pgd_t *pgdp = pgd_offset_k(vaddr);
832 unsigned long big_pte;
833
834 big_pte = KERNEL_PTE(phys_base >> 4);
835 *(pgd_t *)__nocache_fix(pgdp) = __pgd(big_pte);
836}
837
838/* Map sp_bank entry SP_ENTRY, starting at virtual address VBASE. */
839static unsigned long __init map_spbank(unsigned long vbase, int sp_entry)
840{
841 unsigned long pstart = (sp_banks[sp_entry].base_addr & SRMMU_PGDIR_MASK);
842 unsigned long vstart = (vbase & SRMMU_PGDIR_MASK);
843 unsigned long vend = SRMMU_PGDIR_ALIGN(vbase + sp_banks[sp_entry].num_bytes);
844 /* Map "low" memory only */
845 const unsigned long min_vaddr = PAGE_OFFSET;
846 const unsigned long max_vaddr = PAGE_OFFSET + SRMMU_MAXMEM;
847
848 if (vstart < min_vaddr || vstart >= max_vaddr)
849 return vstart;
Sam Ravnborg605ae962012-07-26 11:02:13 +0000850
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 if (vend > max_vaddr || vend < min_vaddr)
852 vend = max_vaddr;
853
Sam Ravnborg605ae962012-07-26 11:02:13 +0000854 while (vstart < vend) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 do_large_mapping(vstart, pstart);
856 vstart += SRMMU_PGDIR_SIZE; pstart += SRMMU_PGDIR_SIZE;
857 }
858 return vstart;
859}
860
Sam Ravnborg32442462012-07-26 11:02:11 +0000861static void __init map_kernel(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862{
863 int i;
864
865 if (phys_base > 0) {
866 do_large_mapping(PAGE_OFFSET, phys_base);
867 }
868
869 for (i = 0; sp_banks[i].num_bytes != 0; i++) {
870 map_spbank((unsigned long)__va(sp_banks[i].base_addr), i);
871 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872}
873
Paul Gortmaker2066aad2013-06-17 15:43:14 -0400874void (*poke_srmmu)(void) = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876void __init srmmu_paging_init(void)
877{
Andres Salomon8d125562010-10-08 14:18:11 -0700878 int i;
879 phandle cpunode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880 char node_str[128];
881 pgd_t *pgd;
882 pmd_t *pmd;
883 pte_t *pte;
884 unsigned long pages_avail;
885
Sam Ravnborgb585e852012-07-26 11:02:24 +0000886 init_mm.context = (unsigned long) NO_CONTEXT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 sparc_iomap.start = SUN4M_IOBASE_VADDR; /* 16MB of IOSPACE on all sun4m's. */
888
889 if (sparc_cpu_model == sun4d)
890 num_contexts = 65536; /* We know it is Viking */
891 else {
892 /* Find the number of contexts on the srmmu. */
893 cpunode = prom_getchild(prom_root_node);
894 num_contexts = 0;
Sam Ravnborg605ae962012-07-26 11:02:13 +0000895 while (cpunode != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 prom_getstring(cpunode, "device_type", node_str, sizeof(node_str));
Sam Ravnborg605ae962012-07-26 11:02:13 +0000897 if (!strcmp(node_str, "cpu")) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 num_contexts = prom_getintdefault(cpunode, "mmu-nctx", 0x8);
899 break;
900 }
901 cpunode = prom_getsibling(cpunode);
902 }
903 }
904
Sam Ravnborg605ae962012-07-26 11:02:13 +0000905 if (!num_contexts) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906 prom_printf("Something wrong, can't find cpu node in paging_init.\n");
907 prom_halt();
908 }
909
910 pages_avail = 0;
911 last_valid_pfn = bootmem_init(&pages_avail);
912
913 srmmu_nocache_calcsize();
914 srmmu_nocache_init();
Sam Ravnborgf71a2aa2012-07-26 11:02:14 +0000915 srmmu_inherit_prom_mappings(0xfe400000, (LINUX_OPPROM_ENDVM - PAGE_SIZE));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 map_kernel();
917
918 /* ctx table has to be physically aligned to its size */
Sam Ravnborgf71a2aa2012-07-26 11:02:14 +0000919 srmmu_context_table = __srmmu_get_nocache(num_contexts * sizeof(ctxd_t), num_contexts * sizeof(ctxd_t));
Sam Ravnborg6b1cabe2016-04-22 19:41:07 +0200920 srmmu_ctx_table_phys = (ctxd_t *)__nocache_pa(srmmu_context_table);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921
Sam Ravnborg605ae962012-07-26 11:02:13 +0000922 for (i = 0; i < num_contexts; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 srmmu_ctxd_set((ctxd_t *)__nocache_fix(&srmmu_context_table[i]), srmmu_swapper_pg_dir);
924
925 flush_cache_all();
926 srmmu_set_ctable_ptr((unsigned long)srmmu_ctx_table_phys);
Bob Breuera54123e2006-03-23 22:36:19 -0800927#ifdef CONFIG_SMP
928 /* Stop from hanging here... */
David S. Miller5d83d662012-05-13 20:49:31 -0700929 local_ops->tlb_all();
Bob Breuera54123e2006-03-23 22:36:19 -0800930#else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 flush_tlb_all();
Bob Breuera54123e2006-03-23 22:36:19 -0800932#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 poke_srmmu();
934
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 srmmu_allocate_ptable_skeleton(sparc_iomap.start, IOBASE_END);
936 srmmu_allocate_ptable_skeleton(DVMA_VADDR, DVMA_END);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937
938 srmmu_allocate_ptable_skeleton(
939 __fix_to_virt(__end_of_fixed_addresses - 1), FIXADDR_TOP);
940 srmmu_allocate_ptable_skeleton(PKMAP_BASE, PKMAP_END);
941
942 pgd = pgd_offset_k(PKMAP_BASE);
Sam Ravnborg9701b262012-05-13 10:21:25 +0200943 pmd = pmd_offset(pgd, PKMAP_BASE);
944 pte = pte_offset_kernel(pmd, PKMAP_BASE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 pkmap_page_table = pte;
946
947 flush_cache_all();
948 flush_tlb_all();
949
950 sparc_context_init(num_contexts);
951
952 kmap_init();
953
954 {
955 unsigned long zones_size[MAX_NR_ZONES];
956 unsigned long zholes_size[MAX_NR_ZONES];
957 unsigned long npages;
958 int znum;
959
960 for (znum = 0; znum < MAX_NR_ZONES; znum++)
961 zones_size[znum] = zholes_size[znum] = 0;
962
963 npages = max_low_pfn - pfn_base;
964
965 zones_size[ZONE_DMA] = npages;
966 zholes_size[ZONE_DMA] = npages - pages_avail;
967
968 npages = highend_pfn - max_low_pfn;
969 zones_size[ZONE_HIGHMEM] = npages;
970 zholes_size[ZONE_HIGHMEM] = npages - calc_highpages();
971
Johannes Weiner9109fb72008-07-23 21:27:20 -0700972 free_area_init_node(0, zones_size, pfn_base, zholes_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973 }
974}
975
Sam Ravnborg9701b262012-05-13 10:21:25 +0200976void mmu_info(struct seq_file *m)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977{
Sam Ravnborg605ae962012-07-26 11:02:13 +0000978 seq_printf(m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 "MMU type\t: %s\n"
980 "contexts\t: %d\n"
981 "nocache total\t: %ld\n"
982 "nocache used\t: %d\n",
983 srmmu_name,
984 num_contexts,
985 srmmu_nocache_size,
986 srmmu_nocache_map.used << SRMMU_NOCACHE_BITMAP_SHIFT);
987}
988
Sam Ravnborgb585e852012-07-26 11:02:24 +0000989int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
990{
991 mm->context = NO_CONTEXT;
992 return 0;
993}
994
Sam Ravnborgb796c6d2012-05-13 10:30:54 +0200995void destroy_context(struct mm_struct *mm)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996{
Andreas Larsson66d0f7e2014-12-18 13:23:23 +0100997 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998
Sam Ravnborg605ae962012-07-26 11:02:13 +0000999 if (mm->context != NO_CONTEXT) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 flush_cache_mm(mm);
1001 srmmu_ctxd_set(&srmmu_context_table[mm->context], srmmu_swapper_pg_dir);
1002 flush_tlb_mm(mm);
Andreas Larsson66d0f7e2014-12-18 13:23:23 +01001003 spin_lock_irqsave(&srmmu_context_spinlock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 free_context(mm->context);
Andreas Larsson66d0f7e2014-12-18 13:23:23 +01001005 spin_unlock_irqrestore(&srmmu_context_spinlock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 mm->context = NO_CONTEXT;
1007 }
1008}
1009
1010/* Init various srmmu chip types. */
1011static void __init srmmu_is_bad(void)
1012{
1013 prom_printf("Could not determine SRMMU chip type.\n");
1014 prom_halt();
1015}
1016
1017static void __init init_vac_layout(void)
1018{
Andres Salomon8d125562010-10-08 14:18:11 -07001019 phandle nd;
1020 int cache_lines;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 char node_str[128];
1022#ifdef CONFIG_SMP
1023 int cpu = 0;
1024 unsigned long max_size = 0;
1025 unsigned long min_line_size = 0x10000000;
1026#endif
1027
1028 nd = prom_getchild(prom_root_node);
Sam Ravnborg605ae962012-07-26 11:02:13 +00001029 while ((nd = prom_getsibling(nd)) != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 prom_getstring(nd, "device_type", node_str, sizeof(node_str));
Sam Ravnborg605ae962012-07-26 11:02:13 +00001031 if (!strcmp(node_str, "cpu")) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 vac_line_size = prom_getint(nd, "cache-line-size");
1033 if (vac_line_size == -1) {
Sam Ravnborg605ae962012-07-26 11:02:13 +00001034 prom_printf("can't determine cache-line-size, halting.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 prom_halt();
1036 }
1037 cache_lines = prom_getint(nd, "cache-nlines");
1038 if (cache_lines == -1) {
1039 prom_printf("can't determine cache-nlines, halting.\n");
1040 prom_halt();
1041 }
1042
1043 vac_cache_size = cache_lines * vac_line_size;
1044#ifdef CONFIG_SMP
Sam Ravnborg605ae962012-07-26 11:02:13 +00001045 if (vac_cache_size > max_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 max_size = vac_cache_size;
Sam Ravnborg605ae962012-07-26 11:02:13 +00001047 if (vac_line_size < min_line_size)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 min_line_size = vac_line_size;
Bob Breuera54123e2006-03-23 22:36:19 -08001049 //FIXME: cpus not contiguous!!
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 cpu++;
Rusty Russellec7c14b2009-03-16 14:40:24 +10301051 if (cpu >= nr_cpu_ids || !cpu_online(cpu))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 break;
1053#else
1054 break;
1055#endif
1056 }
1057 }
Sam Ravnborg605ae962012-07-26 11:02:13 +00001058 if (nd == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 prom_printf("No CPU nodes found, halting.\n");
1060 prom_halt();
1061 }
1062#ifdef CONFIG_SMP
1063 vac_cache_size = max_size;
1064 vac_line_size = min_line_size;
1065#endif
1066 printk("SRMMU: Using VAC size of %d bytes, line size %d bytes.\n",
1067 (int)vac_cache_size, (int)vac_line_size);
1068}
1069
Paul Gortmaker2066aad2013-06-17 15:43:14 -04001070static void poke_hypersparc(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071{
1072 volatile unsigned long clear;
1073 unsigned long mreg = srmmu_get_mmureg();
1074
1075 hyper_flush_unconditional_combined();
1076
1077 mreg &= ~(HYPERSPARC_CWENABLE);
1078 mreg |= (HYPERSPARC_CENABLE | HYPERSPARC_WBENABLE);
1079 mreg |= (HYPERSPARC_CMODE);
1080
1081 srmmu_set_mmureg(mreg);
1082
1083#if 0 /* XXX I think this is bad news... -DaveM */
1084 hyper_clear_all_tags();
1085#endif
1086
1087 put_ross_icr(HYPERSPARC_ICCR_FTD | HYPERSPARC_ICCR_ICE);
1088 hyper_flush_whole_icache();
1089 clear = srmmu_get_faddr();
1090 clear = srmmu_get_fstatus();
1091}
1092
David S. Miller5d83d662012-05-13 20:49:31 -07001093static const struct sparc32_cachetlb_ops hypersparc_ops = {
1094 .cache_all = hypersparc_flush_cache_all,
1095 .cache_mm = hypersparc_flush_cache_mm,
1096 .cache_page = hypersparc_flush_cache_page,
1097 .cache_range = hypersparc_flush_cache_range,
1098 .tlb_all = hypersparc_flush_tlb_all,
1099 .tlb_mm = hypersparc_flush_tlb_mm,
1100 .tlb_page = hypersparc_flush_tlb_page,
1101 .tlb_range = hypersparc_flush_tlb_range,
1102 .page_to_ram = hypersparc_flush_page_to_ram,
1103 .sig_insns = hypersparc_flush_sig_insns,
1104 .page_for_dma = hypersparc_flush_page_for_dma,
1105};
1106
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107static void __init init_hypersparc(void)
1108{
1109 srmmu_name = "ROSS HyperSparc";
1110 srmmu_modtype = HyperSparc;
1111
1112 init_vac_layout();
1113
1114 is_hypersparc = 1;
David S. Miller5d83d662012-05-13 20:49:31 -07001115 sparc32_cachetlb_ops = &hypersparc_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116
1117 poke_srmmu = poke_hypersparc;
1118
1119 hypersparc_setup_blockops();
1120}
1121
Paul Gortmaker2066aad2013-06-17 15:43:14 -04001122static void poke_swift(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123{
1124 unsigned long mreg;
1125
1126 /* Clear any crap from the cache or else... */
1127 swift_flush_cache_all();
1128
1129 /* Enable I & D caches */
1130 mreg = srmmu_get_mmureg();
1131 mreg |= (SWIFT_IE | SWIFT_DE);
1132 /*
1133 * The Swift branch folding logic is completely broken. At
1134 * trap time, if things are just right, if can mistakenly
1135 * think that a trap is coming from kernel mode when in fact
1136 * it is coming from user mode (it mis-executes the branch in
1137 * the trap code). So you see things like crashme completely
1138 * hosing your machine which is completely unacceptable. Turn
1139 * this shit off... nice job Fujitsu.
1140 */
1141 mreg &= ~(SWIFT_BF);
1142 srmmu_set_mmureg(mreg);
1143}
1144
David S. Miller5d83d662012-05-13 20:49:31 -07001145static const struct sparc32_cachetlb_ops swift_ops = {
1146 .cache_all = swift_flush_cache_all,
1147 .cache_mm = swift_flush_cache_mm,
1148 .cache_page = swift_flush_cache_page,
1149 .cache_range = swift_flush_cache_range,
1150 .tlb_all = swift_flush_tlb_all,
1151 .tlb_mm = swift_flush_tlb_mm,
1152 .tlb_page = swift_flush_tlb_page,
1153 .tlb_range = swift_flush_tlb_range,
1154 .page_to_ram = swift_flush_page_to_ram,
1155 .sig_insns = swift_flush_sig_insns,
1156 .page_for_dma = swift_flush_page_for_dma,
1157};
1158
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159#define SWIFT_MASKID_ADDR 0x10003018
1160static void __init init_swift(void)
1161{
1162 unsigned long swift_rev;
1163
1164 __asm__ __volatile__("lda [%1] %2, %0\n\t"
1165 "srl %0, 0x18, %0\n\t" :
1166 "=r" (swift_rev) :
1167 "r" (SWIFT_MASKID_ADDR), "i" (ASI_M_BYPASS));
1168 srmmu_name = "Fujitsu Swift";
Sam Ravnborg605ae962012-07-26 11:02:13 +00001169 switch (swift_rev) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170 case 0x11:
1171 case 0x20:
1172 case 0x23:
1173 case 0x30:
1174 srmmu_modtype = Swift_lots_o_bugs;
1175 hwbug_bitmask |= (HWBUG_KERN_ACCBROKEN | HWBUG_KERN_CBITBROKEN);
1176 /*
1177 * Gee george, I wonder why Sun is so hush hush about
1178 * this hardware bug... really braindamage stuff going
1179 * on here. However I think we can find a way to avoid
1180 * all of the workaround overhead under Linux. Basically,
1181 * any page fault can cause kernel pages to become user
1182 * accessible (the mmu gets confused and clears some of
1183 * the ACC bits in kernel ptes). Aha, sounds pretty
1184 * horrible eh? But wait, after extensive testing it appears
1185 * that if you use pgd_t level large kernel pte's (like the
1186 * 4MB pages on the Pentium) the bug does not get tripped
1187 * at all. This avoids almost all of the major overhead.
1188 * Welcome to a world where your vendor tells you to,
1189 * "apply this kernel patch" instead of "sorry for the
1190 * broken hardware, send it back and we'll give you
1191 * properly functioning parts"
1192 */
1193 break;
1194 case 0x25:
1195 case 0x31:
1196 srmmu_modtype = Swift_bad_c;
1197 hwbug_bitmask |= HWBUG_KERN_CBITBROKEN;
1198 /*
1199 * You see Sun allude to this hardware bug but never
1200 * admit things directly, they'll say things like,
1201 * "the Swift chip cache problems" or similar.
1202 */
1203 break;
1204 default:
1205 srmmu_modtype = Swift_ok;
1206 break;
Joe Perches6cb79b32011-06-03 14:45:23 +00001207 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208
David S. Miller5d83d662012-05-13 20:49:31 -07001209 sparc32_cachetlb_ops = &swift_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210 flush_page_for_dma_global = 0;
1211
1212 /*
1213 * Are you now convinced that the Swift is one of the
1214 * biggest VLSI abortions of all time? Bravo Fujitsu!
1215 * Fujitsu, the !#?!%$'d up processor people. I bet if
1216 * you examined the microcode of the Swift you'd find
1217 * XXX's all over the place.
1218 */
1219 poke_srmmu = poke_swift;
1220}
1221
1222static void turbosparc_flush_cache_all(void)
1223{
1224 flush_user_windows();
1225 turbosparc_idflash_clear();
1226}
1227
1228static void turbosparc_flush_cache_mm(struct mm_struct *mm)
1229{
1230 FLUSH_BEGIN(mm)
1231 flush_user_windows();
1232 turbosparc_idflash_clear();
1233 FLUSH_END
1234}
1235
1236static void turbosparc_flush_cache_range(struct vm_area_struct *vma, unsigned long start, unsigned long end)
1237{
1238 FLUSH_BEGIN(vma->vm_mm)
1239 flush_user_windows();
1240 turbosparc_idflash_clear();
1241 FLUSH_END
1242}
1243
1244static void turbosparc_flush_cache_page(struct vm_area_struct *vma, unsigned long page)
1245{
1246 FLUSH_BEGIN(vma->vm_mm)
1247 flush_user_windows();
1248 if (vma->vm_flags & VM_EXEC)
1249 turbosparc_flush_icache();
1250 turbosparc_flush_dcache();
1251 FLUSH_END
1252}
1253
1254/* TurboSparc is copy-back, if we turn it on, but this does not work. */
1255static void turbosparc_flush_page_to_ram(unsigned long page)
1256{
1257#ifdef TURBOSPARC_WRITEBACK
1258 volatile unsigned long clear;
1259
Sam Ravnborg805918f2012-05-25 21:20:19 +00001260 if (srmmu_probe(page))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261 turbosparc_flush_page_cache(page);
1262 clear = srmmu_get_fstatus();
1263#endif
1264}
1265
1266static void turbosparc_flush_sig_insns(struct mm_struct *mm, unsigned long insn_addr)
1267{
1268}
1269
1270static void turbosparc_flush_page_for_dma(unsigned long page)
1271{
1272 turbosparc_flush_dcache();
1273}
1274
1275static void turbosparc_flush_tlb_all(void)
1276{
1277 srmmu_flush_whole_tlb();
1278}
1279
1280static void turbosparc_flush_tlb_mm(struct mm_struct *mm)
1281{
1282 FLUSH_BEGIN(mm)
1283 srmmu_flush_whole_tlb();
1284 FLUSH_END
1285}
1286
1287static void turbosparc_flush_tlb_range(struct vm_area_struct *vma, unsigned long start, unsigned long end)
1288{
1289 FLUSH_BEGIN(vma->vm_mm)
1290 srmmu_flush_whole_tlb();
1291 FLUSH_END
1292}
1293
1294static void turbosparc_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
1295{
1296 FLUSH_BEGIN(vma->vm_mm)
1297 srmmu_flush_whole_tlb();
1298 FLUSH_END
1299}
1300
1301
Paul Gortmaker2066aad2013-06-17 15:43:14 -04001302static void poke_turbosparc(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303{
1304 unsigned long mreg = srmmu_get_mmureg();
1305 unsigned long ccreg;
1306
1307 /* Clear any crap from the cache or else... */
1308 turbosparc_flush_cache_all();
Sam Ravnborg605ae962012-07-26 11:02:13 +00001309 /* Temporarily disable I & D caches */
1310 mreg &= ~(TURBOSPARC_ICENABLE | TURBOSPARC_DCENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311 mreg &= ~(TURBOSPARC_PCENABLE); /* Don't check parity */
1312 srmmu_set_mmureg(mreg);
Sam Ravnborg605ae962012-07-26 11:02:13 +00001313
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314 ccreg = turbosparc_get_ccreg();
1315
1316#ifdef TURBOSPARC_WRITEBACK
1317 ccreg |= (TURBOSPARC_SNENABLE); /* Do DVMA snooping in Dcache */
1318 ccreg &= ~(TURBOSPARC_uS2 | TURBOSPARC_WTENABLE);
1319 /* Write-back D-cache, emulate VLSI
1320 * abortion number three, not number one */
1321#else
1322 /* For now let's play safe, optimize later */
1323 ccreg |= (TURBOSPARC_SNENABLE | TURBOSPARC_WTENABLE);
1324 /* Do DVMA snooping in Dcache, Write-thru D-cache */
1325 ccreg &= ~(TURBOSPARC_uS2);
1326 /* Emulate VLSI abortion number three, not number one */
1327#endif
1328
1329 switch (ccreg & 7) {
1330 case 0: /* No SE cache */
1331 case 7: /* Test mode */
1332 break;
1333 default:
1334 ccreg |= (TURBOSPARC_SCENABLE);
1335 }
Sam Ravnborg605ae962012-07-26 11:02:13 +00001336 turbosparc_set_ccreg(ccreg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337
1338 mreg |= (TURBOSPARC_ICENABLE | TURBOSPARC_DCENABLE); /* I & D caches on */
1339 mreg |= (TURBOSPARC_ICSNOOP); /* Icache snooping on */
1340 srmmu_set_mmureg(mreg);
1341}
1342
David S. Miller5d83d662012-05-13 20:49:31 -07001343static const struct sparc32_cachetlb_ops turbosparc_ops = {
1344 .cache_all = turbosparc_flush_cache_all,
1345 .cache_mm = turbosparc_flush_cache_mm,
1346 .cache_page = turbosparc_flush_cache_page,
1347 .cache_range = turbosparc_flush_cache_range,
1348 .tlb_all = turbosparc_flush_tlb_all,
1349 .tlb_mm = turbosparc_flush_tlb_mm,
1350 .tlb_page = turbosparc_flush_tlb_page,
1351 .tlb_range = turbosparc_flush_tlb_range,
1352 .page_to_ram = turbosparc_flush_page_to_ram,
1353 .sig_insns = turbosparc_flush_sig_insns,
1354 .page_for_dma = turbosparc_flush_page_for_dma,
1355};
1356
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357static void __init init_turbosparc(void)
1358{
1359 srmmu_name = "Fujitsu TurboSparc";
1360 srmmu_modtype = TurboSparc;
David S. Miller5d83d662012-05-13 20:49:31 -07001361 sparc32_cachetlb_ops = &turbosparc_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362 poke_srmmu = poke_turbosparc;
1363}
1364
Paul Gortmaker2066aad2013-06-17 15:43:14 -04001365static void poke_tsunami(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366{
1367 unsigned long mreg = srmmu_get_mmureg();
1368
1369 tsunami_flush_icache();
1370 tsunami_flush_dcache();
1371 mreg &= ~TSUNAMI_ITD;
1372 mreg |= (TSUNAMI_IENAB | TSUNAMI_DENAB);
1373 srmmu_set_mmureg(mreg);
1374}
1375
David S. Miller5d83d662012-05-13 20:49:31 -07001376static const struct sparc32_cachetlb_ops tsunami_ops = {
1377 .cache_all = tsunami_flush_cache_all,
1378 .cache_mm = tsunami_flush_cache_mm,
1379 .cache_page = tsunami_flush_cache_page,
1380 .cache_range = tsunami_flush_cache_range,
1381 .tlb_all = tsunami_flush_tlb_all,
1382 .tlb_mm = tsunami_flush_tlb_mm,
1383 .tlb_page = tsunami_flush_tlb_page,
1384 .tlb_range = tsunami_flush_tlb_range,
1385 .page_to_ram = tsunami_flush_page_to_ram,
1386 .sig_insns = tsunami_flush_sig_insns,
1387 .page_for_dma = tsunami_flush_page_for_dma,
1388};
1389
Linus Torvalds1da177e2005-04-16 15:20:36 -07001390static void __init init_tsunami(void)
1391{
1392 /*
1393 * Tsunami's pretty sane, Sun and TI actually got it
1394 * somewhat right this time. Fujitsu should have
1395 * taken some lessons from them.
1396 */
1397
1398 srmmu_name = "TI Tsunami";
1399 srmmu_modtype = Tsunami;
David S. Miller5d83d662012-05-13 20:49:31 -07001400 sparc32_cachetlb_ops = &tsunami_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401 poke_srmmu = poke_tsunami;
1402
1403 tsunami_setup_blockops();
1404}
1405
Paul Gortmaker2066aad2013-06-17 15:43:14 -04001406static void poke_viking(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407{
1408 unsigned long mreg = srmmu_get_mmureg();
1409 static int smp_catch;
1410
David S. Miller5d83d662012-05-13 20:49:31 -07001411 if (viking_mxcc_present) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 unsigned long mxcc_control = mxcc_get_creg();
1413
1414 mxcc_control |= (MXCC_CTL_ECE | MXCC_CTL_PRE | MXCC_CTL_MCE);
1415 mxcc_control &= ~(MXCC_CTL_RRC);
1416 mxcc_set_creg(mxcc_control);
1417
1418 /*
1419 * We don't need memory parity checks.
1420 * XXX This is a mess, have to dig out later. ecd.
1421 viking_mxcc_turn_off_parity(&mreg, &mxcc_control);
1422 */
1423
1424 /* We do cache ptables on MXCC. */
1425 mreg |= VIKING_TCENABLE;
1426 } else {
1427 unsigned long bpreg;
1428
1429 mreg &= ~(VIKING_TCENABLE);
Sam Ravnborg605ae962012-07-26 11:02:13 +00001430 if (smp_catch++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 /* Must disable mixed-cmd mode here for other cpu's. */
1432 bpreg = viking_get_bpreg();
1433 bpreg &= ~(VIKING_ACTION_MIX);
1434 viking_set_bpreg(bpreg);
1435
1436 /* Just in case PROM does something funny. */
1437 msi_set_sync();
1438 }
1439 }
1440
1441 mreg |= VIKING_SPENABLE;
1442 mreg |= (VIKING_ICENABLE | VIKING_DCENABLE);
1443 mreg |= VIKING_SBENABLE;
1444 mreg &= ~(VIKING_ACENABLE);
1445 srmmu_set_mmureg(mreg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446}
1447
Bhumika Goyalcbc41b432017-01-14 18:01:54 +05301448static struct sparc32_cachetlb_ops viking_ops __ro_after_init = {
David S. Miller5d83d662012-05-13 20:49:31 -07001449 .cache_all = viking_flush_cache_all,
1450 .cache_mm = viking_flush_cache_mm,
1451 .cache_page = viking_flush_cache_page,
1452 .cache_range = viking_flush_cache_range,
1453 .tlb_all = viking_flush_tlb_all,
1454 .tlb_mm = viking_flush_tlb_mm,
1455 .tlb_page = viking_flush_tlb_page,
1456 .tlb_range = viking_flush_tlb_range,
1457 .page_to_ram = viking_flush_page_to_ram,
1458 .sig_insns = viking_flush_sig_insns,
1459 .page_for_dma = viking_flush_page_for_dma,
1460};
1461
1462#ifdef CONFIG_SMP
1463/* On sun4d the cpu broadcasts local TLB flushes, so we can just
1464 * perform the local TLB flush and all the other cpus will see it.
1465 * But, unfortunately, there is a bug in the sun4d XBUS backplane
1466 * that requires that we add some synchronization to these flushes.
1467 *
1468 * The bug is that the fifo which keeps track of all the pending TLB
1469 * broadcasts in the system is an entry or two too small, so if we
1470 * have too many going at once we'll overflow that fifo and lose a TLB
1471 * flush resulting in corruption.
1472 *
1473 * Our workaround is to take a global spinlock around the TLB flushes,
1474 * which guarentees we won't ever have too many pending. It's a big
1475 * hammer, but a semaphore like system to make sure we only have N TLB
1476 * flushes going at once will require SMP locking anyways so there's
1477 * no real value in trying any harder than this.
1478 */
Bhumika Goyalcbc41b432017-01-14 18:01:54 +05301479static struct sparc32_cachetlb_ops viking_sun4d_smp_ops __ro_after_init = {
David S. Miller5d83d662012-05-13 20:49:31 -07001480 .cache_all = viking_flush_cache_all,
1481 .cache_mm = viking_flush_cache_mm,
1482 .cache_page = viking_flush_cache_page,
1483 .cache_range = viking_flush_cache_range,
1484 .tlb_all = sun4dsmp_flush_tlb_all,
1485 .tlb_mm = sun4dsmp_flush_tlb_mm,
1486 .tlb_page = sun4dsmp_flush_tlb_page,
1487 .tlb_range = sun4dsmp_flush_tlb_range,
1488 .page_to_ram = viking_flush_page_to_ram,
1489 .sig_insns = viking_flush_sig_insns,
1490 .page_for_dma = viking_flush_page_for_dma,
1491};
1492#endif
1493
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494static void __init init_viking(void)
1495{
1496 unsigned long mreg = srmmu_get_mmureg();
1497
1498 /* Ahhh, the viking. SRMMU VLSI abortion number two... */
Sam Ravnborg605ae962012-07-26 11:02:13 +00001499 if (mreg & VIKING_MMODE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500 srmmu_name = "TI Viking";
1501 viking_mxcc_present = 0;
1502 msi_set_sync();
1503
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504 /*
1505 * We need this to make sure old viking takes no hits
1506 * on it's cache for dma snoops to workaround the
1507 * "load from non-cacheable memory" interrupt bug.
1508 * This is only necessary because of the new way in
1509 * which we use the IOMMU.
1510 */
David S. Miller5d83d662012-05-13 20:49:31 -07001511 viking_ops.page_for_dma = viking_flush_page;
1512#ifdef CONFIG_SMP
1513 viking_sun4d_smp_ops.page_for_dma = viking_flush_page;
1514#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515 flush_page_for_dma_global = 0;
1516 } else {
1517 srmmu_name = "TI Viking/MXCC";
1518 viking_mxcc_present = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519 srmmu_cache_pagetables = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520 }
1521
David S. Miller5d83d662012-05-13 20:49:31 -07001522 sparc32_cachetlb_ops = (const struct sparc32_cachetlb_ops *)
1523 &viking_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524#ifdef CONFIG_SMP
David S. Miller5d83d662012-05-13 20:49:31 -07001525 if (sparc_cpu_model == sun4d)
1526 sparc32_cachetlb_ops = (const struct sparc32_cachetlb_ops *)
1527 &viking_sun4d_smp_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529
1530 poke_srmmu = poke_viking;
1531}
1532
1533/* Probe for the srmmu chip version. */
1534static void __init get_srmmu_type(void)
1535{
1536 unsigned long mreg, psr;
1537 unsigned long mod_typ, mod_rev, psr_typ, psr_vers;
1538
1539 srmmu_modtype = SRMMU_INVAL_MOD;
1540 hwbug_bitmask = 0;
1541
1542 mreg = srmmu_get_mmureg(); psr = get_psr();
1543 mod_typ = (mreg & 0xf0000000) >> 28;
1544 mod_rev = (mreg & 0x0f000000) >> 24;
1545 psr_typ = (psr >> 28) & 0xf;
1546 psr_vers = (psr >> 24) & 0xf;
1547
Konrad Eisele75d9e342009-08-17 00:13:33 +00001548 /* First, check for sparc-leon. */
1549 if (sparc_cpu_model == sparc_leon) {
Konrad Eisele75d9e342009-08-17 00:13:33 +00001550 init_leon();
1551 return;
1552 }
1553
1554 /* Second, check for HyperSparc or Cypress. */
Sam Ravnborg605ae962012-07-26 11:02:13 +00001555 if (mod_typ == 1) {
1556 switch (mod_rev) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557 case 7:
1558 /* UP or MP Hypersparc */
1559 init_hypersparc();
1560 break;
1561 case 0:
1562 case 2:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563 case 10:
1564 case 11:
1565 case 12:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566 case 13:
1567 case 14:
1568 case 15:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569 default:
David S. Millerc7020eb2012-05-14 22:02:08 -07001570 prom_printf("Sparc-Linux Cypress support does not longer exit.\n");
1571 prom_halt();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572 break;
Joe Perches6cb79b32011-06-03 14:45:23 +00001573 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574 return;
1575 }
Sam Ravnborg605ae962012-07-26 11:02:13 +00001576
1577 /* Now Fujitsu TurboSparc. It might happen that it is
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578 * in Swift emulation mode, so we will check later...
1579 */
1580 if (psr_typ == 0 && psr_vers == 5) {
1581 init_turbosparc();
1582 return;
1583 }
1584
1585 /* Next check for Fujitsu Swift. */
Sam Ravnborg605ae962012-07-26 11:02:13 +00001586 if (psr_typ == 0 && psr_vers == 4) {
Andres Salomon8d125562010-10-08 14:18:11 -07001587 phandle cpunode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588 char node_str[128];
1589
1590 /* Look if it is not a TurboSparc emulating Swift... */
1591 cpunode = prom_getchild(prom_root_node);
Sam Ravnborg605ae962012-07-26 11:02:13 +00001592 while ((cpunode = prom_getsibling(cpunode)) != 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593 prom_getstring(cpunode, "device_type", node_str, sizeof(node_str));
Sam Ravnborg605ae962012-07-26 11:02:13 +00001594 if (!strcmp(node_str, "cpu")) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595 if (!prom_getintdefault(cpunode, "psr-implementation", 1) &&
1596 prom_getintdefault(cpunode, "psr-version", 1) == 5) {
1597 init_turbosparc();
1598 return;
1599 }
1600 break;
1601 }
1602 }
Sam Ravnborg605ae962012-07-26 11:02:13 +00001603
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604 init_swift();
1605 return;
1606 }
1607
1608 /* Now the Viking family of srmmu. */
Sam Ravnborg605ae962012-07-26 11:02:13 +00001609 if (psr_typ == 4 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610 ((psr_vers == 0) ||
1611 ((psr_vers == 1) && (mod_typ == 0) && (mod_rev == 0)))) {
1612 init_viking();
1613 return;
1614 }
1615
1616 /* Finally the Tsunami. */
Sam Ravnborg605ae962012-07-26 11:02:13 +00001617 if (psr_typ == 4 && psr_vers == 1 && (mod_typ || mod_rev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618 init_tsunami();
1619 return;
1620 }
1621
1622 /* Oh well */
1623 srmmu_is_bad();
1624}
1625
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626#ifdef CONFIG_SMP
1627/* Local cross-calls. */
1628static void smp_flush_page_for_dma(unsigned long page)
1629{
David S. Miller5d83d662012-05-13 20:49:31 -07001630 xc1((smpfunc_t) local_ops->page_for_dma, page);
1631 local_ops->page_for_dma(page);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632}
1633
David S. Miller5d83d662012-05-13 20:49:31 -07001634static void smp_flush_cache_all(void)
1635{
1636 xc0((smpfunc_t) local_ops->cache_all);
1637 local_ops->cache_all();
1638}
1639
1640static void smp_flush_tlb_all(void)
1641{
1642 xc0((smpfunc_t) local_ops->tlb_all);
1643 local_ops->tlb_all();
1644}
1645
1646static void smp_flush_cache_mm(struct mm_struct *mm)
1647{
1648 if (mm->context != NO_CONTEXT) {
1649 cpumask_t cpu_mask;
1650 cpumask_copy(&cpu_mask, mm_cpumask(mm));
1651 cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
1652 if (!cpumask_empty(&cpu_mask))
1653 xc1((smpfunc_t) local_ops->cache_mm, (unsigned long) mm);
1654 local_ops->cache_mm(mm);
1655 }
1656}
1657
1658static void smp_flush_tlb_mm(struct mm_struct *mm)
1659{
1660 if (mm->context != NO_CONTEXT) {
1661 cpumask_t cpu_mask;
1662 cpumask_copy(&cpu_mask, mm_cpumask(mm));
1663 cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
1664 if (!cpumask_empty(&cpu_mask)) {
1665 xc1((smpfunc_t) local_ops->tlb_mm, (unsigned long) mm);
1666 if (atomic_read(&mm->mm_users) == 1 && current->active_mm == mm)
1667 cpumask_copy(mm_cpumask(mm),
1668 cpumask_of(smp_processor_id()));
1669 }
1670 local_ops->tlb_mm(mm);
1671 }
1672}
1673
1674static void smp_flush_cache_range(struct vm_area_struct *vma,
1675 unsigned long start,
1676 unsigned long end)
1677{
1678 struct mm_struct *mm = vma->vm_mm;
1679
1680 if (mm->context != NO_CONTEXT) {
1681 cpumask_t cpu_mask;
1682 cpumask_copy(&cpu_mask, mm_cpumask(mm));
1683 cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
1684 if (!cpumask_empty(&cpu_mask))
1685 xc3((smpfunc_t) local_ops->cache_range,
1686 (unsigned long) vma, start, end);
1687 local_ops->cache_range(vma, start, end);
1688 }
1689}
1690
1691static void smp_flush_tlb_range(struct vm_area_struct *vma,
1692 unsigned long start,
1693 unsigned long end)
1694{
1695 struct mm_struct *mm = vma->vm_mm;
1696
1697 if (mm->context != NO_CONTEXT) {
1698 cpumask_t cpu_mask;
1699 cpumask_copy(&cpu_mask, mm_cpumask(mm));
1700 cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
1701 if (!cpumask_empty(&cpu_mask))
1702 xc3((smpfunc_t) local_ops->tlb_range,
1703 (unsigned long) vma, start, end);
1704 local_ops->tlb_range(vma, start, end);
1705 }
1706}
1707
1708static void smp_flush_cache_page(struct vm_area_struct *vma, unsigned long page)
1709{
1710 struct mm_struct *mm = vma->vm_mm;
1711
1712 if (mm->context != NO_CONTEXT) {
1713 cpumask_t cpu_mask;
1714 cpumask_copy(&cpu_mask, mm_cpumask(mm));
1715 cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
1716 if (!cpumask_empty(&cpu_mask))
1717 xc2((smpfunc_t) local_ops->cache_page,
1718 (unsigned long) vma, page);
1719 local_ops->cache_page(vma, page);
1720 }
1721}
1722
1723static void smp_flush_tlb_page(struct vm_area_struct *vma, unsigned long page)
1724{
1725 struct mm_struct *mm = vma->vm_mm;
1726
1727 if (mm->context != NO_CONTEXT) {
1728 cpumask_t cpu_mask;
1729 cpumask_copy(&cpu_mask, mm_cpumask(mm));
1730 cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
1731 if (!cpumask_empty(&cpu_mask))
1732 xc2((smpfunc_t) local_ops->tlb_page,
1733 (unsigned long) vma, page);
1734 local_ops->tlb_page(vma, page);
1735 }
1736}
1737
1738static void smp_flush_page_to_ram(unsigned long page)
1739{
1740 /* Current theory is that those who call this are the one's
1741 * who have just dirtied their cache with the pages contents
1742 * in kernel space, therefore we only run this on local cpu.
1743 *
1744 * XXX This experiment failed, research further... -DaveM
1745 */
1746#if 1
1747 xc1((smpfunc_t) local_ops->page_to_ram, page);
1748#endif
1749 local_ops->page_to_ram(page);
1750}
1751
1752static void smp_flush_sig_insns(struct mm_struct *mm, unsigned long insn_addr)
1753{
1754 cpumask_t cpu_mask;
1755 cpumask_copy(&cpu_mask, mm_cpumask(mm));
1756 cpumask_clear_cpu(smp_processor_id(), &cpu_mask);
1757 if (!cpumask_empty(&cpu_mask))
1758 xc2((smpfunc_t) local_ops->sig_insns,
1759 (unsigned long) mm, insn_addr);
1760 local_ops->sig_insns(mm, insn_addr);
1761}
1762
Bhumika Goyalcbc41b432017-01-14 18:01:54 +05301763static struct sparc32_cachetlb_ops smp_cachetlb_ops __ro_after_init = {
David S. Miller5d83d662012-05-13 20:49:31 -07001764 .cache_all = smp_flush_cache_all,
1765 .cache_mm = smp_flush_cache_mm,
1766 .cache_page = smp_flush_cache_page,
1767 .cache_range = smp_flush_cache_range,
1768 .tlb_all = smp_flush_tlb_all,
1769 .tlb_mm = smp_flush_tlb_mm,
1770 .tlb_page = smp_flush_tlb_page,
1771 .tlb_range = smp_flush_tlb_range,
1772 .page_to_ram = smp_flush_page_to_ram,
1773 .sig_insns = smp_flush_sig_insns,
1774 .page_for_dma = smp_flush_page_for_dma,
1775};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776#endif
1777
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778/* Load up routines and constants for sun4m and sun4d mmu */
Sam Ravnborga3c5c662012-05-12 20:35:52 +02001779void __init load_mmu(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781 /* Functions */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001782 get_srmmu_type();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783
1784#ifdef CONFIG_SMP
1785 /* El switcheroo... */
David S. Miller5d83d662012-05-13 20:49:31 -07001786 local_ops = sparc32_cachetlb_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001787
David S. Miller5d83d662012-05-13 20:49:31 -07001788 if (sparc_cpu_model == sun4d || sparc_cpu_model == sparc_leon) {
1789 smp_cachetlb_ops.tlb_all = local_ops->tlb_all;
1790 smp_cachetlb_ops.tlb_mm = local_ops->tlb_mm;
1791 smp_cachetlb_ops.tlb_range = local_ops->tlb_range;
1792 smp_cachetlb_ops.tlb_page = local_ops->tlb_page;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793 }
David S. Miller64273d02008-11-26 01:00:58 -08001794
1795 if (poke_srmmu == poke_viking) {
1796 /* Avoid unnecessary cross calls. */
David S. Miller5d83d662012-05-13 20:49:31 -07001797 smp_cachetlb_ops.cache_all = local_ops->cache_all;
1798 smp_cachetlb_ops.cache_mm = local_ops->cache_mm;
1799 smp_cachetlb_ops.cache_range = local_ops->cache_range;
1800 smp_cachetlb_ops.cache_page = local_ops->cache_page;
1801
1802 smp_cachetlb_ops.page_to_ram = local_ops->page_to_ram;
1803 smp_cachetlb_ops.sig_insns = local_ops->sig_insns;
1804 smp_cachetlb_ops.page_for_dma = local_ops->page_for_dma;
David S. Miller64273d02008-11-26 01:00:58 -08001805 }
David S. Miller5d83d662012-05-13 20:49:31 -07001806
1807 /* It really is const after this point. */
1808 sparc32_cachetlb_ops = (const struct sparc32_cachetlb_ops *)
1809 &smp_cachetlb_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810#endif
1811
1812 if (sparc_cpu_model == sun4d)
1813 ld_mmu_iounit();
1814 else
1815 ld_mmu_iommu();
1816#ifdef CONFIG_SMP
1817 if (sparc_cpu_model == sun4d)
1818 sun4d_init_smp();
Konrad Eisele84017072009-08-31 22:08:13 +00001819 else if (sparc_cpu_model == sparc_leon)
1820 leon_init_smp();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821 else
1822 sun4m_init_smp();
1823#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824}