Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2000,2007 Ronald G. Minnich <rminnich@gmail.com> |
Kyösti Mälkki | 0078ceb | 2012-02-28 02:02:27 +0200 | [diff] [blame] | 5 | * Copyright (C) 2005 Tyan (written by Yinghai Lu for Tyan) |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 6 | * Copyright (C) 2007-2008 coresystems GmbH |
Kyösti Mälkki | 0078ceb | 2012-02-28 02:02:27 +0200 | [diff] [blame] | 7 | * Copyright (C) 2012 Kyösti Mälkki <kyosti.malkki@gmail.com> |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; version 2 of the License. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 17 | */ |
| 18 | |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 19 | #include <cpu/x86/mtrr.h> |
Patrick Georgi | 05e740f | 2012-03-31 12:52:21 +0200 | [diff] [blame] | 20 | #include <cpu/x86/cache.h> |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 21 | #include <cpu/x86/post_code.h> |
Kyösti Mälkki | f9d1a42 | 2012-02-28 01:45:44 +0200 | [diff] [blame] | 22 | #include <cpu/x86/lapic_def.h> |
| 23 | |
| 24 | /* Macro to access Local APIC registers at default base. */ |
| 25 | #define LAPIC(x) $(LAPIC_DEFAULT_BASE | LAPIC_ ## x) |
Kyösti Mälkki | 0078ceb | 2012-02-28 02:02:27 +0200 | [diff] [blame] | 26 | #define START_IPI_VECTOR ((CONFIG_AP_SIPI_VECTOR >> 12) & 0xff) |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 27 | |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 28 | #define CACHE_AS_RAM_SIZE CONFIG_DCACHE_RAM_SIZE |
| 29 | #define CACHE_AS_RAM_BASE CONFIG_DCACHE_RAM_BASE |
| 30 | |
| 31 | /* Save the BIST result. */ |
| 32 | movl %eax, %ebp |
| 33 | |
| 34 | cache_as_ram: |
| 35 | post_code(0x20) |
| 36 | |
Kyösti Mälkki | a860c68 | 2012-02-28 02:06:45 +0200 | [diff] [blame] | 37 | movl $LAPIC_BASE_MSR, %ecx |
| 38 | rdmsr |
| 39 | andl $LAPIC_BASE_MSR_BOOTSTRAP_PROCESSOR, %eax |
| 40 | jz ap_init |
| 41 | |
Kyösti Mälkki | 0078ceb | 2012-02-28 02:02:27 +0200 | [diff] [blame] | 42 | /* Zero out all fixed range and variable range MTRRs. |
Kyösti Mälkki | a860c68 | 2012-02-28 02:06:45 +0200 | [diff] [blame] | 43 | * For hyper-threaded CPUs these are shared. |
| 44 | */ |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 45 | movl $mtrr_table, %esi |
Stefan Reinauer | 4a45ec4 | 2015-07-07 00:54:05 +0200 | [diff] [blame] | 46 | movl $((mtrr_table_end - mtrr_table) >> 1), %edi |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 47 | xorl %eax, %eax |
| 48 | xorl %edx, %edx |
| 49 | clear_mtrrs: |
| 50 | movw (%esi), %bx |
| 51 | movzx %bx, %ecx |
| 52 | wrmsr |
| 53 | add $2, %esi |
| 54 | dec %edi |
| 55 | jnz clear_mtrrs |
| 56 | |
Kyösti Mälkki | 0078ceb | 2012-02-28 02:02:27 +0200 | [diff] [blame] | 57 | post_code(0x21) |
| 58 | |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 59 | /* Configure the default memory type to uncacheable. */ |
Alexandru Gagniuc | 86091f9 | 2015-09-30 20:23:09 -0700 | [diff] [blame] | 60 | movl $MTRR_DEF_TYPE_MSR, %ecx |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 61 | rdmsr |
| 62 | andl $(~0x00000cff), %eax |
| 63 | wrmsr |
| 64 | |
Kyösti Mälkki | 0078ceb | 2012-02-28 02:02:27 +0200 | [diff] [blame] | 65 | post_code(0x22) |
| 66 | |
Kyösti Mälkki | a860c68 | 2012-02-28 02:06:45 +0200 | [diff] [blame] | 67 | /* Determine CPU_ADDR_BITS and load PHYSMASK high |
| 68 | * word to %edx. |
| 69 | */ |
| 70 | movl $0x80000000, %eax |
| 71 | cpuid |
| 72 | cmpl $0x80000008, %eax |
| 73 | jc addrsize_no_MSR |
| 74 | movl $0x80000008, %eax |
| 75 | cpuid |
| 76 | movb %al, %cl |
| 77 | sub $32, %cl |
| 78 | movl $1, %edx |
| 79 | shl %cl, %edx |
| 80 | subl $1, %edx |
| 81 | jmp addrsize_set_high |
| 82 | addrsize_no_MSR: |
| 83 | movl $1, %eax |
| 84 | cpuid |
| 85 | andl $(1<<6 | 1<<17), %edx /* PAE or PSE36 */ |
| 86 | jz addrsize_set_high |
| 87 | movl $0x0f, %edx |
| 88 | |
| 89 | /* Preload high word of address mask (in %edx) for Variable |
Elyes HAOUAS | d6e9686 | 2016-08-21 10:12:15 +0200 | [diff] [blame] | 90 | * MTRRs 0 and 1 and enable local APIC at default base. |
Kyösti Mälkki | a860c68 | 2012-02-28 02:06:45 +0200 | [diff] [blame] | 91 | */ |
| 92 | addrsize_set_high: |
| 93 | xorl %eax, %eax |
Alexandru Gagniuc | 86091f9 | 2015-09-30 20:23:09 -0700 | [diff] [blame] | 94 | movl $MTRR_PHYS_MASK(0), %ecx |
Kyösti Mälkki | a860c68 | 2012-02-28 02:06:45 +0200 | [diff] [blame] | 95 | wrmsr |
Alexandru Gagniuc | 86091f9 | 2015-09-30 20:23:09 -0700 | [diff] [blame] | 96 | movl $MTRR_PHYS_MASK(1), %ecx |
Kyösti Mälkki | a860c68 | 2012-02-28 02:06:45 +0200 | [diff] [blame] | 97 | wrmsr |
Kyösti Mälkki | 0078ceb | 2012-02-28 02:02:27 +0200 | [diff] [blame] | 98 | movl $LAPIC_BASE_MSR, %ecx |
Kyösti Mälkki | a860c68 | 2012-02-28 02:06:45 +0200 | [diff] [blame] | 99 | not %edx |
| 100 | movl %edx, %ebx |
Kyösti Mälkki | 0078ceb | 2012-02-28 02:02:27 +0200 | [diff] [blame] | 101 | rdmsr |
Kyösti Mälkki | a860c68 | 2012-02-28 02:06:45 +0200 | [diff] [blame] | 102 | andl %ebx, %edx |
Kyösti Mälkki | 0078ceb | 2012-02-28 02:02:27 +0200 | [diff] [blame] | 103 | andl $(~LAPIC_BASE_MSR_ADDR_MASK), %eax |
| 104 | orl $(LAPIC_DEFAULT_BASE | LAPIC_BASE_MSR_ENABLE), %eax |
| 105 | wrmsr |
Kyösti Mälkki | 0078ceb | 2012-02-28 02:02:27 +0200 | [diff] [blame] | 106 | |
| 107 | bsp_init: |
| 108 | |
| 109 | post_code(0x23) |
| 110 | |
| 111 | /* Send INIT IPI to all excluding ourself. */ |
| 112 | movl LAPIC(ICR), %edi |
| 113 | movl $(LAPIC_DEST_ALLBUT | LAPIC_INT_ASSERT | LAPIC_DM_INIT), %eax |
| 114 | 1: movl %eax, (%edi) |
| 115 | movl $0x30, %ecx |
| 116 | 2: pause |
| 117 | dec %ecx |
| 118 | jnz 2b |
| 119 | movl (%edi), %ecx |
| 120 | andl $LAPIC_ICR_BUSY, %ecx |
| 121 | jnz 1b |
| 122 | |
| 123 | post_code(0x24) |
Patrick Georgi | 819c7d4 | 2012-03-31 13:08:12 +0200 | [diff] [blame] | 124 | |
Kyösti Mälkki | df0fbc7 | 2012-07-04 12:02:58 +0300 | [diff] [blame] | 125 | movl $1, %eax |
Kyösti Mälkki | 0078ceb | 2012-02-28 02:02:27 +0200 | [diff] [blame] | 126 | cpuid |
| 127 | btl $28, %edx |
| 128 | jnc sipi_complete |
| 129 | bswapl %ebx |
Kyösti Mälkki | df0fbc7 | 2012-07-04 12:02:58 +0300 | [diff] [blame] | 130 | movzx %bh, %edi |
| 131 | cmpb $1, %bh |
| 132 | jbe sipi_complete /* only one LAPIC ID in package */ |
| 133 | |
| 134 | movl $0, %eax |
| 135 | cpuid |
| 136 | movb $1, %bl |
| 137 | cmpl $4, %eax |
| 138 | jb cores_counted |
| 139 | movl $4, %eax |
| 140 | movl $0, %ecx |
| 141 | cpuid |
| 142 | shr $26, %eax |
| 143 | movb %al, %bl |
| 144 | inc %bl |
| 145 | |
| 146 | cores_counted: |
| 147 | movl %edi, %eax |
| 148 | divb %bl |
| 149 | cmpb $1, %al |
| 150 | jbe sipi_complete /* only LAPIC ID of a core */ |
| 151 | |
| 152 | /* For a hyper-threading processor, cache must not be disabled |
| 153 | * on an AP on the same physical package with the BSP. |
| 154 | */ |
Kyösti Mälkki | 0078ceb | 2012-02-28 02:02:27 +0200 | [diff] [blame] | 155 | |
| 156 | hyper_threading_cpu: |
| 157 | |
| 158 | /* delay 10 ms */ |
| 159 | movl $10000, %ecx |
| 160 | 1: inb $0x80, %al |
| 161 | dec %ecx |
| 162 | jnz 1b |
| 163 | |
| 164 | post_code(0x25) |
| 165 | |
| 166 | /* Send Start IPI to all excluding ourself. */ |
| 167 | movl LAPIC(ICR), %edi |
| 168 | movl $(LAPIC_DEST_ALLBUT | LAPIC_DM_STARTUP | START_IPI_VECTOR), %eax |
| 169 | 1: movl %eax, (%edi) |
| 170 | movl $0x30, %ecx |
| 171 | 2: pause |
| 172 | dec %ecx |
| 173 | jnz 2b |
| 174 | movl (%edi), %ecx |
| 175 | andl $LAPIC_ICR_BUSY, %ecx |
| 176 | jnz 1b |
| 177 | |
| 178 | /* delay 250 us */ |
| 179 | movl $250, %ecx |
| 180 | 1: inb $0x80, %al |
| 181 | dec %ecx |
| 182 | jnz 1b |
| 183 | |
| 184 | post_code(0x26) |
| 185 | |
| 186 | /* Wait for sibling CPU to start. */ |
Alexandru Gagniuc | 86091f9 | 2015-09-30 20:23:09 -0700 | [diff] [blame] | 187 | 1: movl $(MTRR_PHYS_BASE(0)), %ecx |
Kyösti Mälkki | 0078ceb | 2012-02-28 02:02:27 +0200 | [diff] [blame] | 188 | rdmsr |
| 189 | andl %eax, %eax |
| 190 | jnz sipi_complete |
| 191 | |
| 192 | movl $0x30, %ecx |
| 193 | 2: pause |
| 194 | dec %ecx |
| 195 | jnz 2b |
| 196 | jmp 1b |
| 197 | |
| 198 | |
| 199 | ap_init: |
| 200 | post_code(0x27) |
| 201 | |
| 202 | /* Do not disable cache (so BSP can enable it). */ |
Elyes HAOUAS | 2765a89 | 2016-09-01 19:44:56 +0200 | [diff] [blame] | 203 | movl %cr0, %eax |
Patrick Georgi | 05e740f | 2012-03-31 12:52:21 +0200 | [diff] [blame] | 204 | andl $(~(CR0_CacheDisable | CR0_NoWriteThrough)), %eax |
Kyösti Mälkki | 0078ceb | 2012-02-28 02:02:27 +0200 | [diff] [blame] | 205 | movl %eax, %cr0 |
| 206 | |
| 207 | post_code(0x28) |
| 208 | |
| 209 | /* MTRR registers are shared between HT siblings. */ |
Alexandru Gagniuc | 86091f9 | 2015-09-30 20:23:09 -0700 | [diff] [blame] | 210 | movl $(MTRR_PHYS_BASE(0)), %ecx |
Kyösti Mälkki | 0078ceb | 2012-02-28 02:02:27 +0200 | [diff] [blame] | 211 | movl $(1<<12), %eax |
| 212 | xorl %edx, %edx |
| 213 | wrmsr |
| 214 | |
| 215 | post_code(0x29) |
| 216 | |
| 217 | ap_halt: |
| 218 | cli |
| 219 | 1: hlt |
Kyösti Mälkki | df0fbc7 | 2012-07-04 12:02:58 +0300 | [diff] [blame] | 220 | jmp 1b |
Kyösti Mälkki | 0078ceb | 2012-02-28 02:02:27 +0200 | [diff] [blame] | 221 | |
| 222 | |
| 223 | |
| 224 | sipi_complete: |
| 225 | |
| 226 | post_code(0x2a) |
| 227 | |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 228 | /* Set Cache-as-RAM base address. */ |
Alexandru Gagniuc | 86091f9 | 2015-09-30 20:23:09 -0700 | [diff] [blame] | 229 | movl $(MTRR_PHYS_BASE(0)), %ecx |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 230 | movl $(CACHE_AS_RAM_BASE | MTRR_TYPE_WRBACK), %eax |
| 231 | xorl %edx, %edx |
| 232 | wrmsr |
| 233 | |
| 234 | /* Set Cache-as-RAM mask. */ |
Alexandru Gagniuc | 86091f9 | 2015-09-30 20:23:09 -0700 | [diff] [blame] | 235 | movl $(MTRR_PHYS_MASK(0)), %ecx |
Kyösti Mälkki | a860c68 | 2012-02-28 02:06:45 +0200 | [diff] [blame] | 236 | rdmsr |
Alexandru Gagniuc | 86091f9 | 2015-09-30 20:23:09 -0700 | [diff] [blame] | 237 | movl $(~(CACHE_AS_RAM_SIZE - 1) | MTRR_PHYS_MASK_VALID), %eax |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 238 | wrmsr |
| 239 | |
Kyösti Mälkki | 8a2f167 | 2016-07-20 13:29:59 +0300 | [diff] [blame] | 240 | post_code(0x2b) |
| 241 | |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 242 | /* Enable MTRR. */ |
Alexandru Gagniuc | 86091f9 | 2015-09-30 20:23:09 -0700 | [diff] [blame] | 243 | movl $MTRR_DEF_TYPE_MSR, %ecx |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 244 | rdmsr |
Alexandru Gagniuc | 86091f9 | 2015-09-30 20:23:09 -0700 | [diff] [blame] | 245 | orl $MTRR_DEF_TYPE_EN, %eax |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 246 | wrmsr |
| 247 | |
Kyösti Mälkki | 05d6ffb | 2012-02-16 23:12:04 +0200 | [diff] [blame] | 248 | /* Enable L2 cache Write-Back (WBINVD and FLUSH#). |
| 249 | * |
| 250 | * MSR is set when DisplayFamily_DisplayModel is one of: |
| 251 | * 06_0x, 06_17, 06_1C |
| 252 | * |
| 253 | * Description says this bit enables use of WBINVD and FLUSH#. |
| 254 | * Should this be set only after the system bus and/or memory |
| 255 | * controller can successfully handle write cycles? |
| 256 | */ |
| 257 | |
| 258 | #define EAX_FAMILY(a) (a << 8) /* for family <= 0fH */ |
| 259 | #define EAX_MODEL(a) (((a & 0xf0) << 12) | ((a & 0xf) << 4)) |
| 260 | |
| 261 | movl $1, %eax |
| 262 | cpuid |
| 263 | movl %eax, %ebx |
| 264 | andl $EAX_FAMILY(0x0f), %eax |
| 265 | cmpl $EAX_FAMILY(0x06), %eax |
| 266 | jne no_msr_11e |
| 267 | movl %ebx, %eax |
| 268 | andl $EAX_MODEL(0xff), %eax |
| 269 | cmpl $EAX_MODEL(0x17), %eax |
| 270 | je has_msr_11e |
| 271 | cmpl $EAX_MODEL(0x1c), %eax |
| 272 | je has_msr_11e |
| 273 | andl $EAX_MODEL(0xf0), %eax |
| 274 | cmpl $EAX_MODEL(0x00), %eax |
| 275 | jne no_msr_11e |
| 276 | has_msr_11e: |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 277 | movl $0x11e, %ecx |
| 278 | rdmsr |
| 279 | orl $(1 << 8), %eax |
| 280 | wrmsr |
Kyösti Mälkki | 05d6ffb | 2012-02-16 23:12:04 +0200 | [diff] [blame] | 281 | no_msr_11e: |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 282 | |
Kyösti Mälkki | 0078ceb | 2012-02-28 02:02:27 +0200 | [diff] [blame] | 283 | post_code(0x2c) |
| 284 | |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 285 | /* Enable cache (CR0.CD = 0, CR0.NW = 0). */ |
Kyösti Mälkki | f9d1a42 | 2012-02-28 01:45:44 +0200 | [diff] [blame] | 286 | movl %cr0, %eax |
Patrick Georgi | 05e740f | 2012-03-31 12:52:21 +0200 | [diff] [blame] | 287 | andl $(~(CR0_CacheDisable | CR0_NoWriteThrough)), %eax |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 288 | invd |
| 289 | movl %eax, %cr0 |
| 290 | |
Kyösti Mälkki | eb61ea8 | 2016-07-20 12:50:20 +0300 | [diff] [blame] | 291 | /* Clear the cache memory region. This will also fill up the cache. */ |
Kyösti Mälkki | f9d1a42 | 2012-02-28 01:45:44 +0200 | [diff] [blame] | 292 | cld |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 293 | xorl %eax, %eax |
Kyösti Mälkki | f9d1a42 | 2012-02-28 01:45:44 +0200 | [diff] [blame] | 294 | movl $CACHE_AS_RAM_BASE, %edi |
Stefan Reinauer | 4a45ec4 | 2015-07-07 00:54:05 +0200 | [diff] [blame] | 295 | movl $(CACHE_AS_RAM_SIZE >> 2), %ecx |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 296 | rep stosl |
| 297 | |
Kyösti Mälkki | 8a2f167 | 2016-07-20 13:29:59 +0300 | [diff] [blame] | 298 | post_code(0x2d) |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 299 | /* Enable Cache-as-RAM mode by disabling cache. */ |
| 300 | movl %cr0, %eax |
Patrick Georgi | 05e740f | 2012-03-31 12:52:21 +0200 | [diff] [blame] | 301 | orl $CR0_CacheDisable, %eax |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 302 | movl %eax, %cr0 |
| 303 | |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 304 | /* Enable cache for our code in Flash because we do XIP here */ |
Alexandru Gagniuc | 86091f9 | 2015-09-30 20:23:09 -0700 | [diff] [blame] | 305 | movl $MTRR_PHYS_BASE(1), %ecx |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 306 | xorl %edx, %edx |
| 307 | /* |
| 308 | * IMPORTANT: The following calculation _must_ be done at runtime. See |
| 309 | * http://www.coreboot.org/pipermail/coreboot/2010-October/060855.html |
| 310 | */ |
| 311 | movl $copy_and_run, %eax |
| 312 | andl $(~(CONFIG_XIP_ROM_SIZE - 1)), %eax |
Kyösti Mälkki | dc4820b | 2016-07-21 19:51:01 +0300 | [diff] [blame] | 313 | orl $MTRR_TYPE_WRPROT, %eax |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 314 | wrmsr |
| 315 | |
Alexandru Gagniuc | 86091f9 | 2015-09-30 20:23:09 -0700 | [diff] [blame] | 316 | movl $MTRR_PHYS_MASK(1), %ecx |
Kyösti Mälkki | a860c68 | 2012-02-28 02:06:45 +0200 | [diff] [blame] | 317 | rdmsr |
Alexandru Gagniuc | 86091f9 | 2015-09-30 20:23:09 -0700 | [diff] [blame] | 318 | movl $(~(CONFIG_XIP_ROM_SIZE - 1) | MTRR_PHYS_MASK_VALID), %eax |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 319 | wrmsr |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 320 | |
Kyösti Mälkki | 8a2f167 | 2016-07-20 13:29:59 +0300 | [diff] [blame] | 321 | post_code(0x2e) |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 322 | /* Enable cache. */ |
| 323 | movl %cr0, %eax |
Patrick Georgi | 05e740f | 2012-03-31 12:52:21 +0200 | [diff] [blame] | 324 | andl $(~(CR0_CacheDisable | CR0_NoWriteThrough)), %eax |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 325 | movl %eax, %cr0 |
| 326 | |
Kyösti Mälkki | 39915bc | 2016-11-08 12:13:15 +0200 | [diff] [blame^] | 327 | /* Setup the stack. */ |
| 328 | movl $(CONFIG_DCACHE_RAM_BASE + CONFIG_DCACHE_RAM_SIZE), %eax |
| 329 | movl %eax, %esp |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 330 | |
| 331 | /* Restore the BIST result. */ |
| 332 | movl %ebp, %eax |
| 333 | movl %esp, %ebp |
| 334 | pushl %eax |
| 335 | |
Kyösti Mälkki | 8a2f167 | 2016-07-20 13:29:59 +0300 | [diff] [blame] | 336 | before_romstage: |
Kyösti Mälkki | 0078ceb | 2012-02-28 02:02:27 +0200 | [diff] [blame] | 337 | post_code(0x2f) |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 338 | /* Call romstage.c main function. */ |
Kyösti Mälkki | 408d392 | 2016-06-17 10:43:48 +0300 | [diff] [blame] | 339 | call romstage_main |
| 340 | |
| 341 | /* Save return value from romstage_main. It contains the stack to use |
Kyösti Mälkki | b4f827d | 2016-06-21 06:59:30 +0300 | [diff] [blame] | 342 | * after cache-as-ram is torn down. |
| 343 | */ |
Kyösti Mälkki | 39915bc | 2016-11-08 12:13:15 +0200 | [diff] [blame^] | 344 | movl %eax, %esp |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 345 | |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 346 | post_code(0x30) |
| 347 | |
| 348 | /* Disable cache. */ |
| 349 | movl %cr0, %eax |
Patrick Georgi | 05e740f | 2012-03-31 12:52:21 +0200 | [diff] [blame] | 350 | orl $CR0_CacheDisable, %eax |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 351 | movl %eax, %cr0 |
| 352 | |
Kyösti Mälkki | 8a2f167 | 2016-07-20 13:29:59 +0300 | [diff] [blame] | 353 | post_code(0x31) |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 354 | |
| 355 | /* Disable MTRR. */ |
Alexandru Gagniuc | 86091f9 | 2015-09-30 20:23:09 -0700 | [diff] [blame] | 356 | movl $MTRR_DEF_TYPE_MSR, %ecx |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 357 | rdmsr |
Alexandru Gagniuc | 86091f9 | 2015-09-30 20:23:09 -0700 | [diff] [blame] | 358 | andl $(~MTRR_DEF_TYPE_EN), %eax |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 359 | wrmsr |
| 360 | |
Kyösti Mälkki | 8a2f167 | 2016-07-20 13:29:59 +0300 | [diff] [blame] | 361 | post_code(0x32) |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 362 | |
| 363 | invd |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 364 | |
Kyösti Mälkki | 8a2f167 | 2016-07-20 13:29:59 +0300 | [diff] [blame] | 365 | post_code(0x33) |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 366 | |
| 367 | /* Enable cache. */ |
| 368 | movl %cr0, %eax |
Patrick Georgi | 05e740f | 2012-03-31 12:52:21 +0200 | [diff] [blame] | 369 | andl $~(CR0_CacheDisable | CR0_NoWriteThrough), %eax |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 370 | movl %eax, %cr0 |
| 371 | |
Kyösti Mälkki | 8a2f167 | 2016-07-20 13:29:59 +0300 | [diff] [blame] | 372 | post_code(0x36) |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 373 | |
| 374 | /* Disable cache. */ |
| 375 | movl %cr0, %eax |
Patrick Georgi | 05e740f | 2012-03-31 12:52:21 +0200 | [diff] [blame] | 376 | orl $CR0_CacheDisable, %eax |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 377 | movl %eax, %cr0 |
| 378 | |
| 379 | post_code(0x38) |
| 380 | |
Kyösti Mälkki | f9d1a42 | 2012-02-28 01:45:44 +0200 | [diff] [blame] | 381 | /* Enable Write Back and Speculative Reads for low RAM. */ |
Alexandru Gagniuc | 86091f9 | 2015-09-30 20:23:09 -0700 | [diff] [blame] | 382 | movl $MTRR_PHYS_BASE(0), %ecx |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 383 | movl $(0x00000000 | MTRR_TYPE_WRBACK), %eax |
| 384 | xorl %edx, %edx |
| 385 | wrmsr |
Alexandru Gagniuc | 86091f9 | 2015-09-30 20:23:09 -0700 | [diff] [blame] | 386 | movl $MTRR_PHYS_MASK(0), %ecx |
Kyösti Mälkki | a860c68 | 2012-02-28 02:06:45 +0200 | [diff] [blame] | 387 | rdmsr |
Kyösti Mälkki | 65cc526 | 2016-06-19 20:38:41 +0300 | [diff] [blame] | 388 | movl $(~(CACHE_TMP_RAMTOP - 1) | MTRR_PHYS_MASK_VALID), %eax |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 389 | wrmsr |
| 390 | |
Kyösti Mälkki | 107f72e | 2014-01-06 11:06:26 +0200 | [diff] [blame] | 391 | #if CACHE_ROM_SIZE |
Kyösti Mälkki | 325b92f | 2012-02-28 00:24:15 +0200 | [diff] [blame] | 392 | /* Enable caching and Speculative Reads for Flash ROM device. */ |
Alexandru Gagniuc | 86091f9 | 2015-09-30 20:23:09 -0700 | [diff] [blame] | 393 | movl $MTRR_PHYS_BASE(1), %ecx |
Kyösti Mälkki | 325b92f | 2012-02-28 00:24:15 +0200 | [diff] [blame] | 394 | movl $(CACHE_ROM_BASE | MTRR_TYPE_WRPROT), %eax |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 395 | xorl %edx, %edx |
| 396 | wrmsr |
Alexandru Gagniuc | 86091f9 | 2015-09-30 20:23:09 -0700 | [diff] [blame] | 397 | movl $MTRR_PHYS_MASK(1), %ecx |
Kyösti Mälkki | a860c68 | 2012-02-28 02:06:45 +0200 | [diff] [blame] | 398 | rdmsr |
Alexandru Gagniuc | 86091f9 | 2015-09-30 20:23:09 -0700 | [diff] [blame] | 399 | movl $(~(CACHE_ROM_SIZE - 1) | MTRR_PHYS_MASK_VALID), %eax |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 400 | wrmsr |
Kyösti Mälkki | 5458b9d | 2012-06-30 11:41:08 +0300 | [diff] [blame] | 401 | #endif |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 402 | |
| 403 | post_code(0x39) |
| 404 | |
| 405 | /* And enable cache again after setting MTRRs. */ |
| 406 | movl %cr0, %eax |
Patrick Georgi | 05e740f | 2012-03-31 12:52:21 +0200 | [diff] [blame] | 407 | andl $~(CR0_CacheDisable | CR0_NoWriteThrough), %eax |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 408 | movl %eax, %cr0 |
| 409 | |
| 410 | post_code(0x3a) |
| 411 | |
| 412 | /* Enable MTRR. */ |
Alexandru Gagniuc | 86091f9 | 2015-09-30 20:23:09 -0700 | [diff] [blame] | 413 | movl $MTRR_DEF_TYPE_MSR, %ecx |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 414 | rdmsr |
Alexandru Gagniuc | 86091f9 | 2015-09-30 20:23:09 -0700 | [diff] [blame] | 415 | orl $MTRR_DEF_TYPE_EN, %eax |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 416 | wrmsr |
| 417 | |
| 418 | post_code(0x3b) |
| 419 | |
| 420 | /* Invalidate the cache again. */ |
| 421 | invd |
| 422 | |
| 423 | post_code(0x3c) |
| 424 | |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 425 | __main: |
| 426 | post_code(POST_PREPARE_RAMSTAGE) |
| 427 | cld /* Clear direction flag. */ |
Kyösti Mälkki | 39915bc | 2016-11-08 12:13:15 +0200 | [diff] [blame^] | 428 | call romstage_after_car |
Kyösti Mälkki | 5a660ca | 2012-02-28 00:15:30 +0200 | [diff] [blame] | 429 | |
| 430 | .Lhlt: |
| 431 | post_code(POST_DEAD_CODE) |
| 432 | hlt |
| 433 | jmp .Lhlt |
| 434 | |
| 435 | mtrr_table: |
| 436 | /* Fixed MTRRs */ |
| 437 | .word 0x250, 0x258, 0x259 |
| 438 | .word 0x268, 0x269, 0x26A |
| 439 | .word 0x26B, 0x26C, 0x26D |
| 440 | .word 0x26E, 0x26F |
| 441 | /* Variable MTRRs */ |
| 442 | .word 0x200, 0x201, 0x202, 0x203 |
| 443 | .word 0x204, 0x205, 0x206, 0x207 |
| 444 | .word 0x208, 0x209, 0x20A, 0x20B |
| 445 | .word 0x20C, 0x20D, 0x20E, 0x20F |
| 446 | mtrr_table_end: |