Add support for the ASUS M2N-E board.
[coreboot.git] / src / mainboard / asus / m2n-e / get_bus_conf.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2007 AMD
5  * Written by Yinghai Lu <yinghailu@amd.com> for AMD.
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
20  */
21
22 #include <console/console.h>
23 #include <device/pci.h>
24 #include <device/pci_ids.h>
25 #include <string.h>
26 #include <stdint.h>
27 #if CONFIG_LOGICAL_CPUS==1
28 #include <cpu/amd/multicore.h>
29 #endif
30 #include <cpu/amd/amdk8_sysconf.h>
31 #include <stdlib.h>
32
33 /* Global variables for MB layouts (shared by irqtable/mptable/acpi_table). */
34 // busnum is default.
35 unsigned char bus_mcp55[8];     // 1
36 unsigned apicid_mcp55;
37
38 unsigned pci1234x[] = {
39         /* Here you only need to set value in pci1234 for HT-IO that could
40          * be installed or not. You may need to preset pci1234 for HTIO board,
41          * please refer to * src/northbridge/amd/amdk8/get_sblk_pci1234.c.
42          */
43         0x0000ff0,
44 //      0x0000ff0,
45 //      0x0000ff0,
46 //      0x0000ff0,
47 //      0x0000ff0,
48 //      0x0000ff0,
49 //      0x0000ff0,
50 //      0x0000ff0
51 };
52
53 unsigned hcdnx[] = {
54         /* HT Chain device num, actually it is unit id base of every ht
55          * device in chain, assume every chain only have 4 ht device at most.
56          */
57         0x20202020,
58 //      0x20202020,
59 //      0x20202020,
60 //      0x20202020,
61 //      0x20202020,
62 //      0x20202020,
63 //      0x20202020,
64 //      0x20202020,
65 };
66
67 static unsigned get_bus_conf_done = 0;
68
69 void get_bus_conf(void)
70 {
71         unsigned int apicid_base, sbdn;
72         device_t dev;
73         int i;
74
75         if (get_bus_conf_done == 1)
76                 return;         /* Do it only once. */
77
78         get_bus_conf_done = 1;
79
80         sysconf.hc_possible_num = ARRAY_SIZE(pci1234x);
81         for (i = 0; i < sysconf.hc_possible_num; i++) {
82                 sysconf.pci1234[i] = pci1234x[i];
83                 sysconf.hcdn[i] = hcdnx[i];
84         }
85
86         get_sblk_pci1234();
87
88         sysconf.sbdn = (sysconf.hcdn[0] & 0xff); /* First byte of first chain */
89         sbdn = sysconf.sbdn;
90
91         for (i = 0; i < 8; i++)
92                 bus_mcp55[i] = 0;
93
94         bus_mcp55[0] = (sysconf.pci1234[0] >> 16) & 0xff;
95
96         dev = dev_find_slot(bus_mcp55[0], PCI_DEVFN(sbdn + 0x06, 0));
97         if (dev) {
98                 bus_mcp55[1] = pci_read_config8(dev, PCI_SECONDARY_BUS);
99                 bus_mcp55[2] = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
100                 bus_mcp55[2]++;
101         } else {
102                 printk(BIOS_DEBUG, "ERROR - could not find PCI 1:%02x.0, "
103                        "using defaults\n", sbdn + 0x06);
104                 bus_mcp55[1] = 2;
105                 bus_mcp55[2] = 3;
106         }
107
108         for (i = 2; i < 8; i++) {
109                 dev = dev_find_slot(bus_mcp55[0],
110                                     PCI_DEVFN(sbdn + 0x0a + i - 2, 0));
111                 if (dev)
112                         bus_mcp55[i] = pci_read_config8(dev, PCI_SECONDARY_BUS);
113         }
114
115 #if CONFIG_LOGICAL_CPUS == 1
116         apicid_base = get_apicid_base(1);
117 #else
118         apicid_base = CONFIG_MAX_PHYSICAL_CPUS;
119 #endif
120         apicid_mcp55 = apicid_base + 0;
121 }