0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include <linux/types.h>
0013 #include <linux/zorro.h>
0014 #include <linux/proc_fs.h>
0015 #include <linux/seq_file.h>
0016 #include <linux/init.h>
0017 #include <linux/export.h>
0018
0019 #include <asm/byteorder.h>
0020 #include <linux/uaccess.h>
0021 #include <asm/amigahw.h>
0022 #include <asm/setup.h>
0023
0024 static loff_t
0025 proc_bus_zorro_lseek(struct file *file, loff_t off, int whence)
0026 {
0027 return fixed_size_llseek(file, off, whence, sizeof(struct ConfigDev));
0028 }
0029
0030 static ssize_t
0031 proc_bus_zorro_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
0032 {
0033 struct zorro_dev *z = pde_data(file_inode(file));
0034 struct ConfigDev cd;
0035 loff_t pos = *ppos;
0036
0037 if (pos >= sizeof(struct ConfigDev))
0038 return 0;
0039 if (nbytes >= sizeof(struct ConfigDev))
0040 nbytes = sizeof(struct ConfigDev);
0041 if (pos + nbytes > sizeof(struct ConfigDev))
0042 nbytes = sizeof(struct ConfigDev) - pos;
0043
0044
0045 memset(&cd, 0, sizeof(cd));
0046 cd.cd_Rom = z->rom;
0047 cd.cd_SlotAddr = cpu_to_be16(z->slotaddr);
0048 cd.cd_SlotSize = cpu_to_be16(z->slotsize);
0049 cd.cd_BoardAddr = cpu_to_be32(zorro_resource_start(z));
0050 cd.cd_BoardSize = cpu_to_be32(zorro_resource_len(z));
0051
0052 if (copy_to_user(buf, (void *)&cd + pos, nbytes))
0053 return -EFAULT;
0054 *ppos += nbytes;
0055
0056 return nbytes;
0057 }
0058
0059 static const struct proc_ops bus_zorro_proc_ops = {
0060 .proc_lseek = proc_bus_zorro_lseek,
0061 .proc_read = proc_bus_zorro_read,
0062 };
0063
0064 static void * zorro_seq_start(struct seq_file *m, loff_t *pos)
0065 {
0066 return (*pos < zorro_num_autocon) ? pos : NULL;
0067 }
0068
0069 static void * zorro_seq_next(struct seq_file *m, void *v, loff_t *pos)
0070 {
0071 (*pos)++;
0072 return (*pos < zorro_num_autocon) ? pos : NULL;
0073 }
0074
0075 static void zorro_seq_stop(struct seq_file *m, void *v)
0076 {
0077 }
0078
0079 static int zorro_seq_show(struct seq_file *m, void *v)
0080 {
0081 unsigned int slot = *(loff_t *)v;
0082 struct zorro_dev *z = &zorro_autocon[slot];
0083
0084 seq_printf(m, "%02x\t%08x\t%08lx\t%08lx\t%02x\n", slot, z->id,
0085 (unsigned long)zorro_resource_start(z),
0086 (unsigned long)zorro_resource_len(z),
0087 z->rom.er_Type);
0088 return 0;
0089 }
0090
0091 static const struct seq_operations zorro_devices_seq_ops = {
0092 .start = zorro_seq_start,
0093 .next = zorro_seq_next,
0094 .stop = zorro_seq_stop,
0095 .show = zorro_seq_show,
0096 };
0097
0098 static struct proc_dir_entry *proc_bus_zorro_dir;
0099
0100 static int __init zorro_proc_attach_device(unsigned int slot)
0101 {
0102 struct proc_dir_entry *entry;
0103 char name[4];
0104
0105 sprintf(name, "%02x", slot);
0106 entry = proc_create_data(name, 0, proc_bus_zorro_dir,
0107 &bus_zorro_proc_ops,
0108 &zorro_autocon[slot]);
0109 if (!entry)
0110 return -ENOMEM;
0111 proc_set_size(entry, sizeof(struct zorro_dev));
0112 return 0;
0113 }
0114
0115 static int __init zorro_proc_init(void)
0116 {
0117 unsigned int slot;
0118
0119 if (MACH_IS_AMIGA && AMIGAHW_PRESENT(ZORRO)) {
0120 proc_bus_zorro_dir = proc_mkdir("bus/zorro", NULL);
0121 proc_create_seq("devices", 0, proc_bus_zorro_dir,
0122 &zorro_devices_seq_ops);
0123 for (slot = 0; slot < zorro_num_autocon; slot++)
0124 zorro_proc_attach_device(slot);
0125 }
0126 return 0;
0127 }
0128
0129 device_initcall(zorro_proc_init);