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_pcie.h" |
| 41 |
| 42 #define OFFSET( s, e ) (NvU32)(void *)(&(((s*)0)->e)) |
| 43 |
| 44 |
| 45 typedef struct NvRmUnmapPciMemory_in_t |
| 46 { |
| 47 NvU32 package_; |
| 48 NvU32 function_; |
| 49 NvRmDeviceHandle hDeviceHandle; |
| 50 NvRmPhysAddr mem; |
| 51 NvU32 size; |
| 52 } NV_ALIGN(4) NvRmUnmapPciMemory_in; |
| 53 |
| 54 typedef struct NvRmUnmapPciMemory_inout_t |
| 55 { |
| 56 NvU32 dummy_; |
| 57 } NV_ALIGN(4) NvRmUnmapPciMemory_inout; |
| 58 |
| 59 typedef struct NvRmUnmapPciMemory_out_t |
| 60 { |
| 61 NvU32 dummy_; |
| 62 } NV_ALIGN(4) NvRmUnmapPciMemory_out; |
| 63 |
| 64 typedef struct NvRmUnmapPciMemory_params_t |
| 65 { |
| 66 NvRmUnmapPciMemory_in in; |
| 67 NvRmUnmapPciMemory_inout inout; |
| 68 NvRmUnmapPciMemory_out out; |
| 69 } NvRmUnmapPciMemory_params; |
| 70 |
| 71 typedef struct NvRmMapPciMemory_in_t |
| 72 { |
| 73 NvU32 package_; |
| 74 NvU32 function_; |
| 75 NvRmDeviceHandle hDeviceHandle; |
| 76 NvRmPciPhysAddr mem; |
| 77 NvU32 size; |
| 78 } NV_ALIGN(4) NvRmMapPciMemory_in; |
| 79 |
| 80 typedef struct NvRmMapPciMemory_inout_t |
| 81 { |
| 82 NvU32 dummy_; |
| 83 } NV_ALIGN(4) NvRmMapPciMemory_inout; |
| 84 |
| 85 typedef struct NvRmMapPciMemory_out_t |
| 86 { |
| 87 NvRmPhysAddr ret_; |
| 88 } NV_ALIGN(4) NvRmMapPciMemory_out; |
| 89 |
| 90 typedef struct NvRmMapPciMemory_params_t |
| 91 { |
| 92 NvRmMapPciMemory_in in; |
| 93 NvRmMapPciMemory_inout inout; |
| 94 NvRmMapPciMemory_out out; |
| 95 } NvRmMapPciMemory_params; |
| 96 |
| 97 typedef struct NvRmRegisterPcieLegacyHandler_in_t |
| 98 { |
| 99 NvU32 package_; |
| 100 NvU32 function_; |
| 101 NvRmDeviceHandle hDeviceHandle; |
| 102 NvU32 function_device_bus; |
| 103 NvOsSemaphoreHandle sem; |
| 104 NvBool InterruptEnable; |
| 105 } NV_ALIGN(4) NvRmRegisterPcieLegacyHandler_in; |
| 106 |
| 107 typedef struct NvRmRegisterPcieLegacyHandler_inout_t |
| 108 { |
| 109 NvU32 dummy_; |
| 110 } NV_ALIGN(4) NvRmRegisterPcieLegacyHandler_inout; |
| 111 |
| 112 typedef struct NvRmRegisterPcieLegacyHandler_out_t |
| 113 { |
| 114 NvError ret_; |
| 115 } NV_ALIGN(4) NvRmRegisterPcieLegacyHandler_out; |
| 116 |
| 117 typedef struct NvRmRegisterPcieLegacyHandler_params_t |
| 118 { |
| 119 NvRmRegisterPcieLegacyHandler_in in; |
| 120 NvRmRegisterPcieLegacyHandler_inout inout; |
| 121 NvRmRegisterPcieLegacyHandler_out out; |
| 122 } NvRmRegisterPcieLegacyHandler_params; |
| 123 |
| 124 typedef struct NvRmRegisterPcieMSIHandler_in_t |
| 125 { |
| 126 NvU32 package_; |
| 127 NvU32 function_; |
| 128 NvRmDeviceHandle hDeviceHandle; |
| 129 NvU32 function_device_bus; |
| 130 NvU32 index; |
| 131 NvOsSemaphoreHandle sem; |
| 132 NvBool InterruptEnable; |
| 133 } NV_ALIGN(4) NvRmRegisterPcieMSIHandler_in; |
| 134 |
| 135 typedef struct NvRmRegisterPcieMSIHandler_inout_t |
| 136 { |
| 137 NvU32 dummy_; |
| 138 } NV_ALIGN(4) NvRmRegisterPcieMSIHandler_inout; |
| 139 |
| 140 typedef struct NvRmRegisterPcieMSIHandler_out_t |
| 141 { |
| 142 NvError ret_; |
| 143 } NV_ALIGN(4) NvRmRegisterPcieMSIHandler_out; |
| 144 |
| 145 typedef struct NvRmRegisterPcieMSIHandler_params_t |
| 146 { |
| 147 NvRmRegisterPcieMSIHandler_in in; |
| 148 NvRmRegisterPcieMSIHandler_inout inout; |
| 149 NvRmRegisterPcieMSIHandler_out out; |
| 150 } NvRmRegisterPcieMSIHandler_params; |
| 151 |
| 152 typedef struct NvRmReadWriteConfigSpace_in_t |
| 153 { |
| 154 NvU32 package_; |
| 155 NvU32 function_; |
| 156 NvRmDeviceHandle hDeviceHandle; |
| 157 NvU32 bus_number; |
| 158 NvRmPcieAccessType type; |
| 159 NvU32 offset; |
| 160 NvU8 * Data; |
| 161 NvU32 DataLen; |
| 162 } NV_ALIGN(4) NvRmReadWriteConfigSpace_in; |
| 163 |
| 164 typedef struct NvRmReadWriteConfigSpace_inout_t |
| 165 { |
| 166 NvU32 dummy_; |
| 167 } NV_ALIGN(4) NvRmReadWriteConfigSpace_inout; |
| 168 |
| 169 typedef struct NvRmReadWriteConfigSpace_out_t |
| 170 { |
| 171 NvError ret_; |
| 172 } NV_ALIGN(4) NvRmReadWriteConfigSpace_out; |
| 173 |
| 174 typedef struct NvRmReadWriteConfigSpace_params_t |
| 175 { |
| 176 NvRmReadWriteConfigSpace_in in; |
| 177 NvRmReadWriteConfigSpace_inout inout; |
| 178 NvRmReadWriteConfigSpace_out out; |
| 179 } NvRmReadWriteConfigSpace_params; |
| 180 |
| 181 static NvError NvRmUnmapPciMemory_dispatch_( void *InBuffer, NvU32 InSize, void
*OutBuffer, NvU32 OutSize, NvDispatchCtx* Ctx ) |
| 182 { |
| 183 NvError err_ = NvSuccess; |
| 184 NvRmUnmapPciMemory_in *p_in; |
| 185 |
| 186 p_in = (NvRmUnmapPciMemory_in *)InBuffer; |
| 187 |
| 188 |
| 189 NvRmUnmapPciMemory( p_in->hDeviceHandle, p_in->mem, p_in->size ); |
| 190 |
| 191 return err_; |
| 192 } |
| 193 |
| 194 static NvError NvRmMapPciMemory_dispatch_( void *InBuffer, NvU32 InSize, void *O
utBuffer, NvU32 OutSize, NvDispatchCtx* Ctx ) |
| 195 { |
| 196 NvError err_ = NvSuccess; |
| 197 NvRmMapPciMemory_in *p_in; |
| 198 NvRmMapPciMemory_out *p_out; |
| 199 |
| 200 p_in = (NvRmMapPciMemory_in *)InBuffer; |
| 201 p_out = (NvRmMapPciMemory_out *)((NvU8 *)OutBuffer + OFFSET(NvRmMapPciMemory
_params, out) - OFFSET(NvRmMapPciMemory_params, inout)); |
| 202 |
| 203 |
| 204 p_out->ret_ = NvRmMapPciMemory( p_in->hDeviceHandle, p_in->mem, p_in->size )
; |
| 205 |
| 206 return err_; |
| 207 } |
| 208 |
| 209 static NvError NvRmRegisterPcieLegacyHandler_dispatch_( void *InBuffer, NvU32 In
Size, void *OutBuffer, NvU32 OutSize, NvDispatchCtx* Ctx ) |
| 210 { |
| 211 NvError err_ = NvSuccess; |
| 212 NvRmRegisterPcieLegacyHandler_in *p_in; |
| 213 NvRmRegisterPcieLegacyHandler_out *p_out; |
| 214 NvOsSemaphoreHandle sem = NULL; |
| 215 |
| 216 p_in = (NvRmRegisterPcieLegacyHandler_in *)InBuffer; |
| 217 p_out = (NvRmRegisterPcieLegacyHandler_out *)((NvU8 *)OutBuffer + OFFSET(NvR
mRegisterPcieLegacyHandler_params, out) - OFFSET(NvRmRegisterPcieLegacyHandler_p
arams, inout)); |
| 218 |
| 219 if( p_in->sem ) |
| 220 { |
| 221 err_ = NvOsSemaphoreUnmarshal( p_in->sem, &sem ); |
| 222 if( err_ != NvSuccess ) |
| 223 { |
| 224 err_ = NvError_BadParameter; |
| 225 goto clean; |
| 226 } |
| 227 } |
| 228 |
| 229 p_out->ret_ = NvRmRegisterPcieLegacyHandler( p_in->hDeviceHandle, p_in->func
tion_device_bus, sem, p_in->InterruptEnable ); |
| 230 |
| 231 clean: |
| 232 NvOsSemaphoreDestroy( sem ); |
| 233 return err_; |
| 234 } |
| 235 |
| 236 static NvError NvRmRegisterPcieMSIHandler_dispatch_( void *InBuffer, NvU32 InSiz
e, void *OutBuffer, NvU32 OutSize, NvDispatchCtx* Ctx ) |
| 237 { |
| 238 NvError err_ = NvSuccess; |
| 239 NvRmRegisterPcieMSIHandler_in *p_in; |
| 240 NvRmRegisterPcieMSIHandler_out *p_out; |
| 241 NvOsSemaphoreHandle sem = NULL; |
| 242 |
| 243 p_in = (NvRmRegisterPcieMSIHandler_in *)InBuffer; |
| 244 p_out = (NvRmRegisterPcieMSIHandler_out *)((NvU8 *)OutBuffer + OFFSET(NvRmRe
gisterPcieMSIHandler_params, out) - OFFSET(NvRmRegisterPcieMSIHandler_params, in
out)); |
| 245 |
| 246 if( p_in->sem ) |
| 247 { |
| 248 err_ = NvOsSemaphoreUnmarshal( p_in->sem, &sem ); |
| 249 if( err_ != NvSuccess ) |
| 250 { |
| 251 err_ = NvError_BadParameter; |
| 252 goto clean; |
| 253 } |
| 254 } |
| 255 |
| 256 p_out->ret_ = NvRmRegisterPcieMSIHandler( p_in->hDeviceHandle, p_in->functio
n_device_bus, p_in->index, sem, p_in->InterruptEnable ); |
| 257 |
| 258 clean: |
| 259 NvOsSemaphoreDestroy( sem ); |
| 260 return err_; |
| 261 } |
| 262 |
| 263 static NvError NvRmReadWriteConfigSpace_dispatch_( void *InBuffer, NvU32 InSize,
void *OutBuffer, NvU32 OutSize, NvDispatchCtx* Ctx ) |
| 264 { |
| 265 NvError err_ = NvSuccess; |
| 266 NvRmReadWriteConfigSpace_in *p_in; |
| 267 NvRmReadWriteConfigSpace_out *p_out; |
| 268 NvU8 *Data = NULL; |
| 269 |
| 270 p_in = (NvRmReadWriteConfigSpace_in *)InBuffer; |
| 271 p_out = (NvRmReadWriteConfigSpace_out *)((NvU8 *)OutBuffer + OFFSET(NvRmRead
WriteConfigSpace_params, out) - OFFSET(NvRmReadWriteConfigSpace_params, inout)); |
| 272 |
| 273 if( p_in->DataLen && p_in->Data ) |
| 274 { |
| 275 Data = (NvU8 *)NvOsAlloc( p_in->DataLen * sizeof( NvU8 ) ); |
| 276 if( !Data ) |
| 277 { |
| 278 err_ = NvError_InsufficientMemory; |
| 279 goto clean; |
| 280 } |
| 281 if( p_in->Data ) |
| 282 { |
| 283 err_ = NvOsCopyIn( Data, p_in->Data, p_in->DataLen * sizeof( NvU8 )
); |
| 284 if( err_ != NvSuccess ) |
| 285 { |
| 286 err_ = NvError_BadParameter; |
| 287 goto clean; |
| 288 } |
| 289 } |
| 290 } |
| 291 |
| 292 p_out->ret_ = NvRmReadWriteConfigSpace( p_in->hDeviceHandle, p_in->bus_numbe
r, p_in->type, p_in->offset, Data, p_in->DataLen ); |
| 293 |
| 294 if(p_in->Data && Data) |
| 295 { |
| 296 err_ = NvOsCopyOut( p_in->Data, Data, p_in->DataLen * sizeof( NvU8 ) ); |
| 297 if( err_ != NvSuccess ) |
| 298 { |
| 299 err_ = NvError_BadParameter; |
| 300 } |
| 301 } |
| 302 clean: |
| 303 NvOsFree( Data ); |
| 304 return err_; |
| 305 } |
| 306 |
| 307 NvError nvrm_pcie_Dispatch( NvU32 function, void *InBuffer, NvU32 InSize, void *
OutBuffer, NvU32 OutSize, NvDispatchCtx* Ctx ); |
| 308 NvError nvrm_pcie_Dispatch( NvU32 function, void *InBuffer, NvU32 InSize, void *
OutBuffer, NvU32 OutSize, NvDispatchCtx* Ctx ) |
| 309 { |
| 310 NvError err_ = NvSuccess; |
| 311 |
| 312 switch( function ) { |
| 313 case 4: |
| 314 err_ = NvRmUnmapPciMemory_dispatch_( InBuffer, InSize, OutBuffer, OutSiz
e, Ctx ); |
| 315 break; |
| 316 case 3: |
| 317 err_ = NvRmMapPciMemory_dispatch_( InBuffer, InSize, OutBuffer, OutSize,
Ctx ); |
| 318 break; |
| 319 case 2: |
| 320 err_ = NvRmRegisterPcieLegacyHandler_dispatch_( InBuffer, InSize, OutBuf
fer, OutSize, Ctx ); |
| 321 break; |
| 322 case 1: |
| 323 err_ = NvRmRegisterPcieMSIHandler_dispatch_( InBuffer, InSize, OutBuffer
, OutSize, Ctx ); |
| 324 break; |
| 325 case 0: |
| 326 err_ = NvRmReadWriteConfigSpace_dispatch_( InBuffer, InSize, OutBuffer,
OutSize, Ctx ); |
| 327 break; |
| 328 default: |
| 329 err_ = NvError_BadParameter; |
| 330 break; |
| 331 } |
| 332 |
| 333 return err_; |
| 334 } |
OLD | NEW |