PageRenderTime 91ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/Documentation/driver-api/mei/mei-client-bus.rst

https://github.com/kvaneesh/linux
ReStructuredText | 168 lines | 117 code | 51 blank | 0 comment | 0 complexity | 66197b8cc30923fe07ee6efa7d9290c7 MD5 | raw file
  1. .. SPDX-License-Identifier: GPL-2.0
  2. ==============================================
  3. Intel(R) Management Engine (ME) Client bus API
  4. ==============================================
  5. Rationale
  6. =========
  7. The MEI character device is useful for dedicated applications to send and receive
  8. data to the many FW appliance found in Intel's ME from the user space.
  9. However, for some of the ME functionalities it makes sense to leverage existing software
  10. stack and expose them through existing kernel subsystems.
  11. In order to plug seamlessly into the kernel device driver model we add kernel virtual
  12. bus abstraction on top of the MEI driver. This allows implementing Linux kernel drivers
  13. for the various MEI features as a stand alone entities found in their respective subsystem.
  14. Existing device drivers can even potentially be re-used by adding an MEI CL bus layer to
  15. the existing code.
  16. MEI CL bus API
  17. ==============
  18. A driver implementation for an MEI Client is very similar to any other existing bus
  19. based device drivers. The driver registers itself as an MEI CL bus driver through
  20. the ``struct mei_cl_driver`` structure defined in :file:`include/linux/mei_cl_bus.c`
  21. .. code-block:: C
  22. struct mei_cl_driver {
  23. struct device_driver driver;
  24. const char *name;
  25. const struct mei_cl_device_id *id_table;
  26. int (*probe)(struct mei_cl_device *dev, const struct mei_cl_id *id);
  27. int (*remove)(struct mei_cl_device *dev);
  28. };
  29. The mei_cl_device_id structure defined in :file:`include/linux/mod_devicetable.h` allows a
  30. driver to bind itself against a device name.
  31. .. code-block:: C
  32. struct mei_cl_device_id {
  33. char name[MEI_CL_NAME_SIZE];
  34. uuid_le uuid;
  35. __u8 version;
  36. kernel_ulong_t driver_info;
  37. };
  38. To actually register a driver on the ME Client bus one must call the :c:func:`mei_cl_add_driver`
  39. API. This is typically called at module initialization time.
  40. Once the driver is registered and bound to the device, a driver will typically
  41. try to do some I/O on this bus and this should be done through the :c:func:`mei_cl_send`
  42. and :c:func:`mei_cl_recv` functions. More detailed information is in :ref:`api` section.
  43. In order for a driver to be notified about pending traffic or event, the driver
  44. should register a callback via :c:func:`mei_cl_devev_register_rx_cb` and
  45. :c:func:`mei_cldev_register_notify_cb` function respectively.
  46. .. _api:
  47. API:
  48. ----
  49. .. kernel-doc:: drivers/misc/mei/bus.c
  50. :export: drivers/misc/mei/bus.c
  51. Example
  52. =======
  53. As a theoretical example let's pretend the ME comes with a "contact" NFC IP.
  54. The driver init and exit routines for this device would look like:
  55. .. code-block:: C
  56. #define CONTACT_DRIVER_NAME "contact"
  57. static struct mei_cl_device_id contact_mei_cl_tbl[] = {
  58. { CONTACT_DRIVER_NAME, },
  59. /* required last entry */
  60. { }
  61. };
  62. MODULE_DEVICE_TABLE(mei_cl, contact_mei_cl_tbl);
  63. static struct mei_cl_driver contact_driver = {
  64. .id_table = contact_mei_tbl,
  65. .name = CONTACT_DRIVER_NAME,
  66. .probe = contact_probe,
  67. .remove = contact_remove,
  68. };
  69. static int contact_init(void)
  70. {
  71. int r;
  72. r = mei_cl_driver_register(&contact_driver);
  73. if (r) {
  74. pr_err(CONTACT_DRIVER_NAME ": driver registration failed\n");
  75. return r;
  76. }
  77. return 0;
  78. }
  79. static void __exit contact_exit(void)
  80. {
  81. mei_cl_driver_unregister(&contact_driver);
  82. }
  83. module_init(contact_init);
  84. module_exit(contact_exit);
  85. And the driver's simplified probe routine would look like that:
  86. .. code-block:: C
  87. int contact_probe(struct mei_cl_device *dev, struct mei_cl_device_id *id)
  88. {
  89. [...]
  90. mei_cldev_enable(dev);
  91. mei_cldev_register_rx_cb(dev, contact_rx_cb);
  92. return 0;
  93. }
  94. In the probe routine the driver first enable the MEI device and then registers
  95. an rx handler which is as close as it can get to registering a threaded IRQ handler.
  96. The handler implementation will typically call :c:func:`mei_cldev_recv` and then
  97. process received data.
  98. .. code-block:: C
  99. #define MAX_PAYLOAD 128
  100. #define HDR_SIZE 4
  101. static void conntact_rx_cb(struct mei_cl_device *cldev)
  102. {
  103. struct contact *c = mei_cldev_get_drvdata(cldev);
  104. unsigned char payload[MAX_PAYLOAD];
  105. ssize_t payload_sz;
  106. payload_sz = mei_cldev_recv(cldev, payload, MAX_PAYLOAD)
  107. if (reply_size < HDR_SIZE) {
  108. return;
  109. }
  110. c->process_rx(payload);
  111. }
  112. MEI Client Bus Drivers
  113. ======================
  114. .. toctree::
  115. :maxdepth: 2
  116. hdcp
  117. nfc