summaryrefslogtreecommitdiff
path: root/src/drivers/ocp/vpd/vpd_util.c
blob: 27d7bccb5cd9185b72e5a47ab0700aeb3f2e96cd (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
/* SPDX-License-Identifier: GPL-2.0-only */

#include <console/console.h>
#include <drivers/vpd/vpd.h>
#include <drivers/ocp/include/vpd.h>

int get_int_from_vpd_range(const char *const key, const int fallback, const int min,
	const int max)
{
	int val = fallback;

	if (!vpd_get_int(key, VPD_RW_THEN_RO, &val))
		printk(BIOS_INFO, "%s: not able to get VPD %s, default set to %d\n",
		       __func__, key, fallback);
	else
		printk(BIOS_DEBUG, "%s: VPD %s, got %d\n", __func__, key, val);

	if (val < min || val > max) {
		printk(BIOS_INFO, "Invalid VPD %s value, set default value to %d\n",
			key, fallback);
		val = fallback;
	}

	return val;
}

bool get_bool_from_vpd(const char *const key, const bool fallback)
{
	uint8_t val;

	val = (uint8_t)fallback;

	if (!vpd_get_bool(key, VPD_RW_THEN_RO, &val))
		printk(BIOS_INFO, "%s: not able to get VPD %s, default set to %d\n",
		       __func__, key, fallback);
	else
		printk(BIOS_DEBUG, "%s: VPD %s, got %d\n", __func__, key, val);

	return (bool)val;
}

int get_cxl_mode_from_vpd(void)
{
	return get_int_from_vpd_range(CXL_MODE, CXL_MODE_DEFAULT, 0, CXL_MODE_MAX-1);
}