@@ -501,6 +501,10 @@ typedef struct {
501501 /* Per-client DMA buffers */
502502 uint8_t dmaKeyBuffer [KEY_DATA_SIZE ];
503503 uint8_t dmaNvmBuffer [NVM_OBJECT_DATA_SIZE ];
504+ whNvmMetadata dmaNvmMeta ;
505+ /* DMA configuration */
506+ whServerDmaConfig dmaConfig ;
507+ whServerDmaAddrAllowList dmaAllowList ;
504508#endif
505509} ClientServerPair ;
506510
@@ -654,6 +658,26 @@ static int initClientServerPair(StressTestContext* ctx, int pairIndex)
654658 pair -> serverConfig .crypto = & pair -> cryptoCtx ;
655659 pair -> serverConfig .devId = INVALID_DEVID ;
656660
661+ #ifdef WOLFHSM_CFG_DMA
662+ /* Configure DMA allow list for this pair's buffers */
663+ memset (& pair -> dmaAllowList , 0 , sizeof (pair -> dmaAllowList ));
664+ pair -> dmaAllowList .readList [0 ].addr = pair -> dmaKeyBuffer ;
665+ pair -> dmaAllowList .readList [0 ].size = sizeof (pair -> dmaKeyBuffer );
666+ pair -> dmaAllowList .readList [1 ].addr = pair -> dmaNvmBuffer ;
667+ pair -> dmaAllowList .readList [1 ].size = sizeof (pair -> dmaNvmBuffer );
668+ pair -> dmaAllowList .readList [2 ].addr = & pair -> dmaNvmMeta ;
669+ pair -> dmaAllowList .readList [2 ].size = sizeof (pair -> dmaNvmMeta );
670+
671+ pair -> dmaAllowList .writeList [0 ].addr = pair -> dmaKeyBuffer ;
672+ pair -> dmaAllowList .writeList [0 ].size = sizeof (pair -> dmaKeyBuffer );
673+ pair -> dmaAllowList .writeList [1 ].addr = pair -> dmaNvmBuffer ;
674+ pair -> dmaAllowList .writeList [1 ].size = sizeof (pair -> dmaNvmBuffer );
675+
676+ memset (& pair -> dmaConfig , 0 , sizeof (pair -> dmaConfig ));
677+ pair -> dmaConfig .dmaAddrAllowList = & pair -> dmaAllowList ;
678+ pair -> serverConfig .dmaConfig = & pair -> dmaConfig ;
679+ #endif
680+
657681 /* Initialize client in the main thread to avoid concurrent calls to
658682 * wolfCrypt_Init() and wc_CryptoCb_RegisterDevice() */
659683 rc = wh_Client_Init (& pair -> client , & pair -> clientConfig );
@@ -1191,24 +1215,24 @@ static int doKeyExportDma(ClientServerPair* pair, whKeyId keyId)
11911215
11921216static int doNvmAddObjectDma (ClientServerPair * pair , whNvmId id , int iteration )
11931217{
1194- whNvmMetadata meta ;
1195- int32_t out_rc ;
1196- int rc ;
1218+ int32_t out_rc ;
1219+ int rc ;
11971220
11981221 /* Fill DMA buffer with pattern */
11991222 memset (pair -> dmaNvmBuffer , (uint8_t )(iteration & 0xFF ),
12001223 sizeof (pair -> dmaNvmBuffer ));
12011224
1202- /* Set up metadata */
1203- memset (& meta , 0 , sizeof (meta ));
1204- meta .id = id ;
1205- meta .access = WH_NVM_ACCESS_ANY ;
1206- meta .flags = WH_NVM_FLAGS_USAGE_ANY ;
1207- meta .len = sizeof (pair -> dmaNvmBuffer );
1225+ /* Set up metadata in pair struct so address is in the DMA allow list */
1226+ memset (& pair -> dmaNvmMeta , 0 , sizeof (pair -> dmaNvmMeta ));
1227+ pair -> dmaNvmMeta .id = id ;
1228+ pair -> dmaNvmMeta .access = WH_NVM_ACCESS_ANY ;
1229+ pair -> dmaNvmMeta .flags = WH_NVM_FLAGS_USAGE_ANY ;
1230+ pair -> dmaNvmMeta .len = sizeof (pair -> dmaNvmBuffer );
12081231
12091232 /* Send DMA request */
12101233 rc = wh_Client_NvmAddObjectDmaRequest (
1211- & pair -> client , & meta , sizeof (pair -> dmaNvmBuffer ), pair -> dmaNvmBuffer );
1234+ & pair -> client , & pair -> dmaNvmMeta , sizeof (pair -> dmaNvmBuffer ),
1235+ pair -> dmaNvmBuffer );
12121236 if (rc != WH_ERROR_OK ) {
12131237 return rc ;
12141238 }
0 commit comments