| 1 |
|
| 2 |
|
| 3 |
#include <arch/cpu.h> |
| 4 |
#include <cbmem.h> |
| 5 |
#include <console/console.h> |
| 6 |
#include <cpu/x86/cache.h> |
| 7 |
#include <program_loading.h> |
| 8 |
#include <types.h> |
| 9 |
|
| 10 |
bool clflush_supported(void) |
| 11 |
{ |
| 12 |
return (cpuid_edx(1) >> CPUID_FEATURE_CLFLUSH_BIT) & 1; |
| 13 |
} |
| 14 |
|
| 15 |
void clflush_region(const uintptr_t start, const size_t size) |
| 16 |
{ |
| 17 |
uintptr_t addr; |
| 18 |
const size_t cl_size = ((cpuid_ebx(1) >> 8) & 0xff) * 8; |
| 19 |
|
| 20 |
printk(BIOS_SPEW, "CLFLUSH [0x%lx, 0x%lx]\n", start, start + size); |
| 21 |
|
| 22 |
for (addr = ALIGN_DOWN(start, cl_size); addr < start + size; addr += cl_size) |
| 23 |
clflush((void *)addr); |
| 24 |
} |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
void arch_segment_loaded(uintptr_t start, size_t size, int flags) |
| 31 |
{ |
| 32 |
|
| 33 |
|
| 34 |
if (!ENV_CACHE_AS_RAM) |
| 35 |
return; |
| 36 |
if (!ENV_RAMINIT) |
| 37 |
return; |
| 38 |
if (!CONFIG(POSTCAR_STAGE)) |
| 39 |
return; |
| 40 |
if (!CONFIG(X86_CLFLUSH_CAR)) |
| 41 |
return; |
| 42 |
if (flags != SEG_FINAL) |
| 43 |
return; |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
if (!cbmem_online()) |
| 50 |
return; |
| 51 |
|
| 52 |
if (!self_snooping_supported()) { |
| 53 |
if (clflush_supported()) |
| 54 |
clflush_region(start, size); |
| 55 |
else |
| 56 |
printk(BIOS_DEBUG, "Not flushing cache to RAM, CLFLUSH not supported\n"); |
| 57 |
} |
| 58 |
} |