]> xenbits.xensource.com Git - people/aperard/linux-chromebook.git/commitdiff
CHROMIUM: platform: rename nvram to vbc
authorChe-Liang Chiou <clchiou@chromium.org>
Fri, 9 Nov 2012 01:34:50 +0000 (17:34 -0800)
committerGerrit <chrome-bot@google.com>
Tue, 20 Nov 2012 02:19:07 +0000 (18:19 -0800)
As we are actually accessing vboot context and vboot context is not
limited to be stored on nvram, it is clearer to just call it vbc.

This change also removes obsolete comments and makes API interface
consistent (all read/write should return number of bytes instead of zero
on success).

BUG=none
TEST=manual, add debugging sysfs entry to read/write vboot context and
     make sure it works.

Change-Id: Ifd097a1a8af9edb776eed83fe47cb332f8a3445d
Signed-off-by: Che-Liang Chiou <clchiou@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/37686
Reviewed-by: Simon Glass <sjg@chromium.org>
drivers/platform/arm/chromeos_arm.c
drivers/platform/chromeos.c
drivers/platform/chromeos.h
drivers/platform/x86/chromeos_acpi.c

index f7f21f1c14af38babd6ce27de174d02a1aa7f8bf..214a5977f9b3712133e076ef4a1aa516d86d5459 100644 (file)
 #define BLKNV_MAJOR MMC_BLOCK_MAJOR
 #define BLKNV_MINOR 0
 
-/* location where the nvram data blends into the sector on the MMC device */
+/*
+ * location where the vboot context data blends into the sector on the
+ * MMC device
+ */
 static u16 nv_offset, nv_size;
 static u64 nv_lba;
 
 /*
- * Functions to support nvram on block device. The actual device used is minor
- * 0 of MMC device class, the sector to use is as encoded in
- * firmware_shared_data->nvcxt_lba, the nvram buffer in the sector starts at
- * offset nv_offset and takes nv_size bytes.
+ * Functions to support vboot context on block device. The actual device used
+ * is minor 0 of MMC device class, the sector to use is as encoded in
+ * firmware_shared_data->nvcxt_lba, the vboot context buffer in the sector
+ * starts at offset nv_offset and takes nv_size bytes.
  */
-static void blknv_endio(struct bio *bio, int err)
+static void vbc_blk_endio(struct bio *bio, int err)
 {
        struct completion *c = bio->bi_private;
        bio->bi_private = (void *)err;
        complete(c);
 }
 
-static void blknv_submit_bio(struct bio *bio, int rq)
+static void vbc_blk_submit_bio(struct bio *bio, int rq)
 {
        DECLARE_COMPLETION_ONSTACK(wait);
 
-       bio->bi_end_io  = blknv_endio;
+       bio->bi_end_io  = vbc_blk_endio;
        bio->bi_private = &wait;
        submit_bio(rq, bio);
        wait_for_completion(&wait);
 }
 
