* Allow coreboot to use the full 256 bytes of CMOS memory
authorStefan Reinauer <stepan@coresystems.de>
Wed, 22 Apr 2009 09:03:08 +0000 (09:03 +0000)
committerStefan Reinauer <stepan@openbios.org>
Wed, 22 Apr 2009 09:03:08 +0000 (09:03 +0000)
* Make functions out of the accessor macros in mc146818rtc.c
* don't hide reserved cmos entries from coreboot, only from the user.

Signed-off-by: Stefan Reinauer <stepan@coresystems.de>
Acked-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
git-svn-id: svn://svn.coreboot.org/coreboot/trunk@4170 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1

src/include/boot/coreboot_tables.h
src/pc80/mc146818rtc.c
src/pc80/mc146818rtc_early.c
util/options/build_opt_tbl.c

index f0ab7af7cbc7d2d0d462fbf6d7e521ce9d7e0ad3..0385db9093c487f780ab4e6a109496c6eb0a2cbc 100644 (file)
@@ -223,7 +223,7 @@ struct cmos_defaults {
        uint32_t size;               /* length of this record */
        uint32_t name_length;        /* length of the following name field */
        uint8_t name[CMOS_MAX_NAME_LENGTH]; /* name identifying the default */
-#define CMOS_IMAGE_BUFFER_SIZE 128
+#define CMOS_IMAGE_BUFFER_SIZE 256
        uint8_t default_set[CMOS_IMAGE_BUFFER_SIZE]; /* default settings */
 };
 
index 5da888071ffba2e84f1f596caee189853bbc4af4..0baa389c1ffcd22c218882256b52d1f1dcc49610 100644 (file)
@@ -4,16 +4,6 @@
 #include <boot/coreboot_tables.h>
 #include <string.h>
 
-#define CMOS_READ(addr) ({ \
-outb((addr),RTC_PORT(0)); \
-inb(RTC_PORT(1)); \
-})
-
-#define CMOS_WRITE(val, addr) ({ \
-outb((addr),RTC_PORT(0)); \
-outb((val),RTC_PORT(1)); \
-})
-
 /* control registers - Moto names
  */
 #define RTC_REG_A              10
@@ -83,7 +73,27 @@ outb((val),RTC_PORT(1)); \
 # define RTC_VRT 0x80          /* valid RAM and time */
 /**********************************************************************/
 
+static inline unsigned char cmos_read(unsigned char addr)
+{
+       int offs = 0;
+       if (addr >= 128) {
+               offs = 2;
+               addr -= 128;
+       }
+       outb(addr, RTC_BASE_PORT + offs + 0);
+       return inb(RTC_BASE_PORT + offs + 1);
+}
 
+static inline void cmos_write(unsigned char val, unsigned char addr)
+{
+       int offs = 0;
+       if (addr >= 128) {
+               offs = 2;
+               addr -= 128;
+       }
+       outb(addr, RTC_BASE_PORT + offs + 0);
+       outb(val, RTC_BASE_PORT + offs + 1);
+}
 
 static int rtc_checksum_valid(int range_start, int range_end, int cks_loc)
 {
@@ -91,10 +101,10 @@ static int rtc_checksum_valid(int range_start, int range_end, int cks_loc)
        unsigned sum, old_sum;
        sum = 0;
        for(i = range_start; i <= range_end; i++) {
-               sum += CMOS_READ(i);
+               sum += cmos_read(i);
        }
        sum = (~sum)&0x0ffff;
-       old_sum = ((CMOS_READ(cks_loc)<<8) | CMOS_READ(cks_loc+1))&0x0ffff;
+       old_sum = ((cmos_read(cks_loc)<<8) | cmos_read(cks_loc+1))&0x0ffff;
        return sum == old_sum;
 }
 
@@ -104,11 +114,11 @@ static void rtc_set_checksum(int range_start, int range_end, int cks_loc)
        unsigned sum;
        sum = 0;
        for(i = range_start; i <= range_end; i++) {
-               sum += CMOS_READ(i);
+               sum += cmos_read(i);
        }
        sum = ~(sum & 0x0ffff);
-       CMOS_WRITE(((sum >> 8) & 0x0ff), cks_loc);
-       CMOS_WRITE(((sum >> 0) & 0x0ff), cks_loc+1);
+       cmos_write(((sum >> 8) & 0x0ff), cks_loc);
+       cmos_write(((sum >> 0) & 0x0ff), cks_loc+1);
 }
 
 #define RTC_CONTROL_DEFAULT (RTC_24H)
@@ -130,7 +140,7 @@ void rtc_init(int invalid)
 
 #if HAVE_OPTION_TABLE
        /* See if there has been a CMOS power problem. */
-       x = CMOS_READ(RTC_VALID);
+       x = cmos_read(RTC_VALID);
        cmos_invalid = !(x & RTC_VRT);
 
        /* See if there is a CMOS checksum error */
@@ -143,31 +153,31 @@ void rtc_init(int invalid)
                        cmos_invalid?" Power Problem":"",
                        checksum_invalid?" Checksum invalid":"");
 #if 0
