139923942SSimon Schubert /*- 239923942SSimon Schubert * Copyright (c) Peter Wemm <peter@netplex.com.au> 3c8fe38aeSMatthew Dillon * Copyright (c) 2008 The DragonFly Project. 439923942SSimon Schubert * All rights reserved. 539923942SSimon Schubert * 639923942SSimon Schubert * Redistribution and use in source and binary forms, with or without 739923942SSimon Schubert * modification, are permitted provided that the following conditions 839923942SSimon Schubert * are met: 939923942SSimon Schubert * 1. Redistributions of source code must retain the above copyright 1039923942SSimon Schubert * notice, this list of conditions and the following disclaimer. 1139923942SSimon Schubert * 2. Redistributions in binary form must reproduce the above copyright 1239923942SSimon Schubert * notice, this list of conditions and the following disclaimer in the 1339923942SSimon Schubert * documentation and/or other materials provided with the distribution. 1439923942SSimon Schubert * 1539923942SSimon Schubert * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1639923942SSimon Schubert * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1739923942SSimon Schubert * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1839923942SSimon Schubert * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1939923942SSimon Schubert * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2039923942SSimon Schubert * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2139923942SSimon Schubert * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2239923942SSimon Schubert * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2339923942SSimon Schubert * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2439923942SSimon Schubert * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2539923942SSimon Schubert * SUCH DAMAGE. 2639923942SSimon Schubert * 2739923942SSimon Schubert * Only machine-dependant code should ever include this file. MI 2839923942SSimon Schubert * code and header files do NOT include this file. e.g. sys/globaldata.h 2939923942SSimon Schubert * should not include this file. 3039923942SSimon Schubert * 3139923942SSimon Schubert * $FreeBSD: src/sys/i386/include/globaldata.h,v 1.11.2.1 2000/05/16 06:58:10 dillon Exp $ 3239923942SSimon Schubert */ 3339923942SSimon Schubert 3439923942SSimon Schubert #ifndef _MACHINE_GLOBALDATA_H_ 3539923942SSimon Schubert #define _MACHINE_GLOBALDATA_H_ 3639923942SSimon Schubert 3739923942SSimon Schubert #if defined(_KERNEL) || defined(_KERNEL_STRUCTURES) 3839923942SSimon Schubert 3939923942SSimon Schubert #ifndef _SYS_GLOBALDATA_H_ 4039923942SSimon Schubert #include <sys/globaldata.h> /* struct globaldata */ 4139923942SSimon Schubert #endif 4239923942SSimon Schubert #ifndef _SYS_THREAD_H_ 4339923942SSimon Schubert #include <sys/thread.h> /* struct thread */ 4439923942SSimon Schubert #endif 45c8fe38aeSMatthew Dillon #include <machine/segments.h> /* struct user_segment_descriptor */ 46b2b3ffcdSSimon Schubert #include <machine/tss.h> /* struct x86_64tss */ 47c8fe38aeSMatthew Dillon #include <machine/npx.h> 4839923942SSimon Schubert 4907fc7b93SMatthew Dillon struct pv_entry; 5007fc7b93SMatthew Dillon 5139923942SSimon Schubert /* 5239923942SSimon Schubert * Note on interrupt control. Pending interrupts not yet dispatched are 53729e15a8SSepherosa Ziehau * marked in gd_fpending or gd_spending. Once dispatched the interrupt's 54729e15a8SSepherosa Ziehau * pending bit is cleared and the interrupt is masked. Upon completion 55729e15a8SSepherosa Ziehau * the interrupt is unmasked. 5639923942SSimon Schubert * 5739923942SSimon Schubert * For edge triggered interrupts interrupts may be enabled again at this 5839923942SSimon Schubert * point and if they occur before the interrupt service routine is complete 5939923942SSimon Schubert * the service routine will loop. 6039923942SSimon Schubert * 6139923942SSimon Schubert * The current thread's cpl is stored in the thread structure. 6246d4e165SJordan Gordeev * 6346d4e165SJordan Gordeev * Note: the embedded globaldata and/or the mdglobaldata structure 6446d4e165SJordan Gordeev * may exceed the size of a page. 6539923942SSimon Schubert */ 6639923942SSimon Schubert struct mdglobaldata { 6739923942SSimon Schubert struct globaldata mi; 68c8fe38aeSMatthew Dillon struct user_segment_descriptor gd_common_tssd; 69*31815141SMatthew Dillon struct user_segment_descriptor *gd_tss_gdt; /* gd_gdt[GPROC0_SEL] */ 7039923942SSimon Schubert struct thread *gd_npxthread; 71c8fe38aeSMatthew Dillon union savefpu gd_savefpu; /* fast bcopy/zero temp fpu save area */ 72e5aace14SMatthew Dillon union savefpu gd_zerofpu; /* xrstor/fxrstor/frstor zero regs */ 73c8fe38aeSMatthew Dillon int gd_fpu_lock; /* fast bcopy/zero cpu lock */ 7479f2da03SMatthew Dillon int gd_xinvaltlb; /* reentrancy check invaltlb routine */ 7579f2da03SMatthew Dillon int gd_unused001; 7639923942SSimon Schubert int gd_spending; /* software interrupt pending */ 7739923942SSimon Schubert int gd_sdelayed; /* delayed software ints */ 7839923942SSimon Schubert int gd_currentldt; 7939923942SSimon Schubert int gd_private_tss; 8079f2da03SMatthew Dillon u_int gd_unused002; 8179f2da03SMatthew Dillon u_int gd_unused003; 8239923942SSimon Schubert u_int gd_ss_eflags; 83*31815141SMatthew Dillon struct user_segment_descriptor *gd_gdt; /* pcpu gdt[] table */ 84fc921477SMatthew Dillon long gd_lunused1; 85fc921477SMatthew Dillon long gd_lunused2; 86fc921477SMatthew Dillon long gd_lunusde3; 87da23a592SMatthew Dillon caddr_t gd_aunused0; 88da23a592SMatthew Dillon caddr_t gd_aunused1; 89da23a592SMatthew Dillon caddr_t gd_aunused2; 9007fc7b93SMatthew Dillon struct pv_entry *gd_newpv; 9146d4e165SJordan Gordeev u_int gd_acpi_id; 9246d4e165SJordan Gordeev u_int gd_apic_id; 934611d87fSMatthew Dillon register_t gd_unused004; 944611d87fSMatthew Dillon register_t gd_unused005; 95c8fe38aeSMatthew Dillon register_t gd_user_fs; /* current user fs in MSR */ 96c8fe38aeSMatthew Dillon register_t gd_user_gs; /* current user gs in MSR */ 9779f2da03SMatthew Dillon cpumask_t gd_unused006; 989611ff20SSepherosa Ziehau u_long gd_ipending[3]; 9939923942SSimon Schubert }; 10039923942SSimon Schubert 101c8fe38aeSMatthew Dillon #define MDGLOBALDATA_BASEALLOC_SIZE \ 102c8fe38aeSMatthew Dillon ((sizeof(struct mdglobaldata) + PAGE_MASK) & ~PAGE_MASK) 103c8fe38aeSMatthew Dillon #define MDGLOBALDATA_BASEALLOC_PAGES \ 104c8fe38aeSMatthew Dillon (MDGLOBALDATA_BASEALLOC_SIZE / PAGE_SIZE) 105c8fe38aeSMatthew Dillon #define MDGLOBALDATA_PAD \ 106c8fe38aeSMatthew Dillon (MDGLOBALDATA_BASEALLOC_SIZE - sizeof(struct mdglobaldata)) 107c8fe38aeSMatthew Dillon 10839923942SSimon Schubert /* 10939923942SSimon Schubert * This is the upper (0xff800000) address space layout that is per-cpu. 11039923942SSimon Schubert * It is setup in locore.s and pmap.c for the BSP and in mp_machdep.c for 11139923942SSimon Schubert * each AP. genassym helps export this to the assembler code. 1129e24b495SMatthew Dillon * 1139e24b495SMatthew Dillon * Most of the major elements in struct privatespace must be 1149e24b495SMatthew Dillon * PAGE_SIZE aligned. 11539923942SSimon Schubert */ 11639923942SSimon Schubert struct privatespace { 1179e24b495SMatthew Dillon /* 1189e24b495SMatthew Dillon * page 0 - data page 1199e24b495SMatthew Dillon */ 12039923942SSimon Schubert struct mdglobaldata mdglobaldata; 1210855a2afSJordan Gordeev char __filler0[MDGLOBALDATA_PAD]; 12239923942SSimon Schubert 1234611d87fSMatthew Dillon /* 1249e24b495SMatthew Dillon * page 1 - Unused (unmapped) 1254611d87fSMatthew Dillon */ 126da23a592SMatthew Dillon char unused2[PAGE_SIZE]; 1279e24b495SMatthew Dillon 1289e24b495SMatthew Dillon /* 1299e24b495SMatthew Dillon * page 2 - Trampoline page. Put the trampoline and common_tss 1309e24b495SMatthew Dillon * in the same page to make them easier to isolate 1319e24b495SMatthew Dillon * from the rest of the kernel map. See x86_64/pmap.c 1329e24b495SMatthew Dillon * 1339e24b495SMatthew Dillon * rsp0 points into trampoline. Interrupts are always 1349e24b495SMatthew Dillon * disabled for this case but leave reserved1[] 1359e24b495SMatthew Dillon * reserved just in case. 1369e24b495SMatthew Dillon */ 1379e24b495SMatthew Dillon char reserved1[PAGE_SIZE - 1389e24b495SMatthew Dillon sizeof(struct trampframe) - 1399e24b495SMatthew Dillon sizeof(uint64_t) - 1409e24b495SMatthew Dillon sizeof(struct x86_64tss)]; 1419e24b495SMatthew Dillon struct trampframe trampoline; 1429e24b495SMatthew Dillon uint64_t reserved1b; /* 16-byte-align trampoline */ 14385b33048SMatthew Dillon struct x86_64tss common_tss; /* (misaligned by 8 bytes) */ 1449e24b495SMatthew Dillon 1459e24b495SMatthew Dillon /* 14685b33048SMatthew Dillon * page 3, 4 - NMI, Double fault stack 14785b33048SMatthew Dillon * page 5, 6 - Debug fault stack 1489e24b495SMatthew Dillon */ 14985b33048SMatthew Dillon char dblstack[PAGE_SIZE * 2 - 15085b33048SMatthew Dillon sizeof(struct trampframe)]; 15185b33048SMatthew Dillon struct trampframe dbltramp; 15285b33048SMatthew Dillon char dbgstack[PAGE_SIZE * 2 - 15385b33048SMatthew Dillon sizeof(struct trampframe)]; 15485b33048SMatthew Dillon struct trampframe dbgtramp; 15539923942SSimon Schubert 15685b33048SMatthew Dillon /* page 7+ - idle stack (UPAGES pages) */ 157da23a592SMatthew Dillon char idlestack[UPAGES * PAGE_SIZE]; 1584611d87fSMatthew Dillon } __packed; 159fc921477SMatthew Dillon 16039923942SSimon Schubert #define mdcpu ((struct mdglobaldata *)_get_mycpu()) 161fc921477SMatthew Dillon #define pscpu ((struct privatespace *)_get_mycpu()) 16239923942SSimon Schubert 16339923942SSimon Schubert #endif 16439923942SSimon Schubert 16539923942SSimon Schubert #ifdef _KERNEL 16639923942SSimon Schubert 1674864d541SMatthew Dillon extern struct privatespace *CPU_prvspace[]; 16839923942SSimon Schubert 16939923942SSimon Schubert #endif 17039923942SSimon Schubert 17139923942SSimon Schubert #endif 172