4650c5912612533e2199b1d8935ea8000b8f6346
[coreboot.git] / src / mainboard / asus / p2b-ds / mptable.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2008 Uwe Hermann <uwe@hermann-uwe.de>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
19  */
20
21 #include <console/console.h>
22 #include <arch/smp/mpspec.h>
23 #include <arch/ioapic.h>
24 #include <device/pci.h>
25 #include <string.h>
26 #include <stdint.h>
27
28 static void *smp_write_config_table(void *v)
29 {
30         static const char sig[4] = "PCMP";
31         static const char oem[8] = "COREBOOT";
32         static const char productid[12] = "ASUS P2B-DS ";
33         struct mp_config_table *mc;
34
35         mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
36         memset(mc, 0, sizeof(*mc));
37
38         memcpy(mc->mpc_signature, sig, sizeof(sig));
39         mc->mpc_length = sizeof(*mc);   /* initially just the header */
40         mc->mpc_spec = 0x04;
41         mc->mpc_checksum = 0;           /* not yet computed */
42         memcpy(mc->mpc_oem, oem, sizeof(oem));
43         memcpy(mc->mpc_productid, productid, sizeof(productid));
44         mc->mpc_oemptr = 0;
45         mc->mpc_oemsize = 0;
46         mc->mpc_entry_count = 0;        /* No entries yet... */
47         mc->mpc_lapic = LAPIC_ADDR;
48         mc->mpe_length = 0;
49         mc->mpe_checksum = 0;
50         mc->reserved = 0;
51
52         smp_write_processors(mc);
53
54         /* Bus:         Bus ID  Type */
55         smp_write_bus(mc, 0, "PCI   ");
56         smp_write_bus(mc, 1, "ISA   ");
57
58         /* I/O APICs:   APIC ID Version State           Address */
59         smp_write_ioapic(mc, 2, 0x20, IO_APIC_ADDR);
60         {
61                 device_t dev;
62                 struct resource *res;
63
64                 dev = dev_find_slot(1, PCI_DEVFN(0x1e, 0));
65                 if (dev) {
66                         res = find_resource(dev, PCI_BASE_ADDRESS_0);
67                         if (res)
68                                 smp_write_ioapic(mc, 3, 0x20, res->base);
69                 }
70                 dev = dev_find_slot(1, PCI_DEVFN(0x1c, 0));
71                 if (dev) {
72                         res = find_resource(dev, PCI_BASE_ADDRESS_0);
73                         if (res)
74                                 smp_write_ioapic(mc, 4, 0x20, res->base);
75                 }
76                 dev = dev_find_slot(4, PCI_DEVFN(0x1e, 0));
77                 if (dev) {
78                         res = find_resource(dev, PCI_BASE_ADDRESS_0);
79                         if (res)
80                                 smp_write_ioapic(mc, 5, 0x20, res->base);
81                 }
82                 dev = dev_find_slot(4, PCI_DEVFN(0x1c, 0));
83                 if (dev) {
84                         res = find_resource(dev, PCI_BASE_ADDRESS_0);
85                         if (res)
86                                 smp_write_ioapic(mc, 8, 0x20, res->base);
87                 }
88         }
89
90         mptable_add_isa_interrupts(mc, 0x1, 0x2, 0);
91
92         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW,
93                          0x0, 0x13, 0x2, 0x13);
94         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW,
95                          0x0, 0x18, 0x2, 0x13);
96         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW,
97                          0x0, 0x30, 0x2, 0x10);
98
99         /* Local Ints: Type  Polarity  Trigger  Bus ID  IRQ  APIC ID  PIN# */
100         smp_write_intsrc(mc, mp_ExtINT,
101                          MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH, 0x1, 0x0,
102                          MP_APIC_ALL, 0x0);
103         smp_write_intsrc(mc, mp_NMI, MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH,
104                          0x1, 0x0, MP_APIC_ALL, 0x1);
105
106         /* There is no extension information... */
107
108         /* Compute the checksums */
109         mc->mpe_checksum =
110             smp_compute_checksum(smp_next_mpc_entry(mc), mc->mpe_length);
111         mc->mpc_checksum = smp_compute_checksum(mc, mc->mpc_length);
112         printk(BIOS_DEBUG, "Wrote the mp table end at: %p - %p\n",
113                      mc, smp_next_mpe_entry(mc));
114         return smp_next_mpe_entry(mc);
115 }
116
117 unsigned long write_smp_table(unsigned long addr)
118 {
119         void *v;
120         v = smp_write_floating_table(addr);
121         return (unsigned long)smp_write_config_table(v);
122 }