Initial AMD Serengeti_Cheetah_FAM10 platform for Barcelona support.
[coreboot.git] / src / mainboard / amd / serengeti_cheetah_fam10 / dx / amdfam10_util.asl
1 //
2 // This file is part of the LinuxBIOS 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                                 0x0000,,,)
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                                 0x00000000,,,
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
198                                                 If (Local4)
199                                                 {
200                                                         Concatenate (RTAG (BUF0), Local3, Local5)
201                                                         Store (Local5, Local3)
202                                                 }
203                                                 Else
204                                                 {
205                                                         If (LOr (LAnd (LEqual (Arg1, 0xFF), LEqual (Arg0, 0x00)), LEqual (Arg1, \_SB.PCI0.SBLK)))
206                                                         {
207                                                                 Store (\_SB.PCI0.TOM1, MMIN)
208                                                                 Subtract (MMAX, MMIN, MLEN)
209                                                                 Increment (MLEN)
210                                                         }
211
212                                                         Store (RTAG (BUF0), Local3)
213                                                 }
214
215                                                 Increment (Local4)
216                                         }
217                                 }
218                         }
219
220                         Increment (Local0)
221                 }
222
223                 If (LNot (Local4))
224                 {
225                         Store (BUF0, Local3)
226                 }
227
228                 Return (Local3)
229         }
230
231         Method (GIOR, 2, NotSerialized)
232         {
233                 Name (BUF0, ResourceTemplate ()
234                 {
235                         DWordIO (ResourceProducer, MinFixed, MaxFixed, PosDecode, EntireRange,
236                                 0x00000000, // Address Space Granularity
237                                 0x00000000, // Address Range Minimum
238                                 0x00000000, // Address Range Maximum
239                                 0x00000000, // Address Translation Offset
240                                 0x00000000,,,
241                                 , TypeStatic)
242                 })
243                 CreateDWordField (BUF0, 0x0A, PMIN)
244                 CreateDWordField (BUF0, 0x0E, PMAX)
245                 CreateDWordField (BUF0, 0x16, PLEN)
246                 Store (0x00, Local0)
247                 Store (0x00, Local4)
248                 Store (0x00, Local3)
249                 While (LLess (Local0, 0x40)) // 0x20 ht links  * 2 ( base, limit)
250                 {
251                         Store (DerefOf (Index (\_SB.PCI0.PCIO, Local0)), Local1)
252                         Increment (Local0)
253                         Store (DerefOf (Index (\_SB.PCI0.PCIO, Local0)), Local2)
254                         If (LEqual (And (Local1, 0x03), 0x03))
255                         {
256                                 If (LEqual (Arg0, And (Local2, 0x3f)))
257                                 {
258                                         If (LOr (LEqual (Arg1, 0xFF), LEqual (Arg1, ShiftRight (And (Local1, 0x70), 0x04))))
259                                         {
260                                                 Store (And (Local1, 0x01FFF000), PMIN)
261                                                 Store (And (Local2, 0x01FFF000), PMAX)
262                                                 Or (PMAX, 0x0FFF, PMAX)
263                                                 Subtract (PMAX, PMIN, PLEN)
264                                                 Increment (PLEN)
265
266                                                 If (Local4)
267                                                 {
268                                                         Concatenate (RTAG (BUF0), Local3, Local5)
269                                                         Store (Local5, Local3)
270                                                 }
271                                                 Else
272                                                 {
273                                                         If (LGreater (PMAX, PMIN))
274                                                         {
275                                                                 If (LOr (LAnd (LEqual (Arg1, 0xFF), LEqual (Arg0, 0x00)), LEqual (Arg1, \_SB.PCI0.SBLK)))
276                                                                 {
277                                                                         Store (0x0D00, PMIN)
278                                                                         Subtract (PMAX, PMIN, PLEN)
279                                                                         Increment (PLEN)
280                                                                 }
281
282                                                                 Store (RTAG (BUF0), Local3)
283                                                                 Increment (Local4)
284                                                         }
285
286                                                         If (And (Local1, 0x10))
287                                                         {
288                                                                 Store (0x03B0, PMIN)
289                                                                 Store (0x03DF, PMAX)
290                                                                 Store (0x30, PLEN)
291                                                                 If (Local4)
292                                                                 {
293                                                                         Concatenate (RTAG (BUF0), Local3, Local5)
294                                                                         Store (Local5, Local3)
295                                                                 }
296                                                                 Else
297                                                                 {
298                                                                         Store (RTAG (BUF0), Local3)
299                                                                 }
300                                                         }
301                                                 }
302
303                                                 Increment (Local4)
304                                         }
305                                 }
306                         }
307
308                         Increment (Local0)
309                 }
310
311                 If (LNot (Local4))
312                 {
313                         Store (RTAG (BUF0), Local3)
314                 }
315
316                 Return (Local3)
317         }
318
319         Method (RTAG, 1, NotSerialized)
320         {
321                 Store (Arg0, Local0)
322                 Store (SizeOf (Local0), Local1)
323                 Subtract (Local1, 0x02, Local1)
324                 Multiply (Local1, 0x08, Local1)
325                 CreateField (Local0, 0x00, Local1, RETB)
326                 Store (RETB, Local2)
327                 Return (Local2)
328         }
329 }