Angel Pons | 32859fc | 2020-04-02 23:48:27 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
Aaron Durbin | bd74a4b | 2015-03-06 23:17:33 -0600 | [diff] [blame] | 3 | |
| 4 | #ifndef _STAGE_CACHE_H_ |
| 5 | #define _STAGE_CACHE_H_ |
| 6 | |
| 7 | #include <stddef.h> |
| 8 | #include <stdint.h> |
| 9 | #include <program_loading.h> |
| 10 | |
Marshall Dawson | 8d6e0e0 | 2018-01-30 15:33:23 -0700 | [diff] [blame] | 11 | /* Types of stages that may be stored in stage cache */ |
Aaron Durbin | bd74a4b | 2015-03-06 23:17:33 -0600 | [diff] [blame] | 12 | enum { |
| 13 | STAGE_RAMSTAGE, |
| 14 | STAGE_REFCODE, |
Aaron Durbin | d008413 | 2016-11-29 15:52:08 -0600 | [diff] [blame] | 15 | STAGE_POSTCAR, |
Aaron Durbin | bd74a4b | 2015-03-06 23:17:33 -0600 | [diff] [blame] | 16 | }; |
| 17 | |
Marshall Dawson | 8d6e0e0 | 2018-01-30 15:33:23 -0700 | [diff] [blame] | 18 | /* Types of raw data that may be stored in stage cache */ |
| 19 | enum { |
| 20 | STAGE_S3_DATA, |
| 21 | }; |
| 22 | |
Kyösti Mälkki | 0a4457f | 2019-08-01 20:29:14 +0300 | [diff] [blame] | 23 | #if CONFIG(TSEG_STAGE_CACHE) || CONFIG(CBMEM_STAGE_CACHE) |
Aaron Durbin | bd74a4b | 2015-03-06 23:17:33 -0600 | [diff] [blame] | 24 | /* Cache the loaded stage provided according to the parameters. */ |
Aaron Durbin | 54546c9 | 2015-08-05 00:52:13 -0500 | [diff] [blame] | 25 | void stage_cache_add(int stage_id, const struct prog *stage); |
Subrata Banik | 90f750b | 2019-06-11 17:52:06 +0530 | [diff] [blame] | 26 | /* Load the cached stage at given location returning the stage entry point. */ |
| 27 | void stage_cache_load_stage(int stage_id, struct prog *stage); |
Marshall Dawson | 8d6e0e0 | 2018-01-30 15:33:23 -0700 | [diff] [blame] | 28 | /* Cache non-specific data or code. */ |
| 29 | void stage_cache_add_raw(int stage_id, const void *base, const size_t size); |
| 30 | /* Get a pointer to cached raw data and its size. */ |
| 31 | void stage_cache_get_raw(int stage_id, void **base, size_t *size); |
Kyösti Mälkki | c47c640 | 2019-08-01 08:56:35 +0300 | [diff] [blame] | 32 | |
| 33 | #else /* CONFIG_NO_STAGE_CACHE */ |
| 34 | |
| 35 | static inline void stage_cache_add(int stage_id, const struct prog *stage) {} |
| 36 | static inline void stage_cache_load_stage(int stage_id, struct prog *stage) {} |
| 37 | static inline void stage_cache_add_raw(int stage_id, const void *base, const size_t size) {} |
| 38 | static inline void stage_cache_get_raw(int stage_id, void **base, size_t *size) {} |
| 39 | |
| 40 | #endif |
| 41 | |
Aaron Durbin | bd74a4b | 2015-03-06 23:17:33 -0600 | [diff] [blame] | 42 | /* Fill in parameters for the external stage cache, if utilized. */ |
| 43 | void stage_cache_external_region(void **base, size_t *size); |
| 44 | |
| 45 | /* Metadata associated with each stage. */ |
| 46 | struct stage_cache { |
| 47 | uint64_t load_addr; |
| 48 | uint64_t entry_addr; |
Kyösti Mälkki | d87e4b3 | 2017-09-05 22:43:05 +0300 | [diff] [blame] | 49 | uint64_t arg; |
Aaron Durbin | bd74a4b | 2015-03-06 23:17:33 -0600 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | #endif /* _STAGE_CACHE_H_ */ |