- Timestamp:
- Sep 17, 2007 9:43:35 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/Support/solaris/SUPDrv-solaris.c
r4834 r4851 134 134 }; 135 135 136 #ifndef USE_SESSION_HASH 137 /** 138 * State info for each open file handle. 139 */ 140 typedef struct 141 { 142 /**< Pointer to the session data. */ 143 PSUPDRVSESSION pSession; 144 } vbox_devstate_t; 145 #else 136 146 /** State info. for each driver instance. */ 137 147 typedef struct … … 139 149 dev_info_t *pDip; /* Device handle */ 140 150 } vbox_devstate_t; 151 #endif 141 152 142 153 /** Opaque pointer to state */ … … 159 170 * Kernel entry points 160 171 */ 161 int _init 172 int _init(void) 162 173 { 163 174 cmn_err(CE_CONT, "VBoxDrvSolaris _init"); 164 175 165 int e = ddi_soft_state_init(&g_pVBoxDrvSolarisState, sizeof (vbox_devstate_t), 1); 166 if (e != 0) 167 return e; 168 169 e = mod_install(&g_VBoxDrvSolarisModLinkage); 170 if (e != 0) 176 int rc = ddi_soft_state_init(&g_pVBoxDrvSolarisState, sizeof(vbox_devstate_t), 8); 177 if (!rc) 178 { 179 rc = mod_install(&g_VBoxDrvSolarisModLinkage); 180 if (!rc) 181 return 0; /* success */ 182 171 183 ddi_soft_state_fini(&g_pVBoxDrvSolarisState); 172 173 cmn_err(CE_CONT, "VBoxDrvSolaris _init returns %d", e); 174 return e; 175 } 176 177 int _fini (void) 184 } 185 186 cmn_err(CE_CONT, "VBoxDrvSolaris _init failed with rc=%d", rc); 187 return rc; 188 } 189 190 191 int _fini(void) 178 192 { 179 193 cmn_err(CE_CONT, "VBoxDrvSolaris _fini"); … … 187 201 } 188 202 189 int _info (struct modinfo *pModInfo) 203 204 int _info(struct modinfo *pModInfo) 190 205 { 191 206 cmn_err(CE_CONT, "VBoxDrvSolaris _info"); 192 int e = mod_info 207 int e = mod_info(&g_VBoxDrvSolarisModLinkage, pModInfo); 193 208 cmn_err(CE_CONT, "VBoxDrvSolaris _info returns %d", e); 194 209 return e; … … 200 215 static int VBoxDrvSolarisOpen(dev_t *pDev, int fFlag, int fType, cred_t *pCred) 201 216 { 202 cmn_err(CE_CONT, "VBoxDrvSolarisOpen");203 204 217 int rc; 205 218 PSUPDRVSESSION pSession; 206 219 dprintf(("VBoxDrvSolarisOpen: pDev=%p:%#x\n", pDev, *pDev)); 220 221 #ifndef USE_SESSION_HASH 222 /* 223 * Locate a new device open instance. 224 * 225 * For each open call we'll allocate an item in the soft state of the device. 226 * The item index is stored in the dev_t. I hope this is ok... 227 */ 228 vbox_devstate_t *pState = NULL; 229 unsigned iOpenInstance; 230 for (iOpenInstance = 0; iOpenInstance < 4096; iOpenInstance++) 231 { 232 if ( !ddi_get_soft_state(g_pVBoxDrvSolarisState, iOpenInstance) /* faster */ 233 && ddi_soft_state_zalloc(g_pVBoxDrvSolarisState, iOpenInstance) == DDI_SUCCESS) 234 { 235 pState = ddi_get_soft_state(g_pVBoxDrvSolarisState, iOpenInstance); 236 break; 237 } 238 } 239 if (!pState) 240 { 241 cmn_err(CE_NOTE,"VBoxDrvSolarisOpen: too many open instances."); 242 return ENXIO; 243 } 244 245 /* 246 * Create a new session. 247 */ 248 rc = supdrvCreateSession(&g_DevExt, &pSession); 249 if (RT_SUCCESS(rc)) 250 { 251 pState->pSession = pSession; 252 *pDev = makedevice(getmajor(*pDev), iOpenInstance); 253 dprintf(("VBoxDrvSolarisOpen: returns pDev=%#x pSession=%p pState=%p\n", *pDev, pSession, pState)); 254 return 0; 255 } 256 257 /* failed - clean up */ 258 ddi_soft_state_free(g_pVBoxDrvSolarisState, iOpenInstance); 259 260 #else 207 261 /* 208 262 * Create a new session. … … 235 289 for (instance = 0; instance < DEVICE_MAXINSTANCES; instance++) 236 290 { 237 vbox_devstate_t *pState = ddi_get_soft_state 291 vbox_devstate_t *pState = ddi_get_soft_state(g_pVBoxDrvSolarisState, instance); 238 292 if (pState) 239 293 break; … … 249 303 250 304 return VBoxSupDrvErr2SolarisErr(rc); 251 } 252 253 static int VBoxDrvSolarisClose(dev_t pDev, int flag, int otyp, cred_t *cred) 254 { 255 cmn_err(CE_CONT, "VBoxDrvSolarisClose"); 256 305 #endif 306 } 307 308 309 static int VBoxDrvSolarisClose(dev_t Dev, int flag, int otyp, cred_t *cred) 310 { 311 dprintf(("VBoxDrvSolarisClose: Dev=%#x\n", Dev)); 312 #ifndef USE_SESSION_HASH 313 /* 314 * Get the session and free the soft state item. 315 */ 316 vbox_devstate_t *pState = ddi_get_soft_state(g_pVBoxDrvSolarisState, getminor(Dev)); 317 if (!pState) 318 { 319 OSDBGPRINT(("VBoxDrvSolarisClose: no state data for %#x (%d)\n", Dev, getminor(Dev))); 320 return DDI_SUCCESS; 321 } 322 323 PSUPDRVSESSION pSession = pState->pSession; 324 pState->pSession = NULL; 325 ddi_soft_state_free(g_pVBoxDrvSolarisState, getminor(Dev)); 326 327 if (!pSession) 328 { 329 OSDBGPRINT(("VBoxDrvSolarisClose: no session in state data for %#x (%d)\n", Dev, getminor(Dev))); 330 return DDI_SUCCESS; 331 } 332 333 #else 257 334 RTSPINLOCKTMP Tmp = RTSPINLOCKTMP_INITIALIZER; 258 335 const RTPROCESS Process = RTProcSelf(); … … 298 375 return DDI_FAILURE; 299 376 } 377 #endif 300 378 301 379 /* … … 306 384 } 307 385 386 308 387 static int VBoxDrvSolarisRead(dev_t Dev, struct uio *pUio, cred_t *pCred) 309 388 { … … 312 391 } 313 392 393 314 394 static int VBoxDrvSolarisWrite(dev_t Dev, struct uio *pUio, cred_t *pCred) 315 395 { … … 329 409 { 330 410 cmn_err(CE_CONT, "VBoxDrvSolarisAttach"); 331 int rc = VINF_SUCCESS;332 int instance = 0;333 vbox_devstate_t *pState;334 411 335 412 switch (enmCmd) … … 337 414 case DDI_ATTACH: 338 415 { 339 instance = ddi_get_instance (pDip); 416 int rc; 417 int instance = ddi_get_instance(pDip); 418 #ifdef USE_SESSION_HASH 419 vbox_devstate_t *pState; 340 420 341 421 if (ddi_soft_state_zalloc(g_pVBoxDrvSolarisState, instance) != DDI_SUCCESS) … … 346 426 347 427 pState = ddi_get_soft_state(g_pVBoxDrvSolarisState, instance); 428 #endif 348 429 349 430 /* … … 369 450 * Register ourselves as a character device, pseudo-driver 370 451 */ 371 if (ddi_create_minor_node(pDip, "0", S_IFCHR, 372 instance, DDI_PSEUDO, 0) == DDI_SUCCESS) 452 if (ddi_create_minor_node(pDip, "0", S_IFCHR, instance, DDI_PSEUDO, 0) == DDI_SUCCESS) 373 453 { 454 #ifdef USE_SESSION_HASH 374 455 pState->pDip = pDip; 456 #endif 375 457 ddi_report_dev(pDip); 376 458 return DDI_SUCCESS; … … 416 498 { 417 499 int rc = VINF_SUCCESS; 418 int instance; 419 register vbox_devstate_t *pState; 500 420 501 421 502 cmn_err(CE_CONT, "VBoxDrvSolarisDetach"); … … 424 505 case DDI_DETACH: 425 506 { 426 instance = ddi_get_instance(pDip); 427 pState = ddi_get_soft_state(g_pVBoxDrvSolarisState, instance); 428 507 int instance = ddi_get_instance(pDip); 508 #ifndef USE_SESSION_HASH 509 ddi_remove_minor_node(pDip, NULL); 510 #else 511 vbox_devstate_t *pState = ddi_get_soft_state(g_pVBoxDrvSolarisState, instance); 429 512 ddi_remove_minor_node(pDip, NULL); 430 513 ddi_soft_state_free(g_pVBoxDrvSolarisState, instance); 514 #endif 431 515 432 516 supdrvDeleteDevExt(&g_DevExt); … … 460 544 * @return corresponding solaris error code. 461 545 */ 462 static int VBoxDrvSolarisIOCtl (dev_t Dev, int Cmd, intptr_t pArgs, int Mode, cred_t* pCred, int* pVal) 463 { 546 static int VBoxDrvSolarisIOCtl(dev_t Dev, int Cmd, intptr_t pArgs, int Mode, cred_t *pCred, int *pVal) 547 { 548 #ifndef USE_SESSION_HASH 549 /* 550 * Get the session from the soft state item. 551 */ 552 vbox_devstate_t *pState = ddi_get_soft_state(g_pVBoxDrvSolarisState, getminor(Dev)); 553 if (!pState) 554 { 555 OSDBGPRINT(("VBoxDrvSolarisIOCtl: no state data for %#x (%d)\n", Dev, getminor(Dev))); 556 return EINVAL; 557 } 558 559 PSUPDRVSESSION pSession = pState->pSession; 560 if (!pSession) 561 { 562 OSDBGPRINT(("VBoxDrvSolarisIOCtl: no session in state data for %#x (%d)\n", Dev, getminor(Dev))); 563 return DDI_SUCCESS; 564 } 565 #else 464 566 RTSPINLOCKTMP Tmp = RTSPINLOCKTMP_INITIALIZER; 465 567 const RTPROCESS Process = RTProcSelf(); … … 467 569 PSUPDRVSESSION pSession; 468 570 469 cmn_err(CE_CONT, "VBoxDrvSolarisIOCtl\n");470 571 /* 471 572 * Find the session. … … 485 586 return EINVAL; 486 587 } 588 #endif 487 589 488 590 /* … … 493 595 || Cmd == SUP_IOCTL_FAST_DO_HWACC_RUN 494 596 || Cmd == SUP_IOCTL_FAST_DO_NOP) 495 return supdrvIOCtlFast(Cmd, &g_DevExt, pSession); 597 { 598 *pVal = supdrvIOCtlFast(Cmd, &g_DevExt, pSession); 599 return 0; 600 } 496 601 497 602 return VBoxDrvSolarisIOCtlSlow(pSession, Cmd, Mode, pArgs); … … 670 775 szMsg[sizeof(szMsg) - 1] = '\0'; 671 776 uprintf("SUPR0Printf: %s", szMsg); 777 // cmn_err(CE_CONT, "VBoxDrv: %s", szMsg); 778 672 779 return 0; 673 780 }
Note:
See TracChangeset
for help on using the changeset viewer.