blob: e41b801a8b37da61ab1f1b5e192b0325a3123162 [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{
Aaron Durbinb9ea8b32012-11-02 09:10:30 -0500115 u32 pmir = pci_read_config32(PCH_LPC_DEV, PMIR);
Aaron Durbin76c37002012-10-30 09:03:43 -0500116
117 /* CF9GR indicates a Global Reset */
118 if (enable)
Aaron Durbinb9ea8b32012-11-02 09:10:30 -0500119 pmir |= PMIR_CF9GR;
Aaron Durbin76c37002012-10-30 09:03:43 -0500120 else
Aaron Durbinb9ea8b32012-11-02 09:10:30 -0500121 pmir &= ~PMIR_CF9GR;
Aaron Durbin76c37002012-10-30 09:03:43 -0500122
Aaron Durbinb9ea8b32012-11-02 09:10:30 -0500123 pci_write_config32(PCH_LPC_DEV, PMIR, pmir);
Aaron Durbin76c37002012-10-30 09:03:43 -0500124}
125
126int intel_early_me_init_done(u8 status)
127{
128 u8 reset;
129 int count;
130 u32 mebase_l, mebase_h;
131 struct me_hfs hfs;
132 struct me_did did = {
133 .init_done = ME_INIT_DONE,
134 .status = status
135 };
136
137 /* MEBASE from MESEG_BASE[35:20] */
138 mebase_l = pci_read_config32(PCI_CPU_DEVICE, PCI_CPU_MEBASE_L);
139 mebase_h = pci_read_config32(PCI_CPU_DEVICE, PCI_CPU_MEBASE_H) & 0xf;
140 did.uma_base = (mebase_l >> 20) | (mebase_h << 12);
141
142 /* Send message to ME */
143 printk(BIOS_DEBUG, "ME: Sending Init Done with status: %d, "
144 "UMA base: 0x%04x\n", status, did.uma_base);
145
146 pci_write_dword_ptr(&did, PCI_ME_H_GS);
147
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500148 /*
149 * The ME firmware does not respond with an ACK when NOMEM or ERROR
150 * are sent.
151 */
152 if (status == ME_INIT_STATUS_NOMEM || status == ME_INIT_STATUS_ERROR)
153 return 0;
154
Aaron Durbin76c37002012-10-30 09:03:43 -0500155 /* Must wait for ME acknowledgement */
156 for (count = ME_RETRY; count > 0; --count) {
157 pci_read_dword_ptr(&hfs, PCI_ME_HFS);
158 if (hfs.bios_msg_ack)
159 break;
160 udelay(ME_DELAY);
161 }
162 if (!count) {
163 printk(BIOS_ERR, "ERROR: ME failed to respond\n");
164 return -1;
165 }
166
167 /* Return the requested BIOS action */
168 printk(BIOS_NOTICE, "ME: Requested BIOS Action: %s\n",
169 me_ack_values[hfs.ack_data]);
170
171 /* Check status after acknowledgement */
172 intel_early_me_status();
173
174 reset = 0;
175 switch (hfs.ack_data) {
176 case ME_HFS_ACK_CONTINUE:
177 /* Continue to boot */
178 return 0;
179 case ME_HFS_ACK_RESET:
180 /* Non-power cycle reset */
181 set_global_reset(0);
182 reset = 0x06;
183 break;
184 case ME_HFS_ACK_PWR_CYCLE:
185 /* Power cycle reset */
186 set_global_reset(0);
187 reset = 0x0e;
188 break;
189 case ME_HFS_ACK_GBL_RESET:
190 /* Global reset */
191 set_global_reset(1);
192 reset = 0x0e;
193 break;
194 case ME_HFS_ACK_S3:
195 case ME_HFS_ACK_S4:
196 case ME_HFS_ACK_S5:
197 break;
198 }
199
200 /* Perform the requested reset */
201 if (reset) {
202 outb(reset, 0xcf9);
Aaron Durbin9aa031e2012-11-02 09:16:46 -0500203 while (1) {
204 hlt();
205 }
Aaron Durbin76c37002012-10-30 09:03:43 -0500206 }
207 return -1;
208}