added 2.6.29.6 aldebaran kernel
[nao-ulib.git] / kernel / 2.6.29.6-aldebaran-rt / arch / x86 / power / cpu_32.c
blob274d06082f4851bfcf71c621f7a62db447e54876
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/module.h>
11 #include <linux/suspend.h>
12 #include <asm/mtrr.h>
13 #include <asm/mce.h>
14 #include <asm/xcr.h>
16 static struct saved_context saved_context;
18 unsigned long saved_context_ebx;
19 unsigned long saved_context_esp, saved_context_ebp;
20 unsigned long saved_context_esi, saved_context_edi;
21 unsigned long saved_context_eflags;
23 static void __save_processor_state(struct saved_context *ctxt)
25 mtrr_save_fixed_ranges(NULL);
26 kernel_fpu_begin();
29 * descriptor tables
31 store_gdt(&ctxt->gdt);
32 store_idt(&ctxt->idt);
33 store_tr(ctxt->tr);
36 * segment registers
38 savesegment(es, ctxt->es);
39 savesegment(fs, ctxt->fs);
40 savesegment(gs, ctxt->gs);
41 savesegment(ss, ctxt->ss);
44 * control registers
46 ctxt->cr0 = read_cr0();
47 ctxt->cr2 = read_cr2();
48 ctxt->cr3 = read_cr3();
49 ctxt->cr4 = read_cr4_safe();
52 /* Needed by apm.c */
53 void save_processor_state(void)
55 __save_processor_state(&saved_context);
57 EXPORT_SYMBOL(save_processor_state);
59 static void do_fpu_end(void)
62 * Restore FPU regs if necessary.
64 kernel_fpu_end();
67 static void fix_processor_context(void)
69 int cpu = smp_processor_id();
70 struct tss_struct *t = &per_cpu(init_tss, cpu);
72 set_tss_desc(cpu, t); /*
73 * This just modifies memory; should not be
74 * necessary. But... This is necessary, because
75 * 386 hardware has concept of busy TSS or some
76 * similar stupidity.
79 load_TR_desc(); /* This does ltr */
80 load_LDT(&current->active_mm->context); /* This does lldt */
83 * Now maybe reload the debug registers
85 if (current->thread.debugreg7) {
86 set_debugreg(current->thread.debugreg0, 0);
87 set_debugreg(current->thread.debugreg1, 1);
88 set_debugreg(current->thread.debugreg2, 2);
89 set_debugreg(current->thread.debugreg3, 3);
90 /* no 4 and 5 */
91 set_debugreg(current->thread.debugreg6, 6);
92 set_debugreg(current->thread.debugreg7, 7);
97 static void __restore_processor_state(struct saved_context *ctxt)
100 * control registers
102 /* cr4 was introduced in the Pentium CPU */
103 if (ctxt->cr4)
104 write_cr4(ctxt->cr4);
105 write_cr3(ctxt->cr3);
106 write_cr2(ctxt->cr2);
107 write_cr0(ctxt->cr0);
110 * now restore the descriptor tables to their proper values
111 * ltr is done i fix_processor_context().
113 load_gdt(&ctxt->gdt);
114 load_idt(&ctxt->idt);
117 * segment registers
119 loadsegment(es, ctxt->es);
120 loadsegment(fs, ctxt->fs);
121 loadsegment(gs, ctxt->gs);
122 loadsegment(ss, ctxt->ss);
125 * sysenter MSRs
127 if (boot_cpu_has(X86_FEATURE_SEP))
128 enable_sep_cpu();
131 * restore XCR0 for xsave capable cpu's.
133 if (cpu_has_xsave)
134 xsetbv(XCR_XFEATURE_ENABLED_MASK, pcntxt_mask);
136 fix_processor_context();
137 do_fpu_end();
138 mtrr_ap_init();
139 mcheck_init(&boot_cpu_data);
142 /* Needed by apm.c */
143 void restore_processor_state(void)
145 __restore_processor_state(&saved_context);
147 EXPORT_SYMBOL(restore_processor_state);