xref: /dragonfly/test/nvmm/demo/smallkern/pdir.h (revision 20b815aaa70f0fb8a4c815b9686a6de1feb2fa58)
1 /*
2  * Copyright (c) 2018 The NetBSD Foundation, Inc. All rights reserved.
3  *
4  * This code is derived from software contributed to The NetBSD Foundation
5  * by Maxime Villard.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #ifndef PDIR_H_
30 #define PDIR_H_
31 
32 #ifndef PAGE_SIZE
33 #define PAGE_SIZE   4096
34 #endif
35 #define PDE_SIZE    8
36 #define FRAMESIZE   8
37 
38 #ifdef __DragonFly__
39 #define PGSHIFT               12
40 #define NBPG                  (1 << PGSHIFT)                /* bytes/page */
41 #define PGOFSET               (NBPG - 1)                    /* byte offset into page */
42 #define USPACE                (UPAGES * NBPG)               /* total size of u-area */
43 #endif /* __DragonFly__ */
44 
45 #define IOM_BEGIN   0x0a0000            /* Start of I/O Memory "hole" */
46 #define IOM_END               0x100000            /* End of I/O Memory "hole" */
47 #define IOM_SIZE    (IOM_END - IOM_BEGIN)
48 
49 #define SMALLKERNBASE                   0x0
50 #define SMALLKERNTEXTOFF      (SMALLKERNBASE + 0x100000)
51 
52 #define L4_SLOT_SMALLKERN     0
53 #define L4_SLOT_PTE           255
54 
55 #define PDIR_SLOT_KERN        L4_SLOT_SMALLKERN
56 #define PDIR_SLOT_PTE         L4_SLOT_PTE
57 
58 #define PTE_BASE    ((pt_entry_t *)(L4_SLOT_PTE * NBPD_L4))
59 
60 #define L1_BASE     PTE_BASE
61 #define L2_BASE     ((pd_entry_t *)((char *)L1_BASE + L4_SLOT_PTE * NBPD_L3))
62 #define L3_BASE     ((pd_entry_t *)((char *)L2_BASE + L4_SLOT_PTE * NBPD_L2))
63 #define L4_BASE     ((pd_entry_t *)((char *)L3_BASE + L4_SLOT_PTE * NBPD_L1))
64 
65 #define PDP_BASE    L4_BASE
66 
67 #define NKL4_MAX_ENTRIES      (unsigned long)1
68 #define NKL3_MAX_ENTRIES      (unsigned long)(NKL4_MAX_ENTRIES * 512)
69 #define NKL2_MAX_ENTRIES      (unsigned long)(NKL3_MAX_ENTRIES * 512)
70 #define NKL1_MAX_ENTRIES      (unsigned long)(NKL2_MAX_ENTRIES * 512)
71 
72 #define NKL4_KIMG_ENTRIES     1
73 #define NKL3_KIMG_ENTRIES     1
74 #define NKL2_KIMG_ENTRIES     32
75 
76 #define L1_SHIFT    12
77 #define L2_SHIFT    21
78 #define L3_SHIFT    30
79 #define L4_SHIFT    39
80 #define NBPD_L1               (1UL << L1_SHIFT) /* # bytes mapped by L1 ent (4K) */
81 #define NBPD_L2               (1UL << L2_SHIFT) /* # bytes mapped by L2 ent (2MB) */
82 #define NBPD_L3               (1UL << L3_SHIFT) /* # bytes mapped by L3 ent (1G) */
83 #define NBPD_L4               (1UL << L4_SHIFT) /* # bytes mapped by L4 ent (512G) */
84 
85 #define L4_MASK               0x0000ff8000000000
86 #define L3_MASK               0x0000007fc0000000
87 #define L2_MASK               0x000000003fe00000
88 #define L1_MASK               0x00000000001ff000
89 
90 #define L4_FRAME    L4_MASK
91 #define L3_FRAME    (L4_FRAME|L3_MASK)
92 #define L2_FRAME    (L3_FRAME|L2_MASK)
93 #define L1_FRAME    (L2_FRAME|L1_MASK)
94 
95 #define pl1_i(va)   (((va) & L1_FRAME) >> L1_SHIFT)
96 #define pl2_i(va)   (((va) & L2_FRAME) >> L2_SHIFT)
97 #define pl3_i(va)   (((va) & L3_FRAME) >> L3_SHIFT)
98 #define pl4_i(va)   (((va) & L4_FRAME) >> L4_SHIFT)
99 
100 #endif /* !PDIR_H_ */
101