^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) /* drivers/nubus/proc.c: Proc FS interface for NuBus.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) By David Huggins-Daines <dhd@debian.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) Much code and many ideas from drivers/pci/proc.c:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) Copyright (c) 1997, 1998 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) This is initially based on the Zorro and PCI interfaces. However,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) it works somewhat differently. The intent is to provide a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) structure in /proc analogous to the structure of the NuBus ROM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) resources.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) Therefore each board function gets a directory, which may in turn
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) contain subdirectories. Each slot resource is a file. Unrecognized
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) resources are empty files, since every resource ID requires a special
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) case (e.g. if the resource ID implies a directory or block, then its
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) value has to be interpreted as a slot ROM pointer etc.).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/nubus.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <asm/byteorder.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * /proc/bus/nubus/devices stuff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) nubus_devices_proc_show(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) struct nubus_rsrc *fres;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) for_each_func_rsrc(fres)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) seq_printf(m, "%x\t%04x %04x %04x %04x\t%08lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) fres->board->slot, fres->category, fres->type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) fres->dr_sw, fres->dr_hw, fres->board->slot_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) static struct proc_dir_entry *proc_bus_nubus_dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * /proc/bus/nubus/x/ stuff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) struct proc_dir_entry *nubus_proc_add_board(struct nubus_board *board)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) char name[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) if (!proc_bus_nubus_dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) snprintf(name, sizeof(name), "%x", board->slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) return proc_mkdir(name, proc_bus_nubus_dir);
^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) /* The PDE private data for any directory under /proc/bus/nubus/x/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * is the bytelanes value for the board in slot x.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) struct proc_dir_entry *nubus_proc_add_rsrc_dir(struct proc_dir_entry *procdir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) const struct nubus_dirent *ent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) struct nubus_board *board)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) char name[9];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) int lanes = board->lanes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) if (!procdir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) snprintf(name, sizeof(name), "%x", ent->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) return proc_mkdir_data(name, 0555, procdir, (void *)lanes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) /* The PDE private data for a file under /proc/bus/nubus/x/ is a pointer to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) * an instance of the following structure, which gives the location and size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * of the resource data in the slot ROM. For slot resources which hold only a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * small integer, this integer value is stored directly and size is set to 0.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * A NULL private data pointer indicates an unrecognized resource.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) struct nubus_proc_pde_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) unsigned char *res_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) unsigned int res_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) static struct nubus_proc_pde_data *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) nubus_proc_alloc_pde_data(unsigned char *ptr, unsigned int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) struct nubus_proc_pde_data *pde_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) pde_data = kmalloc(sizeof(*pde_data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) if (!pde_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) pde_data->res_ptr = ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) pde_data->res_size = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) return pde_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) static int nubus_proc_rsrc_show(struct seq_file *m, void *v)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) struct inode *inode = m->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) struct nubus_proc_pde_data *pde_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) pde_data = PDE_DATA(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) if (!pde_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) if (pde_data->res_size > m->size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) return -EFBIG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) if (pde_data->res_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) int lanes = (int)proc_get_parent_data(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) struct nubus_dirent ent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) if (!lanes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) ent.mask = lanes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) ent.base = pde_data->res_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) ent.data = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) nubus_seq_write_rsrc_mem(m, &ent, pde_data->res_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) unsigned int data = (unsigned int)pde_data->res_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) seq_putc(m, data >> 16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) seq_putc(m, data >> 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) seq_putc(m, data >> 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) void nubus_proc_add_rsrc_mem(struct proc_dir_entry *procdir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) const struct nubus_dirent *ent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) unsigned int size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) char name[9];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) struct nubus_proc_pde_data *pde_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) if (!procdir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) snprintf(name, sizeof(name), "%x", ent->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) if (size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) pde_data = nubus_proc_alloc_pde_data(nubus_dirptr(ent), size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) pde_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) proc_create_single_data(name, S_IFREG | 0444, procdir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) nubus_proc_rsrc_show, pde_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) void nubus_proc_add_rsrc(struct proc_dir_entry *procdir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) const struct nubus_dirent *ent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) char name[9];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) unsigned char *data = (unsigned char *)ent->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) if (!procdir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) snprintf(name, sizeof(name), "%x", ent->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) proc_create_single_data(name, S_IFREG | 0444, procdir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) nubus_proc_rsrc_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) nubus_proc_alloc_pde_data(data, 0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) * /proc/nubus stuff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) void __init nubus_proc_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) proc_create_single("nubus", 0, NULL, nubus_proc_show);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) proc_bus_nubus_dir = proc_mkdir("bus/nubus", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) if (!proc_bus_nubus_dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) proc_create_single("devices", 0, proc_bus_nubus_dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) nubus_devices_proc_show);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) }