blob: 1c9ae08225d8d818ab6550adc4346032bb5fa893 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * 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 Dobriyan83314382008-04-29 01:01:45 -070015#include <linux/seq_file.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/init.h>
Paul Gortmaker8aaf7a02011-08-01 10:58:14 -040017#include <linux/export.h>
Geert Uytterhoevenbd9ba8f2013-10-04 09:38:53 +020018
19#include <asm/byteorder.h>
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080020#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <asm/amigahw.h>
22#include <asm/setup.h>
23
24static loff_t
25proc_bus_zorro_lseek(struct file *file, loff_t off, int whence)
26{
Al Viro3be1f2b2013-06-22 12:10:22 +040027 return fixed_size_llseek(file, off, whence, sizeof(struct ConfigDev));
Linus Torvalds1da177e2005-04-16 15:20:36 -070028}
29
30static ssize_t
Al Virod9982652006-01-12 01:06:32 -080031proc_bus_zorro_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -070032{
Al Virod9dda782013-03-31 18:16:14 -040033 struct zorro_dev *z = PDE_DATA(file_inode(file));
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 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 Uytterhoevenbd9ba8f2013-10-04 09:38:53 +020047 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 Torvalds1da177e2005-04-16 15:20:36 -070051
Geert Uytterhoeven2190a1e2010-06-09 11:24:32 +020052 if (copy_to_user(buf, (void *)&cd + pos, nbytes))
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 return -EFAULT;
54 *ppos += nbytes;
55
56 return nbytes;
57}
58
Alexey Dobriyan97a32532020-02-03 17:37:17 -080059static const struct proc_ops bus_zorro_proc_ops = {
60 .proc_lseek = proc_bus_zorro_lseek,
61 .proc_read = proc_bus_zorro_read,
Linus Torvalds1da177e2005-04-16 15:20:36 -070062};
63
Alexey Dobriyan83314382008-04-29 01:01:45 -070064static void * zorro_seq_start(struct seq_file *m, loff_t *pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -070065{
Alexey Dobriyan83314382008-04-29 01:01:45 -070066 return (*pos < zorro_num_autocon) ? pos : NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067}
68
Alexey Dobriyan83314382008-04-29 01:01:45 -070069static void * zorro_seq_next(struct seq_file *m, void *v, loff_t *pos)
70{
71 (*pos)++;
72 return (*pos < zorro_num_autocon) ? pos : NULL;
73}
74
75static void zorro_seq_stop(struct seq_file *m, void *v)
76{
77}
78
79static int zorro_seq_show(struct seq_file *m, void *v)
80{
Geert Uytterhoeven0d305462009-04-05 12:40:41 +020081 unsigned int slot = *(loff_t *)v;
Alexey Dobriyan83314382008-04-29 01:01:45 -070082 struct zorro_dev *z = &zorro_autocon[slot];
83
84 seq_printf(m, "%02x\t%08x\t%08lx\t%08lx\t%02x\n", slot, z->id,
85 (unsigned long)zorro_resource_start(z),
86 (unsigned long)zorro_resource_len(z),
87 z->rom.er_Type);
88 return 0;
89}
90
91static const struct seq_operations zorro_devices_seq_ops = {
92 .start = zorro_seq_start,
93 .next = zorro_seq_next,
94 .stop = zorro_seq_stop,
95 .show = zorro_seq_show,
96};
97
Linus Torvalds1da177e2005-04-16 15:20:36 -070098static struct proc_dir_entry *proc_bus_zorro_dir;
99
Geert Uytterhoeven0d305462009-04-05 12:40:41 +0200100static int __init zorro_proc_attach_device(unsigned int slot)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101{
102 struct proc_dir_entry *entry;
103 char name[4];
104
105 sprintf(name, "%02x", slot);
Denis V. Lunev659f8652008-04-29 01:02:16 -0700106 entry = proc_create_data(name, 0, proc_bus_zorro_dir,
Alexey Dobriyan97a32532020-02-03 17:37:17 -0800107 &bus_zorro_proc_ops,
Denis V. Lunev659f8652008-04-29 01:02:16 -0700108 &zorro_autocon[slot]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 if (!entry)
110 return -ENOMEM;
David Howells271a15e2013-04-12 00:38:51 +0100111 proc_set_size(entry, sizeof(struct zorro_dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 return 0;
113}
114
115static int __init zorro_proc_init(void)
116{
Geert Uytterhoeven0d305462009-04-05 12:40:41 +0200117 unsigned int slot;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
119 if (MACH_IS_AMIGA && AMIGAHW_PRESENT(ZORRO)) {
Alexey Dobriyan9c370662008-04-29 01:01:41 -0700120 proc_bus_zorro_dir = proc_mkdir("bus/zorro", NULL);
Christoph Hellwigfddda2b2018-04-13 19:44:18 +0200121 proc_create_seq("devices", 0, proc_bus_zorro_dir,
122 &zorro_devices_seq_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 for (slot = 0; slot < zorro_num_autocon; slot++)
124 zorro_proc_attach_device(slot);
125 }
126 return 0;
127}
128
Robert P. J. Daya6a26a32008-07-17 21:16:16 +0200129device_initcall(zorro_proc_init);