1    /*
2     * Some or all of this work - Copyright (c) 2006 - 2021, Intel Corp.
3     * All rights reserved.
4     *
5     * Redistribution and use in source and binary forms, with or without modification,
6     * are permitted provided that the following conditions are met:
7     *
8     * Redistributions of source code must retain the above copyright notice,
9     * this list of conditions and the following disclaimer.
10     * Redistributions in binary form must reproduce the above copyright notice,
11     * this list of conditions and the following disclaimer in the documentation
12     * and/or other materials provided with the distribution.
13     * Neither the name of Intel Corporation nor the names of its contributors
14     * may be used to endorse or promote products derived from this software
15     * without specific prior written permission.
16     *
17     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19     * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20     * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21     * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22     * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23     * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24     * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25     * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27     */
28    /*
29     * Resource Descriptor macros
30     */
31    Name (Z029, 0x1D)
32    Name (LPN0, 0x00)
33    Name (LPC0, 0x00)
34    Method (M330, 5, NotSerialized)
35    {
36        LPN0 = Arg1
37        LPC0 = 0x00
38        While (LPN0)
39        {
40            /* Operand */
41
42            Local0 = DerefOf (Arg3 [LPC0])
43            /* Expected result */
44
45            Local1 = DerefOf (Arg4 [LPC0])
46            If ((Local0 != Local1))
47            {
48                ERR (Arg0, Z029, __LINE__, 0x00, 0x00, LPC0, Arg2)
49            }
50
51            LPN0--
52            LPC0++
53        }
54
55        Return (0x00)
56    }
57
58    Method (M331, 7, NotSerialized)
59    {
60        If ((Arg2 != Arg3))
61        {
62            ERR (Arg0, Z029, __LINE__, Arg6, Arg6, Arg2, Arg3)
63        }
64
65        If ((Arg4 != Arg5))
66        {
67            ERR (Arg0, Z029, __LINE__, Arg6, Arg6, Arg4, Arg5)
68        }
69    }
70
71    Method (M332, 6, Serialized)
72    {
73        Name (LPN0, 0x00)
74        Name (LPC0, 0x00)
75        LPN0 = Arg1
76        LPC0 = 0x00
77        While (LPN0)
78        {
79            /* Operand 1 */
80
81            Local0 = DerefOf (Arg3 [LPC0])
82            /* Operand 2 */
83
84            Local1 = DerefOf (Arg4 [LPC0])
85            /* Expected result */
86
87            Local2 = DerefOf (Arg5 [LPC0])
88            Local3 = ConcatenateResTemplate (Local0, Local1)
89            If ((Local3 != Local2))
90            {
91                Debug = Local3
92                Debug = Local2
93                ERR (Arg0, Z029, __LINE__, 0x00, 0x00, LPC0, Arg2)
94            }
95
96            LPN0--
97            LPC0++
98        }
99
100        Return (0x00)
101    }
102
103    /* components/utilities/utmisc.c AcpiUtGenerateChecksum() analog */
104
105    Method (M335, 2, Serialized)
106    {
107        Name (LPN0, 0x00)
108        Name (LPC0, 0x00)
109        Local0 = 0x00 /* sum */
110        LPN0 = Arg1
111        LPC0 = 0x00
112        While (LPN0)
113        {
114            Local1 = DerefOf (Arg0 [LPC0])
115            Local0 += Local1
116            Local0 %= 0x0100
117            LPN0--
118            LPC0++
119        }
120
121        Local0 = (0x00 - Local0)
122        Local0 %= 0x0100
123        Debug = "checksum"
124        Debug = Local0
125        Return (Local0)
126    }
127
128    /* Updates the last byte of each buffer in package with checksum */
129
130    Method (M334, 2, Serialized)
131    {
132        Name (LPN0, 0x00)
133        Name (LPC0, 0x00)
134        LPN0 = Arg1
135        LPC0 = 0x00
136        While (LPN0)
137        {
138            Local1 = DerefOf (Arg0 [LPC0])
139            Local2 = SizeOf (Local1)
140            If (Local2)
141            {
142                Local2--
143                Local3 = M335 (Local1, Local2)
144                Local1 [Local2] = Local3
145                Arg0 [LPC0] = Local1
146            }
147
148            LPN0--
149            LPC0++
150        }
151
152        Return (0x00)
153    }
154