logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

psp-dbc.h (5279B)


  1. /* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */
  2. /*
  3. * Userspace interface for AMD Dynamic Boost Control (DBC)
  4. *
  5. * Copyright (C) 2023 Advanced Micro Devices, Inc.
  6. *
  7. * Author: Mario Limonciello <mario.limonciello@amd.com>
  8. */
  9. #ifndef __PSP_DBC_USER_H__
  10. #define __PSP_DBC_USER_H__
  11. #include <linux/types.h>
  12. /**
  13. * DOC: AMD Dynamic Boost Control (DBC) interface
  14. */
  15. #define DBC_NONCE_SIZE 16
  16. #define DBC_SIG_SIZE 32
  17. #define DBC_UID_SIZE 16
  18. /**
  19. * struct dbc_user_nonce - Nonce exchange structure (input/output).
  20. * @auth_needed: Whether the PSP should authenticate this request (input).
  21. * 0: no authentication, PSP will return single use nonce.
  22. * 1: authentication: PSP will return multi-use nonce.
  23. * @nonce: 8 byte value used for future authentication (output).
  24. * @signature: Optional 32 byte signature created by software using a
  25. * previous nonce (input).
  26. */
  27. struct dbc_user_nonce {
  28. __u32 auth_needed;
  29. __u8 nonce[DBC_NONCE_SIZE];
  30. __u8 signature[DBC_SIG_SIZE];
  31. } __attribute__((packed));
  32. /**
  33. * struct dbc_user_setuid - UID exchange structure (input).
  34. * @uid: 16 byte value representing software identity
  35. * @signature: 32 byte signature created by software using a previous nonce
  36. */
  37. struct dbc_user_setuid {
  38. __u8 uid[DBC_UID_SIZE];
  39. __u8 signature[DBC_SIG_SIZE];
  40. } __attribute__((packed));
  41. /**
  42. * struct dbc_user_param - Parameter exchange structure (input/output).
  43. * @msg_index: Message indicating what parameter to set or get (input)
  44. * @param: 4 byte parameter, units are message specific. (input/output)
  45. * @signature: 32 byte signature.
  46. * - When sending a message this is to be created by software
  47. * using a previous nonce (input)
  48. * - For interpreting results, this signature is updated by the
  49. * PSP to allow software to validate the authenticity of the
  50. * results.
  51. */
  52. struct dbc_user_param {
  53. __u32 msg_index;
  54. __u32 param;
  55. __u8 signature[DBC_SIG_SIZE];
  56. } __attribute__((packed));
  57. /**
  58. * Dynamic Boost Control (DBC) IOC
  59. *
  60. * possible return codes for all DBC IOCTLs:
  61. * 0: success
  62. * -EINVAL: invalid input
  63. * -E2BIG: excess data passed
  64. * -EFAULT: failed to copy to/from userspace
  65. * -EBUSY: mailbox in recovery or in use
  66. * -ENODEV: driver not bound with PSP device
  67. * -EACCES: request isn't authorized
  68. * -EINVAL: invalid parameter
  69. * -ETIMEDOUT: request timed out
  70. * -EAGAIN: invalid request for state machine
  71. * -ENOENT: not implemented
  72. * -ENFILE: overflow
  73. * -EPERM: invalid signature
  74. * -EIO: unknown error
  75. */
  76. #define DBC_IOC_TYPE 'D'
  77. /**
  78. * DBCIOCNONCE - Fetch a nonce from the PSP for authenticating commands.
  79. * If a nonce is fetched without authentication it can only
  80. * be utilized for one command.
  81. * If a nonce is fetched with authentication it can be used
  82. * for multiple requests.
  83. */
  84. #define DBCIOCNONCE _IOWR(DBC_IOC_TYPE, 0x1, struct dbc_user_nonce)
  85. /**
  86. * DBCIOCUID - Set the user ID (UID) of a calling process.
  87. * The user ID is 8 bytes long. It must be programmed using a
  88. * 32 byte signature built using the nonce fetched from
  89. * DBCIOCNONCE.
  90. * The UID can only be set once until the system is rebooted.
  91. */
  92. #define DBCIOCUID _IOW(DBC_IOC_TYPE, 0x2, struct dbc_user_setuid)
  93. /**
  94. * DBCIOCPARAM - Set or get a parameter from the PSP.
  95. * This request will only work after DBCIOCUID has successfully
  96. * set the UID of the calling process.
  97. * Whether the parameter is set or get is controlled by the
  98. * message ID in the request.
  99. * This command must be sent using a 32 byte signature built
  100. * using the nonce fetched from DBCIOCNONCE.
  101. * When the command succeeds, the 32 byte signature will be
  102. * updated by the PSP for software to authenticate the results.
  103. */
  104. #define DBCIOCPARAM _IOWR(DBC_IOC_TYPE, 0x3, struct dbc_user_param)
  105. /**
  106. * enum dbc_cmd_msg - Messages utilized by DBCIOCPARAM
  107. * @PARAM_GET_FMAX_CAP: Get frequency cap (MHz)
  108. * @PARAM_SET_FMAX_CAP: Set frequency cap (MHz)
  109. * @PARAM_GET_PWR_CAP: Get socket power cap (mW)
  110. * @PARAM_SET_PWR_CAP: Set socket power cap (mW)
  111. * @PARAM_GET_GFX_MODE: Get graphics mode (0/1)
  112. * @PARAM_SET_GFX_MODE: Set graphics mode (0/1)
  113. * @PARAM_GET_CURR_TEMP: Get current temperature (degrees C)
  114. * @PARAM_GET_FMAX_MAX: Get maximum allowed value for frequency (MHz)
  115. * @PARAM_GET_FMAX_MIN: Get minimum allowed value for frequency (MHz)
  116. * @PARAM_GET_SOC_PWR_MAX: Get maximum allowed value for SoC power (mw)
  117. * @PARAM_GET_SOC_PWR_MIN: Get minimum allowed value for SoC power (mw)
  118. * @PARAM_GET_SOC_PWR_CUR: Get current value for SoC Power (mW)
  119. */
  120. enum dbc_cmd_msg {
  121. PARAM_GET_FMAX_CAP = 0x3,
  122. PARAM_SET_FMAX_CAP = 0x4,
  123. PARAM_GET_PWR_CAP = 0x5,
  124. PARAM_SET_PWR_CAP = 0x6,
  125. PARAM_GET_GFX_MODE = 0x7,
  126. PARAM_SET_GFX_MODE = 0x8,
  127. PARAM_GET_CURR_TEMP = 0x9,
  128. PARAM_GET_FMAX_MAX = 0xA,
  129. PARAM_GET_FMAX_MIN = 0xB,
  130. PARAM_GET_SOC_PWR_MAX = 0xC,
  131. PARAM_GET_SOC_PWR_MIN = 0xD,
  132. PARAM_GET_SOC_PWR_CUR = 0xE,
  133. };
  134. #endif /* __PSP_DBC_USER_H__ */