~ubuntu-branches/ubuntu/trusty/linux-linaro-omap/trusty

« back to all changes in this revision

Viewing changes to arch/x86/include/asm/desc.h

  • Committer: Package Import Robot
  • Author(s): John Rigby, John Rigby
  • Date: 2011-09-26 10:44:23 UTC
  • Revision ID: package-import@ubuntu.com-20110926104423-57i0gl3v99b3lkfg
Tags: 3.0.0-1007.9
[ John Rigby ]

Enable crypto modules and remove crypto-modules from
exclude-module files
LP: #826021

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
#include <asm/desc_defs.h>
5
5
#include <asm/ldt.h>
6
6
#include <asm/mmu.h>
 
7
 
7
8
#include <linux/smp.h>
8
9
#include <linux/mm_types.h>
9
10
 
10
 
static inline void fill_ldt(struct desc_struct *desc,
11
 
                            const struct user_desc *info)
 
11
static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *info)
12
12
{
13
 
        desc->limit0 = info->limit & 0x0ffff;
14
 
        desc->base0 = info->base_addr & 0x0000ffff;
15
 
 
16
 
        desc->base1 = (info->base_addr & 0x00ff0000) >> 16;
17
 
        desc->type = (info->read_exec_only ^ 1) << 1;
18
 
        desc->type |= info->contents << 2;
19
 
        desc->s = 1;
20
 
        desc->dpl = 0x3;
21
 
        desc->p = info->seg_not_present ^ 1;
22
 
        desc->limit = (info->limit & 0xf0000) >> 16;
23
 
        desc->avl = info->useable;
24
 
        desc->d = info->seg_32bit;
25
 
        desc->g = info->limit_in_pages;
26
 
        desc->base2 = (info->base_addr & 0xff000000) >> 24;
 
13
        desc->limit0            = info->limit & 0x0ffff;
 
14
 
 
15
        desc->base0             = (info->base_addr & 0x0000ffff);
 
16
        desc->base1             = (info->base_addr & 0x00ff0000) >> 16;
 
17
 
 
18
        desc->type              = (info->read_exec_only ^ 1) << 1;
 
19
        desc->type             |= info->contents << 2;
 
20
 
 
21
        desc->s                 = 1;
 
22
        desc->dpl               = 0x3;
 
23
        desc->p                 = info->seg_not_present ^ 1;
 
24
        desc->limit             = (info->limit & 0xf0000) >> 16;
 
25
        desc->avl               = info->useable;
 
26
        desc->d                 = info->seg_32bit;
 
27
        desc->g                 = info->limit_in_pages;
 
28
 
 
29
        desc->base2             = (info->base_addr & 0xff000000) >> 24;
27
30
        /*
28
31
         * Don't allow setting of the lm bit. It is useless anyway
29
32
         * because 64bit system calls require __USER_CS:
30
33
         */
31
 
        desc->l = 0;
 
34
        desc->l                 = 0;
32
35
}
33
36
 
34
37
extern struct desc_ptr idt_descr;
37
40
struct gdt_page {
38
41
        struct desc_struct gdt[GDT_ENTRIES];
39
42
} __attribute__((aligned(PAGE_SIZE)));
 
43
 
40
44
DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
41
45
 
42
46
static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
49
53
static inline void pack_gate(gate_desc *gate, unsigned type, unsigned long func,
50
54
                             unsigned dpl, unsigned ist, unsigned seg)
51
55
{
52
 
        gate->offset_low = PTR_LOW(func);
53
 
        gate->segment = __KERNEL_CS;
54
 
        gate->ist = ist;
55
 
        gate->p = 1;
56
 
        gate->dpl = dpl;
57
 
        gate->zero0 = 0;
58
 
        gate->zero1 = 0;
59
 
        gate->type = type;
60
 
        gate->offset_middle = PTR_MIDDLE(func);
61
 
        gate->offset_high = PTR_HIGH(func);
 
56
        gate->offset_low        = PTR_LOW(func);
 
57
        gate->segment           = __KERNEL_CS;
 
58
        gate->ist               = ist;
 
59
        gate->p                 = 1;
 
60
        gate->dpl               = dpl;
 
61
        gate->zero0             = 0;
 
62
        gate->zero1             = 0;
 
63
        gate->type              = type;
 
64
        gate->offset_middle     = PTR_MIDDLE(func);
 
65
        gate->offset_high       = PTR_HIGH(func);
62
66
}
63
67
 
