aboutsummaryrefslogtreecommitdiffstats
path: root/include/asm-x86/desc_64.h
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
commit54cd0eac7286b83ef1a657d2dddd74e0556209e7 (patch)
treeaed1dfd42c1e66dff168387d9539e98dbe64c098 /include/asm-x86/desc_64.h
parentcc6978528cbd475d952e0eb5073375839dfb600e (diff)
x86: unify paravirt pieces of descriptor handling
With the types used to access descriptors in x86_64 and i386 now being the same, the code that effectively handles them can now be easily shared. This patch moves the paravirt part of desc_32.h into desc.h, and then, we get paravirt support in x86_64 for free. 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/desc_64.h')
-rw-r--r--include/asm-x86/desc_64.h104
1 files changed, 11 insertions, 93 deletions
diff --git a/include/asm-x86/desc_64.h b/include/asm-x86/desc_64.h
index a7a6c301c6b..b0290c45319 100644
--- a/include/asm-x86/desc_64.h
+++ b/include/asm-x86/desc_64.h
@@ -8,47 +8,10 @@
8#ifndef __ASSEMBLY__ 8#ifndef __ASSEMBLY__
9 9
10#include <linux/string.h> 10#include <linux/string.h>
11#include <linux/smp.h>
12 11
13#include <asm/segment.h> 12#include <asm/segment.h>
14 13
15extern struct desc_struct cpu_gdt_table[GDT_ENTRIES]; 14static inline void _set_gate(int gate, unsigned type, unsigned long func,
16
17#define load_TR_desc() asm volatile("ltr %w0"::"r" (GDT_ENTRY_TSS*8))
18#define load_LDT_desc() asm volatile("lldt %w0"::"r" (GDT_ENTRY_LDT*8))
19
20static inline unsigned long __store_tr(void)
21{
22 unsigned long tr;
23
24 asm volatile ("str %w0":"=r" (tr));
25 return tr;
26}
27
28#define store_tr(tr) (tr) = __store_tr()
29
30extern struct desc_ptr cpu_gdt_descr[];
31
32static inline void write_ldt_entry(struct desc_struct *ldt,
33 int entry, void *ptr)
34{
35 memcpy(&ldt[entry], ptr, 8);
36}
37
38/* the cpu gdt accessor */
39#define get_cpu_gdt_table(x) ((struct desc_struct *)cpu_gdt_descr[x].address)
40
41static inline void load_gdt(const struct desc_ptr *ptr)
42{
43 asm volatile("lgdt %w0"::"m" (*ptr));
44}
45
46static inline void store_gdt(struct desc_ptr *ptr)
47{
48 asm("sgdt %w0":"=m" (*ptr));
49}
50
51static inline void _set_gate(void *adr, unsigned type, unsigned long func,
52 unsigned dpl, unsigned ist) 15 unsigned dpl, unsigned ist)
53{ 16{
54 gate_desc s; 17 gate_desc s;
@@ -67,61 +30,37 @@ static inline void _set_gate(void *adr, unsigned type, unsigned long func,
67 * does not need to be atomic because it is only done once at 30 * does not need to be atomic because it is only done once at
68 * setup time 31 * setup time
69 */ 32 */
70 memcpy(adr, &s, 16); 33 write_idt_entry(idt_table, gate, &s);
71} 34}
72 35
73static inline void set_intr_gate(int nr, void *func) 36static inline void set_intr_gate(int nr, void *func)
74{ 37{
75 BUG_ON((unsigned)nr > 0xFF); 38 BUG_ON((unsigned)nr > 0xFF);
76 _set_gate(&idt_table[nr], GATE_INTERRUPT, (unsigned long) func, 0, 0); 39 _set_gate(nr, GATE_INTERRUPT, (unsigned long) func, 0, 0);
77} 40}
78 41
79static inline void set_intr_gate_ist(int nr, void *func, unsigned ist) 42static inline void set_intr_gate_ist(int nr, void *func, unsigned ist)
80{ 43{
81 BUG_ON((unsigned)nr > 0xFF); 44 BUG_ON((unsigned)nr > 0xFF);
82 _set_gate(&idt_table[nr], GATE_INTERRUPT, (unsigned long) func, 0, ist); 45 _set_gate(nr, GATE_INTERRUPT, (unsigned long) func, 0, ist);
83} 46}
84 47
85static inline void set_system_gate(int nr, void *func) 48static inline void set_system_gate(int nr, void *func)
86{ 49{
87 BUG_ON((unsigned)nr > 0xFF); 50 BUG_ON((unsigned)nr > 0xFF);
88 _set_gate(&idt_table[nr], GATE_INTERRUPT, (unsigned long) func, 3, 0); 51 _set_gate(nr, GATE_INTERRUPT, (unsigned long) func, 3, 0);
89} 52}
90 53
91static inline void set_system_gate_ist(int nr, void *func, unsigned ist) 54static inline void set_system_gate_ist(int nr, void *func, unsigned ist)
92{ 55{
93 _set_gate(&idt_table[nr], GATE_INTERRUPT, (unsigned long) func, 3, ist); 56 _set_gate(nr, GATE_INTERRUPT, (unsigned long) func, 3, ist);
94}
95
96static inline void load_idt(const struct desc_ptr *ptr)
97{
98 asm volatile("lidt %w0"::"m" (*ptr));
99}
100
101static inline void store_idt(struct desc_ptr *dtr)
102{
103 asm("sidt %w0":"=m" (*dtr));
104}
105
106static inline void set_tssldt_descriptor(void *ptr, unsigned long tss,
107 unsigned type, unsigned size)
108{
109 struct ldttss_desc64 d;
110
111 memset(&d, 0, sizeof(d));
112 d.limit0 = size & 0xFFFF;
113 d.base0 = PTR_LOW(tss);
114 d.base1 = PTR_MIDDLE(tss) & 0xFF;
115 d.type = type;
116 d.p = 1;
117 d.limit1 = (size >> 16) & 0xF;
118 d.base2 = (PTR_MIDDLE(tss) >> 8) & 0xFF;
119 d.base3 = PTR_HIGH(tss);
120 memcpy(ptr, &d, 16);
121} 57}
122 58
123static inline void set_tss_desc(unsigned cpu, void *addr) 59static inline void set_tss_desc(unsigned cpu, void *addr)
124{ 60{
61 struct desc_struct *d = get_cpu_gdt_table(cpu);
62 tss_desc tss;
63
125 /* 64 /*
126 * sizeof(unsigned long) coming from an extra "long" at the end 65 * sizeof(unsigned long) coming from an extra "long" at the end
127 * of the iobitmap. See tss_struct definition in processor.h 66 * of the iobitmap. See tss_struct definition in processor.h
@@ -129,31 +68,10 @@ static inline void set_tss_desc(unsigned cpu, void *addr)
129 * -1? seg base+limit should be pointing to the address of the 68 * -1? seg base+limit should be pointing to the address of the
130 * last valid byte 69 * last valid byte
131 */ 70 */
132 set_tssldt_descriptor(&get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS], 71 set_tssldt_descriptor(&tss,
133 (unsigned long)addr, DESC_TSS, 72 (unsigned long)addr, DESC_TSS,
134 IO_BITMAP_OFFSET + IO_BITMAP_BYTES + sizeof(unsigned long) - 1); 73 IO_BITMAP_OFFSET + IO_BITMAP_BYTES + sizeof(unsigned long) - 1);
135} 74 write_gdt_entry(d, GDT_ENTRY_TSS, &tss, DESC_TSS);
136
137static inline void set_ldt(void *addr, int entries)
138{
139 if (likely(entries == 0))
140 __asm__ __volatile__("lldt %w0"::"q" (0));
141 else {
142 unsigned cpu = smp_processor_id();
143
144 set_tssldt_descriptor(&get_cpu_gdt_table(cpu)[GDT_ENTRY_LDT],
145 (unsigned long)addr, DESC_LDT, entries * 8 - 1);
146 __asm__ __volatile__("lldt %w0"::"q" (GDT_ENTRY_LDT*8));
147 }
148}
149
150static inline void load_TLS(struct thread_struct *t, unsigned int cpu)
151{
152 unsigned int i;
153 struct desc_struct *gdt = (get_cpu_gdt_table(cpu) + GDT_ENTRY_TLS_MIN);
154
155 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
156 gdt[i] = t->tls_array[i];
157} 75}
158 76
159#endif /* !__ASSEMBLY__ */ 77#endif /* !__ASSEMBLY__ */