aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2015-02-19 06:34:53 +0800
committerStewart Smith <stewart@linux.vnet.ibm.com>2015-02-19 10:49:08 +1100
commit348d5c4875ec46792d1749a88ec7457c62650e08 (patch)
tree9daa0bc9004320f8b3ab2e152f89d271ed3e1a62 /core
parent73b262e768529f152ec64b4418b0c31691bc15c3 (diff)
downloadskiboot-348d5c4875ec46792d1749a88ec7457c62650e08.zip
skiboot-348d5c4875ec46792d1749a88ec7457c62650e08.tar.gz
skiboot-348d5c4875ec46792d1749a88ec7457c62650e08.tar.bz2
core/flash: Move flash NVRAM handling to new flash module
Since we want to prevent conflicts between PNOR and NVRAM, this change moves the flash-nvram handling out of flash-nvram.c and into the generic flash module. This way, the OPAL_FLASH_{READ,WRITE,ERASE} API won't conflict with the OPAL_*_NVRAM api. To do this, we use the flash_register function to look for an "NVRAM" partition. If one is found, it is automatically registered as the system NVRAM backend. We also change the rhesus and astmbc platforms to use the common flash code. Signed-off-by: Jeremy Kerr <jk@ozlabs.org> Reviewed-by: Joel Stanley <joel@jms.id.au> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Diffstat (limited to 'core')
-rw-r--r--core/Makefile.inc2
-rw-r--r--core/flash-nvram.c76
-rw-r--r--core/flash.c107
3 files changed, 105 insertions, 80 deletions
diff --git a/core/Makefile.inc b/core/Makefile.inc
index 1a4e466..590780f 100644
--- a/core/Makefile.inc
+++ b/core/Makefile.inc
@@ -5,7 +5,7 @@ CORE_OBJS = relocate.o console.o stack.o init.o chip.o mem_region.o
CORE_OBJS += malloc.o lock.o cpu.o utils.o fdt.o opal.o interrupts.o
CORE_OBJS += timebase.o opal-msg.o pci.o pci-opal.o fast-reboot.o
CORE_OBJS += device.o exceptions.o trace.o affinity.o vpd.o
-CORE_OBJS += hostservices.o platform.o nvram.o flash-nvram.o hmi.o
+CORE_OBJS += hostservices.o platform.o nvram.o hmi.o
CORE_OBJS += console-log.o ipmi.o time-utils.o pel.o pool.o errorlog.o
CORE_OBJS += timer.o i2c.o rtc.o flash.o
CORE=core/built-in.o
diff --git a/core/flash-nvram.c b/core/flash-nvram.c
deleted file mode 100644
index 7e261b1..0000000
--- a/core/flash-nvram.c
+++ /dev/null
@@ -1,76 +0,0 @@
-/* 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 <device.h>
-#include <console.h>
-#include <opal.h>
-#include <platform.h>
-#include <libflash/libflash.h>
-
-static struct flash_chip *fl_nv_chip;
-static uint32_t fl_nv_start, fl_nv_size;
-
-static int flash_nvram_info(uint32_t *total_size)
-{
- if (!fl_nv_chip)
- return OPAL_HARDWARE;
- *total_size = fl_nv_size;
- return OPAL_SUCCESS;
-}
-
-static int flash_nvram_start_read(void *dst, uint32_t src, uint32_t len)
-{
- int rc;
-
- if ((src + len) > fl_nv_size) {
- prerror("FLASH_NVRAM: read out of bound (0x%x,0x%x)\n",
- src, len);
- return OPAL_PARAMETER;
- }
- rc = flash_read(fl_nv_chip, fl_nv_start + src, dst, len);
- if (rc)
- return rc;
- nvram_read_complete(true);
- return 0;
-}
-
-static int flash_nvram_write(uint32_t dst, void *src, uint32_t len)
-{
- /* TODO: When we have async jobs for PRD, turn this into one */
-
- if ((dst + len) > fl_nv_size) {
- prerror("FLASH_NVRAM: write out of bound (0x%x,0x%x)\n",
- dst, len);
- return OPAL_PARAMETER;
- }
- return flash_smart_write(fl_nv_chip, fl_nv_start + dst, src, len);
-}
-
-int flash_nvram_init(struct flash_chip *chip, uint32_t start, uint32_t size)
-{
- fl_nv_chip = chip;
- fl_nv_start = start;
- fl_nv_size = size;
-
- platform.nvram_info = flash_nvram_info;
- platform.nvram_start_read = flash_nvram_start_read;
- platform.nvram_write = flash_nvram_write;
-
- return 0;
-}
-
diff --git a/core/flash.c b/core/flash.c
index c6b01ad..b24ceaa 100644
--- a/core/flash.c
+++ b/core/flash.c
@@ -37,6 +37,105 @@ static struct flash *system_flash;
/* Using a single lock as we only have one flash at present. */
static struct lock flash_lock;
+/* nvram-on-flash support */
+static struct flash *nvram_flash;
+static u32 nvram_offset, nvram_size;
+
+static int flash_nvram_info(uint32_t *total_size)
+{
+ int rc = OPAL_HARDWARE;
+
+ lock(&flash_lock);
+ if (nvram_flash) {
+ *total_size = nvram_size;
+ rc = OPAL_SUCCESS;
+ }
+ unlock(&flash_lock);
+
+ return rc;
+}
+
+static int flash_nvram_start_read(void *dst, uint32_t src, uint32_t len)
+{
+ int rc;
+
+ lock(&flash_lock);
+
+ if (!nvram_flash) {
+ rc = OPAL_HARDWARE;
+ goto out;
+ }
+
+ if ((src + len) > nvram_size) {
+ prerror("FLASH_NVRAM: read out of bound (0x%x,0x%x)\n",
+ src, len);
+ rc = OPAL_PARAMETER;
+ goto out;
+ }
+
+ rc = flash_read(nvram_flash->chip, nvram_offset + src, dst, len);
+
+out:
+ unlock(&flash_lock);
+ if (!rc)
+ nvram_read_complete(true);
+ return rc;
+}
+
+static int flash_nvram_write(uint32_t dst, void *src, uint32_t len)
+{
+ int rc;
+
+ lock(&flash_lock);
+
+ /* TODO: When we have async jobs for PRD, turn this into one */
+
+ if ((dst + len) > nvram_size) {
+ prerror("FLASH_NVRAM: write out of bound (0x%x,0x%x)\n",
+ dst, len);
+ rc = OPAL_PARAMETER;
+ goto out;
+ }
+ rc = flash_smart_write(nvram_flash->chip, nvram_offset + dst, src, len);
+
+out:
+ unlock(&flash_lock);
+ return rc;
+}
+
+static int flash_nvram_probe(struct flash *flash, struct ffs_handle *ffs)
+{
+ uint32_t start, size, part;
+ int rc;
+
+ prlog(PR_INFO, "FLASH: probing for NVRAM\n");
+
+ rc = ffs_lookup_part(ffs, "NVRAM", &part);
+ if (rc) {
+ prlog(PR_WARNING, "FLASH: no NVRAM partition found\n");
+ return OPAL_HARDWARE;
+ }
+
+ rc = ffs_part_info(ffs, part, NULL,
+ &start, &size, NULL);
+ if (rc) {
+ prlog(PR_ERR, "FLASH: Can't parse ffs info for NVRAM\n");
+ return OPAL_HARDWARE;
+ }
+
+ nvram_flash = flash;
+ nvram_offset = start;
+ nvram_size = size;
+
+ platform.nvram_info = flash_nvram_info;
+ platform.nvram_start_read = flash_nvram_start_read;
+ platform.nvram_write = flash_nvram_write;
+
+ return 0;
+}
+
+/* core flash support */
+
static void flash_add_dt_partition_node(struct dt_node *flash_node, char *name,
uint32_t start, uint32_t size)
{
@@ -124,11 +223,13 @@ int flash_register(struct flash_chip *chip, bool is_system_flash)
ffs = NULL;
}
- if (is_system_flash && !system_flash)
- system_flash = flash;
-
flash_add_dt_node(flash, i, ffs);
+ if (is_system_flash && !system_flash) {
+ system_flash = flash;
+ flash_nvram_probe(flash, ffs);
+ }
+
ffs_close(ffs);
unlock(&flash_lock);