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