Merge master.kernel.org:/pub/scm/linux/kernel/git/davej/cpufreq
[pandora-kernel.git] / arch / i386 / power / cpu.c
1 /*
2  * Suspend support specific for i386.
3  *
4  * Distribute under GPLv2
5  *
6  * Copyright (c) 2002 Pavel Machek <pavel@suse.cz>
7  * Copyright (c) 2001 Patrick Mochel <mochel@osdl.org>
8  */
9
10 #include <linux/module.h>
11 #include <linux/suspend.h>
12 #include <asm/mtrr.h>
13 #include <asm/mce.h>
14
15 static struct saved_context saved_context;
16
17 unsigned long saved_context_ebx;
18 unsigned long saved_context_esp, saved_context_ebp;
19 unsigned long saved_context_esi, saved_context_edi;
20 unsigned long saved_context_eflags;
21
22 void __save_processor_state(struct saved_context *ctxt)
23 {
24         kernel_fpu_begin();
25
26         /*
27          * descriptor tables
28          */
29         store_gdt(&ctxt->gdt_limit);
30         store_idt(&ctxt->idt_limit);
31         store_tr(ctxt->tr);
32
33         /*
34          * segment registers
35          */
36         savesegment(es, ctxt->es);
37         savesegment(fs, ctxt->fs);
38         savesegment(gs, ctxt->gs);
39         savesegment(ss, ctxt->ss);
40
41         /*
42          * control registers 
43          */
44         ctxt->cr0 = read_cr0();
45         ctxt->cr2 = read_cr2();
46         ctxt->cr3 = read_cr3();
47         ctxt->cr4 = read_cr4();
48 }
49
50 void save_processor_state(void)
51 {
52         __save_processor_state(&saved_context);
53 }
54
55 static void do_fpu_end(void)
56 {
57         /*
58          * Restore FPU regs if necessary.
59          */
60         kernel_fpu_end();
61 }
62
63 static void fix_processor_context(void)
64 {
65         int cpu = smp_processor_id();
66         struct tss_struct * t = &per_cpu(init_tss, cpu);
67
68         set_tss_desc(cpu,t);    /* This just modifies memory; should not be necessary. But... This is necessary, because 386 hardware has concept of busy TSS or some similar stupidity. */
69
70         load_TR_desc();                         /* This does ltr */
71         load_LDT(&current->active_mm->context); /* This does lldt */
72
73         /*
74          * Now maybe reload the debug registers
75          */
76         if (current->thread.debugreg[7]){
77                 set_debugreg(current->thread.debugreg[0], 0);
78                 set_debugreg(current->thread.debugreg[1], 1);
79                 set_debugreg(current->thread.debugreg[2], 2);
80                 set_debugreg(current->thread.debugreg[3], 3);
81                 /* no 4 and 5 */
82                 set_debugreg(current->thread.debugreg[6], 6);
83                 set_debugreg(current->thread.debugreg[7], 7);
84         }
85
86 }
87
88 void __restore_processor_state(struct saved_context *ctxt)
89 {
90         /*
91          * control registers
92          */
93         write_cr4(ctxt->cr4);
94         write_cr3(ctxt->cr3);
95         write_cr2(ctxt->cr2);
96         write_cr0(ctxt->cr0);
97
98         /*
99          * now restore the descriptor tables to their proper values
100          * ltr is done i fix_processor_context().
101          */
102         load_gdt(&ctxt->gdt_limit);
103         load_idt(&ctxt->idt_limit);
104
105         /*
106          * segment registers
107          */
108         loadsegment(es, ctxt->es);
109         loadsegment(fs, ctxt->fs);
110         loadsegment(gs, ctxt->gs);
111         loadsegment(ss, ctxt->ss);
112
113         /*
114          * sysenter MSRs
115          */
116         if (boot_cpu_has(X86_FEATURE_SEP))
117                 enable_sep_cpu();
118
119         fix_processor_context();
120         do_fpu_end();
121         mtrr_ap_init();
122         mcheck_init(&boot_cpu_data);
123 }
124
125 void restore_processor_state(void)
126 {
127         __restore_processor_state(&saved_context);
128 }
129
130 /* Needed by apm.c */
131 EXPORT_SYMBOL(save_processor_state);
132 EXPORT_SYMBOL(restore_processor_state);