blob: e5eae0207556b3522bac1c4bba4bee4afbdbb07a [file] [log] [blame]
Jason Glenesk60875b42023-03-16 15:28:10 -07001/* 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 Glenesk60875b42023-03-16 15:28:10 -07008#include <types.h>
9
10static 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
38enum 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 Pattenb9caac72023-03-31 17:16:50 -060045 /*
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 Menzel6e4102b2023-04-06 20:07:12 +020050 printk(BIOS_DEBUG, "fsp_misc_data->smu_power_and_thm_limit = 0x%08X\n",
Tim Van Pattenb9caac72023-03-31 17:16:50 -060051 fsp_misc_data->smu_power_and_thm_limit);
52 *tdp = fsp_misc_data->smu_power_and_thm_limit >> 16;
Jason Glenesk60875b42023-03-16 15:28:10 -070053
54 return CB_SUCCESS;
55}