arch import user (historical) | 7dec0f9 | 2005-07-06 18:17:06 +0000 | [diff] [blame] | 1 | #include <console/console.h> |
| 2 | #include <arch/smp/mpspec.h> |
Uwe Hermann | 74d1a6e | 2010-10-12 17:34:08 +0000 | [diff] [blame] | 3 | #include <arch/ioapic.h> |
arch import user (historical) | 7dec0f9 | 2005-07-06 18:17:06 +0000 | [diff] [blame] | 4 | #include <device/pci.h> |
| 5 | #include <string.h> |
| 6 | #include <stdint.h> |
Patrick Georgi | e166782 | 2012-05-05 15:29:32 +0200 | [diff] [blame] | 7 | #if CONFIG_LOGICAL_CPUS |
Stefan Reinauer | 9a16e3e | 2010-03-29 14:45:36 +0000 | [diff] [blame] | 8 | #include <cpu/amd/multicore.h> |
arch import user (historical) | 7dec0f9 | 2005-07-06 18:17:06 +0000 | [diff] [blame] | 9 | #endif |
| 10 | |
| 11 | static unsigned node_link_to_bus(unsigned node, unsigned link) |
| 12 | { |
| 13 | device_t dev; |
| 14 | unsigned reg; |
| 15 | |
| 16 | dev = dev_find_slot(0, PCI_DEVFN(0x18, 1)); |
| 17 | if (!dev) { |
| 18 | return 0; |
| 19 | } |
| 20 | for(reg = 0xE0; reg < 0xF0; reg += 0x04) { |
| 21 | uint32_t config_map; |
| 22 | unsigned dst_node; |
| 23 | unsigned dst_link; |
| 24 | unsigned bus_base; |
| 25 | config_map = pci_read_config32(dev, reg); |
| 26 | if ((config_map & 3) != 3) { |
| 27 | continue; |
| 28 | } |
| 29 | dst_node = (config_map >> 4) & 7; |
| 30 | dst_link = (config_map >> 8) & 3; |
| 31 | bus_base = (config_map >> 16) & 0xff; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 32 | #if 0 |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 33 | printk(BIOS_DEBUG, "node.link=bus: %d.%d=%d 0x%2x->0x%08x\n", |
arch import user (historical) | 7dec0f9 | 2005-07-06 18:17:06 +0000 | [diff] [blame] | 34 | dst_node, dst_link, bus_base, |
| 35 | reg, config_map); |
| 36 | #endif |
| 37 | if ((dst_node == node) && (dst_link == link)) |
| 38 | { |
| 39 | return bus_base; |
| 40 | } |
| 41 | } |
| 42 | return 0; |
| 43 | } |
| 44 | |
Myles Watson | 08e0fb8 | 2010-03-22 16:33:25 +0000 | [diff] [blame] | 45 | static void *smp_write_config_table(void *v) |
arch import user (historical) | 7dec0f9 | 2005-07-06 18:17:06 +0000 | [diff] [blame] | 46 | { |
arch import user (historical) | 7dec0f9 | 2005-07-06 18:17:06 +0000 | [diff] [blame] | 47 | struct mp_config_table *mc; |
Patrick Georgi | 2097958 | 2010-09-24 18:42:56 +0000 | [diff] [blame] | 48 | int bus_isa; |
arch import user (historical) | 7dec0f9 | 2005-07-06 18:17:06 +0000 | [diff] [blame] | 49 | unsigned char bus_chain_0; |
| 50 | unsigned char bus_8131_1; |
| 51 | unsigned char bus_8131_2; |
| 52 | unsigned char bus_8111_1; |
| 53 | unsigned apicid_base; |
| 54 | unsigned apicid_8111; |
| 55 | unsigned apicid_8131_1; |
| 56 | unsigned apicid_8131_2; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 57 | |
arch import user (historical) | 7dec0f9 | 2005-07-06 18:17:06 +0000 | [diff] [blame] | 58 | mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN); |
arch import user (historical) | 7dec0f9 | 2005-07-06 18:17:06 +0000 | [diff] [blame] | 59 | |
Patrick Georgi | c8feedd | 2012-02-16 18:43:25 +0100 | [diff] [blame] | 60 | mptable_init(mc, LOCAL_APIC_ADDR); |
arch import user (historical) | 7dec0f9 | 2005-07-06 18:17:06 +0000 | [diff] [blame] | 61 | |
| 62 | smp_write_processors(mc); |
| 63 | |
arch import user (historical) | 7dec0f9 | 2005-07-06 18:17:06 +0000 | [diff] [blame] | 64 | { |
| 65 | device_t dev; |
| 66 | |
| 67 | /* HT chain 0 */ |
| 68 | bus_chain_0 = node_link_to_bus(0, 2); |
| 69 | if (bus_chain_0 == 0) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 70 | printk(BIOS_DEBUG, "ERROR - cound not find bus for node 0 chain 0, using defaults\n"); |
arch import user (historical) | 7dec0f9 | 2005-07-06 18:17:06 +0000 | [diff] [blame] | 71 | bus_chain_0 = 1; |
| 72 | } |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 73 | |
arch import user (historical) | 7dec0f9 | 2005-07-06 18:17:06 +0000 | [diff] [blame] | 74 | /* 8111 */ |
| 75 | dev = dev_find_slot(bus_chain_0, PCI_DEVFN(0x03,0)); |
| 76 | if (dev) { |
| 77 | bus_8111_1 = pci_read_config8(dev, PCI_SECONDARY_BUS); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 78 | } |
arch import user (historical) | 7dec0f9 | 2005-07-06 18:17:06 +0000 | [diff] [blame] | 79 | else { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 80 | printk(BIOS_DEBUG, "ERROR - could not find PCI 1:03.0, using defaults\n"); |
arch import user (historical) | 7dec0f9 | 2005-07-06 18:17:06 +0000 | [diff] [blame] | 81 | |
| 82 | bus_8111_1 = 4; |
arch import user (historical) | 7dec0f9 | 2005-07-06 18:17:06 +0000 | [diff] [blame] | 83 | } |
| 84 | /* 8131-1 */ |
| 85 | dev = dev_find_slot(bus_chain_0, PCI_DEVFN(0x01,0)); |
| 86 | if (dev) { |
| 87 | bus_8131_1 = pci_read_config8(dev, PCI_SECONDARY_BUS); |
| 88 | |
| 89 | } |
| 90 | else { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 91 | printk(BIOS_DEBUG, "ERROR - could not find PCI 1:01.0, using defaults\n"); |
arch import user (historical) | 7dec0f9 | 2005-07-06 18:17:06 +0000 | [diff] [blame] | 92 | |
| 93 | bus_8131_1 = 2; |
| 94 | } |
| 95 | /* 8131-2 */ |
| 96 | dev = dev_find_slot(bus_chain_0, PCI_DEVFN(0x02,0)); |
| 97 | if (dev) { |
| 98 | bus_8131_2 = pci_read_config8(dev, PCI_SECONDARY_BUS); |
| 99 | |
| 100 | } |
| 101 | else { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 102 | printk(BIOS_DEBUG, "ERROR - could not find PCI 1:02.0, using defaults\n"); |
arch import user (historical) | 7dec0f9 | 2005-07-06 18:17:06 +0000 | [diff] [blame] | 103 | |
| 104 | bus_8131_2 = 3; |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | /*Bus: Bus ID Type*/ |
Patrick Georgi | 2097958 | 2010-09-24 18:42:56 +0000 | [diff] [blame] | 109 | mptable_write_buses(mc, NULL, &bus_isa); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 110 | |
arch import user (historical) | 7dec0f9 | 2005-07-06 18:17:06 +0000 | [diff] [blame] | 111 | /*I/O APICs: APIC ID Version State Address*/ |
Patrick Georgi | e166782 | 2012-05-05 15:29:32 +0200 | [diff] [blame] | 112 | #if CONFIG_LOGICAL_CPUS |
arch import user (historical) | 7dec0f9 | 2005-07-06 18:17:06 +0000 | [diff] [blame] | 113 | apicid_base = get_apicid_base(3); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 114 | #else |
| 115 | apicid_base = CONFIG_MAX_PHYSICAL_CPUS; |
arch import user (historical) | 7dec0f9 | 2005-07-06 18:17:06 +0000 | [diff] [blame] | 116 | #endif |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 117 | apicid_8111 = apicid_base+0; |
arch import user (historical) | 7dec0f9 | 2005-07-06 18:17:06 +0000 | [diff] [blame] | 118 | apicid_8131_1 = apicid_base+1; |
| 119 | apicid_8131_2 = apicid_base+2; |
| 120 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 121 | smp_write_ioapic(mc, apicid_8111, 0x11, VIO_APIC_VADDR); |
arch import user (historical) | 7dec0f9 | 2005-07-06 18:17:06 +0000 | [diff] [blame] | 122 | { |
| 123 | device_t dev; |
| 124 | struct resource *res; |
| 125 | dev = dev_find_slot(bus_chain_0, PCI_DEVFN(0x1,1)); |
| 126 | if (dev) { |
| 127 | res = find_resource(dev, PCI_BASE_ADDRESS_0); |
| 128 | if (res) { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 129 | smp_write_ioapic(mc, apicid_8131_1, 0x11, |
| 130 | res2mmio(res, 0, 0)); |
arch import user (historical) | 7dec0f9 | 2005-07-06 18:17:06 +0000 | [diff] [blame] | 131 | } |
| 132 | } |
| 133 | dev = dev_find_slot(bus_chain_0, PCI_DEVFN(0x2,1)); |
| 134 | if (dev) { |
| 135 | res = find_resource(dev, PCI_BASE_ADDRESS_0); |
| 136 | if (res) { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 137 | smp_write_ioapic(mc, apicid_8131_2, 0x11, |
| 138 | res2mmio(res, 0, 0)); |
arch import user (historical) | 7dec0f9 | 2005-07-06 18:17:06 +0000 | [diff] [blame] | 139 | } |
| 140 | } |
| 141 | |
| 142 | } |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 143 | |
Patrick Georgi | c5b87c8 | 2010-05-20 15:28:19 +0000 | [diff] [blame] | 144 | mptable_add_isa_interrupts(mc, bus_isa, apicid_8111, 0); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 145 | |
Patrick Georgi | c5b87c8 | 2010-05-20 15:28:19 +0000 | [diff] [blame] | 146 | /*I/O Ints: Type Polarity Trigger Bus ID IRQ APIC ID PIN# */ |
arch import user (historical) | 7dec0f9 | 2005-07-06 18:17:06 +0000 | [diff] [blame] | 147 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_chain_0, (4<<2)|0, apicid_8111, 0x13); |
| 148 | |
| 149 | |
| 150 | //On Board AMD USB |
| 151 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (0<<2)|3, apicid_8111, 0x13); |
| 152 | |
| 153 | //On Board Via USB 1.1 and 2 |
| 154 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (3<<2)|0, apicid_8111, 0x11); //1.1 |
| 155 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (3<<2)|1, apicid_8111, 0x10); //1.1 |
| 156 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (3<<2)|2, apicid_8111, 0x12); //2 |
| 157 | |
| 158 | //Slot 5 PCI 32 |
| 159 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (4<<2)|0, apicid_8111, 0x10); |
| 160 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (4<<2)|1, apicid_8111, 0x11); |
| 161 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (4<<2)|2, apicid_8111, 0x12); // |
| 162 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (4<<2)|3, apicid_8111, 0x13); // |
| 163 | |
| 164 | |
| 165 | //On Board SI Serial ATA |
| 166 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (5<<2)|0, apicid_8111, 0x13); |
| 167 | //On Board ATI Display Adapter |
| 168 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, (6<<2)|0, apicid_8111, 0x12); |
| 169 | |
| 170 | |
| 171 | //Slot 4 PCIX 100/66 |
| 172 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (3<<2)|0, apicid_8131_1, 0x3); |
| 173 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (3<<2)|1, apicid_8131_1, 0x0); |
| 174 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (3<<2)|2, apicid_8131_1, 0x1);// |
| 175 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (3<<2)|3, apicid_8131_1, 0x2);// |
| 176 | |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 177 | //Slot 3 PCIX 100/66 |
arch import user (historical) | 7dec0f9 | 2005-07-06 18:17:06 +0000 | [diff] [blame] | 178 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (2<<2)|0, apicid_8131_1, 0x2); |
| 179 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (2<<2)|1, apicid_8131_1, 0x3);// |
| 180 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (2<<2)|2, apicid_8131_1, 0x0);// |
| 181 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (2<<2)|3, apicid_8131_1, 0x1);// |
| 182 | |
| 183 | //On Board LSI scsi and NIC |
| 184 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (4<<2)|0, apicid_8131_1, 0x0); |
| 185 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (4<<2)|1, apicid_8131_1, 0x1); |
| 186 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (9<<2)|0, apicid_8131_1, 0x0); |
| 187 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (9<<2)|1, apicid_8131_1, 0x1); |
| 188 | |
| 189 | //Slot 2 PCI-X 133/100/66 |
| 190 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_2, (3<<2)|0, apicid_8131_2, 0x0); |
| 191 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_2, (3<<2)|1, apicid_8131_2, 0x1); |
| 192 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_2, (3<<2)|2, apicid_8131_2, 0x2); // |
| 193 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_2, (3<<2)|3, apicid_8131_2, 0x3); // |
| 194 | |
| 195 | //Slot 1 PCI-X 133/100/66 |
| 196 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_2, (1<<2)|0, apicid_8131_2, 0x1); |
| 197 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_2, (1<<2)|1, apicid_8131_2, 0x2); |
| 198 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_2, (1<<2)|2, apicid_8131_2, 0x3);// |
| 199 | smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_2, (1<<2)|3, apicid_8131_2, 0x0);// |
| 200 | |
| 201 | /*Local Ints: Type Polarity Trigger Bus ID IRQ APIC ID PIN#*/ |
Patrick Georgi | 6eb7a53 | 2011-10-07 21:42:52 +0200 | [diff] [blame] | 202 | mptable_lintsrc(mc, bus_isa); |
arch import user (historical) | 7dec0f9 | 2005-07-06 18:17:06 +0000 | [diff] [blame] | 203 | /* There is no extension information... */ |
| 204 | |
| 205 | /* Compute the checksums */ |
Patrick Georgi | b0a9c5c | 2011-10-07 23:01:55 +0200 | [diff] [blame] | 206 | return mptable_finalize(mc); |
arch import user (historical) | 7dec0f9 | 2005-07-06 18:17:06 +0000 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | unsigned long write_smp_table(unsigned long addr) |
| 210 | { |
| 211 | void *v; |
Patrick Georgi | c75c79b | 2011-10-07 22:41:07 +0200 | [diff] [blame] | 212 | v = smp_write_floating_table(addr, 0); |
arch import user (historical) | 7dec0f9 | 2005-07-06 18:17:06 +0000 | [diff] [blame] | 213 | return (unsigned long)smp_write_config_table(v); |
| 214 | } |