source: svn/newcon3bcm2_21bu/nexus/build/tools/syncthunk/bapi_thunks.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: 11.0 KB
Line 
1#!/usr/bin/perl
2#     (c)2007-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_thunks.pm $
39# $brcm_Revision: 17 $
40# $brcm_Date: 12/7/11 10:41a $
41#
42# File Description:
43#
44# Revision History:
45#
46# $brcm_Log: /nexus/build/tools/syncthunk/bapi_thunks.pm $
47#
48# 17   12/7/11 10:41a erickson
49# SW7420-2141: merge as much duplicated kernelmode proxy/usermode ipc
50#  perl code as possible
51#
52# 16   10/31/11 6:13p bandrews
53# SW7231-391: casts to support parser band and timebase as enums
54#
55# SW7420-2078/1   10/11/11 8:22p bandrews
56# SW7231-391: added casts to support dual variant usage of parser band
57#  and timebase
58#
59# 15   9/2/11 10:03a erickson
60# SW7420-1148: allow nexus_register/unregister to objdb from nexus
61#  module. enables more complex resource management.
62#
63# 14   7/13/11 3:43p erickson
64# SW7420-1979: #include nexus_class_verification.h is always required
65#  because of automatic shutdown
66#
67# 13   7/12/11 1:27p erickson
68# SW7420-1979: add support for new shutdown attribute
69#
70# 12   3/17/11 12:00p erickson
71# SW7346-101: fix NEXUS_StopCallbacks for secondary destructors
72#  (specifically, NEXUS_Playpump_ClosePidChannel)
73#
74# 11   1/27/11 3:05p erickson
75# SW7208-152: fix and standardize get_destructor_hash
76#
77# 10   1/27/11 1:43p erickson
78# SW7208-152: fix generation of NEXUS_StopCallbacks
79#
80# 9   1/19/11 2:02p erickson
81# SW7420-1123: socket-based usermode IPC
82#
83# 8   9/22/09 1:54p gmohile
84# SW7405-3060 : Export kernel symbols
85#
86# 7   3/28/08 10:47a vsilyaev
87# PR 40863: Call NEXUS_StopCalbacks prior to the 'destructor' call, since
88#  StopCallback is sticky it would prevent further callback to fire
89#
90# 6   3/24/08 6:58p vsilyaev
91# PR 40863: Changed order of calls to NEXUS_StopCallbacks and
92#  "destructors" in ordder to stop callbacks that were fired during call
93#  to the destructor function
94#
95# 5   3/24/08 6:42p vsilyaev
96# PR 40863: Added injection of NEXUS_StopCallbacks into all destructors
97#
98# 4   3/21/08 11:57a vsilyaev
99# PR 38682: Fixed typo in description
100#
101# 3   1/25/08 4:24p vsilyaev
102# PR 38682: Reduce code size of the generated code
103#
104# 2   1/24/08 4:34p vsilyaev
105# PR 38682: Reduced size and made optional tracing of thunk layer
106#
107# 1   1/18/08 2:15p jgarrett
108# PR 38808: Merging to main branch
109#
110# Nexus_Devel/5   10/15/07 2:53p vsilyaev
111# PR 35824: Fixed handling of (void) functions
112#
113# Nexus_Devel/4   10/12/07 11:49a erickson
114# PR36066: added "or die" to file opens
115#
116# Nexus_Devel/3   10/8/07 3:21p erickson
117# PR35395: added params and retval to trace
118#
119# Nexus_Devel/2   10/3/07 12:14p erickson
120# PR35395: enable thunk trace
121#
122# Nexus_Devel/1   9/27/07 1:33p erickson
123# PR35395: initial impl
124#
125#############################################################################
126use strict;
127
128package bapi_thunks;
129
130use bapi_common;
131use bapi_classes;
132
133# for user-mode IPC, server-side does not pass through the IPC thunk. Therefore a minimal amount of
134# hook is needed in the one thunk that is passed: the sync thunk.
135sub generate_ipc_code
136{
137    my ($func, $destructors, $classes) = @_;
138    my @server_pre_lock;
139    my @server_post_success;
140    my $class;
141
142    CLASS: for $class (@$classes) {
143        if ($class->{DESTRUCTOR} == $func) {
144            for (@{$class->{SHUTDOWN}}) {
145                my $shutdown_target = $_->{'shutdown_target'};
146                my $shutdown_get_connector = $_->{'shutdown_get_connector'};
147                my $params = $func->{PARAMS};
148                my $handle = $$params[0]->{NAME};
149                push @server_pre_lock, "nexus_driver_shutdown_$shutdown_target($shutdown_get_connector($handle));";
150            }
151        }
152    }
153   
154    my $stopcallbacks_handle = bapi_classes::get_stopcallbacks_handle $func, $destructors;
155    if (defined $stopcallbacks_handle) {
156        push @server_pre_lock, "NEXUS_StopCallbacks((void*)$stopcallbacks_handle);";
157    }
158   
159    my %result;
160    $result{'server_pre_lock'} = \@server_pre_lock;
161    $result{'server_post_success'} = \@server_post_success;
162    return \%result;
163}
164
165sub build_thunks
166{
167    my ($module, $filename, $funcs) = @_;
168    my $func;
169    my $destructors = bapi_classes::get_destructors $funcs;
170    my $classes = bapi_classes::get_classes $funcs, $destructors;
171
172    open FILE, ">$filename" or die;
173    print FILE "/*********************************\n";
174    print FILE "*\n";
175    print FILE "* This file is autogenerated by the Nexus Platform makefile.\n";
176    print FILE "*\n";
177    print FILE "* This file acquires the module lock for every public API call into that module. The actual implementation of each function is remapped to _impl.\n";
178    print FILE "*\n";
179    print FILE "*********************************/\n";
180    print FILE "#define NEXUS_THUNK_LAYER\n";
181    print FILE "#include \"nexus_${module}_module.h\"\n";
182    print FILE "#include \"nexus_core_utils.h\"\n";
183    print FILE "#include \"nexus_class_verification.h\"\n";
184    print FILE "BDBG_MODULE(nexus_${module}_thunks);\n";
185    print FILE "#define BDBG_MSG_TRACE(x) \n";
186    print FILE "/* use local static function in order to reduce size of compiled code, size would reduce since NEXUS_XXXModule expanded to function call with three arguments (where at least one is a global symbol) */\n";
187    print FILE "static void module_lock(void) { NEXUS_LockModule();}\n";
188    print FILE "static void module_unlock(void) { NEXUS_UnlockModule();}\n";
189
190
191    # generate prototypes for all the _impl functions
192    for $func (@{$funcs}) {
193        # NOTE: If there's an exception and a function does not belong in the thunk layer, add it here.
194
195        my $impl = $func->{PROTOTYPE};
196        $impl =~ s/$func->{FUNCNAME}/$func->{FUNCNAME}_impl/;
197        print FILE "$impl;\n";
198    }
199
200    # generate the actual thunk layer functions which call the impl functions
201    for $func (@{$funcs}) {
202        my $params = $func->{PARAMS};
203        my $param;
204        my $generated_code = generate_ipc_code $func, $destructors, $classes;
205
206        print FILE "$func->{PROTOTYPE}\n\{\n";
207        if ($func->{RETTYPE} eq "void") {
208        }
209        else {
210            print FILE "  $func->{RETTYPE} result;\n";
211        }
212
213        # enter MSG
214        print FILE "  BDBG_MSG_TRACE((\">%s\(";
215        for $param (@$params) {
216            print FILE "%#lx";
217            if ($param != $params->[-1]) { print FILE ", "; }
218        }
219        print FILE ")\" ";
220        print FILE ", \"$func->{FUNCNAME}\"";
221        for $param (@$params) {
222            print FILE ", ";
223            print FILE "(unsigned long)$param->{NAME}";
224        }
225        print FILE "));\n";
226
227        if (scalar @{$generated_code->{'server_pre_lock'}}) {
228            my $file = \*FILE;
229            bapi_util::print_code $file, $generated_code->{'server_pre_lock'}, "  ";
230        }
231
232        # make call
233        print FILE "  module_lock();\n";
234
235        if ($func->{RETTYPE} eq "void") {
236            print FILE "  $func->{FUNCNAME}_impl(";
237        }
238        else {
239            print FILE "  result = $func->{FUNCNAME}_impl(";
240        }
241        for $param (@$params) {
242            print FILE "$param->{NAME}";
243            if ($param != $params->[-1]) { print FILE ", "; }
244        }
245        print FILE ");\n";
246
247        # leave MSG and return value
248        if ($func->{RETTYPE} eq "void") {
249            print FILE "  module_unlock();\n";
250            print FILE "  BDBG_MSG_TRACE((\"<%s\", \"$func->{FUNCNAME}\"));\n";
251            print FILE "  return;\n";
252        }
253        else {
254            print FILE "  module_unlock();\n";
255            if (scalar @{$generated_code->{'server_post_success'}}) {
256                if ($func->{RETTYPE} eq "NEXUS_Error") {
257                    print FILE "  if (!result) {\n";
258                }
259                else {
260                    print FILE "  if (result) {\n";
261                }
262                my $file = \*FILE;
263                bapi_util::print_code $file, $generated_code->{'server_post_success'}, "    ";
264                print FILE "  }\n";
265            }
266            print FILE "  BDBG_MSG_TRACE((\"<%s\=%#lx\", \"$func->{FUNCNAME}\", (unsigned long)result));\n";
267            print FILE "  return result;\n";
268        }
269        print FILE "}\n\n";
270    }
271    close FILE;
272}
273
274sub build_remapping
275{
276    my ($filename, $funcs) = @_;
277    my $func;
278    open FILE, ">$filename" or die;
279
280    print FILE "/*********************************\n";
281    print FILE "*\n";
282    print FILE "* This file is autogenerated by the Nexus Platform makefile.\n";
283    print FILE "*\n";
284    print FILE "* This file remaps every public API function to _impl. This allows the Nexus modules to call their own public API without reacquiring the module lock.\n";
285    print FILE "*\n";
286    print FILE "*********************************/\n";
287    print FILE "#ifndef NEXUS_THUNK_LAYER\n";
288
289    for $func (@{$funcs}) {
290        print FILE "#define $func->{FUNCNAME} $func->{FUNCNAME}_impl\n";
291    }
292    print FILE "#endif\n";
293    print FILE "\n";
294    close FILE;
295}
296
297
2981;
Note: See TracBrowser for help on using the repository browser.