summaryrefslogtreecommitdiff
path: root/src/soc/mediatek/mt8183/dramc_param.c
blob: d23332536a98b1c282d87651e37e9e43cb709ff1 (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
/* SPDX-License-Identifier: GPL-2.0-only */

#include <string.h>
#include "soc/dramc_param.h"

struct dramc_param *get_dramc_param_from_blob(void *blob)
{
	return (struct dramc_param *)blob;
}

int validate_dramc_param(const void *blob)
{
	const struct dramc_param *param = blob;
	const struct dramc_param_header *hdr = &param->header;

	if (hdr->magic != DRAMC_PARAM_HEADER_MAGIC)
		return DRAMC_ERR_INVALID_MAGIC;

	if (hdr->version != DRAMC_PARAM_HEADER_VERSION)
		return DRAMC_ERR_INVALID_VERSION;

	if (hdr->size != sizeof(*param))
		return DRAMC_ERR_INVALID_SIZE;

	return DRAMC_SUCCESS;
}

int is_valid_dramc_param(const void *blob)
{
	return validate_dramc_param(blob) == DRAMC_SUCCESS;
}

int initialize_dramc_param(void *blob, u16 config)
{
	struct dramc_param *param = blob;
	struct dramc_param_header *hdr = &param->header;

	memset(blob, 0, sizeof(*param));
	hdr->magic = DRAMC_PARAM_HEADER_MAGIC;
	hdr->size = sizeof(*param);
	hdr->version = DRAMC_PARAM_HEADER_VERSION;
	hdr->config = config;
	return 0;
}