64
68
#else
67
71
                             unsigned short seg)
68
72
{
69
73
        gate->a = (seg << 16) | (base & 0xffff);
70
 
        gate->b = (base & 0xffff0000) |
71
 
                  (((0x80 | type | (dpl << 5)) & 0xff) << 8);
 
74
        gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
72
75
}
73
76
 
74
77
#endif
76
79
static inline int desc_empty(const void *ptr)
77
80
{
78
81
        const u32 *desc = ptr;
 
82
 
79
83
        return !(desc[0] | desc[1]);
80
84
}
81
85
 
82
86
#ifdef CONFIG_PARAVIRT
83
87
#include <asm/paravirt.h>
84
88
#else
85
 
#define load_TR_desc() native_load_tr_desc()
86
 
#define load_gdt(dtr) native_load_gdt(dtr)
87
 
#define load_idt(dtr) native_load_idt(dtr)
88
 
#define load_tr(tr) asm volatile("ltr %0"::"m" (tr))
89
 
#define load_ldt(ldt) asm volatile("lldt %0"::"m" (ldt))
90
 
 
91
 
#define store_gdt(dtr) native_store_gdt(dtr)
92
 
#define store_idt(dtr) native_store_idt(dtr)
93
 
#define store_tr(tr) (tr = native_store_tr())
94
 
 
95
 
#define load_TLS(t, cpu) native_load_tls(t, cpu)
96
 
#define set_ldt native_set_ldt
 
89
#define load_TR_desc()                          native_load_tr_desc()
 
90
#define load_gdt(dtr)                           native_load_gdt(dtr)
 
91
#define load_idt(dtr)                           native_load_idt(dtr)
 
92
#define load_tr(tr)                             asm volatile("ltr %0"::"m" (tr))
 
93
#define load_ldt(ldt)                           asm volatile("lldt %0"::"m" (ldt))
 
94
 
 
95
#define store_gdt(dtr)                          native_store_gdt(dtr)
 
96
#define store_idt(dtr)                          native_store_idt(dtr)
 
97
#define store_tr(tr)                            (tr = native_store_tr())
 
98
 
 
99
#define load_TLS(t, cpu)                        native_load_tls(t, cpu)
 
100
#define set_ldt                                 native_set_ldt
 
101
 
97
102
#ifdef CONFIG_X86_32
98
 
#define load_user_cs_desc native_load_user_cs_desc
 
103
#define load_user_cs_desc                       native_load_user_cs_desc
99
104
#endif /*CONFIG_X86_32*/
100
105
 
101
 
#define write_ldt_entry(dt, entry, desc)        \
102
 
        native_write_ldt_entry(dt, entry, desc)
103
 
#define write_gdt_entry(dt, entry, desc, type)          \
104
 
        native_write_gdt_entry(dt, entry, desc, type)
105
 
#define write_idt_entry(dt, entry, g)           \
106
 
        native_write_idt_entry(dt, entry, g)
 
106
#define write_ldt_entry(dt, entry, desc)        native_write_ldt_entry(dt, entry, desc)
 
107
#define write_gdt_entry(dt, entry, desc, type)  native_write_gdt_entry(dt, entry, desc, type)
 
108
#define write_idt_entry(dt, entry, g)           native_write_idt_entry(dt, entry, g)
107
109
 
108
110
static inline void paravirt_alloc_ldt(struct desc_struct *ldt, unsigned entries)
109
111
{
116
118
 
117
119
#define store_ldt(ldt) asm("sldt %0" : "=m"(ldt))
118
120
 
119
 
static inline void native_write_idt_entry(gate_desc *idt, int entry,
120
 
                                          const gate_desc *gate)
 
121
static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
121
122
{
122
123
        memcpy(&idt[entry], gate, sizeof(*gate));
123
124
}
124
125
 
125
 
static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry,
126
 
                                          const void *desc)
 
