Home | History | Annotate | Line # | Download | only in include
pmap.h revision 1.1.28.3
      1  1.1.28.3  pgoyette /* $NetBSD: pmap.h,v 1.1.28.3 2018/05/02 07:20:02 pgoyette Exp $ */
      2       1.1      matt 
      3       1.1      matt /*-
      4       1.1      matt  * Copyright (c) 2014 The NetBSD Foundation, Inc.
      5       1.1      matt  * All rights reserved.
      6       1.1      matt  *
      7       1.1      matt  * This code is derived from software contributed to The NetBSD Foundation
      8       1.1      matt  * by Matt Thomas of 3am Software Foundry.
      9       1.1      matt  *
     10       1.1      matt  * Redistribution and use in source and binary forms, with or without
     11       1.1      matt  * modification, are permitted provided that the following conditions
     12       1.1      matt  * are met:
     13       1.1      matt  * 1. Redistributions of source code must retain the above copyright
     14       1.1      matt  *    notice, this list of conditions and the following disclaimer.
     15       1.1      matt  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.1      matt  *    notice, this list of conditions and the following disclaimer in the
     17       1.1      matt  *    documentation and/or other materials provided with the distribution.
     18       1.1      matt  *
     19       1.1      matt  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20       1.1      matt  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21       1.1      matt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22       1.1      matt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23       1.1      matt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24       1.1      matt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25       1.1      matt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26       1.1      matt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27       1.1      matt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28       1.1      matt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29       1.1      matt  * POSSIBILITY OF SUCH DAMAGE.
     30       1.1      matt  */
     31       1.1      matt 
     32       1.1      matt #ifndef _AARCH64_PMAP_H_
     33       1.1      matt #define _AARCH64_PMAP_H_
     34       1.1      matt 
     35       1.1      matt #ifdef __aarch64__
     36       1.1      matt 
     37       1.1      matt #include <sys/types.h>
     38       1.1      matt #include <sys/pool.h>
     39  1.1.28.1  pgoyette #include <sys/queue.h>
     40       1.1      matt #include <uvm/uvm_pglist.h>
     41       1.1      matt 
     42  1.1.28.1  pgoyette #include <aarch64/pte.h>
     43  1.1.28.1  pgoyette 
     44       1.1      matt #define PMAP_GROWKERNEL
     45       1.1      matt #define PMAP_STEAL_MEMORY
     46       1.1      matt 
     47  1.1.28.1  pgoyette #define __HAVE_VM_PAGE_MD
     48  1.1.28.1  pgoyette 
     49       1.1      matt struct pmap {
     50  1.1.28.1  pgoyette 	kmutex_t pm_lock;
     51       1.1      matt 	struct pool *pm_pvpool;
     52  1.1.28.1  pgoyette 	pd_entry_t *pm_l0table;			/* L0 table: 512G*512 */
     53  1.1.28.1  pgoyette 	paddr_t pm_l0table_pa;
     54  1.1.28.1  pgoyette 
     55  1.1.28.1  pgoyette 	SLIST_HEAD(, vm_page) pm_vmlist;	/* for L[0123] tables */
     56  1.1.28.1  pgoyette 
     57       1.1      matt 	struct pmap_statistics pm_stats;
     58  1.1.28.1  pgoyette 	unsigned int pm_refcnt;
     59  1.1.28.1  pgoyette 	int pm_asid;
     60  1.1.28.1  pgoyette 	bool pm_activated;
     61       1.1      matt };
     62       1.1      matt 
     63  1.1.28.1  pgoyette struct pv_entry;
     64       1.1      matt struct vm_page_md {
     65  1.1.28.1  pgoyette 	kmutex_t mdpg_pvlock;
     66  1.1.28.1  pgoyette 	SLIST_ENTRY(vm_page) mdpg_vmlist;	/* L[0-3] table vm_page list */
     67  1.1.28.1  pgoyette 	TAILQ_HEAD(, pv_entry) mdpg_pvhead;
     68  1.1.28.1  pgoyette 
     69  1.1.28.1  pgoyette 	/* VM_PROT_READ means referenced, VM_PROT_WRITE means modified */
     70  1.1.28.1  pgoyette 	uint32_t mdpg_flags;
     71       1.1      matt };
     72       1.1      matt 
     73  1.1.28.1  pgoyette /* each mdpg_pvlock will be initialized in pmap_init() */
     74  1.1.28.1  pgoyette #define VM_MDPAGE_INIT(pg)				\
     75  1.1.28.1  pgoyette 	do {						\
     76  1.1.28.1  pgoyette 		TAILQ_INIT(&(pg)->mdpage.mdpg_pvhead);	\
     77  1.1.28.1  pgoyette 		(pg)->mdpage.mdpg_flags = 0;		\
     78       1.1      matt 	} while (/*CONSTCOND*/ 0)
     79       1.1      matt 
     80  1.1.28.1  pgoyette #define l0pde_pa(pde)		((paddr_t)((pde) & LX_TBL_PA))
     81  1.1.28.1  pgoyette #define l0pde_index(v)		(((vaddr_t)(v) & L0_ADDR_BITS) >> L0_SHIFT)
     82  1.1.28.1  pgoyette #define l0pde_valid(pde)	(((pde) & LX_VALID) == LX_VALID)
     83  1.1.28.1  pgoyette /* l0pte always contains table entries */
     84  1.1.28.1  pgoyette 
     85  1.1.28.1  pgoyette #define l1pde_pa(pde)		((paddr_t)((pde) & LX_TBL_PA))
     86  1.1.28.1  pgoyette #define l1pde_index(v)		(((vaddr_t)(v) & L1_ADDR_BITS) >> L1_SHIFT)
     87  1.1.28.1  pgoyette #define l1pde_valid(pde)	(((pde) & LX_VALID) == LX_VALID)
     88  1.1.28.1  pgoyette #define l1pde_is_block(pde)	(((pde) & LX_TYPE) == LX_TYPE_BLK)
     89  1.1.28.1  pgoyette #define l1pde_is_table(pde)	(((pde) & LX_TYPE) == LX_TYPE_TBL)
     90  1.1.28.1  pgoyette 
     91  1.1.28.1  pgoyette #define l2pde_pa(pde)		((paddr_t)((pde) & LX_TBL_PA))
     92  1.1.28.1  pgoyette #define l2pde_index(v)		(((vaddr_t)(v) & L2_ADDR_BITS) >> L2_SHIFT)
     93  1.1.28.1  pgoyette #define l2pde_valid(pde)	(((pde) & LX_VALID) == LX_VALID)
     94  1.1.28.1  pgoyette #define l2pde_is_block(pde)	(((pde) & LX_TYPE) == LX_TYPE_BLK)
     95  1.1.28.1  pgoyette #define l2pde_is_table(pde)	(((pde) & LX_TYPE) == LX_TYPE_TBL)
     96  1.1.28.1  pgoyette 
     97  1.1.28.1  pgoyette #define l3pte_pa(pde)		((paddr_t)((pde) & LX_TBL_PA))
     98  1.1.28.1  pgoyette #define l3pte_executable(pde)	\
     99  1.1.28.1  pgoyette     (((pde) & (LX_BLKPAG_UXN|LX_BLKPAG_PXN)) != (LX_BLKPAG_UXN|LX_BLKPAG_PXN))
    100  1.1.28.1  pgoyette #define l3pte_index(v)		(((vaddr_t)(v) & L3_ADDR_BITS) >> L3_SHIFT)
    101  1.1.28.1  pgoyette #define l3pte_valid(pde)	(((pde) & LX_VALID) == LX_VALID)
    102  1.1.28.1  pgoyette #define l3pte_is_page(pde)	(((pde) & LX_TYPE) == L3_TYPE_PAG)
    103  1.1.28.1  pgoyette /* l3pte contains always page entries */
    104  1.1.28.1  pgoyette 
    105  1.1.28.1  pgoyette void pmap_bootstrap(vaddr_t, vaddr_t);
    106  1.1.28.1  pgoyette bool pmap_fault_fixup(struct pmap *, vaddr_t, vm_prot_t, bool user);
    107  1.1.28.1  pgoyette void pmap_db_pteinfo(vaddr_t, void (*)(const char *, ...));
    108  1.1.28.1  pgoyette 
    109  1.1.28.1  pgoyette /* Hooks for the pool allocator */
    110  1.1.28.1  pgoyette paddr_t vtophys(vaddr_t);
    111  1.1.28.1  pgoyette #define VTOPHYS_FAILED		((paddr_t)-1L)	/* POOL_PADDR_INVALID */
    112  1.1.28.1  pgoyette #define POOL_VTOPHYS(va)	vtophys((vaddr_t) (va))
    113  1.1.28.1  pgoyette 
    114  1.1.28.1  pgoyette 
    115  1.1.28.1  pgoyette /* devmap */
    116  1.1.28.1  pgoyette struct pmap_devmap {
    117  1.1.28.1  pgoyette 	vaddr_t pd_va;		/* virtual address */
    118  1.1.28.1  pgoyette 	paddr_t pd_pa;		/* physical address */
    119  1.1.28.1  pgoyette 	psize_t pd_size;	/* size of region */
    120  1.1.28.1  pgoyette 	vm_prot_t pd_prot;	/* protection code */
    121  1.1.28.1  pgoyette 	u_int pd_flags;		/* flags for pmap_kenter_pa() */
    122  1.1.28.1  pgoyette };
    123  1.1.28.1  pgoyette 
    124  1.1.28.1  pgoyette void pmap_devmap_register(const struct pmap_devmap *);
    125  1.1.28.1  pgoyette void pmap_devmap_bootstrap(const struct pmap_devmap *);
    126  1.1.28.1  pgoyette const struct pmap_devmap *pmap_devmap_find_pa(paddr_t, psize_t);
    127  1.1.28.1  pgoyette const struct pmap_devmap *pmap_devmap_find_va(vaddr_t, vsize_t);
    128  1.1.28.1  pgoyette vaddr_t pmap_devmap_phystov(paddr_t);
    129  1.1.28.1  pgoyette paddr_t pmap_devmap_vtophys(paddr_t);
    130  1.1.28.1  pgoyette 
    131  1.1.28.1  pgoyette /* devmap use L2 blocks. (2Mbyte) */
    132  1.1.28.1  pgoyette #define DEVMAP_TRUNC_ADDR(x)	((x) & ~L2_OFFSET)
    133  1.1.28.1  pgoyette #define DEVMAP_ROUND_SIZE(x)	(((x) + L2_SIZE - 1) & ~(L2_SIZE - 1))
    134  1.1.28.1  pgoyette 
    135  1.1.28.1  pgoyette #define	DEVMAP_ENTRY(va, pa, sz)			\
    136  1.1.28.1  pgoyette 	{						\
    137  1.1.28.1  pgoyette 		.pd_va = DEVMAP_TRUNC_ADDR(va),		\
    138  1.1.28.1  pgoyette 		.pd_pa = DEVMAP_TRUNC_ADDR(pa),		\
    139  1.1.28.1  pgoyette 		.pd_size = DEVMAP_ROUND_SIZE(sz),	\
    140  1.1.28.1  pgoyette 		.pd_prot = VM_PROT_READ|VM_PROT_WRITE,	\
    141  1.1.28.1  pgoyette 		.pd_flags = PMAP_NOCACHE		\
    142  1.1.28.1  pgoyette 	}
    143  1.1.28.1  pgoyette #define	DEVMAP_ENTRY_END	{ 0 }
    144  1.1.28.1  pgoyette 
    145  1.1.28.1  pgoyette /* mmap cookie and flags */
    146  1.1.28.1  pgoyette #define AARCH64_MMAP_FLAG_SHIFT		(64 - PGSHIFT)
    147  1.1.28.1  pgoyette #define AARCH64_MMAP_FLAG_MASK		0xf
    148  1.1.28.2  pgoyette #define AARCH64_MMAP_WRITEBACK		0UL
    149  1.1.28.2  pgoyette #define AARCH64_MMAP_NOCACHE		1UL
    150  1.1.28.2  pgoyette #define AARCH64_MMAP_WRITECOMBINE	2UL
    151  1.1.28.2  pgoyette #define AARCH64_MMAP_DEVICE		3UL
    152  1.1.28.1  pgoyette 
    153  1.1.28.1  pgoyette #define ARM_MMAP_WRITECOMBINE		AARCH64_MMAP_WRITECOMBINE
    154  1.1.28.1  pgoyette #define ARM_MMAP_WRITEBACK		AARCH64_MMAP_WRITEBACK
    155  1.1.28.1  pgoyette #define ARM_MMAP_NOCACHE		AARCH64_MMAP_NOCACHE
    156  1.1.28.1  pgoyette #define ARM_MMAP_DEVICE			AARCH64_MMAP_DEVICE
    157  1.1.28.1  pgoyette 
    158  1.1.28.1  pgoyette #define	PMAP_PTE			0x10000000 /* kenter_pa */
    159  1.1.28.1  pgoyette #define	PMAP_DEV			0x20000000 /* kenter_pa */
    160  1.1.28.1  pgoyette 
    161  1.1.28.1  pgoyette static inline u_int
    162  1.1.28.1  pgoyette aarch64_mmap_flags(paddr_t mdpgno)
    163  1.1.28.1  pgoyette {
    164  1.1.28.1  pgoyette 	u_int nflag, pflag;
    165  1.1.28.1  pgoyette 
    166  1.1.28.1  pgoyette 	/*
    167  1.1.28.1  pgoyette 	 * aarch64 arch has 4 memory attribute:
    168  1.1.28.1  pgoyette 	 *
    169  1.1.28.1  pgoyette 	 *  WriteBack      - write back cache
    170  1.1.28.1  pgoyette 	 *  WriteThru      - wite through cache
    171  1.1.28.1  pgoyette 	 *  NoCache        - no cache
    172  1.1.28.1  pgoyette 	 *  Device(nGnRnE) - no Gathering, no Reordering, no Early write ack
    173  1.1.28.1  pgoyette 	 *
    174  1.1.28.1  pgoyette 	 * but pmap has PMAP_{NOCACHE,WRITE_COMBINE,WRITE_BACK} flags.
    175  1.1.28.1  pgoyette 	 */
    176  1.1.28.1  pgoyette 
    177  1.1.28.1  pgoyette 	nflag = (mdpgno >> AARCH64_MMAP_FLAG_SHIFT) & AARCH64_MMAP_FLAG_MASK;
    178  1.1.28.1  pgoyette 	switch (nflag) {
    179  1.1.28.1  pgoyette 	case AARCH64_MMAP_DEVICE:
    180  1.1.28.1  pgoyette 		pflag = PMAP_DEV;
    181  1.1.28.1  pgoyette 		break;
    182  1.1.28.1  pgoyette 	case AARCH64_MMAP_WRITECOMBINE:
    183  1.1.28.1  pgoyette 		pflag = PMAP_WRITE_COMBINE;
    184  1.1.28.1  pgoyette 		break;
    185  1.1.28.1  pgoyette 	case AARCH64_MMAP_WRITEBACK:
    186  1.1.28.1  pgoyette 		pflag = PMAP_WRITE_BACK;
    187  1.1.28.1  pgoyette 		break;
    188  1.1.28.1  pgoyette 	case AARCH64_MMAP_NOCACHE:
    189  1.1.28.1  pgoyette 	default:
    190  1.1.28.1  pgoyette 		pflag = PMAP_NOCACHE;
    191  1.1.28.1  pgoyette 		break;
    192  1.1.28.1  pgoyette 	}
    193  1.1.28.1  pgoyette 	return pflag;
    194  1.1.28.1  pgoyette }
    195  1.1.28.1  pgoyette 
    196  1.1.28.1  pgoyette 
    197  1.1.28.1  pgoyette #define pmap_phys_address(pa)		aarch64_ptob((pa))
    198  1.1.28.1  pgoyette #define pmap_mmap_flags(ppn)		aarch64_mmap_flags((ppn))
    199  1.1.28.1  pgoyette 
    200  1.1.28.1  pgoyette #define pmap_update(pmap)		((void)0)
    201  1.1.28.1  pgoyette #define pmap_copy(dp,sp,d,l,s)		((void)0)
    202  1.1.28.1  pgoyette #define pmap_wired_count(pmap)		((pmap)->pm_stats.wired_count)
    203  1.1.28.1  pgoyette #define pmap_resident_count(pmap)	((pmap)->pm_stats.resident_count)
    204  1.1.28.1  pgoyette 
    205  1.1.28.1  pgoyette bool	pmap_extract_coherency(pmap_t, vaddr_t, paddr_t *, bool *);
    206  1.1.28.1  pgoyette 
    207  1.1.28.1  pgoyette #define	PMAP_MAPSIZE1	L2_SIZE
    208  1.1.28.1  pgoyette 
    209       1.1      matt #elif defined(__arm__)
    210       1.1      matt 
    211       1.1      matt #include <arm/pmap.h>
    212       1.1      matt 
    213  1.1.28.1  pgoyette #endif /* __arm__/__aarch64__ */
    214       1.1      matt 
    215  1.1.28.1  pgoyette #endif /* !_AARCH64_PMAP_ */
    216