blob: dfb42ae70429c51d087a5d0cd0cbc5f9d73f5579 [file] [log] [blame]
Angel Pons4b429832020-04-02 23:48:50 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +02002
Elyes HAOUAS19f5ba82018-10-14 14:52:06 +02003#include <Porting.h>
4#include <AGESA.h>
Kyösti Mälkki2446c1e2020-07-09 07:13:37 +03005#include <amdblocks/biosram.h>
Kyösti Mälkki64df52e2017-09-01 06:13:08 +03006#include <arch/io.h>
Nico Huber3e1b3b12018-10-07 12:45:47 +02007#include <cf9_reset.h>
Elyes HAOUAS20eaef02019-03-29 17:45:28 +01008#include <console/console.h>
Kyösti Mälkki64df52e2017-09-01 06:13:08 +03009#include <device/device.h>
10#include <device/pci_def.h>
Patrick Rudolphe56189c2018-04-18 10:11:59 +020011#include <device/pci_ops.h>
Kyösti Mälkki64df52e2017-09-01 06:13:08 +030012#include <smp/node.h>
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +020013#include <northbridge/amd/agesa/state_machine.h>
14#include <northbridge/amd/agesa/agesa_helper.h>
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +020015#include <sb_cimx.h>
16
17void platform_BeforeInitReset(struct sysinfo *cb, AMD_RESET_PARAMS *Reset)
18{
Kyösti Mälkki3d5e1e52019-12-03 14:06:02 +020019 if (!boot_cpu())
20 return;
21
Kyösti Mälkki520717d2019-12-15 21:37:48 +020022 sb_Poweron_Init();
Kyösti Mälkki3d5e1e52019-12-03 14:06:02 +020023
Kyösti Mälkki64df52e2017-09-01 06:13:08 +030024 /* Reboots with outb(3,0x92), outb(4,0xcf9) or triple-fault all
25 * would fail later in AmdInitPost(), when DRAM is already configured
26 * and C6DramLock bit has been set.
27 *
28 * As a workaround, do a hard reset to clear C6DramLock bit.
29 */
Kyösti Mälkki3d5e1e52019-12-03 14:06:02 +020030
Kyösti Mälkki64df52e2017-09-01 06:13:08 +030031#ifdef __SIMPLE_DEVICE__
32 pci_devfn_t dev = PCI_DEV(0, 0x18, 2);
33#else
Kyösti Mälkki4ad7f5b2018-05-22 01:15:17 +030034 struct device *dev = pcidev_on_root(0x18, 2);
Kyösti Mälkki64df52e2017-09-01 06:13:08 +030035#endif
Kyösti Mälkki3d5e1e52019-12-03 14:06:02 +020036 u32 mct_cfg_lo = pci_read_config32(dev, 0x118);
Elyes Haouasf9b535e2022-07-16 09:47:42 +020037 if (mct_cfg_lo & (1 << 19)) {
Kyösti Mälkki3d5e1e52019-12-03 14:06:02 +020038 printk(BIOS_CRIT, "C6DramLock is set, resetting\n");
39 system_reset();
Kyösti Mälkki64df52e2017-09-01 06:13:08 +030040 }
Kyösti Mälkki3d5e1e52019-12-03 14:06:02 +020041
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +020042}
43
44void platform_BeforeInitEarly(struct sysinfo *cb, AMD_EARLY_PARAMS *Early)
45{
46}
47
48void platform_BeforeInitPost(struct sysinfo *cb, AMD_POST_PARAMS *Post)
49{
Mike Banone7f176c2020-01-19 21:42:09 +030050 Post->MemConfig.BottomIo = (UINT16)(MIN(0xE0000000,
51 MAX(0x28000000, CONFIG_BOTTOMIO_POSITION)) >> 24) & 0xF8;
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +020052}
53
54void platform_AfterInitPost(struct sysinfo *cb, AMD_POST_PARAMS *Post)
55{
56 backup_top_of_low_cacheable(Post->MemConfig.Sub4GCacheTop);
57}
58
59void platform_BeforeInitResume(struct sysinfo *cb, AMD_RESUME_PARAMS *Resume)
60{
61 OemInitResume(&Resume->S3DataBlock);
62}
63
64void platform_AfterInitResume(struct sysinfo *cb, AMD_RESUME_PARAMS *Resume)
65{
66}
67
68void platform_BeforeInitEnv(struct sysinfo *cb, AMD_ENV_PARAMS *Env)
69{
70 EmptyHeap();
71}
72
73void platform_AfterInitEnv(struct sysinfo *cb, AMD_ENV_PARAMS *Env)
74{
75 amd_initenv();
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +020076}
77
78void platform_BeforeS3LateRestore(struct sysinfo *cb, AMD_S3LATE_PARAMS *S3Late)
79{
80 OemS3LateRestore(&S3Late->S3DataBlock);
81}
82
83void platform_AfterS3LateRestore(struct sysinfo *cb, AMD_S3LATE_PARAMS *S3Late)
84{
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +020085}
86
87void platform_BeforeInitMid(struct sysinfo *cb, AMD_MID_PARAMS *Mid)
88{
89 sb_After_Pci_Init();
90 sb_Mid_Post_Init();
91
92 amd_initcpuio();
93}
94
Michał Żygowski506b9c12019-12-20 16:57:13 +010095void platform_BeforeInitLate(struct sysinfo *cb, AMD_LATE_PARAMS *Late)
96{
97}
98
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +020099void platform_AfterInitLate(struct sysinfo *cb, AMD_LATE_PARAMS *Late)
100{
101 sb_Late_Post();
102}
103
104void platform_AfterS3Save(struct sysinfo *cb, AMD_S3SAVE_PARAMS *S3Save)
105{
106 OemS3Save(&S3Save->S3DataBlock);
107}