Unify Local APIC address definitions
[coreboot.git] / src / mainboard / gigabyte / m57sli / mptable.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  * Copyright (C) 2009 Harald Gutmann <harald.gutmann@gmx.net>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
21  */
22
23 #include <console/console.h>
24 #include <arch/smp/mpspec.h>
25 #include <device/pci.h>
26 #include <string.h>
27 #include <stdint.h>
28 #include <cpu/amd/amdk8_sysconf.h>
29
30 extern unsigned char bus_mcp55[8]; //1
31
32 extern unsigned apicid_mcp55;
33
34 static void *smp_write_config_table(void *v)
35 {
36         struct mp_config_table *mc;
37         unsigned sbdn;
38         int i, j, k, bus_isa;
39
40         mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
41
42         mptable_init(mc, LOCAL_APIC_ADDR);
43
44         smp_write_processors(mc);
45
46         get_bus_conf();
47         sbdn = sysconf.sbdn;
48
49         mptable_write_buses(mc, NULL, &bus_isa);
50
51 /*I/O APICs:    APIC ID Version State           Address*/
52         {
53                 device_t dev;
54                 struct resource *res;
55
56                 dev = dev_find_slot(bus_mcp55[0], PCI_DEVFN(sbdn+ 0x1,0));
57                 if (dev) {
58                         res = find_resource(dev, PCI_BASE_ADDRESS_1);
59                         if (res) {
60                                 smp_write_ioapic(mc, apicid_mcp55, 0x11, res->base);
61                         }
62                         /* set up the interrupt registers of mcp55 */
63                         pci_write_config32(dev, 0x7c, 0xc643c643);
64                         pci_write_config32(dev, 0x80, 0x8da01009);
65                         pci_write_config32(dev, 0x84, 0x200018d2);
66                 }
67         }
68
69         mptable_add_isa_interrupts(mc, bus_isa, apicid_mcp55, 0);
70
71 /* PCI interrupts are level triggered, and are
72  * associated with a specific bus/device/function tuple.
73  */
74 #define PCI_INT(bus, dev, fn, pin)                                      \
75         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,\
76                          bus_mcp55[bus], (((dev)<<2)|(fn)), apicid_mcp55, (pin))
77
78         PCI_INT(0,sbdn+1,1, 10); /* SMBus */
79         PCI_INT(0,sbdn+2,0, 22); /* USB */
80         PCI_INT(0,sbdn+2,1, 23); /* USB */
81         PCI_INT(0,sbdn+4,0, 21); /* IDE */
82         PCI_INT(0,sbdn+5,0, 20); /* SATA */
83         PCI_INT(0,sbdn+5,1, 21); /* SATA */
84         PCI_INT(0,sbdn+5,2, 22); /* SATA */
85         PCI_INT(0,sbdn+6,1, 23); /* HD Audio */
86         PCI_INT(0,sbdn+8,0, 20); /* GBit Ethernet */
87
88         /* The PCIe slots, each on its own bus */
89         k = 1;
90         for(i=0; i<4; i++){
91                 for(j=7; j>1; j--){
92                         if(k>3) k=0;
93                         PCI_INT(j,0,i, 16+k);
94                         k++;
95                 }
96                 k--;
97         }
98
99         /* On bus 1: the PCI bus slots...
100            physical PCI slots are j = 7,8
101            FireWire is j = 10
102         */
103         k=2;
104         for(i=0; i<4; i++){
105                 for(j=6; j<11; j++){
106                         if(k>3) k=0;
107                         PCI_INT(1,j,i, 16+k);
108                         k++;
109                 }
110         }
111
112 /*Local Ints:   Type    Polarity    Trigger     Bus ID   IRQ    APIC ID PIN#*/
113         mptable_lintsrc(mc, bus_isa);
114         /* There is no extension information... */
115
116         /* Compute the checksums */
117         return mptable_finalize(mc);
118 }
119
120 unsigned long write_smp_table(unsigned long addr)
121 {
122         void *v;
123         v = smp_write_floating_table(addr, 0);
124         return (unsigned long)smp_write_config_table(v);
125 }