2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2014-11-13 05:42:28 +00:00
|
|
|
/*
|
|
|
|
* From Coreboot src/southbridge/intel/bd82x6x/early_me.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011 The Chromium OS Authors. All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2016-01-17 23:11:50 +00:00
|
|
|
#include <dm.h>
|
2014-11-13 05:42:28 +00:00
|
|
|
#include <errno.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2018-07-19 10:07:33 +00:00
|
|
|
#include <sysreset.h>
|
2014-11-13 05:42:28 +00:00
|
|
|
#include <asm/pci.h>
|
2016-01-17 23:11:58 +00:00
|
|
|
#include <asm/cpu.h>
|
2014-11-13 05:42:28 +00:00
|
|
|
#include <asm/processor.h>
|
|
|
|
#include <asm/arch/me.h>
|
|
|
|
#include <asm/arch/pch.h>
|
|
|
|
#include <asm/io.h>
|
2020-05-10 17:40:11 +00:00
|
|
|
#include <linux/delay.h>
|
2014-11-13 05:42:28 +00:00
|
|
|
|
|
|
|
static const char *const me_ack_values[] = {
|
|
|
|
[ME_HFS_ACK_NO_DID] = "No DID Ack received",
|
|
|
|
[ME_HFS_ACK_RESET] = "Non-power cycle reset",
|
|
|
|
[ME_HFS_ACK_PWR_CYCLE] = "Power cycle reset",
|
|
|
|
[ME_HFS_ACK_S3] = "Go to S3",
|
|
|
|
[ME_HFS_ACK_S4] = "Go to S4",
|
|
|
|
[ME_HFS_ACK_S5] = "Go to S5",
|
|
|
|
[ME_HFS_ACK_GBL_RESET] = "Global Reset",
|
|
|
|
[ME_HFS_ACK_CONTINUE] = "Continue to boot"
|
|
|
|
};
|
|
|
|
|
2016-01-17 23:11:50 +00:00
|
|
|
int intel_early_me_init(struct udevice *me_dev)
|
2014-11-13 05:42:28 +00:00
|
|
|
{
|
|
|
|
int count;
|
|
|
|
struct me_uma uma;
|
|
|
|
struct me_hfs hfs;
|
|
|
|
|
|
|
|
debug("Intel ME early init\n");
|
|
|
|
|
|
|
|
/* Wait for ME UMA SIZE VALID bit to be set */
|
|
|
|
for (count = ME_RETRY; count > 0; --count) {
|
2016-01-17 23:11:50 +00:00
|
|
|
pci_read_dword_ptr(me_dev, &uma, PCI_ME_UMA);
|
2014-11-13 05:42:28 +00:00
|
|
|
if (uma.valid)
|
|
|
|
break;
|
|
|
|
udelay(ME_DELAY);
|
|
|
|
}
|
|
|
|
if (!count) {
|
|
|
|
printf("ERROR: ME is not ready!\n");
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for valid firmware */
|
2016-01-17 23:11:50 +00:00
|
|
|
pci_read_dword_ptr(me_dev, &hfs, PCI_ME_HFS);
|
2014-11-13 05:42:28 +00:00
|
|
|
if (hfs.fpt_bad) {
|
|
|
|
printf("WARNING: ME has bad firmware\n");
|
|
|
|
return -EBADF;
|
|
|
|
}
|
|
|
|
|
|
|
|
debug("Intel ME firmware is ready\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-01-17 23:11:50 +00:00
|
|
|
int intel_early_me_uma_size(struct udevice *me_dev)
|
2014-11-13 05:42:28 +00:00
|
|
|
{
|
|
|
|
struct me_uma uma;
|
|
|
|
|
2016-01-17 23:11:50 +00:00
|
|
|
pci_read_dword_ptr(me_dev, &uma, PCI_ME_UMA);
|
2014-11-13 05:42:28 +00:00
|
|
|
if (uma.valid) {
|
|
|
|
debug("ME: Requested %uMB UMA\n", uma.size);
|
|
|
|
return uma.size;
|
|
|
|
}
|
|
|
|
|
|
|
|
debug("ME: Invalid UMA size\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2016-01-17 23:11:50 +00:00
|
|
|
static inline void set_global_reset(struct udevice *dev, int enable)
|
2014-11-13 05:42:28 +00:00
|
|
|
{
|
|
|
|
u32 etr3;
|
|
|
|
|
2016-01-17 23:11:50 +00:00
|
|
|
dm_pci_read_config32(dev, ETR3, &etr3);
|
2014-11-13 05:42:28 +00:00
|
|
|
|
|
|
|
/* Clear CF9 Without Resume Well Reset Enable */
|
|
|
|
etr3 &= ~ETR3_CWORWRE;
|
|
|
|
|
|
|
|
/* CF9GR indicates a Global Reset */
|
|
|
|
if (enable)
|
|
|
|
etr3 |= ETR3_CF9GR;
|
|
|
|
else
|
|
|
|
etr3 &= ~ETR3_CF9GR;
|
|
|
|
|
2016-01-17 23:11:50 +00:00
|
|
|
dm_pci_write_config32(dev, ETR3, etr3);
|
2014-11-13 05:42:28 +00:00
|
|
|
}
|
|
|
|
|
2016-01-17 23:11:50 +00:00
|
|
|
int intel_early_me_init_done(struct udevice *dev, struct udevice *me_dev,
|
|
|
|
uint status)
|
2014-11-13 05:42:28 +00:00
|
|
|
{
|
|
|
|
int count;
|
|
|
|
u32 mebase_l, mebase_h;
|
|
|
|
struct me_hfs hfs;
|
|
|
|
struct me_did did = {
|
|
|
|
.init_done = ME_INIT_DONE,
|
|
|
|
.status = status
|
|
|
|
};
|
|
|
|
|
|
|
|
/* MEBASE from MESEG_BASE[35:20] */
|
2016-01-17 23:11:50 +00:00
|
|
|
dm_pci_read_config32(PCH_DEV, PCI_CPU_MEBASE_L, &mebase_l);
|
|
|
|
dm_pci_read_config32(PCH_DEV, PCI_CPU_MEBASE_H, &mebase_h);
|
2014-11-13 05:42:28 +00:00
|
|
|
mebase_h &= 0xf;
|
|
|
|
did.uma_base = (mebase_l >> 20) | (mebase_h << 12);
|
|
|
|
|
|
|
|
/* Send message to ME */
|
|
|
|
debug("ME: Sending Init Done with status: %d, UMA base: 0x%04x\n",
|
|
|
|
status, did.uma_base);
|
|
|
|
|
2016-01-17 23:11:50 +00:00
|
|
|
pci_write_dword_ptr(me_dev, &did, PCI_ME_H_GS);
|
2014-11-13 05:42:28 +00:00
|
|
|
|
|
|
|
/* Must wait for ME acknowledgement */
|
|
|
|
for (count = ME_RETRY; count > 0; --count) {
|
2016-01-17 23:11:50 +00:00
|
|
|
pci_read_dword_ptr(me_dev, &hfs, PCI_ME_HFS);
|
2014-11-13 05:42:28 +00:00
|
|
|
if (hfs.bios_msg_ack)
|
|
|
|
break;
|
|
|
|
udelay(ME_DELAY);
|
|
|
|
}
|
|
|
|
if (!count) {
|
|
|
|
printf("ERROR: ME failed to respond\n");
|
2016-01-17 23:11:50 +00:00
|
|
|
return -ETIMEDOUT;
|
2014-11-13 05:42:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the requested BIOS action */
|
|
|
|
debug("ME: Requested BIOS Action: %s\n", me_ack_values[hfs.ack_data]);
|
|
|
|
|
|
|
|
/* Check status after acknowledgement */
|
2016-03-12 05:07:00 +00:00
|
|
|
intel_me_status(me_dev);
|
2014-11-13 05:42:28 +00:00
|
|
|
|
|
|
|
switch (hfs.ack_data) {
|
|
|
|
case ME_HFS_ACK_CONTINUE:
|
|
|
|
/* Continue to boot */
|
|
|
|
return 0;
|
|
|
|
case ME_HFS_ACK_RESET:
|
|
|
|
/* Non-power cycle reset */
|
2016-01-17 23:11:50 +00:00
|
|
|
set_global_reset(dev, 0);
|
2018-07-19 10:07:33 +00:00
|
|
|
sysreset_walk_halt(SYSRESET_COLD);
|
2014-11-13 05:42:28 +00:00
|
|
|
break;
|
|
|
|
case ME_HFS_ACK_PWR_CYCLE:
|
|
|
|
/* Power cycle reset */
|
2016-01-17 23:11:50 +00:00
|
|
|
set_global_reset(dev, 0);
|
2018-07-19 10:07:33 +00:00
|
|
|
sysreset_walk_halt(SYSRESET_COLD);
|
2014-11-13 05:42:28 +00:00
|
|
|
break;
|
|
|
|
case ME_HFS_ACK_GBL_RESET:
|
|
|
|
/* Global reset */
|
2016-01-17 23:11:50 +00:00
|
|
|
set_global_reset(dev, 1);
|
2018-07-19 10:07:33 +00:00
|
|
|
sysreset_walk_halt(SYSRESET_COLD);
|
2014-11-13 05:42:28 +00:00
|
|
|
break;
|
|
|
|
case ME_HFS_ACK_S3:
|
|
|
|
case ME_HFS_ACK_S4:
|
|
|
|
case ME_HFS_ACK_S5:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-01-17 23:11:50 +00:00
|
|
|
return -EINVAL;
|
2014-11-13 05:42:28 +00:00
|
|
|
}
|
2016-01-17 23:11:50 +00:00
|
|
|
|
|
|
|
static const struct udevice_id ivybridge_syscon_ids[] = {
|
2016-01-17 23:11:58 +00:00
|
|
|
{ .compatible = "intel,me", .data = X86_SYSCON_ME },
|
2016-01-17 23:11:50 +00:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(syscon_intel_me) = {
|
|
|
|
.name = "intel_me_syscon",
|
|
|
|
.id = UCLASS_SYSCON,
|
|
|
|
.of_match = ivybridge_syscon_ids,
|
|
|
|
};
|