diff options
author | Jack Miller <distroguy@gmail.com> | 2016-11-29 14:18:22 +1100 |
---|---|---|
committer | Stewart Smith <stewart@linux.vnet.ibm.com> | 2016-12-13 16:49:45 +1100 |
commit | 67265323132888e8b12788542fc7b33b340cc28b (patch) | |
tree | 0e253d5270f4ce63d4aed1a3389cf5d717aca21b | |
parent | 4a6d1a70f0fe50ceb8176f2d6d0fc612f8e32589 (diff) | |
download | skiboot-67265323132888e8b12788542fc7b33b340cc28b.zip skiboot-67265323132888e8b12788542fc7b33b340cc28b.tar.gz skiboot-67265323132888e8b12788542fc7b33b340cc28b.tar.bz2 |
mambo: Add Fake NVRAM driver
Implement a fake NVRAM device based on arbitrary memory reserves.
This allows NVRAM images to be preloaded without the FSP.
Signed-off-by: Jack Miller <jack@codezen.org>
Tested-by: Chris Smart <chris@distroguy.com>
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
-rw-r--r-- | core/platform.c | 3 | ||||
-rw-r--r-- | hw/Makefile.inc | 1 | ||||
-rw-r--r-- | hw/fake-nvram.c | 62 | ||||
-rw-r--r-- | include/skiboot.h | 5 |
4 files changed, 71 insertions, 0 deletions
diff --git a/core/platform.c b/core/platform.c index ba0636d..4e1c691 100644 --- a/core/platform.c +++ b/core/platform.c @@ -136,6 +136,9 @@ static struct platform generic_platform = { .bmc = &generic_bmc, .probe = generic_platform_probe, .init = generic_platform_init, + .nvram_info = fake_nvram_info, + .nvram_start_read = fake_nvram_start_read, + .nvram_write = fake_nvram_write, .cec_power_down = generic_cec_power_down, }; diff --git a/hw/Makefile.inc b/hw/Makefile.inc index a433c2b..f2dc328 100644 --- a/hw/Makefile.inc +++ b/hw/Makefile.inc @@ -6,6 +6,7 @@ HW_OBJS += nx.o nx-rng.o nx-crypto.o nx-842.o HW_OBJS += p7ioc.o p7ioc-inits.o p7ioc-phb.o HW_OBJS += phb3.o sfc-ctrl.o fake-rtc.o bt.o p8-i2c.o prd.o HW_OBJS += dts.o lpc-rtc.o npu.o npu-hw-procedures.o xive.o phb4.o +HW_OBJS += fake-nvram.o HW=hw/built-in.o # FIXME hack this for now diff --git a/hw/fake-nvram.c b/hw/fake-nvram.c new file mode 100644 index 0000000..99bee9f --- /dev/null +++ b/hw/fake-nvram.c @@ -0,0 +1,62 @@ +/* Copyright 2013-2014 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include <skiboot.h> +#include <opal.h> +#include <mem_region.h> +#include <lock.h> + +static struct mem_region *nvram_region = NULL; +static struct lock fake_nvram_lock = LOCK_UNLOCKED; + +int fake_nvram_info(uint32_t *total_size) +{ + nvram_region = find_mem_region("ibm,fake-nvram"); + + if(!nvram_region) + return OPAL_HARDWARE; + + *total_size = nvram_region->len; + + return OPAL_SUCCESS; +} + +int fake_nvram_start_read(void *dst, uint32_t src, uint32_t len) +{ + if(!nvram_region) + return -ENODEV; + + lock(&fake_nvram_lock); + memcpy(dst, (void *) (nvram_region->start + src), len); + unlock(&fake_nvram_lock); + + nvram_read_complete(true); + + return 0; +} + +int fake_nvram_write(uint32_t offset, void *src, uint32_t size) +{ + if(!nvram_region) + return OPAL_HARDWARE; + + lock(&fake_nvram_lock); + memcpy((void *) (nvram_region->start + offset), src, size); + unlock(&fake_nvram_lock); + + return 0; +} + diff --git a/include/skiboot.h b/include/skiboot.h index 3f7c077..2ea64de 100644 --- a/include/skiboot.h +++ b/include/skiboot.h @@ -292,4 +292,9 @@ extern void enter_pm_state(bool winkle); extern uint32_t reset_patch_start; extern uint32_t reset_patch_end; +/* Fallback fake NVRAM */ +extern int fake_nvram_info(uint32_t *total_size); +extern int fake_nvram_start_read(void *dst, uint32_t src, uint32_t len); +extern int fake_nvram_write(uint32_t offset, void *src, uint32_t size); + #endif /* __SKIBOOT_H */ |