summaryrefslogtreecommitdiffstats
path: root/drivers/macintosh/nvram.c
blob: 9bb6166e4bddbbf77f7d705d5759056a95d30a2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
 * /dev/nvram driver for Power Macintosh.
 */
#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>

#define NVRAM_SIZE	8192

static long long nvram_llseek(struct inode *inode, struct file *file,
			      loff_t offset, int origin)
{
	switch (origin) {
	case 1:
		offset += file->f_pos;
		break;
	case 2:
		offset += NVRAM_SIZE;
		break;
	}
	if (offset < 0)
		return -EINVAL;
	file->f_pos = offset;
	return file->f_pos;
}

static long read_nvram(struct inode *inode, struct file *file,
	char *buf, unsigned long count)
{
	unsigned int i = file->f_pos;
	char *p = buf;

	for (; count > 0 && i < NVRAM_SIZE; ++i, ++p, --count)
		put_user(nvram_read_byte(i), p);
	file->f_pos = i;
	return p - buf;
}

static long write_nvram(struct inode *inode, struct file *file,
	const char *buf, unsigned long count)
{
	unsigned int i = file->f_pos;
	const char *p = buf;
	char c;

	for (; count > 0 && i < NVRAM_SIZE; ++i, ++p, --count) {
		get_user(c, p);
		nvram_write_byte(i, c);
	}
	file->f_pos = i;
	return p - buf;
}

static int nvram_open(struct inode *inode, struct file *file)
{
	return 0;
}

struct file_operations nvram_fops = {
	nvram_llseek,
	read_nvram,
	write_nvram,
	NULL,		/* nvram_readdir */
	NULL,		/* nvram_select */
	NULL,		/* nvram_ioctl */
	NULL,		/* nvram_mmap */
	nvram_open,
	NULL,		/* no special release code */
	NULL		/* fsync */
};

static struct miscdevice nvram_dev = {
	NVRAM_MINOR,
	"nvram",
	&nvram_fops
};

__initfunc(int nvram_init(void))
{
	misc_register(&nvram_dev);
	return 0;
}