Blame view

drivers/nubus/proc.c 5.7 KB
b24413180   Greg Kroah-Hartman   License cleanup: ...
1
  // SPDX-License-Identifier: GPL-2.0
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
  /* drivers/nubus/proc.c: Proc FS interface for NuBus.
  
     By David Huggins-Daines <dhd@debian.org>
  
     Much code and many ideas from drivers/pci/proc.c:
     Copyright (c) 1997, 1998 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
  
     This is initially based on the Zorro and PCI interfaces.  However,
     it works somewhat differently.  The intent is to provide a
     structure in /proc analogous to the structure of the NuBus ROM
     resources.
  
     Therefore each NuBus device is in fact a directory, which may in
     turn contain subdirectories.  The "files" correspond to NuBus
     resource records.  For those types of records which we know how to
     convert to formats that are meaningful to userspace (mostly just
     icons) these files will provide "cooked" data.  Otherwise they will
     simply provide raw access (read-only of course) to the ROM.  */
  
  #include <linux/types.h>
  #include <linux/kernel.h>
  #include <linux/nubus.h>
  #include <linux/proc_fs.h>
076ec04b8   Alexey Dobriyan   proc: convert /pr...
25
  #include <linux/seq_file.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
26
  #include <linux/init.h>
99ffab810   Adrian Bunk   nubus: kill drive...
27
  #include <linux/module.h>
7c0f6ba68   Linus Torvalds   Replace <asm/uacc...
28
  #include <linux/uaccess.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
29
30
31
  #include <asm/byteorder.h>
  
  static int
076ec04b8   Alexey Dobriyan   proc: convert /pr...
32
  nubus_devices_proc_show(struct seq_file *m, void *v)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
