5d13701f5a87b8b0e8065c1845bfa3200254255c
[coreboot.git] / src / mainboard / nvidia / l1_2pvv / mptable.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2007 AMD
5  * Written by Yinghai Lu <yinghailu@amd.com> for AMD.
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
20  */
21
22 #include <console/console.h>
23 #include <arch/smp/mpspec.h>
24 #include <device/pci.h>
25 #include <string.h>
26 #include <stdint.h>
27 #include <cpu/amd/amdk8_sysconf.h>
28 #include "mb_sysconf.h"
29
30 static void *smp_write_config_table(void *v)
31 {
32         struct mp_config_table *mc;
33         struct mb_sysconf_t *m;
34         unsigned sbdn;
35         int i, j, bus_isa;
36         unsigned char apicpin[4];
37
38         mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
39
40         mptable_init(mc, LAPIC_ADDR);
41
42         smp_write_processors(mc);
43
44         get_bus_conf();
45         sbdn = sysconf.sbdn;
46         m = sysconf.mb;
47
48         mptable_write_buses(mc, NULL, &bus_isa);
49
50 /*I/O APICs:    APIC ID Version State           Address*/
51         {
52                 device_t dev;
53                 struct resource *res;
54                 uint32_t dword;
55
56                 dev = dev_find_slot(m->bus_mcp55, PCI_DEVFN(sbdn+ 0x1,0));
57                 if (dev) {
58                         res = find_resource(dev, PCI_BASE_ADDRESS_1);
59                         if (res)
60                                 smp_write_ioapic(mc, m->apicid_mcp55, 0x11, res->base);
61
62                 /* Initialize interrupt mapping*/
63                         dword = pci_read_config32(dev, 0x74);
64                         dword &= ~(1<<15);
65                         dword |= 1<<2;
66                         pci_write_config32(dev, 0x74, dword);
67
68                         dword = 0x43c6c643;
69                         pci_write_config32(dev, 0x7c, dword);
70
71                         dword = 0x81001a00;
72                         pci_write_config32(dev, 0x80, dword);
73
74                         dword = 0xd00012d2;
75                         pci_write_config32(dev, 0x84, dword);
76
77                 }
78
79             if (m->bus_mcp55b) {
80                 dev = dev_find_slot(m->bus_mcp55b, PCI_DEVFN(m->sbdnb + 0x1,0));
81                 if (dev) {
82                         res = find_resource(dev, PCI_BASE_ADDRESS_1);
83                         if (res)
84                                 smp_write_ioapic(mc, m->apicid_mcp55b, 0x11, res->base);
85
86                         dword = 0x43c60000;
87                         pci_write_config32(dev, 0x7c, dword);
88
89                         dword = 0x81000000;
90                         pci_write_config32(dev, 0x80, dword);
91
92                         dword = 0xd00002d0;
93                         pci_write_config32(dev, 0x84, dword);
94
95                 }
96
97             }
98
99         }
100
101         mptable_add_isa_interrupts(mc, bus_isa, m->apicid_mcp55, 0);
102
103         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_mcp55, ((sbdn+1)<<2)|1, m->apicid_mcp55, 0xa); // 10
104
105         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_mcp55, ((sbdn+2)<<2)|0, m->apicid_mcp55, 0x16); // 22
106
107         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_mcp55, ((sbdn+2)<<2)|1, m->apicid_mcp55, 0x17); // 23
108
109         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_mcp55, ((sbdn+6)<<2)|1, m->apicid_mcp55, 0x17); // 23
110
111         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_mcp55, ((sbdn+5)<<2)|0, m->apicid_mcp55, 0x14); // 20
112         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_mcp55, ((sbdn+5)<<2)|1, m->apicid_mcp55, 0x17); // 23
113         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_mcp55, ((sbdn+5)<<2)|2, m->apicid_mcp55, 0x15); // 21
114
115         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_mcp55, ((sbdn+8)<<2)|0, m->apicid_mcp55, 0x16); // 22
116         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_mcp55, ((sbdn+9)<<2)|0, m->apicid_mcp55, 0x15); // 21
117
118 //Slot PCIE
119         for (j = 2; j < 8; j++) {
120                 device_t dev;
121                 dev = dev_find_slot(m->bus_mcp55, PCI_DEVFN(sbdn + 0x0a + j - 2 , 0));
122                 if (!dev || !dev->enabled)
123                         continue;
124                 for (i = 0; i < 4; i++)
125                         apicpin[i] = 0x10 + (2+j+i+4-sbdn%4)%4;
126                 smp_write_intsrc_pci_bridge(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, dev, m->apicid_mcp55, apicpin);
127         }
128
129 //Slot PCI 32
130         {
131                 device_t dev;
132                 dev = dev_find_slot(m->bus_mcp55, PCI_DEVFN(sbdn + 6 , 0));
133                 if (dev && dev->enabled) {
134                         for (i = 0; i < 4; i++)
135                                 apicpin[i] = 0x10 + (2+i)%4;
136                         smp_write_intsrc_pci_bridge(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, dev, m->apicid_mcp55, apicpin);
137                 }
138         }
139
140         if (m->bus_mcp55b) {
141                 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_mcp55b, ((m->sbdnb+5)<<2)|0, m->apicid_mcp55b, 0x14); // 20
142                 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_mcp55b, ((m->sbdnb+5)<<2)|1, m->apicid_mcp55b, 0x17); // 23
143                 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_mcp55b, ((m->sbdnb+5)<<2)|2, m->apicid_mcp55b, 0x15); // 21
144
145                 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_mcp55b, ((m->sbdnb+8)<<2)|0, m->apicid_mcp55b, 0x16); // 22
146                 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_mcp55b, ((m->sbdnb+9)<<2)|0, m->apicid_mcp55b, 0x15); // 21
147
148
149         //Slot  PCIE
150                 for (j = 2; j < 8; j++) {
151                         device_t dev;
152                         dev = dev_find_slot(m->bus_mcp55b, PCI_DEVFN(m->sbdnb + 0x0a + j - 2 , 0));
153                         if (!dev || !dev->enabled)
154                                 continue;
155                         for (i = 0; i < 4; i++) {
156                                 apicpin[i] = 0x10 + (2+j+i+4-m->sbdnb%4)%4;
157                         }
158                         smp_write_intsrc_pci_bridge(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, dev, m->apicid_mcp55b, apicpin);
159                 }
160
161         }
162
163 /*Local Ints:   Type    Polarity    Trigger     Bus ID   IRQ    APIC ID PIN#*/
164         mptable_lintsrc(mc, bus_isa);
165         /* There is no extension information... */
166
167         /* Compute the checksums */
168         return mptable_finalize(mc);
169 }
170
171 unsigned long write_smp_table(unsigned long addr)
172 {
173         void *v;
174         v = smp_write_floating_table(addr, 0);
175         return (unsigned long)smp_write_config_table(v);
176 }