1 /*
2  * Copyright (c) 2022 Intel Corporation
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /**
8  * @file
9  * @brief EFI console driver
10  *
11  * @details EFI console driver.
12  * Hooks into the printk and fputc (for printf) modules.
13  */
14 
15 #include <stdio.h>
16 #include <zephyr/device.h>
17 #include <zephyr/init.h>
18 #include <zephyr/sys/printk.h>
19 
20 
21 extern int efi_console_putchar(int c);
22 
23 #if defined(CONFIG_PRINTK) || defined(CONFIG_STDOUT_CONSOLE)
24 /**
25  *
26  * @brief Output one character to EFI console
27  *
28  * Outputs both line feed and carriage return in the case of a '\n'.
29  *
30  * @param c Character to output
31  *
32  * @return The character passed as input.
33  */
34 
console_out(int c)35 static int console_out(int c)
36 {
37 	return efi_console_putchar(c);
38 }
39 
40 #endif
41 
42 #if defined(CONFIG_STDOUT_CONSOLE)
43 extern void __stdout_hook_install(int (*hook)(int));
44 #endif
45 
46 #if defined(CONFIG_PRINTK)
47 extern void __printk_hook_install(int (*fn)(int));
48 #endif
49 
50 /**
51  * @brief Install printk/stdout hook for EFI console output
52  */
53 
efi_console_hook_install(void)54 static void efi_console_hook_install(void)
55 {
56 #if defined(CONFIG_STDOUT_CONSOLE)
57 	__stdout_hook_install(console_out);
58 #endif
59 #if defined(CONFIG_PRINTK)
60 	__printk_hook_install(console_out);
61 #endif
62 }
63 
64 /**
65  * @brief Initialize one EFI as the console port
66  *
67  * @return 0 if successful, otherwise failed.
68  */
efi_console_init(void)69 static int efi_console_init(void)
70 {
71 
72 
73 	efi_console_hook_install();
74 
75 	return 0;
76 }
77 
78 /* EFI console initializes */
79 SYS_INIT(efi_console_init,
80 	PRE_KERNEL_1,
81 	0);
82