blob: c7f225c7e481e78d96fc70b6259040570087da5e [file] [log] [blame]
Peter Oruba80cc9f12008-07-28 18:44:22 +02001/*
2 * AMD CPU Microcode Update Driver for Linux
3 * Copyright (C) 2008 Advanced Micro Devices Inc.
4 *
5 * Author: Peter Oruba <peter.oruba@amd.com>
6 *
7 * Based on work by:
8 * Tigran Aivazian <tigran@aivazian.fsnet.co.uk>
9 *
10 * This driver allows to upgrade microcode on AMD
11 * family 0x10 and 0x11 processors.
12 *
Andreas Herrmann2a3282a72008-12-16 19:08:53 +010013 * Licensed under the terms of the GNU General Public
Peter Oruba80cc9f12008-07-28 18:44:22 +020014 * License version 2. See file COPYING for details.
15*/
16
17#include <linux/capability.h>
18#include <linux/kernel.h>
19#include <linux/init.h>
20#include <linux/sched.h>
21#include <linux/cpumask.h>
22#include <linux/module.h>
23#include <linux/slab.h>
24#include <linux/vmalloc.h>
25#include <linux/miscdevice.h>
26#include <linux/spinlock.h>
27#include <linux/mm.h>
28#include <linux/fs.h>
29#include <linux/mutex.h>
30#include <linux/cpu.h>
31#include <linux/firmware.h>
32#include <linux/platform_device.h>
33#include <linux/pci.h>
34#include <linux/pci_ids.h>
Andreas Herrmannbe957762008-12-16 19:11:23 +010035#include <linux/uaccess.h>
Peter Oruba80cc9f12008-07-28 18:44:22 +020036
37#include <asm/msr.h>
Peter Oruba80cc9f12008-07-28 18:44:22 +020038#include <asm/processor.h>
39#include <asm/microcode.h>
40
41MODULE_DESCRIPTION("AMD Microcode Update Driver");
Peter Oruba3c522042008-10-17 15:30:38 +020042MODULE_AUTHOR("Peter Oruba");
Ingo Molnar5d7b6052008-07-29 10:07:36 +020043MODULE_LICENSE("GPL v2");
Peter Oruba80cc9f12008-07-28 18:44:22 +020044
45#define UCODE_MAGIC 0x00414d44
46#define UCODE_EQUIV_CPU_TABLE_TYPE 0x00000000
47#define UCODE_UCODE_TYPE 0x00000001
48
Dmitry Adamushko18dbc912008-09-23 12:08:44 +020049struct equiv_cpu_entry {
50 unsigned int installed_cpu;
51 unsigned int fixed_errata_mask;
52 unsigned int fixed_errata_compare;
53 unsigned int equiv_cpu;
54};
55
56struct microcode_header_amd {
57 unsigned int data_code;
58 unsigned int patch_id;
59 unsigned char mc_patch_data_id[2];
60 unsigned char mc_patch_data_len;
61 unsigned char init_flag;
62 unsigned int mc_patch_data_checksum;
63 unsigned int nb_dev_id;
64 unsigned int sb_dev_id;
Andreas Herrmann3c763fd2008-12-16 19:07:47 +010065 u16 processor_rev_id;
Dmitry Adamushko18dbc912008-09-23 12:08:44 +020066 unsigned char nb_rev_id;
67 unsigned char sb_rev_id;
68 unsigned char bios_api_rev;
69 unsigned char reserved1[3];
70 unsigned int match_reg[8];
71};
72
73struct microcode_amd {
74 struct microcode_header_amd hdr;
75 unsigned int mpb[0];
76};
77
Peter Oruba80cc9f12008-07-28 18:44:22 +020078#define UCODE_MAX_SIZE (2048)
Peter Orubaa0ac87d2008-07-29 17:41:04 +020079#define DEFAULT_UCODE_DATASIZE (896)
80#define MC_HEADER_SIZE (sizeof(struct microcode_header_amd))
81#define DEFAULT_UCODE_TOTALSIZE (DEFAULT_UCODE_DATASIZE + MC_HEADER_SIZE)
Peter Oruba80cc9f12008-07-28 18:44:22 +020082#define DWSIZE (sizeof(u32))
83/* For now we support a fixed ucode total size only */
84#define get_totalsize(mc) \
85 ((((struct microcode_amd *)mc)->hdr.mc_patch_data_len * 28) \
86 + MC_HEADER_SIZE)
87
Peter Oruba80cc9f12008-07-28 18:44:22 +020088/* serialize access to the physical write */
89static DEFINE_SPINLOCK(microcode_update_lock);
90
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +020091static struct equiv_cpu_entry *equiv_cpu_table;
Peter Oruba80cc9f12008-07-28 18:44:22 +020092
Dmitry Adamushkod45de402008-08-20 00:22:26 +020093static int collect_cpu_info_amd(int cpu, struct cpu_signature *csig)
Peter Oruba80cc9f12008-07-28 18:44:22 +020094{
95 struct cpuinfo_x86 *c = &cpu_data(cpu);
Peter Oruba80cc9f12008-07-28 18:44:22 +020096
Dmitry Adamushkod45de402008-08-20 00:22:26 +020097 memset(csig, 0, sizeof(*csig));
Peter Oruba80cc9f12008-07-28 18:44:22 +020098
99 if (c->x86_vendor != X86_VENDOR_AMD || c->x86 < 0x10) {
100 printk(KERN_ERR "microcode: CPU%d not a capable AMD processor\n",
101 cpu);
Dmitry Adamushkod45de402008-08-20 00:22:26 +0200102 return -1;
Peter Oruba80cc9f12008-07-28 18:44:22 +0200103 }
104
105 asm volatile("movl %1, %%ecx; rdmsr"
Dmitry Adamushkod45de402008-08-20 00:22:26 +0200106 : "=a" (csig->rev)
Peter Oruba80cc9f12008-07-28 18:44:22 +0200107 : "i" (0x0000008B) : "ecx");
108
109 printk(KERN_INFO "microcode: collect_cpu_info_amd : patch_id=0x%x\n",
Dmitry Adamushkod45de402008-08-20 00:22:26 +0200110 csig->rev);
111
112 return 0;
Peter Oruba80cc9f12008-07-28 18:44:22 +0200113}
114
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200115static int get_matching_microcode(int cpu, void *mc, int rev)
Peter Oruba80cc9f12008-07-28 18:44:22 +0200116{
Peter Oruba80cc9f12008-07-28 18:44:22 +0200117 struct microcode_header_amd *mc_header = mc;
Peter Oruba80cc9f12008-07-28 18:44:22 +0200118 struct pci_dev *nb_pci_dev, *sb_pci_dev;
119 unsigned int current_cpu_id;
120 unsigned int equiv_cpu_id = 0x00;
121 unsigned int i = 0;
122
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200123 BUG_ON(equiv_cpu_table == NULL);
Peter Oruba80cc9f12008-07-28 18:44:22 +0200124 current_cpu_id = cpuid_eax(0x00000001);
125
126 while (equiv_cpu_table[i].installed_cpu != 0) {
127 if (current_cpu_id == equiv_cpu_table[i].installed_cpu) {
Andreas Herrmann3c763fd2008-12-16 19:07:47 +0100128 equiv_cpu_id = equiv_cpu_table[i].equiv_cpu & 0xffff;
Peter Oruba80cc9f12008-07-28 18:44:22 +0200129 break;
130 }
131 i++;
132 }
133
134 if (!equiv_cpu_id) {
135 printk(KERN_ERR "microcode: CPU%d cpu_id "
Andreas Herrmann2a3282a72008-12-16 19:08:53 +0100136 "not found in equivalent cpu table\n", cpu);
Peter Oruba80cc9f12008-07-28 18:44:22 +0200137 return 0;
138 }
139
Andreas Herrmann3c763fd2008-12-16 19:07:47 +0100140 if (mc_header->processor_rev_id != equiv_cpu_id) {
141 printk(KERN_ERR "microcode: CPU%d patch does not match "
142 "(processor_rev_id: %x, eqiv_cpu_id: %x)\n",
143 cpu, mc_header->processor_rev_id, equiv_cpu_id);
Peter Oruba80cc9f12008-07-28 18:44:22 +0200144 return 0;
145 }
146
147 /* ucode may be northbridge specific */
148 if (mc_header->nb_dev_id) {
149 nb_pci_dev = pci_get_device(PCI_VENDOR_ID_AMD,
150 (mc_header->nb_dev_id & 0xff),
151 NULL);
152 if ((!nb_pci_dev) ||
153 (mc_header->nb_rev_id != nb_pci_dev->revision)) {
Andreas Herrmann2a3282a72008-12-16 19:08:53 +0100154 printk(KERN_ERR "microcode: CPU%d NB mismatch\n", cpu);
Peter Oruba80cc9f12008-07-28 18:44:22 +0200155 pci_dev_put(nb_pci_dev);
156 return 0;
157 }
158 pci_dev_put(nb_pci_dev);
159 }
160
161 /* ucode may be southbridge specific */
162 if (mc_header->sb_dev_id) {
163 sb_pci_dev = pci_get_device(PCI_VENDOR_ID_AMD,
164 (mc_header->sb_dev_id & 0xff),
165 NULL);
166 if ((!sb_pci_dev) ||
167 (mc_header->sb_rev_id != sb_pci_dev->revision)) {
Andreas Herrmann2a3282a72008-12-16 19:08:53 +0100168 printk(KERN_ERR "microcode: CPU%d SB mismatch\n", cpu);
Peter Oruba80cc9f12008-07-28 18:44:22 +0200169 pci_dev_put(sb_pci_dev);
170 return 0;
171 }
172 pci_dev_put(sb_pci_dev);
173 }
174
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200175 if (mc_header->patch_id <= rev)
Peter Oruba80cc9f12008-07-28 18:44:22 +0200176 return 0;
177
Peter Oruba80cc9f12008-07-28 18:44:22 +0200178 return 1;
179}
180
181static void apply_microcode_amd(int cpu)
182{
183 unsigned long flags;
184 unsigned int eax, edx;
185 unsigned int rev;
186 int cpu_num = raw_smp_processor_id();
187 struct ucode_cpu_info *uci = ucode_cpu_info + cpu_num;
Dmitry Adamushko18dbc912008-09-23 12:08:44 +0200188 struct microcode_amd *mc_amd = uci->mc;
Randy Dunlap5b792d32008-08-21 13:43:51 -0700189 unsigned long addr;
Peter Oruba80cc9f12008-07-28 18:44:22 +0200190
191 /* We should bind the task to the CPU */
192 BUG_ON(cpu_num != cpu);
193
Dmitry Adamushko18dbc912008-09-23 12:08:44 +0200194 if (mc_amd == NULL)
Peter Oruba80cc9f12008-07-28 18:44:22 +0200195 return;
196
197 spin_lock_irqsave(&microcode_update_lock, flags);
198
Dmitry Adamushko18dbc912008-09-23 12:08:44 +0200199 addr = (unsigned long)&mc_amd->hdr.data_code;
Randy Dunlap5b792d32008-08-21 13:43:51 -0700200 edx = (unsigned int)(((unsigned long)upper_32_bits(addr)));
201 eax = (unsigned int)(((unsigned long)lower_32_bits(addr)));
Peter Oruba80cc9f12008-07-28 18:44:22 +0200202
203 asm volatile("movl %0, %%ecx; wrmsr" :
204 : "i" (0xc0010020), "a" (eax), "d" (edx) : "ecx");
205
206 /* get patch id after patching */
207 asm volatile("movl %1, %%ecx; rdmsr"
208 : "=a" (rev)
209 : "i" (0x0000008B) : "ecx");
210
211 spin_unlock_irqrestore(&microcode_update_lock, flags);
212
213 /* check current patch id and patch's id for match */
Dmitry Adamushko18dbc912008-09-23 12:08:44 +0200214 if (rev != mc_amd->hdr.patch_id) {
Peter Oruba80cc9f12008-07-28 18:44:22 +0200215 printk(KERN_ERR "microcode: CPU%d update from revision "
216 "0x%x to 0x%x failed\n", cpu_num,
Dmitry Adamushko18dbc912008-09-23 12:08:44 +0200217 mc_amd->hdr.patch_id, rev);
Peter Oruba80cc9f12008-07-28 18:44:22 +0200218 return;
219 }
220
221 printk(KERN_INFO "microcode: CPU%d updated from revision "
Andreas Herrmann2a3282a72008-12-16 19:08:53 +0100222 "0x%x to 0x%x\n",
Dmitry Adamushko18dbc912008-09-23 12:08:44 +0200223 cpu_num, uci->cpu_sig.rev, mc_amd->hdr.patch_id);
Peter Oruba80cc9f12008-07-28 18:44:22 +0200224
Dmitry Adamushkod45de402008-08-20 00:22:26 +0200225 uci->cpu_sig.rev = rev;
Peter Oruba80cc9f12008-07-28 18:44:22 +0200226}
227
Andreas Herrmann0657d9e2008-12-16 19:14:05 +0100228static int get_ucode_data(void *to, const u8 *from, size_t n)
229{
230 memcpy(to, from, n);
231 return 0;
232}
233
Andreas Herrmann8c135202008-12-16 19:13:00 +0100234static void *get_next_ucode(const u8 *buf, unsigned int size,
Andreas Herrmann0657d9e2008-12-16 19:14:05 +0100235 unsigned int *mc_size)
Peter Oruba80cc9f12008-07-28 18:44:22 +0200236{
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200237 unsigned int total_size;
Peter Orubad4738792008-09-17 15:39:18 +0200238#define UCODE_CONTAINER_SECTION_HDR 8
239 u8 section_hdr[UCODE_CONTAINER_SECTION_HDR];
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200240 void *mc;
Peter Oruba80cc9f12008-07-28 18:44:22 +0200241
Peter Orubad4738792008-09-17 15:39:18 +0200242 if (get_ucode_data(section_hdr, buf, UCODE_CONTAINER_SECTION_HDR))
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200243 return NULL;
Peter Oruba80cc9f12008-07-28 18:44:22 +0200244
Peter Orubad4738792008-09-17 15:39:18 +0200245 if (section_hdr[0] != UCODE_UCODE_TYPE) {
Peter Oruba80cc9f12008-07-28 18:44:22 +0200246 printk(KERN_ERR "microcode: error! "
247 "Wrong microcode payload type field\n");
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200248 return NULL;
Peter Oruba80cc9f12008-07-28 18:44:22 +0200249 }
250
Peter Orubad4738792008-09-17 15:39:18 +0200251 total_size = (unsigned long) (section_hdr[4] + (section_hdr[5] << 8));
Peter Oruba80cc9f12008-07-28 18:44:22 +0200252
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200253 printk(KERN_INFO "microcode: size %u, total_size %u\n",
254 size, total_size);
Peter Oruba80cc9f12008-07-28 18:44:22 +0200255
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200256 if (total_size > size || total_size > UCODE_MAX_SIZE) {
Peter Oruba80cc9f12008-07-28 18:44:22 +0200257 printk(KERN_ERR "microcode: error! Bad data in microcode data file\n");
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200258 return NULL;
Peter Oruba80cc9f12008-07-28 18:44:22 +0200259 }
260
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200261 mc = vmalloc(UCODE_MAX_SIZE);
262 if (mc) {
263 memset(mc, 0, UCODE_MAX_SIZE);
Andreas Herrmannbe957762008-12-16 19:11:23 +0100264 if (get_ucode_data(mc, buf + UCODE_CONTAINER_SECTION_HDR,
265 total_size)) {
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200266 vfree(mc);
267 mc = NULL;
268 } else
Peter Orubad4738792008-09-17 15:39:18 +0200269 *mc_size = total_size + UCODE_CONTAINER_SECTION_HDR;
Peter Oruba80cc9f12008-07-28 18:44:22 +0200270 }
Peter Orubad4738792008-09-17 15:39:18 +0200271#undef UCODE_CONTAINER_SECTION_HDR
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200272 return mc;
Peter Oruba80cc9f12008-07-28 18:44:22 +0200273}
274
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200275
Andreas Herrmann0657d9e2008-12-16 19:14:05 +0100276static int install_equiv_cpu_table(const u8 *buf)
Peter Oruba80cc9f12008-07-28 18:44:22 +0200277{
Peter Orubab6cffde2008-09-17 15:05:52 +0200278#define UCODE_CONTAINER_HEADER_SIZE 12
279 u8 *container_hdr[UCODE_CONTAINER_HEADER_SIZE];
280 unsigned int *buf_pos = (unsigned int *)container_hdr;
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200281 unsigned long size;
Peter Oruba80cc9f12008-07-28 18:44:22 +0200282
Peter Orubab6cffde2008-09-17 15:05:52 +0200283 if (get_ucode_data(&container_hdr, buf, UCODE_CONTAINER_HEADER_SIZE))
Peter Oruba80cc9f12008-07-28 18:44:22 +0200284 return 0;
285
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200286 size = buf_pos[2];
Peter Oruba80cc9f12008-07-28 18:44:22 +0200287
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200288 if (buf_pos[1] != UCODE_EQUIV_CPU_TABLE_TYPE || !size) {
Peter Oruba80cc9f12008-07-28 18:44:22 +0200289 printk(KERN_ERR "microcode: error! "
Andreas Herrmann2a3282a72008-12-16 19:08:53 +0100290 "Wrong microcode equivalent cpu table\n");
Peter Oruba80cc9f12008-07-28 18:44:22 +0200291 return 0;
292 }
293
294 equiv_cpu_table = (struct equiv_cpu_entry *) vmalloc(size);
295 if (!equiv_cpu_table) {
296 printk(KERN_ERR "microcode: error, can't allocate memory for equiv CPU table\n");
297 return 0;
298 }
299
Peter Orubab6cffde2008-09-17 15:05:52 +0200300 buf += UCODE_CONTAINER_HEADER_SIZE;
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200301 if (get_ucode_data(equiv_cpu_table, buf, size)) {
302 vfree(equiv_cpu_table);
303 return 0;
304 }
Peter Oruba80cc9f12008-07-28 18:44:22 +0200305
Peter Orubab6cffde2008-09-17 15:05:52 +0200306 return size + UCODE_CONTAINER_HEADER_SIZE; /* add header length */
307#undef UCODE_CONTAINER_HEADER_SIZE
Peter Oruba80cc9f12008-07-28 18:44:22 +0200308}
309
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200310static void free_equiv_cpu_table(void)
Peter Oruba80cc9f12008-07-28 18:44:22 +0200311{
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200312 if (equiv_cpu_table) {
313 vfree(equiv_cpu_table);
314 equiv_cpu_table = NULL;
Peter Oruba80cc9f12008-07-28 18:44:22 +0200315 }
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200316}
Peter Oruba80cc9f12008-07-28 18:44:22 +0200317
Andreas Herrmann0657d9e2008-12-16 19:14:05 +0100318static int generic_load_microcode(int cpu, const u8 *data, size_t size)
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200319{
320 struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
Andreas Herrmann8c135202008-12-16 19:13:00 +0100321 const u8 *ucode_ptr = data;
322 void *new_mc = NULL;
323 void *mc;
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200324 int new_rev = uci->cpu_sig.rev;
325 unsigned int leftover;
326 unsigned long offset;
Peter Oruba80cc9f12008-07-28 18:44:22 +0200327
Andreas Herrmann0657d9e2008-12-16 19:14:05 +0100328 offset = install_equiv_cpu_table(ucode_ptr);
Peter Oruba80cc9f12008-07-28 18:44:22 +0200329 if (!offset) {
330 printk(KERN_ERR "microcode: installing equivalent cpu table failed\n");
331 return -EINVAL;
332 }
333
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200334 ucode_ptr += offset;
335 leftover = size - offset;
336
337 while (leftover) {
Dmitry Adamushko2f9284e2008-09-23 22:56:35 +0200338 unsigned int uninitialized_var(mc_size);
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200339 struct microcode_header_amd *mc_header;
340
Andreas Herrmann0657d9e2008-12-16 19:14:05 +0100341 mc = get_next_ucode(ucode_ptr, leftover, &mc_size);
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200342 if (!mc)
Peter Oruba80cc9f12008-07-28 18:44:22 +0200343 break;
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200344
345 mc_header = (struct microcode_header_amd *)mc;
346 if (get_matching_microcode(cpu, mc, new_rev)) {
Ingo Molnara1c75cc2008-09-14 14:50:26 +0200347 if (new_mc)
348 vfree(new_mc);
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200349 new_rev = mc_header->patch_id;
350 new_mc = mc;
Andreas Herrmannbe957762008-12-16 19:11:23 +0100351 } else
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200352 vfree(mc);
353
354 ucode_ptr += mc_size;
355 leftover -= mc_size;
Peter Oruba80cc9f12008-07-28 18:44:22 +0200356 }
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200357
358 if (new_mc) {
359 if (!leftover) {
Dmitry Adamushko18dbc912008-09-23 12:08:44 +0200360 if (uci->mc)
361 vfree(uci->mc);
362 uci->mc = new_mc;
Andreas Herrmannbe957762008-12-16 19:11:23 +0100363 pr_debug("microcode: CPU%d found a matching microcode "
364 "update with version 0x%x (current=0x%x)\n",
365 cpu, new_rev, uci->cpu_sig.rev);
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200366 } else
367 vfree(new_mc);
Peter Oruba80cc9f12008-07-28 18:44:22 +0200368 }
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200369
370 free_equiv_cpu_table();
371
372 return (int)leftover;
373}
374
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200375static int request_microcode_fw(int cpu, struct device *device)
376{
377 const char *fw_name = "amd-ucode/microcode_amd.bin";
378 const struct firmware *firmware;
379 int ret;
380
381 /* We should bind the task to the CPU */
382 BUG_ON(cpu != raw_smp_processor_id());
383
384 ret = request_firmware(&firmware, fw_name, device);
385 if (ret) {
Andreas Herrmannbe957762008-12-16 19:11:23 +0100386 printk(KERN_ERR "microcode: ucode data file %s load failed\n",
387 fw_name);
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200388 return ret;
389 }
390
Andreas Herrmann0657d9e2008-12-16 19:14:05 +0100391 ret = generic_load_microcode(cpu, firmware->data, firmware->size);
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200392
Peter Oruba80cc9f12008-07-28 18:44:22 +0200393 release_firmware(firmware);
394
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200395 return ret;
396}
397
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200398static int request_microcode_user(int cpu, const void __user *buf, size_t size)
399{
Andreas Herrmannbe957762008-12-16 19:11:23 +0100400 printk(KERN_WARNING "microcode: AMD microcode update via "
401 "/dev/cpu/microcode is not supported\n");
Dmitry Adamushko2f9284e2008-09-23 22:56:35 +0200402 return -1;
Peter Oruba80cc9f12008-07-28 18:44:22 +0200403}
404
Peter Oruba80cc9f12008-07-28 18:44:22 +0200405static void microcode_fini_cpu_amd(int cpu)
406{
407 struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
408
Dmitry Adamushko18dbc912008-09-23 12:08:44 +0200409 vfree(uci->mc);
410 uci->mc = NULL;
Peter Oruba80cc9f12008-07-28 18:44:22 +0200411}
412
413static struct microcode_ops microcode_amd_ops = {
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200414 .request_microcode_user = request_microcode_user,
415 .request_microcode_fw = request_microcode_fw,
Peter Oruba80cc9f12008-07-28 18:44:22 +0200416 .collect_cpu_info = collect_cpu_info_amd,
417 .apply_microcode = apply_microcode_amd,
418 .microcode_fini_cpu = microcode_fini_cpu_amd,
419};
420
Dmitry Adamushko18dbc912008-09-23 12:08:44 +0200421struct microcode_ops * __init init_amd_microcode(void)
Peter Oruba80cc9f12008-07-28 18:44:22 +0200422{
Dmitry Adamushko18dbc912008-09-23 12:08:44 +0200423 return &microcode_amd_ops;
Peter Oruba80cc9f12008-07-28 18:44:22 +0200424}