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