Skip to content

Commit 281983d

Browse files
committed
sh: fix up MMU reset with variable PMB mapping sizes.
Presently we run in to issues with the MMU resetting the CPU when variable sized mappings are employed. This takes a slightly more aggressive approach to keeping the TLB and cache state sane before establishing the mappings in order to cut down on races observed on SMP configurations. At the same time, we bump the VMA range up to the 0xb000...0xc000 range, as there still seems to be some undocumented behaviour in setting up variable mappings in the 0xa000...0xb000 range, resulting in reset by the TLB. Signed-off-by: Paul Mundt <lethal@linux-sh.org>
1 parent 09e1172 commit 281983d

1 file changed

Lines changed: 31 additions & 6 deletions

File tree

‎arch/sh/mm/pmb.c‎

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <linux/io.h>
2525
#include <linux/spinlock.h>
2626
#include <linux/vmalloc.h>
27+
#include <asm/cacheflush.h>
2728
#include <asm/sizes.h>
2829
#include <asm/system.h>
2930
#include <asm/uaccess.h>
@@ -292,9 +293,18 @@ static void pmb_free(struct pmb_entry *pmbe)
292293
*/
293294
static void __set_pmb_entry(struct pmb_entry *pmbe)
294295
{
296+
unsigned long addr, data;
297+
298+
addr = mk_pmb_addr(pmbe->entry);
299+
data = mk_pmb_data(pmbe->entry);
300+
301+
jump_to_uncached();
302+
295303
/* Set V-bit */
296-
__raw_writel(pmbe->ppn | pmbe->flags | PMB_V, mk_pmb_data(pmbe->entry));
297-
__raw_writel(pmbe->vpn | PMB_V, mk_pmb_addr(pmbe->entry));
304+
__raw_writel(pmbe->vpn | PMB_V, addr);
305+
__raw_writel(pmbe->ppn | pmbe->flags | PMB_V, data);
306+
307+
back_to_cached();
298308
}
299309

300310
static void __clear_pmb_entry(struct pmb_entry *pmbe)
@@ -326,6 +336,7 @@ int pmb_bolt_mapping(unsigned long vaddr, phys_addr_t phys,
326336
unsigned long size, pgprot_t prot)
327337
{
328338
struct pmb_entry *pmbp, *pmbe;
339+
unsigned long orig_addr, orig_size;
329340
unsigned long flags, pmb_flags;
330341
int i, mapped;
331342

@@ -334,6 +345,11 @@ int pmb_bolt_mapping(unsigned long vaddr, phys_addr_t phys,
334345
if (pmb_mapping_exists(vaddr, phys, size))
335346
return 0;
336347

348+
orig_addr = vaddr;
349+
orig_size = size;
350+
351+
flush_tlb_kernel_range(vaddr, vaddr + size);
352+
337353
pmb_flags = pgprot_to_pmb_flags(prot);
338354
pmbp = NULL;
339355

@@ -383,13 +399,15 @@ int pmb_bolt_mapping(unsigned long vaddr, phys_addr_t phys,
383399
}
384400
} while (size >= SZ_16M);
385401

402+
flush_cache_vmap(orig_addr, orig_addr + orig_size);
403+
386404
return 0;
387405
}
388406

389407
void __iomem *pmb_remap_caller(phys_addr_t phys, unsigned long size,
390408
pgprot_t prot, void *caller)
391409
{
392-
unsigned long orig_addr, vaddr;
410+
unsigned long vaddr;
393411
phys_addr_t offset, last_addr;
394412
phys_addr_t align_mask;
395413
unsigned long aligned;
@@ -417,19 +435,24 @@ void __iomem *pmb_remap_caller(phys_addr_t phys, unsigned long size,
417435
phys &= align_mask;
418436
aligned = ALIGN(last_addr, pmb_sizes[i].size) - phys;
419437

420-
area = __get_vm_area_caller(aligned, VM_IOREMAP, uncached_end,
438+
/*
439+
* XXX: This should really start from uncached_end, but this
440+
* causes the MMU to reset, so for now we restrict it to the
441+
* 0xb000...0xc000 range.
442+
*/
443+
area = __get_vm_area_caller(aligned, VM_IOREMAP, 0xb0000000,
421444
P3SEG, caller);
422445
if (!area)
423446
return NULL;
424447

425448
area->phys_addr = phys;
426-
orig_addr = vaddr = (unsigned long)area->addr;
449+
vaddr = (unsigned long)area->addr;
427450

428451
ret = pmb_bolt_mapping(vaddr, phys, size, prot);
429452
if (unlikely(ret != 0))
430453
return ERR_PTR(ret);
431454

432-
return (void __iomem *)(offset + (char *)orig_addr);
455+
return (void __iomem *)(offset + (char *)vaddr);
433456
}
434457

435458
int pmb_unmap(void __iomem *addr)
@@ -477,6 +500,8 @@ static void __pmb_unmap_entry(struct pmb_entry *pmbe, int depth)
477500
*/
478501
__clear_pmb_entry(pmbe);
479502

503+
flush_cache_vunmap(pmbe->vpn, pmbe->vpn + pmbe->size);
504+
480505
pmbe = pmblink->link;
481506

482507
pmb_free(pmblink);

0 commit comments

Comments
 (0)