Patchwork nvramtool: Abstract CMOS accesses

login
register
about
Submitter Patrick Georgi
Date 2011-01-20 13:34:07
Message ID <1295530447.10580.23.camel@linux-0a8x.site>
Download mbox | patch
Permalink /patch/2540/
State Accepted
Headers show

Comments

Patrick Georgi - 2011-01-20 13:34:07
Hi,

in preparation of teaching nvramtool to edit files instead of real
hardware, this patch abstracts CMOS accesses a bit more.

Signed-off-by: Patrick Georgi <patrick.georgi@secunet.com>
Stefan Reinauer - 2011-01-20 18:42:48
* Georgi, Patrick <Patrick.Georgi@secunet.com> [110120 14:34]:
> Hi,
> 
> in preparation of teaching nvramtool to edit files instead of real
> hardware, this patch abstracts CMOS accesses a bit more.
> 
> Signed-off-by: Patrick Georgi <patrick.georgi@secunet.com>

Signed-off-by: Stefan Reinauer <stepan@coreboot.org>
Stefan Reinauer - 2011-01-21 07:11:37
* Stefan Reinauer <stefan.reinauer@coreboot.org> [110120 19:42]:
> * Georgi, Patrick <Patrick.Georgi@secunet.com> [110120 14:34]:
> > Hi,
> > 
> > in preparation of teaching nvramtool to edit files instead of real
> > hardware, this patch abstracts CMOS accesses a bit more.
> > 
> > Signed-off-by: Patrick Georgi <patrick.georgi@secunet.com>
> 
> Signed-off-by: Stefan Reinauer <stepan@coreboot.org>
 
Silly me. This was of course supposed to be an

Acked-by: Stefan Reinauer <stepan@coreboot.org>
Peter Stuge - 2011-01-21 09:16:08
Georgi, Patrick wrote:
> in preparation of teaching nvramtool to edit files instead of real
> hardware, this patch abstracts CMOS accesses a bit more.
> 
> Signed-off-by: Patrick Georgi <patrick.georgi@secunet.com>

Acked-by: Peter Stuge <peter@stuge.se>

Patch

Index: coreboot/util/nvramtool/cmos_lowlevel.c

===================================================================
--- coreboot.orig/util/nvramtool/cmos_lowlevel.c

+++ coreboot/util/nvramtool/cmos_lowlevel.c

@@ -36,6 +36,67 @@ 

 #include "common.h"
 #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);

+} 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 cmos_access_t cmos_hal = {

+	.init = cmos_hal_init,

+	.read = cmos_hal_read,

+	.write = cmos_hal_write

+};

+

+static cmos_access_t *current_access = &cmos_hal;

+

+/* no need to initialize anything */

+static void cmos_hal_init(__attribute__((unused)) void *data)

+{

+}

+

+static unsigned char cmos_hal_read(unsigned index)

+{

+	unsigned short port_0, port_1;

+

+	assert(!verify_cmos_byte_index(index));

+

+	if (index < 128) {

+		port_0 = 0x70;

+		port_1 = 0x71;

+	} else {

+		port_0 = 0x72;

+		port_1 = 0x73;

+	}

+

+	OUTB(index, port_0);

+	return INB(port_1);

+}

+

+static void cmos_hal_write(unsigned index, unsigned char value)

+{

+	unsigned short port_0, port_1;

+

+	assert(!verify_cmos_byte_index(index));

+

+	if (index < 128) {

+		port_0 = 0x70;

+		port_1 = 0x71;

+	} else {

+		port_0 = 0x72;

+		port_1 = 0x73;

+	}

+

+	OUTB(index, port_0);

+	OUTB(value, port_1);

+}

+

+/* Bit-level access */

 typedef struct {
 	unsigned byte_index;
 	unsigned bit_offset;
@@ -181,20 +242,7 @@  void cmos_write(const cmos_entry_t * e,

  ****************************************************************************/
 unsigned char cmos_read_byte(unsigned index)
 {
-	unsigned short port_0, port_1;

-

-	assert(!verify_cmos_byte_index(index));

-

-	if (index < 128) {

-		port_0 = 0x70;

-		port_1 = 0x71;

-	} else {

-		port_0 = 0x72;

-		port_1 = 0x73;

-	}

-

-	OUTB(index, port_0);

-	return INB(port_1);

+	return current_access->read(index);

 }
 
 /****************************************************************************
@@ -209,20 +257,7 @@  unsigned char cmos_read_byte(unsigned in

  ****************************************************************************/
 void cmos_write_byte(unsigned index, unsigned char value)
 {
-	unsigned short port_0, port_1;

-

-	assert(!verify_cmos_byte_index(index));

-

-	if (index < 128) {

-		port_0 = 0x70;

-		port_1 = 0x71;

-	} else {

-		port_0 = 0x72;

-		port_1 = 0x73;

-	}

-

-	OUTB(index, port_0);

-	OUTB(value, port_1);

+	current_access->write(index, value);

 }
 
 /****************************************************************************