4045745bcc78d6bddd085112c25d38c6304d8fb0
[coreboot.git] / src / mainboard / msi / ms9185 / mptable.c
1 /*
2  * This file is part of the LinuxBIOS 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/dualcore.h>
35 #endif
36
37 #include <cpu/amd/amdk8_sysconf.h>
38
39 #include "mb_sysconf.h"
40
41 extern void get_bus_conf(void);
42
43 void *smp_write_config_table(void *v)
44 {
45         static const char sig[4] = "PCMP";
46         static const char oem[3] = "MSI";
47         static const char productid[6] = "MS9185       ";
48         struct mp_config_table *mc;
49
50         unsigned char bus_num;
51        int i;
52        struct mb_sysconf_t *m;
53
54         mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
55         memset(mc, 0, sizeof(*mc));
56
57         memcpy(mc->mpc_signature, sig, sizeof(sig));
58         mc->mpc_length = sizeof(*mc); /* initially just the header */
59         mc->mpc_spec = 0x04;
60         mc->mpc_checksum = 0; /* not yet computed */
61         memcpy(mc->mpc_oem, oem, sizeof(oem));
62         memcpy(mc->mpc_productid, productid, sizeof(productid));
63         mc->mpc_oemptr = 0;
64         mc->mpc_oemsize = 0;
65         mc->mpc_entry_count = 0; /* No entries yet... */
66         mc->mpc_lapic = LAPIC_ADDR;
67         mc->mpe_length = 0;
68         mc->mpe_checksum = 0;
69         mc->reserved = 0;
70
71         smp_write_processors(mc);
72
73        get_bus_conf();
74        m = sysconf.mb;
75
76 /*Bus:         Bus ID  Type*/
77        /* define bus and isa numbers */
78         for(bus_num = 0; bus_num < m->bus_isa; bus_num++) {
79                 smp_write_bus(mc, bus_num, "PCI   ");
80         }
81         smp_write_bus(mc, m->bus_isa, "ISA   ");
82
83 /*I/O APICs:   APIC ID Version State           Address*/
84         {
85                 device_t dev = 0;
86                int i;
87                struct resource *res;
88                for(i=0; i<3; i++) {
89                        dev = dev_find_device(0x1166, 0x0235, dev);
90                        if (dev) {
91                                res = find_resource(dev, PCI_BASE_ADDRESS_0);
92                                if (res) {
93                                        smp_write_ioapic(mc, m->apicid_bcm5785[i], 0x11, res->base);
94                                }
95                        }
96                }
97
98        }
99
100 /*I/O Ints:    Type    Polarity    Trigger     Bus ID   IRQ    APIC ID PIN# */
101        smp_write_intsrc(mc, mp_ExtINT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, m->bus_isa, 0x0, m->apicid_bcm5785[0], 0x0);
102        smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  m->bus_isa, 0x1, m->apicid_bcm5785[0], 0x1);
103        smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  m->bus_isa, 0x0, m->apicid_bcm5785[0], 0x2);
104        smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  m->bus_isa, 0x3, m->apicid_bcm5785[0], 0x3);
105        smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  m->bus_isa, 0x4, m->apicid_bcm5785[0], 0x4);
106        smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  m->bus_isa, 0x5, m->apicid_bcm5785[0], 0x5);
107        smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  m->bus_isa, 0x6, m->apicid_bcm5785[0], 0x6);
108        smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  m->bus_isa, 0x7, m->apicid_bcm5785[0], 0x7);
109        smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  m->bus_isa, 0x8, m->apicid_bcm5785[0], 0x8);
110        smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  m->bus_isa, 0x9, m->apicid_bcm5785[0], 0x9);
111        smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  m->bus_isa, 0xc, m->apicid_bcm5785[0], 0xc);
112        smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  m->bus_isa, 0xd, m->apicid_bcm5785[0], 0xd);
113
114 //IDE
115        outb(0x02, 0xc00); outb(0x0e, 0xc01);
116
117        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
118
119 //SATA
120        outb(0x07, 0xc00); outb(0x0f, 0xc01);
121         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);
122
123 //USB
124        outb(0x01, 0xc00); outb(0x0a, 0xc01);
125         for(i=0;i<3;i++) {
126                 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); //
127         }
128
129
130
131         /* enable int */
132         /* why here? must get the BAR and PCI command bit 1 set before enable it ....*/
133         {
134                 device_t dev;
135                 dev = dev_find_device(0x1166, 0x0205, 0);
136                 if(dev) {
137                         uint32_t dword;
138                         dword = pci_read_config32(dev, 0x6c);
139                         dword |= (1<<4); // enable interrupts
140                         pci_write_config32(dev, 0x6c, dword);
141                 }
142                 }
143
144 //First pci-x slot (on bcm5785) under bus_bcm5785_1:d.0
145        // AIC 8130 Galileo Technology...
146         for(i=0;i<4;i++) {
147                 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); //
148         }
149
150
151 //pci slot (on bcm5785)
152         for(i=0;i<4;i++) {
153                 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); //
154         }
155
156
157 //onboard ati
158         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);
159
160 //PCI-X on bcm5780
161         for(i=0;i<4;i++) {
162                 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); //
163         }
164
165 //onboard Broadcom
166         for(i=0;i<2;i++) {
167                 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); //
168         }
169
170
171 // First PCI-E x8
172         for(i=0;i<4;i++) {
173                 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); //
174         }
175
176
177 // Second PCI-E x8
178         for(i=0;i<4;i++) {
179                 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); //
180         }
181
182 // Third PCI-E x1
183         for(i=0;i<4;i++) {
184                 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); //
185         }
186
187 /*Local Ints:  Type    Polarity    Trigger     Bus ID   IRQ    APIC ID PIN#*/
188        smp_write_intsrc(mc, mp_ExtINT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, m->bus_isa, 0x0, MP_APIC_ALL, 0x0);
189        smp_write_intsrc(mc, mp_NMI, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, m->bus_isa, 0x0, MP_APIC_ALL, 0x1);
190        /* There is no extension information... */
191
192        /* Compute the checksums */
193        mc->mpe_checksum = smp_compute_checksum(smp_next_mpc_entry(mc), mc->mpe_length);
194        mc->mpc_checksum = smp_compute_checksum(mc, mc->mpc_length);
195        printk_debug("Wrote the mp table end at: %p - %p\n",
196                mc, smp_next_mpe_entry(mc));
197        return smp_next_mpe_entry(mc);
198 }
199
200 unsigned long write_smp_table(unsigned long addr)
201 {
202        void *v;
203        v = smp_write_floating_table(addr);
204        return (unsigned long)smp_write_config_table(v);
205 }