ia64/xen-unstable

view xen/arch/x86/microcode.c @ 19848:5839491bbf20

[IA64] replace MAX_VCPUS with d->max_vcpus where necessary.

don't use MAX_VCPUS, and use vcpu::max_vcpus.
The changeset of 2f9e1348aa98 introduced max_vcpus to allow more vcpus
per guest. This patch is ia64 counter part.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
author Isaku Yamahata <yamahata@valinux.co.jp>
date Mon Jun 29 11:26:05 2009 +0900 (2009-06-29)
parents 9f9ba1a7cc92
children
line source
1 /*
2 * Intel CPU Microcode Update Driver for Linux
3 *
4 * Copyright (C) 2000-2006 Tigran Aivazian <tigran@aivazian.fsnet.co.uk>
5 * 2006 Shaohua Li <shaohua.li@intel.com> *
6 * This driver allows to upgrade microcode on Intel processors
7 * belonging to IA-32 family - PentiumPro, Pentium II,
8 * Pentium III, Xeon, Pentium 4, etc.
9 *
10 * Reference: Section 8.11 of Volume 3a, IA-32 Intel? Architecture
11 * Software Developer's Manual
12 * Order Number 253668 or free download from:
13 *
14 * http://developer.intel.com/design/pentium4/manuals/253668.htm
15 *
16 * For more information, go to http://www.urbanmyth.org/microcode
17 *
18 * This program is free software; you can redistribute it and/or
19 * modify it under the terms of the GNU General Public License
20 * as published by the Free Software Foundation; either version
21 * 2 of the License, or (at your option) any later version.
22 */
24 #include <xen/config.h>
25 #include <xen/lib.h>
26 #include <xen/kernel.h>
27 #include <xen/init.h>
28 #include <xen/sched.h>
29 #include <xen/smp.h>
30 #include <xen/spinlock.h>
31 #include <xen/guest_access.h>
33 #include <asm/current.h>
34 #include <asm/msr.h>
35 #include <asm/uaccess.h>
36 #include <asm/processor.h>
37 #include <asm/microcode.h>
39 const struct microcode_ops *microcode_ops;
41 static DEFINE_SPINLOCK(microcode_mutex);
43 struct ucode_cpu_info ucode_cpu_info[NR_CPUS];
45 struct microcode_info {
46 unsigned int cpu;
47 uint32_t buffer_size;
48 int error;
49 char buffer[1];
50 };
52 static void __microcode_fini_cpu(int cpu)
53 {
54 struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
56 xfree(uci->mc.mc_valid);
57 memset(uci, 0, sizeof(*uci));
58 }
60 static void microcode_fini_cpu(int cpu)
61 {
62 spin_lock(&microcode_mutex);
63 __microcode_fini_cpu(cpu);
64 spin_unlock(&microcode_mutex);
65 }
67 int microcode_resume_cpu(int cpu)
68 {
69 int err = 0;
70 struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
71 struct cpu_signature nsig;
73 gdprintk(XENLOG_INFO, "microcode: CPU%d resumed\n", cpu);
75 if ( !uci->mc.mc_valid )
76 return -EIO;
78 /*
79 * Let's verify that the 'cached' ucode does belong
80 * to this cpu (a bit of paranoia):
81 */
82 err = microcode_ops->collect_cpu_info(cpu, &nsig);
83 if ( err )
84 {
85 microcode_fini_cpu(cpu);
86 return err;
87 }
89 if ( microcode_ops->microcode_resume_match(cpu, &nsig) )
90 {
91 return microcode_ops->apply_microcode(cpu);
92 }
93 else
94 {
95 microcode_fini_cpu(cpu);
96 return -EIO;
97 }
98 }
100 static int microcode_update_cpu(const void *buf, size_t size)
101 {
102 int err;
103 unsigned int cpu = smp_processor_id();
104 struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
106 spin_lock(&microcode_mutex);
108 err = microcode_ops->collect_cpu_info(cpu, &uci->cpu_sig);
109 if ( likely(!err) )
110 err = microcode_ops->cpu_request_microcode(cpu, buf, size);
111 else
112 __microcode_fini_cpu(cpu);
114 spin_unlock(&microcode_mutex);
116 return err;
117 }
119 static long do_microcode_update(void *_info)
120 {
121 struct microcode_info *info = _info;
122 int error;
124 BUG_ON(info->cpu != smp_processor_id());
126 error = microcode_update_cpu(info->buffer, info->buffer_size);
127 if ( error )
128 info->error = error;
130 info->cpu = next_cpu(info->cpu, cpu_online_map);
131 if ( info->cpu < NR_CPUS )
132 return continue_hypercall_on_cpu(info->cpu, do_microcode_update, info);
134 error = info->error;
135 xfree(info);
136 return error;
137 }
139 int microcode_update(XEN_GUEST_HANDLE(const_void) buf, unsigned long len)
140 {
141 int ret;
142 struct microcode_info *info;
144 if ( len != (uint32_t)len )
145 return -E2BIG;
147 if ( microcode_ops == NULL )
148 return -EINVAL;
150 info = xmalloc_bytes(sizeof(*info) + len);
151 if ( info == NULL )
152 return -ENOMEM;
154 ret = copy_from_guest(info->buffer, buf, len);
155 if ( ret != 0 )
156 {
157 xfree(info);
158 return ret;
159 }
161 info->buffer_size = len;
162 info->error = 0;
163 info->cpu = first_cpu(cpu_online_map);
165 return continue_hypercall_on_cpu(info->cpu, do_microcode_update, info);
166 }