-static int chromeos_access_nvram_block(struct page *page,
-                                      sector_t sector,
-                                      bool is_read)
+static int vbc_blk_access(struct page *page, sector_t sector, bool is_read)
 {
        struct block_device *bdev;
        struct bio *bio = NULL;
@@ -104,7 +105,7 @@ static int chromeos_access_nvram_block(struct page *page,
        if (!is_read)
                rq |= REQ_WRITE;
 
-       blknv_submit_bio(bio, rq);
+       vbc_blk_submit_bio(bio, rq);
 
        /* nvblk_endio passes up any error in bi_private */
        ret = (int)bio->bi_private;
@@ -120,22 +121,12 @@ out:
        return ret;
 }
 
-static int chromeos_read_nvram_block(struct page *page, sector_t sector)
-{
-       return chromeos_access_nvram_block(page, sector, 1);
-}
-
-static int chromeos_write_nvram_block(struct page *page, sector_t sector)
-{
-       return chromeos_access_nvram_block(page, sector, 0);
-}
-
 /*
  * This function accepts a buffer with exactly nv_size bytes. It reads the
  * appropriate mmc one sector block, extacts the nonvolatile data from there
  * and copies it to the provided buffer.
  */
-static int _chromeos_read(u8 *data)
+static int vbc_blk_read(u8 *data)
 {
        struct page *page;
        char *virtual_addr;
@@ -154,7 +145,7 @@ static int _chromeos_read(u8 *data)
                return -EFAULT;
        }
 
-       ret = chromeos_read_nvram_block(page, nv_lba);
+       ret = vbc_blk_access(page, nv_lba, 1);
        if (ret)
                goto out;
 
@@ -168,10 +159,10 @@ out:
 
 /*
  * This function accepts a buffer with exactly nv_size bytes. It reads the
- * appropriate mmc one sector block, blends in the new nvram contents and then
- * writes the sector back.
+ * appropriate mmc one sector block, blends in the new vboot context contents
+ * and then writes the sector back.
  */
-static int _chromeos_write(const u8 *data)
+static int vbc_blk_write(const u8 *data)
 {
        struct page *page;
        char *virtual_addr;
@@ -190,17 +181,17 @@ static int _chromeos_write(const u8 *data)
                return -EFAULT;
        }
 
-       ret = chromeos_read_nvram_block(page, nv_lba);
+       ret = vbc_blk_access(page, nv_lba, 1);
        if (ret)
                goto out;
 
        /*
-        * Sector has been read, lets blend in nvram data and write the sector
-        * back.
+        * Sector has been read, lets blend in vboot context data and write
+        * the sector back.
         */
        memcpy(virtual_addr + nv_offset, data, nv_size);
 
-       ret = chromeos_write_nvram_block(page, nv_lba);
+       ret = vbc_blk_access(page, nv_lba, 0);
        if (!ret)
                ret = nv_size;
 
@@ -210,40 +201,40 @@ out:
 }
 
 /*
- * Read the nvram buffer contents into the user provided space.
+ * Read the vboot context buffer contents into the user provided space.
  *
  * returns number of bytes copied, or negative error.
  */
