summaryrefslogtreecommitdiff
path: root/src/northbridge/amd
diff options
context:
space:
mode:
Diffstat (limited to 'src/northbridge/amd')
-rw-r--r--src/northbridge/amd/agesa/Makefile.inc9
-rw-r--r--src/northbridge/amd/agesa/acpi_tables.c82
-rw-r--r--src/northbridge/amd/agesa/agesa_helper.h4
-rw-r--r--src/northbridge/amd/agesa/agesawrapper.c1
-rw-r--r--src/northbridge/amd/agesa/def_callouts.c204
-rw-r--r--src/northbridge/amd/agesa/eventlog.c171
-rw-r--r--src/northbridge/amd/agesa/family12/state_machine.c2
-rw-r--r--src/northbridge/amd/agesa/oem_s3.c167
-rw-r--r--src/northbridge/amd/agesa/state_machine.c399
-rw-r--r--src/northbridge/amd/pi/Makefile.inc10
10 files changed, 4 insertions, 1045 deletions
diff --git a/src/northbridge/amd/agesa/Makefile.inc b/src/northbridge/amd/agesa/Makefile.inc
index 2c39b5124f..7de920e616 100644
--- a/src/northbridge/amd/agesa/Makefile.inc
+++ b/src/northbridge/amd/agesa/Makefile.inc
@@ -21,18 +21,9 @@ subdirs-$(CONFIG_NORTHBRIDGE_AMD_AGESA_FAMILY15) += family15
subdirs-$(CONFIG_NORTHBRIDGE_AMD_AGESA_FAMILY15_TN) += family15tn
subdirs-$(CONFIG_NORTHBRIDGE_AMD_AGESA_FAMILY16_KB) += family16kb
-romstage-y += def_callouts.c eventlog.c
-ramstage-y += def_callouts.c eventlog.c acpi_tables.c
-
ifeq ($(CONFIG_AGESA_LEGACY_WRAPPER), y)
romstage-y += agesawrapper.c
ramstage-y += agesawrapper.c
-else
-romstage-y += state_machine.c
-ramstage-y += state_machine.c
endif
-romstage-y += oem_s3.c
-ramstage-y += oem_s3.c
-
endif
diff --git a/src/northbridge/amd/agesa/acpi_tables.c b/src/northbridge/amd/agesa/acpi_tables.c
deleted file mode 100644
index 5335c02f5b..0000000000
--- a/src/northbridge/amd/agesa/acpi_tables.c
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * This file is part of the coreboot project.
- *
- * Copyright (C) 2011-2012 Advanced Micro Devices, Inc.
- * Copyright (C) 2016 Kyösti Mälkki
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- */
-
-#include <northbridge/amd/agesa/state_machine.h>
-#include <northbridge/amd/agesa/agesa_helper.h>
-
-#include "AGESA.h"
-
-/* Fields were removed from the structure and we cannot add them back
- * without new builds of the binaryPI blobs.
- */
-#if !IS_ENABLED(CONFIG_CPU_AMD_AGESA_BINARY_PI) || \
- IS_ENABLED(CONFIG_NORTHBRIDGE_AMD_PI_00630F01) || \
- IS_ENABLED(CONFIG_NORTHBRIDGE_AMD_PI_00730F01)
-
-#define HAS_ACPI_SRAT TRUE
-#define HAS_ACPI_SLIT TRUE
-#else
-#define HAS_ACPI_SRAT FALSE
-#define HAS_ACPI_SLIT FALSE
-#endif
-
-/* We will reference AmdLateParams later to copy ACPI tables. */
-static AMD_LATE_PARAMS *AmdLateParams;
-
-void agesawrapper_setlateinitptr(void *Late)
-{
- AmdLateParams = Late;
-}
-
-void completion_InitLate(struct sysinfo *cb, AMD_LATE_PARAMS *Late)
-{
- AmdLateParams = Late;
-}
-
-void *agesawrapper_getlateinitptr(int pick)
-{
- ASSERT(AmdLateParams != NULL);
-
- switch (pick) {
- case PICK_DMI:
- return AmdLateParams->DmiTable;
- case PICK_PSTATE:
- return AmdLateParams->AcpiPState;
-#if HAS_ACPI_SRAT
- case PICK_SRAT:
- return AmdLateParams->AcpiSrat;
-#endif
-#if HAS_ACPI_SLIT
- case PICK_SLIT:
- return AmdLateParams->AcpiSlit;
-#endif
- case PICK_WHEA_MCE:
- return AmdLateParams->AcpiWheaMce;
- case PICK_WHEA_CMC:
- return AmdLateParams->AcpiWheaCmc;
- case PICK_ALIB:
- return AmdLateParams->AcpiAlib;
- case PICK_IVRS:
- return AmdLateParams->AcpiIvrs;
- case PICK_CRAT:
- return AmdLateParams->AcpiCrat;
- case PICK_CDIT:
- return AmdLateParams->AcpiCdit;
- default:
- return NULL;
- }
- return NULL;
-}
diff --git a/src/northbridge/amd/agesa/agesa_helper.h b/src/northbridge/amd/agesa/agesa_helper.h
index 044393d4b9..17819e9567 100644
--- a/src/northbridge/amd/agesa/agesa_helper.h
+++ b/src/northbridge/amd/agesa/agesa_helper.h
@@ -57,4 +57,8 @@ void EmptyHeap(void);
void fixup_cbmem_to_UC(int s3resume);
void recover_postcar_frame(struct postcar_frame *pcf, int s3resume);
+void restore_mtrr(void);
+void backup_mtrr(void *mtrr_store, u32 *mtrr_store_size);
+const void *OemS3Saved_MTRR_Storage(void);
+
#endif /* _AGESA_HELPER_H_ */
diff --git a/src/northbridge/amd/agesa/agesawrapper.c b/src/northbridge/amd/agesa/agesawrapper.c
index 87a39a9f2b..768f10042f 100644
--- a/src/northbridge/amd/agesa/agesawrapper.c
+++ b/src/northbridge/amd/agesa/agesawrapper.c
@@ -22,7 +22,6 @@
#include <northbridge/amd/agesa/agesawrapper.h>
#include <northbridge/amd/agesa/BiosCallOuts.h>
#include "amdlib.h"
-#include <cpu/amd/agesa/s3_resume.h>
#include "heapManager.h"
diff --git a/src/northbridge/amd/agesa/def_callouts.c b/src/northbridge/amd/agesa/def_callouts.c
deleted file mode 100644
index e0999266f4..0000000000
--- a/src/northbridge/amd/agesa/def_callouts.c
+++ /dev/null
@@ -1,204 +0,0 @@
-/*
- * This file is part of the coreboot project.
- *
- * Copyright (C) 2011 Advanced Micro Devices, Inc.
- * Copyright (C) 2013 Sage Electronic Engineering, LLC
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- */
-
-#include <cbfs.h>
-#include <spd_bin.h>
-#include <string.h>
-
-#include "AGESA.h"
-#include "amdlib.h"
-#include "Ids.h"
-#include <northbridge/amd/agesa/state_machine.h>
-#include "BiosCallOuts.h"
-#include "dimmSpd.h"
-
-#if IS_ENABLED(CONFIG_NORTHBRIDGE_AMD_PI)
-#if IS_ENABLED(CONFIG_ARCH_ROMSTAGE_X86_64) || \
- IS_ENABLED(CONFIG_ARCH_RAMSTAGE_X86_64)
-#error "FIXME: CALLOUT_ENTRY is UINT32 Data, not UINT Data"
-#endif
-#endif
-
-AGESA_STATUS GetBiosCallout (UINT32 Func, UINTN Data, VOID *ConfigPtr)
-{
- AGESA_STATUS status;
- UINTN i;
-
- if (HAS_LEGACY_WRAPPER || ENV_RAMSTAGE) {
- /* One HeapManager serves them all. */
- status = HeapManagerCallout(Func, Data, ConfigPtr);
- if (status != AGESA_UNSUPPORTED)
- return status;
- }
-
-#if HAS_AGESA_FCH_OEM_CALLOUT
- if (!HAS_LEGACY_WRAPPER && Func == AGESA_FCH_OEM_CALLOUT) {
- agesa_fch_oem_config(Data, ConfigPtr);
- return AGESA_SUCCESS;
- }
-#endif
-
- for (i = 0; i < BiosCalloutsLen; i++) {
- if (BiosCallouts[i].CalloutName == Func)
- break;
- }
- if (i >= BiosCalloutsLen)
- return AGESA_UNSUPPORTED;
-
- return BiosCallouts[i].CalloutPtr (Func, Data, ConfigPtr);
-}
-
-AGESA_STATUS agesa_NoopUnsupported (UINT32 Func, UINTN Data, VOID *ConfigPtr)
-{
- return AGESA_UNSUPPORTED;
-}
-
-AGESA_STATUS agesa_NoopSuccess (UINT32 Func, UINTN Data, VOID *ConfigPtr)
-{
- return AGESA_SUCCESS;
-}
-
-AGESA_STATUS agesa_EmptyIdsInitData (UINT32 Func, UINTN Data, VOID *ConfigPtr)
-{
- IDS_NV_ITEM *IdsPtr = ((IDS_CALLOUT_STRUCT *) ConfigPtr)->IdsNvPtr;
- if (Data == IDS_CALLOUT_INIT)
- IdsPtr[0].IdsNvValue = IdsPtr[0].IdsNvId = 0xffff;
- return AGESA_SUCCESS;
-}
-
-AGESA_STATUS agesa_Reset (UINT32 Func, UINTN Data, VOID *ConfigPtr)
-{
- AGESA_STATUS Status;
- UINT8 Value;
- UINTN ResetType;
- AMD_CONFIG_PARAMS *StdHeader;
-
- ResetType = Data;
- StdHeader = ConfigPtr;
-
- //
- // Perform the RESET based upon the ResetType. In case of
- // WARM_RESET_WHENVER and COLD_RESET_WHENEVER, the request will go to
- // AmdResetManager. During the critical condition, where reset is required
- // immediately, the reset will be invoked directly by writing 0x04 to port
- // 0xCF9 (Reset Port).
- //
- switch (ResetType) {
- case WARM_RESET_WHENEVER:
- case COLD_RESET_WHENEVER:
- break;
-
- case WARM_RESET_IMMEDIATELY:
- case COLD_RESET_IMMEDIATELY:
- Value = 0x06;
- LibAmdIoWrite (AccessWidth8, 0xCf9, &Value, StdHeader);
- break;
-
- default:
- break;
- }
-
- Status = 0;
- return Status;
-}
-
-AGESA_STATUS agesa_RunFuncOnAp (UINT32 Func, UINTN Data, VOID *ConfigPtr)
-{
- AMD_CONFIG_PARAMS *StdHeader = ConfigPtr;
- AGESA_STATUS status;
- AP_EXE_PARAMS ApExeParams;
-
- memset(&ApExeParams, 0, sizeof(AP_EXE_PARAMS));
-
- if (HAS_LEGACY_WRAPPER) {
- ApExeParams.StdHeader.AltImageBasePtr = 0;
- ApExeParams.StdHeader.CalloutPtr = &GetBiosCallout;
- ApExeParams.StdHeader.Func = 0;
- ApExeParams.StdHeader.ImageBasePtr = 0;
- } else {
- memcpy(&ApExeParams.StdHeader, StdHeader, sizeof(*StdHeader));
- }
-
- ApExeParams.FunctionNumber = Func;
- ApExeParams.RelatedDataBlock = ConfigPtr;
-
-#if HAS_LEGACY_WRAPPER
- status = AmdLateRunApTask(&ApExeParams);
-#else
- status = module_dispatch(AMD_LATE_RUN_AP_TASK, &ApExeParams.StdHeader);
-#endif
-
- ASSERT(status == AGESA_SUCCESS);
- return status;
-}
-
-#if defined(AGESA_GNB_GFX_GET_VBIOS_IMAGE)
-AGESA_STATUS agesa_GfxGetVbiosImage(UINT32 Func, UINTN FchData, VOID *ConfigPrt)
-{
- GFX_VBIOS_IMAGE_INFO *pVbiosImageInfo = (GFX_VBIOS_IMAGE_INFO *)ConfigPrt;
- pVbiosImageInfo->ImagePtr = cbfs_boot_map_with_leak(
- "pci"CONFIG_VGA_BIOS_ID".rom",
- CBFS_TYPE_OPTIONROM, NULL);
- /* printk(BIOS_DEBUG, "IMGptr=%x\n", pVbiosImageInfo->ImagePtr); */
- return pVbiosImageInfo->ImagePtr == NULL ? AGESA_WARNING : AGESA_SUCCESS;
-}
-#endif
-
-AGESA_STATUS agesa_ReadSpd (UINT32 Func, UINTN Data, VOID *ConfigPtr)
-{
- AGESA_STATUS Status = AGESA_UNSUPPORTED;
-#ifdef __PRE_RAM__
- Status = AmdMemoryReadSPD (Func, Data, ConfigPtr);
-#endif
- return Status;
-}
-
-AGESA_STATUS agesa_ReadSpd_from_cbfs(UINT32 Func, UINTN Data, VOID *ConfigPtr)
-{
- AGESA_STATUS Status = AGESA_UNSUPPORTED;
-#ifdef __PRE_RAM__
- AGESA_READ_SPD_PARAMS *info = ConfigPtr;
- if (info->MemChannelId > 0)
- return AGESA_UNSUPPORTED;
- if (info->SocketId != 0)
- return AGESA_UNSUPPORTED;
- if (info->DimmId != 0)
- return AGESA_UNSUPPORTED;
-
- /* Read index 0, first SPD_SIZE bytes of spd.bin file. */
- if (read_ddr3_spd_from_cbfs((u8*)info->Buffer, 0) < 0)
- die("No SPD data\n");
-
- Status = AGESA_SUCCESS;
-#endif
- return Status;
-}
-
-#if HAS_AGESA_FCH_OEM_CALLOUT
-void agesa_fch_oem_config(uintptr_t Data, AMD_CONFIG_PARAMS *StdHeader)
-{
- /* FIXME: CAR_GLOBAL needed here to pass sysinfo. */
- struct sysinfo *cb_NA = NULL;
-
- if (StdHeader->Func == AMD_INIT_RESET) {
- printk(BIOS_DEBUG, "Fch OEM config in INIT RESET\n");
- board_FCH_InitReset(cb_NA, (FCH_RESET_DATA_BLOCK *)Data);
- } else if (StdHeader->Func == AMD_INIT_ENV) {
- printk(BIOS_DEBUG, "Fch OEM config in INIT ENV\n");
- board_FCH_InitEnv(cb_NA, (FCH_DATA_BLOCK *)Data);
- }
-}
-#endif
diff --git a/src/northbridge/amd/agesa/eventlog.c b/src/northbridge/amd/agesa/eventlog.c
deleted file mode 100644
index 33e5590530..0000000000
--- a/src/northbridge/amd/agesa/eventlog.c
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- * This file is part of the coreboot project.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- */
-
-#include <console/console.h>
-#include <stdint.h>
-#include <string.h>
-
-#include <northbridge/amd/agesa/state_machine.h>
-#include <northbridge/amd/agesa/BiosCallOuts.h>
-#include "amdlib.h"
-#include "AGESA.h"
-#include "AMD.h"
-
-#include <heapManager.h>
-
-static const char undefined[] = "undefined";
-
-/* Match order of enum AGESA_STRUCT_NAME. */
-static const char *AgesaFunctionNameStr[] = {
- "AmdInitRecovery", "AmdCreateStruct", "AmdInitEarly", "AmdInitEnv", "AmdInitLate",
- "AmdInitMid", "AmdInitPost", "AmdInitReset", "AmdInitResume", "AmdReleaseStruct",
- "AmdS3LateRestore","AmdS3Save", "AmdGetApicId", "AmdGetPciAddress", "AmdIdentifyCore",
- "AmdReadEventLog", "AmdGetAvailableExeCacheSize", "AmdLateRunApTask", "AmdIdentifyDimm",
-};
-
-/* heapManager.h */
-static const char *HeapStatusStr[] = {
- "DoNotExistYet", "LocalCache", "TempMem", "SystemMem", "DoNotExistAnymore","S3Resume"
-};
-
-/* This function has to match with enumeration of AGESA_STRUCT_NAME defined
- * inside AMD.h header file. Unfortunately those are different across
- * different vendorcode subtrees.
- *
- * TBD: Fix said header or move this function together with the strings above
- * under vendorcode/ tree.
- */
-
-const char *agesa_struct_name(int state)
-{
-#if IS_ENABLED(CONFIG_CPU_AMD_AGESA_OPENSOURCE)
- if ((state < AMD_INIT_RECOVERY) || (state > AMD_IDENTIFY_DIMMS))
- return undefined;
-
- int index = state - AMD_INIT_RECOVERY;
-#else
- state >>= 12;
- if ((state < AMD_INIT_RECOVERY >> 12) || (state > AMD_IDENTIFY_DIMMS >> 12))
- return undefined;
-
- int index = state - (AMD_INIT_RECOVERY >> 12);
-#endif
- return AgesaFunctionNameStr[index];
-}
-
-const char *heap_status_name(int status)
-{
- if ((status < HEAP_DO_NOT_EXIST_YET) || (status > HEAP_S3_RESUME))
- return undefined;
-
- int index = status - HEAP_DO_NOT_EXIST_YET;
- return HeapStatusStr[index];
-}
-
-/*
- * Possible AGESA_STATUS values:
- *
- * 0x0 = AGESA_SUCCESS
- * 0x1 = AGESA_UNSUPPORTED
- * 0x2 = AGESA_BOUNDS_CHK
- * 0x3 = AGESA_ALERT
- * 0x4 = AGESA_WARNING
- * 0x5 = AGESA_ERROR
- * 0x6 = AGESA_CRITICAL
- * 0x7 = AGESA_FATAL
- */
-static const char * decodeAGESA_STATUS(AGESA_STATUS sret)
-{
- const char* statusStrings[] = { "AGESA_SUCCESS", "AGESA_UNSUPPORTED",
- "AGESA_BOUNDS_CHK", "AGESA_ALERT",
- "AGESA_WARNING", "AGESA_ERROR",
- "AGESA_CRITICAL", "AGESA_FATAL"
- };
- if (sret > 7) return "unknown"; /* Non-AGESA error code */
- return statusStrings[sret];
-}
-
-static void show_event(EVENT_PARAMS *Event)
-{
- printk(BIOS_DEBUG,"\nEventLog: EventClass = %x, EventInfo = %x.\n",
- (unsigned int)Event->EventClass,
- (unsigned int)Event->EventInfo);
- printk(BIOS_DEBUG," Param1 = %x, Param2 = %x.\n",
- (unsigned int)Event->DataParam1,
- (unsigned int)Event->DataParam2);
- printk(BIOS_DEBUG," Param3 = %x, Param4 = %x.\n",
- (unsigned int)Event->DataParam3,
- (unsigned int)Event->DataParam4);
-}
-
-#define MAX_LOG_ENTRIES 100
-
-static void amd_flush_eventlog(EVENT_PARAMS *Event)
-{
- int i = 0;
-
- do {
- AGESA_STATUS status;
-#if HAS_LEGACY_WRAPPER
- status = AmdReadEventLog(Event);
-#else
- status = module_dispatch(AMD_READ_EVENT_LOG, &Event->StdHeader);
-#endif
- if (status != AGESA_SUCCESS)
- return;
- if (Event->EventClass == 0)
- return;
- show_event(Event);
- } while (++i < MAX_LOG_ENTRIES);
-}
-
-void agesawrapper_trace(AGESA_STATUS ret, AMD_CONFIG_PARAMS *StdHeader,
- const char *func)
-{
- EVENT_PARAMS AmdEventParams;
-
- printk(BIOS_DEBUG, "%s() returned %s\n", func, decodeAGESA_STATUS(ret));
- if (ret == AGESA_SUCCESS)
- return;
-
- memset(&AmdEventParams, 0, sizeof(EVENT_PARAMS));
-
- if (HAS_LEGACY_WRAPPER) {
- AmdEventParams.StdHeader.AltImageBasePtr = 0;
- AmdEventParams.StdHeader.CalloutPtr = &GetBiosCallout;
- AmdEventParams.StdHeader.Func = 0;
- AmdEventParams.StdHeader.ImageBasePtr = 0;
- AmdEventParams.StdHeader.HeapStatus = StdHeader->HeapStatus;
- } else {
- memcpy(&AmdEventParams.StdHeader, StdHeader, sizeof(*StdHeader));
- }
-
- amd_flush_eventlog(&AmdEventParams);
-}
-
-AGESA_STATUS agesawrapper_amdreadeventlog (UINT8 HeapStatus)
-{
- EVENT_PARAMS AmdEventParams;
-
- memset(&AmdEventParams, 0, sizeof(EVENT_PARAMS));
-
- AmdEventParams.StdHeader.AltImageBasePtr = 0;
- AmdEventParams.StdHeader.CalloutPtr = &GetBiosCallout;
- AmdEventParams.StdHeader.Func = 0;
- AmdEventParams.StdHeader.ImageBasePtr = 0;
- AmdEventParams.StdHeader.HeapStatus = HeapStatus;
-
- amd_flush_eventlog(&AmdEventParams);
-
- return AGESA_SUCCESS;
-}
diff --git a/src/northbridge/amd/agesa/family12/state_machine.c b/src/northbridge/amd/agesa/family12/state_machine.c
index ed216c74fb..52b065e9e3 100644
--- a/src/northbridge/amd/agesa/family12/state_machine.c
+++ b/src/northbridge/amd/agesa/family12/state_machine.c
@@ -20,8 +20,6 @@
#include <northbridge/amd/agesa/state_machine.h>
#include <northbridge/amd/agesa/agesa_helper.h>
-#include <cpu/amd/agesa/s3_resume.h>
-
#include <sb_cimx.h>
void platform_BeforeInitReset(struct sysinfo *cb, AMD_RESET_PARAMS *Reset)
diff --git a/src/northbridge/amd/agesa/oem_s3.c b/src/northbridge/amd/agesa/oem_s3.c
deleted file mode 100644
index f2cef990db..0000000000
--- a/src/northbridge/amd/agesa/oem_s3.c
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * This file is part of the coreboot project.
- *
- * Copyright (C) 2012 Advanced Micro Devices, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- */
-
-#include <spi-generic.h>
-#include <spi_flash.h>
-#include <string.h>
-#include <cbmem.h>
-#include <program_loading.h>
-#include <cpu/amd/agesa/s3_resume.h>
-#include <northbridge/amd/agesa/agesawrapper.h>
-#include <northbridge/amd/agesa/state_machine.h>
-#include <AGESA.h>
-#include <northbridge/amd/agesa/agesa_helper.h>
-
-typedef enum {
- S3DataTypeNonVolatile = 0, ///< NonVolatile Data Type
- S3DataTypeMTRR ///< MTRR storage
-} S3_DATA_TYPE;
-
-/* The size needs to be 4k aligned, which is the sector size of most flashes. */
-#define S3_DATA_MTRR_SIZE 0x1000
-#define S3_DATA_NONVOLATILE_SIZE 0x1000
-
-#if IS_ENABLED(CONFIG_HAVE_ACPI_RESUME) && \
- (S3_DATA_MTRR_SIZE + S3_DATA_NONVOLATILE_SIZE) > CONFIG_S3_DATA_SIZE
-#error "Please increase the value of S3_DATA_SIZE"
-#endif
-
-static void get_s3nv_data(S3_DATA_TYPE S3DataType, uintptr_t *pos, uintptr_t *len)
-{
- /* FIXME: Find file from CBFS. */
- u32 s3_data = CONFIG_S3_DATA_POS;
-
- switch (S3DataType) {
- case S3DataTypeMTRR:
- *pos = s3_data;
- *len = S3_DATA_MTRR_SIZE;
- break;
- case S3DataTypeNonVolatile:
- *pos = s3_data + S3_DATA_MTRR_SIZE;
- *len = S3_DATA_NONVOLATILE_SIZE;
- break;
- default:
- *pos = 0;
- *len = 0;
- break;
- }
-}
-
-AGESA_STATUS OemInitResume(AMD_S3_PARAMS *dataBlock)
-{
- uintptr_t pos, size;
- get_s3nv_data(S3DataTypeNonVolatile, &pos, &size);
-
- u32 len = *(u32*)pos;
-
- /* Test for uninitialized s3nv data in SPI. */
- if (len == 0 || len == (u32)-1ULL)
- return AGESA_FATAL;
-
- dataBlock->NvStorageSize = len;
- dataBlock->NvStorage = (void *) (pos + sizeof(u32));
- return AGESA_SUCCESS;
-}
-
-AGESA_STATUS OemS3LateRestore(AMD_S3_PARAMS *dataBlock)
-{
- char *heap = cbmem_find(CBMEM_ID_RESUME_SCRATCH);
- if (heap == NULL)
- return AGESA_FATAL;
-
- printk(BIOS_DEBUG, "Using resume HEAP at %08x\n",
- (unsigned int)(uintptr_t) heap);
-
- /* Return allocated CBMEM size, we do not keep track of
- * how much was actually used.
- */
- dataBlock->VolatileStorageSize = HIGH_MEMORY_SCRATCH;
- dataBlock->VolatileStorage = heap;
- return AGESA_SUCCESS;
-}
-
-#if ENV_RAMSTAGE
-
-static int spi_SaveS3info(u32 pos, u32 size, u8 *buf, u32 len)
-{
-#if IS_ENABLED(CONFIG_SPI_FLASH)
- struct spi_flash flash;
-
- spi_init();
- if (spi_flash_probe(0, 0, &flash))
- return -1;
-
- spi_flash_volatile_group_begin(&flash);
-
- spi_flash_erase(&flash, pos, size);
- spi_flash_write(&flash, pos, sizeof(len), &len);
- spi_flash_write(&flash, pos + sizeof(len), len, buf);
-
- spi_flash_volatile_group_end(&flash);
- return 0;
-#else
- return -1;
-#endif
-}
-
-static u8 MTRRStorage[S3_DATA_MTRR_SIZE];
-
-AGESA_STATUS OemS3Save(AMD_S3_PARAMS *dataBlock)
-{
- u32 MTRRStorageSize = 0;
- uintptr_t pos, size;
-
- romstage_ram_stack_base(HIGH_ROMSTAGE_STACK_SIZE, ROMSTAGE_STACK_CBMEM);
-
- /* To be consumed in AmdInitResume. */
- get_s3nv_data(S3DataTypeNonVolatile, &pos, &size);
- if (size && dataBlock->NvStorageSize)
- spi_SaveS3info(pos, size, dataBlock->NvStorage,
- dataBlock->NvStorageSize);
- else
- printk(BIOS_EMERG,
- "Error: Cannot store memory training results in SPI.\n"
- "Error: S3 resume will not be possible.\n"
- );
-
- /* To be consumed in AmdS3LateRestore. */
- char *heap = cbmem_add(CBMEM_ID_RESUME_SCRATCH, HIGH_MEMORY_SCRATCH);
- if (heap) {
- memset(heap, 0, HIGH_MEMORY_SCRATCH);
- memcpy(heap, dataBlock->VolatileStorage, dataBlock->VolatileStorageSize);
- }
-
- /* Collect MTRR setup. */
- backup_mtrr(MTRRStorage, &MTRRStorageSize);
-
- /* To be consumed in restore_mtrr, CPU enumeration in ramstage. */
- get_s3nv_data(S3DataTypeMTRR, &pos, &size);
- if (size && MTRRStorageSize)
- spi_SaveS3info(pos, size, MTRRStorage, MTRRStorageSize);
-
- return AGESA_SUCCESS;
-}
-
-#endif /* ENV_RAMSTAGE */
-
-const void *OemS3Saved_MTRR_Storage(void)
-{
- uintptr_t pos, size;
- get_s3nv_data(S3DataTypeMTRR, &pos, &size);
- if (!size)
- return NULL;
-
- return (void*)(pos + sizeof(UINT32));
-}
diff --git a/src/northbridge/amd/agesa/state_machine.c b/src/northbridge/amd/agesa/state_machine.c
deleted file mode 100644
index 015d445ab9..0000000000
--- a/src/northbridge/amd/agesa/state_machine.c
+++ /dev/null
@@ -1,399 +0,0 @@
-/*
- * This file is part of the coreboot project.
- *
- * Copyright (C) 2011-2012 Advanced Micro Devices, Inc.
- * Copyright (C) 2016 Kyösti Mälkki
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- */
-
-#include <stdint.h>
-#include <string.h>
-
-#include <arch/acpi.h>
-#include <bootstate.h>
-#include <cbfs.h>
-#include <cbmem.h>
-
-#include <northbridge/amd/agesa/state_machine.h>
-#include <northbridge/amd/agesa/agesa_helper.h>
-#include <northbridge/amd/agesa/BiosCallOuts.h>
-#include "amdlib.h"
-#include <cpu/amd/agesa/s3_resume.h>
-
-#include "AMD.h"
-
-#if IS_ENABLED(CONFIG_CPU_AMD_AGESA_OPENSOURCE)
-#include "Dispatcher.h"
-#endif
-
-#if ENV_ROMSTAGE
-#include <PlatformMemoryConfiguration.h>
-CONST PSO_ENTRY ROMDATA DefaultPlatformMemoryConfiguration[] = {PSO_END};
-#endif
-
-static void agesa_locate_image(AMD_CONFIG_PARAMS *StdHeader)
-{
-#if IS_ENABLED(CONFIG_CPU_AMD_AGESA_BINARY_PI)
- const char ModuleIdentifier[] = AGESA_ID;
- const void *agesa, *image;
- size_t file_size;
-
- agesa = cbfs_boot_map_with_leak((const char *)CONFIG_AGESA_CBFS_NAME,
- CBFS_TYPE_RAW, &file_size);
- if (agesa == NULL)
- return;
-
- image = LibAmdLocateImage(agesa, agesa + file_size, 4096,
- ModuleIdentifier);
- StdHeader->ImageBasePtr = (void*) image;
-#endif
-}
-
-void agesa_set_interface(struct sysinfo *cb)
-{
- memset(&cb->StdHeader, 0, sizeof(AMD_CONFIG_PARAMS));
-
- cb->StdHeader.CalloutPtr = GetBiosCallout;
-
- if (IS_ENABLED(CONFIG_CPU_AMD_AGESA_BINARY_PI)) {
- agesa_locate_image(&cb->StdHeader);
- AMD_IMAGE_HEADER *image =
- (void*)(uintptr_t)cb->StdHeader.ImageBasePtr;
- ASSERT(image);
- AMD_MODULE_HEADER *module =
- (void*)(uintptr_t)image->ModuleInfoOffset;
- ASSERT(module && module->ModuleDispatcher);
- }
-}
-
-AGESA_STATUS module_dispatch(AGESA_STRUCT_NAME func,
- AMD_CONFIG_PARAMS *StdHeader)
-{
- MODULE_ENTRY dispatcher;
-
-#if IS_ENABLED(CONFIG_CPU_AMD_AGESA_OPENSOURCE)
- dispatcher = AmdAgesaDispatcher;
-#endif
-#if IS_ENABLED(CONFIG_CPU_AMD_AGESA_BINARY_PI)
- AMD_IMAGE_HEADER *image = (void*)(uintptr_t)StdHeader->ImageBasePtr;
- AMD_MODULE_HEADER *module = (void*)(uintptr_t)image->ModuleInfoOffset;
- dispatcher = module->ModuleDispatcher;
-#endif
-
- StdHeader->Func = func;
- return dispatcher(StdHeader);
-}
-
-static AGESA_STATUS amd_create_struct(AMD_INTERFACE_PARAMS *aip,
- AGESA_STRUCT_NAME func, void *buf, size_t len)
-{
- aip->AgesaFunctionName = func;
- aip->AllocationMethod = 0;
- aip->NewStructPtr = buf;
- aip->NewStructSize = len;
- if (buf != NULL && len != 0)
- aip->AllocationMethod = ByHost;
-
- return module_dispatch(AMD_CREATE_STRUCT, &aip->StdHeader);
-}
-
-static AGESA_STATUS amd_release_struct(AMD_INTERFACE_PARAMS *aip)
-{
- /* Cannot release AMD_LATE_PARAMS until ACPI tables are done. */
- if (aip->AgesaFunctionName == AMD_INIT_LATE)
- return AGESA_SUCCESS;
-
- return module_dispatch(AMD_RELEASE_STRUCT, &aip->StdHeader);
-}
-
-/* By design, for each valid AGESA_STRUCT_NAME, AMD_CONFIG_PARAMS
- * can be evaluated to apply correct typecast based on Func field.
- */
-
-static AGESA_STATUS romstage_dispatch(struct sysinfo *cb,
- AGESA_STRUCT_NAME func, AMD_CONFIG_PARAMS *StdHeader)
-{
- AGESA_STATUS status = AGESA_UNSUPPORTED;
-
- switch (func)
- {
- case AMD_INIT_RESET:
- {
- AMD_RESET_PARAMS *param = (void *)StdHeader;
- platform_BeforeInitReset(cb, param);
- board_BeforeInitReset(cb, param);
- status = module_dispatch(func, StdHeader);
- break;
- }
-
- case AMD_INIT_EARLY:
- {
- AMD_EARLY_PARAMS *param = (void *)StdHeader;
- platform_BeforeInitEarly(cb, param);
- board_BeforeInitEarly(cb, param);
- status = module_dispatch(func, StdHeader);
- break;
- }
-
- case AMD_INIT_POST:
- {
- AMD_POST_PARAMS *param = (void *)StdHeader;
- platform_BeforeInitPost(cb, param);
- board_BeforeInitPost(cb, param);
- status = module_dispatch(func, StdHeader);
- platform_AfterInitPost(cb, param);
- break;
- }
-
- case AMD_INIT_RESUME:
- {
- AMD_RESUME_PARAMS *param = (void *)StdHeader;
- platform_BeforeInitResume(cb, param);
- status = module_dispatch(func, StdHeader);
- platform_AfterInitResume(cb, param);
- break;
- }
-
- default:
- {
- break;
- }
-
- }
- return status;
-}
-
-static AGESA_STATUS ramstage_dispatch(struct sysinfo *cb,
- AGESA_STRUCT_NAME func, AMD_CONFIG_PARAMS *StdHeader)
-{
- AGESA_STATUS status = AGESA_UNSUPPORTED;
-
- switch (func)
- {
- case AMD_INIT_ENV:
- {
- AMD_ENV_PARAMS *param = (void *)StdHeader;
- platform_BeforeInitEnv(cb, param);
- board_BeforeInitEnv(cb, param);
- status = module_dispatch(func, StdHeader);
- platform_AfterInitEnv(cb, param);
- break;
- }
-
- case AMD_S3LATE_RESTORE:
- {
- AMD_S3LATE_PARAMS *param = (void *)StdHeader;
- platform_BeforeS3LateRestore(cb, param);
- status = module_dispatch(func, StdHeader);
- platform_AfterS3LateRestore(cb, param);
- break;
- }
-
- case AMD_INIT_MID:
- {
- AMD_MID_PARAMS *param = (void *)StdHeader;
- platform_BeforeInitMid(cb, param);
- board_BeforeInitMid(cb, param);
- status = module_dispatch(func, StdHeader);
- break;
- }
-
- case AMD_S3_SAVE:
- {
- AMD_S3SAVE_PARAMS *param = (void *)StdHeader;
- status = module_dispatch(func, StdHeader);
- platform_AfterS3Save(cb, param);
- break;
- }
-
- case AMD_INIT_LATE:
- {
- AMD_LATE_PARAMS *param = (void *)StdHeader;
- status = module_dispatch(func, StdHeader);
- platform_AfterInitLate(cb, param);
- completion_InitLate(cb, param);
- break;
- }
-
- default:
- {
- break;
- }
-
- }
- return status;
-}
-
-/* DEBUG trace helper */
-
-struct agesa_state
-{
- u8 apic_id;
-
- AGESA_STRUCT_NAME func;
- const char *function_name;
-};
-
-static void state_on_entry(struct agesa_state *task, AGESA_STRUCT_NAME func,
- const char *struct_name)
-{
- task->apic_id = (u8) (cpuid_ebx(1) >> 24);
- task->func = func;
- task->function_name = struct_name;
-
- printk(BIOS_DEBUG, "\nAPIC %02d: ** Enter %s [%08x]\n",
- task->apic_id, task->function_name, task->func);
-}
-
-static void state_on_exit(struct agesa_state *task,
- AMD_CONFIG_PARAMS *StdHeader)
-{
- printk(BIOS_DEBUG, "APIC %02d: Heap in %s (%d) at 0x%08x\n",
- task->apic_id, heap_status_name(StdHeader->HeapStatus),
- StdHeader->HeapStatus, (u32)StdHeader->HeapBasePtr);
-
- printk(BIOS_DEBUG, "APIC %02d: ** Exit %s [%08x]\n",
- task->apic_id, task->function_name, task->func);
-}
-
-int agesa_execute_state(struct sysinfo *cb, AGESA_STRUCT_NAME func)
-{
- AMD_INTERFACE_PARAMS aip;
- union {
- AMD_RESET_PARAMS reset;
- AMD_S3LATE_PARAMS s3late;
- } agesa_params;
- void *buf = NULL;
- size_t len = 0;
- const char *state_name = agesa_struct_name(func);
-
- AGESA_STATUS status, final;
-
- struct agesa_state task;
- memset(&task, 0, sizeof(task));
- state_on_entry(&task, func, state_name);
-
- aip.StdHeader = cb->StdHeader;
-
- /* For these calls, heap is not available. */
- if (func == AMD_INIT_RESET || func == AMD_S3LATE_RESTORE) {
- buf = (void *) &agesa_params;
- len = sizeof(agesa_params);
- memcpy(buf, &cb->StdHeader, sizeof(cb->StdHeader));
- }
-
- status = amd_create_struct(&aip, func, buf, len);
- ASSERT(status == AGESA_SUCCESS);
-
- /* Must call the function buffer was allocated for.*/
- AMD_CONFIG_PARAMS *StdHeader = aip.NewStructPtr;
- ASSERT(StdHeader->Func == func);
-
- if (ENV_ROMSTAGE)
- final = romstage_dispatch(cb, func, StdHeader);
-
- if (ENV_RAMSTAGE)
- final = ramstage_dispatch(cb, func, StdHeader);
-
- agesawrapper_trace(final, StdHeader, state_name);
- ASSERT(final < AGESA_FATAL);
-
- status = amd_release_struct(&aip);
- ASSERT(status == AGESA_SUCCESS);
-
- state_on_exit(&task, &aip.StdHeader);
-
- return (final < AGESA_FATAL) ? 0 : -1;
-}
-
-#if ENV_RAMSTAGE
-
-static void amd_bs_ramstage_init(void *arg)
-{
- struct sysinfo *cb = arg;
-
- agesa_set_interface(cb);
-
- if (!acpi_is_wakeup_s3())
- agesa_execute_state(cb, AMD_INIT_ENV);
- else {
- agesa_execute_state(cb, AMD_S3LATE_RESTORE);
- fchs3earlyrestore(&cb->StdHeader);
- }
-}
-
-void sb_After_Pci_Restore_Init(void);
-
-static void amd_bs_dev_enable(void *arg)
-{
- struct sysinfo *cb = arg;
-
- if (!acpi_is_wakeup_s3())
- agesa_execute_state(cb, AMD_INIT_MID);
-
- /* FIXME */
- if (IS_ENABLED(CONFIG_AMD_SB_CIMX) && acpi_is_wakeup_s3())
- sb_After_Pci_Restore_Init();
-}
-
-static void amd_bs_post_device(void *arg)
-{
- struct sysinfo *cb = arg;
-
- if (acpi_is_wakeup_s3()) {
- fchs3laterestore(&cb->StdHeader);
- return;
- }
-
- agesa_execute_state(cb, AMD_INIT_LATE);
-
- if (!acpi_s3_resume_allowed())
- return;
-
- agesa_execute_state(cb, AMD_S3_SAVE);
-}
-
-static struct sysinfo state_machine;
-
-BOOT_STATE_INIT_ENTRY(BS_PRE_DEVICE, BS_ON_ENTRY, amd_bs_ramstage_init,
- &state_machine);
-
-BOOT_STATE_INIT_ENTRY(BS_DEV_ENABLE, BS_ON_ENTRY, amd_bs_dev_enable,
- &state_machine);
-
-BOOT_STATE_INIT_ENTRY(BS_POST_DEVICE, BS_ON_EXIT, amd_bs_post_device,
- &state_machine);
-
-#endif /* ENV_RAMSTAGE */
-
-/* Empty stubs for cases board does not need to override anything. */
-void __attribute__((weak))
-board_BeforeInitReset(struct sysinfo *cb, AMD_RESET_PARAMS *Reset) { }
-void __attribute__((weak))
-board_BeforeInitEarly(struct sysinfo *cb, AMD_EARLY_PARAMS *Early) { }
-void __attribute__((weak))
-board_BeforeInitPost(struct sysinfo *cb, AMD_POST_PARAMS *Post) { }
-void __attribute__((weak))
-board_BeforeInitEnv(struct sysinfo *cb, AMD_ENV_PARAMS *Env) { }
-void __attribute__((weak))
-board_BeforeInitMid(struct sysinfo *cb, AMD_MID_PARAMS *Mid) { }
-
-AGESA_STATUS __attribute__((weak))
-fchs3earlyrestore(AMD_CONFIG_PARAMS *StdHeader)
-{
- return AGESA_SUCCESS;
-}
-
-AGESA_STATUS __attribute__((weak))
-fchs3laterestore(AMD_CONFIG_PARAMS *StdHeader)
-{
- return AGESA_SUCCESS;
-}
diff --git a/src/northbridge/amd/pi/Makefile.inc b/src/northbridge/amd/pi/Makefile.inc
index 93c87ecc68..c2c8d8818d 100644
--- a/src/northbridge/amd/pi/Makefile.inc
+++ b/src/northbridge/amd/pi/Makefile.inc
@@ -22,18 +22,8 @@ subdirs-$(CONFIG_NORTHBRIDGE_AMD_PI_00660F01) += 00660F01
ifeq ($(CONFIG_BINARYPI_LEGACY_WRAPPER), y)
romstage-y += agesawrapper.c
ramstage-y += agesawrapper.c
-else
-romstage-y += ../agesa/state_machine.c
-ramstage-y += ../agesa/state_machine.c
-
-romstage-y += ../agesa/eventlog.c
-ramstage-y += ../agesa/eventlog.c
-
endif
-romstage-y += ../agesa/def_callouts.c ../agesa/eventlog.c
-ramstage-y += ../agesa/def_callouts.c ../agesa/eventlog.c ../agesa/acpi_tables.c
-
romstage-y += ramtop.c
postcar-y += ramtop.c
ramstage-y += ramtop.c