2 * This file is part of the coreboot project.
4 * Copyright (C) 2010 coresystems GmbH
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
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.
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,
25 #include <arch/romcc_io.h>
26 #include <console/console.h>
27 #include <cpu/x86/cache.h>
28 #include <cpu/x86/smm.h>
29 #include <device/pci_def.h>
32 extern unsigned char *mbi;
37 /* If YABEL is enabled and it's not running at 0x00000000, we have to add some
38 * offset to all our mbi object memory accesses
40 #if defined(CONFIG_PCI_OPTION_ROM_RUN_YABEL) && !defined(CONFIG_YABEL_DIRECTHW)
41 #define OBJ_OFFSET CONFIG_YABEL_VIRTMEM_LOCATION
43 #define OBJ_OFFSET 0x00000
48 #define D_OPEN (1 << 6)
49 #define D_CLS (1 << 5)
50 #define D_LCK (1 << 4)
51 #define G_SMRANE (1 << 3)
52 #define C_BASE_SEG ((0 << 2) | (1 << 1) | (0 << 0))
60 } __attribute__((packed)) banner_id_t;
63 #define MSH_OK_RESTART 0x0001
64 #define MSH_FWH_ERR 0x00ff
65 #define MSH_IF_BAD_ID 0x0100
66 #define MSH_IF_BAD_FUNC 0x0101
67 #define MSH_IF_MBI_CORRUPT 0x0102
68 #define MSH_IF_BAD_HANDLE 0x0103
69 #define MSH_ALRDY_ATCHED 0x0104
70 #define MSH_NOT_ATCHED 0x0105
72 #define MSH_IF_INVADDR 0x0107
73 #define MSH_IF_UKN_TYPE 0x0108
74 #define MSH_IF_NOT_FOUND 0x0109
75 #define MSH_IF_NO_KEY 0x010a
76 #define MSH_IF_BUF_SIZE 0x010b
77 #define MSH_IF_NOT_PENDING 0x010c
80 dump(u8 * addr, u32 len)
82 printk_debug("\n%s(%p, %x):\n", __func__, addr, len);
84 unsigned int tmpCnt = len;
88 printk_debug("\n%p: ", addr);
92 printk_debug("%02x ", x);
98 //reset addr ptr to print ascii
103 if ((x < 32) || (x >= 127)) {
107 printk_debug("%c", x);
117 u32 smicombuffersize;
118 } __attribute__((packed)) version_t;
129 } __attribute__((packed)) mbi_header_t;
136 } __attribute__((packed)) obj_header_t;
146 } __attribute__((packed)) get_object_t;
148 static void mbi_call(u8 subf, banner_id_t *banner_id)
150 // printk_debug("MBI\n");
151 // printk_debug("|- sub function %x\n", subf);
152 // printk_debug("|- banner id @ %x\n", (u32)banner_id);
153 // printk_debug("| |- mhid %x\n", banner_id->mhid);
154 // printk_debug("| |- function %x\n", banner_id->function);
155 // printk_debug("| |- return status %x\n", banner_id->retsts);
156 // printk_debug("| |- rfu %x\n", banner_id->rfu);
158 switch(banner_id->function) {
161 printk_debug("|- MBI_QueryInterface\n");
162 version = (version_t *)banner_id;
163 version->banner.retsts = MSH_OK;
164 version->versionmajor=1;
165 version->versionminor=3;
166 version->smicombuffersize=0x1000;
170 printk_debug("|- MBI_Attach\n");
171 printk_debug("| |- Not Implemented!\n");
174 printk_debug("|- MBI_Detach\n");
175 printk_debug("| |- Not Implemented!\n");
178 obj_header_t *obj_header = (obj_header_t *)banner_id;
179 mbi_header_t *mbi_header = NULL;
180 printk_debug("|- MBI_GetObjectHeader\n");
181 printk_debug("| |- objnum = %d\n", obj_header->objnum);
184 obj_header->banner.retsts = MSH_IF_NOT_FOUND;
186 for (i=0; i< mbi_len;) {
189 if (!(mbi[i] == 0xf0 && mbi [i+1] == 0xf6)) {
194 mbi_header = (mbi_header_t *)&mbi[i];
195 len = ALIGN((mbi_header->size * 16) + sizeof(mbi_header) + mbi_header->name_len, 16);
197 if (obj_header->objnum == count) {
198 int headerlen = ALIGN(sizeof(mbi_header) + mbi_header->name_len + 15, 16);
199 // printk_debug("| |- headerlen = %d\n", headerlen);
200 memcpy(&obj_header->header, mbi_header, headerlen);
201 obj_header->banner.retsts = MSH_OK;
202 printk_debug("| |- MBI module '");
204 for (j=0; j < mbi_header->name_len && mbi_header->name[j]; j++)
205 printk_debug("%c", mbi_header->name[j]);
206 printk_debug("' found.\n", obj_header->objnum);
207 // dump(banner_id, sizeof(obj_header_t) + 16);
213 if (obj_header->banner.retsts == MSH_IF_NOT_FOUND)
214 printk_debug("| |- MBI object #%d not found.\n", obj_header->objnum);
218 get_object_t *getobj = (get_object_t *)banner_id;
219 mbi_header_t *mbi_header = NULL;
220 printk_debug("|- MBI_GetObject\n");
221 // printk_debug("| |- handle = %016lx\n", getobj->handle);
222 printk_debug("| |- objnum = %d\n", getobj->objnum);
223 printk_debug("| |- start = %x\n", getobj->start);
224 printk_debug("| |- numbytes = %x\n", getobj->numbytes);
225 printk_debug("| |- buflen = %x\n", getobj->buflen);
226 printk_debug("| |- buffer = %x\n", getobj->buffer);
229 getobj->banner.retsts = MSH_IF_NOT_FOUND;
231 for (i=0; i< mbi_len;) {
234 if (!(mbi[i] == 0xf0 && mbi [i+1] == 0xf6)) {
239 mbi_header = (mbi_header_t *)&mbi[i];
240 len = ALIGN((mbi_header->size * 16) + sizeof(mbi_header) + mbi_header->name_len, 16);
242 if (getobj->objnum == count) {
243 printk_debug("| |- len = %x\n", len);
244 memcpy((void *)(getobj->buffer + OBJ_OFFSET),
245 ((char *)mbi_header) + 0x20 , (len > getobj->buflen ? getobj->buflen : len));
247 getobj->banner.retsts = MSH_OK;
248 //dump(banner_id, sizeof(getobj) + len);
254 if (getobj->banner.retsts == MSH_IF_NOT_FOUND)
255 printk_debug("MBI module %d not found.\n", getobj->objnum);
259 printk_debug("|- function %x\n", banner_id->function);
260 printk_debug("| |- Unknown Function!\n");
264 //dump(banner_id, 0x20);
267 #define SMI_IFC_SUCCESS 1
268 #define SMI_IFC_FAILURE_GENERIC 0
269 #define SMI_IFC_FAILURE_INVALID 2
270 #define SMI_IFC_FAILURE_CRITICAL 4
271 #define SMI_IFC_FAILURE_NONCRITICAL 6
278 void smi_interface_call(void)
281 mmio = pci_read_config32(PCI_DEV(0, 0x02, 0), 0x14);
282 // mmio &= 0xfff80000;
283 // printk_debug("mmio=%x\n", mmio);
286 swsmi=pci_read_config16(PCI_DEV(0, 0x02, 0), 0xe0);
291 swsmi &= ~(1 << 0); // clear SMI toggle
293 switch ((swsmi>>1) & 0xf) {
295 printk_debug("Interface Function Presence Test.\n");
297 swsmi &= ~(7 << 5); // Exit: Result
298 swsmi |= (SMI_IFC_SUCCESS << 5);
300 swsmi |= (PC13 << 8);
301 pci_write_config16(PCI_DEV(0, 0x02, 0), 0xe0, swsmi);
303 write32(mmio + 0x71428, 0x494e5443);
306 printk_debug("Get BIOS Data.\n");
307 printk_debug("swsmi=%04x\n", swsmi);
310 printk_debug("Call MBI Functions.\n");
311 mbi_call(swsmi >> 8, (banner_id_t *)((readl(mmio + 0x71428) & 0x000fffff) + OBJ_OFFSET) );
313 swsmi &= ~(7 << 5); // Exit: Result
314 swsmi |= (SMI_IFC_SUCCESS << 5);
315 pci_write_config16(PCI_DEV(0, 0x02, 0), 0xe0, swsmi);
318 printk_debug("System BIOS Callbacks.\n");
319 printk_debug("swsmi=%04x\n", swsmi);
322 printk_debug("Unknown SMI interface call %04x\n", swsmi);
326 swsmi &= ~(7 << 5); // Exit: Result
327 swsmi |= (SMI_IFC_FAILURE_CRITICAL << 7);
328 pci_write_config16(PCI_DEV(0, 0x02, 0), 0xe0, swsmi);
332 * @brief read and clear ERRSTS
333 * @return ERRSTS register
335 static u16 reset_err_status(void)
339 reg16 = pci_read_config16(PCI_DEV(0, 0x00, 0), ERRSTS);
340 /* set status bits are cleared by writing 1 to them */
341 pci_write_config16(PCI_DEV(0, 0x00, 0), ERRSTS, reg16);
346 static void dump_err_status(u32 errsts)
348 printk_debug("ERRSTS: ");
349 if (errsts & (1 << 12)) printk_debug("MBI ");
350 if (errsts & (1 << 9)) printk_debug("LCKF ");
351 if (errsts & (1 << 8)) printk_debug("DTF ");
352 if (errsts & (1 << 5)) printk_debug("UNSC ");
353 if (errsts & (1 << 4)) printk_debug("OOGF ");
354 if (errsts & (1 << 3)) printk_debug("IAAF ");
355 if (errsts & (1 << 2)) printk_debug("ITTEF ");
359 void northbridge_smi_handler(unsigned int node, smm_state_save_area_t *state_save)
363 /* We need to clear the SMI status registers, or we won't see what's
364 * happening in the following calls.
366 errsts = reset_err_status();
367 if (errsts & (1 << 12)) {
368 smi_interface_call();
371 dump_err_status(errsts);