Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/riscv Fixup some pmap / VM related #defines and code



details:   https://anonhg.NetBSD.org/src/rev/0ddedc330668
branches:  trunk
changeset: 1020992:0ddedc330668
user:      skrll <skrll%NetBSD.org@localhost>
date:      Sat May 01 07:41:24 2021 +0000

description:
Fixup some pmap / VM related #defines and code

diffstat:

 sys/arch/riscv/include/pmap.h       |  59 ++++++++++++++-------------
 sys/arch/riscv/include/pte.h        |  78 ++++++++++++++++++++++++++++++++++--
 sys/arch/riscv/include/vmparam.h    |  40 ++++++++++++++++--
 sys/arch/riscv/riscv/pmap_machdep.c |  16 +++++--
 4 files changed, 148 insertions(+), 45 deletions(-)

diffs (truncated from 394 to 300 lines):

diff -r 31f06108bc38 -r 0ddedc330668 sys/arch/riscv/include/pmap.h
--- a/sys/arch/riscv/include/pmap.h     Sat May 01 07:41:14 2021 +0000
+++ b/sys/arch/riscv/include/pmap.h     Sat May 01 07:41:24 2021 +0000
@@ -1,11 +1,12 @@
-/* $NetBSD: pmap.h,v 1.8 2020/12/20 16:38:25 skrll Exp $ */
+/* $NetBSD: pmap.h,v 1.9 2021/05/01 07:41:24 skrll Exp $ */
 
 /*
- * Copyright (c) 2014, 2019 The NetBSD Foundation, Inc.
+ * Copyright (c) 2014, 2019, 2021 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
- * by Matt Thomas (of 3am Software Foundry) and Maxime Villard.
+ * by Matt Thomas (of 3am Software Foundry), Maxime Villard, and
+ * Nick Hudson.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -38,6 +39,7 @@
 
 #if !defined(_MODULE)
 
+#include <sys/cdefs.h>
 #include <sys/types.h>
 #include <sys/pool.h>
 #include <sys/evcnt.h>
@@ -46,26 +48,35 @@
 #include <uvm/pmap/vmpagemd.h>
 
 #include <riscv/pte.h>
+#include <riscv/sysreg.h>
 
 #define PMAP_SEGTABSIZE        NPTEPG
-
-#define NBSEG          (PAGE_SIZE * NPTEPG)
+#define PMAP_PDETABSIZE        NPTEPG
 
 #ifdef _LP64
-#define NBXSEG         (NBSEG * NSEGPG)
-#define XSEGSHIFT      (SEGSHIFT + PGSHIFT - 3)
-#define XSEGOFSET      (PTE_PPN1 | SEGOFSET)
-#define SEGSHIFT       (PGSHIFT + PGSHIFT - 3)
+#define PTPSHIFT       3
+/* This is SV48. */
+//#define SEGLENGTH + SEGSHIFT + SEGSHIFT */
+
+/* This is SV39. */
+#define XSEGSHIFT      (SEGSHIFT + SEGLENGTH)
+#define NBXSEG         (1ULL << XSEGSHIFT)
+#define XSEGOFSET      (NBXSEG - 1)            /* byte offset into xsegment */
+#define XSEGLENGTH     (PGSHIFT - 3)
+#define NXSEGPG                (1 << XSEGLENGTH)
 #else
-#define SEGSHIFT       (PGSHIFT + PGSHIFT - 2)
+#define PTPSHIFT       2
+#define XSEGSHIFT      SEGLENGTH
 #endif
 
-#define SEGOFSET       (PTE_PPN0|PAGE_MASK)
+#define SEGLENGTH      (PGSHIFT - PTPSHIFT)
+#define SEGSHIFT       (SEGLENGTH + PGSHIFT)
+#define NBSEG          (1 << SEGSHIFT)         /* bytes/segment */
+#define SEGOFSET       (NBSEG - 1)             /* byte offset into segment */
 
 #define KERNEL_PID     0
 
 #define PMAP_HWPAGEWALKER              1
-#define PMAP_TLB_NUM_PIDS              256
 #define PMAP_TLB_MAX                   1
 #ifdef _LP64
 #define PMAP_INVALID_PDETAB_ADDRESS    ((pmap_pdetab_t *)(VM_MIN_KERNEL_ADDRESS - PAGE_SIZE))
@@ -74,6 +85,8 @@
 #define PMAP_INVALID_PDETAB_ADDRESS    ((pmap_pdetab_t *)0xdeadbeef)
 #define PMAP_INVALID_SEGTAB_ADDRESS    ((pmap_segtab_t *)0xdeadbeef)
 #endif
