summaryrefslogtreecommitdiff
path: root/util/nvramtool
diff options
context:
space:
mode:
authorPatrick Georgi <patrick.georgi@secunet.com>2011-01-21 07:19:59 +0000
committerPatrick Georgi <patrick.georgi@coresystems.de>2011-01-21 07:19:59 +0000
commit9cd7eba1180396cbd91776a94444696f6b4069c4 (patch)
treeb378bf872b031931f7a8401fb678d56961689a59 /util/nvramtool
parentbe5a178de731dd6b255c38c1e63b3de8b3008a14 (diff)
downloadcoreboot-9cd7eba1180396cbd91776a94444696f6b4069c4.tar.xz
Add support for working on in-memory CMOS data (eg.
as loaded from a file). Signed-off-by: Patrick Georgi <patrick.georgi@secunet.com> Acked-by: Stefan Reinauer <stepan@coreboot.org> git-svn-id: svn://svn.coreboot.org/coreboot/trunk@6284 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
Diffstat (limited to 'util/nvramtool')
-rw-r--r--util/nvramtool/cmos_lowlevel.c58
-rw-r--r--util/nvramtool/cmos_lowlevel.h3
2 files changed, 60 insertions, 1 deletions
diff --git a/util/nvramtool/cmos_lowlevel.c b/util/nvramtool/cmos_lowlevel.c
index 9f44a0b18a..8e19f515aa 100644
--- a/util/nvramtool/cmos_lowlevel.c
+++ b/util/nvramtool/cmos_lowlevel.c
@@ -37,20 +37,36 @@
#include "cmos_lowlevel.h"
/* Hardware Abstraction Layer: lowlevel byte-wise write access */
+
typedef struct {
void (*init)(void* data);
unsigned char (*read)(unsigned addr);
void (*write)(unsigned addr, unsigned char value);
+ void (*set_iopl)(int level);
} cmos_access_t;
static void cmos_hal_init(void* data);
static unsigned char cmos_hal_read(unsigned addr);
static void cmos_hal_write(unsigned addr, unsigned char value);
+static void cmos_set_iopl(int level);
static cmos_access_t cmos_hal = {
.init = cmos_hal_init,
.read = cmos_hal_read,
- .write = cmos_hal_write
+ .write = cmos_hal_write,
+ .set_iopl = cmos_set_iopl,
+};
+
+static void mem_hal_init(void* data);
+static unsigned char mem_hal_read(unsigned addr);
+static void mem_hal_write(unsigned addr, unsigned char value);
+static void mem_set_iopl(int level);
+
+static cmos_access_t memory_hal = {
+ .init = mem_hal_init,
+ .read = mem_hal_read,
+ .write = mem_hal_write,
+ .set_iopl = mem_set_iopl,
};
static cmos_access_t *current_access = &cmos_hal;
@@ -96,6 +112,37 @@ static void cmos_hal_write(unsigned index, unsigned char value)
OUTB(value, port_1);
}
+static unsigned char* mem_hal_data = (unsigned char*)-1;
+static void mem_hal_init(void *data)
+{
+ mem_hal_data = data;
+}
+
+static unsigned char mem_hal_read(unsigned index)
+{
+ assert(mem_hal_data != (unsigned char*)-1);
+ return mem_hal_data[index];
+}
+
+static void mem_hal_write(unsigned index, unsigned char value)
+{
+ assert(mem_hal_data != (unsigned char*)-1);
+ mem_hal_data[index] = value;
+}
+
+void select_hal(hal_t hal, void *data)
+{
+ switch(hal) {
+ case HAL_CMOS:
+ current_access = &cmos_hal;
+ break;
+ case HAL_MEMORY:
+ current_access = &memory_hal;
+ break;
+ }
+ current_access->init(data);
+}
+
/* Bit-level access */
typedef struct {
unsigned byte_index;
@@ -303,6 +350,11 @@ void cmos_write_all(unsigned char data[])
****************************************************************************/
void set_iopl(int level)
{
+ current_access->set_iopl(level);
+}
+
+static void cmos_set_iopl(int level)
+{
#if defined(__FreeBSD__)
static int io_fd = -1;
#endif
@@ -333,6 +385,10 @@ void set_iopl(int level)
#endif
}
+static void mem_set_iopl(__attribute__ ((unused)) int level)
+{
+}
+
/****************************************************************************
* verify_cmos_op
*
diff --git a/util/nvramtool/cmos_lowlevel.h b/util/nvramtool/cmos_lowlevel.h
index ebe82a7a11..3c2efce1e1 100644
--- a/util/nvramtool/cmos_lowlevel.h
+++ b/util/nvramtool/cmos_lowlevel.h
@@ -34,6 +34,9 @@
#include "common.h"
#include "layout.h"
+typedef enum { HAL_CMOS, HAL_MEMORY } hal_t;
+void select_hal(hal_t hal, void *data);
+
#define CMOS_AREA_OUT_OF_RANGE (CMOS_RESULT_START + 0)
#define CMOS_AREA_OVERLAPS_RTC (CMOS_RESULT_START + 1)
#define CMOS_AREA_TOO_WIDE (CMOS_RESULT_START + 2)