1164e7fa3dbaa28c274b0757adaa70e97f7e6b19
[coreboot.git] / src / mainboard / supermicro / x6dhr_ig / mptable.c
1 #include <console/console.h>
2 #include <arch/smp/mpspec.h>
3 #include <device/pci.h>
4 #include <string.h>
5 #include <stdint.h>
6
7 static void *smp_write_config_table(void *v)
8 {
9         static const char sig[4] = "PCMP";
10         static const char oem[8] = "COREBOOT";
11         static const char productid[12] = "X6DHR-iG    ";
12         struct mp_config_table *mc;
13         unsigned char bus_num;
14         unsigned char bus_isa;
15         unsigned char bus_pxhd_1;
16         unsigned char bus_pxhd_2;
17         unsigned char bus_pxhd_3;
18         unsigned char bus_pxhd_4;
19         unsigned char bus_ich5r_1;
20
21         mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
22         memset(mc, 0, sizeof(*mc));
23
24         memcpy(mc->mpc_signature, sig, sizeof(sig));
25         mc->mpc_length = sizeof(*mc); /* initially just the header */
26         mc->mpc_spec = 0x04;
27         mc->mpc_checksum = 0; /* not yet computed */
28         memcpy(mc->mpc_oem, oem, sizeof(oem));
29         memcpy(mc->mpc_productid, productid, sizeof(productid));
30         mc->mpc_oemptr = 0;
31         mc->mpc_oemsize = 0;
32         mc->mpc_entry_count = 0; /* No entries yet... */
33         mc->mpc_lapic = LAPIC_ADDR;
34         mc->mpe_length = 0;
35         mc->mpe_checksum = 0;
36         mc->reserved = 0;
37
38         smp_write_processors(mc);
39
40         {
41                 device_t dev;
42
43                 /* ich5r */
44                 dev = dev_find_slot(0, PCI_DEVFN(0x1e,0));
45                 if (dev) {
46                         bus_ich5r_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
47                         bus_isa    = pci_read_config8(dev, PCI_SUBORDINATE_BUS);
48                         bus_isa++;
49                 }
50                 else {
51                         printk(BIOS_DEBUG, "ERROR - could not find PCI 0:1f.0, using defaults\n");
52
53                         bus_ich5r_1 = 9;
54                         bus_isa = 10;
55                 }
56                 /* pxhd-1 */
57                 dev = dev_find_slot(2, PCI_DEVFN(0x0,0));
58                 if (dev) {
59                         bus_pxhd_1 = pci_read_config8(dev, PCI_SECONDARY_BUS);
60
61                 }
62                 else {
63                         printk(BIOS_DEBUG, "ERROR - could not find PCI 1:00.1, using defaults\n");
64
65                         bus_pxhd_1 = 3;
66                 }
67                 /* pxhd-2 */
68                 dev = dev_find_slot(2, PCI_DEVFN(0x00,2));
69                 if (dev) {
70                         bus_pxhd_2 = pci_read_config8(dev, PCI_SECONDARY_BUS);
71
72                 }
73                 else {
74                         printk(BIOS_DEBUG, "ERROR - could not find PCI 1:02.0, using defaults\n");
75
76                         bus_pxhd_2 = 4;
77                 }
78
79                 /* pxhd-3 */
80                 dev = dev_find_slot(5, PCI_DEVFN(0x0,0));
81                 if (dev) {
82                         bus_pxhd_3 = pci_read_config8(dev, PCI_SECONDARY_BUS);
83
84                 }
85                 else {
86                         printk(BIOS_DEBUG, "ERROR - could not find PCI 1:00.1, using defaults\n");
87
88                         bus_pxhd_3 = 6;
89                 }
90                 /* pxhd-4 */
91                 dev = dev_find_slot(5, PCI_DEVFN(0x00,2));
92                 if (dev) {
93                         bus_pxhd_4 = pci_read_config8(dev, PCI_SECONDARY_BUS);
94
95                 }
96                 else {
97                         printk(BIOS_DEBUG, "ERROR - could not find PCI 1:02.0, using defaults\n");
98
99                         bus_pxhd_4 = 7;
100                 }
101
102         }
103
104         /* define bus and isa numbers */
105         for(bus_num = 0; bus_num < bus_isa; bus_num++) {
106                 smp_write_bus(mc, bus_num, "PCI   ");
107         }
108         smp_write_bus(mc, bus_isa, "ISA   ");
109
110         /* IOAPIC handling */
111
112         smp_write_ioapic(mc, 2, 0x20, 0xfec00000);
113         {
114                 struct resource *res;
115                 device_t dev;
116                 /* pxhd apic 3 */
117                 dev = dev_find_slot(2, PCI_DEVFN(0x00,1));
118                 if (dev) {
119                         res = find_resource(dev, PCI_BASE_ADDRESS_0);
120                         if (res) {
121                                 smp_write_ioapic(mc, 0x03, 0x20, res->base);
122                         }
123                 }
124                 else {
125                         printk(BIOS_DEBUG, "ERROR - could not find IOAPIC PCI 2:00.1\n");
126                 }
127                 /* pxhd apic 4 */
128                 dev = dev_find_slot(2, PCI_DEVFN(0x00,3));
129                 if (dev) {
130                         res = find_resource(dev, PCI_BASE_ADDRESS_0);
131                         if (res) {
132                                 smp_write_ioapic(mc, 0x04, 0x20, res->base);
133                         }
134                 }
135                 else {
136                         printk(BIOS_DEBUG, "ERROR - could not find IOAPIC PCI 2:00.3\n");
137                 }
138                 /* pxhd apic 5 */
139                 dev = dev_find_slot(5, PCI_DEVFN(0x00,1));
140                 if (dev) {
141                         res = find_resource(dev, PCI_BASE_ADDRESS_0);
142                         if (res) {
143                                 smp_write_ioapic(mc, 0x05, 0x20, res->base);
144                         }
145                 }
146                 else {
147                         printk(BIOS_DEBUG, "ERROR - could not find IOAPIC PCI 5:00.1\n");
148                 }
149                 /* pxhd apic 8 */
150                 dev = dev_find_slot(5, PCI_DEVFN(0x00,3));
151                 if (dev) {
152                         res = find_resource(dev, PCI_BASE_ADDRESS_0);
153                         if (res) {
154                                 smp_write_ioapic(mc, 0x08, 0x20, res->base);
155                         }
156                 }
157                 else {
158                         printk(BIOS_DEBUG, "ERROR - could not find IOAPIC PCI 5:00.3\n");
159                 }
160         }
161
162         mptable_add_isa_interrupts(mc, bus_isa, 0x2, 0);
163
164         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
165                 0x00, 0x74, 0x02, 0x10);
166         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
167                 0x00, 0x76, 0x02, 0x12);
168         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
169                 0x00, 0x77, 0x02, 0x17);
170         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
171                 0x00, 0x75, 0x02, 0x13);
172         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
173                 0x00, 0x74, 0x02, 0x10);
174         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
175                 0x00, 0x7c, 0x02, 0x12);
176         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
177                 0x00, 0x7d, 0x02, 0x11);
178         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
179                 bus_pxhd_2, 0x08, 0x04, 0x06);
180         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
181                 bus_pxhd_2, 0x09, 0x04, 0x07);
182         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
183                 bus_pxhd_3, 0x08, 0x05, 0x00);
184         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
185                 bus_pxhd_4, 0x08, 0x08, 0x00);
186         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,
187                 (bus_isa - 1), 0x04, 0x02, 0x10);
188
189         /* Standard local interrupt assignments */
190         smp_write_lintsrc(mc, mp_ExtINT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,
191                 bus_isa, 0x00, MP_APIC_ALL, 0x00);
192         smp_write_lintsrc(mc, mp_NMI, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,
193                 bus_isa, 0x00, MP_APIC_ALL, 0x01);
194
195         /* There is no extension information... */
196
197         /* Compute the checksums */
198         mc->mpe_checksum = smp_compute_checksum(smp_next_mpc_entry(mc), mc->mpe_length);
199
200         mc->mpc_checksum = smp_compute_checksum(mc, mc->mpc_length);
201         printk(BIOS_DEBUG, "Wrote the mp table end at: %p - %p\n",
202                 mc, smp_next_mpe_entry(mc));
203         return smp_next_mpe_entry(mc);
204 }
205
206 unsigned long write_smp_table(unsigned long addr)
207 {
208         void *v;
209         v = smp_write_floating_table(addr);
210         return (unsigned long)smp_write_config_table(v);
211 }
212