@@ -12,11 +12,11 @@ Abstract:
1212
1313--*/
1414
15- use crate :: { ec_dpe_env, mldsa_dpe_env, AxiAddr , Drivers , PauserPrivileges } ;
15+ use crate :: { ec_dpe_env, mldsa_dpe_env, Drivers , PauserPrivileges } ;
1616use arrayvec:: ArrayVec ;
1717use caliptra_api:: mailbox:: {
18- populate_checksum , AxiResponseInfo , InvokeDpeMldsa87Flags , InvokeDpeMldsa87Req ,
19- MailboxReqHeader , MailboxRespHeader , SUBSYSTEM_MAILBOX_SIZE_LIMIT ,
18+ AxiResponseInfo , InvokeDpeMldsa87Flags , InvokeDpeMldsa87Req , MailboxReqHeader ,
19+ MailboxRespHeader , SUBSYSTEM_MAILBOX_SIZE_LIMIT ,
2020} ;
2121use caliptra_cfi_derive_git:: cfi_impl_fn;
2222use caliptra_common:: mailbox_api:: { InvokeDpeReq , InvokeDpeResp } ;
@@ -95,78 +95,20 @@ impl InvokeDpeCmd {
9595 . get ( ..cmd. data_size as usize )
9696 . ok_or ( CaliptraError :: RUNTIME_MAILBOX_INVALID_PARAMS ) ?;
9797
98- // External responses can only be done in subsystem mode
99- if cmd. flags . external_axi_response ( ) && !drivers. soc_ifc . subsystem_mode ( ) {
100- return Err ( CaliptraError :: RUNTIME_MAILBOX_INVALID_PARAMS ) ;
101- }
102-
10398 // Trim the response buffer to the correct size. If the response doesn't fit, it will fail
10499 // during DPE execution and not at the transport layer. This is especially important for DPE
105100 // handle rotation so the caller doesn't lose the handle.
106101 let mbox_resp = if drivers. soc_ifc . subsystem_mode ( ) {
107- let len = if cmd. flags . external_axi_response ( ) {
108- usize:: min ( mbox_resp. len ( ) , cmd. axi_response . max_size as usize )
109- } else {
110- // The mailbox size is smaller when subsystem is enabled
111- usize:: min ( mbox_resp. len ( ) , SUBSYSTEM_MAILBOX_SIZE_LIMIT )
112- } ;
102+ // The mailbox size is smaller when subsystem is enabled
103+ let len = usize:: min ( mbox_resp. len ( ) , SUBSYSTEM_MAILBOX_SIZE_LIMIT ) ;
113104 mbox_resp
114105 . get_mut ( ..len)
115106 . ok_or ( CaliptraError :: RUNTIME_INSUFFICIENT_MEMORY ) ?
116107 } else {
117108 mbox_resp
118109 } ;
119110
120- // Execute the DPE command and get the length of the response that was written
121- let len = Self :: execute ( drivers, dpe_cmd_buf, mbox_resp, CaliptraDpeProfile :: Mldsa87 ) ?;
122-
123- // We are done if the response is going over the mailbox
124- let respond_to_mailbox = !cmd. flags . external_axi_response ( ) ;
125- if respond_to_mailbox {
126- return Ok ( len) ;
127- }
128-
129- // Populate the checksum so the full response can be checked at the destination
130- // Make sure there is at least enough space for the response header
131- let len = usize:: max ( len, size_of :: < MailboxRespHeader > ( ) ) ;
132- populate_checksum (
133- mbox_resp
134- . get_mut ( ..len)
135- . ok_or ( CaliptraError :: RUNTIME_INSUFFICIENT_MEMORY ) ?,
136- ) ;
137-
138- // Get the number of words to send by rounding up to nearest word
139- let num_words = len. next_multiple_of ( 4 ) / 4 ;
140- let len = num_words * 4 ;
141- if len > cmd. axi_response . max_size as usize {
142- return Err ( CaliptraError :: RUNTIME_INSUFFICIENT_MEMORY ) ;
143- }
144-
145- // Get the buffer that will be sent over DMA. The DMA only supports sending words so we need
146- // to convert the response buffer to a &[u32].
147- let buffer = mbox_resp
148- . get ( ..len)
149- . ok_or ( CaliptraError :: RUNTIME_INSUFFICIENT_MEMORY ) ?;
150- let buffer: & [ u32 ] =
151- FromBytes :: ref_from_bytes ( buffer) . map_err ( |_| CaliptraError :: ADDRESS_MISALIGNED ) ?;
152-
153- // Send the response over DMA to the specified AXI address
154- let axi_addr = AxiAddr {
155- lo : cmd. axi_response . addr_lo ,
156- hi : cmd. axi_response . addr_hi ,
157- } ;
158- for ( i, word) in buffer. iter ( ) . enumerate ( ) {
159- drivers. dma . write_dword (
160- AxiAddr {
161- lo : axi_addr. lo + ( i as u32 * 4 ) ,
162- hi : axi_addr. hi ,
163- } ,
164- * word,
165- ) ;
166- }
167-
168- // Response is sent over DMA instead of the mailbox, so return 0 length
169- Ok ( 0 )
111+ Self :: execute ( drivers, dpe_cmd_buf, mbox_resp, CaliptraDpeProfile :: Mldsa87 )
170112 }
171113
172114 #[ cfg_attr( not( feature = "no-cfi" ) , cfi_impl_fn) ]
0 commit comments