2 * This file is part of the coreboot project.
4 * Copyright (C) 2008-2009 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,
23 #include <arch/romcc_io.h>
24 #include <console/console.h>
25 #include <cpu/x86/cache.h>
26 #include <cpu/x86/smm.h>
28 typedef enum { SMI_LOCKED, SMI_UNLOCKED } smi_semaphore;
30 /* SMI multiprocessing semaphore */
31 static volatile smi_semaphore smi_handler_status = SMI_UNLOCKED;
33 static int smi_obtain_lock(void)
41 : "=g" (ret), "=m" (smi_handler_status)
46 return (ret == SMI_UNLOCKED);
49 static void smi_release_lock(void)
54 : "=m" (smi_handler_status)
60 #define LAPIC_ID 0xfee00020
61 static inline __attribute__((always_inline)) unsigned long nodeid(void)
63 return (*((volatile unsigned long *)(LAPIC_ID)) >> 24);
66 void io_trap_handler(int smif)
68 /* If a handler function handled a given IO trap, it
69 * shall return a non-zero value
71 printk(BIOS_DEBUG, "SMI function trap 0x%x: ", smif);
73 if (southbridge_io_trap_handler(smif))
76 if (mainboard_io_trap_handler(smif))
79 printk(BIOS_DEBUG, "Unknown function\n");
83 * @brief Set the EOS bit
85 static void smi_set_eos(void)
87 southbridge_smi_set_eos();
91 * @brief Interrupt handler for SMI#
93 * @param smm_revision revision of the smm state save map
96 void smi_handler(u32 smm_revision)
99 smm_state_save_area_t state_save;
101 /* Are we ok to execute the handler? */
102 if (!smi_obtain_lock()) {
103 /* For security reasons we don't release the other CPUs
104 * until the CPU with the lock is actually done
106 while (smi_handler_status == SMI_LOCKED) /* wait */ ;
114 printk(BIOS_SPEW, "\nSMI# #%d\n", node);
116 switch (smm_revision) {
119 state_save.type = LEGACY;
120 state_save.legacy_state_save = (legacy_smm_state_save_area_t *)
121 (0xa8000 + 0x7e00 - (node * 0x400));
124 state_save.type = EM64T;
125 state_save.em64t_state_save = (em64t_smm_state_save_area_t *)
126 (0xa8000 + 0x7d00 - (node * 0x400));
129 state_save.type = AMD64;
130 state_save.amd64_state_save = (amd64_smm_state_save_area_t *)
131 (0xa8000 + 0x7e00 - (node * 0x400));
134 printk(BIOS_DEBUG, "smm_revision: 0x%08x\n", smm_revision);
135 printk(BIOS_DEBUG, "SMI# not supported on your CPU\n");
136 /* Don't release lock, so no further SMI will happen,
137 * if we don't handle it anyways.
142 /* Call chipset specific SMI handlers. */
144 cpu_smi_handler(node, &state_save);
145 if (northbridge_smi_handler)
146 northbridge_smi_handler(node, &state_save);
147 if (southbridge_smi_handler)
148 southbridge_smi_handler(node, &state_save);
152 /* De-assert SMI# signal to allow another SMI */