cdev.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */
  2. /*
  3. * Surface System Aggregator Module (SSAM) user-space EC interface.
  4. *
  5. * Definitions, structs, and IOCTLs for the /dev/surface/aggregator misc
  6. * device. This device provides direct user-space access to the SSAM EC.
  7. * Intended for debugging and development.
  8. *
  9. * Copyright (C) 2020-2021 Maximilian Luz <luzmaximilian@gmail.com>
  10. */
  11. #ifndef _LINUX_SURFACE_AGGREGATOR_CDEV_H
  12. #define _LINUX_SURFACE_AGGREGATOR_CDEV_H
  13. #include <linux/ioctl.h>
  14. #include <linux/types.h>
  15. /**
  16. * enum ssam_cdev_request_flags - Request flags for SSAM cdev request IOCTL.
  17. *
  18. * @SSAM_CDEV_REQUEST_HAS_RESPONSE:
  19. * Specifies that the request expects a response. If not set, the request
  20. * will be directly completed after its underlying packet has been
  21. * transmitted. If set, the request transport system waits for a response
  22. * of the request.
  23. *
  24. * @SSAM_CDEV_REQUEST_UNSEQUENCED:
  25. * Specifies that the request should be transmitted via an unsequenced
  26. * packet. If set, the request must not have a response, meaning that this
  27. * flag and the %SSAM_CDEV_REQUEST_HAS_RESPONSE flag are mutually
  28. * exclusive.
  29. */
  30. enum ssam_cdev_request_flags {
  31. SSAM_CDEV_REQUEST_HAS_RESPONSE = 0x01,
  32. SSAM_CDEV_REQUEST_UNSEQUENCED = 0x02,
  33. };
  34. /**
  35. * struct ssam_cdev_request - Controller request IOCTL argument.
  36. * @target_category: Target category of the SAM request.
  37. * @target_id: Target ID of the SAM request.
  38. * @command_id: Command ID of the SAM request.
  39. * @instance_id: Instance ID of the SAM request.
  40. * @flags: Request flags (see &enum ssam_cdev_request_flags).
  41. * @status: Request status (output).
  42. * @payload: Request payload (input data).
  43. * @payload.data: Pointer to request payload data.
  44. * @payload.length: Length of request payload data (in bytes).
  45. * @response: Request response (output data).
  46. * @response.data: Pointer to response buffer.
  47. * @response.length: On input: Capacity of response buffer (in bytes).
  48. * On output: Length of request response (number of bytes
  49. * in the buffer that are actually used).
  50. */
  51. struct ssam_cdev_request {
  52. __u8 target_category;
  53. __u8 target_id;
  54. __u8 command_id;
  55. __u8 instance_id;
  56. __u16 flags;
  57. __s16 status;
  58. struct {
  59. __u64 data;
  60. __u16 length;
  61. __u8 __pad[6];
  62. } payload;
  63. struct {
  64. __u64 data;
  65. __u16 length;
  66. __u8 __pad[6];
  67. } response;
  68. } __attribute__((__packed__));
  69. /**
  70. * struct ssam_cdev_notifier_desc - Notifier descriptor.
  71. * @priority: Priority value determining the order in which notifier
  72. * callbacks will be called. A higher value means higher
  73. * priority, i.e. the associated callback will be executed
  74. * earlier than other (lower priority) callbacks.
  75. * @target_category: The event target category for which this notifier should
  76. * receive events.
  77. *
  78. * Specifies the notifier that should be registered or unregistered,
  79. * specifically with which priority and for which target category of events.
  80. */
  81. struct ssam_cdev_notifier_desc {
  82. __s32 priority;
  83. __u8 target_category;
  84. } __attribute__((__packed__));
  85. /**
  86. * struct ssam_cdev_event_desc - Event descriptor.
  87. * @reg: Registry via which the event will be enabled/disabled.
  88. * @reg.target_category: Target category for the event registry requests.
  89. * @reg.target_id: Target ID for the event registry requests.
  90. * @reg.cid_enable: Command ID for the event-enable request.
  91. * @reg.cid_disable: Command ID for the event-disable request.
  92. * @id: ID specifying the event.
  93. * @id.target_category: Target category of the event source.
  94. * @id.instance: Instance ID of the event source.
  95. * @flags: Flags used for enabling the event.
  96. *
  97. * Specifies which event should be enabled/disabled and how to do that.
  98. */
  99. struct ssam_cdev_event_desc {
  100. struct {
  101. __u8 target_category;
  102. __u8 target_id;
  103. __u8 cid_enable;
  104. __u8 cid_disable;
  105. } reg;
  106. struct {
  107. __u8 target_category;
  108. __u8 instance;
  109. } id;
  110. __u8 flags;
  111. } __attribute__((__packed__));
  112. /**
  113. * struct ssam_cdev_event - SSAM event sent by the EC.
  114. * @target_category: Target category of the event source. See &enum ssam_ssh_tc.
  115. * @target_id: Target ID of the event source.
  116. * @command_id: Command ID of the event.
  117. * @instance_id: Instance ID of the event source.
  118. * @length: Length of the event payload in bytes.
  119. * @data: Event payload data.
  120. */
  121. struct ssam_cdev_event {
  122. __u8 target_category;
  123. __u8 target_id;
  124. __u8 command_id;
  125. __u8 instance_id;
  126. __u16 length;
  127. __u8 data[];
  128. } __attribute__((__packed__));
  129. #define SSAM_CDEV_REQUEST _IOWR(0xA5, 1, struct ssam_cdev_request)
  130. #define SSAM_CDEV_NOTIF_REGISTER _IOW(0xA5, 2, struct ssam_cdev_notifier_desc)
  131. #define SSAM_CDEV_NOTIF_UNREGISTER _IOW(0xA5, 3, struct ssam_cdev_notifier_desc)
  132. #define SSAM_CDEV_EVENT_ENABLE _IOW(0xA5, 4, struct ssam_cdev_event_desc)
  133. #define SSAM_CDEV_EVENT_DISABLE _IOW(0xA5, 5, struct ssam_cdev_event_desc)
  134. #endif /* _LINUX_SURFACE_AGGREGATOR_CDEV_H */