Skip to content

Commit ce7a0f7

Browse files
jackpot51crawfxrd
authored andcommitted
System76PayloadPkg: Add lib for logging to System76 EC
Make use of the SMFI command interface to forward logs from edk2 to System76 EC. Signed-off-by: Jeremy Soller <jeremy@system76.com> Signed-off-by: Tim Crawford <tcrawford@system76.com>
1 parent f12cb6d commit ce7a0f7

4 files changed

Lines changed: 174 additions & 1 deletion

File tree

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/** @file
2+
System76 EC logging
3+
4+
Copyright (c) 2020 System76, Inc.
5+
SPDX-License-Identifier: BSD-2-Clause-Patent
6+
7+
**/
8+
9+
#include <Library/IoLib.h>
10+
#include <Library/SerialPortLib.h>
11+
12+
// From coreboot/src/drivers/system76_ec/system76_ec.c {
13+
#define SYSTEM76_EC_BASE 0x0E00
14+
15+
static inline UINT8 system76_ec_read(UINT8 addr) {
16+
return IoRead8(SYSTEM76_EC_BASE + (UINT16)addr);
17+
}
18+
19+
static inline void system76_ec_write(UINT8 addr, UINT8 data) {
20+
IoWrite8(SYSTEM76_EC_BASE + (UINT16)addr, data);
21+
}
22+
23+
void system76_ec_init(void) {
24+
// Clear entire command region
25+
for (int i = 0; i < 256; i++) {
26+
system76_ec_write((UINT8)i, 0);
27+
}
28+
}
29+
30+
void system76_ec_flush(void) {
31+
// Send command
32+
system76_ec_write(0, 4);
33+
34+
// Wait for command completion
35+
while (system76_ec_read(0) != 0) {}
36+
37+
// Clear length
38+
system76_ec_write(3, 0);
39+
}
40+
41+
void system76_ec_print(UINT8 byte) {
42+
// Read length
43+
UINT8 len = system76_ec_read(3);
44+
// Write data at offset
45+
system76_ec_write(len + 4, byte);
46+
// Update length
47+
system76_ec_write(3, len + 1);
48+
49+
// If we hit the end of the buffer, or were given a newline, flush
50+
if (byte == '\n' || len >= 128) {
51+
system76_ec_flush();
52+
}
53+
}
54+
// } From coreboot/src/drivers/system76_ec/system76_ec.c
55+
56+
RETURN_STATUS
57+
EFIAPI
58+
SerialPortInitialize (
59+
VOID
60+
)
61+
{
62+
system76_ec_init();
63+
return RETURN_SUCCESS;
64+
}
65+
66+
UINTN
67+
EFIAPI
68+
SerialPortWrite (
69+
IN UINT8 *Buffer,
70+
IN UINTN NumberOfBytes
71+
)
72+
{
73+
if (Buffer == NULL) {
74+
return 0;
75+
}
76+
77+
if (NumberOfBytes == 0) {
78+
system76_ec_flush();
79+
return 0;
80+
}
81+
82+
for(UINTN i = 0; i < NumberOfBytes; i++) {
83+
system76_ec_print(Buffer[i]);
84+
}
85+
86+
return NumberOfBytes;
87+
}
88+
89+
BOOLEAN
90+
EFIAPI
91+
SerialPortPoll (
92+
VOID
93+
)
94+
{
95+
return FALSE;
96+
}
97+
98+
RETURN_STATUS
99+
EFIAPI
100+
SerialPortGetControl (
101+
OUT UINT32 *Control
102+
)
103+
{
104+
return RETURN_UNSUPPORTED;
105+
}
106+
107+
RETURN_STATUS
108+
EFIAPI
109+
SerialPortSetControl (
110+
IN UINT32 Control
111+
)
112+
{
113+
return RETURN_UNSUPPORTED;
114+
}
115+
116+
RETURN_STATUS
117+
EFIAPI
118+
SerialPortSetAttributes (
119+
IN OUT UINT64 *BaudRate,
120+
IN OUT UINT32 *ReceiveFifoDepth,
121+
IN OUT UINT32 *Timeout,
122+
IN OUT EFI_PARITY_TYPE *Parity,
123+
IN OUT UINT8 *DataBits,
124+
IN OUT EFI_STOP_BITS_TYPE *StopBits
125+
)
126+
{
127+
return RETURN_UNSUPPORTED;
128+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
## @file
2+
# System76 EC logging.
3+
#
4+
# Copyright (c) 2020, System76, Inc.
5+
# SPDX-License-Identifier: BSD-2-Clause-Patent
6+
##
7+
8+
[Defines]
9+
INF_VERSION = 0x00010005
10+
BASE_NAME = System76EcLib
11+
MODULE_UNI_FILE = System76EcLib.uni
12+
FILE_GUID = 76ECF0DD-148B-4E48-8589-FC998823F8C2
13+
MODULE_TYPE = BASE
14+
VERSION_STRING = 0.1
15+
LIBRARY_CLASS = System76EcLib
16+
17+
[Packages]
18+
MdePkg/MdePkg.dec
19+
MdeModulePkg/MdeModulePkg.dec
20+
System76PayloadPkg/System76PayloadPkg.dec
21+
22+
[LibraryClasses]
23+
IoLib
24+
25+
[Sources]
26+
System76EcLib.c
27+
28+
[Pcd]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// /** @file
2+
// System76 EC logging.
3+
//
4+
// Copyright (c) 2020, System76, Inc.
5+
// SPDX-License-Identifier: BSD-2-Clause-Patent
6+
//
7+
// **/
8+
9+
10+
#string STR_MODULE_ABSTRACT #language en-US "System76 EC logging"
11+
12+
#string STR_MODULE_DESCRIPTION #language en-US "System76 EC logging."
13+

System76PayloadPkg/System76PayloadPkg.dsc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
DEFINE CAPSULE_SUPPORT = FALSE
4646
DEFINE LOCKBOX_SUPPORT = FALSE
4747
DEFINE LOAD_OPTION_ROMS = FALSE
48+
DEFINE SYSTEM76_EC_LOGGING = FALSE
4849

4950
#
5051
# Crypto Support
@@ -284,7 +285,10 @@
284285
CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLib.inf
285286
FrameBufferBltLib|MdeModulePkg/Library/FrameBufferBltLib/FrameBufferBltLib.inf
286287
ResetSystemLib|System76PayloadPkg/Library/ResetSystemLib/ResetSystemLib.inf
287-
!if $(USE_CBMEM_FOR_CONSOLE) == TRUE
288+
!if $(SYSTEM76_EC_LOGGING) == TRUE
289+
SerialPortLib|System76PayloadPkg/Library/System76EcLib/System76EcLib.inf
290+
PlatformHookLib|MdeModulePkg/Library/BasePlatformHookLibNull/BasePlatformHookLibNull.inf
291+
!elseif $(USE_CBMEM_FOR_CONSOLE) == TRUE
288292
SerialPortLib|System76PayloadPkg/Library/CbSerialPortLib/CbSerialPortLib.inf
289293
PlatformHookLib|MdeModulePkg/Library/BasePlatformHookLibNull/BasePlatformHookLibNull.inf
290294
!else

0 commit comments

Comments
 (0)