1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include "hpi_internal.h"
25#include "hpimsginit.h"
26#include <linux/nospec.h>
27
28
29static u16 msg_size[HPI_OBJ_MAXINDEX + 1] = HPI_MESSAGE_SIZE_BY_OBJECT;
30
31static u16 res_size[HPI_OBJ_MAXINDEX + 1] = HPI_RESPONSE_SIZE_BY_OBJECT;
32
33static u16 gwSSX2_bypass;
34
35
36
37
38static void hpi_init_message(struct hpi_message *phm, u16 object,
39 u16 function)
40{
41 u16 size;
42
43 if ((object > 0) && (object <= HPI_OBJ_MAXINDEX)) {
44 object = array_index_nospec(object, HPI_OBJ_MAXINDEX + 1);
45 size = msg_size[object];
46 } else {
47 size = sizeof(*phm);
48 }
49
50 memset(phm, 0, size);
51 phm->size = size;
52
53 if (gwSSX2_bypass)
54 phm->type = HPI_TYPE_SSX2BYPASS_MESSAGE;
55 else
56 phm->type = HPI_TYPE_REQUEST;
57 phm->object = object;
58 phm->function = function;
59 phm->version = 0;
60 phm->adapter_index = HPI_ADAPTER_INDEX_INVALID;
61
62}
63
64
65
66
67void hpi_init_response(struct hpi_response *phr, u16 object, u16 function,
68 u16 error)
69{
70 u16 size;
71
72 if ((object > 0) && (object <= HPI_OBJ_MAXINDEX)) {
73 object = array_index_nospec(object, HPI_OBJ_MAXINDEX + 1);
74 size = res_size[object];
75 } else {
76 size = sizeof(*phr);
77 }
78
79 memset(phr, 0, sizeof(*phr));
80 phr->size = size;
81 phr->type = HPI_TYPE_RESPONSE;
82 phr->object = object;
83 phr->function = function;
84 phr->error = error;
85 phr->specific_error = 0;
86 phr->version = 0;
87}
88
89void hpi_init_message_response(struct hpi_message *phm,
90 struct hpi_response *phr, u16 object, u16 function)
91{
92 hpi_init_message(phm, object, function);
93
94
95 hpi_init_response(phr, object, function,
96 HPI_ERROR_PROCESSING_MESSAGE);
97}
98
99static void hpi_init_messageV1(struct hpi_message_header *phm, u16 size,
100 u16 object, u16 function)
101{
102 memset(phm, 0, size);
103 if ((object > 0) && (object <= HPI_OBJ_MAXINDEX)) {
104 phm->size = size;
105 phm->type = HPI_TYPE_REQUEST;
106 phm->object = object;
107 phm->function = function;
108 phm->version = 1;
109
110 }
111}
112
113void hpi_init_responseV1(struct hpi_response_header *phr, u16 size,
114 u16 object, u16 function)
115{
116 (void)object;
117 (void)function;
118 memset(phr, 0, size);
119 phr->size = size;
120 phr->version = 1;
121 phr->type = HPI_TYPE_RESPONSE;
122 phr->error = HPI_ERROR_PROCESSING_MESSAGE;
123}
124
125void hpi_init_message_responseV1(struct hpi_message_header *phm, u16 msg_size,
126 struct hpi_response_header *phr, u16 res_size, u16 object,
127 u16 function)
128{
129 hpi_init_messageV1(phm, msg_size, object, function);
130 hpi_init_responseV1(phr, res_size, object, function);
131}
132