virtio: console: Store each console's size in the console structure
[safe/jmp/linux-2.6] / drivers / char / generic_nvram.c
index 1b5e01e..fda4181 100644 (file)
@@ -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
 #include <linux/miscdevice.h>
 #include <linux/fcntl.h>
 #include <linux/init.h>
-#include <linux/smp_lock.h>
 #include <asm/uaccess.h>
 #include <asm/nvram.h>
+#ifdef CONFIG_PPC_PMAC
+#include <asm/machdep.h>
+#endif
 
 #define NVRAM_SIZE     8192
 
+static ssize_t nvram_len;
+
 static loff_t nvram_llseek(struct file *file, loff_t offset, int origin)
 {
-       lock_kernel();
        switch (origin) {
        case 1:
                offset += file->f_pos;
                break;
        case 2:
-               offset += NVRAM_SIZE;
+               offset += nvram_len;
                break;
        }
-       if (offset < 0) {
-               unlock_kernel();
+       if (offset < 0)
                return -EINVAL;
-       }
+
        file->f_pos = offset;
-       unlock_kernel();
+
        return file->f_pos;
 }
 
@@ -53,9 +55,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;
@@ -71,9 +73,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);
@@ -92,7 +94,7 @@ static int nvram_ioctl(struct inode *inode, struct file *file,
        case IOC_NVRAM_GET_OFFSET: {
                int part, offset;
 
-               if (_machine != _MACH_Pmac)
+               if (!machine_is(powermac))
                        return -EINVAL;
                if (copy_from_user(&part, (void __user*)arg, sizeof(part)) != 0)
                        return -EFAULT;
@@ -114,7 +116,7 @@ static int nvram_ioctl(struct inode *inode, struct file *file,
        return 0;
 }
 
-struct file_operations nvram_fops = {
+const struct file_operations nvram_fops = {
        .owner          = THIS_MODULE,
        .llseek         = nvram_llseek,
        .read           = read_nvram,
@@ -130,9 +132,20 @@ static struct miscdevice nvram_dev = {
 
 int __init nvram_init(void)
 {
-       printk(KERN_INFO "Macintosh non-volatile memory driver v%s\n",
+       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)