linux/arch/x86/power/cpu_32.c
<<
>>
Prefs
   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
  15static struct saved_context saved_context;
  16
  17unsigned long saved_context_ebx;
  18unsigned long saved_context_esp, saved_context_ebp;
  19unsigned long saved_context_esi, saved_context_edi;
  20unsigned long saved_context_eflags;
  21
  22static void __save_processor_state(struct saved_context *ctxt)
  23{
  24        mtrr_save_fixed_ranges(NULL);
  25        kernel_fpu_begin();
  26
  27        /*
  28         * descriptor tables
  29         */
  30        store_gdt(&ctxt->gdt);
  31        store_idt(&ctxt->idt);
  32        store_tr(ctxt->tr);
  33
  34        /*
  35         * segment registers
  36         */
  37        savesegment(es, ctxt->es);
  38        savesegment(fs, ctxt->fs);
  39        savesegment(gs, ctxt->gs);
  40        savesegment(ss, ctxt->ss);
  41
  42        /*
  43         * control registers
  44         */
  45        ctxt->cr0 = read_cr0();
  46        ctxt->cr2 = read_cr2();
  47        ctxt->cr3 = read_cr3();
  48        ctxt->cr4 = read_cr4_safe();
  49}
  50
  51/* Needed by apm.c */
  52void save_processor_state(void)
  53{
  54        __save_processor_state(&saved_context);
  55}
  56EXPORT_SYMBOL(save_processor_state);
  57
  58static void do_fpu_end(void)
  59{
  60        /*
  61         * Restore FPU regs if necessary.
  62         */
  63        kernel_fpu_end();
  64}
  65
  66static void fix_processor_context(void)
  67{
  68        int cpu = smp_processor_id();
  69        struct tss_struct *t = &per_cpu(init_tss, cpu);
  70
  71        set_tss_desc(cpu, t);   /*
  72                                 * This just modifies memory; should not be
  73                                 * necessary. But... This is necessary, because
  74                                 * 386 hardware has concept of busy TSS or some
  75                                 * similar stupidity.
  76                                 */
  77
  78        load_TR_desc();                         /* This does ltr */
  79        load_LDT(&current->active_mm->context); /* This does lldt */
  80
  81        /*
  82         * Now maybe reload the debug registers
  83         */
  84        if (current->thread.debugreg7) {
  85                set_debugreg(current->thread.debugreg0, 0);
  86                set_debugreg(current->thread.debugreg1, 1);
  87                set_debugreg(current->thread.debugreg2, 2);
  88                set_debugreg(current->thread.debugreg3, 3);
  89                /* no 4 and 5 */
  90                set_debugreg(current->thread.debugreg6, 6);
  91                set_debugreg(current->thread.debugreg7, 7);
  92        }
  93
  94}
  95
  96static void __restore_processor_state(struct saved_context *ctxt)
  97{
  98        /*
  99         * control registers
 100         */
 101        /* cr4 was introduced in the Pentium CPU */
 102        if (ctxt->cr4)
 103                write_cr4(ctxt->cr4);
 104        write_cr3(ctxt->cr3);
 105        write_cr2(ctxt->cr2);
 106        write_cr0(ctxt->cr0);
 107
 108        /*
 109         * now restore the descriptor tables to their proper values
 110         * ltr is done i fix_processor_context().
 111         */
 112        load_gdt(&ctxt->gdt);
 113        load_idt(&ctxt->idt);
 114
 115        /*
 116         * segment registers
 117         */
 118        loadsegment(es, ctxt->es);
 119        loadsegment(fs, ctxt->fs);
 120        loadsegment(gs, ctxt->gs);
 121        loadsegment(ss, ctxt->ss);
 122
 123        /*
 124         * sysenter MSRs
 125         */
 126        if (boot_cpu_has(X86_FEATURE_SEP))
 127                enable_sep_cpu();
 128
 129        fix_processor_context();
 130        do_fpu_end();
 131        mtrr_ap_init();
 132        mcheck_init(&boot_cpu_data);
 133}
 134
 135/* Needed by apm.c */
 136void restore_processor_state(void)
 137{
 138        __restore_processor_state(&saved_context);
 139}
 140EXPORT_SYMBOL(restore_processor_state);
 141