• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #include "plat_addr_map.h"
16 #include "hal_cmu.h"
17 #include "hal_location.h"
18 #include "hal_memsc.h"
19 
20 #ifdef CHIP_SUBSYS_SENS
21 #include CHIP_SPECIFIC_HDR(reg_senscmu)
22 
23 static struct SENSCMU_T * const cmu = (struct SENSCMU_T *)SENS_CMU_BASE;
24 #else
25 #include CHIP_SPECIFIC_HDR(reg_cmu)
26 
27 static struct CMU_T * const cmu = (struct CMU_T *)CMU_BASE;
28 #endif
29 
hal_memsc_lock(enum HAL_MEMSC_ID_T id)30 int hal_memsc_lock(enum HAL_MEMSC_ID_T id)
31 {
32     if (id >= ARRAY_SIZE(cmu->MEMSC)) {
33         return 0;
34     }
35 
36     return cmu->MEMSC[id];
37 }
38 
hal_memsc_unlock(enum HAL_MEMSC_ID_T id)39 void hal_memsc_unlock(enum HAL_MEMSC_ID_T id)
40 {
41     if (id >= ARRAY_SIZE(cmu->MEMSC)) {
42         return;
43     }
44 
45     cmu->MEMSC[id] = 1;
46 }
47 
hal_memsc_avail(enum HAL_MEMSC_ID_T id)48 bool hal_memsc_avail(enum HAL_MEMSC_ID_T id)
49 {
50     if (id >= ARRAY_SIZE(cmu->MEMSC)) {
51         return false;
52     }
53 
54     return !!(cmu->MEMSC_STATUS & (1 << id));
55 }
56 
57 #ifdef AON_CMU_BASE
58 #include CHIP_SPECIFIC_HDR(reg_aoncmu)
59 
60 static struct AONCMU_T * const aoncmu = (struct AONCMU_T *)AON_CMU_BASE;
61 
hal_memsc_aon_lock(enum HAL_MEMSC_AON_ID_T id)62 int BOOT_TEXT_SRAM_LOC hal_memsc_aon_lock(enum HAL_MEMSC_AON_ID_T id)
63 {
64     if (id >= ARRAY_SIZE(aoncmu->MEMSC)) {
65         return 0;
66     }
67 
68     return aoncmu->MEMSC[id];
69 }
70 
hal_memsc_aon_unlock(enum HAL_MEMSC_AON_ID_T id)71 void BOOT_TEXT_SRAM_LOC hal_memsc_aon_unlock(enum HAL_MEMSC_AON_ID_T id)
72 {
73     if (id >= ARRAY_SIZE(aoncmu->MEMSC)) {
74         return;
75     }
76 
77     aoncmu->MEMSC[id] = 1;
78 }
79 
hal_memsc_aon_avail(enum HAL_MEMSC_AON_ID_T id)80 bool hal_memsc_aon_avail(enum HAL_MEMSC_AON_ID_T id)
81 {
82     if (id >= ARRAY_SIZE(aoncmu->MEMSC)) {
83         return false;
84     }
85 
86     return !!(aoncmu->MEMSC_STATUS & (1 << id));
87 }
88 #endif
89 
90