Debian Codegraph @

src/southbridge/intel/bd82x6x/early_me.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <arch/io.h>
4 #include <device/pci_ops.h>
5 #include <cf9_reset.h>
6 #include <console/console.h>
7 #include <delay.h>
8 #include <device/pci_def.h>
9 #include <halt.h>
10 #include <southbridge/intel/common/me.h>
11 #include <timestamp.h>
12 #include "me.h"
13 #include "pch.h"
14
15 static const char *me_ack_values[] = {
16 [ME_HFS_ACK_NO_DID] = "No DID Ack received",
17 [ME_HFS_ACK_RESET] = "Non-power cycle reset",
18 [ME_HFS_ACK_PWR_CYCLE] = "Power cycle reset",
19 [ME_HFS_ACK_S3] = "Go to S3",
20 [ME_HFS_ACK_S4] = "Go to S4",
21 [ME_HFS_ACK_S5] = "Go to S5",
22 [ME_HFS_ACK_GBL_RESET] = "Global Reset",
23 [ME_HFS_ACK_CONTINUE] = "Continue to boot"
24 };
25
26 void intel_early_me_status(void)
27 {
28 union me_hfs hfs;
29 union me_gmes gmes;
30 u32 id = pci_read_config32(PCH_ME_DEV, PCI_VENDOR_ID);
31
32 if ((id == 0xffffffff) || (id == 0x00000000) ||
33 (id == 0x0000ffff) || (id == 0xffff0000)) {
34 printk(BIOS_DEBUG, "Missing Intel ME PCI device.\n");
35 } else {
36 hfs.raw = pci_read_config32(PCH_ME_DEV, PCI_ME_HFS);
37 gmes.raw = pci_read_config32(PCH_ME_DEV, PCI_ME_GMES);
38
39 intel_me_status(&hfs, &gmes);
40 }
41 }
42
43 int intel_early_me_init(void)
44 {
45 int count;
46 union me_uma uma;
47 union me_hfs hfs;
48
49 printk(BIOS_INFO, "Intel ME early init\n");
50
51 /* Wait for ME UMA SIZE VALID bit to be set */
52 for (count = ME_RETRY; count > 0; --count) {
53 uma.raw = pci_read_config32(PCH_ME_DEV, PCI_ME_UMA);
54 if (uma.valid)
55 break;
56 udelay(ME_DELAY);
57 }
58 if (!count) {
59 printk(BIOS_ERR, "ME is not ready!\n");
60 return -1;
61 }
62
63 /* Check for valid firmware */
64 hfs.raw = pci_read_config32(PCH_ME_DEV, PCI_ME_HFS);
65 if (hfs.fpt_bad) {
66 printk(BIOS_WARNING, "ME has bad firmware\n");
67 return -1;
68 }
69
70 printk(BIOS_INFO, "Intel ME firmware is ready\n");
71 return 0;
72 }
73
74 int intel_early_me_uma_size(void)
75 {
76 union me_uma uma;
77
78 uma.raw = pci_read_config32(PCH_ME_DEV, PCI_ME_UMA);
79 if (uma.valid) {
80 printk(BIOS_DEBUG, "ME: Requested %uMB UMA\n", uma.size);
81 return uma.size;
82 }
83
84 printk(BIOS_DEBUG, "ME: Invalid UMA size\n");
85 return 0;
86 }
87
88 /**
89 * Check if ME reports that CPU has been replaced.
90 *
91 * @return TRUE when CPU was replaced and full
92 * memory training is required.
93 */
94 bool intel_early_me_cpu_replaced(void)
95 {
96 u32 millisec;
97 union me_gmes gmes;
98
99 gmes.raw = pci_read_config32(PCH_ME_DEV, PCI_ME_GMES);
100
101 /*
102 * Poll CPU replaced status until 50 ms have elapsed since boot.
103 * The ME FW should've had enough time to wake up at this point.
104 */
105 millisec = get_us_since_boot() / 1000;
106 while (!gmes.cpu_replaced_valid && millisec < 50) {
107 udelay(1000);
108 gmes.raw = pci_read_config32(PCH_ME_DEV, PCI_ME_GMES);
109 millisec++;
110 }
111
112 if (gmes.cpu_replaced_valid) {
113 if (gmes.warm_rst_req_for_df) {
114 /*
115 * DF (Dynamic Fusing) is when the ME updates the CAPID0
116 * register in the host bridge depending on the PCH SKU.
117 */
118 printk(BIOS_NOTICE, "CPU was replaced & warm reset required...\n");
119
120 /* Indicate DRAM init not done for MRC */
121 pci_and_config8(PCH_LPC_DEV, GEN_PMCON_2, 0x7f);
122 set_global_reset(0);
123 system_reset();
124 return true;
125 }
126
127 if (gmes.cpu_replaced_sts) {
128 printk(BIOS_NOTICE, "Full memory training required\n");
129 return true;
130 }
131 } else {
132 /* CPU replaced is still not valid (bad ME FW?) */
133 printk(BIOS_NOTICE, "CPU replaced is not valid, assuming CPU was not replaced...\n");
134 }
135 return false;
136 }
137
138 int intel_early_me_init_done(u8 status)
139 {
140 u8 reset, errorcode, opmode;
141 u32 mebase_l, mebase_h;
142 u32 millisec;
143 u32 hfs, me_fws2;
144 union me_did did = {
145 .init_done = ME_INIT_DONE,
146 .status = status
147 };
148 u32 meDID;
149
150 hfs = (pci_read_config32(PCH_ME_DEV, PCI_ME_HFS) & 0xff000) >> 12;
151
152 opmode = (hfs & 0xf0) >> 4;
153 errorcode = hfs & 0xf;
154
155 if (opmode != ME_HFS_MODE_NORMAL) {
156 printk(BIOS_NOTICE, "ME: Wrong mode : %d\n", opmode);
157 //return 0;
158 }
159 if (errorcode) {
160 printk(BIOS_NOTICE, "ME: HFS error : %d\n", errorcode);
161 //return 0;
162 }
163
164 me_fws2 = pci_read_config32(PCH_ME_DEV, PCI_ME_GMES);
165 printk(BIOS_NOTICE, "ME: FWS2: 0x%x\n", me_fws2);
166 printk(BIOS_NOTICE, "ME: Bist in progress: 0x%x\n", me_fws2 & 0x1);
167 printk(BIOS_NOTICE, "ME: ICC Status : 0x%x\n", (me_fws2 & 0x6) >> 1);
168 printk(BIOS_NOTICE, "ME: Invoke MEBx : 0x%x\n", (me_fws2 & 0x8) >> 3);
169 printk(BIOS_NOTICE, "ME: CPU replaced : 0x%x\n", (me_fws2 & 0x10) >> 4);
170 printk(BIOS_NOTICE, "ME: MBP ready : 0x%x\n", (me_fws2 & 0x20) >> 5);
171 printk(BIOS_NOTICE, "ME: MFS failure : 0x%x\n", (me_fws2 & 0x40) >> 6);
172 printk(BIOS_NOTICE, "ME: Warm reset req : 0x%x\n", (me_fws2 & 0x80) >> 7);
173 printk(BIOS_NOTICE, "ME: CPU repl valid : 0x%x\n", (me_fws2 & 0x100) >> 8);
174 printk(BIOS_NOTICE, "ME: (Reserved) : 0x%x\n", (me_fws2 & 0x600) >> 9);
175 printk(BIOS_NOTICE, "ME: FW update req : 0x%x\n", (me_fws2 & 0x800) >> 11);
176 printk(BIOS_NOTICE, "ME: (Reserved) : 0x%x\n", (me_fws2 & 0xf000) >> 12);
177 printk(BIOS_NOTICE, "ME: Current state : 0x%x\n", (me_fws2 & 0xff0000) >> 16);
178 printk(BIOS_NOTICE, "ME: Current PM event: 0x%x\n", (me_fws2 & 0xf000000) >> 24);
179 printk(BIOS_NOTICE, "ME: Progress code : 0x%x\n", (me_fws2 & 0xf0000000) >> 28);
180
181 printk(BIOS_NOTICE, "PASSED! Tell ME that DRAM is ready\n");
182
183 /* MEBASE from MESEG_BASE[35:20] */
184 mebase_l = pci_read_config32(PCI_CPU_DEVICE, PCI_CPU_MEBASE_L);
185 mebase_h = pci_read_config32(PCI_CPU_DEVICE, PCI_CPU_MEBASE_H) & 0xf;
186 did.uma_base = (mebase_l >> 20) | (mebase_h << 12);
187
188 meDID = did.uma_base | (1 << 28);// | (1 << 23);
189 pci_write_config32(PCH_ME_DEV, PCI_ME_H_GS, meDID);
190
191 /* Must wait for ME acknowledgement */
192 if (opmode == ME_HFS_MODE_DEBUG) {
193 printk(BIOS_NOTICE,
194 "ME: ME is reporting as disabled, "
195 "so not waiting for a response.\n");
196 } else {
197 timestamp_add_now(TS_ME_INFORM_DRAM_START);
198 udelay(100);
199 millisec = 0;
200 do {
201 udelay(1000);
202 hfs = (pci_read_config32(
203 PCH_ME_DEV, PCI_ME_HFS) & 0xfe000000)
204 >> 24;
205 millisec++;
206 } while ((((hfs & 0xf0) >> 4) != ME_HFS_BIOS_DRAM_ACK)
207 && (millisec <= 5000));
208 timestamp_add_now(TS_ME_INFORM_DRAM_END);
209 }
210
211 me_fws2 = pci_read_config32(PCH_ME_DEV, PCI_ME_GMES);
212 printk(BIOS_NOTICE, "ME: FWS2: 0x%x\n", me_fws2);
213 printk(BIOS_NOTICE, "ME: Bist in progress: 0x%x\n", me_fws2 & 0x1);
214 printk(BIOS_NOTICE, "ME: ICC Status : 0x%x\n", (me_fws2 & 0x6) >> 1);
215 printk(BIOS_NOTICE, "ME: Invoke MEBx : 0x%x\n", (me_fws2 & 0x8) >> 3);
216 printk(BIOS_NOTICE, "ME: CPU replaced : 0x%x\n", (me_fws2 & 0x10) >> 4);
217 printk(BIOS_NOTICE, "ME: MBP ready : 0x%x\n", (me_fws2 & 0x20) >> 5);
218 printk(BIOS_NOTICE, "ME: MFS failure : 0x%x\n", (me_fws2 & 0x40) >> 6);
219 printk(BIOS_NOTICE, "ME: Warm reset req : 0x%x\n", (me_fws2 & 0x80) >> 7);
220 printk(BIOS_NOTICE, "ME: CPU repl valid : 0x%x\n", (me_fws2 & 0x100) >> 8);
221 printk(BIOS_NOTICE, "ME: (Reserved) : 0x%x\n", (me_fws2 & 0x600) >> 9);
222 printk(BIOS_NOTICE, "ME: FW update req : 0x%x\n", (me_fws2 & 0x800) >> 11);
223 printk(BIOS_NOTICE, "ME: (Reserved) : 0x%x\n", (me_fws2 & 0xf000) >> 12);
224 printk(BIOS_NOTICE, "ME: Current state : 0x%x\n", (me_fws2 & 0xff0000) >> 16);
225 printk(BIOS_NOTICE, "ME: Current PM event: 0x%x\n", (me_fws2 & 0xf000000) >> 24);
226 printk(BIOS_NOTICE, "ME: Progress code : 0x%x\n", (me_fws2 & 0xf0000000) >> 28);
227
228 /* Return the requested BIOS action */
229 printk(BIOS_NOTICE, "ME: Requested BIOS Action: %s\n",
230 me_ack_values[(hfs & 0xe) >> 1]);
231
232 reset = inb(0xcf9);
233 reset &= 0xf1;
234 switch ((hfs & 0xe) >> 1) {
235 case ME_HFS_ACK_NO_DID:
236 case ME_HFS_ACK_CONTINUE:
237 /* Continue to boot */
238 return 0;
239 case ME_HFS_ACK_RESET:
240 /* Non-power cycle reset */
241 set_global_reset(0);
242 reset |= 0x06;
243 break;
244 case ME_HFS_ACK_PWR_CYCLE:
245 /* Power cycle reset */
246 set_global_reset(0);
247 reset |= 0x0e;
248 break;
249 case ME_HFS_ACK_GBL_RESET:
250 /* Global reset */
251 set_global_reset(1);
252 reset |= 0x0e;
253 break;
254 case ME_HFS_ACK_S3:
255 case ME_HFS_ACK_S4:
256 case ME_HFS_ACK_S5:
257 break;
258 }
259
260 /* Perform the requested reset */
261 if (reset) {
262 outb(reset, 0xcf9);
263 halt();
264 }
265 return -1;
266 }