175f59a66SMatthew Dillon /* 275f59a66SMatthew Dillon * Copyright (c) 2006 The DragonFly Project. All rights reserved. 375f59a66SMatthew Dillon * 475f59a66SMatthew Dillon * This code is derived from software contributed to The DragonFly Project 575f59a66SMatthew Dillon * by Matthew Dillon <dillon@backplane.com> 675f59a66SMatthew Dillon * 775f59a66SMatthew Dillon * Redistribution and use in source and binary forms, with or without 875f59a66SMatthew Dillon * modification, are permitted provided that the following conditions 975f59a66SMatthew Dillon * are met: 1075f59a66SMatthew Dillon * 1175f59a66SMatthew Dillon * 1. Redistributions of source code must retain the above copyright 1275f59a66SMatthew Dillon * notice, this list of conditions and the following disclaimer. 1375f59a66SMatthew Dillon * 2. Redistributions in binary form must reproduce the above copyright 1475f59a66SMatthew Dillon * notice, this list of conditions and the following disclaimer in 1575f59a66SMatthew Dillon * the documentation and/or other materials provided with the 1675f59a66SMatthew Dillon * distribution. 1775f59a66SMatthew Dillon * 3. Neither the name of The DragonFly Project nor the names of its 1875f59a66SMatthew Dillon * contributors may be used to endorse or promote products derived 1975f59a66SMatthew Dillon * from this software without specific, prior written permission. 2075f59a66SMatthew Dillon * 2175f59a66SMatthew Dillon * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 2275f59a66SMatthew Dillon * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 2375f59a66SMatthew Dillon * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 2475f59a66SMatthew Dillon * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 2575f59a66SMatthew Dillon * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 2675f59a66SMatthew Dillon * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, 2775f59a66SMatthew Dillon * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 2875f59a66SMatthew Dillon * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 2975f59a66SMatthew Dillon * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 3075f59a66SMatthew Dillon * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 3175f59a66SMatthew Dillon * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3275f59a66SMatthew Dillon * SUCH DAMAGE. 3375f59a66SMatthew Dillon */ 3475f59a66SMatthew Dillon 3575f59a66SMatthew Dillon #ifndef _SYS_VKERNEL_H_ 3675f59a66SMatthew Dillon #define _SYS_VKERNEL_H_ 3775f59a66SMatthew Dillon 3875f59a66SMatthew Dillon #if defined(_KERNEL) || defined(_KERNEL_STRUCTURES) 3975f59a66SMatthew Dillon /* 4075f59a66SMatthew Dillon * KERNEL ONLY DEFINITIONS 4175f59a66SMatthew Dillon */ 4275f59a66SMatthew Dillon 4375f59a66SMatthew Dillon #ifndef _SYS_PARAM_H_ 4475f59a66SMatthew Dillon #include <sys/param.h> 4575f59a66SMatthew Dillon #endif 4675f59a66SMatthew Dillon #ifndef _SYS_QUEUE_H_ 4775f59a66SMatthew Dillon #include <sys/queue.h> 4875f59a66SMatthew Dillon #endif 4975f59a66SMatthew Dillon #ifndef _SYS_TREE_H_ 5075f59a66SMatthew Dillon #include <sys/tree.h> 5175f59a66SMatthew Dillon #endif 5275f59a66SMatthew Dillon #ifndef _SYS_SPINLOCK_H_ 5375f59a66SMatthew Dillon #include <sys/spinlock.h> 5475f59a66SMatthew Dillon #endif 55af2b4857SMatthew Dillon #ifndef _SYS_THREAD_H_ 56af2b4857SMatthew Dillon #include <sys/thread.h> 57af2b4857SMatthew Dillon #endif 584a22e893SMatthew Dillon #include <machine/frame.h> 594e7c41c5SMatthew Dillon #include <machine/vframe.h> 608608b858SMatthew Dillon #include <machine/limits.h> 6175f59a66SMatthew Dillon 6275f59a66SMatthew Dillon struct vmspace_rb_tree; 6375f59a66SMatthew Dillon struct vmspace_entry; 64d95d5e03SMatthew Dillon struct lwp; 6575f59a66SMatthew Dillon RB_PROTOTYPE(vmspace_rb_tree, vmspace_entry, rb_entry, rb_vmspace_compare); 6675f59a66SMatthew Dillon 674a22e893SMatthew Dillon /* 684a22e893SMatthew Dillon * Process operating as virtual kernels manage multiple VM spaces. The 694a22e893SMatthew Dillon * original VM space and trap context is saved in the process's vkernel 704a22e893SMatthew Dillon * structure. 714a22e893SMatthew Dillon */ 7239005e16SMatthew Dillon struct vkernel_lwp { 7339005e16SMatthew Dillon struct trapframe save_trapframe; /* swapped context */ 7439005e16SMatthew Dillon struct vextframe save_vextframe; 7539005e16SMatthew Dillon struct trapframe *user_trapframe; /* copyback to vkernel */ 7639005e16SMatthew Dillon struct vextframe *user_vextframe; 7739005e16SMatthew Dillon struct vmspace_entry *ve; 78d95d5e03SMatthew Dillon struct vmspace_entry *ve_cache; 794a22e893SMatthew Dillon }; 804a22e893SMatthew Dillon 8139005e16SMatthew Dillon struct vkernel_proc { 8239005e16SMatthew Dillon RB_HEAD(vmspace_rb_tree, vmspace_entry) root; 83af2b4857SMatthew Dillon struct lwkt_token token; 8439005e16SMatthew Dillon int refs; 85a86ce0cdSMatthew Dillon register_t vkernel_cr3; 8675f59a66SMatthew Dillon }; 8775f59a66SMatthew Dillon 8875f59a66SMatthew Dillon struct vmspace_entry { 8975f59a66SMatthew Dillon void *id; 9075f59a66SMatthew Dillon struct vmspace *vmspace; 9176f1911eSMatthew Dillon uint32_t flags; 9276f1911eSMatthew Dillon uint32_t refs; /* in-use + 1(on-tree */ 9376f1911eSMatthew Dillon uint32_t cache_refs; /* cache count (separate) */ 9475f59a66SMatthew Dillon RB_ENTRY(vmspace_entry) rb_entry; 9575f59a66SMatthew Dillon }; 9675f59a66SMatthew Dillon 9776f1911eSMatthew Dillon #define VKE_REF_DELETED 0x80000000U 98af2b4857SMatthew Dillon 9975f59a66SMatthew Dillon #ifdef _KERNEL 1004a22e893SMatthew Dillon 1014a22e893SMatthew Dillon void vkernel_inherit(struct proc *p1, struct proc *p2); 1024a22e893SMatthew Dillon void vkernel_exit(struct proc *p); 10339005e16SMatthew Dillon void vkernel_lwp_exit(struct lwp *lp); 104bb47c072SMatthew Dillon void vkernel_trap(struct lwp *lp, struct trapframe *frame); 1054a22e893SMatthew Dillon 10675f59a66SMatthew Dillon #endif 10775f59a66SMatthew Dillon 10875f59a66SMatthew Dillon #else 10975f59a66SMatthew Dillon /* 11075f59a66SMatthew Dillon * USER ONLY DEFINITIONS 11175f59a66SMatthew Dillon */ 11275f59a66SMatthew Dillon 11375f59a66SMatthew Dillon #ifndef _MACHINE_PARAM_H_ 11475f59a66SMatthew Dillon #include <machine/param.h> 11575f59a66SMatthew Dillon #endif 11675f59a66SMatthew Dillon 11775f59a66SMatthew Dillon #endif 11875f59a66SMatthew Dillon 11975f59a66SMatthew Dillon /* 12075f59a66SMatthew Dillon * KERNEL AND USER DEFINITIONS 1218608b858SMatthew Dillon * 1227f4bfbe7SMatthew Dillon * WARNING: vpte_t is 64 bits. A 4-layer page table is used. 12375f59a66SMatthew Dillon */ 1248608b858SMatthew Dillon typedef u_long vpte_t; 12575f59a66SMatthew Dillon 1268608b858SMatthew Dillon #if LONG_BIT == 32 1278608b858SMatthew Dillon #define VPTE_FRAME_END 32 1288608b858SMatthew Dillon #define VPTE_PAGE_BITS 10 1298608b858SMatthew Dillon #define VPTE_FRAME 0xFFFFF000L 1308608b858SMatthew Dillon #elif LONG_BIT == 64 1318608b858SMatthew Dillon #define VPTE_FRAME_END 48 1328608b858SMatthew Dillon #define VPTE_PAGE_BITS 9 1338608b858SMatthew Dillon #define VPTE_FRAME 0x000FFFFFFFFFF000L 1348608b858SMatthew Dillon #else 1358608b858SMatthew Dillon #error "LONG_BIT not defined" 1368608b858SMatthew Dillon #endif 13775f59a66SMatthew Dillon 13875f59a66SMatthew Dillon #define VPTE_PAGE_ENTRIES (PAGE_SIZE / sizeof(vpte_t)) 139afeabdcaSMatthew Dillon #define VPTE_PAGE_MASK ((1 << VPTE_PAGE_BITS) - 1) 140c5a45196SMatthew Dillon #define VPTE_PAGETABLE_SIZE PAGE_SIZE 14175f59a66SMatthew Dillon 142e7f2d7deSMatthew Dillon #define VPTE_V 0x00000001 /* valid */ 143a86ce0cdSMatthew Dillon #define VPTE_RW 0x00000002 /* read/write */ 144a86ce0cdSMatthew Dillon #define VPTE_U 0x00000004 /* user access bit if managed vmspace */ 145a86ce0cdSMatthew Dillon 146c5a45196SMatthew Dillon #define VPTE_A 0x00000020 /* page accessed bit */ 147c5a45196SMatthew Dillon #define VPTE_M 0x00000040 /* page modified bit */ 148a86ce0cdSMatthew Dillon #define VPTE_PS 0x00000080 /* page directory direct mapping */ 149a86ce0cdSMatthew Dillon 150a86ce0cdSMatthew Dillon #define VPTE_G 0x00000100 /* global bit ?? */ 151a86ce0cdSMatthew Dillon #define VPTE_WIRED 0x00000200 /* wired */ 152a86ce0cdSMatthew Dillon #define VPTE_MANAGED 0x00000400 /* managed bit ?? */ 153*73d64b98SMatthew Dillon #define VPTE_NX 0x00000800 /* no-execute bit */ 154c5a45196SMatthew Dillon 15575f59a66SMatthew Dillon #endif 15675f59a66SMatthew Dillon 157