Factor out common mptable code to mptable_init().
[coreboot.git] / src / mainboard / broadcom / blast / mptable.c
1 #include <console/console.h>
2 #include <arch/smp/mpspec.h>
3 #include <arch/io.h>
4 #include <device/pci.h>
5 #include <string.h>
6 #include <stdint.h>
7 #if CONFIG_LOGICAL_CPUS==1
8 #include <cpu/amd/multicore.h>
9 #endif
10 #include <cpu/amd/amdk8_sysconf.h>
11
12 extern  unsigned char bus_isa;
13 extern  unsigned char bus_bcm5780[7];
14 extern  unsigned char bus_bcm5785_0;
15 extern  unsigned char bus_bcm5785_1;
16 extern  unsigned char bus_bcm5785_1_1;
17 extern  unsigned apicid_bcm5785[3];
18
19 extern  unsigned sbdn2;
20
21 static void *smp_write_config_table(void *v)
22 {
23         struct mp_config_table *mc;
24         unsigned char bus_num;
25         int i;
26
27         mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
28
29         mptable_init(mc, "BLAST       ", LAPIC_ADDR);
30
31         smp_write_processors(mc);
32
33         get_bus_conf();
34
35 /*Bus:          Bus ID  Type*/
36        /* define bus and isa numbers */
37         for(bus_num = 0; bus_num < bus_isa; bus_num++) {
38                 smp_write_bus(mc, bus_num, "PCI   ");
39         }
40         smp_write_bus(mc, bus_isa, "ISA   ");
41
42 /*I/O APICs:    APIC ID Version State           Address*/
43         {
44                 device_t dev = 0;
45                 struct resource *res;
46                 for(i=0; i<3; i++) {
47                         dev = dev_find_device(0x1166, 0x0235, dev);
48                         if (dev) {
49                                 res = find_resource(dev, PCI_BASE_ADDRESS_0);
50                                 if (res) {
51                                         smp_write_ioapic(mc, apicid_bcm5785[i], 0x11, res->base);
52                                 }
53                         }
54                 }
55
56         }
57
58         mptable_add_isa_interrupts(mc, bus_isa, apicid_bcm5785[0], 0);
59
60 //IDE
61         outb(0x02, 0xc00); outb(0x0e, 0xc01);
62
63         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  bus_bcm5785_0, ((1+sysconf.sbdn)<<2)|1, apicid_bcm5785[0], 0xe); // IDE
64
65 //SATA
66         outb(0x07, 0xc00); outb(0x0f, 0xc01);
67         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_bcm5785_1, (0x0e<<2)|0, apicid_bcm5785[0], 0xf);
68
69 //USB
70         outb(0x01, 0xc00); outb(0x0a, 0xc01);
71         for(i=0;i<3;i++) {
72                 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_bcm5785_0, ((2+sysconf.sbdn)<<2)|i, apicid_bcm5785[0], 0xa); //
73         }
74
75
76
77         /* enable int */
78         /* why here? must get the BAR and PCI command bit 1 set before enable it ....*/
79         {
80                 device_t dev;
81                 dev = dev_find_device(0x1166, 0x0205, 0);
82                 if(dev) {
83                         uint32_t dword;
84                         dword = pci_read_config32(dev, 0x6c);
85                         dword |= (1<<4); // enable interrupts
86                         pci_write_config32(dev, 0x6c, dword);
87
88                 }
89
90         }
91
92 //First pci-x slot (on bcm5785) under bus_bcm5785_1:d.0
93         for(i=0;i<4;i++) {
94                 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_bcm5785_1_1, (4<<2)|i, apicid_bcm5785[1], 2 + (0+i)%4); //
95         }
96
97
98 //pci slot (on bcm5785)
99         for(i=0;i<4;i++) {
100                 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_bcm5785_0, (4<<2)|i, apicid_bcm5785[1], i%2); //
101         }
102
103
104 //onboard ati
105         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_bcm5785_0, (5<<2)|0, apicid_bcm5785[1], 0x1);
106
107 //PCI-X on bcm5780
108         for(i=0;i<4;i++) {
109                 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_bcm5780[1], (4<<2)|i, apicid_bcm5785[1], 6 + (0+i)%4); //
110         }
111
112         for(i=0;i<4;i++) {
113                 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_bcm5780[1], (5<<2)|i, apicid_bcm5785[1], 6 + (1+i)%4); //
114         }
115
116 //onboard Broadcom
117         for(i=0;i<2;i++) {
118                 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_bcm5780[2], (4<<2)|i, apicid_bcm5785[1], 0xa + (0+i)%4); //
119         }
120
121
122 // First PCI-E x8
123         for(i=0;i<4;i++) {
124                 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_bcm5780[5], (0<<2)|i, apicid_bcm5785[1], 0xe); //
125         }
126
127
128 // Second PCI-E x8
129         for(i=0;i<4;i++) {
130                 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_bcm5780[3], (0<<2)|i, apicid_bcm5785[1], 0xc); //
131         }
132
133
134 // Third PCI-E x1
135         for(i=0;i<4;i++) {
136                 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_bcm5780[4], (0<<2)|i, apicid_bcm5785[1], 0xd); //
137         }
138
139 /*Local Ints:   Type    Polarity    Trigger     Bus ID   IRQ    APIC ID PIN#*/
140         smp_write_intsrc(mc, mp_ExtINT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, bus_isa, 0x0, MP_APIC_ALL, 0x0);
141         smp_write_intsrc(mc, mp_NMI, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, bus_isa, 0x0, MP_APIC_ALL, 0x1);
142         /* There is no extension information... */
143
144         /* Compute the checksums */
145         mc->mpe_checksum = smp_compute_checksum(smp_next_mpc_entry(mc), mc->mpe_length);
146         mc->mpc_checksum = smp_compute_checksum(mc, mc->mpc_length);
147         printk(BIOS_DEBUG, "Wrote the mp table end at: %p - %p\n",
148                 mc, smp_next_mpe_entry(mc));
149         return smp_next_mpe_entry(mc);
150 }
151
152 unsigned long write_smp_table(unsigned long addr)
153 {
154         void *v;
155         v = smp_write_floating_table(addr);
156         return (unsigned long)smp_write_config_table(v);
157 }