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/globutil.asl 7 */ 8 9Method(MIN, 2) 10{ 11 If (LLess(Arg0, Arg1)) { 12 Return (Arg0) 13 } Else { 14 Return (Arg1) 15 } 16} 17 18Method(SLEN, 1) 19{ 20 Store(Arg0, Local0) 21 Return (Sizeof(Local0)) 22} 23 24Method(S2BF, 1, Serialized) 25{ 26 Add(SLEN(Arg0), One, Local0) 27 Name(BUFF, Buffer(Local0) {}) 28 Store(Arg0, BUFF) 29 Return (BUFF) 30} 31 32/* 33 * SCMP - Strong string compare 34 * 35 * Checks both length and content 36 */ 37Method(SCMP, 2) 38{ 39 Store(S2BF(Arg0), Local0) 40 Store(S2BF(Arg1), Local1) 41 Store(Zero, Local4) 42 Store(SLEN(Arg0), Local5) 43 Store(SLEN(Arg1), Local6) 44 Store(MIN(Local5, Local6), Local7) 45 46 While (LLess(Local4, Local7)) { 47 Store(Derefof(Index(Local0, Local4)), Local2) 48 Store(Derefof(Index(Local1, Local4)), Local3) 49 If (LGreater(Local2, Local3)) { 50 Return (One) 51 } Else { 52 If (LLess(Local2, Local3)) { 53 Return (Ones) 54 } 55 } 56 Increment(Local4) 57 } 58 59 If (LLess(Local4, Local5)) { 60 Return (One) 61 } Else { 62 If (LLess(Local4, Local6)) { 63 Return (Ones) 64 } Else { 65 Return (Zero) 66 } 67 } 68} 69 70/* 71 * WCMP - Weak string compare 72 * 73 * Checks to find Arg1 at beginning of Arg0. 74 * Fails if length(Arg0) < length(Arg1). 75 * Returns 0 on fail, 1 on pass. 76 */ 77Method(WCMP, 2) 78{ 79 Store(S2BF(Arg0), Local0) 80 Store(S2BF(Arg1), Local1) 81 If (LLess(SLEN(Arg0), SLEN(Arg1))) { 82 Return (Zero) 83 } 84 Store(Zero, Local2) 85 Store(SLEN(Arg1), Local3) 86 87 While (LLess(Local2, Local3)) { 88 If (LNotEqual(Derefof(Index(Local0, Local2)), 89 Derefof(Index(Local1, Local2)))) { 90 Return (Zero) 91 } 92 Increment(Local2) 93 } 94 95 Return (One) 96} 97 98/* 99 * I2BM - Returns Bit Map 100 * 101 * Arg0 = IRQ Number (0-15) 102 */ 103Method(I2BM, 1) 104{ 105 Store(0, Local0) 106 If (LNotEqual(Arg0, 0)) { 107 Store(1, Local1) 108 ShiftLeft(Local1, Arg0, Local0) 109 } 110 111 Return (Local0) 112} 113