• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #ifndef _STAGE_CACHE_H_
4 #define _STAGE_CACHE_H_
5 
6 #include <romstage_handoff.h>
7 #include <stddef.h>
8 #include <stdint.h>
9 #include <program_loading.h>
10 
11 /* Types of stages that may be stored in stage cache */
12 enum {
13 	STAGE_RAMSTAGE,
14 	STAGE_REFCODE,
15 	STAGE_POSTCAR,
16 };
17 
18 /* Types of raw data that may be stored in stage cache */
19 enum {
20 	STAGE_S3_DATA,
21 };
22 
23 #if CONFIG(TSEG_STAGE_CACHE) || CONFIG(CBMEM_STAGE_CACHE)
24 /* Cache the loaded stage provided according to the parameters. */
25 void stage_cache_add(int stage_id, const struct prog *stage);
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);
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);
32 
33 #else /* CONFIG_NO_STAGE_CACHE */
34 
stage_cache_add(int stage_id,const struct prog * stage)35 static inline void stage_cache_add(int stage_id, const struct prog *stage) {}
stage_cache_load_stage(int stage_id,struct prog * stage)36 static inline void stage_cache_load_stage(int stage_id, struct prog *stage) {}
stage_cache_add_raw(int stage_id,const void * base,const size_t size)37 static inline void stage_cache_add_raw(int stage_id, const void *base, const size_t size) {}
stage_cache_get_raw(int stage_id,void ** base,size_t * size)38 static inline void stage_cache_get_raw(int stage_id, void **base, size_t *size) {}
39 
40 #endif
41 
resume_from_stage_cache(void)42 static inline int resume_from_stage_cache(void)
43 {
44 	if (CONFIG(NO_STAGE_CACHE))
45 		return 0;
46 
47 	/* TBD: Replace this with acpi_is_wakeup_s3(). */
48 	return romstage_handoff_is_resume();
49 }
50 
51 /* Fill in parameters for the external stage cache, if utilized. */
52 void stage_cache_external_region(void **base, size_t *size);
53 
54 /* Metadata associated with each stage. */
55 struct stage_cache {
56 	uint64_t load_addr;
57 	uint64_t entry_addr;
58 	uint64_t arg;
59 };
60 
61 #endif /* _STAGE_CACHE_H_ */
62