coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
mcu.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <arch/barrier.h>
4 #include <cbfs.h>
5 #include <console/console.h>
6 #include <soc/mcu_common.h>
7 #include <soc/symbols.h>
8 #include <timer.h>
9 
10 int mtk_init_mcu(struct mtk_mcu *mcu)
11 {
12  struct stopwatch sw;
13 
14  if (!mcu)
15  return CB_ERR_ARG;
16 
17  stopwatch_init(&sw);
18 
19  mcu->run_size = cbfs_load(mcu->firmware_name, mcu->load_buffer, mcu->buffer_size);
20  if (mcu->run_size == 0) {
21  printk(BIOS_ERR, "%s: Failed to load %s\n", __func__, mcu->firmware_name);
22  return CB_ERR;
23  }
24 
25  if (mcu->run_address) {
26  memcpy(mcu->run_address, mcu->load_buffer, mcu->run_size);
27  /* Memory barrier to ensure data is flushed before resetting MCU. */
28  mb();
29  }
30 
31  if (mcu->reset)
32  mcu->reset(mcu);
33 
34  printk(BIOS_DEBUG, "%s: Loaded (and reset) %s in %ld msecs (%zd bytes)\n",
35  __func__, mcu->firmware_name, stopwatch_duration_msecs(&sw), mcu->run_size);
36 
37  return CB_SUCCESS;
38 }
void * memcpy(void *dest, const void *src, size_t n)
Definition: memcpy.c:7
#define mb()
Definition: barrier.h:19
@ CB_ERR
Generic error code.
Definition: cb_err.h:17
@ CB_ERR_ARG
Invalid argument.
Definition: cb_err.h:18
@ CB_SUCCESS
Call completed successfully.
Definition: cb_err.h:16
static size_t cbfs_load(const char *name, void *buf, size_t size)
Definition: cbfs.h:282
#define printk(level,...)
Definition: stdlib.h:16
static void stopwatch_init(struct stopwatch *sw)
Definition: timer.h:117
static long stopwatch_duration_msecs(struct stopwatch *sw)
Definition: timer.h:182
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
Definition: loglevel.h:72
int mtk_init_mcu(struct mtk_mcu *mcu)
Definition: mcu.c:10
size_t buffer_size
Definition: mcu_common.h:11
void * run_address
Definition: mcu_common.h:8
const char * firmware_name
Definition: mcu_common.h:7
void(* reset)(struct mtk_mcu *mcu)
Definition: mcu_common.h:13
void * load_buffer
Definition: mcu_common.h:10
size_t run_size
Definition: mcu_common.h:9