coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
blobs_init.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <arch/cache.h>
4 #include <device/mmio.h>
5 #include <cbfs.h>
6 #include <console/console.h>
7 #include <string.h>
8 #include <timer.h>
9 
10 #include <soc/iomap.h>
11 #include <soc/soc_services.h>
12 
13 #include "mbn_header.h"
14 
15 static void *load_ipq_blob(const char *file_name)
16 {
17  struct mbn_header *blob_mbn;
18  void *blob_dest;
19  size_t blob_size;
20 
21  blob_mbn = cbfs_map(file_name, &blob_size);
22  if (!blob_mbn)
23  return NULL;
24 
25  /* some sanity checks on the headers */
26  if ((blob_mbn->mbn_version != 3) ||
27  (blob_mbn->mbn_total_size > blob_size))
28  return NULL;
29 
30  blob_dest = (void *) blob_mbn->mbn_destination;
31  if (blob_mbn->mbn_destination) {
32  /* Copy the blob to the appropriate memory location. */
33  memcpy(blob_dest, blob_mbn + 1, blob_mbn->mbn_total_size);
35  return blob_dest;
36  }
37 
38  /*
39  * The blob did not have to be relocated, return its address in CBFS
40  * cache.
41  */
42  return blob_mbn + 1;
43 }
44 
45 #define DDR_VERSION() ((const char *)0x2a03f600)
46 #define MAX_DDR_VERSION_SIZE 48
47 
48 int initialize_dram(void)
49 {
50  void *cdt;
51  int (*ddr_init_function)(void *cdt_header);
52 
53  cdt = load_ipq_blob("cdt.mbn");
54  ddr_init_function = load_ipq_blob("ddr.mbn");
55 
56  if (!cdt || !ddr_init_function) {
57  printk(BIOS_ERR, "cdt: %p, ddr_init_function: %p\n",
58  cdt, ddr_init_function);
59  die("could not find DDR initialization blobs\n");
60  }
61 
62  if (ddr_init_function(cdt) < 0)
63  die("Fail to Initialize DDR\n");
64 
65  /*
66  * Once DDR initializer finished, its version can be found at a fixed
67  * address in SRAM.
68  */
69  printk(BIOS_INFO, "DDR version %.*s initialized\n",
71 
72  return 0;
73 }
74 
75 void start_tzbsp(void)
76 {
77  void *tzbsp = load_ipq_blob("tz.mbn");
78 
79  if (!tzbsp)
80  die("could not find or map TZBSP\n");
81 
82  printk(BIOS_INFO, "Starting TZBSP\n");
83 
84  tz_init_wrapper(0, 0, tzbsp);
85 }
86 
87 /* RPM version is encoded in a 32 bit word at the fixed address */
88 #define RPM_VERSION() (*((u32 *)(0x00108008)))
89 void start_rpm(void)
90 {
91  u32 load_addr;
92  u32 ready_mask = 1 << 10;
93  u32 rpm_version;
94 
95  struct stopwatch sw;
96 
98  printk(BIOS_INFO, "RPM appears to have already started\n");
99  return;
100  }
101 
102  load_addr = (u32) load_ipq_blob("rpm.mbn");
103  if (!load_addr)
104  die("could not find or map RPM code\n");
105 
106  printk(BIOS_INFO, "Starting RPM\n");
107 
108  /* Clear 'ready' indication. */
109  /*
110  * RPM_INT_ACK is clear-on-write type register,
111  * read-modify-write is not recommended.
112  */
113  write32(RPM_INT_ACK, ready_mask);
114 
115  /* Set RPM entry address */
116  write32(RPM_SIGNAL_ENTRY, load_addr);
117  /* Set cookie */
119 
120  /* Wait for RPM start indication, up to 100ms. */
121  stopwatch_init_usecs_expire(&sw, 100000);
122  while (!(read32(RPM_INT) & ready_mask))
123  if (stopwatch_expired(&sw))
124  die("RPM Initialization failed\n");
125 
126  /* Acknowledge RPM initialization */
127  write32(RPM_INT_ACK, ready_mask);
128 
129  /* Report RPM version, it is encoded in a 32 bit value. */
130  rpm_version = RPM_VERSION();
131  printk(BIOS_INFO, "Started RPM version %d.%d.%d\n",
132  rpm_version >> 24,
133  (rpm_version >> 16) & 0xff,
134  rpm_version & 0xffff);
135 }
void cache_sync_instructions(void)
Definition: cache.c:57
static void write32(void *addr, uint32_t val)
Definition: mmio.h:40
static uint32_t read32(const void *addr)
Definition: mmio.h:22
void * memcpy(void *dest, const void *src, size_t n)
Definition: memcpy.c:7
static void * cbfs_map(const char *name, size_t *size_out)
Definition: cbfs.h:246
#define printk(level,...)
Definition: stdlib.h:16
void __noreturn die(const char *fmt,...)
Definition: die.c:17
static int stopwatch_expired(struct stopwatch *sw)
Definition: timer.h:152
static void stopwatch_init_usecs_expire(struct stopwatch *sw, long us)
Definition: timer.h:127
void start_tzbsp(void)
Definition: blobs_init.c:106
int initialize_dram(void)
Definition: blobs_init.c:61
int tz_init_wrapper(int, int, void *)
void start_rpm(void)
Definition: blobs_init.c:89
static void * load_ipq_blob(const char *file_name)
Definition: blobs_init.c:15
#define MAX_DDR_VERSION_SIZE
Definition: blobs_init.c:46
#define RPM_VERSION()
Definition: blobs_init.c:88
#define DDR_VERSION()
Definition: blobs_init.c:45
#define BIOS_INFO
BIOS_INFO - Expected events.
Definition: loglevel.h:113
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
Definition: loglevel.h:72
#define RPM_SIGNAL_COOKIE
Definition: iomap.h:61
#define RPM_INT_ACK
Definition: iomap.h:60
#define RPM_FW_MAGIC_NUM
Definition: iomap.h:63
#define RPM_SIGNAL_ENTRY
Definition: iomap.h:62
#define RPM_INT
Definition: iomap.h:59
#define NULL
Definition: stddef.h:19
uint32_t u32
Definition: stdint.h:51
u32 mbn_total_size
Definition: mbn_header.h:15
u32 mbn_destination
Definition: mbn_header.h:14
u32 mbn_version
Definition: mbn_header.h:12