Release 4.7 drivers/char/generic_nvram.c
/*
* Generic /dev/nvram driver for architectures providing some
* "generic" hooks, that is :
*
* 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
*
*/
#define NVRAM_VERSION "1.1"
#include <linux/module.h>
#include <linux/types.h>
#include <linux/errno.h>
#include <linux/fs.h>
#include <linux/miscdevice.h>
#include <linux/fcntl.h>
#include <linux/init.h>
#include <linux/mutex.h>
#include <linux/pagemap.h>
#include <asm/uaccess.h>
#include <asm/nvram.h>
#ifdef CONFIG_PPC_PMAC
#include <asm/machdep.h>
#endif
#define NVRAM_SIZE 8192
static DEFINE_MUTEX(nvram_mutex);
static ssize_t nvram_len;
static loff_t nvram_llseek(struct file *file, loff_t offset, int origin)
{
return generic_file_llseek_size(file, offset, origin,
MAX_LFS_FILESIZE, nvram_len);
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
benjamin herrenschmidt | benjamin herrenschmidt | 21 | 67.74% | 1 | 50.00% |
al viro | al viro | 10 | 32.26% | 1 | 50.00% |
| Total | 31 | 100.00% | 2 | 100.00% |
static ssize_t read_nvram(struct file *file, char __user *buf,
size_t count, loff_t *ppos)
{
unsigned int i;
char __user *p = buf;
if (!access_ok(VERIFY_WRITE, buf, count))
return -EFAULT;
if (*ppos >= nvram_len)
return 0;
for (i = *ppos; count > 0 && i < nvram_len; ++i, ++p, --count)
if (__put_user(nvram_read_byte(i), p))
return -EFAULT;
*ppos = i;
return p - buf;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
benjamin herrenschmidt | benjamin herrenschmidt | 106 | 96.36% | 1 | 33.33% |
martyn welch | martyn welch | 2 | 1.82% | 1 | 33.33% |
jesper juhl | jesper juhl | 2 | 1.82% | 1 | 33.33% |
| Total | 110 | 100.00% | 3 | 100.00% |
static ssize_t write_nvram(struct file *file, const char __user *buf,
size_t count, loff_t *ppos)
{
unsigned int i;
const char __user *p = buf;
char c;
if (!access_ok(VERIFY_READ, buf, count))
return -EFAULT;
if (*ppos >= nvram_len)
return 0;
for (i = *ppos; count > 0 && i < nvram_len; ++i, ++p, --count) {
if (__get_user(c, p))
return -EFAULT;
nvram_write_byte(c, i);
}
*ppos = i;
return p - buf;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
benjamin herrenschmidt | benjamin herrenschmidt | 117 | 96.69% | 1 | 33.33% |
jesper juhl | jesper juhl | 2 | 1.65% | 1 | 33.33% |
martyn welch | martyn welch | 2 | 1.65% | 1 | 33.33% |
| Total | 121 | 100.00% | 3 | 100.00% |
static int nvram_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
switch(cmd) {
#ifdef CONFIG_PPC_PMAC
case OBSOLETE_PMAC_NVRAM_GET_OFFSET:
printk(KERN_WARNING "nvram: Using obsolete PMAC_NVRAM_GET_OFFSET ioctl\n");
case IOC_NVRAM_GET_OFFSET: {
int part, offset;
if (!machine_is(powermac))
return -EINVAL;
if (copy_from_user(&part, (void __user*)arg, sizeof(part)) != 0)
return -EFAULT;
if (part < pmac_nvram_OF || part > pmac_nvram_NR)
return -EINVAL;
offset = pmac_get_partition(part);
if (copy_to_user((void __user*)arg, &offset, sizeof(offset)) != 0)
return -EFAULT;
break;
}
#endif /* CONFIG_PPC_PMAC */
case IOC_NVRAM_SYNC:
nvram_sync();
break;
default:
return -EINVAL;
}
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
benjamin herrenschmidt | benjamin herrenschmidt | 151 | 100.00% | 2 | 100.00% |
| Total | 151 | 100.00% | 2 | 100.00% |
static long nvram_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
int ret;
mutex_lock(&nvram_mutex);
ret = nvram_ioctl(file, cmd, arg);
mutex_unlock(&nvram_mutex);
return ret;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
arnd bergmann | arnd bergmann | 48 | 100.00% | 2 | 100.00% |
| Total | 48 | 100.00% | 2 | 100.00% |
const struct file_operations nvram_fops = {
.owner = THIS_MODULE,
.llseek = nvram_llseek,
.read = read_nvram,
.write = write_nvram,
.unlocked_ioctl = nvram_unlocked_ioctl,
};
static struct miscdevice nvram_dev = {
NVRAM_MINOR,
"nvram",
&nvram_fops
};
int __init nvram_init(void)
{
int ret = 0;
printk(KERN_INFO "Generic non-volatile memory driver v%s\n",
NVRAM_VERSION);
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;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
martyn welch | martyn welch | 36 | 62.07% | 1 | 33.33% |
benjamin herrenschmidt | benjamin herrenschmidt | 21 | 36.21% | 1 | 33.33% |
philippe de muyter | philippe de muyter | 1 | 1.72% | 1 | 33.33% |
| Total | 58 | 100.00% | 3 | 100.00% |
void __exit nvram_cleanup(void)
{
misc_deregister( &nvram_dev );
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
benjamin herrenschmidt | benjamin herrenschmidt | 14 | 100.00% | 1 | 100.00% |
| Total | 14 | 100.00% | 1 | 100.00% |
module_init(nvram_init);
module_exit(nvram_cleanup);
MODULE_LICENSE("GPL");
Overall Contributors
| Person | Tokens | Prop | Commits | CommitProp |
benjamin herrenschmidt | benjamin herrenschmidt | 531 | 81.19% | 2 | 22.22% |
arnd bergmann | arnd bergmann | 59 | 9.02% | 2 | 22.22% |
martyn welch | martyn welch | 45 | 6.88% | 1 | 11.11% |
al viro | al viro | 13 | 1.99% | 1 | 11.11% |
jesper juhl | jesper juhl | 4 | 0.61% | 1 | 11.11% |
arjan van de ven | arjan van de ven | 1 | 0.15% | 1 | 11.11% |
philippe de muyter | philippe de muyter | 1 | 0.15% | 1 | 11.11% |
| Total | 654 | 100.00% | 9 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.