-/* $OpenBSD: pmap.c,v 1.23 2022/09/10 20:35:29 miod Exp $ */
+/* $OpenBSD: pmap.c,v 1.24 2022/10/17 19:51:54 kettenis Exp $ */
/*
* Copyright (c) 2019-2020 Brian Bamsch <bbamsch@google.com>
#include <machine/riscvreg.h>
#include <machine/sbi.h>
+#include <dev/ofw/fdt.h>
+
#ifdef MULTIPROCESSOR
static inline int
int pmap_cnt_avail, pmap_cnt_allocated;
uint64_t pmap_avail_kvo;
+paddr_t pmap_cached_start, pmap_cached_end;
+paddr_t pmap_uncached_start, pmap_uncached_end;
+
static inline void
pmap_lock(struct pmap *pmap)
{
{
pmap_t pm = pmap_kernel();
struct pte_desc *pted;
+ struct vm_page *pg;
pted = pmap_vp_lookup(pm, va, NULL);
pmap_pte_insert(pted);
tlb_flush_page(pm, va & ~PAGE_MASK);
+
+ pg = PHYS_TO_VM_PAGE(pa);
+ if (pg && cache == PMAP_CACHE_CI)
+ cpu_dcache_wbinv_range(pa & ~PAGE_MASK, PAGE_SIZE);
}
void
case PMAP_CACHE_WT:
break;
case PMAP_CACHE_CI:
+ if (pa >= pmap_cached_start && pa <= pmap_cached_end)
+ pa += (pmap_uncached_start - pmap_cached_start);
break;
case PMAP_CACHE_DEV:
break;
vaddr_t vstart;
int i, j, k;
int lb_idx2, ub_idx2;
+ void *node;
+
+ node = fdt_find_node("/");
+ if (fdt_is_compatible(node, "starfive,jh7100")) {
+ pmap_cached_start = 0x0080000000ULL;
+ pmap_cached_end = 0x087fffffffULL;
+ pmap_uncached_start = 0x1000000000ULL;
+ pmap_uncached_end = 0x17ffffffffULL;
+ }
pmap_setup_avail(memstart, memend, kvo);
pmap_remove_avail(kernelstart + kvo, kernelend + kvo);
pmap_extract(pmap_t pm, vaddr_t va, paddr_t *pap)
{
struct pte_desc *pted;
+ paddr_t pa;
pmap_lock(pm);
pted = pmap_vp_lookup(pm, va, NULL);
pmap_unlock(pm);
return 0;
}
- if (pap != NULL)
- *pap = (pted->pted_pte & PTE_RPGN) | (va & PAGE_MASK);
+ if (pap != NULL) {
+ pa = pted->pted_pte & PTE_RPGN;
+ if (pa >= pmap_uncached_start && pa <= pmap_uncached_end)
+ pa -= (pmap_uncached_start - pmap_cached_start);
+ *pap = pa | (va & PAGE_MASK);
+ }
pmap_unlock(pm);
return 1;