Author: agraf Date: Thu Jul 11 18:49:26 2013 New Revision: 1170 URL: http://tracker.coreboot.org/trac/openbios/changeset/1170
Log: Macio: Fetch nvram offset from fw_cfg if available
We want the hypervisor to tell us where NVRAM lies so that we do not have to rely on hardcoded addresses for it.
Introduce a new fw_cfg interface that allows us to receive it at runtime.
Signed-off-by: Alexander Graf agraf@suse.de
Modified: trunk/openbios-devel/drivers/macio.c trunk/openbios-devel/include/arch/common/fw_cfg.h
Modified: trunk/openbios-devel/drivers/macio.c ============================================================================== --- trunk/openbios-devel/drivers/macio.c Sun Jun 30 05:13:14 2013 (r1169) +++ trunk/openbios-devel/drivers/macio.c Thu Jul 11 18:49:26 2013 (r1170) @@ -43,6 +43,30 @@ return NW_IO_NVRAM_SIZE >> NW_IO_NVRAM_SHIFT; }
+static unsigned long macio_nvram_offset(void) +{ + unsigned long r; + + /* Hypervisor tells us where NVRAM lies */ + r = fw_cfg_read_i32(FW_CFG_PPC_NVRAM_ADDR); + if (r) + return r; + + /* Fall back to hardcoded addresses */ + if (is_oldworld()) + return OW_IO_NVRAM_OFFSET; + + return NW_IO_NVRAM_OFFSET; +} + +static unsigned long macio_nvram_size(void) +{ + if (is_oldworld()) + return OW_IO_NVRAM_SIZE; + else + return NW_IO_NVRAM_SIZE; +} + void macio_nvram_init(const char *path, phys_addr_t addr) { phandle_t chosen, aliases; @@ -51,13 +75,9 @@ char buf[64]; unsigned long nvram_size, nvram_offset;
- if (is_oldworld()) { - nvram_offset = OW_IO_NVRAM_OFFSET; - nvram_size = OW_IO_NVRAM_SIZE; - } else { - nvram_offset = NW_IO_NVRAM_OFFSET; - nvram_size = NW_IO_NVRAM_SIZE; - } + nvram_offset = macio_nvram_offset(); + nvram_size = macio_nvram_size(); + nvram = (char*)addr + nvram_offset; snprintf(buf, sizeof(buf), "%s/nvram", path); nvram_init(buf);
Modified: trunk/openbios-devel/include/arch/common/fw_cfg.h ============================================================================== --- trunk/openbios-devel/include/arch/common/fw_cfg.h Sun Jun 30 05:13:14 2013 (r1169) +++ trunk/openbios-devel/include/arch/common/fw_cfg.h Thu Jul 11 18:49:26 2013 (r1170) @@ -44,6 +44,7 @@ #define FW_CFG_PPC_IS_KVM (FW_CFG_ARCH_LOCAL + 0x05) #define FW_CFG_PPC_KVM_HC (FW_CFG_ARCH_LOCAL + 0x06) #define FW_CFG_PPC_KVM_PID (FW_CFG_ARCH_LOCAL + 0x07) +#define FW_CFG_PPC_NVRAM_ADDR (FW_CFG_ARCH_LOCAL + 0x08)
#define FW_CFG_INVALID 0xffff