1515 * limitations under the License.
1616**/
1717
18- #include "val/include/ acs_val.h"
19- #include "val/include/ acs_pe.h"
20- #include "val/include/ acs_mpam.h"
21- #include "val/include/ acs_memory.h"
22- #include "val/include/ val_interface.h"
18+ #include "acs_val.h"
19+ #include "acs_pe.h"
20+ #include "acs_mpam.h"
21+ #include "acs_memory.h"
22+ #include "val_interface.h"
2323
2424#define TEST_NUM ACS_MPAM_CACHE_TEST_NUM_BASE + 25
2525#define TEST_RULE ""
@@ -47,7 +47,7 @@ Value B < Value A: confirms that the disabled PARTID was deprioritized or blocke
4747If both conditions hold, the test is passed.
4848*/
4949
50- #define BUFFER_SIZE 0x6400000 /* 100 MB */
50+ #define BUFFER_SIZE 0x100000 /* 1MB */
5151#define NUM_SCENARIOS 3
5252
5353static void
@@ -173,6 +173,10 @@ payload(void)
173173 if ((src_buf == NULL ) || (dest_buf == NULL )) {
174174 val_print (ACS_PRINT_ERR , "\n Mem allocation failed" , 0 );
175175 val_set_status (index , RESULT_FAIL (TEST_NUM , 01 ));
176+ if (dest_buf != NULL )
177+ val_memory_free_aligned (dest_buf );
178+ if (src_buf != NULL )
179+ val_memory_free_aligned (src_buf );
176180 return ;
177181 }
178182
@@ -212,6 +216,8 @@ payload(void)
212216
213217 /* Step 5: Start mem copy */
214218 val_memcpy (src_buf , dest_buf , BUFFER_SIZE );
219+ /* Wait for some time before the memcpy settles and counters update */
220+ val_time_delay_ms (TIMEOUT_MEDIUM );
215221
216222 /* Read CSU monitor cnt - number of cache lines filled by PARTID_X at this point */
217223 end_count = val_mpam_read_csumon (msc_index );
@@ -231,6 +237,11 @@ payload(void)
231237 goto cleanup ;
232238 }
233239
240+ /* Invalidate the caches before next scenario */
241+ val_pe_cache_invalidate_range ((uint64_t )src_buf , BUFFER_SIZE );
242+ val_pe_cache_invalidate_range ((uint64_t )dest_buf , BUFFER_SIZE );
243+ val_mem_issue_dsb ();
244+
234245 /* Step 7: Disable PARTID_X. MPAMCFG_DIS.PARTID = PARTID_X.
235246 Do not set NFU. We need the PARTID later */
236247 status = val_mpam_msc_endis_partid (msc_index , 0 , 0 , partid_x );
@@ -253,6 +264,10 @@ payload(void)
253264 if (status ) {
254265 val_print (ACS_PRINT_ERR , "\n MPAM2_EL2 programming failed" , 0 );
255266 /* Free the buffers to the heap manager */
267+ val_pe_cache_invalidate_range ((uint64_t )src_buf , BUFFER_SIZE );
268+ val_pe_cache_invalidate_range ((uint64_t )dest_buf , BUFFER_SIZE );
269+ val_mem_issue_dsb ();
270+
256271 val_memory_free_aligned (src_buf );
257272 val_memory_free_aligned (dest_buf );
258273 val_set_status (index , RESULT_FAIL (TEST_NUM , 03 ));
@@ -269,6 +284,8 @@ payload(void)
269284 };
270285
271286 val_memcpy (src_buf , dest_buf , BUFFER_SIZE );
287+ /* Wait for some time before the memcpy settles and counters update */
288+ val_time_delay_ms (TIMEOUT_MEDIUM );
272289
273290 /* Step 9 */
274291 end_count = val_mpam_read_csumon (msc_index );
@@ -290,6 +307,10 @@ payload(void)
290307 goto cleanup ;
291308 }
292309
310+ val_pe_cache_invalidate_range ((uint64_t )src_buf , BUFFER_SIZE );
311+ val_pe_cache_invalidate_range ((uint64_t )dest_buf , BUFFER_SIZE );
312+ val_mem_issue_dsb ();
313+
293314 /* Step 11: Enable PARTID_X and Disable PARTID_Y. H/w must remember PARTID_X config */
294315 status = val_mpam_msc_endis_partid (msc_index , 1 , 0 , partid_x );
295316 status |= val_mpam_msc_endis_partid (msc_index , 0 , 0 , partid_y );
@@ -304,6 +325,10 @@ payload(void)
304325 if (status ) {
305326 val_print (ACS_PRINT_ERR , "\n MPAM2_EL2 programming failed" , 0 );
306327 /* Free the buffers to the heap manager */
328+ val_pe_cache_invalidate_range ((uint64_t )src_buf , BUFFER_SIZE );
329+ val_pe_cache_invalidate_range ((uint64_t )dest_buf , BUFFER_SIZE );
330+ val_mem_issue_dsb ();
331+
307332 val_memory_free_aligned (src_buf );
308333 val_memory_free_aligned (dest_buf );
309334 val_set_status (index , RESULT_FAIL (TEST_NUM , 04 ));
@@ -323,6 +348,8 @@ payload(void)
323348 };
324349
325350 val_memcpy (src_buf , dest_buf , BUFFER_SIZE );
351+ /* Wait for some time before the memcpy settles and counters update */
352+ val_time_delay_ms (TIMEOUT_MEDIUM );
326353
327354 end_count = val_mpam_read_csumon (msc_index );
328355
@@ -347,6 +374,10 @@ payload(void)
347374 val_mpam_reg_write (MPAM2_EL2 , saved_el2 );
348375
349376 /* Free the buffers to the heap manager */
377+ val_pe_cache_invalidate_range ((uint64_t )src_buf , BUFFER_SIZE );
378+ val_pe_cache_invalidate_range ((uint64_t )dest_buf , BUFFER_SIZE );
379+ val_mem_issue_dsb ();
380+
350381 val_memory_free_aligned (src_buf );
351382 val_memory_free_aligned (dest_buf );
352383 }
0 commit comments