Merge master.kernel.org:/home/rmk/linux-2.6-arm
[linux-2.6/kvm.git] / arch / i386 / power / cpu.c
blob7b0b9ad848e58eb9a723c16c87af4b1eb0aaa566
1 /*
2 * Suspend support specific for i386.
4 * Distribute under GPLv2
6 * Copyright (c) 2002 Pavel Machek <pavel@suse.cz>
7 * Copyright (c) 2001 Patrick Mochel <mochel@osdl.org>
8 */
10 #include <linux/config.h>
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/init.h>
14 #include <linux/types.h>
15 #include <linux/spinlock.h>
16 #include <linux/poll.h>
17 #include <linux/delay.h>
18 #include <linux/sysrq.h>
19 #include <linux/proc_fs.h>
20 #include <linux/irq.h>
21 #include <linux/pm.h>
22 #include <linux/device.h>
23 #include <linux/suspend.h>
24 #include <linux/acpi.h>
26 #include <asm/uaccess.h>
27 #include <asm/acpi.h>
28 #include <asm/tlbflush.h>
29 #include <asm/processor.h>
31 static struct saved_context saved_context;
33 unsigned long saved_context_ebx;
34 unsigned long saved_context_esp, saved_context_ebp;
35 unsigned long saved_context_esi, saved_context_edi;
36 unsigned long saved_context_eflags;
38 void __save_processor_state(struct saved_context *ctxt)
40 kernel_fpu_begin();
43 * descriptor tables
45 store_gdt(&ctxt->gdt_limit);
46 store_idt(&ctxt->idt_limit);
47 store_tr(ctxt->tr);
50 * segment registers
52 savesegment(es, ctxt->es);
53 savesegment(fs, ctxt->fs);
54 savesegment(gs, ctxt->gs);
55 savesegment(ss, ctxt->ss);
58 * control registers
60 ctxt->cr0 = read_cr0();
61 ctxt->cr2 = read_cr2();
62 ctxt->cr3 = read_cr3();
63 ctxt->cr4 = read_cr4();
66 void save_processor_state(void)
68 __save_processor_state(&saved_context);
71 static void
72 do_fpu_end(void)
74 /* restore FPU regs if necessary */
75 /* Do it out of line so that gcc does not move cr0 load to some stupid place */
76 kernel_fpu_end();
77 mxcsr_feature_mask_init();
81 static void fix_processor_context(void)
83 int cpu = smp_processor_id();
84 struct tss_struct * t = &per_cpu(init_tss, cpu);
86 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. */
88 load_TR_desc(); /* This does ltr */
89 load_LDT(&current->active_mm->context); /* This does lldt */
92 * Now maybe reload the debug registers
94 if (current->thread.debugreg[7]){
95 set_debugreg(current->thread.debugreg[0], 0);
96 set_debugreg(current->thread.debugreg[1], 1);
97 set_debugreg(current->thread.debugreg[2], 2);
98 set_debugreg(current->thread.debugreg[3], 3);
99 /* no 4 and 5 */
100 set_debugreg(current->thread.debugreg[6], 6);
101 set_debugreg(current->thread.debugreg[7], 7);
106 void __restore_processor_state(struct saved_context *ctxt)
109 * control registers
111 write_cr4(ctxt->cr4);
112 write_cr3(ctxt->cr3);
113 write_cr2(ctxt->cr2);
114 write_cr2(ctxt->cr0);
117 * now restore the descriptor tables to their proper values
118 * ltr is done i fix_processor_context().
120 load_gdt(&ctxt->gdt_limit);
121 load_idt(&ctxt->idt_limit);
124 * segment registers
126 loadsegment(es, ctxt->es);
127 loadsegment(fs, ctxt->fs);
128 loadsegment(gs, ctxt->gs);
129 loadsegment(ss, ctxt->ss);
132 * sysenter MSRs
134 if (boot_cpu_has(X86_FEATURE_SEP))
135 enable_sep_cpu();
137 fix_processor_context();
138 do_fpu_end();
139 mtrr_ap_init();
142 void restore_processor_state(void)
144 __restore_processor_state(&saved_context);
147 /* Needed by apm.c */
148 EXPORT_SYMBOL(save_processor_state);
149 EXPORT_SYMBOL(restore_processor_state);