blob: ac868025f8edd17c479878682970a3badaa5a772 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Simon Glass268eefd2014-11-12 22:42:28 -07002/*
3 * From Coreboot src/southbridge/intel/bd82x6x/early_me.c
4 *
5 * Copyright (C) 2011 The Chromium OS Authors. All rights reserved.
Simon Glass268eefd2014-11-12 22:42:28 -07006 */
7
Simon Glass37a91ff2016-01-17 16:11:50 -07008#include <dm.h>
Simon Glass268eefd2014-11-12 22:42:28 -07009#include <errno.h>
Simon Glass0f2af882020-05-10 11:40:05 -060010#include <log.h>
Bin Mengaf5b8d22018-07-19 03:07:33 -070011#include <sysreset.h>
Simon Glass268eefd2014-11-12 22:42:28 -070012#include <asm/pci.h>
Simon Glass43a50342016-01-17 16:11:58 -070013#include <asm/cpu.h>
Simon Glass268eefd2014-11-12 22:42:28 -070014#include <asm/processor.h>
15#include <asm/arch/me.h>
16#include <asm/arch/pch.h>
17#include <asm/io.h>
Simon Glassdbd79542020-05-10 11:40:11 -060018#include <linux/delay.h>
Simon Glass268eefd2014-11-12 22:42:28 -070019
20static const char *const me_ack_values[] = {
21 [ME_HFS_ACK_NO_DID] = "No DID Ack received",
22 [ME_HFS_ACK_RESET] = "Non-power cycle reset",
23 [ME_HFS_ACK_PWR_CYCLE] = "Power cycle reset",
24 [ME_HFS_ACK_S3] = "Go to S3",
25 [ME_HFS_ACK_S4] = "Go to S4",
26 [ME_HFS_ACK_S5] = "Go to S5",
27 [ME_HFS_ACK_GBL_RESET] = "Global Reset",
28 [ME_HFS_ACK_CONTINUE] = "Continue to boot"
29};
30
Simon Glass37a91ff2016-01-17 16:11:50 -070031int intel_early_me_init(struct udevice *me_dev)
Simon Glass268eefd2014-11-12 22:42:28 -070032{
33 int count;
34 struct me_uma uma;
35 struct me_hfs hfs;
36
37 debug("Intel ME early init\n");
38
39 /* Wait for ME UMA SIZE VALID bit to be set */
40 for (count = ME_RETRY; count > 0; --count) {
Simon Glass37a91ff2016-01-17 16:11:50 -070041 pci_read_dword_ptr(me_dev, &uma, PCI_ME_UMA);
Simon Glass268eefd2014-11-12 22:42:28 -070042 if (uma.valid)
43 break;
44 udelay(ME_DELAY);
45 }
46 if (!count) {
47 printf("ERROR: ME is not ready!\n");
48 return -EBUSY;
49 }
50
51 /* Check for valid firmware */
Simon Glass37a91ff2016-01-17 16:11:50 -070052 pci_read_dword_ptr(me_dev, &hfs, PCI_ME_HFS);
Simon Glass268eefd2014-11-12 22:42:28 -070053 if (hfs.fpt_bad) {
54 printf("WARNING: ME has bad firmware\n");
55 return -EBADF;
56 }
57
58 debug("Intel ME firmware is ready\n");
59
60 return 0;
61}
62
Simon Glass37a91ff2016-01-17 16:11:50 -070063int intel_early_me_uma_size(struct udevice *me_dev)
Simon Glass268eefd2014-11-12 22:42:28 -070064{
65 struct me_uma uma;
66
Simon Glass37a91ff2016-01-17 16:11:50 -070067 pci_read_dword_ptr(me_dev, &uma, PCI_ME_UMA);
Simon Glass268eefd2014-11-12 22:42:28 -070068 if (uma.valid) {
69 debug("ME: Requested %uMB UMA\n", uma.size);
70 return uma.size;
71 }
72
73 debug("ME: Invalid UMA size\n");
74 return -EINVAL;
75}
76
Simon Glass37a91ff2016-01-17 16:11:50 -070077static inline void set_global_reset(struct udevice *dev, int enable)
Simon Glass268eefd2014-11-12 22:42:28 -070078{
79 u32 etr3;
80
Simon Glass37a91ff2016-01-17 16:11:50 -070081 dm_pci_read_config32(dev, ETR3, &etr3);
Simon Glass268eefd2014-11-12 22:42:28 -070082
83 /* Clear CF9 Without Resume Well Reset Enable */
84 etr3 &= ~ETR3_CWORWRE;
85
86 /* CF9GR indicates a Global Reset */
87 if (enable)
88 etr3 |= ETR3_CF9GR;
89 else
90 etr3 &= ~ETR3_CF9GR;
91
Simon Glass37a91ff2016-01-17 16:11:50 -070092 dm_pci_write_config32(dev, ETR3, etr3);
Simon Glass268eefd2014-11-12 22:42:28 -070093}
94
Simon Glass37a91ff2016-01-17 16:11:50 -070095int intel_early_me_init_done(struct udevice *dev, struct udevice *me_dev,
96 uint status)
Simon Glass268eefd2014-11-12 22:42:28 -070097{
Simon Glass268eefd2014-11-12 22:42:28 -070098 int count;
99 u32 mebase_l, mebase_h;
100 struct me_hfs hfs;
101 struct me_did did = {
102 .init_done = ME_INIT_DONE,
103 .status = status
104 };
105
106 /* MEBASE from MESEG_BASE[35:20] */
Simon Glass37a91ff2016-01-17 16:11:50 -0700107 dm_pci_read_config32(PCH_DEV, PCI_CPU_MEBASE_L, &mebase_l);
108 dm_pci_read_config32(PCH_DEV, PCI_CPU_MEBASE_H, &mebase_h);
Simon Glass268eefd2014-11-12 22:42:28 -0700109 mebase_h &= 0xf;
110 did.uma_base = (mebase_l >> 20) | (mebase_h << 12);
111
112 /* Send message to ME */
113 debug("ME: Sending Init Done with status: %d, UMA base: 0x%04x\n",
114 status, did.uma_base);
115
Simon Glass37a91ff2016-01-17 16:11:50 -0700116 pci_write_dword_ptr(me_dev, &did, PCI_ME_H_GS);
Simon Glass268eefd2014-11-12 22:42:28 -0700117
118 /* Must wait for ME acknowledgement */
119 for (count = ME_RETRY; count > 0; --count) {
Simon Glass37a91ff2016-01-17 16:11:50 -0700120 pci_read_dword_ptr(me_dev, &hfs, PCI_ME_HFS);
Simon Glass268eefd2014-11-12 22:42:28 -0700121 if (hfs.bios_msg_ack)
122 break;
123 udelay(ME_DELAY);
124 }
125 if (!count) {
126 printf("ERROR: ME failed to respond\n");
Simon Glass37a91ff2016-01-17 16:11:50 -0700127 return -ETIMEDOUT;
Simon Glass268eefd2014-11-12 22:42:28 -0700128 }
129
130 /* Return the requested BIOS action */
131 debug("ME: Requested BIOS Action: %s\n", me_ack_values[hfs.ack_data]);
132
133 /* Check status after acknowledgement */
Simon Glassb67be7e2016-03-11 22:07:00 -0700134 intel_me_status(me_dev);
Simon Glass268eefd2014-11-12 22:42:28 -0700135
Simon Glass268eefd2014-11-12 22:42:28 -0700136 switch (hfs.ack_data) {
137 case ME_HFS_ACK_CONTINUE:
138 /* Continue to boot */
139 return 0;
140 case ME_HFS_ACK_RESET:
141 /* Non-power cycle reset */
Simon Glass37a91ff2016-01-17 16:11:50 -0700142 set_global_reset(dev, 0);
Bin Mengaf5b8d22018-07-19 03:07:33 -0700143 sysreset_walk_halt(SYSRESET_COLD);
Simon Glass268eefd2014-11-12 22:42:28 -0700144 break;
145 case ME_HFS_ACK_PWR_CYCLE:
146 /* Power cycle reset */
Simon Glass37a91ff2016-01-17 16:11:50 -0700147 set_global_reset(dev, 0);
Bin Mengaf5b8d22018-07-19 03:07:33 -0700148 sysreset_walk_halt(SYSRESET_COLD);
Simon Glass268eefd2014-11-12 22:42:28 -0700149 break;
150 case ME_HFS_ACK_GBL_RESET:
151 /* Global reset */
Simon Glass37a91ff2016-01-17 16:11:50 -0700152 set_global_reset(dev, 1);
Bin Mengaf5b8d22018-07-19 03:07:33 -0700153 sysreset_walk_halt(SYSRESET_COLD);
Simon Glass268eefd2014-11-12 22:42:28 -0700154 break;
155 case ME_HFS_ACK_S3:
156 case ME_HFS_ACK_S4:
157 case ME_HFS_ACK_S5:
158 break;
159 }
160
Simon Glass37a91ff2016-01-17 16:11:50 -0700161 return -EINVAL;
Simon Glass268eefd2014-11-12 22:42:28 -0700162}
Simon Glass37a91ff2016-01-17 16:11:50 -0700163
164static const struct udevice_id ivybridge_syscon_ids[] = {
Simon Glass43a50342016-01-17 16:11:58 -0700165 { .compatible = "intel,me", .data = X86_SYSCON_ME },
Simon Glass37a91ff2016-01-17 16:11:50 -0700166 { }
167};
168
169U_BOOT_DRIVER(syscon_intel_me) = {
170 .name = "intel_me_syscon",
171 .id = UCLASS_SYSCON,
172 .of_match = ivybridge_syscon_ids,
173};