1 /* SPDX-License-Identifier: GPL-2.0-only */
4 #include <device/pci_ops.h>
6 #include <console/console.h>
8 #include <device/pci_def.h>
10 #include <southbridge/intel/common/me.h>
11 #include <timestamp.h>
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"
26 void intel_early_me_status(void)
30 u32 id
= pci_read_config32(PCH_ME_DEV
, PCI_VENDOR_ID
);
32 if ((id
== 0xffffffff) || (id
== 0x00000000) ||
33 (id
== 0x0000ffff) || (id
== 0xffff0000)) {
34 printk(BIOS_DEBUG
, "Missing Intel ME PCI device.\n");
36 hfs
.raw
= pci_read_config32(PCH_ME_DEV
, PCI_ME_HFS
);
37 gmes
.raw
= pci_read_config32(PCH_ME_DEV
, PCI_ME_GMES
);
39 intel_me_status(&hfs
, &gmes
);
43 int intel_early_me_init(void)
49 printk(BIOS_INFO
, "Intel ME early init\n");
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
);
59 printk(BIOS_ERR
, "ME is not ready!\n");
63 /* Check for valid firmware */
64 hfs
.raw
= pci_read_config32(PCH_ME_DEV
, PCI_ME_HFS
);
66 printk(BIOS_WARNING
, "ME has bad firmware\n");
70 printk(BIOS_INFO
, "Intel ME firmware is ready\n");
74 int intel_early_me_uma_size(void)
78 uma
.raw
= pci_read_config32(PCH_ME_DEV
, PCI_ME_UMA
);
80 printk(BIOS_DEBUG
, "ME: Requested %uMB UMA\n", uma
.size
);
84 printk(BIOS_DEBUG
, "ME: Invalid UMA size\n");
88 int intel_early_me_init_done(u8 status
)
90 u8 reset
, errorcode
, opmode
;
91 u32 mebase_l
, mebase_h
;
95 .init_done
= ME_INIT_DONE
,
100 hfs
= (pci_read_config32(PCH_ME_DEV
, PCI_ME_HFS
) & 0xff000) >> 12;
102 opmode
= (hfs
& 0xf0) >> 4;
103 errorcode
= hfs
& 0xf;
105 if (opmode
!= ME_HFS_MODE_NORMAL
) {
106 printk(BIOS_NOTICE
, "ME: Wrong mode : %d\n", opmode
);
110 printk(BIOS_NOTICE
, "ME: HFS error : %d\n", errorcode
);
114 me_fws2
= pci_read_config32(PCH_ME_DEV
, PCI_ME_GMES
);
115 printk(BIOS_NOTICE
, "ME: FWS2: 0x%x\n", me_fws2
);
116 printk(BIOS_NOTICE
, "ME: Bist in progress: 0x%x\n", me_fws2
& 0x1);
117 printk(BIOS_NOTICE
, "ME: ICC Status : 0x%x\n", (me_fws2
& 0x6) >> 1);
118 printk(BIOS_NOTICE
, "ME: Invoke MEBx : 0x%x\n", (me_fws2
& 0x8) >> 3);
119 printk(BIOS_NOTICE
, "ME: CPU replaced : 0x%x\n", (me_fws2
& 0x10) >> 4);
120 printk(BIOS_NOTICE
, "ME: MBP ready : 0x%x\n", (me_fws2
& 0x20) >> 5);
121 printk(BIOS_NOTICE
, "ME: MFS failure : 0x%x\n", (me_fws2
& 0x40) >> 6);
122 printk(BIOS_NOTICE
, "ME: Warm reset req : 0x%x\n", (me_fws2
& 0x80) >> 7);
123 printk(BIOS_NOTICE
, "ME: CPU repl valid : 0x%x\n", (me_fws2
& 0x100) >> 8);
124 printk(BIOS_NOTICE
, "ME: (Reserved) : 0x%x\n", (me_fws2
& 0x600) >> 9);
125 printk(BIOS_NOTICE
, "ME: FW update req : 0x%x\n", (me_fws2
& 0x800) >> 11);
126 printk(BIOS_NOTICE
, "ME: (Reserved) : 0x%x\n", (me_fws2
& 0xf000) >> 12);
127 printk(BIOS_NOTICE
, "ME: Current state : 0x%x\n", (me_fws2
& 0xff0000) >> 16);
128 printk(BIOS_NOTICE
, "ME: Current PM event: 0x%x\n", (me_fws2
& 0xf000000) >> 24);
129 printk(BIOS_NOTICE
, "ME: Progress code : 0x%x\n", (me_fws2
& 0xf0000000) >> 28);
131 /* Poll CPU replaced for 50ms */
133 while ((((me_fws2
& 0x100) >> 8) == 0) && millisec
< 50) {
135 me_fws2
= pci_read_config32(PCH_ME_DEV
, PCI_ME_GMES
);
138 if (millisec
>= 50 || ((me_fws2
& 0x100) >> 8) == 0x0) {
139 printk(BIOS_NOTICE
, "Waited long enough, or CPU was not replaced, continue...\n");
140 } else if ((me_fws2
& 0x100) == 0x100) {
141 if ((me_fws2
& 0x80) == 0x80) {
142 printk(BIOS_NOTICE
, "CPU was replaced & warm reset required...\n");
143 pci_and_config16(PCH_LPC_DEV
, GEN_PMCON_2
, ~0x80);
148 if (((me_fws2
& 0x10) == 0x10) && (me_fws2
& 0x80) == 0x00) {
149 printk(BIOS_NOTICE
, "Full training required\n");
153 printk(BIOS_NOTICE
, "PASSED! Tell ME that DRAM is ready\n");
155 /* MEBASE from MESEG_BASE[35:20] */
156 mebase_l
= pci_read_config32(PCI_CPU_DEVICE
, PCI_CPU_MEBASE_L
);
157 mebase_h
= pci_read_config32(PCI_CPU_DEVICE
, PCI_CPU_MEBASE_H
) & 0xf;
158 did
.uma_base
= (mebase_l
>> 20) | (mebase_h
<< 12);
160 meDID
= did
.uma_base
| (1 << 28);// | (1 << 23);
161 pci_write_config32(PCH_ME_DEV
, PCI_ME_H_GS
, meDID
);
163 /* Must wait for ME acknowledgement */
164 if (opmode
== ME_HFS_MODE_DEBUG
) {
166 "ME: ME is reporting as disabled, "
167 "so not waiting for a response.\n");
169 timestamp_add_now(TS_ME_INFORM_DRAM_START
);
174 hfs
= (pci_read_config32(
175 PCH_ME_DEV
, PCI_ME_HFS
) & 0xfe000000)
178 } while ((((hfs
& 0xf0) >> 4) != ME_HFS_BIOS_DRAM_ACK
)
179 && (millisec
<= 5000));
180 timestamp_add_now(TS_ME_INFORM_DRAM_END
);
183 me_fws2
= pci_read_config32(PCH_ME_DEV
, PCI_ME_GMES
);
184 printk(BIOS_NOTICE
, "ME: FWS2: 0x%x\n", me_fws2
);
185 printk(BIOS_NOTICE
, "ME: Bist in progress: 0x%x\n", me_fws2
& 0x1);
186 printk(BIOS_NOTICE
, "ME: ICC Status : 0x%x\n", (me_fws2
& 0x6) >> 1);
187 printk(BIOS_NOTICE
, "ME: Invoke MEBx : 0x%x\n", (me_fws2
& 0x8) >> 3);
188 printk(BIOS_NOTICE
, "ME: CPU replaced : 0x%x\n", (me_fws2
& 0x10) >> 4);
189 printk(BIOS_NOTICE
, "ME: MBP ready : 0x%x\n", (me_fws2
& 0x20) >> 5);
190 printk(BIOS_NOTICE
, "ME: MFS failure : 0x%x\n", (me_fws2
& 0x40) >> 6);
191 printk(BIOS_NOTICE
, "ME: Warm reset req : 0x%x\n", (me_fws2
& 0x80) >> 7);
192 printk(BIOS_NOTICE
, "ME: CPU repl valid : 0x%x\n", (me_fws2
& 0x100) >> 8);
193 printk(BIOS_NOTICE
, "ME: (Reserved) : 0x%x\n", (me_fws2
& 0x600) >> 9);
194 printk(BIOS_NOTICE
, "ME: FW update req : 0x%x\n", (me_fws2
& 0x800) >> 11);
195 printk(BIOS_NOTICE
, "ME: (Reserved) : 0x%x\n", (me_fws2
& 0xf000) >> 12);
196 printk(BIOS_NOTICE
, "ME: Current state : 0x%x\n", (me_fws2
& 0xff0000) >> 16);
197 printk(BIOS_NOTICE
, "ME: Current PM event: 0x%x\n", (me_fws2
& 0xf000000) >> 24);
198 printk(BIOS_NOTICE
, "ME: Progress code : 0x%x\n", (me_fws2
& 0xf0000000) >> 28);
200 /* Return the requested BIOS action */
201 printk(BIOS_NOTICE
, "ME: Requested BIOS Action: %s\n",
202 me_ack_values
[(hfs
& 0xe) >> 1]);
206 switch ((hfs
& 0xe) >> 1) {
207 case ME_HFS_ACK_NO_DID
:
208 case ME_HFS_ACK_CONTINUE
:
209 /* Continue to boot */
211 case ME_HFS_ACK_RESET
:
212 /* Non-power cycle reset */
216 case ME_HFS_ACK_PWR_CYCLE
:
217 /* Power cycle reset */
221 case ME_HFS_ACK_GBL_RESET
:
232 /* Perform the requested reset */