Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Copyright (C) 2017-2018, Intel Corporation
4 */
5
6#ifndef __STRATIX10_SVC_CLIENT_H
7#define __STRATIX10_SVC_CLIENT_H
8
9/*
10 * Service layer driver supports client names
11 *
12 * fpga: for FPGA configuration
13 * rsu: for remote status update
14 */
15#define SVC_CLIENT_FPGA "fpga"
16#define SVC_CLIENT_RSU "rsu"
17#define SVC_CLIENT_FCS "fcs"
18
19/*
20 * Status of the sent command, in bit number
21 *
22 * SVC_STATUS_OK:
23 * Secure firmware accepts the request issued by one of service clients.
24 *
25 * SVC_STATUS_BUFFER_SUBMITTED:
26 * Service client successfully submits data buffer to secure firmware.
27 *
28 * SVC_STATUS_BUFFER_DONE:
29 * Secure firmware completes data process, ready to accept the
30 * next WRITE transaction.
31 *
32 * SVC_STATUS_COMPLETED:
33 * Secure firmware completes service request successfully. In case of
34 * FPGA configuration, FPGA should be in user mode.
35 *
36 * SVC_COMMAND_STATUS_BUSY:
37 * Service request is still in process.
38 *
39 * SVC_COMMAND_STATUS_ERROR:
40 * Error encountered during the process of the service request.
41 *
42 * SVC_STATUS_NO_SUPPORT:
43 * Secure firmware doesn't support requested features such as RSU retry
44 * or RSU notify.
45 */
46#define SVC_STATUS_OK 0
47#define SVC_STATUS_BUFFER_SUBMITTED 1
48#define SVC_STATUS_BUFFER_DONE 2
49#define SVC_STATUS_COMPLETED 3
50#define SVC_STATUS_BUSY 4
51#define SVC_STATUS_ERROR 5
52#define SVC_STATUS_NO_SUPPORT 6
53#define SVC_STATUS_INVALID_PARAM 7
54
55/*
56 * Flag bit for COMMAND_RECONFIG
57 *
58 * COMMAND_RECONFIG_FLAG_PARTIAL:
59 * Set to FPGA configuration type (full or partial).
60 */
61#define COMMAND_RECONFIG_FLAG_PARTIAL 0
62
63/*
64 * Timeout settings for service clients:
65 * timeout value used in Stratix10 FPGA manager driver.
66 * timeout value used in RSU driver
67 */
68#define SVC_RECONFIG_REQUEST_TIMEOUT_MS 300
69#define SVC_RECONFIG_BUFFER_TIMEOUT_MS 720
70#define SVC_RSU_REQUEST_TIMEOUT_MS 300
71#define SVC_FCS_REQUEST_TIMEOUT_MS 2000
72#define SVC_COMPLETED_TIMEOUT_MS 30000
73
74struct stratix10_svc_chan;
75
76/**
77 * enum stratix10_svc_command_code - supported service commands
78 *
79 * @COMMAND_NOOP: do 'dummy' request for integration/debug/trouble-shooting
80 *
81 * @COMMAND_RECONFIG: ask for FPGA configuration preparation, return status
82 * is SVC_STATUS_OK
83 *
84 * @COMMAND_RECONFIG_DATA_SUBMIT: submit buffer(s) of bit-stream data for the
85 * FPGA configuration, return status is SVC_STATUS_SUBMITTED or SVC_STATUS_ERROR
86 *
87 * @COMMAND_RECONFIG_DATA_CLAIM: check the status of the configuration, return
88 * status is SVC_STATUS_COMPLETED, or SVC_STATUS_BUSY, or SVC_STATUS_ERROR
89 *
90 * @COMMAND_RECONFIG_STATUS: check the status of the configuration, return
91 * status is SVC_STATUS_COMPLETED, or SVC_STATUS_BUSY, or SVC_STATUS_ERROR
92 *
93 * @COMMAND_RSU_STATUS: request remote system update boot log, return status
94 * is log data or SVC_STATUS_RSU_ERROR
95 *
96 * @COMMAND_RSU_UPDATE: set the offset of the bitstream to boot after reboot,
97 * return status is SVC_STATUS_OK or SVC_STATUS_ERROR
98 *
99 * @COMMAND_RSU_NOTIFY: report the status of hard processor system
100 * software to firmware, return status is SVC_STATUS_OK or
101 * SVC_STATUS_ERROR
102 *
103 * @COMMAND_RSU_RETRY: query firmware for the current image's retry counter,
104 * return status is SVC_STATUS_OK or SVC_STATUS_ERROR
105 *
106 * @COMMAND_RSU_MAX_RETRY: query firmware for the max retry value,
107 * return status is SVC_STATUS_OK or SVC_STATUS_ERROR
108 *
109 * @COMMAND_RSU_DCMF_VERSION: query firmware for the DCMF version, return status
110 * is SVC_STATUS_OK or SVC_STATUS_ERROR
111 *
112 * @COMMAND_POLL_SERVICE_STATUS: poll if the service request is complete,
113 * return statis is SVC_STATUS_OK, SVC_STATUS_ERROR or SVC_STATUS_BUSY
114 *
115 * @COMMAND_FIRMWARE_VERSION: query running firmware version, return status
116 * is SVC_STATUS_OK or SVC_STATUS_ERROR
117 *
118 * @COMMAND_SMC_SVC_VERSION: Non-mailbox SMC SVC API Version,
119 * return status is SVC_STATUS_OK
120 *
121 * @COMMAND_RSU_DCMF_STATUS: query firmware for the DCMF status
122 * return status is SVC_STATUS_OK or SVC_STATUS_ERROR
123 *
124 * @COMMAND_FCS_REQUEST_SERVICE: request validation of image from firmware,
125 * return status is SVC_STATUS_OK, SVC_STATUS_INVALID_PARAM
126 *
127 * @COMMAND_FCS_SEND_CERTIFICATE: send a certificate, return status is
128 * SVC_STATUS_OK, SVC_STATUS_INVALID_PARAM, SVC_STATUS_ERROR
129 *
130 * @COMMAND_FCS_GET_PROVISION_DATA: read the provisioning data, return status is
131 * SVC_STATUS_OK, SVC_STATUS_INVALID_PARAM, SVC_STATUS_ERROR
132 *
133 * @COMMAND_FCS_DATA_ENCRYPTION: encrypt the data, return status is
134 * SVC_STATUS_OK, SVC_STATUS_INVALID_PARAM, SVC_STATUS_ERROR
135 *
136 * @COMMAND_FCS_DATA_DECRYPTION: decrypt the data, return status is
137 * SVC_STATUS_OK, SVC_STATUS_INVALID_PARAM, SVC_STATUS_ERROR
138 *
139 * @COMMAND_FCS_RANDOM_NUMBER_GEN: generate a random number, return status
140 * is SVC_STATUS_OK, SVC_STATUS_ERROR
141 */
142enum stratix10_svc_command_code {
143 /* for FPGA */
144 COMMAND_NOOP = 0,
145 COMMAND_RECONFIG,
146 COMMAND_RECONFIG_DATA_SUBMIT,
147 COMMAND_RECONFIG_DATA_CLAIM,
148 COMMAND_RECONFIG_STATUS,
149 /* for RSU */
150 COMMAND_RSU_STATUS = 10,
151 COMMAND_RSU_UPDATE,
152 COMMAND_RSU_NOTIFY,
153 COMMAND_RSU_RETRY,
154 COMMAND_RSU_MAX_RETRY,
155 COMMAND_RSU_DCMF_VERSION,
156 COMMAND_RSU_DCMF_STATUS,
157 COMMAND_FIRMWARE_VERSION,
158 /* for FCS */
159 COMMAND_FCS_REQUEST_SERVICE = 20,
160 COMMAND_FCS_SEND_CERTIFICATE,
161 COMMAND_FCS_GET_PROVISION_DATA,
162 COMMAND_FCS_DATA_ENCRYPTION,
163 COMMAND_FCS_DATA_DECRYPTION,
164 COMMAND_FCS_RANDOM_NUMBER_GEN,
165 /* for general status poll */
166 COMMAND_POLL_SERVICE_STATUS = 40,
167 /* Non-mailbox SMC Call */
168 COMMAND_SMC_SVC_VERSION = 200,
169};
170
171/**
172 * struct stratix10_svc_client_msg - message sent by client to service
173 * @payload: starting address of data need be processed
174 * @payload_length: to be processed data size in bytes
175 * @payload_output: starting address of processed data
176 * @payload_length_output: processed data size in bytes
177 * @command: service command
178 * @arg: args to be passed via registers and not physically mapped buffers
179 */
180struct stratix10_svc_client_msg {
181 void *payload;
182 size_t payload_length;
183 void *payload_output;
184 size_t payload_length_output;
185 enum stratix10_svc_command_code command;
186 u64 arg[3];
187};
188
189/**
190 * struct stratix10_svc_command_config_type - config type
191 * @flags: flag bit for the type of FPGA configuration
192 */
193struct stratix10_svc_command_config_type {
194 u32 flags;
195};
196
197/**
198 * struct stratix10_svc_cb_data - callback data structure from service layer
199 * @status: the status of sent command
200 * @kaddr1: address of 1st completed data block
201 * @kaddr2: address of 2nd completed data block
202 * @kaddr3: address of 3rd completed data block
203 */
204struct stratix10_svc_cb_data {
205 u32 status;
206 void *kaddr1;
207 void *kaddr2;
208 void *kaddr3;
209};
210
211/**
212 * struct stratix10_svc_client - service client structure
213 * @dev: the client device
214 * @receive_cb: callback to provide service client the received data
215 * @priv: client private data
216 */
217struct stratix10_svc_client {
218 struct device *dev;
219 void (*receive_cb)(struct stratix10_svc_client *client,
220 struct stratix10_svc_cb_data *cb_data);
221 void *priv;
222};
223
224/**
225 * stratix10_svc_request_channel_byname() - request service channel
226 * @client: identity of the client requesting the channel
227 * @name: supporting client name defined above
228 *
229 * Return: a pointer to channel assigned to the client on success,
230 * or ERR_PTR() on error.
231 */
232struct stratix10_svc_chan
233*stratix10_svc_request_channel_byname(struct stratix10_svc_client *client,
234 const char *name);
235
236/**
237 * stratix10_svc_free_channel() - free service channel.
238 * @chan: service channel to be freed
239 */
240void stratix10_svc_free_channel(struct stratix10_svc_chan *chan);
241
242/**
243 * stratix10_svc_allocate_memory() - allocate the momory
244 * @chan: service channel assigned to the client
245 * @size: number of bytes client requests
246 *
247 * Service layer allocates the requested number of bytes from the memory
248 * pool for the client.
249 *
250 * Return: the starting address of allocated memory on success, or
251 * ERR_PTR() on error.
252 */
253void *stratix10_svc_allocate_memory(struct stratix10_svc_chan *chan,
254 size_t size);
255
256/**
257 * stratix10_svc_free_memory() - free allocated memory
258 * @chan: service channel assigned to the client
259 * @kaddr: starting address of memory to be free back to pool
260 */
261void stratix10_svc_free_memory(struct stratix10_svc_chan *chan, void *kaddr);
262
263/**
264 * stratix10_svc_send() - send a message to the remote
265 * @chan: service channel assigned to the client
266 * @msg: message data to be sent, in the format of
267 * struct stratix10_svc_client_msg
268 *
269 * Return: 0 for success, -ENOMEM or -ENOBUFS on error.
270 */
271int stratix10_svc_send(struct stratix10_svc_chan *chan, void *msg);
272
273/**
274 * stratix10_svc_done() - complete service request
275 * @chan: service channel assigned to the client
276 *
277 * This function is used by service client to inform service layer that
278 * client's service requests are completed, or there is an error in the
279 * request process.
280 */
281void stratix10_svc_done(struct stratix10_svc_chan *chan);
282#endif
283