1 // SPDX-License-Identifier: GPL-2.0
2 /* drivers/nubus/proc.c: Proc FS interface for NuBus.
4 By David Huggins-Daines <dhd@debian.org>
6 Much code and many ideas from drivers/pci/proc.c:
7 Copyright (c) 1997, 1998 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
9 This is initially based on the Zorro and PCI interfaces. However,
10 it works somewhat differently. The intent is to provide a
11 structure in /proc analogous to the structure of the NuBus ROM
14 Therefore each NuBus device is in fact a directory, which may in
15 turn contain subdirectories. The "files" correspond to NuBus
16 resource records. For those types of records which we know how to
17 convert to formats that are meaningful to userspace (mostly just
18 icons) these files will provide "cooked" data. Otherwise they will
19 simply provide raw access (read-only of course) to the ROM. */
21 #include <linux/types.h>
22 #include <linux/kernel.h>
23 #include <linux/nubus.h>
24 #include <linux/proc_fs.h>
25 #include <linux/seq_file.h>
26 #include <linux/init.h>
27 #include <linux/module.h>
29 #include <linux/uaccess.h>
30 #include <asm/byteorder.h>
33 nubus_devices_proc_show(struct seq_file
*m
, void *v
)
35 struct nubus_dev
*dev
= nubus_devices
;
38 seq_printf(m
, "%x\t%04x %04x %04x %04x",
44 seq_printf(m
, "\t%08lx\n", dev
->board
->slot_addr
);
50 static int nubus_devices_proc_open(struct inode
*inode
, struct file
*file
)
52 return single_open(file
, nubus_devices_proc_show
, NULL
);
55 static const struct file_operations nubus_devices_proc_fops
= {
56 .open
= nubus_devices_proc_open
,
59 .release
= single_release
,
62 static struct proc_dir_entry
*proc_bus_nubus_dir
;
64 static const struct file_operations nubus_proc_subdir_fops
= {
65 #warning Need to set some I/O handlers here
68 static void nubus_proc_subdir(struct nubus_dev
* dev
,
69 struct proc_dir_entry
* parent
,
70 struct nubus_dir
* dir
)
72 struct nubus_dirent ent
;
74 /* Some of these are directories, others aren't */
75 while (nubus_readdir(dir
, &ent
) != -1) {
77 struct proc_dir_entry
* e
;
79 sprintf(name
, "%x", ent
.type
);
80 e
= proc_create(name
, S_IFREG
| S_IRUGO
| S_IWUSR
, parent
,
81 &nubus_proc_subdir_fops
);
87 /* Can't do this recursively since the root directory is structured
88 somewhat differently from the subdirectories */
89 static void nubus_proc_populate(struct nubus_dev
* dev
,
90 struct proc_dir_entry
* parent
,
91 struct nubus_dir
* root
)
93 struct nubus_dirent ent
;
95 /* We know these are all directories (board resource + one or
96 more functional resources) */
97 while (nubus_readdir(root
, &ent
) != -1) {
99 struct proc_dir_entry
* e
;
100 struct nubus_dir dir
;
102 sprintf(name
, "%x", ent
.type
);
103 e
= proc_mkdir(name
, parent
);
107 if (nubus_get_subdir(&ent
, &dir
) == -1) {
108 /* This shouldn't happen */
109 printk(KERN_ERR
"NuBus root directory node %x:%x has no subdir!\n",
110 dev
->board
->slot
, ent
.type
);
113 nubus_proc_subdir(dev
, e
, &dir
);
118 int nubus_proc_attach_device(struct nubus_dev
*dev
)
120 struct proc_dir_entry
*e
;
121 struct nubus_dir root
;
126 "NULL pointer in nubus_proc_attach_device, shoot the programmer!\n");
130 if (dev
->board
== NULL
) {
132 "NULL pointer in nubus_proc_attach_device, shoot the programmer!\n");
133 printk("dev = %p, dev->board = %p\n", dev
, dev
->board
);
137 /* Create a directory */
138 sprintf(name
, "%x", dev
->board
->slot
);
139 e
= dev
->procdir
= proc_mkdir(name
, proc_bus_nubus_dir
);
143 /* Now recursively populate it with files */
144 nubus_get_root_dir(dev
->board
, &root
);
145 nubus_proc_populate(dev
, e
, &root
);
149 EXPORT_SYMBOL(nubus_proc_attach_device
);
154 static int nubus_proc_show(struct seq_file
*m
, void *v
)
156 const struct nubus_board
*board
= v
;
158 /* Display header on line 1 */
159 if (v
== SEQ_START_TOKEN
)
160 seq_puts(m
, "Nubus devices found:\n");
162 seq_printf(m
, "Slot %X: %s\n", board
->slot
, board
->name
);
166 static void *nubus_proc_start(struct seq_file
*m
, loff_t
*_pos
)
168 struct nubus_board
*board
;
171 if (*_pos
> LONG_MAX
)
175 return SEQ_START_TOKEN
;
176 for (board
= nubus_boards
; board
; board
= board
->next
)
182 static void *nubus_proc_next(struct seq_file
*p
, void *v
, loff_t
*_pos
)
184 /* Walk the list of NuBus boards */
185 struct nubus_board
*board
= v
;
188 if (v
== SEQ_START_TOKEN
)
189 board
= nubus_boards
;
195 static void nubus_proc_stop(struct seq_file
*p
, void *v
)
199 static const struct seq_operations nubus_proc_seqops
= {
200 .start
= nubus_proc_start
,
201 .next
= nubus_proc_next
,
202 .stop
= nubus_proc_stop
,
203 .show
= nubus_proc_show
,
206 static int nubus_proc_open(struct inode
*inode
, struct file
*file
)
208 return seq_open(file
, &nubus_proc_seqops
);
211 static const struct file_operations nubus_proc_fops
= {
212 .open
= nubus_proc_open
,
215 .release
= seq_release
,
218 void __init
proc_bus_nubus_add_devices(void)
220 struct nubus_dev
*dev
;
222 for(dev
= nubus_devices
; dev
; dev
= dev
->next
)
223 nubus_proc_attach_device(dev
);
226 void __init
nubus_proc_init(void)
228 proc_create("nubus", 0, NULL
, &nubus_proc_fops
);
231 proc_bus_nubus_dir
= proc_mkdir("bus/nubus", NULL
);
232 proc_create("devices", 0, proc_bus_nubus_dir
, &nubus_devices_proc_fops
);
233 proc_bus_nubus_add_devices();