| 1 | #!/usr/bin/perl |
|---|
| 2 | ############################################################################# |
|---|
| 3 | # |
|---|
| 4 | # Copyright (c) 2004-2007, Broadcom Corporation. |
|---|
| 5 | # All rights reserved. |
|---|
| 6 | # Confidential Property of Broadcom Corporation. |
|---|
| 7 | # |
|---|
| 8 | # THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE |
|---|
| 9 | # AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR |
|---|
| 10 | # EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. |
|---|
| 11 | # |
|---|
| 12 | # $brcm_Workfile: bapi_usercall.pm $ |
|---|
| 13 | # $brcm_Revision: 5 $ |
|---|
| 14 | # $brcm_Date: 1/5/07 11:52a $ |
|---|
| 15 | # |
|---|
| 16 | # File Description: |
|---|
| 17 | # |
|---|
| 18 | # Revision History: |
|---|
| 19 | # |
|---|
| 20 | # $brcm_Log: /BSEAV/api/build/proxy/bapi_usercall.pm $ |
|---|
| 21 | # |
|---|
| 22 | # 5 1/5/07 11:52a erickson |
|---|
| 23 | # PR26790: for proxy-layer callback conversion, we must convert back on |
|---|
| 24 | # callback out params. |
|---|
| 25 | # |
|---|
| 26 | # 4 3/15/06 4:51p vsilyaev |
|---|
| 27 | # PR20221: NetIF DMA interface |
|---|
| 28 | # |
|---|
| 29 | # 3 9/12/05 12:35p mphillip |
|---|
| 30 | # PR16870: Fix kernel-mode macrovision support |
|---|
| 31 | # |
|---|
| 32 | # 2 9/8/05 6:23p mphillip |
|---|
| 33 | # PR16870: Support for the macrovision data in bdisplay_settings |
|---|
| 34 | # |
|---|
| 35 | # 1 2/7/05 6:56p dlwin |
|---|
| 36 | # Merge down for release 2005_REFSW_MERGETOMAIN: |
|---|
| 37 | # |
|---|
| 38 | # Irvine_BSEAVSW_Devel/10 1/26/05 11:04a erickson |
|---|
| 39 | # PR13837: convert buffer_base to user address |
|---|
| 40 | # |
|---|
| 41 | # Irvine_BSEAVSW_Devel/9 7/23/04 2:41p erickson |
|---|
| 42 | # PR11771: updated proxy layer for settop api changes |
|---|
| 43 | # |
|---|
| 44 | # Irvine_BSEAVSW_Devel/8 7/9/04 1:38p erickson |
|---|
| 45 | # PR11771: rebuilt proxy layer for settop api dataflow redesign, and |
|---|
| 46 | # handle all callbacks with new perl module |
|---|
| 47 | # |
|---|
| 48 | # Irvine_BSEAVSW_Devel/7 6/24/04 10:24a erickson |
|---|
| 49 | # PR11135: added "don't modify" headers |
|---|
| 50 | # |
|---|
| 51 | # Irvine_BSEAVSW_Devel/6 6/18/04 12:33p erickson |
|---|
| 52 | # PR11135: added some timing debug code which can be uncommented if |
|---|
| 53 | # needed |
|---|
| 54 | # |
|---|
| 55 | # Irvine_BSEAVSW_Devel/5 6/17/04 9:37a erickson |
|---|
| 56 | # PR11135: recpump callback enabled |
|---|
| 57 | # |
|---|
| 58 | # Irvine_BSEAVSW_Devel/4 6/16/04 5:16p erickson |
|---|
| 59 | # PR11135: added callback support |
|---|
| 60 | # |
|---|
| 61 | # Irvine_BSEAVSW_Devel/3 6/2/04 2:45p erickson |
|---|
| 62 | # PR11204: changed/removed deprecated settop api functions |
|---|
| 63 | # |
|---|
| 64 | # Irvine_BSEAVSW_Devel/2 6/1/04 11:28a erickson |
|---|
| 65 | # PR11135: added comment |
|---|
| 66 | # |
|---|
| 67 | # Irvine_BSEAVSW_Devel/1 5/17/04 11:14a erickson |
|---|
| 68 | # PR11135: added initial linux proxy impl |
|---|
| 69 | # |
|---|
| 70 | ############################################################################# |
|---|
| 71 | use strict; |
|---|
| 72 | use bapi_callbacks; |
|---|
| 73 | |
|---|
| 74 | package bapi_usercall; |
|---|
| 75 | |
|---|
| 76 | sub parse |
|---|
| 77 | { |
|---|
| 78 | my ($filename, @funcs) = @_; |
|---|
| 79 | my $func; |
|---|
| 80 | open FILE, ">$filename"; |
|---|
| 81 | |
|---|
| 82 | print FILE "/*********************************\n"; |
|---|
| 83 | print FILE "*\n"; |
|---|
| 84 | print FILE "* This file is autogenerated. Do not modify.\n"; |
|---|
| 85 | print FILE "*\n"; |
|---|
| 86 | print FILE "*********************************/\n"; |
|---|
| 87 | |
|---|
| 88 | for $func (@funcs) { |
|---|
| 89 | my $params = $func->{PARAMS}; |
|---|
| 90 | my $param; |
|---|
| 91 | |
|---|
| 92 | print FILE "$func->{PROTOTYPE}\n\{\n"; |
|---|
| 93 | print FILE " int rc;\n"; |
|---|
| 94 | |
|---|
| 95 | # NOTE: The following code can measure time delays across the proxy. |
|---|
| 96 | # See below for more code. |
|---|
| 97 | # print FILE " b_time_t start, end; int diff;\n"; |
|---|
| 98 | # print FILE " b_time_get(&start);\n"; |
|---|
| 99 | |
|---|
| 100 | # If no params, no ioctl |
|---|
| 101 | if ($func->{NOSTRUCT}) { |
|---|
| 102 | print FILE " rc = ioctl(g_ioctl_fd, BSETTOP_IOCTL_$func->{FUNCNAME}, NULL);\n"; |
|---|
| 103 | } |
|---|
| 104 | else { |
|---|
| 105 | print FILE " ioctl_settopapi_struct_$func->{FUNCNAME} st;\n"; |
|---|
| 106 | |
|---|
| 107 | for $param (@$params) { |
|---|
| 108 | print FILE " st.$param->{NAME} = $param->{NAME};\n"; |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | # handle callback sets |
|---|
| 112 | my $callback_text = bapi_callbacks::build_user_callback($func, 1); |
|---|
| 113 | if ($callback_text) { |
|---|
| 114 | printf FILE $callback_text; |
|---|
| 115 | } |
|---|
| 116 | |
|---|
| 117 | print FILE " rc = ioctl(g_ioctl_fd, BSETTOP_IOCTL_$func->{FUNCNAME}, (void*)&st);\n"; |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | # TODO: add a table for failure return codes? |
|---|
| 121 | if ($func->{RETTYPE} eq "bresult") { |
|---|
| 122 | print FILE " if (rc) return BSETTOP_ERROR(berr_external_error);\n"; |
|---|
| 123 | } |
|---|
| 124 | elsif ($func->{RETTYPE} eq "void") { |
|---|
| 125 | print FILE " if (rc) {BSETTOP_ERROR(berr_external_error);}\n"; |
|---|
| 126 | } |
|---|
| 127 | elsif ($func->{RETTYPE} eq "long" || |
|---|
| 128 | $func->{RETTYPE} eq "off_t") { |
|---|
| 129 | print FILE " if (rc) {BSETTOP_ERROR(berr_external_error);return -1;}\n"; |
|---|
| 130 | } |
|---|
| 131 | else { |
|---|
| 132 | # print "'" . $func->{RETTYPE} . "'\n"; |
|---|
| 133 | print FILE " if (rc) {BSETTOP_ERROR(berr_external_error);return NULL;}\n"; |
|---|
| 134 | } |
|---|
| 135 | |
|---|
| 136 | # NOTE: The following code can measure time delays across the proxy. |
|---|
| 137 | # See above for more code. |
|---|
| 138 | # print FILE " b_time_get(&end);\n"; |
|---|
| 139 | # print FILE " diff = b_time_diff(&end, &start);\n"; |
|---|
| 140 | # print FILE " if (diff > 10) BDBG_ERR((\"delay %d, line %d\", diff, __LINE__));\n"; |
|---|
| 141 | |
|---|
| 142 | # |
|---|
| 143 | # mmap any memory returned by the driver |
|---|
| 144 | # |
|---|
| 145 | my $maps = ""; |
|---|
| 146 | for $param (@$params) { |
|---|
| 147 | if ($param->{ISREF} && ($param->{BASETYPE} =~ /\*/)) { |
|---|
| 148 | $maps .= " *st.$param->{NAME} = b_kernel2user((unsigned long)*st.$param->{NAME}, true);\n"; |
|---|
| 149 | } |
|---|
| 150 | } |
|---|
| 151 | if ($func->{FUNCNAME} eq "bsurface_get_memory") { |
|---|
| 152 | $maps .= " memory->buffer = b_kernel2user((unsigned long)memory->buffer, true);\n"; |
|---|
| 153 | } |
|---|
| 154 | if ($func->{FUNCNAME} eq "bplaypump_get_status") { |
|---|
| 155 | $maps .= " status->buffer_base = b_kernel2user((unsigned long)status->buffer_base, true);\n"; |
|---|
| 156 | } |
|---|
| 157 | |
|---|
| 158 | # handle callback gets (reverse lookup) |
|---|
| 159 | my $callback_text = bapi_callbacks::build_user_callback($func, 0); |
|---|
| 160 | if ($callback_text) { |
|---|
| 161 | printf FILE $callback_text; |
|---|
| 162 | } |
|---|
| 163 | |
|---|
| 164 | |
|---|
| 165 | if ($func->{RETTYPE} ne "void") { |
|---|
| 166 | if ($maps) { |
|---|
| 167 | print FILE " if (!st.__retval) {\n"; |
|---|
| 168 | print FILE $maps; |
|---|
| 169 | print FILE " }\n"; |
|---|
| 170 | } |
|---|
| 171 | print FILE " return st.__retval;\n"; |
|---|
| 172 | } |
|---|
| 173 | else { |
|---|
| 174 | if ($maps) { |
|---|
| 175 | print FILE $maps; |
|---|
| 176 | } |
|---|
| 177 | } |
|---|
| 178 | print FILE "}\n\n"; |
|---|
| 179 | } |
|---|
| 180 | close FILE; |
|---|
| 181 | } |
|---|
| 182 | |
|---|
| 183 | 1; |
|---|