143138d012c0e0397204441f951780fc1c6bb8bf
[coreboot.git] / src / mainboard / supermicro / x6dhr_ig / mptable.c
1 #include <console/console.h>
2 #include <arch/smp/mpspec.h>
3 #include <arch/ioapic.h>
4 #include <device/pci.h>
5 #include <string.h>
6 #include <stdint.h>
7
8 static void *smp_write_config_table(void *v)
9 {
10         struct mp_config_table *mc;
11         int bus_isa;
12         unsigned char bus_pxhd_1;
13         unsigned char bus_pxhd_2;
14         unsigned char bus_pxhd_3;
15         unsigned char bus_pxhd_4;
16         unsigned char bus_ich5r_1;
17
18         mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
19
20         mptable_init(mc, LAPIC_ADDR);
21
22         smp_write_processors(mc);
23
24         {
25                 device_t dev;
26
27                 /* ich5r */
28                 dev = dev_find_slot(0, PCI_DEVFN(0x1e,0));
29                 if (dev) {
30                         bus_ich5r_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
31                 }
32                 else {
33                         printk(BIOS_DEBUG, "ERROR - could not find PCI 0:1f.0, using defaults\n");
34
35                         bus_ich5r_1 = 9;
36                 }
37                 /* pxhd-1 */
38                 dev = dev_find_slot(2, PCI_DEVFN(0x0,0));
39                 if (dev) {
40                         bus_pxhd_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
41
42                 }
43                 else {
44                         printk(BIOS_DEBUG, "ERROR - could not find PCI 1:00.1, using defaults\n");
45
46                         bus_pxhd_1 = 3;
47                 }
48                 /* pxhd-2 */
49                 dev = dev_find_slot(2, PCI_DEVFN(0x00,2));
50                 if (dev) {
51                         bus_pxhd_2 = pci_read_config8(dev, PCI_SECONDARY_BUS);
52
53                 }
54                 else {
55                         printk(BIOS_DEBUG, "ERROR - could not find PCI 1:02.0, using defaults\n");
56
57                         bus_pxhd_2 = 4;
58                 }
59
60                 /* pxhd-3 */
61                 dev = dev_find_slot(5, PCI_DEVFN(0x0,0));
62                 if (dev) {
63                         bus_pxhd_3 = pci_read_config8(dev, PCI_SECONDARY_BUS);
64
65                 }
66                 else {
67                         printk(BIOS_DEBUG, "ERROR - could not find PCI 1:00.1, using defaults\n");
68
69                         bus_pxhd_3 = 6;
70                 }
71                 /* pxhd-4 */
72                 dev = dev_find_slot(5, PCI_DEVFN(0x00,2));
73                 if (dev) {
74                         bus_pxhd_4 = pci_read_config8(dev, PCI_SECONDARY_BUS);
75
76                 }
77                 else {
78                         printk(BIOS_DEBUG, "ERROR - could not find PCI 1:02.0, using defaults\n");
79
80                         bus_pxhd_4 = 7;
81                 }
82
83         }
84
85         mptable_write_buses(mc, NULL, &bus_isa);
86
87         /* IOAPIC handling */
88
89         smp_write_ioapic(mc, 2, 0x20, IO_APIC_ADDR);
90         {
91                 struct resource *res;
92                 device_t dev;
93                 /* pxhd apic 3 */
94                 dev = dev_find_slot(2, PCI_DEVFN(0x00,1));
95                 if (dev) {
96                         res = find_resource(dev, PCI_BASE_ADDRESS_0);
97                         if (res) {
98                                 smp_write_ioapic(mc, 0x03, 0x20, res->base);
99                         }
100                 }
101                 else {
102                         printk(BIOS_DEBUG, "ERROR - could not find IOAPIC PCI 2:00.1\n");
103                 }
104                 /* pxhd apic 4 */
105                 dev = dev_find_slot(2, PCI_DEVFN(0x00,3));
106                 if (dev) {
107                         res = find_resource(dev, PCI_BASE_ADDRESS_0);
108                         if (res) {
109                                 smp_write_ioapic(mc, 0x04, 0x20, res->base);
110                         }
111                 }
112                 else {
113                         printk(BIOS_DEBUG, "ERROR - could not find IOAPIC PCI 2:00.3\n");
114                 }
115                 /* pxhd apic 5 */
116                 dev = dev_find_slot(5, PCI_DEVFN(0x00,1));
117                 if (dev) {
118                         res = find_resource(dev, PCI_BASE_ADDRESS_0);
119                         if (res) {
120                                 smp_write_ioapic(mc, 0x05, 0x20, res->base);
121                         }
122                 }
123                 else {
124                         printk(BIOS_DEBUG, "ERROR - could not find IOAPIC PCI 5:00.1\n");
125                 }
126                 /* pxhd apic 8 */
127                 dev = dev_find_slot(5, PCI_DEVFN(0x00,3));
128                 if (dev) {
129                         res = find_resource(dev, PCI_BASE_ADDRESS_0);
130                         if (res) {
131                                 smp_write_ioapic(mc, 0x08, 0x20, res->base);
132                         }
133                 }
134                 else {
135                         printk(BIOS_DEBUG, "ERROR - could not find IOAPIC PCI 5:00.3\n");
136                 }
137         }
138
139         mptable_add_isa_interrupts(mc, bus_isa, 0x2, 0);
140
141         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
142                 0x00, 0x74, 0x02, 0x10);
143         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
144                 0x00, 0x76, 0x02, 0x12);
145         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
146                 0x00, 0x77, 0x02, 0x17);
147         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
148                 0x00, 0x75, 0x02, 0x13);
149         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
150                 0x00, 0x74, 0x02, 0x10);
151         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
152                 0x00, 0x7c, 0x02, 0x12);
153         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
154                 0x00, 0x7d, 0x02, 0x11);
155         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
156                 bus_pxhd_2, 0x08, 0x04, 0x06);
157         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
158                 bus_pxhd_2, 0x09, 0x04, 0x07);
159         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
160                 bus_pxhd_3, 0x08, 0x05, 0x00);
161         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
162                 bus_pxhd_4, 0x08, 0x08, 0x00);
163         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
164                 (bus_isa - 1), 0x04, 0x02, 0x10);
165
166         /* Standard local interrupt assignments */
167         mptable_lintsrc(mc, bus_isa);
168
169         /* There is no extension information... */
170
171         /* Compute the checksums */
172         return mptable_finalize(mc);
173 }
174
175 unsigned long write_smp_table(unsigned long addr)
176 {
177         void *v;
178         v = smp_write_floating_table(addr, 0);
179         return (unsigned long)smp_write_config_table(v);
180 }
181