Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
Alexey Dobriyan | 8331438 | 2008-04-29 01:01:45 -0700 | [diff] [blame] | 14 | #include <linux/seq_file.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <asm/uaccess.h> |
| 17 | #include <asm/amigahw.h> |
| 18 | #include <asm/setup.h> |
| 19 | |
| 20 | static loff_t |
| 21 | proc_bus_zorro_lseek(struct file *file, loff_t off, int whence) |
| 22 | { |
| 23 | loff_t new = -1; |
Geert Uytterhoeven | d50ac46 | 2010-06-05 13:28:09 +0200 | [diff] [blame] | 24 | struct inode *inode = file->f_path.dentry->d_inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
Geert Uytterhoeven | d50ac46 | 2010-06-05 13:28:09 +0200 | [diff] [blame] | 26 | mutex_lock(&inode->i_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | switch (whence) { |
| 28 | case 0: |
| 29 | new = off; |
| 30 | break; |
| 31 | case 1: |
| 32 | new = file->f_pos + off; |
| 33 | break; |
| 34 | case 2: |
| 35 | new = sizeof(struct ConfigDev) + off; |
| 36 | break; |
| 37 | } |
Geert Uytterhoeven | d50ac46 | 2010-06-05 13:28:09 +0200 | [diff] [blame] | 38 | if (new < 0 || new > sizeof(struct ConfigDev)) |
| 39 | new = -EINVAL; |
| 40 | else |
| 41 | file->f_pos = new; |
| 42 | mutex_unlock(&inode->i_mutex); |
| 43 | return new; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | static ssize_t |
Al Viro | d998265 | 2006-01-12 01:06:32 -0800 | [diff] [blame] | 47 | proc_bus_zorro_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | { |
Josef Sipek | b3d7ae5 | 2006-12-08 02:37:48 -0800 | [diff] [blame] | 49 | struct inode *ino = file->f_path.dentry->d_inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | struct proc_dir_entry *dp = PDE(ino); |
| 51 | struct zorro_dev *z = dp->data; |
| 52 | struct ConfigDev cd; |
| 53 | loff_t pos = *ppos; |
| 54 | |
| 55 | if (pos >= sizeof(struct ConfigDev)) |
| 56 | return 0; |
| 57 | if (nbytes >= sizeof(struct ConfigDev)) |
| 58 | nbytes = sizeof(struct ConfigDev); |
| 59 | if (pos + nbytes > sizeof(struct ConfigDev)) |
| 60 | nbytes = sizeof(struct ConfigDev) - pos; |
| 61 | |
| 62 | /* Construct a ConfigDev */ |
| 63 | memset(&cd, 0, sizeof(cd)); |
| 64 | cd.cd_Rom = z->rom; |
| 65 | cd.cd_SlotAddr = z->slotaddr; |
| 66 | cd.cd_SlotSize = z->slotsize; |
| 67 | cd.cd_BoardAddr = (void *)zorro_resource_start(z); |
| 68 | cd.cd_BoardSize = zorro_resource_len(z); |
| 69 | |
Geert Uytterhoeven | 2190a1e | 2010-06-09 11:24:32 +0200 | [diff] [blame] | 70 | if (copy_to_user(buf, (void *)&cd + pos, nbytes)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | return -EFAULT; |
| 72 | *ppos += nbytes; |
| 73 | |
| 74 | return nbytes; |
| 75 | } |
| 76 | |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 77 | static const struct file_operations proc_bus_zorro_operations = { |
Denis V. Lunev | 659f865 | 2008-04-29 01:02:16 -0700 | [diff] [blame] | 78 | .owner = THIS_MODULE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | .llseek = proc_bus_zorro_lseek, |
| 80 | .read = proc_bus_zorro_read, |
| 81 | }; |
| 82 | |
Alexey Dobriyan | 8331438 | 2008-04-29 01:01:45 -0700 | [diff] [blame] | 83 | static void * zorro_seq_start(struct seq_file *m, loff_t *pos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | { |
Alexey Dobriyan | 8331438 | 2008-04-29 01:01:45 -0700 | [diff] [blame] | 85 | return (*pos < zorro_num_autocon) ? pos : NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Alexey Dobriyan | 8331438 | 2008-04-29 01:01:45 -0700 | [diff] [blame] | 88 | static void * zorro_seq_next(struct seq_file *m, void *v, loff_t *pos) |
| 89 | { |
| 90 | (*pos)++; |
| 91 | return (*pos < zorro_num_autocon) ? pos : NULL; |
| 92 | } |
| 93 | |
| 94 | static void zorro_seq_stop(struct seq_file *m, void *v) |
| 95 | { |
| 96 | } |
| 97 | |
| 98 | static int zorro_seq_show(struct seq_file *m, void *v) |
| 99 | { |
Geert Uytterhoeven | 0d30546 | 2009-04-05 12:40:41 +0200 | [diff] [blame] | 100 | unsigned int slot = *(loff_t *)v; |
Alexey Dobriyan | 8331438 | 2008-04-29 01:01:45 -0700 | [diff] [blame] | 101 | struct zorro_dev *z = &zorro_autocon[slot]; |
| 102 | |
| 103 | seq_printf(m, "%02x\t%08x\t%08lx\t%08lx\t%02x\n", slot, z->id, |
| 104 | (unsigned long)zorro_resource_start(z), |
| 105 | (unsigned long)zorro_resource_len(z), |
| 106 | z->rom.er_Type); |
| 107 | return 0; |
| 108 | } |
| 109 | |
| 110 | static const struct seq_operations zorro_devices_seq_ops = { |
| 111 | .start = zorro_seq_start, |
| 112 | .next = zorro_seq_next, |
| 113 | .stop = zorro_seq_stop, |
| 114 | .show = zorro_seq_show, |
| 115 | }; |
| 116 | |
| 117 | static int zorro_devices_proc_open(struct inode *inode, struct file *file) |
| 118 | { |
| 119 | return seq_open(file, &zorro_devices_seq_ops); |
| 120 | } |
| 121 | |
| 122 | static const struct file_operations zorro_devices_proc_fops = { |
| 123 | .owner = THIS_MODULE, |
| 124 | .open = zorro_devices_proc_open, |
| 125 | .read = seq_read, |
| 126 | .llseek = seq_lseek, |
| 127 | .release = seq_release, |
| 128 | }; |
| 129 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | static struct proc_dir_entry *proc_bus_zorro_dir; |
| 131 | |
Geert Uytterhoeven | 0d30546 | 2009-04-05 12:40:41 +0200 | [diff] [blame] | 132 | static int __init zorro_proc_attach_device(unsigned int slot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | { |
| 134 | struct proc_dir_entry *entry; |
| 135 | char name[4]; |
| 136 | |
| 137 | sprintf(name, "%02x", slot); |
Denis V. Lunev | 659f865 | 2008-04-29 01:02:16 -0700 | [diff] [blame] | 138 | entry = proc_create_data(name, 0, proc_bus_zorro_dir, |
| 139 | &proc_bus_zorro_operations, |
| 140 | &zorro_autocon[slot]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | if (!entry) |
| 142 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | entry->size = sizeof(struct zorro_dev); |
| 144 | return 0; |
| 145 | } |
| 146 | |
| 147 | static int __init zorro_proc_init(void) |
| 148 | { |
Geert Uytterhoeven | 0d30546 | 2009-04-05 12:40:41 +0200 | [diff] [blame] | 149 | unsigned int slot; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | |
| 151 | if (MACH_IS_AMIGA && AMIGAHW_PRESENT(ZORRO)) { |
Alexey Dobriyan | 9c37066 | 2008-04-29 01:01:41 -0700 | [diff] [blame] | 152 | proc_bus_zorro_dir = proc_mkdir("bus/zorro", NULL); |
Alexey Dobriyan | 8331438 | 2008-04-29 01:01:45 -0700 | [diff] [blame] | 153 | proc_create("devices", 0, proc_bus_zorro_dir, |
| 154 | &zorro_devices_proc_fops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | for (slot = 0; slot < zorro_num_autocon; slot++) |
| 156 | zorro_proc_attach_device(slot); |
| 157 | } |
| 158 | return 0; |
| 159 | } |
| 160 | |
Robert P. J. Day | a6a26a3 | 2008-07-17 21:16:16 +0200 | [diff] [blame] | 161 | device_initcall(zorro_proc_init); |