Since some people disapprove of white space cleanups mixed in regular commits
[coreboot.git] / src / cpu / intel / model_6bx / model_6bx_init.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2007-2009 coresystems GmbH
5  * Copyright (C) 2010 Joseph Smith <joe@settoplinux.org>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; version 2 of
10  * the License.
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,
20  * MA 02110-1301 USA
21  */
22
23 #include <console/console.h>
24 #include <device/device.h>
25 #include <device/pci.h>
26 #include <string.h>
27 #include <cpu/cpu.h>
28 #include <cpu/x86/mtrr.h>
29 #include <cpu/x86/msr.h>
30 #include <cpu/x86/lapic.h>
31 #include <cpu/intel/microcode.h>
32 #include <cpu/x86/cache.h>
33 #include <usbdebug_direct.h>
34
35 static const uint32_t microcode_updates[] = {
36         #include "microcode-737-MU16b11c.h"
37         #include "microcode-738-MU16b11d.h"
38         #include "microcode-875-MU16b401.h"
39         #include "microcode-885-MU16b402.h"
40         /*  Dummy terminator  */
41         0x0, 0x0, 0x0, 0x0,
42         0x0, 0x0, 0x0, 0x0,
43         0x0, 0x0, 0x0, 0x0,
44         0x0, 0x0, 0x0, 0x0,
45 };
46
47 static inline void strcpy(char *dst, char *src)
48 {
49         while (*src) *dst++ = *src++;
50 }
51
52 static void fill_processor_name(char *processor_name)
53 {
54         struct cpuid_result regs;
55         char temp_processor_name[49];
56         char *processor_name_start;
57         unsigned int *name_as_ints = (unsigned int *)temp_processor_name;
58         int i;
59
60         for (i=0; i<3; i++) {
61                 regs = cpuid(0x80000002 + i);
62                 name_as_ints[i*4 + 0] = regs.eax;
63                 name_as_ints[i*4 + 1] = regs.ebx;
64                 name_as_ints[i*4 + 2] = regs.ecx;
65                 name_as_ints[i*4 + 3] = regs.edx;
66         }
67
68         temp_processor_name[48] = 0;
69
70         /* Skip leading spaces */
71         processor_name_start = temp_processor_name;
72         while (*processor_name_start == ' ')
73                 processor_name_start++;
74
75         memset(processor_name, 0, 49);
76         strcpy(processor_name, processor_name_start);
77 }
78
79 #if CONFIG_USBDEBUG_DIRECT
80 static unsigned ehci_debug_addr;
81 #endif
82
83 static void model_6bx_init(device_t cpu)
84 {
85         char processor_name[49];
86
87         /* Turn on caching if we haven't already */
88         x86_enable_cache();
89
90         /* Update the microcode */
91         intel_update_microcode(microcode_updates);
92
93         /* Print processor name */
94         fill_processor_name(processor_name);
95         printk(BIOS_INFO, "CPU: %s.\n", processor_name);
96
97 #if CONFIG_USBDEBUG_DIRECT
98         // Is this caution really needed?
99         if(!ehci_debug_addr)
100                 ehci_debug_addr = get_ehci_debug();
101         set_ehci_debug(0);
102 #endif
103
104         /* Setup MTRRs */
105         x86_setup_mtrrs(36);
106         x86_mtrr_check();
107
108 #if CONFIG_USBDEBUG_DIRECT
109         set_ehci_debug(ehci_debug_addr);
110 #endif
111
112         /* Enable the local cpu apics */
113         setup_lapic();
114 }
115
116 static struct device_operations cpu_dev_ops = {
117         .init     = model_6bx_init,
118 };
119
120 static struct cpu_device_id cpu_table[] = {
121         { X86_VENDOR_INTEL, 0x06B1 },
122         { X86_VENDOR_INTEL, 0x06B4 }, /* Low Voltage PIII Micro-FCBGA Socket 479 */
123         { 0, 0 },
124 };
125
126 static const struct cpu_driver driver __cpu_driver = {
127         .ops      = &cpu_dev_ops,
128         .id_table = cpu_table,
129 };
130