blob: b7dd77ac265323223707595d5e7c6f255b32ab8a [file] [log] [blame]
arch import user (historical)98d0d302005-07-06 17:13:46 +00001#include <console/console.h>
2#include <arch/smp/mpspec.h>
3#include <device/pci.h>
4#include <string.h>
5#include <stdint.h>
Yinghai Lu6d74d762006-10-04 23:57:49 +00006#include <cpu/amd/amdk8_sysconf.h>
7
Yinghai Lu968bbe82005-12-06 23:34:09 +00008extern unsigned char bus_isa;
9extern unsigned char bus_ck804_0; //1
10extern unsigned char bus_ck804_1; //2
11extern unsigned char bus_ck804_2; //3
12extern unsigned char bus_ck804_3; //4
13extern unsigned char bus_ck804_4; //5
14extern unsigned char bus_ck804_5; //6
Myles Watsona67c354c2008-09-18 15:30:42 +000015extern unsigned char bus_8131_0; //7
16extern unsigned char bus_8131_1; //8
17extern unsigned char bus_8131_2; //9
Yinghai Lu968bbe82005-12-06 23:34:09 +000018extern unsigned apicid_ck804;
19extern unsigned apicid_8131_1;
20extern unsigned apicid_8131_2;
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000021
Yinghai Lu968bbe82005-12-06 23:34:09 +000022extern unsigned sbdn3;
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000023
Myles Watson08e0fb82010-03-22 16:33:25 +000024static void *smp_write_config_table(void *v)
arch import user (historical)98d0d302005-07-06 17:13:46 +000025{
Myles Watsona67c354c2008-09-18 15:30:42 +000026 struct mp_config_table *mc;
Yinghai Lu6d74d762006-10-04 23:57:49 +000027 unsigned sbdn;
Myles Watsona67c354c2008-09-18 15:30:42 +000028 unsigned char bus_num;
Yinghai Lu968bbe82005-12-06 23:34:09 +000029 int i;
arch import user (historical)98d0d302005-07-06 17:13:46 +000030
Myles Watsona67c354c2008-09-18 15:30:42 +000031 mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
arch import user (historical)98d0d302005-07-06 17:13:46 +000032
Uwe Hermann55dc2232010-10-25 15:32:07 +000033 mptable_init(mc, "S2891 ", LAPIC_ADDR);
arch import user (historical)98d0d302005-07-06 17:13:46 +000034
Myles Watsona67c354c2008-09-18 15:30:42 +000035 smp_write_processors(mc);
arch import user (historical)98d0d302005-07-06 17:13:46 +000036
Yinghai Lu968bbe82005-12-06 23:34:09 +000037 get_bus_conf();
Yinghai Lu6d74d762006-10-04 23:57:49 +000038 sbdn = sysconf.sbdn;
arch import user (historical)98d0d302005-07-06 17:13:46 +000039
40/*Bus: Bus ID Type*/
41 /* define bus and isa numbers */
Myles Watsona67c354c2008-09-18 15:30:42 +000042 for(bus_num = 0; bus_num < bus_isa; bus_num++) {
43 smp_write_bus(mc, bus_num, "PCI ");
44 }
45 smp_write_bus(mc, bus_isa, "ISA ");
arch import user (historical)98d0d302005-07-06 17:13:46 +000046
47/*I/O APICs: APIC ID Version State Address*/
Myles Watsona67c354c2008-09-18 15:30:42 +000048 {
49 device_t dev;
arch import user (historical)98d0d302005-07-06 17:13:46 +000050 struct resource *res;
51 uint32_t dword;
52
Myles Watsona67c354c2008-09-18 15:30:42 +000053 dev = dev_find_slot(bus_ck804_0, PCI_DEVFN(sbdn+ 0x1,0));
54 if (dev) {
arch import user (historical)98d0d302005-07-06 17:13:46 +000055 res = find_resource(dev, PCI_BASE_ADDRESS_1);
56 if (res) {
57 smp_write_ioapic(mc, apicid_ck804, 0x11, res->base);
58 }
Myles Watson3d1d3b22008-04-23 20:40:55 +000059
Yinghai Lu6d74d762006-10-04 23:57:49 +000060 /* Initialize interrupt mapping*/
arch import user (historical)98d0d302005-07-06 17:13:46 +000061
Ward Vandewegec4a41162008-04-23 00:40:39 +000062 dword = 0x0120d218;
Myles Watsona67c354c2008-09-18 15:30:42 +000063 pci_write_config32(dev, 0x7c, dword);
arch import user (historical)98d0d302005-07-06 17:13:46 +000064
Myles Watsona67c354c2008-09-18 15:30:42 +000065 dword = 0x12008a00;
66 pci_write_config32(dev, 0x80, dword);
arch import user (historical)98d0d302005-07-06 17:13:46 +000067
Myles Watsona67c354c2008-09-18 15:30:42 +000068 dword = 0x0000007d;
69 pci_write_config32(dev, 0x84, dword);
arch import user (historical)98d0d302005-07-06 17:13:46 +000070
Myles Watsona67c354c2008-09-18 15:30:42 +000071 }
arch import user (historical)98d0d302005-07-06 17:13:46 +000072
Myles Watsona67c354c2008-09-18 15:30:42 +000073 dev = dev_find_slot(bus_8131_0, PCI_DEVFN(sbdn3,1));
74 if (dev) {
arch import user (historical)98d0d302005-07-06 17:13:46 +000075 res = find_resource(dev, PCI_BASE_ADDRESS_0);
76 if (res) {
77 smp_write_ioapic(mc, apicid_8131_1, 0x11, res->base);
78 }
Myles Watsona67c354c2008-09-18 15:30:42 +000079 }
80 dev = dev_find_slot(bus_8131_0, PCI_DEVFN(sbdn3+1,1));
81 if (dev) {
arch import user (historical)98d0d302005-07-06 17:13:46 +000082 res = find_resource(dev, PCI_BASE_ADDRESS_0);
83 if (res) {
84 smp_write_ioapic(mc, apicid_8131_2, 0x11, res->base);
85 }
Myles Watsona67c354c2008-09-18 15:30:42 +000086 }
arch import user (historical)98d0d302005-07-06 17:13:46 +000087
88 }
Myles Watsona67c354c2008-09-18 15:30:42 +000089
Patrick Georgic5b87c82010-05-20 15:28:19 +000090 mptable_add_isa_interrupts(mc, bus_isa, apicid_ck804, 1);
arch import user (historical)98d0d302005-07-06 17:13:46 +000091
Yinghai Lu968bbe82005-12-06 23:34:09 +000092// Onboard ck804 smbus
Myles Watson34b1d4e2009-03-10 20:56:54 +000093 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_ck804_0, ((sbdn+1)<<2)|1, apicid_ck804, 0xa); // 10
arch import user (historical)98d0d302005-07-06 17:13:46 +000094
Yinghai Lu968bbe82005-12-06 23:34:09 +000095// Onboard ck804 USB 1.1
Myles Watsona67c354c2008-09-18 15:30:42 +000096 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_ck804_0, ((sbdn+2)<<2)|0, apicid_ck804, 0x15); // 21
arch import user (historical)98d0d302005-07-06 17:13:46 +000097
Yinghai Lu968bbe82005-12-06 23:34:09 +000098// Onboard ck804 USB 2
Myles Watsona67c354c2008-09-18 15:30:42 +000099 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_ck804_0, ((sbdn+2)<<2)|1, apicid_ck804, 0x14); // 20
arch import user (historical)98d0d302005-07-06 17:13:46 +0000100
Yinghai Lu968bbe82005-12-06 23:34:09 +0000101// Onboard ck804 SATA 0
Myles Watsona67c354c2008-09-18 15:30:42 +0000102 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_ck804_0, ((sbdn +7)<<2)|0, apicid_ck804, 0x17); // 23
arch import user (historical)98d0d302005-07-06 17:13:46 +0000103
Yinghai Lu968bbe82005-12-06 23:34:09 +0000104// Onboard ck804 SATA 1
Myles Watsona67c354c2008-09-18 15:30:42 +0000105 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_ck804_0, ((sbdn +8)<<2)|0, apicid_ck804, 0x16); // 22
arch import user (historical)98d0d302005-07-06 17:13:46 +0000106
Myles Watson34b1d4e2009-03-10 20:56:54 +0000107//Slot PCIE x16
Myles Watsona67c354c2008-09-18 15:30:42 +0000108 for(i=0;i<4;i++) {
109 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_ck804_5, (0x00<<2)|i, apicid_ck804, 0x10 + (2+i+4-sbdn%4)%4);
110 }
arch import user (historical)98d0d302005-07-06 17:13:46 +0000111
Yinghai Lu968bbe82005-12-06 23:34:09 +0000112//Slot PCIE x4
Myles Watsona67c354c2008-09-18 15:30:42 +0000113 for(i=0;i<4;i++) {
114 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_ck804_4, (0x00<<2)|i, apicid_ck804, 0x10 + (1+i+4-sbdn%4)%4);
115 }
arch import user (historical)98d0d302005-07-06 17:13:46 +0000116
Yinghai Lu968bbe82005-12-06 23:34:09 +0000117//Onboard ati
Myles Watsona67c354c2008-09-18 15:30:42 +0000118 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_ck804_1, (7<<2)|0, apicid_ck804, 0x13); // 19
arch import user (historical)98d0d302005-07-06 17:13:46 +0000119
Yinghai Lu968bbe82005-12-06 23:34:09 +0000120//Channel B of 8131
arch import user (historical)98d0d302005-07-06 17:13:46 +0000121
arch import user (historical)98d0d302005-07-06 17:13:46 +0000122
Yinghai Lu968bbe82005-12-06 23:34:09 +0000123//Onboard Broadcom NIC
Myles Watsona67c354c2008-09-18 15:30:42 +0000124 for(i=0;i<2;i++) {
125 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_2, (9<<2)|i, apicid_8131_2, (0+i)%4); //28
126 }
arch import user (historical)98d0d302005-07-06 17:13:46 +0000127
Yinghai Lu968bbe82005-12-06 23:34:09 +0000128//Channel A of 8131
129
Myles Watsona67c354c2008-09-18 15:30:42 +0000130//Slot 4 PCIX 133/100/66
131 for(i=0;i<4;i++) {
132 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (8<<2)|i, apicid_8131_1, (0+i)%4); //24
133 }
Yinghai Lu968bbe82005-12-06 23:34:09 +0000134
135//Slot 3 PCIX 133/100/66 SoDIMM PCI
Myles Watsona67c354c2008-09-18 15:30:42 +0000136 for(i=0;i<4;i++) {
137 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (0xa<<2)|i, apicid_8131_1, (2+i)%4); //26
138 }
arch import user (historical)98d0d302005-07-06 17:13:46 +0000139
140/*Local Ints: Type Polarity Trigger Bus ID IRQ APIC ID PIN#*/
Tobias Diedrichb907d322010-10-26 22:40:16 +0000141 smp_write_lintsrc(mc, mp_ExtINT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, bus_isa, 0x0, MP_APIC_ALL, 0x0);
142 smp_write_lintsrc(mc, mp_NMI, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, bus_isa, 0x0, MP_APIC_ALL, 0x1);
arch import user (historical)98d0d302005-07-06 17:13:46 +0000143 /* There is no extension information... */
144
145 /* Compute the checksums */
146 mc->mpe_checksum = smp_compute_checksum(smp_next_mpc_entry(mc), mc->mpe_length);
147 mc->mpc_checksum = smp_compute_checksum(mc, mc->mpc_length);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000148 printk(BIOS_DEBUG, "Wrote the mp table end at: %p - %p\n",
arch import user (historical)98d0d302005-07-06 17:13:46 +0000149 mc, smp_next_mpe_entry(mc));
150 return smp_next_mpe_entry(mc);
151}
152
153unsigned long write_smp_table(unsigned long addr)
154{
155 void *v;
156 v = smp_write_floating_table(addr);
157 return (unsigned long)smp_write_config_table(v);
158}