Linux Audio

Check our new training course

Loading...
v6.8
  1// SPDX-License-Identifier: GPL-2.0
  2/*
  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>
 15#include <linux/seq_file.h>
 16#include <linux/init.h>
 17#include <linux/export.h>
 18
 19#include <asm/byteorder.h>
 20#include <linux/uaccess.h>
 21#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{
 27	return fixed_size_llseek(file, off, whence, sizeof(struct ConfigDev));
 28}
 29
 30static ssize_t
 31proc_bus_zorro_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
 32{
 33	struct zorro_dev *z = pde_data(file_inode(file));
 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;
 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));
 51
 52	if (copy_to_user(buf, (void *)&cd + pos, nbytes))
 53		return -EFAULT;
 54	*ppos += nbytes;
 55
 56	return nbytes;
 57}
 58
 59static const struct proc_ops bus_zorro_proc_ops = {
 60	.proc_lseek	= proc_bus_zorro_lseek,
 61	.proc_read	= proc_bus_zorro_read,
 
 62};
 63
 64static void * zorro_seq_start(struct seq_file *m, loff_t *pos)
 65{
 66	return (*pos < zorro_num_autocon) ? pos : NULL;
 67}
 68
 69static 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{
 81	unsigned int slot = *(loff_t *)v;
 82	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
 
 
 
 
 
 
 
 
 
 
 
 
 
 98static struct proc_dir_entry *proc_bus_zorro_dir;
 99
100static int __init zorro_proc_attach_device(unsigned int slot)
101{
102	struct proc_dir_entry *entry;
103	char name[4];
104
105	sprintf(name, "%02x", slot);
106	entry = proc_create_data(name, 0, proc_bus_zorro_dir,
107				 &bus_zorro_proc_ops,
108				 &zorro_autocon[slot]);
109	if (!entry)
110		return -ENOMEM;
111	proc_set_size(entry, sizeof(struct zorro_dev));
112	return 0;
113}
114
115static int __init zorro_proc_init(void)
116{
117	unsigned int slot;
118
119	if (MACH_IS_AMIGA && AMIGAHW_PRESENT(ZORRO)) {
120		proc_bus_zorro_dir = proc_mkdir("bus/zorro", NULL);
121		proc_create_seq("devices", 0, proc_bus_zorro_dir,
122			    &zorro_devices_seq_ops);
123		for (slot = 0; slot < zorro_num_autocon; slot++)
124			zorro_proc_attach_device(slot);
125	}
126	return 0;
127}
128
129device_initcall(zorro_proc_init);
v4.17
  1// SPDX-License-Identifier: GPL-2.0
  2/*
  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>
 15#include <linux/seq_file.h>
 16#include <linux/init.h>
 17#include <linux/export.h>
 18
 19#include <asm/byteorder.h>
 20#include <linux/uaccess.h>
 21#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{
 27	return fixed_size_llseek(file, off, whence, sizeof(struct ConfigDev));
 28}
 29
 30static ssize_t
 31proc_bus_zorro_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
 32{
 33	struct zorro_dev *z = PDE_DATA(file_inode(file));
 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;
 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));
 51
 52	if (copy_to_user(buf, (void *)&cd + pos, nbytes))
 53		return -EFAULT;
 54	*ppos += nbytes;
 55
 56	return nbytes;
 57}
 58
 59static const struct file_operations proc_bus_zorro_operations = {
 60	.owner		= THIS_MODULE,
 61	.llseek		= proc_bus_zorro_lseek,
 62	.read		= proc_bus_zorro_read,
 63};
 64
 65static void * zorro_seq_start(struct seq_file *m, loff_t *pos)
 66{
 67	return (*pos < zorro_num_autocon) ? pos : NULL;
 68}
 69
 70static 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
 76static void zorro_seq_stop(struct seq_file *m, void *v)
 77{
 78}
 79
 80static int zorro_seq_show(struct seq_file *m, void *v)
 81{
 82	unsigned int slot = *(loff_t *)v;
 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
 92static 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
 99static int zorro_devices_proc_open(struct inode *inode, struct file *file)
100{
101	return seq_open(file, &zorro_devices_seq_ops);
102}
103
104static const struct file_operations zorro_devices_proc_fops = {
105	.owner		= THIS_MODULE,
106	.open		= zorro_devices_proc_open,
107	.read		= seq_read,
108	.llseek		= seq_lseek,
109	.release	= seq_release,
110};
111
112static struct proc_dir_entry *proc_bus_zorro_dir;
113
114static int __init zorro_proc_attach_device(unsigned int slot)
115{
116	struct proc_dir_entry *entry;
117	char name[4];
118
119	sprintf(name, "%02x", slot);
120	entry = proc_create_data(name, 0, proc_bus_zorro_dir,
121				 &proc_bus_zorro_operations,
122				 &zorro_autocon[slot]);
123	if (!entry)
124		return -ENOMEM;
125	proc_set_size(entry, sizeof(struct zorro_dev));
126	return 0;
127}
128
129static int __init zorro_proc_init(void)
130{
131	unsigned int slot;
132
133	if (MACH_IS_AMIGA && AMIGAHW_PRESENT(ZORRO)) {
134		proc_bus_zorro_dir = proc_mkdir("bus/zorro", NULL);
135		proc_create("devices", 0, proc_bus_zorro_dir,
136			    &zorro_devices_proc_fops);
137		for (slot = 0; slot < zorro_num_autocon; slot++)
138			zorro_proc_attach_device(slot);
139	}
140	return 0;
141}
142
143device_initcall(zorro_proc_init);