1 /* drivers/nubus/proc.c: Proc FS interface for NuBus.
3 By David Huggins-Daines <dhd@debian.org>
5 Much code and many ideas from drivers/pci/proc.c:
6 Copyright (c) 1997, 1998 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
8 This is initially based on the Zorro and PCI interfaces. However,
9 it works somewhat differently. The intent is to provide a
10 structure in /proc analogous to the structure of the NuBus ROM
13 Therefore each NuBus device is in fact a directory, which may in
14 turn contain subdirectories. The "files" correspond to NuBus
15 resource records. For those types of records which we know how to
16 convert to formats that are meaningful to userspace (mostly just
17 icons) these files will provide "cooked" data. Otherwise they will
18 simply provide raw access (read-only of course) to the ROM. */
20 #include <linux/types.h>
21 #include <linux/kernel.h>
22 #include <linux/nubus.h>
23 #include <linux/proc_fs.h>
24 #include <linux/seq_file.h>
25 #include <linux/init.h>
26 #include <linux/module.h>
28 #include <asm/uaccess.h>
29 #include <asm/byteorder.h>
32 nubus_devices_proc_show(struct seq_file *m, void *v)
34 struct nubus_dev *dev = nubus_devices;
37 seq_printf(m, "%x\t%04x %04x %04x %04x",
43 seq_printf(m, "\t%08lx\n", dev->board->slot_addr);
49 static int nubus_devices_proc_open(struct inode *inode, struct file *file)
51 return single_open(file, nubus_devices_proc_show, NULL);
54 static const struct file_operations nubus_devices_proc_fops = {
55 .open = nubus_devices_proc_open,
58 .release = single_release,
61 static struct proc_dir_entry *proc_bus_nubus_dir;
63 static const struct file_operations nubus_proc_subdir_fops = {
64 #warning Need to set some I/O handlers here
67 static void nubus_proc_subdir(struct nubus_dev* dev,
68 struct proc_dir_entry* parent,
69 struct nubus_dir* dir)
71 struct nubus_dirent ent;
73 /* Some of these are directories, others aren't */
74 while (nubus_readdir(dir, &ent) != -1) {
76 struct proc_dir_entry* e;
78 sprintf(name, "%x", ent.type);
79 e = proc_create(name, S_IFREG | S_IRUGO | S_IWUSR, parent,
80 &nubus_proc_subdir_fops);
86 /* Can't do this recursively since the root directory is structured
87 somewhat differently from the subdirectories */
88 static void nubus_proc_populate(struct nubus_dev* dev,
89 struct proc_dir_entry* parent,
90 struct nubus_dir* root)
92 struct nubus_dirent ent;
94 /* We know these are all directories (board resource + one or
95 more functional resources) */
96 while (nubus_readdir(root, &ent) != -1) {
98 struct proc_dir_entry* e;
101 sprintf(name, "%x", ent.type);
102 e = proc_mkdir(name, parent);
106 if (nubus_get_subdir(&ent, &dir) == -1) {
107 /* This shouldn't happen */
108 printk(KERN_ERR "NuBus root directory node %x:%x has no subdir!\n",
109 dev->board->slot, ent.type);
112 nubus_proc_subdir(dev, e, &dir);
117 int nubus_proc_attach_device(struct nubus_dev *dev)
119 struct proc_dir_entry *e;
120 struct nubus_dir root;
125 "NULL pointer in nubus_proc_attach_device, shoot the programmer!\n");
129 if (dev->board == NULL) {
131 "NULL pointer in nubus_proc_attach_device, shoot the programmer!\n");
132 printk("dev = %p, dev->board = %p\n", dev, dev->board);
136 /* Create a directory */
137 sprintf(name, "%x", dev->board->slot);
138 e = dev->procdir = proc_mkdir(name, proc_bus_nubus_dir);
142 /* Now recursively populate it with files */
143 nubus_get_root_dir(dev->board, &root);
144 nubus_proc_populate(dev, e, &root);
148 EXPORT_SYMBOL(nubus_proc_attach_device);
150 /* FIXME: this is certainly broken! */
151 int nubus_proc_detach_device(struct nubus_dev *dev)
153 struct proc_dir_entry *e;
155 if ((e = dev->procdir)) {
156 if (atomic_read(&e->count))
158 remove_proc_entry(e->name, proc_bus_nubus_dir);
163 EXPORT_SYMBOL(nubus_proc_detach_device);
168 static int nubus_proc_show(struct seq_file *m, void *v)
170 const struct nubus_board *board = v;
172 /* Display header on line 1 */
173 if (v == SEQ_START_TOKEN)
174 seq_puts(m, "Nubus devices found:\n");
176 seq_printf(m, "Slot %X: %s\n", board->slot, board->name);
180 static void *nubus_proc_start(struct seq_file *m, loff_t *_pos)
182 struct nubus_board *board;
185 if (*_pos > LONG_MAX)
189 return SEQ_START_TOKEN;
190 for (board = nubus_boards; board; board = board->next)
196 static void *nubus_proc_next(struct seq_file *p, void *v, loff_t *_pos)
198 /* Walk the list of NuBus boards */
199 struct nubus_board *board = v;
202 if (v == SEQ_START_TOKEN)
203 board = nubus_boards;
209 static void nubus_proc_stop(struct seq_file *p, void *v)
213 static const struct seq_operations nubus_proc_seqops = {
214 .start = nubus_proc_start,
215 .next = nubus_proc_next,
216 .stop = nubus_proc_stop,
217 .show = nubus_proc_show,
220 static int nubus_proc_open(struct inode *inode, struct file *file)
222 return seq_open(file, &nubus_proc_seqops);
225 static const struct file_operations nubus_proc_fops = {
226 .open = nubus_proc_open,
229 .release = seq_release,
232 void __init proc_bus_nubus_add_devices(void)
234 struct nubus_dev *dev;
236 for(dev = nubus_devices; dev; dev = dev->next)
237 nubus_proc_attach_device(dev);
240 void __init nubus_proc_init(void)
242 proc_create("nubus", 0, NULL, &nubus_proc_fops);
245 proc_bus_nubus_dir = proc_mkdir("bus/nubus", NULL);
246 proc_create("devices", 0, proc_bus_nubus_dir, &nubus_devices_proc_fops);
247 proc_bus_nubus_add_devices();