blob: 47b8708ba7ae78dceb92c701ba7773b5badcc579 [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>
20#include <device/pci_ids.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;
48
49 pci_read_dword_ptr(&hfs, PCI_ME_HFS);
50 pci_read_dword_ptr(&gmes, PCI_ME_GMES);
51
52 intel_me_status(&hfs, &gmes);
53}
54
55int intel_early_me_init(void)
56{
57 int count;
58 struct me_uma uma;
59 struct me_hfs hfs;
60
61 printk(BIOS_INFO, "Intel ME early init\n");
62
63 /* Wait for ME UMA SIZE VALID bit to be set */
64 for (count = ME_RETRY; count > 0; --count) {
65 pci_read_dword_ptr(&uma, PCI_ME_UMA);
66 if (uma.valid)
67 break;
68 udelay(ME_DELAY);
69 }
70 if (!count) {
71 printk(BIOS_ERR, "ERROR: ME is not ready!\n");
72 return -1;
73 }
74
75 /* Check for valid firmware */
76 pci_read_dword_ptr(&hfs, PCI_ME_HFS);
77 if (hfs.fpt_bad) {
78 printk(BIOS_WARNING, "WARNING: ME has bad firmware\n");
79 return -1;
80 }
81
82 printk(BIOS_INFO, "Intel ME firmware is ready\n");
83 return 0;
84}
85
86int intel_early_me_uma_size(void)
87{
88 struct me_uma uma;
89
90 pci_read_dword_ptr(&uma, PCI_ME_UMA);
91 if (uma.valid) {
92 printk(BIOS_DEBUG, "ME: Requested %uMB UMA\n", uma.size);
93 return uma.size;
94 }
95
96 printk(BIOS_DEBUG, "ME: Invalid UMA size\n");
97 return 0;
98}
99
100static inline void set_global_reset(int enable)
101{
102 u32 etr3 = pci_read_config32(PCH_LPC_DEV, ETR3);
103
104 /* Clear CF9 Without Resume Well Reset Enable */
105 etr3 &= ~ETR3_CWORWRE;
106
107 /* CF9GR indicates a Global Reset */
108 if (enable)
109 etr3 |= ETR3_CF9GR;
110 else
111 etr3 &= ~ETR3_CF9GR;
112
113 pci_write_config32(PCH_LPC_DEV, ETR3, etr3);
114}
115
116int intel_early_me_init_done(u8 status)
117{
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700118 u8 reset, errorcode, opmode;
119 u16 reg16;
Stefan Reinauer8e073822012-04-04 00:07:22 +0200120 u32 mebase_l, mebase_h;
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700121 u32 millisec;
122 u32 hfs, me_fws2;
Stefan Reinauer8e073822012-04-04 00:07:22 +0200123 struct me_did did = {
124 .init_done = ME_INIT_DONE,
125 .status = status
126 };
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700127 u32 meDID;
128
129 hfs = (pci_read_config32(PCI_DEV(0, 0x16, 0), PCI_ME_HFS) & 0xff000) >> 12;
130
131 opmode = (hfs & 0xf0) >> 4;
132 errorcode = hfs & 0xf;
133
134 if (opmode != ME_HFS_MODE_NORMAL) {
135 printk(BIOS_NOTICE, "ME: Wrong mode : %d\n", opmode);
136 //return 0;
137 }
138 if (errorcode) {
139 printk(BIOS_NOTICE, "ME: HFS error : %d\n", errorcode);
140 //return 0;
141 }
142
143 me_fws2 = pci_read_config32(PCI_DEV(0, 0x16, 0), 0x48);
144 printk(BIOS_NOTICE, "ME: FWS2: 0x%x\n", me_fws2);
145 printk(BIOS_NOTICE, "ME: Bist in progress: 0x%x\n", me_fws2 & 0x1);
146 printk(BIOS_NOTICE, "ME: ICC Status : 0x%x\n", (me_fws2 & 0x6) >> 1);
147 printk(BIOS_NOTICE, "ME: Invoke MEBx : 0x%x\n", (me_fws2 & 0x8) >> 3);
148 printk(BIOS_NOTICE, "ME: CPU replaced : 0x%x\n", (me_fws2 & 0x10) >> 4);
149 printk(BIOS_NOTICE, "ME: MBP ready : 0x%x\n", (me_fws2 & 0x20) >> 5);
150 printk(BIOS_NOTICE, "ME: MFS failure : 0x%x\n", (me_fws2 & 0x40) >> 6);
151 printk(BIOS_NOTICE, "ME: Warm reset req : 0x%x\n", (me_fws2 & 0x80) >> 7);
152 printk(BIOS_NOTICE, "ME: CPU repl valid : 0x%x\n", (me_fws2 & 0x100) >> 8);
153 printk(BIOS_NOTICE, "ME: (Reserved) : 0x%x\n", (me_fws2 & 0x600) >> 9);
154 printk(BIOS_NOTICE, "ME: FW update req : 0x%x\n", (me_fws2 & 0x800) >> 11);
155 printk(BIOS_NOTICE, "ME: (Reserved) : 0x%x\n", (me_fws2 & 0xf000) >> 12);
156 printk(BIOS_NOTICE, "ME: Current state : 0x%x\n", (me_fws2 & 0xff0000) >> 16);
157 printk(BIOS_NOTICE, "ME: Current PM event: 0x%x\n", (me_fws2 & 0xf000000) >> 24);
158 printk(BIOS_NOTICE, "ME: Progress code : 0x%x\n", (me_fws2 & 0xf0000000) >> 28);
159
Elyes HAOUAS1bcd7fc2016-07-28 21:20:04 +0200160 // Poll CPU replaced for 50ms
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700161 millisec = 0;
162 while ((((me_fws2 & 0x100) >> 8) == 0) && millisec < 50) {
163 udelay(1000);
164 me_fws2 = pci_read_config32(PCI_DEV(0, 0x16, 0), 0x48);
165 millisec++;
166 }
167 if (millisec >= 50 || ((me_fws2 & 0x100) >> 8) == 0x0) {
168 printk(BIOS_NOTICE, "Waited long enough, or CPU was not replaced, continue...\n");
169 } else if ((me_fws2 & 0x100) == 0x100) {
170 if ((me_fws2 & 0x80) == 0x80) {
171 printk(BIOS_NOTICE, "CPU was replaced & warm reset required...\n");
Kyösti Mälkkid45114f2013-07-26 08:53:59 +0300172 reg16 = pci_read_config16(PCI_DEV(0, 31, 0), 0xa2) & ~0x80;
173 pci_write_config16(PCI_DEV(0, 31, 0), 0xa2, reg16);
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700174 set_global_reset(0);
175 outb(0x6, 0xcf9);
176 halt();
177 }
178
179 if (((me_fws2 & 0x10) == 0x10) && (me_fws2 & 0x80) == 0x00) {
180 printk(BIOS_NOTICE, "Full training required\n");
181 }
182 }
183
184 printk(BIOS_NOTICE, "PASSED! Tell ME that DRAM is ready\n");
Stefan Reinauer8e073822012-04-04 00:07:22 +0200185
186 /* MEBASE from MESEG_BASE[35:20] */
187 mebase_l = pci_read_config32(PCI_CPU_DEVICE, PCI_CPU_MEBASE_L);
188 mebase_h = pci_read_config32(PCI_CPU_DEVICE, PCI_CPU_MEBASE_H) & 0xf;
189 did.uma_base = (mebase_l >> 20) | (mebase_h << 12);
190
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700191 meDID = did.uma_base | (1 << 28);// | (1 << 23);
192 pci_write_config32(PCI_DEV(0, 0x16, 0), PCI_ME_H_GS, meDID);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200193
Stefan Reinauer8e073822012-04-04 00:07:22 +0200194 /* Must wait for ME acknowledgement */
Nathaniel Roachd7e0cb92017-09-09 19:59:07 +0800195 if (opmode == ME_HFS_MODE_DEBUG) {
196 printk(BIOS_NOTICE,
197 "ME: ME is reporting as disabled, "
198 "so not waiting for a response.\n");
199 } else {
200 timestamp_add_now(TS_ME_INFORM_DRAM_WAIT);
201 udelay(100);
202 millisec = 0;
203 do {
204 udelay(1000);
205 hfs = (pci_read_config32(
206 PCI_DEV(0, 0x16, 0), PCI_ME_HFS) & 0xfe000000)
207 >> 24;
208 millisec++;
209 } while ((((hfs & 0xf0) >> 4) != ME_HFS_BIOS_DRAM_ACK)
210 && (millisec <= 5000));
211 timestamp_add_now(TS_ME_INFORM_DRAM_DONE);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200212 }
Nathaniel Roachd7e0cb92017-09-09 19:59:07 +0800213
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700214
215 me_fws2 = pci_read_config32(PCI_DEV(0, 0x16, 0), 0x48);
216 printk(BIOS_NOTICE, "ME: FWS2: 0x%x\n", me_fws2);
217 printk(BIOS_NOTICE, "ME: Bist in progress: 0x%x\n", me_fws2 & 0x1);
218 printk(BIOS_NOTICE, "ME: ICC Status : 0x%x\n", (me_fws2 & 0x6) >> 1);
219 printk(BIOS_NOTICE, "ME: Invoke MEBx : 0x%x\n", (me_fws2 & 0x8) >> 3);
220 printk(BIOS_NOTICE, "ME: CPU replaced : 0x%x\n", (me_fws2 & 0x10) >> 4);
221 printk(BIOS_NOTICE, "ME: MBP ready : 0x%x\n", (me_fws2 & 0x20) >> 5);
222 printk(BIOS_NOTICE, "ME: MFS failure : 0x%x\n", (me_fws2 & 0x40) >> 6);
223 printk(BIOS_NOTICE, "ME: Warm reset req : 0x%x\n", (me_fws2 & 0x80) >> 7);
224 printk(BIOS_NOTICE, "ME: CPU repl valid : 0x%x\n", (me_fws2 & 0x100) >> 8);
225 printk(BIOS_NOTICE, "ME: (Reserved) : 0x%x\n", (me_fws2 & 0x600) >> 9);
226 printk(BIOS_NOTICE, "ME: FW update req : 0x%x\n", (me_fws2 & 0x800) >> 11);
227 printk(BIOS_NOTICE, "ME: (Reserved) : 0x%x\n", (me_fws2 & 0xf000) >> 12);
228 printk(BIOS_NOTICE, "ME: Current state : 0x%x\n", (me_fws2 & 0xff0000) >> 16);
229 printk(BIOS_NOTICE, "ME: Current PM event: 0x%x\n", (me_fws2 & 0xf000000) >> 24);
230 printk(BIOS_NOTICE, "ME: Progress code : 0x%x\n", (me_fws2 & 0xf0000000) >> 28);
231
Stefan Reinauer8e073822012-04-04 00:07:22 +0200232
233 /* Return the requested BIOS action */
234 printk(BIOS_NOTICE, "ME: Requested BIOS Action: %s\n",
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700235 me_ack_values[(hfs & 0xe) >> 1]);
Stefan Reinauer8e073822012-04-04 00:07:22 +0200236
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700237 reset = inb(0xcf9);
238 reset &= 0xf1;
239 switch ((hfs & 0xe) >> 1) {
240 case ME_HFS_ACK_NO_DID:
Stefan Reinauer8e073822012-04-04 00:07:22 +0200241 case ME_HFS_ACK_CONTINUE:
242 /* Continue to boot */
243 return 0;
244 case ME_HFS_ACK_RESET:
245 /* Non-power cycle reset */
246 set_global_reset(0);
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700247 reset |= 0x06;
Stefan Reinauer8e073822012-04-04 00:07:22 +0200248 break;
249 case ME_HFS_ACK_PWR_CYCLE:
250 /* Power cycle reset */
251 set_global_reset(0);
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700252 reset |= 0x0e;
Stefan Reinauer8e073822012-04-04 00:07:22 +0200253 break;
254 case ME_HFS_ACK_GBL_RESET:
255 /* Global reset */
256 set_global_reset(1);
Alexandru Gagniucecf2eb42015-09-28 21:39:12 -0700257 reset |= 0x0e;
Stefan Reinauer8e073822012-04-04 00:07:22 +0200258 break;
259 case ME_HFS_ACK_S3:
260 case ME_HFS_ACK_S4:
261 case ME_HFS_ACK_S5:
262 break;
263 }
264
265 /* Perform the requested reset */
266 if (reset) {
267 outb(reset, 0xcf9);
Patrick Georgi546953c2014-11-29 10:38:17 +0100268 halt();
Stefan Reinauer8e073822012-04-04 00:07:22 +0200269 }
270 return -1;
271}