From 205ed2d2b58f9b93c7c665002aef0c775e64cf63 Mon Sep 17 00:00:00 2001 From: Duncan Laurie Date: Thu, 2 Jun 2016 15:23:42 -0700 Subject: skylake: Add function to set PRR for protecting flash Add a function similar to broadwell to set the PRR for a region of flash and protect it from writes. This is used to secure the MRC cache region if the SPI is write protected. BUG=chrome-os-partner:54003 BRANCH=glados TEST=boot on chell, verify PRR register is set and that the MRC cache region cannot be written if the SPI is write protected. Change-Id: I925ec9ce186f7adac327bca9c96255325b7f54ec Signed-off-by: Duncan Laurie Original-Commit-Id: abb6f645f5ceef3f52bb7afd2632212ea916ff8d Original-Change-Id: I2f90556a217b35b7c93645e41a1fcfe8070c53da Original-Signed-off-by: Duncan Laurie Original-Reviewed-on: https://chromium-review.googlesource.com/349274 Original-Reviewed-by: Shawn N Original-Reviewed-by: Aaron Durbin Original-Tested-by: Shawn N Reviewed-on: https://review.coreboot.org/15102 Tested-by: build bot (Jenkins) Reviewed-by: Aaron Durbin Reviewed-by: Leroy P Leahy Reviewed-by: Paul Menzel --- src/soc/intel/skylake/flash_controller.c | 37 ++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/soc/intel/skylake/flash_controller.c') diff --git a/src/soc/intel/skylake/flash_controller.c b/src/soc/intel/skylake/flash_controller.c index 0af0484082..3507b471cc 100644 --- a/src/soc/intel/skylake/flash_controller.c +++ b/src/soc/intel/skylake/flash_controller.c @@ -386,6 +386,43 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs) return slave; } +int spi_flash_protect(u32 start, u32 size) +{ + pch_spi_regs *spi_bar = get_spi_bar(); + u32 end = start + size - 1; + u32 reg; + int prr; + + if (!spi_bar) + return -1; + + /* Find first empty PRR */ + for (prr = 0; prr < SPI_PRR_MAX; prr++) { + reg = read32(&spi_bar->pr[prr]); + if (reg == 0) + break; + } + if (prr >= SPI_PRR_MAX) { + printk(BIOS_ERR, "ERROR: No SPI PRR free!\n"); + return -1; + } + + /* Set protected range base and limit */ + reg = SPI_PRR(start, end) | SPI_PRR_WPE; + + /* Set the PRR register and verify it is protected */ + write32(&spi_bar->pr[prr], reg); + reg = read32(&spi_bar->pr[prr]); + if (!(reg & SPI_PRR_WPE)) { + printk(BIOS_ERR, "ERROR: Unable to set SPI PRR %d\n", prr); + return -1; + } + + printk(BIOS_INFO, "%s: PRR %d is enabled for range 0x%08x-0x%08x\n", + __func__, prr, start, end); + return 0; +} + #if ENV_RAMSTAGE /* * spi_init() needs run unconditionally in every boot (including resume) to -- cgit v1.2.3