1 /*******************************************************************************
2  * Copyright 2019-2021 Microchip FPGA Embedded Systems Solutions.
3  *
4  * SPDX-License-Identifier: MIT
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22  * IN THE SOFTWARE.
23  *
24  * PolarFire SoC Microprocessor Subsystem(MSS) system services bare metal driver
25  * implementation.
26  */
27 
28 /*=========================================================================*//**
29   @mainpage PolarFire SoC MSS System services Bare Metal Driver
30 
31   ==============================================================================
32   Introduction
33   ==============================================================================
34   The PolarFire SoC system services are the services offered by the system
35   controller. These services can be requested by PolarFire SoC MSS over System
36   Controller Bus (SCB). The MSS appears as SCB master over the SCB bus. MSS can
37   communicate with system controller over SCB by write/read to the MSS SCB
38   register space. The PolarFire SoC system service driver software provides a
39   set of functions for controlling the PolarFire SoC system services as part of
40   a bare-metal system where no operating system is available. It can be adapted
41   to be used as a part of an operating system, but the implementation of the
42   adaptation layer between this driver and the operating system's driver model
43   is outside the scope of this driver.
44 
45   ==============================================================================
46   Hardware Flow Dependencies
47   ==============================================================================
48   The configuration of all the features of the PolarFire SoC MSS system services
49   is covered by this driver. Besides, this driver does not require any other
50   configuration. It relies on SCB register access interface to communicate with
51   system controller.
52   The base address and register addresses are defined in this driver as
53   constants. The interrupt number assigned are defined as constants in the MPFS
54   HAL. Ensure that the latest MPFS HAL is included in the project settings of
55   the SoftConsole toolchain and that it is generated into your project.
56 
57   ==============================================================================
58   Theory of Operation
59   ==============================================================================
60   The PolarFire SoC system services are the services offered by the system
61   controller. These services can be requested by PolarFire SoC MSS over System
62   Controller Bus (SCB). The MSS appears as SCB master over the SCB bus. MSS can
63   communicate with the system controller over SCB by accessing the MSS SCB
64   register space. Requesting a system service over the SCB bus involves a
65   command/response sequence to transfer a system service command from the MSS to
66   the system controller and to transfer status back from the system controller
67   to the MSS. The MSS SCB register space also provides access to the mailbox.
68   The mailbox is used for passing data related to the system service between the
69   MSS and system controller in both directions.
70   On completion of service, the system controller also writes a status code
71   indicating the successful completion of the system service or an error code
72   into the status register.
73 
74   These system services are grouped into the following categories:
75     -  Device and design information services
76     -  Design services
77     -  Data security services
78     -  Fabric services
79     -  MSS services
80 
81   -----------------------------------------------------------------------------
82     Device and Design Information Services
83   -----------------------------------------------------------------------------
84   The PolarFire SoC system service driver can be used to read information about
85   the device on which it is being executed and the current fabric design by
86   making a call to the following functions.
87     -  MSS_SYS_get_serial_number()
88     -  MSS_SYS_get_user_code()
89     -  MSS_SYS_get_design_info()
90     -  MSS_SYS_get_device_certificate()
91     -  MSS_SYS_read_digest()
92     -  MSS_SYS_query_security()
93     -  MSS_SYS_read_debug_info()
94     -  MSS_SYS_read_envm_param()
95 
96   -----------------------------------------------------------------------------
97   Design Services
98   -----------------------------------------------------------------------------
99   The PolarFire SoC system service driver can be used to perform bitstream
100   authentication using the following functions.
101     -  MSS_SYS_bitstream_authenticate_service()
102     -  MSS_SYS_IAP_image_authenticate_service()
103 
104   -----------------------------------------------------------------------------
105   Data Security Services
106   -----------------------------------------------------------------------------
107   The PolarFire SoC System Service driver can be used to execute data security
108   services using the following functions:
109     -  MSS_SYS_digital_signature_service ()
110     -  MSS_SYS_secure_nvm_write()
111     -  MSS_SYS_secure_nvm_read()
112     -  MSS_SYS_puf_emulation_service ()
113     -  MSS_SYS_nonce_service ()
114 
115   -----------------------------------------------------------------------------
116   Executing Fabric Services
117   -----------------------------------------------------------------------------
118   The PolarFire SoC System Service driver can be used to execute fabric services
119   using the following functions:
120     -  MSS_SYS_digest_check_service()
121     -  MSS_SYS_iap_service()
122 
123   -----------------------------------------------------------------------------
124   MSS Services
125   -----------------------------------------------------------------------------
126   The PolarFire SoC System Service driver can be used to execute MSS services
127   using following functions:
128     -  MSS_SYS_spi_copy_service()
129     -  MSS_SYS_probe_read_debug_service()
130     -  MSS_SYS_probe_write_debug_service()
131     -  MSS_SYS_live_probe_debug_service()
132     -  MSS_SYS_MEM_select_debug_service()
133     -  MSS_SYS_MEM_read_debug_service()
134     -  MSS_SYS_MEM_write_debug_service()
135     -  MSS_SYS_apb_read_service()
136     -  MSS_SYS_apb_write_debug_service()
137     -  MSS_SYS_debug_snapshot_service()
138     -  MSS_SYS_generate_otp_service()
139     -  MSS_SYS_match_otp_service()
140     -  MSS_SYS_unlock_debug_passcode_service()
141     -  MSS_SYS_one_way_passcode_service()
142     -  MSS_SYS_terminate_debug_service()
143 
144   -----------------------------------------------------------------------------
145   Mode of operation and status response
146   -----------------------------------------------------------------------------
147   The PolarFire SoC MSS system service driver can be configured to execute
148   service in interrupt mode or polling mode. User need to select the mode of
149   operation by configuring the driver with appropriate service mode macros as a
150   parameter to MSS_SYS_select_service_mode() function. For interrupt mode, the
151   calling service function exits after requesting the system service with a
152   success return value. The actual response from the system controller will only
153   be available after the interrupt occurs. Use the MSS_SYS_read_response()
154   function to read the service response and the status response code.
155   For Polling mode, the calling service function exits only after the
156   completion of the service, the return value in this case will indicate the
157   service response code received from the system controller.
158   All the service execution functions return the 16-bit status returned by
159   system controller on executing the given service. A zero value indicates the
160   successful execution of that service. A non-zero value indicates an error code
161   representing the type of error that was encountered while executing the service.
162   Irrespective of the mode, if the controller is busy executing the previous
163   service the function will exit with the MSS_SYS_BUSY return value. The error
164   codes are different for each service. See individual function descriptions to
165   know the meaning of the error code for each service.
166  */
167 
168 #ifndef MSS_SYS_SERVICES_H_
169 #define MSS_SYS_SERVICES_H_
170 
171 #include <stdint.h>
172 
173 #ifdef __cplusplus
174 extern "C" {
175 #endif
176 
177 /*--------------------------------Public constants----------------------------*/
178 
179 /*-------------------------------------------------------------------------*//**
180   System services Generic constants
181   ============================
182 
183   These constants are used to communicate the outcome of a system services
184   request. These status codes are used across all types of services. The
185   following table lists the system service driver generic constants.
186 
187   MSS_SYS_SUCCESS
188     System service executed successfully.
189 
190   MSS_SYS_BUSY
191     system controller is busy executing system service which was initiated using
192     its AMBA interface.
193 
194   MSS_SYS_PARAM_ERR
195     System service cannot be executed as one or more parameters are not as
196     expected by this driver.
197 
198 */
199 #define MSS_SYS_SUCCESS                                       0u
200 #define MSS_SYS_BUSY                                          0xEFu
201 #define MSS_SYS_PARAM_ERR                                     0xFFu
202 
203 /*-------------------------------------------------------------------------*//**
204   System service execution mode macros
205   ============================
206 
207   The following defines are used to select whether to execute services in
208   interrupt mode or polling mode.
209  */
210 
211 /* Parameter used in MSS_SYS_service_mode() function
212  * to execute the services in interrupt mode
213  */
214 #define MSS_SYS_SERVICE_INTERRUPT_MODE                          1u
215 
216 /* Parameter used in MSS_SYS_service_mode() function
217  * to execute the services in polling mode
218  */
219 #define MSS_SYS_SERVICE_POLLING_MODE                            0u
220 
221 /*-------------------------------------------------------------------------*//**
222   System service error codes
223   ============================
224 
225   The following constants list the success/error code for each system service.
226 */
227 
228 /*-------------------------------------------------------------------------*//**
229   Device Certificate Service error codes
230 
231   MSS_SYS_DCF_DEVICE_MISMATCH
232     Public key or FSN do not match device
233 
234   MSS_SYS_DCF_INVALID_SIGNATURE
235     Certificate signature is invalid
236 
237   MSS_SYS_DCF_SYSTEM_ERROR
238     PUF or storage failure
239 */
240 #define MSS_SYS_DCF_DEVICE_MISMATCH                            1u
241 #define MSS_SYS_DCF_INVALID_SIGNATURE                          2u
242 #define MSS_SYS_DCF_SYSTEM_ERROR                               3u
243 
244 /*------------------------------------------------------------------------*//**
245   Read ENVM parameters service error codes
246 
247   MSS_SYS_ENVM_DIGEST_ERROR
248   Page digest mismatches. Parameter values still returned
249    */
250 #define MSS_SYS_ENVM_DIGEST_ERROR                              1u
251 
252 /*-------------------------------------------------------------------------*//**
253   bitstream authentication and IAP bitstream authentication error codes
254 
255   BSTREAM_AUTH_CHAINING_MISMATCH_ERR
256     Validator or hash chaining mismatch. Incorrectly constructed bitstream or
257     wrong key used.
258 
259   BSTREAM_AUTH_UNEXPECTED_DATA_ERR
260     Unexpected data received.
261     Additional data received after end of EOB component
262 
263   BSTREAM_AUTH_INVALID_ENCRY_KEY_ERR
264     Invalid/corrupt encryption key.
265     The requested key mode is disabled or the key could not be read/reconstructed
266 
267   BSTREAM_AUTH_INVALID_HEADER_ERR
268     Invalid component header
269 
270   BSTREAM_AUTH_BACK_LEVEL_NOT_SATISFIED_ERR
271     Back level not satisfied
272 
273   BSTREAM_AUTH_ILLEGAL_BITSTREAM_MODE_ERR
274     Illegal bitstream mode.
275     Requested bitstream mode is disabled by user security
276 
277   BSTREAM_AUTH_DNS_BINDING_MISMATCH_ERR
278     DSN binding mismatch
279 
280   BSTREAM_AUTH_ILLEGAL_COMPONENT_SEQUENCE_ERR
281     Illegal component sequence
282 
283   BSTREAM_AUTH_INSUFF_DEVICE_CAPAB_ERR
284     Insufficient device capabilities
285 
286   BSTREAM_AUTH_INCORRECT_DEVICEID_ERR
287     Incorrect DEVICEID
288 
289   BSTREAM_AUTH_PROTOCOL_VERSION_ERR
290     Unsupported bitstream protocol version (regeneration required)
291 
292   BSTREAM_AUTH_VERIFY_ERR
293     Verify not permitted on this bitstream
294 
295   BSTREAM_AUTH_INVALID_DEV_CERT_ERR
296     Invalid Device Certificate.
297     Device SCAC is invalid or not present
298 
299   BSTREAM_AUTH_INVALID_DIB_ERR
300     Invalid DIB
301 
302   BSTREAM_AUTH_SPI_NOT_MASTER_ERR
303     Device not in SPI Master Mode.
304     Error may occur only when bitstream is executed through IAP mode
305 
306   BSTREAM_AUTH_AUTOIAP_NO_VALID_IMAGE_ERR
307     No valid images found.
308     Error may occur when bitstream is executed through Auto Update mode.
309     Occurs when No valid image pointers are found.
310 
311   BSTREAM_AUTH_INDEXIAP_NO_VALID_IMAGE_ERR
312     No valid images found.
313     Error may occur when bitstream is executed through IAP mode via Index Mode.
314     Occurs when No valid image pointers are found.
315 
316   BSTREAM_AUTH_NEWER_DESIGN_VERSION_ERR
317     Programmed design version is newer than AutoUpdate image found.
318     Error may occur when bitstream is executed through Auto Update mode
319 
320   BSTREAM_AUTH_INVALID_IMAGE_ERR
321     Selected image was invalid and no recovery was performed due to valid design
322     in device.
323     Error may occur only when bitstream is executed through Auto Update or IAP
324     mode (This error is here for completeness but only can be observed by
325     running the READ_DEBUG_INFO instruction and looking at IAP Error code field)
326 
327   BSTREAM_AUTH_IMAGE_PROGRAM_FAILED_ERR
328     Selected and Recovery image failed to program.
329     Error may occur only when bitstream is executed through Auto Update or
330     IAP mode
331     (This error is here for completeness but only can be observed by running the
332     READ_DEBUG_INFO instruction and looking at IAP Error code field)
333 
334   BSTREAM_AUTH_ABORT_ERR
335     Abort.
336     Non-bitstream instruction executed during bitstream loading.
337 
338   BSTREAM_AUTH_NVMVERIFY_ERR
339     Fabric/UFS verification failed (min or weak limit)
340 
341   BSTREAM_AUTH_PROTECTED_ERR
342     Device security prevented modification of non-volatile memory
343 
344   BSTREAM_AUTH_NOTENA
345     Programming mode not enabled
346 
347   BSTREAM_AUTH_PNVMVERIFY
348     pNVM verify operation failed
349 
350   BSTREAM_AUTH_SYSTEM
351     System hardware error (PUF or DRBG)
352 
353   BSTREAM_AUTH_BADCOMPONENT
354     An internal error was detected in a component payload
355 
356   BSTREAM_AUTH_HVPROGERR
357     HV programming subsystem failure (pump failure)
358 
359   BSTREAM_AUTH_HVSTATE
360     HV programming subsystem in unexpected state (internal error)
361   */
362 #define MSS_SYS_BSTREAM_AUTH_CHAINING_MISMATCH_ERR                1u
363 #define MSS_SYS_BSTREAM_AUTH_UNEXPECTED_DATA_ERR                  2u
364 #define MSS_SYS_BSTREAM_AUTH_INVALID_ENCRY_KEY_ERR                3u
365 #define MSS_SYS_BSTREAM_AUTH_INVALID_HEADER_ERR                   4u
366 #define MSS_SYS_BSTREAM_AUTH_BACK_LEVEL_NOT_SATISFIED_ERR         5u
367 #define MSS_SYS_BSTREAM_AUTH_ILLEGAL_BITSTREAM_MODE_ERR           6u
368 #define MSS_SYS_BSTREAM_AUTH_DNS_BINDING_MISMATCH_ERR             7u
369 #define MSS_SYS_BSTREAM_AUTH_ILLEGAL_COMPONENT_SEQUENCE_ERR       8u
370 #define MSS_SYS_BSTREAM_AUTH_INSUFF_DEVICE_CAPAB_ERR              9u
371 #define MSS_SYS_BSTREAM_AUTH_INCORRECT_DEVICEID_ERR               10u
372 #define MSS_SYS_BSTREAM_AUTH_PROTOCOL_VERSION_ERR                 11u
373 #define MSS_SYS_BSTREAM_AUTH_VERIFY_ERR                           12u
374 #define MSS_SYS_BSTREAM_AUTH_INVALID_DEV_CERT_ERR                 13u
375 #define MSS_SYS_BSTREAM_AUTH_INVALID_DIB_ERR                      14u
376 #define MSS_SYS_BSTREAM_AUTH_SPI_NOT_MASTER_ERR                   21u
377 #define MSS_SYS_BSTREAM_AUTH_AUTOIAP_NO_VALID_IMAGE_ERR           22u
378 #define MSS_SYS_BSTREAM_AUTH_INDEXIAP_NO_VALID_IMAGE_ERR          23u
379 #define MSS_SYS_BSTREAM_AUTH_NEWER_DESIGN_VERSION_ERR             24u
380 /*25            Reserved*/
381 #define MSS_SYS_BSTREAM_AUTH_INVALID_IMAGE_ERR                    26u
382 #define MSS_SYS_BSTREAM_AUTH_IMAGE_PROGRAM_FAILED_ERR             27u
383 #define MSS_SYS_BSTREAM_AUTH_ABORT_ERR                            127u
384 #define MSS_SYS_BSTREAM_AUTH_NVMVERIFY_ERR                        128u
385 #define MSS_SYS_BSTREAM_AUTH_PROTECTED_ERR                        129u
386 #define MSS_SYS_BSTREAM_AUTH_NOTENA                               130u
387 #define MSS_SYS_BSTREAM_AUTH_PNVMVERIFY                           131u
388 #define MSS_SYS_BSTREAM_AUTH_SYSTEM                               132u
389 #define MSS_SYS_BSTREAM_AUTH_BADCOMPONENT                         133u
390 #define MSS_SYS_BSTREAM_AUTH_HVPROGERR                            134u
391 #define MSS_SYS_BSTREAM_AUTH_HVSTATE                              135u
392 
393 /*-------------------------------------------------------------------------*//**
394  Digital Signature Service error code
395 
396   DIGITAL_SIGNATURE_FEK_FAILURE_ERROR
397     Error retrieving FEK
398 
399   DIGITAL_SIGNATURE_DRBG_ERROR
400     Failed to generate nonce
401 
402   DIGITAL_SIGNATURE_ECDSA_ERROR
403     ECDSA failed
404 */
405 #define MSS_SYS_DIGITAL_SIGNATURE_FEK_FAILURE_ERROR             0x01u
406 #define MSS_SYS_DIGITAL_SIGNATURE_DRBG_ERROR                    0x02u
407 #define MSS_SYS_DIGITAL_SIGNATURE_ECDSA_ERROR                   0x03u
408 
409 /*-------------------------------------------------------------------------*//**
410   Secure NVM write error codes
411 
412   SNVM_WRITE_INVALID_SNVMADDR
413     Illegal page address
414 
415   SNVM_WRITE_FAILURE
416     PNVM program/verify failed
417 
418   SNVM_WRITE_SYSTEM_ERROR
419     PUF or storage failure
420 
421   SNVM_WRITE_NOT_PERMITTED
422     Write is not permitted
423 */
424 #define MSS_SYS_SNVM_WRITE_INVALID_SNVMADDR                     1u
425 #define MSS_SYS_SNVM_WRITE_FAILURE                              2u
426 #define MSS_SYS_SNVM_WRITE_SYSTEM_ERROR                         3u
427 #define MSS_SYS_SNVM_WRITE_NOT_PERMITTED                        4u
428 
429 /*-------------------------------------------------------------------------*//**
430   Secure NVM read error codes
431 
432   SNVM_READ_INVALID_SNVMADDR
433     Illegal page address
434 
435   SNVM_READ_AUTHENTICATION_FAILURE
436     Storage corrupt or incorrect USK
437 
438   SNVM_READ_SYSTEM_ERROR
439     PUF or storage failure
440 */
441 #define MSS_SYS_SNVM_READ_INVALID_SNVMADDR                      1u
442 #define MSS_SYS_SNVM_READ_AUTHENTICATION_FAILURE                2u
443 #define MSS_SYS_SNVM_READ_SYSTEM_ERROR                          3u
444 
445 /*-------------------------------------------------------------------------*//**
446    PUF emulation service error codes
447 
448     MSS_SYS_PUF_EMU_INTERNAL_ERR
449        Internal error
450  */
451 #define MSS_SYS_PUF_EMU_INTERNAL_ERR                            1u
452 
453 /*-------------------------------------------------------------------------*//**
454   Nonce Service Error Codes
455 
456   MSS_SYS_NONCE_PUK_FETCH_ERROR
457     Error fetching PUK
458 
459   MSS_SYS_NONCE_SEED_GEN_ERROR
460     Error generating seed
461 */
462 #define MSS_SYS_NONCE_PUK_FETCH_ERROR                          1u
463 #define MSS_SYS_NONCE_SEED_GEN_ERROR                           2u
464 
465 /*-------------------------------------------------------------------------*//**
466   Digest Check service error code
467 
468   MSS_SYS_DIGEST_CHECK_DIGESTERR
469     Digest mismatch occurred
470 */
471 #define MSS_SYS_DIGEST_CHECK_DIGESTERR                            1u
472 
473 /*-------------------------------------------------------------------------*//**
474   SPI COPY SERVICE error codes
475 
476   MSS_SYS_SPI_MASTER_MODE_ERR
477     Device is not configured for master mode
478 
479   MSS_SYS_SPI_AXI_ERR
480     AXI error
481 */
482 #define MSS_SYS_SPI_MASTER_MODE_ERR                               1u
483 #define MSS_SYS_SPI_AXI_ERR                                       2u
484 
485 /*-------------------------------------------------------------------------*//**
486   Probe services error codes
487 
488   MSS_SYS_PROBE_SECERR
489   The operation was blocked by device security.  This will occur if the
490   permanent debug lock UP_DEBUG is set or the user software debug lock
491   SWL_DEBUG is active or the device is in the virgin state. No data is read
492   and PRDATA is invalid.
493  */
494 #define MSS_SYS_PROBE_SECERR                                      1u
495 
496 /*-------------------------------------------------------------------------*//**
497   MEM Services error codes
498 
499   MSS_SYS_MEM_SECERR
500   The operation was blocked by device security.
501   This will occur if the permanent debug lock UP_DEBUG is set or the user
502   software debug lock SWL_DEBUG is active or the device is in the virgin state.
503 
504   MSS_SYS_MEM_TIMEOUTERR
505   Timeout occurred.
506 
507   MSS_SYS_MEM_LOCKERR
508   Target memory failed to lock
509 */
510 #define MSS_SYS_MEM_SECERR                                        1u
511 #define MSS_SYS_MEM_TIMEOUTERR                                    2u
512 #define MSS_SYS_MEM_LOCKERR                                       3u
513 
514 /*-------------------------------------------------------------------------*//**
515   APB services error codes
516 
517   MSS_SYS_APB_SECERR
518   The operation was blocked by device security.
519   This will occur if the permanent debug lock UP_DEBUG is set or the user
520   software debug lock SWL_DEBUG is active or the device is in the virgin state.
521 
522   MSS_SYS_APB_SLVERR
523   The addressed fabric APB peripheral generated a SLVERR response to the bus
524   transaction.
525 
526   MSS_SYS_APB_TIMEOUT
527   The addressed fabric APB peripheral failed to respond before the user-defined
528   APB timeout or the fabric power is not on.
529 */
530 #define MSS_SYS_APB_SECERR                                        1u
531 #define MSS_SYS_APB_SLVERR                                        2u
532 #define MSS_SYS_APB_TIMEOUT                                       3u
533 
534 /*-------------------------------------------------------------------------*//**
535   Debug snapshot service error codes
536 
537    MSS_SYS_DEBUG_SNAPSHOT_SECERR
538    The operation was blocked by device security.
539    This will occur if the permanent debug lock UP_DEBUG is set or the user
540    software debug lock SWL_DEBUG is active or the device is in the virgin state.
541 
542    MSS_SYS_DEBUG_SNAPSHOT_BUSERR
543    A bus error occurred and the snapshot was aborted.  This may occur if:
544        •   the fabric power is off, or
545        •   the fabric APB slave flagged an error, or
546        •   the fabric APB slave was too slow to assert PREADY
547 */
548 #define MSS_SYS_DEBUG_SNAPSHOT_SECERR                             1u
549 #define MSS_SYS_DEBUG_SNAPSHOT_BUSERR                             2u
550 
551 /*-------------------------------------------------------------------------*//**
552   GENERATE OTP SERVICE
553 
554   MSS_SYS_SECERR
555   Operation is blocked by device security
556 
557   MSS_SYS_PROTOCOLERR
558   Invalid key provided
559 */
560 #define MSS_SYS_GENERATE_OTP_SECERR                               1u
561 #define MSS_SYS_GENERATE_OTP_PROTOCOLERR                          2u
562 
563 /*-------------------------------------------------------------------------*//**
564   MATCH OTP SERVICE
565 
566   MSS_SYS_PROTOCOLERR
567   Keymode not supported.
568 
569   MSS_SYS_MATCH_OTP_MISMATCHERR
570   Calculated validator mismatch.
571 */
572 #define MSS_SYS_MATCH_OTP_PROTOCOLERR                             1u
573 #define MSS_SYS_MATCH_OTP_MISMATCHERR                             2u
574 
575 /*-------------------------------------------------------------------------*//**
576   Unlock debug passcode service error codes
577 
578   MSS_SYS_UNLOCK_DEBUG_PASSCODE_SECERR
579   The operation was blocked by device security.
580   Occurs if the lock UL_PLAINTEXT is active or the permanent lock UP_DPK is set.
581 
582   MSS_SYS_UNLOCK_DEBUG_PASSCODE_ERR
583   If the unlock operation fails for any reason then the tamper event
584   PASSCODE_FAIL is generated and all unlocked passcodes are re-locked.
585 */
586 #define MSS_SYS_UNLOCK_DEBUG_PASSCODE_SECERR                     1u
587 #define MSS_SYS_UNLOCK_DEBUG_PASSCODE_ERR                        2u
588 
589 /*-------------------------------------------------------------------------*//**
590   One way passcode service error codes
591 
592   MSS_SYS_OWP_OWPERR
593   If the unlock operation fails for any reason then the tamper event
594   PASSCODE_FAIL is generated and all unlocked passcodes are re-locked.
595 */
596 #define MSS_SYS_OWP_OWPERR                                       1u
597 
598 /*-------------------------------------------------------------------------*//**
599   System service response data length
600   ============================
601 
602   The following constants can be used to indicate the length of the data that
603   is written into the mailbox by the system controller in response to the
604   service being requested.
605 
606   MSS_SYS_NO_RESPONSE_LEN
607     This constant is used to indicate that system controller does not return any
608     mailbox data for the service which is being requested
609 
610   MSS_SYS_SERIAL_NUMBER_RESP_LEN
611     Response length serial number service
612 
613   MSS_SYS_USERCODE_RESP_LEN
614     Response length for Usercode service
615 
616   MSS_SYS_DESIGN_INFO_RESP_LEN
617     Response length for Design info service
618 
619   MSS_SYS_DEVICE_CERTIFICATE_RESP_LEN
620     Response length for Device certificate service
621 
622   MSS_SYS_READ_DIGEST_RESP_LEN
623     Response length Read digest service
624 
625   MSS_SYS_QUERY_SECURITY_RESP_LEN
626     Response length Query security service
627 
628   MSS_SYS_READ_DEBUG_INFO_RESP_LEN
629     Response length Read debug info service
630 
631   MSS_SYS_NONCE_SERVICE_RESP_LEN
632     Response length Nonce service
633 
634   MSS_SYS_READ_ENVM_PARAM_RESP_LEN
635     Response length Read eNVM parameters service
636 
637   MSS_SYS_PROBE_READ_SERVICE_RESP_LEN
638     Response length Probe read service
639 
640   MSS_SYS_GENERATE_OTP_RESP_LEN
641     Response length Generate OTP service
642 
643   MSS_SYS_PUF_EMULATION_SERVICE_RESP_LEN
644     Response length PUF emulation service
645 
646   MSS_SYS_DIGITAL_SIGNATURE_RAW_FORMAT_RESP_SIZE
647     Response length for digital signature service raw format
648 
649   MSS_SYS_DIGITAL_SIGNATURE_DER_FORMAT_RESP_SIZE
650     Response length for digital signature service DER format
651 */
652 #define MSS_SYS_NO_RESPONSE_LEN                                 0u
653 #define MSS_SYS_SERIAL_NUMBER_RESP_LEN                          16u
654 #define MSS_SYS_USERCODE_RESP_LEN                               4u
655 #define MSS_SYS_DESIGN_INFO_RESP_LEN                            36u
656 #define MSS_SYS_DEVICE_CERTIFICATE_RESP_LEN                     1024u
657 #define MSS_SYS_READ_DIGEST_RESP_LEN                            544u
658 #define MSS_SYS_QUERY_SECURITY_RESP_LEN                         33u
659 #define MSS_SYS_READ_DEBUG_INFO_RESP_LEN                        94u
660 #define MSS_SYS_NONCE_SERVICE_RESP_LEN                          32u
661 #define MSS_SYS_READ_ENVM_PARAM_RESP_LEN                        256u
662 #define MSS_SYS_PUF_EMULATION_SERVICE_RESP_LEN                  32u
663 #define MSS_SYS_DIGEST_CHECK_SERVICE_RESP_LEN                   4u
664 #define MSS_SYS_DIGITAL_SIGNATURE_RAW_FORMAT_RESP_SIZE          96u
665 #define MSS_SYS_DIGITAL_SIGNATURE_DER_FORMAT_RESP_SIZE          104u
666 #define MSS_SYS_USER_SECRET_KEY_LEN                             12u
667 #define MSS_SYS_PROBE_READ_SERVICE_RESP_LEN                     4u
668 #define MSS_SYS_GENERATE_OTP_RESP_LEN                           16u
669 
670 /*-------------------------Private constants--------------------------------*/
671 
672 /*-------------------------------------------------------------------------*//**
673   Service request command opcodes
674   ============================
675 
676   The following constants can be used as parameter value of the functions to
677   indicate the system service command opcode.
678  */
679 
680 /*-------------------------------------------------------------------------*//**
681   Device and design information services request command opcodes
682  */
683 #define MSS_SYS_SERIAL_NUMBER_REQUEST_CMD                       0x00u
684 #define MSS_SYS_USERCODE_REQUEST_CMD                            0x01u
685 #define MSS_SYS_DESIGN_INFO_REQUEST_CMD                         0x02u
686 #define MSS_SYS_DEVICE_CERTIFICATE_REQUEST_CMD                  0x03u
687 #define MSS_SYS_READ_DIGEST_REQUEST_CMD                         0x04u
688 #define MSS_SYS_QUERY_SECURITY_REQUEST_CMD                      0x05u
689 #define MSS_SYS_READ_DEBUG_INFO_REQUEST_CMD                     0x06u
690 #define MSS_SYS_READ_ENVM_PARAM_REQUEST_CMD                     0x07u
691 
692 /*-------------------------------------------------------------------------*//**
693   Design services request command opcodes
694 */
695 #define MSS_SYS_BITSTREAM_AUTHENTICATE_CMD                      0x23u
696 #define MSS_SYS_IAP_BITSTREAM_AUTHENTICATE_CMD                  0x22u
697 
698 /*-------------------------------------------------------------------------*//**
699   Data security services request command opcodes
700 */
701 #define MSS_SYS_DIGITAL_SIGNATURE_RAW_FORMAT_REQUEST_CMD        0x19u
702 #define MSS_SYS_DIGITAL_SIGNATURE_DER_FORMAT_REQUEST_CMD        0x1Au
703 #define MSS_SYS_SNVM_NON_AUTHEN_TEXT_REQUEST_CMD                0x10u
704 #define MSS_SYS_SNVM_AUTHEN_TEXT_REQUEST_CMD                    0x11u
705 #define MSS_SYS_SNVM_AUTHEN_CIPHERTEXT_REQUEST_CMD              0x12u
706 #define MSS_SYS_SNVM_READ_REQUEST_CMD                           0x18u
707 #define MSS_SYS_PUF_EMULATION_SERVICE_REQUEST_CMD               0x20u
708 #define MSS_SYS_NONCE_SERVICE_REQUEST_CMD                       0x21u
709 
710 /*-------------------------------------------------------------------------*//**
711   Fabric services request command opcodes
712 */
713 #define MSS_SYS_DIGEST_CHECK_CMD                                0x47u
714 #define MSS_SYS_IAP_PROGRAM_BY_SPIIDX_CMD                       0x42u
715 #define MSS_SYS_IAP_VERIFY_BY_SPIIDX_CMD                        0x44u
716 #define MSS_SYS_IAP_PROGRAM_BY_SPIADDR_CMD                      0x43u
717 #define MSS_SYS_IAP_VERIFY_BY_SPIADDR_CMD                       0x45u
718 #define MSS_SYS_IAP_AUTOUPDATE_CMD                              0x46u
719 
720 /*-------------------------------------------------------------------------*//**
721   MSS services request command opcodes
722 */
723 #define MSS_SYS_SPI_COPY_CMD                                    0X50U
724 #define MSS_SYS_PROBE_READ_DEBUG_CMD                            0X70U
725 #define MSS_SYS_PROBE_WRITE_DEBUG_CMD                           0X71U
726 #define MSS_SYS_LIVE_PROBE_A_DEBUG_CMD                          0X72U
727 #define MSS_SYS_LIVE_PROBE_B_DEBUG_CMD                          0X73U
728 #define MSS_SYS_MEM_SELECT_DEBUG_CMD                            0X74U
729 #define MSS_SYS_MEM_READ_DEBUG_CMD                              0X75U
730 #define MSS_SYS_MEM_WRITE_DEBUG_CMD                             0X76U
731 #define MSS_SYS_APB_READ_DEBUG_CMD                              0X77U
732 #define MSS_SYS_APB_WRITE_DEBUG_CMD                             0X78U
733 #define MSS_SYS_DEBUG_SNAPSHOT_CMD                              0X79U
734 #define MSS_SYS_GENERATE_OTP_CMD                                0X7AU
735 #define MSS_SYS_MATCH_OTP_CMD                                   0X7BU
736 #define MSS_SYS_UNLOCK_DEBUG_PASSCODE                           0X7CU
737 #define MSS_SYS_ONE_WAY_PASSCODE_CMD                            0X7DU
738 #define MSS_SYS_TERMINATE_DEBUG_CMD                             0X7EU
739 
740 /*-------------------------------------------------------------------------*//**
741   System service mailbox data length
742   ============================
743 
744   The following constants are used to specify the mailbox data length of each
745   service for the service that is being requested.
746 */
747 
748 /* This constant is used for the services where no mailbox input data is
749  * required
750  */
751 #define MSS_SYS_WITHOUT_CMD_DATA                                0u
752 
753 #define MSS_SYS_PUF_EMULATION_SERVICE_CMD_LEN                   20u
754 #define MSS_SYS_DIGITAL_SIGNATURE_HASH_DATA_LEN                 48u
755 
756 /*SNVMADDR + RESERVED + PT*/
757 #define MSS_SYS_AUTHENTICATED_TEXT_DATA_LEN                     252u
758 
759 /*SNVMADDR + RESERVED + PT + USK*/
760 #define MSS_SYS_NON_AUTHENTICATED_TEXT_DATA_LEN                 256u
761 
762 #define MSS_SYS_SECURE_NVM_READ_DATA_LEN                        16u
763 #define MSS_SYS_BITSTREAM_AUTHENTICATE_DATA_LEN                 4u
764 #define MSS_SYS_DIGEST_CHECK_DATA_LEN                           4u
765 #define MSS_SYS_IAP_SERVICE_DATA_LEN                            4u
766 #define MSS_SYS_SPI_COPY_MAILBOX_DATA_LEN                       17u
767 #define MSS_SYS_PROBE_READ_SERVICE_DATA_LEN                     2u
768 #define MSS_SYS_PROBE_WRITE_SERVICE_DATA_LEN                    11u
769 #define MSS_SYS_LIVE_PROBE_DEBUG_SERVICE_DATA_LEN               6u
770 #define MSS_SYS_MEM_SELECT_DATA_LEN                             6u
771 #define MSS_SYS_MEM_READ_WRITE_DATA_LEN                         12u
772 #define MSS_SYS_APB_SERVICE_DATA_LEN                            24u
773 #define MSS_SYS_DEBUG_SNAPSHOT_DATA_LEN                         5u
774 #define MSS_SYS_GENERATE_OTP_DATA_LEN                           20u
775 #define MSS_SYS_MATCH_OTP_DATA_LEN                              80u
776 #define MSS_SYS_UNLOCK_DEBUG_PASSCODE_DATA_LEN                  32u
777 #define MSS_SYS_ONE_WAY_PASSCODE_DATA_LEN                       480u
778 
779 /*-------------------------------------------------------------------------*//**
780   System Services mailbox data constants
781   ============================
782  */
783 
784 /* KEY MODE for Generate OTP service
785   KM_USER_KEY1      USER Key 1
786   KM_USER_KEY2      USER Key 2
787   KM_FACTORY_KEY    FK Diversified by UID
788  */
789 #define MSS_SYS_KM_USER_KEY1                                    3u
790 #define MSS_SYS_KM_USER_KEY2                                    4u
791 #define MSS_SYS_KM_FACTORY_KEY                                  7u
792 
793 /*Digest Check Input options
794   DIGEST_CHECK_FABRIC
795     Carry out digest check on Fabric
796 
797   DIGEST_CHECK_CC
798     Carry out digest check on UFS Fabric Configuration (CC) segment
799 
800   DIGEST_CHECK_SNVM
801     Carry out digest check on ROM digest in SNVM segment
802 
803   DIGEST_CHECK_UL
804     Carry out digest check on UFS UL segment
805 
806   DIGEST_CHECK_UKDIGEST0
807     Carry out digest check on UKDIGEST0 in User Key segment
808 
809   DIGEST_CHECK_UKDIGEST1
810     Carry out digest check on UKDIGEST1 in User Key segment
811 
812   DIGEST_CHECK_UKDIGEST2
813     Carry out digest check on UKDIGEST2 in User Key segment (UPK1)
814 
815   DIGEST_CHECK_UKDIGEST3
816     Carry out digest check on UKDIGEST3 in User Key segment (UK1)
817 
818   DIGEST_CHECK_UKDIGEST4
819     Carry out digest check on UKDIGEST4 in User Key segment (DPK)
820 
821   DIGEST_CHECK_UKDIGEST5
822     Carry out digest check on UKDIGEST5 in User Key segment (UPK2)
823 
824   DIGEST_CHECK_UKDIGEST6
825     Carry out digest check on UKDIGEST6 in User Key segment (UK2)
826 
827   DIGEST_CHECK_UPERM
828     Carry out digest check on UFS Permanent lock (UPERM) segment
829 
830   DIGEST_CHECK_SYS
831     Carry out digest check on Factory and Factory Key Segments.
832 */
833 #define MSS_SYS_DIGEST_CHECK_FABRIC                           (0x01<<0x00u)
834 #define MSS_SYS_DIGEST_CHECK_CC                               (0x01<<0x01u)
835 #define MSS_SYS_DIGEST_CHECK_SNVM                             (0x01<<0x02u)
836 #define MSS_SYS_DIGEST_CHECK_UL                               (0x01<<0x03u)
837 #define MSS_SYS_DIGEST_CHECK_UKDIGEST0                        (0x01<<0x04u)
838 #define MSS_SYS_DIGEST_CHECK_UKDIGEST1                        (0x01<<0x05u)
839 #define MSS_SYS_DIGEST_CHECK_UKDIGEST2                        (0x01<<0x06u)
840 #define MSS_SYS_DIGEST_CHECK_UKDIGEST3                        (0x01<<0x07u)
841 #define MSS_SYS_DIGEST_CHECK_UKDIGEST4                        (0x01<<0x08u)
842 #define MSS_SYS_DIGEST_CHECK_UKDIGEST5                        (0x01<<0x09u)
843 #define MSS_SYS_DIGEST_CHECK_UKDIGEST6                        (0x01<<0x0au)
844 #define MSS_SYS_DIGEST_CHECK_UPERM                            (0x01<<0x0bu)
845 #define MSS_SYS_DIGEST_CHECK_SYS                              (0x01<<0x0cu)
846 #define MSS_SYS_DIGEST_CHECK_UKDIGEST7                        (0x01<<0x0du)
847 #define MSS_SYS_DIGEST_CHECK_ENVM                             (0x01<<0x0eu)
848 #define MSS_SYS_DIGEST_CHECK_UKDIGEST8                        (0x01<<0x0fu)
849 #define MSS_SYS_DIGEST_CHECK_UKDIGEST9                        (0x01<<0x10u)
850 #define MSS_SYS_DIGEST_CHECK_UKDIGEST10                       (0x01<<0x11u)
851 
852 /*-------------------------------------------------------------------------*//**
853   Mailbox ECC status
854   Provides ECC status when the mailbox is read. The values are as follows:
855     00: No ECC errors detected, data is correct.
856     01: Exactly one bit erred and has been corrected.
857     10: Exactly two bits erred, no correction performed.
858     11: Reserved.
859 */
860 #define MSS_SYS_MBOX_ECC_NO_ERROR_MASK                         0x00u
861 #define MSS_SYS_MBOX_ONEBIT_ERROR_CORRECTED_MASK               0x40u
862 #define MSS_SYS_MBOX_TWOBIT_ERROR_MASK                         0xC0u
863 
864 /*-------------------------------------------------------------------------*//**
865  * Options for system services
866 */
867 /*   Permitted key modes for one way Pass-code service
868  *   *NS -- Not Supported
869  */
870 #define KM_INIT_FACTORY                                         0x00u/*NS*/
871 #define KM_ZERO_RECOVERY                                        0x01u/*NS*/
872 #define KM_DEFAULT_KEY                                          0x02u
873 #define KM_USER_KEY1                                            0x03u
874 #define KM_USER_KEY2                                            0x04u
875 #define KM_AUTH_CODE                                            0x06u/*NS*/
876 #define KM_FACTORY_KEY                                          0x07u
877 #define KM_FACTORY_EC                                           0x08u/*NS*/
878 #define KM_FACTORY_EC_E                                         0x09u/*NS*/
879 #define KM_USER_EC                                              0x12u/*NS*/
880 #define KM_USER_EC_E                                            0x13u/*NS*/
881 
882 /*-------------------------------------------------------------------------*//**
883   Callback function handler
884   The callback handler is used by the application to indicate the user about
885   the event of interrupt when the driver is configured to execute the system
886   services in interrupt mode.
887   The callback function handler is is registered to the MSS system service
888   driver through the call to MSS_SYS_select_service_mode() function.
889   The actual name of callback function handler is not important. User can select
890   any name.
891  */
892 typedef void (*mss_sys_service_handler_t)(void);
893 
894 /*-------------------------------------------------------------------------*//**
895   The function MSS_SYS_read_response() is used to read the response after
896   execution of system service in interrupt mode only. For polling mode call to
897   MSS_SYS_read_response is not required, as the drive performs the response
898   read operation.
899   @param
900          This function does not have any parameters.
901   @return
902          This function returns the status code returned by the system controller
903          for requested service.
904 
905   Example:
906   @code
907        status = MSS_SYS_read_response();
908 
909   @endcode
910  */
911 uint16_t
912 MSS_SYS_read_response
913 (
914     void
915 );
916 
917 /*-------------------------------------------------------------------------*//**
918   The MSS_SYS_service_mode() function is for user to configure system service
919   execution in polling mode or interrupt mode. This function also registers the
920   callback handler to the driver which will be called when message interrupt
921   occurs.
922 
923   @param sys_service_mode
924                     User can decide whether to execute the service in polling
925                     mode or interrupt mode.
926                     Example:
927                             MSS_SYS_SERVICE_INTERRUPT_MODE
928                             MSS_SYS_SERVICE_POLLING_MODE
929 
930   @param mss_sys_service_interrupt_handler
931                     Callback function to the application. This function is
932                     invoked when message interrupt occurs.
933 
934   @return
935         This function does not return any value.
936 
937   Example:
938   @code
939        MSS_SYS_service_mode(MSS_SYS_SERVICE_POLLING_MODE,
940                             mss_sys_service_interrupt_handler);
941   @endcode
942 */
943 void
944 MSS_SYS_select_service_mode
945 (
946     uint8_t sys_service_mode,
947     mss_sys_service_handler_t mss_sys_service_interrupt_handler
948 );
949 
950 /*-------------------------------------------------------------------------*//**
951   The MSS_SYS_get_serial_number() function fetches the 128-bit Device Serial
952   Number (DSN). This function is non-blocking in the interrupt mode , in that,
953   it will exit immediately after requesting the service. In polling mode, it
954   becomes a blocking function. It will block until the the service is completed
955   and a response is received from the system controller.
956   This function is non-blocking in the interrupt mode , in that, it will exit
957   immediately after requesting the service. In polling mode, it becomes a
958   blocking function. It will block until the the service is completed and a
959   response is received from the system controller.
960 
961   @param p_serial_number
962                     The p_serial_number parameter is a pointer to a buffer
963                     in which the data returned by system controller will be
964                     copied.
965 
966   @param mb_offset
967                     The mb_offset parameter specifies the offset from the start
968                     of mailbox where the data related to this service is
969                     available. All accesses to the mailbox are of word length
970                     (4 bytes). A value 10 (decimal) of this parameter would
971                     mean that the data access area for this service, in the
972                     mailbox starts from 11th word (offset 10).
973   @return
974                     This function returns the status code returned by the
975                     system controller for this service. A '0' status code means
976                     that the service was executed successfully.
977 
978                       | STATUS | Description    | Note                        |
979                       |--------|----------------|-----------------------------|
980                       | 0      | Success        |                             |
981                       | 1      | Error          | DSN could not be read       |
982 */
983 uint16_t
984 MSS_SYS_get_serial_number
985 (
986     uint8_t * p_serial_number,
987     uint16_t mb_offset
988 );
989 
990 /*-------------------------------------------------------------------------*//**
991   The function MSS_SYS_get_user_code() is used to execute "USERCODE" system
992   service.
993   This function is non-blocking in the interrupt mode , in that, it will exit
994   immediately after requesting the service. In polling mode, it becomes a
995   blocking function. It will block until the the service is completed and a
996   response is received from the system controller.
997 
998   @param p_user_code
999                     The p_user_code parameter is a pointer to a buffer
1000                     in which the data returned by system controller will be
1001                     copied.
1002   @param mb_offset
1003                     The mb_offset parameter specifies the offset from the start
1004                     of mailbox where the data related to this service is
1005                     available. All accesses to the mailbox are of word length
1006                     (4 bytes). A value 10 (decimal) of this parameter would
1007                     mean that the data access area for this service, in the
1008                     mailbox starts from 11th word (offset 10).
1009   @return
1010                     This function returns a value to indicate whether the
1011                     service was executed successfully or not. A zero value
1012                     indicates that the service was executed successfully. A
1013                     non-zero value can indicate that either the driver was not
1014                     able to kick-start the service or that the driver was able
1015                     to kick-start the service and receive a status response code
1016                     from the system controller.
1017                     See theory of operations section for detailed information
1018                     about the return status.
1019                     The following table lists the service status code from
1020                     system controller.
1021 
1022                     | STATUS | Description Note |
1023                     |--------|------------------|
1024                     |     0  | Success          |
1025 */
1026 uint16_t
1027 MSS_SYS_get_user_code
1028 (
1029     uint8_t * p_user_code,
1030     uint16_t mb_offset
1031 );
1032 
1033 /*-------------------------------------------------------------------------*//**
1034   The function MSS_SYS_get_design_info() is used to execute "Get Design Info"
1035   system service.
1036   This function is non-blocking in the interrupt mode , in that, it will exit
1037   immediately after requesting the service. In polling mode, it becomes a
1038   blocking function. It will block until the the service is completed and a
1039   response is received from the system controller.
1040 
1041   @param p_design_info   The p_design_info parameter is a pointer to a buffer
1042                          in which the data returned by system controller will be
1043                          copied. Total size of debug information is 76 bytes.
1044                          Below listed fields in the 76 bytes information are
1045                          "reserved bytes". They do not represent meaningful
1046                          information and can be ignored.
1047                             From offset 3 (size 1)
1048                             From offset 18 (size 1)
1049                             From offset 37 (size 4)
1050                             From offset 42 (size 2)
1051                             From offset 50 (size 2)
1052                             From offset 65 (size 7)
1053   @param mb_offset
1054                     The mb_offset parameter specifies the offset from the start
1055                     of mailbox where the data related to this service is
1056                     available. All accesses to the mailbox are of word length
1057                     (4 bytes). A value 10 (decimal) of this parameter would
1058                     mean that the data access area for this service, in the
1059                     mailbox starts from 11th word (offset 10).
1060   @return
1061                     This function returns a value to indicate whether the
1062                     service was executed successfully or not. A zero value
1063                     indicates that the service was executed successfully. A
1064                     non-zero value can indicate that either the driver was not
1065                     able to kick-start the service or that the driver was able
1066                     to kick-start the service and receive a status response code
1067                     from the system controller.
1068                     See theory of operations section for detailed information
1069                     about the return status.
1070                     The following table lists the service status code from
1071                     system controller.
1072 
1073                        | STATUS | Description Note |
1074                        |--------|------------------|
1075                        |     0  | Success          |
1076 
1077 */
1078 uint16_t
1079 MSS_SYS_get_design_info
1080 (
1081     uint8_t * p_design_info,
1082     uint16_t mb_offset
1083 );
1084 
1085 /*-------------------------------------------------------------------------*//**
1086   The function MSS_SYS_get_device_certificate() is used to execute "Get Device
1087   Certificate" system service.
1088 
1089   @param p_device_certificate The p_device_certificate parameter is a pointer
1090                               to a buffer in which the data returned by the
1091                               system controller will be copied.
1092   @param mb_offset
1093                     The mb_offset parameter specifies the offset from the start
1094                     of mailbox where the data related to this service is
1095                     available. All accesses to the mailbox are of word length
1096                     (4 bytes). A value 10 (decimal) of this parameter would
1097                     mean that the data access area for this service, in the
1098                     mailbox starts from 11th word (offset 10).
1099   @return
1100                     This function returns a value to indicate whether the
1101                     service was executed successfully or not. A zero value
1102                     indicates that the service was executed successfully. A
1103                     non-zero value can indicate that either the driver was not
1104                     able to kick-start the service or that the driver was able
1105                     to kick-start the service and receive a status response code
1106                     from the system controller.
1107                     See theory of operations section for detailed information
1108                     about the return status.
1109                     The following table lists the service status code from
1110                     system controller.
1111 
1112      |STATUS    | Description       |  Note
1113      |----------|-------------------|------------------------------------------
1114      |   0      | Success           |Certificate is valid & consistent with
1115      |          |                   |device
1116      |   1      | Signature invalid |Certificate signature is invalid
1117      |   2      | Device mismatch   |Public key or FSN do not match device
1118      |   3      | System error      |PUF or storage failure
1119 */
1120 uint16_t
1121 MSS_SYS_get_device_certificate
1122 (
1123     uint8_t * p_device_certificate,
1124     uint16_t mb_offset
1125 );
1126 
1127 /*-------------------------------------------------------------------------*//**
1128   The function MSS_SYS_read_digest() is used to execute "Read Digest" system
1129   service.
1130   This function is non-blocking in the interrupt mode , in that, it will exit
1131   immediately after requesting the service. In polling mode, it becomes a
1132   blocking function. It will block until the the service is completed and a
1133   response is received from the system controller.
1134 
1135   @param p_digest      The p_digest parameter is a pointer to a buffer
1136                        in which the data returned by system controller will be
1137                        copied.
1138   @param mb_offset
1139                     The mb_offset parameter specifies the offset from the start
1140                     of mailbox where the data related to this service is
1141                     available. All accesses to the mailbox are of word length
1142                     (4 bytes). A value 10 (decimal) of this parameter would
1143                     mean that the data access area for this service, in the
1144                     mailbox starts from 11th word (offset 10).
1145   @return
1146                     This function returns a value to indicate whether the
1147                     service was executed successfully or not. A zero value
1148                     indicates that the service was executed successfully. A
1149                     non-zero value can indicate that either the driver was not
1150                     able to kick-start the service or that the driver was able
1151                     to kick-start the service and receive a status response code
1152                     from the system controller.
1153                     See theory of operations section for detailed information
1154                     about the return status.
1155                     The following table lists the service status code from
1156                     system controller.
1157 
1158                        | STATUS | Description Note |
1159                        |--------|------------------|
1160                        |     0  | Success          |
1161 */
1162 uint16_t
1163 MSS_SYS_read_digest
1164 (
1165    uint8_t * p_digest,
1166    uint16_t mb_offset
1167 );
1168 
1169 /*-------------------------------------------------------------------------*//**
1170   The function MSS_SYS_query_security() is used to execute "Query Security"
1171   system service.
1172   This function is non-blocking in the interrupt mode , in that, it will exit
1173   immediately after requesting the service. In polling mode, it becomes a
1174   blocking function. It will block until the the service is completed and a
1175   response is received from the system controller.
1176 
1177   @param p_security_locks The p_security_locks parameter is a pointer to a buffer
1178                           in which the data returned by system controller will be
1179                           copied.
1180   @param mb_offset
1181                     The mb_offset parameter specifies the offset from the start
1182                     of mailbox where the data related to this service is
1183                     available. All accesses to the mailbox are of word length
1184                     (4 bytes). A value 10 (decimal) of this parameter would
1185                     mean that the data access area for this service, in the
1186                     mailbox starts from 11th word (offset 10).
1187   @return
1188                     This function returns a value to indicate whether the
1189                     service was executed successfully or not. A zero value
1190                     indicates that the service was executed successfully. A
1191                     non-zero value can indicate that either the driver was not
1192                     able to kick-start the service or that the driver was able
1193                     to kick-start the service and receive a status response code
1194                     from the system controller.
1195                     See theory of operations section for detailed information
1196                     about the return status.
1197                     The following table lists the service status code from
1198                     system controller.
1199 
1200                        | STATUS | Description Note |
1201                        |--------|------------------|
1202                        |     0  | Success          |
1203 */
1204 uint16_t
1205 MSS_SYS_query_security
1206 (
1207     uint8_t * p_security_locks,
1208     uint16_t mb_offset
1209 );
1210 
1211 /*-------------------------------------------------------------------------*//**
1212   The function MSS_SYS_read_debug_info() is used to execute "Read Debug info"
1213   system service.
1214   This function is non-blocking in the interrupt mode , in that, it will exit
1215   immediately after requesting the service. In polling mode, it becomes a
1216   blocking function. It will block until the the service is completed and a
1217   response is received from the system controller.
1218 
1219   @param p_debug_info  The p_debug_info parameter is a pointer to a buffer
1220                        in which the data returned by system controller will be
1221                        copied.
1222   @param mb_offset
1223                     The mb_offset parameter specifies the offset from the start
1224                     of mailbox where the data related to this service is
1225                     available. All accesses to the mailbox are of word length
1226                     (4 bytes). A value 10 (decimal) of this parameter would
1227                     mean that the data access area for this service, in the
1228                     mailbox starts from 11th word (offset 10).
1229   @return
1230                     This function returns a value to indicate whether the
1231                     service was executed successfully or not. A zero value
1232                     indicates that the service was executed successfully. A
1233                     non-zero value can indicate that either the driver was not
1234                     able to kick-start the service or that the driver was able
1235                     to kick-start the service and receive a status response code
1236                     from the system controller.
1237                     See theory of operations section for detailed information
1238                     about the return status.
1239                     The following table lists the service status code from
1240                     system controller.
1241 
1242                        | STATUS | Description Note |
1243                        |--------|------------------|
1244                        |     0  | Success          |
1245 */
1246 uint16_t
1247 MSS_SYS_read_debug_info
1248 (
1249     uint8_t * p_debug_info,
1250     uint16_t mb_offset
1251 );
1252 
1253 /*-------------------------------------------------------------------------*//**
1254   The function MSS_SYS_read_envm_parameter() is used to retrieve all parameters
1255   needed for eNVM operation and programming.
1256   This function is non-blocking in the interrupt mode , in that, it will exit
1257   immediately after requesting the service. In polling mode, it becomes a
1258   blocking function. It will block until the the service is completed and a
1259   response is received from the system controller.
1260 
1261   @param p_envm_param
1262                     The p_envm_param parameter specifies the the user buffer
1263                     which will be accumulated with envm parameters after the
1264                     service completes execution.
1265   @param mb_offset
1266                     The mb_offset parameter specifies the offset from the start
1267                     of mailbox where the data related to this service is
1268                     available. All accesses to the mailbox are of word length
1269                     (4 bytes). A value 10 (decimal) of this parameter would
1270                     mean that the data access area for this service, in the
1271                     mailbox starts from 11th word (offset 10).
1272   @return
1273                     This function returns a value to indicate whether the
1274                     service was executed successfully or not. A zero value
1275                     indicates that the service was executed successfully. A
1276                     non-zero value can indicate that either the driver was not
1277                     able to kick-start the service or that the driver was able
1278                     to kick-start the service and receive a status response code
1279                     from the system controller.
1280                     See theory of operations section for detailed information
1281                     about the return status.
1282                     The following table lists the service status code from
1283                     system controller.
1284 
1285                     |STATUS  | Description    |  Note                          |
1286                     |--------|----------------|--------------------------------|
1287                     |   0    |   Success      |                                |
1288                     |   1    |   Digest Error |Page digest mismatches.         |
1289                     |        |                |Parameter values still returned.|
1290 */
1291 uint16_t
1292 MSS_SYS_read_envm_parameter
1293 (
1294     uint8_t * p_envm_param,
1295     uint16_t mb_offset
1296 );
1297 
1298 /*-------------------------------------------------------------------------*//**
1299   The MSS_SYS_authenticate_bitstream() function is used to authenticate
1300   the Bitstream which is located in SPI through a system service routine. Prior
1301   to using the IAP service, it may be required to first validate the new
1302   bitstream before committing the device to reprogramming, thus avoiding the
1303   need to invoke recovery procedures if the bitstream is invalid.
1304 
1305   This service is applicable to bitstreams stored in SPI Flash memory only.
1306   This function is non-blocking in the interrupt mode , in that, it will exit
1307   immediately after requesting the service. In polling mode, it becomes a
1308   blocking function. It will block until the the service is completed and a
1309   response is received from the system controller.
1310 
1311   @param spi_flash_address
1312                     The spi_flash_address parameter specifies the address within
1313                     SPI Flash memory where the bit-stream is stored.
1314   @param mb_offset
1315                     The mb_offset parameter specifies the offset from the start
1316                     of mailbox where the data related to this service is
1317                     available. All accesses to the mailbox are of word length
1318                     (4 bytes). A value 10 (decimal) of this parameter would
1319                     mean that the data access area for this service, in the
1320                     mailbox starts from 11th word (offset 10).
1321   @return
1322                     This function returns a value to indicate whether the
1323                     service was executed successfully or not. A zero value
1324                     indicates that the service was executed successfully. A
1325                     non-zero value can indicate that either the driver was not
1326                     able to kick-start the service or that the driver was able
1327                     to kick-start the service and receive a status response code
1328                     from the system controller.
1329                     See theory of operations section for detailed information
1330                     about the return status.
1331                     The following table lists the service status code from
1332                     system controller.
1333 
1334                     | STATUS   |     Description                               |
1335                     |----------|-----------------------------------------------|
1336                     |   0      |  No error                                     |
1337                     |   1      |  Validator or hash chaining mismatch          |
1338                     |   2      |  Unexpected data received                     |
1339                     |   3      |  Invalid/corrupt encryption key               |
1340                     |   4      |  Invalid component header                     |
1341                     |   5      |  Back level not satisfied                     |
1342                     |   6      |  Illegal bitstream mode                       |
1343                     |   7      |  DSN binding mismatch                         |
1344                     |   8      |  Illegal component sequence                   |
1345                     |   9      |  Insufficient device capabilities             |
1346                     |   10     |  Incorrect DEVICEID                           |
1347                     |   11     |  Unsupported bitstream protocol version       |
1348                     |          |  (regeneration required)                      |
1349                     |   12     |  Verify not permitted on this bitstream       |
1350                     |   13     |  Invalid Device Certificate                   |
1351                     |   14     |  Invalid DIB                                  |
1352                     |   21     |  Device not in SPI Master Mode                |
1353                     |   22     |  No valid images found                        |
1354                     |   23     |  No valid images found                        |
1355                     |   24     |  Programmed design version is newer than Auto |
1356                     |          |  Update image found                           |
1357                     |   25     |  Reserved                                     |
1358                     |   26     |  Selected image was invalid and no recovery   |
1359                     |          |  was performed due to valid design in device  |
1360                     |   27     |  Selected and Recovery image failed to program|
1361                     |   127    |  Abort                                        |
1362                     |   128    |  NVMVERIFY                                    |
1363                     |   129    |  PROTECTED                                    |
1364                     |   130    |  NOTENA                                       |
1365                     |   131    |  PNVMVERIFY                                   |
1366                     |   132    |  SYSTEM                                       |
1367                     |   133    |  BADCOMPONENT                                 |
1368                     |   134    |  HVPROGERR                                    |
1369                     |   135    |  HVSTATE                                      |
1370 */
1371 uint16_t
1372 MSS_SYS_authenticate_bitstream
1373 (
1374     uint32_t spi_flash_address,
1375     uint16_t mb_offset
1376 );
1377 
1378 /*-------------------------------------------------------------------------*//**
1379   The MSS_SYS_authenticate_iap_image() function is used to authenticate
1380   the IAP image which is located in SPI through a system service routine. The
1381   service checks the image descriptor and the referenced bitstream and optional
1382   initialization data.  If the image is authenticated successfully, then the
1383   image is guaranteed to be valid when used by an IAP function.
1384 
1385   This service is applicable to bitstreams stored in SPI Flash memory only.
1386   This function is non-blocking in the interrupt mode , in that, it will exit
1387   immediately after requesting the service. In polling mode, it becomes a
1388   blocking function. It will block until the the service is completed and a
1389   response is received from the system controller.
1390 
1391   @param spi_idx
1392                     The spi_idx parameter specifies the index in the SPI directory to
1393                     be used where the IAP bit-stream is stored.
1394 
1395                     Note: To support recovery SPI_IDX=1 should be an empty slot
1396                     and the recovery image should be located in SPI_IDX=0. Since
1397                     SPI_IDX=1 should be an empty slot it shouldn’t be passed into
1398                     the system service.
1399   @return
1400                    The MSS_SYS_authenticate_iap_image function returns
1401                    one of following status codes. The status code indicates
1402                    the success/failure status of the service execution.
1403 
1404                     | STATUS   |     Description                               |
1405                     |----------|-----------------------------------------------|
1406                     |   0      |  No error                                     |
1407                     |   1      |  Validator or hash chaining mismatch          |
1408                     |   2      |  Unexpected data received                     |
1409                     |   3      |  Invalid/corrupt encryption key               |
1410                     |   4      |  Invalid component header                     |
1411                     |   5      |  Back level not satisfied                     |
1412                     |   6      |  Illegal bitstream mode                       |
1413                     |   7      |  DSN binding mismatch                         |
1414                     |   8      |  Illegal component sequence                   |
1415                     |   9      |  Insufficient device capabilities             |
1416                     |   10     |  Incorrect DEVICEID                           |
1417                     |   11     |  Unsupported bitstream protocol version       |
1418                     |          |  (regeneration required)                      |
1419                     |   12     |  Verify not permitted on this bitstream       |
1420                     |   13     |  Invalid Device Certificate                   |
1421                     |   14     |  Invalid DIB                                  |
1422                     |   21     |  Device not in SPI Master Mode                |
1423                     |   22     |  No valid images found                        |
1424                     |   23     |  No valid images found                        |
1425                     |   24     |  Programmed design version is newer than Auto |
1426                     |          |  Update image found                           |
1427                     |   25     |  Reserved                                     |
1428                     |   26     |  Selected image was invalid and no recovery   |
1429                     |          |  was performed due to valid design in device  |
1430                     |   27     |  Selected and Recovery image failed to program|
1431                     |   127    |  Abort                                        |
1432                     |   128    |  NVMVERIFY                                    |
1433                     |   129    |  PROTECTED                                    |
1434                     |   130    |  NOTENA                                       |
1435                     |   131    |  PNVMVERIFY                                   |
1436                     |   132    |  SYSTEM                                       |
1437                     |   133    |  BADCOMPONENT                                 |
1438                     |   134    |  HVPROGERR                                    |
1439                     |   135    |  HVSTATE                                      |
1440 */
1441 uint16_t
1442 MSS_SYS_authenticate_iap_image
1443 (
1444     uint32_t spi_idx
1445 );
1446 
1447 /*-------------------------------------------------------------------------*//**
1448   The MSS_SYS_puf_emulation_service() function accept a challenge comprising a
1449   8-bit optype and 128-bit challenge and return a 256-bit response unique to
1450   the given challenge and the device.
1451   This function is non-blocking in the interrupt mode , in that, it will exit
1452   immediately after requesting the service. In polling mode, it becomes a
1453   blocking function. It will block until the the service is completed and a
1454   response is received from the system controller.
1455 
1456   @param p_challenge
1457                     The p_challenge parameter specifies the 128-bit challenge
1458                     to be used to generate the unique 256-bits unique
1459                     response.
1460   @param op_type
1461                     The op_type parameter specifies the operational parameter
1462                     to be used to generate the unique 256-bits unique
1463                     response.
1464   @param p_response
1465                     The p_response parameter is a pointer to a buffer in
1466                     which the data returned i.e. response by system controller
1467                     will be copied.
1468   @param mb_offset
1469                     The mb_offset parameter specifies the offset from the start
1470                     of mailbox where the data related to this service is
1471                     available. All accesses to the mailbox are of word length
1472                     (4 bytes). A value 10 (decimal) of this parameter would
1473                     mean that the data access area for this service, in the
1474                     mailbox starts from 11th word (offset 10).
1475   @return
1476                     This function returns a value to indicate whether the
1477                     service was executed successfully or not. A zero value
1478                     indicates that the service was executed successfully. A
1479                     non-zero value can indicate that either the driver was not
1480                     able to kick-start the service or that the driver was able
1481                     to kick-start the service and receive a status response code
1482                     from the system controller.
1483                     See theory of operations section for detailed information
1484                     about the return status.
1485                     The following table lists the service status code from
1486                     system controller.
1487 
1488                     |STATUS  | Description
1489                     |--------|-----------------|
1490                     |   0    |   SUCCESS       |
1491                     |   1    |   INTERNAL ERROR|
1492                     |        |                 |
1493 */
1494 uint16_t
1495 MSS_SYS_puf_emulation_service
1496 (
1497     uint8_t * p_challenge,
1498     uint8_t op_type,
1499     uint8_t* p_response,
1500     uint16_t mb_offset
1501 );
1502 
1503 /*-------------------------------------------------------------------------*//**
1504   The MSS_SYS_digital_signature_service() function is used to generate P-384
1505   ECDSA signature based on SHA384 hash value.
1506   This function is non-blocking in the interrupt mode , in that, it will exit
1507   immediately after requesting the service. In polling mode, it becomes a
1508   blocking function. It will block until the the service is completed and a
1509   response is received from the system controller.
1510 
1511   @param p_hash
1512                     The p_hash parameter is a pointer to the buffer which
1513                     contain the 48 bytes SH384 Hash value(input value).
1514   @param format
1515                     The format parameter specifies the output format of
1516                     generated SIGNATURE field. The different types of output
1517                     signature formats are as follow:
1518                      - DIGITAL_SIGNATURE_RAW_FORMAT
1519                      - DIGITAL_SIGNATURE_DER_FORMAT
1520   @param p_response
1521                     The p_response parameter is a pointer to a buffer which
1522                     contain the generated ECDSA signature. The field may be
1523                     96 bytes or 104 bytes depend upon the output format.
1524   @param mb_offset
1525                     The mb_offset parameter specifies the offset from the start
1526                     of mailbox where the data related to this service is
1527                     available. All accesses to the mailbox are of word length
1528                     (4 bytes). A value 10 (decimal) of this parameter would
1529                     mean that the data access area for this service, in the
1530                     mailbox starts from 11th word (offset 10).
1531   @return
1532                     This function returns a value to indicate whether the
1533                     service was executed successfully or not. A zero value
1534                     indicates that the service was executed successfully. A
1535                     non-zero value can indicate that either the driver was not
1536                     able to kick-start the service or that the driver was able
1537                     to kick-start the service and receive a status response code
1538                     from the system controller.
1539                     See theory of operations section for detailed information
1540                     about the return status.
1541                     The following table lists the service status code from
1542                     system controller.
1543 
1544                     |STATUS | Description                          |
1545                     |-------|--------------------------------------|
1546                     |  0    | Success                              |
1547                     |  1    | FEK Failure Error retrieving FEK     |
1548                     |  2    | DRBG Error  Failed to generate nonce |
1549                     |  3    | ECDSA Error ECDSA failed             |
1550 
1551 */
1552 uint16_t
1553 MSS_SYS_digital_signature_service
1554 (
1555     uint8_t* p_hash,
1556     uint8_t format,
1557     uint8_t* p_response,
1558     uint16_t mb_offset
1559 );
1560 
1561 /*-------------------------------------------------------------------------*//**
1562   The MSS_SYS_secure_nvm_write() function is used to provide write access/write the
1563   data in the sNVM region. Data can be stored in the following format:
1564    -  Non-authenticated plaintext,
1565    -  Authenticated plaintext
1566    -  Authenticated ciphertext
1567   This function is non-blocking in the interrupt mode , in that, it will exit
1568   immediately after requesting the service. In polling mode, it becomes a
1569   blocking function. It will block until the the service is completed and a
1570   response is received from the system controller.
1571 
1572   @param format
1573                     The format parameter specifies the format used to write
1574                     data in sNVM region. The different type of text formats
1575                     are as follow:
1576                      - NON_AUTHENTICATED_PLAINTEXT_FORMAT
1577                      - AUTHENTICATED_PLAINTEXT_FORMAT
1578                      - AUTHENTICATED_CIPHERTEXT_FORMAT
1579   @param snvm_module
1580                     The snvm_module parameter specifies the the sNVM module
1581                     in which the data need to be written.
1582   @param p_data
1583                     The p_data parameter is a pointer to a buffer which
1584                     contains the data to be stored in sNVM region. The data length
1585                     to be written is if fixed depending on the format parameter.
1586                     If NON_AUTHENTICATED_PLAINTEXT_FORMAT is selected then you
1587                     can write 252 bytes in the sNVM module. For other two formats
1588                     the data length is 236 bytes.
1589   @param p_user_key
1590                     The p_user_key parameter is a pointer to a buffer which
1591                     contain the 96-bit key USK (user secret key). This user
1592                     secret key will enhance the security when authentication
1593                     is used.(i.e. When Authenticated plaintext and
1594                     Authenticated ciphertext format is selected).
1595   @param mb_offset
1596                     The mb_offset parameter specifies the offset from the start
1597                     of mailbox where the data related to this service is
1598                     available. All accesses to the mailbox are of word length
1599                     (4 bytes). A value 10 (decimal) of this parameter would
1600                     mean that the data access area for this service, in the
1601                     mailbox starts from 11th word (offset 10).
1602   @return
1603                     This function returns a value to indicate whether the
1604                     service was executed successfully or not. A zero value
1605                     indicates that the service was executed successfully. A
1606                     non-zero value can indicate that either the driver was not
1607                     able to kick-start the service or that the driver was able
1608                     to kick-start the service and receive a status response code
1609                     from the system controller.
1610                     See theory of operations section for detailed information
1611                     about the return status.
1612                     The following table lists the service status code from
1613                     system controller.
1614 
1615                     | STATUS | Description Note                                |
1616                     |--------|-------------------------------------------------|
1617                     |   0    |  Success                                        |
1618                     |   1    |  Invalid SNVMADDR    Illegal page address       |
1619                     |   2    |  Write failure   PNVM program/verify failed     |
1620                     |   3    |  System error    PUF or storage failure         |
1621                     |   4    |  Write Not Permitted ROMFLAG is set             |
1622                     |   5    |  Access failure  Write Access from either Fabric|
1623                     |        |  or MSS was blocked (PolarFire SoC only)        |
1624 */
1625 uint16_t
1626 MSS_SYS_secure_nvm_write
1627 (
1628     uint8_t format,
1629     uint8_t snvm_module,
1630     uint8_t* p_data,
1631     uint8_t* p_user_key,
1632     uint16_t mb_offset
1633 );
1634 
1635 /*-------------------------------------------------------------------------*//**
1636   The MSS_SYS_secure_nvm_read() function is used to read data present in sNVM
1637   region. User should provide USK key, if the data was programmed using
1638   authentication.
1639   This function is non-blocking in the interrupt mode , in that, it will exit
1640   immediately after requesting the service. In polling mode, it becomes a
1641   blocking function. It will block until the the service is completed and a
1642   response is received from the system controller.
1643 
1644   @param snvm_module
1645                     The snvm_module parameter specifies the sNVM module
1646                     from which the data need to be read.
1647   @param p_user_key
1648                     The p_user_key parameter is a pointer to a buffer which
1649                     contain the 96-bit key USK (user secret key). User should
1650                     provide same secret key which is previously used for
1651                     authentication while writing data in sNVM region.
1652   @param p_admin
1653                     The p_admin parameter is a pointer to the buffer where
1654                     the output page admin data will be stored. The page admin
1655                     data is 4 bytes long.
1656   @param p_data
1657                     The p_data parameter is a pointer to a buffer which
1658                     contains the data read from sNVM region. User should
1659                     provide the buffer large enough to store the read data.
1660   @param data_len
1661                     The data_len parameter specifies the number of bytes to be
1662                     read from sNVM.
1663                     The application should know whether the data written in the
1664                     chose sNVM module was previously stored using Authentication
1665                     or not.
1666                     The data_len should be 236 bytes, for authenticated data,
1667                     for not authenticated data the data_len should be 252 bytes.
1668   @param mb_offset
1669                     The mb_offset parameter specifies the offset from the start
1670                     of mailbox where the data related to this service is
1671                     available. All accesses to the mailbox are of word length
1672                     (4 bytes). A value 10 (decimal) of this parameter would
1673                     mean that the data access area for this service, in the
1674                     mailbox starts from 11th word (offset 10).
1675   @return
1676                     This function returns a value to indicate whether the
1677                     service was executed successfully or not. A zero value
1678                     indicates that the service was executed successfully. A
1679                     non-zero value can indicate that either the driver was not
1680                     able to kick-start the service or that the driver was able
1681                     to kick-start the service and receive a status response code
1682                     from the system controller.
1683                     See theory of operations section for detailed information
1684                     about the return status.
1685                     The following table lists the service status code from
1686                     system controller.
1687 
1688                     | STATUS | Description Note                                |
1689                     |--------|-------------------------------------------------|
1690                     |   0    |  Success                                        |
1691                     |   1    |  Invalid SNVMADDR    Illegal page address       |
1692                     |   2    |  Write failure   PNVM program/verify failed     |
1693                     |   3    |  System error    PUF or storage failure         |
1694                     |   4    |  Write Not Permitted ROMFLAG is set             |
1695                     |   5    |  Access failure  Write Access from either Fabric|
1696                     |        |  or MSS was blocked (PolarFire SoC only)        |
1697 */
1698 uint16_t
1699 MSS_SYS_secure_nvm_read
1700 (
1701     uint8_t snvm_module,
1702     uint8_t* p_user_key,
1703     uint8_t* p_admin,
1704     uint8_t* p_data,
1705     uint16_t data_len,
1706     uint16_t mb_offset
1707 );
1708 
1709 /*-------------------------------------------------------------------------*//**
1710   The function MSS_SYS_nonce_service() is used to issue "Nonce Service" system
1711   service to the system controller.
1712 
1713   @param p_nonce
1714                     The p_nonce parameter is a pointer to a buffer
1715                     in which the data returned by system controller will be
1716                     copied.
1717   @param mb_offset
1718                     The mb_offset parameter specifies the offset from the start
1719                     of mailbox where the data related to this service is
1720                     available. All accesses to the mailbox are of word length
1721                     (4 bytes). A value 10 (decimal) of this parameter would
1722                     mean that the data access area for this service, in the
1723                     mailbox starts from 11th word (offset 10).
1724   @return           This function returns the status code returned by the
1725                     system controller for this service. A '0' status code means
1726                     that the service was executed successfully.
1727 
1728                    | STATUS     | Description                              |
1729                    |------------|------------------------------------------|
1730                    |  0         |  Success completion (exit)               |
1731                    |  1         |  Error fetching PUK                      |
1732                    |  2         |  Error generating seed                   |
1733 */
1734 uint16_t
1735 MSS_SYS_nonce_service
1736 (
1737     uint8_t * p_nonce,
1738     uint16_t mb_offset
1739 );
1740 
1741 /*-------------------------------------------------------------------------*//**
1742   The MSS_SYS_digest_check() function is used to Recalculates and compares
1743   digests of selected non-volatile memories.
1744 
1745   This service is applicable to bitstream stored in SPI Flash memory only.
1746   This function is non-blocking in the interrupt mode , in that, it will exit
1747   immediately after requesting the service. In polling mode, it becomes a
1748   blocking function. It will block until the the service is completed and a
1749   response is received from the system controller.
1750 
1751   @param options
1752                The options parameter specifies the digest check options which
1753                indicate the area on which the digest check should be performed.
1754                Below is the list of options. You can OR these options to indicate
1755                to perform digest check on multiple segments.
1756 
1757                   | Options[i]  |    Description                              |
1758                   |-------------|---------------------------------------------|
1759                   |   0x01      |   Fabric digest                             |
1760                   |   0x02      |   Fabric Configuration (CC) segment         |
1761                   |   0x04      |   ROM digest in SNVM segment                |
1762                   |   0x08      |   UL segment                                |
1763                   |   0x10      |   UKDIGEST0 in User Key segment             |
1764                   |   0x20      |   UKDIGEST1 in User Key segment             |
1765                   |   0x40      |   UKDIGEST2 in User Key segment (UPK1)      |
1766                   |   0x80      |   UKDIGEST3 in User Key segment (UK1)       |
1767                   |   0x100     |   UKDIGEST4 in User Key segment (DPK)       |
1768                   |   0x200     |   UKDIGEST5 in User Key segment (UPK2)      |
1769                   |   0x400     |   UKDIGEST6 in User Key segment (UK2)       |
1770                   |   0x800     |   UFS Permanent lock (UPERM) segment        |
1771                   |   0x1000    |   Factory and Factory Key Segments.         |
1772                   |   0x2000    |   UKDIGEST7 in User Key segment (HWM)       |
1773                   |   0x4000    |   ENVMDIGEST                                |
1774                   |   0x8000    |   UKDIGEST8 for MSS Boot Info               |
1775                   |   0x10000   |   SNVM_RW_ACCESS_MAP Digest                 |
1776                   |   0x20000   |   SBIC revocation digest                    |
1777 
1778   @param mb_offset
1779                     The mb_offset parameter specifies the offset from the start
1780                     of mailbox where the data related to this service is
1781                     available. All accesses to the mailbox are of word length
1782                     (4 bytes). A value 10 (decimal) of this parameter would
1783                     mean that the data access area for this service, in the
1784                     mailbox starts from 11th word (offset 10).
1785   @param digesterr
1786                     The digesterr parameter specifies the set bit in case of
1787                     DIGESTERR.
1788 
1789                   | DIGESTERR[i]|    Description                              |
1790                   |-------------|---------------------------------------------|
1791                   |   0x01      |   Fabric digest                             |
1792                   |   0x02      |   Fabric Configuration (CC) segment         |
1793                   |   0x04      |   ROM digest in SNVM segment                |
1794                   |   0x08      |   UL segment                                |
1795                   |   0x10      |   UKDIGEST0 in User Key segment             |
1796                   |   0x20      |   UKDIGEST1 in User Key segment             |
1797                   |   0x40      |   UKDIGEST2 in User Key segment (UPK1)      |
1798                   |   0x80      |   UKDIGEST3 in User Key segment (UK1)       |
1799                   |   0x100     |   UKDIGEST4 in User Key segment (DPK)       |
1800                   |   0x200     |   UKDIGEST5 in User Key segment (UPK2)      |
1801                   |   0x400     |   UKDIGEST6 in User Key segment (UK2)       |
1802                   |   0x800     |   UFS Permanent lock (UPERM) segment        |
1803                   |   0x1000    |   Factory and Factory Key Segments.         |
1804                   |   0x2000    |   UKDIGEST7 in User Key segment (HWM)       |
1805                   |   0x4000    |   ENVMDIGEST                                |
1806                   |   0x8000    |   UKDIGEST8 for MSS Boot Info               |
1807                   |   0x10000   |   SNVM_RW_ACCESS_MAP Digest                 |
1808                   |   0x20000   |   SBIC revocation digest                    |
1809   @return
1810                     This function returns a value to indicate whether the
1811                     service was executed successfully or not. A zero value
1812                     indicates that the service was executed successfully. A
1813                     non-zero value can indicate that either the driver was not
1814                     able to kick-start the service or that the driver was able
1815                     to kick-start the service and receive a status response code
1816                     from the system controller.
1817                     See theory of operations section for detailed information
1818                     about the return status.
1819                     The following table lists the service status code from
1820                     system controller.
1821 
1822                 | STATUS DIGESTERR[i] | Description                            |
1823                 |---------------------|----------------------------------------|
1824                 |      1 or 0         |1 is returned if any of DIGESTERR bits  |
1825                 |                     |are set                                 |
1826 */
1827 uint16_t
1828 MSS_SYS_digest_check
1829 (
1830     uint32_t options,
1831     uint8_t* digesterr,
1832     uint16_t mb_offset
1833 );
1834 
1835 /*-------------------------------------------------------------------------*//**
1836   The MSS_SYS_execute_iap() function is used to IAP service. The IAP service
1837   allows the user to reprogram the device without the need for an external
1838   master. The user design writes the bitstream to be programmed into a SPI Flash
1839   connected to the SPI port.  When the service is invoked, the System Controller
1840   automatically reads the bitstream from the SPI flash and programs the device.
1841   The service allows the image to be executed in either VERIFY or PROGRAM modes.
1842   Another option for IAP is to perform the auto-update sequence. In this case
1843   the newest image of the first two images in the SPI directory is chosen to be
1844   programmed.
1845   This function is non-blocking in the interrupt mode , in that, it will exit
1846   immediately after requesting the service. In polling mode, it becomes a
1847   blocking function. It will block until the the service is completed and a
1848   response is received from the system controller.
1849 
1850   @param iap_cmd
1851                The iap_cmd parameter specifies the specific IAP command which
1852                depends upon VERIFY or PROGRAM modes and the SPI address method.
1853 
1854                    iap_cmd                 Description
1855              IAP_PROGRAM_BY_SPIIDX_CMD     IAP program.
1856              IAP_VERIFY_BY_SPIIDX_CMD      Fabric Configuration (CC) segment
1857              IAP_PROGRAM_BY_SPIADDR_CMD    ROM digest in SNVM segment
1858              IAP_VERIFY_BY_SPIADDR_CMD     UL segment
1859              IAP_AUTOUPDATE_CMD            UKDIGEST0 in User Key segment
1860   @param spiaddr
1861                The spiaddr parameter specifies the either the either the index
1862                in the SPI directory or the SPI address in the SPI Flash memory.
1863                Below is the list of the possible meaning of spiaddr parameter
1864                in accordance with the iap_cmd parameter.
1865 
1866                        iap_cmd                         spiaddr
1867                IAP_PROGRAM_BY_SPIIDX_CMD       Index in the SPI directory.
1868                IAP_VERIFY_BY_SPIIDX_CMD        Index in the SPI directory.
1869                IAP_PROGRAM_BY_SPIADDR_CMD      SPI address in the SPI Flash memory
1870                IAP_VERIFY_BY_SPIADDR_CMD       SPI address in the SPI Flash memory
1871                IAP_AUTOUPDATE_CMD              spiaddr is ignored as No index/
1872                                                address required for this command.
1873 
1874    Note: For the IAP services with command IAP_PROGRAM_BY_SPIIDX_CMD and
1875          IAP_VERIFY_BY_SPIIDX_CMD To support recovery SPI_IDX=1 should be an
1876          empty slot and the recovery image should be located in SPI_IDX=0.
1877          Since SPI_IDX=1 should be an empty slot it shouldn’t be passed into
1878          the system service.
1879   @return
1880                     This function returns a value to indicate whether the
1881                     service was executed successfully or not. A zero value
1882                     indicates that the service was executed successfully. A
1883                     non-zero value can indicate that either the driver was not
1884                     able to kick-start the service or that the driver was able
1885                     to kick-start the service and receive a status response code
1886                     from the system controller.
1887                     See theory of operations section for detailed information
1888                     about the return status.
1889                     The following table lists the service status code from
1890                     system controller.
1891 
1892                     | STATUS   |     Description                               |
1893                     |----------|-----------------------------------------------|
1894                     |   0      |  No error                                     |
1895                     |   1      |  Validator or hash chaining mismatch          |
1896                     |   2      |  Unexpected data received                     |
1897                     |   3      |  Invalid/corrupt encryption key               |
1898                     |   4      |  Invalid component header                     |
1899                     |   5      |  Back level not satisfied                     |
1900                     |   6      |  Illegal bitstream mode                       |
1901                     |   7      |  DSN binding mismatch                         |
1902                     |   8      |  Illegal component sequence                   |
1903                     |   9      |  Insufficient device capabilities             |
1904                     |   10     |  Incorrect DEVICEID                           |
1905                     |   11     |  Unsupported bitstream protocol version       |
1906                     |          |  (regeneration required)                      |
1907                     |   12     |  Verify not permitted on this bitstream       |
1908                     |   13     |  Invalid Device Certificate                   |
1909                     |   14     |  Invalid DIB                                  |
1910                     |   21     |  Device not in SPI Master Mode                |
1911                     |   22     |  No valid images found                        |
1912                     |   23     |  No valid images found                        |
1913                     |   24     |  Programmed design version is newer than Auto |
1914                     |          |  Update image found                           |
1915                     |   25     |  Reserved                                     |
1916                     |   26     |  Selected image was invalid and no recovery   |
1917                     |          |  was performed due to valid design in device  |
1918                     |   27     |  Selected and Recovery image failed to program|
1919                     |   127    |  Abort                                        |
1920                     |   128    |  NVMVERIFY                                    |
1921                     |   129    |  PROTECTED                                    |
1922                     |   130    |  NOTENA                                       |
1923                     |   131    |  PNVMVERIFY                                   |
1924                     |   132    |  SYSTEM                                       |
1925                     |   133    |  BADCOMPONENT                                 |
1926                     |   134    |  HVPROGERR                                    |
1927                     |   135    |  HVSTATE                                      |
1928 */
1929 uint16_t
1930 MSS_SYS_execute_iap
1931 (
1932     uint8_t iap_cmd,
1933     uint32_t spiaddr
1934 );
1935 
1936 /*-------------------------------------------------------------------------*//**
1937   The MSS_SYS_spi_copy() function allows data to be copied from the system
1938   controller SPI flash to MSS memory. The SPI SCK frequency is specified by a
1939   user-defined option with valid values shown in parameter description.
1940   This function is non-blocking in the interrupt mode , in that, it will exit
1941   immediately after requesting the service. In polling mode, it becomes a
1942   blocking function. It will block until the the service is completed and a
1943   response is received from the system controller.
1944 
1945   @param mss_dest_addr
1946                     The 64-bit mss_dest_addr parameter specifies the destination
1947                     address in MSS where system controller copies data from SPI
1948                     flash.
1949   @param mss_spi_flash
1950                     The 32-bit mss_spi_flash parameter specifies the source
1951                     address of data to be copied in MSS.
1952   @param n_bytes
1953                     The n_bytes parameter specifies the number of bytes to
1954                     transfer.
1955   @param options
1956                     The 8 bit options parameter specifies the clock frequency
1957                     used for the SPI transfers.
1958 
1959                     |options |Clock     |
1960                     |--------|----------|
1961                     | 1      | 40MHz    |
1962                     | 2      | 20MHz    |
1963                     | 3      | 13.33MHz |
1964 
1965                     7:2 RESERVED        Reserved for future use
1966   @param mb_offset
1967                     The mb_offset parameter specifies the offset from the start
1968                     of mailbox where the data related to this service is
1969                     available. All accesses to the mailbox are of word length
1970                     (4 bytes). A value 10 (decimal) of this parameter would
1971                     mean that the data access area for this service, in the
1972                     mailbox starts from 11th word (offset 10).
1973   @return
1974                     This function returns a value to indicate whether the
1975                     service was executed successfully or not. A zero value
1976                     indicates that the service was executed successfully. A
1977                     non-zero value can indicate that either the driver was not
1978                     able to kick-start the service or that the driver was able
1979                     to kick-start the service and receive a status response code
1980                     from the system controller.
1981                     See theory of operations section for detailed information
1982                     about the return status.
1983                     The following table lists the service status code from
1984                     system controller.
1985 
1986                     |STATUS    |Description                                  |
1987                     |----------|---------------------------------------------|
1988                     |   0      | Success                                     |
1989                     |   1      | Device not configured for master mode       |
1990                     |   2      | AXI Error                                   |
1991 */
1992 uint16_t
1993 MSS_SYS_spi_copy
1994 (
1995     uint64_t mss_dest_addr,
1996     uint32_t mss_spi_flash,
1997     uint32_t n_bytes,
1998     uint8_t options,
1999     uint16_t mb_offset
2000 );
2001 
2002 /*-------------------------------------------------------------------------*//**
2003   The MSS_SYS_debug_read_probe() function will read the content of a
2004   probe module (59 x 18b words).
2005   This function is non-blocking in the interrupt mode , in that, it will exit
2006   immediately after requesting the service. In polling mode, it becomes a
2007   blocking function. It will block until the the service is completed and a
2008   response is received from the system controller.
2009 
2010   Note: The IPROWADDR & IPSEGADDR addresses are not incremented as the
2011         associated address space is not contiguous. If PRBADDR is 63 it will
2012         wrap back to 0.
2013 
2014   @param ipseg_addr
2015                     The ipseg_addr parameter specifies the probe segment
2016                     address.
2017   @param iprow_addr
2018                     The iprow_addr parameter specifies the probe row address.
2019                     ipseg_addr and iprow_addr parameters specifies the target
2020                     address of probe module.
2021   @param prdata
2022                     The prdata parameter specifies the read data for probe
2023                     word i(0 to 58) within the probe module.
2024   @param mb_offset
2025                     The mb_offset parameter specifies the offset from the start
2026                     of mailbox where the data related to this service is
2027                     available. All accesses to the mailbox are of word length
2028                     (4 bytes). A value 10 (decimal) of this parameter would
2029                     mean that the data access area for this service, in the
2030                     mailbox starts from 11th word (offset 10).
2031   @param resp_offset
2032                     The resp_offset parameter specifies the offset of the
2033                     start of Mailbox response where the data received from
2034                     the service will be available.
2035   @return
2036                     This function returns a value to indicate whether the
2037                     service was executed successfully or not. A zero value
2038                     indicates that the service was executed successfully. A
2039                     non-zero value can indicate that either the driver was not
2040                     able to kick-start the service or that the driver was able
2041                     to kick-start the service and receive a status response code
2042                     from the system controller.
2043                     See theory of operations section for detailed information
2044                     about the return status.
2045                     The following table lists the service status code from
2046                     system controller.
2047 
2048                     |STATUS   | Description   |                               |
2049                     |---------|---------------|-------------------------------|
2050                     |  0      | Success       |                               |
2051                     |  1      | SECERR        | The operation was blocked by  |
2052                     |         |               | device security.              |
2053 */
2054 uint16_t
2055 MSS_SYS_debug_read_probe
2056 (
2057     uint8_t ipseg_addr,
2058     uint8_t iprow_addr,
2059     uint8_t *prdata,
2060     uint16_t mb_offset,
2061     uint8_t resp_offset
2062 );
2063 
2064 /*-------------------------------------------------------------------------*//**
2065   The MSS_SYS_debug_write_probe() function will writes up to 18 bits of
2066   data to selected probe address.
2067   This function is non-blocking in the interrupt mode , in that, it will exit
2068   immediately after requesting the service. In polling mode, it becomes a
2069   blocking function. It will block until the the service is completed and a
2070   response is received from the system controller.
2071 
2072   @param prb_addr
2073                     The prb_addr parameter specifies the probe address.
2074   @param ipseg_addr
2075                     The ipseg_addr parameter specifies the probe segment
2076                     address.
2077   @param iprow_addr
2078                     The iprow_addr parameter specifies the probe row address.
2079                     prb_addr, ipseg_addr and iprow_addr parameters specifies
2080                     the target address of one of the 59 words within a probe
2081                     module.
2082   @param pwmask
2083                     The pwmask parameter specifies the which of the 18 bits of
2084                     pwdata shall be written to selected probe module.
2085   @param pwdata
2086                     The pwdata parameter specifies the value to be written on
2087                     selected probe registers.
2088                     Example: If PWMASK[i] is ‘1’ then probe register i will
2089                     be written to the value specified by PWDATA[i].
2090   @param mb_offset
2091                     The mb_offset parameter specifies the offset from the start
2092                     of mailbox where the data related to this service is
2093                     available. All accesses to the mailbox are of word length
2094                     (4 bytes). A value 10 (decimal) of this parameter would
2095                     mean that the data access area for this service, in the
2096                     mailbox starts from 11th word (offset 10).
2097   @return
2098                     This function returns a value to indicate whether the
2099                     service was executed successfully or not. A zero value
2100                     indicates that the service was executed successfully. A
2101                     non-zero value can indicate that either the driver was not
2102                     able to kick-start the service or that the driver was able
2103                     to kick-start the service and receive a status response code
2104                     from the system controller.
2105                     See theory of operations section for detailed information
2106                     about the return status.
2107                     The following table lists the service status code from
2108                     system controller.
2109 
2110                     |STATUS   | Description   |                               |
2111                     |---------|---------------|-------------------------------|
2112                     |  0      | Success       |                               |
2113                     |  1      | SECERR        | The operation was blocked by  |
2114                     |         |               | device security.              |
2115 */
2116 uint16_t
2117 MSS_SYS_debug_write_probe
2118 (
2119     uint8_t prb_addr,
2120     uint8_t ipseg_addr,
2121     uint8_t iprow_addr,
2122     uint32_t pwmask,
2123     uint32_t pwdata,
2124     uint16_t mb_offset
2125 );
2126 
2127 /*-------------------------------------------------------------------------*//**
2128   The MSS_SYS_debug_live_probe() function will configures channel a or
2129   b of the live probe system.  A live probe is enabled by writing a local
2130   address register within one of the probe segment modules. Each probe segment
2131   module generates its own local channel a live probe outputs which are
2132   combined by OR chains to generate a chip-level live probe channel a signal.
2133   This function is non-blocking in the interrupt mode , in that, it will exit
2134   immediately after requesting the service. In polling mode, it becomes a
2135   blocking function. It will block until the the service is completed and a
2136   response is received from the system controller.
2137 
2138   Note: - When configuring channel a, channel b is not affected and vice versa.
2139         - Live probes are intentionally not cleared by JTAG reset.
2140           They remain in effect until either manually disabled or the device is
2141           reset.
2142 
2143   @param x_addr
2144                     The parameter x_addr specifies the x co-ordinate within
2145                     target probe module.
2146   @param y_addr
2147                     The parameter y_addr specifies the y co-ordinate within
2148                     the target probe module.
2149   @param ipseg_addr
2150                     The ipseg_addr parameter specifies the probe segment
2151                     address.
2152   @param iprow_addr
2153                     The iprow_addr parameter specifies the probe row address.
2154                     ipseg_addr and iprow_addr parameters specifies the target
2155                     address of probe module.
2156   @param clear
2157                     The clear parameter(of size 1-bit) is used to clear the
2158                     configurations of local channels a or b. If CLEAR is ‘1’,
2159                     all local channel x (the applicable channel a or b)
2160                     configurations are cleared before applying the new
2161                     configuration
2162   @param ioen
2163                     The ioen parameter(of size 1-bit) is used to activate
2164                     the probe output pad. If IOEN is ‘1’ then the corresponding
2165                     live probe output pad is activated.  Note that setting IOEN
2166                     to ‘0’ does not disable the internal live probe
2167                     configuration.
2168   @param mb_offset
2169                     The mb_offset parameter specifies the offset from the start
2170                     of mailbox where the data related to this service is
2171                     available. All accesses to the mailbox are of word length
2172                     (4 bytes). A value 10 (decimal) of this parameter would
2173                     mean that the data access area for this service, in the
2174                     mailbox starts from 11th word (offset 10).
2175   @param service_cmd
2176                     The service_cmd parameter specifies the channel(channel
2177                     a or b) selected by the user. User have to provide one of
2178                     the predefined macros to select the channel for live probe
2179                     debug operation.
2180   @return
2181                     This function returns a value to indicate whether the
2182                     service was executed successfully or not. A zero value
2183                     indicates that the service was executed successfully. A
2184                     non-zero value can indicate that either the driver was not
2185                     able to kick-start the service or that the driver was able
2186                     to kick-start the service and receive a status response code
2187                     from the system controller.
2188                     See theory of operations section for detailed information
2189                     about the return status.
2190                     The following table lists the service status code from
2191                     system controller.
2192 
2193                     |STATUS   | Description   |                               |
2194                     |---------|---------------|-------------------------------|
2195                     |  0      | Success       |                               |
2196                     |  1      | SECERR        | The operation was blocked by  |
2197                     |         |               | device security.              |
2198 */
2199 uint16_t
2200 MSS_SYS_debug_live_probe
2201 (
2202     uint8_t x_addr,
2203     uint8_t y_addr,
2204     uint8_t ipseg_addr,
2205     uint8_t iprow_addr,
2206     uint8_t clear,
2207     uint8_t ioen,
2208     uint16_t mb_offset,
2209     uint8_t service_cmd
2210 );
2211 
2212 /*-------------------------------------------------------------------------*//**
2213   The MSS_SYS_debug_select_mem() function will specifies a target
2214   fabric memory to be accessed by the MEM read & MEM write services.
2215   A handshake mechanism is used to request access to the target memory.  The
2216   memory lock may be acquired immediately allowing multiple read/write
2217   operations to be performed as one logical transaction or the lock may be
2218   acquired and released by individual read/write operations.
2219   This function is non-blocking in the interrupt mode , in that, it will exit
2220   immediately after requesting the service. In polling mode, it becomes a
2221   blocking function. It will block until the the service is completed and a
2222   response is received from the system controller.
2223 
2224   @param ipblk_addr
2225                     The ipblk_addr parameter specifies the block address of
2226                     fabric memory.
2227   @param ipseg_addr
2228                     The ipseg_addr parameter specifies the segment address.
2229   @param iprow_addr
2230                     The iprow_addr parameter specifies the row address of
2231                     fabric memory to be accessed by MEM read and MEM write
2232                     services.
2233   @param memtype
2234                     The memtype parameter specifies the type of fabric
2235                     memory to be used for MEM read and write services.
2236 
2237                     MEMTYPE Peripheral  MEMSIZE(words) Access Width
2238                          0   LSRAM x1    16384              1
2239                          1   LSRAM x2    8192               2
2240                          2   LSRAM x5    4096               5
2241                          3   LSRAM x10   2048               10
2242                          4   LSRAM x20   1024               20
2243                          5   µRAM        64                 12
2244                          6   µPROM       256                9
2245                          7   LSRAM x20   1024               20
2246   @param memlock_mode
2247                     The memlock_mode parameter specifies the the memory
2248                     lock states for supported MEMLOCKMODE values.
2249   @param timeout
2250                     When a lock is requested we must consider a scenario
2251                     where the user design may not complete the request
2252                     handshake.  To prevent the firmware from waiting
2253                     indefinitely, the user must specify a timeout after
2254                     which time the handshake is aborted.
2255   @param mb_offset
2256                     The mb_offset parameter specifies the offset from the start
2257                     of mailbox where the data related to this service is
2258                     available. All accesses to the mailbox are of word length
2259                     (4 bytes). A value 10 (decimal) of this parameter would
2260                     mean that the data access area for this service, in the
2261                     mailbox starts from 11th word (offset 10).
2262   @return
2263                     This function returns a value to indicate whether the
2264                     service was executed successfully or not. A zero value
2265                     indicates that the service was executed successfully. A
2266                     non-zero value can indicate that either the driver was not
2267                     able to kick-start the service or that the driver was able
2268                     to kick-start the service and receive a status response code
2269                     from the system controller.
2270                     See theory of operations section for detailed information
2271                     about the return status.
2272                     The following table lists the service status code from
2273                     system controller.
2274 
2275                     |STATUS   | Description   |                               |
2276                     |---------|---------------|-------------------------------|
2277                     |  0      | Success       |                               |
2278                     |  1      | SECERR        | The operation was blocked by  |
2279                     |         |               | device security.              |
2280                     |  2      | TIMEOUTERR    | Timeout occurred.             |
2281                     |  3      | LOCKERR       | Target memory failed to lock  |
2282 */
2283 uint16_t
2284 MSS_SYS_debug_select_mem
2285 (
2286     uint8_t ipblk_addr,
2287     uint8_t ipseg_addr,
2288     uint8_t iprow_addr,
2289     uint8_t memtype,
2290     uint8_t memlock_mode,
2291     uint16_t timeout,
2292     uint16_t mb_offset
2293 );
2294 
2295 /*-------------------------------------------------------------------------*//**
2296   The MSS_SYS_debug_read_mem() function provides an interface to read
2297   data from the memory peripheral that is specified. A handshake mechanism is
2298   used to request access to the target memory.  The memory lock may be acquired
2299   immediately allowing multiple read/write operations to be performed as one
2300   logical transaction.
2301   This function is non-blocking in the interrupt mode , in that, it will exit
2302   immediately after requesting the service. In polling mode, it becomes a
2303   blocking function. It will block until the the service is completed and a
2304   response is received from the system controller.
2305 
2306   @param mem_addr
2307                     The mem_addr parameter sets the target address within the
2308                     currently selected memory peripheral for subsequent
2309                     mem write & mem read instructions.
2310   @param n_words
2311                     The n_words parameter value depends on memtype. The
2312                     maximum limit is the size of memory.
2313   @param mss_addr
2314                     The mss_addr parameter specifies the MSS RAM area where
2315                     to copy the MEM Read data to. Note that all accesses will
2316                     be done with MSS User privileges.
2317   @param mb_offset
2318                     The mb_offset parameter specifies the offset from the start
2319                     of mailbox where the data related to this service is
2320                     available. All accesses to the mailbox are of word length
2321                     (4 bytes). A value 10 (decimal) of this parameter would
2322                     mean that the data access area for this service, in the
2323                     mailbox starts from 11th word (offset 10).
2324   @return
2325                     This function returns a value to indicate whether the
2326                     service was executed successfully or not. A zero value
2327                     indicates that the service was executed successfully. A
2328                     non-zero value can indicate that either the driver was not
2329                     able to kick-start the service or that the driver was able
2330                     to kick-start the service and receive a status response code
2331                     from the system controller.
2332                     See theory of operations section for detailed information
2333                     about the return status.
2334                     The following table lists the service status code from
2335                     system controller.
2336 
2337                     |STATUS   | Description   |                               |
2338                     |---------|---------------|-------------------------------|
2339                     |  0      | Success       |                               |
2340                     |  1      | SECERR        | The operation was blocked by  |
2341                     |         |               | device security.              |
2342                     |  2      | TIMEOUTERR    | Timeout occurred.             |
2343                     |  3      | LOCKERR       | Target memory failed to lock  |
2344 */
2345 uint16_t
2346 MSS_SYS_debug_read_mem
2347 (
2348     uint16_t mem_addr,
2349     uint16_t n_words,
2350     uint64_t mss_addr,
2351     uint16_t mb_offset
2352 );
2353 
2354 /*-------------------------------------------------------------------------*//**
2355   The MSS_SYS_debug_write_mem() function provides an interface to write
2356   data from the memory peripheral that is specified. A handshake mechanism is
2357   used to request access to the target memory.  The memory lock may be acquired
2358   immediately allowing multiple read/write operations to be performed as one
2359   logical transaction.
2360   This function is non-blocking in the interrupt mode , in that, it will exit
2361   immediately after requesting the service. In polling mode, it becomes a
2362   blocking function. It will block until the the service is completed and a
2363   response is received from the system controller.
2364 
2365   @param mem_addr
2366                     The mem_addr parameter sets the target address within the
2367                     currently selected memory peripheral for subsequent
2368                     mem write & mem read instructions.
2369   @param n_words
2370                     The n_words parameter value depends on memtype. The
2371                     maximum limit is the size of memory.
2372   @param mss_addr
2373                     The mss_addr parameter specifies the MSS RAM area where
2374                     to copy the MEM Read data to. Note that all accesses will
2375                     be done with MSS User privileges.
2376   @param mb_offset
2377                     The mb_offset parameter specifies the offset from the start
2378                     of mailbox where the data related to this service is
2379                     available. All accesses to the mailbox are of word length
2380                     (4 bytes). A value 10 (decimal) of this parameter would
2381                     mean that the data access area for this service, in the
2382                     mailbox starts from 11th word (offset 10).
2383   @return
2384                     This function returns a value to indicate whether the
2385                     service was executed successfully or not. A zero value
2386                     indicates that the service was executed successfully. A
2387                     non-zero value can indicate that either the driver was not
2388                     able to kick-start the service or that the driver was able
2389                     to kick-start the service and receive a status response code
2390                     from the system controller.
2391                     See theory of operations section for detailed information
2392                     about the return status.
2393                     The following table lists the service status code from
2394                     system controller.
2395 
2396                     |STATUS   | Description   |                               |
2397                     |---------|---------------|-------------------------------|
2398                     |  0      | Success       |                               |
2399                     |  1      | SECERR        | The operation was blocked by  |
2400                     |         |               | device security.              |
2401                     |  2      | TIMEOUTERR    | Timeout occurred.             |
2402                     |  3      | LOCKERR       | Target memory failed to lock  |
2403 */
2404 uint16_t
2405 MSS_SYS_debug_write_mem
2406 (
2407     uint16_t mem_addr,
2408     uint16_t n_words,
2409     uint64_t mss_addr,
2410     uint16_t mb_offset
2411 );
2412 
2413 /*-------------------------------------------------------------------------*//**
2414   The MSS_SYS_debug_read_apb() function reads a specified number of bytes
2415   from the fabric APB bus to the specified MSS RAM area. The operation makes
2416   the required number of read transactions using the selected transaction size,
2417   APBDWSIZE.
2418   The addressed fabric peripheral may generate an error or fail to respond
2419   within a user-defined window, in which case any subsequent transfers are
2420   aborted and corresponding error flags are returned.
2421   This function is non-blocking in the interrupt mode , in that, it will exit
2422   immediately after requesting the service. In polling mode, it becomes a
2423   blocking function. It will block until the the service is completed and a
2424   response is received from the system controller.
2425 
2426   @param apb_addr
2427                     The apb_addr parameter specifies the target address and
2428                     transfer size for the apb write & apb read operations.
2429   @param apb_wsize
2430                     The apb_wsize parameter specifies the data transfer size
2431                     to be used by the apb write & apb read operations.
2432   @param max_bytes
2433                     The max_bytes parameter is used in calculation specified
2434                     number of bytes from the fabric APB bus to the Shared
2435                     Buffer.
2436                     NBYTES = MAXBYTES + 1
2437   @param mss_addr
2438                     The mss_addr parameter specifies the MSS RAM area where
2439                     to copy the MEM Read data to. Note that all accesses will
2440                     be done with MSS User privileges.
2441   @param mb_offset
2442                     The mb_offset parameter specifies the offset from the start
2443                     of mailbox where the data related to this service is
2444                     available. All accesses to the mailbox are of word length
2445                     (4 bytes). A value 10 (decimal) of this parameter would
2446                     mean that the data access area for this service, in the
2447                     mailbox starts from 11th word (offset 10).
2448   @return
2449                     This function returns a value to indicate whether the
2450                     service was executed successfully or not. A zero value
2451                     indicates that the service was executed successfully. A
2452                     non-zero value can indicate that either the driver was not
2453                     able to kick-start the service or that the driver was able
2454                     to kick-start the service and receive a status response code
2455                     from the system controller.
2456                     See theory of operations section for detailed information
2457                     about the return status.
2458                     The following table lists the service status code from
2459                     system controller.
2460 
2461                   | STATUS  | Description|                                     |
2462                   |---------|------------|-------------------------------------|
2463                   | 0       | Success    |                                     |
2464                   | 1       | SECERR     | The operation was blocked by device |
2465                   |         |            | security.                           |
2466                   | 2       | SLVERR     | The addressed fabric APB peripheral |
2467                   |         |            | generated a SLVERR response to the  |
2468                   |         |            | bus transaction.                    |
2469                   | 3       | TIMEOUT    | The addressed fabric APB peripheral |
2470                   |         |            | failed to respond before the        |
2471                   |         |            | user-defined APB timeout or the     |
2472                   |         |            | fabric power is not on.             |
2473 */
2474 uint16_t
2475 MSS_SYS_debug_read_apb
2476 (
2477     uint32_t apb_addr,
2478     uint8_t  apb_wsize,
2479     uint16_t max_bytes,
2480     uint64_t mss_addr,
2481     uint16_t mb_offset
2482 );
2483 
2484 /*-------------------------------------------------------------------------*//**
2485   The MSS_SYS_debug_write_apb() function writes bytes of data to the
2486   current fabric APB address as specified by APBADDR.  The addressed fabric
2487   peripheral may generate an error or fail to respond within a user-defined
2488   window, in which case the corresponding error flags are returned.
2489   This function is non-blocking in the interrupt mode , in that, it will exit
2490   immediately after requesting the service. In polling mode, it becomes a
2491   blocking function. It will block until the the service is completed and a
2492   response is received from the system controller.
2493 
2494   @param apb_addr
2495                     The apb_addr parameter specifies the target address and
2496                     transfer size for the apb write & apb read operations.
2497   @param apb_wsize
2498                     The apb_wsize parameter specifies the data transfer size
2499                     to be used by the apb write & apb read operations.
2500   @param max_bytes
2501                     The max_bytes parameter is used in calculation specified
2502                     number of bytes from the fabric APB bus to the Shared
2503                     Buffer.
2504                     NBYTES = MAXBYTES + 1
2505   @param mss_addr
2506                     The mss_addr parameter specifies the MSS RAM area where
2507                     to copy the MEM Read data to. Note that all accesses will
2508                     be done with MSS User privileges.
2509   @param mb_offset
2510                     The mb_offset parameter specifies the offset from the start
2511                     of mailbox where the data related to this service is
2512                     available. All accesses to the mailbox are of word length
2513                     (4 bytes). A value 10 (decimal) of this parameter would
2514                     mean that the data access area for this service, in the
2515                     mailbox starts from 11th word (offset 10).
2516   @return
2517                     This function returns a value to indicate whether the
2518                     service was executed successfully or not. A zero value
2519                     indicates that the service was executed successfully. A
2520                     non-zero value can indicate that either the driver was not
2521                     able to kick-start the service or that the driver was able
2522                     to kick-start the service and receive a status response code
2523                     from the system controller.
2524                     See theory of operations section for detailed information
2525                     about the return status.
2526                     The following table lists the service status code from
2527                     system controller.
2528 
2529                   | STATUS  | Description|                                     |
2530                   |---------|------------|-------------------------------------|
2531                   | 0       | Success    |                                     |
2532                   | 1       | SECERR     | The operation was blocked by device |
2533                   |         |            | security.                           |
2534                   | 2       | SLVERR     | The addressed fabric APB peripheral |
2535                   |         |            | generated a SLVERR response to the  |
2536                   |         |            | bus transaction.                    |
2537                   | 3       | TIMEOUT    | The addressed fabric APB peripheral |
2538                   |         |            | failed to respond before the        |
2539                   |         |            | user-defined APB timeout or the     |
2540                   |         |            | fabric power is not on.             |
2541 */
2542 uint16_t
2543 MSS_SYS_debug_write_apb
2544 (
2545     uint32_t apb_addr,
2546     uint8_t  apb_wsize,
2547     uint16_t max_bytes,
2548     uint64_t mss_addr,
2549     uint16_t mb_offset
2550 );
2551 
2552 /*-------------------------------------------------------------------------*//**
2553   The MSS_SYS_debug_fabric_snapshot() function will service generates a
2554   snapshot of the volatile fabric content. Data is read from each LSRAM, µRAM
2555   and probe module and copied to the fabric APB debug port.
2556   This function is non-blocking in the interrupt mode , in that, it will exit
2557   immediately after requesting the service. In polling mode, it becomes a
2558   blocking function. It will block until the the service is completed and a
2559   response is received from the system controller.
2560 
2561   @param port_addr
2562                     The port_addr parameter sets the address of the APB port
2563                     to be used for bulk access debug instructions which are
2564                     used in conjunction with Microsemi fabric debug IP.
2565                     The debug port is a single location on the fabric APB
2566                     bus through which debug data is streamed.
2567   @param apb_fast_write
2568                     The apb_fast_write parameter specifies whether to use
2569                     the fast apb protocol. If apb_fast_write is ‘1’ then,
2570                     during write transfers, the fast APB protocol is used
2571                     and the address range is limited to port_addr[15:2]  and
2572                     port_addr[28:16] is ignored.
2573   @param mb_offset
2574                     The mb_offset parameter specifies the offset from the start
2575                     of mailbox where the data related to this service is
2576                     available. All accesses to the mailbox are of word length
2577                     (4 bytes). A value 10 (decimal) of this parameter would
2578                     mean that the data access area for this service, in the
2579                     mailbox starts from 11th word (offset 10).
2580   @return
2581                     This function returns a value to indicate whether the
2582                     service was executed successfully or not. A zero value
2583                     indicates that the service was executed successfully. A
2584                     non-zero value can indicate that either the driver was not
2585                     able to kick-start the service or that the driver was able
2586                     to kick-start the service and receive a status response code
2587                     from the system controller.
2588                     See theory of operations section for detailed information
2589                     about the return status.
2590                     The following table lists the service status code from
2591                     system controller.
2592 
2593                   | STATUS  | Description|                                     |
2594                   |---------|------------|-------------------------------------|
2595                   | 0       | Success    |                                     |
2596                   | 1       | SECERR     | The operation was blocked by device |
2597                   |         |            | security.                           |
2598                   | 2       | BUSERR     | Bus error occurred and the snapshot |
2599                   |         |            |  was aborted.                     |
2600 */
2601 uint16_t
2602 MSS_SYS_debug_fabric_snapshot
2603 (
2604     uint32_t port_addr,
2605     uint8_t apb_fast_write,
2606     uint16_t mb_offset
2607 );
2608 
2609 /*-------------------------------------------------------------------------*//**
2610   The MSS_SYS_otp_generate() function is used to set up the device to
2611   The receive a one-time passcode.  A 128-bit nonce, NFPGA, is generated and
2612   The stored in volatile memory for later use in the rest of the protocol.
2613   The A 128-bit user nonce, NUSER, is supplied by the user.
2614   This service only unlocks the software debug lock SWL_DEBUG.
2615   This function is non-blocking in the interrupt mode , in that, it will exit
2616   immediately after requesting the service. In polling mode, it becomes a
2617   blocking function. It will block until the the service is completed and a
2618   response is received from the system controller.
2619 
2620   @param keymode
2621                    keymode parameter specifies the key mode to be used to
2622                    transport the encrypted passcode.
2623                    The KEYMODE parameter is not checked for validity until the
2624                    MATCH OTP service is executed.  Both PCTYPE and KEYMODE are
2625                    stored in volatile memory for use by the MATCH OTP service.
2626 
2627                    Supported values for KEYMODE are shown below.
2628                    PCTYPE  KEYMODE  Key Mode       KROOT   Note
2629                      1       3      KM_USER_KEY1    UK1    User key 1
2630                      1       4      KM_USER_KEY2    UK2    User key 2
2631                      1       7      KM_FACTORY_KEY  DFK    FK diversified by UID
2632   @param n_user
2633                    The n_user parameter specifies the user nonce, is supplied
2634                    by the user.
2635   @param n_fpga
2636                     The n_fpga parameter specifies the 128-bit nonce, NFPGA, is
2637                     generated and stored in volatile memory for later use in the
2638                     rest of the protocol.
2639   @param mb_offset
2640                     The mb_offset parameter specifies the offset from the start
2641                     of mailbox where the data related to this service is
2642                     available. All accesses to the mailbox are of word length
2643                     (4 bytes). A value 10 (decimal) of this parameter would
2644                     mean that the data access area for this service, in the
2645                     mailbox starts from 11th word (offset 10).
2646   @param ret_offset
2647                     The ret_offset parameter specifies the offset of the
2648                     start of Mailbox response where the data received from
2649                     the service will be available.
2650   @return
2651                     This function returns a value to indicate whether the
2652                     service was executed successfully or not. A zero value
2653                     indicates that the service was executed successfully. A
2654                     non-zero value can indicate that either the driver was not
2655                     able to kick-start the service or that the driver was able
2656                     to kick-start the service and receive a status response code
2657                     from the system controller.
2658                     See theory of operations section for detailed information
2659                     about the return status.
2660                     The following table lists the service status code from
2661                     system controller.
2662 
2663                     If any part of the service fails, then all unlocked
2664                     passcodes are re-locked and the tamper event
2665                     PASSCODE_FAIL is generated.
2666 
2667                   | STATUS  | Description|                                     |
2668                   |---------|------------|-------------------------------------|
2669                   | 0       | Success    |                                     |
2670                   | 1       | SECERR     | The operation was blocked by device |
2671                   |         |            | security.                           |
2672                   | 2       | PROTOCOLERR| If an invalid key mode is specified |
2673                   |         |            | fails then the returned nonce is    |
2674                   |         |            | 0^128, the protocol is aborted and  |
2675                   |         |            | the tamper event PASSCODE_FAIL is   |
2676                   |         |            | generated.                          |
2677 */
2678 uint16_t
2679 MSS_SYS_otp_generate
2680 (
2681     uint8_t keymode,
2682     uint8_t* n_user,
2683     uint8_t* n_fpga,
2684     uint16_t mb_offset,
2685     uint16_t resp_offset
2686 );
2687 
2688 /*-------------------------------------------------------------------------*//**
2689   The MSS_SYS_otp_match() function is the second part of the one-time
2690   passcode protocol.  Before using this service the GENERATE OTP service must
2691   first be used to obtain a nonce, NFPGA, from the device.
2692   This function is non-blocking in the interrupt mode , in that, it will exit
2693   immediately after requesting the service. In polling mode, it becomes a
2694   blocking function. It will block until the the service is completed and a
2695   response is received from the system controller.
2696 
2697   @param user_id
2698                     The UID parameter is only used if the KEYMODE used for
2699                     the GENERATE OTP service was KEYMODE_FACTORY_KEY and the
2700                     passcode was not the Factory Passcode.
2701   @param validator
2702                     The 256-bit validator parameter store the validator key.
2703   @param otp
2704                     The otp parameter stores the otp value from generate otp
2705                     service.
2706   @param mb_offset
2707                     The mb_offset parameter specifies the offset from the start
2708                     of mailbox where the data related to this service is
2709                     available. All accesses to the mailbox are of word length
2710                     (4 bytes). A value 10 (decimal) of this parameter would
2711                     mean that the data access area for this service, in the
2712                     mailbox starts from 11th word (offset 10).
2713   @param resp_offset
2714                     The resp_offset parameter specifies the offset from the
2715                     start of Mailbox response where the data received from
2716                     the service will be available.
2717   @return
2718                     This function returns a value to indicate whether the
2719                     service was executed successfully or not. A zero value
2720                     indicates that the service was executed successfully. A
2721                     non-zero value can indicate that either the driver was not
2722                     able to kick-start the service or that the driver was able
2723                     to kick-start the service and receive a status response code
2724                     from the system controller.
2725                     See theory of operations section for detailed information
2726                     about the return status.
2727                     The following table lists the service status code from
2728                     system controller.
2729 
2730                     |STATUS|   Description   |
2731                     |------|-----------------|
2732                     |  0   |   Success       |
2733                     |  1   |   PROTOCOLERR   |
2734                     |  2   |   MISMATCHERR   |
2735 */
2736 uint16_t
2737 MSS_SYS_otp_match
2738 (
2739     uint8_t * user_id,
2740     uint8_t * validator,
2741     uint8_t * otp,
2742     uint16_t mb_offset,
2743     uint16_t resp_offset
2744 );
2745 
2746 /*-------------------------------------------------------------------------*//**
2747   The MSS_SYS_unlock_debug_passcode() function will Attempt to match
2748   the user debug pass code using the key loaded into the mailbox.  If the match
2749   is successful the software debug lock SWL_DEBUG is temporarily inactive.
2750   This function is non-blocking in the interrupt mode , in that, it will exit
2751   immediately after requesting the service. In polling mode, it becomes a
2752   blocking function. It will block until the the service is completed and a
2753   response is received from the system controller.
2754 
2755   @param cmd_data
2756                     The parameter cmd_data specifies the device's debug
2757                     passcode (DPK), configured by the user via bitstream.
2758   @param mb_offset
2759                     The mb_offset parameter specifies the offset from the start
2760                     of mailbox where the data related to this service is
2761                     available. All accesses to the mailbox are of word length
2762                     (4 bytes). A value 10 (decimal) of this parameter would
2763                     mean that the data access area for this service, in the
2764                     mailbox starts from 11th word (offset 10).
2765   @param ret_offset
2766                     The ret_offset parameter specifies the offset from the
2767                     start of Mailbox response where the data received from
2768                     the service will be available.
2769   @return
2770                     This function returns a value to indicate whether the
2771                     service was executed successfully or not. A zero value
2772                     indicates that the service was executed successfully. A
2773                     non-zero value can indicate that either the driver was not
2774                     able to kick-start the service or that the driver was able
2775                     to kick-start the service and receive a status response code
2776                     from the system controller.
2777                     See theory of operations section for detailed information
2778                     about the return status.
2779                     The following table lists the service status code from
2780                     system controller.
2781 
2782                   | STATUS  | Description|                                     |
2783                   |---------|------------|-------------------------------------|
2784                   | 0       | Success    |                                     |
2785                   | 1       | SECERR     | The operation was blocked by device |
2786                   |         |            | security.                           |
2787                   | 2       | PROTOCOLERR| If the unlock operation fail for any|
2788                   |         |            | reason, then the tamper event       |
2789                   |         |            | PASSCODE_FAIL is generated.         |
2790 
2791   If any part of the service fails, then all unlocked passcodes are re-locked
2792   and the tamper event PASSCODE_FAIL is generated.
2793 */
2794 uint16_t
2795 MSS_SYS_unlock_debug_passcode
2796 (
2797     uint8_t* cmd_data,
2798     uint16_t mb_offset,
2799     uint16_t resp_offset
2800 );
2801 
2802 /*-------------------------------------------------------------------------*//**
2803   The MSS_SYS_one_way_passcode() function is used to provide a
2804   mechanism for overriding the software debug lock  SWL_DEBUG without requiring
2805   any interaction with an external intelligence.
2806   The following conditions must be met for the OWP to proceed and write the
2807   payload HWM to the device:
2808     •   HWM stored in the device must be valid
2809     •   OWP passcode matches
2810     •   Payload HWM is greater than the HWM stored in the device
2811   After HWM is written the OWP is successful and SWL_DEBUG is unlocked.
2812   This function is non-blocking in the interrupt mode , in that, it will exit
2813   immediately after requesting the service. In polling mode, it becomes a
2814   blocking function. It will block until the the service is completed and a
2815   response is received from the system controller.
2816 
2817   @param msg_id
2818                     The msg_id parameter stores the value of message ID.
2819   @param validator
2820                     The 256-bit validator parameter store the validator key.
2821   @param keymode
2822                     The Keymode parameter specifies the permitted keymodes for
2823                     OWP service.
2824 
2825                      KEYID     Key Mode            Permitted
2826                         0   KM_INIT_FACTORY         No
2827                         1   KM_ZERO_RECOVERY        No
2828                         2   KM_DEFAULT_KEY          Yes
2829                         3   KM_USER_KEY1            Yes
2830                         4   KM_USER_KEY2            Yes
2831                         5       -
2832                         6   KM_AUTH_CODE            No
2833                         7   KM_FACTORY_KEY          Yes
2834                         8   KM_FACTORY_EC           No
2835                         9   KM_FACTORY_EC_E         No
2836                         10      -
2837                         11      -
2838                         12  KM_USER_EC              No
2839                         13  KM_USER_EC_E            No
2840                         14      -
2841                         15      -
2842 
2843   @param dsn
2844                     The dsn parameter stores the value of device serial number.
2845   @param hash
2846                     The hash parameter stores 256-bit hash value.
2847 
2848   @param plaintext_passcode
2849                     The plaintext_passcode parameter stores the passcode value.
2850   @param hwm
2851                     The hwm parameter stores the high water mark value.
2852   @param mb_offset
2853                     The mb_offset parameter specifies the offset from the start
2854                     of mailbox where the data related to this service is
2855                     available. All accesses to the mailbox are of word length
2856                     (4 bytes). A value 10 (decimal) of this parameter would
2857                     mean that the data access area for this service, in the
2858                     mailbox starts from 11th word (offset 10).
2859   @param ret_offset
2860                     The ret_offset parameter specifies the offset from the
2861                     start of Mailbox response where the data received from
2862                     the service will be available.
2863   @return
2864                     This function returns a value to indicate whether the
2865                     service was executed successfully or not. A zero value
2866                     indicates that the service was executed successfully. A
2867                     non-zero value can indicate that either the driver was not
2868                     able to kick-start the service or that the driver was able
2869                     to kick-start the service and receive a status response code
2870                     from the system controller.
2871                     See theory of operations section for detailed information
2872                     about the return status.
2873                     The following table lists the service status code from
2874                     system controller.
2875 
2876                   | STATUS  | Description|                                     |
2877                   |---------|------------|-------------------------------------|
2878                   | 0       | Success    |                                     |
2879                   | 1       | OWPERR     | If the unlock operation fail for any|
2880                   |         |            | reason, then the tamper event       |
2881                   |         |            | PASSCODE_FAIL is generated.         |
2882 
2883   If any part of the service fails, then all unlocked passcodes are re-locked
2884   and the tamper event PASSCODE_FAIL is generated.
2885 */
2886 uint16_t
2887 MSS_SYS_one_way_passcode
2888 (
2889     uint8_t* msg_id,
2890     uint8_t* validator,
2891     uint8_t keymode,
2892     uint8_t* dsn,
2893     uint8_t* hash,
2894     uint8_t* plaintext_passcode,
2895     uint8_t* hwm,
2896     uint16_t mb_offset,
2897     uint16_t resp_offset
2898 );
2899 
2900 /*-------------------------------------------------------------------------*//**
2901   The MSS_SYS_debug_terminate() function will terminate the debug
2902   session. Its purpose is to re-lock all the software based debug locks
2903   (SWL_DEBUG) if needed and to release any memories previously locked using
2904   the MEM Select Debug Service.
2905   This function is non-blocking in the interrupt mode , in that, it will exit
2906   immediately after requesting the service. In polling mode, it becomes a
2907   blocking function. It will block until the the service is completed and a
2908   response is received from the system controller.
2909 
2910   @param mb_offset
2911                     The mb_offset parameter specifies the offset from the start
2912                     of mailbox where the data related to this service is
2913                     available. All accesses to the mailbox are of word length
2914                     (4 bytes). A value 10 (decimal) of this parameter would
2915                     mean that the data access area for this service, in the
2916                     mailbox starts from 11th word (offset 10).
2917   @param resp_offset
2918                     The resp_offset parameter specifies the offset from the
2919                     start of Mailbox, where the data received from
2920                     the service will be available.
2921   @return
2922                     This function returns a value to indicate whether the
2923                     service was executed successfully or not. A zero value
2924                     indicates that the service was executed successfully. A
2925                     non-zero value can indicate that either the driver was not
2926                     able to kick-start the service or that the driver was able
2927                     to kick-start the service and receive a status response code
2928                     from the system controller.
2929                     See theory of operations section for detailed information
2930                     about the return status.
2931                     The following table lists the service status code from
2932                     system controller.
2933 
2934                      |STATUS |  Description |
2935                      |-------|--------------|
2936                      | 0     |  Success     |
2937 */
2938 uint16_t
2939 MSS_SYS_debug_terminate
2940 (
2941     uint16_t mb_offset,
2942     uint16_t resp_offset
2943 );
2944 
2945 typedef struct
2946 {
2947     volatile uint32_t SOFT_RESET;
2948     volatile uint32_t VDETECTOR;
2949     volatile uint32_t TVS_CONTROL;
2950     volatile uint32_t TVS_TEMP_A;
2951     volatile uint32_t TVS_TEMP_B;
2952     volatile uint32_t TVS_TEMP_C;
2953     volatile uint32_t TVS_VOLT_A;
2954     volatile uint32_t TVS_VOLT_B;
2955     volatile uint32_t TVS_VOLT_C;
2956     volatile uint32_t TVS_OUTPUT0;
2957     volatile uint32_t TVS_OUTPUT1;
2958     volatile uint32_t TVS_TRIGGER;
2959     volatile uint32_t TRIM_VDET1P05;
2960     volatile uint32_t TRIM_VDET1P8;
2961     volatile uint32_t TRIM_VDET2P5;
2962     volatile uint32_t TRIM_TVS;
2963     volatile uint32_t TRIM_GDET1P05;
2964     volatile uint32_t RESERVED0;
2965     volatile uint32_t RESERVED1;
2966     volatile uint32_t RESERVED2;
2967     volatile uint32_t SERVICES_CR;
2968     volatile uint32_t SERVICES_SR;
2969     volatile uint32_t USER_DETECTOR_SR;
2970     volatile uint32_t USER_DETECTOR_CR;
2971     volatile uint32_t MSS_SPI_CR;
2972 
2973 } SCBCTRL_TypeDef;
2974 
2975 #define MSS_SCBCTRL                    ((SCBCTRL_TypeDef*) (0x37020000UL))
2976 
2977 /*2kB bytes long mailbox.*/
2978 #define MSS_SCBMAILBOX                 ((uint32_t*) (0x37020800UL))
2979 
2980 /*SCB message register*/
2981 #define MSS_SCBMESSAGE                 ((uint32_t*) (0x20003190UL))
2982 
2983 /*SCB message interrupt register*/
2984 #define MSS_SCBMESSAGE_INT             ((uint32_t*) (0x2000318CUL))
2985 
2986 #ifdef __cplusplus
2987 }
2988 #endif
2989 
2990 #endif /* MSS_SYS_SERVICES_H_ */
2991