hpimsginit.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /******************************************************************************
  3. AudioScience HPI driver
  4. Copyright (C) 1997-2014 AudioScience Inc. <[email protected]>
  5. Hardware Programming Interface (HPI) Utility functions.
  6. (C) Copyright AudioScience Inc. 2007
  7. *******************************************************************************/
  8. #include "hpi_internal.h"
  9. #include "hpimsginit.h"
  10. #include <linux/nospec.h>
  11. /* The actual message size for each object type */
  12. static u16 msg_size[HPI_OBJ_MAXINDEX + 1] = HPI_MESSAGE_SIZE_BY_OBJECT;
  13. /* The actual response size for each object type */
  14. static u16 res_size[HPI_OBJ_MAXINDEX + 1] = HPI_RESPONSE_SIZE_BY_OBJECT;
  15. /* Flag to enable alternate message type for SSX2 bypass. */
  16. static u16 gwSSX2_bypass;
  17. /** \internal
  18. * initialize the HPI message structure
  19. */
  20. static void hpi_init_message(struct hpi_message *phm, u16 object,
  21. u16 function)
  22. {
  23. u16 size;
  24. if ((object > 0) && (object <= HPI_OBJ_MAXINDEX)) {
  25. object = array_index_nospec(object, HPI_OBJ_MAXINDEX + 1);
  26. size = msg_size[object];
  27. } else {
  28. size = sizeof(*phm);
  29. }
  30. memset(phm, 0, size);
  31. phm->size = size;
  32. if (gwSSX2_bypass)
  33. phm->type = HPI_TYPE_SSX2BYPASS_MESSAGE;
  34. else
  35. phm->type = HPI_TYPE_REQUEST;
  36. phm->object = object;
  37. phm->function = function;
  38. phm->version = 0;
  39. phm->adapter_index = HPI_ADAPTER_INDEX_INVALID;
  40. /* Expect actual adapter index to be set by caller */
  41. }
  42. /** \internal
  43. * initialize the HPI response structure
  44. */
  45. void hpi_init_response(struct hpi_response *phr, u16 object, u16 function,
  46. u16 error)
  47. {
  48. u16 size;
  49. if ((object > 0) && (object <= HPI_OBJ_MAXINDEX)) {
  50. object = array_index_nospec(object, HPI_OBJ_MAXINDEX + 1);
  51. size = res_size[object];
  52. } else {
  53. size = sizeof(*phr);
  54. }
  55. memset(phr, 0, sizeof(*phr));
  56. phr->size = size;
  57. phr->type = HPI_TYPE_RESPONSE;
  58. phr->object = object;
  59. phr->function = function;
  60. phr->error = error;
  61. phr->specific_error = 0;
  62. phr->version = 0;
  63. }
  64. void hpi_init_message_response(struct hpi_message *phm,
  65. struct hpi_response *phr, u16 object, u16 function)
  66. {
  67. hpi_init_message(phm, object, function);
  68. /* default error return if the response is
  69. not filled in by the callee */
  70. hpi_init_response(phr, object, function,
  71. HPI_ERROR_PROCESSING_MESSAGE);
  72. }
  73. static void hpi_init_messageV1(struct hpi_message_header *phm, u16 size,
  74. u16 object, u16 function)
  75. {
  76. memset(phm, 0, size);
  77. if ((object > 0) && (object <= HPI_OBJ_MAXINDEX)) {
  78. phm->size = size;
  79. phm->type = HPI_TYPE_REQUEST;
  80. phm->object = object;
  81. phm->function = function;
  82. phm->version = 1;
  83. /* Expect adapter index to be set by caller */
  84. }
  85. }
  86. void hpi_init_responseV1(struct hpi_response_header *phr, u16 size,
  87. u16 object, u16 function)
  88. {
  89. (void)object;
  90. (void)function;
  91. memset(phr, 0, size);
  92. phr->size = size;
  93. phr->version = 1;
  94. phr->type = HPI_TYPE_RESPONSE;
  95. phr->error = HPI_ERROR_PROCESSING_MESSAGE;
  96. }
  97. void hpi_init_message_responseV1(struct hpi_message_header *phm, u16 msg_size,
  98. struct hpi_response_header *phr, u16 res_size, u16 object,
  99. u16 function)
  100. {
  101. hpi_init_messageV1(phm, msg_size, object, function);
  102. hpi_init_responseV1(phr, res_size, object, function);
  103. }