]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - drivers/nubus/proc.c
nubus: Don't use create_proc_entry()
[mirror_ubuntu-zesty-kernel.git] / drivers / nubus / proc.c
CommitLineData
1da177e4
LT
1/* drivers/nubus/proc.c: Proc FS interface for NuBus.
2
3 By David Huggins-Daines <dhd@debian.org>
4
5 Much code and many ideas from drivers/pci/proc.c:
6 Copyright (c) 1997, 1998 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
7
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.
12
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. */
19
20#include <linux/types.h>
21#include <linux/kernel.h>
22#include <linux/nubus.h>
23#include <linux/proc_fs.h>
076ec04b 24#include <linux/seq_file.h>
1da177e4 25#include <linux/init.h>
99ffab81
AB
26#include <linux/module.h>
27
1da177e4
LT
28#include <asm/uaccess.h>
29#include <asm/byteorder.h>
30
31static int
076ec04b 32nubus_devices_proc_show(struct seq_file *m, void *v)
1da177e4
LT
33{
34 struct nubus_dev *dev = nubus_devices;
1da177e4 35
076ec04b
AD
36 while (dev) {
37 seq_printf(m, "%x\t%04x %04x %04x %04x",
1da177e4
LT
38 dev->board->slot,
39 dev->category,
40 dev->type,
41 dev->dr_sw,
42 dev->dr_hw);
076ec04b 43 seq_printf(m, "\t%08lx\n", dev->board->slot_addr);
1da177e4
LT
44 dev = dev->next;
45 }
076ec04b
AD
46 return 0;
47}
48
49static int nubus_devices_proc_open(struct inode *inode, struct file *file)
50{
51 return single_open(file, nubus_devices_proc_show, NULL);
1da177e4
LT
52}
53
076ec04b
AD
54static const struct file_operations nubus_devices_proc_fops = {
55 .owner = THIS_MODULE,
56 .open = nubus_devices_proc_open,
57 .read = seq_read,
58 .llseek = seq_lseek,
59 .release = single_release,
60};
61
1da177e4
LT
62static struct proc_dir_entry *proc_bus_nubus_dir;
63
64static void nubus_proc_subdir(struct nubus_dev* dev,
65 struct proc_dir_entry* parent,
66 struct nubus_dir* dir)
67{
68 struct nubus_dirent ent;
69
70 /* Some of these are directories, others aren't */
71 while (nubus_readdir(dir, &ent) != -1) {
72 char name[8];
73 struct proc_dir_entry* e;
74
75 sprintf(name, "%x", ent.type);
8a25378e
DH
76#warning Need to set some I/O handlers here
77 e = create_proc_read_entry(name, S_IFREG | S_IRUGO | S_IWUSR,
78 parent, NULL, NULL);
1da177e4
LT
79 if (!e) return;
80 }
81}
82
83/* Can't do this recursively since the root directory is structured
84 somewhat differently from the subdirectories */
85static void nubus_proc_populate(struct nubus_dev* dev,
86 struct proc_dir_entry* parent,
87 struct nubus_dir* root)
88{
89 struct nubus_dirent ent;
90
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;
97
98 sprintf(name, "%x", ent.type);
99 e = proc_mkdir(name, parent);
100 if (!e) return;
101
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);
110 }
111 }
112}
113
114int nubus_proc_attach_device(struct nubus_dev *dev)
115{
116 struct proc_dir_entry *e;
117 struct nubus_dir root;
118 char name[8];
119
120 if (dev == NULL) {
121 printk(KERN_ERR
122 "NULL pointer in nubus_proc_attach_device, shoot the programmer!\n");
123 return -1;
124 }
125
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;
131 }
132
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;
138
139 /* Now recursively populate it with files */
140 nubus_get_root_dir(dev->board, &root);
141 nubus_proc_populate(dev, e, &root);
142
143 return 0;
144}
99ffab81 145EXPORT_SYMBOL(nubus_proc_attach_device);
1da177e4
LT
146
147/* FIXME: this is certainly broken! */
148int nubus_proc_detach_device(struct nubus_dev *dev)
149{
150 struct proc_dir_entry *e;
151
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;
157 }
158 return 0;
159}
99ffab81 160EXPORT_SYMBOL(nubus_proc_detach_device);
1da177e4
LT
161
162void __init proc_bus_nubus_add_devices(void)
163{
164 struct nubus_dev *dev;
165
166 for(dev = nubus_devices; dev; dev = dev->next)
167 nubus_proc_attach_device(dev);
168}
169
170void __init nubus_proc_init(void)
171{
172 if (!MACH_IS_MAC)
173 return;
9c37066d 174 proc_bus_nubus_dir = proc_mkdir("bus/nubus", NULL);
076ec04b 175 proc_create("devices", 0, proc_bus_nubus_dir, &nubus_devices_proc_fops);
1da177e4
LT
176 proc_bus_nubus_add_devices();
177}