blob: efdec7cd8e01057aeee63c95b16713c4803c7e61 [file] [log] [blame]
Peter Oruba80cc9f12008-07-28 18:44:22 +02001/*
2 * AMD CPU Microcode Update Driver for Linux
Borislav Petkov597e11a2011-12-02 18:09:23 +01003 * Copyright (C) 2008-2011 Advanced Micro Devices Inc.
Peter Oruba80cc9f12008-07-28 18:44:22 +02004 *
5 * Author: Peter Oruba <peter.oruba@amd.com>
6 *
7 * Based on work by:
8 * Tigran Aivazian <tigran@aivazian.fsnet.co.uk>
9 *
Borislav Petkov597e11a2011-12-02 18:09:23 +010010 * Maintainers:
Andreas Herrmann943482d2012-10-29 18:51:38 +010011 * Andreas Herrmann <herrmann.der.user@googlemail.com>
12 * Borislav Petkov <bp@alien8.de>
Borislav Petkov597e11a2011-12-02 18:09:23 +010013 *
14 * This driver allows to upgrade microcode on F10h AMD
15 * CPUs and later.
Peter Oruba80cc9f12008-07-28 18:44:22 +020016 *
Andreas Herrmann2a3282a72008-12-16 19:08:53 +010017 * Licensed under the terms of the GNU General Public
Peter Oruba80cc9f12008-07-28 18:44:22 +020018 * License version 2. See file COPYING for details.
Ingo Molnar4bae1962009-03-11 11:19:46 +010019 */
Joe Perchesf58e1f52009-12-08 22:30:50 -080020
21#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
22
Ingo Molnar4bae1962009-03-11 11:19:46 +010023#include <linux/firmware.h>
Peter Oruba80cc9f12008-07-28 18:44:22 +020024#include <linux/pci_ids.h>
Andreas Herrmannbe957762008-12-16 19:11:23 +010025#include <linux/uaccess.h>
Ingo Molnar4bae1962009-03-11 11:19:46 +010026#include <linux/vmalloc.h>
27#include <linux/kernel.h>
28#include <linux/module.h>
Ingo Molnar4bae1962009-03-11 11:19:46 +010029#include <linux/pci.h>
Peter Oruba80cc9f12008-07-28 18:44:22 +020030
Peter Oruba80cc9f12008-07-28 18:44:22 +020031#include <asm/microcode.h>
Ingo Molnar4bae1962009-03-11 11:19:46 +010032#include <asm/processor.h>
33#include <asm/msr.h>
Peter Oruba80cc9f12008-07-28 18:44:22 +020034
35MODULE_DESCRIPTION("AMD Microcode Update Driver");
Peter Oruba3c522042008-10-17 15:30:38 +020036MODULE_AUTHOR("Peter Oruba");
Ingo Molnar5d7b6052008-07-29 10:07:36 +020037MODULE_LICENSE("GPL v2");
Peter Oruba80cc9f12008-07-28 18:44:22 +020038
39#define UCODE_MAGIC 0x00414d44
40#define UCODE_EQUIV_CPU_TABLE_TYPE 0x00000000
41#define UCODE_UCODE_TYPE 0x00000001
42
Dmitry Adamushko18dbc912008-09-23 12:08:44 +020043struct equiv_cpu_entry {
Andreas Herrmann5549b942008-12-16 19:21:30 +010044 u32 installed_cpu;
45 u32 fixed_errata_mask;
46 u32 fixed_errata_compare;
47 u16 equiv_cpu;
48 u16 res;
49} __attribute__((packed));
Dmitry Adamushko18dbc912008-09-23 12:08:44 +020050
51struct microcode_header_amd {
Andreas Herrmann5549b942008-12-16 19:21:30 +010052 u32 data_code;
53 u32 patch_id;
54 u16 mc_patch_data_id;
55 u8 mc_patch_data_len;
56 u8 init_flag;
57 u32 mc_patch_data_checksum;
58 u32 nb_dev_id;
59 u32 sb_dev_id;
60 u16 processor_rev_id;
61 u8 nb_rev_id;
62 u8 sb_rev_id;
63 u8 bios_api_rev;
64 u8 reserved1[3];
65 u32 match_reg[8];
66} __attribute__((packed));
Dmitry Adamushko18dbc912008-09-23 12:08:44 +020067
68struct microcode_amd {
Ingo Molnar4bae1962009-03-11 11:19:46 +010069 struct microcode_header_amd hdr;
70 unsigned int mpb[0];
Dmitry Adamushko18dbc912008-09-23 12:08:44 +020071};
72
Borislav Petkov40b7f3d2011-06-15 15:34:57 +020073#define SECTION_HDR_SIZE 8
74#define CONTAINER_HDR_SZ 12
Peter Oruba80cc9f12008-07-28 18:44:22 +020075
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +020076static struct equiv_cpu_entry *equiv_cpu_table;
Peter Oruba80cc9f12008-07-28 18:44:22 +020077
Borislav Petkova3eb3b42012-08-01 15:38:18 +020078struct ucode_patch {
79 struct list_head plist;
80 void *data;
81 u32 patch_id;
82 u16 equiv_cpu;
83};
84
85static LIST_HEAD(pcache);
86
Borislav Petkovc96d2c02012-08-01 14:55:01 +020087static u16 find_equiv_id(unsigned int cpu)
88{
89 struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
90 int i = 0;
91
Borislav Petkova3eb3b42012-08-01 15:38:18 +020092 if (!equiv_cpu_table)
93 return 0;
Borislav Petkovc96d2c02012-08-01 14:55:01 +020094
95 while (equiv_cpu_table[i].installed_cpu != 0) {
96 if (uci->cpu_sig.sig == equiv_cpu_table[i].installed_cpu)
97 return equiv_cpu_table[i].equiv_cpu;
98
99 i++;
100 }
101 return 0;
102}
103
104static u32 find_cpu_family_by_equiv_cpu(u16 equiv_cpu)
105{
106 int i = 0;
107
108 BUG_ON(!equiv_cpu_table);
109
110 while (equiv_cpu_table[i].equiv_cpu != 0) {
111 if (equiv_cpu == equiv_cpu_table[i].equiv_cpu)
112 return equiv_cpu_table[i].installed_cpu;
113 i++;
114 }
115 return 0;
116}
117
Borislav Petkova3eb3b42012-08-01 15:38:18 +0200118/*
119 * a small, trivial cache of per-family ucode patches
120 */
121static struct ucode_patch *cache_find_patch(u16 equiv_cpu)
122{
123 struct ucode_patch *p;
124
125 list_for_each_entry(p, &pcache, plist)
126 if (p->equiv_cpu == equiv_cpu)
127 return p;
128 return NULL;
129}
130
131static void update_cache(struct ucode_patch *new_patch)
132{
133 struct ucode_patch *p;
134
135 list_for_each_entry(p, &pcache, plist) {
136 if (p->equiv_cpu == new_patch->equiv_cpu) {
137 if (p->patch_id >= new_patch->patch_id)
138 /* we already have the latest patch */
139 return;
140
141 list_replace(&p->plist, &new_patch->plist);
142 kfree(p->data);
143 kfree(p);
144 return;
145 }
146 }
147 /* no patch found, add it */
148 list_add_tail(&new_patch->plist, &pcache);
149}
150
151static void free_cache(void)
152{
Dan Carpenter2d297482012-09-05 15:30:42 +0300153 struct ucode_patch *p, *tmp;
Borislav Petkova3eb3b42012-08-01 15:38:18 +0200154
Dan Carpenter2d297482012-09-05 15:30:42 +0300155 list_for_each_entry_safe(p, tmp, &pcache, plist) {
Borislav Petkova3eb3b42012-08-01 15:38:18 +0200156 __list_del(p->plist.prev, p->plist.next);
157 kfree(p->data);
158 kfree(p);
159 }
160}
161
162static struct ucode_patch *find_patch(unsigned int cpu)
163{
164 u16 equiv_id;
165
166 equiv_id = find_equiv_id(cpu);
167 if (!equiv_id)
168 return NULL;
169
170 return cache_find_patch(equiv_id);
171}
172
Dmitry Adamushkod45de402008-08-20 00:22:26 +0200173static int collect_cpu_info_amd(int cpu, struct cpu_signature *csig)
Peter Oruba80cc9f12008-07-28 18:44:22 +0200174{
Andreas Herrmann3b2e3d82010-01-22 21:34:56 +0100175 struct cpuinfo_x86 *c = &cpu_data(cpu);
Peter Oruba80cc9f12008-07-28 18:44:22 +0200176
Borislav Petkov5f5b7472012-07-25 20:06:54 +0200177 csig->sig = cpuid_eax(0x00000001);
Borislav Petkovbcb80e52011-10-17 16:34:36 +0200178 csig->rev = c->microcode;
Borislav Petkov258721e2011-01-05 18:13:19 +0100179 pr_info("CPU%d: patch_level=0x%08x\n", cpu, csig->rev);
180
Dmitry Adamushkod45de402008-08-20 00:22:26 +0200181 return 0;
Peter Oruba80cc9f12008-07-28 18:44:22 +0200182}
183
Borislav Petkov2efb05e2012-08-01 16:16:13 +0200184static unsigned int verify_patch_size(int cpu, u32 patch_size,
Borislav Petkovbe62adb2011-12-02 18:02:17 +0100185 unsigned int size)
Peter Oruba80cc9f12008-07-28 18:44:22 +0200186{
Borislav Petkovbe62adb2011-12-02 18:02:17 +0100187 struct cpuinfo_x86 *c = &cpu_data(cpu);
188 u32 max_size;
189
190#define F1XH_MPB_MAX_SIZE 2048
191#define F14H_MPB_MAX_SIZE 1824
192#define F15H_MPB_MAX_SIZE 4096
Boris Ostrovsky36c46ca2012-11-15 13:41:50 -0500193#define F16H_MPB_MAX_SIZE 3458
Borislav Petkovbe62adb2011-12-02 18:02:17 +0100194
195 switch (c->x86) {
196 case 0x14:
197 max_size = F14H_MPB_MAX_SIZE;
198 break;
199 case 0x15:
200 max_size = F15H_MPB_MAX_SIZE;
201 break;
Boris Ostrovsky36c46ca2012-11-15 13:41:50 -0500202 case 0x16:
203 max_size = F16H_MPB_MAX_SIZE;
204 break;
Borislav Petkovbe62adb2011-12-02 18:02:17 +0100205 default:
206 max_size = F1XH_MPB_MAX_SIZE;
207 break;
208 }
209
210 if (patch_size > min_t(u32, size, max_size)) {
211 pr_err("patch size mismatch\n");
212 return 0;
213 }
214
215 return patch_size;
216}
217
Dmitry Adamushko871b72d2009-05-11 23:48:27 +0200218static int apply_microcode_amd(int cpu)
Peter Oruba80cc9f12008-07-28 18:44:22 +0200219{
Borislav Petkovbcb80e52011-10-17 16:34:36 +0200220 struct cpuinfo_x86 *c = &cpu_data(cpu);
Borislav Petkov2efb05e2012-08-01 16:16:13 +0200221 struct microcode_amd *mc_amd;
222 struct ucode_cpu_info *uci;
223 struct ucode_patch *p;
224 u32 rev, dummy;
Peter Oruba80cc9f12008-07-28 18:44:22 +0200225
Borislav Petkov2efb05e2012-08-01 16:16:13 +0200226 BUG_ON(raw_smp_processor_id() != cpu);
Peter Oruba80cc9f12008-07-28 18:44:22 +0200227
Borislav Petkov2efb05e2012-08-01 16:16:13 +0200228 uci = ucode_cpu_info + cpu;
229
230 p = find_patch(cpu);
231 if (!p)
Dmitry Adamushko871b72d2009-05-11 23:48:27 +0200232 return 0;
Peter Oruba80cc9f12008-07-28 18:44:22 +0200233
Borislav Petkov2efb05e2012-08-01 16:16:13 +0200234 mc_amd = p->data;
235 uci->mc = p->data;
236
Andreas Herrmann29d08872008-12-16 19:16:34 +0100237 rdmsr(MSR_AMD64_PATCH_LEVEL, rev, dummy);
Peter Oruba80cc9f12008-07-28 18:44:22 +0200238
Borislav Petkov685ca6d2012-06-20 16:17:51 +0200239 /* need to apply patch? */
240 if (rev >= mc_amd->hdr.patch_id) {
241 c->microcode = rev;
242 return 0;
243 }
244
245 wrmsrl(MSR_AMD64_PATCH_LOADER, (u64)(long)&mc_amd->hdr.data_code);
246
247 /* verify patch application was successful */
248 rdmsr(MSR_AMD64_PATCH_LEVEL, rev, dummy);
Dmitry Adamushko18dbc912008-09-23 12:08:44 +0200249 if (rev != mc_amd->hdr.patch_id) {
Borislav Petkov258721e2011-01-05 18:13:19 +0100250 pr_err("CPU%d: update failed for patch_level=0x%08x\n",
Joe Perchesf58e1f52009-12-08 22:30:50 -0800251 cpu, mc_amd->hdr.patch_id);
Dmitry Adamushko871b72d2009-05-11 23:48:27 +0200252 return -1;
Peter Oruba80cc9f12008-07-28 18:44:22 +0200253 }
254
Borislav Petkov258721e2011-01-05 18:13:19 +0100255 pr_info("CPU%d: new patch_level=0x%08x\n", cpu, rev);
Dmitry Adamushkod45de402008-08-20 00:22:26 +0200256 uci->cpu_sig.rev = rev;
Borislav Petkovbcb80e52011-10-17 16:34:36 +0200257 c->microcode = rev;
Dmitry Adamushko871b72d2009-05-11 23:48:27 +0200258
259 return 0;
Peter Oruba80cc9f12008-07-28 18:44:22 +0200260}
261
Andreas Herrmann0657d9e2008-12-16 19:14:05 +0100262static int install_equiv_cpu_table(const u8 *buf)
Peter Oruba80cc9f12008-07-28 18:44:22 +0200263{
Borislav Petkov10de52d2010-12-30 22:10:12 +0100264 unsigned int *ibuf = (unsigned int *)buf;
265 unsigned int type = ibuf[1];
266 unsigned int size = ibuf[2];
Peter Oruba80cc9f12008-07-28 18:44:22 +0200267
Borislav Petkov10de52d2010-12-30 22:10:12 +0100268 if (type != UCODE_EQUIV_CPU_TABLE_TYPE || !size) {
Borislav Petkov258721e2011-01-05 18:13:19 +0100269 pr_err("empty section/"
270 "invalid type field in container file section header\n");
Borislav Petkov10de52d2010-12-30 22:10:12 +0100271 return -EINVAL;
Peter Oruba80cc9f12008-07-28 18:44:22 +0200272 }
273
Jesper Juhl8e5e9522010-11-09 00:08:11 +0100274 equiv_cpu_table = vmalloc(size);
Peter Oruba80cc9f12008-07-28 18:44:22 +0200275 if (!equiv_cpu_table) {
Joe Perchesf58e1f52009-12-08 22:30:50 -0800276 pr_err("failed to allocate equivalent CPU table\n");
Borislav Petkov10de52d2010-12-30 22:10:12 +0100277 return -ENOMEM;
Peter Oruba80cc9f12008-07-28 18:44:22 +0200278 }
279
Borislav Petkove7e632f2012-07-20 14:12:21 +0200280 memcpy(equiv_cpu_table, buf + CONTAINER_HDR_SZ, size);
Peter Oruba80cc9f12008-07-28 18:44:22 +0200281
Borislav Petkov40b7f3d2011-06-15 15:34:57 +0200282 /* add header length */
283 return size + CONTAINER_HDR_SZ;
Peter Oruba80cc9f12008-07-28 18:44:22 +0200284}
285
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200286static void free_equiv_cpu_table(void)
Peter Oruba80cc9f12008-07-28 18:44:22 +0200287{
Figo.zhangaeef50b2009-06-07 22:30:36 +0800288 vfree(equiv_cpu_table);
289 equiv_cpu_table = NULL;
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200290}
Peter Oruba80cc9f12008-07-28 18:44:22 +0200291
Borislav Petkov2efb05e2012-08-01 16:16:13 +0200292static void cleanup(void)
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200293{
Borislav Petkov2efb05e2012-08-01 16:16:13 +0200294 free_equiv_cpu_table();
295 free_cache();
296}
Peter Oruba80cc9f12008-07-28 18:44:22 +0200297
Borislav Petkov2efb05e2012-08-01 16:16:13 +0200298/*
299 * We return the current size even if some of the checks failed so that
300 * we can skip over the next patch. If we return a negative value, we
301 * signal a grave error like a memory allocation has failed and the
302 * driver cannot continue functioning normally. In such cases, we tear
303 * down everything we've used up so far and exit.
304 */
305static int verify_and_add_patch(unsigned int cpu, u8 *fw, unsigned int leftover)
306{
307 struct cpuinfo_x86 *c = &cpu_data(cpu);
308 struct microcode_header_amd *mc_hdr;
309 struct ucode_patch *patch;
310 unsigned int patch_size, crnt_size, ret;
311 u32 proc_fam;
312 u16 proc_id;
313
314 patch_size = *(u32 *)(fw + 4);
315 crnt_size = patch_size + SECTION_HDR_SIZE;
316 mc_hdr = (struct microcode_header_amd *)(fw + SECTION_HDR_SIZE);
317 proc_id = mc_hdr->processor_rev_id;
318
319 proc_fam = find_cpu_family_by_equiv_cpu(proc_id);
320 if (!proc_fam) {
321 pr_err("No patch family for equiv ID: 0x%04x\n", proc_id);
322 return crnt_size;
323 }
324
325 /* check if patch is for the current family */
326 proc_fam = ((proc_fam >> 8) & 0xf) + ((proc_fam >> 20) & 0xff);
327 if (proc_fam != c->x86)
328 return crnt_size;
329
330 if (mc_hdr->nb_dev_id || mc_hdr->sb_dev_id) {
331 pr_err("Patch-ID 0x%08x: chipset-specific code unsupported.\n",
332 mc_hdr->patch_id);
333 return crnt_size;
334 }
335
336 ret = verify_patch_size(cpu, patch_size, leftover);
337 if (!ret) {
338 pr_err("Patch-ID 0x%08x: size mismatch.\n", mc_hdr->patch_id);
339 return crnt_size;
340 }
341
342 patch = kzalloc(sizeof(*patch), GFP_KERNEL);
343 if (!patch) {
344 pr_err("Patch allocation failure.\n");
345 return -EINVAL;
346 }
347
348 patch->data = kzalloc(patch_size, GFP_KERNEL);
349 if (!patch->data) {
350 pr_err("Patch data allocation failure.\n");
351 kfree(patch);
352 return -EINVAL;
353 }
354
355 /* All looks ok, copy patch... */
356 memcpy(patch->data, fw + SECTION_HDR_SIZE, patch_size);
357 INIT_LIST_HEAD(&patch->plist);
358 patch->patch_id = mc_hdr->patch_id;
359 patch->equiv_cpu = proc_id;
360
361 /* ... and add to cache. */
362 update_cache(patch);
363
364 return crnt_size;
365}
366
367static enum ucode_state load_microcode_amd(int cpu, const u8 *data, size_t size)
368{
369 enum ucode_state ret = UCODE_ERROR;
370 unsigned int leftover;
371 u8 *fw = (u8 *)data;
372 int crnt_size = 0;
373 int offset;
374
375 offset = install_equiv_cpu_table(data);
Borislav Petkov10de52d2010-12-30 22:10:12 +0100376 if (offset < 0) {
Joe Perchesf58e1f52009-12-08 22:30:50 -0800377 pr_err("failed to create equivalent cpu table\n");
Borislav Petkov2efb05e2012-08-01 16:16:13 +0200378 return ret;
Peter Oruba80cc9f12008-07-28 18:44:22 +0200379 }
Borislav Petkov2efb05e2012-08-01 16:16:13 +0200380 fw += offset;
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200381 leftover = size - offset;
382
Borislav Petkov2efb05e2012-08-01 16:16:13 +0200383 if (*(u32 *)fw != UCODE_UCODE_TYPE) {
Borislav Petkovbe62adb2011-12-02 18:02:17 +0100384 pr_err("invalid type field in container file section header\n");
Borislav Petkov2efb05e2012-08-01 16:16:13 +0200385 free_equiv_cpu_table();
386 return ret;
Borislav Petkovbe62adb2011-12-02 18:02:17 +0100387 }
388
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200389 while (leftover) {
Borislav Petkov2efb05e2012-08-01 16:16:13 +0200390 crnt_size = verify_and_add_patch(cpu, fw, leftover);
391 if (crnt_size < 0)
392 return ret;
Borislav Petkovd7336892011-12-07 17:26:56 +0100393
Borislav Petkov2efb05e2012-08-01 16:16:13 +0200394 fw += crnt_size;
395 leftover -= crnt_size;
Peter Oruba80cc9f12008-07-28 18:44:22 +0200396 }
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200397
Borislav Petkov2efb05e2012-08-01 16:16:13 +0200398 return UCODE_OK;
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200399}
400
Andreas Herrmann5b68edc2012-01-20 17:44:12 +0100401/*
402 * AMD microcode firmware naming convention, up to family 15h they are in
403 * the legacy file:
404 *
405 * amd-ucode/microcode_amd.bin
406 *
407 * This legacy file is always smaller than 2K in size.
408 *
Borislav Petkov2efb05e2012-08-01 16:16:13 +0200409 * Beginning with family 15h, they are in family-specific firmware files:
Andreas Herrmann5b68edc2012-01-20 17:44:12 +0100410 *
411 * amd-ucode/microcode_amd_fam15h.bin
412 * amd-ucode/microcode_amd_fam16h.bin
413 * ...
414 *
415 * These might be larger than 2K.
416 */
Borislav Petkov48e30682012-07-26 15:51:00 +0200417static enum ucode_state request_microcode_amd(int cpu, struct device *device,
418 bool refresh_fw)
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200419{
Andreas Herrmann5b68edc2012-01-20 17:44:12 +0100420 char fw_name[36] = "amd-ucode/microcode_amd.bin";
Andreas Herrmann5b68edc2012-01-20 17:44:12 +0100421 struct cpuinfo_x86 *c = &cpu_data(cpu);
Borislav Petkov2efb05e2012-08-01 16:16:13 +0200422 enum ucode_state ret = UCODE_NFOUND;
423 const struct firmware *fw;
424
425 /* reload ucode container only on the boot cpu */
426 if (!refresh_fw || c->cpu_index != boot_cpu_data.cpu_index)
427 return UCODE_OK;
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200428
Andreas Herrmann5b68edc2012-01-20 17:44:12 +0100429 if (c->x86 >= 0x15)
430 snprintf(fw_name, sizeof(fw_name), "amd-ucode/microcode_amd_fam%.2xh.bin", c->x86);
431
432 if (request_firmware(&fw, (const char *)fw_name, device)) {
Borislav Petkov258721e2011-01-05 18:13:19 +0100433 pr_err("failed to load file %s\n", fw_name);
Borislav Petkovffc7e8a2010-12-30 21:06:01 +0100434 goto out;
Andreas Herrmann3b2e3d82010-01-22 21:34:56 +0100435 }
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200436
Borislav Petkovffc7e8a2010-12-30 21:06:01 +0100437 ret = UCODE_ERROR;
438 if (*(u32 *)fw->data != UCODE_MAGIC) {
Borislav Petkov258721e2011-01-05 18:13:19 +0100439 pr_err("invalid magic value (0x%08x)\n", *(u32 *)fw->data);
Borislav Petkovffc7e8a2010-12-30 21:06:01 +0100440 goto fw_release;
Borislav Petkov506f90e2009-10-29 14:45:52 +0100441 }
442
Borislav Petkov2efb05e2012-08-01 16:16:13 +0200443 /* free old equiv table */
444 free_equiv_cpu_table();
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200445
Borislav Petkov2efb05e2012-08-01 16:16:13 +0200446 ret = load_microcode_amd(cpu, fw->data, fw->size);
447 if (ret != UCODE_OK)
448 cleanup();
449
450 fw_release:
Borislav Petkovffc7e8a2010-12-30 21:06:01 +0100451 release_firmware(fw);
Andreas Herrmann3b2e3d82010-01-22 21:34:56 +0100452
Borislav Petkov2efb05e2012-08-01 16:16:13 +0200453 out:
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200454 return ret;
455}
456
Dmitry Adamushko871b72d2009-05-11 23:48:27 +0200457static enum ucode_state
458request_microcode_user(int cpu, const void __user *buf, size_t size)
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200459{
Dmitry Adamushko871b72d2009-05-11 23:48:27 +0200460 return UCODE_ERROR;
Peter Oruba80cc9f12008-07-28 18:44:22 +0200461}
462
Peter Oruba80cc9f12008-07-28 18:44:22 +0200463static void microcode_fini_cpu_amd(int cpu)
464{
465 struct ucode_cpu_info *uci = ucode_cpu_info + cpu;
466
Dmitry Adamushko18dbc912008-09-23 12:08:44 +0200467 uci->mc = NULL;
Peter Oruba80cc9f12008-07-28 18:44:22 +0200468}
469
470static struct microcode_ops microcode_amd_ops = {
Dmitry Adamushkoa0a29b62008-09-11 23:27:52 +0200471 .request_microcode_user = request_microcode_user,
Borislav Petkovffc7e8a2010-12-30 21:06:01 +0100472 .request_microcode_fw = request_microcode_amd,
Peter Oruba80cc9f12008-07-28 18:44:22 +0200473 .collect_cpu_info = collect_cpu_info_amd,
474 .apply_microcode = apply_microcode_amd,
475 .microcode_fini_cpu = microcode_fini_cpu_amd,
476};
477
Dmitry Adamushko18dbc912008-09-23 12:08:44 +0200478struct microcode_ops * __init init_amd_microcode(void)
Peter Oruba80cc9f12008-07-28 18:44:22 +0200479{
Andreas Herrmann283c1f22012-04-12 16:51:57 +0200480 struct cpuinfo_x86 *c = &cpu_data(0);
481
482 if (c->x86_vendor != X86_VENDOR_AMD || c->x86 < 0x10) {
483 pr_warning("AMD CPU family 0x%x not supported\n", c->x86);
484 return NULL;
485 }
486
Dmitry Adamushko18dbc912008-09-23 12:08:44 +0200487 return &microcode_amd_ops;
Peter Oruba80cc9f12008-07-28 18:44:22 +0200488}
Borislav Petkovf72c1a52011-12-02 16:50:04 +0100489
490void __exit exit_amd_microcode(void)
491{
Borislav Petkov2efb05e2012-08-01 16:16:13 +0200492 cleanup();
Borislav Petkovf72c1a52011-12-02 16:50:04 +0100493}