22715394ab044dac4001b31102c6ab814c2f63bc
[coreboot.git] / src / mainboard / hp / dl145_g3 / mptable.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2001 Eric W.Biederman<ebiderman@lnxi.com>
5  *
6  * Copyright (C) 2006 AMD
7  * Written by Yinghai Lu <yinghailu@gmail.com> for AMD.
8  *
9  * Copyright (C) 2007 University of Mannheim
10  * Written by Philipp Degler <pdegler@rumms.uni-mannheim.e> for Uni of Mannheim
11  *
12  * Copyright (C) 2009 University of Heidelberg
13  * Written by Mondrian Nuessle <nuessle@uni-hd.de> for Uni of Heidelberg
14  *
15  * This program is free software; you can redistribute it and/or modify
16  * it under the terms of the GNU General Public License as published by
17  * the Free Software Foundation; either version 2 of the License, or
18  * (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, write to the Free Software
27  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
28  */
29
30 #include <console/console.h>
31 #include <arch/smp/mpspec.h>
32 #include <arch/io.h>
33 #include <device/pci.h>
34 #include <string.h>
35 #include <stdint.h>
36 #if CONFIG_LOGICAL_CPUS==1
37 #include <cpu/amd/dualcore.h>
38 #endif
39
40 #include <cpu/amd/amdk8_sysconf.h>
41
42 #include "mb_sysconf.h"
43
44 extern void get_bus_conf(void);
45
46 void *smp_write_config_table(void *v)
47 {
48         static const char sig[4] = "PCMP";
49         static const char oem[8] = "HP      ";
50         static const char productid[12] = "TREX        ";
51         struct mp_config_table *mc;
52
53         unsigned char bus_num;
54         int i;
55         struct mb_sysconf_t *m;
56
57         mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
58         memset(mc, 0, sizeof(*mc));
59
60         memcpy(mc->mpc_signature, sig, sizeof(sig));
61         mc->mpc_length = sizeof(*mc); /* initially just the header */
62         mc->mpc_spec = 0x04;
63         mc->mpc_checksum = 0; /* not yet computed */
64         memcpy(mc->mpc_oem, oem, sizeof(oem));
65         memcpy(mc->mpc_productid, productid, sizeof(productid));
66         mc->mpc_oemptr = 0;
67         mc->mpc_oemsize = 0;
68         mc->mpc_entry_count = 0; /* No entries yet... */
69         mc->mpc_lapic = LAPIC_ADDR;
70         mc->mpe_length = 0;
71         mc->mpe_checksum = 0;
72         mc->reserved = 0;
73
74         smp_write_processors(mc);
75
76         get_bus_conf();
77         m = sysconf.mb;
78
79         /*Bus:         Bus ID  Type*/
80         /* define bus and isa numbers */
81 /*      for(bus_num = 0; bus_num < m->bus_isa; bus_num++) {
82                 smp_write_bus(mc, bus_num, "PCI   ");
83                 printk_debug("writing bus %d as PCI...\n",bus_num);
84         }
85         */
86         smp_write_bus(mc, 0, "PCI   ");
87         smp_write_bus(mc, 1, "PCI   ");
88         smp_write_bus(mc, 7, "PCI   ");
89         smp_write_bus(mc, 8, "PCI   ");
90
91         smp_write_bus(mc,m->bus_isa, "ISA   ");
92         printk_debug("writing %d as ISA...\n",m->bus_isa);
93
94         /*I/O APICs:   APIC ID Version State           Address*/
95         {
96                 device_t dev = 0;
97                 int i;
98                 struct resource *res;
99                 for(i=0; i<3; i++) {
100                         dev = dev_find_device(0x1166, 0x0235, dev);
101                         if (dev) {
102                                 res = find_resource(dev, PCI_BASE_ADDRESS_0);
103                                 if (res) {
104                                         printk_debug("APIC %d base address: %x\n",m->apicid_bcm5785[i],  res->base);
105                                         smp_write_ioapic(mc, m->apicid_bcm5785[i], 0x11, res->base);
106                                 }
107                         }
108                 }
109
110         }
111
112         /* IRQ routing as factory BIOS */
113         outb(0x01, 0xc00); outb(0x0A, 0xc01);
114         outb(0x17, 0xc00); outb(0x05, 0xc01);
115 /*      outb(0x2E, 0xc00); outb(0x0B, 0xc01); */
116 /*      outb(0x07, 0xc00); outb(0x07, 0xc01); */
117         outb(0x07, 0xc00); outb(0x0b, 0xc01);
118
119         outb(0x24, 0xc00); outb(0x05, 0xc01);
120         //outb(0x00, 0xc00); outb(0x09, 0xc01);
121         outb(0x02, 0xc00); outb(0x0E, 0xc01);
122
123         // 8259 registers...
124         outb(0xa0, 0x4d0);
125         outb(0x0e, 0x4d1);
126
127         {
128                 device_t dev;
129                 dev = dev_find_device(0x1166, 0x0205, 0);
130                 if(dev) {
131                         uint32_t dword;
132                         dword = pci_read_config32(dev, 0x64);
133                         dword |= (1<<30); // GEVENT14-21 used as PCI IRQ0-7
134                         pci_write_config32(dev, 0x64, dword);
135                 }
136                 // set GEVENT pins to NO OP
137                 outb(0x33, 0xcd6); outb(0x00, 0xcd7);
138                 outb(0x34, 0xcd6); outb(0x00, 0xcd7);
139                 outb(0x35, 0xcd6); outb(0x00, 0xcd7);
140         }
141
142         // hide XIOAPIC PCI configuration space
143         {
144                 device_t dev;
145                 dev = dev_find_device(0x1166, 0x205, 0);
146                 if (dev) {
147                         uint32_t dword;
148                         dword = pci_read_config32(dev, 0x64);
149                         dword |= (1<<26);
150                         pci_write_config32(dev, 0x64, dword);
151                 }
152         }
153
154 /*I/O Ints:    Type    Polarity    Trigger     Bus ID   IRQ    APIC ID PIN# */
155         smp_write_intsrc(mc, mp_ExtINT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_HIGH, m->bus_isa, 0x0, m->apicid_bcm5785[0], 0x0);
156         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  m->bus_isa, 0x1, m->apicid_bcm5785[0], 0x1);
157         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  m->bus_isa, 0x0, m->apicid_bcm5785[0], 0x2);
158         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  m->bus_isa, 0x3, m->apicid_bcm5785[0], 0x3);
159         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  m->bus_isa, 0x4, m->apicid_bcm5785[0], 0x4);
160         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  m->bus_isa, 0x5, m->apicid_bcm5785[0], 0x5);
161         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  m->bus_isa, 0x6, m->apicid_bcm5785[0], 0x6);
162         //SATA
163 /*      printk_debug("MPTABLE_SATA: bus_id:%d irq:%d apic_id:%d pin:%d\n",m->bus_bcm5785_1, (0x0e<<2)|0, m->apicid_bcm5785[0], 0x7); */
164 /*      smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_bcm5785_1, (0x0e<<2)|0, m->apicid_bcm5785[0], 0x7); */
165         printk_debug("MPTABLE_SATA: bus_id:%d irq:%d apic_id:%d pin:%d\n",m->bus_bcm5785_1, (0x0e<<2)|0, m->apicid_bcm5785[0], 0xb);
166         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_bcm5785_1, (0x0e<<2)|0, m->apicid_bcm5785[0], 0xb);
167         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  m->bus_isa, 0x8, m->apicid_bcm5785[0], 0x8);
168         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  m->bus_isa, 0x9, m->apicid_bcm5785[0], 0x9);
169         //USB
170         printk_debug("sysconf.sbdn: %d on bus: %x \n",sysconf.sbdn, m->bus_bcm5785_0);
171         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_bcm5785_0, (0x03<<2)|0, m->apicid_bcm5785[0], 0xa);
172
173         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  m->bus_isa, 0xb, m->apicid_bcm5785[0], 0xb);
174         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  m->bus_isa, 0xc, m->apicid_bcm5785[0], 0xc);
175         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  m->bus_isa, 0xd, m->apicid_bcm5785[0], 0xd);
176         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  m->bus_isa, 0xe, m->apicid_bcm5785[0], 0xe);
177         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  m->bus_isa, 0xf, m->apicid_bcm5785[0], 0xf);
178
179         //VGA
180         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_bcm5785_0, (0x4<<2)|0, m->apicid_bcm5785[1], 0x7);
181
182         //PCIE
183         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_bcm5785_0, (0x6<<2)|0, m->apicid_bcm5785[2], 0xe);
184         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_bcm5785_0, (0x7<<2)|0, m->apicid_bcm5785[2], 0xe);
185         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_bcm5785_0, (0x8<<2)|0, m->apicid_bcm5785[2], 0xe);
186         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_bcm5785_0, (0x9<<2)|0, m->apicid_bcm5785[2], 0xe);
187         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_bcm5785_0, (0xa<<2)|0, m->apicid_bcm5785[2], 0xe);
188
189         //IDE
190 //      outb(0x02, 0xc00); outb(0x0e, 0xc01);
191 //      printk_debug("MPTABLE_IDE: bus_id:%d irq:%d apic_id:%d pin:%d\n",m->bus_bcm5785_0, ((1+sysconf.sbdn)<<2)|1, m->apicid_bcm5785[0], 0xe);
192 //              smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  m->bus_bcm5785_0, (0x02<<2)|1, m->apicid_bcm5785[0], 0xe);
193
194         //onboard Broadcom GbE
195         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,8, (4<<2)|0, m->apicid_bcm5785[2], 0x4);
196         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW,8, (4<<2)|1, m->apicid_bcm5785[2], 0x4);
197
198
199
200         /* enable int */
201         /* why here? must get the BAR and PCI command bit 1 set before enable it ....*/
202         {
203                 device_t dev;
204                 dev = dev_find_device(0x1166, 0x0205, 0);
205                 if(dev) {
206                         uint32_t dword;
207                         dword = pci_read_config32(dev, 0x6c);
208                         dword |= (1<<4); // enable interrupts
209                         printk_debug("6ch: %x\n",dword);
210                         pci_write_config32(dev, 0x6c, dword);
211                 }
212         }
213
214 /*Local Ints:  Type    Polarity    Trigger     Bus ID   IRQ    APIC ID PIN#*/
215         printk_debug("m->bus_isa is: %x\n",m->bus_isa);
216         smp_write_intsrc(mc, mp_ExtINT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, m->bus_isa, 0x0, MP_APIC_ALL, 0x0);
217         smp_write_intsrc(mc, mp_NMI, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, m->bus_isa , 0x0, MP_APIC_ALL, 0x1);
218
219         //extended table entries
220         smp_write_address_space(mc,0 , ADDRESS_TYPE_IO, 0x0, 0x0, 0x0, 0x0001);
221         smp_write_address_space(mc,0 , ADDRESS_TYPE_MEM, 0x0, 0x7f80, 0x0, 0x5e80);
222         smp_write_address_space(mc,0 , ADDRESS_TYPE_PREFETCH, 0x0, 0xde00, 0x0, 0x0100);
223         smp_write_address_space(mc,0 , ADDRESS_TYPE_MEM, 0x0, 0xdf00, 0x0, 0x1fe0);
224         smp_write_address_space(mc,0 , ADDRESS_TYPE_MEM, 0x1000, 0xfee0, 0xf000, 0x011f);
225         smp_write_address_space(mc,0 , ADDRESS_TYPE_MEM, 0x0, 0x000a, 0x0, 0x0006);
226         smp_write_bus_hierarchy(mc, 9, 0x01, 0);
227         smp_write_compatibility_address_space(mc, 0, ADDRESS_RANGE_ADD, 0);
228         smp_write_compatibility_address_space(mc, 0, ADDRESS_RANGE_ADD, 1);
229
230
231         /* Compute the checksums */
232         mc->mpe_checksum = smp_compute_checksum(smp_next_mpc_entry(mc), mc->mpe_length);
233         mc->mpc_checksum = smp_compute_checksum(mc, mc->mpc_length);
234         printk_debug("Wrote the mp table end at: %p - %p\n",
235                 mc, smp_next_mpe_entry(mc));
236         return smp_next_mpe_entry(mc);
237 }
238
239 unsigned long write_smp_table(unsigned long addr)
240 {
241         void *v;
242         v = smp_write_floating_table(addr);
243         return (unsigned long)smp_write_config_table(v);
244 }