]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - drivers/zorro/proc.c
Merge branches 'pm-domains', 'pm-docs' and 'pm-devfreq'
[mirror_ubuntu-zesty-kernel.git] / drivers / zorro / proc.c
CommitLineData
1da177e4 1/*
1da177e4
LT
2 * Procfs interface for the Zorro bus.
3 *
4 * Copyright (C) 1998-2003 Geert Uytterhoeven
5 *
6 * Heavily based on the procfs interface for the PCI bus, which is
7 *
8 * Copyright (C) 1997, 1998 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
9 */
10
11#include <linux/types.h>
12#include <linux/zorro.h>
13#include <linux/proc_fs.h>
8331438b 14#include <linux/seq_file.h>
1da177e4 15#include <linux/init.h>
8aaf7a0e 16#include <linux/export.h>
bd9ba8f4
GU
17
18#include <asm/byteorder.h>
7c0f6ba6 19#include <linux/uaccess.h>
1da177e4
LT
20#include <asm/amigahw.h>
21#include <asm/setup.h>
22
23static loff_t
24proc_bus_zorro_lseek(struct file *file, loff_t off, int whence)
25{
3be1f2b8 26 return fixed_size_llseek(file, off, whence, sizeof(struct ConfigDev));
1da177e4
LT
27}
28
29static ssize_t
d998265f 30proc_bus_zorro_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
1da177e4 31{
d9dda78b 32 struct zorro_dev *z = PDE_DATA(file_inode(file));
1da177e4
LT
33 struct ConfigDev cd;
34 loff_t pos = *ppos;
35
36 if (pos >= sizeof(struct ConfigDev))
37 return 0;
38 if (nbytes >= sizeof(struct ConfigDev))
39 nbytes = sizeof(struct ConfigDev);
40 if (pos + nbytes > sizeof(struct ConfigDev))
41 nbytes = sizeof(struct ConfigDev) - pos;
42
43 /* Construct a ConfigDev */
44 memset(&cd, 0, sizeof(cd));
45 cd.cd_Rom = z->rom;
bd9ba8f4
GU
46 cd.cd_SlotAddr = cpu_to_be16(z->slotaddr);
47 cd.cd_SlotSize = cpu_to_be16(z->slotsize);
48 cd.cd_BoardAddr = cpu_to_be32(zorro_resource_start(z));
49 cd.cd_BoardSize = cpu_to_be32(zorro_resource_len(z));
1da177e4 50
2190a1e7 51 if (copy_to_user(buf, (void *)&cd + pos, nbytes))
1da177e4
LT
52 return -EFAULT;
53 *ppos += nbytes;
54
55 return nbytes;
56}
57
00977a59 58static const struct file_operations proc_bus_zorro_operations = {
659f865e 59 .owner = THIS_MODULE,
1da177e4
LT
60 .llseek = proc_bus_zorro_lseek,
61 .read = proc_bus_zorro_read,
62};
63
8331438b 64static void * zorro_seq_start(struct seq_file *m, loff_t *pos)
1da177e4 65{
8331438b
AD
66 return (*pos < zorro_num_autocon) ? pos : NULL;
67}
68
69static void * zorro_seq_next(struct seq_file *m, void *v, loff_t *pos)
70{
71 (*pos)++;
72 return (*pos < zorro_num_autocon) ? pos : NULL;
73}
74
75static void zorro_seq_stop(struct seq_file *m, void *v)
76{
77}
78
79static int zorro_seq_show(struct seq_file *m, void *v)
80{
0d305464 81 unsigned int slot = *(loff_t *)v;
8331438b
AD
82 struct zorro_dev *z = &zorro_autocon[slot];
83
84 seq_printf(m, "%02x\t%08x\t%08lx\t%08lx\t%02x\n", slot, z->id,
85 (unsigned long)zorro_resource_start(z),
86 (unsigned long)zorro_resource_len(z),
87 z->rom.er_Type);
88 return 0;
89}
90
91static const struct seq_operations zorro_devices_seq_ops = {
92 .start = zorro_seq_start,
93 .next = zorro_seq_next,
94 .stop = zorro_seq_stop,
95 .show = zorro_seq_show,
96};
97
98static int zorro_devices_proc_open(struct inode *inode, struct file *file)
99{
100 return seq_open(file, &zorro_devices_seq_ops);
1da177e4
LT
101}
102
8331438b
AD
103static const struct file_operations zorro_devices_proc_fops = {
104 .owner = THIS_MODULE,
105 .open = zorro_devices_proc_open,
106 .read = seq_read,
107 .llseek = seq_lseek,
108 .release = seq_release,
109};
110
1da177e4
LT
111static struct proc_dir_entry *proc_bus_zorro_dir;
112
0d305464 113static int __init zorro_proc_attach_device(unsigned int slot)
1da177e4
LT
114{
115 struct proc_dir_entry *entry;
116 char name[4];
117
118 sprintf(name, "%02x", slot);
659f865e
DL
119 entry = proc_create_data(name, 0, proc_bus_zorro_dir,
120 &proc_bus_zorro_operations,
121 &zorro_autocon[slot]);
1da177e4
LT
122 if (!entry)
123 return -ENOMEM;
271a15ea 124 proc_set_size(entry, sizeof(struct zorro_dev));
1da177e4
LT
125 return 0;
126}
127
128static int __init zorro_proc_init(void)
129{
0d305464 130 unsigned int slot;
1da177e4
LT
131
132 if (MACH_IS_AMIGA && AMIGAHW_PRESENT(ZORRO)) {
9c37066d 133 proc_bus_zorro_dir = proc_mkdir("bus/zorro", NULL);
8331438b
AD
134 proc_create("devices", 0, proc_bus_zorro_dir,
135 &zorro_devices_proc_fops);
1da177e4
LT
136 for (slot = 0; slot < zorro_num_autocon; slot++)
137 zorro_proc_attach_device(slot);
138 }
139 return 0;
140}
141
a6a26a3e 142device_initcall(zorro_proc_init);