2 * This file is part of the coreboot project.
4 * Copyright (C) 2012 Advanced Micro Devices, Inc.
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.
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.
16 #include <console/console.h>
17 #include <arch/smp/mpspec.h>
18 #include <device/pci.h>
20 #include <arch/ioapic.h>
23 #include <cpu/amd/amdfam15.h>
25 #include <cpu/x86/lapic.h>
26 #include "southbridge/amd/agesa/hudson/hudson.h" /* pm_ioread() */
29 0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x0A,0xF1,0x00,0x00,0x1F,0x1F,0x1F,0x1F,
30 0x09,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
31 0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
32 0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
33 0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
36 u8 intr_data
[0x54] = {
37 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x00,0x00,0x00,0x00,0x1F,0x1F,0x1F,0x1F,
38 0x09,0x1F,0x1F,0x10,0x1F,0x10,0x1F,0x10,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
39 0x05,0x1F,0x1F,0x1F,0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
40 0x12,0x11,0x12,0x11,0x12,0x11,0x12,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
41 0x11,0x13,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
45 static void smp_add_mpc_entry(struct mp_config_table
*mc
, unsigned length
)
47 mc
->mpc_length
+= length
;
48 mc
->mpc_entry_count
++;
51 static void my_smp_write_bus(struct mp_config_table
*mc
,
52 unsigned char id
, const char *bustype
)
54 struct mpc_config_bus
*mpc
;
55 mpc
= smp_next_mpc_entry(mc
);
56 memset(mpc
, '\0', sizeof(*mpc
));
57 mpc
->mpc_type
= MP_BUS
;
59 memcpy(mpc
->mpc_bustype
, bustype
, sizeof(mpc
->mpc_bustype
));
60 smp_add_mpc_entry(mc
, sizeof(*mpc
));
63 static void *smp_write_config_table(void *v
)
65 struct mp_config_table
*mc
;
70 * By the time this function gets called, the IOAPIC registers
71 * have been written so they can be read to get the correct
74 u8 ioapic_id
= (io_apic_read(VIO_APIC_VADDR
, 0x00) >> 24);
75 u8 ioapic_ver
= (io_apic_read(VIO_APIC_VADDR
, 0x01) & 0xFF);
77 mc
= (void *)(((char *)v
) + SMP_FLOATING_TABLE_LEN
);
79 mptable_init(mc
, LOCAL_APIC_ADDR
);
80 memcpy(mc
->mpc_oem
, "AMD ", 8);
82 smp_write_processors(mc
);
84 //mptable_write_buses(mc, NULL, &bus_isa);
85 my_smp_write_bus(mc
, 0, "PCI ");
86 my_smp_write_bus(mc
, 1, "PCI ");
88 my_smp_write_bus(mc
, bus_isa
, "ISA ");
90 /* I/O APICs: APIC ID Version State Address */
91 smp_write_ioapic(mc
, ioapic_id
, ioapic_ver
, VIO_APIC_VADDR
);
94 for (byte
= 0x0; byte
< sizeof(picr_data
); byte
++) {
96 outb(picr_data
[byte
], 0xC01);
99 /* APIC IRQ routine */
100 for (byte
= 0x0; byte
< sizeof(intr_data
); byte
++) {
101 outb(byte
| 0x80, 0xC00);
102 outb(intr_data
[byte
], 0xC01);
105 /* I/O Ints: Type Polarity Trigger Bus ID IRQ APIC ID PIN# */
106 #define IO_LOCAL_INT(type, intr, apicid, pin) \
107 smp_write_lintsrc(mc, (type), MP_IRQ_TRIGGER_EDGE | MP_IRQ_POLARITY_HIGH, bus_isa, (intr), (apicid), (pin));
108 mptable_add_isa_interrupts(mc
, bus_isa
, ioapic_id
, 0);
110 /* PCI interrupts are level triggered, and are
111 * associated with a specific bus/device/function tuple.
113 #define PCI_INT(bus, dev, int_sign, pin) \
114 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, (bus), (((dev)<<2)|(int_sign)), ioapic_id, (pin))
117 PCI_INT(0x0, 0x01, 0x0, intr_data
[0x02]);
118 PCI_INT(0x0, 0x01, 0x1, intr_data
[0x03]);
121 PCI_INT(0x0, 0x14, 0x0, 0x10);
124 PCI_INT(0x0, 0x14, 0x0, intr_data
[0x13]);
127 PCI_INT(0x0, 0x12, 0x0, intr_data
[0x30]);
128 PCI_INT(0x0, 0x12, 0x1, intr_data
[0x31]);
129 PCI_INT(0x0, 0x13, 0x0, intr_data
[0x32]);
130 PCI_INT(0x0, 0x13, 0x1, intr_data
[0x33]);
131 PCI_INT(0x0, 0x16, 0x0, intr_data
[0x34]);
132 PCI_INT(0x0, 0x16, 0x1, intr_data
[0x35]);
133 PCI_INT(0x0, 0x14, 0x2, intr_data
[0x36]);
136 PCI_INT(0x0, 0x11, 0x0, intr_data
[0x40]);
137 PCI_INT(0x0, 0x11, 0x0, intr_data
[0x41]);
139 /* on board NIC & Slot PCIE. */
142 device_t dev
= dev_find_slot(0, PCI_DEVFN(0x14, 4));
143 if (dev
&& dev
->enabled
) {
144 u8 bus_pci
= dev
->link_list
->secondary
;
146 PCI_INT(bus_pci
, 0x5, 0x0, 0x14);
147 PCI_INT(bus_pci
, 0x5, 0x1, 0x15);
148 PCI_INT(bus_pci
, 0x5, 0x2, 0x16);
149 PCI_INT(bus_pci
, 0x5, 0x3, 0x17);
152 PCI_INT(bus_pci
, 0x6, 0x0, 0x15);
153 PCI_INT(bus_pci
, 0x6, 0x1, 0x16);
154 PCI_INT(bus_pci
, 0x6, 0x2, 0x17);
155 PCI_INT(bus_pci
, 0x6, 0x3, 0x14);
158 PCI_INT(bus_pci
, 0x7, 0x0, 0x16);
159 PCI_INT(bus_pci
, 0x7, 0x1, 0x17);
160 PCI_INT(bus_pci
, 0x7, 0x2, 0x14);
161 PCI_INT(bus_pci
, 0x7, 0x3, 0x15);
165 PCI_INT(0x0, 0x06, 0x0, 0x13);
168 PCI_INT(0x0, 0x15, 0x0, 0x10);
170 PCI_INT(0x0, 0x15, 0x1, 0x11);
172 PCI_INT(0x0, 0x15, 0x2, 0x12);
174 PCI_INT(0x0, 0x15, 0x3, 0x13);
176 /*Local Ints: Type Polarity Trigger Bus ID IRQ APIC ID PIN# */
177 IO_LOCAL_INT(mp_ExtINT
, 0, MP_APIC_ALL
, 0x0);
178 IO_LOCAL_INT(mp_NMI
, 0, MP_APIC_ALL
, 0x1);
179 /* There is no extension information... */
181 /* Compute the checksums */
182 return mptable_finalize(mc
);
185 unsigned long write_smp_table(unsigned long addr
)
188 v
= smp_write_floating_table(addr
, 0);
189 return (unsigned long)smp_write_config_table(v
);