+#define PMAP_TLB_NUM_PIDS              (__SHIFTOUT_MASK(SATP_ASID) + 1)
+#define PMAP_TLB_BITMAP_LENGTH          PMAP_TLB_NUM_PIDS
 #define PMAP_TLB_FLUSH_ASID_ON_RESET   false
 
 #define pmap_phys_address(x)           (x)
@@ -120,9 +133,9 @@
 vaddr_t        pmap_md_direct_map_paddr(paddr_t);
 void   pmap_md_init(void);
 bool   pmap_md_tlb_check_entry(void *, vaddr_t, tlb_asid_t, pt_entry_t);
-void    pmap_md_page_syncicache(struct vm_page_md *, const kcpuset_t *);
 
-void   pmap_md_pdetab_activate(struct pmap *);
+void   pmap_md_xtab_activate(struct pmap *, struct lwp *);
+void   pmap_md_xtab_deactivate(struct pmap *);
 void   pmap_md_pdetab_init(struct pmap *);
 bool   pmap_md_ok_to_steal_p(const uvm_physseg_t, size_t);
 
@@ -131,6 +144,9 @@
 #define PMAP_DIRECT_MAP(pa)    (pmap_direct_base + (pa))
 #define PMAP_DIRECT_UNMAP(va)  ((paddr_t)(va) - pmap_direct_base)
 
+#define MEGAPAGE_TRUNC(x)      ((x) & ~SEGOFSET)
+#define MEGAPAGE_ROUND(x)      MEGAPAGE_TRUNC((x) + SEGOFSET)
+
 #ifdef __PMAP_PRIVATE
 static inline void
 pmap_md_page_syncicache(struct vm_page_md *mdpg, const kcpuset_t *kc)
@@ -150,7 +166,6 @@
 static inline void
 pmap_md_vca_remove(struct vm_page_md *mdpg, vaddr_t va)
 {
-
 }
 
 static inline void
@@ -164,20 +179,6 @@
        return PMAP_TLB_NUM_PIDS - 1;
 }
 
-static inline void
-pmap_md_xtab_activate(struct pmap *pm, struct lwp *l)
-{
-
-       /* nothing */
-}
-
-static inline void
-pmap_md_xtab_deactivate(struct pmap *pm)
-{
-
-       /* nothing */
-}
-
 #endif /* __PMAP_PRIVATE */
 #endif /* _KERNEL */
 
diff -r 31f06108bc38 -r 0ddedc330668 sys/arch/riscv/include/pte.h
--- a/sys/arch/riscv/include/pte.h      Sat May 01 07:41:14 2021 +0000
+++ b/sys/arch/riscv/include/pte.h      Sat May 01 07:41:24 2021 +0000
@@ -1,11 +1,12 @@
-/* $NetBSD: pte.h,v 1.5 2020/11/01 19:47:46 skrll Exp $ */
+/* $NetBSD: pte.h,v 1.6 2021/05/01 07:41:24 skrll Exp $ */
 
 /*
- * Copyright (c) 2014, 2019 The NetBSD Foundation, Inc.
+ * Copyright (c) 2014, 2019, 2021 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
- * by Matt Thomas (of 3am Software Foundry) and Maxime Villard.
+ * by Matt Thomas (of 3am Software Foundry), Maxime Villard, and
+ * Nick Hudson.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -56,7 +57,8 @@
 #define NPDEPG         NPTEPG
 
 /* Software PTE bits. */
-#define        PTE_WIRED       __BIT(8)
+#define        PTE_RSW         __BITS(9,8)
+#define        PTE_WIRED       __BIT(9)
 
 /* Hardware PTE bits. */
 // These are hardware defined bits
@@ -69,6 +71,11 @@
 #define        PTE_R           __BIT(1)        // Read
 #define        PTE_V           __BIT(0)        // Valid
 
+#define PTE_HARDWIRED  (PTE_A | PTE_D)
+#define PTE_KERN       (PTE_V | PTE_G)
+#define PTE_RW         (PTE_R | PTE_W)
+#define PTE_RX         (PTE_R | PTE_X)
+
 #define PA_TO_PTE(pa)  (((pa) >> PAGE_SHIFT) << PTE_PPN_SHIFT)
 #define PTE_TO_PA(pte) (((pte) >> PTE_PPN_SHIFT) << PAGE_SHIFT)
 
