pnp.txt 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. =================================
  2. Linux Plug and Play Documentation
  3. =================================
  4. :Author: Adam Belay <ambx1@neo.rr.com>
  5. :Last updated: Oct. 16, 2002
  6. Overview
  7. --------
  8. Plug and Play provides a means of detecting and setting resources for legacy or
  9. otherwise unconfigurable devices. The Linux Plug and Play Layer provides these
  10. services to compatible drivers.
  11. The User Interface
  12. ------------------
  13. The Linux Plug and Play user interface provides a means to activate PnP devices
  14. for legacy and user level drivers that do not support Linux Plug and Play. The
  15. user interface is integrated into sysfs.
  16. In addition to the standard sysfs file the following are created in each
  17. device's directory:
  18. - id - displays a list of support EISA IDs
  19. - options - displays possible resource configurations
  20. - resources - displays currently allocated resources and allows resource changes
  21. activating a device
  22. ^^^^^^^^^^^^^^^^^^^
  23. ::
  24. # echo "auto" > resources
  25. this will invoke the automatic resource config system to activate the device
  26. manually activating a device
  27. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  28. ::
  29. # echo "manual <depnum> <mode>" > resources
  30. <depnum> - the configuration number
  31. <mode> - static or dynamic
  32. static = for next boot
  33. dynamic = now
  34. disabling a device
  35. ^^^^^^^^^^^^^^^^^^
  36. ::
  37. # echo "disable" > resources
  38. EXAMPLE:
  39. Suppose you need to activate the floppy disk controller.
  40. 1. change to the proper directory, in my case it is
  41. /driver/bus/pnp/devices/00:0f::
  42. # cd /driver/bus/pnp/devices/00:0f
  43. # cat name
  44. PC standard floppy disk controller
  45. 2. check if the device is already active::
  46. # cat resources
  47. DISABLED
  48. - Notice the string "DISABLED". This means the device is not active.
  49. 3. check the device's possible configurations (optional)::
  50. # cat options
  51. Dependent: 01 - Priority acceptable
  52. port 0x3f0-0x3f0, align 0x7, size 0x6, 16-bit address decoding
  53. port 0x3f7-0x3f7, align 0x0, size 0x1, 16-bit address decoding
  54. irq 6
  55. dma 2 8-bit compatible
  56. Dependent: 02 - Priority acceptable
  57. port 0x370-0x370, align 0x7, size 0x6, 16-bit address decoding
  58. port 0x377-0x377, align 0x0, size 0x1, 16-bit address decoding
  59. irq 6
  60. dma 2 8-bit compatible
  61. 4. now activate the device::
  62. # echo "auto" > resources
  63. 5. finally check if the device is active::
  64. # cat resources
  65. io 0x3f0-0x3f5
  66. io 0x3f7-0x3f7
  67. irq 6
  68. dma 2
  69. also there are a series of kernel parameters::
  70. pnp_reserve_irq=irq1[,irq2] ....
  71. pnp_reserve_dma=dma1[,dma2] ....
  72. pnp_reserve_io=io1,size1[,io2,size2] ....
  73. pnp_reserve_mem=mem1,size1[,mem2,size2] ....
  74. The Unified Plug and Play Layer
  75. -------------------------------
  76. All Plug and Play drivers, protocols, and services meet at a central location
  77. called the Plug and Play Layer. This layer is responsible for the exchange of
  78. information between PnP drivers and PnP protocols. Thus it automatically
  79. forwards commands to the proper protocol. This makes writing PnP drivers
  80. significantly easier.
  81. The following functions are available from the Plug and Play Layer:
  82. pnp_get_protocol
  83. increments the number of uses by one
  84. pnp_put_protocol
  85. deincrements the number of uses by one
  86. pnp_register_protocol
  87. use this to register a new PnP protocol
  88. pnp_unregister_protocol
  89. use this function to remove a PnP protocol from the Plug and Play Layer
  90. pnp_register_driver
  91. adds a PnP driver to the Plug and Play Layer
  92. this includes driver model integration
  93. returns zero for success or a negative error number for failure; count
  94. calls to the .add() method if you need to know how many devices bind to
  95. the driver
  96. pnp_unregister_driver
  97. removes a PnP driver from the Plug and Play Layer
  98. Plug and Play Protocols
  99. -----------------------
  100. This section contains information for PnP protocol developers.
  101. The following Protocols are currently available in the computing world:
  102. - PNPBIOS:
  103. used for system devices such as serial and parallel ports.
  104. - ISAPNP:
  105. provides PnP support for the ISA bus
  106. - ACPI:
  107. among its many uses, ACPI provides information about system level
  108. devices.
  109. It is meant to replace the PNPBIOS. It is not currently supported by Linux
  110. Plug and Play but it is planned to be in the near future.
  111. Requirements for a Linux PnP protocol:
  112. 1. the protocol must use EISA IDs
  113. 2. the protocol must inform the PnP Layer of a device's current configuration
  114. - the ability to set resources is optional but preferred.
  115. The following are PnP protocol related functions:
  116. pnp_add_device
  117. use this function to add a PnP device to the PnP layer
  118. only call this function when all wanted values are set in the pnp_dev
  119. structure
  120. pnp_init_device
  121. call this to initialize the PnP structure
  122. pnp_remove_device
  123. call this to remove a device from the Plug and Play Layer.
  124. it will fail if the device is still in use.
  125. automatically will free mem used by the device and related structures
  126. pnp_add_id
  127. adds an EISA ID to the list of supported IDs for the specified device
  128. For more information consult the source of a protocol such as
  129. /drivers/pnp/pnpbios/core.c.
  130. Linux Plug and Play Drivers
  131. ---------------------------
  132. This section contains information for Linux PnP driver developers.
  133. The New Way
  134. ^^^^^^^^^^^
  135. 1. first make a list of supported EISA IDS
  136. ex::
  137. static const struct pnp_id pnp_dev_table[] = {
  138. /* Standard LPT Printer Port */
  139. {.id = "PNP0400", .driver_data = 0},
  140. /* ECP Printer Port */
  141. {.id = "PNP0401", .driver_data = 0},
  142. {.id = ""}
  143. };
  144. Please note that the character 'X' can be used as a wild card in the function
  145. portion (last four characters).
  146. ex::
  147. /* Unknown PnP modems */
  148. { "PNPCXXX", UNKNOWN_DEV },
  149. Supported PnP card IDs can optionally be defined.
  150. ex::
  151. static const struct pnp_id pnp_card_table[] = {
  152. { "ANYDEVS", 0 },
  153. { "", 0 }
  154. };
  155. 2. Optionally define probe and remove functions. It may make sense not to
  156. define these functions if the driver already has a reliable method of detecting
  157. the resources, such as the parport_pc driver.
  158. ex::
  159. static int
  160. serial_pnp_probe(struct pnp_dev * dev, const struct pnp_id *card_id, const
  161. struct pnp_id *dev_id)
  162. {
  163. . . .
  164. ex::
  165. static void serial_pnp_remove(struct pnp_dev * dev)
  166. {
  167. . . .
  168. consult /drivers/serial/8250_pnp.c for more information.
  169. 3. create a driver structure
  170. ex::
  171. static struct pnp_driver serial_pnp_driver = {
  172. .name = "serial",
  173. .card_id_table = pnp_card_table,
  174. .id_table = pnp_dev_table,
  175. .probe = serial_pnp_probe,
  176. .remove = serial_pnp_remove,
  177. };
  178. * name and id_table cannot be NULL.
  179. 4. register the driver
  180. ex::
  181. static int __init serial8250_pnp_init(void)
  182. {
  183. return pnp_register_driver(&serial_pnp_driver);
  184. }
  185. The Old Way
  186. ^^^^^^^^^^^
  187. A series of compatibility functions have been created to make it easy to convert
  188. ISAPNP drivers. They should serve as a temporary solution only.
  189. They are as follows::
  190. struct pnp_card *pnp_find_card(unsigned short vendor,
  191. unsigned short device,
  192. struct pnp_card *from)
  193. struct pnp_dev *pnp_find_dev(struct pnp_card *card,
  194. unsigned short vendor,
  195. unsigned short function,
  196. struct pnp_dev *from)