AMD Rev F support
[coreboot.git] / src / mainboard / amd / serengeti_cheetah / 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 #if CONFIG_LOGICAL_CPUS==1
7 #include <cpu/amd/dualcore.h>
8 #endif
9
10 #include <cpu/amd/amdk8_sysconf.h>
11 #include "mb_sysconf.h"
12
13 extern void get_bus_conf(void);
14
15 void *smp_write_config_table(void *v)
16 {
17         static const char sig[4] = "PCMP";
18         static const char oem[8] = "AMD     ";
19         static const char productid[12] = "SERENGETI   ";
20         struct mp_config_table *mc;
21
22         unsigned char bus_num;
23         int i;
24         struct mb_sysconf_t *m;
25
26         mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
27         memset(mc, 0, sizeof(*mc));
28
29         memcpy(mc->mpc_signature, sig, sizeof(sig));
30         mc->mpc_length = sizeof(*mc); /* initially just the header */
31         mc->mpc_spec = 0x04;
32         mc->mpc_checksum = 0; /* not yet computed */
33         memcpy(mc->mpc_oem, oem, sizeof(oem));
34         memcpy(mc->mpc_productid, productid, sizeof(productid));
35         mc->mpc_oemptr = 0;
36         mc->mpc_oemsize = 0;
37         mc->mpc_entry_count = 0; /* No entries yet... */
38         mc->mpc_lapic = LAPIC_ADDR;
39         mc->mpe_length = 0;
40         mc->mpe_checksum = 0;
41         mc->reserved = 0;
42
43         smp_write_processors(mc);
44
45         get_bus_conf();
46
47         m = sysconf.mb;
48
49 /*Bus:          Bus ID  Type*/
50        /* define bus and isa numbers */
51         for(bus_num = 0; bus_num < m->bus_isa; bus_num++) {
52                 smp_write_bus(mc, bus_num, "PCI   ");
53         }
54         smp_write_bus(mc, m->bus_isa, "ISA   ");
55
56 /*I/O APICs:    APIC ID Version State           Address*/
57         smp_write_ioapic(mc, m->apicid_8111, 0x11, 0xfec00000); //8111
58         {
59                 device_t dev;
60                 struct resource *res;
61                 dev = dev_find_slot(m->bus_8132_0, PCI_DEVFN(m->sbdn3, 1));
62                 if (dev) {
63                         res = find_resource(dev, PCI_BASE_ADDRESS_0);
64                         if (res) {
65                                 smp_write_ioapic(mc, m->apicid_8132_1, 0x11, res->base);
66                         }
67                 }
68                 dev = dev_find_slot(m->bus_8132_0, PCI_DEVFN(m->sbdn3+1, 1));
69                 if (dev) {
70                         res = find_resource(dev, PCI_BASE_ADDRESS_0);
71                         if (res) {
72                                 smp_write_ioapic(mc, m->apicid_8132_2, 0x11, res->base);
73                         }
74                 }
75         }
76   
77 /*I/O Ints:     Type    Polarity    Trigger     Bus ID   IRQ    APIC ID PIN# */ 
78         smp_write_intsrc(mc, mp_ExtINT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, m->bus_isa, 0x0, m->apicid_8111, 0x0);
79         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  m->bus_isa, 0x1, m->apicid_8111, 0x1);
80         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  m->bus_isa, 0x0, m->apicid_8111, 0x2);
81         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  m->bus_isa, 0x3, m->apicid_8111, 0x3);
82         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  m->bus_isa, 0x4, m->apicid_8111, 0x4);
83         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  m->bus_isa, 0x5, m->apicid_8111, 0x5);
84         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  m->bus_isa, 0x6, m->apicid_8111, 0x6);
85         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  m->bus_isa, 0x7, m->apicid_8111, 0x7);
86         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  m->bus_isa, 0x8, m->apicid_8111, 0x8);
87         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  m->bus_isa, 0x9, m->apicid_8111, 0x9);
88         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  m->bus_isa, 0xc, m->apicid_8111, 0xc);
89         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  m->bus_isa, 0xd, m->apicid_8111, 0xd);
90         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  m->bus_isa, 0xe, m->apicid_8111, 0xe);
91         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH,  m->bus_isa, 0xf, m->apicid_8111, 0xf);
92 //??? What
93         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_8111_0, ((sysconf.sbdn+1)<<2)|3, m->apicid_8111, 0x13);
94
95 // Onboard AMD USB
96         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_8111_1, (0<<2)|3, m->apicid_8111, 0x13);
97
98         if(sysconf.pci1234[1] & 0xf) {
99         //  Slot AGP
100                 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_8151_1, 0x0, m->apicid_8111, 0x11);
101         }       
102
103 //Slot 3  PCI 32
104         for(i=0;i<4;i++) {
105                 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_8111_1, (5<<2)|i, m->apicid_8111, 0x10 + (1+i)%4); //16
106         }
107
108
109 //Slot 4 PCI 32
110         for(i=0;i<4;i++) {
111                 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_8111_1, (4<<2)|i, m->apicid_8111, 0x10 + (0+i)%4); //16
112         }
113
114
115 //Slot 1 PCI-X 133/100/66
116         for(i=0;i<4;i++) {
117                 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_8132_2, (1<<2)|i, m->apicid_8132_2, (0+i)%4); //
118         }
119
120
121 //Slot 2 PCI-X 133/100/66
122         for(i=0;i<4;i++) {
123                 smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, m->bus_8132_1, (1<<2)|i, m->apicid_8132_1, (1+i)%4); //25
124         }
125
126
127 /*Local Ints:   Type    Polarity    Trigger     Bus ID   IRQ    APIC ID PIN#*/
128         smp_write_intsrc(mc, mp_ExtINT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, m->bus_isa, 0x0, MP_APIC_ALL, 0x0);
129         smp_write_intsrc(mc, mp_NMI, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, m->bus_isa, 0x0, MP_APIC_ALL, 0x1);
130         /* There is no extension information... */
131
132         /* Compute the checksums */
133         mc->mpe_checksum = smp_compute_checksum(smp_next_mpc_entry(mc), mc->mpe_length);
134         mc->mpc_checksum = smp_compute_checksum(mc, mc->mpc_length);
135         printk_debug("Wrote the mp table end at: %p - %p\n",
136                 mc, smp_next_mpe_entry(mc));
137         return smp_next_mpe_entry(mc);
138 }
139
140 unsigned long write_smp_table(unsigned long addr)
141 {
142         void *v;
143         v = smp_write_floating_table(addr);
144         return (unsigned long)smp_write_config_table(v);
145 }