Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *	Procfs interface for the Zorro bus.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *	Copyright (C) 1998-2003 Geert Uytterhoeven
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *	Heavily based on the procfs interface for the PCI bus, which is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *	Copyright (C) 1997, 1998 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/zorro.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <asm/byteorder.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <asm/amigahw.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <asm/setup.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) static loff_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) proc_bus_zorro_lseek(struct file *file, loff_t off, int whence)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	return fixed_size_llseek(file, off, whence, sizeof(struct ConfigDev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) static ssize_t
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) proc_bus_zorro_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	struct zorro_dev *z = PDE_DATA(file_inode(file));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	struct ConfigDev cd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	loff_t pos = *ppos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	if (pos >= sizeof(struct ConfigDev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	if (nbytes >= sizeof(struct ConfigDev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		nbytes = sizeof(struct ConfigDev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	if (pos + nbytes > sizeof(struct ConfigDev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		nbytes = sizeof(struct ConfigDev) - pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	/* Construct a ConfigDev */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	memset(&cd, 0, sizeof(cd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	cd.cd_Rom = z->rom;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	cd.cd_SlotAddr = cpu_to_be16(z->slotaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	cd.cd_SlotSize = cpu_to_be16(z->slotsize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	cd.cd_BoardAddr = cpu_to_be32(zorro_resource_start(z));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	cd.cd_BoardSize = cpu_to_be32(zorro_resource_len(z));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	if (copy_to_user(buf, (void *)&cd + pos, nbytes))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	*ppos += nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	return nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) static const struct proc_ops bus_zorro_proc_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	.proc_lseek	= proc_bus_zorro_lseek,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	.proc_read	= proc_bus_zorro_read,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) static void * zorro_seq_start(struct seq_file *m, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	return (*pos < zorro_num_autocon) ? pos : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) static void * zorro_seq_next(struct seq_file *m, void *v, loff_t *pos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	(*pos)++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	return (*pos < zorro_num_autocon) ? pos : NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) static void zorro_seq_stop(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) static int zorro_seq_show(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	unsigned int slot = *(loff_t *)v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	struct zorro_dev *z = &zorro_autocon[slot];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	seq_printf(m, "%02x\t%08x\t%08lx\t%08lx\t%02x\n", slot, z->id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		   (unsigned long)zorro_resource_start(z),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		   (unsigned long)zorro_resource_len(z),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		   z->rom.er_Type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) static const struct seq_operations zorro_devices_seq_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	.start = zorro_seq_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	.next  = zorro_seq_next,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	.stop  = zorro_seq_stop,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	.show  = zorro_seq_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) static struct proc_dir_entry *proc_bus_zorro_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) static int __init zorro_proc_attach_device(unsigned int slot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	struct proc_dir_entry *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	char name[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	sprintf(name, "%02x", slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	entry = proc_create_data(name, 0, proc_bus_zorro_dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 				 &bus_zorro_proc_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 				 &zorro_autocon[slot]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	if (!entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	proc_set_size(entry, sizeof(struct zorro_dev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) static int __init zorro_proc_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	unsigned int slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	if (MACH_IS_AMIGA && AMIGAHW_PRESENT(ZORRO)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		proc_bus_zorro_dir = proc_mkdir("bus/zorro", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 		proc_create_seq("devices", 0, proc_bus_zorro_dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 			    &zorro_devices_seq_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		for (slot = 0; slot < zorro_num_autocon; slot++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 			zorro_proc_attach_device(slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) device_initcall(zorro_proc_init);