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