| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
#include <boot_device.h> |
| 10 |
#include <commonlib/region.h> |
| 11 |
#include <console/console.h> |
| 12 |
#include <fast_spi_dma.h> |
| 13 |
#include <fmap.h> |
| 14 |
#include <intelblocks/fast_spi.h> |
| 15 |
#include <spi_flash.h> |
| 16 |
|
| 17 |
enum window_type { |
| 18 |
|
| 19 |
FIXED_DECODE_WINDOW, |
| 20 |
|
| 21 |
EXT_BIOS_DECODE_WINDOW, |
| 22 |
TOTAL_DECODE_WINDOWS, |
| 23 |
}; |
| 24 |
|
| 25 |
static struct xlate_region_device real_dev; |
| 26 |
static struct mem_region_device shadow_devs[TOTAL_DECODE_WINDOWS]; |
| 27 |
static struct xlate_window real_dev_windows[TOTAL_DECODE_WINDOWS]; |
| 28 |
|
| 29 |
static void initialize_window(enum window_type type, uintptr_t host_base, |
| 30 |
uintptr_t flash_base, size_t size) |
| 31 |
{ |
| 32 |
mem_region_device_ro_init(&shadow_devs[type], (void *)host_base, size); |
| 33 |
xlate_window_init(&real_dev_windows[type], &shadow_devs[type].rdev, |
| 34 |
flash_base, size); |
| 35 |
printk(BIOS_INFO, "%s: ", |
| 36 |
(type == FIXED_DECODE_WINDOW) ? |
| 37 |
"Fixed Decode Window" : "Extended Decode Window"); |
| 38 |
printk(BIOS_INFO, "SPI flash base=0x%lx, Host base=0x%lx, Size=0x%zx\n", |
| 39 |
flash_base, host_base, size); |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
static void bios_mmap_init(void) |
| 87 |
{ |
| 88 |
static bool init_done; |
| 89 |
|
| 90 |
size_t bios_size, bios_start; |
| 91 |
|
| 92 |
uintptr_t fixed_win_host_base, fixed_win_flash_base; |
| 93 |
uintptr_t ext_win_host_base, ext_win_flash_base; |
| 94 |
size_t fixed_win_size, ext_win_size; |
| 95 |
|
| 96 |
size_t win_count = 0; |
| 97 |
|
| 98 |
if (init_done) |
| 99 |
return; |
| 100 |
|
| 101 |
|
| 102 |
bios_start = fast_spi_get_bios_region(&bios_size); |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
fixed_win_size = MIN(16 * MiB, bios_size); |
| 110 |
fixed_win_host_base = 4ULL * GiB - fixed_win_size; |
| 111 |
fixed_win_flash_base = bios_start + bios_size - fixed_win_size; |
| 112 |
|
| 113 |
initialize_window(FIXED_DECODE_WINDOW, fixed_win_host_base, fixed_win_flash_base, |
| 114 |
fixed_win_size); |
| 115 |
win_count++; |
| 116 |
|
| 117 |
_Static_assert(CONFIG_EXT_BIOS_WIN_BASE != 0, "Extended BIOS window base cannot be 0!"); |
| 118 |
_Static_assert(CONFIG_EXT_BIOS_WIN_SIZE != 0, "Extended BIOS window size cannot be 0!"); |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
ext_win_size = MIN(CONFIG_EXT_BIOS_WIN_SIZE, bios_size - fixed_win_size); |
| 128 |
|
| 129 |
if (ext_win_size) { |
| 130 |
ext_win_host_base = CONFIG_EXT_BIOS_WIN_BASE + CONFIG_EXT_BIOS_WIN_SIZE - |
| 131 |
ext_win_size; |
| 132 |
ext_win_flash_base = fixed_win_flash_base - ext_win_size; |
| 133 |
initialize_window(EXT_BIOS_DECODE_WINDOW, ext_win_host_base, |
| 134 |
ext_win_flash_base, ext_win_size); |
| 135 |
win_count++; |
| 136 |
} |
| 137 |
|
| 138 |
xlate_region_device_ro_init(&real_dev, win_count, real_dev_windows, CONFIG_ROM_SIZE); |
| 139 |
|
| 140 |
init_done = true; |
| 141 |
} |
| 142 |
|
| 143 |
const struct region_device *boot_device_ro(void) |
| 144 |
{ |
| 145 |
bios_mmap_init(); |
| 146 |
|
| 147 |
if (fast_spi_dma_is_supported()) |
| 148 |
spi_flash_dma_install_ops(&real_dev); |
| 149 |
|
| 150 |
return &real_dev.rdev; |
| 151 |
} |
| 152 |
|
| 153 |
void fast_spi_get_ext_bios_window(uintptr_t *base, size_t *size) |
| 154 |
{ |
| 155 |
const struct region_device *rd = &shadow_devs[EXT_BIOS_DECODE_WINDOW].rdev; |
| 156 |
|
| 157 |
bios_mmap_init(); |
| 158 |
|
| 159 |
*size = region_device_sz(rd); |
| 160 |
|
| 161 |
if (*size == 0) { |
| 162 |
*base = 0; |
| 163 |
} else { |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
*base = (uintptr_t)rdev_mmap_full(rd); |
| 169 |
} |
| 170 |
} |
| 171 |
|
| 172 |
uint32_t spi_flash_get_mmap_windows(struct flash_mmap_window *table) |
| 173 |
{ |
| 174 |
int i; |
| 175 |
uint32_t count = 0; |
| 176 |
|
| 177 |
bios_mmap_init(); |
| 178 |
|
| 179 |
for (i = 0; i < TOTAL_DECODE_WINDOWS; i++) { |
| 180 |
if (region_sz(&real_dev_windows[i].sub_region) == 0) |
| 181 |
continue; |
| 182 |
|
| 183 |
count++; |
| 184 |
table->flash_base = region_offset(&real_dev_windows[i].sub_region); |
| 185 |
table->host_base = (uintptr_t)rdev_mmap_full(&shadow_devs[i].rdev); |
| 186 |
table->size = region_sz(&real_dev_windows[i].sub_region); |
| 187 |
|
| 188 |
table++; |
| 189 |
} |
| 190 |
|
| 191 |
return count; |
| 192 |
} |