Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'docs-4.12' of git://git.lwn.net/linux

Pull documentation update from Jonathan Corbet:
"A reasonably busy cycle for documentation this time around. There is a
new guide for user-space API documents, rather sparsely populated at
the moment, but it's a start. Markus improved the infrastructure for
converting diagrams. Mauro has converted much of the USB documentation
over to RST. Plus the usual set of fixes, improvements, and tweaks.

There's a bit more than the usual amount of reaching out of
Documentation/ to fix comments elsewhere in the tree; I have acks for
those where I could get them"

* tag 'docs-4.12' of git://git.lwn.net/linux: (74 commits)
docs: Fix a couple typos
docs: Fix a spelling error in vfio-mediated-device.txt
docs: Fix a spelling error in ioctl-number.txt
MAINTAINERS: update file entry for HSI subsystem
Documentation: allow installing man pages to a user defined directory
Doc/PM: Sync with intel_powerclamp code behavior
zr364xx.rst: usb/devices is now at /sys/kernel/debug/
usb.rst: move documentation from proc_usb_info.txt to USB ReST book
convert philips.txt to ReST and add to media docs
docs-rst: usb: update old usbfs-related documentation
arm: Documentation: update a path name
docs: process/4.Coding.rst: Fix a couple of document refs
docs-rst: fix usb cross-references
usb: gadget.h: be consistent at kernel doc macros
usb: composite.h: fix two warnings when building docs
usb: get rid of some ReST doc build errors
usb.rst: get rid of some Sphinx errors
usb/URB.txt: convert to ReST and update it
usb/persist.txt: convert to ReST and add to driver-api book
usb/hotplug.txt: convert to ReST and add to driver-api book
...

+7108 -6414
+1 -1
Documentation/ABI/stable/sysfs-bus-usb
··· 9 9 hubs this facility is always enabled and their device 10 10 directories will not contain this file. 11 11 12 - For more information, see Documentation/usb/persist.txt. 12 + For more information, see Documentation/driver-api/usb/persist.rst. 13 13 14 14 What: /sys/bus/usb/devices/.../power/autosuspend 15 15 Date: March 2007
+2 -1
Documentation/ABI/stable/vdso
··· 16 16 vDSO, specify the version you are expecting. 17 17 18 18 Programs that dynamically link to glibc will use the vDSO automatically. 19 - Otherwise, you can use the reference parser in Documentation/vDSO/parse_vdso.c. 19 + Otherwise, you can use the reference parser in 20 + tools/testing/selftests/vDSO/parse_vdso.c. 20 21 21 22 Unless otherwise noted, the set of symbols with any given version and the 22 23 ABI of those symbols is considered stable. It may vary across architectures,
+1 -1
Documentation/ABI/testing/sysfs-bus-pci
··· 299 299 Date: November 2016 300 300 Contact: Emil Velikov <emil.l.velikov@gmail.com> 301 301 Description: 302 - This file contains the revision field of the the PCI device. 302 + This file contains the revision field of the PCI device. 303 303 The value comes from device config space. The file is read only.
+13 -9
Documentation/DocBook/Makefile
··· 8 8 9 9 DOCBOOKS := z8530book.xml \ 10 10 kernel-hacking.xml kernel-locking.xml \ 11 - writing_usb_driver.xml networking.xml \ 12 - kernel-api.xml filesystems.xml lsm.xml kgdb.xml \ 13 - gadget.xml libata.xml mtdnand.xml librs.xml rapidio.xml \ 14 - genericirq.xml s390-drivers.xml scsi.xml \ 15 - sh.xml w1.xml \ 16 - writing_musb_glue_layer.xml 11 + networking.xml \ 12 + filesystems.xml lsm.xml kgdb.xml \ 13 + libata.xml mtdnand.xml librs.xml rapidio.xml \ 14 + s390-drivers.xml scsi.xml \ 15 + sh.xml w1.xml 17 16 18 17 ifeq ($(DOCBOOKS),) 19 18 ··· 61 62 mandocs: $(MAN) 62 63 find $(obj)/man -name '*.9' | xargs gzip -nf 63 64 65 + # Default location for installed man pages 66 + export INSTALL_MAN_PATH = $(objtree)/usr 67 + 64 68 installmandocs: mandocs 65 - mkdir -p /usr/local/man/man9/ 69 + mkdir -p $(INSTALL_MAN_PATH)/man/man9/ 66 70 find $(obj)/man -name '*.9.gz' -printf '%h %f\n' | \ 67 71 sort -k 2 -k 1 | uniq -f 1 | sed -e 's: :/:' | \ 68 - xargs install -m 644 -t /usr/local/man/man9/ 72 + xargs install -m 644 -t $(INSTALL_MAN_PATH)/man/man9/ 69 73 70 74 # no-op for the DocBook toolchain 71 75 epubdocs: ··· 240 238 @echo ' psdocs - Postscript' 241 239 @echo ' xmldocs - XML DocBook' 242 240 @echo ' mandocs - man pages' 243 - @echo ' installmandocs - install man pages generated by mandocs' 241 + @echo ' installmandocs - install man pages generated by mandocs to INSTALL_MAN_PATH'; \ 242 + echo ' (default: $(INSTALL_MAN_PATH))'; \ 243 + echo '' 244 244 @echo ' cleandocs - clean all generated DocBook files' 245 245 @echo 246 246 @echo ' make DOCBOOKS="s1.xml s2.xml" [target] Generate only docs s1.xml s2.xml'
-793
Documentation/DocBook/gadget.tmpl
··· 1 - <?xml version="1.0" encoding="UTF-8"?> 2 - <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" 3 - "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" []> 4 - 5 - <book id="USB-Gadget-API"> 6 - <bookinfo> 7 - <title>USB Gadget API for Linux</title> 8 - <date>20 August 2004</date> 9 - <edition>20 August 2004</edition> 10 - 11 - <legalnotice> 12 - <para> 13 - This documentation is free software; you can redistribute 14 - it and/or modify it under the terms of the GNU General Public 15 - License as published by the Free Software Foundation; either 16 - version 2 of the License, or (at your option) any later 17 - version. 18 - </para> 19 - 20 - <para> 21 - This program is distributed in the hope that it will be 22 - useful, but WITHOUT ANY WARRANTY; without even the implied 23 - warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 24 - See the GNU General Public License for more details. 25 - </para> 26 - 27 - <para> 28 - You should have received a copy of the GNU General Public 29 - License along with this program; if not, write to the Free 30 - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, 31 - MA 02111-1307 USA 32 - </para> 33 - 34 - <para> 35 - For more details see the file COPYING in the source 36 - distribution of Linux. 37 - </para> 38 - </legalnotice> 39 - <copyright> 40 - <year>2003-2004</year> 41 - <holder>David Brownell</holder> 42 - </copyright> 43 - 44 - <author> 45 - <firstname>David</firstname> 46 - <surname>Brownell</surname> 47 - <affiliation> 48 - <address><email>dbrownell@users.sourceforge.net</email></address> 49 - </affiliation> 50 - </author> 51 - </bookinfo> 52 - 53 - <toc></toc> 54 - 55 - <chapter id="intro"><title>Introduction</title> 56 - 57 - <para>This document presents a Linux-USB "Gadget" 58 - kernel mode 59 - API, for use within peripherals and other USB devices 60 - that embed Linux. 61 - It provides an overview of the API structure, 62 - and shows how that fits into a system development project. 63 - This is the first such API released on Linux to address 64 - a number of important problems, including: </para> 65 - 66 - <itemizedlist> 67 - <listitem><para>Supports USB 2.0, for high speed devices which 68 - can stream data at several dozen megabytes per second. 69 - </para></listitem> 70 - <listitem><para>Handles devices with dozens of endpoints just as 71 - well as ones with just two fixed-function ones. Gadget drivers 72 - can be written so they're easy to port to new hardware. 73 - </para></listitem> 74 - <listitem><para>Flexible enough to expose more complex USB device 75 - capabilities such as multiple configurations, multiple interfaces, 76 - composite devices, 77 - and alternate interface settings. 78 - </para></listitem> 79 - <listitem><para>USB "On-The-Go" (OTG) support, in conjunction 80 - with updates to the Linux-USB host side. 81 - </para></listitem> 82 - <listitem><para>Sharing data structures and API models with the 83 - Linux-USB host side API. This helps the OTG support, and 84 - looks forward to more-symmetric frameworks (where the same 85 - I/O model is used by both host and device side drivers). 86 - </para></listitem> 87 - <listitem><para>Minimalist, so it's easier to support new device 88 - controller hardware. I/O processing doesn't imply large 89 - demands for memory or CPU resources. 90 - </para></listitem> 91 - </itemizedlist> 92 - 93 - 94 - <para>Most Linux developers will not be able to use this API, since they 95 - have USB "host" hardware in a PC, workstation, or server. 96 - Linux users with embedded systems are more likely to 97 - have USB peripheral hardware. 98 - To distinguish drivers running inside such hardware from the 99 - more familiar Linux "USB device drivers", 100 - which are host side proxies for the real USB devices, 101 - a different term is used: 102 - the drivers inside the peripherals are "USB gadget drivers". 103 - In USB protocol interactions, the device driver is the master 104 - (or "client driver") 105 - and the gadget driver is the slave (or "function driver"). 106 - </para> 107 - 108 - <para>The gadget API resembles the host side Linux-USB API in that both 109 - use queues of request objects to package I/O buffers, and those requests 110 - may be submitted or canceled. 111 - They share common definitions for the standard USB 112 - <emphasis>Chapter 9</emphasis> messages, structures, and constants. 113 - Also, both APIs bind and unbind drivers to devices. 114 - The APIs differ in detail, since the host side's current 115 - URB framework exposes a number of implementation details 116 - and assumptions that are inappropriate for a gadget API. 117 - While the model for control transfers and configuration 118 - management is necessarily different (one side is a hardware-neutral master, 119 - the other is a hardware-aware slave), the endpoint I/0 API used here 120 - should also be usable for an overhead-reduced host side API. 121 - </para> 122 - 123 - </chapter> 124 - 125 - <chapter id="structure"><title>Structure of Gadget Drivers</title> 126 - 127 - <para>A system running inside a USB peripheral 128 - normally has at least three layers inside the kernel to handle 129 - USB protocol processing, and may have additional layers in 130 - user space code. 131 - The "gadget" API is used by the middle layer to interact 132 - with the lowest level (which directly handles hardware). 133 - </para> 134 - 135 - <para>In Linux, from the bottom up, these layers are: 136 - </para> 137 - 138 - <variablelist> 139 - 140 - <varlistentry> 141 - <term><emphasis>USB Controller Driver</emphasis></term> 142 - 143 - <listitem> 144 - <para>This is the lowest software level. 145 - It is the only layer that talks to hardware, 146 - through registers, fifos, dma, irqs, and the like. 147 - The <filename>&lt;linux/usb/gadget.h&gt;</filename> API abstracts 148 - the peripheral controller endpoint hardware. 149 - That hardware is exposed through endpoint objects, which accept 150 - streams of IN/OUT buffers, and through callbacks that interact 151 - with gadget drivers. 152 - Since normal USB devices only have one upstream 153 - port, they only have one of these drivers. 154 - The controller driver can support any number of different 155 - gadget drivers, but only one of them can be used at a time. 156 - </para> 157 - 158 - <para>Examples of such controller hardware include 159 - the PCI-based NetChip 2280 USB 2.0 high speed controller, 160 - the SA-11x0 or PXA-25x UDC (found within many PDAs), 161 - and a variety of other products. 162 - </para> 163 - 164 - </listitem></varlistentry> 165 - 166 - <varlistentry> 167 - <term><emphasis>Gadget Driver</emphasis></term> 168 - 169 - <listitem> 170 - <para>The lower boundary of this driver implements hardware-neutral 171 - USB functions, using calls to the controller driver. 172 - Because such hardware varies widely in capabilities and restrictions, 173 - and is used in embedded environments where space is at a premium, 174 - the gadget driver is often configured at compile time 175 - to work with endpoints supported by one particular controller. 176 - Gadget drivers may be portable to several different controllers, 177 - using conditional compilation. 178 - (Recent kernels substantially simplify the work involved in 179 - supporting new hardware, by <emphasis>autoconfiguring</emphasis> 180 - endpoints automatically for many bulk-oriented drivers.) 181 - Gadget driver responsibilities include: 182 - </para> 183 - <itemizedlist> 184 - <listitem><para>handling setup requests (ep0 protocol responses) 185 - possibly including class-specific functionality 186 - </para></listitem> 187 - <listitem><para>returning configuration and string descriptors 188 - </para></listitem> 189 - <listitem><para>(re)setting configurations and interface 190 - altsettings, including enabling and configuring endpoints 191 - </para></listitem> 192 - <listitem><para>handling life cycle events, such as managing 193 - bindings to hardware, 194 - USB suspend/resume, remote wakeup, 195 - and disconnection from the USB host. 196 - </para></listitem> 197 - <listitem><para>managing IN and OUT transfers on all currently 198 - enabled endpoints 199 - </para></listitem> 200 - </itemizedlist> 201 - 202 - <para> 203 - Such drivers may be modules of proprietary code, although 204 - that approach is discouraged in the Linux community. 205 - </para> 206 - </listitem></varlistentry> 207 - 208 - <varlistentry> 209 - <term><emphasis>Upper Level</emphasis></term> 210 - 211 - <listitem> 212 - <para>Most gadget drivers have an upper boundary that connects 213 - to some Linux driver or framework in Linux. 214 - Through that boundary flows the data which the gadget driver 215 - produces and/or consumes through protocol transfers over USB. 216 - Examples include: 217 - </para> 218 - <itemizedlist> 219 - <listitem><para>user mode code, using generic (gadgetfs) 220 - or application specific files in 221 - <filename>/dev</filename> 222 - </para></listitem> 223 - <listitem><para>networking subsystem (for network gadgets, 224 - like the CDC Ethernet Model gadget driver) 225 - </para></listitem> 226 - <listitem><para>data capture drivers, perhaps video4Linux or 227 - a scanner driver; or test and measurement hardware. 228 - </para></listitem> 229 - <listitem><para>input subsystem (for HID gadgets) 230 - </para></listitem> 231 - <listitem><para>sound subsystem (for audio gadgets) 232 - </para></listitem> 233 - <listitem><para>file system (for PTP gadgets) 234 - </para></listitem> 235 - <listitem><para>block i/o subsystem (for usb-storage gadgets) 236 - </para></listitem> 237 - <listitem><para>... and more </para></listitem> 238 - </itemizedlist> 239 - </listitem></varlistentry> 240 - 241 - <varlistentry> 242 - <term><emphasis>Additional Layers</emphasis></term> 243 - 244 - <listitem> 245 - <para>Other layers may exist. 246 - These could include kernel layers, such as network protocol stacks, 247 - as well as user mode applications building on standard POSIX 248 - system call APIs such as 249 - <emphasis>open()</emphasis>, <emphasis>close()</emphasis>, 250 - <emphasis>read()</emphasis> and <emphasis>write()</emphasis>. 251 - On newer systems, POSIX Async I/O calls may be an option. 252 - Such user mode code will not necessarily be subject to 253 - the GNU General Public License (GPL). 254 - </para> 255 - </listitem></varlistentry> 256 - 257 - 258 - </variablelist> 259 - 260 - <para>OTG-capable systems will also need to include a standard Linux-USB 261 - host side stack, 262 - with <emphasis>usbcore</emphasis>, 263 - one or more <emphasis>Host Controller Drivers</emphasis> (HCDs), 264 - <emphasis>USB Device Drivers</emphasis> to support 265 - the OTG "Targeted Peripheral List", 266 - and so forth. 267 - There will also be an <emphasis>OTG Controller Driver</emphasis>, 268 - which is visible to gadget and device driver developers only indirectly. 269 - That helps the host and device side USB controllers implement the 270 - two new OTG protocols (HNP and SRP). 271 - Roles switch (host to peripheral, or vice versa) using HNP 272 - during USB suspend processing, and SRP can be viewed as a 273 - more battery-friendly kind of device wakeup protocol. 274 - </para> 275 - 276 - <para>Over time, reusable utilities are evolving to help make some 277 - gadget driver tasks simpler. 278 - For example, building configuration descriptors from vectors of 279 - descriptors for the configurations interfaces and endpoints is 280 - now automated, and many drivers now use autoconfiguration to 281 - choose hardware endpoints and initialize their descriptors. 282 - 283 - A potential example of particular interest 284 - is code implementing standard USB-IF protocols for 285 - HID, networking, storage, or audio classes. 286 - Some developers are interested in KDB or KGDB hooks, to let 287 - target hardware be remotely debugged. 288 - Most such USB protocol code doesn't need to be hardware-specific, 289 - any more than network protocols like X11, HTTP, or NFS are. 290 - Such gadget-side interface drivers should eventually be combined, 291 - to implement composite devices. 292 - </para> 293 - 294 - </chapter> 295 - 296 - 297 - <chapter id="api"><title>Kernel Mode Gadget API</title> 298 - 299 - <para>Gadget drivers declare themselves through a 300 - <emphasis>struct usb_gadget_driver</emphasis>, which is responsible for 301 - most parts of enumeration for a <emphasis>struct usb_gadget</emphasis>. 302 - The response to a set_configuration usually involves 303 - enabling one or more of the <emphasis>struct usb_ep</emphasis> objects 304 - exposed by the gadget, and submitting one or more 305 - <emphasis>struct usb_request</emphasis> buffers to transfer data. 306 - Understand those four data types, and their operations, and 307 - you will understand how this API works. 308 - </para> 309 - 310 - <note><title>Incomplete Data Type Descriptions</title> 311 - 312 - <para>This documentation was prepared using the standard Linux 313 - kernel <filename>docproc</filename> tool, which turns text 314 - and in-code comments into SGML DocBook and then into usable 315 - formats such as HTML or PDF. 316 - Other than the "Chapter 9" data types, most of the significant 317 - data types and functions are described here. 318 - </para> 319 - 320 - <para>However, docproc does not understand all the C constructs 321 - that are used, so some relevant information is likely omitted from 322 - what you are reading. 323 - One example of such information is endpoint autoconfiguration. 324 - You'll have to read the header file, and use example source 325 - code (such as that for "Gadget Zero"), to fully understand the API. 326 - </para> 327 - 328 - <para>The part of the API implementing some basic 329 - driver capabilities is specific to the version of the 330 - Linux kernel that's in use. 331 - The 2.6 kernel includes a <emphasis>driver model</emphasis> 332 - framework that has no analogue on earlier kernels; 333 - so those parts of the gadget API are not fully portable. 334 - (They are implemented on 2.4 kernels, but in a different way.) 335 - The driver model state is another part of this API that is 336 - ignored by the kerneldoc tools. 337 - </para> 338 - </note> 339 - 340 - <para>The core API does not expose 341 - every possible hardware feature, only the most widely available ones. 342 - There are significant hardware features, such as device-to-device DMA 343 - (without temporary storage in a memory buffer) 344 - that would be added using hardware-specific APIs. 345 - </para> 346 - 347 - <para>This API allows drivers to use conditional compilation to handle 348 - endpoint capabilities of different hardware, but doesn't require that. 349 - Hardware tends to have arbitrary restrictions, relating to 350 - transfer types, addressing, packet sizes, buffering, and availability. 351 - As a rule, such differences only matter for "endpoint zero" logic 352 - that handles device configuration and management. 353 - The API supports limited run-time 354 - detection of capabilities, through naming conventions for endpoints. 355 - Many drivers will be able to at least partially autoconfigure 356 - themselves. 357 - In particular, driver init sections will often have endpoint 358 - autoconfiguration logic that scans the hardware's list of endpoints 359 - to find ones matching the driver requirements 360 - (relying on those conventions), to eliminate some of the most 361 - common reasons for conditional compilation. 362 - </para> 363 - 364 - <para>Like the Linux-USB host side API, this API exposes 365 - the "chunky" nature of USB messages: I/O requests are in terms 366 - of one or more "packets", and packet boundaries are visible to drivers. 367 - Compared to RS-232 serial protocols, USB resembles 368 - synchronous protocols like HDLC 369 - (N bytes per frame, multipoint addressing, host as the primary 370 - station and devices as secondary stations) 371 - more than asynchronous ones 372 - (tty style: 8 data bits per frame, no parity, one stop bit). 373 - So for example the controller drivers won't buffer 374 - two single byte writes into a single two-byte USB IN packet, 375 - although gadget drivers may do so when they implement 376 - protocols where packet boundaries (and "short packets") 377 - are not significant. 378 - </para> 379 - 380 - <sect1 id="lifecycle"><title>Driver Life Cycle</title> 381 - 382 - <para>Gadget drivers make endpoint I/O requests to hardware without 383 - needing to know many details of the hardware, but driver 384 - setup/configuration code needs to handle some differences. 385 - Use the API like this: 386 - </para> 387 - 388 - <orderedlist numeration='arabic'> 389 - 390 - <listitem><para>Register a driver for the particular device side 391 - usb controller hardware, 392 - such as the net2280 on PCI (USB 2.0), 393 - sa11x0 or pxa25x as found in Linux PDAs, 394 - and so on. 395 - At this point the device is logically in the USB ch9 initial state 396 - ("attached"), drawing no power and not usable 397 - (since it does not yet support enumeration). 398 - Any host should not see the device, since it's not 399 - activated the data line pullup used by the host to 400 - detect a device, even if VBUS power is available. 401 - </para></listitem> 402 - 403 - <listitem><para>Register a gadget driver that implements some higher level 404 - device function. That will then bind() to a usb_gadget, which 405 - activates the data line pullup sometime after detecting VBUS. 406 - </para></listitem> 407 - 408 - <listitem><para>The hardware driver can now start enumerating. 409 - The steps it handles are to accept USB power and set_address requests. 410 - Other steps are handled by the gadget driver. 411 - If the gadget driver module is unloaded before the host starts to 412 - enumerate, steps before step 7 are skipped. 413 - </para></listitem> 414 - 415 - <listitem><para>The gadget driver's setup() call returns usb descriptors, 416 - based both on what the bus interface hardware provides and on the 417 - functionality being implemented. 418 - That can involve alternate settings or configurations, 419 - unless the hardware prevents such operation. 420 - For OTG devices, each configuration descriptor includes 421 - an OTG descriptor. 422 - </para></listitem> 423 - 424 - <listitem><para>The gadget driver handles the last step of enumeration, 425 - when the USB host issues a set_configuration call. 426 - It enables all endpoints used in that configuration, 427 - with all interfaces in their default settings. 428 - That involves using a list of the hardware's endpoints, enabling each 429 - endpoint according to its descriptor. 430 - It may also involve using <function>usb_gadget_vbus_draw</function> 431 - to let more power be drawn from VBUS, as allowed by that configuration. 432 - For OTG devices, setting a configuration may also involve reporting 433 - HNP capabilities through a user interface. 434 - </para></listitem> 435 - 436 - <listitem><para>Do real work and perform data transfers, possibly involving 437 - changes to interface settings or switching to new configurations, until the 438 - device is disconnect()ed from the host. 439 - Queue any number of transfer requests to each endpoint. 440 - It may be suspended and resumed several times before being disconnected. 441 - On disconnect, the drivers go back to step 3 (above). 442 - </para></listitem> 443 - 444 - <listitem><para>When the gadget driver module is being unloaded, 445 - the driver unbind() callback is issued. That lets the controller 446 - driver be unloaded. 447 - </para></listitem> 448 - 449 - </orderedlist> 450 - 451 - <para>Drivers will normally be arranged so that just loading the 452 - gadget driver module (or statically linking it into a Linux kernel) 453 - allows the peripheral device to be enumerated, but some drivers 454 - will defer enumeration until some higher level component (like 455 - a user mode daemon) enables it. 456 - Note that at this lowest level there are no policies about how 457 - ep0 configuration logic is implemented, 458 - except that it should obey USB specifications. 459 - Such issues are in the domain of gadget drivers, 460 - including knowing about implementation constraints 461 - imposed by some USB controllers 462 - or understanding that composite devices might happen to 463 - be built by integrating reusable components. 464 - </para> 465 - 466 - <para>Note that the lifecycle above can be slightly different 467 - for OTG devices. 468 - Other than providing an additional OTG descriptor in each 469 - configuration, only the HNP-related differences are particularly 470 - visible to driver code. 471 - They involve reporting requirements during the SET_CONFIGURATION 472 - request, and the option to invoke HNP during some suspend callbacks. 473 - Also, SRP changes the semantics of 474 - <function>usb_gadget_wakeup</function> 475 - slightly. 476 - </para> 477 - 478 - </sect1> 479 - 480 - <sect1 id="ch9"><title>USB 2.0 Chapter 9 Types and Constants</title> 481 - 482 - <para>Gadget drivers 483 - rely on common USB structures and constants 484 - defined in the 485 - <filename>&lt;linux/usb/ch9.h&gt;</filename> 486 - header file, which is standard in Linux 2.6 kernels. 487 - These are the same types and constants used by host 488 - side drivers (and usbcore). 489 - </para> 490 - 491 - !Iinclude/linux/usb/ch9.h 492 - </sect1> 493 - 494 - <sect1 id="core"><title>Core Objects and Methods</title> 495 - 496 - <para>These are declared in 497 - <filename>&lt;linux/usb/gadget.h&gt;</filename>, 498 - and are used by gadget drivers to interact with 499 - USB peripheral controller drivers. 500 - </para> 501 - 502 - <!-- yeech, this is ugly in nsgmls PDF output. 503 - 504 - the PDF bookmark and refentry output nesting is wrong, 505 - and the member/argument documentation indents ugly. 506 - 507 - plus something (docproc?) adds whitespace before the 508 - descriptive paragraph text, so it can't line up right 509 - unless the explanations are trivial. 510 - --> 511 - 512 - !Iinclude/linux/usb/gadget.h 513 - </sect1> 514 - 515 - <sect1 id="utils"><title>Optional Utilities</title> 516 - 517 - <para>The core API is sufficient for writing a USB Gadget Driver, 518 - but some optional utilities are provided to simplify common tasks. 519 - These utilities include endpoint autoconfiguration. 520 - </para> 521 - 522 - !Edrivers/usb/gadget/usbstring.c 523 - !Edrivers/usb/gadget/config.c 524 - <!-- !Edrivers/usb/gadget/epautoconf.c --> 525 - </sect1> 526 - 527 - <sect1 id="composite"><title>Composite Device Framework</title> 528 - 529 - <para>The core API is sufficient for writing drivers for composite 530 - USB devices (with more than one function in a given configuration), 531 - and also multi-configuration devices (also more than one function, 532 - but not necessarily sharing a given configuration). 533 - There is however an optional framework which makes it easier to 534 - reuse and combine functions. 535 - </para> 536 - 537 - <para>Devices using this framework provide a <emphasis>struct 538 - usb_composite_driver</emphasis>, which in turn provides one or 539 - more <emphasis>struct usb_configuration</emphasis> instances. 540 - Each such configuration includes at least one 541 - <emphasis>struct usb_function</emphasis>, which packages a user 542 - visible role such as "network link" or "mass storage device". 543 - Management functions may also exist, such as "Device Firmware 544 - Upgrade". 545 - </para> 546 - 547 - !Iinclude/linux/usb/composite.h 548 - !Edrivers/usb/gadget/composite.c 549 - 550 - </sect1> 551 - 552 - <sect1 id="functions"><title>Composite Device Functions</title> 553 - 554 - <para>At this writing, a few of the current gadget drivers have 555 - been converted to this framework. 556 - Near-term plans include converting all of them, except for "gadgetfs". 557 - </para> 558 - 559 - !Edrivers/usb/gadget/function/f_acm.c 560 - !Edrivers/usb/gadget/function/f_ecm.c 561 - !Edrivers/usb/gadget/function/f_subset.c 562 - !Edrivers/usb/gadget/function/f_obex.c 563 - !Edrivers/usb/gadget/function/f_serial.c 564 - 565 - </sect1> 566 - 567 - 568 - </chapter> 569 - 570 - <chapter id="controllers"><title>Peripheral Controller Drivers</title> 571 - 572 - <para>The first hardware supporting this API was the NetChip 2280 573 - controller, which supports USB 2.0 high speed and is based on PCI. 574 - This is the <filename>net2280</filename> driver module. 575 - The driver supports Linux kernel versions 2.4 and 2.6; 576 - contact NetChip Technologies for development boards and product 577 - information. 578 - </para> 579 - 580 - <para>Other hardware working in the "gadget" framework includes: 581 - Intel's PXA 25x and IXP42x series processors 582 - (<filename>pxa2xx_udc</filename>), 583 - Toshiba TC86c001 "Goku-S" (<filename>goku_udc</filename>), 584 - Renesas SH7705/7727 (<filename>sh_udc</filename>), 585 - MediaQ 11xx (<filename>mq11xx_udc</filename>), 586 - Hynix HMS30C7202 (<filename>h7202_udc</filename>), 587 - National 9303/4 (<filename>n9604_udc</filename>), 588 - Texas Instruments OMAP (<filename>omap_udc</filename>), 589 - Sharp LH7A40x (<filename>lh7a40x_udc</filename>), 590 - and more. 591 - Most of those are full speed controllers. 592 - </para> 593 - 594 - <para>At this writing, there are people at work on drivers in 595 - this framework for several other USB device controllers, 596 - with plans to make many of them be widely available. 597 - </para> 598 - 599 - <!-- !Edrivers/usb/gadget/net2280.c --> 600 - 601 - <para>A partial USB simulator, 602 - the <filename>dummy_hcd</filename> driver, is available. 603 - It can act like a net2280, a pxa25x, or an sa11x0 in terms 604 - of available endpoints and device speeds; and it simulates 605 - control, bulk, and to some extent interrupt transfers. 606 - That lets you develop some parts of a gadget driver on a normal PC, 607 - without any special hardware, and perhaps with the assistance 608 - of tools such as GDB running with User Mode Linux. 609 - At least one person has expressed interest in adapting that 610 - approach, hooking it up to a simulator for a microcontroller. 611 - Such simulators can help debug subsystems where the runtime hardware 612 - is unfriendly to software development, or is not yet available. 613 - </para> 614 - 615 - <para>Support for other controllers is expected to be developed 616 - and contributed 617 - over time, as this driver framework evolves. 618 - </para> 619 - 620 - </chapter> 621 - 622 - <chapter id="gadget"><title>Gadget Drivers</title> 623 - 624 - <para>In addition to <emphasis>Gadget Zero</emphasis> 625 - (used primarily for testing and development with drivers 626 - for usb controller hardware), other gadget drivers exist. 627 - </para> 628 - 629 - <para>There's an <emphasis>ethernet</emphasis> gadget 630 - driver, which implements one of the most useful 631 - <emphasis>Communications Device Class</emphasis> (CDC) models. 632 - One of the standards for cable modem interoperability even 633 - specifies the use of this ethernet model as one of two 634 - mandatory options. 635 - Gadgets using this code look to a USB host as if they're 636 - an Ethernet adapter. 637 - It provides access to a network where the gadget's CPU is one host, 638 - which could easily be bridging, routing, or firewalling 639 - access to other networks. 640 - Since some hardware can't fully implement the CDC Ethernet 641 - requirements, this driver also implements a "good parts only" 642 - subset of CDC Ethernet. 643 - (That subset doesn't advertise itself as CDC Ethernet, 644 - to avoid creating problems.) 645 - </para> 646 - 647 - <para>Support for Microsoft's <emphasis>RNDIS</emphasis> 648 - protocol has been contributed by Pengutronix and Auerswald GmbH. 649 - This is like CDC Ethernet, but it runs on more slightly USB hardware 650 - (but less than the CDC subset). 651 - However, its main claim to fame is being able to connect directly to 652 - recent versions of Windows, using drivers that Microsoft bundles 653 - and supports, making it much simpler to network with Windows. 654 - </para> 655 - 656 - <para>There is also support for user mode gadget drivers, 657 - using <emphasis>gadgetfs</emphasis>. 658 - This provides a <emphasis>User Mode API</emphasis> that presents 659 - each endpoint as a single file descriptor. I/O is done using 660 - normal <emphasis>read()</emphasis> and <emphasis>read()</emphasis> calls. 661 - Familiar tools like GDB and pthreads can be used to 662 - develop and debug user mode drivers, so that once a robust 663 - controller driver is available many applications for it 664 - won't require new kernel mode software. 665 - Linux 2.6 <emphasis>Async I/O (AIO)</emphasis> 666 - support is available, so that user mode software 667 - can stream data with only slightly more overhead 668 - than a kernel driver. 669 - </para> 670 - 671 - <para>There's a USB Mass Storage class driver, which provides 672 - a different solution for interoperability with systems such 673 - as MS-Windows and MacOS. 674 - That <emphasis>Mass Storage</emphasis> driver uses a 675 - file or block device as backing store for a drive, 676 - like the <filename>loop</filename> driver. 677 - The USB host uses the BBB, CB, or CBI versions of the mass 678 - storage class specification, using transparent SCSI commands 679 - to access the data from the backing store. 680 - </para> 681 - 682 - <para>There's a "serial line" driver, useful for TTY style 683 - operation over USB. 684 - The latest version of that driver supports CDC ACM style 685 - operation, like a USB modem, and so on most hardware it can 686 - interoperate easily with MS-Windows. 687 - One interesting use of that driver is in boot firmware (like a BIOS), 688 - which can sometimes use that model with very small systems without 689 - real serial lines. 690 - </para> 691 - 692 - <para>Support for other kinds of gadget is expected to 693 - be developed and contributed 694 - over time, as this driver framework evolves. 695 - </para> 696 - 697 - </chapter> 698 - 699 - <chapter id="otg"><title>USB On-The-GO (OTG)</title> 700 - 701 - <para>USB OTG support on Linux 2.6 was initially developed 702 - by Texas Instruments for 703 - <ulink url="http://www.omap.com">OMAP</ulink> 16xx and 17xx 704 - series processors. 705 - Other OTG systems should work in similar ways, but the 706 - hardware level details could be very different. 707 - </para> 708 - 709 - <para>Systems need specialized hardware support to implement OTG, 710 - notably including a special <emphasis>Mini-AB</emphasis> jack 711 - and associated transceiver to support <emphasis>Dual-Role</emphasis> 712 - operation: 713 - they can act either as a host, using the standard 714 - Linux-USB host side driver stack, 715 - or as a peripheral, using this "gadget" framework. 716 - To do that, the system software relies on small additions 717 - to those programming interfaces, 718 - and on a new internal component (here called an "OTG Controller") 719 - affecting which driver stack connects to the OTG port. 720 - In each role, the system can re-use the existing pool of 721 - hardware-neutral drivers, layered on top of the controller 722 - driver interfaces (<emphasis>usb_bus</emphasis> or 723 - <emphasis>usb_gadget</emphasis>). 724 - Such drivers need at most minor changes, and most of the calls 725 - added to support OTG can also benefit non-OTG products. 726 - </para> 727 - 728 - <itemizedlist> 729 - <listitem><para>Gadget drivers test the <emphasis>is_otg</emphasis> 730 - flag, and use it to determine whether or not to include 731 - an OTG descriptor in each of their configurations. 732 - </para></listitem> 733 - <listitem><para>Gadget drivers may need changes to support the 734 - two new OTG protocols, exposed in new gadget attributes 735 - such as <emphasis>b_hnp_enable</emphasis> flag. 736 - HNP support should be reported through a user interface 737 - (two LEDs could suffice), and is triggered in some cases 738 - when the host suspends the peripheral. 739 - SRP support can be user-initiated just like remote wakeup, 740 - probably by pressing the same button. 741 - </para></listitem> 742 - <listitem><para>On the host side, USB device drivers need 743 - to be taught to trigger HNP at appropriate moments, using 744 - <function>usb_suspend_device()</function>. 745 - That also conserves battery power, which is useful even 746 - for non-OTG configurations. 747 - </para></listitem> 748 - <listitem><para>Also on the host side, a driver must support the 749 - OTG "Targeted Peripheral List". That's just a whitelist, 750 - used to reject peripherals not supported with a given 751 - Linux OTG host. 752 - <emphasis>This whitelist is product-specific; 753 - each product must modify <filename>otg_whitelist.h</filename> 754 - to match its interoperability specification. 755 - </emphasis> 756 - </para> 757 - <para>Non-OTG Linux hosts, like PCs and workstations, 758 - normally have some solution for adding drivers, so that 759 - peripherals that aren't recognized can eventually be supported. 760 - That approach is unreasonable for consumer products that may 761 - never have their firmware upgraded, and where it's usually 762 - unrealistic to expect traditional PC/workstation/server kinds 763 - of support model to work. 764 - For example, it's often impractical to change device firmware 765 - once the product has been distributed, so driver bugs can't 766 - normally be fixed if they're found after shipment. 767 - </para></listitem> 768 - </itemizedlist> 769 - 770 - <para> 771 - Additional changes are needed below those hardware-neutral 772 - <emphasis>usb_bus</emphasis> and <emphasis>usb_gadget</emphasis> 773 - driver interfaces; those aren't discussed here in any detail. 774 - Those affect the hardware-specific code for each USB Host or Peripheral 775 - controller, and how the HCD initializes (since OTG can be active only 776 - on a single port). 777 - They also involve what may be called an <emphasis>OTG Controller 778 - Driver</emphasis>, managing the OTG transceiver and the OTG state 779 - machine logic as well as much of the root hub behavior for the 780 - OTG port. 781 - The OTG controller driver needs to activate and deactivate USB 782 - controllers depending on the relevant device role. 783 - Some related changes were needed inside usbcore, so that it 784 - can identify OTG-capable devices and respond appropriately 785 - to HNP or SRP protocols. 786 - </para> 787 - 788 - </chapter> 789 - 790 - </book> 791 - <!-- 792 - vim:syntax=sgml:sw=4 793 - -->
-520
Documentation/DocBook/genericirq.tmpl
··· 1 - <?xml version="1.0" encoding="UTF-8"?> 2 - <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" 3 - "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" []> 4 - 5 - <book id="Generic-IRQ-Guide"> 6 - <bookinfo> 7 - <title>Linux generic IRQ handling</title> 8 - 9 - <authorgroup> 10 - <author> 11 - <firstname>Thomas</firstname> 12 - <surname>Gleixner</surname> 13 - <affiliation> 14 - <address> 15 - <email>tglx@linutronix.de</email> 16 - </address> 17 - </affiliation> 18 - </author> 19 - <author> 20 - <firstname>Ingo</firstname> 21 - <surname>Molnar</surname> 22 - <affiliation> 23 - <address> 24 - <email>mingo@elte.hu</email> 25 - </address> 26 - </affiliation> 27 - </author> 28 - </authorgroup> 29 - 30 - <copyright> 31 - <year>2005-2010</year> 32 - <holder>Thomas Gleixner</holder> 33 - </copyright> 34 - <copyright> 35 - <year>2005-2006</year> 36 - <holder>Ingo Molnar</holder> 37 - </copyright> 38 - 39 - <legalnotice> 40 - <para> 41 - This documentation is free software; you can redistribute 42 - it and/or modify it under the terms of the GNU General Public 43 - License version 2 as published by the Free Software Foundation. 44 - </para> 45 - 46 - <para> 47 - This program is distributed in the hope that it will be 48 - useful, but WITHOUT ANY WARRANTY; without even the implied 49 - warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 50 - See the GNU General Public License for more details. 51 - </para> 52 - 53 - <para> 54 - You should have received a copy of the GNU General Public 55 - License along with this program; if not, write to the Free 56 - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, 57 - MA 02111-1307 USA 58 - </para> 59 - 60 - <para> 61 - For more details see the file COPYING in the source 62 - distribution of Linux. 63 - </para> 64 - </legalnotice> 65 - </bookinfo> 66 - 67 - <toc></toc> 68 - 69 - <chapter id="intro"> 70 - <title>Introduction</title> 71 - <para> 72 - The generic interrupt handling layer is designed to provide a 73 - complete abstraction of interrupt handling for device drivers. 74 - It is able to handle all the different types of interrupt controller 75 - hardware. Device drivers use generic API functions to request, enable, 76 - disable and free interrupts. The drivers do not have to know anything 77 - about interrupt hardware details, so they can be used on different 78 - platforms without code changes. 79 - </para> 80 - <para> 81 - This documentation is provided to developers who want to implement 82 - an interrupt subsystem based for their architecture, with the help 83 - of the generic IRQ handling layer. 84 - </para> 85 - </chapter> 86 - 87 - <chapter id="rationale"> 88 - <title>Rationale</title> 89 - <para> 90 - The original implementation of interrupt handling in Linux uses 91 - the __do_IRQ() super-handler, which is able to deal with every 92 - type of interrupt logic. 93 - </para> 94 - <para> 95 - Originally, Russell King identified different types of handlers to 96 - build a quite universal set for the ARM interrupt handler 97 - implementation in Linux 2.5/2.6. He distinguished between: 98 - <itemizedlist> 99 - <listitem><para>Level type</para></listitem> 100 - <listitem><para>Edge type</para></listitem> 101 - <listitem><para>Simple type</para></listitem> 102 - </itemizedlist> 103 - During the implementation we identified another type: 104 - <itemizedlist> 105 - <listitem><para>Fast EOI type</para></listitem> 106 - </itemizedlist> 107 - In the SMP world of the __do_IRQ() super-handler another type 108 - was identified: 109 - <itemizedlist> 110 - <listitem><para>Per CPU type</para></listitem> 111 - </itemizedlist> 112 - </para> 113 - <para> 114 - This split implementation of high-level IRQ handlers allows us to 115 - optimize the flow of the interrupt handling for each specific 116 - interrupt type. This reduces complexity in that particular code path 117 - and allows the optimized handling of a given type. 118 - </para> 119 - <para> 120 - The original general IRQ implementation used hw_interrupt_type 121 - structures and their ->ack(), ->end() [etc.] callbacks to 122 - differentiate the flow control in the super-handler. This leads to 123 - a mix of flow logic and low-level hardware logic, and it also leads 124 - to unnecessary code duplication: for example in i386, there is an 125 - ioapic_level_irq and an ioapic_edge_irq IRQ-type which share many 126 - of the low-level details but have different flow handling. 127 - </para> 128 - <para> 129 - A more natural abstraction is the clean separation of the 130 - 'irq flow' and the 'chip details'. 131 - </para> 132 - <para> 133 - Analysing a couple of architecture's IRQ subsystem implementations 134 - reveals that most of them can use a generic set of 'irq flow' 135 - methods and only need to add the chip-level specific code. 136 - The separation is also valuable for (sub)architectures 137 - which need specific quirks in the IRQ flow itself but not in the 138 - chip details - and thus provides a more transparent IRQ subsystem 139 - design. 140 - </para> 141 - <para> 142 - Each interrupt descriptor is assigned its own high-level flow 143 - handler, which is normally one of the generic 144 - implementations. (This high-level flow handler implementation also 145 - makes it simple to provide demultiplexing handlers which can be 146 - found in embedded platforms on various architectures.) 147 - </para> 148 - <para> 149 - The separation makes the generic interrupt handling layer more 150 - flexible and extensible. For example, an (sub)architecture can 151 - use a generic IRQ-flow implementation for 'level type' interrupts 152 - and add a (sub)architecture specific 'edge type' implementation. 153 - </para> 154 - <para> 155 - To make the transition to the new model easier and prevent the 156 - breakage of existing implementations, the __do_IRQ() super-handler 157 - is still available. This leads to a kind of duality for the time 158 - being. Over time the new model should be used in more and more 159 - architectures, as it enables smaller and cleaner IRQ subsystems. 160 - It's deprecated for three years now and about to be removed. 161 - </para> 162 - </chapter> 163 - <chapter id="bugs"> 164 - <title>Known Bugs And Assumptions</title> 165 - <para> 166 - None (knock on wood). 167 - </para> 168 - </chapter> 169 - 170 - <chapter id="Abstraction"> 171 - <title>Abstraction layers</title> 172 - <para> 173 - There are three main levels of abstraction in the interrupt code: 174 - <orderedlist> 175 - <listitem><para>High-level driver API</para></listitem> 176 - <listitem><para>High-level IRQ flow handlers</para></listitem> 177 - <listitem><para>Chip-level hardware encapsulation</para></listitem> 178 - </orderedlist> 179 - </para> 180 - <sect1 id="Interrupt_control_flow"> 181 - <title>Interrupt control flow</title> 182 - <para> 183 - Each interrupt is described by an interrupt descriptor structure 184 - irq_desc. The interrupt is referenced by an 'unsigned int' numeric 185 - value which selects the corresponding interrupt description structure 186 - in the descriptor structures array. 187 - The descriptor structure contains status information and pointers 188 - to the interrupt flow method and the interrupt chip structure 189 - which are assigned to this interrupt. 190 - </para> 191 - <para> 192 - Whenever an interrupt triggers, the low-level architecture code calls 193 - into the generic interrupt code by calling desc->handle_irq(). 194 - This high-level IRQ handling function only uses desc->irq_data.chip 195 - primitives referenced by the assigned chip descriptor structure. 196 - </para> 197 - </sect1> 198 - <sect1 id="Highlevel_Driver_API"> 199 - <title>High-level Driver API</title> 200 - <para> 201 - The high-level Driver API consists of following functions: 202 - <itemizedlist> 203 - <listitem><para>request_irq()</para></listitem> 204 - <listitem><para>free_irq()</para></listitem> 205 - <listitem><para>disable_irq()</para></listitem> 206 - <listitem><para>enable_irq()</para></listitem> 207 - <listitem><para>disable_irq_nosync() (SMP only)</para></listitem> 208 - <listitem><para>synchronize_irq() (SMP only)</para></listitem> 209 - <listitem><para>irq_set_irq_type()</para></listitem> 210 - <listitem><para>irq_set_irq_wake()</para></listitem> 211 - <listitem><para>irq_set_handler_data()</para></listitem> 212 - <listitem><para>irq_set_chip()</para></listitem> 213 - <listitem><para>irq_set_chip_data()</para></listitem> 214 - </itemizedlist> 215 - See the autogenerated function documentation for details. 216 - </para> 217 - </sect1> 218 - <sect1 id="Highlevel_IRQ_flow_handlers"> 219 - <title>High-level IRQ flow handlers</title> 220 - <para> 221 - The generic layer provides a set of pre-defined irq-flow methods: 222 - <itemizedlist> 223 - <listitem><para>handle_level_irq</para></listitem> 224 - <listitem><para>handle_edge_irq</para></listitem> 225 - <listitem><para>handle_fasteoi_irq</para></listitem> 226 - <listitem><para>handle_simple_irq</para></listitem> 227 - <listitem><para>handle_percpu_irq</para></listitem> 228 - <listitem><para>handle_edge_eoi_irq</para></listitem> 229 - <listitem><para>handle_bad_irq</para></listitem> 230 - </itemizedlist> 231 - The interrupt flow handlers (either pre-defined or architecture 232 - specific) are assigned to specific interrupts by the architecture 233 - either during bootup or during device initialization. 234 - </para> 235 - <sect2 id="Default_flow_implementations"> 236 - <title>Default flow implementations</title> 237 - <sect3 id="Helper_functions"> 238 - <title>Helper functions</title> 239 - <para> 240 - The helper functions call the chip primitives and 241 - are used by the default flow implementations. 242 - The following helper functions are implemented (simplified excerpt): 243 - <programlisting> 244 - default_enable(struct irq_data *data) 245 - { 246 - desc->irq_data.chip->irq_unmask(data); 247 - } 248 - 249 - default_disable(struct irq_data *data) 250 - { 251 - if (!delay_disable(data)) 252 - desc->irq_data.chip->irq_mask(data); 253 - } 254 - 255 - default_ack(struct irq_data *data) 256 - { 257 - chip->irq_ack(data); 258 - } 259 - 260 - default_mask_ack(struct irq_data *data) 261 - { 262 - if (chip->irq_mask_ack) { 263 - chip->irq_mask_ack(data); 264 - } else { 265 - chip->irq_mask(data); 266 - chip->irq_ack(data); 267 - } 268 - } 269 - 270 - noop(struct irq_data *data)) 271 - { 272 - } 273 - 274 - </programlisting> 275 - </para> 276 - </sect3> 277 - </sect2> 278 - <sect2 id="Default_flow_handler_implementations"> 279 - <title>Default flow handler implementations</title> 280 - <sect3 id="Default_Level_IRQ_flow_handler"> 281 - <title>Default Level IRQ flow handler</title> 282 - <para> 283 - handle_level_irq provides a generic implementation 284 - for level-triggered interrupts. 285 - </para> 286 - <para> 287 - The following control flow is implemented (simplified excerpt): 288 - <programlisting> 289 - desc->irq_data.chip->irq_mask_ack(); 290 - handle_irq_event(desc->action); 291 - desc->irq_data.chip->irq_unmask(); 292 - </programlisting> 293 - </para> 294 - </sect3> 295 - <sect3 id="Default_FASTEOI_IRQ_flow_handler"> 296 - <title>Default Fast EOI IRQ flow handler</title> 297 - <para> 298 - handle_fasteoi_irq provides a generic implementation 299 - for interrupts, which only need an EOI at the end of 300 - the handler. 301 - </para> 302 - <para> 303 - The following control flow is implemented (simplified excerpt): 304 - <programlisting> 305 - handle_irq_event(desc->action); 306 - desc->irq_data.chip->irq_eoi(); 307 - </programlisting> 308 - </para> 309 - </sect3> 310 - <sect3 id="Default_Edge_IRQ_flow_handler"> 311 - <title>Default Edge IRQ flow handler</title> 312 - <para> 313 - handle_edge_irq provides a generic implementation 314 - for edge-triggered interrupts. 315 - </para> 316 - <para> 317 - The following control flow is implemented (simplified excerpt): 318 - <programlisting> 319 - if (desc->status &amp; running) { 320 - desc->irq_data.chip->irq_mask_ack(); 321 - desc->status |= pending | masked; 322 - return; 323 - } 324 - desc->irq_data.chip->irq_ack(); 325 - desc->status |= running; 326 - do { 327 - if (desc->status &amp; masked) 328 - desc->irq_data.chip->irq_unmask(); 329 - desc->status &amp;= ~pending; 330 - handle_irq_event(desc->action); 331 - } while (status &amp; pending); 332 - desc->status &amp;= ~running; 333 - </programlisting> 334 - </para> 335 - </sect3> 336 - <sect3 id="Default_simple_IRQ_flow_handler"> 337 - <title>Default simple IRQ flow handler</title> 338 - <para> 339 - handle_simple_irq provides a generic implementation 340 - for simple interrupts. 341 - </para> 342 - <para> 343 - Note: The simple flow handler does not call any 344 - handler/chip primitives. 345 - </para> 346 - <para> 347 - The following control flow is implemented (simplified excerpt): 348 - <programlisting> 349 - handle_irq_event(desc->action); 350 - </programlisting> 351 - </para> 352 - </sect3> 353 - <sect3 id="Default_per_CPU_flow_handler"> 354 - <title>Default per CPU flow handler</title> 355 - <para> 356 - handle_percpu_irq provides a generic implementation 357 - for per CPU interrupts. 358 - </para> 359 - <para> 360 - Per CPU interrupts are only available on SMP and 361 - the handler provides a simplified version without 362 - locking. 363 - </para> 364 - <para> 365 - The following control flow is implemented (simplified excerpt): 366 - <programlisting> 367 - if (desc->irq_data.chip->irq_ack) 368 - desc->irq_data.chip->irq_ack(); 369 - handle_irq_event(desc->action); 370 - if (desc->irq_data.chip->irq_eoi) 371 - desc->irq_data.chip->irq_eoi(); 372 - </programlisting> 373 - </para> 374 - </sect3> 375 - <sect3 id="EOI_Edge_IRQ_flow_handler"> 376 - <title>EOI Edge IRQ flow handler</title> 377 - <para> 378 - handle_edge_eoi_irq provides an abnomination of the edge 379 - handler which is solely used to tame a badly wreckaged 380 - irq controller on powerpc/cell. 381 - </para> 382 - </sect3> 383 - <sect3 id="BAD_IRQ_flow_handler"> 384 - <title>Bad IRQ flow handler</title> 385 - <para> 386 - handle_bad_irq is used for spurious interrupts which 387 - have no real handler assigned.. 388 - </para> 389 - </sect3> 390 - </sect2> 391 - <sect2 id="Quirks_and_optimizations"> 392 - <title>Quirks and optimizations</title> 393 - <para> 394 - The generic functions are intended for 'clean' architectures and chips, 395 - which have no platform-specific IRQ handling quirks. If an architecture 396 - needs to implement quirks on the 'flow' level then it can do so by 397 - overriding the high-level irq-flow handler. 398 - </para> 399 - </sect2> 400 - <sect2 id="Delayed_interrupt_disable"> 401 - <title>Delayed interrupt disable</title> 402 - <para> 403 - This per interrupt selectable feature, which was introduced by Russell 404 - King in the ARM interrupt implementation, does not mask an interrupt 405 - at the hardware level when disable_irq() is called. The interrupt is 406 - kept enabled and is masked in the flow handler when an interrupt event 407 - happens. This prevents losing edge interrupts on hardware which does 408 - not store an edge interrupt event while the interrupt is disabled at 409 - the hardware level. When an interrupt arrives while the IRQ_DISABLED 410 - flag is set, then the interrupt is masked at the hardware level and 411 - the IRQ_PENDING bit is set. When the interrupt is re-enabled by 412 - enable_irq() the pending bit is checked and if it is set, the 413 - interrupt is resent either via hardware or by a software resend 414 - mechanism. (It's necessary to enable CONFIG_HARDIRQS_SW_RESEND when 415 - you want to use the delayed interrupt disable feature and your 416 - hardware is not capable of retriggering an interrupt.) 417 - The delayed interrupt disable is not configurable. 418 - </para> 419 - </sect2> 420 - </sect1> 421 - <sect1 id="Chiplevel_hardware_encapsulation"> 422 - <title>Chip-level hardware encapsulation</title> 423 - <para> 424 - The chip-level hardware descriptor structure irq_chip 425 - contains all the direct chip relevant functions, which 426 - can be utilized by the irq flow implementations. 427 - <itemizedlist> 428 - <listitem><para>irq_ack()</para></listitem> 429 - <listitem><para>irq_mask_ack() - Optional, recommended for performance</para></listitem> 430 - <listitem><para>irq_mask()</para></listitem> 431 - <listitem><para>irq_unmask()</para></listitem> 432 - <listitem><para>irq_eoi() - Optional, required for EOI flow handlers</para></listitem> 433 - <listitem><para>irq_retrigger() - Optional</para></listitem> 434 - <listitem><para>irq_set_type() - Optional</para></listitem> 435 - <listitem><para>irq_set_wake() - Optional</para></listitem> 436 - </itemizedlist> 437 - These primitives are strictly intended to mean what they say: ack means 438 - ACK, masking means masking of an IRQ line, etc. It is up to the flow 439 - handler(s) to use these basic units of low-level functionality. 440 - </para> 441 - </sect1> 442 - </chapter> 443 - 444 - <chapter id="doirq"> 445 - <title>__do_IRQ entry point</title> 446 - <para> 447 - The original implementation __do_IRQ() was an alternative entry 448 - point for all types of interrupts. It no longer exists. 449 - </para> 450 - <para> 451 - This handler turned out to be not suitable for all 452 - interrupt hardware and was therefore reimplemented with split 453 - functionality for edge/level/simple/percpu interrupts. This is not 454 - only a functional optimization. It also shortens code paths for 455 - interrupts. 456 - </para> 457 - </chapter> 458 - 459 - <chapter id="locking"> 460 - <title>Locking on SMP</title> 461 - <para> 462 - The locking of chip registers is up to the architecture that 463 - defines the chip primitives. The per-irq structure is 464 - protected via desc->lock, by the generic layer. 465 - </para> 466 - </chapter> 467 - 468 - <chapter id="genericchip"> 469 - <title>Generic interrupt chip</title> 470 - <para> 471 - To avoid copies of identical implementations of IRQ chips the 472 - core provides a configurable generic interrupt chip 473 - implementation. Developers should check carefully whether the 474 - generic chip fits their needs before implementing the same 475 - functionality slightly differently themselves. 476 - </para> 477 - !Ekernel/irq/generic-chip.c 478 - </chapter> 479 - 480 - <chapter id="structs"> 481 - <title>Structures</title> 482 - <para> 483 - This chapter contains the autogenerated documentation of the structures which are 484 - used in the generic IRQ layer. 485 - </para> 486 - !Iinclude/linux/irq.h 487 - !Iinclude/linux/interrupt.h 488 - </chapter> 489 - 490 - <chapter id="pubfunctions"> 491 - <title>Public Functions Provided</title> 492 - <para> 493 - This chapter contains the autogenerated documentation of the kernel API functions 494 - which are exported. 495 - </para> 496 - !Ekernel/irq/manage.c 497 - !Ekernel/irq/chip.c 498 - </chapter> 499 - 500 - <chapter id="intfunctions"> 501 - <title>Internal Functions Provided</title> 502 - <para> 503 - This chapter contains the autogenerated documentation of the internal functions. 504 - </para> 505 - !Ikernel/irq/irqdesc.c 506 - !Ikernel/irq/handle.c 507 - !Ikernel/irq/chip.c 508 - </chapter> 509 - 510 - <chapter id="credits"> 511 - <title>Credits</title> 512 - <para> 513 - The following people have contributed to this document: 514 - <orderedlist> 515 - <listitem><para>Thomas Gleixner<email>tglx@linutronix.de</email></para></listitem> 516 - <listitem><para>Ingo Molnar<email>mingo@elte.hu</email></para></listitem> 517 - </orderedlist> 518 - </para> 519 - </chapter> 520 - </book>
-331
Documentation/DocBook/kernel-api.tmpl
··· 1 - <?xml version="1.0" encoding="UTF-8"?> 2 - <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" 3 - "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" []> 4 - 5 - <book id="LinuxKernelAPI"> 6 - <bookinfo> 7 - <title>The Linux Kernel API</title> 8 - 9 - <legalnotice> 10 - <para> 11 - This documentation is free software; you can redistribute 12 - it and/or modify it under the terms of the GNU General Public 13 - License as published by the Free Software Foundation; either 14 - version 2 of the License, or (at your option) any later 15 - version. 16 - </para> 17 - 18 - <para> 19 - This program is distributed in the hope that it will be 20 - useful, but WITHOUT ANY WARRANTY; without even the implied 21 - warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 22 - See the GNU General Public License for more details. 23 - </para> 24 - 25 - <para> 26 - You should have received a copy of the GNU General Public 27 - License along with this program; if not, write to the Free 28 - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, 29 - MA 02111-1307 USA 30 - </para> 31 - 32 - <para> 33 - For more details see the file COPYING in the source 34 - distribution of Linux. 35 - </para> 36 - </legalnotice> 37 - </bookinfo> 38 - 39 - <toc></toc> 40 - 41 - <chapter id="adt"> 42 - <title>Data Types</title> 43 - <sect1><title>Doubly Linked Lists</title> 44 - !Iinclude/linux/list.h 45 - </sect1> 46 - </chapter> 47 - 48 - <chapter id="libc"> 49 - <title>Basic C Library Functions</title> 50 - 51 - <para> 52 - When writing drivers, you cannot in general use routines which are 53 - from the C Library. Some of the functions have been found generally 54 - useful and they are listed below. The behaviour of these functions 55 - may vary slightly from those defined by ANSI, and these deviations 56 - are noted in the text. 57 - </para> 58 - 59 - <sect1><title>String Conversions</title> 60 - !Elib/vsprintf.c 61 - !Finclude/linux/kernel.h kstrtol 62 - !Finclude/linux/kernel.h kstrtoul 63 - !Elib/kstrtox.c 64 - </sect1> 65 - <sect1><title>String Manipulation</title> 66 - <!-- All functions are exported at now 67 - X!Ilib/string.c 68 - --> 69 - !Elib/string.c 70 - </sect1> 71 - <sect1><title>Bit Operations</title> 72 - !Iarch/x86/include/asm/bitops.h 73 - </sect1> 74 - </chapter> 75 - 76 - <chapter id="kernel-lib"> 77 - <title>Basic Kernel Library Functions</title> 78 - 79 - <para> 80 - The Linux kernel provides more basic utility functions. 81 - </para> 82 - 83 - <sect1><title>Bitmap Operations</title> 84 - !Elib/bitmap.c 85 - !Ilib/bitmap.c 86 - </sect1> 87 - 88 - <sect1><title>Command-line Parsing</title> 89 - !Elib/cmdline.c 90 - </sect1> 91 - 92 - <sect1 id="crc"><title>CRC Functions</title> 93 - !Elib/crc7.c 94 - !Elib/crc16.c 95 - !Elib/crc-itu-t.c 96 - !Elib/crc32.c 97 - !Elib/crc-ccitt.c 98 - </sect1> 99 - 100 - <sect1 id="idr"><title>idr/ida Functions</title> 101 - !Pinclude/linux/idr.h idr sync 102 - !Plib/idr.c IDA description 103 - !Elib/idr.c 104 - </sect1> 105 - </chapter> 106 - 107 - <chapter id="mm"> 108 - <title>Memory Management in Linux</title> 109 - <sect1><title>The Slab Cache</title> 110 - !Iinclude/linux/slab.h 111 - !Emm/slab.c 112 - !Emm/util.c 113 - </sect1> 114 - <sect1><title>User Space Memory Access</title> 115 - !Iarch/x86/include/asm/uaccess_32.h 116 - !Earch/x86/lib/usercopy_32.c 117 - </sect1> 118 - <sect1><title>More Memory Management Functions</title> 119 - !Emm/readahead.c 120 - !Emm/filemap.c 121 - !Emm/memory.c 122 - !Emm/vmalloc.c 123 - !Imm/page_alloc.c 124 - !Emm/mempool.c 125 - !Emm/dmapool.c 126 - !Emm/page-writeback.c 127 - !Emm/truncate.c 128 - </sect1> 129 - </chapter> 130 - 131 - 132 - <chapter id="ipc"> 133 - <title>Kernel IPC facilities</title> 134 - 135 - <sect1><title>IPC utilities</title> 136 - !Iipc/util.c 137 - </sect1> 138 - </chapter> 139 - 140 - <chapter id="kfifo"> 141 - <title>FIFO Buffer</title> 142 - <sect1><title>kfifo interface</title> 143 - !Iinclude/linux/kfifo.h 144 - </sect1> 145 - </chapter> 146 - 147 - <chapter id="relayfs"> 148 - <title>relay interface support</title> 149 - 150 - <para> 151 - Relay interface support 152 - is designed to provide an efficient mechanism for tools and 153 - facilities to relay large amounts of data from kernel space to 154 - user space. 155 - </para> 156 - 157 - <sect1><title>relay interface</title> 158 - !Ekernel/relay.c 159 - !Ikernel/relay.c 160 - </sect1> 161 - </chapter> 162 - 163 - <chapter id="modload"> 164 - <title>Module Support</title> 165 - <sect1><title>Module Loading</title> 166 - !Ekernel/kmod.c 167 - </sect1> 168 - <sect1><title>Inter Module support</title> 169 - <para> 170 - Refer to the file kernel/module.c for more information. 171 - </para> 172 - <!-- FIXME: Removed for now since no structured comments in source 173 - X!Ekernel/module.c 174 - --> 175 - </sect1> 176 - </chapter> 177 - 178 - <chapter id="hardware"> 179 - <title>Hardware Interfaces</title> 180 - <sect1><title>Interrupt Handling</title> 181 - !Ekernel/irq/manage.c 182 - </sect1> 183 - 184 - <sect1><title>DMA Channels</title> 185 - !Ekernel/dma.c 186 - </sect1> 187 - 188 - <sect1><title>Resources Management</title> 189 - !Ikernel/resource.c 190 - !Ekernel/resource.c 191 - </sect1> 192 - 193 - <sect1><title>MTRR Handling</title> 194 - !Earch/x86/kernel/cpu/mtrr/main.c 195 - </sect1> 196 - 197 - <sect1><title>PCI Support Library</title> 198 - !Edrivers/pci/pci.c 199 - !Edrivers/pci/pci-driver.c 200 - !Edrivers/pci/remove.c 201 - !Edrivers/pci/search.c 202 - !Edrivers/pci/msi.c 203 - !Edrivers/pci/bus.c 204 - !Edrivers/pci/access.c 205 - !Edrivers/pci/irq.c 206 - !Edrivers/pci/htirq.c 207 - <!-- FIXME: Removed for now since no structured comments in source 208 - X!Edrivers/pci/hotplug.c 209 - --> 210 - !Edrivers/pci/probe.c 211 - !Edrivers/pci/slot.c 212 - !Edrivers/pci/rom.c 213 - !Edrivers/pci/iov.c 214 - !Idrivers/pci/pci-sysfs.c 215 - </sect1> 216 - <sect1><title>PCI Hotplug Support Library</title> 217 - !Edrivers/pci/hotplug/pci_hotplug_core.c 218 - </sect1> 219 - </chapter> 220 - 221 - <chapter id="firmware"> 222 - <title>Firmware Interfaces</title> 223 - <sect1><title>DMI Interfaces</title> 224 - !Edrivers/firmware/dmi_scan.c 225 - </sect1> 226 - <sect1><title>EDD Interfaces</title> 227 - !Idrivers/firmware/edd.c 228 - </sect1> 229 - </chapter> 230 - 231 - <chapter id="security"> 232 - <title>Security Framework</title> 233 - !Isecurity/security.c 234 - !Esecurity/inode.c 235 - </chapter> 236 - 237 - <chapter id="audit"> 238 - <title>Audit Interfaces</title> 239 - !Ekernel/audit.c 240 - !Ikernel/auditsc.c 241 - !Ikernel/auditfilter.c 242 - </chapter> 243 - 244 - <chapter id="accounting"> 245 - <title>Accounting Framework</title> 246 - !Ikernel/acct.c 247 - </chapter> 248 - 249 - <chapter id="blkdev"> 250 - <title>Block Devices</title> 251 - !Eblock/blk-core.c 252 - !Iblock/blk-core.c 253 - !Eblock/blk-map.c 254 - !Iblock/blk-sysfs.c 255 - !Eblock/blk-settings.c 256 - !Eblock/blk-exec.c 257 - !Eblock/blk-flush.c 258 - !Eblock/blk-lib.c 259 - !Eblock/blk-tag.c 260 - !Iblock/blk-tag.c 261 - !Eblock/blk-integrity.c 262 - !Ikernel/trace/blktrace.c 263 - !Iblock/genhd.c 264 - !Eblock/genhd.c 265 - </chapter> 266 - 267 - <chapter id="chrdev"> 268 - <title>Char devices</title> 269 - !Efs/char_dev.c 270 - </chapter> 271 - 272 - <chapter id="miscdev"> 273 - <title>Miscellaneous Devices</title> 274 - !Edrivers/char/misc.c 275 - </chapter> 276 - 277 - <chapter id="clk"> 278 - <title>Clock Framework</title> 279 - 280 - <para> 281 - The clock framework defines programming interfaces to support 282 - software management of the system clock tree. 283 - This framework is widely used with System-On-Chip (SOC) platforms 284 - to support power management and various devices which may need 285 - custom clock rates. 286 - Note that these "clocks" don't relate to timekeeping or real 287 - time clocks (RTCs), each of which have separate frameworks. 288 - These <structname>struct clk</structname> instances may be used 289 - to manage for example a 96 MHz signal that is used to shift bits 290 - into and out of peripherals or busses, or otherwise trigger 291 - synchronous state machine transitions in system hardware. 292 - </para> 293 - 294 - <para> 295 - Power management is supported by explicit software clock gating: 296 - unused clocks are disabled, so the system doesn't waste power 297 - changing the state of transistors that aren't in active use. 298 - On some systems this may be backed by hardware clock gating, 299 - where clocks are gated without being disabled in software. 300 - Sections of chips that are powered but not clocked may be able 301 - to retain their last state. 302 - This low power state is often called a <emphasis>retention 303 - mode</emphasis>. 304 - This mode still incurs leakage currents, especially with finer 305 - circuit geometries, but for CMOS circuits power is mostly used 306 - by clocked state changes. 307 - </para> 308 - 309 - <para> 310 - Power-aware drivers only enable their clocks when the device 311 - they manage is in active use. Also, system sleep states often 312 - differ according to which clock domains are active: while a 313 - "standby" state may allow wakeup from several active domains, a 314 - "mem" (suspend-to-RAM) state may require a more wholesale shutdown 315 - of clocks derived from higher speed PLLs and oscillators, limiting 316 - the number of possible wakeup event sources. A driver's suspend 317 - method may need to be aware of system-specific clock constraints 318 - on the target sleep state. 319 - </para> 320 - 321 - <para> 322 - Some platforms support programmable clock generators. These 323 - can be used by external chips of various kinds, such as other 324 - CPUs, multimedia codecs, and devices with strict requirements 325 - for interface clocking. 326 - </para> 327 - 328 - !Iinclude/linux/clk.h 329 - </chapter> 330 - 331 - </book>
-873
Documentation/DocBook/writing_musb_glue_layer.tmpl
··· 1 - <?xml version="1.0" encoding="UTF-8"?> 2 - <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" 3 - "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" []> 4 - 5 - <book id="Writing-MUSB-Glue-Layer"> 6 - <bookinfo> 7 - <title>Writing an MUSB Glue Layer</title> 8 - 9 - <authorgroup> 10 - <author> 11 - <firstname>Apelete</firstname> 12 - <surname>Seketeli</surname> 13 - <affiliation> 14 - <address> 15 - <email>apelete at seketeli.net</email> 16 - </address> 17 - </affiliation> 18 - </author> 19 - </authorgroup> 20 - 21 - <copyright> 22 - <year>2014</year> 23 - <holder>Apelete Seketeli</holder> 24 - </copyright> 25 - 26 - <legalnotice> 27 - <para> 28 - This documentation is free software; you can redistribute it 29 - and/or modify it under the terms of the GNU General Public 30 - License as published by the Free Software Foundation; either 31 - version 2 of the License, or (at your option) any later version. 32 - </para> 33 - 34 - <para> 35 - This documentation is distributed in the hope that it will be 36 - useful, but WITHOUT ANY WARRANTY; without even the implied 37 - warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 38 - See the GNU General Public License for more details. 39 - </para> 40 - 41 - <para> 42 - You should have received a copy of the GNU General Public License 43 - along with this documentation; if not, write to the Free Software 44 - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 45 - 02111-1307 USA 46 - </para> 47 - 48 - <para> 49 - For more details see the file COPYING in the Linux kernel source 50 - tree. 51 - </para> 52 - </legalnotice> 53 - </bookinfo> 54 - 55 - <toc></toc> 56 - 57 - <chapter id="introduction"> 58 - <title>Introduction</title> 59 - <para> 60 - The Linux MUSB subsystem is part of the larger Linux USB 61 - subsystem. It provides support for embedded USB Device Controllers 62 - (UDC) that do not use Universal Host Controller Interface (UHCI) 63 - or Open Host Controller Interface (OHCI). 64 - </para> 65 - <para> 66 - Instead, these embedded UDC rely on the USB On-the-Go (OTG) 67 - specification which they implement at least partially. The silicon 68 - reference design used in most cases is the Multipoint USB 69 - Highspeed Dual-Role Controller (MUSB HDRC) found in the Mentor 70 - Graphics Inventra™ design. 71 - </para> 72 - <para> 73 - As a self-taught exercise I have written an MUSB glue layer for 74 - the Ingenic JZ4740 SoC, modelled after the many MUSB glue layers 75 - in the kernel source tree. This layer can be found at 76 - drivers/usb/musb/jz4740.c. In this documentation I will walk 77 - through the basics of the jz4740.c glue layer, explaining the 78 - different pieces and what needs to be done in order to write your 79 - own device glue layer. 80 - </para> 81 - </chapter> 82 - 83 - <chapter id="linux-musb-basics"> 84 - <title>Linux MUSB Basics</title> 85 - <para> 86 - To get started on the topic, please read USB On-the-Go Basics (see 87 - Resources) which provides an introduction of USB OTG operation at 88 - the hardware level. A couple of wiki pages by Texas Instruments 89 - and Analog Devices also provide an overview of the Linux kernel 90 - MUSB configuration, albeit focused on some specific devices 91 - provided by these companies. Finally, getting acquainted with the 92 - USB specification at USB home page may come in handy, with 93 - practical instance provided through the Writing USB Device Drivers 94 - documentation (again, see Resources). 95 - </para> 96 - <para> 97 - Linux USB stack is a layered architecture in which the MUSB 98 - controller hardware sits at the lowest. The MUSB controller driver 99 - abstract the MUSB controller hardware to the Linux USB stack. 100 - </para> 101 - <programlisting> 102 - ------------------------ 103 - | | &lt;------- drivers/usb/gadget 104 - | Linux USB Core Stack | &lt;------- drivers/usb/host 105 - | | &lt;------- drivers/usb/core 106 - ------------------------ 107 - 108 - -------------------------- 109 - | | &lt;------ drivers/usb/musb/musb_gadget.c 110 - | MUSB Controller driver | &lt;------ drivers/usb/musb/musb_host.c 111 - | | &lt;------ drivers/usb/musb/musb_core.c 112 - -------------------------- 113 - 114 - --------------------------------- 115 - | MUSB Platform Specific Driver | 116 - | | &lt;-- drivers/usb/musb/jz4740.c 117 - | aka &quot;Glue Layer&quot; | 118 - --------------------------------- 119 - 120 - --------------------------------- 121 - | MUSB Controller Hardware | 122 - --------------------------------- 123 - </programlisting> 124 - <para> 125 - As outlined above, the glue layer is actually the platform 126 - specific code sitting in between the controller driver and the 127 - controller hardware. 128 - </para> 129 - <para> 130 - Just like a Linux USB driver needs to register itself with the 131 - Linux USB subsystem, the MUSB glue layer needs first to register 132 - itself with the MUSB controller driver. This will allow the 133 - controller driver to know about which device the glue layer 134 - supports and which functions to call when a supported device is 135 - detected or released; remember we are talking about an embedded 136 - controller chip here, so no insertion or removal at run-time. 137 - </para> 138 - <para> 139 - All of this information is passed to the MUSB controller driver 140 - through a platform_driver structure defined in the glue layer as: 141 - </para> 142 - <programlisting linenumbering="numbered"> 143 - static struct platform_driver jz4740_driver = { 144 - .probe = jz4740_probe, 145 - .remove = jz4740_remove, 146 - .driver = { 147 - .name = "musb-jz4740", 148 - }, 149 - }; 150 - </programlisting> 151 - <para> 152 - The probe and remove function pointers are called when a matching 153 - device is detected and, respectively, released. The name string 154 - describes the device supported by this glue layer. In the current 155 - case it matches a platform_device structure declared in 156 - arch/mips/jz4740/platform.c. Note that we are not using device 157 - tree bindings here. 158 - </para> 159 - <para> 160 - In order to register itself to the controller driver, the glue 161 - layer goes through a few steps, basically allocating the 162 - controller hardware resources and initialising a couple of 163 - circuits. To do so, it needs to keep track of the information used 164 - throughout these steps. This is done by defining a private 165 - jz4740_glue structure: 166 - </para> 167 - <programlisting linenumbering="numbered"> 168 - struct jz4740_glue { 169 - struct device *dev; 170 - struct platform_device *musb; 171 - struct clk *clk; 172 - }; 173 - </programlisting> 174 - <para> 175 - The dev and musb members are both device structure variables. The 176 - first one holds generic information about the device, since it's 177 - the basic device structure, and the latter holds information more 178 - closely related to the subsystem the device is registered to. The 179 - clk variable keeps information related to the device clock 180 - operation. 181 - </para> 182 - <para> 183 - Let's go through the steps of the probe function that leads the 184 - glue layer to register itself to the controller driver. 185 - </para> 186 - <para> 187 - N.B.: For the sake of readability each function will be split in 188 - logical parts, each part being shown as if it was independent from 189 - the others. 190 - </para> 191 - <programlisting linenumbering="numbered"> 192 - static int jz4740_probe(struct platform_device *pdev) 193 - { 194 - struct platform_device *musb; 195 - struct jz4740_glue *glue; 196 - struct clk *clk; 197 - int ret; 198 - 199 - glue = devm_kzalloc(&amp;pdev->dev, sizeof(*glue), GFP_KERNEL); 200 - if (!glue) 201 - return -ENOMEM; 202 - 203 - musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO); 204 - if (!musb) { 205 - dev_err(&amp;pdev->dev, "failed to allocate musb device\n"); 206 - return -ENOMEM; 207 - } 208 - 209 - clk = devm_clk_get(&amp;pdev->dev, "udc"); 210 - if (IS_ERR(clk)) { 211 - dev_err(&amp;pdev->dev, "failed to get clock\n"); 212 - ret = PTR_ERR(clk); 213 - goto err_platform_device_put; 214 - } 215 - 216 - ret = clk_prepare_enable(clk); 217 - if (ret) { 218 - dev_err(&amp;pdev->dev, "failed to enable clock\n"); 219 - goto err_platform_device_put; 220 - } 221 - 222 - musb->dev.parent = &amp;pdev->dev; 223 - 224 - glue->dev = &amp;pdev->dev; 225 - glue->musb = musb; 226 - glue->clk = clk; 227 - 228 - return 0; 229 - 230 - err_platform_device_put: 231 - platform_device_put(musb); 232 - return ret; 233 - } 234 - </programlisting> 235 - <para> 236 - The first few lines of the probe function allocate and assign the 237 - glue, musb and clk variables. The GFP_KERNEL flag (line 8) allows 238 - the allocation process to sleep and wait for memory, thus being 239 - usable in a blocking situation. The PLATFORM_DEVID_AUTO flag (line 240 - 12) allows automatic allocation and management of device IDs in 241 - order to avoid device namespace collisions with explicit IDs. With 242 - devm_clk_get() (line 18) the glue layer allocates the clock -- the 243 - <literal>devm_</literal> prefix indicates that clk_get() is 244 - managed: it automatically frees the allocated clock resource data 245 - when the device is released -- and enable it. 246 - </para> 247 - <para> 248 - Then comes the registration steps: 249 - </para> 250 - <programlisting linenumbering="numbered"> 251 - static int jz4740_probe(struct platform_device *pdev) 252 - { 253 - struct musb_hdrc_platform_data *pdata = &amp;jz4740_musb_platform_data; 254 - 255 - pdata->platform_ops = &amp;jz4740_musb_ops; 256 - 257 - platform_set_drvdata(pdev, glue); 258 - 259 - ret = platform_device_add_resources(musb, pdev->resource, 260 - pdev->num_resources); 261 - if (ret) { 262 - dev_err(&amp;pdev->dev, "failed to add resources\n"); 263 - goto err_clk_disable; 264 - } 265 - 266 - ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); 267 - if (ret) { 268 - dev_err(&amp;pdev->dev, "failed to add platform_data\n"); 269 - goto err_clk_disable; 270 - } 271 - 272 - return 0; 273 - 274 - err_clk_disable: 275 - clk_disable_unprepare(clk); 276 - err_platform_device_put: 277 - platform_device_put(musb); 278 - return ret; 279 - } 280 - </programlisting> 281 - <para> 282 - The first step is to pass the device data privately held by the 283 - glue layer on to the controller driver through 284 - platform_set_drvdata() (line 7). Next is passing on the device 285 - resources information, also privately held at that point, through 286 - platform_device_add_resources() (line 9). 287 - </para> 288 - <para> 289 - Finally comes passing on the platform specific data to the 290 - controller driver (line 16). Platform data will be discussed in 291 - <link linkend="device-platform-data">Chapter 4</link>, but here 292 - we are looking at the platform_ops function pointer (line 5) in 293 - musb_hdrc_platform_data structure (line 3). This function 294 - pointer allows the MUSB controller driver to know which function 295 - to call for device operation: 296 - </para> 297 - <programlisting linenumbering="numbered"> 298 - static const struct musb_platform_ops jz4740_musb_ops = { 299 - .init = jz4740_musb_init, 300 - .exit = jz4740_musb_exit, 301 - }; 302 - </programlisting> 303 - <para> 304 - Here we have the minimal case where only init and exit functions 305 - are called by the controller driver when needed. Fact is the 306 - JZ4740 MUSB controller is a basic controller, lacking some 307 - features found in other controllers, otherwise we may also have 308 - pointers to a few other functions like a power management function 309 - or a function to switch between OTG and non-OTG modes, for 310 - instance. 311 - </para> 312 - <para> 313 - At that point of the registration process, the controller driver 314 - actually calls the init function: 315 - </para> 316 - <programlisting linenumbering="numbered"> 317 - static int jz4740_musb_init(struct musb *musb) 318 - { 319 - musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); 320 - if (!musb->xceiv) { 321 - pr_err("HS UDC: no transceiver configured\n"); 322 - return -ENODEV; 323 - } 324 - 325 - /* Silicon does not implement ConfigData register. 326 - * Set dyn_fifo to avoid reading EP config from hardware. 327 - */ 328 - musb->dyn_fifo = true; 329 - 330 - musb->isr = jz4740_musb_interrupt; 331 - 332 - return 0; 333 - } 334 - </programlisting> 335 - <para> 336 - The goal of jz4740_musb_init() is to get hold of the transceiver 337 - driver data of the MUSB controller hardware and pass it on to the 338 - MUSB controller driver, as usual. The transceiver is the circuitry 339 - inside the controller hardware responsible for sending/receiving 340 - the USB data. Since it is an implementation of the physical layer 341 - of the OSI model, the transceiver is also referred to as PHY. 342 - </para> 343 - <para> 344 - Getting hold of the MUSB PHY driver data is done with 345 - usb_get_phy() which returns a pointer to the structure 346 - containing the driver instance data. The next couple of 347 - instructions (line 12 and 14) are used as a quirk and to setup 348 - IRQ handling respectively. Quirks and IRQ handling will be 349 - discussed later in <link linkend="device-quirks">Chapter 350 - 5</link> and <link linkend="handling-irqs">Chapter 3</link>. 351 - </para> 352 - <programlisting linenumbering="numbered"> 353 - static int jz4740_musb_exit(struct musb *musb) 354 - { 355 - usb_put_phy(musb->xceiv); 356 - 357 - return 0; 358 - } 359 - </programlisting> 360 - <para> 361 - Acting as the counterpart of init, the exit function releases the 362 - MUSB PHY driver when the controller hardware itself is about to be 363 - released. 364 - </para> 365 - <para> 366 - Again, note that init and exit are fairly simple in this case due 367 - to the basic set of features of the JZ4740 controller hardware. 368 - When writing an musb glue layer for a more complex controller 369 - hardware, you might need to take care of more processing in those 370 - two functions. 371 - </para> 372 - <para> 373 - Returning from the init function, the MUSB controller driver jumps 374 - back into the probe function: 375 - </para> 376 - <programlisting linenumbering="numbered"> 377 - static int jz4740_probe(struct platform_device *pdev) 378 - { 379 - ret = platform_device_add(musb); 380 - if (ret) { 381 - dev_err(&amp;pdev->dev, "failed to register musb device\n"); 382 - goto err_clk_disable; 383 - } 384 - 385 - return 0; 386 - 387 - err_clk_disable: 388 - clk_disable_unprepare(clk); 389 - err_platform_device_put: 390 - platform_device_put(musb); 391 - return ret; 392 - } 393 - </programlisting> 394 - <para> 395 - This is the last part of the device registration process where the 396 - glue layer adds the controller hardware device to Linux kernel 397 - device hierarchy: at this stage, all known information about the 398 - device is passed on to the Linux USB core stack. 399 - </para> 400 - <programlisting linenumbering="numbered"> 401 - static int jz4740_remove(struct platform_device *pdev) 402 - { 403 - struct jz4740_glue *glue = platform_get_drvdata(pdev); 404 - 405 - platform_device_unregister(glue->musb); 406 - clk_disable_unprepare(glue->clk); 407 - 408 - return 0; 409 - } 410 - </programlisting> 411 - <para> 412 - Acting as the counterpart of probe, the remove function unregister 413 - the MUSB controller hardware (line 5) and disable the clock (line 414 - 6), allowing it to be gated. 415 - </para> 416 - </chapter> 417 - 418 - <chapter id="handling-irqs"> 419 - <title>Handling IRQs</title> 420 - <para> 421 - Additionally to the MUSB controller hardware basic setup and 422 - registration, the glue layer is also responsible for handling the 423 - IRQs: 424 - </para> 425 - <programlisting linenumbering="numbered"> 426 - static irqreturn_t jz4740_musb_interrupt(int irq, void *__hci) 427 - { 428 - unsigned long flags; 429 - irqreturn_t retval = IRQ_NONE; 430 - struct musb *musb = __hci; 431 - 432 - spin_lock_irqsave(&amp;musb->lock, flags); 433 - 434 - musb->int_usb = musb_readb(musb->mregs, MUSB_INTRUSB); 435 - musb->int_tx = musb_readw(musb->mregs, MUSB_INTRTX); 436 - musb->int_rx = musb_readw(musb->mregs, MUSB_INTRRX); 437 - 438 - /* 439 - * The controller is gadget only, the state of the host mode IRQ bits is 440 - * undefined. Mask them to make sure that the musb driver core will 441 - * never see them set 442 - */ 443 - musb->int_usb &amp;= MUSB_INTR_SUSPEND | MUSB_INTR_RESUME | 444 - MUSB_INTR_RESET | MUSB_INTR_SOF; 445 - 446 - if (musb->int_usb || musb->int_tx || musb->int_rx) 447 - retval = musb_interrupt(musb); 448 - 449 - spin_unlock_irqrestore(&amp;musb->lock, flags); 450 - 451 - return retval; 452 - } 453 - </programlisting> 454 - <para> 455 - Here the glue layer mostly has to read the relevant hardware 456 - registers and pass their values on to the controller driver which 457 - will handle the actual event that triggered the IRQ. 458 - </para> 459 - <para> 460 - The interrupt handler critical section is protected by the 461 - spin_lock_irqsave() and counterpart spin_unlock_irqrestore() 462 - functions (line 7 and 24 respectively), which prevent the 463 - interrupt handler code to be run by two different threads at the 464 - same time. 465 - </para> 466 - <para> 467 - Then the relevant interrupt registers are read (line 9 to 11): 468 - </para> 469 - <itemizedlist> 470 - <listitem> 471 - <para> 472 - MUSB_INTRUSB: indicates which USB interrupts are currently 473 - active, 474 - </para> 475 - </listitem> 476 - <listitem> 477 - <para> 478 - MUSB_INTRTX: indicates which of the interrupts for TX 479 - endpoints are currently active, 480 - </para> 481 - </listitem> 482 - <listitem> 483 - <para> 484 - MUSB_INTRRX: indicates which of the interrupts for TX 485 - endpoints are currently active. 486 - </para> 487 - </listitem> 488 - </itemizedlist> 489 - <para> 490 - Note that musb_readb() is used to read 8-bit registers at most, 491 - while musb_readw() allows us to read at most 16-bit registers. 492 - There are other functions that can be used depending on the size 493 - of your device registers. See musb_io.h for more information. 494 - </para> 495 - <para> 496 - Instruction on line 18 is another quirk specific to the JZ4740 497 - USB device controller, which will be discussed later in <link 498 - linkend="device-quirks">Chapter 5</link>. 499 - </para> 500 - <para> 501 - The glue layer still needs to register the IRQ handler though. 502 - Remember the instruction on line 14 of the init function: 503 - </para> 504 - <programlisting linenumbering="numbered"> 505 - static int jz4740_musb_init(struct musb *musb) 506 - { 507 - musb->isr = jz4740_musb_interrupt; 508 - 509 - return 0; 510 - } 511 - </programlisting> 512 - <para> 513 - This instruction sets a pointer to the glue layer IRQ handler 514 - function, in order for the controller hardware to call the handler 515 - back when an IRQ comes from the controller hardware. The interrupt 516 - handler is now implemented and registered. 517 - </para> 518 - </chapter> 519 - 520 - <chapter id="device-platform-data"> 521 - <title>Device Platform Data</title> 522 - <para> 523 - In order to write an MUSB glue layer, you need to have some data 524 - describing the hardware capabilities of your controller hardware, 525 - which is called the platform data. 526 - </para> 527 - <para> 528 - Platform data is specific to your hardware, though it may cover a 529 - broad range of devices, and is generally found somewhere in the 530 - arch/ directory, depending on your device architecture. 531 - </para> 532 - <para> 533 - For instance, platform data for the JZ4740 SoC is found in 534 - arch/mips/jz4740/platform.c. In the platform.c file each device of 535 - the JZ4740 SoC is described through a set of structures. 536 - </para> 537 - <para> 538 - Here is the part of arch/mips/jz4740/platform.c that covers the 539 - USB Device Controller (UDC): 540 - </para> 541 - <programlisting linenumbering="numbered"> 542 - /* USB Device Controller */ 543 - struct platform_device jz4740_udc_xceiv_device = { 544 - .name = "usb_phy_gen_xceiv", 545 - .id = 0, 546 - }; 547 - 548 - static struct resource jz4740_udc_resources[] = { 549 - [0] = { 550 - .start = JZ4740_UDC_BASE_ADDR, 551 - .end = JZ4740_UDC_BASE_ADDR + 0x10000 - 1, 552 - .flags = IORESOURCE_MEM, 553 - }, 554 - [1] = { 555 - .start = JZ4740_IRQ_UDC, 556 - .end = JZ4740_IRQ_UDC, 557 - .flags = IORESOURCE_IRQ, 558 - .name = "mc", 559 - }, 560 - }; 561 - 562 - struct platform_device jz4740_udc_device = { 563 - .name = "musb-jz4740", 564 - .id = -1, 565 - .dev = { 566 - .dma_mask = &amp;jz4740_udc_device.dev.coherent_dma_mask, 567 - .coherent_dma_mask = DMA_BIT_MASK(32), 568 - }, 569 - .num_resources = ARRAY_SIZE(jz4740_udc_resources), 570 - .resource = jz4740_udc_resources, 571 - }; 572 - </programlisting> 573 - <para> 574 - The jz4740_udc_xceiv_device platform device structure (line 2) 575 - describes the UDC transceiver with a name and id number. 576 - </para> 577 - <para> 578 - At the time of this writing, note that 579 - &quot;usb_phy_gen_xceiv&quot; is the specific name to be used for 580 - all transceivers that are either built-in with reference USB IP or 581 - autonomous and doesn't require any PHY programming. You will need 582 - to set CONFIG_NOP_USB_XCEIV=y in the kernel configuration to make 583 - use of the corresponding transceiver driver. The id field could be 584 - set to -1 (equivalent to PLATFORM_DEVID_NONE), -2 (equivalent to 585 - PLATFORM_DEVID_AUTO) or start with 0 for the first device of this 586 - kind if we want a specific id number. 587 - </para> 588 - <para> 589 - The jz4740_udc_resources resource structure (line 7) defines the 590 - UDC registers base addresses. 591 - </para> 592 - <para> 593 - The first array (line 9 to 11) defines the UDC registers base 594 - memory addresses: start points to the first register memory 595 - address, end points to the last register memory address and the 596 - flags member defines the type of resource we are dealing with. So 597 - IORESOURCE_MEM is used to define the registers memory addresses. 598 - The second array (line 14 to 17) defines the UDC IRQ registers 599 - addresses. Since there is only one IRQ register available for the 600 - JZ4740 UDC, start and end point at the same address. The 601 - IORESOURCE_IRQ flag tells that we are dealing with IRQ resources, 602 - and the name &quot;mc&quot; is in fact hard-coded in the MUSB core 603 - in order for the controller driver to retrieve this IRQ resource 604 - by querying it by its name. 605 - </para> 606 - <para> 607 - Finally, the jz4740_udc_device platform device structure (line 21) 608 - describes the UDC itself. 609 - </para> 610 - <para> 611 - The &quot;musb-jz4740&quot; name (line 22) defines the MUSB 612 - driver that is used for this device; remember this is in fact 613 - the name that we used in the jz4740_driver platform driver 614 - structure in <link linkend="linux-musb-basics">Chapter 615 - 2</link>. The id field (line 23) is set to -1 (equivalent to 616 - PLATFORM_DEVID_NONE) since we do not need an id for the device: 617 - the MUSB controller driver was already set to allocate an 618 - automatic id in <link linkend="linux-musb-basics">Chapter 619 - 2</link>. In the dev field we care for DMA related information 620 - here. The dma_mask field (line 25) defines the width of the DMA 621 - mask that is going to be used, and coherent_dma_mask (line 26) 622 - has the same purpose but for the alloc_coherent DMA mappings: in 623 - both cases we are using a 32 bits mask. Then the resource field 624 - (line 29) is simply a pointer to the resource structure defined 625 - before, while the num_resources field (line 28) keeps track of 626 - the number of arrays defined in the resource structure (in this 627 - case there were two resource arrays defined before). 628 - </para> 629 - <para> 630 - With this quick overview of the UDC platform data at the arch/ 631 - level now done, let's get back to the MUSB glue layer specific 632 - platform data in drivers/usb/musb/jz4740.c: 633 - </para> 634 - <programlisting linenumbering="numbered"> 635 - static struct musb_hdrc_config jz4740_musb_config = { 636 - /* Silicon does not implement USB OTG. */ 637 - .multipoint = 0, 638 - /* Max EPs scanned, driver will decide which EP can be used. */ 639 - .num_eps = 4, 640 - /* RAMbits needed to configure EPs from table */ 641 - .ram_bits = 9, 642 - .fifo_cfg = jz4740_musb_fifo_cfg, 643 - .fifo_cfg_size = ARRAY_SIZE(jz4740_musb_fifo_cfg), 644 - }; 645 - 646 - static struct musb_hdrc_platform_data jz4740_musb_platform_data = { 647 - .mode = MUSB_PERIPHERAL, 648 - .config = &amp;jz4740_musb_config, 649 - }; 650 - </programlisting> 651 - <para> 652 - First the glue layer configures some aspects of the controller 653 - driver operation related to the controller hardware specifics. 654 - This is done through the jz4740_musb_config musb_hdrc_config 655 - structure. 656 - </para> 657 - <para> 658 - Defining the OTG capability of the controller hardware, the 659 - multipoint member (line 3) is set to 0 (equivalent to false) 660 - since the JZ4740 UDC is not OTG compatible. Then num_eps (line 661 - 5) defines the number of USB endpoints of the controller 662 - hardware, including endpoint 0: here we have 3 endpoints + 663 - endpoint 0. Next is ram_bits (line 7) which is the width of the 664 - RAM address bus for the MUSB controller hardware. This 665 - information is needed when the controller driver cannot 666 - automatically configure endpoints by reading the relevant 667 - controller hardware registers. This issue will be discussed when 668 - we get to device quirks in <link linkend="device-quirks">Chapter 669 - 5</link>. Last two fields (line 8 and 9) are also about device 670 - quirks: fifo_cfg points to the USB endpoints configuration table 671 - and fifo_cfg_size keeps track of the size of the number of 672 - entries in that configuration table. More on that later in <link 673 - linkend="device-quirks">Chapter 5</link>. 674 - </para> 675 - <para> 676 - Then this configuration is embedded inside 677 - jz4740_musb_platform_data musb_hdrc_platform_data structure (line 678 - 11): config is a pointer to the configuration structure itself, 679 - and mode tells the controller driver if the controller hardware 680 - may be used as MUSB_HOST only, MUSB_PERIPHERAL only or MUSB_OTG 681 - which is a dual mode. 682 - </para> 683 - <para> 684 - Remember that jz4740_musb_platform_data is then used to convey 685 - platform data information as we have seen in the probe function 686 - in <link linkend="linux-musb-basics">Chapter 2</link> 687 - </para> 688 - </chapter> 689 - 690 - <chapter id="device-quirks"> 691 - <title>Device Quirks</title> 692 - <para> 693 - Completing the platform data specific to your device, you may also 694 - need to write some code in the glue layer to work around some 695 - device specific limitations. These quirks may be due to some 696 - hardware bugs, or simply be the result of an incomplete 697 - implementation of the USB On-the-Go specification. 698 - </para> 699 - <para> 700 - The JZ4740 UDC exhibits such quirks, some of which we will discuss 701 - here for the sake of insight even though these might not be found 702 - in the controller hardware you are working on. 703 - </para> 704 - <para> 705 - Let's get back to the init function first: 706 - </para> 707 - <programlisting linenumbering="numbered"> 708 - static int jz4740_musb_init(struct musb *musb) 709 - { 710 - musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); 711 - if (!musb->xceiv) { 712 - pr_err("HS UDC: no transceiver configured\n"); 713 - return -ENODEV; 714 - } 715 - 716 - /* Silicon does not implement ConfigData register. 717 - * Set dyn_fifo to avoid reading EP config from hardware. 718 - */ 719 - musb->dyn_fifo = true; 720 - 721 - musb->isr = jz4740_musb_interrupt; 722 - 723 - return 0; 724 - } 725 - </programlisting> 726 - <para> 727 - Instruction on line 12 helps the MUSB controller driver to work 728 - around the fact that the controller hardware is missing registers 729 - that are used for USB endpoints configuration. 730 - </para> 731 - <para> 732 - Without these registers, the controller driver is unable to read 733 - the endpoints configuration from the hardware, so we use line 12 734 - instruction to bypass reading the configuration from silicon, and 735 - rely on a hard-coded table that describes the endpoints 736 - configuration instead: 737 - </para> 738 - <programlisting linenumbering="numbered"> 739 - static struct musb_fifo_cfg jz4740_musb_fifo_cfg[] = { 740 - { .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, }, 741 - { .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, }, 742 - { .hw_ep_num = 2, .style = FIFO_TX, .maxpacket = 64, }, 743 - }; 744 - </programlisting> 745 - <para> 746 - Looking at the configuration table above, we see that each 747 - endpoints is described by three fields: hw_ep_num is the endpoint 748 - number, style is its direction (either FIFO_TX for the controller 749 - driver to send packets in the controller hardware, or FIFO_RX to 750 - receive packets from hardware), and maxpacket defines the maximum 751 - size of each data packet that can be transmitted over that 752 - endpoint. Reading from the table, the controller driver knows that 753 - endpoint 1 can be used to send and receive USB data packets of 512 754 - bytes at once (this is in fact a bulk in/out endpoint), and 755 - endpoint 2 can be used to send data packets of 64 bytes at once 756 - (this is in fact an interrupt endpoint). 757 - </para> 758 - <para> 759 - Note that there is no information about endpoint 0 here: that one 760 - is implemented by default in every silicon design, with a 761 - predefined configuration according to the USB specification. For 762 - more examples of endpoint configuration tables, see musb_core.c. 763 - </para> 764 - <para> 765 - Let's now get back to the interrupt handler function: 766 - </para> 767 - <programlisting linenumbering="numbered"> 768 - static irqreturn_t jz4740_musb_interrupt(int irq, void *__hci) 769 - { 770 - unsigned long flags; 771 - irqreturn_t retval = IRQ_NONE; 772 - struct musb *musb = __hci; 773 - 774 - spin_lock_irqsave(&amp;musb->lock, flags); 775 - 776 - musb->int_usb = musb_readb(musb->mregs, MUSB_INTRUSB); 777 - musb->int_tx = musb_readw(musb->mregs, MUSB_INTRTX); 778 - musb->int_rx = musb_readw(musb->mregs, MUSB_INTRRX); 779 - 780 - /* 781 - * The controller is gadget only, the state of the host mode IRQ bits is 782 - * undefined. Mask them to make sure that the musb driver core will 783 - * never see them set 784 - */ 785 - musb->int_usb &amp;= MUSB_INTR_SUSPEND | MUSB_INTR_RESUME | 786 - MUSB_INTR_RESET | MUSB_INTR_SOF; 787 - 788 - if (musb->int_usb || musb->int_tx || musb->int_rx) 789 - retval = musb_interrupt(musb); 790 - 791 - spin_unlock_irqrestore(&amp;musb->lock, flags); 792 - 793 - return retval; 794 - } 795 - </programlisting> 796 - <para> 797 - Instruction on line 18 above is a way for the controller driver to 798 - work around the fact that some interrupt bits used for USB host 799 - mode operation are missing in the MUSB_INTRUSB register, thus left 800 - in an undefined hardware state, since this MUSB controller 801 - hardware is used in peripheral mode only. As a consequence, the 802 - glue layer masks these missing bits out to avoid parasite 803 - interrupts by doing a logical AND operation between the value read 804 - from MUSB_INTRUSB and the bits that are actually implemented in 805 - the register. 806 - </para> 807 - <para> 808 - These are only a couple of the quirks found in the JZ4740 USB 809 - device controller. Some others were directly addressed in the MUSB 810 - core since the fixes were generic enough to provide a better 811 - handling of the issues for others controller hardware eventually. 812 - </para> 813 - </chapter> 814 - 815 - <chapter id="conclusion"> 816 - <title>Conclusion</title> 817 - <para> 818 - Writing a Linux MUSB glue layer should be a more accessible task, 819 - as this documentation tries to show the ins and outs of this 820 - exercise. 821 - </para> 822 - <para> 823 - The JZ4740 USB device controller being fairly simple, I hope its 824 - glue layer serves as a good example for the curious mind. Used 825 - with the current MUSB glue layers, this documentation should 826 - provide enough guidance to get started; should anything gets out 827 - of hand, the linux-usb mailing list archive is another helpful 828 - resource to browse through. 829 - </para> 830 - </chapter> 831 - 832 - <chapter id="acknowledgements"> 833 - <title>Acknowledgements</title> 834 - <para> 835 - Many thanks to Lars-Peter Clausen and Maarten ter Huurne for 836 - answering my questions while I was writing the JZ4740 glue layer 837 - and for helping me out getting the code in good shape. 838 - </para> 839 - <para> 840 - I would also like to thank the Qi-Hardware community at large for 841 - its cheerful guidance and support. 842 - </para> 843 - </chapter> 844 - 845 - <chapter id="resources"> 846 - <title>Resources</title> 847 - <para> 848 - USB Home Page: 849 - <ulink url="http://www.usb.org">http://www.usb.org</ulink> 850 - </para> 851 - <para> 852 - linux-usb Mailing List Archives: 853 - <ulink url="http://marc.info/?l=linux-usb">http://marc.info/?l=linux-usb</ulink> 854 - </para> 855 - <para> 856 - USB On-the-Go Basics: 857 - <ulink url="http://www.maximintegrated.com/app-notes/index.mvp/id/1822">http://www.maximintegrated.com/app-notes/index.mvp/id/1822</ulink> 858 - </para> 859 - <para> 860 - Writing USB Device Drivers: 861 - <ulink url="https://www.kernel.org/doc/htmldocs/writing_usb_driver/index.html">https://www.kernel.org/doc/htmldocs/writing_usb_driver/index.html</ulink> 862 - </para> 863 - <para> 864 - Texas Instruments USB Configuration Wiki Page: 865 - <ulink url="http://processors.wiki.ti.com/index.php/Usbgeneralpage">http://processors.wiki.ti.com/index.php/Usbgeneralpage</ulink> 866 - </para> 867 - <para> 868 - Analog Devices Blackfin MUSB Configuration: 869 - <ulink url="http://docs.blackfin.uclinux.org/doku.php?id=linux-kernel:drivers:musb">http://docs.blackfin.uclinux.org/doku.php?id=linux-kernel:drivers:musb</ulink> 870 - </para> 871 - </chapter> 872 - 873 - </book>
-412
Documentation/DocBook/writing_usb_driver.tmpl
··· 1 - <?xml version="1.0" encoding="UTF-8"?> 2 - <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" 3 - "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" []> 4 - 5 - <book id="USBDeviceDriver"> 6 - <bookinfo> 7 - <title>Writing USB Device Drivers</title> 8 - 9 - <authorgroup> 10 - <author> 11 - <firstname>Greg</firstname> 12 - <surname>Kroah-Hartman</surname> 13 - <affiliation> 14 - <address> 15 - <email>greg@kroah.com</email> 16 - </address> 17 - </affiliation> 18 - </author> 19 - </authorgroup> 20 - 21 - <copyright> 22 - <year>2001-2002</year> 23 - <holder>Greg Kroah-Hartman</holder> 24 - </copyright> 25 - 26 - <legalnotice> 27 - <para> 28 - This documentation is free software; you can redistribute 29 - it and/or modify it under the terms of the GNU General Public 30 - License as published by the Free Software Foundation; either 31 - version 2 of the License, or (at your option) any later 32 - version. 33 - </para> 34 - 35 - <para> 36 - This program is distributed in the hope that it will be 37 - useful, but WITHOUT ANY WARRANTY; without even the implied 38 - warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 39 - See the GNU General Public License for more details. 40 - </para> 41 - 42 - <para> 43 - You should have received a copy of the GNU General Public 44 - License along with this program; if not, write to the Free 45 - Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, 46 - MA 02111-1307 USA 47 - </para> 48 - 49 - <para> 50 - For more details see the file COPYING in the source 51 - distribution of Linux. 52 - </para> 53 - 54 - <para> 55 - This documentation is based on an article published in 56 - Linux Journal Magazine, October 2001, Issue 90. 57 - </para> 58 - </legalnotice> 59 - </bookinfo> 60 - 61 - <toc></toc> 62 - 63 - <chapter id="intro"> 64 - <title>Introduction</title> 65 - <para> 66 - The Linux USB subsystem has grown from supporting only two different 67 - types of devices in the 2.2.7 kernel (mice and keyboards), to over 20 68 - different types of devices in the 2.4 kernel. Linux currently supports 69 - almost all USB class devices (standard types of devices like keyboards, 70 - mice, modems, printers and speakers) and an ever-growing number of 71 - vendor-specific devices (such as USB to serial converters, digital 72 - cameras, Ethernet devices and MP3 players). For a full list of the 73 - different USB devices currently supported, see Resources. 74 - </para> 75 - <para> 76 - The remaining kinds of USB devices that do not have support on Linux are 77 - almost all vendor-specific devices. Each vendor decides to implement a 78 - custom protocol to talk to their device, so a custom driver usually needs 79 - to be created. Some vendors are open with their USB protocols and help 80 - with the creation of Linux drivers, while others do not publish them, and 81 - developers are forced to reverse-engineer. See Resources for some links 82 - to handy reverse-engineering tools. 83 - </para> 84 - <para> 85 - Because each different protocol causes a new driver to be created, I have 86 - written a generic USB driver skeleton, modelled after the pci-skeleton.c 87 - file in the kernel source tree upon which many PCI network drivers have 88 - been based. This USB skeleton can be found at drivers/usb/usb-skeleton.c 89 - in the kernel source tree. In this article I will walk through the basics 90 - of the skeleton driver, explaining the different pieces and what needs to 91 - be done to customize it to your specific device. 92 - </para> 93 - </chapter> 94 - 95 - <chapter id="basics"> 96 - <title>Linux USB Basics</title> 97 - <para> 98 - If you are going to write a Linux USB driver, please become familiar with 99 - the USB protocol specification. It can be found, along with many other 100 - useful documents, at the USB home page (see Resources). An excellent 101 - introduction to the Linux USB subsystem can be found at the USB Working 102 - Devices List (see Resources). It explains how the Linux USB subsystem is 103 - structured and introduces the reader to the concept of USB urbs 104 - (USB Request Blocks), which are essential to USB drivers. 105 - </para> 106 - <para> 107 - The first thing a Linux USB driver needs to do is register itself with 108 - the Linux USB subsystem, giving it some information about which devices 109 - the driver supports and which functions to call when a device supported 110 - by the driver is inserted or removed from the system. All of this 111 - information is passed to the USB subsystem in the usb_driver structure. 112 - The skeleton driver declares a usb_driver as: 113 - </para> 114 - <programlisting> 115 - static struct usb_driver skel_driver = { 116 - .name = "skeleton", 117 - .probe = skel_probe, 118 - .disconnect = skel_disconnect, 119 - .fops = &amp;skel_fops, 120 - .minor = USB_SKEL_MINOR_BASE, 121 - .id_table = skel_table, 122 - }; 123 - </programlisting> 124 - <para> 125 - The variable name is a string that describes the driver. It is used in 126 - informational messages printed to the system log. The probe and 127 - disconnect function pointers are called when a device that matches the 128 - information provided in the id_table variable is either seen or removed. 129 - </para> 130 - <para> 131 - The fops and minor variables are optional. Most USB drivers hook into 132 - another kernel subsystem, such as the SCSI, network or TTY subsystem. 133 - These types of drivers register themselves with the other kernel 134 - subsystem, and any user-space interactions are provided through that 135 - interface. But for drivers that do not have a matching kernel subsystem, 136 - such as MP3 players or scanners, a method of interacting with user space 137 - is needed. The USB subsystem provides a way to register a minor device 138 - number and a set of file_operations function pointers that enable this 139 - user-space interaction. The skeleton driver needs this kind of interface, 140 - so it provides a minor starting number and a pointer to its 141 - file_operations functions. 142 - </para> 143 - <para> 144 - The USB driver is then registered with a call to usb_register, usually in 145 - the driver's init function, as shown here: 146 - </para> 147 - <programlisting> 148 - static int __init usb_skel_init(void) 149 - { 150 - int result; 151 - 152 - /* register this driver with the USB subsystem */ 153 - result = usb_register(&amp;skel_driver); 154 - if (result &lt; 0) { 155 - err(&quot;usb_register failed for the &quot;__FILE__ &quot;driver.&quot; 156 - &quot;Error number %d&quot;, result); 157 - return -1; 158 - } 159 - 160 - return 0; 161 - } 162 - module_init(usb_skel_init); 163 - </programlisting> 164 - <para> 165 - When the driver is unloaded from the system, it needs to deregister 166 - itself with the USB subsystem. This is done with the usb_deregister 167 - function: 168 - </para> 169 - <programlisting> 170 - static void __exit usb_skel_exit(void) 171 - { 172 - /* deregister this driver with the USB subsystem */ 173 - usb_deregister(&amp;skel_driver); 174 - } 175 - module_exit(usb_skel_exit); 176 - </programlisting> 177 - <para> 178 - To enable the linux-hotplug system to load the driver automatically when 179 - the device is plugged in, you need to create a MODULE_DEVICE_TABLE. The 180 - following code tells the hotplug scripts that this module supports a 181 - single device with a specific vendor and product ID: 182 - </para> 183 - <programlisting> 184 - /* table of devices that work with this driver */ 185 - static struct usb_device_id skel_table [] = { 186 - { USB_DEVICE(USB_SKEL_VENDOR_ID, USB_SKEL_PRODUCT_ID) }, 187 - { } /* Terminating entry */ 188 - }; 189 - MODULE_DEVICE_TABLE (usb, skel_table); 190 - </programlisting> 191 - <para> 192 - There are other macros that can be used in describing a usb_device_id for 193 - drivers that support a whole class of USB drivers. See usb.h for more 194 - information on this. 195 - </para> 196 - </chapter> 197 - 198 - <chapter id="device"> 199 - <title>Device operation</title> 200 - <para> 201 - When a device is plugged into the USB bus that matches the device ID 202 - pattern that your driver registered with the USB core, the probe function 203 - is called. The usb_device structure, interface number and the interface ID 204 - are passed to the function: 205 - </para> 206 - <programlisting> 207 - static int skel_probe(struct usb_interface *interface, 208 - const struct usb_device_id *id) 209 - </programlisting> 210 - <para> 211 - The driver now needs to verify that this device is actually one that it 212 - can accept. If so, it returns 0. 213 - If not, or if any error occurs during initialization, an errorcode 214 - (such as <literal>-ENOMEM</literal> or <literal>-ENODEV</literal>) 215 - is returned from the probe function. 216 - </para> 217 - <para> 218 - In the skeleton driver, we determine what end points are marked as bulk-in 219 - and bulk-out. We create buffers to hold the data that will be sent and 220 - received from the device, and a USB urb to write data to the device is 221 - initialized. 222 - </para> 223 - <para> 224 - Conversely, when the device is removed from the USB bus, the disconnect 225 - function is called with the device pointer. The driver needs to clean any 226 - private data that has been allocated at this time and to shut down any 227 - pending urbs that are in the USB system. 228 - </para> 229 - <para> 230 - Now that the device is plugged into the system and the driver is bound to 231 - the device, any of the functions in the file_operations structure that 232 - were passed to the USB subsystem will be called from a user program trying 233 - to talk to the device. The first function called will be open, as the 234 - program tries to open the device for I/O. We increment our private usage 235 - count and save a pointer to our internal structure in the file 236 - structure. This is done so that future calls to file operations will 237 - enable the driver to determine which device the user is addressing. All 238 - of this is done with the following code: 239 - </para> 240 - <programlisting> 241 - /* increment our usage count for the module */ 242 - ++skel->open_count; 243 - 244 - /* save our object in the file's private structure */ 245 - file->private_data = dev; 246 - </programlisting> 247 - <para> 248 - After the open function is called, the read and write functions are called 249 - to receive and send data to the device. In the skel_write function, we 250 - receive a pointer to some data that the user wants to send to the device 251 - and the size of the data. The function determines how much data it can 252 - send to the device based on the size of the write urb it has created (this 253 - size depends on the size of the bulk out end point that the device has). 254 - Then it copies the data from user space to kernel space, points the urb to 255 - the data and submits the urb to the USB subsystem. This can be seen in 256 - the following code: 257 - </para> 258 - <programlisting> 259 - /* we can only write as much as 1 urb will hold */ 260 - bytes_written = (count > skel->bulk_out_size) ? skel->bulk_out_size : count; 261 - 262 - /* copy the data from user space into our urb */ 263 - copy_from_user(skel->write_urb->transfer_buffer, buffer, bytes_written); 264 - 265 - /* set up our urb */ 266 - usb_fill_bulk_urb(skel->write_urb, 267 - skel->dev, 268 - usb_sndbulkpipe(skel->dev, skel->bulk_out_endpointAddr), 269 - skel->write_urb->transfer_buffer, 270 - bytes_written, 271 - skel_write_bulk_callback, 272 - skel); 273 - 274 - /* send the data out the bulk port */ 275 - result = usb_submit_urb(skel->write_urb); 276 - if (result) { 277 - err(&quot;Failed submitting write urb, error %d&quot;, result); 278 - } 279 - </programlisting> 280 - <para> 281 - When the write urb is filled up with the proper information using the 282 - usb_fill_bulk_urb function, we point the urb's completion callback to call our 283 - own skel_write_bulk_callback function. This function is called when the 284 - urb is finished by the USB subsystem. The callback function is called in 285 - interrupt context, so caution must be taken not to do very much processing 286 - at that time. Our implementation of skel_write_bulk_callback merely 287 - reports if the urb was completed successfully or not and then returns. 288 - </para> 289 - <para> 290 - The read function works a bit differently from the write function in that 291 - we do not use an urb to transfer data from the device to the driver. 292 - Instead we call the usb_bulk_msg function, which can be used to send or 293 - receive data from a device without having to create urbs and handle 294 - urb completion callback functions. We call the usb_bulk_msg function, 295 - giving it a buffer into which to place any data received from the device 296 - and a timeout value. If the timeout period expires without receiving any 297 - data from the device, the function will fail and return an error message. 298 - This can be shown with the following code: 299 - </para> 300 - <programlisting> 301 - /* do an immediate bulk read to get data from the device */ 302 - retval = usb_bulk_msg (skel->dev, 303 - usb_rcvbulkpipe (skel->dev, 304 - skel->bulk_in_endpointAddr), 305 - skel->bulk_in_buffer, 306 - skel->bulk_in_size, 307 - &amp;count, HZ*10); 308 - /* if the read was successful, copy the data to user space */ 309 - if (!retval) { 310 - if (copy_to_user (buffer, skel->bulk_in_buffer, count)) 311 - retval = -EFAULT; 312 - else 313 - retval = count; 314 - } 315 - </programlisting> 316 - <para> 317 - The usb_bulk_msg function can be very useful for doing single reads or 318 - writes to a device; however, if you need to read or write constantly to a 319 - device, it is recommended to set up your own urbs and submit them to the 320 - USB subsystem. 321 - </para> 322 - <para> 323 - When the user program releases the file handle that it has been using to 324 - talk to the device, the release function in the driver is called. In this 325 - function we decrement our private usage count and wait for possible 326 - pending writes: 327 - </para> 328 - <programlisting> 329 - /* decrement our usage count for the device */ 330 - --skel->open_count; 331 - </programlisting> 332 - <para> 333 - One of the more difficult problems that USB drivers must be able to handle 334 - smoothly is the fact that the USB device may be removed from the system at 335 - any point in time, even if a program is currently talking to it. It needs 336 - to be able to shut down any current reads and writes and notify the 337 - user-space programs that the device is no longer there. The following 338 - code (function <function>skel_delete</function>) 339 - is an example of how to do this: </para> 340 - <programlisting> 341 - static inline void skel_delete (struct usb_skel *dev) 342 - { 343 - kfree (dev->bulk_in_buffer); 344 - if (dev->bulk_out_buffer != NULL) 345 - usb_free_coherent (dev->udev, dev->bulk_out_size, 346 - dev->bulk_out_buffer, 347 - dev->write_urb->transfer_dma); 348 - usb_free_urb (dev->write_urb); 349 - kfree (dev); 350 - } 351 - </programlisting> 352 - <para> 353 - If a program currently has an open handle to the device, we reset the flag 354 - <literal>device_present</literal>. For 355 - every read, write, release and other functions that expect a device to be 356 - present, the driver first checks this flag to see if the device is 357 - still present. If not, it releases that the device has disappeared, and a 358 - -ENODEV error is returned to the user-space program. When the release 359 - function is eventually called, it determines if there is no device 360 - and if not, it does the cleanup that the skel_disconnect 361 - function normally does if there are no open files on the device (see 362 - Listing 5). 363 - </para> 364 - </chapter> 365 - 366 - <chapter id="iso"> 367 - <title>Isochronous Data</title> 368 - <para> 369 - This usb-skeleton driver does not have any examples of interrupt or 370 - isochronous data being sent to or from the device. Interrupt data is sent 371 - almost exactly as bulk data is, with a few minor exceptions. Isochronous 372 - data works differently with continuous streams of data being sent to or 373 - from the device. The audio and video camera drivers are very good examples 374 - of drivers that handle isochronous data and will be useful if you also 375 - need to do this. 376 - </para> 377 - </chapter> 378 - 379 - <chapter id="Conclusion"> 380 - <title>Conclusion</title> 381 - <para> 382 - Writing Linux USB device drivers is not a difficult task as the 383 - usb-skeleton driver shows. This driver, combined with the other current 384 - USB drivers, should provide enough examples to help a beginning author 385 - create a working driver in a minimal amount of time. The linux-usb-devel 386 - mailing list archives also contain a lot of helpful information. 387 - </para> 388 - </chapter> 389 - 390 - <chapter id="resources"> 391 - <title>Resources</title> 392 - <para> 393 - The Linux USB Project: <ulink url="http://www.linux-usb.org">http://www.linux-usb.org/</ulink> 394 - </para> 395 - <para> 396 - Linux Hotplug Project: <ulink url="http://linux-hotplug.sourceforge.net">http://linux-hotplug.sourceforge.net/</ulink> 397 - </para> 398 - <para> 399 - Linux USB Working Devices List: <ulink url="http://www.qbik.ch/usb/devices">http://www.qbik.ch/usb/devices/</ulink> 400 - </para> 401 - <para> 402 - linux-usb-devel Mailing List Archives: <ulink url="http://marc.theaimsgroup.com/?l=linux-usb-devel">http://marc.theaimsgroup.com/?l=linux-usb-devel</ulink> 403 - </para> 404 - <para> 405 - Programming Guide for Linux USB Device Drivers: <ulink url="http://usb.cs.tum.edu/usbdoc">http://usb.cs.tum.edu/usbdoc</ulink> 406 - </para> 407 - <para> 408 - USB Home Page: <ulink url="http://www.usb.org">http://www.usb.org</ulink> 409 - </para> 410 - </chapter> 411 - 412 - </book>
+6 -6
Documentation/PCI/pci-error-recovery.txt
··· 11 11 12 12 Many PCI bus controllers are able to detect a variety of hardware 13 13 PCI errors on the bus, such as parity errors on the data and address 14 - busses, as well as SERR and PERR errors. Some of the more advanced 14 + buses, as well as SERR and PERR errors. Some of the more advanced 15 15 chipsets are able to deal with these errors; these include PCI-E chipsets, 16 16 and the PCI-host bridges found on IBM Power4, Power5 and Power6-based 17 17 pSeries boxes. A typical action taken is to disconnect the affected device, ··· 173 173 >>> a value of 0xff on read, and writes will be dropped. If more than 174 174 >>> EEH_MAX_FAILS I/O's are attempted to a frozen adapter, EEH 175 175 >>> assumes that the device driver has gone into an infinite loop 176 - >>> and prints an error to syslog. A reboot is then required to 176 + >>> and prints an error to syslog. A reboot is then required to 177 177 >>> get the device working again. 178 178 179 179 STEP 2: MMIO Enabled ··· 231 231 STEP 3: Link Reset 232 232 ------------------ 233 233 The platform resets the link. This is a PCI-Express specific step 234 - and is done whenever a non-fatal error has been detected that can be 234 + and is done whenever a fatal error has been detected that can be 235 235 "solved" by resetting the link. 236 236 237 237 STEP 4: Slot Reset 238 238 ------------------ 239 239 240 240 In response to a return value of PCI_ERS_RESULT_NEED_RESET, the 241 - the platform will perform a slot reset on the requesting PCI device(s). 241 + the platform will perform a slot reset on the requesting PCI device(s). 242 242 The actual steps taken by a platform to perform a slot reset 243 243 will be platform-dependent. Upon completion of slot reset, the 244 244 platform will call the device slot_reset() callback. ··· 258 258 259 259 For most PCI devices, a soft reset will be sufficient for recovery. 260 260 Optional fundamental reset is provided to support a limited number 261 - of PCI Express PCI devices for which a soft reset is not sufficient 261 + of PCI Express devices for which a soft reset is not sufficient 262 262 for recovery. 263 263 264 264 If the platform supports PCI hotplug, then the reset might be ··· 303 303 Same as above. 304 304 305 305 Drivers for PCI Express cards that require a fundamental reset must 306 - set the needs_freset bit in the pci_dev structure in their probe function. 306 + set the needs_freset bit in the pci_dev structure in their probe function. 307 307 For example, the QLogic qla2xxx driver sets the needs_freset bit for certain 308 308 PCI card types: 309 309
+1 -1
Documentation/acpi/aml-debugger.txt
··· 15 15 CONFIG_ACPI_DEBUGGER=y 16 16 CONFIG_ACPI_DEBUGGER_USER=m 17 17 18 - The userspace utlities can be built from the kernel source tree using 18 + The userspace utilities can be built from the kernel source tree using 19 19 the following commands: 20 20 21 21 $ cd tools
+3 -3
Documentation/acpi/enumeration.txt
··· 367 367 368 368 Device Tree namespace link device ID 369 369 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 370 - The Device Tree protocol uses device indentification based on the "compatible" 370 + The Device Tree protocol uses device identification based on the "compatible" 371 371 property whose value is a string or an array of strings recognized as device 372 372 identifiers by drivers and the driver core. The set of all those strings may be 373 - regarded as a device indentification namespace analogous to the ACPI/PNP device 373 + regarded as a device identification namespace analogous to the ACPI/PNP device 374 374 ID namespace. Consequently, in principle it should not be necessary to allocate 375 375 a new (and arguably redundant) ACPI/PNP device ID for a devices with an existing 376 376 identification string in the Device Tree (DT) namespace, especially if that ID ··· 381 381 list the IDs of devices the given one is compatible with, but those IDs must 382 382 belong to one of the namespaces prescribed by the ACPI specification (see 383 383 Section 6.1.2 of ACPI 6.0 for details) and the DT namespace is not one of them. 384 - Moreover, the specification mandates that either a _HID or an _ADR identificaion 384 + Moreover, the specification mandates that either a _HID or an _ADR identification 385 385 object be present for all ACPI objects representing devices (Section 6.1 of ACPI 386 386 6.0). For non-enumerable bus types that object must be _HID and its value must 387 387 be a device ID from one of the namespaces prescribed by the specification too.
+1
Documentation/admin-guide/index.rst
··· 60 60 mono 61 61 java 62 62 ras 63 + pm/index 63 64 64 65 .. only:: subproject and html 65 66
+3 -1
Documentation/admin-guide/kernel-parameters.rst
··· 1 + .. _kernelparameters: 2 + 1 3 The kernel's command-line parameters 2 4 ==================================== 3 5 ··· 198 196 199 197 Finally, the [KMG] suffix is commonly described after a number of kernel 200 198 parameter values. These 'K', 'M', and 'G' letters represent the _binary_ 201 - multipliers 'Kilo', 'Mega', and 'Giga', equalling 2^10, 2^20, and 2^30 199 + multipliers 'Kilo', 'Mega', and 'Giga', equaling 2^10, 2^20, and 2^30 202 200 bytes respectively. Such letter suffixes can also be entirely omitted: 203 201 204 202 .. include:: kernel-parameters.txt
+700
Documentation/admin-guide/pm/cpufreq.rst
··· 1 + .. |struct cpufreq_policy| replace:: :c:type:`struct cpufreq_policy <cpufreq_policy>` 2 + 3 + ======================= 4 + CPU Performance Scaling 5 + ======================= 6 + 7 + :: 8 + 9 + Copyright (c) 2017 Intel Corp., Rafael J. Wysocki <rafael.j.wysocki@intel.com> 10 + 11 + The Concept of CPU Performance Scaling 12 + ====================================== 13 + 14 + The majority of modern processors are capable of operating in a number of 15 + different clock frequency and voltage configurations, often referred to as 16 + Operating Performance Points or P-states (in ACPI terminology). As a rule, 17 + the higher the clock frequency and the higher the voltage, the more instructions 18 + can be retired by the CPU over a unit of time, but also the higher the clock 19 + frequency and the higher the voltage, the more energy is consumed over a unit of 20 + time (or the more power is drawn) by the CPU in the given P-state. Therefore 21 + there is a natural tradeoff between the CPU capacity (the number of instructions 22 + that can be executed over a unit of time) and the power drawn by the CPU. 23 + 24 + In some situations it is desirable or even necessary to run the program as fast 25 + as possible and then there is no reason to use any P-states different from the 26 + highest one (i.e. the highest-performance frequency/voltage configuration 27 + available). In some other cases, however, it may not be necessary to execute 28 + instructions so quickly and maintaining the highest available CPU capacity for a 29 + relatively long time without utilizing it entirely may be regarded as wasteful. 30 + It also may not be physically possible to maintain maximum CPU capacity for too 31 + long for thermal or power supply capacity reasons or similar. To cover those 32 + cases, there are hardware interfaces allowing CPUs to be switched between 33 + different frequency/voltage configurations or (in the ACPI terminology) to be 34 + put into different P-states. 35 + 36 + Typically, they are used along with algorithms to estimate the required CPU 37 + capacity, so as to decide which P-states to put the CPUs into. Of course, since 38 + the utilization of the system generally changes over time, that has to be done 39 + repeatedly on a regular basis. The activity by which this happens is referred 40 + to as CPU performance scaling or CPU frequency scaling (because it involves 41 + adjusting the CPU clock frequency). 42 + 43 + 44 + CPU Performance Scaling in Linux 45 + ================================ 46 + 47 + The Linux kernel supports CPU performance scaling by means of the ``CPUFreq`` 48 + (CPU Frequency scaling) subsystem that consists of three layers of code: the 49 + core, scaling governors and scaling drivers. 50 + 51 + The ``CPUFreq`` core provides the common code infrastructure and user space 52 + interfaces for all platforms that support CPU performance scaling. It defines 53 + the basic framework in which the other components operate. 54 + 55 + Scaling governors implement algorithms to estimate the required CPU capacity. 56 + As a rule, each governor implements one, possibly parametrized, scaling 57 + algorithm. 58 + 59 + Scaling drivers talk to the hardware. They provide scaling governors with 60 + information on the available P-states (or P-state ranges in some cases) and 61 + access platform-specific hardware interfaces to change CPU P-states as requested 62 + by scaling governors. 63 + 64 + In principle, all available scaling governors can be used with every scaling 65 + driver. That design is based on the observation that the information used by 66 + performance scaling algorithms for P-state selection can be represented in a 67 + platform-independent form in the majority of cases, so it should be possible 68 + to use the same performance scaling algorithm implemented in exactly the same 69 + way regardless of which scaling driver is used. Consequently, the same set of 70 + scaling governors should be suitable for every supported platform. 71 + 72 + However, that observation may not hold for performance scaling algorithms 73 + based on information provided by the hardware itself, for example through 74 + feedback registers, as that information is typically specific to the hardware 75 + interface it comes from and may not be easily represented in an abstract, 76 + platform-independent way. For this reason, ``CPUFreq`` allows scaling drivers 77 + to bypass the governor layer and implement their own performance scaling 78 + algorithms. That is done by the ``intel_pstate`` scaling driver. 79 + 80 + 81 + ``CPUFreq`` Policy Objects 82 + ========================== 83 + 84 + In some cases the hardware interface for P-state control is shared by multiple 85 + CPUs. That is, for example, the same register (or set of registers) is used to 86 + control the P-state of multiple CPUs at the same time and writing to it affects 87 + all of those CPUs simultaneously. 88 + 89 + Sets of CPUs sharing hardware P-state control interfaces are represented by 90 + ``CPUFreq`` as |struct cpufreq_policy| objects. For consistency, 91 + |struct cpufreq_policy| is also used when there is only one CPU in the given 92 + set. 93 + 94 + The ``CPUFreq`` core maintains a pointer to a |struct cpufreq_policy| object for 95 + every CPU in the system, including CPUs that are currently offline. If multiple 96 + CPUs share the same hardware P-state control interface, all of the pointers 97 + corresponding to them point to the same |struct cpufreq_policy| object. 98 + 99 + ``CPUFreq`` uses |struct cpufreq_policy| as its basic data type and the design 100 + of its user space interface is based on the policy concept. 101 + 102 + 103 + CPU Initialization 104 + ================== 105 + 106 + First of all, a scaling driver has to be registered for ``CPUFreq`` to work. 107 + It is only possible to register one scaling driver at a time, so the scaling 108 + driver is expected to be able to handle all CPUs in the system. 109 + 110 + The scaling driver may be registered before or after CPU registration. If 111 + CPUs are registered earlier, the driver core invokes the ``CPUFreq`` core to 112 + take a note of all of the already registered CPUs during the registration of the 113 + scaling driver. In turn, if any CPUs are registered after the registration of 114 + the scaling driver, the ``CPUFreq`` core will be invoked to take note of them 115 + at their registration time. 116 + 117 + In any case, the ``CPUFreq`` core is invoked to take note of any logical CPU it 118 + has not seen so far as soon as it is ready to handle that CPU. [Note that the 119 + logical CPU may be a physical single-core processor, or a single core in a 120 + multicore processor, or a hardware thread in a physical processor or processor 121 + core. In what follows "CPU" always means "logical CPU" unless explicitly stated 122 + otherwise and the word "processor" is used to refer to the physical part 123 + possibly including multiple logical CPUs.] 124 + 125 + Once invoked, the ``CPUFreq`` core checks if the policy pointer is already set 126 + for the given CPU and if so, it skips the policy object creation. Otherwise, 127 + a new policy object is created and initialized, which involves the creation of 128 + a new policy directory in ``sysfs``, and the policy pointer corresponding to 129 + the given CPU is set to the new policy object's address in memory. 130 + 131 + Next, the scaling driver's ``->init()`` callback is invoked with the policy 132 + pointer of the new CPU passed to it as the argument. That callback is expected 133 + to initialize the performance scaling hardware interface for the given CPU (or, 134 + more precisely, for the set of CPUs sharing the hardware interface it belongs 135 + to, represented by its policy object) and, if the policy object it has been 136 + called for is new, to set parameters of the policy, like the minimum and maximum 137 + frequencies supported by the hardware, the table of available frequencies (if 138 + the set of supported P-states is not a continuous range), and the mask of CPUs 139 + that belong to the same policy (including both online and offline CPUs). That 140 + mask is then used by the core to populate the policy pointers for all of the 141 + CPUs in it. 142 + 143 + The next major initialization step for a new policy object is to attach a 144 + scaling governor to it (to begin with, that is the default scaling governor 145 + determined by the kernel configuration, but it may be changed later 146 + via ``sysfs``). First, a pointer to the new policy object is passed to the 147 + governor's ``->init()`` callback which is expected to initialize all of the 148 + data structures necessary to handle the given policy and, possibly, to add 149 + a governor ``sysfs`` interface to it. Next, the governor is started by 150 + invoking its ``->start()`` callback. 151 + 152 + That callback it expected to register per-CPU utilization update callbacks for 153 + all of the online CPUs belonging to the given policy with the CPU scheduler. 154 + The utilization update callbacks will be invoked by the CPU scheduler on 155 + important events, like task enqueue and dequeue, on every iteration of the 156 + scheduler tick or generally whenever the CPU utilization may change (from the 157 + scheduler's perspective). They are expected to carry out computations needed 158 + to determine the P-state to use for the given policy going forward and to 159 + invoke the scaling driver to make changes to the hardware in accordance with 160 + the P-state selection. The scaling driver may be invoked directly from 161 + scheduler context or asynchronously, via a kernel thread or workqueue, depending 162 + on the configuration and capabilities of the scaling driver and the governor. 163 + 164 + Similar steps are taken for policy objects that are not new, but were "inactive" 165 + previously, meaning that all of the CPUs belonging to them were offline. The 166 + only practical difference in that case is that the ``CPUFreq`` core will attempt 167 + to use the scaling governor previously used with the policy that became 168 + "inactive" (and is re-initialized now) instead of the default governor. 169 + 170 + In turn, if a previously offline CPU is being brought back online, but some 171 + other CPUs sharing the policy object with it are online already, there is no 172 + need to re-initialize the policy object at all. In that case, it only is 173 + necessary to restart the scaling governor so that it can take the new online CPU 174 + into account. That is achieved by invoking the governor's ``->stop`` and 175 + ``->start()`` callbacks, in this order, for the entire policy. 176 + 177 + As mentioned before, the ``intel_pstate`` scaling driver bypasses the scaling 178 + governor layer of ``CPUFreq`` and provides its own P-state selection algorithms. 179 + Consequently, if ``intel_pstate`` is used, scaling governors are not attached to 180 + new policy objects. Instead, the driver's ``->setpolicy()`` callback is invoked 181 + to register per-CPU utilization update callbacks for each policy. These 182 + callbacks are invoked by the CPU scheduler in the same way as for scaling 183 + governors, but in the ``intel_pstate`` case they both determine the P-state to 184 + use and change the hardware configuration accordingly in one go from scheduler 185 + context. 186 + 187 + The policy objects created during CPU initialization and other data structures 188 + associated with them are torn down when the scaling driver is unregistered 189 + (which happens when the kernel module containing it is unloaded, for example) or 190 + when the last CPU belonging to the given policy in unregistered. 191 + 192 + 193 + Policy Interface in ``sysfs`` 194 + ============================= 195 + 196 + During the initialization of the kernel, the ``CPUFreq`` core creates a 197 + ``sysfs`` directory (kobject) called ``cpufreq`` under 198 + :file:`/sys/devices/system/cpu/`. 199 + 200 + That directory contains a ``policyX`` subdirectory (where ``X`` represents an 201 + integer number) for every policy object maintained by the ``CPUFreq`` core. 202 + Each ``policyX`` directory is pointed to by ``cpufreq`` symbolic links 203 + under :file:`/sys/devices/system/cpu/cpuY/` (where ``Y`` represents an integer 204 + that may be different from the one represented by ``X``) for all of the CPUs 205 + associated with (or belonging to) the given policy. The ``policyX`` directories 206 + in :file:`/sys/devices/system/cpu/cpufreq` each contain policy-specific 207 + attributes (files) to control ``CPUFreq`` behavior for the corresponding policy 208 + objects (that is, for all of the CPUs associated with them). 209 + 210 + Some of those attributes are generic. They are created by the ``CPUFreq`` core 211 + and their behavior generally does not depend on what scaling driver is in use 212 + and what scaling governor is attached to the given policy. Some scaling drivers 213 + also add driver-specific attributes to the policy directories in ``sysfs`` to 214 + control policy-specific aspects of driver behavior. 215 + 216 + The generic attributes under :file:`/sys/devices/system/cpu/cpufreq/policyX/` 217 + are the following: 218 + 219 + ``affected_cpus`` 220 + List of online CPUs belonging to this policy (i.e. sharing the hardware 221 + performance scaling interface represented by the ``policyX`` policy 222 + object). 223 + 224 + ``bios_limit`` 225 + If the platform firmware (BIOS) tells the OS to apply an upper limit to 226 + CPU frequencies, that limit will be reported through this attribute (if 227 + present). 228 + 229 + The existence of the limit may be a result of some (often unintentional) 230 + BIOS settings, restrictions coming from a service processor or another 231 + BIOS/HW-based mechanisms. 232 + 233 + This does not cover ACPI thermal limitations which can be discovered 234 + through a generic thermal driver. 235 + 236 + This attribute is not present if the scaling driver in use does not 237 + support it. 238 + 239 + ``cpuinfo_max_freq`` 240 + Maximum possible operating frequency the CPUs belonging to this policy 241 + can run at (in kHz). 242 + 243 + ``cpuinfo_min_freq`` 244 + Minimum possible operating frequency the CPUs belonging to this policy 245 + can run at (in kHz). 246 + 247 + ``cpuinfo_transition_latency`` 248 + The time it takes to switch the CPUs belonging to this policy from one 249 + P-state to another, in nanoseconds. 250 + 251 + If unknown or if known to be so high that the scaling driver does not 252 + work with the `ondemand`_ governor, -1 (:c:macro:`CPUFREQ_ETERNAL`) 253 + will be returned by reads from this attribute. 254 + 255 + ``related_cpus`` 256 + List of all (online and offline) CPUs belonging to this policy. 257 + 258 + ``scaling_available_governors`` 259 + List of ``CPUFreq`` scaling governors present in the kernel that can 260 + be attached to this policy or (if the ``intel_pstate`` scaling driver is 261 + in use) list of scaling algorithms provided by the driver that can be 262 + applied to this policy. 263 + 264 + [Note that some governors are modular and it may be necessary to load a 265 + kernel module for the governor held by it to become available and be 266 + listed by this attribute.] 267 + 268 + ``scaling_cur_freq`` 269 + Current frequency of all of the CPUs belonging to this policy (in kHz). 270 + 271 + For the majority of scaling drivers, this is the frequency of the last 272 + P-state requested by the driver from the hardware using the scaling 273 + interface provided by it, which may or may not reflect the frequency 274 + the CPU is actually running at (due to hardware design and other 275 + limitations). 276 + 277 + Some scaling drivers (e.g. ``intel_pstate``) attempt to provide 278 + information more precisely reflecting the current CPU frequency through 279 + this attribute, but that still may not be the exact current CPU 280 + frequency as seen by the hardware at the moment. 281 + 282 + ``scaling_driver`` 283 + The scaling driver currently in use. 284 + 285 + ``scaling_governor`` 286 + The scaling governor currently attached to this policy or (if the 287 + ``intel_pstate`` scaling driver is in use) the scaling algorithm 288 + provided by the driver that is currently applied to this policy. 289 + 290 + This attribute is read-write and writing to it will cause a new scaling 291 + governor to be attached to this policy or a new scaling algorithm 292 + provided by the scaling driver to be applied to it (in the 293 + ``intel_pstate`` case), as indicated by the string written to this 294 + attribute (which must be one of the names listed by the 295 + ``scaling_available_governors`` attribute described above). 296 + 297 + ``scaling_max_freq`` 298 + Maximum frequency the CPUs belonging to this policy are allowed to be 299 + running at (in kHz). 300 + 301 + This attribute is read-write and writing a string representing an 302 + integer to it will cause a new limit to be set (it must not be lower 303 + than the value of the ``scaling_min_freq`` attribute). 304 + 305 + ``scaling_min_freq`` 306 + Minimum frequency the CPUs belonging to this policy are allowed to be 307 + running at (in kHz). 308 + 309 + This attribute is read-write and writing a string representing a 310 + non-negative integer to it will cause a new limit to be set (it must not 311 + be higher than the value of the ``scaling_max_freq`` attribute). 312 + 313 + ``scaling_setspeed`` 314 + This attribute is functional only if the `userspace`_ scaling governor 315 + is attached to the given policy. 316 + 317 + It returns the last frequency requested by the governor (in kHz) or can 318 + be written to in order to set a new frequency for the policy. 319 + 320 + 321 + Generic Scaling Governors 322 + ========================= 323 + 324 + ``CPUFreq`` provides generic scaling governors that can be used with all 325 + scaling drivers. As stated before, each of them implements a single, possibly 326 + parametrized, performance scaling algorithm. 327 + 328 + Scaling governors are attached to policy objects and different policy objects 329 + can be handled by different scaling governors at the same time (although that 330 + may lead to suboptimal results in some cases). 331 + 332 + The scaling governor for a given policy object can be changed at any time with 333 + the help of the ``scaling_governor`` policy attribute in ``sysfs``. 334 + 335 + Some governors expose ``sysfs`` attributes to control or fine-tune the scaling 336 + algorithms implemented by them. Those attributes, referred to as governor 337 + tunables, can be either global (system-wide) or per-policy, depending on the 338 + scaling driver in use. If the driver requires governor tunables to be 339 + per-policy, they are located in a subdirectory of each policy directory. 340 + Otherwise, they are located in a subdirectory under 341 + :file:`/sys/devices/system/cpu/cpufreq/`. In either case the name of the 342 + subdirectory containing the governor tunables is the name of the governor 343 + providing them. 344 + 345 + ``performance`` 346 + --------------- 347 + 348 + When attached to a policy object, this governor causes the highest frequency, 349 + within the ``scaling_max_freq`` policy limit, to be requested for that policy. 350 + 351 + The request is made once at that time the governor for the policy is set to 352 + ``performance`` and whenever the ``scaling_max_freq`` or ``scaling_min_freq`` 353 + policy limits change after that. 354 + 355 + ``powersave`` 356 + ------------- 357 + 358 + When attached to a policy object, this governor causes the lowest frequency, 359 + within the ``scaling_min_freq`` policy limit, to be requested for that policy. 360 + 361 + The request is made once at that time the governor for the policy is set to 362 + ``powersave`` and whenever the ``scaling_max_freq`` or ``scaling_min_freq`` 363 + policy limits change after that. 364 + 365 + ``userspace`` 366 + ------------- 367 + 368 + This governor does not do anything by itself. Instead, it allows user space 369 + to set the CPU frequency for the policy it is attached to by writing to the 370 + ``scaling_setspeed`` attribute of that policy. 371 + 372 + ``schedutil`` 373 + ------------- 374 + 375 + This governor uses CPU utilization data available from the CPU scheduler. It 376 + generally is regarded as a part of the CPU scheduler, so it can access the 377 + scheduler's internal data structures directly. 378 + 379 + It runs entirely in scheduler context, although in some cases it may need to 380 + invoke the scaling driver asynchronously when it decides that the CPU frequency 381 + should be changed for a given policy (that depends on whether or not the driver 382 + is capable of changing the CPU frequency from scheduler context). 383 + 384 + The actions of this governor for a particular CPU depend on the scheduling class 385 + invoking its utilization update callback for that CPU. If it is invoked by the 386 + RT or deadline scheduling classes, the governor will increase the frequency to 387 + the allowed maximum (that is, the ``scaling_max_freq`` policy limit). In turn, 388 + if it is invoked by the CFS scheduling class, the governor will use the 389 + Per-Entity Load Tracking (PELT) metric for the root control group of the 390 + given CPU as the CPU utilization estimate (see the `Per-entity load tracking`_ 391 + LWN.net article for a description of the PELT mechanism). Then, the new 392 + CPU frequency to apply is computed in accordance with the formula 393 + 394 + f = 1.25 * ``f_0`` * ``util`` / ``max`` 395 + 396 + where ``util`` is the PELT number, ``max`` is the theoretical maximum of 397 + ``util``, and ``f_0`` is either the maximum possible CPU frequency for the given 398 + policy (if the PELT number is frequency-invariant), or the current CPU frequency 399 + (otherwise). 400 + 401 + This governor also employs a mechanism allowing it to temporarily bump up the 402 + CPU frequency for tasks that have been waiting on I/O most recently, called 403 + "IO-wait boosting". That happens when the :c:macro:`SCHED_CPUFREQ_IOWAIT` flag 404 + is passed by the scheduler to the governor callback which causes the frequency 405 + to go up to the allowed maximum immediately and then draw back to the value 406 + returned by the above formula over time. 407 + 408 + This governor exposes only one tunable: 409 + 410 + ``rate_limit_us`` 411 + Minimum time (in microseconds) that has to pass between two consecutive 412 + runs of governor computations (default: 1000 times the scaling driver's 413 + transition latency). 414 + 415 + The purpose of this tunable is to reduce the scheduler context overhead 416 + of the governor which might be excessive without it. 417 + 418 + This governor generally is regarded as a replacement for the older `ondemand`_ 419 + and `conservative`_ governors (described below), as it is simpler and more 420 + tightly integrated with the CPU scheduler, its overhead in terms of CPU context 421 + switches and similar is less significant, and it uses the scheduler's own CPU 422 + utilization metric, so in principle its decisions should not contradict the 423 + decisions made by the other parts of the scheduler. 424 + 425 + ``ondemand`` 426 + ------------ 427 + 428 + This governor uses CPU load as a CPU frequency selection metric. 429 + 430 + In order to estimate the current CPU load, it measures the time elapsed between 431 + consecutive invocations of its worker routine and computes the fraction of that 432 + time in which the given CPU was not idle. The ratio of the non-idle (active) 433 + time to the total CPU time is taken as an estimate of the load. 434 + 435 + If this governor is attached to a policy shared by multiple CPUs, the load is 436 + estimated for all of them and the greatest result is taken as the load estimate 437 + for the entire policy. 438 + 439 + The worker routine of this governor has to run in process context, so it is 440 + invoked asynchronously (via a workqueue) and CPU P-states are updated from 441 + there if necessary. As a result, the scheduler context overhead from this 442 + governor is minimum, but it causes additional CPU context switches to happen 443 + relatively often and the CPU P-state updates triggered by it can be relatively 444 + irregular. Also, it affects its own CPU load metric by running code that 445 + reduces the CPU idle time (even though the CPU idle time is only reduced very 446 + slightly by it). 447 + 448 + It generally selects CPU frequencies proportional to the estimated load, so that 449 + the value of the ``cpuinfo_max_freq`` policy attribute corresponds to the load of 450 + 1 (or 100%), and the value of the ``cpuinfo_min_freq`` policy attribute 451 + corresponds to the load of 0, unless when the load exceeds a (configurable) 452 + speedup threshold, in which case it will go straight for the highest frequency 453 + it is allowed to use (the ``scaling_max_freq`` policy limit). 454 + 455 + This governor exposes the following tunables: 456 + 457 + ``sampling_rate`` 458 + This is how often the governor's worker routine should run, in 459 + microseconds. 460 + 461 + Typically, it is set to values of the order of 10000 (10 ms). Its 462 + default value is equal to the value of ``cpuinfo_transition_latency`` 463 + for each policy this governor is attached to (but since the unit here 464 + is greater by 1000, this means that the time represented by 465 + ``sampling_rate`` is 1000 times greater than the transition latency by 466 + default). 467 + 468 + If this tunable is per-policy, the following shell command sets the time 469 + represented by it to be 750 times as high as the transition latency:: 470 + 471 + # echo `$(($(cat cpuinfo_transition_latency) * 750 / 1000)) > ondemand/sampling_rate 472 + 473 + 474 + ``min_sampling_rate`` 475 + The minimum value of ``sampling_rate``. 476 + 477 + Equal to 10000 (10 ms) if :c:macro:`CONFIG_NO_HZ_COMMON` and 478 + :c:data:`tick_nohz_active` are both set or to 20 times the value of 479 + :c:data:`jiffies` in microseconds otherwise. 480 + 481 + ``up_threshold`` 482 + If the estimated CPU load is above this value (in percent), the governor 483 + will set the frequency to the maximum value allowed for the policy. 484 + Otherwise, the selected frequency will be proportional to the estimated 485 + CPU load. 486 + 487 + ``ignore_nice_load`` 488 + If set to 1 (default 0), it will cause the CPU load estimation code to 489 + treat the CPU time spent on executing tasks with "nice" levels greater 490 + than 0 as CPU idle time. 491 + 492 + This may be useful if there are tasks in the system that should not be 493 + taken into account when deciding what frequency to run the CPUs at. 494 + Then, to make that happen it is sufficient to increase the "nice" level 495 + of those tasks above 0 and set this attribute to 1. 496 + 497 + ``sampling_down_factor`` 498 + Temporary multiplier, between 1 (default) and 100 inclusive, to apply to 499 + the ``sampling_rate`` value if the CPU load goes above ``up_threshold``. 500 + 501 + This causes the next execution of the governor's worker routine (after 502 + setting the frequency to the allowed maximum) to be delayed, so the 503 + frequency stays at the maximum level for a longer time. 504 + 505 + Frequency fluctuations in some bursty workloads may be avoided this way 506 + at the cost of additional energy spent on maintaining the maximum CPU 507 + capacity. 508 + 509 + ``powersave_bias`` 510 + Reduction factor to apply to the original frequency target of the 511 + governor (including the maximum value used when the ``up_threshold`` 512 + value is exceeded by the estimated CPU load) or sensitivity threshold 513 + for the AMD frequency sensitivity powersave bias driver 514 + (:file:`drivers/cpufreq/amd_freq_sensitivity.c`), between 0 and 1000 515 + inclusive. 516 + 517 + If the AMD frequency sensitivity powersave bias driver is not loaded, 518 + the effective frequency to apply is given by 519 + 520 + f * (1 - ``powersave_bias`` / 1000) 521 + 522 + where f is the governor's original frequency target. The default value 523 + of this attribute is 0 in that case. 524 + 525 + If the AMD frequency sensitivity powersave bias driver is loaded, the 526 + value of this attribute is 400 by default and it is used in a different 527 + way. 528 + 529 + On Family 16h (and later) AMD processors there is a mechanism to get a 530 + measured workload sensitivity, between 0 and 100% inclusive, from the 531 + hardware. That value can be used to estimate how the performance of the 532 + workload running on a CPU will change in response to frequency changes. 533 + 534 + The performance of a workload with the sensitivity of 0 (memory-bound or 535 + IO-bound) is not expected to increase at all as a result of increasing 536 + the CPU frequency, whereas workloads with the sensitivity of 100% 537 + (CPU-bound) are expected to perform much better if the CPU frequency is 538 + increased. 539 + 540 + If the workload sensitivity is less than the threshold represented by 541 + the ``powersave_bias`` value, the sensitivity powersave bias driver 542 + will cause the governor to select a frequency lower than its original 543 + target, so as to avoid over-provisioning workloads that will not benefit 544 + from running at higher CPU frequencies. 545 + 546 + ``conservative`` 547 + ---------------- 548 + 549 + This governor uses CPU load as a CPU frequency selection metric. 550 + 551 + It estimates the CPU load in the same way as the `ondemand`_ governor described 552 + above, but the CPU frequency selection algorithm implemented by it is different. 553 + 554 + Namely, it avoids changing the frequency significantly over short time intervals 555 + which may not be suitable for systems with limited power supply capacity (e.g. 556 + battery-powered). To achieve that, it changes the frequency in relatively 557 + small steps, one step at a time, up or down - depending on whether or not a 558 + (configurable) threshold has been exceeded by the estimated CPU load. 559 + 560 + This governor exposes the following tunables: 561 + 562 + ``freq_step`` 563 + Frequency step in percent of the maximum frequency the governor is 564 + allowed to set (the ``scaling_max_freq`` policy limit), between 0 and 565 + 100 (5 by default). 566 + 567 + This is how much the frequency is allowed to change in one go. Setting 568 + it to 0 will cause the default frequency step (5 percent) to be used 569 + and setting it to 100 effectively causes the governor to periodically 570 + switch the frequency between the ``scaling_min_freq`` and 571 + ``scaling_max_freq`` policy limits. 572 + 573 + ``down_threshold`` 574 + Threshold value (in percent, 20 by default) used to determine the 575 + frequency change direction. 576 + 577 + If the estimated CPU load is greater than this value, the frequency will 578 + go up (by ``freq_step``). If the load is less than this value (and the 579 + ``sampling_down_factor`` mechanism is not in effect), the frequency will 580 + go down. Otherwise, the frequency will not be changed. 581 + 582 + ``sampling_down_factor`` 583 + Frequency decrease deferral factor, between 1 (default) and 10 584 + inclusive. 585 + 586 + It effectively causes the frequency to go down ``sampling_down_factor`` 587 + times slower than it ramps up. 588 + 589 + 590 + Frequency Boost Support 591 + ======================= 592 + 593 + Background 594 + ---------- 595 + 596 + Some processors support a mechanism to raise the operating frequency of some 597 + cores in a multicore package temporarily (and above the sustainable frequency 598 + threshold for the whole package) under certain conditions, for example if the 599 + whole chip is not fully utilized and below its intended thermal or power budget. 600 + 601 + Different names are used by different vendors to refer to this functionality. 602 + For Intel processors it is referred to as "Turbo Boost", AMD calls it 603 + "Turbo-Core" or (in technical documentation) "Core Performance Boost" and so on. 604 + As a rule, it also is implemented differently by different vendors. The simple 605 + term "frequency boost" is used here for brevity to refer to all of those 606 + implementations. 607 + 608 + The frequency boost mechanism may be either hardware-based or software-based. 609 + If it is hardware-based (e.g. on x86), the decision to trigger the boosting is 610 + made by the hardware (although in general it requires the hardware to be put 611 + into a special state in which it can control the CPU frequency within certain 612 + limits). If it is software-based (e.g. on ARM), the scaling driver decides 613 + whether or not to trigger boosting and when to do that. 614 + 615 + The ``boost`` File in ``sysfs`` 616 + ------------------------------- 617 + 618 + This file is located under :file:`/sys/devices/system/cpu/cpufreq/` and controls 619 + the "boost" setting for the whole system. It is not present if the underlying 620 + scaling driver does not support the frequency boost mechanism (or supports it, 621 + but provides a driver-specific interface for controlling it, like 622 + ``intel_pstate``). 623 + 624 + If the value in this file is 1, the frequency boost mechanism is enabled. This 625 + means that either the hardware can be put into states in which it is able to 626 + trigger boosting (in the hardware-based case), or the software is allowed to 627 + trigger boosting (in the software-based case). It does not mean that boosting 628 + is actually in use at the moment on any CPUs in the system. It only means a 629 + permission to use the frequency boost mechanism (which still may never be used 630 + for other reasons). 631 + 632 + If the value in this file is 0, the frequency boost mechanism is disabled and 633 + cannot be used at all. 634 + 635 + The only values that can be written to this file are 0 and 1. 636 + 637 + Rationale for Boost Control Knob 638 + -------------------------------- 639 + 640 + The frequency boost mechanism is generally intended to help to achieve optimum 641 + CPU performance on time scales below software resolution (e.g. below the 642 + scheduler tick interval) and it is demonstrably suitable for many workloads, but 643 + it may lead to problems in certain situations. 644 + 645 + For this reason, many systems make it possible to disable the frequency boost 646 + mechanism in the platform firmware (BIOS) setup, but that requires the system to 647 + be restarted for the setting to be adjusted as desired, which may not be 648 + practical at least in some cases. For example: 649 + 650 + 1. Boosting means overclocking the processor, although under controlled 651 + conditions. Generally, the processor's energy consumption increases 652 + as a result of increasing its frequency and voltage, even temporarily. 653 + That may not be desirable on systems that switch to power sources of 654 + limited capacity, such as batteries, so the ability to disable the boost 655 + mechanism while the system is running may help there (but that depends on 656 + the workload too). 657 + 658 + 2. In some situations deterministic behavior is more important than 659 + performance or energy consumption (or both) and the ability to disable 660 + boosting while the system is running may be useful then. 661 + 662 + 3. To examine the impact of the frequency boost mechanism itself, it is useful 663 + to be able to run tests with and without boosting, preferably without 664 + restarting the system in the meantime. 665 + 666 + 4. Reproducible results are important when running benchmarks. Since 667 + the boosting functionality depends on the load of the whole package, 668 + single-thread performance may vary because of it which may lead to 669 + unreproducible results sometimes. That can be avoided by disabling the 670 + frequency boost mechanism before running benchmarks sensitive to that 671 + issue. 672 + 673 + Legacy AMD ``cpb`` Knob 674 + ----------------------- 675 + 676 + The AMD powernow-k8 scaling driver supports a ``sysfs`` knob very similar to 677 + the global ``boost`` one. It is used for disabling/enabling the "Core 678 + Performance Boost" feature of some AMD processors. 679 + 680 + If present, that knob is located in every ``CPUFreq`` policy directory in 681 + ``sysfs`` (:file:`/sys/devices/system/cpu/cpufreq/policyX/`) and is called 682 + ``cpb``, which indicates a more fine grained control interface. The actual 683 + implementation, however, works on the system-wide basis and setting that knob 684 + for one policy causes the same value of it to be set for all of the other 685 + policies at the same time. 686 + 687 + That knob is still supported on AMD processors that support its underlying 688 + hardware feature, but it may be configured out of the kernel (via the 689 + :c:macro:`CONFIG_X86_ACPI_CPUFREQ_CPB` configuration option) and the global 690 + ``boost`` knob is present regardless. Thus it is always possible use the 691 + ``boost`` knob instead of the ``cpb`` one which is highly recommended, as that 692 + is more consistent with what all of the other systems do (and the ``cpb`` knob 693 + may not be supported any more in the future). 694 + 695 + The ``cpb`` knob is never present for any processors without the underlying 696 + hardware feature (e.g. all Intel ones), even if the 697 + :c:macro:`CONFIG_X86_ACPI_CPUFREQ_CPB` configuration option is set. 698 + 699 + 700 + .. _Per-entity load tracking: https://lwn.net/Articles/531853/
+15
Documentation/admin-guide/pm/index.rst
··· 1 + ================ 2 + Power Management 3 + ================ 4 + 5 + .. toctree:: 6 + :maxdepth: 2 7 + 8 + cpufreq 9 + 10 + .. only:: subproject and html 11 + 12 + Indices 13 + ======= 14 + 15 + * :ref:`genindex`
+6 -6
Documentation/admin-guide/ras.rst
··· 8 8 ************ 9 9 10 10 Reliability, Availability and Serviceability (RAS) is a concept used on 11 - servers meant to measure their robusteness. 11 + servers meant to measure their robustness. 12 12 13 13 Reliability 14 14 is the probability that a system will produce correct outputs. ··· 42 42 43 43 * CPU – detect errors at instruction execution and at L1/L2/L3 caches; 44 44 * Memory – add error correction logic (ECC) to detect and correct errors; 45 - * I/O – add CRC checksums for tranfered data; 45 + * I/O – add CRC checksums for transferred data; 46 46 * Storage – RAID, journal file systems, checksums, 47 47 Self-Monitoring, Analysis and Reporting Technology (SMART). 48 48 49 49 By monitoring the number of occurrences of error detections, it is possible 50 50 to identify if the probability of hardware errors is increasing, and, on such 51 - case, do a preventive maintainance to replace a degrated component while 51 + case, do a preventive maintenance to replace a degraded component while 52 52 those errors are correctable. 53 53 54 54 Types of errors ··· 121 121 On the above example, a DDR4 SO-DIMM memory module is located at the 122 122 system's memory labeled as "BANK 0", as given by the *bank locator* field. 123 123 Please notice that, on such system, the *total width* is equal to the 124 - *data witdh*. It means that such memory module doesn't have error 124 + *data width*. It means that such memory module doesn't have error 125 125 detection/correction mechanisms. 126 126 127 127 Unfortunately, not all systems use the same field to specify the memory ··· 145 145 146 146 There, the DDR3 RDIMM memory module is located at the system's memory labeled 147 147 as "DIMM_A1", as given by the *locator* field. Please notice that this 148 - memory module has 64 bits of *data witdh* and 72 bits of *total width*. So, 148 + memory module has 64 bits of *data width* and 72 bits of *total width*. So, 149 149 it has 8 extra bits to be used by error detection and correction mechanisms. 150 150 Such kind of memory is called Error-correcting code memory (ECC memory). 151 151 ··· 186 186 .. [#f1] Please notice that several memory controllers allow operation on a 187 187 mode called "Lock-Step", where it groups two memory modules together, 188 188 doing 128-bit reads/writes. That gives 16 bits for error correction, with 189 - significatively improves the error correction mechanism, at the expense 189 + significantly improves the error correction mechanism, at the expense 190 190 that, when an error happens, there's no way to know what memory module is 191 191 to blame. So, it has to blame both memory modules. 192 192
+34 -5
Documentation/admin-guide/security-bugs.rst
··· 14 14 The Linux kernel security team can be contacted by email at 15 15 <security@kernel.org>. This is a private list of security officers 16 16 who will help verify the bug report and develop and release a fix. 17 - It is possible that the security team will bring in extra help from 18 - area maintainers to understand and fix the security vulnerability. 17 + If you already have a fix, please include it with your report, as 18 + that can speed up the process considerably. It is possible that the 19 + security team will bring in extra help from area maintainers to 20 + understand and fix the security vulnerability. 19 21 20 22 As it is with any bug, the more information provided the easier it 21 23 will be to diagnose and fix. Please review the procedure outlined in 22 - admin-guide/reporting-bugs.rst if you are unclear about what information is helpful. 23 - Any exploit code is very helpful and will not be released without 24 - consent from the reporter unless it has already been made public. 24 + admin-guide/reporting-bugs.rst if you are unclear about what 25 + information is helpful. Any exploit code is very helpful and will not 26 + be released without consent from the reporter unless it has already been 27 + made public. 25 28 26 29 Disclosure 27 30 ---------- ··· 41 38 disclosure is from immediate (esp. if it's already publicly known) 42 39 to a few weeks. As a basic default policy, we expect report date to 43 40 disclosure date to be on the order of 7 days. 41 + 42 + Coordination 43 + ------------ 44 + 45 + Fixes for sensitive bugs, such as those that might lead to privilege 46 + escalations, may need to be coordinated with the private 47 + <linux-distros@vs.openwall.org> mailing list so that distribution vendors 48 + are well prepared to issue a fixed kernel upon public disclosure of the 49 + upstream fix. Distros will need some time to test the proposed patch and 50 + will generally request at least a few days of embargo, and vendor update 51 + publication prefers to happen Tuesday through Thursday. When appropriate, 52 + the security team can assist with this coordination, or the reporter can 53 + include linux-distros from the start. In this case, remember to prefix 54 + the email Subject line with "[vs]" as described in the linux-distros wiki: 55 + <http://oss-security.openwall.org/wiki/mailing-lists/distros#how-to-use-the-lists> 56 + 57 + CVE assignment 58 + -------------- 59 + 60 + The security team does not normally assign CVEs, nor do we require them 61 + for reports or fixes, as this can needlessly complicate the process and 62 + may delay the bug handling. If a reporter wishes to have a CVE identifier 63 + assigned ahead of public disclosure, they will need to contact the private 64 + linux-distros list, described above. When such a CVE identifier is known 65 + before a patch is provided, it is desirable to mention it in the commit 66 + message, though. 44 67 45 68 Non-disclosure agreements 46 69 -------------------------
+2 -1
Documentation/admin-guide/sysrq.rst
··· 212 212 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 213 213 214 214 There are some keyboards that produce a different keycode for SysRq than the 215 - pre-defined value of 99 (see ``KEY_SYSRQ`` in ``include/linux/input.h``), or 215 + pre-defined value of 99 216 + (see ``KEY_SYSRQ`` in ``include/uapi/linux/input-event-codes.h``), or 216 217 which don't have a SysRq key at all. In these cases, run ``showkey -s`` to find 217 218 an appropriate scancode sequence, and use ``setkeycodes <sequence> 99`` to map 218 219 this sequence to the usual SysRq code (e.g., ``setkeycodes e05b 99``). It's
+1 -1
Documentation/arm/mem_alignment
··· 48 48 For example, the following will turn on the warnings, but without 49 49 fixing up or sending SIGBUS signals: 50 50 51 - echo 1 > /proc/sys/debug/alignment 51 + echo 1 > /proc/cpu/alignment 52 52 53 53 You can also read the content of the same file to get statistical 54 54 information on unaligned access occurrences plus the current mode of
+3 -3
Documentation/conf.py
··· 17 17 import sphinx 18 18 19 19 # Get Sphinx version 20 - major, minor, patch = map(int, sphinx.__version__.split(".")) 20 + major, minor, patch = sphinx.version_info[:3] 21 21 22 22 23 23 # If extensions (or modules to document with autodoc) are in another directory, ··· 29 29 # -- General configuration ------------------------------------------------ 30 30 31 31 # If your documentation needs a minimal Sphinx version, state it here. 32 - #needs_sphinx = '1.0' 32 + needs_sphinx = '1.2' 33 33 34 34 # Add any Sphinx extension module names here, as strings. They can be 35 35 # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 36 36 # ones. 37 - extensions = ['kerneldoc', 'rstFlatTable', 'kernel_include', 'cdomain'] 37 + extensions = ['kerneldoc', 'rstFlatTable', 'kernel_include', 'cdomain', 'kfigure'] 38 38 39 39 # The name of the math extension changed on Sphinx 1.4 40 40 if major == 1 and minor > 3:
+130
Documentation/core-api/flexible-arrays.rst
··· 1 + 2 + =================================== 3 + Using flexible arrays in the kernel 4 + =================================== 5 + 6 + Large contiguous memory allocations can be unreliable in the Linux kernel. 7 + Kernel programmers will sometimes respond to this problem by allocating 8 + pages with :c:func:`vmalloc()`. This solution not ideal, though. On 32-bit 9 + systems, memory from vmalloc() must be mapped into a relatively small address 10 + space; it's easy to run out. On SMP systems, the page table changes required 11 + by vmalloc() allocations can require expensive cross-processor interrupts on 12 + all CPUs. And, on all systems, use of space in the vmalloc() range increases 13 + pressure on the translation lookaside buffer (TLB), reducing the performance 14 + of the system. 15 + 16 + In many cases, the need for memory from vmalloc() can be eliminated by piecing 17 + together an array from smaller parts; the flexible array library exists to make 18 + this task easier. 19 + 20 + A flexible array holds an arbitrary (within limits) number of fixed-sized 21 + objects, accessed via an integer index. Sparse arrays are handled 22 + reasonably well. Only single-page allocations are made, so memory 23 + allocation failures should be relatively rare. The down sides are that the 24 + arrays cannot be indexed directly, individual object size cannot exceed the 25 + system page size, and putting data into a flexible array requires a copy 26 + operation. It's also worth noting that flexible arrays do no internal 27 + locking at all; if concurrent access to an array is possible, then the 28 + caller must arrange for appropriate mutual exclusion. 29 + 30 + The creation of a flexible array is done with :c:func:`flex_array_alloc()`:: 31 + 32 + #include <linux/flex_array.h> 33 + 34 + struct flex_array *flex_array_alloc(int element_size, 35 + unsigned int total, 36 + gfp_t flags); 37 + 38 + The individual object size is provided by ``element_size``, while total is the 39 + maximum number of objects which can be stored in the array. The flags 40 + argument is passed directly to the internal memory allocation calls. With 41 + the current code, using flags to ask for high memory is likely to lead to 42 + notably unpleasant side effects. 43 + 44 + It is also possible to define flexible arrays at compile time with:: 45 + 46 + DEFINE_FLEX_ARRAY(name, element_size, total); 47 + 48 + This macro will result in a definition of an array with the given name; the 49 + element size and total will be checked for validity at compile time. 50 + 51 + Storing data into a flexible array is accomplished with a call to 52 + :c:func:`flex_array_put()`:: 53 + 54 + int flex_array_put(struct flex_array *array, unsigned int element_nr, 55 + void *src, gfp_t flags); 56 + 57 + This call will copy the data from src into the array, in the position 58 + indicated by ``element_nr`` (which must be less than the maximum specified when 59 + the array was created). If any memory allocations must be performed, flags 60 + will be used. The return value is zero on success, a negative error code 61 + otherwise. 62 + 63 + There might possibly be a need to store data into a flexible array while 64 + running in some sort of atomic context; in this situation, sleeping in the 65 + memory allocator would be a bad thing. That can be avoided by using 66 + ``GFP_ATOMIC`` for the flags value, but, often, there is a better way. The 67 + trick is to ensure that any needed memory allocations are done before 68 + entering atomic context, using :c:func:`flex_array_prealloc()`:: 69 + 70 + int flex_array_prealloc(struct flex_array *array, unsigned int start, 71 + unsigned int nr_elements, gfp_t flags); 72 + 73 + This function will ensure that memory for the elements indexed in the range 74 + defined by ``start`` and ``nr_elements`` has been allocated. Thereafter, a 75 + ``flex_array_put()`` call on an element in that range is guaranteed not to 76 + block. 77 + 78 + Getting data back out of the array is done with :c:func:`flex_array_get()`:: 79 + 80 + void *flex_array_get(struct flex_array *fa, unsigned int element_nr); 81 + 82 + The return value is a pointer to the data element, or NULL if that 83 + particular element has never been allocated. 84 + 85 + Note that it is possible to get back a valid pointer for an element which 86 + has never been stored in the array. Memory for array elements is allocated 87 + one page at a time; a single allocation could provide memory for several 88 + adjacent elements. Flexible array elements are normally initialized to the 89 + value ``FLEX_ARRAY_FREE`` (defined as 0x6c in <linux/poison.h>), so errors 90 + involving that number probably result from use of unstored array entries. 91 + Note that, if array elements are allocated with ``__GFP_ZERO``, they will be 92 + initialized to zero and this poisoning will not happen. 93 + 94 + Individual elements in the array can be cleared with 95 + :c:func:`flex_array_clear()`:: 96 + 97 + int flex_array_clear(struct flex_array *array, unsigned int element_nr); 98 + 99 + This function will set the given element to ``FLEX_ARRAY_FREE`` and return 100 + zero. If storage for the indicated element is not allocated for the array, 101 + ``flex_array_clear()`` will return ``-EINVAL`` instead. Note that clearing an 102 + element does not release the storage associated with it; to reduce the 103 + allocated size of an array, call :c:func:`flex_array_shrink()`:: 104 + 105 + int flex_array_shrink(struct flex_array *array); 106 + 107 + The return value will be the number of pages of memory actually freed. 108 + This function works by scanning the array for pages containing nothing but 109 + ``FLEX_ARRAY_FREE`` bytes, so (1) it can be expensive, and (2) it will not work 110 + if the array's pages are allocated with ``__GFP_ZERO``. 111 + 112 + It is possible to remove all elements of an array with a call to 113 + :c:func:`flex_array_free_parts()`:: 114 + 115 + void flex_array_free_parts(struct flex_array *array); 116 + 117 + This call frees all elements, but leaves the array itself in place. 118 + Freeing the entire array is done with :c:func:`flex_array_free()`:: 119 + 120 + void flex_array_free(struct flex_array *array); 121 + 122 + As of this writing, there are no users of flexible arrays in the mainline 123 + kernel. The functions described here are also not exported to modules; 124 + that will probably be fixed when somebody comes up with a need for it. 125 + 126 + 127 + Flexible array functions 128 + ------------------------ 129 + 130 + .. kernel-doc:: include/linux/flex_array.h
+440
Documentation/core-api/genericirq.rst
··· 1 + .. include:: <isonum.txt> 2 + 3 + ========================== 4 + Linux generic IRQ handling 5 + ========================== 6 + 7 + :Copyright: |copy| 2005-2010: Thomas Gleixner 8 + :Copyright: |copy| 2005-2006: Ingo Molnar 9 + 10 + Introduction 11 + ============ 12 + 13 + The generic interrupt handling layer is designed to provide a complete 14 + abstraction of interrupt handling for device drivers. It is able to 15 + handle all the different types of interrupt controller hardware. Device 16 + drivers use generic API functions to request, enable, disable and free 17 + interrupts. The drivers do not have to know anything about interrupt 18 + hardware details, so they can be used on different platforms without 19 + code changes. 20 + 21 + This documentation is provided to developers who want to implement an 22 + interrupt subsystem based for their architecture, with the help of the 23 + generic IRQ handling layer. 24 + 25 + Rationale 26 + ========= 27 + 28 + The original implementation of interrupt handling in Linux uses the 29 + :c:func:`__do_IRQ` super-handler, which is able to deal with every type of 30 + interrupt logic. 31 + 32 + Originally, Russell King identified different types of handlers to build 33 + a quite universal set for the ARM interrupt handler implementation in 34 + Linux 2.5/2.6. He distinguished between: 35 + 36 + - Level type 37 + 38 + - Edge type 39 + 40 + - Simple type 41 + 42 + During the implementation we identified another type: 43 + 44 + - Fast EOI type 45 + 46 + In the SMP world of the :c:func:`__do_IRQ` super-handler another type was 47 + identified: 48 + 49 + - Per CPU type 50 + 51 + This split implementation of high-level IRQ handlers allows us to 52 + optimize the flow of the interrupt handling for each specific interrupt 53 + type. This reduces complexity in that particular code path and allows 54 + the optimized handling of a given type. 55 + 56 + The original general IRQ implementation used hw_interrupt_type 57 + structures and their ``->ack``, ``->end`` [etc.] callbacks to differentiate 58 + the flow control in the super-handler. This leads to a mix of flow logic 59 + and low-level hardware logic, and it also leads to unnecessary code 60 + duplication: for example in i386, there is an ``ioapic_level_irq`` and an 61 + ``ioapic_edge_irq`` IRQ-type which share many of the low-level details but 62 + have different flow handling. 63 + 64 + A more natural abstraction is the clean separation of the 'irq flow' and 65 + the 'chip details'. 66 + 67 + Analysing a couple of architecture's IRQ subsystem implementations 68 + reveals that most of them can use a generic set of 'irq flow' methods 69 + and only need to add the chip-level specific code. The separation is 70 + also valuable for (sub)architectures which need specific quirks in the 71 + IRQ flow itself but not in the chip details - and thus provides a more 72 + transparent IRQ subsystem design. 73 + 74 + Each interrupt descriptor is assigned its own high-level flow handler, 75 + which is normally one of the generic implementations. (This high-level 76 + flow handler implementation also makes it simple to provide 77 + demultiplexing handlers which can be found in embedded platforms on 78 + various architectures.) 79 + 80 + The separation makes the generic interrupt handling layer more flexible 81 + and extensible. For example, an (sub)architecture can use a generic 82 + IRQ-flow implementation for 'level type' interrupts and add a 83 + (sub)architecture specific 'edge type' implementation. 84 + 85 + To make the transition to the new model easier and prevent the breakage 86 + of existing implementations, the :c:func:`__do_IRQ` super-handler is still 87 + available. This leads to a kind of duality for the time being. Over time 88 + the new model should be used in more and more architectures, as it 89 + enables smaller and cleaner IRQ subsystems. It's deprecated for three 90 + years now and about to be removed. 91 + 92 + Known Bugs And Assumptions 93 + ========================== 94 + 95 + None (knock on wood). 96 + 97 + Abstraction layers 98 + ================== 99 + 100 + There are three main levels of abstraction in the interrupt code: 101 + 102 + 1. High-level driver API 103 + 104 + 2. High-level IRQ flow handlers 105 + 106 + 3. Chip-level hardware encapsulation 107 + 108 + Interrupt control flow 109 + ---------------------- 110 + 111 + Each interrupt is described by an interrupt descriptor structure 112 + irq_desc. The interrupt is referenced by an 'unsigned int' numeric 113 + value which selects the corresponding interrupt description structure in 114 + the descriptor structures array. The descriptor structure contains 115 + status information and pointers to the interrupt flow method and the 116 + interrupt chip structure which are assigned to this interrupt. 117 + 118 + Whenever an interrupt triggers, the low-level architecture code calls 119 + into the generic interrupt code by calling :c:func:`desc->handle_irq`. This 120 + high-level IRQ handling function only uses desc->irq_data.chip 121 + primitives referenced by the assigned chip descriptor structure. 122 + 123 + High-level Driver API 124 + --------------------- 125 + 126 + The high-level Driver API consists of following functions: 127 + 128 + - :c:func:`request_irq` 129 + 130 + - :c:func:`free_irq` 131 + 132 + - :c:func:`disable_irq` 133 + 134 + - :c:func:`enable_irq` 135 + 136 + - :c:func:`disable_irq_nosync` (SMP only) 137 + 138 + - :c:func:`synchronize_irq` (SMP only) 139 + 140 + - :c:func:`irq_set_irq_type` 141 + 142 + - :c:func:`irq_set_irq_wake` 143 + 144 + - :c:func:`irq_set_handler_data` 145 + 146 + - :c:func:`irq_set_chip` 147 + 148 + - :c:func:`irq_set_chip_data` 149 + 150 + See the autogenerated function documentation for details. 151 + 152 + High-level IRQ flow handlers 153 + ---------------------------- 154 + 155 + The generic layer provides a set of pre-defined irq-flow methods: 156 + 157 + - :c:func:`handle_level_irq` 158 + 159 + - :c:func:`handle_edge_irq` 160 + 161 + - :c:func:`handle_fasteoi_irq` 162 + 163 + - :c:func:`handle_simple_irq` 164 + 165 + - :c:func:`handle_percpu_irq` 166 + 167 + - :c:func:`handle_edge_eoi_irq` 168 + 169 + - :c:func:`handle_bad_irq` 170 + 171 + The interrupt flow handlers (either pre-defined or architecture 172 + specific) are assigned to specific interrupts by the architecture either 173 + during bootup or during device initialization. 174 + 175 + Default flow implementations 176 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 177 + 178 + Helper functions 179 + ^^^^^^^^^^^^^^^^ 180 + 181 + The helper functions call the chip primitives and are used by the 182 + default flow implementations. The following helper functions are 183 + implemented (simplified excerpt):: 184 + 185 + default_enable(struct irq_data *data) 186 + { 187 + desc->irq_data.chip->irq_unmask(data); 188 + } 189 + 190 + default_disable(struct irq_data *data) 191 + { 192 + if (!delay_disable(data)) 193 + desc->irq_data.chip->irq_mask(data); 194 + } 195 + 196 + default_ack(struct irq_data *data) 197 + { 198 + chip->irq_ack(data); 199 + } 200 + 201 + default_mask_ack(struct irq_data *data) 202 + { 203 + if (chip->irq_mask_ack) { 204 + chip->irq_mask_ack(data); 205 + } else { 206 + chip->irq_mask(data); 207 + chip->irq_ack(data); 208 + } 209 + } 210 + 211 + noop(struct irq_data *data)) 212 + { 213 + } 214 + 215 + 216 + 217 + Default flow handler implementations 218 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 219 + 220 + Default Level IRQ flow handler 221 + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 222 + 223 + handle_level_irq provides a generic implementation for level-triggered 224 + interrupts. 225 + 226 + The following control flow is implemented (simplified excerpt):: 227 + 228 + :c:func:`desc->irq_data.chip->irq_mask_ack`; 229 + handle_irq_event(desc->action); 230 + :c:func:`desc->irq_data.chip->irq_unmask`; 231 + 232 + 233 + Default Fast EOI IRQ flow handler 234 + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 235 + 236 + handle_fasteoi_irq provides a generic implementation for interrupts, 237 + which only need an EOI at the end of the handler. 238 + 239 + The following control flow is implemented (simplified excerpt):: 240 + 241 + handle_irq_event(desc->action); 242 + :c:func:`desc->irq_data.chip->irq_eoi`; 243 + 244 + 245 + Default Edge IRQ flow handler 246 + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 247 + 248 + handle_edge_irq provides a generic implementation for edge-triggered 249 + interrupts. 250 + 251 + The following control flow is implemented (simplified excerpt):: 252 + 253 + if (desc->status & running) { 254 + :c:func:`desc->irq_data.chip->irq_mask_ack`; 255 + desc->status |= pending | masked; 256 + return; 257 + } 258 + :c:func:`desc->irq_data.chip->irq_ack`; 259 + desc->status |= running; 260 + do { 261 + if (desc->status & masked) 262 + :c:func:`desc->irq_data.chip->irq_unmask`; 263 + desc->status &= ~pending; 264 + handle_irq_event(desc->action); 265 + } while (status & pending); 266 + desc->status &= ~running; 267 + 268 + 269 + Default simple IRQ flow handler 270 + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 271 + 272 + handle_simple_irq provides a generic implementation for simple 273 + interrupts. 274 + 275 + .. note:: 276 + 277 + The simple flow handler does not call any handler/chip primitives. 278 + 279 + The following control flow is implemented (simplified excerpt):: 280 + 281 + handle_irq_event(desc->action); 282 + 283 + 284 + Default per CPU flow handler 285 + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 286 + 287 + handle_percpu_irq provides a generic implementation for per CPU 288 + interrupts. 289 + 290 + Per CPU interrupts are only available on SMP and the handler provides a 291 + simplified version without locking. 292 + 293 + The following control flow is implemented (simplified excerpt):: 294 + 295 + if (desc->irq_data.chip->irq_ack) 296 + :c:func:`desc->irq_data.chip->irq_ack`; 297 + handle_irq_event(desc->action); 298 + if (desc->irq_data.chip->irq_eoi) 299 + :c:func:`desc->irq_data.chip->irq_eoi`; 300 + 301 + 302 + EOI Edge IRQ flow handler 303 + ^^^^^^^^^^^^^^^^^^^^^^^^^ 304 + 305 + handle_edge_eoi_irq provides an abnomination of the edge handler 306 + which is solely used to tame a badly wreckaged irq controller on 307 + powerpc/cell. 308 + 309 + Bad IRQ flow handler 310 + ^^^^^^^^^^^^^^^^^^^^ 311 + 312 + handle_bad_irq is used for spurious interrupts which have no real 313 + handler assigned.. 314 + 315 + Quirks and optimizations 316 + ~~~~~~~~~~~~~~~~~~~~~~~~ 317 + 318 + The generic functions are intended for 'clean' architectures and chips, 319 + which have no platform-specific IRQ handling quirks. If an architecture 320 + needs to implement quirks on the 'flow' level then it can do so by 321 + overriding the high-level irq-flow handler. 322 + 323 + Delayed interrupt disable 324 + ~~~~~~~~~~~~~~~~~~~~~~~~~ 325 + 326 + This per interrupt selectable feature, which was introduced by Russell 327 + King in the ARM interrupt implementation, does not mask an interrupt at 328 + the hardware level when :c:func:`disable_irq` is called. The interrupt is kept 329 + enabled and is masked in the flow handler when an interrupt event 330 + happens. This prevents losing edge interrupts on hardware which does not 331 + store an edge interrupt event while the interrupt is disabled at the 332 + hardware level. When an interrupt arrives while the IRQ_DISABLED flag 333 + is set, then the interrupt is masked at the hardware level and the 334 + IRQ_PENDING bit is set. When the interrupt is re-enabled by 335 + :c:func:`enable_irq` the pending bit is checked and if it is set, the interrupt 336 + is resent either via hardware or by a software resend mechanism. (It's 337 + necessary to enable CONFIG_HARDIRQS_SW_RESEND when you want to use 338 + the delayed interrupt disable feature and your hardware is not capable 339 + of retriggering an interrupt.) The delayed interrupt disable is not 340 + configurable. 341 + 342 + Chip-level hardware encapsulation 343 + --------------------------------- 344 + 345 + The chip-level hardware descriptor structure :c:type:`irq_chip` contains all 346 + the direct chip relevant functions, which can be utilized by the irq flow 347 + implementations. 348 + 349 + - ``irq_ack`` 350 + 351 + - ``irq_mask_ack`` - Optional, recommended for performance 352 + 353 + - ``irq_mask`` 354 + 355 + - ``irq_unmask`` 356 + 357 + - ``irq_eoi`` - Optional, required for EOI flow handlers 358 + 359 + - ``irq_retrigger`` - Optional 360 + 361 + - ``irq_set_type`` - Optional 362 + 363 + - ``irq_set_wake`` - Optional 364 + 365 + These primitives are strictly intended to mean what they say: ack means 366 + ACK, masking means masking of an IRQ line, etc. It is up to the flow 367 + handler(s) to use these basic units of low-level functionality. 368 + 369 + __do_IRQ entry point 370 + ==================== 371 + 372 + The original implementation :c:func:`__do_IRQ` was an alternative entry point 373 + for all types of interrupts. It no longer exists. 374 + 375 + This handler turned out to be not suitable for all interrupt hardware 376 + and was therefore reimplemented with split functionality for 377 + edge/level/simple/percpu interrupts. This is not only a functional 378 + optimization. It also shortens code paths for interrupts. 379 + 380 + Locking on SMP 381 + ============== 382 + 383 + The locking of chip registers is up to the architecture that defines the 384 + chip primitives. The per-irq structure is protected via desc->lock, by 385 + the generic layer. 386 + 387 + Generic interrupt chip 388 + ====================== 389 + 390 + To avoid copies of identical implementations of IRQ chips the core 391 + provides a configurable generic interrupt chip implementation. 392 + Developers should check carefully whether the generic chip fits their 393 + needs before implementing the same functionality slightly differently 394 + themselves. 395 + 396 + .. kernel-doc:: kernel/irq/generic-chip.c 397 + :export: 398 + 399 + Structures 400 + ========== 401 + 402 + This chapter contains the autogenerated documentation of the structures 403 + which are used in the generic IRQ layer. 404 + 405 + .. kernel-doc:: include/linux/irq.h 406 + :internal: 407 + 408 + .. kernel-doc:: include/linux/interrupt.h 409 + :internal: 410 + 411 + Public Functions Provided 412 + ========================= 413 + 414 + This chapter contains the autogenerated documentation of the kernel API 415 + functions which are exported. 416 + 417 + .. kernel-doc:: kernel/irq/manage.c 418 + 419 + .. kernel-doc:: kernel/irq/chip.c 420 + 421 + Internal Functions Provided 422 + =========================== 423 + 424 + This chapter contains the autogenerated documentation of the internal 425 + functions. 426 + 427 + .. kernel-doc:: kernel/irq/irqdesc.c 428 + 429 + .. kernel-doc:: kernel/irq/handle.c 430 + 431 + .. kernel-doc:: kernel/irq/chip.c 432 + 433 + Credits 434 + ======= 435 + 436 + The following people have contributed to this document: 437 + 438 + 1. Thomas Gleixner tglx@linutronix.de 439 + 440 + 2. Ingo Molnar mingo@elte.hu
+3
Documentation/core-api/index.rst
··· 11 11 .. toctree:: 12 12 :maxdepth: 1 13 13 14 + kernel-api 14 15 assoc_array 15 16 atomic_ops 16 17 cpu_hotplug 17 18 local_ops 18 19 workqueue 20 + genericirq 21 + flexible-arrays 19 22 20 23 Interfaces for kernel debugging 21 24 ===============================
+346
Documentation/core-api/kernel-api.rst
··· 1 + ==================== 2 + The Linux Kernel API 3 + ==================== 4 + 5 + Data Types 6 + ========== 7 + 8 + Doubly Linked Lists 9 + ------------------- 10 + 11 + .. kernel-doc:: include/linux/list.h 12 + :internal: 13 + 14 + Basic C Library Functions 15 + ========================= 16 + 17 + When writing drivers, you cannot in general use routines which are from 18 + the C Library. Some of the functions have been found generally useful 19 + and they are listed below. The behaviour of these functions may vary 20 + slightly from those defined by ANSI, and these deviations are noted in 21 + the text. 22 + 23 + String Conversions 24 + ------------------ 25 + 26 + .. kernel-doc:: lib/vsprintf.c 27 + :export: 28 + 29 + .. kernel-doc:: include/linux/kernel.h 30 + :functions: kstrtol 31 + 32 + .. kernel-doc:: include/linux/kernel.h 33 + :functions: kstrtoul 34 + 35 + .. kernel-doc:: lib/kstrtox.c 36 + :export: 37 + 38 + String Manipulation 39 + ------------------- 40 + 41 + .. kernel-doc:: lib/string.c 42 + :export: 43 + 44 + Bit Operations 45 + -------------- 46 + 47 + .. kernel-doc:: arch/x86/include/asm/bitops.h 48 + :internal: 49 + 50 + Basic Kernel Library Functions 51 + ============================== 52 + 53 + The Linux kernel provides more basic utility functions. 54 + 55 + Bitmap Operations 56 + ----------------- 57 + 58 + .. kernel-doc:: lib/bitmap.c 59 + :export: 60 + 61 + .. kernel-doc:: lib/bitmap.c 62 + :internal: 63 + 64 + Command-line Parsing 65 + -------------------- 66 + 67 + .. kernel-doc:: lib/cmdline.c 68 + :export: 69 + 70 + CRC Functions 71 + ------------- 72 + 73 + .. kernel-doc:: lib/crc7.c 74 + :export: 75 + 76 + .. kernel-doc:: lib/crc16.c 77 + :export: 78 + 79 + .. kernel-doc:: lib/crc-itu-t.c 80 + :export: 81 + 82 + .. kernel-doc:: lib/crc32.c 83 + 84 + .. kernel-doc:: lib/crc-ccitt.c 85 + :export: 86 + 87 + idr/ida Functions 88 + ----------------- 89 + 90 + .. kernel-doc:: include/linux/idr.h 91 + :doc: idr sync 92 + 93 + .. kernel-doc:: lib/idr.c 94 + :doc: IDA description 95 + 96 + .. kernel-doc:: lib/idr.c 97 + :export: 98 + 99 + Memory Management in Linux 100 + ========================== 101 + 102 + The Slab Cache 103 + -------------- 104 + 105 + .. kernel-doc:: include/linux/slab.h 106 + :internal: 107 + 108 + .. kernel-doc:: mm/slab.c 109 + :export: 110 + 111 + .. kernel-doc:: mm/util.c 112 + :export: 113 + 114 + User Space Memory Access 115 + ------------------------ 116 + 117 + .. kernel-doc:: arch/x86/include/asm/uaccess_32.h 118 + :internal: 119 + 120 + .. kernel-doc:: arch/x86/lib/usercopy_32.c 121 + :export: 122 + 123 + More Memory Management Functions 124 + -------------------------------- 125 + 126 + .. kernel-doc:: mm/readahead.c 127 + :export: 128 + 129 + .. kernel-doc:: mm/filemap.c 130 + :export: 131 + 132 + .. kernel-doc:: mm/memory.c 133 + :export: 134 + 135 + .. kernel-doc:: mm/vmalloc.c 136 + :export: 137 + 138 + .. kernel-doc:: mm/page_alloc.c 139 + :internal: 140 + 141 + .. kernel-doc:: mm/mempool.c 142 + :export: 143 + 144 + .. kernel-doc:: mm/dmapool.c 145 + :export: 146 + 147 + .. kernel-doc:: mm/page-writeback.c 148 + :export: 149 + 150 + .. kernel-doc:: mm/truncate.c 151 + :export: 152 + 153 + Kernel IPC facilities 154 + ===================== 155 + 156 + IPC utilities 157 + ------------- 158 + 159 + .. kernel-doc:: ipc/util.c 160 + :internal: 161 + 162 + FIFO Buffer 163 + =========== 164 + 165 + kfifo interface 166 + --------------- 167 + 168 + .. kernel-doc:: include/linux/kfifo.h 169 + :internal: 170 + 171 + relay interface support 172 + ======================= 173 + 174 + Relay interface support is designed to provide an efficient mechanism 175 + for tools and facilities to relay large amounts of data from kernel 176 + space to user space. 177 + 178 + relay interface 179 + --------------- 180 + 181 + .. kernel-doc:: kernel/relay.c 182 + :export: 183 + 184 + .. kernel-doc:: kernel/relay.c 185 + :internal: 186 + 187 + Module Support 188 + ============== 189 + 190 + Module Loading 191 + -------------- 192 + 193 + .. kernel-doc:: kernel/kmod.c 194 + :export: 195 + 196 + Inter Module support 197 + -------------------- 198 + 199 + Refer to the file kernel/module.c for more information. 200 + 201 + Hardware Interfaces 202 + =================== 203 + 204 + Interrupt Handling 205 + ------------------ 206 + 207 + .. kernel-doc:: kernel/irq/manage.c 208 + :export: 209 + 210 + DMA Channels 211 + ------------ 212 + 213 + .. kernel-doc:: kernel/dma.c 214 + :export: 215 + 216 + Resources Management 217 + -------------------- 218 + 219 + .. kernel-doc:: kernel/resource.c 220 + :internal: 221 + 222 + .. kernel-doc:: kernel/resource.c 223 + :export: 224 + 225 + MTRR Handling 226 + ------------- 227 + 228 + .. kernel-doc:: arch/x86/kernel/cpu/mtrr/main.c 229 + :export: 230 + 231 + Security Framework 232 + ================== 233 + 234 + .. kernel-doc:: security/security.c 235 + :internal: 236 + 237 + .. kernel-doc:: security/inode.c 238 + :export: 239 + 240 + Audit Interfaces 241 + ================ 242 + 243 + .. kernel-doc:: kernel/audit.c 244 + :export: 245 + 246 + .. kernel-doc:: kernel/auditsc.c 247 + :internal: 248 + 249 + .. kernel-doc:: kernel/auditfilter.c 250 + :internal: 251 + 252 + Accounting Framework 253 + ==================== 254 + 255 + .. kernel-doc:: kernel/acct.c 256 + :internal: 257 + 258 + Block Devices 259 + ============= 260 + 261 + .. kernel-doc:: block/blk-core.c 262 + :export: 263 + 264 + .. kernel-doc:: block/blk-core.c 265 + :internal: 266 + 267 + .. kernel-doc:: block/blk-map.c 268 + :export: 269 + 270 + .. kernel-doc:: block/blk-sysfs.c 271 + :internal: 272 + 273 + .. kernel-doc:: block/blk-settings.c 274 + :export: 275 + 276 + .. kernel-doc:: block/blk-exec.c 277 + :export: 278 + 279 + .. kernel-doc:: block/blk-flush.c 280 + :export: 281 + 282 + .. kernel-doc:: block/blk-lib.c 283 + :export: 284 + 285 + .. kernel-doc:: block/blk-tag.c 286 + :export: 287 + 288 + .. kernel-doc:: block/blk-tag.c 289 + :internal: 290 + 291 + .. kernel-doc:: block/blk-integrity.c 292 + :export: 293 + 294 + .. kernel-doc:: kernel/trace/blktrace.c 295 + :internal: 296 + 297 + .. kernel-doc:: block/genhd.c 298 + :internal: 299 + 300 + .. kernel-doc:: block/genhd.c 301 + :export: 302 + 303 + Char devices 304 + ============ 305 + 306 + .. kernel-doc:: fs/char_dev.c 307 + :export: 308 + 309 + Clock Framework 310 + =============== 311 + 312 + The clock framework defines programming interfaces to support software 313 + management of the system clock tree. This framework is widely used with 314 + System-On-Chip (SOC) platforms to support power management and various 315 + devices which may need custom clock rates. Note that these "clocks" 316 + don't relate to timekeeping or real time clocks (RTCs), each of which 317 + have separate frameworks. These :c:type:`struct clk <clk>` 318 + instances may be used to manage for example a 96 MHz signal that is used 319 + to shift bits into and out of peripherals or busses, or otherwise 320 + trigger synchronous state machine transitions in system hardware. 321 + 322 + Power management is supported by explicit software clock gating: unused 323 + clocks are disabled, so the system doesn't waste power changing the 324 + state of transistors that aren't in active use. On some systems this may 325 + be backed by hardware clock gating, where clocks are gated without being 326 + disabled in software. Sections of chips that are powered but not clocked 327 + may be able to retain their last state. This low power state is often 328 + called a *retention mode*. This mode still incurs leakage currents, 329 + especially with finer circuit geometries, but for CMOS circuits power is 330 + mostly used by clocked state changes. 331 + 332 + Power-aware drivers only enable their clocks when the device they manage 333 + is in active use. Also, system sleep states often differ according to 334 + which clock domains are active: while a "standby" state may allow wakeup 335 + from several active domains, a "mem" (suspend-to-RAM) state may require 336 + a more wholesale shutdown of clocks derived from higher speed PLLs and 337 + oscillators, limiting the number of possible wakeup event sources. A 338 + driver's suspend method may need to be aware of system-specific clock 339 + constraints on the target sleep state. 340 + 341 + Some platforms support programmable clock generators. These can be used 342 + by external chips of various kinds, such as other CPUs, multimedia 343 + codecs, and devices with strict requirements for interface clocking. 344 + 345 + .. kernel-doc:: include/linux/clk.h 346 + :internal:
-93
Documentation/cpu-freq/boost.txt
··· 1 - Processor boosting control 2 - 3 - - information for users - 4 - 5 - Quick guide for the impatient: 6 - -------------------- 7 - /sys/devices/system/cpu/cpufreq/boost 8 - controls the boost setting for the whole system. You can read and write 9 - that file with either "0" (boosting disabled) or "1" (boosting allowed). 10 - Reading or writing 1 does not mean that the system is boosting at this 11 - very moment, but only that the CPU _may_ raise the frequency at it's 12 - discretion. 13 - -------------------- 14 - 15 - Introduction 16 - ------------- 17 - Some CPUs support a functionality to raise the operating frequency of 18 - some cores in a multi-core package if certain conditions apply, mostly 19 - if the whole chip is not fully utilized and below it's intended thermal 20 - budget. The decision about boost disable/enable is made either at hardware 21 - (e.g. x86) or software (e.g ARM). 22 - On Intel CPUs this is called "Turbo Boost", AMD calls it "Turbo-Core", 23 - in technical documentation "Core performance boost". In Linux we use 24 - the term "boost" for convenience. 25 - 26 - Rationale for disable switch 27 - ---------------------------- 28 - 29 - Though the idea is to just give better performance without any user 30 - intervention, sometimes the need arises to disable this functionality. 31 - Most systems offer a switch in the (BIOS) firmware to disable the 32 - functionality at all, but a more fine-grained and dynamic control would 33 - be desirable: 34 - 1. While running benchmarks, reproducible results are important. Since 35 - the boosting functionality depends on the load of the whole package, 36 - single thread performance can vary. By explicitly disabling the boost 37 - functionality at least for the benchmark's run-time the system will run 38 - at a fixed frequency and results are reproducible again. 39 - 2. To examine the impact of the boosting functionality it is helpful 40 - to do tests with and without boosting. 41 - 3. Boosting means overclocking the processor, though under controlled 42 - conditions. By raising the frequency and the voltage the processor 43 - will consume more power than without the boosting, which may be 44 - undesirable for instance for mobile users. Disabling boosting may 45 - save power here, though this depends on the workload. 46 - 47 - 48 - User controlled switch 49 - ---------------------- 50 - 51 - To allow the user to toggle the boosting functionality, the cpufreq core 52 - driver exports a sysfs knob to enable or disable it. There is a file: 53 - /sys/devices/system/cpu/cpufreq/boost 54 - which can either read "0" (boosting disabled) or "1" (boosting enabled). 55 - The file is exported only when cpufreq driver supports boosting. 56 - Explicitly changing the permissions and writing to that file anyway will 57 - return EINVAL. 58 - 59 - On supported CPUs one can write either a "0" or a "1" into this file. 60 - This will either disable the boost functionality on all cores in the 61 - whole system (0) or will allow the software or hardware to boost at will 62 - (1). 63 - 64 - Writing a "1" does not explicitly boost the system, but just allows the 65 - CPU to boost at their discretion. Some implementations take external 66 - factors like the chip's temperature into account, so boosting once does 67 - not necessarily mean that it will occur every time even using the exact 68 - same software setup. 69 - 70 - 71 - AMD legacy cpb switch 72 - --------------------- 73 - The AMD powernow-k8 driver used to support a very similar switch to 74 - disable or enable the "Core Performance Boost" feature of some AMD CPUs. 75 - This switch was instantiated in each CPU's cpufreq directory 76 - (/sys/devices/system/cpu[0-9]*/cpufreq) and was called "cpb". 77 - Though the per CPU existence hints at a more fine grained control, the 78 - actual implementation only supported a system-global switch semantics, 79 - which was simply reflected into each CPU's file. Writing a 0 or 1 into it 80 - would pull the other CPUs to the same state. 81 - For compatibility reasons this file and its behavior is still supported 82 - on AMD CPUs, though it is now protected by a config switch 83 - (X86_ACPI_CPUFREQ_CPB). On Intel CPUs this file will never be created, 84 - even with the config option set. 85 - This functionality is considered legacy and will be removed in some future 86 - kernel version. 87 - 88 - More fine grained boosting control 89 - ---------------------------------- 90 - 91 - Technically it is possible to switch the boosting functionality at least 92 - on a per package basis, for some CPUs even per core. Currently the driver 93 - does not support it, but this may be implemented in the future.
+1 -1
Documentation/cpu-freq/cpu-drivers.txt
··· 231 231 Only for drivers with target_index() and CPUFREQ_ASYNC_NOTIFICATION unset. 232 232 233 233 get_intermediate should return a stable intermediate frequency platform wants to 234 - switch to, and target_intermediate() should set CPU to to that frequency, before 234 + switch to, and target_intermediate() should set CPU to that frequency, before 235 235 jumping to the frequency corresponding to 'index'. Core will take care of 236 236 sending notifications and driver doesn't have to handle them in 237 237 target_intermediate() or target_index().
-301
Documentation/cpu-freq/governors.txt
··· 1 - CPU frequency and voltage scaling code in the Linux(TM) kernel 2 - 3 - 4 - L i n u x C P U F r e q 5 - 6 - C P U F r e q G o v e r n o r s 7 - 8 - - information for users and developers - 9 - 10 - 11 - Dominik Brodowski <linux@brodo.de> 12 - some additions and corrections by Nico Golde <nico@ngolde.de> 13 - Rafael J. Wysocki <rafael.j.wysocki@intel.com> 14 - Viresh Kumar <viresh.kumar@linaro.org> 15 - 16 - 17 - 18 - Clock scaling allows you to change the clock speed of the CPUs on the 19 - fly. This is a nice method to save battery power, because the lower 20 - the clock speed, the less power the CPU consumes. 21 - 22 - 23 - Contents: 24 - --------- 25 - 1. What is a CPUFreq Governor? 26 - 27 - 2. Governors In the Linux Kernel 28 - 2.1 Performance 29 - 2.2 Powersave 30 - 2.3 Userspace 31 - 2.4 Ondemand 32 - 2.5 Conservative 33 - 2.6 Schedutil 34 - 35 - 3. The Governor Interface in the CPUfreq Core 36 - 37 - 4. References 38 - 39 - 40 - 1. What Is A CPUFreq Governor? 41 - ============================== 42 - 43 - Most cpufreq drivers (except the intel_pstate and longrun) or even most 44 - cpu frequency scaling algorithms only allow the CPU frequency to be set 45 - to predefined fixed values. In order to offer dynamic frequency 46 - scaling, the cpufreq core must be able to tell these drivers of a 47 - "target frequency". So these specific drivers will be transformed to 48 - offer a "->target/target_index/fast_switch()" call instead of the 49 - "->setpolicy()" call. For set_policy drivers, all stays the same, 50 - though. 51 - 52 - How to decide what frequency within the CPUfreq policy should be used? 53 - That's done using "cpufreq governors". 54 - 55 - Basically, it's the following flow graph: 56 - 57 - CPU can be set to switch independently | CPU can only be set 58 - within specific "limits" | to specific frequencies 59 - 60 - "CPUfreq policy" 61 - consists of frequency limits (policy->{min,max}) 62 - and CPUfreq governor to be used 63 - / \ 64 - / \ 65 - / the cpufreq governor decides 66 - / (dynamically or statically) 67 - / what target_freq to set within 68 - / the limits of policy->{min,max} 69 - / \ 70 - / \ 71 - Using the ->setpolicy call, Using the ->target/target_index/fast_switch call, 72 - the limits and the the frequency closest 73 - "policy" is set. to target_freq is set. 74 - It is assured that it 75 - is within policy->{min,max} 76 - 77 - 78 - 2. Governors In the Linux Kernel 79 - ================================ 80 - 81 - 2.1 Performance 82 - --------------- 83 - 84 - The CPUfreq governor "performance" sets the CPU statically to the 85 - highest frequency within the borders of scaling_min_freq and 86 - scaling_max_freq. 87 - 88 - 89 - 2.2 Powersave 90 - ------------- 91 - 92 - The CPUfreq governor "powersave" sets the CPU statically to the 93 - lowest frequency within the borders of scaling_min_freq and 94 - scaling_max_freq. 95 - 96 - 97 - 2.3 Userspace 98 - ------------- 99 - 100 - The CPUfreq governor "userspace" allows the user, or any userspace 101 - program running with UID "root", to set the CPU to a specific frequency 102 - by making a sysfs file "scaling_setspeed" available in the CPU-device 103 - directory. 104 - 105 - 106 - 2.4 Ondemand 107 - ------------ 108 - 109 - The CPUfreq governor "ondemand" sets the CPU frequency depending on the 110 - current system load. Load estimation is triggered by the scheduler 111 - through the update_util_data->func hook; when triggered, cpufreq checks 112 - the CPU-usage statistics over the last period and the governor sets the 113 - CPU accordingly. The CPU must have the capability to switch the 114 - frequency very quickly. 115 - 116 - Sysfs files: 117 - 118 - * sampling_rate: 119 - 120 - Measured in uS (10^-6 seconds), this is how often you want the kernel 121 - to look at the CPU usage and to make decisions on what to do about the 122 - frequency. Typically this is set to values of around '10000' or more. 123 - It's default value is (cmp. with users-guide.txt): transition_latency 124 - * 1000. Be aware that transition latency is in ns and sampling_rate 125 - is in us, so you get the same sysfs value by default. Sampling rate 126 - should always get adjusted considering the transition latency to set 127 - the sampling rate 750 times as high as the transition latency in the 128 - bash (as said, 1000 is default), do: 129 - 130 - $ echo `$(($(cat cpuinfo_transition_latency) * 750 / 1000)) > ondemand/sampling_rate 131 - 132 - * sampling_rate_min: 133 - 134 - The sampling rate is limited by the HW transition latency: 135 - transition_latency * 100 136 - 137 - Or by kernel restrictions: 138 - - If CONFIG_NO_HZ_COMMON is set, the limit is 10ms fixed. 139 - - If CONFIG_NO_HZ_COMMON is not set or nohz=off boot parameter is 140 - used, the limits depend on the CONFIG_HZ option: 141 - HZ=1000: min=20000us (20ms) 142 - HZ=250: min=80000us (80ms) 143 - HZ=100: min=200000us (200ms) 144 - 145 - The highest value of kernel and HW latency restrictions is shown and 146 - used as the minimum sampling rate. 147 - 148 - * up_threshold: 149 - 150 - This defines what the average CPU usage between the samplings of 151 - 'sampling_rate' needs to be for the kernel to make a decision on 152 - whether it should increase the frequency. For example when it is set 153 - to its default value of '95' it means that between the checking 154 - intervals the CPU needs to be on average more than 95% in use to then 155 - decide that the CPU frequency needs to be increased. 156 - 157 - * ignore_nice_load: 158 - 159 - This parameter takes a value of '0' or '1'. When set to '0' (its 160 - default), all processes are counted towards the 'cpu utilisation' 161 - value. When set to '1', the processes that are run with a 'nice' 162 - value will not count (and thus be ignored) in the overall usage 163 - calculation. This is useful if you are running a CPU intensive 164 - calculation on your laptop that you do not care how long it takes to 165 - complete as you can 'nice' it and prevent it from taking part in the 166 - deciding process of whether to increase your CPU frequency. 167 - 168 - * sampling_down_factor: 169 - 170 - This parameter controls the rate at which the kernel makes a decision 171 - on when to decrease the frequency while running at top speed. When set 172 - to 1 (the default) decisions to reevaluate load are made at the same 173 - interval regardless of current clock speed. But when set to greater 174 - than 1 (e.g. 100) it acts as a multiplier for the scheduling interval 175 - for reevaluating load when the CPU is at its top speed due to high 176 - load. This improves performance by reducing the overhead of load 177 - evaluation and helping the CPU stay at its top speed when truly busy, 178 - rather than shifting back and forth in speed. This tunable has no 179 - effect on behavior at lower speeds/lower CPU loads. 180 - 181 - * powersave_bias: 182 - 183 - This parameter takes a value between 0 to 1000. It defines the 184 - percentage (times 10) value of the target frequency that will be 185 - shaved off of the target. For example, when set to 100 -- 10%, when 186 - ondemand governor would have targeted 1000 MHz, it will target 187 - 1000 MHz - (10% of 1000 MHz) = 900 MHz instead. This is set to 0 188 - (disabled) by default. 189 - 190 - When AMD frequency sensitivity powersave bias driver -- 191 - drivers/cpufreq/amd_freq_sensitivity.c is loaded, this parameter 192 - defines the workload frequency sensitivity threshold in which a lower 193 - frequency is chosen instead of ondemand governor's original target. 194 - The frequency sensitivity is a hardware reported (on AMD Family 16h 195 - Processors and above) value between 0 to 100% that tells software how 196 - the performance of the workload running on a CPU will change when 197 - frequency changes. A workload with sensitivity of 0% (memory/IO-bound) 198 - will not perform any better on higher core frequency, whereas a 199 - workload with sensitivity of 100% (CPU-bound) will perform better 200 - higher the frequency. When the driver is loaded, this is set to 400 by 201 - default -- for CPUs running workloads with sensitivity value below 202 - 40%, a lower frequency is chosen. Unloading the driver or writing 0 203 - will disable this feature. 204 - 205 - 206 - 2.5 Conservative 207 - ---------------- 208 - 209 - The CPUfreq governor "conservative", much like the "ondemand" 210 - governor, sets the CPU frequency depending on the current usage. It 211 - differs in behaviour in that it gracefully increases and decreases the 212 - CPU speed rather than jumping to max speed the moment there is any load 213 - on the CPU. This behaviour is more suitable in a battery powered 214 - environment. The governor is tweaked in the same manner as the 215 - "ondemand" governor through sysfs with the addition of: 216 - 217 - * freq_step: 218 - 219 - This describes what percentage steps the cpu freq should be increased 220 - and decreased smoothly by. By default the cpu frequency will increase 221 - in 5% chunks of your maximum cpu frequency. You can change this value 222 - to anywhere between 0 and 100 where '0' will effectively lock your CPU 223 - at a speed regardless of its load whilst '100' will, in theory, make 224 - it behave identically to the "ondemand" governor. 225 - 226 - * down_threshold: 227 - 228 - Same as the 'up_threshold' found for the "ondemand" governor but for 229 - the opposite direction. For example when set to its default value of 230 - '20' it means that if the CPU usage needs to be below 20% between 231 - samples to have the frequency decreased. 232 - 233 - * sampling_down_factor: 234 - 235 - Similar functionality as in "ondemand" governor. But in 236 - "conservative", it controls the rate at which the kernel makes a 237 - decision on when to decrease the frequency while running in any speed. 238 - Load for frequency increase is still evaluated every sampling rate. 239 - 240 - 241 - 2.6 Schedutil 242 - ------------- 243 - 244 - The "schedutil" governor aims at better integration with the Linux 245 - kernel scheduler. Load estimation is achieved through the scheduler's 246 - Per-Entity Load Tracking (PELT) mechanism, which also provides 247 - information about the recent load [1]. This governor currently does 248 - load based DVFS only for tasks managed by CFS. RT and DL scheduler tasks 249 - are always run at the highest frequency. Unlike all the other 250 - governors, the code is located under the kernel/sched/ directory. 251 - 252 - Sysfs files: 253 - 254 - * rate_limit_us: 255 - 256 - This contains a value in microseconds. The governor waits for 257 - rate_limit_us time before reevaluating the load again, after it has 258 - evaluated the load once. 259 - 260 - For an in-depth comparison with the other governors refer to [2]. 261 - 262 - 263 - 3. The Governor Interface in the CPUfreq Core 264 - ============================================= 265 - 266 - A new governor must register itself with the CPUfreq core using 267 - "cpufreq_register_governor". The struct cpufreq_governor, which has to 268 - be passed to that function, must contain the following values: 269 - 270 - governor->name - A unique name for this governor. 271 - governor->owner - .THIS_MODULE for the governor module (if appropriate). 272 - 273 - plus a set of hooks to the functions implementing the governor's logic. 274 - 275 - The CPUfreq governor may call the CPU processor driver using one of 276 - these two functions: 277 - 278 - int cpufreq_driver_target(struct cpufreq_policy *policy, 279 - unsigned int target_freq, 280 - unsigned int relation); 281 - 282 - int __cpufreq_driver_target(struct cpufreq_policy *policy, 283 - unsigned int target_freq, 284 - unsigned int relation); 285 - 286 - target_freq must be within policy->min and policy->max, of course. 287 - What's the difference between these two functions? When your governor is 288 - in a direct code path of a call to governor callbacks, like 289 - governor->start(), the policy->rwsem is still held in the cpufreq core, 290 - and there's no need to lock it again (in fact, this would cause a 291 - deadlock). So use __cpufreq_driver_target only in these cases. In all 292 - other cases (for example, when there's a "daemonized" function that 293 - wakes up every second), use cpufreq_driver_target to take policy->rwsem 294 - before the command is passed to the cpufreq driver. 295 - 296 - 4. References 297 - ============= 298 - 299 - [1] Per-entity load tracking: https://lwn.net/Articles/531853/ 300 - [2] Improvements in CPU frequency management: https://lwn.net/Articles/682391/ 301 -
-7
Documentation/cpu-freq/index.txt
··· 21 21 22 22 amd-powernow.txt - AMD powernow driver specific file. 23 23 24 - boost.txt - Frequency boosting support. 25 - 26 24 core.txt - General description of the CPUFreq core and 27 25 of CPUFreq notifiers. 28 26 ··· 30 32 31 33 cpufreq-stats.txt - General description of sysfs cpufreq stats. 32 34 33 - governors.txt - What are cpufreq governors and how to 34 - implement them? 35 - 36 35 index.txt - File index, Mailing list and Links (this document) 37 36 38 37 intel-pstate.txt - Intel pstate cpufreq driver specific file. 39 38 40 39 pcc-cpufreq.txt - PCC cpufreq driver specific file. 41 - 42 - user-guide.txt - User Guide to CPUFreq 43 40 44 41 45 42 Mailing List
-228
Documentation/cpu-freq/user-guide.txt
··· 1 - CPU frequency and voltage scaling code in the Linux(TM) kernel 2 - 3 - 4 - L i n u x C P U F r e q 5 - 6 - U S E R G U I D E 7 - 8 - 9 - Dominik Brodowski <linux@brodo.de> 10 - 11 - 12 - 13 - Clock scaling allows you to change the clock speed of the CPUs on the 14 - fly. This is a nice method to save battery power, because the lower 15 - the clock speed, the less power the CPU consumes. 16 - 17 - 18 - Contents: 19 - --------- 20 - 1. Supported Architectures and Processors 21 - 1.1 ARM and ARM64 22 - 1.2 x86 23 - 1.3 sparc64 24 - 1.4 ppc 25 - 1.5 SuperH 26 - 1.6 Blackfin 27 - 28 - 2. "Policy" / "Governor"? 29 - 2.1 Policy 30 - 2.2 Governor 31 - 32 - 3. How to change the CPU cpufreq policy and/or speed 33 - 3.1 Preferred interface: sysfs 34 - 35 - 36 - 37 - 1. Supported Architectures and Processors 38 - ========================================= 39 - 40 - 1.1 ARM and ARM64 41 - ----------------- 42 - 43 - Almost all ARM and ARM64 platforms support CPU frequency scaling. 44 - 45 - 1.2 x86 46 - ------- 47 - 48 - The following processors for the x86 architecture are supported by cpufreq: 49 - 50 - AMD Elan - SC400, SC410 51 - AMD mobile K6-2+ 52 - AMD mobile K6-3+ 53 - AMD mobile Duron 54 - AMD mobile Athlon 55 - AMD Opteron 56 - AMD Athlon 64 57 - Cyrix Media GXm 58 - Intel mobile PIII and Intel mobile PIII-M on certain chipsets 59 - Intel Pentium 4, Intel Xeon 60 - Intel Pentium M (Centrino) 61 - National Semiconductors Geode GX 62 - Transmeta Crusoe 63 - Transmeta Efficeon 64 - VIA Cyrix 3 / C3 65 - various processors on some ACPI 2.0-compatible systems [*] 66 - And many more 67 - 68 - [*] Only if "ACPI Processor Performance States" are available 69 - to the ACPI<->BIOS interface. 70 - 71 - 72 - 1.3 sparc64 73 - ----------- 74 - 75 - The following processors for the sparc64 architecture are supported by 76 - cpufreq: 77 - 78 - UltraSPARC-III 79 - 80 - 81 - 1.4 ppc 82 - ------- 83 - 84 - Several "PowerBook" and "iBook2" notebooks are supported. 85 - The following POWER processors are supported in powernv mode: 86 - POWER8 87 - POWER9 88 - 89 - 1.5 SuperH 90 - ---------- 91 - 92 - All SuperH processors supporting rate rounding through the clock 93 - framework are supported by cpufreq. 94 - 95 - 1.6 Blackfin 96 - ------------ 97 - 98 - The following Blackfin processors are supported by cpufreq: 99 - 100 - BF522, BF523, BF524, BF525, BF526, BF527, Rev 0.1 or higher 101 - BF531, BF532, BF533, Rev 0.3 or higher 102 - BF534, BF536, BF537, Rev 0.2 or higher 103 - BF561, Rev 0.3 or higher 104 - BF542, BF544, BF547, BF548, BF549, Rev 0.1 or higher 105 - 106 - 107 - 2. "Policy" / "Governor" ? 108 - ========================== 109 - 110 - Some CPU frequency scaling-capable processor switch between various 111 - frequencies and operating voltages "on the fly" without any kernel or 112 - user involvement. This guarantees very fast switching to a frequency 113 - which is high enough to serve the user's needs, but low enough to save 114 - power. 115 - 116 - 117 - 2.1 Policy 118 - ---------- 119 - 120 - On these systems, all you can do is select the lower and upper 121 - frequency limit as well as whether you want more aggressive 122 - power-saving or more instantly available processing power. 123 - 124 - 125 - 2.2 Governor 126 - ------------ 127 - 128 - On all other cpufreq implementations, these boundaries still need to 129 - be set. Then, a "governor" must be selected. Such a "governor" decides 130 - what speed the processor shall run within the boundaries. One such 131 - "governor" is the "userspace" governor. This one allows the user - or 132 - a yet-to-implement userspace program - to decide what specific speed 133 - the processor shall run at. 134 - 135 - 136 - 3. How to change the CPU cpufreq policy and/or speed 137 - ==================================================== 138 - 139 - 3.1 Preferred Interface: sysfs 140 - ------------------------------ 141 - 142 - The preferred interface is located in the sysfs filesystem. If you 143 - mounted it at /sys, the cpufreq interface is located in a subdirectory 144 - "cpufreq" within the cpu-device directory 145 - (e.g. /sys/devices/system/cpu/cpu0/cpufreq/ for the first CPU). 146 - 147 - affected_cpus : List of Online CPUs that require software 148 - coordination of frequency. 149 - 150 - cpuinfo_cur_freq : Current frequency of the CPU as obtained from 151 - the hardware, in KHz. This is the frequency 152 - the CPU actually runs at. 153 - 154 - cpuinfo_min_freq : this file shows the minimum operating 155 - frequency the processor can run at(in kHz) 156 - 157 - cpuinfo_max_freq : this file shows the maximum operating 158 - frequency the processor can run at(in kHz) 159 - 160 - cpuinfo_transition_latency The time it takes on this CPU to 161 - switch between two frequencies in nano 162 - seconds. If unknown or known to be 163 - that high that the driver does not 164 - work with the ondemand governor, -1 165 - (CPUFREQ_ETERNAL) will be returned. 166 - Using this information can be useful 167 - to choose an appropriate polling 168 - frequency for a kernel governor or 169 - userspace daemon. Make sure to not 170 - switch the frequency too often 171 - resulting in performance loss. 172 - 173 - related_cpus : List of Online + Offline CPUs that need software 174 - coordination of frequency. 175 - 176 - scaling_available_frequencies : List of available frequencies, in KHz. 177 - 178 - scaling_available_governors : this file shows the CPUfreq governors 179 - available in this kernel. You can see the 180 - currently activated governor in 181 - 182 - scaling_cur_freq : Current frequency of the CPU as determined by 183 - the governor and cpufreq core, in KHz. This is 184 - the frequency the kernel thinks the CPU runs 185 - at. 186 - 187 - scaling_driver : this file shows what cpufreq driver is 188 - used to set the frequency on this CPU 189 - 190 - scaling_governor, and by "echoing" the name of another 191 - governor you can change it. Please note 192 - that some governors won't load - they only 193 - work on some specific architectures or 194 - processors. 195 - 196 - scaling_min_freq and 197 - scaling_max_freq show the current "policy limits" (in 198 - kHz). By echoing new values into these 199 - files, you can change these limits. 200 - NOTE: when setting a policy you need to 201 - first set scaling_max_freq, then 202 - scaling_min_freq. 203 - 204 - scaling_setspeed This can be read to get the currently programmed 205 - value by the governor. This can be written to 206 - change the current frequency for a group of 207 - CPUs, represented by a policy. This is supported 208 - currently only by the userspace governor. 209 - 210 - bios_limit : If the BIOS tells the OS to limit a CPU to 211 - lower frequencies, the user can read out the 212 - maximum available frequency from this file. 213 - This typically can happen through (often not 214 - intended) BIOS settings, restrictions 215 - triggered through a service processor or other 216 - BIOS/HW based implementations. 217 - This does not cover thermal ACPI limitations 218 - which can be detected through the generic 219 - thermal driver. 220 - 221 - If you have selected the "userspace" governor which allows you to 222 - set the CPU operating frequency to a specific value, you can read out 223 - the current frequency in 224 - 225 - scaling_setspeed. By "echoing" a new frequency into this 226 - you can change the speed of the CPU, 227 - but only within the limits of 228 - scaling_min_freq and scaling_max_freq.
+1 -1
Documentation/cputopology.txt
··· 100 100 101 101 For architectures that don't support books (CONFIG_SCHED_BOOK) there are no 102 102 default definitions for topology_book_id() and topology_book_cpumask(). 103 - For architectures that don't support drawes (CONFIG_SCHED_DRAWER) there are 103 + For architectures that don't support drawers (CONFIG_SCHED_DRAWER) there are 104 104 no default definitions for topology_drawer_id() and topology_drawer_cpumask(). 105 105 106 106 Additionally, CPU topology information is provided under
+2 -2
Documentation/debugging-via-ohci1394.txt
··· 100 100 CardBus and even some Express cards which are fully compliant to OHCI-1394 101 101 specification are available. If it requires no driver for Windows operating 102 102 systems, it most likely is. Only specialized shops have cards which are not 103 - compliant, they are based on TI PCILynx chips and require drivers for Win- 104 - dows operating systems. 103 + compliant, they are based on TI PCILynx chips and require drivers for Windows 104 + operating systems. 105 105 106 106 The mentioned kernel log message contains the string "physUB" if the 107 107 controller implements a writable Physical Upper Bound register. This is
+1 -1
Documentation/device-mapper/cache.txt
··· 290 290 range's end value is "one past the end", meaning 5-10 expresses a range 291 291 of values from 5 to 9. Each cblock must be expressed as a decimal 292 292 value, in the future a variant message that takes cblock ranges 293 - expressed in hexidecimal may be needed to better support efficient 293 + expressed in hexadecimal may be needed to better support efficient 294 294 invalidation of larger caches. The cache must be in passthrough mode 295 295 when invalidate_cblocks is used. 296 296
+3
Documentation/doc-guide/hello.dot
··· 1 + graph G { 2 + Hello -- World 3 + }
+112 -3
Documentation/doc-guide/sphinx.rst
··· 34 34 35 35 To generate documentation, Sphinx (``sphinx-build``) must obviously be 36 36 installed. For prettier HTML output, the Read the Docs Sphinx theme 37 - (``sphinx_rtd_theme``) is used if available. For PDF output, ``rst2pdf`` is also 38 - needed. All of these are widely available and packaged in distributions. 37 + (``sphinx_rtd_theme``) is used if available. For PDF output you'll also need 38 + ``XeLaTeX`` and ``convert(1)`` from ImageMagick (https://www.imagemagick.org). 39 + All of these are widely available and packaged in distributions. 39 40 40 41 To pass extra options to Sphinx, you can use the ``SPHINXOPTS`` make 41 42 variable. For example, use ``make SPHINXOPTS=-v htmldocs`` to get more verbose ··· 74 73 75 74 Here are some specific guidelines for the kernel documentation: 76 75 77 - * Please don't go overboard with reStructuredText markup. Keep it simple. 76 + * Please don't go overboard with reStructuredText markup. Keep it 77 + simple. For the most part the documentation should be plain text with 78 + just enough consistency in formatting that it can be converted to 79 + other formats. 80 + 81 + * Please keep the formatting changes minimal when converting existing 82 + documentation to reStructuredText. 83 + 84 + * Also update the content, not just the formatting, when converting 85 + documentation. 78 86 79 87 * Please stick to this order of heading adornments: 80 88 ··· 112 102 number and order of section title adornment styles, the order enforced will be 113 103 the order as encountered."), having the higher levels the same overall makes 114 104 it easier to follow the documents. 105 + 106 + * For inserting fixed width text blocks (for code examples, use case 107 + examples, etc.), use ``::`` for anything that doesn't really benefit 108 + from syntax highlighting, especially short snippets. Use 109 + ``.. code-block:: <language>`` for longer code blocks that benefit 110 + from highlighting. 115 111 116 112 117 113 the C domain ··· 233 217 * .. _`last row`: 234 218 235 219 - column 3 220 + 221 + 222 + Figures & Images 223 + ================ 224 + 225 + If you want to add an image, you should use the ``kernel-figure`` and 226 + ``kernel-image`` directives. E.g. to insert a figure with a scalable 227 + image format use SVG (:ref:`svg_image_example`):: 228 + 229 + .. kernel-figure:: svg_image.svg 230 + :alt: simple SVG image 231 + 232 + SVG image example 233 + 234 + .. _svg_image_example: 235 + 236 + .. kernel-figure:: svg_image.svg 237 + :alt: simple SVG image 238 + 239 + SVG image example 240 + 241 + The kernel figure (and image) directive support **DOT** formated files, see 242 + 243 + * DOT: http://graphviz.org/pdf/dotguide.pdf 244 + * Graphviz: http://www.graphviz.org/content/dot-language 245 + 246 + A simple example (:ref:`hello_dot_file`):: 247 + 248 + .. kernel-figure:: hello.dot 249 + :alt: hello world 250 + 251 + DOT's hello world example 252 + 253 + .. _hello_dot_file: 254 + 255 + .. kernel-figure:: hello.dot 256 + :alt: hello world 257 + 258 + DOT's hello world example 259 + 260 + Embed *render* markups (or languages) like Graphviz's **DOT** is provided by the 261 + ``kernel-render`` directives.:: 262 + 263 + .. kernel-render:: DOT 264 + :alt: foobar digraph 265 + :caption: Embedded **DOT** (Graphviz) code 266 + 267 + digraph foo { 268 + "bar" -> "baz"; 269 + } 270 + 271 + How this will be rendered depends on the installed tools. If Graphviz is 272 + installed, you will see an vector image. If not the raw markup is inserted as 273 + *literal-block* (:ref:`hello_dot_render`). 274 + 275 + .. _hello_dot_render: 276 + 277 + .. kernel-render:: DOT 278 + :alt: foobar digraph 279 + :caption: Embedded **DOT** (Graphviz) code 280 + 281 + digraph foo { 282 + "bar" -> "baz"; 283 + } 284 + 285 + The *render* directive has all the options known from the *figure* directive, 286 + plus option ``caption``. If ``caption`` has a value, a *figure* node is 287 + inserted. If not, a *image* node is inserted. A ``caption`` is also needed, if 288 + you want to refer it (:ref:`hello_svg_render`). 289 + 290 + Embedded **SVG**:: 291 + 292 + .. kernel-render:: SVG 293 + :caption: Embedded **SVG** markup 294 + :alt: so-nw-arrow 295 + 296 + <?xml version="1.0" encoding="UTF-8"?> 297 + <svg xmlns="http://www.w3.org/2000/svg" version="1.1" ...> 298 + ... 299 + </svg> 300 + 301 + .. _hello_svg_render: 302 + 303 + .. kernel-render:: SVG 304 + :caption: Embedded **SVG** markup 305 + :alt: so-nw-arrow 306 + 307 + <?xml version="1.0" encoding="UTF-8"?> 308 + <svg xmlns="http://www.w3.org/2000/svg" 309 + version="1.1" baseProfile="full" width="70px" height="40px" viewBox="0 0 700 400"> 310 + <line x1="180" y1="370" x2="500" y2="50" stroke="black" stroke-width="15px"/> 311 + <polygon points="585 0 525 25 585 50" transform="rotate(135 525 25)"/> 312 + </svg>
+10
Documentation/doc-guide/svg_image.svg
··· 1 + <?xml version="1.0" encoding="UTF-8"?> 2 + <!-- originate: https://commons.wikimedia.org/wiki/File:Variable_Resistor.svg --> 3 + <svg xmlns="http://www.w3.org/2000/svg" 4 + version="1.1" baseProfile="full" 5 + width="70px" height="40px" viewBox="0 0 700 400"> 6 + <line x1="0" y1="200" x2="700" y2="200" stroke="black" stroke-width="20px"/> 7 + <rect x="100" y="100" width="500" height="200" fill="white" stroke="black" stroke-width="20px"/> 8 + <line x1="180" y1="370" x2="500" y2="50" stroke="black" stroke-width="15px"/> 9 + <polygon points="585 0 525 25 585 50" transform="rotate(135 525 25)"/> 10 + </svg>
+6
Documentation/driver-api/basics.rst
··· 7 7 .. kernel-doc:: include/linux/init.h 8 8 :internal: 9 9 10 + Driver device table 11 + ------------------- 12 + 13 + .. kernel-doc:: include/linux/mod_devicetable.h 14 + :internal: 15 + 10 16 Atomic and pointer manipulation 11 17 ------------------------------- 12 18
+1
Documentation/driver-api/firmware/index.rst
··· 7 7 introduction 8 8 core 9 9 request_firmware 10 + other_interfaces 10 11 11 12 .. only:: subproject and html 12 13
+15
Documentation/driver-api/firmware/other_interfaces.rst
··· 1 + Other Firmware Interfaces 2 + ========================= 3 + 4 + DMI Interfaces 5 + -------------- 6 + 7 + .. kernel-doc:: drivers/firmware/dmi_scan.c 8 + :export: 9 + 10 + EDD Interfaces 11 + -------------- 12 + 13 + .. kernel-doc:: drivers/firmware/edd.c 14 + :internal: 15 +
+3 -1
Documentation/driver-api/index.rst
··· 26 26 regulator 27 27 iio/index 28 28 input 29 - usb 29 + usb/index 30 + pci 30 31 spi 31 32 i2c 32 33 hsi ··· 37 36 80211/index 38 37 uio-howto 39 38 firmware/index 39 + misc_devices 40 40 41 41 .. only:: subproject and html 42 42
+5
Documentation/driver-api/misc_devices.rst
··· 1 + Miscellaneous Devices 2 + ===================== 3 + 4 + .. kernel-doc:: drivers/char/misc.c 5 + :export:
+50
Documentation/driver-api/pci.rst
··· 1 + PCI Support Library 2 + ------------------- 3 + 4 + .. kernel-doc:: drivers/pci/pci.c 5 + :export: 6 + 7 + .. kernel-doc:: drivers/pci/pci-driver.c 8 + :export: 9 + 10 + .. kernel-doc:: drivers/pci/remove.c 11 + :export: 12 + 13 + .. kernel-doc:: drivers/pci/search.c 14 + :export: 15 + 16 + .. kernel-doc:: drivers/pci/msi.c 17 + :export: 18 + 19 + .. kernel-doc:: drivers/pci/bus.c 20 + :export: 21 + 22 + .. kernel-doc:: drivers/pci/access.c 23 + :export: 24 + 25 + .. kernel-doc:: drivers/pci/irq.c 26 + :export: 27 + 28 + .. kernel-doc:: drivers/pci/htirq.c 29 + :export: 30 + 31 + .. kernel-doc:: drivers/pci/probe.c 32 + :export: 33 + 34 + .. kernel-doc:: drivers/pci/slot.c 35 + :export: 36 + 37 + .. kernel-doc:: drivers/pci/rom.c 38 + :export: 39 + 40 + .. kernel-doc:: drivers/pci/iov.c 41 + :export: 42 + 43 + .. kernel-doc:: drivers/pci/pci-sysfs.c 44 + :internal: 45 + 46 + PCI Hotplug Support Library 47 + --------------------------- 48 + 49 + .. kernel-doc:: drivers/pci/hotplug/pci_hotplug_core.c 50 + :export:
-748
Documentation/driver-api/usb.rst
··· 1 - =========================== 2 - The Linux-USB Host Side API 3 - =========================== 4 - 5 - Introduction to USB on Linux 6 - ============================ 7 - 8 - A Universal Serial Bus (USB) is used to connect a host, such as a PC or 9 - workstation, to a number of peripheral devices. USB uses a tree 10 - structure, with the host as the root (the system's master), hubs as 11 - interior nodes, and peripherals as leaves (and slaves). Modern PCs 12 - support several such trees of USB devices, usually 13 - a few USB 3.0 (5 GBit/s) or USB 3.1 (10 GBit/s) and some legacy 14 - USB 2.0 (480 MBit/s) busses just in case. 15 - 16 - That master/slave asymmetry was designed-in for a number of reasons, one 17 - being ease of use. It is not physically possible to mistake upstream and 18 - downstream or it does not matter with a type C plug (or they are built into the 19 - peripheral). Also, the host software doesn't need to deal with 20 - distributed auto-configuration since the pre-designated master node 21 - manages all that. 22 - 23 - Kernel developers added USB support to Linux early in the 2.2 kernel 24 - series and have been developing it further since then. Besides support 25 - for each new generation of USB, various host controllers gained support, 26 - new drivers for peripherals have been added and advanced features for latency 27 - measurement and improved power management introduced. 28 - 29 - Linux can run inside USB devices as well as on the hosts that control 30 - the devices. But USB device drivers running inside those peripherals 31 - don't do the same things as the ones running inside hosts, so they've 32 - been given a different name: *gadget drivers*. This document does not 33 - cover gadget drivers. 34 - 35 - USB Host-Side API Model 36 - ======================= 37 - 38 - Host-side drivers for USB devices talk to the "usbcore" APIs. There are 39 - two. One is intended for *general-purpose* drivers (exposed through 40 - driver frameworks), and the other is for drivers that are *part of the 41 - core*. Such core drivers include the *hub* driver (which manages trees 42 - of USB devices) and several different kinds of *host controller 43 - drivers*, which control individual busses. 44 - 45 - The device model seen by USB drivers is relatively complex. 46 - 47 - - USB supports four kinds of data transfers (control, bulk, interrupt, 48 - and isochronous). Two of them (control and bulk) use bandwidth as 49 - it's available, while the other two (interrupt and isochronous) are 50 - scheduled to provide guaranteed bandwidth. 51 - 52 - - The device description model includes one or more "configurations" 53 - per device, only one of which is active at a time. Devices are supposed 54 - to be capable of operating at lower than their top 55 - speeds and may provide a BOS descriptor showing the lowest speed they 56 - remain fully operational at. 57 - 58 - - From USB 3.0 on configurations have one or more "functions", which 59 - provide a common functionality and are grouped together for purposes 60 - of power management. 61 - 62 - - Configurations or functions have one or more "interfaces", each of which may have 63 - "alternate settings". Interfaces may be standardized by USB "Class" 64 - specifications, or may be specific to a vendor or device. 65 - 66 - USB device drivers actually bind to interfaces, not devices. Think of 67 - them as "interface drivers", though you may not see many devices 68 - where the distinction is important. *Most USB devices are simple, 69 - with only one function, one configuration, one interface, and one alternate 70 - setting.* 71 - 72 - - Interfaces have one or more "endpoints", each of which supports one 73 - type and direction of data transfer such as "bulk out" or "interrupt 74 - in". The entire configuration may have up to sixteen endpoints in 75 - each direction, allocated as needed among all the interfaces. 76 - 77 - - Data transfer on USB is packetized; each endpoint has a maximum 78 - packet size. Drivers must often be aware of conventions such as 79 - flagging the end of bulk transfers using "short" (including zero 80 - length) packets. 81 - 82 - - The Linux USB API supports synchronous calls for control and bulk 83 - messages. It also supports asynchronous calls for all kinds of data 84 - transfer, using request structures called "URBs" (USB Request 85 - Blocks). 86 - 87 - Accordingly, the USB Core API exposed to device drivers covers quite a 88 - lot of territory. You'll probably need to consult the USB 3.0 89 - specification, available online from www.usb.org at no cost, as well as 90 - class or device specifications. 91 - 92 - The only host-side drivers that actually touch hardware (reading/writing 93 - registers, handling IRQs, and so on) are the HCDs. In theory, all HCDs 94 - provide the same functionality through the same API. In practice, that's 95 - becoming more true, but there are still differences 96 - that crop up especially with fault handling on the less common controllers. 97 - Different controllers don't 98 - necessarily report the same aspects of failures, and recovery from 99 - faults (including software-induced ones like unlinking an URB) isn't yet 100 - fully consistent. Device driver authors should make a point of doing 101 - disconnect testing (while the device is active) with each different host 102 - controller driver, to make sure drivers don't have bugs of their own as 103 - well as to make sure they aren't relying on some HCD-specific behavior. 104 - 105 - USB-Standard Types 106 - ================== 107 - 108 - In ``<linux/usb/ch9.h>`` you will find the USB data types defined in 109 - chapter 9 of the USB specification. These data types are used throughout 110 - USB, and in APIs including this host side API, gadget APIs, and usbfs. 111 - 112 - .. kernel-doc:: include/linux/usb/ch9.h 113 - :internal: 114 - 115 - Host-Side Data Types and Macros 116 - =============================== 117 - 118 - The host side API exposes several layers to drivers, some of which are 119 - more necessary than others. These support lifecycle models for host side 120 - drivers and devices, and support passing buffers through usbcore to some 121 - HCD that performs the I/O for the device driver. 122 - 123 - .. kernel-doc:: include/linux/usb.h 124 - :internal: 125 - 126 - USB Core APIs 127 - ============= 128 - 129 - There are two basic I/O models in the USB API. The most elemental one is 130 - asynchronous: drivers submit requests in the form of an URB, and the 131 - URB's completion callback handles the next step. All USB transfer types 132 - support that model, although there are special cases for control URBs 133 - (which always have setup and status stages, but may not have a data 134 - stage) and isochronous URBs (which allow large packets and include 135 - per-packet fault reports). Built on top of that is synchronous API 136 - support, where a driver calls a routine that allocates one or more URBs, 137 - submits them, and waits until they complete. There are synchronous 138 - wrappers for single-buffer control and bulk transfers (which are awkward 139 - to use in some driver disconnect scenarios), and for scatterlist based 140 - streaming i/o (bulk or interrupt). 141 - 142 - USB drivers need to provide buffers that can be used for DMA, although 143 - they don't necessarily need to provide the DMA mapping themselves. There 144 - are APIs to use used when allocating DMA buffers, which can prevent use 145 - of bounce buffers on some systems. In some cases, drivers may be able to 146 - rely on 64bit DMA to eliminate another kind of bounce buffer. 147 - 148 - .. kernel-doc:: drivers/usb/core/urb.c 149 - :export: 150 - 151 - .. kernel-doc:: drivers/usb/core/message.c 152 - :export: 153 - 154 - .. kernel-doc:: drivers/usb/core/file.c 155 - :export: 156 - 157 - .. kernel-doc:: drivers/usb/core/driver.c 158 - :export: 159 - 160 - .. kernel-doc:: drivers/usb/core/usb.c 161 - :export: 162 - 163 - .. kernel-doc:: drivers/usb/core/hub.c 164 - :export: 165 - 166 - Host Controller APIs 167 - ==================== 168 - 169 - These APIs are only for use by host controller drivers, most of which 170 - implement standard register interfaces such as XHCI, EHCI, OHCI, or UHCI. UHCI 171 - was one of the first interfaces, designed by Intel and also used by VIA; 172 - it doesn't do much in hardware. OHCI was designed later, to have the 173 - hardware do more work (bigger transfers, tracking protocol state, and so 174 - on). EHCI was designed with USB 2.0; its design has features that 175 - resemble OHCI (hardware does much more work) as well as UHCI (some parts 176 - of ISO support, TD list processing). XHCI was designed with USB 3.0. It 177 - continues to shift support for functionality into hardware. 178 - 179 - There are host controllers other than the "big three", although most PCI 180 - based controllers (and a few non-PCI based ones) use one of those 181 - interfaces. Not all host controllers use DMA; some use PIO, and there is 182 - also a simulator and a virtual host controller to pipe USB over the network. 183 - 184 - The same basic APIs are available to drivers for all those controllers. 185 - For historical reasons they are in two layers: :c:type:`struct 186 - usb_bus <usb_bus>` is a rather thin layer that became available 187 - in the 2.2 kernels, while :c:type:`struct usb_hcd <usb_hcd>` 188 - is a more featureful layer 189 - that lets HCDs share common code, to shrink driver size and 190 - significantly reduce hcd-specific behaviors. 191 - 192 - .. kernel-doc:: drivers/usb/core/hcd.c 193 - :export: 194 - 195 - .. kernel-doc:: drivers/usb/core/hcd-pci.c 196 - :export: 197 - 198 - .. kernel-doc:: drivers/usb/core/buffer.c 199 - :internal: 200 - 201 - The USB Filesystem (usbfs) 202 - ========================== 203 - 204 - This chapter presents the Linux *usbfs*. You may prefer to avoid writing 205 - new kernel code for your USB driver; that's the problem that usbfs set 206 - out to solve. User mode device drivers are usually packaged as 207 - applications or libraries, and may use usbfs through some programming 208 - library that wraps it. Such libraries include 209 - `libusb <http://libusb.sourceforge.net>`__ for C/C++, and 210 - `jUSB <http://jUSB.sourceforge.net>`__ for Java. 211 - 212 - **Note** 213 - 214 - This particular documentation is incomplete, especially with respect 215 - to the asynchronous mode. As of kernel 2.5.66 the code and this 216 - (new) documentation need to be cross-reviewed. 217 - 218 - Configure usbfs into Linux kernels by enabling the *USB filesystem* 219 - option (CONFIG_USB_DEVICEFS), and you get basic support for user mode 220 - USB device drivers. Until relatively recently it was often (confusingly) 221 - called *usbdevfs* although it wasn't solving what *devfs* was. Every USB 222 - device will appear in usbfs, regardless of whether or not it has a 223 - kernel driver. 224 - 225 - What files are in "usbfs"? 226 - -------------------------- 227 - 228 - Conventionally mounted at ``/proc/bus/usb``, usbfs features include: 229 - 230 - - ``/proc/bus/usb/devices`` ... a text file showing each of the USB 231 - devices on known to the kernel, and their configuration descriptors. 232 - You can also poll() this to learn about new devices. 233 - 234 - - ``/proc/bus/usb/BBB/DDD`` ... magic files exposing the each device's 235 - configuration descriptors, and supporting a series of ioctls for 236 - making device requests, including I/O to devices. (Purely for access 237 - by programs.) 238 - 239 - Each bus is given a number (BBB) based on when it was enumerated; within 240 - each bus, each device is given a similar number (DDD). Those BBB/DDD 241 - paths are not "stable" identifiers; expect them to change even if you 242 - always leave the devices plugged in to the same hub port. *Don't even 243 - think of saving these in application configuration files.* Stable 244 - identifiers are available, for user mode applications that want to use 245 - them. HID and networking devices expose these stable IDs, so that for 246 - example you can be sure that you told the right UPS to power down its 247 - second server. "usbfs" doesn't (yet) expose those IDs. 248 - 249 - Mounting and Access Control 250 - --------------------------- 251 - 252 - There are a number of mount options for usbfs, which will be of most 253 - interest to you if you need to override the default access control 254 - policy. That policy is that only root may read or write device files 255 - (``/proc/bus/BBB/DDD``) although anyone may read the ``devices`` or 256 - ``drivers`` files. I/O requests to the device also need the 257 - CAP_SYS_RAWIO capability, 258 - 259 - The significance of that is that by default, all user mode device 260 - drivers need super-user privileges. You can change modes or ownership in 261 - a driver setup when the device hotplugs, or maye just start the driver 262 - right then, as a privileged server (or some activity within one). That's 263 - the most secure approach for multi-user systems, but for single user 264 - systems ("trusted" by that user) it's more convenient just to grant 265 - everyone all access (using the *devmode=0666* option) so the driver can 266 - start whenever it's needed. 267 - 268 - The mount options for usbfs, usable in /etc/fstab or in command line 269 - invocations of *mount*, are: 270 - 271 - *busgid*\ =NNNNN 272 - Controls the GID used for the /proc/bus/usb/BBB directories. 273 - (Default: 0) 274 - 275 - *busmode*\ =MMM 276 - Controls the file mode used for the /proc/bus/usb/BBB directories. 277 - (Default: 0555) 278 - 279 - *busuid*\ =NNNNN 280 - Controls the UID used for the /proc/bus/usb/BBB directories. 281 - (Default: 0) 282 - 283 - *devgid*\ =NNNNN 284 - Controls the GID used for the /proc/bus/usb/BBB/DDD files. (Default: 285 - 0) 286 - 287 - *devmode*\ =MMM 288 - Controls the file mode used for the /proc/bus/usb/BBB/DDD files. 289 - (Default: 0644) 290 - 291 - *devuid*\ =NNNNN 292 - Controls the UID used for the /proc/bus/usb/BBB/DDD files. (Default: 293 - 0) 294 - 295 - *listgid*\ =NNNNN 296 - Controls the GID used for the /proc/bus/usb/devices and drivers 297 - files. (Default: 0) 298 - 299 - *listmode*\ =MMM 300 - Controls the file mode used for the /proc/bus/usb/devices and 301 - drivers files. (Default: 0444) 302 - 303 - *listuid*\ =NNNNN 304 - Controls the UID used for the /proc/bus/usb/devices and drivers 305 - files. (Default: 0) 306 - 307 - Note that many Linux distributions hard-wire the mount options for usbfs 308 - in their init scripts, such as ``/etc/rc.d/rc.sysinit``, rather than 309 - making it easy to set this per-system policy in ``/etc/fstab``. 310 - 311 - /proc/bus/usb/devices 312 - --------------------- 313 - 314 - This file is handy for status viewing tools in user mode, which can scan 315 - the text format and ignore most of it. More detailed device status 316 - (including class and vendor status) is available from device-specific 317 - files. For information about the current format of this file, see the 318 - ``Documentation/usb/proc_usb_info.txt`` file in your Linux kernel 319 - sources. 320 - 321 - This file, in combination with the poll() system call, can also be used 322 - to detect when devices are added or removed: 323 - 324 - :: 325 - 326 - int fd; 327 - struct pollfd pfd; 328 - 329 - fd = open("/proc/bus/usb/devices", O_RDONLY); 330 - pfd = { fd, POLLIN, 0 }; 331 - for (;;) { 332 - /* The first time through, this call will return immediately. */ 333 - poll(&pfd, 1, -1); 334 - 335 - /* To see what's changed, compare the file's previous and current 336 - contents or scan the filesystem. (Scanning is more precise.) */ 337 - } 338 - 339 - Note that this behavior is intended to be used for informational and 340 - debug purposes. It would be more appropriate to use programs such as 341 - udev or HAL to initialize a device or start a user-mode helper program, 342 - for instance. 343 - 344 - /proc/bus/usb/BBB/DDD 345 - --------------------- 346 - 347 - Use these files in one of these basic ways: 348 - 349 - *They can be read,* producing first the device descriptor (18 bytes) and 350 - then the descriptors for the current configuration. See the USB 2.0 spec 351 - for details about those binary data formats. You'll need to convert most 352 - multibyte values from little endian format to your native host byte 353 - order, although a few of the fields in the device descriptor (both of 354 - the BCD-encoded fields, and the vendor and product IDs) will be 355 - byteswapped for you. Note that configuration descriptors include 356 - descriptors for interfaces, altsettings, endpoints, and maybe additional 357 - class descriptors. 358 - 359 - *Perform USB operations* using *ioctl()* requests to make endpoint I/O 360 - requests (synchronously or asynchronously) or manage the device. These 361 - requests need the CAP_SYS_RAWIO capability, as well as filesystem 362 - access permissions. Only one ioctl request can be made on one of these 363 - device files at a time. This means that if you are synchronously reading 364 - an endpoint from one thread, you won't be able to write to a different 365 - endpoint from another thread until the read completes. This works for 366 - *half duplex* protocols, but otherwise you'd use asynchronous i/o 367 - requests. 368 - 369 - Life Cycle of User Mode Drivers 370 - ------------------------------- 371 - 372 - Such a driver first needs to find a device file for a device it knows 373 - how to handle. Maybe it was told about it because a ``/sbin/hotplug`` 374 - event handling agent chose that driver to handle the new device. Or 375 - maybe it's an application that scans all the /proc/bus/usb device files, 376 - and ignores most devices. In either case, it should :c:func:`read()` 377 - all the descriptors from the device file, and check them against what it 378 - knows how to handle. It might just reject everything except a particular 379 - vendor and product ID, or need a more complex policy. 380 - 381 - Never assume there will only be one such device on the system at a time! 382 - If your code can't handle more than one device at a time, at least 383 - detect when there's more than one, and have your users choose which 384 - device to use. 385 - 386 - Once your user mode driver knows what device to use, it interacts with 387 - it in either of two styles. The simple style is to make only control 388 - requests; some devices don't need more complex interactions than those. 389 - (An example might be software using vendor-specific control requests for 390 - some initialization or configuration tasks, with a kernel driver for the 391 - rest.) 392 - 393 - More likely, you need a more complex style driver: one using non-control 394 - endpoints, reading or writing data and claiming exclusive use of an 395 - interface. *Bulk* transfers are easiest to use, but only their sibling 396 - *interrupt* transfers work with low speed devices. Both interrupt and 397 - *isochronous* transfers offer service guarantees because their bandwidth 398 - is reserved. Such "periodic" transfers are awkward to use through usbfs, 399 - unless you're using the asynchronous calls. However, interrupt transfers 400 - can also be used in a synchronous "one shot" style. 401 - 402 - Your user-mode driver should never need to worry about cleaning up 403 - request state when the device is disconnected, although it should close 404 - its open file descriptors as soon as it starts seeing the ENODEV errors. 405 - 406 - The ioctl() Requests 407 - -------------------- 408 - 409 - To use these ioctls, you need to include the following headers in your 410 - userspace program: 411 - 412 - :: 413 - 414 - #include <linux/usb.h> 415 - #include <linux/usbdevice_fs.h> 416 - #include <asm/byteorder.h> 417 - 418 - The standard USB device model requests, from "Chapter 9" of the USB 2.0 419 - specification, are automatically included from the ``<linux/usb/ch9.h>`` 420 - header. 421 - 422 - Unless noted otherwise, the ioctl requests described here will update 423 - the modification time on the usbfs file to which they are applied 424 - (unless they fail). A return of zero indicates success; otherwise, a 425 - standard USB error code is returned. (These are documented in 426 - ``Documentation/usb/error-codes.txt`` in your kernel sources.) 427 - 428 - Each of these files multiplexes access to several I/O streams, one per 429 - endpoint. Each device has one control endpoint (endpoint zero) which 430 - supports a limited RPC style RPC access. Devices are configured by 431 - hub_wq (in the kernel) setting a device-wide *configuration* that 432 - affects things like power consumption and basic functionality. The 433 - endpoints are part of USB *interfaces*, which may have *altsettings* 434 - affecting things like which endpoints are available. Many devices only 435 - have a single configuration and interface, so drivers for them will 436 - ignore configurations and altsettings. 437 - 438 - Management/Status Requests 439 - ~~~~~~~~~~~~~~~~~~~~~~~~~~ 440 - 441 - A number of usbfs requests don't deal very directly with device I/O. 442 - They mostly relate to device management and status. These are all 443 - synchronous requests. 444 - 445 - USBDEVFS_CLAIMINTERFACE 446 - This is used to force usbfs to claim a specific interface, which has 447 - not previously been claimed by usbfs or any other kernel driver. The 448 - ioctl parameter is an integer holding the number of the interface 449 - (bInterfaceNumber from descriptor). 450 - 451 - Note that if your driver doesn't claim an interface before trying to 452 - use one of its endpoints, and no other driver has bound to it, then 453 - the interface is automatically claimed by usbfs. 454 - 455 - This claim will be released by a RELEASEINTERFACE ioctl, or by 456 - closing the file descriptor. File modification time is not updated 457 - by this request. 458 - 459 - USBDEVFS_CONNECTINFO 460 - Says whether the device is lowspeed. The ioctl parameter points to a 461 - structure like this: 462 - 463 - :: 464 - 465 - struct usbdevfs_connectinfo { 466 - unsigned int devnum; 467 - unsigned char slow; 468 - }; 469 - 470 - File modification time is not updated by this request. 471 - 472 - *You can't tell whether a "not slow" device is connected at high 473 - speed (480 MBit/sec) or just full speed (12 MBit/sec).* You should 474 - know the devnum value already, it's the DDD value of the device file 475 - name. 476 - 477 - USBDEVFS_GETDRIVER 478 - Returns the name of the kernel driver bound to a given interface (a 479 - string). Parameter is a pointer to this structure, which is 480 - modified: 481 - 482 - :: 483 - 484 - struct usbdevfs_getdriver { 485 - unsigned int interface; 486 - char driver[USBDEVFS_MAXDRIVERNAME + 1]; 487 - }; 488 - 489 - File modification time is not updated by this request. 490 - 491 - USBDEVFS_IOCTL 492 - Passes a request from userspace through to a kernel driver that has 493 - an ioctl entry in the *struct usb_driver* it registered. 494 - 495 - :: 496 - 497 - struct usbdevfs_ioctl { 498 - int ifno; 499 - int ioctl_code; 500 - void *data; 501 - }; 502 - 503 - /* user mode call looks like this. 504 - * 'request' becomes the driver->ioctl() 'code' parameter. 505 - * the size of 'param' is encoded in 'request', and that data 506 - * is copied to or from the driver->ioctl() 'buf' parameter. 507 - */ 508 - static int 509 - usbdev_ioctl (int fd, int ifno, unsigned request, void *param) 510 - { 511 - struct usbdevfs_ioctl wrapper; 512 - 513 - wrapper.ifno = ifno; 514 - wrapper.ioctl_code = request; 515 - wrapper.data = param; 516 - 517 - return ioctl (fd, USBDEVFS_IOCTL, &wrapper); 518 - } 519 - 520 - File modification time is not updated by this request. 521 - 522 - This request lets kernel drivers talk to user mode code through 523 - filesystem operations even when they don't create a character or 524 - block special device. It's also been used to do things like ask 525 - devices what device special file should be used. Two pre-defined 526 - ioctls are used to disconnect and reconnect kernel drivers, so that 527 - user mode code can completely manage binding and configuration of 528 - devices. 529 - 530 - USBDEVFS_RELEASEINTERFACE 531 - This is used to release the claim usbfs made on interface, either 532 - implicitly or because of a USBDEVFS_CLAIMINTERFACE call, before the 533 - file descriptor is closed. The ioctl parameter is an integer holding 534 - the number of the interface (bInterfaceNumber from descriptor); File 535 - modification time is not updated by this request. 536 - 537 - **Warning** 538 - 539 - *No security check is made to ensure that the task which made 540 - the claim is the one which is releasing it. This means that user 541 - mode driver may interfere other ones.* 542 - 543 - USBDEVFS_RESETEP 544 - Resets the data toggle value for an endpoint (bulk or interrupt) to 545 - DATA0. The ioctl parameter is an integer endpoint number (1 to 15, 546 - as identified in the endpoint descriptor), with USB_DIR_IN added 547 - if the device's endpoint sends data to the host. 548 - 549 - **Warning** 550 - 551 - *Avoid using this request. It should probably be removed.* Using 552 - it typically means the device and driver will lose toggle 553 - synchronization. If you really lost synchronization, you likely 554 - need to completely handshake with the device, using a request 555 - like CLEAR_HALT or SET_INTERFACE. 556 - 557 - USBDEVFS_DROP_PRIVILEGES 558 - This is used to relinquish the ability to do certain operations 559 - which are considered to be privileged on a usbfs file descriptor. 560 - This includes claiming arbitrary interfaces, resetting a device on 561 - which there are currently claimed interfaces from other users, and 562 - issuing USBDEVFS_IOCTL calls. The ioctl parameter is a 32 bit mask 563 - of interfaces the user is allowed to claim on this file descriptor. 564 - You may issue this ioctl more than one time to narrow said mask. 565 - 566 - Synchronous I/O Support 567 - ~~~~~~~~~~~~~~~~~~~~~~~ 568 - 569 - Synchronous requests involve the kernel blocking until the user mode 570 - request completes, either by finishing successfully or by reporting an 571 - error. In most cases this is the simplest way to use usbfs, although as 572 - noted above it does prevent performing I/O to more than one endpoint at 573 - a time. 574 - 575 - USBDEVFS_BULK 576 - Issues a bulk read or write request to the device. The ioctl 577 - parameter is a pointer to this structure: 578 - 579 - :: 580 - 581 - struct usbdevfs_bulktransfer { 582 - unsigned int ep; 583 - unsigned int len; 584 - unsigned int timeout; /* in milliseconds */ 585 - void *data; 586 - }; 587 - 588 - The "ep" value identifies a bulk endpoint number (1 to 15, as 589 - identified in an endpoint descriptor), masked with USB_DIR_IN when 590 - referring to an endpoint which sends data to the host from the 591 - device. The length of the data buffer is identified by "len"; Recent 592 - kernels support requests up to about 128KBytes. *FIXME say how read 593 - length is returned, and how short reads are handled.*. 594 - 595 - USBDEVFS_CLEAR_HALT 596 - Clears endpoint halt (stall) and resets the endpoint toggle. This is 597 - only meaningful for bulk or interrupt endpoints. The ioctl parameter 598 - is an integer endpoint number (1 to 15, as identified in an endpoint 599 - descriptor), masked with USB_DIR_IN when referring to an endpoint 600 - which sends data to the host from the device. 601 - 602 - Use this on bulk or interrupt endpoints which have stalled, 603 - returning *-EPIPE* status to a data transfer request. Do not issue 604 - the control request directly, since that could invalidate the host's 605 - record of the data toggle. 606 - 607 - USBDEVFS_CONTROL 608 - Issues a control request to the device. The ioctl parameter points 609 - to a structure like this: 610 - 611 - :: 612 - 613 - struct usbdevfs_ctrltransfer { 614 - __u8 bRequestType; 615 - __u8 bRequest; 616 - __u16 wValue; 617 - __u16 wIndex; 618 - __u16 wLength; 619 - __u32 timeout; /* in milliseconds */ 620 - void *data; 621 - }; 622 - 623 - The first eight bytes of this structure are the contents of the 624 - SETUP packet to be sent to the device; see the USB 2.0 specification 625 - for details. The bRequestType value is composed by combining a 626 - USB_TYPE_\* value, a USB_DIR_\* value, and a USB_RECIP_\* 627 - value (from *<linux/usb.h>*). If wLength is nonzero, it describes 628 - the length of the data buffer, which is either written to the device 629 - (USB_DIR_OUT) or read from the device (USB_DIR_IN). 630 - 631 - At this writing, you can't transfer more than 4 KBytes of data to or 632 - from a device; usbfs has a limit, and some host controller drivers 633 - have a limit. (That's not usually a problem.) *Also* there's no way 634 - to say it's not OK to get a short read back from the device. 635 - 636 - USBDEVFS_RESET 637 - Does a USB level device reset. The ioctl parameter is ignored. After 638 - the reset, this rebinds all device interfaces. File modification 639 - time is not updated by this request. 640 - 641 - **Warning** 642 - 643 - *Avoid using this call* until some usbcore bugs get fixed, since 644 - it does not fully synchronize device, interface, and driver (not 645 - just usbfs) state. 646 - 647 - USBDEVFS_SETINTERFACE 648 - Sets the alternate setting for an interface. The ioctl parameter is 649 - a pointer to a structure like this: 650 - 651 - :: 652 - 653 - struct usbdevfs_setinterface { 654 - unsigned int interface; 655 - unsigned int altsetting; 656 - }; 657 - 658 - File modification time is not updated by this request. 659 - 660 - Those struct members are from some interface descriptor applying to 661 - the current configuration. The interface number is the 662 - bInterfaceNumber value, and the altsetting number is the 663 - bAlternateSetting value. (This resets each endpoint in the 664 - interface.) 665 - 666 - USBDEVFS_SETCONFIGURATION 667 - Issues the :c:func:`usb_set_configuration()` call for the 668 - device. The parameter is an integer holding the number of a 669 - configuration (bConfigurationValue from descriptor). File 670 - modification time is not updated by this request. 671 - 672 - **Warning** 673 - 674 - *Avoid using this call* until some usbcore bugs get fixed, since 675 - it does not fully synchronize device, interface, and driver (not 676 - just usbfs) state. 677 - 678 - Asynchronous I/O Support 679 - ~~~~~~~~~~~~~~~~~~~~~~~~ 680 - 681 - As mentioned above, there are situations where it may be important to 682 - initiate concurrent operations from user mode code. This is particularly 683 - important for periodic transfers (interrupt and isochronous), but it can 684 - be used for other kinds of USB requests too. In such cases, the 685 - asynchronous requests described here are essential. Rather than 686 - submitting one request and having the kernel block until it completes, 687 - the blocking is separate. 688 - 689 - These requests are packaged into a structure that resembles the URB used 690 - by kernel device drivers. (No POSIX Async I/O support here, sorry.) It 691 - identifies the endpoint type (USBDEVFS_URB_TYPE_\*), endpoint 692 - (number, masked with USB_DIR_IN as appropriate), buffer and length, 693 - and a user "context" value serving to uniquely identify each request. 694 - (It's usually a pointer to per-request data.) Flags can modify requests 695 - (not as many as supported for kernel drivers). 696 - 697 - Each request can specify a realtime signal number (between SIGRTMIN and 698 - SIGRTMAX, inclusive) to request a signal be sent when the request 699 - completes. 700 - 701 - When usbfs returns these urbs, the status value is updated, and the 702 - buffer may have been modified. Except for isochronous transfers, the 703 - actual_length is updated to say how many bytes were transferred; if the 704 - USBDEVFS_URB_DISABLE_SPD flag is set ("short packets are not OK"), if 705 - fewer bytes were read than were requested then you get an error report. 706 - 707 - :: 708 - 709 - struct usbdevfs_iso_packet_desc { 710 - unsigned int length; 711 - unsigned int actual_length; 712 - unsigned int status; 713 - }; 714 - 715 - struct usbdevfs_urb { 716 - unsigned char type; 717 - unsigned char endpoint; 718 - int status; 719 - unsigned int flags; 720 - void *buffer; 721 - int buffer_length; 722 - int actual_length; 723 - int start_frame; 724 - int number_of_packets; 725 - int error_count; 726 - unsigned int signr; 727 - void *usercontext; 728 - struct usbdevfs_iso_packet_desc iso_frame_desc[]; 729 - }; 730 - 731 - For these asynchronous requests, the file modification time reflects 732 - when the request was initiated. This contrasts with their use with the 733 - synchronous requests, where it reflects when requests complete. 734 - 735 - USBDEVFS_DISCARDURB 736 - *TBS* File modification time is not updated by this request. 737 - 738 - USBDEVFS_DISCSIGNAL 739 - *TBS* File modification time is not updated by this request. 740 - 741 - USBDEVFS_REAPURB 742 - *TBS* File modification time is not updated by this request. 743 - 744 - USBDEVFS_REAPURBNDELAY 745 - *TBS* File modification time is not updated by this request. 746 - 747 - USBDEVFS_SUBMITURB 748 - *TBS*
+290
Documentation/driver-api/usb/URB.rst
··· 1 + .. _usb-urb: 2 + 3 + USB Request Block (URB) 4 + ~~~~~~~~~~~~~~~~~~~~~~~ 5 + 6 + :Revised: 2000-Dec-05 7 + :Again: 2002-Jul-06 8 + :Again: 2005-Sep-19 9 + :Again: 2017-Mar-29 10 + 11 + 12 + .. note:: 13 + 14 + The USB subsystem now has a substantial section at :ref:`usb-hostside-api` 15 + section, generated from the current source code. 16 + This particular documentation file isn't complete and may not be 17 + updated to the last version; don't rely on it except for a quick 18 + overview. 19 + 20 + Basic concept or 'What is an URB?' 21 + ================================== 22 + 23 + The basic idea of the new driver is message passing, the message itself is 24 + called USB Request Block, or URB for short. 25 + 26 + - An URB consists of all relevant information to execute any USB transaction 27 + and deliver the data and status back. 28 + 29 + - Execution of an URB is inherently an asynchronous operation, i.e. the 30 + :c:func:`usb_submit_urb` call returns immediately after it has successfully 31 + queued the requested action. 32 + 33 + - Transfers for one URB can be canceled with :c:func:`usb_unlink_urb` 34 + at any time. 35 + 36 + - Each URB has a completion handler, which is called after the action 37 + has been successfully completed or canceled. The URB also contains a 38 + context-pointer for passing information to the completion handler. 39 + 40 + - Each endpoint for a device logically supports a queue of requests. 41 + You can fill that queue, so that the USB hardware can still transfer 42 + data to an endpoint while your driver handles completion of another. 43 + This maximizes use of USB bandwidth, and supports seamless streaming 44 + of data to (or from) devices when using periodic transfer modes. 45 + 46 + 47 + The URB structure 48 + ================= 49 + 50 + Some of the fields in struct :c:type:`urb` are:: 51 + 52 + struct urb 53 + { 54 + // (IN) device and pipe specify the endpoint queue 55 + struct usb_device *dev; // pointer to associated USB device 56 + unsigned int pipe; // endpoint information 57 + 58 + unsigned int transfer_flags; // URB_ISO_ASAP, URB_SHORT_NOT_OK, etc. 59 + 60 + // (IN) all urbs need completion routines 61 + void *context; // context for completion routine 62 + usb_complete_t complete; // pointer to completion routine 63 + 64 + // (OUT) status after each completion 65 + int status; // returned status 66 + 67 + // (IN) buffer used for data transfers 68 + void *transfer_buffer; // associated data buffer 69 + u32 transfer_buffer_length; // data buffer length 70 + int number_of_packets; // size of iso_frame_desc 71 + 72 + // (OUT) sometimes only part of CTRL/BULK/INTR transfer_buffer is used 73 + u32 actual_length; // actual data buffer length 74 + 75 + // (IN) setup stage for CTRL (pass a struct usb_ctrlrequest) 76 + unsigned char *setup_packet; // setup packet (control only) 77 + 78 + // Only for PERIODIC transfers (ISO, INTERRUPT) 79 + // (IN/OUT) start_frame is set unless URB_ISO_ASAP isn't set 80 + int start_frame; // start frame 81 + int interval; // polling interval 82 + 83 + // ISO only: packets are only "best effort"; each can have errors 84 + int error_count; // number of errors 85 + struct usb_iso_packet_descriptor iso_frame_desc[0]; 86 + }; 87 + 88 + Your driver must create the "pipe" value using values from the appropriate 89 + endpoint descriptor in an interface that it's claimed. 90 + 91 + 92 + How to get an URB? 93 + ================== 94 + 95 + URBs are allocated by calling :c:func:`usb_alloc_urb`:: 96 + 97 + struct urb *usb_alloc_urb(int isoframes, int mem_flags) 98 + 99 + Return value is a pointer to the allocated URB, 0 if allocation failed. 100 + The parameter isoframes specifies the number of isochronous transfer frames 101 + you want to schedule. For CTRL/BULK/INT, use 0. The mem_flags parameter 102 + holds standard memory allocation flags, letting you control (among other 103 + things) whether the underlying code may block or not. 104 + 105 + To free an URB, use :c:func:`usb_free_urb`:: 106 + 107 + void usb_free_urb(struct urb *urb) 108 + 109 + You may free an urb that you've submitted, but which hasn't yet been 110 + returned to you in a completion callback. It will automatically be 111 + deallocated when it is no longer in use. 112 + 113 + 114 + What has to be filled in? 115 + ========================= 116 + 117 + Depending on the type of transaction, there are some inline functions 118 + defined in ``linux/usb.h`` to simplify the initialization, such as 119 + :c:func:`usb_fill_control_urb`, :c:func:`usb_fill_bulk_urb` and 120 + :c:func:`usb_fill_int_urb`. In general, they need the usb device pointer, 121 + the pipe (usual format from usb.h), the transfer buffer, the desired transfer 122 + length, the completion handler, and its context. Take a look at the some 123 + existing drivers to see how they're used. 124 + 125 + Flags: 126 + 127 + - For ISO there are two startup behaviors: Specified start_frame or ASAP. 128 + - For ASAP set ``URB_ISO_ASAP`` in transfer_flags. 129 + 130 + If short packets should NOT be tolerated, set ``URB_SHORT_NOT_OK`` in 131 + transfer_flags. 132 + 133 + 134 + How to submit an URB? 135 + ===================== 136 + 137 + Just call :c:func:`usb_submit_urb`:: 138 + 139 + int usb_submit_urb(struct urb *urb, int mem_flags) 140 + 141 + The ``mem_flags`` parameter, such as ``GFP_ATOMIC``, controls memory 142 + allocation, such as whether the lower levels may block when memory is tight. 143 + 144 + It immediately returns, either with status 0 (request queued) or some 145 + error code, usually caused by the following: 146 + 147 + - Out of memory (``-ENOMEM``) 148 + - Unplugged device (``-ENODEV``) 149 + - Stalled endpoint (``-EPIPE``) 150 + - Too many queued ISO transfers (``-EAGAIN``) 151 + - Too many requested ISO frames (``-EFBIG``) 152 + - Invalid INT interval (``-EINVAL``) 153 + - More than one packet for INT (``-EINVAL``) 154 + 155 + After submission, ``urb->status`` is ``-EINPROGRESS``; however, you should 156 + never look at that value except in your completion callback. 157 + 158 + For isochronous endpoints, your completion handlers should (re)submit 159 + URBs to the same endpoint with the ``URB_ISO_ASAP`` flag, using 160 + multi-buffering, to get seamless ISO streaming. 161 + 162 + 163 + How to cancel an already running URB? 164 + ===================================== 165 + 166 + There are two ways to cancel an URB you've submitted but which hasn't 167 + been returned to your driver yet. For an asynchronous cancel, call 168 + :c:func:`usb_unlink_urb`:: 169 + 170 + int usb_unlink_urb(struct urb *urb) 171 + 172 + It removes the urb from the internal list and frees all allocated 173 + HW descriptors. The status is changed to reflect unlinking. Note 174 + that the URB will not normally have finished when :c:func:`usb_unlink_urb` 175 + returns; you must still wait for the completion handler to be called. 176 + 177 + To cancel an URB synchronously, call :c:func:`usb_kill_urb`:: 178 + 179 + void usb_kill_urb(struct urb *urb) 180 + 181 + It does everything :c:func:`usb_unlink_urb` does, and in addition it waits 182 + until after the URB has been returned and the completion handler 183 + has finished. It also marks the URB as temporarily unusable, so 184 + that if the completion handler or anyone else tries to resubmit it 185 + they will get a ``-EPERM`` error. Thus you can be sure that when 186 + :c:func:`usb_kill_urb` returns, the URB is totally idle. 187 + 188 + There is a lifetime issue to consider. An URB may complete at any 189 + time, and the completion handler may free the URB. If this happens 190 + while :c:func:`usb_unlink_urb` or :c:func:`usb_kill_urb` is running, it will 191 + cause a memory-access violation. The driver is responsible for avoiding this, 192 + which often means some sort of lock will be needed to prevent the URB 193 + from being deallocated while it is still in use. 194 + 195 + On the other hand, since usb_unlink_urb may end up calling the 196 + completion handler, the handler must not take any lock that is held 197 + when usb_unlink_urb is invoked. The general solution to this problem 198 + is to increment the URB's reference count while holding the lock, then 199 + drop the lock and call usb_unlink_urb or usb_kill_urb, and then 200 + decrement the URB's reference count. You increment the reference 201 + count by calling :c:func`usb_get_urb`:: 202 + 203 + struct urb *usb_get_urb(struct urb *urb) 204 + 205 + (ignore the return value; it is the same as the argument) and 206 + decrement the reference count by calling :c:func:`usb_free_urb`. Of course, 207 + none of this is necessary if there's no danger of the URB being freed 208 + by the completion handler. 209 + 210 + 211 + What about the completion handler? 212 + ================================== 213 + 214 + The handler is of the following type:: 215 + 216 + typedef void (*usb_complete_t)(struct urb *) 217 + 218 + I.e., it gets the URB that caused the completion call. In the completion 219 + handler, you should have a look at ``urb->status`` to detect any USB errors. 220 + Since the context parameter is included in the URB, you can pass 221 + information to the completion handler. 222 + 223 + Note that even when an error (or unlink) is reported, data may have been 224 + transferred. That's because USB transfers are packetized; it might take 225 + sixteen packets to transfer your 1KByte buffer, and ten of them might 226 + have transferred successfully before the completion was called. 227 + 228 + 229 + .. warning:: 230 + 231 + NEVER SLEEP IN A COMPLETION HANDLER. 232 + 233 + These are often called in atomic context. 234 + 235 + In the current kernel, completion handlers run with local interrupts 236 + disabled, but in the future this will be changed, so don't assume that 237 + local IRQs are always disabled inside completion handlers. 238 + 239 + How to do isochronous (ISO) transfers? 240 + ====================================== 241 + 242 + Besides the fields present on a bulk transfer, for ISO, you also 243 + also have to set ``urb->interval`` to say how often to make transfers; it's 244 + often one per frame (which is once every microframe for highspeed devices). 245 + The actual interval used will be a power of two that's no bigger than what 246 + you specify. You can use the :c:func:`usb_fill_int_urb` macro to fill 247 + most ISO transfer fields. 248 + 249 + For ISO transfers you also have to fill a :c:type:`usb_iso_packet_descriptor` 250 + structure, allocated at the end of the URB by :c:func:`usb_alloc_urb`, for 251 + each packet you want to schedule. 252 + 253 + The :c:func:`usb_submit_urb` call modifies ``urb->interval`` to the implemented 254 + interval value that is less than or equal to the requested interval value. If 255 + ``URB_ISO_ASAP`` scheduling is used, ``urb->start_frame`` is also updated. 256 + 257 + For each entry you have to specify the data offset for this frame (base is 258 + transfer_buffer), and the length you want to write/expect to read. 259 + After completion, actual_length contains the actual transferred length and 260 + status contains the resulting status for the ISO transfer for this frame. 261 + It is allowed to specify a varying length from frame to frame (e.g. for 262 + audio synchronisation/adaptive transfer rates). You can also use the length 263 + 0 to omit one or more frames (striping). 264 + 265 + For scheduling you can choose your own start frame or ``URB_ISO_ASAP``. As 266 + explained earlier, if you always keep at least one URB queued and your 267 + completion keeps (re)submitting a later URB, you'll get smooth ISO streaming 268 + (if usb bandwidth utilization allows). 269 + 270 + If you specify your own start frame, make sure it's several frames in advance 271 + of the current frame. You might want this model if you're synchronizing 272 + ISO data with some other event stream. 273 + 274 + 275 + How to start interrupt (INT) transfers? 276 + ======================================= 277 + 278 + Interrupt transfers, like isochronous transfers, are periodic, and happen 279 + in intervals that are powers of two (1, 2, 4 etc) units. Units are frames 280 + for full and low speed devices, and microframes for high speed ones. 281 + You can use the :c:func:`usb_fill_int_urb` macro to fill INT transfer fields. 282 + 283 + The :c:func:`usb_submit_urb` call modifies ``urb->interval`` to the implemented 284 + interval value that is less than or equal to the requested interval value. 285 + 286 + In Linux 2.6, unlike earlier versions, interrupt URBs are not automagically 287 + restarted when they complete. They end when the completion handler is 288 + called, just like other URBs. If you want an interrupt URB to be restarted, 289 + your completion handler must resubmit it. 290 + s
+207
Documentation/driver-api/usb/error-codes.rst
··· 1 + .. _usb-error-codes: 2 + 3 + USB Error codes 4 + ~~~~~~~~~~~~~~~ 5 + 6 + :Revised: 2004-Oct-21 7 + 8 + This is the documentation of (hopefully) all possible error codes (and 9 + their interpretation) that can be returned from usbcore. 10 + 11 + Some of them are returned by the Host Controller Drivers (HCDs), which 12 + device drivers only see through usbcore. As a rule, all the HCDs should 13 + behave the same except for transfer speed dependent behaviors and the 14 + way certain faults are reported. 15 + 16 + 17 + Error codes returned by :c:func:`usb_submit_urb` 18 + ================================================ 19 + 20 + Non-USB-specific: 21 + 22 + 23 + =============== =============================================== 24 + 0 URB submission went fine 25 + 26 + ``-ENOMEM`` no memory for allocation of internal structures 27 + =============== =============================================== 28 + 29 + USB-specific: 30 + 31 + ======================= ======================================================= 32 + ``-EBUSY`` The URB is already active. 33 + 34 + ``-ENODEV`` specified USB-device or bus doesn't exist 35 + 36 + ``-ENOENT`` specified interface or endpoint does not exist or 37 + is not enabled 38 + 39 + ``-ENXIO`` host controller driver does not support queuing of 40 + this type of urb. (treat as a host controller bug.) 41 + 42 + ``-EINVAL`` a) Invalid transfer type specified (or not supported) 43 + b) Invalid or unsupported periodic transfer interval 44 + c) ISO: attempted to change transfer interval 45 + d) ISO: ``number_of_packets`` is < 0 46 + e) various other cases 47 + 48 + ``-EXDEV`` ISO: ``URB_ISO_ASAP`` wasn't specified and all the 49 + frames the URB would be scheduled in have already 50 + expired. 51 + 52 + ``-EFBIG`` Host controller driver can't schedule that many ISO 53 + frames. 54 + 55 + ``-EPIPE`` The pipe type specified in the URB doesn't match the 56 + endpoint's actual type. 57 + 58 + ``-EMSGSIZE`` (a) endpoint maxpacket size is zero; it is not usable 59 + in the current interface altsetting. 60 + (b) ISO packet is larger than the endpoint maxpacket. 61 + (c) requested data transfer length is invalid: negative 62 + or too large for the host controller. 63 + 64 + ``-ENOSPC`` This request would overcommit the usb bandwidth reserved 65 + for periodic transfers (interrupt, isochronous). 66 + 67 + ``-ESHUTDOWN`` The device or host controller has been disabled due to 68 + some problem that could not be worked around. 69 + 70 + ``-EPERM`` Submission failed because ``urb->reject`` was set. 71 + 72 + ``-EHOSTUNREACH`` URB was rejected because the device is suspended. 73 + 74 + ``-ENOEXEC`` A control URB doesn't contain a Setup packet. 75 + ======================= ======================================================= 76 + 77 + Error codes returned by ``in urb->status`` or in ``iso_frame_desc[n].status`` (for ISO) 78 + ======================================================================================= 79 + 80 + USB device drivers may only test urb status values in completion handlers. 81 + This is because otherwise there would be a race between HCDs updating 82 + these values on one CPU, and device drivers testing them on another CPU. 83 + 84 + A transfer's actual_length may be positive even when an error has been 85 + reported. That's because transfers often involve several packets, so that 86 + one or more packets could finish before an error stops further endpoint I/O. 87 + 88 + For isochronous URBs, the urb status value is non-zero only if the URB is 89 + unlinked, the device is removed, the host controller is disabled, or the total 90 + transferred length is less than the requested length and the 91 + ``URB_SHORT_NOT_OK`` flag is set. Completion handlers for isochronous URBs 92 + should only see ``urb->status`` set to zero, ``-ENOENT``, ``-ECONNRESET``, 93 + ``-ESHUTDOWN``, or ``-EREMOTEIO``. Individual frame descriptor status fields 94 + may report more status codes. 95 + 96 + 97 + =============================== =============================================== 98 + 0 Transfer completed successfully 99 + 100 + ``-ENOENT`` URB was synchronously unlinked by 101 + :c:func:`usb_unlink_urb` 102 + 103 + ``-EINPROGRESS`` URB still pending, no results yet 104 + (That is, if drivers see this it's a bug.) 105 + 106 + ``-EPROTO`` [#f1]_, [#f2]_ a) bitstuff error 107 + b) no response packet received within the 108 + prescribed bus turn-around time 109 + c) unknown USB error 110 + 111 + ``-EILSEQ`` [#f1]_, [#f2]_ a) CRC mismatch 112 + b) no response packet received within the 113 + prescribed bus turn-around time 114 + c) unknown USB error 115 + 116 + Note that often the controller hardware does 117 + not distinguish among cases a), b), and c), so 118 + a driver cannot tell whether there was a 119 + protocol error, a failure to respond (often 120 + caused by device disconnect), or some other 121 + fault. 122 + 123 + ``-ETIME`` [#f2]_ No response packet received within the 124 + prescribed bus turn-around time. This error 125 + may instead be reported as 126 + ``-EPROTO`` or ``-EILSEQ``. 127 + 128 + ``-ETIMEDOUT`` Synchronous USB message functions use this code 129 + to indicate timeout expired before the transfer 130 + completed, and no other error was reported 131 + by HC. 132 + 133 + ``-EPIPE`` [#f2]_ Endpoint stalled. For non-control endpoints, 134 + reset this status with 135 + :c:func:`usb_clear_halt`. 136 + 137 + ``-ECOMM`` During an IN transfer, the host controller 138 + received data from an endpoint faster than it 139 + could be written to system memory 140 + 141 + ``-ENOSR`` During an OUT transfer, the host controller 142 + could not retrieve data from system memory fast 143 + enough to keep up with the USB data rate 144 + 145 + ``-EOVERFLOW`` [#f1]_ The amount of data returned by the endpoint was 146 + greater than either the max packet size of the 147 + endpoint or the remaining buffer size. 148 + "Babble". 149 + 150 + ``-EREMOTEIO`` The data read from the endpoint did not fill 151 + the specified buffer, and ``URB_SHORT_NOT_OK`` 152 + was set in ``urb->transfer_flags``. 153 + 154 + ``-ENODEV`` Device was removed. Often preceded by a burst 155 + of other errors, since the hub driver doesn't 156 + detect device removal events immediately. 157 + 158 + ``-EXDEV`` ISO transfer only partially completed 159 + (only set in ``iso_frame_desc[n].status``, 160 + not ``urb->status``) 161 + 162 + ``-EINVAL`` ISO madness, if this happens: Log off and 163 + go home 164 + 165 + ``-ECONNRESET`` URB was asynchronously unlinked by 166 + :c:func:`usb_unlink_urb` 167 + 168 + ``-ESHUTDOWN`` The device or host controller has been 169 + disabled due to some problem that could not 170 + be worked around, such as a physical 171 + disconnect. 172 + =============================== =============================================== 173 + 174 + 175 + .. [#f1] 176 + 177 + Error codes like ``-EPROTO``, ``-EILSEQ`` and ``-EOVERFLOW`` normally 178 + indicate hardware problems such as bad devices (including firmware) 179 + or cables. 180 + 181 + .. [#f2] 182 + 183 + This is also one of several codes that different kinds of host 184 + controller use to indicate a transfer has failed because of device 185 + disconnect. In the interval before the hub driver starts disconnect 186 + processing, devices may receive such fault reports for every request. 187 + 188 + 189 + 190 + Error codes returned by usbcore-functions 191 + ========================================= 192 + 193 + .. note:: expect also other submit and transfer status codes 194 + 195 + :c:func:`usb_register`: 196 + 197 + ======================= =================================== 198 + ``-EINVAL`` error during registering new driver 199 + ======================= =================================== 200 + 201 + ``usb_get_*/usb_set_*()``, 202 + :c:func:`usb_control_msg`, 203 + :c:func:`usb_bulk_msg()`: 204 + 205 + ======================= ============================================== 206 + ``-ETIMEDOUT`` Timeout expired before the transfer completed. 207 + ======================= ==============================================
+510
Documentation/driver-api/usb/gadget.rst
··· 1 + ======================== 2 + USB Gadget API for Linux 3 + ======================== 4 + 5 + :Author: David Brownell 6 + :Date: 20 August 2004 7 + 8 + Introduction 9 + ============ 10 + 11 + This document presents a Linux-USB "Gadget" kernel mode API, for use 12 + within peripherals and other USB devices that embed Linux. It provides 13 + an overview of the API structure, and shows how that fits into a system 14 + development project. This is the first such API released on Linux to 15 + address a number of important problems, including: 16 + 17 + - Supports USB 2.0, for high speed devices which can stream data at 18 + several dozen megabytes per second. 19 + 20 + - Handles devices with dozens of endpoints just as well as ones with 21 + just two fixed-function ones. Gadget drivers can be written so 22 + they're easy to port to new hardware. 23 + 24 + - Flexible enough to expose more complex USB device capabilities such 25 + as multiple configurations, multiple interfaces, composite devices, 26 + and alternate interface settings. 27 + 28 + - USB "On-The-Go" (OTG) support, in conjunction with updates to the 29 + Linux-USB host side. 30 + 31 + - Sharing data structures and API models with the Linux-USB host side 32 + API. This helps the OTG support, and looks forward to more-symmetric 33 + frameworks (where the same I/O model is used by both host and device 34 + side drivers). 35 + 36 + - Minimalist, so it's easier to support new device controller hardware. 37 + I/O processing doesn't imply large demands for memory or CPU 38 + resources. 39 + 40 + Most Linux developers will not be able to use this API, since they have 41 + USB ``host`` hardware in a PC, workstation, or server. Linux users with 42 + embedded systems are more likely to have USB peripheral hardware. To 43 + distinguish drivers running inside such hardware from the more familiar 44 + Linux "USB device drivers", which are host side proxies for the real USB 45 + devices, a different term is used: the drivers inside the peripherals 46 + are "USB gadget drivers". In USB protocol interactions, the device 47 + driver is the master (or "client driver") and the gadget driver is the 48 + slave (or "function driver"). 49 + 50 + The gadget API resembles the host side Linux-USB API in that both use 51 + queues of request objects to package I/O buffers, and those requests may 52 + be submitted or canceled. They share common definitions for the standard 53 + USB *Chapter 9* messages, structures, and constants. Also, both APIs 54 + bind and unbind drivers to devices. The APIs differ in detail, since the 55 + host side's current URB framework exposes a number of implementation 56 + details and assumptions that are inappropriate for a gadget API. While 57 + the model for control transfers and configuration management is 58 + necessarily different (one side is a hardware-neutral master, the other 59 + is a hardware-aware slave), the endpoint I/0 API used here should also 60 + be usable for an overhead-reduced host side API. 61 + 62 + Structure of Gadget Drivers 63 + =========================== 64 + 65 + A system running inside a USB peripheral normally has at least three 66 + layers inside the kernel to handle USB protocol processing, and may have 67 + additional layers in user space code. The ``gadget`` API is used by the 68 + middle layer to interact with the lowest level (which directly handles 69 + hardware). 70 + 71 + In Linux, from the bottom up, these layers are: 72 + 73 + *USB Controller Driver* 74 + This is the lowest software level. It is the only layer that talks 75 + to hardware, through registers, fifos, dma, irqs, and the like. The 76 + ``<linux/usb/gadget.h>`` API abstracts the peripheral controller 77 + endpoint hardware. That hardware is exposed through endpoint 78 + objects, which accept streams of IN/OUT buffers, and through 79 + callbacks that interact with gadget drivers. Since normal USB 80 + devices only have one upstream port, they only have one of these 81 + drivers. The controller driver can support any number of different 82 + gadget drivers, but only one of them can be used at a time. 83 + 84 + Examples of such controller hardware include the PCI-based NetChip 85 + 2280 USB 2.0 high speed controller, the SA-11x0 or PXA-25x UDC 86 + (found within many PDAs), and a variety of other products. 87 + 88 + *Gadget Driver* 89 + The lower boundary of this driver implements hardware-neutral USB 90 + functions, using calls to the controller driver. Because such 91 + hardware varies widely in capabilities and restrictions, and is used 92 + in embedded environments where space is at a premium, the gadget 93 + driver is often configured at compile time to work with endpoints 94 + supported by one particular controller. Gadget drivers may be 95 + portable to several different controllers, using conditional 96 + compilation. (Recent kernels substantially simplify the work 97 + involved in supporting new hardware, by *autoconfiguring* endpoints 98 + automatically for many bulk-oriented drivers.) Gadget driver 99 + responsibilities include: 100 + 101 + - handling setup requests (ep0 protocol responses) possibly 102 + including class-specific functionality 103 + 104 + - returning configuration and string descriptors 105 + 106 + - (re)setting configurations and interface altsettings, including 107 + enabling and configuring endpoints 108 + 109 + - handling life cycle events, such as managing bindings to 110 + hardware, USB suspend/resume, remote wakeup, and disconnection 111 + from the USB host. 112 + 113 + - managing IN and OUT transfers on all currently enabled endpoints 114 + 115 + Such drivers may be modules of proprietary code, although that 116 + approach is discouraged in the Linux community. 117 + 118 + *Upper Level* 119 + Most gadget drivers have an upper boundary that connects to some 120 + Linux driver or framework in Linux. Through that boundary flows the 121 + data which the gadget driver produces and/or consumes through 122 + protocol transfers over USB. Examples include: 123 + 124 + - user mode code, using generic (gadgetfs) or application specific 125 + files in ``/dev`` 126 + 127 + - networking subsystem (for network gadgets, like the CDC Ethernet 128 + Model gadget driver) 129 + 130 + - data capture drivers, perhaps video4Linux or a scanner driver; or 131 + test and measurement hardware. 132 + 133 + - input subsystem (for HID gadgets) 134 + 135 + - sound subsystem (for audio gadgets) 136 + 137 + - file system (for PTP gadgets) 138 + 139 + - block i/o subsystem (for usb-storage gadgets) 140 + 141 + - ... and more 142 + 143 + *Additional Layers* 144 + Other layers may exist. These could include kernel layers, such as 145 + network protocol stacks, as well as user mode applications building 146 + on standard POSIX system call APIs such as ``open()``, ``close()``, 147 + ``read()`` and ``write()``. On newer systems, POSIX Async I/O calls may 148 + be an option. Such user mode code will not necessarily be subject to 149 + the GNU General Public License (GPL). 150 + 151 + OTG-capable systems will also need to include a standard Linux-USB host 152 + side stack, with ``usbcore``, one or more *Host Controller Drivers* 153 + (HCDs), *USB Device Drivers* to support the OTG "Targeted Peripheral 154 + List", and so forth. There will also be an *OTG Controller Driver*, 155 + which is visible to gadget and device driver developers only indirectly. 156 + That helps the host and device side USB controllers implement the two 157 + new OTG protocols (HNP and SRP). Roles switch (host to peripheral, or 158 + vice versa) using HNP during USB suspend processing, and SRP can be 159 + viewed as a more battery-friendly kind of device wakeup protocol. 160 + 161 + Over time, reusable utilities are evolving to help make some gadget 162 + driver tasks simpler. For example, building configuration descriptors 163 + from vectors of descriptors for the configurations interfaces and 164 + endpoints is now automated, and many drivers now use autoconfiguration 165 + to choose hardware endpoints and initialize their descriptors. A 166 + potential example of particular interest is code implementing standard 167 + USB-IF protocols for HID, networking, storage, or audio classes. Some 168 + developers are interested in KDB or KGDB hooks, to let target hardware 169 + be remotely debugged. Most such USB protocol code doesn't need to be 170 + hardware-specific, any more than network protocols like X11, HTTP, or 171 + NFS are. Such gadget-side interface drivers should eventually be 172 + combined, to implement composite devices. 173 + 174 + Kernel Mode Gadget API 175 + ====================== 176 + 177 + Gadget drivers declare themselves through a struct 178 + :c:type:`usb_gadget_driver`, which is responsible for most parts of enumeration 179 + for a struct :c:type:`usb_gadget`. The response to a set_configuration usually 180 + involves enabling one or more of the struct :c:type:`usb_ep` objects exposed by 181 + the gadget, and submitting one or more struct :c:type:`usb_request` buffers to 182 + transfer data. Understand those four data types, and their operations, 183 + and you will understand how this API works. 184 + 185 + .. Note:: 186 + 187 + Other than the "Chapter 9" data types, most of the significant data 188 + types and functions are described here. 189 + 190 + However, some relevant information is likely omitted from what you 191 + are reading. One example of such information is endpoint 192 + autoconfiguration. You'll have to read the header file, and use 193 + example source code (such as that for "Gadget Zero"), to fully 194 + understand the API. 195 + 196 + The part of the API implementing some basic driver capabilities is 197 + specific to the version of the Linux kernel that's in use. The 2.6 198 + and upper kernel versions include a *driver model* framework that has 199 + no analogue on earlier kernels; so those parts of the gadget API are 200 + not fully portable. (They are implemented on 2.4 kernels, but in a 201 + different way.) The driver model state is another part of this API that is 202 + ignored by the kerneldoc tools. 203 + 204 + The core API does not expose every possible hardware feature, only the 205 + most widely available ones. There are significant hardware features, 206 + such as device-to-device DMA (without temporary storage in a memory 207 + buffer) that would be added using hardware-specific APIs. 208 + 209 + This API allows drivers to use conditional compilation to handle 210 + endpoint capabilities of different hardware, but doesn't require that. 211 + Hardware tends to have arbitrary restrictions, relating to transfer 212 + types, addressing, packet sizes, buffering, and availability. As a rule, 213 + such differences only matter for "endpoint zero" logic that handles 214 + device configuration and management. The API supports limited run-time 215 + detection of capabilities, through naming conventions for endpoints. 216 + Many drivers will be able to at least partially autoconfigure 217 + themselves. In particular, driver init sections will often have endpoint 218 + autoconfiguration logic that scans the hardware's list of endpoints to 219 + find ones matching the driver requirements (relying on those 220 + conventions), to eliminate some of the most common reasons for 221 + conditional compilation. 222 + 223 + Like the Linux-USB host side API, this API exposes the "chunky" nature 224 + of USB messages: I/O requests are in terms of one or more "packets", and 225 + packet boundaries are visible to drivers. Compared to RS-232 serial 226 + protocols, USB resembles synchronous protocols like HDLC (N bytes per 227 + frame, multipoint addressing, host as the primary station and devices as 228 + secondary stations) more than asynchronous ones (tty style: 8 data bits 229 + per frame, no parity, one stop bit). So for example the controller 230 + drivers won't buffer two single byte writes into a single two-byte USB 231 + IN packet, although gadget drivers may do so when they implement 232 + protocols where packet boundaries (and "short packets") are not 233 + significant. 234 + 235 + Driver Life Cycle 236 + ----------------- 237 + 238 + Gadget drivers make endpoint I/O requests to hardware without needing to 239 + know many details of the hardware, but driver setup/configuration code 240 + needs to handle some differences. Use the API like this: 241 + 242 + 1. Register a driver for the particular device side usb controller 243 + hardware, such as the net2280 on PCI (USB 2.0), sa11x0 or pxa25x as 244 + found in Linux PDAs, and so on. At this point the device is logically 245 + in the USB ch9 initial state (``attached``), drawing no power and not 246 + usable (since it does not yet support enumeration). Any host should 247 + not see the device, since it's not activated the data line pullup 248 + used by the host to detect a device, even if VBUS power is available. 249 + 250 + 2. Register a gadget driver that implements some higher level device 251 + function. That will then bind() to a :c:type:`usb_gadget`, which activates 252 + the data line pullup sometime after detecting VBUS. 253 + 254 + 3. The hardware driver can now start enumerating. The steps it handles 255 + are to accept USB ``power`` and ``set_address`` requests. Other steps are 256 + handled by the gadget driver. If the gadget driver module is unloaded 257 + before the host starts to enumerate, steps before step 7 are skipped. 258 + 259 + 4. The gadget driver's ``setup()`` call returns usb descriptors, based both 260 + on what the bus interface hardware provides and on the functionality 261 + being implemented. That can involve alternate settings or 262 + configurations, unless the hardware prevents such operation. For OTG 263 + devices, each configuration descriptor includes an OTG descriptor. 264 + 265 + 5. The gadget driver handles the last step of enumeration, when the USB 266 + host issues a ``set_configuration`` call. It enables all endpoints used 267 + in that configuration, with all interfaces in their default settings. 268 + That involves using a list of the hardware's endpoints, enabling each 269 + endpoint according to its descriptor. It may also involve using 270 + ``usb_gadget_vbus_draw`` to let more power be drawn from VBUS, as 271 + allowed by that configuration. For OTG devices, setting a 272 + configuration may also involve reporting HNP capabilities through a 273 + user interface. 274 + 275 + 6. Do real work and perform data transfers, possibly involving changes 276 + to interface settings or switching to new configurations, until the 277 + device is disconnect()ed from the host. Queue any number of transfer 278 + requests to each endpoint. It may be suspended and resumed several 279 + times before being disconnected. On disconnect, the drivers go back 280 + to step 3 (above). 281 + 282 + 7. When the gadget driver module is being unloaded, the driver unbind() 283 + callback is issued. That lets the controller driver be unloaded. 284 + 285 + Drivers will normally be arranged so that just loading the gadget driver 286 + module (or statically linking it into a Linux kernel) allows the 287 + peripheral device to be enumerated, but some drivers will defer 288 + enumeration until some higher level component (like a user mode daemon) 289 + enables it. Note that at this lowest level there are no policies about 290 + how ep0 configuration logic is implemented, except that it should obey 291 + USB specifications. Such issues are in the domain of gadget drivers, 292 + including knowing about implementation constraints imposed by some USB 293 + controllers or understanding that composite devices might happen to be 294 + built by integrating reusable components. 295 + 296 + Note that the lifecycle above can be slightly different for OTG devices. 297 + Other than providing an additional OTG descriptor in each configuration, 298 + only the HNP-related differences are particularly visible to driver 299 + code. They involve reporting requirements during the ``SET_CONFIGURATION`` 300 + request, and the option to invoke HNP during some suspend callbacks. 301 + Also, SRP changes the semantics of ``usb_gadget_wakeup`` slightly. 302 + 303 + USB 2.0 Chapter 9 Types and Constants 304 + ------------------------------------- 305 + 306 + Gadget drivers rely on common USB structures and constants defined in 307 + the :ref:`linux/usb/ch9.h <usb_chapter9>` header file, which is standard in 308 + Linux 2.6+ kernels. These are the same types and constants used by host side 309 + drivers (and usbcore). 310 + 311 + Core Objects and Methods 312 + ------------------------ 313 + 314 + These are declared in ``<linux/usb/gadget.h>``, and are used by gadget 315 + drivers to interact with USB peripheral controller drivers. 316 + 317 + .. kernel-doc:: include/linux/usb/gadget.h 318 + :internal: 319 + 320 + Optional Utilities 321 + ------------------ 322 + 323 + The core API is sufficient for writing a USB Gadget Driver, but some 324 + optional utilities are provided to simplify common tasks. These 325 + utilities include endpoint autoconfiguration. 326 + 327 + .. kernel-doc:: drivers/usb/gadget/usbstring.c 328 + :export: 329 + 330 + .. kernel-doc:: drivers/usb/gadget/config.c 331 + :export: 332 + 333 + Composite Device Framework 334 + -------------------------- 335 + 336 + The core API is sufficient for writing drivers for composite USB devices 337 + (with more than one function in a given configuration), and also 338 + multi-configuration devices (also more than one function, but not 339 + necessarily sharing a given configuration). There is however an optional 340 + framework which makes it easier to reuse and combine functions. 341 + 342 + Devices using this framework provide a struct :c:type:`usb_composite_driver`, 343 + which in turn provides one or more struct :c:type:`usb_configuration` 344 + instances. Each such configuration includes at least one struct 345 + :c:type:`usb_function`, which packages a user visible role such as "network 346 + link" or "mass storage device". Management functions may also exist, 347 + such as "Device Firmware Upgrade". 348 + 349 + .. kernel-doc:: include/linux/usb/composite.h 350 + :internal: 351 + 352 + .. kernel-doc:: drivers/usb/gadget/composite.c 353 + :export: 354 + 355 + Composite Device Functions 356 + -------------------------- 357 + 358 + At this writing, a few of the current gadget drivers have been converted 359 + to this framework. Near-term plans include converting all of them, 360 + except for ``gadgetfs``. 361 + 362 + Peripheral Controller Drivers 363 + ============================= 364 + 365 + The first hardware supporting this API was the NetChip 2280 controller, 366 + which supports USB 2.0 high speed and is based on PCI. This is the 367 + ``net2280`` driver module. The driver supports Linux kernel versions 2.4 368 + and 2.6; contact NetChip Technologies for development boards and product 369 + information. 370 + 371 + Other hardware working in the ``gadget`` framework includes: Intel's PXA 372 + 25x and IXP42x series processors (``pxa2xx_udc``), Toshiba TC86c001 373 + "Goku-S" (``goku_udc``), Renesas SH7705/7727 (``sh_udc``), MediaQ 11xx 374 + (``mq11xx_udc``), Hynix HMS30C7202 (``h7202_udc``), National 9303/4 375 + (``n9604_udc``), Texas Instruments OMAP (``omap_udc``), Sharp LH7A40x 376 + (``lh7a40x_udc``), and more. Most of those are full speed controllers. 377 + 378 + At this writing, there are people at work on drivers in this framework 379 + for several other USB device controllers, with plans to make many of 380 + them be widely available. 381 + 382 + A partial USB simulator, the ``dummy_hcd`` driver, is available. It can 383 + act like a net2280, a pxa25x, or an sa11x0 in terms of available 384 + endpoints and device speeds; and it simulates control, bulk, and to some 385 + extent interrupt transfers. That lets you develop some parts of a gadget 386 + driver on a normal PC, without any special hardware, and perhaps with 387 + the assistance of tools such as GDB running with User Mode Linux. At 388 + least one person has expressed interest in adapting that approach, 389 + hooking it up to a simulator for a microcontroller. Such simulators can 390 + help debug subsystems where the runtime hardware is unfriendly to 391 + software development, or is not yet available. 392 + 393 + Support for other controllers is expected to be developed and 394 + contributed over time, as this driver framework evolves. 395 + 396 + Gadget Drivers 397 + ============== 398 + 399 + In addition to *Gadget Zero* (used primarily for testing and development 400 + with drivers for usb controller hardware), other gadget drivers exist. 401 + 402 + There's an ``ethernet`` gadget driver, which implements one of the most 403 + useful *Communications Device Class* (CDC) models. One of the standards 404 + for cable modem interoperability even specifies the use of this ethernet 405 + model as one of two mandatory options. Gadgets using this code look to a 406 + USB host as if they're an Ethernet adapter. It provides access to a 407 + network where the gadget's CPU is one host, which could easily be 408 + bridging, routing, or firewalling access to other networks. Since some 409 + hardware can't fully implement the CDC Ethernet requirements, this 410 + driver also implements a "good parts only" subset of CDC Ethernet. (That 411 + subset doesn't advertise itself as CDC Ethernet, to avoid creating 412 + problems.) 413 + 414 + Support for Microsoft's ``RNDIS`` protocol has been contributed by 415 + Pengutronix and Auerswald GmbH. This is like CDC Ethernet, but it runs 416 + on more slightly USB hardware (but less than the CDC subset). However, 417 + its main claim to fame is being able to connect directly to recent 418 + versions of Windows, using drivers that Microsoft bundles and supports, 419 + making it much simpler to network with Windows. 420 + 421 + There is also support for user mode gadget drivers, using ``gadgetfs``. 422 + This provides a *User Mode API* that presents each endpoint as a single 423 + file descriptor. I/O is done using normal ``read()`` and ``read()`` calls. 424 + Familiar tools like GDB and pthreads can be used to develop and debug 425 + user mode drivers, so that once a robust controller driver is available 426 + many applications for it won't require new kernel mode software. Linux 427 + 2.6 *Async I/O (AIO)* support is available, so that user mode software 428 + can stream data with only slightly more overhead than a kernel driver. 429 + 430 + There's a USB Mass Storage class driver, which provides a different 431 + solution for interoperability with systems such as MS-Windows and MacOS. 432 + That *Mass Storage* driver uses a file or block device as backing store 433 + for a drive, like the ``loop`` driver. The USB host uses the BBB, CB, or 434 + CBI versions of the mass storage class specification, using transparent 435 + SCSI commands to access the data from the backing store. 436 + 437 + There's a "serial line" driver, useful for TTY style operation over USB. 438 + The latest version of that driver supports CDC ACM style operation, like 439 + a USB modem, and so on most hardware it can interoperate easily with 440 + MS-Windows. One interesting use of that driver is in boot firmware (like 441 + a BIOS), which can sometimes use that model with very small systems 442 + without real serial lines. 443 + 444 + Support for other kinds of gadget is expected to be developed and 445 + contributed over time, as this driver framework evolves. 446 + 447 + USB On-The-GO (OTG) 448 + =================== 449 + 450 + USB OTG support on Linux 2.6 was initially developed by Texas 451 + Instruments for `OMAP <http://www.omap.com>`__ 16xx and 17xx series 452 + processors. Other OTG systems should work in similar ways, but the 453 + hardware level details could be very different. 454 + 455 + Systems need specialized hardware support to implement OTG, notably 456 + including a special *Mini-AB* jack and associated transceiver to support 457 + *Dual-Role* operation: they can act either as a host, using the standard 458 + Linux-USB host side driver stack, or as a peripheral, using this 459 + ``gadget`` framework. To do that, the system software relies on small 460 + additions to those programming interfaces, and on a new internal 461 + component (here called an "OTG Controller") affecting which driver stack 462 + connects to the OTG port. In each role, the system can re-use the 463 + existing pool of hardware-neutral drivers, layered on top of the 464 + controller driver interfaces (:c:type:`usb_bus` or :c:type:`usb_gadget`). 465 + Such drivers need at most minor changes, and most of the calls added to 466 + support OTG can also benefit non-OTG products. 467 + 468 + - Gadget drivers test the ``is_otg`` flag, and use it to determine 469 + whether or not to include an OTG descriptor in each of their 470 + configurations. 471 + 472 + - Gadget drivers may need changes to support the two new OTG protocols, 473 + exposed in new gadget attributes such as ``b_hnp_enable`` flag. HNP 474 + support should be reported through a user interface (two LEDs could 475 + suffice), and is triggered in some cases when the host suspends the 476 + peripheral. SRP support can be user-initiated just like remote 477 + wakeup, probably by pressing the same button. 478 + 479 + - On the host side, USB device drivers need to be taught to trigger HNP 480 + at appropriate moments, using ``usb_suspend_device()``. That also 481 + conserves battery power, which is useful even for non-OTG 482 + configurations. 483 + 484 + - Also on the host side, a driver must support the OTG "Targeted 485 + Peripheral List". That's just a whitelist, used to reject peripherals 486 + not supported with a given Linux OTG host. *This whitelist is 487 + product-specific; each product must modify* ``otg_whitelist.h`` *to 488 + match its interoperability specification.* 489 + 490 + Non-OTG Linux hosts, like PCs and workstations, normally have some 491 + solution for adding drivers, so that peripherals that aren't 492 + recognized can eventually be supported. That approach is unreasonable 493 + for consumer products that may never have their firmware upgraded, 494 + and where it's usually unrealistic to expect traditional 495 + PC/workstation/server kinds of support model to work. For example, 496 + it's often impractical to change device firmware once the product has 497 + been distributed, so driver bugs can't normally be fixed if they're 498 + found after shipment. 499 + 500 + Additional changes are needed below those hardware-neutral :c:type:`usb_bus` 501 + and :c:type:`usb_gadget` driver interfaces; those aren't discussed here in any 502 + detail. Those affect the hardware-specific code for each USB Host or 503 + Peripheral controller, and how the HCD initializes (since OTG can be 504 + active only on a single port). They also involve what may be called an 505 + *OTG Controller Driver*, managing the OTG transceiver and the OTG state 506 + machine logic as well as much of the root hub behavior for the OTG port. 507 + The OTG controller driver needs to activate and deactivate USB 508 + controllers depending on the relevant device role. Some related changes 509 + were needed inside usbcore, so that it can identify OTG-capable devices 510 + and respond appropriately to HNP or SRP protocols.
+26
Documentation/driver-api/usb/index.rst
··· 1 + ============= 2 + Linux USB API 3 + ============= 4 + 5 + .. toctree:: 6 + 7 + usb 8 + gadget 9 + anchors 10 + bulk-streams 11 + callbacks 12 + dma 13 + URB 14 + power-management 15 + hotplug 16 + persist 17 + error-codes 18 + writing_usb_driver 19 + writing_musb_glue_layer 20 + 21 + .. only:: subproject and html 22 + 23 + Indices 24 + ======= 25 + 26 + * :ref:`genindex`
+1047
Documentation/driver-api/usb/usb.rst
··· 1 + .. _usb-hostside-api: 2 + 3 + =========================== 4 + The Linux-USB Host Side API 5 + =========================== 6 + 7 + Introduction to USB on Linux 8 + ============================ 9 + 10 + A Universal Serial Bus (USB) is used to connect a host, such as a PC or 11 + workstation, to a number of peripheral devices. USB uses a tree 12 + structure, with the host as the root (the system's master), hubs as 13 + interior nodes, and peripherals as leaves (and slaves). Modern PCs 14 + support several such trees of USB devices, usually 15 + a few USB 3.0 (5 GBit/s) or USB 3.1 (10 GBit/s) and some legacy 16 + USB 2.0 (480 MBit/s) busses just in case. 17 + 18 + That master/slave asymmetry was designed-in for a number of reasons, one 19 + being ease of use. It is not physically possible to mistake upstream and 20 + downstream or it does not matter with a type C plug (or they are built into the 21 + peripheral). Also, the host software doesn't need to deal with 22 + distributed auto-configuration since the pre-designated master node 23 + manages all that. 24 + 25 + Kernel developers added USB support to Linux early in the 2.2 kernel 26 + series and have been developing it further since then. Besides support 27 + for each new generation of USB, various host controllers gained support, 28 + new drivers for peripherals have been added and advanced features for latency 29 + measurement and improved power management introduced. 30 + 31 + Linux can run inside USB devices as well as on the hosts that control 32 + the devices. But USB device drivers running inside those peripherals 33 + don't do the same things as the ones running inside hosts, so they've 34 + been given a different name: *gadget drivers*. This document does not 35 + cover gadget drivers. 36 + 37 + USB Host-Side API Model 38 + ======================= 39 + 40 + Host-side drivers for USB devices talk to the "usbcore" APIs. There are 41 + two. One is intended for *general-purpose* drivers (exposed through 42 + driver frameworks), and the other is for drivers that are *part of the 43 + core*. Such core drivers include the *hub* driver (which manages trees 44 + of USB devices) and several different kinds of *host controller 45 + drivers*, which control individual busses. 46 + 47 + The device model seen by USB drivers is relatively complex. 48 + 49 + - USB supports four kinds of data transfers (control, bulk, interrupt, 50 + and isochronous). Two of them (control and bulk) use bandwidth as 51 + it's available, while the other two (interrupt and isochronous) are 52 + scheduled to provide guaranteed bandwidth. 53 + 54 + - The device description model includes one or more "configurations" 55 + per device, only one of which is active at a time. Devices are supposed 56 + to be capable of operating at lower than their top 57 + speeds and may provide a BOS descriptor showing the lowest speed they 58 + remain fully operational at. 59 + 60 + - From USB 3.0 on configurations have one or more "functions", which 61 + provide a common functionality and are grouped together for purposes 62 + of power management. 63 + 64 + - Configurations or functions have one or more "interfaces", each of which may have 65 + "alternate settings". Interfaces may be standardized by USB "Class" 66 + specifications, or may be specific to a vendor or device. 67 + 68 + USB device drivers actually bind to interfaces, not devices. Think of 69 + them as "interface drivers", though you may not see many devices 70 + where the distinction is important. *Most USB devices are simple, 71 + with only one function, one configuration, one interface, and one alternate 72 + setting.* 73 + 74 + - Interfaces have one or more "endpoints", each of which supports one 75 + type and direction of data transfer such as "bulk out" or "interrupt 76 + in". The entire configuration may have up to sixteen endpoints in 77 + each direction, allocated as needed among all the interfaces. 78 + 79 + - Data transfer on USB is packetized; each endpoint has a maximum 80 + packet size. Drivers must often be aware of conventions such as 81 + flagging the end of bulk transfers using "short" (including zero 82 + length) packets. 83 + 84 + - The Linux USB API supports synchronous calls for control and bulk 85 + messages. It also supports asynchronous calls for all kinds of data 86 + transfer, using request structures called "URBs" (USB Request 87 + Blocks). 88 + 89 + Accordingly, the USB Core API exposed to device drivers covers quite a 90 + lot of territory. You'll probably need to consult the USB 3.0 91 + specification, available online from www.usb.org at no cost, as well as 92 + class or device specifications. 93 + 94 + The only host-side drivers that actually touch hardware (reading/writing 95 + registers, handling IRQs, and so on) are the HCDs. In theory, all HCDs 96 + provide the same functionality through the same API. In practice, that's 97 + becoming more true, but there are still differences 98 + that crop up especially with fault handling on the less common controllers. 99 + Different controllers don't 100 + necessarily report the same aspects of failures, and recovery from 101 + faults (including software-induced ones like unlinking an URB) isn't yet 102 + fully consistent. Device driver authors should make a point of doing 103 + disconnect testing (while the device is active) with each different host 104 + controller driver, to make sure drivers don't have bugs of their own as 105 + well as to make sure they aren't relying on some HCD-specific behavior. 106 + 107 + .. _usb_chapter9: 108 + 109 + USB-Standard Types 110 + ================== 111 + 112 + In ``<linux/usb/ch9.h>`` you will find the USB data types defined in 113 + chapter 9 of the USB specification. These data types are used throughout 114 + USB, and in APIs including this host side API, gadget APIs, usb character 115 + devices and debugfs interfaces. 116 + 117 + .. kernel-doc:: include/linux/usb/ch9.h 118 + :internal: 119 + 120 + .. _usb_header: 121 + 122 + Host-Side Data Types and Macros 123 + =============================== 124 + 125 + The host side API exposes several layers to drivers, some of which are 126 + more necessary than others. These support lifecycle models for host side 127 + drivers and devices, and support passing buffers through usbcore to some 128 + HCD that performs the I/O for the device driver. 129 + 130 + .. kernel-doc:: include/linux/usb.h 131 + :internal: 132 + 133 + USB Core APIs 134 + ============= 135 + 136 + There are two basic I/O models in the USB API. The most elemental one is 137 + asynchronous: drivers submit requests in the form of an URB, and the 138 + URB's completion callback handles the next step. All USB transfer types 139 + support that model, although there are special cases for control URBs 140 + (which always have setup and status stages, but may not have a data 141 + stage) and isochronous URBs (which allow large packets and include 142 + per-packet fault reports). Built on top of that is synchronous API 143 + support, where a driver calls a routine that allocates one or more URBs, 144 + submits them, and waits until they complete. There are synchronous 145 + wrappers for single-buffer control and bulk transfers (which are awkward 146 + to use in some driver disconnect scenarios), and for scatterlist based 147 + streaming i/o (bulk or interrupt). 148 + 149 + USB drivers need to provide buffers that can be used for DMA, although 150 + they don't necessarily need to provide the DMA mapping themselves. There 151 + are APIs to use used when allocating DMA buffers, which can prevent use 152 + of bounce buffers on some systems. In some cases, drivers may be able to 153 + rely on 64bit DMA to eliminate another kind of bounce buffer. 154 + 155 + .. kernel-doc:: drivers/usb/core/urb.c 156 + :export: 157 + 158 + .. kernel-doc:: drivers/usb/core/message.c 159 + :export: 160 + 161 + .. kernel-doc:: drivers/usb/core/file.c 162 + :export: 163 + 164 + .. kernel-doc:: drivers/usb/core/driver.c 165 + :export: 166 + 167 + .. kernel-doc:: drivers/usb/core/usb.c 168 + :export: 169 + 170 + .. kernel-doc:: drivers/usb/core/hub.c 171 + :export: 172 + 173 + Host Controller APIs 174 + ==================== 175 + 176 + These APIs are only for use by host controller drivers, most of which 177 + implement standard register interfaces such as XHCI, EHCI, OHCI, or UHCI. UHCI 178 + was one of the first interfaces, designed by Intel and also used by VIA; 179 + it doesn't do much in hardware. OHCI was designed later, to have the 180 + hardware do more work (bigger transfers, tracking protocol state, and so 181 + on). EHCI was designed with USB 2.0; its design has features that 182 + resemble OHCI (hardware does much more work) as well as UHCI (some parts 183 + of ISO support, TD list processing). XHCI was designed with USB 3.0. It 184 + continues to shift support for functionality into hardware. 185 + 186 + There are host controllers other than the "big three", although most PCI 187 + based controllers (and a few non-PCI based ones) use one of those 188 + interfaces. Not all host controllers use DMA; some use PIO, and there is 189 + also a simulator and a virtual host controller to pipe USB over the network. 190 + 191 + The same basic APIs are available to drivers for all those controllers. 192 + For historical reasons they are in two layers: :c:type:`struct 193 + usb_bus <usb_bus>` is a rather thin layer that became available 194 + in the 2.2 kernels, while :c:type:`struct usb_hcd <usb_hcd>` 195 + is a more featureful layer 196 + that lets HCDs share common code, to shrink driver size and 197 + significantly reduce hcd-specific behaviors. 198 + 199 + .. kernel-doc:: drivers/usb/core/hcd.c 200 + :export: 201 + 202 + .. kernel-doc:: drivers/usb/core/hcd-pci.c 203 + :export: 204 + 205 + .. kernel-doc:: drivers/usb/core/buffer.c 206 + :internal: 207 + 208 + The USB character device nodes 209 + ============================== 210 + 211 + This chapter presents the Linux character device nodes. You may prefer 212 + to avoid writing new kernel code for your USB driver. User mode device 213 + drivers are usually packaged as applications or libraries, and may use 214 + character devices through some programming library that wraps it. 215 + Such libraries include: 216 + 217 + - `libusb <http://libusb.sourceforge.net>`__ for C/C++, and 218 + - `jUSB <http://jUSB.sourceforge.net>`__ for Java. 219 + 220 + Some old information about it can be seen at the "USB Device Filesystem" 221 + section of the USB Guide. The latest copy of the USB Guide can be found 222 + at http://www.linux-usb.org/ 223 + 224 + .. note:: 225 + 226 + - They were used to be implemented via *usbfs*, but this is not part of 227 + the sysfs debug interface. 228 + 229 + - This particular documentation is incomplete, especially with respect 230 + to the asynchronous mode. As of kernel 2.5.66 the code and this 231 + (new) documentation need to be cross-reviewed. 232 + 233 + What files are in "devtmpfs"? 234 + ----------------------------- 235 + 236 + Conventionally mounted at ``/dev/bus/usb/``, usbfs features include: 237 + 238 + - ``/dev/bus/usb/BBB/DDD`` ... magic files exposing the each device's 239 + configuration descriptors, and supporting a series of ioctls for 240 + making device requests, including I/O to devices. (Purely for access 241 + by programs.) 242 + 243 + Each bus is given a number (``BBB``) based on when it was enumerated; within 244 + each bus, each device is given a similar number (``DDD``). Those ``BBB/DDD`` 245 + paths are not "stable" identifiers; expect them to change even if you 246 + always leave the devices plugged in to the same hub port. *Don't even 247 + think of saving these in application configuration files.* Stable 248 + identifiers are available, for user mode applications that want to use 249 + them. HID and networking devices expose these stable IDs, so that for 250 + example you can be sure that you told the right UPS to power down its 251 + second server. Pleast note that it doesn't (yet) expose those IDs. 252 + 253 + /dev/bus/usb/BBB/DDD 254 + -------------------- 255 + 256 + Use these files in one of these basic ways: 257 + 258 + - *They can be read,* producing first the device descriptor (18 bytes) and 259 + then the descriptors for the current configuration. See the USB 2.0 spec 260 + for details about those binary data formats. You'll need to convert most 261 + multibyte values from little endian format to your native host byte 262 + order, although a few of the fields in the device descriptor (both of 263 + the BCD-encoded fields, and the vendor and product IDs) will be 264 + byteswapped for you. Note that configuration descriptors include 265 + descriptors for interfaces, altsettings, endpoints, and maybe additional 266 + class descriptors. 267 + 268 + - *Perform USB operations* using *ioctl()* requests to make endpoint I/O 269 + requests (synchronously or asynchronously) or manage the device. These 270 + requests need the ``CAP_SYS_RAWIO`` capability, as well as filesystem 271 + access permissions. Only one ioctl request can be made on one of these 272 + device files at a time. This means that if you are synchronously reading 273 + an endpoint from one thread, you won't be able to write to a different 274 + endpoint from another thread until the read completes. This works for 275 + *half duplex* protocols, but otherwise you'd use asynchronous i/o 276 + requests. 277 + 278 + Each connected USB device has one file. The ``BBB`` indicates the bus 279 + number. The ``DDD`` indicates the device address on that bus. Both 280 + of these numbers are assigned sequentially, and can be reused, so 281 + you can't rely on them for stable access to devices. For example, 282 + it's relatively common for devices to re-enumerate while they are 283 + still connected (perhaps someone jostled their power supply, hub, 284 + or USB cable), so a device might be ``002/027`` when you first connect 285 + it and ``002/048`` sometime later. 286 + 287 + These files can be read as binary data. The binary data consists 288 + of first the device descriptor, then the descriptors for each 289 + configuration of the device. Multi-byte fields in the device descriptor 290 + are converted to host endianness by the kernel. The configuration 291 + descriptors are in bus endian format! The configuration descriptor 292 + are wTotalLength bytes apart. If a device returns less configuration 293 + descriptor data than indicated by wTotalLength there will be a hole in 294 + the file for the missing bytes. This information is also shown 295 + in text form by the ``/sys/kernel/debug/usb/devices`` file, described later. 296 + 297 + These files may also be used to write user-level drivers for the USB 298 + devices. You would open the ``/dev/bus/usb/BBB/DDD`` file read/write, 299 + read its descriptors to make sure it's the device you expect, and then 300 + bind to an interface (or perhaps several) using an ioctl call. You 301 + would issue more ioctls to the device to communicate to it using 302 + control, bulk, or other kinds of USB transfers. The IOCTLs are 303 + listed in the ``<linux/usbdevice_fs.h>`` file, and at this writing the 304 + source code (``linux/drivers/usb/core/devio.c``) is the primary reference 305 + for how to access devices through those files. 306 + 307 + Note that since by default these ``BBB/DDD`` files are writable only by 308 + root, only root can write such user mode drivers. You can selectively 309 + grant read/write permissions to other users by using ``chmod``. Also, 310 + usbfs mount options such as ``devmode=0666`` may be helpful. 311 + 312 + 313 + Life Cycle of User Mode Drivers 314 + ------------------------------- 315 + 316 + Such a driver first needs to find a device file for a device it knows 317 + how to handle. Maybe it was told about it because a ``/sbin/hotplug`` 318 + event handling agent chose that driver to handle the new device. Or 319 + maybe it's an application that scans all the ``/dev/bus/usb`` device files, 320 + and ignores most devices. In either case, it should :c:func:`read()` 321 + all the descriptors from the device file, and check them against what it 322 + knows how to handle. It might just reject everything except a particular 323 + vendor and product ID, or need a more complex policy. 324 + 325 + Never assume there will only be one such device on the system at a time! 326 + If your code can't handle more than one device at a time, at least 327 + detect when there's more than one, and have your users choose which 328 + device to use. 329 + 330 + Once your user mode driver knows what device to use, it interacts with 331 + it in either of two styles. The simple style is to make only control 332 + requests; some devices don't need more complex interactions than those. 333 + (An example might be software using vendor-specific control requests for 334 + some initialization or configuration tasks, with a kernel driver for the 335 + rest.) 336 + 337 + More likely, you need a more complex style driver: one using non-control 338 + endpoints, reading or writing data and claiming exclusive use of an 339 + interface. *Bulk* transfers are easiest to use, but only their sibling 340 + *interrupt* transfers work with low speed devices. Both interrupt and 341 + *isochronous* transfers offer service guarantees because their bandwidth 342 + is reserved. Such "periodic" transfers are awkward to use through usbfs, 343 + unless you're using the asynchronous calls. However, interrupt transfers 344 + can also be used in a synchronous "one shot" style. 345 + 346 + Your user-mode driver should never need to worry about cleaning up 347 + request state when the device is disconnected, although it should close 348 + its open file descriptors as soon as it starts seeing the ENODEV errors. 349 + 350 + The ioctl() Requests 351 + -------------------- 352 + 353 + To use these ioctls, you need to include the following headers in your 354 + userspace program:: 355 + 356 + #include <linux/usb.h> 357 + #include <linux/usbdevice_fs.h> 358 + #include <asm/byteorder.h> 359 + 360 + The standard USB device model requests, from "Chapter 9" of the USB 2.0 361 + specification, are automatically included from the ``<linux/usb/ch9.h>`` 362 + header. 363 + 364 + Unless noted otherwise, the ioctl requests described here will update 365 + the modification time on the usbfs file to which they are applied 366 + (unless they fail). A return of zero indicates success; otherwise, a 367 + standard USB error code is returned (These are documented in 368 + :ref:`usb-error-codes`). 369 + 370 + Each of these files multiplexes access to several I/O streams, one per 371 + endpoint. Each device has one control endpoint (endpoint zero) which 372 + supports a limited RPC style RPC access. Devices are configured by 373 + hub_wq (in the kernel) setting a device-wide *configuration* that 374 + affects things like power consumption and basic functionality. The 375 + endpoints are part of USB *interfaces*, which may have *altsettings* 376 + affecting things like which endpoints are available. Many devices only 377 + have a single configuration and interface, so drivers for them will 378 + ignore configurations and altsettings. 379 + 380 + Management/Status Requests 381 + ~~~~~~~~~~~~~~~~~~~~~~~~~~ 382 + 383 + A number of usbfs requests don't deal very directly with device I/O. 384 + They mostly relate to device management and status. These are all 385 + synchronous requests. 386 + 387 + USBDEVFS_CLAIMINTERFACE 388 + This is used to force usbfs to claim a specific interface, which has 389 + not previously been claimed by usbfs or any other kernel driver. The 390 + ioctl parameter is an integer holding the number of the interface 391 + (bInterfaceNumber from descriptor). 392 + 393 + Note that if your driver doesn't claim an interface before trying to 394 + use one of its endpoints, and no other driver has bound to it, then 395 + the interface is automatically claimed by usbfs. 396 + 397 + This claim will be released by a RELEASEINTERFACE ioctl, or by 398 + closing the file descriptor. File modification time is not updated 399 + by this request. 400 + 401 + USBDEVFS_CONNECTINFO 402 + Says whether the device is lowspeed. The ioctl parameter points to a 403 + structure like this:: 404 + 405 + struct usbdevfs_connectinfo { 406 + unsigned int devnum; 407 + unsigned char slow; 408 + }; 409 + 410 + File modification time is not updated by this request. 411 + 412 + *You can't tell whether a "not slow" device is connected at high 413 + speed (480 MBit/sec) or just full speed (12 MBit/sec).* You should 414 + know the devnum value already, it's the DDD value of the device file 415 + name. 416 + 417 + USBDEVFS_GETDRIVER 418 + Returns the name of the kernel driver bound to a given interface (a 419 + string). Parameter is a pointer to this structure, which is 420 + modified:: 421 + 422 + struct usbdevfs_getdriver { 423 + unsigned int interface; 424 + char driver[USBDEVFS_MAXDRIVERNAME + 1]; 425 + }; 426 + 427 + File modification time is not updated by this request. 428 + 429 + USBDEVFS_IOCTL 430 + Passes a request from userspace through to a kernel driver that has 431 + an ioctl entry in the *struct usb_driver* it registered:: 432 + 433 + struct usbdevfs_ioctl { 434 + int ifno; 435 + int ioctl_code; 436 + void *data; 437 + }; 438 + 439 + /* user mode call looks like this. 440 + * 'request' becomes the driver->ioctl() 'code' parameter. 441 + * the size of 'param' is encoded in 'request', and that data 442 + * is copied to or from the driver->ioctl() 'buf' parameter. 443 + */ 444 + static int 445 + usbdev_ioctl (int fd, int ifno, unsigned request, void *param) 446 + { 447 + struct usbdevfs_ioctl wrapper; 448 + 449 + wrapper.ifno = ifno; 450 + wrapper.ioctl_code = request; 451 + wrapper.data = param; 452 + 453 + return ioctl (fd, USBDEVFS_IOCTL, &wrapper); 454 + } 455 + 456 + File modification time is not updated by this request. 457 + 458 + This request lets kernel drivers talk to user mode code through 459 + filesystem operations even when they don't create a character or 460 + block special device. It's also been used to do things like ask 461 + devices what device special file should be used. Two pre-defined 462 + ioctls are used to disconnect and reconnect kernel drivers, so that 463 + user mode code can completely manage binding and configuration of 464 + devices. 465 + 466 + USBDEVFS_RELEASEINTERFACE 467 + This is used to release the claim usbfs made on interface, either 468 + implicitly or because of a USBDEVFS_CLAIMINTERFACE call, before the 469 + file descriptor is closed. The ioctl parameter is an integer holding 470 + the number of the interface (bInterfaceNumber from descriptor); File 471 + modification time is not updated by this request. 472 + 473 + .. warning:: 474 + 475 + *No security check is made to ensure that the task which made 476 + the claim is the one which is releasing it. This means that user 477 + mode driver may interfere other ones.* 478 + 479 + USBDEVFS_RESETEP 480 + Resets the data toggle value for an endpoint (bulk or interrupt) to 481 + DATA0. The ioctl parameter is an integer endpoint number (1 to 15, 482 + as identified in the endpoint descriptor), with USB_DIR_IN added 483 + if the device's endpoint sends data to the host. 484 + 485 + .. Warning:: 486 + 487 + *Avoid using this request. It should probably be removed.* Using 488 + it typically means the device and driver will lose toggle 489 + synchronization. If you really lost synchronization, you likely 490 + need to completely handshake with the device, using a request 491 + like CLEAR_HALT or SET_INTERFACE. 492 + 493 + USBDEVFS_DROP_PRIVILEGES 494 + This is used to relinquish the ability to do certain operations 495 + which are considered to be privileged on a usbfs file descriptor. 496 + This includes claiming arbitrary interfaces, resetting a device on 497 + which there are currently claimed interfaces from other users, and 498 + issuing USBDEVFS_IOCTL calls. The ioctl parameter is a 32 bit mask 499 + of interfaces the user is allowed to claim on this file descriptor. 500 + You may issue this ioctl more than one time to narrow said mask. 501 + 502 + Synchronous I/O Support 503 + ~~~~~~~~~~~~~~~~~~~~~~~ 504 + 505 + Synchronous requests involve the kernel blocking until the user mode 506 + request completes, either by finishing successfully or by reporting an 507 + error. In most cases this is the simplest way to use usbfs, although as 508 + noted above it does prevent performing I/O to more than one endpoint at 509 + a time. 510 + 511 + USBDEVFS_BULK 512 + Issues a bulk read or write request to the device. The ioctl 513 + parameter is a pointer to this structure:: 514 + 515 + struct usbdevfs_bulktransfer { 516 + unsigned int ep; 517 + unsigned int len; 518 + unsigned int timeout; /* in milliseconds */ 519 + void *data; 520 + }; 521 + 522 + The ``ep`` value identifies a bulk endpoint number (1 to 15, as 523 + identified in an endpoint descriptor), masked with USB_DIR_IN when 524 + referring to an endpoint which sends data to the host from the 525 + device. The length of the data buffer is identified by ``len``; Recent 526 + kernels support requests up to about 128KBytes. *FIXME say how read 527 + length is returned, and how short reads are handled.*. 528 + 529 + USBDEVFS_CLEAR_HALT 530 + Clears endpoint halt (stall) and resets the endpoint toggle. This is 531 + only meaningful for bulk or interrupt endpoints. The ioctl parameter 532 + is an integer endpoint number (1 to 15, as identified in an endpoint 533 + descriptor), masked with USB_DIR_IN when referring to an endpoint 534 + which sends data to the host from the device. 535 + 536 + Use this on bulk or interrupt endpoints which have stalled, 537 + returning ``-EPIPE`` status to a data transfer request. Do not issue 538 + the control request directly, since that could invalidate the host's 539 + record of the data toggle. 540 + 541 + USBDEVFS_CONTROL 542 + Issues a control request to the device. The ioctl parameter points 543 + to a structure like this:: 544 + 545 + struct usbdevfs_ctrltransfer { 546 + __u8 bRequestType; 547 + __u8 bRequest; 548 + __u16 wValue; 549 + __u16 wIndex; 550 + __u16 wLength; 551 + __u32 timeout; /* in milliseconds */ 552 + void *data; 553 + }; 554 + 555 + The first eight bytes of this structure are the contents of the 556 + SETUP packet to be sent to the device; see the USB 2.0 specification 557 + for details. The bRequestType value is composed by combining a 558 + ``USB_TYPE_*`` value, a ``USB_DIR_*`` value, and a ``USB_RECIP_*`` 559 + value (from ``linux/usb.h``). If wLength is nonzero, it describes 560 + the length of the data buffer, which is either written to the device 561 + (USB_DIR_OUT) or read from the device (USB_DIR_IN). 562 + 563 + At this writing, you can't transfer more than 4 KBytes of data to or 564 + from a device; usbfs has a limit, and some host controller drivers 565 + have a limit. (That's not usually a problem.) *Also* there's no way 566 + to say it's not OK to get a short read back from the device. 567 + 568 + USBDEVFS_RESET 569 + Does a USB level device reset. The ioctl parameter is ignored. After 570 + the reset, this rebinds all device interfaces. File modification 571 + time is not updated by this request. 572 + 573 + .. warning:: 574 + 575 + *Avoid using this call* until some usbcore bugs get fixed, since 576 + it does not fully synchronize device, interface, and driver (not 577 + just usbfs) state. 578 + 579 + USBDEVFS_SETINTERFACE 580 + Sets the alternate setting for an interface. The ioctl parameter is 581 + a pointer to a structure like this:: 582 + 583 + struct usbdevfs_setinterface { 584 + unsigned int interface; 585 + unsigned int altsetting; 586 + }; 587 + 588 + File modification time is not updated by this request. 589 + 590 + Those struct members are from some interface descriptor applying to 591 + the current configuration. The interface number is the 592 + bInterfaceNumber value, and the altsetting number is the 593 + bAlternateSetting value. (This resets each endpoint in the 594 + interface.) 595 + 596 + USBDEVFS_SETCONFIGURATION 597 + Issues the :c:func:`usb_set_configuration()` call for the 598 + device. The parameter is an integer holding the number of a 599 + configuration (bConfigurationValue from descriptor). File 600 + modification time is not updated by this request. 601 + 602 + .. warning:: 603 + 604 + *Avoid using this call* until some usbcore bugs get fixed, since 605 + it does not fully synchronize device, interface, and driver (not 606 + just usbfs) state. 607 + 608 + Asynchronous I/O Support 609 + ~~~~~~~~~~~~~~~~~~~~~~~~ 610 + 611 + As mentioned above, there are situations where it may be important to 612 + initiate concurrent operations from user mode code. This is particularly 613 + important for periodic transfers (interrupt and isochronous), but it can 614 + be used for other kinds of USB requests too. In such cases, the 615 + asynchronous requests described here are essential. Rather than 616 + submitting one request and having the kernel block until it completes, 617 + the blocking is separate. 618 + 619 + These requests are packaged into a structure that resembles the URB used 620 + by kernel device drivers. (No POSIX Async I/O support here, sorry.) It 621 + identifies the endpoint type (``USBDEVFS_URB_TYPE_*``), endpoint 622 + (number, masked with USB_DIR_IN as appropriate), buffer and length, 623 + and a user "context" value serving to uniquely identify each request. 624 + (It's usually a pointer to per-request data.) Flags can modify requests 625 + (not as many as supported for kernel drivers). 626 + 627 + Each request can specify a realtime signal number (between SIGRTMIN and 628 + SIGRTMAX, inclusive) to request a signal be sent when the request 629 + completes. 630 + 631 + When usbfs returns these urbs, the status value is updated, and the 632 + buffer may have been modified. Except for isochronous transfers, the 633 + actual_length is updated to say how many bytes were transferred; if the 634 + USBDEVFS_URB_DISABLE_SPD flag is set ("short packets are not OK"), if 635 + fewer bytes were read than were requested then you get an error report:: 636 + 637 + struct usbdevfs_iso_packet_desc { 638 + unsigned int length; 639 + unsigned int actual_length; 640 + unsigned int status; 641 + }; 642 + 643 + struct usbdevfs_urb { 644 + unsigned char type; 645 + unsigned char endpoint; 646 + int status; 647 + unsigned int flags; 648 + void *buffer; 649 + int buffer_length; 650 + int actual_length; 651 + int start_frame; 652 + int number_of_packets; 653 + int error_count; 654 + unsigned int signr; 655 + void *usercontext; 656 + struct usbdevfs_iso_packet_desc iso_frame_desc[]; 657 + }; 658 + 659 + For these asynchronous requests, the file modification time reflects 660 + when the request was initiated. This contrasts with their use with the 661 + synchronous requests, where it reflects when requests complete. 662 + 663 + USBDEVFS_DISCARDURB 664 + *TBS* File modification time is not updated by this request. 665 + 666 + USBDEVFS_DISCSIGNAL 667 + *TBS* File modification time is not updated by this request. 668 + 669 + USBDEVFS_REAPURB 670 + *TBS* File modification time is not updated by this request. 671 + 672 + USBDEVFS_REAPURBNDELAY 673 + *TBS* File modification time is not updated by this request. 674 + 675 + USBDEVFS_SUBMITURB 676 + *TBS* 677 + 678 + The USB devices 679 + =============== 680 + 681 + The USB devices are now exported via debugfs: 682 + 683 + - ``/sys/kernel/debug/usb/devices`` ... a text file showing each of the USB 684 + devices on known to the kernel, and their configuration descriptors. 685 + You can also poll() this to learn about new devices. 686 + 687 + /sys/kernel/debug/usb/devices 688 + ----------------------------- 689 + 690 + This file is handy for status viewing tools in user mode, which can scan 691 + the text format and ignore most of it. More detailed device status 692 + (including class and vendor status) is available from device-specific 693 + files. For information about the current format of this file, see the 694 + ``Documentation/usb/proc_usb_info.txt`` file in your Linux kernel 695 + sources. 696 + 697 + This file, in combination with the poll() system call, can also be used 698 + to detect when devices are added or removed:: 699 + 700 + int fd; 701 + struct pollfd pfd; 702 + 703 + fd = open("/sys/kernel/debug/usb/devices", O_RDONLY); 704 + pfd = { fd, POLLIN, 0 }; 705 + for (;;) { 706 + /* The first time through, this call will return immediately. */ 707 + poll(&pfd, 1, -1); 708 + 709 + /* To see what's changed, compare the file's previous and current 710 + contents or scan the filesystem. (Scanning is more precise.) */ 711 + } 712 + 713 + Note that this behavior is intended to be used for informational and 714 + debug purposes. It would be more appropriate to use programs such as 715 + udev or HAL to initialize a device or start a user-mode helper program, 716 + for instance. 717 + 718 + In this file, each device's output has multiple lines of ASCII output. 719 + 720 + I made it ASCII instead of binary on purpose, so that someone 721 + can obtain some useful data from it without the use of an 722 + auxiliary program. However, with an auxiliary program, the numbers 723 + in the first 4 columns of each ``T:`` line (topology info: 724 + Lev, Prnt, Port, Cnt) can be used to build a USB topology diagram. 725 + 726 + Each line is tagged with a one-character ID for that line:: 727 + 728 + T = Topology (etc.) 729 + B = Bandwidth (applies only to USB host controllers, which are 730 + virtualized as root hubs) 731 + D = Device descriptor info. 732 + P = Product ID info. (from Device descriptor, but they won't fit 733 + together on one line) 734 + S = String descriptors. 735 + C = Configuration descriptor info. (* = active configuration) 736 + I = Interface descriptor info. 737 + E = Endpoint descriptor info. 738 + 739 + /sys/kernel/debug/usb/devices output format 740 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 741 + 742 + Legend:: 743 + d = decimal number (may have leading spaces or 0's) 744 + x = hexadecimal number (may have leading spaces or 0's) 745 + s = string 746 + 747 + 748 + 749 + Topology info 750 + ^^^^^^^^^^^^^ 751 + 752 + :: 753 + 754 + T: Bus=dd Lev=dd Prnt=dd Port=dd Cnt=dd Dev#=ddd Spd=dddd MxCh=dd 755 + | | | | | | | | |__MaxChildren 756 + | | | | | | | |__Device Speed in Mbps 757 + | | | | | | |__DeviceNumber 758 + | | | | | |__Count of devices at this level 759 + | | | | |__Connector/Port on Parent for this device 760 + | | | |__Parent DeviceNumber 761 + | | |__Level in topology for this bus 762 + | |__Bus number 763 + |__Topology info tag 764 + 765 + Speed may be: 766 + 767 + ======= ====================================================== 768 + 1.5 Mbit/s for low speed USB 769 + 12 Mbit/s for full speed USB 770 + 480 Mbit/s for high speed USB (added for USB 2.0); 771 + also used for Wireless USB, which has no fixed speed 772 + 5000 Mbit/s for SuperSpeed USB (added for USB 3.0) 773 + ======= ====================================================== 774 + 775 + For reasons lost in the mists of time, the Port number is always 776 + too low by 1. For example, a device plugged into port 4 will 777 + show up with ``Port=03``. 778 + 779 + Bandwidth info 780 + ^^^^^^^^^^^^^^ 781 + 782 + :: 783 + 784 + B: Alloc=ddd/ddd us (xx%), #Int=ddd, #Iso=ddd 785 + | | | |__Number of isochronous requests 786 + | | |__Number of interrupt requests 787 + | |__Total Bandwidth allocated to this bus 788 + |__Bandwidth info tag 789 + 790 + Bandwidth allocation is an approximation of how much of one frame 791 + (millisecond) is in use. It reflects only periodic transfers, which 792 + are the only transfers that reserve bandwidth. Control and bulk 793 + transfers use all other bandwidth, including reserved bandwidth that 794 + is not used for transfers (such as for short packets). 795 + 796 + The percentage is how much of the "reserved" bandwidth is scheduled by 797 + those transfers. For a low or full speed bus (loosely, "USB 1.1"), 798 + 90% of the bus bandwidth is reserved. For a high speed bus (loosely, 799 + "USB 2.0") 80% is reserved. 800 + 801 + 802 + Device descriptor info & Product ID info 803 + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 804 + 805 + :: 806 + 807 + D: Ver=x.xx Cls=xx(s) Sub=xx Prot=xx MxPS=dd #Cfgs=dd 808 + P: Vendor=xxxx ProdID=xxxx Rev=xx.xx 809 + 810 + where:: 811 + 812 + D: Ver=x.xx Cls=xx(sssss) Sub=xx Prot=xx MxPS=dd #Cfgs=dd 813 + | | | | | | |__NumberConfigurations 814 + | | | | | |__MaxPacketSize of Default Endpoint 815 + | | | | |__DeviceProtocol 816 + | | | |__DeviceSubClass 817 + | | |__DeviceClass 818 + | |__Device USB version 819 + |__Device info tag #1 820 + 821 + where:: 822 + 823 + P: Vendor=xxxx ProdID=xxxx Rev=xx.xx 824 + | | | |__Product revision number 825 + | | |__Product ID code 826 + | |__Vendor ID code 827 + |__Device info tag #2 828 + 829 + 830 + String descriptor info 831 + ^^^^^^^^^^^^^^^^^^^^^^ 832 + :: 833 + 834 + S: Manufacturer=ssss 835 + | |__Manufacturer of this device as read from the device. 836 + | For USB host controller drivers (virtual root hubs) this may 837 + | be omitted, or (for newer drivers) will identify the kernel 838 + | version and the driver which provides this hub emulation. 839 + |__String info tag 840 + 841 + S: Product=ssss 842 + | |__Product description of this device as read from the device. 843 + | For older USB host controller drivers (virtual root hubs) this 844 + | indicates the driver; for newer ones, it's a product (and vendor) 845 + | description that often comes from the kernel's PCI ID database. 846 + |__String info tag 847 + 848 + S: SerialNumber=ssss 849 + | |__Serial Number of this device as read from the device. 850 + | For USB host controller drivers (virtual root hubs) this is 851 + | some unique ID, normally a bus ID (address or slot name) that 852 + | can't be shared with any other device. 853 + |__String info tag 854 + 855 + 856 + 857 + Configuration descriptor info 858 + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 859 + :: 860 + 861 + C:* #Ifs=dd Cfg#=dd Atr=xx MPwr=dddmA 862 + | | | | | |__MaxPower in mA 863 + | | | | |__Attributes 864 + | | | |__ConfiguratioNumber 865 + | | |__NumberOfInterfaces 866 + | |__ "*" indicates the active configuration (others are " ") 867 + |__Config info tag 868 + 869 + USB devices may have multiple configurations, each of which act 870 + rather differently. For example, a bus-powered configuration 871 + might be much less capable than one that is self-powered. Only 872 + one device configuration can be active at a time; most devices 873 + have only one configuration. 874 + 875 + Each configuration consists of one or more interfaces. Each 876 + interface serves a distinct "function", which is typically bound 877 + to a different USB device driver. One common example is a USB 878 + speaker with an audio interface for playback, and a HID interface 879 + for use with software volume control. 880 + 881 + Interface descriptor info (can be multiple per Config) 882 + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 883 + :: 884 + 885 + I:* If#=dd Alt=dd #EPs=dd Cls=xx(sssss) Sub=xx Prot=xx Driver=ssss 886 + | | | | | | | | |__Driver name 887 + | | | | | | | | or "(none)" 888 + | | | | | | | |__InterfaceProtocol 889 + | | | | | | |__InterfaceSubClass 890 + | | | | | |__InterfaceClass 891 + | | | | |__NumberOfEndpoints 892 + | | | |__AlternateSettingNumber 893 + | | |__InterfaceNumber 894 + | |__ "*" indicates the active altsetting (others are " ") 895 + |__Interface info tag 896 + 897 + A given interface may have one or more "alternate" settings. 898 + For example, default settings may not use more than a small 899 + amount of periodic bandwidth. To use significant fractions 900 + of bus bandwidth, drivers must select a non-default altsetting. 901 + 902 + Only one setting for an interface may be active at a time, and 903 + only one driver may bind to an interface at a time. Most devices 904 + have only one alternate setting per interface. 905 + 906 + 907 + Endpoint descriptor info (can be multiple per Interface) 908 + ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 909 + 910 + :: 911 + 912 + E: Ad=xx(s) Atr=xx(ssss) MxPS=dddd Ivl=dddss 913 + | | | | |__Interval (max) between transfers 914 + | | | |__EndpointMaxPacketSize 915 + | | |__Attributes(EndpointType) 916 + | |__EndpointAddress(I=In,O=Out) 917 + |__Endpoint info tag 918 + 919 + The interval is nonzero for all periodic (interrupt or isochronous) 920 + endpoints. For high speed endpoints the transfer interval may be 921 + measured in microseconds rather than milliseconds. 922 + 923 + For high speed periodic endpoints, the ``EndpointMaxPacketSize`` reflects 924 + the per-microframe data transfer size. For "high bandwidth" 925 + endpoints, that can reflect two or three packets (for up to 926 + 3KBytes every 125 usec) per endpoint. 927 + 928 + With the Linux-USB stack, periodic bandwidth reservations use the 929 + transfer intervals and sizes provided by URBs, which can be less 930 + than those found in endpoint descriptor. 931 + 932 + Usage examples 933 + ~~~~~~~~~~~~~~ 934 + 935 + If a user or script is interested only in Topology info, for 936 + example, use something like ``grep ^T: /sys/kernel/debug/usb/devices`` 937 + for only the Topology lines. A command like 938 + ``grep -i ^[tdp]: /sys/kernel/debug/usb/devices`` can be used to list 939 + only the lines that begin with the characters in square brackets, 940 + where the valid characters are TDPCIE. With a slightly more able 941 + script, it can display any selected lines (for example, only T, D, 942 + and P lines) and change their output format. (The ``procusb`` 943 + Perl script is the beginning of this idea. It will list only 944 + selected lines [selected from TBDPSCIE] or "All" lines from 945 + ``/sys/kernel/debug/usb/devices``.) 946 + 947 + The Topology lines can be used to generate a graphic/pictorial 948 + of the USB devices on a system's root hub. (See more below 949 + on how to do this.) 950 + 951 + The Interface lines can be used to determine what driver is 952 + being used for each device, and which altsetting it activated. 953 + 954 + The Configuration lines could be used to list maximum power 955 + (in milliamps) that a system's USB devices are using. 956 + For example, ``grep ^C: /sys/kernel/debug/usb/devices``. 957 + 958 + 959 + Here's an example, from a system which has a UHCI root hub, 960 + an external hub connected to the root hub, and a mouse and 961 + a serial converter connected to the external hub. 962 + 963 + :: 964 + 965 + T: Bus=00 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#= 1 Spd=12 MxCh= 2 966 + B: Alloc= 28/900 us ( 3%), #Int= 2, #Iso= 0 967 + D: Ver= 1.00 Cls=09(hub ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1 968 + P: Vendor=0000 ProdID=0000 Rev= 0.00 969 + S: Product=USB UHCI Root Hub 970 + S: SerialNumber=dce0 971 + C:* #Ifs= 1 Cfg#= 1 Atr=40 MxPwr= 0mA 972 + I: If#= 0 Alt= 0 #EPs= 1 Cls=09(hub ) Sub=00 Prot=00 Driver=hub 973 + E: Ad=81(I) Atr=03(Int.) MxPS= 8 Ivl=255ms 974 + 975 + T: Bus=00 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#= 2 Spd=12 MxCh= 4 976 + D: Ver= 1.00 Cls=09(hub ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1 977 + P: Vendor=0451 ProdID=1446 Rev= 1.00 978 + C:* #Ifs= 1 Cfg#= 1 Atr=e0 MxPwr=100mA 979 + I: If#= 0 Alt= 0 #EPs= 1 Cls=09(hub ) Sub=00 Prot=00 Driver=hub 980 + E: Ad=81(I) Atr=03(Int.) MxPS= 1 Ivl=255ms 981 + 982 + T: Bus=00 Lev=02 Prnt=02 Port=00 Cnt=01 Dev#= 3 Spd=1.5 MxCh= 0 983 + D: Ver= 1.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1 984 + P: Vendor=04b4 ProdID=0001 Rev= 0.00 985 + C:* #Ifs= 1 Cfg#= 1 Atr=80 MxPwr=100mA 986 + I: If#= 0 Alt= 0 #EPs= 1 Cls=03(HID ) Sub=01 Prot=02 Driver=mouse 987 + E: Ad=81(I) Atr=03(Int.) MxPS= 3 Ivl= 10ms 988 + 989 + T: Bus=00 Lev=02 Prnt=02 Port=02 Cnt=02 Dev#= 4 Spd=12 MxCh= 0 990 + D: Ver= 1.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1 991 + P: Vendor=0565 ProdID=0001 Rev= 1.08 992 + S: Manufacturer=Peracom Networks, Inc. 993 + S: Product=Peracom USB to Serial Converter 994 + C:* #Ifs= 1 Cfg#= 1 Atr=a0 MxPwr=100mA 995 + I: If#= 0 Alt= 0 #EPs= 3 Cls=00(>ifc ) Sub=00 Prot=00 Driver=serial 996 + E: Ad=81(I) Atr=02(Bulk) MxPS= 64 Ivl= 16ms 997 + E: Ad=01(O) Atr=02(Bulk) MxPS= 16 Ivl= 16ms 998 + E: Ad=82(I) Atr=03(Int.) MxPS= 8 Ivl= 8ms 999 + 1000 + 1001 + Selecting only the ``T:`` and ``I:`` lines from this (for example, by using 1002 + ``procusb ti``), we have 1003 + 1004 + :: 1005 + 1006 + T: Bus=00 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#= 1 Spd=12 MxCh= 2 1007 + T: Bus=00 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#= 2 Spd=12 MxCh= 4 1008 + I: If#= 0 Alt= 0 #EPs= 1 Cls=09(hub ) Sub=00 Prot=00 Driver=hub 1009 + T: Bus=00 Lev=02 Prnt=02 Port=00 Cnt=01 Dev#= 3 Spd=1.5 MxCh= 0 1010 + I: If#= 0 Alt= 0 #EPs= 1 Cls=03(HID ) Sub=01 Prot=02 Driver=mouse 1011 + T: Bus=00 Lev=02 Prnt=02 Port=02 Cnt=02 Dev#= 4 Spd=12 MxCh= 0 1012 + I: If#= 0 Alt= 0 #EPs= 3 Cls=00(>ifc ) Sub=00 Prot=00 Driver=serial 1013 + 1014 + 1015 + Physically this looks like (or could be converted to):: 1016 + 1017 + +------------------+ 1018 + | PC/root_hub (12)| Dev# = 1 1019 + +------------------+ (nn) is Mbps. 1020 + Level 0 | CN.0 | CN.1 | [CN = connector/port #] 1021 + +------------------+ 1022 + / 1023 + / 1024 + +-----------------------+ 1025 + Level 1 | Dev#2: 4-port hub (12)| 1026 + +-----------------------+ 1027 + |CN.0 |CN.1 |CN.2 |CN.3 | 1028 + +-----------------------+ 1029 + \ \____________________ 1030 + \_____ \ 1031 + \ \ 1032 + +--------------------+ +--------------------+ 1033 + Level 2 | Dev# 3: mouse (1.5)| | Dev# 4: serial (12)| 1034 + +--------------------+ +--------------------+ 1035 + 1036 + 1037 + 1038 + Or, in a more tree-like structure (ports [Connectors] without 1039 + connections could be omitted):: 1040 + 1041 + PC: Dev# 1, root hub, 2 ports, 12 Mbps 1042 + |_ CN.0: Dev# 2, hub, 4 ports, 12 Mbps 1043 + |_ CN.0: Dev #3, mouse, 1.5 Mbps 1044 + |_ CN.1: 1045 + |_ CN.2: Dev #4, serial, 12 Mbps 1046 + |_ CN.3: 1047 + |_ CN.1:
+723
Documentation/driver-api/usb/writing_musb_glue_layer.rst
··· 1 + ========================= 2 + Writing a MUSB Glue Layer 3 + ========================= 4 + 5 + :Author: Apelete Seketeli 6 + 7 + Introduction 8 + ============ 9 + 10 + The Linux MUSB subsystem is part of the larger Linux USB subsystem. It 11 + provides support for embedded USB Device Controllers (UDC) that do not 12 + use Universal Host Controller Interface (UHCI) or Open Host Controller 13 + Interface (OHCI). 14 + 15 + Instead, these embedded UDC rely on the USB On-the-Go (OTG) 16 + specification which they implement at least partially. The silicon 17 + reference design used in most cases is the Multipoint USB Highspeed 18 + Dual-Role Controller (MUSB HDRC) found in the Mentor Graphics Inventra™ 19 + design. 20 + 21 + As a self-taught exercise I have written an MUSB glue layer for the 22 + Ingenic JZ4740 SoC, modelled after the many MUSB glue layers in the 23 + kernel source tree. This layer can be found at 24 + ``drivers/usb/musb/jz4740.c``. In this documentation I will walk through the 25 + basics of the ``jz4740.c`` glue layer, explaining the different pieces and 26 + what needs to be done in order to write your own device glue layer. 27 + 28 + .. _musb-basics: 29 + 30 + Linux MUSB Basics 31 + ================= 32 + 33 + To get started on the topic, please read USB On-the-Go Basics (see 34 + Resources) which provides an introduction of USB OTG operation at the 35 + hardware level. A couple of wiki pages by Texas Instruments and Analog 36 + Devices also provide an overview of the Linux kernel MUSB configuration, 37 + albeit focused on some specific devices provided by these companies. 38 + Finally, getting acquainted with the USB specification at USB home page 39 + may come in handy, with practical instance provided through the Writing 40 + USB Device Drivers documentation (again, see Resources). 41 + 42 + Linux USB stack is a layered architecture in which the MUSB controller 43 + hardware sits at the lowest. The MUSB controller driver abstract the 44 + MUSB controller hardware to the Linux USB stack:: 45 + 46 + ------------------------ 47 + | | <------- drivers/usb/gadget 48 + | Linux USB Core Stack | <------- drivers/usb/host 49 + | | <------- drivers/usb/core 50 + ------------------------ 51 + 52 + -------------------------- 53 + | | <------ drivers/usb/musb/musb_gadget.c 54 + | MUSB Controller driver | <------ drivers/usb/musb/musb_host.c 55 + | | <------ drivers/usb/musb/musb_core.c 56 + -------------------------- 57 + 58 + --------------------------------- 59 + | MUSB Platform Specific Driver | 60 + | | <-- drivers/usb/musb/jz4740.c 61 + | aka "Glue Layer" | 62 + --------------------------------- 63 + 64 + --------------------------------- 65 + | MUSB Controller Hardware | 66 + --------------------------------- 67 + 68 + As outlined above, the glue layer is actually the platform specific code 69 + sitting in between the controller driver and the controller hardware. 70 + 71 + Just like a Linux USB driver needs to register itself with the Linux USB 72 + subsystem, the MUSB glue layer needs first to register itself with the 73 + MUSB controller driver. This will allow the controller driver to know 74 + about which device the glue layer supports and which functions to call 75 + when a supported device is detected or released; remember we are talking 76 + about an embedded controller chip here, so no insertion or removal at 77 + run-time. 78 + 79 + All of this information is passed to the MUSB controller driver through 80 + a :c:type:`platform_driver` structure defined in the glue layer as:: 81 + 82 + static struct platform_driver jz4740_driver = { 83 + .probe = jz4740_probe, 84 + .remove = jz4740_remove, 85 + .driver = { 86 + .name = "musb-jz4740", 87 + }, 88 + }; 89 + 90 + The probe and remove function pointers are called when a matching device 91 + is detected and, respectively, released. The name string describes the 92 + device supported by this glue layer. In the current case it matches a 93 + platform_device structure declared in ``arch/mips/jz4740/platform.c``. Note 94 + that we are not using device tree bindings here. 95 + 96 + In order to register itself to the controller driver, the glue layer 97 + goes through a few steps, basically allocating the controller hardware 98 + resources and initialising a couple of circuits. To do so, it needs to 99 + keep track of the information used throughout these steps. This is done 100 + by defining a private ``jz4740_glue`` structure:: 101 + 102 + struct jz4740_glue { 103 + struct device *dev; 104 + struct platform_device *musb; 105 + struct clk *clk; 106 + }; 107 + 108 + 109 + The dev and musb members are both device structure variables. The first 110 + one holds generic information about the device, since it's the basic 111 + device structure, and the latter holds information more closely related 112 + to the subsystem the device is registered to. The clk variable keeps 113 + information related to the device clock operation. 114 + 115 + Let's go through the steps of the probe function that leads the glue 116 + layer to register itself to the controller driver. 117 + 118 + .. note:: 119 + 120 + For the sake of readability each function will be split in logical 121 + parts, each part being shown as if it was independent from the others. 122 + 123 + .. code-block:: c 124 + :emphasize-lines: 8,12,18 125 + 126 + static int jz4740_probe(struct platform_device *pdev) 127 + { 128 + struct platform_device *musb; 129 + struct jz4740_glue *glue; 130 + struct clk *clk; 131 + int ret; 132 + 133 + glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL); 134 + if (!glue) 135 + return -ENOMEM; 136 + 137 + musb = platform_device_alloc("musb-hdrc", PLATFORM_DEVID_AUTO); 138 + if (!musb) { 139 + dev_err(&pdev->dev, "failed to allocate musb device\n"); 140 + return -ENOMEM; 141 + } 142 + 143 + clk = devm_clk_get(&pdev->dev, "udc"); 144 + if (IS_ERR(clk)) { 145 + dev_err(&pdev->dev, "failed to get clock\n"); 146 + ret = PTR_ERR(clk); 147 + goto err_platform_device_put; 148 + } 149 + 150 + ret = clk_prepare_enable(clk); 151 + if (ret) { 152 + dev_err(&pdev->dev, "failed to enable clock\n"); 153 + goto err_platform_device_put; 154 + } 155 + 156 + musb->dev.parent = &pdev->dev; 157 + 158 + glue->dev = &pdev->dev; 159 + glue->musb = musb; 160 + glue->clk = clk; 161 + 162 + return 0; 163 + 164 + err_platform_device_put: 165 + platform_device_put(musb); 166 + return ret; 167 + } 168 + 169 + The first few lines of the probe function allocate and assign the glue, 170 + musb and clk variables. The ``GFP_KERNEL`` flag (line 8) allows the 171 + allocation process to sleep and wait for memory, thus being usable in a 172 + locking situation. The ``PLATFORM_DEVID_AUTO`` flag (line 12) allows 173 + automatic allocation and management of device IDs in order to avoid 174 + device namespace collisions with explicit IDs. With :c:func:`devm_clk_get` 175 + (line 18) the glue layer allocates the clock -- the ``devm_`` prefix 176 + indicates that :c:func:`clk_get` is managed: it automatically frees the 177 + allocated clock resource data when the device is released -- and enable 178 + it. 179 + 180 + 181 + 182 + Then comes the registration steps: 183 + 184 + .. code-block:: c 185 + :emphasize-lines: 3,5,7,9,16 186 + 187 + static int jz4740_probe(struct platform_device *pdev) 188 + { 189 + struct musb_hdrc_platform_data *pdata = &jz4740_musb_platform_data; 190 + 191 + pdata->platform_ops = &jz4740_musb_ops; 192 + 193 + platform_set_drvdata(pdev, glue); 194 + 195 + ret = platform_device_add_resources(musb, pdev->resource, 196 + pdev->num_resources); 197 + if (ret) { 198 + dev_err(&pdev->dev, "failed to add resources\n"); 199 + goto err_clk_disable; 200 + } 201 + 202 + ret = platform_device_add_data(musb, pdata, sizeof(*pdata)); 203 + if (ret) { 204 + dev_err(&pdev->dev, "failed to add platform_data\n"); 205 + goto err_clk_disable; 206 + } 207 + 208 + return 0; 209 + 210 + err_clk_disable: 211 + clk_disable_unprepare(clk); 212 + err_platform_device_put: 213 + platform_device_put(musb); 214 + return ret; 215 + } 216 + 217 + The first step is to pass the device data privately held by the glue 218 + layer on to the controller driver through :c:func:`platform_set_drvdata` 219 + (line 7). Next is passing on the device resources information, also privately 220 + held at that point, through :c:func:`platform_device_add_resources` (line 9). 221 + 222 + Finally comes passing on the platform specific data to the controller 223 + driver (line 16). Platform data will be discussed in 224 + :ref:`musb-dev-platform-data`, but here we are looking at the 225 + ``platform_ops`` function pointer (line 5) in ``musb_hdrc_platform_data`` 226 + structure (line 3). This function pointer allows the MUSB controller 227 + driver to know which function to call for device operation:: 228 + 229 + static const struct musb_platform_ops jz4740_musb_ops = { 230 + .init = jz4740_musb_init, 231 + .exit = jz4740_musb_exit, 232 + }; 233 + 234 + Here we have the minimal case where only init and exit functions are 235 + called by the controller driver when needed. Fact is the JZ4740 MUSB 236 + controller is a basic controller, lacking some features found in other 237 + controllers, otherwise we may also have pointers to a few other 238 + functions like a power management function or a function to switch 239 + between OTG and non-OTG modes, for instance. 240 + 241 + At that point of the registration process, the controller driver 242 + actually calls the init function: 243 + 244 + .. code-block:: c 245 + :emphasize-lines: 12,14 246 + 247 + static int jz4740_musb_init(struct musb *musb) 248 + { 249 + musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); 250 + if (!musb->xceiv) { 251 + pr_err("HS UDC: no transceiver configured\n"); 252 + return -ENODEV; 253 + } 254 + 255 + /* Silicon does not implement ConfigData register. 256 + * Set dyn_fifo to avoid reading EP config from hardware. 257 + */ 258 + musb->dyn_fifo = true; 259 + 260 + musb->isr = jz4740_musb_interrupt; 261 + 262 + return 0; 263 + } 264 + 265 + The goal of ``jz4740_musb_init()`` is to get hold of the transceiver 266 + driver data of the MUSB controller hardware and pass it on to the MUSB 267 + controller driver, as usual. The transceiver is the circuitry inside the 268 + controller hardware responsible for sending/receiving the USB data. 269 + Since it is an implementation of the physical layer of the OSI model, 270 + the transceiver is also referred to as PHY. 271 + 272 + Getting hold of the ``MUSB PHY`` driver data is done with ``usb_get_phy()`` 273 + which returns a pointer to the structure containing the driver instance 274 + data. The next couple of instructions (line 12 and 14) are used as a 275 + quirk and to setup IRQ handling respectively. Quirks and IRQ handling 276 + will be discussed later in :ref:`musb-dev-quirks` and 277 + :ref:`musb-handling-irqs`\ :: 278 + 279 + static int jz4740_musb_exit(struct musb *musb) 280 + { 281 + usb_put_phy(musb->xceiv); 282 + 283 + return 0; 284 + } 285 + 286 + Acting as the counterpart of init, the exit function releases the MUSB 287 + PHY driver when the controller hardware itself is about to be released. 288 + 289 + Again, note that init and exit are fairly simple in this case due to the 290 + basic set of features of the JZ4740 controller hardware. When writing an 291 + musb glue layer for a more complex controller hardware, you might need 292 + to take care of more processing in those two functions. 293 + 294 + Returning from the init function, the MUSB controller driver jumps back 295 + into the probe function:: 296 + 297 + static int jz4740_probe(struct platform_device *pdev) 298 + { 299 + ret = platform_device_add(musb); 300 + if (ret) { 301 + dev_err(&pdev->dev, "failed to register musb device\n"); 302 + goto err_clk_disable; 303 + } 304 + 305 + return 0; 306 + 307 + err_clk_disable: 308 + clk_disable_unprepare(clk); 309 + err_platform_device_put: 310 + platform_device_put(musb); 311 + return ret; 312 + } 313 + 314 + This is the last part of the device registration process where the glue 315 + layer adds the controller hardware device to Linux kernel device 316 + hierarchy: at this stage, all known information about the device is 317 + passed on to the Linux USB core stack: 318 + 319 + .. code-block:: c 320 + :emphasize-lines: 5,6 321 + 322 + static int jz4740_remove(struct platform_device *pdev) 323 + { 324 + struct jz4740_glue *glue = platform_get_drvdata(pdev); 325 + 326 + platform_device_unregister(glue->musb); 327 + clk_disable_unprepare(glue->clk); 328 + 329 + return 0; 330 + } 331 + 332 + Acting as the counterpart of probe, the remove function unregister the 333 + MUSB controller hardware (line 5) and disable the clock (line 6), 334 + allowing it to be gated. 335 + 336 + .. _musb-handling-irqs: 337 + 338 + Handling IRQs 339 + ============= 340 + 341 + Additionally to the MUSB controller hardware basic setup and 342 + registration, the glue layer is also responsible for handling the IRQs: 343 + 344 + .. code-block:: c 345 + :emphasize-lines: 7,9-11,14,24 346 + 347 + static irqreturn_t jz4740_musb_interrupt(int irq, void *__hci) 348 + { 349 + unsigned long flags; 350 + irqreturn_t retval = IRQ_NONE; 351 + struct musb *musb = __hci; 352 + 353 + spin_lock_irqsave(&musb->lock, flags); 354 + 355 + musb->int_usb = musb_readb(musb->mregs, MUSB_INTRUSB); 356 + musb->int_tx = musb_readw(musb->mregs, MUSB_INTRTX); 357 + musb->int_rx = musb_readw(musb->mregs, MUSB_INTRRX); 358 + 359 + /* 360 + * The controller is gadget only, the state of the host mode IRQ bits is 361 + * undefined. Mask them to make sure that the musb driver core will 362 + * never see them set 363 + */ 364 + musb->int_usb &= MUSB_INTR_SUSPEND | MUSB_INTR_RESUME | 365 + MUSB_INTR_RESET | MUSB_INTR_SOF; 366 + 367 + if (musb->int_usb || musb->int_tx || musb->int_rx) 368 + retval = musb_interrupt(musb); 369 + 370 + spin_unlock_irqrestore(&musb->lock, flags); 371 + 372 + return retval; 373 + } 374 + 375 + Here the glue layer mostly has to read the relevant hardware registers 376 + and pass their values on to the controller driver which will handle the 377 + actual event that triggered the IRQ. 378 + 379 + The interrupt handler critical section is protected by the 380 + :c:func:`spin_lock_irqsave` and counterpart :c:func:`spin_unlock_irqrestore` 381 + functions (line 7 and 24 respectively), which prevent the interrupt 382 + handler code to be run by two different threads at the same time. 383 + 384 + Then the relevant interrupt registers are read (line 9 to 11): 385 + 386 + - ``MUSB_INTRUSB``: indicates which USB interrupts are currently active, 387 + 388 + - ``MUSB_INTRTX``: indicates which of the interrupts for TX endpoints are 389 + currently active, 390 + 391 + - ``MUSB_INTRRX``: indicates which of the interrupts for TX endpoints are 392 + currently active. 393 + 394 + Note that :c:func:`musb_readb` is used to read 8-bit registers at most, while 395 + :c:func:`musb_readw` allows us to read at most 16-bit registers. There are 396 + other functions that can be used depending on the size of your device 397 + registers. See ``musb_io.h`` for more information. 398 + 399 + Instruction on line 18 is another quirk specific to the JZ4740 USB 400 + device controller, which will be discussed later in :ref:`musb-dev-quirks`. 401 + 402 + The glue layer still needs to register the IRQ handler though. Remember 403 + the instruction on line 14 of the init function:: 404 + 405 + static int jz4740_musb_init(struct musb *musb) 406 + { 407 + musb->isr = jz4740_musb_interrupt; 408 + 409 + return 0; 410 + } 411 + 412 + This instruction sets a pointer to the glue layer IRQ handler function, 413 + in order for the controller hardware to call the handler back when an 414 + IRQ comes from the controller hardware. The interrupt handler is now 415 + implemented and registered. 416 + 417 + .. _musb-dev-platform-data: 418 + 419 + Device Platform Data 420 + ==================== 421 + 422 + In order to write an MUSB glue layer, you need to have some data 423 + describing the hardware capabilities of your controller hardware, which 424 + is called the platform data. 425 + 426 + Platform data is specific to your hardware, though it may cover a broad 427 + range of devices, and is generally found somewhere in the ``arch/`` 428 + directory, depending on your device architecture. 429 + 430 + For instance, platform data for the JZ4740 SoC is found in 431 + ``arch/mips/jz4740/platform.c``. In the ``platform.c`` file each device of the 432 + JZ4740 SoC is described through a set of structures. 433 + 434 + Here is the part of ``arch/mips/jz4740/platform.c`` that covers the USB 435 + Device Controller (UDC): 436 + 437 + .. code-block:: c 438 + :emphasize-lines: 2,7,14-17,21,22,25,26,28,29 439 + 440 + /* USB Device Controller */ 441 + struct platform_device jz4740_udc_xceiv_device = { 442 + .name = "usb_phy_gen_xceiv", 443 + .id = 0, 444 + }; 445 + 446 + static struct resource jz4740_udc_resources[] = { 447 + [0] = { 448 + .start = JZ4740_UDC_BASE_ADDR, 449 + .end = JZ4740_UDC_BASE_ADDR + 0x10000 - 1, 450 + .flags = IORESOURCE_MEM, 451 + }, 452 + [1] = { 453 + .start = JZ4740_IRQ_UDC, 454 + .end = JZ4740_IRQ_UDC, 455 + .flags = IORESOURCE_IRQ, 456 + .name = "mc", 457 + }, 458 + }; 459 + 460 + struct platform_device jz4740_udc_device = { 461 + .name = "musb-jz4740", 462 + .id = -1, 463 + .dev = { 464 + .dma_mask = &jz4740_udc_device.dev.coherent_dma_mask, 465 + .coherent_dma_mask = DMA_BIT_MASK(32), 466 + }, 467 + .num_resources = ARRAY_SIZE(jz4740_udc_resources), 468 + .resource = jz4740_udc_resources, 469 + }; 470 + 471 + The ``jz4740_udc_xceiv_device`` platform device structure (line 2) 472 + describes the UDC transceiver with a name and id number. 473 + 474 + At the time of this writing, note that ``usb_phy_gen_xceiv`` is the 475 + specific name to be used for all transceivers that are either built-in 476 + with reference USB IP or autonomous and doesn't require any PHY 477 + programming. You will need to set ``CONFIG_NOP_USB_XCEIV=y`` in the 478 + kernel configuration to make use of the corresponding transceiver 479 + driver. The id field could be set to -1 (equivalent to 480 + ``PLATFORM_DEVID_NONE``), -2 (equivalent to ``PLATFORM_DEVID_AUTO``) or 481 + start with 0 for the first device of this kind if we want a specific id 482 + number. 483 + 484 + The ``jz4740_udc_resources`` resource structure (line 7) defines the UDC 485 + registers base addresses. 486 + 487 + The first array (line 9 to 11) defines the UDC registers base memory 488 + addresses: start points to the first register memory address, end points 489 + to the last register memory address and the flags member defines the 490 + type of resource we are dealing with. So ``IORESOURCE_MEM`` is used to 491 + define the registers memory addresses. The second array (line 14 to 17) 492 + defines the UDC IRQ registers addresses. Since there is only one IRQ 493 + register available for the JZ4740 UDC, start and end point at the same 494 + address. The ``IORESOURCE_IRQ`` flag tells that we are dealing with IRQ 495 + resources, and the name ``mc`` is in fact hard-coded in the MUSB core in 496 + order for the controller driver to retrieve this IRQ resource by 497 + querying it by its name. 498 + 499 + Finally, the ``jz4740_udc_device`` platform device structure (line 21) 500 + describes the UDC itself. 501 + 502 + The ``musb-jz4740`` name (line 22) defines the MUSB driver that is used 503 + for this device; remember this is in fact the name that we used in the 504 + ``jz4740_driver`` platform driver structure in :ref:`musb-basics`. 505 + The id field (line 23) is set to -1 (equivalent to ``PLATFORM_DEVID_NONE``) 506 + since we do not need an id for the device: the MUSB controller driver was 507 + already set to allocate an automatic id in :ref:`musb-basics`. In the dev field 508 + we care for DMA related information here. The ``dma_mask`` field (line 25) 509 + defines the width of the DMA mask that is going to be used, and 510 + ``coherent_dma_mask`` (line 26) has the same purpose but for the 511 + ``alloc_coherent`` DMA mappings: in both cases we are using a 32 bits mask. 512 + Then the resource field (line 29) is simply a pointer to the resource 513 + structure defined before, while the ``num_resources`` field (line 28) keeps 514 + track of the number of arrays defined in the resource structure (in this 515 + case there were two resource arrays defined before). 516 + 517 + With this quick overview of the UDC platform data at the ``arch/`` level now 518 + done, let's get back to the MUSB glue layer specific platform data in 519 + ``drivers/usb/musb/jz4740.c``: 520 + 521 + .. code-block:: c 522 + :emphasize-lines: 3,5,7-9,11 523 + 524 + static struct musb_hdrc_config jz4740_musb_config = { 525 + /* Silicon does not implement USB OTG. */ 526 + .multipoint = 0, 527 + /* Max EPs scanned, driver will decide which EP can be used. */ 528 + .num_eps = 4, 529 + /* RAMbits needed to configure EPs from table */ 530 + .ram_bits = 9, 531 + .fifo_cfg = jz4740_musb_fifo_cfg, 532 + .fifo_cfg_size = ARRAY_SIZE(jz4740_musb_fifo_cfg), 533 + }; 534 + 535 + static struct musb_hdrc_platform_data jz4740_musb_platform_data = { 536 + .mode = MUSB_PERIPHERAL, 537 + .config = &jz4740_musb_config, 538 + }; 539 + 540 + First the glue layer configures some aspects of the controller driver 541 + operation related to the controller hardware specifics. This is done 542 + through the ``jz4740_musb_config`` :c:type:`musb_hdrc_config` structure. 543 + 544 + Defining the OTG capability of the controller hardware, the multipoint 545 + member (line 3) is set to 0 (equivalent to false) since the JZ4740 UDC 546 + is not OTG compatible. Then ``num_eps`` (line 5) defines the number of USB 547 + endpoints of the controller hardware, including endpoint 0: here we have 548 + 3 endpoints + endpoint 0. Next is ``ram_bits`` (line 7) which is the width 549 + of the RAM address bus for the MUSB controller hardware. This 550 + information is needed when the controller driver cannot automatically 551 + configure endpoints by reading the relevant controller hardware 552 + registers. This issue will be discussed when we get to device quirks in 553 + :ref:`musb-dev-quirks`. Last two fields (line 8 and 9) are also 554 + about device quirks: ``fifo_cfg`` points to the USB endpoints configuration 555 + table and ``fifo_cfg_size`` keeps track of the size of the number of 556 + entries in that configuration table. More on that later in 557 + :ref:`musb-dev-quirks`. 558 + 559 + Then this configuration is embedded inside ``jz4740_musb_platform_data`` 560 + :c:type:`musb_hdrc_platform_data` structure (line 11): config is a pointer to 561 + the configuration structure itself, and mode tells the controller driver 562 + if the controller hardware may be used as ``MUSB_HOST`` only, 563 + ``MUSB_PERIPHERAL`` only or ``MUSB_OTG`` which is a dual mode. 564 + 565 + Remember that ``jz4740_musb_platform_data`` is then used to convey 566 + platform data information as we have seen in the probe function in 567 + :ref:`musb-basics`. 568 + 569 + .. _musb-dev-quirks: 570 + 571 + Device Quirks 572 + ============= 573 + 574 + Completing the platform data specific to your device, you may also need 575 + to write some code in the glue layer to work around some device specific 576 + limitations. These quirks may be due to some hardware bugs, or simply be 577 + the result of an incomplete implementation of the USB On-the-Go 578 + specification. 579 + 580 + The JZ4740 UDC exhibits such quirks, some of which we will discuss here 581 + for the sake of insight even though these might not be found in the 582 + controller hardware you are working on. 583 + 584 + Let's get back to the init function first: 585 + 586 + .. code-block:: c 587 + :emphasize-lines: 12 588 + 589 + static int jz4740_musb_init(struct musb *musb) 590 + { 591 + musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2); 592 + if (!musb->xceiv) { 593 + pr_err("HS UDC: no transceiver configured\n"); 594 + return -ENODEV; 595 + } 596 + 597 + /* Silicon does not implement ConfigData register. 598 + * Set dyn_fifo to avoid reading EP config from hardware. 599 + */ 600 + musb->dyn_fifo = true; 601 + 602 + musb->isr = jz4740_musb_interrupt; 603 + 604 + return 0; 605 + } 606 + 607 + Instruction on line 12 helps the MUSB controller driver to work around 608 + the fact that the controller hardware is missing registers that are used 609 + for USB endpoints configuration. 610 + 611 + Without these registers, the controller driver is unable to read the 612 + endpoints configuration from the hardware, so we use line 12 instruction 613 + to bypass reading the configuration from silicon, and rely on a 614 + hard-coded table that describes the endpoints configuration instead:: 615 + 616 + static struct musb_fifo_cfg jz4740_musb_fifo_cfg[] = { 617 + { .hw_ep_num = 1, .style = FIFO_TX, .maxpacket = 512, }, 618 + { .hw_ep_num = 1, .style = FIFO_RX, .maxpacket = 512, }, 619 + { .hw_ep_num = 2, .style = FIFO_TX, .maxpacket = 64, }, 620 + }; 621 + 622 + Looking at the configuration table above, we see that each endpoints is 623 + described by three fields: ``hw_ep_num`` is the endpoint number, style is 624 + its direction (either ``FIFO_TX`` for the controller driver to send packets 625 + in the controller hardware, or ``FIFO_RX`` to receive packets from 626 + hardware), and maxpacket defines the maximum size of each data packet 627 + that can be transmitted over that endpoint. Reading from the table, the 628 + controller driver knows that endpoint 1 can be used to send and receive 629 + USB data packets of 512 bytes at once (this is in fact a bulk in/out 630 + endpoint), and endpoint 2 can be used to send data packets of 64 bytes 631 + at once (this is in fact an interrupt endpoint). 632 + 633 + Note that there is no information about endpoint 0 here: that one is 634 + implemented by default in every silicon design, with a predefined 635 + configuration according to the USB specification. For more examples of 636 + endpoint configuration tables, see ``musb_core.c``. 637 + 638 + Let's now get back to the interrupt handler function: 639 + 640 + .. code-block:: c 641 + :emphasize-lines: 18-19 642 + 643 + static irqreturn_t jz4740_musb_interrupt(int irq, void *__hci) 644 + { 645 + unsigned long flags; 646 + irqreturn_t retval = IRQ_NONE; 647 + struct musb *musb = __hci; 648 + 649 + spin_lock_irqsave(&musb->lock, flags); 650 + 651 + musb->int_usb = musb_readb(musb->mregs, MUSB_INTRUSB); 652 + musb->int_tx = musb_readw(musb->mregs, MUSB_INTRTX); 653 + musb->int_rx = musb_readw(musb->mregs, MUSB_INTRRX); 654 + 655 + /* 656 + * The controller is gadget only, the state of the host mode IRQ bits is 657 + * undefined. Mask them to make sure that the musb driver core will 658 + * never see them set 659 + */ 660 + musb->int_usb &= MUSB_INTR_SUSPEND | MUSB_INTR_RESUME | 661 + MUSB_INTR_RESET | MUSB_INTR_SOF; 662 + 663 + if (musb->int_usb || musb->int_tx || musb->int_rx) 664 + retval = musb_interrupt(musb); 665 + 666 + spin_unlock_irqrestore(&musb->lock, flags); 667 + 668 + return retval; 669 + } 670 + 671 + Instruction on line 18 above is a way for the controller driver to work 672 + around the fact that some interrupt bits used for USB host mode 673 + operation are missing in the ``MUSB_INTRUSB`` register, thus left in an 674 + undefined hardware state, since this MUSB controller hardware is used in 675 + peripheral mode only. As a consequence, the glue layer masks these 676 + missing bits out to avoid parasite interrupts by doing a logical AND 677 + operation between the value read from ``MUSB_INTRUSB`` and the bits that 678 + are actually implemented in the register. 679 + 680 + These are only a couple of the quirks found in the JZ4740 USB device 681 + controller. Some others were directly addressed in the MUSB core since 682 + the fixes were generic enough to provide a better handling of the issues 683 + for others controller hardware eventually. 684 + 685 + Conclusion 686 + ========== 687 + 688 + Writing a Linux MUSB glue layer should be a more accessible task, as 689 + this documentation tries to show the ins and outs of this exercise. 690 + 691 + The JZ4740 USB device controller being fairly simple, I hope its glue 692 + layer serves as a good example for the curious mind. Used with the 693 + current MUSB glue layers, this documentation should provide enough 694 + guidance to get started; should anything gets out of hand, the linux-usb 695 + mailing list archive is another helpful resource to browse through. 696 + 697 + Acknowledgements 698 + ================ 699 + 700 + Many thanks to Lars-Peter Clausen and Maarten ter Huurne for answering 701 + my questions while I was writing the JZ4740 glue layer and for helping 702 + me out getting the code in good shape. 703 + 704 + I would also like to thank the Qi-Hardware community at large for its 705 + cheerful guidance and support. 706 + 707 + Resources 708 + ========= 709 + 710 + USB Home Page: http://www.usb.org 711 + 712 + linux-usb Mailing List Archives: http://marc.info/?l=linux-usb 713 + 714 + USB On-the-Go Basics: 715 + http://www.maximintegrated.com/app-notes/index.mvp/id/1822 716 + 717 + :ref:`Writing USB Device Drivers <writing-usb-driver>` 718 + 719 + Texas Instruments USB Configuration Wiki Page: 720 + http://processors.wiki.ti.com/index.php/Usbgeneralpage 721 + 722 + Analog Devices Blackfin MUSB Configuration: 723 + http://docs.blackfin.uclinux.org/doku.php?id=linux-kernel:drivers:musb
+326
Documentation/driver-api/usb/writing_usb_driver.rst
··· 1 + .. _writing-usb-driver: 2 + 3 + ========================== 4 + Writing USB Device Drivers 5 + ========================== 6 + 7 + :Author: Greg Kroah-Hartman 8 + 9 + Introduction 10 + ============ 11 + 12 + The Linux USB subsystem has grown from supporting only two different 13 + types of devices in the 2.2.7 kernel (mice and keyboards), to over 20 14 + different types of devices in the 2.4 kernel. Linux currently supports 15 + almost all USB class devices (standard types of devices like keyboards, 16 + mice, modems, printers and speakers) and an ever-growing number of 17 + vendor-specific devices (such as USB to serial converters, digital 18 + cameras, Ethernet devices and MP3 players). For a full list of the 19 + different USB devices currently supported, see Resources. 20 + 21 + The remaining kinds of USB devices that do not have support on Linux are 22 + almost all vendor-specific devices. Each vendor decides to implement a 23 + custom protocol to talk to their device, so a custom driver usually 24 + needs to be created. Some vendors are open with their USB protocols and 25 + help with the creation of Linux drivers, while others do not publish 26 + them, and developers are forced to reverse-engineer. See Resources for 27 + some links to handy reverse-engineering tools. 28 + 29 + Because each different protocol causes a new driver to be created, I 30 + have written a generic USB driver skeleton, modelled after the 31 + pci-skeleton.c file in the kernel source tree upon which many PCI 32 + network drivers have been based. This USB skeleton can be found at 33 + drivers/usb/usb-skeleton.c in the kernel source tree. In this article I 34 + will walk through the basics of the skeleton driver, explaining the 35 + different pieces and what needs to be done to customize it to your 36 + specific device. 37 + 38 + Linux USB Basics 39 + ================ 40 + 41 + If you are going to write a Linux USB driver, please become familiar 42 + with the USB protocol specification. It can be found, along with many 43 + other useful documents, at the USB home page (see Resources). An 44 + excellent introduction to the Linux USB subsystem can be found at the 45 + USB Working Devices List (see Resources). It explains how the Linux USB 46 + subsystem is structured and introduces the reader to the concept of USB 47 + urbs (USB Request Blocks), which are essential to USB drivers. 48 + 49 + The first thing a Linux USB driver needs to do is register itself with 50 + the Linux USB subsystem, giving it some information about which devices 51 + the driver supports and which functions to call when a device supported 52 + by the driver is inserted or removed from the system. All of this 53 + information is passed to the USB subsystem in the :c:type:`usb_driver` 54 + structure. The skeleton driver declares a :c:type:`usb_driver` as:: 55 + 56 + static struct usb_driver skel_driver = { 57 + .name = "skeleton", 58 + .probe = skel_probe, 59 + .disconnect = skel_disconnect, 60 + .fops = &skel_fops, 61 + .minor = USB_SKEL_MINOR_BASE, 62 + .id_table = skel_table, 63 + }; 64 + 65 + 66 + The variable name is a string that describes the driver. It is used in 67 + informational messages printed to the system log. The probe and 68 + disconnect function pointers are called when a device that matches the 69 + information provided in the ``id_table`` variable is either seen or 70 + removed. 71 + 72 + The fops and minor variables are optional. Most USB drivers hook into 73 + another kernel subsystem, such as the SCSI, network or TTY subsystem. 74 + These types of drivers register themselves with the other kernel 75 + subsystem, and any user-space interactions are provided through that 76 + interface. But for drivers that do not have a matching kernel subsystem, 77 + such as MP3 players or scanners, a method of interacting with user space 78 + is needed. The USB subsystem provides a way to register a minor device 79 + number and a set of :c:type:`file_operations` function pointers that enable 80 + this user-space interaction. The skeleton driver needs this kind of 81 + interface, so it provides a minor starting number and a pointer to its 82 + :c:type:`file_operations` functions. 83 + 84 + The USB driver is then registered with a call to :c:func:`usb_register`, 85 + usually in the driver's init function, as shown here:: 86 + 87 + static int __init usb_skel_init(void) 88 + { 89 + int result; 90 + 91 + /* register this driver with the USB subsystem */ 92 + result = usb_register(&skel_driver); 93 + if (result < 0) { 94 + err("usb_register failed for the "__FILE__ "driver." 95 + "Error number %d", result); 96 + return -1; 97 + } 98 + 99 + return 0; 100 + } 101 + module_init(usb_skel_init); 102 + 103 + 104 + When the driver is unloaded from the system, it needs to deregister 105 + itself with the USB subsystem. This is done with the :c:func:`usb_deregister` 106 + function:: 107 + 108 + static void __exit usb_skel_exit(void) 109 + { 110 + /* deregister this driver with the USB subsystem */ 111 + usb_deregister(&skel_driver); 112 + } 113 + module_exit(usb_skel_exit); 114 + 115 + 116 + To enable the linux-hotplug system to load the driver automatically when 117 + the device is plugged in, you need to create a ``MODULE_DEVICE_TABLE``. 118 + The following code tells the hotplug scripts that this module supports a 119 + single device with a specific vendor and product ID:: 120 + 121 + /* table of devices that work with this driver */ 122 + static struct usb_device_id skel_table [] = { 123 + { USB_DEVICE(USB_SKEL_VENDOR_ID, USB_SKEL_PRODUCT_ID) }, 124 + { } /* Terminating entry */ 125 + }; 126 + MODULE_DEVICE_TABLE (usb, skel_table); 127 + 128 + 129 + There are other macros that can be used in describing a struct 130 + :c:type:`usb_device_id` for drivers that support a whole class of USB 131 + drivers. See :ref:`usb.h <usb_header>` for more information on this. 132 + 133 + Device operation 134 + ================ 135 + 136 + When a device is plugged into the USB bus that matches the device ID 137 + pattern that your driver registered with the USB core, the probe 138 + function is called. The :c:type:`usb_device` structure, interface number and 139 + the interface ID are passed to the function:: 140 + 141 + static int skel_probe(struct usb_interface *interface, 142 + const struct usb_device_id *id) 143 + 144 + 145 + The driver now needs to verify that this device is actually one that it 146 + can accept. If so, it returns 0. If not, or if any error occurs during 147 + initialization, an errorcode (such as ``-ENOMEM`` or ``-ENODEV``) is 148 + returned from the probe function. 149 + 150 + In the skeleton driver, we determine what end points are marked as 151 + bulk-in and bulk-out. We create buffers to hold the data that will be 152 + sent and received from the device, and a USB urb to write data to the 153 + device is initialized. 154 + 155 + Conversely, when the device is removed from the USB bus, the disconnect 156 + function is called with the device pointer. The driver needs to clean 157 + any private data that has been allocated at this time and to shut down 158 + any pending urbs that are in the USB system. 159 + 160 + Now that the device is plugged into the system and the driver is bound 161 + to the device, any of the functions in the :c:type:`file_operations` structure 162 + that were passed to the USB subsystem will be called from a user program 163 + trying to talk to the device. The first function called will be open, as 164 + the program tries to open the device for I/O. We increment our private 165 + usage count and save a pointer to our internal structure in the file 166 + structure. This is done so that future calls to file operations will 167 + enable the driver to determine which device the user is addressing. All 168 + of this is done with the following code:: 169 + 170 + /* increment our usage count for the module */ 171 + ++skel->open_count; 172 + 173 + /* save our object in the file's private structure */ 174 + file->private_data = dev; 175 + 176 + 177 + After the open function is called, the read and write functions are 178 + called to receive and send data to the device. In the ``skel_write`` 179 + function, we receive a pointer to some data that the user wants to send 180 + to the device and the size of the data. The function determines how much 181 + data it can send to the device based on the size of the write urb it has 182 + created (this size depends on the size of the bulk out end point that 183 + the device has). Then it copies the data from user space to kernel 184 + space, points the urb to the data and submits the urb to the USB 185 + subsystem. This can be seen in the following code:: 186 + 187 + /* we can only write as much as 1 urb will hold */ 188 + bytes_written = (count > skel->bulk_out_size) ? skel->bulk_out_size : count; 189 + 190 + /* copy the data from user space into our urb */ 191 + copy_from_user(skel->write_urb->transfer_buffer, buffer, bytes_written); 192 + 193 + /* set up our urb */ 194 + usb_fill_bulk_urb(skel->write_urb, 195 + skel->dev, 196 + usb_sndbulkpipe(skel->dev, skel->bulk_out_endpointAddr), 197 + skel->write_urb->transfer_buffer, 198 + bytes_written, 199 + skel_write_bulk_callback, 200 + skel); 201 + 202 + /* send the data out the bulk port */ 203 + result = usb_submit_urb(skel->write_urb); 204 + if (result) { 205 + err("Failed submitting write urb, error %d", result); 206 + } 207 + 208 + 209 + When the write urb is filled up with the proper information using the 210 + :c:func:`usb_fill_bulk_urb` function, we point the urb's completion callback 211 + to call our own ``skel_write_bulk_callback`` function. This function is 212 + called when the urb is finished by the USB subsystem. The callback 213 + function is called in interrupt context, so caution must be taken not to 214 + do very much processing at that time. Our implementation of 215 + ``skel_write_bulk_callback`` merely reports if the urb was completed 216 + successfully or not and then returns. 217 + 218 + The read function works a bit differently from the write function in 219 + that we do not use an urb to transfer data from the device to the 220 + driver. Instead we call the :c:func:`usb_bulk_msg` function, which can be used 221 + to send or receive data from a device without having to create urbs and 222 + handle urb completion callback functions. We call the :c:func:`usb_bulk_msg` 223 + function, giving it a buffer into which to place any data received from 224 + the device and a timeout value. If the timeout period expires without 225 + receiving any data from the device, the function will fail and return an 226 + error message. This can be shown with the following code:: 227 + 228 + /* do an immediate bulk read to get data from the device */ 229 + retval = usb_bulk_msg (skel->dev, 230 + usb_rcvbulkpipe (skel->dev, 231 + skel->bulk_in_endpointAddr), 232 + skel->bulk_in_buffer, 233 + skel->bulk_in_size, 234 + &count, HZ*10); 235 + /* if the read was successful, copy the data to user space */ 236 + if (!retval) { 237 + if (copy_to_user (buffer, skel->bulk_in_buffer, count)) 238 + retval = -EFAULT; 239 + else 240 + retval = count; 241 + } 242 + 243 + 244 + The :c:func:`usb_bulk_msg` function can be very useful for doing single reads 245 + or writes to a device; however, if you need to read or write constantly to 246 + a device, it is recommended to set up your own urbs and submit them to 247 + the USB subsystem. 248 + 249 + When the user program releases the file handle that it has been using to 250 + talk to the device, the release function in the driver is called. In 251 + this function we decrement our private usage count and wait for possible 252 + pending writes:: 253 + 254 + /* decrement our usage count for the device */ 255 + --skel->open_count; 256 + 257 + 258 + One of the more difficult problems that USB drivers must be able to 259 + handle smoothly is the fact that the USB device may be removed from the 260 + system at any point in time, even if a program is currently talking to 261 + it. It needs to be able to shut down any current reads and writes and 262 + notify the user-space programs that the device is no longer there. The 263 + following code (function ``skel_delete``) is an example of how to do 264 + this:: 265 + 266 + static inline void skel_delete (struct usb_skel *dev) 267 + { 268 + kfree (dev->bulk_in_buffer); 269 + if (dev->bulk_out_buffer != NULL) 270 + usb_free_coherent (dev->udev, dev->bulk_out_size, 271 + dev->bulk_out_buffer, 272 + dev->write_urb->transfer_dma); 273 + usb_free_urb (dev->write_urb); 274 + kfree (dev); 275 + } 276 + 277 + 278 + If a program currently has an open handle to the device, we reset the 279 + flag ``device_present``. For every read, write, release and other 280 + functions that expect a device to be present, the driver first checks 281 + this flag to see if the device is still present. If not, it releases 282 + that the device has disappeared, and a ``-ENODEV`` error is returned to the 283 + user-space program. When the release function is eventually called, it 284 + determines if there is no device and if not, it does the cleanup that 285 + the ``skel_disconnect`` function normally does if there are no open files 286 + on the device (see Listing 5). 287 + 288 + Isochronous Data 289 + ================ 290 + 291 + This usb-skeleton driver does not have any examples of interrupt or 292 + isochronous data being sent to or from the device. Interrupt data is 293 + sent almost exactly as bulk data is, with a few minor exceptions. 294 + Isochronous data works differently with continuous streams of data being 295 + sent to or from the device. The audio and video camera drivers are very 296 + good examples of drivers that handle isochronous data and will be useful 297 + if you also need to do this. 298 + 299 + Conclusion 300 + ========== 301 + 302 + Writing Linux USB device drivers is not a difficult task as the 303 + usb-skeleton driver shows. This driver, combined with the other current 304 + USB drivers, should provide enough examples to help a beginning author 305 + create a working driver in a minimal amount of time. The linux-usb-devel 306 + mailing list archives also contain a lot of helpful information. 307 + 308 + Resources 309 + ========= 310 + 311 + The Linux USB Project: 312 + http://www.linux-usb.org/ 313 + 314 + Linux Hotplug Project: 315 + http://linux-hotplug.sourceforge.net/ 316 + 317 + Linux USB Working Devices List: 318 + http://www.qbik.ch/usb/devices/ 319 + 320 + linux-usb-devel Mailing List Archives: 321 + http://marc.theaimsgroup.com/?l=linux-usb-devel 322 + 323 + Programming Guide for Linux USB Device Drivers: 324 + http://usb.cs.tum.edu/usbdoc 325 + 326 + USB Home Page: http://www.usb.org
+1 -1
Documentation/early-userspace/README
··· 86 86 maintained separately from the kernel. 87 87 88 88 You can obtain somewhat infrequent snapshots of klibc from 89 - ftp://ftp.kernel.org/pub/linux/libs/klibc/ 89 + https://www.kernel.org/pub/linux/libs/klibc/ 90 90 91 91 For active users, you are better off using the klibc git 92 92 repository, at http://git.kernel.org/?p=libs/klibc/klibc.git
+1 -1
Documentation/filesystems/ext4.txt
··· 25 25 26 26 or 27 27 28 - ftp://ftp.kernel.org/pub/linux/kernel/people/tytso/e2fsprogs/ 28 + https://www.kernel.org/pub/linux/kernel/people/tytso/e2fsprogs/ 29 29 30 30 or grab the latest git repository from: 31 31
+2 -2
Documentation/filesystems/nfs/nfs-rdma.txt
··· 110 110 - Install a Linux kernel with NFS/RDMA 111 111 112 112 The NFS/RDMA client and server are both included in the mainline Linux 113 - kernel version 2.6.25 and later. This and other versions of the 2.6 Linux 113 + kernel version 2.6.25 and later. This and other versions of the Linux 114 114 kernel can be found at: 115 115 116 - ftp://ftp.kernel.org/pub/linux/kernel/v2.6/ 116 + https://www.kernel.org/pub/linux/kernel/ 117 117 118 118 Download the sources and place them in an appropriate location. 119 119
+1 -1
Documentation/hid/hidraw.txt
··· 81 81 BUS_HIL 82 82 BUS_BLUETOOTH 83 83 BUS_VIRTUAL 84 - which are defined in linux/input.h. 84 + which are defined in uapi/linux/input.h. 85 85 86 86 HIDIOCGRAWNAME(len): Get Raw Name 87 87 This ioctl returns a string containing the vendor and product strings of
+20
Documentation/index.rst
··· 24 24 25 25 admin-guide/index 26 26 27 + Application-developer documentation 28 + ----------------------------------- 29 + 30 + The user-space API manual gathers together documents describing aspects of 31 + the kernel interface as seen by application developers. 32 + 33 + .. toctree:: 34 + :maxdepth: 2 35 + 36 + userspace-api/index 37 + 38 + 27 39 Introduction to kernel development 28 40 ---------------------------------- 29 41 ··· 87 75 :maxdepth: 1 88 76 89 77 translations/zh_CN/index 78 + 79 + Japanese translations 80 + --------------------- 81 + 82 + .. toctree:: 83 + :maxdepth: 1 84 + 85 + translations/ja_JP/index 90 86 91 87 Indices and tables 92 88 ==================
+3 -3
Documentation/input/ff.txt
··· 106 106 107 107 Effects are file descriptor specific. 108 108 109 - See <linux/input.h> for a description of the ff_effect struct. You should also 110 - find help in a few sketches, contained in files shape.fig and interactive.fig. 111 - You need xfig to visualize these files. 109 + See <uapi/linux/input.h> for a description of the ff_effect struct. You should 110 + also find help in a few sketches, contained in files shape.fig and 111 + interactive.fig. You need xfig to visualize these files. 112 112 113 113 3.3 Removing an effect from the device 114 114 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+2 -2
Documentation/input/input-programming.txt
··· 174 174 175 175 input_report_key(struct input_dev *dev, int code, int value) 176 176 177 - See linux/input.h for the allowable values of code (from 0 to KEY_MAX). 178 - Value is interpreted as a truth value, ie any nonzero value means key 177 + See uapi/linux/input-event-codes.h for the allowable values of code (from 0 to 178 + KEY_MAX). Value is interpreted as a truth value, ie any nonzero value means key 179 179 pressed, zero value means key released. The input code generates events only 180 180 in case the value is different from before. 181 181
+1 -1
Documentation/ioctl/ioctl-number.txt
··· 212 212 'c' 00-1F linux/chio.h conflict! 213 213 'c' 80-9F arch/s390/include/asm/chsc.h conflict! 214 214 'c' A0-AF arch/x86/include/asm/msr.h conflict! 215 - 'd' 00-FF linux/char/drm/drm/h conflict! 215 + 'd' 00-FF linux/char/drm/drm.h conflict! 216 216 'd' 02-40 pcmcia/ds.h conflict! 217 217 'd' F0-FF linux/digi1.h 218 218 'e' all linux/digi1.h conflict!
+1 -1
Documentation/leds/leds-lp55xx.txt
··· 117 117 Inside the callback, the selected engine is loaded and memory is updated. 118 118 To run programmed pattern, 'run_engine' attribute should be enabled. 119 119 120 - The pattern sqeuence of LP8501 is similar to LP5523. 120 + The pattern sequence of LP8501 is similar to LP5523. 121 121 However pattern data is specific. 122 122 Ex 1) Engine 1 is used 123 123 echo 1 > /sys/bus/i2c/devices/xxxx/select_engine
+1 -1
Documentation/md/md-cluster.txt
··· 77 77 3.1.2 RESYNCING: informs other nodes that a resync is initiated or 78 78 ended so that each node may suspend or resume the region. Each 79 79 RESYNCING message identifies a range of the devices that the 80 - sending node is about to resync. This over-rides any pervious 80 + sending node is about to resync. This overrides any previous 81 81 notification from that node: only one ranged can be resynced at a 82 82 time per-node. 83 83
+1 -46
Documentation/media/Makefile
··· 1 - # Rules to convert DOT and SVG to Sphinx images 2 - 3 - SRC_DIR=$(srctree)/Documentation/media 4 - 5 - DOTS = \ 6 - uapi/v4l/pipeline.dot \ 7 - 8 - IMAGES = \ 9 - typical_media_device.svg \ 10 - uapi/dvb/dvbstb.svg \ 11 - uapi/v4l/bayer.svg \ 12 - uapi/v4l/constraints.svg \ 13 - uapi/v4l/crop.svg \ 14 - uapi/v4l/fieldseq_bt.svg \ 15 - uapi/v4l/fieldseq_tb.svg \ 16 - uapi/v4l/nv12mt.svg \ 17 - uapi/v4l/nv12mt_example.svg \ 18 - uapi/v4l/pipeline.svg \ 19 - uapi/v4l/selection.svg \ 20 - uapi/v4l/subdev-image-processing-full.svg \ 21 - uapi/v4l/subdev-image-processing-scaling-multi-source.svg \ 22 - uapi/v4l/subdev-image-processing-crop.svg \ 23 - uapi/v4l/vbi_525.svg \ 24 - uapi/v4l/vbi_625.svg \ 25 - uapi/v4l/vbi_hsync.svg \ 26 - 27 - DOTTGT := $(patsubst %.dot,%.svg,$(DOTS)) 28 - IMGDOT := $(patsubst %,$(SRC_DIR)/%,$(DOTTGT)) 29 - 30 - IMGTGT := $(patsubst %.svg,%.pdf,$(IMAGES)) 31 - IMGPDF := $(patsubst %,$(SRC_DIR)/%,$(IMGTGT)) 32 - 33 - cmd = $(echo-cmd) $(cmd_$(1)) 34 - 35 - quiet_cmd_genpdf = GENPDF $2 36 - cmd_genpdf = convert $2 $3 37 - 38 - quiet_cmd_gendot = DOT $2 39 - cmd_gendot = dot -Tsvg $2 > $3 || { rm -f $3; exit 1; } 40 - 41 - %.pdf: %.svg 42 - @$(call cmd,genpdf,$<,$@) 43 - 44 - %.svg: %.dot 45 - @$(call cmd,gendot,$<,$@) 46 - 47 1 # Rules to convert a .h file to inline RST documentation 48 2 3 + SRC_DIR=$(srctree)/Documentation/media 49 4 PARSER = $(srctree)/Documentation/sphinx/parse-headers.pl 50 5 UAPI = $(srctree)/include/uapi/linux 51 6 KAPI = $(srctree)/include/linux
+3 -3
Documentation/media/intro.rst
··· 13 13 14 14 .. _typical_media_device: 15 15 16 - .. figure:: typical_media_device.* 17 - :alt: typical_media_device.pdf / typical_media_device.svg 18 - :align: center 16 + .. kernel-figure:: typical_media_device.svg 17 + :alt: typical_media_device.svg 18 + :align: center 19 19 20 20 Typical Media Device 21 21
+3 -3
Documentation/media/uapi/dvb/intro.rst
··· 55 55 56 56 .. _stb_components: 57 57 58 - .. figure:: dvbstb.* 59 - :alt: dvbstb.pdf / dvbstb.svg 60 - :align: center 58 + .. kernel-figure:: dvbstb.svg 59 + :alt: dvbstb.svg 60 + :align: center 61 61 62 62 Components of a DVB card/STB 63 63
+2 -2
Documentation/media/uapi/v4l/crop.rst
··· 53 53 54 54 .. _crop-scale: 55 55 56 - .. figure:: crop.* 57 - :alt: crop.pdf / crop.svg 56 + .. kernel-figure:: crop.svg 57 + :alt: crop.svg 58 58 :align: center 59 59 60 60 Image Cropping, Insertion and Scaling
+9 -13
Documentation/media/uapi/v4l/dev-raw-vbi.rst
··· 221 221 222 222 .. _vbi-hsync: 223 223 224 - .. figure:: vbi_hsync.* 225 - :alt: vbi_hsync.pdf / vbi_hsync.svg 226 - :align: center 224 + .. kernel-figure:: vbi_hsync.svg 225 + :alt: vbi_hsync.svg 226 + :align: center 227 227 228 228 **Figure 4.1. Line synchronization** 229 229 230 230 231 231 .. _vbi-525: 232 232 233 - .. figure:: vbi_525.* 234 - :alt: vbi_525.pdf / vbi_525.svg 235 - :align: center 233 + .. kernel-figure:: vbi_525.svg 234 + :alt: vbi_525.svg 235 + :align: center 236 236 237 237 **Figure 4.2. ITU-R 525 line numbering (M/NTSC and M/PAL)** 238 238 239 - 240 - 241 239 .. _vbi-625: 242 240 243 - .. figure:: vbi_625.* 244 - :alt: vbi_625.pdf / vbi_625.svg 245 - :align: center 241 + .. kernel-figure:: vbi_625.svg 242 + :alt: vbi_625.svg 243 + :align: center 246 244 247 245 **Figure 4.3. ITU-R 625 line numbering** 248 - 249 - 250 246 251 247 Remember the VBI image format depends on the selected video standard, 252 248 therefore the application must choose a new standard or query the
+11 -11
Documentation/media/uapi/v4l/dev-subdev.rst
··· 99 99 100 100 .. _pipeline-scaling: 101 101 102 - .. figure:: pipeline.* 103 - :alt: pipeline.pdf / pipeline.svg 104 - :align: center 102 + .. kernel-figure:: pipeline.dot 103 + :alt: pipeline.dot 104 + :align: center 105 105 106 106 Image Format Negotiation on Pipelines 107 107 ··· 404 404 405 405 .. _subdev-image-processing-crop: 406 406 407 - .. figure:: subdev-image-processing-crop.* 408 - :alt: subdev-image-processing-crop.pdf / subdev-image-processing-crop.svg 409 - :align: center 407 + .. kernel-figure:: subdev-image-processing-crop.svg 408 + :alt: subdev-image-processing-crop.svg 409 + :align: center 410 410 411 411 **Figure 4.5. Image processing in subdevs: simple crop example** 412 412 ··· 421 421 422 422 .. _subdev-image-processing-scaling-multi-source: 423 423 424 - .. figure:: subdev-image-processing-scaling-multi-source.* 425 - :alt: subdev-image-processing-scaling-multi-source.pdf / subdev-image-processing-scaling-multi-source.svg 426 - :align: center 424 + .. kernel-figure:: subdev-image-processing-scaling-multi-source.svg 425 + :alt: subdev-image-processing-scaling-multi-source.svg 426 + :align: center 427 427 428 428 **Figure 4.6. Image processing in subdevs: scaling with multiple sources** 429 429 ··· 437 437 438 438 .. _subdev-image-processing-full: 439 439 440 - .. figure:: subdev-image-processing-full.* 441 - :alt: subdev-image-processing-full.pdf / subdev-image-processing-full.svg 440 + .. kernel-figure:: subdev-image-processing-full.svg 441 + :alt: subdev-image-processing-full.svg 442 442 :align: center 443 443 444 444 **Figure 4.7. Image processing in subdevs: scaling and composition with multiple sinks and sources**
+7 -4
Documentation/media/uapi/v4l/field-order.rst
··· 141 141 Field Order, Top Field First Transmitted 142 142 ======================================== 143 143 144 - .. figure:: fieldseq_tb.* 145 - :alt: fieldseq_tb.pdf / fieldseq_tb.svg 144 + .. kernel-figure:: fieldseq_tb.svg 145 + :alt: fieldseq_tb.svg 146 146 :align: center 147 + 148 + Field Order, Top Field First Transmitted 147 149 148 150 149 151 .. _fieldseq-bt: ··· 153 151 Field Order, Bottom Field First Transmitted 154 152 =========================================== 155 153 156 - .. figure:: fieldseq_bt.* 157 - :alt: fieldseq_bt.pdf / fieldseq_bt.svg 154 + .. kernel-figure:: fieldseq_bt.svg 155 + :alt: fieldseq_bt.svg 158 156 :align: center 159 157 158 + Field Order, Bottom Field First Transmitted
+4 -4
Documentation/media/uapi/v4l/pixfmt-nv12mt.rst
··· 33 33 34 34 .. _nv12mt: 35 35 36 - .. figure:: nv12mt.* 37 - :alt: nv12mt.pdf / nv12mt.svg 36 + .. kernel-figure:: nv12mt.svg 37 + :alt: nv12mt.svg 38 38 :align: center 39 39 40 40 V4L2_PIX_FMT_NV12MT macroblock Z shape memory layout ··· 50 50 51 51 .. _nv12mt_ex: 52 52 53 - .. figure:: nv12mt_example.* 54 - :alt: nv12mt_example.pdf / nv12mt_example.svg 53 + .. kernel-figure:: nv12mt_example.svg 54 + :alt: nv12mt_example.svg 55 55 :align: center 56 56 57 57 Example V4L2_PIX_FMT_NV12MT memory layout of macroblocks
+3 -3
Documentation/media/uapi/v4l/selection-api-003.rst
··· 7 7 8 8 .. _sel-targets-capture: 9 9 10 - .. figure:: selection.* 11 - :alt: selection.pdf / selection.svg 12 - :align: center 10 + .. kernel-figure:: selection.svg 11 + :alt: selection.svg 12 + :align: center 13 13 14 14 Cropping and composing targets 15 15
+2 -2
Documentation/media/uapi/v4l/subdev-formats.rst
··· 1514 1514 1515 1515 .. _bayer-patterns: 1516 1516 1517 - .. figure:: bayer.* 1518 - :alt: bayer.pdf / bayer.svg 1517 + .. kernel-figure:: bayer.svg 1518 + :alt: bayer.svg 1519 1519 :align: center 1520 1520 1521 1521 **Figure 4.8 Bayer Patterns**
+1
Documentation/media/v4l-drivers/index.rst
··· 45 45 meye 46 46 omap3isp 47 47 omap4_camera 48 + philips 48 49 pvrusb2 49 50 pxa_camera 50 51 radiotrack
+1 -1
Documentation/media/v4l-drivers/zr364xx.rst
··· 30 30 at the source code). 31 31 32 32 You can get these values by looking at /var/log/messages when you plug 33 - your camera, or by typing : cat /proc/bus/usb/devices. 33 + your camera, or by typing : cat /sys/kernel/debug/usb/devices. 34 34 35 35 If you manage to use your cam with this code, you can send me a mail 36 36 (royale@zerezo.com) with the name of your cam and a patch if needed.
+2 -2
Documentation/mmc/mmc-dev-attrs.txt
··· 13 13 14 14 All attributes are read-only. 15 15 16 - cid Card Identifaction Register 16 + cid Card Identification Register 17 17 csd Card Specific Data Register 18 18 scr SD Card Configuration Register (SD only) 19 19 date Manufacturing Date (from CID Register) ··· 71 71 "preferred_erase_size" is in bytes. 72 72 73 73 Note on raw_rpmb_size_mult: 74 - "raw_rpmb_size_mult" is a mutliple of 128kB block. 74 + "raw_rpmb_size_mult" is a multiple of 128kB block. 75 75 RPMB size in byte is calculated by using the following equation: 76 76 RPMB partition size = 128kB x raw_rpmb_size_mult
+1 -1
Documentation/networking/cdc_mbim.txt
··· 332 332 [5] "MBIM (Mobile Broadband Interface Model) Registry" 333 333 - http://compliance.usb.org/mbim/ 334 334 335 - [6] "/proc/bus/usb filesystem output" 335 + [6] "/dev/bus/usb filesystem output" 336 336 - Documentation/usb/proc_usb_info.txt 337 337 338 338 [7] "/sys/bus/usb/devices/.../descriptors"
+1 -1
Documentation/networking/e100.txt
··· 130 130 version 1.6 or later is required for this functionality. 131 131 132 132 The latest release of ethtool can be found from 133 - http://ftp.kernel.org/pub/software/network/ethtool/ 133 + https://www.kernel.org/pub/software/network/ethtool/ 134 134 135 135 Enabling Wake on LAN* (WoL) 136 136 ---------------------------
+1 -1
Documentation/networking/e1000.txt
··· 435 435 version 1.6 or later is required for this functionality. 436 436 437 437 The latest release of ethtool can be found from 438 - http://ftp.kernel.org/pub/software/network/ethtool/ 438 + https://www.kernel.org/pub/software/network/ethtool/ 439 439 440 440 Enabling Wake on LAN* (WoL) 441 441 ---------------------------
+1 -1
Documentation/networking/e1000e.txt
··· 274 274 diagnostics, as well as displaying statistical information. We 275 275 strongly recommend downloading the latest version of ethtool at: 276 276 277 - http://ftp.kernel.org/pub/software/network/ethtool/ 277 + https://kernel.org/pub/software/network/ethtool/ 278 278 279 279 NOTE: When validating enable/disable tests on some parts (82578, for example) 280 280 you need to add a few seconds between tests when working with ethtool.
+1 -1
Documentation/networking/igb.txt
··· 63 63 diagnostics, as well as displaying statistical information. The latest 64 64 version of ethtool can be found at: 65 65 66 - http://ftp.kernel.org/pub/software/network/ethtool/ 66 + https://www.kernel.org/pub/software/network/ethtool/ 67 67 68 68 Enabling Wake on LAN* (WoL) 69 69 ---------------------------
+1 -1
Documentation/networking/igbvf.txt
··· 62 62 version 3.0 or later is required for this functionality, although we 63 63 strongly recommend downloading the latest version at: 64 64 65 - http://ftp.kernel.org/pub/software/network/ethtool/ 65 + https://www.kernel.org/pub/software/network/ethtool/ 66 66 67 67 Support 68 68 =======
+1 -1
Documentation/networking/ixgb.txt
··· 313 313 version 1.6 or later is required for this functionality. 314 314 315 315 The latest release of ethtool can be found from 316 - http://ftp.kernel.org/pub/software/network/ethtool/ 316 + https://www.kernel.org/pub/software/network/ethtool/ 317 317 318 318 NOTE: The ethtool version 1.6 only supports a limited set of ethtool options. 319 319 Support for a more complete ethtool feature set can be enabled by
+1 -1
Documentation/networking/ixgbe.txt
··· 272 272 ethtool version is required for this functionality. 273 273 274 274 The latest release of ethtool can be found from 275 - http://ftp.kernel.org/pub/software/network/ethtool/ 275 + https://www.kernel.org/pub/software/network/ethtool/ 276 276 277 277 FCoE 278 278 ----
+1 -1
Documentation/phy.txt
··· 97 97 non-dt boot, it should contain the label of the PHY. The two 98 98 devm_phy_get associates the device with the PHY using devres on 99 99 successful PHY get. On driver detach, release function is invoked on 100 - the the devres data and devres data is freed. phy_optional_get and 100 + the devres data and devres data is freed. phy_optional_get and 101 101 devm_phy_optional_get should be used when the phy is optional. These 102 102 two functions will never return -ENODEV, but instead returns NULL when 103 103 the phy cannot be found.Some generic drivers, such as ehci, may use multiple
+1 -1
Documentation/power/swsusp.txt
··· 406 406 before suspending; then remount them after resuming. 407 407 408 408 There is a work-around for this problem. For more information, see 409 - Documentation/usb/persist.txt. 409 + Documentation/driver-api/usb/persist.rst. 410 410 411 411 Q: Can I suspend-to-disk using a swap partition under LVM? 412 412
+9 -8
Documentation/process/4.Coding.rst
··· 22 22 ************ 23 23 24 24 The kernel has long had a standard coding style, described in 25 - Documentation/process/coding-style.rst. For much of that time, the policies described 26 - in that file were taken as being, at most, advisory. As a result, there is 27 - a substantial amount of code in the kernel which does not meet the coding 28 - style guidelines. The presence of that code leads to two independent 29 - hazards for kernel developers. 25 + :ref:`Documentation/process/coding-style.rst <codingstyle>`. For much of 26 + that time, the policies described in that file were taken as being, at most, 27 + advisory. As a result, there is a substantial amount of code in the kernel 28 + which does not meet the coding style guidelines. The presence of that code 29 + leads to two independent hazards for kernel developers. 30 30 31 31 The first of these is to believe that the kernel coding standards do not 32 32 matter and are not enforced. The truth of the matter is that adding new ··· 343 343 Documentation/ABI/README for a description of how this documentation should 344 344 be formatted and what information needs to be provided. 345 345 346 - The file Documentation/admin-guide/kernel-parameters.rst describes all of the kernel's 347 - boot-time parameters. Any patch which adds new parameters should add the 348 - appropriate entries to this file. 346 + The file :ref:`Documentation/admin-guide/kernel-parameters.rst 347 + <kernelparameters>` describes all of the kernel's boot-time parameters. 348 + Any patch which adds new parameters should add the appropriate entries to 349 + this file. 349 350 350 351 Any new configuration options must be accompanied by help text which 351 352 clearly explains the options and when the user might want to select them.
+3 -9
Documentation/process/applying-patches.rst
··· 250 250 251 251 The 4.x.y (-stable) and 4.x patches live at 252 252 253 - ftp://ftp.kernel.org/pub/linux/kernel/v4.x/ 253 + https://www.kernel.org/pub/linux/kernel/v4.x/ 254 254 255 255 The -rc patches live at 256 256 257 - ftp://ftp.kernel.org/pub/linux/kernel/v4.x/testing/ 258 - 259 - In place of ``ftp.kernel.org`` you can use ``ftp.cc.kernel.org``, where cc is a 260 - country code. This way you'll be downloading from a mirror site that's most 261 - likely geographically closer to you, resulting in faster downloads for you, 262 - less bandwidth used globally and less load on the main kernel.org servers -- 263 - these are good things, so do use mirrors when possible. 257 + https://www.kernel.org/pub/linux/kernel/v4.x/testing/ 264 258 265 259 266 260 The 4.x kernels ··· 311 317 The -stable team usually do make incremental patches available as well 312 318 as patches against the latest mainline release, but I only cover the 313 319 non-incremental ones below. The incremental ones can be found at 314 - ftp://ftp.kernel.org/pub/linux/kernel/v4.x/incr/ 320 + https://www.kernel.org/pub/linux/kernel/v4.x/incr/ 315 321 316 322 These patches are not incremental, meaning that for example the 4.7.3 317 323 patch does not apply on top of the 4.7.2 kernel source, but rather on top
+9 -8
Documentation/process/changes.rst
··· 318 318 .. note:: 319 319 320 320 Please notice that, for PDF and LaTeX output, you'll also need ``XeLaTeX`` 321 - version 3.14159265. Depending on the distribution, you may also need 322 - to install a series of ``texlive`` packages that provide the minimal 323 - set of functionalities required for ``XeLaTex`` to work. 321 + version 3.14159265. Depending on the distribution, you may also need to 322 + install a series of ``texlive`` packages that provide the minimal set of 323 + functionalities required for ``XeLaTex`` to work. For PDF output you'll also 324 + need ``convert(1)`` from ImageMagick (https://www.imagemagick.org). 324 325 325 326 Other tools 326 327 ----------- ··· 349 348 Binutils 350 349 -------- 351 350 352 - - <ftp://ftp.kernel.org/pub/linux/devel/binutils/> 351 + - <https://www.kernel.org/pub/linux/devel/binutils/> 353 352 354 353 OpenSSL 355 354 ------- ··· 362 361 Util-linux 363 362 ---------- 364 363 365 - - <ftp://ftp.kernel.org/pub/linux/utils/util-linux/> 364 + - <https://www.kernel.org/pub/linux/utils/util-linux/> 366 365 367 366 Ksymoops 368 367 -------- 369 368 370 - - <ftp://ftp.kernel.org/pub/linux/utils/kernel/ksymoops/v2.4/> 369 + - <https://www.kernel.org/pub/linux/utils/kernel/ksymoops/v2.4/> 371 370 372 371 Module-Init-Tools 373 372 ----------------- 374 373 375 - - <ftp://ftp.kernel.org/pub/linux/kernel/people/rusty/modules/> 374 + - <https://www.kernel.org/pub/linux/utils/kernel/module-init-tools/> 376 375 377 376 Mkinitrd 378 377 -------- ··· 402 401 Pcmciautils 403 402 ----------- 404 403 405 - - <ftp://ftp.kernel.org/pub/linux/utils/kernel/pcmcia/> 404 + - <https://www.kernel.org/pub/linux/utils/kernel/pcmcia/> 406 405 407 406 Quota-tools 408 407 -----------
+1 -1
Documentation/sphinx/cdomain.py
··· 44 44 __version__ = '1.0' 45 45 46 46 # Get Sphinx version 47 - major, minor, patch = map(int, sphinx.__version__.split(".")) 47 + major, minor, patch = sphinx.version_info[:3] 48 48 49 49 def setup(app): 50 50
+551
Documentation/sphinx/kfigure.py
··· 1 + # -*- coding: utf-8; mode: python -*- 2 + # pylint: disable=C0103, R0903, R0912, R0915 3 + u""" 4 + scalable figure and image handling 5 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 6 + 7 + Sphinx extension which implements scalable image handling. 8 + 9 + :copyright: Copyright (C) 2016 Markus Heiser 10 + :license: GPL Version 2, June 1991 see Linux/COPYING for details. 11 + 12 + The build for image formats depend on image's source format and output's 13 + destination format. This extension implement methods to simplify image 14 + handling from the author's POV. Directives like ``kernel-figure`` implement 15 + methods *to* always get the best output-format even if some tools are not 16 + installed. For more details take a look at ``convert_image(...)`` which is 17 + the core of all conversions. 18 + 19 + * ``.. kernel-image``: for image handling / a ``.. image::`` replacement 20 + 21 + * ``.. kernel-figure``: for figure handling / a ``.. figure::`` replacement 22 + 23 + * ``.. kernel-render``: for render markup / a concept to embed *render* 24 + markups (or languages). Supported markups (see ``RENDER_MARKUP_EXT``) 25 + 26 + - ``DOT``: render embedded Graphviz's **DOC** 27 + - ``SVG``: render embedded Scalable Vector Graphics (**SVG**) 28 + - ... *developable* 29 + 30 + Used tools: 31 + 32 + * ``dot(1)``: Graphviz (http://www.graphviz.org). If Graphviz is not 33 + available, the DOT language is inserted as literal-block. 34 + 35 + * SVG to PDF: To generate PDF, you need at least one of this tools: 36 + 37 + - ``convert(1)``: ImageMagick (https://www.imagemagick.org) 38 + 39 + List of customizations: 40 + 41 + * generate PDF from SVG / used by PDF (LaTeX) builder 42 + 43 + * generate SVG (html-builder) and PDF (latex-builder) from DOT files. 44 + DOT: see http://www.graphviz.org/content/dot-language 45 + 46 + """ 47 + 48 + import os 49 + from os import path 50 + import subprocess 51 + from hashlib import sha1 52 + import sys 53 + 54 + from docutils import nodes 55 + from docutils.statemachine import ViewList 56 + from docutils.parsers.rst import directives 57 + from docutils.parsers.rst.directives import images 58 + import sphinx 59 + 60 + from sphinx.util.nodes import clean_astext 61 + from six import iteritems 62 + 63 + PY3 = sys.version_info[0] == 3 64 + 65 + if PY3: 66 + _unicode = str 67 + else: 68 + _unicode = unicode 69 + 70 + # Get Sphinx version 71 + major, minor, patch = sphinx.version_info[:3] 72 + if major == 1 and minor > 3: 73 + # patches.Figure only landed in Sphinx 1.4 74 + from sphinx.directives.patches import Figure # pylint: disable=C0413 75 + else: 76 + Figure = images.Figure 77 + 78 + __version__ = '1.0.0' 79 + 80 + # simple helper 81 + # ------------- 82 + 83 + def which(cmd): 84 + """Searches the ``cmd`` in the ``PATH`` enviroment. 85 + 86 + This *which* searches the PATH for executable ``cmd`` . First match is 87 + returned, if nothing is found, ``None` is returned. 88 + """ 89 + envpath = os.environ.get('PATH', None) or os.defpath 90 + for folder in envpath.split(os.pathsep): 91 + fname = folder + os.sep + cmd 92 + if path.isfile(fname): 93 + return fname 94 + 95 + def mkdir(folder, mode=0o775): 96 + if not path.isdir(folder): 97 + os.makedirs(folder, mode) 98 + 99 + def file2literal(fname): 100 + with open(fname, "r") as src: 101 + data = src.read() 102 + node = nodes.literal_block(data, data) 103 + return node 104 + 105 + def isNewer(path1, path2): 106 + """Returns True if ``path1`` is newer than ``path2`` 107 + 108 + If ``path1`` exists and is newer than ``path2`` the function returns 109 + ``True`` is returned otherwise ``False`` 110 + """ 111 + return (path.exists(path1) 112 + and os.stat(path1).st_ctime > os.stat(path2).st_ctime) 113 + 114 + def pass_handle(self, node): # pylint: disable=W0613 115 + pass 116 + 117 + # setup conversion tools and sphinx extension 118 + # ------------------------------------------- 119 + 120 + # Graphviz's dot(1) support 121 + dot_cmd = None 122 + 123 + # ImageMagick' convert(1) support 124 + convert_cmd = None 125 + 126 + 127 + def setup(app): 128 + # check toolchain first 129 + app.connect('builder-inited', setupTools) 130 + 131 + # image handling 132 + app.add_directive("kernel-image", KernelImage) 133 + app.add_node(kernel_image, 134 + html = (visit_kernel_image, pass_handle), 135 + latex = (visit_kernel_image, pass_handle), 136 + texinfo = (visit_kernel_image, pass_handle), 137 + text = (visit_kernel_image, pass_handle), 138 + man = (visit_kernel_image, pass_handle), ) 139 + 140 + # figure handling 141 + app.add_directive("kernel-figure", KernelFigure) 142 + app.add_node(kernel_figure, 143 + html = (visit_kernel_figure, pass_handle), 144 + latex = (visit_kernel_figure, pass_handle), 145 + texinfo = (visit_kernel_figure, pass_handle), 146 + text = (visit_kernel_figure, pass_handle), 147 + man = (visit_kernel_figure, pass_handle), ) 148 + 149 + # render handling 150 + app.add_directive('kernel-render', KernelRender) 151 + app.add_node(kernel_render, 152 + html = (visit_kernel_render, pass_handle), 153 + latex = (visit_kernel_render, pass_handle), 154 + texinfo = (visit_kernel_render, pass_handle), 155 + text = (visit_kernel_render, pass_handle), 156 + man = (visit_kernel_render, pass_handle), ) 157 + 158 + app.connect('doctree-read', add_kernel_figure_to_std_domain) 159 + 160 + return dict( 161 + version = __version__, 162 + parallel_read_safe = True, 163 + parallel_write_safe = True 164 + ) 165 + 166 + 167 + def setupTools(app): 168 + u""" 169 + Check available build tools and log some *verbose* messages. 170 + 171 + This function is called once, when the builder is initiated. 172 + """ 173 + global dot_cmd, convert_cmd # pylint: disable=W0603 174 + app.verbose("kfigure: check installed tools ...") 175 + 176 + dot_cmd = which('dot') 177 + convert_cmd = which('convert') 178 + 179 + if dot_cmd: 180 + app.verbose("use dot(1) from: " + dot_cmd) 181 + else: 182 + app.warn("dot(1) not found, for better output quality install " 183 + "graphviz from http://www.graphviz.org") 184 + if convert_cmd: 185 + app.verbose("use convert(1) from: " + convert_cmd) 186 + else: 187 + app.warn( 188 + "convert(1) not found, for SVG to PDF conversion install " 189 + "ImageMagick (https://www.imagemagick.org)") 190 + 191 + 192 + # integrate conversion tools 193 + # -------------------------- 194 + 195 + RENDER_MARKUP_EXT = { 196 + # The '.ext' must be handled by convert_image(..) function's *in_ext* input. 197 + # <name> : <.ext> 198 + 'DOT' : '.dot', 199 + 'SVG' : '.svg' 200 + } 201 + 202 + def convert_image(img_node, translator, src_fname=None): 203 + """Convert a image node for the builder. 204 + 205 + Different builder prefer different image formats, e.g. *latex* builder 206 + prefer PDF while *html* builder prefer SVG format for images. 207 + 208 + This function handles output image formats in dependence of source the 209 + format (of the image) and the translator's output format. 210 + """ 211 + app = translator.builder.app 212 + 213 + fname, in_ext = path.splitext(path.basename(img_node['uri'])) 214 + if src_fname is None: 215 + src_fname = path.join(translator.builder.srcdir, img_node['uri']) 216 + if not path.exists(src_fname): 217 + src_fname = path.join(translator.builder.outdir, img_node['uri']) 218 + 219 + dst_fname = None 220 + 221 + # in kernel builds, use 'make SPHINXOPTS=-v' to see verbose messages 222 + 223 + app.verbose('assert best format for: ' + img_node['uri']) 224 + 225 + if in_ext == '.dot': 226 + 227 + if not dot_cmd: 228 + app.verbose("dot from graphviz not available / include DOT raw.") 229 + img_node.replace_self(file2literal(src_fname)) 230 + 231 + elif translator.builder.format == 'latex': 232 + dst_fname = path.join(translator.builder.outdir, fname + '.pdf') 233 + img_node['uri'] = fname + '.pdf' 234 + img_node['candidates'] = {'*': fname + '.pdf'} 235 + 236 + 237 + elif translator.builder.format == 'html': 238 + dst_fname = path.join( 239 + translator.builder.outdir, 240 + translator.builder.imagedir, 241 + fname + '.svg') 242 + img_node['uri'] = path.join( 243 + translator.builder.imgpath, fname + '.svg') 244 + img_node['candidates'] = { 245 + '*': path.join(translator.builder.imgpath, fname + '.svg')} 246 + 247 + else: 248 + # all other builder formats will include DOT as raw 249 + img_node.replace_self(file2literal(src_fname)) 250 + 251 + elif in_ext == '.svg': 252 + 253 + if translator.builder.format == 'latex': 254 + if convert_cmd is None: 255 + app.verbose("no SVG to PDF conversion available / include SVG raw.") 256 + img_node.replace_self(file2literal(src_fname)) 257 + else: 258 + dst_fname = path.join(translator.builder.outdir, fname + '.pdf') 259 + img_node['uri'] = fname + '.pdf' 260 + img_node['candidates'] = {'*': fname + '.pdf'} 261 + 262 + if dst_fname: 263 + # the builder needs not to copy one more time, so pop it if exists. 264 + translator.builder.images.pop(img_node['uri'], None) 265 + _name = dst_fname[len(translator.builder.outdir) + 1:] 266 + 267 + if isNewer(dst_fname, src_fname): 268 + app.verbose("convert: {out}/%s already exists and is newer" % _name) 269 + 270 + else: 271 + ok = False 272 + mkdir(path.dirname(dst_fname)) 273 + 274 + if in_ext == '.dot': 275 + app.verbose('convert DOT to: {out}/' + _name) 276 + ok = dot2format(app, src_fname, dst_fname) 277 + 278 + elif in_ext == '.svg': 279 + app.verbose('convert SVG to: {out}/' + _name) 280 + ok = svg2pdf(app, src_fname, dst_fname) 281 + 282 + if not ok: 283 + img_node.replace_self(file2literal(src_fname)) 284 + 285 + 286 + def dot2format(app, dot_fname, out_fname): 287 + """Converts DOT file to ``out_fname`` using ``dot(1)``. 288 + 289 + * ``dot_fname`` pathname of the input DOT file, including extension ``.dot`` 290 + * ``out_fname`` pathname of the output file, including format extension 291 + 292 + The *format extension* depends on the ``dot`` command (see ``man dot`` 293 + option ``-Txxx``). Normally you will use one of the following extensions: 294 + 295 + - ``.ps`` for PostScript, 296 + - ``.svg`` or ``svgz`` for Structured Vector Graphics, 297 + - ``.fig`` for XFIG graphics and 298 + - ``.png`` or ``gif`` for common bitmap graphics. 299 + 300 + """ 301 + out_format = path.splitext(out_fname)[1][1:] 302 + cmd = [dot_cmd, '-T%s' % out_format, dot_fname] 303 + exit_code = 42 304 + 305 + with open(out_fname, "w") as out: 306 + exit_code = subprocess.call(cmd, stdout = out) 307 + if exit_code != 0: 308 + app.warn("Error #%d when calling: %s" % (exit_code, " ".join(cmd))) 309 + return bool(exit_code == 0) 310 + 311 + def svg2pdf(app, svg_fname, pdf_fname): 312 + """Converts SVG to PDF with ``convert(1)`` command. 313 + 314 + Uses ``convert(1)`` from ImageMagick (https://www.imagemagick.org) for 315 + conversion. Returns ``True`` on success and ``False`` if an error occurred. 316 + 317 + * ``svg_fname`` pathname of the input SVG file with extension (``.svg``) 318 + * ``pdf_name`` pathname of the output PDF file with extension (``.pdf``) 319 + 320 + """ 321 + cmd = [convert_cmd, svg_fname, pdf_fname] 322 + # use stdout and stderr from parent 323 + exit_code = subprocess.call(cmd) 324 + if exit_code != 0: 325 + app.warn("Error #%d when calling: %s" % (exit_code, " ".join(cmd))) 326 + return bool(exit_code == 0) 327 + 328 + 329 + # image handling 330 + # --------------------- 331 + 332 + def visit_kernel_image(self, node): # pylint: disable=W0613 333 + """Visitor of the ``kernel_image`` Node. 334 + 335 + Handles the ``image`` child-node with the ``convert_image(...)``. 336 + """ 337 + img_node = node[0] 338 + convert_image(img_node, self) 339 + 340 + class kernel_image(nodes.image): 341 + """Node for ``kernel-image`` directive.""" 342 + pass 343 + 344 + class KernelImage(images.Image): 345 + u"""KernelImage directive 346 + 347 + Earns everything from ``.. image::`` directive, except *remote URI* and 348 + *glob* pattern. The KernelImage wraps a image node into a 349 + kernel_image node. See ``visit_kernel_image``. 350 + """ 351 + 352 + def run(self): 353 + uri = self.arguments[0] 354 + if uri.endswith('.*') or uri.find('://') != -1: 355 + raise self.severe( 356 + 'Error in "%s: %s": glob pattern and remote images are not allowed' 357 + % (self.name, uri)) 358 + result = images.Image.run(self) 359 + if len(result) == 2 or isinstance(result[0], nodes.system_message): 360 + return result 361 + (image_node,) = result 362 + # wrap image node into a kernel_image node / see visitors 363 + node = kernel_image('', image_node) 364 + return [node] 365 + 366 + # figure handling 367 + # --------------------- 368 + 369 + def visit_kernel_figure(self, node): # pylint: disable=W0613 370 + """Visitor of the ``kernel_figure`` Node. 371 + 372 + Handles the ``image`` child-node with the ``convert_image(...)``. 373 + """ 374 + img_node = node[0][0] 375 + convert_image(img_node, self) 376 + 377 + class kernel_figure(nodes.figure): 378 + """Node for ``kernel-figure`` directive.""" 379 + 380 + class KernelFigure(Figure): 381 + u"""KernelImage directive 382 + 383 + Earns everything from ``.. figure::`` directive, except *remote URI* and 384 + *glob* pattern. The KernelFigure wraps a figure node into a kernel_figure 385 + node. See ``visit_kernel_figure``. 386 + """ 387 + 388 + def run(self): 389 + uri = self.arguments[0] 390 + if uri.endswith('.*') or uri.find('://') != -1: 391 + raise self.severe( 392 + 'Error in "%s: %s":' 393 + ' glob pattern and remote images are not allowed' 394 + % (self.name, uri)) 395 + result = Figure.run(self) 396 + if len(result) == 2 or isinstance(result[0], nodes.system_message): 397 + return result 398 + (figure_node,) = result 399 + # wrap figure node into a kernel_figure node / see visitors 400 + node = kernel_figure('', figure_node) 401 + return [node] 402 + 403 + 404 + # render handling 405 + # --------------------- 406 + 407 + def visit_kernel_render(self, node): 408 + """Visitor of the ``kernel_render`` Node. 409 + 410 + If rendering tools available, save the markup of the ``literal_block`` child 411 + node into a file and replace the ``literal_block`` node with a new created 412 + ``image`` node, pointing to the saved markup file. Afterwards, handle the 413 + image child-node with the ``convert_image(...)``. 414 + """ 415 + app = self.builder.app 416 + srclang = node.get('srclang') 417 + 418 + app.verbose('visit kernel-render node lang: "%s"' % (srclang)) 419 + 420 + tmp_ext = RENDER_MARKUP_EXT.get(srclang, None) 421 + if tmp_ext is None: 422 + app.warn('kernel-render: "%s" unknow / include raw.' % (srclang)) 423 + return 424 + 425 + if not dot_cmd and tmp_ext == '.dot': 426 + app.verbose("dot from graphviz not available / include raw.") 427 + return 428 + 429 + literal_block = node[0] 430 + 431 + code = literal_block.astext() 432 + hashobj = code.encode('utf-8') # str(node.attributes) 433 + fname = path.join('%s-%s' % (srclang, sha1(hashobj).hexdigest())) 434 + 435 + tmp_fname = path.join( 436 + self.builder.outdir, self.builder.imagedir, fname + tmp_ext) 437 + 438 + if not path.isfile(tmp_fname): 439 + mkdir(path.dirname(tmp_fname)) 440 + with open(tmp_fname, "w") as out: 441 + out.write(code) 442 + 443 + img_node = nodes.image(node.rawsource, **node.attributes) 444 + img_node['uri'] = path.join(self.builder.imgpath, fname + tmp_ext) 445 + img_node['candidates'] = { 446 + '*': path.join(self.builder.imgpath, fname + tmp_ext)} 447 + 448 + literal_block.replace_self(img_node) 449 + convert_image(img_node, self, tmp_fname) 450 + 451 + 452 + class kernel_render(nodes.General, nodes.Inline, nodes.Element): 453 + """Node for ``kernel-render`` directive.""" 454 + pass 455 + 456 + class KernelRender(Figure): 457 + u"""KernelRender directive 458 + 459 + Render content by external tool. Has all the options known from the 460 + *figure* directive, plus option ``caption``. If ``caption`` has a 461 + value, a figure node with the *caption* is inserted. If not, a image node is 462 + inserted. 463 + 464 + The KernelRender directive wraps the text of the directive into a 465 + literal_block node and wraps it into a kernel_render node. See 466 + ``visit_kernel_render``. 467 + """ 468 + has_content = True 469 + required_arguments = 1 470 + optional_arguments = 0 471 + final_argument_whitespace = False 472 + 473 + # earn options from 'figure' 474 + option_spec = Figure.option_spec.copy() 475 + option_spec['caption'] = directives.unchanged 476 + 477 + def run(self): 478 + return [self.build_node()] 479 + 480 + def build_node(self): 481 + 482 + srclang = self.arguments[0].strip() 483 + if srclang not in RENDER_MARKUP_EXT.keys(): 484 + return [self.state_machine.reporter.warning( 485 + 'Unknow source language "%s", use one of: %s.' % ( 486 + srclang, ",".join(RENDER_MARKUP_EXT.keys())), 487 + line=self.lineno)] 488 + 489 + code = '\n'.join(self.content) 490 + if not code.strip(): 491 + return [self.state_machine.reporter.warning( 492 + 'Ignoring "%s" directive without content.' % ( 493 + self.name), 494 + line=self.lineno)] 495 + 496 + node = kernel_render() 497 + node['alt'] = self.options.get('alt','') 498 + node['srclang'] = srclang 499 + literal_node = nodes.literal_block(code, code) 500 + node += literal_node 501 + 502 + caption = self.options.get('caption') 503 + if caption: 504 + # parse caption's content 505 + parsed = nodes.Element() 506 + self.state.nested_parse( 507 + ViewList([caption], source=''), self.content_offset, parsed) 508 + caption_node = nodes.caption( 509 + parsed[0].rawsource, '', *parsed[0].children) 510 + caption_node.source = parsed[0].source 511 + caption_node.line = parsed[0].line 512 + 513 + figure_node = nodes.figure('', node) 514 + for k,v in self.options.items(): 515 + figure_node[k] = v 516 + figure_node += caption_node 517 + 518 + node = figure_node 519 + 520 + return node 521 + 522 + def add_kernel_figure_to_std_domain(app, doctree): 523 + """Add kernel-figure anchors to 'std' domain. 524 + 525 + The ``StandardDomain.process_doc(..)`` method does not know how to resolve 526 + the caption (label) of ``kernel-figure`` directive (it only knows about 527 + standard nodes, e.g. table, figure etc.). Without any additional handling 528 + this will result in a 'undefined label' for kernel-figures. 529 + 530 + This handle adds labels of kernel-figure to the 'std' domain labels. 531 + """ 532 + 533 + std = app.env.domains["std"] 534 + docname = app.env.docname 535 + labels = std.data["labels"] 536 + 537 + for name, explicit in iteritems(doctree.nametypes): 538 + if not explicit: 539 + continue 540 + labelid = doctree.nameids[name] 541 + if labelid is None: 542 + continue 543 + node = doctree.ids[labelid] 544 + 545 + if node.tagname == 'kernel_figure': 546 + for n in node.next_node(): 547 + if n.tagname == 'caption': 548 + sectname = clean_astext(n) 549 + # add label to std domain 550 + labels[name] = docname, labelid, sectname 551 + break
+11 -2
Documentation/sphinx/tmplcvt
··· 7 7 # fix \_ 8 8 # title line? 9 9 # 10 + set -eu 11 + 12 + if [ "$#" != "2" ]; then 13 + echo "$0 <docbook file> <rst file>" 14 + exit 15 + fi 16 + 17 + DIR=$(dirname $0) 10 18 11 19 in=$1 12 20 rst=$2 13 21 tmp=$rst.tmp 14 22 15 23 cp $in $tmp 16 - sed --in-place -f convert_template.sed $tmp 24 + sed --in-place -f $DIR/convert_template.sed $tmp 17 25 pandoc -s -S -f docbook -t rst -o $rst $tmp 18 - sed --in-place -f post_convert.sed $rst 26 + sed --in-place -f $DIR/post_convert.sed $rst 19 27 rm $tmp 28 + echo "book writen to $rst"
+1 -1
Documentation/static-keys.txt
··· 118 118 119 119 Keys defined via DEFINE_STATIC_KEY_TRUE(), or DEFINE_STATIC_KEY_FALSE, may 120 120 be used in either static_branch_likely() or static_branch_unlikely() 121 - statemnts. 121 + statements. 122 122 123 123 Branch(es) can be set true via: 124 124
+1 -1
Documentation/sync_file.txt
··· 37 37 Out-fences are fences that the driver creates. 38 38 39 39 On the other hand if the driver receives fence(s) through a sync_file from 40 - userspace we call these fence(s) 'in-fences'. Receiveing in-fences means that 40 + userspace we call these fence(s) 'in-fences'. Receiving in-fences means that 41 41 we need to wait for the fence(s) to signal before using any buffer related to 42 42 the in-fences. 43 43
+15 -5
Documentation/thermal/intel_powerclamp.txt
··· 268 268 max_state:50 269 269 type:intel_powerclamp 270 270 271 + cur_state allows user to set the desired idle percentage. Writing 0 to 272 + cur_state will stop idle injection. Writing a value between 1 and 273 + max_state will start the idle injection. Reading cur_state returns the 274 + actual and current idle percentage. This may not be the same value 275 + set by the user in that current idle percentage depends on workload 276 + and includes natural idle. When idle injection is disabled, reading 277 + cur_state returns value -1 instead of 0 which is to avoid confusing 278 + 100% busy state with the disabled state. 279 + 271 280 Example usage: 272 281 - To inject 25% idle time 273 282 $ sudo sh -c "echo 25 > /sys/class/thermal/cooling_device80/cur_state ··· 287 278 will not show idle injection kernel threads. 288 279 289 280 If the system is busy (spin test below) and has less than 25% natural 290 - idle time, powerclamp kernel threads will do idle injection, which 291 - appear running to the scheduler. But the overall system idle is still 292 - reflected. In this example, 24.1% idle is shown. This helps the 293 - system admin or user determine the cause of slowdown, when a 294 - powerclamp driver is in action. 281 + idle time, powerclamp kernel threads will do idle injection. Forced 282 + idle time is accounted as normal idle in that common code path is 283 + taken as the idle task. 284 + 285 + In this example, 24.1% idle is shown. This helps the system admin or 286 + user determine the cause of slowdown, when a powerclamp driver is in action. 295 287 296 288 297 289 Tasks: 197 total, 1 running, 196 sleeping, 0 stopped, 0 zombie
-637
Documentation/translations/ja_JP/HOWTO
··· 1 - NOTE: 2 - This is a version of Documentation/HOWTO translated into Japanese. 3 - This document is maintained by Tsugikazu Shibata <tshibata@ab.jp.nec.com> 4 - and the JF Project team <www.linux.or.jp/JF>. 5 - If you find any difference between this document and the original file 6 - or a problem with the translation, 7 - please contact the maintainer of this file or JF project. 8 - 9 - Please also note that the purpose of this file is to be easier to read 10 - for non English (read: Japanese) speakers and is not intended as a 11 - fork. So if you have any comments or updates for this file, please try 12 - to update the original English file first. 13 - 14 - Last Updated: 2013/07/19 15 - ================================== 16 - これは、 17 - linux-3.10/Documentation/HOWTO 18 - の和訳です。 19 - 20 - 翻訳団体: JF プロジェクト < http://linuxjf.sourceforge.jp/ > 21 - 翻訳日: 2013/7/19 22 - 翻訳者: Tsugikazu Shibata <tshibata at ab dot jp dot nec dot com> 23 - 校正者: 松倉さん <nbh--mats at nifty dot com> 24 - 小林 雅典さん (Masanori Kobayasi) <zap03216 at nifty dot ne dot jp> 25 - 武井伸光さん、<takei at webmasters dot gr dot jp> 26 - かねこさん (Seiji Kaneko) <skaneko at a2 dot mbn dot or dot jp> 27 - 野口さん (Kenji Noguchi) <tokyo246 at gmail dot com> 28 - 河内さん (Takayoshi Kochi) <t-kochi at bq dot jp dot nec dot com> 29 - 岩本さん (iwamoto) <iwamoto.kn at ncos dot nec dot co dot jp> 30 - 内田さん (Satoshi Uchida) <s-uchida at ap dot jp dot nec dot com> 31 - ================================== 32 - 33 - Linux カーネル開発のやり方 34 - ------------------------------- 35 - 36 - これは上のトピック( Linux カーネル開発のやり方)の重要な事柄を網羅した 37 - ドキュメントです。ここには Linux カーネル開発者になるための方法と 38 - Linux カーネル開発コミュニティと共に活動するやり方を学ぶ方法が含まれて 39 - います。カーネルプログラミングに関する技術的な項目に関することは何も含 40 - めないようにしていますが、カーネル開発者となるための正しい方向に向かう 41 - 手助けになります。 42 - 43 - もし、このドキュメントのどこかが古くなっていた場合には、このドキュメン 44 - トの最後にリストしたメンテナにパッチを送ってください。 45 - 46 - はじめに 47 - --------- 48 - 49 - あなたは Linux カーネルの開発者になる方法を学びたいのでしょうか? そ 50 - れともあなたは上司から「このデバイスの Linux ドライバを書くように」と 51 - 言われているのでしょうか?  52 - この文書の目的は、あなたが踏むべき手順と、コミュニティと一緒にうまく働 53 - くヒントを書き下すことで、あなたが知るべき全てのことを教えることです。 54 - また、このコミュニティがなぜ今うまくまわっているのかという理由の一部も 55 - 説明しようと試みています。 56 - 57 - 58 - カーネルは 少量のアーキテクチャ依存部分がアセンブリ言語で書かれている 59 - 以外は大部分は C 言語で書かれています。C言語をよく理解していることはカー 60 - ネル開発者には必要です。アーキテクチャ向けの低レベル部分の開発をするの 61 - でなければ、(どんなアーキテクチャでも)アセンブリ(訳注: 言語)は必要あり 62 - ません。以下の本は、C 言語の十分な知識や何年もの経験に取って代わるもの 63 - ではありませんが、少なくともリファレンスとしては良い本です。 64 - - "The C Programming Language" by Kernighan and Ritchie [Prentice Hall] 65 - -『プログラミング言語C第2版』(B.W. カーニハン/D.M. リッチー著 石田晴久訳) [共立出版] 66 - - "Practical C Programming" by Steve Oualline [O'Reilly] 67 - - 『C実践プログラミング第3版』(Steve Oualline著 望月康司監訳 谷口功訳) [オライリージャパン] 68 - - "C: A Reference Manual" by Harbison and Steele [Prentice Hall] 69 - - 『新・詳説 C 言語 H&S リファレンス』 70 - (サミュエル P ハービソン/ガイ L スティール共著 斉藤 信男監訳)[ソフトバンク] 71 - 72 - カーネルは GNU C と GNU ツールチェインを使って書かれています。カーネル 73 - は ISO C89 仕様に準拠して書く一方で、標準には無い言語拡張を多く使って 74 - います。カーネルは標準 C ライブラリとは関係がないといった、C 言語フリー 75 - スタンディング環境です。そのため、C の標準で使えないものもあります。任 76 - 意の long long の除算や浮動小数点は使えません。 77 - ときどき、カーネルがツールチェインや C 言語拡張に置いている前提がどう 78 - なっているのかわかりにくいことがあり、また、残念なことに決定的なリファ 79 - レンスは存在しません。情報を得るには、gcc の info ページ( info gcc )を 80 - 見てください。 81 - 82 - あなたは既存の開発コミュニティと一緒に作業する方法を学ぼうとしているこ 83 - とに留意してください。そのコミュニティは、コーディング、スタイル、 84 - 開発手順について高度な標準を持つ、多様な人の集まりです。 85 - 地理的に分散した大規模なチームに対してもっともうまくいくとわかったこと 86 - をベースにしながら、これらの標準は長い時間をかけて築かれてきました。 87 - これらはきちんと文書化されていますから、事前にこれらの標準についてでき 88 - るだけたくさん学んでください。また皆があなたやあなたの会社のやり方に合わ 89 - せてくれると思わないでください。 90 - 91 - 法的問題 92 - ------------ 93 - 94 - Linux カーネルのソースコードは GPL ライセンスの下でリリースされていま 95 - す。ライセンスの詳細については、ソースツリーのメインディレクトリに存在 96 - する、COPYING のファイルを見てください。もしライセンスについてさらに質 97 - 問があれば、Linux Kernel メーリングリストに質問するのではなく、どうぞ 98 - 法律家に相談してください。メーリングリストの人達は法律家ではなく、法的 99 - 問題については彼らの声明はあてにするべきではありません。 100 - 101 - GPL に関する共通の質問や回答については、以下を参照してください。 102 - http://www.gnu.org/licenses/gpl-faq.html 103 - 104 - ドキュメント 105 - ------------ 106 - 107 - Linux カーネルソースツリーは幅広い範囲のドキュメントを含んでおり、それ 108 - らはカーネルコミュニティと会話する方法を学ぶのに非常に貴重なものです。 109 - 新しい機能がカーネルに追加される場合、その機能の使い方について説明した 110 - 新しいドキュメントファイルも追加することを勧めます。 111 - カーネルの変更が、カーネルがユーザ空間に公開しているインターフェイスの 112 - 変更を引き起こす場合、その変更を説明するマニュアルページのパッチや情報 113 - をマニュアルページのメンテナ mtk.manpages@gmail.com に送り、CC を 114 - linux-api@vger.kernel.org に送ることを勧めます。 115 - 116 - 以下はカーネルソースツリーに含まれている読んでおくべきファイルの一覧で 117 - す- 118 - 119 - README 120 - このファイルは Linuxカーネルの簡単な背景とカーネルを設定(訳注 121 - configure )し、生成(訳注 build )するために必要なことは何かが書かれ 122 - ています。カーネルに関して初めての人はここからスタートすると良いで 123 - しょう。 124 - 125 - Documentation/Changes 126 - このファイルはカーネルをうまく生成(訳注 build )し、走らせるのに最 127 - 小限のレベルで必要な数々のソフトウェアパッケージの一覧を示してい 128 - ます。 129 - 130 - Documentation/process/coding-style.rst 131 - これは Linux カーネルのコーディングスタイルと背景にある理由を記述 132 - しています。全ての新しいコードはこのドキュメントにあるガイドライン 133 - に従っていることを期待されています。大部分のメンテナはこれらのルー 134 - ルに従っているものだけを受け付け、多くの人は正しいスタイルのコード 135 - だけをレビューします。 136 - 137 - Documentation/process/submitting-patches.rst 138 - Documentation/process/submitting-drivers.rst 139 - これらのファイルには、どうやってうまくパッチを作って投稿するかに 140 - ついて非常に詳しく書かれており、以下を含みます(これだけに限らない 141 - けれども) 142 - - Email に含むこと 143 - - Email の形式 144 - - だれに送るか 145 - これらのルールに従えばうまくいくことを保証することではありません 146 - が (すべてのパッチは内容とスタイルについて精査を受けるので)、 147 - ルールに従わなければ間違いなくうまくいかないでしょう。 148 - 149 - この他にパッチを作る方法についてのよくできた記述は- 150 - 151 - "The Perfect Patch" 152 - http://www.ozlabs.org/~akpm/stuff/tpp.txt 153 - "Linux kernel patch submission format" 154 - http://linux.yyz.us/patch-format.html 155 - 156 - Documentation/process/stable-api-nonsense.rst 157 - このファイルはカーネルの中に不変のAPIを持たないことにした意識的な 158 - 決断の背景にある理由について書かれています。以下のようなことを含 159 - んでいます- 160 - - サブシステムとの間に層を作ること(コンパチビリティのため?) 161 - - オペレーティングシステム間のドライバの移植性 162 - - カーネルソースツリーの素早い変更を遅らせる(もしくは素早い変更 163 - を妨げる) 164 - このドキュメントは Linux 開発の思想を理解するのに非常に重要です。 165 - そして、他のOSでの開発者が Linux に移る時にとても重要です。 166 - 167 - Documentation/admin-guide/security-bugs.rst 168 - もし Linux カーネルでセキュリティ問題を発見したように思ったら、こ 169 - のドキュメントのステップに従ってカーネル開発者に連絡し、問題解決を 170 - 支援してください。 171 - 172 - Documentation/process/management-style.rst 173 - このドキュメントは Linux カーネルのメンテナ達がどう行動するか、 174 - 彼らの手法の背景にある共有されている精神について記述しています。こ 175 - れはカーネル開発の初心者なら(もしくは、単に興味があるだけの人でも) 176 - 重要です。なぜならこのドキュメントは、カーネルメンテナ達の独特な 177 - 行動についての多くの誤解や混乱を解消するからです。 178 - 179 - Documentation/process/stable-kernel-rules.rst 180 - このファイルはどのように stable カーネルのリリースが行われるかのルー 181 - ルが記述されています。そしてこれらのリリースの中のどこかで変更を取 182 - り入れてもらいたい場合に何をすれば良いかが示されています。 183 - 184 - Documentation/process/kernel-docs.rst 185 -   カーネル開発に付随する外部ドキュメントのリストです。もしあなたが 186 - 探しているものがカーネル内のドキュメントでみつからなかった場合、 187 - このリストをあたってみてください。 188 - 189 - Documentation/process/applying-patches.rst 190 - パッチとはなにか、パッチをどうやって様々なカーネルの開発ブランチに 191 - 適用するのかについて正確に記述した良い入門書です。 192 - 193 - カーネルはソースコードから自動的に生成可能な多数のドキュメントを自分自 194 - 身でもっています。これにはカーネル内 API のすべての記述や、どう正しく 195 - ロックをかけるかの規則が含まれます。このドキュメントは 196 - Documentation/DocBook/ ディレクトリに作られ、以下のように 197 - make pdfdocs 198 - make psdocs 199 - make htmldocs 200 - make mandocs 201 - コマンドを実行するとメインカーネルのソースディレクトリから 202 - それぞれ、PDF, Postscript, HTML, man page の形式で生成されます。 203 - 204 - カーネル開発者になるには 205 - --------------------------- 206 - 207 - もしあなたが、Linux カーネル開発について何も知らないならば、 208 - KernelNewbies プロジェクトを見るべきです 209 - http://kernelnewbies.org 210 - 211 - このサイトには役に立つメーリングリストがあり、基本的なカーネル開発に関 212 - するほとんどどんな種類の質問もできます (既に回答されているようなことを 213 - 聞く前にまずはアーカイブを調べてください)。 214 - またここには、リアルタイムで質問を聞くことができる IRC チャネルや、Linux 215 - カーネルの開発に関して学ぶのに便利なたくさんの役に立つドキュメントがあ 216 - ります。 217 - 218 - web サイトには、コードの構成、サブシステム、現在存在するプロジェクト(ツ 219 - リーにあるもの無いものの両方)の基本的な管理情報があります。 220 - ここには、また、カーネルのコンパイルのやり方やパッチの当て方などの間接 221 - 的な基本情報も記述されています。 222 - 223 - あなたがどこからスタートして良いかわからないが、Linux カーネル開発コミュ 224 - ニティに参加して何かすることをさがしている場合には、Linux kernel 225 - Janitor's プロジェクトにいけば良いでしょう - 226 - http://kernelnewbies.org/KernelJanitors 227 - ここはそのようなスタートをするのにうってつけの場所です。ここには、 228 - Linux カーネルソースツリーの中に含まれる、きれいにし、修正しなければな 229 - らない、単純な問題のリストが記述されています。このプロジェクトに関わる 230 - 開発者と一緒に作業することで、あなたのパッチを Linuxカーネルツリーに入 231 - れるための基礎を学ぶことができ、そしてもしあなたがまだアイディアを持っ 232 - ていない場合には、次にやる仕事の方向性が見えてくるかもしれません。 233 - 234 - もしあなたが、すでにひとまとまりコードを書いていて、カーネルツリーに入 235 - れたいと思っていたり、それに関する適切な支援を求めたい場合、カーネル 236 - メンターズプロジェクトはそのような皆さんを助けるためにできました。 237 - ここにはメーリングリストがあり、以下から参照できます 238 - http://selenic.com/mailman/listinfo/kernel-mentors 239 - 240 - 実際に Linux カーネルのコードについて修正を加える前に、どうやってその 241 - コードが動作するのかを理解することが必要です。そのためには、特別なツー 242 - ルの助けを借りてでも、それを直接よく読むことが最良の方法です(ほとんど 243 - のトリッキーな部分は十分にコメントしてありますから)。そういうツールで 244 - 特におすすめなのは、Linux クロスリファレンスプロジェクトです。これは、 245 - 自己参照方式で、索引がついた web 形式で、ソースコードを参照することが 246 - できます。この最新の素晴しいカーネルコードのリポジトリは以下で見つかり 247 - ます- 248 - http://lxr.free-electrons.com/ 249 - 250 - 開発プロセス 251 - ----------------------- 252 - 253 - Linux カーネルの開発プロセスは現在幾つかの異なるメインカーネル「ブラン 254 - チ」と多数のサブシステム毎のカーネルブランチから構成されます。 255 - これらのブランチとは- 256 - - メインの 3.x カーネルツリー 257 - - 3.x.y -stable カーネルツリー 258 - - 3.x -git カーネルパッチ 259 - - サブシステム毎のカーネルツリーとパッチ 260 - - 統合テストのための 3.x -next カーネルツリー 261 - 262 - 3.x カーネルツリー 263 - ----------------- 264 - 265 - 3.x カーネルは Linus Torvalds によってメンテナンスされ、kernel.org 266 - の pub/linux/kernel/v3.x/ ディレクトリに存在します。この開発プロセスは 267 - 以下のとおり- 268 - 269 - - 新しいカーネルがリリースされた直後に、2週間の特別期間が設けられ、 270 - この期間中に、メンテナ達は Linus に大きな差分を送ることができます。 271 - このような差分は通常 -next カーネルに数週間含まれてきたパッチです。 272 - 大きな変更は git(カーネルのソース管理ツール、詳細は 273 - http://git-scm.com/ 参照) を使って送るのが好ましいやり方ですが、パッ 274 - チファイルの形式のまま送るのでも十分です。 275 - 276 - - 2週間後、-rc1 カーネルがリリースされ、この後にはカーネル全体の安定 277 - 性に影響をあたえるような新機能は含まない類のパッチしか取り込むこと 278 - はできません。新しいドライバ(もしくはファイルシステム)のパッチは 279 - -rc1 の後で受け付けられることもあることを覚えておいてください。な 280 - ぜなら、変更が独立していて、追加されたコードの外の領域に影響を与え 281 - ない限り、退行のリスクは無いからです。-rc1 がリリースされた後、 282 - Linus へパッチを送付するのに git を使うこともできますが、パッチは 283 - レビューのために、パブリックなメーリングリストへも同時に送る必要が 284 - あります。 285 - 286 - - 新しい -rc は Linus が、最新の git ツリーがテスト目的であれば十分 287 - に安定した状態にあると判断したときにリリースされます。目標は毎週新 288 - しい -rc カーネルをリリースすることです。 289 - 290 - - このプロセスはカーネルが 「準備ができた」と考えられるまで継続しま 291 - す。このプロセスはだいたい 6週間継続します。 292 - 293 - Andrew Morton が Linux-kernel メーリングリストにカーネルリリースについ 294 - て書いたことをここで言っておくことは価値があります- 295 - 「カーネルがいつリリースされるかは誰も知りません。なぜなら、これは現 296 - 実に認識されたバグの状況によりリリースされるのであり、前もって決めら 297 - れた計画によってリリースされるものではないからです。」 298 - 299 - 3.x.y -stable カーネルツリー 300 - --------------------------- 301 - 302 - バージョン番号が3つの数字に分かれているカーネルは -stable カーネルです。 303 - これには、3.x カーネルで見つかったセキュリティ問題や重大な後戻りに対 304 - する比較的小さい重要な修正が含まれます。 305 - 306 - これは、開発/実験的バージョンのテストに協力することに興味が無く、 307 - 最新の安定したカーネルを使いたいユーザに推奨するブランチです。 308 - 309 - もし、3.x.y カーネルが存在しない場合には、番号が一番大きい 3.x が 310 - 最新の安定版カーネルです。 311 - 312 - 3.x.y は "stable" チーム <stable@vger.kernel.org> でメンテされており、必 313 - 要に応じてリリースされます。通常のリリース期間は 2週間毎ですが、差し迫っ 314 - た問題がなければもう少し長くなることもあります。セキュリティ関連の問題 315 - の場合はこれに対してだいたいの場合、すぐにリリースがされます。 316 - 317 - カーネルツリーに入っている、Documentation/process/stable-kernel-rules.rst ファ 318 - イルにはどのような種類の変更が -stable ツリーに受け入れ可能か、またリ 319 - リースプロセスがどう動くかが記述されています。 320 - 321 - 3.x -git パッチ 322 - ------------------ 323 - 324 - git リポジトリで管理されているLinus のカーネルツリーの毎日のスナップ 325 - ショットがあります。(だから -git という名前がついています)。これらのパッ 326 - チはおおむね毎日リリースされており、Linus のツリーの現状を表します。こ 327 - れは -rc カーネルと比べて、パッチが大丈夫かどうかも確認しないで自動的 328 - に生成されるので、より実験的です。 329 - 330 - サブシステム毎のカーネルツリーとパッチ 331 - ------------------------------------------- 332 - 333 - それぞれのカーネルサブシステムのメンテナ達は --- そして多くのカーネル 334 - サブシステムの開発者達も --- 各自の最新の開発状況をソースリポジトリに 335 - 公開しています。そのため、自分とは異なる領域のカーネルで何が起きている 336 - かを他の人が見られるようになっています。開発が早く進んでいる領域では、 337 - 開発者は自身の投稿がどのサブシステムカーネルツリーを元にしているか質問 338 - されるので、その投稿とすでに進行中の他の作業との衝突が避けられます。 339 - 340 - 大部分のこれらのリポジトリは git ツリーです。しかしその他の SCM や 341 - quilt シリーズとして公開されているパッチキューも使われています。これら 342 - のサブシステムリポジトリのアドレスは MAINTAINERS ファイルにリストされ 343 - ています。これらの多くは http://git.kernel.org/ で参照することができま 344 - す。 345 - 346 - 提案されたパッチがこのようなサブシステムツリーにコミットされる前に、メー 347 - リングリストで事前にレビューにかけられます(以下の対応するセクションを 348 - 参照)。いくつかのカーネルサブシステムでは、このレビューは patchwork 349 - というツールによって追跡されます。Patchwork は web インターフェイスに 350 - よってパッチ投稿の表示、パッチへのコメント付けや改訂などができ、そして 351 - メンテナはパッチに対して、レビュー中、受付済み、拒否というようなマーク 352 - をつけることができます。大部分のこれらの patchwork のサイトは 353 - http://patchwork.kernel.org/ でリストされています。 354 - 355 - 統合テストのための 3.x -next カーネルツリー 356 - --------------------------------------------- 357 - 358 - サブシステムツリーの更新内容がメインラインの 3.x ツリーにマージされ 359 - る前に、それらは統合テストされる必要があります。この目的のため、実質的 360 - に全サブシステムツリーからほぼ毎日プルされてできる特別なテスト用のリ 361 - ポジトリが存在します- 362 - http://git.kernel.org/?p=linux/kernel/git/next/linux-next.git 363 - 364 - このやり方によって、-next カーネルは次のマージ機会でどんなものがメイン 365 - ラインカーネルにマージされるか、おおまかなの展望を提供します。-next 366 - カーネルの実行テストを行う冒険好きなテスターは大いに歓迎されます 367 - 368 - バグレポート 369 - ------------- 370 - 371 - bugzilla.kernel.org は Linux カーネル開発者がカーネルのバグを追跡する 372 - 場所です。ユーザは見つけたバグの全てをこのツールで報告すべきです。 373 - どう kernel bugzilla を使うかの詳細は、以下を参照してください- 374 - http://bugzilla.kernel.org/page.cgi?id=faq.html 375 - メインカーネルソースディレクトリにあるファイル admin-guide/reporting-bugs.rst はカーネ 376 - ルバグらしいものについてどうレポートするかの良いテンプレートであり、問 377 - 題の追跡を助けるためにカーネル開発者にとってどんな情報が必要なのかの詳 378 - 細が書かれています。 379 - 380 - バグレポートの管理 381 - ------------------- 382 - 383 - あなたのハッキングのスキルを訓練する最高の方法のひとつに、他人がレポー 384 - トしたバグを修正することがあります。あなたがカーネルをより安定化させる 385 - こに寄与するということだけでなく、あなたは 現実の問題を修正することを 386 - 学び、自分のスキルも強化でき、また他の開発者があなたの存在に気がつき 387 - ます。バグを修正することは、多くの開発者の中から自分が功績をあげる最善 388 - の道です、なぜなら多くの人は他人のバグの修正に時間を浪費することを好ま 389 - ないからです。 390 - 391 - すでにレポートされたバグのために仕事をするためには、 392 - http://bugzilla.kernel.org に行ってください。もし今後のバグレポートに 393 - ついてアドバイスを受けたいのであれば、bugme-new メーリングリスト(新し 394 - いバグレポートだけがここにメールされる) または bugme-janitor メーリン 395 - グリスト(bugzilla の変更毎にここにメールされる)を購読できます。 396 - 397 - http://lists.linux-foundation.org/mailman/listinfo/bugme-new 398 - http://lists.linux-foundation.org/mailman/listinfo/bugme-janitors 399 - 400 - メーリングリスト 401 - ------------- 402 - 403 - 上のいくつかのドキュメントで述べていますが、コアカーネル開発者の大部分 404 - は Linux kernel メーリングリストに参加しています。このリストの登録/脱 405 - 退の方法については以下を参照してください- 406 - http://vger.kernel.org/vger-lists.html#linux-kernel 407 - 408 - このメーリングリストのアーカイブは web 上の多数の場所に存在します。こ 409 - れらのアーカイブを探すにはサーチエンジンを使いましょう。例えば- 410 - http://dir.gmane.org/gmane.linux.kernel 411 - 412 - リストに投稿する前にすでにその話題がアーカイブに存在するかどうかを検索 413 - することを是非やってください。多数の事がすでに詳細に渡って議論されて 414 - おり、アーカイブにのみ記録されています。 415 - 416 - 大部分のカーネルサブシステムも自分の個別の開発を実施するメーリングリス 417 - トを持っています。個々のグループがどんなリストを持っているかは、 418 - MAINTAINERS ファイルにリストがありますので参照してください。 419 - 420 - 多くのリストは kernel.org でホストされています。これらの情報は以下にあ 421 - ります- 422 - http://vger.kernel.org/vger-lists.html 423 - 424 - メーリングリストを使う場合、良い行動習慣に従うようにしましょう。 425 - 少し安っぽいが、以下の URL は上のリスト(や他のリスト)で会話する場合の 426 - シンプルなガイドラインを示しています- 427 - http://www.albion.com/netiquette/ 428 - 429 - もし複数の人があなたのメールに返事をした場合、CC: で受ける人のリストは 430 - だいぶ多くなるでしょう。良い理由がない場合、CC: リストから誰かを削除を 431 - しないように、また、メーリングリストのアドレスだけにリプライすることの 432 - ないようにしましょう。1つは送信者から、もう1つはリストからのように、メー 433 - ルを2回受けることになってもそれに慣れ、しゃれたメールヘッダーを追加し 434 - てこの状態を変えようとしないように。人々はそのようなことは好みません。 435 - 436 - 今までのメールでのやりとりとその間のあなたの発言はそのまま残し、 437 - "John Kernelhacker wrote ...:" の行をあなたのリプライの先頭行にして、 438 - メールの先頭でなく、各引用行の間にあなたの言いたいことを追加するべきで 439 - す。 440 - 441 - もしパッチをメールに付ける場合は、Documentation/process/submitting-patches.rst に提 442 - 示されているように、それは プレーンな可読テキストにすることを忘れない 443 - ようにしましょう。カーネル開発者は 添付や圧縮したパッチを扱いたがりま 444 - せん- 445 - 彼らはあなたのパッチの行毎にコメントを入れたいので、そのためにはそうす 446 - るしかありません。あなたのメールプログラムが空白やタブを圧縮しないよう 447 - に確認した方が良いです。最初の良いテストとしては、自分にメールを送って 448 - みて、そのパッチを自分で当ててみることです。もしそれがうまく行かないな 449 - ら、あなたのメールプログラムを直してもらうか、正しく動くように変えるべ 450 - きです。 451 - 452 - とりわけ、他の登録者に対する尊敬を表すようにすることを覚えておいてくだ 453 - さい。 454 - 455 - コミュニティと共に働くこと 456 - -------------------------- 457 - 458 - カーネルコミュニティのゴールは可能なかぎり最高のカーネルを提供すること 459 - です。あなたがパッチを受け入れてもらうために投稿した場合、それは、技術 460 - 的メリットだけがレビューされます。その際、あなたは何を予想すべきでしょ 461 - うか? 462 - - 批判 463 - - コメント 464 - - 変更の要求 465 - - パッチの正当性の証明要求 466 - - 沈黙 467 - 468 - 思い出してください、ここはあなたのパッチをカーネルに入れる話です。あ 469 - なたは、あなたのパッチに対する批判とコメントを受け入れるべきで、それら 470 - を技術的レベルで評価して、パッチを再作成するか、なぜそれらの変更をすべ 471 - きでないかを明確で簡潔な理由の説明を提供してください。 472 - もし、あなたのパッチに何も反応がない場合、たまにはメールの山に埋もれて 473 - 見逃され、あなたの投稿が忘れられてしまうこともあるので、数日待って再度 474 - 投稿してください。 475 - 476 - あなたがやるべきでないものは? 477 - - 質問なしにあなたのパッチが受け入れられると想像すること 478 - - 守りに入ること 479 - - コメントを無視すること 480 - - 要求された変更を何もしないでパッチを出し直すこと 481 - 482 - 可能な限り最高の技術的解決を求めているコミュニティでは、パッチがどのく 483 - らい有益なのかについては常に異なる意見があります。あなたは協調的である 484 - べきですし、また、あなたのアイディアをカーネルに対してうまく合わせるよ 485 - うにすることが望まれています。もしくは、最低限あなたのアイディアがそれ 486 - だけの価値があるとすすんで証明するようにしなければなりません。 487 - 正しい解決に向かって進もうという意志がある限り、間違うことがあっても許 488 - 容されることを忘れないでください。 489 - 490 - あなたの最初のパッチに単に 1ダースもの修正を求めるリストの返答になるこ 491 - とも普通のことです。これはあなたのパッチが受け入れられないということで 492 - は *ありません*、そしてあなた自身に反対することを意味するのでも *ありま 493 - せん*。単に自分のパッチに対して指摘された問題を全て修正して再送すれば 494 - 良いのです。 495 - 496 - 497 - カーネルコミュニティと企業組織のちがい 498 - ----------------------------------------------------------------- 499 - 500 - カーネルコミュニティは大部分の伝統的な会社の開発環境とは異ったやり方で 501 - 動いています。以下は問題を避けるためにできると良いことのリストです- 502 - 503 - あなたの提案する変更について言うときのうまい言い方: 504 - 505 - - "これは複数の問題を解決します" 506 - - "これは2000行のコードを削除します" 507 - - "以下のパッチは、私が言おうとしていることを説明するものです" 508 - - "私はこれを5つの異なるアーキテクチャでテストしたのですが..." 509 - - "以下は一連の小さなパッチ群ですが..." 510 - - "これは典型的なマシンでの性能を向上させます.." 511 - 512 - やめた方が良い悪い言い方: 513 - 514 - - このやり方で AIX/ptx/Solaris ではできたので、できるはずだ 515 - - 私はこれを20年もの間やってきた、だから 516 - - これは、私の会社が金儲けをするために必要だ 517 - - これは我々のエンタープライズ向け商品ラインのためである 518 - - これは 私が自分のアイディアを記述した、1000ページの設計資料である 519 - - 私はこれについて、6ケ月作業している。 520 - - 以下は ... に関する5000行のパッチです 521 - - 私は現在のぐちゃぐちゃを全部書き直した、それが以下です... 522 - - 私は〆切がある、そのためこのパッチは今すぐ適用される必要がある 523 - 524 - カーネルコミュニティが大部分の伝統的なソフトウェアエンジニアリングの労 525 - 働環境と異なるもう一つの点は、やりとりに顔を合わせないということです。 526 - email と irc を第一のコミュニケーションの形とする一つの利点は、性別や 527 - 民族の差別がないことです。Linux カーネルの職場環境は女性や少数民族を受 528 - 容します。なぜなら、email アドレスによってのみあなたが認識されるからで 529 - す。 530 - 国際的な側面からも活動領域を均等にするようにします。なぜならば、あなた 531 - は人の名前で性別を想像できないからです。ある男性が アンドレアという名 532 - 前で、女性の名前は パット かもしれません (訳注 Andrea は米国では女性、 533 - それ以外(欧州など)では男性名として使われることが多い。同様に、Pat は 534 - Patricia (主に女性名)や Patrick (主に男性名)の略称)。 535 - Linux カーネルの活動をして、意見を表明したことがある大部分の女性は、前 536 - 向きな経験をもっています。 537 - 538 - 言葉の壁は英語が得意でない一部の人には問題になります。 539 - メーリングリストの中できちんとアイディアを交換するには、相当うまく英語 540 - を操れる必要があることもあります。そのため、あなたは自分のメール 541 - を送る前に英語で意味が通じているかをチェックすることをお薦めします。 542 - 543 - 変更を分割する 544 - --------------------- 545 - 546 - Linux カーネルコミュニティは、一度に大量のコードの塊を喜んで受容するこ 547 - とはありません。変更は正確に説明される必要があり、議論され、小さい、個 548 - 別の部分に分割する必要があります。これはこれまで多くの会社がやり慣れて 549 - きたことと全く正反対のことです。あなたのプロポーザルは、開発プロセスのと 550 - ても早い段階から紹介されるべきです。そうすれば あなたは自分のやってい 551 - ることにフィードバックを得られます。これは、コミュニティからみれば、あ 552 - なたが彼らと一緒にやっているように感じられ、単にあなたの提案する機能の 553 - ゴミ捨て場として使っているのではない、と感じられるでしょう。 554 - しかし、一度に 50 もの email をメーリングリストに送りつけるようなことは 555 - やってはいけません、あなたのパッチ群はいつもどんな時でもそれよりは小さ 556 - くなければなりません。 557 - 558 - パッチを分割する理由は以下です- 559 - 560 - 1) 小さいパッチはあなたのパッチが適用される見込みを大きくします、カー 561 - ネルの人達はパッチが正しいかどうかを確認する時間や労力をかけないか 562 - らです。5行のパッチはメンテナがたった1秒見るだけで適用できます。 563 - しかし、500行のパッチは、正しいことをレビューするのに数時間かかるか 564 - もしれません(時間はパッチのサイズなどにより指数関数に比例してかかり 565 - ます) 566 - 567 - 小さいパッチは何かあったときにデバッグもとても簡単になります。パッ 568 - チを1個1個取り除くのは、とても大きなパッチを当てた後に(かつ、何かお 569 - かしくなった後で)解剖するのに比べればとても簡単です。 570 - 571 - 2) 小さいパッチを送るだけでなく、送るまえに、書き直して、シンプルにす 572 - る(もしくは、単に順番を変えるだけでも)ことも、とても重要です。 573 - 574 - 以下はカーネル開発者の Al Viro のたとえ話です: 575 - 576 - "生徒の数学の宿題を採点する先生のことを考えてみてください、先 577 - 生は生徒が解に到達するまでの試行錯誤を見たいとは思わないでしょ 578 - う。先生は簡潔な最高の解を見たいのです。良い生徒はこれを知って 579 - おり、そして最終解の前の中間作業を提出することは決してないので 580 - す" 581 - 582 - カーネル開発でもこれは同じです。メンテナ達とレビューア達は、 583 - 問題を解決する解の背後になる思考プロセスを見たいとは思いません。 584 - 彼らは単純であざやかな解決方法を見たいのです。 585 - 586 - あざやかな解を説明するのと、コミュニティと共に仕事をし、未解決の仕事を 587 - 議論することのバランスをキープするのは難しいかもしれません。 588 - ですから、開発プロセスの早期段階で改善のためのフィードバックをもらうよ 589 - うにするのも良いですが、変更点を小さい部分に分割して全体ではまだ完成し 590 - ていない仕事を(部分的に)取り込んでもらえるようにすることも良いことです。 591 - 592 - また、でき上がっていないものや、"将来直す" ようなパッチを、本流に含め 593 - てもらうように送っても、それは受け付けられないことを理解してください。 594 - 595 - あなたの変更を正当化する 596 - ------------------- 597 - 598 - あなたのパッチを分割するのと同時に、なぜその変更を追加しなければならな 599 - いかを Linux コミュニティに知らせることはとても重要です。新機能は必要 600 - 性と有用性で正当化されなければなりません。 601 - 602 - あなたの変更の説明 603 - -------------------- 604 - 605 - あなたのパッチを送付する場合には、メールの中のテキストで何を言うかにつ 606 - いて、特別に注意を払ってください。この情報はパッチの ChangeLog に使わ 607 - れ、いつも皆がみられるように保管されます。これは次のような項目を含め、 608 - パッチを完全に記述するべきです- 609 - 610 - - なぜ変更が必要か 611 - - パッチ全体の設計アプローチ 612 - - 実装の詳細 613 - - テスト結果 614 - 615 - これについて全てがどのようにあるべきかについての詳細は、以下のドキュメ 616 - ントの ChangeLog セクションを見てください- 617 - "The Perfect Patch" 618 - http://www.ozlabs.org/~akpm/stuff/tpp.txt 619 - 620 - これらのどれもが、時にはとても困難です。これらの慣例を完璧に実施するに 621 - は数年かかるかもしれません。これは継続的な改善のプロセスであり、そのた 622 - めには多数の忍耐と決意を必要とするものです。でも、諦めないで、これは可 623 - 能なことです。多数の人がすでにできていますし、彼らも皆最初はあなたと同 624 - じところからスタートしたのですから。 625 - 626 - Paolo Ciarrocchi に感謝、彼は彼の書いた "Development Process" 627 - (http://lwn.net/Articles/94386/) セクションをこのテキストの原型にする 628 - ことを許可してくれました。Rundy Dunlap と Gerrit Huizenga はメーリング 629 - リストでやるべきこととやってはいけないことのリストを提供してくれました。 630 - 以下の人々のレビュー、コメント、貢献に感謝。 631 - Pat Mochel, Hanna Linder, Randy Dunlap, Kay Sievers, 632 - Vojtech Pavlik, Jan Kara, Josh Boyer, Kees Cook, Andrew Morton, Andi 633 - Kleen, Vadim Lobanov, Jesper Juhl, Adrian Bunk, Keri Harris, Frans Pop, 634 - David A. Wheeler, Junio Hamano, Michael Kerrisk, と Alex Shepard 635 - 彼らの支援なしでは、このドキュメントはできなかったでしょう。 636 - 637 - Maintainer: Greg Kroah-Hartman <greg@kroah.com>
+661
Documentation/translations/ja_JP/howto.rst
··· 1 + NOTE: 2 + This is a version of Documentation/HOWTO translated into Japanese. 3 + This document is maintained by Tsugikazu Shibata <tshibata@ab.jp.nec.com> 4 + If you find any difference between this document and the original file or 5 + a problem with the translation, please contact the maintainer of this file. 6 + 7 + Please also note that the purpose of this file is to be easier to 8 + read for non English (read: Japanese) speakers and is not intended as 9 + a fork. So if you have any comments or updates for this file, please 10 + try to update the original English file first. 11 + 12 + ---------------------------------- 13 + 14 + この文書は、 15 + Documentation/process/howto.rst 16 + の和訳です。 17 + 18 + 翻訳者: Tsugikazu Shibata <tshibata@ab.jp.nec.com> 19 + 20 + ---------------------------------- 21 + 22 + Linux カーネル開発のやり方 23 + ========================== 24 + 25 + これは上のトピック( Linux カーネル開発のやり方)の重要な事柄を網羅した 26 + ドキュメントです。ここには Linux カーネル開発者になるための方法とLinux 27 + カーネル開発コミュニティと共に活動するやり方を学ぶ方法が含まれています。 28 + カーネルプログラミングに関する技術的な項目に関することは何も含めないよ 29 + うにしていますが、カーネル開発者となるための正しい方向に向かう手助けに 30 + なります。 31 + 32 + もし、このドキュメントのどこかが古くなっていた場合には、このドキュメント 33 + の最後にリストしたメンテナにパッチを送ってください。 34 + 35 + はじめに 36 + --------- 37 + 38 + あなたは Linux カーネルの開発者になる方法を学びたいのでしょうか? そ 39 + れとも上司から「このデバイスの Linux ドライバを書くように」と言われた 40 + のかもしれません。この文書の目的は、あなたが踏むべき手順と、コミュニティ 41 + と一緒にうまく働くヒントを書き下すことで、あなたが知るべき全てのことを 42 + 教えることです。また、このコミュニティがなぜ今うまくまわっているのかと 43 + いう理由も説明しようと試みています。 44 + 45 + カーネルは少量のアーキテクチャ依存部分がアセンブリ言語で書かれている以 46 + 外の大部分は C 言語で書かれています。C言語をよく理解していることはカー 47 + ネル開発に必要です。低レベルのアーキテクチャ開発をするのでなければ、 48 + (どんなアーキテクチャでも)アセンブリ(訳注: 言語)は必要ありません。以下 49 + の本は、C 言語の十分な知識や何年もの経験に取って代わるものではありませ 50 + んが、少なくともリファレンスとしては良い本です。 51 + 52 + - "The C Programming Language" by Kernighan and Ritchie [Prentice Hall] 53 + - 『プログラミング言語C第2版』(B.W. カーニハン/D.M. リッチー著 石田晴久訳) [共立出版] 54 + - "Practical C Programming" by Steve Oualline [O'Reilly] 55 + - 『C実践プログラミング第3版』(Steve Oualline著 望月康司監訳 谷口功訳) [オライリージャパン] 56 + - "C: A Reference Manual" by Harbison and Steele [Prentice Hall] 57 + - 『新・詳説 C 言語 H&S リファレンス』 (サミュエル P ハービソン/ガイ L スティール共著 斉藤 信男監訳)[ソフトバンク] 58 + 59 + カーネルは GNU C と GNU ツールチェインを使って書かれています。カーネル 60 + は ISO C89 仕様に準拠して書く一方で、標準には無い言語拡張を多く使って 61 + います。カーネルは標準 C ライブラリに依存しない、C 言語非依存環境です。 62 + そのため、C の標準の中で使えないものもあります。特に任意の long long 63 + の除算や浮動小数点は使えません。カーネルがツールチェインや C 言語拡張 64 + に置いている前提がどうなっているのかわかりにくいことが時々あり、また、 65 + 残念なことに決定的なリファレンスは存在しません。情報を得るには、gcc の 66 + info ページ( info gcc )を見てください。 67 + 68 + あなたは既存の開発コミュニティと一緒に作業する方法を学ぼうとしているこ 69 + とに思い出してください。そのコミュニティは、コーディング、スタイル、開 70 + 発手順について高度な標準を持つ、多様な人の集まりです。地理的に分散した 71 + 大規模なチームに対してもっともうまくいくとわかったことをベースにしなが 72 + ら、これらの標準は長い時間をかけて築かれてきました。これらはきちんと文 73 + 書化されていますから、事前にこれらの標準について事前にできるだけたくさ 74 + ん学んでください。また皆があなたやあなたの会社のやり方に合わせてくれる 75 + と思わないでください。 76 + 77 + 法的問題 78 + -------- 79 + 80 + Linux カーネルのソースコードは GPL ライセンスの下でリリースされていま 81 + す。ライセンスの詳細については、ソースツリーのメインディレクトリに存在 82 + する、COPYING のファイルを見てください。もしライセンスについてさらに質 83 + 問があれば、Linux Kernel メーリングリストに質問するのではなく、どうぞ 84 + 法律家に相談してください。メーリングリストの人達は法律家ではなく、法的 85 + 問題については彼らの声明はあてにするべきではありません。 86 + 87 + GPL に関する共通の質問や回答については、以下を参照してください- 88 + 89 + https://www.gnu.org/licenses/gpl-faq.html 90 + 91 + ドキュメント 92 + ------------ 93 + 94 + Linux カーネルソースツリーは幅広い範囲のドキュメントを含んでおり、それ 95 + らはカーネルコミュニティと会話する方法を学ぶのに非常に貴重なものです。 96 + 新しい機能がカーネルに追加される場合、その機能の使い方について説明した 97 + 新しいドキュメントファイルも追加することを勧めます。 98 + カーネルの変更が、カーネルがユーザ空間に公開しているインターフェイスの 99 + 変更を引き起こす場合、その変更を説明するマニュアルページのパッチや情報 100 + をマニュアルページのメンテナ mtk.manpages@gmail.com に送り、CC を 101 + linux-api@vger.kernel.org に送ることを勧めます。 102 + 103 + 以下はカーネルソースツリーに含まれている読んでおくべきファイルの一覧で 104 + す- 105 + 106 + README 107 + このファイルは Linuxカーネルの簡単な背景とカーネルを設定(訳注 108 + configure )し、生成(訳注 build )するために必要なことは何かが書かれ 109 + ています。 カーネルに関して初めての人はここからスタートすると良い 110 + でしょう。 111 + 112 + :ref:`Documentation/Process/changes.rst <changes>` 113 + このファイルはカーネルをうまく生成(訳注 build )し、走らせるのに最 114 + 小限のレベルで必要な数々のソフトウェアパッケージの一覧を示してい 115 + ます。 116 + 117 + :ref:`Documentation/process/coding-style.rst <codingstyle>` 118 + これは Linux カーネルのコーディングスタイルと背景にある理由を記述 119 + しています。全ての新しいコードはこのドキュメントにあるガイドライン 120 + に従っていることを期待されています。大部分のメンテナはこれらのルー 121 + ルに従っているものだけを受け付け、多くの人は正しいスタイルのコード 122 + だけをレビューします。 123 + 124 + :ref:`Documentation/process/submitting-patches.rst <codingstyle>` と :ref:`Documentation/process/submitting-drivers.rst <submittingdrivers>` 125 + これらのファイルには、どうやってうまくパッチを作って投稿するかにつ 126 + いて非常に詳しく書かれており、以下を含みます (これだけに限らない 127 + けれども) 128 + 129 + - Email に含むこと 130 + - Email の形式 131 + - だれに送るか 132 + 133 + これらのルールに従えばうまくいくことを保証することではありません 134 + が (すべてのパッチは内容とスタイルについて精査を受けるので)、 135 + ルールに従わなければ間違いなくうまくいかないでしょう。 136 + 137 + この他にパッチを作る方法についてのよくできた記述は- 138 + 139 + "The Perfect Patch" 140 + http://www.ozlabs.org/~akpm/stuff/tpp.txt 141 + "Linux kernel patch submission format" 142 + http://linux.yyz.us/patch-format.html 143 + 144 + :ref:`Documentation/process/stable-api-nonsense.rst <stable_api_nonsense>` 145 + このファイルはカーネルの中に不変の API を持たないことにした意識的 146 + な決断の背景にある理由について書かれています。以下のようなことを含 147 + んでいます- 148 + 149 + - サブシステムとの間に層を作ること(コンパチビリティのため?) 150 + - オペレーティングシステム間のドライバの移植性 151 + - カーネルソースツリーの素早い変更を遅らせる(もしくは素早い変更を妨げる) 152 + 153 + このドキュメントは Linux 開発の思想を理解するのに非常に重要です。 154 + そして、他のOSでの開発者が Linux に移る時にとても重要です。 155 + 156 + :ref:`Documentation/admin-guide/security-bugs.rst <securitybugs>` 157 + もし Linux カーネルでセキュリティ問題を発見したように思ったら、こ 158 + のドキュメントのステップに従ってカーネル開発者に連絡し、問題解決を 159 + 支援してください。 160 + 161 + :ref:`Documentation/process/management-style.rst <managementstyle>` 162 + このドキュメントは Linux カーネルのメンテナ達がどう行動するか、 163 + 彼らの手法の背景にある共有されている精神について記述しています。こ 164 + れはカーネル開発の初心者なら(もしくは、単に興味があるだけの人でも) 165 + 重要です。なぜならこのドキュメントは、カーネルメンテナ達の独特な 166 + 行動についての多くの誤解や混乱を解消するからです。 167 + 168 + :ref:`Documentation/process/stable-kernel-rules.rst <stable_kernel_rules>` 169 + このファイルはどのように stable カーネルのリリースが行われるかのルー 170 + ルが記述されています。そしてこれらのリリースの中のどこかで変更を取 171 + り入れてもらいたい場合に何をすれば良いかが示されています。 172 + 173 + :Ref:`Documentation/process/kernel-docs.rst <kernel_docs>` 174 + カーネル開発に付随する外部ドキュメントのリストです。もしあなたが探 175 + しているものがカーネル内のドキュメントでみつからなかった場合、この 176 + リストをあたってみてください。 177 + 178 + :ref:`Documentation/process/applying-patches.rst <applying_patches>` 179 + パッチとはなにか、パッチをどうやって様々なカーネルの開発ブランチに 180 + 適用するのかについて正確に記述した良い入門書です。 181 + 182 + カーネルはソースコードそのものや、このファイルのようなリストラクチャー 183 + ドテキストマークアップ(ReST)から自動的に生成可能な多数のドキュメントを 184 + もっています。これにはカーネル内APIの完全な記述や、正しくロックをかけ 185 + るための規則などが含まれます。 186 + 187 + これら全てのドキュメントを PDF や HTML で生成するには以下を実行します - :: 188 + 189 + make pdfdocs 190 + make htmldocs 191 + 192 + それぞれメインカーネルのソースディレクトリから実行します。 193 + 194 + ReSTマークアップを使ったドキュメントは Documentation/outputに生成され 195 + ます。Latex とePub 形式で生成するには - :: 196 + 197 + make latexdocs 198 + make epubdocs 199 + 200 + 現在、幾つかの DocBook形式で書かれたドキュメントは ReST形式に転換中で 201 + す。それらのドキュメントはDocumentation/DocBook ディレクトリに生成され、 202 + Postscript または man ページの形式を生成するには以下のようにします - :: 203 + 204 + make psdocs 205 + make mandocs 206 + 207 + カーネル開発者になるには 208 + ------------------------ 209 + 210 + もしあなたが、Linux カーネル開発について何も知らないのならば、 211 + KernelNewbies プロジェクトを見るべきです 212 + 213 + https://kernelnewbies.org 214 + 215 + このサイトには役に立つメーリングリストがあり、基本的なカーネル開発に関 216 + するほとんどどんな種類の質問もできます (既に回答されているようなことを 217 + 聞く前にまずはアーカイブを調べてください)。またここには、リアルタイム 218 + で質問を聞くことができる IRC チャネルや、Linuxカーネルの開発に関して学 219 + ぶのに便利なたくさんの役に立つドキュメントがあります。 220 + 221 + Web サイトには、コードの構成、サブシステム、現在存在するプロジェクト 222 + (ツリーにあるもの無いものの両方)の基本的な管理情報があります。ここには、 223 + また、カーネルのコンパイルのやり方やパッチの当て方などの間接的な基本情 224 + 報も記述されています。 225 + 226 + あなたがどこからスタートして良いかわからないが、Linux カーネル開発コミュ 227 + ニティに参加して何かすることをさがしているのであれば、Linux kernel 228 + Janitor's プロジェクトにいけば良いでしょう - 229 + 230 + https://kernelnewbies.org/KernelJanitors 231 + 232 + ここはそのようなスタートをするのにうってつけの場所です。ここには、 233 + Linux カーネルソースツリーの中に含まれる、きれいにし、修正しなければな 234 + らない、単純な問題のリストが記述されています。このプロジェクトに関わる 235 + 開発者と一緒に作業することで、あなたのパッチを Linuxカーネルツリーに入 236 + れるための基礎を学ぶことができ、そしてもしあなたがまだアイディアを持っ 237 + ていない場合には、次にやる仕事の方向性が見えてくるかもしれません。 238 + 239 + もしあなたが、すでにひとまとまりコードを書いていて、カーネルツリーに入 240 + れたいと思っていたり、それに関する適切な支援を求めたい場合、カーネルメ 241 + ンターズプロジェクトはそのような皆さんを助けるためにできました。ここに 242 + はメーリングリストがあり、以下から参照できます - 243 + 244 + https://selenic.com/mailman/listinfo/kernel-mentors 245 + 246 + 実際に Linux カーネルのコードについて修正を加える前に、どうやってその 247 + コードが動作するのかを理解することが必要です。そのためには、特別なツー 248 + ルの助けを借りてでも、それを直接よく読むことが最良の方法です(ほとんど 249 + のトリッキーな部分は十分にコメントしてありますから)。そういうツールで 250 + 特におすすめなのは、Linux クロスリファレンスプロジェクトです。これは、 251 + 自己参照方式で、索引がついた web 形式で、ソースコードを参照することが 252 + できます。この最新の素晴しいカーネルコードのリポジトリは以下で見つかり 253 + ます - 254 + 255 + http://lxr.free-electrons.com/ 256 + 257 + 開発プロセス 258 + ------------ 259 + 260 + Linux カーネルの開発プロセスは現在幾つかの異なるメインカーネル「ブラン 261 + チ」と多数のサブシステム毎のカーネルブランチから構成されます。これらの 262 + ブランチとは - 263 + 264 + - メインの 4.x カーネルツリー 265 + - 4.x.y -stable カーネルツリー 266 + - 4.x -git カーネルパッチ 267 + - サブシステム毎のカーネルツリーとパッチ 268 + - 統合テストのための 4.x -next カーネルツリー 269 + 270 + 4.x カーネルツリー 271 + ~~~~~~~~~~~~~~~~~~ 272 + 273 + 4.x カーネルは Linus Torvalds によってメンテナンスされ、 274 + https://kernel.org の pub/linux/kernel/v4.x/ ディレクトリに存在します。 275 + この開発プロセスは以下のとおり - 276 + 277 + - 新しいカーネルがリリースされた直後に、2週間の特別期間が設けられ、 278 + この期間中に、メンテナ達は Linus に大きな差分を送ることができます。 279 + このような差分は通常 -next カーネルに数週間含まれてきたパッチです。 280 + 大きな変更は git(カーネルのソース管理ツール、詳細は 281 + http://git-scm.com/ 参照) を使って送るのが好ましいやり方ですが、パッ 282 + チファイルの形式のまま送るのでも十分です。 283 + - 2週間後、-rc1 カーネルがリリースされ、この後にはカーネル全体の安定 284 + 性に影響をあたえるような新機能は含まない類のパッチしか取り込むこと 285 + はできません。新しいドライバ(もしくはファイルシステム)のパッチは 286 + -rc1 の後で受け付けられることもあることを覚えておいてください。な 287 + ぜなら、変更が独立していて、追加されたコードの外の領域に影響を与え 288 + ない限り、退行のリスクは無いからです。-rc1 がリリースされた後、 289 + Linus へパッチを送付するのに git を使うこともできますが、パッチは 290 + レビューのために、パブリックなメーリングリストへも同時に送る必要が 291 + あります。 292 + - 新しい -rc は Linus が、最新の git ツリーがテスト目的であれば十分 293 + に安定した状態にあると判断したときにリリースされます。目標は毎週新 294 + しい -rc カーネルをリリースすることです。 295 + - このプロセスはカーネルが 「準備ができた」と考えられるまで継続しま 296 + す。このプロセスはだいたい 6週間継続します。 297 + 298 + Andrew Morton が Linux-kernel メーリングリストにカーネルリリースについ 299 + て書いたことをここで言っておくことは価値があります - 300 + 301 + *「カーネルがいつリリースされるかは誰も知りません。なぜなら、 302 + これは現実に認識されたバグの状況によりリリースされるのであり、 303 + 前もって決められた計画によってリリースされるものではないから 304 + です。」* 305 + 306 + 4.x.y -stable カーネルツリー 307 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 308 + 309 + バージョン番号が3つの数字に分かれているカーネルは -stable カーネルです。 310 + これには、4.x カーネルで見つかったセキュリティ問題や重大な後戻りに対す 311 + る比較的小さい重要な修正が含まれます。 312 + 313 + これは、開発/実験的バージョンのテストに協力することに興味が無く、最新 314 + の安定したカーネルを使いたいユーザに推奨するブランチです。 315 + 316 + もし、4.x.y カーネルが存在しない場合には、番号が一番大きい 4.x が最新 317 + の安定版カーネルです。 318 + 319 + 4.x.y は "stable" チーム <stable@vger.kernel.org> でメンテされており、 320 + 必要に応じてリリースされます。通常のリリース期間は 2週間毎ですが、差 321 + し迫った問題がなければもう少し長くなることもあります。セキュリティ関 322 + 連の問題の場合はこれに対してだいたいの場合、すぐにリリースがされます。 323 + 324 + カーネルツリーに入っている、 325 + Documentation/process/stable-kernel-rules.rst ファイルにはどのような種 326 + 類の変更が -stable ツリーに受け入れ可能か、またリリースプロセスがどう 327 + 動くかが記述されています。 328 + 329 + 4.x -git パッチ 330 + ~~~~~~~~~~~~~~~ 331 + 332 + git リポジトリで管理されているLinus のカーネルツリーの毎日のスナップ 333 + ショットがあります。(だから -git という名前がついています)。これらのパッ 334 + チはおおむね毎日リリースされており、Linus のツリーの現状を表します。こ 335 + れは -rc カーネルと比べて、パッチが大丈夫かどうかも確認しないで自動的 336 + に生成されるので、より実験的です。 337 + 338 + サブシステム毎のカーネルツリーとパッチ 339 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 340 + 341 + それぞれのカーネルサブシステムのメンテナ達は --- そして多くのカーネル 342 + サブシステムの開発者達も --- 各自の最新の開発状況をソースリポジトリに 343 + 公開しています。そのため、自分とは異なる領域のカーネルで何が起きている 344 + かを他の人が見られるようになっています。開発が早く進んでいる領域では、 345 + 開発者は自身の投稿がどのサブシステムカーネルツリーを元にしているか質問 346 + されるので、その投稿とすでに進行中の他の作業との衝突が避けられます。 347 + 348 + 大部分のこれらのリポジトリは git ツリーです。しかしその他の SCM や 349 + quilt シリーズとして公開されているパッチキューも使われています。これら 350 + のサブシステムリポジトリのアドレスは MAINTAINERS ファイルにリストされ 351 + ています。これらの多くは https://git.kernel.org/ で参照することができま 352 + す。 353 + 354 + 提案されたパッチがこのようなサブシステムツリーにコミットされる前に、メー 355 + リングリストで事前にレビューにかけられます(以下の対応するセクションを 356 + 参照)。いくつかのカーネルサブシステムでは、このレビューは patchworkと 357 + いうツールによって追跡されます。Patchwork は web インターフェイスによっ 358 + てパッチ投稿の表示、パッチへのコメント付けや改訂などができ、そしてメン 359 + テナはパッチに対して、レビュー中、受付済み、拒否というようなマークをつ 360 + けることができます。大部分のこれらの patchwork のサイトは 361 + https://patchwork.kernel.org/ でリストされています。 362 + 363 + 統合テストのための 4.x -next カーネルツリー 364 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 365 + 366 + サブシステムツリーの更新内容がメインラインの 4.x ツリーにマージされる 367 + 前に、それらは統合テストされる必要があります。この目的のため、実質的に 368 + 全サブシステムツリーからほぼ毎日プルされてできる特別なテスト用のリポジ 369 + トリが存在します- 370 + 371 + https://git.kernel.org/?p=linux/kernel/git/next/linux-next.git 372 + 373 + このやり方によって、-next カーネルは次のマージ機会でどんなものがメイン 374 + ラインカーネルにマージされるか、おおまかなの展望を提供します。-next カー 375 + ネルの実行テストを行う冒険好きなテスターは大いに歓迎されます。 376 + 377 + バグレポート 378 + ------------- 379 + 380 + https://bugzilla.kernel.org は Linux カーネル開発者がカーネルのバグを追跡する 381 + 場所です。ユーザは見つけたバグの全てをこのツールで報告すべきです。どう 382 + kernel bugzilla を使うかの詳細は、以下を参照してください - 383 + 384 + https://bugzilla.kernel.org/page.cgi?id=faq.html 385 + 386 + メインカーネルソースディレクトリにあるファイル 387 + admin-guide/reporting-bugs.rstはカーネルバグらしいものについてどうレポー 388 + トするかの良いテンプレートであり、問題の追跡を助けるためにカーネル開発 389 + 者にとってどんな情報が必要なのかの詳細が書かれています。 390 + 391 + バグレポートの管理 392 + ------------------- 393 + 394 + あなたのハッキングのスキルを訓練する最高の方法のひとつに、他人がレポー 395 + トしたバグを修正することがあります。あなたがカーネルをより安定化させる 396 + こに寄与するということだけでなく、あなたは 現実の問題を修正することを 397 + 学び、自分のスキルも強化でき、また他の開発者があなたの存在に気がつきま 398 + す。バグを修正することは、多くの開発者の中から自分が功績をあげる最善の 399 + 道です、なぜなら多くの人は他人のバグの修正に時間を浪費することを好まな 400 + いからです。 401 + 402 + すでにレポートされたバグのために仕事をするためには、 403 + https://bugzilla.kernel.org に行ってください。もし今後のバグレポートに 404 + ついてアドバイスを受けたいのであれば、bugme-new メーリングリスト(新し 405 + いバグレポートだけがここにメールされる) または bugme-janitor メーリン 406 + グリスト(bugzilla の変更毎にここにメールされる)を購読できます。 407 + 408 + https://lists.linux-foundation.org/mailman/listinfo/bugme-new 409 + 410 + https://lists.linux-foundation.org/mailman/listinfo/bugme-janitors 411 + 412 + メーリングリスト 413 + ---------------- 414 + 415 + 上のいくつかのドキュメントで述べていますが、コアカーネル開発者の大部分 416 + は Linux kernel メーリングリストに参加しています。このリストの登録/脱 417 + 退の方法については以下を参照してください- 418 + 419 + http://vger.kernel.org/vger-lists.html#linux-kernel 420 + 421 + このメーリングリストのアーカイブは web 上の多数の場所に存在します。こ 422 + れらのアーカイブを探すにはサーチエンジンを使いましょう。例えば- 423 + 424 + http://dir.gmane.org/gmane.linux.kernel 425 + 426 + リストに投稿する前にすでにその話題がアーカイブに存在するかどうかを検索 427 + することを是非やってください。多数の事がすでに詳細に渡って議論されてお 428 + り、アーカイブにのみ記録されています。 429 + 430 + 大部分のカーネルサブシステムも自分の個別の開発を実施するメーリングリス 431 + トを持っています。個々のグループがどんなリストを持っているかは、 432 + MAINTAINERS ファイルにリストがありますので参照してください。 433 + 434 + 多くのリストは kernel.org でホストされています。これらの情報は以下にあ 435 + ります - 436 + 437 + http://vger.kernel.org/vger-lists.html 438 + 439 + メーリングリストを使う場合、良い行動習慣に従うようにしましょう。少し安っ 440 + ぽいが、以下の URL は上のリスト(や他のリスト)で会話する場合のシンプル 441 + なガイドラインを示しています - 442 + 443 + http://www.albion.com/netiquette/ 444 + 445 + もし複数の人があなたのメールに返事をした場合、CC: で受ける人のリストは 446 + だいぶ多くなるでしょう。正当な理由がない限り、CC: リストから誰かを削除 447 + をしないように、また、メーリングリストのアドレスだけにリプライすること 448 + のないようにしましょう。1つは送信者から、もう1つはリストからのように、 449 + メールを2回受けることになってもそれに慣れ、しゃれたメールヘッダーを追 450 + 加してこの状態を変えようとしないように。人々はそのようなことは好みませ 451 + ん。 452 + 453 + 今までのメールでのやりとりとその間のあなたの発言はそのまま残し、 454 + "John Kernelhacker wrote ...:" の行をあなたのリプライの先頭行にして、 455 + メールの先頭でなく、各引用行の間にあなたの言いたいことを追加するべきで 456 + す。 457 + 458 + もしパッチをメールに付ける場合は、 459 + Documentation/process/submitting-patches.rst に提示されているように、そ 460 + れは プレーンな可読テキストにすることを忘れないようにしましょう。カー 461 + ネル開発者は 添付や圧縮したパッチを扱いたがりません。彼らはあなたのパッ 462 + チの行毎にコメントを入れたいので、そうするしかありません。あなたのメー 463 + ルプログラムが空白やタブを圧縮しないように確認しましょう。最初の良いテ 464 + ストとしては、自分にメールを送ってみて、そのパッチを自分で当ててみるこ 465 + とです。もしそれがうまく行かないなら、あなたのメールプログラムを直して 466 + もらうか、正しく動くように変えるべきです。 467 + 468 + 何をおいても、他の購読者に対する敬意を表すことを忘れないでください。 469 + 470 + コミュニティと共に働くこと 471 + -------------------------- 472 + 473 + カーネルコミュニティのゴールは可能なかぎり最高のカーネルを提供すること 474 + です。あなたがパッチを受け入れてもらうために投稿した場合、それは、技術 475 + 的メリットだけがレビューされます。その際、あなたは何を予想すべきでしょ 476 + うか? 477 + 478 + - 批判 479 + - コメント 480 + - 変更の要求 481 + - パッチの正当性の証明要求 482 + - 沈黙 483 + 484 + 思い出してください、これはあなたのパッチをカーネルに入れる話です。あな 485 + たは、あなたのパッチに対する批判とコメントを受け入れるべきで、それらを 486 + 技術的レベルで評価して、パッチを再作成するか、なぜそれらの変更をすべき 487 + でないかを明確で簡潔な理由の説明を提供してください。もし、あなたのパッ 488 + チに何も反応がない場合、たまにはメールの山に埋もれて見逃され、あなたの 489 + 投稿が忘れられてしまうこともあるので、数日待って再度投稿してください。 490 + 491 + あなたがやるべきでないことは? 492 + 493 + - 質問なしにあなたのパッチが受け入れられると想像すること 494 + - 守りに入ること 495 + - コメントを無視すること 496 + - 要求された変更を何もしないでパッチを出し直すこと 497 + 498 + 可能な限り最高の技術的解決を求めているコミュニティでは、パッチがどのく 499 + らい有益なのかについては常に異なる意見があります。あなたは協調的である 500 + べきですし、また、あなたのアイディアをカーネルに対してうまく合わせるよ 501 + うにすることが望まれています。もしくは、最低限あなたのアイディアがそれ 502 + だけの価値があるとすすんで証明するようにしなければなりません。 503 + 正しい解決に向かって進もうという意志がある限り、間違うことがあっても許 504 + 容されることを忘れないでください。 505 + 506 + あなたの最初のパッチに単に 1ダースもの修正を求めるリストの返答になるこ 507 + とも普通のことです。これはあなたのパッチが受け入れられないということで 508 + は **ありません**、そしてあなた自身に反対することを意味するのでも **あ 509 + りません**。単に自分のパッチに対して指摘された問題を全て修正して再送す 510 + れば良いのです。 511 + 512 + 513 + カーネルコミュニティと企業組織のちがい 514 + ----------------------------------------------------------------- 515 + 516 + カーネルコミュニティは大部分の伝統的な会社の開発環境とは異ったやり方で 517 + 動いています。以下は問題を避けるためにできると良いことのリストです。 518 + 519 + あなたの提案する変更について言うときのうまい言い方 - 520 + 521 + - "これは複数の問題を解決します" 522 + - "これは2000行のコードを削除します" 523 + - "以下のパッチは、私が言おうとしていることを説明するものです" 524 + - "私はこれを5つの異なるアーキテクチャでテストしたのですが..." 525 + - "以下は一連の小さなパッチ群ですが..." 526 + - "これは典型的なマシンでの性能を向上させます..." 527 + 528 + やめた方が良い悪い言い方 - 529 + 530 + - "このやり方で AIX/ptx/Solaris ではできたので、できるはずだ..." 531 + - "私はこれを20年もの間やってきた、だから..." 532 + - "これは私の会社が金儲けをするために必要だ" 533 + - "これは我々のエンタープライズ向け商品ラインのためである" 534 + - "これは私が自分のアイディアを記述した、1000ページの設計資料である" 535 + - "私はこれについて、6ケ月作業している..." 536 + - "以下は ... に関する5000行のパッチです" 537 + - "私は現在のぐちゃぐちゃを全部書き直した、それが以下です..." 538 + - "私は〆切がある、そのためこのパッチは今すぐ適用される必要がある" 539 + 540 + カーネルコミュニティが大部分の伝統的なソフトウェアエンジニアリングの労 541 + 働環境と異なるもう一つの点は、やりとりに顔を合わせないということです。 542 + email と irc を第一のコミュニケーションの形とする一つの利点は、性別や 543 + 民族の差別がないことです。Linux カーネルの職場環境は女性や少数民族を受 544 + 容します。なぜなら、email アドレスによってのみあなたが認識されるからで 545 + す。 546 + 国際的な側面からも活動領域を均等にするようにします。なぜならば、あなた 547 + は人の名前で性別を想像できないからです。ある男性が アンドレアという名 548 + 前で、女性の名前は パット かもしれません (訳注 Andrea は米国では女性、 549 + それ以外(欧州など)では男性名として使われることが多い。同様に、Pat は 550 + Patricia (主に女性名)や Patrick (主に男性名)の略称)。 551 + Linux カーネルの活動をして、意見を表明したことがある大部分の女性は、前 552 + 向きな経験をもっています。 553 + 554 + 言葉の壁は英語が得意でない一部の人には問題になります。メーリングリスト 555 + の中で、きちんとアイディアを交換するには、相当うまく英語を操れる必要が 556 + あることもあります。そのため、自分のメールを送る前に英語で意味が通じて 557 + いるかをチェックすることをお薦めします。 558 + 559 + 変更を分割する 560 + -------------- 561 + 562 + Linux カーネルコミュニティは、一度に大量のコードの塊を喜んで受容するこ 563 + とはありません。変更は正確に説明される必要があり、議論され、小さい、個 564 + 別の部分に分割する必要があります。これはこれまで多くの会社がやり慣れて 565 + きたことと全く正反対のことです。あなたのプロポーザルは、開発プロセスのと 566 + ても早い段階から紹介されるべきです。そうすれば あなたは自分のやってい 567 + ることにフィードバックを得られます。これは、コミュニティからみれば、あ 568 + なたが彼らと一緒にやっているように感じられ、単にあなたの提案する機能の 569 + ゴミ捨て場として使っているのではない、と感じられるでしょう。 570 + しかし、一度に 50 もの email をメーリングリストに送りつけるようなことは 571 + やってはいけません、あなたのパッチ群はいつもどんな時でもそれよりは小さ 572 + くなければなりません。 573 + 574 + パッチを分割する理由は以下 - 575 + 576 + 1) 小さいパッチはあなたのパッチが適用される見込みを大きくします、カー 577 + ネルの人達はパッチが正しいかどうかを確認する時間や労力をかけないか 578 + らです。5行のパッチはメンテナがたった1秒見るだけで適用できます。 579 + しかし、500行のパッチは、正しいことをレビューするのに数時間かかるか 580 + もしれません(時間はパッチのサイズなどにより指数関数に比例してかかり 581 + ます) 582 + 583 + 小さいパッチは何かあったときにデバッグもとても簡単になります。パッ 584 + チを1個1個取り除くのは、とても大きなパッチを当てた後に(かつ、何かお 585 + かしくなった後で)解剖するのに比べればとても簡単です。 586 + 587 + 2) 小さいパッチを送るだけでなく、送るまえに、書き直して、シンプルにす 588 + る(もしくは、単に順番を変えるだけでも)ことも、とても重要です。 589 + 590 + 以下はカーネル開発者の Al Viro のたとえ話です - 591 + 592 + *"生徒の数学の宿題を採点する先生のことを考えてみてください、 593 + 先生は生徒が解に到達するまでの試行錯誤を見たいとは思わないでし 594 + ょう。先生は簡潔な最高の解を見たいのです。良い生徒はこれを知っ 595 + ており、そして最終解の前の中間作業を提出することは決してないの 596 + です* 597 + 598 + *カーネル開発でもこれは同じです。メンテナ達とレビューア達は、 599 + 問題を解決する解の背後になる思考プロセスを見たいとは思いません。 600 + 彼らは単純であざやかな解決方法を見たいのです。"* 601 + 602 + あざやかな解を説明するのと、コミュニティと共に仕事をし、未解決の仕事を 603 + 議論することのバランスをキープするのは難しいかもしれません。ですから、 604 + 開発プロセスの早期段階で改善のためのフィードバックをもらうようにするの 605 + も良いですが、変更点を小さい部分に分割して全体ではまだ完成していない仕 606 + 事を(部分的に)取り込んでもらえるようにすることも良いことです。 607 + 608 + また、でき上がっていないものや、"将来直す" ようなパッチを、本流に含め 609 + てもらうように送っても、それは受け付けられないことを理解してください。 610 + 611 + あなたの変更を正当化する 612 + ------------------------ 613 + 614 + あなたのパッチを分割するのと同時に、なぜその変更を追加しなければならな 615 + いかを Linux コミュニティに知らせることはとても重要です。新機能は必要 616 + 性と有用性で正当化されなければなりません。 617 + 618 + あなたの変更を説明する 619 + ---------------------- 620 + 621 + あなたのパッチを送付する場合には、メールの中のテキストで何を言うかにつ 622 + いて、特別に注意を払ってください。この情報はパッチの ChangeLog に使わ 623 + れ、いつも皆がみられるように保管されます。これは次のような項目を含め、 624 + パッチを完全に記述するべきです - 625 + 626 + - なぜ変更が必要か 627 + - パッチ全体の設計アプローチ 628 + - 実装の詳細 629 + - テスト結果 630 + 631 + これについて全てがどのようにあるべきかについての詳細は、以下のドキュメ 632 + ントの ChangeLog セクションを見てください - 633 + 634 + "The Perfect Patch" 635 + http://www.ozlabs.org/~akpm/stuff/tpp.txt 636 + 637 + これらはどれも、実行することが時にはとても困難です。これらの例を完璧に 638 + 実施するには数年かかるかもしれません。これは継続的な改善のプロセスであ 639 + り、多くの忍耐と決意を必要とするものです。でも諦めないで、実現は可能で 640 + す。多数の人がすでにできていますし、彼らも最初はあなたと同じところから 641 + スタートしたのですから。 642 + 643 + 644 + 645 + 646 + ---------- 647 + 648 + Paolo Ciarrocchi に感謝、彼は彼の書いた "Development Process" 649 + (https://lwn.net/Articles/94386/) セクションをこのテキストの原型にする 650 + ことを許可してくれました。Rundy Dunlap と Gerrit Huizenga はメーリング 651 + リストでやるべきこととやってはいけないことのリストを提供してくれました。 652 + 以下の人々のレビュー、コメント、貢献に感謝。 653 + Pat Mochel, Hanna Linder, Randy Dunlap, Kay Sievers, 654 + Vojtech Pavlik, Jan Kara, Josh Boyer, Kees Cook, Andrew Morton, Andi 655 + Kleen, Vadim Lobanov, Jesper Juhl, Adrian Bunk, Keri Harris, Frans Pop, 656 + David A. Wheeler, Junio Hamano, Michael Kerrisk, と Alex Shepard 657 + 彼らの支援なしでは、このドキュメントはできなかったでしょう。 658 + 659 + 660 + 661 + Maintainer: Greg Kroah-Hartman <greg@kroah.com>
+12
Documentation/translations/ja_JP/index.rst
··· 1 + .. raw:: latex 2 + 3 + \renewcommand\thesection* 4 + \renewcommand\thesubsection* 5 + 6 + Japanese translations 7 + ===================== 8 + 9 + .. toctree:: 10 + :maxdepth: 1 11 + 12 + howto
+2 -2
Documentation/translations/zh_CN/sparse.txt
··· 1 - Chinese translated version of Documentation/sparse.txt 1 + Chinese translated version of Documentation/dev-tools/sparse.rst 2 2 3 3 If you have any comment or update to the content, please contact the 4 4 original document maintainer directly. However, if you have a problem ··· 8 8 9 9 Chinese maintainer: Li Yang <leo@zh-kernel.org> 10 10 --------------------------------------------------------------------- 11 - Documentation/sparse.txt 的中文翻译 11 + Documentation/dev-tools/sparse.rst 的中文翻译 12 12 13 13 如果想评论或更新本文的内容,请直接联系原文档的维护者。如果你使用英文 14 14 交流有困难的话,也可以向中文版维护者求助。如果本翻译更新不及时或者翻
+115 -78
Documentation/unshare.txt Documentation/userspace-api/unshare.rst
··· 1 + unshare system call 2 + =================== 1 3 2 - unshare system call: 3 - -------------------- 4 - This document describes the new system call, unshare. The document 4 + This document describes the new system call, unshare(). The document 5 5 provides an overview of the feature, why it is needed, how it can 6 6 be used, its interface specification, design, implementation and 7 7 how it can be tested. 8 8 9 - Change Log: 10 - ----------- 9 + Change Log 10 + ---------- 11 11 version 0.1 Initial document, Janak Desai (janak@us.ibm.com), Jan 11, 2006 12 12 13 - Contents: 14 - --------- 13 + Contents 14 + -------- 15 15 1) Overview 16 16 2) Benefits 17 17 3) Cost ··· 24 24 25 25 1) Overview 26 26 ----------- 27 + 27 28 Most legacy operating system kernels support an abstraction of threads 28 29 as multiple execution contexts within a process. These kernels provide 29 30 special resources and mechanisms to maintain these "threads". The Linux ··· 39 38 call, applications can selectively choose which resources to share 40 39 between threads. 41 40 42 - unshare system call adds a primitive to the Linux thread model that 41 + unshare() system call adds a primitive to the Linux thread model that 43 42 allows threads to selectively 'unshare' any resources that were being 44 - shared at the time of their creation. unshare was conceptualized by 43 + shared at the time of their creation. unshare() was conceptualized by 45 44 Al Viro in the August of 2000, on the Linux-Kernel mailing list, as part 46 - of the discussion on POSIX threads on Linux. unshare augments the 45 + of the discussion on POSIX threads on Linux. unshare() augments the 47 46 usefulness of Linux threads for applications that would like to control 48 - shared resources without creating a new process. unshare is a natural 47 + shared resources without creating a new process. unshare() is a natural 49 48 addition to the set of available primitives on Linux that implement 50 49 the concept of process/thread as a virtual machine. 51 50 52 51 2) Benefits 53 52 ----------- 54 - unshare would be useful to large application frameworks such as PAM 53 + 54 + unshare() would be useful to large application frameworks such as PAM 55 55 where creating a new process to control sharing/unsharing of process 56 56 resources is not possible. Since namespaces are shared by default 57 - when creating a new process using fork or clone, unshare can benefit 57 + when creating a new process using fork or clone, unshare() can benefit 58 58 even non-threaded applications if they have a need to disassociate 59 59 from default shared namespace. The following lists two use-cases 60 - where unshare can be used. 60 + where unshare() can be used. 61 61 62 62 2.1 Per-security context namespaces 63 - ----------------------------------- 64 - unshare can be used to implement polyinstantiated directories using 63 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 64 + 65 + unshare() can be used to implement polyinstantiated directories using 65 66 the kernel's per-process namespace mechanism. Polyinstantiated directories, 66 67 such as per-user and/or per-security context instance of /tmp, /var/tmp or 67 68 per-security context instance of a user's home directory, isolate user 68 - processes when working with these directories. Using unshare, a PAM 69 + processes when working with these directories. Using unshare(), a PAM 69 70 module can easily setup a private namespace for a user at login. 70 71 Polyinstantiated directories are required for Common Criteria certification 71 72 with Labeled System Protection Profile, however, with the availability ··· 77 74 appropriate by system administrators. 78 75 79 76 2.2 unsharing of virtual memory and/or open files 80 - ------------------------------------------------- 77 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 78 + 81 79 Consider a client/server application where the server is processing 82 80 client requests by creating processes that share resources such as 83 - virtual memory and open files. Without unshare, the server has to 81 + virtual memory and open files. Without unshare(), the server has to 84 82 decide what needs to be shared at the time of creating the process 85 - which services the request. unshare allows the server an ability to 83 + which services the request. unshare() allows the server an ability to 86 84 disassociate parts of the context during the servicing of the 87 85 request. For large and complex middleware application frameworks, this 88 - ability to unshare after the process was created can be very 86 + ability to unshare() after the process was created can be very 89 87 useful. 90 88 91 89 3) Cost 92 90 ------- 93 - In order to not duplicate code and to handle the fact that unshare 91 + 92 + In order to not duplicate code and to handle the fact that unshare() 94 93 works on an active task (as opposed to clone/fork working on a newly 95 - allocated inactive task) unshare had to make minor reorganizational 94 + allocated inactive task) unshare() had to make minor reorganizational 96 95 changes to copy_* functions utilized by clone/fork system call. 97 96 There is a cost associated with altering existing, well tested and 98 97 stable code to implement a new feature that may not get exercised 99 98 extensively in the beginning. However, with proper design and code 100 - review of the changes and creation of an unshare test for the LTP 99 + review of the changes and creation of an unshare() test for the LTP 101 100 the benefits of this new feature can exceed its cost. 102 101 103 102 4) Requirements 104 103 --------------- 105 - unshare reverses sharing that was done using clone(2) system call, 106 - so unshare should have a similar interface as clone(2). That is, 104 + 105 + unshare() reverses sharing that was done using clone(2) system call, 106 + so unshare() should have a similar interface as clone(2). That is, 107 107 since flags in clone(int flags, void *stack) specifies what should 108 108 be shared, similar flags in unshare(int flags) should specify 109 109 what should be unshared. Unfortunately, this may appear to invert ··· 114 108 However, there was no easy solution that was less confusing and that 115 109 allowed incremental context unsharing in future without an ABI change. 116 110 117 - unshare interface should accommodate possible future addition of 111 + unshare() interface should accommodate possible future addition of 118 112 new context flags without requiring a rebuild of old applications. 119 - If and when new context flags are added, unshare design should allow 113 + If and when new context flags are added, unshare() design should allow 120 114 incremental unsharing of those resources on an as needed basis. 121 115 122 116 5) Functional Specification 123 117 --------------------------- 118 + 124 119 NAME 125 120 unshare - disassociate parts of the process execution context 126 121 ··· 131 124 int unshare(int flags); 132 125 133 126 DESCRIPTION 134 - unshare allows a process to disassociate parts of its execution 127 + unshare() allows a process to disassociate parts of its execution 135 128 context that are currently being shared with other processes. Part 136 129 of execution context, such as the namespace, is shared by default 137 130 when a new process is created using fork(2), while other parts, ··· 139 132 shared by explicit request to share them when creating a process 140 133 using clone(2). 141 134 142 - The main use of unshare is to allow a process to control its 135 + The main use of unshare() is to allow a process to control its 143 136 shared execution context without creating a new process. 144 137 145 138 The flags argument specifies one or bitwise-or'ed of several of ··· 183 176 184 177 6) High Level Design 185 178 -------------------- 186 - Depending on the flags argument, the unshare system call allocates 179 + 180 + Depending on the flags argument, the unshare() system call allocates 187 181 appropriate process context structures, populates it with values from 188 182 the current shared version, associates newly duplicated structures 189 183 with the current task structure and releases corresponding shared 190 184 versions. Helper functions of clone (copy_*) could not be used 191 - directly by unshare because of the following two reasons. 185 + directly by unshare() because of the following two reasons. 186 + 192 187 1) clone operates on a newly allocated not-yet-active task 193 - structure, where as unshare operates on the current active 194 - task. Therefore unshare has to take appropriate task_lock() 188 + structure, where as unshare() operates on the current active 189 + task. Therefore unshare() has to take appropriate task_lock() 195 190 before associating newly duplicated context structures 196 - 2) unshare has to allocate and duplicate all context structures 191 + 192 + 2) unshare() has to allocate and duplicate all context structures 197 193 that are being unshared, before associating them with the 198 194 current task and releasing older shared structures. Failure 199 195 do so will create race conditions and/or oops when trying ··· 212 202 current context structure was moved into new dup_* functions. Now, 213 203 copy_* functions call dup_* functions to allocate and duplicate 214 204 appropriate context structures and then associate them with the 215 - task structure that is being constructed. unshare system call on 205 + task structure that is being constructed. unshare() system call on 216 206 the other hand performs the following: 207 + 217 208 1) Check flags to force missing, but implied, flags 218 - 2) For each context structure, call the corresponding unshare 209 + 210 + 2) For each context structure, call the corresponding unshare() 219 211 helper function to allocate and duplicate a new context 220 212 structure, if the appropriate bit is set in the flags argument. 213 + 221 214 3) If there is no error in allocation and duplication and there 222 215 are new context structures then lock the current task structure, 223 216 associate new context structures with the current task structure, 224 217 and release the lock on the current task structure. 218 + 225 219 4) Appropriately release older, shared, context structures. 226 220 227 221 7) Low Level Design 228 222 ------------------- 229 - Implementation of unshare can be grouped in the following 4 different 223 + 224 + Implementation of unshare() can be grouped in the following 4 different 230 225 items: 226 + 231 227 a) Reorganization of existing copy_* functions 232 - b) unshare system call service function 233 - c) unshare helper functions for each different process context 228 + 229 + b) unshare() system call service function 230 + 231 + c) unshare() helper functions for each different process context 232 + 234 233 d) Registration of system call number for different architectures 235 234 236 - 7.1) Reorganization of copy_* functions 237 - Each copy function such as copy_mm, copy_namespace, copy_files, 238 - etc, had roughly two components. The first component allocated 239 - and duplicated the appropriate structure and the second component 240 - linked it to the task structure passed in as an argument to the copy 241 - function. The first component was split into its own function. 242 - These dup_* functions allocated and duplicated the appropriate 243 - context structure. The reorganized copy_* functions invoked 244 - their corresponding dup_* functions and then linked the newly 245 - duplicated structures to the task structure with which the 246 - copy function was called. 235 + 7.1) Reorganization of copy_* functions 236 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 247 237 248 - 7.2) unshare system call service function 238 + Each copy function such as copy_mm, copy_namespace, copy_files, 239 + etc, had roughly two components. The first component allocated 240 + and duplicated the appropriate structure and the second component 241 + linked it to the task structure passed in as an argument to the copy 242 + function. The first component was split into its own function. 243 + These dup_* functions allocated and duplicated the appropriate 244 + context structure. The reorganized copy_* functions invoked 245 + their corresponding dup_* functions and then linked the newly 246 + duplicated structures to the task structure with which the 247 + copy function was called. 248 + 249 + 7.2) unshare() system call service function 250 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 251 + 249 252 * Check flags 250 253 Force implied flags. If CLONE_THREAD is set force CLONE_VM. 251 254 If CLONE_VM is set, force CLONE_SIGHAND. If CLONE_SIGHAND is 252 255 set and signals are also being shared, force CLONE_THREAD. If 253 256 CLONE_NEWNS is set, force CLONE_FS. 257 + 254 258 * For each context flag, invoke the corresponding unshare_* 255 259 helper routine with flags passed into the system call and a 256 260 reference to pointer pointing the new unshared structure 261 + 257 262 * If any new structures are created by unshare_* helper 258 263 functions, take the task_lock() on the current task, 259 264 modify appropriate context pointers, and release the 260 265 task lock. 266 + 261 267 * For all newly unshared structures, release the corresponding 262 268 older, shared, structures. 263 269 264 - 7.3) unshare_* helper functions 265 - For unshare_* helpers corresponding to CLONE_SYSVSEM, CLONE_SIGHAND, 266 - and CLONE_THREAD, return -EINVAL since they are not implemented yet. 267 - For others, check the flag value to see if the unsharing is 268 - required for that structure. If it is, invoke the corresponding 269 - dup_* function to allocate and duplicate the structure and return 270 - a pointer to it. 270 + 7.3) unshare_* helper functions 271 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 271 272 272 - 7.4) Appropriately modify architecture specific code to register the 273 - new system call. 273 + For unshare_* helpers corresponding to CLONE_SYSVSEM, CLONE_SIGHAND, 274 + and CLONE_THREAD, return -EINVAL since they are not implemented yet. 275 + For others, check the flag value to see if the unsharing is 276 + required for that structure. If it is, invoke the corresponding 277 + dup_* function to allocate and duplicate the structure and return 278 + a pointer to it. 279 + 280 + 7.4) Finally 281 + ~~~~~~~~~~~~ 282 + 283 + Appropriately modify architecture specific code to register the 284 + new system call. 274 285 275 286 8) Test Specification 276 287 --------------------- 277 - The test for unshare should test the following: 288 + 289 + The test for unshare() should test the following: 290 + 278 291 1) Valid flags: Test to check that clone flags for signal and 279 - signal handlers, for which unsharing is not implemented 280 - yet, return -EINVAL. 292 + signal handlers, for which unsharing is not implemented 293 + yet, return -EINVAL. 294 + 281 295 2) Missing/implied flags: Test to make sure that if unsharing 282 - namespace without specifying unsharing of filesystem, correctly 283 - unshares both namespace and filesystem information. 296 + namespace without specifying unsharing of filesystem, correctly 297 + unshares both namespace and filesystem information. 298 + 284 299 3) For each of the four (namespace, filesystem, files and vm) 285 - supported unsharing, verify that the system call correctly 286 - unshares the appropriate structure. Verify that unsharing 287 - them individually as well as in combination with each 288 - other works as expected. 300 + supported unsharing, verify that the system call correctly 301 + unshares the appropriate structure. Verify that unsharing 302 + them individually as well as in combination with each 303 + other works as expected. 304 + 289 305 4) Concurrent execution: Use shared memory segments and futex on 290 - an address in the shm segment to synchronize execution of 291 - about 10 threads. Have a couple of threads execute execve, 292 - a couple _exit and the rest unshare with different combination 293 - of flags. Verify that unsharing is performed as expected and 294 - that there are no oops or hangs. 306 + an address in the shm segment to synchronize execution of 307 + about 10 threads. Have a couple of threads execute execve, 308 + a couple _exit and the rest unshare with different combination 309 + of flags. Verify that unsharing is performed as expected and 310 + that there are no oops or hangs. 295 311 296 312 9) Future Work 297 313 -------------- 298 - The current implementation of unshare does not allow unsharing of 314 + 315 + The current implementation of unshare() does not allow unsharing of 299 316 signals and signal handlers. Signals are complex to begin with and 300 317 to unshare signals and/or signal handlers of a currently running 301 318 process is even more complex. If in the future there is a specific 302 319 need to allow unsharing of signals and/or signal handlers, it can 303 - be incrementally added to unshare without affecting legacy 304 - applications using unshare. 320 + be incrementally added to unshare() without affecting legacy 321 + applications using unshare(). 305 322
-261
Documentation/usb/URB.txt
··· 1 - Revised: 2000-Dec-05. 2 - Again: 2002-Jul-06 3 - Again: 2005-Sep-19 4 - 5 - NOTE: 6 - 7 - The USB subsystem now has a substantial section in "The Linux Kernel API" 8 - guide (in Documentation/DocBook), generated from the current source 9 - code. This particular documentation file isn't particularly current or 10 - complete; don't rely on it except for a quick overview. 11 - 12 - 13 - 1.1. Basic concept or 'What is an URB?' 14 - 15 - The basic idea of the new driver is message passing, the message itself is 16 - called USB Request Block, or URB for short. 17 - 18 - - An URB consists of all relevant information to execute any USB transaction 19 - and deliver the data and status back. 20 - 21 - - Execution of an URB is inherently an asynchronous operation, i.e. the 22 - usb_submit_urb(urb) call returns immediately after it has successfully 23 - queued the requested action. 24 - 25 - - Transfers for one URB can be canceled with usb_unlink_urb(urb) at any time. 26 - 27 - - Each URB has a completion handler, which is called after the action 28 - has been successfully completed or canceled. The URB also contains a 29 - context-pointer for passing information to the completion handler. 30 - 31 - - Each endpoint for a device logically supports a queue of requests. 32 - You can fill that queue, so that the USB hardware can still transfer 33 - data to an endpoint while your driver handles completion of another. 34 - This maximizes use of USB bandwidth, and supports seamless streaming 35 - of data to (or from) devices when using periodic transfer modes. 36 - 37 - 38 - 1.2. The URB structure 39 - 40 - Some of the fields in an URB are: 41 - 42 - struct urb 43 - { 44 - // (IN) device and pipe specify the endpoint queue 45 - struct usb_device *dev; // pointer to associated USB device 46 - unsigned int pipe; // endpoint information 47 - 48 - unsigned int transfer_flags; // ISO_ASAP, SHORT_NOT_OK, etc. 49 - 50 - // (IN) all urbs need completion routines 51 - void *context; // context for completion routine 52 - void (*complete)(struct urb *); // pointer to completion routine 53 - 54 - // (OUT) status after each completion 55 - int status; // returned status 56 - 57 - // (IN) buffer used for data transfers 58 - void *transfer_buffer; // associated data buffer 59 - int transfer_buffer_length; // data buffer length 60 - int number_of_packets; // size of iso_frame_desc 61 - 62 - // (OUT) sometimes only part of CTRL/BULK/INTR transfer_buffer is used 63 - int actual_length; // actual data buffer length 64 - 65 - // (IN) setup stage for CTRL (pass a struct usb_ctrlrequest) 66 - unsigned char* setup_packet; // setup packet (control only) 67 - 68 - // Only for PERIODIC transfers (ISO, INTERRUPT) 69 - // (IN/OUT) start_frame is set unless ISO_ASAP isn't set 70 - int start_frame; // start frame 71 - int interval; // polling interval 72 - 73 - // ISO only: packets are only "best effort"; each can have errors 74 - int error_count; // number of errors 75 - struct usb_iso_packet_descriptor iso_frame_desc[0]; 76 - }; 77 - 78 - Your driver must create the "pipe" value using values from the appropriate 79 - endpoint descriptor in an interface that it's claimed. 80 - 81 - 82 - 1.3. How to get an URB? 83 - 84 - URBs are allocated with the following call 85 - 86 - struct urb *usb_alloc_urb(int isoframes, int mem_flags) 87 - 88 - Return value is a pointer to the allocated URB, 0 if allocation failed. 89 - The parameter isoframes specifies the number of isochronous transfer frames 90 - you want to schedule. For CTRL/BULK/INT, use 0. The mem_flags parameter 91 - holds standard memory allocation flags, letting you control (among other 92 - things) whether the underlying code may block or not. 93 - 94 - To free an URB, use 95 - 96 - void usb_free_urb(struct urb *urb) 97 - 98 - You may free an urb that you've submitted, but which hasn't yet been 99 - returned to you in a completion callback. It will automatically be 100 - deallocated when it is no longer in use. 101 - 102 - 103 - 1.4. What has to be filled in? 104 - 105 - Depending on the type of transaction, there are some inline functions 106 - defined in <linux/usb.h> to simplify the initialization, such as 107 - fill_control_urb() and fill_bulk_urb(). In general, they need the usb 108 - device pointer, the pipe (usual format from usb.h), the transfer buffer, 109 - the desired transfer length, the completion handler, and its context. 110 - Take a look at the some existing drivers to see how they're used. 111 - 112 - Flags: 113 - For ISO there are two startup behaviors: Specified start_frame or ASAP. 114 - For ASAP set URB_ISO_ASAP in transfer_flags. 115 - 116 - If short packets should NOT be tolerated, set URB_SHORT_NOT_OK in 117 - transfer_flags. 118 - 119 - 120 - 1.5. How to submit an URB? 121 - 122 - Just call 123 - 124 - int usb_submit_urb(struct urb *urb, int mem_flags) 125 - 126 - The mem_flags parameter, such as SLAB_ATOMIC, controls memory allocation, 127 - such as whether the lower levels may block when memory is tight. 128 - 129 - It immediately returns, either with status 0 (request queued) or some 130 - error code, usually caused by the following: 131 - 132 - - Out of memory (-ENOMEM) 133 - - Unplugged device (-ENODEV) 134 - - Stalled endpoint (-EPIPE) 135 - - Too many queued ISO transfers (-EAGAIN) 136 - - Too many requested ISO frames (-EFBIG) 137 - - Invalid INT interval (-EINVAL) 138 - - More than one packet for INT (-EINVAL) 139 - 140 - After submission, urb->status is -EINPROGRESS; however, you should never 141 - look at that value except in your completion callback. 142 - 143 - For isochronous endpoints, your completion handlers should (re)submit 144 - URBs to the same endpoint with the ISO_ASAP flag, using multi-buffering, 145 - to get seamless ISO streaming. 146 - 147 - 148 - 1.6. How to cancel an already running URB? 149 - 150 - There are two ways to cancel an URB you've submitted but which hasn't 151 - been returned to your driver yet. For an asynchronous cancel, call 152 - 153 - int usb_unlink_urb(struct urb *urb) 154 - 155 - It removes the urb from the internal list and frees all allocated 156 - HW descriptors. The status is changed to reflect unlinking. Note 157 - that the URB will not normally have finished when usb_unlink_urb() 158 - returns; you must still wait for the completion handler to be called. 159 - 160 - To cancel an URB synchronously, call 161 - 162 - void usb_kill_urb(struct urb *urb) 163 - 164 - It does everything usb_unlink_urb does, and in addition it waits 165 - until after the URB has been returned and the completion handler 166 - has finished. It also marks the URB as temporarily unusable, so 167 - that if the completion handler or anyone else tries to resubmit it 168 - they will get a -EPERM error. Thus you can be sure that when 169 - usb_kill_urb() returns, the URB is totally idle. 170 - 171 - There is a lifetime issue to consider. An URB may complete at any 172 - time, and the completion handler may free the URB. If this happens 173 - while usb_unlink_urb or usb_kill_urb is running, it will cause a 174 - memory-access violation. The driver is responsible for avoiding this, 175 - which often means some sort of lock will be needed to prevent the URB 176 - from being deallocated while it is still in use. 177 - 178 - On the other hand, since usb_unlink_urb may end up calling the 179 - completion handler, the handler must not take any lock that is held 180 - when usb_unlink_urb is invoked. The general solution to this problem 181 - is to increment the URB's reference count while holding the lock, then 182 - drop the lock and call usb_unlink_urb or usb_kill_urb, and then 183 - decrement the URB's reference count. You increment the reference 184 - count by calling 185 - 186 - struct urb *usb_get_urb(struct urb *urb) 187 - 188 - (ignore the return value; it is the same as the argument) and 189 - decrement the reference count by calling usb_free_urb. Of course, 190 - none of this is necessary if there's no danger of the URB being freed 191 - by the completion handler. 192 - 193 - 194 - 1.7. What about the completion handler? 195 - 196 - The handler is of the following type: 197 - 198 - typedef void (*usb_complete_t)(struct urb *) 199 - 200 - I.e., it gets the URB that caused the completion call. In the completion 201 - handler, you should have a look at urb->status to detect any USB errors. 202 - Since the context parameter is included in the URB, you can pass 203 - information to the completion handler. 204 - 205 - Note that even when an error (or unlink) is reported, data may have been 206 - transferred. That's because USB transfers are packetized; it might take 207 - sixteen packets to transfer your 1KByte buffer, and ten of them might 208 - have transferred successfully before the completion was called. 209 - 210 - 211 - NOTE: ***** WARNING ***** 212 - NEVER SLEEP IN A COMPLETION HANDLER. These are often called in atomic 213 - context. 214 - 215 - In the current kernel, completion handlers run with local interrupts 216 - disabled, but in the future this will be changed, so don't assume that 217 - local IRQs are always disabled inside completion handlers. 218 - 219 - 1.8. How to do isochronous (ISO) transfers? 220 - 221 - For ISO transfers you have to fill a usb_iso_packet_descriptor structure, 222 - allocated at the end of the URB by usb_alloc_urb(n,mem_flags), for each 223 - packet you want to schedule. You also have to set urb->interval to say 224 - how often to make transfers; it's often one per frame (which is once 225 - every microframe for highspeed devices). The actual interval used will 226 - be a power of two that's no bigger than what you specify. 227 - 228 - The usb_submit_urb() call modifies urb->interval to the implemented interval 229 - value that is less than or equal to the requested interval value. If 230 - ISO_ASAP scheduling is used, urb->start_frame is also updated. 231 - 232 - For each entry you have to specify the data offset for this frame (base is 233 - transfer_buffer), and the length you want to write/expect to read. 234 - After completion, actual_length contains the actual transferred length and 235 - status contains the resulting status for the ISO transfer for this frame. 236 - It is allowed to specify a varying length from frame to frame (e.g. for 237 - audio synchronisation/adaptive transfer rates). You can also use the length 238 - 0 to omit one or more frames (striping). 239 - 240 - For scheduling you can choose your own start frame or ISO_ASAP. As explained 241 - earlier, if you always keep at least one URB queued and your completion 242 - keeps (re)submitting a later URB, you'll get smooth ISO streaming (if usb 243 - bandwidth utilization allows). 244 - 245 - If you specify your own start frame, make sure it's several frames in advance 246 - of the current frame. You might want this model if you're synchronizing 247 - ISO data with some other event stream. 248 - 249 - 250 - 1.9. How to start interrupt (INT) transfers? 251 - 252 - Interrupt transfers, like isochronous transfers, are periodic, and happen 253 - in intervals that are powers of two (1, 2, 4 etc) units. Units are frames 254 - for full and low speed devices, and microframes for high speed ones. 255 - The usb_submit_urb() call modifies urb->interval to the implemented interval 256 - value that is less than or equal to the requested interval value. 257 - 258 - In Linux 2.6, unlike earlier versions, interrupt URBs are not automagically 259 - restarted when they complete. They end when the completion handler is 260 - called, just like other URBs. If you want an interrupt URB to be restarted, 261 - your completion handler must resubmit it.
+1 -1
Documentation/usb/acm.txt
··· 64 64 65 65 2. Verifying that it works 66 66 ~~~~~~~~~~~~~~~~~~~~~~~~~~ 67 - The first step would be to check /proc/bus/usb/devices, it should look 67 + The first step would be to check /sys/kernel/debug/usb/devices, it should look 68 68 like this: 69 69 70 70 T: Bus=01 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#= 1 Spd=12 MxCh= 2
+20 -16
Documentation/usb/anchors.txt Documentation/driver-api/usb/anchors.rst
··· 1 + USB Anchors 2 + ~~~~~~~~~~~ 3 + 1 4 What is anchor? 2 5 =============== 3 6 ··· 16 13 ============================= 17 14 18 15 There's no API to allocate an anchor. It is simply declared 19 - as struct usb_anchor. init_usb_anchor() must be called to 16 + as struct usb_anchor. :c:func:`init_usb_anchor` must be called to 20 17 initialise the data structure. 21 18 22 19 Deallocation ··· 29 26 =================================================== 30 27 31 28 An association of URBs to an anchor is made by an explicit 32 - call to usb_anchor_urb(). The association is maintained until 29 + call to :c:func:`usb_anchor_urb`. The association is maintained until 33 30 an URB is finished by (successful) completion. Thus disassociation 34 31 is automatic. A function is provided to forcibly finish (kill) 35 32 all URBs associated with an anchor. 36 - Furthermore, disassociation can be made with usb_unanchor_urb() 33 + Furthermore, disassociation can be made with :c:func:`usb_unanchor_urb` 37 34 38 35 Operations on multitudes of URBs 39 36 ================================ 40 37 41 - usb_kill_anchored_urbs() 42 - ------------------------ 38 + :c:func:`usb_kill_anchored_urbs` 39 + -------------------------------- 43 40 44 41 This function kills all URBs associated with an anchor. The URBs 45 42 are called in the reverse temporal order they were submitted. 46 43 This way no data can be reordered. 47 44 48 - usb_unlink_anchored_urbs() 49 - -------------------------- 45 + :c:func:`usb_unlink_anchored_urbs` 46 + ---------------------------------- 47 + 50 48 51 49 This function unlinks all URBs associated with an anchor. The URBs 52 50 are processed in the reverse temporal order they were submitted. 53 - This is similar to usb_kill_anchored_urbs(), but it will not sleep. 51 + This is similar to :c:func:`usb_kill_anchored_urbs`, but it will not sleep. 54 52 Therefore no guarantee is made that the URBs have been unlinked when 55 53 the call returns. They may be unlinked later but will be unlinked in 56 54 finite time. 57 55 58 - usb_scuttle_anchored_urbs() 59 - --------------------------- 56 + :c:func:`usb_scuttle_anchored_urbs` 57 + ----------------------------------- 60 58 61 59 All URBs of an anchor are unanchored en masse. 62 60 63 - usb_wait_anchor_empty_timeout() 64 - ------------------------------- 61 + :c:func:`usb_wait_anchor_empty_timeout` 62 + --------------------------------------- 65 63 66 64 This function waits for all URBs associated with an anchor to finish 67 65 or a timeout, whichever comes first. Its return value will tell you 68 66 whether the timeout was reached. 69 67 70 - usb_anchor_empty() 71 - ------------------ 68 + :c:func:`usb_anchor_empty` 69 + -------------------------- 72 70 73 71 Returns true if no URBs are associated with an anchor. Locking 74 72 is the caller's responsibility. 75 73 76 - usb_get_from_anchor() 77 - --------------------- 74 + :c:func:`usb_get_from_anchor` 75 + ----------------------------- 78 76 79 77 Returns the oldest anchored URB of an anchor. The URB is unanchored 80 78 and returned with a reference. As you may mix URBs to several
+9 -4
Documentation/usb/bulk-streams.txt Documentation/driver-api/usb/bulk-streams.rst
··· 1 + USB bulk streams 2 + ~~~~~~~~~~~~~~~~ 3 + 1 4 Background 2 5 ========== 3 6 ··· 28 25 Driver implications 29 26 =================== 30 27 31 - int usb_alloc_streams(struct usb_interface *interface, 28 + :: 29 + 30 + int usb_alloc_streams(struct usb_interface *interface, 32 31 struct usb_host_endpoint **eps, unsigned int num_eps, 33 32 unsigned int num_streams, gfp_t mem_flags); 34 33 ··· 58 53 59 54 60 55 Picking new Stream IDs to use 61 - ============================ 56 + ============================= 62 57 63 58 Stream ID 0 is reserved, and should not be used to communicate with devices. If 64 59 usb_alloc_streams() returns with a value of N, you may use streams 1 though N. ··· 73 68 ======== 74 69 75 70 If a driver wishes to stop using streams to communicate with the device, it 76 - should call 71 + should call:: 77 72 78 - void usb_free_streams(struct usb_interface *interface, 73 + void usb_free_streams(struct usb_interface *interface, 79 74 struct usb_host_endpoint **eps, unsigned int num_eps, 80 75 gfp_t mem_flags); 81 76
+44 -21
Documentation/usb/callbacks.txt Documentation/driver-api/usb/callbacks.rst
··· 1 + USB core callbacks 2 + ~~~~~~~~~~~~~~~~~~ 3 + 1 4 What callbacks will usbcore do? 2 5 =============================== 3 6 ··· 8 5 structure and through the completion handler of URBs a driver submits. 9 6 Only the former are in the scope of this document. These two kinds of 10 7 callbacks are completely independent of each other. Information on the 11 - completion callback can be found in Documentation/usb/URB.txt. 8 + completion callback can be found in :ref:`usb-urb`. 12 9 13 10 The callbacks defined in the driver structure are: 14 11 15 12 1. Hotplugging callbacks: 16 13 17 - * @probe: Called to see if the driver is willing to manage a particular 18 - * interface on a device. 19 - * @disconnect: Called when the interface is no longer accessible, usually 20 - * because its device has been (or is being) disconnected or the 21 - * driver module is being unloaded. 14 + - @probe: 15 + Called to see if the driver is willing to manage a particular 16 + interface on a device. 17 + 18 + - @disconnect: 19 + Called when the interface is no longer accessible, usually 20 + because its device has been (or is being) disconnected or the 21 + driver module is being unloaded. 22 22 23 23 2. Odd backdoor through usbfs: 24 24 25 - * @ioctl: Used for drivers that want to talk to userspace through 26 - * the "usbfs" filesystem. This lets devices provide ways to 27 - * expose information to user space regardless of where they 28 - * do (or don't) show up otherwise in the filesystem. 25 + - @ioctl: 26 + Used for drivers that want to talk to userspace through 27 + the "usbfs" filesystem. This lets devices provide ways to 28 + expose information to user space regardless of where they 29 + do (or don't) show up otherwise in the filesystem. 29 30 30 31 3. Power management (PM) callbacks: 31 32 32 - * @suspend: Called when the device is going to be suspended. 33 - * @resume: Called when the device is being resumed. 34 - * @reset_resume: Called when the suspended device has been reset instead 35 - * of being resumed. 33 + - @suspend: 34 + Called when the device is going to be suspended. 35 + 36 + - @resume: 37 + Called when the device is being resumed. 38 + 39 + - @reset_resume: 40 + Called when the suspended device has been reset instead 41 + of being resumed. 36 42 37 43 4. Device level operations: 38 44 39 - * @pre_reset: Called when the device is about to be reset. 40 - * @post_reset: Called after the device has been reset 45 + - @pre_reset: 46 + Called when the device is about to be reset. 47 + 48 + - @post_reset: 49 + Called after the device has been reset 41 50 42 51 The ioctl interface (2) should be used only if you have a very good 43 52 reason. Sysfs is preferred these days. The PM callbacks are covered 44 - separately in Documentation/usb/power-management.txt. 53 + separately in :ref:`usb-power-management`. 45 54 46 55 Calling conventions 47 56 =================== ··· 73 58 The probe() callback 74 59 -------------------- 75 60 76 - int (*probe) (struct usb_interface *intf, 61 + :: 62 + 63 + int (*probe) (struct usb_interface *intf, 77 64 const struct usb_device_id *id); 78 65 79 66 Accept or decline an interface. If you accept the device return 0, ··· 92 75 The disconnect() callback 93 76 ------------------------- 94 77 95 - void (*disconnect) (struct usb_interface *intf); 78 + :: 79 + 80 + void (*disconnect) (struct usb_interface *intf); 96 81 97 82 This callback is a signal to break any connection with an interface. 98 83 You are not allowed any IO to a device after returning from this ··· 112 93 pre_reset 113 94 --------- 114 95 115 - int (*pre_reset)(struct usb_interface *intf); 96 + :: 97 + 98 + int (*pre_reset)(struct usb_interface *intf); 116 99 117 100 A driver or user space is triggering a reset on the device which 118 101 contains the interface passed as an argument. Cease IO, wait for all ··· 128 107 post_reset 129 108 ---------- 130 109 131 - int (*post_reset)(struct usb_interface *intf); 110 + :: 111 + 112 + int (*post_reset)(struct usb_interface *intf); 132 113 133 114 The reset has completed. Restore any saved device state and begin 134 115 using the device again.
+27 -24
Documentation/usb/dma.txt Documentation/driver-api/usb/dma.rst
··· 1 + USB DMA 2 + ~~~~~~~ 3 + 1 4 In Linux 2.5 kernels (and later), USB device drivers have additional control 2 5 over how DMA may be used to perform I/O operations. The APIs are detailed 3 6 in the kernel usb programming guide (kerneldoc, from the source code). 4 7 5 - 6 - API OVERVIEW 8 + API overview 9 + ============ 7 10 8 11 The big picture is that USB drivers can continue to ignore most DMA issues, 9 12 though they still must provide DMA-ready buffers (see 10 - Documentation/DMA-API-HOWTO.txt). That's how they've worked through 11 - the 2.4 (and earlier) kernels. 13 + ``Documentation/DMA-API-HOWTO.txt``). That's how they've worked through 14 + the 2.4 (and earlier) kernels, or they can now be DMA-aware. 12 15 13 - OR: they can now be DMA-aware. 16 + DMA-aware usb drivers: 14 17 15 18 - New calls enable DMA-aware drivers, letting them allocate dma buffers and 16 19 manage dma mappings for existing dma-ready buffers (see below). ··· 23 20 drivers must not use it.) 24 21 25 22 - "usbcore" will map this DMA address, if a DMA-aware driver didn't do 26 - it first and set URB_NO_TRANSFER_DMA_MAP. HCDs 23 + it first and set ``URB_NO_TRANSFER_DMA_MAP``. HCDs 27 24 don't manage dma mappings for URBs. 28 25 29 26 - There's a new "generic DMA API", parts of which are usable by USB device 30 27 drivers. Never use dma_set_mask() on any USB interface or device; that 31 28 would potentially break all devices sharing that bus. 32 29 33 - 34 - ELIMINATING COPIES 30 + Eliminating copies 31 + ================== 35 32 36 33 It's good to avoid making CPUs copy data needlessly. The costs can add up, 37 34 and effects like cache-trashing can impose subtle penalties. ··· 44 41 For those specific cases, USB has primitives to allocate less expensive 45 42 memory. They work like kmalloc and kfree versions that give you the right 46 43 kind of addresses to store in urb->transfer_buffer and urb->transfer_dma. 47 - You'd also set URB_NO_TRANSFER_DMA_MAP in urb->transfer_flags: 44 + You'd also set ``URB_NO_TRANSFER_DMA_MAP`` in urb->transfer_flags:: 48 45 49 46 void *usb_alloc_coherent (struct usb_device *dev, size_t size, 50 47 int mem_flags, dma_addr_t *dma); ··· 52 49 void usb_free_coherent (struct usb_device *dev, size_t size, 53 50 void *addr, dma_addr_t dma); 54 51 55 - Most drivers should *NOT* be using these primitives; they don't need 52 + Most drivers should **NOT** be using these primitives; they don't need 56 53 to use this type of memory ("dma-coherent"), and memory returned from 57 - kmalloc() will work just fine. 54 + :c:func:`kmalloc` will work just fine. 58 55 59 56 The memory buffer returned is "dma-coherent"; sometimes you might need to 60 57 force a consistent memory access ordering by using memory barriers. It's 61 58 not using a streaming DMA mapping, so it's good for small transfers on 62 59 systems where the I/O would otherwise thrash an IOMMU mapping. (See 63 - Documentation/DMA-API-HOWTO.txt for definitions of "coherent" and 60 + ``Documentation/DMA-API-HOWTO.txt`` for definitions of "coherent" and 64 61 "streaming" DMA mappings.) 65 62 66 63 Asking for 1/Nth of a page (as well as asking for N pages) is reasonably ··· 78 75 way to expose these capabilities ... and in any case, HIGHMEM is mostly a 79 76 design wart specific to x86_32. So your best bet is to ensure you never 80 77 pass a highmem buffer into a USB driver. That's easy; it's the default 81 - behavior. Just don't override it; e.g. with NETIF_F_HIGHDMA. 78 + behavior. Just don't override it; e.g. with ``NETIF_F_HIGHDMA``. 82 79 83 80 This may force your callers to do some bounce buffering, copying from 84 81 high memory to "normal" DMA memory. If you can come up with a good way 85 82 to fix this issue (for x86_32 machines with over 1 GByte of memory), 86 83 feel free to submit patches. 87 84 88 - 89 - WORKING WITH EXISTING BUFFERS 85 + Working with existing buffers 86 + ============================= 90 87 91 88 Existing buffers aren't usable for DMA without first being mapped into the 92 89 DMA address space of the device. However, most buffers passed to your ··· 95 92 96 93 - When you're using scatterlists, you can map everything at once. On some 97 94 systems, this kicks in an IOMMU and turns the scatterlists into single 98 - DMA transactions: 95 + DMA transactions:: 99 96 100 97 int usb_buffer_map_sg (struct usb_device *dev, unsigned pipe, 101 98 struct scatterlist *sg, int nents); ··· 106 103 void usb_buffer_unmap_sg (struct usb_device *dev, unsigned pipe, 107 104 struct scatterlist *sg, int n_hw_ents); 108 105 109 - It's probably easier to use the new usb_sg_*() calls, which do the DMA 106 + It's probably easier to use the new ``usb_sg_*()`` calls, which do the DMA 110 107 mapping and apply other tweaks to make scatterlist i/o be fast. 111 108 112 109 - Some drivers may prefer to work with the model that they're mapping large ··· 115 112 here, since it's cheaper to just synchronize the buffer than to unmap it 116 113 each time an urb completes and then re-map it on during resubmission. 117 114 118 - These calls all work with initialized urbs: urb->dev, urb->pipe, 119 - urb->transfer_buffer, and urb->transfer_buffer_length must all be 120 - valid when these calls are used (urb->setup_packet must be valid too 121 - if urb is a control request): 115 + These calls all work with initialized urbs: ``urb->dev``, ``urb->pipe``, 116 + ``urb->transfer_buffer``, and ``urb->transfer_buffer_length`` must all be 117 + valid when these calls are used (``urb->setup_packet`` must be valid too 118 + if urb is a control request):: 122 119 123 120 struct urb *usb_buffer_map (struct urb *urb); 124 121 ··· 126 123 127 124 void usb_buffer_unmap (struct urb *urb); 128 125 129 - The calls manage urb->transfer_dma for you, and set URB_NO_TRANSFER_DMA_MAP 130 - so that usbcore won't map or unmap the buffer. They cannot be used for 131 - setup_packet buffers in control requests. 126 + The calls manage ``urb->transfer_dma`` for you, and set 127 + ``URB_NO_TRANSFER_DMA_MAP`` so that usbcore won't map or unmap the buffer. 128 + They cannot be used for setup_packet buffers in control requests. 132 129 133 130 Note that several of those interfaces are currently commented out, since 134 131 they don't have current users. See the source code. Other than the dmasync
-175
Documentation/usb/error-codes.txt
··· 1 - Revised: 2004-Oct-21 2 - 3 - This is the documentation of (hopefully) all possible error codes (and 4 - their interpretation) that can be returned from usbcore. 5 - 6 - Some of them are returned by the Host Controller Drivers (HCDs), which 7 - device drivers only see through usbcore. As a rule, all the HCDs should 8 - behave the same except for transfer speed dependent behaviors and the 9 - way certain faults are reported. 10 - 11 - 12 - ************************************************************************** 13 - * Error codes returned by usb_submit_urb * 14 - ************************************************************************** 15 - 16 - Non-USB-specific: 17 - 18 - 0 URB submission went fine 19 - 20 - -ENOMEM no memory for allocation of internal structures 21 - 22 - USB-specific: 23 - 24 - -EBUSY The URB is already active. 25 - 26 - -ENODEV specified USB-device or bus doesn't exist 27 - 28 - -ENOENT specified interface or endpoint does not exist or 29 - is not enabled 30 - 31 - -ENXIO host controller driver does not support queuing of this type 32 - of urb. (treat as a host controller bug.) 33 - 34 - -EINVAL a) Invalid transfer type specified (or not supported) 35 - b) Invalid or unsupported periodic transfer interval 36 - c) ISO: attempted to change transfer interval 37 - d) ISO: number_of_packets is < 0 38 - e) various other cases 39 - 40 - -EXDEV ISO: URB_ISO_ASAP wasn't specified and all the frames 41 - the URB would be scheduled in have already expired. 42 - 43 - -EFBIG Host controller driver can't schedule that many ISO frames. 44 - 45 - -EPIPE The pipe type specified in the URB doesn't match the 46 - endpoint's actual type. 47 - 48 - -EMSGSIZE (a) endpoint maxpacket size is zero; it is not usable 49 - in the current interface altsetting. 50 - (b) ISO packet is larger than the endpoint maxpacket. 51 - (c) requested data transfer length is invalid: negative 52 - or too large for the host controller. 53 - 54 - -ENOSPC This request would overcommit the usb bandwidth reserved 55 - for periodic transfers (interrupt, isochronous). 56 - 57 - -ESHUTDOWN The device or host controller has been disabled due to some 58 - problem that could not be worked around. 59 - 60 - -EPERM Submission failed because urb->reject was set. 61 - 62 - -EHOSTUNREACH URB was rejected because the device is suspended. 63 - 64 - -ENOEXEC A control URB doesn't contain a Setup packet. 65 - 66 - 67 - ************************************************************************** 68 - * Error codes returned by in urb->status * 69 - * or in iso_frame_desc[n].status (for ISO) * 70 - ************************************************************************** 71 - 72 - USB device drivers may only test urb status values in completion handlers. 73 - This is because otherwise there would be a race between HCDs updating 74 - these values on one CPU, and device drivers testing them on another CPU. 75 - 76 - A transfer's actual_length may be positive even when an error has been 77 - reported. That's because transfers often involve several packets, so that 78 - one or more packets could finish before an error stops further endpoint I/O. 79 - 80 - For isochronous URBs, the urb status value is non-zero only if the URB is 81 - unlinked, the device is removed, the host controller is disabled, or the total 82 - transferred length is less than the requested length and the URB_SHORT_NOT_OK 83 - flag is set. Completion handlers for isochronous URBs should only see 84 - urb->status set to zero, -ENOENT, -ECONNRESET, -ESHUTDOWN, or -EREMOTEIO. 85 - Individual frame descriptor status fields may report more status codes. 86 - 87 - 88 - 0 Transfer completed successfully 89 - 90 - -ENOENT URB was synchronously unlinked by usb_unlink_urb 91 - 92 - -EINPROGRESS URB still pending, no results yet 93 - (That is, if drivers see this it's a bug.) 94 - 95 - -EPROTO (*, **) a) bitstuff error 96 - b) no response packet received within the 97 - prescribed bus turn-around time 98 - c) unknown USB error 99 - 100 - -EILSEQ (*, **) a) CRC mismatch 101 - b) no response packet received within the 102 - prescribed bus turn-around time 103 - c) unknown USB error 104 - 105 - Note that often the controller hardware does not 106 - distinguish among cases a), b), and c), so a 107 - driver cannot tell whether there was a protocol 108 - error, a failure to respond (often caused by 109 - device disconnect), or some other fault. 110 - 111 - -ETIME (**) No response packet received within the prescribed 112 - bus turn-around time. This error may instead be 113 - reported as -EPROTO or -EILSEQ. 114 - 115 - -ETIMEDOUT Synchronous USB message functions use this code 116 - to indicate timeout expired before the transfer 117 - completed, and no other error was reported by HC. 118 - 119 - -EPIPE (**) Endpoint stalled. For non-control endpoints, 120 - reset this status with usb_clear_halt(). 121 - 122 - -ECOMM During an IN transfer, the host controller 123 - received data from an endpoint faster than it 124 - could be written to system memory 125 - 126 - -ENOSR During an OUT transfer, the host controller 127 - could not retrieve data from system memory fast 128 - enough to keep up with the USB data rate 129 - 130 - -EOVERFLOW (*) The amount of data returned by the endpoint was 131 - greater than either the max packet size of the 132 - endpoint or the remaining buffer size. "Babble". 133 - 134 - -EREMOTEIO The data read from the endpoint did not fill the 135 - specified buffer, and URB_SHORT_NOT_OK was set in 136 - urb->transfer_flags. 137 - 138 - -ENODEV Device was removed. Often preceded by a burst of 139 - other errors, since the hub driver doesn't detect 140 - device removal events immediately. 141 - 142 - -EXDEV ISO transfer only partially completed 143 - (only set in iso_frame_desc[n].status, not urb->status) 144 - 145 - -EINVAL ISO madness, if this happens: Log off and go home 146 - 147 - -ECONNRESET URB was asynchronously unlinked by usb_unlink_urb 148 - 149 - -ESHUTDOWN The device or host controller has been disabled due 150 - to some problem that could not be worked around, 151 - such as a physical disconnect. 152 - 153 - 154 - (*) Error codes like -EPROTO, -EILSEQ and -EOVERFLOW normally indicate 155 - hardware problems such as bad devices (including firmware) or cables. 156 - 157 - (**) This is also one of several codes that different kinds of host 158 - controller use to indicate a transfer has failed because of device 159 - disconnect. In the interval before the hub driver starts disconnect 160 - processing, devices may receive such fault reports for every request. 161 - 162 - 163 - 164 - ************************************************************************** 165 - * Error codes returned by usbcore-functions * 166 - * (expect also other submit and transfer status codes) * 167 - ************************************************************************** 168 - 169 - usb_register(): 170 - -EINVAL error during registering new driver 171 - 172 - usb_get_*/usb_set_*(): 173 - usb_control_msg(): 174 - usb_bulk_msg(): 175 - -ETIMEDOUT Timeout expired before the transfer completed.
+2 -2
Documentation/usb/gadget_serial.txt
··· 189 189 to the Linux host with a USB cable, the host system should recognize 190 190 the gadget serial device. For example, the command 191 191 192 - cat /proc/bus/usb/devices 192 + cat /sys/kernel/debug/usb/devices 193 193 194 194 should show something like this: 195 195 ··· 221 221 to the Linux host with a USB cable, the host system should recognize 222 222 the gadget serial device. For example, the command 223 223 224 - cat /proc/bus/usb/devices 224 + cat /sys/kernel/debug/usb/devices 225 225 226 226 should show something like this: 227 227
+36 -30
Documentation/usb/hotplug.txt Documentation/driver-api/usb/hotplug.rst
··· 1 - LINUX HOTPLUGGING 1 + USB hotplugging 2 + ~~~~~~~~~~~~~~~ 3 + 4 + Linux Hotplugging 5 + ================= 6 + 2 7 3 8 In hotpluggable busses like USB (and Cardbus PCI), end-users plug devices 4 9 into the bus with power on. In most cases, users expect the devices to become ··· 35 30 that is currently available only when the drivers are dynamically linked, 36 31 you get the best hotplugging when you configure a highly modular system. 37 32 33 + Kernel Hotplug Helper (``/sbin/hotplug``) 34 + ========================================= 38 35 39 - KERNEL HOTPLUG HELPER (/sbin/hotplug) 40 - 41 - There is a kernel parameter: /proc/sys/kernel/hotplug, which normally 42 - holds the pathname "/sbin/hotplug". That parameter names a program 36 + There is a kernel parameter: ``/proc/sys/kernel/hotplug``, which normally 37 + holds the pathname ``/sbin/hotplug``. That parameter names a program 43 38 which the kernel may invoke at various times. 44 39 45 40 The /sbin/hotplug program can be invoked by any subsystem as part of its ··· 56 51 Mailing list information is also available at that site. 57 52 58 53 59 - -------------------------------------------------------------------------- 54 + USB Policy Agent 55 + ================ 60 56 61 - 62 - USB POLICY AGENT 63 - 64 - The USB subsystem currently invokes /sbin/hotplug when USB devices 57 + The USB subsystem currently invokes ``/sbin/hotplug`` when USB devices 65 58 are added or removed from system. The invocation is done by the kernel 66 59 hub workqueue [hub_wq], or else as part of root hub initialization 67 60 (done by init, modprobe, kapmd, etc). Its single command line parameter 68 61 is the string "usb", and it passes these environment variables: 69 62 70 - ACTION ... "add", "remove" 71 - PRODUCT ... USB vendor, product, and version codes (hex) 72 - TYPE ... device class codes (decimal) 73 - INTERFACE ... interface 0 class codes (decimal) 63 + ========== ============================================ 64 + ACTION ``add``, ``remove`` 65 + PRODUCT USB vendor, product, and version codes (hex) 66 + TYPE device class codes (decimal) 67 + INTERFACE interface 0 class codes (decimal) 68 + ========== ============================================ 74 69 75 70 If "usbdevfs" is configured, DEVICE and DEVFS are also passed. DEVICE is 76 71 the pathname of the device, and is useful for devices with multiple and/or 77 72 alternate interfaces that complicate driver selection. By design, USB 78 - hotplugging is independent of "usbdevfs": you can do most essential parts 73 + hotplugging is independent of ``usbdevfs``: you can do most essential parts 79 74 of USB device setup without using that filesystem, and without running a 80 75 user mode daemon to detect changes in system configuration. 81 76 ··· 84 79 leverage USB module-init-tools support. Later agents might unload drivers. 85 80 86 81 87 - USB MODUTILS SUPPORT 82 + USB Modutils Support 83 + ==================== 88 84 89 - Current versions of module-init-tools will create a "modules.usbmap" file 90 - which contains the entries from each driver's MODULE_DEVICE_TABLE. Such 85 + Current versions of module-init-tools will create a ``modules.usbmap`` file 86 + which contains the entries from each driver's ``MODULE_DEVICE_TABLE``. Such 91 87 files can be used by various user mode policy agents to make sure all the 92 88 right driver modules get loaded, either at boot time or later. 93 89 94 - See <linux/usb.h> for full information about such table entries; or look 90 + See ``linux/usb.h`` for full information about such table entries; or look 95 91 at existing drivers. Each table entry describes one or more criteria to 96 92 be used when matching a driver to a device or class of devices. The 97 93 specific criteria are identified by bits set in "match_flags", paired 98 94 with field values. You can construct the criteria directly, or with 99 - macros such as these, and use driver_info to store more information. 95 + macros such as these, and use driver_info to store more information:: 100 96 101 97 USB_DEVICE (vendorId, productId) 102 98 ... matching devices with specified vendor and product ids ··· 109 103 ... matching specified device class info 110 104 111 105 A short example, for a driver that supports several specific USB devices 112 - and their quirks, might have a MODULE_DEVICE_TABLE like this: 106 + and their quirks, might have a MODULE_DEVICE_TABLE like this:: 113 107 114 108 static const struct usb_device_id mydriver_id_table[] = { 115 109 { USB_DEVICE (0x9999, 0xaaaa), driver_info: QUIRK_X }, ··· 122 116 Most USB device drivers should pass these tables to the USB subsystem as 123 117 well as to the module management subsystem. Not all, though: some driver 124 118 frameworks connect using interfaces layered over USB, and so they won't 125 - need such a "struct usb_driver". 119 + need such a struct :c:type:`usb_driver`. 126 120 127 121 Drivers that connect directly to the USB subsystem should be declared 128 - something like this: 122 + something like this:: 129 123 130 124 static struct usb_driver mydriver = { 131 125 .name = "mydriver", ··· 144 138 145 139 When the USB subsystem knows about a driver's device ID table, it's used when 146 140 choosing drivers to probe(). The thread doing new device processing checks 147 - drivers' device ID entries from the MODULE_DEVICE_TABLE against interface and 148 - device descriptors for the device. It will only call probe() if there is a 149 - match, and the third argument to probe() will be the entry that matched. 141 + drivers' device ID entries from the ``MODULE_DEVICE_TABLE`` against interface 142 + and device descriptors for the device. It will only call ``probe()`` if there 143 + is a match, and the third argument to ``probe()`` will be the entry that 144 + matched. 150 145 151 - If you don't provide an id_table for your driver, then your driver may get 152 - probed for each new device; the third parameter to probe() will be null. 153 - 154 - 146 + If you don't provide an ``id_table`` for your driver, then your driver may get 147 + probed for each new device; the third parameter to ``probe()`` will be 148 + ``NULL``.
+14 -8
Documentation/usb/persist.txt Documentation/driver-api/usb/persist.rst
··· 1 - USB device persistence during system suspend 1 + .. _usb-persist: 2 2 3 - Alan Stern <stern@rowland.harvard.edu> 3 + USB device persistence during system suspend 4 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 4 5 5 - September 2, 2006 (Updated February 25, 2008) 6 + :Author: Alan Stern <stern@rowland.harvard.edu> 7 + :Date: September 2, 2006 (Updated February 25, 2008) 6 8 7 9 8 - What is the problem? 10 + What is the problem? 11 + ==================== 9 12 10 13 According to the USB specification, when a USB bus is suspended the 11 14 bus must continue to supply suspend current (around 1-5 mA). This ··· 66 63 much better.) 67 64 68 65 69 - What is the solution? 66 + What is the solution? 67 + ===================== 70 68 71 69 The kernel includes a feature called USB-persist. It tries to work 72 70 around these issues by allowing the core USB device data structures to ··· 103 99 104 100 Note that the "USB-persist" feature will be applied only to those 105 101 devices for which it is enabled. You can enable the feature by doing 106 - (as root): 102 + (as root):: 107 103 108 104 echo 1 >/sys/bus/usb/devices/.../power/persist 109 105 ··· 114 110 devices where it really matters. 115 111 116 112 117 - Is this the best solution? 113 + Is this the best solution? 114 + ========================== 118 115 119 116 Perhaps not. Arguably, keeping track of mounted filesystems and 120 117 memory mappings across device disconnects should be handled by a ··· 135 130 other device types, such as network interfaces. 136 131 137 132 138 - WARNING: USB-persist can be dangerous!! 133 + WARNING: USB-persist can be dangerous!! 134 + ======================================= 139 135 140 136 When recovering an interrupted power session the kernel does its best 141 137 to make sure the USB device hasn't been changed; that is, the same
+213 -191
Documentation/usb/power-management.txt Documentation/driver-api/usb/power-management.rst
··· 1 - Power Management for USB 1 + .. _usb-power-management: 2 2 3 - Alan Stern <stern@rowland.harvard.edu> 3 + Power Management for USB 4 + ~~~~~~~~~~~~~~~~~~~~~~~~ 4 5 5 - Last-updated: February 2014 6 + :Author: Alan Stern <stern@rowland.harvard.edu> 7 + :Date: Last-updated: February 2014 6 8 7 - 9 + .. 8 10 Contents: 9 11 --------- 10 12 * What is Power Management? ··· 27 25 * Suggested Userspace Port Power Policy 28 26 29 27 30 - What is Power Management? 31 - ------------------------- 28 + What is Power Management? 29 + ------------------------- 32 30 33 31 Power Management (PM) is the practice of saving energy by suspending 34 32 parts of a computer system when they aren't being used. While a 35 - component is "suspended" it is in a nonfunctional low-power state; it 33 + component is ``suspended`` it is in a nonfunctional low-power state; it 36 34 might even be turned off completely. A suspended component can be 37 - "resumed" (returned to a functional full-power state) when the kernel 35 + ``resumed`` (returned to a functional full-power state) when the kernel 38 36 needs to use it. (There also are forms of PM in which components are 39 37 placed in a less functional but still usable state instead of being 40 38 suspended; an example would be reducing the CPU's clock rate. This ··· 46 44 call it a "dynamic suspend" (also known as a "runtime suspend" or 47 45 "selective suspend"). This document concentrates mostly on how 48 46 dynamic PM is implemented in the USB subsystem, although system PM is 49 - covered to some extent (see Documentation/power/*.txt for more 47 + covered to some extent (see ``Documentation/power/*.txt`` for more 50 48 information about system PM). 51 49 52 - System PM support is present only if the kernel was built with CONFIG_SUSPEND 53 - or CONFIG_HIBERNATION enabled. Dynamic PM support for USB is present whenever 54 - the kernel was built with CONFIG_PM enabled. 50 + System PM support is present only if the kernel was built with 51 + ``CONFIG_SUSPEND`` or ``CONFIG_HIBERNATION`` enabled. Dynamic PM support 52 + 53 + for USB is present whenever 54 + the kernel was built with ``CONFIG_PM`` enabled. 55 55 56 56 [Historically, dynamic PM support for USB was present only if the 57 - kernel had been built with CONFIG_USB_SUSPEND enabled (which depended on 58 - CONFIG_PM_RUNTIME). Starting with the 3.10 kernel release, dynamic PM support 59 - for USB was present whenever the kernel was built with CONFIG_PM_RUNTIME 60 - enabled. The CONFIG_USB_SUSPEND option had been eliminated.] 57 + kernel had been built with ``CONFIG_USB_SUSPEND`` enabled (which depended on 58 + ``CONFIG_PM_RUNTIME``). Starting with the 3.10 kernel release, dynamic PM 59 + support for USB was present whenever the kernel was built with 60 + ``CONFIG_PM_RUNTIME`` enabled. The ``CONFIG_USB_SUSPEND`` option had been 61 + eliminated.] 61 62 62 63 63 - What is Remote Wakeup? 64 - ---------------------- 64 + What is Remote Wakeup? 65 + ---------------------- 65 66 66 67 When a device has been suspended, it generally doesn't resume until 67 68 the computer tells it to. Likewise, if the entire computer has been ··· 81 76 pressed, or a suspended USB hub resuming when a device is plugged in. 82 77 83 78 84 - When is a USB device idle? 85 - -------------------------- 79 + When is a USB device idle? 80 + -------------------------- 86 81 87 82 A device is idle whenever the kernel thinks it's not busy doing 88 83 anything important and thus is a candidate for being suspended. The ··· 97 92 being accessed through sysfs, then it definitely is idle. 98 93 99 94 100 - Forms of dynamic PM 101 - ------------------- 95 + Forms of dynamic PM 96 + ------------------- 102 97 103 98 Dynamic suspends occur when the kernel decides to suspend an idle 104 - device. This is called "autosuspend" for short. In general, a device 99 + device. This is called ``autosuspend`` for short. In general, a device 105 100 won't be autosuspended unless it has been idle for some minimum period 106 101 of time, the so-called idle-delay time. 107 102 ··· 130 125 allowed to issue dynamic suspends. 131 126 132 127 133 - The user interface for dynamic PM 134 - --------------------------------- 128 + The user interface for dynamic PM 129 + --------------------------------- 135 130 136 - The user interface for controlling dynamic PM is located in the power/ 131 + The user interface for controlling dynamic PM is located in the ``power/`` 137 132 subdirectory of each USB device's sysfs directory, that is, in 138 - /sys/bus/usb/devices/.../power/ where "..." is the device's ID. The 133 + ``/sys/bus/usb/devices/.../power/`` where "..." is the device's ID. The 139 134 relevant attribute files are: wakeup, control, and 140 - autosuspend_delay_ms. (There may also be a file named "level"; this 135 + ``autosuspend_delay_ms``. (There may also be a file named ``level``; this 141 136 file was deprecated as of the 2.6.35 kernel and replaced by the 142 - "control" file. In 2.6.38 the "autosuspend" file will be deprecated 143 - and replaced by the "autosuspend_delay_ms" file. The only difference 137 + ``control`` file. In 2.6.38 the ``autosuspend`` file will be deprecated 138 + and replaced by the ``autosuspend_delay_ms`` file. The only difference 144 139 is that the newer file expresses the delay in milliseconds whereas the 145 140 older file uses seconds. Confusingly, both files are present in 2.6.37 146 - but only "autosuspend" works.) 141 + but only ``autosuspend`` works.) 147 142 148 - power/wakeup 143 + ``power/wakeup`` 149 144 150 145 This file is empty if the device does not support 151 146 remote wakeup. Otherwise the file contains either the 152 - word "enabled" or the word "disabled", and you can 147 + word ``enabled`` or the word ``disabled``, and you can 153 148 write those words to the file. The setting determines 154 149 whether or not remote wakeup will be enabled when the 155 150 device is next suspended. (If the setting is changed 156 151 while the device is suspended, the change won't take 157 152 effect until the following suspend.) 158 153 159 - power/control 154 + ``power/control`` 160 155 161 - This file contains one of two words: "on" or "auto". 156 + This file contains one of two words: ``on`` or ``auto``. 162 157 You can write those words to the file to change the 163 158 device's setting. 164 159 165 - "on" means that the device should be resumed and 166 - autosuspend is not allowed. (Of course, system 167 - suspends are still allowed.) 160 + - ``on`` means that the device should be resumed and 161 + autosuspend is not allowed. (Of course, system 162 + suspends are still allowed.) 168 163 169 - "auto" is the normal state in which the kernel is 170 - allowed to autosuspend and autoresume the device. 164 + - ``auto`` is the normal state in which the kernel is 165 + allowed to autosuspend and autoresume the device. 171 166 172 167 (In kernels up to 2.6.32, you could also specify 173 - "suspend", meaning that the device should remain 168 + ``suspend``, meaning that the device should remain 174 169 suspended and autoresume was not allowed. This 175 170 setting is no longer supported.) 176 171 177 - power/autosuspend_delay_ms 172 + ``power/autosuspend_delay_ms`` 178 173 179 174 This file contains an integer value, which is the 180 175 number of milliseconds the device should remain idle ··· 185 180 number to the file to change the autosuspend 186 181 idle-delay time. 187 182 188 - Writing "-1" to power/autosuspend_delay_ms and writing "on" to 189 - power/control do essentially the same thing -- they both prevent the 183 + Writing ``-1`` to ``power/autosuspend_delay_ms`` and writing ``on`` to 184 + ``power/control`` do essentially the same thing -- they both prevent the 190 185 device from being autosuspended. Yes, this is a redundancy in the 191 186 API. 192 187 193 - (In 2.6.21 writing "0" to power/autosuspend would prevent the device 188 + (In 2.6.21 writing ``0`` to ``power/autosuspend`` would prevent the device 194 189 from being autosuspended; the behavior was changed in 2.6.22. The 195 - power/autosuspend attribute did not exist prior to 2.6.21, and the 196 - power/level attribute did not exist prior to 2.6.22. power/control 197 - was added in 2.6.34, and power/autosuspend_delay_ms was added in 190 + ``power/autosuspend`` attribute did not exist prior to 2.6.21, and the 191 + ``power/level`` attribute did not exist prior to 2.6.22. ``power/control`` 192 + was added in 2.6.34, and ``power/autosuspend_delay_ms`` was added in 198 193 2.6.37 but did not become functional until 2.6.38.) 199 194 200 195 201 - Changing the default idle-delay time 202 - ------------------------------------ 196 + Changing the default idle-delay time 197 + ------------------------------------ 203 198 204 199 The default autosuspend idle-delay time (in seconds) is controlled by 205 200 a module parameter in usbcore. You can specify the value when usbcore 206 201 is loaded. For example, to set it to 5 seconds instead of 2 you would 207 - do: 202 + do:: 208 203 209 204 modprobe usbcore autosuspend=5 210 205 211 206 Equivalently, you could add to a configuration file in /etc/modprobe.d 212 - a line saying: 207 + a line saying:: 213 208 214 209 options usbcore autosuspend=5 215 210 ··· 219 214 image. 220 215 221 216 If usbcore is compiled into the kernel rather than built as a loadable 222 - module, you can add 217 + module, you can add:: 223 218 224 219 usbcore.autosuspend=5 225 220 226 221 to the kernel's boot command line. 227 222 228 223 Finally, the parameter value can be changed while the system is 229 - running. If you do: 224 + running. If you do:: 230 225 231 226 echo 5 >/sys/module/usbcore/parameters/autosuspend 232 227 ··· 239 234 then to enable autosuspend for selected devices. 240 235 241 236 242 - Warnings 243 - -------- 237 + Warnings 238 + -------- 244 239 245 240 The USB specification states that all USB devices must support power 246 241 management. Nevertheless, the sad fact is that many devices do not ··· 251 246 the same deficiency. 252 247 253 248 For this reason, by default the kernel disables autosuspend (the 254 - power/control attribute is initialized to "on") for all devices other 249 + ``power/control`` attribute is initialized to ``on``) for all devices other 255 250 than hubs. Hubs, at least, appear to be reasonably well-behaved in 256 251 this regard. 257 252 ··· 289 284 possible.) Take care. 290 285 291 286 292 - The driver interface for Power Management 293 - ----------------------------------------- 287 + The driver interface for Power Management 288 + ----------------------------------------- 294 289 295 290 The requirements for a USB driver to support external power management 296 - are pretty modest; the driver need only define 291 + are pretty modest; the driver need only define:: 297 292 298 293 .suspend 299 294 .resume 300 295 .reset_resume 301 296 302 - methods in its usb_driver structure, and the reset_resume method is 303 - optional. The methods' jobs are quite simple: 297 + methods in its :c:type:`usb_driver` structure, and the ``reset_resume`` method 298 + is optional. The methods' jobs are quite simple: 304 299 305 - The suspend method is called to warn the driver that the 300 + - The ``suspend`` method is called to warn the driver that the 306 301 device is going to be suspended. If the driver returns a 307 302 negative error code, the suspend will be aborted. Normally 308 303 the driver will return 0, in which case it must cancel all 309 - outstanding URBs (usb_kill_urb()) and not submit any more. 304 + outstanding URBs (:c:func:`usb_kill_urb`) and not submit any more. 310 305 311 - The resume method is called to tell the driver that the 306 + - The ``resume`` method is called to tell the driver that the 312 307 device has been resumed and the driver can return to normal 313 308 operation. URBs may once more be submitted. 314 309 315 - The reset_resume method is called to tell the driver that 310 + - The ``reset_resume`` method is called to tell the driver that 316 311 the device has been resumed and it also has been reset. 317 312 The driver should redo any necessary device initialization, 318 313 since the device has probably lost most or all of its state ··· 320 315 before the suspend). 321 316 322 317 If the device is disconnected or powered down while it is suspended, 323 - the disconnect method will be called instead of the resume or 324 - reset_resume method. This is also quite likely to happen when 318 + the ``disconnect`` method will be called instead of the ``resume`` or 319 + ``reset_resume`` method. This is also quite likely to happen when 325 320 waking up from hibernation, as many systems do not maintain suspend 326 321 current to the USB host controllers during hibernation. (It's 327 322 possible to work around the hibernation-forces-disconnect problem by 328 323 using the USB Persist facility.) 329 324 330 - The reset_resume method is used by the USB Persist facility (see 331 - Documentation/usb/persist.txt) and it can also be used under certain 332 - circumstances when CONFIG_USB_PERSIST is not enabled. Currently, if a 325 + The ``reset_resume`` method is used by the USB Persist facility (see 326 + :ref:`usb-persist`) and it can also be used under certain 327 + circumstances when ``CONFIG_USB_PERSIST`` is not enabled. Currently, if a 333 328 device is reset during a resume and the driver does not have a 334 - reset_resume method, the driver won't receive any notification about 335 - the resume. Later kernels will call the driver's disconnect method; 329 + ``reset_resume`` method, the driver won't receive any notification about 330 + the resume. Later kernels will call the driver's ``disconnect`` method; 336 331 2.6.23 doesn't do this. 337 332 338 - USB drivers are bound to interfaces, so their suspend and resume 333 + USB drivers are bound to interfaces, so their ``suspend`` and ``resume`` 339 334 methods get called when the interfaces are suspended or resumed. In 340 335 principle one might want to suspend some interfaces on a device (i.e., 341 336 force the drivers for those interface to stop all activity) without ··· 346 341 closest you can come is to unbind the interfaces' drivers. 347 342 348 343 349 - The driver interface for autosuspend and autoresume 350 - --------------------------------------------------- 344 + The driver interface for autosuspend and autoresume 345 + --------------------------------------------------- 351 346 352 347 To support autosuspend and autoresume, a driver should implement all 353 348 three of the methods listed above. In addition, a driver indicates 354 - that it supports autosuspend by setting the .supports_autosuspend flag 349 + that it supports autosuspend by setting the ``.supports_autosuspend`` flag 355 350 in its usb_driver structure. It is then responsible for informing the 356 351 USB core whenever one of its interfaces becomes busy or idle. The 357 - driver does so by calling these six functions: 352 + driver does so by calling these six functions:: 358 353 359 354 int usb_autopm_get_interface(struct usb_interface *intf); 360 355 void usb_autopm_put_interface(struct usb_interface *intf); ··· 373 368 Drivers need not be concerned about balancing changes to the usage 374 369 counter; the USB core will undo any remaining "get"s when a driver 375 370 is unbound from its interface. As a corollary, drivers must not call 376 - any of the usb_autopm_* functions after their disconnect() routine has 377 - returned. 371 + any of the ``usb_autopm_*`` functions after their ``disconnect`` 372 + routine has returned. 378 373 379 374 Drivers using the async routines are responsible for their own 380 375 synchronization and mutual exclusion. 381 376 382 - usb_autopm_get_interface() increments the usage counter and 377 + :c:func:`usb_autopm_get_interface` increments the usage counter and 383 378 does an autoresume if the device is suspended. If the 384 379 autoresume fails, the counter is decremented back. 385 380 386 - usb_autopm_put_interface() decrements the usage counter and 381 + :c:func:`usb_autopm_put_interface` decrements the usage counter and 387 382 attempts an autosuspend if the new value is = 0. 388 383 389 - usb_autopm_get_interface_async() and 390 - usb_autopm_put_interface_async() do almost the same things as 384 + :c:func:`usb_autopm_get_interface_async` and 385 + :c:func:`usb_autopm_put_interface_async` do almost the same things as 391 386 their non-async counterparts. The big difference is that they 392 387 use a workqueue to do the resume or suspend part of their 393 388 jobs. As a result they can be called in an atomic context, 394 389 such as an URB's completion handler, but when they return the 395 390 device will generally not yet be in the desired state. 396 391 397 - usb_autopm_get_interface_no_resume() and 398 - usb_autopm_put_interface_no_suspend() merely increment or 392 + :c:func:`usb_autopm_get_interface_no_resume` and 393 + :c:func:`usb_autopm_put_interface_no_suspend` merely increment or 399 394 decrement the usage counter; they do not attempt to carry out 400 395 an autoresume or an autosuspend. Hence they can be called in 401 396 an atomic context. 402 397 403 398 The simplest usage pattern is that a driver calls 404 - usb_autopm_get_interface() in its open routine and 405 - usb_autopm_put_interface() in its close or release routine. But other 399 + :c:func:`usb_autopm_get_interface` in its open routine and 400 + :c:func:`usb_autopm_put_interface` in its close or release routine. But other 406 401 patterns are possible. 407 402 408 403 The autosuspend attempts mentioned above will often fail for one 409 - reason or another. For example, the power/control attribute might be 410 - set to "on", or another interface in the same device might not be 404 + reason or another. For example, the ``power/control`` attribute might be 405 + set to ``on``, or another interface in the same device might not be 411 406 idle. This is perfectly normal. If the reason for failure was that 412 407 the device hasn't been idle for long enough, a timer is scheduled to 413 408 carry out the operation automatically when the autosuspend idle-delay ··· 418 413 autosuspend, there's no idle-delay for an autoresume. 419 414 420 415 421 - Other parts of the driver interface 422 - ----------------------------------- 416 + Other parts of the driver interface 417 + ----------------------------------- 423 418 424 - Drivers can enable autosuspend for their devices by calling 419 + Drivers can enable autosuspend for their devices by calling:: 425 420 426 421 usb_enable_autosuspend(struct usb_device *udev); 427 422 428 - in their probe() routine, if they know that the device is capable of 423 + in their :c:func:`probe` routine, if they know that the device is capable of 429 424 suspending and resuming correctly. This is exactly equivalent to 430 - writing "auto" to the device's power/control attribute. Likewise, 431 - drivers can disable autosuspend by calling 425 + writing ``auto`` to the device's ``power/control`` attribute. Likewise, 426 + drivers can disable autosuspend by calling:: 432 427 433 428 usb_disable_autosuspend(struct usb_device *udev); 434 429 435 - This is exactly the same as writing "on" to the power/control attribute. 430 + This is exactly the same as writing ``on`` to the ``power/control`` attribute. 436 431 437 432 Sometimes a driver needs to make sure that remote wakeup is enabled 438 433 during autosuspend. For example, there's not much point 439 434 autosuspending a keyboard if the user can't cause the keyboard to do a 440 435 remote wakeup by typing on it. If the driver sets 441 - intf->needs_remote_wakeup to 1, the kernel won't autosuspend the 436 + ``intf->needs_remote_wakeup`` to 1, the kernel won't autosuspend the 442 437 device if remote wakeup isn't available. (If the device is already 443 438 autosuspended, though, setting this flag won't cause the kernel to 444 - autoresume it. Normally a driver would set this flag in its probe 439 + autoresume it. Normally a driver would set this flag in its ``probe`` 445 440 method, at which time the device is guaranteed not to be 446 441 autosuspended.) 447 442 448 443 If a driver does its I/O asynchronously in interrupt context, it 449 - should call usb_autopm_get_interface_async() before starting output and 450 - usb_autopm_put_interface_async() when the output queue drains. When 451 - it receives an input event, it should call 444 + should call :c:func:`usb_autopm_get_interface_async` before starting output and 445 + :c:func:`usb_autopm_put_interface_async` when the output queue drains. When 446 + it receives an input event, it should call:: 452 447 453 448 usb_mark_last_busy(struct usb_device *udev); 454 449 ··· 458 453 so drivers need to worry only when interrupt-driven input arrives. 459 454 460 455 Asynchronous operation is always subject to races. For example, a 461 - driver may call the usb_autopm_get_interface_async() routine at a time 456 + driver may call the :c:func:`usb_autopm_get_interface_async` routine at a time 462 457 when the core has just finished deciding the device has been idle for 463 - long enough but not yet gotten around to calling the driver's suspend 464 - method. The suspend method must be responsible for synchronizing with 458 + long enough but not yet gotten around to calling the driver's ``suspend`` 459 + method. The ``suspend`` method must be responsible for synchronizing with 465 460 the I/O request routine and the URB completion handler; it should 466 461 cause autosuspends to fail with -EBUSY if the driver needs to use the 467 462 device. 468 463 469 464 External suspend calls should never be allowed to fail in this way, 470 465 only autosuspend calls. The driver can tell them apart by applying 471 - the PMSG_IS_AUTO() macro to the message argument to the suspend 466 + the :c:func:`PMSG_IS_AUTO` macro to the message argument to the ``suspend`` 472 467 method; it will return True for internal PM events (autosuspend) and 473 468 False for external PM events. 474 469 475 470 476 - Mutual exclusion 477 - ---------------- 471 + Mutual exclusion 472 + ---------------- 478 473 479 474 For external events -- but not necessarily for autosuspend or 480 475 autoresume -- the device semaphore (udev->dev.sem) will be held when a 481 - suspend or resume method is called. This implies that external 482 - suspend/resume events are mutually exclusive with calls to probe, 483 - disconnect, pre_reset, and post_reset; the USB core guarantees that 476 + ``suspend`` or ``resume`` method is called. This implies that external 477 + suspend/resume events are mutually exclusive with calls to ``probe``, 478 + ``disconnect``, ``pre_reset``, and ``post_reset``; the USB core guarantees that 484 479 this is true of autosuspend/autoresume events as well. 485 480 486 481 If a driver wants to block all suspend/resume calls during some 487 482 critical section, the best way is to lock the device and call 488 - usb_autopm_get_interface() (and do the reverse at the end of the 483 + :c:func:`usb_autopm_get_interface` (and do the reverse at the end of the 489 484 critical section). Holding the device semaphore will block all 490 - external PM calls, and the usb_autopm_get_interface() will prevent any 485 + external PM calls, and the :c:func:`usb_autopm_get_interface` will prevent any 491 486 internal PM calls, even if it fails. (Exercise: Why?) 492 487 493 488 494 - Interaction between dynamic PM and system PM 495 - -------------------------------------------- 489 + Interaction between dynamic PM and system PM 490 + -------------------------------------------- 496 491 497 492 Dynamic power management and system power management can interact in 498 493 a couple of ways. ··· 517 512 and on the hardware and firmware design. 518 513 519 514 520 - xHCI hardware link PM 521 - --------------------- 515 + xHCI hardware link PM 516 + --------------------- 522 517 523 518 xHCI host controller provides hardware link power management to usb2.0 524 519 (xHCI 1.0 feature) and usb3.0 devices which support link PM. By ··· 527 522 which state device can enter and resume very quickly. 528 523 529 524 The user interface for controlling hardware LPM is located in the 530 - power/ subdirectory of each USB device's sysfs directory, that is, in 531 - /sys/bus/usb/devices/.../power/ where "..." is the device's ID. The 532 - relevant attribute files are usb2_hardware_lpm and usb3_hardware_lpm. 525 + ``power/`` subdirectory of each USB device's sysfs directory, that is, in 526 + ``/sys/bus/usb/devices/.../power/`` where "..." is the device's ID. The 527 + relevant attribute files are ``usb2_hardware_lpm`` and ``usb3_hardware_lpm``. 533 528 534 - power/usb2_hardware_lpm 529 + ``power/usb2_hardware_lpm`` 535 530 536 531 When a USB2 device which support LPM is plugged to a 537 532 xHCI host root hub which support software LPM, the ··· 542 537 can write y/Y/1 or n/N/0 to the file to enable/disable 543 538 USB2 hardware LPM manually. This is for test purpose mainly. 544 539 545 - power/usb3_hardware_lpm_u1 546 - power/usb3_hardware_lpm_u2 540 + ``power/usb3_hardware_lpm_u1`` 541 + ``power/usb3_hardware_lpm_u2`` 547 542 548 543 When a USB 3.0 lpm-capable device is plugged in to a 549 544 xHCI host which supports link PM, it will check if U1 ··· 555 550 indicating whether or not USB3 hardware LPM U1 or U2 556 551 is enabled for the device. 557 552 558 - USB Port Power Control 559 - ---------------------- 553 + USB Port Power Control 554 + ---------------------- 560 555 561 556 In addition to suspending endpoint devices and enabling hardware 562 557 controlled link power management, the USB subsystem also has the 563 558 capability to disable power to ports under some conditions. Power is 564 - controlled through Set/ClearPortFeature(PORT_POWER) requests to a hub. 559 + controlled through ``Set/ClearPortFeature(PORT_POWER)`` requests to a hub. 565 560 In the case of a root or platform-internal hub the host controller 566 - driver translates PORT_POWER requests into platform firmware (ACPI) 561 + driver translates ``PORT_POWER`` requests into platform firmware (ACPI) 567 562 method calls to set the port power state. For more background see the 568 - Linux Plumbers Conference 2012 slides [1] and video [2]: 563 + Linux Plumbers Conference 2012 slides [#f1]_ and video [#f2]_: 569 564 570 - Upon receiving a ClearPortFeature(PORT_POWER) request a USB port is 571 - logically off, and may trigger the actual loss of VBUS to the port [3]. 565 + Upon receiving a ``ClearPortFeature(PORT_POWER)`` request a USB port is 566 + logically off, and may trigger the actual loss of VBUS to the port [#f3]_. 572 567 VBUS may be maintained in the case where a hub gangs multiple ports into 573 568 a shared power well causing power to remain until all ports in the gang 574 569 are turned off. VBUS may also be maintained by hub ports configured for 575 570 a charging application. In any event a logically off port will lose 576 571 connection with its device, not respond to hotplug events, and not 577 - respond to remote wakeup events*. 572 + respond to remote wakeup events. 578 573 579 - WARNING: turning off a port may result in the inability to hot add a device. 580 - Please see "User Interface for Port Power Control" for details. 574 + .. warning:: 575 + 576 + turning off a port may result in the inability to hot add a device. 577 + Please see "User Interface for Port Power Control" for details. 581 578 582 579 As far as the effect on the device itself it is similar to what a device 583 580 goes through during system suspend, i.e. the power session is lost. Any ··· 588 581 implementation shares the same device recovery path (and honors the same 589 582 quirks) as the system resume path for the hub. 590 583 591 - [1]: http://dl.dropbox.com/u/96820575/sarah-sharp-lpt-port-power-off2-mini.pdf 592 - [2]: http://linuxplumbers.ubicast.tv/videos/usb-port-power-off-kerneluserspace-api/ 593 - [3]: USB 3.1 Section 10.12 594 - * wakeup note: if a device is configured to send wakeup events the port 584 + .. [#f1] 585 + 586 + http://dl.dropbox.com/u/96820575/sarah-sharp-lpt-port-power-off2-mini.pdf 587 + 588 + .. [#f2] 589 + 590 + http://linuxplumbers.ubicast.tv/videos/usb-port-power-off-kerneluserspace-api/ 591 + 592 + .. [#f3] 593 + 594 + USB 3.1 Section 10.12 595 + 596 + wakeup note: if a device is configured to send wakeup events the port 595 597 power control implementation will block poweroff attempts on that 596 598 port. 597 599 598 600 599 - User Interface for Port Power Control 600 - ------------------------------------- 601 + User Interface for Port Power Control 602 + ------------------------------------- 601 603 602 604 The port power control mechanism uses the PM runtime system. Poweroff is 603 - requested by clearing the power/pm_qos_no_power_off flag of the port device 605 + requested by clearing the ``power/pm_qos_no_power_off`` flag of the port device 604 606 (defaults to 1). If the port is disconnected it will immediately receive a 605 - ClearPortFeature(PORT_POWER) request. Otherwise, it will honor the pm runtime 606 - rules and require the attached child device and all descendants to be suspended. 607 - This mechanism is dependent on the hub advertising port power switching in its 608 - hub descriptor (wHubCharacteristics logical power switching mode field). 607 + ``ClearPortFeature(PORT_POWER)`` request. Otherwise, it will honor the pm 608 + runtime rules and require the attached child device and all descendants to be 609 + suspended. This mechanism is dependent on the hub advertising port power 610 + switching in its hub descriptor (wHubCharacteristics logical power switching 611 + mode field). 609 612 610 613 Note, some interface devices/drivers do not support autosuspend. Userspace may 611 - need to unbind the interface drivers before the usb_device will suspend. An 612 - unbound interface device is suspended by default. When unbinding, be careful 613 - to unbind interface drivers, not the driver of the parent usb device. Also, 614 - leave hub interface drivers bound. If the driver for the usb device (not 615 - interface) is unbound the kernel is no longer able to resume the device. If a 616 - hub interface driver is unbound, control of its child ports is lost and all 617 - attached child-devices will disconnect. A good rule of thumb is that if the 618 - 'driver/module' link for a device points to /sys/module/usbcore then unbinding 619 - it will interfere with port power control. 614 + need to unbind the interface drivers before the :c:type:`usb_device` will 615 + suspend. An unbound interface device is suspended by default. When unbinding, 616 + be careful to unbind interface drivers, not the driver of the parent usb 617 + device. Also, leave hub interface drivers bound. If the driver for the usb 618 + device (not interface) is unbound the kernel is no longer able to resume the 619 + device. If a hub interface driver is unbound, control of its child ports is 620 + lost and all attached child-devices will disconnect. A good rule of thumb is 621 + that if the 'driver/module' link for a device points to 622 + ``/sys/module/usbcore`` then unbinding it will interfere with port power 623 + control. 620 624 621 625 Example of the relevant files for port power control. Note, in this example 622 - these files are relative to a usb hub device (prefix). 626 + these files are relative to a usb hub device (prefix):: 623 627 624 628 prefix=/sys/devices/pci0000:00/0000:00:14.0/usb3/3-1 625 629 ··· 649 631 650 632 In addition to these files some ports may have a 'peer' link to a port on 651 633 another hub. The expectation is that all superspeed ports have a 652 - hi-speed peer. 634 + hi-speed peer:: 653 635 654 - $prefix/3-1:1.0/3-1-port1/peer -> ../../../../usb2/2-1/2-1:1.0/2-1-port1 655 - ../../../../usb2/2-1/2-1:1.0/2-1-port1/peer -> ../../../../usb3/3-1/3-1:1.0/3-1-port1 636 + $prefix/3-1:1.0/3-1-port1/peer -> ../../../../usb2/2-1/2-1:1.0/2-1-port1 637 + ../../../../usb2/2-1/2-1:1.0/2-1-port1/peer -> ../../../../usb3/3-1/3-1:1.0/3-1-port1 656 638 657 639 Distinct from 'companion ports', or 'ehci/xhci shared switchover ports' 658 640 peer ports are simply the hi-speed and superspeed interface pins that ··· 663 645 connection and attempt to connect to the hi-speed pins. The 664 646 implementation takes steps to prevent this: 665 647 666 - 1/ Port suspend is sequenced to guarantee that hi-speed ports are powered-off 648 + 1. Port suspend is sequenced to guarantee that hi-speed ports are powered-off 667 649 before their superspeed peer is permitted to power-off. The implication is 668 - that the setting pm_qos_no_power_off to zero on a superspeed port may not cause 669 - the port to power-off until its highspeed peer has gone to its runtime suspend 670 - state. Userspace must take care to order the suspensions if it wants to 671 - guarantee that a superspeed port will power-off. 650 + that the setting ``pm_qos_no_power_off`` to zero on a superspeed port may 651 + not cause the port to power-off until its highspeed peer has gone to its 652 + runtime suspend state. Userspace must take care to order the suspensions 653 + if it wants to guarantee that a superspeed port will power-off. 672 654 673 - 2/ Port resume is sequenced to force a superspeed port to power-on prior to its 655 + 2. Port resume is sequenced to force a superspeed port to power-on prior to its 674 656 highspeed peer. 675 657 676 - 3/ Port resume always triggers an attached child device to resume. After a 658 + 3. Port resume always triggers an attached child device to resume. After a 677 659 power session is lost the device may have been removed, or need reset. 678 660 Resuming the child device when the parent port regains power resolves those 679 - states and clamps the maximum port power cycle frequency at the rate the child 680 - device can suspend (autosuspend-delay) and resume (reset-resume latency). 661 + states and clamps the maximum port power cycle frequency at the rate the 662 + child device can suspend (autosuspend-delay) and resume (reset-resume 663 + latency). 681 664 682 665 Sysfs files relevant for port power control: 683 - <hubdev-portX>/power/pm_qos_no_power_off: 666 + 667 + ``<hubdev-portX>/power/pm_qos_no_power_off``: 684 668 This writable flag controls the state of an idle port. 685 669 Once all children and descendants have suspended the 686 670 port may suspend/poweroff provided that ··· 690 670 '1' the port will remain active/powered regardless of 691 671 the stats of descendants. Defaults to 1. 692 672 693 - <hubdev-portX>/power/runtime_status: 673 + ``<hubdev-portX>/power/runtime_status``: 694 674 This file reflects whether the port is 'active' (power is on) 695 675 or 'suspended' (logically off). There is no indication to 696 676 userspace whether VBUS is still supplied. 697 677 698 - <hubdev-portX>/connect_type: 678 + ``<hubdev-portX>/connect_type``: 699 679 An advisory read-only flag to userspace indicating the 700 680 location and connection type of the port. It returns 701 681 one of four values 'hotplug', 'hardwired', 'not used', 702 682 and 'unknown'. All values, besides unknown, are set by 703 683 platform firmware. 704 684 705 - "hotplug" indicates an externally connectable/visible 685 + ``hotplug`` indicates an externally connectable/visible 706 686 port on the platform. Typically userspace would choose 707 687 to keep such a port powered to handle new device 708 688 connection events. 709 689 710 - "hardwired" refers to a port that is not visible but 690 + ``hardwired`` refers to a port that is not visible but 711 691 connectable. Examples are internal ports for USB 712 692 bluetooth that can be disconnected via an external 713 693 switch or a port with a hardwired USB camera. It is ··· 718 698 powering off, or to activate the port prior to enabling 719 699 connection via a switch. 720 700 721 - "not used" refers to an internal port that is expected 701 + ``not used`` refers to an internal port that is expected 722 702 to never have a device connected to it. These may be 723 703 empty internal ports, or ports that are not physically 724 704 exposed on a platform. Considered safe to be 725 705 powered-off at all times. 726 706 727 - "unknown" means platform firmware does not provide 707 + ``unknown`` means platform firmware does not provide 728 708 information for this port. Most commonly refers to 729 709 external hub ports which should be considered 'hotplug' 730 710 for policy decisions. 731 711 732 - NOTE1: since we are relying on the BIOS to get this ACPI 733 - information correct, the USB port descriptions may be 734 - missing or wrong. 712 + .. note:: 735 713 736 - NOTE2: Take care in clearing pm_qos_no_power_off. Once 737 - power is off this port will 738 - not respond to new connect events. 714 + - since we are relying on the BIOS to get this ACPI 715 + information correct, the USB port descriptions may 716 + be missing or wrong. 717 + 718 + - Take care in clearing ``pm_qos_no_power_off``. Once 719 + power is off this port will 720 + not respond to new connect events. 739 721 740 722 Once a child device is attached additional constraints are 741 723 applied before the port is allowed to poweroff. 742 724 743 - <child>/power/control: 744 - Must be 'auto', and the port will not 745 - power down until <child>/power/runtime_status 725 + ``<child>/power/control``: 726 + Must be ``auto``, and the port will not 727 + power down until ``<child>/power/runtime_status`` 746 728 reflects the 'suspended' state. Default 747 729 value is controlled by child device driver. 748 730 749 - <child>/power/persist: 750 - This defaults to '1' for most devices and indicates if 731 + ``<child>/power/persist``: 732 + This defaults to ``1`` for most devices and indicates if 751 733 kernel can persist the device's configuration across a 752 734 power session loss (suspend / port-power event). When 753 - this value is '0' (quirky devices), port poweroff is 735 + this value is ``0`` (quirky devices), port poweroff is 754 736 disabled. 755 737 756 - <child>/driver/unbind: 738 + ``<child>/driver/unbind``: 757 739 Wakeup capable devices will block port poweroff. At 758 740 this time the only mechanism to clear the usb-internal 759 741 wakeup-capability for an interface device is to unbind 760 742 its driver. 761 743 762 - Summary of poweroff pre-requisite settings relative to a port device: 744 + Summary of poweroff pre-requisite settings relative to a port device:: 763 745 764 746 echo 0 > power/pm_qos_no_power_off 765 747 echo 0 > peer/power/pm_qos_no_power_off # if it exists ··· 769 747 echo auto > <child>/power/control 770 748 echo 1 > <child>/power/persist # this is the default value 771 749 772 - Suggested Userspace Port Power Policy 773 - ------------------------------------- 750 + Suggested Userspace Port Power Policy 751 + ------------------------------------- 774 752 775 753 As noted above userspace needs to be careful and deliberate about what 776 754 ports are enabled for poweroff. 777 755 778 756 The default configuration is that all ports start with 779 - power/pm_qos_no_power_off set to '1' causing ports to always remain 757 + ``power/pm_qos_no_power_off`` set to ``1`` causing ports to always remain 780 758 active. 781 759 782 760 Given confidence in the platform firmware's description of the ports ··· 786 764 connection switch for the port. 787 765 788 766 A more aggressive userspace policy is to enable USB port power off for 789 - all ports (set <hubdev-portX>/power/pm_qos_no_power_off to '0') when 767 + all ports (set ``<hubdev-portX>/power/pm_qos_no_power_off`` to ``0``) when 790 768 some external factor indicates the user has stopped interacting with the 791 769 system. For example, a distro may want to enable power off all USB 792 770 ports when the screen blanks, and re-power them when the screen becomes
-390
Documentation/usb/proc_usb_info.txt
··· 1 - /proc/bus/usb filesystem output 2 - =============================== 3 - (version 2010.09.13) 4 - 5 - 6 - The usbfs filesystem for USB devices is traditionally mounted at 7 - /proc/bus/usb. It provides the /proc/bus/usb/devices file, as well as 8 - the /proc/bus/usb/BBB/DDD files. 9 - 10 - In many modern systems the usbfs filesystem isn't used at all. Instead 11 - USB device nodes are created under /dev/usb/ or someplace similar. The 12 - "devices" file is available in debugfs, typically as 13 - /sys/kernel/debug/usb/devices. 14 - 15 - 16 - **NOTE**: If /proc/bus/usb appears empty, and a host controller 17 - driver has been linked, then you need to mount the 18 - filesystem. Issue the command (as root): 19 - 20 - mount -t usbfs none /proc/bus/usb 21 - 22 - An alternative and more permanent method would be to add 23 - 24 - none /proc/bus/usb usbfs defaults 0 0 25 - 26 - to /etc/fstab. This will mount usbfs at each reboot. 27 - You can then issue `cat /proc/bus/usb/devices` to extract 28 - USB device information, and user mode drivers can use usbfs 29 - to interact with USB devices. 30 - 31 - There are a number of mount options supported by usbfs. 32 - Consult the source code (linux/drivers/usb/core/inode.c) for 33 - information about those options. 34 - 35 - **NOTE**: The filesystem has been renamed from "usbdevfs" to 36 - "usbfs", to reduce confusion with "devfs". You may 37 - still see references to the older "usbdevfs" name. 38 - 39 - For more information on mounting the usbfs file system, see the 40 - "USB Device Filesystem" section of the USB Guide. The latest copy 41 - of the USB Guide can be found at http://www.linux-usb.org/ 42 - 43 - 44 - THE /proc/bus/usb/BBB/DDD FILES: 45 - -------------------------------- 46 - Each connected USB device has one file. The BBB indicates the bus 47 - number. The DDD indicates the device address on that bus. Both 48 - of these numbers are assigned sequentially, and can be reused, so 49 - you can't rely on them for stable access to devices. For example, 50 - it's relatively common for devices to re-enumerate while they are 51 - still connected (perhaps someone jostled their power supply, hub, 52 - or USB cable), so a device might be 002/027 when you first connect 53 - it and 002/048 sometime later. 54 - 55 - These files can be read as binary data. The binary data consists 56 - of first the device descriptor, then the descriptors for each 57 - configuration of the device. Multi-byte fields in the device descriptor 58 - are converted to host endianness by the kernel. The configuration 59 - descriptors are in bus endian format! The configuration descriptor 60 - are wTotalLength bytes apart. If a device returns less configuration 61 - descriptor data than indicated by wTotalLength there will be a hole in 62 - the file for the missing bytes. This information is also shown 63 - in text form by the /proc/bus/usb/devices file, described later. 64 - 65 - These files may also be used to write user-level drivers for the USB 66 - devices. You would open the /proc/bus/usb/BBB/DDD file read/write, 67 - read its descriptors to make sure it's the device you expect, and then 68 - bind to an interface (or perhaps several) using an ioctl call. You 69 - would issue more ioctls to the device to communicate to it using 70 - control, bulk, or other kinds of USB transfers. The IOCTLs are 71 - listed in the <linux/usbdevice_fs.h> file, and at this writing the 72 - source code (linux/drivers/usb/core/devio.c) is the primary reference 73 - for how to access devices through those files. 74 - 75 - Note that since by default these BBB/DDD files are writable only by 76 - root, only root can write such user mode drivers. You can selectively 77 - grant read/write permissions to other users by using "chmod". Also, 78 - usbfs mount options such as "devmode=0666" may be helpful. 79 - 80 - 81 - 82 - THE /proc/bus/usb/devices FILE: 83 - ------------------------------- 84 - In /proc/bus/usb/devices, each device's output has multiple 85 - lines of ASCII output. 86 - I made it ASCII instead of binary on purpose, so that someone 87 - can obtain some useful data from it without the use of an 88 - auxiliary program. However, with an auxiliary program, the numbers 89 - in the first 4 columns of each "T:" line (topology info: 90 - Lev, Prnt, Port, Cnt) can be used to build a USB topology diagram. 91 - 92 - Each line is tagged with a one-character ID for that line: 93 - 94 - T = Topology (etc.) 95 - B = Bandwidth (applies only to USB host controllers, which are 96 - virtualized as root hubs) 97 - D = Device descriptor info. 98 - P = Product ID info. (from Device descriptor, but they won't fit 99 - together on one line) 100 - S = String descriptors. 101 - C = Configuration descriptor info. (* = active configuration) 102 - I = Interface descriptor info. 103 - E = Endpoint descriptor info. 104 - 105 - ======================================================================= 106 - 107 - /proc/bus/usb/devices output format: 108 - 109 - Legend: 110 - d = decimal number (may have leading spaces or 0's) 111 - x = hexadecimal number (may have leading spaces or 0's) 112 - s = string 113 - 114 - 115 - Topology info: 116 - 117 - T: Bus=dd Lev=dd Prnt=dd Port=dd Cnt=dd Dev#=ddd Spd=dddd MxCh=dd 118 - | | | | | | | | |__MaxChildren 119 - | | | | | | | |__Device Speed in Mbps 120 - | | | | | | |__DeviceNumber 121 - | | | | | |__Count of devices at this level 122 - | | | | |__Connector/Port on Parent for this device 123 - | | | |__Parent DeviceNumber 124 - | | |__Level in topology for this bus 125 - | |__Bus number 126 - |__Topology info tag 127 - 128 - Speed may be: 129 - 1.5 Mbit/s for low speed USB 130 - 12 Mbit/s for full speed USB 131 - 480 Mbit/s for high speed USB (added for USB 2.0); 132 - also used for Wireless USB, which has no fixed speed 133 - 5000 Mbit/s for SuperSpeed USB (added for USB 3.0) 134 - 135 - For reasons lost in the mists of time, the Port number is always 136 - too low by 1. For example, a device plugged into port 4 will 137 - show up with "Port=03". 138 - 139 - Bandwidth info: 140 - B: Alloc=ddd/ddd us (xx%), #Int=ddd, #Iso=ddd 141 - | | | |__Number of isochronous requests 142 - | | |__Number of interrupt requests 143 - | |__Total Bandwidth allocated to this bus 144 - |__Bandwidth info tag 145 - 146 - Bandwidth allocation is an approximation of how much of one frame 147 - (millisecond) is in use. It reflects only periodic transfers, which 148 - are the only transfers that reserve bandwidth. Control and bulk 149 - transfers use all other bandwidth, including reserved bandwidth that 150 - is not used for transfers (such as for short packets). 151 - 152 - The percentage is how much of the "reserved" bandwidth is scheduled by 153 - those transfers. For a low or full speed bus (loosely, "USB 1.1"), 154 - 90% of the bus bandwidth is reserved. For a high speed bus (loosely, 155 - "USB 2.0") 80% is reserved. 156 - 157 - 158 - Device descriptor info & Product ID info: 159 - 160 - D: Ver=x.xx Cls=xx(s) Sub=xx Prot=xx MxPS=dd #Cfgs=dd 161 - P: Vendor=xxxx ProdID=xxxx Rev=xx.xx 162 - 163 - where 164 - D: Ver=x.xx Cls=xx(sssss) Sub=xx Prot=xx MxPS=dd #Cfgs=dd 165 - | | | | | | |__NumberConfigurations 166 - | | | | | |__MaxPacketSize of Default Endpoint 167 - | | | | |__DeviceProtocol 168 - | | | |__DeviceSubClass 169 - | | |__DeviceClass 170 - | |__Device USB version 171 - |__Device info tag #1 172 - 173 - where 174 - P: Vendor=xxxx ProdID=xxxx Rev=xx.xx 175 - | | | |__Product revision number 176 - | | |__Product ID code 177 - | |__Vendor ID code 178 - |__Device info tag #2 179 - 180 - 181 - String descriptor info: 182 - 183 - S: Manufacturer=ssss 184 - | |__Manufacturer of this device as read from the device. 185 - | For USB host controller drivers (virtual root hubs) this may 186 - | be omitted, or (for newer drivers) will identify the kernel 187 - | version and the driver which provides this hub emulation. 188 - |__String info tag 189 - 190 - S: Product=ssss 191 - | |__Product description of this device as read from the device. 192 - | For older USB host controller drivers (virtual root hubs) this 193 - | indicates the driver; for newer ones, it's a product (and vendor) 194 - | description that often comes from the kernel's PCI ID database. 195 - |__String info tag 196 - 197 - S: SerialNumber=ssss 198 - | |__Serial Number of this device as read from the device. 199 - | For USB host controller drivers (virtual root hubs) this is 200 - | some unique ID, normally a bus ID (address or slot name) that 201 - | can't be shared with any other device. 202 - |__String info tag 203 - 204 - 205 - 206 - Configuration descriptor info: 207 - 208 - C:* #Ifs=dd Cfg#=dd Atr=xx MPwr=dddmA 209 - | | | | | |__MaxPower in mA 210 - | | | | |__Attributes 211 - | | | |__ConfiguratioNumber 212 - | | |__NumberOfInterfaces 213 - | |__ "*" indicates the active configuration (others are " ") 214 - |__Config info tag 215 - 216 - USB devices may have multiple configurations, each of which act 217 - rather differently. For example, a bus-powered configuration 218 - might be much less capable than one that is self-powered. Only 219 - one device configuration can be active at a time; most devices 220 - have only one configuration. 221 - 222 - Each configuration consists of one or more interfaces. Each 223 - interface serves a distinct "function", which is typically bound 224 - to a different USB device driver. One common example is a USB 225 - speaker with an audio interface for playback, and a HID interface 226 - for use with software volume control. 227 - 228 - 229 - Interface descriptor info (can be multiple per Config): 230 - 231 - I:* If#=dd Alt=dd #EPs=dd Cls=xx(sssss) Sub=xx Prot=xx Driver=ssss 232 - | | | | | | | | |__Driver name 233 - | | | | | | | | or "(none)" 234 - | | | | | | | |__InterfaceProtocol 235 - | | | | | | |__InterfaceSubClass 236 - | | | | | |__InterfaceClass 237 - | | | | |__NumberOfEndpoints 238 - | | | |__AlternateSettingNumber 239 - | | |__InterfaceNumber 240 - | |__ "*" indicates the active altsetting (others are " ") 241 - |__Interface info tag 242 - 243 - A given interface may have one or more "alternate" settings. 244 - For example, default settings may not use more than a small 245 - amount of periodic bandwidth. To use significant fractions 246 - of bus bandwidth, drivers must select a non-default altsetting. 247 - 248 - Only one setting for an interface may be active at a time, and 249 - only one driver may bind to an interface at a time. Most devices 250 - have only one alternate setting per interface. 251 - 252 - 253 - Endpoint descriptor info (can be multiple per Interface): 254 - 255 - E: Ad=xx(s) Atr=xx(ssss) MxPS=dddd Ivl=dddss 256 - | | | | |__Interval (max) between transfers 257 - | | | |__EndpointMaxPacketSize 258 - | | |__Attributes(EndpointType) 259 - | |__EndpointAddress(I=In,O=Out) 260 - |__Endpoint info tag 261 - 262 - The interval is nonzero for all periodic (interrupt or isochronous) 263 - endpoints. For high speed endpoints the transfer interval may be 264 - measured in microseconds rather than milliseconds. 265 - 266 - For high speed periodic endpoints, the "MaxPacketSize" reflects 267 - the per-microframe data transfer size. For "high bandwidth" 268 - endpoints, that can reflect two or three packets (for up to 269 - 3KBytes every 125 usec) per endpoint. 270 - 271 - With the Linux-USB stack, periodic bandwidth reservations use the 272 - transfer intervals and sizes provided by URBs, which can be less 273 - than those found in endpoint descriptor. 274 - 275 - 276 - ======================================================================= 277 - 278 - 279 - If a user or script is interested only in Topology info, for 280 - example, use something like "grep ^T: /proc/bus/usb/devices" 281 - for only the Topology lines. A command like 282 - "grep -i ^[tdp]: /proc/bus/usb/devices" can be used to list 283 - only the lines that begin with the characters in square brackets, 284 - where the valid characters are TDPCIE. With a slightly more able 285 - script, it can display any selected lines (for example, only T, D, 286 - and P lines) and change their output format. (The "procusb" 287 - Perl script is the beginning of this idea. It will list only 288 - selected lines [selected from TBDPSCIE] or "All" lines from 289 - /proc/bus/usb/devices.) 290 - 291 - The Topology lines can be used to generate a graphic/pictorial 292 - of the USB devices on a system's root hub. (See more below 293 - on how to do this.) 294 - 295 - The Interface lines can be used to determine what driver is 296 - being used for each device, and which altsetting it activated. 297 - 298 - The Configuration lines could be used to list maximum power 299 - (in milliamps) that a system's USB devices are using. 300 - For example, "grep ^C: /proc/bus/usb/devices". 301 - 302 - 303 - Here's an example, from a system which has a UHCI root hub, 304 - an external hub connected to the root hub, and a mouse and 305 - a serial converter connected to the external hub. 306 - 307 - T: Bus=00 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#= 1 Spd=12 MxCh= 2 308 - B: Alloc= 28/900 us ( 3%), #Int= 2, #Iso= 0 309 - D: Ver= 1.00 Cls=09(hub ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1 310 - P: Vendor=0000 ProdID=0000 Rev= 0.00 311 - S: Product=USB UHCI Root Hub 312 - S: SerialNumber=dce0 313 - C:* #Ifs= 1 Cfg#= 1 Atr=40 MxPwr= 0mA 314 - I: If#= 0 Alt= 0 #EPs= 1 Cls=09(hub ) Sub=00 Prot=00 Driver=hub 315 - E: Ad=81(I) Atr=03(Int.) MxPS= 8 Ivl=255ms 316 - 317 - T: Bus=00 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#= 2 Spd=12 MxCh= 4 318 - D: Ver= 1.00 Cls=09(hub ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1 319 - P: Vendor=0451 ProdID=1446 Rev= 1.00 320 - C:* #Ifs= 1 Cfg#= 1 Atr=e0 MxPwr=100mA 321 - I: If#= 0 Alt= 0 #EPs= 1 Cls=09(hub ) Sub=00 Prot=00 Driver=hub 322 - E: Ad=81(I) Atr=03(Int.) MxPS= 1 Ivl=255ms 323 - 324 - T: Bus=00 Lev=02 Prnt=02 Port=00 Cnt=01 Dev#= 3 Spd=1.5 MxCh= 0 325 - D: Ver= 1.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1 326 - P: Vendor=04b4 ProdID=0001 Rev= 0.00 327 - C:* #Ifs= 1 Cfg#= 1 Atr=80 MxPwr=100mA 328 - I: If#= 0 Alt= 0 #EPs= 1 Cls=03(HID ) Sub=01 Prot=02 Driver=mouse 329 - E: Ad=81(I) Atr=03(Int.) MxPS= 3 Ivl= 10ms 330 - 331 - T: Bus=00 Lev=02 Prnt=02 Port=02 Cnt=02 Dev#= 4 Spd=12 MxCh= 0 332 - D: Ver= 1.00 Cls=00(>ifc ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1 333 - P: Vendor=0565 ProdID=0001 Rev= 1.08 334 - S: Manufacturer=Peracom Networks, Inc. 335 - S: Product=Peracom USB to Serial Converter 336 - C:* #Ifs= 1 Cfg#= 1 Atr=a0 MxPwr=100mA 337 - I: If#= 0 Alt= 0 #EPs= 3 Cls=00(>ifc ) Sub=00 Prot=00 Driver=serial 338 - E: Ad=81(I) Atr=02(Bulk) MxPS= 64 Ivl= 16ms 339 - E: Ad=01(O) Atr=02(Bulk) MxPS= 16 Ivl= 16ms 340 - E: Ad=82(I) Atr=03(Int.) MxPS= 8 Ivl= 8ms 341 - 342 - 343 - Selecting only the "T:" and "I:" lines from this (for example, by using 344 - "procusb ti"), we have: 345 - 346 - T: Bus=00 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#= 1 Spd=12 MxCh= 2 347 - T: Bus=00 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#= 2 Spd=12 MxCh= 4 348 - I: If#= 0 Alt= 0 #EPs= 1 Cls=09(hub ) Sub=00 Prot=00 Driver=hub 349 - T: Bus=00 Lev=02 Prnt=02 Port=00 Cnt=01 Dev#= 3 Spd=1.5 MxCh= 0 350 - I: If#= 0 Alt= 0 #EPs= 1 Cls=03(HID ) Sub=01 Prot=02 Driver=mouse 351 - T: Bus=00 Lev=02 Prnt=02 Port=02 Cnt=02 Dev#= 4 Spd=12 MxCh= 0 352 - I: If#= 0 Alt= 0 #EPs= 3 Cls=00(>ifc ) Sub=00 Prot=00 Driver=serial 353 - 354 - 355 - Physically this looks like (or could be converted to): 356 - 357 - +------------------+ 358 - | PC/root_hub (12)| Dev# = 1 359 - +------------------+ (nn) is Mbps. 360 - Level 0 | CN.0 | CN.1 | [CN = connector/port #] 361 - +------------------+ 362 - / 363 - / 364 - +-----------------------+ 365 - Level 1 | Dev#2: 4-port hub (12)| 366 - +-----------------------+ 367 - |CN.0 |CN.1 |CN.2 |CN.3 | 368 - +-----------------------+ 369 - \ \____________________ 370 - \_____ \ 371 - \ \ 372 - +--------------------+ +--------------------+ 373 - Level 2 | Dev# 3: mouse (1.5)| | Dev# 4: serial (12)| 374 - +--------------------+ +--------------------+ 375 - 376 - 377 - 378 - Or, in a more tree-like structure (ports [Connectors] without 379 - connections could be omitted): 380 - 381 - PC: Dev# 1, root hub, 2 ports, 12 Mbps 382 - |_ CN.0: Dev# 2, hub, 4 ports, 12 Mbps 383 - |_ CN.0: Dev #3, mouse, 1.5 Mbps 384 - |_ CN.1: 385 - |_ CN.2: Dev #4, serial, 12 Mbps 386 - |_ CN.3: 387 - |_ CN.1: 388 - 389 - 390 - ### END ###
+10
Documentation/userspace-api/conf.py
··· 1 + # -*- coding: utf-8; mode: python -*- 2 + 3 + project = "The Linux kernel user-space API guide" 4 + 5 + tags.add("subproject") 6 + 7 + latex_documents = [ 8 + ('index', 'userspace-api.tex', project, 9 + 'The kernel development community', 'manual'), 10 + ]
+26
Documentation/userspace-api/index.rst
··· 1 + ===================================== 2 + The Linux kernel user-space API guide 3 + ===================================== 4 + 5 + .. _man-pages: https://www.kernel.org/doc/man-pages/ 6 + 7 + While much of the kernel's user-space API is documented elsewhere 8 + (particularly in the man-pages_ project), some user-space information can 9 + also be found in the kernel tree itself. This manual is intended to be the 10 + place where this information is gathered. 11 + 12 + .. class:: toc-title 13 + 14 + Table of contents 15 + 16 + .. toctree:: 17 + :maxdepth: 2 18 + 19 + unshare 20 + 21 + .. only:: subproject and html 22 + 23 + Indices 24 + ======= 25 + 26 + * :ref:`genindex`
+4 -4
Documentation/vfio-mediated-device.txt
··· 217 217 218 218 * [<type-id>] 219 219 220 - The [<type-id>] name is created by adding the the device driver string as a 221 - prefix to the string provided by the vendor driver. This format of this name 222 - is as follows: 220 + The [<type-id>] name is created by adding the device driver string as a prefix 221 + to the string provided by the vendor driver. This format of this name is as 222 + follows: 223 223 224 224 sprintf(buf, "%s-%s", dev_driver_string(parent->dev), group->name); 225 225 ··· 380 380 /dev/ttyS1, UART: 16550A, Port: 0xc150, IRQ: 10 381 381 /dev/ttyS2, UART: 16550A, Port: 0xc158, IRQ: 10 382 382 383 - 6. Using a minicom or any terminal enulation program, open port /dev/ttyS1 or 383 + 6. Using minicom or any terminal emulation program, open port /dev/ttyS1 or 384 384 /dev/ttyS2 with hardware flow control disabled. 385 385 386 386 7. Type data on the minicom terminal or send data to the terminal emulation
+1 -1
Documentation/zorro.txt
··· 11 11 The Zorro bus is the bus used in the Amiga family of computers. Thanks to 12 12 AutoConfig(tm), it's 100% Plug-and-Play. 13 13 14 - There are two types of Zorro busses, Zorro II and Zorro III: 14 + There are two types of Zorro buses, Zorro II and Zorro III: 15 15 16 16 - The Zorro II address space is 24-bit and lies within the first 16 MB of the 17 17 Amiga's address map.
+1 -1
MAINTAINERS
··· 6036 6036 T: git git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-hsi.git 6037 6037 S: Maintained 6038 6038 F: Documentation/ABI/testing/sysfs-bus-hsi 6039 - F: Documentation/device-drivers/serial-interfaces.rst 6039 + F: Documentation/driver-api/hsi.rst 6040 6040 F: drivers/hsi/ 6041 6041 F: include/linux/hsi/ 6042 6042 F: include/uapi/linux/hsi/
+2 -2
Makefile
··· 172 172 # Use 'make C=2' to enable checking of *all* source files, regardless 173 173 # of whether they are re-compiled or not. 174 174 # 175 - # See the file "Documentation/sparse.txt" for more details, including 176 - # where to get the "sparse" utility. 175 + # See the file "Documentation/dev-tools/sparse.rst" for more details, 176 + # including where to get the "sparse" utility. 177 177 178 178 ifeq ("$(origin C)", "command line") 179 179 KBUILD_CHECKSRC = $(C)
+4 -3
block/genhd.c
··· 271 271 /** 272 272 * register_blkdev - register a new block device 273 273 * 274 - * @major: the requested major device number [1..255]. If @major=0, try to 274 + * @major: the requested major device number [1..255]. If @major = 0, try to 275 275 * allocate any unused major number. 276 276 * @name: the name of the new block device as a zero terminated string 277 277 * 278 278 * The @name must be unique within the system. 279 279 * 280 - * The return value depends on the @major input parameter. 280 + * The return value depends on the @major input parameter: 281 + * 281 282 * - if a major device number was requested in range [1..255] then the 282 283 * function returns zero on success, or a negative error code 283 - * - if any unused major number was requested with @major=0 parameter 284 + * - if any unused major number was requested with @major = 0 parameter 284 285 * then the return value is the allocated major number in range 285 286 * [1..255] or a negative error code otherwise 286 287 */
+15 -6
drivers/media/usb/pwc/philips.txt Documentation/media/v4l-drivers/philips.rst
··· 1 + Philips webcams (pwc driver) 2 + ============================ 3 + 1 4 This file contains some additional information for the Philips and OEM webcams. 2 5 E-mail: webcam@smcc.demon.nl Last updated: 2004-01-19 3 6 Site: http://www.smcc.demon.nl/webcam/ 4 7 5 8 As of this moment, the following cameras are supported: 9 + 6 10 * Philips PCA645 7 11 * Philips PCA646 8 12 * Philips PCVC675 ··· 93 89 compression (only useful with the plugin) 94 90 With this option you can control the compression factor that the camera 95 91 uses to squeeze the image through the USB bus. You can set the 96 - parameter between 0 and 3: 92 + parameter between 0 and 3:: 93 + 97 94 0 = prefer uncompressed images; if the requested mode is not available 98 95 in an uncompressed format, the driver will silently switch to low 99 96 compression. ··· 114 109 leds 115 110 This settings takes 2 integers, that define the on/off time for the LED 116 111 (in milliseconds). One of the interesting things that you can do with 117 - this is let the LED blink while the camera is in use. This: 112 + this is let the LED blink while the camera is in use. This:: 118 113 119 114 leds=500,500 120 115 121 - will blink the LED once every second. But with: 116 + will blink the LED once every second. But with:: 122 117 123 118 leds=0,0 124 119 ··· 146 141 A camera is specified by its type (the number from the camera model, 147 142 like PCA645, PCVC750VC, etc) and optionally the serial number (visible 148 143 in /proc/bus/usb/devices). A hint consists of a string with the following 149 - format: 144 + format:: 150 145 151 146 [type[.serialnumber]:]node 152 147 ··· 155 150 would be rather pointless). The serialnumber is separated from the type 156 151 by a '.'; the node number by a ':'. 157 152 158 - This somewhat cryptic syntax is best explained by a few examples: 153 + This somewhat cryptic syntax is best explained by a few examples:: 159 154 160 155 dev_hint=3,5 The first detected cam gets assigned 161 156 /dev/video3, the second /dev/video5. Any ··· 175 170 through /dev/video6. 176 171 177 172 Some points worth knowing: 173 + 178 174 - Serialnumbers are case sensitive and must be written full, including 179 175 leading zeroes (it's treated as a string). 180 176 - If a device node is already occupied, registration will fail and ··· 195 189 If you want to trace something, look up the bit value(s) in the table 196 190 below, add the values together and supply that to the trace variable. 197 191 192 + ====== ======= ================================================ ======= 198 193 Value Value Description Default 199 194 (dec) (hex) 195 + ====== ======= ================================================ ======= 200 196 1 0x1 Module initialization; this will log messages On 201 197 while loading and unloading the module 202 198 ··· 216 208 64 0x40 Show viewport and image sizes Off 217 209 218 210 128 0x80 PWCX debugging Off 211 + ====== ======= ================================================ ======= 219 212 220 213 For example, to trace the open() & read() functions, sum 8 + 4 = 12, 221 214 so you would supply trace=12 during insmod or modprobe. If ··· 225 216 226 217 227 218 228 - Example: 219 + Example:: 229 220 230 221 # modprobe pwc size=cif fps=15 power_save=1 231 222
+1 -1
drivers/pci/irq.c
··· 31 31 * driver). 32 32 * 33 33 * Returns: 34 - * a suggestion for fixing it (although the driver is not required to 34 + * a suggestion for fixing it (although the driver is not required to 35 35 * act on this). 36 36 */ 37 37 enum pci_lost_interrupt_reason pci_lost_interrupt(struct pci_dev *pdev)
+1 -1
drivers/staging/most/hdm-usb/hdm_usb.c
··· 490 490 * disconnect. In the interval before the hub driver starts disconnect 491 491 * processing, devices may receive such fault reports for every request. 492 492 * 493 - * See <https://www.kernel.org/doc/Documentation/usb/error-codes.txt> 493 + * See <https://www.kernel.org/doc/Documentation/driver-api/usb/error-codes.rst> 494 494 */ 495 495 static void hdm_read_completion(struct urb *urb) 496 496 {
+1 -1
drivers/usb/core/Kconfig
··· 26 26 unplugged, causing any mounted filesystems to be lost. The 27 27 persist feature can still be enabled for individual devices 28 28 through the power/persist sysfs node. See 29 - Documentation/usb/persist.txt for more info. 29 + Documentation/driver-api/usb/persist.rst for more info. 30 30 31 31 If you have any questions about this, say Y here, only say N 32 32 if you know exactly what you are doing.
+1
drivers/usb/core/message.c
··· 474 474 * significantly improve USB throughput. 475 475 * 476 476 * There are three kinds of completion for this function. 477 + * 477 478 * (1) success, where io->status is zero. The number of io->bytes 478 479 * transferred is as requested. 479 480 * (2) error, where io->status is a negative errno value. The number
+2 -2
include/linux/clk.h
··· 132 132 * @q: clk compared against p 133 133 * 134 134 * Returns true if the two struct clk pointers both point to the same hardware 135 - * clock node. Put differently, returns true if struct clk *p and struct clk *q 136 - * share the same struct clk_core object. 135 + * clock node. Put differently, returns true if @p and @q 136 + * share the same &struct clk_core object. 137 137 * 138 138 * Returns false otherwise. Note that two NULL clks are treated as matching. 139 139 */
+67
include/linux/flex_array.h
··· 61 61 FLEX_ARRAY_ELEMENTS_PER_PART(__element_size)); \ 62 62 } 63 63 64 + /** 65 + * flex_array_alloc() - Creates a flexible array. 66 + * @element_size: individual object size. 67 + * @total: maximum number of objects which can be stored. 68 + * @flags: GFP flags 69 + * 70 + * Return: Returns an object of structure flex_array. 71 + */ 64 72 struct flex_array *flex_array_alloc(int element_size, unsigned int total, 65 73 gfp_t flags); 74 + 75 + /** 76 + * flex_array_prealloc() - Ensures that memory for the elements indexed in the 77 + * range defined by start and nr_elements has been allocated. 78 + * @fa: array to allocate memory to. 79 + * @start: start address 80 + * @nr_elements: number of elements to be allocated. 81 + * @flags: GFP flags 82 + * 83 + */ 66 84 int flex_array_prealloc(struct flex_array *fa, unsigned int start, 67 85 unsigned int nr_elements, gfp_t flags); 86 + 87 + /** 88 + * flex_array_free() - Removes all elements of a flexible array. 89 + * @fa: array to be freed. 90 + */ 68 91 void flex_array_free(struct flex_array *fa); 92 + 93 + /** 94 + * flex_array_free_parts() - Removes all elements of a flexible array, but 95 + * leaves the array itself in place. 96 + * @fa: array to be emptied. 97 + */ 69 98 void flex_array_free_parts(struct flex_array *fa); 99 + 100 + /** 101 + * flex_array_put() - Stores data into a flexible array. 102 + * @fa: array where element is to be stored. 103 + * @element_nr: position to copy, must be less than the maximum specified when 104 + * the array was created. 105 + * @src: data source to be copied into the array. 106 + * @flags: GFP flags 107 + * 108 + * Return: Returns zero on success, a negative error code otherwise. 109 + */ 70 110 int flex_array_put(struct flex_array *fa, unsigned int element_nr, void *src, 71 111 gfp_t flags); 112 + 113 + /** 114 + * flex_array_clear() - Clears an individual element in the array, sets the 115 + * given element to FLEX_ARRAY_FREE. 116 + * @element_nr: element position to clear. 117 + * @fa: array to which element to be cleared belongs. 118 + * 119 + * Return: Returns zero on success, -EINVAL otherwise. 120 + */ 72 121 int flex_array_clear(struct flex_array *fa, unsigned int element_nr); 122 + 123 + /** 124 + * flex_array_get() - Retrieves data into a flexible array. 125 + * 126 + * @element_nr: Element position to retrieve data from. 127 + * @fa: array from which data is to be retrieved. 128 + * 129 + * Return: Returns a pointer to the data element, or NULL if that 130 + * particular element has never been allocated. 131 + */ 73 132 void *flex_array_get(struct flex_array *fa, unsigned int element_nr); 133 + 134 + /** 135 + * flex_array_shrink() - Reduces the allocated size of an array. 136 + * @fa: array to shrink. 137 + * 138 + * Return: Returns number of pages of memory actually freed. 139 + * 140 + */ 74 141 int flex_array_shrink(struct flex_array *fa); 75 142 76 143 #define flex_array_put_ptr(fa, nr, src, gfp) \
+4 -2
include/linux/usb/composite.h
··· 451 451 * sure doing that won't hurt too much. 452 452 * 453 453 * One notion for how to handle Wireless USB devices involves: 454 + * 454 455 * (a) a second gadget here, discovery mechanism TBD, but likely 455 456 * needing separate "register/unregister WUSB gadget" calls; 456 457 * (b) updates to usb_gadget to include flags "is it wireless", ··· 504 503 /* protects deactivations and delayed_status counts*/ 505 504 spinlock_t lock; 506 505 507 - unsigned setup_pending:1; 508 - unsigned os_desc_pending:1; 506 + /* public: */ 507 + unsigned int setup_pending:1; 508 + unsigned int os_desc_pending:1; 509 509 }; 510 510 511 511 extern int usb_string_id(struct usb_composite_dev *c);
+1 -1
include/linux/usb/gadget.h
··· 188 188 * @caps:The structure describing types and directions supported by endoint. 189 189 * @maxpacket:The maximum packet size used on this endpoint. The initial 190 190 * value can sometimes be reduced (hardware allowing), according to 191 - * the endpoint descriptor used to configure the endpoint. 191 + * the endpoint descriptor used to configure the endpoint. 192 192 * @maxpacket_limit:The maximum packet size value which can be handled by this 193 193 * endpoint. It's set once by UDC driver when endpoint is initialized, and 194 194 * should not be changed. Should not be confused with maxpacket.
+7 -5
ipc/util.c
··· 474 474 * Check user, group, other permissions for access 475 475 * to ipc resources. return 0 if allowed 476 476 * 477 - * @flag will most probably be 0 or S_...UGO from <linux/stat.h> 477 + * @flag will most probably be 0 or ``S_...UGO`` from <linux/stat.h> 478 478 */ 479 479 int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag) 480 480 { ··· 672 672 * 673 673 * This function does some common audit and permissions check for some IPC_XXX 674 674 * cmd and is called from semctl_down, shmctl_down and msgctl_down. 675 - * It must be called without any lock held and 676 - * - retrieves the ipc with the given id in the given table. 677 - * - performs some audit and permission check, depending on the given cmd 678 - * - returns a pointer to the ipc object or otherwise, the corresponding error. 675 + * It must be called without any lock held and: 676 + * 677 + * - retrieves the ipc with the given id in the given table. 678 + * - performs some audit and permission check, depending on the given cmd 679 + * - returns a pointer to the ipc object or otherwise, the corresponding 680 + * error. 679 681 * 680 682 * Call holding the both the rwsem and the rcu read lock. 681 683 */
+5 -4
lib/Kconfig.debug
··· 130 130 nullarbor:~ # echo -n 'func svc_process -p' > 131 131 <debugfs>/dynamic_debug/control 132 132 133 - See Documentation/dynamic-debug-howto.txt for additional information. 133 + See Documentation/admin-guide/dynamic-debug-howto.rst for additional 134 + information. 134 135 135 136 endmenu # "printk and dmesg options" 136 137 ··· 405 404 by pressing various keys while holding SysRq (Alt+PrintScreen). It 406 405 also works on a serial console (on PC hardware at least), if you 407 406 send a BREAK and then within 5 seconds a command keypress. The 408 - keys are documented in <file:Documentation/sysrq.txt>. Don't say Y 409 - unless you really know what this hack does. 407 + keys are documented in <file:Documentation/admin-guide/sysrq.rst>. 408 + Don't say Y unless you really know what this hack does. 410 409 411 410 config MAGIC_SYSRQ_DEFAULT_ENABLE 412 411 hex "Enable magic SysRq key functions by default" ··· 415 414 help 416 415 Specifies which SysRq key functions are enabled by default. 417 416 This may be set to 1 or 0 to enable or disable them all, or 418 - to a bitmask as described in Documentation/sysrq.txt. 417 + to a bitmask as described in Documentation/admin-guide/sysrq.rst. 419 418 420 419 config MAGIC_SYSRQ_SERIAL 421 420 bool "Enable magic SysRq key over serial"
+17 -11
lib/bitmap.c
··· 502 502 * Syntax: range:used_size/group_size 503 503 * Example: 0-1023:2/256 ==> 0,1,256,257,512,513,768,769 504 504 * 505 - * Returns 0 on success, -errno on invalid input strings. 506 - * Error values: 507 - * %-EINVAL: second number in range smaller than first 508 - * %-EINVAL: invalid character in string 509 - * %-ERANGE: bit number specified too large for mask 505 + * Returns: 0 on success, -errno on invalid input strings. Error values: 506 + * 507 + * - ``-EINVAL``: second number in range smaller than first 508 + * - ``-EINVAL``: invalid character in string 509 + * - ``-ERANGE``: bit number specified too large for mask 510 510 */ 511 511 static int __bitmap_parselist(const char *buf, unsigned int buflen, 512 512 int is_user, unsigned long *maskp, ··· 864 864 * 11 was set in @orig had no affect on @dst. 865 865 * 866 866 * Example [2] for bitmap_fold() + bitmap_onto(): 867 - * Let's say @relmap has these ten bits set: 867 + * Let's say @relmap has these ten bits set:: 868 + * 868 869 * 40 41 42 43 45 48 53 61 74 95 870 + * 869 871 * (for the curious, that's 40 plus the first ten terms of the 870 872 * Fibonacci sequence.) 871 873 * 872 874 * Further lets say we use the following code, invoking 873 875 * bitmap_fold() then bitmap_onto, as suggested above to 874 - * avoid the possibility of an empty @dst result: 876 + * avoid the possibility of an empty @dst result:: 875 877 * 876 878 * unsigned long *tmp; // a temporary bitmap's bits 877 879 * ··· 884 882 * various @orig's. I list the zero-based positions of each set bit. 885 883 * The tmp column shows the intermediate result, as computed by 886 884 * using bitmap_fold() to fold the @orig bitmap modulo ten 887 - * (the weight of @relmap). 885 + * (the weight of @relmap): 888 886 * 887 + * =============== ============== ================= 889 888 * @orig tmp @dst 890 889 * 0 0 40 891 890 * 1 1 41 892 891 * 9 9 95 893 - * 10 0 40 (*) 892 + * 10 0 40 [#f1]_ 894 893 * 1 3 5 7 1 3 5 7 41 43 48 61 895 894 * 0 1 2 3 4 0 1 2 3 4 40 41 42 43 45 896 895 * 0 9 18 27 0 9 8 7 40 61 74 95 897 896 * 0 10 20 30 0 40 898 897 * 0 11 22 33 0 1 2 3 40 41 42 43 899 898 * 0 12 24 36 0 2 4 6 40 42 45 53 900 - * 78 102 211 1 2 8 41 42 74 (*) 899 + * 78 102 211 1 2 8 41 42 74 [#f1]_ 900 + * =============== ============== ================= 901 901 * 902 - * (*) For these marked lines, if we hadn't first done bitmap_fold() 902 + * .. [#f1] 903 + * 904 + * For these marked lines, if we hadn't first done bitmap_fold() 903 905 * into tmp, then the @dst result would have been empty. 904 906 * 905 907 * If either of @orig or @relmap is empty (no set bits), then @dst
+1 -1
lib/string.c
··· 131 131 * @src: Where to copy the string from 132 132 * @size: size of destination buffer 133 133 * 134 - * Compatible with *BSD: the result is always a valid 134 + * Compatible with ``*BSD``: the result is always a valid 135 135 * NUL-terminated string that fits in the buffer (unless, 136 136 * of course, the buffer size is zero). It does not pad 137 137 * out the result like strncpy() does.
+3 -3
lib/vsprintf.c
··· 1954 1954 * This function generally follows C99 vsnprintf, but has some 1955 1955 * extensions and a few limitations: 1956 1956 * 1957 - * %n is unsupported 1958 - * %p* is handled by pointer() 1957 + * - ``%n`` is unsupported 1958 + * - ``%p*`` is handled by pointer() 1959 1959 * 1960 1960 * See pointer() or Documentation/printk-formats.txt for more 1961 1961 * extensive description. 1962 1962 * 1963 - * ** Please update the documentation in both places when making changes ** 1963 + * **Please update the documentation in both places when making changes** 1964 1964 * 1965 1965 * The return value is the number of characters which would 1966 1966 * be generated for the given input, excluding the trailing
+10 -8
mm/filemap.c
··· 519 519 * 520 520 * Write out and wait upon file offsets lstart->lend, inclusive. 521 521 * 522 - * Note that `lend' is inclusive (describes the last byte to be written) so 522 + * Note that @lend is inclusive (describes the last byte to be written) so 523 523 * that this function can be used to write to the very end-of-file (end = -1). 524 524 */ 525 525 int filemap_write_and_wait_range(struct address_space *mapping, ··· 1277 1277 * 1278 1278 * PCG flags modify how the page is returned. 1279 1279 * 1280 - * FGP_ACCESSED: the page will be marked accessed 1281 - * FGP_LOCK: Page is return locked 1282 - * FGP_CREAT: If page is not present then a new page is allocated using 1283 - * @gfp_mask and added to the page cache and the VM's LRU 1284 - * list. The page is returned locked and with an increased 1285 - * refcount. Otherwise, %NULL is returned. 1280 + * @fgp_flags can be: 1281 + * 1282 + * - FGP_ACCESSED: the page will be marked accessed 1283 + * - FGP_LOCK: Page is return locked 1284 + * - FGP_CREAT: If page is not present then a new page is allocated using 1285 + * @gfp_mask and added to the page cache and the VM's LRU 1286 + * list. The page is returned locked and with an increased 1287 + * refcount. Otherwise, NULL is returned. 1286 1288 * 1287 1289 * If FGP_LOCK or FGP_CREAT are specified then the function may sleep even 1288 1290 * if the GFP flags specified for FGP_CREAT are atomic. ··· 3003 3001 * @gfp_mask: memory allocation flags (and I/O mode) 3004 3002 * 3005 3003 * The address_space is to try to release any data against the page 3006 - * (presumably at page->private). If the release was successful, return `1'. 3004 + * (presumably at page->private). If the release was successful, return '1'. 3007 3005 * Otherwise return zero. 3008 3006 * 3009 3007 * This may also be called if PG_fscache is set on a page, indicating that the
+2 -1
mm/page_alloc.c
··· 4247 4247 * nr_free_zone_pages() counts the number of counts pages which are beyond the 4248 4248 * high watermark within all zones at or below a given zone index. For each 4249 4249 * zone, the number of pages is calculated as: 4250 - * managed_pages - high_pages 4250 + * 4251 + * nr_free_zone_pages = managed_pages - high_pages 4251 4252 */ 4252 4253 static unsigned long nr_free_zone_pages(int offset) 4253 4254 {
+1 -1
mm/vmalloc.c
··· 1579 1579 * have CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG, but making the calling 1580 1580 * conventions for vfree() arch-depenedent would be a really bad idea) 1581 1581 * 1582 - * NOTE: assumes that the object at *addr has a size >= sizeof(llist_node) 1582 + * NOTE: assumes that the object at @addr has a size >= sizeof(llist_node) 1583 1583 */ 1584 1584 void vfree(const void *addr) 1585 1585 {
+14 -5
scripts/kernel-doc
··· 202 202 # '&struct_name.member' - name of a structure member 203 203 # '@parameter' - name of a parameter 204 204 # '%CONST' - name of a constant. 205 + # '``LITERAL``' - literal string without any spaces on it. 205 206 206 207 ## init lots of data 207 208 ··· 211 210 my $anon_struct_union = 0; 212 211 213 212 # match expressions used to find embedded type information 214 - my $type_constant = '\%([-_\w]+)'; 213 + my $type_constant = '\b``([^\`]+)``\b'; 214 + my $type_constant2 = '\%([-_\w]+)'; 215 215 my $type_func = '(\w+)\(\)'; 216 216 my $type_param = '\@(\w+(\.\.\.)?)'; 217 217 my $type_fp_param = '\@(\w+)\(\)'; # Special RST handling for func ptr params ··· 237 235 # these work fairly well 238 236 my @highlights_html = ( 239 237 [$type_constant, "<i>\$1</i>"], 238 + [$type_constant2, "<i>\$1</i>"], 240 239 [$type_func, "<b>\$1</b>"], 241 240 [$type_enum_xml, "<i>\$1</i>"], 242 241 [$type_struct_xml, "<i>\$1</i>"], ··· 255 252 # html version 5 256 253 my @highlights_html5 = ( 257 254 [$type_constant, "<span class=\"const\">\$1</span>"], 255 + [$type_constant2, "<span class=\"const\">\$1</span>"], 258 256 [$type_func, "<span class=\"func\">\$1</span>"], 259 257 [$type_enum_xml, "<span class=\"enum\">\$1</span>"], 260 258 [$type_struct_xml, "<span class=\"struct\">\$1</span>"], ··· 272 268 my @highlights_xml = ( 273 269 ["([^=])\\\"([^\\\"<]+)\\\"", "\$1<quote>\$2</quote>"], 274 270 [$type_constant, "<constant>\$1</constant>"], 271 + [$type_constant2, "<constant>\$1</constant>"], 275 272 [$type_enum_xml, "<type>\$1</type>"], 276 273 [$type_struct_xml, "<structname>\$1</structname>"], 277 274 [$type_typedef_xml, "<type>\$1</type>"], ··· 288 283 # gnome, docbook format 289 284 my @highlights_gnome = ( 290 285 [$type_constant, "<replaceable class=\"option\">\$1</replaceable>"], 286 + [$type_constant2, "<replaceable class=\"option\">\$1</replaceable>"], 291 287 [$type_func, "<function>\$1</function>"], 292 288 [$type_enum, "<type>\$1</type>"], 293 289 [$type_struct, "<structname>\$1</structname>"], ··· 304 298 # these are pretty rough 305 299 my @highlights_man = ( 306 300 [$type_constant, "\$1"], 301 + [$type_constant2, "\$1"], 307 302 [$type_func, "\\\\fB\$1\\\\fP"], 308 303 [$type_enum, "\\\\fI\$1\\\\fP"], 309 304 [$type_struct, "\\\\fI\$1\\\\fP"], ··· 319 312 # text-mode 320 313 my @highlights_text = ( 321 314 [$type_constant, "\$1"], 315 + [$type_constant2, "\$1"], 322 316 [$type_func, "\$1"], 323 317 [$type_enum, "\$1"], 324 318 [$type_struct, "\$1"], ··· 334 326 # rst-mode 335 327 my @highlights_rst = ( 336 328 [$type_constant, "``\$1``"], 329 + [$type_constant2, "``\$1``"], 337 330 # Note: need to escape () to avoid func matching later 338 331 [$type_member_func, "\\:c\\:type\\:`\$1\$2\$3\\\\(\\\\) <\$1>`"], 339 332 [$type_member, "\\:c\\:type\\:`\$1\$2\$3 <\$1>`"], ··· 353 344 # list mode 354 345 my @highlights_list = ( 355 346 [$type_constant, "\$1"], 347 + [$type_constant2, "\$1"], 356 348 [$type_func, "\$1"], 357 349 [$type_enum, "\$1"], 358 350 [$type_struct, "\$1"], ··· 2402 2392 } 2403 2393 2404 2394 $anon_struct_union = 0; 2405 - my $param_name = $param; 2406 - $param_name =~ s/\[.*//; 2395 + $param =~ s/[\[\)].*//; 2407 2396 2408 2397 if ($type eq "" && $param =~ /\.\.\.$/) 2409 2398 { ··· 2433 2424 # but inline preprocessor statements); 2434 2425 # also ignore unnamed structs/unions; 2435 2426 if (!$anon_struct_union) { 2436 - if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) { 2427 + if (!defined $parameterdescs{$param} && $param !~ /^#/) { 2437 2428 2438 - $parameterdescs{$param_name} = $undescribed; 2429 + $parameterdescs{$param} = $undescribed; 2439 2430 2440 2431 if (($type eq 'function') || ($type eq 'enum')) { 2441 2432 print STDERR "${file}:$.: warning: Function parameter ".
+8 -4
security/security.c
··· 103 103 * to avoid security registration races. This method may also be used 104 104 * to check if your LSM is currently loaded during kernel initialization. 105 105 * 106 - * Return true if: 107 - * -The passed LSM is the one chosen by user at boot time, 108 - * -or the passed LSM is configured as the default and the user did not 109 - * choose an alternate LSM at boot time. 106 + * Returns: 107 + * 108 + * true if: 109 + * 110 + * - The passed LSM is the one chosen by user at boot time, 111 + * - or the passed LSM is configured as the default and the user did not 112 + * choose an alternate LSM at boot time. 113 + * 110 114 * Otherwise, return false. 111 115 */ 112 116 int __init security_module_enable(const char *module)