blob: 8ed6e0e9d6e3d34a0e4234fe76a610f8dcf1c015 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Simon Glass428dfa42015-01-19 22:16:14 -07002/*
Bin Meng8575ab12015-10-11 21:37:38 -07003 * Copyright (C) 2014 Google, Inc
Bin Meng1f81b592015-10-11 21:37:39 -07004 * Copyright (C) 2015 Bin Meng <bmeng.cn@gmail.com>
Simon Glass428dfa42015-01-19 22:16:14 -07005 */
6
Bin Meng8575ab12015-10-11 21:37:38 -07007#ifndef _ASM_MRCCACHE_H
8#define _ASM_MRCCACHE_H
Simon Glass428dfa42015-01-19 22:16:14 -07009
Simon Glass3ba929a2020-10-30 21:38:53 -060010#include <compiler.h>
11
Simon Glass91c07362019-12-06 21:42:01 -070012#define MRC_DATA_ALIGN 0x100
Bin Meng8575ab12015-10-11 21:37:38 -070013#define MRC_DATA_SIGNATURE (('M' << 0) | ('R' << 8) | \
14 ('C' << 16) | ('D'<<24))
Simon Glass428dfa42015-01-19 22:16:14 -070015
Bin Meng1f81b592015-10-11 21:37:39 -070016#define MRC_DATA_HEADER_SIZE 32
17
Bin Meng8575ab12015-10-11 21:37:38 -070018struct __packed mrc_data_container {
Simon Glass428dfa42015-01-19 22:16:14 -070019 u32 signature; /* "MRCD" */
20 u32 data_size; /* Size of the 'data' field */
21 u32 checksum; /* IP style checksum */
22 u32 reserved; /* For header alignment */
23 u8 data[0]; /* Variable size, platform/run time dependent */
24};
25
Bin Meng2845ead2015-10-11 21:37:41 -070026struct mrc_region {
27 u32 base;
28 u32 offset;
29 u32 length;
30};
31
Simon Glass91efff52019-12-06 21:42:07 -070032/* Types of MRC data */
33enum mrc_type_t {
34 MRC_TYPE_NORMAL,
Simon Glassb5b0aff2019-12-06 21:42:08 -070035 MRC_TYPE_VAR,
Simon Glass91efff52019-12-06 21:42:07 -070036
37 MRC_TYPE_COUNT,
38};
39
Simon Glass35f15f62015-03-26 09:29:26 -060040struct udevice;
Simon Glass428dfa42015-01-19 22:16:14 -070041
42/**
43 * mrccache_find_current() - find the latest MRC cache record
44 *
45 * This searches the MRC cache region looking for the latest record to use
46 * for setting up SDRAM
47 *
Bin Meng8575ab12015-10-11 21:37:38 -070048 * @entry: Position and size of MRC cache in SPI flash
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010049 * Return: pointer to latest record, or NULL if none
Simon Glass428dfa42015-01-19 22:16:14 -070050 */
Bin Meng2845ead2015-10-11 21:37:41 -070051struct mrc_data_container *mrccache_find_current(struct mrc_region *entry);
Simon Glass428dfa42015-01-19 22:16:14 -070052
53/**
Bin Meng1f81b592015-10-11 21:37:39 -070054 * mrccache_reserve() - reserve MRC data on the stack
55 *
56 * This copies MRC data pointed by gd->arch.mrc_output to a new place on the
57 * stack with length gd->arch.mrc_output_len, and updates gd->arch.mrc_output
58 * to point to the new place once the migration is done.
59 *
60 * This routine should be called by reserve_arch() before U-Boot is relocated
61 * when MRC cache is enabled.
62 *
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010063 * Return: 0 always
Bin Meng1f81b592015-10-11 21:37:39 -070064 */
65int mrccache_reserve(void);
66
67/**
68 * mrccache_get_region() - get MRC region on the SPI flash
69 *
70 * This gets MRC region whose offset and size are described in the device tree
Simon Glass00bf2792020-05-27 06:58:49 -060071 * as a subnode to the SPI flash. This tries to find the SPI flash device
72 * (without probing it), falling back to looking for the devicetree node if
73 * driver model is not inited or the SPI flash is not found.
Bin Meng1f81b592015-10-11 21:37:39 -070074 *
Simon Glass91efff52019-12-06 21:42:07 -070075 * @type: Type of MRC data to use
Simon Glass00bf2792020-05-27 06:58:49 -060076 * @devp: Returns pointer to the SPI flash device, if found
Bin Meng1f81b592015-10-11 21:37:39 -070077 * @entry: Position and size of MRC cache in SPI flash
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010078 * Return: 0 if success, -ENOENT if SPI flash node does not exist in the
Bin Meng1f81b592015-10-11 21:37:39 -070079 * device tree, -EPERM if MRC region subnode does not exist in the device
80 * tree, -EINVAL if MRC region properties format is incorrect, other error
81 * if SPI flash probe failed.
82 */
Simon Glass91efff52019-12-06 21:42:07 -070083int mrccache_get_region(enum mrc_type_t type, struct udevice **devp,
84 struct mrc_region *entry);
Bin Meng1f81b592015-10-11 21:37:39 -070085
86/**
87 * mrccache_save() - save MRC data to the SPI flash
88 *
89 * This saves MRC data stored previously by gd->arch.mrc_output to a proper
90 * place within the MRC region on the SPI flash.
91 *
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +010092 * Return: 0 if saved to SPI flash successfully, other error if failed
Bin Meng1f81b592015-10-11 21:37:39 -070093 */
94int mrccache_save(void);
95
Simon Glass48fd8562019-04-25 21:58:57 -060096/**
97 * mrccache_spl_save() - Save to the MRC region from SPL
98 *
99 * When SPL is used to set up the memory controller we want to save the MRC
100 * data in SPL to avoid needing to pass it up to U-Boot proper to save. This
101 * function handles that.
102 *
Heinrich Schuchardt47b4c022022-01-19 18:05:50 +0100103 * Return: 0 if saved to SPI flash successfully, other error if failed
Simon Glass48fd8562019-04-25 21:58:57 -0600104 */
105int mrccache_spl_save(void);
106
Bin Meng8575ab12015-10-11 21:37:38 -0700107#endif /* _ASM_MRCCACHE_H */