@@ -91,6 +98,12 @@
 #define pl1_i(va)      (((va) >> L1_SHIFT) & Ln_ADDR_MASK)
 #define pl0_i(va)      (((va) >> L0_SHIFT) & Ln_ADDR_MASK)
 
+static inline const size_t
+pte_index(vaddr_t va)
+{
+       return ((va >> PGSHIFT) & (NPTEPG - 1));
+}
+
 static inline bool
 pte_valid_p(pt_entry_t pte)
 {
@@ -136,7 +149,7 @@
 static inline paddr_t
 pte_to_paddr(pt_entry_t pte)
 {
-       return pte & ~PAGE_MASK;
+       return PTE_TO_PA(pte);
 }
 
 static inline pt_entry_t
@@ -224,7 +237,7 @@
 {
        pt_entry_t pte = (pt_entry_t)PA_TO_PTE(pa);
 
-       pte |= PTE_WIRED | PTE_V;
+       pte |= PTE_WIRED | PTE_G | PTE_V;
        pte |= pte_flag_bits(NULL, flags, true);
        pte |= pte_prot_bits(NULL, prot, true); /* pretend unmanaged */
 
@@ -237,6 +250,59 @@
        *ptep = pte;
 }
 
+static inline pd_entry_t
+pte_invalid_pde(void)
+{
+       return 0;
+}
+
+static inline pd_entry_t
+pte_pde_pdetab(paddr_t pa, bool kernel_p)
+{
+       return PTE_V | (pa >> PAGE_SHIFT) << L2_SHIFT;
+}
+
+static inline pd_entry_t
+pte_pde_ptpage(paddr_t pa, bool kernel_p)
+{
+       return PTE_V | PTE_X | PTE_W | PTE_R | (pa >> PAGE_SHIFT) << L2_SHIFT;
+}
+
+static inline bool
+pte_pde_valid_p(pd_entry_t pde)
+{
+       return (pde & (PTE_X | PTE_W | PTE_R)) == 0;
+}
+
+static inline paddr_t
+pte_pde_to_paddr(pd_entry_t pde)
+{
+       return pte_to_paddr((pt_entry_t)pde);
+}
+
+static inline pd_entry_t
+pte_pde_cas(pd_entry_t *pdep, pd_entry_t opde, pt_entry_t npde)
+{
+#ifdef MULTIPROCESSOR
+#ifdef _LP64
+       return atomic_cas_64(pdep, opde, npde);
+#else
+       return atomic_cas_32(pdep, opde, npde);
+#endif
+#else
+       *pdep = npde;
+       return 0;
+#endif
+}
+
+static inline void
+pte_pde_set(pd_entry_t *pdep, pd_entry_t npde)
+{
+
+       *pdep = npde;
+}
+
+
 static inline pt_entry_t
 pte_value(pt_entry_t pte)
 {
diff -r 31f06108bc38 -r 0ddedc330668 sys/arch/riscv/include/vmparam.h
--- a/sys/arch/riscv/include/vmparam.h  Sat May 01 07:41:14 2021 +0000
+++ b/sys/arch/riscv/include/vmparam.h  Sat May 01 07:41:24 2021 +0000
@@ -1,11 +1,11 @@
-/*     $NetBSD: vmparam.h,v 1.8 2021/02/26 02:18:29 simonb Exp $       */
+/*     $NetBSD: vmparam.h,v 1.9 2021/05/01 07:41:24 skrll Exp $        */
 
 /*-
- * Copyright (c) 2014 The NetBSD Foundation, Inc.
+ * Copyright (c) 2014, 2020 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
- * by Matt Thomas of 3am Software Foundry.
+ * by Matt Thomas of 3am Software Foundry, and Nick Hudson.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -42,6 +42,10 @@
  * Machine dependent VM constants for RISCV.
  */
 
+/*
+ * We use a 4K page on both RV64 and RV32 systems.
+ * Override PAGE_* definitions to compile-time constants.
+ */
 #define        PAGE_SHIFT      PGSHIFT
 #define        PAGE_SIZE       (1 << PAGE_SHIFT)
 #define        PAGE_MASK       (PAGE_SIZE - 1)
@@ -105,17 +109,43 @@
  */
 #define VM_MIN_ADDRESS         ((vaddr_t)0x00000000)
 #ifdef _LP64   /* Sv39 */
+/*
+ * kernel virtual space layout:
+ *   0xffff_ffc0_0000_0000  -   64GiB  KERNEL VM Space (inc. text/data/bss)



Home | Main Index | Thread Index | Old Index