xref: /openbmc/u-boot/arch/x86/include/asm/acpi/debug.asl (revision 57efeb04)
1/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * Copyright (C) 2008 Advanced Micro Devices, Inc.
4 * Copyright (C) 2016 Bin Meng <bmeng.cn@gmail.com>
5 *
6 * Modified from coreboot src/arch/x86/acpi/debug.asl
7 */
8
9/* POST register region */
10OperationRegion(X80, SystemIO, 0x80, 1)
11Field(X80, ByteAcc, NoLock, Preserve)
12{
13	P80, 8
14}
15
16/* Legacy serial port register region */
17OperationRegion(CREG, SystemIO, 0x3F8, 8)
18Field(CREG, ByteAcc, NoLock, Preserve)
19{
20	CDAT, 8,
21	CDLM, 8,
22	    , 8,
23	CLCR, 8,
24	CMCR, 8,
25	CLSR, 8
26}
27
28/* DINI - Initialize the serial port to 115200 8-N-1 */
29Method(DINI)
30{
31	Store(0x83, CLCR)
32	Store(0x01, CDAT)	/* 115200 baud (low) */
33	Store(0x00, CDLM)	/* 115200 baud (high) */
34	Store(0x03, CLCR)	/* word=8 stop=1 parity=none */
35	Store(0x03, CMCR)	/* DTR=1 RTS=1 out1/2=Off loop=Off */
36	Store(0x00, CDLM)	/* turn off interrupts */
37}
38
39/* THRE - Wait for serial port transmitter holding register to go empty */
40Method(THRE)
41{
42	And(CLSR, 0x20, Local0)
43	While (LEqual(Local0, Zero)) {
44		And(CLSR, 0x20, Local0)
45	}
46}
47
48/* OUTX - Send a single raw character */
49Method(OUTX, 1)
50{
51	THRE()
52	Store(Arg0, CDAT)
53}
54
55/* OUTC - Send a single character, expanding LF into CR/LF */
56Method(OUTC, 1)
57{
58	If (LEqual(Arg0, 0x0a)) {
59		OUTX(0x0d)
60	}
61	OUTX(Arg0)
62}
63
64/* DBGN - Send a single hex nibble */
65Method(DBGN, 1)
66{
67	And(Arg0, 0x0f, Local0)
68	If (LLess(Local0, 10)) {
69		Add(Local0, 0x30, Local0)
70	} Else {
71		Add(Local0, 0x37, Local0)
72	}
73	OUTC(Local0)
74}
75
76/* DBGB - Send a hex byte */
77Method(DBGB, 1)
78{
79	ShiftRight(Arg0, 4, Local0)
80	DBGN(Local0)
81	DBGN(Arg0)
82}
83
84/* DBGW - Send a hex word */
85Method(DBGW, 1)
86{
87	ShiftRight(Arg0, 8, Local0)
88	DBGB(Local0)
89	DBGB(Arg0)
90}
91
92/* DBGD - Send a hex dword */
93Method(DBGD, 1)
94{
95	ShiftRight(Arg0, 16, Local0)
96	DBGW(Local0)
97	DBGW(Arg0)
98}
99
100/* Get a char from a string */
101Method(GETC, 2)
102{
103	CreateByteField(Arg0, Arg1, DBGC)
104	Return (DBGC)
105}
106
107/* DBGO - Send either a string or an integer */
108Method(DBGO, 1, Serialized)
109{
110	If (LEqual(ObjectType(Arg0), 1)) {
111		If (LGreater(Arg0, 0xffff)) {
112			DBGD(Arg0)
113		} Else {
114			If (LGreater(Arg0, 0xff)) {
115				DBGW(Arg0)
116			} Else {
117				DBGB(Arg0)
118			}
119		}
120	} Else {
121		Name(BDBG, Buffer(80) {})
122		Store(Arg0, BDBG)
123		Store(0, Local1)
124		While (One) {
125			Store(GETC(BDBG, Local1), Local0)
126			If (LEqual(Local0, 0)) {
127				Return (Zero)
128			}
129			OUTC(Local0)
130			Increment(Local1)
131		}
132	}
133
134	Return (Zero)
135}
136