126
static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
127
127
{
128
128
        memcpy(&ldt[entry], desc, 8);
129
129
}
130
130
 
131
 
static inline void native_write_gdt_entry(struct desc_struct *gdt, int entry,
132
 
                                          const void *desc, int type)
 
131
static inline void
 
132
native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int type)
133
133
{
134
134
        unsigned int size;
 
135
 
135
136
        switch (type) {
136
 
        case DESC_TSS:
137
 
                size = sizeof(tss_desc);
138
 
                break;
139
 
        case DESC_LDT:
140
 
                size = sizeof(ldt_desc);
141
 
                break;
142
 
        default:
143
 
                size = sizeof(struct desc_struct);
144
 
                break;
 
137
        case DESC_TSS:  size = sizeof(tss_desc);        break;
 
138
        case DESC_LDT:  size = sizeof(ldt_desc);        break;
 
139
        default:        size = sizeof(*gdt);            break;
145
140
        }
 
141
 
146
142
        memcpy(&gdt[entry], desc, size);
147
143
}
148
144
 
158
154
}
159
155
 
160
156
 
161
 
static inline void set_tssldt_descriptor(void *d, unsigned long addr,
162
 
                                         unsigned type, unsigned size)
 
157
static inline void set_tssldt_descriptor(void *d, unsigned long addr, unsigned type, unsigned size)
163
158
{
164
159
#ifdef CONFIG_X86_64
165
160
        struct ldttss_desc64 *desc = d;
 
161
 
166
162
        memset(desc, 0, sizeof(*desc));
167
 
        desc->limit0 = size & 0xFFFF;
168
 
        desc->base0 = PTR_LOW(addr);
169
 
        desc->base1 = PTR_MIDDLE(addr) & 0xFF;
170
 
        desc->type = type;
171
 
        desc->p = 1;
172
 
        desc->limit1 = (size >> 16) & 0xF;
173
 
        desc->base2 = (PTR_MIDDLE(addr) >> 8) & 0xFF;
174
 
        desc->base3 = PTR_HIGH(addr);
 
163
 
 
164
        desc->limit0            = size & 0xFFFF;
 
165
        desc->base0             = PTR_LOW(addr);
 
166
        desc->base1             = PTR_MIDDLE(addr) & 0xFF;
 
167
        desc->type              = type;
 
168
        desc->p                 = 1;
 
169
        desc->limit1            = (size >> 16) & 0xF;
 
170
        desc->base2             = (PTR_MIDDLE(addr) >> 8) & 0xFF;
 
171
        desc->base3             = PTR_HIGH(addr);
175
172
#else
176
173
        pack_descriptor((struct desc_struct *)d, addr, size, 0x80 | type, 0);
177
174
#endif
241
238
static inline unsigned long native_store_tr(void)
242
239
{
243
240
        unsigned long tr;
 
241
 
244
242
        asm volatile("str %0":"=r" (tr));
 
243
 
245
244
        return tr;
246
245
}
247
246
 
248
247
static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
249
248
{
 
249
        struct desc_struct *gdt = get_cpu_gdt_table(cpu);
250
250
        unsigned int i;
251
 
        struct desc_struct *gdt = get_cpu_gdt_table(cpu);
252
251
 
253
252
        for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
254
253
                gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
317
316
                             unsigned dpl, unsigned ist, unsigned seg)
318
317
{
319
318
        gate_desc s;
 
319
 
320
320
        pack_gate(&s, type, (unsigned long)addr, dpl, ist, seg);
321
321
        /*
322
322
         * does not need to be atomic because it is only done once at
347
347
                set_bit(vector, used_vectors);
348
348
                if (first_system_vector > vector)
349
349
                        first_system_vector = vector;
350
 
        } else
 
350
        } else {
351
351
                BUG();
 
352
        }
352
353
}
353
354
 
354
355
static inline void alloc_intr_gate(unsigned int n, void *addr)