Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * Procfs interface for the Zorro bus. |
| 4 | * |
| 5 | * Copyright (C) 1998-2003 Geert Uytterhoeven |
| 6 | * |
| 7 | * Heavily based on the procfs interface for the PCI bus, which is |
| 8 | * |
| 9 | * Copyright (C) 1997, 1998 Martin Mares <mj@atrey.karlin.mff.cuni.cz> |
| 10 | */ |
| 11 | |
| 12 | #include <linux/types.h> |
| 13 | #include <linux/zorro.h> |
| 14 | #include <linux/proc_fs.h> |
Alexey Dobriyan | 8331438 | 2008-04-29 01:01:45 -0700 | [diff] [blame] | 15 | #include <linux/seq_file.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <linux/init.h> |
Paul Gortmaker | 8aaf7a0 | 2011-08-01 10:58:14 -0400 | [diff] [blame] | 17 | #include <linux/export.h> |
Geert Uytterhoeven | bd9ba8f | 2013-10-04 09:38:53 +0200 | [diff] [blame] | 18 | |
| 19 | #include <asm/byteorder.h> |
Linus Torvalds | 7c0f6ba | 2016-12-24 11:46:01 -0800 | [diff] [blame] | 20 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <asm/amigahw.h> |
| 22 | #include <asm/setup.h> |
| 23 | |
| 24 | static loff_t |
| 25 | proc_bus_zorro_lseek(struct file *file, loff_t off, int whence) |
| 26 | { |
Al Viro | 3be1f2b | 2013-06-22 12:10:22 +0400 | [diff] [blame] | 27 | return fixed_size_llseek(file, off, whence, sizeof(struct ConfigDev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | static ssize_t |
Al Viro | d998265 | 2006-01-12 01:06:32 -0800 | [diff] [blame] | 31 | 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] | 32 | { |
Al Viro | d9dda78 | 2013-03-31 18:16:14 -0400 | [diff] [blame] | 33 | struct zorro_dev *z = PDE_DATA(file_inode(file)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | struct ConfigDev cd; |
| 35 | loff_t pos = *ppos; |
| 36 | |
| 37 | if (pos >= sizeof(struct ConfigDev)) |
| 38 | return 0; |
| 39 | if (nbytes >= sizeof(struct ConfigDev)) |
| 40 | nbytes = sizeof(struct ConfigDev); |
| 41 | if (pos + nbytes > sizeof(struct ConfigDev)) |
| 42 | nbytes = sizeof(struct ConfigDev) - pos; |
| 43 | |
| 44 | /* Construct a ConfigDev */ |
| 45 | memset(&cd, 0, sizeof(cd)); |
| 46 | cd.cd_Rom = z->rom; |
Geert Uytterhoeven | bd9ba8f | 2013-10-04 09:38:53 +0200 | [diff] [blame] | 47 | cd.cd_SlotAddr = cpu_to_be16(z->slotaddr); |
| 48 | cd.cd_SlotSize = cpu_to_be16(z->slotsize); |
| 49 | cd.cd_BoardAddr = cpu_to_be32(zorro_resource_start(z)); |
| 50 | cd.cd_BoardSize = cpu_to_be32(zorro_resource_len(z)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
Geert Uytterhoeven | 2190a1e | 2010-06-09 11:24:32 +0200 | [diff] [blame] | 52 | if (copy_to_user(buf, (void *)&cd + pos, nbytes)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | return -EFAULT; |
| 54 | *ppos += nbytes; |
| 55 | |
| 56 | return nbytes; |
| 57 | } |
| 58 | |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 59 | static const struct file_operations proc_bus_zorro_operations = { |
Denis V. Lunev | 659f865 | 2008-04-29 01:02:16 -0700 | [diff] [blame] | 60 | .owner = THIS_MODULE, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | .llseek = proc_bus_zorro_lseek, |
| 62 | .read = proc_bus_zorro_read, |
| 63 | }; |
| 64 | |
Alexey Dobriyan | 8331438 | 2008-04-29 01:01:45 -0700 | [diff] [blame] | 65 | static void * zorro_seq_start(struct seq_file *m, loff_t *pos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | { |
Alexey Dobriyan | 8331438 | 2008-04-29 01:01:45 -0700 | [diff] [blame] | 67 | return (*pos < zorro_num_autocon) ? pos : NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | } |
| 69 | |
Alexey Dobriyan | 8331438 | 2008-04-29 01:01:45 -0700 | [diff] [blame] | 70 | static void * zorro_seq_next(struct seq_file *m, void *v, loff_t *pos) |
| 71 | { |
| 72 | (*pos)++; |
| 73 | return (*pos < zorro_num_autocon) ? pos : NULL; |
| 74 | } |
| 75 | |
| 76 | static void zorro_seq_stop(struct seq_file *m, void *v) |
| 77 | { |
| 78 | } |
| 79 | |
| 80 | static int zorro_seq_show(struct seq_file *m, void *v) |
| 81 | { |
Geert Uytterhoeven | 0d30546 | 2009-04-05 12:40:41 +0200 | [diff] [blame] | 82 | unsigned int slot = *(loff_t *)v; |
Alexey Dobriyan | 8331438 | 2008-04-29 01:01:45 -0700 | [diff] [blame] | 83 | struct zorro_dev *z = &zorro_autocon[slot]; |
| 84 | |
| 85 | seq_printf(m, "%02x\t%08x\t%08lx\t%08lx\t%02x\n", slot, z->id, |
| 86 | (unsigned long)zorro_resource_start(z), |
| 87 | (unsigned long)zorro_resource_len(z), |
| 88 | z->rom.er_Type); |
| 89 | return 0; |
| 90 | } |
| 91 | |
| 92 | static const struct seq_operations zorro_devices_seq_ops = { |
| 93 | .start = zorro_seq_start, |
| 94 | .next = zorro_seq_next, |
| 95 | .stop = zorro_seq_stop, |
| 96 | .show = zorro_seq_show, |
| 97 | }; |
| 98 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | static struct proc_dir_entry *proc_bus_zorro_dir; |
| 100 | |
Geert Uytterhoeven | 0d30546 | 2009-04-05 12:40:41 +0200 | [diff] [blame] | 101 | static int __init zorro_proc_attach_device(unsigned int slot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | { |
| 103 | struct proc_dir_entry *entry; |
| 104 | char name[4]; |
| 105 | |
| 106 | sprintf(name, "%02x", slot); |
Denis V. Lunev | 659f865 | 2008-04-29 01:02:16 -0700 | [diff] [blame] | 107 | entry = proc_create_data(name, 0, proc_bus_zorro_dir, |
| 108 | &proc_bus_zorro_operations, |
| 109 | &zorro_autocon[slot]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | if (!entry) |
| 111 | return -ENOMEM; |
David Howells | 271a15e | 2013-04-12 00:38:51 +0100 | [diff] [blame] | 112 | proc_set_size(entry, sizeof(struct zorro_dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | return 0; |
| 114 | } |
| 115 | |
| 116 | static int __init zorro_proc_init(void) |
| 117 | { |
Geert Uytterhoeven | 0d30546 | 2009-04-05 12:40:41 +0200 | [diff] [blame] | 118 | unsigned int slot; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
| 120 | if (MACH_IS_AMIGA && AMIGAHW_PRESENT(ZORRO)) { |
Alexey Dobriyan | 9c37066 | 2008-04-29 01:01:41 -0700 | [diff] [blame] | 121 | proc_bus_zorro_dir = proc_mkdir("bus/zorro", NULL); |
Christoph Hellwig | fddda2b | 2018-04-13 19:44:18 +0200 | [diff] [blame] | 122 | proc_create_seq("devices", 0, proc_bus_zorro_dir, |
| 123 | &zorro_devices_seq_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | for (slot = 0; slot < zorro_num_autocon; slot++) |
| 125 | zorro_proc_attach_device(slot); |
| 126 | } |
| 127 | return 0; |
| 128 | } |
| 129 | |
Robert P. J. Day | a6a26a3 | 2008-07-17 21:16:16 +0200 | [diff] [blame] | 130 | device_initcall(zorro_proc_init); |