-               CMOS_WRITE(0, 0x01);
-               CMOS_WRITE(0, 0x03);
-               CMOS_WRITE(0, 0x05);
+               cmos_write(0, 0x01);
+               cmos_write(0, 0x03);
+               cmos_write(0, 0x05);
                for(i = 10; i < 48; i++) {
-                       CMOS_WRITE(0, i);
+                       cmos_write(0, i);
                }
                
                if (cmos_invalid) {
                        /* Now setup a default date of Sat 1 January 2000 */
-                       CMOS_WRITE(0, 0x00); /* seconds */
-                       CMOS_WRITE(0, 0x02); /* minutes */
-                       CMOS_WRITE(1, 0x04); /* hours */
-                       CMOS_WRITE(7, 0x06); /* day of week */
-                       CMOS_WRITE(1, 0x07); /* day of month */
-                       CMOS_WRITE(1, 0x08); /* month */
-                       CMOS_WRITE(0, 0x09); /* year */
+                       cmos_write(0, 0x00); /* seconds */
+                       cmos_write(0, 0x02); /* minutes */
+                       cmos_write(1, 0x04); /* hours */
+                       cmos_write(7, 0x06); /* day of week */
+                       cmos_write(1, 0x07); /* day of month */
+                       cmos_write(1, 0x08); /* month */
+                       cmos_write(0, 0x09); /* year */
                }
 #endif
        }
 #endif
 
        /* Setup the real time clock */
-       CMOS_WRITE(RTC_CONTROL_DEFAULT, RTC_CONTROL);
+       cmos_write(RTC_CONTROL_DEFAULT, RTC_CONTROL);
        /* Setup the frequency it operates at */
-       CMOS_WRITE(RTC_FREQ_SELECT_DEFAULT, RTC_FREQ_SELECT);
+       cmos_write(RTC_FREQ_SELECT_DEFAULT, RTC_FREQ_SELECT);
 
 #if HAVE_OPTION_TABLE
        /* See if there is a LB CMOS checksum error */
@@ -182,7 +192,7 @@ void rtc_init(int invalid)
 #endif
 
        /* Clear any pending interrupts */
-       (void) CMOS_READ(RTC_INTR_FLAGS);
+       (void) cmos_read(RTC_INTR_FLAGS);
 }
 
 
@@ -207,7 +217,7 @@ static int get_cmos_value(unsigned long bit, unsigned long length, void *vret)
        byte=bit/8;     /* find the byte where the data starts */
        byte_bit=bit%8; /* find the bit in the byte where the data starts */
        if(length<9) {  /* one byte or less */
-               uchar = CMOS_READ(byte); /* load the byte */
+               uchar = cmos_read(byte); /* load the byte */
                uchar >>= byte_bit;     /* shift the bits to byte align */
                /* clear unspecified bits */
                ret[0] = uchar & ((1 << length) -1);
@@ -215,7 +225,7 @@ static int get_cmos_value(unsigned long bit, unsigned long length, void *vret)
        else {  /* more that one byte so transfer the whole bytes */
                for(i=0;length;i++,length-=8,byte++) {
                        /* load the byte */
-                       ret[i]=CMOS_READ(byte);
+                       ret[i]=cmos_read(byte);
                }
        }
        return 0;
index 0c7d822718136e4c9a98073bf1d4830ac64a96ad..83e340c70bc40919cdcf8ddf2d9e025733546bcb 100644 (file)
 
 static unsigned char cmos_read(unsigned char addr)
 {
-       outb(addr, RTC_BASE_PORT + 0);
-       return inb(RTC_BASE_PORT + 1);
+       int offs = 0;
+       if (addr >= 128) {
+               offs = 2;
+               addr -= 128;
+       }
+       outb(addr, RTC_BASE_PORT + offs + 0);
+       return inb(RTC_BASE_PORT + offs + 1);
 }
 
 static void cmos_write(unsigned char val, unsigned char addr)
 {
-       outb(addr, RTC_BASE_PORT + 0);
-       outb(val, RTC_BASE_PORT + 1);
+       int offs = 0;
+       if (addr >= 128) {
+               offs = 2;
+               addr -= 128;
+       }
+       outb(addr, RTC_BASE_PORT + offs + 0);
+       outb(val, RTC_BASE_PORT + offs + 1);
 }
 
 static int cmos_error(void)
index 4d98f8eceefab98dd405c5796c4506e5c75811ed..cca1b7c464f7febcba73a7d2d85879e3953c37f8 100644 (file)
@@ -8,7 +8,7 @@
 #include "../../src/include/pc80/mc146818rtc.h"
 #include "../../src/include/boot/coreboot_tables.h"
 
-#define CMOS_IMAGE_BUFFER_SIZE 128
+#define CMOS_IMAGE_BUFFER_SIZE 256
 #define INPUT_LINE_MAX 256
 #define MAX_VALUE_BYTE_LENGTH 64
 
@@ -563,9 +563,7 @@ int main(int argc, char **argv)
                                continue;
                        }
                        ce = (struct cmos_entries *)ptr;
-                       if (ce->config == 'r') {
-                               continue;
-                       }
+
                        if (!is_ident((char *)ce->name)) {
                                fprintf(stderr, "Invalid identifier: %s\n",
                                        ce->name);