85a652fc00c65fa0067e4b0c8a4dfb98d56fdaa0
[coreboot.git] / src / cpu / amd / model_fxx / model_fxx_update_microcode.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2005 Advanced Micro Devices, Inc.
5  * Copyright (C) 2010 Advanced Micro Devices, Inc.
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
20  */
21
22 /*
23  * Description: Microcode patch support for k8 by yhlu
24  */
25
26
27 #include <console/console.h>
28 #include <device/device.h>
29 #include <device/pci.h>
30 #include <string.h>
31
32 #include <cpu/amd/microcode.h>
33
34 static uint8_t microcode_updates[] __attribute__ ((aligned(16))) = {
35
36 #if CONFIG_K8_REV_F_SUPPORT == 0
37         #include "microcode_rev_c.h"
38         #include "microcode_rev_d.h"
39         #include "microcode_rev_e.h"
40 #endif
41
42 #if CONFIG_K8_REV_F_SUPPORT == 1
43 //      #include "microcode_rev_f.h"
44 #endif
45         /*  Dummy terminator  */
46         0x0, 0x0, 0x0, 0x0,
47         0x0, 0x0, 0x0, 0x0,
48         0x0, 0x0, 0x0, 0x0,
49         0x0, 0x0, 0x0, 0x0,
50 };
51
52 static unsigned get_equivalent_processor_rev_id(unsigned orig_id) {
53         static unsigned id_mapping_table[] = {
54         #if CONFIG_K8_REV_F_SUPPORT == 0
55                 0x0f48, 0x0048,
56                 0x0f58, 0x0048,
57
58                 0x0f4a, 0x004a,
59                 0x0f5a, 0x004a,
60                 0x0f7a, 0x004a,
61                 0x0f82, 0x004a,
62                 0x0fc0, 0x004a,
63                 0x0ff0, 0x004a,
64
65                 0x10f50, 0x0150,
66                 0x10f70, 0x0150,
67                 0x10f80, 0x0150,
68                 0x10fc0, 0x0150,
69                 0x10ff0, 0x0150,
70
71                 0x20f10, 0x0210,
72                 0x20f12, 0x0210,
73                 0x20f32, 0x0210,
74                 0x20fb1, 0x0210,
75         #endif
76
77         #if CONFIG_K8_REV_F_SUPPORT == 1
78
79         #endif
80
81         };
82
83
84         unsigned new_id;
85         int i;
86
87         new_id = 0;
88
89         for(i=0; i<sizeof(id_mapping_table); i+=2 ) {
90                 if(id_mapping_table[i]==orig_id) {
91                         new_id = id_mapping_table[i+1];
92                         break;
93                 }
94         }
95
96         return new_id;
97
98 }
99
100 void model_fxx_update_microcode(unsigned cpu_deviceid)
101 {
102         unsigned equivalent_processor_rev_id;
103
104         /* Update the microcode */
105         equivalent_processor_rev_id = get_equivalent_processor_rev_id(cpu_deviceid );
106         if(equivalent_processor_rev_id != 0)
107                 amd_update_microcode(microcode_updates, equivalent_processor_rev_id);
108
109 }
110