aboutsummaryrefslogtreecommitdiffstats
path: root/include/asm-x86
diff options
context:
space:
mode:
authorGlauber de Oliveira Costa <gcosta@redhat.com>2008-01-30 07:31:14 -0500
committerIngo Molnar <mingo@elte.hu>2008-01-30 07:31:14 -0500
commit881c2975d02b6575c417a6eee40868d60a9ecba9 (patch)
tree402785bef46e3051aca5d006eaddbf0b99aff502 /include/asm-x86
parent59fbed775aa5a6f352bfbde6b40508b541086b7e (diff)
x86: unify non-paravirt parts of desc.h
This patch unifies the non-paravirt part of desc_{32,64}.h into desc.h. Most of it, is simply common code, that is moved to the shared header. The only exception is the set_ldt_desc in desc_64.h, which is changed - included its name - to accomodate for the way the ldt is set up in i386. Also, constant definitions used in desc_32.h are moved to desc_defs.h Signed-off-by: Glauber de Oliveira Costa <gcosta@redhat.com> Signed-off-by: Ingo Molnar <mingo@elte.hu> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'include/asm-x86')
-rw-r--r--include/asm-x86/desc.h65
-rw-r--r--include/asm-x86/desc_32.h58
-rw-r--r--include/asm-x86/desc_64.h55
-rw-r--r--include/asm-x86/mmu_context_64.h4
4 files changed, 76 insertions, 106 deletions
diff --git a/include/asm-x86/desc.h b/include/asm-x86/desc.h
index 47086d2d9298..99c4adc851e2 100644
--- a/include/asm-x86/desc.h
+++ b/include/asm-x86/desc.h
@@ -4,6 +4,7 @@
4#ifndef __ASSEMBLY__ 4#ifndef __ASSEMBLY__
5#include <asm/desc_defs.h> 5#include <asm/desc_defs.h>
6#include <asm/ldt.h> 6#include <asm/ldt.h>
7#include <asm/mmu.h>
7 8
8static inline void fill_ldt(struct desc_struct *desc, struct user_desc *info) 9static inline void fill_ldt(struct desc_struct *desc, struct user_desc *info)
9{ 10{
@@ -23,7 +24,8 @@ static inline void fill_ldt(struct desc_struct *desc, struct user_desc *info)
23 desc->base2 = (info->base_addr & 0xff000000) >> 24; 24 desc->base2 = (info->base_addr & 0xff000000) >> 24;
24} 25}
25 26
26#endif 27extern struct desc_ptr idt_descr;
28extern gate_desc idt_table[];
27 29
28#ifdef CONFIG_X86_32 30#ifdef CONFIG_X86_32
29# include "desc_32.h" 31# include "desc_32.h"
@@ -31,4 +33,65 @@ static inline void fill_ldt(struct desc_struct *desc, struct user_desc *info)
31# include "desc_64.h" 33# include "desc_64.h"
32#endif 34#endif
33 35
36#define _LDT_empty(info) (\
37 (info)->base_addr == 0 && \
38 (info)->limit == 0 && \
39 (info)->contents == 0 && \
40 (info)->read_exec_only == 1 && \
41 (info)->seg_32bit == 0 && \
42 (info)->limit_in_pages == 0 && \
43 (info)->seg_not_present == 1 && \
44 (info)->useable == 0)
45
46#ifdef CONFIG_X86_64
47#define LDT_empty(info) (_LDT_empty(info) && ((info)->lm == 0))
48#else
49#define LDT_empty(info) (_LDT_empty(info))
50#endif
51
52static inline void clear_LDT(void)
53{
54 set_ldt(NULL, 0);
55}
56
57/*
58 * load one particular LDT into the current CPU
59 */
60static inline void load_LDT_nolock(mm_context_t *pc)
61{
62 set_ldt(pc->ldt, pc->size);
63}
64
65static inline void load_LDT(mm_context_t *pc)
66{
67 preempt_disable();
68 load_LDT_nolock(pc);
69 preempt_enable();
70}
71
72#else
73/*
74 * GET_DESC_BASE reads the descriptor base of the specified segment.
75 *
76 * Args:
77 * idx - descriptor index
78 * gdt - GDT pointer
79 * base - 32bit register to which the base will be written
80 * lo_w - lo word of the "base" register
81 * lo_b - lo byte of the "base" register
82 * hi_b - hi byte of the low word of the "base" register
83 *
84 * Example:
85 * GET_DESC_BASE(GDT_ENTRY_ESPFIX_SS, %ebx, %eax, %ax, %al, %ah)
86 * Will read the base address of GDT_ENTRY_ESPFIX_SS and put it into %eax.
87 */
88#define GET_DESC_BASE(idx, gdt, base, lo_w, lo_b, hi_b) \
89 movb idx*8+4(gdt), lo_b; \
90 movb idx*8+7(gdt), hi_b; \
91 shll $16, base; \
92 movw idx*8+2(gdt), lo_w;
93
94
95#endif /* __ASSEMBLY__ */
96
34#endif 97#endif
diff --git a/include/asm-x86/desc_32.h b/include/asm-x86/desc_32.h
index 14238df87c7d..01415ad35fdf 100644
--- a/include/asm-x86/desc_32.h
+++ b/include/asm-x86/desc_32.h
@@ -11,8 +11,6 @@
11#include <linux/smp.h> 11#include <linux/smp.h>
12#include <linux/percpu.h> 12#include <linux/percpu.h>
13 13
14#include <asm/mmu.h>
15
16struct gdt_page 14struct gdt_page
17{ 15{
18 struct desc_struct gdt[GDT_ENTRIES]; 16 struct desc_struct gdt[GDT_ENTRIES];
@@ -24,8 +22,6 @@ static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
24 return per_cpu(gdt_page, cpu).gdt; 22 return per_cpu(gdt_page, cpu).gdt;
25} 23}
26 24
27extern struct desc_ptr idt_descr;
28extern gate_desc idt_table[];
29extern void set_intr_gate(unsigned int irq, void * addr); 25extern void set_intr_gate(unsigned int irq, void * addr);
30 26
31static inline void pack_descriptor(struct desc_struct *desc, 27static inline void pack_descriptor(struct desc_struct *desc,
@@ -172,36 +168,6 @@ static inline void __set_tss_desc(unsigned int cpu, unsigned int entry, const vo
172 168
173#define set_tss_desc(cpu,addr) __set_tss_desc(cpu, GDT_ENTRY_TSS, addr) 169#define set_tss_desc(cpu,addr) __set_tss_desc(cpu, GDT_ENTRY_TSS, addr)
174 170
175#define LDT_empty(info) (\
176 (info)->base_addr == 0 && \
177 (info)->limit == 0 && \
178 (info)->contents == 0 && \
179 (info)->read_exec_only == 1 && \
180 (info)->seg_32bit == 0 && \
181 (info)->limit_in_pages == 0 && \
182 (info)->seg_not_present == 1 && \
183 (info)->useable == 0 )
184
185static inline void clear_LDT(void)
186{
187 set_ldt(NULL, 0);
188}
189
190/*
191 * load one particular LDT into the current CPU
192 */
193static inline void load_LDT_nolock(mm_context_t *pc)
194{
195 set_ldt(pc->ldt, pc->size);
196}
197
198static inline void load_LDT(mm_context_t *pc)
199{
200 preempt_disable();
201 load_LDT_nolock(pc);
202 preempt_enable();
203}
204
205static inline unsigned long get_desc_base(unsigned long *desc) 171static inline unsigned long get_desc_base(unsigned long *desc)
206{ 172{
207 unsigned long base; 173 unsigned long base;
@@ -210,30 +176,6 @@ static inline unsigned long get_desc_base(unsigned long *desc)
210 (desc[1] & 0xff000000); 176 (desc[1] & 0xff000000);
211 return base; 177 return base;
212} 178}
213
214#else /* __ASSEMBLY__ */
215
216/*
217 * GET_DESC_BASE reads the descriptor base of the specified segment.
218 *
219 * Args:
220 * idx - descriptor index
221 * gdt - GDT pointer
222 * base - 32bit register to which the base will be written
223 * lo_w - lo word of the "base" register
224 * lo_b - lo byte of the "base" register
225 * hi_b - hi byte of the low word of the "base" register
226 *
227 * Example:
228 * GET_DESC_BASE(GDT_ENTRY_ESPFIX_SS, %ebx, %eax, %ax, %al, %ah)
229 * Will read the base address of GDT_ENTRY_ESPFIX_SS and put it into %eax.
230 */
231#define GET_DESC_BASE(idx, gdt, base, lo_w, lo_b, hi_b) \
232 movb idx*8+4(gdt), lo_b; \
233 movb idx*8+7(gdt), hi_b; \
234 shll $16, base; \
235 movw idx*8+2(gdt), lo_w;
236
237#endif /* !__ASSEMBLY__ */ 179#endif /* !__ASSEMBLY__ */
238 180
239#endif 181#endif
diff --git a/include/asm-x86/desc_64.h b/include/asm-x86/desc_64.h
index 7cdd3f0420fd..c037c7d55b92 100644
--- a/include/asm-x86/desc_64.h
+++ b/include/asm-x86/desc_64.h
@@ -9,16 +9,13 @@
9 9
10#include <linux/string.h> 10#include <linux/string.h>
11#include <linux/smp.h> 11#include <linux/smp.h>
12#include <asm/desc_defs.h>
13 12
14#include <asm/segment.h> 13#include <asm/segment.h>
15#include <asm/mmu.h>
16 14
17extern struct desc_struct cpu_gdt_table[GDT_ENTRIES]; 15extern struct desc_struct cpu_gdt_table[GDT_ENTRIES];
18 16
19#define load_TR_desc() asm volatile("ltr %w0"::"r" (GDT_ENTRY_TSS*8)) 17#define load_TR_desc() asm volatile("ltr %w0"::"r" (GDT_ENTRY_TSS*8))
20#define load_LDT_desc() asm volatile("lldt %w0"::"r" (GDT_ENTRY_LDT*8)) 18#define load_LDT_desc() asm volatile("lldt %w0"::"r" (GDT_ENTRY_LDT*8))
21#define clear_LDT() asm volatile("lldt %w0"::"r" (0))
22 19
23static inline unsigned long __store_tr(void) 20static inline unsigned long __store_tr(void)
24{ 21{
@@ -30,7 +27,6 @@ static inline unsigned long __store_tr(void)
30 27
31#define store_tr(tr) (tr) = __store_tr() 28#define store_tr(tr) (tr) = __store_tr()
32 29
33extern gate_desc idt_table[];
34extern struct desc_ptr cpu_gdt_descr[]; 30extern struct desc_ptr cpu_gdt_descr[];
35 31
36static inline void write_ldt_entry(struct desc_struct *ldt, 32static inline void write_ldt_entry(struct desc_struct *ldt,
@@ -138,22 +134,18 @@ static inline void set_tss_desc(unsigned cpu, void *addr)
138 IO_BITMAP_OFFSET + IO_BITMAP_BYTES + sizeof(unsigned long) - 1); 134 IO_BITMAP_OFFSET + IO_BITMAP_BYTES + sizeof(unsigned long) - 1);
139} 135}
140 136
141static inline void set_ldt_desc(unsigned cpu, void *addr, int size) 137static inline void set_ldt(void *addr, int entries)
142{ 138{
143 set_tssldt_descriptor(&get_cpu_gdt_table(cpu)[GDT_ENTRY_LDT], 139 if (likely(entries == 0))
144 (unsigned long)addr, DESC_LDT, size * 8 - 1); 140 __asm__ __volatile__("lldt %w0"::"q" (0));
145} 141 else {
142 unsigned cpu = smp_processor_id();
146 143
147#define LDT_empty(info) (\ 144 set_tssldt_descriptor(&get_cpu_gdt_table(cpu)[GDT_ENTRY_LDT],
148 (info)->base_addr == 0 && \ 145 (unsigned long)addr, DESC_LDT, entries * 8 - 1);
149 (info)->limit == 0 && \ 146 __asm__ __volatile__("lldt %w0"::"q" (GDT_ENTRY_LDT*8));
150 (info)->contents == 0 && \ 147 }
151 (info)->read_exec_only == 1 && \ 148}
152 (info)->seg_32bit == 0 && \
153 (info)->limit_in_pages == 0 && \
154 (info)->seg_not_present == 1 && \
155 (info)->useable == 0 && \
156 (info)->lm == 0)
157 149
158static inline void load_TLS(struct thread_struct *t, unsigned int cpu) 150static inline void load_TLS(struct thread_struct *t, unsigned int cpu)
159{ 151{
@@ -164,32 +156,6 @@ static inline void load_TLS(struct thread_struct *t, unsigned int cpu)
164 gdt[i] = t->tls_array[i]; 156 gdt[i] = t->tls_array[i];
165} 157}
166 158
167/*
168 * load one particular LDT into the current CPU
169 */
170static inline void load_LDT_nolock(mm_context_t *pc, int cpu)
171{
172 int count = pc->size;
173
174 if (likely(!count)) {
175 clear_LDT();
176 return;
177 }
178
179 set_ldt_desc(cpu, pc->ldt, count);
180 load_LDT_desc();
181}
182
183static inline void load_LDT(mm_context_t *pc)
184{
185 int cpu = get_cpu();
186
187 load_LDT_nolock(pc, cpu);
188 put_cpu();
189}
190
191extern struct desc_ptr idt_descr;
192
193static inline unsigned long get_desc_base(const void *ptr) 159static inline unsigned long get_desc_base(const void *ptr)
194{ 160{
195 const u32 *desc = ptr; 161 const u32 *desc = ptr;
@@ -199,7 +165,6 @@ static inline unsigned long get_desc_base(const void *ptr)
199 (desc[1] & 0xff000000); 165 (desc[1] & 0xff000000);
200 return base; 166 return base;
201} 167}
202
203#endif /* !__ASSEMBLY__ */ 168#endif /* !__ASSEMBLY__ */
204 169
205#endif 170#endif
diff --git a/include/asm-x86/mmu_context_64.h b/include/asm-x86/mmu_context_64.h
index 29f95c3acc28..98bfe43dd806 100644
--- a/include/asm-x86/mmu_context_64.h
+++ b/include/asm-x86/mmu_context_64.h
@@ -43,7 +43,7 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
43 load_cr3(next->pgd); 43 load_cr3(next->pgd);
44 44
45 if (unlikely(next->context.ldt != prev->context.ldt)) 45 if (unlikely(next->context.ldt != prev->context.ldt))
46 load_LDT_nolock(&next->context, cpu); 46 load_LDT_nolock(&next->context);
47 } 47 }
48#ifdef CONFIG_SMP 48#ifdef CONFIG_SMP
49 else { 49 else {
@@ -56,7 +56,7 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
56 * to make sure to use no freed page tables. 56 * to make sure to use no freed page tables.
57 */ 57 */
58 load_cr3(next->pgd); 58 load_cr3(next->pgd);
59 load_LDT_nolock(&next->context, cpu); 59 load_LDT_nolock(&next->context);
60 } 60 }
61 } 61 }
62#endif 62#endif