xref: /dragonfly/sys/platform/pc64/include/globaldata.h (revision 31815141bcac6910dceb328608728c1824cd7ee5)
1 /*-
2  * Copyright (c) Peter Wemm <peter@netplex.com.au>
3  * Copyright (c) 2008 The DragonFly Project.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  *
27  *        Only machine-dependant code should ever include this file.  MI
28  *        code and header files do NOT include this file.  e.g. sys/globaldata.h
29  *        should not include this file.
30  *
31  * $FreeBSD: src/sys/i386/include/globaldata.h,v 1.11.2.1 2000/05/16 06:58:10 dillon Exp $
32  */
33 
34 #ifndef _MACHINE_GLOBALDATA_H_
35 #define _MACHINE_GLOBALDATA_H_
36 
37 #if defined(_KERNEL) || defined(_KERNEL_STRUCTURES)
38 
39 #ifndef _SYS_GLOBALDATA_H_
40 #include <sys/globaldata.h>   /* struct globaldata */
41 #endif
42 #ifndef _SYS_THREAD_H_
43 #include <sys/thread.h>                 /* struct thread */
44 #endif
45 #include <machine/segments.h> /* struct user_segment_descriptor */
46 #include <machine/tss.h>      /* struct x86_64tss */
47 #include <machine/npx.h>
48 
49 struct pv_entry;
50 
51 /*
52  * Note on interrupt control.  Pending interrupts not yet dispatched are
53  * marked in gd_fpending or gd_spending.  Once dispatched the interrupt's
54  * pending bit is cleared and the interrupt is masked.  Upon completion
55  * the interrupt is unmasked.
56  *
57  * For edge triggered interrupts interrupts may be enabled again at this
58  * point and if they occur before the interrupt service routine is complete
59  * the service routine will loop.
60  *
61  * The current thread's cpl is stored in the thread structure.
62  *
63  * Note: the embedded globaldata and/or the mdglobaldata structure
64  * may exceed the size of a page.
65  */
66 struct mdglobaldata {
67           struct globaldata mi;
68           struct user_segment_descriptor gd_common_tssd;
69           struct user_segment_descriptor *gd_tss_gdt;       /* gd_gdt[GPROC0_SEL] */
70           struct thread   *gd_npxthread;
71           union savefpu       gd_savefpu;         /* fast bcopy/zero temp fpu save area */
72           union savefpu       gd_zerofpu;         /* xrstor/fxrstor/frstor zero regs */
73           int                 gd_fpu_lock;        /* fast bcopy/zero cpu lock */
74           int                 gd_xinvaltlb;       /* reentrancy check invaltlb routine */
75           int                 gd_unused001;
76           int                 gd_spending;        /* software interrupt pending */
77           int                 gd_sdelayed;        /* delayed software ints */
78           int                 gd_currentldt;
79           int                 gd_private_tss;
80           u_int               gd_unused002;
81           u_int               gd_unused003;
82           u_int               gd_ss_eflags;
83           struct user_segment_descriptor *gd_gdt; /* pcpu gdt[] table */
84           long                gd_lunused1;
85           long                gd_lunused2;
86           long                gd_lunusde3;
87           caddr_t             gd_aunused0;
88           caddr_t             gd_aunused1;
89           caddr_t             gd_aunused2;
90           struct pv_entry     *gd_newpv;
91           u_int               gd_acpi_id;
92           u_int               gd_apic_id;
93           register_t          gd_unused004;
94           register_t          gd_unused005;
95           register_t          gd_user_fs;         /* current user fs in MSR */
96           register_t          gd_user_gs;         /* current user gs in MSR */
97           cpumask_t gd_unused006;
98           u_long              gd_ipending[3];
99 };
100 
101 #define MDGLOBALDATA_BASEALLOC_SIZE     \
102           ((sizeof(struct mdglobaldata) + PAGE_MASK) & ~PAGE_MASK)
103 #define MDGLOBALDATA_BASEALLOC_PAGES    \
104           (MDGLOBALDATA_BASEALLOC_SIZE / PAGE_SIZE)
105 #define MDGLOBALDATA_PAD                \
106           (MDGLOBALDATA_BASEALLOC_SIZE - sizeof(struct mdglobaldata))
107 
108 /*
109  * This is the upper (0xff800000) address space layout that is per-cpu.
110  * It is setup in locore.s and pmap.c for the BSP and in mp_machdep.c for
111  * each AP.  genassym helps export this to the assembler code.
112  *
113  * Most of the major elements in struct privatespace must be
114  * PAGE_SIZE aligned.
115  */
116 struct privatespace {
117           /*
118            * page 0 - data page
119            */
120           struct mdglobaldata mdglobaldata;
121           char                __filler0[MDGLOBALDATA_PAD];
122 
123           /*
124            * page 1 - Unused (unmapped)
125            */
126           char                unused2[PAGE_SIZE];
127 
128           /*
129            * page 2 - Trampoline page.  Put the trampoline and common_tss
130            *            in the same page to make them easier to isolate
131            *            from the rest of the kernel map.  See x86_64/pmap.c
132            *
133            *            rsp0 points into trampoline.  Interrupts are always
134            *            disabled for this case but leave reserved1[]
135            *            reserved just in case.
136            */
137           char                reserved1[PAGE_SIZE -
138                                           sizeof(struct trampframe) -
139                                           sizeof(uint64_t) -
140                                           sizeof(struct x86_64tss)];
141           struct trampframe trampoline;
142           uint64_t  reserved1b;         /* 16-byte-align trampoline */
143           struct x86_64tss common_tss;  /* (misaligned by 8 bytes) */
144 
145           /*
146            * page 3, 4 - NMI, Double fault stack
147            * page 5, 6 - Debug fault stack
148            */
149           char                dblstack[PAGE_SIZE * 2 -
150                                          sizeof(struct trampframe)];
151           struct trampframe dbltramp;
152           char                dbgstack[PAGE_SIZE * 2 -
153                                          sizeof(struct trampframe)];
154           struct trampframe dbgtramp;
155 
156           /* page 7+   - idle stack (UPAGES pages) */
157           char                idlestack[UPAGES * PAGE_SIZE];
158 } __packed;
159 
160 #define mdcpu                 ((struct mdglobaldata *)_get_mycpu())
161 #define pscpu                 ((struct privatespace *)_get_mycpu())
162 
163 #endif
164 
165 #ifdef _KERNEL
166 
167 extern struct privatespace *CPU_prvspace[];
168 
169 #endif
170 
171 #endif
172