8e760576474faae504c898a875a1584df4b5d41d
[coreboot.git] / src / mainboard / hp / dl145_g1 / 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 #include <cpu/amd/amdk8_sysconf.h>
8
9 extern  unsigned char bus_isa;
10 extern  unsigned char bus_8131_0;
11 extern  unsigned char bus_8131_1;
12 extern  unsigned char bus_8131_2;
13 extern  unsigned char bus_8111_0;
14 extern  unsigned char bus_8111_1;
15 extern  unsigned apicid_8111;
16 extern  unsigned apicid_8131_1;
17 extern  unsigned apicid_8131_2;
18
19 extern  unsigned sbdn3;
20
21
22
23 static void *smp_write_config_table(void *v)
24 {
25         static const char sig[4] = "PCMP";
26         static const char oem[8] = "COREBOOT";
27         static const char productid[12] = "DL145G1     ";
28         struct mp_config_table *mc;
29
30         unsigned char bus_num;
31
32         mc = (void *)(((char *)v) + SMP_FLOATING_TABLE_LEN);
33         memset(mc, 0, sizeof(*mc));
34
35         memcpy(mc->mpc_signature, sig, sizeof(sig));
36         mc->mpc_length = sizeof(*mc); /* initially just the header */
37         mc->mpc_spec = 0x04;
38         mc->mpc_checksum = 0; /* not yet computed */
39         memcpy(mc->mpc_oem, oem, sizeof(oem));
40         memcpy(mc->mpc_productid, productid, sizeof(productid));
41         mc->mpc_oemptr = 0;
42         mc->mpc_oemsize = 0;
43         mc->mpc_entry_count = 0; /* No entries yet... */
44         mc->mpc_lapic = LAPIC_ADDR;
45         mc->mpe_length = 0;
46         mc->mpe_checksum = 0;
47         mc->reserved = 0;
48
49         smp_write_processors(mc);
50
51         get_bus_conf();
52
53
54 /*Bus:          Bus ID  Type*/
55         /* define bus and isa numbers */
56         for(bus_num = 0; bus_num < bus_isa; bus_num++) {
57                 smp_write_bus(mc, bus_num, "PCI   ");
58         }
59         smp_write_bus(mc, bus_isa, "ISA   ");
60
61
62 /*I/O APICs:    APIC ID Version State           Address*/
63         smp_write_ioapic(mc, apicid_8111, 0x20, 0xfec00000);
64         {
65                 device_t dev;
66                 struct resource *res;
67                 dev = dev_find_slot(bus_8131_0, PCI_DEVFN(sbdn3,1));
68                 if (dev) {
69                         res = find_resource(dev, PCI_BASE_ADDRESS_0);
70                         if (res) {
71                                 smp_write_ioapic(mc, apicid_8131_1, 0x20, res->base);
72                         }
73                 }
74                 dev = dev_find_slot(bus_8131_0, PCI_DEVFN(sbdn3+1,1));
75                 if (dev) {
76                         res = find_resource(dev, PCI_BASE_ADDRESS_0);
77                         if (res) {
78                                 smp_write_ioapic(mc, apicid_8131_2, 0x20, res->base);
79                         }
80                 }
81
82         }
83
84         mptable_add_isa_interrupts(mc, bus_isa, apicid_8111, 0);
85
86         //
87         // The commented-out lines are auto-detected on my servers.
88         //
89 /*I/O Ints:     Type    Polarity    Trigger     Bus ID   IRQ    APIC ID PIN# */
90         // Integrated SMBus 2.0
91         //smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_0, ( 0x4 <<2)|3, apicid_8111  , 0x15);
92         // Integrated AMD AC97 Audio
93         //smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_0, ( 0x4 <<2)|1, apicid_8111  , 0x11);
94         //smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_0, ( 0x4 <<2)|2, apicid_8111  , 0x12);
95         // Integrated AMD USB
96         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, ( 0x4 <<2)|0, apicid_8111  , 0x10);
97         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, ( 0x0 <<2)|3, apicid_8111  , 0x13);
98         // On board ATI Rage XL
99         //smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8111_1, ( 0x5 <<2)|0, apicid_8111  , 0x14);
100         // On board Broadcom nics
101         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_2, ( 0x3 <<2)|0, apicid_8131_2, 0x03);
102         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_2, ( 0x3 <<2)|1, apicid_8131_2, 0x00);
103         // On board LSI SCSI
104         //smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_2, ( 0x2 <<2)|0, apicid_8131_2, 0x02);
105
106         // PCIX-133 Slot
107         smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, ( 0x1 <<2)|0, apicid_8131_1, 0x01);
108         //smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, ( 0x1 <<2)|1, apicid_8131_1, 0x02);
109         //smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, ( 0x1 <<2)|2, apicid_8131_1, 0x03);
110         //smp_write_intsrc(mc, mp_INT, MP_IRQ_TRIGGER_LEVEL|MP_IRQ_POLARITY_LOW, bus_8131_1, ( 0x1 <<2)|3, apicid_8131_1, 0x04);
111
112 /*Local Ints:   Type    Polarity    Trigger     Bus ID   IRQ    APIC ID PIN#*/
113         smp_write_intsrc(mc, mp_ExtINT, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, bus_isa, 0x0, MP_APIC_ALL, 0x0);
114         smp_write_intsrc(mc, mp_NMI, MP_IRQ_TRIGGER_EDGE|MP_IRQ_POLARITY_HIGH, bus_isa, 0x0, MP_APIC_ALL, 0x1);
115         /* There is no extension information... */
116
117         /* Compute the checksums */
118         mc->mpe_checksum = smp_compute_checksum(smp_next_mpc_entry(mc), mc->mpe_length);
119         mc->mpc_checksum = smp_compute_checksum(mc, mc->mpc_length);
120         printk(BIOS_DEBUG, "Wrote the mp table end at: %p - %p\n",
121                 mc, smp_next_mpe_entry(mc));
122         return smp_next_mpe_entry(mc);
123 }
124
125 unsigned long write_smp_table(unsigned long addr)
126 {
127         void *v;
128         v = smp_write_floating_table(addr);
129         return (unsigned long)smp_write_config_table(v);
130 }