blob: 1eb30a1ff74ccee50ae6c290335ebf818e7b5ed6 [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
22#include <arch/hlt.h>
23#include <arch/io.h>
24#include <arch/romcc_io.h>
25#include <console/console.h>
26#include <delay.h>
27#include <device/pci_ids.h>
28#include <string.h>
29#include "me.h"
30#include "pch.h"
31
32static const char *me_ack_values[] = {
33 [ME_HFS_ACK_NO_DID] = "No DID Ack received",
34 [ME_HFS_ACK_RESET] = "Non-power cycle reset",
35 [ME_HFS_ACK_PWR_CYCLE] = "Power cycle reset",
36 [ME_HFS_ACK_S3] = "Go to S3",
37 [ME_HFS_ACK_S4] = "Go to S4",
38 [ME_HFS_ACK_S5] = "Go to S5",
39 [ME_HFS_ACK_GBL_RESET] = "Global Reset",
40 [ME_HFS_ACK_CONTINUE] = "Continue to boot"
41};
42
43static inline void pci_read_dword_ptr(void *ptr, int offset)
44{
45 u32 dword = pci_read_config32(PCH_ME_DEV, offset);
46 memcpy(ptr, &dword, sizeof(dword));
47}
48
49static inline void pci_write_dword_ptr(void *ptr, int offset)
50{
51 u32 dword = 0;
52 memcpy(&dword, ptr, sizeof(dword));
53 pci_write_config32(PCH_ME_DEV, offset, dword);
54}
55
56void intel_early_me_status(void)
57{
58 struct me_hfs hfs;
Aaron Durbin9aa031e2012-11-02 09:16:46 -050059 struct me_hfs2 hfs2;
Aaron Durbin76c37002012-10-30 09:03:43 -050060
61 pci_read_dword_ptr(&hfs, PCI_ME_HFS);
Aaron Durbin9aa031e2012-11-02 09:16:46 -050062 pci_read_dword_ptr(&hfs2, PCI_ME_HFS2);
Aaron Durbin76c37002012-10-30 09:03:43 -050063
Aaron Durbin9aa031e2012-11-02 09:16:46 -050064 intel_me_status(&hfs, &hfs2);
Aaron Durbin76c37002012-10-30 09:03:43 -050065}
66
67int intel_early_me_init(void)
68{
69 int count;
70 struct me_uma uma;
71 struct me_hfs hfs;
72
73 printk(BIOS_INFO, "Intel ME early init\n");
74
75 /* Wait for ME UMA SIZE VALID bit to be set */
Aaron Durbin9aa031e2012-11-02 09:16:46 -050076 /* FIXME: ME9 BGW indicates a 5 sec poll timeout. */
Aaron Durbin76c37002012-10-30 09:03:43 -050077 for (count = ME_RETRY; count > 0; --count) {
78 pci_read_dword_ptr(&uma, PCI_ME_UMA);
79 if (uma.valid)
80 break;
81 udelay(ME_DELAY);
82 }
83 if (!count) {
84 printk(BIOS_ERR, "ERROR: ME is not ready!\n");
85 return -1;
86 }
87
88 /* Check for valid firmware */
89 pci_read_dword_ptr(&hfs, PCI_ME_HFS);
90 if (hfs.fpt_bad) {
91 printk(BIOS_WARNING, "WARNING: ME has bad firmware\n");
92 return -1;
93 }
94
95 printk(BIOS_INFO, "Intel ME firmware is ready\n");
96 return 0;
97}
98
99int intel_early_me_uma_size(void)
100{
101 struct me_uma uma;
102
103 pci_read_dword_ptr(&uma, PCI_ME_UMA);
104 if (uma.valid) {
105 printk(BIOS_DEBUG, "ME: Requested %uMB UMA\n", uma.size);
106 return uma.size;
107 }
108
109 printk(BIOS_DEBUG, "ME: Invalid UMA size\n");
110 return 0;
111}
112
113static inline void set_global_reset(int enable)
114{
115 u32 etr3 = pci_read_config32(PCH_LPC_DEV, ETR3);
116
117 /* Clear CF9 Without Resume Well Reset Enable */
118 etr3 &= ~ETR3_CWORWRE;
119
120 /* CF9GR indicates a Global Reset */
121 if (enable)
122 etr3 |= ETR3_CF9GR;
123 else
124 etr3 &= ~ETR3_CF9GR;
125
126 pci_write_config32(PCH_LPC_DEV, ETR3, etr3);
127}
128
129int intel_early_me_init_done(u8 status)
130{
131 u8 reset;
132 int count;
133 u32 mebase_l, mebase_h;
134 struct me_hfs hfs;
135 struct me_did did = {
136 .init_done = ME_INIT_DONE,
137 .status = status
138 };
139
140 /* MEBASE from MESEG_BASE[35:20] */
141 mebase_l = pci_read_config32(PCI_CPU_DEVICE, PCI_CPU_MEBASE_L);
142 mebase_h = pci_read_config32(PCI_CPU_DEVICE, PCI_CPU_MEBASE_H) & 0xf;
143 did.uma_base = (mebase_l >> 20) | (mebase_h << 12);
144
145 /* Send message to ME */
146 printk(BIOS_DEBUG, "ME: Sending Init Done with status: %d, "
147 "UMA base: 0x%04x\n", status, did.uma_base);
148
149 pci_write_dword_ptr(&did, PCI_ME_H_GS);
150
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500151 /*
152 * The ME firmware does not respond with an ACK when NOMEM or ERROR
153 * are sent.
154 */
155 if (status == ME_INIT_STATUS_NOMEM || status == ME_INIT_STATUS_ERROR)
156 return 0;
157
Aaron Durbin76c37002012-10-30 09:03:43 -0500158 /* Must wait for ME acknowledgement */
159 for (count = ME_RETRY; count > 0; --count) {
160 pci_read_dword_ptr(&hfs, PCI_ME_HFS);
161 if (hfs.bios_msg_ack)
162 break;
163 udelay(ME_DELAY);
164 }
165 if (!count) {
166 printk(BIOS_ERR, "ERROR: ME failed to respond\n");
167 return -1;
168 }
169
170 /* Return the requested BIOS action */
171 printk(BIOS_NOTICE, "ME: Requested BIOS Action: %s\n",
172 me_ack_values[hfs.ack_data]);
173
174 /* Check status after acknowledgement */
175 intel_early_me_status();
176
177 reset = 0;
178 switch (hfs.ack_data) {
179 case ME_HFS_ACK_CONTINUE:
180 /* Continue to boot */
181 return 0;
182 case ME_HFS_ACK_RESET:
183 /* Non-power cycle reset */
184 set_global_reset(0);
185 reset = 0x06;
186 break;
187 case ME_HFS_ACK_PWR_CYCLE:
188 /* Power cycle reset */
189 set_global_reset(0);
190 reset = 0x0e;
191 break;
192 case ME_HFS_ACK_GBL_RESET:
193 /* Global reset */
194 set_global_reset(1);
195 reset = 0x0e;
196 break;
197 case ME_HFS_ACK_S3:
198 case ME_HFS_ACK_S4:
199 case ME_HFS_ACK_S5:
200 break;
201 }
202
203 /* Perform the requested reset */
204 if (reset) {
205 outb(reset, 0xcf9);
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500206 while (1) {
207 hlt();
208 }
Aaron Durbin76c37002012-10-30 09:03:43 -0500209 }
210 return -1;
211}