powerpc: Implement nvram ioctls
Add the powerpc-specific ioctls to the nvram module. This allows the nvram module to replace the generic_nvram module. 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:
parent
ebcebc7f45
commit
95ac14b8a3
|
@ -48,6 +48,9 @@
|
||||||
#include <linux/mutex.h>
|
#include <linux/mutex.h>
|
||||||
#include <linux/pagemap.h>
|
#include <linux/pagemap.h>
|
||||||
|
|
||||||
|
#ifdef CONFIG_PPC
|
||||||
|
#include <asm/nvram.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
static DEFINE_MUTEX(nvram_mutex);
|
static DEFINE_MUTEX(nvram_mutex);
|
||||||
static DEFINE_SPINLOCK(nvram_state_lock);
|
static DEFINE_SPINLOCK(nvram_state_lock);
|
||||||
|
@ -283,6 +286,38 @@ static long nvram_misc_ioctl(struct file *file, unsigned int cmd,
|
||||||
long ret = -ENOTTY;
|
long ret = -ENOTTY;
|
||||||
|
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
|
#ifdef CONFIG_PPC
|
||||||
|
case OBSOLETE_PMAC_NVRAM_GET_OFFSET:
|
||||||
|
pr_warn("nvram: Using obsolete PMAC_NVRAM_GET_OFFSET ioctl\n");
|
||||||
|
/* fall through */
|
||||||
|
case IOC_NVRAM_GET_OFFSET:
|
||||||
|
ret = -EINVAL;
|
||||||
|
#ifdef CONFIG_PPC_PMAC
|
||||||
|
if (machine_is(powermac)) {
|
||||||
|
int part, offset;
|
||||||
|
|
||||||
|
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;
|
||||||
|
ret = 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
break;
|
||||||
|
case IOC_NVRAM_SYNC:
|
||||||
|
if (ppc_md.nvram_sync != NULL) {
|
||||||
|
mutex_lock(&nvram_mutex);
|
||||||
|
ppc_md.nvram_sync();
|
||||||
|
mutex_unlock(&nvram_mutex);
|
||||||
|
}
|
||||||
|
ret = 0;
|
||||||
|
break;
|
||||||
|
#elif defined(CONFIG_X86) || defined(CONFIG_M68K)
|
||||||
case NVRAM_INIT:
|
case NVRAM_INIT:
|
||||||
/* initialize NVRAM contents and checksum */
|
/* initialize NVRAM contents and checksum */
|
||||||
if (!capable(CAP_SYS_ADMIN))
|
if (!capable(CAP_SYS_ADMIN))
|
||||||
|
@ -306,6 +341,7 @@ static long nvram_misc_ioctl(struct file *file, unsigned int cmd,
|
||||||
mutex_unlock(&nvram_mutex);
|
mutex_unlock(&nvram_mutex);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
#endif /* CONFIG_X86 || CONFIG_M68K */
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -321,12 +357,14 @@ static int nvram_misc_open(struct inode *inode, struct file *file)
|
||||||
return -EBUSY;
|
return -EBUSY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(CONFIG_X86) || defined(CONFIG_M68K)
|
||||||
/* Prevent multiple writers if the set_checksum ioctl is implemented. */
|
/* Prevent multiple writers if the set_checksum ioctl is implemented. */
|
||||||
if ((arch_nvram_ops.set_checksum != NULL) &&
|
if ((arch_nvram_ops.set_checksum != NULL) &&
|
||||||
(file->f_mode & FMODE_WRITE) && (nvram_open_mode & NVRAM_WRITE)) {
|
(file->f_mode & FMODE_WRITE) && (nvram_open_mode & NVRAM_WRITE)) {
|
||||||
spin_unlock(&nvram_state_lock);
|
spin_unlock(&nvram_state_lock);
|
||||||
return -EBUSY;
|
return -EBUSY;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (file->f_flags & O_EXCL)
|
if (file->f_flags & O_EXCL)
|
||||||
nvram_open_mode |= NVRAM_EXCL;
|
nvram_open_mode |= NVRAM_EXCL;
|
||||||
|
|
|
@ -31,8 +31,10 @@ struct nvram_ops {
|
||||||
void (*write_byte)(unsigned char, int);
|
void (*write_byte)(unsigned char, int);
|
||||||
ssize_t (*read)(char *, size_t, loff_t *);
|
ssize_t (*read)(char *, size_t, loff_t *);
|
||||||
ssize_t (*write)(char *, size_t, loff_t *);
|
ssize_t (*write)(char *, size_t, loff_t *);
|
||||||
|
#if defined(CONFIG_X86) || defined(CONFIG_M68K)
|
||||||
long (*initialize)(void);
|
long (*initialize)(void);
|
||||||
long (*set_checksum)(void);
|
long (*set_checksum)(void);
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
extern const struct nvram_ops arch_nvram_ops;
|
extern const struct nvram_ops arch_nvram_ops;
|
||||||
|
|
Loading…
Reference in New Issue