summaryrefslogtreecommitdiffstats
path: root/src/soc/amd/common/fsp/fsp_ccx_cppc_hob.c
blob: aaf492e7372738b8d63864bd602daead9b603b02 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* SPDX-License-Identifier: GPL-2.0-only */

#include <amdblocks/cppc.h>
#include <ccx_cppc_data.h>
#include <console/console.h>
#include <FspGuids.h>
#include <fsp/util.h>
#include <types.h>


static enum cb_err get_ccx_cppc_data_hob(const struct fsp_ccx_cppc_data **cppc_data)
{
	static const struct fsp_ccx_cppc_data *cppc_data_cache;
	size_t hob_size = 0;
	const struct fsp_ccx_cppc_data *hob;

	if (cppc_data_cache) {
		*cppc_data = cppc_data_cache;
		return CB_SUCCESS;
	}

	hob = fsp_find_extension_hob_by_guid(AMD_FSP_CCX_CPPC_DATA_HOB_GUID.b, &hob_size);

	if (hob == NULL || hob_size < sizeof(struct fsp_ccx_cppc_data)) {
		printk(BIOS_ERR, "Couldn't find CCX CPPC data HOB.\n");
		return CB_ERR;
	}

	if (hob->version != FSP_CCX_CPPC_DATA_VERSION) {
		printk(BIOS_ERR, "Unexpected CCX CPPC data HOB version.\n");
		return CB_ERR;
	}

	cppc_data_cache = hob;
	*cppc_data = cppc_data_cache;
	return CB_SUCCESS;
}

enum cb_err get_ccx_cppc_min_frequency(uint32_t *freq)
{
	const struct fsp_ccx_cppc_data *cppc_data = NULL;

	if (get_ccx_cppc_data_hob(&cppc_data) != CB_SUCCESS)
		return CB_ERR;

	*freq = cppc_data->ccx_cppc_min_speed;
	printk(BIOS_SPEW, "CCX CPPC min speed: %d MHz\n", *freq);

	return CB_SUCCESS;
}

enum cb_err get_ccx_cppc_nom_frequency(uint32_t *freq)
{
	const struct fsp_ccx_cppc_data *cppc_data = NULL;

	if (get_ccx_cppc_data_hob(&cppc_data) != CB_SUCCESS)
		return CB_ERR;

	*freq = cppc_data->ccx_cppc_nom_speed;
	printk(BIOS_SPEW, "CCX CPPC nom speed: %d MHz\n", *freq);

	return CB_SUCCESS;
}