Add constants for fast path resume copying
[coreboot.git] / src / mainboard / amd / serengeti_cheetah_fam10 / get_bus_conf.c
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 #include <console/console.h>
21 #include <device/pci.h>
22 #include <device/pci_ids.h>
23 #include <string.h>
24 #include <stdint.h>
25 #if CONFIG_LOGICAL_CPUS==1
26 #include <cpu/amd/multicore.h>
27 #endif
28
29 #include <cpu/amd/amdfam10_sysconf.h>
30
31 #include <stdlib.h>
32 #include "mb_sysconf.h"
33
34 /* Global variables for MB layouts and these will be shared by irqtable mptable and acpi_tables */
35 struct mb_sysconf_t mb_sysconf;
36
37 /* Here you only need to set value in pci1234 for HT-IO that could be
38 installed or not You may need to preset pci1234 for HTIO board, please
39 refer to src/northbridge/amd/amdfam10/get_sblk_pci1234.c for detail */
40 static u32 pci1234x[] = {
41         0x0000ffc, 0x0000ffc, 0x0000ffc, 0x0000ffc, 0x0000ffc, 0x0000ffc,
42         0x0000ffc, 0x0000ffc, 0x0000ffc, 0x0000ffc, 0x0000ffc, 0x0000ffc,
43         0x0000ffc, 0x0000ffc, 0x0000ffc, 0x0000ffc, 0x0000ffc, 0x0000ffc,
44         0x0000ffc, 0x0000ffc, 0x0000ffc, 0x0000ffc, 0x0000ffc, 0x0000ffc,
45         0x0000ffc, 0x0000ffc, 0x0000ffc, 0x0000ffc, 0x0000ffc, 0x0000ffc,
46         0x0000ffc, 0x0000ffc,
47         };
48
49
50 /* HT Chain device num, actually it is unit id base of every ht device
51 in chain, assume every chain only have 4 ht device at most */
52
53 static unsigned hcdnx[] = {
54         0x20202020, 0x20202020, 0x20202020, 0x20202020, 0x20202020,
55         0x20202020, 0x20202020, 0x20202020, 0x20202020, 0x20202020,
56         0x20202020, 0x20202020, 0x20202020, 0x20202020, 0x20202020,
57         0x20202020, 0x20202020, 0x20202020, 0x20202020, 0x20202020,
58         0x20202020, 0x20202020, 0x20202020, 0x20202020, 0x20202020,
59         0x20202020, 0x20202020, 0x20202020, 0x20202020, 0x20202020,
60         0x20202020, 0x20202020,
61 };
62
63
64
65 extern void get_pci1234(void);
66
67 static u32 get_bus_conf_done = 0;
68
69 static u32 get_hcid(u32 i)
70 {
71         u32 id = 0;
72         u32 busn = (sysconf.pci1234[i] >> 12) & 0xff;
73         u32 devn = sysconf.hcdn[i] & 0xff;
74         device_t dev;
75
76         dev = dev_find_slot(busn, PCI_DEVFN(devn,0));
77
78         switch (dev->device) {
79         case 0x7458: //8132
80                 id = 1;
81                 break;
82         case 0x7454: //8151
83                 id = 2;
84                 break;
85         case 0x7450: //8131
86                 id = 3;
87                 break;
88         }
89         // we may need more way to find out hcid: subsystem id? GPIO read ?
90         // we need use id for 1. bus num, 2. mptable, 3. acpi table
91         return id;
92 }
93
94 void get_bus_conf(void)
95 {
96         u32 apicid_base;
97
98         device_t dev;
99         int i, j;
100         struct mb_sysconf_t *m;
101
102         if(get_bus_conf_done == 1)
103                 return; //do it only once
104
105         get_bus_conf_done = 1;
106
107         sysconf.mb = &mb_sysconf;
108
109         m = sysconf.mb;
110
111         sysconf.hc_possible_num = ARRAY_SIZE(pci1234x);
112         for(i=0;i<sysconf.hc_possible_num; i++) {
113                 sysconf.pci1234[i] = pci1234x[i];
114                 sysconf.hcdn[i] = hcdnx[i];
115         }
116
117         get_pci1234();
118
119         sysconf.sbdn = (sysconf.hcdn[0] >> 8) & 0xff;
120         m->sbdn3 = sysconf.hcdn[0] & 0xff;
121
122         m->bus_8132_0 = (sysconf.pci1234[0] >> 12) & 0xff;
123         m->bus_8111_0 = m->bus_8132_0;
124
125         /* 8111 */
126         dev = dev_find_slot(m->bus_8111_0, PCI_DEVFN(sysconf.sbdn,0));
127         if (dev) {
128                 m->bus_8111_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
129         } else {
130                 printk(BIOS_DEBUG, "ERROR - could not find PCI %02x:%02x.0, using defaults\n", m->bus_8111_0, sysconf.sbdn);
131         }
132
133         /* 8132-1 */
134         dev = dev_find_slot(m->bus_8132_0, PCI_DEVFN(m->sbdn3,0));
135         if (dev) {
136                 m->bus_8132_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
137         } else {
138                 printk(BIOS_DEBUG, "ERROR - could not find PCI %02x:%02x.0, using defaults\n", m->bus_8132_0, m->sbdn3);
139         }
140
141         /* 8132-2 */
142         dev = dev_find_slot(m->bus_8132_0, PCI_DEVFN(m->sbdn3+1,0));
143         if (dev) {
144                 m->bus_8132_2 = pci_read_config8(dev, PCI_SECONDARY_BUS);
145         } else {
146                 printk(BIOS_DEBUG, "ERROR - could not find PCI %02x:%02x.0, using defaults\n", m->bus_8132_0, m->sbdn3+1);
147         }
148
149          /* HT chain 1 */
150         j=0;
151         for(i=1; i< sysconf.hc_possible_num; i++) {
152                 if(!(sysconf.pci1234[i] & 0x1) ) continue;
153
154                 // check hcid type here
155                 sysconf.hcid[i] = get_hcid(i);
156
157                 switch(sysconf.hcid[i]) {
158
159                 case 1: //8132
160                 case 3: //8131
161
162                         m->bus_8132a[j][0] = (sysconf.pci1234[i] >> 12) & 0xff;
163
164                         m->sbdn3a[j] = sysconf.hcdn[i] & 0xff;
165
166                         /* 8132-1 */
167                         dev = dev_find_slot(m->bus_8132a[j][0], PCI_DEVFN(m->sbdn3a[j],0));
168                         if (dev) {
169                                 m->bus_8132a[j][1] = pci_read_config8(dev, PCI_SECONDARY_BUS);
170                         } else {
171                                 printk(BIOS_DEBUG, "ERROR - could not find PCI %02x:%02x.0, using defaults\n", m->bus_8132a[j][0], m->sbdn3a[j]);
172                         }
173
174                         /* 8132-2 */
175                         dev = dev_find_slot(m->bus_8132a[j][0], PCI_DEVFN(m->sbdn3a[j]+1,0));
176                         if (dev) {
177                                 m->bus_8132a[j][2] = pci_read_config8(dev, PCI_SECONDARY_BUS);
178                         } else {
179                                 printk(BIOS_DEBUG, "ERROR - could not find PCI %02x:%02x.0, using defaults\n", m->bus_8132a[j][0], m->sbdn3a[j]+1);
180                         }
181
182                         break;
183
184                 case 2: //8151
185
186                         m->bus_8151[j][0] = (sysconf.pci1234[i] >> 12) & 0xff;
187                         m->sbdn5[j] = sysconf.hcdn[i] & 0xff;
188                         /* 8151 */
189                         dev = dev_find_slot(m->bus_8151[j][0], PCI_DEVFN(m->sbdn5[j]+1, 0));
190
191                         if (dev) {
192                                 m->bus_8151[j][1] = pci_read_config8(dev, PCI_SECONDARY_BUS);
193                         } else {
194                                 printk(BIOS_DEBUG, "ERROR - could not find PCI %02x:%02x.0, using defaults\n", m->bus_8151[j][0], m->sbdn5[j]+1);
195                         }
196
197                         break;
198                 }
199
200                 j++;
201          }
202
203 /*I/O APICs:    APIC ID Version State           Address*/
204         apicid_base = 0;
205         m->apicid_8111 = apicid_base + 0;
206         m->apicid_8132_1 = apicid_base + 1;
207         m->apicid_8132_2 = apicid_base + 2;
208         for(i=0;i<j;i++) {
209                 m->apicid_8132a[i][0] = apicid_base + 3 + i * 2;
210                 m->apicid_8132a[i][1] = apicid_base + 3 + i * 2 + 1;
211         }
212 }