Simon Glass | 428dfa4 | 2015-01-19 22:16:14 -0700 | [diff] [blame] | 1 | /* |
Bin Meng | 8575ab1 | 2015-10-11 21:37:38 -0700 | [diff] [blame^] | 2 | * Copyright (C) 2014 Google, Inc |
Simon Glass | 428dfa4 | 2015-01-19 22:16:14 -0700 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 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 | |
| 10 | #define MRC_DATA_ALIGN 0x1000 |
Bin Meng | 8575ab1 | 2015-10-11 21:37:38 -0700 | [diff] [blame^] | 11 | #define MRC_DATA_SIGNATURE (('M' << 0) | ('R' << 8) | \ |
| 12 | ('C' << 16) | ('D'<<24)) |
Simon Glass | 428dfa4 | 2015-01-19 22:16:14 -0700 | [diff] [blame] | 13 | |
Bin Meng | 8575ab1 | 2015-10-11 21:37:38 -0700 | [diff] [blame^] | 14 | struct __packed mrc_data_container { |
Simon Glass | 428dfa4 | 2015-01-19 22:16:14 -0700 | [diff] [blame] | 15 | u32 signature; /* "MRCD" */ |
| 16 | u32 data_size; /* Size of the 'data' field */ |
| 17 | u32 checksum; /* IP style checksum */ |
| 18 | u32 reserved; /* For header alignment */ |
| 19 | u8 data[0]; /* Variable size, platform/run time dependent */ |
| 20 | }; |
| 21 | |
| 22 | struct fmap_entry; |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 23 | struct udevice; |
Simon Glass | 428dfa4 | 2015-01-19 22:16:14 -0700 | [diff] [blame] | 24 | |
| 25 | /** |
| 26 | * mrccache_find_current() - find the latest MRC cache record |
| 27 | * |
| 28 | * This searches the MRC cache region looking for the latest record to use |
| 29 | * for setting up SDRAM |
| 30 | * |
Bin Meng | 8575ab1 | 2015-10-11 21:37:38 -0700 | [diff] [blame^] | 31 | * @entry: Position and size of MRC cache in SPI flash |
Simon Glass | 428dfa4 | 2015-01-19 22:16:14 -0700 | [diff] [blame] | 32 | * @return pointer to latest record, or NULL if none |
| 33 | */ |
| 34 | struct mrc_data_container *mrccache_find_current(struct fmap_entry *entry); |
| 35 | |
| 36 | /** |
| 37 | * mrccache_update() - update the MRC cache with a new record |
| 38 | * |
Bin Meng | 8575ab1 | 2015-10-11 21:37:38 -0700 | [diff] [blame^] | 39 | * This writes a new record to the end of the MRC cache region. If the new |
| 40 | * record is the same as the latest record then the write is skipped |
Simon Glass | 428dfa4 | 2015-01-19 22:16:14 -0700 | [diff] [blame] | 41 | * |
| 42 | * @sf: SPI flash to write to |
| 43 | * @entry: Position and size of MRC cache in SPI flash |
| 44 | * @cur: Record to write |
| 45 | * @return 0 if updated, -EEXIST if the record is the same as the latest |
Bin Meng | d61a7b4 | 2015-10-11 21:37:37 -0700 | [diff] [blame] | 46 | * record, -EINVAL if the record is not valid, other error if SPI write failed |
Simon Glass | 428dfa4 | 2015-01-19 22:16:14 -0700 | [diff] [blame] | 47 | */ |
Simon Glass | 35f15f6 | 2015-03-26 09:29:26 -0600 | [diff] [blame] | 48 | int mrccache_update(struct udevice *sf, struct fmap_entry *entry, |
Simon Glass | 428dfa4 | 2015-01-19 22:16:14 -0700 | [diff] [blame] | 49 | struct mrc_data_container *cur); |
| 50 | |
Bin Meng | 8575ab1 | 2015-10-11 21:37:38 -0700 | [diff] [blame^] | 51 | #endif /* _ASM_MRCCACHE_H */ |