dpmcp.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
  2. /*
  3. * Copyright 2013-2016 Freescale Semiconductor Inc.
  4. *
  5. */
  6. #include <linux/kernel.h>
  7. #include <linux/fsl/mc.h>
  8. #include "fsl-mc-private.h"
  9. /**
  10. * dpmcp_open() - Open a control session for the specified object.
  11. * @mc_io: Pointer to MC portal's I/O object
  12. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  13. * @dpmcp_id: DPMCP unique ID
  14. * @token: Returned token; use in subsequent API calls
  15. *
  16. * This function can be used to open a control session for an
  17. * already created object; an object may have been declared in
  18. * the DPL or by calling the dpmcp_create function.
  19. * This function returns a unique authentication token,
  20. * associated with the specific object ID and the specific MC
  21. * portal; this token must be used in all subsequent commands for
  22. * this specific object
  23. *
  24. * Return: '0' on Success; Error code otherwise.
  25. */
  26. int dpmcp_open(struct fsl_mc_io *mc_io,
  27. u32 cmd_flags,
  28. int dpmcp_id,
  29. u16 *token)
  30. {
  31. struct fsl_mc_command cmd = { 0 };
  32. struct dpmcp_cmd_open *cmd_params;
  33. int err;
  34. /* prepare command */
  35. cmd.header = mc_encode_cmd_header(DPMCP_CMDID_OPEN,
  36. cmd_flags, 0);
  37. cmd_params = (struct dpmcp_cmd_open *)cmd.params;
  38. cmd_params->dpmcp_id = cpu_to_le32(dpmcp_id);
  39. /* send command to mc*/
  40. err = mc_send_command(mc_io, &cmd);
  41. if (err)
  42. return err;
  43. /* retrieve response parameters */
  44. *token = mc_cmd_hdr_read_token(&cmd);
  45. return err;
  46. }
  47. /**
  48. * dpmcp_close() - Close the control session of the object
  49. * @mc_io: Pointer to MC portal's I/O object
  50. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  51. * @token: Token of DPMCP object
  52. *
  53. * After this function is called, no further operations are
  54. * allowed on the object without opening a new control session.
  55. *
  56. * Return: '0' on Success; Error code otherwise.
  57. */
  58. int dpmcp_close(struct fsl_mc_io *mc_io,
  59. u32 cmd_flags,
  60. u16 token)
  61. {
  62. struct fsl_mc_command cmd = { 0 };
  63. /* prepare command */
  64. cmd.header = mc_encode_cmd_header(DPMCP_CMDID_CLOSE,
  65. cmd_flags, token);
  66. /* send command to mc*/
  67. return mc_send_command(mc_io, &cmd);
  68. }
  69. /**
  70. * dpmcp_reset() - Reset the DPMCP, returns the object to initial state.
  71. * @mc_io: Pointer to MC portal's I/O object
  72. * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_'
  73. * @token: Token of DPMCP object
  74. *
  75. * Return: '0' on Success; Error code otherwise.
  76. */
  77. int dpmcp_reset(struct fsl_mc_io *mc_io,
  78. u32 cmd_flags,
  79. u16 token)
  80. {
  81. struct fsl_mc_command cmd = { 0 };
  82. /* prepare command */
  83. cmd.header = mc_encode_cmd_header(DPMCP_CMDID_RESET,
  84. cmd_flags, token);
  85. /* send command to mc*/
  86. return mc_send_command(mc_io, &cmd);
  87. }