kernel - Fix lwbuf leak for i386
[dragonfly.git] / sys / platform / pc32 / include / globaldata.h
1 /*-
2  * Copyright (c) Peter Wemm <peter@netplex.com.au>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  *      Only machine-dependant code should ever include this file.  MI
27  *      code and header files do NOT include this file.  e.g. sys/globaldata.h
28  *      should not include this file.
29  *
30  * $FreeBSD: src/sys/i386/include/globaldata.h,v 1.11.2.1 2000/05/16 06:58:10 dillon Exp $
31  * $DragonFly: src/sys/platform/pc32/include/globaldata.h,v 1.29 2006/10/23 21:50:31 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 #ifndef _MACHINE_SEGMENTS_H_
46 #include <machine/segments.h>   /* struct segment_descriptor */
47 #endif
48 #ifndef _MACHINE_TSS_H_
49 #include <machine/tss.h>        /* struct i386tss */
50 #endif
51 #ifndef _MACHINE_NPX_H_
52 #include <machine/npx.h>
53 #endif
54 #ifndef _CPU_LWBUF_H_
55 #include <cpu/lwbuf.h>
56 #endif
57
58 /*
59  * Note on interrupt control.  Pending interrupts not yet dispatched are
60  * marked in gd_fpending or gd_spending.  Once dispatched the interrupt's
61  * pending bit is cleared and the interrupt is masked.  Upon completion
62  * the interrupt is unmasked.
63  *
64  * For edge triggered interrupts interrupts may be enabled again at this
65  * point and if they occur before the interrupt service routine is complete
66  * the service routine will loop.
67  *
68  * The current thread's cpl is stored in the thread structure.
69  *
70  * Note: the embedded globaldata and/or the mdglobaldata structure
71  * may exceed the size of a page.
72  */
73 struct mdglobaldata {
74         struct globaldata mi;
75         struct segment_descriptor gd_common_tssd;
76         struct segment_descriptor *gd_tss_gdt;
77         struct thread   *gd_npxthread;
78         struct i386tss  gd_common_tss;
79         struct lwbuf_list gd_lwbuf_fpages; /* lwbuf: free kva */
80         int             gd_lwbuf_count;
81         union savefpu   gd_savefpu;     /* fast bcopy/zero temp fpu save area */
82         int             gd_fpu_lock;    /* fast bcopy/zero cpu lock */
83         int             gd_fpending;    /* fast interrupt pending */
84         int             unused002;
85         int             gd_spending;    /* software interrupt pending */
86         int             gd_sdelayed;    /* delayed software ints */
87         int             gd_currentldt;
88         int             gd_private_tss;
89         u_int           unused001;
90         u_int           gd_other_cpus;
91         u_int           gd_ss_eflags;
92         pt_entry_t      *gd_CMAP1;
93         pt_entry_t      *gd_CMAP2;
94         pt_entry_t      *gd_CMAP3;
95         pt_entry_t      *gd_PMAP1;
96         pt_entry_t      *gd_GDMAP1;     /* per-cpu whole page table map */
97         caddr_t         gd_CADDR1;
98         caddr_t         gd_CADDR2;
99         caddr_t         gd_CADDR3;
100         unsigned        *gd_PADDR1;
101         unsigned        *gd_GDADDR1;    /* per-cpu whole page table map va */
102         u_int           gd_acpi_id;
103         u_int           gd_apic_id;
104 };
105
106 #define MDGLOBALDATA_BASEALLOC_SIZE     \
107         ((sizeof(struct mdglobaldata) + PAGE_MASK) & ~PAGE_MASK)
108 #define MDGLOBALDATA_BASEALLOC_PAGES    \
109         (MDGLOBALDATA_BASEALLOC_SIZE / PAGE_SIZE)
110 #define MDGLOBALDATA_PAD                \
111         (MDGLOBALDATA_BASEALLOC_SIZE - sizeof(struct mdglobaldata))
112
113 /*
114  * This is the upper (0xff800000) address space layout that is per-cpu.
115  * It is setup in locore.s and pmap.c for the BSP and in mp_machdep.c for
116  * each AP.  genassym helps export this to the assembler code.
117  *
118  * WARNING!  page-bounded fields and page table indexes are hardwired
119  * for SMPpt[] setup in i386/i386/mp_machdep.c and locore.s.
120  *
121  * WARNING!  sizeof(privatespace[SMP_MAXCPU]) must fit in the KVA
122  * reserved for the SMPpt page table (typically one page table page = 4MB).
123  *
124  * WARNING!  This structure must be a multiple of PAGE_SIZE.
125  */
126 struct privatespace {
127         /* main data page */
128         struct mdglobaldata mdglobaldata;
129         char            __filler0[MDGLOBALDATA_PAD];
130
131         /* mapping pages - CPAGE1,CPAGE2,CPAGE3,PPAGE1 */
132         char            CPAGE1[PAGE_SIZE];              /* SMPpt[n+0] */
133         char            CPAGE2[PAGE_SIZE];              /* SMPpt[n+1] */
134         char            CPAGE3[PAGE_SIZE];              /* SMPpt[n+2] */
135         char            PPAGE1[PAGE_SIZE];              /* SMPpt[n+3] */
136
137         /* idle stack (UPAGES pages) */
138         char            idlestack[UPAGES * PAGE_SIZE];  /* SMPpt[n+4] */
139 };
140 #define mdcpu           ((struct mdglobaldata *)_get_mycpu())
141
142 #endif
143
144 #ifdef _KERNEL
145
146 extern struct privatespace CPU_prvspace[];
147
148 #endif
149
150 #endif