source: svn/newcon3bcm2_21bu/nexus/build/tools/ipcthunk/bapi_common.pm

Last change on this file was 76, checked in by megakiss, 10 years ago

1W 대기전력을 만족시키기 위하여 POWEROFF시 튜너를 Standby 상태로 함

  • Property svn:executable set to *
File size: 30.1 KB
Line 
1#!/usr/bin/perl
2#     (c)2003-2011 Broadcom Corporation
3#
4#  This program is the proprietary software of Broadcom Corporation and/or its licensors,
5#  and may only be used, duplicated, modified or distributed pursuant to the terms and
6#  conditions of a separate, written license agreement executed between you and Broadcom
7#  (an "Authorized License").  Except as set forth in an Authorized License, Broadcom grants
8#  no license (express or implied), right to use, or waiver of any kind with respect to the
9#  Software, and Broadcom expressly reserves all rights in and to the Software and all
10#  intellectual property rights therein.  IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU
11#  HAVE NO RIGHT TO USE THIS SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY
12#  NOTIFY BROADCOM AND DISCONTINUE ALL USE OF THE SOFTWARE.
13#
14#  Except as expressly set forth in the Authorized License,
15#
16#  1.     This program, including its structure, sequence and organization, constitutes the valuable trade
17#  secrets of Broadcom, and you shall use all reasonable efforts to protect the confidentiality thereof,
18#  and to use this information only in connection with your use of Broadcom integrated circuit products.
19#
20#  2.     TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
21#  AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, REPRESENTATIONS OR
22#  WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO
23#  THE SOFTWARE.  BROADCOM SPECIFICALLY DISCLAIMS ANY AND ALL IMPLIED WARRANTIES
24#  OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE,
25#  LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION
26#  OR CORRESPONDENCE TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT OF
27#  USE OR PERFORMANCE OF THE SOFTWARE.
28#
29#  3.     TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR ITS
30#  LICENSORS BE LIABLE FOR (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, INDIRECT, OR
31#  EXEMPLARY DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY WAY RELATING TO YOUR
32#  USE OF OR INABILITY TO USE THE SOFTWARE EVEN IF BROADCOM HAS BEEN ADVISED OF
33#  THE POSSIBILITY OF SUCH DAMAGES; OR (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT
34#  ACTUALLY PAID FOR THE SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE
35#  LIMITATIONS SHALL APPLY NOTWITHSTANDING ANY FAILURE OF ESSENTIAL PURPOSE OF
36#  ANY LIMITED REMEDY.
37#
38# $brcm_Workfile: bapi_common.pm $
39# $brcm_Revision: 24 $
40# $brcm_Date: 12/7/11 10:41a $
41#
42# File Description:
43#
44# Revision History:
45#
46# $brcm_Log: /nexus/build/tools/ipcthunk/bapi_common.pm $
47#
48# 24   12/7/11 10:41a erickson
49# SW7420-2141: merge as much duplicated kernelmode proxy/usermode ipc
50#  perl code as possible
51#
52# 23   11/29/11 11:31a erickson
53# SW7420-2129: remove null_allowed=trusted attribute
54#
55# 22   11/7/11 3:59p bandrews
56# SW7231-446: merge to main
57#
58# SW7231-446/2   11/4/11 9:44p bandrews
59# SW7231-446: fix based on review
60#
61# SW7231-446/1   11/3/11 7:55p bandrews
62# SW7231-446: implemented
63#
64# 21   9/13/11 1:23p erickson
65# SW7420-1148: change client modes to unprotected/protected/untrusted
66#
67# 20   8/30/11 9:10a erickson
68# SW7420-1991: fix conversion of input params
69#
70# 19   7/29/11 12:11p erickson
71# SW7420-1991: fix nelem,nelem_out attribute support, reorganize to be
72#  closer to kernelproxy/bapi_common.pm layout
73#
74# 19   7/29/11 12:10p erickson
75# SW7420-1991: fix nelem,nelem_out attribute support, reorganize to be
76#  closer to kernelproxy/bapi_common.pm layout
77#
78# 18   7/28/11 3:28p erickson
79# SW7425-1029: fix NEXUS_CallbackDesc proxy for functions with enums, not
80#  handles
81#
82# 17   7/26/11 12:07p erickson
83# SW7420-1992: callback database must take client id so that callbacks
84#  can be disconnected when a client releases
85#
86# 15   7/12/11 1:26p erickson
87# SW7420-1979: add support for new shutdown attribute
88#
89# 14   5/13/11 12:18p erickson
90# SW7420-1873: remove shutdown attribute
91#
92# 13   4/18/11 1:48p erickson
93# SW7420-1123: use void* for intermediate device offset to avoid strict
94#  aliasing warnings
95#
96# 12   4/14/11 11:59a erickson
97# SW7420-1679: clean up NEXUS_Memory_Allocate using
98#  attr{dealloc=NEXUS_Memory_Free}
99#
100# 11   3/17/11 11:59a erickson
101# SW7346-101: fix NEXUS_StopCallbacks for secondary destructors
102#  (specifically, NEXUS_Playpump_ClosePidChannel)
103#
104# 10   3/1/11 9:31a erickson
105# SW7420-1123: add skip_thunk to centralize test for filenames that
106#  should not be thunked
107#
108# 9   2/28/11 3:27p erickson
109# SW7420-1123: add nelem_convert attribute support
110#
111# 8   2/16/11 4:00p erickson
112# SW7420-1507: fix callback registration in Open functions
113#
114# 7   2/16/11 2:17p erickson
115# SW7420-1123: implement nelem/nelem_out for IPC thunk
116#
117# 6   2/15/11 2:28p erickson
118# SW7420-1123: refactor IPC thunk to separate in/out params
119#
120# 5   2/9/11 11:43a erickson
121# SW7420-1441: support attr{local=true}
122#
123# 4   1/28/11 9:04a erickson
124# SW7420-1440: refactor secondary_destructor
125#
126# 3   1/27/11 3:05p erickson
127# SW7208-152: fix and standardize get_destructor_hash
128#
129# 2   1/19/11 2:03p erickson
130# SW7420-1123: socket-based usermode IPC
131#
132# 1   9/29/10 9:34a erickson
133# SW7420-1123: add linux usermode IPC
134#
135#############################################################################
136use strict;
137use bapi_util;
138
139package bapi_common;
140
141sub version_value
142{
143    my $version = shift;
144    sprintf " 0x%08Xul ", ($version & 0xFFFFFFFF);
145}
146
147sub version_ipc
148{
149    my $module = shift;
150    return "B_IPC_${module}_NEXUS_INIT";
151}
152
153sub version_define
154{
155    my $module = shift;
156    return "NEXUS_${module}_MODULE_VERSION";
157}
158
159sub ipc_name
160{
161    my $module = uc shift;
162    my $func = shift;
163
164    return "B_IPC_${module}_$func->{FUNCNAME}";
165}
166
167sub ipc_struct
168{
169    my $module = uc shift;
170    my $func = shift;
171    return "B_IPC_${module}_$func->{FUNCNAME}_data";
172}
173
174sub ipc_block
175{
176    my $module = uc shift;
177    return "B_IPC_${module}_data";
178}
179
180sub ipc_header
181{
182    my $module = shift;
183    my $module_lc = lc $module;
184
185    return "nexus_${module_lc}_ipc_api.h";
186}
187
188sub process_function_param {
189    my $func = shift;
190    my $param = shift;
191    my @ipc_inparams;
192    my @ipc_outparams;
193    my $driver_arg;
194    my $completed=0;
195    my $null_allowed=0;
196    my $name = $param->{NAME};
197    my $driver_in_arg = "in_data->data.$func->{FUNCNAME}.in";
198    my $driver_out_arg = "out_data->data.$func->{FUNCNAME}.out";
199
200    if (exists $param->{ATTR}) {
201        my $attr;
202        my $value;
203        while (($attr, $value) = each %{$param->{ATTR}} ) {
204            next if($attr eq 'dealloc');
205            next if($attr eq 'reserved');
206            next if($attr eq 'nelem_out');
207            next if($attr eq 'nelem_convert');
208            if(($attr eq 'nelem' || $attr eq 'fixed_length')) {
209                # unix domain sockets can pass 4K atomically. to make the implementation much simpler, the thunk
210                # requires that all params (including nelem and nelem_out params) to fit within one packet.
211                # anything greater will cause the call to fail. # the app can then be rewritten to request smaller chunks.
212                if ($param->{INPARAM}) {
213                    push @ipc_inparams, "unsigned ${name}_variable_offset;";
214                    $driver_arg = "(void *)&(&$driver_in_arg.variable_params)[$driver_in_arg.${name}_variable_offset]";
215                }
216                else {
217                    push @ipc_outparams, "unsigned ${name}_variable_offset;";
218                    $driver_arg = "(void *)&(&$driver_out_arg.variable_params)[$driver_out_arg.${name}_variable_offset]";
219                }
220                $completed = 1;
221            }
222            elsif($attr eq 'memory' && $value eq 'cached' ) {
223                if ($param->{INPARAM}) {
224                    push @ipc_inparams, "NEXUS_Ipc_DeviceAddress $param->{NAME};";
225                    $driver_arg = "NEXUS_OffsetToCachedAddr((uint32_t)$driver_in_arg.$name)";
226                }
227                else {
228                    push @ipc_outparams, "NEXUS_Ipc_DeviceAddress $param->{NAME};";
229                    $driver_arg = "($param->{TYPE})&$driver_out_arg.$name";
230                }
231                $completed = 1;
232            }
233            elsif($attr eq 'null_allowed') {
234                $null_allowed = $value;
235            }
236            else {
237                print STDERR "ERROR: Unsupported attribute $attr = $value for $param->{NAME} in $func->{FUNCNAME}\n";
238            }
239        }
240    }
241
242    if($completed) {
243    }
244    elsif ($param->{ISREF} && $param->{BASETYPE} ne 'void') {
245        if ($param->{INPARAM}) {
246            push @ipc_inparams, "$param->{BASETYPE} $name;";
247            $driver_arg = "($driver_in_arg.$name\_isnull ? NULL : &$driver_in_arg.$name )";
248            push @ipc_inparams, "bool $name\_isnull;";
249        } else {
250            push @ipc_outparams, "$param->{BASETYPE} $name;";
251            $driver_arg = "&$driver_out_arg.$name";
252        }
253    }
254    else {
255        # must be inparam
256        push @ipc_inparams, "$param->{TYPE} $param->{NAME};";
257        $driver_arg = "$driver_in_arg.$name";
258    }
259    my %result;
260    $result{'ipc_inparams'} = \@ipc_inparams;
261    $result{'ipc_outparams'} = \@ipc_outparams;
262    $result{'driver_arg'} = $driver_arg;
263    return \%result;
264}
265
266sub process_function_attributes {
267    my $func = shift;
268    my $structs = shift;
269    my $funcs = shift;
270    my $params = $func->{PARAMS};
271    my @proxy_post_success;
272    my @proxy_pre_call;
273    my @driver_pre_call;
274    my @driver_post_success;
275    my @driver_post_error;
276    my @driver_post_always;
277    my @proxy_vars;
278    my %driver_overwrite;
279    my ($attr,$value);
280    my $param;
281    my $field;
282    my $arg_no=0;
283    my $driver_in_arg = "in_data->data.$func->{FUNCNAME}.in";
284    my $driver_out_arg = "out_data->data.$func->{FUNCNAME}.out";
285
286    if(exists $func->{ATTR}) {
287        while (($attr, $value) = each %{$func->{ATTR}} ) {
288            next if($attr eq 'destructor');
289            next if($attr eq 'secondary_destructor');
290            next if($attr eq 'release');
291            next if($attr eq 'local');
292            next if($attr eq 'dealloc');
293            next if($attr eq 'shutdown');
294            next if($attr eq 'chain'); # not supported
295
296            print STDERR "ERROR: Unsupported attribute $attr = $value for $func->{FUNCNAME}\n";
297        }
298    }
299
300    for $param (@$params) {
301        my $name = $param->{NAME};
302        $arg_no ++;
303
304        if (!exists $param->{ATTR}->{'nelem'} &&
305            !exists $param->{ATTR}->{'memory'} &&
306            !exists $param->{ATTR}->{'fixed_length'})
307        {
308            # ordinary params
309            if ($param->{ISREF} && $param->{BASETYPE} ne 'void') {
310                if ($param->{INPARAM}) {
311                    my $null_allowed = $param->{ATTR}->{'null_allowed'};
312                    if (!defined $null_allowed) {
313                        push @driver_pre_call, "if ($driver_in_arg.$name\_isnull) {";
314                        push @driver_pre_call, "    BDBG_ERR((\"NULL not allowed for $name param in $func->{FUNCNAME}: %d\", __LINE__));";
315                        push @driver_pre_call, "    goto err_fault;";
316                        push @driver_pre_call, "}";
317                    }
318                    push @proxy_pre_call, "if($name!=NULL) {";
319                    push @proxy_pre_call, "    $driver_in_arg.$name\_isnull = false;";
320                    push @proxy_pre_call, "    $driver_in_arg.$name = * $name;";
321                    push @proxy_pre_call, "} else {";
322                    push @proxy_pre_call, "    $driver_in_arg.$name\_isnull = true;";
323                    push @proxy_pre_call, "}";
324                } else {
325                    # NULL out param will crash the client; harmless to server
326                    push @proxy_post_success, "* $name = $driver_out_arg.$name;";
327                }
328            }
329            else {
330                # must be inparam
331                push @proxy_pre_call, "$driver_in_arg.$name = $name;";
332            }
333        }
334
335        # must exchange eInvalid and NULL for protected clients for Timebase and ParserBand as direct params
336        # this code only handles output param conversion post call
337        # pre-call, post-verification NULL->eInvalid input conversion is done in bapi_ipc_server.pm
338        if ($param->{ISREF})
339        {
340            if ($param->{BASETYPE} eq 'NEXUS_Timebase' || $param->{BASETYPE} eq 'NEXUS_ParserBand')
341            {
342                if (!$param->{INPARAM})
343                {
344                    push @driver_post_success, "if (client_module_state->client->config.mode != NEXUS_ClientMode_eUnprotected) {";
345                    push @driver_post_success, "  if ($driver_out_arg.$name != NULL) {"; # check pointer
346                    push @driver_post_success, "    if (*$driver_out_arg.$name == $param->{BASETYPE}_eInvalid) {"; # check pointed to value
347                    push @driver_post_success, "      *$driver_out_arg.$name = ($param->{BASETYPE})NULL;";
348                    push @driver_post_success, "    }";
349                    push @driver_post_success, "  }";
350                    push @driver_post_success, "}";
351                }
352            }
353        }
354       
355        if($param->{BASETYPE} eq 'NEXUS_CallbackDesc') {
356            if ($param->{INPARAM}) {
357                my $handle = "$driver_in_arg.$$params[0]->{NAME}";
358                my $id = sprintf("0x%05x", ((bapi_util::func_id $funcs, $func)*256 + $arg_no + 0x10000));
359                my $notnull_test = "! $driver_in_arg.$name\_isnull";
360                push @driver_pre_call, "if($notnull_test) {";
361                push @driver_pre_call, "   /* MAP callback from proxy space to the driver space */";
362                push @driver_pre_call, "   NEXUS_DRIVER_CALLBACK_TO_DRIVER(&$driver_in_arg.$name, $handle, $id);";
363                push @driver_pre_call, "}";
364                push @driver_post_success, "if($notnull_test) {";
365                push @driver_post_success, "    /* after function succeded, commit changes */";
366                push @driver_post_success, "    NEXUS_DRIVER_CALLBACK_TO_DRIVER_COMMIT(&$driver_in_arg.$name, $handle, $id);";
367                push @driver_post_success, "}";
368                push @driver_post_error, "if($notnull_test) {";
369                push @driver_post_error, "    /* if error occured, then cancel changes in the callback mapping */";
370                push @driver_post_error, "    NEXUS_DRIVER_CALLBACK_TO_DRIVER_CANCEL(&$driver_in_arg.$name, $handle, $id);";
371                push @driver_post_error, "}";
372            } else {
373                print STDERR "ERROR: pointer to NEXUS_CallbackDesc could be only input parameter\n";
374            }
375        }
376       
377        if (exists $structs->{$param->{BASETYPE}}) {
378            my $field_no = 0;
379            my @pre_update_proxy;
380            my @pre_update_driver;
381            my @post_update_proxy;
382            my @post_update_driver;
383            my @post_error_driver;
384
385#            bapi_parse_c::print_struct $structs->{$param->{BASETYPE}}
386            for $field (@{$structs->{$param->{BASETYPE}}}) {
387                my $field_driver_in = "$driver_in_arg.$name.$field->{NAME}";
388                my $field_driver_out = "$driver_out_arg.$name.$field->{NAME}";
389
390                $field_no ++;
391                if($field->{TYPE} eq 'NEXUS_CallbackDesc') {
392                    my $id = sprintf("0x%04x", ((bapi_util::struct_id $structs, $param->{BASETYPE})*256 + $field_no));
393                    my $handle;
394                    if ($func->{RETTYPE_ISHANDLE}) {
395                        $handle = 'NULL'; # update after sucess
396                    }
397                    elsif ($$params[0]->{ISHANDLE}) {
398                        $handle = "$driver_in_arg.$$params[0]->{NAME}";
399                    }
400                    elsif (!$$params[0]->{ISREF} && $param != $$params[0]) {
401                        # enum instead of handle.
402                        # use enum type + enum value as psuedo handle
403                        # hardcoded for a max of 128 enum values per type
404                        # value<<2+1 to use non-4 byte aligned value to ensure no conflict with actual handle
405                        $handle = "(($id<<9) + ($driver_in_arg.$$params[0]->{NAME}<<2) + 1)";
406                    }
407                    if (defined $handle && $param->{ISREF}) {
408                        if ($param->{INPARAM}) {
409                            push @pre_update_driver, "/* MAP callback from proxy space to the driver space */";
410                            push @pre_update_driver, "NEXUS_DRIVER_CALLBACK_TO_DRIVER(&$field_driver_in, $handle, $id);";
411                            if($handle eq 'NULL') {
412                                push @post_update_driver, "/* since callback wasn't avaliable before calling function, use the return result to update callback */";
413                                push @post_update_driver, "NEXUS_DRIVER_CALLBACK_UPDATE(&$field_driver_in, $handle, $id, $driver_out_arg.__retval);";
414                            } else {
415                                push @post_update_driver, "/* after function succeded, commit changes */";
416                                push @post_update_driver, "NEXUS_DRIVER_CALLBACK_TO_DRIVER_COMMIT(&$field_driver_in, $handle, $id);";
417                            }
418                            push @post_error_driver, "/* if error occured, then cancel changes in the callback mapping */";
419                            push @post_error_driver, "NEXUS_DRIVER_CALLBACK_TO_DRIVER_CANCEL(&$field_driver_in, $handle, $id);";
420                        } else {
421                            push @post_update_driver, "/* MAP callback from the driver space to proxy space */";
422                            push @post_update_driver, "NEXUS_DRIVER_CALLBACK_TO_CLIENT(&$field_driver_out, $handle, $id);";
423                        }
424                    }
425                }
426                # must exchange eInvalid and NULL for protected clients for Timebase and ParserBand as struct members
427                # this code only handles output param conversion post call
428                # pre-call, post-verification NULL->eInvalid input conversion is done in bapi_driver_ioctl.pm
429                # TODO: is field as pointer supported?
430                elsif ($field->{TYPE} eq 'NEXUS_Timebase' || $field->{TYPE} eq 'NEXUS_ParserBand')
431                {
432                    if (!$param->{INPARAM})
433                    {
434                        push @driver_post_success, "if (client_module_state->client->config.mode != NEXUS_ClientMode_eUnprotected) {";
435                        push @driver_post_success, "  if ($field_driver_out == $field->{TYPE}_eInvalid) {";
436                        push @driver_post_success, "    $field_driver_out = ($field->{TYPE})NULL;";
437                        push @driver_post_success, "  }";
438                        push @driver_post_success, "}";
439                    }
440                }
441
442                if (exists $field->{ATTR}) {
443#                   print " $func->{FUNCNAME} :";
444#                   print "  field: $field->{TYPE} $field->{NAME} -> ";
445#                   bapi_parse_c::print_attr $field->{ATTR};
446                    while (($attr, $value) = each %{$field->{ATTR}} ) {
447                        my $field_proxy = "$name->$field->{NAME}";
448                        my $field_copy = "$driver_in_arg.$name.$field->{NAME}";
449                        if($attr eq 'memory') {
450                            if($value eq 'cached') {
451                                if ($param->{ISREF}) {
452                                    if ($param->{INPARAM}) {
453                                        next if (exists $param->{ATTR}->{'nelem'});
454                                        push @pre_update_proxy, "/* convert address to the device offset */";
455                                        push @pre_update_proxy, "$field_copy = $field_copy ? (void *) NEXUS_AddrToOffset($field_copy) : $field_copy;";
456
457                                        push @pre_update_driver, "/* convert offset (substituted by the proxy ) to the cached address */";
458                                        push @pre_update_driver, "NEXUS_DRIVER_RECV_ADDR($field_driver_in,cached);";
459                                        next;
460                                    } else {
461                                        push @post_update_proxy, "/* convert offset (substituted by the driver) to the cached address */";
462                                        push @post_update_proxy, "$field_proxy = $field_proxy ? NEXUS_OffsetToCachedAddr((uint32_t)$field_proxy) : $field_proxy ;";
463
464                                        push @post_update_driver, "/* convert offset (substituted by the proxy) to the cached address */";
465                                        push @post_update_driver, "NEXUS_DRIVER_SEND_ADDR($field_driver_out,cached);";
466                                        next;
467                                    }
468                                }
469                            }
470                        }
471                        print STDERR "ERROR: Unsupported attribute $attr = $value for $field->{NAME} in $param->{BASETYPE}\n";
472                    }
473                }
474            }
475            if(scalar @pre_update_proxy) {
476                push @proxy_pre_call, "if($name) {";
477                push @proxy_pre_call, "     /* update values ... */";
478                bapi_util::append_code \@proxy_pre_call, \@pre_update_proxy, "     ";
479                push @proxy_pre_call, "}";
480            }
481            bapi_util::append_if \@driver_pre_call, "! $driver_in_arg.$name\_isnull", \@pre_update_driver;
482            # out params cannot be null
483            bapi_util::append_code \@driver_post_error, \@post_error_driver;
484            bapi_util::append_code \@driver_post_success, \@post_update_driver;
485            bapi_util::append_code \@proxy_post_success , \@post_update_proxy;
486        }
487       
488        if(exists $param->{ATTR}) {
489            while (($attr, $value) = each %{$param->{ATTR}} ) {
490                if($attr eq 'nelem_convert' || $attr eq 'nelem_out') {
491                    if( !exists $param->{ATTR}->{'nelem'}) {
492                        print STDERR "ERROR: $attr requires nelem: $func->{FUNCNAME}\n";
493                    }
494                    next; # handled with nelem
495                }
496                next if($attr eq 'dealloc'); # skip here
497                next if($attr eq 'null_allowed'); # skip here
498                next if($attr eq 'reserved'); # unnecessary for socket ipc
499
500                if(($attr eq 'nelem' || $attr eq 'fixed_length')) {
501                    # unix domain sockets can pass 4K atomically. to make the implementation much simpler, the thunk
502                    # requires that all params (including nelem and nelem_out params) to fit within one packet.
503                    # anything greater will cause the call to fail. # the app can then be rewritten to request smaller chunks.
504                    if ($param->{INPARAM}) {
505                        my $length = "$value";
506                        my $array_type;
507   
508                        if (exists $param->{ATTR}->{'nelem_convert'}) {
509                            $length =  $param->{ATTR}->{'nelem_convert'} . "($length)";
510                        }
511                        if($param->{BASETYPE} ne 'void') {
512                            $length = "(sizeof($param->{BASETYPE})*($length))";
513                            $array_type = $param->{BASETYPE};
514                        }
515                        else {
516                            $array_type = "uint8_t";
517                        }
518                       
519                        push @proxy_pre_call, "if (__variable_in_offset+$length>__data_size) {BDBG_ERR((\"length exceeded %d > %d: %d\", __variable_in_offset+$length, __data_size, __LINE__)); goto err_call;}";
520                        push @proxy_pre_call, "$driver_in_arg.${name}_variable_offset = __variable_in_offset;";
521                        push @proxy_pre_call, "__variable_in_offset += $length;";
522                        push @proxy_pre_call, "{";
523                        push @proxy_pre_call, "  $array_type *dest = ($array_type*)&(&$driver_in_arg.variable_params)[$driver_in_arg.${name}_variable_offset];";
524                        push @proxy_pre_call, "  BKNI_Memcpy(dest, $name, $length);";
525                       
526                        # Handle address translation
527                        my @driver_update_structure;
528                        my @proxy_update_structure;
529                        if (exists $structs->{$param->{BASETYPE}}) {
530                            my $field;
531                            for $field (@{$structs->{$param->{BASETYPE}}}) {
532                                if (exists $field->{ATTR}) {
533                                    my ($attr,$value);
534                                    while (($attr, $value) = each %{$field->{ATTR}} ) {
535                                        if($attr eq 'memory' && $value eq 'cached' && $param->{ISREF} && $param->{INPARAM}) {
536                                            my $field_copy = "dest[i].$field->{NAME}";
537                                            push @proxy_update_structure, "    /* convert address to the device offset */";
538                                            push @proxy_update_structure, "    $field_copy = (void *) NEXUS_AddrToOffset($field_copy);";
539
540                                            push @driver_update_structure, "    /* convert offset (substituted by the proxy) to the cached address */";
541                                            push @driver_update_structure, "    NEXUS_DRIVER_RECV_ADDR($field_copy,cached);";
542                                            next;
543                                        }
544                                        print STDERR "ERROR: Unsupported attribute $attr = $value for $field->{NAME} in $param->{BASETYPE}\n";
545                                    }
546                                }
547                            }
548                        }
549                        if (scalar @driver_update_structure) {
550                            # no dest pointer needed unless field conversion is required   
551                            push @driver_pre_call, "{";
552                            push @driver_pre_call, "  $array_type *dest = ($array_type*)&(&$driver_in_arg.variable_params)[$driver_in_arg.${name}_variable_offset];";
553                            push @driver_pre_call, "  {unsigned i;for(i=0;i<$driver_in_arg.$value;i++) {";
554                            push @driver_pre_call, @driver_update_structure;
555                            push @driver_pre_call, "  }}";
556                            push @driver_pre_call, "}";
557                        }
558                        if (scalar @proxy_update_structure) {
559                            push @proxy_pre_call, "  {unsigned i;for(i=0;i<$value;i++) {";
560                            push @proxy_pre_call, @proxy_update_structure;
561                            push @proxy_pre_call, "  }}";
562                        }
563                        push @proxy_pre_call, "}";
564                    }
565                    else {
566                        my $length = "$driver_in_arg.$value";
567                        my $length_out;
568   
569                        if (exists $param->{ATTR}->{'nelem_out'}) {
570                            $length_out = "$driver_out_arg.$param->{ATTR}->{'nelem_out'}";
571                        }
572                        else {
573                            $length_out = $length;
574                        }
575                        if (exists $param->{ATTR}->{'nelem_convert'}) {
576                            $length_out =  $param->{ATTR}->{'nelem_convert'} . "($length_out)";
577                        }
578   
579                        if($param->{BASETYPE} ne 'void') {
580                            $length_out = "(sizeof($param->{BASETYPE})*($length_out))";
581                            $length = "(sizeof($param->{BASETYPE})*($length))";
582                        }
583                       
584                        push @driver_pre_call, "if (*p_out_data_size-sizeof(void*)+__variable_out_offset+$length>out_mem_size) {BDBG_ERR((\"length exceeded %d-%d+%d+%d > %d: %d\", *p_out_data_size,sizeof(void*),__variable_out_offset,$length,out_mem_size, __LINE__)); goto err_fault;}";
585                        push @driver_pre_call, "$driver_out_arg.${name}_variable_offset = __variable_out_offset;";
586                        push @driver_pre_call, "__variable_out_offset += $length;";
587                        push @driver_pre_call, "(*p_out_data_size) += $length;";
588                        push @proxy_post_success, "BKNI_Memcpy($name, &(&$driver_out_arg.variable_params)[$driver_out_arg.${name}_variable_offset], $length_out);";
589                    }
590                }
591                elsif($attr eq 'memory' && $value eq 'cached' ) {
592                    if ($param->{INPARAM}) {
593                        push @proxy_pre_call, "/* convert offset (substituted by the driver) to the cached address */";
594                        push @proxy_pre_call, "$driver_in_arg.$name = (void *)NEXUS_AddrToOffset((void *)$name);";
595                        # driver_pre_call NEXUS_OffsetToCachedAddr handled in process_function_param
596                    }
597                    else {
598                        # handle return value. if client passes NULL outparam, only the client crashes
599                        push @proxy_post_success, "/* convert offset (substituted by the driver) to the cached address */";
600                        push @proxy_post_success, "*$name = $driver_out_arg.$name ? NEXUS_OffsetToCachedAddr((uint32_t)$driver_out_arg.$name) : NULL;";
601                        push @driver_post_success, "/* convert address to the device offset */";
602                        push @driver_post_success, "NEXUS_DRIVER_SEND_ADDR($driver_out_arg.$name, cached);";
603                    }
604                }
605                else {
606                    print STDERR "ERROR: Unsupported attribute $attr = $value for $param->{NAME} in $func->{FUNCNAME}\n";
607                }
608            }
609        }
610    }
611   
612    my %result;
613    if (scalar @proxy_post_success) {
614        $result{'proxy_post_success'} = \@proxy_post_success;
615    }
616    if (scalar @driver_post_success) {
617        $result{'driver_post_success'} = \@driver_post_success;
618    }
619    if (scalar @proxy_pre_call) {
620        $result{'proxy_pre_call'} = \@proxy_pre_call;
621    }
622    if (scalar @driver_pre_call) {
623        $result{'driver_pre_call'} = \@driver_pre_call;
624    }
625    if (scalar @proxy_vars) {
626        $result{'proxy_vars'} = \@proxy_vars;
627    }
628    if (scalar @driver_post_error) {
629        $result{'driver_post_error'} = \@driver_post_error;
630    }
631    if (scalar @driver_post_always) {
632        $result{'driver_post_always'} = \@driver_post_always;
633    }
634
635    $result{'driver_overwrite'} = \%driver_overwrite;
636    return \%result;
637}
638
639
6401;
641
Note: See TracBrowser for help on using the repository browser.