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_spi.h" |
| 41 |
| 42 #define OFFSET( s, e ) (NvU32)(void *)(&(((s*)0)->e)) |
| 43 |
| 44 |
| 45 typedef struct NvRmSpiSetSignalMode_in_t |
| 46 { |
| 47 NvU32 package_; |
| 48 NvU32 function_; |
| 49 NvRmSpiHandle hRmSpi; |
| 50 NvU32 ChipSelectId; |
| 51 NvU32 SpiSignalMode; |
| 52 } NV_ALIGN(4) NvRmSpiSetSignalMode_in; |
| 53 |
| 54 typedef struct NvRmSpiSetSignalMode_inout_t |
| 55 { |
| 56 NvU32 dummy_; |
| 57 } NV_ALIGN(4) NvRmSpiSetSignalMode_inout; |
| 58 |
| 59 typedef struct NvRmSpiSetSignalMode_out_t |
| 60 { |
| 61 NvU32 dummy_; |
| 62 } NV_ALIGN(4) NvRmSpiSetSignalMode_out; |
| 63 |
| 64 typedef struct NvRmSpiSetSignalMode_params_t |
| 65 { |
| 66 NvRmSpiSetSignalMode_in in; |
| 67 NvRmSpiSetSignalMode_inout inout; |
| 68 NvRmSpiSetSignalMode_out out; |
| 69 } NvRmSpiSetSignalMode_params; |
| 70 |
| 71 typedef struct NvRmSpiGetTransactionData_in_t |
| 72 { |
| 73 NvU32 package_; |
| 74 NvU32 function_; |
| 75 NvRmSpiHandle hRmSpi; |
| 76 NvU8 * pReadBuffer; |
| 77 NvU32 BytesRequested; |
| 78 NvU32 WaitTimeout; |
| 79 } NV_ALIGN(4) NvRmSpiGetTransactionData_in; |
| 80 |
| 81 typedef struct NvRmSpiGetTransactionData_inout_t |
| 82 { |
| 83 NvU32 dummy_; |
| 84 } NV_ALIGN(4) NvRmSpiGetTransactionData_inout; |
| 85 |
| 86 typedef struct NvRmSpiGetTransactionData_out_t |
| 87 { |
| 88 NvError ret_; |
| 89 NvU32 pBytesTransfererd; |
| 90 } NV_ALIGN(4) NvRmSpiGetTransactionData_out; |
| 91 |
| 92 typedef struct NvRmSpiGetTransactionData_params_t |
| 93 { |
| 94 NvRmSpiGetTransactionData_in in; |
| 95 NvRmSpiGetTransactionData_inout inout; |
| 96 NvRmSpiGetTransactionData_out out; |
| 97 } NvRmSpiGetTransactionData_params; |
| 98 |
| 99 typedef struct NvRmSpiStartTransaction_in_t |
| 100 { |
| 101 NvU32 package_; |
| 102 NvU32 function_; |
| 103 NvRmSpiHandle hRmSpi; |
| 104 NvU32 ChipSelectId; |
| 105 NvU32 ClockSpeedInKHz; |
| 106 NvBool IsReadTransfer; |
| 107 NvU8 * pWriteBuffer; |
| 108 NvU32 BytesRequested; |
| 109 NvU32 PacketSizeInBits; |
| 110 } NV_ALIGN(4) NvRmSpiStartTransaction_in; |
| 111 |
| 112 typedef struct NvRmSpiStartTransaction_inout_t |
| 113 { |
| 114 NvU32 dummy_; |
| 115 } NV_ALIGN(4) NvRmSpiStartTransaction_inout; |
| 116 |
| 117 typedef struct NvRmSpiStartTransaction_out_t |
| 118 { |
| 119 NvError ret_; |
| 120 } NV_ALIGN(4) NvRmSpiStartTransaction_out; |
| 121 |
| 122 typedef struct NvRmSpiStartTransaction_params_t |
| 123 { |
| 124 NvRmSpiStartTransaction_in in; |
| 125 NvRmSpiStartTransaction_inout inout; |
| 126 NvRmSpiStartTransaction_out out; |
| 127 } NvRmSpiStartTransaction_params; |
| 128 |
| 129 typedef struct NvRmSpiTransaction_in_t |
| 130 { |
| 131 NvU32 package_; |
| 132 NvU32 function_; |
| 133 NvRmSpiHandle hRmSpi; |
| 134 NvU32 SpiPinMap; |
| 135 NvU32 ChipSelectId; |
| 136 NvU32 ClockSpeedInKHz; |
| 137 NvU8 * pReadBuffer; |
| 138 NvU8 * pWriteBuffer; |
| 139 NvU32 BytesRequested; |
| 140 NvU32 PacketSizeInBits; |
| 141 } NV_ALIGN(4) NvRmSpiTransaction_in; |
| 142 |
| 143 typedef struct NvRmSpiTransaction_inout_t |
| 144 { |
| 145 NvU32 dummy_; |
| 146 } NV_ALIGN(4) NvRmSpiTransaction_inout; |
| 147 |
| 148 typedef struct NvRmSpiTransaction_out_t |
| 149 { |
| 150 NvU32 dummy_; |
| 151 } NV_ALIGN(4) NvRmSpiTransaction_out; |
| 152 |
| 153 typedef struct NvRmSpiTransaction_params_t |
| 154 { |
| 155 NvRmSpiTransaction_in in; |
| 156 NvRmSpiTransaction_inout inout; |
| 157 NvRmSpiTransaction_out out; |
| 158 } NvRmSpiTransaction_params; |
| 159 |
| 160 typedef struct NvRmSpiClose_in_t |
| 161 { |
| 162 NvU32 package_; |
| 163 NvU32 function_; |
| 164 NvRmSpiHandle hRmSpi; |
| 165 } NV_ALIGN(4) NvRmSpiClose_in; |
| 166 |
| 167 typedef struct NvRmSpiClose_inout_t |
| 168 { |
| 169 NvU32 dummy_; |
| 170 } NV_ALIGN(4) NvRmSpiClose_inout; |
| 171 |
| 172 typedef struct NvRmSpiClose_out_t |
| 173 { |
| 174 NvU32 dummy_; |
| 175 } NV_ALIGN(4) NvRmSpiClose_out; |
| 176 |
| 177 typedef struct NvRmSpiClose_params_t |
| 178 { |
| 179 NvRmSpiClose_in in; |
| 180 NvRmSpiClose_inout inout; |
| 181 NvRmSpiClose_out out; |
| 182 } NvRmSpiClose_params; |
| 183 |
| 184 typedef struct NvRmSpiOpen_in_t |
| 185 { |
| 186 NvU32 package_; |
| 187 NvU32 function_; |
| 188 NvRmDeviceHandle hRmDevice; |
| 189 NvU32 IoModule; |
| 190 NvU32 InstanceId; |
| 191 NvBool IsMasterMode; |
| 192 } NV_ALIGN(4) NvRmSpiOpen_in; |
| 193 |
| 194 typedef struct NvRmSpiOpen_inout_t |
| 195 { |
| 196 NvU32 dummy_; |
| 197 } NV_ALIGN(4) NvRmSpiOpen_inout; |
| 198 |
| 199 typedef struct NvRmSpiOpen_out_t |
| 200 { |
| 201 NvError ret_; |
| 202 NvRmSpiHandle phRmSpi; |
| 203 } NV_ALIGN(4) NvRmSpiOpen_out; |
| 204 |
| 205 typedef struct NvRmSpiOpen_params_t |
| 206 { |
| 207 NvRmSpiOpen_in in; |
| 208 NvRmSpiOpen_inout inout; |
| 209 NvRmSpiOpen_out out; |
| 210 } NvRmSpiOpen_params; |
| 211 |
| 212 static NvError NvRmSpiSetSignalMode_dispatch_( void *InBuffer, NvU32 InSize, voi
d *OutBuffer, NvU32 OutSize, NvDispatchCtx* Ctx ) |
| 213 { |
| 214 NvError err_ = NvSuccess; |
| 215 NvRmSpiSetSignalMode_in *p_in; |
| 216 |
| 217 p_in = (NvRmSpiSetSignalMode_in *)InBuffer; |
| 218 |
| 219 |
| 220 NvRmSpiSetSignalMode( p_in->hRmSpi, p_in->ChipSelectId, p_in->SpiSignalMode
); |
| 221 |
| 222 return err_; |
| 223 } |
| 224 |
| 225 static NvError NvRmSpiGetTransactionData_dispatch_( void *InBuffer, NvU32 InSize
, void *OutBuffer, NvU32 OutSize, NvDispatchCtx* Ctx ) |
| 226 { |
| 227 NvError err_ = NvSuccess; |
| 228 NvRmSpiGetTransactionData_in *p_in; |
| 229 NvRmSpiGetTransactionData_out *p_out; |
| 230 NvU8 *pReadBuffer = NULL; |
| 231 |
| 232 p_in = (NvRmSpiGetTransactionData_in *)InBuffer; |
| 233 p_out = (NvRmSpiGetTransactionData_out *)((NvU8 *)OutBuffer + OFFSET(NvRmSpi
GetTransactionData_params, out) - OFFSET(NvRmSpiGetTransactionData_params, inout
)); |
| 234 |
| 235 if( p_in->BytesRequested && p_in->pReadBuffer ) |
| 236 { |
| 237 pReadBuffer = (NvU8 *)NvOsAlloc( p_in->BytesRequested * sizeof( NvU8 )
); |
| 238 if( !pReadBuffer ) |
| 239 { |
| 240 err_ = NvError_InsufficientMemory; |
| 241 goto clean; |
| 242 } |
| 243 } |
| 244 |
| 245 p_out->ret_ = NvRmSpiGetTransactionData( p_in->hRmSpi, pReadBuffer, p_in->By
tesRequested, &p_out->pBytesTransfererd, p_in->WaitTimeout ); |
| 246 |
| 247 if(p_in->pReadBuffer && pReadBuffer) |
| 248 { |
| 249 err_ = NvOsCopyOut( p_in->pReadBuffer, pReadBuffer, p_in->BytesRequested
* sizeof( NvU8 ) ); |
| 250 if( err_ != NvSuccess ) |
| 251 { |
| 252 err_ = NvError_BadParameter; |
| 253 } |
| 254 } |
| 255 clean: |
| 256 NvOsFree( pReadBuffer ); |
| 257 return err_; |
| 258 } |
| 259 |
| 260 static NvError NvRmSpiStartTransaction_dispatch_( void *InBuffer, NvU32 InSize,
void *OutBuffer, NvU32 OutSize, NvDispatchCtx* Ctx ) |
| 261 { |
| 262 NvError err_ = NvSuccess; |
| 263 NvRmSpiStartTransaction_in *p_in; |
| 264 NvRmSpiStartTransaction_out *p_out; |
| 265 NvU8 *pWriteBuffer = NULL; |
| 266 |
| 267 p_in = (NvRmSpiStartTransaction_in *)InBuffer; |
| 268 p_out = (NvRmSpiStartTransaction_out *)((NvU8 *)OutBuffer + OFFSET(NvRmSpiSt
artTransaction_params, out) - OFFSET(NvRmSpiStartTransaction_params, inout)); |
| 269 |
| 270 if( p_in->BytesRequested && p_in->pWriteBuffer ) |
| 271 { |
| 272 pWriteBuffer = (NvU8 *)NvOsAlloc( p_in->BytesRequested * sizeof( NvU8
) ); |
| 273 if( !pWriteBuffer ) |
| 274 { |
| 275 err_ = NvError_InsufficientMemory; |
| 276 goto clean; |
| 277 } |
| 278 if( p_in->pWriteBuffer ) |
| 279 { |
| 280 err_ = NvOsCopyIn( pWriteBuffer, p_in->pWriteBuffer, p_in->BytesRequ
ested * sizeof( NvU8 ) ); |
| 281 if( err_ != NvSuccess ) |
| 282 { |
| 283 err_ = NvError_BadParameter; |
| 284 goto clean; |
| 285 } |
| 286 } |
| 287 } |
| 288 |
| 289 p_out->ret_ = NvRmSpiStartTransaction( p_in->hRmSpi, p_in->ChipSelectId, p_i
n->ClockSpeedInKHz, p_in->IsReadTransfer, pWriteBuffer, p_in->BytesRequested, p_
in->PacketSizeInBits ); |
| 290 |
| 291 clean: |
| 292 NvOsFree( pWriteBuffer ); |
| 293 return err_; |
| 294 } |
| 295 |
| 296 static NvError NvRmSpiTransaction_dispatch_( void *InBuffer, NvU32 InSize, void
*OutBuffer, NvU32 OutSize, NvDispatchCtx* Ctx ) |
| 297 { |
| 298 NvError err_ = NvSuccess; |
| 299 NvRmSpiTransaction_in *p_in; |
| 300 NvU8 *pReadBuffer = NULL; |
| 301 NvU8 *pWriteBuffer = NULL; |
| 302 |
| 303 p_in = (NvRmSpiTransaction_in *)InBuffer; |
| 304 |
| 305 if( p_in->BytesRequested && p_in->pReadBuffer ) |
| 306 { |
| 307 pReadBuffer = (NvU8 *)NvOsAlloc( p_in->BytesRequested * sizeof( NvU8 )
); |
| 308 if( !pReadBuffer ) |
| 309 { |
| 310 err_ = NvError_InsufficientMemory; |
| 311 goto clean; |
| 312 } |
| 313 } |
| 314 if( p_in->BytesRequested && p_in->pWriteBuffer ) |
| 315 { |
| 316 pWriteBuffer = (NvU8 *)NvOsAlloc( p_in->BytesRequested * sizeof( NvU8
) ); |
| 317 if( !pWriteBuffer ) |
| 318 { |
| 319 err_ = NvError_InsufficientMemory; |
| 320 goto clean; |
| 321 } |
| 322 if( p_in->pWriteBuffer ) |
| 323 { |
| 324 err_ = NvOsCopyIn( pWriteBuffer, p_in->pWriteBuffer, p_in->BytesRequ
ested * sizeof( NvU8 ) ); |
| 325 if( err_ != NvSuccess ) |
| 326 { |
| 327 err_ = NvError_BadParameter; |
| 328 goto clean; |
| 329 } |
| 330 } |
| 331 } |
| 332 |
| 333 NvRmSpiTransaction( p_in->hRmSpi, p_in->SpiPinMap, p_in->ChipSelectId, p_in-
>ClockSpeedInKHz, pReadBuffer, pWriteBuffer, p_in->BytesRequested, p_in->PacketS
izeInBits ); |
| 334 |
| 335 if(p_in->pReadBuffer && pReadBuffer) |
| 336 { |
| 337 err_ = NvOsCopyOut( p_in->pReadBuffer, pReadBuffer, p_in->BytesRequested
* sizeof( NvU8 ) ); |
| 338 if( err_ != NvSuccess ) |
| 339 { |
| 340 err_ = NvError_BadParameter; |
| 341 } |
| 342 } |
| 343 clean: |
| 344 NvOsFree( pReadBuffer ); |
| 345 NvOsFree( pWriteBuffer ); |
| 346 return err_; |
| 347 } |
| 348 |
| 349 static NvError NvRmSpiClose_dispatch_( void *InBuffer, NvU32 InSize, void *OutBu
ffer, NvU32 OutSize, NvDispatchCtx* Ctx ) |
| 350 { |
| 351 NvError err_ = NvSuccess; |
| 352 NvRmSpiClose_in *p_in; |
| 353 |
| 354 p_in = (NvRmSpiClose_in *)InBuffer; |
| 355 |
| 356 |
| 357 NvRmSpiClose( p_in->hRmSpi ); |
| 358 |
| 359 return err_; |
| 360 } |
| 361 |
| 362 static NvError NvRmSpiOpen_dispatch_( void *InBuffer, NvU32 InSize, void *OutBuf
fer, NvU32 OutSize, NvDispatchCtx* Ctx ) |
| 363 { |
| 364 NvError err_ = NvSuccess; |
| 365 NvRmSpiOpen_in *p_in; |
| 366 NvRmSpiOpen_out *p_out; |
| 367 |
| 368 p_in = (NvRmSpiOpen_in *)InBuffer; |
| 369 p_out = (NvRmSpiOpen_out *)((NvU8 *)OutBuffer + OFFSET(NvRmSpiOpen_params, o
ut) - OFFSET(NvRmSpiOpen_params, inout)); |
| 370 |
| 371 |
| 372 p_out->ret_ = NvRmSpiOpen( p_in->hRmDevice, p_in->IoModule, p_in->InstanceId
, p_in->IsMasterMode, &p_out->phRmSpi ); |
| 373 |
| 374 return err_; |
| 375 } |
| 376 |
| 377 NvError nvrm_spi_Dispatch( NvU32 function, void *InBuffer, NvU32 InSize, void *O
utBuffer, NvU32 OutSize, NvDispatchCtx* Ctx ); |
| 378 NvError nvrm_spi_Dispatch( NvU32 function, void *InBuffer, NvU32 InSize, void *O
utBuffer, NvU32 OutSize, NvDispatchCtx* Ctx ) |
| 379 { |
| 380 NvError err_ = NvSuccess; |
| 381 |
| 382 switch( function ) { |
| 383 case 5: |
| 384 err_ = NvRmSpiSetSignalMode_dispatch_( InBuffer, InSize, OutBuffer, OutS
ize, Ctx ); |
| 385 break; |
| 386 case 4: |
| 387 err_ = NvRmSpiGetTransactionData_dispatch_( InBuffer, InSize, OutBuffer,
OutSize, Ctx ); |
| 388 break; |
| 389 case 3: |
| 390 err_ = NvRmSpiStartTransaction_dispatch_( InBuffer, InSize, OutBuffer, O
utSize, Ctx ); |
| 391 break; |
| 392 case 2: |
| 393 err_ = NvRmSpiTransaction_dispatch_( InBuffer, InSize, OutBuffer, OutSiz
e, Ctx ); |
| 394 break; |
| 395 case 1: |
| 396 err_ = NvRmSpiClose_dispatch_( InBuffer, InSize, OutBuffer, OutSize, Ctx
); |
| 397 break; |
| 398 case 0: |
| 399 err_ = NvRmSpiOpen_dispatch_( InBuffer, InSize, OutBuffer, OutSize, Ctx
); |
| 400 break; |
| 401 default: |
| 402 err_ = NvError_BadParameter; |
| 403 break; |
| 404 } |
| 405 |
| 406 return err_; |
| 407 } |
OLD | NEW |