Two hda_verb.h files: Add more comments.
[coreboot.git] / src / arch / i386 / acpi / globutil.asl
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2008 Advanced Micro Devices, Inc.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
18  */
19
20 /*
21 Scope(\_SB) {
22         #include "globutil.asl"
23 }
24 */
25
26 /* string compare functions */
27 Method(MIN, 2)
28 {
29         if (LLess(Arg0, Arg1)) {
30                 Return(Arg0)
31         } else {
32                 Return(Arg1)
33         }
34 }
35
36 Method(SLEN, 1)
37 {
38         Store(Arg0, Local0)
39         Return(Sizeof(Local0))
40 }
41
42 Method(S2BF, 1)
43 {
44         Add(SLEN(Arg0), One, Local0)
45         Name(BUFF, Buffer(Local0) {})
46         Store(Arg0, BUFF)
47         Return(BUFF)
48 }
49
50 /* Strong string compare.  Checks both length and content */
51 Method(SCMP, 2)
52 {
53         Store(S2BF(Arg0), Local0)
54         Store(S2BF(Arg1), Local1)
55         Store(Zero, Local4)
56         Store(SLEN(Arg0), Local5)
57         Store(SLEN(Arg1), Local6)
58         Store(MIN(Local5, Local6), Local7)
59
60         While(LLess(Local4, Local7)) {
61                 Store(Derefof(Index(Local0, Local4)), Local2)
62                 Store(Derefof(Index(Local1, Local4)), Local3)
63                 if (LGreater(Local2, Local3)) {
64                         Return(One)
65                 } else {
66                         if (LLess(Local2, Local3)) {
67                                 Return(Ones)
68                         }
69                 }
70                 Increment(Local4)
71         }
72         if (LLess(Local4, Local5)) {
73                 Return(One)
74         } else {
75                 if (LLess(Local4, Local6)) {
76                         Return(Ones)
77                 } else {
78                         Return(Zero)
79                 }
80         }
81 }
82
83 /* Weak string compare.  Checks to find Arg1 at beginning of Arg0.
84 * Fails if length(Arg0) < length(Arg1).  Returns 0 on Fail, 1 on
85 * Pass.
86 */
87 Method(WCMP, 2)
88 {
89         Store(S2BF(Arg0), Local0)
90         Store(S2BF(Arg1), Local1)
91         if (LLess(SLEN(Arg0), SLEN(Arg1))) {
92                 Return(0)
93         }
94         Store(Zero, Local2)
95         Store(SLEN(Arg1), Local3)
96
97         While(LLess(Local2, Local3)) {
98                 if (LNotEqual(Derefof(Index(Local0, Local2)),
99                         Derefof(Index(Local1, Local2)))) {
100                         Return(0)
101                 }
102                 Increment(Local2)
103         }
104         Return(One)
105 }
106
107 /* ARG0 = IRQ Number(0-15)
108 * Returns Bit Map
109 */
110 Method(I2BM, 1)
111 {
112         Store(0, Local0)
113         if (LNotEqual(ARG0, 0)) {
114                 Store(1, Local1)
115                 ShiftLeft(Local1, ARG0, Local0)
116         }
117         Return(Local0)
118 }