Factor out common mptable code to mptable_init().
[coreboot.git] / src / mainboard / asrock / 939a785gmh / mptable.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2010 Advanced Micro Devices, Inc.
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; version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
18  */
19
20 #include <console/console.h>
21 #include <arch/smp/mpspec.h>
22 #include <device/pci.h>
23 #include <arch/io.h>
24 #include <string.h>
25 #include <stdint.h>
26 #include <cpu/amd/amdk8_sysconf.h>
27
28 extern u8 bus_isa;
29 extern u8 bus_rs780[11];
30 extern u8 bus_sb700[2];
31
32 extern u32 apicid_sb700;
33
34 extern u32 bus_type[256];
35 extern u32 sbdn_rs780;
36 extern u32 sbdn_sb700;
37
38 static void *smp_write_config_table(void *v)
39 {
40         struct mp_config_table *mc;
41         int j;
42
43         mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
44
45         mptable_init(mc, "939A785GMH  ", LAPIC_ADDR);
46
47         smp_write_processors(mc);
48
49         get_bus_conf();
50
51         /* Bus:         Bus ID  Type */
52         /* define bus and isa numbers */
53         for (j = 0; j < bus_isa; j++) {
54                 smp_write_bus(mc, j, (char *)"PCI   ");
55         }
56         smp_write_bus(mc, bus_isa, (char *)"ISA   ");
57
58         /* I/O APICs:   APIC ID Version State   Address */
59         {
60                 device_t dev;
61                 u32 dword;
62                 u8 byte;
63
64                 dev =
65                     dev_find_slot(bus_sb700[0],
66                                   PCI_DEVFN(sbdn_sb700 + 0x14, 0));
67                 if (dev) {
68                         dword = pci_read_config32(dev, 0x74) & 0xfffffff0;
69                         smp_write_ioapic(mc, apicid_sb700, 0x11, dword);
70
71                         /* Initialize interrupt mapping */
72                         /* aza */
73                         byte = pci_read_config8(dev, 0x63);
74                         byte &= 0xf8;
75                         byte |= 0;      /* 0: INTA, ...., 7: INTH */
76                         pci_write_config8(dev, 0x63, byte);
77
78                         /* SATA */
79                         dword = pci_read_config32(dev, 0xac);
80                         dword &= ~(7 << 26);
81                         dword |= 6 << 26;       /* 0: INTA, ...., 7: INTH */
82                         /* dword |= 1<<22; PIC and APIC co exists */
83                         pci_write_config32(dev, 0xac, dword);
84
85                         /*
86                          * 00:12.0: PROG SATA : INT F
87                          * 00:13.0: INTA USB_0
88                          * 00:13.1: INTB USB_1
89                          * 00:13.2: INTC USB_2
90                          * 00:13.3: INTD USB_3
91                          * 00:13.4: INTC USB_4
92                          * 00:13.5: INTD USB2
93                          * 00:14.1: INTA IDE
94                          * 00:14.2: Prog HDA : INT E
95                          * 00:14.5: INTB ACI
96                          * 00:14.6: INTB MCI
97                          */
98                 }
99         }
100
101 #define IO_LOCAL_INT(type, intr, apicid, pin) \
102         smp_write_intsrc(mc, (type), MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH, bus_isa, (intr), (apicid), (pin));
103
104         mptable_add_isa_interrupts(mc, bus_isa, apicid_sb700, 0);
105
106         /* PCI interrupts are level triggered, and are
107          * associated with a specific bus/device/function tuple.
108          */
109 #if CONFIG_GENERATE_ACPI_TABLES == 0
110 #define PCI_INT(bus, dev, fn, pin) \
111         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, (bus), (((dev)<<2)|(fn)), apicid_sb700, (pin))
112 #else
113 #define PCI_INT(bus, dev, fn, pin)
114 #endif
115
116         /* usb */
117         PCI_INT(0x0, 0x12, 0x0, 0x10); /* USB */
118         PCI_INT(0x0, 0x12, 0x1, 0x11);
119         PCI_INT(0x0, 0x13, 0x0, 0x12);
120         PCI_INT(0x0, 0x13, 0x1, 0x13);
121         PCI_INT(0x0, 0x14, 0x0, 0x10);
122
123         /* sata */
124         PCI_INT(0x0, 0x11, 0x0, 0x16);
125
126         /* HD Audio: b0:d20:f1:reg63 should be 0. */
127         /* PCI_INT(0x0, 0x14, 0x2, 0x12); */
128
129         /* on board NIC & Slot PCIE.  */
130         /* PCI_INT(bus_rs780[0x1], 0x5, 0x0, 0x12); */
131 /*      PCI_INT(bus_rs780[0x1], 0x5, 0x1, 0x13); */
132         PCI_INT(bus_rs780[0x2], 0x0, 0x0, 0x12); /* Dev 2, external GFX */
133         /* PCI_INT(bus_rs780[0x3], 0x0, 0x0, 0x13); */
134         PCI_INT(bus_rs780[0x4], 0x0, 0x0, 0x10);
135         /* configuration B doesnt need dev 5,6,7 */
136         /*
137          * PCI_INT(bus_rs780[0x5], 0x0, 0x0, 0x11);
138          * PCI_INT(bus_rs780[0x6], 0x0, 0x0, 0x12);
139          * PCI_INT(bus_rs780[0x7], 0x0, 0x0, 0x13);
140          */
141         PCI_INT(bus_rs780[0x9], 0x0, 0x0, 0x11);
142         PCI_INT(bus_rs780[0xA], 0x0, 0x0, 0x12); /* NIC */
143
144         /* PCI slots */
145         /* PCI_SLOT 0. */
146         PCI_INT(bus_sb700[1], 0x5, 0x0, 0x14);
147         PCI_INT(bus_sb700[1], 0x5, 0x1, 0x15);
148         PCI_INT(bus_sb700[1], 0x5, 0x2, 0x16);
149         PCI_INT(bus_sb700[1], 0x5, 0x3, 0x17);
150
151         /* PCI_SLOT 1. */
152         PCI_INT(bus_sb700[1], 0x6, 0x0, 0x15);
153         PCI_INT(bus_sb700[1], 0x6, 0x1, 0x16);
154         PCI_INT(bus_sb700[1], 0x6, 0x2, 0x17);
155         PCI_INT(bus_sb700[1], 0x6, 0x3, 0x14);
156
157         /* PCI_SLOT 2. */
158         PCI_INT(bus_sb700[1], 0x7, 0x0, 0x16);
159         PCI_INT(bus_sb700[1], 0x7, 0x1, 0x17);
160         PCI_INT(bus_sb700[1], 0x7, 0x2, 0x14);
161         PCI_INT(bus_sb700[1], 0x7, 0x3, 0x15);
162
163         /*Local Ints:   Type    Polarity    Trigger     Bus ID   IRQ    APIC ID PIN# */
164         IO_LOCAL_INT(mp_ExtINT, 0x0, MP_APIC_ALL, 0x0);
165         IO_LOCAL_INT(mp_NMI, 0x0, MP_APIC_ALL, 0x1);
166         /* There is no extension information... */
167
168         /* Compute the checksums */
169         mc->mpe_checksum =
170             smp_compute_checksum(smp_next_mpc_entry(mc), mc->mpe_length);
171         mc->mpc_checksum = smp_compute_checksum(mc, mc->mpc_length);
172         printk(BIOS_DEBUG, "Wrote the mp table end at: %p - %p\n",
173                      mc, smp_next_mpe_entry(mc));
174         return smp_next_mpe_entry(mc);
175 }
176
177 unsigned long write_smp_table(unsigned long addr)
178 {
179         void *v;
180         v = smp_write_floating_table(addr);
181         return (unsigned long)smp_write_config_table(v);
182 }