V4L/DVB (6715): ivtv: Remove unnecessary register update
[linux-2.6/verdex.git] / include / asm-x86 / desc_64.h
blob7d9c938e69fd296d1e493565fc2e4dca0265b291
1 /* Written 2000 by Andi Kleen */
2 #ifndef __ARCH_DESC_H
3 #define __ARCH_DESC_H
5 #include <linux/threads.h>
6 #include <asm/ldt.h>
8 #ifndef __ASSEMBLY__
10 #include <linux/string.h>
11 #include <linux/smp.h>
12 #include <asm/desc_defs.h>
14 #include <asm/segment.h>
15 #include <asm/mmu.h>
17 extern struct desc_struct cpu_gdt_table[GDT_ENTRIES];
19 #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))
21 #define clear_LDT() asm volatile("lldt %w0"::"r" (0))
23 static inline unsigned long __store_tr(void)
25 unsigned long tr;
27 asm volatile ("str %w0":"=r" (tr));
28 return tr;
31 #define store_tr(tr) (tr) = __store_tr()
34 * This is the ldt that every process will get unless we need
35 * something other than this.
37 extern struct desc_struct default_ldt[];
38 extern struct gate_struct idt_table[];
39 extern struct desc_ptr cpu_gdt_descr[];
41 /* the cpu gdt accessor */
42 #define cpu_gdt(_cpu) ((struct desc_struct *)cpu_gdt_descr[_cpu].address)
44 static inline void load_gdt(const struct desc_ptr *ptr)
46 asm volatile("lgdt %w0"::"m" (*ptr));
49 static inline void store_gdt(struct desc_ptr *ptr)
51 asm("sgdt %w0":"=m" (*ptr));
54 static inline void _set_gate(void *adr, unsigned type, unsigned long func, unsigned dpl, unsigned ist)
56 struct gate_struct s;
57 s.offset_low = PTR_LOW(func);
58 s.segment = __KERNEL_CS;
59 s.ist = ist;
60 s.p = 1;
61 s.dpl = dpl;
62 s.zero0 = 0;
63 s.zero1 = 0;
64 s.type = type;
65 s.offset_middle = PTR_MIDDLE(func);
66 s.offset_high = PTR_HIGH(func);
67 /* does not need to be atomic because it is only done once at setup time */
68 memcpy(adr, &s, 16);
71 static inline void set_intr_gate(int nr, void *func)
73 BUG_ON((unsigned)nr > 0xFF);
74 _set_gate(&idt_table[nr], GATE_INTERRUPT, (unsigned long) func, 0, 0);
77 static inline void set_intr_gate_ist(int nr, void *func, unsigned ist)
79 BUG_ON((unsigned)nr > 0xFF);
80 _set_gate(&idt_table[nr], GATE_INTERRUPT, (unsigned long) func, 0, ist);
83 static inline void set_system_gate(int nr, void *func)
85 BUG_ON((unsigned)nr > 0xFF);
86 _set_gate(&idt_table[nr], GATE_INTERRUPT, (unsigned long) func, 3, 0);
89 static inline void set_system_gate_ist(int nr, void *func, unsigned ist)
91 _set_gate(&idt_table[nr], GATE_INTERRUPT, (unsigned long) func, 3, ist);
94 static inline void load_idt(const struct desc_ptr *ptr)
96 asm volatile("lidt %w0"::"m" (*ptr));
99 static inline void store_idt(struct desc_ptr *dtr)
101 asm("sidt %w0":"=m" (*dtr));
104 static inline void set_tssldt_descriptor(void *ptr, unsigned long tss, unsigned type,
105 unsigned size)
107 struct ldttss_desc d;
108 memset(&d,0,sizeof(d));
109 d.limit0 = size & 0xFFFF;
110 d.base0 = PTR_LOW(tss);
111 d.base1 = PTR_MIDDLE(tss) & 0xFF;
112 d.type = type;
113 d.p = 1;
114 d.limit1 = (size >> 16) & 0xF;
115 d.base2 = (PTR_MIDDLE(tss) >> 8) & 0xFF;
116 d.base3 = PTR_HIGH(tss);
117 memcpy(ptr, &d, 16);
120 static inline void set_tss_desc(unsigned cpu, void *addr)
123 * sizeof(unsigned long) coming from an extra "long" at the end
124 * of the iobitmap. See tss_struct definition in processor.h
126 * -1? seg base+limit should be pointing to the address of the
127 * last valid byte
129 set_tssldt_descriptor(&cpu_gdt(cpu)[GDT_ENTRY_TSS],
130 (unsigned long)addr, DESC_TSS,
131 IO_BITMAP_OFFSET + IO_BITMAP_BYTES + sizeof(unsigned long) - 1);
134 static inline void set_ldt_desc(unsigned cpu, void *addr, int size)
136 set_tssldt_descriptor(&cpu_gdt(cpu)[GDT_ENTRY_LDT], (unsigned long)addr,
137 DESC_LDT, size * 8 - 1);
140 #define LDT_entry_a(info) \
141 ((((info)->base_addr & 0x0000ffff) << 16) | ((info)->limit & 0x0ffff))
142 /* Don't allow setting of the lm bit. It is useless anyways because
143 64bit system calls require __USER_CS. */
144 #define LDT_entry_b(info) \
145 (((info)->base_addr & 0xff000000) | \
146 (((info)->base_addr & 0x00ff0000) >> 16) | \
147 ((info)->limit & 0xf0000) | \
148 (((info)->read_exec_only ^ 1) << 9) | \
149 ((info)->contents << 10) | \
150 (((info)->seg_not_present ^ 1) << 15) | \
151 ((info)->seg_32bit << 22) | \
152 ((info)->limit_in_pages << 23) | \
153 ((info)->useable << 20) | \
154 /* ((info)->lm << 21) | */ \
155 0x7000)
157 #define LDT_empty(info) (\
158 (info)->base_addr == 0 && \
159 (info)->limit == 0 && \
160 (info)->contents == 0 && \
161 (info)->read_exec_only == 1 && \
162 (info)->seg_32bit == 0 && \
163 (info)->limit_in_pages == 0 && \
164 (info)->seg_not_present == 1 && \
165 (info)->useable == 0 && \
166 (info)->lm == 0)
168 static inline void load_TLS(struct thread_struct *t, unsigned int cpu)
170 unsigned int i;
171 u64 *gdt = (u64 *)(cpu_gdt(cpu) + GDT_ENTRY_TLS_MIN);
173 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
174 gdt[i] = t->tls_array[i];
178 * load one particular LDT into the current CPU
180 static inline void load_LDT_nolock (mm_context_t *pc, int cpu)
182 int count = pc->size;
184 if (likely(!count)) {
185 clear_LDT();
186 return;
189 set_ldt_desc(cpu, pc->ldt, count);
190 load_LDT_desc();
193 static inline void load_LDT(mm_context_t *pc)
195 int cpu = get_cpu();
196 load_LDT_nolock(pc, cpu);
197 put_cpu();
200 extern struct desc_ptr idt_descr;
202 #endif /* !__ASSEMBLY__ */
204 #endif