printk_foo -> printk(BIOS_FOO, ...)
[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/dualcore.h>
9 #endif
10
11 #include <cpu/amd/amdk8_sysconf.h>
12
13 extern  unsigned char bus_isa;
14 extern  unsigned char bus_bcm5780[7];
15 extern  unsigned char bus_bcm5785_0;
16 extern  unsigned char bus_bcm5785_1;
17 extern  unsigned char bus_bcm5785_1_1;
18 extern  unsigned apicid_bcm5785[3];
19
20 extern  unsigned sbdn2;
21
22 extern void get_bus_conf(void);
23
24 void *smp_write_config_table(void *v)
25 {
26         static const char sig[4] = "PCMP";
27         static const char oem[8] = "BROADCOM";
28         static const char productid[12] = "BLAST       ";
29         struct mp_config_table *mc;
30
31         unsigned char bus_num;
32         int i;
33
34         mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
35         memset(mc, 0, sizeof(*mc));
36
37         memcpy(mc->mpc_signature, sig, sizeof(sig));
38         mc->mpc_length = sizeof(*mc); /* initially just the header */
39         mc->mpc_spec = 0x04;
40         mc->mpc_checksum = 0; /* not yet computed */
41         memcpy(mc->mpc_oem, oem, sizeof(oem));
42         memcpy(mc->mpc_productid, productid, sizeof(productid));
43         mc->mpc_oemptr = 0;
44         mc->mpc_oemsize = 0;
45         mc->mpc_entry_count = 0; /* No entries yet... */
46         mc->mpc_lapic = LAPIC_ADDR;
47         mc->mpe_length = 0;
48         mc->mpe_checksum = 0;
49         mc->reserved = 0;
50
51         smp_write_processors(mc);
52
53         get_bus_conf();
54
55 /*Bus:          Bus ID  Type*/
56        /* define bus and isa numbers */
57         for(bus_num = 0; bus_num < bus_isa; bus_num++) {
58                 smp_write_bus(mc, bus_num, "PCI   ");
59         }
60         smp_write_bus(mc, bus_isa, "ISA   ");
61
62 /*I/O APICs:    APIC ID Version State           Address*/
63         {
64                 device_t dev = 0;
65                 int i;
66                 struct resource *res;
67                 for(i=0; i<3; i++) {
68                         dev = dev_find_device(0x1166, 0x0235, dev);
69                         if (dev) {
70                                 res = find_resource(dev, PCI_BASE_ADDRESS_0);
71                                 if (res) {
72                                         smp_write_ioapic(mc, apicid_bcm5785[i], 0x11, res->base);
73                                 }
74                         }
75                 }
76                 
77         }
78         
79 /*I/O Ints:     Type    Polarity    Trigger     Bus ID   IRQ    APIC ID PIN# */
80         smp_write_intsrc(mc, mp_ExtINT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, bus_isa, 0x0, apicid_bcm5785[0], 0x0);
81         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  bus_isa, 0x1, apicid_bcm5785[0], 0x1); 
82         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  bus_isa, 0x0, apicid_bcm5785[0], 0x2);
83         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  bus_isa, 0x3, apicid_bcm5785[0], 0x3);
84         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  bus_isa, 0x4, apicid_bcm5785[0], 0x4);
85         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  bus_isa, 0x5, apicid_bcm5785[0], 0x5);
86         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  bus_isa, 0x6, apicid_bcm5785[0], 0x6);
87         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  bus_isa, 0x7, apicid_bcm5785[0], 0x7);
88         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  bus_isa, 0x8, apicid_bcm5785[0], 0x8);
89         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  bus_isa, 0x9, apicid_bcm5785[0], 0x9);
90         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  bus_isa, 0xc, apicid_bcm5785[0], 0xc);
91         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  bus_isa, 0xd, apicid_bcm5785[0], 0xd);
92
93 //IDE   
94         outb(0x02, 0xc00); outb(0x0e, 0xc01);
95
96         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
97
98 //SATA
99         outb(0x07, 0xc00); outb(0x0f, 0xc01);
100         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_bcm5785_1, (0x0e<<2)|0, apicid_bcm5785[0], 0xf);
101         
102 //USB
103         outb(0x01, 0xc00); outb(0x0a, 0xc01);
104         for(i=0;i<3;i++) {
105                 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); //
106         }
107
108         
109
110         /* enable int */
111         /* why here? must get the BAR and PCI command bit 1 set before enable it ....*/
112         {
113                 device_t dev;
114                 dev = dev_find_device(0x1166, 0x0205, 0);
115                 if(dev) {
116                         uint32_t dword;
117                         dword = pci_read_config32(dev, 0x6c);
118                         dword |= (1<<4); // enable interrupts
119                         pci_write_config32(dev, 0x6c, dword);
120
121                 }
122
123         }
124
125 //First pci-x slot (on bcm5785) under bus_bcm5785_1:d.0
126         for(i=0;i<4;i++) {
127                 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); //
128         }
129
130
131 //pci slot (on bcm5785)  
132         for(i=0;i<4;i++) {
133                 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); //
134         }
135
136
137 //onboard ati 
138         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_bcm5785_0, (5<<2)|0, apicid_bcm5785[1], 0x1);
139
140 //PCI-X on bcm5780
141         for(i=0;i<4;i++) {
142                 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); //
143         }
144
145         for(i=0;i<4;i++) {
146                 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); //
147         }
148
149 //onboard Broadcom
150         for(i=0;i<2;i++) {
151                 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); //
152         }
153
154
155 // First PCI-E x8
156         for(i=0;i<4;i++) {
157                 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_bcm5780[5], (0<<2)|i, apicid_bcm5785[1], 0xe); //
158         }
159
160
161 // Second PCI-E x8 
162         for(i=0;i<4;i++) {
163                 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_bcm5780[3], (0<<2)|i, apicid_bcm5785[1], 0xc); //
164         }
165
166
167 // Third PCI-E x1
168         for(i=0;i<4;i++) {
169                 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_bcm5780[4], (0<<2)|i, apicid_bcm5785[1], 0xd); //
170         }
171
172 /*Local Ints:   Type    Polarity    Trigger     Bus ID   IRQ    APIC ID PIN#*/
173         smp_write_intsrc(mc, mp_ExtINT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, bus_isa, 0x0, MP_APIC_ALL, 0x0);
174         smp_write_intsrc(mc, mp_NMI, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, bus_isa, 0x0, MP_APIC_ALL, 0x1);
175         /* There is no extension information... */
176
177         /* Compute the checksums */
178         mc->mpe_checksum = smp_compute_checksum(smp_next_mpc_entry(mc), mc->mpe_length);
179         mc->mpc_checksum = smp_compute_checksum(mc, mc->mpc_length);
180         printk(BIOS_DEBUG, "Wrote the mp table end at: %p - %p\n",
181                 mc, smp_next_mpe_entry(mc));
182         return smp_next_mpe_entry(mc);
183 }
184
185 unsigned long write_smp_table(unsigned long addr)
186 {
187         void *v;
188         v = smp_write_floating_table(addr);
189         return (unsigned long)smp_write_config_table(v);
190 }