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 #include <zephyr/sys/printk-hooks.h>
20 #include <zephyr/sys/libc-hooks.h>
21 
22 extern int efi_console_putchar(int c);
23 
24 #if defined(CONFIG_PRINTK) || defined(CONFIG_STDOUT_CONSOLE)
25 /**
26  *
27  * @brief Output one character to EFI console
28  *
29  * Outputs both line feed and carriage return in the case of a '\n'.
30  *
31  * @param c Character to output
32  *
33  * @return The character passed as input.
34  */
35 
console_out(int c)36 static int console_out(int c)
37 {
38 	return efi_console_putchar(c);
39 }
40 
41 #endif
42 
43 /**
44  * @brief Install printk/stdout hook for EFI console output
45  */
46 
efi_console_hook_install(void)47 static void efi_console_hook_install(void)
48 {
49 #if defined(CONFIG_STDOUT_CONSOLE)
50 	__stdout_hook_install(console_out);
51 #endif
52 #if defined(CONFIG_PRINTK)
53 	__printk_hook_install(console_out);
54 #endif
55 }
56 
57 /**
58  * @brief Initialize one EFI as the console port
59  *
60  * @return 0 if successful, otherwise failed.
61  */
efi_console_init(void)62 static int efi_console_init(void)
63 {
64 
65 
66 	efi_console_hook_install();
67 
68 	return 0;
69 }
70 
71 /* EFI console initializes */
72 SYS_INIT(efi_console_init,
73 	PRE_KERNEL_1,
74 	0);
75