OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2009 NVIDIA Corporation. |
| 3 * All rights reserved. |
| 4 * |
| 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are met: |
| 7 * |
| 8 * Redistributions of source code must retain the above copyright notice, |
| 9 * this list of conditions and the following disclaimer. |
| 10 * |
| 11 * Redistributions in binary form must reproduce the above copyright notice, |
| 12 * this list of conditions and the following disclaimer in the documentation |
| 13 * and/or other materials provided with the distribution. |
| 14 * |
| 15 * Neither the name of the NVIDIA Corporation nor the names of its contributors |
| 16 * may be used to endorse or promote products derived from this software |
| 17 * without specific prior written permission. |
| 18 * |
| 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 29 * POSSIBILITY OF SUCH DAMAGE. |
| 30 * |
| 31 */ |
| 32 |
| 33 #define NV_IDL_IS_DISPATCH |
| 34 |
| 35 #include "nvcommon.h" |
| 36 #include "nvos.h" |
| 37 #include "nvassert.h" |
| 38 #include "nvreftrack.h" |
| 39 #include "nvidlcmd.h" |
| 40 #include "nvrm_owr.h" |
| 41 |
| 42 #define OFFSET( s, e ) (NvU32)(void *)(&(((s*)0)->e)) |
| 43 |
| 44 |
| 45 typedef struct NvRmOwrTransaction_in_t |
| 46 { |
| 47 NvU32 package_; |
| 48 NvU32 function_; |
| 49 NvRmOwrHandle hOwr; |
| 50 NvU32 OwrPinMap; |
| 51 NvU8 * Data; |
| 52 NvU32 DataLen; |
| 53 NvRmOwrTransactionInfo * Transaction; |
| 54 NvU32 NumOfTransactions; |
| 55 } NV_ALIGN(4) NvRmOwrTransaction_in; |
| 56 |
| 57 typedef struct NvRmOwrTransaction_inout_t |
| 58 { |
| 59 NvU32 dummy_; |
| 60 } NV_ALIGN(4) NvRmOwrTransaction_inout; |
| 61 |
| 62 typedef struct NvRmOwrTransaction_out_t |
| 63 { |
| 64 NvError ret_; |
| 65 } NV_ALIGN(4) NvRmOwrTransaction_out; |
| 66 |
| 67 typedef struct NvRmOwrTransaction_params_t |
| 68 { |
| 69 NvRmOwrTransaction_in in; |
| 70 NvRmOwrTransaction_inout inout; |
| 71 NvRmOwrTransaction_out out; |
| 72 } NvRmOwrTransaction_params; |
| 73 |
| 74 typedef struct NvRmOwrClose_in_t |
| 75 { |
| 76 NvU32 package_; |
| 77 NvU32 function_; |
| 78 NvRmOwrHandle hOwr; |
| 79 } NV_ALIGN(4) NvRmOwrClose_in; |
| 80 |
| 81 typedef struct NvRmOwrClose_inout_t |
| 82 { |
| 83 NvU32 dummy_; |
| 84 } NV_ALIGN(4) NvRmOwrClose_inout; |
| 85 |
| 86 typedef struct NvRmOwrClose_out_t |
| 87 { |
| 88 NvU32 dummy_; |
| 89 } NV_ALIGN(4) NvRmOwrClose_out; |
| 90 |
| 91 typedef struct NvRmOwrClose_params_t |
| 92 { |
| 93 NvRmOwrClose_in in; |
| 94 NvRmOwrClose_inout inout; |
| 95 NvRmOwrClose_out out; |
| 96 } NvRmOwrClose_params; |
| 97 |
| 98 typedef struct NvRmOwrOpen_in_t |
| 99 { |
| 100 NvU32 package_; |
| 101 NvU32 function_; |
| 102 NvRmDeviceHandle hDevice; |
| 103 NvU32 instance; |
| 104 } NV_ALIGN(4) NvRmOwrOpen_in; |
| 105 |
| 106 typedef struct NvRmOwrOpen_inout_t |
| 107 { |
| 108 NvU32 dummy_; |
| 109 } NV_ALIGN(4) NvRmOwrOpen_inout; |
| 110 |
| 111 typedef struct NvRmOwrOpen_out_t |
| 112 { |
| 113 NvError ret_; |
| 114 NvRmOwrHandle hOwr; |
| 115 } NV_ALIGN(4) NvRmOwrOpen_out; |
| 116 |
| 117 typedef struct NvRmOwrOpen_params_t |
| 118 { |
| 119 NvRmOwrOpen_in in; |
| 120 NvRmOwrOpen_inout inout; |
| 121 NvRmOwrOpen_out out; |
| 122 } NvRmOwrOpen_params; |
| 123 |
| 124 static NvError NvRmOwrTransaction_dispatch_( void *InBuffer, NvU32 InSize, void
*OutBuffer, NvU32 OutSize, NvDispatchCtx* Ctx ) |
| 125 { |
| 126 NvError err_ = NvSuccess; |
| 127 NvRmOwrTransaction_in *p_in; |
| 128 NvRmOwrTransaction_out *p_out; |
| 129 NvU8 *Data = NULL; |
| 130 NvRmOwrTransactionInfo *Transaction = NULL; |
| 131 |
| 132 p_in = (NvRmOwrTransaction_in *)InBuffer; |
| 133 p_out = (NvRmOwrTransaction_out *)((NvU8 *)OutBuffer + OFFSET(NvRmOwrTransac
tion_params, out) - OFFSET(NvRmOwrTransaction_params, inout)); |
| 134 |
| 135 if( p_in->DataLen && p_in->Data ) |
| 136 { |
| 137 Data = (NvU8 *)NvOsAlloc( p_in->DataLen * sizeof( NvU8 ) ); |
| 138 if( !Data ) |
| 139 { |
| 140 err_ = NvError_InsufficientMemory; |
| 141 goto clean; |
| 142 } |
| 143 if( p_in->Data ) |
| 144 { |
| 145 err_ = NvOsCopyIn( Data, p_in->Data, p_in->DataLen * sizeof( NvU8 )
); |
| 146 if( err_ != NvSuccess ) |
| 147 { |
| 148 err_ = NvError_BadParameter; |
| 149 goto clean; |
| 150 } |
| 151 } |
| 152 } |
| 153 if( p_in->NumOfTransactions && p_in->Transaction ) |
| 154 { |
| 155 Transaction = (NvRmOwrTransactionInfo *)NvOsAlloc( p_in->NumOfTransacti
ons * sizeof( NvRmOwrTransactionInfo ) ); |
| 156 if( !Transaction ) |
| 157 { |
| 158 err_ = NvError_InsufficientMemory; |
| 159 goto clean; |
| 160 } |
| 161 if( p_in->Transaction ) |
| 162 { |
| 163 err_ = NvOsCopyIn( Transaction, p_in->Transaction, p_in->NumOfTransa
ctions * sizeof( NvRmOwrTransactionInfo ) ); |
| 164 if( err_ != NvSuccess ) |
| 165 { |
| 166 err_ = NvError_BadParameter; |
| 167 goto clean; |
| 168 } |
| 169 } |
| 170 } |
| 171 |
| 172 p_out->ret_ = NvRmOwrTransaction( p_in->hOwr, p_in->OwrPinMap, Data, p_in->D
ataLen, Transaction, p_in->NumOfTransactions ); |
| 173 |
| 174 if(p_in->Data && Data) |
| 175 { |
| 176 err_ = NvOsCopyOut( p_in->Data, Data, p_in->DataLen * sizeof( NvU8 ) ); |
| 177 if( err_ != NvSuccess ) |
| 178 { |
| 179 err_ = NvError_BadParameter; |
| 180 } |
| 181 } |
| 182 clean: |
| 183 NvOsFree( Data ); |
| 184 NvOsFree( Transaction ); |
| 185 return err_; |
| 186 } |
| 187 |
| 188 static NvError NvRmOwrClose_dispatch_( void *InBuffer, NvU32 InSize, void *OutBu
ffer, NvU32 OutSize, NvDispatchCtx* Ctx ) |
| 189 { |
| 190 NvError err_ = NvSuccess; |
| 191 NvRmOwrClose_in *p_in; |
| 192 |
| 193 p_in = (NvRmOwrClose_in *)InBuffer; |
| 194 |
| 195 |
| 196 NvRmOwrClose( p_in->hOwr ); |
| 197 |
| 198 return err_; |
| 199 } |
| 200 |
| 201 static NvError NvRmOwrOpen_dispatch_( void *InBuffer, NvU32 InSize, void *OutBuf
fer, NvU32 OutSize, NvDispatchCtx* Ctx ) |
| 202 { |
| 203 NvError err_ = NvSuccess; |
| 204 NvRmOwrOpen_in *p_in; |
| 205 NvRmOwrOpen_out *p_out; |
| 206 |
| 207 p_in = (NvRmOwrOpen_in *)InBuffer; |
| 208 p_out = (NvRmOwrOpen_out *)((NvU8 *)OutBuffer + OFFSET(NvRmOwrOpen_params, o
ut) - OFFSET(NvRmOwrOpen_params, inout)); |
| 209 |
| 210 |
| 211 p_out->ret_ = NvRmOwrOpen( p_in->hDevice, p_in->instance, &p_out->hOwr ); |
| 212 |
| 213 return err_; |
| 214 } |
| 215 |
| 216 NvError nvrm_owr_Dispatch( NvU32 function, void *InBuffer, NvU32 InSize, void *O
utBuffer, NvU32 OutSize, NvDispatchCtx* Ctx ); |
| 217 NvError nvrm_owr_Dispatch( NvU32 function, void *InBuffer, NvU32 InSize, void *O
utBuffer, NvU32 OutSize, NvDispatchCtx* Ctx ) |
| 218 { |
| 219 NvError err_ = NvSuccess; |
| 220 |
| 221 switch( function ) { |
| 222 case 2: |
| 223 err_ = NvRmOwrTransaction_dispatch_( InBuffer, InSize, OutBuffer, OutSiz
e, Ctx ); |
| 224 break; |
| 225 case 1: |
| 226 err_ = NvRmOwrClose_dispatch_( InBuffer, InSize, OutBuffer, OutSize, Ctx
); |
| 227 break; |
| 228 case 0: |
| 229 err_ = NvRmOwrOpen_dispatch_( InBuffer, InSize, OutBuffer, OutSize, Ctx
); |
| 230 break; |
| 231 default: |
| 232 err_ = NvError_BadParameter; |
| 233 break; |
| 234 } |
| 235 |
| 236 return err_; |
| 237 } |
OLD | NEW |