1 |
1275 |
phoenix |
/*
|
2 |
|
|
* devices.c
|
3 |
|
|
* (C) Copyright 1999 Randy Dunlap.
|
4 |
|
|
* (C) Copyright 1999,2000 Thomas Sailer <sailer@ife.ee.ethz.ch>. (proc file per device)
|
5 |
|
|
* (C) Copyright 1999 Deti Fliegl (new USB architecture)
|
6 |
|
|
*
|
7 |
|
|
* $id$
|
8 |
|
|
*
|
9 |
|
|
* This program is free software; you can redistribute it and/or modify
|
10 |
|
|
* it under the terms of the GNU General Public License as published by
|
11 |
|
|
* the Free Software Foundation; either version 2 of the License, or
|
12 |
|
|
* (at your option) any later version.
|
13 |
|
|
*
|
14 |
|
|
* This program is distributed in the hope that it will be useful,
|
15 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17 |
|
|
* GNU General Public License for more details.
|
18 |
|
|
*
|
19 |
|
|
* You should have received a copy of the GNU General Public License
|
20 |
|
|
* along with this program; if not, write to the Free Software
|
21 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
22 |
|
|
*
|
23 |
|
|
*************************************************************
|
24 |
|
|
*
|
25 |
|
|
* <mountpoint>/devices contains USB topology, device, config, class,
|
26 |
|
|
* interface, & endpoint data.
|
27 |
|
|
*
|
28 |
|
|
* I considered using /proc/bus/usb/devices/device# for each device
|
29 |
|
|
* as it is attached or detached, but I didn't like this for some
|
30 |
|
|
* reason -- maybe it's just too deep of a directory structure.
|
31 |
|
|
* I also don't like looking in multiple places to gather and view
|
32 |
|
|
* the data. Having only one file for ./devices also prevents race
|
33 |
|
|
* conditions that could arise if a program was reading device info
|
34 |
|
|
* for devices that are being removed (unplugged). (That is, the
|
35 |
|
|
* program may find a directory for devnum_12 then try to open it,
|
36 |
|
|
* but it was just unplugged, so the directory is now deleted.
|
37 |
|
|
* But programs would just have to be prepared for situations like
|
38 |
|
|
* this in any plug-and-play environment.)
|
39 |
|
|
*
|
40 |
|
|
* 1999-12-16: Thomas Sailer <sailer@ife.ee.ethz.ch>
|
41 |
|
|
* Converted the whole proc stuff to real
|
42 |
|
|
* read methods. Now not the whole device list needs to fit
|
43 |
|
|
* into one page, only the device list for one bus.
|
44 |
|
|
* Added a poll method to /proc/bus/usb/devices, to wake
|
45 |
|
|
* up an eventual usbd
|
46 |
|
|
* 2000-01-04: Thomas Sailer <sailer@ife.ee.ethz.ch>
|
47 |
|
|
* Turned into its own filesystem
|
48 |
|
|
* 2000-07-05: Ashley Montanaro <ashley@compsoc.man.ac.uk>
|
49 |
|
|
* Converted file reading routine to dump to buffer once
|
50 |
|
|
* per device, not per bus
|
51 |
|
|
*
|
52 |
|
|
* $Id: devices.c,v 1.1.1.1 2004-04-15 01:52:35 phoenix Exp $
|
53 |
|
|
*/
|
54 |
|
|
|
55 |
|
|
#include <linux/fs.h>
|
56 |
|
|
#include <linux/mm.h>
|
57 |
|
|
#include <linux/slab.h>
|
58 |
|
|
#include <linux/poll.h>
|
59 |
|
|
#include <linux/usb.h>
|
60 |
|
|
#include <linux/smp_lock.h>
|
61 |
|
|
#include <linux/usbdevice_fs.h>
|
62 |
|
|
#include <asm/uaccess.h>
|
63 |
|
|
|
64 |
|
|
#include "hcd.h"
|
65 |
|
|
|
66 |
|
|
#define MAX_TOPO_LEVEL 6
|
67 |
|
|
|
68 |
|
|
/* Define ALLOW_SERIAL_NUMBER if you want to see the serial number of devices */
|
69 |
|
|
#define ALLOW_SERIAL_NUMBER
|
70 |
|
|
|
71 |
|
|
static char *format_topo =
|
72 |
|
|
/* T: Bus=dd Lev=dd Prnt=dd Port=dd Cnt=dd Dev#=ddd Spd=ddd MxCh=dd */
|
73 |
|
|
"T: Bus=%2.2d Lev=%2.2d Prnt=%2.2d Port=%2.2d Cnt=%2.2d Dev#=%3d Spd=%3s MxCh=%2d\n";
|
74 |
|
|
|
75 |
|
|
static char *format_string_manufacturer =
|
76 |
|
|
/* S: Manufacturer=xxxx */
|
77 |
|
|
"S: Manufacturer=%.100s\n";
|
78 |
|
|
|
79 |
|
|
static char *format_string_product =
|
80 |
|
|
/* S: Product=xxxx */
|
81 |
|
|
"S: Product=%.100s\n";
|
82 |
|
|
|
83 |
|
|
#ifdef ALLOW_SERIAL_NUMBER
|
84 |
|
|
static char *format_string_serialnumber =
|
85 |
|
|
/* S: SerialNumber=xxxx */
|
86 |
|
|
"S: SerialNumber=%.100s\n";
|
87 |
|
|
#endif
|
88 |
|
|
|
89 |
|
|
static char *format_bandwidth =
|
90 |
|
|
/* B: Alloc=ddd/ddd us (xx%), #Int=ddd, #Iso=ddd */
|
91 |
|
|
"B: Alloc=%3d/%3d us (%2d%%), #Int=%3d, #Iso=%3d\n";
|
92 |
|
|
|
93 |
|
|
static char *format_device1 =
|
94 |
|
|
/* D: Ver=xx.xx Cls=xx(sssss) Sub=xx Prot=xx MxPS=dd #Cfgs=dd */
|
95 |
|
|
"D: Ver=%2x.%02x Cls=%02x(%-5s) Sub=%02x Prot=%02x MxPS=%2d #Cfgs=%3d\n";
|
96 |
|
|
|
97 |
|
|
static char *format_device2 =
|
98 |
|
|
/* P: Vendor=xxxx ProdID=xxxx Rev=xx.xx */
|
99 |
|
|
"P: Vendor=%04x ProdID=%04x Rev=%2x.%02x\n";
|
100 |
|
|
|
101 |
|
|
static char *format_config =
|
102 |
|
|
/* C: #Ifs=dd Cfg#=dd Atr=xx MPwr=dddmA */
|
103 |
|
|
"C:%c #Ifs=%2d Cfg#=%2d Atr=%02x MxPwr=%3dmA\n";
|
104 |
|
|
|
105 |
|
|
static char *format_iface =
|
106 |
|
|
/* I: If#=dd Alt=dd #EPs=dd Cls=xx(sssss) Sub=xx Prot=xx Driver=xxxx*/
|
107 |
|
|
"I: If#=%2d Alt=%2d #EPs=%2d Cls=%02x(%-5s) Sub=%02x Prot=%02x Driver=%s\n";
|
108 |
|
|
|
109 |
|
|
static char *format_endpt =
|
110 |
|
|
/* E: Ad=xx(s) Atr=xx(ssss) MxPS=dddd Ivl=D?s */
|
111 |
|
|
"E: Ad=%02x(%c) Atr=%02x(%-4s) MxPS=%4d Ivl=%d%cs\n";
|
112 |
|
|
|
113 |
|
|
|
114 |
|
|
/*
|
115 |
|
|
* Need access to the driver and USB bus lists.
|
116 |
|
|
* extern struct list_head usb_driver_list;
|
117 |
|
|
* extern struct list_head usb_bus_list;
|
118 |
|
|
* However, these will come from functions that return ptrs to each of them.
|
119 |
|
|
*/
|
120 |
|
|
|
121 |
|
|
static DECLARE_WAIT_QUEUE_HEAD(deviceconndiscwq);
|
122 |
|
|
static unsigned int conndiscevcnt = 0;
|
123 |
|
|
|
124 |
|
|
/* this struct stores the poll state for <mountpoint>/devices pollers */
|
125 |
|
|
struct usb_device_status {
|
126 |
|
|
unsigned int lastev;
|
127 |
|
|
};
|
128 |
|
|
|
129 |
|
|
struct class_info {
|
130 |
|
|
int class;
|
131 |
|
|
char *class_name;
|
132 |
|
|
};
|
133 |
|
|
|
134 |
|
|
static const struct class_info clas_info[] =
|
135 |
|
|
{ /* max. 5 chars. per name string */
|
136 |
|
|
{USB_CLASS_PER_INTERFACE, ">ifc"},
|
137 |
|
|
{USB_CLASS_AUDIO, "audio"},
|
138 |
|
|
{USB_CLASS_COMM, "comm."},
|
139 |
|
|
{USB_CLASS_HID, "HID"},
|
140 |
|
|
{USB_CLASS_HUB, "hub"},
|
141 |
|
|
{USB_CLASS_PHYSICAL, "PID"},
|
142 |
|
|
{USB_CLASS_PRINTER, "print"},
|
143 |
|
|
{USB_CLASS_MASS_STORAGE, "stor."},
|
144 |
|
|
{USB_CLASS_CDC_DATA, "data"},
|
145 |
|
|
{USB_CLASS_APP_SPEC, "app."},
|
146 |
|
|
{USB_CLASS_VENDOR_SPEC, "vend."},
|
147 |
|
|
{USB_CLASS_STILL_IMAGE, "still"},
|
148 |
|
|
{USB_CLASS_CSCID, "scard"},
|
149 |
|
|
{USB_CLASS_CONTENT_SEC, "c-sec"},
|
150 |
|
|
{-1, "unk."} /* leave as last */
|
151 |
|
|
};
|
152 |
|
|
|
153 |
|
|
/*****************************************************************/
|
154 |
|
|
|
155 |
|
|
void usbdevfs_conn_disc_event(void)
|
156 |
|
|
{
|
157 |
|
|
wake_up(&deviceconndiscwq);
|
158 |
|
|
conndiscevcnt++;
|
159 |
|
|
}
|
160 |
|
|
|
161 |
|
|
static const char *class_decode(const int class)
|
162 |
|
|
{
|
163 |
|
|
int ix;
|
164 |
|
|
|
165 |
|
|
for (ix = 0; clas_info[ix].class != -1; ix++)
|
166 |
|
|
if (clas_info[ix].class == class)
|
167 |
|
|
break;
|
168 |
|
|
return (clas_info[ix].class_name);
|
169 |
|
|
}
|
170 |
|
|
|
171 |
|
|
static char *usb_dump_endpoint_descriptor (
|
172 |
|
|
int speed,
|
173 |
|
|
char *start,
|
174 |
|
|
char *end,
|
175 |
|
|
const struct usb_endpoint_descriptor *desc
|
176 |
|
|
)
|
177 |
|
|
{
|
178 |
|
|
char dir, unit, *type;
|
179 |
|
|
unsigned interval, in, bandwidth = 1;
|
180 |
|
|
|
181 |
|
|
if (start > end)
|
182 |
|
|
return start;
|
183 |
|
|
in = (desc->bEndpointAddress & USB_DIR_IN);
|
184 |
|
|
dir = in ? 'I' : 'O';
|
185 |
|
|
if (speed == USB_SPEED_HIGH) {
|
186 |
|
|
switch (desc->wMaxPacketSize & (0x03 << 11)) {
|
187 |
|
|
case 1 << 11: bandwidth = 2; break;
|
188 |
|
|
case 2 << 11: bandwidth = 3; break;
|
189 |
|
|
}
|
190 |
|
|
}
|
191 |
|
|
|
192 |
|
|
/* this isn't checking for illegal values */
|
193 |
|
|
switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) {
|
194 |
|
|
case USB_ENDPOINT_XFER_CONTROL:
|
195 |
|
|
type = "Ctrl";
|
196 |
|
|
if (speed == USB_SPEED_HIGH) /* uframes per NAK */
|
197 |
|
|
interval = desc->bInterval;
|
198 |
|
|
else
|
199 |
|
|
interval = 0;
|
200 |
|
|
dir = 'B'; /* ctrl is bidirectional */
|
201 |
|
|
break;
|
202 |
|
|
case USB_ENDPOINT_XFER_ISOC:
|
203 |
|
|
type = "Isoc";
|
204 |
|
|
interval = 1 << (desc->bInterval - 1);
|
205 |
|
|
break;
|
206 |
|
|
case USB_ENDPOINT_XFER_BULK:
|
207 |
|
|
type = "Bulk";
|
208 |
|
|
if (speed == USB_SPEED_HIGH && !in) /* uframes per NAK */
|
209 |
|
|
interval = desc->bInterval;
|
210 |
|
|
else
|
211 |
|
|
interval = 0;
|
212 |
|
|
break;
|
213 |
|
|
case USB_ENDPOINT_XFER_INT:
|
214 |
|
|
type = "Int.";
|
215 |
|
|
if (speed == USB_SPEED_HIGH) {
|
216 |
|
|
interval = 1 << (desc->bInterval - 1);
|
217 |
|
|
} else
|
218 |
|
|
interval = desc->bInterval;
|
219 |
|
|
break;
|
220 |
|
|
default: /* "can't happen" */
|
221 |
|
|
return start;
|
222 |
|
|
}
|
223 |
|
|
interval *= (speed == USB_SPEED_HIGH) ? 125 : 1000;
|
224 |
|
|
if (interval % 1000)
|
225 |
|
|
unit = 'u';
|
226 |
|
|
else {
|
227 |
|
|
unit = 'm';
|
228 |
|
|
interval /= 1000;
|
229 |
|
|
}
|
230 |
|
|
|
231 |
|
|
start += sprintf(start, format_endpt, desc->bEndpointAddress, dir,
|
232 |
|
|
desc->bmAttributes, type,
|
233 |
|
|
(desc->wMaxPacketSize & 0x07ff) * bandwidth,
|
234 |
|
|
interval, unit);
|
235 |
|
|
return start;
|
236 |
|
|
}
|
237 |
|
|
|
238 |
|
|
static char *usb_dump_interface_descriptor(char *start, char *end, const struct usb_interface *iface, int setno)
|
239 |
|
|
{
|
240 |
|
|
struct usb_interface_descriptor *desc = &iface->altsetting[setno];
|
241 |
|
|
|
242 |
|
|
if (start > end)
|
243 |
|
|
return start;
|
244 |
|
|
start += sprintf(start, format_iface,
|
245 |
|
|
desc->bInterfaceNumber,
|
246 |
|
|
desc->bAlternateSetting,
|
247 |
|
|
desc->bNumEndpoints,
|
248 |
|
|
desc->bInterfaceClass,
|
249 |
|
|
class_decode(desc->bInterfaceClass),
|
250 |
|
|
desc->bInterfaceSubClass,
|
251 |
|
|
desc->bInterfaceProtocol,
|
252 |
|
|
iface->driver ? iface->driver->name : "(none)");
|
253 |
|
|
return start;
|
254 |
|
|
}
|
255 |
|
|
|
256 |
|
|
static char *usb_dump_interface(
|
257 |
|
|
int speed,
|
258 |
|
|
char *start,
|
259 |
|
|
char *end,
|
260 |
|
|
const struct usb_interface *iface,
|
261 |
|
|
int setno
|
262 |
|
|
) {
|
263 |
|
|
struct usb_interface_descriptor *desc = &iface->altsetting[setno];
|
264 |
|
|
int i;
|
265 |
|
|
|
266 |
|
|
start = usb_dump_interface_descriptor(start, end, iface, setno);
|
267 |
|
|
for (i = 0; i < desc->bNumEndpoints; i++) {
|
268 |
|
|
if (start > end)
|
269 |
|
|
return start;
|
270 |
|
|
start = usb_dump_endpoint_descriptor(speed,
|
271 |
|
|
start, end, desc->endpoint + i);
|
272 |
|
|
}
|
273 |
|
|
return start;
|
274 |
|
|
}
|
275 |
|
|
|
276 |
|
|
/* TBD:
|
277 |
|
|
* 0. TBDs
|
278 |
|
|
* 1. marking active config and ifaces (code lists all, but should mark
|
279 |
|
|
* which ones are active, if any)
|
280 |
|
|
* 2. add <halted> status to each endpoint line
|
281 |
|
|
*/
|
282 |
|
|
|
283 |
|
|
static char *usb_dump_config_descriptor(char *start, char *end, const struct usb_config_descriptor *desc, int active)
|
284 |
|
|
{
|
285 |
|
|
if (start > end)
|
286 |
|
|
return start;
|
287 |
|
|
start += sprintf(start, format_config,
|
288 |
|
|
active ? '*' : ' ', /* mark active/actual/current cfg. */
|
289 |
|
|
desc->bNumInterfaces,
|
290 |
|
|
desc->bConfigurationValue,
|
291 |
|
|
desc->bmAttributes,
|
292 |
|
|
desc->MaxPower * 2);
|
293 |
|
|
return start;
|
294 |
|
|
}
|
295 |
|
|
|
296 |
|
|
static char *usb_dump_config (
|
297 |
|
|
int speed,
|
298 |
|
|
char *start,
|
299 |
|
|
char *end,
|
300 |
|
|
const struct usb_config_descriptor *config,
|
301 |
|
|
int active
|
302 |
|
|
)
|
303 |
|
|
{
|
304 |
|
|
int i, j;
|
305 |
|
|
struct usb_interface *interface;
|
306 |
|
|
|
307 |
|
|
if (start > end)
|
308 |
|
|
return start;
|
309 |
|
|
if (!config) /* getting these some in 2.3.7; none in 2.3.6 */
|
310 |
|
|
return start + sprintf(start, "(null Cfg. desc.)\n");
|
311 |
|
|
start = usb_dump_config_descriptor(start, end, config, active);
|
312 |
|
|
for (i = 0; i < config->bNumInterfaces; i++) {
|
313 |
|
|
interface = config->interface + i;
|
314 |
|
|
if (!interface)
|
315 |
|
|
break;
|
316 |
|
|
for (j = 0; j < interface->num_altsetting; j++) {
|
317 |
|
|
if (start > end)
|
318 |
|
|
return start;
|
319 |
|
|
start = usb_dump_interface(speed,
|
320 |
|
|
start, end, interface, j);
|
321 |
|
|
}
|
322 |
|
|
}
|
323 |
|
|
return start;
|
324 |
|
|
}
|
325 |
|
|
|
326 |
|
|
/*
|
327 |
|
|
* Dump the different USB descriptors.
|
328 |
|
|
*/
|
329 |
|
|
static char *usb_dump_device_descriptor(char *start, char *end, const struct usb_device_descriptor *desc)
|
330 |
|
|
{
|
331 |
|
|
if (start > end)
|
332 |
|
|
return start;
|
333 |
|
|
start += sprintf (start, format_device1,
|
334 |
|
|
desc->bcdUSB >> 8, desc->bcdUSB & 0xff,
|
335 |
|
|
desc->bDeviceClass,
|
336 |
|
|
class_decode (desc->bDeviceClass),
|
337 |
|
|
desc->bDeviceSubClass,
|
338 |
|
|
desc->bDeviceProtocol,
|
339 |
|
|
desc->bMaxPacketSize0,
|
340 |
|
|
desc->bNumConfigurations);
|
341 |
|
|
if (start > end)
|
342 |
|
|
return start;
|
343 |
|
|
start += sprintf(start, format_device2,
|
344 |
|
|
desc->idVendor, desc->idProduct,
|
345 |
|
|
desc->bcdDevice >> 8, desc->bcdDevice & 0xff);
|
346 |
|
|
return start;
|
347 |
|
|
}
|
348 |
|
|
|
349 |
|
|
/*
|
350 |
|
|
* Dump the different strings that this device holds.
|
351 |
|
|
*/
|
352 |
|
|
static char *usb_dump_device_strings (char *start, char *end, struct usb_device *dev)
|
353 |
|
|
{
|
354 |
|
|
char *buf;
|
355 |
|
|
|
356 |
|
|
if (start > end)
|
357 |
|
|
return start;
|
358 |
|
|
buf = kmalloc(128, GFP_KERNEL);
|
359 |
|
|
if (!buf)
|
360 |
|
|
return start;
|
361 |
|
|
if (dev->descriptor.iManufacturer) {
|
362 |
|
|
if (usb_string(dev, dev->descriptor.iManufacturer, buf, 128) > 0)
|
363 |
|
|
start += sprintf(start, format_string_manufacturer, buf);
|
364 |
|
|
}
|
365 |
|
|
if (start > end)
|
366 |
|
|
goto out;
|
367 |
|
|
if (dev->descriptor.iProduct) {
|
368 |
|
|
if (usb_string(dev, dev->descriptor.iProduct, buf, 128) > 0)
|
369 |
|
|
start += sprintf(start, format_string_product, buf);
|
370 |
|
|
}
|
371 |
|
|
if (start > end)
|
372 |
|
|
goto out;
|
373 |
|
|
#ifdef ALLOW_SERIAL_NUMBER
|
374 |
|
|
if (dev->descriptor.iSerialNumber) {
|
375 |
|
|
if (usb_string(dev, dev->descriptor.iSerialNumber, buf, 128) > 0)
|
376 |
|
|
start += sprintf(start, format_string_serialnumber, buf);
|
377 |
|
|
}
|
378 |
|
|
#endif
|
379 |
|
|
out:
|
380 |
|
|
kfree(buf);
|
381 |
|
|
return start;
|
382 |
|
|
}
|
383 |
|
|
|
384 |
|
|
static char *usb_dump_desc(char *start, char *end, struct usb_device *dev)
|
385 |
|
|
{
|
386 |
|
|
int i;
|
387 |
|
|
|
388 |
|
|
if (start > end)
|
389 |
|
|
return start;
|
390 |
|
|
|
391 |
|
|
start = usb_dump_device_descriptor(start, end, &dev->descriptor);
|
392 |
|
|
|
393 |
|
|
if (start > end)
|
394 |
|
|
return start;
|
395 |
|
|
|
396 |
|
|
start = usb_dump_device_strings (start, end, dev);
|
397 |
|
|
|
398 |
|
|
for (i = 0; i < dev->descriptor.bNumConfigurations; i++) {
|
399 |
|
|
if (start > end)
|
400 |
|
|
return start;
|
401 |
|
|
start = usb_dump_config(dev->speed,
|
402 |
|
|
start, end, dev->config + i,
|
403 |
|
|
/* active ? */
|
404 |
|
|
(dev->config + i) == dev->actconfig);
|
405 |
|
|
}
|
406 |
|
|
return start;
|
407 |
|
|
}
|
408 |
|
|
|
409 |
|
|
|
410 |
|
|
#ifdef PROC_EXTRA /* TBD: may want to add this code later */
|
411 |
|
|
|
412 |
|
|
static char *usb_dump_hub_descriptor(char *start, char *end, const struct usb_hub_descriptor * desc)
|
413 |
|
|
{
|
414 |
|
|
int leng = USB_DT_HUB_NONVAR_SIZE;
|
415 |
|
|
unsigned char *ptr = (unsigned char *)desc;
|
416 |
|
|
|
417 |
|
|
if (start > end)
|
418 |
|
|
return start;
|
419 |
|
|
start += sprintf(start, "Interface:");
|
420 |
|
|
while (leng && start <= end) {
|
421 |
|
|
start += sprintf(start, " %02x", *ptr);
|
422 |
|
|
ptr++; leng--;
|
423 |
|
|
}
|
424 |
|
|
*start++ = '\n';
|
425 |
|
|
return start;
|
426 |
|
|
}
|
427 |
|
|
|
428 |
|
|
static char *usb_dump_string(char *start, char *end, const struct usb_device *dev, char *id, int index)
|
429 |
|
|
{
|
430 |
|
|
if (start > end)
|
431 |
|
|
return start;
|
432 |
|
|
start += sprintf(start, "Interface:");
|
433 |
|
|
if (index <= dev->maxstring && dev->stringindex && dev->stringindex[index])
|
434 |
|
|
start += sprintf(start, "%s: %.100s ", id, dev->stringindex[index]);
|
435 |
|
|
return start;
|
436 |
|
|
}
|
437 |
|
|
|
438 |
|
|
#endif /* PROC_EXTRA */
|
439 |
|
|
|
440 |
|
|
/*****************************************************************/
|
441 |
|
|
|
442 |
|
|
/* This is a recursive function. Parameters:
|
443 |
|
|
* buffer - the user-space buffer to write data into
|
444 |
|
|
* nbytes - the maximum number of bytes to write
|
445 |
|
|
* skip_bytes - the number of bytes to skip before writing anything
|
446 |
|
|
* file_offset - the offset into the devices file on completion
|
447 |
|
|
*/
|
448 |
|
|
static ssize_t usb_device_dump(char **buffer, size_t *nbytes, loff_t *skip_bytes, loff_t *file_offset,
|
449 |
|
|
struct usb_device *usbdev, struct usb_bus *bus, int level, int index, int count)
|
450 |
|
|
{
|
451 |
|
|
int chix;
|
452 |
|
|
int ret, cnt = 0;
|
453 |
|
|
int parent_devnum = 0;
|
454 |
|
|
char *pages_start, *data_end, *speed;
|
455 |
|
|
unsigned int length;
|
456 |
|
|
ssize_t total_written = 0;
|
457 |
|
|
|
458 |
|
|
/* don't bother with anything else if we're not writing any data */
|
459 |
|
|
if (*nbytes <= 0)
|
460 |
|
|
return 0;
|
461 |
|
|
|
462 |
|
|
if (level > MAX_TOPO_LEVEL)
|
463 |
|
|
return total_written;
|
464 |
|
|
/* allocate 2^1 pages = 8K (on i386); should be more than enough for one device */
|
465 |
|
|
if (!(pages_start = (char*) __get_free_pages(GFP_KERNEL,1)))
|
466 |
|
|
return -ENOMEM;
|
467 |
|
|
|
468 |
|
|
if (usbdev->parent && usbdev->parent->devnum != -1)
|
469 |
|
|
parent_devnum = usbdev->parent->devnum;
|
470 |
|
|
/*
|
471 |
|
|
* So the root hub's parent is 0 and any device that is
|
472 |
|
|
* plugged into the root hub has a parent of 0.
|
473 |
|
|
*/
|
474 |
|
|
switch (usbdev->speed) {
|
475 |
|
|
case USB_SPEED_LOW:
|
476 |
|
|
speed = "1.5"; break;
|
477 |
|
|
case USB_SPEED_UNKNOWN: /* usb 1.1 root hub code */
|
478 |
|
|
case USB_SPEED_FULL:
|
479 |
|
|
speed = "12 "; break;
|
480 |
|
|
case USB_SPEED_HIGH:
|
481 |
|
|
speed = "480"; break;
|
482 |
|
|
default:
|
483 |
|
|
speed = "?? ";
|
484 |
|
|
}
|
485 |
|
|
data_end = pages_start + sprintf(pages_start, format_topo,
|
486 |
|
|
bus->busnum, level, parent_devnum,
|
487 |
|
|
index, count, usbdev->devnum,
|
488 |
|
|
speed, usbdev->maxchild);
|
489 |
|
|
/*
|
490 |
|
|
* level = topology-tier level;
|
491 |
|
|
* parent_devnum = parent device number;
|
492 |
|
|
* index = parent's connector number;
|
493 |
|
|
* count = device count at this level
|
494 |
|
|
*/
|
495 |
|
|
/* If this is the root hub, display the bandwidth information */
|
496 |
|
|
if (level == 0) {
|
497 |
|
|
int max;
|
498 |
|
|
|
499 |
|
|
/* high speed reserves 80%, full/low reserves 90% */
|
500 |
|
|
if (usbdev->speed == USB_SPEED_HIGH)
|
501 |
|
|
max = 800;
|
502 |
|
|
else
|
503 |
|
|
max = FRAME_TIME_MAX_USECS_ALLOC;
|
504 |
|
|
|
505 |
|
|
/* report "average" periodic allocation over a microsecond.
|
506 |
|
|
* the schedules are actually bursty, HCDs need to deal with
|
507 |
|
|
* that and just compute/report this average.
|
508 |
|
|
*/
|
509 |
|
|
data_end += sprintf(data_end, format_bandwidth,
|
510 |
|
|
bus->bandwidth_allocated, max,
|
511 |
|
|
(100 * bus->bandwidth_allocated + max / 2)
|
512 |
|
|
/ max,
|
513 |
|
|
bus->bandwidth_int_reqs,
|
514 |
|
|
bus->bandwidth_isoc_reqs);
|
515 |
|
|
}
|
516 |
|
|
data_end = usb_dump_desc(data_end, pages_start + (2 * PAGE_SIZE) - 256, usbdev);
|
517 |
|
|
|
518 |
|
|
if (data_end > (pages_start + (2 * PAGE_SIZE) - 256))
|
519 |
|
|
data_end += sprintf(data_end, "(truncated)\n");
|
520 |
|
|
|
521 |
|
|
length = data_end - pages_start;
|
522 |
|
|
/* if we can start copying some data to the user */
|
523 |
|
|
if (length > *skip_bytes) {
|
524 |
|
|
length -= *skip_bytes;
|
525 |
|
|
if (length > *nbytes)
|
526 |
|
|
length = *nbytes;
|
527 |
|
|
if (copy_to_user(*buffer, pages_start + *skip_bytes, length)) {
|
528 |
|
|
free_pages((unsigned long)pages_start, 1);
|
529 |
|
|
|
530 |
|
|
if (total_written == 0)
|
531 |
|
|
return -EFAULT;
|
532 |
|
|
return total_written;
|
533 |
|
|
}
|
534 |
|
|
*nbytes -= length;
|
535 |
|
|
*file_offset += length;
|
536 |
|
|
total_written += length;
|
537 |
|
|
*buffer += length;
|
538 |
|
|
*skip_bytes = 0;
|
539 |
|
|
} else
|
540 |
|
|
*skip_bytes -= length;
|
541 |
|
|
|
542 |
|
|
free_pages((unsigned long)pages_start, 1);
|
543 |
|
|
|
544 |
|
|
/* Now look at all of this device's children. */
|
545 |
|
|
for (chix = 0; chix < usbdev->maxchild; chix++) {
|
546 |
|
|
if (usbdev->children[chix]) {
|
547 |
|
|
ret = usb_device_dump(buffer, nbytes, skip_bytes, file_offset, usbdev->children[chix],
|
548 |
|
|
bus, level + 1, chix, ++cnt);
|
549 |
|
|
if (ret == -EFAULT)
|
550 |
|
|
return total_written;
|
551 |
|
|
total_written += ret;
|
552 |
|
|
}
|
553 |
|
|
}
|
554 |
|
|
return total_written;
|
555 |
|
|
}
|
556 |
|
|
|
557 |
|
|
static ssize_t usb_device_read(struct file *file, char *buf, size_t nbytes, loff_t *ppos)
|
558 |
|
|
{
|
559 |
|
|
struct list_head *buslist;
|
560 |
|
|
struct usb_bus *bus;
|
561 |
|
|
ssize_t ret, total_written = 0;
|
562 |
|
|
loff_t skip_bytes = *ppos;
|
563 |
|
|
|
564 |
|
|
if (*ppos < 0)
|
565 |
|
|
return -EINVAL;
|
566 |
|
|
if (nbytes <= 0)
|
567 |
|
|
return 0;
|
568 |
|
|
if (!access_ok(VERIFY_WRITE, buf, nbytes))
|
569 |
|
|
return -EFAULT;
|
570 |
|
|
|
571 |
|
|
/* enumerate busses */
|
572 |
|
|
down (&usb_bus_list_lock);
|
573 |
|
|
for (buslist = usb_bus_list.next; buslist != &usb_bus_list; buslist = buslist->next) {
|
574 |
|
|
/* print devices for this bus */
|
575 |
|
|
bus = list_entry(buslist, struct usb_bus, bus_list);
|
576 |
|
|
/* recurse through all children of the root hub */
|
577 |
|
|
ret = usb_device_dump(&buf, &nbytes, &skip_bytes, ppos, bus->root_hub, bus, 0, 0, 0);
|
578 |
|
|
if (ret < 0) {
|
579 |
|
|
up(&usb_bus_list_lock);
|
580 |
|
|
return ret;
|
581 |
|
|
}
|
582 |
|
|
total_written += ret;
|
583 |
|
|
}
|
584 |
|
|
up (&usb_bus_list_lock);
|
585 |
|
|
return total_written;
|
586 |
|
|
}
|
587 |
|
|
|
588 |
|
|
/* Kernel lock for "lastev" protection */
|
589 |
|
|
static unsigned int usb_device_poll(struct file *file, struct poll_table_struct *wait)
|
590 |
|
|
{
|
591 |
|
|
struct usb_device_status *st = (struct usb_device_status *)file->private_data;
|
592 |
|
|
unsigned int mask = 0;
|
593 |
|
|
|
594 |
|
|
lock_kernel();
|
595 |
|
|
if (!st) {
|
596 |
|
|
st = kmalloc(sizeof(struct usb_device_status), GFP_KERNEL);
|
597 |
|
|
if (!st) {
|
598 |
|
|
unlock_kernel();
|
599 |
|
|
return POLLIN;
|
600 |
|
|
}
|
601 |
|
|
/*
|
602 |
|
|
* need to prevent the module from being unloaded, since
|
603 |
|
|
* proc_unregister does not call the release method and
|
604 |
|
|
* we would have a memory leak
|
605 |
|
|
*/
|
606 |
|
|
st->lastev = conndiscevcnt;
|
607 |
|
|
file->private_data = st;
|
608 |
|
|
mask = POLLIN;
|
609 |
|
|
}
|
610 |
|
|
if (file->f_mode & FMODE_READ)
|
611 |
|
|
poll_wait(file, &deviceconndiscwq, wait);
|
612 |
|
|
if (st->lastev != conndiscevcnt)
|
613 |
|
|
mask |= POLLIN;
|
614 |
|
|
st->lastev = conndiscevcnt;
|
615 |
|
|
unlock_kernel();
|
616 |
|
|
return mask;
|
617 |
|
|
}
|
618 |
|
|
|
619 |
|
|
static int usb_device_open(struct inode *inode, struct file *file)
|
620 |
|
|
{
|
621 |
|
|
file->private_data = NULL;
|
622 |
|
|
return 0;
|
623 |
|
|
}
|
624 |
|
|
|
625 |
|
|
static int usb_device_release(struct inode *inode, struct file *file)
|
626 |
|
|
{
|
627 |
|
|
if (file->private_data) {
|
628 |
|
|
kfree(file->private_data);
|
629 |
|
|
file->private_data = NULL;
|
630 |
|
|
}
|
631 |
|
|
|
632 |
|
|
return 0;
|
633 |
|
|
}
|
634 |
|
|
|
635 |
|
|
static loff_t usb_device_lseek(struct file * file, loff_t offset, int orig)
|
636 |
|
|
{
|
637 |
|
|
switch (orig) {
|
638 |
|
|
case 0:
|
639 |
|
|
file->f_pos = offset;
|
640 |
|
|
return file->f_pos;
|
641 |
|
|
|
642 |
|
|
case 1:
|
643 |
|
|
file->f_pos += offset;
|
644 |
|
|
return file->f_pos;
|
645 |
|
|
|
646 |
|
|
case 2:
|
647 |
|
|
return -EINVAL;
|
648 |
|
|
|
649 |
|
|
default:
|
650 |
|
|
return -EINVAL;
|
651 |
|
|
}
|
652 |
|
|
}
|
653 |
|
|
|
654 |
|
|
struct file_operations usbdevfs_devices_fops = {
|
655 |
|
|
llseek: usb_device_lseek,
|
656 |
|
|
read: usb_device_read,
|
657 |
|
|
poll: usb_device_poll,
|
658 |
|
|
open: usb_device_open,
|
659 |
|
|
release: usb_device_release,
|
660 |
|
|
};
|