blob: b94f3a65b904eac276ded329f6f9cf18ac5b647a [file] [log] [blame]
Angel Ponsae593872020-04-04 18:50:57 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Martin Rothc450fbe2017-10-02 13:46:50 -06002
Marc Jonesa9f72772017-11-16 18:47:36 -07003#include <device/device.h>
Martin Rothc450fbe2017-10-02 13:46:50 -06004#include <device/pci_def.h>
Richard Spiegel0ad74ac2017-12-08 16:53:29 -07005#include <amdblocks/BiosCallOuts.h>
Elyes HAOUAS20eaef02019-03-29 17:45:28 +01006#include <console/console.h>
Martin Rothc450fbe2017-10-02 13:46:50 -06007#include <soc/southbridge.h>
Marc Jonesa9f72772017-11-16 18:47:36 -07008#include <soc/pci_devs.h>
Richard Spiegel0ad74ac2017-12-08 16:53:29 -07009#include <amdblocks/agesawrapper.h>
Marc Jonesafd03d82017-11-16 10:01:08 -070010#include <amdblocks/dimm_spd.h>
Richard Spiegela9f49362018-03-05 08:11:50 -070011#include <amdblocks/car.h>
Martin Rothc450fbe2017-10-02 13:46:50 -060012
Elyes HAOUAS20eaef02019-03-29 17:45:28 +010013#include "chip.h"
14
Richard Spiegel271b8a52018-11-06 16:32:28 -070015void __weak platform_FchParams_reset(FCH_RESET_DATA_BLOCK *FchParams_reset) {}
Richard Spiegeld1a44a12017-12-26 08:26:31 -070016
Richard Spiegel271b8a52018-11-06 16:32:28 -070017AGESA_STATUS agesa_fch_initreset(uint32_t Func, uintptr_t FchData,
18 void *ConfigPtr)
Martin Rothc450fbe2017-10-02 13:46:50 -060019{
20 AMD_CONFIG_PARAMS *StdHeader = ConfigPtr;
21
22 if (StdHeader->Func == AMD_INIT_RESET) {
23 FCH_RESET_DATA_BLOCK *FchParams_reset;
24 FchParams_reset = (FCH_RESET_DATA_BLOCK *)FchData;
25 printk(BIOS_DEBUG, "Fch OEM config in INIT RESET ");
Martin Rothc450fbe2017-10-02 13:46:50 -060026
27 /* Get platform specific configuration changes */
28 platform_FchParams_reset(FchParams_reset);
29
30 printk(BIOS_DEBUG, "Done\n");
31 }
32
33 return AGESA_SUCCESS;
34}
35
Richard Spiegel271b8a52018-11-06 16:32:28 -070036AGESA_STATUS agesa_fch_initenv(uint32_t Func, uintptr_t FchData,
37 void *ConfigPtr)
Martin Rothc450fbe2017-10-02 13:46:50 -060038{
39 AMD_CONFIG_PARAMS *StdHeader = ConfigPtr;
Kyösti Mälkkie7377552018-06-21 16:20:55 +030040 const struct device *dev = pcidev_path_on_root(SATA_DEVFN);
Martin Rothc450fbe2017-10-02 13:46:50 -060041
42 if (StdHeader->Func == AMD_INIT_ENV) {
43 FCH_DATA_BLOCK *FchParams_env = (FCH_DATA_BLOCK *)FchData;
44 printk(BIOS_DEBUG, "Fch OEM config in INIT ENV ");
45
Martin Rothc450fbe2017-10-02 13:46:50 -060046 /* XHCI configuration */
Julius Wernercd49cce2019-03-05 16:53:33 -080047 if (CONFIG(STONEYRIDGE_XHCI_ENABLE))
Martin Rothc450fbe2017-10-02 13:46:50 -060048 FchParams_env->Usb.Xhci0Enable = TRUE;
49 else
50 FchParams_env->Usb.Xhci0Enable = FALSE;
51 FchParams_env->Usb.Xhci1Enable = FALSE;
52
Martin Rothc450fbe2017-10-02 13:46:50 -060053 /* SATA configuration */
54 FchParams_env->Sata.SataClass = CONFIG_STONEYRIDGE_SATA_MODE;
Richard Spiegelbb18b432018-08-03 10:37:28 -070055 if (dev && dev->enabled) {
56 switch ((SATA_CLASS)CONFIG_STONEYRIDGE_SATA_MODE) {
57 case SataRaid:
58 case SataAhci:
59 case SataAhci7804:
60 case SataLegacyIde:
61 FchParams_env->Sata.SataIdeMode = FALSE;
62 break;
63 case SataIde2Ahci:
64 case SataIde2Ahci7804:
65 default: /* SataNativeIde */
66 FchParams_env->Sata.SataIdeMode = TRUE;
67 break;
68 }
69 } else
Martin Rothc450fbe2017-10-02 13:46:50 -060070 FchParams_env->Sata.SataIdeMode = FALSE;
Martin Rothc450fbe2017-10-02 13:46:50 -060071
72 /* Platform updates */
73 platform_FchParams_env(FchParams_env);
74
75 printk(BIOS_DEBUG, "Done\n");
76 }
77
78 return AGESA_SUCCESS;
79}
80
Richard Spiegel271b8a52018-11-06 16:32:28 -070081AGESA_STATUS agesa_ReadSpd(uint32_t Func, uintptr_t Data, void *ConfigPtr)
Martin Rothc450fbe2017-10-02 13:46:50 -060082{
Marc Jonesa9f72772017-11-16 18:47:36 -070083 uint8_t spd_address;
84 int err;
85 DEVTREE_CONST struct device *dev;
86 DEVTREE_CONST struct soc_amd_stoneyridge_config *conf;
87 AGESA_READ_SPD_PARAMS *info = ConfigPtr;
Martin Rothc450fbe2017-10-02 13:46:50 -060088
Kyösti Mälkki11cac782022-04-07 07:16:48 +030089 if (!ENV_RAMINIT)
Marc Jonesa9f72772017-11-16 18:47:36 -070090 return AGESA_UNSUPPORTED;
Martin Rothc450fbe2017-10-02 13:46:50 -060091
Kyösti Mälkkie7377552018-06-21 16:20:55 +030092 dev = pcidev_path_on_root(DCT_DEVFN);
Marc Jonesa9f72772017-11-16 18:47:36 -070093 if (dev == NULL)
94 return AGESA_ERROR;
Martin Rothc450fbe2017-10-02 13:46:50 -060095
Marc Jonesa9f72772017-11-16 18:47:36 -070096 conf = dev->chip_info;
97 if (conf == NULL)
98 return AGESA_ERROR;
Martin Rothc450fbe2017-10-02 13:46:50 -060099
Marc Jonesa9f72772017-11-16 18:47:36 -0700100 if (info->SocketId >= ARRAY_SIZE(conf->spd_addr_lookup))
101 return AGESA_ERROR;
102 if (info->MemChannelId >= ARRAY_SIZE(conf->spd_addr_lookup[0]))
103 return AGESA_ERROR;
104 if (info->DimmId >= ARRAY_SIZE(conf->spd_addr_lookup[0][0]))
105 return AGESA_ERROR;
106
107 spd_address = conf->spd_addr_lookup
108 [info->SocketId][info->MemChannelId][info->DimmId];
109 if (spd_address == 0)
110 return AGESA_ERROR;
111
112 err = mainboard_read_spd(spd_address, (void *)info->Buffer,
113 CONFIG_DIMM_SPD_SIZE);
114
115 /* Read the SPD if the mainboard didn't fill the buffer */
116 if (err || (*info->Buffer == 0))
117 err = sb_read_spd(spd_address, (void *)info->Buffer,
118 CONFIG_DIMM_SPD_SIZE);
119
120 if (err)
121 return AGESA_ERROR;
122
123 return AGESA_SUCCESS;
124}
125
Richard Spiegel271b8a52018-11-06 16:32:28 -0700126AGESA_STATUS agesa_HaltThisAp(uint32_t Func, uintptr_t Data, void *ConfigPtr)
Richard Spiegela9f49362018-03-05 08:11:50 -0700127{
128 AGESA_HALT_THIS_AP_PARAMS *info = ConfigPtr;
129 uint32_t flags = 0;
130
131 if (info->PrimaryCore == TRUE)
132 return AGESA_UNSUPPORTED; /* force normal path */
133 if (info->ExecWbinvd == TRUE)
134 flags |= 1;
135 if (info->CacheEn == TRUE)
136 flags |= 2;
137
138 ap_teardown_car(flags); /* does not return */
139
140 /* Should never reach here */
141 return AGESA_UNSUPPORTED;
142}
143
Marc Jonesa9f72772017-11-16 18:47:36 -0700144/* Allow mainboards to fill the SPD buffer */
Aaron Durbin64031672018-04-21 14:45:32 -0600145__weak int mainboard_read_spd(uint8_t spdAddress, char *buf,
Marc Jonesa9f72772017-11-16 18:47:36 -0700146 size_t len)
147{
148 printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__);
149 return -1; /* SPD not read */
Martin Rothc450fbe2017-10-02 13:46:50 -0600150}