- First pass at s2880 support.
[coreboot.git] / src / mainboard / amd / quartet / auto.c
1 #define ASSEMBLY 1
2 #include <stdint.h>
3 #include <device/pci_def.h>
4 #include <cpu/p6/apic.h>
5 #include <arch/io.h>
6 #include <device/pnp.h>
7 #include <arch/romcc_io.h>
8 #include "pc80/serial.c"
9 #include "arch/i386/lib/console.c"
10 #include "ram/ramtest.c"
11 #include "northbridge/amd/amdk8/early_ht.c"
12 #include "southbridge/amd/amd8111/amd8111_early_smbus.c"
13 #include "northbridge/amd/amdk8/raminit.h"
14 #include "cpu/k8/apic_timer.c"
15 #include "lib/delay.c"
16 #include "cpu/p6/boot_cpu.c"
17 #include "northbridge/amd/amdk8/reset_test.c"
18 #include "debug.c"
19
20 static void memreset_setup(const struct mem_controller *ctrl)
21 {
22         /* Set the memreset low */
23         outb((0 << 7)|(0 << 6)|(0<<5)|(0<<4)|(1<<2)|(0<<0), SMBUS_IO_BASE + 0xc0 + 28);
24         /* Ensure the BIOS has control of the memory lines */
25         outb((0 << 7)|(0 << 6)|(0<<5)|(0<<4)|(1<<2)|(0<<0), SMBUS_IO_BASE + 0xc0 + 29);
26 }
27
28 static void memreset(const struct mem_controller *ctrl)
29 {
30         udelay(800);
31         /* Set memreset_high */
32         outb((0<<7)|(0<<6)|(0<<5)|(0<<4)|(1<<2)|(1<<0), SMBUS_IO_BASE + 0xc0 + 28);
33         udelay(50);
34 }
35
36 /*
37  * generate_row is specific to board implementation
38  *
39  */
40
41 static unsigned int generate_row(uint8_t node, uint8_t row, uint8_t maxnodes)
42 {
43         /* Routing Table Node i 
44          *
45          * F0: 0x40, 0x44, 0x48, 0x4c, 0x50, 0x54, 0x58, 0x5c 
46          *  i:    0,    1,    2,    3,    4,    5,    6,    7
47          *
48          * [ 0: 3] Request Route
49          *     [0] Route to this node
50          *     [1] Route to Link 0
51          *     [2] Route to Link 1
52          *     [3] Route to Link 2
53          * [11: 8] Response Route
54          *     [0] Route to this node
55          *     [1] Route to Link 0
56          *     [2] Route to Link 1
57          *     [3] Route to Link 2
58          * [19:16] Broadcast route
59          *     [0] Route to this node
60          *     [1] Route to Link 0
61          *     [2] Route to Link 1
62          *     [3] Route to Link 2
63          */
64
65         uint32_t ret=0x00010101; /* default row entry */
66
67         static const unsigned int rows_2p[2][2] = {
68                 { 0x00030101, 0x00010202 },
69                 { 0x00010202, 0x00030101 }
70         };
71
72         static const unsigned int rows_4p[4][4] = {
73                 { 0x00070101, 0x00010404, 0x00050202, 0x00010402 },
74                 { 0x00010808, 0x000b0101, 0x00010802, 0x00090202 },
75                 { 0x00090202, 0x00010802, 0x000b0101, 0x00010808 },
76                 { 0x00010402, 0x00050202, 0x00010404, 0x00070101 }
77         };
78
79         if (!(node>=maxnodes || row>=maxnodes)) {
80                 if (maxnodes==2)
81                         ret=rows_2p[node][row];
82                 if (maxnodes==4)
83                         ret=rows_4p[node][row];
84         }
85
86         return ret;
87 }
88
89 static inline int spd_read_byte(unsigned device, unsigned address)
90 {
91         return smbus_read_byte(device, address);
92 }
93
94 #include "northbridge/amd/amdk8/cpu_ldtstop.c"
95 #include "southbridge/amd/amd8111/amd8111_ldtstop.c"
96
97 #include "northbridge/amd/amdk8/raminit.c"
98 #include "northbridge/amd/amdk8/coherent_ht.c"
99 #include "sdram/generic_sdram.c"
100
101 #include "resourcemap.c" /* quartet does not want the default */
102
103 static void enable_lapic(void)
104 {
105
106         msr_t msr;
107         msr = rdmsr(0x1b);
108         msr.hi &= 0xffffff00;
109         msr.lo &= 0x000007ff;
110         msr.lo |= APIC_DEFAULT_BASE | (1 << 11);
111         wrmsr(0x1b, msr);
112 }
113
114 static void stop_this_cpu(void)
115 {
116         unsigned apicid;
117         apicid = apic_read(APIC_ID) >> 24;
118
119         /* Send an APIC INIT to myself */
120         apic_write(APIC_ICR2, SET_APIC_DEST_FIELD(apicid));
121         apic_write(APIC_ICR, APIC_INT_LEVELTRIG | APIC_INT_ASSERT | APIC_DM_INIT);
122         /* Wait for the ipi send to finish */
123         apic_wait_icr_idle();
124
125         /* Deassert the APIC INIT */
126         apic_write(APIC_ICR2, SET_APIC_DEST_FIELD(apicid));
127         apic_write(APIC_ICR,  APIC_INT_LEVELTRIG | APIC_DM_INIT);
128         /* Wait for the ipi send to finish */
129         apic_wait_icr_idle();
130
131         /* If I haven't halted spin forever */
132         for(;;) {
133                 hlt();
134         }
135 }
136
137 #define PC87360_FDC  0x00
138 #define PC87360_PP   0x01
139 #define PC87360_SP2  0x02
140 #define PC87360_SP1  0x03
141 #define PC87360_SWC  0x04
142 #define PC87360_KBCM 0x05
143 #define PC87360_KBCK 0x06
144 #define PC87360_GPIO 0x07
145 #define PC87360_ACB  0x08
146 #define PC87360_FSCM 0x09
147 #define PC87360_WDT  0x0A
148
149 static void pc87360_enable_serial(void)
150 {
151         pnp_set_logical_device(SIO_BASE, PC87360_SP1);
152         pnp_set_enable(SIO_BASE, 1);
153         pnp_set_iobase0(SIO_BASE, 0x3f8);
154 }
155
156 static void main(void)
157 {
158         /*
159          * GPIO28 of 8111 will control H0_MEMRESET_L
160          * GPIO29 of 8111 will control H1_MEMRESET_L
161          */
162
163         static const struct mem_controller cpu0 = {
164                 .f0 = PCI_DEV(0, 0x18, 0),
165                 .f1 = PCI_DEV(0, 0x18, 1),
166                 .f2 = PCI_DEV(0, 0x18, 2),
167                 .f3 = PCI_DEV(0, 0x18, 3),
168                 .channel0 = { (0xa<<3)|0, (0xa<<3)|2, 0, 0 },
169                 .channel1 = { (0xa<<3)|1, (0xa<<3)|3, 0, 0 },
170         };
171         static const struct mem_controller cpu1 = {
172                 .f0 = PCI_DEV(0, 0x19, 0),
173                 .f1 = PCI_DEV(0, 0x19, 1),
174                 .f2 = PCI_DEV(0, 0x19, 2),
175                 .f3 = PCI_DEV(0, 0x19, 3),
176                 .channel0 = { (0xa<<3)|4, (0xa<<3)|6, 0, 0 },
177                 .channel1 = { (0xa<<3)|5, (0xa<<3)|7, 0, 0 },
178         };
179         static const struct mem_controller cpu2 = {
180                 .f0 = PCI_DEV(0, 0x1a, 0),
181                 .f1 = PCI_DEV(0, 0x1a, 1),
182                 .f2 = PCI_DEV(0, 0x1a, 2),
183                 .f3 = PCI_DEV(0, 0x1a, 3),
184                 .channel0 = { (0xa<<3)|8, (0xa<<3)|10, 0, 0 },
185                 .channel1 = { (0xa<<3)|9, (0xa<<3)|11, 0, 0 },
186         };
187         static const struct mem_controller cpu3 = {
188                 .f0 = PCI_DEV(0, 0x1b, 0),
189                 .f1 = PCI_DEV(0, 0x1b, 1),
190                 .f2 = PCI_DEV(0, 0x1b, 2),
191                 .f3 = PCI_DEV(0, 0x1b, 3),
192                 .channel0 = { (0xa<<3)|12, (0xa<<3)|14, 0, 0 },
193                 .channel1 = { (0xa<<3)|13, (0xa<<3)|15, 0, 0 },
194         };
195         
196         if (cpu_init_detected()) {
197                 asm("jmp __cpu_reset");
198         }
199         pc87360_enable_serial();
200         uart_init();
201         console_init();
202         enable_lapic();
203         if (!boot_cpu()) {
204                 stop_this_cpu();
205         }
206         init_timer();
207         setup_default_resource_map();
208         setup_coherent_ht_domain();
209         enumerate_ht_chain(0);
210         distinguish_cpu_resets();
211         
212 #if 1 
213         print_pci_devices();
214 #endif
215         enable_smbus();
216 #if 0
217         dump_spd_registers(&cpu0);
218 #endif
219         sdram_initialize(&cpu0);
220
221 #if 1
222         dump_pci_devices();
223 #endif
224 #if 0
225         dump_pci_device(PCI_DEV(0, 0x18, 2));
226 #endif
227
228         /* Check all of memory */
229 #if 0
230         msr_t msr;
231         msr = rdmsr(TOP_MEM);
232         print_debug("TOP_MEM: ");
233         print_debug_hex32(msr.hi);
234         print_debug_hex32(msr.lo);
235         print_debug("\r\n");
236 #endif
237 #if 0
238         ram_check(0x00000000, msr.lo);
239 #else
240         /* Check 16MB of memory */
241         ram_check(0x00000000, 0x01000000);
242 #endif
243 }