Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Copyright (C) 2017-2018, Intel Corporation
0004  */
0005 
0006 #ifndef __STRATIX10_SVC_CLIENT_H
0007 #define __STRATIX10_SVC_CLIENT_H
0008 
0009 /*
0010  * Service layer driver supports client names
0011  *
0012  * fpga: for FPGA configuration
0013  * rsu: for remote status update
0014  */
0015 #define SVC_CLIENT_FPGA         "fpga"
0016 #define SVC_CLIENT_RSU          "rsu"
0017 #define SVC_CLIENT_FCS          "fcs"
0018 
0019 /*
0020  * Status of the sent command, in bit number
0021  *
0022  * SVC_STATUS_OK:
0023  * Secure firmware accepts the request issued by one of service clients.
0024  *
0025  * SVC_STATUS_BUFFER_SUBMITTED:
0026  * Service client successfully submits data buffer to secure firmware.
0027  *
0028  * SVC_STATUS_BUFFER_DONE:
0029  * Secure firmware completes data process, ready to accept the
0030  * next WRITE transaction.
0031  *
0032  * SVC_STATUS_COMPLETED:
0033  * Secure firmware completes service request successfully. In case of
0034  * FPGA configuration, FPGA should be in user mode.
0035  *
0036  * SVC_COMMAND_STATUS_BUSY:
0037  * Service request is still in process.
0038  *
0039  * SVC_COMMAND_STATUS_ERROR:
0040  * Error encountered during the process of the service request.
0041  *
0042  * SVC_STATUS_NO_SUPPORT:
0043  * Secure firmware doesn't support requested features such as RSU retry
0044  * or RSU notify.
0045  */
0046 #define SVC_STATUS_OK           0
0047 #define SVC_STATUS_BUFFER_SUBMITTED 1
0048 #define SVC_STATUS_BUFFER_DONE      2
0049 #define SVC_STATUS_COMPLETED        3
0050 #define SVC_STATUS_BUSY         4
0051 #define SVC_STATUS_ERROR        5
0052 #define SVC_STATUS_NO_SUPPORT       6
0053 #define SVC_STATUS_INVALID_PARAM    7
0054 
0055 /*
0056  * Flag bit for COMMAND_RECONFIG
0057  *
0058  * COMMAND_RECONFIG_FLAG_PARTIAL:
0059  * Set to FPGA configuration type (full or partial).
0060  */
0061 #define COMMAND_RECONFIG_FLAG_PARTIAL   0
0062 
0063 /*
0064  * Timeout settings for service clients:
0065  * timeout value used in Stratix10 FPGA manager driver.
0066  * timeout value used in RSU driver
0067  */
0068 #define SVC_RECONFIG_REQUEST_TIMEOUT_MS         300
0069 #define SVC_RECONFIG_BUFFER_TIMEOUT_MS          720
0070 #define SVC_RSU_REQUEST_TIMEOUT_MS              300
0071 #define SVC_FCS_REQUEST_TIMEOUT_MS      2000
0072 #define SVC_COMPLETED_TIMEOUT_MS        30000
0073 
0074 struct stratix10_svc_chan;
0075 
0076 /**
0077  * enum stratix10_svc_command_code - supported service commands
0078  *
0079  * @COMMAND_NOOP: do 'dummy' request for integration/debug/trouble-shooting
0080  *
0081  * @COMMAND_RECONFIG: ask for FPGA configuration preparation, return status
0082  * is SVC_STATUS_OK
0083  *
0084  * @COMMAND_RECONFIG_DATA_SUBMIT: submit buffer(s) of bit-stream data for the
0085  * FPGA configuration, return status is SVC_STATUS_SUBMITTED or SVC_STATUS_ERROR
0086  *
0087  * @COMMAND_RECONFIG_DATA_CLAIM: check the status of the configuration, return
0088  * status is SVC_STATUS_COMPLETED, or SVC_STATUS_BUSY, or SVC_STATUS_ERROR
0089  *
0090  * @COMMAND_RECONFIG_STATUS: check the status of the configuration, return
0091  * status is SVC_STATUS_COMPLETED, or SVC_STATUS_BUSY, or SVC_STATUS_ERROR
0092  *
0093  * @COMMAND_RSU_STATUS: request remote system update boot log, return status
0094  * is log data or SVC_STATUS_RSU_ERROR
0095  *
0096  * @COMMAND_RSU_UPDATE: set the offset of the bitstream to boot after reboot,
0097  * return status is SVC_STATUS_OK or SVC_STATUS_ERROR
0098  *
0099  * @COMMAND_RSU_NOTIFY: report the status of hard processor system
0100  * software to firmware, return status is SVC_STATUS_OK or
0101  * SVC_STATUS_ERROR
0102  *
0103  * @COMMAND_RSU_RETRY: query firmware for the current image's retry counter,
0104  * return status is SVC_STATUS_OK or SVC_STATUS_ERROR
0105  *
0106  * @COMMAND_RSU_MAX_RETRY: query firmware for the max retry value,
0107  * return status is SVC_STATUS_OK or SVC_STATUS_ERROR
0108  *
0109  * @COMMAND_RSU_DCMF_VERSION: query firmware for the DCMF version, return status
0110  * is SVC_STATUS_OK or SVC_STATUS_ERROR
0111  *
0112  * @COMMAND_POLL_SERVICE_STATUS: poll if the service request is complete,
0113  * return statis is SVC_STATUS_OK, SVC_STATUS_ERROR or SVC_STATUS_BUSY
0114  *
0115  * @COMMAND_FIRMWARE_VERSION: query running firmware version, return status
0116  * is SVC_STATUS_OK or SVC_STATUS_ERROR
0117  *
0118  * @COMMAND_SMC_SVC_VERSION: Non-mailbox SMC SVC API Version,
0119  * return status is SVC_STATUS_OK
0120  *
0121  * @COMMAND_RSU_DCMF_STATUS: query firmware for the DCMF status
0122  * return status is SVC_STATUS_OK or SVC_STATUS_ERROR
0123  *
0124  * @COMMAND_FCS_REQUEST_SERVICE: request validation of image from firmware,
0125  * return status is SVC_STATUS_OK, SVC_STATUS_INVALID_PARAM
0126  *
0127  * @COMMAND_FCS_SEND_CERTIFICATE: send a certificate, return status is
0128  * SVC_STATUS_OK, SVC_STATUS_INVALID_PARAM, SVC_STATUS_ERROR
0129  *
0130  * @COMMAND_FCS_GET_PROVISION_DATA: read the provisioning data, return status is
0131  * SVC_STATUS_OK, SVC_STATUS_INVALID_PARAM, SVC_STATUS_ERROR
0132  *
0133  * @COMMAND_FCS_DATA_ENCRYPTION: encrypt the data, return status is
0134  * SVC_STATUS_OK, SVC_STATUS_INVALID_PARAM, SVC_STATUS_ERROR
0135  *
0136  * @COMMAND_FCS_DATA_DECRYPTION: decrypt the data, return status is
0137  * SVC_STATUS_OK, SVC_STATUS_INVALID_PARAM, SVC_STATUS_ERROR
0138  *
0139  * @COMMAND_FCS_RANDOM_NUMBER_GEN: generate a random number, return status
0140  * is SVC_STATUS_OK, SVC_STATUS_ERROR
0141  */
0142 enum stratix10_svc_command_code {
0143     /* for FPGA */
0144     COMMAND_NOOP = 0,
0145     COMMAND_RECONFIG,
0146     COMMAND_RECONFIG_DATA_SUBMIT,
0147     COMMAND_RECONFIG_DATA_CLAIM,
0148     COMMAND_RECONFIG_STATUS,
0149     /* for RSU */
0150     COMMAND_RSU_STATUS = 10,
0151     COMMAND_RSU_UPDATE,
0152     COMMAND_RSU_NOTIFY,
0153     COMMAND_RSU_RETRY,
0154     COMMAND_RSU_MAX_RETRY,
0155     COMMAND_RSU_DCMF_VERSION,
0156     COMMAND_RSU_DCMF_STATUS,
0157     COMMAND_FIRMWARE_VERSION,
0158     /* for FCS */
0159     COMMAND_FCS_REQUEST_SERVICE = 20,
0160     COMMAND_FCS_SEND_CERTIFICATE,
0161     COMMAND_FCS_GET_PROVISION_DATA,
0162     COMMAND_FCS_DATA_ENCRYPTION,
0163     COMMAND_FCS_DATA_DECRYPTION,
0164     COMMAND_FCS_RANDOM_NUMBER_GEN,
0165     /* for general status poll */
0166     COMMAND_POLL_SERVICE_STATUS = 40,
0167     /* Non-mailbox SMC Call */
0168     COMMAND_SMC_SVC_VERSION = 200,
0169 };
0170 
0171 /**
0172  * struct stratix10_svc_client_msg - message sent by client to service
0173  * @payload: starting address of data need be processed
0174  * @payload_length: to be processed data size in bytes
0175  * @payload_output: starting address of processed data
0176  * @payload_length_output: processed data size in bytes
0177  * @command: service command
0178  * @arg: args to be passed via registers and not physically mapped buffers
0179  */
0180 struct stratix10_svc_client_msg {
0181     void *payload;
0182     size_t payload_length;
0183     void *payload_output;
0184     size_t payload_length_output;
0185     enum stratix10_svc_command_code command;
0186     u64 arg[3];
0187 };
0188 
0189 /**
0190  * struct stratix10_svc_command_config_type - config type
0191  * @flags: flag bit for the type of FPGA configuration
0192  */
0193 struct stratix10_svc_command_config_type {
0194     u32 flags;
0195 };
0196 
0197 /**
0198  * struct stratix10_svc_cb_data - callback data structure from service layer
0199  * @status: the status of sent command
0200  * @kaddr1: address of 1st completed data block
0201  * @kaddr2: address of 2nd completed data block
0202  * @kaddr3: address of 3rd completed data block
0203  */
0204 struct stratix10_svc_cb_data {
0205     u32 status;
0206     void *kaddr1;
0207     void *kaddr2;
0208     void *kaddr3;
0209 };
0210 
0211 /**
0212  * struct stratix10_svc_client - service client structure
0213  * @dev: the client device
0214  * @receive_cb: callback to provide service client the received data
0215  * @priv: client private data
0216  */
0217 struct stratix10_svc_client {
0218     struct device *dev;
0219     void (*receive_cb)(struct stratix10_svc_client *client,
0220                struct stratix10_svc_cb_data *cb_data);
0221     void *priv;
0222 };
0223 
0224 /**
0225  * stratix10_svc_request_channel_byname() - request service channel
0226  * @client: identity of the client requesting the channel
0227  * @name: supporting client name defined above
0228  *
0229  * Return: a pointer to channel assigned to the client on success,
0230  * or ERR_PTR() on error.
0231  */
0232 struct stratix10_svc_chan
0233 *stratix10_svc_request_channel_byname(struct stratix10_svc_client *client,
0234     const char *name);
0235 
0236 /**
0237  * stratix10_svc_free_channel() - free service channel.
0238  * @chan: service channel to be freed
0239  */
0240 void stratix10_svc_free_channel(struct stratix10_svc_chan *chan);
0241 
0242 /**
0243  * stratix10_svc_allocate_memory() - allocate the momory
0244  * @chan: service channel assigned to the client
0245  * @size: number of bytes client requests
0246  *
0247  * Service layer allocates the requested number of bytes from the memory
0248  * pool for the client.
0249  *
0250  * Return: the starting address of allocated memory on success, or
0251  * ERR_PTR() on error.
0252  */
0253 void *stratix10_svc_allocate_memory(struct stratix10_svc_chan *chan,
0254                     size_t size);
0255 
0256 /**
0257  * stratix10_svc_free_memory() - free allocated memory
0258  * @chan: service channel assigned to the client
0259  * @kaddr: starting address of memory to be free back to pool
0260  */
0261 void stratix10_svc_free_memory(struct stratix10_svc_chan *chan, void *kaddr);
0262 
0263 /**
0264  * stratix10_svc_send() - send a message to the remote
0265  * @chan: service channel assigned to the client
0266  * @msg: message data to be sent, in the format of
0267  * struct stratix10_svc_client_msg
0268  *
0269  * Return: 0 for success, -ENOMEM or -ENOBUFS on error.
0270  */
0271 int stratix10_svc_send(struct stratix10_svc_chan *chan, void *msg);
0272 
0273 /**
0274  * stratix10_svc_done() - complete service request
0275  * @chan: service channel assigned to the client
0276  *
0277  * This function is used by service client to inform service layer that
0278  * client's service requests are completed, or there is an error in the
0279  * request process.
0280  */
0281 void stratix10_svc_done(struct stratix10_svc_chan *chan);
0282 #endif
0283