diff options
author | Thomas Gleixner <tglx@linutronix.de> | 2009-03-23 09:50:03 -0400 |
---|---|---|
committer | Thomas Gleixner <tglx@linutronix.de> | 2009-03-23 16:20:20 -0400 |
commit | 80c5520811d3805adcb15c570ea5e2d489fa5d0b (patch) | |
tree | ae797a7f4af39f80e77526533d06ac23b439f0ab /arch/x86/kernel/microcode_core.c | |
parent | b3e3b302cf6dc8d60b67f0e84d1fa5648889c038 (diff) | |
parent | 8c083f081d0014057901c68a0a3e0f8ca7ac8d23 (diff) |
Merge branch 'cpus4096' into irq/threaded
Conflicts:
arch/parisc/kernel/irq.c
kernel/irq/handle.c
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'arch/x86/kernel/microcode_core.c')
-rw-r--r-- | arch/x86/kernel/microcode_core.c | 160 |
1 files changed, 88 insertions, 72 deletions
diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c index c9b721ba968c..a0f3851ef310 100644 --- a/arch/x86/kernel/microcode_core.c +++ b/arch/x86/kernel/microcode_core.c | |||
@@ -70,67 +70,78 @@ | |||
70 | * Fix sigmatch() macro to handle old CPUs with pf == 0. | 70 | * Fix sigmatch() macro to handle old CPUs with pf == 0. |
71 | * Thanks to Stuart Swales for pointing out this bug. | 71 | * Thanks to Stuart Swales for pointing out this bug. |
72 | */ | 72 | */ |
73 | #include <linux/platform_device.h> | ||
73 | #include <linux/capability.h> | 74 | #include <linux/capability.h> |
74 | #include <linux/kernel.h> | 75 | #include <linux/miscdevice.h> |
75 | #include <linux/init.h> | 76 | #include <linux/firmware.h> |
76 | #include <linux/sched.h> | ||
77 | #include <linux/smp_lock.h> | 77 | #include <linux/smp_lock.h> |
78 | #include <linux/spinlock.h> | ||
78 | #include <linux/cpumask.h> | 79 | #include <linux/cpumask.h> |
79 | #include <linux/module.h> | 80 | #include <linux/uaccess.h> |
80 | #include <linux/slab.h> | ||
81 | #include <linux/vmalloc.h> | 81 | #include <linux/vmalloc.h> |
82 | #include <linux/miscdevice.h> | 82 | #include <linux/kernel.h> |
83 | #include <linux/spinlock.h> | 83 | #include <linux/module.h> |
84 | #include <linux/mm.h> | ||
85 | #include <linux/fs.h> | ||
86 | #include <linux/mutex.h> | 84 | #include <linux/mutex.h> |
85 | #include <linux/sched.h> | ||
86 | #include <linux/init.h> | ||
87 | #include <linux/slab.h> | ||
87 | #include <linux/cpu.h> | 88 | #include <linux/cpu.h> |
88 | #include <linux/firmware.h> | 89 | #include <linux/fs.h> |
89 | #include <linux/platform_device.h> | 90 | #include <linux/mm.h> |
90 | 91 | ||
91 | #include <asm/msr.h> | ||
92 | #include <asm/uaccess.h> | ||
93 | #include <asm/processor.h> | ||
94 | #include <asm/microcode.h> | 92 | #include <asm/microcode.h> |
93 | #include <asm/processor.h> | ||
94 | #include <asm/msr.h> | ||
95 | 95 | ||
96 | MODULE_DESCRIPTION("Microcode Update Driver"); | 96 | MODULE_DESCRIPTION("Microcode Update Driver"); |
97 | MODULE_AUTHOR("Tigran Aivazian <tigran@aivazian.fsnet.co.uk>"); | 97 | MODULE_AUTHOR("Tigran Aivazian <tigran@aivazian.fsnet.co.uk>"); |
98 | MODULE_LICENSE("GPL"); | 98 | MODULE_LICENSE("GPL"); |
99 | 99 | ||
100 | #define MICROCODE_VERSION "2.00" | 100 | #define MICROCODE_VERSION "2.00" |
101 | 101 | ||
102 | static struct microcode_ops *microcode_ops; | 102 | static struct microcode_ops *microcode_ops; |
103 | 103 | ||
104 | /* no concurrent ->write()s are allowed on /dev/cpu/microcode */ | 104 | /* no concurrent ->write()s are allowed on /dev/cpu/microcode */ |
105 | static DEFINE_MUTEX(microcode_mutex); | 105 | static DEFINE_MUTEX(microcode_mutex); |
106 | 106 | ||
107 | struct ucode_cpu_info ucode_cpu_info[NR_CPUS]; | 107 | struct ucode_cpu_info ucode_cpu_info[NR_CPUS]; |
108 | EXPORT_SYMBOL_GPL(ucode_cpu_info); | 108 | EXPORT_SYMBOL_GPL(ucode_cpu_info); |
109 | 109 | ||
110 | #ifdef CONFIG_MICROCODE_OLD_INTERFACE | 110 | #ifdef CONFIG_MICROCODE_OLD_INTERFACE |
111 | struct update_for_cpu { | ||
112 | const void __user *buf; | ||
113 | size_t size; | ||
114 | }; | ||
115 | |||
116 | static long update_for_cpu(void *_ufc) | ||
117 | { | ||
118 | struct update_for_cpu *ufc = _ufc; | ||
119 | int error; | ||
120 | |||
121 | error = microcode_ops->request_microcode_user(smp_processor_id(), | ||
122 | ufc->buf, ufc->size); | ||
123 | if (error < 0) | ||
124 | return error; | ||
125 | if (!error) | ||
126 | microcode_ops->apply_microcode(smp_processor_id()); | ||
127 | return error; | ||
128 | } | ||
129 | |||
111 | static int do_microcode_update(const void __user *buf, size_t size) | 130 | static int do_microcode_update(const void __user *buf, size_t size) |
112 | { | 131 | { |
113 | cpumask_t old; | ||
114 | int error = 0; | 132 | int error = 0; |
115 | int cpu; | 133 | int cpu; |
116 | 134 | struct update_for_cpu ufc = { .buf = buf, .size = size }; | |
117 | old = current->cpus_allowed; | ||
118 | 135 | ||
119 | for_each_online_cpu(cpu) { | 136 | for_each_online_cpu(cpu) { |
120 | struct ucode_cpu_info *uci = ucode_cpu_info + cpu; | 137 | struct ucode_cpu_info *uci = ucode_cpu_info + cpu; |
121 | 138 | ||
122 | if (!uci->valid) | 139 | if (!uci->valid) |
123 | continue; | 140 | continue; |
124 | 141 | error = work_on_cpu(cpu, update_for_cpu, &ufc); | |
125 | set_cpus_allowed_ptr(current, &cpumask_of_cpu(cpu)); | ||
126 | error = microcode_ops->request_microcode_user(cpu, buf, size); | ||
127 | if (error < 0) | 142 | if (error < 0) |
128 | goto out; | 143 | break; |
129 | if (!error) | ||
130 | microcode_ops->apply_microcode(cpu); | ||
131 | } | 144 | } |
132 | out: | ||
133 | set_cpus_allowed_ptr(current, &old); | ||
134 | return error; | 145 | return error; |
135 | } | 146 | } |
136 | 147 | ||
@@ -198,18 +209,33 @@ static void microcode_dev_exit(void) | |||
198 | 209 | ||
199 | MODULE_ALIAS_MISCDEV(MICROCODE_MINOR); | 210 | MODULE_ALIAS_MISCDEV(MICROCODE_MINOR); |
200 | #else | 211 | #else |
201 | #define microcode_dev_init() 0 | 212 | #define microcode_dev_init() 0 |
202 | #define microcode_dev_exit() do { } while (0) | 213 | #define microcode_dev_exit() do { } while (0) |
203 | #endif | 214 | #endif |
204 | 215 | ||
205 | /* fake device for request_firmware */ | 216 | /* fake device for request_firmware */ |
206 | static struct platform_device *microcode_pdev; | 217 | static struct platform_device *microcode_pdev; |
218 | |||
219 | static long reload_for_cpu(void *unused) | ||
220 | { | ||
221 | struct ucode_cpu_info *uci = ucode_cpu_info + smp_processor_id(); | ||
222 | int err = 0; | ||
223 | |||
224 | mutex_lock(µcode_mutex); | ||
225 | if (uci->valid) { | ||
226 | err = microcode_ops->request_microcode_fw(smp_processor_id(), | ||
227 | µcode_pdev->dev); | ||
228 | if (!err) | ||
229 | microcode_ops->apply_microcode(smp_processor_id()); | ||
230 | } | ||
231 | mutex_unlock(µcode_mutex); | ||
232 | return err; | ||
233 | } | ||
207 | 234 | ||
208 | static ssize_t reload_store(struct sys_device *dev, | 235 | static ssize_t reload_store(struct sys_device *dev, |
209 | struct sysdev_attribute *attr, | 236 | struct sysdev_attribute *attr, |
210 | const char *buf, size_t sz) | 237 | const char *buf, size_t sz) |
211 | { | 238 | { |
212 | struct ucode_cpu_info *uci = ucode_cpu_info + dev->id; | ||
213 | char *end; | 239 | char *end; |
214 | unsigned long val = simple_strtoul(buf, &end, 0); | 240 | unsigned long val = simple_strtoul(buf, &end, 0); |
215 | int err = 0; | 241 | int err = 0; |
@@ -218,21 +244,9 @@ static ssize_t reload_store(struct sys_device *dev, | |||
218 | if (end == buf) | 244 | if (end == buf) |
219 | return -EINVAL; | 245 | return -EINVAL; |
220 | if (val == 1) { | 246 | if (val == 1) { |
221 | cpumask_t old = current->cpus_allowed; | ||
222 | |||
223 | get_online_cpus(); | 247 | get_online_cpus(); |
224 | if (cpu_online(cpu)) { | 248 | if (cpu_online(cpu)) |
225 | set_cpus_allowed_ptr(current, &cpumask_of_cpu(cpu)); | 249 | err = work_on_cpu(cpu, reload_for_cpu, NULL); |
226 | mutex_lock(µcode_mutex); | ||
227 | if (uci->valid) { | ||
228 | err = microcode_ops->request_microcode_fw(cpu, | ||
229 | µcode_pdev->dev); | ||
230 | if (!err) | ||
231 | microcode_ops->apply_microcode(cpu); | ||
232 | } | ||
233 | mutex_unlock(µcode_mutex); | ||
234 | set_cpus_allowed_ptr(current, &old); | ||
235 | } | ||
236 | put_online_cpus(); | 250 | put_online_cpus(); |
237 | } | 251 | } |
238 | if (err) | 252 | if (err) |
@@ -268,8 +282,8 @@ static struct attribute *mc_default_attrs[] = { | |||
268 | }; | 282 | }; |
269 | 283 | ||
270 | static struct attribute_group mc_attr_group = { | 284 | static struct attribute_group mc_attr_group = { |
271 | .attrs = mc_default_attrs, | 285 | .attrs = mc_default_attrs, |
272 | .name = "microcode", | 286 | .name = "microcode", |
273 | }; | 287 | }; |
274 | 288 | ||
275 | static void __microcode_fini_cpu(int cpu) | 289 | static void __microcode_fini_cpu(int cpu) |
@@ -328,9 +342,9 @@ static int microcode_resume_cpu(int cpu) | |||
328 | return 0; | 342 | return 0; |
329 | } | 343 | } |
330 | 344 | ||
331 | static void microcode_update_cpu(int cpu) | 345 | static long microcode_update_cpu(void *unused) |
332 | { | 346 | { |
333 | struct ucode_cpu_info *uci = ucode_cpu_info + cpu; | 347 | struct ucode_cpu_info *uci = ucode_cpu_info + smp_processor_id(); |
334 | int err = 0; | 348 | int err = 0; |
335 | 349 | ||
336 | /* | 350 | /* |
@@ -338,30 +352,27 @@ static void microcode_update_cpu(int cpu) | |||
338 | * otherwise just request a firmware: | 352 | * otherwise just request a firmware: |
339 | */ | 353 | */ |
340 | if (uci->valid) { | 354 | if (uci->valid) { |
341 | err = microcode_resume_cpu(cpu); | 355 | err = microcode_resume_cpu(smp_processor_id()); |
342 | } else { | 356 | } else { |
343 | collect_cpu_info(cpu); | 357 | collect_cpu_info(smp_processor_id()); |
344 | if (uci->valid && system_state == SYSTEM_RUNNING) | 358 | if (uci->valid && system_state == SYSTEM_RUNNING) |
345 | err = microcode_ops->request_microcode_fw(cpu, | 359 | err = microcode_ops->request_microcode_fw( |
360 | smp_processor_id(), | ||
346 | µcode_pdev->dev); | 361 | µcode_pdev->dev); |
347 | } | 362 | } |
348 | if (!err) | 363 | if (!err) |
349 | microcode_ops->apply_microcode(cpu); | 364 | microcode_ops->apply_microcode(smp_processor_id()); |
365 | return err; | ||
350 | } | 366 | } |
351 | 367 | ||
352 | static void microcode_init_cpu(int cpu) | 368 | static int microcode_init_cpu(int cpu) |
353 | { | 369 | { |
354 | cpumask_t old = current->cpus_allowed; | 370 | int err; |
355 | |||
356 | set_cpus_allowed_ptr(current, &cpumask_of_cpu(cpu)); | ||
357 | /* We should bind the task to the CPU */ | ||
358 | BUG_ON(raw_smp_processor_id() != cpu); | ||
359 | |||
360 | mutex_lock(µcode_mutex); | 371 | mutex_lock(µcode_mutex); |
361 | microcode_update_cpu(cpu); | 372 | err = work_on_cpu(cpu, microcode_update_cpu, NULL); |
362 | mutex_unlock(µcode_mutex); | 373 | mutex_unlock(µcode_mutex); |
363 | 374 | ||
364 | set_cpus_allowed_ptr(current, &old); | 375 | return err; |
365 | } | 376 | } |
366 | 377 | ||
367 | static int mc_sysdev_add(struct sys_device *sys_dev) | 378 | static int mc_sysdev_add(struct sys_device *sys_dev) |
@@ -379,8 +390,11 @@ static int mc_sysdev_add(struct sys_device *sys_dev) | |||
379 | if (err) | 390 | if (err) |
380 | return err; | 391 | return err; |
381 | 392 | ||
382 | microcode_init_cpu(cpu); | 393 | err = microcode_init_cpu(cpu); |
383 | return 0; | 394 | if (err) |
395 | sysfs_remove_group(&sys_dev->kobj, &mc_attr_group); | ||
396 | |||
397 | return err; | ||
384 | } | 398 | } |
385 | 399 | ||
386 | static int mc_sysdev_remove(struct sys_device *sys_dev) | 400 | static int mc_sysdev_remove(struct sys_device *sys_dev) |
@@ -404,14 +418,14 @@ static int mc_sysdev_resume(struct sys_device *dev) | |||
404 | return 0; | 418 | return 0; |
405 | 419 | ||
406 | /* only CPU 0 will apply ucode here */ | 420 | /* only CPU 0 will apply ucode here */ |
407 | microcode_update_cpu(0); | 421 | microcode_update_cpu(NULL); |
408 | return 0; | 422 | return 0; |
409 | } | 423 | } |
410 | 424 | ||
411 | static struct sysdev_driver mc_sysdev_driver = { | 425 | static struct sysdev_driver mc_sysdev_driver = { |
412 | .add = mc_sysdev_add, | 426 | .add = mc_sysdev_add, |
413 | .remove = mc_sysdev_remove, | 427 | .remove = mc_sysdev_remove, |
414 | .resume = mc_sysdev_resume, | 428 | .resume = mc_sysdev_resume, |
415 | }; | 429 | }; |
416 | 430 | ||
417 | static __cpuinit int | 431 | static __cpuinit int |
@@ -424,7 +438,9 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu) | |||
424 | switch (action) { | 438 | switch (action) { |
425 | case CPU_ONLINE: | 439 | case CPU_ONLINE: |
426 | case CPU_ONLINE_FROZEN: | 440 | case CPU_ONLINE_FROZEN: |
427 | microcode_init_cpu(cpu); | 441 | if (microcode_init_cpu(cpu)) |
442 | printk(KERN_ERR "microcode: failed to init CPU%d\n", | ||
443 | cpu); | ||
428 | case CPU_DOWN_FAILED: | 444 | case CPU_DOWN_FAILED: |
429 | case CPU_DOWN_FAILED_FROZEN: | 445 | case CPU_DOWN_FAILED_FROZEN: |
430 | pr_debug("microcode: CPU%d added\n", cpu); | 446 | pr_debug("microcode: CPU%d added\n", cpu); |
@@ -448,7 +464,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu) | |||
448 | } | 464 | } |
449 | 465 | ||
450 | static struct notifier_block __refdata mc_cpu_notifier = { | 466 | static struct notifier_block __refdata mc_cpu_notifier = { |
451 | .notifier_call = mc_cpu_callback, | 467 | .notifier_call = mc_cpu_callback, |
452 | }; | 468 | }; |
453 | 469 | ||
454 | static int __init microcode_init(void) | 470 | static int __init microcode_init(void) |