Unify Local APIC address definitions
[coreboot.git] / src / mainboard / msi / ms9282 / mptable.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2006 AMD
5  * Written by Yinghai Lu <yinghailu@amd.com> for AMD.
6  *
7  * Copyright (C) 2006 MSI
8  * Written by Bingxun Shi <bingxunshi@gmail.com> for MSI.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
23  */
24
25 #include <console/console.h>
26 #include <arch/smp/mpspec.h>
27 #include <device/pci.h>
28 #include <string.h>
29 #include <stdint.h>
30 #include <cpu/amd/amdk8_sysconf.h>
31 #include "mb_sysconf.h"
32
33 static void *smp_write_config_table(void *v)
34 {
35         struct mp_config_table *mc;
36         struct mb_sysconf_t *m;
37         unsigned sbdn;
38
39         int i, j, bus_isa;
40
41         mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
42
43         mptable_init(mc, LOCAL_APIC_ADDR);
44
45         smp_write_processors(mc);
46
47         get_bus_conf();
48         sbdn = sysconf.sbdn;
49         m = sysconf.mb;
50
51         mptable_write_buses(mc, NULL, &bus_isa);
52
53 /*I/O APICs:   APIC ID Version State           Address*/
54         {
55                 device_t dev;
56                struct resource *res;
57                uint32_t dword;
58
59                 dev = dev_find_slot(m->bus_mcp55[0], PCI_DEVFN(sbdn+ 0x1,0));
60                 if (dev) {
61                        res = find_resource(dev, PCI_BASE_ADDRESS_1);
62                        if (res) {
63                                smp_write_ioapic(mc, m->apicid_mcp55, 0x11, res->base);
64                        }
65
66                        dword = 0x43c6c643;
67                        pci_write_config32(dev, 0x7c, dword);
68
69                        dword = 0x81001a00;
70                        pci_write_config32(dev, 0x80, dword);
71
72                        dword = 0xd00002d2;
73                        pci_write_config32(dev, 0x84, dword);
74
75                 }
76
77
78        }
79
80         mptable_add_isa_interrupts(mc, bus_isa, m->apicid_mcp55, 0);
81
82 //SMBUS
83         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_mcp55[0], ((sbdn+1)<<2)|1, m->apicid_mcp55, 0xa);
84
85 //USB1.1
86         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_mcp55[0], ((sbdn+2)<<2)|0, m->apicid_mcp55, 0x16); // 22
87
88 //USB2.0
89         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_mcp55[0], ((sbdn+2)<<2)|1, m->apicid_mcp55, 0x17); // 23
90
91 //SATA1
92         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_mcp55[0], ((sbdn+5)<<2)|0, m->apicid_mcp55, 0x14); // 20
93
94 //SATA2
95         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_mcp55[0], ((sbdn+5)<<2)|1, m->apicid_mcp55, 0x17); // 23
96
97 //SATA3
98         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_mcp55[0], ((sbdn+5)<<2)|2, m->apicid_mcp55, 0x15); // 21
99
100 //NIC1
101         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_mcp55[0], ((sbdn+8)<<2)|0, m->apicid_mcp55, 0x16); // 22
102 //NIC2
103         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_mcp55[0], ((sbdn+9)<<2)|0, m->apicid_mcp55, 0x15); // 21
104
105        for(j=7; j>=2; j--) {
106                if(!m->bus_mcp55[j]) continue;
107                for(i=0;i<4;i++) {
108                        smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_mcp55[j], (0x00<<2)|i, m->apicid_mcp55, 0x10 + (2+j+i+4-sbdn%4)%4);
109                }
110        }
111
112        for(j=0; j<1; j++)
113                for(i=0;i<4;i++) {
114                        smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_mcp55[1], ((0x04+j)<<2)|i, m->apicid_mcp55, 0x10 + (2+i+j)%4);
115                }
116
117 /*Local Ints:  Type    Polarity    Trigger     Bus ID   IRQ    APIC ID PIN#*/
118        mptable_lintsrc(mc, bus_isa);
119        /* There is no extension information... */
120
121        /* Compute the checksums */
122        return mptable_finalize(mc);
123 }
124
125 unsigned long write_smp_table(unsigned long addr)
126 {
127        void *v;
128        v = smp_write_floating_table(addr, 0);
129        return (unsigned long)smp_write_config_table(v);
130 }