1 | /* |
---|
2 | * Dual Port Memory Manager |
---|
3 | * |
---|
4 | * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994. |
---|
5 | * On-Line Applications Research Corporation (OAR). |
---|
6 | * All rights assigned to U.S. Government, 1994. |
---|
7 | * |
---|
8 | * This material may be reproduced by or for the U.S. Government pursuant |
---|
9 | * to the copyright license under the clause at DFARS 252.227-7013. This |
---|
10 | * notice must appear in all copies of this file and its derivatives. |
---|
11 | * |
---|
12 | * $Id$ |
---|
13 | */ |
---|
14 | |
---|
15 | #include <rtems/system.h> |
---|
16 | #include <rtems/support.h> |
---|
17 | #include <rtems/address.h> |
---|
18 | #include <rtems/dpmem.h> |
---|
19 | #include <rtems/object.h> |
---|
20 | #include <rtems/thread.h> |
---|
21 | |
---|
22 | /*PAGE |
---|
23 | * |
---|
24 | * _Dual_ported_memory_Manager_initialization |
---|
25 | * |
---|
26 | * This routine initializes all dual-ported memory manager related |
---|
27 | * data structures. |
---|
28 | * |
---|
29 | * Input parameters: |
---|
30 | * maximum_ports - number of ports to initialize |
---|
31 | * |
---|
32 | * Output parameters: NONE |
---|
33 | */ |
---|
34 | |
---|
35 | void _Dual_ported_memory_Manager_initialization( |
---|
36 | unsigned32 maximum_ports |
---|
37 | ) |
---|
38 | { |
---|
39 | _Objects_Initialize_information( |
---|
40 | &_Dual_ported_memory_Information, |
---|
41 | OBJECTS_RTEMS_PORTS, |
---|
42 | FALSE, |
---|
43 | maximum_ports, |
---|
44 | sizeof( Dual_ported_memory_Control ), |
---|
45 | FALSE, |
---|
46 | RTEMS_MAXIMUM_NAME_LENGTH |
---|
47 | ); |
---|
48 | } |
---|
49 | |
---|
50 | /*PAGE |
---|
51 | * |
---|
52 | * rtems_port_create |
---|
53 | * |
---|
54 | * This directive creates a port into a dual-ported memory area. |
---|
55 | * |
---|
56 | * Input parameters: |
---|
57 | * name - user defined port name |
---|
58 | * internal_start - internal start address of port |
---|
59 | * external_start - external start address of port |
---|
60 | * length - physical length in bytes |
---|
61 | * id - address of port id to set |
---|
62 | * |
---|
63 | * Output parameters: |
---|
64 | * id - port id |
---|
65 | * RTEMS_SUCCESSFUL - if successful |
---|
66 | * error code - if unsuccessful |
---|
67 | */ |
---|
68 | |
---|
69 | rtems_status_code rtems_port_create( |
---|
70 | rtems_name name, |
---|
71 | void *internal_start, |
---|
72 | void *external_start, |
---|
73 | unsigned32 length, |
---|
74 | Objects_Id *id |
---|
75 | ) |
---|
76 | { |
---|
77 | register Dual_ported_memory_Control *the_port; |
---|
78 | |
---|
79 | if ( !rtems_is_name_valid( name) ) |
---|
80 | return ( RTEMS_INVALID_NAME ); |
---|
81 | |
---|
82 | if ( !_Addresses_Is_aligned( internal_start ) || |
---|
83 | !_Addresses_Is_aligned( external_start ) ) |
---|
84 | return( RTEMS_INVALID_ADDRESS ); |
---|
85 | |
---|
86 | _Thread_Disable_dispatch(); /* to prevent deletion */ |
---|
87 | |
---|
88 | the_port = _Dual_ported_memory_Allocate(); |
---|
89 | |
---|
90 | if ( !the_port ) { |
---|
91 | _Thread_Enable_dispatch(); |
---|
92 | return( RTEMS_TOO_MANY ); |
---|
93 | } |
---|
94 | |
---|
95 | the_port->internal_base = internal_start; |
---|
96 | the_port->external_base = external_start; |
---|
97 | the_port->length = length - 1; |
---|
98 | |
---|
99 | _Objects_Open( |
---|
100 | &_Dual_ported_memory_Information, |
---|
101 | &the_port->Object, |
---|
102 | &name |
---|
103 | ); |
---|
104 | |
---|
105 | *id = the_port->Object.id; |
---|
106 | _Thread_Enable_dispatch(); |
---|
107 | return( RTEMS_SUCCESSFUL ); |
---|
108 | } |
---|
109 | |
---|
110 | /*PAGE |
---|
111 | * |
---|
112 | * rtems_port_ident |
---|
113 | * |
---|
114 | * This directive returns the system ID associated with |
---|
115 | * the port name. |
---|
116 | * |
---|
117 | * Input parameters: |
---|
118 | * name - user defined port name |
---|
119 | * id - pointer to port id |
---|
120 | * |
---|
121 | * Output parameters: |
---|
122 | * *id - port id |
---|
123 | * RTEMS_SUCCESSFUL - if successful |
---|
124 | * error code - if unsuccessful |
---|
125 | */ |
---|
126 | |
---|
127 | rtems_status_code rtems_port_ident( |
---|
128 | rtems_name name, |
---|
129 | Objects_Id *id |
---|
130 | ) |
---|
131 | { |
---|
132 | return( |
---|
133 | _Objects_Name_to_id( |
---|
134 | &_Dual_ported_memory_Information, |
---|
135 | &name, |
---|
136 | RTEMS_SEARCH_ALL_NODES, |
---|
137 | id |
---|
138 | ) |
---|
139 | ); |
---|
140 | } |
---|
141 | |
---|
142 | /*PAGE |
---|
143 | * |
---|
144 | * rtems_port_delete |
---|
145 | * |
---|
146 | * This directive allows a thread to delete a dual-ported memory area |
---|
147 | * specified by the dual-ported memory identifier. |
---|
148 | * |
---|
149 | * Input parameters: |
---|
150 | * id - dual-ported memory area id |
---|
151 | * |
---|
152 | * Output parameters: |
---|
153 | * RTEMS_SUCCESSFUL - if successful |
---|
154 | * error code - if unsuccessful |
---|
155 | */ |
---|
156 | |
---|
157 | rtems_status_code rtems_port_delete( |
---|
158 | Objects_Id id |
---|
159 | ) |
---|
160 | { |
---|
161 | register Dual_ported_memory_Control *the_port; |
---|
162 | Objects_Locations location; |
---|
163 | |
---|
164 | the_port = _Dual_ported_memory_Get( id, &location ); |
---|
165 | switch ( location ) { |
---|
166 | case OBJECTS_ERROR: |
---|
167 | return( RTEMS_INVALID_ID ); |
---|
168 | case OBJECTS_REMOTE: /* this error cannot be returned */ |
---|
169 | return( RTEMS_INTERNAL_ERROR ); |
---|
170 | case OBJECTS_LOCAL: |
---|
171 | _Objects_Close( &_Dual_ported_memory_Information, &the_port->Object ); |
---|
172 | _Dual_ported_memory_Free( the_port ); |
---|
173 | _Thread_Enable_dispatch(); |
---|
174 | return( RTEMS_SUCCESSFUL ); |
---|
175 | } |
---|
176 | |
---|
177 | return( RTEMS_INTERNAL_ERROR ); /* unreached - only to remove warnings */ |
---|
178 | } |
---|
179 | |
---|
180 | /*PAGE |
---|
181 | * |
---|
182 | * rtems_port_internal_to_external |
---|
183 | * |
---|
184 | * This directive converts an internal dual-ported memory address to an |
---|
185 | * external dual-ported memory address. If the given internal address |
---|
186 | * is an invalid dual-ported address, then the external address is set |
---|
187 | * to the given internal address. |
---|
188 | * |
---|
189 | * Input parameters: |
---|
190 | * id - id of dual-ported memory object |
---|
191 | * internal - internal address to set |
---|
192 | * external - pointer to external address |
---|
193 | * |
---|
194 | * Output parameters: |
---|
195 | * external - external address |
---|
196 | * RTEMS_SUCCESSFUL - always succeeds |
---|
197 | */ |
---|
198 | |
---|
199 | rtems_status_code rtems_port_internal_to_external( |
---|
200 | Objects_Id id, |
---|
201 | void *internal, |
---|
202 | void **external |
---|
203 | ) |
---|
204 | { |
---|
205 | register Dual_ported_memory_Control *the_port; |
---|
206 | Objects_Locations location; |
---|
207 | unsigned32 ending; |
---|
208 | |
---|
209 | the_port = _Dual_ported_memory_Get( id, &location ); |
---|
210 | switch ( location ) { |
---|
211 | case OBJECTS_ERROR: |
---|
212 | return( RTEMS_INVALID_ID ); |
---|
213 | case OBJECTS_REMOTE: /* this error cannot be returned */ |
---|
214 | return( RTEMS_INTERNAL_ERROR ); |
---|
215 | case OBJECTS_LOCAL: |
---|
216 | ending = _Addresses_Subtract( internal, the_port->internal_base ); |
---|
217 | if ( ending > the_port->length ) |
---|
218 | *external = internal; |
---|
219 | else |
---|
220 | *external = _Addresses_Add_offset( the_port->external_base, |
---|
221 | ending ); |
---|
222 | _Thread_Enable_dispatch(); |
---|
223 | return( RTEMS_SUCCESSFUL ); |
---|
224 | } |
---|
225 | |
---|
226 | return( RTEMS_INTERNAL_ERROR ); /* unreached - only to remove warnings */ |
---|
227 | } |
---|
228 | |
---|
229 | /*PAGE |
---|
230 | * |
---|
231 | * rtems_port_external_to_internal |
---|
232 | * |
---|
233 | * This directive converts an external dual-ported memory address to an |
---|
234 | * internal dual-ported memory address. If the given external address |
---|
235 | * is an invalid dual-ported address, then the internal address is set |
---|
236 | * to the given external address. |
---|
237 | * |
---|
238 | * Input parameters: |
---|
239 | * id - id of dp memory object |
---|
240 | * external - external address |
---|
241 | * internal - pointer of internal address to set |
---|
242 | * |
---|
243 | * Output parameters: |
---|
244 | * internal - internal address |
---|
245 | * RTEMS_SUCCESSFUL - always succeeds |
---|
246 | */ |
---|
247 | |
---|
248 | rtems_status_code rtems_port_external_to_internal( |
---|
249 | Objects_Id id, |
---|
250 | void *external, |
---|
251 | void **internal |
---|
252 | ) |
---|
253 | { |
---|
254 | register Dual_ported_memory_Control *the_port; |
---|
255 | Objects_Locations location; |
---|
256 | unsigned32 ending; |
---|
257 | |
---|
258 | the_port = _Dual_ported_memory_Get( id, &location ); |
---|
259 | switch ( location ) { |
---|
260 | case OBJECTS_ERROR: |
---|
261 | return( RTEMS_INVALID_ID ); |
---|
262 | case OBJECTS_REMOTE: /* this error cannot be returned */ |
---|
263 | return( RTEMS_INTERNAL_ERROR ); |
---|
264 | case OBJECTS_LOCAL: |
---|
265 | ending = _Addresses_Subtract( external, the_port->external_base ); |
---|
266 | if ( ending > the_port->length ) |
---|
267 | *internal = external; |
---|
268 | else |
---|
269 | *internal = _Addresses_Add_offset( the_port->internal_base, |
---|
270 | ending ); |
---|
271 | _Thread_Enable_dispatch(); |
---|
272 | return( RTEMS_SUCCESSFUL ); |
---|
273 | } |
---|
274 | |
---|
275 | return( RTEMS_INTERNAL_ERROR ); /* unreached - only to remove warnings */ |
---|
276 | } |
---|