Commit b5d92a49 authored by Anton Blanchard's avatar Anton Blanchard

ppc64: Add RTAS NVRAM driver, from Todd Inglett

parent 09f37343
......@@ -449,7 +449,6 @@ CONFIG_PSMOUSE=y
#
# CONFIG_WATCHDOG is not set
# CONFIG_INTEL_RNG is not set
CONFIG_NVRAM=y
# CONFIG_DTLK is not set
# CONFIG_R3964 is not set
# CONFIG_APPLICOM is not set
......
......@@ -38,18 +38,13 @@ endif
ifeq ($(CONFIG_PPC_PSERIES),y)
obj-$(CONFIG_PCI) += pSeries_pci.o pSeries_lpar.o pSeries_hvCall.o
obj-y += rtasd.o
obj-y += rtasd.o nvram.o
endif
obj-$(CONFIG_KGDB) += ppc-stub.o
obj-$(CONFIG_SMP) += smp.o
# tibit: for matrox_init2()
ifeq ($(CONFIG_NVRAM),y)
obj-$(CONFIG_NVRAM) += pmac_nvram.o
endif
obj-y += prom.o lmb.o rtas.o rtas-proc.o chrp_setup.o i8259.o
include $(TOPDIR)/Rules.make
......
/*
* c 2001 PPC 64 Team, IBM Corp
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*
* /dev/nvram driver for PPC64
*
* This perhaps should live in drivers/char
*/
#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/nvram.h>
#include <linux/init.h>
#include <asm/uaccess.h>
#include <asm/nvram.h>
#include <asm/rtas.h>
#include <asm/prom.h>
static unsigned int rtas_nvram_size;
static unsigned int nvram_fetch, nvram_store;
static char nvram_buf[4]; /* assume this is in the first 4GB */
static loff_t nvram_llseek(struct file *file, loff_t offset, int origin)
{
switch (origin) {
case 1:
offset += file->f_pos;
break;
case 2:
offset += rtas_nvram_size;
break;
}
if (offset < 0)
return -EINVAL;
file->f_pos = offset;
return file->f_pos;
}
static ssize_t read_nvram(struct file *file, char *buf,
size_t count, loff_t *ppos)
{
unsigned int i;
unsigned long len;
char *p = buf;
if (verify_area(VERIFY_WRITE, buf, count))
return -EFAULT;
if (*ppos >= rtas_nvram_size)
return 0;
for (i = *ppos; count > 0 && i < rtas_nvram_size; ++i, ++p, --count) {
if ((rtas_call(nvram_fetch, 3, 2, &len, i, __pa(nvram_buf), 1) != 0) ||
len != 1)
return -EIO;
if (__put_user(nvram_buf[0], p))
return -EFAULT;
}
*ppos = i;
return p - buf;
}
static ssize_t write_nvram(struct file *file, const char *buf,
size_t count, loff_t *ppos)
{
unsigned int i;
unsigned long len;
const char *p = buf;
char c;
if (verify_area(VERIFY_READ, buf, count))
return -EFAULT;
if (*ppos >= rtas_nvram_size)
return 0;
for (i = *ppos; count > 0 && i < rtas_nvram_size; ++i, ++p, --count) {
if (__get_user(c, p))
return -EFAULT;
nvram_buf[0] = c;
if ((rtas_call(nvram_store, 3, 2, &len, i, __pa(nvram_buf), 1) != 0) ||
len != 1)
return -EIO;
}
*ppos = i;
return p - buf;
}
static int nvram_ioctl(struct inode *inode, struct file *file,
unsigned int cmd, unsigned long arg)
{
return -EINVAL;
}
struct file_operations nvram_fops = {
owner: THIS_MODULE,
llseek: nvram_llseek,
read: read_nvram,
write: write_nvram,
ioctl: nvram_ioctl,
};
static struct miscdevice nvram_dev = {
NVRAM_MINOR,
"nvram",
&nvram_fops
};
int __init nvram_init(void)
{
struct device_node *nvram;
unsigned int *nbytes_p, proplen;
if ((nvram = find_type_devices("nvram")) != NULL) {
nbytes_p = (unsigned int *)get_property(nvram, "#bytes", &proplen);
if (nbytes_p && proplen == sizeof(unsigned int)) {
rtas_nvram_size = *nbytes_p;
}
}
nvram_fetch = rtas_token("nvram-fetch");
nvram_store = rtas_token("nvram-store");
printk(KERN_INFO "PPC64 nvram contains %d bytes\n", rtas_nvram_size);
misc_register(&nvram_dev);
return 0;
}
void __exit nvram_cleanup(void)
{
misc_deregister( &nvram_dev );
}
module_init(nvram_init);
module_exit(nvram_cleanup);
MODULE_LICENSE("GPL");
......@@ -148,17 +148,5 @@ extern char cmd_line[512];
extern void setup_pci_ptrs(void);
/*
* Power macintoshes have either a CUDA or a PMU controlling
* system reset, power, NVRAM, RTC.
*/
typedef enum sys_ctrler_kind {
SYS_CTRLER_UNKNOWN = 0,
SYS_CTRLER_CUDA = 1,
SYS_CTRLER_PMU = 2,
} sys_ctrler_t;
extern sys_ctrler_t sys_ctrler;
#endif /* _PPC_MACHDEP_H */
#endif /* __KERNEL__ */
......@@ -36,33 +36,4 @@
#define BIN_TO_BCD(val) ((val)=(((val)/10)<<4) + (val)%10)
#endif
/* PowerMac specific nvram stuffs */
enum {
pmac_nvram_OF, /* Open Firmware partition */
pmac_nvram_XPRAM, /* MacOS XPRAM partition */
pmac_nvram_NR /* MacOS Name Registry partition */
};
/* Return partition offset in nvram */
extern int pmac_get_partition(int partition);
/* Direct access to XPRAM */
extern u8 pmac_xpram_read(int xpaddr);
extern void pmac_xpram_write(int xpaddr, u8 data);
/* Some offsets in XPRAM */
#define PMAC_XPRAM_MACHINE_LOC 0xe4
#define PMAC_XPRAM_SOUND_VOLUME 0x08
/* Machine location structure in XPRAM */
struct pmac_machine_location {
u32 latitude; /* 2+30 bit Fractional number */
u32 longitude; /* 2+30 bit Fractional number */
u32 delta; /* mix of GMT delta and DLS */
};
/* /dev/nvram ioctls */
#define PMAC_NVRAM_GET_OFFSET _IOWR('p', 0x40, int) /* Get NVRAM partition offset */
#endif /* _PPC64_NVRAM_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment