| 1 | #!/usr/bin/perl |
|---|
| 2 | # (c)2004-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_ipc_client.pm $ |
|---|
| 39 | # $brcm_Revision: 12 $ |
|---|
| 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_ipc_client.pm $ |
|---|
| 47 | # |
|---|
| 48 | # 12 12/7/11 10:41a erickson |
|---|
| 49 | # SW7420-2141: merge as much duplicated kernelmode proxy/usermode ipc |
|---|
| 50 | # perl code as possible |
|---|
| 51 | # |
|---|
| 52 | # 11 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:21p bandrews |
|---|
| 56 | # SW7231-391: added casts to support parser band and timebase dual |
|---|
| 57 | # variants |
|---|
| 58 | # |
|---|
| 59 | # 10 8/8/11 3:40p erickson |
|---|
| 60 | # SW7420-1123: if IPC fails, return failure return code |
|---|
| 61 | # |
|---|
| 62 | # 9 7/29/11 12:10p erickson |
|---|
| 63 | # SW7420-1991: fix nelem,nelem_out attribute support, reorganize to be |
|---|
| 64 | # closer to kernelproxy/bapi_common.pm layout |
|---|
| 65 | # |
|---|
| 66 | # 8 4/12/11 4:25p erickson |
|---|
| 67 | # SW7420-1123: reduce size of inparams |
|---|
| 68 | # |
|---|
| 69 | # 7 3/17/11 11:59a erickson |
|---|
| 70 | # SW7346-101: fix NEXUS_StopCallbacks for secondary destructors |
|---|
| 71 | # (specifically, NEXUS_Playpump_ClosePidChannel) |
|---|
| 72 | # |
|---|
| 73 | # 6 3/11/11 1:04p erickson |
|---|
| 74 | # SW7420-1123: add NEXUS_PROXY_THUNK_LAYER |
|---|
| 75 | # |
|---|
| 76 | # 5 2/16/11 2:17p erickson |
|---|
| 77 | # SW7420-1123: implement nelem/nelem_out for IPC thunk |
|---|
| 78 | # |
|---|
| 79 | # 4 2/15/11 2:28p erickson |
|---|
| 80 | # SW7420-1123: refactor IPC thunk to separate in/out params |
|---|
| 81 | # |
|---|
| 82 | # 3 2/9/11 11:43a erickson |
|---|
| 83 | # SW7420-1441: support attr{local=true} |
|---|
| 84 | # |
|---|
| 85 | # 2 1/19/11 2:03p erickson |
|---|
| 86 | # SW7420-1123: socket-based usermode IPC |
|---|
| 87 | # |
|---|
| 88 | # 1 9/29/10 9:34a erickson |
|---|
| 89 | # SW7420-1123: add linux usermode IPC |
|---|
| 90 | # |
|---|
| 91 | ############################################################################# |
|---|
| 92 | use strict; |
|---|
| 93 | use bapi_classes; |
|---|
| 94 | |
|---|
| 95 | package bapi_ipc_client; |
|---|
| 96 | |
|---|
| 97 | sub generate |
|---|
| 98 | { |
|---|
| 99 | my ($filename, $module, $version, $structs, @funcs) = @_; |
|---|
| 100 | my $func; |
|---|
| 101 | my $destructors = bapi_classes::get_destructors \@funcs; |
|---|
| 102 | my $module_lc = lc $module; |
|---|
| 103 | |
|---|
| 104 | open FILE, ">$filename"; |
|---|
| 105 | |
|---|
| 106 | print FILE bapi_util::header $module; |
|---|
| 107 | |
|---|
| 108 | print FILE "#define NEXUS_PROXY_THUNK_LAYER\n"; |
|---|
| 109 | print FILE "#include \"client/nexus_client_prologue.h\"\n"; |
|---|
| 110 | print FILE "#include \"nexus_${module_lc}_module.h\"\n"; |
|---|
| 111 | print FILE "#include \"nexus_core_utils.h\"\n"; |
|---|
| 112 | print FILE "BDBG_MODULE(nexus_${module_lc}_ipc_client);\n"; |
|---|
| 113 | print FILE "\n\n"; |
|---|
| 114 | print FILE "#define nexus_client_module_init nexus_client_${module_lc}_init\n"; |
|---|
| 115 | print FILE "#define nexus_client_module_uninit nexus_client_${module_lc}_uninit\n"; |
|---|
| 116 | print FILE "#define nexus_client_module_state nexus_client_${module_lc}_state\n"; |
|---|
| 117 | print FILE "#include \"" . (bapi_common::ipc_header $module) . "\"\n"; |
|---|
| 118 | print FILE "#define NEXUS_IPC_MODULE_INIT " . (bapi_common::version_ipc $module) . "\n"; |
|---|
| 119 | print FILE "#define NEXUS_CLIENT_MODULE_VERSION " . (bapi_common::version_define $module) . "\n"; |
|---|
| 120 | print FILE "#define NEXUS_CLIENT_MODULE_NAME \"$module\"\n"; |
|---|
| 121 | print FILE "#include \"client/nexus_client_body.h\"\n"; |
|---|
| 122 | |
|---|
| 123 | for $func (@funcs) { |
|---|
| 124 | my $params = $func->{PARAMS}; |
|---|
| 125 | my $param; |
|---|
| 126 | my $attr = bapi_common::process_function_attributes $func, $structs, \@funcs; |
|---|
| 127 | |
|---|
| 128 | next if(exists $func->{ATTR}->{'local'}); # local function compiled verbatim into the proxy code |
|---|
| 129 | |
|---|
| 130 | print FILE "$func->{PROTOTYPE}\n\{\n"; |
|---|
| 131 | print FILE " unsigned __data_size, __n;\n"; |
|---|
| 132 | print FILE " unsigned __variable_in_offset = 0;\n"; |
|---|
| 133 | print FILE " void *temp;\n"; |
|---|
| 134 | print FILE " NEXUS_Error __rc;\n"; |
|---|
| 135 | if ($func->{RETTYPE} eq "NEXUS_Error") { |
|---|
| 136 | print FILE " NEXUS_Error __result=NEXUS_UNKNOWN;\n"; |
|---|
| 137 | } elsif ($func->{RETTYPE} ne "void") { |
|---|
| 138 | print FILE " $func->{RETTYPE} __result=($func->{RETTYPE})NULL;\n"; |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | print FILE " " . (bapi_common::ipc_block $module) . " *in_data, *out_data;\n"; |
|---|
| 142 | bapi_util::print_code \*FILE, $attr->{proxy_vars}, " "; |
|---|
| 143 | print FILE "\n"; |
|---|
| 144 | print FILE " NEXUS_CLIENT_ENTER($func->{FUNCNAME});\n"; |
|---|
| 145 | print FILE " BSTD_UNUSED(__variable_in_offset); /* may be unused */\n"; |
|---|
| 146 | |
|---|
| 147 | print FILE "\n"; |
|---|
| 148 | print FILE " /* coverity[unreachable] dummy jump to prevent warning */\n"; |
|---|
| 149 | print FILE " if(0) {goto err_alloc;}\n"; |
|---|
| 150 | print FILE "\n"; |
|---|
| 151 | print FILE " __rc = NEXUS_P_Client_LockModule(nexus_client_module_state, &temp, &__data_size);\n"; |
|---|
| 152 | print FILE " if (__rc) {__rc=BERR_TRACE(__rc);goto err_lock;}\n"; |
|---|
| 153 | # client uses same memory for in & out params, but retains separate in_data/out_data names for compatibility w/ server side auto-gen code |
|---|
| 154 | print FILE " out_data = in_data = temp;\n"; |
|---|
| 155 | |
|---|
| 156 | my $stopcallbacks_handle = bapi_classes::get_stopcallbacks_handle $func, $destructors; |
|---|
| 157 | if (defined $stopcallbacks_handle) { |
|---|
| 158 | print FILE " NEXUS_P_Client_StopCallbacks(nexus_client_module_state, (void *)$stopcallbacks_handle);\n"; |
|---|
| 159 | } |
|---|
| 160 | |
|---|
| 161 | print FILE "\n"; |
|---|
| 162 | print FILE " in_data->header.function_id = " . (bapi_common::ipc_name $module, $func) . ";\n"; |
|---|
| 163 | print FILE " in_data->header.version = " . (bapi_common::version_define $module) . ";\n"; |
|---|
| 164 | bapi_util::print_code \*FILE, $attr->{proxy_pre_call}, " "; |
|---|
| 165 | |
|---|
| 166 | print FILE " __n = sizeof(in_data->header)+sizeof(in_data->data.$func->{FUNCNAME}.in);\n"; |
|---|
| 167 | # subtract sizeof(void*) because __variable_in_offset double counts the size of in.variable_params. |
|---|
| 168 | print FILE " if (__variable_in_offset) __n += __variable_in_offset - sizeof(void*);\n"; |
|---|
| 169 | print FILE " __rc = NEXUS_P_Client_CallServer(nexus_client_module_state, in_data, __n, out_data, __data_size, &__n);\n"; |
|---|
| 170 | if ($func->{RETTYPE} eq "NEXUS_Error") { |
|---|
| 171 | print FILE " if (__rc!=NEXUS_SUCCESS) {__result=BERR_TRACE(__rc);goto err_call;}\n"; |
|---|
| 172 | } |
|---|
| 173 | else { |
|---|
| 174 | print FILE " if (__rc!=NEXUS_SUCCESS) {__rc=BERR_TRACE(__rc);goto err_call;}\n"; |
|---|
| 175 | } |
|---|
| 176 | print FILE " if (__n<sizeof(out_data->header)+sizeof(out_data->data.$func->{FUNCNAME}.out)) {__rc=BERR_TRACE(-1);goto err_call;}\n"; |
|---|
| 177 | |
|---|
| 178 | bapi_util::print_code \*FILE, $attr->{proxy_post_success}, " "; |
|---|
| 179 | |
|---|
| 180 | if ($func->{RETTYPE} ne "void") { |
|---|
| 181 | print FILE " __result = out_data->data.$func->{FUNCNAME}.out.__retval;\n"; |
|---|
| 182 | } |
|---|
| 183 | |
|---|
| 184 | if (defined $stopcallbacks_handle) { |
|---|
| 185 | print FILE "\n"; |
|---|
| 186 | print FILE " NEXUS_P_Client_StartCallbacks(nexus_client_module_state, (void *)$stopcallbacks_handle);\n"; |
|---|
| 187 | } |
|---|
| 188 | |
|---|
| 189 | print FILE "\n"; |
|---|
| 190 | print FILE "err_call:\n"; |
|---|
| 191 | print FILE " NEXUS_P_Client_UnlockModule(nexus_client_module_state);\n"; |
|---|
| 192 | print FILE "err_lock:\n"; |
|---|
| 193 | print FILE "err_alloc:\n"; |
|---|
| 194 | print FILE " NEXUS_CLIENT_LEAVE($func->{FUNCNAME});\n"; |
|---|
| 195 | if ($func->{RETTYPE} ne "void") { |
|---|
| 196 | print FILE " return __result;\n" |
|---|
| 197 | } else { |
|---|
| 198 | print FILE " return;\n" |
|---|
| 199 | } |
|---|
| 200 | |
|---|
| 201 | print FILE "}\n\n"; |
|---|
| 202 | |
|---|
| 203 | } |
|---|
| 204 | close FILE; |
|---|
| 205 | } |
|---|
| 206 | |
|---|
| 207 | 1; |
|---|
| 208 | |
|---|