Stefan Reinauer | 36a2268 | 2008-10-29 04:52:57 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2007-2008 coresystems GmbH |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License as |
| 8 | * published by the Free Software Foundation; version 2 of |
| 9 | * the License. |
| 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, |
| 19 | * MA 02110-1301 USA |
| 20 | */ |
| 21 | |
| 22 | |
| 23 | #include <device/device.h> |
| 24 | #include <device/pci.h> |
| 25 | #include <console/console.h> |
| 26 | #include <arch/smp/mpspec.h> |
| 27 | #include <string.h> |
| 28 | #include <stdint.h> |
| 29 | |
| 30 | void *smp_write_config_table(void *v) |
| 31 | { |
| 32 | static const char sig[4] = "PCMP"; |
| 33 | static const char oem[8] = "COREBOOT"; |
| 34 | static const char productid[12] = "986LCD-M "; |
| 35 | struct mp_config_table *mc; |
Stefan Reinauer | 762a230 | 2010-01-19 21:15:37 +0000 | [diff] [blame] | 36 | struct device *riser = NULL, *firewire = NULL; |
Stefan Reinauer | 36a2268 | 2008-10-29 04:52:57 +0000 | [diff] [blame] | 37 | int i; |
Stefan Reinauer | 762a230 | 2010-01-19 21:15:37 +0000 | [diff] [blame] | 38 | int max_pci_bus, firewire_bus = 0, riser_bus = 0, isa_bus; |
Stefan Reinauer | 36a2268 | 2008-10-29 04:52:57 +0000 | [diff] [blame] | 39 | |
| 40 | mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN); |
| 41 | memset(mc, 0, sizeof(*mc)); |
| 42 | |
| 43 | memcpy(mc->mpc_signature, sig, sizeof(sig)); |
| 44 | mc->mpc_length = sizeof(*mc); /* initially just the header */ |
| 45 | mc->mpc_spec = 0x04; |
| 46 | mc->mpc_checksum = 0; /* not yet computed */ |
| 47 | memcpy(mc->mpc_oem, oem, sizeof(oem)); |
| 48 | memcpy(mc->mpc_productid, productid, sizeof(productid)); |
| 49 | mc->mpc_oemptr = 0; |
| 50 | mc->mpc_oemsize = 0; |
| 51 | mc->mpc_entry_count = 0; /* No entries yet... */ |
| 52 | mc->mpc_lapic = LAPIC_ADDR; |
| 53 | mc->mpe_length = 0; |
| 54 | mc->mpe_checksum = 0; |
| 55 | mc->reserved = 0; |
| 56 | |
| 57 | smp_write_processors(mc); |
Stefan Reinauer | 762a230 | 2010-01-19 21:15:37 +0000 | [diff] [blame] | 58 | max_pci_bus=0; |
Stefan Reinauer | 36a2268 | 2008-10-29 04:52:57 +0000 | [diff] [blame] | 59 | |
Stefan Reinauer | 762a230 | 2010-01-19 21:15:37 +0000 | [diff] [blame] | 60 | firewire = dev_find_device(0x104c, 0x8023, 0); |
| 61 | if (firewire) { |
| 62 | firewire_bus = firewire->bus->secondary; |
| 63 | printk_spew("Firewire device is on bus %x\n", |
| 64 | firewire_bus); |
| 65 | max_pci_bus = firewire_bus; |
| 66 | } |
| 67 | |
| 68 | // If a riser card is used, this riser is detected on bus 4, so its secondary bus is the |
| 69 | // highest bus number on the pci bus. |
| 70 | riser = dev_find_device(0x3388, 0x0021, 0); |
| 71 | if (!riser) |
| 72 | riser = dev_find_device(0x3388, 0x0022, 0); |
| 73 | if (riser) { |
| 74 | riser_bus = riser->link[0].secondary; |
| 75 | printk_spew("Riser bus is %x\n", riser_bus); |
| 76 | max_pci_bus = riser_bus; |
| 77 | } |
Stefan Reinauer | 36a2268 | 2008-10-29 04:52:57 +0000 | [diff] [blame] | 78 | |
| 79 | /* ISA bus follows */ |
| 80 | isa_bus = max_pci_bus + 1; |
| 81 | |
| 82 | /* Bus: Bus ID Type */ |
| 83 | for (i=0; i <= max_pci_bus; i++) |
| 84 | smp_write_bus(mc, i, "PCI "); |
| 85 | |
| 86 | smp_write_bus(mc, isa_bus, "ISA "); |
| 87 | |
| 88 | /* I/O APICs: APIC ID Version State Address */ |
| 89 | smp_write_ioapic(mc, 2, 0x20, 0xfec00000); |
| 90 | |
| 91 | /* Legacy Interrupts */ |
| 92 | |
| 93 | /* I/O Ints: Type Polarity Trigger Bus ID IRQ APIC ID PIN# */ |
| 94 | smp_write_intsrc(mc, mp_ExtINT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, isa_bus, 0x0, 0x2, 0x0); |
| 95 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, isa_bus, 0x1, 0x2, 0x1); |
| 96 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, isa_bus, 0x0, 0x2, 0x2); |
| 97 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, isa_bus, 0x3, 0x2, 0x3); |
| 98 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, isa_bus, 0x4, 0x2, 0x4); |
| 99 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, isa_bus, 0x8, 0x2, 0x8); |
| 100 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, isa_bus, 0x9, 0x2, 0x9); |
| 101 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, isa_bus, 0xa, 0x2, 0xa); |
| 102 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, isa_bus, 0xb, 0x2, 0xb); |
| 103 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, isa_bus, 0xc, 0x2, 0xc); |
| 104 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, isa_bus, 0xd, 0x2, 0xd); |
| 105 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, isa_bus, 0xe, 0x2, 0xe); |
| 106 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, isa_bus, 0xf, 0x2, 0xf); |
| 107 | |
| 108 | /* Builtin devices on Bus 0 */ |
| 109 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, 0x0, 0x8, 0x2, 0x10); |
| 110 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, 0x0, 0x7d, 0x2, 0x13); |
| 111 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, 0x0, 0x74, 0x2, 0x17); |
| 112 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, 0x0, 0x75, 0x2, 0x13); |
| 113 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, 0x0, 0x76, 0x2, 0x12); |
| 114 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, 0x0, 0x77, 0x2, 0x10); |
| 115 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, 0x0, 0x6c, 0x2, 0x10); |
| 116 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, 0x0, 0x70, 0x2, 0x10); |
| 117 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, 0x0, 0x71, 0x2, 0x11); |
| 118 | |
| 119 | /* Firewire 4:0.0 */ |
Stefan Reinauer | 762a230 | 2010-01-19 21:15:37 +0000 | [diff] [blame] | 120 | if (firewire) { |
| 121 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, firewire_bus, 0x0, 0x2, 0x10); |
| 122 | } |
Stefan Reinauer | 36a2268 | 2008-10-29 04:52:57 +0000 | [diff] [blame] | 123 | |
Stefan Reinauer | 762a230 | 2010-01-19 21:15:37 +0000 | [diff] [blame] | 124 | if (riser) { |
| 125 | /* Old riser card */ |
| 126 | // riser slot top 5:8.0 |
| 127 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, riser_bus, 0x20, 0x2, 0x14); |
| 128 | // riser slot middle 5:9.0 |
| 129 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, riser_bus, 0x24, 0x2, 0x15); |
| 130 | // riser slot bottom 5:a.0 |
| 131 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, riser_bus, 0x28, 0x2, 0x16); |
Stefan Reinauer | 36a2268 | 2008-10-29 04:52:57 +0000 | [diff] [blame] | 132 | |
Stefan Reinauer | 762a230 | 2010-01-19 21:15:37 +0000 | [diff] [blame] | 133 | /* New Riser Card */ |
| 134 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, riser_bus, 0x30, 0x2, 0x14); |
| 135 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, riser_bus, 0x34, 0x2, 0x15); |
| 136 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, riser_bus, 0x38, 0x2, 0x16); |
| 137 | } |
Stefan Reinauer | e1025d0 | 2009-03-11 15:20:36 +0000 | [diff] [blame] | 138 | |
Stefan Reinauer | 36a2268 | 2008-10-29 04:52:57 +0000 | [diff] [blame] | 139 | /* Onboard Ethernet */ |
| 140 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, 0x1, 0x0, 0x2, 0x10); |
| 141 | |
| 142 | /* Local Ints: Type Polarity Trigger Bus ID IRQ APIC ID PIN# */ |
| 143 | smp_write_intsrc(mc, mp_ExtINT, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, isa_bus, 0x0, MP_APIC_ALL, 0x0); |
| 144 | smp_write_intsrc(mc, mp_NMI, MP_IRQ_TRIGGER_DEFAULT|MP_IRQ_POLARITY_DEFAULT, isa_bus, 0x0, MP_APIC_ALL, 0x1); |
| 145 | |
| 146 | /* Compute the checksums */ |
| 147 | mc->mpe_checksum = smp_compute_checksum(smp_next_mpc_entry(mc), mc->mpe_length); |
| 148 | mc->mpc_checksum = smp_compute_checksum(mc, mc->mpc_length); |
| 149 | |
| 150 | printk_debug("Wrote the mp table end at: %p - %p\n", mc, smp_next_mpe_entry(mc)); |
| 151 | |
| 152 | return smp_next_mpe_entry(mc); |
| 153 | } |
| 154 | |
| 155 | unsigned long write_smp_table(unsigned long addr) |
| 156 | { |
| 157 | void *v; |
| 158 | v = smp_write_floating_table(addr); |
| 159 | return (unsigned long)smp_write_config_table(v); |
| 160 | } |