Angel Pons | 182dbde | 2020-04-02 23:49:05 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 2 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 3 | #include <arch/io.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 4 | #include <device/pci_ops.h> |
Elyes HAOUAS | 46c5807 | 2019-04-28 18:17:17 +0200 | [diff] [blame] | 5 | #include <cf9_reset.h> |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 6 | #include <console/console.h> |
| 7 | #include <delay.h> |
Nicola Corna | 14604da | 2018-05-15 17:15:03 +0200 | [diff] [blame] | 8 | #include <device/pci_def.h> |
Patrick Georgi | 546953c | 2014-11-29 10:38:17 +0100 | [diff] [blame] | 9 | #include <halt.h> |
Angel Pons | 20a609f | 2021-02-06 23:22:33 +0100 | [diff] [blame] | 10 | #include <southbridge/intel/common/me.h> |
Nathaniel Roach | 52f0871 | 2017-09-09 19:58:08 +0800 | [diff] [blame] | 11 | #include <timestamp.h> |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 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 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 26 | void intel_early_me_status(void) |
| 27 | { |
Angel Pons | 3f7bb7d | 2021-01-27 13:03:20 +0100 | [diff] [blame] | 28 | union me_hfs hfs; |
| 29 | union me_gmes gmes; |
Nicola Corna | 14604da | 2018-05-15 17:15:03 +0200 | [diff] [blame] | 30 | u32 id = pci_read_config32(PCH_ME_DEV, PCI_VENDOR_ID); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 31 | |
Nicola Corna | 14604da | 2018-05-15 17:15:03 +0200 | [diff] [blame] | 32 | if ((id == 0xffffffff) || (id == 0x00000000) || |
| 33 | (id == 0x0000ffff) || (id == 0xffff0000)) { |
| 34 | printk(BIOS_DEBUG, "Missing Intel ME PCI device.\n"); |
| 35 | } else { |
Angel Pons | 3f7bb7d | 2021-01-27 13:03:20 +0100 | [diff] [blame] | 36 | hfs.raw = pci_read_config32(PCH_ME_DEV, PCI_ME_HFS); |
| 37 | gmes.raw = pci_read_config32(PCH_ME_DEV, PCI_ME_GMES); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 38 | |
Nicola Corna | 14604da | 2018-05-15 17:15:03 +0200 | [diff] [blame] | 39 | intel_me_status(&hfs, &gmes); |
| 40 | } |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | int intel_early_me_init(void) |
| 44 | { |
| 45 | int count; |
Angel Pons | 3f7bb7d | 2021-01-27 13:03:20 +0100 | [diff] [blame] | 46 | union me_uma uma; |
| 47 | union me_hfs hfs; |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 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) { |
Angel Pons | 3f7bb7d | 2021-01-27 13:03:20 +0100 | [diff] [blame] | 53 | uma.raw = pci_read_config32(PCH_ME_DEV, PCI_ME_UMA); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 54 | if (uma.valid) |
| 55 | break; |
| 56 | udelay(ME_DELAY); |
| 57 | } |
| 58 | if (!count) { |
Julius Werner | e966595 | 2022-01-21 17:06:20 -0800 | [diff] [blame] | 59 | printk(BIOS_ERR, "ME is not ready!\n"); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 60 | return -1; |
| 61 | } |
| 62 | |
| 63 | /* Check for valid firmware */ |
Angel Pons | 3f7bb7d | 2021-01-27 13:03:20 +0100 | [diff] [blame] | 64 | hfs.raw = pci_read_config32(PCH_ME_DEV, PCI_ME_HFS); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 65 | if (hfs.fpt_bad) { |
Julius Werner | e966595 | 2022-01-21 17:06:20 -0800 | [diff] [blame] | 66 | printk(BIOS_WARNING, "ME has bad firmware\n"); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 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 | { |
Angel Pons | 3f7bb7d | 2021-01-27 13:03:20 +0100 | [diff] [blame] | 76 | union me_uma uma; |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 77 | |
Angel Pons | 3f7bb7d | 2021-01-27 13:03:20 +0100 | [diff] [blame] | 78 | uma.raw = pci_read_config32(PCH_ME_DEV, PCI_ME_UMA); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 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 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 88 | int intel_early_me_init_done(u8 status) |
| 89 | { |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 90 | u8 reset, errorcode, opmode; |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 91 | u32 mebase_l, mebase_h; |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 92 | u32 millisec; |
| 93 | u32 hfs, me_fws2; |
Angel Pons | 3f7bb7d | 2021-01-27 13:03:20 +0100 | [diff] [blame] | 94 | union me_did did = { |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 95 | .init_done = ME_INIT_DONE, |
| 96 | .status = status |
| 97 | }; |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 98 | u32 meDID; |
| 99 | |
Angel Pons | ec2ee18 | 2021-01-27 13:08:59 +0100 | [diff] [blame] | 100 | hfs = (pci_read_config32(PCH_ME_DEV, PCI_ME_HFS) & 0xff000) >> 12; |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 101 | |
| 102 | opmode = (hfs & 0xf0) >> 4; |
| 103 | errorcode = hfs & 0xf; |
| 104 | |
| 105 | if (opmode != ME_HFS_MODE_NORMAL) { |
| 106 | printk(BIOS_NOTICE, "ME: Wrong mode : %d\n", opmode); |
| 107 | //return 0; |
| 108 | } |
| 109 | if (errorcode) { |
| 110 | printk(BIOS_NOTICE, "ME: HFS error : %d\n", errorcode); |
| 111 | //return 0; |
| 112 | } |
| 113 | |
Angel Pons | ec2ee18 | 2021-01-27 13:08:59 +0100 | [diff] [blame] | 114 | me_fws2 = pci_read_config32(PCH_ME_DEV, PCI_ME_GMES); |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 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); |
| 130 | |
Angel Pons | ec2ee18 | 2021-01-27 13:08:59 +0100 | [diff] [blame] | 131 | /* Poll CPU replaced for 50ms */ |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 132 | millisec = 0; |
| 133 | while ((((me_fws2 & 0x100) >> 8) == 0) && millisec < 50) { |
| 134 | udelay(1000); |
Angel Pons | ec2ee18 | 2021-01-27 13:08:59 +0100 | [diff] [blame] | 135 | me_fws2 = pci_read_config32(PCH_ME_DEV, PCI_ME_GMES); |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 136 | millisec++; |
| 137 | } |
| 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"); |
Angel Pons | ec2ee18 | 2021-01-27 13:08:59 +0100 | [diff] [blame] | 143 | pci_and_config16(PCH_LPC_DEV, GEN_PMCON_2, ~0x80); |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 144 | set_global_reset(0); |
Elyes HAOUAS | 46c5807 | 2019-04-28 18:17:17 +0200 | [diff] [blame] | 145 | system_reset(); |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | if (((me_fws2 & 0x10) == 0x10) && (me_fws2 & 0x80) == 0x00) { |
| 149 | printk(BIOS_NOTICE, "Full training required\n"); |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | printk(BIOS_NOTICE, "PASSED! Tell ME that DRAM is ready\n"); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 154 | |
| 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); |
| 159 | |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 160 | meDID = did.uma_base | (1 << 28);// | (1 << 23); |
Angel Pons | ec2ee18 | 2021-01-27 13:08:59 +0100 | [diff] [blame] | 161 | pci_write_config32(PCH_ME_DEV, PCI_ME_H_GS, meDID); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 162 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 163 | /* Must wait for ME acknowledgement */ |
Nathaniel Roach | d7e0cb9 | 2017-09-09 19:59:07 +0800 | [diff] [blame] | 164 | if (opmode == ME_HFS_MODE_DEBUG) { |
| 165 | printk(BIOS_NOTICE, |
| 166 | "ME: ME is reporting as disabled, " |
| 167 | "so not waiting for a response.\n"); |
| 168 | } else { |
Jakub Czapiga | ad6157e | 2022-02-15 11:50:31 +0100 | [diff] [blame] | 169 | timestamp_add_now(TS_ME_INFORM_DRAM_START); |
Nathaniel Roach | d7e0cb9 | 2017-09-09 19:59:07 +0800 | [diff] [blame] | 170 | udelay(100); |
| 171 | millisec = 0; |
| 172 | do { |
| 173 | udelay(1000); |
| 174 | hfs = (pci_read_config32( |
Angel Pons | ec2ee18 | 2021-01-27 13:08:59 +0100 | [diff] [blame] | 175 | PCH_ME_DEV, PCI_ME_HFS) & 0xfe000000) |
Nathaniel Roach | d7e0cb9 | 2017-09-09 19:59:07 +0800 | [diff] [blame] | 176 | >> 24; |
| 177 | millisec++; |
| 178 | } while ((((hfs & 0xf0) >> 4) != ME_HFS_BIOS_DRAM_ACK) |
| 179 | && (millisec <= 5000)); |
Jakub Czapiga | ad6157e | 2022-02-15 11:50:31 +0100 | [diff] [blame] | 180 | timestamp_add_now(TS_ME_INFORM_DRAM_END); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 181 | } |
Nathaniel Roach | d7e0cb9 | 2017-09-09 19:59:07 +0800 | [diff] [blame] | 182 | |
Angel Pons | ec2ee18 | 2021-01-27 13:08:59 +0100 | [diff] [blame] | 183 | me_fws2 = pci_read_config32(PCH_ME_DEV, PCI_ME_GMES); |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 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); |
| 199 | |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 200 | /* Return the requested BIOS action */ |
| 201 | printk(BIOS_NOTICE, "ME: Requested BIOS Action: %s\n", |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 202 | me_ack_values[(hfs & 0xe) >> 1]); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 203 | |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 204 | reset = inb(0xcf9); |
| 205 | reset &= 0xf1; |
| 206 | switch ((hfs & 0xe) >> 1) { |
| 207 | case ME_HFS_ACK_NO_DID: |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 208 | case ME_HFS_ACK_CONTINUE: |
| 209 | /* Continue to boot */ |
| 210 | return 0; |
| 211 | case ME_HFS_ACK_RESET: |
| 212 | /* Non-power cycle reset */ |
| 213 | set_global_reset(0); |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 214 | reset |= 0x06; |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 215 | break; |
| 216 | case ME_HFS_ACK_PWR_CYCLE: |
| 217 | /* Power cycle reset */ |
| 218 | set_global_reset(0); |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 219 | reset |= 0x0e; |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 220 | break; |
| 221 | case ME_HFS_ACK_GBL_RESET: |
| 222 | /* Global reset */ |
| 223 | set_global_reset(1); |
Alexandru Gagniuc | ecf2eb4 | 2015-09-28 21:39:12 -0700 | [diff] [blame] | 224 | reset |= 0x0e; |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 225 | break; |
| 226 | case ME_HFS_ACK_S3: |
| 227 | case ME_HFS_ACK_S4: |
| 228 | case ME_HFS_ACK_S5: |
| 229 | break; |
| 230 | } |
| 231 | |
| 232 | /* Perform the requested reset */ |
| 233 | if (reset) { |
| 234 | outb(reset, 0xcf9); |
Patrick Georgi | 546953c | 2014-11-29 10:38:17 +0100 | [diff] [blame] | 235 | halt(); |
Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame] | 236 | } |
| 237 | return -1; |
| 238 | } |