Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 1 | /* |
Stefan Reinauer | 7e61e45 | 2008-01-18 10:35:56 +0000 | [diff] [blame] | 2 | * This file is part of the coreboot project. |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2007 AMD |
| 5 | * Written by Yinghai Lu <yinghailu@amd.com> for AMD. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 16 | */ |
| 17 | |
| 18 | #include <console/console.h> |
| 19 | #include <arch/smp/mpspec.h> |
| 20 | #include <device/pci.h> |
| 21 | #include <string.h> |
| 22 | #include <stdint.h> |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 23 | #include <cpu/amd/amdk8_sysconf.h> |
Uwe Hermann | 55dc223 | 2010-10-25 15:32:07 +0000 | [diff] [blame] | 24 | |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 25 | extern unsigned char bus_mcp55[8]; //1 |
| 26 | |
| 27 | extern unsigned apicid_mcp55; |
| 28 | |
| 29 | extern unsigned char bus_pcix[3]; // under bus_mcp55_2 |
| 30 | |
Myles Watson | 08e0fb8 | 2010-03-22 16:33:25 +0000 | [diff] [blame] | 31 | static void *smp_write_config_table(void *v) |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 32 | { |
Elyes HAOUAS | 8da96e5 | 2016-09-22 21:20:54 +0200 | [diff] [blame^] | 33 | struct mp_config_table *mc; |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 34 | unsigned sbdn; |
Patrick Georgi | 7411eab | 2010-11-22 14:14:56 +0000 | [diff] [blame] | 35 | int i, j, bus_isa; |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 36 | |
Elyes HAOUAS | 8da96e5 | 2016-09-22 21:20:54 +0200 | [diff] [blame^] | 37 | mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN); |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 38 | |
Patrick Georgi | c8feedd | 2012-02-16 18:43:25 +0100 | [diff] [blame] | 39 | mptable_init(mc, LOCAL_APIC_ADDR); |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 40 | |
Elyes HAOUAS | 8da96e5 | 2016-09-22 21:20:54 +0200 | [diff] [blame^] | 41 | smp_write_processors(mc); |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 42 | |
| 43 | get_bus_conf(); |
| 44 | sbdn = sysconf.sbdn; |
| 45 | |
Patrick Georgi | 7411eab | 2010-11-22 14:14:56 +0000 | [diff] [blame] | 46 | mptable_write_buses(mc, NULL, &bus_isa); |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 47 | |
| 48 | /*I/O APICs: APIC ID Version State Address*/ |
Elyes HAOUAS | 8da96e5 | 2016-09-22 21:20:54 +0200 | [diff] [blame^] | 49 | { |
| 50 | device_t dev; |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 51 | struct resource *res; |
| 52 | uint32_t dword; |
| 53 | |
Elyes HAOUAS | 8da96e5 | 2016-09-22 21:20:54 +0200 | [diff] [blame^] | 54 | dev = dev_find_slot(bus_mcp55[0], PCI_DEVFN(sbdn+ 0x1,0)); |
| 55 | if (dev) { |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 56 | res = find_resource(dev, PCI_BASE_ADDRESS_1); |
| 57 | if (res) { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 58 | smp_write_ioapic(mc, apicid_mcp55, 0x11, |
| 59 | res2mmio(res, 0, 0)); |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | dword = 0x43c6c643; |
Elyes HAOUAS | 8da96e5 | 2016-09-22 21:20:54 +0200 | [diff] [blame^] | 63 | pci_write_config32(dev, 0x7c, dword); |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 64 | |
Elyes HAOUAS | 8da96e5 | 2016-09-22 21:20:54 +0200 | [diff] [blame^] | 65 | dword = 0x81001a00; |
| 66 | pci_write_config32(dev, 0x80, dword); |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 67 | |
Elyes HAOUAS | 8da96e5 | 2016-09-22 21:20:54 +0200 | [diff] [blame^] | 68 | dword = 0xd00012d2; |
| 69 | pci_write_config32(dev, 0x84, dword); |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 70 | |
Elyes HAOUAS | 8da96e5 | 2016-09-22 21:20:54 +0200 | [diff] [blame^] | 71 | } |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 72 | |
| 73 | |
| 74 | |
| 75 | } |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 76 | |
Patrick Georgi | c5b87c8 | 2010-05-20 15:28:19 +0000 | [diff] [blame] | 77 | mptable_add_isa_interrupts(mc, bus_isa, apicid_mcp55, 0); |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 78 | |
Patrick Georgi | c5b87c8 | 2010-05-20 15:28:19 +0000 | [diff] [blame] | 79 | /*I/O Ints: Type Polarity Trigger Bus ID IRQ APIC ID PIN# */ |
Elyes HAOUAS | 8da96e5 | 2016-09-22 21:20:54 +0200 | [diff] [blame^] | 80 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_mcp55[0], ((sbdn+1)<<2)|1, apicid_mcp55, 0xa); |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 81 | |
Elyes HAOUAS | 8da96e5 | 2016-09-22 21:20:54 +0200 | [diff] [blame^] | 82 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_mcp55[0], ((sbdn+2)<<2)|0, apicid_mcp55, 0x16); // 22 |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 83 | |
Elyes HAOUAS | 8da96e5 | 2016-09-22 21:20:54 +0200 | [diff] [blame^] | 84 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_mcp55[0], ((sbdn+2)<<2)|1, apicid_mcp55, 0x17); // 23 |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 85 | |
Elyes HAOUAS | 8da96e5 | 2016-09-22 21:20:54 +0200 | [diff] [blame^] | 86 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_mcp55[0], ((sbdn+6)<<2)|1, apicid_mcp55, 0x17); // 23 |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 87 | |
Elyes HAOUAS | 8da96e5 | 2016-09-22 21:20:54 +0200 | [diff] [blame^] | 88 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_mcp55[0], ((sbdn+5)<<2)|0, apicid_mcp55, 0x14); // 20 |
| 89 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_mcp55[0], ((sbdn+5)<<2)|1, apicid_mcp55, 0x17); // 23 |
| 90 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_mcp55[0], ((sbdn+5)<<2)|2, apicid_mcp55, 0x15); // 21 |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 91 | |
Elyes HAOUAS | 8da96e5 | 2016-09-22 21:20:54 +0200 | [diff] [blame^] | 92 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_mcp55[0], ((sbdn+8)<<2)|0, apicid_mcp55, 0x16); // 22 |
| 93 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_mcp55[0], ((sbdn+9)<<2)|0, apicid_mcp55, 0x15); // 21 |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 94 | |
Elyes HAOUAS | a5aad2e | 2016-09-19 09:47:16 -0600 | [diff] [blame] | 95 | for(j = 7; j >= 2; j--) { |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 96 | if(!bus_mcp55[j]) continue; |
Elyes HAOUAS | 8da96e5 | 2016-09-22 21:20:54 +0200 | [diff] [blame^] | 97 | for(i = 0; i < 4; i++) { |
| 98 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_mcp55[j], (0x00 << 2)|i, apicid_mcp55, 0x10 + (2+j+i+4-sbdn%4)%4); |
| 99 | } |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 100 | } |
| 101 | |
Elyes HAOUAS | 8da96e5 | 2016-09-22 21:20:54 +0200 | [diff] [blame^] | 102 | for(i = 0; i < 4; i++) { |
| 103 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_mcp55[1], (0x04 << 2)|i, apicid_mcp55, 0x10 + (0+i)%4); |
| 104 | } |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 105 | |
| 106 | |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 107 | if(bus_pcix[0]) { |
Elyes HAOUAS | a5aad2e | 2016-09-19 09:47:16 -0600 | [diff] [blame] | 108 | for(i = 0; i < 2; i++) { |
| 109 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_pcix[2], (4 << 2)|i, apicid_mcp55, 0x10 + (0+i+4-sbdn%4)%4); //16, 17 |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 110 | } |
| 111 | |
Elyes HAOUAS | a5aad2e | 2016-09-19 09:47:16 -0600 | [diff] [blame] | 112 | for(i = 0; i < 4; i++) { |
| 113 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_pcix[1], (4 << 2)|i, apicid_mcp55, 0x10 + (2+i+4-sbdn%4)%4); // 18, 19, 16, 17 |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 114 | } |
| 115 | } |
| 116 | |
| 117 | /*Local Ints: Type Polarity Trigger Bus ID IRQ APIC ID PIN#*/ |
Patrick Georgi | 6eb7a53 | 2011-10-07 21:42:52 +0200 | [diff] [blame] | 118 | mptable_lintsrc(mc, bus_isa); |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 119 | /* There is no extension information... */ |
| 120 | |
| 121 | /* Compute the checksums */ |
Patrick Georgi | b0a9c5c | 2011-10-07 23:01:55 +0200 | [diff] [blame] | 122 | return mptable_finalize(mc); |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | unsigned long write_smp_table(unsigned long addr) |
| 126 | { |
| 127 | void *v; |
Patrick Georgi | c75c79b | 2011-10-07 22:41:07 +0200 | [diff] [blame] | 128 | v = smp_write_floating_table(addr, 0); |
Yinghai Lu | f55b58d | 2007-02-17 14:28:11 +0000 | [diff] [blame] | 129 | return (unsigned long)smp_write_config_table(v); |
| 130 | } |