| 1 |
|
| 2 |
|
| 3 |
#include <assert.h> |
| 4 |
#include <console/console.h> |
| 5 |
#include <cpu/x86/cache.h> |
| 6 |
#include <device/pci_ids.h> |
| 7 |
#include <device/pci_ops.h> |
| 8 |
#include <soc/cpu.h> |
| 9 |
#include <soc/iomap.h> |
| 10 |
#include <soc/loader.h> |
| 11 |
#include <soc/pci_devs.h> |
| 12 |
#include <string.h> |
| 13 |
#include <symbols.h> |
| 14 |
|
| 15 |
static void flush_cache(uintptr_t start, uintptr_t size) |
| 16 |
{ |
| 17 |
uintptr_t end; |
| 18 |
uintptr_t addr; |
| 19 |
|
| 20 |
end = start + (ALIGN_UP(size, 4096)); |
| 21 |
for (addr = start; addr < end; addr += 64) |
| 22 |
clflush((void *)addr); |
| 23 |
} |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
bool load_ibb(uint32_t ibb_dest, uint32_t ibb_size) |
| 31 |
{ |
| 32 |
uint32_t host_to_cse = (ibb_size << 4) | 0xc0000000; |
| 33 |
uint32_t cse_to_host; |
| 34 |
uint32_t state; |
| 35 |
uint8_t ring_index; |
| 36 |
|
| 37 |
uint32_t chunk_num; |
| 38 |
uint32_t chunk_index = 0; |
| 39 |
uint32_t chunk_size; |
| 40 |
uint32_t number_of_chunks; |
| 41 |
uint32_t ibb_size_left; |
| 42 |
|
| 43 |
uint8_t *dst; |
| 44 |
uint8_t *src; |
| 45 |
uint32_t size; |
| 46 |
|
| 47 |
|
| 48 |
if ((pci_read_config32(PCH_DEV_CSE, 0) != |
| 49 |
((PCI_DID_INTEL_APL_CSE0 << 16) | PCI_VID_INTEL)) && |
| 50 |
(pci_read_config32(PCH_DEV_CSE, 0) != |
| 51 |
((PCI_DID_INTEL_GLK_CSE0 << 16) | PCI_VID_INTEL))) |
| 52 |
return -1; |
| 53 |
|
| 54 |
|
| 55 |
pci_write_config32(PCH_DEV_CSE, HOST2CSE, host_to_cse); |
| 56 |
|
| 57 |
|
| 58 |
do { |
| 59 |
cse_to_host = pci_read_config32(PCH_DEV_CSE, CSE2HOST); |
| 60 |
chunk_num = (cse_to_host >> 28) & 3; |
| 61 |
} while (chunk_num == 0); |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
if (chunk_num == 3) |
| 68 |
chunk_num = 4; |
| 69 |
|
| 70 |
|
| 71 |
number_of_chunks = chunk_num; |
| 72 |
|
| 73 |
ibb_size_left = (cse_to_host & 0x0fffc000) >> 4; |
| 74 |
ibb_size = ibb_size_left; |
| 75 |
chunk_size = SHARED_SRAM_SIZE / number_of_chunks; |
| 76 |
|
| 77 |
|
| 78 |
while (ibb_size_left > 0) { |
| 79 |
|
| 80 |
|
| 81 |
state = (cse_to_host ^ host_to_cse) & 0x0f; |
| 82 |
while (state == 0) { |
| 83 |
cse_to_host = pci_read_config32(PCH_DEV_CSE, CSE2HOST); |
| 84 |
state = (cse_to_host ^ host_to_cse) & 0x0f; |
| 85 |
} |
| 86 |
|
| 87 |
|
| 88 |
ring_index = (uint8_t)(chunk_index % number_of_chunks); |
| 89 |
if ((state & (1 << ring_index)) != 0) { |
| 90 |
|
| 91 |
src = (uint8_t *)(uintptr_t) |
| 92 |
(SHARED_SRAM_BASE + chunk_size * ring_index); |
| 93 |
dst = (uint8_t *)(uintptr_t) |
| 94 |
(ibb_dest + chunk_size * chunk_index); |
| 95 |
|
| 96 |
if (ibb_size_left < chunk_size) |
| 97 |
size = ibb_size_left; |
| 98 |
else |
| 99 |
size = chunk_size; |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
if (size > CSE_RBP_LIMIT) |
| 108 |
die("CSE RBP capabilities exceeded!\n"); |
| 109 |
|
| 110 |
|
| 111 |
if ((uint32_t)src >= SHARED_SRAM_BASE) |
| 112 |
flush_cache((uint32_t)(uint32_t)src, size); |
| 113 |
|
| 114 |
memcpy(dst, src, size); |
| 115 |
assert(!memcmp(dst, src, size)); |
| 116 |
ibb_size_left -= size; |
| 117 |
|
| 118 |
|
| 119 |
host_to_cse ^= 1 << ring_index; |
| 120 |
pci_write_config32(PCH_DEV_CSE, HOST2CSE, host_to_cse); |
| 121 |
|
| 122 |
chunk_index++; |
| 123 |
} |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
do { |
| 128 |
cse_to_host = pci_read_config32(PCH_DEV_CSE, CSE2HOST); |
| 129 |
} while ((cse_to_host & (BIT(10))) == 0); |
| 130 |
|
| 131 |
if ((cse_to_host & ((BIT(9)))) != 0) |
| 132 |
printk(BIOS_DEBUG, "CSE RBP: IBBM loaded to CAR!\n"); |
| 133 |
|
| 134 |
|
| 135 |
clear_mca_bank4(); |
| 136 |
|
| 137 |
return 0; |
| 138 |
} |