blob: 0ec65932063f66203e1d0382a0aef48ac13693bd [file] [log] [blame]
developer02e65912023-08-17 16:33:10 +08001/* adapter_memxs.c
2 *
3 * Low-level Memory Access API implementation.
4 */
5
6/*****************************************************************************
7* Copyright (c) 2012-2020 by Rambus, Inc. and/or its subsidiaries.
8*
9* This program is free software: you can redistribute it and/or modify
10* it under the terms of the GNU General Public License as published by
11* the Free Software Foundation, either version 2 of the License, or
12* any later version.
13*
14* This program is distributed in the hope that it will be useful,
15* but WITHOUT ANY WARRANTY; without even the implied warranty of
16* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17* GNU General Public License for more details.
18*
19* You should have received a copy of the GNU General Public License
20* along with this program. If not, see <http://www.gnu.org/licenses/>.
21*****************************************************************************/
22
23/*----------------------------------------------------------------------------
24 * This module implements (provides) the following interface(s):
25 */
26
27// MemXS API
28#include "api_memxs.h"
29
30
31/*----------------------------------------------------------------------------
32 * This module uses (requires) the following interface(s):
33 */
34
35// Default configuration
36#include "c_adapter_memxs.h"
37
38// Driver Framework Basic Definitions API
39#include "basic_defs.h"
40
41// Driver Framework Device API
42#include "device_types.h" // Device_Handle_t
43#include "device_rw.h" // Device_Read/Write
44#include "device_mgmt.h"
45
46// Driver Framework C Run-Time Library API
47#include "clib.h" // memcmp
48
49
50/*----------------------------------------------------------------------------
51 * Definitions and macros
52 */
53
54/*----------------------------------------------------------------------------
55 * MemXS_DeviceAdmin_t
56 *
57 * MemXS device record
58 */
59typedef struct
60{
61 const char * DevName;
62
63 unsigned int FirstOfs;
64
65 unsigned int LastOfs;
66
67 Device_Handle_t MemXS_Device;
68
69} MemXS_DeviceAdmin_t;
70
71
72/*----------------------------------------------------------------------------
73 * Local variables
74 */
75
76// Here is the dependency on the Driver Framework configuration
77// via the MemXS configuration
78#ifndef HWPAL_DEVICES
79#error "Expected HWPAL_DEVICES defined by cs_memxs.h"
80#endif
81
82// Here is the dependency on the Driver Framework configuration
83// via the MemXS configuration
84#undef HWPAL_DEVICE_ADD
85#define HWPAL_DEVICE_ADD(_name, _devnr, _firstofs, _lastofs, _flags) \
86 { _name, _firstofs, _lastofs, NULL }
87
88static MemXS_DeviceAdmin_t MemXS_Devices[] =
89{
90 HWPAL_DEVICES
91};
92
93static const unsigned int MemXS_Device_Count =
94 (sizeof(MemXS_Devices) / sizeof(MemXS_DeviceAdmin_t));
95
96
97/*----------------------------------------------------------------------------
98 * MemXS_NULLHandle
99 *
100 */
101const MemXS_Handle_t MemXS_NULLHandle = { 0 };
102
103
104/*----------------------------------------------------------------------------
105 * MemXS_Init
106 */
107bool
108MemXS_Init (void)
109{
110 unsigned int i;
111
112 for(i = 0; i < MemXS_Device_Count; i++)
113 {
114 MemXS_Devices[i].MemXS_Device = NULL;
115
116 MemXS_Devices[i].MemXS_Device =
117 Device_Find (MemXS_Devices[i].DevName);
118
119 if (MemXS_Devices[i].MemXS_Device == NULL)
120 {
121 return false;
122 }
123 } // for
124
125 return true;
126}
127
128
129/*-----------------------------------------------------------------------------
130 * MemXS_Handle_IsSame
131 */
132bool
133MemXS_Handle_IsSame(
134 const MemXS_Handle_t * const Handle1_p,
135 const MemXS_Handle_t * const Handle2_p)
136{
137 return Handle1_p->p == Handle2_p->p;
138}
139
140
141/*-----------------------------------------------------------------------------
142 * MemXS_Device_Count_Get
143 */
144MemXS_Status_t
145MemXS_Device_Count_Get(
146 unsigned int * const DeviceCount_p)
147{
148 if (DeviceCount_p == NULL)
149 return MEMXS_INVALID_PARAMETER;
150
151 *DeviceCount_p = MemXS_Device_Count;
152
153 return MEMXS_STATUS_OK;
154}
155
156
157/*-----------------------------------------------------------------------------
158 * MemXS_Device_Info_Get
159 */
160MemXS_Status_t
161MemXS_Device_Info_Get(
162 const unsigned int DeviceIndex,
163 MemXS_DevInfo_t * const DeviceInfo_p)
164{
165 if (DeviceInfo_p == NULL)
166 return MEMXS_INVALID_PARAMETER;
167
168 if (DeviceIndex > MemXS_Device_Count)
169 return MEMXS_INVALID_PARAMETER;
170
171 DeviceInfo_p->Index = DeviceIndex;
172 DeviceInfo_p->Handle.p = MemXS_Devices[DeviceIndex].MemXS_Device;
173 DeviceInfo_p->Name_p = MemXS_Devices[DeviceIndex].DevName;
174 DeviceInfo_p->FirstOfs = MemXS_Devices[DeviceIndex].FirstOfs;
175 DeviceInfo_p->LastOfs = MemXS_Devices[DeviceIndex].LastOfs;
176
177 return MEMXS_STATUS_OK;
178}
179
180
181/*----------------------------------------------------------------------------
182 * MemXS_Read32
183 */
184uint32_t
185MemXS_Read32(
186 const MemXS_Handle_t Handle,
187 const unsigned int ByteOffset)
188{
189 Device_Handle_t Device = (Device_Handle_t)Handle.p;
190
191 return Device_Read32(Device, ByteOffset);
192}
193
194
195/*----------------------------------------------------------------------------
196 * MemXS_Write32
197 */
198void
199MemXS_Write32(
200 const MemXS_Handle_t Handle,
201 const unsigned int ByteOffset,
202 const uint32_t Value)
203{
204 Device_Handle_t Device = (Device_Handle_t)Handle.p;
205
206 Device_Write32(Device, ByteOffset, Value);
207}
208
209
210/*----------------------------------------------------------------------------
211 * MemXS_Read32Array
212 */
213void
214MemXS_Read32Array(
215 const MemXS_Handle_t Handle,
216 const unsigned int ByteOffset,
217 uint32_t * MemoryDst_p,
218 const int Count)
219{
220 Device_Handle_t Device = (Device_Handle_t)Handle.p;
221
222 Device_Read32Array(Device, ByteOffset, MemoryDst_p, Count);
223}
224
225
226/*----------------------------------------------------------------------------
227 * MemXS_Write32Array
228 */
229void
230MemXS_Write32Array(
231 const MemXS_Handle_t Handle,
232 const unsigned int ByteOffset,
233 const uint32_t * MemorySrc_p,
234 const int Count)
235{
236 Device_Handle_t Device = (Device_Handle_t)Handle.p;
237
238 Device_Write32Array(Device, ByteOffset, MemorySrc_p, Count);
239}
240
241
242/* end of file adapter_memxs.c */