blob: ee149d09b58409a7c8267bbb5a0a8a2c51789d8f [file] [log] [blame]
Stefan Reinauer8e073822012-04-04 00:07:22 +02001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2011 The Chromium OS Authors. All rights reserved.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; version 2 of
9 * the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
Stefan Reinauer8e073822012-04-04 00:07:22 +020015 */
16
Stefan Reinauer8e073822012-04-04 00:07:22 +020017#include <arch/io.h>
Stefan Reinauer8e073822012-04-04 00:07:22 +020018#include <console/console.h>
19#include <delay.h>
Nicola Corna14604da2018-05-15 17:15:03 +020020#include <device/pci_def.h>
Patrick Georgi546953c2014-11-29 10:38:17 +010021#include <halt.h>
Stefan Reinauer8e073822012-04-04 00:07:22 +020022#include <string.h>
Nathaniel Roach52f08712017-09-09 19:58:08 +080023#include <timestamp.h>
Stefan Reinauer8e073822012-04-04 00:07:22 +020024#include "me.h"
25#include "pch.h"
26
27static const char *me_ack_values[] = {
28 [ME_HFS_ACK_NO_DID] = "No DID Ack received",
29 [ME_HFS_ACK_RESET] = "Non-power cycle reset",
30 [ME_HFS_ACK_PWR_CYCLE] = "Power cycle reset",
31 [ME_HFS_ACK_S3] = "Go to S3",
32 [ME_HFS_ACK_S4] = "Go to S4",
33 [ME_HFS_ACK_S5] = "Go to S5",
34 [ME_HFS_ACK_GBL_RESET] = "Global Reset",
35 [ME_HFS_ACK_CONTINUE] = "Continue to boot"
36};
37
38static inline void pci_read_dword_ptr(void *ptr, int offset)
39{
40 u32 dword = pci_read_config32(PCH_ME_DEV, offset);
41 memcpy(ptr, &dword, sizeof(dword));
42}
43
Stefan Reinauer8e073822012-04-04 00:07:22 +020044void intel_early_me_status(void)
45{
46 struct me_hfs hfs;
47 struct me_gmes gmes;
Nicola Corna14604da2018-05-15 17:15:03 +020048 u32 id = pci_read_config32(PCH_ME_DEV, PCI_VENDOR_ID);
Stefan Reinauer8e073822012-04-04 00:07:22 +020049
Nicola Corna14604da2018-05-15 17:15:03 +020050 if ((id == 0xffffffff) || (id == 0x00000000) ||
51 (id == 0x0000ffff) || (id == 0xffff0000)) {
52 printk(BIOS_DEBUG, "Missing Intel ME PCI device.\n");
53 } else {
54 pci_read_dword_ptr(&hfs, PCI_ME_HFS);
55 pci_read_dword_ptr(&gmes, PCI_ME_GMES);
Stefan Reinauer8e073822012-04-04 00:07:22 +020056
Nicola Corna14604da2018-05-15 17:15:03 +020057 intel_me_status(&hfs, &gmes);
58 }
Stefan Reinauer8e073822012-04-04 00:07:22 +020059}
60
61int intel_early_me_init(void)
62{
63 int count;
64 struct me_uma uma;
65 struct me_hfs hfs;
66
67 printk(BIOS_INFO, "Intel ME early init\n");
68
69 /* Wait for ME UMA SIZE VALID bit to be set */
70 for (count = ME_RETRY; count > 0; --count) {
71 pci_read_dword_ptr(&uma, PCI_ME_UMA);
72 if (uma.valid)
73 break;
74 udelay(ME_DELAY);
75 }
76 if (!count) {
77 printk(BIOS_ERR, "ERROR: ME is not ready!\n");
78 return -1;
79 }
80
81 /* Check for valid firmware */
82 pci_read_dword_ptr(&hfs, PCI_ME_HFS);
83 if (hfs.fpt_bad) {
84 printk(BIOS_WARNING, "WARNING: ME has bad firmware\n");
85 return -1;
86 }
87
88 printk(BIOS_INFO, "Intel ME firmware is ready\n");
89 return 0;
90}
91
92int intel_early_me_uma_size(void)
93{
94 struct me_uma uma;
95
96 pci_read_dword_ptr(&uma, PCI_ME_UMA);
97 if (uma.valid) {
98 printk(BIOS_DEBUG, "ME: Requested %uMB UMA\n", uma.size);
99 return uma.size;
100 }
101
102 printk(BIOS_DEBUG, "ME: Invalid UMA size\n");
103 return 0;
104}
105
106static inline void set_global_reset(int enable)
107{
108 u32 etr3 = pci_read_config32(PCH_LPC_DEV, ETR3);
109
110 /* Clear CF9 Without Resume Well Reset Enable */
111 etr3 &= ~ETR3_CWORWRE;
112
113 /* CF9GR indicates a Global Reset */
114 if (enable)
115 etr3 |= ETR3_CF9GR;
116 else
117 etr3 &= ~ETR3_CF9GR;
118
119 pci_write_config32(PCH_LPC_DEV, ETR3, etr3);
120}
121
122int intel_early_me_init_done(u8 status)
123{
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700124 u8 reset, errorcode, opmode;
125 u16 reg16;
Stefan Reinauer8e073822012-04-04 00:07:22 +0200126 u32 mebase_l, mebase_h;
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700127 u32 millisec;
128 u32 hfs, me_fws2;
Stefan Reinauer8e073822012-04-04 00:07:22 +0200129 struct me_did did = {
130 .init_done = ME_INIT_DONE,
131 .status = status
132 };
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700133 u32 meDID;
134
135 hfs = (pci_read_config32(PCI_DEV(0, 0x16, 0), PCI_ME_HFS) & 0xff000) >> 12;
136
137 opmode = (hfs & 0xf0) >> 4;
138 errorcode = hfs & 0xf;
139
140 if (opmode != ME_HFS_MODE_NORMAL) {
141 printk(BIOS_NOTICE, "ME: Wrong mode : %d\n", opmode);
142 //return 0;
143 }
144 if (errorcode) {
145 printk(BIOS_NOTICE, "ME: HFS error : %d\n", errorcode);
146 //return 0;
147 }
148
149 me_fws2 = pci_read_config32(PCI_DEV(0, 0x16, 0), 0x48);
150 printk(BIOS_NOTICE, "ME: FWS2: 0x%x\n", me_fws2);
151 printk(BIOS_NOTICE, "ME: Bist in progress: 0x%x\n", me_fws2 & 0x1);
152 printk(BIOS_NOTICE, "ME: ICC Status : 0x%x\n", (me_fws2 & 0x6) >> 1);
153 printk(BIOS_NOTICE, "ME: Invoke MEBx : 0x%x\n", (me_fws2 & 0x8) >> 3);
154 printk(BIOS_NOTICE, "ME: CPU replaced : 0x%x\n", (me_fws2 & 0x10) >> 4);
155 printk(BIOS_NOTICE, "ME: MBP ready : 0x%x\n", (me_fws2 & 0x20) >> 5);
156 printk(BIOS_NOTICE, "ME: MFS failure : 0x%x\n", (me_fws2 & 0x40) >> 6);
157 printk(BIOS_NOTICE, "ME: Warm reset req : 0x%x\n", (me_fws2 & 0x80) >> 7);
158 printk(BIOS_NOTICE, "ME: CPU repl valid : 0x%x\n", (me_fws2 & 0x100) >> 8);
159 printk(BIOS_NOTICE, "ME: (Reserved) : 0x%x\n", (me_fws2 & 0x600) >> 9);
160 printk(BIOS_NOTICE, "ME: FW update req : 0x%x\n", (me_fws2 & 0x800) >> 11);
161 printk(BIOS_NOTICE, "ME: (Reserved) : 0x%x\n", (me_fws2 & 0xf000) >> 12);
162 printk(BIOS_NOTICE, "ME: Current state : 0x%x\n", (me_fws2 & 0xff0000) >> 16);
163 printk(BIOS_NOTICE, "ME: Current PM event: 0x%x\n", (me_fws2 & 0xf000000) >> 24);
164 printk(BIOS_NOTICE, "ME: Progress code : 0x%x\n", (me_fws2 & 0xf0000000) >> 28);
165
Elyes HAOUAS1bcd7fc2016-07-28 21:20:04 +0200166 // Poll CPU replaced for 50ms
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700167 millisec = 0;
168 while ((((me_fws2 & 0x100) >> 8) == 0) && millisec < 50) {
169 udelay(1000);
170 me_fws2 = pci_read_config32(PCI_DEV(0, 0x16, 0), 0x48);
171 millisec++;
172 }
173 if (millisec >= 50 || ((me_fws2 & 0x100) >> 8) == 0x0) {
174 printk(BIOS_NOTICE, "Waited long enough, or CPU was not replaced, continue...\n");
175 } else if ((me_fws2 & 0x100) == 0x100) {
176 if ((me_fws2 & 0x80) == 0x80) {
177 printk(BIOS_NOTICE, "CPU was replaced & warm reset required...\n");
Kyösti Mälkkid45114f2013-07-26 08:53:59 +0300178 reg16 = pci_read_config16(PCI_DEV(0, 31, 0), 0xa2) & ~0x80;
179 pci_write_config16(PCI_DEV(0, 31, 0), 0xa2, reg16);
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700180 set_global_reset(0);
181 outb(0x6, 0xcf9);
182 halt();
183 }
184
185 if (((me_fws2 & 0x10) == 0x10) && (me_fws2 & 0x80) == 0x00) {
186 printk(BIOS_NOTICE, "Full training required\n");
187 }
188 }
189
190 printk(BIOS_NOTICE, "PASSED! Tell ME that DRAM is ready\n");
Stefan Reinauer8e073822012-04-04 00:07:22 +0200191
192 /* MEBASE from MESEG_BASE[35:20] */
193 mebase_l = pci_read_config32(PCI_CPU_DEVICE, PCI_CPU_MEBASE_L);
194 mebase_h = pci_read_config32(PCI_CPU_DEVICE, PCI_CPU_MEBASE_H) & 0xf;
195 did.uma_base = (mebase_l >> 20) | (mebase_h << 12);
196
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700197 meDID = did.uma_base | (1 << 28);// | (1 << 23);
198 pci_write_config32(PCI_DEV(0, 0x16, 0), PCI_ME_H_GS, meDID);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200199
Stefan Reinauer8e073822012-04-04 00:07:22 +0200200 /* Must wait for ME acknowledgement */
Nathaniel Roachd7e0cb92017-09-09 19:59:07 +0800201 if (opmode == ME_HFS_MODE_DEBUG) {
202 printk(BIOS_NOTICE,
203 "ME: ME is reporting as disabled, "
204 "so not waiting for a response.\n");
205 } else {
206 timestamp_add_now(TS_ME_INFORM_DRAM_WAIT);
207 udelay(100);
208 millisec = 0;
209 do {
210 udelay(1000);
211 hfs = (pci_read_config32(
212 PCI_DEV(0, 0x16, 0), PCI_ME_HFS) & 0xfe000000)
213 >> 24;
214 millisec++;
215 } while ((((hfs & 0xf0) >> 4) != ME_HFS_BIOS_DRAM_ACK)
216 && (millisec <= 5000));
217 timestamp_add_now(TS_ME_INFORM_DRAM_DONE);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200218 }
Nathaniel Roachd7e0cb92017-09-09 19:59:07 +0800219
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700220
221 me_fws2 = pci_read_config32(PCI_DEV(0, 0x16, 0), 0x48);
222 printk(BIOS_NOTICE, "ME: FWS2: 0x%x\n", me_fws2);
223 printk(BIOS_NOTICE, "ME: Bist in progress: 0x%x\n", me_fws2 & 0x1);
224 printk(BIOS_NOTICE, "ME: ICC Status : 0x%x\n", (me_fws2 & 0x6) >> 1);
225 printk(BIOS_NOTICE, "ME: Invoke MEBx : 0x%x\n", (me_fws2 & 0x8) >> 3);
226 printk(BIOS_NOTICE, "ME: CPU replaced : 0x%x\n", (me_fws2 & 0x10) >> 4);
227 printk(BIOS_NOTICE, "ME: MBP ready : 0x%x\n", (me_fws2 & 0x20) >> 5);
228 printk(BIOS_NOTICE, "ME: MFS failure : 0x%x\n", (me_fws2 & 0x40) >> 6);
229 printk(BIOS_NOTICE, "ME: Warm reset req : 0x%x\n", (me_fws2 & 0x80) >> 7);
230 printk(BIOS_NOTICE, "ME: CPU repl valid : 0x%x\n", (me_fws2 & 0x100) >> 8);
231 printk(BIOS_NOTICE, "ME: (Reserved) : 0x%x\n", (me_fws2 & 0x600) >> 9);
232 printk(BIOS_NOTICE, "ME: FW update req : 0x%x\n", (me_fws2 & 0x800) >> 11);
233 printk(BIOS_NOTICE, "ME: (Reserved) : 0x%x\n", (me_fws2 & 0xf000) >> 12);
234 printk(BIOS_NOTICE, "ME: Current state : 0x%x\n", (me_fws2 & 0xff0000) >> 16);
235 printk(BIOS_NOTICE, "ME: Current PM event: 0x%x\n", (me_fws2 & 0xf000000) >> 24);
236 printk(BIOS_NOTICE, "ME: Progress code : 0x%x\n", (me_fws2 & 0xf0000000) >> 28);
237
Stefan Reinauer8e073822012-04-04 00:07:22 +0200238
239 /* Return the requested BIOS action */
240 printk(BIOS_NOTICE, "ME: Requested BIOS Action: %s\n",
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700241 me_ack_values[(hfs & 0xe) >> 1]);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200242
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700243 reset = inb(0xcf9);
244 reset &= 0xf1;
245 switch ((hfs & 0xe) >> 1) {
246 case ME_HFS_ACK_NO_DID:
Stefan Reinauer8e073822012-04-04 00:07:22 +0200247 case ME_HFS_ACK_CONTINUE:
248 /* Continue to boot */
249 return 0;
250 case ME_HFS_ACK_RESET:
251 /* Non-power cycle reset */
252 set_global_reset(0);
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700253 reset |= 0x06;
Stefan Reinauer8e073822012-04-04 00:07:22 +0200254 break;
255 case ME_HFS_ACK_PWR_CYCLE:
256 /* Power cycle reset */
257 set_global_reset(0);
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700258 reset |= 0x0e;
Stefan Reinauer8e073822012-04-04 00:07:22 +0200259 break;
260 case ME_HFS_ACK_GBL_RESET:
261 /* Global reset */
262 set_global_reset(1);
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700263 reset |= 0x0e;
Stefan Reinauer8e073822012-04-04 00:07:22 +0200264 break;
265 case ME_HFS_ACK_S3:
266 case ME_HFS_ACK_S4:
267 case ME_HFS_ACK_S5:
268 break;
269 }
270
271 /* Perform the requested reset */
272 if (reset) {
273 outb(reset, 0xcf9);
Patrick Georgi546953c2014-11-29 10:38:17 +0100274 halt();
Stefan Reinauer8e073822012-04-04 00:07:22 +0200275 }
276 return -1;
277}