| 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_ipc_apidef.pm $ |
|---|
| 39 | # $brcm_Revision: 4 $ |
|---|
| 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_apidef.pm $ |
|---|
| 47 | # |
|---|
| 48 | # 4 12/7/11 10:41a erickson |
|---|
| 49 | # SW7420-2141: merge as much duplicated kernelmode proxy/usermode ipc |
|---|
| 50 | # perl code as possible |
|---|
| 51 | # |
|---|
| 52 | # 3 2/15/11 2:28p erickson |
|---|
| 53 | # SW7420-1123: refactor IPC thunk to separate in/out params |
|---|
| 54 | # |
|---|
| 55 | # 2 1/19/11 2:03p erickson |
|---|
| 56 | # SW7420-1123: socket-based usermode IPC |
|---|
| 57 | # |
|---|
| 58 | # 1 9/29/10 9:34a erickson |
|---|
| 59 | # SW7420-1123: add linux usermode IPC |
|---|
| 60 | # |
|---|
| 61 | ############################################################################# |
|---|
| 62 | use strict; |
|---|
| 63 | use bapi_common; |
|---|
| 64 | use bapi_util; |
|---|
| 65 | |
|---|
| 66 | package bapi_ipc_apidef; |
|---|
| 67 | |
|---|
| 68 | sub generate_ipc_block |
|---|
| 69 | { |
|---|
| 70 | my ($file, $module, $funcs) = @_; |
|---|
| 71 | my $func; |
|---|
| 72 | my $block = bapi_common::ipc_block $module; |
|---|
| 73 | my $module_lc = lc $module; |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | print $file "/* structure to store copy of all in and out parameters */\n"; |
|---|
| 77 | print $file "typedef struct $block {\n"; |
|---|
| 78 | print $file " NEXUS_Ipc_Header header;\n"; |
|---|
| 79 | print $file " union {\n"; |
|---|
| 80 | for $func (@$funcs) { |
|---|
| 81 | my $params = $func->{PARAMS}; |
|---|
| 82 | my $param; |
|---|
| 83 | my @struct; |
|---|
| 84 | #if (!$func->{NOSTRUCT}) |
|---|
| 85 | { |
|---|
| 86 | my $struct = bapi_common::ipc_struct $module, $func; |
|---|
| 87 | print $file " $struct $func->{FUNCNAME}; \n"; |
|---|
| 88 | } |
|---|
| 89 | } |
|---|
| 90 | print $file " } data; \n"; |
|---|
| 91 | print $file "} $block;\n"; |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | # this function takes an array of function data structures as input |
|---|
| 95 | # it prints out structure definitions for IPC |
|---|
| 96 | sub generate |
|---|
| 97 | { |
|---|
| 98 | my ($filename, $module, $version, @funcs) = @_; |
|---|
| 99 | my $func; |
|---|
| 100 | open FILE, ">$filename"; |
|---|
| 101 | my $cnt = 0; |
|---|
| 102 | |
|---|
| 103 | print FILE bapi_util::header $module; |
|---|
| 104 | |
|---|
| 105 | print FILE "\n\n"; |
|---|
| 106 | print FILE "#define " . (bapi_common::version_define $module) . (bapi_common::version_value $version) . "\n"; |
|---|
| 107 | |
|---|
| 108 | $cnt++; |
|---|
| 109 | |
|---|
| 110 | for $func (@funcs) { |
|---|
| 111 | my $funcname = $func->{FUNCNAME}; |
|---|
| 112 | my $params = $func->{PARAMS}; |
|---|
| 113 | my $param; |
|---|
| 114 | my $ipc_name = bapi_common::ipc_name $module, $func; |
|---|
| 115 | my $struct = bapi_common::ipc_struct $module, $func; |
|---|
| 116 | my @members; |
|---|
| 117 | |
|---|
| 118 | # in params |
|---|
| 119 | push @members, "struct {"; |
|---|
| 120 | for $param (@$params) { |
|---|
| 121 | if ($param->{INPARAM}) { |
|---|
| 122 | my $info = bapi_common::process_function_param $func, $param; |
|---|
| 123 | bapi_util::append_code \@members, $info->{'ipc_inparams'}, " "; |
|---|
| 124 | } |
|---|
| 125 | } |
|---|
| 126 | push @members, " uint8_t *variable_params;"; |
|---|
| 127 | push @members, "} in;"; |
|---|
| 128 | |
|---|
| 129 | # out params, including retval |
|---|
| 130 | push @members, "struct {"; |
|---|
| 131 | # If the RETTYPE is a reference, make it a value |
|---|
| 132 | if ( $func->{RETTYPE} !~ /void\s*\*$/ && $func->{RETTYPE} =~ /\*$/) { |
|---|
| 133 | my $rettype = $func->{RETTYPE}; |
|---|
| 134 | $rettype =~ s/const//; |
|---|
| 135 | $rettype =~ s/\*//; |
|---|
| 136 | push @members, " $rettype __retval;"; |
|---|
| 137 | } elsif ($func->{RETTYPE} ne "void") { |
|---|
| 138 | push @members, " $func->{RETTYPE} __retval;"; |
|---|
| 139 | } |
|---|
| 140 | |
|---|
| 141 | for $param (@$params) { |
|---|
| 142 | if (!$param->{INPARAM}) { |
|---|
| 143 | my $info = bapi_common::process_function_param $func, $param; |
|---|
| 144 | bapi_util::append_code \@members, $info->{'ipc_outparams'}, " "; |
|---|
| 145 | } |
|---|
| 146 | } |
|---|
| 147 | push @members, " uint8_t *variable_params;"; |
|---|
| 148 | push @members, "} out;"; |
|---|
| 149 | |
|---|
| 150 | print FILE "#define $ipc_name NEXUS_IPC_ID($module,$cnt)\n\n"; |
|---|
| 151 | print FILE "typedef union $struct \{\n"; |
|---|
| 152 | bapi_util::print_code \*FILE, \@members, " "; |
|---|
| 153 | print FILE "} $struct ;\n\n"; |
|---|
| 154 | |
|---|
| 155 | $cnt++; |
|---|
| 156 | } |
|---|
| 157 | generate_ipc_block \*FILE, $module, \@funcs; |
|---|
| 158 | close FILE; |
|---|
| 159 | } |
|---|
| 160 | |
|---|
| 161 | 1; |
|---|