diff options
author | Benjamin Herrenschmidt <benh@kernel.crashing.org> | 2011-05-20 01:36:52 -0400 |
---|---|---|
committer | Benjamin Herrenschmidt <benh@kernel.crashing.org> | 2011-05-20 01:36:52 -0400 |
commit | 880102e78547c1db158a17e36cf0cdd98e7ad710 (patch) | |
tree | 3fff9cc54c44dafe275cfabefb96c589e08d971d /drivers | |
parent | 3d07f0e83d4323d2cd45cc583f7cf1957aca3cac (diff) | |
parent | 39ab05c8e0b519ff0a04a869f065746e6e8c3d95 (diff) |
Merge remote branch 'origin/master' into merge
Manual merge of arch/powerpc/kernel/smp.c and add missing scheduler_ipi()
call to arch/powerpc/platforms/cell/interrupt.c
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Diffstat (limited to 'drivers')
125 files changed, 15294 insertions, 1154 deletions
diff --git a/drivers/Kconfig b/drivers/Kconfig index 177c7d156933..557a469c7aa6 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig | |||
@@ -119,4 +119,7 @@ source "drivers/platform/Kconfig" | |||
119 | source "drivers/clk/Kconfig" | 119 | source "drivers/clk/Kconfig" |
120 | 120 | ||
121 | source "drivers/hwspinlock/Kconfig" | 121 | source "drivers/hwspinlock/Kconfig" |
122 | |||
123 | source "drivers/clocksource/Kconfig" | ||
124 | |||
122 | endmenu | 125 | endmenu |
diff --git a/drivers/acpi/processor_perflib.c b/drivers/acpi/processor_perflib.c index 3a73a93596e8..85b32376dad7 100644 --- a/drivers/acpi/processor_perflib.c +++ b/drivers/acpi/processor_perflib.c | |||
@@ -49,10 +49,6 @@ ACPI_MODULE_NAME("processor_perflib"); | |||
49 | 49 | ||
50 | static DEFINE_MUTEX(performance_mutex); | 50 | static DEFINE_MUTEX(performance_mutex); |
51 | 51 | ||
52 | /* Use cpufreq debug layer for _PPC changes. */ | ||
53 | #define cpufreq_printk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_CORE, \ | ||
54 | "cpufreq-core", msg) | ||
55 | |||
56 | /* | 52 | /* |
57 | * _PPC support is implemented as a CPUfreq policy notifier: | 53 | * _PPC support is implemented as a CPUfreq policy notifier: |
58 | * This means each time a CPUfreq driver registered also with | 54 | * This means each time a CPUfreq driver registered also with |
@@ -145,7 +141,7 @@ static int acpi_processor_get_platform_limit(struct acpi_processor *pr) | |||
145 | return -ENODEV; | 141 | return -ENODEV; |
146 | } | 142 | } |
147 | 143 | ||
148 | cpufreq_printk("CPU %d: _PPC is %d - frequency %s limited\n", pr->id, | 144 | pr_debug("CPU %d: _PPC is %d - frequency %s limited\n", pr->id, |
149 | (int)ppc, ppc ? "" : "not"); | 145 | (int)ppc, ppc ? "" : "not"); |
150 | 146 | ||
151 | pr->performance_platform_limit = (int)ppc; | 147 | pr->performance_platform_limit = (int)ppc; |
diff --git a/drivers/acpi/processor_throttling.c b/drivers/acpi/processor_throttling.c index ad3501739563..605a2954ef17 100644 --- a/drivers/acpi/processor_throttling.c +++ b/drivers/acpi/processor_throttling.c | |||
@@ -710,20 +710,14 @@ static int acpi_processor_get_throttling_fadt(struct acpi_processor *pr) | |||
710 | } | 710 | } |
711 | 711 | ||
712 | #ifdef CONFIG_X86 | 712 | #ifdef CONFIG_X86 |
713 | static int acpi_throttling_rdmsr(struct acpi_processor *pr, | 713 | static int acpi_throttling_rdmsr(u64 *value) |
714 | u64 *value) | ||
715 | { | 714 | { |
716 | struct cpuinfo_x86 *c; | ||
717 | u64 msr_high, msr_low; | 715 | u64 msr_high, msr_low; |
718 | unsigned int cpu; | ||
719 | u64 msr = 0; | 716 | u64 msr = 0; |
720 | int ret = -1; | 717 | int ret = -1; |
721 | 718 | ||
722 | cpu = pr->id; | 719 | if ((this_cpu_read(cpu_info.x86_vendor) != X86_VENDOR_INTEL) || |
723 | c = &cpu_data(cpu); | 720 | !this_cpu_has(X86_FEATURE_ACPI)) { |
724 | |||
725 | if ((c->x86_vendor != X86_VENDOR_INTEL) || | ||
726 | !cpu_has(c, X86_FEATURE_ACPI)) { | ||
727 | printk(KERN_ERR PREFIX | 721 | printk(KERN_ERR PREFIX |
728 | "HARDWARE addr space,NOT supported yet\n"); | 722 | "HARDWARE addr space,NOT supported yet\n"); |
729 | } else { | 723 | } else { |
@@ -738,18 +732,13 @@ static int acpi_throttling_rdmsr(struct acpi_processor *pr, | |||
738 | return ret; | 732 | return ret; |
739 | } | 733 | } |
740 | 734 | ||
741 | static int acpi_throttling_wrmsr(struct acpi_processor *pr, u64 value) | 735 | static int acpi_throttling_wrmsr(u64 value) |
742 | { | 736 | { |
743 | struct cpuinfo_x86 *c; | ||
744 | unsigned int cpu; | ||
745 | int ret = -1; | 737 | int ret = -1; |
746 | u64 msr; | 738 | u64 msr; |
747 | 739 | ||
748 | cpu = pr->id; | 740 | if ((this_cpu_read(cpu_info.x86_vendor) != X86_VENDOR_INTEL) || |
749 | c = &cpu_data(cpu); | 741 | !this_cpu_has(X86_FEATURE_ACPI)) { |
750 | |||
751 | if ((c->x86_vendor != X86_VENDOR_INTEL) || | ||
752 | !cpu_has(c, X86_FEATURE_ACPI)) { | ||
753 | printk(KERN_ERR PREFIX | 742 | printk(KERN_ERR PREFIX |
754 | "HARDWARE addr space,NOT supported yet\n"); | 743 | "HARDWARE addr space,NOT supported yet\n"); |
755 | } else { | 744 | } else { |
@@ -761,15 +750,14 @@ static int acpi_throttling_wrmsr(struct acpi_processor *pr, u64 value) | |||
761 | return ret; | 750 | return ret; |
762 | } | 751 | } |
763 | #else | 752 | #else |
764 | static int acpi_throttling_rdmsr(struct acpi_processor *pr, | 753 | static int acpi_throttling_rdmsr(u64 *value) |
765 | u64 *value) | ||
766 | { | 754 | { |
767 | printk(KERN_ERR PREFIX | 755 | printk(KERN_ERR PREFIX |
768 | "HARDWARE addr space,NOT supported yet\n"); | 756 | "HARDWARE addr space,NOT supported yet\n"); |
769 | return -1; | 757 | return -1; |
770 | } | 758 | } |
771 | 759 | ||
772 | static int acpi_throttling_wrmsr(struct acpi_processor *pr, u64 value) | 760 | static int acpi_throttling_wrmsr(u64 value) |
773 | { | 761 | { |
774 | printk(KERN_ERR PREFIX | 762 | printk(KERN_ERR PREFIX |
775 | "HARDWARE addr space,NOT supported yet\n"); | 763 | "HARDWARE addr space,NOT supported yet\n"); |
@@ -801,7 +789,7 @@ static int acpi_read_throttling_status(struct acpi_processor *pr, | |||
801 | ret = 0; | 789 | ret = 0; |
802 | break; | 790 | break; |
803 | case ACPI_ADR_SPACE_FIXED_HARDWARE: | 791 | case ACPI_ADR_SPACE_FIXED_HARDWARE: |
804 | ret = acpi_throttling_rdmsr(pr, value); | 792 | ret = acpi_throttling_rdmsr(value); |
805 | break; | 793 | break; |
806 | default: | 794 | default: |
807 | printk(KERN_ERR PREFIX "Unknown addr space %d\n", | 795 | printk(KERN_ERR PREFIX "Unknown addr space %d\n", |
@@ -834,7 +822,7 @@ static int acpi_write_throttling_state(struct acpi_processor *pr, | |||
834 | ret = 0; | 822 | ret = 0; |
835 | break; | 823 | break; |
836 | case ACPI_ADR_SPACE_FIXED_HARDWARE: | 824 | case ACPI_ADR_SPACE_FIXED_HARDWARE: |
837 | ret = acpi_throttling_wrmsr(pr, value); | 825 | ret = acpi_throttling_wrmsr(value); |
838 | break; | 826 | break; |
839 | default: | 827 | default: |
840 | printk(KERN_ERR PREFIX "Unknown addr space %d\n", | 828 | printk(KERN_ERR PREFIX "Unknown addr space %d\n", |
diff --git a/drivers/base/Kconfig b/drivers/base/Kconfig index e9e5238f3106..d57e8d0fb823 100644 --- a/drivers/base/Kconfig +++ b/drivers/base/Kconfig | |||
@@ -168,11 +168,4 @@ config SYS_HYPERVISOR | |||
168 | bool | 168 | bool |
169 | default n | 169 | default n |
170 | 170 | ||
171 | config ARCH_NO_SYSDEV_OPS | ||
172 | bool | ||
173 | ---help--- | ||
174 | To be selected by architectures that don't use sysdev class or | ||
175 | sysdev driver power management (suspend/resume) and shutdown | ||
176 | operations. | ||
177 | |||
178 | endmenu | 171 | endmenu |
diff --git a/drivers/base/base.h b/drivers/base/base.h index 19f49e41ce5d..a34dca0ad041 100644 --- a/drivers/base/base.h +++ b/drivers/base/base.h | |||
@@ -111,8 +111,6 @@ static inline int driver_match_device(struct device_driver *drv, | |||
111 | return drv->bus->match ? drv->bus->match(dev, drv) : 1; | 111 | return drv->bus->match ? drv->bus->match(dev, drv) : 1; |
112 | } | 112 | } |
113 | 113 | ||
114 | extern void sysdev_shutdown(void); | ||
115 | |||
116 | extern char *make_class_name(const char *name, struct kobject *kobj); | 114 | extern char *make_class_name(const char *name, struct kobject *kobj); |
117 | 115 | ||
118 | extern int devres_release_all(struct device *dev); | 116 | extern int devres_release_all(struct device *dev); |
diff --git a/drivers/base/core.c b/drivers/base/core.c index 81b78ede37c4..bc8729d603a7 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c | |||
@@ -400,7 +400,7 @@ static void device_remove_groups(struct device *dev, | |||
400 | static int device_add_attrs(struct device *dev) | 400 | static int device_add_attrs(struct device *dev) |
401 | { | 401 | { |
402 | struct class *class = dev->class; | 402 | struct class *class = dev->class; |
403 | struct device_type *type = dev->type; | 403 | const struct device_type *type = dev->type; |
404 | int error; | 404 | int error; |
405 | 405 | ||
406 | if (class) { | 406 | if (class) { |
@@ -440,7 +440,7 @@ static int device_add_attrs(struct device *dev) | |||
440 | static void device_remove_attrs(struct device *dev) | 440 | static void device_remove_attrs(struct device *dev) |
441 | { | 441 | { |
442 | struct class *class = dev->class; | 442 | struct class *class = dev->class; |
443 | struct device_type *type = dev->type; | 443 | const struct device_type *type = dev->type; |
444 | 444 | ||
445 | device_remove_groups(dev, dev->groups); | 445 | device_remove_groups(dev, dev->groups); |
446 | 446 | ||
@@ -1314,8 +1314,7 @@ EXPORT_SYMBOL_GPL(put_device); | |||
1314 | EXPORT_SYMBOL_GPL(device_create_file); | 1314 | EXPORT_SYMBOL_GPL(device_create_file); |
1315 | EXPORT_SYMBOL_GPL(device_remove_file); | 1315 | EXPORT_SYMBOL_GPL(device_remove_file); |
1316 | 1316 | ||
1317 | struct root_device | 1317 | struct root_device { |
1318 | { | ||
1319 | struct device dev; | 1318 | struct device dev; |
1320 | struct module *owner; | 1319 | struct module *owner; |
1321 | }; | 1320 | }; |
diff --git a/drivers/base/dd.c b/drivers/base/dd.c index da57ee9d63fe..6658da743c3a 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c | |||
@@ -245,6 +245,10 @@ int device_attach(struct device *dev) | |||
245 | 245 | ||
246 | device_lock(dev); | 246 | device_lock(dev); |
247 | if (dev->driver) { | 247 | if (dev->driver) { |
248 | if (klist_node_attached(&dev->p->knode_driver)) { | ||
249 | ret = 1; | ||
250 | goto out_unlock; | ||
251 | } | ||
248 | ret = device_bind_driver(dev); | 252 | ret = device_bind_driver(dev); |
249 | if (ret == 0) | 253 | if (ret == 0) |
250 | ret = 1; | 254 | ret = 1; |
@@ -257,6 +261,7 @@ int device_attach(struct device *dev) | |||
257 | ret = bus_for_each_drv(dev->bus, NULL, dev, __device_attach); | 261 | ret = bus_for_each_drv(dev->bus, NULL, dev, __device_attach); |
258 | pm_runtime_put_sync(dev); | 262 | pm_runtime_put_sync(dev); |
259 | } | 263 | } |
264 | out_unlock: | ||
260 | device_unlock(dev); | 265 | device_unlock(dev); |
261 | return ret; | 266 | return ret; |
262 | } | 267 | } |
@@ -316,8 +321,7 @@ static void __device_release_driver(struct device *dev) | |||
316 | 321 | ||
317 | drv = dev->driver; | 322 | drv = dev->driver; |
318 | if (drv) { | 323 | if (drv) { |
319 | pm_runtime_get_noresume(dev); | 324 | pm_runtime_get_sync(dev); |
320 | pm_runtime_barrier(dev); | ||
321 | 325 | ||
322 | driver_sysfs_remove(dev); | 326 | driver_sysfs_remove(dev); |
323 | 327 | ||
@@ -326,6 +330,8 @@ static void __device_release_driver(struct device *dev) | |||
326 | BUS_NOTIFY_UNBIND_DRIVER, | 330 | BUS_NOTIFY_UNBIND_DRIVER, |
327 | dev); | 331 | dev); |
328 | 332 | ||
333 | pm_runtime_put_sync(dev); | ||
334 | |||
329 | if (dev->bus && dev->bus->remove) | 335 | if (dev->bus && dev->bus->remove) |
330 | dev->bus->remove(dev); | 336 | dev->bus->remove(dev); |
331 | else if (drv->remove) | 337 | else if (drv->remove) |
@@ -338,7 +344,6 @@ static void __device_release_driver(struct device *dev) | |||
338 | BUS_NOTIFY_UNBOUND_DRIVER, | 344 | BUS_NOTIFY_UNBOUND_DRIVER, |
339 | dev); | 345 | dev); |
340 | 346 | ||
341 | pm_runtime_put_sync(dev); | ||
342 | } | 347 | } |
343 | } | 348 | } |
344 | 349 | ||
@@ -408,17 +413,16 @@ void *dev_get_drvdata(const struct device *dev) | |||
408 | } | 413 | } |
409 | EXPORT_SYMBOL(dev_get_drvdata); | 414 | EXPORT_SYMBOL(dev_get_drvdata); |
410 | 415 | ||
411 | void dev_set_drvdata(struct device *dev, void *data) | 416 | int dev_set_drvdata(struct device *dev, void *data) |
412 | { | 417 | { |
413 | int error; | 418 | int error; |
414 | 419 | ||
415 | if (!dev) | ||
416 | return; | ||
417 | if (!dev->p) { | 420 | if (!dev->p) { |
418 | error = device_private_init(dev); | 421 | error = device_private_init(dev); |
419 | if (error) | 422 | if (error) |
420 | return; | 423 | return error; |
421 | } | 424 | } |
422 | dev->p->driver_data = data; | 425 | dev->p->driver_data = data; |
426 | return 0; | ||
423 | } | 427 | } |
424 | EXPORT_SYMBOL(dev_set_drvdata); | 428 | EXPORT_SYMBOL(dev_set_drvdata); |
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c index 8c798ef7f13f..bbb03e6f7255 100644 --- a/drivers/base/firmware_class.c +++ b/drivers/base/firmware_class.c | |||
@@ -521,6 +521,11 @@ static int _request_firmware(const struct firmware **firmware_p, | |||
521 | if (!firmware_p) | 521 | if (!firmware_p) |
522 | return -EINVAL; | 522 | return -EINVAL; |
523 | 523 | ||
524 | if (WARN_ON(usermodehelper_is_disabled())) { | ||
525 | dev_err(device, "firmware: %s will not be loaded\n", name); | ||
526 | return -EBUSY; | ||
527 | } | ||
528 | |||
524 | *firmware_p = firmware = kzalloc(sizeof(*firmware), GFP_KERNEL); | 529 | *firmware_p = firmware = kzalloc(sizeof(*firmware), GFP_KERNEL); |
525 | if (!firmware) { | 530 | if (!firmware) { |
526 | dev_err(device, "%s: kmalloc(struct firmware) failed\n", | 531 | dev_err(device, "%s: kmalloc(struct firmware) failed\n", |
diff --git a/drivers/base/memory.c b/drivers/base/memory.c index 3da6a43b7756..0a134a424a37 100644 --- a/drivers/base/memory.c +++ b/drivers/base/memory.c | |||
@@ -48,7 +48,8 @@ static const char *memory_uevent_name(struct kset *kset, struct kobject *kobj) | |||
48 | return MEMORY_CLASS_NAME; | 48 | return MEMORY_CLASS_NAME; |
49 | } | 49 | } |
50 | 50 | ||
51 | static int memory_uevent(struct kset *kset, struct kobject *obj, struct kobj_uevent_env *env) | 51 | static int memory_uevent(struct kset *kset, struct kobject *obj, |
52 | struct kobj_uevent_env *env) | ||
52 | { | 53 | { |
53 | int retval = 0; | 54 | int retval = 0; |
54 | 55 | ||
@@ -228,10 +229,11 @@ int memory_isolate_notify(unsigned long val, void *v) | |||
228 | * OK to have direct references to sparsemem variables in here. | 229 | * OK to have direct references to sparsemem variables in here. |
229 | */ | 230 | */ |
230 | static int | 231 | static int |
231 | memory_section_action(unsigned long phys_index, unsigned long action) | 232 | memory_block_action(unsigned long phys_index, unsigned long action) |
232 | { | 233 | { |
233 | int i; | 234 | int i; |
234 | unsigned long start_pfn, start_paddr; | 235 | unsigned long start_pfn, start_paddr; |
236 | unsigned long nr_pages = PAGES_PER_SECTION * sections_per_block; | ||
235 | struct page *first_page; | 237 | struct page *first_page; |
236 | int ret; | 238 | int ret; |
237 | 239 | ||
@@ -243,7 +245,7 @@ memory_section_action(unsigned long phys_index, unsigned long action) | |||
243 | * that way. | 245 | * that way. |
244 | */ | 246 | */ |
245 | if (action == MEM_ONLINE) { | 247 | if (action == MEM_ONLINE) { |
246 | for (i = 0; i < PAGES_PER_SECTION; i++) { | 248 | for (i = 0; i < nr_pages; i++) { |
247 | if (PageReserved(first_page+i)) | 249 | if (PageReserved(first_page+i)) |
248 | continue; | 250 | continue; |
249 | 251 | ||
@@ -257,12 +259,12 @@ memory_section_action(unsigned long phys_index, unsigned long action) | |||
257 | switch (action) { | 259 | switch (action) { |
258 | case MEM_ONLINE: | 260 | case MEM_ONLINE: |
259 | start_pfn = page_to_pfn(first_page); | 261 | start_pfn = page_to_pfn(first_page); |
260 | ret = online_pages(start_pfn, PAGES_PER_SECTION); | 262 | ret = online_pages(start_pfn, nr_pages); |
261 | break; | 263 | break; |
262 | case MEM_OFFLINE: | 264 | case MEM_OFFLINE: |
263 | start_paddr = page_to_pfn(first_page) << PAGE_SHIFT; | 265 | start_paddr = page_to_pfn(first_page) << PAGE_SHIFT; |
264 | ret = remove_memory(start_paddr, | 266 | ret = remove_memory(start_paddr, |
265 | PAGES_PER_SECTION << PAGE_SHIFT); | 267 | nr_pages << PAGE_SHIFT); |
266 | break; | 268 | break; |
267 | default: | 269 | default: |
268 | WARN(1, KERN_WARNING "%s(%ld, %ld) unknown action: " | 270 | WARN(1, KERN_WARNING "%s(%ld, %ld) unknown action: " |
@@ -276,7 +278,7 @@ memory_section_action(unsigned long phys_index, unsigned long action) | |||
276 | static int memory_block_change_state(struct memory_block *mem, | 278 | static int memory_block_change_state(struct memory_block *mem, |
277 | unsigned long to_state, unsigned long from_state_req) | 279 | unsigned long to_state, unsigned long from_state_req) |
278 | { | 280 | { |
279 | int i, ret = 0; | 281 | int ret = 0; |
280 | 282 | ||
281 | mutex_lock(&mem->state_mutex); | 283 | mutex_lock(&mem->state_mutex); |
282 | 284 | ||
@@ -288,20 +290,11 @@ static int memory_block_change_state(struct memory_block *mem, | |||
288 | if (to_state == MEM_OFFLINE) | 290 | if (to_state == MEM_OFFLINE) |
289 | mem->state = MEM_GOING_OFFLINE; | 291 | mem->state = MEM_GOING_OFFLINE; |
290 | 292 | ||
291 | for (i = 0; i < sections_per_block; i++) { | 293 | ret = memory_block_action(mem->start_section_nr, to_state); |
292 | ret = memory_section_action(mem->start_section_nr + i, | ||
293 | to_state); | ||
294 | if (ret) | ||
295 | break; | ||
296 | } | ||
297 | |||
298 | if (ret) { | ||
299 | for (i = 0; i < sections_per_block; i++) | ||
300 | memory_section_action(mem->start_section_nr + i, | ||
301 | from_state_req); | ||
302 | 294 | ||
295 | if (ret) | ||
303 | mem->state = from_state_req; | 296 | mem->state = from_state_req; |
304 | } else | 297 | else |
305 | mem->state = to_state; | 298 | mem->state = to_state; |
306 | 299 | ||
307 | out: | 300 | out: |
diff --git a/drivers/base/platform.c b/drivers/base/platform.c index 9e0e4fc24c46..1c291af637b3 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c | |||
@@ -192,18 +192,18 @@ EXPORT_SYMBOL_GPL(platform_device_alloc); | |||
192 | int platform_device_add_resources(struct platform_device *pdev, | 192 | int platform_device_add_resources(struct platform_device *pdev, |
193 | const struct resource *res, unsigned int num) | 193 | const struct resource *res, unsigned int num) |
194 | { | 194 | { |
195 | struct resource *r; | 195 | struct resource *r = NULL; |
196 | 196 | ||
197 | if (!res) | 197 | if (res) { |
198 | return 0; | 198 | r = kmemdup(res, sizeof(struct resource) * num, GFP_KERNEL); |
199 | 199 | if (!r) | |
200 | r = kmemdup(res, sizeof(struct resource) * num, GFP_KERNEL); | 200 | return -ENOMEM; |
201 | if (r) { | ||
202 | pdev->resource = r; | ||
203 | pdev->num_resources = num; | ||
204 | return 0; | ||
205 | } | 201 | } |
206 | return -ENOMEM; | 202 | |
203 | kfree(pdev->resource); | ||
204 | pdev->resource = r; | ||
205 | pdev->num_resources = num; | ||
206 | return 0; | ||
207 | } | 207 | } |
208 | EXPORT_SYMBOL_GPL(platform_device_add_resources); | 208 | EXPORT_SYMBOL_GPL(platform_device_add_resources); |
209 | 209 | ||
@@ -220,17 +220,17 @@ EXPORT_SYMBOL_GPL(platform_device_add_resources); | |||
220 | int platform_device_add_data(struct platform_device *pdev, const void *data, | 220 | int platform_device_add_data(struct platform_device *pdev, const void *data, |
221 | size_t size) | 221 | size_t size) |
222 | { | 222 | { |
223 | void *d; | 223 | void *d = NULL; |
224 | 224 | ||
225 | if (!data) | 225 | if (data) { |
226 | return 0; | 226 | d = kmemdup(data, size, GFP_KERNEL); |
227 | 227 | if (!d) | |
228 | d = kmemdup(data, size, GFP_KERNEL); | 228 | return -ENOMEM; |
229 | if (d) { | ||
230 | pdev->dev.platform_data = d; | ||
231 | return 0; | ||
232 | } | 229 | } |
233 | return -ENOMEM; | 230 | |
231 | kfree(pdev->dev.platform_data); | ||
232 | pdev->dev.platform_data = d; | ||
233 | return 0; | ||
234 | } | 234 | } |
235 | EXPORT_SYMBOL_GPL(platform_device_add_data); | 235 | EXPORT_SYMBOL_GPL(platform_device_add_data); |
236 | 236 | ||
@@ -667,7 +667,7 @@ static int platform_legacy_resume(struct device *dev) | |||
667 | return ret; | 667 | return ret; |
668 | } | 668 | } |
669 | 669 | ||
670 | static int platform_pm_prepare(struct device *dev) | 670 | int platform_pm_prepare(struct device *dev) |
671 | { | 671 | { |
672 | struct device_driver *drv = dev->driver; | 672 | struct device_driver *drv = dev->driver; |
673 | int ret = 0; | 673 | int ret = 0; |
@@ -678,7 +678,7 @@ static int platform_pm_prepare(struct device *dev) | |||
678 | return ret; | 678 | return ret; |
679 | } | 679 | } |
680 | 680 | ||
681 | static void platform_pm_complete(struct device *dev) | 681 | void platform_pm_complete(struct device *dev) |
682 | { | 682 | { |
683 | struct device_driver *drv = dev->driver; | 683 | struct device_driver *drv = dev->driver; |
684 | 684 | ||
@@ -686,16 +686,11 @@ static void platform_pm_complete(struct device *dev) | |||
686 | drv->pm->complete(dev); | 686 | drv->pm->complete(dev); |
687 | } | 687 | } |
688 | 688 | ||
689 | #else /* !CONFIG_PM_SLEEP */ | 689 | #endif /* CONFIG_PM_SLEEP */ |
690 | |||
691 | #define platform_pm_prepare NULL | ||
692 | #define platform_pm_complete NULL | ||
693 | |||
694 | #endif /* !CONFIG_PM_SLEEP */ | ||
695 | 690 | ||
696 | #ifdef CONFIG_SUSPEND | 691 | #ifdef CONFIG_SUSPEND |
697 | 692 | ||
698 | int __weak platform_pm_suspend(struct device *dev) | 693 | int platform_pm_suspend(struct device *dev) |
699 | { | 694 | { |
700 | struct device_driver *drv = dev->driver; | 695 | struct device_driver *drv = dev->driver; |
701 | int ret = 0; | 696 | int ret = 0; |
@@ -713,7 +708,7 @@ int __weak platform_pm_suspend(struct device *dev) | |||
713 | return ret; | 708 | return ret; |
714 | } | 709 | } |
715 | 710 | ||
716 | int __weak platform_pm_suspend_noirq(struct device *dev) | 711 | int platform_pm_suspend_noirq(struct device *dev) |
717 | { | 712 | { |
718 | struct device_driver *drv = dev->driver; | 713 | struct device_driver *drv = dev->driver; |
719 | int ret = 0; | 714 | int ret = 0; |
@@ -729,7 +724,7 @@ int __weak platform_pm_suspend_noirq(struct device *dev) | |||
729 | return ret; | 724 | return ret; |
730 | } | 725 | } |
731 | 726 | ||
732 | int __weak platform_pm_resume(struct device *dev) | 727 | int platform_pm_resume(struct device *dev) |
733 | { | 728 | { |
734 | struct device_driver *drv = dev->driver; | 729 | struct device_driver *drv = dev->driver; |
735 | int ret = 0; | 730 | int ret = 0; |
@@ -747,7 +742,7 @@ int __weak platform_pm_resume(struct device *dev) | |||
747 | return ret; | 742 | return ret; |
748 | } | 743 | } |
749 | 744 | ||
750 | int __weak platform_pm_resume_noirq(struct device *dev) | 745 | int platform_pm_resume_noirq(struct device *dev) |
751 | { | 746 | { |
752 | struct device_driver *drv = dev->driver; | 747 | struct device_driver *drv = dev->driver; |
753 | int ret = 0; | 748 | int ret = 0; |
@@ -763,18 +758,11 @@ int __weak platform_pm_resume_noirq(struct device *dev) | |||
763 | return ret; | 758 | return ret; |
764 | } | 759 | } |
765 | 760 | ||
766 | #else /* !CONFIG_SUSPEND */ | 761 | #endif /* CONFIG_SUSPEND */ |
767 | |||
768 | #define platform_pm_suspend NULL | ||
769 | #define platform_pm_resume NULL | ||
770 | #define platform_pm_suspend_noirq NULL | ||
771 | #define platform_pm_resume_noirq NULL | ||
772 | |||
773 | #endif /* !CONFIG_SUSPEND */ | ||
774 | 762 | ||
775 | #ifdef CONFIG_HIBERNATE_CALLBACKS | 763 | #ifdef CONFIG_HIBERNATE_CALLBACKS |
776 | 764 | ||
777 | static int platform_pm_freeze(struct device *dev) | 765 | int platform_pm_freeze(struct device *dev) |
778 | { | 766 | { |
779 | struct device_driver *drv = dev->driver; | 767 | struct device_driver *drv = dev->driver; |
780 | int ret = 0; | 768 | int ret = 0; |
@@ -792,7 +780,7 @@ static int platform_pm_freeze(struct device *dev) | |||
792 | return ret; | 780 | return ret; |
793 | } | 781 | } |
794 | 782 | ||
795 | static int platform_pm_freeze_noirq(struct device *dev) | 783 | int platform_pm_freeze_noirq(struct device *dev) |
796 | { | 784 | { |
797 | struct device_driver *drv = dev->driver; | 785 | struct device_driver *drv = dev->driver; |
798 | int ret = 0; | 786 | int ret = 0; |
@@ -808,7 +796,7 @@ static int platform_pm_freeze_noirq(struct device *dev) | |||
808 | return ret; | 796 | return ret; |
809 | } | 797 | } |
810 | 798 | ||
811 | static int platform_pm_thaw(struct device *dev) | 799 | int platform_pm_thaw(struct device *dev) |
812 | { | 800 | { |
813 | struct device_driver *drv = dev->driver; | 801 | struct device_driver *drv = dev->driver; |
814 | int ret = 0; | 802 | int ret = 0; |
@@ -826,7 +814,7 @@ static int platform_pm_thaw(struct device *dev) | |||
826 | return ret; | 814 | return ret; |
827 | } | 815 | } |
828 | 816 | ||
829 | static int platform_pm_thaw_noirq(struct device *dev) | 817 | int platform_pm_thaw_noirq(struct device *dev) |
830 | { | 818 | { |
831 | struct device_driver *drv = dev->driver; | 819 | struct device_driver *drv = dev->driver; |
832 | int ret = 0; | 820 | int ret = 0; |
@@ -842,7 +830,7 @@ static int platform_pm_thaw_noirq(struct device *dev) | |||
842 | return ret; | 830 | return ret; |
843 | } | 831 | } |
844 | 832 | ||
845 | static int platform_pm_poweroff(struct device *dev) | 833 | int platform_pm_poweroff(struct device *dev) |
846 | { | 834 | { |
847 | struct device_driver *drv = dev->driver; | 835 | struct device_driver *drv = dev->driver; |
848 | int ret = 0; | 836 | int ret = 0; |
@@ -860,7 +848,7 @@ static int platform_pm_poweroff(struct device *dev) | |||
860 | return ret; | 848 | return ret; |
861 | } | 849 | } |
862 | 850 | ||
863 | static int platform_pm_poweroff_noirq(struct device *dev) | 851 | int platform_pm_poweroff_noirq(struct device *dev) |
864 | { | 852 | { |
865 | struct device_driver *drv = dev->driver; | 853 | struct device_driver *drv = dev->driver; |
866 | int ret = 0; | 854 | int ret = 0; |
@@ -876,7 +864,7 @@ static int platform_pm_poweroff_noirq(struct device *dev) | |||
876 | return ret; | 864 | return ret; |
877 | } | 865 | } |
878 | 866 | ||
879 | static int platform_pm_restore(struct device *dev) | 867 | int platform_pm_restore(struct device *dev) |
880 | { | 868 | { |
881 | struct device_driver *drv = dev->driver; | 869 | struct device_driver *drv = dev->driver; |
882 | int ret = 0; | 870 | int ret = 0; |
@@ -894,7 +882,7 @@ static int platform_pm_restore(struct device *dev) | |||
894 | return ret; | 882 | return ret; |
895 | } | 883 | } |
896 | 884 | ||
897 | static int platform_pm_restore_noirq(struct device *dev) | 885 | int platform_pm_restore_noirq(struct device *dev) |
898 | { | 886 | { |
899 | struct device_driver *drv = dev->driver; | 887 | struct device_driver *drv = dev->driver; |
900 | int ret = 0; | 888 | int ret = 0; |
@@ -910,62 +898,13 @@ static int platform_pm_restore_noirq(struct device *dev) | |||
910 | return ret; | 898 | return ret; |
911 | } | 899 | } |
912 | 900 | ||
913 | #else /* !CONFIG_HIBERNATE_CALLBACKS */ | 901 | #endif /* CONFIG_HIBERNATE_CALLBACKS */ |
914 | |||
915 | #define platform_pm_freeze NULL | ||
916 | #define platform_pm_thaw NULL | ||
917 | #define platform_pm_poweroff NULL | ||
918 | #define platform_pm_restore NULL | ||
919 | #define platform_pm_freeze_noirq NULL | ||
920 | #define platform_pm_thaw_noirq NULL | ||
921 | #define platform_pm_poweroff_noirq NULL | ||
922 | #define platform_pm_restore_noirq NULL | ||
923 | |||
924 | #endif /* !CONFIG_HIBERNATE_CALLBACKS */ | ||
925 | |||
926 | #ifdef CONFIG_PM_RUNTIME | ||
927 | |||
928 | int __weak platform_pm_runtime_suspend(struct device *dev) | ||
929 | { | ||
930 | return pm_generic_runtime_suspend(dev); | ||
931 | }; | ||
932 | |||
933 | int __weak platform_pm_runtime_resume(struct device *dev) | ||
934 | { | ||
935 | return pm_generic_runtime_resume(dev); | ||
936 | }; | ||
937 | |||
938 | int __weak platform_pm_runtime_idle(struct device *dev) | ||
939 | { | ||
940 | return pm_generic_runtime_idle(dev); | ||
941 | }; | ||
942 | |||
943 | #else /* !CONFIG_PM_RUNTIME */ | ||
944 | |||
945 | #define platform_pm_runtime_suspend NULL | ||
946 | #define platform_pm_runtime_resume NULL | ||
947 | #define platform_pm_runtime_idle NULL | ||
948 | |||
949 | #endif /* !CONFIG_PM_RUNTIME */ | ||
950 | 902 | ||
951 | static const struct dev_pm_ops platform_dev_pm_ops = { | 903 | static const struct dev_pm_ops platform_dev_pm_ops = { |
952 | .prepare = platform_pm_prepare, | 904 | .runtime_suspend = pm_generic_runtime_suspend, |
953 | .complete = platform_pm_complete, | 905 | .runtime_resume = pm_generic_runtime_resume, |
954 | .suspend = platform_pm_suspend, | 906 | .runtime_idle = pm_generic_runtime_idle, |
955 | .resume = platform_pm_resume, | 907 | USE_PLATFORM_PM_SLEEP_OPS |
956 | .freeze = platform_pm_freeze, | ||
957 | .thaw = platform_pm_thaw, | ||
958 | .poweroff = platform_pm_poweroff, | ||
959 | .restore = platform_pm_restore, | ||
960 | .suspend_noirq = platform_pm_suspend_noirq, | ||
961 | .resume_noirq = platform_pm_resume_noirq, | ||
962 | .freeze_noirq = platform_pm_freeze_noirq, | ||
963 | .thaw_noirq = platform_pm_thaw_noirq, | ||
964 | .poweroff_noirq = platform_pm_poweroff_noirq, | ||
965 | .restore_noirq = platform_pm_restore_noirq, | ||
966 | .runtime_suspend = platform_pm_runtime_suspend, | ||
967 | .runtime_resume = platform_pm_runtime_resume, | ||
968 | .runtime_idle = platform_pm_runtime_idle, | ||
969 | }; | 908 | }; |
970 | 909 | ||
971 | struct bus_type platform_bus_type = { | 910 | struct bus_type platform_bus_type = { |
@@ -977,41 +916,6 @@ struct bus_type platform_bus_type = { | |||
977 | }; | 916 | }; |
978 | EXPORT_SYMBOL_GPL(platform_bus_type); | 917 | EXPORT_SYMBOL_GPL(platform_bus_type); |
979 | 918 | ||
980 | /** | ||
981 | * platform_bus_get_pm_ops() - return pointer to busses dev_pm_ops | ||
982 | * | ||
983 | * This function can be used by platform code to get the current | ||
984 | * set of dev_pm_ops functions used by the platform_bus_type. | ||
985 | */ | ||
986 | const struct dev_pm_ops * __init platform_bus_get_pm_ops(void) | ||
987 | { | ||
988 | return platform_bus_type.pm; | ||
989 | } | ||
990 | |||
991 | /** | ||
992 | * platform_bus_set_pm_ops() - update dev_pm_ops for the platform_bus_type | ||
993 | * | ||
994 | * @pm: pointer to new dev_pm_ops struct to be used for platform_bus_type | ||
995 | * | ||
996 | * Platform code can override the dev_pm_ops methods of | ||
997 | * platform_bus_type by using this function. It is expected that | ||
998 | * platform code will first do a platform_bus_get_pm_ops(), then | ||
999 | * kmemdup it, then customize selected methods and pass a pointer to | ||
1000 | * the new struct dev_pm_ops to this function. | ||
1001 | * | ||
1002 | * Since platform-specific code is customizing methods for *all* | ||
1003 | * devices (not just platform-specific devices) it is expected that | ||
1004 | * any custom overrides of these functions will keep existing behavior | ||
1005 | * and simply extend it. For example, any customization of the | ||
1006 | * runtime PM methods should continue to call the pm_generic_* | ||
1007 | * functions as the default ones do in addition to the | ||
1008 | * platform-specific behavior. | ||
1009 | */ | ||
1010 | void __init platform_bus_set_pm_ops(const struct dev_pm_ops *pm) | ||
1011 | { | ||
1012 | platform_bus_type.pm = pm; | ||
1013 | } | ||
1014 | |||
1015 | int __init platform_bus_init(void) | 919 | int __init platform_bus_init(void) |
1016 | { | 920 | { |
1017 | int error; | 921 | int error; |
diff --git a/drivers/base/power/Makefile b/drivers/base/power/Makefile index 118c1b92a511..3647e114d0e7 100644 --- a/drivers/base/power/Makefile +++ b/drivers/base/power/Makefile | |||
@@ -3,6 +3,6 @@ obj-$(CONFIG_PM_SLEEP) += main.o wakeup.o | |||
3 | obj-$(CONFIG_PM_RUNTIME) += runtime.o | 3 | obj-$(CONFIG_PM_RUNTIME) += runtime.o |
4 | obj-$(CONFIG_PM_TRACE_RTC) += trace.o | 4 | obj-$(CONFIG_PM_TRACE_RTC) += trace.o |
5 | obj-$(CONFIG_PM_OPP) += opp.o | 5 | obj-$(CONFIG_PM_OPP) += opp.o |
6 | obj-$(CONFIG_HAVE_CLK) += clock_ops.o | ||
6 | 7 | ||
7 | ccflags-$(CONFIG_DEBUG_DRIVER) := -DDEBUG | 8 | ccflags-$(CONFIG_DEBUG_DRIVER) := -DDEBUG \ No newline at end of file |
8 | ccflags-$(CONFIG_PM_VERBOSE) += -DDEBUG | ||
diff --git a/drivers/base/power/clock_ops.c b/drivers/base/power/clock_ops.c new file mode 100644 index 000000000000..c0dd09df7be8 --- /dev/null +++ b/drivers/base/power/clock_ops.c | |||
@@ -0,0 +1,431 @@ | |||
1 | /* | ||
2 | * drivers/base/power/clock_ops.c - Generic clock manipulation PM callbacks | ||
3 | * | ||
4 | * Copyright (c) 2011 Rafael J. Wysocki <rjw@sisk.pl>, Renesas Electronics Corp. | ||
5 | * | ||
6 | * This file is released under the GPLv2. | ||
7 | */ | ||
8 | |||
9 | #include <linux/init.h> | ||
10 | #include <linux/kernel.h> | ||
11 | #include <linux/io.h> | ||
12 | #include <linux/pm.h> | ||
13 | #include <linux/pm_runtime.h> | ||
14 | #include <linux/clk.h> | ||
15 | #include <linux/slab.h> | ||
16 | #include <linux/err.h> | ||
17 | |||
18 | #ifdef CONFIG_PM_RUNTIME | ||
19 | |||
20 | struct pm_runtime_clk_data { | ||
21 | struct list_head clock_list; | ||
22 | struct mutex lock; | ||
23 | }; | ||
24 | |||
25 | enum pce_status { | ||
26 | PCE_STATUS_NONE = 0, | ||
27 | PCE_STATUS_ACQUIRED, | ||
28 | PCE_STATUS_ENABLED, | ||
29 | PCE_STATUS_ERROR, | ||
30 | }; | ||
31 | |||
32 | struct pm_clock_entry { | ||
33 | struct list_head node; | ||
34 | char *con_id; | ||
35 | struct clk *clk; | ||
36 | enum pce_status status; | ||
37 | }; | ||
38 | |||
39 | static struct pm_runtime_clk_data *__to_prd(struct device *dev) | ||
40 | { | ||
41 | return dev ? dev->power.subsys_data : NULL; | ||
42 | } | ||
43 | |||
44 | /** | ||
45 | * pm_runtime_clk_add - Start using a device clock for runtime PM. | ||
46 | * @dev: Device whose clock is going to be used for runtime PM. | ||
47 | * @con_id: Connection ID of the clock. | ||
48 | * | ||
49 | * Add the clock represented by @con_id to the list of clocks used for | ||
50 | * the runtime PM of @dev. | ||
51 | */ | ||
52 | int pm_runtime_clk_add(struct device *dev, const char *con_id) | ||
53 | { | ||
54 | struct pm_runtime_clk_data *prd = __to_prd(dev); | ||
55 | struct pm_clock_entry *ce; | ||
56 | |||
57 | if (!prd) | ||
58 | return -EINVAL; | ||
59 | |||
60 | ce = kzalloc(sizeof(*ce), GFP_KERNEL); | ||
61 | if (!ce) { | ||
62 | dev_err(dev, "Not enough memory for clock entry.\n"); | ||
63 | return -ENOMEM; | ||
64 | } | ||
65 | |||
66 | if (con_id) { | ||
67 | ce->con_id = kstrdup(con_id, GFP_KERNEL); | ||
68 | if (!ce->con_id) { | ||
69 | dev_err(dev, | ||
70 | "Not enough memory for clock connection ID.\n"); | ||
71 | kfree(ce); | ||
72 | return -ENOMEM; | ||
73 | } | ||
74 | } | ||
75 | |||
76 | mutex_lock(&prd->lock); | ||
77 | list_add_tail(&ce->node, &prd->clock_list); | ||
78 | mutex_unlock(&prd->lock); | ||
79 | return 0; | ||
80 | } | ||
81 | |||
82 | /** | ||
83 | * __pm_runtime_clk_remove - Destroy runtime PM clock entry. | ||
84 | * @ce: Runtime PM clock entry to destroy. | ||
85 | * | ||
86 | * This routine must be called under the mutex protecting the runtime PM list | ||
87 | * of clocks corresponding the the @ce's device. | ||
88 | */ | ||
89 | static void __pm_runtime_clk_remove(struct pm_clock_entry *ce) | ||
90 | { | ||
91 | if (!ce) | ||
92 | return; | ||
93 | |||
94 | list_del(&ce->node); | ||
95 | |||
96 | if (ce->status < PCE_STATUS_ERROR) { | ||
97 | if (ce->status == PCE_STATUS_ENABLED) | ||
98 | clk_disable(ce->clk); | ||
99 | |||
100 | if (ce->status >= PCE_STATUS_ACQUIRED) | ||
101 | clk_put(ce->clk); | ||
102 | } | ||
103 | |||
104 | if (ce->con_id) | ||
105 | kfree(ce->con_id); | ||
106 | |||
107 | kfree(ce); | ||
108 | } | ||
109 | |||
110 | /** | ||
111 | * pm_runtime_clk_remove - Stop using a device clock for runtime PM. | ||
112 | * @dev: Device whose clock should not be used for runtime PM any more. | ||
113 | * @con_id: Connection ID of the clock. | ||
114 | * | ||
115 | * Remove the clock represented by @con_id from the list of clocks used for | ||
116 | * the runtime PM of @dev. | ||
117 | */ | ||
118 | void pm_runtime_clk_remove(struct device *dev, const char *con_id) | ||
119 | { | ||
120 | struct pm_runtime_clk_data *prd = __to_prd(dev); | ||
121 | struct pm_clock_entry *ce; | ||
122 | |||
123 | if (!prd) | ||
124 | return; | ||
125 | |||
126 | mutex_lock(&prd->lock); | ||
127 | |||
128 | list_for_each_entry(ce, &prd->clock_list, node) { | ||
129 | if (!con_id && !ce->con_id) { | ||
130 | __pm_runtime_clk_remove(ce); | ||
131 | break; | ||
132 | } else if (!con_id || !ce->con_id) { | ||
133 | continue; | ||
134 | } else if (!strcmp(con_id, ce->con_id)) { | ||
135 | __pm_runtime_clk_remove(ce); | ||
136 | break; | ||
137 | } | ||
138 | } | ||
139 | |||
140 | mutex_unlock(&prd->lock); | ||
141 | } | ||
142 | |||
143 | /** | ||
144 | * pm_runtime_clk_init - Initialize a device's list of runtime PM clocks. | ||
145 | * @dev: Device to initialize the list of runtime PM clocks for. | ||
146 | * | ||
147 | * Allocate a struct pm_runtime_clk_data object, initialize its lock member and | ||
148 | * make the @dev's power.subsys_data field point to it. | ||
149 | */ | ||
150 | int pm_runtime_clk_init(struct device *dev) | ||
151 | { | ||
152 | struct pm_runtime_clk_data *prd; | ||
153 | |||
154 | prd = kzalloc(sizeof(*prd), GFP_KERNEL); | ||
155 | if (!prd) { | ||
156 | dev_err(dev, "Not enough memory fo runtime PM data.\n"); | ||
157 | return -ENOMEM; | ||
158 | } | ||
159 | |||
160 | INIT_LIST_HEAD(&prd->clock_list); | ||
161 | mutex_init(&prd->lock); | ||
162 | dev->power.subsys_data = prd; | ||
163 | return 0; | ||
164 | } | ||
165 | |||
166 | /** | ||
167 | * pm_runtime_clk_destroy - Destroy a device's list of runtime PM clocks. | ||
168 | * @dev: Device to destroy the list of runtime PM clocks for. | ||
169 | * | ||
170 | * Clear the @dev's power.subsys_data field, remove the list of clock entries | ||
171 | * from the struct pm_runtime_clk_data object pointed to by it before and free | ||
172 | * that object. | ||
173 | */ | ||
174 | void pm_runtime_clk_destroy(struct device *dev) | ||
175 | { | ||
176 | struct pm_runtime_clk_data *prd = __to_prd(dev); | ||
177 | struct pm_clock_entry *ce, *c; | ||
178 | |||
179 | if (!prd) | ||
180 | return; | ||
181 | |||
182 | dev->power.subsys_data = NULL; | ||
183 | |||
184 | mutex_lock(&prd->lock); | ||
185 | |||
186 | list_for_each_entry_safe_reverse(ce, c, &prd->clock_list, node) | ||
187 | __pm_runtime_clk_remove(ce); | ||
188 | |||
189 | mutex_unlock(&prd->lock); | ||
190 | |||
191 | kfree(prd); | ||
192 | } | ||
193 | |||
194 | /** | ||
195 | * pm_runtime_clk_acquire - Acquire a device clock. | ||
196 | * @dev: Device whose clock is to be acquired. | ||
197 | * @con_id: Connection ID of the clock. | ||
198 | */ | ||
199 | static void pm_runtime_clk_acquire(struct device *dev, | ||
200 | struct pm_clock_entry *ce) | ||
201 | { | ||
202 | ce->clk = clk_get(dev, ce->con_id); | ||
203 | if (IS_ERR(ce->clk)) { | ||
204 | ce->status = PCE_STATUS_ERROR; | ||
205 | } else { | ||
206 | ce->status = PCE_STATUS_ACQUIRED; | ||
207 | dev_dbg(dev, "Clock %s managed by runtime PM.\n", ce->con_id); | ||
208 | } | ||
209 | } | ||
210 | |||
211 | /** | ||
212 | * pm_runtime_clk_suspend - Disable clocks in a device's runtime PM clock list. | ||
213 | * @dev: Device to disable the clocks for. | ||
214 | */ | ||
215 | int pm_runtime_clk_suspend(struct device *dev) | ||
216 | { | ||
217 | struct pm_runtime_clk_data *prd = __to_prd(dev); | ||
218 | struct pm_clock_entry *ce; | ||
219 | |||
220 | dev_dbg(dev, "%s()\n", __func__); | ||
221 | |||
222 | if (!prd) | ||
223 | return 0; | ||
224 | |||
225 | mutex_lock(&prd->lock); | ||
226 | |||
227 | list_for_each_entry_reverse(ce, &prd->clock_list, node) { | ||
228 | if (ce->status == PCE_STATUS_NONE) | ||
229 | pm_runtime_clk_acquire(dev, ce); | ||
230 | |||
231 | if (ce->status < PCE_STATUS_ERROR) { | ||
232 | clk_disable(ce->clk); | ||
233 | ce->status = PCE_STATUS_ACQUIRED; | ||
234 | } | ||
235 | } | ||
236 | |||
237 | mutex_unlock(&prd->lock); | ||
238 | |||
239 | return 0; | ||
240 | } | ||
241 | |||
242 | /** | ||
243 | * pm_runtime_clk_resume - Enable clocks in a device's runtime PM clock list. | ||
244 | * @dev: Device to enable the clocks for. | ||
245 | */ | ||
246 | int pm_runtime_clk_resume(struct device *dev) | ||
247 | { | ||
248 | struct pm_runtime_clk_data *prd = __to_prd(dev); | ||
249 | struct pm_clock_entry *ce; | ||
250 | |||
251 | dev_dbg(dev, "%s()\n", __func__); | ||
252 | |||
253 | if (!prd) | ||
254 | return 0; | ||
255 | |||
256 | mutex_lock(&prd->lock); | ||
257 | |||
258 | list_for_each_entry(ce, &prd->clock_list, node) { | ||
259 | if (ce->status == PCE_STATUS_NONE) | ||
260 | pm_runtime_clk_acquire(dev, ce); | ||
261 | |||
262 | if (ce->status < PCE_STATUS_ERROR) { | ||
263 | clk_enable(ce->clk); | ||
264 | ce->status = PCE_STATUS_ENABLED; | ||
265 | } | ||
266 | } | ||
267 | |||
268 | mutex_unlock(&prd->lock); | ||
269 | |||
270 | return 0; | ||
271 | } | ||
272 | |||
273 | /** | ||
274 | * pm_runtime_clk_notify - Notify routine for device addition and removal. | ||
275 | * @nb: Notifier block object this function is a member of. | ||
276 | * @action: Operation being carried out by the caller. | ||
277 | * @data: Device the routine is being run for. | ||
278 | * | ||
279 | * For this function to work, @nb must be a member of an object of type | ||
280 | * struct pm_clk_notifier_block containing all of the requisite data. | ||
281 | * Specifically, the pwr_domain member of that object is copied to the device's | ||
282 | * pwr_domain field and its con_ids member is used to populate the device's list | ||
283 | * of runtime PM clocks, depending on @action. | ||
284 | * | ||
285 | * If the device's pwr_domain field is already populated with a value different | ||
286 | * from the one stored in the struct pm_clk_notifier_block object, the function | ||
287 | * does nothing. | ||
288 | */ | ||
289 | static int pm_runtime_clk_notify(struct notifier_block *nb, | ||
290 | unsigned long action, void *data) | ||
291 | { | ||
292 | struct pm_clk_notifier_block *clknb; | ||
293 | struct device *dev = data; | ||
294 | char *con_id; | ||
295 | int error; | ||
296 | |||
297 | dev_dbg(dev, "%s() %ld\n", __func__, action); | ||
298 | |||
299 | clknb = container_of(nb, struct pm_clk_notifier_block, nb); | ||
300 | |||
301 | switch (action) { | ||
302 | case BUS_NOTIFY_ADD_DEVICE: | ||
303 | if (dev->pwr_domain) | ||
304 | break; | ||
305 | |||
306 | error = pm_runtime_clk_init(dev); | ||
307 | if (error) | ||
308 | break; | ||
309 | |||
310 | dev->pwr_domain = clknb->pwr_domain; | ||
311 | if (clknb->con_ids[0]) { | ||
312 | for (con_id = clknb->con_ids[0]; *con_id; con_id++) | ||
313 | pm_runtime_clk_add(dev, con_id); | ||
314 | } else { | ||
315 | pm_runtime_clk_add(dev, NULL); | ||
316 | } | ||
317 | |||
318 | break; | ||
319 | case BUS_NOTIFY_DEL_DEVICE: | ||
320 | if (dev->pwr_domain != clknb->pwr_domain) | ||
321 | break; | ||
322 | |||
323 | dev->pwr_domain = NULL; | ||
324 | pm_runtime_clk_destroy(dev); | ||
325 | break; | ||
326 | } | ||
327 | |||
328 | return 0; | ||
329 | } | ||
330 | |||
331 | #else /* !CONFIG_PM_RUNTIME */ | ||
332 | |||
333 | /** | ||
334 | * enable_clock - Enable a device clock. | ||
335 | * @dev: Device whose clock is to be enabled. | ||
336 | * @con_id: Connection ID of the clock. | ||
337 | */ | ||
338 | static void enable_clock(struct device *dev, const char *con_id) | ||
339 | { | ||
340 | struct clk *clk; | ||
341 | |||
342 | clk = clk_get(dev, con_id); | ||
343 | if (!IS_ERR(clk)) { | ||
344 | clk_enable(clk); | ||
345 | clk_put(clk); | ||
346 | dev_info(dev, "Runtime PM disabled, clock forced on.\n"); | ||
347 | } | ||
348 | } | ||
349 | |||
350 | /** | ||
351 | * disable_clock - Disable a device clock. | ||
352 | * @dev: Device whose clock is to be disabled. | ||
353 | * @con_id: Connection ID of the clock. | ||
354 | */ | ||
355 | static void disable_clock(struct device *dev, const char *con_id) | ||
356 | { | ||
357 | struct clk *clk; | ||
358 | |||
359 | clk = clk_get(dev, con_id); | ||
360 | if (!IS_ERR(clk)) { | ||
361 | clk_disable(clk); | ||
362 | clk_put(clk); | ||
363 | dev_info(dev, "Runtime PM disabled, clock forced off.\n"); | ||
364 | } | ||
365 | } | ||
366 | |||
367 | /** | ||
368 | * pm_runtime_clk_notify - Notify routine for device addition and removal. | ||
369 | * @nb: Notifier block object this function is a member of. | ||
370 | * @action: Operation being carried out by the caller. | ||
371 | * @data: Device the routine is being run for. | ||
372 | * | ||
373 | * For this function to work, @nb must be a member of an object of type | ||
374 | * struct pm_clk_notifier_block containing all of the requisite data. | ||
375 | * Specifically, the con_ids member of that object is used to enable or disable | ||
376 | * the device's clocks, depending on @action. | ||
377 | */ | ||
378 | static int pm_runtime_clk_notify(struct notifier_block *nb, | ||
379 | unsigned long action, void *data) | ||
380 | { | ||
381 | struct pm_clk_notifier_block *clknb; | ||
382 | struct device *dev = data; | ||
383 | char *con_id; | ||
384 | |||
385 | dev_dbg(dev, "%s() %ld\n", __func__, action); | ||
386 | |||
387 | clknb = container_of(nb, struct pm_clk_notifier_block, nb); | ||
388 | |||
389 | switch (action) { | ||
390 | case BUS_NOTIFY_ADD_DEVICE: | ||
391 | if (clknb->con_ids[0]) { | ||
392 | for (con_id = clknb->con_ids[0]; *con_id; con_id++) | ||
393 | enable_clock(dev, con_id); | ||
394 | } else { | ||
395 | enable_clock(dev, NULL); | ||
396 | } | ||
397 | break; | ||
398 | case BUS_NOTIFY_DEL_DEVICE: | ||
399 | if (clknb->con_ids[0]) { | ||
400 | for (con_id = clknb->con_ids[0]; *con_id; con_id++) | ||
401 | disable_clock(dev, con_id); | ||
402 | } else { | ||
403 | disable_clock(dev, NULL); | ||
404 | } | ||
405 | break; | ||
406 | } | ||
407 | |||
408 | return 0; | ||
409 | } | ||
410 | |||
411 | #endif /* !CONFIG_PM_RUNTIME */ | ||
412 | |||
413 | /** | ||
414 | * pm_runtime_clk_add_notifier - Add bus type notifier for runtime PM clocks. | ||
415 | * @bus: Bus type to add the notifier to. | ||
416 | * @clknb: Notifier to be added to the given bus type. | ||
417 | * | ||
418 | * The nb member of @clknb is not expected to be initialized and its | ||
419 | * notifier_call member will be replaced with pm_runtime_clk_notify(). However, | ||
420 | * the remaining members of @clknb should be populated prior to calling this | ||
421 | * routine. | ||
422 | */ | ||
423 | void pm_runtime_clk_add_notifier(struct bus_type *bus, | ||
424 | struct pm_clk_notifier_block *clknb) | ||
425 | { | ||
426 | if (!bus || !clknb) | ||
427 | return; | ||
428 | |||
429 | clknb->nb.notifier_call = pm_runtime_clk_notify; | ||
430 | bus_register_notifier(bus, &clknb->nb); | ||
431 | } | ||
diff --git a/drivers/base/power/generic_ops.c b/drivers/base/power/generic_ops.c index 42f97f925629..cb3bb368681c 100644 --- a/drivers/base/power/generic_ops.c +++ b/drivers/base/power/generic_ops.c | |||
@@ -74,6 +74,23 @@ EXPORT_SYMBOL_GPL(pm_generic_runtime_resume); | |||
74 | 74 | ||
75 | #ifdef CONFIG_PM_SLEEP | 75 | #ifdef CONFIG_PM_SLEEP |
76 | /** | 76 | /** |
77 | * pm_generic_prepare - Generic routine preparing a device for power transition. | ||
78 | * @dev: Device to prepare. | ||
79 | * | ||
80 | * Prepare a device for a system-wide power transition. | ||
81 | */ | ||
82 | int pm_generic_prepare(struct device *dev) | ||
83 | { | ||
84 | struct device_driver *drv = dev->driver; | ||
85 | int ret = 0; | ||
86 | |||
87 | if (drv && drv->pm && drv->pm->prepare) | ||
88 | ret = drv->pm->prepare(dev); | ||
89 | |||
90 | return ret; | ||
91 | } | ||
92 | |||
93 | /** | ||
77 | * __pm_generic_call - Generic suspend/freeze/poweroff/thaw subsystem callback. | 94 | * __pm_generic_call - Generic suspend/freeze/poweroff/thaw subsystem callback. |
78 | * @dev: Device to handle. | 95 | * @dev: Device to handle. |
79 | * @event: PM transition of the system under way. | 96 | * @event: PM transition of the system under way. |
@@ -213,16 +230,38 @@ int pm_generic_restore(struct device *dev) | |||
213 | return __pm_generic_resume(dev, PM_EVENT_RESTORE); | 230 | return __pm_generic_resume(dev, PM_EVENT_RESTORE); |
214 | } | 231 | } |
215 | EXPORT_SYMBOL_GPL(pm_generic_restore); | 232 | EXPORT_SYMBOL_GPL(pm_generic_restore); |
233 | |||
234 | /** | ||
235 | * pm_generic_complete - Generic routine competing a device power transition. | ||
236 | * @dev: Device to handle. | ||
237 | * | ||
238 | * Complete a device power transition during a system-wide power transition. | ||
239 | */ | ||
240 | void pm_generic_complete(struct device *dev) | ||
241 | { | ||
242 | struct device_driver *drv = dev->driver; | ||
243 | |||
244 | if (drv && drv->pm && drv->pm->complete) | ||
245 | drv->pm->complete(dev); | ||
246 | |||
247 | /* | ||
248 | * Let runtime PM try to suspend devices that haven't been in use before | ||
249 | * going into the system-wide sleep state we're resuming from. | ||
250 | */ | ||
251 | pm_runtime_idle(dev); | ||
252 | } | ||
216 | #endif /* CONFIG_PM_SLEEP */ | 253 | #endif /* CONFIG_PM_SLEEP */ |
217 | 254 | ||
218 | struct dev_pm_ops generic_subsys_pm_ops = { | 255 | struct dev_pm_ops generic_subsys_pm_ops = { |
219 | #ifdef CONFIG_PM_SLEEP | 256 | #ifdef CONFIG_PM_SLEEP |
257 | .prepare = pm_generic_prepare, | ||
220 | .suspend = pm_generic_suspend, | 258 | .suspend = pm_generic_suspend, |
221 | .resume = pm_generic_resume, | 259 | .resume = pm_generic_resume, |
222 | .freeze = pm_generic_freeze, | 260 | .freeze = pm_generic_freeze, |
223 | .thaw = pm_generic_thaw, | 261 | .thaw = pm_generic_thaw, |
224 | .poweroff = pm_generic_poweroff, | 262 | .poweroff = pm_generic_poweroff, |
225 | .restore = pm_generic_restore, | 263 | .restore = pm_generic_restore, |
264 | .complete = pm_generic_complete, | ||
226 | #endif | 265 | #endif |
227 | #ifdef CONFIG_PM_RUNTIME | 266 | #ifdef CONFIG_PM_RUNTIME |
228 | .runtime_suspend = pm_generic_runtime_suspend, | 267 | .runtime_suspend = pm_generic_runtime_suspend, |
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c index abe3ab709e87..aa6320207745 100644 --- a/drivers/base/power/main.c +++ b/drivers/base/power/main.c | |||
@@ -426,10 +426,8 @@ static int device_resume_noirq(struct device *dev, pm_message_t state) | |||
426 | 426 | ||
427 | if (dev->pwr_domain) { | 427 | if (dev->pwr_domain) { |
428 | pm_dev_dbg(dev, state, "EARLY power domain "); | 428 | pm_dev_dbg(dev, state, "EARLY power domain "); |
429 | pm_noirq_op(dev, &dev->pwr_domain->ops, state); | 429 | error = pm_noirq_op(dev, &dev->pwr_domain->ops, state); |
430 | } | 430 | } else if (dev->type && dev->type->pm) { |
431 | |||
432 | if (dev->type && dev->type->pm) { | ||
433 | pm_dev_dbg(dev, state, "EARLY type "); | 431 | pm_dev_dbg(dev, state, "EARLY type "); |
434 | error = pm_noirq_op(dev, dev->type->pm, state); | 432 | error = pm_noirq_op(dev, dev->type->pm, state); |
435 | } else if (dev->class && dev->class->pm) { | 433 | } else if (dev->class && dev->class->pm) { |
@@ -517,7 +515,8 @@ static int device_resume(struct device *dev, pm_message_t state, bool async) | |||
517 | 515 | ||
518 | if (dev->pwr_domain) { | 516 | if (dev->pwr_domain) { |
519 | pm_dev_dbg(dev, state, "power domain "); | 517 | pm_dev_dbg(dev, state, "power domain "); |
520 | pm_op(dev, &dev->pwr_domain->ops, state); | 518 | error = pm_op(dev, &dev->pwr_domain->ops, state); |
519 | goto End; | ||
521 | } | 520 | } |
522 | 521 | ||
523 | if (dev->type && dev->type->pm) { | 522 | if (dev->type && dev->type->pm) { |
@@ -580,11 +579,13 @@ static bool is_async(struct device *dev) | |||
580 | * Execute the appropriate "resume" callback for all devices whose status | 579 | * Execute the appropriate "resume" callback for all devices whose status |
581 | * indicates that they are suspended. | 580 | * indicates that they are suspended. |
582 | */ | 581 | */ |
583 | static void dpm_resume(pm_message_t state) | 582 | void dpm_resume(pm_message_t state) |
584 | { | 583 | { |
585 | struct device *dev; | 584 | struct device *dev; |
586 | ktime_t starttime = ktime_get(); | 585 | ktime_t starttime = ktime_get(); |
587 | 586 | ||
587 | might_sleep(); | ||
588 | |||
588 | mutex_lock(&dpm_list_mtx); | 589 | mutex_lock(&dpm_list_mtx); |
589 | pm_transition = state; | 590 | pm_transition = state; |
590 | async_error = 0; | 591 | async_error = 0; |
@@ -629,12 +630,11 @@ static void device_complete(struct device *dev, pm_message_t state) | |||
629 | { | 630 | { |
630 | device_lock(dev); | 631 | device_lock(dev); |
631 | 632 | ||
632 | if (dev->pwr_domain && dev->pwr_domain->ops.complete) { | 633 | if (dev->pwr_domain) { |
633 | pm_dev_dbg(dev, state, "completing power domain "); | 634 | pm_dev_dbg(dev, state, "completing power domain "); |
634 | dev->pwr_domain->ops.complete(dev); | 635 | if (dev->pwr_domain->ops.complete) |
635 | } | 636 | dev->pwr_domain->ops.complete(dev); |
636 | 637 | } else if (dev->type && dev->type->pm) { | |
637 | if (dev->type && dev->type->pm) { | ||
638 | pm_dev_dbg(dev, state, "completing type "); | 638 | pm_dev_dbg(dev, state, "completing type "); |
639 | if (dev->type->pm->complete) | 639 | if (dev->type->pm->complete) |
640 | dev->type->pm->complete(dev); | 640 | dev->type->pm->complete(dev); |
@@ -658,10 +658,12 @@ static void device_complete(struct device *dev, pm_message_t state) | |||
658 | * Execute the ->complete() callbacks for all devices whose PM status is not | 658 | * Execute the ->complete() callbacks for all devices whose PM status is not |
659 | * DPM_ON (this allows new devices to be registered). | 659 | * DPM_ON (this allows new devices to be registered). |
660 | */ | 660 | */ |
661 | static void dpm_complete(pm_message_t state) | 661 | void dpm_complete(pm_message_t state) |
662 | { | 662 | { |
663 | struct list_head list; | 663 | struct list_head list; |
664 | 664 | ||
665 | might_sleep(); | ||
666 | |||
665 | INIT_LIST_HEAD(&list); | 667 | INIT_LIST_HEAD(&list); |
666 | mutex_lock(&dpm_list_mtx); | 668 | mutex_lock(&dpm_list_mtx); |
667 | while (!list_empty(&dpm_prepared_list)) { | 669 | while (!list_empty(&dpm_prepared_list)) { |
@@ -690,7 +692,6 @@ static void dpm_complete(pm_message_t state) | |||
690 | */ | 692 | */ |
691 | void dpm_resume_end(pm_message_t state) | 693 | void dpm_resume_end(pm_message_t state) |
692 | { | 694 | { |
693 | might_sleep(); | ||
694 | dpm_resume(state); | 695 | dpm_resume(state); |
695 | dpm_complete(state); | 696 | dpm_complete(state); |
696 | } | 697 | } |
@@ -732,7 +733,12 @@ static int device_suspend_noirq(struct device *dev, pm_message_t state) | |||
732 | { | 733 | { |
733 | int error; | 734 | int error; |
734 | 735 | ||
735 | if (dev->type && dev->type->pm) { | 736 | if (dev->pwr_domain) { |
737 | pm_dev_dbg(dev, state, "LATE power domain "); | ||
738 | error = pm_noirq_op(dev, &dev->pwr_domain->ops, state); | ||
739 | if (error) | ||
740 | return error; | ||
741 | } else if (dev->type && dev->type->pm) { | ||
736 | pm_dev_dbg(dev, state, "LATE type "); | 742 | pm_dev_dbg(dev, state, "LATE type "); |
737 | error = pm_noirq_op(dev, dev->type->pm, state); | 743 | error = pm_noirq_op(dev, dev->type->pm, state); |
738 | if (error) | 744 | if (error) |
@@ -749,11 +755,6 @@ static int device_suspend_noirq(struct device *dev, pm_message_t state) | |||
749 | return error; | 755 | return error; |
750 | } | 756 | } |
751 | 757 | ||
752 | if (dev->pwr_domain) { | ||
753 | pm_dev_dbg(dev, state, "LATE power domain "); | ||
754 | pm_noirq_op(dev, &dev->pwr_domain->ops, state); | ||
755 | } | ||
756 | |||
757 | return 0; | 758 | return 0; |
758 | } | 759 | } |
759 | 760 | ||
@@ -841,21 +842,27 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async) | |||
841 | goto End; | 842 | goto End; |
842 | } | 843 | } |
843 | 844 | ||
845 | if (dev->pwr_domain) { | ||
846 | pm_dev_dbg(dev, state, "power domain "); | ||
847 | error = pm_op(dev, &dev->pwr_domain->ops, state); | ||
848 | goto End; | ||
849 | } | ||
850 | |||
844 | if (dev->type && dev->type->pm) { | 851 | if (dev->type && dev->type->pm) { |
845 | pm_dev_dbg(dev, state, "type "); | 852 | pm_dev_dbg(dev, state, "type "); |
846 | error = pm_op(dev, dev->type->pm, state); | 853 | error = pm_op(dev, dev->type->pm, state); |
847 | goto Domain; | 854 | goto End; |
848 | } | 855 | } |
849 | 856 | ||
850 | if (dev->class) { | 857 | if (dev->class) { |
851 | if (dev->class->pm) { | 858 | if (dev->class->pm) { |
852 | pm_dev_dbg(dev, state, "class "); | 859 | pm_dev_dbg(dev, state, "class "); |
853 | error = pm_op(dev, dev->class->pm, state); | 860 | error = pm_op(dev, dev->class->pm, state); |
854 | goto Domain; | 861 | goto End; |
855 | } else if (dev->class->suspend) { | 862 | } else if (dev->class->suspend) { |
856 | pm_dev_dbg(dev, state, "legacy class "); | 863 | pm_dev_dbg(dev, state, "legacy class "); |
857 | error = legacy_suspend(dev, state, dev->class->suspend); | 864 | error = legacy_suspend(dev, state, dev->class->suspend); |
858 | goto Domain; | 865 | goto End; |
859 | } | 866 | } |
860 | } | 867 | } |
861 | 868 | ||
@@ -869,12 +876,6 @@ static int __device_suspend(struct device *dev, pm_message_t state, bool async) | |||
869 | } | 876 | } |
870 | } | 877 | } |
871 | 878 | ||
872 | Domain: | ||
873 | if (!error && dev->pwr_domain) { | ||
874 | pm_dev_dbg(dev, state, "power domain "); | ||
875 | pm_op(dev, &dev->pwr_domain->ops, state); | ||
876 | } | ||
877 | |||
878 | End: | 879 | End: |
879 | device_unlock(dev); | 880 | device_unlock(dev); |
880 | complete_all(&dev->power.completion); | 881 | complete_all(&dev->power.completion); |
@@ -914,11 +915,13 @@ static int device_suspend(struct device *dev) | |||
914 | * dpm_suspend - Execute "suspend" callbacks for all non-sysdev devices. | 915 | * dpm_suspend - Execute "suspend" callbacks for all non-sysdev devices. |
915 | * @state: PM transition of the system being carried out. | 916 | * @state: PM transition of the system being carried out. |
916 | */ | 917 | */ |
917 | static int dpm_suspend(pm_message_t state) | 918 | int dpm_suspend(pm_message_t state) |
918 | { | 919 | { |
919 | ktime_t starttime = ktime_get(); | 920 | ktime_t starttime = ktime_get(); |
920 | int error = 0; | 921 | int error = 0; |
921 | 922 | ||
923 | might_sleep(); | ||
924 | |||
922 | mutex_lock(&dpm_list_mtx); | 925 | mutex_lock(&dpm_list_mtx); |
923 | pm_transition = state; | 926 | pm_transition = state; |
924 | async_error = 0; | 927 | async_error = 0; |
@@ -965,7 +968,14 @@ static int device_prepare(struct device *dev, pm_message_t state) | |||
965 | 968 | ||
966 | device_lock(dev); | 969 | device_lock(dev); |
967 | 970 | ||
968 | if (dev->type && dev->type->pm) { | 971 | if (dev->pwr_domain) { |
972 | pm_dev_dbg(dev, state, "preparing power domain "); | ||
973 | if (dev->pwr_domain->ops.prepare) | ||
974 | error = dev->pwr_domain->ops.prepare(dev); | ||
975 | suspend_report_result(dev->pwr_domain->ops.prepare, error); | ||
976 | if (error) | ||
977 | goto End; | ||
978 | } else if (dev->type && dev->type->pm) { | ||
969 | pm_dev_dbg(dev, state, "preparing type "); | 979 | pm_dev_dbg(dev, state, "preparing type "); |
970 | if (dev->type->pm->prepare) | 980 | if (dev->type->pm->prepare) |
971 | error = dev->type->pm->prepare(dev); | 981 | error = dev->type->pm->prepare(dev); |
@@ -984,13 +994,6 @@ static int device_prepare(struct device *dev, pm_message_t state) | |||
984 | if (dev->bus->pm->prepare) | 994 | if (dev->bus->pm->prepare) |
985 | error = dev->bus->pm->prepare(dev); | 995 | error = dev->bus->pm->prepare(dev); |
986 | suspend_report_result(dev->bus->pm->prepare, error); | 996 | suspend_report_result(dev->bus->pm->prepare, error); |
987 | if (error) | ||
988 | goto End; | ||
989 | } | ||
990 | |||
991 | if (dev->pwr_domain && dev->pwr_domain->ops.prepare) { | ||
992 | pm_dev_dbg(dev, state, "preparing power domain "); | ||
993 | dev->pwr_domain->ops.prepare(dev); | ||
994 | } | 997 | } |
995 | 998 | ||
996 | End: | 999 | End: |
@@ -1005,10 +1008,12 @@ static int device_prepare(struct device *dev, pm_message_t state) | |||
1005 | * | 1008 | * |
1006 | * Execute the ->prepare() callback(s) for all devices. | 1009 | * Execute the ->prepare() callback(s) for all devices. |
1007 | */ | 1010 | */ |
1008 | static int dpm_prepare(pm_message_t state) | 1011 | int dpm_prepare(pm_message_t state) |
1009 | { | 1012 | { |
1010 | int error = 0; | 1013 | int error = 0; |
1011 | 1014 | ||
1015 | might_sleep(); | ||
1016 | |||
1012 | mutex_lock(&dpm_list_mtx); | 1017 | mutex_lock(&dpm_list_mtx); |
1013 | while (!list_empty(&dpm_list)) { | 1018 | while (!list_empty(&dpm_list)) { |
1014 | struct device *dev = to_device(dpm_list.next); | 1019 | struct device *dev = to_device(dpm_list.next); |
@@ -1057,7 +1062,6 @@ int dpm_suspend_start(pm_message_t state) | |||
1057 | { | 1062 | { |
1058 | int error; | 1063 | int error; |
1059 | 1064 | ||
1060 | might_sleep(); | ||
1061 | error = dpm_prepare(state); | 1065 | error = dpm_prepare(state); |
1062 | if (!error) | 1066 | if (!error) |
1063 | error = dpm_suspend(state); | 1067 | error = dpm_suspend(state); |
diff --git a/drivers/base/power/runtime.c b/drivers/base/power/runtime.c index 3172c60d23a9..0d4587b15c55 100644 --- a/drivers/base/power/runtime.c +++ b/drivers/base/power/runtime.c | |||
@@ -168,7 +168,6 @@ static int rpm_check_suspend_allowed(struct device *dev) | |||
168 | static int rpm_idle(struct device *dev, int rpmflags) | 168 | static int rpm_idle(struct device *dev, int rpmflags) |
169 | { | 169 | { |
170 | int (*callback)(struct device *); | 170 | int (*callback)(struct device *); |
171 | int (*domain_callback)(struct device *); | ||
172 | int retval; | 171 | int retval; |
173 | 172 | ||
174 | retval = rpm_check_suspend_allowed(dev); | 173 | retval = rpm_check_suspend_allowed(dev); |
@@ -214,7 +213,9 @@ static int rpm_idle(struct device *dev, int rpmflags) | |||
214 | 213 | ||
215 | dev->power.idle_notification = true; | 214 | dev->power.idle_notification = true; |
216 | 215 | ||
217 | if (dev->type && dev->type->pm) | 216 | if (dev->pwr_domain) |
217 | callback = dev->pwr_domain->ops.runtime_idle; | ||
218 | else if (dev->type && dev->type->pm) | ||
218 | callback = dev->type->pm->runtime_idle; | 219 | callback = dev->type->pm->runtime_idle; |
219 | else if (dev->class && dev->class->pm) | 220 | else if (dev->class && dev->class->pm) |
220 | callback = dev->class->pm->runtime_idle; | 221 | callback = dev->class->pm->runtime_idle; |
@@ -223,19 +224,10 @@ static int rpm_idle(struct device *dev, int rpmflags) | |||
223 | else | 224 | else |
224 | callback = NULL; | 225 | callback = NULL; |
225 | 226 | ||
226 | if (dev->pwr_domain) | 227 | if (callback) { |
227 | domain_callback = dev->pwr_domain->ops.runtime_idle; | ||
228 | else | ||
229 | domain_callback = NULL; | ||
230 | |||
231 | if (callback || domain_callback) { | ||
232 | spin_unlock_irq(&dev->power.lock); | 228 | spin_unlock_irq(&dev->power.lock); |
233 | 229 | ||
234 | if (domain_callback) | 230 | callback(dev); |
235 | retval = domain_callback(dev); | ||
236 | |||
237 | if (!retval && callback) | ||
238 | callback(dev); | ||
239 | 231 | ||
240 | spin_lock_irq(&dev->power.lock); | 232 | spin_lock_irq(&dev->power.lock); |
241 | } | 233 | } |
@@ -382,7 +374,9 @@ static int rpm_suspend(struct device *dev, int rpmflags) | |||
382 | 374 | ||
383 | __update_runtime_status(dev, RPM_SUSPENDING); | 375 | __update_runtime_status(dev, RPM_SUSPENDING); |
384 | 376 | ||
385 | if (dev->type && dev->type->pm) | 377 | if (dev->pwr_domain) |
378 | callback = dev->pwr_domain->ops.runtime_suspend; | ||
379 | else if (dev->type && dev->type->pm) | ||
386 | callback = dev->type->pm->runtime_suspend; | 380 | callback = dev->type->pm->runtime_suspend; |
387 | else if (dev->class && dev->class->pm) | 381 | else if (dev->class && dev->class->pm) |
388 | callback = dev->class->pm->runtime_suspend; | 382 | callback = dev->class->pm->runtime_suspend; |
@@ -400,8 +394,6 @@ static int rpm_suspend(struct device *dev, int rpmflags) | |||
400 | else | 394 | else |
401 | pm_runtime_cancel_pending(dev); | 395 | pm_runtime_cancel_pending(dev); |
402 | } else { | 396 | } else { |
403 | if (dev->pwr_domain) | ||
404 | rpm_callback(dev->pwr_domain->ops.runtime_suspend, dev); | ||
405 | no_callback: | 397 | no_callback: |
406 | __update_runtime_status(dev, RPM_SUSPENDED); | 398 | __update_runtime_status(dev, RPM_SUSPENDED); |
407 | pm_runtime_deactivate_timer(dev); | 399 | pm_runtime_deactivate_timer(dev); |
@@ -582,9 +574,8 @@ static int rpm_resume(struct device *dev, int rpmflags) | |||
582 | __update_runtime_status(dev, RPM_RESUMING); | 574 | __update_runtime_status(dev, RPM_RESUMING); |
583 | 575 | ||
584 | if (dev->pwr_domain) | 576 | if (dev->pwr_domain) |
585 | rpm_callback(dev->pwr_domain->ops.runtime_resume, dev); | 577 | callback = dev->pwr_domain->ops.runtime_resume; |
586 | 578 | else if (dev->type && dev->type->pm) | |
587 | if (dev->type && dev->type->pm) | ||
588 | callback = dev->type->pm->runtime_resume; | 579 | callback = dev->type->pm->runtime_resume; |
589 | else if (dev->class && dev->class->pm) | 580 | else if (dev->class && dev->class->pm) |
590 | callback = dev->class->pm->runtime_resume; | 581 | callback = dev->class->pm->runtime_resume; |
diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c index fff49bee781d..a9f5b8979611 100644 --- a/drivers/base/power/sysfs.c +++ b/drivers/base/power/sysfs.c | |||
@@ -212,8 +212,9 @@ static ssize_t autosuspend_delay_ms_store(struct device *dev, | |||
212 | static DEVICE_ATTR(autosuspend_delay_ms, 0644, autosuspend_delay_ms_show, | 212 | static DEVICE_ATTR(autosuspend_delay_ms, 0644, autosuspend_delay_ms_show, |
213 | autosuspend_delay_ms_store); | 213 | autosuspend_delay_ms_store); |
214 | 214 | ||
215 | #endif | 215 | #endif /* CONFIG_PM_RUNTIME */ |
216 | 216 | ||
217 | #ifdef CONFIG_PM_SLEEP | ||
217 | static ssize_t | 218 | static ssize_t |
218 | wake_show(struct device * dev, struct device_attribute *attr, char * buf) | 219 | wake_show(struct device * dev, struct device_attribute *attr, char * buf) |
219 | { | 220 | { |
@@ -248,7 +249,6 @@ wake_store(struct device * dev, struct device_attribute *attr, | |||
248 | 249 | ||
249 | static DEVICE_ATTR(wakeup, 0644, wake_show, wake_store); | 250 | static DEVICE_ATTR(wakeup, 0644, wake_show, wake_store); |
250 | 251 | ||
251 | #ifdef CONFIG_PM_SLEEP | ||
252 | static ssize_t wakeup_count_show(struct device *dev, | 252 | static ssize_t wakeup_count_show(struct device *dev, |
253 | struct device_attribute *attr, char *buf) | 253 | struct device_attribute *attr, char *buf) |
254 | { | 254 | { |
diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c index abbbd33e8d8a..84f7c7d5a098 100644 --- a/drivers/base/power/wakeup.c +++ b/drivers/base/power/wakeup.c | |||
@@ -110,7 +110,6 @@ void wakeup_source_add(struct wakeup_source *ws) | |||
110 | spin_lock_irq(&events_lock); | 110 | spin_lock_irq(&events_lock); |
111 | list_add_rcu(&ws->entry, &wakeup_sources); | 111 | list_add_rcu(&ws->entry, &wakeup_sources); |
112 | spin_unlock_irq(&events_lock); | 112 | spin_unlock_irq(&events_lock); |
113 | synchronize_rcu(); | ||
114 | } | 113 | } |
115 | EXPORT_SYMBOL_GPL(wakeup_source_add); | 114 | EXPORT_SYMBOL_GPL(wakeup_source_add); |
116 | 115 | ||
diff --git a/drivers/base/sys.c b/drivers/base/sys.c index acde9b5ee131..9dff77bfe1e3 100644 --- a/drivers/base/sys.c +++ b/drivers/base/sys.c | |||
@@ -328,203 +328,8 @@ void sysdev_unregister(struct sys_device *sysdev) | |||
328 | kobject_put(&sysdev->kobj); | 328 | kobject_put(&sysdev->kobj); |
329 | } | 329 | } |
330 | 330 | ||
331 | 331 | EXPORT_SYMBOL_GPL(sysdev_register); | |
332 | #ifndef CONFIG_ARCH_NO_SYSDEV_OPS | 332 | EXPORT_SYMBOL_GPL(sysdev_unregister); |
333 | /** | ||
334 | * sysdev_shutdown - Shut down all system devices. | ||
335 | * | ||
336 | * Loop over each class of system devices, and the devices in each | ||
337 | * of those classes. For each device, we call the shutdown method for | ||
338 | * each driver registered for the device - the auxiliaries, | ||
339 | * and the class driver. | ||
340 | * | ||
341 | * Note: The list is iterated in reverse order, so that we shut down | ||
342 | * child devices before we shut down their parents. The list ordering | ||
343 | * is guaranteed by virtue of the fact that child devices are registered | ||
344 | * after their parents. | ||
345 | */ | ||
346 | void sysdev_shutdown(void) | ||
347 | { | ||
348 | struct sysdev_class *cls; | ||
349 | |||
350 | pr_debug("Shutting Down System Devices\n"); | ||
351 | |||
352 | mutex_lock(&sysdev_drivers_lock); | ||
353 | list_for_each_entry_reverse(cls, &system_kset->list, kset.kobj.entry) { | ||
354 | struct sys_device *sysdev; | ||
355 | |||
356 | pr_debug("Shutting down type '%s':\n", | ||
357 | kobject_name(&cls->kset.kobj)); | ||
358 | |||
359 | list_for_each_entry(sysdev, &cls->kset.list, kobj.entry) { | ||
360 | struct sysdev_driver *drv; | ||
361 | pr_debug(" %s\n", kobject_name(&sysdev->kobj)); | ||
362 | |||
363 | /* Call auxiliary drivers first */ | ||
364 | list_for_each_entry(drv, &cls->drivers, entry) { | ||
365 | if (drv->shutdown) | ||
366 | drv->shutdown(sysdev); | ||
367 | } | ||
368 | |||
369 | /* Now call the generic one */ | ||
370 | if (cls->shutdown) | ||
371 | cls->shutdown(sysdev); | ||
372 | } | ||
373 | } | ||
374 | mutex_unlock(&sysdev_drivers_lock); | ||
375 | } | ||
376 | |||
377 | static void __sysdev_resume(struct sys_device *dev) | ||
378 | { | ||
379 | struct sysdev_class *cls = dev->cls; | ||
380 | struct sysdev_driver *drv; | ||
381 | |||
382 | /* First, call the class-specific one */ | ||
383 | if (cls->resume) | ||
384 | cls->resume(dev); | ||
385 | WARN_ONCE(!irqs_disabled(), | ||
386 | "Interrupts enabled after %pF\n", cls->resume); | ||
387 | |||
388 | /* Call auxiliary drivers next. */ | ||
389 | list_for_each_entry(drv, &cls->drivers, entry) { | ||
390 | if (drv->resume) | ||
391 | drv->resume(dev); | ||
392 | WARN_ONCE(!irqs_disabled(), | ||
393 | "Interrupts enabled after %pF\n", drv->resume); | ||
394 | } | ||
395 | } | ||
396 | |||
397 | /** | ||
398 | * sysdev_suspend - Suspend all system devices. | ||
399 | * @state: Power state to enter. | ||
400 | * | ||
401 | * We perform an almost identical operation as sysdev_shutdown() | ||
402 | * above, though calling ->suspend() instead. Interrupts are disabled | ||
403 | * when this called. Devices are responsible for both saving state and | ||
404 | * quiescing or powering down the device. | ||
405 | * | ||
406 | * This is only called by the device PM core, so we let them handle | ||
407 | * all synchronization. | ||
408 | */ | ||
409 | int sysdev_suspend(pm_message_t state) | ||
410 | { | ||
411 | struct sysdev_class *cls; | ||
412 | struct sys_device *sysdev, *err_dev; | ||
413 | struct sysdev_driver *drv, *err_drv; | ||
414 | int ret; | ||
415 | |||
416 | pr_debug("Checking wake-up interrupts\n"); | ||
417 | |||
418 | /* Return error code if there are any wake-up interrupts pending */ | ||
419 | ret = check_wakeup_irqs(); | ||
420 | if (ret) | ||
421 | return ret; | ||
422 | |||
423 | WARN_ONCE(!irqs_disabled(), | ||
424 | "Interrupts enabled while suspending system devices\n"); | ||
425 | |||
426 | pr_debug("Suspending System Devices\n"); | ||
427 | |||
428 | list_for_each_entry_reverse(cls, &system_kset->list, kset.kobj.entry) { | ||
429 | pr_debug("Suspending type '%s':\n", | ||
430 | kobject_name(&cls->kset.kobj)); | ||
431 | |||
432 | list_for_each_entry(sysdev, &cls->kset.list, kobj.entry) { | ||
433 | pr_debug(" %s\n", kobject_name(&sysdev->kobj)); | ||
434 | |||
435 | /* Call auxiliary drivers first */ | ||
436 | list_for_each_entry(drv, &cls->drivers, entry) { | ||
437 | if (drv->suspend) { | ||
438 | ret = drv->suspend(sysdev, state); | ||
439 | if (ret) | ||
440 | goto aux_driver; | ||
441 | } | ||
442 | WARN_ONCE(!irqs_disabled(), | ||
443 | "Interrupts enabled after %pF\n", | ||
444 | drv->suspend); | ||
445 | } | ||
446 | |||
447 | /* Now call the generic one */ | ||
448 | if (cls->suspend) { | ||
449 | ret = cls->suspend(sysdev, state); | ||
450 | if (ret) | ||
451 | goto cls_driver; | ||
452 | WARN_ONCE(!irqs_disabled(), | ||
453 | "Interrupts enabled after %pF\n", | ||
454 | cls->suspend); | ||
455 | } | ||
456 | } | ||
457 | } | ||
458 | return 0; | ||
459 | /* resume current sysdev */ | ||
460 | cls_driver: | ||
461 | drv = NULL; | ||
462 | printk(KERN_ERR "Class suspend failed for %s: %d\n", | ||
463 | kobject_name(&sysdev->kobj), ret); | ||
464 | |||
465 | aux_driver: | ||
466 | if (drv) | ||
467 | printk(KERN_ERR "Class driver suspend failed for %s: %d\n", | ||
468 | kobject_name(&sysdev->kobj), ret); | ||
469 | list_for_each_entry(err_drv, &cls->drivers, entry) { | ||
470 | if (err_drv == drv) | ||
471 | break; | ||
472 | if (err_drv->resume) | ||
473 | err_drv->resume(sysdev); | ||
474 | } | ||
475 | |||
476 | /* resume other sysdevs in current class */ | ||
477 | list_for_each_entry(err_dev, &cls->kset.list, kobj.entry) { | ||
478 | if (err_dev == sysdev) | ||
479 | break; | ||
480 | pr_debug(" %s\n", kobject_name(&err_dev->kobj)); | ||
481 | __sysdev_resume(err_dev); | ||
482 | } | ||
483 | |||
484 | /* resume other classes */ | ||
485 | list_for_each_entry_continue(cls, &system_kset->list, kset.kobj.entry) { | ||
486 | list_for_each_entry(err_dev, &cls->kset.list, kobj.entry) { | ||
487 | pr_debug(" %s\n", kobject_name(&err_dev->kobj)); | ||
488 | __sysdev_resume(err_dev); | ||
489 | } | ||
490 | } | ||
491 | return ret; | ||
492 | } | ||
493 | EXPORT_SYMBOL_GPL(sysdev_suspend); | ||
494 | |||
495 | /** | ||
496 | * sysdev_resume - Bring system devices back to life. | ||
497 | * | ||
498 | * Similar to sysdev_suspend(), but we iterate the list forwards | ||
499 | * to guarantee that parent devices are resumed before their children. | ||
500 | * | ||
501 | * Note: Interrupts are disabled when called. | ||
502 | */ | ||
503 | int sysdev_resume(void) | ||
504 | { | ||
505 | struct sysdev_class *cls; | ||
506 | |||
507 | WARN_ONCE(!irqs_disabled(), | ||
508 | "Interrupts enabled while resuming system devices\n"); | ||
509 | |||
510 | pr_debug("Resuming System Devices\n"); | ||
511 | |||
512 | list_for_each_entry(cls, &system_kset->list, kset.kobj.entry) { | ||
513 | struct sys_device *sysdev; | ||
514 | |||
515 | pr_debug("Resuming type '%s':\n", | ||
516 | kobject_name(&cls->kset.kobj)); | ||
517 | |||
518 | list_for_each_entry(sysdev, &cls->kset.list, kobj.entry) { | ||
519 | pr_debug(" %s\n", kobject_name(&sysdev->kobj)); | ||
520 | |||
521 | __sysdev_resume(sysdev); | ||
522 | } | ||
523 | } | ||
524 | return 0; | ||
525 | } | ||
526 | EXPORT_SYMBOL_GPL(sysdev_resume); | ||
527 | #endif /* CONFIG_ARCH_NO_SYSDEV_OPS */ | ||
528 | 333 | ||
529 | int __init system_bus_init(void) | 334 | int __init system_bus_init(void) |
530 | { | 335 | { |
@@ -534,9 +339,6 @@ int __init system_bus_init(void) | |||
534 | return 0; | 339 | return 0; |
535 | } | 340 | } |
536 | 341 | ||
537 | EXPORT_SYMBOL_GPL(sysdev_register); | ||
538 | EXPORT_SYMBOL_GPL(sysdev_unregister); | ||
539 | |||
540 | #define to_ext_attr(x) container_of(x, struct sysdev_ext_attribute, attr) | 342 | #define to_ext_attr(x) container_of(x, struct sysdev_ext_attribute, attr) |
541 | 343 | ||
542 | ssize_t sysdev_store_ulong(struct sys_device *sysdev, | 344 | ssize_t sysdev_store_ulong(struct sys_device *sysdev, |
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig index ad59b4e0a9b5..49502bc5360a 100644 --- a/drivers/char/Kconfig +++ b/drivers/char/Kconfig | |||
@@ -523,7 +523,7 @@ config RAW_DRIVER | |||
523 | with the O_DIRECT flag. | 523 | with the O_DIRECT flag. |
524 | 524 | ||
525 | config MAX_RAW_DEVS | 525 | config MAX_RAW_DEVS |
526 | int "Maximum number of RAW devices to support (1-8192)" | 526 | int "Maximum number of RAW devices to support (1-65536)" |
527 | depends on RAW_DRIVER | 527 | depends on RAW_DRIVER |
528 | default "256" | 528 | default "256" |
529 | help | 529 | help |
diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c index 7066e801b9d3..051474c65b78 100644 --- a/drivers/char/hpet.c +++ b/drivers/char/hpet.c | |||
@@ -84,8 +84,6 @@ static struct clocksource clocksource_hpet = { | |||
84 | .rating = 250, | 84 | .rating = 250, |
85 | .read = read_hpet, | 85 | .read = read_hpet, |
86 | .mask = CLOCKSOURCE_MASK(64), | 86 | .mask = CLOCKSOURCE_MASK(64), |
87 | .mult = 0, /* to be calculated */ | ||
88 | .shift = 10, | ||
89 | .flags = CLOCK_SOURCE_IS_CONTINUOUS, | 87 | .flags = CLOCK_SOURCE_IS_CONTINUOUS, |
90 | }; | 88 | }; |
91 | static struct clocksource *hpet_clocksource; | 89 | static struct clocksource *hpet_clocksource; |
@@ -934,9 +932,7 @@ int hpet_alloc(struct hpet_data *hdp) | |||
934 | if (!hpet_clocksource) { | 932 | if (!hpet_clocksource) { |
935 | hpet_mctr = (void __iomem *)&hpetp->hp_hpet->hpet_mc; | 933 | hpet_mctr = (void __iomem *)&hpetp->hp_hpet->hpet_mc; |
936 | CLKSRC_FSYS_MMIO_SET(clocksource_hpet.fsys_mmio, hpet_mctr); | 934 | CLKSRC_FSYS_MMIO_SET(clocksource_hpet.fsys_mmio, hpet_mctr); |
937 | clocksource_hpet.mult = clocksource_hz2mult(hpetp->hp_tick_freq, | 935 | clocksource_register_hz(&clocksource_hpet, hpetp->hp_tick_freq); |
938 | clocksource_hpet.shift); | ||
939 | clocksource_register(&clocksource_hpet); | ||
940 | hpetp->hp_clocksource = &clocksource_hpet; | 936 | hpetp->hp_clocksource = &clocksource_hpet; |
941 | hpet_clocksource = &clocksource_hpet; | 937 | hpet_clocksource = &clocksource_hpet; |
942 | } | 938 | } |
diff --git a/drivers/char/mem.c b/drivers/char/mem.c index 436a99017998..8fc04b4f311f 100644 --- a/drivers/char/mem.c +++ b/drivers/char/mem.c | |||
@@ -806,29 +806,41 @@ static const struct file_operations oldmem_fops = { | |||
806 | }; | 806 | }; |
807 | #endif | 807 | #endif |
808 | 808 | ||
809 | static ssize_t kmsg_write(struct file *file, const char __user *buf, | 809 | static ssize_t kmsg_writev(struct kiocb *iocb, const struct iovec *iv, |
810 | size_t count, loff_t *ppos) | 810 | unsigned long count, loff_t pos) |
811 | { | 811 | { |
812 | char *tmp; | 812 | char *line, *p; |
813 | ssize_t ret; | 813 | int i; |
814 | ssize_t ret = -EFAULT; | ||
815 | size_t len = iov_length(iv, count); | ||
814 | 816 | ||
815 | tmp = kmalloc(count + 1, GFP_KERNEL); | 817 | line = kmalloc(len + 1, GFP_KERNEL); |
816 | if (tmp == NULL) | 818 | if (line == NULL) |
817 | return -ENOMEM; | 819 | return -ENOMEM; |
818 | ret = -EFAULT; | 820 | |
819 | if (!copy_from_user(tmp, buf, count)) { | 821 | /* |
820 | tmp[count] = 0; | 822 | * copy all vectors into a single string, to ensure we do |
821 | ret = printk("%s", tmp); | 823 | * not interleave our log line with other printk calls |
822 | if (ret > count) | 824 | */ |
823 | /* printk can add a prefix */ | 825 | p = line; |
824 | ret = count; | 826 | for (i = 0; i < count; i++) { |
827 | if (copy_from_user(p, iv[i].iov_base, iv[i].iov_len)) | ||
828 | goto out; | ||
829 | p += iv[i].iov_len; | ||
825 | } | 830 | } |
826 | kfree(tmp); | 831 | p[0] = '\0'; |
832 | |||
833 | ret = printk("%s", line); | ||
834 | /* printk can add a prefix */ | ||
835 | if (ret > len) | ||
836 | ret = len; | ||
837 | out: | ||
838 | kfree(line); | ||
827 | return ret; | 839 | return ret; |
828 | } | 840 | } |
829 | 841 | ||
830 | static const struct file_operations kmsg_fops = { | 842 | static const struct file_operations kmsg_fops = { |
831 | .write = kmsg_write, | 843 | .aio_write = kmsg_writev, |
832 | .llseek = noop_llseek, | 844 | .llseek = noop_llseek, |
833 | }; | 845 | }; |
834 | 846 | ||
diff --git a/drivers/char/raw.c b/drivers/char/raw.c index b4b9d5a47885..b33e8ea314ed 100644 --- a/drivers/char/raw.c +++ b/drivers/char/raw.c | |||
@@ -21,6 +21,7 @@ | |||
21 | #include <linux/mutex.h> | 21 | #include <linux/mutex.h> |
22 | #include <linux/gfp.h> | 22 | #include <linux/gfp.h> |
23 | #include <linux/compat.h> | 23 | #include <linux/compat.h> |
24 | #include <linux/vmalloc.h> | ||
24 | 25 | ||
25 | #include <asm/uaccess.h> | 26 | #include <asm/uaccess.h> |
26 | 27 | ||
@@ -30,10 +31,15 @@ struct raw_device_data { | |||
30 | }; | 31 | }; |
31 | 32 | ||
32 | static struct class *raw_class; | 33 | static struct class *raw_class; |
33 | static struct raw_device_data raw_devices[MAX_RAW_MINORS]; | 34 | static struct raw_device_data *raw_devices; |
34 | static DEFINE_MUTEX(raw_mutex); | 35 | static DEFINE_MUTEX(raw_mutex); |
35 | static const struct file_operations raw_ctl_fops; /* forward declaration */ | 36 | static const struct file_operations raw_ctl_fops; /* forward declaration */ |
36 | 37 | ||
38 | static int max_raw_minors = MAX_RAW_MINORS; | ||
39 | |||
40 | module_param(max_raw_minors, int, 0); | ||
41 | MODULE_PARM_DESC(max_raw_minors, "Maximum number of raw devices (1-65536)"); | ||
42 | |||
37 | /* | 43 | /* |
38 | * Open/close code for raw IO. | 44 | * Open/close code for raw IO. |
39 | * | 45 | * |
@@ -125,7 +131,7 @@ static int bind_set(int number, u64 major, u64 minor) | |||
125 | struct raw_device_data *rawdev; | 131 | struct raw_device_data *rawdev; |
126 | int err = 0; | 132 | int err = 0; |
127 | 133 | ||
128 | if (number <= 0 || number >= MAX_RAW_MINORS) | 134 | if (number <= 0 || number >= max_raw_minors) |
129 | return -EINVAL; | 135 | return -EINVAL; |
130 | 136 | ||
131 | if (MAJOR(dev) != major || MINOR(dev) != minor) | 137 | if (MAJOR(dev) != major || MINOR(dev) != minor) |
@@ -312,14 +318,27 @@ static int __init raw_init(void) | |||
312 | dev_t dev = MKDEV(RAW_MAJOR, 0); | 318 | dev_t dev = MKDEV(RAW_MAJOR, 0); |
313 | int ret; | 319 | int ret; |
314 | 320 | ||
315 | ret = register_chrdev_region(dev, MAX_RAW_MINORS, "raw"); | 321 | if (max_raw_minors < 1 || max_raw_minors > 65536) { |
322 | printk(KERN_WARNING "raw: invalid max_raw_minors (must be" | ||
323 | " between 1 and 65536), using %d\n", MAX_RAW_MINORS); | ||
324 | max_raw_minors = MAX_RAW_MINORS; | ||
325 | } | ||
326 | |||
327 | raw_devices = vmalloc(sizeof(struct raw_device_data) * max_raw_minors); | ||
328 | if (!raw_devices) { | ||
329 | printk(KERN_ERR "Not enough memory for raw device structures\n"); | ||
330 | ret = -ENOMEM; | ||
331 | goto error; | ||
332 | } | ||
333 | memset(raw_devices, 0, sizeof(struct raw_device_data) * max_raw_minors); | ||
334 | |||
335 | ret = register_chrdev_region(dev, max_raw_minors, "raw"); | ||
316 | if (ret) | 336 | if (ret) |
317 | goto error; | 337 | goto error; |
318 | 338 | ||
319 | cdev_init(&raw_cdev, &raw_fops); | 339 | cdev_init(&raw_cdev, &raw_fops); |
320 | ret = cdev_add(&raw_cdev, dev, MAX_RAW_MINORS); | 340 | ret = cdev_add(&raw_cdev, dev, max_raw_minors); |
321 | if (ret) { | 341 | if (ret) { |
322 | kobject_put(&raw_cdev.kobj); | ||
323 | goto error_region; | 342 | goto error_region; |
324 | } | 343 | } |
325 | 344 | ||
@@ -336,8 +355,9 @@ static int __init raw_init(void) | |||
336 | return 0; | 355 | return 0; |
337 | 356 | ||
338 | error_region: | 357 | error_region: |
339 | unregister_chrdev_region(dev, MAX_RAW_MINORS); | 358 | unregister_chrdev_region(dev, max_raw_minors); |
340 | error: | 359 | error: |
360 | vfree(raw_devices); | ||
341 | return ret; | 361 | return ret; |
342 | } | 362 | } |
343 | 363 | ||
@@ -346,7 +366,7 @@ static void __exit raw_exit(void) | |||
346 | device_destroy(raw_class, MKDEV(RAW_MAJOR, 0)); | 366 | device_destroy(raw_class, MKDEV(RAW_MAJOR, 0)); |
347 | class_destroy(raw_class); | 367 | class_destroy(raw_class); |
348 | cdev_del(&raw_cdev); | 368 | cdev_del(&raw_cdev); |
349 | unregister_chrdev_region(MKDEV(RAW_MAJOR, 0), MAX_RAW_MINORS); | 369 | unregister_chrdev_region(MKDEV(RAW_MAJOR, 0), max_raw_minors); |
350 | } | 370 | } |
351 | 371 | ||
352 | module_init(raw_init); | 372 | module_init(raw_init); |
diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig new file mode 100644 index 000000000000..110aeeb52f9a --- /dev/null +++ b/drivers/clocksource/Kconfig | |||
@@ -0,0 +1,2 @@ | |||
1 | config CLKSRC_I8253 | ||
2 | bool | ||
diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile index be61ece6330b..cfb6383b543a 100644 --- a/drivers/clocksource/Makefile +++ b/drivers/clocksource/Makefile | |||
@@ -6,3 +6,4 @@ obj-$(CONFIG_CS5535_CLOCK_EVENT_SRC) += cs5535-clockevt.o | |||
6 | obj-$(CONFIG_SH_TIMER_CMT) += sh_cmt.o | 6 | obj-$(CONFIG_SH_TIMER_CMT) += sh_cmt.o |
7 | obj-$(CONFIG_SH_TIMER_MTU2) += sh_mtu2.o | 7 | obj-$(CONFIG_SH_TIMER_MTU2) += sh_mtu2.o |
8 | obj-$(CONFIG_SH_TIMER_TMU) += sh_tmu.o | 8 | obj-$(CONFIG_SH_TIMER_TMU) += sh_tmu.o |
9 | obj-$(CONFIG_CLKSRC_I8253) += i8253.o | ||
diff --git a/drivers/clocksource/cyclone.c b/drivers/clocksource/cyclone.c index 64e528e8bfa6..72f811f73e9c 100644 --- a/drivers/clocksource/cyclone.c +++ b/drivers/clocksource/cyclone.c | |||
@@ -29,8 +29,6 @@ static struct clocksource clocksource_cyclone = { | |||
29 | .rating = 250, | 29 | .rating = 250, |
30 | .read = read_cyclone, | 30 | .read = read_cyclone, |
31 | .mask = CYCLONE_TIMER_MASK, | 31 | .mask = CYCLONE_TIMER_MASK, |
32 | .mult = 10, | ||
33 | .shift = 0, | ||
34 | .flags = CLOCK_SOURCE_IS_CONTINUOUS, | 32 | .flags = CLOCK_SOURCE_IS_CONTINUOUS, |
35 | }; | 33 | }; |
36 | 34 | ||
@@ -108,12 +106,8 @@ static int __init init_cyclone_clocksource(void) | |||
108 | } | 106 | } |
109 | cyclone_ptr = cyclone_timer; | 107 | cyclone_ptr = cyclone_timer; |
110 | 108 | ||
111 | /* sort out mult/shift values: */ | 109 | return clocksource_register_hz(&clocksource_cyclone, |
112 | clocksource_cyclone.shift = 22; | 110 | CYCLONE_TIMER_FREQ); |
113 | clocksource_cyclone.mult = clocksource_hz2mult(CYCLONE_TIMER_FREQ, | ||
114 | clocksource_cyclone.shift); | ||
115 | |||
116 | return clocksource_register(&clocksource_cyclone); | ||
117 | } | 111 | } |
118 | 112 | ||
119 | arch_initcall(init_cyclone_clocksource); | 113 | arch_initcall(init_cyclone_clocksource); |
diff --git a/drivers/clocksource/i8253.c b/drivers/clocksource/i8253.c new file mode 100644 index 000000000000..225c1761b372 --- /dev/null +++ b/drivers/clocksource/i8253.c | |||
@@ -0,0 +1,88 @@ | |||
1 | /* | ||
2 | * i8253 PIT clocksource | ||
3 | */ | ||
4 | #include <linux/clocksource.h> | ||
5 | #include <linux/init.h> | ||
6 | #include <linux/io.h> | ||
7 | #include <linux/spinlock.h> | ||
8 | #include <linux/timex.h> | ||
9 | |||
10 | #include <asm/i8253.h> | ||
11 | |||
12 | /* | ||
13 | * Since the PIT overflows every tick, its not very useful | ||
14 | * to just read by itself. So use jiffies to emulate a free | ||
15 | * running counter: | ||
16 | */ | ||
17 | static cycle_t i8253_read(struct clocksource *cs) | ||
18 | { | ||
19 | static int old_count; | ||
20 | static u32 old_jifs; | ||
21 | unsigned long flags; | ||
22 | int count; | ||
23 | u32 jifs; | ||
24 | |||
25 | raw_spin_lock_irqsave(&i8253_lock, flags); | ||
26 | /* | ||
27 | * Although our caller may have the read side of xtime_lock, | ||
28 | * this is now a seqlock, and we are cheating in this routine | ||
29 | * by having side effects on state that we cannot undo if | ||
30 | * there is a collision on the seqlock and our caller has to | ||
31 | * retry. (Namely, old_jifs and old_count.) So we must treat | ||
32 | * jiffies as volatile despite the lock. We read jiffies | ||
33 | * before latching the timer count to guarantee that although | ||
34 | * the jiffies value might be older than the count (that is, | ||
35 | * the counter may underflow between the last point where | ||
36 | * jiffies was incremented and the point where we latch the | ||
37 | * count), it cannot be newer. | ||
38 | */ | ||
39 | jifs = jiffies; | ||
40 | outb_pit(0x00, PIT_MODE); /* latch the count ASAP */ | ||
41 | count = inb_pit(PIT_CH0); /* read the latched count */ | ||
42 | count |= inb_pit(PIT_CH0) << 8; | ||
43 | |||
44 | /* VIA686a test code... reset the latch if count > max + 1 */ | ||
45 | if (count > LATCH) { | ||
46 | outb_pit(0x34, PIT_MODE); | ||
47 | outb_pit(PIT_LATCH & 0xff, PIT_CH0); | ||
48 | outb_pit(PIT_LATCH >> 8, PIT_CH0); | ||
49 | count = PIT_LATCH - 1; | ||
50 | } | ||
51 | |||
52 | /* | ||
53 | * It's possible for count to appear to go the wrong way for a | ||
54 | * couple of reasons: | ||
55 | * | ||
56 | * 1. The timer counter underflows, but we haven't handled the | ||
57 | * resulting interrupt and incremented jiffies yet. | ||
58 | * 2. Hardware problem with the timer, not giving us continuous time, | ||
59 | * the counter does small "jumps" upwards on some Pentium systems, | ||
60 | * (see c't 95/10 page 335 for Neptun bug.) | ||
61 | * | ||
62 | * Previous attempts to handle these cases intelligently were | ||
63 | * buggy, so we just do the simple thing now. | ||
64 | */ | ||
65 | if (count > old_count && jifs == old_jifs) | ||
66 | count = old_count; | ||
67 | |||
68 | old_count = count; | ||
69 | old_jifs = jifs; | ||
70 | |||
71 | raw_spin_unlock_irqrestore(&i8253_lock, flags); | ||
72 | |||
73 | count = (PIT_LATCH - 1) - count; | ||
74 | |||
75 | return (cycle_t)(jifs * PIT_LATCH) + count; | ||
76 | } | ||
77 | |||
78 | static struct clocksource i8253_cs = { | ||
79 | .name = "pit", | ||
80 | .rating = 110, | ||
81 | .read = i8253_read, | ||
82 | .mask = CLOCKSOURCE_MASK(32), | ||
83 | }; | ||
84 | |||
85 | int __init clocksource_i8253_init(void) | ||
86 | { | ||
87 | return clocksource_register_hz(&i8253_cs, PIT_TICK_RATE); | ||
88 | } | ||
diff --git a/drivers/cpufreq/Kconfig b/drivers/cpufreq/Kconfig index ca8ee8093d6c..9fb84853d8e3 100644 --- a/drivers/cpufreq/Kconfig +++ b/drivers/cpufreq/Kconfig | |||
@@ -1,3 +1,5 @@ | |||
1 | menu "CPU Frequency scaling" | ||
2 | |||
1 | config CPU_FREQ | 3 | config CPU_FREQ |
2 | bool "CPU Frequency scaling" | 4 | bool "CPU Frequency scaling" |
3 | help | 5 | help |
@@ -18,19 +20,6 @@ if CPU_FREQ | |||
18 | config CPU_FREQ_TABLE | 20 | config CPU_FREQ_TABLE |
19 | tristate | 21 | tristate |
20 | 22 | ||
21 | config CPU_FREQ_DEBUG | ||
22 | bool "Enable CPUfreq debugging" | ||
23 | help | ||
24 | Say Y here to enable CPUfreq subsystem (including drivers) | ||
25 | debugging. You will need to activate it via the kernel | ||
26 | command line by passing | ||
27 | cpufreq.debug=<value> | ||
28 | |||
29 | To get <value>, add | ||
30 | 1 to activate CPUfreq core debugging, | ||
31 | 2 to activate CPUfreq drivers debugging, and | ||
32 | 4 to activate CPUfreq governor debugging | ||
33 | |||
34 | config CPU_FREQ_STAT | 23 | config CPU_FREQ_STAT |
35 | tristate "CPU frequency translation statistics" | 24 | tristate "CPU frequency translation statistics" |
36 | select CPU_FREQ_TABLE | 25 | select CPU_FREQ_TABLE |
@@ -190,4 +179,10 @@ config CPU_FREQ_GOV_CONSERVATIVE | |||
190 | 179 | ||
191 | If in doubt, say N. | 180 | If in doubt, say N. |
192 | 181 | ||
193 | endif # CPU_FREQ | 182 | menu "x86 CPU frequency scaling drivers" |
183 | depends on X86 | ||
184 | source "drivers/cpufreq/Kconfig.x86" | ||
185 | endmenu | ||
186 | |||
187 | endif | ||
188 | endmenu | ||
diff --git a/drivers/cpufreq/Kconfig.x86 b/drivers/cpufreq/Kconfig.x86 new file mode 100644 index 000000000000..78ff7ee48951 --- /dev/null +++ b/drivers/cpufreq/Kconfig.x86 | |||
@@ -0,0 +1,255 @@ | |||
1 | # | ||
2 | # x86 CPU Frequency scaling drivers | ||
3 | # | ||
4 | |||
5 | config X86_PCC_CPUFREQ | ||
6 | tristate "Processor Clocking Control interface driver" | ||
7 | depends on ACPI && ACPI_PROCESSOR | ||
8 | help | ||
9 | This driver adds support for the PCC interface. | ||
10 | |||
11 | For details, take a look at: | ||
12 | <file:Documentation/cpu-freq/pcc-cpufreq.txt>. | ||
13 | |||
14 | To compile this driver as a module, choose M here: the | ||
15 | module will be called pcc-cpufreq. | ||
16 | |||
17 | If in doubt, say N. | ||
18 | |||
19 | config X86_ACPI_CPUFREQ | ||
20 | tristate "ACPI Processor P-States driver" | ||
21 | select CPU_FREQ_TABLE | ||
22 | depends on ACPI_PROCESSOR | ||
23 | help | ||
24 | This driver adds a CPUFreq driver which utilizes the ACPI | ||
25 | Processor Performance States. | ||
26 | This driver also supports Intel Enhanced Speedstep. | ||
27 | |||
28 | To compile this driver as a module, choose M here: the | ||
29 | module will be called acpi-cpufreq. | ||
30 | |||
31 | For details, take a look at <file:Documentation/cpu-freq/>. | ||
32 | |||
33 | If in doubt, say N. | ||
34 | |||
35 | config ELAN_CPUFREQ | ||
36 | tristate "AMD Elan SC400 and SC410" | ||
37 | select CPU_FREQ_TABLE | ||
38 | depends on MELAN | ||
39 | ---help--- | ||
40 | This adds the CPUFreq driver for AMD Elan SC400 and SC410 | ||
41 | processors. | ||
42 | |||
43 | You need to specify the processor maximum speed as boot | ||
44 | parameter: elanfreq=maxspeed (in kHz) or as module | ||
45 | parameter "max_freq". | ||
46 | |||
47 | For details, take a look at <file:Documentation/cpu-freq/>. | ||
48 | |||
49 | If in doubt, say N. | ||
50 | |||
51 | config SC520_CPUFREQ | ||
52 | tristate "AMD Elan SC520" | ||
53 | select CPU_FREQ_TABLE | ||
54 | depends on MELAN | ||
55 | ---help--- | ||
56 | This adds the CPUFreq driver for AMD Elan SC520 processor. | ||
57 | |||
58 | For details, take a look at <file:Documentation/cpu-freq/>. | ||
59 | |||
60 | If in doubt, say N. | ||
61 | |||
62 | |||
63 | config X86_POWERNOW_K6 | ||
64 | tristate "AMD Mobile K6-2/K6-3 PowerNow!" | ||
65 | select CPU_FREQ_TABLE | ||
66 | depends on X86_32 | ||
67 | help | ||
68 | This adds the CPUFreq driver for mobile AMD K6-2+ and mobile | ||
69 | AMD K6-3+ processors. | ||
70 | |||
71 | For details, take a look at <file:Documentation/cpu-freq/>. | ||
72 | |||
73 | If in doubt, say N. | ||
74 | |||
75 | config X86_POWERNOW_K7 | ||
76 | tristate "AMD Mobile Athlon/Duron PowerNow!" | ||
77 | select CPU_FREQ_TABLE | ||
78 | depends on X86_32 | ||
79 | help | ||
80 | This adds the CPUFreq driver for mobile AMD K7 mobile processors. | ||
81 | |||
82 | For details, take a look at <file:Documentation/cpu-freq/>. | ||
83 | |||
84 | If in doubt, say N. | ||
85 | |||
86 | config X86_POWERNOW_K7_ACPI | ||
87 | bool | ||
88 | depends on X86_POWERNOW_K7 && ACPI_PROCESSOR | ||
89 | depends on !(X86_POWERNOW_K7 = y && ACPI_PROCESSOR = m) | ||
90 | depends on X86_32 | ||
91 | default y | ||
92 | |||
93 | config X86_POWERNOW_K8 | ||
94 | tristate "AMD Opteron/Athlon64 PowerNow!" | ||
95 | select CPU_FREQ_TABLE | ||
96 | depends on ACPI && ACPI_PROCESSOR | ||
97 | help | ||
98 | This adds the CPUFreq driver for K8/K10 Opteron/Athlon64 processors. | ||
99 | |||
100 | To compile this driver as a module, choose M here: the | ||
101 | module will be called powernow-k8. | ||
102 | |||
103 | For details, take a look at <file:Documentation/cpu-freq/>. | ||
104 | |||
105 | config X86_GX_SUSPMOD | ||
106 | tristate "Cyrix MediaGX/NatSemi Geode Suspend Modulation" | ||
107 | depends on X86_32 && PCI | ||
108 | help | ||
109 | This add the CPUFreq driver for NatSemi Geode processors which | ||
110 | support suspend modulation. | ||
111 | |||
112 | For details, take a look at <file:Documentation/cpu-freq/>. | ||
113 | |||
114 | If in doubt, say N. | ||
115 | |||
116 | config X86_SPEEDSTEP_CENTRINO | ||
117 | tristate "Intel Enhanced SpeedStep (deprecated)" | ||
118 | select CPU_FREQ_TABLE | ||
119 | select X86_SPEEDSTEP_CENTRINO_TABLE if X86_32 | ||
120 | depends on X86_32 || (X86_64 && ACPI_PROCESSOR) | ||
121 | help | ||
122 | This is deprecated and this functionality is now merged into | ||
123 | acpi_cpufreq (X86_ACPI_CPUFREQ). Use that driver instead of | ||
124 | speedstep_centrino. | ||
125 | This adds the CPUFreq driver for Enhanced SpeedStep enabled | ||
126 | mobile CPUs. This means Intel Pentium M (Centrino) CPUs | ||
127 | or 64bit enabled Intel Xeons. | ||
128 | |||
129 | To compile this driver as a module, choose M here: the | ||
130 | module will be called speedstep-centrino. | ||
131 | |||
132 | For details, take a look at <file:Documentation/cpu-freq/>. | ||
133 | |||
134 | If in doubt, say N. | ||
135 | |||
136 | config X86_SPEEDSTEP_CENTRINO_TABLE | ||
137 | bool "Built-in tables for Banias CPUs" | ||
138 | depends on X86_32 && X86_SPEEDSTEP_CENTRINO | ||
139 | default y | ||
140 | help | ||
141 | Use built-in tables for Banias CPUs if ACPI encoding | ||
142 | is not available. | ||
143 | |||
144 | If in doubt, say N. | ||
145 | |||
146 | config X86_SPEEDSTEP_ICH | ||
147 | tristate "Intel Speedstep on ICH-M chipsets (ioport interface)" | ||
148 | select CPU_FREQ_TABLE | ||
149 | depends on X86_32 | ||
150 | help | ||
151 | This adds the CPUFreq driver for certain mobile Intel Pentium III | ||
152 | (Coppermine), all mobile Intel Pentium III-M (Tualatin) and all | ||
153 | mobile Intel Pentium 4 P4-M on systems which have an Intel ICH2, | ||
154 | ICH3 or ICH4 southbridge. | ||
155 | |||
156 | For details, take a look at <file:Documentation/cpu-freq/>. | ||
157 | |||
158 | If in doubt, say N. | ||
159 | |||
160 | config X86_SPEEDSTEP_SMI | ||
161 | tristate "Intel SpeedStep on 440BX/ZX/MX chipsets (SMI interface)" | ||
162 | select CPU_FREQ_TABLE | ||
163 | depends on X86_32 && EXPERIMENTAL | ||
164 | help | ||
165 | This adds the CPUFreq driver for certain mobile Intel Pentium III | ||
166 | (Coppermine), all mobile Intel Pentium III-M (Tualatin) | ||
167 | on systems which have an Intel 440BX/ZX/MX southbridge. | ||
168 | |||
169 | For details, take a look at <file:Documentation/cpu-freq/>. | ||
170 | |||
171 | If in doubt, say N. | ||
172 | |||
173 | config X86_P4_CLOCKMOD | ||
174 | tristate "Intel Pentium 4 clock modulation" | ||
175 | select CPU_FREQ_TABLE | ||
176 | help | ||
177 | This adds the CPUFreq driver for Intel Pentium 4 / XEON | ||
178 | processors. When enabled it will lower CPU temperature by skipping | ||
179 | clocks. | ||
180 | |||
181 | This driver should be only used in exceptional | ||
182 | circumstances when very low power is needed because it causes severe | ||
183 | slowdowns and noticeable latencies. Normally Speedstep should be used | ||
184 | instead. | ||
185 | |||
186 | To compile this driver as a module, choose M here: the | ||
187 | module will be called p4-clockmod. | ||
188 | |||
189 | For details, take a look at <file:Documentation/cpu-freq/>. | ||
190 | |||
191 | Unless you are absolutely sure say N. | ||
192 | |||
193 | config X86_CPUFREQ_NFORCE2 | ||
194 | tristate "nVidia nForce2 FSB changing" | ||
195 | depends on X86_32 && EXPERIMENTAL | ||
196 | help | ||
197 | This adds the CPUFreq driver for FSB changing on nVidia nForce2 | ||
198 | platforms. | ||
199 | |||
200 | For details, take a look at <file:Documentation/cpu-freq/>. | ||
201 | |||
202 | If in doubt, say N. | ||
203 | |||
204 | config X86_LONGRUN | ||
205 | tristate "Transmeta LongRun" | ||
206 | depends on X86_32 | ||
207 | help | ||
208 | This adds the CPUFreq driver for Transmeta Crusoe and Efficeon processors | ||
209 | which support LongRun. | ||
210 | |||
211 | For details, take a look at <file:Documentation/cpu-freq/>. | ||
212 | |||
213 | If in doubt, say N. | ||
214 | |||
215 | config X86_LONGHAUL | ||
216 | tristate "VIA Cyrix III Longhaul" | ||
217 | select CPU_FREQ_TABLE | ||
218 | depends on X86_32 && ACPI_PROCESSOR | ||
219 | help | ||
220 | This adds the CPUFreq driver for VIA Samuel/CyrixIII, | ||
221 | VIA Cyrix Samuel/C3, VIA Cyrix Ezra and VIA Cyrix Ezra-T | ||
222 | processors. | ||
223 | |||
224 | For details, take a look at <file:Documentation/cpu-freq/>. | ||
225 | |||
226 | If in doubt, say N. | ||
227 | |||
228 | config X86_E_POWERSAVER | ||
229 | tristate "VIA C7 Enhanced PowerSaver (DANGEROUS)" | ||
230 | select CPU_FREQ_TABLE | ||
231 | depends on X86_32 && EXPERIMENTAL | ||
232 | help | ||
233 | This adds the CPUFreq driver for VIA C7 processors. However, this driver | ||
234 | does not have any safeguards to prevent operating the CPU out of spec | ||
235 | and is thus considered dangerous. Please use the regular ACPI cpufreq | ||
236 | driver, enabled by CONFIG_X86_ACPI_CPUFREQ. | ||
237 | |||
238 | If in doubt, say N. | ||
239 | |||
240 | comment "shared options" | ||
241 | |||
242 | config X86_SPEEDSTEP_LIB | ||
243 | tristate | ||
244 | default (X86_SPEEDSTEP_ICH || X86_SPEEDSTEP_SMI || X86_P4_CLOCKMOD) | ||
245 | |||
246 | config X86_SPEEDSTEP_RELAXED_CAP_CHECK | ||
247 | bool "Relaxed speedstep capability checks" | ||
248 | depends on X86_32 && (X86_SPEEDSTEP_SMI || X86_SPEEDSTEP_ICH) | ||
249 | help | ||
250 | Don't perform all checks for a speedstep capable system which would | ||
251 | normally be done. Some ancient or strange systems, though speedstep | ||
252 | capable, don't always indicate that they are speedstep capable. This | ||
253 | option lets the probing code bypass some of those checks if the | ||
254 | parameter "relaxed_check=1" is passed to the module. | ||
255 | |||
diff --git a/drivers/cpufreq/Makefile b/drivers/cpufreq/Makefile index 71fc3b4173f1..c7f1a6f16b6e 100644 --- a/drivers/cpufreq/Makefile +++ b/drivers/cpufreq/Makefile | |||
@@ -13,3 +13,29 @@ obj-$(CONFIG_CPU_FREQ_GOV_CONSERVATIVE) += cpufreq_conservative.o | |||
13 | # CPUfreq cross-arch helpers | 13 | # CPUfreq cross-arch helpers |
14 | obj-$(CONFIG_CPU_FREQ_TABLE) += freq_table.o | 14 | obj-$(CONFIG_CPU_FREQ_TABLE) += freq_table.o |
15 | 15 | ||
16 | ##################################################################################d | ||
17 | # x86 drivers. | ||
18 | # Link order matters. K8 is preferred to ACPI because of firmware bugs in early | ||
19 | # K8 systems. ACPI is preferred to all other hardware-specific drivers. | ||
20 | # speedstep-* is preferred over p4-clockmod. | ||
21 | |||
22 | obj-$(CONFIG_X86_POWERNOW_K8) += powernow-k8.o mperf.o | ||
23 | obj-$(CONFIG_X86_ACPI_CPUFREQ) += acpi-cpufreq.o mperf.o | ||
24 | obj-$(CONFIG_X86_PCC_CPUFREQ) += pcc-cpufreq.o | ||
25 | obj-$(CONFIG_X86_POWERNOW_K6) += powernow-k6.o | ||
26 | obj-$(CONFIG_X86_POWERNOW_K7) += powernow-k7.o | ||
27 | obj-$(CONFIG_X86_LONGHAUL) += longhaul.o | ||
28 | obj-$(CONFIG_X86_E_POWERSAVER) += e_powersaver.o | ||
29 | obj-$(CONFIG_ELAN_CPUFREQ) += elanfreq.o | ||
30 | obj-$(CONFIG_SC520_CPUFREQ) += sc520_freq.o | ||
31 | obj-$(CONFIG_X86_LONGRUN) += longrun.o | ||
32 | obj-$(CONFIG_X86_GX_SUSPMOD) += gx-suspmod.o | ||
33 | obj-$(CONFIG_X86_SPEEDSTEP_ICH) += speedstep-ich.o | ||
34 | obj-$(CONFIG_X86_SPEEDSTEP_LIB) += speedstep-lib.o | ||
35 | obj-$(CONFIG_X86_SPEEDSTEP_SMI) += speedstep-smi.o | ||
36 | obj-$(CONFIG_X86_SPEEDSTEP_CENTRINO) += speedstep-centrino.o | ||
37 | obj-$(CONFIG_X86_P4_CLOCKMOD) += p4-clockmod.o | ||
38 | obj-$(CONFIG_X86_CPUFREQ_NFORCE2) += cpufreq-nforce2.o | ||
39 | |||
40 | ##################################################################################d | ||
41 | |||
diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c new file mode 100644 index 000000000000..4e04e1274388 --- /dev/null +++ b/drivers/cpufreq/acpi-cpufreq.c | |||
@@ -0,0 +1,773 @@ | |||
1 | /* | ||
2 | * acpi-cpufreq.c - ACPI Processor P-States Driver | ||
3 | * | ||
4 | * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com> | ||
5 | * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com> | ||
6 | * Copyright (C) 2002 - 2004 Dominik Brodowski <linux@brodo.de> | ||
7 | * Copyright (C) 2006 Denis Sadykov <denis.m.sadykov@intel.com> | ||
8 | * | ||
9 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or modify | ||
12 | * it under the terms of the GNU General Public License as published by | ||
13 | * the Free Software Foundation; either version 2 of the License, or (at | ||
14 | * your option) any later version. | ||
15 | * | ||
16 | * This program is distributed in the hope that it will be useful, but | ||
17 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
19 | * General Public License for more details. | ||
20 | * | ||
21 | * You should have received a copy of the GNU General Public License along | ||
22 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
23 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. | ||
24 | * | ||
25 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
26 | */ | ||
27 | |||
28 | #include <linux/kernel.h> | ||
29 | #include <linux/module.h> | ||
30 | #include <linux/init.h> | ||
31 | #include <linux/smp.h> | ||
32 | #include <linux/sched.h> | ||
33 | #include <linux/cpufreq.h> | ||
34 | #include <linux/compiler.h> | ||
35 | #include <linux/dmi.h> | ||
36 | #include <linux/slab.h> | ||
37 | |||
38 | #include <linux/acpi.h> | ||
39 | #include <linux/io.h> | ||
40 | #include <linux/delay.h> | ||
41 | #include <linux/uaccess.h> | ||
42 | |||
43 | #include <acpi/processor.h> | ||
44 | |||
45 | #include <asm/msr.h> | ||
46 | #include <asm/processor.h> | ||
47 | #include <asm/cpufeature.h> | ||
48 | #include "mperf.h" | ||
49 | |||
50 | MODULE_AUTHOR("Paul Diefenbaugh, Dominik Brodowski"); | ||
51 | MODULE_DESCRIPTION("ACPI Processor P-States Driver"); | ||
52 | MODULE_LICENSE("GPL"); | ||
53 | |||
54 | enum { | ||
55 | UNDEFINED_CAPABLE = 0, | ||
56 | SYSTEM_INTEL_MSR_CAPABLE, | ||
57 | SYSTEM_IO_CAPABLE, | ||
58 | }; | ||
59 | |||
60 | #define INTEL_MSR_RANGE (0xffff) | ||
61 | |||
62 | struct acpi_cpufreq_data { | ||
63 | struct acpi_processor_performance *acpi_data; | ||
64 | struct cpufreq_frequency_table *freq_table; | ||
65 | unsigned int resume; | ||
66 | unsigned int cpu_feature; | ||
67 | }; | ||
68 | |||
69 | static DEFINE_PER_CPU(struct acpi_cpufreq_data *, acfreq_data); | ||
70 | |||
71 | /* acpi_perf_data is a pointer to percpu data. */ | ||
72 | static struct acpi_processor_performance __percpu *acpi_perf_data; | ||
73 | |||
74 | static struct cpufreq_driver acpi_cpufreq_driver; | ||
75 | |||
76 | static unsigned int acpi_pstate_strict; | ||
77 | |||
78 | static int check_est_cpu(unsigned int cpuid) | ||
79 | { | ||
80 | struct cpuinfo_x86 *cpu = &cpu_data(cpuid); | ||
81 | |||
82 | return cpu_has(cpu, X86_FEATURE_EST); | ||
83 | } | ||
84 | |||
85 | static unsigned extract_io(u32 value, struct acpi_cpufreq_data *data) | ||
86 | { | ||
87 | struct acpi_processor_performance *perf; | ||
88 | int i; | ||
89 | |||
90 | perf = data->acpi_data; | ||
91 | |||
92 | for (i = 0; i < perf->state_count; i++) { | ||
93 | if (value == perf->states[i].status) | ||
94 | return data->freq_table[i].frequency; | ||
95 | } | ||
96 | return 0; | ||
97 | } | ||
98 | |||
99 | static unsigned extract_msr(u32 msr, struct acpi_cpufreq_data *data) | ||
100 | { | ||
101 | int i; | ||
102 | struct acpi_processor_performance *perf; | ||
103 | |||
104 | msr &= INTEL_MSR_RANGE; | ||
105 | perf = data->acpi_data; | ||
106 | |||
107 | for (i = 0; data->freq_table[i].frequency != CPUFREQ_TABLE_END; i++) { | ||
108 | if (msr == perf->states[data->freq_table[i].index].status) | ||
109 | return data->freq_table[i].frequency; | ||
110 | } | ||
111 | return data->freq_table[0].frequency; | ||
112 | } | ||
113 | |||
114 | static unsigned extract_freq(u32 val, struct acpi_cpufreq_data *data) | ||
115 | { | ||
116 | switch (data->cpu_feature) { | ||
117 | case SYSTEM_INTEL_MSR_CAPABLE: | ||
118 | return extract_msr(val, data); | ||
119 | case SYSTEM_IO_CAPABLE: | ||
120 | return extract_io(val, data); | ||
121 | default: | ||
122 | return 0; | ||
123 | } | ||
124 | } | ||
125 | |||
126 | struct msr_addr { | ||
127 | u32 reg; | ||
128 | }; | ||
129 | |||
130 | struct io_addr { | ||
131 | u16 port; | ||
132 | u8 bit_width; | ||
133 | }; | ||
134 | |||
135 | struct drv_cmd { | ||
136 | unsigned int type; | ||
137 | const struct cpumask *mask; | ||
138 | union { | ||
139 | struct msr_addr msr; | ||
140 | struct io_addr io; | ||
141 | } addr; | ||
142 | u32 val; | ||
143 | }; | ||
144 | |||
145 | /* Called via smp_call_function_single(), on the target CPU */ | ||
146 | static void do_drv_read(void *_cmd) | ||
147 | { | ||
148 | struct drv_cmd *cmd = _cmd; | ||
149 | u32 h; | ||
150 | |||
151 | switch (cmd->type) { | ||
152 | case SYSTEM_INTEL_MSR_CAPABLE: | ||
153 | rdmsr(cmd->addr.msr.reg, cmd->val, h); | ||
154 | break; | ||
155 | case SYSTEM_IO_CAPABLE: | ||
156 | acpi_os_read_port((acpi_io_address)cmd->addr.io.port, | ||
157 | &cmd->val, | ||
158 | (u32)cmd->addr.io.bit_width); | ||
159 | break; | ||
160 | default: | ||
161 | break; | ||
162 | } | ||
163 | } | ||
164 | |||
165 | /* Called via smp_call_function_many(), on the target CPUs */ | ||
166 | static void do_drv_write(void *_cmd) | ||
167 | { | ||
168 | struct drv_cmd *cmd = _cmd; | ||
169 | u32 lo, hi; | ||
170 | |||
171 | switch (cmd->type) { | ||
172 | case SYSTEM_INTEL_MSR_CAPABLE: | ||
173 | rdmsr(cmd->addr.msr.reg, lo, hi); | ||
174 | lo = (lo & ~INTEL_MSR_RANGE) | (cmd->val & INTEL_MSR_RANGE); | ||
175 | wrmsr(cmd->addr.msr.reg, lo, hi); | ||
176 | break; | ||
177 | case SYSTEM_IO_CAPABLE: | ||
178 | acpi_os_write_port((acpi_io_address)cmd->addr.io.port, | ||
179 | cmd->val, | ||
180 | (u32)cmd->addr.io.bit_width); | ||
181 | break; | ||
182 | default: | ||
183 | break; | ||
184 | } | ||
185 | } | ||
186 | |||
187 | static void drv_read(struct drv_cmd *cmd) | ||
188 | { | ||
189 | int err; | ||
190 | cmd->val = 0; | ||
191 | |||
192 | err = smp_call_function_any(cmd->mask, do_drv_read, cmd, 1); | ||
193 | WARN_ON_ONCE(err); /* smp_call_function_any() was buggy? */ | ||
194 | } | ||
195 | |||
196 | static void drv_write(struct drv_cmd *cmd) | ||
197 | { | ||
198 | int this_cpu; | ||
199 | |||
200 | this_cpu = get_cpu(); | ||
201 | if (cpumask_test_cpu(this_cpu, cmd->mask)) | ||
202 | do_drv_write(cmd); | ||
203 | smp_call_function_many(cmd->mask, do_drv_write, cmd, 1); | ||
204 | put_cpu(); | ||
205 | } | ||
206 | |||
207 | static u32 get_cur_val(const struct cpumask *mask) | ||
208 | { | ||
209 | struct acpi_processor_performance *perf; | ||
210 | struct drv_cmd cmd; | ||
211 | |||
212 | if (unlikely(cpumask_empty(mask))) | ||
213 | return 0; | ||
214 | |||
215 | switch (per_cpu(acfreq_data, cpumask_first(mask))->cpu_feature) { | ||
216 | case SYSTEM_INTEL_MSR_CAPABLE: | ||
217 | cmd.type = SYSTEM_INTEL_MSR_CAPABLE; | ||
218 | cmd.addr.msr.reg = MSR_IA32_PERF_STATUS; | ||
219 | break; | ||
220 | case SYSTEM_IO_CAPABLE: | ||
221 | cmd.type = SYSTEM_IO_CAPABLE; | ||
222 | perf = per_cpu(acfreq_data, cpumask_first(mask))->acpi_data; | ||
223 | cmd.addr.io.port = perf->control_register.address; | ||
224 | cmd.addr.io.bit_width = perf->control_register.bit_width; | ||
225 | break; | ||
226 | default: | ||
227 | return 0; | ||
228 | } | ||
229 | |||
230 | cmd.mask = mask; | ||
231 | drv_read(&cmd); | ||
232 | |||
233 | pr_debug("get_cur_val = %u\n", cmd.val); | ||
234 | |||
235 | return cmd.val; | ||
236 | } | ||
237 | |||
238 | static unsigned int get_cur_freq_on_cpu(unsigned int cpu) | ||
239 | { | ||
240 | struct acpi_cpufreq_data *data = per_cpu(acfreq_data, cpu); | ||
241 | unsigned int freq; | ||
242 | unsigned int cached_freq; | ||
243 | |||
244 | pr_debug("get_cur_freq_on_cpu (%d)\n", cpu); | ||
245 | |||
246 | if (unlikely(data == NULL || | ||
247 | data->acpi_data == NULL || data->freq_table == NULL)) { | ||
248 | return 0; | ||
249 | } | ||
250 | |||
251 | cached_freq = data->freq_table[data->acpi_data->state].frequency; | ||
252 | freq = extract_freq(get_cur_val(cpumask_of(cpu)), data); | ||
253 | if (freq != cached_freq) { | ||
254 | /* | ||
255 | * The dreaded BIOS frequency change behind our back. | ||
256 | * Force set the frequency on next target call. | ||
257 | */ | ||
258 | data->resume = 1; | ||
259 | } | ||
260 | |||
261 | pr_debug("cur freq = %u\n", freq); | ||
262 | |||
263 | return freq; | ||
264 | } | ||
265 | |||
266 | static unsigned int check_freqs(const struct cpumask *mask, unsigned int freq, | ||
267 | struct acpi_cpufreq_data *data) | ||
268 | { | ||
269 | unsigned int cur_freq; | ||
270 | unsigned int i; | ||
271 | |||
272 | for (i = 0; i < 100; i++) { | ||
273 | cur_freq = extract_freq(get_cur_val(mask), data); | ||
274 | if (cur_freq == freq) | ||
275 | return 1; | ||
276 | udelay(10); | ||
277 | } | ||
278 | return 0; | ||
279 | } | ||
280 | |||
281 | static int acpi_cpufreq_target(struct cpufreq_policy *policy, | ||
282 | unsigned int target_freq, unsigned int relation) | ||
283 | { | ||
284 | struct acpi_cpufreq_data *data = per_cpu(acfreq_data, policy->cpu); | ||
285 | struct acpi_processor_performance *perf; | ||
286 | struct cpufreq_freqs freqs; | ||
287 | struct drv_cmd cmd; | ||
288 | unsigned int next_state = 0; /* Index into freq_table */ | ||
289 | unsigned int next_perf_state = 0; /* Index into perf table */ | ||
290 | unsigned int i; | ||
291 | int result = 0; | ||
292 | |||
293 | pr_debug("acpi_cpufreq_target %d (%d)\n", target_freq, policy->cpu); | ||
294 | |||
295 | if (unlikely(data == NULL || | ||
296 | data->acpi_data == NULL || data->freq_table == NULL)) { | ||
297 | return -ENODEV; | ||
298 | } | ||
299 | |||
300 | perf = data->acpi_data; | ||
301 | result = cpufreq_frequency_table_target(policy, | ||
302 | data->freq_table, | ||
303 | target_freq, | ||
304 | relation, &next_state); | ||
305 | if (unlikely(result)) { | ||
306 | result = -ENODEV; | ||
307 | goto out; | ||
308 | } | ||
309 | |||
310 | next_perf_state = data->freq_table[next_state].index; | ||
311 | if (perf->state == next_perf_state) { | ||
312 | if (unlikely(data->resume)) { | ||
313 | pr_debug("Called after resume, resetting to P%d\n", | ||
314 | next_perf_state); | ||
315 | data->resume = 0; | ||
316 | } else { | ||
317 | pr_debug("Already at target state (P%d)\n", | ||
318 | next_perf_state); | ||
319 | goto out; | ||
320 | } | ||
321 | } | ||
322 | |||
323 | switch (data->cpu_feature) { | ||
324 | case SYSTEM_INTEL_MSR_CAPABLE: | ||
325 | cmd.type = SYSTEM_INTEL_MSR_CAPABLE; | ||
326 | cmd.addr.msr.reg = MSR_IA32_PERF_CTL; | ||
327 | cmd.val = (u32) perf->states[next_perf_state].control; | ||
328 | break; | ||
329 | case SYSTEM_IO_CAPABLE: | ||
330 | cmd.type = SYSTEM_IO_CAPABLE; | ||
331 | cmd.addr.io.port = perf->control_register.address; | ||
332 | cmd.addr.io.bit_width = perf->control_register.bit_width; | ||
333 | cmd.val = (u32) perf->states[next_perf_state].control; | ||
334 | break; | ||
335 | default: | ||
336 | result = -ENODEV; | ||
337 | goto out; | ||
338 | } | ||
339 | |||
340 | /* cpufreq holds the hotplug lock, so we are safe from here on */ | ||
341 | if (policy->shared_type != CPUFREQ_SHARED_TYPE_ANY) | ||
342 | cmd.mask = policy->cpus; | ||
343 | else | ||
344 | cmd.mask = cpumask_of(policy->cpu); | ||
345 | |||
346 | freqs.old = perf->states[perf->state].core_frequency * 1000; | ||
347 | freqs.new = data->freq_table[next_state].frequency; | ||
348 | for_each_cpu(i, policy->cpus) { | ||
349 | freqs.cpu = i; | ||
350 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
351 | } | ||
352 | |||
353 | drv_write(&cmd); | ||
354 | |||
355 | if (acpi_pstate_strict) { | ||
356 | if (!check_freqs(cmd.mask, freqs.new, data)) { | ||
357 | pr_debug("acpi_cpufreq_target failed (%d)\n", | ||
358 | policy->cpu); | ||
359 | result = -EAGAIN; | ||
360 | goto out; | ||
361 | } | ||
362 | } | ||
363 | |||
364 | for_each_cpu(i, policy->cpus) { | ||
365 | freqs.cpu = i; | ||
366 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
367 | } | ||
368 | perf->state = next_perf_state; | ||
369 | |||
370 | out: | ||
371 | return result; | ||
372 | } | ||
373 | |||
374 | static int acpi_cpufreq_verify(struct cpufreq_policy *policy) | ||
375 | { | ||
376 | struct acpi_cpufreq_data *data = per_cpu(acfreq_data, policy->cpu); | ||
377 | |||
378 | pr_debug("acpi_cpufreq_verify\n"); | ||
379 | |||
380 | return cpufreq_frequency_table_verify(policy, data->freq_table); | ||
381 | } | ||
382 | |||
383 | static unsigned long | ||
384 | acpi_cpufreq_guess_freq(struct acpi_cpufreq_data *data, unsigned int cpu) | ||
385 | { | ||
386 | struct acpi_processor_performance *perf = data->acpi_data; | ||
387 | |||
388 | if (cpu_khz) { | ||
389 | /* search the closest match to cpu_khz */ | ||
390 | unsigned int i; | ||
391 | unsigned long freq; | ||
392 | unsigned long freqn = perf->states[0].core_frequency * 1000; | ||
393 | |||
394 | for (i = 0; i < (perf->state_count-1); i++) { | ||
395 | freq = freqn; | ||
396 | freqn = perf->states[i+1].core_frequency * 1000; | ||
397 | if ((2 * cpu_khz) > (freqn + freq)) { | ||
398 | perf->state = i; | ||
399 | return freq; | ||
400 | } | ||
401 | } | ||
402 | perf->state = perf->state_count-1; | ||
403 | return freqn; | ||
404 | } else { | ||
405 | /* assume CPU is at P0... */ | ||
406 | perf->state = 0; | ||
407 | return perf->states[0].core_frequency * 1000; | ||
408 | } | ||
409 | } | ||
410 | |||
411 | static void free_acpi_perf_data(void) | ||
412 | { | ||
413 | unsigned int i; | ||
414 | |||
415 | /* Freeing a NULL pointer is OK, and alloc_percpu zeroes. */ | ||
416 | for_each_possible_cpu(i) | ||
417 | free_cpumask_var(per_cpu_ptr(acpi_perf_data, i) | ||
418 | ->shared_cpu_map); | ||
419 | free_percpu(acpi_perf_data); | ||
420 | } | ||
421 | |||
422 | /* | ||
423 | * acpi_cpufreq_early_init - initialize ACPI P-States library | ||
424 | * | ||
425 | * Initialize the ACPI P-States library (drivers/acpi/processor_perflib.c) | ||
426 | * in order to determine correct frequency and voltage pairings. We can | ||
427 | * do _PDC and _PSD and find out the processor dependency for the | ||
428 | * actual init that will happen later... | ||
429 | */ | ||
430 | static int __init acpi_cpufreq_early_init(void) | ||
431 | { | ||
432 | unsigned int i; | ||
433 | pr_debug("acpi_cpufreq_early_init\n"); | ||
434 | |||
435 | acpi_perf_data = alloc_percpu(struct acpi_processor_performance); | ||
436 | if (!acpi_perf_data) { | ||
437 | pr_debug("Memory allocation error for acpi_perf_data.\n"); | ||
438 | return -ENOMEM; | ||
439 | } | ||
440 | for_each_possible_cpu(i) { | ||
441 | if (!zalloc_cpumask_var_node( | ||
442 | &per_cpu_ptr(acpi_perf_data, i)->shared_cpu_map, | ||
443 | GFP_KERNEL, cpu_to_node(i))) { | ||
444 | |||
445 | /* Freeing a NULL pointer is OK: alloc_percpu zeroes. */ | ||
446 | free_acpi_perf_data(); | ||
447 | return -ENOMEM; | ||
448 | } | ||
449 | } | ||
450 | |||
451 | /* Do initialization in ACPI core */ | ||
452 | acpi_processor_preregister_performance(acpi_perf_data); | ||
453 | return 0; | ||
454 | } | ||
455 | |||
456 | #ifdef CONFIG_SMP | ||
457 | /* | ||
458 | * Some BIOSes do SW_ANY coordination internally, either set it up in hw | ||
459 | * or do it in BIOS firmware and won't inform about it to OS. If not | ||
460 | * detected, this has a side effect of making CPU run at a different speed | ||
461 | * than OS intended it to run at. Detect it and handle it cleanly. | ||
462 | */ | ||
463 | static int bios_with_sw_any_bug; | ||
464 | |||
465 | static int sw_any_bug_found(const struct dmi_system_id *d) | ||
466 | { | ||
467 | bios_with_sw_any_bug = 1; | ||
468 | return 0; | ||
469 | } | ||
470 | |||
471 | static const struct dmi_system_id sw_any_bug_dmi_table[] = { | ||
472 | { | ||
473 | .callback = sw_any_bug_found, | ||
474 | .ident = "Supermicro Server X6DLP", | ||
475 | .matches = { | ||
476 | DMI_MATCH(DMI_SYS_VENDOR, "Supermicro"), | ||
477 | DMI_MATCH(DMI_BIOS_VERSION, "080010"), | ||
478 | DMI_MATCH(DMI_PRODUCT_NAME, "X6DLP"), | ||
479 | }, | ||
480 | }, | ||
481 | { } | ||
482 | }; | ||
483 | |||
484 | static int acpi_cpufreq_blacklist(struct cpuinfo_x86 *c) | ||
485 | { | ||
486 | /* Intel Xeon Processor 7100 Series Specification Update | ||
487 | * http://www.intel.com/Assets/PDF/specupdate/314554.pdf | ||
488 | * AL30: A Machine Check Exception (MCE) Occurring during an | ||
489 | * Enhanced Intel SpeedStep Technology Ratio Change May Cause | ||
490 | * Both Processor Cores to Lock Up. */ | ||
491 | if (c->x86_vendor == X86_VENDOR_INTEL) { | ||
492 | if ((c->x86 == 15) && | ||
493 | (c->x86_model == 6) && | ||
494 | (c->x86_mask == 8)) { | ||
495 | printk(KERN_INFO "acpi-cpufreq: Intel(R) " | ||
496 | "Xeon(R) 7100 Errata AL30, processors may " | ||
497 | "lock up on frequency changes: disabling " | ||
498 | "acpi-cpufreq.\n"); | ||
499 | return -ENODEV; | ||
500 | } | ||
501 | } | ||
502 | return 0; | ||
503 | } | ||
504 | #endif | ||
505 | |||
506 | static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy) | ||
507 | { | ||
508 | unsigned int i; | ||
509 | unsigned int valid_states = 0; | ||
510 | unsigned int cpu = policy->cpu; | ||
511 | struct acpi_cpufreq_data *data; | ||
512 | unsigned int result = 0; | ||
513 | struct cpuinfo_x86 *c = &cpu_data(policy->cpu); | ||
514 | struct acpi_processor_performance *perf; | ||
515 | #ifdef CONFIG_SMP | ||
516 | static int blacklisted; | ||
517 | #endif | ||
518 | |||
519 | pr_debug("acpi_cpufreq_cpu_init\n"); | ||
520 | |||
521 | #ifdef CONFIG_SMP | ||
522 | if (blacklisted) | ||
523 | return blacklisted; | ||
524 | blacklisted = acpi_cpufreq_blacklist(c); | ||
525 | if (blacklisted) | ||
526 | return blacklisted; | ||
527 | #endif | ||
528 | |||
529 | data = kzalloc(sizeof(struct acpi_cpufreq_data), GFP_KERNEL); | ||
530 | if (!data) | ||
531 | return -ENOMEM; | ||
532 | |||
533 | data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu); | ||
534 | per_cpu(acfreq_data, cpu) = data; | ||
535 | |||
536 | if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) | ||
537 | acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS; | ||
538 | |||
539 | result = acpi_processor_register_performance(data->acpi_data, cpu); | ||
540 | if (result) | ||
541 | goto err_free; | ||
542 | |||
543 | perf = data->acpi_data; | ||
544 | policy->shared_type = perf->shared_type; | ||
545 | |||
546 | /* | ||
547 | * Will let policy->cpus know about dependency only when software | ||
548 | * coordination is required. | ||
549 | */ | ||
550 | if (policy->shared_type == CPUFREQ_SHARED_TYPE_ALL || | ||
551 | policy->shared_type == CPUFREQ_SHARED_TYPE_ANY) { | ||
552 | cpumask_copy(policy->cpus, perf->shared_cpu_map); | ||
553 | } | ||
554 | cpumask_copy(policy->related_cpus, perf->shared_cpu_map); | ||
555 | |||
556 | #ifdef CONFIG_SMP | ||
557 | dmi_check_system(sw_any_bug_dmi_table); | ||
558 | if (bios_with_sw_any_bug && cpumask_weight(policy->cpus) == 1) { | ||
559 | policy->shared_type = CPUFREQ_SHARED_TYPE_ALL; | ||
560 | cpumask_copy(policy->cpus, cpu_core_mask(cpu)); | ||
561 | } | ||
562 | #endif | ||
563 | |||
564 | /* capability check */ | ||
565 | if (perf->state_count <= 1) { | ||
566 | pr_debug("No P-States\n"); | ||
567 | result = -ENODEV; | ||
568 | goto err_unreg; | ||
569 | } | ||
570 | |||
571 | if (perf->control_register.space_id != perf->status_register.space_id) { | ||
572 | result = -ENODEV; | ||
573 | goto err_unreg; | ||
574 | } | ||
575 | |||
576 | switch (perf->control_register.space_id) { | ||
577 | case ACPI_ADR_SPACE_SYSTEM_IO: | ||
578 | pr_debug("SYSTEM IO addr space\n"); | ||
579 | data->cpu_feature = SYSTEM_IO_CAPABLE; | ||
580 | break; | ||
581 | case ACPI_ADR_SPACE_FIXED_HARDWARE: | ||
582 | pr_debug("HARDWARE addr space\n"); | ||
583 | if (!check_est_cpu(cpu)) { | ||
584 | result = -ENODEV; | ||
585 | goto err_unreg; | ||
586 | } | ||
587 | data->cpu_feature = SYSTEM_INTEL_MSR_CAPABLE; | ||
588 | break; | ||
589 | default: | ||
590 | pr_debug("Unknown addr space %d\n", | ||
591 | (u32) (perf->control_register.space_id)); | ||
592 | result = -ENODEV; | ||
593 | goto err_unreg; | ||
594 | } | ||
595 | |||
596 | data->freq_table = kmalloc(sizeof(struct cpufreq_frequency_table) * | ||
597 | (perf->state_count+1), GFP_KERNEL); | ||
598 | if (!data->freq_table) { | ||
599 | result = -ENOMEM; | ||
600 | goto err_unreg; | ||
601 | } | ||
602 | |||
603 | /* detect transition latency */ | ||
604 | policy->cpuinfo.transition_latency = 0; | ||
605 | for (i = 0; i < perf->state_count; i++) { | ||
606 | if ((perf->states[i].transition_latency * 1000) > | ||
607 | policy->cpuinfo.transition_latency) | ||
608 | policy->cpuinfo.transition_latency = | ||
609 | perf->states[i].transition_latency * 1000; | ||
610 | } | ||
611 | |||
612 | /* Check for high latency (>20uS) from buggy BIOSes, like on T42 */ | ||
613 | if (perf->control_register.space_id == ACPI_ADR_SPACE_FIXED_HARDWARE && | ||
614 | policy->cpuinfo.transition_latency > 20 * 1000) { | ||
615 | policy->cpuinfo.transition_latency = 20 * 1000; | ||
616 | printk_once(KERN_INFO | ||
617 | "P-state transition latency capped at 20 uS\n"); | ||
618 | } | ||
619 | |||
620 | /* table init */ | ||
621 | for (i = 0; i < perf->state_count; i++) { | ||
622 | if (i > 0 && perf->states[i].core_frequency >= | ||
623 | data->freq_table[valid_states-1].frequency / 1000) | ||
624 | continue; | ||
625 | |||
626 | data->freq_table[valid_states].index = i; | ||
627 | data->freq_table[valid_states].frequency = | ||
628 | perf->states[i].core_frequency * 1000; | ||
629 | valid_states++; | ||
630 | } | ||
631 | data->freq_table[valid_states].frequency = CPUFREQ_TABLE_END; | ||
632 | perf->state = 0; | ||
633 | |||
634 | result = cpufreq_frequency_table_cpuinfo(policy, data->freq_table); | ||
635 | if (result) | ||
636 | goto err_freqfree; | ||
637 | |||
638 | if (perf->states[0].core_frequency * 1000 != policy->cpuinfo.max_freq) | ||
639 | printk(KERN_WARNING FW_WARN "P-state 0 is not max freq\n"); | ||
640 | |||
641 | switch (perf->control_register.space_id) { | ||
642 | case ACPI_ADR_SPACE_SYSTEM_IO: | ||
643 | /* Current speed is unknown and not detectable by IO port */ | ||
644 | policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu); | ||
645 | break; | ||
646 | case ACPI_ADR_SPACE_FIXED_HARDWARE: | ||
647 | acpi_cpufreq_driver.get = get_cur_freq_on_cpu; | ||
648 | policy->cur = get_cur_freq_on_cpu(cpu); | ||
649 | break; | ||
650 | default: | ||
651 | break; | ||
652 | } | ||
653 | |||
654 | /* notify BIOS that we exist */ | ||
655 | acpi_processor_notify_smm(THIS_MODULE); | ||
656 | |||
657 | /* Check for APERF/MPERF support in hardware */ | ||
658 | if (cpu_has(c, X86_FEATURE_APERFMPERF)) | ||
659 | acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf; | ||
660 | |||
661 | pr_debug("CPU%u - ACPI performance management activated.\n", cpu); | ||
662 | for (i = 0; i < perf->state_count; i++) | ||
663 | pr_debug(" %cP%d: %d MHz, %d mW, %d uS\n", | ||
664 | (i == perf->state ? '*' : ' '), i, | ||
665 | (u32) perf->states[i].core_frequency, | ||
666 | (u32) perf->states[i].power, | ||
667 | (u32) perf->states[i].transition_latency); | ||
668 | |||
669 | cpufreq_frequency_table_get_attr(data->freq_table, policy->cpu); | ||
670 | |||
671 | /* | ||
672 | * the first call to ->target() should result in us actually | ||
673 | * writing something to the appropriate registers. | ||
674 | */ | ||
675 | data->resume = 1; | ||
676 | |||
677 | return result; | ||
678 | |||
679 | err_freqfree: | ||
680 | kfree(data->freq_table); | ||
681 | err_unreg: | ||
682 | acpi_processor_unregister_performance(perf, cpu); | ||
683 | err_free: | ||
684 | kfree(data); | ||
685 | per_cpu(acfreq_data, cpu) = NULL; | ||
686 | |||
687 | return result; | ||
688 | } | ||
689 | |||
690 | static int acpi_cpufreq_cpu_exit(struct cpufreq_policy *policy) | ||
691 | { | ||
692 | struct acpi_cpufreq_data *data = per_cpu(acfreq_data, policy->cpu); | ||
693 | |||
694 | pr_debug("acpi_cpufreq_cpu_exit\n"); | ||
695 | |||
696 | if (data) { | ||
697 | cpufreq_frequency_table_put_attr(policy->cpu); | ||
698 | per_cpu(acfreq_data, policy->cpu) = NULL; | ||
699 | acpi_processor_unregister_performance(data->acpi_data, | ||
700 | policy->cpu); | ||
701 | kfree(data->freq_table); | ||
702 | kfree(data); | ||
703 | } | ||
704 | |||
705 | return 0; | ||
706 | } | ||
707 | |||
708 | static int acpi_cpufreq_resume(struct cpufreq_policy *policy) | ||
709 | { | ||
710 | struct acpi_cpufreq_data *data = per_cpu(acfreq_data, policy->cpu); | ||
711 | |||
712 | pr_debug("acpi_cpufreq_resume\n"); | ||
713 | |||
714 | data->resume = 1; | ||
715 | |||
716 | return 0; | ||
717 | } | ||
718 | |||
719 | static struct freq_attr *acpi_cpufreq_attr[] = { | ||
720 | &cpufreq_freq_attr_scaling_available_freqs, | ||
721 | NULL, | ||
722 | }; | ||
723 | |||
724 | static struct cpufreq_driver acpi_cpufreq_driver = { | ||
725 | .verify = acpi_cpufreq_verify, | ||
726 | .target = acpi_cpufreq_target, | ||
727 | .bios_limit = acpi_processor_get_bios_limit, | ||
728 | .init = acpi_cpufreq_cpu_init, | ||
729 | .exit = acpi_cpufreq_cpu_exit, | ||
730 | .resume = acpi_cpufreq_resume, | ||
731 | .name = "acpi-cpufreq", | ||
732 | .owner = THIS_MODULE, | ||
733 | .attr = acpi_cpufreq_attr, | ||
734 | }; | ||
735 | |||
736 | static int __init acpi_cpufreq_init(void) | ||
737 | { | ||
738 | int ret; | ||
739 | |||
740 | if (acpi_disabled) | ||
741 | return 0; | ||
742 | |||
743 | pr_debug("acpi_cpufreq_init\n"); | ||
744 | |||
745 | ret = acpi_cpufreq_early_init(); | ||
746 | if (ret) | ||
747 | return ret; | ||
748 | |||
749 | ret = cpufreq_register_driver(&acpi_cpufreq_driver); | ||
750 | if (ret) | ||
751 | free_acpi_perf_data(); | ||
752 | |||
753 | return ret; | ||
754 | } | ||
755 | |||
756 | static void __exit acpi_cpufreq_exit(void) | ||
757 | { | ||
758 | pr_debug("acpi_cpufreq_exit\n"); | ||
759 | |||
760 | cpufreq_unregister_driver(&acpi_cpufreq_driver); | ||
761 | |||
762 | free_percpu(acpi_perf_data); | ||
763 | } | ||
764 | |||
765 | module_param(acpi_pstate_strict, uint, 0644); | ||
766 | MODULE_PARM_DESC(acpi_pstate_strict, | ||
767 | "value 0 or non-zero. non-zero -> strict ACPI checks are " | ||
768 | "performed during frequency changes."); | ||
769 | |||
770 | late_initcall(acpi_cpufreq_init); | ||
771 | module_exit(acpi_cpufreq_exit); | ||
772 | |||
773 | MODULE_ALIAS("acpi"); | ||
diff --git a/drivers/cpufreq/cpufreq-nforce2.c b/drivers/cpufreq/cpufreq-nforce2.c new file mode 100644 index 000000000000..7bac808804f3 --- /dev/null +++ b/drivers/cpufreq/cpufreq-nforce2.c | |||
@@ -0,0 +1,444 @@ | |||
1 | /* | ||
2 | * (C) 2004-2006 Sebastian Witt <se.witt@gmx.net> | ||
3 | * | ||
4 | * Licensed under the terms of the GNU GPL License version 2. | ||
5 | * Based upon reverse engineered information | ||
6 | * | ||
7 | * BIG FAT DISCLAIMER: Work in progress code. Possibly *dangerous* | ||
8 | */ | ||
9 | |||
10 | #include <linux/kernel.h> | ||
11 | #include <linux/module.h> | ||
12 | #include <linux/moduleparam.h> | ||
13 | #include <linux/init.h> | ||
14 | #include <linux/cpufreq.h> | ||
15 | #include <linux/pci.h> | ||
16 | #include <linux/delay.h> | ||
17 | |||
18 | #define NFORCE2_XTAL 25 | ||
19 | #define NFORCE2_BOOTFSB 0x48 | ||
20 | #define NFORCE2_PLLENABLE 0xa8 | ||
21 | #define NFORCE2_PLLREG 0xa4 | ||
22 | #define NFORCE2_PLLADR 0xa0 | ||
23 | #define NFORCE2_PLL(mul, div) (0x100000 | (mul << 8) | div) | ||
24 | |||
25 | #define NFORCE2_MIN_FSB 50 | ||
26 | #define NFORCE2_SAFE_DISTANCE 50 | ||
27 | |||
28 | /* Delay in ms between FSB changes */ | ||
29 | /* #define NFORCE2_DELAY 10 */ | ||
30 | |||
31 | /* | ||
32 | * nforce2_chipset: | ||
33 | * FSB is changed using the chipset | ||
34 | */ | ||
35 | static struct pci_dev *nforce2_dev; | ||
36 | |||
37 | /* fid: | ||
38 | * multiplier * 10 | ||
39 | */ | ||
40 | static int fid; | ||
41 | |||
42 | /* min_fsb, max_fsb: | ||
43 | * minimum and maximum FSB (= FSB at boot time) | ||
44 | */ | ||
45 | static int min_fsb; | ||
46 | static int max_fsb; | ||
47 | |||
48 | MODULE_AUTHOR("Sebastian Witt <se.witt@gmx.net>"); | ||
49 | MODULE_DESCRIPTION("nForce2 FSB changing cpufreq driver"); | ||
50 | MODULE_LICENSE("GPL"); | ||
51 | |||
52 | module_param(fid, int, 0444); | ||
53 | module_param(min_fsb, int, 0444); | ||
54 | |||
55 | MODULE_PARM_DESC(fid, "CPU multiplier to use (11.5 = 115)"); | ||
56 | MODULE_PARM_DESC(min_fsb, | ||
57 | "Minimum FSB to use, if not defined: current FSB - 50"); | ||
58 | |||
59 | #define PFX "cpufreq-nforce2: " | ||
60 | |||
61 | /** | ||
62 | * nforce2_calc_fsb - calculate FSB | ||
63 | * @pll: PLL value | ||
64 | * | ||
65 | * Calculates FSB from PLL value | ||
66 | */ | ||
67 | static int nforce2_calc_fsb(int pll) | ||
68 | { | ||
69 | unsigned char mul, div; | ||
70 | |||
71 | mul = (pll >> 8) & 0xff; | ||
72 | div = pll & 0xff; | ||
73 | |||
74 | if (div > 0) | ||
75 | return NFORCE2_XTAL * mul / div; | ||
76 | |||
77 | return 0; | ||
78 | } | ||
79 | |||
80 | /** | ||
81 | * nforce2_calc_pll - calculate PLL value | ||
82 | * @fsb: FSB | ||
83 | * | ||
84 | * Calculate PLL value for given FSB | ||
85 | */ | ||
86 | static int nforce2_calc_pll(unsigned int fsb) | ||
87 | { | ||
88 | unsigned char xmul, xdiv; | ||
89 | unsigned char mul = 0, div = 0; | ||
90 | int tried = 0; | ||
91 | |||
92 | /* Try to calculate multiplier and divider up to 4 times */ | ||
93 | while (((mul == 0) || (div == 0)) && (tried <= 3)) { | ||
94 | for (xdiv = 2; xdiv <= 0x80; xdiv++) | ||
95 | for (xmul = 1; xmul <= 0xfe; xmul++) | ||
96 | if (nforce2_calc_fsb(NFORCE2_PLL(xmul, xdiv)) == | ||
97 | fsb + tried) { | ||
98 | mul = xmul; | ||
99 | div = xdiv; | ||
100 | } | ||
101 | tried++; | ||
102 | } | ||
103 | |||
104 | if ((mul == 0) || (div == 0)) | ||
105 | return -1; | ||
106 | |||
107 | return NFORCE2_PLL(mul, div); | ||
108 | } | ||
109 | |||
110 | /** | ||
111 | * nforce2_write_pll - write PLL value to chipset | ||
112 | * @pll: PLL value | ||
113 | * | ||
114 | * Writes new FSB PLL value to chipset | ||
115 | */ | ||
116 | static void nforce2_write_pll(int pll) | ||
117 | { | ||
118 | int temp; | ||
119 | |||
120 | /* Set the pll addr. to 0x00 */ | ||
121 | pci_write_config_dword(nforce2_dev, NFORCE2_PLLADR, 0); | ||
122 | |||
123 | /* Now write the value in all 64 registers */ | ||
124 | for (temp = 0; temp <= 0x3f; temp++) | ||
125 | pci_write_config_dword(nforce2_dev, NFORCE2_PLLREG, pll); | ||
126 | |||
127 | return; | ||
128 | } | ||
129 | |||
130 | /** | ||
131 | * nforce2_fsb_read - Read FSB | ||
132 | * | ||
133 | * Read FSB from chipset | ||
134 | * If bootfsb != 0, return FSB at boot-time | ||
135 | */ | ||
136 | static unsigned int nforce2_fsb_read(int bootfsb) | ||
137 | { | ||
138 | struct pci_dev *nforce2_sub5; | ||
139 | u32 fsb, temp = 0; | ||
140 | |||
141 | /* Get chipset boot FSB from subdevice 5 (FSB at boot-time) */ | ||
142 | nforce2_sub5 = pci_get_subsys(PCI_VENDOR_ID_NVIDIA, 0x01EF, | ||
143 | PCI_ANY_ID, PCI_ANY_ID, NULL); | ||
144 | if (!nforce2_sub5) | ||
145 | return 0; | ||
146 | |||
147 | pci_read_config_dword(nforce2_sub5, NFORCE2_BOOTFSB, &fsb); | ||
148 | fsb /= 1000000; | ||
149 | |||
150 | /* Check if PLL register is already set */ | ||
151 | pci_read_config_byte(nforce2_dev, NFORCE2_PLLENABLE, (u8 *)&temp); | ||
152 | |||
153 | if (bootfsb || !temp) | ||
154 | return fsb; | ||
155 | |||
156 | /* Use PLL register FSB value */ | ||
157 | pci_read_config_dword(nforce2_dev, NFORCE2_PLLREG, &temp); | ||
158 | fsb = nforce2_calc_fsb(temp); | ||
159 | |||
160 | return fsb; | ||
161 | } | ||
162 | |||
163 | /** | ||
164 | * nforce2_set_fsb - set new FSB | ||
165 | * @fsb: New FSB | ||
166 | * | ||
167 | * Sets new FSB | ||
168 | */ | ||
169 | static int nforce2_set_fsb(unsigned int fsb) | ||
170 | { | ||
171 | u32 temp = 0; | ||
172 | unsigned int tfsb; | ||
173 | int diff; | ||
174 | int pll = 0; | ||
175 | |||
176 | if ((fsb > max_fsb) || (fsb < NFORCE2_MIN_FSB)) { | ||
177 | printk(KERN_ERR PFX "FSB %d is out of range!\n", fsb); | ||
178 | return -EINVAL; | ||
179 | } | ||
180 | |||
181 | tfsb = nforce2_fsb_read(0); | ||
182 | if (!tfsb) { | ||
183 | printk(KERN_ERR PFX "Error while reading the FSB\n"); | ||
184 | return -EINVAL; | ||
185 | } | ||
186 | |||
187 | /* First write? Then set actual value */ | ||
188 | pci_read_config_byte(nforce2_dev, NFORCE2_PLLENABLE, (u8 *)&temp); | ||
189 | if (!temp) { | ||
190 | pll = nforce2_calc_pll(tfsb); | ||
191 | |||
192 | if (pll < 0) | ||
193 | return -EINVAL; | ||
194 | |||
195 | nforce2_write_pll(pll); | ||
196 | } | ||
197 | |||
198 | /* Enable write access */ | ||
199 | temp = 0x01; | ||
200 | pci_write_config_byte(nforce2_dev, NFORCE2_PLLENABLE, (u8)temp); | ||
201 | |||
202 | diff = tfsb - fsb; | ||
203 | |||
204 | if (!diff) | ||
205 | return 0; | ||
206 | |||
207 | while ((tfsb != fsb) && (tfsb <= max_fsb) && (tfsb >= min_fsb)) { | ||
208 | if (diff < 0) | ||
209 | tfsb++; | ||
210 | else | ||
211 | tfsb--; | ||
212 | |||
213 | /* Calculate the PLL reg. value */ | ||
214 | pll = nforce2_calc_pll(tfsb); | ||
215 | if (pll == -1) | ||
216 | return -EINVAL; | ||
217 | |||
218 | nforce2_write_pll(pll); | ||
219 | #ifdef NFORCE2_DELAY | ||
220 | mdelay(NFORCE2_DELAY); | ||
221 | #endif | ||
222 | } | ||
223 | |||
224 | temp = 0x40; | ||
225 | pci_write_config_byte(nforce2_dev, NFORCE2_PLLADR, (u8)temp); | ||
226 | |||
227 | return 0; | ||
228 | } | ||
229 | |||
230 | /** | ||
231 | * nforce2_get - get the CPU frequency | ||
232 | * @cpu: CPU number | ||
233 | * | ||
234 | * Returns the CPU frequency | ||
235 | */ | ||
236 | static unsigned int nforce2_get(unsigned int cpu) | ||
237 | { | ||
238 | if (cpu) | ||
239 | return 0; | ||
240 | return nforce2_fsb_read(0) * fid * 100; | ||
241 | } | ||
242 | |||
243 | /** | ||
244 | * nforce2_target - set a new CPUFreq policy | ||
245 | * @policy: new policy | ||
246 | * @target_freq: the target frequency | ||
247 | * @relation: how that frequency relates to achieved frequency | ||
248 | * (CPUFREQ_RELATION_L or CPUFREQ_RELATION_H) | ||
249 | * | ||
250 | * Sets a new CPUFreq policy. | ||
251 | */ | ||
252 | static int nforce2_target(struct cpufreq_policy *policy, | ||
253 | unsigned int target_freq, unsigned int relation) | ||
254 | { | ||
255 | /* unsigned long flags; */ | ||
256 | struct cpufreq_freqs freqs; | ||
257 | unsigned int target_fsb; | ||
258 | |||
259 | if ((target_freq > policy->max) || (target_freq < policy->min)) | ||
260 | return -EINVAL; | ||
261 | |||
262 | target_fsb = target_freq / (fid * 100); | ||
263 | |||
264 | freqs.old = nforce2_get(policy->cpu); | ||
265 | freqs.new = target_fsb * fid * 100; | ||
266 | freqs.cpu = 0; /* Only one CPU on nForce2 platforms */ | ||
267 | |||
268 | if (freqs.old == freqs.new) | ||
269 | return 0; | ||
270 | |||
271 | pr_debug("Old CPU frequency %d kHz, new %d kHz\n", | ||
272 | freqs.old, freqs.new); | ||
273 | |||
274 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
275 | |||
276 | /* Disable IRQs */ | ||
277 | /* local_irq_save(flags); */ | ||
278 | |||
279 | if (nforce2_set_fsb(target_fsb) < 0) | ||
280 | printk(KERN_ERR PFX "Changing FSB to %d failed\n", | ||
281 | target_fsb); | ||
282 | else | ||
283 | pr_debug("Changed FSB successfully to %d\n", | ||
284 | target_fsb); | ||
285 | |||
286 | /* Enable IRQs */ | ||
287 | /* local_irq_restore(flags); */ | ||
288 | |||
289 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
290 | |||
291 | return 0; | ||
292 | } | ||
293 | |||
294 | /** | ||
295 | * nforce2_verify - verifies a new CPUFreq policy | ||
296 | * @policy: new policy | ||
297 | */ | ||
298 | static int nforce2_verify(struct cpufreq_policy *policy) | ||
299 | { | ||
300 | unsigned int fsb_pol_max; | ||
301 | |||
302 | fsb_pol_max = policy->max / (fid * 100); | ||
303 | |||
304 | if (policy->min < (fsb_pol_max * fid * 100)) | ||
305 | policy->max = (fsb_pol_max + 1) * fid * 100; | ||
306 | |||
307 | cpufreq_verify_within_limits(policy, | ||
308 | policy->cpuinfo.min_freq, | ||
309 | policy->cpuinfo.max_freq); | ||
310 | return 0; | ||
311 | } | ||
312 | |||
313 | static int nforce2_cpu_init(struct cpufreq_policy *policy) | ||
314 | { | ||
315 | unsigned int fsb; | ||
316 | unsigned int rfid; | ||
317 | |||
318 | /* capability check */ | ||
319 | if (policy->cpu != 0) | ||
320 | return -ENODEV; | ||
321 | |||
322 | /* Get current FSB */ | ||
323 | fsb = nforce2_fsb_read(0); | ||
324 | |||
325 | if (!fsb) | ||
326 | return -EIO; | ||
327 | |||
328 | /* FIX: Get FID from CPU */ | ||
329 | if (!fid) { | ||
330 | if (!cpu_khz) { | ||
331 | printk(KERN_WARNING PFX | ||
332 | "cpu_khz not set, can't calculate multiplier!\n"); | ||
333 | return -ENODEV; | ||
334 | } | ||
335 | |||
336 | fid = cpu_khz / (fsb * 100); | ||
337 | rfid = fid % 5; | ||
338 | |||
339 | if (rfid) { | ||
340 | if (rfid > 2) | ||
341 | fid += 5 - rfid; | ||
342 | else | ||
343 | fid -= rfid; | ||
344 | } | ||
345 | } | ||
346 | |||
347 | printk(KERN_INFO PFX "FSB currently at %i MHz, FID %d.%d\n", fsb, | ||
348 | fid / 10, fid % 10); | ||
349 | |||
350 | /* Set maximum FSB to FSB at boot time */ | ||
351 | max_fsb = nforce2_fsb_read(1); | ||
352 | |||
353 | if (!max_fsb) | ||
354 | return -EIO; | ||
355 | |||
356 | if (!min_fsb) | ||
357 | min_fsb = max_fsb - NFORCE2_SAFE_DISTANCE; | ||
358 | |||
359 | if (min_fsb < NFORCE2_MIN_FSB) | ||
360 | min_fsb = NFORCE2_MIN_FSB; | ||
361 | |||
362 | /* cpuinfo and default policy values */ | ||
363 | policy->cpuinfo.min_freq = min_fsb * fid * 100; | ||
364 | policy->cpuinfo.max_freq = max_fsb * fid * 100; | ||
365 | policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL; | ||
366 | policy->cur = nforce2_get(policy->cpu); | ||
367 | policy->min = policy->cpuinfo.min_freq; | ||
368 | policy->max = policy->cpuinfo.max_freq; | ||
369 | |||
370 | return 0; | ||
371 | } | ||
372 | |||
373 | static int nforce2_cpu_exit(struct cpufreq_policy *policy) | ||
374 | { | ||
375 | return 0; | ||
376 | } | ||
377 | |||
378 | static struct cpufreq_driver nforce2_driver = { | ||
379 | .name = "nforce2", | ||
380 | .verify = nforce2_verify, | ||
381 | .target = nforce2_target, | ||
382 | .get = nforce2_get, | ||
383 | .init = nforce2_cpu_init, | ||
384 | .exit = nforce2_cpu_exit, | ||
385 | .owner = THIS_MODULE, | ||
386 | }; | ||
387 | |||
388 | /** | ||
389 | * nforce2_detect_chipset - detect the Southbridge which contains FSB PLL logic | ||
390 | * | ||
391 | * Detects nForce2 A2 and C1 stepping | ||
392 | * | ||
393 | */ | ||
394 | static int nforce2_detect_chipset(void) | ||
395 | { | ||
396 | nforce2_dev = pci_get_subsys(PCI_VENDOR_ID_NVIDIA, | ||
397 | PCI_DEVICE_ID_NVIDIA_NFORCE2, | ||
398 | PCI_ANY_ID, PCI_ANY_ID, NULL); | ||
399 | |||
400 | if (nforce2_dev == NULL) | ||
401 | return -ENODEV; | ||
402 | |||
403 | printk(KERN_INFO PFX "Detected nForce2 chipset revision %X\n", | ||
404 | nforce2_dev->revision); | ||
405 | printk(KERN_INFO PFX | ||
406 | "FSB changing is maybe unstable and can lead to " | ||
407 | "crashes and data loss.\n"); | ||
408 | |||
409 | return 0; | ||
410 | } | ||
411 | |||
412 | /** | ||
413 | * nforce2_init - initializes the nForce2 CPUFreq driver | ||
414 | * | ||
415 | * Initializes the nForce2 FSB support. Returns -ENODEV on unsupported | ||
416 | * devices, -EINVAL on problems during initiatization, and zero on | ||
417 | * success. | ||
418 | */ | ||
419 | static int __init nforce2_init(void) | ||
420 | { | ||
421 | /* TODO: do we need to detect the processor? */ | ||
422 | |||
423 | /* detect chipset */ | ||
424 | if (nforce2_detect_chipset()) { | ||
425 | printk(KERN_INFO PFX "No nForce2 chipset.\n"); | ||
426 | return -ENODEV; | ||
427 | } | ||
428 | |||
429 | return cpufreq_register_driver(&nforce2_driver); | ||
430 | } | ||
431 | |||
432 | /** | ||
433 | * nforce2_exit - unregisters cpufreq module | ||
434 | * | ||
435 | * Unregisters nForce2 FSB change support. | ||
436 | */ | ||
437 | static void __exit nforce2_exit(void) | ||
438 | { | ||
439 | cpufreq_unregister_driver(&nforce2_driver); | ||
440 | } | ||
441 | |||
442 | module_init(nforce2_init); | ||
443 | module_exit(nforce2_exit); | ||
444 | |||
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 2dafc5c38ae7..0a5bea9e3585 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c | |||
@@ -32,9 +32,6 @@ | |||
32 | 32 | ||
33 | #include <trace/events/power.h> | 33 | #include <trace/events/power.h> |
34 | 34 | ||
35 | #define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_CORE, \ | ||
36 | "cpufreq-core", msg) | ||
37 | |||
38 | /** | 35 | /** |
39 | * The "cpufreq driver" - the arch- or hardware-dependent low | 36 | * The "cpufreq driver" - the arch- or hardware-dependent low |
40 | * level driver of CPUFreq support, and its spinlock. This lock | 37 | * level driver of CPUFreq support, and its spinlock. This lock |
@@ -181,93 +178,6 @@ EXPORT_SYMBOL_GPL(cpufreq_cpu_put); | |||
181 | 178 | ||
182 | 179 | ||
183 | /********************************************************************* | 180 | /********************************************************************* |
184 | * UNIFIED DEBUG HELPERS * | ||
185 | *********************************************************************/ | ||
186 | #ifdef CONFIG_CPU_FREQ_DEBUG | ||
187 | |||
188 | /* what part(s) of the CPUfreq subsystem are debugged? */ | ||
189 | static unsigned int debug; | ||
190 | |||
191 | /* is the debug output ratelimit'ed using printk_ratelimit? User can | ||
192 | * set or modify this value. | ||
193 | */ | ||
194 | static unsigned int debug_ratelimit = 1; | ||
195 | |||
196 | /* is the printk_ratelimit'ing enabled? It's enabled after a successful | ||
197 | * loading of a cpufreq driver, temporarily disabled when a new policy | ||
198 | * is set, and disabled upon cpufreq driver removal | ||
199 | */ | ||
200 | static unsigned int disable_ratelimit = 1; | ||
201 | static DEFINE_SPINLOCK(disable_ratelimit_lock); | ||
202 | |||
203 | static void cpufreq_debug_enable_ratelimit(void) | ||
204 | { | ||
205 | unsigned long flags; | ||
206 | |||
207 | spin_lock_irqsave(&disable_ratelimit_lock, flags); | ||
208 | if (disable_ratelimit) | ||
209 | disable_ratelimit--; | ||
210 | spin_unlock_irqrestore(&disable_ratelimit_lock, flags); | ||
211 | } | ||
212 | |||
213 | static void cpufreq_debug_disable_ratelimit(void) | ||
214 | { | ||
215 | unsigned long flags; | ||
216 | |||
217 | spin_lock_irqsave(&disable_ratelimit_lock, flags); | ||
218 | disable_ratelimit++; | ||
219 | spin_unlock_irqrestore(&disable_ratelimit_lock, flags); | ||
220 | } | ||
221 | |||
222 | void cpufreq_debug_printk(unsigned int type, const char *prefix, | ||
223 | const char *fmt, ...) | ||
224 | { | ||
225 | char s[256]; | ||
226 | va_list args; | ||
227 | unsigned int len; | ||
228 | unsigned long flags; | ||
229 | |||
230 | WARN_ON(!prefix); | ||
231 | if (type & debug) { | ||
232 | spin_lock_irqsave(&disable_ratelimit_lock, flags); | ||
233 | if (!disable_ratelimit && debug_ratelimit | ||
234 | && !printk_ratelimit()) { | ||
235 | spin_unlock_irqrestore(&disable_ratelimit_lock, flags); | ||
236 | return; | ||
237 | } | ||
238 | spin_unlock_irqrestore(&disable_ratelimit_lock, flags); | ||
239 | |||
240 | len = snprintf(s, 256, KERN_DEBUG "%s: ", prefix); | ||
241 | |||
242 | va_start(args, fmt); | ||
243 | len += vsnprintf(&s[len], (256 - len), fmt, args); | ||
244 | va_end(args); | ||
245 | |||
246 | printk(s); | ||
247 | |||
248 | WARN_ON(len < 5); | ||
249 | } | ||
250 | } | ||
251 | EXPORT_SYMBOL(cpufreq_debug_printk); | ||
252 | |||
253 | |||
254 | module_param(debug, uint, 0644); | ||
255 | MODULE_PARM_DESC(debug, "CPUfreq debugging: add 1 to debug core," | ||
256 | " 2 to debug drivers, and 4 to debug governors."); | ||
257 | |||
258 | module_param(debug_ratelimit, uint, 0644); | ||
259 | MODULE_PARM_DESC(debug_ratelimit, "CPUfreq debugging:" | ||
260 | " set to 0 to disable ratelimiting."); | ||
261 | |||
262 | #else /* !CONFIG_CPU_FREQ_DEBUG */ | ||
263 | |||
264 | static inline void cpufreq_debug_enable_ratelimit(void) { return; } | ||
265 | static inline void cpufreq_debug_disable_ratelimit(void) { return; } | ||
266 | |||
267 | #endif /* CONFIG_CPU_FREQ_DEBUG */ | ||
268 | |||
269 | |||
270 | /********************************************************************* | ||
271 | * EXTERNALLY AFFECTING FREQUENCY CHANGES * | 181 | * EXTERNALLY AFFECTING FREQUENCY CHANGES * |
272 | *********************************************************************/ | 182 | *********************************************************************/ |
273 | 183 | ||
@@ -291,7 +201,7 @@ static void adjust_jiffies(unsigned long val, struct cpufreq_freqs *ci) | |||
291 | if (!l_p_j_ref_freq) { | 201 | if (!l_p_j_ref_freq) { |
292 | l_p_j_ref = loops_per_jiffy; | 202 | l_p_j_ref = loops_per_jiffy; |
293 | l_p_j_ref_freq = ci->old; | 203 | l_p_j_ref_freq = ci->old; |
294 | dprintk("saving %lu as reference value for loops_per_jiffy; " | 204 | pr_debug("saving %lu as reference value for loops_per_jiffy; " |
295 | "freq is %u kHz\n", l_p_j_ref, l_p_j_ref_freq); | 205 | "freq is %u kHz\n", l_p_j_ref, l_p_j_ref_freq); |
296 | } | 206 | } |
297 | if ((val == CPUFREQ_PRECHANGE && ci->old < ci->new) || | 207 | if ((val == CPUFREQ_PRECHANGE && ci->old < ci->new) || |
@@ -299,7 +209,7 @@ static void adjust_jiffies(unsigned long val, struct cpufreq_freqs *ci) | |||
299 | (val == CPUFREQ_RESUMECHANGE || val == CPUFREQ_SUSPENDCHANGE)) { | 209 | (val == CPUFREQ_RESUMECHANGE || val == CPUFREQ_SUSPENDCHANGE)) { |
300 | loops_per_jiffy = cpufreq_scale(l_p_j_ref, l_p_j_ref_freq, | 210 | loops_per_jiffy = cpufreq_scale(l_p_j_ref, l_p_j_ref_freq, |
301 | ci->new); | 211 | ci->new); |
302 | dprintk("scaling loops_per_jiffy to %lu " | 212 | pr_debug("scaling loops_per_jiffy to %lu " |
303 | "for frequency %u kHz\n", loops_per_jiffy, ci->new); | 213 | "for frequency %u kHz\n", loops_per_jiffy, ci->new); |
304 | } | 214 | } |
305 | } | 215 | } |
@@ -326,7 +236,7 @@ void cpufreq_notify_transition(struct cpufreq_freqs *freqs, unsigned int state) | |||
326 | BUG_ON(irqs_disabled()); | 236 | BUG_ON(irqs_disabled()); |
327 | 237 | ||
328 | freqs->flags = cpufreq_driver->flags; | 238 | freqs->flags = cpufreq_driver->flags; |
329 | dprintk("notification %u of frequency transition to %u kHz\n", | 239 | pr_debug("notification %u of frequency transition to %u kHz\n", |
330 | state, freqs->new); | 240 | state, freqs->new); |
331 | 241 | ||
332 | policy = per_cpu(cpufreq_cpu_data, freqs->cpu); | 242 | policy = per_cpu(cpufreq_cpu_data, freqs->cpu); |
@@ -340,7 +250,7 @@ void cpufreq_notify_transition(struct cpufreq_freqs *freqs, unsigned int state) | |||
340 | if (!(cpufreq_driver->flags & CPUFREQ_CONST_LOOPS)) { | 250 | if (!(cpufreq_driver->flags & CPUFREQ_CONST_LOOPS)) { |
341 | if ((policy) && (policy->cpu == freqs->cpu) && | 251 | if ((policy) && (policy->cpu == freqs->cpu) && |
342 | (policy->cur) && (policy->cur != freqs->old)) { | 252 | (policy->cur) && (policy->cur != freqs->old)) { |
343 | dprintk("Warning: CPU frequency is" | 253 | pr_debug("Warning: CPU frequency is" |
344 | " %u, cpufreq assumed %u kHz.\n", | 254 | " %u, cpufreq assumed %u kHz.\n", |
345 | freqs->old, policy->cur); | 255 | freqs->old, policy->cur); |
346 | freqs->old = policy->cur; | 256 | freqs->old = policy->cur; |
@@ -353,7 +263,7 @@ void cpufreq_notify_transition(struct cpufreq_freqs *freqs, unsigned int state) | |||
353 | 263 | ||
354 | case CPUFREQ_POSTCHANGE: | 264 | case CPUFREQ_POSTCHANGE: |
355 | adjust_jiffies(CPUFREQ_POSTCHANGE, freqs); | 265 | adjust_jiffies(CPUFREQ_POSTCHANGE, freqs); |
356 | dprintk("FREQ: %lu - CPU: %lu", (unsigned long)freqs->new, | 266 | pr_debug("FREQ: %lu - CPU: %lu", (unsigned long)freqs->new, |
357 | (unsigned long)freqs->cpu); | 267 | (unsigned long)freqs->cpu); |
358 | trace_power_frequency(POWER_PSTATE, freqs->new, freqs->cpu); | 268 | trace_power_frequency(POWER_PSTATE, freqs->new, freqs->cpu); |
359 | trace_cpu_frequency(freqs->new, freqs->cpu); | 269 | trace_cpu_frequency(freqs->new, freqs->cpu); |
@@ -411,21 +321,14 @@ static int cpufreq_parse_governor(char *str_governor, unsigned int *policy, | |||
411 | t = __find_governor(str_governor); | 321 | t = __find_governor(str_governor); |
412 | 322 | ||
413 | if (t == NULL) { | 323 | if (t == NULL) { |
414 | char *name = kasprintf(GFP_KERNEL, "cpufreq_%s", | 324 | int ret; |
415 | str_governor); | ||
416 | |||
417 | if (name) { | ||
418 | int ret; | ||
419 | 325 | ||
420 | mutex_unlock(&cpufreq_governor_mutex); | 326 | mutex_unlock(&cpufreq_governor_mutex); |
421 | ret = request_module("%s", name); | 327 | ret = request_module("cpufreq_%s", str_governor); |
422 | mutex_lock(&cpufreq_governor_mutex); | 328 | mutex_lock(&cpufreq_governor_mutex); |
423 | 329 | ||
424 | if (ret == 0) | 330 | if (ret == 0) |
425 | t = __find_governor(str_governor); | 331 | t = __find_governor(str_governor); |
426 | } | ||
427 | |||
428 | kfree(name); | ||
429 | } | 332 | } |
430 | 333 | ||
431 | if (t != NULL) { | 334 | if (t != NULL) { |
@@ -753,7 +656,7 @@ no_policy: | |||
753 | static void cpufreq_sysfs_release(struct kobject *kobj) | 656 | static void cpufreq_sysfs_release(struct kobject *kobj) |
754 | { | 657 | { |
755 | struct cpufreq_policy *policy = to_policy(kobj); | 658 | struct cpufreq_policy *policy = to_policy(kobj); |
756 | dprintk("last reference is dropped\n"); | 659 | pr_debug("last reference is dropped\n"); |
757 | complete(&policy->kobj_unregister); | 660 | complete(&policy->kobj_unregister); |
758 | } | 661 | } |
759 | 662 | ||
@@ -788,7 +691,7 @@ static int cpufreq_add_dev_policy(unsigned int cpu, | |||
788 | gov = __find_governor(per_cpu(cpufreq_cpu_governor, cpu)); | 691 | gov = __find_governor(per_cpu(cpufreq_cpu_governor, cpu)); |
789 | if (gov) { | 692 | if (gov) { |
790 | policy->governor = gov; | 693 | policy->governor = gov; |
791 | dprintk("Restoring governor %s for cpu %d\n", | 694 | pr_debug("Restoring governor %s for cpu %d\n", |
792 | policy->governor->name, cpu); | 695 | policy->governor->name, cpu); |
793 | } | 696 | } |
794 | #endif | 697 | #endif |
@@ -824,7 +727,7 @@ static int cpufreq_add_dev_policy(unsigned int cpu, | |||
824 | per_cpu(cpufreq_cpu_data, cpu) = managed_policy; | 727 | per_cpu(cpufreq_cpu_data, cpu) = managed_policy; |
825 | spin_unlock_irqrestore(&cpufreq_driver_lock, flags); | 728 | spin_unlock_irqrestore(&cpufreq_driver_lock, flags); |
826 | 729 | ||
827 | dprintk("CPU already managed, adding link\n"); | 730 | pr_debug("CPU already managed, adding link\n"); |
828 | ret = sysfs_create_link(&sys_dev->kobj, | 731 | ret = sysfs_create_link(&sys_dev->kobj, |
829 | &managed_policy->kobj, | 732 | &managed_policy->kobj, |
830 | "cpufreq"); | 733 | "cpufreq"); |
@@ -865,7 +768,7 @@ static int cpufreq_add_dev_symlink(unsigned int cpu, | |||
865 | if (!cpu_online(j)) | 768 | if (!cpu_online(j)) |
866 | continue; | 769 | continue; |
867 | 770 | ||
868 | dprintk("CPU %u already managed, adding link\n", j); | 771 | pr_debug("CPU %u already managed, adding link\n", j); |
869 | managed_policy = cpufreq_cpu_get(cpu); | 772 | managed_policy = cpufreq_cpu_get(cpu); |
870 | cpu_sys_dev = get_cpu_sysdev(j); | 773 | cpu_sys_dev = get_cpu_sysdev(j); |
871 | ret = sysfs_create_link(&cpu_sys_dev->kobj, &policy->kobj, | 774 | ret = sysfs_create_link(&cpu_sys_dev->kobj, &policy->kobj, |
@@ -941,7 +844,7 @@ static int cpufreq_add_dev_interface(unsigned int cpu, | |||
941 | policy->user_policy.governor = policy->governor; | 844 | policy->user_policy.governor = policy->governor; |
942 | 845 | ||
943 | if (ret) { | 846 | if (ret) { |
944 | dprintk("setting policy failed\n"); | 847 | pr_debug("setting policy failed\n"); |
945 | if (cpufreq_driver->exit) | 848 | if (cpufreq_driver->exit) |
946 | cpufreq_driver->exit(policy); | 849 | cpufreq_driver->exit(policy); |
947 | } | 850 | } |
@@ -977,8 +880,7 @@ static int cpufreq_add_dev(struct sys_device *sys_dev) | |||
977 | if (cpu_is_offline(cpu)) | 880 | if (cpu_is_offline(cpu)) |
978 | return 0; | 881 | return 0; |
979 | 882 | ||
980 | cpufreq_debug_disable_ratelimit(); | 883 | pr_debug("adding CPU %u\n", cpu); |
981 | dprintk("adding CPU %u\n", cpu); | ||
982 | 884 | ||
983 | #ifdef CONFIG_SMP | 885 | #ifdef CONFIG_SMP |
984 | /* check whether a different CPU already registered this | 886 | /* check whether a different CPU already registered this |
@@ -986,7 +888,6 @@ static int cpufreq_add_dev(struct sys_device *sys_dev) | |||
986 | policy = cpufreq_cpu_get(cpu); | 888 | policy = cpufreq_cpu_get(cpu); |
987 | if (unlikely(policy)) { | 889 | if (unlikely(policy)) { |
988 | cpufreq_cpu_put(policy); | 890 | cpufreq_cpu_put(policy); |
989 | cpufreq_debug_enable_ratelimit(); | ||
990 | return 0; | 891 | return 0; |
991 | } | 892 | } |
992 | #endif | 893 | #endif |
@@ -1037,7 +938,7 @@ static int cpufreq_add_dev(struct sys_device *sys_dev) | |||
1037 | */ | 938 | */ |
1038 | ret = cpufreq_driver->init(policy); | 939 | ret = cpufreq_driver->init(policy); |
1039 | if (ret) { | 940 | if (ret) { |
1040 | dprintk("initialization failed\n"); | 941 | pr_debug("initialization failed\n"); |
1041 | goto err_unlock_policy; | 942 | goto err_unlock_policy; |
1042 | } | 943 | } |
1043 | policy->user_policy.min = policy->min; | 944 | policy->user_policy.min = policy->min; |
@@ -1063,8 +964,7 @@ static int cpufreq_add_dev(struct sys_device *sys_dev) | |||
1063 | 964 | ||
1064 | kobject_uevent(&policy->kobj, KOBJ_ADD); | 965 | kobject_uevent(&policy->kobj, KOBJ_ADD); |
1065 | module_put(cpufreq_driver->owner); | 966 | module_put(cpufreq_driver->owner); |
1066 | dprintk("initialization complete\n"); | 967 | pr_debug("initialization complete\n"); |
1067 | cpufreq_debug_enable_ratelimit(); | ||
1068 | 968 | ||
1069 | return 0; | 969 | return 0; |
1070 | 970 | ||
@@ -1088,7 +988,6 @@ err_free_policy: | |||
1088 | nomem_out: | 988 | nomem_out: |
1089 | module_put(cpufreq_driver->owner); | 989 | module_put(cpufreq_driver->owner); |
1090 | module_out: | 990 | module_out: |
1091 | cpufreq_debug_enable_ratelimit(); | ||
1092 | return ret; | 991 | return ret; |
1093 | } | 992 | } |
1094 | 993 | ||
@@ -1112,15 +1011,13 @@ static int __cpufreq_remove_dev(struct sys_device *sys_dev) | |||
1112 | unsigned int j; | 1011 | unsigned int j; |
1113 | #endif | 1012 | #endif |
1114 | 1013 | ||
1115 | cpufreq_debug_disable_ratelimit(); | 1014 | pr_debug("unregistering CPU %u\n", cpu); |
1116 | dprintk("unregistering CPU %u\n", cpu); | ||
1117 | 1015 | ||
1118 | spin_lock_irqsave(&cpufreq_driver_lock, flags); | 1016 | spin_lock_irqsave(&cpufreq_driver_lock, flags); |
1119 | data = per_cpu(cpufreq_cpu_data, cpu); | 1017 | data = per_cpu(cpufreq_cpu_data, cpu); |
1120 | 1018 | ||
1121 | if (!data) { | 1019 | if (!data) { |
1122 | spin_unlock_irqrestore(&cpufreq_driver_lock, flags); | 1020 | spin_unlock_irqrestore(&cpufreq_driver_lock, flags); |
1123 | cpufreq_debug_enable_ratelimit(); | ||
1124 | unlock_policy_rwsem_write(cpu); | 1021 | unlock_policy_rwsem_write(cpu); |
1125 | return -EINVAL; | 1022 | return -EINVAL; |
1126 | } | 1023 | } |
@@ -1132,12 +1029,11 @@ static int __cpufreq_remove_dev(struct sys_device *sys_dev) | |||
1132 | * only need to unlink, put and exit | 1029 | * only need to unlink, put and exit |
1133 | */ | 1030 | */ |
1134 | if (unlikely(cpu != data->cpu)) { | 1031 | if (unlikely(cpu != data->cpu)) { |
1135 | dprintk("removing link\n"); | 1032 | pr_debug("removing link\n"); |
1136 | cpumask_clear_cpu(cpu, data->cpus); | 1033 | cpumask_clear_cpu(cpu, data->cpus); |
1137 | spin_unlock_irqrestore(&cpufreq_driver_lock, flags); | 1034 | spin_unlock_irqrestore(&cpufreq_driver_lock, flags); |
1138 | kobj = &sys_dev->kobj; | 1035 | kobj = &sys_dev->kobj; |
1139 | cpufreq_cpu_put(data); | 1036 | cpufreq_cpu_put(data); |
1140 | cpufreq_debug_enable_ratelimit(); | ||
1141 | unlock_policy_rwsem_write(cpu); | 1037 | unlock_policy_rwsem_write(cpu); |
1142 | sysfs_remove_link(kobj, "cpufreq"); | 1038 | sysfs_remove_link(kobj, "cpufreq"); |
1143 | return 0; | 1039 | return 0; |
@@ -1170,7 +1066,7 @@ static int __cpufreq_remove_dev(struct sys_device *sys_dev) | |||
1170 | for_each_cpu(j, data->cpus) { | 1066 | for_each_cpu(j, data->cpus) { |
1171 | if (j == cpu) | 1067 | if (j == cpu) |
1172 | continue; | 1068 | continue; |
1173 | dprintk("removing link for cpu %u\n", j); | 1069 | pr_debug("removing link for cpu %u\n", j); |
1174 | #ifdef CONFIG_HOTPLUG_CPU | 1070 | #ifdef CONFIG_HOTPLUG_CPU |
1175 | strncpy(per_cpu(cpufreq_cpu_governor, j), | 1071 | strncpy(per_cpu(cpufreq_cpu_governor, j), |
1176 | data->governor->name, CPUFREQ_NAME_LEN); | 1072 | data->governor->name, CPUFREQ_NAME_LEN); |
@@ -1199,21 +1095,35 @@ static int __cpufreq_remove_dev(struct sys_device *sys_dev) | |||
1199 | * not referenced anymore by anybody before we proceed with | 1095 | * not referenced anymore by anybody before we proceed with |
1200 | * unloading. | 1096 | * unloading. |
1201 | */ | 1097 | */ |
1202 | dprintk("waiting for dropping of refcount\n"); | 1098 | pr_debug("waiting for dropping of refcount\n"); |
1203 | wait_for_completion(cmp); | 1099 | wait_for_completion(cmp); |
1204 | dprintk("wait complete\n"); | 1100 | pr_debug("wait complete\n"); |
1205 | 1101 | ||
1206 | lock_policy_rwsem_write(cpu); | 1102 | lock_policy_rwsem_write(cpu); |
1207 | if (cpufreq_driver->exit) | 1103 | if (cpufreq_driver->exit) |
1208 | cpufreq_driver->exit(data); | 1104 | cpufreq_driver->exit(data); |
1209 | unlock_policy_rwsem_write(cpu); | 1105 | unlock_policy_rwsem_write(cpu); |
1210 | 1106 | ||
1107 | #ifdef CONFIG_HOTPLUG_CPU | ||
1108 | /* when the CPU which is the parent of the kobj is hotplugged | ||
1109 | * offline, check for siblings, and create cpufreq sysfs interface | ||
1110 | * and symlinks | ||
1111 | */ | ||
1112 | if (unlikely(cpumask_weight(data->cpus) > 1)) { | ||
1113 | /* first sibling now owns the new sysfs dir */ | ||
1114 | cpumask_clear_cpu(cpu, data->cpus); | ||
1115 | cpufreq_add_dev(get_cpu_sysdev(cpumask_first(data->cpus))); | ||
1116 | |||
1117 | /* finally remove our own symlink */ | ||
1118 | lock_policy_rwsem_write(cpu); | ||
1119 | __cpufreq_remove_dev(sys_dev); | ||
1120 | } | ||
1121 | #endif | ||
1122 | |||
1211 | free_cpumask_var(data->related_cpus); | 1123 | free_cpumask_var(data->related_cpus); |
1212 | free_cpumask_var(data->cpus); | 1124 | free_cpumask_var(data->cpus); |
1213 | kfree(data); | 1125 | kfree(data); |
1214 | per_cpu(cpufreq_cpu_data, cpu) = NULL; | ||
1215 | 1126 | ||
1216 | cpufreq_debug_enable_ratelimit(); | ||
1217 | return 0; | 1127 | return 0; |
1218 | } | 1128 | } |
1219 | 1129 | ||
@@ -1239,7 +1149,7 @@ static void handle_update(struct work_struct *work) | |||
1239 | struct cpufreq_policy *policy = | 1149 | struct cpufreq_policy *policy = |
1240 | container_of(work, struct cpufreq_policy, update); | 1150 | container_of(work, struct cpufreq_policy, update); |
1241 | unsigned int cpu = policy->cpu; | 1151 | unsigned int cpu = policy->cpu; |
1242 | dprintk("handle_update for cpu %u called\n", cpu); | 1152 | pr_debug("handle_update for cpu %u called\n", cpu); |
1243 | cpufreq_update_policy(cpu); | 1153 | cpufreq_update_policy(cpu); |
1244 | } | 1154 | } |
1245 | 1155 | ||
@@ -1257,7 +1167,7 @@ static void cpufreq_out_of_sync(unsigned int cpu, unsigned int old_freq, | |||
1257 | { | 1167 | { |
1258 | struct cpufreq_freqs freqs; | 1168 | struct cpufreq_freqs freqs; |
1259 | 1169 | ||
1260 | dprintk("Warning: CPU frequency out of sync: cpufreq and timing " | 1170 | pr_debug("Warning: CPU frequency out of sync: cpufreq and timing " |
1261 | "core thinks of %u, is %u kHz.\n", old_freq, new_freq); | 1171 | "core thinks of %u, is %u kHz.\n", old_freq, new_freq); |
1262 | 1172 | ||
1263 | freqs.cpu = cpu; | 1173 | freqs.cpu = cpu; |
@@ -1360,7 +1270,7 @@ static int cpufreq_bp_suspend(void) | |||
1360 | int cpu = smp_processor_id(); | 1270 | int cpu = smp_processor_id(); |
1361 | struct cpufreq_policy *cpu_policy; | 1271 | struct cpufreq_policy *cpu_policy; |
1362 | 1272 | ||
1363 | dprintk("suspending cpu %u\n", cpu); | 1273 | pr_debug("suspending cpu %u\n", cpu); |
1364 | 1274 | ||
1365 | /* If there's no policy for the boot CPU, we have nothing to do. */ | 1275 | /* If there's no policy for the boot CPU, we have nothing to do. */ |
1366 | cpu_policy = cpufreq_cpu_get(cpu); | 1276 | cpu_policy = cpufreq_cpu_get(cpu); |
@@ -1398,7 +1308,7 @@ static void cpufreq_bp_resume(void) | |||
1398 | int cpu = smp_processor_id(); | 1308 | int cpu = smp_processor_id(); |
1399 | struct cpufreq_policy *cpu_policy; | 1309 | struct cpufreq_policy *cpu_policy; |
1400 | 1310 | ||
1401 | dprintk("resuming cpu %u\n", cpu); | 1311 | pr_debug("resuming cpu %u\n", cpu); |
1402 | 1312 | ||
1403 | /* If there's no policy for the boot CPU, we have nothing to do. */ | 1313 | /* If there's no policy for the boot CPU, we have nothing to do. */ |
1404 | cpu_policy = cpufreq_cpu_get(cpu); | 1314 | cpu_policy = cpufreq_cpu_get(cpu); |
@@ -1510,7 +1420,7 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy, | |||
1510 | { | 1420 | { |
1511 | int retval = -EINVAL; | 1421 | int retval = -EINVAL; |
1512 | 1422 | ||
1513 | dprintk("target for CPU %u: %u kHz, relation %u\n", policy->cpu, | 1423 | pr_debug("target for CPU %u: %u kHz, relation %u\n", policy->cpu, |
1514 | target_freq, relation); | 1424 | target_freq, relation); |
1515 | if (cpu_online(policy->cpu) && cpufreq_driver->target) | 1425 | if (cpu_online(policy->cpu) && cpufreq_driver->target) |
1516 | retval = cpufreq_driver->target(policy, target_freq, relation); | 1426 | retval = cpufreq_driver->target(policy, target_freq, relation); |
@@ -1596,7 +1506,7 @@ static int __cpufreq_governor(struct cpufreq_policy *policy, | |||
1596 | if (!try_module_get(policy->governor->owner)) | 1506 | if (!try_module_get(policy->governor->owner)) |
1597 | return -EINVAL; | 1507 | return -EINVAL; |
1598 | 1508 | ||
1599 | dprintk("__cpufreq_governor for CPU %u, event %u\n", | 1509 | pr_debug("__cpufreq_governor for CPU %u, event %u\n", |
1600 | policy->cpu, event); | 1510 | policy->cpu, event); |
1601 | ret = policy->governor->governor(policy, event); | 1511 | ret = policy->governor->governor(policy, event); |
1602 | 1512 | ||
@@ -1697,8 +1607,7 @@ static int __cpufreq_set_policy(struct cpufreq_policy *data, | |||
1697 | { | 1607 | { |
1698 | int ret = 0; | 1608 | int ret = 0; |
1699 | 1609 | ||
1700 | cpufreq_debug_disable_ratelimit(); | 1610 | pr_debug("setting new policy for CPU %u: %u - %u kHz\n", policy->cpu, |
1701 | dprintk("setting new policy for CPU %u: %u - %u kHz\n", policy->cpu, | ||
1702 | policy->min, policy->max); | 1611 | policy->min, policy->max); |
1703 | 1612 | ||
1704 | memcpy(&policy->cpuinfo, &data->cpuinfo, | 1613 | memcpy(&policy->cpuinfo, &data->cpuinfo, |
@@ -1735,19 +1644,19 @@ static int __cpufreq_set_policy(struct cpufreq_policy *data, | |||
1735 | data->min = policy->min; | 1644 | data->min = policy->min; |
1736 | data->max = policy->max; | 1645 | data->max = policy->max; |
1737 | 1646 | ||
1738 | dprintk("new min and max freqs are %u - %u kHz\n", | 1647 | pr_debug("new min and max freqs are %u - %u kHz\n", |
1739 | data->min, data->max); | 1648 | data->min, data->max); |
1740 | 1649 | ||
1741 | if (cpufreq_driver->setpolicy) { | 1650 | if (cpufreq_driver->setpolicy) { |
1742 | data->policy = policy->policy; | 1651 | data->policy = policy->policy; |
1743 | dprintk("setting range\n"); | 1652 | pr_debug("setting range\n"); |
1744 | ret = cpufreq_driver->setpolicy(policy); | 1653 | ret = cpufreq_driver->setpolicy(policy); |
1745 | } else { | 1654 | } else { |
1746 | if (policy->governor != data->governor) { | 1655 | if (policy->governor != data->governor) { |
1747 | /* save old, working values */ | 1656 | /* save old, working values */ |
1748 | struct cpufreq_governor *old_gov = data->governor; | 1657 | struct cpufreq_governor *old_gov = data->governor; |
1749 | 1658 | ||
1750 | dprintk("governor switch\n"); | 1659 | pr_debug("governor switch\n"); |
1751 | 1660 | ||
1752 | /* end old governor */ | 1661 | /* end old governor */ |
1753 | if (data->governor) | 1662 | if (data->governor) |
@@ -1757,7 +1666,7 @@ static int __cpufreq_set_policy(struct cpufreq_policy *data, | |||
1757 | data->governor = policy->governor; | 1666 | data->governor = policy->governor; |
1758 | if (__cpufreq_governor(data, CPUFREQ_GOV_START)) { | 1667 | if (__cpufreq_governor(data, CPUFREQ_GOV_START)) { |
1759 | /* new governor failed, so re-start old one */ | 1668 | /* new governor failed, so re-start old one */ |
1760 | dprintk("starting governor %s failed\n", | 1669 | pr_debug("starting governor %s failed\n", |
1761 | data->governor->name); | 1670 | data->governor->name); |
1762 | if (old_gov) { | 1671 | if (old_gov) { |
1763 | data->governor = old_gov; | 1672 | data->governor = old_gov; |
@@ -1769,12 +1678,11 @@ static int __cpufreq_set_policy(struct cpufreq_policy *data, | |||
1769 | } | 1678 | } |
1770 | /* might be a policy change, too, so fall through */ | 1679 | /* might be a policy change, too, so fall through */ |
1771 | } | 1680 | } |
1772 | dprintk("governor: change or update limits\n"); | 1681 | pr_debug("governor: change or update limits\n"); |
1773 | __cpufreq_governor(data, CPUFREQ_GOV_LIMITS); | 1682 | __cpufreq_governor(data, CPUFREQ_GOV_LIMITS); |
1774 | } | 1683 | } |
1775 | 1684 | ||
1776 | error_out: | 1685 | error_out: |
1777 | cpufreq_debug_enable_ratelimit(); | ||
1778 | return ret; | 1686 | return ret; |
1779 | } | 1687 | } |
1780 | 1688 | ||
@@ -1801,7 +1709,7 @@ int cpufreq_update_policy(unsigned int cpu) | |||
1801 | goto fail; | 1709 | goto fail; |
1802 | } | 1710 | } |
1803 | 1711 | ||
1804 | dprintk("updating policy for CPU %u\n", cpu); | 1712 | pr_debug("updating policy for CPU %u\n", cpu); |
1805 | memcpy(&policy, data, sizeof(struct cpufreq_policy)); | 1713 | memcpy(&policy, data, sizeof(struct cpufreq_policy)); |
1806 | policy.min = data->user_policy.min; | 1714 | policy.min = data->user_policy.min; |
1807 | policy.max = data->user_policy.max; | 1715 | policy.max = data->user_policy.max; |
@@ -1813,7 +1721,7 @@ int cpufreq_update_policy(unsigned int cpu) | |||
1813 | if (cpufreq_driver->get) { | 1721 | if (cpufreq_driver->get) { |
1814 | policy.cur = cpufreq_driver->get(cpu); | 1722 | policy.cur = cpufreq_driver->get(cpu); |
1815 | if (!data->cur) { | 1723 | if (!data->cur) { |
1816 | dprintk("Driver did not initialize current freq"); | 1724 | pr_debug("Driver did not initialize current freq"); |
1817 | data->cur = policy.cur; | 1725 | data->cur = policy.cur; |
1818 | } else { | 1726 | } else { |
1819 | if (data->cur != policy.cur) | 1727 | if (data->cur != policy.cur) |
@@ -1889,7 +1797,7 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data) | |||
1889 | ((!driver_data->setpolicy) && (!driver_data->target))) | 1797 | ((!driver_data->setpolicy) && (!driver_data->target))) |
1890 | return -EINVAL; | 1798 | return -EINVAL; |
1891 | 1799 | ||
1892 | dprintk("trying to register driver %s\n", driver_data->name); | 1800 | pr_debug("trying to register driver %s\n", driver_data->name); |
1893 | 1801 | ||
1894 | if (driver_data->setpolicy) | 1802 | if (driver_data->setpolicy) |
1895 | driver_data->flags |= CPUFREQ_CONST_LOOPS; | 1803 | driver_data->flags |= CPUFREQ_CONST_LOOPS; |
@@ -1920,15 +1828,14 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data) | |||
1920 | 1828 | ||
1921 | /* if all ->init() calls failed, unregister */ | 1829 | /* if all ->init() calls failed, unregister */ |
1922 | if (ret) { | 1830 | if (ret) { |
1923 | dprintk("no CPU initialized for driver %s\n", | 1831 | pr_debug("no CPU initialized for driver %s\n", |
1924 | driver_data->name); | 1832 | driver_data->name); |
1925 | goto err_sysdev_unreg; | 1833 | goto err_sysdev_unreg; |
1926 | } | 1834 | } |
1927 | } | 1835 | } |
1928 | 1836 | ||
1929 | register_hotcpu_notifier(&cpufreq_cpu_notifier); | 1837 | register_hotcpu_notifier(&cpufreq_cpu_notifier); |
1930 | dprintk("driver %s up and running\n", driver_data->name); | 1838 | pr_debug("driver %s up and running\n", driver_data->name); |
1931 | cpufreq_debug_enable_ratelimit(); | ||
1932 | 1839 | ||
1933 | return 0; | 1840 | return 0; |
1934 | err_sysdev_unreg: | 1841 | err_sysdev_unreg: |
@@ -1955,14 +1862,10 @@ int cpufreq_unregister_driver(struct cpufreq_driver *driver) | |||
1955 | { | 1862 | { |
1956 | unsigned long flags; | 1863 | unsigned long flags; |
1957 | 1864 | ||
1958 | cpufreq_debug_disable_ratelimit(); | 1865 | if (!cpufreq_driver || (driver != cpufreq_driver)) |
1959 | |||
1960 | if (!cpufreq_driver || (driver != cpufreq_driver)) { | ||
1961 | cpufreq_debug_enable_ratelimit(); | ||
1962 | return -EINVAL; | 1866 | return -EINVAL; |
1963 | } | ||
1964 | 1867 | ||
1965 | dprintk("unregistering driver %s\n", driver->name); | 1868 | pr_debug("unregistering driver %s\n", driver->name); |
1966 | 1869 | ||
1967 | sysdev_driver_unregister(&cpu_sysdev_class, &cpufreq_sysdev_driver); | 1870 | sysdev_driver_unregister(&cpu_sysdev_class, &cpufreq_sysdev_driver); |
1968 | unregister_hotcpu_notifier(&cpufreq_cpu_notifier); | 1871 | unregister_hotcpu_notifier(&cpufreq_cpu_notifier); |
diff --git a/drivers/cpufreq/cpufreq_performance.c b/drivers/cpufreq/cpufreq_performance.c index 7e2e515087f8..f13a8a9af6a1 100644 --- a/drivers/cpufreq/cpufreq_performance.c +++ b/drivers/cpufreq/cpufreq_performance.c | |||
@@ -15,9 +15,6 @@ | |||
15 | #include <linux/cpufreq.h> | 15 | #include <linux/cpufreq.h> |
16 | #include <linux/init.h> | 16 | #include <linux/init.h> |
17 | 17 | ||
18 | #define dprintk(msg...) \ | ||
19 | cpufreq_debug_printk(CPUFREQ_DEBUG_GOVERNOR, "performance", msg) | ||
20 | |||
21 | 18 | ||
22 | static int cpufreq_governor_performance(struct cpufreq_policy *policy, | 19 | static int cpufreq_governor_performance(struct cpufreq_policy *policy, |
23 | unsigned int event) | 20 | unsigned int event) |
@@ -25,7 +22,7 @@ static int cpufreq_governor_performance(struct cpufreq_policy *policy, | |||
25 | switch (event) { | 22 | switch (event) { |
26 | case CPUFREQ_GOV_START: | 23 | case CPUFREQ_GOV_START: |
27 | case CPUFREQ_GOV_LIMITS: | 24 | case CPUFREQ_GOV_LIMITS: |
28 | dprintk("setting to %u kHz because of event %u\n", | 25 | pr_debug("setting to %u kHz because of event %u\n", |
29 | policy->max, event); | 26 | policy->max, event); |
30 | __cpufreq_driver_target(policy, policy->max, | 27 | __cpufreq_driver_target(policy, policy->max, |
31 | CPUFREQ_RELATION_H); | 28 | CPUFREQ_RELATION_H); |
diff --git a/drivers/cpufreq/cpufreq_powersave.c b/drivers/cpufreq/cpufreq_powersave.c index e6db5faf3eb1..4c2eb512f2bc 100644 --- a/drivers/cpufreq/cpufreq_powersave.c +++ b/drivers/cpufreq/cpufreq_powersave.c | |||
@@ -15,16 +15,13 @@ | |||
15 | #include <linux/cpufreq.h> | 15 | #include <linux/cpufreq.h> |
16 | #include <linux/init.h> | 16 | #include <linux/init.h> |
17 | 17 | ||
18 | #define dprintk(msg...) \ | ||
19 | cpufreq_debug_printk(CPUFREQ_DEBUG_GOVERNOR, "powersave", msg) | ||
20 | |||
21 | static int cpufreq_governor_powersave(struct cpufreq_policy *policy, | 18 | static int cpufreq_governor_powersave(struct cpufreq_policy *policy, |
22 | unsigned int event) | 19 | unsigned int event) |
23 | { | 20 | { |
24 | switch (event) { | 21 | switch (event) { |
25 | case CPUFREQ_GOV_START: | 22 | case CPUFREQ_GOV_START: |
26 | case CPUFREQ_GOV_LIMITS: | 23 | case CPUFREQ_GOV_LIMITS: |
27 | dprintk("setting to %u kHz because of event %u\n", | 24 | pr_debug("setting to %u kHz because of event %u\n", |
28 | policy->min, event); | 25 | policy->min, event); |
29 | __cpufreq_driver_target(policy, policy->min, | 26 | __cpufreq_driver_target(policy, policy->min, |
30 | CPUFREQ_RELATION_L); | 27 | CPUFREQ_RELATION_L); |
diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c index 00d73fc8e4e2..b60a4c263686 100644 --- a/drivers/cpufreq/cpufreq_stats.c +++ b/drivers/cpufreq/cpufreq_stats.c | |||
@@ -165,17 +165,27 @@ static int freq_table_get_index(struct cpufreq_stats *stat, unsigned int freq) | |||
165 | return -1; | 165 | return -1; |
166 | } | 166 | } |
167 | 167 | ||
168 | /* should be called late in the CPU removal sequence so that the stats | ||
169 | * memory is still available in case someone tries to use it. | ||
170 | */ | ||
168 | static void cpufreq_stats_free_table(unsigned int cpu) | 171 | static void cpufreq_stats_free_table(unsigned int cpu) |
169 | { | 172 | { |
170 | struct cpufreq_stats *stat = per_cpu(cpufreq_stats_table, cpu); | 173 | struct cpufreq_stats *stat = per_cpu(cpufreq_stats_table, cpu); |
171 | struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); | ||
172 | if (policy && policy->cpu == cpu) | ||
173 | sysfs_remove_group(&policy->kobj, &stats_attr_group); | ||
174 | if (stat) { | 174 | if (stat) { |
175 | kfree(stat->time_in_state); | 175 | kfree(stat->time_in_state); |
176 | kfree(stat); | 176 | kfree(stat); |
177 | } | 177 | } |
178 | per_cpu(cpufreq_stats_table, cpu) = NULL; | 178 | per_cpu(cpufreq_stats_table, cpu) = NULL; |
179 | } | ||
180 | |||
181 | /* must be called early in the CPU removal sequence (before | ||
182 | * cpufreq_remove_dev) so that policy is still valid. | ||
183 | */ | ||
184 | static void cpufreq_stats_free_sysfs(unsigned int cpu) | ||
185 | { | ||
186 | struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); | ||
187 | if (policy && policy->cpu == cpu) | ||
188 | sysfs_remove_group(&policy->kobj, &stats_attr_group); | ||
179 | if (policy) | 189 | if (policy) |
180 | cpufreq_cpu_put(policy); | 190 | cpufreq_cpu_put(policy); |
181 | } | 191 | } |
@@ -316,6 +326,9 @@ static int __cpuinit cpufreq_stat_cpu_callback(struct notifier_block *nfb, | |||
316 | case CPU_ONLINE_FROZEN: | 326 | case CPU_ONLINE_FROZEN: |
317 | cpufreq_update_policy(cpu); | 327 | cpufreq_update_policy(cpu); |
318 | break; | 328 | break; |
329 | case CPU_DOWN_PREPARE: | ||
330 | cpufreq_stats_free_sysfs(cpu); | ||
331 | break; | ||
319 | case CPU_DEAD: | 332 | case CPU_DEAD: |
320 | case CPU_DEAD_FROZEN: | 333 | case CPU_DEAD_FROZEN: |
321 | cpufreq_stats_free_table(cpu); | 334 | cpufreq_stats_free_table(cpu); |
@@ -324,9 +337,10 @@ static int __cpuinit cpufreq_stat_cpu_callback(struct notifier_block *nfb, | |||
324 | return NOTIFY_OK; | 337 | return NOTIFY_OK; |
325 | } | 338 | } |
326 | 339 | ||
327 | static struct notifier_block cpufreq_stat_cpu_notifier __refdata = | 340 | /* priority=1 so this will get called before cpufreq_remove_dev */ |
328 | { | 341 | static struct notifier_block cpufreq_stat_cpu_notifier __refdata = { |
329 | .notifier_call = cpufreq_stat_cpu_callback, | 342 | .notifier_call = cpufreq_stat_cpu_callback, |
343 | .priority = 1, | ||
330 | }; | 344 | }; |
331 | 345 | ||
332 | static struct notifier_block notifier_policy_block = { | 346 | static struct notifier_block notifier_policy_block = { |
diff --git a/drivers/cpufreq/cpufreq_userspace.c b/drivers/cpufreq/cpufreq_userspace.c index 66d2d1d6c80f..f231015904c0 100644 --- a/drivers/cpufreq/cpufreq_userspace.c +++ b/drivers/cpufreq/cpufreq_userspace.c | |||
@@ -37,9 +37,6 @@ static DEFINE_PER_CPU(unsigned int, cpu_is_managed); | |||
37 | static DEFINE_MUTEX(userspace_mutex); | 37 | static DEFINE_MUTEX(userspace_mutex); |
38 | static int cpus_using_userspace_governor; | 38 | static int cpus_using_userspace_governor; |
39 | 39 | ||
40 | #define dprintk(msg...) \ | ||
41 | cpufreq_debug_printk(CPUFREQ_DEBUG_GOVERNOR, "userspace", msg) | ||
42 | |||
43 | /* keep track of frequency transitions */ | 40 | /* keep track of frequency transitions */ |
44 | static int | 41 | static int |
45 | userspace_cpufreq_notifier(struct notifier_block *nb, unsigned long val, | 42 | userspace_cpufreq_notifier(struct notifier_block *nb, unsigned long val, |
@@ -50,7 +47,7 @@ userspace_cpufreq_notifier(struct notifier_block *nb, unsigned long val, | |||
50 | if (!per_cpu(cpu_is_managed, freq->cpu)) | 47 | if (!per_cpu(cpu_is_managed, freq->cpu)) |
51 | return 0; | 48 | return 0; |
52 | 49 | ||
53 | dprintk("saving cpu_cur_freq of cpu %u to be %u kHz\n", | 50 | pr_debug("saving cpu_cur_freq of cpu %u to be %u kHz\n", |
54 | freq->cpu, freq->new); | 51 | freq->cpu, freq->new); |
55 | per_cpu(cpu_cur_freq, freq->cpu) = freq->new; | 52 | per_cpu(cpu_cur_freq, freq->cpu) = freq->new; |
56 | 53 | ||
@@ -73,7 +70,7 @@ static int cpufreq_set(struct cpufreq_policy *policy, unsigned int freq) | |||
73 | { | 70 | { |
74 | int ret = -EINVAL; | 71 | int ret = -EINVAL; |
75 | 72 | ||
76 | dprintk("cpufreq_set for cpu %u, freq %u kHz\n", policy->cpu, freq); | 73 | pr_debug("cpufreq_set for cpu %u, freq %u kHz\n", policy->cpu, freq); |
77 | 74 | ||
78 | mutex_lock(&userspace_mutex); | 75 | mutex_lock(&userspace_mutex); |
79 | if (!per_cpu(cpu_is_managed, policy->cpu)) | 76 | if (!per_cpu(cpu_is_managed, policy->cpu)) |
@@ -134,7 +131,7 @@ static int cpufreq_governor_userspace(struct cpufreq_policy *policy, | |||
134 | per_cpu(cpu_max_freq, cpu) = policy->max; | 131 | per_cpu(cpu_max_freq, cpu) = policy->max; |
135 | per_cpu(cpu_cur_freq, cpu) = policy->cur; | 132 | per_cpu(cpu_cur_freq, cpu) = policy->cur; |
136 | per_cpu(cpu_set_freq, cpu) = policy->cur; | 133 | per_cpu(cpu_set_freq, cpu) = policy->cur; |
137 | dprintk("managing cpu %u started " | 134 | pr_debug("managing cpu %u started " |
138 | "(%u - %u kHz, currently %u kHz)\n", | 135 | "(%u - %u kHz, currently %u kHz)\n", |
139 | cpu, | 136 | cpu, |
140 | per_cpu(cpu_min_freq, cpu), | 137 | per_cpu(cpu_min_freq, cpu), |
@@ -156,12 +153,12 @@ static int cpufreq_governor_userspace(struct cpufreq_policy *policy, | |||
156 | per_cpu(cpu_min_freq, cpu) = 0; | 153 | per_cpu(cpu_min_freq, cpu) = 0; |
157 | per_cpu(cpu_max_freq, cpu) = 0; | 154 | per_cpu(cpu_max_freq, cpu) = 0; |
158 | per_cpu(cpu_set_freq, cpu) = 0; | 155 | per_cpu(cpu_set_freq, cpu) = 0; |
159 | dprintk("managing cpu %u stopped\n", cpu); | 156 | pr_debug("managing cpu %u stopped\n", cpu); |
160 | mutex_unlock(&userspace_mutex); | 157 | mutex_unlock(&userspace_mutex); |
161 | break; | 158 | break; |
162 | case CPUFREQ_GOV_LIMITS: | 159 | case CPUFREQ_GOV_LIMITS: |
163 | mutex_lock(&userspace_mutex); | 160 | mutex_lock(&userspace_mutex); |
164 | dprintk("limit event for cpu %u: %u - %u kHz, " | 161 | pr_debug("limit event for cpu %u: %u - %u kHz, " |
165 | "currently %u kHz, last set to %u kHz\n", | 162 | "currently %u kHz, last set to %u kHz\n", |
166 | cpu, policy->min, policy->max, | 163 | cpu, policy->min, policy->max, |
167 | per_cpu(cpu_cur_freq, cpu), | 164 | per_cpu(cpu_cur_freq, cpu), |
diff --git a/drivers/cpufreq/e_powersaver.c b/drivers/cpufreq/e_powersaver.c new file mode 100644 index 000000000000..35a257dd4bb7 --- /dev/null +++ b/drivers/cpufreq/e_powersaver.c | |||
@@ -0,0 +1,367 @@ | |||
1 | /* | ||
2 | * Based on documentation provided by Dave Jones. Thanks! | ||
3 | * | ||
4 | * Licensed under the terms of the GNU GPL License version 2. | ||
5 | * | ||
6 | * BIG FAT DISCLAIMER: Work in progress code. Possibly *dangerous* | ||
7 | */ | ||
8 | |||
9 | #include <linux/kernel.h> | ||
10 | #include <linux/module.h> | ||
11 | #include <linux/init.h> | ||
12 | #include <linux/cpufreq.h> | ||
13 | #include <linux/ioport.h> | ||
14 | #include <linux/slab.h> | ||
15 | #include <linux/timex.h> | ||
16 | #include <linux/io.h> | ||
17 | #include <linux/delay.h> | ||
18 | |||
19 | #include <asm/msr.h> | ||
20 | #include <asm/tsc.h> | ||
21 | |||
22 | #define EPS_BRAND_C7M 0 | ||
23 | #define EPS_BRAND_C7 1 | ||
24 | #define EPS_BRAND_EDEN 2 | ||
25 | #define EPS_BRAND_C3 3 | ||
26 | #define EPS_BRAND_C7D 4 | ||
27 | |||
28 | struct eps_cpu_data { | ||
29 | u32 fsb; | ||
30 | struct cpufreq_frequency_table freq_table[]; | ||
31 | }; | ||
32 | |||
33 | static struct eps_cpu_data *eps_cpu[NR_CPUS]; | ||
34 | |||
35 | |||
36 | static unsigned int eps_get(unsigned int cpu) | ||
37 | { | ||
38 | struct eps_cpu_data *centaur; | ||
39 | u32 lo, hi; | ||
40 | |||
41 | if (cpu) | ||
42 | return 0; | ||
43 | centaur = eps_cpu[cpu]; | ||
44 | if (centaur == NULL) | ||
45 | return 0; | ||
46 | |||
47 | /* Return current frequency */ | ||
48 | rdmsr(MSR_IA32_PERF_STATUS, lo, hi); | ||
49 | return centaur->fsb * ((lo >> 8) & 0xff); | ||
50 | } | ||
51 | |||
52 | static int eps_set_state(struct eps_cpu_data *centaur, | ||
53 | unsigned int cpu, | ||
54 | u32 dest_state) | ||
55 | { | ||
56 | struct cpufreq_freqs freqs; | ||
57 | u32 lo, hi; | ||
58 | int err = 0; | ||
59 | int i; | ||
60 | |||
61 | freqs.old = eps_get(cpu); | ||
62 | freqs.new = centaur->fsb * ((dest_state >> 8) & 0xff); | ||
63 | freqs.cpu = cpu; | ||
64 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
65 | |||
66 | /* Wait while CPU is busy */ | ||
67 | rdmsr(MSR_IA32_PERF_STATUS, lo, hi); | ||
68 | i = 0; | ||
69 | while (lo & ((1 << 16) | (1 << 17))) { | ||
70 | udelay(16); | ||
71 | rdmsr(MSR_IA32_PERF_STATUS, lo, hi); | ||
72 | i++; | ||
73 | if (unlikely(i > 64)) { | ||
74 | err = -ENODEV; | ||
75 | goto postchange; | ||
76 | } | ||
77 | } | ||
78 | /* Set new multiplier and voltage */ | ||
79 | wrmsr(MSR_IA32_PERF_CTL, dest_state & 0xffff, 0); | ||
80 | /* Wait until transition end */ | ||
81 | i = 0; | ||
82 | do { | ||
83 | udelay(16); | ||
84 | rdmsr(MSR_IA32_PERF_STATUS, lo, hi); | ||
85 | i++; | ||
86 | if (unlikely(i > 64)) { | ||
87 | err = -ENODEV; | ||
88 | goto postchange; | ||
89 | } | ||
90 | } while (lo & ((1 << 16) | (1 << 17))); | ||
91 | |||
92 | /* Return current frequency */ | ||
93 | postchange: | ||
94 | rdmsr(MSR_IA32_PERF_STATUS, lo, hi); | ||
95 | freqs.new = centaur->fsb * ((lo >> 8) & 0xff); | ||
96 | |||
97 | #ifdef DEBUG | ||
98 | { | ||
99 | u8 current_multiplier, current_voltage; | ||
100 | |||
101 | /* Print voltage and multiplier */ | ||
102 | rdmsr(MSR_IA32_PERF_STATUS, lo, hi); | ||
103 | current_voltage = lo & 0xff; | ||
104 | printk(KERN_INFO "eps: Current voltage = %dmV\n", | ||
105 | current_voltage * 16 + 700); | ||
106 | current_multiplier = (lo >> 8) & 0xff; | ||
107 | printk(KERN_INFO "eps: Current multiplier = %d\n", | ||
108 | current_multiplier); | ||
109 | } | ||
110 | #endif | ||
111 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
112 | return err; | ||
113 | } | ||
114 | |||
115 | static int eps_target(struct cpufreq_policy *policy, | ||
116 | unsigned int target_freq, | ||
117 | unsigned int relation) | ||
118 | { | ||
119 | struct eps_cpu_data *centaur; | ||
120 | unsigned int newstate = 0; | ||
121 | unsigned int cpu = policy->cpu; | ||
122 | unsigned int dest_state; | ||
123 | int ret; | ||
124 | |||
125 | if (unlikely(eps_cpu[cpu] == NULL)) | ||
126 | return -ENODEV; | ||
127 | centaur = eps_cpu[cpu]; | ||
128 | |||
129 | if (unlikely(cpufreq_frequency_table_target(policy, | ||
130 | &eps_cpu[cpu]->freq_table[0], | ||
131 | target_freq, | ||
132 | relation, | ||
133 | &newstate))) { | ||
134 | return -EINVAL; | ||
135 | } | ||
136 | |||
137 | /* Make frequency transition */ | ||
138 | dest_state = centaur->freq_table[newstate].index & 0xffff; | ||
139 | ret = eps_set_state(centaur, cpu, dest_state); | ||
140 | if (ret) | ||
141 | printk(KERN_ERR "eps: Timeout!\n"); | ||
142 | return ret; | ||
143 | } | ||
144 | |||
145 | static int eps_verify(struct cpufreq_policy *policy) | ||
146 | { | ||
147 | return cpufreq_frequency_table_verify(policy, | ||
148 | &eps_cpu[policy->cpu]->freq_table[0]); | ||
149 | } | ||
150 | |||
151 | static int eps_cpu_init(struct cpufreq_policy *policy) | ||
152 | { | ||
153 | unsigned int i; | ||
154 | u32 lo, hi; | ||
155 | u64 val; | ||
156 | u8 current_multiplier, current_voltage; | ||
157 | u8 max_multiplier, max_voltage; | ||
158 | u8 min_multiplier, min_voltage; | ||
159 | u8 brand = 0; | ||
160 | u32 fsb; | ||
161 | struct eps_cpu_data *centaur; | ||
162 | struct cpuinfo_x86 *c = &cpu_data(0); | ||
163 | struct cpufreq_frequency_table *f_table; | ||
164 | int k, step, voltage; | ||
165 | int ret; | ||
166 | int states; | ||
167 | |||
168 | if (policy->cpu != 0) | ||
169 | return -ENODEV; | ||
170 | |||
171 | /* Check brand */ | ||
172 | printk(KERN_INFO "eps: Detected VIA "); | ||
173 | |||
174 | switch (c->x86_model) { | ||
175 | case 10: | ||
176 | rdmsr(0x1153, lo, hi); | ||
177 | brand = (((lo >> 2) ^ lo) >> 18) & 3; | ||
178 | printk(KERN_CONT "Model A "); | ||
179 | break; | ||
180 | case 13: | ||
181 | rdmsr(0x1154, lo, hi); | ||
182 | brand = (((lo >> 4) ^ (lo >> 2))) & 0x000000ff; | ||
183 | printk(KERN_CONT "Model D "); | ||
184 | break; | ||
185 | } | ||
186 | |||
187 | switch (brand) { | ||
188 | case EPS_BRAND_C7M: | ||
189 | printk(KERN_CONT "C7-M\n"); | ||
190 | break; | ||
191 | case EPS_BRAND_C7: | ||
192 | printk(KERN_CONT "C7\n"); | ||
193 | break; | ||
194 | case EPS_BRAND_EDEN: | ||
195 | printk(KERN_CONT "Eden\n"); | ||
196 | break; | ||
197 | case EPS_BRAND_C7D: | ||
198 | printk(KERN_CONT "C7-D\n"); | ||
199 | break; | ||
200 | case EPS_BRAND_C3: | ||
201 | printk(KERN_CONT "C3\n"); | ||
202 | return -ENODEV; | ||
203 | break; | ||
204 | } | ||
205 | /* Enable Enhanced PowerSaver */ | ||
206 | rdmsrl(MSR_IA32_MISC_ENABLE, val); | ||
207 | if (!(val & MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP)) { | ||
208 | val |= MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP; | ||
209 | wrmsrl(MSR_IA32_MISC_ENABLE, val); | ||
210 | /* Can be locked at 0 */ | ||
211 | rdmsrl(MSR_IA32_MISC_ENABLE, val); | ||
212 | if (!(val & MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP)) { | ||
213 | printk(KERN_INFO "eps: Can't enable Enhanced PowerSaver\n"); | ||
214 | return -ENODEV; | ||
215 | } | ||
216 | } | ||
217 | |||
218 | /* Print voltage and multiplier */ | ||
219 | rdmsr(MSR_IA32_PERF_STATUS, lo, hi); | ||
220 | current_voltage = lo & 0xff; | ||
221 | printk(KERN_INFO "eps: Current voltage = %dmV\n", | ||
222 | current_voltage * 16 + 700); | ||
223 | current_multiplier = (lo >> 8) & 0xff; | ||
224 | printk(KERN_INFO "eps: Current multiplier = %d\n", current_multiplier); | ||
225 | |||
226 | /* Print limits */ | ||
227 | max_voltage = hi & 0xff; | ||
228 | printk(KERN_INFO "eps: Highest voltage = %dmV\n", | ||
229 | max_voltage * 16 + 700); | ||
230 | max_multiplier = (hi >> 8) & 0xff; | ||
231 | printk(KERN_INFO "eps: Highest multiplier = %d\n", max_multiplier); | ||
232 | min_voltage = (hi >> 16) & 0xff; | ||
233 | printk(KERN_INFO "eps: Lowest voltage = %dmV\n", | ||
234 | min_voltage * 16 + 700); | ||
235 | min_multiplier = (hi >> 24) & 0xff; | ||
236 | printk(KERN_INFO "eps: Lowest multiplier = %d\n", min_multiplier); | ||
237 | |||
238 | /* Sanity checks */ | ||
239 | if (current_multiplier == 0 || max_multiplier == 0 | ||
240 | || min_multiplier == 0) | ||
241 | return -EINVAL; | ||
242 | if (current_multiplier > max_multiplier | ||
243 | || max_multiplier <= min_multiplier) | ||
244 | return -EINVAL; | ||
245 | if (current_voltage > 0x1f || max_voltage > 0x1f) | ||
246 | return -EINVAL; | ||
247 | if (max_voltage < min_voltage) | ||
248 | return -EINVAL; | ||
249 | |||
250 | /* Calc FSB speed */ | ||
251 | fsb = cpu_khz / current_multiplier; | ||
252 | /* Calc number of p-states supported */ | ||
253 | if (brand == EPS_BRAND_C7M) | ||
254 | states = max_multiplier - min_multiplier + 1; | ||
255 | else | ||
256 | states = 2; | ||
257 | |||
258 | /* Allocate private data and frequency table for current cpu */ | ||
259 | centaur = kzalloc(sizeof(struct eps_cpu_data) | ||
260 | + (states + 1) * sizeof(struct cpufreq_frequency_table), | ||
261 | GFP_KERNEL); | ||
262 | if (!centaur) | ||
263 | return -ENOMEM; | ||
264 | eps_cpu[0] = centaur; | ||
265 | |||
266 | /* Copy basic values */ | ||
267 | centaur->fsb = fsb; | ||
268 | |||
269 | /* Fill frequency and MSR value table */ | ||
270 | f_table = ¢aur->freq_table[0]; | ||
271 | if (brand != EPS_BRAND_C7M) { | ||
272 | f_table[0].frequency = fsb * min_multiplier; | ||
273 | f_table[0].index = (min_multiplier << 8) | min_voltage; | ||
274 | f_table[1].frequency = fsb * max_multiplier; | ||
275 | f_table[1].index = (max_multiplier << 8) | max_voltage; | ||
276 | f_table[2].frequency = CPUFREQ_TABLE_END; | ||
277 | } else { | ||
278 | k = 0; | ||
279 | step = ((max_voltage - min_voltage) * 256) | ||
280 | / (max_multiplier - min_multiplier); | ||
281 | for (i = min_multiplier; i <= max_multiplier; i++) { | ||
282 | voltage = (k * step) / 256 + min_voltage; | ||
283 | f_table[k].frequency = fsb * i; | ||
284 | f_table[k].index = (i << 8) | voltage; | ||
285 | k++; | ||
286 | } | ||
287 | f_table[k].frequency = CPUFREQ_TABLE_END; | ||
288 | } | ||
289 | |||
290 | policy->cpuinfo.transition_latency = 140000; /* 844mV -> 700mV in ns */ | ||
291 | policy->cur = fsb * current_multiplier; | ||
292 | |||
293 | ret = cpufreq_frequency_table_cpuinfo(policy, ¢aur->freq_table[0]); | ||
294 | if (ret) { | ||
295 | kfree(centaur); | ||
296 | return ret; | ||
297 | } | ||
298 | |||
299 | cpufreq_frequency_table_get_attr(¢aur->freq_table[0], policy->cpu); | ||
300 | return 0; | ||
301 | } | ||
302 | |||
303 | static int eps_cpu_exit(struct cpufreq_policy *policy) | ||
304 | { | ||
305 | unsigned int cpu = policy->cpu; | ||
306 | struct eps_cpu_data *centaur; | ||
307 | u32 lo, hi; | ||
308 | |||
309 | if (eps_cpu[cpu] == NULL) | ||
310 | return -ENODEV; | ||
311 | centaur = eps_cpu[cpu]; | ||
312 | |||
313 | /* Get max frequency */ | ||
314 | rdmsr(MSR_IA32_PERF_STATUS, lo, hi); | ||
315 | /* Set max frequency */ | ||
316 | eps_set_state(centaur, cpu, hi & 0xffff); | ||
317 | /* Bye */ | ||
318 | cpufreq_frequency_table_put_attr(policy->cpu); | ||
319 | kfree(eps_cpu[cpu]); | ||
320 | eps_cpu[cpu] = NULL; | ||
321 | return 0; | ||
322 | } | ||
323 | |||
324 | static struct freq_attr *eps_attr[] = { | ||
325 | &cpufreq_freq_attr_scaling_available_freqs, | ||
326 | NULL, | ||
327 | }; | ||
328 | |||
329 | static struct cpufreq_driver eps_driver = { | ||
330 | .verify = eps_verify, | ||
331 | .target = eps_target, | ||
332 | .init = eps_cpu_init, | ||
333 | .exit = eps_cpu_exit, | ||
334 | .get = eps_get, | ||
335 | .name = "e_powersaver", | ||
336 | .owner = THIS_MODULE, | ||
337 | .attr = eps_attr, | ||
338 | }; | ||
339 | |||
340 | static int __init eps_init(void) | ||
341 | { | ||
342 | struct cpuinfo_x86 *c = &cpu_data(0); | ||
343 | |||
344 | /* This driver will work only on Centaur C7 processors with | ||
345 | * Enhanced SpeedStep/PowerSaver registers */ | ||
346 | if (c->x86_vendor != X86_VENDOR_CENTAUR | ||
347 | || c->x86 != 6 || c->x86_model < 10) | ||
348 | return -ENODEV; | ||
349 | if (!cpu_has(c, X86_FEATURE_EST)) | ||
350 | return -ENODEV; | ||
351 | |||
352 | if (cpufreq_register_driver(&eps_driver)) | ||
353 | return -EINVAL; | ||
354 | return 0; | ||
355 | } | ||
356 | |||
357 | static void __exit eps_exit(void) | ||
358 | { | ||
359 | cpufreq_unregister_driver(&eps_driver); | ||
360 | } | ||
361 | |||
362 | MODULE_AUTHOR("Rafal Bilski <rafalbilski@interia.pl>"); | ||
363 | MODULE_DESCRIPTION("Enhanced PowerSaver driver for VIA C7 CPU's."); | ||
364 | MODULE_LICENSE("GPL"); | ||
365 | |||
366 | module_init(eps_init); | ||
367 | module_exit(eps_exit); | ||
diff --git a/drivers/cpufreq/elanfreq.c b/drivers/cpufreq/elanfreq.c new file mode 100644 index 000000000000..c587db472a75 --- /dev/null +++ b/drivers/cpufreq/elanfreq.c | |||
@@ -0,0 +1,309 @@ | |||
1 | /* | ||
2 | * elanfreq: cpufreq driver for the AMD ELAN family | ||
3 | * | ||
4 | * (c) Copyright 2002 Robert Schwebel <r.schwebel@pengutronix.de> | ||
5 | * | ||
6 | * Parts of this code are (c) Sven Geggus <sven@geggus.net> | ||
7 | * | ||
8 | * All Rights Reserved. | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or | ||
11 | * modify it under the terms of the GNU General Public License | ||
12 | * as published by the Free Software Foundation; either version | ||
13 | * 2 of the License, or (at your option) any later version. | ||
14 | * | ||
15 | * 2002-02-13: - initial revision for 2.4.18-pre9 by Robert Schwebel | ||
16 | * | ||
17 | */ | ||
18 | |||
19 | #include <linux/kernel.h> | ||
20 | #include <linux/module.h> | ||
21 | #include <linux/init.h> | ||
22 | |||
23 | #include <linux/delay.h> | ||
24 | #include <linux/cpufreq.h> | ||
25 | |||
26 | #include <asm/msr.h> | ||
27 | #include <linux/timex.h> | ||
28 | #include <linux/io.h> | ||
29 | |||
30 | #define REG_CSCIR 0x22 /* Chip Setup and Control Index Register */ | ||
31 | #define REG_CSCDR 0x23 /* Chip Setup and Control Data Register */ | ||
32 | |||
33 | /* Module parameter */ | ||
34 | static int max_freq; | ||
35 | |||
36 | struct s_elan_multiplier { | ||
37 | int clock; /* frequency in kHz */ | ||
38 | int val40h; /* PMU Force Mode register */ | ||
39 | int val80h; /* CPU Clock Speed Register */ | ||
40 | }; | ||
41 | |||
42 | /* | ||
43 | * It is important that the frequencies | ||
44 | * are listed in ascending order here! | ||
45 | */ | ||
46 | static struct s_elan_multiplier elan_multiplier[] = { | ||
47 | {1000, 0x02, 0x18}, | ||
48 | {2000, 0x02, 0x10}, | ||
49 | {4000, 0x02, 0x08}, | ||
50 | {8000, 0x00, 0x00}, | ||
51 | {16000, 0x00, 0x02}, | ||
52 | {33000, 0x00, 0x04}, | ||
53 | {66000, 0x01, 0x04}, | ||
54 | {99000, 0x01, 0x05} | ||
55 | }; | ||
56 | |||
57 | static struct cpufreq_frequency_table elanfreq_table[] = { | ||
58 | {0, 1000}, | ||
59 | {1, 2000}, | ||
60 | {2, 4000}, | ||
61 | {3, 8000}, | ||
62 | {4, 16000}, | ||
63 | {5, 33000}, | ||
64 | {6, 66000}, | ||
65 | {7, 99000}, | ||
66 | {0, CPUFREQ_TABLE_END}, | ||
67 | }; | ||
68 | |||
69 | |||
70 | /** | ||
71 | * elanfreq_get_cpu_frequency: determine current cpu speed | ||
72 | * | ||
73 | * Finds out at which frequency the CPU of the Elan SOC runs | ||
74 | * at the moment. Frequencies from 1 to 33 MHz are generated | ||
75 | * the normal way, 66 and 99 MHz are called "Hyperspeed Mode" | ||
76 | * and have the rest of the chip running with 33 MHz. | ||
77 | */ | ||
78 | |||
79 | static unsigned int elanfreq_get_cpu_frequency(unsigned int cpu) | ||
80 | { | ||
81 | u8 clockspeed_reg; /* Clock Speed Register */ | ||
82 | |||
83 | local_irq_disable(); | ||
84 | outb_p(0x80, REG_CSCIR); | ||
85 | clockspeed_reg = inb_p(REG_CSCDR); | ||
86 | local_irq_enable(); | ||
87 | |||
88 | if ((clockspeed_reg & 0xE0) == 0xE0) | ||
89 | return 0; | ||
90 | |||
91 | /* Are we in CPU clock multiplied mode (66/99 MHz)? */ | ||
92 | if ((clockspeed_reg & 0xE0) == 0xC0) { | ||
93 | if ((clockspeed_reg & 0x01) == 0) | ||
94 | return 66000; | ||
95 | else | ||
96 | return 99000; | ||
97 | } | ||
98 | |||
99 | /* 33 MHz is not 32 MHz... */ | ||
100 | if ((clockspeed_reg & 0xE0) == 0xA0) | ||
101 | return 33000; | ||
102 | |||
103 | return (1<<((clockspeed_reg & 0xE0) >> 5)) * 1000; | ||
104 | } | ||
105 | |||
106 | |||
107 | /** | ||
108 | * elanfreq_set_cpu_frequency: Change the CPU core frequency | ||
109 | * @cpu: cpu number | ||
110 | * @freq: frequency in kHz | ||
111 | * | ||
112 | * This function takes a frequency value and changes the CPU frequency | ||
113 | * according to this. Note that the frequency has to be checked by | ||
114 | * elanfreq_validatespeed() for correctness! | ||
115 | * | ||
116 | * There is no return value. | ||
117 | */ | ||
118 | |||
119 | static void elanfreq_set_cpu_state(unsigned int state) | ||
120 | { | ||
121 | struct cpufreq_freqs freqs; | ||
122 | |||
123 | freqs.old = elanfreq_get_cpu_frequency(0); | ||
124 | freqs.new = elan_multiplier[state].clock; | ||
125 | freqs.cpu = 0; /* elanfreq.c is UP only driver */ | ||
126 | |||
127 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
128 | |||
129 | printk(KERN_INFO "elanfreq: attempting to set frequency to %i kHz\n", | ||
130 | elan_multiplier[state].clock); | ||
131 | |||
132 | |||
133 | /* | ||
134 | * Access to the Elan's internal registers is indexed via | ||
135 | * 0x22: Chip Setup & Control Register Index Register (CSCI) | ||
136 | * 0x23: Chip Setup & Control Register Data Register (CSCD) | ||
137 | * | ||
138 | */ | ||
139 | |||
140 | /* | ||
141 | * 0x40 is the Power Management Unit's Force Mode Register. | ||
142 | * Bit 6 enables Hyperspeed Mode (66/100 MHz core frequency) | ||
143 | */ | ||
144 | |||
145 | local_irq_disable(); | ||
146 | outb_p(0x40, REG_CSCIR); /* Disable hyperspeed mode */ | ||
147 | outb_p(0x00, REG_CSCDR); | ||
148 | local_irq_enable(); /* wait till internal pipelines and */ | ||
149 | udelay(1000); /* buffers have cleaned up */ | ||
150 | |||
151 | local_irq_disable(); | ||
152 | |||
153 | /* now, set the CPU clock speed register (0x80) */ | ||
154 | outb_p(0x80, REG_CSCIR); | ||
155 | outb_p(elan_multiplier[state].val80h, REG_CSCDR); | ||
156 | |||
157 | /* now, the hyperspeed bit in PMU Force Mode Register (0x40) */ | ||
158 | outb_p(0x40, REG_CSCIR); | ||
159 | outb_p(elan_multiplier[state].val40h, REG_CSCDR); | ||
160 | udelay(10000); | ||
161 | local_irq_enable(); | ||
162 | |||
163 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
164 | }; | ||
165 | |||
166 | |||
167 | /** | ||
168 | * elanfreq_validatespeed: test if frequency range is valid | ||
169 | * @policy: the policy to validate | ||
170 | * | ||
171 | * This function checks if a given frequency range in kHz is valid | ||
172 | * for the hardware supported by the driver. | ||
173 | */ | ||
174 | |||
175 | static int elanfreq_verify(struct cpufreq_policy *policy) | ||
176 | { | ||
177 | return cpufreq_frequency_table_verify(policy, &elanfreq_table[0]); | ||
178 | } | ||
179 | |||
180 | static int elanfreq_target(struct cpufreq_policy *policy, | ||
181 | unsigned int target_freq, | ||
182 | unsigned int relation) | ||
183 | { | ||
184 | unsigned int newstate = 0; | ||
185 | |||
186 | if (cpufreq_frequency_table_target(policy, &elanfreq_table[0], | ||
187 | target_freq, relation, &newstate)) | ||
188 | return -EINVAL; | ||
189 | |||
190 | elanfreq_set_cpu_state(newstate); | ||
191 | |||
192 | return 0; | ||
193 | } | ||
194 | |||
195 | |||
196 | /* | ||
197 | * Module init and exit code | ||
198 | */ | ||
199 | |||
200 | static int elanfreq_cpu_init(struct cpufreq_policy *policy) | ||
201 | { | ||
202 | struct cpuinfo_x86 *c = &cpu_data(0); | ||
203 | unsigned int i; | ||
204 | int result; | ||
205 | |||
206 | /* capability check */ | ||
207 | if ((c->x86_vendor != X86_VENDOR_AMD) || | ||
208 | (c->x86 != 4) || (c->x86_model != 10)) | ||
209 | return -ENODEV; | ||
210 | |||
211 | /* max freq */ | ||
212 | if (!max_freq) | ||
213 | max_freq = elanfreq_get_cpu_frequency(0); | ||
214 | |||
215 | /* table init */ | ||
216 | for (i = 0; (elanfreq_table[i].frequency != CPUFREQ_TABLE_END); i++) { | ||
217 | if (elanfreq_table[i].frequency > max_freq) | ||
218 | elanfreq_table[i].frequency = CPUFREQ_ENTRY_INVALID; | ||
219 | } | ||
220 | |||
221 | /* cpuinfo and default policy values */ | ||
222 | policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL; | ||
223 | policy->cur = elanfreq_get_cpu_frequency(0); | ||
224 | |||
225 | result = cpufreq_frequency_table_cpuinfo(policy, elanfreq_table); | ||
226 | if (result) | ||
227 | return result; | ||
228 | |||
229 | cpufreq_frequency_table_get_attr(elanfreq_table, policy->cpu); | ||
230 | return 0; | ||
231 | } | ||
232 | |||
233 | |||
234 | static int elanfreq_cpu_exit(struct cpufreq_policy *policy) | ||
235 | { | ||
236 | cpufreq_frequency_table_put_attr(policy->cpu); | ||
237 | return 0; | ||
238 | } | ||
239 | |||
240 | |||
241 | #ifndef MODULE | ||
242 | /** | ||
243 | * elanfreq_setup - elanfreq command line parameter parsing | ||
244 | * | ||
245 | * elanfreq command line parameter. Use: | ||
246 | * elanfreq=66000 | ||
247 | * to set the maximum CPU frequency to 66 MHz. Note that in | ||
248 | * case you do not give this boot parameter, the maximum | ||
249 | * frequency will fall back to _current_ CPU frequency which | ||
250 | * might be lower. If you build this as a module, use the | ||
251 | * max_freq module parameter instead. | ||
252 | */ | ||
253 | static int __init elanfreq_setup(char *str) | ||
254 | { | ||
255 | max_freq = simple_strtoul(str, &str, 0); | ||
256 | printk(KERN_WARNING "You're using the deprecated elanfreq command line option. Use elanfreq.max_freq instead, please!\n"); | ||
257 | return 1; | ||
258 | } | ||
259 | __setup("elanfreq=", elanfreq_setup); | ||
260 | #endif | ||
261 | |||
262 | |||
263 | static struct freq_attr *elanfreq_attr[] = { | ||
264 | &cpufreq_freq_attr_scaling_available_freqs, | ||
265 | NULL, | ||
266 | }; | ||
267 | |||
268 | |||
269 | static struct cpufreq_driver elanfreq_driver = { | ||
270 | .get = elanfreq_get_cpu_frequency, | ||
271 | .verify = elanfreq_verify, | ||
272 | .target = elanfreq_target, | ||
273 | .init = elanfreq_cpu_init, | ||
274 | .exit = elanfreq_cpu_exit, | ||
275 | .name = "elanfreq", | ||
276 | .owner = THIS_MODULE, | ||
277 | .attr = elanfreq_attr, | ||
278 | }; | ||
279 | |||
280 | |||
281 | static int __init elanfreq_init(void) | ||
282 | { | ||
283 | struct cpuinfo_x86 *c = &cpu_data(0); | ||
284 | |||
285 | /* Test if we have the right hardware */ | ||
286 | if ((c->x86_vendor != X86_VENDOR_AMD) || | ||
287 | (c->x86 != 4) || (c->x86_model != 10)) { | ||
288 | printk(KERN_INFO "elanfreq: error: no Elan processor found!\n"); | ||
289 | return -ENODEV; | ||
290 | } | ||
291 | return cpufreq_register_driver(&elanfreq_driver); | ||
292 | } | ||
293 | |||
294 | |||
295 | static void __exit elanfreq_exit(void) | ||
296 | { | ||
297 | cpufreq_unregister_driver(&elanfreq_driver); | ||
298 | } | ||
299 | |||
300 | |||
301 | module_param(max_freq, int, 0444); | ||
302 | |||
303 | MODULE_LICENSE("GPL"); | ||
304 | MODULE_AUTHOR("Robert Schwebel <r.schwebel@pengutronix.de>, " | ||
305 | "Sven Geggus <sven@geggus.net>"); | ||
306 | MODULE_DESCRIPTION("cpufreq driver for AMD's Elan CPUs"); | ||
307 | |||
308 | module_init(elanfreq_init); | ||
309 | module_exit(elanfreq_exit); | ||
diff --git a/drivers/cpufreq/freq_table.c b/drivers/cpufreq/freq_table.c index 05432216e224..90431cb92804 100644 --- a/drivers/cpufreq/freq_table.c +++ b/drivers/cpufreq/freq_table.c | |||
@@ -14,9 +14,6 @@ | |||
14 | #include <linux/init.h> | 14 | #include <linux/init.h> |
15 | #include <linux/cpufreq.h> | 15 | #include <linux/cpufreq.h> |
16 | 16 | ||
17 | #define dprintk(msg...) \ | ||
18 | cpufreq_debug_printk(CPUFREQ_DEBUG_CORE, "freq-table", msg) | ||
19 | |||
20 | /********************************************************************* | 17 | /********************************************************************* |
21 | * FREQUENCY TABLE HELPERS * | 18 | * FREQUENCY TABLE HELPERS * |
22 | *********************************************************************/ | 19 | *********************************************************************/ |
@@ -31,11 +28,11 @@ int cpufreq_frequency_table_cpuinfo(struct cpufreq_policy *policy, | |||
31 | for (i = 0; (table[i].frequency != CPUFREQ_TABLE_END); i++) { | 28 | for (i = 0; (table[i].frequency != CPUFREQ_TABLE_END); i++) { |
32 | unsigned int freq = table[i].frequency; | 29 | unsigned int freq = table[i].frequency; |
33 | if (freq == CPUFREQ_ENTRY_INVALID) { | 30 | if (freq == CPUFREQ_ENTRY_INVALID) { |
34 | dprintk("table entry %u is invalid, skipping\n", i); | 31 | pr_debug("table entry %u is invalid, skipping\n", i); |
35 | 32 | ||
36 | continue; | 33 | continue; |
37 | } | 34 | } |
38 | dprintk("table entry %u: %u kHz, %u index\n", | 35 | pr_debug("table entry %u: %u kHz, %u index\n", |
39 | i, freq, table[i].index); | 36 | i, freq, table[i].index); |
40 | if (freq < min_freq) | 37 | if (freq < min_freq) |
41 | min_freq = freq; | 38 | min_freq = freq; |
@@ -61,7 +58,7 @@ int cpufreq_frequency_table_verify(struct cpufreq_policy *policy, | |||
61 | unsigned int i; | 58 | unsigned int i; |
62 | unsigned int count = 0; | 59 | unsigned int count = 0; |
63 | 60 | ||
64 | dprintk("request for verification of policy (%u - %u kHz) for cpu %u\n", | 61 | pr_debug("request for verification of policy (%u - %u kHz) for cpu %u\n", |
65 | policy->min, policy->max, policy->cpu); | 62 | policy->min, policy->max, policy->cpu); |
66 | 63 | ||
67 | if (!cpu_online(policy->cpu)) | 64 | if (!cpu_online(policy->cpu)) |
@@ -86,7 +83,7 @@ int cpufreq_frequency_table_verify(struct cpufreq_policy *policy, | |||
86 | cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq, | 83 | cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq, |
87 | policy->cpuinfo.max_freq); | 84 | policy->cpuinfo.max_freq); |
88 | 85 | ||
89 | dprintk("verification lead to (%u - %u kHz) for cpu %u\n", | 86 | pr_debug("verification lead to (%u - %u kHz) for cpu %u\n", |
90 | policy->min, policy->max, policy->cpu); | 87 | policy->min, policy->max, policy->cpu); |
91 | 88 | ||
92 | return 0; | 89 | return 0; |
@@ -110,7 +107,7 @@ int cpufreq_frequency_table_target(struct cpufreq_policy *policy, | |||
110 | }; | 107 | }; |
111 | unsigned int i; | 108 | unsigned int i; |
112 | 109 | ||
113 | dprintk("request for target %u kHz (relation: %u) for cpu %u\n", | 110 | pr_debug("request for target %u kHz (relation: %u) for cpu %u\n", |
114 | target_freq, relation, policy->cpu); | 111 | target_freq, relation, policy->cpu); |
115 | 112 | ||
116 | switch (relation) { | 113 | switch (relation) { |
@@ -167,7 +164,7 @@ int cpufreq_frequency_table_target(struct cpufreq_policy *policy, | |||
167 | } else | 164 | } else |
168 | *index = optimal.index; | 165 | *index = optimal.index; |
169 | 166 | ||
170 | dprintk("target is %u (%u kHz, %u)\n", *index, table[*index].frequency, | 167 | pr_debug("target is %u (%u kHz, %u)\n", *index, table[*index].frequency, |
171 | table[*index].index); | 168 | table[*index].index); |
172 | 169 | ||
173 | return 0; | 170 | return 0; |
@@ -216,14 +213,14 @@ EXPORT_SYMBOL_GPL(cpufreq_freq_attr_scaling_available_freqs); | |||
216 | void cpufreq_frequency_table_get_attr(struct cpufreq_frequency_table *table, | 213 | void cpufreq_frequency_table_get_attr(struct cpufreq_frequency_table *table, |
217 | unsigned int cpu) | 214 | unsigned int cpu) |
218 | { | 215 | { |
219 | dprintk("setting show_table for cpu %u to %p\n", cpu, table); | 216 | pr_debug("setting show_table for cpu %u to %p\n", cpu, table); |
220 | per_cpu(cpufreq_show_table, cpu) = table; | 217 | per_cpu(cpufreq_show_table, cpu) = table; |
221 | } | 218 | } |
222 | EXPORT_SYMBOL_GPL(cpufreq_frequency_table_get_attr); | 219 | EXPORT_SYMBOL_GPL(cpufreq_frequency_table_get_attr); |
223 | 220 | ||
224 | void cpufreq_frequency_table_put_attr(unsigned int cpu) | 221 | void cpufreq_frequency_table_put_attr(unsigned int cpu) |
225 | { | 222 | { |
226 | dprintk("clearing show_table for cpu %u\n", cpu); | 223 | pr_debug("clearing show_table for cpu %u\n", cpu); |
227 | per_cpu(cpufreq_show_table, cpu) = NULL; | 224 | per_cpu(cpufreq_show_table, cpu) = NULL; |
228 | } | 225 | } |
229 | EXPORT_SYMBOL_GPL(cpufreq_frequency_table_put_attr); | 226 | EXPORT_SYMBOL_GPL(cpufreq_frequency_table_put_attr); |
diff --git a/drivers/cpufreq/gx-suspmod.c b/drivers/cpufreq/gx-suspmod.c new file mode 100644 index 000000000000..ffe1f2c92ed3 --- /dev/null +++ b/drivers/cpufreq/gx-suspmod.c | |||
@@ -0,0 +1,514 @@ | |||
1 | /* | ||
2 | * Cyrix MediaGX and NatSemi Geode Suspend Modulation | ||
3 | * (C) 2002 Zwane Mwaikambo <zwane@commfireservices.com> | ||
4 | * (C) 2002 Hiroshi Miura <miura@da-cha.org> | ||
5 | * All Rights Reserved | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or | ||
8 | * modify it under the terms of the GNU General Public License | ||
9 | * version 2 as published by the Free Software Foundation | ||
10 | * | ||
11 | * The author(s) of this software shall not be held liable for damages | ||
12 | * of any nature resulting due to the use of this software. This | ||
13 | * software is provided AS-IS with no warranties. | ||
14 | * | ||
15 | * Theoretical note: | ||
16 | * | ||
17 | * (see Geode(tm) CS5530 manual (rev.4.1) page.56) | ||
18 | * | ||
19 | * CPU frequency control on NatSemi Geode GX1/GXLV processor and CS55x0 | ||
20 | * are based on Suspend Modulation. | ||
21 | * | ||
22 | * Suspend Modulation works by asserting and de-asserting the SUSP# pin | ||
23 | * to CPU(GX1/GXLV) for configurable durations. When asserting SUSP# | ||
24 | * the CPU enters an idle state. GX1 stops its core clock when SUSP# is | ||
25 | * asserted then power consumption is reduced. | ||
26 | * | ||
27 | * Suspend Modulation's OFF/ON duration are configurable | ||
28 | * with 'Suspend Modulation OFF Count Register' | ||
29 | * and 'Suspend Modulation ON Count Register'. | ||
30 | * These registers are 8bit counters that represent the number of | ||
31 | * 32us intervals which the SUSP# pin is asserted(ON)/de-asserted(OFF) | ||
32 | * to the processor. | ||
33 | * | ||
34 | * These counters define a ratio which is the effective frequency | ||
35 | * of operation of the system. | ||
36 | * | ||
37 | * OFF Count | ||
38 | * F_eff = Fgx * ---------------------- | ||
39 | * OFF Count + ON Count | ||
40 | * | ||
41 | * 0 <= On Count, Off Count <= 255 | ||
42 | * | ||
43 | * From these limits, we can get register values | ||
44 | * | ||
45 | * off_duration + on_duration <= MAX_DURATION | ||
46 | * on_duration = off_duration * (stock_freq - freq) / freq | ||
47 | * | ||
48 | * off_duration = (freq * DURATION) / stock_freq | ||
49 | * on_duration = DURATION - off_duration | ||
50 | * | ||
51 | * | ||
52 | *--------------------------------------------------------------------------- | ||
53 | * | ||
54 | * ChangeLog: | ||
55 | * Dec. 12, 2003 Hiroshi Miura <miura@da-cha.org> | ||
56 | * - fix on/off register mistake | ||
57 | * - fix cpu_khz calc when it stops cpu modulation. | ||
58 | * | ||
59 | * Dec. 11, 2002 Hiroshi Miura <miura@da-cha.org> | ||
60 | * - rewrite for Cyrix MediaGX Cx5510/5520 and | ||
61 | * NatSemi Geode Cs5530(A). | ||
62 | * | ||
63 | * Jul. ??, 2002 Zwane Mwaikambo <zwane@commfireservices.com> | ||
64 | * - cs5530_mod patch for 2.4.19-rc1. | ||
65 | * | ||
66 | *--------------------------------------------------------------------------- | ||
67 | * | ||
68 | * Todo | ||
69 | * Test on machines with 5510, 5530, 5530A | ||
70 | */ | ||
71 | |||
72 | /************************************************************************ | ||
73 | * Suspend Modulation - Definitions * | ||
74 | ************************************************************************/ | ||
75 | |||
76 | #include <linux/kernel.h> | ||
77 | #include <linux/module.h> | ||
78 | #include <linux/init.h> | ||
79 | #include <linux/smp.h> | ||
80 | #include <linux/cpufreq.h> | ||
81 | #include <linux/pci.h> | ||
82 | #include <linux/errno.h> | ||
83 | #include <linux/slab.h> | ||
84 | |||
85 | #include <asm/processor-cyrix.h> | ||
86 | |||
87 | /* PCI config registers, all at F0 */ | ||
88 | #define PCI_PMER1 0x80 /* power management enable register 1 */ | ||
89 | #define PCI_PMER2 0x81 /* power management enable register 2 */ | ||
90 | #define PCI_PMER3 0x82 /* power management enable register 3 */ | ||
91 | #define PCI_IRQTC 0x8c /* irq speedup timer counter register:typical 2 to 4ms */ | ||
92 | #define PCI_VIDTC 0x8d /* video speedup timer counter register: typical 50 to 100ms */ | ||
93 | #define PCI_MODOFF 0x94 /* suspend modulation OFF counter register, 1 = 32us */ | ||
94 | #define PCI_MODON 0x95 /* suspend modulation ON counter register */ | ||
95 | #define PCI_SUSCFG 0x96 /* suspend configuration register */ | ||
96 | |||
97 | /* PMER1 bits */ | ||
98 | #define GPM (1<<0) /* global power management */ | ||
99 | #define GIT (1<<1) /* globally enable PM device idle timers */ | ||
100 | #define GTR (1<<2) /* globally enable IO traps */ | ||
101 | #define IRQ_SPDUP (1<<3) /* disable clock throttle during interrupt handling */ | ||
102 | #define VID_SPDUP (1<<4) /* disable clock throttle during vga video handling */ | ||
103 | |||
104 | /* SUSCFG bits */ | ||
105 | #define SUSMOD (1<<0) /* enable/disable suspend modulation */ | ||
106 | /* the below is supported only with cs5530 (after rev.1.2)/cs5530A */ | ||
107 | #define SMISPDUP (1<<1) /* select how SMI re-enable suspend modulation: */ | ||
108 | /* IRQTC timer or read SMI speedup disable reg.(F1BAR[08-09h]) */ | ||
109 | #define SUSCFG (1<<2) /* enable powering down a GXLV processor. "Special 3Volt Suspend" mode */ | ||
110 | /* the below is supported only with cs5530A */ | ||
111 | #define PWRSVE_ISA (1<<3) /* stop ISA clock */ | ||
112 | #define PWRSVE (1<<4) /* active idle */ | ||
113 | |||
114 | struct gxfreq_params { | ||
115 | u8 on_duration; | ||
116 | u8 off_duration; | ||
117 | u8 pci_suscfg; | ||
118 | u8 pci_pmer1; | ||
119 | u8 pci_pmer2; | ||
120 | struct pci_dev *cs55x0; | ||
121 | }; | ||
122 | |||
123 | static struct gxfreq_params *gx_params; | ||
124 | static int stock_freq; | ||
125 | |||
126 | /* PCI bus clock - defaults to 30.000 if cpu_khz is not available */ | ||
127 | static int pci_busclk; | ||
128 | module_param(pci_busclk, int, 0444); | ||
129 | |||
130 | /* maximum duration for which the cpu may be suspended | ||
131 | * (32us * MAX_DURATION). If no parameter is given, this defaults | ||
132 | * to 255. | ||
133 | * Note that this leads to a maximum of 8 ms(!) where the CPU clock | ||
134 | * is suspended -- processing power is just 0.39% of what it used to be, | ||
135 | * though. 781.25 kHz(!) for a 200 MHz processor -- wow. */ | ||
136 | static int max_duration = 255; | ||
137 | module_param(max_duration, int, 0444); | ||
138 | |||
139 | /* For the default policy, we want at least some processing power | ||
140 | * - let's say 5%. (min = maxfreq / POLICY_MIN_DIV) | ||
141 | */ | ||
142 | #define POLICY_MIN_DIV 20 | ||
143 | |||
144 | |||
145 | /** | ||
146 | * we can detect a core multipiler from dir0_lsb | ||
147 | * from GX1 datasheet p.56, | ||
148 | * MULT[3:0]: | ||
149 | * 0000 = SYSCLK multiplied by 4 (test only) | ||
150 | * 0001 = SYSCLK multiplied by 10 | ||
151 | * 0010 = SYSCLK multiplied by 4 | ||
152 | * 0011 = SYSCLK multiplied by 6 | ||
153 | * 0100 = SYSCLK multiplied by 9 | ||
154 | * 0101 = SYSCLK multiplied by 5 | ||
155 | * 0110 = SYSCLK multiplied by 7 | ||
156 | * 0111 = SYSCLK multiplied by 8 | ||
157 | * of 33.3MHz | ||
158 | **/ | ||
159 | static int gx_freq_mult[16] = { | ||
160 | 4, 10, 4, 6, 9, 5, 7, 8, | ||
161 | 0, 0, 0, 0, 0, 0, 0, 0 | ||
162 | }; | ||
163 | |||
164 | |||
165 | /**************************************************************** | ||
166 | * Low Level chipset interface * | ||
167 | ****************************************************************/ | ||
168 | static struct pci_device_id gx_chipset_tbl[] __initdata = { | ||
169 | { PCI_VDEVICE(CYRIX, PCI_DEVICE_ID_CYRIX_5530_LEGACY), }, | ||
170 | { PCI_VDEVICE(CYRIX, PCI_DEVICE_ID_CYRIX_5520), }, | ||
171 | { PCI_VDEVICE(CYRIX, PCI_DEVICE_ID_CYRIX_5510), }, | ||
172 | { 0, }, | ||
173 | }; | ||
174 | |||
175 | static void gx_write_byte(int reg, int value) | ||
176 | { | ||
177 | pci_write_config_byte(gx_params->cs55x0, reg, value); | ||
178 | } | ||
179 | |||
180 | /** | ||
181 | * gx_detect_chipset: | ||
182 | * | ||
183 | **/ | ||
184 | static __init struct pci_dev *gx_detect_chipset(void) | ||
185 | { | ||
186 | struct pci_dev *gx_pci = NULL; | ||
187 | |||
188 | /* check if CPU is a MediaGX or a Geode. */ | ||
189 | if ((boot_cpu_data.x86_vendor != X86_VENDOR_NSC) && | ||
190 | (boot_cpu_data.x86_vendor != X86_VENDOR_CYRIX)) { | ||
191 | pr_debug("error: no MediaGX/Geode processor found!\n"); | ||
192 | return NULL; | ||
193 | } | ||
194 | |||
195 | /* detect which companion chip is used */ | ||
196 | for_each_pci_dev(gx_pci) { | ||
197 | if ((pci_match_id(gx_chipset_tbl, gx_pci)) != NULL) | ||
198 | return gx_pci; | ||
199 | } | ||
200 | |||
201 | pr_debug("error: no supported chipset found!\n"); | ||
202 | return NULL; | ||
203 | } | ||
204 | |||
205 | /** | ||
206 | * gx_get_cpuspeed: | ||
207 | * | ||
208 | * Finds out at which efficient frequency the Cyrix MediaGX/NatSemi | ||
209 | * Geode CPU runs. | ||
210 | */ | ||
211 | static unsigned int gx_get_cpuspeed(unsigned int cpu) | ||
212 | { | ||
213 | if ((gx_params->pci_suscfg & SUSMOD) == 0) | ||
214 | return stock_freq; | ||
215 | |||
216 | return (stock_freq * gx_params->off_duration) | ||
217 | / (gx_params->on_duration + gx_params->off_duration); | ||
218 | } | ||
219 | |||
220 | /** | ||
221 | * gx_validate_speed: | ||
222 | * determine current cpu speed | ||
223 | * | ||
224 | **/ | ||
225 | |||
226 | static unsigned int gx_validate_speed(unsigned int khz, u8 *on_duration, | ||
227 | u8 *off_duration) | ||
228 | { | ||
229 | unsigned int i; | ||
230 | u8 tmp_on, tmp_off; | ||
231 | int old_tmp_freq = stock_freq; | ||
232 | int tmp_freq; | ||
233 | |||
234 | *off_duration = 1; | ||
235 | *on_duration = 0; | ||
236 | |||
237 | for (i = max_duration; i > 0; i--) { | ||
238 | tmp_off = ((khz * i) / stock_freq) & 0xff; | ||
239 | tmp_on = i - tmp_off; | ||
240 | tmp_freq = (stock_freq * tmp_off) / i; | ||
241 | /* if this relation is closer to khz, use this. If it's equal, | ||
242 | * prefer it, too - lower latency */ | ||
243 | if (abs(tmp_freq - khz) <= abs(old_tmp_freq - khz)) { | ||
244 | *on_duration = tmp_on; | ||
245 | *off_duration = tmp_off; | ||
246 | old_tmp_freq = tmp_freq; | ||
247 | } | ||
248 | } | ||
249 | |||
250 | return old_tmp_freq; | ||
251 | } | ||
252 | |||
253 | |||
254 | /** | ||
255 | * gx_set_cpuspeed: | ||
256 | * set cpu speed in khz. | ||
257 | **/ | ||
258 | |||
259 | static void gx_set_cpuspeed(unsigned int khz) | ||
260 | { | ||
261 | u8 suscfg, pmer1; | ||
262 | unsigned int new_khz; | ||
263 | unsigned long flags; | ||
264 | struct cpufreq_freqs freqs; | ||
265 | |||
266 | freqs.cpu = 0; | ||
267 | freqs.old = gx_get_cpuspeed(0); | ||
268 | |||
269 | new_khz = gx_validate_speed(khz, &gx_params->on_duration, | ||
270 | &gx_params->off_duration); | ||
271 | |||
272 | freqs.new = new_khz; | ||
273 | |||
274 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
275 | local_irq_save(flags); | ||
276 | |||
277 | |||
278 | |||
279 | if (new_khz != stock_freq) { | ||
280 | /* if new khz == 100% of CPU speed, it is special case */ | ||
281 | switch (gx_params->cs55x0->device) { | ||
282 | case PCI_DEVICE_ID_CYRIX_5530_LEGACY: | ||
283 | pmer1 = gx_params->pci_pmer1 | IRQ_SPDUP | VID_SPDUP; | ||
284 | /* FIXME: need to test other values -- Zwane,Miura */ | ||
285 | /* typical 2 to 4ms */ | ||
286 | gx_write_byte(PCI_IRQTC, 4); | ||
287 | /* typical 50 to 100ms */ | ||
288 | gx_write_byte(PCI_VIDTC, 100); | ||
289 | gx_write_byte(PCI_PMER1, pmer1); | ||
290 | |||
291 | if (gx_params->cs55x0->revision < 0x10) { | ||
292 | /* CS5530(rev 1.2, 1.3) */ | ||
293 | suscfg = gx_params->pci_suscfg|SUSMOD; | ||
294 | } else { | ||
295 | /* CS5530A,B.. */ | ||
296 | suscfg = gx_params->pci_suscfg|SUSMOD|PWRSVE; | ||
297 | } | ||
298 | break; | ||
299 | case PCI_DEVICE_ID_CYRIX_5520: | ||
300 | case PCI_DEVICE_ID_CYRIX_5510: | ||
301 | suscfg = gx_params->pci_suscfg | SUSMOD; | ||
302 | break; | ||
303 | default: | ||
304 | local_irq_restore(flags); | ||
305 | pr_debug("fatal: try to set unknown chipset.\n"); | ||
306 | return; | ||
307 | } | ||
308 | } else { | ||
309 | suscfg = gx_params->pci_suscfg & ~(SUSMOD); | ||
310 | gx_params->off_duration = 0; | ||
311 | gx_params->on_duration = 0; | ||
312 | pr_debug("suspend modulation disabled: cpu runs 100%% speed.\n"); | ||
313 | } | ||
314 | |||
315 | gx_write_byte(PCI_MODOFF, gx_params->off_duration); | ||
316 | gx_write_byte(PCI_MODON, gx_params->on_duration); | ||
317 | |||
318 | gx_write_byte(PCI_SUSCFG, suscfg); | ||
319 | pci_read_config_byte(gx_params->cs55x0, PCI_SUSCFG, &suscfg); | ||
320 | |||
321 | local_irq_restore(flags); | ||
322 | |||
323 | gx_params->pci_suscfg = suscfg; | ||
324 | |||
325 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
326 | |||
327 | pr_debug("suspend modulation w/ duration of ON:%d us, OFF:%d us\n", | ||
328 | gx_params->on_duration * 32, gx_params->off_duration * 32); | ||
329 | pr_debug("suspend modulation w/ clock speed: %d kHz.\n", freqs.new); | ||
330 | } | ||
331 | |||
332 | /**************************************************************** | ||
333 | * High level functions * | ||
334 | ****************************************************************/ | ||
335 | |||
336 | /* | ||
337 | * cpufreq_gx_verify: test if frequency range is valid | ||
338 | * | ||
339 | * This function checks if a given frequency range in kHz is valid | ||
340 | * for the hardware supported by the driver. | ||
341 | */ | ||
342 | |||
343 | static int cpufreq_gx_verify(struct cpufreq_policy *policy) | ||
344 | { | ||
345 | unsigned int tmp_freq = 0; | ||
346 | u8 tmp1, tmp2; | ||
347 | |||
348 | if (!stock_freq || !policy) | ||
349 | return -EINVAL; | ||
350 | |||
351 | policy->cpu = 0; | ||
352 | cpufreq_verify_within_limits(policy, (stock_freq / max_duration), | ||
353 | stock_freq); | ||
354 | |||
355 | /* it needs to be assured that at least one supported frequency is | ||
356 | * within policy->min and policy->max. If it is not, policy->max | ||
357 | * needs to be increased until one freuqency is supported. | ||
358 | * policy->min may not be decreased, though. This way we guarantee a | ||
359 | * specific processing capacity. | ||
360 | */ | ||
361 | tmp_freq = gx_validate_speed(policy->min, &tmp1, &tmp2); | ||
362 | if (tmp_freq < policy->min) | ||
363 | tmp_freq += stock_freq / max_duration; | ||
364 | policy->min = tmp_freq; | ||
365 | if (policy->min > policy->max) | ||
366 | policy->max = tmp_freq; | ||
367 | tmp_freq = gx_validate_speed(policy->max, &tmp1, &tmp2); | ||
368 | if (tmp_freq > policy->max) | ||
369 | tmp_freq -= stock_freq / max_duration; | ||
370 | policy->max = tmp_freq; | ||
371 | if (policy->max < policy->min) | ||
372 | policy->max = policy->min; | ||
373 | cpufreq_verify_within_limits(policy, (stock_freq / max_duration), | ||
374 | stock_freq); | ||
375 | |||
376 | return 0; | ||
377 | } | ||
378 | |||
379 | /* | ||
380 | * cpufreq_gx_target: | ||
381 | * | ||
382 | */ | ||
383 | static int cpufreq_gx_target(struct cpufreq_policy *policy, | ||
384 | unsigned int target_freq, | ||
385 | unsigned int relation) | ||
386 | { | ||
387 | u8 tmp1, tmp2; | ||
388 | unsigned int tmp_freq; | ||
389 | |||
390 | if (!stock_freq || !policy) | ||
391 | return -EINVAL; | ||
392 | |||
393 | policy->cpu = 0; | ||
394 | |||
395 | tmp_freq = gx_validate_speed(target_freq, &tmp1, &tmp2); | ||
396 | while (tmp_freq < policy->min) { | ||
397 | tmp_freq += stock_freq / max_duration; | ||
398 | tmp_freq = gx_validate_speed(tmp_freq, &tmp1, &tmp2); | ||
399 | } | ||
400 | while (tmp_freq > policy->max) { | ||
401 | tmp_freq -= stock_freq / max_duration; | ||
402 | tmp_freq = gx_validate_speed(tmp_freq, &tmp1, &tmp2); | ||
403 | } | ||
404 | |||
405 | gx_set_cpuspeed(tmp_freq); | ||
406 | |||
407 | return 0; | ||
408 | } | ||
409 | |||
410 | static int cpufreq_gx_cpu_init(struct cpufreq_policy *policy) | ||
411 | { | ||
412 | unsigned int maxfreq, curfreq; | ||
413 | |||
414 | if (!policy || policy->cpu != 0) | ||
415 | return -ENODEV; | ||
416 | |||
417 | /* determine maximum frequency */ | ||
418 | if (pci_busclk) | ||
419 | maxfreq = pci_busclk * gx_freq_mult[getCx86(CX86_DIR1) & 0x0f]; | ||
420 | else if (cpu_khz) | ||
421 | maxfreq = cpu_khz; | ||
422 | else | ||
423 | maxfreq = 30000 * gx_freq_mult[getCx86(CX86_DIR1) & 0x0f]; | ||
424 | |||
425 | stock_freq = maxfreq; | ||
426 | curfreq = gx_get_cpuspeed(0); | ||
427 | |||
428 | pr_debug("cpu max frequency is %d.\n", maxfreq); | ||
429 | pr_debug("cpu current frequency is %dkHz.\n", curfreq); | ||
430 | |||
431 | /* setup basic struct for cpufreq API */ | ||
432 | policy->cpu = 0; | ||
433 | |||
434 | if (max_duration < POLICY_MIN_DIV) | ||
435 | policy->min = maxfreq / max_duration; | ||
436 | else | ||
437 | policy->min = maxfreq / POLICY_MIN_DIV; | ||
438 | policy->max = maxfreq; | ||
439 | policy->cur = curfreq; | ||
440 | policy->cpuinfo.min_freq = maxfreq / max_duration; | ||
441 | policy->cpuinfo.max_freq = maxfreq; | ||
442 | policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL; | ||
443 | |||
444 | return 0; | ||
445 | } | ||
446 | |||
447 | /* | ||
448 | * cpufreq_gx_init: | ||
449 | * MediaGX/Geode GX initialize cpufreq driver | ||
450 | */ | ||
451 | static struct cpufreq_driver gx_suspmod_driver = { | ||
452 | .get = gx_get_cpuspeed, | ||
453 | .verify = cpufreq_gx_verify, | ||
454 | .target = cpufreq_gx_target, | ||
455 | .init = cpufreq_gx_cpu_init, | ||
456 | .name = "gx-suspmod", | ||
457 | .owner = THIS_MODULE, | ||
458 | }; | ||
459 | |||
460 | static int __init cpufreq_gx_init(void) | ||
461 | { | ||
462 | int ret; | ||
463 | struct gxfreq_params *params; | ||
464 | struct pci_dev *gx_pci; | ||
465 | |||
466 | /* Test if we have the right hardware */ | ||
467 | gx_pci = gx_detect_chipset(); | ||
468 | if (gx_pci == NULL) | ||
469 | return -ENODEV; | ||
470 | |||
471 | /* check whether module parameters are sane */ | ||
472 | if (max_duration > 0xff) | ||
473 | max_duration = 0xff; | ||
474 | |||
475 | pr_debug("geode suspend modulation available.\n"); | ||
476 | |||
477 | params = kzalloc(sizeof(struct gxfreq_params), GFP_KERNEL); | ||
478 | if (params == NULL) | ||
479 | return -ENOMEM; | ||
480 | |||
481 | params->cs55x0 = gx_pci; | ||
482 | gx_params = params; | ||
483 | |||
484 | /* keep cs55x0 configurations */ | ||
485 | pci_read_config_byte(params->cs55x0, PCI_SUSCFG, &(params->pci_suscfg)); | ||
486 | pci_read_config_byte(params->cs55x0, PCI_PMER1, &(params->pci_pmer1)); | ||
487 | pci_read_config_byte(params->cs55x0, PCI_PMER2, &(params->pci_pmer2)); | ||
488 | pci_read_config_byte(params->cs55x0, PCI_MODON, &(params->on_duration)); | ||
489 | pci_read_config_byte(params->cs55x0, PCI_MODOFF, | ||
490 | &(params->off_duration)); | ||
491 | |||
492 | ret = cpufreq_register_driver(&gx_suspmod_driver); | ||
493 | if (ret) { | ||
494 | kfree(params); | ||
495 | return ret; /* register error! */ | ||
496 | } | ||
497 | |||
498 | return 0; | ||
499 | } | ||
500 | |||
501 | static void __exit cpufreq_gx_exit(void) | ||
502 | { | ||
503 | cpufreq_unregister_driver(&gx_suspmod_driver); | ||
504 | pci_dev_put(gx_params->cs55x0); | ||
505 | kfree(gx_params); | ||
506 | } | ||
507 | |||
508 | MODULE_AUTHOR("Hiroshi Miura <miura@da-cha.org>"); | ||
509 | MODULE_DESCRIPTION("Cpufreq driver for Cyrix MediaGX and NatSemi Geode"); | ||
510 | MODULE_LICENSE("GPL"); | ||
511 | |||
512 | module_init(cpufreq_gx_init); | ||
513 | module_exit(cpufreq_gx_exit); | ||
514 | |||
diff --git a/drivers/cpufreq/longhaul.c b/drivers/cpufreq/longhaul.c new file mode 100644 index 000000000000..f47d26e2a135 --- /dev/null +++ b/drivers/cpufreq/longhaul.c | |||
@@ -0,0 +1,1024 @@ | |||
1 | /* | ||
2 | * (C) 2001-2004 Dave Jones. <davej@redhat.com> | ||
3 | * (C) 2002 Padraig Brady. <padraig@antefacto.com> | ||
4 | * | ||
5 | * Licensed under the terms of the GNU GPL License version 2. | ||
6 | * Based upon datasheets & sample CPUs kindly provided by VIA. | ||
7 | * | ||
8 | * VIA have currently 3 different versions of Longhaul. | ||
9 | * Version 1 (Longhaul) uses the BCR2 MSR at 0x1147. | ||
10 | * It is present only in Samuel 1 (C5A), Samuel 2 (C5B) stepping 0. | ||
11 | * Version 2 of longhaul is backward compatible with v1, but adds | ||
12 | * LONGHAUL MSR for purpose of both frequency and voltage scaling. | ||
13 | * Present in Samuel 2 (steppings 1-7 only) (C5B), and Ezra (C5C). | ||
14 | * Version 3 of longhaul got renamed to Powersaver and redesigned | ||
15 | * to use only the POWERSAVER MSR at 0x110a. | ||
16 | * It is present in Ezra-T (C5M), Nehemiah (C5X) and above. | ||
17 | * It's pretty much the same feature wise to longhaul v2, though | ||
18 | * there is provision for scaling FSB too, but this doesn't work | ||
19 | * too well in practice so we don't even try to use this. | ||
20 | * | ||
21 | * BIG FAT DISCLAIMER: Work in progress code. Possibly *dangerous* | ||
22 | */ | ||
23 | |||
24 | #include <linux/kernel.h> | ||
25 | #include <linux/module.h> | ||
26 | #include <linux/moduleparam.h> | ||
27 | #include <linux/init.h> | ||
28 | #include <linux/cpufreq.h> | ||
29 | #include <linux/pci.h> | ||
30 | #include <linux/slab.h> | ||
31 | #include <linux/string.h> | ||
32 | #include <linux/delay.h> | ||
33 | #include <linux/timex.h> | ||
34 | #include <linux/io.h> | ||
35 | #include <linux/acpi.h> | ||
36 | |||
37 | #include <asm/msr.h> | ||
38 | #include <acpi/processor.h> | ||
39 | |||
40 | #include "longhaul.h" | ||
41 | |||
42 | #define PFX "longhaul: " | ||
43 | |||
44 | #define TYPE_LONGHAUL_V1 1 | ||
45 | #define TYPE_LONGHAUL_V2 2 | ||
46 | #define TYPE_POWERSAVER 3 | ||
47 | |||
48 | #define CPU_SAMUEL 1 | ||
49 | #define CPU_SAMUEL2 2 | ||
50 | #define CPU_EZRA 3 | ||
51 | #define CPU_EZRA_T 4 | ||
52 | #define CPU_NEHEMIAH 5 | ||
53 | #define CPU_NEHEMIAH_C 6 | ||
54 | |||
55 | /* Flags */ | ||
56 | #define USE_ACPI_C3 (1 << 1) | ||
57 | #define USE_NORTHBRIDGE (1 << 2) | ||
58 | |||
59 | static int cpu_model; | ||
60 | static unsigned int numscales = 16; | ||
61 | static unsigned int fsb; | ||
62 | |||
63 | static const struct mV_pos *vrm_mV_table; | ||
64 | static const unsigned char *mV_vrm_table; | ||
65 | |||
66 | static unsigned int highest_speed, lowest_speed; /* kHz */ | ||
67 | static unsigned int minmult, maxmult; | ||
68 | static int can_scale_voltage; | ||
69 | static struct acpi_processor *pr; | ||
70 | static struct acpi_processor_cx *cx; | ||
71 | static u32 acpi_regs_addr; | ||
72 | static u8 longhaul_flags; | ||
73 | static unsigned int longhaul_index; | ||
74 | |||
75 | /* Module parameters */ | ||
76 | static int scale_voltage; | ||
77 | static int disable_acpi_c3; | ||
78 | static int revid_errata; | ||
79 | |||
80 | |||
81 | /* Clock ratios multiplied by 10 */ | ||
82 | static int mults[32]; | ||
83 | static int eblcr[32]; | ||
84 | static int longhaul_version; | ||
85 | static struct cpufreq_frequency_table *longhaul_table; | ||
86 | |||
87 | static char speedbuffer[8]; | ||
88 | |||
89 | static char *print_speed(int speed) | ||
90 | { | ||
91 | if (speed < 1000) { | ||
92 | snprintf(speedbuffer, sizeof(speedbuffer), "%dMHz", speed); | ||
93 | return speedbuffer; | ||
94 | } | ||
95 | |||
96 | if (speed%1000 == 0) | ||
97 | snprintf(speedbuffer, sizeof(speedbuffer), | ||
98 | "%dGHz", speed/1000); | ||
99 | else | ||
100 | snprintf(speedbuffer, sizeof(speedbuffer), | ||
101 | "%d.%dGHz", speed/1000, (speed%1000)/100); | ||
102 | |||
103 | return speedbuffer; | ||
104 | } | ||
105 | |||
106 | |||
107 | static unsigned int calc_speed(int mult) | ||
108 | { | ||
109 | int khz; | ||
110 | khz = (mult/10)*fsb; | ||
111 | if (mult%10) | ||
112 | khz += fsb/2; | ||
113 | khz *= 1000; | ||
114 | return khz; | ||
115 | } | ||
116 | |||
117 | |||
118 | static int longhaul_get_cpu_mult(void) | ||
119 | { | ||
120 | unsigned long invalue = 0, lo, hi; | ||
121 | |||
122 | rdmsr(MSR_IA32_EBL_CR_POWERON, lo, hi); | ||
123 | invalue = (lo & (1<<22|1<<23|1<<24|1<<25))>>22; | ||
124 | if (longhaul_version == TYPE_LONGHAUL_V2 || | ||
125 | longhaul_version == TYPE_POWERSAVER) { | ||
126 | if (lo & (1<<27)) | ||
127 | invalue += 16; | ||
128 | } | ||
129 | return eblcr[invalue]; | ||
130 | } | ||
131 | |||
132 | /* For processor with BCR2 MSR */ | ||
133 | |||
134 | static void do_longhaul1(unsigned int mults_index) | ||
135 | { | ||
136 | union msr_bcr2 bcr2; | ||
137 | |||
138 | rdmsrl(MSR_VIA_BCR2, bcr2.val); | ||
139 | /* Enable software clock multiplier */ | ||
140 | bcr2.bits.ESOFTBF = 1; | ||
141 | bcr2.bits.CLOCKMUL = mults_index & 0xff; | ||
142 | |||
143 | /* Sync to timer tick */ | ||
144 | safe_halt(); | ||
145 | /* Change frequency on next halt or sleep */ | ||
146 | wrmsrl(MSR_VIA_BCR2, bcr2.val); | ||
147 | /* Invoke transition */ | ||
148 | ACPI_FLUSH_CPU_CACHE(); | ||
149 | halt(); | ||
150 | |||
151 | /* Disable software clock multiplier */ | ||
152 | local_irq_disable(); | ||
153 | rdmsrl(MSR_VIA_BCR2, bcr2.val); | ||
154 | bcr2.bits.ESOFTBF = 0; | ||
155 | wrmsrl(MSR_VIA_BCR2, bcr2.val); | ||
156 | } | ||
157 | |||
158 | /* For processor with Longhaul MSR */ | ||
159 | |||
160 | static void do_powersaver(int cx_address, unsigned int mults_index, | ||
161 | unsigned int dir) | ||
162 | { | ||
163 | union msr_longhaul longhaul; | ||
164 | u32 t; | ||
165 | |||
166 | rdmsrl(MSR_VIA_LONGHAUL, longhaul.val); | ||
167 | /* Setup new frequency */ | ||
168 | if (!revid_errata) | ||
169 | longhaul.bits.RevisionKey = longhaul.bits.RevisionID; | ||
170 | else | ||
171 | longhaul.bits.RevisionKey = 0; | ||
172 | longhaul.bits.SoftBusRatio = mults_index & 0xf; | ||
173 | longhaul.bits.SoftBusRatio4 = (mults_index & 0x10) >> 4; | ||
174 | /* Setup new voltage */ | ||
175 | if (can_scale_voltage) | ||
176 | longhaul.bits.SoftVID = (mults_index >> 8) & 0x1f; | ||
177 | /* Sync to timer tick */ | ||
178 | safe_halt(); | ||
179 | /* Raise voltage if necessary */ | ||
180 | if (can_scale_voltage && dir) { | ||
181 | longhaul.bits.EnableSoftVID = 1; | ||
182 | wrmsrl(MSR_VIA_LONGHAUL, longhaul.val); | ||
183 | /* Change voltage */ | ||
184 | if (!cx_address) { | ||
185 | ACPI_FLUSH_CPU_CACHE(); | ||
186 | halt(); | ||
187 | } else { | ||
188 | ACPI_FLUSH_CPU_CACHE(); | ||
189 | /* Invoke C3 */ | ||
190 | inb(cx_address); | ||
191 | /* Dummy op - must do something useless after P_LVL3 | ||
192 | * read */ | ||
193 | t = inl(acpi_gbl_FADT.xpm_timer_block.address); | ||
194 | } | ||
195 | longhaul.bits.EnableSoftVID = 0; | ||
196 | wrmsrl(MSR_VIA_LONGHAUL, longhaul.val); | ||
197 | } | ||
198 | |||
199 | /* Change frequency on next halt or sleep */ | ||
200 | longhaul.bits.EnableSoftBusRatio = 1; | ||
201 | wrmsrl(MSR_VIA_LONGHAUL, longhaul.val); | ||
202 | if (!cx_address) { | ||
203 | ACPI_FLUSH_CPU_CACHE(); | ||
204 | halt(); | ||
205 | } else { | ||
206 | ACPI_FLUSH_CPU_CACHE(); | ||
207 | /* Invoke C3 */ | ||
208 | inb(cx_address); | ||
209 | /* Dummy op - must do something useless after P_LVL3 read */ | ||
210 | t = inl(acpi_gbl_FADT.xpm_timer_block.address); | ||
211 | } | ||
212 | /* Disable bus ratio bit */ | ||
213 | longhaul.bits.EnableSoftBusRatio = 0; | ||
214 | wrmsrl(MSR_VIA_LONGHAUL, longhaul.val); | ||
215 | |||
216 | /* Reduce voltage if necessary */ | ||
217 | if (can_scale_voltage && !dir) { | ||
218 | longhaul.bits.EnableSoftVID = 1; | ||
219 | wrmsrl(MSR_VIA_LONGHAUL, longhaul.val); | ||
220 | /* Change voltage */ | ||
221 | if (!cx_address) { | ||
222 | ACPI_FLUSH_CPU_CACHE(); | ||
223 | halt(); | ||
224 | } else { | ||
225 | ACPI_FLUSH_CPU_CACHE(); | ||
226 | /* Invoke C3 */ | ||
227 | inb(cx_address); | ||
228 | /* Dummy op - must do something useless after P_LVL3 | ||
229 | * read */ | ||
230 | t = inl(acpi_gbl_FADT.xpm_timer_block.address); | ||
231 | } | ||
232 | longhaul.bits.EnableSoftVID = 0; | ||
233 | wrmsrl(MSR_VIA_LONGHAUL, longhaul.val); | ||
234 | } | ||
235 | } | ||
236 | |||
237 | /** | ||
238 | * longhaul_set_cpu_frequency() | ||
239 | * @mults_index : bitpattern of the new multiplier. | ||
240 | * | ||
241 | * Sets a new clock ratio. | ||
242 | */ | ||
243 | |||
244 | static void longhaul_setstate(unsigned int table_index) | ||
245 | { | ||
246 | unsigned int mults_index; | ||
247 | int speed, mult; | ||
248 | struct cpufreq_freqs freqs; | ||
249 | unsigned long flags; | ||
250 | unsigned int pic1_mask, pic2_mask; | ||
251 | u16 bm_status = 0; | ||
252 | u32 bm_timeout = 1000; | ||
253 | unsigned int dir = 0; | ||
254 | |||
255 | mults_index = longhaul_table[table_index].index; | ||
256 | /* Safety precautions */ | ||
257 | mult = mults[mults_index & 0x1f]; | ||
258 | if (mult == -1) | ||
259 | return; | ||
260 | speed = calc_speed(mult); | ||
261 | if ((speed > highest_speed) || (speed < lowest_speed)) | ||
262 | return; | ||
263 | /* Voltage transition before frequency transition? */ | ||
264 | if (can_scale_voltage && longhaul_index < table_index) | ||
265 | dir = 1; | ||
266 | |||
267 | freqs.old = calc_speed(longhaul_get_cpu_mult()); | ||
268 | freqs.new = speed; | ||
269 | freqs.cpu = 0; /* longhaul.c is UP only driver */ | ||
270 | |||
271 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
272 | |||
273 | pr_debug("Setting to FSB:%dMHz Mult:%d.%dx (%s)\n", | ||
274 | fsb, mult/10, mult%10, print_speed(speed/1000)); | ||
275 | retry_loop: | ||
276 | preempt_disable(); | ||
277 | local_irq_save(flags); | ||
278 | |||
279 | pic2_mask = inb(0xA1); | ||
280 | pic1_mask = inb(0x21); /* works on C3. save mask. */ | ||
281 | outb(0xFF, 0xA1); /* Overkill */ | ||
282 | outb(0xFE, 0x21); /* TMR0 only */ | ||
283 | |||
284 | /* Wait while PCI bus is busy. */ | ||
285 | if (acpi_regs_addr && (longhaul_flags & USE_NORTHBRIDGE | ||
286 | || ((pr != NULL) && pr->flags.bm_control))) { | ||
287 | bm_status = inw(acpi_regs_addr); | ||
288 | bm_status &= 1 << 4; | ||
289 | while (bm_status && bm_timeout) { | ||
290 | outw(1 << 4, acpi_regs_addr); | ||
291 | bm_timeout--; | ||
292 | bm_status = inw(acpi_regs_addr); | ||
293 | bm_status &= 1 << 4; | ||
294 | } | ||
295 | } | ||
296 | |||
297 | if (longhaul_flags & USE_NORTHBRIDGE) { | ||
298 | /* Disable AGP and PCI arbiters */ | ||
299 | outb(3, 0x22); | ||
300 | } else if ((pr != NULL) && pr->flags.bm_control) { | ||
301 | /* Disable bus master arbitration */ | ||
302 | acpi_write_bit_register(ACPI_BITREG_ARB_DISABLE, 1); | ||
303 | } | ||
304 | switch (longhaul_version) { | ||
305 | |||
306 | /* | ||
307 | * Longhaul v1. (Samuel[C5A] and Samuel2 stepping 0[C5B]) | ||
308 | * Software controlled multipliers only. | ||
309 | */ | ||
310 | case TYPE_LONGHAUL_V1: | ||
311 | do_longhaul1(mults_index); | ||
312 | break; | ||
313 | |||
314 | /* | ||
315 | * Longhaul v2 appears in Samuel2 Steppings 1->7 [C5B] and Ezra [C5C] | ||
316 | * | ||
317 | * Longhaul v3 (aka Powersaver). (Ezra-T [C5M] & Nehemiah [C5N]) | ||
318 | * Nehemiah can do FSB scaling too, but this has never been proven | ||
319 | * to work in practice. | ||
320 | */ | ||
321 | case TYPE_LONGHAUL_V2: | ||
322 | case TYPE_POWERSAVER: | ||
323 | if (longhaul_flags & USE_ACPI_C3) { | ||
324 | /* Don't allow wakeup */ | ||
325 | acpi_write_bit_register(ACPI_BITREG_BUS_MASTER_RLD, 0); | ||
326 | do_powersaver(cx->address, mults_index, dir); | ||
327 | } else { | ||
328 | do_powersaver(0, mults_index, dir); | ||
329 | } | ||
330 | break; | ||
331 | } | ||
332 | |||
333 | if (longhaul_flags & USE_NORTHBRIDGE) { | ||
334 | /* Enable arbiters */ | ||
335 | outb(0, 0x22); | ||
336 | } else if ((pr != NULL) && pr->flags.bm_control) { | ||
337 | /* Enable bus master arbitration */ | ||
338 | acpi_write_bit_register(ACPI_BITREG_ARB_DISABLE, 0); | ||
339 | } | ||
340 | outb(pic2_mask, 0xA1); /* restore mask */ | ||
341 | outb(pic1_mask, 0x21); | ||
342 | |||
343 | local_irq_restore(flags); | ||
344 | preempt_enable(); | ||
345 | |||
346 | freqs.new = calc_speed(longhaul_get_cpu_mult()); | ||
347 | /* Check if requested frequency is set. */ | ||
348 | if (unlikely(freqs.new != speed)) { | ||
349 | printk(KERN_INFO PFX "Failed to set requested frequency!\n"); | ||
350 | /* Revision ID = 1 but processor is expecting revision key | ||
351 | * equal to 0. Jumpers at the bottom of processor will change | ||
352 | * multiplier and FSB, but will not change bits in Longhaul | ||
353 | * MSR nor enable voltage scaling. */ | ||
354 | if (!revid_errata) { | ||
355 | printk(KERN_INFO PFX "Enabling \"Ignore Revision ID\" " | ||
356 | "option.\n"); | ||
357 | revid_errata = 1; | ||
358 | msleep(200); | ||
359 | goto retry_loop; | ||
360 | } | ||
361 | /* Why ACPI C3 sometimes doesn't work is a mystery for me. | ||
362 | * But it does happen. Processor is entering ACPI C3 state, | ||
363 | * but it doesn't change frequency. I tried poking various | ||
364 | * bits in northbridge registers, but without success. */ | ||
365 | if (longhaul_flags & USE_ACPI_C3) { | ||
366 | printk(KERN_INFO PFX "Disabling ACPI C3 support.\n"); | ||
367 | longhaul_flags &= ~USE_ACPI_C3; | ||
368 | if (revid_errata) { | ||
369 | printk(KERN_INFO PFX "Disabling \"Ignore " | ||
370 | "Revision ID\" option.\n"); | ||
371 | revid_errata = 0; | ||
372 | } | ||
373 | msleep(200); | ||
374 | goto retry_loop; | ||
375 | } | ||
376 | /* This shouldn't happen. Longhaul ver. 2 was reported not | ||
377 | * working on processors without voltage scaling, but with | ||
378 | * RevID = 1. RevID errata will make things right. Just | ||
379 | * to be 100% sure. */ | ||
380 | if (longhaul_version == TYPE_LONGHAUL_V2) { | ||
381 | printk(KERN_INFO PFX "Switching to Longhaul ver. 1\n"); | ||
382 | longhaul_version = TYPE_LONGHAUL_V1; | ||
383 | msleep(200); | ||
384 | goto retry_loop; | ||
385 | } | ||
386 | } | ||
387 | /* Report true CPU frequency */ | ||
388 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
389 | |||
390 | if (!bm_timeout) | ||
391 | printk(KERN_INFO PFX "Warning: Timeout while waiting for " | ||
392 | "idle PCI bus.\n"); | ||
393 | } | ||
394 | |||
395 | /* | ||
396 | * Centaur decided to make life a little more tricky. | ||
397 | * Only longhaul v1 is allowed to read EBLCR BSEL[0:1]. | ||
398 | * Samuel2 and above have to try and guess what the FSB is. | ||
399 | * We do this by assuming we booted at maximum multiplier, and interpolate | ||
400 | * between that value multiplied by possible FSBs and cpu_mhz which | ||
401 | * was calculated at boot time. Really ugly, but no other way to do this. | ||
402 | */ | ||
403 | |||
404 | #define ROUNDING 0xf | ||
405 | |||
406 | static int guess_fsb(int mult) | ||
407 | { | ||
408 | int speed = cpu_khz / 1000; | ||
409 | int i; | ||
410 | int speeds[] = { 666, 1000, 1333, 2000 }; | ||
411 | int f_max, f_min; | ||
412 | |||
413 | for (i = 0; i < 4; i++) { | ||
414 | f_max = ((speeds[i] * mult) + 50) / 100; | ||
415 | f_max += (ROUNDING / 2); | ||
416 | f_min = f_max - ROUNDING; | ||
417 | if ((speed <= f_max) && (speed >= f_min)) | ||
418 | return speeds[i] / 10; | ||
419 | } | ||
420 | return 0; | ||
421 | } | ||
422 | |||
423 | |||
424 | static int __cpuinit longhaul_get_ranges(void) | ||
425 | { | ||
426 | unsigned int i, j, k = 0; | ||
427 | unsigned int ratio; | ||
428 | int mult; | ||
429 | |||
430 | /* Get current frequency */ | ||
431 | mult = longhaul_get_cpu_mult(); | ||
432 | if (mult == -1) { | ||
433 | printk(KERN_INFO PFX "Invalid (reserved) multiplier!\n"); | ||
434 | return -EINVAL; | ||
435 | } | ||
436 | fsb = guess_fsb(mult); | ||
437 | if (fsb == 0) { | ||
438 | printk(KERN_INFO PFX "Invalid (reserved) FSB!\n"); | ||
439 | return -EINVAL; | ||
440 | } | ||
441 | /* Get max multiplier - as we always did. | ||
442 | * Longhaul MSR is useful only when voltage scaling is enabled. | ||
443 | * C3 is booting at max anyway. */ | ||
444 | maxmult = mult; | ||
445 | /* Get min multiplier */ | ||
446 | switch (cpu_model) { | ||
447 | case CPU_NEHEMIAH: | ||
448 | minmult = 50; | ||
449 | break; | ||
450 | case CPU_NEHEMIAH_C: | ||
451 | minmult = 40; | ||
452 | break; | ||
453 | default: | ||
454 | minmult = 30; | ||
455 | break; | ||
456 | } | ||
457 | |||
458 | pr_debug("MinMult:%d.%dx MaxMult:%d.%dx\n", | ||
459 | minmult/10, minmult%10, maxmult/10, maxmult%10); | ||
460 | |||
461 | highest_speed = calc_speed(maxmult); | ||
462 | lowest_speed = calc_speed(minmult); | ||
463 | pr_debug("FSB:%dMHz Lowest speed: %s Highest speed:%s\n", fsb, | ||
464 | print_speed(lowest_speed/1000), | ||
465 | print_speed(highest_speed/1000)); | ||
466 | |||
467 | if (lowest_speed == highest_speed) { | ||
468 | printk(KERN_INFO PFX "highestspeed == lowest, aborting.\n"); | ||
469 | return -EINVAL; | ||
470 | } | ||
471 | if (lowest_speed > highest_speed) { | ||
472 | printk(KERN_INFO PFX "nonsense! lowest (%d > %d) !\n", | ||
473 | lowest_speed, highest_speed); | ||
474 | return -EINVAL; | ||
475 | } | ||
476 | |||
477 | longhaul_table = kmalloc((numscales + 1) * sizeof(*longhaul_table), | ||
478 | GFP_KERNEL); | ||
479 | if (!longhaul_table) | ||
480 | return -ENOMEM; | ||
481 | |||
482 | for (j = 0; j < numscales; j++) { | ||
483 | ratio = mults[j]; | ||
484 | if (ratio == -1) | ||
485 | continue; | ||
486 | if (ratio > maxmult || ratio < minmult) | ||
487 | continue; | ||
488 | longhaul_table[k].frequency = calc_speed(ratio); | ||
489 | longhaul_table[k].index = j; | ||
490 | k++; | ||
491 | } | ||
492 | if (k <= 1) { | ||
493 | kfree(longhaul_table); | ||
494 | return -ENODEV; | ||
495 | } | ||
496 | /* Sort */ | ||
497 | for (j = 0; j < k - 1; j++) { | ||
498 | unsigned int min_f, min_i; | ||
499 | min_f = longhaul_table[j].frequency; | ||
500 | min_i = j; | ||
501 | for (i = j + 1; i < k; i++) { | ||
502 | if (longhaul_table[i].frequency < min_f) { | ||
503 | min_f = longhaul_table[i].frequency; | ||
504 | min_i = i; | ||
505 | } | ||
506 | } | ||
507 | if (min_i != j) { | ||
508 | swap(longhaul_table[j].frequency, | ||
509 | longhaul_table[min_i].frequency); | ||
510 | swap(longhaul_table[j].index, | ||
511 | longhaul_table[min_i].index); | ||
512 | } | ||
513 | } | ||
514 | |||
515 | longhaul_table[k].frequency = CPUFREQ_TABLE_END; | ||
516 | |||
517 | /* Find index we are running on */ | ||
518 | for (j = 0; j < k; j++) { | ||
519 | if (mults[longhaul_table[j].index & 0x1f] == mult) { | ||
520 | longhaul_index = j; | ||
521 | break; | ||
522 | } | ||
523 | } | ||
524 | return 0; | ||
525 | } | ||
526 | |||
527 | |||
528 | static void __cpuinit longhaul_setup_voltagescaling(void) | ||
529 | { | ||
530 | union msr_longhaul longhaul; | ||
531 | struct mV_pos minvid, maxvid, vid; | ||
532 | unsigned int j, speed, pos, kHz_step, numvscales; | ||
533 | int min_vid_speed; | ||
534 | |||
535 | rdmsrl(MSR_VIA_LONGHAUL, longhaul.val); | ||
536 | if (!(longhaul.bits.RevisionID & 1)) { | ||
537 | printk(KERN_INFO PFX "Voltage scaling not supported by CPU.\n"); | ||
538 | return; | ||
539 | } | ||
540 | |||
541 | if (!longhaul.bits.VRMRev) { | ||
542 | printk(KERN_INFO PFX "VRM 8.5\n"); | ||
543 | vrm_mV_table = &vrm85_mV[0]; | ||
544 | mV_vrm_table = &mV_vrm85[0]; | ||
545 | } else { | ||
546 | printk(KERN_INFO PFX "Mobile VRM\n"); | ||
547 | if (cpu_model < CPU_NEHEMIAH) | ||
548 | return; | ||
549 | vrm_mV_table = &mobilevrm_mV[0]; | ||
550 | mV_vrm_table = &mV_mobilevrm[0]; | ||
551 | } | ||
552 | |||
553 | minvid = vrm_mV_table[longhaul.bits.MinimumVID]; | ||
554 | maxvid = vrm_mV_table[longhaul.bits.MaximumVID]; | ||
555 | |||
556 | if (minvid.mV == 0 || maxvid.mV == 0 || minvid.mV > maxvid.mV) { | ||
557 | printk(KERN_INFO PFX "Bogus values Min:%d.%03d Max:%d.%03d. " | ||
558 | "Voltage scaling disabled.\n", | ||
559 | minvid.mV/1000, minvid.mV%1000, | ||
560 | maxvid.mV/1000, maxvid.mV%1000); | ||
561 | return; | ||
562 | } | ||
563 | |||
564 | if (minvid.mV == maxvid.mV) { | ||
565 | printk(KERN_INFO PFX "Claims to support voltage scaling but " | ||
566 | "min & max are both %d.%03d. " | ||
567 | "Voltage scaling disabled\n", | ||
568 | maxvid.mV/1000, maxvid.mV%1000); | ||
569 | return; | ||
570 | } | ||
571 | |||
572 | /* How many voltage steps*/ | ||
573 | numvscales = maxvid.pos - minvid.pos + 1; | ||
574 | printk(KERN_INFO PFX | ||
575 | "Max VID=%d.%03d " | ||
576 | "Min VID=%d.%03d, " | ||
577 | "%d possible voltage scales\n", | ||
578 | maxvid.mV/1000, maxvid.mV%1000, | ||
579 | minvid.mV/1000, minvid.mV%1000, | ||
580 | numvscales); | ||
581 | |||
582 | /* Calculate max frequency at min voltage */ | ||
583 | j = longhaul.bits.MinMHzBR; | ||
584 | if (longhaul.bits.MinMHzBR4) | ||
585 | j += 16; | ||
586 | min_vid_speed = eblcr[j]; | ||
587 | if (min_vid_speed == -1) | ||
588 | return; | ||
589 | switch (longhaul.bits.MinMHzFSB) { | ||
590 | case 0: | ||
591 | min_vid_speed *= 13333; | ||
592 | break; | ||
593 | case 1: | ||
594 | min_vid_speed *= 10000; | ||
595 | break; | ||
596 | case 3: | ||
597 | min_vid_speed *= 6666; | ||
598 | break; | ||
599 | default: | ||
600 | return; | ||
601 | break; | ||
602 | } | ||
603 | if (min_vid_speed >= highest_speed) | ||
604 | return; | ||
605 | /* Calculate kHz for one voltage step */ | ||
606 | kHz_step = (highest_speed - min_vid_speed) / numvscales; | ||
607 | |||
608 | j = 0; | ||
609 | while (longhaul_table[j].frequency != CPUFREQ_TABLE_END) { | ||
610 | speed = longhaul_table[j].frequency; | ||
611 | if (speed > min_vid_speed) | ||
612 | pos = (speed - min_vid_speed) / kHz_step + minvid.pos; | ||
613 | else | ||
614 | pos = minvid.pos; | ||
615 | longhaul_table[j].index |= mV_vrm_table[pos] << 8; | ||
616 | vid = vrm_mV_table[mV_vrm_table[pos]]; | ||
617 | printk(KERN_INFO PFX "f: %d kHz, index: %d, vid: %d mV\n", | ||
618 | speed, j, vid.mV); | ||
619 | j++; | ||
620 | } | ||
621 | |||
622 | can_scale_voltage = 1; | ||
623 | printk(KERN_INFO PFX "Voltage scaling enabled.\n"); | ||
624 | } | ||
625 | |||
626 | |||
627 | static int longhaul_verify(struct cpufreq_policy *policy) | ||
628 | { | ||
629 | return cpufreq_frequency_table_verify(policy, longhaul_table); | ||
630 | } | ||
631 | |||
632 | |||
633 | static int longhaul_target(struct cpufreq_policy *policy, | ||
634 | unsigned int target_freq, unsigned int relation) | ||
635 | { | ||
636 | unsigned int table_index = 0; | ||
637 | unsigned int i; | ||
638 | unsigned int dir = 0; | ||
639 | u8 vid, current_vid; | ||
640 | |||
641 | if (cpufreq_frequency_table_target(policy, longhaul_table, target_freq, | ||
642 | relation, &table_index)) | ||
643 | return -EINVAL; | ||
644 | |||
645 | /* Don't set same frequency again */ | ||
646 | if (longhaul_index == table_index) | ||
647 | return 0; | ||
648 | |||
649 | if (!can_scale_voltage) | ||
650 | longhaul_setstate(table_index); | ||
651 | else { | ||
652 | /* On test system voltage transitions exceeding single | ||
653 | * step up or down were turning motherboard off. Both | ||
654 | * "ondemand" and "userspace" are unsafe. C7 is doing | ||
655 | * this in hardware, C3 is old and we need to do this | ||
656 | * in software. */ | ||
657 | i = longhaul_index; | ||
658 | current_vid = (longhaul_table[longhaul_index].index >> 8); | ||
659 | current_vid &= 0x1f; | ||
660 | if (table_index > longhaul_index) | ||
661 | dir = 1; | ||
662 | while (i != table_index) { | ||
663 | vid = (longhaul_table[i].index >> 8) & 0x1f; | ||
664 | if (vid != current_vid) { | ||
665 | longhaul_setstate(i); | ||
666 | current_vid = vid; | ||
667 | msleep(200); | ||
668 | } | ||
669 | if (dir) | ||
670 | i++; | ||
671 | else | ||
672 | i--; | ||
673 | } | ||
674 | longhaul_setstate(table_index); | ||
675 | } | ||
676 | longhaul_index = table_index; | ||
677 | return 0; | ||
678 | } | ||
679 | |||
680 | |||
681 | static unsigned int longhaul_get(unsigned int cpu) | ||
682 | { | ||
683 | if (cpu) | ||
684 | return 0; | ||
685 | return calc_speed(longhaul_get_cpu_mult()); | ||
686 | } | ||
687 | |||
688 | static acpi_status longhaul_walk_callback(acpi_handle obj_handle, | ||
689 | u32 nesting_level, | ||
690 | void *context, void **return_value) | ||
691 | { | ||
692 | struct acpi_device *d; | ||
693 | |||
694 | if (acpi_bus_get_device(obj_handle, &d)) | ||
695 | return 0; | ||
696 | |||
697 | *return_value = acpi_driver_data(d); | ||
698 | return 1; | ||
699 | } | ||
700 | |||
701 | /* VIA don't support PM2 reg, but have something similar */ | ||
702 | static int enable_arbiter_disable(void) | ||
703 | { | ||
704 | struct pci_dev *dev; | ||
705 | int status = 1; | ||
706 | int reg; | ||
707 | u8 pci_cmd; | ||
708 | |||
709 | /* Find PLE133 host bridge */ | ||
710 | reg = 0x78; | ||
711 | dev = pci_get_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8601_0, | ||
712 | NULL); | ||
713 | /* Find PM133/VT8605 host bridge */ | ||
714 | if (dev == NULL) | ||
715 | dev = pci_get_device(PCI_VENDOR_ID_VIA, | ||
716 | PCI_DEVICE_ID_VIA_8605_0, NULL); | ||
717 | /* Find CLE266 host bridge */ | ||
718 | if (dev == NULL) { | ||
719 | reg = 0x76; | ||
720 | dev = pci_get_device(PCI_VENDOR_ID_VIA, | ||
721 | PCI_DEVICE_ID_VIA_862X_0, NULL); | ||
722 | /* Find CN400 V-Link host bridge */ | ||
723 | if (dev == NULL) | ||
724 | dev = pci_get_device(PCI_VENDOR_ID_VIA, 0x7259, NULL); | ||
725 | } | ||
726 | if (dev != NULL) { | ||
727 | /* Enable access to port 0x22 */ | ||
728 | pci_read_config_byte(dev, reg, &pci_cmd); | ||
729 | if (!(pci_cmd & 1<<7)) { | ||
730 | pci_cmd |= 1<<7; | ||
731 | pci_write_config_byte(dev, reg, pci_cmd); | ||
732 | pci_read_config_byte(dev, reg, &pci_cmd); | ||
733 | if (!(pci_cmd & 1<<7)) { | ||
734 | printk(KERN_ERR PFX | ||
735 | "Can't enable access to port 0x22.\n"); | ||
736 | status = 0; | ||
737 | } | ||
738 | } | ||
739 | pci_dev_put(dev); | ||
740 | return status; | ||
741 | } | ||
742 | return 0; | ||
743 | } | ||
744 | |||
745 | static int longhaul_setup_southbridge(void) | ||
746 | { | ||
747 | struct pci_dev *dev; | ||
748 | u8 pci_cmd; | ||
749 | |||
750 | /* Find VT8235 southbridge */ | ||
751 | dev = pci_get_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8235, NULL); | ||
752 | if (dev == NULL) | ||
753 | /* Find VT8237 southbridge */ | ||
754 | dev = pci_get_device(PCI_VENDOR_ID_VIA, | ||
755 | PCI_DEVICE_ID_VIA_8237, NULL); | ||
756 | if (dev != NULL) { | ||
757 | /* Set transition time to max */ | ||
758 | pci_read_config_byte(dev, 0xec, &pci_cmd); | ||
759 | pci_cmd &= ~(1 << 2); | ||
760 | pci_write_config_byte(dev, 0xec, pci_cmd); | ||
761 | pci_read_config_byte(dev, 0xe4, &pci_cmd); | ||
762 | pci_cmd &= ~(1 << 7); | ||
763 | pci_write_config_byte(dev, 0xe4, pci_cmd); | ||
764 | pci_read_config_byte(dev, 0xe5, &pci_cmd); | ||
765 | pci_cmd |= 1 << 7; | ||
766 | pci_write_config_byte(dev, 0xe5, pci_cmd); | ||
767 | /* Get address of ACPI registers block*/ | ||
768 | pci_read_config_byte(dev, 0x81, &pci_cmd); | ||
769 | if (pci_cmd & 1 << 7) { | ||
770 | pci_read_config_dword(dev, 0x88, &acpi_regs_addr); | ||
771 | acpi_regs_addr &= 0xff00; | ||
772 | printk(KERN_INFO PFX "ACPI I/O at 0x%x\n", | ||
773 | acpi_regs_addr); | ||
774 | } | ||
775 | |||
776 | pci_dev_put(dev); | ||
777 | return 1; | ||
778 | } | ||
779 | return 0; | ||
780 | } | ||
781 | |||
782 | static int __cpuinit longhaul_cpu_init(struct cpufreq_policy *policy) | ||
783 | { | ||
784 | struct cpuinfo_x86 *c = &cpu_data(0); | ||
785 | char *cpuname = NULL; | ||
786 | int ret; | ||
787 | u32 lo, hi; | ||
788 | |||
789 | /* Check what we have on this motherboard */ | ||
790 | switch (c->x86_model) { | ||
791 | case 6: | ||
792 | cpu_model = CPU_SAMUEL; | ||
793 | cpuname = "C3 'Samuel' [C5A]"; | ||
794 | longhaul_version = TYPE_LONGHAUL_V1; | ||
795 | memcpy(mults, samuel1_mults, sizeof(samuel1_mults)); | ||
796 | memcpy(eblcr, samuel1_eblcr, sizeof(samuel1_eblcr)); | ||
797 | break; | ||
798 | |||
799 | case 7: | ||
800 | switch (c->x86_mask) { | ||
801 | case 0: | ||
802 | longhaul_version = TYPE_LONGHAUL_V1; | ||
803 | cpu_model = CPU_SAMUEL2; | ||
804 | cpuname = "C3 'Samuel 2' [C5B]"; | ||
805 | /* Note, this is not a typo, early Samuel2's had | ||
806 | * Samuel1 ratios. */ | ||
807 | memcpy(mults, samuel1_mults, sizeof(samuel1_mults)); | ||
808 | memcpy(eblcr, samuel2_eblcr, sizeof(samuel2_eblcr)); | ||
809 | break; | ||
810 | case 1 ... 15: | ||
811 | longhaul_version = TYPE_LONGHAUL_V2; | ||
812 | if (c->x86_mask < 8) { | ||
813 | cpu_model = CPU_SAMUEL2; | ||
814 | cpuname = "C3 'Samuel 2' [C5B]"; | ||
815 | } else { | ||
816 | cpu_model = CPU_EZRA; | ||
817 | cpuname = "C3 'Ezra' [C5C]"; | ||
818 | } | ||
819 | memcpy(mults, ezra_mults, sizeof(ezra_mults)); | ||
820 | memcpy(eblcr, ezra_eblcr, sizeof(ezra_eblcr)); | ||
821 | break; | ||
822 | } | ||
823 | break; | ||
824 | |||
825 | case 8: | ||
826 | cpu_model = CPU_EZRA_T; | ||
827 | cpuname = "C3 'Ezra-T' [C5M]"; | ||
828 | longhaul_version = TYPE_POWERSAVER; | ||
829 | numscales = 32; | ||
830 | memcpy(mults, ezrat_mults, sizeof(ezrat_mults)); | ||
831 | memcpy(eblcr, ezrat_eblcr, sizeof(ezrat_eblcr)); | ||
832 | break; | ||
833 | |||
834 | case 9: | ||
835 | longhaul_version = TYPE_POWERSAVER; | ||
836 | numscales = 32; | ||
837 | memcpy(mults, nehemiah_mults, sizeof(nehemiah_mults)); | ||
838 | memcpy(eblcr, nehemiah_eblcr, sizeof(nehemiah_eblcr)); | ||
839 | switch (c->x86_mask) { | ||
840 | case 0 ... 1: | ||
841 | cpu_model = CPU_NEHEMIAH; | ||
842 | cpuname = "C3 'Nehemiah A' [C5XLOE]"; | ||
843 | break; | ||
844 | case 2 ... 4: | ||
845 | cpu_model = CPU_NEHEMIAH; | ||
846 | cpuname = "C3 'Nehemiah B' [C5XLOH]"; | ||
847 | break; | ||
848 | case 5 ... 15: | ||
849 | cpu_model = CPU_NEHEMIAH_C; | ||
850 | cpuname = "C3 'Nehemiah C' [C5P]"; | ||
851 | break; | ||
852 | } | ||
853 | break; | ||
854 | |||
855 | default: | ||
856 | cpuname = "Unknown"; | ||
857 | break; | ||
858 | } | ||
859 | /* Check Longhaul ver. 2 */ | ||
860 | if (longhaul_version == TYPE_LONGHAUL_V2) { | ||
861 | rdmsr(MSR_VIA_LONGHAUL, lo, hi); | ||
862 | if (lo == 0 && hi == 0) | ||
863 | /* Looks like MSR isn't present */ | ||
864 | longhaul_version = TYPE_LONGHAUL_V1; | ||
865 | } | ||
866 | |||
867 | printk(KERN_INFO PFX "VIA %s CPU detected. ", cpuname); | ||
868 | switch (longhaul_version) { | ||
869 | case TYPE_LONGHAUL_V1: | ||
870 | case TYPE_LONGHAUL_V2: | ||
871 | printk(KERN_CONT "Longhaul v%d supported.\n", longhaul_version); | ||
872 | break; | ||
873 | case TYPE_POWERSAVER: | ||
874 | printk(KERN_CONT "Powersaver supported.\n"); | ||
875 | break; | ||
876 | }; | ||
877 | |||
878 | /* Doesn't hurt */ | ||
879 | longhaul_setup_southbridge(); | ||
880 | |||
881 | /* Find ACPI data for processor */ | ||
882 | acpi_walk_namespace(ACPI_TYPE_PROCESSOR, ACPI_ROOT_OBJECT, | ||
883 | ACPI_UINT32_MAX, &longhaul_walk_callback, NULL, | ||
884 | NULL, (void *)&pr); | ||
885 | |||
886 | /* Check ACPI support for C3 state */ | ||
887 | if (pr != NULL && longhaul_version == TYPE_POWERSAVER) { | ||
888 | cx = &pr->power.states[ACPI_STATE_C3]; | ||
889 | if (cx->address > 0 && cx->latency <= 1000) | ||
890 | longhaul_flags |= USE_ACPI_C3; | ||
891 | } | ||
892 | /* Disable if it isn't working */ | ||
893 | if (disable_acpi_c3) | ||
894 | longhaul_flags &= ~USE_ACPI_C3; | ||
895 | /* Check if northbridge is friendly */ | ||
896 | if (enable_arbiter_disable()) | ||
897 | longhaul_flags |= USE_NORTHBRIDGE; | ||
898 | |||
899 | /* Check ACPI support for bus master arbiter disable */ | ||
900 | if (!(longhaul_flags & USE_ACPI_C3 | ||
901 | || longhaul_flags & USE_NORTHBRIDGE) | ||
902 | && ((pr == NULL) || !(pr->flags.bm_control))) { | ||
903 | printk(KERN_ERR PFX | ||
904 | "No ACPI support. Unsupported northbridge.\n"); | ||
905 | return -ENODEV; | ||
906 | } | ||
907 | |||
908 | if (longhaul_flags & USE_NORTHBRIDGE) | ||
909 | printk(KERN_INFO PFX "Using northbridge support.\n"); | ||
910 | if (longhaul_flags & USE_ACPI_C3) | ||
911 | printk(KERN_INFO PFX "Using ACPI support.\n"); | ||
912 | |||
913 | ret = longhaul_get_ranges(); | ||
914 | if (ret != 0) | ||
915 | return ret; | ||
916 | |||
917 | if ((longhaul_version != TYPE_LONGHAUL_V1) && (scale_voltage != 0)) | ||
918 | longhaul_setup_voltagescaling(); | ||
919 | |||
920 | policy->cpuinfo.transition_latency = 200000; /* nsec */ | ||
921 | policy->cur = calc_speed(longhaul_get_cpu_mult()); | ||
922 | |||
923 | ret = cpufreq_frequency_table_cpuinfo(policy, longhaul_table); | ||
924 | if (ret) | ||
925 | return ret; | ||
926 | |||
927 | cpufreq_frequency_table_get_attr(longhaul_table, policy->cpu); | ||
928 | |||
929 | return 0; | ||
930 | } | ||
931 | |||
932 | static int __devexit longhaul_cpu_exit(struct cpufreq_policy *policy) | ||
933 | { | ||
934 | cpufreq_frequency_table_put_attr(policy->cpu); | ||
935 | return 0; | ||
936 | } | ||
937 | |||
938 | static struct freq_attr *longhaul_attr[] = { | ||
939 | &cpufreq_freq_attr_scaling_available_freqs, | ||
940 | NULL, | ||
941 | }; | ||
942 | |||
943 | static struct cpufreq_driver longhaul_driver = { | ||
944 | .verify = longhaul_verify, | ||
945 | .target = longhaul_target, | ||
946 | .get = longhaul_get, | ||
947 | .init = longhaul_cpu_init, | ||
948 | .exit = __devexit_p(longhaul_cpu_exit), | ||
949 | .name = "longhaul", | ||
950 | .owner = THIS_MODULE, | ||
951 | .attr = longhaul_attr, | ||
952 | }; | ||
953 | |||
954 | |||
955 | static int __init longhaul_init(void) | ||
956 | { | ||
957 | struct cpuinfo_x86 *c = &cpu_data(0); | ||
958 | |||
959 | if (c->x86_vendor != X86_VENDOR_CENTAUR || c->x86 != 6) | ||
960 | return -ENODEV; | ||
961 | |||
962 | #ifdef CONFIG_SMP | ||
963 | if (num_online_cpus() > 1) { | ||
964 | printk(KERN_ERR PFX "More than 1 CPU detected, " | ||
965 | "longhaul disabled.\n"); | ||
966 | return -ENODEV; | ||
967 | } | ||
968 | #endif | ||
969 | #ifdef CONFIG_X86_IO_APIC | ||
970 | if (cpu_has_apic) { | ||
971 | printk(KERN_ERR PFX "APIC detected. Longhaul is currently " | ||
972 | "broken in this configuration.\n"); | ||
973 | return -ENODEV; | ||
974 | } | ||
975 | #endif | ||
976 | switch (c->x86_model) { | ||
977 | case 6 ... 9: | ||
978 | return cpufreq_register_driver(&longhaul_driver); | ||
979 | case 10: | ||
980 | printk(KERN_ERR PFX "Use acpi-cpufreq driver for VIA C7\n"); | ||
981 | default: | ||
982 | ; | ||
983 | } | ||
984 | |||
985 | return -ENODEV; | ||
986 | } | ||
987 | |||
988 | |||
989 | static void __exit longhaul_exit(void) | ||
990 | { | ||
991 | int i; | ||
992 | |||
993 | for (i = 0; i < numscales; i++) { | ||
994 | if (mults[i] == maxmult) { | ||
995 | longhaul_setstate(i); | ||
996 | break; | ||
997 | } | ||
998 | } | ||
999 | |||
1000 | cpufreq_unregister_driver(&longhaul_driver); | ||
1001 | kfree(longhaul_table); | ||
1002 | } | ||
1003 | |||
1004 | /* Even if BIOS is exporting ACPI C3 state, and it is used | ||
1005 | * with success when CPU is idle, this state doesn't | ||
1006 | * trigger frequency transition in some cases. */ | ||
1007 | module_param(disable_acpi_c3, int, 0644); | ||
1008 | MODULE_PARM_DESC(disable_acpi_c3, "Don't use ACPI C3 support"); | ||
1009 | /* Change CPU voltage with frequency. Very useful to save | ||
1010 | * power, but most VIA C3 processors aren't supporting it. */ | ||
1011 | module_param(scale_voltage, int, 0644); | ||
1012 | MODULE_PARM_DESC(scale_voltage, "Scale voltage of processor"); | ||
1013 | /* Force revision key to 0 for processors which doesn't | ||
1014 | * support voltage scaling, but are introducing itself as | ||
1015 | * such. */ | ||
1016 | module_param(revid_errata, int, 0644); | ||
1017 | MODULE_PARM_DESC(revid_errata, "Ignore CPU Revision ID"); | ||
1018 | |||
1019 | MODULE_AUTHOR("Dave Jones <davej@redhat.com>"); | ||
1020 | MODULE_DESCRIPTION("Longhaul driver for VIA Cyrix processors."); | ||
1021 | MODULE_LICENSE("GPL"); | ||
1022 | |||
1023 | late_initcall(longhaul_init); | ||
1024 | module_exit(longhaul_exit); | ||
diff --git a/drivers/cpufreq/longhaul.h b/drivers/cpufreq/longhaul.h new file mode 100644 index 000000000000..cbf48fbca881 --- /dev/null +++ b/drivers/cpufreq/longhaul.h | |||
@@ -0,0 +1,353 @@ | |||
1 | /* | ||
2 | * longhaul.h | ||
3 | * (C) 2003 Dave Jones. | ||
4 | * | ||
5 | * Licensed under the terms of the GNU GPL License version 2. | ||
6 | * | ||
7 | * VIA-specific information | ||
8 | */ | ||
9 | |||
10 | union msr_bcr2 { | ||
11 | struct { | ||
12 | unsigned Reseved:19, // 18:0 | ||
13 | ESOFTBF:1, // 19 | ||
14 | Reserved2:3, // 22:20 | ||
15 | CLOCKMUL:4, // 26:23 | ||
16 | Reserved3:5; // 31:27 | ||
17 | } bits; | ||
18 | unsigned long val; | ||
19 | }; | ||
20 | |||
21 | union msr_longhaul { | ||
22 | struct { | ||
23 | unsigned RevisionID:4, // 3:0 | ||
24 | RevisionKey:4, // 7:4 | ||
25 | EnableSoftBusRatio:1, // 8 | ||
26 | EnableSoftVID:1, // 9 | ||
27 | EnableSoftBSEL:1, // 10 | ||
28 | Reserved:3, // 11:13 | ||
29 | SoftBusRatio4:1, // 14 | ||
30 | VRMRev:1, // 15 | ||
31 | SoftBusRatio:4, // 19:16 | ||
32 | SoftVID:5, // 24:20 | ||
33 | Reserved2:3, // 27:25 | ||
34 | SoftBSEL:2, // 29:28 | ||
35 | Reserved3:2, // 31:30 | ||
36 | MaxMHzBR:4, // 35:32 | ||
37 | MaximumVID:5, // 40:36 | ||
38 | MaxMHzFSB:2, // 42:41 | ||
39 | MaxMHzBR4:1, // 43 | ||
40 | Reserved4:4, // 47:44 | ||
41 | MinMHzBR:4, // 51:48 | ||
42 | MinimumVID:5, // 56:52 | ||
43 | MinMHzFSB:2, // 58:57 | ||
44 | MinMHzBR4:1, // 59 | ||
45 | Reserved5:4; // 63:60 | ||
46 | } bits; | ||
47 | unsigned long long val; | ||
48 | }; | ||
49 | |||
50 | /* | ||
51 | * Clock ratio tables. Div/Mod by 10 to get ratio. | ||
52 | * The eblcr values specify the ratio read from the CPU. | ||
53 | * The mults values specify what to write to the CPU. | ||
54 | */ | ||
55 | |||
56 | /* | ||
57 | * VIA C3 Samuel 1 & Samuel 2 (stepping 0) | ||
58 | */ | ||
59 | static const int __cpuinitdata samuel1_mults[16] = { | ||
60 | -1, /* 0000 -> RESERVED */ | ||
61 | 30, /* 0001 -> 3.0x */ | ||
62 | 40, /* 0010 -> 4.0x */ | ||
63 | -1, /* 0011 -> RESERVED */ | ||
64 | -1, /* 0100 -> RESERVED */ | ||
65 | 35, /* 0101 -> 3.5x */ | ||
66 | 45, /* 0110 -> 4.5x */ | ||
67 | 55, /* 0111 -> 5.5x */ | ||
68 | 60, /* 1000 -> 6.0x */ | ||
69 | 70, /* 1001 -> 7.0x */ | ||
70 | 80, /* 1010 -> 8.0x */ | ||
71 | 50, /* 1011 -> 5.0x */ | ||
72 | 65, /* 1100 -> 6.5x */ | ||
73 | 75, /* 1101 -> 7.5x */ | ||
74 | -1, /* 1110 -> RESERVED */ | ||
75 | -1, /* 1111 -> RESERVED */ | ||
76 | }; | ||
77 | |||
78 | static const int __cpuinitdata samuel1_eblcr[16] = { | ||
79 | 50, /* 0000 -> RESERVED */ | ||
80 | 30, /* 0001 -> 3.0x */ | ||
81 | 40, /* 0010 -> 4.0x */ | ||
82 | -1, /* 0011 -> RESERVED */ | ||
83 | 55, /* 0100 -> 5.5x */ | ||
84 | 35, /* 0101 -> 3.5x */ | ||
85 | 45, /* 0110 -> 4.5x */ | ||
86 | -1, /* 0111 -> RESERVED */ | ||
87 | -1, /* 1000 -> RESERVED */ | ||
88 | 70, /* 1001 -> 7.0x */ | ||
89 | 80, /* 1010 -> 8.0x */ | ||
90 | 60, /* 1011 -> 6.0x */ | ||
91 | -1, /* 1100 -> RESERVED */ | ||
92 | 75, /* 1101 -> 7.5x */ | ||
93 | -1, /* 1110 -> RESERVED */ | ||
94 | 65, /* 1111 -> 6.5x */ | ||
95 | }; | ||
96 | |||
97 | /* | ||
98 | * VIA C3 Samuel2 Stepping 1->15 | ||
99 | */ | ||
100 | static const int __cpuinitdata samuel2_eblcr[16] = { | ||
101 | 50, /* 0000 -> 5.0x */ | ||
102 | 30, /* 0001 -> 3.0x */ | ||
103 | 40, /* 0010 -> 4.0x */ | ||
104 | 100, /* 0011 -> 10.0x */ | ||
105 | 55, /* 0100 -> 5.5x */ | ||
106 | 35, /* 0101 -> 3.5x */ | ||
107 | 45, /* 0110 -> 4.5x */ | ||
108 | 110, /* 0111 -> 11.0x */ | ||
109 | 90, /* 1000 -> 9.0x */ | ||
110 | 70, /* 1001 -> 7.0x */ | ||
111 | 80, /* 1010 -> 8.0x */ | ||
112 | 60, /* 1011 -> 6.0x */ | ||
113 | 120, /* 1100 -> 12.0x */ | ||
114 | 75, /* 1101 -> 7.5x */ | ||
115 | 130, /* 1110 -> 13.0x */ | ||
116 | 65, /* 1111 -> 6.5x */ | ||
117 | }; | ||
118 | |||
119 | /* | ||
120 | * VIA C3 Ezra | ||
121 | */ | ||
122 | static const int __cpuinitdata ezra_mults[16] = { | ||
123 | 100, /* 0000 -> 10.0x */ | ||
124 | 30, /* 0001 -> 3.0x */ | ||
125 | 40, /* 0010 -> 4.0x */ | ||
126 | 90, /* 0011 -> 9.0x */ | ||
127 | 95, /* 0100 -> 9.5x */ | ||
128 | 35, /* 0101 -> 3.5x */ | ||
129 | 45, /* 0110 -> 4.5x */ | ||
130 | 55, /* 0111 -> 5.5x */ | ||
131 | 60, /* 1000 -> 6.0x */ | ||
132 | 70, /* 1001 -> 7.0x */ | ||
133 | 80, /* 1010 -> 8.0x */ | ||
134 | 50, /* 1011 -> 5.0x */ | ||
135 | 65, /* 1100 -> 6.5x */ | ||
136 | 75, /* 1101 -> 7.5x */ | ||
137 | 85, /* 1110 -> 8.5x */ | ||
138 | 120, /* 1111 -> 12.0x */ | ||
139 | }; | ||
140 | |||
141 | static const int __cpuinitdata ezra_eblcr[16] = { | ||
142 | 50, /* 0000 -> 5.0x */ | ||
143 | 30, /* 0001 -> 3.0x */ | ||
144 | 40, /* 0010 -> 4.0x */ | ||
145 | 100, /* 0011 -> 10.0x */ | ||
146 | 55, /* 0100 -> 5.5x */ | ||
147 | 35, /* 0101 -> 3.5x */ | ||
148 | 45, /* 0110 -> 4.5x */ | ||
149 | 95, /* 0111 -> 9.5x */ | ||
150 | 90, /* 1000 -> 9.0x */ | ||
151 | 70, /* 1001 -> 7.0x */ | ||
152 | 80, /* 1010 -> 8.0x */ | ||
153 | 60, /* 1011 -> 6.0x */ | ||
154 | 120, /* 1100 -> 12.0x */ | ||
155 | 75, /* 1101 -> 7.5x */ | ||
156 | 85, /* 1110 -> 8.5x */ | ||
157 | 65, /* 1111 -> 6.5x */ | ||
158 | }; | ||
159 | |||
160 | /* | ||
161 | * VIA C3 (Ezra-T) [C5M]. | ||
162 | */ | ||
163 | static const int __cpuinitdata ezrat_mults[32] = { | ||
164 | 100, /* 0000 -> 10.0x */ | ||
165 | 30, /* 0001 -> 3.0x */ | ||
166 | 40, /* 0010 -> 4.0x */ | ||
167 | 90, /* 0011 -> 9.0x */ | ||
168 | 95, /* 0100 -> 9.5x */ | ||
169 | 35, /* 0101 -> 3.5x */ | ||
170 | 45, /* 0110 -> 4.5x */ | ||
171 | 55, /* 0111 -> 5.5x */ | ||
172 | 60, /* 1000 -> 6.0x */ | ||
173 | 70, /* 1001 -> 7.0x */ | ||
174 | 80, /* 1010 -> 8.0x */ | ||
175 | 50, /* 1011 -> 5.0x */ | ||
176 | 65, /* 1100 -> 6.5x */ | ||
177 | 75, /* 1101 -> 7.5x */ | ||
178 | 85, /* 1110 -> 8.5x */ | ||
179 | 120, /* 1111 -> 12.0x */ | ||
180 | |||
181 | -1, /* 0000 -> RESERVED (10.0x) */ | ||
182 | 110, /* 0001 -> 11.0x */ | ||
183 | -1, /* 0010 -> 12.0x */ | ||
184 | -1, /* 0011 -> RESERVED (9.0x)*/ | ||
185 | 105, /* 0100 -> 10.5x */ | ||
186 | 115, /* 0101 -> 11.5x */ | ||
187 | 125, /* 0110 -> 12.5x */ | ||
188 | 135, /* 0111 -> 13.5x */ | ||
189 | 140, /* 1000 -> 14.0x */ | ||
190 | 150, /* 1001 -> 15.0x */ | ||
191 | 160, /* 1010 -> 16.0x */ | ||
192 | 130, /* 1011 -> 13.0x */ | ||
193 | 145, /* 1100 -> 14.5x */ | ||
194 | 155, /* 1101 -> 15.5x */ | ||
195 | -1, /* 1110 -> RESERVED (13.0x) */ | ||
196 | -1, /* 1111 -> RESERVED (12.0x) */ | ||
197 | }; | ||
198 | |||
199 | static const int __cpuinitdata ezrat_eblcr[32] = { | ||
200 | 50, /* 0000 -> 5.0x */ | ||
201 | 30, /* 0001 -> 3.0x */ | ||
202 | 40, /* 0010 -> 4.0x */ | ||
203 | 100, /* 0011 -> 10.0x */ | ||
204 | 55, /* 0100 -> 5.5x */ | ||
205 | 35, /* 0101 -> 3.5x */ | ||
206 | 45, /* 0110 -> 4.5x */ | ||
207 | 95, /* 0111 -> 9.5x */ | ||
208 | 90, /* 1000 -> 9.0x */ | ||
209 | 70, /* 1001 -> 7.0x */ | ||
210 | 80, /* 1010 -> 8.0x */ | ||
211 | 60, /* 1011 -> 6.0x */ | ||
212 | 120, /* 1100 -> 12.0x */ | ||
213 | 75, /* 1101 -> 7.5x */ | ||
214 | 85, /* 1110 -> 8.5x */ | ||
215 | 65, /* 1111 -> 6.5x */ | ||
216 | |||
217 | -1, /* 0000 -> RESERVED (9.0x) */ | ||
218 | 110, /* 0001 -> 11.0x */ | ||
219 | 120, /* 0010 -> 12.0x */ | ||
220 | -1, /* 0011 -> RESERVED (10.0x)*/ | ||
221 | 135, /* 0100 -> 13.5x */ | ||
222 | 115, /* 0101 -> 11.5x */ | ||
223 | 125, /* 0110 -> 12.5x */ | ||
224 | 105, /* 0111 -> 10.5x */ | ||
225 | 130, /* 1000 -> 13.0x */ | ||
226 | 150, /* 1001 -> 15.0x */ | ||
227 | 160, /* 1010 -> 16.0x */ | ||
228 | 140, /* 1011 -> 14.0x */ | ||
229 | -1, /* 1100 -> RESERVED (12.0x) */ | ||
230 | 155, /* 1101 -> 15.5x */ | ||
231 | -1, /* 1110 -> RESERVED (13.0x) */ | ||
232 | 145, /* 1111 -> 14.5x */ | ||
233 | }; | ||
234 | |||
235 | /* | ||
236 | * VIA C3 Nehemiah */ | ||
237 | |||
238 | static const int __cpuinitdata nehemiah_mults[32] = { | ||
239 | 100, /* 0000 -> 10.0x */ | ||
240 | -1, /* 0001 -> 16.0x */ | ||
241 | 40, /* 0010 -> 4.0x */ | ||
242 | 90, /* 0011 -> 9.0x */ | ||
243 | 95, /* 0100 -> 9.5x */ | ||
244 | -1, /* 0101 -> RESERVED */ | ||
245 | 45, /* 0110 -> 4.5x */ | ||
246 | 55, /* 0111 -> 5.5x */ | ||
247 | 60, /* 1000 -> 6.0x */ | ||
248 | 70, /* 1001 -> 7.0x */ | ||
249 | 80, /* 1010 -> 8.0x */ | ||
250 | 50, /* 1011 -> 5.0x */ | ||
251 | 65, /* 1100 -> 6.5x */ | ||
252 | 75, /* 1101 -> 7.5x */ | ||
253 | 85, /* 1110 -> 8.5x */ | ||
254 | 120, /* 1111 -> 12.0x */ | ||
255 | -1, /* 0000 -> 10.0x */ | ||
256 | 110, /* 0001 -> 11.0x */ | ||
257 | -1, /* 0010 -> 12.0x */ | ||
258 | -1, /* 0011 -> 9.0x */ | ||
259 | 105, /* 0100 -> 10.5x */ | ||
260 | 115, /* 0101 -> 11.5x */ | ||
261 | 125, /* 0110 -> 12.5x */ | ||
262 | 135, /* 0111 -> 13.5x */ | ||
263 | 140, /* 1000 -> 14.0x */ | ||
264 | 150, /* 1001 -> 15.0x */ | ||
265 | 160, /* 1010 -> 16.0x */ | ||
266 | 130, /* 1011 -> 13.0x */ | ||
267 | 145, /* 1100 -> 14.5x */ | ||
268 | 155, /* 1101 -> 15.5x */ | ||
269 | -1, /* 1110 -> RESERVED (13.0x) */ | ||
270 | -1, /* 1111 -> 12.0x */ | ||
271 | }; | ||
272 | |||
273 | static const int __cpuinitdata nehemiah_eblcr[32] = { | ||
274 | 50, /* 0000 -> 5.0x */ | ||
275 | 160, /* 0001 -> 16.0x */ | ||
276 | 40, /* 0010 -> 4.0x */ | ||
277 | 100, /* 0011 -> 10.0x */ | ||
278 | 55, /* 0100 -> 5.5x */ | ||
279 | -1, /* 0101 -> RESERVED */ | ||
280 | 45, /* 0110 -> 4.5x */ | ||
281 | 95, /* 0111 -> 9.5x */ | ||
282 | 90, /* 1000 -> 9.0x */ | ||
283 | 70, /* 1001 -> 7.0x */ | ||
284 | 80, /* 1010 -> 8.0x */ | ||
285 | 60, /* 1011 -> 6.0x */ | ||
286 | 120, /* 1100 -> 12.0x */ | ||
287 | 75, /* 1101 -> 7.5x */ | ||
288 | 85, /* 1110 -> 8.5x */ | ||
289 | 65, /* 1111 -> 6.5x */ | ||
290 | 90, /* 0000 -> 9.0x */ | ||
291 | 110, /* 0001 -> 11.0x */ | ||
292 | 120, /* 0010 -> 12.0x */ | ||
293 | 100, /* 0011 -> 10.0x */ | ||
294 | 135, /* 0100 -> 13.5x */ | ||
295 | 115, /* 0101 -> 11.5x */ | ||
296 | 125, /* 0110 -> 12.5x */ | ||
297 | 105, /* 0111 -> 10.5x */ | ||
298 | 130, /* 1000 -> 13.0x */ | ||
299 | 150, /* 1001 -> 15.0x */ | ||
300 | 160, /* 1010 -> 16.0x */ | ||
301 | 140, /* 1011 -> 14.0x */ | ||
302 | 120, /* 1100 -> 12.0x */ | ||
303 | 155, /* 1101 -> 15.5x */ | ||
304 | -1, /* 1110 -> RESERVED (13.0x) */ | ||
305 | 145 /* 1111 -> 14.5x */ | ||
306 | }; | ||
307 | |||
308 | /* | ||
309 | * Voltage scales. Div/Mod by 1000 to get actual voltage. | ||
310 | * Which scale to use depends on the VRM type in use. | ||
311 | */ | ||
312 | |||
313 | struct mV_pos { | ||
314 | unsigned short mV; | ||
315 | unsigned short pos; | ||
316 | }; | ||
317 | |||
318 | static const struct mV_pos __cpuinitdata vrm85_mV[32] = { | ||
319 | {1250, 8}, {1200, 6}, {1150, 4}, {1100, 2}, | ||
320 | {1050, 0}, {1800, 30}, {1750, 28}, {1700, 26}, | ||
321 | {1650, 24}, {1600, 22}, {1550, 20}, {1500, 18}, | ||
322 | {1450, 16}, {1400, 14}, {1350, 12}, {1300, 10}, | ||
323 | {1275, 9}, {1225, 7}, {1175, 5}, {1125, 3}, | ||
324 | {1075, 1}, {1825, 31}, {1775, 29}, {1725, 27}, | ||
325 | {1675, 25}, {1625, 23}, {1575, 21}, {1525, 19}, | ||
326 | {1475, 17}, {1425, 15}, {1375, 13}, {1325, 11} | ||
327 | }; | ||
328 | |||
329 | static const unsigned char __cpuinitdata mV_vrm85[32] = { | ||
330 | 0x04, 0x14, 0x03, 0x13, 0x02, 0x12, 0x01, 0x11, | ||
331 | 0x00, 0x10, 0x0f, 0x1f, 0x0e, 0x1e, 0x0d, 0x1d, | ||
332 | 0x0c, 0x1c, 0x0b, 0x1b, 0x0a, 0x1a, 0x09, 0x19, | ||
333 | 0x08, 0x18, 0x07, 0x17, 0x06, 0x16, 0x05, 0x15 | ||
334 | }; | ||
335 | |||
336 | static const struct mV_pos __cpuinitdata mobilevrm_mV[32] = { | ||
337 | {1750, 31}, {1700, 30}, {1650, 29}, {1600, 28}, | ||
338 | {1550, 27}, {1500, 26}, {1450, 25}, {1400, 24}, | ||
339 | {1350, 23}, {1300, 22}, {1250, 21}, {1200, 20}, | ||
340 | {1150, 19}, {1100, 18}, {1050, 17}, {1000, 16}, | ||
341 | {975, 15}, {950, 14}, {925, 13}, {900, 12}, | ||
342 | {875, 11}, {850, 10}, {825, 9}, {800, 8}, | ||
343 | {775, 7}, {750, 6}, {725, 5}, {700, 4}, | ||
344 | {675, 3}, {650, 2}, {625, 1}, {600, 0} | ||
345 | }; | ||
346 | |||
347 | static const unsigned char __cpuinitdata mV_mobilevrm[32] = { | ||
348 | 0x1f, 0x1e, 0x1d, 0x1c, 0x1b, 0x1a, 0x19, 0x18, | ||
349 | 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, | ||
350 | 0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08, | ||
351 | 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00 | ||
352 | }; | ||
353 | |||
diff --git a/drivers/cpufreq/longrun.c b/drivers/cpufreq/longrun.c new file mode 100644 index 000000000000..34ea359b370e --- /dev/null +++ b/drivers/cpufreq/longrun.c | |||
@@ -0,0 +1,324 @@ | |||
1 | /* | ||
2 | * (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de> | ||
3 | * | ||
4 | * Licensed under the terms of the GNU GPL License version 2. | ||
5 | * | ||
6 | * BIG FAT DISCLAIMER: Work in progress code. Possibly *dangerous* | ||
7 | */ | ||
8 | |||
9 | #include <linux/kernel.h> | ||
10 | #include <linux/module.h> | ||
11 | #include <linux/init.h> | ||
12 | #include <linux/cpufreq.h> | ||
13 | #include <linux/timex.h> | ||
14 | |||
15 | #include <asm/msr.h> | ||
16 | #include <asm/processor.h> | ||
17 | |||
18 | static struct cpufreq_driver longrun_driver; | ||
19 | |||
20 | /** | ||
21 | * longrun_{low,high}_freq is needed for the conversion of cpufreq kHz | ||
22 | * values into per cent values. In TMTA microcode, the following is valid: | ||
23 | * performance_pctg = (current_freq - low_freq)/(high_freq - low_freq) | ||
24 | */ | ||
25 | static unsigned int longrun_low_freq, longrun_high_freq; | ||
26 | |||
27 | |||
28 | /** | ||
29 | * longrun_get_policy - get the current LongRun policy | ||
30 | * @policy: struct cpufreq_policy where current policy is written into | ||
31 | * | ||
32 | * Reads the current LongRun policy by access to MSR_TMTA_LONGRUN_FLAGS | ||
33 | * and MSR_TMTA_LONGRUN_CTRL | ||
34 | */ | ||
35 | static void __cpuinit longrun_get_policy(struct cpufreq_policy *policy) | ||
36 | { | ||
37 | u32 msr_lo, msr_hi; | ||
38 | |||
39 | rdmsr(MSR_TMTA_LONGRUN_FLAGS, msr_lo, msr_hi); | ||
40 | pr_debug("longrun flags are %x - %x\n", msr_lo, msr_hi); | ||
41 | if (msr_lo & 0x01) | ||
42 | policy->policy = CPUFREQ_POLICY_PERFORMANCE; | ||
43 | else | ||
44 | policy->policy = CPUFREQ_POLICY_POWERSAVE; | ||
45 | |||
46 | rdmsr(MSR_TMTA_LONGRUN_CTRL, msr_lo, msr_hi); | ||
47 | pr_debug("longrun ctrl is %x - %x\n", msr_lo, msr_hi); | ||
48 | msr_lo &= 0x0000007F; | ||
49 | msr_hi &= 0x0000007F; | ||
50 | |||
51 | if (longrun_high_freq <= longrun_low_freq) { | ||
52 | /* Assume degenerate Longrun table */ | ||
53 | policy->min = policy->max = longrun_high_freq; | ||
54 | } else { | ||
55 | policy->min = longrun_low_freq + msr_lo * | ||
56 | ((longrun_high_freq - longrun_low_freq) / 100); | ||
57 | policy->max = longrun_low_freq + msr_hi * | ||
58 | ((longrun_high_freq - longrun_low_freq) / 100); | ||
59 | } | ||
60 | policy->cpu = 0; | ||
61 | } | ||
62 | |||
63 | |||
64 | /** | ||
65 | * longrun_set_policy - sets a new CPUFreq policy | ||
66 | * @policy: new policy | ||
67 | * | ||
68 | * Sets a new CPUFreq policy on LongRun-capable processors. This function | ||
69 | * has to be called with cpufreq_driver locked. | ||
70 | */ | ||
71 | static int longrun_set_policy(struct cpufreq_policy *policy) | ||
72 | { | ||
73 | u32 msr_lo, msr_hi; | ||
74 | u32 pctg_lo, pctg_hi; | ||
75 | |||
76 | if (!policy) | ||
77 | return -EINVAL; | ||
78 | |||
79 | if (longrun_high_freq <= longrun_low_freq) { | ||
80 | /* Assume degenerate Longrun table */ | ||
81 | pctg_lo = pctg_hi = 100; | ||
82 | } else { | ||
83 | pctg_lo = (policy->min - longrun_low_freq) / | ||
84 | ((longrun_high_freq - longrun_low_freq) / 100); | ||
85 | pctg_hi = (policy->max - longrun_low_freq) / | ||
86 | ((longrun_high_freq - longrun_low_freq) / 100); | ||
87 | } | ||
88 | |||
89 | if (pctg_hi > 100) | ||
90 | pctg_hi = 100; | ||
91 | if (pctg_lo > pctg_hi) | ||
92 | pctg_lo = pctg_hi; | ||
93 | |||
94 | /* performance or economy mode */ | ||
95 | rdmsr(MSR_TMTA_LONGRUN_FLAGS, msr_lo, msr_hi); | ||
96 | msr_lo &= 0xFFFFFFFE; | ||
97 | switch (policy->policy) { | ||
98 | case CPUFREQ_POLICY_PERFORMANCE: | ||
99 | msr_lo |= 0x00000001; | ||
100 | break; | ||
101 | case CPUFREQ_POLICY_POWERSAVE: | ||
102 | break; | ||
103 | } | ||
104 | wrmsr(MSR_TMTA_LONGRUN_FLAGS, msr_lo, msr_hi); | ||
105 | |||
106 | /* lower and upper boundary */ | ||
107 | rdmsr(MSR_TMTA_LONGRUN_CTRL, msr_lo, msr_hi); | ||
108 | msr_lo &= 0xFFFFFF80; | ||
109 | msr_hi &= 0xFFFFFF80; | ||
110 | msr_lo |= pctg_lo; | ||
111 | msr_hi |= pctg_hi; | ||
112 | wrmsr(MSR_TMTA_LONGRUN_CTRL, msr_lo, msr_hi); | ||
113 | |||
114 | return 0; | ||
115 | } | ||
116 | |||
117 | |||
118 | /** | ||
119 | * longrun_verify_poliy - verifies a new CPUFreq policy | ||
120 | * @policy: the policy to verify | ||
121 | * | ||
122 | * Validates a new CPUFreq policy. This function has to be called with | ||
123 | * cpufreq_driver locked. | ||
124 | */ | ||
125 | static int longrun_verify_policy(struct cpufreq_policy *policy) | ||
126 | { | ||
127 | if (!policy) | ||
128 | return -EINVAL; | ||
129 | |||
130 | policy->cpu = 0; | ||
131 | cpufreq_verify_within_limits(policy, | ||
132 | policy->cpuinfo.min_freq, | ||
133 | policy->cpuinfo.max_freq); | ||
134 | |||
135 | if ((policy->policy != CPUFREQ_POLICY_POWERSAVE) && | ||
136 | (policy->policy != CPUFREQ_POLICY_PERFORMANCE)) | ||
137 | return -EINVAL; | ||
138 | |||
139 | return 0; | ||
140 | } | ||
141 | |||
142 | static unsigned int longrun_get(unsigned int cpu) | ||
143 | { | ||
144 | u32 eax, ebx, ecx, edx; | ||
145 | |||
146 | if (cpu) | ||
147 | return 0; | ||
148 | |||
149 | cpuid(0x80860007, &eax, &ebx, &ecx, &edx); | ||
150 | pr_debug("cpuid eax is %u\n", eax); | ||
151 | |||
152 | return eax * 1000; | ||
153 | } | ||
154 | |||
155 | /** | ||
156 | * longrun_determine_freqs - determines the lowest and highest possible core frequency | ||
157 | * @low_freq: an int to put the lowest frequency into | ||
158 | * @high_freq: an int to put the highest frequency into | ||
159 | * | ||
160 | * Determines the lowest and highest possible core frequencies on this CPU. | ||
161 | * This is necessary to calculate the performance percentage according to | ||
162 | * TMTA rules: | ||
163 | * performance_pctg = (target_freq - low_freq)/(high_freq - low_freq) | ||
164 | */ | ||
165 | static int __cpuinit longrun_determine_freqs(unsigned int *low_freq, | ||
166 | unsigned int *high_freq) | ||
167 | { | ||
168 | u32 msr_lo, msr_hi; | ||
169 | u32 save_lo, save_hi; | ||
170 | u32 eax, ebx, ecx, edx; | ||
171 | u32 try_hi; | ||
172 | struct cpuinfo_x86 *c = &cpu_data(0); | ||
173 | |||
174 | if (!low_freq || !high_freq) | ||
175 | return -EINVAL; | ||
176 | |||
177 | if (cpu_has(c, X86_FEATURE_LRTI)) { | ||
178 | /* if the LongRun Table Interface is present, the | ||
179 | * detection is a bit easier: | ||
180 | * For minimum frequency, read out the maximum | ||
181 | * level (msr_hi), write that into "currently | ||
182 | * selected level", and read out the frequency. | ||
183 | * For maximum frequency, read out level zero. | ||
184 | */ | ||
185 | /* minimum */ | ||
186 | rdmsr(MSR_TMTA_LRTI_READOUT, msr_lo, msr_hi); | ||
187 | wrmsr(MSR_TMTA_LRTI_READOUT, msr_hi, msr_hi); | ||
188 | rdmsr(MSR_TMTA_LRTI_VOLT_MHZ, msr_lo, msr_hi); | ||
189 | *low_freq = msr_lo * 1000; /* to kHz */ | ||
190 | |||
191 | /* maximum */ | ||
192 | wrmsr(MSR_TMTA_LRTI_READOUT, 0, msr_hi); | ||
193 | rdmsr(MSR_TMTA_LRTI_VOLT_MHZ, msr_lo, msr_hi); | ||
194 | *high_freq = msr_lo * 1000; /* to kHz */ | ||
195 | |||
196 | pr_debug("longrun table interface told %u - %u kHz\n", | ||
197 | *low_freq, *high_freq); | ||
198 | |||
199 | if (*low_freq > *high_freq) | ||
200 | *low_freq = *high_freq; | ||
201 | return 0; | ||
202 | } | ||
203 | |||
204 | /* set the upper border to the value determined during TSC init */ | ||
205 | *high_freq = (cpu_khz / 1000); | ||
206 | *high_freq = *high_freq * 1000; | ||
207 | pr_debug("high frequency is %u kHz\n", *high_freq); | ||
208 | |||
209 | /* get current borders */ | ||
210 | rdmsr(MSR_TMTA_LONGRUN_CTRL, msr_lo, msr_hi); | ||
211 | save_lo = msr_lo & 0x0000007F; | ||
212 | save_hi = msr_hi & 0x0000007F; | ||
213 | |||
214 | /* if current perf_pctg is larger than 90%, we need to decrease the | ||
215 | * upper limit to make the calculation more accurate. | ||
216 | */ | ||
217 | cpuid(0x80860007, &eax, &ebx, &ecx, &edx); | ||
218 | /* try decreasing in 10% steps, some processors react only | ||
219 | * on some barrier values */ | ||
220 | for (try_hi = 80; try_hi > 0 && ecx > 90; try_hi -= 10) { | ||
221 | /* set to 0 to try_hi perf_pctg */ | ||
222 | msr_lo &= 0xFFFFFF80; | ||
223 | msr_hi &= 0xFFFFFF80; | ||
224 | msr_hi |= try_hi; | ||
225 | wrmsr(MSR_TMTA_LONGRUN_CTRL, msr_lo, msr_hi); | ||
226 | |||
227 | /* read out current core MHz and current perf_pctg */ | ||
228 | cpuid(0x80860007, &eax, &ebx, &ecx, &edx); | ||
229 | |||
230 | /* restore values */ | ||
231 | wrmsr(MSR_TMTA_LONGRUN_CTRL, save_lo, save_hi); | ||
232 | } | ||
233 | pr_debug("percentage is %u %%, freq is %u MHz\n", ecx, eax); | ||
234 | |||
235 | /* performance_pctg = (current_freq - low_freq)/(high_freq - low_freq) | ||
236 | * eqals | ||
237 | * low_freq * (1 - perf_pctg) = (cur_freq - high_freq * perf_pctg) | ||
238 | * | ||
239 | * high_freq * perf_pctg is stored tempoarily into "ebx". | ||
240 | */ | ||
241 | ebx = (((cpu_khz / 1000) * ecx) / 100); /* to MHz */ | ||
242 | |||
243 | if ((ecx > 95) || (ecx == 0) || (eax < ebx)) | ||
244 | return -EIO; | ||
245 | |||
246 | edx = ((eax - ebx) * 100) / (100 - ecx); | ||
247 | *low_freq = edx * 1000; /* back to kHz */ | ||
248 | |||
249 | pr_debug("low frequency is %u kHz\n", *low_freq); | ||
250 | |||
251 | if (*low_freq > *high_freq) | ||
252 | *low_freq = *high_freq; | ||
253 | |||
254 | return 0; | ||
255 | } | ||
256 | |||
257 | |||
258 | static int __cpuinit longrun_cpu_init(struct cpufreq_policy *policy) | ||
259 | { | ||
260 | int result = 0; | ||
261 | |||
262 | /* capability check */ | ||
263 | if (policy->cpu != 0) | ||
264 | return -ENODEV; | ||
265 | |||
266 | /* detect low and high frequency */ | ||
267 | result = longrun_determine_freqs(&longrun_low_freq, &longrun_high_freq); | ||
268 | if (result) | ||
269 | return result; | ||
270 | |||
271 | /* cpuinfo and default policy values */ | ||
272 | policy->cpuinfo.min_freq = longrun_low_freq; | ||
273 | policy->cpuinfo.max_freq = longrun_high_freq; | ||
274 | policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL; | ||
275 | longrun_get_policy(policy); | ||
276 | |||
277 | return 0; | ||
278 | } | ||
279 | |||
280 | |||
281 | static struct cpufreq_driver longrun_driver = { | ||
282 | .flags = CPUFREQ_CONST_LOOPS, | ||
283 | .verify = longrun_verify_policy, | ||
284 | .setpolicy = longrun_set_policy, | ||
285 | .get = longrun_get, | ||
286 | .init = longrun_cpu_init, | ||
287 | .name = "longrun", | ||
288 | .owner = THIS_MODULE, | ||
289 | }; | ||
290 | |||
291 | |||
292 | /** | ||
293 | * longrun_init - initializes the Transmeta Crusoe LongRun CPUFreq driver | ||
294 | * | ||
295 | * Initializes the LongRun support. | ||
296 | */ | ||
297 | static int __init longrun_init(void) | ||
298 | { | ||
299 | struct cpuinfo_x86 *c = &cpu_data(0); | ||
300 | |||
301 | if (c->x86_vendor != X86_VENDOR_TRANSMETA || | ||
302 | !cpu_has(c, X86_FEATURE_LONGRUN)) | ||
303 | return -ENODEV; | ||
304 | |||
305 | return cpufreq_register_driver(&longrun_driver); | ||
306 | } | ||
307 | |||
308 | |||
309 | /** | ||
310 | * longrun_exit - unregisters LongRun support | ||
311 | */ | ||
312 | static void __exit longrun_exit(void) | ||
313 | { | ||
314 | cpufreq_unregister_driver(&longrun_driver); | ||
315 | } | ||
316 | |||
317 | |||
318 | MODULE_AUTHOR("Dominik Brodowski <linux@brodo.de>"); | ||
319 | MODULE_DESCRIPTION("LongRun driver for Transmeta Crusoe and " | ||
320 | "Efficeon processors."); | ||
321 | MODULE_LICENSE("GPL"); | ||
322 | |||
323 | module_init(longrun_init); | ||
324 | module_exit(longrun_exit); | ||
diff --git a/drivers/cpufreq/mperf.c b/drivers/cpufreq/mperf.c new file mode 100644 index 000000000000..911e193018ae --- /dev/null +++ b/drivers/cpufreq/mperf.c | |||
@@ -0,0 +1,51 @@ | |||
1 | #include <linux/kernel.h> | ||
2 | #include <linux/smp.h> | ||
3 | #include <linux/module.h> | ||
4 | #include <linux/init.h> | ||
5 | #include <linux/cpufreq.h> | ||
6 | #include <linux/slab.h> | ||
7 | |||
8 | #include "mperf.h" | ||
9 | |||
10 | static DEFINE_PER_CPU(struct aperfmperf, acfreq_old_perf); | ||
11 | |||
12 | /* Called via smp_call_function_single(), on the target CPU */ | ||
13 | static void read_measured_perf_ctrs(void *_cur) | ||
14 | { | ||
15 | struct aperfmperf *am = _cur; | ||
16 | |||
17 | get_aperfmperf(am); | ||
18 | } | ||
19 | |||
20 | /* | ||
21 | * Return the measured active (C0) frequency on this CPU since last call | ||
22 | * to this function. | ||
23 | * Input: cpu number | ||
24 | * Return: Average CPU frequency in terms of max frequency (zero on error) | ||
25 | * | ||
26 | * We use IA32_MPERF and IA32_APERF MSRs to get the measured performance | ||
27 | * over a period of time, while CPU is in C0 state. | ||
28 | * IA32_MPERF counts at the rate of max advertised frequency | ||
29 | * IA32_APERF counts at the rate of actual CPU frequency | ||
30 | * Only IA32_APERF/IA32_MPERF ratio is architecturally defined and | ||
31 | * no meaning should be associated with absolute values of these MSRs. | ||
32 | */ | ||
33 | unsigned int cpufreq_get_measured_perf(struct cpufreq_policy *policy, | ||
34 | unsigned int cpu) | ||
35 | { | ||
36 | struct aperfmperf perf; | ||
37 | unsigned long ratio; | ||
38 | unsigned int retval; | ||
39 | |||
40 | if (smp_call_function_single(cpu, read_measured_perf_ctrs, &perf, 1)) | ||
41 | return 0; | ||
42 | |||
43 | ratio = calc_aperfmperf_ratio(&per_cpu(acfreq_old_perf, cpu), &perf); | ||
44 | per_cpu(acfreq_old_perf, cpu) = perf; | ||
45 | |||
46 | retval = (policy->cpuinfo.max_freq * ratio) >> APERFMPERF_SHIFT; | ||
47 | |||
48 | return retval; | ||
49 | } | ||
50 | EXPORT_SYMBOL_GPL(cpufreq_get_measured_perf); | ||
51 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/cpufreq/mperf.h b/drivers/cpufreq/mperf.h new file mode 100644 index 000000000000..5dbf2950dc22 --- /dev/null +++ b/drivers/cpufreq/mperf.h | |||
@@ -0,0 +1,9 @@ | |||
1 | /* | ||
2 | * (c) 2010 Advanced Micro Devices, Inc. | ||
3 | * Your use of this code is subject to the terms and conditions of the | ||
4 | * GNU general public license version 2. See "COPYING" or | ||
5 | * http://www.gnu.org/licenses/gpl.html | ||
6 | */ | ||
7 | |||
8 | unsigned int cpufreq_get_measured_perf(struct cpufreq_policy *policy, | ||
9 | unsigned int cpu); | ||
diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c new file mode 100644 index 000000000000..6be3e0760c26 --- /dev/null +++ b/drivers/cpufreq/p4-clockmod.c | |||
@@ -0,0 +1,329 @@ | |||
1 | /* | ||
2 | * Pentium 4/Xeon CPU on demand clock modulation/speed scaling | ||
3 | * (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de> | ||
4 | * (C) 2002 Zwane Mwaikambo <zwane@commfireservices.com> | ||
5 | * (C) 2002 Arjan van de Ven <arjanv@redhat.com> | ||
6 | * (C) 2002 Tora T. Engstad | ||
7 | * All Rights Reserved | ||
8 | * | ||
9 | * This program is free software; you can redistribute it and/or | ||
10 | * modify it under the terms of the GNU General Public License | ||
11 | * as published by the Free Software Foundation; either version | ||
12 | * 2 of the License, or (at your option) any later version. | ||
13 | * | ||
14 | * The author(s) of this software shall not be held liable for damages | ||
15 | * of any nature resulting due to the use of this software. This | ||
16 | * software is provided AS-IS with no warranties. | ||
17 | * | ||
18 | * Date Errata Description | ||
19 | * 20020525 N44, O17 12.5% or 25% DC causes lockup | ||
20 | * | ||
21 | */ | ||
22 | |||
23 | #include <linux/kernel.h> | ||
24 | #include <linux/module.h> | ||
25 | #include <linux/init.h> | ||
26 | #include <linux/smp.h> | ||
27 | #include <linux/cpufreq.h> | ||
28 | #include <linux/cpumask.h> | ||
29 | #include <linux/timex.h> | ||
30 | |||
31 | #include <asm/processor.h> | ||
32 | #include <asm/msr.h> | ||
33 | #include <asm/timer.h> | ||
34 | |||
35 | #include "speedstep-lib.h" | ||
36 | |||
37 | #define PFX "p4-clockmod: " | ||
38 | |||
39 | /* | ||
40 | * Duty Cycle (3bits), note DC_DISABLE is not specified in | ||
41 | * intel docs i just use it to mean disable | ||
42 | */ | ||
43 | enum { | ||
44 | DC_RESV, DC_DFLT, DC_25PT, DC_38PT, DC_50PT, | ||
45 | DC_64PT, DC_75PT, DC_88PT, DC_DISABLE | ||
46 | }; | ||
47 | |||
48 | #define DC_ENTRIES 8 | ||
49 | |||
50 | |||
51 | static int has_N44_O17_errata[NR_CPUS]; | ||
52 | static unsigned int stock_freq; | ||
53 | static struct cpufreq_driver p4clockmod_driver; | ||
54 | static unsigned int cpufreq_p4_get(unsigned int cpu); | ||
55 | |||
56 | static int cpufreq_p4_setdc(unsigned int cpu, unsigned int newstate) | ||
57 | { | ||
58 | u32 l, h; | ||
59 | |||
60 | if (!cpu_online(cpu) || | ||
61 | (newstate > DC_DISABLE) || (newstate == DC_RESV)) | ||
62 | return -EINVAL; | ||
63 | |||
64 | rdmsr_on_cpu(cpu, MSR_IA32_THERM_STATUS, &l, &h); | ||
65 | |||
66 | if (l & 0x01) | ||
67 | pr_debug("CPU#%d currently thermal throttled\n", cpu); | ||
68 | |||
69 | if (has_N44_O17_errata[cpu] && | ||
70 | (newstate == DC_25PT || newstate == DC_DFLT)) | ||
71 | newstate = DC_38PT; | ||
72 | |||
73 | rdmsr_on_cpu(cpu, MSR_IA32_THERM_CONTROL, &l, &h); | ||
74 | if (newstate == DC_DISABLE) { | ||
75 | pr_debug("CPU#%d disabling modulation\n", cpu); | ||
76 | wrmsr_on_cpu(cpu, MSR_IA32_THERM_CONTROL, l & ~(1<<4), h); | ||
77 | } else { | ||
78 | pr_debug("CPU#%d setting duty cycle to %d%%\n", | ||
79 | cpu, ((125 * newstate) / 10)); | ||
80 | /* bits 63 - 5 : reserved | ||
81 | * bit 4 : enable/disable | ||
82 | * bits 3-1 : duty cycle | ||
83 | * bit 0 : reserved | ||
84 | */ | ||
85 | l = (l & ~14); | ||
86 | l = l | (1<<4) | ((newstate & 0x7)<<1); | ||
87 | wrmsr_on_cpu(cpu, MSR_IA32_THERM_CONTROL, l, h); | ||
88 | } | ||
89 | |||
90 | return 0; | ||
91 | } | ||
92 | |||
93 | |||
94 | static struct cpufreq_frequency_table p4clockmod_table[] = { | ||
95 | {DC_RESV, CPUFREQ_ENTRY_INVALID}, | ||
96 | {DC_DFLT, 0}, | ||
97 | {DC_25PT, 0}, | ||
98 | {DC_38PT, 0}, | ||
99 | {DC_50PT, 0}, | ||
100 | {DC_64PT, 0}, | ||
101 | {DC_75PT, 0}, | ||
102 | {DC_88PT, 0}, | ||
103 | {DC_DISABLE, 0}, | ||
104 | {DC_RESV, CPUFREQ_TABLE_END}, | ||
105 | }; | ||
106 | |||
107 | |||
108 | static int cpufreq_p4_target(struct cpufreq_policy *policy, | ||
109 | unsigned int target_freq, | ||
110 | unsigned int relation) | ||
111 | { | ||
112 | unsigned int newstate = DC_RESV; | ||
113 | struct cpufreq_freqs freqs; | ||
114 | int i; | ||
115 | |||
116 | if (cpufreq_frequency_table_target(policy, &p4clockmod_table[0], | ||
117 | target_freq, relation, &newstate)) | ||
118 | return -EINVAL; | ||
119 | |||
120 | freqs.old = cpufreq_p4_get(policy->cpu); | ||
121 | freqs.new = stock_freq * p4clockmod_table[newstate].index / 8; | ||
122 | |||
123 | if (freqs.new == freqs.old) | ||
124 | return 0; | ||
125 | |||
126 | /* notifiers */ | ||
127 | for_each_cpu(i, policy->cpus) { | ||
128 | freqs.cpu = i; | ||
129 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
130 | } | ||
131 | |||
132 | /* run on each logical CPU, | ||
133 | * see section 13.15.3 of IA32 Intel Architecture Software | ||
134 | * Developer's Manual, Volume 3 | ||
135 | */ | ||
136 | for_each_cpu(i, policy->cpus) | ||
137 | cpufreq_p4_setdc(i, p4clockmod_table[newstate].index); | ||
138 | |||
139 | /* notifiers */ | ||
140 | for_each_cpu(i, policy->cpus) { | ||
141 | freqs.cpu = i; | ||
142 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
143 | } | ||
144 | |||
145 | return 0; | ||
146 | } | ||
147 | |||
148 | |||
149 | static int cpufreq_p4_verify(struct cpufreq_policy *policy) | ||
150 | { | ||
151 | return cpufreq_frequency_table_verify(policy, &p4clockmod_table[0]); | ||
152 | } | ||
153 | |||
154 | |||
155 | static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c) | ||
156 | { | ||
157 | if (c->x86 == 0x06) { | ||
158 | if (cpu_has(c, X86_FEATURE_EST)) | ||
159 | printk_once(KERN_WARNING PFX "Warning: EST-capable " | ||
160 | "CPU detected. The acpi-cpufreq module offers " | ||
161 | "voltage scaling in addition to frequency " | ||
162 | "scaling. You should use that instead of " | ||
163 | "p4-clockmod, if possible.\n"); | ||
164 | switch (c->x86_model) { | ||
165 | case 0x0E: /* Core */ | ||
166 | case 0x0F: /* Core Duo */ | ||
167 | case 0x16: /* Celeron Core */ | ||
168 | case 0x1C: /* Atom */ | ||
169 | p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS; | ||
170 | return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE); | ||
171 | case 0x0D: /* Pentium M (Dothan) */ | ||
172 | p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS; | ||
173 | /* fall through */ | ||
174 | case 0x09: /* Pentium M (Banias) */ | ||
175 | return speedstep_get_frequency(SPEEDSTEP_CPU_PM); | ||
176 | } | ||
177 | } | ||
178 | |||
179 | if (c->x86 != 0xF) | ||
180 | return 0; | ||
181 | |||
182 | /* on P-4s, the TSC runs with constant frequency independent whether | ||
183 | * throttling is active or not. */ | ||
184 | p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS; | ||
185 | |||
186 | if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) { | ||
187 | printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. " | ||
188 | "The speedstep-ich or acpi cpufreq modules offer " | ||
189 | "voltage scaling in addition of frequency scaling. " | ||
190 | "You should use either one instead of p4-clockmod, " | ||
191 | "if possible.\n"); | ||
192 | return speedstep_get_frequency(SPEEDSTEP_CPU_P4M); | ||
193 | } | ||
194 | |||
195 | return speedstep_get_frequency(SPEEDSTEP_CPU_P4D); | ||
196 | } | ||
197 | |||
198 | |||
199 | |||
200 | static int cpufreq_p4_cpu_init(struct cpufreq_policy *policy) | ||
201 | { | ||
202 | struct cpuinfo_x86 *c = &cpu_data(policy->cpu); | ||
203 | int cpuid = 0; | ||
204 | unsigned int i; | ||
205 | |||
206 | #ifdef CONFIG_SMP | ||
207 | cpumask_copy(policy->cpus, cpu_sibling_mask(policy->cpu)); | ||
208 | #endif | ||
209 | |||
210 | /* Errata workaround */ | ||
211 | cpuid = (c->x86 << 8) | (c->x86_model << 4) | c->x86_mask; | ||
212 | switch (cpuid) { | ||
213 | case 0x0f07: | ||
214 | case 0x0f0a: | ||
215 | case 0x0f11: | ||
216 | case 0x0f12: | ||
217 | has_N44_O17_errata[policy->cpu] = 1; | ||
218 | pr_debug("has errata -- disabling low frequencies\n"); | ||
219 | } | ||
220 | |||
221 | if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4D && | ||
222 | c->x86_model < 2) { | ||
223 | /* switch to maximum frequency and measure result */ | ||
224 | cpufreq_p4_setdc(policy->cpu, DC_DISABLE); | ||
225 | recalibrate_cpu_khz(); | ||
226 | } | ||
227 | /* get max frequency */ | ||
228 | stock_freq = cpufreq_p4_get_frequency(c); | ||
229 | if (!stock_freq) | ||
230 | return -EINVAL; | ||
231 | |||
232 | /* table init */ | ||
233 | for (i = 1; (p4clockmod_table[i].frequency != CPUFREQ_TABLE_END); i++) { | ||
234 | if ((i < 2) && (has_N44_O17_errata[policy->cpu])) | ||
235 | p4clockmod_table[i].frequency = CPUFREQ_ENTRY_INVALID; | ||
236 | else | ||
237 | p4clockmod_table[i].frequency = (stock_freq * i)/8; | ||
238 | } | ||
239 | cpufreq_frequency_table_get_attr(p4clockmod_table, policy->cpu); | ||
240 | |||
241 | /* cpuinfo and default policy values */ | ||
242 | |||
243 | /* the transition latency is set to be 1 higher than the maximum | ||
244 | * transition latency of the ondemand governor */ | ||
245 | policy->cpuinfo.transition_latency = 10000001; | ||
246 | policy->cur = stock_freq; | ||
247 | |||
248 | return cpufreq_frequency_table_cpuinfo(policy, &p4clockmod_table[0]); | ||
249 | } | ||
250 | |||
251 | |||
252 | static int cpufreq_p4_cpu_exit(struct cpufreq_policy *policy) | ||
253 | { | ||
254 | cpufreq_frequency_table_put_attr(policy->cpu); | ||
255 | return 0; | ||
256 | } | ||
257 | |||
258 | static unsigned int cpufreq_p4_get(unsigned int cpu) | ||
259 | { | ||
260 | u32 l, h; | ||
261 | |||
262 | rdmsr_on_cpu(cpu, MSR_IA32_THERM_CONTROL, &l, &h); | ||
263 | |||
264 | if (l & 0x10) { | ||
265 | l = l >> 1; | ||
266 | l &= 0x7; | ||
267 | } else | ||
268 | l = DC_DISABLE; | ||
269 | |||
270 | if (l != DC_DISABLE) | ||
271 | return stock_freq * l / 8; | ||
272 | |||
273 | return stock_freq; | ||
274 | } | ||
275 | |||
276 | static struct freq_attr *p4clockmod_attr[] = { | ||
277 | &cpufreq_freq_attr_scaling_available_freqs, | ||
278 | NULL, | ||
279 | }; | ||
280 | |||
281 | static struct cpufreq_driver p4clockmod_driver = { | ||
282 | .verify = cpufreq_p4_verify, | ||
283 | .target = cpufreq_p4_target, | ||
284 | .init = cpufreq_p4_cpu_init, | ||
285 | .exit = cpufreq_p4_cpu_exit, | ||
286 | .get = cpufreq_p4_get, | ||
287 | .name = "p4-clockmod", | ||
288 | .owner = THIS_MODULE, | ||
289 | .attr = p4clockmod_attr, | ||
290 | }; | ||
291 | |||
292 | |||
293 | static int __init cpufreq_p4_init(void) | ||
294 | { | ||
295 | struct cpuinfo_x86 *c = &cpu_data(0); | ||
296 | int ret; | ||
297 | |||
298 | /* | ||
299 | * THERM_CONTROL is architectural for IA32 now, so | ||
300 | * we can rely on the capability checks | ||
301 | */ | ||
302 | if (c->x86_vendor != X86_VENDOR_INTEL) | ||
303 | return -ENODEV; | ||
304 | |||
305 | if (!test_cpu_cap(c, X86_FEATURE_ACPI) || | ||
306 | !test_cpu_cap(c, X86_FEATURE_ACC)) | ||
307 | return -ENODEV; | ||
308 | |||
309 | ret = cpufreq_register_driver(&p4clockmod_driver); | ||
310 | if (!ret) | ||
311 | printk(KERN_INFO PFX "P4/Xeon(TM) CPU On-Demand Clock " | ||
312 | "Modulation available\n"); | ||
313 | |||
314 | return ret; | ||
315 | } | ||
316 | |||
317 | |||
318 | static void __exit cpufreq_p4_exit(void) | ||
319 | { | ||
320 | cpufreq_unregister_driver(&p4clockmod_driver); | ||
321 | } | ||
322 | |||
323 | |||
324 | MODULE_AUTHOR("Zwane Mwaikambo <zwane@commfireservices.com>"); | ||
325 | MODULE_DESCRIPTION("cpufreq driver for Pentium(TM) 4/Xeon(TM)"); | ||
326 | MODULE_LICENSE("GPL"); | ||
327 | |||
328 | late_initcall(cpufreq_p4_init); | ||
329 | module_exit(cpufreq_p4_exit); | ||
diff --git a/drivers/cpufreq/pcc-cpufreq.c b/drivers/cpufreq/pcc-cpufreq.c new file mode 100644 index 000000000000..7b0603eb0129 --- /dev/null +++ b/drivers/cpufreq/pcc-cpufreq.c | |||
@@ -0,0 +1,621 @@ | |||
1 | /* | ||
2 | * pcc-cpufreq.c - Processor Clocking Control firmware cpufreq interface | ||
3 | * | ||
4 | * Copyright (C) 2009 Red Hat, Matthew Garrett <mjg@redhat.com> | ||
5 | * Copyright (C) 2009 Hewlett-Packard Development Company, L.P. | ||
6 | * Nagananda Chumbalkar <nagananda.chumbalkar@hp.com> | ||
7 | * | ||
8 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or modify | ||
11 | * it under the terms of the GNU General Public License as published by | ||
12 | * the Free Software Foundation; version 2 of the License. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, but | ||
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or NON | ||
17 | * INFRINGEMENT. See the GNU General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License along | ||
20 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
21 | * 675 Mass Ave, Cambridge, MA 02139, USA. | ||
22 | * | ||
23 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
24 | */ | ||
25 | |||
26 | #include <linux/kernel.h> | ||
27 | #include <linux/module.h> | ||
28 | #include <linux/init.h> | ||
29 | #include <linux/smp.h> | ||
30 | #include <linux/sched.h> | ||
31 | #include <linux/cpufreq.h> | ||
32 | #include <linux/compiler.h> | ||
33 | #include <linux/slab.h> | ||
34 | |||
35 | #include <linux/acpi.h> | ||
36 | #include <linux/io.h> | ||
37 | #include <linux/spinlock.h> | ||
38 | #include <linux/uaccess.h> | ||
39 | |||
40 | #include <acpi/processor.h> | ||
41 | |||
42 | #define PCC_VERSION "1.10.00" | ||
43 | #define POLL_LOOPS 300 | ||
44 | |||
45 | #define CMD_COMPLETE 0x1 | ||
46 | #define CMD_GET_FREQ 0x0 | ||
47 | #define CMD_SET_FREQ 0x1 | ||
48 | |||
49 | #define BUF_SZ 4 | ||
50 | |||
51 | struct pcc_register_resource { | ||
52 | u8 descriptor; | ||
53 | u16 length; | ||
54 | u8 space_id; | ||
55 | u8 bit_width; | ||
56 | u8 bit_offset; | ||
57 | u8 access_size; | ||
58 | u64 address; | ||
59 | } __attribute__ ((packed)); | ||
60 | |||
61 | struct pcc_memory_resource { | ||
62 | u8 descriptor; | ||
63 | u16 length; | ||
64 | u8 space_id; | ||
65 | u8 resource_usage; | ||
66 | u8 type_specific; | ||
67 | u64 granularity; | ||
68 | u64 minimum; | ||
69 | u64 maximum; | ||
70 | u64 translation_offset; | ||
71 | u64 address_length; | ||
72 | } __attribute__ ((packed)); | ||
73 | |||
74 | static struct cpufreq_driver pcc_cpufreq_driver; | ||
75 | |||
76 | struct pcc_header { | ||
77 | u32 signature; | ||
78 | u16 length; | ||
79 | u8 major; | ||
80 | u8 minor; | ||
81 | u32 features; | ||
82 | u16 command; | ||
83 | u16 status; | ||
84 | u32 latency; | ||
85 | u32 minimum_time; | ||
86 | u32 maximum_time; | ||
87 | u32 nominal; | ||
88 | u32 throttled_frequency; | ||
89 | u32 minimum_frequency; | ||
90 | }; | ||
91 | |||
92 | static void __iomem *pcch_virt_addr; | ||
93 | static struct pcc_header __iomem *pcch_hdr; | ||
94 | |||
95 | static DEFINE_SPINLOCK(pcc_lock); | ||
96 | |||
97 | static struct acpi_generic_address doorbell; | ||
98 | |||
99 | static u64 doorbell_preserve; | ||
100 | static u64 doorbell_write; | ||
101 | |||
102 | static u8 OSC_UUID[16] = {0x9F, 0x2C, 0x9B, 0x63, 0x91, 0x70, 0x1f, 0x49, | ||
103 | 0xBB, 0x4F, 0xA5, 0x98, 0x2F, 0xA1, 0xB5, 0x46}; | ||
104 | |||
105 | struct pcc_cpu { | ||
106 | u32 input_offset; | ||
107 | u32 output_offset; | ||
108 | }; | ||
109 | |||
110 | static struct pcc_cpu __percpu *pcc_cpu_info; | ||
111 | |||
112 | static int pcc_cpufreq_verify(struct cpufreq_policy *policy) | ||
113 | { | ||
114 | cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq, | ||
115 | policy->cpuinfo.max_freq); | ||
116 | return 0; | ||
117 | } | ||
118 | |||
119 | static inline void pcc_cmd(void) | ||
120 | { | ||
121 | u64 doorbell_value; | ||
122 | int i; | ||
123 | |||
124 | acpi_read(&doorbell_value, &doorbell); | ||
125 | acpi_write((doorbell_value & doorbell_preserve) | doorbell_write, | ||
126 | &doorbell); | ||
127 | |||
128 | for (i = 0; i < POLL_LOOPS; i++) { | ||
129 | if (ioread16(&pcch_hdr->status) & CMD_COMPLETE) | ||
130 | break; | ||
131 | } | ||
132 | } | ||
133 | |||
134 | static inline void pcc_clear_mapping(void) | ||
135 | { | ||
136 | if (pcch_virt_addr) | ||
137 | iounmap(pcch_virt_addr); | ||
138 | pcch_virt_addr = NULL; | ||
139 | } | ||
140 | |||
141 | static unsigned int pcc_get_freq(unsigned int cpu) | ||
142 | { | ||
143 | struct pcc_cpu *pcc_cpu_data; | ||
144 | unsigned int curr_freq; | ||
145 | unsigned int freq_limit; | ||
146 | u16 status; | ||
147 | u32 input_buffer; | ||
148 | u32 output_buffer; | ||
149 | |||
150 | spin_lock(&pcc_lock); | ||
151 | |||
152 | pr_debug("get: get_freq for CPU %d\n", cpu); | ||
153 | pcc_cpu_data = per_cpu_ptr(pcc_cpu_info, cpu); | ||
154 | |||
155 | input_buffer = 0x1; | ||
156 | iowrite32(input_buffer, | ||
157 | (pcch_virt_addr + pcc_cpu_data->input_offset)); | ||
158 | iowrite16(CMD_GET_FREQ, &pcch_hdr->command); | ||
159 | |||
160 | pcc_cmd(); | ||
161 | |||
162 | output_buffer = | ||
163 | ioread32(pcch_virt_addr + pcc_cpu_data->output_offset); | ||
164 | |||
165 | /* Clear the input buffer - we are done with the current command */ | ||
166 | memset_io((pcch_virt_addr + pcc_cpu_data->input_offset), 0, BUF_SZ); | ||
167 | |||
168 | status = ioread16(&pcch_hdr->status); | ||
169 | if (status != CMD_COMPLETE) { | ||
170 | pr_debug("get: FAILED: for CPU %d, status is %d\n", | ||
171 | cpu, status); | ||
172 | goto cmd_incomplete; | ||
173 | } | ||
174 | iowrite16(0, &pcch_hdr->status); | ||
175 | curr_freq = (((ioread32(&pcch_hdr->nominal) * (output_buffer & 0xff)) | ||
176 | / 100) * 1000); | ||
177 | |||
178 | pr_debug("get: SUCCESS: (virtual) output_offset for cpu %d is " | ||
179 | "0x%p, contains a value of: 0x%x. Speed is: %d MHz\n", | ||
180 | cpu, (pcch_virt_addr + pcc_cpu_data->output_offset), | ||
181 | output_buffer, curr_freq); | ||
182 | |||
183 | freq_limit = (output_buffer >> 8) & 0xff; | ||
184 | if (freq_limit != 0xff) { | ||
185 | pr_debug("get: frequency for cpu %d is being temporarily" | ||
186 | " capped at %d\n", cpu, curr_freq); | ||
187 | } | ||
188 | |||
189 | spin_unlock(&pcc_lock); | ||
190 | return curr_freq; | ||
191 | |||
192 | cmd_incomplete: | ||
193 | iowrite16(0, &pcch_hdr->status); | ||
194 | spin_unlock(&pcc_lock); | ||
195 | return 0; | ||
196 | } | ||
197 | |||
198 | static int pcc_cpufreq_target(struct cpufreq_policy *policy, | ||
199 | unsigned int target_freq, | ||
200 | unsigned int relation) | ||
201 | { | ||
202 | struct pcc_cpu *pcc_cpu_data; | ||
203 | struct cpufreq_freqs freqs; | ||
204 | u16 status; | ||
205 | u32 input_buffer; | ||
206 | int cpu; | ||
207 | |||
208 | spin_lock(&pcc_lock); | ||
209 | cpu = policy->cpu; | ||
210 | pcc_cpu_data = per_cpu_ptr(pcc_cpu_info, cpu); | ||
211 | |||
212 | pr_debug("target: CPU %d should go to target freq: %d " | ||
213 | "(virtual) input_offset is 0x%p\n", | ||
214 | cpu, target_freq, | ||
215 | (pcch_virt_addr + pcc_cpu_data->input_offset)); | ||
216 | |||
217 | freqs.new = target_freq; | ||
218 | freqs.cpu = cpu; | ||
219 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
220 | |||
221 | input_buffer = 0x1 | (((target_freq * 100) | ||
222 | / (ioread32(&pcch_hdr->nominal) * 1000)) << 8); | ||
223 | iowrite32(input_buffer, | ||
224 | (pcch_virt_addr + pcc_cpu_data->input_offset)); | ||
225 | iowrite16(CMD_SET_FREQ, &pcch_hdr->command); | ||
226 | |||
227 | pcc_cmd(); | ||
228 | |||
229 | /* Clear the input buffer - we are done with the current command */ | ||
230 | memset_io((pcch_virt_addr + pcc_cpu_data->input_offset), 0, BUF_SZ); | ||
231 | |||
232 | status = ioread16(&pcch_hdr->status); | ||
233 | if (status != CMD_COMPLETE) { | ||
234 | pr_debug("target: FAILED for cpu %d, with status: 0x%x\n", | ||
235 | cpu, status); | ||
236 | goto cmd_incomplete; | ||
237 | } | ||
238 | iowrite16(0, &pcch_hdr->status); | ||
239 | |||
240 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
241 | pr_debug("target: was SUCCESSFUL for cpu %d\n", cpu); | ||
242 | spin_unlock(&pcc_lock); | ||
243 | |||
244 | return 0; | ||
245 | |||
246 | cmd_incomplete: | ||
247 | iowrite16(0, &pcch_hdr->status); | ||
248 | spin_unlock(&pcc_lock); | ||
249 | return -EINVAL; | ||
250 | } | ||
251 | |||
252 | static int pcc_get_offset(int cpu) | ||
253 | { | ||
254 | acpi_status status; | ||
255 | struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL}; | ||
256 | union acpi_object *pccp, *offset; | ||
257 | struct pcc_cpu *pcc_cpu_data; | ||
258 | struct acpi_processor *pr; | ||
259 | int ret = 0; | ||
260 | |||
261 | pr = per_cpu(processors, cpu); | ||
262 | pcc_cpu_data = per_cpu_ptr(pcc_cpu_info, cpu); | ||
263 | |||
264 | status = acpi_evaluate_object(pr->handle, "PCCP", NULL, &buffer); | ||
265 | if (ACPI_FAILURE(status)) | ||
266 | return -ENODEV; | ||
267 | |||
268 | pccp = buffer.pointer; | ||
269 | if (!pccp || pccp->type != ACPI_TYPE_PACKAGE) { | ||
270 | ret = -ENODEV; | ||
271 | goto out_free; | ||
272 | }; | ||
273 | |||
274 | offset = &(pccp->package.elements[0]); | ||
275 | if (!offset || offset->type != ACPI_TYPE_INTEGER) { | ||
276 | ret = -ENODEV; | ||
277 | goto out_free; | ||
278 | } | ||
279 | |||
280 | pcc_cpu_data->input_offset = offset->integer.value; | ||
281 | |||
282 | offset = &(pccp->package.elements[1]); | ||
283 | if (!offset || offset->type != ACPI_TYPE_INTEGER) { | ||
284 | ret = -ENODEV; | ||
285 | goto out_free; | ||
286 | } | ||
287 | |||
288 | pcc_cpu_data->output_offset = offset->integer.value; | ||
289 | |||
290 | memset_io((pcch_virt_addr + pcc_cpu_data->input_offset), 0, BUF_SZ); | ||
291 | memset_io((pcch_virt_addr + pcc_cpu_data->output_offset), 0, BUF_SZ); | ||
292 | |||
293 | pr_debug("pcc_get_offset: for CPU %d: pcc_cpu_data " | ||
294 | "input_offset: 0x%x, pcc_cpu_data output_offset: 0x%x\n", | ||
295 | cpu, pcc_cpu_data->input_offset, pcc_cpu_data->output_offset); | ||
296 | out_free: | ||
297 | kfree(buffer.pointer); | ||
298 | return ret; | ||
299 | } | ||
300 | |||
301 | static int __init pcc_cpufreq_do_osc(acpi_handle *handle) | ||
302 | { | ||
303 | acpi_status status; | ||
304 | struct acpi_object_list input; | ||
305 | struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL}; | ||
306 | union acpi_object in_params[4]; | ||
307 | union acpi_object *out_obj; | ||
308 | u32 capabilities[2]; | ||
309 | u32 errors; | ||
310 | u32 supported; | ||
311 | int ret = 0; | ||
312 | |||
313 | input.count = 4; | ||
314 | input.pointer = in_params; | ||
315 | in_params[0].type = ACPI_TYPE_BUFFER; | ||
316 | in_params[0].buffer.length = 16; | ||
317 | in_params[0].buffer.pointer = OSC_UUID; | ||
318 | in_params[1].type = ACPI_TYPE_INTEGER; | ||
319 | in_params[1].integer.value = 1; | ||
320 | in_params[2].type = ACPI_TYPE_INTEGER; | ||
321 | in_params[2].integer.value = 2; | ||
322 | in_params[3].type = ACPI_TYPE_BUFFER; | ||
323 | in_params[3].buffer.length = 8; | ||
324 | in_params[3].buffer.pointer = (u8 *)&capabilities; | ||
325 | |||
326 | capabilities[0] = OSC_QUERY_ENABLE; | ||
327 | capabilities[1] = 0x1; | ||
328 | |||
329 | status = acpi_evaluate_object(*handle, "_OSC", &input, &output); | ||
330 | if (ACPI_FAILURE(status)) | ||
331 | return -ENODEV; | ||
332 | |||
333 | if (!output.length) | ||
334 | return -ENODEV; | ||
335 | |||
336 | out_obj = output.pointer; | ||
337 | if (out_obj->type != ACPI_TYPE_BUFFER) { | ||
338 | ret = -ENODEV; | ||
339 | goto out_free; | ||
340 | } | ||
341 | |||
342 | errors = *((u32 *)out_obj->buffer.pointer) & ~(1 << 0); | ||
343 | if (errors) { | ||
344 | ret = -ENODEV; | ||
345 | goto out_free; | ||
346 | } | ||
347 | |||
348 | supported = *((u32 *)(out_obj->buffer.pointer + 4)); | ||
349 | if (!(supported & 0x1)) { | ||
350 | ret = -ENODEV; | ||
351 | goto out_free; | ||
352 | } | ||
353 | |||
354 | kfree(output.pointer); | ||
355 | capabilities[0] = 0x0; | ||
356 | capabilities[1] = 0x1; | ||
357 | |||
358 | status = acpi_evaluate_object(*handle, "_OSC", &input, &output); | ||
359 | if (ACPI_FAILURE(status)) | ||
360 | return -ENODEV; | ||
361 | |||
362 | if (!output.length) | ||
363 | return -ENODEV; | ||
364 | |||
365 | out_obj = output.pointer; | ||
366 | if (out_obj->type != ACPI_TYPE_BUFFER) { | ||
367 | ret = -ENODEV; | ||
368 | goto out_free; | ||
369 | } | ||
370 | |||
371 | errors = *((u32 *)out_obj->buffer.pointer) & ~(1 << 0); | ||
372 | if (errors) { | ||
373 | ret = -ENODEV; | ||
374 | goto out_free; | ||
375 | } | ||
376 | |||
377 | supported = *((u32 *)(out_obj->buffer.pointer + 4)); | ||
378 | if (!(supported & 0x1)) { | ||
379 | ret = -ENODEV; | ||
380 | goto out_free; | ||
381 | } | ||
382 | |||
383 | out_free: | ||
384 | kfree(output.pointer); | ||
385 | return ret; | ||
386 | } | ||
387 | |||
388 | static int __init pcc_cpufreq_probe(void) | ||
389 | { | ||
390 | acpi_status status; | ||
391 | struct acpi_buffer output = {ACPI_ALLOCATE_BUFFER, NULL}; | ||
392 | struct pcc_memory_resource *mem_resource; | ||
393 | struct pcc_register_resource *reg_resource; | ||
394 | union acpi_object *out_obj, *member; | ||
395 | acpi_handle handle, osc_handle, pcch_handle; | ||
396 | int ret = 0; | ||
397 | |||
398 | status = acpi_get_handle(NULL, "\\_SB", &handle); | ||
399 | if (ACPI_FAILURE(status)) | ||
400 | return -ENODEV; | ||
401 | |||
402 | status = acpi_get_handle(handle, "PCCH", &pcch_handle); | ||
403 | if (ACPI_FAILURE(status)) | ||
404 | return -ENODEV; | ||
405 | |||
406 | status = acpi_get_handle(handle, "_OSC", &osc_handle); | ||
407 | if (ACPI_SUCCESS(status)) { | ||
408 | ret = pcc_cpufreq_do_osc(&osc_handle); | ||
409 | if (ret) | ||
410 | pr_debug("probe: _OSC evaluation did not succeed\n"); | ||
411 | /* Firmware's use of _OSC is optional */ | ||
412 | ret = 0; | ||
413 | } | ||
414 | |||
415 | status = acpi_evaluate_object(handle, "PCCH", NULL, &output); | ||
416 | if (ACPI_FAILURE(status)) | ||
417 | return -ENODEV; | ||
418 | |||
419 | out_obj = output.pointer; | ||
420 | if (out_obj->type != ACPI_TYPE_PACKAGE) { | ||
421 | ret = -ENODEV; | ||
422 | goto out_free; | ||
423 | } | ||
424 | |||
425 | member = &out_obj->package.elements[0]; | ||
426 | if (member->type != ACPI_TYPE_BUFFER) { | ||
427 | ret = -ENODEV; | ||
428 | goto out_free; | ||
429 | } | ||
430 | |||
431 | mem_resource = (struct pcc_memory_resource *)member->buffer.pointer; | ||
432 | |||
433 | pr_debug("probe: mem_resource descriptor: 0x%x," | ||
434 | " length: %d, space_id: %d, resource_usage: %d," | ||
435 | " type_specific: %d, granularity: 0x%llx," | ||
436 | " minimum: 0x%llx, maximum: 0x%llx," | ||
437 | " translation_offset: 0x%llx, address_length: 0x%llx\n", | ||
438 | mem_resource->descriptor, mem_resource->length, | ||
439 | mem_resource->space_id, mem_resource->resource_usage, | ||
440 | mem_resource->type_specific, mem_resource->granularity, | ||
441 | mem_resource->minimum, mem_resource->maximum, | ||
442 | mem_resource->translation_offset, | ||
443 | mem_resource->address_length); | ||
444 | |||
445 | if (mem_resource->space_id != ACPI_ADR_SPACE_SYSTEM_MEMORY) { | ||
446 | ret = -ENODEV; | ||
447 | goto out_free; | ||
448 | } | ||
449 | |||
450 | pcch_virt_addr = ioremap_nocache(mem_resource->minimum, | ||
451 | mem_resource->address_length); | ||
452 | if (pcch_virt_addr == NULL) { | ||
453 | pr_debug("probe: could not map shared mem region\n"); | ||
454 | goto out_free; | ||
455 | } | ||
456 | pcch_hdr = pcch_virt_addr; | ||
457 | |||
458 | pr_debug("probe: PCCH header (virtual) addr: 0x%p\n", pcch_hdr); | ||
459 | pr_debug("probe: PCCH header is at physical address: 0x%llx," | ||
460 | " signature: 0x%x, length: %d bytes, major: %d, minor: %d," | ||
461 | " supported features: 0x%x, command field: 0x%x," | ||
462 | " status field: 0x%x, nominal latency: %d us\n", | ||
463 | mem_resource->minimum, ioread32(&pcch_hdr->signature), | ||
464 | ioread16(&pcch_hdr->length), ioread8(&pcch_hdr->major), | ||
465 | ioread8(&pcch_hdr->minor), ioread32(&pcch_hdr->features), | ||
466 | ioread16(&pcch_hdr->command), ioread16(&pcch_hdr->status), | ||
467 | ioread32(&pcch_hdr->latency)); | ||
468 | |||
469 | pr_debug("probe: min time between commands: %d us," | ||
470 | " max time between commands: %d us," | ||
471 | " nominal CPU frequency: %d MHz," | ||
472 | " minimum CPU frequency: %d MHz," | ||
473 | " minimum CPU frequency without throttling: %d MHz\n", | ||
474 | ioread32(&pcch_hdr->minimum_time), | ||
475 | ioread32(&pcch_hdr->maximum_time), | ||
476 | ioread32(&pcch_hdr->nominal), | ||
477 | ioread32(&pcch_hdr->throttled_frequency), | ||
478 | ioread32(&pcch_hdr->minimum_frequency)); | ||
479 | |||
480 | member = &out_obj->package.elements[1]; | ||
481 | if (member->type != ACPI_TYPE_BUFFER) { | ||
482 | ret = -ENODEV; | ||
483 | goto pcch_free; | ||
484 | } | ||
485 | |||
486 | reg_resource = (struct pcc_register_resource *)member->buffer.pointer; | ||
487 | |||
488 | doorbell.space_id = reg_resource->space_id; | ||
489 | doorbell.bit_width = reg_resource->bit_width; | ||
490 | doorbell.bit_offset = reg_resource->bit_offset; | ||
491 | doorbell.access_width = 64; | ||
492 | doorbell.address = reg_resource->address; | ||
493 | |||
494 | pr_debug("probe: doorbell: space_id is %d, bit_width is %d, " | ||
495 | "bit_offset is %d, access_width is %d, address is 0x%llx\n", | ||
496 | doorbell.space_id, doorbell.bit_width, doorbell.bit_offset, | ||
497 | doorbell.access_width, reg_resource->address); | ||
498 | |||
499 | member = &out_obj->package.elements[2]; | ||
500 | if (member->type != ACPI_TYPE_INTEGER) { | ||
501 | ret = -ENODEV; | ||
502 | goto pcch_free; | ||
503 | } | ||
504 | |||
505 | doorbell_preserve = member->integer.value; | ||
506 | |||
507 | member = &out_obj->package.elements[3]; | ||
508 | if (member->type != ACPI_TYPE_INTEGER) { | ||
509 | ret = -ENODEV; | ||
510 | goto pcch_free; | ||
511 | } | ||
512 | |||
513 | doorbell_write = member->integer.value; | ||
514 | |||
515 | pr_debug("probe: doorbell_preserve: 0x%llx," | ||
516 | " doorbell_write: 0x%llx\n", | ||
517 | doorbell_preserve, doorbell_write); | ||
518 | |||
519 | pcc_cpu_info = alloc_percpu(struct pcc_cpu); | ||
520 | if (!pcc_cpu_info) { | ||
521 | ret = -ENOMEM; | ||
522 | goto pcch_free; | ||
523 | } | ||
524 | |||
525 | printk(KERN_DEBUG "pcc-cpufreq: (v%s) driver loaded with frequency" | ||
526 | " limits: %d MHz, %d MHz\n", PCC_VERSION, | ||
527 | ioread32(&pcch_hdr->minimum_frequency), | ||
528 | ioread32(&pcch_hdr->nominal)); | ||
529 | kfree(output.pointer); | ||
530 | return ret; | ||
531 | pcch_free: | ||
532 | pcc_clear_mapping(); | ||
533 | out_free: | ||
534 | kfree(output.pointer); | ||
535 | return ret; | ||
536 | } | ||
537 | |||
538 | static int pcc_cpufreq_cpu_init(struct cpufreq_policy *policy) | ||
539 | { | ||
540 | unsigned int cpu = policy->cpu; | ||
541 | unsigned int result = 0; | ||
542 | |||
543 | if (!pcch_virt_addr) { | ||
544 | result = -1; | ||
545 | goto out; | ||
546 | } | ||
547 | |||
548 | result = pcc_get_offset(cpu); | ||
549 | if (result) { | ||
550 | pr_debug("init: PCCP evaluation failed\n"); | ||
551 | goto out; | ||
552 | } | ||
553 | |||
554 | policy->max = policy->cpuinfo.max_freq = | ||
555 | ioread32(&pcch_hdr->nominal) * 1000; | ||
556 | policy->min = policy->cpuinfo.min_freq = | ||
557 | ioread32(&pcch_hdr->minimum_frequency) * 1000; | ||
558 | policy->cur = pcc_get_freq(cpu); | ||
559 | |||
560 | if (!policy->cur) { | ||
561 | pr_debug("init: Unable to get current CPU frequency\n"); | ||
562 | result = -EINVAL; | ||
563 | goto out; | ||
564 | } | ||
565 | |||
566 | pr_debug("init: policy->max is %d, policy->min is %d\n", | ||
567 | policy->max, policy->min); | ||
568 | out: | ||
569 | return result; | ||
570 | } | ||
571 | |||
572 | static int pcc_cpufreq_cpu_exit(struct cpufreq_policy *policy) | ||
573 | { | ||
574 | return 0; | ||
575 | } | ||
576 | |||
577 | static struct cpufreq_driver pcc_cpufreq_driver = { | ||
578 | .flags = CPUFREQ_CONST_LOOPS, | ||
579 | .get = pcc_get_freq, | ||
580 | .verify = pcc_cpufreq_verify, | ||
581 | .target = pcc_cpufreq_target, | ||
582 | .init = pcc_cpufreq_cpu_init, | ||
583 | .exit = pcc_cpufreq_cpu_exit, | ||
584 | .name = "pcc-cpufreq", | ||
585 | .owner = THIS_MODULE, | ||
586 | }; | ||
587 | |||
588 | static int __init pcc_cpufreq_init(void) | ||
589 | { | ||
590 | int ret; | ||
591 | |||
592 | if (acpi_disabled) | ||
593 | return 0; | ||
594 | |||
595 | ret = pcc_cpufreq_probe(); | ||
596 | if (ret) { | ||
597 | pr_debug("pcc_cpufreq_init: PCCH evaluation failed\n"); | ||
598 | return ret; | ||
599 | } | ||
600 | |||
601 | ret = cpufreq_register_driver(&pcc_cpufreq_driver); | ||
602 | |||
603 | return ret; | ||
604 | } | ||
605 | |||
606 | static void __exit pcc_cpufreq_exit(void) | ||
607 | { | ||
608 | cpufreq_unregister_driver(&pcc_cpufreq_driver); | ||
609 | |||
610 | pcc_clear_mapping(); | ||
611 | |||
612 | free_percpu(pcc_cpu_info); | ||
613 | } | ||
614 | |||
615 | MODULE_AUTHOR("Matthew Garrett, Naga Chumbalkar"); | ||
616 | MODULE_VERSION(PCC_VERSION); | ||
617 | MODULE_DESCRIPTION("Processor Clocking Control interface driver"); | ||
618 | MODULE_LICENSE("GPL"); | ||
619 | |||
620 | late_initcall(pcc_cpufreq_init); | ||
621 | module_exit(pcc_cpufreq_exit); | ||
diff --git a/drivers/cpufreq/powernow-k6.c b/drivers/cpufreq/powernow-k6.c new file mode 100644 index 000000000000..b3379d6a5c57 --- /dev/null +++ b/drivers/cpufreq/powernow-k6.c | |||
@@ -0,0 +1,261 @@ | |||
1 | /* | ||
2 | * This file was based upon code in Powertweak Linux (http://powertweak.sf.net) | ||
3 | * (C) 2000-2003 Dave Jones, Arjan van de Ven, Janne Pänkälä, | ||
4 | * Dominik Brodowski. | ||
5 | * | ||
6 | * Licensed under the terms of the GNU GPL License version 2. | ||
7 | * | ||
8 | * BIG FAT DISCLAIMER: Work in progress code. Possibly *dangerous* | ||
9 | */ | ||
10 | |||
11 | #include <linux/kernel.h> | ||
12 | #include <linux/module.h> | ||
13 | #include <linux/init.h> | ||
14 | #include <linux/cpufreq.h> | ||
15 | #include <linux/ioport.h> | ||
16 | #include <linux/timex.h> | ||
17 | #include <linux/io.h> | ||
18 | |||
19 | #include <asm/msr.h> | ||
20 | |||
21 | #define POWERNOW_IOPORT 0xfff0 /* it doesn't matter where, as long | ||
22 | as it is unused */ | ||
23 | |||
24 | #define PFX "powernow-k6: " | ||
25 | static unsigned int busfreq; /* FSB, in 10 kHz */ | ||
26 | static unsigned int max_multiplier; | ||
27 | |||
28 | |||
29 | /* Clock ratio multiplied by 10 - see table 27 in AMD#23446 */ | ||
30 | static struct cpufreq_frequency_table clock_ratio[] = { | ||
31 | {45, /* 000 -> 4.5x */ 0}, | ||
32 | {50, /* 001 -> 5.0x */ 0}, | ||
33 | {40, /* 010 -> 4.0x */ 0}, | ||
34 | {55, /* 011 -> 5.5x */ 0}, | ||
35 | {20, /* 100 -> 2.0x */ 0}, | ||
36 | {30, /* 101 -> 3.0x */ 0}, | ||
37 | {60, /* 110 -> 6.0x */ 0}, | ||
38 | {35, /* 111 -> 3.5x */ 0}, | ||
39 | {0, CPUFREQ_TABLE_END} | ||
40 | }; | ||
41 | |||
42 | |||
43 | /** | ||
44 | * powernow_k6_get_cpu_multiplier - returns the current FSB multiplier | ||
45 | * | ||
46 | * Returns the current setting of the frequency multiplier. Core clock | ||
47 | * speed is frequency of the Front-Side Bus multiplied with this value. | ||
48 | */ | ||
49 | static int powernow_k6_get_cpu_multiplier(void) | ||
50 | { | ||
51 | u64 invalue = 0; | ||
52 | u32 msrval; | ||
53 | |||
54 | msrval = POWERNOW_IOPORT + 0x1; | ||
55 | wrmsr(MSR_K6_EPMR, msrval, 0); /* enable the PowerNow port */ | ||
56 | invalue = inl(POWERNOW_IOPORT + 0x8); | ||
57 | msrval = POWERNOW_IOPORT + 0x0; | ||
58 | wrmsr(MSR_K6_EPMR, msrval, 0); /* disable it again */ | ||
59 | |||
60 | return clock_ratio[(invalue >> 5)&7].index; | ||
61 | } | ||
62 | |||
63 | |||
64 | /** | ||
65 | * powernow_k6_set_state - set the PowerNow! multiplier | ||
66 | * @best_i: clock_ratio[best_i] is the target multiplier | ||
67 | * | ||
68 | * Tries to change the PowerNow! multiplier | ||
69 | */ | ||
70 | static void powernow_k6_set_state(unsigned int best_i) | ||
71 | { | ||
72 | unsigned long outvalue = 0, invalue = 0; | ||
73 | unsigned long msrval; | ||
74 | struct cpufreq_freqs freqs; | ||
75 | |||
76 | if (clock_ratio[best_i].index > max_multiplier) { | ||
77 | printk(KERN_ERR PFX "invalid target frequency\n"); | ||
78 | return; | ||
79 | } | ||
80 | |||
81 | freqs.old = busfreq * powernow_k6_get_cpu_multiplier(); | ||
82 | freqs.new = busfreq * clock_ratio[best_i].index; | ||
83 | freqs.cpu = 0; /* powernow-k6.c is UP only driver */ | ||
84 | |||
85 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
86 | |||
87 | /* we now need to transform best_i to the BVC format, see AMD#23446 */ | ||
88 | |||
89 | outvalue = (1<<12) | (1<<10) | (1<<9) | (best_i<<5); | ||
90 | |||
91 | msrval = POWERNOW_IOPORT + 0x1; | ||
92 | wrmsr(MSR_K6_EPMR, msrval, 0); /* enable the PowerNow port */ | ||
93 | invalue = inl(POWERNOW_IOPORT + 0x8); | ||
94 | invalue = invalue & 0xf; | ||
95 | outvalue = outvalue | invalue; | ||
96 | outl(outvalue , (POWERNOW_IOPORT + 0x8)); | ||
97 | msrval = POWERNOW_IOPORT + 0x0; | ||
98 | wrmsr(MSR_K6_EPMR, msrval, 0); /* disable it again */ | ||
99 | |||
100 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
101 | |||
102 | return; | ||
103 | } | ||
104 | |||
105 | |||
106 | /** | ||
107 | * powernow_k6_verify - verifies a new CPUfreq policy | ||
108 | * @policy: new policy | ||
109 | * | ||
110 | * Policy must be within lowest and highest possible CPU Frequency, | ||
111 | * and at least one possible state must be within min and max. | ||
112 | */ | ||
113 | static int powernow_k6_verify(struct cpufreq_policy *policy) | ||
114 | { | ||
115 | return cpufreq_frequency_table_verify(policy, &clock_ratio[0]); | ||
116 | } | ||
117 | |||
118 | |||
119 | /** | ||
120 | * powernow_k6_setpolicy - sets a new CPUFreq policy | ||
121 | * @policy: new policy | ||
122 | * @target_freq: the target frequency | ||
123 | * @relation: how that frequency relates to achieved frequency | ||
124 | * (CPUFREQ_RELATION_L or CPUFREQ_RELATION_H) | ||
125 | * | ||
126 | * sets a new CPUFreq policy | ||
127 | */ | ||
128 | static int powernow_k6_target(struct cpufreq_policy *policy, | ||
129 | unsigned int target_freq, | ||
130 | unsigned int relation) | ||
131 | { | ||
132 | unsigned int newstate = 0; | ||
133 | |||
134 | if (cpufreq_frequency_table_target(policy, &clock_ratio[0], | ||
135 | target_freq, relation, &newstate)) | ||
136 | return -EINVAL; | ||
137 | |||
138 | powernow_k6_set_state(newstate); | ||
139 | |||
140 | return 0; | ||
141 | } | ||
142 | |||
143 | |||
144 | static int powernow_k6_cpu_init(struct cpufreq_policy *policy) | ||
145 | { | ||
146 | unsigned int i, f; | ||
147 | int result; | ||
148 | |||
149 | if (policy->cpu != 0) | ||
150 | return -ENODEV; | ||
151 | |||
152 | /* get frequencies */ | ||
153 | max_multiplier = powernow_k6_get_cpu_multiplier(); | ||
154 | busfreq = cpu_khz / max_multiplier; | ||
155 | |||
156 | /* table init */ | ||
157 | for (i = 0; (clock_ratio[i].frequency != CPUFREQ_TABLE_END); i++) { | ||
158 | f = clock_ratio[i].index; | ||
159 | if (f > max_multiplier) | ||
160 | clock_ratio[i].frequency = CPUFREQ_ENTRY_INVALID; | ||
161 | else | ||
162 | clock_ratio[i].frequency = busfreq * f; | ||
163 | } | ||
164 | |||
165 | /* cpuinfo and default policy values */ | ||
166 | policy->cpuinfo.transition_latency = 200000; | ||
167 | policy->cur = busfreq * max_multiplier; | ||
168 | |||
169 | result = cpufreq_frequency_table_cpuinfo(policy, clock_ratio); | ||
170 | if (result) | ||
171 | return result; | ||
172 | |||
173 | cpufreq_frequency_table_get_attr(clock_ratio, policy->cpu); | ||
174 | |||
175 | return 0; | ||
176 | } | ||
177 | |||
178 | |||
179 | static int powernow_k6_cpu_exit(struct cpufreq_policy *policy) | ||
180 | { | ||
181 | unsigned int i; | ||
182 | for (i = 0; i < 8; i++) { | ||
183 | if (i == max_multiplier) | ||
184 | powernow_k6_set_state(i); | ||
185 | } | ||
186 | cpufreq_frequency_table_put_attr(policy->cpu); | ||
187 | return 0; | ||
188 | } | ||
189 | |||
190 | static unsigned int powernow_k6_get(unsigned int cpu) | ||
191 | { | ||
192 | unsigned int ret; | ||
193 | ret = (busfreq * powernow_k6_get_cpu_multiplier()); | ||
194 | return ret; | ||
195 | } | ||
196 | |||
197 | static struct freq_attr *powernow_k6_attr[] = { | ||
198 | &cpufreq_freq_attr_scaling_available_freqs, | ||
199 | NULL, | ||
200 | }; | ||
201 | |||
202 | static struct cpufreq_driver powernow_k6_driver = { | ||
203 | .verify = powernow_k6_verify, | ||
204 | .target = powernow_k6_target, | ||
205 | .init = powernow_k6_cpu_init, | ||
206 | .exit = powernow_k6_cpu_exit, | ||
207 | .get = powernow_k6_get, | ||
208 | .name = "powernow-k6", | ||
209 | .owner = THIS_MODULE, | ||
210 | .attr = powernow_k6_attr, | ||
211 | }; | ||
212 | |||
213 | |||
214 | /** | ||
215 | * powernow_k6_init - initializes the k6 PowerNow! CPUFreq driver | ||
216 | * | ||
217 | * Initializes the K6 PowerNow! support. Returns -ENODEV on unsupported | ||
218 | * devices, -EINVAL or -ENOMEM on problems during initiatization, and zero | ||
219 | * on success. | ||
220 | */ | ||
221 | static int __init powernow_k6_init(void) | ||
222 | { | ||
223 | struct cpuinfo_x86 *c = &cpu_data(0); | ||
224 | |||
225 | if ((c->x86_vendor != X86_VENDOR_AMD) || (c->x86 != 5) || | ||
226 | ((c->x86_model != 12) && (c->x86_model != 13))) | ||
227 | return -ENODEV; | ||
228 | |||
229 | if (!request_region(POWERNOW_IOPORT, 16, "PowerNow!")) { | ||
230 | printk(KERN_INFO PFX "PowerNow IOPORT region already used.\n"); | ||
231 | return -EIO; | ||
232 | } | ||
233 | |||
234 | if (cpufreq_register_driver(&powernow_k6_driver)) { | ||
235 | release_region(POWERNOW_IOPORT, 16); | ||
236 | return -EINVAL; | ||
237 | } | ||
238 | |||
239 | return 0; | ||
240 | } | ||
241 | |||
242 | |||
243 | /** | ||
244 | * powernow_k6_exit - unregisters AMD K6-2+/3+ PowerNow! support | ||
245 | * | ||
246 | * Unregisters AMD K6-2+ / K6-3+ PowerNow! support. | ||
247 | */ | ||
248 | static void __exit powernow_k6_exit(void) | ||
249 | { | ||
250 | cpufreq_unregister_driver(&powernow_k6_driver); | ||
251 | release_region(POWERNOW_IOPORT, 16); | ||
252 | } | ||
253 | |||
254 | |||
255 | MODULE_AUTHOR("Arjan van de Ven, Dave Jones <davej@redhat.com>, " | ||
256 | "Dominik Brodowski <linux@brodo.de>"); | ||
257 | MODULE_DESCRIPTION("PowerNow! driver for AMD K6-2+ / K6-3+ processors."); | ||
258 | MODULE_LICENSE("GPL"); | ||
259 | |||
260 | module_init(powernow_k6_init); | ||
261 | module_exit(powernow_k6_exit); | ||
diff --git a/drivers/cpufreq/powernow-k7.c b/drivers/cpufreq/powernow-k7.c new file mode 100644 index 000000000000..d71d9f372359 --- /dev/null +++ b/drivers/cpufreq/powernow-k7.c | |||
@@ -0,0 +1,747 @@ | |||
1 | /* | ||
2 | * AMD K7 Powernow driver. | ||
3 | * (C) 2003 Dave Jones on behalf of SuSE Labs. | ||
4 | * (C) 2003-2004 Dave Jones <davej@redhat.com> | ||
5 | * | ||
6 | * Licensed under the terms of the GNU GPL License version 2. | ||
7 | * Based upon datasheets & sample CPUs kindly provided by AMD. | ||
8 | * | ||
9 | * Errata 5: | ||
10 | * CPU may fail to execute a FID/VID change in presence of interrupt. | ||
11 | * - We cli/sti on stepping A0 CPUs around the FID/VID transition. | ||
12 | * Errata 15: | ||
13 | * CPU with half frequency multipliers may hang upon wakeup from disconnect. | ||
14 | * - We disable half multipliers if ACPI is used on A0 stepping CPUs. | ||
15 | */ | ||
16 | |||
17 | #include <linux/kernel.h> | ||
18 | #include <linux/module.h> | ||
19 | #include <linux/moduleparam.h> | ||
20 | #include <linux/init.h> | ||
21 | #include <linux/cpufreq.h> | ||
22 | #include <linux/slab.h> | ||
23 | #include <linux/string.h> | ||
24 | #include <linux/dmi.h> | ||
25 | #include <linux/timex.h> | ||
26 | #include <linux/io.h> | ||
27 | |||
28 | #include <asm/timer.h> /* Needed for recalibrate_cpu_khz() */ | ||
29 | #include <asm/msr.h> | ||
30 | #include <asm/system.h> | ||
31 | |||
32 | #ifdef CONFIG_X86_POWERNOW_K7_ACPI | ||
33 | #include <linux/acpi.h> | ||
34 | #include <acpi/processor.h> | ||
35 | #endif | ||
36 | |||
37 | #include "powernow-k7.h" | ||
38 | |||
39 | #define PFX "powernow: " | ||
40 | |||
41 | |||
42 | struct psb_s { | ||
43 | u8 signature[10]; | ||
44 | u8 tableversion; | ||
45 | u8 flags; | ||
46 | u16 settlingtime; | ||
47 | u8 reserved1; | ||
48 | u8 numpst; | ||
49 | }; | ||
50 | |||
51 | struct pst_s { | ||
52 | u32 cpuid; | ||
53 | u8 fsbspeed; | ||
54 | u8 maxfid; | ||
55 | u8 startvid; | ||
56 | u8 numpstates; | ||
57 | }; | ||
58 | |||
59 | #ifdef CONFIG_X86_POWERNOW_K7_ACPI | ||
60 | union powernow_acpi_control_t { | ||
61 | struct { | ||
62 | unsigned long fid:5, | ||
63 | vid:5, | ||
64 | sgtc:20, | ||
65 | res1:2; | ||
66 | } bits; | ||
67 | unsigned long val; | ||
68 | }; | ||
69 | #endif | ||
70 | |||
71 | /* divide by 1000 to get VCore voltage in V. */ | ||
72 | static const int mobile_vid_table[32] = { | ||
73 | 2000, 1950, 1900, 1850, 1800, 1750, 1700, 1650, | ||
74 | 1600, 1550, 1500, 1450, 1400, 1350, 1300, 0, | ||
75 | 1275, 1250, 1225, 1200, 1175, 1150, 1125, 1100, | ||
76 | 1075, 1050, 1025, 1000, 975, 950, 925, 0, | ||
77 | }; | ||
78 | |||
79 | /* divide by 10 to get FID. */ | ||
80 | static const int fid_codes[32] = { | ||
81 | 110, 115, 120, 125, 50, 55, 60, 65, | ||
82 | 70, 75, 80, 85, 90, 95, 100, 105, | ||
83 | 30, 190, 40, 200, 130, 135, 140, 210, | ||
84 | 150, 225, 160, 165, 170, 180, -1, -1, | ||
85 | }; | ||
86 | |||
87 | /* This parameter is used in order to force ACPI instead of legacy method for | ||
88 | * configuration purpose. | ||
89 | */ | ||
90 | |||
91 | static int acpi_force; | ||
92 | |||
93 | static struct cpufreq_frequency_table *powernow_table; | ||
94 | |||
95 | static unsigned int can_scale_bus; | ||
96 | static unsigned int can_scale_vid; | ||
97 | static unsigned int minimum_speed = -1; | ||
98 | static unsigned int maximum_speed; | ||
99 | static unsigned int number_scales; | ||
100 | static unsigned int fsb; | ||
101 | static unsigned int latency; | ||
102 | static char have_a0; | ||
103 | |||
104 | static int check_fsb(unsigned int fsbspeed) | ||
105 | { | ||
106 | int delta; | ||
107 | unsigned int f = fsb / 1000; | ||
108 | |||
109 | delta = (fsbspeed > f) ? fsbspeed - f : f - fsbspeed; | ||
110 | return delta < 5; | ||
111 | } | ||
112 | |||
113 | static int check_powernow(void) | ||
114 | { | ||
115 | struct cpuinfo_x86 *c = &cpu_data(0); | ||
116 | unsigned int maxei, eax, ebx, ecx, edx; | ||
117 | |||
118 | if ((c->x86_vendor != X86_VENDOR_AMD) || (c->x86 != 6)) { | ||
119 | #ifdef MODULE | ||
120 | printk(KERN_INFO PFX "This module only works with " | ||
121 | "AMD K7 CPUs\n"); | ||
122 | #endif | ||
123 | return 0; | ||
124 | } | ||
125 | |||
126 | /* Get maximum capabilities */ | ||
127 | maxei = cpuid_eax(0x80000000); | ||
128 | if (maxei < 0x80000007) { /* Any powernow info ? */ | ||
129 | #ifdef MODULE | ||
130 | printk(KERN_INFO PFX "No powernow capabilities detected\n"); | ||
131 | #endif | ||
132 | return 0; | ||
133 | } | ||
134 | |||
135 | if ((c->x86_model == 6) && (c->x86_mask == 0)) { | ||
136 | printk(KERN_INFO PFX "K7 660[A0] core detected, " | ||
137 | "enabling errata workarounds\n"); | ||
138 | have_a0 = 1; | ||
139 | } | ||
140 | |||
141 | cpuid(0x80000007, &eax, &ebx, &ecx, &edx); | ||
142 | |||
143 | /* Check we can actually do something before we say anything.*/ | ||
144 | if (!(edx & (1 << 1 | 1 << 2))) | ||
145 | return 0; | ||
146 | |||
147 | printk(KERN_INFO PFX "PowerNOW! Technology present. Can scale: "); | ||
148 | |||
149 | if (edx & 1 << 1) { | ||
150 | printk("frequency"); | ||
151 | can_scale_bus = 1; | ||
152 | } | ||
153 | |||
154 | if ((edx & (1 << 1 | 1 << 2)) == 0x6) | ||
155 | printk(" and "); | ||
156 | |||
157 | if (edx & 1 << 2) { | ||
158 | printk("voltage"); | ||
159 | can_scale_vid = 1; | ||
160 | } | ||
161 | |||
162 | printk(".\n"); | ||
163 | return 1; | ||
164 | } | ||
165 | |||
166 | #ifdef CONFIG_X86_POWERNOW_K7_ACPI | ||
167 | static void invalidate_entry(unsigned int entry) | ||
168 | { | ||
169 | powernow_table[entry].frequency = CPUFREQ_ENTRY_INVALID; | ||
170 | } | ||
171 | #endif | ||
172 | |||
173 | static int get_ranges(unsigned char *pst) | ||
174 | { | ||
175 | unsigned int j; | ||
176 | unsigned int speed; | ||
177 | u8 fid, vid; | ||
178 | |||
179 | powernow_table = kzalloc((sizeof(struct cpufreq_frequency_table) * | ||
180 | (number_scales + 1)), GFP_KERNEL); | ||
181 | if (!powernow_table) | ||
182 | return -ENOMEM; | ||
183 | |||
184 | for (j = 0 ; j < number_scales; j++) { | ||
185 | fid = *pst++; | ||
186 | |||
187 | powernow_table[j].frequency = (fsb * fid_codes[fid]) / 10; | ||
188 | powernow_table[j].index = fid; /* lower 8 bits */ | ||
189 | |||
190 | speed = powernow_table[j].frequency; | ||
191 | |||
192 | if ((fid_codes[fid] % 10) == 5) { | ||
193 | #ifdef CONFIG_X86_POWERNOW_K7_ACPI | ||
194 | if (have_a0 == 1) | ||
195 | invalidate_entry(j); | ||
196 | #endif | ||
197 | } | ||
198 | |||
199 | if (speed < minimum_speed) | ||
200 | minimum_speed = speed; | ||
201 | if (speed > maximum_speed) | ||
202 | maximum_speed = speed; | ||
203 | |||
204 | vid = *pst++; | ||
205 | powernow_table[j].index |= (vid << 8); /* upper 8 bits */ | ||
206 | |||
207 | pr_debug(" FID: 0x%x (%d.%dx [%dMHz]) " | ||
208 | "VID: 0x%x (%d.%03dV)\n", fid, fid_codes[fid] / 10, | ||
209 | fid_codes[fid] % 10, speed/1000, vid, | ||
210 | mobile_vid_table[vid]/1000, | ||
211 | mobile_vid_table[vid]%1000); | ||
212 | } | ||
213 | powernow_table[number_scales].frequency = CPUFREQ_TABLE_END; | ||
214 | powernow_table[number_scales].index = 0; | ||
215 | |||
216 | return 0; | ||
217 | } | ||
218 | |||
219 | |||
220 | static void change_FID(int fid) | ||
221 | { | ||
222 | union msr_fidvidctl fidvidctl; | ||
223 | |||
224 | rdmsrl(MSR_K7_FID_VID_CTL, fidvidctl.val); | ||
225 | if (fidvidctl.bits.FID != fid) { | ||
226 | fidvidctl.bits.SGTC = latency; | ||
227 | fidvidctl.bits.FID = fid; | ||
228 | fidvidctl.bits.VIDC = 0; | ||
229 | fidvidctl.bits.FIDC = 1; | ||
230 | wrmsrl(MSR_K7_FID_VID_CTL, fidvidctl.val); | ||
231 | } | ||
232 | } | ||
233 | |||
234 | |||
235 | static void change_VID(int vid) | ||
236 | { | ||
237 | union msr_fidvidctl fidvidctl; | ||
238 | |||
239 | rdmsrl(MSR_K7_FID_VID_CTL, fidvidctl.val); | ||
240 | if (fidvidctl.bits.VID != vid) { | ||
241 | fidvidctl.bits.SGTC = latency; | ||
242 | fidvidctl.bits.VID = vid; | ||
243 | fidvidctl.bits.FIDC = 0; | ||
244 | fidvidctl.bits.VIDC = 1; | ||
245 | wrmsrl(MSR_K7_FID_VID_CTL, fidvidctl.val); | ||
246 | } | ||
247 | } | ||
248 | |||
249 | |||
250 | static void change_speed(unsigned int index) | ||
251 | { | ||
252 | u8 fid, vid; | ||
253 | struct cpufreq_freqs freqs; | ||
254 | union msr_fidvidstatus fidvidstatus; | ||
255 | int cfid; | ||
256 | |||
257 | /* fid are the lower 8 bits of the index we stored into | ||
258 | * the cpufreq frequency table in powernow_decode_bios, | ||
259 | * vid are the upper 8 bits. | ||
260 | */ | ||
261 | |||
262 | fid = powernow_table[index].index & 0xFF; | ||
263 | vid = (powernow_table[index].index & 0xFF00) >> 8; | ||
264 | |||
265 | freqs.cpu = 0; | ||
266 | |||
267 | rdmsrl(MSR_K7_FID_VID_STATUS, fidvidstatus.val); | ||
268 | cfid = fidvidstatus.bits.CFID; | ||
269 | freqs.old = fsb * fid_codes[cfid] / 10; | ||
270 | |||
271 | freqs.new = powernow_table[index].frequency; | ||
272 | |||
273 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
274 | |||
275 | /* Now do the magic poking into the MSRs. */ | ||
276 | |||
277 | if (have_a0 == 1) /* A0 errata 5 */ | ||
278 | local_irq_disable(); | ||
279 | |||
280 | if (freqs.old > freqs.new) { | ||
281 | /* Going down, so change FID first */ | ||
282 | change_FID(fid); | ||
283 | change_VID(vid); | ||
284 | } else { | ||
285 | /* Going up, so change VID first */ | ||
286 | change_VID(vid); | ||
287 | change_FID(fid); | ||
288 | } | ||
289 | |||
290 | |||
291 | if (have_a0 == 1) | ||
292 | local_irq_enable(); | ||
293 | |||
294 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
295 | } | ||
296 | |||
297 | |||
298 | #ifdef CONFIG_X86_POWERNOW_K7_ACPI | ||
299 | |||
300 | static struct acpi_processor_performance *acpi_processor_perf; | ||
301 | |||
302 | static int powernow_acpi_init(void) | ||
303 | { | ||
304 | int i; | ||
305 | int retval = 0; | ||
306 | union powernow_acpi_control_t pc; | ||
307 | |||
308 | if (acpi_processor_perf != NULL && powernow_table != NULL) { | ||
309 | retval = -EINVAL; | ||
310 | goto err0; | ||
311 | } | ||
312 | |||
313 | acpi_processor_perf = kzalloc(sizeof(struct acpi_processor_performance), | ||
314 | GFP_KERNEL); | ||
315 | if (!acpi_processor_perf) { | ||
316 | retval = -ENOMEM; | ||
317 | goto err0; | ||
318 | } | ||
319 | |||
320 | if (!zalloc_cpumask_var(&acpi_processor_perf->shared_cpu_map, | ||
321 | GFP_KERNEL)) { | ||
322 | retval = -ENOMEM; | ||
323 | goto err05; | ||
324 | } | ||
325 | |||
326 | if (acpi_processor_register_performance(acpi_processor_perf, 0)) { | ||
327 | retval = -EIO; | ||
328 | goto err1; | ||
329 | } | ||
330 | |||
331 | if (acpi_processor_perf->control_register.space_id != | ||
332 | ACPI_ADR_SPACE_FIXED_HARDWARE) { | ||
333 | retval = -ENODEV; | ||
334 | goto err2; | ||
335 | } | ||
336 | |||
337 | if (acpi_processor_perf->status_register.space_id != | ||
338 | ACPI_ADR_SPACE_FIXED_HARDWARE) { | ||
339 | retval = -ENODEV; | ||
340 | goto err2; | ||
341 | } | ||
342 | |||
343 | number_scales = acpi_processor_perf->state_count; | ||
344 | |||
345 | if (number_scales < 2) { | ||
346 | retval = -ENODEV; | ||
347 | goto err2; | ||
348 | } | ||
349 | |||
350 | powernow_table = kzalloc((sizeof(struct cpufreq_frequency_table) * | ||
351 | (number_scales + 1)), GFP_KERNEL); | ||
352 | if (!powernow_table) { | ||
353 | retval = -ENOMEM; | ||
354 | goto err2; | ||
355 | } | ||
356 | |||
357 | pc.val = (unsigned long) acpi_processor_perf->states[0].control; | ||
358 | for (i = 0; i < number_scales; i++) { | ||
359 | u8 fid, vid; | ||
360 | struct acpi_processor_px *state = | ||
361 | &acpi_processor_perf->states[i]; | ||
362 | unsigned int speed, speed_mhz; | ||
363 | |||
364 | pc.val = (unsigned long) state->control; | ||
365 | pr_debug("acpi: P%d: %d MHz %d mW %d uS control %08x SGTC %d\n", | ||
366 | i, | ||
367 | (u32) state->core_frequency, | ||
368 | (u32) state->power, | ||
369 | (u32) state->transition_latency, | ||
370 | (u32) state->control, | ||
371 | pc.bits.sgtc); | ||
372 | |||
373 | vid = pc.bits.vid; | ||
374 | fid = pc.bits.fid; | ||
375 | |||
376 | powernow_table[i].frequency = fsb * fid_codes[fid] / 10; | ||
377 | powernow_table[i].index = fid; /* lower 8 bits */ | ||
378 | powernow_table[i].index |= (vid << 8); /* upper 8 bits */ | ||
379 | |||
380 | speed = powernow_table[i].frequency; | ||
381 | speed_mhz = speed / 1000; | ||
382 | |||
383 | /* processor_perflib will multiply the MHz value by 1000 to | ||
384 | * get a KHz value (e.g. 1266000). However, powernow-k7 works | ||
385 | * with true KHz values (e.g. 1266768). To ensure that all | ||
386 | * powernow frequencies are available, we must ensure that | ||
387 | * ACPI doesn't restrict them, so we round up the MHz value | ||
388 | * to ensure that perflib's computed KHz value is greater than | ||
389 | * or equal to powernow's KHz value. | ||
390 | */ | ||
391 | if (speed % 1000 > 0) | ||
392 | speed_mhz++; | ||
393 | |||
394 | if ((fid_codes[fid] % 10) == 5) { | ||
395 | if (have_a0 == 1) | ||
396 | invalidate_entry(i); | ||
397 | } | ||
398 | |||
399 | pr_debug(" FID: 0x%x (%d.%dx [%dMHz]) " | ||
400 | "VID: 0x%x (%d.%03dV)\n", fid, fid_codes[fid] / 10, | ||
401 | fid_codes[fid] % 10, speed_mhz, vid, | ||
402 | mobile_vid_table[vid]/1000, | ||
403 | mobile_vid_table[vid]%1000); | ||
404 | |||
405 | if (state->core_frequency != speed_mhz) { | ||
406 | state->core_frequency = speed_mhz; | ||
407 | pr_debug(" Corrected ACPI frequency to %d\n", | ||
408 | speed_mhz); | ||
409 | } | ||
410 | |||
411 | if (latency < pc.bits.sgtc) | ||
412 | latency = pc.bits.sgtc; | ||
413 | |||
414 | if (speed < minimum_speed) | ||
415 | minimum_speed = speed; | ||
416 | if (speed > maximum_speed) | ||
417 | maximum_speed = speed; | ||
418 | } | ||
419 | |||
420 | powernow_table[i].frequency = CPUFREQ_TABLE_END; | ||
421 | powernow_table[i].index = 0; | ||
422 | |||
423 | /* notify BIOS that we exist */ | ||
424 | acpi_processor_notify_smm(THIS_MODULE); | ||
425 | |||
426 | return 0; | ||
427 | |||
428 | err2: | ||
429 | acpi_processor_unregister_performance(acpi_processor_perf, 0); | ||
430 | err1: | ||
431 | free_cpumask_var(acpi_processor_perf->shared_cpu_map); | ||
432 | err05: | ||
433 | kfree(acpi_processor_perf); | ||
434 | err0: | ||
435 | printk(KERN_WARNING PFX "ACPI perflib can not be used on " | ||
436 | "this platform\n"); | ||
437 | acpi_processor_perf = NULL; | ||
438 | return retval; | ||
439 | } | ||
440 | #else | ||
441 | static int powernow_acpi_init(void) | ||
442 | { | ||
443 | printk(KERN_INFO PFX "no support for ACPI processor found." | ||
444 | " Please recompile your kernel with ACPI processor\n"); | ||
445 | return -EINVAL; | ||
446 | } | ||
447 | #endif | ||
448 | |||
449 | static void print_pst_entry(struct pst_s *pst, unsigned int j) | ||
450 | { | ||
451 | pr_debug("PST:%d (@%p)\n", j, pst); | ||
452 | pr_debug(" cpuid: 0x%x fsb: %d maxFID: 0x%x startvid: 0x%x\n", | ||
453 | pst->cpuid, pst->fsbspeed, pst->maxfid, pst->startvid); | ||
454 | } | ||
455 | |||
456 | static int powernow_decode_bios(int maxfid, int startvid) | ||
457 | { | ||
458 | struct psb_s *psb; | ||
459 | struct pst_s *pst; | ||
460 | unsigned int i, j; | ||
461 | unsigned char *p; | ||
462 | unsigned int etuple; | ||
463 | unsigned int ret; | ||
464 | |||
465 | etuple = cpuid_eax(0x80000001); | ||
466 | |||
467 | for (i = 0xC0000; i < 0xffff0 ; i += 16) { | ||
468 | |||
469 | p = phys_to_virt(i); | ||
470 | |||
471 | if (memcmp(p, "AMDK7PNOW!", 10) == 0) { | ||
472 | pr_debug("Found PSB header at %p\n", p); | ||
473 | psb = (struct psb_s *) p; | ||
474 | pr_debug("Table version: 0x%x\n", psb->tableversion); | ||
475 | if (psb->tableversion != 0x12) { | ||
476 | printk(KERN_INFO PFX "Sorry, only v1.2 tables" | ||
477 | " supported right now\n"); | ||
478 | return -ENODEV; | ||
479 | } | ||
480 | |||
481 | pr_debug("Flags: 0x%x\n", psb->flags); | ||
482 | if ((psb->flags & 1) == 0) | ||
483 | pr_debug("Mobile voltage regulator\n"); | ||
484 | else | ||
485 | pr_debug("Desktop voltage regulator\n"); | ||
486 | |||
487 | latency = psb->settlingtime; | ||
488 | if (latency < 100) { | ||
489 | printk(KERN_INFO PFX "BIOS set settling time " | ||
490 | "to %d microseconds. " | ||
491 | "Should be at least 100. " | ||
492 | "Correcting.\n", latency); | ||
493 | latency = 100; | ||
494 | } | ||
495 | pr_debug("Settling Time: %d microseconds.\n", | ||
496 | psb->settlingtime); | ||
497 | pr_debug("Has %d PST tables. (Only dumping ones " | ||
498 | "relevant to this CPU).\n", | ||
499 | psb->numpst); | ||
500 | |||
501 | p += sizeof(struct psb_s); | ||
502 | |||
503 | pst = (struct pst_s *) p; | ||
504 | |||
505 | for (j = 0; j < psb->numpst; j++) { | ||
506 | pst = (struct pst_s *) p; | ||
507 | number_scales = pst->numpstates; | ||
508 | |||
509 | if ((etuple == pst->cpuid) && | ||
510 | check_fsb(pst->fsbspeed) && | ||
511 | (maxfid == pst->maxfid) && | ||
512 | (startvid == pst->startvid)) { | ||
513 | print_pst_entry(pst, j); | ||
514 | p = (char *)pst + sizeof(struct pst_s); | ||
515 | ret = get_ranges(p); | ||
516 | return ret; | ||
517 | } else { | ||
518 | unsigned int k; | ||
519 | p = (char *)pst + sizeof(struct pst_s); | ||
520 | for (k = 0; k < number_scales; k++) | ||
521 | p += 2; | ||
522 | } | ||
523 | } | ||
524 | printk(KERN_INFO PFX "No PST tables match this cpuid " | ||
525 | "(0x%x)\n", etuple); | ||
526 | printk(KERN_INFO PFX "This is indicative of a broken " | ||
527 | "BIOS.\n"); | ||
528 | |||
529 | return -EINVAL; | ||
530 | } | ||
531 | p++; | ||
532 | } | ||
533 | |||
534 | return -ENODEV; | ||
535 | } | ||
536 | |||
537 | |||
538 | static int powernow_target(struct cpufreq_policy *policy, | ||
539 | unsigned int target_freq, | ||
540 | unsigned int relation) | ||
541 | { | ||
542 | unsigned int newstate; | ||
543 | |||
544 | if (cpufreq_frequency_table_target(policy, powernow_table, target_freq, | ||
545 | relation, &newstate)) | ||
546 | return -EINVAL; | ||
547 | |||
548 | change_speed(newstate); | ||
549 | |||
550 | return 0; | ||
551 | } | ||
552 | |||
553 | |||
554 | static int powernow_verify(struct cpufreq_policy *policy) | ||
555 | { | ||
556 | return cpufreq_frequency_table_verify(policy, powernow_table); | ||
557 | } | ||
558 | |||
559 | /* | ||
560 | * We use the fact that the bus frequency is somehow | ||
561 | * a multiple of 100000/3 khz, then we compute sgtc according | ||
562 | * to this multiple. | ||
563 | * That way, we match more how AMD thinks all of that work. | ||
564 | * We will then get the same kind of behaviour already tested under | ||
565 | * the "well-known" other OS. | ||
566 | */ | ||
567 | static int __cpuinit fixup_sgtc(void) | ||
568 | { | ||
569 | unsigned int sgtc; | ||
570 | unsigned int m; | ||
571 | |||
572 | m = fsb / 3333; | ||
573 | if ((m % 10) >= 5) | ||
574 | m += 5; | ||
575 | |||
576 | m /= 10; | ||
577 | |||
578 | sgtc = 100 * m * latency; | ||
579 | sgtc = sgtc / 3; | ||
580 | if (sgtc > 0xfffff) { | ||
581 | printk(KERN_WARNING PFX "SGTC too large %d\n", sgtc); | ||
582 | sgtc = 0xfffff; | ||
583 | } | ||
584 | return sgtc; | ||
585 | } | ||
586 | |||
587 | static unsigned int powernow_get(unsigned int cpu) | ||
588 | { | ||
589 | union msr_fidvidstatus fidvidstatus; | ||
590 | unsigned int cfid; | ||
591 | |||
592 | if (cpu) | ||
593 | return 0; | ||
594 | rdmsrl(MSR_K7_FID_VID_STATUS, fidvidstatus.val); | ||
595 | cfid = fidvidstatus.bits.CFID; | ||
596 | |||
597 | return fsb * fid_codes[cfid] / 10; | ||
598 | } | ||
599 | |||
600 | |||
601 | static int __cpuinit acer_cpufreq_pst(const struct dmi_system_id *d) | ||
602 | { | ||
603 | printk(KERN_WARNING PFX | ||
604 | "%s laptop with broken PST tables in BIOS detected.\n", | ||
605 | d->ident); | ||
606 | printk(KERN_WARNING PFX | ||
607 | "You need to downgrade to 3A21 (09/09/2002), or try a newer " | ||
608 | "BIOS than 3A71 (01/20/2003)\n"); | ||
609 | printk(KERN_WARNING PFX | ||
610 | "cpufreq scaling has been disabled as a result of this.\n"); | ||
611 | return 0; | ||
612 | } | ||
613 | |||
614 | /* | ||
615 | * Some Athlon laptops have really fucked PST tables. | ||
616 | * A BIOS update is all that can save them. | ||
617 | * Mention this, and disable cpufreq. | ||
618 | */ | ||
619 | static struct dmi_system_id __cpuinitdata powernow_dmi_table[] = { | ||
620 | { | ||
621 | .callback = acer_cpufreq_pst, | ||
622 | .ident = "Acer Aspire", | ||
623 | .matches = { | ||
624 | DMI_MATCH(DMI_SYS_VENDOR, "Insyde Software"), | ||
625 | DMI_MATCH(DMI_BIOS_VERSION, "3A71"), | ||
626 | }, | ||
627 | }, | ||
628 | { } | ||
629 | }; | ||
630 | |||
631 | static int __cpuinit powernow_cpu_init(struct cpufreq_policy *policy) | ||
632 | { | ||
633 | union msr_fidvidstatus fidvidstatus; | ||
634 | int result; | ||
635 | |||
636 | if (policy->cpu != 0) | ||
637 | return -ENODEV; | ||
638 | |||
639 | rdmsrl(MSR_K7_FID_VID_STATUS, fidvidstatus.val); | ||
640 | |||
641 | recalibrate_cpu_khz(); | ||
642 | |||
643 | fsb = (10 * cpu_khz) / fid_codes[fidvidstatus.bits.CFID]; | ||
644 | if (!fsb) { | ||
645 | printk(KERN_WARNING PFX "can not determine bus frequency\n"); | ||
646 | return -EINVAL; | ||
647 | } | ||
648 | pr_debug("FSB: %3dMHz\n", fsb/1000); | ||
649 | |||
650 | if (dmi_check_system(powernow_dmi_table) || acpi_force) { | ||
651 | printk(KERN_INFO PFX "PSB/PST known to be broken. " | ||
652 | "Trying ACPI instead\n"); | ||
653 | result = powernow_acpi_init(); | ||
654 | } else { | ||
655 | result = powernow_decode_bios(fidvidstatus.bits.MFID, | ||
656 | fidvidstatus.bits.SVID); | ||
657 | if (result) { | ||
658 | printk(KERN_INFO PFX "Trying ACPI perflib\n"); | ||
659 | maximum_speed = 0; | ||
660 | minimum_speed = -1; | ||
661 | latency = 0; | ||
662 | result = powernow_acpi_init(); | ||
663 | if (result) { | ||
664 | printk(KERN_INFO PFX | ||
665 | "ACPI and legacy methods failed\n"); | ||
666 | } | ||
667 | } else { | ||
668 | /* SGTC use the bus clock as timer */ | ||
669 | latency = fixup_sgtc(); | ||
670 | printk(KERN_INFO PFX "SGTC: %d\n", latency); | ||
671 | } | ||
672 | } | ||
673 | |||
674 | if (result) | ||
675 | return result; | ||
676 | |||
677 | printk(KERN_INFO PFX "Minimum speed %d MHz. Maximum speed %d MHz.\n", | ||
678 | minimum_speed/1000, maximum_speed/1000); | ||
679 | |||
680 | policy->cpuinfo.transition_latency = | ||
681 | cpufreq_scale(2000000UL, fsb, latency); | ||
682 | |||
683 | policy->cur = powernow_get(0); | ||
684 | |||
685 | cpufreq_frequency_table_get_attr(powernow_table, policy->cpu); | ||
686 | |||
687 | return cpufreq_frequency_table_cpuinfo(policy, powernow_table); | ||
688 | } | ||
689 | |||
690 | static int powernow_cpu_exit(struct cpufreq_policy *policy) | ||
691 | { | ||
692 | cpufreq_frequency_table_put_attr(policy->cpu); | ||
693 | |||
694 | #ifdef CONFIG_X86_POWERNOW_K7_ACPI | ||
695 | if (acpi_processor_perf) { | ||
696 | acpi_processor_unregister_performance(acpi_processor_perf, 0); | ||
697 | free_cpumask_var(acpi_processor_perf->shared_cpu_map); | ||
698 | kfree(acpi_processor_perf); | ||
699 | } | ||
700 | #endif | ||
701 | |||
702 | kfree(powernow_table); | ||
703 | return 0; | ||
704 | } | ||
705 | |||
706 | static struct freq_attr *powernow_table_attr[] = { | ||
707 | &cpufreq_freq_attr_scaling_available_freqs, | ||
708 | NULL, | ||
709 | }; | ||
710 | |||
711 | static struct cpufreq_driver powernow_driver = { | ||
712 | .verify = powernow_verify, | ||
713 | .target = powernow_target, | ||
714 | .get = powernow_get, | ||
715 | #ifdef CONFIG_X86_POWERNOW_K7_ACPI | ||
716 | .bios_limit = acpi_processor_get_bios_limit, | ||
717 | #endif | ||
718 | .init = powernow_cpu_init, | ||
719 | .exit = powernow_cpu_exit, | ||
720 | .name = "powernow-k7", | ||
721 | .owner = THIS_MODULE, | ||
722 | .attr = powernow_table_attr, | ||
723 | }; | ||
724 | |||
725 | static int __init powernow_init(void) | ||
726 | { | ||
727 | if (check_powernow() == 0) | ||
728 | return -ENODEV; | ||
729 | return cpufreq_register_driver(&powernow_driver); | ||
730 | } | ||
731 | |||
732 | |||
733 | static void __exit powernow_exit(void) | ||
734 | { | ||
735 | cpufreq_unregister_driver(&powernow_driver); | ||
736 | } | ||
737 | |||
738 | module_param(acpi_force, int, 0444); | ||
739 | MODULE_PARM_DESC(acpi_force, "Force ACPI to be used."); | ||
740 | |||
741 | MODULE_AUTHOR("Dave Jones <davej@redhat.com>"); | ||
742 | MODULE_DESCRIPTION("Powernow driver for AMD K7 processors."); | ||
743 | MODULE_LICENSE("GPL"); | ||
744 | |||
745 | late_initcall(powernow_init); | ||
746 | module_exit(powernow_exit); | ||
747 | |||
diff --git a/drivers/cpufreq/powernow-k7.h b/drivers/cpufreq/powernow-k7.h new file mode 100644 index 000000000000..35fb4eaf6e1c --- /dev/null +++ b/drivers/cpufreq/powernow-k7.h | |||
@@ -0,0 +1,43 @@ | |||
1 | /* | ||
2 | * (C) 2003 Dave Jones. | ||
3 | * | ||
4 | * Licensed under the terms of the GNU GPL License version 2. | ||
5 | * | ||
6 | * AMD-specific information | ||
7 | * | ||
8 | */ | ||
9 | |||
10 | union msr_fidvidctl { | ||
11 | struct { | ||
12 | unsigned FID:5, // 4:0 | ||
13 | reserved1:3, // 7:5 | ||
14 | VID:5, // 12:8 | ||
15 | reserved2:3, // 15:13 | ||
16 | FIDC:1, // 16 | ||
17 | VIDC:1, // 17 | ||
18 | reserved3:2, // 19:18 | ||
19 | FIDCHGRATIO:1, // 20 | ||
20 | reserved4:11, // 31-21 | ||
21 | SGTC:20, // 32:51 | ||
22 | reserved5:12; // 63:52 | ||
23 | } bits; | ||
24 | unsigned long long val; | ||
25 | }; | ||
26 | |||
27 | union msr_fidvidstatus { | ||
28 | struct { | ||
29 | unsigned CFID:5, // 4:0 | ||
30 | reserved1:3, // 7:5 | ||
31 | SFID:5, // 12:8 | ||
32 | reserved2:3, // 15:13 | ||
33 | MFID:5, // 20:16 | ||
34 | reserved3:11, // 31:21 | ||
35 | CVID:5, // 36:32 | ||
36 | reserved4:3, // 39:37 | ||
37 | SVID:5, // 44:40 | ||
38 | reserved5:3, // 47:45 | ||
39 | MVID:5, // 52:48 | ||
40 | reserved6:11; // 63:53 | ||
41 | } bits; | ||
42 | unsigned long long val; | ||
43 | }; | ||
diff --git a/drivers/cpufreq/powernow-k8.c b/drivers/cpufreq/powernow-k8.c new file mode 100644 index 000000000000..83479b6fb9a1 --- /dev/null +++ b/drivers/cpufreq/powernow-k8.c | |||
@@ -0,0 +1,1607 @@ | |||
1 | /* | ||
2 | * (c) 2003-2010 Advanced Micro Devices, Inc. | ||
3 | * Your use of this code is subject to the terms and conditions of the | ||
4 | * GNU general public license version 2. See "COPYING" or | ||
5 | * http://www.gnu.org/licenses/gpl.html | ||
6 | * | ||
7 | * Support : mark.langsdorf@amd.com | ||
8 | * | ||
9 | * Based on the powernow-k7.c module written by Dave Jones. | ||
10 | * (C) 2003 Dave Jones on behalf of SuSE Labs | ||
11 | * (C) 2004 Dominik Brodowski <linux@brodo.de> | ||
12 | * (C) 2004 Pavel Machek <pavel@ucw.cz> | ||
13 | * Licensed under the terms of the GNU GPL License version 2. | ||
14 | * Based upon datasheets & sample CPUs kindly provided by AMD. | ||
15 | * | ||
16 | * Valuable input gratefully received from Dave Jones, Pavel Machek, | ||
17 | * Dominik Brodowski, Jacob Shin, and others. | ||
18 | * Originally developed by Paul Devriendt. | ||
19 | * Processor information obtained from Chapter 9 (Power and Thermal Management) | ||
20 | * of the "BIOS and Kernel Developer's Guide for the AMD Athlon 64 and AMD | ||
21 | * Opteron Processors" available for download from www.amd.com | ||
22 | * | ||
23 | * Tables for specific CPUs can be inferred from | ||
24 | * http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/30430.pdf | ||
25 | */ | ||
26 | |||
27 | #include <linux/kernel.h> | ||
28 | #include <linux/smp.h> | ||
29 | #include <linux/module.h> | ||
30 | #include <linux/init.h> | ||
31 | #include <linux/cpufreq.h> | ||
32 | #include <linux/slab.h> | ||
33 | #include <linux/string.h> | ||
34 | #include <linux/cpumask.h> | ||
35 | #include <linux/sched.h> /* for current / set_cpus_allowed() */ | ||
36 | #include <linux/io.h> | ||
37 | #include <linux/delay.h> | ||
38 | |||
39 | #include <asm/msr.h> | ||
40 | |||
41 | #include <linux/acpi.h> | ||
42 | #include <linux/mutex.h> | ||
43 | #include <acpi/processor.h> | ||
44 | |||
45 | #define PFX "powernow-k8: " | ||
46 | #define VERSION "version 2.20.00" | ||
47 | #include "powernow-k8.h" | ||
48 | #include "mperf.h" | ||
49 | |||
50 | /* serialize freq changes */ | ||
51 | static DEFINE_MUTEX(fidvid_mutex); | ||
52 | |||
53 | static DEFINE_PER_CPU(struct powernow_k8_data *, powernow_data); | ||
54 | |||
55 | static int cpu_family = CPU_OPTERON; | ||
56 | |||
57 | /* core performance boost */ | ||
58 | static bool cpb_capable, cpb_enabled; | ||
59 | static struct msr __percpu *msrs; | ||
60 | |||
61 | static struct cpufreq_driver cpufreq_amd64_driver; | ||
62 | |||
63 | #ifndef CONFIG_SMP | ||
64 | static inline const struct cpumask *cpu_core_mask(int cpu) | ||
65 | { | ||
66 | return cpumask_of(0); | ||
67 | } | ||
68 | #endif | ||
69 | |||
70 | /* Return a frequency in MHz, given an input fid */ | ||
71 | static u32 find_freq_from_fid(u32 fid) | ||
72 | { | ||
73 | return 800 + (fid * 100); | ||
74 | } | ||
75 | |||
76 | /* Return a frequency in KHz, given an input fid */ | ||
77 | static u32 find_khz_freq_from_fid(u32 fid) | ||
78 | { | ||
79 | return 1000 * find_freq_from_fid(fid); | ||
80 | } | ||
81 | |||
82 | static u32 find_khz_freq_from_pstate(struct cpufreq_frequency_table *data, | ||
83 | u32 pstate) | ||
84 | { | ||
85 | return data[pstate].frequency; | ||
86 | } | ||
87 | |||
88 | /* Return the vco fid for an input fid | ||
89 | * | ||
90 | * Each "low" fid has corresponding "high" fid, and you can get to "low" fids | ||
91 | * only from corresponding high fids. This returns "high" fid corresponding to | ||
92 | * "low" one. | ||
93 | */ | ||
94 | static u32 convert_fid_to_vco_fid(u32 fid) | ||
95 | { | ||
96 | if (fid < HI_FID_TABLE_BOTTOM) | ||
97 | return 8 + (2 * fid); | ||
98 | else | ||
99 | return fid; | ||
100 | } | ||
101 | |||
102 | /* | ||
103 | * Return 1 if the pending bit is set. Unless we just instructed the processor | ||
104 | * to transition to a new state, seeing this bit set is really bad news. | ||
105 | */ | ||
106 | static int pending_bit_stuck(void) | ||
107 | { | ||
108 | u32 lo, hi; | ||
109 | |||
110 | if (cpu_family == CPU_HW_PSTATE) | ||
111 | return 0; | ||
112 | |||
113 | rdmsr(MSR_FIDVID_STATUS, lo, hi); | ||
114 | return lo & MSR_S_LO_CHANGE_PENDING ? 1 : 0; | ||
115 | } | ||
116 | |||
117 | /* | ||
118 | * Update the global current fid / vid values from the status msr. | ||
119 | * Returns 1 on error. | ||
120 | */ | ||
121 | static int query_current_values_with_pending_wait(struct powernow_k8_data *data) | ||
122 | { | ||
123 | u32 lo, hi; | ||
124 | u32 i = 0; | ||
125 | |||
126 | if (cpu_family == CPU_HW_PSTATE) { | ||
127 | rdmsr(MSR_PSTATE_STATUS, lo, hi); | ||
128 | i = lo & HW_PSTATE_MASK; | ||
129 | data->currpstate = i; | ||
130 | |||
131 | /* | ||
132 | * a workaround for family 11h erratum 311 might cause | ||
133 | * an "out-of-range Pstate if the core is in Pstate-0 | ||
134 | */ | ||
135 | if ((boot_cpu_data.x86 == 0x11) && (i >= data->numps)) | ||
136 | data->currpstate = HW_PSTATE_0; | ||
137 | |||
138 | return 0; | ||
139 | } | ||
140 | do { | ||
141 | if (i++ > 10000) { | ||
142 | pr_debug("detected change pending stuck\n"); | ||
143 | return 1; | ||
144 | } | ||
145 | rdmsr(MSR_FIDVID_STATUS, lo, hi); | ||
146 | } while (lo & MSR_S_LO_CHANGE_PENDING); | ||
147 | |||
148 | data->currvid = hi & MSR_S_HI_CURRENT_VID; | ||
149 | data->currfid = lo & MSR_S_LO_CURRENT_FID; | ||
150 | |||
151 | return 0; | ||
152 | } | ||
153 | |||
154 | /* the isochronous relief time */ | ||
155 | static void count_off_irt(struct powernow_k8_data *data) | ||
156 | { | ||
157 | udelay((1 << data->irt) * 10); | ||
158 | return; | ||
159 | } | ||
160 | |||
161 | /* the voltage stabilization time */ | ||
162 | static void count_off_vst(struct powernow_k8_data *data) | ||
163 | { | ||
164 | udelay(data->vstable * VST_UNITS_20US); | ||
165 | return; | ||
166 | } | ||
167 | |||
168 | /* need to init the control msr to a safe value (for each cpu) */ | ||
169 | static void fidvid_msr_init(void) | ||
170 | { | ||
171 | u32 lo, hi; | ||
172 | u8 fid, vid; | ||
173 | |||
174 | rdmsr(MSR_FIDVID_STATUS, lo, hi); | ||
175 | vid = hi & MSR_S_HI_CURRENT_VID; | ||
176 | fid = lo & MSR_S_LO_CURRENT_FID; | ||
177 | lo = fid | (vid << MSR_C_LO_VID_SHIFT); | ||
178 | hi = MSR_C_HI_STP_GNT_BENIGN; | ||
179 | pr_debug("cpu%d, init lo 0x%x, hi 0x%x\n", smp_processor_id(), lo, hi); | ||
180 | wrmsr(MSR_FIDVID_CTL, lo, hi); | ||
181 | } | ||
182 | |||
183 | /* write the new fid value along with the other control fields to the msr */ | ||
184 | static int write_new_fid(struct powernow_k8_data *data, u32 fid) | ||
185 | { | ||
186 | u32 lo; | ||
187 | u32 savevid = data->currvid; | ||
188 | u32 i = 0; | ||
189 | |||
190 | if ((fid & INVALID_FID_MASK) || (data->currvid & INVALID_VID_MASK)) { | ||
191 | printk(KERN_ERR PFX "internal error - overflow on fid write\n"); | ||
192 | return 1; | ||
193 | } | ||
194 | |||
195 | lo = fid; | ||
196 | lo |= (data->currvid << MSR_C_LO_VID_SHIFT); | ||
197 | lo |= MSR_C_LO_INIT_FID_VID; | ||
198 | |||
199 | pr_debug("writing fid 0x%x, lo 0x%x, hi 0x%x\n", | ||
200 | fid, lo, data->plllock * PLL_LOCK_CONVERSION); | ||
201 | |||
202 | do { | ||
203 | wrmsr(MSR_FIDVID_CTL, lo, data->plllock * PLL_LOCK_CONVERSION); | ||
204 | if (i++ > 100) { | ||
205 | printk(KERN_ERR PFX | ||
206 | "Hardware error - pending bit very stuck - " | ||
207 | "no further pstate changes possible\n"); | ||
208 | return 1; | ||
209 | } | ||
210 | } while (query_current_values_with_pending_wait(data)); | ||
211 | |||
212 | count_off_irt(data); | ||
213 | |||
214 | if (savevid != data->currvid) { | ||
215 | printk(KERN_ERR PFX | ||
216 | "vid change on fid trans, old 0x%x, new 0x%x\n", | ||
217 | savevid, data->currvid); | ||
218 | return 1; | ||
219 | } | ||
220 | |||
221 | if (fid != data->currfid) { | ||
222 | printk(KERN_ERR PFX | ||
223 | "fid trans failed, fid 0x%x, curr 0x%x\n", fid, | ||
224 | data->currfid); | ||
225 | return 1; | ||
226 | } | ||
227 | |||
228 | return 0; | ||
229 | } | ||
230 | |||
231 | /* Write a new vid to the hardware */ | ||
232 | static int write_new_vid(struct powernow_k8_data *data, u32 vid) | ||
233 | { | ||
234 | u32 lo; | ||
235 | u32 savefid = data->currfid; | ||
236 | int i = 0; | ||
237 | |||
238 | if ((data->currfid & INVALID_FID_MASK) || (vid & INVALID_VID_MASK)) { | ||
239 | printk(KERN_ERR PFX "internal error - overflow on vid write\n"); | ||
240 | return 1; | ||
241 | } | ||
242 | |||
243 | lo = data->currfid; | ||
244 | lo |= (vid << MSR_C_LO_VID_SHIFT); | ||
245 | lo |= MSR_C_LO_INIT_FID_VID; | ||
246 | |||
247 | pr_debug("writing vid 0x%x, lo 0x%x, hi 0x%x\n", | ||
248 | vid, lo, STOP_GRANT_5NS); | ||
249 | |||
250 | do { | ||
251 | wrmsr(MSR_FIDVID_CTL, lo, STOP_GRANT_5NS); | ||
252 | if (i++ > 100) { | ||
253 | printk(KERN_ERR PFX "internal error - pending bit " | ||
254 | "very stuck - no further pstate " | ||
255 | "changes possible\n"); | ||
256 | return 1; | ||
257 | } | ||
258 | } while (query_current_values_with_pending_wait(data)); | ||
259 | |||
260 | if (savefid != data->currfid) { | ||
261 | printk(KERN_ERR PFX "fid changed on vid trans, old " | ||
262 | "0x%x new 0x%x\n", | ||
263 | savefid, data->currfid); | ||
264 | return 1; | ||
265 | } | ||
266 | |||
267 | if (vid != data->currvid) { | ||
268 | printk(KERN_ERR PFX "vid trans failed, vid 0x%x, " | ||
269 | "curr 0x%x\n", | ||
270 | vid, data->currvid); | ||
271 | return 1; | ||
272 | } | ||
273 | |||
274 | return 0; | ||
275 | } | ||
276 | |||
277 | /* | ||
278 | * Reduce the vid by the max of step or reqvid. | ||
279 | * Decreasing vid codes represent increasing voltages: | ||
280 | * vid of 0 is 1.550V, vid of 0x1e is 0.800V, vid of VID_OFF is off. | ||
281 | */ | ||
282 | static int decrease_vid_code_by_step(struct powernow_k8_data *data, | ||
283 | u32 reqvid, u32 step) | ||
284 | { | ||
285 | if ((data->currvid - reqvid) > step) | ||
286 | reqvid = data->currvid - step; | ||
287 | |||
288 | if (write_new_vid(data, reqvid)) | ||
289 | return 1; | ||
290 | |||
291 | count_off_vst(data); | ||
292 | |||
293 | return 0; | ||
294 | } | ||
295 | |||
296 | /* Change hardware pstate by single MSR write */ | ||
297 | static int transition_pstate(struct powernow_k8_data *data, u32 pstate) | ||
298 | { | ||
299 | wrmsr(MSR_PSTATE_CTRL, pstate, 0); | ||
300 | data->currpstate = pstate; | ||
301 | return 0; | ||
302 | } | ||
303 | |||
304 | /* Change Opteron/Athlon64 fid and vid, by the 3 phases. */ | ||
305 | static int transition_fid_vid(struct powernow_k8_data *data, | ||
306 | u32 reqfid, u32 reqvid) | ||
307 | { | ||
308 | if (core_voltage_pre_transition(data, reqvid, reqfid)) | ||
309 | return 1; | ||
310 | |||
311 | if (core_frequency_transition(data, reqfid)) | ||
312 | return 1; | ||
313 | |||
314 | if (core_voltage_post_transition(data, reqvid)) | ||
315 | return 1; | ||
316 | |||
317 | if (query_current_values_with_pending_wait(data)) | ||
318 | return 1; | ||
319 | |||
320 | if ((reqfid != data->currfid) || (reqvid != data->currvid)) { | ||
321 | printk(KERN_ERR PFX "failed (cpu%d): req 0x%x 0x%x, " | ||
322 | "curr 0x%x 0x%x\n", | ||
323 | smp_processor_id(), | ||
324 | reqfid, reqvid, data->currfid, data->currvid); | ||
325 | return 1; | ||
326 | } | ||
327 | |||
328 | pr_debug("transitioned (cpu%d): new fid 0x%x, vid 0x%x\n", | ||
329 | smp_processor_id(), data->currfid, data->currvid); | ||
330 | |||
331 | return 0; | ||
332 | } | ||
333 | |||
334 | /* Phase 1 - core voltage transition ... setup voltage */ | ||
335 | static int core_voltage_pre_transition(struct powernow_k8_data *data, | ||
336 | u32 reqvid, u32 reqfid) | ||
337 | { | ||
338 | u32 rvosteps = data->rvo; | ||
339 | u32 savefid = data->currfid; | ||
340 | u32 maxvid, lo, rvomult = 1; | ||
341 | |||
342 | pr_debug("ph1 (cpu%d): start, currfid 0x%x, currvid 0x%x, " | ||
343 | "reqvid 0x%x, rvo 0x%x\n", | ||
344 | smp_processor_id(), | ||
345 | data->currfid, data->currvid, reqvid, data->rvo); | ||
346 | |||
347 | if ((savefid < LO_FID_TABLE_TOP) && (reqfid < LO_FID_TABLE_TOP)) | ||
348 | rvomult = 2; | ||
349 | rvosteps *= rvomult; | ||
350 | rdmsr(MSR_FIDVID_STATUS, lo, maxvid); | ||
351 | maxvid = 0x1f & (maxvid >> 16); | ||
352 | pr_debug("ph1 maxvid=0x%x\n", maxvid); | ||
353 | if (reqvid < maxvid) /* lower numbers are higher voltages */ | ||
354 | reqvid = maxvid; | ||
355 | |||
356 | while (data->currvid > reqvid) { | ||
357 | pr_debug("ph1: curr 0x%x, req vid 0x%x\n", | ||
358 | data->currvid, reqvid); | ||
359 | if (decrease_vid_code_by_step(data, reqvid, data->vidmvs)) | ||
360 | return 1; | ||
361 | } | ||
362 | |||
363 | while ((rvosteps > 0) && | ||
364 | ((rvomult * data->rvo + data->currvid) > reqvid)) { | ||
365 | if (data->currvid == maxvid) { | ||
366 | rvosteps = 0; | ||
367 | } else { | ||
368 | pr_debug("ph1: changing vid for rvo, req 0x%x\n", | ||
369 | data->currvid - 1); | ||
370 | if (decrease_vid_code_by_step(data, data->currvid-1, 1)) | ||
371 | return 1; | ||
372 | rvosteps--; | ||
373 | } | ||
374 | } | ||
375 | |||
376 | if (query_current_values_with_pending_wait(data)) | ||
377 | return 1; | ||
378 | |||
379 | if (savefid != data->currfid) { | ||
380 | printk(KERN_ERR PFX "ph1 err, currfid changed 0x%x\n", | ||
381 | data->currfid); | ||
382 | return 1; | ||
383 | } | ||
384 | |||
385 | pr_debug("ph1 complete, currfid 0x%x, currvid 0x%x\n", | ||
386 | data->currfid, data->currvid); | ||
387 | |||
388 | return 0; | ||
389 | } | ||
390 | |||
391 | /* Phase 2 - core frequency transition */ | ||
392 | static int core_frequency_transition(struct powernow_k8_data *data, u32 reqfid) | ||
393 | { | ||
394 | u32 vcoreqfid, vcocurrfid, vcofiddiff; | ||
395 | u32 fid_interval, savevid = data->currvid; | ||
396 | |||
397 | if (data->currfid == reqfid) { | ||
398 | printk(KERN_ERR PFX "ph2 null fid transition 0x%x\n", | ||
399 | data->currfid); | ||
400 | return 0; | ||
401 | } | ||
402 | |||
403 | pr_debug("ph2 (cpu%d): starting, currfid 0x%x, currvid 0x%x, " | ||
404 | "reqfid 0x%x\n", | ||
405 | smp_processor_id(), | ||
406 | data->currfid, data->currvid, reqfid); | ||
407 | |||
408 | vcoreqfid = convert_fid_to_vco_fid(reqfid); | ||
409 | vcocurrfid = convert_fid_to_vco_fid(data->currfid); | ||
410 | vcofiddiff = vcocurrfid > vcoreqfid ? vcocurrfid - vcoreqfid | ||
411 | : vcoreqfid - vcocurrfid; | ||
412 | |||
413 | if ((reqfid <= LO_FID_TABLE_TOP) && (data->currfid <= LO_FID_TABLE_TOP)) | ||
414 | vcofiddiff = 0; | ||
415 | |||
416 | while (vcofiddiff > 2) { | ||
417 | (data->currfid & 1) ? (fid_interval = 1) : (fid_interval = 2); | ||
418 | |||
419 | if (reqfid > data->currfid) { | ||
420 | if (data->currfid > LO_FID_TABLE_TOP) { | ||
421 | if (write_new_fid(data, | ||
422 | data->currfid + fid_interval)) | ||
423 | return 1; | ||
424 | } else { | ||
425 | if (write_new_fid | ||
426 | (data, | ||
427 | 2 + convert_fid_to_vco_fid(data->currfid))) | ||
428 | return 1; | ||
429 | } | ||
430 | } else { | ||
431 | if (write_new_fid(data, data->currfid - fid_interval)) | ||
432 | return 1; | ||
433 | } | ||
434 | |||
435 | vcocurrfid = convert_fid_to_vco_fid(data->currfid); | ||
436 | vcofiddiff = vcocurrfid > vcoreqfid ? vcocurrfid - vcoreqfid | ||
437 | : vcoreqfid - vcocurrfid; | ||
438 | } | ||
439 | |||
440 | if (write_new_fid(data, reqfid)) | ||
441 | return 1; | ||
442 | |||
443 | if (query_current_values_with_pending_wait(data)) | ||
444 | return 1; | ||
445 | |||
446 | if (data->currfid != reqfid) { | ||
447 | printk(KERN_ERR PFX | ||
448 | "ph2: mismatch, failed fid transition, " | ||
449 | "curr 0x%x, req 0x%x\n", | ||
450 | data->currfid, reqfid); | ||
451 | return 1; | ||
452 | } | ||
453 | |||
454 | if (savevid != data->currvid) { | ||
455 | printk(KERN_ERR PFX "ph2: vid changed, save 0x%x, curr 0x%x\n", | ||
456 | savevid, data->currvid); | ||
457 | return 1; | ||
458 | } | ||
459 | |||
460 | pr_debug("ph2 complete, currfid 0x%x, currvid 0x%x\n", | ||
461 | data->currfid, data->currvid); | ||
462 | |||
463 | return 0; | ||
464 | } | ||
465 | |||
466 | /* Phase 3 - core voltage transition flow ... jump to the final vid. */ | ||
467 | static int core_voltage_post_transition(struct powernow_k8_data *data, | ||
468 | u32 reqvid) | ||
469 | { | ||
470 | u32 savefid = data->currfid; | ||
471 | u32 savereqvid = reqvid; | ||
472 | |||
473 | pr_debug("ph3 (cpu%d): starting, currfid 0x%x, currvid 0x%x\n", | ||
474 | smp_processor_id(), | ||
475 | data->currfid, data->currvid); | ||
476 | |||
477 | if (reqvid != data->currvid) { | ||
478 | if (write_new_vid(data, reqvid)) | ||
479 | return 1; | ||
480 | |||
481 | if (savefid != data->currfid) { | ||
482 | printk(KERN_ERR PFX | ||
483 | "ph3: bad fid change, save 0x%x, curr 0x%x\n", | ||
484 | savefid, data->currfid); | ||
485 | return 1; | ||
486 | } | ||
487 | |||
488 | if (data->currvid != reqvid) { | ||
489 | printk(KERN_ERR PFX | ||
490 | "ph3: failed vid transition\n, " | ||
491 | "req 0x%x, curr 0x%x", | ||
492 | reqvid, data->currvid); | ||
493 | return 1; | ||
494 | } | ||
495 | } | ||
496 | |||
497 | if (query_current_values_with_pending_wait(data)) | ||
498 | return 1; | ||
499 | |||
500 | if (savereqvid != data->currvid) { | ||
501 | pr_debug("ph3 failed, currvid 0x%x\n", data->currvid); | ||
502 | return 1; | ||
503 | } | ||
504 | |||
505 | if (savefid != data->currfid) { | ||
506 | pr_debug("ph3 failed, currfid changed 0x%x\n", | ||
507 | data->currfid); | ||
508 | return 1; | ||
509 | } | ||
510 | |||
511 | pr_debug("ph3 complete, currfid 0x%x, currvid 0x%x\n", | ||
512 | data->currfid, data->currvid); | ||
513 | |||
514 | return 0; | ||
515 | } | ||
516 | |||
517 | static void check_supported_cpu(void *_rc) | ||
518 | { | ||
519 | u32 eax, ebx, ecx, edx; | ||
520 | int *rc = _rc; | ||
521 | |||
522 | *rc = -ENODEV; | ||
523 | |||
524 | if (__this_cpu_read(cpu_info.x86_vendor) != X86_VENDOR_AMD) | ||
525 | return; | ||
526 | |||
527 | eax = cpuid_eax(CPUID_PROCESSOR_SIGNATURE); | ||
528 | if (((eax & CPUID_XFAM) != CPUID_XFAM_K8) && | ||
529 | ((eax & CPUID_XFAM) < CPUID_XFAM_10H)) | ||
530 | return; | ||
531 | |||
532 | if ((eax & CPUID_XFAM) == CPUID_XFAM_K8) { | ||
533 | if (((eax & CPUID_USE_XFAM_XMOD) != CPUID_USE_XFAM_XMOD) || | ||
534 | ((eax & CPUID_XMOD) > CPUID_XMOD_REV_MASK)) { | ||
535 | printk(KERN_INFO PFX | ||
536 | "Processor cpuid %x not supported\n", eax); | ||
537 | return; | ||
538 | } | ||
539 | |||
540 | eax = cpuid_eax(CPUID_GET_MAX_CAPABILITIES); | ||
541 | if (eax < CPUID_FREQ_VOLT_CAPABILITIES) { | ||
542 | printk(KERN_INFO PFX | ||
543 | "No frequency change capabilities detected\n"); | ||
544 | return; | ||
545 | } | ||
546 | |||
547 | cpuid(CPUID_FREQ_VOLT_CAPABILITIES, &eax, &ebx, &ecx, &edx); | ||
548 | if ((edx & P_STATE_TRANSITION_CAPABLE) | ||
549 | != P_STATE_TRANSITION_CAPABLE) { | ||
550 | printk(KERN_INFO PFX | ||
551 | "Power state transitions not supported\n"); | ||
552 | return; | ||
553 | } | ||
554 | } else { /* must be a HW Pstate capable processor */ | ||
555 | cpuid(CPUID_FREQ_VOLT_CAPABILITIES, &eax, &ebx, &ecx, &edx); | ||
556 | if ((edx & USE_HW_PSTATE) == USE_HW_PSTATE) | ||
557 | cpu_family = CPU_HW_PSTATE; | ||
558 | else | ||
559 | return; | ||
560 | } | ||
561 | |||
562 | *rc = 0; | ||
563 | } | ||
564 | |||
565 | static int check_pst_table(struct powernow_k8_data *data, struct pst_s *pst, | ||
566 | u8 maxvid) | ||
567 | { | ||
568 | unsigned int j; | ||
569 | u8 lastfid = 0xff; | ||
570 | |||
571 | for (j = 0; j < data->numps; j++) { | ||
572 | if (pst[j].vid > LEAST_VID) { | ||
573 | printk(KERN_ERR FW_BUG PFX "vid %d invalid : 0x%x\n", | ||
574 | j, pst[j].vid); | ||
575 | return -EINVAL; | ||
576 | } | ||
577 | if (pst[j].vid < data->rvo) { | ||
578 | /* vid + rvo >= 0 */ | ||
579 | printk(KERN_ERR FW_BUG PFX "0 vid exceeded with pstate" | ||
580 | " %d\n", j); | ||
581 | return -ENODEV; | ||
582 | } | ||
583 | if (pst[j].vid < maxvid + data->rvo) { | ||
584 | /* vid + rvo >= maxvid */ | ||
585 | printk(KERN_ERR FW_BUG PFX "maxvid exceeded with pstate" | ||
586 | " %d\n", j); | ||
587 | return -ENODEV; | ||
588 | } | ||
589 | if (pst[j].fid > MAX_FID) { | ||
590 | printk(KERN_ERR FW_BUG PFX "maxfid exceeded with pstate" | ||
591 | " %d\n", j); | ||
592 | return -ENODEV; | ||
593 | } | ||
594 | if (j && (pst[j].fid < HI_FID_TABLE_BOTTOM)) { | ||
595 | /* Only first fid is allowed to be in "low" range */ | ||
596 | printk(KERN_ERR FW_BUG PFX "two low fids - %d : " | ||
597 | "0x%x\n", j, pst[j].fid); | ||
598 | return -EINVAL; | ||
599 | } | ||
600 | if (pst[j].fid < lastfid) | ||
601 | lastfid = pst[j].fid; | ||
602 | } | ||
603 | if (lastfid & 1) { | ||
604 | printk(KERN_ERR FW_BUG PFX "lastfid invalid\n"); | ||
605 | return -EINVAL; | ||
606 | } | ||
607 | if (lastfid > LO_FID_TABLE_TOP) | ||
608 | printk(KERN_INFO FW_BUG PFX | ||
609 | "first fid not from lo freq table\n"); | ||
610 | |||
611 | return 0; | ||
612 | } | ||
613 | |||
614 | static void invalidate_entry(struct cpufreq_frequency_table *powernow_table, | ||
615 | unsigned int entry) | ||
616 | { | ||
617 | powernow_table[entry].frequency = CPUFREQ_ENTRY_INVALID; | ||
618 | } | ||
619 | |||
620 | static void print_basics(struct powernow_k8_data *data) | ||
621 | { | ||
622 | int j; | ||
623 | for (j = 0; j < data->numps; j++) { | ||
624 | if (data->powernow_table[j].frequency != | ||
625 | CPUFREQ_ENTRY_INVALID) { | ||
626 | if (cpu_family == CPU_HW_PSTATE) { | ||
627 | printk(KERN_INFO PFX | ||
628 | " %d : pstate %d (%d MHz)\n", j, | ||
629 | data->powernow_table[j].index, | ||
630 | data->powernow_table[j].frequency/1000); | ||
631 | } else { | ||
632 | printk(KERN_INFO PFX | ||
633 | "fid 0x%x (%d MHz), vid 0x%x\n", | ||
634 | data->powernow_table[j].index & 0xff, | ||
635 | data->powernow_table[j].frequency/1000, | ||
636 | data->powernow_table[j].index >> 8); | ||
637 | } | ||
638 | } | ||
639 | } | ||
640 | if (data->batps) | ||
641 | printk(KERN_INFO PFX "Only %d pstates on battery\n", | ||
642 | data->batps); | ||
643 | } | ||
644 | |||
645 | static u32 freq_from_fid_did(u32 fid, u32 did) | ||
646 | { | ||
647 | u32 mhz = 0; | ||
648 | |||
649 | if (boot_cpu_data.x86 == 0x10) | ||
650 | mhz = (100 * (fid + 0x10)) >> did; | ||
651 | else if (boot_cpu_data.x86 == 0x11) | ||
652 | mhz = (100 * (fid + 8)) >> did; | ||
653 | else | ||
654 | BUG(); | ||
655 | |||
656 | return mhz * 1000; | ||
657 | } | ||
658 | |||
659 | static int fill_powernow_table(struct powernow_k8_data *data, | ||
660 | struct pst_s *pst, u8 maxvid) | ||
661 | { | ||
662 | struct cpufreq_frequency_table *powernow_table; | ||
663 | unsigned int j; | ||
664 | |||
665 | if (data->batps) { | ||
666 | /* use ACPI support to get full speed on mains power */ | ||
667 | printk(KERN_WARNING PFX | ||
668 | "Only %d pstates usable (use ACPI driver for full " | ||
669 | "range\n", data->batps); | ||
670 | data->numps = data->batps; | ||
671 | } | ||
672 | |||
673 | for (j = 1; j < data->numps; j++) { | ||
674 | if (pst[j-1].fid >= pst[j].fid) { | ||
675 | printk(KERN_ERR PFX "PST out of sequence\n"); | ||
676 | return -EINVAL; | ||
677 | } | ||
678 | } | ||
679 | |||
680 | if (data->numps < 2) { | ||
681 | printk(KERN_ERR PFX "no p states to transition\n"); | ||
682 | return -ENODEV; | ||
683 | } | ||
684 | |||
685 | if (check_pst_table(data, pst, maxvid)) | ||
686 | return -EINVAL; | ||
687 | |||
688 | powernow_table = kmalloc((sizeof(struct cpufreq_frequency_table) | ||
689 | * (data->numps + 1)), GFP_KERNEL); | ||
690 | if (!powernow_table) { | ||
691 | printk(KERN_ERR PFX "powernow_table memory alloc failure\n"); | ||
692 | return -ENOMEM; | ||
693 | } | ||
694 | |||
695 | for (j = 0; j < data->numps; j++) { | ||
696 | int freq; | ||
697 | powernow_table[j].index = pst[j].fid; /* lower 8 bits */ | ||
698 | powernow_table[j].index |= (pst[j].vid << 8); /* upper 8 bits */ | ||
699 | freq = find_khz_freq_from_fid(pst[j].fid); | ||
700 | powernow_table[j].frequency = freq; | ||
701 | } | ||
702 | powernow_table[data->numps].frequency = CPUFREQ_TABLE_END; | ||
703 | powernow_table[data->numps].index = 0; | ||
704 | |||
705 | if (query_current_values_with_pending_wait(data)) { | ||
706 | kfree(powernow_table); | ||
707 | return -EIO; | ||
708 | } | ||
709 | |||
710 | pr_debug("cfid 0x%x, cvid 0x%x\n", data->currfid, data->currvid); | ||
711 | data->powernow_table = powernow_table; | ||
712 | if (cpumask_first(cpu_core_mask(data->cpu)) == data->cpu) | ||
713 | print_basics(data); | ||
714 | |||
715 | for (j = 0; j < data->numps; j++) | ||
716 | if ((pst[j].fid == data->currfid) && | ||
717 | (pst[j].vid == data->currvid)) | ||
718 | return 0; | ||
719 | |||
720 | pr_debug("currfid/vid do not match PST, ignoring\n"); | ||
721 | return 0; | ||
722 | } | ||
723 | |||
724 | /* Find and validate the PSB/PST table in BIOS. */ | ||
725 | static int find_psb_table(struct powernow_k8_data *data) | ||
726 | { | ||
727 | struct psb_s *psb; | ||
728 | unsigned int i; | ||
729 | u32 mvs; | ||
730 | u8 maxvid; | ||
731 | u32 cpst = 0; | ||
732 | u32 thiscpuid; | ||
733 | |||
734 | for (i = 0xc0000; i < 0xffff0; i += 0x10) { | ||
735 | /* Scan BIOS looking for the signature. */ | ||
736 | /* It can not be at ffff0 - it is too big. */ | ||
737 | |||
738 | psb = phys_to_virt(i); | ||
739 | if (memcmp(psb, PSB_ID_STRING, PSB_ID_STRING_LEN) != 0) | ||
740 | continue; | ||
741 | |||
742 | pr_debug("found PSB header at 0x%p\n", psb); | ||
743 | |||
744 | pr_debug("table vers: 0x%x\n", psb->tableversion); | ||
745 | if (psb->tableversion != PSB_VERSION_1_4) { | ||
746 | printk(KERN_ERR FW_BUG PFX "PSB table is not v1.4\n"); | ||
747 | return -ENODEV; | ||
748 | } | ||
749 | |||
750 | pr_debug("flags: 0x%x\n", psb->flags1); | ||
751 | if (psb->flags1) { | ||
752 | printk(KERN_ERR FW_BUG PFX "unknown flags\n"); | ||
753 | return -ENODEV; | ||
754 | } | ||
755 | |||
756 | data->vstable = psb->vstable; | ||
757 | pr_debug("voltage stabilization time: %d(*20us)\n", | ||
758 | data->vstable); | ||
759 | |||
760 | pr_debug("flags2: 0x%x\n", psb->flags2); | ||
761 | data->rvo = psb->flags2 & 3; | ||
762 | data->irt = ((psb->flags2) >> 2) & 3; | ||
763 | mvs = ((psb->flags2) >> 4) & 3; | ||
764 | data->vidmvs = 1 << mvs; | ||
765 | data->batps = ((psb->flags2) >> 6) & 3; | ||
766 | |||
767 | pr_debug("ramp voltage offset: %d\n", data->rvo); | ||
768 | pr_debug("isochronous relief time: %d\n", data->irt); | ||
769 | pr_debug("maximum voltage step: %d - 0x%x\n", mvs, data->vidmvs); | ||
770 | |||
771 | pr_debug("numpst: 0x%x\n", psb->num_tables); | ||
772 | cpst = psb->num_tables; | ||
773 | if ((psb->cpuid == 0x00000fc0) || | ||
774 | (psb->cpuid == 0x00000fe0)) { | ||
775 | thiscpuid = cpuid_eax(CPUID_PROCESSOR_SIGNATURE); | ||
776 | if ((thiscpuid == 0x00000fc0) || | ||
777 | (thiscpuid == 0x00000fe0)) | ||
778 | cpst = 1; | ||
779 | } | ||
780 | if (cpst != 1) { | ||
781 | printk(KERN_ERR FW_BUG PFX "numpst must be 1\n"); | ||
782 | return -ENODEV; | ||
783 | } | ||
784 | |||
785 | data->plllock = psb->plllocktime; | ||
786 | pr_debug("plllocktime: 0x%x (units 1us)\n", psb->plllocktime); | ||
787 | pr_debug("maxfid: 0x%x\n", psb->maxfid); | ||
788 | pr_debug("maxvid: 0x%x\n", psb->maxvid); | ||
789 | maxvid = psb->maxvid; | ||
790 | |||
791 | data->numps = psb->numps; | ||
792 | pr_debug("numpstates: 0x%x\n", data->numps); | ||
793 | return fill_powernow_table(data, | ||
794 | (struct pst_s *)(psb+1), maxvid); | ||
795 | } | ||
796 | /* | ||
797 | * If you see this message, complain to BIOS manufacturer. If | ||
798 | * he tells you "we do not support Linux" or some similar | ||
799 | * nonsense, remember that Windows 2000 uses the same legacy | ||
800 | * mechanism that the old Linux PSB driver uses. Tell them it | ||
801 | * is broken with Windows 2000. | ||
802 | * | ||
803 | * The reference to the AMD documentation is chapter 9 in the | ||
804 | * BIOS and Kernel Developer's Guide, which is available on | ||
805 | * www.amd.com | ||
806 | */ | ||
807 | printk(KERN_ERR FW_BUG PFX "No PSB or ACPI _PSS objects\n"); | ||
808 | printk(KERN_ERR PFX "Make sure that your BIOS is up to date" | ||
809 | " and Cool'N'Quiet support is enabled in BIOS setup\n"); | ||
810 | return -ENODEV; | ||
811 | } | ||
812 | |||
813 | static void powernow_k8_acpi_pst_values(struct powernow_k8_data *data, | ||
814 | unsigned int index) | ||
815 | { | ||
816 | u64 control; | ||
817 | |||
818 | if (!data->acpi_data.state_count || (cpu_family == CPU_HW_PSTATE)) | ||
819 | return; | ||
820 | |||
821 | control = data->acpi_data.states[index].control; | ||
822 | data->irt = (control >> IRT_SHIFT) & IRT_MASK; | ||
823 | data->rvo = (control >> RVO_SHIFT) & RVO_MASK; | ||
824 | data->exttype = (control >> EXT_TYPE_SHIFT) & EXT_TYPE_MASK; | ||
825 | data->plllock = (control >> PLL_L_SHIFT) & PLL_L_MASK; | ||
826 | data->vidmvs = 1 << ((control >> MVS_SHIFT) & MVS_MASK); | ||
827 | data->vstable = (control >> VST_SHIFT) & VST_MASK; | ||
828 | } | ||
829 | |||
830 | static int powernow_k8_cpu_init_acpi(struct powernow_k8_data *data) | ||
831 | { | ||
832 | struct cpufreq_frequency_table *powernow_table; | ||
833 | int ret_val = -ENODEV; | ||
834 | u64 control, status; | ||
835 | |||
836 | if (acpi_processor_register_performance(&data->acpi_data, data->cpu)) { | ||
837 | pr_debug("register performance failed: bad ACPI data\n"); | ||
838 | return -EIO; | ||
839 | } | ||
840 | |||
841 | /* verify the data contained in the ACPI structures */ | ||
842 | if (data->acpi_data.state_count <= 1) { | ||
843 | pr_debug("No ACPI P-States\n"); | ||
844 | goto err_out; | ||
845 | } | ||
846 | |||
847 | control = data->acpi_data.control_register.space_id; | ||
848 | status = data->acpi_data.status_register.space_id; | ||
849 | |||
850 | if ((control != ACPI_ADR_SPACE_FIXED_HARDWARE) || | ||
851 | (status != ACPI_ADR_SPACE_FIXED_HARDWARE)) { | ||
852 | pr_debug("Invalid control/status registers (%llx - %llx)\n", | ||
853 | control, status); | ||
854 | goto err_out; | ||
855 | } | ||
856 | |||
857 | /* fill in data->powernow_table */ | ||
858 | powernow_table = kmalloc((sizeof(struct cpufreq_frequency_table) | ||
859 | * (data->acpi_data.state_count + 1)), GFP_KERNEL); | ||
860 | if (!powernow_table) { | ||
861 | pr_debug("powernow_table memory alloc failure\n"); | ||
862 | goto err_out; | ||
863 | } | ||
864 | |||
865 | /* fill in data */ | ||
866 | data->numps = data->acpi_data.state_count; | ||
867 | powernow_k8_acpi_pst_values(data, 0); | ||
868 | |||
869 | if (cpu_family == CPU_HW_PSTATE) | ||
870 | ret_val = fill_powernow_table_pstate(data, powernow_table); | ||
871 | else | ||
872 | ret_val = fill_powernow_table_fidvid(data, powernow_table); | ||
873 | if (ret_val) | ||
874 | goto err_out_mem; | ||
875 | |||
876 | powernow_table[data->acpi_data.state_count].frequency = | ||
877 | CPUFREQ_TABLE_END; | ||
878 | powernow_table[data->acpi_data.state_count].index = 0; | ||
879 | data->powernow_table = powernow_table; | ||
880 | |||
881 | if (cpumask_first(cpu_core_mask(data->cpu)) == data->cpu) | ||
882 | print_basics(data); | ||
883 | |||
884 | /* notify BIOS that we exist */ | ||
885 | acpi_processor_notify_smm(THIS_MODULE); | ||
886 | |||
887 | if (!zalloc_cpumask_var(&data->acpi_data.shared_cpu_map, GFP_KERNEL)) { | ||
888 | printk(KERN_ERR PFX | ||
889 | "unable to alloc powernow_k8_data cpumask\n"); | ||
890 | ret_val = -ENOMEM; | ||
891 | goto err_out_mem; | ||
892 | } | ||
893 | |||
894 | return 0; | ||
895 | |||
896 | err_out_mem: | ||
897 | kfree(powernow_table); | ||
898 | |||
899 | err_out: | ||
900 | acpi_processor_unregister_performance(&data->acpi_data, data->cpu); | ||
901 | |||
902 | /* data->acpi_data.state_count informs us at ->exit() | ||
903 | * whether ACPI was used */ | ||
904 | data->acpi_data.state_count = 0; | ||
905 | |||
906 | return ret_val; | ||
907 | } | ||
908 | |||
909 | static int fill_powernow_table_pstate(struct powernow_k8_data *data, | ||
910 | struct cpufreq_frequency_table *powernow_table) | ||
911 | { | ||
912 | int i; | ||
913 | u32 hi = 0, lo = 0; | ||
914 | rdmsr(MSR_PSTATE_CUR_LIMIT, lo, hi); | ||
915 | data->max_hw_pstate = (lo & HW_PSTATE_MAX_MASK) >> HW_PSTATE_MAX_SHIFT; | ||
916 | |||
917 | for (i = 0; i < data->acpi_data.state_count; i++) { | ||
918 | u32 index; | ||
919 | |||
920 | index = data->acpi_data.states[i].control & HW_PSTATE_MASK; | ||
921 | if (index > data->max_hw_pstate) { | ||
922 | printk(KERN_ERR PFX "invalid pstate %d - " | ||
923 | "bad value %d.\n", i, index); | ||
924 | printk(KERN_ERR PFX "Please report to BIOS " | ||
925 | "manufacturer\n"); | ||
926 | invalidate_entry(powernow_table, i); | ||
927 | continue; | ||
928 | } | ||
929 | rdmsr(MSR_PSTATE_DEF_BASE + index, lo, hi); | ||
930 | if (!(hi & HW_PSTATE_VALID_MASK)) { | ||
931 | pr_debug("invalid pstate %d, ignoring\n", index); | ||
932 | invalidate_entry(powernow_table, i); | ||
933 | continue; | ||
934 | } | ||
935 | |||
936 | powernow_table[i].index = index; | ||
937 | |||
938 | /* Frequency may be rounded for these */ | ||
939 | if ((boot_cpu_data.x86 == 0x10 && boot_cpu_data.x86_model < 10) | ||
940 | || boot_cpu_data.x86 == 0x11) { | ||
941 | powernow_table[i].frequency = | ||
942 | freq_from_fid_did(lo & 0x3f, (lo >> 6) & 7); | ||
943 | } else | ||
944 | powernow_table[i].frequency = | ||
945 | data->acpi_data.states[i].core_frequency * 1000; | ||
946 | } | ||
947 | return 0; | ||
948 | } | ||
949 | |||
950 | static int fill_powernow_table_fidvid(struct powernow_k8_data *data, | ||
951 | struct cpufreq_frequency_table *powernow_table) | ||
952 | { | ||
953 | int i; | ||
954 | |||
955 | for (i = 0; i < data->acpi_data.state_count; i++) { | ||
956 | u32 fid; | ||
957 | u32 vid; | ||
958 | u32 freq, index; | ||
959 | u64 status, control; | ||
960 | |||
961 | if (data->exttype) { | ||
962 | status = data->acpi_data.states[i].status; | ||
963 | fid = status & EXT_FID_MASK; | ||
964 | vid = (status >> VID_SHIFT) & EXT_VID_MASK; | ||
965 | } else { | ||
966 | control = data->acpi_data.states[i].control; | ||
967 | fid = control & FID_MASK; | ||
968 | vid = (control >> VID_SHIFT) & VID_MASK; | ||
969 | } | ||
970 | |||
971 | pr_debug(" %d : fid 0x%x, vid 0x%x\n", i, fid, vid); | ||
972 | |||
973 | index = fid | (vid<<8); | ||
974 | powernow_table[i].index = index; | ||
975 | |||
976 | freq = find_khz_freq_from_fid(fid); | ||
977 | powernow_table[i].frequency = freq; | ||
978 | |||
979 | /* verify frequency is OK */ | ||
980 | if ((freq > (MAX_FREQ * 1000)) || (freq < (MIN_FREQ * 1000))) { | ||
981 | pr_debug("invalid freq %u kHz, ignoring\n", freq); | ||
982 | invalidate_entry(powernow_table, i); | ||
983 | continue; | ||
984 | } | ||
985 | |||
986 | /* verify voltage is OK - | ||
987 | * BIOSs are using "off" to indicate invalid */ | ||
988 | if (vid == VID_OFF) { | ||
989 | pr_debug("invalid vid %u, ignoring\n", vid); | ||
990 | invalidate_entry(powernow_table, i); | ||
991 | continue; | ||
992 | } | ||
993 | |||
994 | if (freq != (data->acpi_data.states[i].core_frequency * 1000)) { | ||
995 | printk(KERN_INFO PFX "invalid freq entries " | ||
996 | "%u kHz vs. %u kHz\n", freq, | ||
997 | (unsigned int) | ||
998 | (data->acpi_data.states[i].core_frequency | ||
999 | * 1000)); | ||
1000 | invalidate_entry(powernow_table, i); | ||
1001 | continue; | ||
1002 | } | ||
1003 | } | ||
1004 | return 0; | ||
1005 | } | ||
1006 | |||
1007 | static void powernow_k8_cpu_exit_acpi(struct powernow_k8_data *data) | ||
1008 | { | ||
1009 | if (data->acpi_data.state_count) | ||
1010 | acpi_processor_unregister_performance(&data->acpi_data, | ||
1011 | data->cpu); | ||
1012 | free_cpumask_var(data->acpi_data.shared_cpu_map); | ||
1013 | } | ||
1014 | |||
1015 | static int get_transition_latency(struct powernow_k8_data *data) | ||
1016 | { | ||
1017 | int max_latency = 0; | ||
1018 | int i; | ||
1019 | for (i = 0; i < data->acpi_data.state_count; i++) { | ||
1020 | int cur_latency = data->acpi_data.states[i].transition_latency | ||
1021 | + data->acpi_data.states[i].bus_master_latency; | ||
1022 | if (cur_latency > max_latency) | ||
1023 | max_latency = cur_latency; | ||
1024 | } | ||
1025 | if (max_latency == 0) { | ||
1026 | /* | ||
1027 | * Fam 11h and later may return 0 as transition latency. This | ||
1028 | * is intended and means "very fast". While cpufreq core and | ||
1029 | * governors currently can handle that gracefully, better set it | ||
1030 | * to 1 to avoid problems in the future. | ||
1031 | */ | ||
1032 | if (boot_cpu_data.x86 < 0x11) | ||
1033 | printk(KERN_ERR FW_WARN PFX "Invalid zero transition " | ||
1034 | "latency\n"); | ||
1035 | max_latency = 1; | ||
1036 | } | ||
1037 | /* value in usecs, needs to be in nanoseconds */ | ||
1038 | return 1000 * max_latency; | ||
1039 | } | ||
1040 | |||
1041 | /* Take a frequency, and issue the fid/vid transition command */ | ||
1042 | static int transition_frequency_fidvid(struct powernow_k8_data *data, | ||
1043 | unsigned int index) | ||
1044 | { | ||
1045 | u32 fid = 0; | ||
1046 | u32 vid = 0; | ||
1047 | int res, i; | ||
1048 | struct cpufreq_freqs freqs; | ||
1049 | |||
1050 | pr_debug("cpu %d transition to index %u\n", smp_processor_id(), index); | ||
1051 | |||
1052 | /* fid/vid correctness check for k8 */ | ||
1053 | /* fid are the lower 8 bits of the index we stored into | ||
1054 | * the cpufreq frequency table in find_psb_table, vid | ||
1055 | * are the upper 8 bits. | ||
1056 | */ | ||
1057 | fid = data->powernow_table[index].index & 0xFF; | ||
1058 | vid = (data->powernow_table[index].index & 0xFF00) >> 8; | ||
1059 | |||
1060 | pr_debug("table matched fid 0x%x, giving vid 0x%x\n", fid, vid); | ||
1061 | |||
1062 | if (query_current_values_with_pending_wait(data)) | ||
1063 | return 1; | ||
1064 | |||
1065 | if ((data->currvid == vid) && (data->currfid == fid)) { | ||
1066 | pr_debug("target matches current values (fid 0x%x, vid 0x%x)\n", | ||
1067 | fid, vid); | ||
1068 | return 0; | ||
1069 | } | ||
1070 | |||
1071 | pr_debug("cpu %d, changing to fid 0x%x, vid 0x%x\n", | ||
1072 | smp_processor_id(), fid, vid); | ||
1073 | freqs.old = find_khz_freq_from_fid(data->currfid); | ||
1074 | freqs.new = find_khz_freq_from_fid(fid); | ||
1075 | |||
1076 | for_each_cpu(i, data->available_cores) { | ||
1077 | freqs.cpu = i; | ||
1078 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
1079 | } | ||
1080 | |||
1081 | res = transition_fid_vid(data, fid, vid); | ||
1082 | freqs.new = find_khz_freq_from_fid(data->currfid); | ||
1083 | |||
1084 | for_each_cpu(i, data->available_cores) { | ||
1085 | freqs.cpu = i; | ||
1086 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
1087 | } | ||
1088 | return res; | ||
1089 | } | ||
1090 | |||
1091 | /* Take a frequency, and issue the hardware pstate transition command */ | ||
1092 | static int transition_frequency_pstate(struct powernow_k8_data *data, | ||
1093 | unsigned int index) | ||
1094 | { | ||
1095 | u32 pstate = 0; | ||
1096 | int res, i; | ||
1097 | struct cpufreq_freqs freqs; | ||
1098 | |||
1099 | pr_debug("cpu %d transition to index %u\n", smp_processor_id(), index); | ||
1100 | |||
1101 | /* get MSR index for hardware pstate transition */ | ||
1102 | pstate = index & HW_PSTATE_MASK; | ||
1103 | if (pstate > data->max_hw_pstate) | ||
1104 | return 0; | ||
1105 | freqs.old = find_khz_freq_from_pstate(data->powernow_table, | ||
1106 | data->currpstate); | ||
1107 | freqs.new = find_khz_freq_from_pstate(data->powernow_table, pstate); | ||
1108 | |||
1109 | for_each_cpu(i, data->available_cores) { | ||
1110 | freqs.cpu = i; | ||
1111 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
1112 | } | ||
1113 | |||
1114 | res = transition_pstate(data, pstate); | ||
1115 | freqs.new = find_khz_freq_from_pstate(data->powernow_table, pstate); | ||
1116 | |||
1117 | for_each_cpu(i, data->available_cores) { | ||
1118 | freqs.cpu = i; | ||
1119 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
1120 | } | ||
1121 | return res; | ||
1122 | } | ||
1123 | |||
1124 | /* Driver entry point to switch to the target frequency */ | ||
1125 | static int powernowk8_target(struct cpufreq_policy *pol, | ||
1126 | unsigned targfreq, unsigned relation) | ||
1127 | { | ||
1128 | cpumask_var_t oldmask; | ||
1129 | struct powernow_k8_data *data = per_cpu(powernow_data, pol->cpu); | ||
1130 | u32 checkfid; | ||
1131 | u32 checkvid; | ||
1132 | unsigned int newstate; | ||
1133 | int ret = -EIO; | ||
1134 | |||
1135 | if (!data) | ||
1136 | return -EINVAL; | ||
1137 | |||
1138 | checkfid = data->currfid; | ||
1139 | checkvid = data->currvid; | ||
1140 | |||
1141 | /* only run on specific CPU from here on. */ | ||
1142 | /* This is poor form: use a workqueue or smp_call_function_single */ | ||
1143 | if (!alloc_cpumask_var(&oldmask, GFP_KERNEL)) | ||
1144 | return -ENOMEM; | ||
1145 | |||
1146 | cpumask_copy(oldmask, tsk_cpus_allowed(current)); | ||
1147 | set_cpus_allowed_ptr(current, cpumask_of(pol->cpu)); | ||
1148 | |||
1149 | if (smp_processor_id() != pol->cpu) { | ||
1150 | printk(KERN_ERR PFX "limiting to cpu %u failed\n", pol->cpu); | ||
1151 | goto err_out; | ||
1152 | } | ||
1153 | |||
1154 | if (pending_bit_stuck()) { | ||
1155 | printk(KERN_ERR PFX "failing targ, change pending bit set\n"); | ||
1156 | goto err_out; | ||
1157 | } | ||
1158 | |||
1159 | pr_debug("targ: cpu %d, %d kHz, min %d, max %d, relation %d\n", | ||
1160 | pol->cpu, targfreq, pol->min, pol->max, relation); | ||
1161 | |||
1162 | if (query_current_values_with_pending_wait(data)) | ||
1163 | goto err_out; | ||
1164 | |||
1165 | if (cpu_family != CPU_HW_PSTATE) { | ||
1166 | pr_debug("targ: curr fid 0x%x, vid 0x%x\n", | ||
1167 | data->currfid, data->currvid); | ||
1168 | |||
1169 | if ((checkvid != data->currvid) || | ||
1170 | (checkfid != data->currfid)) { | ||
1171 | printk(KERN_INFO PFX | ||
1172 | "error - out of sync, fix 0x%x 0x%x, " | ||
1173 | "vid 0x%x 0x%x\n", | ||
1174 | checkfid, data->currfid, | ||
1175 | checkvid, data->currvid); | ||
1176 | } | ||
1177 | } | ||
1178 | |||
1179 | if (cpufreq_frequency_table_target(pol, data->powernow_table, | ||
1180 | targfreq, relation, &newstate)) | ||
1181 | goto err_out; | ||
1182 | |||
1183 | mutex_lock(&fidvid_mutex); | ||
1184 | |||
1185 | powernow_k8_acpi_pst_values(data, newstate); | ||
1186 | |||
1187 | if (cpu_family == CPU_HW_PSTATE) | ||
1188 | ret = transition_frequency_pstate(data, newstate); | ||
1189 | else | ||
1190 | ret = transition_frequency_fidvid(data, newstate); | ||
1191 | if (ret) { | ||
1192 | printk(KERN_ERR PFX "transition frequency failed\n"); | ||
1193 | ret = 1; | ||
1194 | mutex_unlock(&fidvid_mutex); | ||
1195 | goto err_out; | ||
1196 | } | ||
1197 | mutex_unlock(&fidvid_mutex); | ||
1198 | |||
1199 | if (cpu_family == CPU_HW_PSTATE) | ||
1200 | pol->cur = find_khz_freq_from_pstate(data->powernow_table, | ||
1201 | newstate); | ||
1202 | else | ||
1203 | pol->cur = find_khz_freq_from_fid(data->currfid); | ||
1204 | ret = 0; | ||
1205 | |||
1206 | err_out: | ||
1207 | set_cpus_allowed_ptr(current, oldmask); | ||
1208 | free_cpumask_var(oldmask); | ||
1209 | return ret; | ||
1210 | } | ||
1211 | |||
1212 | /* Driver entry point to verify the policy and range of frequencies */ | ||
1213 | static int powernowk8_verify(struct cpufreq_policy *pol) | ||
1214 | { | ||
1215 | struct powernow_k8_data *data = per_cpu(powernow_data, pol->cpu); | ||
1216 | |||
1217 | if (!data) | ||
1218 | return -EINVAL; | ||
1219 | |||
1220 | return cpufreq_frequency_table_verify(pol, data->powernow_table); | ||
1221 | } | ||
1222 | |||
1223 | struct init_on_cpu { | ||
1224 | struct powernow_k8_data *data; | ||
1225 | int rc; | ||
1226 | }; | ||
1227 | |||
1228 | static void __cpuinit powernowk8_cpu_init_on_cpu(void *_init_on_cpu) | ||
1229 | { | ||
1230 | struct init_on_cpu *init_on_cpu = _init_on_cpu; | ||
1231 | |||
1232 | if (pending_bit_stuck()) { | ||
1233 | printk(KERN_ERR PFX "failing init, change pending bit set\n"); | ||
1234 | init_on_cpu->rc = -ENODEV; | ||
1235 | return; | ||
1236 | } | ||
1237 | |||
1238 | if (query_current_values_with_pending_wait(init_on_cpu->data)) { | ||
1239 | init_on_cpu->rc = -ENODEV; | ||
1240 | return; | ||
1241 | } | ||
1242 | |||
1243 | if (cpu_family == CPU_OPTERON) | ||
1244 | fidvid_msr_init(); | ||
1245 | |||
1246 | init_on_cpu->rc = 0; | ||
1247 | } | ||
1248 | |||
1249 | /* per CPU init entry point to the driver */ | ||
1250 | static int __cpuinit powernowk8_cpu_init(struct cpufreq_policy *pol) | ||
1251 | { | ||
1252 | static const char ACPI_PSS_BIOS_BUG_MSG[] = | ||
1253 | KERN_ERR FW_BUG PFX "No compatible ACPI _PSS objects found.\n" | ||
1254 | FW_BUG PFX "Try again with latest BIOS.\n"; | ||
1255 | struct powernow_k8_data *data; | ||
1256 | struct init_on_cpu init_on_cpu; | ||
1257 | int rc; | ||
1258 | struct cpuinfo_x86 *c = &cpu_data(pol->cpu); | ||
1259 | |||
1260 | if (!cpu_online(pol->cpu)) | ||
1261 | return -ENODEV; | ||
1262 | |||
1263 | smp_call_function_single(pol->cpu, check_supported_cpu, &rc, 1); | ||
1264 | if (rc) | ||
1265 | return -ENODEV; | ||
1266 | |||
1267 | data = kzalloc(sizeof(struct powernow_k8_data), GFP_KERNEL); | ||
1268 | if (!data) { | ||
1269 | printk(KERN_ERR PFX "unable to alloc powernow_k8_data"); | ||
1270 | return -ENOMEM; | ||
1271 | } | ||
1272 | |||
1273 | data->cpu = pol->cpu; | ||
1274 | data->currpstate = HW_PSTATE_INVALID; | ||
1275 | |||
1276 | if (powernow_k8_cpu_init_acpi(data)) { | ||
1277 | /* | ||
1278 | * Use the PSB BIOS structure. This is only available on | ||
1279 | * an UP version, and is deprecated by AMD. | ||
1280 | */ | ||
1281 | if (num_online_cpus() != 1) { | ||
1282 | printk_once(ACPI_PSS_BIOS_BUG_MSG); | ||
1283 | goto err_out; | ||
1284 | } | ||
1285 | if (pol->cpu != 0) { | ||
1286 | printk(KERN_ERR FW_BUG PFX "No ACPI _PSS objects for " | ||
1287 | "CPU other than CPU0. Complain to your BIOS " | ||
1288 | "vendor.\n"); | ||
1289 | goto err_out; | ||
1290 | } | ||
1291 | rc = find_psb_table(data); | ||
1292 | if (rc) | ||
1293 | goto err_out; | ||
1294 | |||
1295 | /* Take a crude guess here. | ||
1296 | * That guess was in microseconds, so multiply with 1000 */ | ||
1297 | pol->cpuinfo.transition_latency = ( | ||
1298 | ((data->rvo + 8) * data->vstable * VST_UNITS_20US) + | ||
1299 | ((1 << data->irt) * 30)) * 1000; | ||
1300 | } else /* ACPI _PSS objects available */ | ||
1301 | pol->cpuinfo.transition_latency = get_transition_latency(data); | ||
1302 | |||
1303 | /* only run on specific CPU from here on */ | ||
1304 | init_on_cpu.data = data; | ||
1305 | smp_call_function_single(data->cpu, powernowk8_cpu_init_on_cpu, | ||
1306 | &init_on_cpu, 1); | ||
1307 | rc = init_on_cpu.rc; | ||
1308 | if (rc != 0) | ||
1309 | goto err_out_exit_acpi; | ||
1310 | |||
1311 | if (cpu_family == CPU_HW_PSTATE) | ||
1312 | cpumask_copy(pol->cpus, cpumask_of(pol->cpu)); | ||
1313 | else | ||
1314 | cpumask_copy(pol->cpus, cpu_core_mask(pol->cpu)); | ||
1315 | data->available_cores = pol->cpus; | ||
1316 | |||
1317 | if (cpu_family == CPU_HW_PSTATE) | ||
1318 | pol->cur = find_khz_freq_from_pstate(data->powernow_table, | ||
1319 | data->currpstate); | ||
1320 | else | ||
1321 | pol->cur = find_khz_freq_from_fid(data->currfid); | ||
1322 | pr_debug("policy current frequency %d kHz\n", pol->cur); | ||
1323 | |||
1324 | /* min/max the cpu is capable of */ | ||
1325 | if (cpufreq_frequency_table_cpuinfo(pol, data->powernow_table)) { | ||
1326 | printk(KERN_ERR FW_BUG PFX "invalid powernow_table\n"); | ||
1327 | powernow_k8_cpu_exit_acpi(data); | ||
1328 | kfree(data->powernow_table); | ||
1329 | kfree(data); | ||
1330 | return -EINVAL; | ||
1331 | } | ||
1332 | |||
1333 | /* Check for APERF/MPERF support in hardware */ | ||
1334 | if (cpu_has(c, X86_FEATURE_APERFMPERF)) | ||
1335 | cpufreq_amd64_driver.getavg = cpufreq_get_measured_perf; | ||
1336 | |||
1337 | cpufreq_frequency_table_get_attr(data->powernow_table, pol->cpu); | ||
1338 | |||
1339 | if (cpu_family == CPU_HW_PSTATE) | ||
1340 | pr_debug("cpu_init done, current pstate 0x%x\n", | ||
1341 | data->currpstate); | ||
1342 | else | ||
1343 | pr_debug("cpu_init done, current fid 0x%x, vid 0x%x\n", | ||
1344 | data->currfid, data->currvid); | ||
1345 | |||
1346 | per_cpu(powernow_data, pol->cpu) = data; | ||
1347 | |||
1348 | return 0; | ||
1349 | |||
1350 | err_out_exit_acpi: | ||
1351 | powernow_k8_cpu_exit_acpi(data); | ||
1352 | |||
1353 | err_out: | ||
1354 | kfree(data); | ||
1355 | return -ENODEV; | ||
1356 | } | ||
1357 | |||
1358 | static int __devexit powernowk8_cpu_exit(struct cpufreq_policy *pol) | ||
1359 | { | ||
1360 | struct powernow_k8_data *data = per_cpu(powernow_data, pol->cpu); | ||
1361 | |||
1362 | if (!data) | ||
1363 | return -EINVAL; | ||
1364 | |||
1365 | powernow_k8_cpu_exit_acpi(data); | ||
1366 | |||
1367 | cpufreq_frequency_table_put_attr(pol->cpu); | ||
1368 | |||
1369 | kfree(data->powernow_table); | ||
1370 | kfree(data); | ||
1371 | per_cpu(powernow_data, pol->cpu) = NULL; | ||
1372 | |||
1373 | return 0; | ||
1374 | } | ||
1375 | |||
1376 | static void query_values_on_cpu(void *_err) | ||
1377 | { | ||
1378 | int *err = _err; | ||
1379 | struct powernow_k8_data *data = __this_cpu_read(powernow_data); | ||
1380 | |||
1381 | *err = query_current_values_with_pending_wait(data); | ||
1382 | } | ||
1383 | |||
1384 | static unsigned int powernowk8_get(unsigned int cpu) | ||
1385 | { | ||
1386 | struct powernow_k8_data *data = per_cpu(powernow_data, cpu); | ||
1387 | unsigned int khz = 0; | ||
1388 | int err; | ||
1389 | |||
1390 | if (!data) | ||
1391 | return 0; | ||
1392 | |||
1393 | smp_call_function_single(cpu, query_values_on_cpu, &err, true); | ||
1394 | if (err) | ||
1395 | goto out; | ||
1396 | |||
1397 | if (cpu_family == CPU_HW_PSTATE) | ||
1398 | khz = find_khz_freq_from_pstate(data->powernow_table, | ||
1399 | data->currpstate); | ||
1400 | else | ||
1401 | khz = find_khz_freq_from_fid(data->currfid); | ||
1402 | |||
1403 | |||
1404 | out: | ||
1405 | return khz; | ||
1406 | } | ||
1407 | |||
1408 | static void _cpb_toggle_msrs(bool t) | ||
1409 | { | ||
1410 | int cpu; | ||
1411 | |||
1412 | get_online_cpus(); | ||
1413 | |||
1414 | rdmsr_on_cpus(cpu_online_mask, MSR_K7_HWCR, msrs); | ||
1415 | |||
1416 | for_each_cpu(cpu, cpu_online_mask) { | ||
1417 | struct msr *reg = per_cpu_ptr(msrs, cpu); | ||
1418 | if (t) | ||
1419 | reg->l &= ~BIT(25); | ||
1420 | else | ||
1421 | reg->l |= BIT(25); | ||
1422 | } | ||
1423 | wrmsr_on_cpus(cpu_online_mask, MSR_K7_HWCR, msrs); | ||
1424 | |||
1425 | put_online_cpus(); | ||
1426 | } | ||
1427 | |||
1428 | /* | ||
1429 | * Switch on/off core performance boosting. | ||
1430 | * | ||
1431 | * 0=disable | ||
1432 | * 1=enable. | ||
1433 | */ | ||
1434 | static void cpb_toggle(bool t) | ||
1435 | { | ||
1436 | if (!cpb_capable) | ||
1437 | return; | ||
1438 | |||
1439 | if (t && !cpb_enabled) { | ||
1440 | cpb_enabled = true; | ||
1441 | _cpb_toggle_msrs(t); | ||
1442 | printk(KERN_INFO PFX "Core Boosting enabled.\n"); | ||
1443 | } else if (!t && cpb_enabled) { | ||
1444 | cpb_enabled = false; | ||
1445 | _cpb_toggle_msrs(t); | ||
1446 | printk(KERN_INFO PFX "Core Boosting disabled.\n"); | ||
1447 | } | ||
1448 | } | ||
1449 | |||
1450 | static ssize_t store_cpb(struct cpufreq_policy *policy, const char *buf, | ||
1451 | size_t count) | ||
1452 | { | ||
1453 | int ret = -EINVAL; | ||
1454 | unsigned long val = 0; | ||
1455 | |||
1456 | ret = strict_strtoul(buf, 10, &val); | ||
1457 | if (!ret && (val == 0 || val == 1) && cpb_capable) | ||
1458 | cpb_toggle(val); | ||
1459 | else | ||
1460 | return -EINVAL; | ||
1461 | |||
1462 | return count; | ||
1463 | } | ||
1464 | |||
1465 | static ssize_t show_cpb(struct cpufreq_policy *policy, char *buf) | ||
1466 | { | ||
1467 | return sprintf(buf, "%u\n", cpb_enabled); | ||
1468 | } | ||
1469 | |||
1470 | #define define_one_rw(_name) \ | ||
1471 | static struct freq_attr _name = \ | ||
1472 | __ATTR(_name, 0644, show_##_name, store_##_name) | ||
1473 | |||
1474 | define_one_rw(cpb); | ||
1475 | |||
1476 | static struct freq_attr *powernow_k8_attr[] = { | ||
1477 | &cpufreq_freq_attr_scaling_available_freqs, | ||
1478 | &cpb, | ||
1479 | NULL, | ||
1480 | }; | ||
1481 | |||
1482 | static struct cpufreq_driver cpufreq_amd64_driver = { | ||
1483 | .verify = powernowk8_verify, | ||
1484 | .target = powernowk8_target, | ||
1485 | .bios_limit = acpi_processor_get_bios_limit, | ||
1486 | .init = powernowk8_cpu_init, | ||
1487 | .exit = __devexit_p(powernowk8_cpu_exit), | ||
1488 | .get = powernowk8_get, | ||
1489 | .name = "powernow-k8", | ||
1490 | .owner = THIS_MODULE, | ||
1491 | .attr = powernow_k8_attr, | ||
1492 | }; | ||
1493 | |||
1494 | /* | ||
1495 | * Clear the boost-disable flag on the CPU_DOWN path so that this cpu | ||
1496 | * cannot block the remaining ones from boosting. On the CPU_UP path we | ||
1497 | * simply keep the boost-disable flag in sync with the current global | ||
1498 | * state. | ||
1499 | */ | ||
1500 | static int cpb_notify(struct notifier_block *nb, unsigned long action, | ||
1501 | void *hcpu) | ||
1502 | { | ||
1503 | unsigned cpu = (long)hcpu; | ||
1504 | u32 lo, hi; | ||
1505 | |||
1506 | switch (action) { | ||
1507 | case CPU_UP_PREPARE: | ||
1508 | case CPU_UP_PREPARE_FROZEN: | ||
1509 | |||
1510 | if (!cpb_enabled) { | ||
1511 | rdmsr_on_cpu(cpu, MSR_K7_HWCR, &lo, &hi); | ||
1512 | lo |= BIT(25); | ||
1513 | wrmsr_on_cpu(cpu, MSR_K7_HWCR, lo, hi); | ||
1514 | } | ||
1515 | break; | ||
1516 | |||
1517 | case CPU_DOWN_PREPARE: | ||
1518 | case CPU_DOWN_PREPARE_FROZEN: | ||
1519 | rdmsr_on_cpu(cpu, MSR_K7_HWCR, &lo, &hi); | ||
1520 | lo &= ~BIT(25); | ||
1521 | wrmsr_on_cpu(cpu, MSR_K7_HWCR, lo, hi); | ||
1522 | break; | ||
1523 | |||
1524 | default: | ||
1525 | break; | ||
1526 | } | ||
1527 | |||
1528 | return NOTIFY_OK; | ||
1529 | } | ||
1530 | |||
1531 | static struct notifier_block cpb_nb = { | ||
1532 | .notifier_call = cpb_notify, | ||
1533 | }; | ||
1534 | |||
1535 | /* driver entry point for init */ | ||
1536 | static int __cpuinit powernowk8_init(void) | ||
1537 | { | ||
1538 | unsigned int i, supported_cpus = 0, cpu; | ||
1539 | int rv; | ||
1540 | |||
1541 | for_each_online_cpu(i) { | ||
1542 | int rc; | ||
1543 | smp_call_function_single(i, check_supported_cpu, &rc, 1); | ||
1544 | if (rc == 0) | ||
1545 | supported_cpus++; | ||
1546 | } | ||
1547 | |||
1548 | if (supported_cpus != num_online_cpus()) | ||
1549 | return -ENODEV; | ||
1550 | |||
1551 | printk(KERN_INFO PFX "Found %d %s (%d cpu cores) (" VERSION ")\n", | ||
1552 | num_online_nodes(), boot_cpu_data.x86_model_id, supported_cpus); | ||
1553 | |||
1554 | if (boot_cpu_has(X86_FEATURE_CPB)) { | ||
1555 | |||
1556 | cpb_capable = true; | ||
1557 | |||
1558 | msrs = msrs_alloc(); | ||
1559 | if (!msrs) { | ||
1560 | printk(KERN_ERR "%s: Error allocating msrs!\n", __func__); | ||
1561 | return -ENOMEM; | ||
1562 | } | ||
1563 | |||
1564 | register_cpu_notifier(&cpb_nb); | ||
1565 | |||
1566 | rdmsr_on_cpus(cpu_online_mask, MSR_K7_HWCR, msrs); | ||
1567 | |||
1568 | for_each_cpu(cpu, cpu_online_mask) { | ||
1569 | struct msr *reg = per_cpu_ptr(msrs, cpu); | ||
1570 | cpb_enabled |= !(!!(reg->l & BIT(25))); | ||
1571 | } | ||
1572 | |||
1573 | printk(KERN_INFO PFX "Core Performance Boosting: %s.\n", | ||
1574 | (cpb_enabled ? "on" : "off")); | ||
1575 | } | ||
1576 | |||
1577 | rv = cpufreq_register_driver(&cpufreq_amd64_driver); | ||
1578 | if (rv < 0 && boot_cpu_has(X86_FEATURE_CPB)) { | ||
1579 | unregister_cpu_notifier(&cpb_nb); | ||
1580 | msrs_free(msrs); | ||
1581 | msrs = NULL; | ||
1582 | } | ||
1583 | return rv; | ||
1584 | } | ||
1585 | |||
1586 | /* driver entry point for term */ | ||
1587 | static void __exit powernowk8_exit(void) | ||
1588 | { | ||
1589 | pr_debug("exit\n"); | ||
1590 | |||
1591 | if (boot_cpu_has(X86_FEATURE_CPB)) { | ||
1592 | msrs_free(msrs); | ||
1593 | msrs = NULL; | ||
1594 | |||
1595 | unregister_cpu_notifier(&cpb_nb); | ||
1596 | } | ||
1597 | |||
1598 | cpufreq_unregister_driver(&cpufreq_amd64_driver); | ||
1599 | } | ||
1600 | |||
1601 | MODULE_AUTHOR("Paul Devriendt <paul.devriendt@amd.com> and " | ||
1602 | "Mark Langsdorf <mark.langsdorf@amd.com>"); | ||
1603 | MODULE_DESCRIPTION("AMD Athlon 64 and Opteron processor frequency driver."); | ||
1604 | MODULE_LICENSE("GPL"); | ||
1605 | |||
1606 | late_initcall(powernowk8_init); | ||
1607 | module_exit(powernowk8_exit); | ||
diff --git a/drivers/cpufreq/powernow-k8.h b/drivers/cpufreq/powernow-k8.h new file mode 100644 index 000000000000..3744d26cdc2b --- /dev/null +++ b/drivers/cpufreq/powernow-k8.h | |||
@@ -0,0 +1,222 @@ | |||
1 | /* | ||
2 | * (c) 2003-2006 Advanced Micro Devices, Inc. | ||
3 | * Your use of this code is subject to the terms and conditions of the | ||
4 | * GNU general public license version 2. See "COPYING" or | ||
5 | * http://www.gnu.org/licenses/gpl.html | ||
6 | */ | ||
7 | |||
8 | enum pstate { | ||
9 | HW_PSTATE_INVALID = 0xff, | ||
10 | HW_PSTATE_0 = 0, | ||
11 | HW_PSTATE_1 = 1, | ||
12 | HW_PSTATE_2 = 2, | ||
13 | HW_PSTATE_3 = 3, | ||
14 | HW_PSTATE_4 = 4, | ||
15 | HW_PSTATE_5 = 5, | ||
16 | HW_PSTATE_6 = 6, | ||
17 | HW_PSTATE_7 = 7, | ||
18 | }; | ||
19 | |||
20 | struct powernow_k8_data { | ||
21 | unsigned int cpu; | ||
22 | |||
23 | u32 numps; /* number of p-states */ | ||
24 | u32 batps; /* number of p-states supported on battery */ | ||
25 | u32 max_hw_pstate; /* maximum legal hardware pstate */ | ||
26 | |||
27 | /* these values are constant when the PSB is used to determine | ||
28 | * vid/fid pairings, but are modified during the ->target() call | ||
29 | * when ACPI is used */ | ||
30 | u32 rvo; /* ramp voltage offset */ | ||
31 | u32 irt; /* isochronous relief time */ | ||
32 | u32 vidmvs; /* usable value calculated from mvs */ | ||
33 | u32 vstable; /* voltage stabilization time, units 20 us */ | ||
34 | u32 plllock; /* pll lock time, units 1 us */ | ||
35 | u32 exttype; /* extended interface = 1 */ | ||
36 | |||
37 | /* keep track of the current fid / vid or pstate */ | ||
38 | u32 currvid; | ||
39 | u32 currfid; | ||
40 | enum pstate currpstate; | ||
41 | |||
42 | /* the powernow_table includes all frequency and vid/fid pairings: | ||
43 | * fid are the lower 8 bits of the index, vid are the upper 8 bits. | ||
44 | * frequency is in kHz */ | ||
45 | struct cpufreq_frequency_table *powernow_table; | ||
46 | |||
47 | /* the acpi table needs to be kept. it's only available if ACPI was | ||
48 | * used to determine valid frequency/vid/fid states */ | ||
49 | struct acpi_processor_performance acpi_data; | ||
50 | |||
51 | /* we need to keep track of associated cores, but let cpufreq | ||
52 | * handle hotplug events - so just point at cpufreq pol->cpus | ||
53 | * structure */ | ||
54 | struct cpumask *available_cores; | ||
55 | }; | ||
56 | |||
57 | /* processor's cpuid instruction support */ | ||
58 | #define CPUID_PROCESSOR_SIGNATURE 1 /* function 1 */ | ||
59 | #define CPUID_XFAM 0x0ff00000 /* extended family */ | ||
60 | #define CPUID_XFAM_K8 0 | ||
61 | #define CPUID_XMOD 0x000f0000 /* extended model */ | ||
62 | #define CPUID_XMOD_REV_MASK 0x000c0000 | ||
63 | #define CPUID_XFAM_10H 0x00100000 /* family 0x10 */ | ||
64 | #define CPUID_USE_XFAM_XMOD 0x00000f00 | ||
65 | #define CPUID_GET_MAX_CAPABILITIES 0x80000000 | ||
66 | #define CPUID_FREQ_VOLT_CAPABILITIES 0x80000007 | ||
67 | #define P_STATE_TRANSITION_CAPABLE 6 | ||
68 | |||
69 | /* Model Specific Registers for p-state transitions. MSRs are 64-bit. For */ | ||
70 | /* writes (wrmsr - opcode 0f 30), the register number is placed in ecx, and */ | ||
71 | /* the value to write is placed in edx:eax. For reads (rdmsr - opcode 0f 32), */ | ||
72 | /* the register number is placed in ecx, and the data is returned in edx:eax. */ | ||
73 | |||
74 | #define MSR_FIDVID_CTL 0xc0010041 | ||
75 | #define MSR_FIDVID_STATUS 0xc0010042 | ||
76 | |||
77 | /* Field definitions within the FID VID Low Control MSR : */ | ||
78 | #define MSR_C_LO_INIT_FID_VID 0x00010000 | ||
79 | #define MSR_C_LO_NEW_VID 0x00003f00 | ||
80 | #define MSR_C_LO_NEW_FID 0x0000003f | ||
81 | #define MSR_C_LO_VID_SHIFT 8 | ||
82 | |||
83 | /* Field definitions within the FID VID High Control MSR : */ | ||
84 | #define MSR_C_HI_STP_GNT_TO 0x000fffff | ||
85 | |||
86 | /* Field definitions within the FID VID Low Status MSR : */ | ||
87 | #define MSR_S_LO_CHANGE_PENDING 0x80000000 /* cleared when completed */ | ||
88 | #define MSR_S_LO_MAX_RAMP_VID 0x3f000000 | ||
89 | #define MSR_S_LO_MAX_FID 0x003f0000 | ||
90 | #define MSR_S_LO_START_FID 0x00003f00 | ||
91 | #define MSR_S_LO_CURRENT_FID 0x0000003f | ||
92 | |||
93 | /* Field definitions within the FID VID High Status MSR : */ | ||
94 | #define MSR_S_HI_MIN_WORKING_VID 0x3f000000 | ||
95 | #define MSR_S_HI_MAX_WORKING_VID 0x003f0000 | ||
96 | #define MSR_S_HI_START_VID 0x00003f00 | ||
97 | #define MSR_S_HI_CURRENT_VID 0x0000003f | ||
98 | #define MSR_C_HI_STP_GNT_BENIGN 0x00000001 | ||
99 | |||
100 | |||
101 | /* Hardware Pstate _PSS and MSR definitions */ | ||
102 | #define USE_HW_PSTATE 0x00000080 | ||
103 | #define HW_PSTATE_MASK 0x00000007 | ||
104 | #define HW_PSTATE_VALID_MASK 0x80000000 | ||
105 | #define HW_PSTATE_MAX_MASK 0x000000f0 | ||
106 | #define HW_PSTATE_MAX_SHIFT 4 | ||
107 | #define MSR_PSTATE_DEF_BASE 0xc0010064 /* base of Pstate MSRs */ | ||
108 | #define MSR_PSTATE_STATUS 0xc0010063 /* Pstate Status MSR */ | ||
109 | #define MSR_PSTATE_CTRL 0xc0010062 /* Pstate control MSR */ | ||
110 | #define MSR_PSTATE_CUR_LIMIT 0xc0010061 /* pstate current limit MSR */ | ||
111 | |||
112 | /* define the two driver architectures */ | ||
113 | #define CPU_OPTERON 0 | ||
114 | #define CPU_HW_PSTATE 1 | ||
115 | |||
116 | |||
117 | /* | ||
118 | * There are restrictions frequencies have to follow: | ||
119 | * - only 1 entry in the low fid table ( <=1.4GHz ) | ||
120 | * - lowest entry in the high fid table must be >= 2 * the entry in the | ||
121 | * low fid table | ||
122 | * - lowest entry in the high fid table must be a <= 200MHz + 2 * the entry | ||
123 | * in the low fid table | ||
124 | * - the parts can only step at <= 200 MHz intervals, odd fid values are | ||
125 | * supported in revision G and later revisions. | ||
126 | * - lowest frequency must be >= interprocessor hypertransport link speed | ||
127 | * (only applies to MP systems obviously) | ||
128 | */ | ||
129 | |||
130 | /* fids (frequency identifiers) are arranged in 2 tables - lo and hi */ | ||
131 | #define LO_FID_TABLE_TOP 7 /* fid values marking the boundary */ | ||
132 | #define HI_FID_TABLE_BOTTOM 8 /* between the low and high tables */ | ||
133 | |||
134 | #define LO_VCOFREQ_TABLE_TOP 1400 /* corresponding vco frequency values */ | ||
135 | #define HI_VCOFREQ_TABLE_BOTTOM 1600 | ||
136 | |||
137 | #define MIN_FREQ_RESOLUTION 200 /* fids jump by 2 matching freq jumps by 200 */ | ||
138 | |||
139 | #define MAX_FID 0x2a /* Spec only gives FID values as far as 5 GHz */ | ||
140 | #define LEAST_VID 0x3e /* Lowest (numerically highest) useful vid value */ | ||
141 | |||
142 | #define MIN_FREQ 800 /* Min and max freqs, per spec */ | ||
143 | #define MAX_FREQ 5000 | ||
144 | |||
145 | #define INVALID_FID_MASK 0xffffffc0 /* not a valid fid if these bits are set */ | ||
146 | #define INVALID_VID_MASK 0xffffffc0 /* not a valid vid if these bits are set */ | ||
147 | |||
148 | #define VID_OFF 0x3f | ||
149 | |||
150 | #define STOP_GRANT_5NS 1 /* min poss memory access latency for voltage change */ | ||
151 | |||
152 | #define PLL_LOCK_CONVERSION (1000/5) /* ms to ns, then divide by clock period */ | ||
153 | |||
154 | #define MAXIMUM_VID_STEPS 1 /* Current cpus only allow a single step of 25mV */ | ||
155 | #define VST_UNITS_20US 20 /* Voltage Stabilization Time is in units of 20us */ | ||
156 | |||
157 | /* | ||
158 | * Most values of interest are encoded in a single field of the _PSS | ||
159 | * entries: the "control" value. | ||
160 | */ | ||
161 | |||
162 | #define IRT_SHIFT 30 | ||
163 | #define RVO_SHIFT 28 | ||
164 | #define EXT_TYPE_SHIFT 27 | ||
165 | #define PLL_L_SHIFT 20 | ||
166 | #define MVS_SHIFT 18 | ||
167 | #define VST_SHIFT 11 | ||
168 | #define VID_SHIFT 6 | ||
169 | #define IRT_MASK 3 | ||
170 | #define RVO_MASK 3 | ||
171 | #define EXT_TYPE_MASK 1 | ||
172 | #define PLL_L_MASK 0x7f | ||
173 | #define MVS_MASK 3 | ||
174 | #define VST_MASK 0x7f | ||
175 | #define VID_MASK 0x1f | ||
176 | #define FID_MASK 0x1f | ||
177 | #define EXT_VID_MASK 0x3f | ||
178 | #define EXT_FID_MASK 0x3f | ||
179 | |||
180 | |||
181 | /* | ||
182 | * Version 1.4 of the PSB table. This table is constructed by BIOS and is | ||
183 | * to tell the OS's power management driver which VIDs and FIDs are | ||
184 | * supported by this particular processor. | ||
185 | * If the data in the PSB / PST is wrong, then this driver will program the | ||
186 | * wrong values into hardware, which is very likely to lead to a crash. | ||
187 | */ | ||
188 | |||
189 | #define PSB_ID_STRING "AMDK7PNOW!" | ||
190 | #define PSB_ID_STRING_LEN 10 | ||
191 | |||
192 | #define PSB_VERSION_1_4 0x14 | ||
193 | |||
194 | struct psb_s { | ||
195 | u8 signature[10]; | ||
196 | u8 tableversion; | ||
197 | u8 flags1; | ||
198 | u16 vstable; | ||
199 | u8 flags2; | ||
200 | u8 num_tables; | ||
201 | u32 cpuid; | ||
202 | u8 plllocktime; | ||
203 | u8 maxfid; | ||
204 | u8 maxvid; | ||
205 | u8 numps; | ||
206 | }; | ||
207 | |||
208 | /* Pairs of fid/vid values are appended to the version 1.4 PSB table. */ | ||
209 | struct pst_s { | ||
210 | u8 fid; | ||
211 | u8 vid; | ||
212 | }; | ||
213 | |||
214 | static int core_voltage_pre_transition(struct powernow_k8_data *data, | ||
215 | u32 reqvid, u32 regfid); | ||
216 | static int core_voltage_post_transition(struct powernow_k8_data *data, u32 reqvid); | ||
217 | static int core_frequency_transition(struct powernow_k8_data *data, u32 reqfid); | ||
218 | |||
219 | static void powernow_k8_acpi_pst_values(struct powernow_k8_data *data, unsigned int index); | ||
220 | |||
221 | static int fill_powernow_table_pstate(struct powernow_k8_data *data, struct cpufreq_frequency_table *powernow_table); | ||
222 | static int fill_powernow_table_fidvid(struct powernow_k8_data *data, struct cpufreq_frequency_table *powernow_table); | ||
diff --git a/drivers/cpufreq/sc520_freq.c b/drivers/cpufreq/sc520_freq.c new file mode 100644 index 000000000000..1e205e6b1727 --- /dev/null +++ b/drivers/cpufreq/sc520_freq.c | |||
@@ -0,0 +1,192 @@ | |||
1 | /* | ||
2 | * sc520_freq.c: cpufreq driver for the AMD Elan sc520 | ||
3 | * | ||
4 | * Copyright (C) 2005 Sean Young <sean@mess.org> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU General Public License | ||
8 | * as published by the Free Software Foundation; either version | ||
9 | * 2 of the License, or (at your option) any later version. | ||
10 | * | ||
11 | * Based on elanfreq.c | ||
12 | * | ||
13 | * 2005-03-30: - initial revision | ||
14 | */ | ||
15 | |||
16 | #include <linux/kernel.h> | ||
17 | #include <linux/module.h> | ||
18 | #include <linux/init.h> | ||
19 | |||
20 | #include <linux/delay.h> | ||
21 | #include <linux/cpufreq.h> | ||
22 | #include <linux/timex.h> | ||
23 | #include <linux/io.h> | ||
24 | |||
25 | #include <asm/msr.h> | ||
26 | |||
27 | #define MMCR_BASE 0xfffef000 /* The default base address */ | ||
28 | #define OFFS_CPUCTL 0x2 /* CPU Control Register */ | ||
29 | |||
30 | static __u8 __iomem *cpuctl; | ||
31 | |||
32 | #define PFX "sc520_freq: " | ||
33 | |||
34 | static struct cpufreq_frequency_table sc520_freq_table[] = { | ||
35 | {0x01, 100000}, | ||
36 | {0x02, 133000}, | ||
37 | {0, CPUFREQ_TABLE_END}, | ||
38 | }; | ||
39 | |||
40 | static unsigned int sc520_freq_get_cpu_frequency(unsigned int cpu) | ||
41 | { | ||
42 | u8 clockspeed_reg = *cpuctl; | ||
43 | |||
44 | switch (clockspeed_reg & 0x03) { | ||
45 | default: | ||
46 | printk(KERN_ERR PFX "error: cpuctl register has unexpected " | ||
47 | "value %02x\n", clockspeed_reg); | ||
48 | case 0x01: | ||
49 | return 100000; | ||
50 | case 0x02: | ||
51 | return 133000; | ||
52 | } | ||
53 | } | ||
54 | |||
55 | static void sc520_freq_set_cpu_state(unsigned int state) | ||
56 | { | ||
57 | |||
58 | struct cpufreq_freqs freqs; | ||
59 | u8 clockspeed_reg; | ||
60 | |||
61 | freqs.old = sc520_freq_get_cpu_frequency(0); | ||
62 | freqs.new = sc520_freq_table[state].frequency; | ||
63 | freqs.cpu = 0; /* AMD Elan is UP */ | ||
64 | |||
65 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
66 | |||
67 | pr_debug("attempting to set frequency to %i kHz\n", | ||
68 | sc520_freq_table[state].frequency); | ||
69 | |||
70 | local_irq_disable(); | ||
71 | |||
72 | clockspeed_reg = *cpuctl & ~0x03; | ||
73 | *cpuctl = clockspeed_reg | sc520_freq_table[state].index; | ||
74 | |||
75 | local_irq_enable(); | ||
76 | |||
77 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
78 | }; | ||
79 | |||
80 | static int sc520_freq_verify(struct cpufreq_policy *policy) | ||
81 | { | ||
82 | return cpufreq_frequency_table_verify(policy, &sc520_freq_table[0]); | ||
83 | } | ||
84 | |||
85 | static int sc520_freq_target(struct cpufreq_policy *policy, | ||
86 | unsigned int target_freq, | ||
87 | unsigned int relation) | ||
88 | { | ||
89 | unsigned int newstate = 0; | ||
90 | |||
91 | if (cpufreq_frequency_table_target(policy, sc520_freq_table, | ||
92 | target_freq, relation, &newstate)) | ||
93 | return -EINVAL; | ||
94 | |||
95 | sc520_freq_set_cpu_state(newstate); | ||
96 | |||
97 | return 0; | ||
98 | } | ||
99 | |||
100 | |||
101 | /* | ||
102 | * Module init and exit code | ||
103 | */ | ||
104 | |||
105 | static int sc520_freq_cpu_init(struct cpufreq_policy *policy) | ||
106 | { | ||
107 | struct cpuinfo_x86 *c = &cpu_data(0); | ||
108 | int result; | ||
109 | |||
110 | /* capability check */ | ||
111 | if (c->x86_vendor != X86_VENDOR_AMD || | ||
112 | c->x86 != 4 || c->x86_model != 9) | ||
113 | return -ENODEV; | ||
114 | |||
115 | /* cpuinfo and default policy values */ | ||
116 | policy->cpuinfo.transition_latency = 1000000; /* 1ms */ | ||
117 | policy->cur = sc520_freq_get_cpu_frequency(0); | ||
118 | |||
119 | result = cpufreq_frequency_table_cpuinfo(policy, sc520_freq_table); | ||
120 | if (result) | ||
121 | return result; | ||
122 | |||
123 | cpufreq_frequency_table_get_attr(sc520_freq_table, policy->cpu); | ||
124 | |||
125 | return 0; | ||
126 | } | ||
127 | |||
128 | |||
129 | static int sc520_freq_cpu_exit(struct cpufreq_policy *policy) | ||
130 | { | ||
131 | cpufreq_frequency_table_put_attr(policy->cpu); | ||
132 | return 0; | ||
133 | } | ||
134 | |||
135 | |||
136 | static struct freq_attr *sc520_freq_attr[] = { | ||
137 | &cpufreq_freq_attr_scaling_available_freqs, | ||
138 | NULL, | ||
139 | }; | ||
140 | |||
141 | |||
142 | static struct cpufreq_driver sc520_freq_driver = { | ||
143 | .get = sc520_freq_get_cpu_frequency, | ||
144 | .verify = sc520_freq_verify, | ||
145 | .target = sc520_freq_target, | ||
146 | .init = sc520_freq_cpu_init, | ||
147 | .exit = sc520_freq_cpu_exit, | ||
148 | .name = "sc520_freq", | ||
149 | .owner = THIS_MODULE, | ||
150 | .attr = sc520_freq_attr, | ||
151 | }; | ||
152 | |||
153 | |||
154 | static int __init sc520_freq_init(void) | ||
155 | { | ||
156 | struct cpuinfo_x86 *c = &cpu_data(0); | ||
157 | int err; | ||
158 | |||
159 | /* Test if we have the right hardware */ | ||
160 | if (c->x86_vendor != X86_VENDOR_AMD || | ||
161 | c->x86 != 4 || c->x86_model != 9) { | ||
162 | pr_debug("no Elan SC520 processor found!\n"); | ||
163 | return -ENODEV; | ||
164 | } | ||
165 | cpuctl = ioremap((unsigned long)(MMCR_BASE + OFFS_CPUCTL), 1); | ||
166 | if (!cpuctl) { | ||
167 | printk(KERN_ERR "sc520_freq: error: failed to remap memory\n"); | ||
168 | return -ENOMEM; | ||
169 | } | ||
170 | |||
171 | err = cpufreq_register_driver(&sc520_freq_driver); | ||
172 | if (err) | ||
173 | iounmap(cpuctl); | ||
174 | |||
175 | return err; | ||
176 | } | ||
177 | |||
178 | |||
179 | static void __exit sc520_freq_exit(void) | ||
180 | { | ||
181 | cpufreq_unregister_driver(&sc520_freq_driver); | ||
182 | iounmap(cpuctl); | ||
183 | } | ||
184 | |||
185 | |||
186 | MODULE_LICENSE("GPL"); | ||
187 | MODULE_AUTHOR("Sean Young <sean@mess.org>"); | ||
188 | MODULE_DESCRIPTION("cpufreq driver for AMD's Elan sc520 CPU"); | ||
189 | |||
190 | module_init(sc520_freq_init); | ||
191 | module_exit(sc520_freq_exit); | ||
192 | |||
diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c new file mode 100644 index 000000000000..6ea3455def21 --- /dev/null +++ b/drivers/cpufreq/speedstep-centrino.c | |||
@@ -0,0 +1,633 @@ | |||
1 | /* | ||
2 | * cpufreq driver for Enhanced SpeedStep, as found in Intel's Pentium | ||
3 | * M (part of the Centrino chipset). | ||
4 | * | ||
5 | * Since the original Pentium M, most new Intel CPUs support Enhanced | ||
6 | * SpeedStep. | ||
7 | * | ||
8 | * Despite the "SpeedStep" in the name, this is almost entirely unlike | ||
9 | * traditional SpeedStep. | ||
10 | * | ||
11 | * Modelled on speedstep.c | ||
12 | * | ||
13 | * Copyright (C) 2003 Jeremy Fitzhardinge <jeremy@goop.org> | ||
14 | */ | ||
15 | |||
16 | #include <linux/kernel.h> | ||
17 | #include <linux/module.h> | ||
18 | #include <linux/init.h> | ||
19 | #include <linux/cpufreq.h> | ||
20 | #include <linux/sched.h> /* current */ | ||
21 | #include <linux/delay.h> | ||
22 | #include <linux/compiler.h> | ||
23 | #include <linux/gfp.h> | ||
24 | |||
25 | #include <asm/msr.h> | ||
26 | #include <asm/processor.h> | ||
27 | #include <asm/cpufeature.h> | ||
28 | |||
29 | #define PFX "speedstep-centrino: " | ||
30 | #define MAINTAINER "cpufreq@vger.kernel.org" | ||
31 | |||
32 | #define INTEL_MSR_RANGE (0xffff) | ||
33 | |||
34 | struct cpu_id | ||
35 | { | ||
36 | __u8 x86; /* CPU family */ | ||
37 | __u8 x86_model; /* model */ | ||
38 | __u8 x86_mask; /* stepping */ | ||
39 | }; | ||
40 | |||
41 | enum { | ||
42 | CPU_BANIAS, | ||
43 | CPU_DOTHAN_A1, | ||
44 | CPU_DOTHAN_A2, | ||
45 | CPU_DOTHAN_B0, | ||
46 | CPU_MP4HT_D0, | ||
47 | CPU_MP4HT_E0, | ||
48 | }; | ||
49 | |||
50 | static const struct cpu_id cpu_ids[] = { | ||
51 | [CPU_BANIAS] = { 6, 9, 5 }, | ||
52 | [CPU_DOTHAN_A1] = { 6, 13, 1 }, | ||
53 | [CPU_DOTHAN_A2] = { 6, 13, 2 }, | ||
54 | [CPU_DOTHAN_B0] = { 6, 13, 6 }, | ||
55 | [CPU_MP4HT_D0] = {15, 3, 4 }, | ||
56 | [CPU_MP4HT_E0] = {15, 4, 1 }, | ||
57 | }; | ||
58 | #define N_IDS ARRAY_SIZE(cpu_ids) | ||
59 | |||
60 | struct cpu_model | ||
61 | { | ||
62 | const struct cpu_id *cpu_id; | ||
63 | const char *model_name; | ||
64 | unsigned max_freq; /* max clock in kHz */ | ||
65 | |||
66 | struct cpufreq_frequency_table *op_points; /* clock/voltage pairs */ | ||
67 | }; | ||
68 | static int centrino_verify_cpu_id(const struct cpuinfo_x86 *c, | ||
69 | const struct cpu_id *x); | ||
70 | |||
71 | /* Operating points for current CPU */ | ||
72 | static DEFINE_PER_CPU(struct cpu_model *, centrino_model); | ||
73 | static DEFINE_PER_CPU(const struct cpu_id *, centrino_cpu); | ||
74 | |||
75 | static struct cpufreq_driver centrino_driver; | ||
76 | |||
77 | #ifdef CONFIG_X86_SPEEDSTEP_CENTRINO_TABLE | ||
78 | |||
79 | /* Computes the correct form for IA32_PERF_CTL MSR for a particular | ||
80 | frequency/voltage operating point; frequency in MHz, volts in mV. | ||
81 | This is stored as "index" in the structure. */ | ||
82 | #define OP(mhz, mv) \ | ||
83 | { \ | ||
84 | .frequency = (mhz) * 1000, \ | ||
85 | .index = (((mhz)/100) << 8) | ((mv - 700) / 16) \ | ||
86 | } | ||
87 | |||
88 | /* | ||
89 | * These voltage tables were derived from the Intel Pentium M | ||
90 | * datasheet, document 25261202.pdf, Table 5. I have verified they | ||
91 | * are consistent with my IBM ThinkPad X31, which has a 1.3GHz Pentium | ||
92 | * M. | ||
93 | */ | ||
94 | |||
95 | /* Ultra Low Voltage Intel Pentium M processor 900MHz (Banias) */ | ||
96 | static struct cpufreq_frequency_table banias_900[] = | ||
97 | { | ||
98 | OP(600, 844), | ||
99 | OP(800, 988), | ||
100 | OP(900, 1004), | ||
101 | { .frequency = CPUFREQ_TABLE_END } | ||
102 | }; | ||
103 | |||
104 | /* Ultra Low Voltage Intel Pentium M processor 1000MHz (Banias) */ | ||
105 | static struct cpufreq_frequency_table banias_1000[] = | ||
106 | { | ||
107 | OP(600, 844), | ||
108 | OP(800, 972), | ||
109 | OP(900, 988), | ||
110 | OP(1000, 1004), | ||
111 | { .frequency = CPUFREQ_TABLE_END } | ||
112 | }; | ||
113 | |||
114 | /* Low Voltage Intel Pentium M processor 1.10GHz (Banias) */ | ||
115 | static struct cpufreq_frequency_table banias_1100[] = | ||
116 | { | ||
117 | OP( 600, 956), | ||
118 | OP( 800, 1020), | ||
119 | OP( 900, 1100), | ||
120 | OP(1000, 1164), | ||
121 | OP(1100, 1180), | ||
122 | { .frequency = CPUFREQ_TABLE_END } | ||
123 | }; | ||
124 | |||
125 | |||
126 | /* Low Voltage Intel Pentium M processor 1.20GHz (Banias) */ | ||
127 | static struct cpufreq_frequency_table banias_1200[] = | ||
128 | { | ||
129 | OP( 600, 956), | ||
130 | OP( 800, 1004), | ||
131 | OP( 900, 1020), | ||
132 | OP(1000, 1100), | ||
133 | OP(1100, 1164), | ||
134 | OP(1200, 1180), | ||
135 | { .frequency = CPUFREQ_TABLE_END } | ||
136 | }; | ||
137 | |||
138 | /* Intel Pentium M processor 1.30GHz (Banias) */ | ||
139 | static struct cpufreq_frequency_table banias_1300[] = | ||
140 | { | ||
141 | OP( 600, 956), | ||
142 | OP( 800, 1260), | ||
143 | OP(1000, 1292), | ||
144 | OP(1200, 1356), | ||
145 | OP(1300, 1388), | ||
146 | { .frequency = CPUFREQ_TABLE_END } | ||
147 | }; | ||
148 | |||
149 | /* Intel Pentium M processor 1.40GHz (Banias) */ | ||
150 | static struct cpufreq_frequency_table banias_1400[] = | ||
151 | { | ||
152 | OP( 600, 956), | ||
153 | OP( 800, 1180), | ||
154 | OP(1000, 1308), | ||
155 | OP(1200, 1436), | ||
156 | OP(1400, 1484), | ||
157 | { .frequency = CPUFREQ_TABLE_END } | ||
158 | }; | ||
159 | |||
160 | /* Intel Pentium M processor 1.50GHz (Banias) */ | ||
161 | static struct cpufreq_frequency_table banias_1500[] = | ||
162 | { | ||
163 | OP( 600, 956), | ||
164 | OP( 800, 1116), | ||
165 | OP(1000, 1228), | ||
166 | OP(1200, 1356), | ||
167 | OP(1400, 1452), | ||
168 | OP(1500, 1484), | ||
169 | { .frequency = CPUFREQ_TABLE_END } | ||
170 | }; | ||
171 | |||
172 | /* Intel Pentium M processor 1.60GHz (Banias) */ | ||
173 | static struct cpufreq_frequency_table banias_1600[] = | ||
174 | { | ||
175 | OP( 600, 956), | ||
176 | OP( 800, 1036), | ||
177 | OP(1000, 1164), | ||
178 | OP(1200, 1276), | ||
179 | OP(1400, 1420), | ||
180 | OP(1600, 1484), | ||
181 | { .frequency = CPUFREQ_TABLE_END } | ||
182 | }; | ||
183 | |||
184 | /* Intel Pentium M processor 1.70GHz (Banias) */ | ||
185 | static struct cpufreq_frequency_table banias_1700[] = | ||
186 | { | ||
187 | OP( 600, 956), | ||
188 | OP( 800, 1004), | ||
189 | OP(1000, 1116), | ||
190 | OP(1200, 1228), | ||
191 | OP(1400, 1308), | ||
192 | OP(1700, 1484), | ||
193 | { .frequency = CPUFREQ_TABLE_END } | ||
194 | }; | ||
195 | #undef OP | ||
196 | |||
197 | #define _BANIAS(cpuid, max, name) \ | ||
198 | { .cpu_id = cpuid, \ | ||
199 | .model_name = "Intel(R) Pentium(R) M processor " name "MHz", \ | ||
200 | .max_freq = (max)*1000, \ | ||
201 | .op_points = banias_##max, \ | ||
202 | } | ||
203 | #define BANIAS(max) _BANIAS(&cpu_ids[CPU_BANIAS], max, #max) | ||
204 | |||
205 | /* CPU models, their operating frequency range, and freq/voltage | ||
206 | operating points */ | ||
207 | static struct cpu_model models[] = | ||
208 | { | ||
209 | _BANIAS(&cpu_ids[CPU_BANIAS], 900, " 900"), | ||
210 | BANIAS(1000), | ||
211 | BANIAS(1100), | ||
212 | BANIAS(1200), | ||
213 | BANIAS(1300), | ||
214 | BANIAS(1400), | ||
215 | BANIAS(1500), | ||
216 | BANIAS(1600), | ||
217 | BANIAS(1700), | ||
218 | |||
219 | /* NULL model_name is a wildcard */ | ||
220 | { &cpu_ids[CPU_DOTHAN_A1], NULL, 0, NULL }, | ||
221 | { &cpu_ids[CPU_DOTHAN_A2], NULL, 0, NULL }, | ||
222 | { &cpu_ids[CPU_DOTHAN_B0], NULL, 0, NULL }, | ||
223 | { &cpu_ids[CPU_MP4HT_D0], NULL, 0, NULL }, | ||
224 | { &cpu_ids[CPU_MP4HT_E0], NULL, 0, NULL }, | ||
225 | |||
226 | { NULL, } | ||
227 | }; | ||
228 | #undef _BANIAS | ||
229 | #undef BANIAS | ||
230 | |||
231 | static int centrino_cpu_init_table(struct cpufreq_policy *policy) | ||
232 | { | ||
233 | struct cpuinfo_x86 *cpu = &cpu_data(policy->cpu); | ||
234 | struct cpu_model *model; | ||
235 | |||
236 | for(model = models; model->cpu_id != NULL; model++) | ||
237 | if (centrino_verify_cpu_id(cpu, model->cpu_id) && | ||
238 | (model->model_name == NULL || | ||
239 | strcmp(cpu->x86_model_id, model->model_name) == 0)) | ||
240 | break; | ||
241 | |||
242 | if (model->cpu_id == NULL) { | ||
243 | /* No match at all */ | ||
244 | pr_debug("no support for CPU model \"%s\": " | ||
245 | "send /proc/cpuinfo to " MAINTAINER "\n", | ||
246 | cpu->x86_model_id); | ||
247 | return -ENOENT; | ||
248 | } | ||
249 | |||
250 | if (model->op_points == NULL) { | ||
251 | /* Matched a non-match */ | ||
252 | pr_debug("no table support for CPU model \"%s\"\n", | ||
253 | cpu->x86_model_id); | ||
254 | pr_debug("try using the acpi-cpufreq driver\n"); | ||
255 | return -ENOENT; | ||
256 | } | ||
257 | |||
258 | per_cpu(centrino_model, policy->cpu) = model; | ||
259 | |||
260 | pr_debug("found \"%s\": max frequency: %dkHz\n", | ||
261 | model->model_name, model->max_freq); | ||
262 | |||
263 | return 0; | ||
264 | } | ||
265 | |||
266 | #else | ||
267 | static inline int centrino_cpu_init_table(struct cpufreq_policy *policy) | ||
268 | { | ||
269 | return -ENODEV; | ||
270 | } | ||
271 | #endif /* CONFIG_X86_SPEEDSTEP_CENTRINO_TABLE */ | ||
272 | |||
273 | static int centrino_verify_cpu_id(const struct cpuinfo_x86 *c, | ||
274 | const struct cpu_id *x) | ||
275 | { | ||
276 | if ((c->x86 == x->x86) && | ||
277 | (c->x86_model == x->x86_model) && | ||
278 | (c->x86_mask == x->x86_mask)) | ||
279 | return 1; | ||
280 | return 0; | ||
281 | } | ||
282 | |||
283 | /* To be called only after centrino_model is initialized */ | ||
284 | static unsigned extract_clock(unsigned msr, unsigned int cpu, int failsafe) | ||
285 | { | ||
286 | int i; | ||
287 | |||
288 | /* | ||
289 | * Extract clock in kHz from PERF_CTL value | ||
290 | * for centrino, as some DSDTs are buggy. | ||
291 | * Ideally, this can be done using the acpi_data structure. | ||
292 | */ | ||
293 | if ((per_cpu(centrino_cpu, cpu) == &cpu_ids[CPU_BANIAS]) || | ||
294 | (per_cpu(centrino_cpu, cpu) == &cpu_ids[CPU_DOTHAN_A1]) || | ||
295 | (per_cpu(centrino_cpu, cpu) == &cpu_ids[CPU_DOTHAN_B0])) { | ||
296 | msr = (msr >> 8) & 0xff; | ||
297 | return msr * 100000; | ||
298 | } | ||
299 | |||
300 | if ((!per_cpu(centrino_model, cpu)) || | ||
301 | (!per_cpu(centrino_model, cpu)->op_points)) | ||
302 | return 0; | ||
303 | |||
304 | msr &= 0xffff; | ||
305 | for (i = 0; | ||
306 | per_cpu(centrino_model, cpu)->op_points[i].frequency | ||
307 | != CPUFREQ_TABLE_END; | ||
308 | i++) { | ||
309 | if (msr == per_cpu(centrino_model, cpu)->op_points[i].index) | ||
310 | return per_cpu(centrino_model, cpu)-> | ||
311 | op_points[i].frequency; | ||
312 | } | ||
313 | if (failsafe) | ||
314 | return per_cpu(centrino_model, cpu)->op_points[i-1].frequency; | ||
315 | else | ||
316 | return 0; | ||
317 | } | ||
318 | |||
319 | /* Return the current CPU frequency in kHz */ | ||
320 | static unsigned int get_cur_freq(unsigned int cpu) | ||
321 | { | ||
322 | unsigned l, h; | ||
323 | unsigned clock_freq; | ||
324 | |||
325 | rdmsr_on_cpu(cpu, MSR_IA32_PERF_STATUS, &l, &h); | ||
326 | clock_freq = extract_clock(l, cpu, 0); | ||
327 | |||
328 | if (unlikely(clock_freq == 0)) { | ||
329 | /* | ||
330 | * On some CPUs, we can see transient MSR values (which are | ||
331 | * not present in _PSS), while CPU is doing some automatic | ||
332 | * P-state transition (like TM2). Get the last freq set | ||
333 | * in PERF_CTL. | ||
334 | */ | ||
335 | rdmsr_on_cpu(cpu, MSR_IA32_PERF_CTL, &l, &h); | ||
336 | clock_freq = extract_clock(l, cpu, 1); | ||
337 | } | ||
338 | return clock_freq; | ||
339 | } | ||
340 | |||
341 | |||
342 | static int centrino_cpu_init(struct cpufreq_policy *policy) | ||
343 | { | ||
344 | struct cpuinfo_x86 *cpu = &cpu_data(policy->cpu); | ||
345 | unsigned freq; | ||
346 | unsigned l, h; | ||
347 | int ret; | ||
348 | int i; | ||
349 | |||
350 | /* Only Intel makes Enhanced Speedstep-capable CPUs */ | ||
351 | if (cpu->x86_vendor != X86_VENDOR_INTEL || | ||
352 | !cpu_has(cpu, X86_FEATURE_EST)) | ||
353 | return -ENODEV; | ||
354 | |||
355 | if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) | ||
356 | centrino_driver.flags |= CPUFREQ_CONST_LOOPS; | ||
357 | |||
358 | if (policy->cpu != 0) | ||
359 | return -ENODEV; | ||
360 | |||
361 | for (i = 0; i < N_IDS; i++) | ||
362 | if (centrino_verify_cpu_id(cpu, &cpu_ids[i])) | ||
363 | break; | ||
364 | |||
365 | if (i != N_IDS) | ||
366 | per_cpu(centrino_cpu, policy->cpu) = &cpu_ids[i]; | ||
367 | |||
368 | if (!per_cpu(centrino_cpu, policy->cpu)) { | ||
369 | pr_debug("found unsupported CPU with " | ||
370 | "Enhanced SpeedStep: send /proc/cpuinfo to " | ||
371 | MAINTAINER "\n"); | ||
372 | return -ENODEV; | ||
373 | } | ||
374 | |||
375 | if (centrino_cpu_init_table(policy)) { | ||
376 | return -ENODEV; | ||
377 | } | ||
378 | |||
379 | /* Check to see if Enhanced SpeedStep is enabled, and try to | ||
380 | enable it if not. */ | ||
381 | rdmsr(MSR_IA32_MISC_ENABLE, l, h); | ||
382 | |||
383 | if (!(l & MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP)) { | ||
384 | l |= MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP; | ||
385 | pr_debug("trying to enable Enhanced SpeedStep (%x)\n", l); | ||
386 | wrmsr(MSR_IA32_MISC_ENABLE, l, h); | ||
387 | |||
388 | /* check to see if it stuck */ | ||
389 | rdmsr(MSR_IA32_MISC_ENABLE, l, h); | ||
390 | if (!(l & MSR_IA32_MISC_ENABLE_ENHANCED_SPEEDSTEP)) { | ||
391 | printk(KERN_INFO PFX | ||
392 | "couldn't enable Enhanced SpeedStep\n"); | ||
393 | return -ENODEV; | ||
394 | } | ||
395 | } | ||
396 | |||
397 | freq = get_cur_freq(policy->cpu); | ||
398 | policy->cpuinfo.transition_latency = 10000; | ||
399 | /* 10uS transition latency */ | ||
400 | policy->cur = freq; | ||
401 | |||
402 | pr_debug("centrino_cpu_init: cur=%dkHz\n", policy->cur); | ||
403 | |||
404 | ret = cpufreq_frequency_table_cpuinfo(policy, | ||
405 | per_cpu(centrino_model, policy->cpu)->op_points); | ||
406 | if (ret) | ||
407 | return (ret); | ||
408 | |||
409 | cpufreq_frequency_table_get_attr( | ||
410 | per_cpu(centrino_model, policy->cpu)->op_points, policy->cpu); | ||
411 | |||
412 | return 0; | ||
413 | } | ||
414 | |||
415 | static int centrino_cpu_exit(struct cpufreq_policy *policy) | ||
416 | { | ||
417 | unsigned int cpu = policy->cpu; | ||
418 | |||
419 | if (!per_cpu(centrino_model, cpu)) | ||
420 | return -ENODEV; | ||
421 | |||
422 | cpufreq_frequency_table_put_attr(cpu); | ||
423 | |||
424 | per_cpu(centrino_model, cpu) = NULL; | ||
425 | |||
426 | return 0; | ||
427 | } | ||
428 | |||
429 | /** | ||
430 | * centrino_verify - verifies a new CPUFreq policy | ||
431 | * @policy: new policy | ||
432 | * | ||
433 | * Limit must be within this model's frequency range at least one | ||
434 | * border included. | ||
435 | */ | ||
436 | static int centrino_verify (struct cpufreq_policy *policy) | ||
437 | { | ||
438 | return cpufreq_frequency_table_verify(policy, | ||
439 | per_cpu(centrino_model, policy->cpu)->op_points); | ||
440 | } | ||
441 | |||
442 | /** | ||
443 | * centrino_setpolicy - set a new CPUFreq policy | ||
444 | * @policy: new policy | ||
445 | * @target_freq: the target frequency | ||
446 | * @relation: how that frequency relates to achieved frequency | ||
447 | * (CPUFREQ_RELATION_L or CPUFREQ_RELATION_H) | ||
448 | * | ||
449 | * Sets a new CPUFreq policy. | ||
450 | */ | ||
451 | static int centrino_target (struct cpufreq_policy *policy, | ||
452 | unsigned int target_freq, | ||
453 | unsigned int relation) | ||
454 | { | ||
455 | unsigned int newstate = 0; | ||
456 | unsigned int msr, oldmsr = 0, h = 0, cpu = policy->cpu; | ||
457 | struct cpufreq_freqs freqs; | ||
458 | int retval = 0; | ||
459 | unsigned int j, k, first_cpu, tmp; | ||
460 | cpumask_var_t covered_cpus; | ||
461 | |||
462 | if (unlikely(!zalloc_cpumask_var(&covered_cpus, GFP_KERNEL))) | ||
463 | return -ENOMEM; | ||
464 | |||
465 | if (unlikely(per_cpu(centrino_model, cpu) == NULL)) { | ||
466 | retval = -ENODEV; | ||
467 | goto out; | ||
468 | } | ||
469 | |||
470 | if (unlikely(cpufreq_frequency_table_target(policy, | ||
471 | per_cpu(centrino_model, cpu)->op_points, | ||
472 | target_freq, | ||
473 | relation, | ||
474 | &newstate))) { | ||
475 | retval = -EINVAL; | ||
476 | goto out; | ||
477 | } | ||
478 | |||
479 | first_cpu = 1; | ||
480 | for_each_cpu(j, policy->cpus) { | ||
481 | int good_cpu; | ||
482 | |||
483 | /* cpufreq holds the hotplug lock, so we are safe here */ | ||
484 | if (!cpu_online(j)) | ||
485 | continue; | ||
486 | |||
487 | /* | ||
488 | * Support for SMP systems. | ||
489 | * Make sure we are running on CPU that wants to change freq | ||
490 | */ | ||
491 | if (policy->shared_type == CPUFREQ_SHARED_TYPE_ANY) | ||
492 | good_cpu = cpumask_any_and(policy->cpus, | ||
493 | cpu_online_mask); | ||
494 | else | ||
495 | good_cpu = j; | ||
496 | |||
497 | if (good_cpu >= nr_cpu_ids) { | ||
498 | pr_debug("couldn't limit to CPUs in this domain\n"); | ||
499 | retval = -EAGAIN; | ||
500 | if (first_cpu) { | ||
501 | /* We haven't started the transition yet. */ | ||
502 | goto out; | ||
503 | } | ||
504 | break; | ||
505 | } | ||
506 | |||
507 | msr = per_cpu(centrino_model, cpu)->op_points[newstate].index; | ||
508 | |||
509 | if (first_cpu) { | ||
510 | rdmsr_on_cpu(good_cpu, MSR_IA32_PERF_CTL, &oldmsr, &h); | ||
511 | if (msr == (oldmsr & 0xffff)) { | ||
512 | pr_debug("no change needed - msr was and needs " | ||
513 | "to be %x\n", oldmsr); | ||
514 | retval = 0; | ||
515 | goto out; | ||
516 | } | ||
517 | |||
518 | freqs.old = extract_clock(oldmsr, cpu, 0); | ||
519 | freqs.new = extract_clock(msr, cpu, 0); | ||
520 | |||
521 | pr_debug("target=%dkHz old=%d new=%d msr=%04x\n", | ||
522 | target_freq, freqs.old, freqs.new, msr); | ||
523 | |||
524 | for_each_cpu(k, policy->cpus) { | ||
525 | if (!cpu_online(k)) | ||
526 | continue; | ||
527 | freqs.cpu = k; | ||
528 | cpufreq_notify_transition(&freqs, | ||
529 | CPUFREQ_PRECHANGE); | ||
530 | } | ||
531 | |||
532 | first_cpu = 0; | ||
533 | /* all but 16 LSB are reserved, treat them with care */ | ||
534 | oldmsr &= ~0xffff; | ||
535 | msr &= 0xffff; | ||
536 | oldmsr |= msr; | ||
537 | } | ||
538 | |||
539 | wrmsr_on_cpu(good_cpu, MSR_IA32_PERF_CTL, oldmsr, h); | ||
540 | if (policy->shared_type == CPUFREQ_SHARED_TYPE_ANY) | ||
541 | break; | ||
542 | |||
543 | cpumask_set_cpu(j, covered_cpus); | ||
544 | } | ||
545 | |||
546 | for_each_cpu(k, policy->cpus) { | ||
547 | if (!cpu_online(k)) | ||
548 | continue; | ||
549 | freqs.cpu = k; | ||
550 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
551 | } | ||
552 | |||
553 | if (unlikely(retval)) { | ||
554 | /* | ||
555 | * We have failed halfway through the frequency change. | ||
556 | * We have sent callbacks to policy->cpus and | ||
557 | * MSRs have already been written on coverd_cpus. | ||
558 | * Best effort undo.. | ||
559 | */ | ||
560 | |||
561 | for_each_cpu(j, covered_cpus) | ||
562 | wrmsr_on_cpu(j, MSR_IA32_PERF_CTL, oldmsr, h); | ||
563 | |||
564 | tmp = freqs.new; | ||
565 | freqs.new = freqs.old; | ||
566 | freqs.old = tmp; | ||
567 | for_each_cpu(j, policy->cpus) { | ||
568 | if (!cpu_online(j)) | ||
569 | continue; | ||
570 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
571 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
572 | } | ||
573 | } | ||
574 | retval = 0; | ||
575 | |||
576 | out: | ||
577 | free_cpumask_var(covered_cpus); | ||
578 | return retval; | ||
579 | } | ||
580 | |||
581 | static struct freq_attr* centrino_attr[] = { | ||
582 | &cpufreq_freq_attr_scaling_available_freqs, | ||
583 | NULL, | ||
584 | }; | ||
585 | |||
586 | static struct cpufreq_driver centrino_driver = { | ||
587 | .name = "centrino", /* should be speedstep-centrino, | ||
588 | but there's a 16 char limit */ | ||
589 | .init = centrino_cpu_init, | ||
590 | .exit = centrino_cpu_exit, | ||
591 | .verify = centrino_verify, | ||
592 | .target = centrino_target, | ||
593 | .get = get_cur_freq, | ||
594 | .attr = centrino_attr, | ||
595 | .owner = THIS_MODULE, | ||
596 | }; | ||
597 | |||
598 | |||
599 | /** | ||
600 | * centrino_init - initializes the Enhanced SpeedStep CPUFreq driver | ||
601 | * | ||
602 | * Initializes the Enhanced SpeedStep support. Returns -ENODEV on | ||
603 | * unsupported devices, -ENOENT if there's no voltage table for this | ||
604 | * particular CPU model, -EINVAL on problems during initiatization, | ||
605 | * and zero on success. | ||
606 | * | ||
607 | * This is quite picky. Not only does the CPU have to advertise the | ||
608 | * "est" flag in the cpuid capability flags, we look for a specific | ||
609 | * CPU model and stepping, and we need to have the exact model name in | ||
610 | * our voltage tables. That is, be paranoid about not releasing | ||
611 | * someone's valuable magic smoke. | ||
612 | */ | ||
613 | static int __init centrino_init(void) | ||
614 | { | ||
615 | struct cpuinfo_x86 *cpu = &cpu_data(0); | ||
616 | |||
617 | if (!cpu_has(cpu, X86_FEATURE_EST)) | ||
618 | return -ENODEV; | ||
619 | |||
620 | return cpufreq_register_driver(¢rino_driver); | ||
621 | } | ||
622 | |||
623 | static void __exit centrino_exit(void) | ||
624 | { | ||
625 | cpufreq_unregister_driver(¢rino_driver); | ||
626 | } | ||
627 | |||
628 | MODULE_AUTHOR ("Jeremy Fitzhardinge <jeremy@goop.org>"); | ||
629 | MODULE_DESCRIPTION ("Enhanced SpeedStep driver for Intel Pentium M processors."); | ||
630 | MODULE_LICENSE ("GPL"); | ||
631 | |||
632 | late_initcall(centrino_init); | ||
633 | module_exit(centrino_exit); | ||
diff --git a/drivers/cpufreq/speedstep-ich.c b/drivers/cpufreq/speedstep-ich.c new file mode 100644 index 000000000000..a748ce782fee --- /dev/null +++ b/drivers/cpufreq/speedstep-ich.c | |||
@@ -0,0 +1,448 @@ | |||
1 | /* | ||
2 | * (C) 2001 Dave Jones, Arjan van de ven. | ||
3 | * (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de> | ||
4 | * | ||
5 | * Licensed under the terms of the GNU GPL License version 2. | ||
6 | * Based upon reverse engineered information, and on Intel documentation | ||
7 | * for chipsets ICH2-M and ICH3-M. | ||
8 | * | ||
9 | * Many thanks to Ducrot Bruno for finding and fixing the last | ||
10 | * "missing link" for ICH2-M/ICH3-M support, and to Thomas Winkler | ||
11 | * for extensive testing. | ||
12 | * | ||
13 | * BIG FAT DISCLAIMER: Work in progress code. Possibly *dangerous* | ||
14 | */ | ||
15 | |||
16 | |||
17 | /********************************************************************* | ||
18 | * SPEEDSTEP - DEFINITIONS * | ||
19 | *********************************************************************/ | ||
20 | |||
21 | #include <linux/kernel.h> | ||
22 | #include <linux/module.h> | ||
23 | #include <linux/init.h> | ||
24 | #include <linux/cpufreq.h> | ||
25 | #include <linux/pci.h> | ||
26 | #include <linux/sched.h> | ||
27 | |||
28 | #include "speedstep-lib.h" | ||
29 | |||
30 | |||
31 | /* speedstep_chipset: | ||
32 | * It is necessary to know which chipset is used. As accesses to | ||
33 | * this device occur at various places in this module, we need a | ||
34 | * static struct pci_dev * pointing to that device. | ||
35 | */ | ||
36 | static struct pci_dev *speedstep_chipset_dev; | ||
37 | |||
38 | |||
39 | /* speedstep_processor | ||
40 | */ | ||
41 | static enum speedstep_processor speedstep_processor; | ||
42 | |||
43 | static u32 pmbase; | ||
44 | |||
45 | /* | ||
46 | * There are only two frequency states for each processor. Values | ||
47 | * are in kHz for the time being. | ||
48 | */ | ||
49 | static struct cpufreq_frequency_table speedstep_freqs[] = { | ||
50 | {SPEEDSTEP_HIGH, 0}, | ||
51 | {SPEEDSTEP_LOW, 0}, | ||
52 | {0, CPUFREQ_TABLE_END}, | ||
53 | }; | ||
54 | |||
55 | |||
56 | /** | ||
57 | * speedstep_find_register - read the PMBASE address | ||
58 | * | ||
59 | * Returns: -ENODEV if no register could be found | ||
60 | */ | ||
61 | static int speedstep_find_register(void) | ||
62 | { | ||
63 | if (!speedstep_chipset_dev) | ||
64 | return -ENODEV; | ||
65 | |||
66 | /* get PMBASE */ | ||
67 | pci_read_config_dword(speedstep_chipset_dev, 0x40, &pmbase); | ||
68 | if (!(pmbase & 0x01)) { | ||
69 | printk(KERN_ERR "speedstep-ich: could not find speedstep register\n"); | ||
70 | return -ENODEV; | ||
71 | } | ||
72 | |||
73 | pmbase &= 0xFFFFFFFE; | ||
74 | if (!pmbase) { | ||
75 | printk(KERN_ERR "speedstep-ich: could not find speedstep register\n"); | ||
76 | return -ENODEV; | ||
77 | } | ||
78 | |||
79 | pr_debug("pmbase is 0x%x\n", pmbase); | ||
80 | return 0; | ||
81 | } | ||
82 | |||
83 | /** | ||
84 | * speedstep_set_state - set the SpeedStep state | ||
85 | * @state: new processor frequency state (SPEEDSTEP_LOW or SPEEDSTEP_HIGH) | ||
86 | * | ||
87 | * Tries to change the SpeedStep state. Can be called from | ||
88 | * smp_call_function_single. | ||
89 | */ | ||
90 | static void speedstep_set_state(unsigned int state) | ||
91 | { | ||
92 | u8 pm2_blk; | ||
93 | u8 value; | ||
94 | unsigned long flags; | ||
95 | |||
96 | if (state > 0x1) | ||
97 | return; | ||
98 | |||
99 | /* Disable IRQs */ | ||
100 | local_irq_save(flags); | ||
101 | |||
102 | /* read state */ | ||
103 | value = inb(pmbase + 0x50); | ||
104 | |||
105 | pr_debug("read at pmbase 0x%x + 0x50 returned 0x%x\n", pmbase, value); | ||
106 | |||
107 | /* write new state */ | ||
108 | value &= 0xFE; | ||
109 | value |= state; | ||
110 | |||
111 | pr_debug("writing 0x%x to pmbase 0x%x + 0x50\n", value, pmbase); | ||
112 | |||
113 | /* Disable bus master arbitration */ | ||
114 | pm2_blk = inb(pmbase + 0x20); | ||
115 | pm2_blk |= 0x01; | ||
116 | outb(pm2_blk, (pmbase + 0x20)); | ||
117 | |||
118 | /* Actual transition */ | ||
119 | outb(value, (pmbase + 0x50)); | ||
120 | |||
121 | /* Restore bus master arbitration */ | ||
122 | pm2_blk &= 0xfe; | ||
123 | outb(pm2_blk, (pmbase + 0x20)); | ||
124 | |||
125 | /* check if transition was successful */ | ||
126 | value = inb(pmbase + 0x50); | ||
127 | |||
128 | /* Enable IRQs */ | ||
129 | local_irq_restore(flags); | ||
130 | |||
131 | pr_debug("read at pmbase 0x%x + 0x50 returned 0x%x\n", pmbase, value); | ||
132 | |||
133 | if (state == (value & 0x1)) | ||
134 | pr_debug("change to %u MHz succeeded\n", | ||
135 | speedstep_get_frequency(speedstep_processor) / 1000); | ||
136 | else | ||
137 | printk(KERN_ERR "cpufreq: change failed - I/O error\n"); | ||
138 | |||
139 | return; | ||
140 | } | ||
141 | |||
142 | /* Wrapper for smp_call_function_single. */ | ||
143 | static void _speedstep_set_state(void *_state) | ||
144 | { | ||
145 | speedstep_set_state(*(unsigned int *)_state); | ||
146 | } | ||
147 | |||
148 | /** | ||
149 | * speedstep_activate - activate SpeedStep control in the chipset | ||
150 | * | ||
151 | * Tries to activate the SpeedStep status and control registers. | ||
152 | * Returns -EINVAL on an unsupported chipset, and zero on success. | ||
153 | */ | ||
154 | static int speedstep_activate(void) | ||
155 | { | ||
156 | u16 value = 0; | ||
157 | |||
158 | if (!speedstep_chipset_dev) | ||
159 | return -EINVAL; | ||
160 | |||
161 | pci_read_config_word(speedstep_chipset_dev, 0x00A0, &value); | ||
162 | if (!(value & 0x08)) { | ||
163 | value |= 0x08; | ||
164 | pr_debug("activating SpeedStep (TM) registers\n"); | ||
165 | pci_write_config_word(speedstep_chipset_dev, 0x00A0, value); | ||
166 | } | ||
167 | |||
168 | return 0; | ||
169 | } | ||
170 | |||
171 | |||
172 | /** | ||
173 | * speedstep_detect_chipset - detect the Southbridge which contains SpeedStep logic | ||
174 | * | ||
175 | * Detects ICH2-M, ICH3-M and ICH4-M so far. The pci_dev points to | ||
176 | * the LPC bridge / PM module which contains all power-management | ||
177 | * functions. Returns the SPEEDSTEP_CHIPSET_-number for the detected | ||
178 | * chipset, or zero on failure. | ||
179 | */ | ||
180 | static unsigned int speedstep_detect_chipset(void) | ||
181 | { | ||
182 | speedstep_chipset_dev = pci_get_subsys(PCI_VENDOR_ID_INTEL, | ||
183 | PCI_DEVICE_ID_INTEL_82801DB_12, | ||
184 | PCI_ANY_ID, PCI_ANY_ID, | ||
185 | NULL); | ||
186 | if (speedstep_chipset_dev) | ||
187 | return 4; /* 4-M */ | ||
188 | |||
189 | speedstep_chipset_dev = pci_get_subsys(PCI_VENDOR_ID_INTEL, | ||
190 | PCI_DEVICE_ID_INTEL_82801CA_12, | ||
191 | PCI_ANY_ID, PCI_ANY_ID, | ||
192 | NULL); | ||
193 | if (speedstep_chipset_dev) | ||
194 | return 3; /* 3-M */ | ||
195 | |||
196 | |||
197 | speedstep_chipset_dev = pci_get_subsys(PCI_VENDOR_ID_INTEL, | ||
198 | PCI_DEVICE_ID_INTEL_82801BA_10, | ||
199 | PCI_ANY_ID, PCI_ANY_ID, | ||
200 | NULL); | ||
201 | if (speedstep_chipset_dev) { | ||
202 | /* speedstep.c causes lockups on Dell Inspirons 8000 and | ||
203 | * 8100 which use a pretty old revision of the 82815 | ||
204 | * host brige. Abort on these systems. | ||
205 | */ | ||
206 | static struct pci_dev *hostbridge; | ||
207 | |||
208 | hostbridge = pci_get_subsys(PCI_VENDOR_ID_INTEL, | ||
209 | PCI_DEVICE_ID_INTEL_82815_MC, | ||
210 | PCI_ANY_ID, PCI_ANY_ID, | ||
211 | NULL); | ||
212 | |||
213 | if (!hostbridge) | ||
214 | return 2; /* 2-M */ | ||
215 | |||
216 | if (hostbridge->revision < 5) { | ||
217 | pr_debug("hostbridge does not support speedstep\n"); | ||
218 | speedstep_chipset_dev = NULL; | ||
219 | pci_dev_put(hostbridge); | ||
220 | return 0; | ||
221 | } | ||
222 | |||
223 | pci_dev_put(hostbridge); | ||
224 | return 2; /* 2-M */ | ||
225 | } | ||
226 | |||
227 | return 0; | ||
228 | } | ||
229 | |||
230 | static void get_freq_data(void *_speed) | ||
231 | { | ||
232 | unsigned int *speed = _speed; | ||
233 | |||
234 | *speed = speedstep_get_frequency(speedstep_processor); | ||
235 | } | ||
236 | |||
237 | static unsigned int speedstep_get(unsigned int cpu) | ||
238 | { | ||
239 | unsigned int speed; | ||
240 | |||
241 | /* You're supposed to ensure CPU is online. */ | ||
242 | if (smp_call_function_single(cpu, get_freq_data, &speed, 1) != 0) | ||
243 | BUG(); | ||
244 | |||
245 | pr_debug("detected %u kHz as current frequency\n", speed); | ||
246 | return speed; | ||
247 | } | ||
248 | |||
249 | /** | ||
250 | * speedstep_target - set a new CPUFreq policy | ||
251 | * @policy: new policy | ||
252 | * @target_freq: the target frequency | ||
253 | * @relation: how that frequency relates to achieved frequency | ||
254 | * (CPUFREQ_RELATION_L or CPUFREQ_RELATION_H) | ||
255 | * | ||
256 | * Sets a new CPUFreq policy. | ||
257 | */ | ||
258 | static int speedstep_target(struct cpufreq_policy *policy, | ||
259 | unsigned int target_freq, | ||
260 | unsigned int relation) | ||
261 | { | ||
262 | unsigned int newstate = 0, policy_cpu; | ||
263 | struct cpufreq_freqs freqs; | ||
264 | int i; | ||
265 | |||
266 | if (cpufreq_frequency_table_target(policy, &speedstep_freqs[0], | ||
267 | target_freq, relation, &newstate)) | ||
268 | return -EINVAL; | ||
269 | |||
270 | policy_cpu = cpumask_any_and(policy->cpus, cpu_online_mask); | ||
271 | freqs.old = speedstep_get(policy_cpu); | ||
272 | freqs.new = speedstep_freqs[newstate].frequency; | ||
273 | freqs.cpu = policy->cpu; | ||
274 | |||
275 | pr_debug("transiting from %u to %u kHz\n", freqs.old, freqs.new); | ||
276 | |||
277 | /* no transition necessary */ | ||
278 | if (freqs.old == freqs.new) | ||
279 | return 0; | ||
280 | |||
281 | for_each_cpu(i, policy->cpus) { | ||
282 | freqs.cpu = i; | ||
283 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
284 | } | ||
285 | |||
286 | smp_call_function_single(policy_cpu, _speedstep_set_state, &newstate, | ||
287 | true); | ||
288 | |||
289 | for_each_cpu(i, policy->cpus) { | ||
290 | freqs.cpu = i; | ||
291 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
292 | } | ||
293 | |||
294 | return 0; | ||
295 | } | ||
296 | |||
297 | |||
298 | /** | ||
299 | * speedstep_verify - verifies a new CPUFreq policy | ||
300 | * @policy: new policy | ||
301 | * | ||
302 | * Limit must be within speedstep_low_freq and speedstep_high_freq, with | ||
303 | * at least one border included. | ||
304 | */ | ||
305 | static int speedstep_verify(struct cpufreq_policy *policy) | ||
306 | { | ||
307 | return cpufreq_frequency_table_verify(policy, &speedstep_freqs[0]); | ||
308 | } | ||
309 | |||
310 | struct get_freqs { | ||
311 | struct cpufreq_policy *policy; | ||
312 | int ret; | ||
313 | }; | ||
314 | |||
315 | static void get_freqs_on_cpu(void *_get_freqs) | ||
316 | { | ||
317 | struct get_freqs *get_freqs = _get_freqs; | ||
318 | |||
319 | get_freqs->ret = | ||
320 | speedstep_get_freqs(speedstep_processor, | ||
321 | &speedstep_freqs[SPEEDSTEP_LOW].frequency, | ||
322 | &speedstep_freqs[SPEEDSTEP_HIGH].frequency, | ||
323 | &get_freqs->policy->cpuinfo.transition_latency, | ||
324 | &speedstep_set_state); | ||
325 | } | ||
326 | |||
327 | static int speedstep_cpu_init(struct cpufreq_policy *policy) | ||
328 | { | ||
329 | int result; | ||
330 | unsigned int policy_cpu, speed; | ||
331 | struct get_freqs gf; | ||
332 | |||
333 | /* only run on CPU to be set, or on its sibling */ | ||
334 | #ifdef CONFIG_SMP | ||
335 | cpumask_copy(policy->cpus, cpu_sibling_mask(policy->cpu)); | ||
336 | #endif | ||
337 | policy_cpu = cpumask_any_and(policy->cpus, cpu_online_mask); | ||
338 | |||
339 | /* detect low and high frequency and transition latency */ | ||
340 | gf.policy = policy; | ||
341 | smp_call_function_single(policy_cpu, get_freqs_on_cpu, &gf, 1); | ||
342 | if (gf.ret) | ||
343 | return gf.ret; | ||
344 | |||
345 | /* get current speed setting */ | ||
346 | speed = speedstep_get(policy_cpu); | ||
347 | if (!speed) | ||
348 | return -EIO; | ||
349 | |||
350 | pr_debug("currently at %s speed setting - %i MHz\n", | ||
351 | (speed == speedstep_freqs[SPEEDSTEP_LOW].frequency) | ||
352 | ? "low" : "high", | ||
353 | (speed / 1000)); | ||
354 | |||
355 | /* cpuinfo and default policy values */ | ||
356 | policy->cur = speed; | ||
357 | |||
358 | result = cpufreq_frequency_table_cpuinfo(policy, speedstep_freqs); | ||
359 | if (result) | ||
360 | return result; | ||
361 | |||
362 | cpufreq_frequency_table_get_attr(speedstep_freqs, policy->cpu); | ||
363 | |||
364 | return 0; | ||
365 | } | ||
366 | |||
367 | |||
368 | static int speedstep_cpu_exit(struct cpufreq_policy *policy) | ||
369 | { | ||
370 | cpufreq_frequency_table_put_attr(policy->cpu); | ||
371 | return 0; | ||
372 | } | ||
373 | |||
374 | static struct freq_attr *speedstep_attr[] = { | ||
375 | &cpufreq_freq_attr_scaling_available_freqs, | ||
376 | NULL, | ||
377 | }; | ||
378 | |||
379 | |||
380 | static struct cpufreq_driver speedstep_driver = { | ||
381 | .name = "speedstep-ich", | ||
382 | .verify = speedstep_verify, | ||
383 | .target = speedstep_target, | ||
384 | .init = speedstep_cpu_init, | ||
385 | .exit = speedstep_cpu_exit, | ||
386 | .get = speedstep_get, | ||
387 | .owner = THIS_MODULE, | ||
388 | .attr = speedstep_attr, | ||
389 | }; | ||
390 | |||
391 | |||
392 | /** | ||
393 | * speedstep_init - initializes the SpeedStep CPUFreq driver | ||
394 | * | ||
395 | * Initializes the SpeedStep support. Returns -ENODEV on unsupported | ||
396 | * devices, -EINVAL on problems during initiatization, and zero on | ||
397 | * success. | ||
398 | */ | ||
399 | static int __init speedstep_init(void) | ||
400 | { | ||
401 | /* detect processor */ | ||
402 | speedstep_processor = speedstep_detect_processor(); | ||
403 | if (!speedstep_processor) { | ||
404 | pr_debug("Intel(R) SpeedStep(TM) capable processor " | ||
405 | "not found\n"); | ||
406 | return -ENODEV; | ||
407 | } | ||
408 | |||
409 | /* detect chipset */ | ||
410 | if (!speedstep_detect_chipset()) { | ||
411 | pr_debug("Intel(R) SpeedStep(TM) for this chipset not " | ||
412 | "(yet) available.\n"); | ||
413 | return -ENODEV; | ||
414 | } | ||
415 | |||
416 | /* activate speedstep support */ | ||
417 | if (speedstep_activate()) { | ||
418 | pci_dev_put(speedstep_chipset_dev); | ||
419 | return -EINVAL; | ||
420 | } | ||
421 | |||
422 | if (speedstep_find_register()) | ||
423 | return -ENODEV; | ||
424 | |||
425 | return cpufreq_register_driver(&speedstep_driver); | ||
426 | } | ||
427 | |||
428 | |||
429 | /** | ||
430 | * speedstep_exit - unregisters SpeedStep support | ||
431 | * | ||
432 | * Unregisters SpeedStep support. | ||
433 | */ | ||
434 | static void __exit speedstep_exit(void) | ||
435 | { | ||
436 | pci_dev_put(speedstep_chipset_dev); | ||
437 | cpufreq_unregister_driver(&speedstep_driver); | ||
438 | } | ||
439 | |||
440 | |||
441 | MODULE_AUTHOR("Dave Jones <davej@redhat.com>, " | ||
442 | "Dominik Brodowski <linux@brodo.de>"); | ||
443 | MODULE_DESCRIPTION("Speedstep driver for Intel mobile processors on chipsets " | ||
444 | "with ICH-M southbridges."); | ||
445 | MODULE_LICENSE("GPL"); | ||
446 | |||
447 | module_init(speedstep_init); | ||
448 | module_exit(speedstep_exit); | ||
diff --git a/drivers/cpufreq/speedstep-lib.c b/drivers/cpufreq/speedstep-lib.c new file mode 100644 index 000000000000..8af2d2fd9d51 --- /dev/null +++ b/drivers/cpufreq/speedstep-lib.c | |||
@@ -0,0 +1,478 @@ | |||
1 | /* | ||
2 | * (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de> | ||
3 | * | ||
4 | * Licensed under the terms of the GNU GPL License version 2. | ||
5 | * | ||
6 | * Library for common functions for Intel SpeedStep v.1 and v.2 support | ||
7 | * | ||
8 | * BIG FAT DISCLAIMER: Work in progress code. Possibly *dangerous* | ||
9 | */ | ||
10 | |||
11 | #include <linux/kernel.h> | ||
12 | #include <linux/module.h> | ||
13 | #include <linux/moduleparam.h> | ||
14 | #include <linux/init.h> | ||
15 | #include <linux/cpufreq.h> | ||
16 | |||
17 | #include <asm/msr.h> | ||
18 | #include <asm/tsc.h> | ||
19 | #include "speedstep-lib.h" | ||
20 | |||
21 | #define PFX "speedstep-lib: " | ||
22 | |||
23 | #ifdef CONFIG_X86_SPEEDSTEP_RELAXED_CAP_CHECK | ||
24 | static int relaxed_check; | ||
25 | #else | ||
26 | #define relaxed_check 0 | ||
27 | #endif | ||
28 | |||
29 | /********************************************************************* | ||
30 | * GET PROCESSOR CORE SPEED IN KHZ * | ||
31 | *********************************************************************/ | ||
32 | |||
33 | static unsigned int pentium3_get_frequency(enum speedstep_processor processor) | ||
34 | { | ||
35 | /* See table 14 of p3_ds.pdf and table 22 of 29834003.pdf */ | ||
36 | struct { | ||
37 | unsigned int ratio; /* Frequency Multiplier (x10) */ | ||
38 | u8 bitmap; /* power on configuration bits | ||
39 | [27, 25:22] (in MSR 0x2a) */ | ||
40 | } msr_decode_mult[] = { | ||
41 | { 30, 0x01 }, | ||
42 | { 35, 0x05 }, | ||
43 | { 40, 0x02 }, | ||
44 | { 45, 0x06 }, | ||
45 | { 50, 0x00 }, | ||
46 | { 55, 0x04 }, | ||
47 | { 60, 0x0b }, | ||
48 | { 65, 0x0f }, | ||
49 | { 70, 0x09 }, | ||
50 | { 75, 0x0d }, | ||
51 | { 80, 0x0a }, | ||
52 | { 85, 0x26 }, | ||
53 | { 90, 0x20 }, | ||
54 | { 100, 0x2b }, | ||
55 | { 0, 0xff } /* error or unknown value */ | ||
56 | }; | ||
57 | |||
58 | /* PIII(-M) FSB settings: see table b1-b of 24547206.pdf */ | ||
59 | struct { | ||
60 | unsigned int value; /* Front Side Bus speed in MHz */ | ||
61 | u8 bitmap; /* power on configuration bits [18: 19] | ||
62 | (in MSR 0x2a) */ | ||
63 | } msr_decode_fsb[] = { | ||
64 | { 66, 0x0 }, | ||
65 | { 100, 0x2 }, | ||
66 | { 133, 0x1 }, | ||
67 | { 0, 0xff} | ||
68 | }; | ||
69 | |||
70 | u32 msr_lo, msr_tmp; | ||
71 | int i = 0, j = 0; | ||
72 | |||
73 | /* read MSR 0x2a - we only need the low 32 bits */ | ||
74 | rdmsr(MSR_IA32_EBL_CR_POWERON, msr_lo, msr_tmp); | ||
75 | pr_debug("P3 - MSR_IA32_EBL_CR_POWERON: 0x%x 0x%x\n", msr_lo, msr_tmp); | ||
76 | msr_tmp = msr_lo; | ||
77 | |||
78 | /* decode the FSB */ | ||
79 | msr_tmp &= 0x00c0000; | ||
80 | msr_tmp >>= 18; | ||
81 | while (msr_tmp != msr_decode_fsb[i].bitmap) { | ||
82 | if (msr_decode_fsb[i].bitmap == 0xff) | ||
83 | return 0; | ||
84 | i++; | ||
85 | } | ||
86 | |||
87 | /* decode the multiplier */ | ||
88 | if (processor == SPEEDSTEP_CPU_PIII_C_EARLY) { | ||
89 | pr_debug("workaround for early PIIIs\n"); | ||
90 | msr_lo &= 0x03c00000; | ||
91 | } else | ||
92 | msr_lo &= 0x0bc00000; | ||
93 | msr_lo >>= 22; | ||
94 | while (msr_lo != msr_decode_mult[j].bitmap) { | ||
95 | if (msr_decode_mult[j].bitmap == 0xff) | ||
96 | return 0; | ||
97 | j++; | ||
98 | } | ||
99 | |||
100 | pr_debug("speed is %u\n", | ||
101 | (msr_decode_mult[j].ratio * msr_decode_fsb[i].value * 100)); | ||
102 | |||
103 | return msr_decode_mult[j].ratio * msr_decode_fsb[i].value * 100; | ||
104 | } | ||
105 | |||
106 | |||
107 | static unsigned int pentiumM_get_frequency(void) | ||
108 | { | ||
109 | u32 msr_lo, msr_tmp; | ||
110 | |||
111 | rdmsr(MSR_IA32_EBL_CR_POWERON, msr_lo, msr_tmp); | ||
112 | pr_debug("PM - MSR_IA32_EBL_CR_POWERON: 0x%x 0x%x\n", msr_lo, msr_tmp); | ||
113 | |||
114 | /* see table B-2 of 24547212.pdf */ | ||
115 | if (msr_lo & 0x00040000) { | ||
116 | printk(KERN_DEBUG PFX "PM - invalid FSB: 0x%x 0x%x\n", | ||
117 | msr_lo, msr_tmp); | ||
118 | return 0; | ||
119 | } | ||
120 | |||
121 | msr_tmp = (msr_lo >> 22) & 0x1f; | ||
122 | pr_debug("bits 22-26 are 0x%x, speed is %u\n", | ||
123 | msr_tmp, (msr_tmp * 100 * 1000)); | ||
124 | |||
125 | return msr_tmp * 100 * 1000; | ||
126 | } | ||
127 | |||
128 | static unsigned int pentium_core_get_frequency(void) | ||
129 | { | ||
130 | u32 fsb = 0; | ||
131 | u32 msr_lo, msr_tmp; | ||
132 | int ret; | ||
133 | |||
134 | rdmsr(MSR_FSB_FREQ, msr_lo, msr_tmp); | ||
135 | /* see table B-2 of 25366920.pdf */ | ||
136 | switch (msr_lo & 0x07) { | ||
137 | case 5: | ||
138 | fsb = 100000; | ||
139 | break; | ||
140 | case 1: | ||
141 | fsb = 133333; | ||
142 | break; | ||
143 | case 3: | ||
144 | fsb = 166667; | ||
145 | break; | ||
146 | case 2: | ||
147 | fsb = 200000; | ||
148 | break; | ||
149 | case 0: | ||
150 | fsb = 266667; | ||
151 | break; | ||
152 | case 4: | ||
153 | fsb = 333333; | ||
154 | break; | ||
155 | default: | ||
156 | printk(KERN_ERR "PCORE - MSR_FSB_FREQ undefined value"); | ||
157 | } | ||
158 | |||
159 | rdmsr(MSR_IA32_EBL_CR_POWERON, msr_lo, msr_tmp); | ||
160 | pr_debug("PCORE - MSR_IA32_EBL_CR_POWERON: 0x%x 0x%x\n", | ||
161 | msr_lo, msr_tmp); | ||
162 | |||
163 | msr_tmp = (msr_lo >> 22) & 0x1f; | ||
164 | pr_debug("bits 22-26 are 0x%x, speed is %u\n", | ||
165 | msr_tmp, (msr_tmp * fsb)); | ||
166 | |||
167 | ret = (msr_tmp * fsb); | ||
168 | return ret; | ||
169 | } | ||
170 | |||
171 | |||
172 | static unsigned int pentium4_get_frequency(void) | ||
173 | { | ||
174 | struct cpuinfo_x86 *c = &boot_cpu_data; | ||
175 | u32 msr_lo, msr_hi, mult; | ||
176 | unsigned int fsb = 0; | ||
177 | unsigned int ret; | ||
178 | u8 fsb_code; | ||
179 | |||
180 | /* Pentium 4 Model 0 and 1 do not have the Core Clock Frequency | ||
181 | * to System Bus Frequency Ratio Field in the Processor Frequency | ||
182 | * Configuration Register of the MSR. Therefore the current | ||
183 | * frequency cannot be calculated and has to be measured. | ||
184 | */ | ||
185 | if (c->x86_model < 2) | ||
186 | return cpu_khz; | ||
187 | |||
188 | rdmsr(0x2c, msr_lo, msr_hi); | ||
189 | |||
190 | pr_debug("P4 - MSR_EBC_FREQUENCY_ID: 0x%x 0x%x\n", msr_lo, msr_hi); | ||
191 | |||
192 | /* decode the FSB: see IA-32 Intel (C) Architecture Software | ||
193 | * Developer's Manual, Volume 3: System Prgramming Guide, | ||
194 | * revision #12 in Table B-1: MSRs in the Pentium 4 and | ||
195 | * Intel Xeon Processors, on page B-4 and B-5. | ||
196 | */ | ||
197 | fsb_code = (msr_lo >> 16) & 0x7; | ||
198 | switch (fsb_code) { | ||
199 | case 0: | ||
200 | fsb = 100 * 1000; | ||
201 | break; | ||
202 | case 1: | ||
203 | fsb = 13333 * 10; | ||
204 | break; | ||
205 | case 2: | ||
206 | fsb = 200 * 1000; | ||
207 | break; | ||
208 | } | ||
209 | |||
210 | if (!fsb) | ||
211 | printk(KERN_DEBUG PFX "couldn't detect FSB speed. " | ||
212 | "Please send an e-mail to <linux@brodo.de>\n"); | ||
213 | |||
214 | /* Multiplier. */ | ||
215 | mult = msr_lo >> 24; | ||
216 | |||
217 | pr_debug("P4 - FSB %u kHz; Multiplier %u; Speed %u kHz\n", | ||
218 | fsb, mult, (fsb * mult)); | ||
219 | |||
220 | ret = (fsb * mult); | ||
221 | return ret; | ||
222 | } | ||
223 | |||
224 | |||
225 | /* Warning: may get called from smp_call_function_single. */ | ||
226 | unsigned int speedstep_get_frequency(enum speedstep_processor processor) | ||
227 | { | ||
228 | switch (processor) { | ||
229 | case SPEEDSTEP_CPU_PCORE: | ||
230 | return pentium_core_get_frequency(); | ||
231 | case SPEEDSTEP_CPU_PM: | ||
232 | return pentiumM_get_frequency(); | ||
233 | case SPEEDSTEP_CPU_P4D: | ||
234 | case SPEEDSTEP_CPU_P4M: | ||
235 | return pentium4_get_frequency(); | ||
236 | case SPEEDSTEP_CPU_PIII_T: | ||
237 | case SPEEDSTEP_CPU_PIII_C: | ||
238 | case SPEEDSTEP_CPU_PIII_C_EARLY: | ||
239 | return pentium3_get_frequency(processor); | ||
240 | default: | ||
241 | return 0; | ||
242 | }; | ||
243 | return 0; | ||
244 | } | ||
245 | EXPORT_SYMBOL_GPL(speedstep_get_frequency); | ||
246 | |||
247 | |||
248 | /********************************************************************* | ||
249 | * DETECT SPEEDSTEP-CAPABLE PROCESSOR * | ||
250 | *********************************************************************/ | ||
251 | |||
252 | unsigned int speedstep_detect_processor(void) | ||
253 | { | ||
254 | struct cpuinfo_x86 *c = &cpu_data(0); | ||
255 | u32 ebx, msr_lo, msr_hi; | ||
256 | |||
257 | pr_debug("x86: %x, model: %x\n", c->x86, c->x86_model); | ||
258 | |||
259 | if ((c->x86_vendor != X86_VENDOR_INTEL) || | ||
260 | ((c->x86 != 6) && (c->x86 != 0xF))) | ||
261 | return 0; | ||
262 | |||
263 | if (c->x86 == 0xF) { | ||
264 | /* Intel Mobile Pentium 4-M | ||
265 | * or Intel Mobile Pentium 4 with 533 MHz FSB */ | ||
266 | if (c->x86_model != 2) | ||
267 | return 0; | ||
268 | |||
269 | ebx = cpuid_ebx(0x00000001); | ||
270 | ebx &= 0x000000FF; | ||
271 | |||
272 | pr_debug("ebx value is %x, x86_mask is %x\n", ebx, c->x86_mask); | ||
273 | |||
274 | switch (c->x86_mask) { | ||
275 | case 4: | ||
276 | /* | ||
277 | * B-stepping [M-P4-M] | ||
278 | * sample has ebx = 0x0f, production has 0x0e. | ||
279 | */ | ||
280 | if ((ebx == 0x0e) || (ebx == 0x0f)) | ||
281 | return SPEEDSTEP_CPU_P4M; | ||
282 | break; | ||
283 | case 7: | ||
284 | /* | ||
285 | * C-stepping [M-P4-M] | ||
286 | * needs to have ebx=0x0e, else it's a celeron: | ||
287 | * cf. 25130917.pdf / page 7, footnote 5 even | ||
288 | * though 25072120.pdf / page 7 doesn't say | ||
289 | * samples are only of B-stepping... | ||
290 | */ | ||
291 | if (ebx == 0x0e) | ||
292 | return SPEEDSTEP_CPU_P4M; | ||
293 | break; | ||
294 | case 9: | ||
295 | /* | ||
296 | * D-stepping [M-P4-M or M-P4/533] | ||
297 | * | ||
298 | * this is totally strange: CPUID 0x0F29 is | ||
299 | * used by M-P4-M, M-P4/533 and(!) Celeron CPUs. | ||
300 | * The latter need to be sorted out as they don't | ||
301 | * support speedstep. | ||
302 | * Celerons with CPUID 0x0F29 may have either | ||
303 | * ebx=0x8 or 0xf -- 25130917.pdf doesn't say anything | ||
304 | * specific. | ||
305 | * M-P4-Ms may have either ebx=0xe or 0xf [see above] | ||
306 | * M-P4/533 have either ebx=0xe or 0xf. [25317607.pdf] | ||
307 | * also, M-P4M HTs have ebx=0x8, too | ||
308 | * For now, they are distinguished by the model_id | ||
309 | * string | ||
310 | */ | ||
311 | if ((ebx == 0x0e) || | ||
312 | (strstr(c->x86_model_id, | ||
313 | "Mobile Intel(R) Pentium(R) 4") != NULL)) | ||
314 | return SPEEDSTEP_CPU_P4M; | ||
315 | break; | ||
316 | default: | ||
317 | break; | ||
318 | } | ||
319 | return 0; | ||
320 | } | ||
321 | |||
322 | switch (c->x86_model) { | ||
323 | case 0x0B: /* Intel PIII [Tualatin] */ | ||
324 | /* cpuid_ebx(1) is 0x04 for desktop PIII, | ||
325 | * 0x06 for mobile PIII-M */ | ||
326 | ebx = cpuid_ebx(0x00000001); | ||
327 | pr_debug("ebx is %x\n", ebx); | ||
328 | |||
329 | ebx &= 0x000000FF; | ||
330 | |||
331 | if (ebx != 0x06) | ||
332 | return 0; | ||
333 | |||
334 | /* So far all PIII-M processors support SpeedStep. See | ||
335 | * Intel's 24540640.pdf of June 2003 | ||
336 | */ | ||
337 | return SPEEDSTEP_CPU_PIII_T; | ||
338 | |||
339 | case 0x08: /* Intel PIII [Coppermine] */ | ||
340 | |||
341 | /* all mobile PIII Coppermines have FSB 100 MHz | ||
342 | * ==> sort out a few desktop PIIIs. */ | ||
343 | rdmsr(MSR_IA32_EBL_CR_POWERON, msr_lo, msr_hi); | ||
344 | pr_debug("Coppermine: MSR_IA32_EBL_CR_POWERON is 0x%x, 0x%x\n", | ||
345 | msr_lo, msr_hi); | ||
346 | msr_lo &= 0x00c0000; | ||
347 | if (msr_lo != 0x0080000) | ||
348 | return 0; | ||
349 | |||
350 | /* | ||
351 | * If the processor is a mobile version, | ||
352 | * platform ID has bit 50 set | ||
353 | * it has SpeedStep technology if either | ||
354 | * bit 56 or 57 is set | ||
355 | */ | ||
356 | rdmsr(MSR_IA32_PLATFORM_ID, msr_lo, msr_hi); | ||
357 | pr_debug("Coppermine: MSR_IA32_PLATFORM ID is 0x%x, 0x%x\n", | ||
358 | msr_lo, msr_hi); | ||
359 | if ((msr_hi & (1<<18)) && | ||
360 | (relaxed_check ? 1 : (msr_hi & (3<<24)))) { | ||
361 | if (c->x86_mask == 0x01) { | ||
362 | pr_debug("early PIII version\n"); | ||
363 | return SPEEDSTEP_CPU_PIII_C_EARLY; | ||
364 | } else | ||
365 | return SPEEDSTEP_CPU_PIII_C; | ||
366 | } | ||
367 | |||
368 | default: | ||
369 | return 0; | ||
370 | } | ||
371 | } | ||
372 | EXPORT_SYMBOL_GPL(speedstep_detect_processor); | ||
373 | |||
374 | |||
375 | /********************************************************************* | ||
376 | * DETECT SPEEDSTEP SPEEDS * | ||
377 | *********************************************************************/ | ||
378 | |||
379 | unsigned int speedstep_get_freqs(enum speedstep_processor processor, | ||
380 | unsigned int *low_speed, | ||
381 | unsigned int *high_speed, | ||
382 | unsigned int *transition_latency, | ||
383 | void (*set_state) (unsigned int state)) | ||
384 | { | ||
385 | unsigned int prev_speed; | ||
386 | unsigned int ret = 0; | ||
387 | unsigned long flags; | ||
388 | struct timeval tv1, tv2; | ||
389 | |||
390 | if ((!processor) || (!low_speed) || (!high_speed) || (!set_state)) | ||
391 | return -EINVAL; | ||
392 | |||
393 | pr_debug("trying to determine both speeds\n"); | ||
394 | |||
395 | /* get current speed */ | ||
396 | prev_speed = speedstep_get_frequency(processor); | ||
397 | if (!prev_speed) | ||
398 | return -EIO; | ||
399 | |||
400 | pr_debug("previous speed is %u\n", prev_speed); | ||
401 | |||
402 | local_irq_save(flags); | ||
403 | |||
404 | /* switch to low state */ | ||
405 | set_state(SPEEDSTEP_LOW); | ||
406 | *low_speed = speedstep_get_frequency(processor); | ||
407 | if (!*low_speed) { | ||
408 | ret = -EIO; | ||
409 | goto out; | ||
410 | } | ||
411 | |||
412 | pr_debug("low speed is %u\n", *low_speed); | ||
413 | |||
414 | /* start latency measurement */ | ||
415 | if (transition_latency) | ||
416 | do_gettimeofday(&tv1); | ||
417 | |||
418 | /* switch to high state */ | ||
419 | set_state(SPEEDSTEP_HIGH); | ||
420 | |||
421 | /* end latency measurement */ | ||
422 | if (transition_latency) | ||
423 | do_gettimeofday(&tv2); | ||
424 | |||
425 | *high_speed = speedstep_get_frequency(processor); | ||
426 | if (!*high_speed) { | ||
427 | ret = -EIO; | ||
428 | goto out; | ||
429 | } | ||
430 | |||
431 | pr_debug("high speed is %u\n", *high_speed); | ||
432 | |||
433 | if (*low_speed == *high_speed) { | ||
434 | ret = -ENODEV; | ||
435 | goto out; | ||
436 | } | ||
437 | |||
438 | /* switch to previous state, if necessary */ | ||
439 | if (*high_speed != prev_speed) | ||
440 | set_state(SPEEDSTEP_LOW); | ||
441 | |||
442 | if (transition_latency) { | ||
443 | *transition_latency = (tv2.tv_sec - tv1.tv_sec) * USEC_PER_SEC + | ||
444 | tv2.tv_usec - tv1.tv_usec; | ||
445 | pr_debug("transition latency is %u uSec\n", *transition_latency); | ||
446 | |||
447 | /* convert uSec to nSec and add 20% for safety reasons */ | ||
448 | *transition_latency *= 1200; | ||
449 | |||
450 | /* check if the latency measurement is too high or too low | ||
451 | * and set it to a safe value (500uSec) in that case | ||
452 | */ | ||
453 | if (*transition_latency > 10000000 || | ||
454 | *transition_latency < 50000) { | ||
455 | printk(KERN_WARNING PFX "frequency transition " | ||
456 | "measured seems out of range (%u " | ||
457 | "nSec), falling back to a safe one of" | ||
458 | "%u nSec.\n", | ||
459 | *transition_latency, 500000); | ||
460 | *transition_latency = 500000; | ||
461 | } | ||
462 | } | ||
463 | |||
464 | out: | ||
465 | local_irq_restore(flags); | ||
466 | return ret; | ||
467 | } | ||
468 | EXPORT_SYMBOL_GPL(speedstep_get_freqs); | ||
469 | |||
470 | #ifdef CONFIG_X86_SPEEDSTEP_RELAXED_CAP_CHECK | ||
471 | module_param(relaxed_check, int, 0444); | ||
472 | MODULE_PARM_DESC(relaxed_check, | ||
473 | "Don't do all checks for speedstep capability."); | ||
474 | #endif | ||
475 | |||
476 | MODULE_AUTHOR("Dominik Brodowski <linux@brodo.de>"); | ||
477 | MODULE_DESCRIPTION("Library for Intel SpeedStep 1 or 2 cpufreq drivers."); | ||
478 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/cpufreq/speedstep-lib.h b/drivers/cpufreq/speedstep-lib.h new file mode 100644 index 000000000000..70d9cea1219d --- /dev/null +++ b/drivers/cpufreq/speedstep-lib.h | |||
@@ -0,0 +1,49 @@ | |||
1 | /* | ||
2 | * (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de> | ||
3 | * | ||
4 | * Licensed under the terms of the GNU GPL License version 2. | ||
5 | * | ||
6 | * Library for common functions for Intel SpeedStep v.1 and v.2 support | ||
7 | * | ||
8 | * BIG FAT DISCLAIMER: Work in progress code. Possibly *dangerous* | ||
9 | */ | ||
10 | |||
11 | |||
12 | |||
13 | /* processors */ | ||
14 | enum speedstep_processor { | ||
15 | SPEEDSTEP_CPU_PIII_C_EARLY = 0x00000001, /* Coppermine core */ | ||
16 | SPEEDSTEP_CPU_PIII_C = 0x00000002, /* Coppermine core */ | ||
17 | SPEEDSTEP_CPU_PIII_T = 0x00000003, /* Tualatin core */ | ||
18 | SPEEDSTEP_CPU_P4M = 0x00000004, /* P4-M */ | ||
19 | /* the following processors are not speedstep-capable and are not auto-detected | ||
20 | * in speedstep_detect_processor(). However, their speed can be detected using | ||
21 | * the speedstep_get_frequency() call. */ | ||
22 | SPEEDSTEP_CPU_PM = 0xFFFFFF03, /* Pentium M */ | ||
23 | SPEEDSTEP_CPU_P4D = 0xFFFFFF04, /* desktop P4 */ | ||
24 | SPEEDSTEP_CPU_PCORE = 0xFFFFFF05, /* Core */ | ||
25 | }; | ||
26 | |||
27 | /* speedstep states -- only two of them */ | ||
28 | |||
29 | #define SPEEDSTEP_HIGH 0x00000000 | ||
30 | #define SPEEDSTEP_LOW 0x00000001 | ||
31 | |||
32 | |||
33 | /* detect a speedstep-capable processor */ | ||
34 | extern enum speedstep_processor speedstep_detect_processor(void); | ||
35 | |||
36 | /* detect the current speed (in khz) of the processor */ | ||
37 | extern unsigned int speedstep_get_frequency(enum speedstep_processor processor); | ||
38 | |||
39 | |||
40 | /* detect the low and high speeds of the processor. The callback | ||
41 | * set_state"'s first argument is either SPEEDSTEP_HIGH or | ||
42 | * SPEEDSTEP_LOW; the second argument is zero so that no | ||
43 | * cpufreq_notify_transition calls are initiated. | ||
44 | */ | ||
45 | extern unsigned int speedstep_get_freqs(enum speedstep_processor processor, | ||
46 | unsigned int *low_speed, | ||
47 | unsigned int *high_speed, | ||
48 | unsigned int *transition_latency, | ||
49 | void (*set_state) (unsigned int state)); | ||
diff --git a/drivers/cpufreq/speedstep-smi.c b/drivers/cpufreq/speedstep-smi.c new file mode 100644 index 000000000000..c76ead3490bf --- /dev/null +++ b/drivers/cpufreq/speedstep-smi.c | |||
@@ -0,0 +1,464 @@ | |||
1 | /* | ||
2 | * Intel SpeedStep SMI driver. | ||
3 | * | ||
4 | * (C) 2003 Hiroshi Miura <miura@da-cha.org> | ||
5 | * | ||
6 | * Licensed under the terms of the GNU GPL License version 2. | ||
7 | * | ||
8 | */ | ||
9 | |||
10 | |||
11 | /********************************************************************* | ||
12 | * SPEEDSTEP - DEFINITIONS * | ||
13 | *********************************************************************/ | ||
14 | |||
15 | #include <linux/kernel.h> | ||
16 | #include <linux/module.h> | ||
17 | #include <linux/moduleparam.h> | ||
18 | #include <linux/init.h> | ||
19 | #include <linux/cpufreq.h> | ||
20 | #include <linux/delay.h> | ||
21 | #include <linux/io.h> | ||
22 | #include <asm/ist.h> | ||
23 | |||
24 | #include "speedstep-lib.h" | ||
25 | |||
26 | /* speedstep system management interface port/command. | ||
27 | * | ||
28 | * These parameters are got from IST-SMI BIOS call. | ||
29 | * If user gives it, these are used. | ||
30 | * | ||
31 | */ | ||
32 | static int smi_port; | ||
33 | static int smi_cmd; | ||
34 | static unsigned int smi_sig; | ||
35 | |||
36 | /* info about the processor */ | ||
37 | static enum speedstep_processor speedstep_processor; | ||
38 | |||
39 | /* | ||
40 | * There are only two frequency states for each processor. Values | ||
41 | * are in kHz for the time being. | ||
42 | */ | ||
43 | static struct cpufreq_frequency_table speedstep_freqs[] = { | ||
44 | {SPEEDSTEP_HIGH, 0}, | ||
45 | {SPEEDSTEP_LOW, 0}, | ||
46 | {0, CPUFREQ_TABLE_END}, | ||
47 | }; | ||
48 | |||
49 | #define GET_SPEEDSTEP_OWNER 0 | ||
50 | #define GET_SPEEDSTEP_STATE 1 | ||
51 | #define SET_SPEEDSTEP_STATE 2 | ||
52 | #define GET_SPEEDSTEP_FREQS 4 | ||
53 | |||
54 | /* how often shall the SMI call be tried if it failed, e.g. because | ||
55 | * of DMA activity going on? */ | ||
56 | #define SMI_TRIES 5 | ||
57 | |||
58 | /** | ||
59 | * speedstep_smi_ownership | ||
60 | */ | ||
61 | static int speedstep_smi_ownership(void) | ||
62 | { | ||
63 | u32 command, result, magic, dummy; | ||
64 | u32 function = GET_SPEEDSTEP_OWNER; | ||
65 | unsigned char magic_data[] = "Copyright (c) 1999 Intel Corporation"; | ||
66 | |||
67 | command = (smi_sig & 0xffffff00) | (smi_cmd & 0xff); | ||
68 | magic = virt_to_phys(magic_data); | ||
69 | |||
70 | pr_debug("trying to obtain ownership with command %x at port %x\n", | ||
71 | command, smi_port); | ||
72 | |||
73 | __asm__ __volatile__( | ||
74 | "push %%ebp\n" | ||
75 | "out %%al, (%%dx)\n" | ||
76 | "pop %%ebp\n" | ||
77 | : "=D" (result), | ||
78 | "=a" (dummy), "=b" (dummy), "=c" (dummy), "=d" (dummy), | ||
79 | "=S" (dummy) | ||
80 | : "a" (command), "b" (function), "c" (0), "d" (smi_port), | ||
81 | "D" (0), "S" (magic) | ||
82 | : "memory" | ||
83 | ); | ||
84 | |||
85 | pr_debug("result is %x\n", result); | ||
86 | |||
87 | return result; | ||
88 | } | ||
89 | |||
90 | /** | ||
91 | * speedstep_smi_get_freqs - get SpeedStep preferred & current freq. | ||
92 | * @low: the low frequency value is placed here | ||
93 | * @high: the high frequency value is placed here | ||
94 | * | ||
95 | * Only available on later SpeedStep-enabled systems, returns false results or | ||
96 | * even hangs [cf. bugme.osdl.org # 1422] on earlier systems. Empirical testing | ||
97 | * shows that the latter occurs if !(ist_info.event & 0xFFFF). | ||
98 | */ | ||
99 | static int speedstep_smi_get_freqs(unsigned int *low, unsigned int *high) | ||
100 | { | ||
101 | u32 command, result = 0, edi, high_mhz, low_mhz, dummy; | ||
102 | u32 state = 0; | ||
103 | u32 function = GET_SPEEDSTEP_FREQS; | ||
104 | |||
105 | if (!(ist_info.event & 0xFFFF)) { | ||
106 | pr_debug("bug #1422 -- can't read freqs from BIOS\n"); | ||
107 | return -ENODEV; | ||
108 | } | ||
109 | |||
110 | command = (smi_sig & 0xffffff00) | (smi_cmd & 0xff); | ||
111 | |||
112 | pr_debug("trying to determine frequencies with command %x at port %x\n", | ||
113 | command, smi_port); | ||
114 | |||
115 | __asm__ __volatile__( | ||
116 | "push %%ebp\n" | ||
117 | "out %%al, (%%dx)\n" | ||
118 | "pop %%ebp" | ||
119 | : "=a" (result), | ||
120 | "=b" (high_mhz), | ||
121 | "=c" (low_mhz), | ||
122 | "=d" (state), "=D" (edi), "=S" (dummy) | ||
123 | : "a" (command), | ||
124 | "b" (function), | ||
125 | "c" (state), | ||
126 | "d" (smi_port), "S" (0), "D" (0) | ||
127 | ); | ||
128 | |||
129 | pr_debug("result %x, low_freq %u, high_freq %u\n", | ||
130 | result, low_mhz, high_mhz); | ||
131 | |||
132 | /* abort if results are obviously incorrect... */ | ||
133 | if ((high_mhz + low_mhz) < 600) | ||
134 | return -EINVAL; | ||
135 | |||
136 | *high = high_mhz * 1000; | ||
137 | *low = low_mhz * 1000; | ||
138 | |||
139 | return result; | ||
140 | } | ||
141 | |||
142 | /** | ||
143 | * speedstep_get_state - set the SpeedStep state | ||
144 | * @state: processor frequency state (SPEEDSTEP_LOW or SPEEDSTEP_HIGH) | ||
145 | * | ||
146 | */ | ||
147 | static int speedstep_get_state(void) | ||
148 | { | ||
149 | u32 function = GET_SPEEDSTEP_STATE; | ||
150 | u32 result, state, edi, command, dummy; | ||
151 | |||
152 | command = (smi_sig & 0xffffff00) | (smi_cmd & 0xff); | ||
153 | |||
154 | pr_debug("trying to determine current setting with command %x " | ||
155 | "at port %x\n", command, smi_port); | ||
156 | |||
157 | __asm__ __volatile__( | ||
158 | "push %%ebp\n" | ||
159 | "out %%al, (%%dx)\n" | ||
160 | "pop %%ebp\n" | ||
161 | : "=a" (result), | ||
162 | "=b" (state), "=D" (edi), | ||
163 | "=c" (dummy), "=d" (dummy), "=S" (dummy) | ||
164 | : "a" (command), "b" (function), "c" (0), | ||
165 | "d" (smi_port), "S" (0), "D" (0) | ||
166 | ); | ||
167 | |||
168 | pr_debug("state is %x, result is %x\n", state, result); | ||
169 | |||
170 | return state & 1; | ||
171 | } | ||
172 | |||
173 | |||
174 | /** | ||
175 | * speedstep_set_state - set the SpeedStep state | ||
176 | * @state: new processor frequency state (SPEEDSTEP_LOW or SPEEDSTEP_HIGH) | ||
177 | * | ||
178 | */ | ||
179 | static void speedstep_set_state(unsigned int state) | ||
180 | { | ||
181 | unsigned int result = 0, command, new_state, dummy; | ||
182 | unsigned long flags; | ||
183 | unsigned int function = SET_SPEEDSTEP_STATE; | ||
184 | unsigned int retry = 0; | ||
185 | |||
186 | if (state > 0x1) | ||
187 | return; | ||
188 | |||
189 | /* Disable IRQs */ | ||
190 | local_irq_save(flags); | ||
191 | |||
192 | command = (smi_sig & 0xffffff00) | (smi_cmd & 0xff); | ||
193 | |||
194 | pr_debug("trying to set frequency to state %u " | ||
195 | "with command %x at port %x\n", | ||
196 | state, command, smi_port); | ||
197 | |||
198 | do { | ||
199 | if (retry) { | ||
200 | pr_debug("retry %u, previous result %u, waiting...\n", | ||
201 | retry, result); | ||
202 | mdelay(retry * 50); | ||
203 | } | ||
204 | retry++; | ||
205 | __asm__ __volatile__( | ||
206 | "push %%ebp\n" | ||
207 | "out %%al, (%%dx)\n" | ||
208 | "pop %%ebp" | ||
209 | : "=b" (new_state), "=D" (result), | ||
210 | "=c" (dummy), "=a" (dummy), | ||
211 | "=d" (dummy), "=S" (dummy) | ||
212 | : "a" (command), "b" (function), "c" (state), | ||
213 | "d" (smi_port), "S" (0), "D" (0) | ||
214 | ); | ||
215 | } while ((new_state != state) && (retry <= SMI_TRIES)); | ||
216 | |||
217 | /* enable IRQs */ | ||
218 | local_irq_restore(flags); | ||
219 | |||
220 | if (new_state == state) | ||
221 | pr_debug("change to %u MHz succeeded after %u tries " | ||
222 | "with result %u\n", | ||
223 | (speedstep_freqs[new_state].frequency / 1000), | ||
224 | retry, result); | ||
225 | else | ||
226 | printk(KERN_ERR "cpufreq: change to state %u " | ||
227 | "failed with new_state %u and result %u\n", | ||
228 | state, new_state, result); | ||
229 | |||
230 | return; | ||
231 | } | ||
232 | |||
233 | |||
234 | /** | ||
235 | * speedstep_target - set a new CPUFreq policy | ||
236 | * @policy: new policy | ||
237 | * @target_freq: new freq | ||
238 | * @relation: | ||
239 | * | ||
240 | * Sets a new CPUFreq policy/freq. | ||
241 | */ | ||
242 | static int speedstep_target(struct cpufreq_policy *policy, | ||
243 | unsigned int target_freq, unsigned int relation) | ||
244 | { | ||
245 | unsigned int newstate = 0; | ||
246 | struct cpufreq_freqs freqs; | ||
247 | |||
248 | if (cpufreq_frequency_table_target(policy, &speedstep_freqs[0], | ||
249 | target_freq, relation, &newstate)) | ||
250 | return -EINVAL; | ||
251 | |||
252 | freqs.old = speedstep_freqs[speedstep_get_state()].frequency; | ||
253 | freqs.new = speedstep_freqs[newstate].frequency; | ||
254 | freqs.cpu = 0; /* speedstep.c is UP only driver */ | ||
255 | |||
256 | if (freqs.old == freqs.new) | ||
257 | return 0; | ||
258 | |||
259 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | ||
260 | speedstep_set_state(newstate); | ||
261 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | ||
262 | |||
263 | return 0; | ||
264 | } | ||
265 | |||
266 | |||
267 | /** | ||
268 | * speedstep_verify - verifies a new CPUFreq policy | ||
269 | * @policy: new policy | ||
270 | * | ||
271 | * Limit must be within speedstep_low_freq and speedstep_high_freq, with | ||
272 | * at least one border included. | ||
273 | */ | ||
274 | static int speedstep_verify(struct cpufreq_policy *policy) | ||
275 | { | ||
276 | return cpufreq_frequency_table_verify(policy, &speedstep_freqs[0]); | ||
277 | } | ||
278 | |||
279 | |||
280 | static int speedstep_cpu_init(struct cpufreq_policy *policy) | ||
281 | { | ||
282 | int result; | ||
283 | unsigned int speed, state; | ||
284 | unsigned int *low, *high; | ||
285 | |||
286 | /* capability check */ | ||
287 | if (policy->cpu != 0) | ||
288 | return -ENODEV; | ||
289 | |||
290 | result = speedstep_smi_ownership(); | ||
291 | if (result) { | ||
292 | pr_debug("fails in acquiring ownership of a SMI interface.\n"); | ||
293 | return -EINVAL; | ||
294 | } | ||
295 | |||
296 | /* detect low and high frequency */ | ||
297 | low = &speedstep_freqs[SPEEDSTEP_LOW].frequency; | ||
298 | high = &speedstep_freqs[SPEEDSTEP_HIGH].frequency; | ||
299 | |||
300 | result = speedstep_smi_get_freqs(low, high); | ||
301 | if (result) { | ||
302 | /* fall back to speedstep_lib.c dection mechanism: | ||
303 | * try both states out */ | ||
304 | pr_debug("could not detect low and high frequencies " | ||
305 | "by SMI call.\n"); | ||
306 | result = speedstep_get_freqs(speedstep_processor, | ||
307 | low, high, | ||
308 | NULL, | ||
309 | &speedstep_set_state); | ||
310 | |||
311 | if (result) { | ||
312 | pr_debug("could not detect two different speeds" | ||
313 | " -- aborting.\n"); | ||
314 | return result; | ||
315 | } else | ||
316 | pr_debug("workaround worked.\n"); | ||
317 | } | ||
318 | |||
319 | /* get current speed setting */ | ||
320 | state = speedstep_get_state(); | ||
321 | speed = speedstep_freqs[state].frequency; | ||
322 | |||
323 | pr_debug("currently at %s speed setting - %i MHz\n", | ||
324 | (speed == speedstep_freqs[SPEEDSTEP_LOW].frequency) | ||
325 | ? "low" : "high", | ||
326 | (speed / 1000)); | ||
327 | |||
328 | /* cpuinfo and default policy values */ | ||
329 | policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL; | ||
330 | policy->cur = speed; | ||
331 | |||
332 | result = cpufreq_frequency_table_cpuinfo(policy, speedstep_freqs); | ||
333 | if (result) | ||
334 | return result; | ||
335 | |||
336 | cpufreq_frequency_table_get_attr(speedstep_freqs, policy->cpu); | ||
337 | |||
338 | return 0; | ||
339 | } | ||
340 | |||
341 | static int speedstep_cpu_exit(struct cpufreq_policy *policy) | ||
342 | { | ||
343 | cpufreq_frequency_table_put_attr(policy->cpu); | ||
344 | return 0; | ||
345 | } | ||
346 | |||
347 | static unsigned int speedstep_get(unsigned int cpu) | ||
348 | { | ||
349 | if (cpu) | ||
350 | return -ENODEV; | ||
351 | return speedstep_get_frequency(speedstep_processor); | ||
352 | } | ||
353 | |||
354 | |||
355 | static int speedstep_resume(struct cpufreq_policy *policy) | ||
356 | { | ||
357 | int result = speedstep_smi_ownership(); | ||
358 | |||
359 | if (result) | ||
360 | pr_debug("fails in re-acquiring ownership of a SMI interface.\n"); | ||
361 | |||
362 | return result; | ||
363 | } | ||
364 | |||
365 | static struct freq_attr *speedstep_attr[] = { | ||
366 | &cpufreq_freq_attr_scaling_available_freqs, | ||
367 | NULL, | ||
368 | }; | ||
369 | |||
370 | static struct cpufreq_driver speedstep_driver = { | ||
371 | .name = "speedstep-smi", | ||
372 | .verify = speedstep_verify, | ||
373 | .target = speedstep_target, | ||
374 | .init = speedstep_cpu_init, | ||
375 | .exit = speedstep_cpu_exit, | ||
376 | .get = speedstep_get, | ||
377 | .resume = speedstep_resume, | ||
378 | .owner = THIS_MODULE, | ||
379 | .attr = speedstep_attr, | ||
380 | }; | ||
381 | |||
382 | /** | ||
383 | * speedstep_init - initializes the SpeedStep CPUFreq driver | ||
384 | * | ||
385 | * Initializes the SpeedStep support. Returns -ENODEV on unsupported | ||
386 | * BIOS, -EINVAL on problems during initiatization, and zero on | ||
387 | * success. | ||
388 | */ | ||
389 | static int __init speedstep_init(void) | ||
390 | { | ||
391 | speedstep_processor = speedstep_detect_processor(); | ||
392 | |||
393 | switch (speedstep_processor) { | ||
394 | case SPEEDSTEP_CPU_PIII_T: | ||
395 | case SPEEDSTEP_CPU_PIII_C: | ||
396 | case SPEEDSTEP_CPU_PIII_C_EARLY: | ||
397 | break; | ||
398 | default: | ||
399 | speedstep_processor = 0; | ||
400 | } | ||
401 | |||
402 | if (!speedstep_processor) { | ||
403 | pr_debug("No supported Intel CPU detected.\n"); | ||
404 | return -ENODEV; | ||
405 | } | ||
406 | |||
407 | pr_debug("signature:0x%.8ulx, command:0x%.8ulx, " | ||
408 | "event:0x%.8ulx, perf_level:0x%.8ulx.\n", | ||
409 | ist_info.signature, ist_info.command, | ||
410 | ist_info.event, ist_info.perf_level); | ||
411 | |||
412 | /* Error if no IST-SMI BIOS or no PARM | ||
413 | sig= 'ISGE' aka 'Intel Speedstep Gate E' */ | ||
414 | if ((ist_info.signature != 0x47534943) && ( | ||
415 | (smi_port == 0) || (smi_cmd == 0))) | ||
416 | return -ENODEV; | ||
417 | |||
418 | if (smi_sig == 1) | ||
419 | smi_sig = 0x47534943; | ||
420 | else | ||
421 | smi_sig = ist_info.signature; | ||
422 | |||
423 | /* setup smi_port from MODLULE_PARM or BIOS */ | ||
424 | if ((smi_port > 0xff) || (smi_port < 0)) | ||
425 | return -EINVAL; | ||
426 | else if (smi_port == 0) | ||
427 | smi_port = ist_info.command & 0xff; | ||
428 | |||
429 | if ((smi_cmd > 0xff) || (smi_cmd < 0)) | ||
430 | return -EINVAL; | ||
431 | else if (smi_cmd == 0) | ||
432 | smi_cmd = (ist_info.command >> 16) & 0xff; | ||
433 | |||
434 | return cpufreq_register_driver(&speedstep_driver); | ||
435 | } | ||
436 | |||
437 | |||
438 | /** | ||
439 | * speedstep_exit - unregisters SpeedStep support | ||
440 | * | ||
441 | * Unregisters SpeedStep support. | ||
442 | */ | ||
443 | static void __exit speedstep_exit(void) | ||
444 | { | ||
445 | cpufreq_unregister_driver(&speedstep_driver); | ||
446 | } | ||
447 | |||
448 | module_param(smi_port, int, 0444); | ||
449 | module_param(smi_cmd, int, 0444); | ||
450 | module_param(smi_sig, uint, 0444); | ||
451 | |||
452 | MODULE_PARM_DESC(smi_port, "Override the BIOS-given IST port with this value " | ||
453 | "-- Intel's default setting is 0xb2"); | ||
454 | MODULE_PARM_DESC(smi_cmd, "Override the BIOS-given IST command with this value " | ||
455 | "-- Intel's default setting is 0x82"); | ||
456 | MODULE_PARM_DESC(smi_sig, "Set to 1 to fake the IST signature when using the " | ||
457 | "SMI interface."); | ||
458 | |||
459 | MODULE_AUTHOR("Hiroshi Miura"); | ||
460 | MODULE_DESCRIPTION("Speedstep driver for IST applet SMI interface."); | ||
461 | MODULE_LICENSE("GPL"); | ||
462 | |||
463 | module_init(speedstep_init); | ||
464 | module_exit(speedstep_exit); | ||
diff --git a/drivers/firmware/Kconfig b/drivers/firmware/Kconfig index b3a25a55ba23..efba163595db 100644 --- a/drivers/firmware/Kconfig +++ b/drivers/firmware/Kconfig | |||
@@ -157,4 +157,6 @@ config SIGMA | |||
157 | If unsure, say N here. Drivers that need these helpers will select | 157 | If unsure, say N here. Drivers that need these helpers will select |
158 | this option automatically. | 158 | this option automatically. |
159 | 159 | ||
160 | source "drivers/firmware/google/Kconfig" | ||
161 | |||
160 | endmenu | 162 | endmenu |
diff --git a/drivers/firmware/Makefile b/drivers/firmware/Makefile index 00bb0b80a79f..47338c979126 100644 --- a/drivers/firmware/Makefile +++ b/drivers/firmware/Makefile | |||
@@ -13,3 +13,5 @@ obj-$(CONFIG_ISCSI_IBFT_FIND) += iscsi_ibft_find.o | |||
13 | obj-$(CONFIG_ISCSI_IBFT) += iscsi_ibft.o | 13 | obj-$(CONFIG_ISCSI_IBFT) += iscsi_ibft.o |
14 | obj-$(CONFIG_FIRMWARE_MEMMAP) += memmap.o | 14 | obj-$(CONFIG_FIRMWARE_MEMMAP) += memmap.o |
15 | obj-$(CONFIG_SIGMA) += sigma.o | 15 | obj-$(CONFIG_SIGMA) += sigma.o |
16 | |||
17 | obj-$(CONFIG_GOOGLE_FIRMWARE) += google/ | ||
diff --git a/drivers/firmware/edd.c b/drivers/firmware/edd.c index 96c25d93eed1..f1b7f659d3c9 100644 --- a/drivers/firmware/edd.c +++ b/drivers/firmware/edd.c | |||
@@ -531,8 +531,8 @@ static int | |||
531 | edd_has_edd30(struct edd_device *edev) | 531 | edd_has_edd30(struct edd_device *edev) |
532 | { | 532 | { |
533 | struct edd_info *info; | 533 | struct edd_info *info; |
534 | int i, nonzero_path = 0; | 534 | int i; |
535 | char c; | 535 | u8 csum = 0; |
536 | 536 | ||
537 | if (!edev) | 537 | if (!edev) |
538 | return 0; | 538 | return 0; |
@@ -544,16 +544,16 @@ edd_has_edd30(struct edd_device *edev) | |||
544 | return 0; | 544 | return 0; |
545 | } | 545 | } |
546 | 546 | ||
547 | for (i = 30; i <= 73; i++) { | 547 | |
548 | c = *(((uint8_t *) info) + i + 4); | 548 | /* We support only T13 spec */ |
549 | if (c) { | 549 | if (info->params.device_path_info_length != 44) |
550 | nonzero_path++; | 550 | return 0; |
551 | break; | 551 | |
552 | } | 552 | for (i = 30; i < info->params.device_path_info_length + 30; i++) |
553 | } | 553 | csum += *(((u8 *)&info->params) + i); |
554 | if (!nonzero_path) { | 554 | |
555 | if (csum) | ||
555 | return 0; | 556 | return 0; |
556 | } | ||
557 | 557 | ||
558 | return 1; | 558 | return 1; |
559 | } | 559 | } |
diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c index ff0c373e3bbf..a2d2f1f0d4f3 100644 --- a/drivers/firmware/efivars.c +++ b/drivers/firmware/efivars.c | |||
@@ -677,8 +677,8 @@ create_efivars_bin_attributes(struct efivars *efivars) | |||
677 | 677 | ||
678 | return 0; | 678 | return 0; |
679 | out_free: | 679 | out_free: |
680 | kfree(efivars->new_var); | 680 | kfree(efivars->del_var); |
681 | efivars->new_var = NULL; | 681 | efivars->del_var = NULL; |
682 | kfree(efivars->new_var); | 682 | kfree(efivars->new_var); |
683 | efivars->new_var = NULL; | 683 | efivars->new_var = NULL; |
684 | return error; | 684 | return error; |
@@ -803,6 +803,8 @@ efivars_init(void) | |||
803 | ops.set_variable = efi.set_variable; | 803 | ops.set_variable = efi.set_variable; |
804 | ops.get_next_variable = efi.get_next_variable; | 804 | ops.get_next_variable = efi.get_next_variable; |
805 | error = register_efivars(&__efivars, &ops, efi_kobj); | 805 | error = register_efivars(&__efivars, &ops, efi_kobj); |
806 | if (error) | ||
807 | goto err_put; | ||
806 | 808 | ||
807 | /* Don't forget the systab entry */ | 809 | /* Don't forget the systab entry */ |
808 | error = sysfs_create_group(efi_kobj, &efi_subsys_attr_group); | 810 | error = sysfs_create_group(efi_kobj, &efi_subsys_attr_group); |
@@ -810,18 +812,25 @@ efivars_init(void) | |||
810 | printk(KERN_ERR | 812 | printk(KERN_ERR |
811 | "efivars: Sysfs attribute export failed with error %d.\n", | 813 | "efivars: Sysfs attribute export failed with error %d.\n", |
812 | error); | 814 | error); |
813 | unregister_efivars(&__efivars); | 815 | goto err_unregister; |
814 | kobject_put(efi_kobj); | ||
815 | } | 816 | } |
816 | 817 | ||
818 | return 0; | ||
819 | |||
820 | err_unregister: | ||
821 | unregister_efivars(&__efivars); | ||
822 | err_put: | ||
823 | kobject_put(efi_kobj); | ||
817 | return error; | 824 | return error; |
818 | } | 825 | } |
819 | 826 | ||
820 | static void __exit | 827 | static void __exit |
821 | efivars_exit(void) | 828 | efivars_exit(void) |
822 | { | 829 | { |
823 | unregister_efivars(&__efivars); | 830 | if (efi_enabled) { |
824 | kobject_put(efi_kobj); | 831 | unregister_efivars(&__efivars); |
832 | kobject_put(efi_kobj); | ||
833 | } | ||
825 | } | 834 | } |
826 | 835 | ||
827 | module_init(efivars_init); | 836 | module_init(efivars_init); |
diff --git a/drivers/firmware/google/Kconfig b/drivers/firmware/google/Kconfig new file mode 100644 index 000000000000..87096b6ca5c9 --- /dev/null +++ b/drivers/firmware/google/Kconfig | |||
@@ -0,0 +1,31 @@ | |||
1 | config GOOGLE_FIRMWARE | ||
2 | bool "Google Firmware Drivers" | ||
3 | depends on X86 | ||
4 | default n | ||
5 | help | ||
6 | These firmware drivers are used by Google's servers. They are | ||
7 | only useful if you are working directly on one of their | ||
8 | proprietary servers. If in doubt, say "N". | ||
9 | |||
10 | menu "Google Firmware Drivers" | ||
11 | depends on GOOGLE_FIRMWARE | ||
12 | |||
13 | config GOOGLE_SMI | ||
14 | tristate "SMI interface for Google platforms" | ||
15 | depends on ACPI && DMI | ||
16 | select EFI_VARS | ||
17 | help | ||
18 | Say Y here if you want to enable SMI callbacks for Google | ||
19 | platforms. This provides an interface for writing to and | ||
20 | clearing the EFI event log and reading and writing NVRAM | ||
21 | variables. | ||
22 | |||
23 | config GOOGLE_MEMCONSOLE | ||
24 | tristate "Firmware Memory Console" | ||
25 | depends on DMI | ||
26 | help | ||
27 | This option enables the kernel to search for a firmware log in | ||
28 | the EBDA on Google servers. If found, this log is exported to | ||
29 | userland in the file /sys/firmware/log. | ||
30 | |||
31 | endmenu | ||
diff --git a/drivers/firmware/google/Makefile b/drivers/firmware/google/Makefile new file mode 100644 index 000000000000..54a294e3cb61 --- /dev/null +++ b/drivers/firmware/google/Makefile | |||
@@ -0,0 +1,3 @@ | |||
1 | |||
2 | obj-$(CONFIG_GOOGLE_SMI) += gsmi.o | ||
3 | obj-$(CONFIG_GOOGLE_MEMCONSOLE) += memconsole.o | ||
diff --git a/drivers/firmware/google/gsmi.c b/drivers/firmware/google/gsmi.c new file mode 100644 index 000000000000..fa7f0b3e81dd --- /dev/null +++ b/drivers/firmware/google/gsmi.c | |||
@@ -0,0 +1,940 @@ | |||
1 | /* | ||
2 | * Copyright 2010 Google Inc. All Rights Reserved. | ||
3 | * Author: dlaurie@google.com (Duncan Laurie) | ||
4 | * | ||
5 | * Re-worked to expose sysfs APIs by mikew@google.com (Mike Waychison) | ||
6 | * | ||
7 | * EFI SMI interface for Google platforms | ||
8 | */ | ||
9 | |||
10 | #include <linux/kernel.h> | ||
11 | #include <linux/init.h> | ||
12 | #include <linux/types.h> | ||
13 | #include <linux/device.h> | ||
14 | #include <linux/platform_device.h> | ||
15 | #include <linux/errno.h> | ||
16 | #include <linux/string.h> | ||
17 | #include <linux/spinlock.h> | ||
18 | #include <linux/dma-mapping.h> | ||
19 | #include <linux/dmapool.h> | ||
20 | #include <linux/fs.h> | ||
21 | #include <linux/slab.h> | ||
22 | #include <linux/ioctl.h> | ||
23 | #include <linux/acpi.h> | ||
24 | #include <linux/io.h> | ||
25 | #include <linux/uaccess.h> | ||
26 | #include <linux/dmi.h> | ||
27 | #include <linux/kdebug.h> | ||
28 | #include <linux/reboot.h> | ||
29 | #include <linux/efi.h> | ||
30 | |||
31 | #define GSMI_SHUTDOWN_CLEAN 0 /* Clean Shutdown */ | ||
32 | /* TODO(mikew@google.com): Tie in HARDLOCKUP_DETECTOR with NMIWDT */ | ||
33 | #define GSMI_SHUTDOWN_NMIWDT 1 /* NMI Watchdog */ | ||
34 | #define GSMI_SHUTDOWN_PANIC 2 /* Panic */ | ||
35 | #define GSMI_SHUTDOWN_OOPS 3 /* Oops */ | ||
36 | #define GSMI_SHUTDOWN_DIE 4 /* Die -- No longer meaningful */ | ||
37 | #define GSMI_SHUTDOWN_MCE 5 /* Machine Check */ | ||
38 | #define GSMI_SHUTDOWN_SOFTWDT 6 /* Software Watchdog */ | ||
39 | #define GSMI_SHUTDOWN_MBE 7 /* Uncorrected ECC */ | ||
40 | #define GSMI_SHUTDOWN_TRIPLE 8 /* Triple Fault */ | ||
41 | |||
42 | #define DRIVER_VERSION "1.0" | ||
43 | #define GSMI_GUID_SIZE 16 | ||
44 | #define GSMI_BUF_SIZE 1024 | ||
45 | #define GSMI_BUF_ALIGN sizeof(u64) | ||
46 | #define GSMI_CALLBACK 0xef | ||
47 | |||
48 | /* SMI return codes */ | ||
49 | #define GSMI_SUCCESS 0x00 | ||
50 | #define GSMI_UNSUPPORTED2 0x03 | ||
51 | #define GSMI_LOG_FULL 0x0b | ||
52 | #define GSMI_VAR_NOT_FOUND 0x0e | ||
53 | #define GSMI_HANDSHAKE_SPIN 0x7d | ||
54 | #define GSMI_HANDSHAKE_CF 0x7e | ||
55 | #define GSMI_HANDSHAKE_NONE 0x7f | ||
56 | #define GSMI_INVALID_PARAMETER 0x82 | ||
57 | #define GSMI_UNSUPPORTED 0x83 | ||
58 | #define GSMI_BUFFER_TOO_SMALL 0x85 | ||
59 | #define GSMI_NOT_READY 0x86 | ||
60 | #define GSMI_DEVICE_ERROR 0x87 | ||
61 | #define GSMI_NOT_FOUND 0x8e | ||
62 | |||
63 | #define QUIRKY_BOARD_HASH 0x78a30a50 | ||
64 | |||
65 | /* Internally used commands passed to the firmware */ | ||
66 | #define GSMI_CMD_GET_NVRAM_VAR 0x01 | ||
67 | #define GSMI_CMD_GET_NEXT_VAR 0x02 | ||
68 | #define GSMI_CMD_SET_NVRAM_VAR 0x03 | ||
69 | #define GSMI_CMD_SET_EVENT_LOG 0x08 | ||
70 | #define GSMI_CMD_CLEAR_EVENT_LOG 0x09 | ||
71 | #define GSMI_CMD_CLEAR_CONFIG 0x20 | ||
72 | #define GSMI_CMD_HANDSHAKE_TYPE 0xC1 | ||
73 | |||
74 | /* Magic entry type for kernel events */ | ||
75 | #define GSMI_LOG_ENTRY_TYPE_KERNEL 0xDEAD | ||
76 | |||
77 | /* SMI buffers must be in 32bit physical address space */ | ||
78 | struct gsmi_buf { | ||
79 | u8 *start; /* start of buffer */ | ||
80 | size_t length; /* length of buffer */ | ||
81 | dma_addr_t handle; /* dma allocation handle */ | ||
82 | u32 address; /* physical address of buffer */ | ||
83 | }; | ||
84 | |||
85 | struct gsmi_device { | ||
86 | struct platform_device *pdev; /* platform device */ | ||
87 | struct gsmi_buf *name_buf; /* variable name buffer */ | ||
88 | struct gsmi_buf *data_buf; /* generic data buffer */ | ||
89 | struct gsmi_buf *param_buf; /* parameter buffer */ | ||
90 | spinlock_t lock; /* serialize access to SMIs */ | ||
91 | u16 smi_cmd; /* SMI command port */ | ||
92 | int handshake_type; /* firmware handler interlock type */ | ||
93 | struct dma_pool *dma_pool; /* DMA buffer pool */ | ||
94 | } gsmi_dev; | ||
95 | |||
96 | /* Packed structures for communicating with the firmware */ | ||
97 | struct gsmi_nvram_var_param { | ||
98 | efi_guid_t guid; | ||
99 | u32 name_ptr; | ||
100 | u32 attributes; | ||
101 | u32 data_len; | ||
102 | u32 data_ptr; | ||
103 | } __packed; | ||
104 | |||
105 | struct gsmi_get_next_var_param { | ||
106 | u8 guid[GSMI_GUID_SIZE]; | ||
107 | u32 name_ptr; | ||
108 | u32 name_len; | ||
109 | } __packed; | ||
110 | |||
111 | struct gsmi_set_eventlog_param { | ||
112 | u32 data_ptr; | ||
113 | u32 data_len; | ||
114 | u32 type; | ||
115 | } __packed; | ||
116 | |||
117 | /* Event log formats */ | ||
118 | struct gsmi_log_entry_type_1 { | ||
119 | u16 type; | ||
120 | u32 instance; | ||
121 | } __packed; | ||
122 | |||
123 | |||
124 | /* | ||
125 | * Some platforms don't have explicit SMI handshake | ||
126 | * and need to wait for SMI to complete. | ||
127 | */ | ||
128 | #define GSMI_DEFAULT_SPINCOUNT 0x10000 | ||
129 | static unsigned int spincount = GSMI_DEFAULT_SPINCOUNT; | ||
130 | module_param(spincount, uint, 0600); | ||
131 | MODULE_PARM_DESC(spincount, | ||
132 | "The number of loop iterations to use when using the spin handshake."); | ||
133 | |||
134 | static struct gsmi_buf *gsmi_buf_alloc(void) | ||
135 | { | ||
136 | struct gsmi_buf *smibuf; | ||
137 | |||
138 | smibuf = kzalloc(sizeof(*smibuf), GFP_KERNEL); | ||
139 | if (!smibuf) { | ||
140 | printk(KERN_ERR "gsmi: out of memory\n"); | ||
141 | return NULL; | ||
142 | } | ||
143 | |||
144 | /* allocate buffer in 32bit address space */ | ||
145 | smibuf->start = dma_pool_alloc(gsmi_dev.dma_pool, GFP_KERNEL, | ||
146 | &smibuf->handle); | ||
147 | if (!smibuf->start) { | ||
148 | printk(KERN_ERR "gsmi: failed to allocate name buffer\n"); | ||
149 | kfree(smibuf); | ||
150 | return NULL; | ||
151 | } | ||
152 | |||
153 | /* fill in the buffer handle */ | ||
154 | smibuf->length = GSMI_BUF_SIZE; | ||
155 | smibuf->address = (u32)virt_to_phys(smibuf->start); | ||
156 | |||
157 | return smibuf; | ||
158 | } | ||
159 | |||
160 | static void gsmi_buf_free(struct gsmi_buf *smibuf) | ||
161 | { | ||
162 | if (smibuf) { | ||
163 | if (smibuf->start) | ||
164 | dma_pool_free(gsmi_dev.dma_pool, smibuf->start, | ||
165 | smibuf->handle); | ||
166 | kfree(smibuf); | ||
167 | } | ||
168 | } | ||
169 | |||
170 | /* | ||
171 | * Make a call to gsmi func(sub). GSMI error codes are translated to | ||
172 | * in-kernel errnos (0 on success, -ERRNO on error). | ||
173 | */ | ||
174 | static int gsmi_exec(u8 func, u8 sub) | ||
175 | { | ||
176 | u16 cmd = (sub << 8) | func; | ||
177 | u16 result = 0; | ||
178 | int rc = 0; | ||
179 | |||
180 | /* | ||
181 | * AH : Subfunction number | ||
182 | * AL : Function number | ||
183 | * EBX : Parameter block address | ||
184 | * DX : SMI command port | ||
185 | * | ||
186 | * Three protocols here. See also the comment in gsmi_init(). | ||
187 | */ | ||
188 | if (gsmi_dev.handshake_type == GSMI_HANDSHAKE_CF) { | ||
189 | /* | ||
190 | * If handshake_type == HANDSHAKE_CF then set CF on the | ||
191 | * way in and wait for the handler to clear it; this avoids | ||
192 | * corrupting register state on those chipsets which have | ||
193 | * a delay between writing the SMI trigger register and | ||
194 | * entering SMM. | ||
195 | */ | ||
196 | asm volatile ( | ||
197 | "stc\n" | ||
198 | "outb %%al, %%dx\n" | ||
199 | "1: jc 1b\n" | ||
200 | : "=a" (result) | ||
201 | : "0" (cmd), | ||
202 | "d" (gsmi_dev.smi_cmd), | ||
203 | "b" (gsmi_dev.param_buf->address) | ||
204 | : "memory", "cc" | ||
205 | ); | ||
206 | } else if (gsmi_dev.handshake_type == GSMI_HANDSHAKE_SPIN) { | ||
207 | /* | ||
208 | * If handshake_type == HANDSHAKE_SPIN we spin a | ||
209 | * hundred-ish usecs to ensure the SMI has triggered. | ||
210 | */ | ||
211 | asm volatile ( | ||
212 | "outb %%al, %%dx\n" | ||
213 | "1: loop 1b\n" | ||
214 | : "=a" (result) | ||
215 | : "0" (cmd), | ||
216 | "d" (gsmi_dev.smi_cmd), | ||
217 | "b" (gsmi_dev.param_buf->address), | ||
218 | "c" (spincount) | ||
219 | : "memory", "cc" | ||
220 | ); | ||
221 | } else { | ||
222 | /* | ||
223 | * If handshake_type == HANDSHAKE_NONE we do nothing; | ||
224 | * either we don't need to or it's legacy firmware that | ||
225 | * doesn't understand the CF protocol. | ||
226 | */ | ||
227 | asm volatile ( | ||
228 | "outb %%al, %%dx\n\t" | ||
229 | : "=a" (result) | ||
230 | : "0" (cmd), | ||
231 | "d" (gsmi_dev.smi_cmd), | ||
232 | "b" (gsmi_dev.param_buf->address) | ||
233 | : "memory", "cc" | ||
234 | ); | ||
235 | } | ||
236 | |||
237 | /* check return code from SMI handler */ | ||
238 | switch (result) { | ||
239 | case GSMI_SUCCESS: | ||
240 | break; | ||
241 | case GSMI_VAR_NOT_FOUND: | ||
242 | /* not really an error, but let the caller know */ | ||
243 | rc = 1; | ||
244 | break; | ||
245 | case GSMI_INVALID_PARAMETER: | ||
246 | printk(KERN_ERR "gsmi: exec 0x%04x: Invalid parameter\n", cmd); | ||
247 | rc = -EINVAL; | ||
248 | break; | ||
249 | case GSMI_BUFFER_TOO_SMALL: | ||
250 | printk(KERN_ERR "gsmi: exec 0x%04x: Buffer too small\n", cmd); | ||
251 | rc = -ENOMEM; | ||
252 | break; | ||
253 | case GSMI_UNSUPPORTED: | ||
254 | case GSMI_UNSUPPORTED2: | ||
255 | if (sub != GSMI_CMD_HANDSHAKE_TYPE) | ||
256 | printk(KERN_ERR "gsmi: exec 0x%04x: Not supported\n", | ||
257 | cmd); | ||
258 | rc = -ENOSYS; | ||
259 | break; | ||
260 | case GSMI_NOT_READY: | ||
261 | printk(KERN_ERR "gsmi: exec 0x%04x: Not ready\n", cmd); | ||
262 | rc = -EBUSY; | ||
263 | break; | ||
264 | case GSMI_DEVICE_ERROR: | ||
265 | printk(KERN_ERR "gsmi: exec 0x%04x: Device error\n", cmd); | ||
266 | rc = -EFAULT; | ||
267 | break; | ||
268 | case GSMI_NOT_FOUND: | ||
269 | printk(KERN_ERR "gsmi: exec 0x%04x: Data not found\n", cmd); | ||
270 | rc = -ENOENT; | ||
271 | break; | ||
272 | case GSMI_LOG_FULL: | ||
273 | printk(KERN_ERR "gsmi: exec 0x%04x: Log full\n", cmd); | ||
274 | rc = -ENOSPC; | ||
275 | break; | ||
276 | case GSMI_HANDSHAKE_CF: | ||
277 | case GSMI_HANDSHAKE_SPIN: | ||
278 | case GSMI_HANDSHAKE_NONE: | ||
279 | rc = result; | ||
280 | break; | ||
281 | default: | ||
282 | printk(KERN_ERR "gsmi: exec 0x%04x: Unknown error 0x%04x\n", | ||
283 | cmd, result); | ||
284 | rc = -ENXIO; | ||
285 | } | ||
286 | |||
287 | return rc; | ||
288 | } | ||
289 | |||
290 | /* Return the number of unicode characters in data */ | ||
291 | static size_t | ||
292 | utf16_strlen(efi_char16_t *data, unsigned long maxlength) | ||
293 | { | ||
294 | unsigned long length = 0; | ||
295 | |||
296 | while (*data++ != 0 && length < maxlength) | ||
297 | length++; | ||
298 | return length; | ||
299 | } | ||
300 | |||
301 | static efi_status_t gsmi_get_variable(efi_char16_t *name, | ||
302 | efi_guid_t *vendor, u32 *attr, | ||
303 | unsigned long *data_size, | ||
304 | void *data) | ||
305 | { | ||
306 | struct gsmi_nvram_var_param param = { | ||
307 | .name_ptr = gsmi_dev.name_buf->address, | ||
308 | .data_ptr = gsmi_dev.data_buf->address, | ||
309 | .data_len = (u32)*data_size, | ||
310 | }; | ||
311 | efi_status_t ret = EFI_SUCCESS; | ||
312 | unsigned long flags; | ||
313 | size_t name_len = utf16_strlen(name, GSMI_BUF_SIZE / 2); | ||
314 | int rc; | ||
315 | |||
316 | if (name_len >= GSMI_BUF_SIZE / 2) | ||
317 | return EFI_BAD_BUFFER_SIZE; | ||
318 | |||
319 | spin_lock_irqsave(&gsmi_dev.lock, flags); | ||
320 | |||
321 | /* Vendor guid */ | ||
322 | memcpy(¶m.guid, vendor, sizeof(param.guid)); | ||
323 | |||
324 | /* variable name, already in UTF-16 */ | ||
325 | memset(gsmi_dev.name_buf->start, 0, gsmi_dev.name_buf->length); | ||
326 | memcpy(gsmi_dev.name_buf->start, name, name_len * 2); | ||
327 | |||
328 | /* data pointer */ | ||
329 | memset(gsmi_dev.data_buf->start, 0, gsmi_dev.data_buf->length); | ||
330 | |||
331 | /* parameter buffer */ | ||
332 | memset(gsmi_dev.param_buf->start, 0, gsmi_dev.param_buf->length); | ||
333 | memcpy(gsmi_dev.param_buf->start, ¶m, sizeof(param)); | ||
334 | |||
335 | rc = gsmi_exec(GSMI_CALLBACK, GSMI_CMD_GET_NVRAM_VAR); | ||
336 | if (rc < 0) { | ||
337 | printk(KERN_ERR "gsmi: Get Variable failed\n"); | ||
338 | ret = EFI_LOAD_ERROR; | ||
339 | } else if (rc == 1) { | ||
340 | /* variable was not found */ | ||
341 | ret = EFI_NOT_FOUND; | ||
342 | } else { | ||
343 | /* Get the arguments back */ | ||
344 | memcpy(¶m, gsmi_dev.param_buf->start, sizeof(param)); | ||
345 | |||
346 | /* The size reported is the min of all of our buffers */ | ||
347 | *data_size = min(*data_size, gsmi_dev.data_buf->length); | ||
348 | *data_size = min_t(unsigned long, *data_size, param.data_len); | ||
349 | |||
350 | /* Copy data back to return buffer. */ | ||
351 | memcpy(data, gsmi_dev.data_buf->start, *data_size); | ||
352 | |||
353 | /* All variables are have the following attributes */ | ||
354 | *attr = EFI_VARIABLE_NON_VOLATILE | | ||
355 | EFI_VARIABLE_BOOTSERVICE_ACCESS | | ||
356 | EFI_VARIABLE_RUNTIME_ACCESS; | ||
357 | } | ||
358 | |||
359 | spin_unlock_irqrestore(&gsmi_dev.lock, flags); | ||
360 | |||
361 | return ret; | ||
362 | } | ||
363 | |||
364 | static efi_status_t gsmi_get_next_variable(unsigned long *name_size, | ||
365 | efi_char16_t *name, | ||
366 | efi_guid_t *vendor) | ||
367 | { | ||
368 | struct gsmi_get_next_var_param param = { | ||
369 | .name_ptr = gsmi_dev.name_buf->address, | ||
370 | .name_len = gsmi_dev.name_buf->length, | ||
371 | }; | ||
372 | efi_status_t ret = EFI_SUCCESS; | ||
373 | int rc; | ||
374 | unsigned long flags; | ||
375 | |||
376 | /* For the moment, only support buffers that exactly match in size */ | ||
377 | if (*name_size != GSMI_BUF_SIZE) | ||
378 | return EFI_BAD_BUFFER_SIZE; | ||
379 | |||
380 | /* Let's make sure the thing is at least null-terminated */ | ||
381 | if (utf16_strlen(name, GSMI_BUF_SIZE / 2) == GSMI_BUF_SIZE / 2) | ||
382 | return EFI_INVALID_PARAMETER; | ||
383 | |||
384 | spin_lock_irqsave(&gsmi_dev.lock, flags); | ||
385 | |||
386 | /* guid */ | ||
387 | memcpy(¶m.guid, vendor, sizeof(param.guid)); | ||
388 | |||
389 | /* variable name, already in UTF-16 */ | ||
390 | memcpy(gsmi_dev.name_buf->start, name, *name_size); | ||
391 | |||
392 | /* parameter buffer */ | ||
393 | memset(gsmi_dev.param_buf->start, 0, gsmi_dev.param_buf->length); | ||
394 | memcpy(gsmi_dev.param_buf->start, ¶m, sizeof(param)); | ||
395 | |||
396 | rc = gsmi_exec(GSMI_CALLBACK, GSMI_CMD_GET_NEXT_VAR); | ||
397 | if (rc < 0) { | ||
398 | printk(KERN_ERR "gsmi: Get Next Variable Name failed\n"); | ||
399 | ret = EFI_LOAD_ERROR; | ||
400 | } else if (rc == 1) { | ||
401 | /* variable not found -- end of list */ | ||
402 | ret = EFI_NOT_FOUND; | ||
403 | } else { | ||
404 | /* copy variable data back to return buffer */ | ||
405 | memcpy(¶m, gsmi_dev.param_buf->start, sizeof(param)); | ||
406 | |||
407 | /* Copy the name back */ | ||
408 | memcpy(name, gsmi_dev.name_buf->start, GSMI_BUF_SIZE); | ||
409 | *name_size = utf16_strlen(name, GSMI_BUF_SIZE / 2) * 2; | ||
410 | |||
411 | /* copy guid to return buffer */ | ||
412 | memcpy(vendor, ¶m.guid, sizeof(param.guid)); | ||
413 | ret = EFI_SUCCESS; | ||
414 | } | ||
415 | |||
416 | spin_unlock_irqrestore(&gsmi_dev.lock, flags); | ||
417 | |||
418 | return ret; | ||
419 | } | ||
420 | |||
421 | static efi_status_t gsmi_set_variable(efi_char16_t *name, | ||
422 | efi_guid_t *vendor, | ||
423 | unsigned long attr, | ||
424 | unsigned long data_size, | ||
425 | void *data) | ||
426 | { | ||
427 | struct gsmi_nvram_var_param param = { | ||
428 | .name_ptr = gsmi_dev.name_buf->address, | ||
429 | .data_ptr = gsmi_dev.data_buf->address, | ||
430 | .data_len = (u32)data_size, | ||
431 | .attributes = EFI_VARIABLE_NON_VOLATILE | | ||
432 | EFI_VARIABLE_BOOTSERVICE_ACCESS | | ||
433 | EFI_VARIABLE_RUNTIME_ACCESS, | ||
434 | }; | ||
435 | size_t name_len = utf16_strlen(name, GSMI_BUF_SIZE / 2); | ||
436 | efi_status_t ret = EFI_SUCCESS; | ||
437 | int rc; | ||
438 | unsigned long flags; | ||
439 | |||
440 | if (name_len >= GSMI_BUF_SIZE / 2) | ||
441 | return EFI_BAD_BUFFER_SIZE; | ||
442 | |||
443 | spin_lock_irqsave(&gsmi_dev.lock, flags); | ||
444 | |||
445 | /* guid */ | ||
446 | memcpy(¶m.guid, vendor, sizeof(param.guid)); | ||
447 | |||
448 | /* variable name, already in UTF-16 */ | ||
449 | memset(gsmi_dev.name_buf->start, 0, gsmi_dev.name_buf->length); | ||
450 | memcpy(gsmi_dev.name_buf->start, name, name_len * 2); | ||
451 | |||
452 | /* data pointer */ | ||
453 | memset(gsmi_dev.data_buf->start, 0, gsmi_dev.data_buf->length); | ||
454 | memcpy(gsmi_dev.data_buf->start, data, data_size); | ||
455 | |||
456 | /* parameter buffer */ | ||
457 | memset(gsmi_dev.param_buf->start, 0, gsmi_dev.param_buf->length); | ||
458 | memcpy(gsmi_dev.param_buf->start, ¶m, sizeof(param)); | ||
459 | |||
460 | rc = gsmi_exec(GSMI_CALLBACK, GSMI_CMD_SET_NVRAM_VAR); | ||
461 | if (rc < 0) { | ||
462 | printk(KERN_ERR "gsmi: Set Variable failed\n"); | ||
463 | ret = EFI_INVALID_PARAMETER; | ||
464 | } | ||
465 | |||
466 | spin_unlock_irqrestore(&gsmi_dev.lock, flags); | ||
467 | |||
468 | return ret; | ||
469 | } | ||
470 | |||
471 | static const struct efivar_operations efivar_ops = { | ||
472 | .get_variable = gsmi_get_variable, | ||
473 | .set_variable = gsmi_set_variable, | ||
474 | .get_next_variable = gsmi_get_next_variable, | ||
475 | }; | ||
476 | |||
477 | static ssize_t eventlog_write(struct file *filp, struct kobject *kobj, | ||
478 | struct bin_attribute *bin_attr, | ||
479 | char *buf, loff_t pos, size_t count) | ||
480 | { | ||
481 | struct gsmi_set_eventlog_param param = { | ||
482 | .data_ptr = gsmi_dev.data_buf->address, | ||
483 | }; | ||
484 | int rc = 0; | ||
485 | unsigned long flags; | ||
486 | |||
487 | /* Pull the type out */ | ||
488 | if (count < sizeof(u32)) | ||
489 | return -EINVAL; | ||
490 | param.type = *(u32 *)buf; | ||
491 | count -= sizeof(u32); | ||
492 | buf += sizeof(u32); | ||
493 | |||
494 | /* The remaining buffer is the data payload */ | ||
495 | if (count > gsmi_dev.data_buf->length) | ||
496 | return -EINVAL; | ||
497 | param.data_len = count - sizeof(u32); | ||
498 | |||
499 | spin_lock_irqsave(&gsmi_dev.lock, flags); | ||
500 | |||
501 | /* data pointer */ | ||
502 | memset(gsmi_dev.data_buf->start, 0, gsmi_dev.data_buf->length); | ||
503 | memcpy(gsmi_dev.data_buf->start, buf, param.data_len); | ||
504 | |||
505 | /* parameter buffer */ | ||
506 | memset(gsmi_dev.param_buf->start, 0, gsmi_dev.param_buf->length); | ||
507 | memcpy(gsmi_dev.param_buf->start, ¶m, sizeof(param)); | ||
508 | |||
509 | rc = gsmi_exec(GSMI_CALLBACK, GSMI_CMD_SET_EVENT_LOG); | ||
510 | if (rc < 0) | ||
511 | printk(KERN_ERR "gsmi: Set Event Log failed\n"); | ||
512 | |||
513 | spin_unlock_irqrestore(&gsmi_dev.lock, flags); | ||
514 | |||
515 | return rc; | ||
516 | |||
517 | } | ||
518 | |||
519 | static struct bin_attribute eventlog_bin_attr = { | ||
520 | .attr = {.name = "append_to_eventlog", .mode = 0200}, | ||
521 | .write = eventlog_write, | ||
522 | }; | ||
523 | |||
524 | static ssize_t gsmi_clear_eventlog_store(struct kobject *kobj, | ||
525 | struct kobj_attribute *attr, | ||
526 | const char *buf, size_t count) | ||
527 | { | ||
528 | int rc; | ||
529 | unsigned long flags; | ||
530 | unsigned long val; | ||
531 | struct { | ||
532 | u32 percentage; | ||
533 | u32 data_type; | ||
534 | } param; | ||
535 | |||
536 | rc = strict_strtoul(buf, 0, &val); | ||
537 | if (rc) | ||
538 | return rc; | ||
539 | |||
540 | /* | ||
541 | * Value entered is a percentage, 0 through 100, anything else | ||
542 | * is invalid. | ||
543 | */ | ||
544 | if (val > 100) | ||
545 | return -EINVAL; | ||
546 | |||
547 | /* data_type here selects the smbios event log. */ | ||
548 | param.percentage = val; | ||
549 | param.data_type = 0; | ||
550 | |||
551 | spin_lock_irqsave(&gsmi_dev.lock, flags); | ||
552 | |||
553 | /* parameter buffer */ | ||
554 | memset(gsmi_dev.param_buf->start, 0, gsmi_dev.param_buf->length); | ||
555 | memcpy(gsmi_dev.param_buf->start, ¶m, sizeof(param)); | ||
556 | |||
557 | rc = gsmi_exec(GSMI_CALLBACK, GSMI_CMD_CLEAR_EVENT_LOG); | ||
558 | |||
559 | spin_unlock_irqrestore(&gsmi_dev.lock, flags); | ||
560 | |||
561 | if (rc) | ||
562 | return rc; | ||
563 | return count; | ||
564 | } | ||
565 | |||
566 | static struct kobj_attribute gsmi_clear_eventlog_attr = { | ||
567 | .attr = {.name = "clear_eventlog", .mode = 0200}, | ||
568 | .store = gsmi_clear_eventlog_store, | ||
569 | }; | ||
570 | |||
571 | static ssize_t gsmi_clear_config_store(struct kobject *kobj, | ||
572 | struct kobj_attribute *attr, | ||
573 | const char *buf, size_t count) | ||
574 | { | ||
575 | int rc; | ||
576 | unsigned long flags; | ||
577 | |||
578 | spin_lock_irqsave(&gsmi_dev.lock, flags); | ||
579 | |||
580 | /* clear parameter buffer */ | ||
581 | memset(gsmi_dev.param_buf->start, 0, gsmi_dev.param_buf->length); | ||
582 | |||
583 | rc = gsmi_exec(GSMI_CALLBACK, GSMI_CMD_CLEAR_CONFIG); | ||
584 | |||
585 | spin_unlock_irqrestore(&gsmi_dev.lock, flags); | ||
586 | |||
587 | if (rc) | ||
588 | return rc; | ||
589 | return count; | ||
590 | } | ||
591 | |||
592 | static struct kobj_attribute gsmi_clear_config_attr = { | ||
593 | .attr = {.name = "clear_config", .mode = 0200}, | ||
594 | .store = gsmi_clear_config_store, | ||
595 | }; | ||
596 | |||
597 | static const struct attribute *gsmi_attrs[] = { | ||
598 | &gsmi_clear_config_attr.attr, | ||
599 | &gsmi_clear_eventlog_attr.attr, | ||
600 | NULL, | ||
601 | }; | ||
602 | |||
603 | static int gsmi_shutdown_reason(int reason) | ||
604 | { | ||
605 | struct gsmi_log_entry_type_1 entry = { | ||
606 | .type = GSMI_LOG_ENTRY_TYPE_KERNEL, | ||
607 | .instance = reason, | ||
608 | }; | ||
609 | struct gsmi_set_eventlog_param param = { | ||
610 | .data_len = sizeof(entry), | ||
611 | .type = 1, | ||
612 | }; | ||
613 | static int saved_reason; | ||
614 | int rc = 0; | ||
615 | unsigned long flags; | ||
616 | |||
617 | /* avoid duplicate entries in the log */ | ||
618 | if (saved_reason & (1 << reason)) | ||
619 | return 0; | ||
620 | |||
621 | spin_lock_irqsave(&gsmi_dev.lock, flags); | ||
622 | |||
623 | saved_reason |= (1 << reason); | ||
624 | |||
625 | /* data pointer */ | ||
626 | memset(gsmi_dev.data_buf->start, 0, gsmi_dev.data_buf->length); | ||
627 | memcpy(gsmi_dev.data_buf->start, &entry, sizeof(entry)); | ||
628 | |||
629 | /* parameter buffer */ | ||
630 | param.data_ptr = gsmi_dev.data_buf->address; | ||
631 | memset(gsmi_dev.param_buf->start, 0, gsmi_dev.param_buf->length); | ||
632 | memcpy(gsmi_dev.param_buf->start, ¶m, sizeof(param)); | ||
633 | |||
634 | rc = gsmi_exec(GSMI_CALLBACK, GSMI_CMD_SET_EVENT_LOG); | ||
635 | |||
636 | spin_unlock_irqrestore(&gsmi_dev.lock, flags); | ||
637 | |||
638 | if (rc < 0) | ||
639 | printk(KERN_ERR "gsmi: Log Shutdown Reason failed\n"); | ||
640 | else | ||
641 | printk(KERN_EMERG "gsmi: Log Shutdown Reason 0x%02x\n", | ||
642 | reason); | ||
643 | |||
644 | return rc; | ||
645 | } | ||
646 | |||
647 | static int gsmi_reboot_callback(struct notifier_block *nb, | ||
648 | unsigned long reason, void *arg) | ||
649 | { | ||
650 | gsmi_shutdown_reason(GSMI_SHUTDOWN_CLEAN); | ||
651 | return NOTIFY_DONE; | ||
652 | } | ||
653 | |||
654 | static struct notifier_block gsmi_reboot_notifier = { | ||
655 | .notifier_call = gsmi_reboot_callback | ||
656 | }; | ||
657 | |||
658 | static int gsmi_die_callback(struct notifier_block *nb, | ||
659 | unsigned long reason, void *arg) | ||
660 | { | ||
661 | if (reason == DIE_OOPS) | ||
662 | gsmi_shutdown_reason(GSMI_SHUTDOWN_OOPS); | ||
663 | return NOTIFY_DONE; | ||
664 | } | ||
665 | |||
666 | static struct notifier_block gsmi_die_notifier = { | ||
667 | .notifier_call = gsmi_die_callback | ||
668 | }; | ||
669 | |||
670 | static int gsmi_panic_callback(struct notifier_block *nb, | ||
671 | unsigned long reason, void *arg) | ||
672 | { | ||
673 | gsmi_shutdown_reason(GSMI_SHUTDOWN_PANIC); | ||
674 | return NOTIFY_DONE; | ||
675 | } | ||
676 | |||
677 | static struct notifier_block gsmi_panic_notifier = { | ||
678 | .notifier_call = gsmi_panic_callback, | ||
679 | }; | ||
680 | |||
681 | /* | ||
682 | * This hash function was blatantly copied from include/linux/hash.h. | ||
683 | * It is used by this driver to obfuscate a board name that requires a | ||
684 | * quirk within this driver. | ||
685 | * | ||
686 | * Please do not remove this copy of the function as any changes to the | ||
687 | * global utility hash_64() function would break this driver's ability | ||
688 | * to identify a board and provide the appropriate quirk -- mikew@google.com | ||
689 | */ | ||
690 | static u64 __init local_hash_64(u64 val, unsigned bits) | ||
691 | { | ||
692 | u64 hash = val; | ||
693 | |||
694 | /* Sigh, gcc can't optimise this alone like it does for 32 bits. */ | ||
695 | u64 n = hash; | ||
696 | n <<= 18; | ||
697 | hash -= n; | ||
698 | n <<= 33; | ||
699 | hash -= n; | ||
700 | n <<= 3; | ||
701 | hash += n; | ||
702 | n <<= 3; | ||
703 | hash -= n; | ||
704 | n <<= 4; | ||
705 | hash += n; | ||
706 | n <<= 2; | ||
707 | hash += n; | ||
708 | |||
709 | /* High bits are more random, so use them. */ | ||
710 | return hash >> (64 - bits); | ||
711 | } | ||
712 | |||
713 | static u32 __init hash_oem_table_id(char s[8]) | ||
714 | { | ||
715 | u64 input; | ||
716 | memcpy(&input, s, 8); | ||
717 | return local_hash_64(input, 32); | ||
718 | } | ||
719 | |||
720 | static struct dmi_system_id gsmi_dmi_table[] __initdata = { | ||
721 | { | ||
722 | .ident = "Google Board", | ||
723 | .matches = { | ||
724 | DMI_MATCH(DMI_BOARD_VENDOR, "Google, Inc."), | ||
725 | }, | ||
726 | }, | ||
727 | {} | ||
728 | }; | ||
729 | MODULE_DEVICE_TABLE(dmi, gsmi_dmi_table); | ||
730 | |||
731 | static __init int gsmi_system_valid(void) | ||
732 | { | ||
733 | u32 hash; | ||
734 | |||
735 | if (!dmi_check_system(gsmi_dmi_table)) | ||
736 | return -ENODEV; | ||
737 | |||
738 | /* | ||
739 | * Only newer firmware supports the gsmi interface. All older | ||
740 | * firmware that didn't support this interface used to plug the | ||
741 | * table name in the first four bytes of the oem_table_id field. | ||
742 | * Newer firmware doesn't do that though, so use that as the | ||
743 | * discriminant factor. We have to do this in order to | ||
744 | * whitewash our board names out of the public driver. | ||
745 | */ | ||
746 | if (!strncmp(acpi_gbl_FADT.header.oem_table_id, "FACP", 4)) { | ||
747 | printk(KERN_INFO "gsmi: Board is too old\n"); | ||
748 | return -ENODEV; | ||
749 | } | ||
750 | |||
751 | /* Disable on board with 1.0 BIOS due to Google bug 2602657 */ | ||
752 | hash = hash_oem_table_id(acpi_gbl_FADT.header.oem_table_id); | ||
753 | if (hash == QUIRKY_BOARD_HASH) { | ||
754 | const char *bios_ver = dmi_get_system_info(DMI_BIOS_VERSION); | ||
755 | if (strncmp(bios_ver, "1.0", 3) == 0) { | ||
756 | pr_info("gsmi: disabled on this board's BIOS %s\n", | ||
757 | bios_ver); | ||
758 | return -ENODEV; | ||
759 | } | ||
760 | } | ||
761 | |||
762 | /* check for valid SMI command port in ACPI FADT */ | ||
763 | if (acpi_gbl_FADT.smi_command == 0) { | ||
764 | pr_info("gsmi: missing smi_command\n"); | ||
765 | return -ENODEV; | ||
766 | } | ||
767 | |||
768 | /* Found */ | ||
769 | return 0; | ||
770 | } | ||
771 | |||
772 | static struct kobject *gsmi_kobj; | ||
773 | static struct efivars efivars; | ||
774 | |||
775 | static __init int gsmi_init(void) | ||
776 | { | ||
777 | unsigned long flags; | ||
778 | int ret; | ||
779 | |||
780 | ret = gsmi_system_valid(); | ||
781 | if (ret) | ||
782 | return ret; | ||
783 | |||
784 | gsmi_dev.smi_cmd = acpi_gbl_FADT.smi_command; | ||
785 | |||
786 | /* register device */ | ||
787 | gsmi_dev.pdev = platform_device_register_simple("gsmi", -1, NULL, 0); | ||
788 | if (IS_ERR(gsmi_dev.pdev)) { | ||
789 | printk(KERN_ERR "gsmi: unable to register platform device\n"); | ||
790 | return PTR_ERR(gsmi_dev.pdev); | ||
791 | } | ||
792 | |||
793 | /* SMI access needs to be serialized */ | ||
794 | spin_lock_init(&gsmi_dev.lock); | ||
795 | |||
796 | /* SMI callbacks require 32bit addresses */ | ||
797 | gsmi_dev.pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32); | ||
798 | gsmi_dev.pdev->dev.dma_mask = | ||
799 | &gsmi_dev.pdev->dev.coherent_dma_mask; | ||
800 | ret = -ENOMEM; | ||
801 | gsmi_dev.dma_pool = dma_pool_create("gsmi", &gsmi_dev.pdev->dev, | ||
802 | GSMI_BUF_SIZE, GSMI_BUF_ALIGN, 0); | ||
803 | if (!gsmi_dev.dma_pool) | ||
804 | goto out_err; | ||
805 | |||
806 | /* | ||
807 | * pre-allocate buffers because sometimes we are called when | ||
808 | * this is not feasible: oops, panic, die, mce, etc | ||
809 | */ | ||
810 | gsmi_dev.name_buf = gsmi_buf_alloc(); | ||
811 | if (!gsmi_dev.name_buf) { | ||
812 | printk(KERN_ERR "gsmi: failed to allocate name buffer\n"); | ||
813 | goto out_err; | ||
814 | } | ||
815 | |||
816 | gsmi_dev.data_buf = gsmi_buf_alloc(); | ||
817 | if (!gsmi_dev.data_buf) { | ||
818 | printk(KERN_ERR "gsmi: failed to allocate data buffer\n"); | ||
819 | goto out_err; | ||
820 | } | ||
821 | |||
822 | gsmi_dev.param_buf = gsmi_buf_alloc(); | ||
823 | if (!gsmi_dev.param_buf) { | ||
824 | printk(KERN_ERR "gsmi: failed to allocate param buffer\n"); | ||
825 | goto out_err; | ||
826 | } | ||
827 | |||
828 | /* | ||
829 | * Determine type of handshake used to serialize the SMI | ||
830 | * entry. See also gsmi_exec(). | ||
831 | * | ||
832 | * There's a "behavior" present on some chipsets where writing the | ||
833 | * SMI trigger register in the southbridge doesn't result in an | ||
834 | * immediate SMI. Rather, the processor can execute "a few" more | ||
835 | * instructions before the SMI takes effect. To ensure synchronous | ||
836 | * behavior, implement a handshake between the kernel driver and the | ||
837 | * firmware handler to spin until released. This ioctl determines | ||
838 | * the type of handshake. | ||
839 | * | ||
840 | * NONE: The firmware handler does not implement any | ||
841 | * handshake. Either it doesn't need to, or it's legacy firmware | ||
842 | * that doesn't know it needs to and never will. | ||
843 | * | ||
844 | * CF: The firmware handler will clear the CF in the saved | ||
845 | * state before returning. The driver may set the CF and test for | ||
846 | * it to clear before proceeding. | ||
847 | * | ||
848 | * SPIN: The firmware handler does not implement any handshake | ||
849 | * but the driver should spin for a hundred or so microseconds | ||
850 | * to ensure the SMI has triggered. | ||
851 | * | ||
852 | * Finally, the handler will return -ENOSYS if | ||
853 | * GSMI_CMD_HANDSHAKE_TYPE is unimplemented, which implies | ||
854 | * HANDSHAKE_NONE. | ||
855 | */ | ||
856 | spin_lock_irqsave(&gsmi_dev.lock, flags); | ||
857 | gsmi_dev.handshake_type = GSMI_HANDSHAKE_SPIN; | ||
858 | gsmi_dev.handshake_type = | ||
859 | gsmi_exec(GSMI_CALLBACK, GSMI_CMD_HANDSHAKE_TYPE); | ||
860 | if (gsmi_dev.handshake_type == -ENOSYS) | ||
861 | gsmi_dev.handshake_type = GSMI_HANDSHAKE_NONE; | ||
862 | spin_unlock_irqrestore(&gsmi_dev.lock, flags); | ||
863 | |||
864 | /* Remove and clean up gsmi if the handshake could not complete. */ | ||
865 | if (gsmi_dev.handshake_type == -ENXIO) { | ||
866 | printk(KERN_INFO "gsmi version " DRIVER_VERSION | ||
867 | " failed to load\n"); | ||
868 | ret = -ENODEV; | ||
869 | goto out_err; | ||
870 | } | ||
871 | |||
872 | printk(KERN_INFO "gsmi version " DRIVER_VERSION " loaded\n"); | ||
873 | |||
874 | /* Register in the firmware directory */ | ||
875 | ret = -ENOMEM; | ||
876 | gsmi_kobj = kobject_create_and_add("gsmi", firmware_kobj); | ||
877 | if (!gsmi_kobj) { | ||
878 | printk(KERN_INFO "gsmi: Failed to create firmware kobj\n"); | ||
879 | goto out_err; | ||
880 | } | ||
881 | |||
882 | /* Setup eventlog access */ | ||
883 | ret = sysfs_create_bin_file(gsmi_kobj, &eventlog_bin_attr); | ||
884 | if (ret) { | ||
885 | printk(KERN_INFO "gsmi: Failed to setup eventlog"); | ||
886 | goto out_err; | ||
887 | } | ||
888 | |||
889 | /* Other attributes */ | ||
890 | ret = sysfs_create_files(gsmi_kobj, gsmi_attrs); | ||
891 | if (ret) { | ||
892 | printk(KERN_INFO "gsmi: Failed to add attrs"); | ||
893 | goto out_err; | ||
894 | } | ||
895 | |||
896 | if (register_efivars(&efivars, &efivar_ops, gsmi_kobj)) { | ||
897 | printk(KERN_INFO "gsmi: Failed to register efivars\n"); | ||
898 | goto out_err; | ||
899 | } | ||
900 | |||
901 | register_reboot_notifier(&gsmi_reboot_notifier); | ||
902 | register_die_notifier(&gsmi_die_notifier); | ||
903 | atomic_notifier_chain_register(&panic_notifier_list, | ||
904 | &gsmi_panic_notifier); | ||
905 | |||
906 | return 0; | ||
907 | |||
908 | out_err: | ||
909 | kobject_put(gsmi_kobj); | ||
910 | gsmi_buf_free(gsmi_dev.param_buf); | ||
911 | gsmi_buf_free(gsmi_dev.data_buf); | ||
912 | gsmi_buf_free(gsmi_dev.name_buf); | ||
913 | if (gsmi_dev.dma_pool) | ||
914 | dma_pool_destroy(gsmi_dev.dma_pool); | ||
915 | platform_device_unregister(gsmi_dev.pdev); | ||
916 | pr_info("gsmi: failed to load: %d\n", ret); | ||
917 | return ret; | ||
918 | } | ||
919 | |||
920 | static void __exit gsmi_exit(void) | ||
921 | { | ||
922 | unregister_reboot_notifier(&gsmi_reboot_notifier); | ||
923 | unregister_die_notifier(&gsmi_die_notifier); | ||
924 | atomic_notifier_chain_unregister(&panic_notifier_list, | ||
925 | &gsmi_panic_notifier); | ||
926 | unregister_efivars(&efivars); | ||
927 | |||
928 | kobject_put(gsmi_kobj); | ||
929 | gsmi_buf_free(gsmi_dev.param_buf); | ||
930 | gsmi_buf_free(gsmi_dev.data_buf); | ||
931 | gsmi_buf_free(gsmi_dev.name_buf); | ||
932 | dma_pool_destroy(gsmi_dev.dma_pool); | ||
933 | platform_device_unregister(gsmi_dev.pdev); | ||
934 | } | ||
935 | |||
936 | module_init(gsmi_init); | ||
937 | module_exit(gsmi_exit); | ||
938 | |||
939 | MODULE_AUTHOR("Google, Inc."); | ||
940 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c new file mode 100644 index 000000000000..2a90ba613613 --- /dev/null +++ b/drivers/firmware/google/memconsole.c | |||
@@ -0,0 +1,166 @@ | |||
1 | /* | ||
2 | * memconsole.c | ||
3 | * | ||
4 | * Infrastructure for importing the BIOS memory based console | ||
5 | * into the kernel log ringbuffer. | ||
6 | * | ||
7 | * Copyright 2010 Google Inc. All rights reserved. | ||
8 | */ | ||
9 | |||
10 | #include <linux/ctype.h> | ||
11 | #include <linux/init.h> | ||
12 | #include <linux/kernel.h> | ||
13 | #include <linux/string.h> | ||
14 | #include <linux/sysfs.h> | ||
15 | #include <linux/kobject.h> | ||
16 | #include <linux/module.h> | ||
17 | #include <linux/dmi.h> | ||
18 | #include <asm/bios_ebda.h> | ||
19 | |||
20 | #define BIOS_MEMCONSOLE_V1_MAGIC 0xDEADBABE | ||
21 | #define BIOS_MEMCONSOLE_V2_MAGIC (('M')|('C'<<8)|('O'<<16)|('N'<<24)) | ||
22 | |||
23 | struct biosmemcon_ebda { | ||
24 | u32 signature; | ||
25 | union { | ||
26 | struct { | ||
27 | u8 enabled; | ||
28 | u32 buffer_addr; | ||
29 | u16 start; | ||
30 | u16 end; | ||
31 | u16 num_chars; | ||
32 | u8 wrapped; | ||
33 | } __packed v1; | ||
34 | struct { | ||
35 | u32 buffer_addr; | ||
36 | /* Misdocumented as number of pages! */ | ||
37 | u16 num_bytes; | ||
38 | u16 start; | ||
39 | u16 end; | ||
40 | } __packed v2; | ||
41 | }; | ||
42 | } __packed; | ||
43 | |||
44 | static char *memconsole_baseaddr; | ||
45 | static size_t memconsole_length; | ||
46 | |||
47 | static ssize_t memconsole_read(struct file *filp, struct kobject *kobp, | ||
48 | struct bin_attribute *bin_attr, char *buf, | ||
49 | loff_t pos, size_t count) | ||
50 | { | ||
51 | return memory_read_from_buffer(buf, count, &pos, memconsole_baseaddr, | ||
52 | memconsole_length); | ||
53 | } | ||
54 | |||
55 | static struct bin_attribute memconsole_bin_attr = { | ||
56 | .attr = {.name = "log", .mode = 0444}, | ||
57 | .read = memconsole_read, | ||
58 | }; | ||
59 | |||
60 | |||
61 | static void found_v1_header(struct biosmemcon_ebda *hdr) | ||
62 | { | ||
63 | printk(KERN_INFO "BIOS console v1 EBDA structure found at %p\n", hdr); | ||
64 | printk(KERN_INFO "BIOS console buffer at 0x%.8x, " | ||
65 | "start = %d, end = %d, num = %d\n", | ||
66 | hdr->v1.buffer_addr, hdr->v1.start, | ||
67 | hdr->v1.end, hdr->v1.num_chars); | ||
68 | |||
69 | memconsole_length = hdr->v1.num_chars; | ||
70 | memconsole_baseaddr = phys_to_virt(hdr->v1.buffer_addr); | ||
71 | } | ||
72 | |||
73 | static void found_v2_header(struct biosmemcon_ebda *hdr) | ||
74 | { | ||
75 | printk(KERN_INFO "BIOS console v2 EBDA structure found at %p\n", hdr); | ||
76 | printk(KERN_INFO "BIOS console buffer at 0x%.8x, " | ||
77 | "start = %d, end = %d, num_bytes = %d\n", | ||
78 | hdr->v2.buffer_addr, hdr->v2.start, | ||
79 | hdr->v2.end, hdr->v2.num_bytes); | ||
80 | |||
81 | memconsole_length = hdr->v2.end - hdr->v2.start; | ||
82 | memconsole_baseaddr = phys_to_virt(hdr->v2.buffer_addr | ||
83 | + hdr->v2.start); | ||
84 | } | ||
85 | |||
86 | /* | ||
87 | * Search through the EBDA for the BIOS Memory Console, and | ||
88 | * set the global variables to point to it. Return true if found. | ||
89 | */ | ||
90 | static bool found_memconsole(void) | ||
91 | { | ||
92 | unsigned int address; | ||
93 | size_t length, cur; | ||
94 | |||
95 | address = get_bios_ebda(); | ||
96 | if (!address) { | ||
97 | printk(KERN_INFO "BIOS EBDA non-existent.\n"); | ||
98 | return false; | ||
99 | } | ||
100 | |||
101 | /* EBDA length is byte 0 of EBDA (in KB) */ | ||
102 | length = *(u8 *)phys_to_virt(address); | ||
103 | length <<= 10; /* convert to bytes */ | ||
104 | |||
105 | /* | ||
106 | * Search through EBDA for BIOS memory console structure | ||
107 | * note: signature is not necessarily dword-aligned | ||
108 | */ | ||
109 | for (cur = 0; cur < length; cur++) { | ||
110 | struct biosmemcon_ebda *hdr = phys_to_virt(address + cur); | ||
111 | |||
112 | /* memconsole v1 */ | ||
113 | if (hdr->signature == BIOS_MEMCONSOLE_V1_MAGIC) { | ||
114 | found_v1_header(hdr); | ||
115 | return true; | ||
116 | } | ||
117 | |||
118 | /* memconsole v2 */ | ||
119 | if (hdr->signature == BIOS_MEMCONSOLE_V2_MAGIC) { | ||
120 | found_v2_header(hdr); | ||
121 | return true; | ||
122 | } | ||
123 | } | ||
124 | |||
125 | printk(KERN_INFO "BIOS console EBDA structure not found!\n"); | ||
126 | return false; | ||
127 | } | ||
128 | |||
129 | static struct dmi_system_id memconsole_dmi_table[] __initdata = { | ||
130 | { | ||
131 | .ident = "Google Board", | ||
132 | .matches = { | ||
133 | DMI_MATCH(DMI_BOARD_VENDOR, "Google, Inc."), | ||
134 | }, | ||
135 | }, | ||
136 | {} | ||
137 | }; | ||
138 | MODULE_DEVICE_TABLE(dmi, memconsole_dmi_table); | ||
139 | |||
140 | static int __init memconsole_init(void) | ||
141 | { | ||
142 | int ret; | ||
143 | |||
144 | if (!dmi_check_system(memconsole_dmi_table)) | ||
145 | return -ENODEV; | ||
146 | |||
147 | if (!found_memconsole()) | ||
148 | return -ENODEV; | ||
149 | |||
150 | memconsole_bin_attr.size = memconsole_length; | ||
151 | |||
152 | ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr); | ||
153 | |||
154 | return ret; | ||
155 | } | ||
156 | |||
157 | static void __exit memconsole_exit(void) | ||
158 | { | ||
159 | sysfs_remove_bin_file(firmware_kobj, &memconsole_bin_attr); | ||
160 | } | ||
161 | |||
162 | module_init(memconsole_init); | ||
163 | module_exit(memconsole_exit); | ||
164 | |||
165 | MODULE_AUTHOR("Google, Inc."); | ||
166 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/firmware/iscsi_ibft_find.c b/drivers/firmware/iscsi_ibft_find.c index 2192456dfd68..f032e446fc11 100644 --- a/drivers/firmware/iscsi_ibft_find.c +++ b/drivers/firmware/iscsi_ibft_find.c | |||
@@ -42,7 +42,20 @@ | |||
42 | struct acpi_table_ibft *ibft_addr; | 42 | struct acpi_table_ibft *ibft_addr; |
43 | EXPORT_SYMBOL_GPL(ibft_addr); | 43 | EXPORT_SYMBOL_GPL(ibft_addr); |
44 | 44 | ||
45 | #define IBFT_SIGN "iBFT" | 45 | static const struct { |
46 | char *sign; | ||
47 | } ibft_signs[] = { | ||
48 | #ifdef CONFIG_ACPI | ||
49 | /* | ||
50 | * One spec says "IBFT", the other says "iBFT". We have to check | ||
51 | * for both. | ||
52 | */ | ||
53 | { ACPI_SIG_IBFT }, | ||
54 | #endif | ||
55 | { "iBFT" }, | ||
56 | { "BIFT" }, /* Broadcom iSCSI Offload */ | ||
57 | }; | ||
58 | |||
46 | #define IBFT_SIGN_LEN 4 | 59 | #define IBFT_SIGN_LEN 4 |
47 | #define IBFT_START 0x80000 /* 512kB */ | 60 | #define IBFT_START 0x80000 /* 512kB */ |
48 | #define IBFT_END 0x100000 /* 1MB */ | 61 | #define IBFT_END 0x100000 /* 1MB */ |
@@ -62,6 +75,7 @@ static int __init find_ibft_in_mem(void) | |||
62 | unsigned long pos; | 75 | unsigned long pos; |
63 | unsigned int len = 0; | 76 | unsigned int len = 0; |
64 | void *virt; | 77 | void *virt; |
78 | int i; | ||
65 | 79 | ||
66 | for (pos = IBFT_START; pos < IBFT_END; pos += 16) { | 80 | for (pos = IBFT_START; pos < IBFT_END; pos += 16) { |
67 | /* The table can't be inside the VGA BIOS reserved space, | 81 | /* The table can't be inside the VGA BIOS reserved space, |
@@ -69,18 +83,23 @@ static int __init find_ibft_in_mem(void) | |||
69 | if (pos == VGA_MEM) | 83 | if (pos == VGA_MEM) |
70 | pos += VGA_SIZE; | 84 | pos += VGA_SIZE; |
71 | virt = isa_bus_to_virt(pos); | 85 | virt = isa_bus_to_virt(pos); |
72 | if (memcmp(virt, IBFT_SIGN, IBFT_SIGN_LEN) == 0) { | 86 | |
73 | unsigned long *addr = | 87 | for (i = 0; i < ARRAY_SIZE(ibft_signs); i++) { |
74 | (unsigned long *)isa_bus_to_virt(pos + 4); | 88 | if (memcmp(virt, ibft_signs[i].sign, IBFT_SIGN_LEN) == |
75 | len = *addr; | 89 | 0) { |
76 | /* if the length of the table extends past 1M, | 90 | unsigned long *addr = |
77 | * the table cannot be valid. */ | 91 | (unsigned long *)isa_bus_to_virt(pos + 4); |
78 | if (pos + len <= (IBFT_END-1)) { | 92 | len = *addr; |
79 | ibft_addr = (struct acpi_table_ibft *)virt; | 93 | /* if the length of the table extends past 1M, |
80 | break; | 94 | * the table cannot be valid. */ |
95 | if (pos + len <= (IBFT_END-1)) { | ||
96 | ibft_addr = (struct acpi_table_ibft *)virt; | ||
97 | goto done; | ||
98 | } | ||
81 | } | 99 | } |
82 | } | 100 | } |
83 | } | 101 | } |
102 | done: | ||
84 | return len; | 103 | return len; |
85 | } | 104 | } |
86 | /* | 105 | /* |
@@ -89,18 +108,12 @@ static int __init find_ibft_in_mem(void) | |||
89 | */ | 108 | */ |
90 | unsigned long __init find_ibft_region(unsigned long *sizep) | 109 | unsigned long __init find_ibft_region(unsigned long *sizep) |
91 | { | 110 | { |
92 | 111 | int i; | |
93 | ibft_addr = NULL; | 112 | ibft_addr = NULL; |
94 | 113 | ||
95 | #ifdef CONFIG_ACPI | 114 | #ifdef CONFIG_ACPI |
96 | /* | 115 | for (i = 0; i < ARRAY_SIZE(ibft_signs) && !ibft_addr; i++) |
97 | * One spec says "IBFT", the other says "iBFT". We have to check | 116 | acpi_table_parse(ibft_signs[i].sign, acpi_find_ibft); |
98 | * for both. | ||
99 | */ | ||
100 | if (!ibft_addr) | ||
101 | acpi_table_parse(ACPI_SIG_IBFT, acpi_find_ibft); | ||
102 | if (!ibft_addr) | ||
103 | acpi_table_parse(IBFT_SIGN, acpi_find_ibft); | ||
104 | #endif /* CONFIG_ACPI */ | 117 | #endif /* CONFIG_ACPI */ |
105 | 118 | ||
106 | /* iBFT 1.03 section 1.4.3.1 mandates that UEFI machines will | 119 | /* iBFT 1.03 section 1.4.3.1 mandates that UEFI machines will |
diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c index 5ed9d25d021a..99dde874fbbd 100644 --- a/drivers/infiniband/core/cma.c +++ b/drivers/infiniband/core/cma.c | |||
@@ -148,6 +148,7 @@ struct rdma_id_private { | |||
148 | u32 qp_num; | 148 | u32 qp_num; |
149 | u8 srq; | 149 | u8 srq; |
150 | u8 tos; | 150 | u8 tos; |
151 | u8 reuseaddr; | ||
151 | }; | 152 | }; |
152 | 153 | ||
153 | struct cma_multicast { | 154 | struct cma_multicast { |
@@ -712,6 +713,21 @@ static inline int cma_any_addr(struct sockaddr *addr) | |||
712 | return cma_zero_addr(addr) || cma_loopback_addr(addr); | 713 | return cma_zero_addr(addr) || cma_loopback_addr(addr); |
713 | } | 714 | } |
714 | 715 | ||
716 | static int cma_addr_cmp(struct sockaddr *src, struct sockaddr *dst) | ||
717 | { | ||
718 | if (src->sa_family != dst->sa_family) | ||
719 | return -1; | ||
720 | |||
721 | switch (src->sa_family) { | ||
722 | case AF_INET: | ||
723 | return ((struct sockaddr_in *) src)->sin_addr.s_addr != | ||
724 | ((struct sockaddr_in *) dst)->sin_addr.s_addr; | ||
725 | default: | ||
726 | return ipv6_addr_cmp(&((struct sockaddr_in6 *) src)->sin6_addr, | ||
727 | &((struct sockaddr_in6 *) dst)->sin6_addr); | ||
728 | } | ||
729 | } | ||
730 | |||
715 | static inline __be16 cma_port(struct sockaddr *addr) | 731 | static inline __be16 cma_port(struct sockaddr *addr) |
716 | { | 732 | { |
717 | if (addr->sa_family == AF_INET) | 733 | if (addr->sa_family == AF_INET) |
@@ -1564,50 +1580,6 @@ static void cma_listen_on_all(struct rdma_id_private *id_priv) | |||
1564 | mutex_unlock(&lock); | 1580 | mutex_unlock(&lock); |
1565 | } | 1581 | } |
1566 | 1582 | ||
1567 | int rdma_listen(struct rdma_cm_id *id, int backlog) | ||
1568 | { | ||
1569 | struct rdma_id_private *id_priv; | ||
1570 | int ret; | ||
1571 | |||
1572 | id_priv = container_of(id, struct rdma_id_private, id); | ||
1573 | if (id_priv->state == CMA_IDLE) { | ||
1574 | ((struct sockaddr *) &id->route.addr.src_addr)->sa_family = AF_INET; | ||
1575 | ret = rdma_bind_addr(id, (struct sockaddr *) &id->route.addr.src_addr); | ||
1576 | if (ret) | ||
1577 | return ret; | ||
1578 | } | ||
1579 | |||
1580 | if (!cma_comp_exch(id_priv, CMA_ADDR_BOUND, CMA_LISTEN)) | ||
1581 | return -EINVAL; | ||
1582 | |||
1583 | id_priv->backlog = backlog; | ||
1584 | if (id->device) { | ||
1585 | switch (rdma_node_get_transport(id->device->node_type)) { | ||
1586 | case RDMA_TRANSPORT_IB: | ||
1587 | ret = cma_ib_listen(id_priv); | ||
1588 | if (ret) | ||
1589 | goto err; | ||
1590 | break; | ||
1591 | case RDMA_TRANSPORT_IWARP: | ||
1592 | ret = cma_iw_listen(id_priv, backlog); | ||
1593 | if (ret) | ||
1594 | goto err; | ||
1595 | break; | ||
1596 | default: | ||
1597 | ret = -ENOSYS; | ||
1598 | goto err; | ||
1599 | } | ||
1600 | } else | ||
1601 | cma_listen_on_all(id_priv); | ||
1602 | |||
1603 | return 0; | ||
1604 | err: | ||
1605 | id_priv->backlog = 0; | ||
1606 | cma_comp_exch(id_priv, CMA_LISTEN, CMA_ADDR_BOUND); | ||
1607 | return ret; | ||
1608 | } | ||
1609 | EXPORT_SYMBOL(rdma_listen); | ||
1610 | |||
1611 | void rdma_set_service_type(struct rdma_cm_id *id, int tos) | 1583 | void rdma_set_service_type(struct rdma_cm_id *id, int tos) |
1612 | { | 1584 | { |
1613 | struct rdma_id_private *id_priv; | 1585 | struct rdma_id_private *id_priv; |
@@ -2090,6 +2062,25 @@ err: | |||
2090 | } | 2062 | } |
2091 | EXPORT_SYMBOL(rdma_resolve_addr); | 2063 | EXPORT_SYMBOL(rdma_resolve_addr); |
2092 | 2064 | ||
2065 | int rdma_set_reuseaddr(struct rdma_cm_id *id, int reuse) | ||
2066 | { | ||
2067 | struct rdma_id_private *id_priv; | ||
2068 | unsigned long flags; | ||
2069 | int ret; | ||
2070 | |||
2071 | id_priv = container_of(id, struct rdma_id_private, id); | ||
2072 | spin_lock_irqsave(&id_priv->lock, flags); | ||
2073 | if (id_priv->state == CMA_IDLE) { | ||
2074 | id_priv->reuseaddr = reuse; | ||
2075 | ret = 0; | ||
2076 | } else { | ||
2077 | ret = -EINVAL; | ||
2078 | } | ||
2079 | spin_unlock_irqrestore(&id_priv->lock, flags); | ||
2080 | return ret; | ||
2081 | } | ||
2082 | EXPORT_SYMBOL(rdma_set_reuseaddr); | ||
2083 | |||
2093 | static void cma_bind_port(struct rdma_bind_list *bind_list, | 2084 | static void cma_bind_port(struct rdma_bind_list *bind_list, |
2094 | struct rdma_id_private *id_priv) | 2085 | struct rdma_id_private *id_priv) |
2095 | { | 2086 | { |
@@ -2165,41 +2156,71 @@ retry: | |||
2165 | return -EADDRNOTAVAIL; | 2156 | return -EADDRNOTAVAIL; |
2166 | } | 2157 | } |
2167 | 2158 | ||
2168 | static int cma_use_port(struct idr *ps, struct rdma_id_private *id_priv) | 2159 | /* |
2160 | * Check that the requested port is available. This is called when trying to | ||
2161 | * bind to a specific port, or when trying to listen on a bound port. In | ||
2162 | * the latter case, the provided id_priv may already be on the bind_list, but | ||
2163 | * we still need to check that it's okay to start listening. | ||
2164 | */ | ||
2165 | static int cma_check_port(struct rdma_bind_list *bind_list, | ||
2166 | struct rdma_id_private *id_priv, uint8_t reuseaddr) | ||
2169 | { | 2167 | { |
2170 | struct rdma_id_private *cur_id; | 2168 | struct rdma_id_private *cur_id; |
2171 | struct sockaddr_in *sin, *cur_sin; | 2169 | struct sockaddr *addr, *cur_addr; |
2172 | struct rdma_bind_list *bind_list; | ||
2173 | struct hlist_node *node; | 2170 | struct hlist_node *node; |
2171 | |||
2172 | addr = (struct sockaddr *) &id_priv->id.route.addr.src_addr; | ||
2173 | if (cma_any_addr(addr) && !reuseaddr) | ||
2174 | return -EADDRNOTAVAIL; | ||
2175 | |||
2176 | hlist_for_each_entry(cur_id, node, &bind_list->owners, node) { | ||
2177 | if (id_priv == cur_id) | ||
2178 | continue; | ||
2179 | |||
2180 | if ((cur_id->state == CMA_LISTEN) || | ||
2181 | !reuseaddr || !cur_id->reuseaddr) { | ||
2182 | cur_addr = (struct sockaddr *) &cur_id->id.route.addr.src_addr; | ||
2183 | if (cma_any_addr(cur_addr)) | ||
2184 | return -EADDRNOTAVAIL; | ||
2185 | |||
2186 | if (!cma_addr_cmp(addr, cur_addr)) | ||
2187 | return -EADDRINUSE; | ||
2188 | } | ||
2189 | } | ||
2190 | return 0; | ||
2191 | } | ||
2192 | |||
2193 | static int cma_use_port(struct idr *ps, struct rdma_id_private *id_priv) | ||
2194 | { | ||
2195 | struct rdma_bind_list *bind_list; | ||
2174 | unsigned short snum; | 2196 | unsigned short snum; |
2197 | int ret; | ||
2175 | 2198 | ||
2176 | sin = (struct sockaddr_in *) &id_priv->id.route.addr.src_addr; | 2199 | snum = ntohs(cma_port((struct sockaddr *) &id_priv->id.route.addr.src_addr)); |
2177 | snum = ntohs(sin->sin_port); | ||
2178 | if (snum < PROT_SOCK && !capable(CAP_NET_BIND_SERVICE)) | 2200 | if (snum < PROT_SOCK && !capable(CAP_NET_BIND_SERVICE)) |
2179 | return -EACCES; | 2201 | return -EACCES; |
2180 | 2202 | ||
2181 | bind_list = idr_find(ps, snum); | 2203 | bind_list = idr_find(ps, snum); |
2182 | if (!bind_list) | 2204 | if (!bind_list) { |
2183 | return cma_alloc_port(ps, id_priv, snum); | 2205 | ret = cma_alloc_port(ps, id_priv, snum); |
2184 | 2206 | } else { | |
2185 | /* | 2207 | ret = cma_check_port(bind_list, id_priv, id_priv->reuseaddr); |
2186 | * We don't support binding to any address if anyone is bound to | 2208 | if (!ret) |
2187 | * a specific address on the same port. | 2209 | cma_bind_port(bind_list, id_priv); |
2188 | */ | ||
2189 | if (cma_any_addr((struct sockaddr *) &id_priv->id.route.addr.src_addr)) | ||
2190 | return -EADDRNOTAVAIL; | ||
2191 | |||
2192 | hlist_for_each_entry(cur_id, node, &bind_list->owners, node) { | ||
2193 | if (cma_any_addr((struct sockaddr *) &cur_id->id.route.addr.src_addr)) | ||
2194 | return -EADDRNOTAVAIL; | ||
2195 | |||
2196 | cur_sin = (struct sockaddr_in *) &cur_id->id.route.addr.src_addr; | ||
2197 | if (sin->sin_addr.s_addr == cur_sin->sin_addr.s_addr) | ||
2198 | return -EADDRINUSE; | ||
2199 | } | 2210 | } |
2211 | return ret; | ||
2212 | } | ||
2200 | 2213 | ||
2201 | cma_bind_port(bind_list, id_priv); | 2214 | static int cma_bind_listen(struct rdma_id_private *id_priv) |
2202 | return 0; | 2215 | { |
2216 | struct rdma_bind_list *bind_list = id_priv->bind_list; | ||
2217 | int ret = 0; | ||
2218 | |||
2219 | mutex_lock(&lock); | ||
2220 | if (bind_list->owners.first->next) | ||
2221 | ret = cma_check_port(bind_list, id_priv, 0); | ||
2222 | mutex_unlock(&lock); | ||
2223 | return ret; | ||
2203 | } | 2224 | } |
2204 | 2225 | ||
2205 | static int cma_get_port(struct rdma_id_private *id_priv) | 2226 | static int cma_get_port(struct rdma_id_private *id_priv) |
@@ -2253,6 +2274,56 @@ static int cma_check_linklocal(struct rdma_dev_addr *dev_addr, | |||
2253 | return 0; | 2274 | return 0; |
2254 | } | 2275 | } |
2255 | 2276 | ||
2277 | int rdma_listen(struct rdma_cm_id *id, int backlog) | ||
2278 | { | ||
2279 | struct rdma_id_private *id_priv; | ||
2280 | int ret; | ||
2281 | |||
2282 | id_priv = container_of(id, struct rdma_id_private, id); | ||
2283 | if (id_priv->state == CMA_IDLE) { | ||
2284 | ((struct sockaddr *) &id->route.addr.src_addr)->sa_family = AF_INET; | ||
2285 | ret = rdma_bind_addr(id, (struct sockaddr *) &id->route.addr.src_addr); | ||
2286 | if (ret) | ||
2287 | return ret; | ||
2288 | } | ||
2289 | |||
2290 | if (!cma_comp_exch(id_priv, CMA_ADDR_BOUND, CMA_LISTEN)) | ||
2291 | return -EINVAL; | ||
2292 | |||
2293 | if (id_priv->reuseaddr) { | ||
2294 | ret = cma_bind_listen(id_priv); | ||
2295 | if (ret) | ||
2296 | goto err; | ||
2297 | } | ||
2298 | |||
2299 | id_priv->backlog = backlog; | ||
2300 | if (id->device) { | ||
2301 | switch (rdma_node_get_transport(id->device->node_type)) { | ||
2302 | case RDMA_TRANSPORT_IB: | ||
2303 | ret = cma_ib_listen(id_priv); | ||
2304 | if (ret) | ||
2305 | goto err; | ||
2306 | break; | ||
2307 | case RDMA_TRANSPORT_IWARP: | ||
2308 | ret = cma_iw_listen(id_priv, backlog); | ||
2309 | if (ret) | ||
2310 | goto err; | ||
2311 | break; | ||
2312 | default: | ||
2313 | ret = -ENOSYS; | ||
2314 | goto err; | ||
2315 | } | ||
2316 | } else | ||
2317 | cma_listen_on_all(id_priv); | ||
2318 | |||
2319 | return 0; | ||
2320 | err: | ||
2321 | id_priv->backlog = 0; | ||
2322 | cma_comp_exch(id_priv, CMA_LISTEN, CMA_ADDR_BOUND); | ||
2323 | return ret; | ||
2324 | } | ||
2325 | EXPORT_SYMBOL(rdma_listen); | ||
2326 | |||
2256 | int rdma_bind_addr(struct rdma_cm_id *id, struct sockaddr *addr) | 2327 | int rdma_bind_addr(struct rdma_cm_id *id, struct sockaddr *addr) |
2257 | { | 2328 | { |
2258 | struct rdma_id_private *id_priv; | 2329 | struct rdma_id_private *id_priv; |
diff --git a/drivers/infiniband/core/iwcm.c b/drivers/infiniband/core/iwcm.c index 2a1e9ae134b4..a9c042345c6f 100644 --- a/drivers/infiniband/core/iwcm.c +++ b/drivers/infiniband/core/iwcm.c | |||
@@ -725,7 +725,7 @@ static int cm_conn_rep_handler(struct iwcm_id_private *cm_id_priv, | |||
725 | */ | 725 | */ |
726 | clear_bit(IWCM_F_CONNECT_WAIT, &cm_id_priv->flags); | 726 | clear_bit(IWCM_F_CONNECT_WAIT, &cm_id_priv->flags); |
727 | BUG_ON(cm_id_priv->state != IW_CM_STATE_CONN_SENT); | 727 | BUG_ON(cm_id_priv->state != IW_CM_STATE_CONN_SENT); |
728 | if (iw_event->status == IW_CM_EVENT_STATUS_ACCEPTED) { | 728 | if (iw_event->status == 0) { |
729 | cm_id_priv->id.local_addr = iw_event->local_addr; | 729 | cm_id_priv->id.local_addr = iw_event->local_addr; |
730 | cm_id_priv->id.remote_addr = iw_event->remote_addr; | 730 | cm_id_priv->id.remote_addr = iw_event->remote_addr; |
731 | cm_id_priv->state = IW_CM_STATE_ESTABLISHED; | 731 | cm_id_priv->state = IW_CM_STATE_ESTABLISHED; |
diff --git a/drivers/infiniband/core/ucma.c b/drivers/infiniband/core/ucma.c index ec1e9da1488b..b3fa798525b2 100644 --- a/drivers/infiniband/core/ucma.c +++ b/drivers/infiniband/core/ucma.c | |||
@@ -883,6 +883,13 @@ static int ucma_set_option_id(struct ucma_context *ctx, int optname, | |||
883 | } | 883 | } |
884 | rdma_set_service_type(ctx->cm_id, *((u8 *) optval)); | 884 | rdma_set_service_type(ctx->cm_id, *((u8 *) optval)); |
885 | break; | 885 | break; |
886 | case RDMA_OPTION_ID_REUSEADDR: | ||
887 | if (optlen != sizeof(int)) { | ||
888 | ret = -EINVAL; | ||
889 | break; | ||
890 | } | ||
891 | ret = rdma_set_reuseaddr(ctx->cm_id, *((int *) optval) ? 1 : 0); | ||
892 | break; | ||
886 | default: | 893 | default: |
887 | ret = -ENOSYS; | 894 | ret = -ENOSYS; |
888 | } | 895 | } |
diff --git a/drivers/infiniband/hw/cxgb4/cm.c b/drivers/infiniband/hw/cxgb4/cm.c index 9d8dcfab2b38..d7ee70fc9173 100644 --- a/drivers/infiniband/hw/cxgb4/cm.c +++ b/drivers/infiniband/hw/cxgb4/cm.c | |||
@@ -1198,9 +1198,7 @@ static int pass_open_rpl(struct c4iw_dev *dev, struct sk_buff *skb) | |||
1198 | } | 1198 | } |
1199 | PDBG("%s ep %p status %d error %d\n", __func__, ep, | 1199 | PDBG("%s ep %p status %d error %d\n", __func__, ep, |
1200 | rpl->status, status2errno(rpl->status)); | 1200 | rpl->status, status2errno(rpl->status)); |
1201 | ep->com.wr_wait.ret = status2errno(rpl->status); | 1201 | c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status)); |
1202 | ep->com.wr_wait.done = 1; | ||
1203 | wake_up(&ep->com.wr_wait.wait); | ||
1204 | 1202 | ||
1205 | return 0; | 1203 | return 0; |
1206 | } | 1204 | } |
@@ -1234,9 +1232,7 @@ static int close_listsrv_rpl(struct c4iw_dev *dev, struct sk_buff *skb) | |||
1234 | struct c4iw_listen_ep *ep = lookup_stid(t, stid); | 1232 | struct c4iw_listen_ep *ep = lookup_stid(t, stid); |
1235 | 1233 | ||
1236 | PDBG("%s ep %p\n", __func__, ep); | 1234 | PDBG("%s ep %p\n", __func__, ep); |
1237 | ep->com.wr_wait.ret = status2errno(rpl->status); | 1235 | c4iw_wake_up(&ep->com.wr_wait, status2errno(rpl->status)); |
1238 | ep->com.wr_wait.done = 1; | ||
1239 | wake_up(&ep->com.wr_wait.wait); | ||
1240 | return 0; | 1236 | return 0; |
1241 | } | 1237 | } |
1242 | 1238 | ||
@@ -1466,7 +1462,7 @@ static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb) | |||
1466 | struct c4iw_qp_attributes attrs; | 1462 | struct c4iw_qp_attributes attrs; |
1467 | int disconnect = 1; | 1463 | int disconnect = 1; |
1468 | int release = 0; | 1464 | int release = 0; |
1469 | int closing = 0; | 1465 | int abort = 0; |
1470 | struct tid_info *t = dev->rdev.lldi.tids; | 1466 | struct tid_info *t = dev->rdev.lldi.tids; |
1471 | unsigned int tid = GET_TID(hdr); | 1467 | unsigned int tid = GET_TID(hdr); |
1472 | 1468 | ||
@@ -1492,23 +1488,22 @@ static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb) | |||
1492 | * in rdma connection migration (see c4iw_accept_cr()). | 1488 | * in rdma connection migration (see c4iw_accept_cr()). |
1493 | */ | 1489 | */ |
1494 | __state_set(&ep->com, CLOSING); | 1490 | __state_set(&ep->com, CLOSING); |
1495 | ep->com.wr_wait.done = 1; | ||
1496 | ep->com.wr_wait.ret = -ECONNRESET; | ||
1497 | PDBG("waking up ep %p tid %u\n", ep, ep->hwtid); | 1491 | PDBG("waking up ep %p tid %u\n", ep, ep->hwtid); |
1498 | wake_up(&ep->com.wr_wait.wait); | 1492 | c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET); |
1499 | break; | 1493 | break; |
1500 | case MPA_REP_SENT: | 1494 | case MPA_REP_SENT: |
1501 | __state_set(&ep->com, CLOSING); | 1495 | __state_set(&ep->com, CLOSING); |
1502 | ep->com.wr_wait.done = 1; | ||
1503 | ep->com.wr_wait.ret = -ECONNRESET; | ||
1504 | PDBG("waking up ep %p tid %u\n", ep, ep->hwtid); | 1496 | PDBG("waking up ep %p tid %u\n", ep, ep->hwtid); |
1505 | wake_up(&ep->com.wr_wait.wait); | 1497 | c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET); |
1506 | break; | 1498 | break; |
1507 | case FPDU_MODE: | 1499 | case FPDU_MODE: |
1508 | start_ep_timer(ep); | 1500 | start_ep_timer(ep); |
1509 | __state_set(&ep->com, CLOSING); | 1501 | __state_set(&ep->com, CLOSING); |
1510 | closing = 1; | 1502 | attrs.next_state = C4IW_QP_STATE_CLOSING; |
1503 | abort = c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp, | ||
1504 | C4IW_QP_ATTR_NEXT_STATE, &attrs, 1); | ||
1511 | peer_close_upcall(ep); | 1505 | peer_close_upcall(ep); |
1506 | disconnect = 1; | ||
1512 | break; | 1507 | break; |
1513 | case ABORTING: | 1508 | case ABORTING: |
1514 | disconnect = 0; | 1509 | disconnect = 0; |
@@ -1536,11 +1531,6 @@ static int peer_close(struct c4iw_dev *dev, struct sk_buff *skb) | |||
1536 | BUG_ON(1); | 1531 | BUG_ON(1); |
1537 | } | 1532 | } |
1538 | mutex_unlock(&ep->com.mutex); | 1533 | mutex_unlock(&ep->com.mutex); |
1539 | if (closing) { | ||
1540 | attrs.next_state = C4IW_QP_STATE_CLOSING; | ||
1541 | c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp, | ||
1542 | C4IW_QP_ATTR_NEXT_STATE, &attrs, 1); | ||
1543 | } | ||
1544 | if (disconnect) | 1534 | if (disconnect) |
1545 | c4iw_ep_disconnect(ep, 0, GFP_KERNEL); | 1535 | c4iw_ep_disconnect(ep, 0, GFP_KERNEL); |
1546 | if (release) | 1536 | if (release) |
@@ -1581,9 +1571,7 @@ static int peer_abort(struct c4iw_dev *dev, struct sk_buff *skb) | |||
1581 | /* | 1571 | /* |
1582 | * Wake up any threads in rdma_init() or rdma_fini(). | 1572 | * Wake up any threads in rdma_init() or rdma_fini(). |
1583 | */ | 1573 | */ |
1584 | ep->com.wr_wait.done = 1; | 1574 | c4iw_wake_up(&ep->com.wr_wait, -ECONNRESET); |
1585 | ep->com.wr_wait.ret = -ECONNRESET; | ||
1586 | wake_up(&ep->com.wr_wait.wait); | ||
1587 | 1575 | ||
1588 | mutex_lock(&ep->com.mutex); | 1576 | mutex_lock(&ep->com.mutex); |
1589 | switch (ep->com.state) { | 1577 | switch (ep->com.state) { |
@@ -1710,14 +1698,14 @@ static int terminate(struct c4iw_dev *dev, struct sk_buff *skb) | |||
1710 | ep = lookup_tid(t, tid); | 1698 | ep = lookup_tid(t, tid); |
1711 | BUG_ON(!ep); | 1699 | BUG_ON(!ep); |
1712 | 1700 | ||
1713 | if (ep->com.qp) { | 1701 | if (ep && ep->com.qp) { |
1714 | printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid, | 1702 | printk(KERN_WARNING MOD "TERM received tid %u qpid %u\n", tid, |
1715 | ep->com.qp->wq.sq.qid); | 1703 | ep->com.qp->wq.sq.qid); |
1716 | attrs.next_state = C4IW_QP_STATE_TERMINATE; | 1704 | attrs.next_state = C4IW_QP_STATE_TERMINATE; |
1717 | c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp, | 1705 | c4iw_modify_qp(ep->com.qp->rhp, ep->com.qp, |
1718 | C4IW_QP_ATTR_NEXT_STATE, &attrs, 1); | 1706 | C4IW_QP_ATTR_NEXT_STATE, &attrs, 1); |
1719 | } else | 1707 | } else |
1720 | printk(KERN_WARNING MOD "TERM received tid %u no qp\n", tid); | 1708 | printk(KERN_WARNING MOD "TERM received tid %u no ep/qp\n", tid); |
1721 | 1709 | ||
1722 | return 0; | 1710 | return 0; |
1723 | } | 1711 | } |
@@ -2296,14 +2284,8 @@ static int fw6_msg(struct c4iw_dev *dev, struct sk_buff *skb) | |||
2296 | ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff); | 2284 | ret = (int)((be64_to_cpu(rpl->data[0]) >> 8) & 0xff); |
2297 | wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1]; | 2285 | wr_waitp = (struct c4iw_wr_wait *)(__force unsigned long) rpl->data[1]; |
2298 | PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret); | 2286 | PDBG("%s wr_waitp %p ret %u\n", __func__, wr_waitp, ret); |
2299 | if (wr_waitp) { | 2287 | if (wr_waitp) |
2300 | if (ret) | 2288 | c4iw_wake_up(wr_waitp, ret ? -ret : 0); |
2301 | wr_waitp->ret = -ret; | ||
2302 | else | ||
2303 | wr_waitp->ret = 0; | ||
2304 | wr_waitp->done = 1; | ||
2305 | wake_up(&wr_waitp->wait); | ||
2306 | } | ||
2307 | kfree_skb(skb); | 2289 | kfree_skb(skb); |
2308 | break; | 2290 | break; |
2309 | case 2: | 2291 | case 2: |
diff --git a/drivers/infiniband/hw/cxgb4/device.c b/drivers/infiniband/hw/cxgb4/device.c index e29172c2afcb..40a13cc633a3 100644 --- a/drivers/infiniband/hw/cxgb4/device.c +++ b/drivers/infiniband/hw/cxgb4/device.c | |||
@@ -44,7 +44,7 @@ MODULE_DESCRIPTION("Chelsio T4 RDMA Driver"); | |||
44 | MODULE_LICENSE("Dual BSD/GPL"); | 44 | MODULE_LICENSE("Dual BSD/GPL"); |
45 | MODULE_VERSION(DRV_VERSION); | 45 | MODULE_VERSION(DRV_VERSION); |
46 | 46 | ||
47 | static LIST_HEAD(dev_list); | 47 | static LIST_HEAD(uld_ctx_list); |
48 | static DEFINE_MUTEX(dev_mutex); | 48 | static DEFINE_MUTEX(dev_mutex); |
49 | 49 | ||
50 | static struct dentry *c4iw_debugfs_root; | 50 | static struct dentry *c4iw_debugfs_root; |
@@ -370,18 +370,23 @@ static void c4iw_rdev_close(struct c4iw_rdev *rdev) | |||
370 | c4iw_destroy_resource(&rdev->resource); | 370 | c4iw_destroy_resource(&rdev->resource); |
371 | } | 371 | } |
372 | 372 | ||
373 | static void c4iw_remove(struct c4iw_dev *dev) | 373 | struct uld_ctx { |
374 | struct list_head entry; | ||
375 | struct cxgb4_lld_info lldi; | ||
376 | struct c4iw_dev *dev; | ||
377 | }; | ||
378 | |||
379 | static void c4iw_remove(struct uld_ctx *ctx) | ||
374 | { | 380 | { |
375 | PDBG("%s c4iw_dev %p\n", __func__, dev); | 381 | PDBG("%s c4iw_dev %p\n", __func__, ctx->dev); |
376 | list_del(&dev->entry); | 382 | c4iw_unregister_device(ctx->dev); |
377 | if (dev->registered) | 383 | c4iw_rdev_close(&ctx->dev->rdev); |
378 | c4iw_unregister_device(dev); | 384 | idr_destroy(&ctx->dev->cqidr); |
379 | c4iw_rdev_close(&dev->rdev); | 385 | idr_destroy(&ctx->dev->qpidr); |
380 | idr_destroy(&dev->cqidr); | 386 | idr_destroy(&ctx->dev->mmidr); |
381 | idr_destroy(&dev->qpidr); | 387 | iounmap(ctx->dev->rdev.oc_mw_kva); |
382 | idr_destroy(&dev->mmidr); | 388 | ib_dealloc_device(&ctx->dev->ibdev); |
383 | iounmap(dev->rdev.oc_mw_kva); | 389 | ctx->dev = NULL; |
384 | ib_dealloc_device(&dev->ibdev); | ||
385 | } | 390 | } |
386 | 391 | ||
387 | static struct c4iw_dev *c4iw_alloc(const struct cxgb4_lld_info *infop) | 392 | static struct c4iw_dev *c4iw_alloc(const struct cxgb4_lld_info *infop) |
@@ -392,7 +397,7 @@ static struct c4iw_dev *c4iw_alloc(const struct cxgb4_lld_info *infop) | |||
392 | devp = (struct c4iw_dev *)ib_alloc_device(sizeof(*devp)); | 397 | devp = (struct c4iw_dev *)ib_alloc_device(sizeof(*devp)); |
393 | if (!devp) { | 398 | if (!devp) { |
394 | printk(KERN_ERR MOD "Cannot allocate ib device\n"); | 399 | printk(KERN_ERR MOD "Cannot allocate ib device\n"); |
395 | return NULL; | 400 | return ERR_PTR(-ENOMEM); |
396 | } | 401 | } |
397 | devp->rdev.lldi = *infop; | 402 | devp->rdev.lldi = *infop; |
398 | 403 | ||
@@ -402,27 +407,23 @@ static struct c4iw_dev *c4iw_alloc(const struct cxgb4_lld_info *infop) | |||
402 | devp->rdev.oc_mw_kva = ioremap_wc(devp->rdev.oc_mw_pa, | 407 | devp->rdev.oc_mw_kva = ioremap_wc(devp->rdev.oc_mw_pa, |
403 | devp->rdev.lldi.vr->ocq.size); | 408 | devp->rdev.lldi.vr->ocq.size); |
404 | 409 | ||
405 | printk(KERN_INFO MOD "ocq memory: " | 410 | PDBG(KERN_INFO MOD "ocq memory: " |
406 | "hw_start 0x%x size %u mw_pa 0x%lx mw_kva %p\n", | 411 | "hw_start 0x%x size %u mw_pa 0x%lx mw_kva %p\n", |
407 | devp->rdev.lldi.vr->ocq.start, devp->rdev.lldi.vr->ocq.size, | 412 | devp->rdev.lldi.vr->ocq.start, devp->rdev.lldi.vr->ocq.size, |
408 | devp->rdev.oc_mw_pa, devp->rdev.oc_mw_kva); | 413 | devp->rdev.oc_mw_pa, devp->rdev.oc_mw_kva); |
409 | 414 | ||
410 | mutex_lock(&dev_mutex); | ||
411 | |||
412 | ret = c4iw_rdev_open(&devp->rdev); | 415 | ret = c4iw_rdev_open(&devp->rdev); |
413 | if (ret) { | 416 | if (ret) { |
414 | mutex_unlock(&dev_mutex); | 417 | mutex_unlock(&dev_mutex); |
415 | printk(KERN_ERR MOD "Unable to open CXIO rdev err %d\n", ret); | 418 | printk(KERN_ERR MOD "Unable to open CXIO rdev err %d\n", ret); |
416 | ib_dealloc_device(&devp->ibdev); | 419 | ib_dealloc_device(&devp->ibdev); |
417 | return NULL; | 420 | return ERR_PTR(ret); |
418 | } | 421 | } |
419 | 422 | ||
420 | idr_init(&devp->cqidr); | 423 | idr_init(&devp->cqidr); |
421 | idr_init(&devp->qpidr); | 424 | idr_init(&devp->qpidr); |
422 | idr_init(&devp->mmidr); | 425 | idr_init(&devp->mmidr); |
423 | spin_lock_init(&devp->lock); | 426 | spin_lock_init(&devp->lock); |
424 | list_add_tail(&devp->entry, &dev_list); | ||
425 | mutex_unlock(&dev_mutex); | ||
426 | 427 | ||
427 | if (c4iw_debugfs_root) { | 428 | if (c4iw_debugfs_root) { |
428 | devp->debugfs_root = debugfs_create_dir( | 429 | devp->debugfs_root = debugfs_create_dir( |
@@ -435,7 +436,7 @@ static struct c4iw_dev *c4iw_alloc(const struct cxgb4_lld_info *infop) | |||
435 | 436 | ||
436 | static void *c4iw_uld_add(const struct cxgb4_lld_info *infop) | 437 | static void *c4iw_uld_add(const struct cxgb4_lld_info *infop) |
437 | { | 438 | { |
438 | struct c4iw_dev *dev; | 439 | struct uld_ctx *ctx; |
439 | static int vers_printed; | 440 | static int vers_printed; |
440 | int i; | 441 | int i; |
441 | 442 | ||
@@ -443,25 +444,33 @@ static void *c4iw_uld_add(const struct cxgb4_lld_info *infop) | |||
443 | printk(KERN_INFO MOD "Chelsio T4 RDMA Driver - version %s\n", | 444 | printk(KERN_INFO MOD "Chelsio T4 RDMA Driver - version %s\n", |
444 | DRV_VERSION); | 445 | DRV_VERSION); |
445 | 446 | ||
446 | dev = c4iw_alloc(infop); | 447 | ctx = kzalloc(sizeof *ctx, GFP_KERNEL); |
447 | if (!dev) | 448 | if (!ctx) { |
449 | ctx = ERR_PTR(-ENOMEM); | ||
448 | goto out; | 450 | goto out; |
451 | } | ||
452 | ctx->lldi = *infop; | ||
449 | 453 | ||
450 | PDBG("%s found device %s nchan %u nrxq %u ntxq %u nports %u\n", | 454 | PDBG("%s found device %s nchan %u nrxq %u ntxq %u nports %u\n", |
451 | __func__, pci_name(dev->rdev.lldi.pdev), | 455 | __func__, pci_name(ctx->lldi.pdev), |
452 | dev->rdev.lldi.nchan, dev->rdev.lldi.nrxq, | 456 | ctx->lldi.nchan, ctx->lldi.nrxq, |
453 | dev->rdev.lldi.ntxq, dev->rdev.lldi.nports); | 457 | ctx->lldi.ntxq, ctx->lldi.nports); |
458 | |||
459 | mutex_lock(&dev_mutex); | ||
460 | list_add_tail(&ctx->entry, &uld_ctx_list); | ||
461 | mutex_unlock(&dev_mutex); | ||
454 | 462 | ||
455 | for (i = 0; i < dev->rdev.lldi.nrxq; i++) | 463 | for (i = 0; i < ctx->lldi.nrxq; i++) |
456 | PDBG("rxqid[%u] %u\n", i, dev->rdev.lldi.rxq_ids[i]); | 464 | PDBG("rxqid[%u] %u\n", i, ctx->lldi.rxq_ids[i]); |
457 | out: | 465 | out: |
458 | return dev; | 466 | return ctx; |
459 | } | 467 | } |
460 | 468 | ||
461 | static int c4iw_uld_rx_handler(void *handle, const __be64 *rsp, | 469 | static int c4iw_uld_rx_handler(void *handle, const __be64 *rsp, |
462 | const struct pkt_gl *gl) | 470 | const struct pkt_gl *gl) |
463 | { | 471 | { |
464 | struct c4iw_dev *dev = handle; | 472 | struct uld_ctx *ctx = handle; |
473 | struct c4iw_dev *dev = ctx->dev; | ||
465 | struct sk_buff *skb; | 474 | struct sk_buff *skb; |
466 | const struct cpl_act_establish *rpl; | 475 | const struct cpl_act_establish *rpl; |
467 | unsigned int opcode; | 476 | unsigned int opcode; |
@@ -503,47 +512,49 @@ nomem: | |||
503 | 512 | ||
504 | static int c4iw_uld_state_change(void *handle, enum cxgb4_state new_state) | 513 | static int c4iw_uld_state_change(void *handle, enum cxgb4_state new_state) |
505 | { | 514 | { |
506 | struct c4iw_dev *dev = handle; | 515 | struct uld_ctx *ctx = handle; |
507 | 516 | ||
508 | PDBG("%s new_state %u\n", __func__, new_state); | 517 | PDBG("%s new_state %u\n", __func__, new_state); |
509 | switch (new_state) { | 518 | switch (new_state) { |
510 | case CXGB4_STATE_UP: | 519 | case CXGB4_STATE_UP: |
511 | printk(KERN_INFO MOD "%s: Up\n", pci_name(dev->rdev.lldi.pdev)); | 520 | printk(KERN_INFO MOD "%s: Up\n", pci_name(ctx->lldi.pdev)); |
512 | if (!dev->registered) { | 521 | if (!ctx->dev) { |
513 | int ret; | 522 | int ret = 0; |
514 | ret = c4iw_register_device(dev); | 523 | |
515 | if (ret) | 524 | ctx->dev = c4iw_alloc(&ctx->lldi); |
525 | if (!IS_ERR(ctx->dev)) | ||
526 | ret = c4iw_register_device(ctx->dev); | ||
527 | if (IS_ERR(ctx->dev) || ret) | ||
516 | printk(KERN_ERR MOD | 528 | printk(KERN_ERR MOD |
517 | "%s: RDMA registration failed: %d\n", | 529 | "%s: RDMA registration failed: %d\n", |
518 | pci_name(dev->rdev.lldi.pdev), ret); | 530 | pci_name(ctx->lldi.pdev), ret); |
519 | } | 531 | } |
520 | break; | 532 | break; |
521 | case CXGB4_STATE_DOWN: | 533 | case CXGB4_STATE_DOWN: |
522 | printk(KERN_INFO MOD "%s: Down\n", | 534 | printk(KERN_INFO MOD "%s: Down\n", |
523 | pci_name(dev->rdev.lldi.pdev)); | 535 | pci_name(ctx->lldi.pdev)); |
524 | if (dev->registered) | 536 | if (ctx->dev) |
525 | c4iw_unregister_device(dev); | 537 | c4iw_remove(ctx); |
526 | break; | 538 | break; |
527 | case CXGB4_STATE_START_RECOVERY: | 539 | case CXGB4_STATE_START_RECOVERY: |
528 | printk(KERN_INFO MOD "%s: Fatal Error\n", | 540 | printk(KERN_INFO MOD "%s: Fatal Error\n", |
529 | pci_name(dev->rdev.lldi.pdev)); | 541 | pci_name(ctx->lldi.pdev)); |
530 | dev->rdev.flags |= T4_FATAL_ERROR; | 542 | if (ctx->dev) { |
531 | if (dev->registered) { | ||
532 | struct ib_event event; | 543 | struct ib_event event; |
533 | 544 | ||
545 | ctx->dev->rdev.flags |= T4_FATAL_ERROR; | ||
534 | memset(&event, 0, sizeof event); | 546 | memset(&event, 0, sizeof event); |
535 | event.event = IB_EVENT_DEVICE_FATAL; | 547 | event.event = IB_EVENT_DEVICE_FATAL; |
536 | event.device = &dev->ibdev; | 548 | event.device = &ctx->dev->ibdev; |
537 | ib_dispatch_event(&event); | 549 | ib_dispatch_event(&event); |
538 | c4iw_unregister_device(dev); | 550 | c4iw_remove(ctx); |
539 | } | 551 | } |
540 | break; | 552 | break; |
541 | case CXGB4_STATE_DETACH: | 553 | case CXGB4_STATE_DETACH: |
542 | printk(KERN_INFO MOD "%s: Detach\n", | 554 | printk(KERN_INFO MOD "%s: Detach\n", |
543 | pci_name(dev->rdev.lldi.pdev)); | 555 | pci_name(ctx->lldi.pdev)); |
544 | mutex_lock(&dev_mutex); | 556 | if (ctx->dev) |
545 | c4iw_remove(dev); | 557 | c4iw_remove(ctx); |
546 | mutex_unlock(&dev_mutex); | ||
547 | break; | 558 | break; |
548 | } | 559 | } |
549 | return 0; | 560 | return 0; |
@@ -576,11 +587,13 @@ static int __init c4iw_init_module(void) | |||
576 | 587 | ||
577 | static void __exit c4iw_exit_module(void) | 588 | static void __exit c4iw_exit_module(void) |
578 | { | 589 | { |
579 | struct c4iw_dev *dev, *tmp; | 590 | struct uld_ctx *ctx, *tmp; |
580 | 591 | ||
581 | mutex_lock(&dev_mutex); | 592 | mutex_lock(&dev_mutex); |
582 | list_for_each_entry_safe(dev, tmp, &dev_list, entry) { | 593 | list_for_each_entry_safe(ctx, tmp, &uld_ctx_list, entry) { |
583 | c4iw_remove(dev); | 594 | if (ctx->dev) |
595 | c4iw_remove(ctx); | ||
596 | kfree(ctx); | ||
584 | } | 597 | } |
585 | mutex_unlock(&dev_mutex); | 598 | mutex_unlock(&dev_mutex); |
586 | cxgb4_unregister_uld(CXGB4_ULD_RDMA); | 599 | cxgb4_unregister_uld(CXGB4_ULD_RDMA); |
diff --git a/drivers/infiniband/hw/cxgb4/iw_cxgb4.h b/drivers/infiniband/hw/cxgb4/iw_cxgb4.h index 9f6166f59268..35d2a5dd9bb4 100644 --- a/drivers/infiniband/hw/cxgb4/iw_cxgb4.h +++ b/drivers/infiniband/hw/cxgb4/iw_cxgb4.h | |||
@@ -131,42 +131,58 @@ static inline int c4iw_num_stags(struct c4iw_rdev *rdev) | |||
131 | 131 | ||
132 | #define C4IW_WR_TO (10*HZ) | 132 | #define C4IW_WR_TO (10*HZ) |
133 | 133 | ||
134 | enum { | ||
135 | REPLY_READY = 0, | ||
136 | }; | ||
137 | |||
134 | struct c4iw_wr_wait { | 138 | struct c4iw_wr_wait { |
135 | wait_queue_head_t wait; | 139 | wait_queue_head_t wait; |
136 | int done; | 140 | unsigned long status; |
137 | int ret; | 141 | int ret; |
138 | }; | 142 | }; |
139 | 143 | ||
140 | static inline void c4iw_init_wr_wait(struct c4iw_wr_wait *wr_waitp) | 144 | static inline void c4iw_init_wr_wait(struct c4iw_wr_wait *wr_waitp) |
141 | { | 145 | { |
142 | wr_waitp->ret = 0; | 146 | wr_waitp->ret = 0; |
143 | wr_waitp->done = 0; | 147 | wr_waitp->status = 0; |
144 | init_waitqueue_head(&wr_waitp->wait); | 148 | init_waitqueue_head(&wr_waitp->wait); |
145 | } | 149 | } |
146 | 150 | ||
151 | static inline void c4iw_wake_up(struct c4iw_wr_wait *wr_waitp, int ret) | ||
152 | { | ||
153 | wr_waitp->ret = ret; | ||
154 | set_bit(REPLY_READY, &wr_waitp->status); | ||
155 | wake_up(&wr_waitp->wait); | ||
156 | } | ||
157 | |||
147 | static inline int c4iw_wait_for_reply(struct c4iw_rdev *rdev, | 158 | static inline int c4iw_wait_for_reply(struct c4iw_rdev *rdev, |
148 | struct c4iw_wr_wait *wr_waitp, | 159 | struct c4iw_wr_wait *wr_waitp, |
149 | u32 hwtid, u32 qpid, | 160 | u32 hwtid, u32 qpid, |
150 | const char *func) | 161 | const char *func) |
151 | { | 162 | { |
152 | unsigned to = C4IW_WR_TO; | 163 | unsigned to = C4IW_WR_TO; |
153 | do { | 164 | int ret; |
154 | 165 | ||
155 | wait_event_timeout(wr_waitp->wait, wr_waitp->done, to); | 166 | do { |
156 | if (!wr_waitp->done) { | 167 | ret = wait_event_timeout(wr_waitp->wait, |
168 | test_and_clear_bit(REPLY_READY, &wr_waitp->status), to); | ||
169 | if (!ret) { | ||
157 | printk(KERN_ERR MOD "%s - Device %s not responding - " | 170 | printk(KERN_ERR MOD "%s - Device %s not responding - " |
158 | "tid %u qpid %u\n", func, | 171 | "tid %u qpid %u\n", func, |
159 | pci_name(rdev->lldi.pdev), hwtid, qpid); | 172 | pci_name(rdev->lldi.pdev), hwtid, qpid); |
173 | if (c4iw_fatal_error(rdev)) { | ||
174 | wr_waitp->ret = -EIO; | ||
175 | break; | ||
176 | } | ||
160 | to = to << 2; | 177 | to = to << 2; |
161 | } | 178 | } |
162 | } while (!wr_waitp->done); | 179 | } while (!ret); |
163 | if (wr_waitp->ret) | 180 | if (wr_waitp->ret) |
164 | printk(KERN_WARNING MOD "%s: FW reply %d tid %u qpid %u\n", | 181 | PDBG("%s: FW reply %d tid %u qpid %u\n", |
165 | pci_name(rdev->lldi.pdev), wr_waitp->ret, hwtid, qpid); | 182 | pci_name(rdev->lldi.pdev), wr_waitp->ret, hwtid, qpid); |
166 | return wr_waitp->ret; | 183 | return wr_waitp->ret; |
167 | } | 184 | } |
168 | 185 | ||
169 | |||
170 | struct c4iw_dev { | 186 | struct c4iw_dev { |
171 | struct ib_device ibdev; | 187 | struct ib_device ibdev; |
172 | struct c4iw_rdev rdev; | 188 | struct c4iw_rdev rdev; |
@@ -175,9 +191,7 @@ struct c4iw_dev { | |||
175 | struct idr qpidr; | 191 | struct idr qpidr; |
176 | struct idr mmidr; | 192 | struct idr mmidr; |
177 | spinlock_t lock; | 193 | spinlock_t lock; |
178 | struct list_head entry; | ||
179 | struct dentry *debugfs_root; | 194 | struct dentry *debugfs_root; |
180 | u8 registered; | ||
181 | }; | 195 | }; |
182 | 196 | ||
183 | static inline struct c4iw_dev *to_c4iw_dev(struct ib_device *ibdev) | 197 | static inline struct c4iw_dev *to_c4iw_dev(struct ib_device *ibdev) |
diff --git a/drivers/infiniband/hw/cxgb4/provider.c b/drivers/infiniband/hw/cxgb4/provider.c index f66dd8bf5128..5b9e4220ca08 100644 --- a/drivers/infiniband/hw/cxgb4/provider.c +++ b/drivers/infiniband/hw/cxgb4/provider.c | |||
@@ -516,7 +516,6 @@ int c4iw_register_device(struct c4iw_dev *dev) | |||
516 | if (ret) | 516 | if (ret) |
517 | goto bail2; | 517 | goto bail2; |
518 | } | 518 | } |
519 | dev->registered = 1; | ||
520 | return 0; | 519 | return 0; |
521 | bail2: | 520 | bail2: |
522 | ib_unregister_device(&dev->ibdev); | 521 | ib_unregister_device(&dev->ibdev); |
@@ -535,6 +534,5 @@ void c4iw_unregister_device(struct c4iw_dev *dev) | |||
535 | c4iw_class_attributes[i]); | 534 | c4iw_class_attributes[i]); |
536 | ib_unregister_device(&dev->ibdev); | 535 | ib_unregister_device(&dev->ibdev); |
537 | kfree(dev->ibdev.iwcm); | 536 | kfree(dev->ibdev.iwcm); |
538 | dev->registered = 0; | ||
539 | return; | 537 | return; |
540 | } | 538 | } |
diff --git a/drivers/infiniband/hw/cxgb4/qp.c b/drivers/infiniband/hw/cxgb4/qp.c index 70a5a3c646da..3b773b05a898 100644 --- a/drivers/infiniband/hw/cxgb4/qp.c +++ b/drivers/infiniband/hw/cxgb4/qp.c | |||
@@ -214,7 +214,7 @@ static int create_qp(struct c4iw_rdev *rdev, struct t4_wq *wq, | |||
214 | V_FW_RI_RES_WR_HOSTFCMODE(0) | /* no host cidx updates */ | 214 | V_FW_RI_RES_WR_HOSTFCMODE(0) | /* no host cidx updates */ |
215 | V_FW_RI_RES_WR_CPRIO(0) | /* don't keep in chip cache */ | 215 | V_FW_RI_RES_WR_CPRIO(0) | /* don't keep in chip cache */ |
216 | V_FW_RI_RES_WR_PCIECHN(0) | /* set by uP at ri_init time */ | 216 | V_FW_RI_RES_WR_PCIECHN(0) | /* set by uP at ri_init time */ |
217 | t4_sq_onchip(&wq->sq) ? F_FW_RI_RES_WR_ONCHIP : 0 | | 217 | (t4_sq_onchip(&wq->sq) ? F_FW_RI_RES_WR_ONCHIP : 0) | |
218 | V_FW_RI_RES_WR_IQID(scq->cqid)); | 218 | V_FW_RI_RES_WR_IQID(scq->cqid)); |
219 | res->u.sqrq.dcaen_to_eqsize = cpu_to_be32( | 219 | res->u.sqrq.dcaen_to_eqsize = cpu_to_be32( |
220 | V_FW_RI_RES_WR_DCAEN(0) | | 220 | V_FW_RI_RES_WR_DCAEN(0) | |
@@ -1210,7 +1210,6 @@ int c4iw_modify_qp(struct c4iw_dev *rhp, struct c4iw_qp *qhp, | |||
1210 | if (ret) { | 1210 | if (ret) { |
1211 | if (internal) | 1211 | if (internal) |
1212 | c4iw_get_ep(&qhp->ep->com); | 1212 | c4iw_get_ep(&qhp->ep->com); |
1213 | disconnect = abort = 1; | ||
1214 | goto err; | 1213 | goto err; |
1215 | } | 1214 | } |
1216 | break; | 1215 | break; |
diff --git a/drivers/infiniband/hw/ipath/ipath_driver.c b/drivers/infiniband/hw/ipath/ipath_driver.c index 58c0e417bc30..be24ac726114 100644 --- a/drivers/infiniband/hw/ipath/ipath_driver.c +++ b/drivers/infiniband/hw/ipath/ipath_driver.c | |||
@@ -398,7 +398,6 @@ static int __devinit ipath_init_one(struct pci_dev *pdev, | |||
398 | struct ipath_devdata *dd; | 398 | struct ipath_devdata *dd; |
399 | unsigned long long addr; | 399 | unsigned long long addr; |
400 | u32 bar0 = 0, bar1 = 0; | 400 | u32 bar0 = 0, bar1 = 0; |
401 | u8 rev; | ||
402 | 401 | ||
403 | dd = ipath_alloc_devdata(pdev); | 402 | dd = ipath_alloc_devdata(pdev); |
404 | if (IS_ERR(dd)) { | 403 | if (IS_ERR(dd)) { |
@@ -540,13 +539,7 @@ static int __devinit ipath_init_one(struct pci_dev *pdev, | |||
540 | goto bail_regions; | 539 | goto bail_regions; |
541 | } | 540 | } |
542 | 541 | ||
543 | ret = pci_read_config_byte(pdev, PCI_REVISION_ID, &rev); | 542 | dd->ipath_pcirev = pdev->revision; |
544 | if (ret) { | ||
545 | ipath_dev_err(dd, "Failed to read PCI revision ID unit " | ||
546 | "%u: err %d\n", dd->ipath_unit, -ret); | ||
547 | goto bail_regions; /* shouldn't ever happen */ | ||
548 | } | ||
549 | dd->ipath_pcirev = rev; | ||
550 | 543 | ||
551 | #if defined(__powerpc__) | 544 | #if defined(__powerpc__) |
552 | /* There isn't a generic way to specify writethrough mappings */ | 545 | /* There isn't a generic way to specify writethrough mappings */ |
diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c index 33c7eedaba6c..e74cdf9ef471 100644 --- a/drivers/infiniband/hw/nes/nes_cm.c +++ b/drivers/infiniband/hw/nes/nes_cm.c | |||
@@ -2563,7 +2563,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp) | |||
2563 | u16 last_ae; | 2563 | u16 last_ae; |
2564 | u8 original_hw_tcp_state; | 2564 | u8 original_hw_tcp_state; |
2565 | u8 original_ibqp_state; | 2565 | u8 original_ibqp_state; |
2566 | enum iw_cm_event_status disconn_status = IW_CM_EVENT_STATUS_OK; | 2566 | int disconn_status = 0; |
2567 | int issue_disconn = 0; | 2567 | int issue_disconn = 0; |
2568 | int issue_close = 0; | 2568 | int issue_close = 0; |
2569 | int issue_flush = 0; | 2569 | int issue_flush = 0; |
@@ -2605,7 +2605,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp) | |||
2605 | (last_ae == NES_AEQE_AEID_LLP_CONNECTION_RESET))) { | 2605 | (last_ae == NES_AEQE_AEID_LLP_CONNECTION_RESET))) { |
2606 | issue_disconn = 1; | 2606 | issue_disconn = 1; |
2607 | if (last_ae == NES_AEQE_AEID_LLP_CONNECTION_RESET) | 2607 | if (last_ae == NES_AEQE_AEID_LLP_CONNECTION_RESET) |
2608 | disconn_status = IW_CM_EVENT_STATUS_RESET; | 2608 | disconn_status = -ECONNRESET; |
2609 | } | 2609 | } |
2610 | 2610 | ||
2611 | if (((original_hw_tcp_state == NES_AEQE_TCP_STATE_CLOSED) || | 2611 | if (((original_hw_tcp_state == NES_AEQE_TCP_STATE_CLOSED) || |
@@ -2666,7 +2666,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp) | |||
2666 | cm_id->provider_data = nesqp; | 2666 | cm_id->provider_data = nesqp; |
2667 | /* Send up the close complete event */ | 2667 | /* Send up the close complete event */ |
2668 | cm_event.event = IW_CM_EVENT_CLOSE; | 2668 | cm_event.event = IW_CM_EVENT_CLOSE; |
2669 | cm_event.status = IW_CM_EVENT_STATUS_OK; | 2669 | cm_event.status = 0; |
2670 | cm_event.provider_data = cm_id->provider_data; | 2670 | cm_event.provider_data = cm_id->provider_data; |
2671 | cm_event.local_addr = cm_id->local_addr; | 2671 | cm_event.local_addr = cm_id->local_addr; |
2672 | cm_event.remote_addr = cm_id->remote_addr; | 2672 | cm_event.remote_addr = cm_id->remote_addr; |
@@ -2966,7 +2966,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param) | |||
2966 | nes_add_ref(&nesqp->ibqp); | 2966 | nes_add_ref(&nesqp->ibqp); |
2967 | 2967 | ||
2968 | cm_event.event = IW_CM_EVENT_ESTABLISHED; | 2968 | cm_event.event = IW_CM_EVENT_ESTABLISHED; |
2969 | cm_event.status = IW_CM_EVENT_STATUS_ACCEPTED; | 2969 | cm_event.status = 0; |
2970 | cm_event.provider_data = (void *)nesqp; | 2970 | cm_event.provider_data = (void *)nesqp; |
2971 | cm_event.local_addr = cm_id->local_addr; | 2971 | cm_event.local_addr = cm_id->local_addr; |
2972 | cm_event.remote_addr = cm_id->remote_addr; | 2972 | cm_event.remote_addr = cm_id->remote_addr; |
@@ -3377,7 +3377,7 @@ static void cm_event_connected(struct nes_cm_event *event) | |||
3377 | 3377 | ||
3378 | /* notify OF layer we successfully created the requested connection */ | 3378 | /* notify OF layer we successfully created the requested connection */ |
3379 | cm_event.event = IW_CM_EVENT_CONNECT_REPLY; | 3379 | cm_event.event = IW_CM_EVENT_CONNECT_REPLY; |
3380 | cm_event.status = IW_CM_EVENT_STATUS_ACCEPTED; | 3380 | cm_event.status = 0; |
3381 | cm_event.provider_data = cm_id->provider_data; | 3381 | cm_event.provider_data = cm_id->provider_data; |
3382 | cm_event.local_addr.sin_family = AF_INET; | 3382 | cm_event.local_addr.sin_family = AF_INET; |
3383 | cm_event.local_addr.sin_port = cm_id->local_addr.sin_port; | 3383 | cm_event.local_addr.sin_port = cm_id->local_addr.sin_port; |
@@ -3484,7 +3484,7 @@ static void cm_event_reset(struct nes_cm_event *event) | |||
3484 | nesqp->cm_id = NULL; | 3484 | nesqp->cm_id = NULL; |
3485 | /* cm_id->provider_data = NULL; */ | 3485 | /* cm_id->provider_data = NULL; */ |
3486 | cm_event.event = IW_CM_EVENT_DISCONNECT; | 3486 | cm_event.event = IW_CM_EVENT_DISCONNECT; |
3487 | cm_event.status = IW_CM_EVENT_STATUS_RESET; | 3487 | cm_event.status = -ECONNRESET; |
3488 | cm_event.provider_data = cm_id->provider_data; | 3488 | cm_event.provider_data = cm_id->provider_data; |
3489 | cm_event.local_addr = cm_id->local_addr; | 3489 | cm_event.local_addr = cm_id->local_addr; |
3490 | cm_event.remote_addr = cm_id->remote_addr; | 3490 | cm_event.remote_addr = cm_id->remote_addr; |
@@ -3495,7 +3495,7 @@ static void cm_event_reset(struct nes_cm_event *event) | |||
3495 | ret = cm_id->event_handler(cm_id, &cm_event); | 3495 | ret = cm_id->event_handler(cm_id, &cm_event); |
3496 | atomic_inc(&cm_closes); | 3496 | atomic_inc(&cm_closes); |
3497 | cm_event.event = IW_CM_EVENT_CLOSE; | 3497 | cm_event.event = IW_CM_EVENT_CLOSE; |
3498 | cm_event.status = IW_CM_EVENT_STATUS_OK; | 3498 | cm_event.status = 0; |
3499 | cm_event.provider_data = cm_id->provider_data; | 3499 | cm_event.provider_data = cm_id->provider_data; |
3500 | cm_event.local_addr = cm_id->local_addr; | 3500 | cm_event.local_addr = cm_id->local_addr; |
3501 | cm_event.remote_addr = cm_id->remote_addr; | 3501 | cm_event.remote_addr = cm_id->remote_addr; |
@@ -3534,7 +3534,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event) | |||
3534 | cm_node, cm_id, jiffies); | 3534 | cm_node, cm_id, jiffies); |
3535 | 3535 | ||
3536 | cm_event.event = IW_CM_EVENT_CONNECT_REQUEST; | 3536 | cm_event.event = IW_CM_EVENT_CONNECT_REQUEST; |
3537 | cm_event.status = IW_CM_EVENT_STATUS_OK; | 3537 | cm_event.status = 0; |
3538 | cm_event.provider_data = (void *)cm_node; | 3538 | cm_event.provider_data = (void *)cm_node; |
3539 | 3539 | ||
3540 | cm_event.local_addr.sin_family = AF_INET; | 3540 | cm_event.local_addr.sin_family = AF_INET; |
diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c index 26d8018c0a7c..95ca93ceedac 100644 --- a/drivers/infiniband/hw/nes/nes_verbs.c +++ b/drivers/infiniband/hw/nes/nes_verbs.c | |||
@@ -1484,7 +1484,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp) | |||
1484 | (nesqp->ibqp_state == IB_QPS_RTR)) && (nesqp->cm_id)) { | 1484 | (nesqp->ibqp_state == IB_QPS_RTR)) && (nesqp->cm_id)) { |
1485 | cm_id = nesqp->cm_id; | 1485 | cm_id = nesqp->cm_id; |
1486 | cm_event.event = IW_CM_EVENT_CONNECT_REPLY; | 1486 | cm_event.event = IW_CM_EVENT_CONNECT_REPLY; |
1487 | cm_event.status = IW_CM_EVENT_STATUS_TIMEOUT; | 1487 | cm_event.status = -ETIMEDOUT; |
1488 | cm_event.local_addr = cm_id->local_addr; | 1488 | cm_event.local_addr = cm_id->local_addr; |
1489 | cm_event.remote_addr = cm_id->remote_addr; | 1489 | cm_event.remote_addr = cm_id->remote_addr; |
1490 | cm_event.private_data = NULL; | 1490 | cm_event.private_data = NULL; |
diff --git a/drivers/infiniband/hw/qib/qib_iba7322.c b/drivers/infiniband/hw/qib/qib_iba7322.c index 6bab3eaea70f..9f53e68a096a 100644 --- a/drivers/infiniband/hw/qib/qib_iba7322.c +++ b/drivers/infiniband/hw/qib/qib_iba7322.c | |||
@@ -7534,7 +7534,8 @@ static int serdes_7322_init_new(struct qib_pportdata *ppd) | |||
7534 | ibsd_wr_allchans(ppd, 4, (1 << 10), BMASK(10, 10)); | 7534 | ibsd_wr_allchans(ppd, 4, (1 << 10), BMASK(10, 10)); |
7535 | tstart = get_jiffies_64(); | 7535 | tstart = get_jiffies_64(); |
7536 | while (chan_done && | 7536 | while (chan_done && |
7537 | !time_after64(tstart, tstart + msecs_to_jiffies(500))) { | 7537 | !time_after64(get_jiffies_64(), |
7538 | tstart + msecs_to_jiffies(500))) { | ||
7538 | msleep(20); | 7539 | msleep(20); |
7539 | for (chan = 0; chan < SERDES_CHANS; ++chan) { | 7540 | for (chan = 0; chan < SERDES_CHANS; ++chan) { |
7540 | rxcaldone = ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), | 7541 | rxcaldone = ahb_mod(ppd->dd, IBSD(ppd->hw_pidx), |
diff --git a/drivers/infiniband/hw/qib/qib_pcie.c b/drivers/infiniband/hw/qib/qib_pcie.c index 48b6674cbc49..891cc2ff5f00 100644 --- a/drivers/infiniband/hw/qib/qib_pcie.c +++ b/drivers/infiniband/hw/qib/qib_pcie.c | |||
@@ -526,11 +526,8 @@ static int qib_tune_pcie_coalesce(struct qib_devdata *dd) | |||
526 | */ | 526 | */ |
527 | devid = parent->device; | 527 | devid = parent->device; |
528 | if (devid >= 0x25e2 && devid <= 0x25fa) { | 528 | if (devid >= 0x25e2 && devid <= 0x25fa) { |
529 | u8 rev; | ||
530 | |||
531 | /* 5000 P/V/X/Z */ | 529 | /* 5000 P/V/X/Z */ |
532 | pci_read_config_byte(parent, PCI_REVISION_ID, &rev); | 530 | if (parent->revision <= 0xb2) |
533 | if (rev <= 0xb2) | ||
534 | bits = 1U << 10; | 531 | bits = 1U << 10; |
535 | else | 532 | else |
536 | bits = 7U << 10; | 533 | bits = 7U << 10; |
diff --git a/drivers/input/keyboard/atakbd.c b/drivers/input/keyboard/atakbd.c index 1839194ea987..10bcd4ae5402 100644 --- a/drivers/input/keyboard/atakbd.c +++ b/drivers/input/keyboard/atakbd.c | |||
@@ -223,8 +223,9 @@ static int __init atakbd_init(void) | |||
223 | return -ENODEV; | 223 | return -ENODEV; |
224 | 224 | ||
225 | // need to init core driver if not already done so | 225 | // need to init core driver if not already done so |
226 | if (atari_keyb_init()) | 226 | error = atari_keyb_init(); |
227 | return -ENODEV; | 227 | if (error) |
228 | return error; | ||
228 | 229 | ||
229 | atakbd_dev = input_allocate_device(); | 230 | atakbd_dev = input_allocate_device(); |
230 | if (!atakbd_dev) | 231 | if (!atakbd_dev) |
diff --git a/drivers/input/mouse/atarimouse.c b/drivers/input/mouse/atarimouse.c index adf45b3040e9..5c4a692bf73a 100644 --- a/drivers/input/mouse/atarimouse.c +++ b/drivers/input/mouse/atarimouse.c | |||
@@ -77,15 +77,15 @@ static void atamouse_interrupt(char *buf) | |||
77 | #endif | 77 | #endif |
78 | 78 | ||
79 | /* only relative events get here */ | 79 | /* only relative events get here */ |
80 | dx = buf[1]; | 80 | dx = buf[1]; |
81 | dy = -buf[2]; | 81 | dy = buf[2]; |
82 | 82 | ||
83 | input_report_rel(atamouse_dev, REL_X, dx); | 83 | input_report_rel(atamouse_dev, REL_X, dx); |
84 | input_report_rel(atamouse_dev, REL_Y, dy); | 84 | input_report_rel(atamouse_dev, REL_Y, dy); |
85 | 85 | ||
86 | input_report_key(atamouse_dev, BTN_LEFT, buttons & 0x1); | 86 | input_report_key(atamouse_dev, BTN_LEFT, buttons & 0x4); |
87 | input_report_key(atamouse_dev, BTN_MIDDLE, buttons & 0x2); | 87 | input_report_key(atamouse_dev, BTN_MIDDLE, buttons & 0x2); |
88 | input_report_key(atamouse_dev, BTN_RIGHT, buttons & 0x4); | 88 | input_report_key(atamouse_dev, BTN_RIGHT, buttons & 0x1); |
89 | 89 | ||
90 | input_sync(atamouse_dev); | 90 | input_sync(atamouse_dev); |
91 | 91 | ||
@@ -108,7 +108,7 @@ static int atamouse_open(struct input_dev *dev) | |||
108 | static void atamouse_close(struct input_dev *dev) | 108 | static void atamouse_close(struct input_dev *dev) |
109 | { | 109 | { |
110 | ikbd_mouse_disable(); | 110 | ikbd_mouse_disable(); |
111 | atari_mouse_interrupt_hook = NULL; | 111 | atari_input_mouse_interrupt_hook = NULL; |
112 | } | 112 | } |
113 | 113 | ||
114 | static int __init atamouse_init(void) | 114 | static int __init atamouse_init(void) |
@@ -118,8 +118,9 @@ static int __init atamouse_init(void) | |||
118 | if (!MACH_IS_ATARI || !ATARIHW_PRESENT(ST_MFP)) | 118 | if (!MACH_IS_ATARI || !ATARIHW_PRESENT(ST_MFP)) |
119 | return -ENODEV; | 119 | return -ENODEV; |
120 | 120 | ||
121 | if (!atari_keyb_init()) | 121 | error = atari_keyb_init(); |
122 | return -ENODEV; | 122 | if (error) |
123 | return error; | ||
123 | 124 | ||
124 | atamouse_dev = input_allocate_device(); | 125 | atamouse_dev = input_allocate_device(); |
125 | if (!atamouse_dev) | 126 | if (!atamouse_dev) |
diff --git a/drivers/lguest/Kconfig b/drivers/lguest/Kconfig index 0aaa0597a622..34ae49dc557c 100644 --- a/drivers/lguest/Kconfig +++ b/drivers/lguest/Kconfig | |||
@@ -5,8 +5,10 @@ config LGUEST | |||
5 | ---help--- | 5 | ---help--- |
6 | This is a very simple module which allows you to run | 6 | This is a very simple module which allows you to run |
7 | multiple instances of the same Linux kernel, using the | 7 | multiple instances of the same Linux kernel, using the |
8 | "lguest" command found in the Documentation/lguest directory. | 8 | "lguest" command found in the Documentation/virtual/lguest |
9 | directory. | ||
10 | |||
9 | Note that "lguest" is pronounced to rhyme with "fell quest", | 11 | Note that "lguest" is pronounced to rhyme with "fell quest", |
10 | not "rustyvisor". See Documentation/lguest/lguest.txt. | 12 | not "rustyvisor". See Documentation/virtual/lguest/lguest.txt. |
11 | 13 | ||
12 | If unsure, say N. If curious, say M. If masochistic, say Y. | 14 | If unsure, say N. If curious, say M. If masochistic, say Y. |
diff --git a/drivers/lguest/Makefile b/drivers/lguest/Makefile index 7d463c26124f..8ac947c7e7c7 100644 --- a/drivers/lguest/Makefile +++ b/drivers/lguest/Makefile | |||
@@ -18,7 +18,7 @@ Mastery: PREFIX=M | |||
18 | Beer: | 18 | Beer: |
19 | @for f in Preparation Guest Drivers Launcher Host Switcher Mastery; do echo "{==- $$f -==}"; make -s $$f; done; echo "{==-==}" | 19 | @for f in Preparation Guest Drivers Launcher Host Switcher Mastery; do echo "{==- $$f -==}"; make -s $$f; done; echo "{==-==}" |
20 | Preparation Preparation! Guest Drivers Launcher Host Switcher Mastery: | 20 | Preparation Preparation! Guest Drivers Launcher Host Switcher Mastery: |
21 | @sh ../../Documentation/lguest/extract $(PREFIX) `find ../../* -name '*.[chS]' -wholename '*lguest*'` | 21 | @sh ../../Documentation/virtual/lguest/extract $(PREFIX) `find ../../* -name '*.[chS]' -wholename '*lguest*'` |
22 | Puppy: | 22 | Puppy: |
23 | @clear | 23 | @clear |
24 | @printf " __ \n (___()'\`;\n /, /\`\n \\\\\\\"--\\\\\\ \n" | 24 | @printf " __ \n (___()'\`;\n /, /\`\n \\\\\\\"--\\\\\\ \n" |
diff --git a/drivers/misc/ti-st/Kconfig b/drivers/misc/ti-st/Kconfig index 2c8c3f39710d..abb5de1afce3 100644 --- a/drivers/misc/ti-st/Kconfig +++ b/drivers/misc/ti-st/Kconfig | |||
@@ -5,7 +5,7 @@ | |||
5 | menu "Texas Instruments shared transport line discipline" | 5 | menu "Texas Instruments shared transport line discipline" |
6 | config TI_ST | 6 | config TI_ST |
7 | tristate "Shared transport core driver" | 7 | tristate "Shared transport core driver" |
8 | depends on RFKILL | 8 | depends on NET && GPIOLIB |
9 | select FW_LOADER | 9 | select FW_LOADER |
10 | help | 10 | help |
11 | This enables the shared transport core driver for TI | 11 | This enables the shared transport core driver for TI |
diff --git a/drivers/misc/ti-st/st_core.c b/drivers/misc/ti-st/st_core.c index 486117f72c9f..f91f82eabda7 100644 --- a/drivers/misc/ti-st/st_core.c +++ b/drivers/misc/ti-st/st_core.c | |||
@@ -43,13 +43,15 @@ static void add_channel_to_table(struct st_data_s *st_gdata, | |||
43 | pr_info("%s: id %d\n", __func__, new_proto->chnl_id); | 43 | pr_info("%s: id %d\n", __func__, new_proto->chnl_id); |
44 | /* list now has the channel id as index itself */ | 44 | /* list now has the channel id as index itself */ |
45 | st_gdata->list[new_proto->chnl_id] = new_proto; | 45 | st_gdata->list[new_proto->chnl_id] = new_proto; |
46 | st_gdata->is_registered[new_proto->chnl_id] = true; | ||
46 | } | 47 | } |
47 | 48 | ||
48 | static void remove_channel_from_table(struct st_data_s *st_gdata, | 49 | static void remove_channel_from_table(struct st_data_s *st_gdata, |
49 | struct st_proto_s *proto) | 50 | struct st_proto_s *proto) |
50 | { | 51 | { |
51 | pr_info("%s: id %d\n", __func__, proto->chnl_id); | 52 | pr_info("%s: id %d\n", __func__, proto->chnl_id); |
52 | st_gdata->list[proto->chnl_id] = NULL; | 53 | /* st_gdata->list[proto->chnl_id] = NULL; */ |
54 | st_gdata->is_registered[proto->chnl_id] = false; | ||
53 | } | 55 | } |
54 | 56 | ||
55 | /* | 57 | /* |
@@ -104,7 +106,7 @@ void st_send_frame(unsigned char chnl_id, struct st_data_s *st_gdata) | |||
104 | 106 | ||
105 | if (unlikely | 107 | if (unlikely |
106 | (st_gdata == NULL || st_gdata->rx_skb == NULL | 108 | (st_gdata == NULL || st_gdata->rx_skb == NULL |
107 | || st_gdata->list[chnl_id] == NULL)) { | 109 | || st_gdata->is_registered[chnl_id] == false)) { |
108 | pr_err("chnl_id %d not registered, no data to send?", | 110 | pr_err("chnl_id %d not registered, no data to send?", |
109 | chnl_id); | 111 | chnl_id); |
110 | kfree_skb(st_gdata->rx_skb); | 112 | kfree_skb(st_gdata->rx_skb); |
@@ -141,14 +143,15 @@ void st_reg_complete(struct st_data_s *st_gdata, char err) | |||
141 | unsigned char i = 0; | 143 | unsigned char i = 0; |
142 | pr_info(" %s ", __func__); | 144 | pr_info(" %s ", __func__); |
143 | for (i = 0; i < ST_MAX_CHANNELS; i++) { | 145 | for (i = 0; i < ST_MAX_CHANNELS; i++) { |
144 | if (likely(st_gdata != NULL && st_gdata->list[i] != NULL && | 146 | if (likely(st_gdata != NULL && |
145 | st_gdata->list[i]->reg_complete_cb != NULL)) { | 147 | st_gdata->is_registered[i] == true && |
148 | st_gdata->list[i]->reg_complete_cb != NULL)) { | ||
146 | st_gdata->list[i]->reg_complete_cb | 149 | st_gdata->list[i]->reg_complete_cb |
147 | (st_gdata->list[i]->priv_data, err); | 150 | (st_gdata->list[i]->priv_data, err); |
148 | pr_info("protocol %d's cb sent %d\n", i, err); | 151 | pr_info("protocol %d's cb sent %d\n", i, err); |
149 | if (err) { /* cleanup registered protocol */ | 152 | if (err) { /* cleanup registered protocol */ |
150 | st_gdata->protos_registered--; | 153 | st_gdata->protos_registered--; |
151 | st_gdata->list[i] = NULL; | 154 | st_gdata->is_registered[i] = false; |
152 | } | 155 | } |
153 | } | 156 | } |
154 | } | 157 | } |
@@ -475,9 +478,9 @@ void kim_st_list_protocols(struct st_data_s *st_gdata, void *buf) | |||
475 | { | 478 | { |
476 | seq_printf(buf, "[%d]\nBT=%c\nFM=%c\nGPS=%c\n", | 479 | seq_printf(buf, "[%d]\nBT=%c\nFM=%c\nGPS=%c\n", |
477 | st_gdata->protos_registered, | 480 | st_gdata->protos_registered, |
478 | st_gdata->list[0x04] != NULL ? 'R' : 'U', | 481 | st_gdata->is_registered[0x04] == true ? 'R' : 'U', |
479 | st_gdata->list[0x08] != NULL ? 'R' : 'U', | 482 | st_gdata->is_registered[0x08] == true ? 'R' : 'U', |
480 | st_gdata->list[0x09] != NULL ? 'R' : 'U'); | 483 | st_gdata->is_registered[0x09] == true ? 'R' : 'U'); |
481 | } | 484 | } |
482 | 485 | ||
483 | /********************************************************************/ | 486 | /********************************************************************/ |
@@ -504,7 +507,7 @@ long st_register(struct st_proto_s *new_proto) | |||
504 | return -EPROTONOSUPPORT; | 507 | return -EPROTONOSUPPORT; |
505 | } | 508 | } |
506 | 509 | ||
507 | if (st_gdata->list[new_proto->chnl_id] != NULL) { | 510 | if (st_gdata->is_registered[new_proto->chnl_id] == true) { |
508 | pr_err("chnl_id %d already registered", new_proto->chnl_id); | 511 | pr_err("chnl_id %d already registered", new_proto->chnl_id); |
509 | return -EALREADY; | 512 | return -EALREADY; |
510 | } | 513 | } |
@@ -563,7 +566,7 @@ long st_register(struct st_proto_s *new_proto) | |||
563 | /* check for already registered once more, | 566 | /* check for already registered once more, |
564 | * since the above check is old | 567 | * since the above check is old |
565 | */ | 568 | */ |
566 | if (st_gdata->list[new_proto->chnl_id] != NULL) { | 569 | if (st_gdata->is_registered[new_proto->chnl_id] == true) { |
567 | pr_err(" proto %d already registered ", | 570 | pr_err(" proto %d already registered ", |
568 | new_proto->chnl_id); | 571 | new_proto->chnl_id); |
569 | return -EALREADY; | 572 | return -EALREADY; |
diff --git a/drivers/misc/ti-st/st_kim.c b/drivers/misc/ti-st/st_kim.c index b4488c8f6b23..5da93ee6f6be 100644 --- a/drivers/misc/ti-st/st_kim.c +++ b/drivers/misc/ti-st/st_kim.c | |||
@@ -30,6 +30,7 @@ | |||
30 | #include <linux/debugfs.h> | 30 | #include <linux/debugfs.h> |
31 | #include <linux/seq_file.h> | 31 | #include <linux/seq_file.h> |
32 | #include <linux/sched.h> | 32 | #include <linux/sched.h> |
33 | #include <linux/sysfs.h> | ||
33 | #include <linux/tty.h> | 34 | #include <linux/tty.h> |
34 | 35 | ||
35 | #include <linux/skbuff.h> | 36 | #include <linux/skbuff.h> |
diff --git a/drivers/mtd/maps/Kconfig b/drivers/mtd/maps/Kconfig index 44b1f46458ca..5069111c81cc 100644 --- a/drivers/mtd/maps/Kconfig +++ b/drivers/mtd/maps/Kconfig | |||
@@ -260,6 +260,13 @@ config MTD_BCM963XX | |||
260 | Support for parsing CFE image tag and creating MTD partitions on | 260 | Support for parsing CFE image tag and creating MTD partitions on |
261 | Broadcom BCM63xx boards. | 261 | Broadcom BCM63xx boards. |
262 | 262 | ||
263 | config MTD_LANTIQ | ||
264 | tristate "Lantiq SoC NOR support" | ||
265 | depends on LANTIQ | ||
266 | select MTD_PARTITIONS | ||
267 | help | ||
268 | Support for NOR flash attached to the Lantiq SoC's External Bus Unit. | ||
269 | |||
263 | config MTD_DILNETPC | 270 | config MTD_DILNETPC |
264 | tristate "CFI Flash device mapped on DIL/Net PC" | 271 | tristate "CFI Flash device mapped on DIL/Net PC" |
265 | depends on X86 && MTD_PARTITIONS && MTD_CFI_INTELEXT && BROKEN | 272 | depends on X86 && MTD_PARTITIONS && MTD_CFI_INTELEXT && BROKEN |
diff --git a/drivers/mtd/maps/Makefile b/drivers/mtd/maps/Makefile index 08533bd5cba7..6adf4c9b9057 100644 --- a/drivers/mtd/maps/Makefile +++ b/drivers/mtd/maps/Makefile | |||
@@ -60,3 +60,4 @@ obj-$(CONFIG_MTD_VMU) += vmu-flash.o | |||
60 | obj-$(CONFIG_MTD_GPIO_ADDR) += gpio-addr-flash.o | 60 | obj-$(CONFIG_MTD_GPIO_ADDR) += gpio-addr-flash.o |
61 | obj-$(CONFIG_MTD_BCM963XX) += bcm963xx-flash.o | 61 | obj-$(CONFIG_MTD_BCM963XX) += bcm963xx-flash.o |
62 | obj-$(CONFIG_MTD_LATCH_ADDR) += latch-addr-flash.o | 62 | obj-$(CONFIG_MTD_LATCH_ADDR) += latch-addr-flash.o |
63 | obj-$(CONFIG_MTD_LANTIQ) += lantiq-flash.o | ||
diff --git a/drivers/mtd/maps/lantiq-flash.c b/drivers/mtd/maps/lantiq-flash.c new file mode 100644 index 000000000000..a90cabd7b84d --- /dev/null +++ b/drivers/mtd/maps/lantiq-flash.c | |||
@@ -0,0 +1,251 @@ | |||
1 | /* | ||
2 | * This program is free software; you can redistribute it and/or modify it | ||
3 | * under the terms of the GNU General Public License version 2 as published | ||
4 | * by the Free Software Foundation. | ||
5 | * | ||
6 | * Copyright (C) 2004 Liu Peng Infineon IFAP DC COM CPE | ||
7 | * Copyright (C) 2010 John Crispin <blogic@openwrt.org> | ||
8 | */ | ||
9 | |||
10 | #include <linux/module.h> | ||
11 | #include <linux/types.h> | ||
12 | #include <linux/kernel.h> | ||
13 | #include <linux/io.h> | ||
14 | #include <linux/slab.h> | ||
15 | #include <linux/init.h> | ||
16 | #include <linux/mtd/mtd.h> | ||
17 | #include <linux/mtd/map.h> | ||
18 | #include <linux/mtd/partitions.h> | ||
19 | #include <linux/mtd/cfi.h> | ||
20 | #include <linux/platform_device.h> | ||
21 | #include <linux/mtd/physmap.h> | ||
22 | |||
23 | #include <lantiq_soc.h> | ||
24 | #include <lantiq_platform.h> | ||
25 | |||
26 | /* | ||
27 | * The NOR flash is connected to the same external bus unit (EBU) as PCI. | ||
28 | * To make PCI work we need to enable the endianness swapping for the address | ||
29 | * written to the EBU. This endianness swapping works for PCI correctly but | ||
30 | * fails for attached NOR devices. To workaround this we need to use a complex | ||
31 | * map. The workaround involves swapping all addresses whilst probing the chip. | ||
32 | * Once probing is complete we stop swapping the addresses but swizzle the | ||
33 | * unlock addresses to ensure that access to the NOR device works correctly. | ||
34 | */ | ||
35 | |||
36 | enum { | ||
37 | LTQ_NOR_PROBING, | ||
38 | LTQ_NOR_NORMAL | ||
39 | }; | ||
40 | |||
41 | struct ltq_mtd { | ||
42 | struct resource *res; | ||
43 | struct mtd_info *mtd; | ||
44 | struct map_info *map; | ||
45 | }; | ||
46 | |||
47 | static char ltq_map_name[] = "ltq_nor"; | ||
48 | |||
49 | static map_word | ||
50 | ltq_read16(struct map_info *map, unsigned long adr) | ||
51 | { | ||
52 | unsigned long flags; | ||
53 | map_word temp; | ||
54 | |||
55 | if (map->map_priv_1 == LTQ_NOR_PROBING) | ||
56 | adr ^= 2; | ||
57 | spin_lock_irqsave(&ebu_lock, flags); | ||
58 | temp.x[0] = *(u16 *)(map->virt + adr); | ||
59 | spin_unlock_irqrestore(&ebu_lock, flags); | ||
60 | return temp; | ||
61 | } | ||
62 | |||
63 | static void | ||
64 | ltq_write16(struct map_info *map, map_word d, unsigned long adr) | ||
65 | { | ||
66 | unsigned long flags; | ||
67 | |||
68 | if (map->map_priv_1 == LTQ_NOR_PROBING) | ||
69 | adr ^= 2; | ||
70 | spin_lock_irqsave(&ebu_lock, flags); | ||
71 | *(u16 *)(map->virt + adr) = d.x[0]; | ||
72 | spin_unlock_irqrestore(&ebu_lock, flags); | ||
73 | } | ||
74 | |||
75 | /* | ||
76 | * The following 2 functions copy data between iomem and a cached memory | ||
77 | * section. As memcpy() makes use of pre-fetching we cannot use it here. | ||
78 | * The normal alternative of using memcpy_{to,from}io also makes use of | ||
79 | * memcpy() on MIPS so it is not applicable either. We are therefore stuck | ||
80 | * with having to use our own loop. | ||
81 | */ | ||
82 | static void | ||
83 | ltq_copy_from(struct map_info *map, void *to, | ||
84 | unsigned long from, ssize_t len) | ||
85 | { | ||
86 | unsigned char *f = (unsigned char *)map->virt + from; | ||
87 | unsigned char *t = (unsigned char *)to; | ||
88 | unsigned long flags; | ||
89 | |||
90 | spin_lock_irqsave(&ebu_lock, flags); | ||
91 | while (len--) | ||
92 | *t++ = *f++; | ||
93 | spin_unlock_irqrestore(&ebu_lock, flags); | ||
94 | } | ||
95 | |||
96 | static void | ||
97 | ltq_copy_to(struct map_info *map, unsigned long to, | ||
98 | const void *from, ssize_t len) | ||
99 | { | ||
100 | unsigned char *f = (unsigned char *)from; | ||
101 | unsigned char *t = (unsigned char *)map->virt + to; | ||
102 | unsigned long flags; | ||
103 | |||
104 | spin_lock_irqsave(&ebu_lock, flags); | ||
105 | while (len--) | ||
106 | *t++ = *f++; | ||
107 | spin_unlock_irqrestore(&ebu_lock, flags); | ||
108 | } | ||
109 | |||
110 | static const char const *part_probe_types[] = { "cmdlinepart", NULL }; | ||
111 | |||
112 | static int __init | ||
113 | ltq_mtd_probe(struct platform_device *pdev) | ||
114 | { | ||
115 | struct physmap_flash_data *ltq_mtd_data = dev_get_platdata(&pdev->dev); | ||
116 | struct ltq_mtd *ltq_mtd; | ||
117 | struct mtd_partition *parts; | ||
118 | struct resource *res; | ||
119 | int nr_parts = 0; | ||
120 | struct cfi_private *cfi; | ||
121 | int err; | ||
122 | |||
123 | ltq_mtd = kzalloc(sizeof(struct ltq_mtd), GFP_KERNEL); | ||
124 | platform_set_drvdata(pdev, ltq_mtd); | ||
125 | |||
126 | ltq_mtd->res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
127 | if (!ltq_mtd->res) { | ||
128 | dev_err(&pdev->dev, "failed to get memory resource"); | ||
129 | err = -ENOENT; | ||
130 | goto err_out; | ||
131 | } | ||
132 | |||
133 | res = devm_request_mem_region(&pdev->dev, ltq_mtd->res->start, | ||
134 | resource_size(ltq_mtd->res), dev_name(&pdev->dev)); | ||
135 | if (!ltq_mtd->res) { | ||
136 | dev_err(&pdev->dev, "failed to request mem resource"); | ||
137 | err = -EBUSY; | ||
138 | goto err_out; | ||
139 | } | ||
140 | |||
141 | ltq_mtd->map = kzalloc(sizeof(struct map_info), GFP_KERNEL); | ||
142 | ltq_mtd->map->phys = res->start; | ||
143 | ltq_mtd->map->size = resource_size(res); | ||
144 | ltq_mtd->map->virt = devm_ioremap_nocache(&pdev->dev, | ||
145 | ltq_mtd->map->phys, ltq_mtd->map->size); | ||
146 | if (!ltq_mtd->map->virt) { | ||
147 | dev_err(&pdev->dev, "failed to ioremap!\n"); | ||
148 | err = -ENOMEM; | ||
149 | goto err_free; | ||
150 | } | ||
151 | |||
152 | ltq_mtd->map->name = ltq_map_name; | ||
153 | ltq_mtd->map->bankwidth = 2; | ||
154 | ltq_mtd->map->read = ltq_read16; | ||
155 | ltq_mtd->map->write = ltq_write16; | ||
156 | ltq_mtd->map->copy_from = ltq_copy_from; | ||
157 | ltq_mtd->map->copy_to = ltq_copy_to; | ||
158 | |||
159 | ltq_mtd->map->map_priv_1 = LTQ_NOR_PROBING; | ||
160 | ltq_mtd->mtd = do_map_probe("cfi_probe", ltq_mtd->map); | ||
161 | ltq_mtd->map->map_priv_1 = LTQ_NOR_NORMAL; | ||
162 | |||
163 | if (!ltq_mtd->mtd) { | ||
164 | dev_err(&pdev->dev, "probing failed\n"); | ||
165 | err = -ENXIO; | ||
166 | goto err_unmap; | ||
167 | } | ||
168 | |||
169 | ltq_mtd->mtd->owner = THIS_MODULE; | ||
170 | |||
171 | cfi = ltq_mtd->map->fldrv_priv; | ||
172 | cfi->addr_unlock1 ^= 1; | ||
173 | cfi->addr_unlock2 ^= 1; | ||
174 | |||
175 | nr_parts = parse_mtd_partitions(ltq_mtd->mtd, | ||
176 | part_probe_types, &parts, 0); | ||
177 | if (nr_parts > 0) { | ||
178 | dev_info(&pdev->dev, | ||
179 | "using %d partitions from cmdline", nr_parts); | ||
180 | } else { | ||
181 | nr_parts = ltq_mtd_data->nr_parts; | ||
182 | parts = ltq_mtd_data->parts; | ||
183 | } | ||
184 | |||
185 | err = add_mtd_partitions(ltq_mtd->mtd, parts, nr_parts); | ||
186 | if (err) { | ||
187 | dev_err(&pdev->dev, "failed to add partitions\n"); | ||
188 | goto err_destroy; | ||
189 | } | ||
190 | |||
191 | return 0; | ||
192 | |||
193 | err_destroy: | ||
194 | map_destroy(ltq_mtd->mtd); | ||
195 | err_unmap: | ||
196 | iounmap(ltq_mtd->map->virt); | ||
197 | err_free: | ||
198 | kfree(ltq_mtd->map); | ||
199 | err_out: | ||
200 | kfree(ltq_mtd); | ||
201 | return err; | ||
202 | } | ||
203 | |||
204 | static int __devexit | ||
205 | ltq_mtd_remove(struct platform_device *pdev) | ||
206 | { | ||
207 | struct ltq_mtd *ltq_mtd = platform_get_drvdata(pdev); | ||
208 | |||
209 | if (ltq_mtd) { | ||
210 | if (ltq_mtd->mtd) { | ||
211 | del_mtd_partitions(ltq_mtd->mtd); | ||
212 | map_destroy(ltq_mtd->mtd); | ||
213 | } | ||
214 | if (ltq_mtd->map->virt) | ||
215 | iounmap(ltq_mtd->map->virt); | ||
216 | kfree(ltq_mtd->map); | ||
217 | kfree(ltq_mtd); | ||
218 | } | ||
219 | return 0; | ||
220 | } | ||
221 | |||
222 | static struct platform_driver ltq_mtd_driver = { | ||
223 | .remove = __devexit_p(ltq_mtd_remove), | ||
224 | .driver = { | ||
225 | .name = "ltq_nor", | ||
226 | .owner = THIS_MODULE, | ||
227 | }, | ||
228 | }; | ||
229 | |||
230 | static int __init | ||
231 | init_ltq_mtd(void) | ||
232 | { | ||
233 | int ret = platform_driver_probe(<q_mtd_driver, ltq_mtd_probe); | ||
234 | |||
235 | if (ret) | ||
236 | pr_err("ltq_nor: error registering platform driver"); | ||
237 | return ret; | ||
238 | } | ||
239 | |||
240 | static void __exit | ||
241 | exit_ltq_mtd(void) | ||
242 | { | ||
243 | platform_driver_unregister(<q_mtd_driver); | ||
244 | } | ||
245 | |||
246 | module_init(init_ltq_mtd); | ||
247 | module_exit(exit_ltq_mtd); | ||
248 | |||
249 | MODULE_LICENSE("GPL"); | ||
250 | MODULE_AUTHOR("John Crispin <blogic@openwrt.org>"); | ||
251 | MODULE_DESCRIPTION("Lantiq SoC NOR"); | ||
diff --git a/drivers/mtd/nand/au1550nd.c b/drivers/mtd/nand/au1550nd.c index 3ffe05db4923..5d513b54a7d7 100644 --- a/drivers/mtd/nand/au1550nd.c +++ b/drivers/mtd/nand/au1550nd.c | |||
@@ -10,6 +10,7 @@ | |||
10 | */ | 10 | */ |
11 | 11 | ||
12 | #include <linux/slab.h> | 12 | #include <linux/slab.h> |
13 | #include <linux/gpio.h> | ||
13 | #include <linux/init.h> | 14 | #include <linux/init.h> |
14 | #include <linux/module.h> | 15 | #include <linux/module.h> |
15 | #include <linux/interrupt.h> | 16 | #include <linux/interrupt.h> |
@@ -470,7 +471,7 @@ static int __init au1xxx_nand_init(void) | |||
470 | 471 | ||
471 | #ifdef CONFIG_MIPS_PB1550 | 472 | #ifdef CONFIG_MIPS_PB1550 |
472 | /* set gpio206 high */ | 473 | /* set gpio206 high */ |
473 | au_writel(au_readl(GPIO2_DIR) & ~(1 << 6), GPIO2_DIR); | 474 | gpio_direction_input(206); |
474 | 475 | ||
475 | boot_swapboot = (au_readl(MEM_STSTAT) & (0x7 << 1)) | ((bcsr_read(BCSR_STATUS) >> 6) & 0x1); | 476 | boot_swapboot = (au_readl(MEM_STSTAT) & (0x7 << 1)) | ((bcsr_read(BCSR_STATUS) >> 6) & 0x1); |
476 | 477 | ||
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig index 6c884ef1b069..19f04a34783a 100644 --- a/drivers/net/Kconfig +++ b/drivers/net/Kconfig | |||
@@ -2017,6 +2017,13 @@ config FTMAC100 | |||
2017 | from Faraday. It is used on Faraday A320, Andes AG101 and some | 2017 | from Faraday. It is used on Faraday A320, Andes AG101 and some |
2018 | other ARM/NDS32 SoC's. | 2018 | other ARM/NDS32 SoC's. |
2019 | 2019 | ||
2020 | config LANTIQ_ETOP | ||
2021 | tristate "Lantiq SoC ETOP driver" | ||
2022 | depends on SOC_TYPE_XWAY | ||
2023 | help | ||
2024 | Support for the MII0 inside the Lantiq SoC | ||
2025 | |||
2026 | |||
2020 | source "drivers/net/fs_enet/Kconfig" | 2027 | source "drivers/net/fs_enet/Kconfig" |
2021 | 2028 | ||
2022 | source "drivers/net/octeon/Kconfig" | 2029 | source "drivers/net/octeon/Kconfig" |
diff --git a/drivers/net/Makefile b/drivers/net/Makefile index e5a7375685ad..209fbb70619b 100644 --- a/drivers/net/Makefile +++ b/drivers/net/Makefile | |||
@@ -259,6 +259,7 @@ obj-$(CONFIG_MLX4_CORE) += mlx4/ | |||
259 | obj-$(CONFIG_ENC28J60) += enc28j60.o | 259 | obj-$(CONFIG_ENC28J60) += enc28j60.o |
260 | obj-$(CONFIG_ETHOC) += ethoc.o | 260 | obj-$(CONFIG_ETHOC) += ethoc.o |
261 | obj-$(CONFIG_GRETH) += greth.o | 261 | obj-$(CONFIG_GRETH) += greth.o |
262 | obj-$(CONFIG_LANTIQ_ETOP) += lantiq_etop.o | ||
262 | 263 | ||
263 | obj-$(CONFIG_XTENSA_XT2000_SONIC) += xtsonic.o | 264 | obj-$(CONFIG_XTENSA_XT2000_SONIC) += xtsonic.o |
264 | 265 | ||
diff --git a/drivers/net/atarilance.c b/drivers/net/atarilance.c index ce0091eb06f5..1264d781b554 100644 --- a/drivers/net/atarilance.c +++ b/drivers/net/atarilance.c | |||
@@ -554,7 +554,7 @@ static unsigned long __init lance_probe1( struct net_device *dev, | |||
554 | memaddr == (unsigned short *)0xffe00000) { | 554 | memaddr == (unsigned short *)0xffe00000) { |
555 | /* PAMs card and Riebl on ST use level 5 autovector */ | 555 | /* PAMs card and Riebl on ST use level 5 autovector */ |
556 | if (request_irq(IRQ_AUTO_5, lance_interrupt, IRQ_TYPE_PRIO, | 556 | if (request_irq(IRQ_AUTO_5, lance_interrupt, IRQ_TYPE_PRIO, |
557 | "PAM/Riebl-ST Ethernet", dev)) { | 557 | "PAM,Riebl-ST Ethernet", dev)) { |
558 | printk( "Lance: request for irq %d failed\n", IRQ_AUTO_5 ); | 558 | printk( "Lance: request for irq %d failed\n", IRQ_AUTO_5 ); |
559 | return 0; | 559 | return 0; |
560 | } | 560 | } |
diff --git a/drivers/net/ixgbe/ixgbe_main.c b/drivers/net/ixgbe/ixgbe_main.c index 6f8adc7f5d7c..e145f2c455cb 100644 --- a/drivers/net/ixgbe/ixgbe_main.c +++ b/drivers/net/ixgbe/ixgbe_main.c | |||
@@ -5100,11 +5100,6 @@ err_set_interrupt: | |||
5100 | return err; | 5100 | return err; |
5101 | } | 5101 | } |
5102 | 5102 | ||
5103 | static void ring_free_rcu(struct rcu_head *head) | ||
5104 | { | ||
5105 | kfree(container_of(head, struct ixgbe_ring, rcu)); | ||
5106 | } | ||
5107 | |||
5108 | /** | 5103 | /** |
5109 | * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings | 5104 | * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings |
5110 | * @adapter: board private structure to clear interrupt scheme on | 5105 | * @adapter: board private structure to clear interrupt scheme on |
@@ -5126,7 +5121,7 @@ void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter) | |||
5126 | /* ixgbe_get_stats64() might access this ring, we must wait | 5121 | /* ixgbe_get_stats64() might access this ring, we must wait |
5127 | * a grace period before freeing it. | 5122 | * a grace period before freeing it. |
5128 | */ | 5123 | */ |
5129 | call_rcu(&ring->rcu, ring_free_rcu); | 5124 | kfree_rcu(ring, rcu); |
5130 | adapter->rx_ring[i] = NULL; | 5125 | adapter->rx_ring[i] = NULL; |
5131 | } | 5126 | } |
5132 | 5127 | ||
diff --git a/drivers/net/lantiq_etop.c b/drivers/net/lantiq_etop.c new file mode 100644 index 000000000000..45f252b7da30 --- /dev/null +++ b/drivers/net/lantiq_etop.c | |||
@@ -0,0 +1,805 @@ | |||
1 | /* | ||
2 | * This program is free software; you can redistribute it and/or modify it | ||
3 | * under the terms of the GNU General Public License version 2 as published | ||
4 | * by the Free Software Foundation. | ||
5 | * | ||
6 | * This program is distributed in the hope that it will be useful, | ||
7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
8 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
9 | * GNU General Public License for more details. | ||
10 | * | ||
11 | * You should have received a copy of the GNU General Public License | ||
12 | * along with this program; if not, write to the Free Software | ||
13 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. | ||
14 | * | ||
15 | * Copyright (C) 2011 John Crispin <blogic@openwrt.org> | ||
16 | */ | ||
17 | |||
18 | #include <linux/kernel.h> | ||
19 | #include <linux/slab.h> | ||
20 | #include <linux/errno.h> | ||
21 | #include <linux/types.h> | ||
22 | #include <linux/interrupt.h> | ||
23 | #include <linux/uaccess.h> | ||
24 | #include <linux/in.h> | ||
25 | #include <linux/netdevice.h> | ||
26 | #include <linux/etherdevice.h> | ||
27 | #include <linux/phy.h> | ||
28 | #include <linux/ip.h> | ||
29 | #include <linux/tcp.h> | ||
30 | #include <linux/skbuff.h> | ||
31 | #include <linux/mm.h> | ||
32 | #include <linux/platform_device.h> | ||
33 | #include <linux/ethtool.h> | ||
34 | #include <linux/init.h> | ||
35 | #include <linux/delay.h> | ||
36 | #include <linux/io.h> | ||
37 | |||
38 | #include <asm/checksum.h> | ||
39 | |||
40 | #include <lantiq_soc.h> | ||
41 | #include <xway_dma.h> | ||
42 | #include <lantiq_platform.h> | ||
43 | |||
44 | #define LTQ_ETOP_MDIO 0x11804 | ||
45 | #define MDIO_REQUEST 0x80000000 | ||
46 | #define MDIO_READ 0x40000000 | ||
47 | #define MDIO_ADDR_MASK 0x1f | ||
48 | #define MDIO_ADDR_OFFSET 0x15 | ||
49 | #define MDIO_REG_MASK 0x1f | ||
50 | #define MDIO_REG_OFFSET 0x10 | ||
51 | #define MDIO_VAL_MASK 0xffff | ||
52 | |||
53 | #define PPE32_CGEN 0x800 | ||
54 | #define LQ_PPE32_ENET_MAC_CFG 0x1840 | ||
55 | |||
56 | #define LTQ_ETOP_ENETS0 0x11850 | ||
57 | #define LTQ_ETOP_MAC_DA0 0x1186C | ||
58 | #define LTQ_ETOP_MAC_DA1 0x11870 | ||
59 | #define LTQ_ETOP_CFG 0x16020 | ||
60 | #define LTQ_ETOP_IGPLEN 0x16080 | ||
61 | |||
62 | #define MAX_DMA_CHAN 0x8 | ||
63 | #define MAX_DMA_CRC_LEN 0x4 | ||
64 | #define MAX_DMA_DATA_LEN 0x600 | ||
65 | |||
66 | #define ETOP_FTCU BIT(28) | ||
67 | #define ETOP_MII_MASK 0xf | ||
68 | #define ETOP_MII_NORMAL 0xd | ||
69 | #define ETOP_MII_REVERSE 0xe | ||
70 | #define ETOP_PLEN_UNDER 0x40 | ||
71 | #define ETOP_CGEN 0x800 | ||
72 | |||
73 | /* use 2 static channels for TX/RX */ | ||
74 | #define LTQ_ETOP_TX_CHANNEL 1 | ||
75 | #define LTQ_ETOP_RX_CHANNEL 6 | ||
76 | #define IS_TX(x) (x == LTQ_ETOP_TX_CHANNEL) | ||
77 | #define IS_RX(x) (x == LTQ_ETOP_RX_CHANNEL) | ||
78 | |||
79 | #define ltq_etop_r32(x) ltq_r32(ltq_etop_membase + (x)) | ||
80 | #define ltq_etop_w32(x, y) ltq_w32(x, ltq_etop_membase + (y)) | ||
81 | #define ltq_etop_w32_mask(x, y, z) \ | ||
82 | ltq_w32_mask(x, y, ltq_etop_membase + (z)) | ||
83 | |||
84 | #define DRV_VERSION "1.0" | ||
85 | |||
86 | static void __iomem *ltq_etop_membase; | ||
87 | |||
88 | struct ltq_etop_chan { | ||
89 | int idx; | ||
90 | int tx_free; | ||
91 | struct net_device *netdev; | ||
92 | struct napi_struct napi; | ||
93 | struct ltq_dma_channel dma; | ||
94 | struct sk_buff *skb[LTQ_DESC_NUM]; | ||
95 | }; | ||
96 | |||
97 | struct ltq_etop_priv { | ||
98 | struct net_device *netdev; | ||
99 | struct ltq_eth_data *pldata; | ||
100 | struct resource *res; | ||
101 | |||
102 | struct mii_bus *mii_bus; | ||
103 | struct phy_device *phydev; | ||
104 | |||
105 | struct ltq_etop_chan ch[MAX_DMA_CHAN]; | ||
106 | int tx_free[MAX_DMA_CHAN >> 1]; | ||
107 | |||
108 | spinlock_t lock; | ||
109 | }; | ||
110 | |||
111 | static int | ||
112 | ltq_etop_alloc_skb(struct ltq_etop_chan *ch) | ||
113 | { | ||
114 | ch->skb[ch->dma.desc] = dev_alloc_skb(MAX_DMA_DATA_LEN); | ||
115 | if (!ch->skb[ch->dma.desc]) | ||
116 | return -ENOMEM; | ||
117 | ch->dma.desc_base[ch->dma.desc].addr = dma_map_single(NULL, | ||
118 | ch->skb[ch->dma.desc]->data, MAX_DMA_DATA_LEN, | ||
119 | DMA_FROM_DEVICE); | ||
120 | ch->dma.desc_base[ch->dma.desc].addr = | ||
121 | CPHYSADDR(ch->skb[ch->dma.desc]->data); | ||
122 | ch->dma.desc_base[ch->dma.desc].ctl = | ||
123 | LTQ_DMA_OWN | LTQ_DMA_RX_OFFSET(NET_IP_ALIGN) | | ||
124 | MAX_DMA_DATA_LEN; | ||
125 | skb_reserve(ch->skb[ch->dma.desc], NET_IP_ALIGN); | ||
126 | return 0; | ||
127 | } | ||
128 | |||
129 | static void | ||
130 | ltq_etop_hw_receive(struct ltq_etop_chan *ch) | ||
131 | { | ||
132 | struct ltq_etop_priv *priv = netdev_priv(ch->netdev); | ||
133 | struct ltq_dma_desc *desc = &ch->dma.desc_base[ch->dma.desc]; | ||
134 | struct sk_buff *skb = ch->skb[ch->dma.desc]; | ||
135 | int len = (desc->ctl & LTQ_DMA_SIZE_MASK) - MAX_DMA_CRC_LEN; | ||
136 | unsigned long flags; | ||
137 | |||
138 | spin_lock_irqsave(&priv->lock, flags); | ||
139 | if (ltq_etop_alloc_skb(ch)) { | ||
140 | netdev_err(ch->netdev, | ||
141 | "failed to allocate new rx buffer, stopping DMA\n"); | ||
142 | ltq_dma_close(&ch->dma); | ||
143 | } | ||
144 | ch->dma.desc++; | ||
145 | ch->dma.desc %= LTQ_DESC_NUM; | ||
146 | spin_unlock_irqrestore(&priv->lock, flags); | ||
147 | |||
148 | skb_put(skb, len); | ||
149 | skb->dev = ch->netdev; | ||
150 | skb->protocol = eth_type_trans(skb, ch->netdev); | ||
151 | netif_receive_skb(skb); | ||
152 | } | ||
153 | |||
154 | static int | ||
155 | ltq_etop_poll_rx(struct napi_struct *napi, int budget) | ||
156 | { | ||
157 | struct ltq_etop_chan *ch = container_of(napi, | ||
158 | struct ltq_etop_chan, napi); | ||
159 | int rx = 0; | ||
160 | int complete = 0; | ||
161 | |||
162 | while ((rx < budget) && !complete) { | ||
163 | struct ltq_dma_desc *desc = &ch->dma.desc_base[ch->dma.desc]; | ||
164 | |||
165 | if ((desc->ctl & (LTQ_DMA_OWN | LTQ_DMA_C)) == LTQ_DMA_C) { | ||
166 | ltq_etop_hw_receive(ch); | ||
167 | rx++; | ||
168 | } else { | ||
169 | complete = 1; | ||
170 | } | ||
171 | } | ||
172 | if (complete || !rx) { | ||
173 | napi_complete(&ch->napi); | ||
174 | ltq_dma_ack_irq(&ch->dma); | ||
175 | } | ||
176 | return rx; | ||
177 | } | ||
178 | |||
179 | static int | ||
180 | ltq_etop_poll_tx(struct napi_struct *napi, int budget) | ||
181 | { | ||
182 | struct ltq_etop_chan *ch = | ||
183 | container_of(napi, struct ltq_etop_chan, napi); | ||
184 | struct ltq_etop_priv *priv = netdev_priv(ch->netdev); | ||
185 | struct netdev_queue *txq = | ||
186 | netdev_get_tx_queue(ch->netdev, ch->idx >> 1); | ||
187 | unsigned long flags; | ||
188 | |||
189 | spin_lock_irqsave(&priv->lock, flags); | ||
190 | while ((ch->dma.desc_base[ch->tx_free].ctl & | ||
191 | (LTQ_DMA_OWN | LTQ_DMA_C)) == LTQ_DMA_C) { | ||
192 | dev_kfree_skb_any(ch->skb[ch->tx_free]); | ||
193 | ch->skb[ch->tx_free] = NULL; | ||
194 | memset(&ch->dma.desc_base[ch->tx_free], 0, | ||
195 | sizeof(struct ltq_dma_desc)); | ||
196 | ch->tx_free++; | ||
197 | ch->tx_free %= LTQ_DESC_NUM; | ||
198 | } | ||
199 | spin_unlock_irqrestore(&priv->lock, flags); | ||
200 | |||
201 | if (netif_tx_queue_stopped(txq)) | ||
202 | netif_tx_start_queue(txq); | ||
203 | napi_complete(&ch->napi); | ||
204 | ltq_dma_ack_irq(&ch->dma); | ||
205 | return 1; | ||
206 | } | ||
207 | |||
208 | static irqreturn_t | ||
209 | ltq_etop_dma_irq(int irq, void *_priv) | ||
210 | { | ||
211 | struct ltq_etop_priv *priv = _priv; | ||
212 | int ch = irq - LTQ_DMA_CH0_INT; | ||
213 | |||
214 | napi_schedule(&priv->ch[ch].napi); | ||
215 | return IRQ_HANDLED; | ||
216 | } | ||
217 | |||
218 | static void | ||
219 | ltq_etop_free_channel(struct net_device *dev, struct ltq_etop_chan *ch) | ||
220 | { | ||
221 | struct ltq_etop_priv *priv = netdev_priv(dev); | ||
222 | |||
223 | ltq_dma_free(&ch->dma); | ||
224 | if (ch->dma.irq) | ||
225 | free_irq(ch->dma.irq, priv); | ||
226 | if (IS_RX(ch->idx)) { | ||
227 | int desc; | ||
228 | for (desc = 0; desc < LTQ_DESC_NUM; desc++) | ||
229 | dev_kfree_skb_any(ch->skb[ch->dma.desc]); | ||
230 | } | ||
231 | } | ||
232 | |||
233 | static void | ||
234 | ltq_etop_hw_exit(struct net_device *dev) | ||
235 | { | ||
236 | struct ltq_etop_priv *priv = netdev_priv(dev); | ||
237 | int i; | ||
238 | |||
239 | ltq_pmu_disable(PMU_PPE); | ||
240 | for (i = 0; i < MAX_DMA_CHAN; i++) | ||
241 | if (IS_TX(i) || IS_RX(i)) | ||
242 | ltq_etop_free_channel(dev, &priv->ch[i]); | ||
243 | } | ||
244 | |||
245 | static int | ||
246 | ltq_etop_hw_init(struct net_device *dev) | ||
247 | { | ||
248 | struct ltq_etop_priv *priv = netdev_priv(dev); | ||
249 | int i; | ||
250 | |||
251 | ltq_pmu_enable(PMU_PPE); | ||
252 | |||
253 | switch (priv->pldata->mii_mode) { | ||
254 | case PHY_INTERFACE_MODE_RMII: | ||
255 | ltq_etop_w32_mask(ETOP_MII_MASK, | ||
256 | ETOP_MII_REVERSE, LTQ_ETOP_CFG); | ||
257 | break; | ||
258 | |||
259 | case PHY_INTERFACE_MODE_MII: | ||
260 | ltq_etop_w32_mask(ETOP_MII_MASK, | ||
261 | ETOP_MII_NORMAL, LTQ_ETOP_CFG); | ||
262 | break; | ||
263 | |||
264 | default: | ||
265 | netdev_err(dev, "unknown mii mode %d\n", | ||
266 | priv->pldata->mii_mode); | ||
267 | return -ENOTSUPP; | ||
268 | } | ||
269 | |||
270 | /* enable crc generation */ | ||
271 | ltq_etop_w32(PPE32_CGEN, LQ_PPE32_ENET_MAC_CFG); | ||
272 | |||
273 | ltq_dma_init_port(DMA_PORT_ETOP); | ||
274 | |||
275 | for (i = 0; i < MAX_DMA_CHAN; i++) { | ||
276 | int irq = LTQ_DMA_CH0_INT + i; | ||
277 | struct ltq_etop_chan *ch = &priv->ch[i]; | ||
278 | |||
279 | ch->idx = ch->dma.nr = i; | ||
280 | |||
281 | if (IS_TX(i)) { | ||
282 | ltq_dma_alloc_tx(&ch->dma); | ||
283 | request_irq(irq, ltq_etop_dma_irq, IRQF_DISABLED, | ||
284 | "etop_tx", priv); | ||
285 | } else if (IS_RX(i)) { | ||
286 | ltq_dma_alloc_rx(&ch->dma); | ||
287 | for (ch->dma.desc = 0; ch->dma.desc < LTQ_DESC_NUM; | ||
288 | ch->dma.desc++) | ||
289 | if (ltq_etop_alloc_skb(ch)) | ||
290 | return -ENOMEM; | ||
291 | ch->dma.desc = 0; | ||
292 | request_irq(irq, ltq_etop_dma_irq, IRQF_DISABLED, | ||
293 | "etop_rx", priv); | ||
294 | } | ||
295 | ch->dma.irq = irq; | ||
296 | } | ||
297 | return 0; | ||
298 | } | ||
299 | |||
300 | static void | ||
301 | ltq_etop_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) | ||
302 | { | ||
303 | strcpy(info->driver, "Lantiq ETOP"); | ||
304 | strcpy(info->bus_info, "internal"); | ||
305 | strcpy(info->version, DRV_VERSION); | ||
306 | } | ||
307 | |||
308 | static int | ||
309 | ltq_etop_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) | ||
310 | { | ||
311 | struct ltq_etop_priv *priv = netdev_priv(dev); | ||
312 | |||
313 | return phy_ethtool_gset(priv->phydev, cmd); | ||
314 | } | ||
315 | |||
316 | static int | ||
317 | ltq_etop_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) | ||
318 | { | ||
319 | struct ltq_etop_priv *priv = netdev_priv(dev); | ||
320 | |||
321 | return phy_ethtool_sset(priv->phydev, cmd); | ||
322 | } | ||
323 | |||
324 | static int | ||
325 | ltq_etop_nway_reset(struct net_device *dev) | ||
326 | { | ||
327 | struct ltq_etop_priv *priv = netdev_priv(dev); | ||
328 | |||
329 | return phy_start_aneg(priv->phydev); | ||
330 | } | ||
331 | |||
332 | static const struct ethtool_ops ltq_etop_ethtool_ops = { | ||
333 | .get_drvinfo = ltq_etop_get_drvinfo, | ||
334 | .get_settings = ltq_etop_get_settings, | ||
335 | .set_settings = ltq_etop_set_settings, | ||
336 | .nway_reset = ltq_etop_nway_reset, | ||
337 | }; | ||
338 | |||
339 | static int | ||
340 | ltq_etop_mdio_wr(struct mii_bus *bus, int phy_addr, int phy_reg, u16 phy_data) | ||
341 | { | ||
342 | u32 val = MDIO_REQUEST | | ||
343 | ((phy_addr & MDIO_ADDR_MASK) << MDIO_ADDR_OFFSET) | | ||
344 | ((phy_reg & MDIO_REG_MASK) << MDIO_REG_OFFSET) | | ||
345 | phy_data; | ||
346 | |||
347 | while (ltq_etop_r32(LTQ_ETOP_MDIO) & MDIO_REQUEST) | ||
348 | ; | ||
349 | ltq_etop_w32(val, LTQ_ETOP_MDIO); | ||
350 | return 0; | ||
351 | } | ||
352 | |||
353 | static int | ||
354 | ltq_etop_mdio_rd(struct mii_bus *bus, int phy_addr, int phy_reg) | ||
355 | { | ||
356 | u32 val = MDIO_REQUEST | MDIO_READ | | ||
357 | ((phy_addr & MDIO_ADDR_MASK) << MDIO_ADDR_OFFSET) | | ||
358 | ((phy_reg & MDIO_REG_MASK) << MDIO_REG_OFFSET); | ||
359 | |||
360 | while (ltq_etop_r32(LTQ_ETOP_MDIO) & MDIO_REQUEST) | ||
361 | ; | ||
362 | ltq_etop_w32(val, LTQ_ETOP_MDIO); | ||
363 | while (ltq_etop_r32(LTQ_ETOP_MDIO) & MDIO_REQUEST) | ||
364 | ; | ||
365 | val = ltq_etop_r32(LTQ_ETOP_MDIO) & MDIO_VAL_MASK; | ||
366 | return val; | ||
367 | } | ||
368 | |||
369 | static void | ||
370 | ltq_etop_mdio_link(struct net_device *dev) | ||
371 | { | ||
372 | /* nothing to do */ | ||
373 | } | ||
374 | |||
375 | static int | ||
376 | ltq_etop_mdio_probe(struct net_device *dev) | ||
377 | { | ||
378 | struct ltq_etop_priv *priv = netdev_priv(dev); | ||
379 | struct phy_device *phydev = NULL; | ||
380 | int phy_addr; | ||
381 | |||
382 | for (phy_addr = 0; phy_addr < PHY_MAX_ADDR; phy_addr++) { | ||
383 | if (priv->mii_bus->phy_map[phy_addr]) { | ||
384 | phydev = priv->mii_bus->phy_map[phy_addr]; | ||
385 | break; | ||
386 | } | ||
387 | } | ||
388 | |||
389 | if (!phydev) { | ||
390 | netdev_err(dev, "no PHY found\n"); | ||
391 | return -ENODEV; | ||
392 | } | ||
393 | |||
394 | phydev = phy_connect(dev, dev_name(&phydev->dev), <q_etop_mdio_link, | ||
395 | 0, priv->pldata->mii_mode); | ||
396 | |||
397 | if (IS_ERR(phydev)) { | ||
398 | netdev_err(dev, "Could not attach to PHY\n"); | ||
399 | return PTR_ERR(phydev); | ||
400 | } | ||
401 | |||
402 | phydev->supported &= (SUPPORTED_10baseT_Half | ||
403 | | SUPPORTED_10baseT_Full | ||
404 | | SUPPORTED_100baseT_Half | ||
405 | | SUPPORTED_100baseT_Full | ||
406 | | SUPPORTED_Autoneg | ||
407 | | SUPPORTED_MII | ||
408 | | SUPPORTED_TP); | ||
409 | |||
410 | phydev->advertising = phydev->supported; | ||
411 | priv->phydev = phydev; | ||
412 | pr_info("%s: attached PHY [%s] (phy_addr=%s, irq=%d)\n", | ||
413 | dev->name, phydev->drv->name, | ||
414 | dev_name(&phydev->dev), phydev->irq); | ||
415 | |||
416 | return 0; | ||
417 | } | ||
418 | |||
419 | static int | ||
420 | ltq_etop_mdio_init(struct net_device *dev) | ||
421 | { | ||
422 | struct ltq_etop_priv *priv = netdev_priv(dev); | ||
423 | int i; | ||
424 | int err; | ||
425 | |||
426 | priv->mii_bus = mdiobus_alloc(); | ||
427 | if (!priv->mii_bus) { | ||
428 | netdev_err(dev, "failed to allocate mii bus\n"); | ||
429 | err = -ENOMEM; | ||
430 | goto err_out; | ||
431 | } | ||
432 | |||
433 | priv->mii_bus->priv = dev; | ||
434 | priv->mii_bus->read = ltq_etop_mdio_rd; | ||
435 | priv->mii_bus->write = ltq_etop_mdio_wr; | ||
436 | priv->mii_bus->name = "ltq_mii"; | ||
437 | snprintf(priv->mii_bus->id, MII_BUS_ID_SIZE, "%x", 0); | ||
438 | priv->mii_bus->irq = kmalloc(sizeof(int) * PHY_MAX_ADDR, GFP_KERNEL); | ||
439 | if (!priv->mii_bus->irq) { | ||
440 | err = -ENOMEM; | ||
441 | goto err_out_free_mdiobus; | ||
442 | } | ||
443 | |||
444 | for (i = 0; i < PHY_MAX_ADDR; ++i) | ||
445 | priv->mii_bus->irq[i] = PHY_POLL; | ||
446 | |||
447 | if (mdiobus_register(priv->mii_bus)) { | ||
448 | err = -ENXIO; | ||
449 | goto err_out_free_mdio_irq; | ||
450 | } | ||
451 | |||
452 | if (ltq_etop_mdio_probe(dev)) { | ||
453 | err = -ENXIO; | ||
454 | goto err_out_unregister_bus; | ||
455 | } | ||
456 | return 0; | ||
457 | |||
458 | err_out_unregister_bus: | ||
459 | mdiobus_unregister(priv->mii_bus); | ||
460 | err_out_free_mdio_irq: | ||
461 | kfree(priv->mii_bus->irq); | ||
462 | err_out_free_mdiobus: | ||
463 | mdiobus_free(priv->mii_bus); | ||
464 | err_out: | ||
465 | return err; | ||
466 | } | ||
467 | |||
468 | static void | ||
469 | ltq_etop_mdio_cleanup(struct net_device *dev) | ||
470 | { | ||
471 | struct ltq_etop_priv *priv = netdev_priv(dev); | ||
472 | |||
473 | phy_disconnect(priv->phydev); | ||
474 | mdiobus_unregister(priv->mii_bus); | ||
475 | kfree(priv->mii_bus->irq); | ||
476 | mdiobus_free(priv->mii_bus); | ||
477 | } | ||
478 | |||
479 | static int | ||
480 | ltq_etop_open(struct net_device *dev) | ||
481 | { | ||
482 | struct ltq_etop_priv *priv = netdev_priv(dev); | ||
483 | int i; | ||
484 | |||
485 | for (i = 0; i < MAX_DMA_CHAN; i++) { | ||
486 | struct ltq_etop_chan *ch = &priv->ch[i]; | ||
487 | |||
488 | if (!IS_TX(i) && (!IS_RX(i))) | ||
489 | continue; | ||
490 | ltq_dma_open(&ch->dma); | ||
491 | napi_enable(&ch->napi); | ||
492 | } | ||
493 | phy_start(priv->phydev); | ||
494 | netif_tx_start_all_queues(dev); | ||
495 | return 0; | ||
496 | } | ||
497 | |||
498 | static int | ||
499 | ltq_etop_stop(struct net_device *dev) | ||
500 | { | ||
501 | struct ltq_etop_priv *priv = netdev_priv(dev); | ||
502 | int i; | ||
503 | |||
504 | netif_tx_stop_all_queues(dev); | ||
505 | phy_stop(priv->phydev); | ||
506 | for (i = 0; i < MAX_DMA_CHAN; i++) { | ||
507 | struct ltq_etop_chan *ch = &priv->ch[i]; | ||
508 | |||
509 | if (!IS_RX(i) && !IS_TX(i)) | ||
510 | continue; | ||
511 | napi_disable(&ch->napi); | ||
512 | ltq_dma_close(&ch->dma); | ||
513 | } | ||
514 | return 0; | ||
515 | } | ||
516 | |||
517 | static int | ||
518 | ltq_etop_tx(struct sk_buff *skb, struct net_device *dev) | ||
519 | { | ||
520 | int queue = skb_get_queue_mapping(skb); | ||
521 | struct netdev_queue *txq = netdev_get_tx_queue(dev, queue); | ||
522 | struct ltq_etop_priv *priv = netdev_priv(dev); | ||
523 | struct ltq_etop_chan *ch = &priv->ch[(queue << 1) | 1]; | ||
524 | struct ltq_dma_desc *desc = &ch->dma.desc_base[ch->dma.desc]; | ||
525 | int len; | ||
526 | unsigned long flags; | ||
527 | u32 byte_offset; | ||
528 | |||
529 | len = skb->len < ETH_ZLEN ? ETH_ZLEN : skb->len; | ||
530 | |||
531 | if ((desc->ctl & (LTQ_DMA_OWN | LTQ_DMA_C)) || ch->skb[ch->dma.desc]) { | ||
532 | dev_kfree_skb_any(skb); | ||
533 | netdev_err(dev, "tx ring full\n"); | ||
534 | netif_tx_stop_queue(txq); | ||
535 | return NETDEV_TX_BUSY; | ||
536 | } | ||
537 | |||
538 | /* dma needs to start on a 16 byte aligned address */ | ||
539 | byte_offset = CPHYSADDR(skb->data) % 16; | ||
540 | ch->skb[ch->dma.desc] = skb; | ||
541 | |||
542 | dev->trans_start = jiffies; | ||
543 | |||
544 | spin_lock_irqsave(&priv->lock, flags); | ||
545 | desc->addr = ((unsigned int) dma_map_single(NULL, skb->data, len, | ||
546 | DMA_TO_DEVICE)) - byte_offset; | ||
547 | wmb(); | ||
548 | desc->ctl = LTQ_DMA_OWN | LTQ_DMA_SOP | LTQ_DMA_EOP | | ||
549 | LTQ_DMA_TX_OFFSET(byte_offset) | (len & LTQ_DMA_SIZE_MASK); | ||
550 | ch->dma.desc++; | ||
551 | ch->dma.desc %= LTQ_DESC_NUM; | ||
552 | spin_unlock_irqrestore(&priv->lock, flags); | ||
553 | |||
554 | if (ch->dma.desc_base[ch->dma.desc].ctl & LTQ_DMA_OWN) | ||
555 | netif_tx_stop_queue(txq); | ||
556 | |||
557 | return NETDEV_TX_OK; | ||
558 | } | ||
559 | |||
560 | static int | ||
561 | ltq_etop_change_mtu(struct net_device *dev, int new_mtu) | ||
562 | { | ||
563 | int ret = eth_change_mtu(dev, new_mtu); | ||
564 | |||
565 | if (!ret) { | ||
566 | struct ltq_etop_priv *priv = netdev_priv(dev); | ||
567 | unsigned long flags; | ||
568 | |||
569 | spin_lock_irqsave(&priv->lock, flags); | ||
570 | ltq_etop_w32((ETOP_PLEN_UNDER << 16) | new_mtu, | ||
571 | LTQ_ETOP_IGPLEN); | ||
572 | spin_unlock_irqrestore(&priv->lock, flags); | ||
573 | } | ||
574 | return ret; | ||
575 | } | ||
576 | |||
577 | static int | ||
578 | ltq_etop_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) | ||
579 | { | ||
580 | struct ltq_etop_priv *priv = netdev_priv(dev); | ||
581 | |||
582 | /* TODO: mii-toll reports "No MII transceiver present!." ?!*/ | ||
583 | return phy_mii_ioctl(priv->phydev, rq, cmd); | ||
584 | } | ||
585 | |||
586 | static int | ||
587 | ltq_etop_set_mac_address(struct net_device *dev, void *p) | ||
588 | { | ||
589 | int ret = eth_mac_addr(dev, p); | ||
590 | |||
591 | if (!ret) { | ||
592 | struct ltq_etop_priv *priv = netdev_priv(dev); | ||
593 | unsigned long flags; | ||
594 | |||
595 | /* store the mac for the unicast filter */ | ||
596 | spin_lock_irqsave(&priv->lock, flags); | ||
597 | ltq_etop_w32(*((u32 *)dev->dev_addr), LTQ_ETOP_MAC_DA0); | ||
598 | ltq_etop_w32(*((u16 *)&dev->dev_addr[4]) << 16, | ||
599 | LTQ_ETOP_MAC_DA1); | ||
600 | spin_unlock_irqrestore(&priv->lock, flags); | ||
601 | } | ||
602 | return ret; | ||
603 | } | ||
604 | |||
605 | static void | ||
606 | ltq_etop_set_multicast_list(struct net_device *dev) | ||
607 | { | ||
608 | struct ltq_etop_priv *priv = netdev_priv(dev); | ||
609 | unsigned long flags; | ||
610 | |||
611 | /* ensure that the unicast filter is not enabled in promiscious mode */ | ||
612 | spin_lock_irqsave(&priv->lock, flags); | ||
613 | if ((dev->flags & IFF_PROMISC) || (dev->flags & IFF_ALLMULTI)) | ||
614 | ltq_etop_w32_mask(ETOP_FTCU, 0, LTQ_ETOP_ENETS0); | ||
615 | else | ||
616 | ltq_etop_w32_mask(0, ETOP_FTCU, LTQ_ETOP_ENETS0); | ||
617 | spin_unlock_irqrestore(&priv->lock, flags); | ||
618 | } | ||
619 | |||
620 | static u16 | ||
621 | ltq_etop_select_queue(struct net_device *dev, struct sk_buff *skb) | ||
622 | { | ||
623 | /* we are currently only using the first queue */ | ||
624 | return 0; | ||
625 | } | ||
626 | |||
627 | static int | ||
628 | ltq_etop_init(struct net_device *dev) | ||
629 | { | ||
630 | struct ltq_etop_priv *priv = netdev_priv(dev); | ||
631 | struct sockaddr mac; | ||
632 | int err; | ||
633 | |||
634 | ether_setup(dev); | ||
635 | dev->watchdog_timeo = 10 * HZ; | ||
636 | err = ltq_etop_hw_init(dev); | ||
637 | if (err) | ||
638 | goto err_hw; | ||
639 | ltq_etop_change_mtu(dev, 1500); | ||
640 | |||
641 | memcpy(&mac, &priv->pldata->mac, sizeof(struct sockaddr)); | ||
642 | if (!is_valid_ether_addr(mac.sa_data)) { | ||
643 | pr_warn("etop: invalid MAC, using random\n"); | ||
644 | random_ether_addr(mac.sa_data); | ||
645 | } | ||
646 | |||
647 | err = ltq_etop_set_mac_address(dev, &mac); | ||
648 | if (err) | ||
649 | goto err_netdev; | ||
650 | ltq_etop_set_multicast_list(dev); | ||
651 | err = ltq_etop_mdio_init(dev); | ||
652 | if (err) | ||
653 | goto err_netdev; | ||
654 | return 0; | ||
655 | |||
656 | err_netdev: | ||
657 | unregister_netdev(dev); | ||
658 | free_netdev(dev); | ||
659 | err_hw: | ||
660 | ltq_etop_hw_exit(dev); | ||
661 | return err; | ||
662 | } | ||
663 | |||
664 | static void | ||
665 | ltq_etop_tx_timeout(struct net_device *dev) | ||
666 | { | ||
667 | int err; | ||
668 | |||
669 | ltq_etop_hw_exit(dev); | ||
670 | err = ltq_etop_hw_init(dev); | ||
671 | if (err) | ||
672 | goto err_hw; | ||
673 | dev->trans_start = jiffies; | ||
674 | netif_wake_queue(dev); | ||
675 | return; | ||
676 | |||
677 | err_hw: | ||
678 | ltq_etop_hw_exit(dev); | ||
679 | netdev_err(dev, "failed to restart etop after TX timeout\n"); | ||
680 | } | ||
681 | |||
682 | static const struct net_device_ops ltq_eth_netdev_ops = { | ||
683 | .ndo_open = ltq_etop_open, | ||
684 | .ndo_stop = ltq_etop_stop, | ||
685 | .ndo_start_xmit = ltq_etop_tx, | ||
686 | .ndo_change_mtu = ltq_etop_change_mtu, | ||
687 | .ndo_do_ioctl = ltq_etop_ioctl, | ||
688 | .ndo_set_mac_address = ltq_etop_set_mac_address, | ||
689 | .ndo_validate_addr = eth_validate_addr, | ||
690 | .ndo_set_multicast_list = ltq_etop_set_multicast_list, | ||
691 | .ndo_select_queue = ltq_etop_select_queue, | ||
692 | .ndo_init = ltq_etop_init, | ||
693 | .ndo_tx_timeout = ltq_etop_tx_timeout, | ||
694 | }; | ||
695 | |||
696 | static int __init | ||
697 | ltq_etop_probe(struct platform_device *pdev) | ||
698 | { | ||
699 | struct net_device *dev; | ||
700 | struct ltq_etop_priv *priv; | ||
701 | struct resource *res; | ||
702 | int err; | ||
703 | int i; | ||
704 | |||
705 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
706 | if (!res) { | ||
707 | dev_err(&pdev->dev, "failed to get etop resource\n"); | ||
708 | err = -ENOENT; | ||
709 | goto err_out; | ||
710 | } | ||
711 | |||
712 | res = devm_request_mem_region(&pdev->dev, res->start, | ||
713 | resource_size(res), dev_name(&pdev->dev)); | ||
714 | if (!res) { | ||
715 | dev_err(&pdev->dev, "failed to request etop resource\n"); | ||
716 | err = -EBUSY; | ||
717 | goto err_out; | ||
718 | } | ||
719 | |||
720 | ltq_etop_membase = devm_ioremap_nocache(&pdev->dev, | ||
721 | res->start, resource_size(res)); | ||
722 | if (!ltq_etop_membase) { | ||
723 | dev_err(&pdev->dev, "failed to remap etop engine %d\n", | ||
724 | pdev->id); | ||
725 | err = -ENOMEM; | ||
726 | goto err_out; | ||
727 | } | ||
728 | |||
729 | dev = alloc_etherdev_mq(sizeof(struct ltq_etop_priv), 4); | ||
730 | strcpy(dev->name, "eth%d"); | ||
731 | dev->netdev_ops = <q_eth_netdev_ops; | ||
732 | dev->ethtool_ops = <q_etop_ethtool_ops; | ||
733 | priv = netdev_priv(dev); | ||
734 | priv->res = res; | ||
735 | priv->pldata = dev_get_platdata(&pdev->dev); | ||
736 | priv->netdev = dev; | ||
737 | spin_lock_init(&priv->lock); | ||
738 | |||
739 | for (i = 0; i < MAX_DMA_CHAN; i++) { | ||
740 | if (IS_TX(i)) | ||
741 | netif_napi_add(dev, &priv->ch[i].napi, | ||
742 | ltq_etop_poll_tx, 8); | ||
743 | else if (IS_RX(i)) | ||
744 | netif_napi_add(dev, &priv->ch[i].napi, | ||
745 | ltq_etop_poll_rx, 32); | ||
746 | priv->ch[i].netdev = dev; | ||
747 | } | ||
748 | |||
749 | err = register_netdev(dev); | ||
750 | if (err) | ||
751 | goto err_free; | ||
752 | |||
753 | platform_set_drvdata(pdev, dev); | ||
754 | return 0; | ||
755 | |||
756 | err_free: | ||
757 | kfree(dev); | ||
758 | err_out: | ||
759 | return err; | ||
760 | } | ||
761 | |||
762 | static int __devexit | ||
763 | ltq_etop_remove(struct platform_device *pdev) | ||
764 | { | ||
765 | struct net_device *dev = platform_get_drvdata(pdev); | ||
766 | |||
767 | if (dev) { | ||
768 | netif_tx_stop_all_queues(dev); | ||
769 | ltq_etop_hw_exit(dev); | ||
770 | ltq_etop_mdio_cleanup(dev); | ||
771 | unregister_netdev(dev); | ||
772 | } | ||
773 | return 0; | ||
774 | } | ||
775 | |||
776 | static struct platform_driver ltq_mii_driver = { | ||
777 | .remove = __devexit_p(ltq_etop_remove), | ||
778 | .driver = { | ||
779 | .name = "ltq_etop", | ||
780 | .owner = THIS_MODULE, | ||
781 | }, | ||
782 | }; | ||
783 | |||
784 | int __init | ||
785 | init_ltq_etop(void) | ||
786 | { | ||
787 | int ret = platform_driver_probe(<q_mii_driver, ltq_etop_probe); | ||
788 | |||
789 | if (ret) | ||
790 | pr_err("ltq_etop: Error registering platfom driver!"); | ||
791 | return ret; | ||
792 | } | ||
793 | |||
794 | static void __exit | ||
795 | exit_ltq_etop(void) | ||
796 | { | ||
797 | platform_driver_unregister(<q_mii_driver); | ||
798 | } | ||
799 | |||
800 | module_init(init_ltq_etop); | ||
801 | module_exit(exit_ltq_etop); | ||
802 | |||
803 | MODULE_AUTHOR("John Crispin <blogic@openwrt.org>"); | ||
804 | MODULE_DESCRIPTION("Lantiq SoC ETOP"); | ||
805 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c index 78e34e9e4f00..d8e4e69ad0b9 100644 --- a/drivers/net/macvlan.c +++ b/drivers/net/macvlan.c | |||
@@ -603,21 +603,13 @@ static int macvlan_port_create(struct net_device *dev) | |||
603 | return err; | 603 | return err; |
604 | } | 604 | } |
605 | 605 | ||
606 | static void macvlan_port_rcu_free(struct rcu_head *head) | ||
607 | { | ||
608 | struct macvlan_port *port; | ||
609 | |||
610 | port = container_of(head, struct macvlan_port, rcu); | ||
611 | kfree(port); | ||
612 | } | ||
613 | |||
614 | static void macvlan_port_destroy(struct net_device *dev) | 606 | static void macvlan_port_destroy(struct net_device *dev) |
615 | { | 607 | { |
616 | struct macvlan_port *port = macvlan_port_get(dev); | 608 | struct macvlan_port *port = macvlan_port_get(dev); |
617 | 609 | ||
618 | dev->priv_flags &= ~IFF_MACVLAN_PORT; | 610 | dev->priv_flags &= ~IFF_MACVLAN_PORT; |
619 | netdev_rx_handler_unregister(dev); | 611 | netdev_rx_handler_unregister(dev); |
620 | call_rcu(&port->rcu, macvlan_port_rcu_free); | 612 | kfree_rcu(port, rcu); |
621 | } | 613 | } |
622 | 614 | ||
623 | static int macvlan_validate(struct nlattr *tb[], struct nlattr *data[]) | 615 | static int macvlan_validate(struct nlattr *tb[], struct nlattr *data[]) |
diff --git a/drivers/pci/intel-iommu.c b/drivers/pci/intel-iommu.c index d552d2c77844..6af6b628175b 100644 --- a/drivers/pci/intel-iommu.c +++ b/drivers/pci/intel-iommu.c | |||
@@ -39,6 +39,7 @@ | |||
39 | #include <linux/syscore_ops.h> | 39 | #include <linux/syscore_ops.h> |
40 | #include <linux/tboot.h> | 40 | #include <linux/tboot.h> |
41 | #include <linux/dmi.h> | 41 | #include <linux/dmi.h> |
42 | #include <linux/pci-ats.h> | ||
42 | #include <asm/cacheflush.h> | 43 | #include <asm/cacheflush.h> |
43 | #include <asm/iommu.h> | 44 | #include <asm/iommu.h> |
44 | #include "pci.h" | 45 | #include "pci.h" |
diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index 553d8ee55c1c..42fae4776515 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c | |||
@@ -13,6 +13,7 @@ | |||
13 | #include <linux/mutex.h> | 13 | #include <linux/mutex.h> |
14 | #include <linux/string.h> | 14 | #include <linux/string.h> |
15 | #include <linux/delay.h> | 15 | #include <linux/delay.h> |
16 | #include <linux/pci-ats.h> | ||
16 | #include "pci.h" | 17 | #include "pci.h" |
17 | 18 | ||
18 | #define VIRTFN_ID_LEN 16 | 19 | #define VIRTFN_ID_LEN 16 |
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index a6ec200fe5ee..4020025f854e 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h | |||
@@ -250,15 +250,6 @@ struct pci_sriov { | |||
250 | u8 __iomem *mstate; /* VF Migration State Array */ | 250 | u8 __iomem *mstate; /* VF Migration State Array */ |
251 | }; | 251 | }; |
252 | 252 | ||
253 | /* Address Translation Service */ | ||
254 | struct pci_ats { | ||
255 | int pos; /* capability position */ | ||
256 | int stu; /* Smallest Translation Unit */ | ||
257 | int qdep; /* Invalidate Queue Depth */ | ||
258 | int ref_cnt; /* Physical Function reference count */ | ||
259 | unsigned int is_enabled:1; /* Enable bit is set */ | ||
260 | }; | ||
261 | |||
262 | #ifdef CONFIG_PCI_IOV | 253 | #ifdef CONFIG_PCI_IOV |
263 | extern int pci_iov_init(struct pci_dev *dev); | 254 | extern int pci_iov_init(struct pci_dev *dev); |
264 | extern void pci_iov_release(struct pci_dev *dev); | 255 | extern void pci_iov_release(struct pci_dev *dev); |
@@ -269,19 +260,6 @@ extern resource_size_t pci_sriov_resource_alignment(struct pci_dev *dev, | |||
269 | extern void pci_restore_iov_state(struct pci_dev *dev); | 260 | extern void pci_restore_iov_state(struct pci_dev *dev); |
270 | extern int pci_iov_bus_range(struct pci_bus *bus); | 261 | extern int pci_iov_bus_range(struct pci_bus *bus); |
271 | 262 | ||
272 | extern int pci_enable_ats(struct pci_dev *dev, int ps); | ||
273 | extern void pci_disable_ats(struct pci_dev *dev); | ||
274 | extern int pci_ats_queue_depth(struct pci_dev *dev); | ||
275 | /** | ||
276 | * pci_ats_enabled - query the ATS status | ||
277 | * @dev: the PCI device | ||
278 | * | ||
279 | * Returns 1 if ATS capability is enabled, or 0 if not. | ||
280 | */ | ||
281 | static inline int pci_ats_enabled(struct pci_dev *dev) | ||
282 | { | ||
283 | return dev->ats && dev->ats->is_enabled; | ||
284 | } | ||
285 | #else | 263 | #else |
286 | static inline int pci_iov_init(struct pci_dev *dev) | 264 | static inline int pci_iov_init(struct pci_dev *dev) |
287 | { | 265 | { |
@@ -304,21 +282,6 @@ static inline int pci_iov_bus_range(struct pci_bus *bus) | |||
304 | return 0; | 282 | return 0; |
305 | } | 283 | } |
306 | 284 | ||
307 | static inline int pci_enable_ats(struct pci_dev *dev, int ps) | ||
308 | { | ||
309 | return -ENODEV; | ||
310 | } | ||
311 | static inline void pci_disable_ats(struct pci_dev *dev) | ||
312 | { | ||
313 | } | ||
314 | static inline int pci_ats_queue_depth(struct pci_dev *dev) | ||
315 | { | ||
316 | return -ENODEV; | ||
317 | } | ||
318 | static inline int pci_ats_enabled(struct pci_dev *dev) | ||
319 | { | ||
320 | return 0; | ||
321 | } | ||
322 | #endif /* CONFIG_PCI_IOV */ | 285 | #endif /* CONFIG_PCI_IOV */ |
323 | 286 | ||
324 | static inline resource_size_t pci_resource_alignment(struct pci_dev *dev, | 287 | static inline resource_size_t pci_resource_alignment(struct pci_dev *dev, |
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig index e1878877399c..42891726ea72 100644 --- a/drivers/rtc/Kconfig +++ b/drivers/rtc/Kconfig | |||
@@ -3,10 +3,10 @@ | |||
3 | # | 3 | # |
4 | 4 | ||
5 | config RTC_LIB | 5 | config RTC_LIB |
6 | tristate | 6 | bool |
7 | 7 | ||
8 | menuconfig RTC_CLASS | 8 | menuconfig RTC_CLASS |
9 | tristate "Real Time Clock" | 9 | bool "Real Time Clock" |
10 | default n | 10 | default n |
11 | depends on !S390 | 11 | depends on !S390 |
12 | select RTC_LIB | 12 | select RTC_LIB |
@@ -15,9 +15,6 @@ menuconfig RTC_CLASS | |||
15 | be allowed to plug one or more RTCs to your system. You will | 15 | be allowed to plug one or more RTCs to your system. You will |
16 | probably want to enable one or more of the interfaces below. | 16 | probably want to enable one or more of the interfaces below. |
17 | 17 | ||
18 | This driver can also be built as a module. If so, the module | ||
19 | will be called rtc-core. | ||
20 | |||
21 | if RTC_CLASS | 18 | if RTC_CLASS |
22 | 19 | ||
23 | config RTC_HCTOSYS | 20 | config RTC_HCTOSYS |
diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c index 39013867cbd6..4194e59e14cd 100644 --- a/drivers/rtc/class.c +++ b/drivers/rtc/class.c | |||
@@ -41,26 +41,21 @@ static void rtc_device_release(struct device *dev) | |||
41 | * system's wall clock; restore it on resume(). | 41 | * system's wall clock; restore it on resume(). |
42 | */ | 42 | */ |
43 | 43 | ||
44 | static struct timespec delta; | ||
45 | static time_t oldtime; | 44 | static time_t oldtime; |
45 | static struct timespec oldts; | ||
46 | 46 | ||
47 | static int rtc_suspend(struct device *dev, pm_message_t mesg) | 47 | static int rtc_suspend(struct device *dev, pm_message_t mesg) |
48 | { | 48 | { |
49 | struct rtc_device *rtc = to_rtc_device(dev); | 49 | struct rtc_device *rtc = to_rtc_device(dev); |
50 | struct rtc_time tm; | 50 | struct rtc_time tm; |
51 | struct timespec ts = current_kernel_time(); | ||
52 | 51 | ||
53 | if (strcmp(dev_name(&rtc->dev), CONFIG_RTC_HCTOSYS_DEVICE) != 0) | 52 | if (strcmp(dev_name(&rtc->dev), CONFIG_RTC_HCTOSYS_DEVICE) != 0) |
54 | return 0; | 53 | return 0; |
55 | 54 | ||
56 | rtc_read_time(rtc, &tm); | 55 | rtc_read_time(rtc, &tm); |
56 | ktime_get_ts(&oldts); | ||
57 | rtc_tm_to_time(&tm, &oldtime); | 57 | rtc_tm_to_time(&tm, &oldtime); |
58 | 58 | ||
59 | /* RTC precision is 1 second; adjust delta for avg 1/2 sec err */ | ||
60 | set_normalized_timespec(&delta, | ||
61 | ts.tv_sec - oldtime, | ||
62 | ts.tv_nsec - (NSEC_PER_SEC >> 1)); | ||
63 | |||
64 | return 0; | 59 | return 0; |
65 | } | 60 | } |
66 | 61 | ||
@@ -70,10 +65,12 @@ static int rtc_resume(struct device *dev) | |||
70 | struct rtc_time tm; | 65 | struct rtc_time tm; |
71 | time_t newtime; | 66 | time_t newtime; |
72 | struct timespec time; | 67 | struct timespec time; |
68 | struct timespec newts; | ||
73 | 69 | ||
74 | if (strcmp(dev_name(&rtc->dev), CONFIG_RTC_HCTOSYS_DEVICE) != 0) | 70 | if (strcmp(dev_name(&rtc->dev), CONFIG_RTC_HCTOSYS_DEVICE) != 0) |
75 | return 0; | 71 | return 0; |
76 | 72 | ||
73 | ktime_get_ts(&newts); | ||
77 | rtc_read_time(rtc, &tm); | 74 | rtc_read_time(rtc, &tm); |
78 | if (rtc_valid_tm(&tm) != 0) { | 75 | if (rtc_valid_tm(&tm) != 0) { |
79 | pr_debug("%s: bogus resume time\n", dev_name(&rtc->dev)); | 76 | pr_debug("%s: bogus resume time\n", dev_name(&rtc->dev)); |
@@ -85,15 +82,13 @@ static int rtc_resume(struct device *dev) | |||
85 | pr_debug("%s: time travel!\n", dev_name(&rtc->dev)); | 82 | pr_debug("%s: time travel!\n", dev_name(&rtc->dev)); |
86 | return 0; | 83 | return 0; |
87 | } | 84 | } |
85 | /* calculate the RTC time delta */ | ||
86 | set_normalized_timespec(&time, newtime - oldtime, 0); | ||
88 | 87 | ||
89 | /* restore wall clock using delta against this RTC; | 88 | /* subtract kernel time between rtc_suspend to rtc_resume */ |
90 | * adjust again for avg 1/2 second RTC sampling error | 89 | time = timespec_sub(time, timespec_sub(newts, oldts)); |
91 | */ | ||
92 | set_normalized_timespec(&time, | ||
93 | newtime + delta.tv_sec, | ||
94 | (NSEC_PER_SEC >> 1) + delta.tv_nsec); | ||
95 | do_settimeofday(&time); | ||
96 | 90 | ||
91 | timekeeping_inject_sleeptime(&time); | ||
97 | return 0; | 92 | return 0; |
98 | } | 93 | } |
99 | 94 | ||
diff --git a/drivers/ssb/pci.c b/drivers/ssb/pci.c index 6f34963b3c64..7ad48585c5e6 100644 --- a/drivers/ssb/pci.c +++ b/drivers/ssb/pci.c | |||
@@ -662,7 +662,6 @@ static int sprom_extract(struct ssb_bus *bus, struct ssb_sprom *out, | |||
662 | static int ssb_pci_sprom_get(struct ssb_bus *bus, | 662 | static int ssb_pci_sprom_get(struct ssb_bus *bus, |
663 | struct ssb_sprom *sprom) | 663 | struct ssb_sprom *sprom) |
664 | { | 664 | { |
665 | const struct ssb_sprom *fallback; | ||
666 | int err; | 665 | int err; |
667 | u16 *buf; | 666 | u16 *buf; |
668 | 667 | ||
@@ -707,10 +706,17 @@ static int ssb_pci_sprom_get(struct ssb_bus *bus, | |||
707 | if (err) { | 706 | if (err) { |
708 | /* All CRC attempts failed. | 707 | /* All CRC attempts failed. |
709 | * Maybe there is no SPROM on the device? | 708 | * Maybe there is no SPROM on the device? |
710 | * If we have a fallback, use that. */ | 709 | * Now we ask the arch code if there is some sprom |
711 | fallback = ssb_get_fallback_sprom(); | 710 | * available for this device in some other storage */ |
712 | if (fallback) { | 711 | err = ssb_fill_sprom_with_fallback(bus, sprom); |
713 | memcpy(sprom, fallback, sizeof(*sprom)); | 712 | if (err) { |
713 | ssb_printk(KERN_WARNING PFX "WARNING: Using" | ||
714 | " fallback SPROM failed (err %d)\n", | ||
715 | err); | ||
716 | } else { | ||
717 | ssb_dprintk(KERN_DEBUG PFX "Using SPROM" | ||
718 | " revision %d provided by" | ||
719 | " platform.\n", sprom->revision); | ||
714 | err = 0; | 720 | err = 0; |
715 | goto out_free; | 721 | goto out_free; |
716 | } | 722 | } |
diff --git a/drivers/ssb/sprom.c b/drivers/ssb/sprom.c index 5f34d7a3e3a5..45ff0e3a3828 100644 --- a/drivers/ssb/sprom.c +++ b/drivers/ssb/sprom.c | |||
@@ -17,7 +17,7 @@ | |||
17 | #include <linux/slab.h> | 17 | #include <linux/slab.h> |
18 | 18 | ||
19 | 19 | ||
20 | static const struct ssb_sprom *fallback_sprom; | 20 | static int(*get_fallback_sprom)(struct ssb_bus *dev, struct ssb_sprom *out); |
21 | 21 | ||
22 | 22 | ||
23 | static int sprom2hex(const u16 *sprom, char *buf, size_t buf_len, | 23 | static int sprom2hex(const u16 *sprom, char *buf, size_t buf_len, |
@@ -145,36 +145,43 @@ out: | |||
145 | } | 145 | } |
146 | 146 | ||
147 | /** | 147 | /** |
148 | * ssb_arch_set_fallback_sprom - Set a fallback SPROM for use if no SPROM is found. | 148 | * ssb_arch_register_fallback_sprom - Registers a method providing a |
149 | * fallback SPROM if no SPROM is found. | ||
149 | * | 150 | * |
150 | * @sprom: The SPROM data structure to register. | 151 | * @sprom_callback: The callback function. |
151 | * | 152 | * |
152 | * With this function the architecture implementation may register a fallback | 153 | * With this function the architecture implementation may register a |
153 | * SPROM data structure. The fallback is only used for PCI based SSB devices, | 154 | * callback handler which fills the SPROM data structure. The fallback is |
154 | * where no valid SPROM can be found in the shadow registers. | 155 | * only used for PCI based SSB devices, where no valid SPROM can be found |
156 | * in the shadow registers. | ||
155 | * | 157 | * |
156 | * This function is useful for weird architectures that have a half-assed SSB device | 158 | * This function is useful for weird architectures that have a half-assed |
157 | * hardwired to their PCI bus. | 159 | * SSB device hardwired to their PCI bus. |
158 | * | 160 | * |
159 | * Note that it does only work with PCI attached SSB devices. PCMCIA devices currently | 161 | * Note that it does only work with PCI attached SSB devices. PCMCIA |
160 | * don't use this fallback. | 162 | * devices currently don't use this fallback. |
161 | * Architectures must provide the SPROM for native SSB devices anyway, | 163 | * Architectures must provide the SPROM for native SSB devices anyway, so |
162 | * so the fallback also isn't used for native devices. | 164 | * the fallback also isn't used for native devices. |
163 | * | 165 | * |
164 | * This function is available for architecture code, only. So it is not exported. | 166 | * This function is available for architecture code, only. So it is not |
167 | * exported. | ||
165 | */ | 168 | */ |
166 | int ssb_arch_set_fallback_sprom(const struct ssb_sprom *sprom) | 169 | int ssb_arch_register_fallback_sprom(int (*sprom_callback)(struct ssb_bus *bus, |
170 | struct ssb_sprom *out)) | ||
167 | { | 171 | { |
168 | if (fallback_sprom) | 172 | if (get_fallback_sprom) |
169 | return -EEXIST; | 173 | return -EEXIST; |
170 | fallback_sprom = sprom; | 174 | get_fallback_sprom = sprom_callback; |
171 | 175 | ||
172 | return 0; | 176 | return 0; |
173 | } | 177 | } |
174 | 178 | ||
175 | const struct ssb_sprom *ssb_get_fallback_sprom(void) | 179 | int ssb_fill_sprom_with_fallback(struct ssb_bus *bus, struct ssb_sprom *out) |
176 | { | 180 | { |
177 | return fallback_sprom; | 181 | if (!get_fallback_sprom) |
182 | return -ENOENT; | ||
183 | |||
184 | return get_fallback_sprom(bus, out); | ||
178 | } | 185 | } |
179 | 186 | ||
180 | /* http://bcm-v4.sipsolutions.net/802.11/IsSpromAvailable */ | 187 | /* http://bcm-v4.sipsolutions.net/802.11/IsSpromAvailable */ |
diff --git a/drivers/ssb/ssb_private.h b/drivers/ssb/ssb_private.h index 0331139a726f..77653014db0b 100644 --- a/drivers/ssb/ssb_private.h +++ b/drivers/ssb/ssb_private.h | |||
@@ -171,7 +171,8 @@ ssize_t ssb_attr_sprom_store(struct ssb_bus *bus, | |||
171 | const char *buf, size_t count, | 171 | const char *buf, size_t count, |
172 | int (*sprom_check_crc)(const u16 *sprom, size_t size), | 172 | int (*sprom_check_crc)(const u16 *sprom, size_t size), |
173 | int (*sprom_write)(struct ssb_bus *bus, const u16 *sprom)); | 173 | int (*sprom_write)(struct ssb_bus *bus, const u16 *sprom)); |
174 | extern const struct ssb_sprom *ssb_get_fallback_sprom(void); | 174 | extern int ssb_fill_sprom_with_fallback(struct ssb_bus *bus, |
175 | struct ssb_sprom *out); | ||
175 | 176 | ||
176 | 177 | ||
177 | /* core.c */ | 178 | /* core.c */ |
diff --git a/drivers/tty/serial/Kconfig b/drivers/tty/serial/Kconfig index 80484af781e1..b1f0f83b870d 100644 --- a/drivers/tty/serial/Kconfig +++ b/drivers/tty/serial/Kconfig | |||
@@ -1391,6 +1391,14 @@ config SERIAL_OF_PLATFORM_NWPSERIAL_CONSOLE | |||
1391 | help | 1391 | help |
1392 | Support for Console on the NWP serial ports. | 1392 | Support for Console on the NWP serial ports. |
1393 | 1393 | ||
1394 | config SERIAL_LANTIQ | ||
1395 | bool "Lantiq serial driver" | ||
1396 | depends on LANTIQ | ||
1397 | select SERIAL_CORE | ||
1398 | select SERIAL_CORE_CONSOLE | ||
1399 | help | ||
1400 | Support for console and UART on Lantiq SoCs. | ||
1401 | |||
1394 | config SERIAL_QE | 1402 | config SERIAL_QE |
1395 | tristate "Freescale QUICC Engine serial port support" | 1403 | tristate "Freescale QUICC Engine serial port support" |
1396 | depends on QUICC_ENGINE | 1404 | depends on QUICC_ENGINE |
diff --git a/drivers/tty/serial/Makefile b/drivers/tty/serial/Makefile index fee0690ef8e3..35276043d9d1 100644 --- a/drivers/tty/serial/Makefile +++ b/drivers/tty/serial/Makefile | |||
@@ -94,3 +94,4 @@ obj-$(CONFIG_SERIAL_IFX6X60) += ifx6x60.o | |||
94 | obj-$(CONFIG_SERIAL_PCH_UART) += pch_uart.o | 94 | obj-$(CONFIG_SERIAL_PCH_UART) += pch_uart.o |
95 | obj-$(CONFIG_SERIAL_MSM_SMD) += msm_smd_tty.o | 95 | obj-$(CONFIG_SERIAL_MSM_SMD) += msm_smd_tty.o |
96 | obj-$(CONFIG_SERIAL_MXS_AUART) += mxs-auart.o | 96 | obj-$(CONFIG_SERIAL_MXS_AUART) += mxs-auart.o |
97 | obj-$(CONFIG_SERIAL_LANTIQ) += lantiq.o | ||
diff --git a/drivers/tty/serial/lantiq.c b/drivers/tty/serial/lantiq.c new file mode 100644 index 000000000000..58cf279ed879 --- /dev/null +++ b/drivers/tty/serial/lantiq.c | |||
@@ -0,0 +1,756 @@ | |||
1 | /* | ||
2 | * Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o. | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify it | ||
5 | * under the terms of the GNU General Public License version 2 as published | ||
6 | * by the Free Software Foundation. | ||
7 | * | ||
8 | * This program is distributed in the hope that it will be useful, | ||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
11 | * GNU General Public License for more details. | ||
12 | * | ||
13 | * You should have received a copy of the GNU General Public License | ||
14 | * along with this program; if not, write to the Free Software | ||
15 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
16 | * | ||
17 | * Copyright (C) 2004 Infineon IFAP DC COM CPE | ||
18 | * Copyright (C) 2007 Felix Fietkau <nbd@openwrt.org> | ||
19 | * Copyright (C) 2007 John Crispin <blogic@openwrt.org> | ||
20 | * Copyright (C) 2010 Thomas Langer, <thomas.langer@lantiq.com> | ||
21 | */ | ||
22 | |||
23 | #include <linux/slab.h> | ||
24 | #include <linux/module.h> | ||
25 | #include <linux/ioport.h> | ||
26 | #include <linux/init.h> | ||
27 | #include <linux/console.h> | ||
28 | #include <linux/sysrq.h> | ||
29 | #include <linux/device.h> | ||
30 | #include <linux/tty.h> | ||
31 | #include <linux/tty_flip.h> | ||
32 | #include <linux/serial_core.h> | ||
33 | #include <linux/serial.h> | ||
34 | #include <linux/platform_device.h> | ||
35 | #include <linux/io.h> | ||
36 | #include <linux/clk.h> | ||
37 | |||
38 | #include <lantiq_soc.h> | ||
39 | |||
40 | #define PORT_LTQ_ASC 111 | ||
41 | #define MAXPORTS 2 | ||
42 | #define UART_DUMMY_UER_RX 1 | ||
43 | #define DRVNAME "ltq_asc" | ||
44 | #ifdef __BIG_ENDIAN | ||
45 | #define LTQ_ASC_TBUF (0x0020 + 3) | ||
46 | #define LTQ_ASC_RBUF (0x0024 + 3) | ||
47 | #else | ||
48 | #define LTQ_ASC_TBUF 0x0020 | ||
49 | #define LTQ_ASC_RBUF 0x0024 | ||
50 | #endif | ||
51 | #define LTQ_ASC_FSTAT 0x0048 | ||
52 | #define LTQ_ASC_WHBSTATE 0x0018 | ||
53 | #define LTQ_ASC_STATE 0x0014 | ||
54 | #define LTQ_ASC_IRNCR 0x00F8 | ||
55 | #define LTQ_ASC_CLC 0x0000 | ||
56 | #define LTQ_ASC_ID 0x0008 | ||
57 | #define LTQ_ASC_PISEL 0x0004 | ||
58 | #define LTQ_ASC_TXFCON 0x0044 | ||
59 | #define LTQ_ASC_RXFCON 0x0040 | ||
60 | #define LTQ_ASC_CON 0x0010 | ||
61 | #define LTQ_ASC_BG 0x0050 | ||
62 | #define LTQ_ASC_IRNREN 0x00F4 | ||
63 | |||
64 | #define ASC_IRNREN_TX 0x1 | ||
65 | #define ASC_IRNREN_RX 0x2 | ||
66 | #define ASC_IRNREN_ERR 0x4 | ||
67 | #define ASC_IRNREN_TX_BUF 0x8 | ||
68 | #define ASC_IRNCR_TIR 0x1 | ||
69 | #define ASC_IRNCR_RIR 0x2 | ||
70 | #define ASC_IRNCR_EIR 0x4 | ||
71 | |||
72 | #define ASCOPT_CSIZE 0x3 | ||
73 | #define TXFIFO_FL 1 | ||
74 | #define RXFIFO_FL 1 | ||
75 | #define ASCCLC_DISS 0x2 | ||
76 | #define ASCCLC_RMCMASK 0x0000FF00 | ||
77 | #define ASCCLC_RMCOFFSET 8 | ||
78 | #define ASCCON_M_8ASYNC 0x0 | ||
79 | #define ASCCON_M_7ASYNC 0x2 | ||
80 | #define ASCCON_ODD 0x00000020 | ||
81 | #define ASCCON_STP 0x00000080 | ||
82 | #define ASCCON_BRS 0x00000100 | ||
83 | #define ASCCON_FDE 0x00000200 | ||
84 | #define ASCCON_R 0x00008000 | ||
85 | #define ASCCON_FEN 0x00020000 | ||
86 | #define ASCCON_ROEN 0x00080000 | ||
87 | #define ASCCON_TOEN 0x00100000 | ||
88 | #define ASCSTATE_PE 0x00010000 | ||
89 | #define ASCSTATE_FE 0x00020000 | ||
90 | #define ASCSTATE_ROE 0x00080000 | ||
91 | #define ASCSTATE_ANY (ASCSTATE_ROE|ASCSTATE_PE|ASCSTATE_FE) | ||
92 | #define ASCWHBSTATE_CLRREN 0x00000001 | ||
93 | #define ASCWHBSTATE_SETREN 0x00000002 | ||
94 | #define ASCWHBSTATE_CLRPE 0x00000004 | ||
95 | #define ASCWHBSTATE_CLRFE 0x00000008 | ||
96 | #define ASCWHBSTATE_CLRROE 0x00000020 | ||
97 | #define ASCTXFCON_TXFEN 0x0001 | ||
98 | #define ASCTXFCON_TXFFLU 0x0002 | ||
99 | #define ASCTXFCON_TXFITLMASK 0x3F00 | ||
100 | #define ASCTXFCON_TXFITLOFF 8 | ||
101 | #define ASCRXFCON_RXFEN 0x0001 | ||
102 | #define ASCRXFCON_RXFFLU 0x0002 | ||
103 | #define ASCRXFCON_RXFITLMASK 0x3F00 | ||
104 | #define ASCRXFCON_RXFITLOFF 8 | ||
105 | #define ASCFSTAT_RXFFLMASK 0x003F | ||
106 | #define ASCFSTAT_TXFFLMASK 0x3F00 | ||
107 | #define ASCFSTAT_TXFREEMASK 0x3F000000 | ||
108 | #define ASCFSTAT_TXFREEOFF 24 | ||
109 | |||
110 | static void lqasc_tx_chars(struct uart_port *port); | ||
111 | static struct ltq_uart_port *lqasc_port[MAXPORTS]; | ||
112 | static struct uart_driver lqasc_reg; | ||
113 | static DEFINE_SPINLOCK(ltq_asc_lock); | ||
114 | |||
115 | struct ltq_uart_port { | ||
116 | struct uart_port port; | ||
117 | struct clk *clk; | ||
118 | unsigned int tx_irq; | ||
119 | unsigned int rx_irq; | ||
120 | unsigned int err_irq; | ||
121 | }; | ||
122 | |||
123 | static inline struct | ||
124 | ltq_uart_port *to_ltq_uart_port(struct uart_port *port) | ||
125 | { | ||
126 | return container_of(port, struct ltq_uart_port, port); | ||
127 | } | ||
128 | |||
129 | static void | ||
130 | lqasc_stop_tx(struct uart_port *port) | ||
131 | { | ||
132 | return; | ||
133 | } | ||
134 | |||
135 | static void | ||
136 | lqasc_start_tx(struct uart_port *port) | ||
137 | { | ||
138 | unsigned long flags; | ||
139 | spin_lock_irqsave(<q_asc_lock, flags); | ||
140 | lqasc_tx_chars(port); | ||
141 | spin_unlock_irqrestore(<q_asc_lock, flags); | ||
142 | return; | ||
143 | } | ||
144 | |||
145 | static void | ||
146 | lqasc_stop_rx(struct uart_port *port) | ||
147 | { | ||
148 | ltq_w32(ASCWHBSTATE_CLRREN, port->membase + LTQ_ASC_WHBSTATE); | ||
149 | } | ||
150 | |||
151 | static void | ||
152 | lqasc_enable_ms(struct uart_port *port) | ||
153 | { | ||
154 | } | ||
155 | |||
156 | static int | ||
157 | lqasc_rx_chars(struct uart_port *port) | ||
158 | { | ||
159 | struct tty_struct *tty = tty_port_tty_get(&port->state->port); | ||
160 | unsigned int ch = 0, rsr = 0, fifocnt; | ||
161 | |||
162 | if (!tty) { | ||
163 | dev_dbg(port->dev, "%s:tty is busy now", __func__); | ||
164 | return -EBUSY; | ||
165 | } | ||
166 | fifocnt = | ||
167 | ltq_r32(port->membase + LTQ_ASC_FSTAT) & ASCFSTAT_RXFFLMASK; | ||
168 | while (fifocnt--) { | ||
169 | u8 flag = TTY_NORMAL; | ||
170 | ch = ltq_r8(port->membase + LTQ_ASC_RBUF); | ||
171 | rsr = (ltq_r32(port->membase + LTQ_ASC_STATE) | ||
172 | & ASCSTATE_ANY) | UART_DUMMY_UER_RX; | ||
173 | tty_flip_buffer_push(tty); | ||
174 | port->icount.rx++; | ||
175 | |||
176 | /* | ||
177 | * Note that the error handling code is | ||
178 | * out of the main execution path | ||
179 | */ | ||
180 | if (rsr & ASCSTATE_ANY) { | ||
181 | if (rsr & ASCSTATE_PE) { | ||
182 | port->icount.parity++; | ||
183 | ltq_w32_mask(0, ASCWHBSTATE_CLRPE, | ||
184 | port->membase + LTQ_ASC_WHBSTATE); | ||
185 | } else if (rsr & ASCSTATE_FE) { | ||
186 | port->icount.frame++; | ||
187 | ltq_w32_mask(0, ASCWHBSTATE_CLRFE, | ||
188 | port->membase + LTQ_ASC_WHBSTATE); | ||
189 | } | ||
190 | if (rsr & ASCSTATE_ROE) { | ||
191 | port->icount.overrun++; | ||
192 | ltq_w32_mask(0, ASCWHBSTATE_CLRROE, | ||
193 | port->membase + LTQ_ASC_WHBSTATE); | ||
194 | } | ||
195 | |||
196 | rsr &= port->read_status_mask; | ||
197 | |||
198 | if (rsr & ASCSTATE_PE) | ||
199 | flag = TTY_PARITY; | ||
200 | else if (rsr & ASCSTATE_FE) | ||
201 | flag = TTY_FRAME; | ||
202 | } | ||
203 | |||
204 | if ((rsr & port->ignore_status_mask) == 0) | ||
205 | tty_insert_flip_char(tty, ch, flag); | ||
206 | |||
207 | if (rsr & ASCSTATE_ROE) | ||
208 | /* | ||
209 | * Overrun is special, since it's reported | ||
210 | * immediately, and doesn't affect the current | ||
211 | * character | ||
212 | */ | ||
213 | tty_insert_flip_char(tty, 0, TTY_OVERRUN); | ||
214 | } | ||
215 | if (ch != 0) | ||
216 | tty_flip_buffer_push(tty); | ||
217 | tty_kref_put(tty); | ||
218 | return 0; | ||
219 | } | ||
220 | |||
221 | static void | ||
222 | lqasc_tx_chars(struct uart_port *port) | ||
223 | { | ||
224 | struct circ_buf *xmit = &port->state->xmit; | ||
225 | if (uart_tx_stopped(port)) { | ||
226 | lqasc_stop_tx(port); | ||
227 | return; | ||
228 | } | ||
229 | |||
230 | while (((ltq_r32(port->membase + LTQ_ASC_FSTAT) & | ||
231 | ASCFSTAT_TXFREEMASK) >> ASCFSTAT_TXFREEOFF) != 0) { | ||
232 | if (port->x_char) { | ||
233 | ltq_w8(port->x_char, port->membase + LTQ_ASC_TBUF); | ||
234 | port->icount.tx++; | ||
235 | port->x_char = 0; | ||
236 | continue; | ||
237 | } | ||
238 | |||
239 | if (uart_circ_empty(xmit)) | ||
240 | break; | ||
241 | |||
242 | ltq_w8(port->state->xmit.buf[port->state->xmit.tail], | ||
243 | port->membase + LTQ_ASC_TBUF); | ||
244 | xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); | ||
245 | port->icount.tx++; | ||
246 | } | ||
247 | |||
248 | if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) | ||
249 | uart_write_wakeup(port); | ||
250 | } | ||
251 | |||
252 | static irqreturn_t | ||
253 | lqasc_tx_int(int irq, void *_port) | ||
254 | { | ||
255 | unsigned long flags; | ||
256 | struct uart_port *port = (struct uart_port *)_port; | ||
257 | spin_lock_irqsave(<q_asc_lock, flags); | ||
258 | ltq_w32(ASC_IRNCR_TIR, port->membase + LTQ_ASC_IRNCR); | ||
259 | spin_unlock_irqrestore(<q_asc_lock, flags); | ||
260 | lqasc_start_tx(port); | ||
261 | return IRQ_HANDLED; | ||
262 | } | ||
263 | |||
264 | static irqreturn_t | ||
265 | lqasc_err_int(int irq, void *_port) | ||
266 | { | ||
267 | unsigned long flags; | ||
268 | struct uart_port *port = (struct uart_port *)_port; | ||
269 | spin_lock_irqsave(<q_asc_lock, flags); | ||
270 | /* clear any pending interrupts */ | ||
271 | ltq_w32_mask(0, ASCWHBSTATE_CLRPE | ASCWHBSTATE_CLRFE | | ||
272 | ASCWHBSTATE_CLRROE, port->membase + LTQ_ASC_WHBSTATE); | ||
273 | spin_unlock_irqrestore(<q_asc_lock, flags); | ||
274 | return IRQ_HANDLED; | ||
275 | } | ||
276 | |||
277 | static irqreturn_t | ||
278 | lqasc_rx_int(int irq, void *_port) | ||
279 | { | ||
280 | unsigned long flags; | ||
281 | struct uart_port *port = (struct uart_port *)_port; | ||
282 | spin_lock_irqsave(<q_asc_lock, flags); | ||
283 | ltq_w32(ASC_IRNCR_RIR, port->membase + LTQ_ASC_IRNCR); | ||
284 | lqasc_rx_chars(port); | ||
285 | spin_unlock_irqrestore(<q_asc_lock, flags); | ||
286 | return IRQ_HANDLED; | ||
287 | } | ||
288 | |||
289 | static unsigned int | ||
290 | lqasc_tx_empty(struct uart_port *port) | ||
291 | { | ||
292 | int status; | ||
293 | status = ltq_r32(port->membase + LTQ_ASC_FSTAT) & ASCFSTAT_TXFFLMASK; | ||
294 | return status ? 0 : TIOCSER_TEMT; | ||
295 | } | ||
296 | |||
297 | static unsigned int | ||
298 | lqasc_get_mctrl(struct uart_port *port) | ||
299 | { | ||
300 | return TIOCM_CTS | TIOCM_CAR | TIOCM_DSR; | ||
301 | } | ||
302 | |||
303 | static void | ||
304 | lqasc_set_mctrl(struct uart_port *port, u_int mctrl) | ||
305 | { | ||
306 | } | ||
307 | |||
308 | static void | ||
309 | lqasc_break_ctl(struct uart_port *port, int break_state) | ||
310 | { | ||
311 | } | ||
312 | |||
313 | static int | ||
314 | lqasc_startup(struct uart_port *port) | ||
315 | { | ||
316 | struct ltq_uart_port *ltq_port = to_ltq_uart_port(port); | ||
317 | int retval; | ||
318 | |||
319 | port->uartclk = clk_get_rate(ltq_port->clk); | ||
320 | |||
321 | ltq_w32_mask(ASCCLC_DISS | ASCCLC_RMCMASK, (1 << ASCCLC_RMCOFFSET), | ||
322 | port->membase + LTQ_ASC_CLC); | ||
323 | |||
324 | ltq_w32(0, port->membase + LTQ_ASC_PISEL); | ||
325 | ltq_w32( | ||
326 | ((TXFIFO_FL << ASCTXFCON_TXFITLOFF) & ASCTXFCON_TXFITLMASK) | | ||
327 | ASCTXFCON_TXFEN | ASCTXFCON_TXFFLU, | ||
328 | port->membase + LTQ_ASC_TXFCON); | ||
329 | ltq_w32( | ||
330 | ((RXFIFO_FL << ASCRXFCON_RXFITLOFF) & ASCRXFCON_RXFITLMASK) | ||
331 | | ASCRXFCON_RXFEN | ASCRXFCON_RXFFLU, | ||
332 | port->membase + LTQ_ASC_RXFCON); | ||
333 | /* make sure other settings are written to hardware before | ||
334 | * setting enable bits | ||
335 | */ | ||
336 | wmb(); | ||
337 | ltq_w32_mask(0, ASCCON_M_8ASYNC | ASCCON_FEN | ASCCON_TOEN | | ||
338 | ASCCON_ROEN, port->membase + LTQ_ASC_CON); | ||
339 | |||
340 | retval = request_irq(ltq_port->tx_irq, lqasc_tx_int, | ||
341 | IRQF_DISABLED, "asc_tx", port); | ||
342 | if (retval) { | ||
343 | pr_err("failed to request lqasc_tx_int\n"); | ||
344 | return retval; | ||
345 | } | ||
346 | |||
347 | retval = request_irq(ltq_port->rx_irq, lqasc_rx_int, | ||
348 | IRQF_DISABLED, "asc_rx", port); | ||
349 | if (retval) { | ||
350 | pr_err("failed to request lqasc_rx_int\n"); | ||
351 | goto err1; | ||
352 | } | ||
353 | |||
354 | retval = request_irq(ltq_port->err_irq, lqasc_err_int, | ||
355 | IRQF_DISABLED, "asc_err", port); | ||
356 | if (retval) { | ||
357 | pr_err("failed to request lqasc_err_int\n"); | ||
358 | goto err2; | ||
359 | } | ||
360 | |||
361 | ltq_w32(ASC_IRNREN_RX | ASC_IRNREN_ERR | ASC_IRNREN_TX, | ||
362 | port->membase + LTQ_ASC_IRNREN); | ||
363 | return 0; | ||
364 | |||
365 | err2: | ||
366 | free_irq(ltq_port->rx_irq, port); | ||
367 | err1: | ||
368 | free_irq(ltq_port->tx_irq, port); | ||
369 | return retval; | ||
370 | } | ||
371 | |||
372 | static void | ||
373 | lqasc_shutdown(struct uart_port *port) | ||
374 | { | ||
375 | struct ltq_uart_port *ltq_port = to_ltq_uart_port(port); | ||
376 | free_irq(ltq_port->tx_irq, port); | ||
377 | free_irq(ltq_port->rx_irq, port); | ||
378 | free_irq(ltq_port->err_irq, port); | ||
379 | |||
380 | ltq_w32(0, port->membase + LTQ_ASC_CON); | ||
381 | ltq_w32_mask(ASCRXFCON_RXFEN, ASCRXFCON_RXFFLU, | ||
382 | port->membase + LTQ_ASC_RXFCON); | ||
383 | ltq_w32_mask(ASCTXFCON_TXFEN, ASCTXFCON_TXFFLU, | ||
384 | port->membase + LTQ_ASC_TXFCON); | ||
385 | } | ||
386 | |||
387 | static void | ||
388 | lqasc_set_termios(struct uart_port *port, | ||
389 | struct ktermios *new, struct ktermios *old) | ||
390 | { | ||
391 | unsigned int cflag; | ||
392 | unsigned int iflag; | ||
393 | unsigned int divisor; | ||
394 | unsigned int baud; | ||
395 | unsigned int con = 0; | ||
396 | unsigned long flags; | ||
397 | |||
398 | cflag = new->c_cflag; | ||
399 | iflag = new->c_iflag; | ||
400 | |||
401 | switch (cflag & CSIZE) { | ||
402 | case CS7: | ||
403 | con = ASCCON_M_7ASYNC; | ||
404 | break; | ||
405 | |||
406 | case CS5: | ||
407 | case CS6: | ||
408 | default: | ||
409 | new->c_cflag &= ~ CSIZE; | ||
410 | new->c_cflag |= CS8; | ||
411 | con = ASCCON_M_8ASYNC; | ||
412 | break; | ||
413 | } | ||
414 | |||
415 | cflag &= ~CMSPAR; /* Mark/Space parity is not supported */ | ||
416 | |||
417 | if (cflag & CSTOPB) | ||
418 | con |= ASCCON_STP; | ||
419 | |||
420 | if (cflag & PARENB) { | ||
421 | if (!(cflag & PARODD)) | ||
422 | con &= ~ASCCON_ODD; | ||
423 | else | ||
424 | con |= ASCCON_ODD; | ||
425 | } | ||
426 | |||
427 | port->read_status_mask = ASCSTATE_ROE; | ||
428 | if (iflag & INPCK) | ||
429 | port->read_status_mask |= ASCSTATE_FE | ASCSTATE_PE; | ||
430 | |||
431 | port->ignore_status_mask = 0; | ||
432 | if (iflag & IGNPAR) | ||
433 | port->ignore_status_mask |= ASCSTATE_FE | ASCSTATE_PE; | ||
434 | |||
435 | if (iflag & IGNBRK) { | ||
436 | /* | ||
437 | * If we're ignoring parity and break indicators, | ||
438 | * ignore overruns too (for real raw support). | ||
439 | */ | ||
440 | if (iflag & IGNPAR) | ||
441 | port->ignore_status_mask |= ASCSTATE_ROE; | ||
442 | } | ||
443 | |||
444 | if ((cflag & CREAD) == 0) | ||
445 | port->ignore_status_mask |= UART_DUMMY_UER_RX; | ||
446 | |||
447 | /* set error signals - framing, parity and overrun, enable receiver */ | ||
448 | con |= ASCCON_FEN | ASCCON_TOEN | ASCCON_ROEN; | ||
449 | |||
450 | spin_lock_irqsave(<q_asc_lock, flags); | ||
451 | |||
452 | /* set up CON */ | ||
453 | ltq_w32_mask(0, con, port->membase + LTQ_ASC_CON); | ||
454 | |||
455 | /* Set baud rate - take a divider of 2 into account */ | ||
456 | baud = uart_get_baud_rate(port, new, old, 0, port->uartclk / 16); | ||
457 | divisor = uart_get_divisor(port, baud); | ||
458 | divisor = divisor / 2 - 1; | ||
459 | |||
460 | /* disable the baudrate generator */ | ||
461 | ltq_w32_mask(ASCCON_R, 0, port->membase + LTQ_ASC_CON); | ||
462 | |||
463 | /* make sure the fractional divider is off */ | ||
464 | ltq_w32_mask(ASCCON_FDE, 0, port->membase + LTQ_ASC_CON); | ||
465 | |||
466 | /* set up to use divisor of 2 */ | ||
467 | ltq_w32_mask(ASCCON_BRS, 0, port->membase + LTQ_ASC_CON); | ||
468 | |||
469 | /* now we can write the new baudrate into the register */ | ||
470 | ltq_w32(divisor, port->membase + LTQ_ASC_BG); | ||
471 | |||
472 | /* turn the baudrate generator back on */ | ||
473 | ltq_w32_mask(0, ASCCON_R, port->membase + LTQ_ASC_CON); | ||
474 | |||
475 | /* enable rx */ | ||
476 | ltq_w32(ASCWHBSTATE_SETREN, port->membase + LTQ_ASC_WHBSTATE); | ||
477 | |||
478 | spin_unlock_irqrestore(<q_asc_lock, flags); | ||
479 | |||
480 | /* Don't rewrite B0 */ | ||
481 | if (tty_termios_baud_rate(new)) | ||
482 | tty_termios_encode_baud_rate(new, baud, baud); | ||
483 | } | ||
484 | |||
485 | static const char* | ||
486 | lqasc_type(struct uart_port *port) | ||
487 | { | ||
488 | if (port->type == PORT_LTQ_ASC) | ||
489 | return DRVNAME; | ||
490 | else | ||
491 | return NULL; | ||
492 | } | ||
493 | |||
494 | static void | ||
495 | lqasc_release_port(struct uart_port *port) | ||
496 | { | ||
497 | if (port->flags & UPF_IOREMAP) { | ||
498 | iounmap(port->membase); | ||
499 | port->membase = NULL; | ||
500 | } | ||
501 | } | ||
502 | |||
503 | static int | ||
504 | lqasc_request_port(struct uart_port *port) | ||
505 | { | ||
506 | struct platform_device *pdev = to_platform_device(port->dev); | ||
507 | struct resource *res; | ||
508 | int size; | ||
509 | |||
510 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
511 | if (!res) { | ||
512 | dev_err(&pdev->dev, "cannot obtain I/O memory region"); | ||
513 | return -ENODEV; | ||
514 | } | ||
515 | size = resource_size(res); | ||
516 | |||
517 | res = devm_request_mem_region(&pdev->dev, res->start, | ||
518 | size, dev_name(&pdev->dev)); | ||
519 | if (!res) { | ||
520 | dev_err(&pdev->dev, "cannot request I/O memory region"); | ||
521 | return -EBUSY; | ||
522 | } | ||
523 | |||
524 | if (port->flags & UPF_IOREMAP) { | ||
525 | port->membase = devm_ioremap_nocache(&pdev->dev, | ||
526 | port->mapbase, size); | ||
527 | if (port->membase == NULL) | ||
528 | return -ENOMEM; | ||
529 | } | ||
530 | return 0; | ||
531 | } | ||
532 | |||
533 | static void | ||
534 | lqasc_config_port(struct uart_port *port, int flags) | ||
535 | { | ||
536 | if (flags & UART_CONFIG_TYPE) { | ||
537 | port->type = PORT_LTQ_ASC; | ||
538 | lqasc_request_port(port); | ||
539 | } | ||
540 | } | ||
541 | |||
542 | static int | ||
543 | lqasc_verify_port(struct uart_port *port, | ||
544 | struct serial_struct *ser) | ||
545 | { | ||
546 | int ret = 0; | ||
547 | if (ser->type != PORT_UNKNOWN && ser->type != PORT_LTQ_ASC) | ||
548 | ret = -EINVAL; | ||
549 | if (ser->irq < 0 || ser->irq >= NR_IRQS) | ||
550 | ret = -EINVAL; | ||
551 | if (ser->baud_base < 9600) | ||
552 | ret = -EINVAL; | ||
553 | return ret; | ||
554 | } | ||
555 | |||
556 | static struct uart_ops lqasc_pops = { | ||
557 | .tx_empty = lqasc_tx_empty, | ||
558 | .set_mctrl = lqasc_set_mctrl, | ||
559 | .get_mctrl = lqasc_get_mctrl, | ||
560 | .stop_tx = lqasc_stop_tx, | ||
561 | .start_tx = lqasc_start_tx, | ||
562 | .stop_rx = lqasc_stop_rx, | ||
563 | .enable_ms = lqasc_enable_ms, | ||
564 | .break_ctl = lqasc_break_ctl, | ||
565 | .startup = lqasc_startup, | ||
566 | .shutdown = lqasc_shutdown, | ||
567 | .set_termios = lqasc_set_termios, | ||
568 | .type = lqasc_type, | ||
569 | .release_port = lqasc_release_port, | ||
570 | .request_port = lqasc_request_port, | ||
571 | .config_port = lqasc_config_port, | ||
572 | .verify_port = lqasc_verify_port, | ||
573 | }; | ||
574 | |||
575 | static void | ||
576 | lqasc_console_putchar(struct uart_port *port, int ch) | ||
577 | { | ||
578 | int fifofree; | ||
579 | |||
580 | if (!port->membase) | ||
581 | return; | ||
582 | |||
583 | do { | ||
584 | fifofree = (ltq_r32(port->membase + LTQ_ASC_FSTAT) | ||
585 | & ASCFSTAT_TXFREEMASK) >> ASCFSTAT_TXFREEOFF; | ||
586 | } while (fifofree == 0); | ||
587 | ltq_w8(ch, port->membase + LTQ_ASC_TBUF); | ||
588 | } | ||
589 | |||
590 | |||
591 | static void | ||
592 | lqasc_console_write(struct console *co, const char *s, u_int count) | ||
593 | { | ||
594 | struct ltq_uart_port *ltq_port; | ||
595 | struct uart_port *port; | ||
596 | unsigned long flags; | ||
597 | |||
598 | if (co->index >= MAXPORTS) | ||
599 | return; | ||
600 | |||
601 | ltq_port = lqasc_port[co->index]; | ||
602 | if (!ltq_port) | ||
603 | return; | ||
604 | |||
605 | port = <q_port->port; | ||
606 | |||
607 | spin_lock_irqsave(<q_asc_lock, flags); | ||
608 | uart_console_write(port, s, count, lqasc_console_putchar); | ||
609 | spin_unlock_irqrestore(<q_asc_lock, flags); | ||
610 | } | ||
611 | |||
612 | static int __init | ||
613 | lqasc_console_setup(struct console *co, char *options) | ||
614 | { | ||
615 | struct ltq_uart_port *ltq_port; | ||
616 | struct uart_port *port; | ||
617 | int baud = 115200; | ||
618 | int bits = 8; | ||
619 | int parity = 'n'; | ||
620 | int flow = 'n'; | ||
621 | |||
622 | if (co->index >= MAXPORTS) | ||
623 | return -ENODEV; | ||
624 | |||
625 | ltq_port = lqasc_port[co->index]; | ||
626 | if (!ltq_port) | ||
627 | return -ENODEV; | ||
628 | |||
629 | port = <q_port->port; | ||
630 | |||
631 | port->uartclk = clk_get_rate(ltq_port->clk); | ||
632 | |||
633 | if (options) | ||
634 | uart_parse_options(options, &baud, &parity, &bits, &flow); | ||
635 | return uart_set_options(port, co, baud, parity, bits, flow); | ||
636 | } | ||
637 | |||
638 | static struct console lqasc_console = { | ||
639 | .name = "ttyLTQ", | ||
640 | .write = lqasc_console_write, | ||
641 | .device = uart_console_device, | ||
642 | .setup = lqasc_console_setup, | ||
643 | .flags = CON_PRINTBUFFER, | ||
644 | .index = -1, | ||
645 | .data = &lqasc_reg, | ||
646 | }; | ||
647 | |||
648 | static int __init | ||
649 | lqasc_console_init(void) | ||
650 | { | ||
651 | register_console(&lqasc_console); | ||
652 | return 0; | ||
653 | } | ||
654 | console_initcall(lqasc_console_init); | ||
655 | |||
656 | static struct uart_driver lqasc_reg = { | ||
657 | .owner = THIS_MODULE, | ||
658 | .driver_name = DRVNAME, | ||
659 | .dev_name = "ttyLTQ", | ||
660 | .major = 0, | ||
661 | .minor = 0, | ||
662 | .nr = MAXPORTS, | ||
663 | .cons = &lqasc_console, | ||
664 | }; | ||
665 | |||
666 | static int __init | ||
667 | lqasc_probe(struct platform_device *pdev) | ||
668 | { | ||
669 | struct ltq_uart_port *ltq_port; | ||
670 | struct uart_port *port; | ||
671 | struct resource *mmres, *irqres; | ||
672 | int tx_irq, rx_irq, err_irq; | ||
673 | struct clk *clk; | ||
674 | int ret; | ||
675 | |||
676 | mmres = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
677 | irqres = platform_get_resource(pdev, IORESOURCE_IRQ, 0); | ||
678 | if (!mmres || !irqres) | ||
679 | return -ENODEV; | ||
680 | |||
681 | if (pdev->id >= MAXPORTS) | ||
682 | return -EBUSY; | ||
683 | |||
684 | if (lqasc_port[pdev->id] != NULL) | ||
685 | return -EBUSY; | ||
686 | |||
687 | clk = clk_get(&pdev->dev, "fpi"); | ||
688 | if (IS_ERR(clk)) { | ||
689 | pr_err("failed to get fpi clk\n"); | ||
690 | return -ENOENT; | ||
691 | } | ||
692 | |||
693 | tx_irq = platform_get_irq_byname(pdev, "tx"); | ||
694 | rx_irq = platform_get_irq_byname(pdev, "rx"); | ||
695 | err_irq = platform_get_irq_byname(pdev, "err"); | ||
696 | if ((tx_irq < 0) | (rx_irq < 0) | (err_irq < 0)) | ||
697 | return -ENODEV; | ||
698 | |||
699 | ltq_port = kzalloc(sizeof(struct ltq_uart_port), GFP_KERNEL); | ||
700 | if (!ltq_port) | ||
701 | return -ENOMEM; | ||
702 | |||
703 | port = <q_port->port; | ||
704 | |||
705 | port->iotype = SERIAL_IO_MEM; | ||
706 | port->flags = ASYNC_BOOT_AUTOCONF | UPF_IOREMAP; | ||
707 | port->ops = &lqasc_pops; | ||
708 | port->fifosize = 16; | ||
709 | port->type = PORT_LTQ_ASC, | ||
710 | port->line = pdev->id; | ||
711 | port->dev = &pdev->dev; | ||
712 | |||
713 | port->irq = tx_irq; /* unused, just to be backward-compatibe */ | ||
714 | port->mapbase = mmres->start; | ||
715 | |||
716 | ltq_port->clk = clk; | ||
717 | |||
718 | ltq_port->tx_irq = tx_irq; | ||
719 | ltq_port->rx_irq = rx_irq; | ||
720 | ltq_port->err_irq = err_irq; | ||
721 | |||
722 | lqasc_port[pdev->id] = ltq_port; | ||
723 | platform_set_drvdata(pdev, ltq_port); | ||
724 | |||
725 | ret = uart_add_one_port(&lqasc_reg, port); | ||
726 | |||
727 | return ret; | ||
728 | } | ||
729 | |||
730 | static struct platform_driver lqasc_driver = { | ||
731 | .driver = { | ||
732 | .name = DRVNAME, | ||
733 | .owner = THIS_MODULE, | ||
734 | }, | ||
735 | }; | ||
736 | |||
737 | int __init | ||
738 | init_lqasc(void) | ||
739 | { | ||
740 | int ret; | ||
741 | |||
742 | ret = uart_register_driver(&lqasc_reg); | ||
743 | if (ret != 0) | ||
744 | return ret; | ||
745 | |||
746 | ret = platform_driver_probe(&lqasc_driver, lqasc_probe); | ||
747 | if (ret != 0) | ||
748 | uart_unregister_driver(&lqasc_reg); | ||
749 | |||
750 | return ret; | ||
751 | } | ||
752 | |||
753 | module_init(init_lqasc); | ||
754 | |||
755 | MODULE_DESCRIPTION("Lantiq serial port driver"); | ||
756 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c index 51fe1795d5a8..d2efe823c20d 100644 --- a/drivers/uio/uio.c +++ b/drivers/uio/uio.c | |||
@@ -381,7 +381,13 @@ static int uio_get_minor(struct uio_device *idev) | |||
381 | retval = -ENOMEM; | 381 | retval = -ENOMEM; |
382 | goto exit; | 382 | goto exit; |
383 | } | 383 | } |
384 | idev->minor = id & MAX_ID_MASK; | 384 | if (id < UIO_MAX_DEVICES) { |
385 | idev->minor = id; | ||
386 | } else { | ||
387 | dev_err(idev->dev, "too many uio devices\n"); | ||
388 | retval = -EINVAL; | ||
389 | idr_remove(&uio_idr, id); | ||
390 | } | ||
385 | exit: | 391 | exit: |
386 | mutex_unlock(&minor_lock); | 392 | mutex_unlock(&minor_lock); |
387 | return retval; | 393 | return retval; |
@@ -587,14 +593,12 @@ static ssize_t uio_write(struct file *filep, const char __user *buf, | |||
587 | 593 | ||
588 | static int uio_find_mem_index(struct vm_area_struct *vma) | 594 | static int uio_find_mem_index(struct vm_area_struct *vma) |
589 | { | 595 | { |
590 | int mi; | ||
591 | struct uio_device *idev = vma->vm_private_data; | 596 | struct uio_device *idev = vma->vm_private_data; |
592 | 597 | ||
593 | for (mi = 0; mi < MAX_UIO_MAPS; mi++) { | 598 | if (vma->vm_pgoff < MAX_UIO_MAPS) { |
594 | if (idev->info->mem[mi].size == 0) | 599 | if (idev->info->mem[vma->vm_pgoff].size == 0) |
595 | return -1; | 600 | return -1; |
596 | if (vma->vm_pgoff == mi) | 601 | return (int)vma->vm_pgoff; |
597 | return mi; | ||
598 | } | 602 | } |
599 | return -1; | 603 | return -1; |
600 | } | 604 | } |
diff --git a/drivers/uio/uio_netx.c b/drivers/uio/uio_netx.c index 5ffdb483b015..a879fd5741f8 100644 --- a/drivers/uio/uio_netx.c +++ b/drivers/uio/uio_netx.c | |||
@@ -18,6 +18,9 @@ | |||
18 | 18 | ||
19 | #define PCI_VENDOR_ID_HILSCHER 0x15CF | 19 | #define PCI_VENDOR_ID_HILSCHER 0x15CF |
20 | #define PCI_DEVICE_ID_HILSCHER_NETX 0x0000 | 20 | #define PCI_DEVICE_ID_HILSCHER_NETX 0x0000 |
21 | #define PCI_DEVICE_ID_HILSCHER_NETPLC 0x0010 | ||
22 | #define PCI_SUBDEVICE_ID_NETPLC_RAM 0x0000 | ||
23 | #define PCI_SUBDEVICE_ID_NETPLC_FLASH 0x0001 | ||
21 | #define PCI_SUBDEVICE_ID_NXSB_PCA 0x3235 | 24 | #define PCI_SUBDEVICE_ID_NXSB_PCA 0x3235 |
22 | #define PCI_SUBDEVICE_ID_NXPCA 0x3335 | 25 | #define PCI_SUBDEVICE_ID_NXPCA 0x3335 |
23 | 26 | ||
@@ -66,6 +69,10 @@ static int __devinit netx_pci_probe(struct pci_dev *dev, | |||
66 | bar = 0; | 69 | bar = 0; |
67 | info->name = "netx"; | 70 | info->name = "netx"; |
68 | break; | 71 | break; |
72 | case PCI_DEVICE_ID_HILSCHER_NETPLC: | ||
73 | bar = 0; | ||
74 | info->name = "netplc"; | ||
75 | break; | ||
69 | default: | 76 | default: |
70 | bar = 2; | 77 | bar = 2; |
71 | info->name = "netx_plx"; | 78 | info->name = "netx_plx"; |
@@ -134,6 +141,18 @@ static struct pci_device_id netx_pci_ids[] = { | |||
134 | .subdevice = 0, | 141 | .subdevice = 0, |
135 | }, | 142 | }, |
136 | { | 143 | { |
144 | .vendor = PCI_VENDOR_ID_HILSCHER, | ||
145 | .device = PCI_DEVICE_ID_HILSCHER_NETPLC, | ||
146 | .subvendor = PCI_VENDOR_ID_HILSCHER, | ||
147 | .subdevice = PCI_SUBDEVICE_ID_NETPLC_RAM, | ||
148 | }, | ||
149 | { | ||
150 | .vendor = PCI_VENDOR_ID_HILSCHER, | ||
151 | .device = PCI_DEVICE_ID_HILSCHER_NETPLC, | ||
152 | .subvendor = PCI_VENDOR_ID_HILSCHER, | ||
153 | .subdevice = PCI_SUBDEVICE_ID_NETPLC_FLASH, | ||
154 | }, | ||
155 | { | ||
137 | .vendor = PCI_VENDOR_ID_PLX, | 156 | .vendor = PCI_VENDOR_ID_PLX, |
138 | .device = PCI_DEVICE_ID_PLX_9030, | 157 | .device = PCI_DEVICE_ID_PLX_9030, |
139 | .subvendor = PCI_VENDOR_ID_PLX, | 158 | .subvendor = PCI_VENDOR_ID_PLX, |
diff --git a/drivers/uio/uio_pdrv_genirq.c b/drivers/uio/uio_pdrv_genirq.c index 7174d518b8a6..0f424af7f109 100644 --- a/drivers/uio/uio_pdrv_genirq.c +++ b/drivers/uio/uio_pdrv_genirq.c | |||
@@ -189,6 +189,10 @@ static int uio_pdrv_genirq_remove(struct platform_device *pdev) | |||
189 | 189 | ||
190 | uio_unregister_device(priv->uioinfo); | 190 | uio_unregister_device(priv->uioinfo); |
191 | pm_runtime_disable(&pdev->dev); | 191 | pm_runtime_disable(&pdev->dev); |
192 | |||
193 | priv->uioinfo->handler = NULL; | ||
194 | priv->uioinfo->irqcontrol = NULL; | ||
195 | |||
192 | kfree(priv); | 196 | kfree(priv); |
193 | return 0; | 197 | return 0; |
194 | } | 198 | } |
diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 2ab291241635..7aa4eea930f1 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c | |||
@@ -4,7 +4,7 @@ | |||
4 | * Author: Michael S. Tsirkin <mst@redhat.com> | 4 | * Author: Michael S. Tsirkin <mst@redhat.com> |
5 | * | 5 | * |
6 | * Inspiration, some code, and most witty comments come from | 6 | * Inspiration, some code, and most witty comments come from |
7 | * Documentation/lguest/lguest.c, by Rusty Russell | 7 | * Documentation/virtual/lguest/lguest.c, by Rusty Russell |
8 | * | 8 | * |
9 | * This work is licensed under the terms of the GNU GPL, version 2. | 9 | * This work is licensed under the terms of the GNU GPL, version 2. |
10 | * | 10 | * |
diff --git a/drivers/video/atafb.c b/drivers/video/atafb.c index 5b2b5ef4edba..64e41f5448c4 100644 --- a/drivers/video/atafb.c +++ b/drivers/video/atafb.c | |||
@@ -3117,7 +3117,7 @@ int __init atafb_init(void) | |||
3117 | atafb_ops.fb_setcolreg = &falcon_setcolreg; | 3117 | atafb_ops.fb_setcolreg = &falcon_setcolreg; |
3118 | error = request_irq(IRQ_AUTO_4, falcon_vbl_switcher, | 3118 | error = request_irq(IRQ_AUTO_4, falcon_vbl_switcher, |
3119 | IRQ_TYPE_PRIO, | 3119 | IRQ_TYPE_PRIO, |
3120 | "framebuffer/modeswitch", | 3120 | "framebuffer:modeswitch", |
3121 | falcon_vbl_switcher); | 3121 | falcon_vbl_switcher); |
3122 | if (error) | 3122 | if (error) |
3123 | return error; | 3123 | return error; |
diff --git a/drivers/watchdog/Kconfig b/drivers/watchdog/Kconfig index 1b0f98bc51b5..022f9eb0b7bf 100644 --- a/drivers/watchdog/Kconfig +++ b/drivers/watchdog/Kconfig | |||
@@ -990,6 +990,12 @@ config BCM63XX_WDT | |||
990 | To compile this driver as a loadable module, choose M here. | 990 | To compile this driver as a loadable module, choose M here. |
991 | The module will be called bcm63xx_wdt. | 991 | The module will be called bcm63xx_wdt. |
992 | 992 | ||
993 | config LANTIQ_WDT | ||
994 | tristate "Lantiq SoC watchdog" | ||
995 | depends on LANTIQ | ||
996 | help | ||
997 | Hardware driver for the Lantiq SoC Watchdog Timer. | ||
998 | |||
993 | # PARISC Architecture | 999 | # PARISC Architecture |
994 | 1000 | ||
995 | # POWERPC Architecture | 1001 | # POWERPC Architecture |
diff --git a/drivers/watchdog/Makefile b/drivers/watchdog/Makefile index 3f8608b922a7..ed26f7094e47 100644 --- a/drivers/watchdog/Makefile +++ b/drivers/watchdog/Makefile | |||
@@ -123,6 +123,7 @@ obj-$(CONFIG_AR7_WDT) += ar7_wdt.o | |||
123 | obj-$(CONFIG_TXX9_WDT) += txx9wdt.o | 123 | obj-$(CONFIG_TXX9_WDT) += txx9wdt.o |
124 | obj-$(CONFIG_OCTEON_WDT) += octeon-wdt.o | 124 | obj-$(CONFIG_OCTEON_WDT) += octeon-wdt.o |
125 | octeon-wdt-y := octeon-wdt-main.o octeon-wdt-nmi.o | 125 | octeon-wdt-y := octeon-wdt-main.o octeon-wdt-nmi.o |
126 | obj-$(CONFIG_LANTIQ_WDT) += lantiq_wdt.o | ||
126 | 127 | ||
127 | # PARISC Architecture | 128 | # PARISC Architecture |
128 | 129 | ||
diff --git a/drivers/watchdog/lantiq_wdt.c b/drivers/watchdog/lantiq_wdt.c new file mode 100644 index 000000000000..7d82adac1cb2 --- /dev/null +++ b/drivers/watchdog/lantiq_wdt.c | |||
@@ -0,0 +1,261 @@ | |||
1 | /* | ||
2 | * This program is free software; you can redistribute it and/or modify it | ||
3 | * under the terms of the GNU General Public License version 2 as published | ||
4 | * by the Free Software Foundation. | ||
5 | * | ||
6 | * Copyright (C) 2010 John Crispin <blogic@openwrt.org> | ||
7 | * Based on EP93xx wdt driver | ||
8 | */ | ||
9 | |||
10 | #include <linux/module.h> | ||
11 | #include <linux/fs.h> | ||
12 | #include <linux/miscdevice.h> | ||
13 | #include <linux/watchdog.h> | ||
14 | #include <linux/platform_device.h> | ||
15 | #include <linux/uaccess.h> | ||
16 | #include <linux/clk.h> | ||
17 | #include <linux/io.h> | ||
18 | |||
19 | #include <lantiq.h> | ||
20 | |||
21 | /* Section 3.4 of the datasheet | ||
22 | * The password sequence protects the WDT control register from unintended | ||
23 | * write actions, which might cause malfunction of the WDT. | ||
24 | * | ||
25 | * essentially the following two magic passwords need to be written to allow | ||
26 | * IO access to the WDT core | ||
27 | */ | ||
28 | #define LTQ_WDT_PW1 0x00BE0000 | ||
29 | #define LTQ_WDT_PW2 0x00DC0000 | ||
30 | |||
31 | #define LTQ_WDT_CR 0x0 /* watchdog control register */ | ||
32 | #define LTQ_WDT_SR 0x8 /* watchdog status register */ | ||
33 | |||
34 | #define LTQ_WDT_SR_EN (0x1 << 31) /* enable bit */ | ||
35 | #define LTQ_WDT_SR_PWD (0x3 << 26) /* turn on power */ | ||
36 | #define LTQ_WDT_SR_CLKDIV (0x3 << 24) /* turn on clock and set */ | ||
37 | /* divider to 0x40000 */ | ||
38 | #define LTQ_WDT_DIVIDER 0x40000 | ||
39 | #define LTQ_MAX_TIMEOUT ((1 << 16) - 1) /* the reload field is 16 bit */ | ||
40 | |||
41 | static int nowayout = WATCHDOG_NOWAYOUT; | ||
42 | |||
43 | static void __iomem *ltq_wdt_membase; | ||
44 | static unsigned long ltq_io_region_clk_rate; | ||
45 | |||
46 | static unsigned long ltq_wdt_bootstatus; | ||
47 | static unsigned long ltq_wdt_in_use; | ||
48 | static int ltq_wdt_timeout = 30; | ||
49 | static int ltq_wdt_ok_to_close; | ||
50 | |||
51 | static void | ||
52 | ltq_wdt_enable(void) | ||
53 | { | ||
54 | ltq_wdt_timeout = ltq_wdt_timeout * | ||
55 | (ltq_io_region_clk_rate / LTQ_WDT_DIVIDER) + 0x1000; | ||
56 | if (ltq_wdt_timeout > LTQ_MAX_TIMEOUT) | ||
57 | ltq_wdt_timeout = LTQ_MAX_TIMEOUT; | ||
58 | |||
59 | /* write the first password magic */ | ||
60 | ltq_w32(LTQ_WDT_PW1, ltq_wdt_membase + LTQ_WDT_CR); | ||
61 | /* write the second magic plus the configuration and new timeout */ | ||
62 | ltq_w32(LTQ_WDT_SR_EN | LTQ_WDT_SR_PWD | LTQ_WDT_SR_CLKDIV | | ||
63 | LTQ_WDT_PW2 | ltq_wdt_timeout, ltq_wdt_membase + LTQ_WDT_CR); | ||
64 | } | ||
65 | |||
66 | static void | ||
67 | ltq_wdt_disable(void) | ||
68 | { | ||
69 | /* write the first password magic */ | ||
70 | ltq_w32(LTQ_WDT_PW1, ltq_wdt_membase + LTQ_WDT_CR); | ||
71 | /* write the second password magic with no config | ||
72 | * this turns the watchdog off | ||
73 | */ | ||
74 | ltq_w32(LTQ_WDT_PW2, ltq_wdt_membase + LTQ_WDT_CR); | ||
75 | } | ||
76 | |||
77 | static ssize_t | ||
78 | ltq_wdt_write(struct file *file, const char __user *data, | ||
79 | size_t len, loff_t *ppos) | ||
80 | { | ||
81 | if (len) { | ||
82 | if (!nowayout) { | ||
83 | size_t i; | ||
84 | |||
85 | ltq_wdt_ok_to_close = 0; | ||
86 | for (i = 0; i != len; i++) { | ||
87 | char c; | ||
88 | |||
89 | if (get_user(c, data + i)) | ||
90 | return -EFAULT; | ||
91 | if (c == 'V') | ||
92 | ltq_wdt_ok_to_close = 1; | ||
93 | else | ||
94 | ltq_wdt_ok_to_close = 0; | ||
95 | } | ||
96 | } | ||
97 | ltq_wdt_enable(); | ||
98 | } | ||
99 | |||
100 | return len; | ||
101 | } | ||
102 | |||
103 | static struct watchdog_info ident = { | ||
104 | .options = WDIOF_MAGICCLOSE | WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | | ||
105 | WDIOF_CARDRESET, | ||
106 | .identity = "ltq_wdt", | ||
107 | }; | ||
108 | |||
109 | static long | ||
110 | ltq_wdt_ioctl(struct file *file, | ||
111 | unsigned int cmd, unsigned long arg) | ||
112 | { | ||
113 | int ret = -ENOTTY; | ||
114 | |||
115 | switch (cmd) { | ||
116 | case WDIOC_GETSUPPORT: | ||
117 | ret = copy_to_user((struct watchdog_info __user *)arg, &ident, | ||
118 | sizeof(ident)) ? -EFAULT : 0; | ||
119 | break; | ||
120 | |||
121 | case WDIOC_GETBOOTSTATUS: | ||
122 | ret = put_user(ltq_wdt_bootstatus, (int __user *)arg); | ||
123 | break; | ||
124 | |||
125 | case WDIOC_GETSTATUS: | ||
126 | ret = put_user(0, (int __user *)arg); | ||
127 | break; | ||
128 | |||
129 | case WDIOC_SETTIMEOUT: | ||
130 | ret = get_user(ltq_wdt_timeout, (int __user *)arg); | ||
131 | if (!ret) | ||
132 | ltq_wdt_enable(); | ||
133 | /* intentional drop through */ | ||
134 | case WDIOC_GETTIMEOUT: | ||
135 | ret = put_user(ltq_wdt_timeout, (int __user *)arg); | ||
136 | break; | ||
137 | |||
138 | case WDIOC_KEEPALIVE: | ||
139 | ltq_wdt_enable(); | ||
140 | ret = 0; | ||
141 | break; | ||
142 | } | ||
143 | return ret; | ||
144 | } | ||
145 | |||
146 | static int | ||
147 | ltq_wdt_open(struct inode *inode, struct file *file) | ||
148 | { | ||
149 | if (test_and_set_bit(0, <q_wdt_in_use)) | ||
150 | return -EBUSY; | ||
151 | ltq_wdt_in_use = 1; | ||
152 | ltq_wdt_enable(); | ||
153 | |||
154 | return nonseekable_open(inode, file); | ||
155 | } | ||
156 | |||
157 | static int | ||
158 | ltq_wdt_release(struct inode *inode, struct file *file) | ||
159 | { | ||
160 | if (ltq_wdt_ok_to_close) | ||
161 | ltq_wdt_disable(); | ||
162 | else | ||
163 | pr_err("ltq_wdt: watchdog closed without warning\n"); | ||
164 | ltq_wdt_ok_to_close = 0; | ||
165 | clear_bit(0, <q_wdt_in_use); | ||
166 | |||
167 | return 0; | ||
168 | } | ||
169 | |||
170 | static const struct file_operations ltq_wdt_fops = { | ||
171 | .owner = THIS_MODULE, | ||
172 | .write = ltq_wdt_write, | ||
173 | .unlocked_ioctl = ltq_wdt_ioctl, | ||
174 | .open = ltq_wdt_open, | ||
175 | .release = ltq_wdt_release, | ||
176 | .llseek = no_llseek, | ||
177 | }; | ||
178 | |||
179 | static struct miscdevice ltq_wdt_miscdev = { | ||
180 | .minor = WATCHDOG_MINOR, | ||
181 | .name = "watchdog", | ||
182 | .fops = <q_wdt_fops, | ||
183 | }; | ||
184 | |||
185 | static int __init | ||
186 | ltq_wdt_probe(struct platform_device *pdev) | ||
187 | { | ||
188 | struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
189 | struct clk *clk; | ||
190 | |||
191 | if (!res) { | ||
192 | dev_err(&pdev->dev, "cannot obtain I/O memory region"); | ||
193 | return -ENOENT; | ||
194 | } | ||
195 | res = devm_request_mem_region(&pdev->dev, res->start, | ||
196 | resource_size(res), dev_name(&pdev->dev)); | ||
197 | if (!res) { | ||
198 | dev_err(&pdev->dev, "cannot request I/O memory region"); | ||
199 | return -EBUSY; | ||
200 | } | ||
201 | ltq_wdt_membase = devm_ioremap_nocache(&pdev->dev, res->start, | ||
202 | resource_size(res)); | ||
203 | if (!ltq_wdt_membase) { | ||
204 | dev_err(&pdev->dev, "cannot remap I/O memory region\n"); | ||
205 | return -ENOMEM; | ||
206 | } | ||
207 | |||
208 | /* we do not need to enable the clock as it is always running */ | ||
209 | clk = clk_get(&pdev->dev, "io"); | ||
210 | WARN_ON(!clk); | ||
211 | ltq_io_region_clk_rate = clk_get_rate(clk); | ||
212 | clk_put(clk); | ||
213 | |||
214 | if (ltq_reset_cause() == LTQ_RST_CAUSE_WDTRST) | ||
215 | ltq_wdt_bootstatus = WDIOF_CARDRESET; | ||
216 | |||
217 | return misc_register(<q_wdt_miscdev); | ||
218 | } | ||
219 | |||
220 | static int __devexit | ||
221 | ltq_wdt_remove(struct platform_device *pdev) | ||
222 | { | ||
223 | misc_deregister(<q_wdt_miscdev); | ||
224 | |||
225 | if (ltq_wdt_membase) | ||
226 | iounmap(ltq_wdt_membase); | ||
227 | |||
228 | return 0; | ||
229 | } | ||
230 | |||
231 | |||
232 | static struct platform_driver ltq_wdt_driver = { | ||
233 | .remove = __devexit_p(ltq_wdt_remove), | ||
234 | .driver = { | ||
235 | .name = "ltq_wdt", | ||
236 | .owner = THIS_MODULE, | ||
237 | }, | ||
238 | }; | ||
239 | |||
240 | static int __init | ||
241 | init_ltq_wdt(void) | ||
242 | { | ||
243 | return platform_driver_probe(<q_wdt_driver, ltq_wdt_probe); | ||
244 | } | ||
245 | |||
246 | static void __exit | ||
247 | exit_ltq_wdt(void) | ||
248 | { | ||
249 | return platform_driver_unregister(<q_wdt_driver); | ||
250 | } | ||
251 | |||
252 | module_init(init_ltq_wdt); | ||
253 | module_exit(exit_ltq_wdt); | ||
254 | |||
255 | module_param(nowayout, int, 0); | ||
256 | MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started"); | ||
257 | |||
258 | MODULE_AUTHOR("John Crispin <blogic@openwrt.org>"); | ||
259 | MODULE_DESCRIPTION("Lantiq SoC Watchdog"); | ||
260 | MODULE_LICENSE("GPL"); | ||
261 | MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR); | ||
diff --git a/drivers/watchdog/mtx-1_wdt.c b/drivers/watchdog/mtx-1_wdt.c index 5ec5ac1f7878..1479dc4d6129 100644 --- a/drivers/watchdog/mtx-1_wdt.c +++ b/drivers/watchdog/mtx-1_wdt.c | |||
@@ -66,6 +66,7 @@ static struct { | |||
66 | int default_ticks; | 66 | int default_ticks; |
67 | unsigned long inuse; | 67 | unsigned long inuse; |
68 | unsigned gpio; | 68 | unsigned gpio; |
69 | int gstate; | ||
69 | } mtx1_wdt_device; | 70 | } mtx1_wdt_device; |
70 | 71 | ||
71 | static void mtx1_wdt_trigger(unsigned long unused) | 72 | static void mtx1_wdt_trigger(unsigned long unused) |
@@ -75,13 +76,13 @@ static void mtx1_wdt_trigger(unsigned long unused) | |||
75 | spin_lock(&mtx1_wdt_device.lock); | 76 | spin_lock(&mtx1_wdt_device.lock); |
76 | if (mtx1_wdt_device.running) | 77 | if (mtx1_wdt_device.running) |
77 | ticks--; | 78 | ticks--; |
78 | /* | 79 | |
79 | * toggle GPIO2_15 | 80 | /* toggle wdt gpio */ |
80 | */ | 81 | mtx1_wdt_device.gstate = ~mtx1_wdt_device.gstate; |
81 | tmp = au_readl(GPIO2_DIR); | 82 | if (mtx1_wdt_device.gstate) |
82 | tmp = (tmp & ~(1 << mtx1_wdt_device.gpio)) | | 83 | gpio_direction_output(mtx1_wdt_device.gpio, 1); |
83 | ((~tmp) & (1 << mtx1_wdt_device.gpio)); | 84 | else |
84 | au_writel(tmp, GPIO2_DIR); | 85 | gpio_direction_input(mtx1_wdt_device.gpio); |
85 | 86 | ||
86 | if (mtx1_wdt_device.queue && ticks) | 87 | if (mtx1_wdt_device.queue && ticks) |
87 | mod_timer(&mtx1_wdt_device.timer, jiffies + MTX1_WDT_INTERVAL); | 88 | mod_timer(&mtx1_wdt_device.timer, jiffies + MTX1_WDT_INTERVAL); |
@@ -103,7 +104,8 @@ static void mtx1_wdt_start(void) | |||
103 | spin_lock_irqsave(&mtx1_wdt_device.lock, flags); | 104 | spin_lock_irqsave(&mtx1_wdt_device.lock, flags); |
104 | if (!mtx1_wdt_device.queue) { | 105 | if (!mtx1_wdt_device.queue) { |
105 | mtx1_wdt_device.queue = 1; | 106 | mtx1_wdt_device.queue = 1; |
106 | gpio_set_value(mtx1_wdt_device.gpio, 1); | 107 | mtx1_wdt_device.gstate = 1; |
108 | gpio_direction_output(mtx1_wdt_device.gpio, 1); | ||
107 | mod_timer(&mtx1_wdt_device.timer, jiffies + MTX1_WDT_INTERVAL); | 109 | mod_timer(&mtx1_wdt_device.timer, jiffies + MTX1_WDT_INTERVAL); |
108 | } | 110 | } |
109 | mtx1_wdt_device.running++; | 111 | mtx1_wdt_device.running++; |
@@ -117,7 +119,8 @@ static int mtx1_wdt_stop(void) | |||
117 | spin_lock_irqsave(&mtx1_wdt_device.lock, flags); | 119 | spin_lock_irqsave(&mtx1_wdt_device.lock, flags); |
118 | if (mtx1_wdt_device.queue) { | 120 | if (mtx1_wdt_device.queue) { |
119 | mtx1_wdt_device.queue = 0; | 121 | mtx1_wdt_device.queue = 0; |
120 | gpio_set_value(mtx1_wdt_device.gpio, 0); | 122 | mtx1_wdt_device.gstate = 0; |
123 | gpio_direction_output(mtx1_wdt_device.gpio, 0); | ||
121 | } | 124 | } |
122 | ticks = mtx1_wdt_device.default_ticks; | 125 | ticks = mtx1_wdt_device.default_ticks; |
123 | spin_unlock_irqrestore(&mtx1_wdt_device.lock, flags); | 126 | spin_unlock_irqrestore(&mtx1_wdt_device.lock, flags); |
diff --git a/drivers/xen/Makefile b/drivers/xen/Makefile index f420f1ff7f13..4781f806701d 100644 --- a/drivers/xen/Makefile +++ b/drivers/xen/Makefile | |||
@@ -4,21 +4,21 @@ obj-y += xenbus/ | |||
4 | nostackp := $(call cc-option, -fno-stack-protector) | 4 | nostackp := $(call cc-option, -fno-stack-protector) |
5 | CFLAGS_features.o := $(nostackp) | 5 | CFLAGS_features.o := $(nostackp) |
6 | 6 | ||
7 | obj-$(CONFIG_BLOCK) += biomerge.o | 7 | obj-$(CONFIG_BLOCK) += biomerge.o |
8 | obj-$(CONFIG_HOTPLUG_CPU) += cpu_hotplug.o | 8 | obj-$(CONFIG_HOTPLUG_CPU) += cpu_hotplug.o |
9 | obj-$(CONFIG_XEN_XENCOMM) += xencomm.o | 9 | obj-$(CONFIG_XEN_XENCOMM) += xencomm.o |
10 | obj-$(CONFIG_XEN_BALLOON) += xen-balloon.o | 10 | obj-$(CONFIG_XEN_BALLOON) += xen-balloon.o |
11 | obj-$(CONFIG_XEN_DEV_EVTCHN) += xen-evtchn.o | 11 | obj-$(CONFIG_XEN_DEV_EVTCHN) += xen-evtchn.o |
12 | obj-$(CONFIG_XEN_GNTDEV) += xen-gntdev.o | 12 | obj-$(CONFIG_XEN_GNTDEV) += xen-gntdev.o |
13 | obj-$(CONFIG_XEN_GRANT_DEV_ALLOC) += xen-gntalloc.o | 13 | obj-$(CONFIG_XEN_GRANT_DEV_ALLOC) += xen-gntalloc.o |
14 | obj-$(CONFIG_XENFS) += xenfs/ | 14 | obj-$(CONFIG_XENFS) += xenfs/ |
15 | obj-$(CONFIG_XEN_SYS_HYPERVISOR) += sys-hypervisor.o | 15 | obj-$(CONFIG_XEN_SYS_HYPERVISOR) += sys-hypervisor.o |
16 | obj-$(CONFIG_XEN_PLATFORM_PCI) += xen-platform-pci.o | 16 | obj-$(CONFIG_XEN_PLATFORM_PCI) += xen-platform-pci.o |
17 | obj-$(CONFIG_SWIOTLB_XEN) += swiotlb-xen.o | 17 | obj-$(CONFIG_SWIOTLB_XEN) += swiotlb-xen.o |
18 | obj-$(CONFIG_XEN_DOM0) += pci.o | 18 | obj-$(CONFIG_XEN_DOM0) += pci.o |
19 | 19 | ||
20 | xen-evtchn-y := evtchn.o | 20 | xen-evtchn-y := evtchn.o |
21 | xen-gntdev-y := gntdev.o | 21 | xen-gntdev-y := gntdev.o |
22 | xen-gntalloc-y := gntalloc.o | 22 | xen-gntalloc-y := gntalloc.o |
23 | 23 | ||
24 | xen-platform-pci-y := platform-pci.o | 24 | xen-platform-pci-y := platform-pci.o |
diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c index 043af8ad6b60..f54290baa3db 100644 --- a/drivers/xen/balloon.c +++ b/drivers/xen/balloon.c | |||
@@ -114,7 +114,6 @@ static void __balloon_append(struct page *page) | |||
114 | if (PageHighMem(page)) { | 114 | if (PageHighMem(page)) { |
115 | list_add_tail(&page->lru, &ballooned_pages); | 115 | list_add_tail(&page->lru, &ballooned_pages); |
116 | balloon_stats.balloon_high++; | 116 | balloon_stats.balloon_high++; |
117 | dec_totalhigh_pages(); | ||
118 | } else { | 117 | } else { |
119 | list_add(&page->lru, &ballooned_pages); | 118 | list_add(&page->lru, &ballooned_pages); |
120 | balloon_stats.balloon_low++; | 119 | balloon_stats.balloon_low++; |
@@ -124,6 +123,8 @@ static void __balloon_append(struct page *page) | |||
124 | static void balloon_append(struct page *page) | 123 | static void balloon_append(struct page *page) |
125 | { | 124 | { |
126 | __balloon_append(page); | 125 | __balloon_append(page); |
126 | if (PageHighMem(page)) | ||
127 | dec_totalhigh_pages(); | ||
127 | totalram_pages--; | 128 | totalram_pages--; |
128 | } | 129 | } |
129 | 130 | ||
@@ -193,7 +194,7 @@ static enum bp_state update_schedule(enum bp_state state) | |||
193 | return BP_EAGAIN; | 194 | return BP_EAGAIN; |
194 | } | 195 | } |
195 | 196 | ||
196 | static unsigned long current_target(void) | 197 | static long current_credit(void) |
197 | { | 198 | { |
198 | unsigned long target = balloon_stats.target_pages; | 199 | unsigned long target = balloon_stats.target_pages; |
199 | 200 | ||
@@ -202,7 +203,7 @@ static unsigned long current_target(void) | |||
202 | balloon_stats.balloon_low + | 203 | balloon_stats.balloon_low + |
203 | balloon_stats.balloon_high); | 204 | balloon_stats.balloon_high); |
204 | 205 | ||
205 | return target; | 206 | return target - balloon_stats.current_pages; |
206 | } | 207 | } |
207 | 208 | ||
208 | static enum bp_state increase_reservation(unsigned long nr_pages) | 209 | static enum bp_state increase_reservation(unsigned long nr_pages) |
@@ -246,7 +247,7 @@ static enum bp_state increase_reservation(unsigned long nr_pages) | |||
246 | set_phys_to_machine(pfn, frame_list[i]); | 247 | set_phys_to_machine(pfn, frame_list[i]); |
247 | 248 | ||
248 | /* Link back into the page tables if not highmem. */ | 249 | /* Link back into the page tables if not highmem. */ |
249 | if (!xen_hvm_domain() && pfn < max_low_pfn) { | 250 | if (xen_pv_domain() && !PageHighMem(page)) { |
250 | int ret; | 251 | int ret; |
251 | ret = HYPERVISOR_update_va_mapping( | 252 | ret = HYPERVISOR_update_va_mapping( |
252 | (unsigned long)__va(pfn << PAGE_SHIFT), | 253 | (unsigned long)__va(pfn << PAGE_SHIFT), |
@@ -293,7 +294,7 @@ static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp) | |||
293 | 294 | ||
294 | scrub_page(page); | 295 | scrub_page(page); |
295 | 296 | ||
296 | if (!xen_hvm_domain() && !PageHighMem(page)) { | 297 | if (xen_pv_domain() && !PageHighMem(page)) { |
297 | ret = HYPERVISOR_update_va_mapping( | 298 | ret = HYPERVISOR_update_va_mapping( |
298 | (unsigned long)__va(pfn << PAGE_SHIFT), | 299 | (unsigned long)__va(pfn << PAGE_SHIFT), |
299 | __pte_ma(0), 0); | 300 | __pte_ma(0), 0); |
@@ -337,7 +338,7 @@ static void balloon_process(struct work_struct *work) | |||
337 | mutex_lock(&balloon_mutex); | 338 | mutex_lock(&balloon_mutex); |
338 | 339 | ||
339 | do { | 340 | do { |
340 | credit = current_target() - balloon_stats.current_pages; | 341 | credit = current_credit(); |
341 | 342 | ||
342 | if (credit > 0) | 343 | if (credit > 0) |
343 | state = increase_reservation(credit); | 344 | state = increase_reservation(credit); |
@@ -420,7 +421,7 @@ void free_xenballooned_pages(int nr_pages, struct page** pages) | |||
420 | } | 421 | } |
421 | 422 | ||
422 | /* The balloon may be too large now. Shrink it if needed. */ | 423 | /* The balloon may be too large now. Shrink it if needed. */ |
423 | if (current_target() != balloon_stats.current_pages) | 424 | if (current_credit()) |
424 | schedule_delayed_work(&balloon_worker, 0); | 425 | schedule_delayed_work(&balloon_worker, 0); |
425 | 426 | ||
426 | mutex_unlock(&balloon_mutex); | 427 | mutex_unlock(&balloon_mutex); |
@@ -429,7 +430,7 @@ EXPORT_SYMBOL(free_xenballooned_pages); | |||
429 | 430 | ||
430 | static int __init balloon_init(void) | 431 | static int __init balloon_init(void) |
431 | { | 432 | { |
432 | unsigned long pfn, nr_pages, extra_pfn_end; | 433 | unsigned long pfn, extra_pfn_end; |
433 | struct page *page; | 434 | struct page *page; |
434 | 435 | ||
435 | if (!xen_domain()) | 436 | if (!xen_domain()) |
@@ -437,11 +438,7 @@ static int __init balloon_init(void) | |||
437 | 438 | ||
438 | pr_info("xen/balloon: Initialising balloon driver.\n"); | 439 | pr_info("xen/balloon: Initialising balloon driver.\n"); |
439 | 440 | ||
440 | if (xen_pv_domain()) | 441 | balloon_stats.current_pages = xen_pv_domain() ? min(xen_start_info->nr_pages, max_pfn) : max_pfn; |
441 | nr_pages = xen_start_info->nr_pages; | ||
442 | else | ||
443 | nr_pages = max_pfn; | ||
444 | balloon_stats.current_pages = min(nr_pages, max_pfn); | ||
445 | balloon_stats.target_pages = balloon_stats.current_pages; | 442 | balloon_stats.target_pages = balloon_stats.current_pages; |
446 | balloon_stats.balloon_low = 0; | 443 | balloon_stats.balloon_low = 0; |
447 | balloon_stats.balloon_high = 0; | 444 | balloon_stats.balloon_high = 0; |
@@ -466,7 +463,7 @@ static int __init balloon_init(void) | |||
466 | pfn < extra_pfn_end; | 463 | pfn < extra_pfn_end; |
467 | pfn++) { | 464 | pfn++) { |
468 | page = pfn_to_page(pfn); | 465 | page = pfn_to_page(pfn); |
469 | /* totalram_pages doesn't include the boot-time | 466 | /* totalram_pages and totalhigh_pages do not include the boot-time |
470 | balloon extension, so don't subtract from it. */ | 467 | balloon extension, so don't subtract from it. */ |
471 | __balloon_append(page); | 468 | __balloon_append(page); |
472 | } | 469 | } |
diff --git a/drivers/xen/events.c b/drivers/xen/events.c index 33167b43ac7e..3ff822b48145 100644 --- a/drivers/xen/events.c +++ b/drivers/xen/events.c | |||
@@ -101,6 +101,7 @@ struct irq_info | |||
101 | unsigned short gsi; | 101 | unsigned short gsi; |
102 | unsigned char vector; | 102 | unsigned char vector; |
103 | unsigned char flags; | 103 | unsigned char flags; |
104 | uint16_t domid; | ||
104 | } pirq; | 105 | } pirq; |
105 | } u; | 106 | } u; |
106 | }; | 107 | }; |
@@ -118,6 +119,8 @@ static DEFINE_PER_CPU(unsigned long [NR_EVENT_CHANNELS/BITS_PER_LONG], | |||
118 | static struct irq_chip xen_dynamic_chip; | 119 | static struct irq_chip xen_dynamic_chip; |
119 | static struct irq_chip xen_percpu_chip; | 120 | static struct irq_chip xen_percpu_chip; |
120 | static struct irq_chip xen_pirq_chip; | 121 | static struct irq_chip xen_pirq_chip; |
122 | static void enable_dynirq(struct irq_data *data); | ||
123 | static void disable_dynirq(struct irq_data *data); | ||
121 | 124 | ||
122 | /* Get info for IRQ */ | 125 | /* Get info for IRQ */ |
123 | static struct irq_info *info_for_irq(unsigned irq) | 126 | static struct irq_info *info_for_irq(unsigned irq) |
@@ -184,6 +187,7 @@ static void xen_irq_info_pirq_init(unsigned irq, | |||
184 | unsigned short pirq, | 187 | unsigned short pirq, |
185 | unsigned short gsi, | 188 | unsigned short gsi, |
186 | unsigned short vector, | 189 | unsigned short vector, |
190 | uint16_t domid, | ||
187 | unsigned char flags) | 191 | unsigned char flags) |
188 | { | 192 | { |
189 | struct irq_info *info = info_for_irq(irq); | 193 | struct irq_info *info = info_for_irq(irq); |
@@ -193,6 +197,7 @@ static void xen_irq_info_pirq_init(unsigned irq, | |||
193 | info->u.pirq.pirq = pirq; | 197 | info->u.pirq.pirq = pirq; |
194 | info->u.pirq.gsi = gsi; | 198 | info->u.pirq.gsi = gsi; |
195 | info->u.pirq.vector = vector; | 199 | info->u.pirq.vector = vector; |
200 | info->u.pirq.domid = domid; | ||
196 | info->u.pirq.flags = flags; | 201 | info->u.pirq.flags = flags; |
197 | } | 202 | } |
198 | 203 | ||
@@ -473,16 +478,6 @@ static void xen_free_irq(unsigned irq) | |||
473 | irq_free_desc(irq); | 478 | irq_free_desc(irq); |
474 | } | 479 | } |
475 | 480 | ||
476 | static void pirq_unmask_notify(int irq) | ||
477 | { | ||
478 | struct physdev_eoi eoi = { .irq = pirq_from_irq(irq) }; | ||
479 | |||
480 | if (unlikely(pirq_needs_eoi(irq))) { | ||
481 | int rc = HYPERVISOR_physdev_op(PHYSDEVOP_eoi, &eoi); | ||
482 | WARN_ON(rc); | ||
483 | } | ||
484 | } | ||
485 | |||
486 | static void pirq_query_unmask(int irq) | 481 | static void pirq_query_unmask(int irq) |
487 | { | 482 | { |
488 | struct physdev_irq_status_query irq_status; | 483 | struct physdev_irq_status_query irq_status; |
@@ -506,6 +501,29 @@ static bool probing_irq(int irq) | |||
506 | return desc && desc->action == NULL; | 501 | return desc && desc->action == NULL; |
507 | } | 502 | } |
508 | 503 | ||
504 | static void eoi_pirq(struct irq_data *data) | ||
505 | { | ||
506 | int evtchn = evtchn_from_irq(data->irq); | ||
507 | struct physdev_eoi eoi = { .irq = pirq_from_irq(data->irq) }; | ||
508 | int rc = 0; | ||
509 | |||
510 | irq_move_irq(data); | ||
511 | |||
512 | if (VALID_EVTCHN(evtchn)) | ||
513 | clear_evtchn(evtchn); | ||
514 | |||
515 | if (pirq_needs_eoi(data->irq)) { | ||
516 | rc = HYPERVISOR_physdev_op(PHYSDEVOP_eoi, &eoi); | ||
517 | WARN_ON(rc); | ||
518 | } | ||
519 | } | ||
520 | |||
521 | static void mask_ack_pirq(struct irq_data *data) | ||
522 | { | ||
523 | disable_dynirq(data); | ||
524 | eoi_pirq(data); | ||
525 | } | ||
526 | |||
509 | static unsigned int __startup_pirq(unsigned int irq) | 527 | static unsigned int __startup_pirq(unsigned int irq) |
510 | { | 528 | { |
511 | struct evtchn_bind_pirq bind_pirq; | 529 | struct evtchn_bind_pirq bind_pirq; |
@@ -539,7 +557,7 @@ static unsigned int __startup_pirq(unsigned int irq) | |||
539 | 557 | ||
540 | out: | 558 | out: |
541 | unmask_evtchn(evtchn); | 559 | unmask_evtchn(evtchn); |
542 | pirq_unmask_notify(irq); | 560 | eoi_pirq(irq_get_irq_data(irq)); |
543 | 561 | ||
544 | return 0; | 562 | return 0; |
545 | } | 563 | } |
@@ -579,18 +597,7 @@ static void enable_pirq(struct irq_data *data) | |||
579 | 597 | ||
580 | static void disable_pirq(struct irq_data *data) | 598 | static void disable_pirq(struct irq_data *data) |
581 | { | 599 | { |
582 | } | 600 | disable_dynirq(data); |
583 | |||
584 | static void ack_pirq(struct irq_data *data) | ||
585 | { | ||
586 | int evtchn = evtchn_from_irq(data->irq); | ||
587 | |||
588 | irq_move_irq(data); | ||
589 | |||
590 | if (VALID_EVTCHN(evtchn)) { | ||
591 | mask_evtchn(evtchn); | ||
592 | clear_evtchn(evtchn); | ||
593 | } | ||
594 | } | 601 | } |
595 | 602 | ||
596 | static int find_irq_by_gsi(unsigned gsi) | 603 | static int find_irq_by_gsi(unsigned gsi) |
@@ -639,9 +646,6 @@ int xen_bind_pirq_gsi_to_irq(unsigned gsi, | |||
639 | if (irq < 0) | 646 | if (irq < 0) |
640 | goto out; | 647 | goto out; |
641 | 648 | ||
642 | irq_set_chip_and_handler_name(irq, &xen_pirq_chip, handle_level_irq, | ||
643 | name); | ||
644 | |||
645 | irq_op.irq = irq; | 649 | irq_op.irq = irq; |
646 | irq_op.vector = 0; | 650 | irq_op.vector = 0; |
647 | 651 | ||
@@ -655,9 +659,35 @@ int xen_bind_pirq_gsi_to_irq(unsigned gsi, | |||
655 | goto out; | 659 | goto out; |
656 | } | 660 | } |
657 | 661 | ||
658 | xen_irq_info_pirq_init(irq, 0, pirq, gsi, irq_op.vector, | 662 | xen_irq_info_pirq_init(irq, 0, pirq, gsi, irq_op.vector, DOMID_SELF, |
659 | shareable ? PIRQ_SHAREABLE : 0); | 663 | shareable ? PIRQ_SHAREABLE : 0); |
660 | 664 | ||
665 | pirq_query_unmask(irq); | ||
666 | /* We try to use the handler with the appropriate semantic for the | ||
667 | * type of interrupt: if the interrupt doesn't need an eoi | ||
668 | * (pirq_needs_eoi returns false), we treat it like an edge | ||
669 | * triggered interrupt so we use handle_edge_irq. | ||
670 | * As a matter of fact this only happens when the corresponding | ||
671 | * physical interrupt is edge triggered or an msi. | ||
672 | * | ||
673 | * On the other hand if the interrupt needs an eoi (pirq_needs_eoi | ||
674 | * returns true) we treat it like a level triggered interrupt so we | ||
675 | * use handle_fasteoi_irq like the native code does for this kind of | ||
676 | * interrupts. | ||
677 | * Depending on the Xen version, pirq_needs_eoi might return true | ||
678 | * not only for level triggered interrupts but for edge triggered | ||
679 | * interrupts too. In any case Xen always honors the eoi mechanism, | ||
680 | * not injecting any more pirqs of the same kind if the first one | ||
681 | * hasn't received an eoi yet. Therefore using the fasteoi handler | ||
682 | * is the right choice either way. | ||
683 | */ | ||
684 | if (pirq_needs_eoi(irq)) | ||
685 | irq_set_chip_and_handler_name(irq, &xen_pirq_chip, | ||
686 | handle_fasteoi_irq, name); | ||
687 | else | ||
688 | irq_set_chip_and_handler_name(irq, &xen_pirq_chip, | ||
689 | handle_edge_irq, name); | ||
690 | |||
661 | out: | 691 | out: |
662 | spin_unlock(&irq_mapping_update_lock); | 692 | spin_unlock(&irq_mapping_update_lock); |
663 | 693 | ||
@@ -680,7 +710,8 @@ int xen_allocate_pirq_msi(struct pci_dev *dev, struct msi_desc *msidesc) | |||
680 | } | 710 | } |
681 | 711 | ||
682 | int xen_bind_pirq_msi_to_irq(struct pci_dev *dev, struct msi_desc *msidesc, | 712 | int xen_bind_pirq_msi_to_irq(struct pci_dev *dev, struct msi_desc *msidesc, |
683 | int pirq, int vector, const char *name) | 713 | int pirq, int vector, const char *name, |
714 | domid_t domid) | ||
684 | { | 715 | { |
685 | int irq, ret; | 716 | int irq, ret; |
686 | 717 | ||
@@ -690,10 +721,10 @@ int xen_bind_pirq_msi_to_irq(struct pci_dev *dev, struct msi_desc *msidesc, | |||
690 | if (irq == -1) | 721 | if (irq == -1) |
691 | goto out; | 722 | goto out; |
692 | 723 | ||
693 | irq_set_chip_and_handler_name(irq, &xen_pirq_chip, handle_level_irq, | 724 | irq_set_chip_and_handler_name(irq, &xen_pirq_chip, handle_edge_irq, |
694 | name); | 725 | name); |
695 | 726 | ||
696 | xen_irq_info_pirq_init(irq, 0, pirq, 0, vector, 0); | 727 | xen_irq_info_pirq_init(irq, 0, pirq, 0, vector, domid, 0); |
697 | ret = irq_set_msi_desc(irq, msidesc); | 728 | ret = irq_set_msi_desc(irq, msidesc); |
698 | if (ret < 0) | 729 | if (ret < 0) |
699 | goto error_irq; | 730 | goto error_irq; |
@@ -722,9 +753,16 @@ int xen_destroy_irq(int irq) | |||
722 | 753 | ||
723 | if (xen_initial_domain()) { | 754 | if (xen_initial_domain()) { |
724 | unmap_irq.pirq = info->u.pirq.pirq; | 755 | unmap_irq.pirq = info->u.pirq.pirq; |
725 | unmap_irq.domid = DOMID_SELF; | 756 | unmap_irq.domid = info->u.pirq.domid; |
726 | rc = HYPERVISOR_physdev_op(PHYSDEVOP_unmap_pirq, &unmap_irq); | 757 | rc = HYPERVISOR_physdev_op(PHYSDEVOP_unmap_pirq, &unmap_irq); |
727 | if (rc) { | 758 | /* If another domain quits without making the pci_disable_msix |
759 | * call, the Xen hypervisor takes care of freeing the PIRQs | ||
760 | * (free_domain_pirqs). | ||
761 | */ | ||
762 | if ((rc == -ESRCH && info->u.pirq.domid != DOMID_SELF)) | ||
763 | printk(KERN_INFO "domain %d does not have %d anymore\n", | ||
764 | info->u.pirq.domid, info->u.pirq.pirq); | ||
765 | else if (rc) { | ||
728 | printk(KERN_WARNING "unmap irq failed %d\n", rc); | 766 | printk(KERN_WARNING "unmap irq failed %d\n", rc); |
729 | goto out; | 767 | goto out; |
730 | } | 768 | } |
@@ -759,6 +797,12 @@ out: | |||
759 | return irq; | 797 | return irq; |
760 | } | 798 | } |
761 | 799 | ||
800 | |||
801 | int xen_pirq_from_irq(unsigned irq) | ||
802 | { | ||
803 | return pirq_from_irq(irq); | ||
804 | } | ||
805 | EXPORT_SYMBOL_GPL(xen_pirq_from_irq); | ||
762 | int bind_evtchn_to_irq(unsigned int evtchn) | 806 | int bind_evtchn_to_irq(unsigned int evtchn) |
763 | { | 807 | { |
764 | int irq; | 808 | int irq; |
@@ -773,7 +817,7 @@ int bind_evtchn_to_irq(unsigned int evtchn) | |||
773 | goto out; | 817 | goto out; |
774 | 818 | ||
775 | irq_set_chip_and_handler_name(irq, &xen_dynamic_chip, | 819 | irq_set_chip_and_handler_name(irq, &xen_dynamic_chip, |
776 | handle_fasteoi_irq, "event"); | 820 | handle_edge_irq, "event"); |
777 | 821 | ||
778 | xen_irq_info_evtchn_init(irq, evtchn); | 822 | xen_irq_info_evtchn_init(irq, evtchn); |
779 | } | 823 | } |
@@ -1179,9 +1223,6 @@ static void __xen_evtchn_do_upcall(void) | |||
1179 | port = (word_idx * BITS_PER_LONG) + bit_idx; | 1223 | port = (word_idx * BITS_PER_LONG) + bit_idx; |
1180 | irq = evtchn_to_irq[port]; | 1224 | irq = evtchn_to_irq[port]; |
1181 | 1225 | ||
1182 | mask_evtchn(port); | ||
1183 | clear_evtchn(port); | ||
1184 | |||
1185 | if (irq != -1) { | 1226 | if (irq != -1) { |
1186 | desc = irq_to_desc(irq); | 1227 | desc = irq_to_desc(irq); |
1187 | if (desc) | 1228 | if (desc) |
@@ -1337,10 +1378,16 @@ static void ack_dynirq(struct irq_data *data) | |||
1337 | { | 1378 | { |
1338 | int evtchn = evtchn_from_irq(data->irq); | 1379 | int evtchn = evtchn_from_irq(data->irq); |
1339 | 1380 | ||
1340 | irq_move_masked_irq(data); | 1381 | irq_move_irq(data); |
1341 | 1382 | ||
1342 | if (VALID_EVTCHN(evtchn)) | 1383 | if (VALID_EVTCHN(evtchn)) |
1343 | unmask_evtchn(evtchn); | 1384 | clear_evtchn(evtchn); |
1385 | } | ||
1386 | |||
1387 | static void mask_ack_dynirq(struct irq_data *data) | ||
1388 | { | ||
1389 | disable_dynirq(data); | ||
1390 | ack_dynirq(data); | ||
1344 | } | 1391 | } |
1345 | 1392 | ||
1346 | static int retrigger_dynirq(struct irq_data *data) | 1393 | static int retrigger_dynirq(struct irq_data *data) |
@@ -1502,6 +1549,18 @@ void xen_poll_irq(int irq) | |||
1502 | xen_poll_irq_timeout(irq, 0 /* no timeout */); | 1549 | xen_poll_irq_timeout(irq, 0 /* no timeout */); |
1503 | } | 1550 | } |
1504 | 1551 | ||
1552 | /* Check whether the IRQ line is shared with other guests. */ | ||
1553 | int xen_test_irq_shared(int irq) | ||
1554 | { | ||
1555 | struct irq_info *info = info_for_irq(irq); | ||
1556 | struct physdev_irq_status_query irq_status = { .irq = info->u.pirq.pirq }; | ||
1557 | |||
1558 | if (HYPERVISOR_physdev_op(PHYSDEVOP_irq_status_query, &irq_status)) | ||
1559 | return 0; | ||
1560 | return !(irq_status.flags & XENIRQSTAT_shared); | ||
1561 | } | ||
1562 | EXPORT_SYMBOL_GPL(xen_test_irq_shared); | ||
1563 | |||
1505 | void xen_irq_resume(void) | 1564 | void xen_irq_resume(void) |
1506 | { | 1565 | { |
1507 | unsigned int cpu, evtchn; | 1566 | unsigned int cpu, evtchn; |
@@ -1535,7 +1594,9 @@ static struct irq_chip xen_dynamic_chip __read_mostly = { | |||
1535 | .irq_mask = disable_dynirq, | 1594 | .irq_mask = disable_dynirq, |
1536 | .irq_unmask = enable_dynirq, | 1595 | .irq_unmask = enable_dynirq, |
1537 | 1596 | ||
1538 | .irq_eoi = ack_dynirq, | 1597 | .irq_ack = ack_dynirq, |
1598 | .irq_mask_ack = mask_ack_dynirq, | ||
1599 | |||
1539 | .irq_set_affinity = set_affinity_irq, | 1600 | .irq_set_affinity = set_affinity_irq, |
1540 | .irq_retrigger = retrigger_dynirq, | 1601 | .irq_retrigger = retrigger_dynirq, |
1541 | }; | 1602 | }; |
@@ -1545,14 +1606,15 @@ static struct irq_chip xen_pirq_chip __read_mostly = { | |||
1545 | 1606 | ||
1546 | .irq_startup = startup_pirq, | 1607 | .irq_startup = startup_pirq, |
1547 | .irq_shutdown = shutdown_pirq, | 1608 | .irq_shutdown = shutdown_pirq, |
1548 | |||
1549 | .irq_enable = enable_pirq, | 1609 | .irq_enable = enable_pirq, |
1550 | .irq_unmask = enable_pirq, | ||
1551 | |||
1552 | .irq_disable = disable_pirq, | 1610 | .irq_disable = disable_pirq, |
1553 | .irq_mask = disable_pirq, | ||
1554 | 1611 | ||
1555 | .irq_ack = ack_pirq, | 1612 | .irq_mask = disable_dynirq, |
1613 | .irq_unmask = enable_dynirq, | ||
1614 | |||
1615 | .irq_ack = eoi_pirq, | ||
1616 | .irq_eoi = eoi_pirq, | ||
1617 | .irq_mask_ack = mask_ack_pirq, | ||
1556 | 1618 | ||
1557 | .irq_set_affinity = set_affinity_irq, | 1619 | .irq_set_affinity = set_affinity_irq, |
1558 | 1620 | ||
diff --git a/drivers/xen/gntalloc.c b/drivers/xen/gntalloc.c index a7ffdfe19fc9..f6832f46aea4 100644 --- a/drivers/xen/gntalloc.c +++ b/drivers/xen/gntalloc.c | |||
@@ -427,6 +427,17 @@ static long gntalloc_ioctl(struct file *filp, unsigned int cmd, | |||
427 | return 0; | 427 | return 0; |
428 | } | 428 | } |
429 | 429 | ||
430 | static void gntalloc_vma_open(struct vm_area_struct *vma) | ||
431 | { | ||
432 | struct gntalloc_gref *gref = vma->vm_private_data; | ||
433 | if (!gref) | ||
434 | return; | ||
435 | |||
436 | spin_lock(&gref_lock); | ||
437 | gref->users++; | ||
438 | spin_unlock(&gref_lock); | ||
439 | } | ||
440 | |||
430 | static void gntalloc_vma_close(struct vm_area_struct *vma) | 441 | static void gntalloc_vma_close(struct vm_area_struct *vma) |
431 | { | 442 | { |
432 | struct gntalloc_gref *gref = vma->vm_private_data; | 443 | struct gntalloc_gref *gref = vma->vm_private_data; |
@@ -441,6 +452,7 @@ static void gntalloc_vma_close(struct vm_area_struct *vma) | |||
441 | } | 452 | } |
442 | 453 | ||
443 | static struct vm_operations_struct gntalloc_vmops = { | 454 | static struct vm_operations_struct gntalloc_vmops = { |
455 | .open = gntalloc_vma_open, | ||
444 | .close = gntalloc_vma_close, | 456 | .close = gntalloc_vma_close, |
445 | }; | 457 | }; |
446 | 458 | ||
@@ -471,8 +483,6 @@ static int gntalloc_mmap(struct file *filp, struct vm_area_struct *vma) | |||
471 | vma->vm_private_data = gref; | 483 | vma->vm_private_data = gref; |
472 | 484 | ||
473 | vma->vm_flags |= VM_RESERVED; | 485 | vma->vm_flags |= VM_RESERVED; |
474 | vma->vm_flags |= VM_DONTCOPY; | ||
475 | vma->vm_flags |= VM_PFNMAP | VM_PFN_AT_MMAP; | ||
476 | 486 | ||
477 | vma->vm_ops = &gntalloc_vmops; | 487 | vma->vm_ops = &gntalloc_vmops; |
478 | 488 | ||
diff --git a/drivers/xen/gntdev.c b/drivers/xen/gntdev.c index b0f9e8fb0052..f914b26cf0c2 100644 --- a/drivers/xen/gntdev.c +++ b/drivers/xen/gntdev.c | |||
@@ -330,17 +330,26 @@ static int unmap_grant_pages(struct grant_map *map, int offset, int pages) | |||
330 | 330 | ||
331 | /* ------------------------------------------------------------------ */ | 331 | /* ------------------------------------------------------------------ */ |
332 | 332 | ||
333 | static void gntdev_vma_open(struct vm_area_struct *vma) | ||
334 | { | ||
335 | struct grant_map *map = vma->vm_private_data; | ||
336 | |||
337 | pr_debug("gntdev_vma_open %p\n", vma); | ||
338 | atomic_inc(&map->users); | ||
339 | } | ||
340 | |||
333 | static void gntdev_vma_close(struct vm_area_struct *vma) | 341 | static void gntdev_vma_close(struct vm_area_struct *vma) |
334 | { | 342 | { |
335 | struct grant_map *map = vma->vm_private_data; | 343 | struct grant_map *map = vma->vm_private_data; |
336 | 344 | ||
337 | pr_debug("close %p\n", vma); | 345 | pr_debug("gntdev_vma_close %p\n", vma); |
338 | map->vma = NULL; | 346 | map->vma = NULL; |
339 | vma->vm_private_data = NULL; | 347 | vma->vm_private_data = NULL; |
340 | gntdev_put_map(map); | 348 | gntdev_put_map(map); |
341 | } | 349 | } |
342 | 350 | ||
343 | static struct vm_operations_struct gntdev_vmops = { | 351 | static struct vm_operations_struct gntdev_vmops = { |
352 | .open = gntdev_vma_open, | ||
344 | .close = gntdev_vma_close, | 353 | .close = gntdev_vma_close, |
345 | }; | 354 | }; |
346 | 355 | ||
@@ -652,7 +661,10 @@ static int gntdev_mmap(struct file *flip, struct vm_area_struct *vma) | |||
652 | 661 | ||
653 | vma->vm_ops = &gntdev_vmops; | 662 | vma->vm_ops = &gntdev_vmops; |
654 | 663 | ||
655 | vma->vm_flags |= VM_RESERVED|VM_DONTCOPY|VM_DONTEXPAND|VM_PFNMAP; | 664 | vma->vm_flags |= VM_RESERVED|VM_DONTEXPAND; |
665 | |||
666 | if (use_ptemod) | ||
667 | vma->vm_flags |= VM_DONTCOPY|VM_PFNMAP; | ||
656 | 668 | ||
657 | vma->vm_private_data = map; | 669 | vma->vm_private_data = map; |
658 | 670 | ||
diff --git a/drivers/xen/grant-table.c b/drivers/xen/grant-table.c index 3745a318defc..fd725cde6ad1 100644 --- a/drivers/xen/grant-table.c +++ b/drivers/xen/grant-table.c | |||
@@ -466,13 +466,30 @@ int gnttab_map_refs(struct gnttab_map_grant_ref *map_ops, | |||
466 | if (map_ops[i].status) | 466 | if (map_ops[i].status) |
467 | continue; | 467 | continue; |
468 | 468 | ||
469 | /* m2p override only supported for GNTMAP_contains_pte mappings */ | 469 | if (map_ops[i].flags & GNTMAP_contains_pte) { |
470 | if (!(map_ops[i].flags & GNTMAP_contains_pte)) | 470 | pte = (pte_t *) (mfn_to_virt(PFN_DOWN(map_ops[i].host_addr)) + |
471 | continue; | ||
472 | pte = (pte_t *) (mfn_to_virt(PFN_DOWN(map_ops[i].host_addr)) + | ||
473 | (map_ops[i].host_addr & ~PAGE_MASK)); | 471 | (map_ops[i].host_addr & ~PAGE_MASK)); |
474 | mfn = pte_mfn(*pte); | 472 | mfn = pte_mfn(*pte); |
475 | ret = m2p_add_override(mfn, pages[i]); | 473 | } else { |
474 | /* If you really wanted to do this: | ||
475 | * mfn = PFN_DOWN(map_ops[i].dev_bus_addr); | ||
476 | * | ||
477 | * The reason we do not implement it is b/c on the | ||
478 | * unmap path (gnttab_unmap_refs) we have no means of | ||
479 | * checking whether the page is !GNTMAP_contains_pte. | ||
480 | * | ||
481 | * That is without some extra data-structure to carry | ||
482 | * the struct page, bool clear_pte, and list_head next | ||
483 | * tuples and deal with allocation/delallocation, etc. | ||
484 | * | ||
485 | * The users of this API set the GNTMAP_contains_pte | ||
486 | * flag so lets just return not supported until it | ||
487 | * becomes neccessary to implement. | ||
488 | */ | ||
489 | return -EOPNOTSUPP; | ||
490 | } | ||
491 | ret = m2p_add_override(mfn, pages[i], | ||
492 | map_ops[i].flags & GNTMAP_contains_pte); | ||
476 | if (ret) | 493 | if (ret) |
477 | return ret; | 494 | return ret; |
478 | } | 495 | } |
@@ -494,7 +511,7 @@ int gnttab_unmap_refs(struct gnttab_unmap_grant_ref *unmap_ops, | |||
494 | return ret; | 511 | return ret; |
495 | 512 | ||
496 | for (i = 0; i < count; i++) { | 513 | for (i = 0; i < count; i++) { |
497 | ret = m2p_remove_override(pages[i]); | 514 | ret = m2p_remove_override(pages[i], true /* clear the PTE */); |
498 | if (ret) | 515 | if (ret) |
499 | return ret; | 516 | return ret; |
500 | } | 517 | } |
diff --git a/drivers/xen/manage.c b/drivers/xen/manage.c index a2eee574784e..0b5366b5be20 100644 --- a/drivers/xen/manage.c +++ b/drivers/xen/manage.c | |||
@@ -70,12 +70,7 @@ static int xen_suspend(void *data) | |||
70 | 70 | ||
71 | BUG_ON(!irqs_disabled()); | 71 | BUG_ON(!irqs_disabled()); |
72 | 72 | ||
73 | err = sysdev_suspend(PMSG_FREEZE); | 73 | err = syscore_suspend(); |
74 | if (!err) { | ||
75 | err = syscore_suspend(); | ||
76 | if (err) | ||
77 | sysdev_resume(); | ||
78 | } | ||
79 | if (err) { | 74 | if (err) { |
80 | printk(KERN_ERR "xen_suspend: system core suspend failed: %d\n", | 75 | printk(KERN_ERR "xen_suspend: system core suspend failed: %d\n", |
81 | err); | 76 | err); |
@@ -102,7 +97,6 @@ static int xen_suspend(void *data) | |||
102 | } | 97 | } |
103 | 98 | ||
104 | syscore_resume(); | 99 | syscore_resume(); |
105 | sysdev_resume(); | ||
106 | 100 | ||
107 | return 0; | 101 | return 0; |
108 | } | 102 | } |
diff --git a/drivers/xen/sys-hypervisor.c b/drivers/xen/sys-hypervisor.c index 60f1827a32cb..1e0fe01eb670 100644 --- a/drivers/xen/sys-hypervisor.c +++ b/drivers/xen/sys-hypervisor.c | |||
@@ -215,7 +215,7 @@ static struct attribute_group xen_compilation_group = { | |||
215 | .attrs = xen_compile_attrs, | 215 | .attrs = xen_compile_attrs, |
216 | }; | 216 | }; |
217 | 217 | ||
218 | int __init static xen_compilation_init(void) | 218 | static int __init xen_compilation_init(void) |
219 | { | 219 | { |
220 | return sysfs_create_group(hypervisor_kobj, &xen_compilation_group); | 220 | return sysfs_create_group(hypervisor_kobj, &xen_compilation_group); |
221 | } | 221 | } |