Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Simon Glass | 428dfa4 | 2015-01-19 22:16:14 -0700 | [diff] [blame] | 2 | /* |
Bin Meng | 8575ab1 | 2015-10-11 21:37:38 -0700 | [diff] [blame] | 3 | * Copyright (C) 2014 Google, Inc |
Bin Meng | 1f81b59 | 2015-10-11 21:37:39 -0700 | [diff] [blame] | 4 | * Copyright (C) 2015 Bin Meng <bmeng.cn@gmail.com> |
Simon Glass | 428dfa4 | 2015-01-19 22:16:14 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
Bin Meng | 8575ab1 | 2015-10-11 21:37:38 -0700 | [diff] [blame] | 7 | #ifndef _ASM_MRCCACHE_H |
| 8 | #define _ASM_MRCCACHE_H |
Simon Glass | 428dfa4 | 2015-01-19 22:16:14 -0700 | [diff] [blame] | 9 | |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame^] | 10 | #include <compiler.h> |
| 11 | |
Simon Glass | 91c0736 | 2019-12-06 21:42:01 -0700 | [diff] [blame] | 12 | #define MRC_DATA_ALIGN 0x100 |
Bin Meng | 8575ab1 | 2015-10-11 21:37:38 -0700 | [diff] [blame] | 13 | #define MRC_DATA_SIGNATURE (('M' << 0) | ('R' << 8) | \ |
| 14 | ('C' << 16) | ('D'<<24)) |
Simon Glass | 428dfa4 | 2015-01-19 22:16:14 -0700 | [diff] [blame] | 15 | |
Bin Meng | 1f81b59 | 2015-10-11 21:37:39 -0700 | [diff] [blame] | 16 | #define MRC_DATA_HEADER_SIZE 32 |
| 17 | |
Bin Meng | 8575ab1 | 2015-10-11 21:37:38 -0700 | [diff] [blame] | 18 | struct __packed mrc_data_container { |
Simon Glass | 428dfa4 | 2015-01-19 22:16:14 -0700 | [diff] [blame] | 19 | 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 Meng | 2845ead | 2015-10-11 21:37:41 -0700 | [diff] [blame] | 26 | struct mrc_region { |
| 27 | u32 base; |
| 28 | u32 offset; |
| 29 | u32 length; |
| 30 | }; |
| 31 | |
Simon Glass | 91efff5 | 2019-12-06 21:42:07 -0700 | [diff] [blame] | 32 | /* Types of MRC data */ |
| 33 | enum mrc_type_t { |
| 34 | MRC_TYPE_NORMAL, |
Simon Glass | b5b0aff | 2019-12-06 21:42:08 -0700 | [diff] [blame] | 35 | MRC_TYPE_VAR, |
Simon Glass | 91efff5 | 2019-12-06 21:42:07 -0700 | [diff] [blame] | 36 | |
| 37 | MRC_TYPE_COUNT, |
| 38 | }; |
| 39 | |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 40 | struct udevice; |
Simon Glass | 428dfa4 | 2015-01-19 22:16:14 -0700 | [diff] [blame] | 41 | |
| 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 Meng | 8575ab1 | 2015-10-11 21:37:38 -0700 | [diff] [blame] | 48 | * @entry: Position and size of MRC cache in SPI flash |
Simon Glass | 428dfa4 | 2015-01-19 22:16:14 -0700 | [diff] [blame] | 49 | * @return pointer to latest record, or NULL if none |
| 50 | */ |
Bin Meng | 2845ead | 2015-10-11 21:37:41 -0700 | [diff] [blame] | 51 | struct mrc_data_container *mrccache_find_current(struct mrc_region *entry); |
Simon Glass | 428dfa4 | 2015-01-19 22:16:14 -0700 | [diff] [blame] | 52 | |
| 53 | /** |
Bin Meng | 1f81b59 | 2015-10-11 21:37:39 -0700 | [diff] [blame] | 54 | * 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 | * |
| 63 | * @return 0 always |
| 64 | */ |
| 65 | int 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 Glass | 00bf279 | 2020-05-27 06:58:49 -0600 | [diff] [blame] | 71 | * 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 Meng | 1f81b59 | 2015-10-11 21:37:39 -0700 | [diff] [blame] | 74 | * |
Simon Glass | 91efff5 | 2019-12-06 21:42:07 -0700 | [diff] [blame] | 75 | * @type: Type of MRC data to use |
Simon Glass | 00bf279 | 2020-05-27 06:58:49 -0600 | [diff] [blame] | 76 | * @devp: Returns pointer to the SPI flash device, if found |
Bin Meng | 1f81b59 | 2015-10-11 21:37:39 -0700 | [diff] [blame] | 77 | * @entry: Position and size of MRC cache in SPI flash |
| 78 | * @return 0 if success, -ENOENT if SPI flash node does not exist in the |
| 79 | * 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 Glass | 91efff5 | 2019-12-06 21:42:07 -0700 | [diff] [blame] | 83 | int mrccache_get_region(enum mrc_type_t type, struct udevice **devp, |
| 84 | struct mrc_region *entry); |
Bin Meng | 1f81b59 | 2015-10-11 21:37:39 -0700 | [diff] [blame] | 85 | |
| 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 | * |
| 92 | * @return 0 if saved to SPI flash successfully, other error if failed |
| 93 | */ |
| 94 | int mrccache_save(void); |
| 95 | |
Simon Glass | 48fd856 | 2019-04-25 21:58:57 -0600 | [diff] [blame] | 96 | /** |
| 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 | * |
| 103 | * @return 0 if saved to SPI flash successfully, other error if failed |
| 104 | */ |
| 105 | int mrccache_spl_save(void); |
| 106 | |
Bin Meng | 8575ab1 | 2015-10-11 21:37:38 -0700 | [diff] [blame] | 107 | #endif /* _ASM_MRCCACHE_H */ |