pnp.txt 6.8 KB

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