Unify Local APIC address definitions
[coreboot.git] / src / mainboard / msi / ms9185 / mptable.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2001 Eric W.Biederman<ebiderman@lnxi.com>
5  *
6  * Copyright (C) 2006 AMD
7  * Written by Yinghai Lu <yinghailu@gmail.com> for AMD.
8  *
9  * Copyright (C) 2006 MSI
10  * Written by bxshi <bingxunshi@gmail.com> for MSI.
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
25  */
26
27 #include <console/console.h>
28 #include <arch/smp/mpspec.h>
29 #include <arch/io.h>
30 #include <device/pci.h>
31 #include <string.h>
32 #include <stdint.h>
33 #if CONFIG_LOGICAL_CPUS==1
34 #include <cpu/amd/multicore.h>
35 #endif
36 #include <cpu/amd/amdk8_sysconf.h>
37 #include "mb_sysconf.h"
38
39 static void *smp_write_config_table(void *v)
40 {
41         struct mp_config_table *mc;
42
43         int i, bus_isa;
44         struct mb_sysconf_t *m;
45
46         mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
47
48         mptable_init(mc, LOCAL_APIC_ADDR);
49
50         smp_write_processors(mc);
51
52         get_bus_conf();
53         m = sysconf.mb;
54
55         mptable_write_buses(mc, NULL, &bus_isa);
56
57 /*I/O APICs:   APIC ID Version State           Address*/
58         {
59                 device_t dev = 0;
60                struct resource *res;
61                for(i=0; i<3; i++) {
62                        dev = dev_find_device(0x1166, 0x0235, dev);
63                        if (dev) {
64                                res = find_resource(dev, PCI_BASE_ADDRESS_0);
65                                if (res) {
66                                        smp_write_ioapic(mc, m->apicid_bcm5785[i], 0x11, res->base);
67                                }
68                        }
69                }
70
71        }
72
73         mptable_add_isa_interrupts(mc, bus_isa, m->apicid_bcm5785[0], 0);
74
75 //IDE
76        outb(0x02, 0xc00); outb(0x0e, 0xc01);
77
78        smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  m->bus_bcm5785_0, ((1+sysconf.sbdn)<<2)|1, m->apicid_bcm5785[0], 0xe); // IDE
79
80 //SATA
81        outb(0x07, 0xc00); outb(0x0f, 0xc01);
82         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_bcm5785_1, (0x0e<<2)|0, m->apicid_bcm5785[0], 0xf);
83
84 //USB
85        outb(0x01, 0xc00); outb(0x0a, 0xc01);
86         for(i=0;i<3;i++) {
87                 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_bcm5785_0, ((2+sysconf.sbdn)<<2)|i, m->apicid_bcm5785[0], 0xa); //
88         }
89
90
91
92         /* enable int */
93         /* why here? must get the BAR and PCI command bit 1 set before enable it ....*/
94         {
95                 device_t dev;
96                 dev = dev_find_device(0x1166, 0x0205, 0);
97                 if(dev) {
98                         uint32_t dword;
99                         dword = pci_read_config32(dev, 0x6c);
100                         dword |= (1<<4); // enable interrupts
101                         pci_write_config32(dev, 0x6c, dword);
102                 }
103                 }
104
105 //First pci-x slot (on bcm5785) under bus_bcm5785_1:d.0
106        // AIC 8130 Galileo Technology...
107         for(i=0;i<4;i++) {
108                 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_bcm5785_1_1, (6<<2)|i, m->apicid_bcm5785[1], 2 + (1+i)%4); //
109         }
110
111
112 //pci slot (on bcm5785)
113         for(i=0;i<4;i++) {
114                 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_bcm5785_0, (5<<2)|i, m->apicid_bcm5785[1], 8+i%4); //
115         }
116
117
118 //onboard ati
119         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_bcm5785_0, (4<<2)|0, m->apicid_bcm5785[1], 0x1);
120
121 //PCI-X on bcm5780
122         for(i=0;i<4;i++) {
123                 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_bcm5780[1], (4<<2)|i, m->apicid_bcm5785[1], 2 + (0+i)%4); //
124         }
125
126 //onboard Broadcom
127         for(i=0;i<2;i++) {
128                 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_bcm5780[2], (4<<2)|i, m->apicid_bcm5785[1], 0xa + (0+i)%4); //
129         }
130
131
132 // First PCI-E x8
133         for(i=0;i<4;i++) {
134                 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_bcm5780[5], (0<<2)|i, m->apicid_bcm5785[1], 0xe); //
135         }
136
137
138 // Second PCI-E x8
139         for(i=0;i<4;i++) {
140                 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_bcm5780[3], (0<<2)|i, m->apicid_bcm5785[1], 0xc); //
141         }
142
143 // Third PCI-E x1
144         for(i=0;i<4;i++) {
145                 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_bcm5780[4], (0<<2)|i, m->apicid_bcm5785[1], 0xd); //
146         }
147
148 /*Local Ints:  Type    Polarity    Trigger     Bus ID   IRQ    APIC ID PIN#*/
149        mptable_lintsrc(mc, bus_isa);
150        /* There is no extension information... */
151
152        /* Compute the checksums */
153        return mptable_finalize(mc);
154 }
155
156 unsigned long write_smp_table(unsigned long addr)
157 {
158        void *v;
159        v = smp_write_floating_table(addr, 0);
160        return (unsigned long)smp_write_config_table(v);
161 }