33
34
  {
  	struct nubus_dev *dev = nubus_devices;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
35

076ec04b8   Alexey Dobriyan   proc: convert /pr...
36
37
  	while (dev) {
  		seq_printf(m, "%x\t%04x %04x %04x %04x",
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
38
39
40
41
42
  			      dev->board->slot,
  			      dev->category,
  			      dev->type,
  			      dev->dr_sw,
  			      dev->dr_hw);
076ec04b8   Alexey Dobriyan   proc: convert /pr...
43
44
  		seq_printf(m, "\t%08lx
  ", dev->board->slot_addr);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
45
46
  		dev = dev->next;
  	}
076ec04b8   Alexey Dobriyan   proc: convert /pr...
47
48
49
50
51
52
  	return 0;
  }
  
  static int nubus_devices_proc_open(struct inode *inode, struct file *file)
  {
  	return single_open(file, nubus_devices_proc_show, NULL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
53
  }
076ec04b8   Alexey Dobriyan   proc: convert /pr...
54
  static const struct file_operations nubus_devices_proc_fops = {
076ec04b8   Alexey Dobriyan   proc: convert /pr...
55
56
57
58
59
  	.open		= nubus_devices_proc_open,
  	.read		= seq_read,
  	.llseek		= seq_lseek,
  	.release	= single_release,
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
60
  static struct proc_dir_entry *proc_bus_nubus_dir;
11db656ad   David Howells   nubus: Don't use ...
61
62
63
  static const struct file_operations nubus_proc_subdir_fops = {
  #warning Need to set some I/O handlers here
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
64
65
66
67
68
69
70
71
72
73
74
75
  static void nubus_proc_subdir(struct nubus_dev* dev,
  			      struct proc_dir_entry* parent,
  			      struct nubus_dir* dir)
  {
  	struct nubus_dirent ent;
  
  	/* Some of these are directories, others aren't */
  	while (nubus_readdir(dir, &ent) != -1) {
  		char name[8];
  		struct proc_dir_entry* e;
  		
  		sprintf(name, "%x", ent.type);
11db656ad   David Howells   nubus: Don't use ...
76
77
78
79
  		e = proc_create(name, S_IFREG | S_IRUGO | S_IWUSR, parent,
  				&nubus_proc_subdir_fops);
  		if (!e)
  			return;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
  	}
  }
  
  /* Can't do this recursively since the root directory is structured
     somewhat differently from the subdirectories */
  static void nubus_proc_populate(struct nubus_dev* dev,
  				struct proc_dir_entry* parent,
  				struct nubus_dir* root)
  {
  	struct nubus_dirent ent;
  
  	/* We know these are all directories (board resource + one or
  	   more functional resources) */
  	while (nubus_readdir(root, &ent) != -1) {
  		char name[8];
  		struct proc_dir_entry* e;
  		struct nubus_dir dir;
  		
  		sprintf(name, "%x", ent.type);
  		e = proc_mkdir(name, parent);
  		if (!e) return;
  
  		/* And descend */
  		if (nubus_get_subdir(&ent, &dir) == -1) {
  			/* This shouldn't happen */
  			printk(KERN_ERR "NuBus root directory node %x:%x has no subdir!
  ",
  			       dev->board->slot, ent.type);
  			continue;
  		} else {
  			nubus_proc_subdir(dev, e, &dir);
  		}
  	}
  }
  
  int nubus_proc_attach_device(struct nubus_dev *dev)
  {
  	struct proc_dir_entry *e;
  	struct nubus_dir root;
  	char name[8];
  
  	if (dev == NULL) {
  		printk(KERN_ERR
  		       "NULL pointer in nubus_proc_attach_device, shoot the programmer!
  ");
  		return -1;
  	}
  		
  	if (dev->board == NULL) {
  		printk(KERN_ERR
  		       "NULL pointer in nubus_proc_attach_device, shoot the programmer!
  ");
  		printk("dev = %p, dev->board = %p
  ", dev, dev->board);
  		return -1;
  	}
  		
  	/* Create a directory */
  	sprintf(name, "%x", dev->board->slot);
  	e = dev->procdir = proc_mkdir(name, proc_bus_nubus_dir);
  	if (!e)
  		return -ENOMEM;
  
  	/* Now recursively populate it with files */
  	nubus_get_root_dir(dev->board, &root);
  	nubus_proc_populate(dev, e, &root);
  
  	return 0;
  }
99ffab810   Adrian Bunk   nubus: kill drive...
149
  EXPORT_SYMBOL(nubus_proc_attach_device);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
150

11db656ad   David Howells   nubus: Don't use ...
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
  /*
   * /proc/nubus stuff
   */
  static int nubus_proc_show(struct seq_file *m, void *v)
  {
  	const struct nubus_board *board = v;
  
  	/* Display header on line 1 */
  	if (v == SEQ_START_TOKEN)
  		seq_puts(m, "Nubus devices found:
  ");
  	else
  		seq_printf(m, "Slot %X: %s
  ", board->slot, board->name);
  	return 0;
  }
  
  static void *nubus_proc_start(struct seq_file *m, loff_t *_pos)
  {
  	struct nubus_board *board;
  	unsigned pos;
  
  	if (*_pos > LONG_MAX)
  		return NULL;
  	pos = *_pos;
  	if (pos == 0)
  		return SEQ_START_TOKEN;
  	for (board = nubus_boards; board; board = board->next)
  		if (--pos == 0)
  			break;
  	return board;
  }
  
  static void *nubus_proc_next(struct seq_file *p, void *v, loff_t *_pos)
  {
  	/* Walk the list of NuBus boards */
  	struct nubus_board *board = v;
  
  	++*_pos;
  	if (v == SEQ_START_TOKEN)
  		board = nubus_boards;
  	else if (board)
  		board = board->next;
  	return board;
  }
  
  static void nubus_proc_stop(struct seq_file *p, void *v)
  {
  }
  
  static const struct seq_operations nubus_proc_seqops = {
  	.start	= nubus_proc_start,
  	.next	= nubus_proc_next,
  	.stop	= nubus_proc_stop,
  	.show	= nubus_proc_show,
  };
  
  static int nubus_proc_open(struct inode *inode, struct file *file)
  {
  	return seq_open(file, &nubus_proc_seqops);
  }
  
  static const struct file_operations nubus_proc_fops = {
  	.open		= nubus_proc_open,
  	.read		= seq_read,
  	.llseek		= seq_lseek,
  	.release	= seq_release,
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
219
220
221
222
223
224
225
226
227
228
  void __init proc_bus_nubus_add_devices(void)
  {
  	struct nubus_dev *dev;
  	
  	for(dev = nubus_devices; dev; dev = dev->next)
  		nubus_proc_attach_device(dev);
  }
  
  void __init nubus_proc_init(void)
  {
11db656ad   David Howells   nubus: Don't use ...
229
  	proc_create("nubus", 0, NULL, &nubus_proc_fops);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
230
231
  	if (!MACH_IS_MAC)
  		return;
9c37066d8   Alexey Dobriyan   proc: remove proc...
232
  	proc_bus_nubus_dir = proc_mkdir("bus/nubus", NULL);
076ec04b8   Alexey Dobriyan   proc: convert /pr...
233
  	proc_create("devices", 0, proc_bus_nubus_dir, &nubus_devices_proc_fops);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
234
235
  	proc_bus_nubus_add_devices();
  }