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>
This commit is contained in:

committed by
Greg Kroah-Hartman

parent
2d58636e0a
commit
109b3a89a7
@@ -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 */
|
||||
|
Reference in New Issue
Block a user