• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
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  * Description: Provides sfc port template \n
16  *
17  * History: \n
18  * 2022-11-30, Create file. \n
19  */
20 #include "hal_sfc_v150.h"
21 #ifndef BUILD_NOOSAL
22 #include "soc_osal.h"
23 #endif
24 #include "sfc_porting.h"
25 
26 #define SFC_MCPU_START      0x200000
27 #define SFC_MCPU_END        0x9FFFFF
28 #define SFC_REG_BASE_ADDR   0x48000000
29 
30 #define SFC_DELAY_ONCE_US   100
31 #define SFC_DELAY_TIMES     50000
32 
33 uintptr_t const g_sfc_start_addr = (uintptr_t)SFC_MCPU_START;
34 
35 uintptr_t const g_sfc_end_addr = (uintptr_t)SFC_MCPU_END;
36 
37 uintptr_t const g_sfc_global_conf_base_addr = SFC_REG_BASE_ADDR + 0x100;
38 
39 uintptr_t const g_sfc_bus_regs_base_addr = SFC_REG_BASE_ADDR + 0x200;
40 
41 uintptr_t const g_sfc_bus_dma_regs_base_addr = SFC_REG_BASE_ADDR + 0x240;
42 
43 uintptr_t const g_sfc_cmd_regs_base_addr = SFC_REG_BASE_ADDR + 0x300;
44 
45 uintptr_t const g_sfc_cmd_databuf_base_addr = SFC_REG_BASE_ADDR + 0x400;
46 
47 uint32_t g_sfc_delay_once_us = SFC_DELAY_ONCE_US;
48 
49 uint32_t g_sfc_delay_times = SFC_DELAY_TIMES;
50 
51 #ifndef BUILD_NOOSAL
52 osal_mutex g_sfc_mutex = {NULL};
53 
54 bool g_sfc_mutex_inited = false;
55 #endif
56 
sfc_port_get_sfc_start_addr(void)57 uintptr_t sfc_port_get_sfc_start_addr(void)
58 {
59     return g_sfc_start_addr;
60 }
61 
sfc_port_get_sfc_end_addr(void)62 uintptr_t sfc_port_get_sfc_end_addr(void)
63 {
64     return g_sfc_end_addr;
65 }
66 
sfc_port_get_sfc_global_conf_base_addr(void)67 uintptr_t sfc_port_get_sfc_global_conf_base_addr(void)
68 {
69     return g_sfc_global_conf_base_addr;
70 }
71 
sfc_port_get_sfc_bus_regs_base_addr(void)72 uintptr_t sfc_port_get_sfc_bus_regs_base_addr(void)
73 {
74     return g_sfc_bus_regs_base_addr;
75 }
76 
sfc_port_get_sfc_bus_dma_regs_base_addr(void)77 uintptr_t sfc_port_get_sfc_bus_dma_regs_base_addr(void)
78 {
79     return g_sfc_bus_dma_regs_base_addr;
80 }
81 
sfc_port_get_sfc_cmd_regs_base_addr(void)82 uintptr_t sfc_port_get_sfc_cmd_regs_base_addr(void)
83 {
84     return g_sfc_cmd_regs_base_addr;
85 }
86 
sfc_port_get_sfc_cmd_databuf_base_addr(void)87 uintptr_t sfc_port_get_sfc_cmd_databuf_base_addr(void)
88 {
89     return g_sfc_cmd_databuf_base_addr;
90 }
91 
92 #ifdef USE_ROM_SFC
sfc_port_register_hal_funcs(void)93 void sfc_port_register_hal_funcs(void)
94 {
95     hal_sfc_register_funcs(hal_sfc_v150_funcs_get());
96 }
97 
sfc_port_unregister_hal_funcs(void)98 void sfc_port_unregister_hal_funcs(void)
99 {
100     hal_sfc_unregister_funcs();
101 }
102 #endif
103 
sfc_port_set_delay_once_time(uint32_t delay_us)104 void sfc_port_set_delay_once_time(uint32_t delay_us)
105 {
106     g_sfc_delay_once_us = delay_us;
107 }
108 
sfc_port_get_delay_once_time(void)109 uint32_t sfc_port_get_delay_once_time(void)
110 {
111     return g_sfc_delay_once_us;
112 }
113 
sfc_port_set_delay_times(uint32_t delay_times)114 void sfc_port_set_delay_times(uint32_t delay_times)
115 {
116     g_sfc_delay_times = delay_times;
117 }
118 
sfc_port_get_delay_times(void)119 uint32_t sfc_port_get_delay_times(void)
120 {
121     return g_sfc_delay_times;
122 }
123 
sfc_port_lock_init(void)124 void sfc_port_lock_init(void)
125 {
126 #ifndef BUILD_NOOSAL
127     if (!g_sfc_mutex_inited) {
128         osal_mutex_init(&g_sfc_mutex);
129         g_sfc_mutex_inited = true;
130     }
131 #endif
132 }
133 
sfc_port_lock(void)134 uint32_t sfc_port_lock(void)
135 {
136 #ifndef BUILD_NOOSAL
137     uint32_t lock_sts = osal_irq_lock();
138     return lock_sts;
139 #else
140     return 0;
141 #endif
142 }
143 
sfc_port_unlock(uint32_t lock_sts)144 void sfc_port_unlock(uint32_t lock_sts)
145 {
146 #ifndef BUILD_NOOSAL
147     osal_irq_restore(lock_sts);
148 #else
149     unused(lock_sts);
150 #endif
151 }
152 
153 #ifndef BUILD_NOOSAL
hal_sfc_get_flash_id(uint32_t * flash_id)154 errcode_t hal_sfc_get_flash_id(uint32_t *flash_id)
155 {
156     hal_sfc_funcs_t *sfc = hal_sfc_get_funcs();
157     if ((sfc == NULL) && (sfc->get_flash_id == NULL)) {
158         return ERRCODE_INVALID_PARAM;
159     }
160 
161     return sfc->get_flash_id(flash_id);
162 }
163 #endif
164 
165