Debian Codegraph @

src/soc/mediatek/common/mtk_fsp.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <cbfs.h>
4 #include <console/console.h>
5 #include <soc/mtk_fsp.h>
6 #include <timer.h>
7
8 #define MAX_PARAM_ENTRIES 32
9 #define FSP_INTF_SIZE (sizeof(struct mtk_fsp_intf) + \
10 sizeof(struct mtk_fsp_param) * MAX_PARAM_ENTRIES)
11
12 static struct mtk_fsp_intf *intf;
13 static uint8_t fsp_intf_buf[FSP_INTF_SIZE] __aligned(8);
14
15 static int vprintf_wrapper(const char *fmt, va_list args)
16 {
17 return vprintk(BIOS_INFO, fmt, args);
18 }
19
20 void mtk_fsp_init(enum fsp_phase phase)
21 {
22 intf = (struct mtk_fsp_intf *)fsp_intf_buf;
23 intf->major_version = INTF_MAJOR_VER;
24 intf->minor_version = INTF_MINOR_VER;
25 intf->header_size = sizeof(struct mtk_fsp_intf);
26 intf->entry_size = sizeof(struct mtk_fsp_param);
27 intf->num_entries = 0;
28 intf->phase = phase;
29 intf->do_vprintf = vprintf_wrapper;
30 }
31
32 enum cb_err mtk_fsp_add_param(enum fsp_param_type type, size_t param_size,
33 void *param)
34 {
35 struct mtk_fsp_param *entry;
36
37 if (!intf) {
38 printk(BIOS_ERR, "%s: intf is not initialized\n", __func__);
39 return CB_ERR;
40 }
41
42 if (intf->num_entries == MAX_PARAM_ENTRIES) {
43 printk(BIOS_ERR, "%s: run out all entries\n", __func__);
44 return CB_ERR;
45 }
46
47 entry = &intf->entries[intf->num_entries];
48
49 entry->param_type = type;
50 entry->param_size = param_size;
51 entry->param = param;
52 intf->num_entries++;
53
54 return CB_SUCCESS;
55 }
56
57 static void mtk_fsp_dump_intf(void)
58 {
59 struct mtk_fsp_param *entry;
60
61 if (!intf) {
62 printk(BIOS_ERR, "%s: intf is not initialized\n", __func__);
63 return;
64 }
65
66 printk(BIOS_DEBUG, "%s: major version: %u, minor version: %u\n",
67 __func__, intf->major_version, intf->minor_version);
68 printk(BIOS_DEBUG, "%s: FSP phase: %u, status: %d\n",
69 __func__, intf->phase, intf->status);
70 printk(BIOS_DEBUG, "%-5s %-10s %-10s %s\n", "Param", "type", "size", "address");
71 for (int i = 0; i < intf->num_entries; i++) {
72 entry = &intf->entries[i];
73 printk(BIOS_DEBUG, "%-5u %-10u %-10u %p\n",
74 i, entry->param_type, entry->param_size, entry->param);
75 }
76 }
77
78 static const char *mtk_fsp_file(void)
79 {
80 return CONFIG_CBFS_PREFIX "/mtk_fsp_" ENV_STRING;
81 }
82
83 enum cb_err mtk_fsp_load_and_run(void)
84 {
85 struct prog fsp = PROG_INIT(PROG_REFCODE, mtk_fsp_file());
86 struct stopwatch sw;
87
88 stopwatch_init(&sw);
89 if (cbfs_prog_stage_load(&fsp)) {
90 printk(BIOS_ERR, "%s: CBFS load program failed\n", __func__);
91 return CB_ERR;
92 }
93
94 if (!intf) {
95 printk(BIOS_ERR, "%s: intf is not initialized\n", __func__);
96 return CB_ERR;
97 }
98
99 prog_set_arg(&fsp, intf);
100 prog_run(&fsp);
101
102 if (intf->status != FSP_STATUS_SUCCESS) {
103 mtk_fsp_dump_intf();
104 return CB_ERR;
105 }
106
107 printk(BIOS_INFO, "%s: run %s at phase %#x in %lld msecs\n",
108 __func__, mtk_fsp_file(), intf->phase, stopwatch_duration_msecs(&sw));
109
110 return CB_SUCCESS;
111 }