aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/nvram.h
diff options
context:
space:
mode:
authorFinn Thain <fthain@telegraphics.com.au>2019-01-15 15:18:56 +1100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2019-01-22 10:21:44 +0100
commit109b3a89a7c48405d61a05d7a1720581a4f1574c (patch)
tree00bfc8a815366b81e44fe00580cfcb593a6bd429 /include/linux/nvram.h
parentchar/nvram: Allow the set_checksum and initialize ioctls to be omitted (diff)
downloadlinux-dev-109b3a89a7c48405d61a05d7a1720581a4f1574c.tar.xz
linux-dev-109b3a89a7c48405d61a05d7a1720581a4f1574c.zip
char/nvram: Implement NVRAM read/write methods
Refactor the RTC "CMOS" NVRAM functions so that they can be used as arch_nvram_ops methods. Checksumming logic is moved from the misc device operations to the nvram read/write operations. This makes the misc device implementation more generic. This preserves the locking mechanism such that "read if checksum valid" and "write and update checksum" remain atomic operations. Some platforms implement byte-range read/write methods which are similar to file_operations struct methods. Other platforms provide only byte-at-a-time methods. The former are more efficient but may be unavailable so fall back on the latter methods when necessary. Tested-by: Stan Johnson <userm57@yahoo.com> Signed-off-by: Finn Thain <fthain@telegraphics.com.au> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'include/linux/nvram.h')
-rw-r--r--include/linux/nvram.h32
1 files changed, 30 insertions, 2 deletions
diff --git a/include/linux/nvram.h b/include/linux/nvram.h
index 31c763087746..9df85703735c 100644
--- a/include/linux/nvram.h
+++ b/include/linux/nvram.h
@@ -66,18 +66,46 @@ static inline void nvram_write_byte(unsigned char val, int addr)
#endif
}
+static inline ssize_t nvram_read_bytes(char *buf, size_t count, loff_t *ppos)
+{
+ ssize_t nvram_size = nvram_get_size();
+ loff_t i;
+ char *p = buf;
+
+ if (nvram_size < 0)
+ return nvram_size;
+ for (i = *ppos; count > 0 && i < nvram_size; ++i, ++p, --count)
+ *p = nvram_read_byte(i);
+ *ppos = i;
+ return p - buf;
+}
+
+static inline ssize_t nvram_write_bytes(char *buf, size_t count, loff_t *ppos)
+{
+ ssize_t nvram_size = nvram_get_size();
+ loff_t i;
+ char *p = buf;
+
+ if (nvram_size < 0)
+ return nvram_size;
+ for (i = *ppos; count > 0 && i < nvram_size; ++i, ++p, --count)
+ nvram_write_byte(*p, i);
+ *ppos = i;
+ return p - buf;
+}
+
static inline ssize_t nvram_read(char *buf, size_t count, loff_t *ppos)
{
if (arch_nvram_ops.read)
return arch_nvram_ops.read(buf, count, ppos);
- return -ENODEV;
+ return nvram_read_bytes(buf, count, ppos);
}
static inline ssize_t nvram_write(char *buf, size_t count, loff_t *ppos)
{
if (arch_nvram_ops.write)
return arch_nvram_ops.write(buf, count, ppos);
- return -ENODEV;
+ return nvram_write_bytes(buf, count, ppos);
}
#endif /* _LINUX_NVRAM_H */