blob: b57ca734c70224eebfae871acfba295b1489c5ef [file] [log] [blame]
Aaron Durbin76c37002012-10-30 09:03:43 -05001/*
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.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
19 * MA 02110-1301 USA
20 */
21
Aaron Durbin76c37002012-10-30 09:03:43 -050022#include <arch/io.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050023#include <console/console.h>
24#include <delay.h>
25#include <device/pci_ids.h>
Patrick Georgibd79c5e2014-11-28 22:35:36 +010026#include <halt.h>
Aaron Durbin76c37002012-10-30 09:03:43 -050027#include <string.h>
28#include "me.h"
29#include "pch.h"
30
31static const char *me_ack_values[] = {
32 [ME_HFS_ACK_NO_DID] = "No DID Ack received",
33 [ME_HFS_ACK_RESET] = "Non-power cycle reset",
34 [ME_HFS_ACK_PWR_CYCLE] = "Power cycle reset",
35 [ME_HFS_ACK_S3] = "Go to S3",
36 [ME_HFS_ACK_S4] = "Go to S4",
37 [ME_HFS_ACK_S5] = "Go to S5",
38 [ME_HFS_ACK_GBL_RESET] = "Global Reset",
39 [ME_HFS_ACK_CONTINUE] = "Continue to boot"
40};
41
42static inline void pci_read_dword_ptr(void *ptr, int offset)
43{
44 u32 dword = pci_read_config32(PCH_ME_DEV, offset);
45 memcpy(ptr, &dword, sizeof(dword));
46}
47
48static inline void pci_write_dword_ptr(void *ptr, int offset)
49{
50 u32 dword = 0;
51 memcpy(&dword, ptr, sizeof(dword));
52 pci_write_config32(PCH_ME_DEV, offset, dword);
53}
54
55void intel_early_me_status(void)
56{
57 struct me_hfs hfs;
Aaron Durbin9aa031e2012-11-02 09:16:46 -050058 struct me_hfs2 hfs2;
Aaron Durbin76c37002012-10-30 09:03:43 -050059
60 pci_read_dword_ptr(&hfs, PCI_ME_HFS);
Aaron Durbin9aa031e2012-11-02 09:16:46 -050061 pci_read_dword_ptr(&hfs2, PCI_ME_HFS2);
Aaron Durbin76c37002012-10-30 09:03:43 -050062
Aaron Durbin9aa031e2012-11-02 09:16:46 -050063 intel_me_status(&hfs, &hfs2);
Aaron Durbin76c37002012-10-30 09:03:43 -050064}
65
66int intel_early_me_init(void)
67{
68 int count;
69 struct me_uma uma;
70 struct me_hfs hfs;
71
72 printk(BIOS_INFO, "Intel ME early init\n");
73
74 /* Wait for ME UMA SIZE VALID bit to be set */
Aaron Durbin9aa031e2012-11-02 09:16:46 -050075 /* FIXME: ME9 BGW indicates a 5 sec poll timeout. */
Aaron Durbin76c37002012-10-30 09:03:43 -050076 for (count = ME_RETRY; count > 0; --count) {
77 pci_read_dword_ptr(&uma, PCI_ME_UMA);
78 if (uma.valid)
79 break;
80 udelay(ME_DELAY);
81 }
82 if (!count) {
83 printk(BIOS_ERR, "ERROR: ME is not ready!\n");
84 return -1;
85 }
86
87 /* Check for valid firmware */
88 pci_read_dword_ptr(&hfs, PCI_ME_HFS);
89 if (hfs.fpt_bad) {
90 printk(BIOS_WARNING, "WARNING: ME has bad firmware\n");
91 return -1;
92 }
93
94 printk(BIOS_INFO, "Intel ME firmware is ready\n");
95 return 0;
96}
97
98int intel_early_me_uma_size(void)
99{
100 struct me_uma uma;
101
102 pci_read_dword_ptr(&uma, PCI_ME_UMA);
103 if (uma.valid) {
104 printk(BIOS_DEBUG, "ME: Requested %uMB UMA\n", uma.size);
105 return uma.size;
106 }
107
108 printk(BIOS_DEBUG, "ME: Invalid UMA size\n");
109 return 0;
110}
111
112static inline void set_global_reset(int enable)
113{
Aaron Durbinb9ea8b32012-11-02 09:10:30 -0500114 u32 pmir = pci_read_config32(PCH_LPC_DEV, PMIR);
Aaron Durbin76c37002012-10-30 09:03:43 -0500115
116 /* CF9GR indicates a Global Reset */
117 if (enable)
Aaron Durbinb9ea8b32012-11-02 09:10:30 -0500118 pmir |= PMIR_CF9GR;
Aaron Durbin76c37002012-10-30 09:03:43 -0500119 else
Aaron Durbinb9ea8b32012-11-02 09:10:30 -0500120 pmir &= ~PMIR_CF9GR;
Aaron Durbin76c37002012-10-30 09:03:43 -0500121
Aaron Durbinb9ea8b32012-11-02 09:10:30 -0500122 pci_write_config32(PCH_LPC_DEV, PMIR, pmir);
Aaron Durbin76c37002012-10-30 09:03:43 -0500123}
124
125int intel_early_me_init_done(u8 status)
126{
127 u8 reset;
128 int count;
129 u32 mebase_l, mebase_h;
130 struct me_hfs hfs;
131 struct me_did did = {
132 .init_done = ME_INIT_DONE,
133 .status = status
134 };
135
136 /* MEBASE from MESEG_BASE[35:20] */
137 mebase_l = pci_read_config32(PCI_CPU_DEVICE, PCI_CPU_MEBASE_L);
138 mebase_h = pci_read_config32(PCI_CPU_DEVICE, PCI_CPU_MEBASE_H) & 0xf;
139 did.uma_base = (mebase_l >> 20) | (mebase_h << 12);
140
141 /* Send message to ME */
142 printk(BIOS_DEBUG, "ME: Sending Init Done with status: %d, "
143 "UMA base: 0x%04x\n", status, did.uma_base);
144
145 pci_write_dword_ptr(&did, PCI_ME_H_GS);
146
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500147 /*
148 * The ME firmware does not respond with an ACK when NOMEM or ERROR
149 * are sent.
150 */
151 if (status == ME_INIT_STATUS_NOMEM || status == ME_INIT_STATUS_ERROR)
152 return 0;
153
Aaron Durbin76c37002012-10-30 09:03:43 -0500154 /* Must wait for ME acknowledgement */
155 for (count = ME_RETRY; count > 0; --count) {
156 pci_read_dword_ptr(&hfs, PCI_ME_HFS);
157 if (hfs.bios_msg_ack)
158 break;
159 udelay(ME_DELAY);
160 }
161 if (!count) {
162 printk(BIOS_ERR, "ERROR: ME failed to respond\n");
163 return -1;
164 }
165
166 /* Return the requested BIOS action */
167 printk(BIOS_NOTICE, "ME: Requested BIOS Action: %s\n",
168 me_ack_values[hfs.ack_data]);
169
170 /* Check status after acknowledgement */
171 intel_early_me_status();
172
173 reset = 0;
174 switch (hfs.ack_data) {
175 case ME_HFS_ACK_CONTINUE:
176 /* Continue to boot */
177 return 0;
178 case ME_HFS_ACK_RESET:
179 /* Non-power cycle reset */
180 set_global_reset(0);
181 reset = 0x06;
182 break;
183 case ME_HFS_ACK_PWR_CYCLE:
184 /* Power cycle reset */
185 set_global_reset(0);
186 reset = 0x0e;
187 break;
188 case ME_HFS_ACK_GBL_RESET:
189 /* Global reset */
190 set_global_reset(1);
191 reset = 0x0e;
192 break;
193 case ME_HFS_ACK_S3:
194 case ME_HFS_ACK_S4:
195 case ME_HFS_ACK_S5:
196 break;
197 }
198
199 /* Perform the requested reset */
200 if (reset) {
201 outb(reset, 0xcf9);
Patrick Georgibd79c5e2014-11-28 22:35:36 +0100202 halt();
Aaron Durbin76c37002012-10-30 09:03:43 -0500203 }
204 return -1;
205}