blob: 3b51fd84c11180a43a4114e77b0b989c21b5b1bb [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>
8#include <string.h>
9#include <types.h>
10
11static enum cb_err get_amd_misc_data_hob(const struct amd_misc_data **fsp_misc_data, int min_revision)
12{
13 static const struct amd_misc_data *fsp_misc_data_cache;
14 size_t hob_size = 0;
15 const struct amd_misc_data *hob;
16
17 if (fsp_misc_data_cache) {
18 *fsp_misc_data = fsp_misc_data_cache;
19 return CB_SUCCESS;
20 }
21
22 hob = fsp_find_extension_hob_by_guid(AMD_MISC_DATA_HOB_GUID.b, &hob_size);
23
24 if (hob == NULL || hob_size < sizeof(struct amd_misc_data)) {
25 printk(BIOS_ERR, "Couldn't find fsp misc data HOB.\n");
26 return CB_ERR;
27 }
28
29 if (hob->version < min_revision) {
30 printk(BIOS_ERR, "Unexpected fsp misc data HOB version.\n");
31 return CB_ERR;
32 }
33
34 fsp_misc_data_cache = hob;
35 *fsp_misc_data = fsp_misc_data_cache;
36 return CB_SUCCESS;
37}
38
39enum cb_err get_amd_smu_reported_tdp(uint32_t *tdp)
40{
41 const struct amd_misc_data *fsp_misc_data = NULL;
42
43 if (get_amd_misc_data_hob(&fsp_misc_data, AMD_MISC_DATA_VERSION) != CB_SUCCESS)
44 return CB_ERR;
45
Tim Van Pattenb9caac72023-03-31 17:16:50 -060046 /*
47 * The FSP will return the TDP in the format 0xX0000, where 'X' is the value
48 * we're interested in. For example: 0xF0000 (15W), 0x60000 (6W). Re-interpret
49 * the value so the caller just sees the TDP.
50 */
51 printk(BIOS_INFO, "fsp_misc_data->smu_power_and_thm_limit = 0x%08X\n",
52 fsp_misc_data->smu_power_and_thm_limit);
53 *tdp = fsp_misc_data->smu_power_and_thm_limit >> 16;
Jason Glenesk60875b42023-03-16 15:28:10 -070054
55 return CB_SUCCESS;
56}