1 /* SPDX-License-Identifier: GPL-2.0-only */
4 #include <console/console.h>
5 #include <soc/mtk_fsp.h>
7 #define MAX_PARAM_ENTRIES 32
8 #define FSP_INTF_SIZE (sizeof(struct mtk_fsp_intf) + \
9 sizeof(struct mtk_fsp_param) * MAX_PARAM_ENTRIES)
11 static struct mtk_fsp_intf
*intf
;
12 static uint8_t fsp_intf_buf
[FSP_INTF_SIZE
] __aligned(8);
14 static int vprintf_wrapper(const char *fmt
, va_list args
)
16 return vprintk(BIOS_INFO
, fmt
, args
);
19 void mtk_fsp_init(enum fsp_phase phase
)
21 intf
= (struct mtk_fsp_intf
*)fsp_intf_buf
;
22 intf
->major_version
= INTF_MAJOR_VER
;
23 intf
->minor_version
= INTF_MINOR_VER
;
24 intf
->header_size
= sizeof(struct mtk_fsp_intf
);
25 intf
->entry_size
= sizeof(struct mtk_fsp_param
);
26 intf
->num_entries
= 0;
28 intf
->do_vprintf
= vprintf_wrapper
;
31 enum cb_err
mtk_fsp_add_param(enum fsp_param_type type
, size_t param_size
,
34 struct mtk_fsp_param
*entry
;
37 printk(BIOS_ERR
, "%s: intf is not initialized\n", __func__
);
41 if (intf
->num_entries
== MAX_PARAM_ENTRIES
) {
42 printk(BIOS_ERR
, "%s: run out all entries\n", __func__
);
46 entry
= &intf
->entries
[intf
->num_entries
];
48 entry
->param_type
= type
;
49 entry
->param_size
= param_size
;
56 static void mtk_fsp_dump_intf(void)
58 struct mtk_fsp_param
*entry
;
61 printk(BIOS_ERR
, "%s: intf is not initialized\n", __func__
);
65 printk(BIOS_DEBUG
, "%s: major version: %u, minor version: %u\n",
66 __func__
, intf
->major_version
, intf
->minor_version
);
67 printk(BIOS_DEBUG
, "%s: FSP phase: %u, status: %d\n",
68 __func__
, intf
->phase
, intf
->status
);
69 printk(BIOS_DEBUG
, "%-5s %-10s %-10s %s\n", "Param", "type", "size", "address");
70 for (int i
= 0; i
< intf
->num_entries
; i
++) {
71 entry
= &intf
->entries
[i
];
72 printk(BIOS_DEBUG
, "%-5u %-10u %-10u %p\n",
73 i
, entry
->param_type
, entry
->param_size
, entry
->param
);
77 static const char *mtk_fsp_file(void)
79 return CONFIG_CBFS_PREFIX
"/mtk_fsp_" ENV_STRING
;
82 enum cb_err
mtk_fsp_load_and_run(void)
84 struct prog fsp
= PROG_INIT(PROG_REFCODE
, mtk_fsp_file());
86 if (cbfs_prog_stage_load(&fsp
)) {
87 printk(BIOS_ERR
, "%s: CBFS load program failed\n", __func__
);
92 printk(BIOS_ERR
, "%s: intf is not initialized\n", __func__
);
96 prog_set_arg(&fsp
, intf
);
99 if (intf
->status
!= FSP_STATUS_SUCCESS
) {
104 printk(BIOS_INFO
, "%s: run %s at phase %#x done\n",
105 __func__
, mtk_fsp_file(), intf
->phase
);