]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/pdk.git/blob - packages/ti/diag/sdr/test/sdtf-test/src/j721e_evm/r5f/baremetal/sdtf_rat.c
c46fd8f82a0f3d986c9e2aa29a3d6e0b81034375
[processor-sdk/pdk.git] / packages / ti / diag / sdr / test / sdtf-test / src / j721e_evm / r5f / baremetal / sdtf_rat.c
1 /*
2  * SDTF RAT
3  *
4  * Software Diagnostics Reference Test for RAT module
5  *
6  *  Copyright (c) Texas Instruments Incorporated 2019-2020
7  *
8  *  Redistribution and use in source and binary forms, with or without
9  *  modification, are permitted provided that the following conditions
10  *  are met:
11  *
12  *    Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  *
15  *    Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the
18  *    distribution.
19  *
20  *    Neither the name of Texas Instruments Incorporated nor the names of
21  *    its contributors may be used to endorse or promote products derived
22  *    from this software without specific prior written permission.
23  *
24  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
27  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
28  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35  *
36  */
38 #include <stdint.h>
39 #include <ti/csl/csl_rat.h>
41 #include "sdtf_common.h"
42 #include "sdtf_profile.h"
43 #include "sdtf_test.h"
44 #include "sdtf_rat.h"
46 /* Choosing unused address space */
47 #define SDTF_RAT_SELF_TEST_TRANSLATE_BASE  (0x10000000U)
49 #pragma DATA_SECTION (SDTF_RATTestArray, ".sdtf_rat_testsection");
50 #pragma DATA_ALIGN (SDTF_RATTestArray, 32);
51 uint32_t SDTF_RATTestArray[8];
53 #define SDTF_RAT_REGION_INDEX 0
55 /*********************************************************************
56  *
57  * \brief Test RAT module
58  *
59  *
60  * \return 0 if test pass, -1 in case of failure
61  */
62 int32_t SDTF_runtestRAT(void)
63 {
64     int32_t retValue=0;
65     CSL_RatTranslationCfgInfo translationCfg;
67     SDTF_printf("\n RAT Test: starting");
69     translationCfg.translatedAddress = ((uint64_t)&SDTF_RATTestArray);
70     translationCfg.sizeInBytes = sizeof(SDTF_RATTestArray);
71     translationCfg.baseAddress = (uint32_t)SDTF_RAT_SELF_TEST_TRANSLATE_BASE;
73     SDTF_profileBegin(SDTF_PROFILE_ONESHOT);
74     retValue = SDTF_RATSelfTest(SDTF_RAT_REGION_INDEX, &translationCfg, &SDTF_RATTestArray[0]);
76     SDTF_profileEnd(SDTF_PROFILE_ONESHOT);
77     if (retValue != 0 ) {
78         SDTF_printf("\n RAT Test failed");
79     } else {
80         SDTF_printf("\n RAT Test  complete");
81         SDTF_printf("\n Cycles taken %u", SDTF_profileDelta(SDTF_PROFILE_ONESHOT));
82     }
84     return retValue;
86 }
87 /*********************************************************************
88  *
89  * \brief Self test for RAT module
90  * Note: This function assumes both the mapped and translated addresses are accessible directly
91  * for the self test
92  * Note: The values in the region may be overwritten
93  *
94  * \param regionIndex: RAT region index to be used for the test
95  * \param pTranslateCfg: Pointer to translation configuration for
96  *                       the RAT mapping
97  * \param pTestMemArea: Test memory area for doing the RAT region mapping
98  *
99  * \return 0 if test pass, -1 in case of failure
100  */
101 /* Note this function assumes both the mapped and translated addresses are accessible directly
102  * for the self test
103  * Note: The values in the region may be overwritten
104  */
105 int32_t SDTF_RATSelfTest(uint32_t regionIndex, CSL_RatTranslationCfgInfo *pTranslationCfg,
106                          uint32_t *pTestMemArea)
108     int32_t retValue=0;
109     int32_t cslStatus;
110     bool result;
111     CSL_ratRegs *pRatRegs = (CSL_ratRegs *)CSL_MCU_ARMSS_RAT_CFG_BASE;
112     uint32_t *pMappedBase;
114     /* The assumption is that the tranlated Address is accessible directly as well
115      * for Self test to work.
116      */
117     if ((pTranslationCfg->translatedAddress > (uint64_t)0xffffffffu)
118             && (pTranslationCfg->translatedAddress != (uint64_t)pTestMemArea)){
119         retValue = -1;
120     }
122     if (retValue == 0) {
123         /* Write a value to RAT region */
124         pTestMemArea[0] = 0xbabeface;
126         /* Set up RAT translation */
127         result = CSL_ratConfigRegionTranslation(pRatRegs, regionIndex, pTranslationCfg);
128         if(result == false) {
129             retValue = -1;
130         }
131     }
133     if (retValue == 0) {
134         /* Verify RAT configuration */
135         cslStatus = CSL_ratVerifyConfigRegionTranslation(pRatRegs, regionIndex, pTranslationCfg);
136         if (cslStatus != CSL_PASS) {
137             retValue = -1;
138         }
139     }
141     if (retValue == 0) {
142         /* Now write another value to test area */
143         pTestMemArea[1] = 0xaaaa5555;
145         pMappedBase = ((uint32_t *)(SDTF_RAT_SELF_TEST_TRANSLATE_BASE));
147         /* Check the first written value */
148         if (pMappedBase[0] != pTestMemArea[0]) {
149             retValue = -1;
150         }
151     }
153     if (retValue == 0) {
155         /* Check second value written after RAT configuration */
156         if (pMappedBase[1] != pTestMemArea[1]) {
157             retValue = -1;
158         }
159     }
161     if (retValue == 0) {
163         /* Write a value to mapped region */
164         pMappedBase[2] = 0x5555aaaa;
165         /* Check third write to mapped area */
166         if (pMappedBase[1] != pTestMemArea[1]) {
167             retValue = -1;
168         }
169     }
171     /* Disable RAT region */
172     CSL_ratDisableRegionTranslation(pRatRegs, regionIndex);
174     return retValue;