more acpica fixes... The tricky part is the stuff in the AMD mainboard directories.
[coreboot.git] / src / northbridge / amd / amdfam10 / amdfam10_util.asl
1 //
2 // This file is part of the coreboot project.
3 //
4 // Copyright (C) 2007 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 //AMD FAM10 util for BUSB and res range
21
22 Scope (\_SB)
23 {
24
25         Name (OSTB, Ones)
26         Method (OSTP, 0, NotSerialized)
27         {
28                 If (LEqual (^OSTB, Ones))
29                 {
30                         Store (0x00, ^OSTB)
31                 }
32
33                 Return (^OSTB)
34         }
35
36         Method (SEQL, 2, Serialized)
37         {
38                 Store (SizeOf (Arg0), Local0)
39                 Store (SizeOf (Arg1), Local1)
40                 If (LNot (LEqual (Local0, Local1))) { Return (Zero) }
41
42                 Name (BUF0, Buffer (Local0) {})
43                 Store (Arg0, BUF0)
44                 Name (BUF1, Buffer (Local0) {})
45                 Store (Arg1, BUF1)
46                 Store (Zero, Local2)
47                 While (LLess (Local2, Local0))
48                 {
49                         Store (DerefOf (Index (BUF0, Local2)), Local3)
50                         Store (DerefOf (Index (BUF1, Local2)), Local4)
51                         If (LNot (LEqual (Local3, Local4))) { Return (Zero) }
52
53                         Increment (Local2)
54                 }
55
56                 Return (One)
57         }
58
59
60         Method (DADD, 2, NotSerialized)
61         {
62                 Store( Arg1, Local0)
63                 Store( Arg0, Local1)
64                 Add( ShiftLeft(Local1,16), Local0, Local0)
65                 Return (Local0)
66         }
67
68
69         Method (GHCE, 1, NotSerialized) // check if the HC enabled
70         {
71                 Store (DerefOf (Index (\_SB.PCI0.HCLK, Arg0)), Local1)
72                 if(LEqual ( And(Local1, 0x01), 0x01)) { Return (0x0F) }
73                 Else { Return (0x00) }
74         }
75
76         Method (GHCN, 1, NotSerialized) // get the node num for the HC
77         {
78                 Store (0x00, Local0)
79                 Store (DerefOf (Index (\_SB.PCI0.HCLK, Arg0)), Local1)
80                 Store (ShiftRight( And (Local1, 0xfc), 0x02), Local0)
81                 Return (Local0)
82         }
83
84         Method (GHCL, 1, NotSerialized) // get the link num on node for the HC
85         {
86                 Store (0x00, Local0)
87                 Store (DerefOf (Index (\_SB.PCI0.HCLK, Arg0)), Local1)
88                 Store (ShiftRight( And (Local1, 0x700), 0x08), Local0)
89                 Return (Local0)
90         }
91
92         Method (GHCD, 2, NotSerialized) // get the unit id base for the HT device in HC
93         {
94                 Store (0x00, Local0)
95                 Store (DerefOf (Index (\_SB.PCI0.HCDN, Arg0)), Local1)
96                 Store (Arg1, Local2) // Arg1 could be 3, 2, 1, 0
97                 Multiply (Local2, 0x08, Local2) // change to 24, 16, 8, 0
98                 Store (And (ShiftRight( Local1, Local2), 0xff), Local0)
99                 Return (Local0)
100         }
101
102         Method (GBUS, 2, NotSerialized)
103         {
104                 Store (0x00, Local0)
105                 While (LLess (Local0, 0x20)) // 32 ht links
106                 {
107                         Store (DerefOf (Index (\_SB.PCI0.BUSN, Local0)), Local1)
108                         If (LEqual (And (Local1, 0x03), 0x03))
109                         {
110                                 If (LEqual (Arg0, ShiftRight (And (Local1, 0xfc), 0x02)))
111                                 {
112                                         If (LOr (LEqual (Arg1, 0xFF), LEqual (Arg1, ShiftRight (And (Local1, 0x0700), 0x08))))
113                                         {
114                                                 Return (ShiftRight (And (Local1, 0x000FF000), 0x0c))
115                                         }
116                                 }
117                         }
118
119                         Increment (Local0)
120                 }
121
122                 Return (0x00)
123         }
124
125         Method (GWBN, 2, NotSerialized)
126         {
127                 Name (BUF0, ResourceTemplate ()
128                 {
129                         WordBusNumber (ResourceProducer, MinFixed, MaxFixed, PosDecode,
130                                 0x0000, // Address Space Granularity
131                                 0x0000, // Address Range Minimum
132                                 0x0000, // Address Range Maximum
133                                 0x0000, // Address Translation Offset
134                                 0x0001,,,)
135                 })
136                 CreateWordField (BUF0, 0x08, BMIN)
137                 CreateWordField (BUF0, 0x0A, BMAX)
138                 CreateWordField (BUF0, 0x0E, BLEN)
139                 Store (0x00, Local0)
140                 While (LLess (Local0, 0x20))
141                 {
142                         Store (DerefOf (Index (\_SB.PCI0.BUSN, Local0)), Local1)
143                         If (LEqual (And (Local1, 0x03), 0x03))
144                         {
145                                 If (LEqual (Arg0, ShiftRight (And (Local1, 0xfc), 0x02)))
146                                 {
147                                         If (LOr (LEqual (Arg1, 0xFF), LEqual (Arg1, ShiftRight (And (Local1, 0x0700), 0x08))))
148                                         {
149                                                 Store (ShiftRight (And (Local1, 0x000FF000), 0x0c), BMIN)
150                                                 Store (ShiftRight (Local1, 0x14), BMAX)
151                                                 Subtract (BMAX, BMIN, BLEN)
152                                                 Increment (BLEN)
153                                                 Return (RTAG (BUF0))
154                                         }
155                                 }
156                         }
157
158                         Increment (Local0)
159                 }
160
161                 Return (RTAG (BUF0))
162         }
163
164         Method (GMEM, 2, NotSerialized)
165         {
166                 Name (BUF0, ResourceTemplate ()
167                 {
168                         DWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed, NonCacheable, ReadWrite,
169                                 0x00000000, // Address Space Granularity
170                                 0x00000000, // Address Range Minimum
171                                 0x00000000, // Address Range Maximum
172                                 0x00000000, // Address Translation Offset
173                                 0x00000001,,,
174                                 , AddressRangeMemory, TypeStatic)
175                 })
176                 CreateDWordField (BUF0, 0x0A, MMIN)
177                 CreateDWordField (BUF0, 0x0E, MMAX)
178                 CreateDWordField (BUF0, 0x16, MLEN)
179                 Store (0x00, Local0)
180                 Store (0x00, Local4)
181                 Store (0x00, Local3)
182                 While (LLess (Local0, 0x80)) // 0x20 links * 2(mem, prefmem ) *2 ( base, limit )
183                 {
184                         Store (DerefOf (Index (\_SB.PCI0.MMIO, Local0)), Local1)
185                         Increment (Local0)
186                         Store (DerefOf (Index (\_SB.PCI0.MMIO, Local0)), Local2)
187                         If (LEqual (And (Local1, 0x03), 0x03))
188                         {
189                                 If (LEqual (Arg0, And (Local2, 0x3f)))
190                                 {
191                                         If (LOr (LEqual (Arg1, 0xFF), LEqual (Arg1, ShiftRight (And (Local1, 0x70), 0x04))))
192                                         {
193                                                 Store (ShiftLeft (And (Local1, 0xFFFFFF00), 0x08), MMIN)
194                                                 Store (ShiftLeft (And (Local2, 0xFFFFFF00), 0x08), MMAX)
195                                                 Or (MMAX, 0xFFFF, MMAX)
196                                                 Subtract (MMAX, MMIN, MLEN)
197                                                 Increment (MLEN)
198
199                                                 If (Local4)
200                                                 {
201                                                         Concatenate (RTAG (BUF0), Local3, Local5)
202                                                         Store (Local5, Local3)
203                                                 }
204                                                 Else
205                                                 {
206                                                         Store (RTAG (BUF0), Local3)
207                                                 }
208
209                                                 Increment (Local4)
210                                         }
211                                 }
212                         }
213
214                         Increment (Local0)
215                 }
216
217                 If (LNot (Local4))
218                 {
219                         Store (BUF0, Local3)
220                 }
221
222                 Return (Local3)
223         }
224
225         Method (GIOR, 2, NotSerialized)
226         {
227                 Name (BUF0, ResourceTemplate ()
228                 {
229                         DWordIO (ResourceProducer, MinFixed, MaxFixed, PosDecode, EntireRange,
230                                 0x00000000, // Address Space Granularity
231                                 0x00000000, // Address Range Minimum
232                                 0x00000000, // Address Range Maximum
233                                 0x00000000, // Address Translation Offset
234                                 0x00000001,,,
235                                 , TypeStatic)
236                 })
237                 CreateDWordField (BUF0, 0x0A, PMIN)
238                 CreateDWordField (BUF0, 0x0E, PMAX)
239                 CreateDWordField (BUF0, 0x16, PLEN)
240                 Store (0x00, Local0)
241                 Store (0x00, Local4)
242                 Store (0x00, Local3)
243                 While (LLess (Local0, 0x40)) // 0x20 ht links * 2 ( base, limit)
244                 {
245                         Store (DerefOf (Index (\_SB.PCI0.PCIO, Local0)), Local1)
246                         Increment (Local0)
247                         Store (DerefOf (Index (\_SB.PCI0.PCIO, Local0)), Local2)
248                         If (LEqual (And (Local1, 0x03), 0x03))
249                         {
250                                 If (LEqual (Arg0, And (Local2, 0x3f)))
251                                 {
252                                         If (LOr (LEqual (Arg1, 0xFF), LEqual (Arg1, ShiftRight (And (Local1, 0x70), 0x04))))
253                                         {
254                                                 Store (And (Local1, 0x01FFF000), PMIN)
255                                                 Store (And (Local2, 0x01FFF000), PMAX)
256                                                 Or (PMAX, 0x0FFF, PMAX)
257                                                 Subtract (PMAX, PMIN, PLEN)
258                                                 Increment (PLEN)
259
260                                                 If (Local4)
261                                                 {
262                                                         Concatenate (RTAG (BUF0), Local3, Local5)
263                                                         Store (Local5, Local3)
264                                                 }
265                                                 Else
266                                                 {
267                                                         If (LGreater (PMAX, PMIN))
268                                                         {
269                                                                 If (LOr (LAnd (LEqual (Arg1, 0xFF), LEqual (Arg0, 0x00)), LEqual (Arg1, \_SB.PCI0.SBLK)))
270                                                                 {
271                                                                         Store (0x0D00, PMIN)
272                                                                         Subtract (PMAX, PMIN, PLEN)
273                                                                         Increment (PLEN)
274                                                                 }
275
276                                                                 Store (RTAG (BUF0), Local3)
277                                                                 Increment (Local4)
278                                                         }
279
280                                                         If (And (Local1, 0x10))
281                                                         {
282                                                                 Store (0x03B0, PMIN)
283                                                                 Store (0x03DF, PMAX)
284                                                                 Store (0x30, PLEN)
285
286                                                                 If (Local4)
287                                                                 {
288                                                                         Concatenate (RTAG (BUF0), Local3, Local5)
289                                                                         Store (Local5, Local3)
290                                                                 }
291                                                                 Else
292                                                                 {
293                                                                         Store (RTAG (BUF0), Local3)
294                                                                 }
295                                                         }
296                                                 }
297
298                                                 Increment (Local4)
299                                         }
300                                 }
301                         }
302
303                         Increment (Local0)
304                 }
305
306                 If (LNot (Local4))
307                 {
308                         Store (RTAG (BUF0), Local3)
309                 }
310
311                 Return (Local3)
312         }
313
314         Method (RTAG, 1, NotSerialized)
315         {
316                 Store (Arg0, Local0)
317                 Store (SizeOf (Local0), Local1)
318                 Subtract (Local1, 0x02, Local1)
319                 Multiply (Local1, 0x08, Local1)
320                 CreateField (Local0, 0x00, Local1, RETB)
321                 Store (RETB, Local2)
322                 Return (Local2)
323         }
324 }