blob: 71c7f9045b95e87ae2b38835329d347c60d5f45e [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
15extern unsigned char bus_8131_0; //7
16extern unsigned char bus_8131_1; //8
17extern unsigned char bus_8131_2; //9
18extern unsigned char bus_ck804b_0;//a
19extern unsigned char bus_ck804b_1;//b
20extern unsigned char bus_ck804b_2;//c
21extern unsigned char bus_ck804b_3;//d
22extern unsigned char bus_ck804b_4;//e
23extern unsigned char bus_ck804b_5;//f
24extern unsigned apicid_ck804;
25extern unsigned apicid_8131_1;
26extern unsigned apicid_8131_2;
27extern unsigned apicid_ck804b;
arch import user (historical)ef03afa2005-07-06 17:15:30 +000028
Yinghai Lu968bbe82005-12-06 23:34:09 +000029extern unsigned sbdn3;
30extern unsigned sbdnb;
Yinghai Lu13f1c2a2005-07-08 02:49:49 +000031
Myles Watson54913b92009-10-13 20:00:09 +000032static void *smp_write_config_table(void *v)
arch import user (historical)98d0d302005-07-06 17:13:46 +000033{
Myles Watsona67c354c2008-09-18 15:30:42 +000034 struct mp_config_table *mc;
Yinghai Lu6d74d762006-10-04 23:57:49 +000035 unsigned sbdn;
Myles Watsona67c354c2008-09-18 15:30:42 +000036 unsigned char bus_num;
Yinghai Lu968bbe82005-12-06 23:34:09 +000037 int i;
arch import user (historical)98d0d302005-07-06 17:13:46 +000038
Myles Watsona67c354c2008-09-18 15:30:42 +000039 mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
arch import user (historical)98d0d302005-07-06 17:13:46 +000040
Uwe Hermann55dc2232010-10-25 15:32:07 +000041 mptable_init(mc, "S2895 ", LAPIC_ADDR);
arch import user (historical)98d0d302005-07-06 17:13:46 +000042
Myles Watsona67c354c2008-09-18 15:30:42 +000043 smp_write_processors(mc);
arch import user (historical)98d0d302005-07-06 17:13:46 +000044
Yinghai Lu968bbe82005-12-06 23:34:09 +000045 get_bus_conf();
Yinghai Lu6d74d762006-10-04 23:57:49 +000046 sbdn = sysconf.sbdn;
arch import user (historical)98d0d302005-07-06 17:13:46 +000047
48/*Bus: Bus ID Type*/
49 /* define bus and isa numbers */
Myles Watsona67c354c2008-09-18 15:30:42 +000050 for(bus_num = 0; bus_num < bus_isa; bus_num++) {
51 smp_write_bus(mc, bus_num, "PCI ");
52 }
53 smp_write_bus(mc, bus_isa, "ISA ");
arch import user (historical)98d0d302005-07-06 17:13:46 +000054
55/*I/O APICs: APIC ID Version State Address*/
Myles Watsona67c354c2008-09-18 15:30:42 +000056 {
57 device_t dev;
arch import user (historical)98d0d302005-07-06 17:13:46 +000058 struct resource *res;
59 uint32_t dword;
60
Myles Watsona67c354c2008-09-18 15:30:42 +000061 dev = dev_find_slot(bus_ck804_0, PCI_DEVFN(sbdn+ 0x1,0));
62 if (dev) {
arch import user (historical)98d0d302005-07-06 17:13:46 +000063 res = find_resource(dev, PCI_BASE_ADDRESS_1);
64 if (res) {
65 smp_write_ioapic(mc, apicid_ck804, 0x11, res->base);
66 }
67
Myles Watson3d1d3b22008-04-23 20:40:55 +000068 /* Initialize interrupt mapping*/
Yinghai Lu968bbe82005-12-06 23:34:09 +000069
Myles Watson3d1d3b22008-04-23 20:40:55 +000070 dword = 0x0120d218;
Myles Watsona67c354c2008-09-18 15:30:42 +000071 pci_write_config32(dev, 0x7c, dword);
arch import user (historical)98d0d302005-07-06 17:13:46 +000072
Myles Watsona67c354c2008-09-18 15:30:42 +000073 dword = 0x12008a00;
74 pci_write_config32(dev, 0x80, dword);
arch import user (historical)98d0d302005-07-06 17:13:46 +000075
Myles Watsona67c354c2008-09-18 15:30:42 +000076 dword = 0x00080d7d;
77 pci_write_config32(dev, 0x84, dword);
arch import user (historical)98d0d302005-07-06 17:13:46 +000078
Myles Watsona67c354c2008-09-18 15:30:42 +000079 }
arch import user (historical)98d0d302005-07-06 17:13:46 +000080
Myles Watsona67c354c2008-09-18 15:30:42 +000081 dev = dev_find_slot(bus_8131_0, PCI_DEVFN(sbdn3,1));
82 if (dev) {
arch import user (historical)98d0d302005-07-06 17:13:46 +000083 res = find_resource(dev, PCI_BASE_ADDRESS_0);
84 if (res) {
85 smp_write_ioapic(mc, apicid_8131_1, 0x11, res->base);
86 }
Myles Watsona67c354c2008-09-18 15:30:42 +000087 }
88 dev = dev_find_slot(bus_8131_0, PCI_DEVFN(sbdn3+1,1));
89 if (dev) {
arch import user (historical)98d0d302005-07-06 17:13:46 +000090 res = find_resource(dev, PCI_BASE_ADDRESS_0);
91 if (res) {
92 smp_write_ioapic(mc, apicid_8131_2, 0x11, res->base);
93 }
Myles Watsona67c354c2008-09-18 15:30:42 +000094 }
arch import user (historical)98d0d302005-07-06 17:13:46 +000095
Yinghai Lu6d74d762006-10-04 23:57:49 +000096 if(sysconf.pci1234[2] & 0xf) {
Myles Watsona67c354c2008-09-18 15:30:42 +000097 dev = dev_find_slot(bus_ck804b_0, PCI_DEVFN(sbdnb + 0x1,0));
98 if (dev) {
arch import user (historical)98d0d302005-07-06 17:13:46 +000099 res = find_resource(dev, PCI_BASE_ADDRESS_1);
100 if (res) {
101 smp_write_ioapic(mc, apicid_ck804b, 0x11, res->base);
102 }
103
Myles Watson34b1d4e2009-03-10 20:56:54 +0000104 dword = 0x0000d218; // Why does the factory BIOS have 0?
Myles Watsona67c354c2008-09-18 15:30:42 +0000105 pci_write_config32(dev, 0x7c, dword);
arch import user (historical)98d0d302005-07-06 17:13:46 +0000106
Myles Watsona67c354c2008-09-18 15:30:42 +0000107 dword = 0x00000000;
108 pci_write_config32(dev, 0x80, dword);
arch import user (historical)98d0d302005-07-06 17:13:46 +0000109
Myles Watson34b1d4e2009-03-10 20:56:54 +0000110 dword = 0x00000d00; // Same here.
Myles Watsona67c354c2008-09-18 15:30:42 +0000111 pci_write_config32(dev, 0x84, dword);
arch import user (historical)98d0d302005-07-06 17:13:46 +0000112
Myles Watsona67c354c2008-09-18 15:30:42 +0000113 }
Yinghai Lu968bbe82005-12-06 23:34:09 +0000114 }
arch import user (historical)98d0d302005-07-06 17:13:46 +0000115
116 }
Myles Watsona67c354c2008-09-18 15:30:42 +0000117
Patrick Georgic5b87c82010-05-20 15:28:19 +0000118 mptable_add_isa_interrupts(mc, bus_isa, apicid_ck804, 1);
arch import user (historical)98d0d302005-07-06 17:13:46 +0000119
Patrick Georgic5b87c82010-05-20 15:28:19 +0000120/*I/O Ints: Type Polarity Trigger Bus ID IRQ APIC ID PIN# */
Yinghai Lu968bbe82005-12-06 23:34:09 +0000121// Onboard ck804 smbus
Myles Watsona67c354c2008-09-18 15:30:42 +0000122 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_ck804_0, ((sbdn+1)<<2)|1, apicid_ck804, 0xa);
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000123// 10
arch import user (historical)98d0d302005-07-06 17:13:46 +0000124
Yinghai Lu968bbe82005-12-06 23:34:09 +0000125// Onboard ck804 USB 1.1
Myles Watsona67c354c2008-09-18 15:30:42 +0000126 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 +0000127
Yinghai Lu968bbe82005-12-06 23:34:09 +0000128// Onboard ck804 USB 2
Myles Watsona67c354c2008-09-18 15:30:42 +0000129 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 +0000130
Yinghai Lu968bbe82005-12-06 23:34:09 +0000131// Onboard ck804 Audio
Myles Watsona67c354c2008-09-18 15:30:42 +0000132 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_ck804_0, ((sbdn+4)<<2)|0, apicid_ck804, 0x14); // 20
arch import user (historical)98d0d302005-07-06 17:13:46 +0000133
Yinghai Lu968bbe82005-12-06 23:34:09 +0000134// Onboard ck804 SATA 0
Myles Watsona67c354c2008-09-18 15:30:42 +0000135 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 +0000136
Yinghai Lu968bbe82005-12-06 23:34:09 +0000137// Onboard ck804 SATA 1
Myles Watsona67c354c2008-09-18 15:30:42 +0000138 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 +0000139
Yinghai Lu968bbe82005-12-06 23:34:09 +0000140// Onboard ck804 NIC
Myles Watsona67c354c2008-09-18 15:30:42 +0000141 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_ck804_0, ((sbdn +0x0a)<<2)|0, apicid_ck804, 0x15); // 21
arch import user (historical)98d0d302005-07-06 17:13:46 +0000142
Myles Watson34b1d4e2009-03-10 20:56:54 +0000143//Slot PCIE x16
Myles Watsona67c354c2008-09-18 15:30:42 +0000144 for(i=0;i<4;i++) {
145 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);
146 }
arch import user (historical)98d0d302005-07-06 17:13:46 +0000147
Yinghai Lu968bbe82005-12-06 23:34:09 +0000148//Onboard Firewire
Myles Watsona67c354c2008-09-18 15:30:42 +0000149 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_ck804_1, (0x05<<2)|0, apicid_ck804, 0x13); // 19
arch import user (historical)98d0d302005-07-06 17:13:46 +0000150
Yinghai Lu968bbe82005-12-06 23:34:09 +0000151//Slot 2 PCI 32
Myles Watsona67c354c2008-09-18 15:30:42 +0000152 for(i=0;i<4;i++) {
Myles Watson34b1d4e2009-03-10 20:56:54 +0000153 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_ck804_1, (0x04<<2)|i, apicid_ck804, 0x10 + (0+i)%4); //16
Myles Watsona67c354c2008-09-18 15:30:42 +0000154 }
arch import user (historical)98d0d302005-07-06 17:13:46 +0000155
Yinghai Lu6d74d762006-10-04 23:57:49 +0000156 if(sysconf.pci1234[2] & 0xf) {
Yinghai Lu968bbe82005-12-06 23:34:09 +0000157//Onboard ck804b NIC
Myles Watsona67c354c2008-09-18 15:30:42 +0000158 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_ck804b_0, ((sbdnb+0x0a)<<2)|0, apicid_ck804b, 0x15);//24+4+4+21=53
arch import user (historical)98d0d302005-07-06 17:13:46 +0000159
Yinghai Lu968bbe82005-12-06 23:34:09 +0000160//Slot 3 PCIE x16
Myles Watsona67c354c2008-09-18 15:30:42 +0000161 for(i=0;i<4;i++) {
162 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_ck804b_5, (0x00<<2)|i, apicid_ck804b, 0x10 + (2+i+4-sbdnb%4)%4);
163 }
Yinghai Lu968bbe82005-12-06 23:34:09 +0000164 }
arch import user (historical)98d0d302005-07-06 17:13:46 +0000165
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000166//Channel B of 8131
167
168//Slot 4 PCI-X 100/66
Myles Watsona67c354c2008-09-18 15:30:42 +0000169 for(i=0;i<4;i++) {
170 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_2, (4<<2)|i, apicid_8131_2, (0+i)%4);
171 }
arch import user (historical)98d0d302005-07-06 17:13:46 +0000172
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000173//Slot 5 PCIX 100/66
Myles Watsona67c354c2008-09-18 15:30:42 +0000174 for(i=0;i<4;i++) {
175 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_2, (9<<2)|i, apicid_8131_2, (1+i)%4); // 29
176 }
arch import user (historical)98d0d302005-07-06 17:13:46 +0000177
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000178//OnBoard LSI SCSI
Myles Watsona67c354c2008-09-18 15:30:42 +0000179 for(i=0;i<2;i++) {
180 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_2, (6<<2)|i, apicid_8131_2, (2+i)%4); //30
181 }
arch import user (historical)98d0d302005-07-06 17:13:46 +0000182
Yinghai Lu13f1c2a2005-07-08 02:49:49 +0000183//Channel A of 8131
184
Myles Watsona67c354c2008-09-18 15:30:42 +0000185//Slot 6 PCIX 133/100/66
186 for(i=0;i<4;i++) {
187 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, (4<<2)|i, apicid_8131_1, (0+i)%4); //24
188 }
arch import user (historical)98d0d302005-07-06 17:13:46 +0000189
190/*Local Ints: Type Polarity Trigger Bus ID IRQ APIC ID PIN#*/
Tobias Diedrichb907d322010-10-26 22:40:16 +0000191 smp_write_lintsrc(mc, mp_ExtINT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, bus_isa, 0x0, MP_APIC_ALL, 0x0);
192 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 +0000193 /* There is no extension information... */
194
195 /* Compute the checksums */
196 mc->mpe_checksum = smp_compute_checksum(smp_next_mpc_entry(mc), mc->mpe_length);
197 mc->mpc_checksum = smp_compute_checksum(mc, mc->mpc_length);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000198 printk(BIOS_DEBUG, "Wrote the mp table end at: %p - %p\n",
arch import user (historical)98d0d302005-07-06 17:13:46 +0000199 mc, smp_next_mpe_entry(mc));
200 return smp_next_mpe_entry(mc);
201}
202
203unsigned long write_smp_table(unsigned long addr)
204{
205 void *v;
206 v = smp_write_floating_table(addr);
207 return (unsigned long)smp_write_config_table(v);
208}