-int chromeos_platform_read_nvram(u8 *nvram_buffer, int buf_size)
+ssize_t chromeos_vbc_read(void *buf, size_t count)
 {
        if (!nv_size) {
                pr_err("%s nonvolatile context not configured!\n", __func__);
                return -ENODEV;
        }
 
-       if (buf_size < nv_size) {
-               pr_err("not enough room to read nvram (%d < %d)\n",
-                      buf_size, nv_size);
+       if (count < nv_size) {
+               pr_err("not enough room to read vboot context (%zd < %d)\n",
+                      count, nv_size);
                return -ENOSPC;
        }
 
-       return _chromeos_read(nvram_buffer);
+       return vbc_blk_read(buf);
 }
 
-int chromeos_platform_write_nvram(u8 *nvram_buffer, int buf_size)
+ssize_t chromeos_vbc_write(const void *buf, size_t count)
 {
        if (!nv_size) {
                pr_err("%s nonvolatile context not configured!\n", __func__);
                return -ENODEV;
        }
 
-       if (buf_size != nv_size) {
-               pr_err("wrong write buffer size (%d != %d)\n",
-                      buf_size, nv_size);
+       if (count != nv_size) {
+               pr_err("wrong write buffer size (%zd != %d)\n",
+                      count, nv_size);
                return -ENOSPC;
        }
 
-       return _chromeos_write(nvram_buffer);
+       return vbc_blk_write(buf);
 }
 
 static int __devinit chromeos_arm_platform_gpio(struct platform_device *pdev)
@@ -302,9 +293,9 @@ static int __devinit chromeos_arm_probe(struct platform_device *pdev)
        nv_size = be32_to_cpup(prop);
 
        if ((nv_offset + nv_size > SECTOR_SIZE) ||
-           (nv_size > MAX_NVRAM_BUFFER_SIZE)) {
-               /* nvram block won't fit into a sector */
-               dev_err(&pdev->dev, "bad nvram location: %d:%d!\n",
+           (nv_size > MAX_VBOOT_CONTEXT_BUFFER_SIZE)) {
+               /* vboot context block won't fit into a sector */
+               dev_err(&pdev->dev, "bad vboot context location: %d:%d!\n",
                        nv_offset, nv_size);
                err = -EINVAL;
                goto err;
index f4eb1b11727155fe52156cae77bd5b1355b558c6..2f18edc3a5e09313ff5e06dc33c006b1d9acdcaf 100644 (file)
  *  You should have received a copy of the GNU General Public License
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- * This module isolates ChromeOS platform specific behavior.  In particular,
- * it uses calls from chromeos_acpi.c to control the boot flow, and exports some
- * helper functions for kernel-side consumers of platform configuration, such
- * as nvram flags.
  */
 
 #include <linux/types.h>
@@ -31,8 +26,8 @@
 #include <linux/ramoops.h>
 #include "chromeos.h"
 
-static int chromeos_read_nvram(u8 *nvram_buffer, int buf_size);
-static int chromeos_write_nvram_byte(unsigned offset, u8 value);
+static int vbc_read(u8 *buf, int buf_size);
+static int vbc_write_byte(unsigned offset, u8 value);
 
 /* the following defines are copied from
  * vboot_reference:firmware/lib/vboot_nvstorage.c.
@@ -45,8 +40,7 @@ int chromeos_set_need_recovery(void)
        if (!chromeos_legacy_set_need_recovery())
                return 0;
 
-       return chromeos_write_nvram_byte(RECOVERY_OFFSET,
-                                        VBNV_RECOVERY_RW_INVALID_OS);
+       return vbc_write_byte(RECOVERY_OFFSET, VBNV_RECOVERY_RW_INVALID_OS);
 }
 
 /*
@@ -71,11 +65,11 @@ static u8 crc8(const u8 *data, int len)
        return (u8)(crc >> 8);
 }
 
-static int chromeos_write_nvram_byte(unsigned offset, u8 value)
+static int vbc_write_byte(unsigned offset, u8 value)
 {
-       u8 nvram_buffer[MAX_NVRAM_BUFFER_SIZE];
+       u8 buf[MAX_VBOOT_CONTEXT_BUFFER_SIZE];
 
-       int size = chromeos_read_nvram(nvram_buffer, sizeof(nvram_buffer));
+       ssize_t size = vbc_read(buf, sizeof(buf));
 
        if (size <= 0)
                return -EINVAL;
@@ -83,32 +77,29 @@ static int chromeos_write_nvram_byte(unsigned offset, u8 value)
        if (offset >= (size - 1))
                return -EINVAL;
 
-       if (nvram_buffer[offset] == value)
+       if (buf[offset] == value)
                return 0;
 
-       nvram_buffer[offset] = value;
-       nvram_buffer[size - 1] = crc8(nvram_buffer, size - 1);
+       buf[offset] = value;
+       buf[size - 1] = crc8(buf, size - 1);
 
-       return chromeos_platform_write_nvram(nvram_buffer, size);
+       return chromeos_vbc_write(buf, size);
 }
 
 /*
- * Read nvram buffer contents and verify it. Return 0 on success and -1 on
- * failure (uninitialized subsystem, corrupted crc8 value, not enough room in
- * the buffer, etc.).
- *
- * If everything checks out - return number of bytes in the NVRAM buffer, -1
- * on any error.
+ * Read vboot context and verify it.  If everything checks out, return number
+ * of bytes in the vboot context buffer, -1 on any error (uninitialized
+ * subsystem, corrupted crc8 value, not enough room in the buffer, etc.).
  */
-static int chromeos_read_nvram(u8 *nvram_buffer, int buf_size)
+static int vbc_read(u8 *buf, int buf_size)
 {
-       int size = chromeos_platform_read_nvram(nvram_buffer, buf_size);
+       ssize_t size = chromeos_vbc_read(buf, buf_size);
 
        if (size <= 0)
                return -1;
 
-       if (nvram_buffer[size - 1] != crc8(nvram_buffer, size - 1)) {
-               pr_err("%s: NVRAM contents corrupted\n", __func__);
+       if (buf[size - 1] != crc8(buf, size - 1)) {
+               pr_err("%s: vboot context contents corrupted\n", __func__);
                return -1;
        }
        return size;
index 7c2d8fa9931146e4aca06dec63942b8a9089f640..79bffd8f6a0dc7f65ce6d601af66dc2a4dddac4b 100644 (file)
  *  You should have received a copy of the GNU General Public License
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- * This module isolates ChromeOS platform specific behavior.  In particular,
- * it uses calls from chromeos_acpi.c to control the boot flow, and exports some
- * helper functions for kernel-side consumers of platform configuration, such
- * as nvram flags.
  */
 #ifndef _DRIVERS_PLATFORM_CHROMEOS_H
 #define _DRIVERS_PLATFORM_CHROMEOS_H
 
-#define MAX_NVRAM_BUFFER_SIZE 64  /* Should be enough for anything. */
+#define MAX_VBOOT_CONTEXT_BUFFER_SIZE 64  /* Should be enough for anything. */
 
 #ifdef CONFIG_ACPI_CHROMEOS
 extern int chromeos_legacy_set_need_recovery(void);
@@ -31,7 +26,24 @@ extern int chromeos_legacy_set_need_recovery(void);
 static inline int chromeos_legacy_set_need_recovery(void) { return -ENODEV; }
 #endif
 
-extern int chromeos_platform_read_nvram(u8 *nvram_buffer, int buf_size);
-extern int chromeos_platform_write_nvram(u8 *nvram_buffer, int buf_size);
+/**
+ * Read vboot context to buffer
+ *
+ * @param buf          Pointer to buffer for storing vboot context
+ * @param count                Size of buffer
+ * @return     on success, the number of bytes read is returned and
+ *             on error, -err is returned.
+ */
+ssize_t chromeos_vbc_read(void *buf, size_t count);
+
+/**
+ * Write vboot context from buffer
+ *
+ * @param buf          Pointer to buffer of new vboot context content
+ * @param count                Size of buffer
+ * @return     on success, the number of bytes written is returned and
+ *             on error, -err is returned.
+ */
+ssize_t chromeos_vbc_write(const void *buf, size_t count);
 
 #endif /* _DRIVERS_PLATFORM_CHROMEOS_H */
index aa4b9ca1e2eefb47ff74646cbb1991343bec564b..6522464c6178905406afcfdaa714d4340524df52 100644 (file)
@@ -188,7 +188,7 @@ int chromeos_legacy_set_need_recovery(void)
  *
  * retrun number of bytes copied, or -1 on any error.
  */
-int chromeos_platform_read_nvram(u8 *nvram_buffer, int buf_size)
+ssize_t chromeos_vbc_read(void *buf, size_t count)
 {
 
        int base, size, i;
@@ -202,19 +202,19 @@ int chromeos_platform_read_nvram(u8 *nvram_buffer, int buf_size)
        base = chromeos_acpi_if_data.nv_base.cad_value;
        size = chromeos_acpi_if_data.nv_size.cad_value;
 
-       if (buf_size < size) {
-               pr_err("%s: not enough room to read nvram (%d < %d)\n",
-                      __func__, buf_size, size);
+       if (count < size) {
+               pr_err("%s: not enough room to read nvram (%zd < %d)\n",
+                      __func__, count, size);
                return -EINVAL;
        }
 
        for (i = 0; i < size; i++)
-               nvram_buffer[i] = nvram_read_byte(base++);
+               ((u8 *)buf)[i] = nvram_read_byte(base++);
 
        return size;
 }
 
-int chromeos_platform_write_nvram(u8 *nvram_buffer, int buf_size)
+ssize_t chromeos_vbc_write(const void *buf, size_t count)
 {
        unsigned base, size, i;
 
@@ -227,9 +227,9 @@ int chromeos_platform_write_nvram(u8 *nvram_buffer, int buf_size)
        size = chromeos_acpi_if_data.nv_size.cad_value;
        base = chromeos_acpi_if_data.nv_base.cad_value;
 
-       if (buf_size != size) {
-               printk(MY_ERR "%s: wrong buffer size (%d != %d)!\n", __func__,
-                      buf_size, size);
+       if (count != size) {
+               printk(MY_ERR "%s: wrong buffer size (%zd != %d)!\n", __func__,
+                      count, size);
                return -EINVAL;
        }
 
@@ -237,11 +237,11 @@ int chromeos_platform_write_nvram(u8 *nvram_buffer, int buf_size)
                u8 c;
 
                c = nvram_read_byte(base + i);
-               if (c == nvram_buffer[i])
+               if (c == ((u8 *)buf)[i])
                        continue;
-               nvram_write_byte(nvram_buffer[i], base + i);
+               nvram_write_byte(((u8 *)buf)[i], base + i);
        }
-       return 0;
+       return size;
 }
 
 /*