| 1 | /*	$NetBSD: pmap_pv.h,v 1.17 2020/03/17 22:29:19 ad Exp $	*/ |
| 2 | |
| 3 | /*- |
| 4 | * Copyright (c)2008 YAMAMOTO Takashi, |
| 5 | * All rights reserved. |
| 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 AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
| 17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
| 20 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 21 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 22 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 24 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 26 | * SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | #ifndef _X86_PMAP_PV_H_ |
| 30 | #define	_X86_PMAP_PV_H_ |
| 31 | |
| 32 | #include <sys/mutex.h> |
| 33 | #include <sys/queue.h> |
| 34 | #include <sys/rbtree.h> |
| 35 | |
| 36 | struct vm_page; |
| 37 | struct pmap_page; |
| 38 | |
| 39 | /* |
| 40 | * structures to track P->V mapping |
| 41 | * |
| 42 | * this file is intended to be minimum as it's included by <machine/vmparam.h>. |
| 43 | */ |
| 44 | |
| 45 | /* |
| 46 | * pv_pte: describe a pte |
| 47 | */ |
| 48 | |
| 49 | struct pv_pte { |
| 50 | 	struct vm_page *pte_ptp;	/* PTP; NULL for pmap_kernel() */ |
| 51 | 	vaddr_t pte_va;			/* VA */ |
| 52 | }; |
| 53 | |
| 54 | /* |
| 55 | * pv_entry: plug pv_pte into lists. 32 bytes on i386, 64 on amd64. |
| 56 | */ |
| 57 | |
| 58 | struct pv_entry { |
| 59 | 	struct pv_pte pve_pte;		/* should be the first member */ |
| 60 | 	LIST_ENTRY(pv_entry) pve_list;	/* on pmap_page::pp_pvlist */ |
| 61 | 	rb_node_t pve_rb;		/* red-black tree node */ |
| 62 | 	struct pmap_page *pve_pp;	/* backpointer to mapped page */ |
| 63 | }; |
| 64 | #define	pve_next	pve_list.le_next |
| 65 | |
| 66 | /* |
| 67 | * pmap_page: a structure which is embedded in each vm_page. |
| 68 | */ |
| 69 | |
| 70 | struct pmap_page { |
| 71 | 	union { |
| 72 | 		/* PTPs */ |
| 73 | 		rb_tree_t rb; |
| 74 | |
| 75 | 		/* PTPs, when being freed */ |
| 76 | 		LIST_ENTRY(vm_page) link; |
| 77 | |
| 78 | 		/* Non-PTPs (i.e. normal pages) */ |
| 79 | 		struct { |
| 80 | 			struct pv_pte pte; |
| 81 | 			LIST_HEAD(, pv_entry) pvlist; |
| 82 | 			uint8_t attrs; |
| 83 | 		} s; |
| 84 | 	} pp_u; |
| 85 | 	kmutex_t	pp_lock; |
| 86 | #define	pp_rb		pp_u.rb |
| 87 | #define	pp_link		pp_u.link |
| 88 | #define	pp_pte		pp_u.s.pte |
| 89 | #define pp_pvlist	pp_u.s.pvlist |
| 90 | #define	pp_attrs	pp_u.s.attrs |
| 91 | }; |
| 92 | |
| 93 | #define PP_ATTRS_D	0x01	/* Dirty */ |
| 94 | #define PP_ATTRS_A	0x02	/* Accessed */ |
| 95 | #define PP_ATTRS_W	0x04	/* Writable */ |
| 96 | |
| 97 | #define	PMAP_PAGE_INIT(pp) \ |
| 98 | do { \ |
| 99 | 	LIST_INIT(&(pp)->pp_pvlist); \ |
| 100 | 	mutex_init(&(pp)->pp_lock, MUTEX_NODEBUG, IPL_VM); \ |
| 101 | } while (/* CONSTCOND */ 0); |
| 102 | |
| 103 | #endif /* !_X86_PMAP_PV_H_ */ |