1 // SPDX-License-Identifier: GPL-2.0-only
2 /******************************************************************************
4 AudioScience HPI driver
5 Copyright (C) 1997-2014 AudioScience Inc. <support@audioscience.com>
8 Hardware Programming Interface (HPI) Utility functions.
10 (C) Copyright AudioScience Inc. 2007
11 *******************************************************************************/
13 #include "hpi_internal.h"
14 #include "hpimsginit.h"
15 #include <linux/nospec.h>
17 /* The actual message size for each object type */
18 static u16 msg_size
[HPI_OBJ_MAXINDEX
+ 1] = HPI_MESSAGE_SIZE_BY_OBJECT
;
19 /* The actual response size for each object type */
20 static u16 res_size
[HPI_OBJ_MAXINDEX
+ 1] = HPI_RESPONSE_SIZE_BY_OBJECT
;
21 /* Flag to enable alternate message type for SSX2 bypass. */
22 static u16 gwSSX2_bypass
;
25 * initialize the HPI message structure
27 static void hpi_init_message(struct hpi_message
*phm
, u16 object
,
32 if ((object
> 0) && (object
<= HPI_OBJ_MAXINDEX
)) {
33 object
= array_index_nospec(object
, HPI_OBJ_MAXINDEX
+ 1);
34 size
= msg_size
[object
];
43 phm
->type
= HPI_TYPE_SSX2BYPASS_MESSAGE
;
45 phm
->type
= HPI_TYPE_REQUEST
;
47 phm
->function
= function
;
49 phm
->adapter_index
= HPI_ADAPTER_INDEX_INVALID
;
50 /* Expect actual adapter index to be set by caller */
54 * initialize the HPI response structure
56 void hpi_init_response(struct hpi_response
*phr
, u16 object
, u16 function
,
61 if ((object
> 0) && (object
<= HPI_OBJ_MAXINDEX
)) {
62 object
= array_index_nospec(object
, HPI_OBJ_MAXINDEX
+ 1);
63 size
= res_size
[object
];
68 memset(phr
, 0, sizeof(*phr
));
70 phr
->type
= HPI_TYPE_RESPONSE
;
72 phr
->function
= function
;
74 phr
->specific_error
= 0;
78 void hpi_init_message_response(struct hpi_message
*phm
,
79 struct hpi_response
*phr
, u16 object
, u16 function
)
81 hpi_init_message(phm
, object
, function
);
82 /* default error return if the response is
83 not filled in by the callee */
84 hpi_init_response(phr
, object
, function
,
85 HPI_ERROR_PROCESSING_MESSAGE
);
88 static void hpi_init_messageV1(struct hpi_message_header
*phm
, u16 size
,
89 u16 object
, u16 function
)
92 if ((object
> 0) && (object
<= HPI_OBJ_MAXINDEX
)) {
94 phm
->type
= HPI_TYPE_REQUEST
;
96 phm
->function
= function
;
98 /* Expect adapter index to be set by caller */
102 void hpi_init_responseV1(struct hpi_response_header
*phr
, u16 size
,
103 u16 object
, u16 function
)
107 memset(phr
, 0, size
);
110 phr
->type
= HPI_TYPE_RESPONSE
;
111 phr
->error
= HPI_ERROR_PROCESSING_MESSAGE
;
114 void hpi_init_message_responseV1(struct hpi_message_header
*phm
, u16 msg_size
,
115 struct hpi_response_header
*phr
, u16 res_size
, u16 object
,
118 hpi_init_messageV1(phm
, msg_size
, object
, function
);
119 hpi_init_responseV1(phr
, res_size
, object
, function
);