| 1 |
|
| 2 |
|
| 3 |
#include <stdint.h> |
| 4 |
#include <arch/hlt.h> |
| 5 |
#include <arch/io.h> |
| 6 |
#include <device/pci_ops.h> |
| 7 |
#include <console/console.h> |
| 8 |
#include <cpu/x86/cache.h> |
| 9 |
#include <cpu/x86/smm.h> |
| 10 |
#include <cpu/intel/em64t100_save_state.h> |
| 11 |
#include <device/pci_def.h> |
| 12 |
#include <intelblocks/fast_spi.h> |
| 13 |
#include <smmstore.h> |
| 14 |
#include <spi-generic.h> |
| 15 |
#include <soc/iomap.h> |
| 16 |
#include <soc/soc_util.h> |
| 17 |
#include <soc/pm.h> |
| 18 |
#include <soc/nvs.h> |
| 19 |
|
| 20 |
void southbridge_smi_set_eos(void) |
| 21 |
{ |
| 22 |
enable_smi(EOS); |
| 23 |
} |
| 24 |
|
| 25 |
static void busmaster_disable_on_bus(int bus) |
| 26 |
{ |
| 27 |
int slot, func; |
| 28 |
unsigned int val; |
| 29 |
unsigned char hdr; |
| 30 |
|
| 31 |
for (slot = 0; slot < 0x20; slot++) { |
| 32 |
for (func = 0; func < 8; func++) { |
| 33 |
u16 reg16; |
| 34 |
|
| 35 |
pci_devfn_t dev = PCI_DEV(bus, slot, func); |
| 36 |
val = pci_read_config32(dev, PCI_VENDOR_ID); |
| 37 |
|
| 38 |
if (val == 0xffffffff || val == 0x00000000 || |
| 39 |
val == 0x0000ffff || val == 0xffff0000) |
| 40 |
continue; |
| 41 |
|
| 42 |
|
| 43 |
reg16 = pci_read_config16(dev, PCI_COMMAND); |
| 44 |
reg16 &= ~PCI_COMMAND_MASTER; |
| 45 |
pci_write_config16(dev, PCI_COMMAND, reg16); |
| 46 |
|
| 47 |
|
| 48 |
hdr = pci_read_config8(dev, PCI_HEADER_TYPE); |
| 49 |
hdr &= 0x7f; |
| 50 |
if (hdr == PCI_HEADER_TYPE_BRIDGE || |
| 51 |
hdr == PCI_HEADER_TYPE_CARDBUS) { |
| 52 |
unsigned int buses; |
| 53 |
buses = pci_read_config32(dev, PCI_PRIMARY_BUS); |
| 54 |
busmaster_disable_on_bus((buses >> 8) & 0xff); |
| 55 |
} |
| 56 |
} |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
static void southbridge_smi_sleep(void) |
| 61 |
{ |
| 62 |
uint32_t reg32; |
| 63 |
uint8_t slp_typ; |
| 64 |
uint16_t pmbase = get_pmbase(); |
| 65 |
|
| 66 |
|
| 67 |
disable_smi(SLP_SMI_EN); |
| 68 |
|
| 69 |
|
| 70 |
reg32 = inl((uint16_t)(pmbase + PM1_CNT)); |
| 71 |
printk(BIOS_SPEW, "SMI#: SLP = 0x%08x\n", reg32); |
| 72 |
slp_typ = (reg32 >> 10) & 7; |
| 73 |
|
| 74 |
|
| 75 |
mainboard_smi_sleep((uint8_t)(slp_typ - 2)); |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
switch (slp_typ) { |
| 81 |
case SLP_TYP_S0: |
| 82 |
printk(BIOS_DEBUG, "SMI#: Entering S0 (On)\n"); |
| 83 |
break; |
| 84 |
case SLP_TYP_S1: |
| 85 |
printk(BIOS_DEBUG, "SMI#: Entering S1 (Assert STPCLK#)\n"); |
| 86 |
break; |
| 87 |
case SLP_TYP_S3: |
| 88 |
printk(BIOS_DEBUG, "SMI#: Entering S3 (Suspend-To-RAM)\n"); |
| 89 |
|
| 90 |
|
| 91 |
wbinvd(); |
| 92 |
break; |
| 93 |
case SLP_TYP_S4: |
| 94 |
printk(BIOS_DEBUG, "SMI#: Entering S4 (Suspend-To-Disk)\n"); |
| 95 |
break; |
| 96 |
case SLP_TYP_S5: |
| 97 |
printk(BIOS_DEBUG, "SMI#: Entering S5 (Soft Power off)\n"); |
| 98 |
|
| 99 |
|
| 100 |
disable_all_gpe(); |
| 101 |
|
| 102 |
|
| 103 |
busmaster_disable_on_bus(0); |
| 104 |
break; |
| 105 |
default: |
| 106 |
printk(BIOS_DEBUG, "SMI#: ERROR: SLP_TYP reserved\n"); |
| 107 |
break; |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
enable_pm1_control(SLP_EN); |
| 115 |
|
| 116 |
|
| 117 |
if (slp_typ > 1) |
| 118 |
hlt(); |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
reg32 = inl((uint16_t)(pmbase + PM1_CNT)); |
| 125 |
if (reg32 & SCI_EN) { |
| 126 |
|
| 127 |
disable_pm1_control(SLP_EN | SLP_TYP); |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
static em64t100_smm_state_save_area_t *smi_apmc_find_state_save(uint8_t cmd) |
| 137 |
{ |
| 138 |
em64t100_smm_state_save_area_t *state; |
| 139 |
int node; |
| 140 |
|
| 141 |
|
| 142 |
for (node = 0; node < CONFIG_MAX_CPUS; node++) { |
| 143 |
state = smm_get_save_state(node); |
| 144 |
if (!state) |
| 145 |
continue; |
| 146 |
|
| 147 |
|
| 148 |
if (!(state->io_misc_info & (1 << 0))) |
| 149 |
continue; |
| 150 |
|
| 151 |
|
| 152 |
if (state->io_misc_info & (1 << 4)) |
| 153 |
continue; |
| 154 |
|
| 155 |
|
| 156 |
if (((state->io_misc_info >> 16) & 0xff) != APM_CNT) |
| 157 |
continue; |
| 158 |
|
| 159 |
|
| 160 |
if ((state->rax & 0xff) != cmd) |
| 161 |
continue; |
| 162 |
|
| 163 |
return state; |
| 164 |
} |
| 165 |
|
| 166 |
return NULL; |
| 167 |
} |
| 168 |
|
| 169 |
static void finalize(void) |
| 170 |
{ |
| 171 |
static int finalize_done; |
| 172 |
|
| 173 |
if (finalize_done) { |
| 174 |
printk(BIOS_DEBUG, "SMM already finalized.\n"); |
| 175 |
return; |
| 176 |
} |
| 177 |
finalize_done = 1; |
| 178 |
|
| 179 |
if (CONFIG(SPI_FLASH_SMM)) |
| 180 |
|
| 181 |
fast_spi_init(); |
| 182 |
} |
| 183 |
|
| 184 |
static void southbridge_smi_store(void) |
| 185 |
{ |
| 186 |
u8 sub_command, ret; |
| 187 |
em64t100_smm_state_save_area_t *io_smi = |
| 188 |
smi_apmc_find_state_save(APM_CNT_SMMSTORE); |
| 189 |
uint32_t reg_ebx; |
| 190 |
|
| 191 |
if (!io_smi) |
| 192 |
return; |
| 193 |
|
| 194 |
sub_command = (io_smi->rax >> 8) & 0xff; |
| 195 |
|
| 196 |
|
| 197 |
reg_ebx = io_smi->rbx; |
| 198 |
|
| 199 |
|
| 200 |
ret = smmstore_exec(sub_command, (void *)reg_ebx); |
| 201 |
io_smi->rax = ret; |
| 202 |
} |
| 203 |
|
| 204 |
static void southbridge_smi_apmc(void) |
| 205 |
{ |
| 206 |
uint8_t reg8; |
| 207 |
|
| 208 |
reg8 = apm_get_apmc(); |
| 209 |
switch (reg8) { |
| 210 |
case APM_CNT_ACPI_DISABLE: |
| 211 |
disable_pm1_control(SCI_EN); |
| 212 |
break; |
| 213 |
case APM_CNT_ACPI_ENABLE: |
| 214 |
enable_pm1_control(SCI_EN); |
| 215 |
break; |
| 216 |
case APM_CNT_FINALIZE: |
| 217 |
finalize(); |
| 218 |
break; |
| 219 |
case APM_CNT_SMMSTORE: |
| 220 |
if (CONFIG(SMMSTORE)) |
| 221 |
southbridge_smi_store(); |
| 222 |
break; |
| 223 |
} |
| 224 |
|
| 225 |
mainboard_smi_apmc(reg8); |
| 226 |
} |
| 227 |
|
| 228 |
static void southbridge_smi_pm1(void) |
| 229 |
{ |
| 230 |
uint16_t pm1_sts = clear_pm1_status(); |
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
if (pm1_sts & PWRBTN_STS) { |
| 236 |
|
| 237 |
disable_pm1_control(-1UL); |
| 238 |
enable_pm1_control(SLP_EN | (SLP_TYP_S5 << SLP_TYP_SHIFT)); |
| 239 |
} |
| 240 |
} |
| 241 |
|
| 242 |
static void southbridge_smi_gpe0(void) { clear_gpe_status(); } |
| 243 |
|
| 244 |
static void southbridge_smi_tco(void) |
| 245 |
{ |
| 246 |
uint32_t tco_sts = clear_tco_status(); |
| 247 |
|
| 248 |
|
| 249 |
if (!tco_sts) |
| 250 |
return; |
| 251 |
|
| 252 |
if (tco_sts & TCO1_STS_TIMEOUT) { |
| 253 |
|
| 254 |
printk(BIOS_DEBUG, "TCO Timeout.\n"); |
| 255 |
} |
| 256 |
} |
| 257 |
|
| 258 |
static void southbridge_smi_periodic(void) |
| 259 |
{ |
| 260 |
uint32_t reg32; |
| 261 |
|
| 262 |
reg32 = inl((uint16_t)(get_pmbase() + SMI_EN)); |
| 263 |
|
| 264 |
|
| 265 |
if ((reg32 & PERIODIC_EN) == 0) |
| 266 |
return; |
| 267 |
|
| 268 |
printk(BIOS_DEBUG, "Periodic SMI.\n"); |
| 269 |
} |
| 270 |
|
| 271 |
typedef void (*smi_handler_t)(void); |
| 272 |
|
| 273 |
static const smi_handler_t southbridge_smi[32] = { |
| 274 |
NULL, |
| 275 |
NULL, |
| 276 |
NULL, |
| 277 |
NULL, |
| 278 |
southbridge_smi_sleep, |
| 279 |
southbridge_smi_apmc, |
| 280 |
NULL, |
| 281 |
NULL, |
| 282 |
southbridge_smi_pm1, |
| 283 |
southbridge_smi_gpe0, |
| 284 |
NULL, |
| 285 |
NULL, |
| 286 |
NULL, |
| 287 |
southbridge_smi_tco, |
| 288 |
southbridge_smi_periodic, |
| 289 |
NULL, |
| 290 |
NULL, |
| 291 |
NULL, |
| 292 |
NULL, |
| 293 |
NULL, |
| 294 |
NULL, |
| 295 |
NULL, |
| 296 |
NULL, |
| 297 |
NULL, |
| 298 |
NULL, |
| 299 |
NULL, |
| 300 |
NULL, |
| 301 |
NULL, |
| 302 |
NULL, |
| 303 |
NULL, |
| 304 |
NULL, |
| 305 |
NULL |
| 306 |
}; |
| 307 |
|
| 308 |
void southbridge_smi_handler(void) |
| 309 |
{ |
| 310 |
int i; |
| 311 |
uint32_t smi_sts; |
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
smi_sts = clear_smi_status(); |
| 317 |
|
| 318 |
|
| 319 |
for (i = 0; i < ARRAY_SIZE(southbridge_smi); i++) { |
| 320 |
if (!(smi_sts & (1 << i))) |
| 321 |
continue; |
| 322 |
|
| 323 |
if (southbridge_smi[i] != NULL) { |
| 324 |
southbridge_smi[i](); |
| 325 |
} else { |
| 326 |
printk(BIOS_DEBUG, "SMI_STS[%d] occurred, but no " |
| 327 |
"handler available.\n", |
| 328 |
i); |
| 329 |
} |
| 330 |
} |
| 331 |
} |