Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris...
[sfrench/cifs-2.6.git] / drivers / staging / epl / EplApiProcessImage.c
1 /****************************************************************************
2
3   (c) SYSTEC electronic GmbH, D-07973 Greiz, August-Bebel-Str. 29
4       www.systec-electronic.com
5
6   Project:      openPOWERLINK
7
8   Description:  source file for EPL API module (process image)
9
10   License:
11
12     Redistribution and use in source and binary forms, with or without
13     modification, are permitted provided that the following conditions
14     are met:
15
16     1. Redistributions of source code must retain the above copyright
17        notice, this list of conditions and the following disclaimer.
18
19     2. Redistributions in binary form must reproduce the above copyright
20        notice, this list of conditions and the following disclaimer in the
21        documentation and/or other materials provided with the distribution.
22
23     3. Neither the name of SYSTEC electronic GmbH nor the names of its
24        contributors may be used to endorse or promote products derived
25        from this software without prior written permission. For written
26        permission, please contact info@systec-electronic.com.
27
28     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29     "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30     LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
31     FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
32     COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
33     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
34     BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
35     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
36     CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37     LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
38     ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39     POSSIBILITY OF SUCH DAMAGE.
40
41     Severability Clause:
42
43         If a provision of this License is or becomes illegal, invalid or
44         unenforceable in any jurisdiction, that shall not affect:
45         1. the validity or enforceability in that jurisdiction of any other
46            provision of this License; or
47         2. the validity or enforceability in other jurisdictions of that or
48            any other provision of this License.
49
50   -------------------------------------------------------------------------
51
52                 $RCSfile: EplApiProcessImage.c,v $
53
54                 $Author: D.Krueger $
55
56                 $Revision: 1.7 $  $Date: 2008/11/13 17:13:09 $
57
58                 $State: Exp $
59
60                 Build Environment:
61                     GCC V3.4
62
63   -------------------------------------------------------------------------
64
65   Revision History:
66
67   2006/10/10 d.k.:   start of the implementation, version 1.00
68
69 ****************************************************************************/
70
71 #include "Epl.h"
72 //#include "kernel/EplPdokCal.h"
73
74 #if (TARGET_SYSTEM == _LINUX_) && defined(__KERNEL__)
75 #include <asm/uaccess.h>
76 #endif
77
78 /***************************************************************************/
79 /*                                                                         */
80 /*                                                                         */
81 /*          G L O B A L   D E F I N I T I O N S                            */
82 /*                                                                         */
83 /*                                                                         */
84 /***************************************************************************/
85
86 //---------------------------------------------------------------------------
87 // const defines
88 //---------------------------------------------------------------------------
89
90 //---------------------------------------------------------------------------
91 // local types
92 //---------------------------------------------------------------------------
93
94 //---------------------------------------------------------------------------
95 // modul globale vars
96 //---------------------------------------------------------------------------
97
98 //---------------------------------------------------------------------------
99 // local function prototypes
100 //---------------------------------------------------------------------------
101
102 /***************************************************************************/
103 /*                                                                         */
104 /*                                                                         */
105 /*          C L A S S  EplApi                                              */
106 /*                                                                         */
107 /*                                                                         */
108 /***************************************************************************/
109 //
110 // Description:
111 //
112 //
113 /***************************************************************************/
114
115 //=========================================================================//
116 //                                                                         //
117 //          P R I V A T E   D E F I N I T I O N S                          //
118 //                                                                         //
119 //=========================================================================//
120
121 //---------------------------------------------------------------------------
122 // const defines
123 //---------------------------------------------------------------------------
124
125 //---------------------------------------------------------------------------
126 // local types
127 //---------------------------------------------------------------------------
128
129 #if ((EPL_API_PROCESS_IMAGE_SIZE_IN > 0) || (EPL_API_PROCESS_IMAGE_SIZE_OUT > 0))
130 typedef struct {
131 #if EPL_API_PROCESS_IMAGE_SIZE_IN > 0
132         BYTE m_abProcessImageInput[EPL_API_PROCESS_IMAGE_SIZE_IN];
133 #endif
134 #if EPL_API_PROCESS_IMAGE_SIZE_OUT > 0
135         BYTE m_abProcessImageOutput[EPL_API_PROCESS_IMAGE_SIZE_OUT];
136 #endif
137
138 } tEplApiProcessImageInstance;
139
140 //---------------------------------------------------------------------------
141 // local vars
142 //---------------------------------------------------------------------------
143
144 static tEplApiProcessImageInstance EplApiProcessImageInstance_g;
145 #endif
146
147 //---------------------------------------------------------------------------
148 // local function prototypes
149 //---------------------------------------------------------------------------
150
151 //=========================================================================//
152 //                                                                         //
153 //          P U B L I C   F U N C T I O N S                                //
154 //                                                                         //
155 //=========================================================================//
156
157 //---------------------------------------------------------------------------
158 //
159 // Function:    EplApiProcessImageSetup()
160 //
161 // Description: sets up static process image
162 //
163 // Parameters:  (none)
164 //
165 // Returns:     tEplKernel              = error code
166 //
167 //
168 // State:
169 //
170 //---------------------------------------------------------------------------
171
172 tEplKernel PUBLIC EplApiProcessImageSetup(void)
173 {
174         tEplKernel Ret = kEplSuccessful;
175 #if ((EPL_API_PROCESS_IMAGE_SIZE_IN > 0) || (EPL_API_PROCESS_IMAGE_SIZE_OUT > 0))
176         unsigned int uiVarEntries;
177         tEplObdSize ObdSize;
178 #endif
179
180 #if EPL_API_PROCESS_IMAGE_SIZE_IN > 0
181         uiVarEntries = EPL_API_PROCESS_IMAGE_SIZE_IN;
182         ObdSize = 1;
183         Ret = EplApiLinkObject(0x2000,
184                                EplApiProcessImageInstance_g.
185                                m_abProcessImageInput, &uiVarEntries, &ObdSize,
186                                1);
187
188         uiVarEntries = EPL_API_PROCESS_IMAGE_SIZE_IN;
189         ObdSize = 1;
190         Ret = EplApiLinkObject(0x2001,
191                                EplApiProcessImageInstance_g.
192                                m_abProcessImageInput, &uiVarEntries, &ObdSize,
193                                1);
194
195         ObdSize = 2;
196         uiVarEntries = EPL_API_PROCESS_IMAGE_SIZE_IN / ObdSize;
197         Ret = EplApiLinkObject(0x2010,
198                                EplApiProcessImageInstance_g.
199                                m_abProcessImageInput, &uiVarEntries, &ObdSize,
200                                1);
201
202         ObdSize = 2;
203         uiVarEntries = EPL_API_PROCESS_IMAGE_SIZE_IN / ObdSize;
204         Ret = EplApiLinkObject(0x2011,
205                                EplApiProcessImageInstance_g.
206                                m_abProcessImageInput, &uiVarEntries, &ObdSize,
207                                1);
208
209         ObdSize = 4;
210         uiVarEntries = EPL_API_PROCESS_IMAGE_SIZE_IN / ObdSize;
211         Ret = EplApiLinkObject(0x2020,
212                                EplApiProcessImageInstance_g.
213                                m_abProcessImageInput, &uiVarEntries, &ObdSize,
214                                1);
215
216         ObdSize = 4;
217         uiVarEntries = EPL_API_PROCESS_IMAGE_SIZE_IN / ObdSize;
218         Ret = EplApiLinkObject(0x2021,
219                                EplApiProcessImageInstance_g.
220                                m_abProcessImageInput, &uiVarEntries, &ObdSize,
221                                1);
222 #endif
223
224 #if EPL_API_PROCESS_IMAGE_SIZE_OUT > 0
225         uiVarEntries = EPL_API_PROCESS_IMAGE_SIZE_OUT;
226         ObdSize = 1;
227         Ret = EplApiLinkObject(0x2030,
228                                EplApiProcessImageInstance_g.
229                                m_abProcessImageOutput, &uiVarEntries, &ObdSize,
230                                1);
231
232         uiVarEntries = EPL_API_PROCESS_IMAGE_SIZE_OUT;
233         ObdSize = 1;
234         Ret = EplApiLinkObject(0x2031,
235                                EplApiProcessImageInstance_g.
236                                m_abProcessImageOutput, &uiVarEntries, &ObdSize,
237                                1);
238
239         ObdSize = 2;
240         uiVarEntries = EPL_API_PROCESS_IMAGE_SIZE_OUT / ObdSize;
241         Ret = EplApiLinkObject(0x2040,
242                                EplApiProcessImageInstance_g.
243                                m_abProcessImageOutput, &uiVarEntries, &ObdSize,
244                                1);
245
246         ObdSize = 2;
247         uiVarEntries = EPL_API_PROCESS_IMAGE_SIZE_OUT / ObdSize;
248         Ret = EplApiLinkObject(0x2041,
249                                EplApiProcessImageInstance_g.
250                                m_abProcessImageOutput, &uiVarEntries, &ObdSize,
251                                1);
252
253         ObdSize = 4;
254         uiVarEntries = EPL_API_PROCESS_IMAGE_SIZE_OUT / ObdSize;
255         Ret = EplApiLinkObject(0x2050,
256                                EplApiProcessImageInstance_g.
257                                m_abProcessImageOutput, &uiVarEntries, &ObdSize,
258                                1);
259
260         ObdSize = 4;
261         uiVarEntries = EPL_API_PROCESS_IMAGE_SIZE_OUT / ObdSize;
262         Ret = EplApiLinkObject(0x2051,
263                                EplApiProcessImageInstance_g.
264                                m_abProcessImageOutput, &uiVarEntries, &ObdSize,
265                                1);
266 #endif
267
268         return Ret;
269 }
270
271 //----------------------------------------------------------------------------
272 // Function:    EplApiProcessImageExchangeIn()
273 //
274 // Description: replaces passed input process image with the one of EPL stack
275 //
276 // Parameters:  pPI_p                   = input process image
277 //
278 // Returns:     tEplKernel              = error code
279 //
280 // State:
281 //----------------------------------------------------------------------------
282
283 tEplKernel PUBLIC EplApiProcessImageExchangeIn(tEplApiProcessImage * pPI_p)
284 {
285         tEplKernel Ret = kEplSuccessful;
286
287 #if EPL_API_PROCESS_IMAGE_SIZE_IN > 0
288 #if (TARGET_SYSTEM == _LINUX_) && defined(__KERNEL__)
289         copy_to_user(pPI_p->m_pImage,
290                      EplApiProcessImageInstance_g.m_abProcessImageInput,
291                      min(pPI_p->m_uiSize,
292                          sizeof(EplApiProcessImageInstance_g.
293                                 m_abProcessImageInput)));
294 #else
295         EPL_MEMCPY(pPI_p->m_pImage,
296                    EplApiProcessImageInstance_g.m_abProcessImageInput,
297                    min(pPI_p->m_uiSize,
298                        sizeof(EplApiProcessImageInstance_g.
299                               m_abProcessImageInput)));
300 #endif
301 #endif
302
303         return Ret;
304 }
305
306 //----------------------------------------------------------------------------
307 // Function:    EplApiProcessImageExchangeOut()
308 //
309 // Description: copies passed output process image to EPL stack.
310 //
311 // Parameters:  pPI_p                   = output process image
312 //
313 // Returns:     tEplKernel              = error code
314 //
315 // State:
316 //----------------------------------------------------------------------------
317
318 tEplKernel PUBLIC EplApiProcessImageExchangeOut(tEplApiProcessImage * pPI_p)
319 {
320         tEplKernel Ret = kEplSuccessful;
321
322 #if EPL_API_PROCESS_IMAGE_SIZE_OUT > 0
323 #if (TARGET_SYSTEM == _LINUX_) && defined(__KERNEL__)
324         copy_from_user(EplApiProcessImageInstance_g.m_abProcessImageOutput,
325                        pPI_p->m_pImage,
326                        min(pPI_p->m_uiSize,
327                            sizeof(EplApiProcessImageInstance_g.
328                                   m_abProcessImageOutput)));
329 #else
330         EPL_MEMCPY(EplApiProcessImageInstance_g.m_abProcessImageOutput,
331                    pPI_p->m_pImage,
332                    min(pPI_p->m_uiSize,
333                        sizeof(EplApiProcessImageInstance_g.
334                               m_abProcessImageOutput)));
335 #endif
336 #endif
337
338         return Ret;
339 }
340
341 //=========================================================================//
342 //                                                                         //
343 //          P R I V A T E   F U N C T I O N S                              //
344 //                                                                         //
345 //=========================================================================//
346
347 // EOF