| 1 |
|
| 2 |
|
| 3 |
#include <cf9_reset.h> |
| 4 |
#include <commonlib/region.h> |
| 5 |
#include <console/console.h> |
| 6 |
#include <cpu/cpu.h> |
| 7 |
#include <cpu/intel/cpu_ids.h> |
| 8 |
#include <device/mmio.h> |
| 9 |
#include <fmap.h> |
| 10 |
#include <intelblocks/pmclib.h> |
| 11 |
#include <soc/bootblock.h> |
| 12 |
#include <types.h> |
| 13 |
|
| 14 |
|
| 15 |
#define FLMSTR1 0x80 |
| 16 |
|
| 17 |
|
| 18 |
#define FLASH_SIGN_OFFSET 0x10 |
| 19 |
#define FLMSTR_WR_SHIFT_V2 20 |
| 20 |
#define FLASH_VAL_SIGN 0xFF0A55A |
| 21 |
|
| 22 |
|
| 23 |
static bool is_descriptor_writeable(uint8_t *desc) |
| 24 |
{ |
| 25 |
|
| 26 |
if (read32p((uintptr_t)(desc + FLASH_SIGN_OFFSET)) != FLASH_VAL_SIGN) { |
| 27 |
printk(BIOS_ERR, "Flash Descriptor is not valid\n"); |
| 28 |
return false; |
| 29 |
} |
| 30 |
|
| 31 |
|
| 32 |
if (!((read32p((uintptr_t)(desc + FLMSTR1)) >> FLMSTR_WR_SHIFT_V2) & BIT(0))) { |
| 33 |
printk(BIOS_ERR, "Host doesn't have write access to Descriptor Region\n"); |
| 34 |
return false; |
| 35 |
} |
| 36 |
|
| 37 |
return true; |
| 38 |
} |
| 39 |
|
| 40 |
void configure_descriptor(struct descriptor_byte *bytes, size_t num) |
| 41 |
{ |
| 42 |
uint8_t si_desc_buf[CONFIG_SI_DESC_REGION_SZ]; |
| 43 |
struct region_device desc_rdev; |
| 44 |
bool update_required = false; |
| 45 |
|
| 46 |
if (fmap_locate_area_as_rdev_rw(CONFIG_SI_DESC_REGION, &desc_rdev) < 0) { |
| 47 |
printk(BIOS_ERR, "Failed to locate %s in the FMAP\n", CONFIG_SI_DESC_REGION); |
| 48 |
return; |
| 49 |
} |
| 50 |
|
| 51 |
if (rdev_readat(&desc_rdev, si_desc_buf, 0, CONFIG_SI_DESC_REGION_SZ) != |
| 52 |
CONFIG_SI_DESC_REGION_SZ) { |
| 53 |
printk(BIOS_ERR, "Failed to read Descriptor Region from SPI Flash\n"); |
| 54 |
return; |
| 55 |
} |
| 56 |
|
| 57 |
if (!is_descriptor_writeable(si_desc_buf)) |
| 58 |
return; |
| 59 |
|
| 60 |
for (size_t i = 0; i < num; i++) { |
| 61 |
size_t offset = bytes[i].offset; |
| 62 |
uint8_t desired_value = bytes[i].desired_value; |
| 63 |
printk(BIOS_DEBUG, "Current value of Descriptor byte 0x%zx: 0x%x\n", |
| 64 |
offset, si_desc_buf[offset]); |
| 65 |
if (si_desc_buf[offset] != desired_value) { |
| 66 |
update_required = true; |
| 67 |
si_desc_buf[offset] = desired_value; |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
if (!update_required) { |
| 72 |
printk(BIOS_DEBUG, "Update of Descriptor is not required!\n"); |
| 73 |
return; |
| 74 |
} |
| 75 |
|
| 76 |
if (rdev_eraseat(&desc_rdev, 0, CONFIG_SI_DESC_REGION_SZ) != CONFIG_SI_DESC_REGION_SZ) { |
| 77 |
printk(BIOS_ERR, "Failed to erase Descriptor Region area\n"); |
| 78 |
return; |
| 79 |
} |
| 80 |
|
| 81 |
if (rdev_writeat(&desc_rdev, si_desc_buf, 0, CONFIG_SI_DESC_REGION_SZ) |
| 82 |
!= CONFIG_SI_DESC_REGION_SZ) { |
| 83 |
printk(BIOS_ERR, "Failed to update Descriptor Region\n"); |
| 84 |
return; |
| 85 |
} |
| 86 |
|
| 87 |
printk(BIOS_DEBUG, "Update of Descriptor successful, trigger GLOBAL RESET\n"); |
| 88 |
|
| 89 |
pmc_global_reset_enable(true); |
| 90 |
do_full_reset(); |
| 91 |
die("Failed to trigger GLOBAL RESET\n"); |
| 92 |
} |