]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - arch/x86/kernel/acpi/cstate.c
cf5ec586f22069c5bdeb3a3dee49dc77536a228b
[linux-2.6-omap-h63xx.git] / arch / x86 / kernel / acpi / cstate.c
1 /*
2  * Copyright (C) 2005 Intel Corporation
3  *      Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
4  *      - Added _PDC for SMP C-states on Intel CPUs
5  */
6
7 #include <linux/kernel.h>
8 #include <linux/module.h>
9 #include <linux/init.h>
10 #include <linux/acpi.h>
11 #include <linux/cpu.h>
12 #include <linux/sched.h>
13
14 #include <acpi/processor.h>
15 #include <asm/acpi.h>
16
17 /*
18  * Initialize bm_flags based on the CPU cache properties
19  * On SMP it depends on cache configuration
20  * - When cache is not shared among all CPUs, we flush cache
21  *   before entering C3.
22  * - When cache is shared among all CPUs, we use bm_check
23  *   mechanism as in UP case
24  *
25  * This routine is called only after all the CPUs are online
26  */
27 void acpi_processor_power_init_bm_check(struct acpi_processor_flags *flags,
28                                         unsigned int cpu)
29 {
30         struct cpuinfo_x86 *c = &cpu_data(cpu);
31
32         flags->bm_check = 0;
33         if (num_online_cpus() == 1)
34                 flags->bm_check = 1;
35         else if (c->x86_vendor == X86_VENDOR_INTEL) {
36                 /*
37                  * Today all CPUs that support C3 share cache.
38                  * TBD: This needs to look at cache shared map, once
39                  * multi-core detection patch makes to the base.
40                  */
41                 flags->bm_check = 1;
42         }
43 }
44 EXPORT_SYMBOL(acpi_processor_power_init_bm_check);
45
46 /* The code below handles cstate entry with monitor-mwait pair on Intel*/
47
48 struct cstate_entry {
49         struct {
50                 unsigned int eax;
51                 unsigned int ecx;
52         } states[ACPI_PROCESSOR_MAX_POWER];
53 };
54 static struct cstate_entry *cpu_cstate_entry;   /* per CPU ptr */
55
56 static short mwait_supported[ACPI_PROCESSOR_MAX_POWER];
57
58 #define MWAIT_SUBSTATE_MASK     (0xf)
59 #define MWAIT_SUBSTATE_SIZE     (4)
60
61 #define CPUID_MWAIT_LEAF (5)
62 #define CPUID5_ECX_EXTENSIONS_SUPPORTED (0x1)
63 #define CPUID5_ECX_INTERRUPT_BREAK      (0x2)
64
65 #define MWAIT_ECX_INTERRUPT_BREAK       (0x1)
66
67 #define NATIVE_CSTATE_BEYOND_HALT       (2)
68
69 static long acpi_processor_ffh_cstate_probe_cpu(void *_cx)
70 {
71         struct acpi_processor_cx *cx = _cx;
72         long retval;
73         unsigned int eax, ebx, ecx, edx;
74         unsigned int edx_part;
75         unsigned int cstate_type; /* C-state type and not ACPI C-state type */
76         unsigned int num_cstate_subtype;
77
78         cpuid(CPUID_MWAIT_LEAF, &eax, &ebx, &ecx, &edx);
79
80         /* Check whether this particular cx_type (in CST) is supported or not */
81         cstate_type = (cx->address >> MWAIT_SUBSTATE_SIZE) + 1;
82         edx_part = edx >> (cstate_type * MWAIT_SUBSTATE_SIZE);
83         num_cstate_subtype = edx_part & MWAIT_SUBSTATE_MASK;
84
85         retval = 0;
86         if (num_cstate_subtype < (cx->address & MWAIT_SUBSTATE_MASK)) {
87                 retval = -1;
88                 goto out;
89         }
90
91         /* mwait ecx extensions INTERRUPT_BREAK should be supported for C2/C3 */
92         if (!(ecx & CPUID5_ECX_EXTENSIONS_SUPPORTED) ||
93             !(ecx & CPUID5_ECX_INTERRUPT_BREAK)) {
94                 retval = -1;
95                 goto out;
96         }
97
98         if (!mwait_supported[cstate_type]) {
99                 mwait_supported[cstate_type] = 1;
100                 printk(KERN_DEBUG
101                         "Monitor-Mwait will be used to enter C-%d "
102                         "state\n", cx->type);
103         }
104         snprintf(cx->desc,
105                         ACPI_CX_DESC_LEN, "ACPI FFH INTEL MWAIT 0x%x",
106                         cx->address);
107 out:
108         return retval;
109 }
110
111 int acpi_processor_ffh_cstate_probe(unsigned int cpu,
112                 struct acpi_processor_cx *cx, struct acpi_power_register *reg)
113 {
114         struct cstate_entry *percpu_entry;
115         struct cpuinfo_x86 *c = &cpu_data(cpu);
116         long retval;
117
118         if (!cpu_cstate_entry || c->cpuid_level < CPUID_MWAIT_LEAF)
119                 return -1;
120
121         if (reg->bit_offset != NATIVE_CSTATE_BEYOND_HALT)
122                 return -1;
123
124         percpu_entry = per_cpu_ptr(cpu_cstate_entry, cpu);
125         percpu_entry->states[cx->index].eax = 0;
126         percpu_entry->states[cx->index].ecx = 0;
127
128         /* Make sure we are running on right CPU */
129
130         retval = work_on_cpu(cpu, acpi_processor_ffh_cstate_probe_cpu, cx);
131         if (retval == 0) {
132                 /* Use the hint in CST */
133                 percpu_entry->states[cx->index].eax = cx->address;
134                 percpu_entry->states[cx->index].ecx = MWAIT_ECX_INTERRUPT_BREAK;
135         }
136         return retval;
137 }
138 EXPORT_SYMBOL_GPL(acpi_processor_ffh_cstate_probe);
139
140 void acpi_processor_ffh_cstate_enter(struct acpi_processor_cx *cx)
141 {
142         unsigned int cpu = smp_processor_id();
143         struct cstate_entry *percpu_entry;
144
145         percpu_entry = per_cpu_ptr(cpu_cstate_entry, cpu);
146         mwait_idle_with_hints(percpu_entry->states[cx->index].eax,
147                               percpu_entry->states[cx->index].ecx);
148 }
149 EXPORT_SYMBOL_GPL(acpi_processor_ffh_cstate_enter);
150
151 static int __init ffh_cstate_init(void)
152 {
153         struct cpuinfo_x86 *c = &boot_cpu_data;
154         if (c->x86_vendor != X86_VENDOR_INTEL)
155                 return -1;
156
157         cpu_cstate_entry = alloc_percpu(struct cstate_entry);
158         return 0;
159 }
160
161 static void __exit ffh_cstate_exit(void)
162 {
163         free_percpu(cpu_cstate_entry);
164         cpu_cstate_entry = NULL;
165 }
166
167 arch_initcall(ffh_cstate_init);
168 __exitcall(ffh_cstate_exit);