mei-client-bus.txt 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. Intel(R) Management Engine (ME) Client bus API
  2. ==============================================
  3. Rationale
  4. =========
  5. MEI misc character device is useful for dedicated applications to send and receive
  6. data to the many FW appliance found in Intel's ME from the user space.
  7. However for some of the ME functionalities it make sense to leverage existing software
  8. stack and expose them through existing kernel subsystems.
  9. In order to plug seamlessly into the kernel device driver model we add kernel virtual
  10. bus abstraction on top of the MEI driver. This allows implementing linux kernel drivers
  11. for the various MEI features as a stand alone entities found in their respective subsystem.
  12. Existing device drivers can even potentially be re-used by adding an MEI CL bus layer to
  13. the existing code.
  14. MEI CL bus API
  15. ==============
  16. A driver implementation for an MEI Client is very similar to existing bus
  17. based device drivers. The driver registers itself as an MEI CL bus driver through
  18. the mei_cl_driver structure:
  19. struct mei_cl_driver {
  20. struct device_driver driver;
  21. const char *name;
  22. const struct mei_cl_device_id *id_table;
  23. int (*probe)(struct mei_cl_device *dev, const struct mei_cl_id *id);
  24. int (*remove)(struct mei_cl_device *dev);
  25. };
  26. struct mei_cl_id {
  27. char name[MEI_NAME_SIZE];
  28. kernel_ulong_t driver_info;
  29. };
  30. The mei_cl_id structure allows the driver to bind itself against a device name.
  31. To actually register a driver on the ME Client bus one must call the mei_cl_add_driver()
  32. API. This is typically called at module init time.
  33. Once registered on the ME Client bus, a driver will typically try to do some I/O on
  34. this bus and this should be done through the mei_cl_send() and mei_cl_recv()
  35. routines. The latter is synchronous (blocks and sleeps until data shows up).
  36. In order for drivers to be notified of pending events waiting for them (e.g.
  37. an Rx event) they can register an event handler through the
  38. mei_cl_register_event_cb() routine. Currently only the MEI_EVENT_RX event
  39. will trigger an event handler call and the driver implementation is supposed
  40. to call mei_recv() from the event handler in order to fetch the pending
  41. received buffers.
  42. Example
  43. =======
  44. As a theoretical example let's pretend the ME comes with a "contact" NFC IP.
  45. The driver init and exit routines for this device would look like:
  46. #define CONTACT_DRIVER_NAME "contact"
  47. static struct mei_cl_device_id contact_mei_cl_tbl[] = {
  48. { CONTACT_DRIVER_NAME, },
  49. /* required last entry */
  50. { }
  51. };
  52. MODULE_DEVICE_TABLE(mei_cl, contact_mei_cl_tbl);
  53. static struct mei_cl_driver contact_driver = {
  54. .id_table = contact_mei_tbl,
  55. .name = CONTACT_DRIVER_NAME,
  56. .probe = contact_probe,
  57. .remove = contact_remove,
  58. };
  59. static int contact_init(void)
  60. {
  61. int r;
  62. r = mei_cl_driver_register(&contact_driver);
  63. if (r) {
  64. pr_err(CONTACT_DRIVER_NAME ": driver registration failed\n");
  65. return r;
  66. }
  67. return 0;
  68. }
  69. static void __exit contact_exit(void)
  70. {
  71. mei_cl_driver_unregister(&contact_driver);
  72. }
  73. module_init(contact_init);
  74. module_exit(contact_exit);
  75. And the driver's simplified probe routine would look like that:
  76. int contact_probe(struct mei_cl_device *dev, struct mei_cl_device_id *id)
  77. {
  78. struct contact_driver *contact;
  79. [...]
  80. mei_cl_enable_device(dev);
  81. mei_cl_register_event_cb(dev, contact_event_cb, contact);
  82. return 0;
  83. }
  84. In the probe routine the driver first enable the MEI device and then registers
  85. an ME bus event handler which is as close as it can get to registering a
  86. threaded IRQ handler.
  87. The handler implementation will typically call some I/O routine depending on
  88. the pending events:
  89. #define MAX_NFC_PAYLOAD 128
  90. static void contact_event_cb(struct mei_cl_device *dev, u32 events,
  91. void *context)
  92. {
  93. struct contact_driver *contact = context;
  94. if (events & BIT(MEI_EVENT_RX)) {
  95. u8 payload[MAX_NFC_PAYLOAD];
  96. int payload_size;
  97. payload_size = mei_recv(dev, payload, MAX_NFC_PAYLOAD);
  98. if (payload_size <= 0)
  99. return;
  100. /* Hook to the NFC subsystem */
  101. nfc_hci_recv_frame(contact->hdev, payload, payload_size);
  102. }
  103. }