iwlwifi: introduce host commands callbacks
[linux/fpc-iii.git] / drivers / nubus / proc.c
blobe07492be1f4ac36a418896f77f45a4a25fffdaa7
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
11 resources.
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/init.h>
25 #include <linux/module.h>
27 #include <asm/uaccess.h>
28 #include <asm/byteorder.h>
30 static int
31 get_nubus_dev_info(char *buf, char **start, off_t pos, int count)
33 struct nubus_dev *dev = nubus_devices;
34 off_t at = 0;
35 int len, cnt;
37 cnt = 0;
38 while (dev && count > cnt) {
39 len = sprintf(buf, "%x\t%04x %04x %04x %04x",
40 dev->board->slot,
41 dev->category,
42 dev->type,
43 dev->dr_sw,
44 dev->dr_hw);
45 len += sprintf(buf+len,
46 "\t%08lx",
47 dev->board->slot_addr);
48 buf[len++] = '\n';
49 at += len;
50 if (at >= pos) {
51 if (!*start) {
52 *start = buf + (pos - (at - len));
53 cnt = at - pos;
54 } else
55 cnt += len;
56 buf += len;
58 dev = dev->next;
60 return (count > cnt) ? cnt : count;
63 static struct proc_dir_entry *proc_bus_nubus_dir;
65 static void nubus_proc_subdir(struct nubus_dev* dev,
66 struct proc_dir_entry* parent,
67 struct nubus_dir* dir)
69 struct nubus_dirent ent;
71 /* Some of these are directories, others aren't */
72 while (nubus_readdir(dir, &ent) != -1) {
73 char name[8];
74 struct proc_dir_entry* e;
76 sprintf(name, "%x", ent.type);
77 e = create_proc_entry(name, S_IFREG | S_IRUGO |
78 S_IWUSR, parent);
79 if (!e) return;
83 /* Can't do this recursively since the root directory is structured
84 somewhat differently from the subdirectories */
85 static void nubus_proc_populate(struct nubus_dev* dev,
86 struct proc_dir_entry* parent,
87 struct nubus_dir* root)
89 struct nubus_dirent ent;
91 /* We know these are all directories (board resource + one or
92 more functional resources) */
93 while (nubus_readdir(root, &ent) != -1) {
94 char name[8];
95 struct proc_dir_entry* e;
96 struct nubus_dir dir;
98 sprintf(name, "%x", ent.type);
99 e = proc_mkdir(name, parent);
100 if (!e) return;
102 /* And descend */
103 if (nubus_get_subdir(&ent, &dir) == -1) {
104 /* This shouldn't happen */
105 printk(KERN_ERR "NuBus root directory node %x:%x has no subdir!\n",
106 dev->board->slot, ent.type);
107 continue;
108 } else {
109 nubus_proc_subdir(dev, e, &dir);
114 int nubus_proc_attach_device(struct nubus_dev *dev)
116 struct proc_dir_entry *e;
117 struct nubus_dir root;
118 char name[8];
120 if (dev == NULL) {
121 printk(KERN_ERR
122 "NULL pointer in nubus_proc_attach_device, shoot the programmer!\n");
123 return -1;
126 if (dev->board == NULL) {
127 printk(KERN_ERR
128 "NULL pointer in nubus_proc_attach_device, shoot the programmer!\n");
129 printk("dev = %p, dev->board = %p\n", dev, dev->board);
130 return -1;
133 /* Create a directory */
134 sprintf(name, "%x", dev->board->slot);
135 e = dev->procdir = proc_mkdir(name, proc_bus_nubus_dir);
136 if (!e)
137 return -ENOMEM;
139 /* Now recursively populate it with files */
140 nubus_get_root_dir(dev->board, &root);
141 nubus_proc_populate(dev, e, &root);
143 return 0;
145 EXPORT_SYMBOL(nubus_proc_attach_device);
147 /* FIXME: this is certainly broken! */
148 int nubus_proc_detach_device(struct nubus_dev *dev)
150 struct proc_dir_entry *e;
152 if ((e = dev->procdir)) {
153 if (atomic_read(&e->count))
154 return -EBUSY;
155 remove_proc_entry(e->name, proc_bus_nubus_dir);
156 dev->procdir = NULL;
158 return 0;
160 EXPORT_SYMBOL(nubus_proc_detach_device);
162 void __init proc_bus_nubus_add_devices(void)
164 struct nubus_dev *dev;
166 for(dev = nubus_devices; dev; dev = dev->next)
167 nubus_proc_attach_device(dev);
170 void __init nubus_proc_init(void)
172 if (!MACH_IS_MAC)
173 return;
174 proc_bus_nubus_dir = proc_mkdir("nubus", proc_bus);
175 create_proc_info_entry("devices", 0, proc_bus_nubus_dir,
176 get_nubus_dev_info);
177 proc_bus_nubus_add_devices();