Jason Glenesk | 60875b4 | 2023-03-16 15:28:10 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #include <console/console.h> |
| 4 | #include <FspGuids.h> |
| 5 | #include <fsp/amd_misc_data.h> |
| 6 | #include <fsp/amd_misc_data_hob.h> |
| 7 | #include <fsp/util.h> |
Jason Glenesk | 60875b4 | 2023-03-16 15:28:10 -0700 | [diff] [blame] | 8 | #include <types.h> |
| 9 | |
| 10 | static enum cb_err get_amd_misc_data_hob(const struct amd_misc_data **fsp_misc_data, int min_revision) |
| 11 | { |
| 12 | static const struct amd_misc_data *fsp_misc_data_cache; |
| 13 | size_t hob_size = 0; |
| 14 | const struct amd_misc_data *hob; |
| 15 | |
| 16 | if (fsp_misc_data_cache) { |
| 17 | *fsp_misc_data = fsp_misc_data_cache; |
| 18 | return CB_SUCCESS; |
| 19 | } |
| 20 | |
| 21 | hob = fsp_find_extension_hob_by_guid(AMD_MISC_DATA_HOB_GUID.b, &hob_size); |
| 22 | |
| 23 | if (hob == NULL || hob_size < sizeof(struct amd_misc_data)) { |
| 24 | printk(BIOS_ERR, "Couldn't find fsp misc data HOB.\n"); |
| 25 | return CB_ERR; |
| 26 | } |
| 27 | |
| 28 | if (hob->version < min_revision) { |
| 29 | printk(BIOS_ERR, "Unexpected fsp misc data HOB version.\n"); |
| 30 | return CB_ERR; |
| 31 | } |
| 32 | |
| 33 | fsp_misc_data_cache = hob; |
| 34 | *fsp_misc_data = fsp_misc_data_cache; |
| 35 | return CB_SUCCESS; |
| 36 | } |
| 37 | |
| 38 | enum cb_err get_amd_smu_reported_tdp(uint32_t *tdp) |
| 39 | { |
| 40 | const struct amd_misc_data *fsp_misc_data = NULL; |
| 41 | |
| 42 | if (get_amd_misc_data_hob(&fsp_misc_data, AMD_MISC_DATA_VERSION) != CB_SUCCESS) |
| 43 | return CB_ERR; |
| 44 | |
Tim Van Patten | b9caac7 | 2023-03-31 17:16:50 -0600 | [diff] [blame] | 45 | /* |
| 46 | * The FSP will return the TDP in the format 0xX0000, where 'X' is the value |
| 47 | * we're interested in. For example: 0xF0000 (15W), 0x60000 (6W). Re-interpret |
| 48 | * the value so the caller just sees the TDP. |
| 49 | */ |
Paul Menzel | 6e4102b | 2023-04-06 20:07:12 +0200 | [diff] [blame] | 50 | printk(BIOS_DEBUG, "fsp_misc_data->smu_power_and_thm_limit = 0x%08X\n", |
Tim Van Patten | b9caac7 | 2023-03-31 17:16:50 -0600 | [diff] [blame] | 51 | fsp_misc_data->smu_power_and_thm_limit); |
| 52 | *tdp = fsp_misc_data->smu_power_and_thm_limit >> 16; |
Jason Glenesk | 60875b4 | 2023-03-16 15:28:10 -0700 | [diff] [blame] | 53 | |
| 54 | return CB_SUCCESS; |
| 55 | } |