linux/drivers/macintosh/nvram.c
<<
>>
Prefs
   1/*
   2 * /dev/nvram driver for Power Macintosh.
   3 */
   4
   5#define NVRAM_VERSION "1.0"
   6
   7#include <linux/module.h>
   8
   9#include <linux/types.h>
  10#include <linux/errno.h>
  11#include <linux/fs.h>
  12#include <linux/miscdevice.h>
  13#include <linux/fcntl.h>
  14#include <linux/nvram.h>
  15#include <linux/init.h>
  16#include <asm/uaccess.h>
  17#include <asm/nvram.h>
  18
  19#define NVRAM_SIZE      8192
  20
  21static loff_t nvram_llseek(struct file *file, loff_t offset, int origin)
  22{
  23        switch (origin) {
  24        case 0:
  25                break;
  26        case 1:
  27                offset += file->f_pos;
  28                break;
  29        case 2:
  30                offset += NVRAM_SIZE;
  31                break;
  32        default:
  33                offset = -1;
  34        }
  35        if (offset < 0)
  36                return -EINVAL;
  37
  38        file->f_pos = offset;
  39        return file->f_pos;
  40}
  41
  42static ssize_t read_nvram(struct file *file, char __user *buf,
  43                          size_t count, loff_t *ppos)
  44{
  45        unsigned int i;
  46        char __user *p = buf;
  47
  48        if (!access_ok(VERIFY_WRITE, buf, count))
  49                return -EFAULT;
  50        if (*ppos >= NVRAM_SIZE)
  51                return 0;
  52        for (i = *ppos; count > 0 && i < NVRAM_SIZE; ++i, ++p, --count)
  53                if (__put_user(nvram_read_byte(i), p))
  54                        return -EFAULT;
  55        *ppos = i;
  56        return p - buf;
  57}
  58
  59static ssize_t write_nvram(struct file *file, const char __user *buf,
  60                           size_t count, loff_t *ppos)
  61{
  62        unsigned int i;
  63        const char __user *p = buf;
  64        char c;
  65
  66        if (!access_ok(VERIFY_READ, buf, count))
  67                return -EFAULT;
  68        if (*ppos >= NVRAM_SIZE)
  69                return 0;
  70        for (i = *ppos; count > 0 && i < NVRAM_SIZE; ++i, ++p, --count) {
  71                if (__get_user(c, p))
  72                        return -EFAULT;
  73                nvram_write_byte(c, i);
  74        }
  75        *ppos = i;
  76        return p - buf;
  77}
  78
  79static long nvram_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  80{
  81        switch(cmd) {
  82                case PMAC_NVRAM_GET_OFFSET:
  83                {
  84                        int part, offset;
  85                        if (copy_from_user(&part, (void __user*)arg, sizeof(part)) != 0)
  86                                return -EFAULT;
  87                        if (part < pmac_nvram_OF || part > pmac_nvram_NR)
  88                                return -EINVAL;
  89                        offset = pmac_get_partition(part);
  90                        if (copy_to_user((void __user*)arg, &offset, sizeof(offset)) != 0)
  91                                return -EFAULT;
  92                        break;
  93                }
  94
  95                default:
  96                        return -EINVAL;
  97        }
  98
  99        return 0;
 100}
 101
 102const struct file_operations nvram_fops = {
 103        .owner          = THIS_MODULE,
 104        .llseek         = nvram_llseek(str href="drivers/macintosh/nvram.c#L104" i3ivers/maclass="line" name="L95">acla4nvra_byt                href="+code=nvra_nvram" class="sref">read_nvram(str href="drivers/macintosh/nvram.c#L104" id="L16" c0lass="line" name="L16"> 06a4write_nvr          = write_nvram(str href="drivers/macintosh/nvram.c#L104" id="L17" c0lass="line" name="L17"> 07a4nvraunlockedtl" cl = nvram_ioctl(str href="drivers/macintosh/nvram.c#L104" id="L18" c0lass="line" name="L18"> 08a4
 09a4   10<1a>#incic longct nvradevice.hnvram_ioctce. = {
  101            ref="+code=NVRAM_SIZEMINOlass="sref">pmacM_SIZEMINOl(str href="drivers/macintosh/nvram.c#L104" id="L12" cclass="line" name="L12">   12<11>            n class="string">"1.0&m.c#Lt;
   13<11>        .nvram_fops = {href="drivers/macintosh/nvram.c#L104" id="L104" class="line" name="L14">   14<1a>#inc} href="drivers/macintosh/nvram.c#L100" id="L15" cclass="line" name="L15">   15<11>
   16<1a>#inc__user.h__usm_fops.h   17<1a>#inc href="drivers/macintosh/nvram.c#L103" id="L18" cclass="line" name="L18">   18<11>        &tlass="sref">nvrap">&tl(nvraKERN_INFO "1.0&ntosh.
   19<11>                    ref="+code=NVRAM_SIZEION" class="sref">NVRAM_VERSION 1  20<12>            rn ownedevi_registcl(&nvram_ioctce. = {a href="drivers/macintosh/nvram.c#L90" 1id="L11" cclass="line" name="L21">1  21<1a>stat href="drivers/macintosh/nvram.c#L101" id="L22" 1class="line" name="L22">1  22<1a>{
1  23<1a>     __userexp1  24<12>{
1  25<1a>            ref="+code=p" cdevi_deregistclass="sref">ownedevi_deregistcl((voi ;nvram_ioctce. = {
a href="drivers/macintosh/nvram.c#L90" 1id="L16" cclass="line" name="L26">1  26<1a>     href="drivers/macintosh/nvram.c#L101" id="L17" cclass="line" name="L27">1  27<12>
1  28<1a>    ref="+code=p" cde.h__usde.h__usm_fops.h1  29<1a>    ref="+code=p" cde.h__usde.hp1  30<1a>    ref="+code=partLE_LICENSlass="sref">THISLE_LICENSl("1.0&GPLt;
1  31<1a>    
    

v>

The inal LXR software by th href="+codhttp://sourceforge.net/projects/lxla>LXR ent"uh experi"> *al /macion by ref="+codmailto:lxl@l/ini.no">lxl@l/ini.no, si. v> lxl.l/ini.no kindly hostcd by ref="+codhttp://www.redpill-l/ipro.no">Redpill L/ipro AS, sizeprovider of L/iuxst chult>&q and ations ser.h since 1995. v>