Unify Local APIC address definitions
[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_bcm5780[7];
13 extern  unsigned char bus_bcm5785_0;
14 extern  unsigned char bus_bcm5785_1;
15 extern  unsigned char bus_bcm5785_1_1;
16 extern  unsigned apicid_bcm5785[3];
17
18 extern  unsigned sbdn2;
19
20 static void *smp_write_config_table(void *v)
21 {
22         struct mp_config_table *mc;
23         int i, bus_isa;
24
25         mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
26
27         mptable_init(mc, LOCAL_APIC_ADDR);
28
29         smp_write_processors(mc);
30
31         get_bus_conf();
32
33         mptable_write_buses(mc, NULL, &bus_isa);
34
35 /*I/O APICs:    APIC ID Version State           Address*/
36         {
37                 device_t dev = 0;
38                 struct resource *res;
39                 for(i=0; i<3; i++) {
40                         dev = dev_find_device(0x1166, 0x0235, dev);
41                         if (dev) {
42                                 res = find_resource(dev, PCI_BASE_ADDRESS_0);
43                                 if (res) {
44                                         smp_write_ioapic(mc, apicid_bcm5785[i], 0x11, res->base);
45                                 }
46                         }
47                 }
48
49         }
50
51         mptable_add_isa_interrupts(mc, bus_isa, apicid_bcm5785[0], 0);
52
53 //IDE
54         outb(0x02, 0xc00); outb(0x0e, 0xc01);
55
56         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
57
58 //SATA
59         outb(0x07, 0xc00); outb(0x0f, 0xc01);
60         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_bcm5785_1, (0x0e<<2)|0, apicid_bcm5785[0], 0xf);
61
62 //USB
63         outb(0x01, 0xc00); outb(0x0a, 0xc01);
64         for(i=0;i<3;i++) {
65                 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); //
66         }
67
68
69
70         /* enable int */
71         /* why here? must get the BAR and PCI command bit 1 set before enable it ....*/
72         {
73                 device_t dev;
74                 dev = dev_find_device(0x1166, 0x0205, 0);
75                 if(dev) {
76                         uint32_t dword;
77                         dword = pci_read_config32(dev, 0x6c);
78                         dword |= (1<<4); // enable interrupts
79                         pci_write_config32(dev, 0x6c, dword);
80
81                 }
82
83         }
84
85 //First pci-x slot (on bcm5785) under bus_bcm5785_1:d.0
86         for(i=0;i<4;i++) {
87                 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); //
88         }
89
90
91 //pci slot (on bcm5785)
92         for(i=0;i<4;i++) {
93                 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); //
94         }
95
96
97 //onboard ati
98         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_bcm5785_0, (5<<2)|0, apicid_bcm5785[1], 0x1);
99
100 //PCI-X on bcm5780
101         for(i=0;i<4;i++) {
102                 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); //
103         }
104
105         for(i=0;i<4;i++) {
106                 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); //
107         }
108
109 //onboard Broadcom
110         for(i=0;i<2;i++) {
111                 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); //
112         }
113
114
115 // First PCI-E x8
116         for(i=0;i<4;i++) {
117                 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_bcm5780[5], (0<<2)|i, apicid_bcm5785[1], 0xe); //
118         }
119
120
121 // Second PCI-E x8
122         for(i=0;i<4;i++) {
123                 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_bcm5780[3], (0<<2)|i, apicid_bcm5785[1], 0xc); //
124         }
125
126
127 // Third PCI-E x1
128         for(i=0;i<4;i++) {
129                 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_bcm5780[4], (0<<2)|i, apicid_bcm5785[1], 0xd); //
130         }
131
132 /*Local Ints:   Type    Polarity    Trigger     Bus ID   IRQ    APIC ID PIN#*/
133         mptable_lintsrc(mc, bus_isa);
134         /* There is no extension information... */
135
136         /* Compute the checksums */
137         return mptable_finalize(mc);
138 }
139
140 unsigned long write_smp_table(unsigned long addr)
141 {
142         void *v;
143         v = smp_write_floating_table(addr, 0);
144         return (unsigned long)smp_write_config_table(v);
145 }