Angel Pons | 8a3453f | 2020-04-02 23:48:19 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Kyösti Mälkki | c459f96 | 2014-05-04 17:07:45 +0300 | [diff] [blame] | 2 | |
Kyösti Mälkki | 36abdc4 | 2014-05-05 16:40:15 +0300 | [diff] [blame] | 3 | #include <cbfs.h> |
Elyes HAOUAS | 20eaef0 | 2019-03-29 17:45:28 +0100 | [diff] [blame] | 4 | #include <console/console.h> |
Patrick Georgi | 0e3c59e | 2017-01-28 15:59:25 +0100 | [diff] [blame] | 5 | #include <spd_bin.h> |
Kyösti Mälkki | c7dcec6 | 2017-07-28 04:48:35 +0300 | [diff] [blame] | 6 | #include <string.h> |
Kyösti Mälkki | 36abdc4 | 2014-05-05 16:40:15 +0300 | [diff] [blame] | 7 | |
Elyes HAOUAS | 19f5ba8 | 2018-10-14 14:52:06 +0200 | [diff] [blame] | 8 | #include <AGESA.h> |
| 9 | #include <amdlib.h> |
Kyösti Mälkki | c459f96 | 2014-05-04 17:07:45 +0300 | [diff] [blame] | 10 | #include "Ids.h" |
Kyösti Mälkki | c7dcec6 | 2017-07-28 04:48:35 +0300 | [diff] [blame] | 11 | #include <northbridge/amd/agesa/state_machine.h> |
Kyösti Mälkki | d4955f0 | 2017-09-08 07:14:17 +0300 | [diff] [blame] | 12 | #include <northbridge/amd/agesa/BiosCallOuts.h> |
| 13 | #include <northbridge/amd/agesa/dimmSpd.h> |
Kyösti Mälkki | c459f96 | 2014-05-04 17:07:45 +0300 | [diff] [blame] | 14 | |
Kyösti Mälkki | d8bf22a | 2020-06-08 06:05:03 +0300 | [diff] [blame] | 15 | #if ENV_X86_64 && CONFIG(NORTHBRIDGE_AMD_PI) |
Kyösti Mälkki | 9de8261 | 2017-04-13 16:56:07 +0300 | [diff] [blame] | 16 | #error "FIXME: CALLOUT_ENTRY is UINT32 Data, not UINT Data" |
| 17 | #endif |
Kyösti Mälkki | 9de8261 | 2017-04-13 16:56:07 +0300 | [diff] [blame] | 18 | |
Stefan Reinauer | dd132a5 | 2015-07-30 11:16:37 -0700 | [diff] [blame] | 19 | AGESA_STATUS GetBiosCallout (UINT32 Func, UINTN Data, VOID *ConfigPtr) |
Kyösti Mälkki | 6025efa | 2014-05-05 13:20:56 +0300 | [diff] [blame] | 20 | { |
Kyösti Mälkki | 82fbda7 | 2015-01-02 22:46:32 +0200 | [diff] [blame] | 21 | AGESA_STATUS status; |
Kyösti Mälkki | 6025efa | 2014-05-05 13:20:56 +0300 | [diff] [blame] | 22 | UINTN i; |
| 23 | |
Kyösti Mälkki | 46f04cb | 2017-09-06 15:42:23 +0300 | [diff] [blame] | 24 | if (ENV_RAMSTAGE) { |
Kyösti Mälkki | 3b4b069 | 2017-09-08 07:37:06 +0300 | [diff] [blame] | 25 | /* One HeapManager serves them all. */ |
| 26 | status = HeapManagerCallout(Func, Data, ConfigPtr); |
| 27 | if (status != AGESA_UNSUPPORTED) |
| 28 | return status; |
| 29 | } |
Kyösti Mälkki | 82fbda7 | 2015-01-02 22:46:32 +0200 | [diff] [blame] | 30 | |
Kyösti Mälkki | bf201d5 | 2017-03-30 17:26:25 +0300 | [diff] [blame] | 31 | #if HAS_AGESA_FCH_OEM_CALLOUT |
Kyösti Mälkki | 46f04cb | 2017-09-06 15:42:23 +0300 | [diff] [blame] | 32 | if (Func == AGESA_FCH_OEM_CALLOUT) { |
Kyösti Mälkki | bf201d5 | 2017-03-30 17:26:25 +0300 | [diff] [blame] | 33 | agesa_fch_oem_config(Data, ConfigPtr); |
| 34 | return AGESA_SUCCESS; |
| 35 | } |
| 36 | #endif |
| 37 | |
Kyösti Mälkki | 6025efa | 2014-05-05 13:20:56 +0300 | [diff] [blame] | 38 | for (i = 0; i < BiosCalloutsLen; i++) { |
| 39 | if (BiosCallouts[i].CalloutName == Func) |
| 40 | break; |
| 41 | } |
Elyes HAOUAS | 5a7e72f | 2016-08-23 21:36:02 +0200 | [diff] [blame] | 42 | if (i >= BiosCalloutsLen) |
Kyösti Mälkki | 6025efa | 2014-05-05 13:20:56 +0300 | [diff] [blame] | 43 | return AGESA_UNSUPPORTED; |
| 44 | |
Elyes Haouas | 76c6323 | 2022-07-16 09:47:00 +0200 | [diff] [blame] | 45 | return BiosCallouts[i].CalloutPtr(Func, Data, ConfigPtr); |
Kyösti Mälkki | 6025efa | 2014-05-05 13:20:56 +0300 | [diff] [blame] | 46 | } |
| 47 | |
Elyes Haouas | 76c6323 | 2022-07-16 09:47:00 +0200 | [diff] [blame] | 48 | AGESA_STATUS agesa_NoopUnsupported(UINT32 Func, UINTN Data, VOID *ConfigPtr) |
Kyösti Mälkki | c459f96 | 2014-05-04 17:07:45 +0300 | [diff] [blame] | 49 | { |
| 50 | return AGESA_UNSUPPORTED; |
| 51 | } |
| 52 | |
Elyes Haouas | 76c6323 | 2022-07-16 09:47:00 +0200 | [diff] [blame] | 53 | AGESA_STATUS agesa_NoopSuccess(UINT32 Func, UINTN Data, VOID *ConfigPtr) |
Kyösti Mälkki | c459f96 | 2014-05-04 17:07:45 +0300 | [diff] [blame] | 54 | { |
| 55 | return AGESA_SUCCESS; |
| 56 | } |
| 57 | |
Elyes Haouas | 76c6323 | 2022-07-16 09:47:00 +0200 | [diff] [blame] | 58 | AGESA_STATUS agesa_EmptyIdsInitData(UINT32 Func, UINTN Data, VOID *ConfigPtr) |
Kyösti Mälkki | c459f96 | 2014-05-04 17:07:45 +0300 | [diff] [blame] | 59 | { |
| 60 | IDS_NV_ITEM *IdsPtr = ((IDS_CALLOUT_STRUCT *) ConfigPtr)->IdsNvPtr; |
| 61 | if (Data == IDS_CALLOUT_INIT) |
| 62 | IdsPtr[0].IdsNvValue = IdsPtr[0].IdsNvId = 0xffff; |
| 63 | return AGESA_SUCCESS; |
| 64 | } |
Kyösti Mälkki | 5e19fa4 | 2014-05-04 23:13:54 +0300 | [diff] [blame] | 65 | |
Elyes Haouas | 76c6323 | 2022-07-16 09:47:00 +0200 | [diff] [blame] | 66 | AGESA_STATUS agesa_Reset(UINT32 Func, UINTN Data, VOID *ConfigPtr) |
Kyösti Mälkki | 5e19fa4 | 2014-05-04 23:13:54 +0300 | [diff] [blame] | 67 | { |
| 68 | AGESA_STATUS Status; |
| 69 | UINT8 Value; |
| 70 | UINTN ResetType; |
| 71 | AMD_CONFIG_PARAMS *StdHeader; |
| 72 | |
| 73 | ResetType = Data; |
| 74 | StdHeader = ConfigPtr; |
| 75 | |
| 76 | // |
| 77 | // Perform the RESET based upon the ResetType. In case of |
Elyes HAOUAS | 1895838 | 2018-08-07 12:23:16 +0200 | [diff] [blame] | 78 | // WARM_RESET_WHENEVER and COLD_RESET_WHENEVER, the request will go to |
Kyösti Mälkki | 5e19fa4 | 2014-05-04 23:13:54 +0300 | [diff] [blame] | 79 | // AmdResetManager. During the critical condition, where reset is required |
| 80 | // immediately, the reset will be invoked directly by writing 0x04 to port |
| 81 | // 0xCF9 (Reset Port). |
| 82 | // |
| 83 | switch (ResetType) { |
| 84 | case WARM_RESET_WHENEVER: |
| 85 | case COLD_RESET_WHENEVER: |
| 86 | break; |
| 87 | |
| 88 | case WARM_RESET_IMMEDIATELY: |
| 89 | case COLD_RESET_IMMEDIATELY: |
| 90 | Value = 0x06; |
Elyes Haouas | 76c6323 | 2022-07-16 09:47:00 +0200 | [diff] [blame] | 91 | LibAmdIoWrite(AccessWidth8, 0xCf9, &Value, StdHeader); |
Kyösti Mälkki | 5e19fa4 | 2014-05-04 23:13:54 +0300 | [diff] [blame] | 92 | break; |
| 93 | |
| 94 | default: |
| 95 | break; |
| 96 | } |
| 97 | |
| 98 | Status = 0; |
| 99 | return Status; |
| 100 | } |
Kyösti Mälkki | 6b4b151 | 2014-05-05 12:05:53 +0300 | [diff] [blame] | 101 | |
Elyes Haouas | 76c6323 | 2022-07-16 09:47:00 +0200 | [diff] [blame] | 102 | AGESA_STATUS agesa_RunFuncOnAp(UINT32 Func, UINTN Data, VOID *ConfigPtr) |
Kyösti Mälkki | 6b4b151 | 2014-05-05 12:05:53 +0300 | [diff] [blame] | 103 | { |
Kyösti Mälkki | 28c4d2f | 2016-11-25 11:21:02 +0200 | [diff] [blame] | 104 | AMD_CONFIG_PARAMS *StdHeader = ConfigPtr; |
Kyösti Mälkki | c7dcec6 | 2017-07-28 04:48:35 +0300 | [diff] [blame] | 105 | AGESA_STATUS status; |
| 106 | AP_EXE_PARAMS ApExeParams; |
Kyösti Mälkki | 6b4b151 | 2014-05-05 12:05:53 +0300 | [diff] [blame] | 107 | |
Kyösti Mälkki | c7dcec6 | 2017-07-28 04:48:35 +0300 | [diff] [blame] | 108 | memset(&ApExeParams, 0, sizeof(AP_EXE_PARAMS)); |
Kyösti Mälkki | 46f04cb | 2017-09-06 15:42:23 +0300 | [diff] [blame] | 109 | memcpy(&ApExeParams.StdHeader, StdHeader, sizeof(*StdHeader)); |
Kyösti Mälkki | 28c4d2f | 2016-11-25 11:21:02 +0200 | [diff] [blame] | 110 | |
Kyösti Mälkki | c7dcec6 | 2017-07-28 04:48:35 +0300 | [diff] [blame] | 111 | ApExeParams.FunctionNumber = Func; |
| 112 | ApExeParams.RelatedDataBlock = ConfigPtr; |
| 113 | |
Kyösti Mälkki | 28c4d2f | 2016-11-25 11:21:02 +0200 | [diff] [blame] | 114 | status = module_dispatch(AMD_LATE_RUN_AP_TASK, &ApExeParams.StdHeader); |
Kyösti Mälkki | c7dcec6 | 2017-07-28 04:48:35 +0300 | [diff] [blame] | 115 | |
Kyösti Mälkki | 28c4d2f | 2016-11-25 11:21:02 +0200 | [diff] [blame] | 116 | ASSERT(status == AGESA_SUCCESS); |
Kyösti Mälkki | c7dcec6 | 2017-07-28 04:48:35 +0300 | [diff] [blame] | 117 | return status; |
Kyösti Mälkki | 6b4b151 | 2014-05-05 12:05:53 +0300 | [diff] [blame] | 118 | } |
| 119 | |
Kyösti Mälkki | a28bfad | 2017-04-13 17:01:18 +0300 | [diff] [blame] | 120 | #if defined(AGESA_GNB_GFX_GET_VBIOS_IMAGE) |
Stefan Reinauer | dd132a5 | 2015-07-30 11:16:37 -0700 | [diff] [blame] | 121 | AGESA_STATUS agesa_GfxGetVbiosImage(UINT32 Func, UINTN FchData, VOID *ConfigPrt) |
Kyösti Mälkki | cb989f2 | 2014-05-04 23:13:08 +0300 | [diff] [blame] | 122 | { |
| 123 | GFX_VBIOS_IMAGE_INFO *pVbiosImageInfo = (GFX_VBIOS_IMAGE_INFO *)ConfigPrt; |
Julius Werner | 834b3ec | 2020-03-04 16:52:08 -0800 | [diff] [blame] | 124 | pVbiosImageInfo->ImagePtr = cbfs_map("pci"CONFIG_VGA_BIOS_ID".rom", NULL); |
Kyösti Mälkki | cb989f2 | 2014-05-04 23:13:08 +0300 | [diff] [blame] | 125 | /* printk(BIOS_DEBUG, "IMGptr=%x\n", pVbiosImageInfo->ImagePtr); */ |
| 126 | return pVbiosImageInfo->ImagePtr == NULL ? AGESA_WARNING : AGESA_SUCCESS; |
| 127 | } |
Kyösti Mälkki | a1ebbc4 | 2014-10-17 22:33:22 +0300 | [diff] [blame] | 128 | #endif |
Kyösti Mälkki | c5cc9f2 | 2014-10-17 22:33:22 +0300 | [diff] [blame] | 129 | |
Elyes Haouas | 76c6323 | 2022-07-16 09:47:00 +0200 | [diff] [blame] | 130 | AGESA_STATUS agesa_ReadSpd(UINT32 Func, UINTN Data, VOID *ConfigPtr) |
Kyösti Mälkki | c5cc9f2 | 2014-10-17 22:33:22 +0300 | [diff] [blame] | 131 | { |
Kyösti Mälkki | 11cac78 | 2022-04-07 07:16:48 +0300 | [diff] [blame] | 132 | if (!ENV_RAMINIT) |
Kyösti Mälkki | 5be75d5 | 2019-08-19 08:41:50 +0300 | [diff] [blame] | 133 | return AGESA_UNSUPPORTED; |
| 134 | |
Elyes Haouas | 76c6323 | 2022-07-16 09:47:00 +0200 | [diff] [blame] | 135 | return AmdMemoryReadSPD(Func, Data, ConfigPtr); |
Kyösti Mälkki | c5cc9f2 | 2014-10-17 22:33:22 +0300 | [diff] [blame] | 136 | } |
Kyösti Mälkki | 36abdc4 | 2014-05-05 16:40:15 +0300 | [diff] [blame] | 137 | |
Stefan Reinauer | dd132a5 | 2015-07-30 11:16:37 -0700 | [diff] [blame] | 138 | AGESA_STATUS agesa_ReadSpd_from_cbfs(UINT32 Func, UINTN Data, VOID *ConfigPtr) |
Kyösti Mälkki | 36abdc4 | 2014-05-05 16:40:15 +0300 | [diff] [blame] | 139 | { |
Kyösti Mälkki | 36abdc4 | 2014-05-05 16:40:15 +0300 | [diff] [blame] | 140 | AGESA_READ_SPD_PARAMS *info = ConfigPtr; |
Kyösti Mälkki | 5be75d5 | 2019-08-19 08:41:50 +0300 | [diff] [blame] | 141 | |
Kyösti Mälkki | 11cac78 | 2022-04-07 07:16:48 +0300 | [diff] [blame] | 142 | if (!ENV_RAMINIT) |
Kyösti Mälkki | 5be75d5 | 2019-08-19 08:41:50 +0300 | [diff] [blame] | 143 | return AGESA_UNSUPPORTED; |
| 144 | |
Kyösti Mälkki | 36abdc4 | 2014-05-05 16:40:15 +0300 | [diff] [blame] | 145 | if (info->MemChannelId > 0) |
| 146 | return AGESA_UNSUPPORTED; |
| 147 | if (info->SocketId != 0) |
| 148 | return AGESA_UNSUPPORTED; |
| 149 | if (info->DimmId != 0) |
| 150 | return AGESA_UNSUPPORTED; |
| 151 | |
| 152 | /* Read index 0, first SPD_SIZE bytes of spd.bin file. */ |
Patrick Georgi | 2e08b59 | 2017-01-28 15:26:43 +0100 | [diff] [blame] | 153 | if (read_ddr3_spd_from_cbfs((u8*)info->Buffer, 0) < 0) |
Kyösti Mälkki | 36abdc4 | 2014-05-05 16:40:15 +0300 | [diff] [blame] | 154 | die("No SPD data\n"); |
| 155 | |
Kyösti Mälkki | 5be75d5 | 2019-08-19 08:41:50 +0300 | [diff] [blame] | 156 | return AGESA_SUCCESS; |
Kyösti Mälkki | 36abdc4 | 2014-05-05 16:40:15 +0300 | [diff] [blame] | 157 | } |
Kyösti Mälkki | bf201d5 | 2017-03-30 17:26:25 +0300 | [diff] [blame] | 158 | |
| 159 | #if HAS_AGESA_FCH_OEM_CALLOUT |
| 160 | void agesa_fch_oem_config(uintptr_t Data, AMD_CONFIG_PARAMS *StdHeader) |
| 161 | { |
Kyösti Mälkki | bf201d5 | 2017-03-30 17:26:25 +0300 | [diff] [blame] | 162 | struct sysinfo *cb_NA = NULL; |
| 163 | |
| 164 | if (StdHeader->Func == AMD_INIT_RESET) { |
| 165 | printk(BIOS_DEBUG, "Fch OEM config in INIT RESET\n"); |
| 166 | board_FCH_InitReset(cb_NA, (FCH_RESET_DATA_BLOCK *)Data); |
| 167 | } else if (StdHeader->Func == AMD_INIT_ENV) { |
| 168 | printk(BIOS_DEBUG, "Fch OEM config in INIT ENV\n"); |
| 169 | board_FCH_InitEnv(cb_NA, (FCH_DATA_BLOCK *)Data); |
| 170 | } |
| 171 | } |
| 172 | #endif |