• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <cbmem.h>
4 #include <console/console.h>
5 #include <console/streams.h>
6 #include <cpu/x86/tsc.h>
7 #include <program_loading.h>
8 #include <rmodule.h>
9 #include <stage_cache.h>
10 
11 #include <soc/ramstage.h>
12 #include <soc/efi_wrapper.h>
13 
send_to_console(unsigned char b)14 static void ABI_X86 send_to_console(unsigned char b)
15 {
16 	console_tx_byte(b);
17 }
18 
load_reference_code(void)19 static efi_wrapper_entry_t load_reference_code(void)
20 {
21 	if (resume_from_stage_cache()) {
22 		struct prog prog;
23 		stage_cache_load_stage(STAGE_REFCODE, &prog);
24 		return prog_entry(&prog);
25 	}
26 
27 	struct prog prog =
28 		PROG_INIT(PROG_REFCODE, CONFIG_CBFS_PREFIX "/refcode");
29 	struct rmod_stage_load refcode = {
30 		.cbmem_id = CBMEM_ID_REFCODE,
31 		.prog = &prog,
32 	};
33 
34 	if (rmodule_stage_load(&refcode)) {
35 		printk(BIOS_DEBUG, "Error loading reference code.\n");
36 		return NULL;
37 	}
38 
39 	/* Cache loaded reference code. */
40 	stage_cache_add(STAGE_REFCODE, &prog);
41 
42 	return prog_entry(&prog);
43 }
44 
baytrail_run_reference_code(void)45 void baytrail_run_reference_code(void)
46 {
47 	int ret;
48 	efi_wrapper_entry_t entry;
49 	struct efi_wrapper_params wrp = {
50 		.version = EFI_WRAPPER_VER,
51 		.console_out = send_to_console,
52 	};
53 
54 	entry = load_reference_code();
55 
56 	if (entry == NULL)
57 		return;
58 
59 	wrp.tsc_ticks_per_microsecond = tsc_freq_mhz();
60 
61 	/* Call into reference code. */
62 	ret = entry(&wrp);
63 
64 	if (ret != 0) {
65 		printk(BIOS_DEBUG, "Reference code returned %d\n", ret);
66 		return;
67 	}
68 }
69