f021ec20786c5e9f5b6408692413eef88c0e92d0
[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
31 #include <cpu/amd/amdk8_sysconf.h>
32
33 #include "mb_sysconf.h"
34
35 extern void get_bus_conf(void);
36
37 void *smp_write_config_table(void *v)
38 {
39         static const char sig[4] = "PCMP";
40         static const char oem[8] = "MSI    ";
41         static const char productid[12] = "MS9282       ";
42         struct mp_config_table *mc;
43        struct mb_sysconf_t *m;
44        unsigned sbdn;
45
46        int i,j;
47
48         mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
49         memset(mc, 0, sizeof(*mc));
50
51         memcpy(mc->mpc_signature, sig, sizeof(sig));
52         mc->mpc_length = sizeof(*mc); /* initially just the header */
53         mc->mpc_spec = 0x04;
54         mc->mpc_checksum = 0; /* not yet computed */
55         memcpy(mc->mpc_oem, oem, sizeof(oem));
56         memcpy(mc->mpc_productid, productid, sizeof(productid));
57         mc->mpc_oemptr = 0;
58         mc->mpc_oemsize = 0;
59         mc->mpc_entry_count = 0; /* No entries yet... */
60         mc->mpc_lapic = LAPIC_ADDR;
61         mc->mpe_length = 0;
62         mc->mpe_checksum = 0;
63         mc->reserved = 0;
64
65         smp_write_processors(mc);
66
67        get_bus_conf();
68        sbdn = sysconf.sbdn;
69        m = sysconf.mb;
70
71 /*Bus:         Bus ID  Type*/
72        /* define bus and isa numbers */
73         for(j= 0; j < 256 ; j++) {
74                if(m->bus_type[j])
75                         smp_write_bus(mc, j, "PCI   ");
76         }
77         smp_write_bus(mc, m->bus_isa, "ISA   ");
78
79 /*I/O APICs:   APIC ID Version State           Address*/
80         {
81                 device_t dev;
82                struct resource *res;
83                uint32_t dword;
84
85                 dev = dev_find_slot(m->bus_mcp55[0], PCI_DEVFN(sbdn+ 0x1,0));
86                 if (dev) {
87                        res = find_resource(dev, PCI_BASE_ADDRESS_1);
88                        if (res) {
89                                smp_write_ioapic(mc, m->apicid_mcp55, 0x11, res->base);
90                        }
91
92                        dword = 0x43c6c643;
93                        pci_write_config32(dev, 0x7c, dword);
94
95                        dword = 0x81001a00;
96                        pci_write_config32(dev, 0x80, dword);
97
98                        dword = 0xd00002d2;
99                        pci_write_config32(dev, 0x84, dword);
100
101                 }
102
103
104        }
105
106                   /*I/O Ints:  Type    Polarity    Trigger                     Bus ID   IRQ    APIC ID PIN# */
107        smp_write_intsrc(mc, mp_ExtINT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, m->bus_isa, 0x0, m->apicid_mcp55, 0x0);
108        smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  m->bus_isa, 0x1, m->apicid_mcp55, 0x1);
109        smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  m->bus_isa, 0x0, m->apicid_mcp55, 0x2);
110        smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  m->bus_isa, 0x3, m->apicid_mcp55, 0x3);
111        smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  m->bus_isa, 0x4, m->apicid_mcp55, 0x4);
112        smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  m->bus_isa, 0x6, m->apicid_mcp55, 0x6);
113        smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  m->bus_isa, 0x7, m->apicid_mcp55, 0x7);
114        smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  m->bus_isa, 0x8, m->apicid_mcp55, 0x8);
115        smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  m->bus_isa, 0xc, m->apicid_mcp55, 0xc);
116        smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  m->bus_isa, 0xd, m->apicid_mcp55, 0xd);
117        smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  m->bus_isa, 0xe, m->apicid_mcp55, 0xe);
118        smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  m->bus_isa, 0xf, m->apicid_mcp55, 0xf);
119
120 //SMBUS
121         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);
122
123 //USB1.1
124         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
125
126 //USB2.0
127         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
128
129 //SATA1
130         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
131
132 //SATA2
133         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
134
135 //SATA3
136         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
137
138 //NIC1
139         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
140 //NIC2
141         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
142
143        for(j=7; j>=2; j--) {
144                if(!m->bus_mcp55[j]) continue;
145                for(i=0;i<4;i++) {
146                        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);
147                }
148        }
149
150        for(j=0; j<1; j++)
151                for(i=0;i<4;i++) {
152                        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);
153                }
154
155 /*Local Ints:  Type    Polarity    Trigger     Bus ID   IRQ    APIC ID PIN#*/
156        smp_write_intsrc(mc, mp_ExtINT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, m->bus_isa, 0x0, MP_APIC_ALL, 0x0);
157        smp_write_intsrc(mc, mp_NMI, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, m->bus_isa, 0x0, MP_APIC_ALL, 0x1);
158        /* There is no extension information... */
159
160        /* Compute the checksums */
161        mc->mpe_checksum = smp_compute_checksum(smp_next_mpc_entry(mc), mc->mpe_length);
162        mc->mpc_checksum = smp_compute_checksum(mc, mc->mpc_length);
163        printk_debug("Wrote the mp table end at: %p - %p\n",
164                mc, smp_next_mpe_entry(mc));
165        return smp_next_mpe_entry(mc);
166 }
167
168 unsigned long write_smp_table(unsigned long addr)
169 {
170        void *v;
171        v = smp_write_floating_table(addr);
172        return (unsigned long)smp_write_config_table(v);
173 }