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

Documentation: PCI: convert pci.txt to reST

Convert plain text documentation to reStructuredText format and add it to
Sphinx TOC tree. No essential content change.

Move the description of struct pci_driver and struct pci_device_id into
in-source comments.

Signed-off-by: Changbin Du <changbin.du@gmail.com>
[bhelgaas: fix kernel-doc warnings related to moving descriptions to
linux/pci.h, fix "space tab" whitespace errors in mod_devicetable.h]
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>

authored by

Changbin Du and committed by
Bjorn Helgaas
229b4e07 c42eaffa

+221 -212
+2
Documentation/PCI/index.rst
··· 7 7 .. toctree:: 8 8 :maxdepth: 2 9 9 :numbered: 10 + 11 + pci
+148 -206
Documentation/PCI/pci.txt Documentation/PCI/pci.rst
··· 1 + .. SPDX-License-Identifier: GPL-2.0 1 2 2 - How To Write Linux PCI Drivers 3 + ============================== 4 + How To Write Linux PCI Drivers 5 + ============================== 3 6 4 - by Martin Mares <mj@ucw.cz> on 07-Feb-2000 5 - updated by Grant Grundler <grundler@parisc-linux.org> on 23-Dec-2006 7 + :Authors: - Martin Mares <mj@ucw.cz> 8 + - Grant Grundler <grundler@parisc-linux.org> 6 9 7 - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 8 10 The world of PCI is vast and full of (mostly unpleasant) surprises. 9 11 Since each CPU architecture implements different chip-sets and PCI devices 10 12 have different requirements (erm, "features"), the result is the PCI support ··· 17 15 A more complete resource is the third edition of "Linux Device Drivers" 18 16 by Jonathan Corbet, Alessandro Rubini, and Greg Kroah-Hartman. 19 17 LDD3 is available for free (under Creative Commons License) from: 20 - 21 - http://lwn.net/Kernel/LDD3/ 18 + http://lwn.net/Kernel/LDD3/. 22 19 23 20 However, keep in mind that all documents are subject to "bit rot". 24 21 Refer to the source code if things are not working as described here. ··· 26 25 "Linux PCI" <linux-pci@atrey.karlin.mff.cuni.cz> mailing list. 27 26 28 27 29 - 30 - 0. Structure of PCI drivers 31 - ~~~~~~~~~~~~~~~~~~~~~~~~~~~ 28 + Structure of PCI drivers 29 + ======================== 32 30 PCI drivers "discover" PCI devices in a system via pci_register_driver(). 33 31 Actually, it's the other way around. When the PCI generic code discovers 34 32 a new device, the driver with a matching "description" will be notified. ··· 42 42 Once the driver knows about a PCI device and takes ownership, the 43 43 driver generally needs to perform the following initialization: 44 44 45 - Enable the device 46 - Request MMIO/IOP resources 47 - Set the DMA mask size (for both coherent and streaming DMA) 48 - Allocate and initialize shared control data (pci_allocate_coherent()) 49 - Access device configuration space (if needed) 50 - Register IRQ handler (request_irq()) 51 - Initialize non-PCI (i.e. LAN/SCSI/etc parts of the chip) 52 - Enable DMA/processing engines 45 + - Enable the device 46 + - Request MMIO/IOP resources 47 + - Set the DMA mask size (for both coherent and streaming DMA) 48 + - Allocate and initialize shared control data (pci_allocate_coherent()) 49 + - Access device configuration space (if needed) 50 + - Register IRQ handler (request_irq()) 51 + - Initialize non-PCI (i.e. LAN/SCSI/etc parts of the chip) 52 + - Enable DMA/processing engines 53 53 54 54 When done using the device, and perhaps the module needs to be unloaded, 55 55 the driver needs to take the follow steps: 56 - Disable the device from generating IRQs 57 - Release the IRQ (free_irq()) 58 - Stop all DMA activity 59 - Release DMA buffers (both streaming and coherent) 60 - Unregister from other subsystems (e.g. scsi or netdev) 61 - Release MMIO/IOP resources 62 - Disable the device 56 + 57 + - Disable the device from generating IRQs 58 + - Release the IRQ (free_irq()) 59 + - Stop all DMA activity 60 + - Release DMA buffers (both streaming and coherent) 61 + - Unregister from other subsystems (e.g. scsi or netdev) 62 + - Release MMIO/IOP resources 63 + - Disable the device 63 64 64 65 Most of these topics are covered in the following sections. 65 66 For the rest look at LDD3 or <linux/pci.h> . ··· 71 70 lots of ifdefs in the drivers. 72 71 73 72 73 + pci_register_driver() call 74 + ========================== 74 75 75 - 1. pci_register_driver() call 76 - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 77 - 78 - PCI device drivers call pci_register_driver() during their 76 + PCI device drivers call ``pci_register_driver()`` during their 79 77 initialization with a pointer to a structure describing the driver 80 - (struct pci_driver): 78 + (``struct pci_driver``): 81 79 82 - field name Description 83 - ---------- ------------------------------------------------------ 84 - id_table Pointer to table of device ID's the driver is 85 - interested in. Most drivers should export this 86 - table using MODULE_DEVICE_TABLE(pci,...). 80 + .. kernel-doc:: include/linux/pci.h 81 + :functions: pci_driver 87 82 88 - probe This probing function gets called (during execution 89 - of pci_register_driver() for already existing 90 - devices or later if a new device gets inserted) for 91 - all PCI devices which match the ID table and are not 92 - "owned" by the other drivers yet. This function gets 93 - passed a "struct pci_dev *" for each device whose 94 - entry in the ID table matches the device. The probe 95 - function returns zero when the driver chooses to 96 - take "ownership" of the device or an error code 97 - (negative number) otherwise. 98 - The probe function always gets called from process 99 - context, so it can sleep. 100 - 101 - remove The remove() function gets called whenever a device 102 - being handled by this driver is removed (either during 103 - deregistration of the driver or when it's manually 104 - pulled out of a hot-pluggable slot). 105 - The remove function always gets called from process 106 - context, so it can sleep. 107 - 108 - suspend Put device into low power state. 109 - suspend_late Put device into low power state. 110 - 111 - resume_early Wake device from low power state. 112 - resume Wake device from low power state. 113 - 114 - (Please see Documentation/power/pci.txt for descriptions 115 - of PCI Power Management and the related functions.) 116 - 117 - shutdown Hook into reboot_notifier_list (kernel/sys.c). 118 - Intended to stop any idling DMA operations. 119 - Useful for enabling wake-on-lan (NIC) or changing 120 - the power state of a device before reboot. 121 - e.g. drivers/net/e100.c. 122 - 123 - err_handler See Documentation/PCI/pci-error-recovery.txt 124 - 125 - 126 - The ID table is an array of struct pci_device_id entries ending with an 83 + The ID table is an array of ``struct pci_device_id`` entries ending with an 127 84 all-zero entry. Definitions with static const are generally preferred. 128 85 129 - Each entry consists of: 86 + .. kernel-doc:: include/linux/mod_devicetable.h 87 + :functions: pci_device_id 130 88 131 - vendor,device Vendor and device ID to match (or PCI_ANY_ID) 132 - 133 - subvendor, Subsystem vendor and device ID to match (or PCI_ANY_ID) 134 - subdevice, 135 - 136 - class Device class, subclass, and "interface" to match. 137 - See Appendix D of the PCI Local Bus Spec or 138 - include/linux/pci_ids.h for a full list of classes. 139 - Most drivers do not need to specify class/class_mask 140 - as vendor/device is normally sufficient. 141 - 142 - class_mask limit which sub-fields of the class field are compared. 143 - See drivers/scsi/sym53c8xx_2/ for example of usage. 144 - 145 - driver_data Data private to the driver. 146 - Most drivers don't need to use driver_data field. 147 - Best practice is to use driver_data as an index 148 - into a static list of equivalent device types, 149 - instead of using it as a pointer. 150 - 151 - 152 - Most drivers only need PCI_DEVICE() or PCI_DEVICE_CLASS() to set up 89 + Most drivers only need ``PCI_DEVICE()`` or ``PCI_DEVICE_CLASS()`` to set up 153 90 a pci_device_id table. 154 91 155 92 New PCI IDs may be added to a device driver pci_ids table at runtime 156 - as shown below: 93 + as shown below:: 157 94 158 - echo "vendor device subvendor subdevice class class_mask driver_data" > \ 159 - /sys/bus/pci/drivers/{driver}/new_id 95 + echo "vendor device subvendor subdevice class class_mask driver_data" > \ 96 + /sys/bus/pci/drivers/{driver}/new_id 160 97 161 98 All fields are passed in as hexadecimal values (no leading 0x). 162 99 The vendor and device fields are mandatory, the others are optional. Users 163 100 need pass only as many optional fields as necessary: 164 - o subvendor and subdevice fields default to PCI_ANY_ID (FFFFFFFF) 165 - o class and classmask fields default to 0 166 - o driver_data defaults to 0UL. 101 + 102 + - subvendor and subdevice fields default to PCI_ANY_ID (FFFFFFFF) 103 + - class and classmask fields default to 0 104 + - driver_data defaults to 0UL. 167 105 168 106 Note that driver_data must match the value used by any of the pci_device_id 169 107 entries defined in the driver. This makes the driver_data field mandatory ··· 115 175 automatically calls the remove hook for all devices handled by the driver. 116 176 117 177 118 - 1.1 "Attributes" for driver functions/data 178 + "Attributes" for driver functions/data 179 + -------------------------------------- 119 180 120 181 Please mark the initialization and cleanup functions where appropriate 121 182 (the corresponding macros are defined in <linux/init.h>): 122 183 184 + ====== ================================================= 123 185 __init Initialization code. Thrown away after the driver 124 186 initializes. 125 187 __exit Exit code. Ignored for non-modular drivers. 188 + ====== ================================================= 126 189 127 190 Tips on when/where to use the above attributes: 128 - o The module_init()/module_exit() functions (and all 191 + - The module_init()/module_exit() functions (and all 129 192 initialization functions called _only_ from these) 130 193 should be marked __init/__exit. 131 194 132 - o Do not mark the struct pci_driver. 195 + - Do not mark the struct pci_driver. 133 196 134 - o Do NOT mark a function if you are not sure which mark to use. 197 + - Do NOT mark a function if you are not sure which mark to use. 135 198 Better to not mark the function than mark the function wrong. 136 199 137 200 138 - 139 - 2. How to find PCI devices manually 140 - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 201 + How to find PCI devices manually 202 + ================================ 141 203 142 204 PCI drivers should have a really good reason for not using the 143 205 pci_register_driver() interface to search for PCI devices. ··· 149 207 150 208 A manual search may be performed using the following constructs: 151 209 152 - Searching by vendor and device ID: 210 + Searching by vendor and device ID:: 153 211 154 212 struct pci_dev *dev = NULL; 155 213 while (dev = pci_get_device(VENDOR_ID, DEVICE_ID, dev)) 156 214 configure_device(dev); 157 215 158 - Searching by class ID (iterate in a similar way): 216 + Searching by class ID (iterate in a similar way):: 159 217 160 218 pci_get_class(CLASS_ID, dev) 161 219 162 - Searching by both vendor/device and subsystem vendor/device ID: 220 + Searching by both vendor/device and subsystem vendor/device ID:: 163 221 164 222 pci_get_subsys(VENDOR_ID,DEVICE_ID, SUBSYS_VENDOR_ID, SUBSYS_DEVICE_ID, dev). 165 223 ··· 172 230 decrement the reference count on these devices by calling pci_dev_put(). 173 231 174 232 175 - 176 - 3. Device Initialization Steps 177 - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 233 + Device Initialization Steps 234 + =========================== 178 235 179 236 As noted in the introduction, most PCI drivers need the following steps 180 237 for device initialization: 181 238 182 - Enable the device 183 - Request MMIO/IOP resources 184 - Set the DMA mask size (for both coherent and streaming DMA) 185 - Allocate and initialize shared control data (pci_allocate_coherent()) 186 - Access device configuration space (if needed) 187 - Register IRQ handler (request_irq()) 188 - Initialize non-PCI (i.e. LAN/SCSI/etc parts of the chip) 189 - Enable DMA/processing engines. 239 + - Enable the device 240 + - Request MMIO/IOP resources 241 + - Set the DMA mask size (for both coherent and streaming DMA) 242 + - Allocate and initialize shared control data (pci_allocate_coherent()) 243 + - Access device configuration space (if needed) 244 + - Register IRQ handler (request_irq()) 245 + - Initialize non-PCI (i.e. LAN/SCSI/etc parts of the chip) 246 + - Enable DMA/processing engines. 190 247 191 248 The driver can access PCI config space registers at any time. 192 249 (Well, almost. When running BIST, config space can go away...but ··· 193 252 will return garbage). 194 253 195 254 196 - 3.1 Enable the PCI device 197 - ~~~~~~~~~~~~~~~~~~~~~~~~~ 255 + Enable the PCI device 256 + --------------------- 198 257 Before touching any device registers, the driver needs to enable 199 258 the PCI device by calling pci_enable_device(). This will: 200 - o wake up the device if it was in suspended state, 201 - o allocate I/O and memory regions of the device (if BIOS did not), 202 - o allocate an IRQ (if BIOS did not). 203 259 204 - NOTE: pci_enable_device() can fail! Check the return value. 260 + - wake up the device if it was in suspended state, 261 + - allocate I/O and memory regions of the device (if BIOS did not), 262 + - allocate an IRQ (if BIOS did not). 205 263 206 - [ OS BUG: we don't check resource allocations before enabling those 207 - resources. The sequence would make more sense if we called 208 - pci_request_resources() before calling pci_enable_device(). 209 - Currently, the device drivers can't detect the bug when when two 210 - devices have been allocated the same range. This is not a common 211 - problem and unlikely to get fixed soon. 264 + .. note:: 265 + pci_enable_device() can fail! Check the return value. 212 266 213 - This has been discussed before but not changed as of 2.6.19: 214 - http://lkml.org/lkml/2006/3/2/194 215 - ] 267 + .. warning:: 268 + OS BUG: we don't check resource allocations before enabling those 269 + resources. The sequence would make more sense if we called 270 + pci_request_resources() before calling pci_enable_device(). 271 + Currently, the device drivers can't detect the bug when when two 272 + devices have been allocated the same range. This is not a common 273 + problem and unlikely to get fixed soon. 274 + 275 + This has been discussed before but not changed as of 2.6.19: 276 + http://lkml.org/lkml/2006/3/2/194 277 + 216 278 217 279 pci_set_master() will enable DMA by setting the bus master bit 218 280 in the PCI_COMMAND register. It also fixes the latency timer value if ··· 232 288 Mem-Wr-Inval. 233 289 234 290 235 - 3.2 Request MMIO/IOP resources 236 - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 291 + Request MMIO/IOP resources 292 + -------------------------- 237 293 Memory (MMIO), and I/O port addresses should NOT be read directly 238 294 from the PCI device config space. Use the values in the pci_dev structure 239 295 as the PCI "bus address" might have been remapped to a "host physical" ··· 248 304 calling pci_disable_device(). 249 305 The idea is to prevent two devices colliding on the same address range. 250 306 251 - [ See OS BUG comment above. Currently (2.6.19), The driver can only 252 - determine MMIO and IO Port resource availability _after_ calling 253 - pci_enable_device(). ] 307 + .. tip:: 308 + See OS BUG comment above. Currently (2.6.19), The driver can only 309 + determine MMIO and IO Port resource availability _after_ calling 310 + pci_enable_device(). 254 311 255 312 Generic flavors of pci_request_region() are request_mem_region() 256 313 (for MMIO ranges) and request_region() (for IO Port ranges). ··· 261 316 Also see pci_request_selected_regions() below. 262 317 263 318 264 - 3.3 Set the DMA mask size 265 - ~~~~~~~~~~~~~~~~~~~~~~~~~ 266 - [ If anything below doesn't make sense, please refer to 267 - Documentation/DMA-API.txt. This section is just a reminder that 268 - drivers need to indicate DMA capabilities of the device and is not 269 - an authoritative source for DMA interfaces. ] 319 + Set the DMA mask size 320 + --------------------- 321 + .. note:: 322 + If anything below doesn't make sense, please refer to 323 + Documentation/DMA-API.txt. This section is just a reminder that 324 + drivers need to indicate DMA capabilities of the device and is not 325 + an authoritative source for DMA interfaces. 270 326 271 327 While all drivers should explicitly indicate the DMA capability 272 328 (e.g. 32 or 64 bit) of the PCI bus master, devices with more than ··· 288 342 ("consistent") data. 289 343 290 344 291 - 3.4 Setup shared control data 292 - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 345 + Setup shared control data 346 + ------------------------- 293 347 Once the DMA masks are set, the driver can allocate "consistent" (a.k.a. shared) 294 348 memory. See Documentation/DMA-API.txt for a full description of 295 349 the DMA APIs. This section is just a reminder that it needs to be done 296 350 before enabling DMA on the device. 297 351 298 352 299 - 3.5 Initialize device registers 300 - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 353 + Initialize device registers 354 + --------------------------- 301 355 Some drivers will need specific "capability" fields programmed 302 356 or other "vendor specific" register initialized or reset. 303 357 E.g. clearing pending interrupts. 304 358 305 359 306 - 3.6 Register IRQ handler 307 - ~~~~~~~~~~~~~~~~~~~~~~~~ 360 + Register IRQ handler 361 + -------------------- 308 362 While calling request_irq() is the last step described here, 309 363 this is often just another intermediate step to initialize a device. 310 364 This step can often be deferred until the device is opened for use. ··· 342 396 pci_alloc_irq_vectors. 343 397 344 398 There are (at least) two really good reasons for using MSI: 399 + 345 400 1) MSI is an exclusive interrupt vector by definition. 346 401 This means the interrupt handler doesn't have to verify 347 402 its device caused the interrupt. ··· 357 410 of MSI/MSI-X usage. 358 411 359 412 360 - 361 - 4. PCI device shutdown 362 - ~~~~~~~~~~~~~~~~~~~~~~~ 413 + PCI device shutdown 414 + =================== 363 415 364 416 When a PCI device driver is being unloaded, most of the following 365 417 steps need to be performed: 366 418 367 - Disable the device from generating IRQs 368 - Release the IRQ (free_irq()) 369 - Stop all DMA activity 370 - Release DMA buffers (both streaming and consistent) 371 - Unregister from other subsystems (e.g. scsi or netdev) 372 - Disable device from responding to MMIO/IO Port addresses 373 - Release MMIO/IO Port resource(s) 419 + - Disable the device from generating IRQs 420 + - Release the IRQ (free_irq()) 421 + - Stop all DMA activity 422 + - Release DMA buffers (both streaming and consistent) 423 + - Unregister from other subsystems (e.g. scsi or netdev) 424 + - Disable device from responding to MMIO/IO Port addresses 425 + - Release MMIO/IO Port resource(s) 374 426 375 427 376 - 4.1 Stop IRQs on the device 377 - ~~~~~~~~~~~~~~~~~~~~~~~~~~~ 428 + Stop IRQs on the device 429 + ----------------------- 378 430 How to do this is chip/device specific. If it's not done, it opens 379 431 the possibility of a "screaming interrupt" if (and only if) 380 432 the IRQ is shared with another device. ··· 392 446 are not susceptible to the "screaming interrupt" problem. 393 447 394 448 395 - 4.2 Release the IRQ 396 - ~~~~~~~~~~~~~~~~~~~ 449 + Release the IRQ 450 + --------------- 397 451 Once the device is quiesced (no more IRQs), one can call free_irq(). 398 452 This function will return control once any pending IRQs are handled, 399 453 "unhook" the drivers IRQ handler from that IRQ, and finally release 400 454 the IRQ if no one else is using it. 401 455 402 456 403 - 4.3 Stop all DMA activity 404 - ~~~~~~~~~~~~~~~~~~~~~~~~~ 457 + Stop all DMA activity 458 + --------------------- 405 459 It's extremely important to stop all DMA operations BEFORE attempting 406 460 to deallocate DMA control data. Failure to do so can result in memory 407 461 corruption, hangs, and on some chip-sets a hard crash. ··· 413 467 didn't get this step right in the past. 414 468 415 469 416 - 4.4 Release DMA buffers 417 - ~~~~~~~~~~~~~~~~~~~~~~~ 470 + Release DMA buffers 471 + ------------------- 418 472 Once DMA is stopped, clean up streaming DMA first. 419 473 I.e. unmap data buffers and return buffers to "upstream" 420 474 owners if there is one. ··· 424 478 See Documentation/DMA-API.txt for details on unmapping interfaces. 425 479 426 480 427 - 4.5 Unregister from other subsystems 428 - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 481 + Unregister from other subsystems 482 + -------------------------------- 429 483 Most low level PCI device drivers support some other subsystem 430 484 like USB, ALSA, SCSI, NetDev, Infiniband, etc. Make sure your 431 485 driver isn't losing resources from that other subsystem. ··· 433 487 the subsystem attempts to call into a driver that has been unloaded. 434 488 435 489 436 - 4.6 Disable Device from responding to MMIO/IO Port addresses 437 - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 490 + Disable Device from responding to MMIO/IO Port addresses 491 + -------------------------------------------------------- 438 492 io_unmap() MMIO or IO Port resources and then call pci_disable_device(). 439 493 This is the symmetric opposite of pci_enable_device(). 440 494 Do not access device registers after calling pci_disable_device(). 441 495 442 496 443 - 4.7 Release MMIO/IO Port Resource(s) 444 - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 497 + Release MMIO/IO Port Resource(s) 498 + -------------------------------- 445 499 Call pci_release_region() to mark the MMIO or IO Port range as available. 446 500 Failure to do so usually results in the inability to reload the driver. 447 501 448 502 503 + How to access PCI config space 504 + ============================== 449 505 450 - 5. How to access PCI config space 451 - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 452 - 453 - You can use pci_(read|write)_config_(byte|word|dword) to access the config 454 - space of a device represented by struct pci_dev *. All these functions return 0 455 - when successful or an error code (PCIBIOS_...) which can be translated to a text 456 - string by pcibios_strerror. Most drivers expect that accesses to valid PCI 506 + You can use `pci_(read|write)_config_(byte|word|dword)` to access the config 507 + space of a device represented by `struct pci_dev *`. All these functions return 508 + 0 when successful or an error code (`PCIBIOS_...`) which can be translated to a 509 + text string by pcibios_strerror. Most drivers expect that accesses to valid PCI 457 510 devices don't fail. 458 511 459 512 If you don't have a struct pci_dev available, you can call 460 - pci_bus_(read|write)_config_(byte|word|dword) to access a given device 513 + `pci_bus_(read|write)_config_(byte|word|dword)` to access a given device 461 514 and function on that bus. 462 515 463 516 If you access fields in the standard portion of the config header, please ··· 467 522 corresponding register block for you. 468 523 469 524 525 + Other interesting functions 526 + =========================== 470 527 471 - 6. Other interesting functions 472 - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 473 - 528 + ============================= ================================================ 474 529 pci_get_domain_bus_and_slot() Find pci_dev corresponding to given domain, 475 530 bus and slot and number. If the device is 476 531 found, its reference count is increased. ··· 484 539 pci_get_drvdata() Return private driver data pointer for a pci_dev 485 540 pci_set_mwi() Enable Memory-Write-Invalidate transactions. 486 541 pci_clear_mwi() Disable Memory-Write-Invalidate transactions. 542 + ============================= ================================================ 487 543 488 544 489 - 490 - 7. Miscellaneous hints 491 - ~~~~~~~~~~~~~~~~~~~~~~ 545 + Miscellaneous hints 546 + =================== 492 547 493 548 When displaying PCI device names to the user (for example when a driver wants 494 549 to tell the user what card has it found), please use pci_name(pci_dev). ··· 504 559 to be handled by platform and generic code, not individual drivers. 505 560 506 561 507 - 508 - 8. Vendor and device identifications 509 - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 562 + Vendor and device identifications 563 + ================================= 510 564 511 565 Do not add new device or vendor IDs to include/linux/pci_ids.h unless they 512 566 are shared across multiple drivers. You can add private definitions in ··· 519 575 and https://github.com/pciutils/pciids. 520 576 521 577 522 - 523 - 9. Obsolete functions 524 - ~~~~~~~~~~~~~~~~~~~~~ 578 + Obsolete functions 579 + ================== 525 580 526 581 There are several functions which you might come across when trying to 527 582 port an old driver to the new PCI interface. They are no longer present 528 583 in the kernel as they aren't compatible with hotplug or PCI domains or 529 584 having sane locking. 530 585 586 + ================= =========================================== 531 587 pci_find_device() Superseded by pci_get_device() 532 588 pci_find_subsys() Superseded by pci_get_subsys() 533 589 pci_find_slot() Superseded by pci_get_domain_bus_and_slot() 534 590 pci_get_slot() Superseded by pci_get_domain_bus_and_slot() 535 - 591 + ================= =========================================== 536 592 537 593 The alternative is the traditional PCI device driver that walks PCI 538 594 device lists. This is still possible but discouraged. 539 595 540 596 541 - 542 - 10. MMIO Space and "Write Posting" 543 - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 597 + MMIO Space and "Write Posting" 598 + ============================== 544 599 545 600 Converting a driver from using I/O Port space to using MMIO space 546 601 often requires some additional changes. Specifically, "write posting" ··· 552 609 553 610 Thus, timing sensitive code should add readl() where the CPU is 554 611 expected to wait before doing other work. The classic "bit banging" 555 - sequence works fine for I/O Port space: 612 + sequence works fine for I/O Port space:: 556 613 557 614 for (i = 8; --i; val >>= 1) { 558 615 outb(val & 1, ioport_reg); /* write bit */ 559 616 udelay(10); 560 617 } 561 618 562 - The same sequence for MMIO space should be: 619 + The same sequence for MMIO space should be:: 563 620 564 621 for (i = 8; --i; val >>= 1) { 565 622 writeb(val & 1, mmio_reg); /* write bit */ ··· 576 633 expected to not respond to a readl(). Most x86 platforms will allow 577 634 MMIO reads to master abort (a.k.a. "Soft Fail") and return garbage 578 635 (e.g. ~0). But many RISC platforms will crash (a.k.a."Hard Fail"). 579 -
+24 -5
include/linux/mod_devicetable.h
··· 16 16 17 17 #define PCI_ANY_ID (~0) 18 18 19 + /** 20 + * struct pci_device_id - PCI device ID structure 21 + * @vendor: Vendor ID to match (or PCI_ANY_ID) 22 + * @device: Device ID to match (or PCI_ANY_ID) 23 + * @subvendor: Subsystem vendor ID to match (or PCI_ANY_ID) 24 + * @subdevice: Subsystem device ID to match (or PCI_ANY_ID) 25 + * @class: Device class, subclass, and "interface" to match. 26 + * See Appendix D of the PCI Local Bus Spec or 27 + * include/linux/pci_ids.h for a full list of classes. 28 + * Most drivers do not need to specify class/class_mask 29 + * as vendor/device is normally sufficient. 30 + * @class_mask: Limit which sub-fields of the class field are compared. 31 + * See drivers/scsi/sym53c8xx_2/ for example of usage. 32 + * @driver_data: Data private to the driver. 33 + * Most drivers don't need to use driver_data field. 34 + * Best practice is to use driver_data as an index 35 + * into a static list of equivalent device types, 36 + * instead of using it as a pointer. 37 + */ 19 38 struct pci_device_id { 20 39 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/ 21 40 __u32 subvendor, subdevice; /* Subsystem ID's or PCI_ANY_ID */ ··· 276 257 __u16 match_flags; 277 258 278 259 __u16 manf_id; 279 - __u16 card_id; 260 + __u16 card_id; 280 261 281 - __u8 func_id; 262 + __u8 func_id; 282 263 283 264 /* for real multi-function devices */ 284 - __u8 function; 265 + __u8 function; 285 266 286 267 /* for pseudo multi-function devices */ 287 - __u8 device_no; 268 + __u8 device_no; 288 269 289 - __u32 prod_id_hash[4]; 270 + __u32 prod_id_hash[4]; 290 271 291 272 /* not matched against in kernelspace */ 292 273 const char * prod_id[4];
+47 -1
include/linux/pci.h
··· 151 151 #define PCI_PM_BUS_WAIT 50 152 152 153 153 /** 154 + * typedef pci_channel_state_t 155 + * 154 156 * The pci_channel state describes connectivity between the CPU and 155 157 * the PCI device. If some PCI bus between here and the PCI device 156 158 * has crashed or locked up, this info is reflected here. ··· 777 775 778 776 779 777 struct module; 778 + 779 + /** 780 + * struct pci_driver - PCI driver structure 781 + * @node: List of driver structures. 782 + * @name: Driver name. 783 + * @id_table: Pointer to table of device IDs the driver is 784 + * interested in. Most drivers should export this 785 + * table using MODULE_DEVICE_TABLE(pci,...). 786 + * @probe: This probing function gets called (during execution 787 + * of pci_register_driver() for already existing 788 + * devices or later if a new device gets inserted) for 789 + * all PCI devices which match the ID table and are not 790 + * "owned" by the other drivers yet. This function gets 791 + * passed a "struct pci_dev \*" for each device whose 792 + * entry in the ID table matches the device. The probe 793 + * function returns zero when the driver chooses to 794 + * take "ownership" of the device or an error code 795 + * (negative number) otherwise. 796 + * The probe function always gets called from process 797 + * context, so it can sleep. 798 + * @remove: The remove() function gets called whenever a device 799 + * being handled by this driver is removed (either during 800 + * deregistration of the driver or when it's manually 801 + * pulled out of a hot-pluggable slot). 802 + * The remove function always gets called from process 803 + * context, so it can sleep. 804 + * @suspend: Put device into low power state. 805 + * @suspend_late: Put device into low power state. 806 + * @resume_early: Wake device from low power state. 807 + * @resume: Wake device from low power state. 808 + * (Please see Documentation/power/pci.txt for descriptions 809 + * of PCI Power Management and the related functions.) 810 + * @shutdown: Hook into reboot_notifier_list (kernel/sys.c). 811 + * Intended to stop any idling DMA operations. 812 + * Useful for enabling wake-on-lan (NIC) or changing 813 + * the power state of a device before reboot. 814 + * e.g. drivers/net/e100.c. 815 + * @sriov_configure: Optional driver callback to allow configuration of 816 + * number of VFs to enable via sysfs "sriov_numvfs" file. 817 + * @err_handler: See Documentation/PCI/pci-error-recovery.rst 818 + * @groups: Sysfs attribute groups. 819 + * @driver: Driver model structure. 820 + * @dynids: List of dynamically added device IDs. 821 + */ 780 822 struct pci_driver { 781 823 struct list_head node; 782 824 const char *name; ··· 2252 2206 2253 2207 /** 2254 2208 * pci_vpd_info_field_size - Extracts the information field length 2255 - * @lrdt: Pointer to the beginning of an information field header 2209 + * @info_field: Pointer to the beginning of an information field header 2256 2210 * 2257 2211 * Returns the extracted information field length. 2258 2212 */