Skip to content

Commit

Permalink
powerpc/nvram: Enable use Generic NVRAM driver for different size chips
Browse files Browse the repository at this point in the history
Remove the reliance on a staticly defined NVRAM size, allowing
platforms to support NVRAMs with sizes differing from the standard.

A fall back value is provided for platforms not supporting this extension.

Signed-off-by: Martyn Welch <martyn.welch@gefanuc.com>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
  • Loading branch information
Martyn Welch authored and Benjamin Herrenschmidt committed Sep 11, 2009
1 parent 1d6ed32 commit d331d83
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
3 changes: 3 additions & 0 deletions arch/powerpc/include/asm/nvram.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ extern void pmac_xpram_write(int xpaddr, u8 data);
/* Synchronize NVRAM */
extern void nvram_sync(void);

/* Determine NVRAM size */
extern ssize_t nvram_get_size(void);

/* Normal access to NVRAM */
extern unsigned char nvram_read_byte(int i);
extern void nvram_write_byte(unsigned char c, int i);
Expand Down
8 changes: 8 additions & 0 deletions arch/powerpc/kernel/setup_32.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,14 @@ void nvram_write_byte(unsigned char val, int addr)
}
EXPORT_SYMBOL(nvram_write_byte);

ssize_t nvram_get_size(void)
{
if (ppc_md.nvram_size)
return ppc_md.nvram_size();
return -1;
}
EXPORT_SYMBOL(nvram_get_size);

void nvram_sync(void)
{
if (ppc_md.nvram_sync)
Expand Down
27 changes: 20 additions & 7 deletions drivers/char/generic_nvram.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Generic /dev/nvram driver for architectures providing some
* "generic" hooks, that is :
*
* nvram_read_byte, nvram_write_byte, nvram_sync
* nvram_read_byte, nvram_write_byte, nvram_sync, nvram_get_size
*
* Note that an additional hook is supported for PowerMac only
* for getting the nvram "partition" informations
Expand All @@ -28,6 +28,8 @@

#define NVRAM_SIZE 8192

static ssize_t nvram_len;

static loff_t nvram_llseek(struct file *file, loff_t offset, int origin)
{
lock_kernel();
Expand All @@ -36,7 +38,7 @@ static loff_t nvram_llseek(struct file *file, loff_t offset, int origin)
offset += file->f_pos;
break;
case 2:
offset += NVRAM_SIZE;
offset += nvram_len;
break;
}
if (offset < 0) {
Expand All @@ -56,9 +58,9 @@ static ssize_t read_nvram(struct file *file, char __user *buf,

if (!access_ok(VERIFY_WRITE, buf, count))
return -EFAULT;
if (*ppos >= NVRAM_SIZE)
if (*ppos >= nvram_len)
return 0;
for (i = *ppos; count > 0 && i < NVRAM_SIZE; ++i, ++p, --count)
for (i = *ppos; count > 0 && i < nvram_len; ++i, ++p, --count)
if (__put_user(nvram_read_byte(i), p))
return -EFAULT;
*ppos = i;
Expand All @@ -74,9 +76,9 @@ static ssize_t write_nvram(struct file *file, const char __user *buf,

if (!access_ok(VERIFY_READ, buf, count))
return -EFAULT;
if (*ppos >= NVRAM_SIZE)
if (*ppos >= nvram_len)
return 0;
for (i = *ppos; count > 0 && i < NVRAM_SIZE; ++i, ++p, --count) {
for (i = *ppos; count > 0 && i < nvram_len; ++i, ++p, --count) {
if (__get_user(c, p))
return -EFAULT;
nvram_write_byte(c, i);
Expand Down Expand Up @@ -133,9 +135,20 @@ static struct miscdevice nvram_dev = {

int __init nvram_init(void)
{
int ret = 0;

printk(KERN_INFO "Generic non-volatile memory driver v%s\n",
NVRAM_VERSION);
return misc_register(&nvram_dev);
ret = misc_register(&nvram_dev);
if (ret != 0)
goto out;

nvram_len = nvram_get_size();
if (nvram_len < 0)
nvram_len = NVRAM_SIZE;

out:
return ret;
}

void __exit nvram_cleanup(void)
Expand Down

0 comments on commit d331d83

Please sign in to comment.