Blame view

drivers/zorro/proc.c 3.76 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
  /*
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2
3
4
5
6
7
8
9
10
11
12
13
   *	Procfs interface for the Zorro bus.
   *
   *	Copyright (C) 1998-2003 Geert Uytterhoeven
   *
   *	Heavily based on the procfs interface for the PCI bus, which is
   *
   *	Copyright (C) 1997, 1998 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
   */
  
  #include <linux/types.h>
  #include <linux/zorro.h>
  #include <linux/proc_fs.h>
8331438b3   Alexey Dobriyan   proc: switch /pro...
14
  #include <linux/seq_file.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
15
  #include <linux/init.h>
8aaf7a0e3   Paul Gortmaker   drivers/zorro: Ad...
16
  #include <linux/export.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
17
18
19
20
21
22
23
24
  #include <asm/uaccess.h>
  #include <asm/amigahw.h>
  #include <asm/setup.h>
  
  static loff_t
  proc_bus_zorro_lseek(struct file *file, loff_t off, int whence)
  {
  	loff_t new = -1;
d50ac468d   Geert Uytterhoeven   zorro: BKL removal
25
  	struct inode *inode = file->f_path.dentry->d_inode;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
26

d50ac468d   Geert Uytterhoeven   zorro: BKL removal
27
  	mutex_lock(&inode->i_mutex);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
28
29
30
31
32
33
34
35
36
37
38
  	switch (whence) {
  	case 0:
  		new = off;
  		break;
  	case 1:
  		new = file->f_pos + off;
  		break;
  	case 2:
  		new = sizeof(struct ConfigDev) + off;
  		break;
  	}
d50ac468d   Geert Uytterhoeven   zorro: BKL removal
39
40
41
42
43
44
  	if (new < 0 || new > sizeof(struct ConfigDev))
  		new = -EINVAL;
  	else
  		file->f_pos = new;
  	mutex_unlock(&inode->i_mutex);
  	return new;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
45
46
47
  }
  
  static ssize_t
d998265fe   Al Viro   [PATCH] m68k: zor...
48
  proc_bus_zorro_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
49
  {
b3d7ae5f4   Josef Sipek   [PATCH] struct pa...
50
  	struct inode *ino = file->f_path.dentry->d_inode;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
  	struct proc_dir_entry *dp = PDE(ino);
  	struct zorro_dev *z = dp->data;
  	struct ConfigDev cd;
  	loff_t pos = *ppos;
  
  	if (pos >= sizeof(struct ConfigDev))
  		return 0;
  	if (nbytes >= sizeof(struct ConfigDev))
  		nbytes = sizeof(struct ConfigDev);
  	if (pos + nbytes > sizeof(struct ConfigDev))
  		nbytes = sizeof(struct ConfigDev) - pos;
  
  	/* Construct a ConfigDev */
  	memset(&cd, 0, sizeof(cd));
  	cd.cd_Rom = z->rom;
  	cd.cd_SlotAddr = z->slotaddr;
  	cd.cd_SlotSize = z->slotsize;
  	cd.cd_BoardAddr = (void *)zorro_resource_start(z);
  	cd.cd_BoardSize = zorro_resource_len(z);
2190a1e77   Geert Uytterhoeven   zorro: Fix readin...
70
  	if (copy_to_user(buf, (void *)&cd + pos, nbytes))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
71
72
73
74
75
  		return -EFAULT;
  	*ppos += nbytes;
  
  	return nbytes;
  }
00977a59b   Arjan van de Ven   [PATCH] mark stru...
76
  static const struct file_operations proc_bus_zorro_operations = {
659f865ea   Denis V. Lunev   zorro: use non-ra...
77
  	.owner		= THIS_MODULE,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
78
79
80
  	.llseek		= proc_bus_zorro_lseek,
  	.read		= proc_bus_zorro_read,
  };
8331438b3   Alexey Dobriyan   proc: switch /pro...
81
  static void * zorro_seq_start(struct seq_file *m, loff_t *pos)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
82
  {
8331438b3   Alexey Dobriyan   proc: switch /pro...
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
  	return (*pos < zorro_num_autocon) ? pos : NULL;
  }
  
  static void * zorro_seq_next(struct seq_file *m, void *v, loff_t *pos)
  {
  	(*pos)++;
  	return (*pos < zorro_num_autocon) ? pos : NULL;
  }
  
  static void zorro_seq_stop(struct seq_file *m, void *v)
  {
  }
  
  static int zorro_seq_show(struct seq_file *m, void *v)
  {
0d305464a   Geert Uytterhoeven   m68k: amiga - Zor...
98
  	unsigned int slot = *(loff_t *)v;
8331438b3   Alexey Dobriyan   proc: switch /pro...
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
  	struct zorro_dev *z = &zorro_autocon[slot];
  
  	seq_printf(m, "%02x\t%08x\t%08lx\t%08lx\t%02x
  ", slot, z->id,
  		   (unsigned long)zorro_resource_start(z),
  		   (unsigned long)zorro_resource_len(z),
  		   z->rom.er_Type);
  	return 0;
  }
  
  static const struct seq_operations zorro_devices_seq_ops = {
  	.start = zorro_seq_start,
  	.next  = zorro_seq_next,
  	.stop  = zorro_seq_stop,
  	.show  = zorro_seq_show,
  };
  
  static int zorro_devices_proc_open(struct inode *inode, struct file *file)
  {
  	return seq_open(file, &zorro_devices_seq_ops);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
119
  }
8331438b3   Alexey Dobriyan   proc: switch /pro...
120
121
122
123
124
125
126
  static const struct file_operations zorro_devices_proc_fops = {
  	.owner		= THIS_MODULE,
  	.open		= zorro_devices_proc_open,
  	.read		= seq_read,
  	.llseek		= seq_lseek,
  	.release	= seq_release,
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
127
  static struct proc_dir_entry *proc_bus_zorro_dir;
0d305464a   Geert Uytterhoeven   m68k: amiga - Zor...
128
  static int __init zorro_proc_attach_device(unsigned int slot)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
129
130
131
132
133
  {
  	struct proc_dir_entry *entry;
  	char name[4];
  
  	sprintf(name, "%02x", slot);
659f865ea   Denis V. Lunev   zorro: use non-ra...
134
135
136
  	entry = proc_create_data(name, 0, proc_bus_zorro_dir,
  				 &proc_bus_zorro_operations,
  				 &zorro_autocon[slot]);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
137
138
  	if (!entry)
  		return -ENOMEM;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
139
140
141
142
143
144
  	entry->size = sizeof(struct zorro_dev);
  	return 0;
  }
  
  static int __init zorro_proc_init(void)
  {
0d305464a   Geert Uytterhoeven   m68k: amiga - Zor...
145
  	unsigned int slot;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
146
147
  
  	if (MACH_IS_AMIGA && AMIGAHW_PRESENT(ZORRO)) {
9c37066d8   Alexey Dobriyan   proc: remove proc...
148
  		proc_bus_zorro_dir = proc_mkdir("bus/zorro", NULL);
8331438b3   Alexey Dobriyan   proc: switch /pro...
149
150
  		proc_create("devices", 0, proc_bus_zorro_dir,
  			    &zorro_devices_proc_fops);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
151
152
153
154
155
  		for (slot = 0; slot < zorro_num_autocon; slot++)
  			zorro_proc_attach_device(slot);
  	}
  	return 0;
  }
a6a26a3e6   Robert P. J. Day   ZORRO: Replace de...
156
  device_initcall(zorro_proc_init);