Loading...
1/******************************************************************************
2
3 AudioScience HPI driver
4 Copyright (C) 1997-2011 AudioScience Inc. <support@audioscience.com>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of version 2 of the GNU General Public License as
8 published by the Free Software Foundation;
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19 Hardware Programming Interface (HPI) Utility functions.
20
21 (C) Copyright AudioScience Inc. 2007
22*******************************************************************************/
23
24#include "hpi_internal.h"
25#include "hpimsginit.h"
26
27/* The actual message size for each object type */
28static u16 msg_size[HPI_OBJ_MAXINDEX + 1] = HPI_MESSAGE_SIZE_BY_OBJECT;
29/* The actual response size for each object type */
30static u16 res_size[HPI_OBJ_MAXINDEX + 1] = HPI_RESPONSE_SIZE_BY_OBJECT;
31/* Flag to enable alternate message type for SSX2 bypass. */
32static u16 gwSSX2_bypass;
33
34/** \internal
35 * initialize the HPI message structure
36 */
37static void hpi_init_message(struct hpi_message *phm, u16 object,
38 u16 function)
39{
40 memset(phm, 0, sizeof(*phm));
41 if ((object > 0) && (object <= HPI_OBJ_MAXINDEX))
42 phm->size = msg_size[object];
43 else
44 phm->size = sizeof(*phm);
45
46 if (gwSSX2_bypass)
47 phm->type = HPI_TYPE_SSX2BYPASS_MESSAGE;
48 else
49 phm->type = HPI_TYPE_REQUEST;
50 phm->object = object;
51 phm->function = function;
52 phm->version = 0;
53 phm->adapter_index = HPI_ADAPTER_INDEX_INVALID;
54 /* Expect actual adapter index to be set by caller */
55}
56
57/** \internal
58 * initialize the HPI response structure
59 */
60void hpi_init_response(struct hpi_response *phr, u16 object, u16 function,
61 u16 error)
62{
63 memset(phr, 0, sizeof(*phr));
64 phr->type = HPI_TYPE_RESPONSE;
65 if ((object > 0) && (object <= HPI_OBJ_MAXINDEX))
66 phr->size = res_size[object];
67 else
68 phr->size = sizeof(*phr);
69 phr->object = object;
70 phr->function = function;
71 phr->error = error;
72 phr->specific_error = 0;
73 phr->version = 0;
74}
75
76void hpi_init_message_response(struct hpi_message *phm,
77 struct hpi_response *phr, u16 object, u16 function)
78{
79 hpi_init_message(phm, object, function);
80 /* default error return if the response is
81 not filled in by the callee */
82 hpi_init_response(phr, object, function,
83 HPI_ERROR_PROCESSING_MESSAGE);
84}
85
86static void hpi_init_messageV1(struct hpi_message_header *phm, u16 size,
87 u16 object, u16 function)
88{
89 memset(phm, 0, sizeof(*phm));
90 if ((object > 0) && (object <= HPI_OBJ_MAXINDEX)) {
91 phm->size = size;
92 phm->type = HPI_TYPE_REQUEST;
93 phm->object = object;
94 phm->function = function;
95 phm->version = 1;
96 /* Expect adapter index to be set by caller */
97 }
98}
99
100void hpi_init_responseV1(struct hpi_response_header *phr, u16 size,
101 u16 object, u16 function)
102{
103 memset(phr, 0, sizeof(*phr));
104 phr->size = size;
105 phr->version = 1;
106 phr->type = HPI_TYPE_RESPONSE;
107 phr->error = HPI_ERROR_PROCESSING_MESSAGE;
108}
109
110void hpi_init_message_responseV1(struct hpi_message_header *phm, u16 msg_size,
111 struct hpi_response_header *phr, u16 res_size, u16 object,
112 u16 function)
113{
114 hpi_init_messageV1(phm, msg_size, object, function);
115 hpi_init_responseV1(phr, res_size, object, function);
116}
1// SPDX-License-Identifier: GPL-2.0-only
2/******************************************************************************
3
4 AudioScience HPI driver
5 Copyright (C) 1997-2014 AudioScience Inc. <support@audioscience.com>
6
7
8 Hardware Programming Interface (HPI) Utility functions.
9
10 (C) Copyright AudioScience Inc. 2007
11*******************************************************************************/
12
13#include "hpi_internal.h"
14#include "hpimsginit.h"
15#include <linux/nospec.h>
16
17/* The actual message size for each object type */
18static u16 msg_size[HPI_OBJ_MAXINDEX + 1] = HPI_MESSAGE_SIZE_BY_OBJECT;
19/* The actual response size for each object type */
20static u16 res_size[HPI_OBJ_MAXINDEX + 1] = HPI_RESPONSE_SIZE_BY_OBJECT;
21/* Flag to enable alternate message type for SSX2 bypass. */
22static u16 gwSSX2_bypass;
23
24/** \internal
25 * initialize the HPI message structure
26 */
27static void hpi_init_message(struct hpi_message *phm, u16 object,
28 u16 function)
29{
30 u16 size;
31
32 if ((object > 0) && (object <= HPI_OBJ_MAXINDEX)) {
33 object = array_index_nospec(object, HPI_OBJ_MAXINDEX + 1);
34 size = msg_size[object];
35 } else {
36 size = sizeof(*phm);
37 }
38
39 memset(phm, 0, size);
40 phm->size = size;
41
42 if (gwSSX2_bypass)
43 phm->type = HPI_TYPE_SSX2BYPASS_MESSAGE;
44 else
45 phm->type = HPI_TYPE_REQUEST;
46 phm->object = object;
47 phm->function = function;
48 phm->version = 0;
49 phm->adapter_index = HPI_ADAPTER_INDEX_INVALID;
50 /* Expect actual adapter index to be set by caller */
51}
52
53/** \internal
54 * initialize the HPI response structure
55 */
56void hpi_init_response(struct hpi_response *phr, u16 object, u16 function,
57 u16 error)
58{
59 u16 size;
60
61 if ((object > 0) && (object <= HPI_OBJ_MAXINDEX)) {
62 object = array_index_nospec(object, HPI_OBJ_MAXINDEX + 1);
63 size = res_size[object];
64 } else {
65 size = sizeof(*phr);
66 }
67
68 memset(phr, 0, sizeof(*phr));
69 phr->size = size;
70 phr->type = HPI_TYPE_RESPONSE;
71 phr->object = object;
72 phr->function = function;
73 phr->error = error;
74 phr->specific_error = 0;
75 phr->version = 0;
76}
77
78void hpi_init_message_response(struct hpi_message *phm,
79 struct hpi_response *phr, u16 object, u16 function)
80{
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);
86}
87
88static void hpi_init_messageV1(struct hpi_message_header *phm, u16 size,
89 u16 object, u16 function)
90{
91 memset(phm, 0, size);
92 if ((object > 0) && (object <= HPI_OBJ_MAXINDEX)) {
93 phm->size = size;
94 phm->type = HPI_TYPE_REQUEST;
95 phm->object = object;
96 phm->function = function;
97 phm->version = 1;
98 /* Expect adapter index to be set by caller */
99 }
100}
101
102void hpi_init_responseV1(struct hpi_response_header *phr, u16 size,
103 u16 object, u16 function)
104{
105 (void)object;
106 (void)function;
107 memset(phr, 0, size);
108 phr->size = size;
109 phr->version = 1;
110 phr->type = HPI_TYPE_RESPONSE;
111 phr->error = HPI_ERROR_PROCESSING_MESSAGE;
112}
113
114void hpi_init_message_responseV1(struct hpi_message_header *phm, u16 msg_size,
115 struct hpi_response_header *phr, u16 res_size, u16 object,
116 u16 function)
117{
118 hpi_init_messageV1(phm, msg_size, object, function);
119 hpi_init_responseV1(phr, res_size, object, function);
120}