1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #pragma ident "%Z%%M% %I% %E% SMI" 28 29 /* 30 * PCI Express nexus driver interface 31 */ 32 33 #include <sys/types.h> 34 #include <sys/conf.h> /* nulldev */ 35 #include <sys/stat.h> /* devctl */ 36 #include <sys/kmem.h> 37 #include <sys/sunddi.h> 38 #include <sys/sunndi.h> 39 #include <sys/hotplug/pci/pcihp.h> 40 #include <sys/ontrap.h> 41 #include <sys/ddi_impldefs.h> 42 #include <sys/ddi_subrdefs.h> 43 #include <sys/spl.h> 44 #include <sys/epm.h> 45 #include <sys/iommutsb.h> 46 #include "px_obj.h" 47 #include "pcie_pwr.h" 48 49 /*LINTLIBRARY*/ 50 51 /* 52 * function prototypes for dev ops routines: 53 */ 54 static int px_attach(dev_info_t *dip, ddi_attach_cmd_t cmd); 55 static int px_detach(dev_info_t *dip, ddi_detach_cmd_t cmd); 56 static int px_info(dev_info_t *dip, ddi_info_cmd_t infocmd, 57 void *arg, void **result); 58 static int px_pwr_setup(dev_info_t *dip); 59 static void px_pwr_teardown(dev_info_t *dip); 60 61 /* 62 * bus ops and dev ops structures: 63 */ 64 static struct bus_ops px_bus_ops = { 65 BUSO_REV, 66 px_map, 67 0, 68 0, 69 0, 70 i_ddi_map_fault, 71 px_dma_setup, 72 px_dma_allochdl, 73 px_dma_freehdl, 74 px_dma_bindhdl, 75 px_dma_unbindhdl, 76 px_lib_dma_sync, 77 px_dma_win, 78 px_dma_ctlops, 79 px_ctlops, 80 ddi_bus_prop_op, 81 ndi_busop_get_eventcookie, 82 ndi_busop_add_eventcall, 83 ndi_busop_remove_eventcall, 84 ndi_post_event, 85 NULL, 86 NULL, /* (*bus_config)(); */ 87 NULL, /* (*bus_unconfig)(); */ 88 px_fm_init_child, /* (*bus_fm_init)(); */ 89 NULL, /* (*bus_fm_fini)(); */ 90 px_bus_enter, /* (*bus_fm_access_enter)(); */ 91 px_bus_exit, /* (*bus_fm_access_fini)(); */ 92 pcie_bus_power, /* (*bus_power)(); */ 93 px_intr_ops /* (*bus_intr_op)(); */ 94 }; 95 96 extern struct cb_ops px_cb_ops; 97 98 static struct dev_ops px_ops = { 99 DEVO_REV, 100 0, 101 px_info, 102 nulldev, 103 0, 104 px_attach, 105 px_detach, 106 nodev, 107 &px_cb_ops, 108 &px_bus_ops, 109 nulldev 110 }; 111 112 /* 113 * module definitions: 114 */ 115 #include <sys/modctl.h> 116 extern struct mod_ops mod_driverops; 117 118 static struct modldrv modldrv = { 119 &mod_driverops, /* Type of module - driver */ 120 "PCI Express nexus driver %I%", /* Name of module. */ 121 &px_ops, /* driver ops */ 122 }; 123 124 static struct modlinkage modlinkage = { 125 MODREV_1, (void *)&modldrv, NULL 126 }; 127 128 /* driver soft state */ 129 void *px_state_p; 130 131 int 132 _init(void) 133 { 134 int e; 135 136 /* 137 * Initialize per-px bus soft state pointer. 138 */ 139 e = ddi_soft_state_init(&px_state_p, sizeof (px_t), 1); 140 if (e != DDI_SUCCESS) 141 return (e); 142 143 /* 144 * Install the module. 145 */ 146 e = mod_install(&modlinkage); 147 if (e != DDI_SUCCESS) 148 ddi_soft_state_fini(&px_state_p); 149 return (e); 150 } 151 152 int 153 _fini(void) 154 { 155 int e; 156 157 /* 158 * Remove the module. 159 */ 160 e = mod_remove(&modlinkage); 161 if (e != DDI_SUCCESS) 162 return (e); 163 164 /* Free px soft state */ 165 ddi_soft_state_fini(&px_state_p); 166 167 return (e); 168 } 169 170 int 171 _info(struct modinfo *modinfop) 172 { 173 return (mod_info(&modlinkage, modinfop)); 174 } 175 176 /* ARGSUSED */ 177 static int 178 px_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result) 179 { 180 int instance = getminor((dev_t)arg); 181 px_t *px_p = INST_TO_STATE(instance); 182 183 #ifdef HOTPLUG 184 /* 185 * Allow hotplug to deal with ones it manages 186 * Hot Plug will be done later. 187 */ 188 if (px_p && (px_p->hotplug_capable == B_TRUE)) 189 return (pcihp_info(dip, infocmd, arg, result)); 190 #endif /* HOTPLUG */ 191 192 /* non-hotplug or not attached */ 193 switch (infocmd) { 194 case DDI_INFO_DEVT2INSTANCE: 195 *result = (void *)instance; 196 return (DDI_SUCCESS); 197 198 case DDI_INFO_DEVT2DEVINFO: 199 if (px_p == NULL) 200 return (DDI_FAILURE); 201 *result = (void *)px_p->px_dip; 202 return (DDI_SUCCESS); 203 204 default: 205 return (DDI_FAILURE); 206 } 207 } 208 209 /* device driver entry points */ 210 /* 211 * attach entry point: 212 */ 213 /*ARGSUSED*/ 214 static int 215 px_attach(dev_info_t *dip, ddi_attach_cmd_t cmd) 216 { 217 px_t *px_p; /* per bus state pointer */ 218 int instance = DIP_TO_INST(dip); 219 int ret = DDI_SUCCESS; 220 devhandle_t dev_hdl = NULL; 221 222 switch (cmd) { 223 case DDI_ATTACH: 224 DBG(DBG_ATTACH, dip, "DDI_ATTACH\n"); 225 226 /* 227 * Allocate and get the per-px soft state structure. 228 */ 229 if (ddi_soft_state_zalloc(px_state_p, instance) 230 != DDI_SUCCESS) { 231 cmn_err(CE_WARN, "%s%d: can't allocate px state", 232 ddi_driver_name(dip), instance); 233 goto err_bad_px_softstate; 234 } 235 px_p = INST_TO_STATE(instance); 236 px_p->px_dip = dip; 237 mutex_init(&px_p->px_mutex, NULL, MUTEX_DRIVER, NULL); 238 px_p->px_soft_state = PX_SOFT_STATE_CLOSED; 239 px_p->px_open_count = 0; 240 241 /* 242 * Get key properties of the pci bridge node and 243 * determine it's type (psycho, schizo, etc ...). 244 */ 245 if (px_get_props(px_p, dip) == DDI_FAILURE) 246 goto err_bad_px_prop; 247 248 if ((px_fm_attach(px_p)) != DDI_SUCCESS) 249 goto err_bad_fm; 250 251 if (px_lib_dev_init(dip, &dev_hdl) != DDI_SUCCESS) 252 goto err_bad_dev_init; 253 254 /* Initilize device handle */ 255 px_p->px_dev_hdl = dev_hdl; 256 257 /* 258 * Initialize interrupt block. Note that this 259 * initialize error handling for the PEC as well. 260 */ 261 if ((ret = px_ib_attach(px_p)) != DDI_SUCCESS) 262 goto err_bad_ib; 263 264 if (px_cb_attach(px_p) != DDI_SUCCESS) 265 goto err_bad_cb; 266 267 /* 268 * Start creating the modules. 269 * Note that attach() routines should 270 * register and enable their own interrupts. 271 */ 272 273 if ((px_mmu_attach(px_p)) != DDI_SUCCESS) 274 goto err_bad_mmu; 275 276 if ((px_msiq_attach(px_p)) != DDI_SUCCESS) 277 goto err_bad_msiq; 278 279 if ((px_msi_attach(px_p)) != DDI_SUCCESS) 280 goto err_bad_msi; 281 282 if ((px_pec_attach(px_p)) != DDI_SUCCESS) 283 goto err_bad_pec; 284 285 if ((px_dma_attach(px_p)) != DDI_SUCCESS) 286 goto err_bad_pec; /* nothing to uninitialize on DMA */ 287 288 /* 289 * All of the error handlers have been registered 290 * by now so it's time to activate the interrupt. 291 */ 292 if ((ret = px_err_add_intr(&px_p->px_fault)) != DDI_SUCCESS) 293 goto err_bad_pec_add_intr; 294 295 /* 296 * Create the "devctl" node for hotplug and pcitool support. 297 * For non-hotplug bus, we still need ":devctl" to 298 * support DEVCTL_DEVICE_* and DEVCTL_BUS_* ioctls. 299 */ 300 if (ddi_create_minor_node(dip, "devctl", S_IFCHR, 301 PCIHP_AP_MINOR_NUM(instance, PCIHP_DEVCTL_MINOR), 302 DDI_NT_NEXUS, 0) != DDI_SUCCESS) { 303 goto err_bad_devctl_node; 304 } 305 /* 306 * power management setup. Even if it fails, attach will 307 * succeed as this is a optional feature. Since we are 308 * always at full power, this is not critical. 309 */ 310 if (pwr_common_setup(dip) != DDI_SUCCESS) { 311 DBG(DBG_PWR, dip, "pwr_common_setup failed\n"); 312 } else if (px_pwr_setup(dip) != DDI_SUCCESS) { 313 DBG(DBG_PWR, dip, "px_pwr_setup failed \n"); 314 pwr_common_teardown(dip); 315 } 316 317 /* 318 * add cpr callback 319 */ 320 px_cpr_add_callb(px_p); 321 322 ddi_report_dev(dip); 323 324 px_p->px_state = PX_ATTACHED; 325 DBG(DBG_ATTACH, dip, "attach success\n"); 326 break; 327 328 err_bad_devctl_node: 329 px_err_rem_intr(&px_p->px_fault); 330 err_bad_pec_add_intr: 331 px_pec_detach(px_p); 332 err_bad_pec: 333 px_msi_detach(px_p); 334 err_bad_msi: 335 px_msiq_detach(px_p); 336 err_bad_msiq: 337 px_mmu_detach(px_p); 338 err_bad_mmu: 339 px_cb_detach(px_p); 340 err_bad_cb: 341 px_ib_detach(px_p); 342 err_bad_ib: 343 (void) px_lib_dev_fini(dip); 344 err_bad_dev_init: 345 px_fm_detach(px_p); 346 err_bad_fm: 347 px_free_props(px_p); 348 err_bad_px_prop: 349 mutex_destroy(&px_p->px_mutex); 350 ddi_soft_state_free(px_state_p, instance); 351 err_bad_px_softstate: 352 ret = DDI_FAILURE; 353 break; 354 355 case DDI_RESUME: 356 DBG(DBG_ATTACH, dip, "DDI_RESUME\n"); 357 358 px_p = INST_TO_STATE(instance); 359 360 mutex_enter(&px_p->px_mutex); 361 362 /* suspend might have not succeeded */ 363 if (px_p->px_state != PX_SUSPENDED) { 364 DBG(DBG_ATTACH, px_p->px_dip, 365 "instance NOT suspended\n"); 366 ret = DDI_FAILURE; 367 break; 368 } 369 370 px_lib_resume(dip); 371 (void) pcie_pwr_resume(dip); 372 px_p->px_state = PX_ATTACHED; 373 374 mutex_exit(&px_p->px_mutex); 375 376 break; 377 default: 378 DBG(DBG_ATTACH, dip, "unsupported attach op\n"); 379 ret = DDI_FAILURE; 380 break; 381 } 382 383 return (ret); 384 } 385 386 /* 387 * detach entry point: 388 */ 389 /*ARGSUSED*/ 390 static int 391 px_detach(dev_info_t *dip, ddi_detach_cmd_t cmd) 392 { 393 int instance = ddi_get_instance(dip); 394 px_t *px_p = INST_TO_STATE(instance); 395 int ret; 396 397 /* 398 * Make sure we are currently attached 399 */ 400 if (px_p->px_state != PX_ATTACHED) { 401 DBG(DBG_DETACH, dip, "failed - instance not attached\n"); 402 return (DDI_FAILURE); 403 } 404 405 mutex_enter(&px_p->px_mutex); 406 407 switch (cmd) { 408 case DDI_DETACH: 409 DBG(DBG_DETACH, dip, "DDI_DETACH\n"); 410 411 /* 412 * remove cpr callback 413 */ 414 px_cpr_rem_callb(px_p); 415 416 #ifdef HOTPLUG 417 /* 418 * Hot plug will be done later. 419 */ 420 if (px_p->hotplug_capable == B_TRUE) { 421 if (pxhp_uninit(dip) == DDI_FAILURE) { 422 mutex_exit(&px_p->px_mutex); 423 return (DDI_FAILURE); 424 } 425 } 426 #endif /* HOTPLUG */ 427 428 /* 429 * things which used to be done in obj_destroy 430 * are now in-lined here. 431 */ 432 433 px_p->px_state = PX_DETACHED; 434 435 ddi_remove_minor_node(dip, "devctl"); 436 px_err_rem_intr(&px_p->px_fault); 437 px_pec_detach(px_p); 438 px_msi_detach(px_p); 439 px_msiq_detach(px_p); 440 px_mmu_detach(px_p); 441 px_cb_detach(px_p); 442 px_ib_detach(px_p); 443 (void) px_lib_dev_fini(dip); 444 px_fm_detach(px_p); 445 446 /* 447 * Free the px soft state structure and the rest of the 448 * resources it's using. 449 */ 450 px_free_props(px_p); 451 px_pwr_teardown(dip); 452 pwr_common_teardown(dip); 453 mutex_exit(&px_p->px_mutex); 454 mutex_destroy(&px_p->px_mutex); 455 ddi_soft_state_free(px_state_p, instance); 456 457 /* Free the interrupt-priorities prop if we created it. */ { 458 int len; 459 460 if (ddi_getproplen(DDI_DEV_T_ANY, dip, 461 DDI_PROP_NOTPROM | DDI_PROP_DONTPASS, 462 "interrupt-priorities", &len) == DDI_PROP_SUCCESS) 463 (void) ddi_prop_remove(DDI_DEV_T_NONE, dip, 464 "interrupt-priorities"); 465 } 466 467 px_p->px_dev_hdl = NULL; 468 469 return (DDI_SUCCESS); 470 471 case DDI_SUSPEND: 472 if (pcie_pwr_suspend(dip) != DDI_SUCCESS) { 473 mutex_exit(&px_p->px_mutex); 474 return (DDI_FAILURE); 475 } 476 if ((ret = px_lib_suspend(dip)) == DDI_SUCCESS) 477 px_p->px_state = PX_SUSPENDED; 478 mutex_exit(&px_p->px_mutex); 479 480 return (ret); 481 482 default: 483 DBG(DBG_DETACH, dip, "unsupported detach op\n"); 484 mutex_exit(&px_p->px_mutex); 485 return (DDI_FAILURE); 486 } 487 } 488 489 /* 490 * power management related initialization specific to px 491 * called by px_attach() 492 */ 493 static int 494 px_pwr_setup(dev_info_t *dip) 495 { 496 pcie_pwr_t *pwr_p; 497 int instance = ddi_get_instance(dip); 498 px_t *px_p = INST_TO_STATE(instance); 499 ddi_intr_handle_impl_t hdl; 500 ddi_iblock_cookie_t iblk_cookie; 501 502 ASSERT(PCIE_PMINFO(dip)); 503 pwr_p = PCIE_NEXUS_PMINFO(dip); 504 ASSERT(pwr_p); 505 506 /* 507 * indicate support LDI (Layered Driver Interface) 508 * Create the property, if it is not already there 509 */ 510 if (!ddi_prop_exists(DDI_DEV_T_NONE, dip, DDI_PROP_DONTPASS, 511 DDI_KERNEL_IOCTL)) { 512 if (ddi_prop_create(DDI_DEV_T_NONE, dip, DDI_PROP_CANSLEEP, 513 DDI_KERNEL_IOCTL, NULL, 0) != DDI_PROP_SUCCESS) { 514 DBG(DBG_PWR, dip, "can't create kernel ioctl prop\n"); 515 return (DDI_FAILURE); 516 } 517 } 518 /* No support for device PM. We are always at full power */ 519 pwr_p->pwr_func_lvl = PM_LEVEL_D0; 520 521 mutex_init(&px_p->px_l23ready_lock, NULL, MUTEX_DRIVER, 522 (void *)px_pwr_pil); 523 cv_init(&px_p->px_l23ready_cv, NULL, CV_DRIVER, NULL); 524 525 mutex_init(&px_p->px_lup_lock, NULL, MUTEX_DRIVER, 526 (void *)PX_ERR_PIL); 527 cv_init(&px_p->px_lup_cv, NULL, CV_DRIVER, NULL); 528 529 if (ddi_get_soft_iblock_cookie(dip, DDI_SOFTINT_HIGH, 530 &iblk_cookie) != DDI_SUCCESS) { 531 DBG(DBG_PWR, dip, "px_pwr_setup: couldn't get iblock cookie\n"); 532 goto pwr_setup_err1; 533 } 534 mutex_init(&px_p->px_lupsoft_lock, NULL, MUTEX_DRIVER, 535 (void *)iblk_cookie); 536 if (ddi_add_softintr(dip, DDI_SOFTINT_HIGH, &px_p->px_lupsoft_id, 537 NULL, NULL, px_lup_softintr, (caddr_t)px_p) != DDI_SUCCESS) { 538 DBG(DBG_PWR, dip, "px_pwr_setup: couldn't add soft intr \n"); 539 goto pwr_setup_err2; 540 } 541 542 /* Initilize handle */ 543 hdl.ih_cb_arg1 = px_p; 544 hdl.ih_cb_arg2 = NULL; 545 hdl.ih_ver = DDI_INTR_VERSION; 546 hdl.ih_state = DDI_IHDL_STATE_ALLOC; 547 hdl.ih_dip = dip; 548 hdl.ih_inum = 0; 549 hdl.ih_pri = px_pwr_pil; 550 551 /* Add PME_TO_ACK message handler */ 552 hdl.ih_cb_func = (ddi_intr_handler_t *)px_pmeq_intr; 553 if (px_add_msiq_intr(dip, dip, &hdl, MSG_REC, 554 (msgcode_t)PCIE_PME_ACK_MSG, &px_p->px_pm_msiq_id) != DDI_SUCCESS) { 555 DBG(DBG_PWR, dip, "px_pwr_setup: couldn't add " 556 " PME_TO_ACK intr\n"); 557 goto px_pwrsetup_err; 558 } 559 px_lib_msg_setmsiq(dip, PCIE_PME_ACK_MSG, px_p->px_pm_msiq_id); 560 px_lib_msg_setvalid(dip, PCIE_PME_ACK_MSG, PCIE_MSG_VALID); 561 562 return (DDI_SUCCESS); 563 564 px_pwrsetup_err: 565 ddi_remove_softintr(px_p->px_lupsoft_id); 566 pwr_setup_err2: 567 mutex_destroy(&px_p->px_lupsoft_lock); 568 pwr_setup_err1: 569 mutex_destroy(&px_p->px_lup_lock); 570 cv_destroy(&px_p->px_lup_cv); 571 mutex_destroy(&px_p->px_l23ready_lock); 572 cv_destroy(&px_p->px_l23ready_cv); 573 574 return (DDI_FAILURE); 575 } 576 577 /* 578 * undo whatever is done in px_pwr_setup. called by px_detach() 579 */ 580 static void 581 px_pwr_teardown(dev_info_t *dip) 582 { 583 int instance = ddi_get_instance(dip); 584 px_t *px_p = INST_TO_STATE(instance); 585 ddi_intr_handle_impl_t hdl; 586 587 if (!PCIE_PMINFO(dip) || !PCIE_NEXUS_PMINFO(dip)) 588 return; 589 590 /* Initilize handle */ 591 hdl.ih_ver = DDI_INTR_VERSION; 592 hdl.ih_state = DDI_IHDL_STATE_ALLOC; 593 hdl.ih_dip = dip; 594 hdl.ih_inum = 0; 595 596 px_lib_msg_setvalid(dip, PCIE_PME_ACK_MSG, PCIE_MSG_INVALID); 597 (void) px_rem_msiq_intr(dip, dip, &hdl, MSG_REC, PCIE_PME_ACK_MSG, 598 px_p->px_pm_msiq_id); 599 600 px_p->px_pm_msiq_id = -1; 601 602 cv_destroy(&px_p->px_l23ready_cv); 603 ddi_remove_softintr(px_p->px_lupsoft_id); 604 mutex_destroy(&px_p->px_lupsoft_lock); 605 mutex_destroy(&px_p->px_lup_lock); 606 mutex_destroy(&px_p->px_l23ready_lock); 607 } 608 609 /* bus driver entry points */ 610 611 /* 612 * bus map entry point: 613 * 614 * if map request is for an rnumber 615 * get the corresponding regspec from device node 616 * build a new regspec in our parent's format 617 * build a new map_req with the new regspec 618 * call up the tree to complete the mapping 619 */ 620 int 621 px_map(dev_info_t *dip, dev_info_t *rdip, ddi_map_req_t *mp, 622 off_t off, off_t len, caddr_t *addrp) 623 { 624 px_t *px_p = DIP_TO_STATE(dip); 625 struct regspec p_regspec; 626 ddi_map_req_t p_mapreq; 627 int reglen, rval, r_no; 628 pci_regspec_t reloc_reg, *rp = &reloc_reg; 629 630 DBG(DBG_MAP, dip, "rdip=%s%d:", 631 ddi_driver_name(rdip), ddi_get_instance(rdip)); 632 633 if (mp->map_flags & DDI_MF_USER_MAPPING) 634 return (DDI_ME_UNIMPLEMENTED); 635 636 switch (mp->map_type) { 637 case DDI_MT_REGSPEC: 638 reloc_reg = *(pci_regspec_t *)mp->map_obj.rp; /* dup whole */ 639 break; 640 641 case DDI_MT_RNUMBER: 642 r_no = mp->map_obj.rnumber; 643 DBG(DBG_MAP | DBG_CONT, dip, " r#=%x", r_no); 644 645 if (ddi_getlongprop(DDI_DEV_T_ANY, rdip, DDI_PROP_DONTPASS, 646 "reg", (caddr_t)&rp, ®len) != DDI_SUCCESS) 647 return (DDI_ME_RNUMBER_RANGE); 648 649 if (r_no < 0 || r_no >= reglen / sizeof (pci_regspec_t)) { 650 kmem_free(rp, reglen); 651 return (DDI_ME_RNUMBER_RANGE); 652 } 653 rp += r_no; 654 break; 655 656 default: 657 return (DDI_ME_INVAL); 658 } 659 DBG(DBG_MAP | DBG_CONT, dip, "\n"); 660 661 if ((rp->pci_phys_hi & PCI_REG_ADDR_M) == PCI_ADDR_CONFIG) { 662 /* 663 * There may be a need to differentiate between PCI 664 * and PCI-Ex devices so the following range check is 665 * done correctly, depending on the implementation of 666 * px_pci bridge nexus driver. 667 */ 668 if ((off >= PCIE_CONF_HDR_SIZE) || 669 (len > PCIE_CONF_HDR_SIZE) || 670 (off + len > PCIE_CONF_HDR_SIZE)) 671 return (DDI_ME_INVAL); 672 /* 673 * the following function returning a DDI_FAILURE assumes 674 * that there are no virtual config space access services 675 * defined in this layer. Otherwise it is availed right 676 * here and we return. 677 */ 678 rval = px_lib_map_vconfig(dip, mp, off, rp, addrp); 679 if (rval == DDI_SUCCESS) 680 goto done; 681 } 682 683 /* 684 * No virtual config space services or we are mapping 685 * a region of memory mapped config/IO/memory space, so proceed 686 * to the parent. 687 */ 688 689 /* relocate within 64-bit pci space through "assigned-addresses" */ 690 if (rval = px_reloc_reg(dip, rdip, px_p, rp)) 691 goto done; 692 693 if (len) /* adjust regspec according to mapping request */ 694 rp->pci_size_low = len; /* MIN ? */ 695 rp->pci_phys_low += off; 696 697 /* translate relocated pci regspec into parent space through "ranges" */ 698 if (rval = px_xlate_reg(px_p, rp, &p_regspec)) 699 goto done; 700 701 p_mapreq = *mp; /* dup the whole structure */ 702 p_mapreq.map_type = DDI_MT_REGSPEC; 703 p_mapreq.map_obj.rp = &p_regspec; 704 rval = ddi_map(dip, &p_mapreq, 0, 0, addrp); 705 706 if (rval == DDI_SUCCESS) { 707 /* 708 * Set-up access functions for FM access error capable drivers. 709 */ 710 if (DDI_FM_ACC_ERR_CAP(ddi_fm_capable(rdip)) && 711 mp->map_handlep->ah_acc.devacc_attr_access != 712 DDI_DEFAULT_ACC) 713 px_fm_acc_setup(mp, rdip); 714 } 715 716 done: 717 if (mp->map_type == DDI_MT_RNUMBER) 718 kmem_free(rp - r_no, reglen); 719 720 return (rval); 721 } 722 723 /* 724 * bus dma map entry point 725 * return value: 726 * DDI_DMA_PARTIAL_MAP 1 727 * DDI_DMA_MAPOK 0 728 * DDI_DMA_MAPPED 0 729 * DDI_DMA_NORESOURCES -1 730 * DDI_DMA_NOMAPPING -2 731 * DDI_DMA_TOOBIG -3 732 */ 733 int 734 px_dma_setup(dev_info_t *dip, dev_info_t *rdip, ddi_dma_req_t *dmareq, 735 ddi_dma_handle_t *handlep) 736 { 737 px_t *px_p = DIP_TO_STATE(dip); 738 px_mmu_t *mmu_p = px_p->px_mmu_p; 739 ddi_dma_impl_t *mp; 740 int ret; 741 742 DBG(DBG_DMA_MAP, dip, "mapping - rdip=%s%d type=%s\n", 743 ddi_driver_name(rdip), ddi_get_instance(rdip), 744 handlep ? "alloc" : "advisory"); 745 746 if (!(mp = px_dma_lmts2hdl(dip, rdip, mmu_p, dmareq))) 747 return (DDI_DMA_NORESOURCES); 748 if (mp == (ddi_dma_impl_t *)DDI_DMA_NOMAPPING) 749 return (DDI_DMA_NOMAPPING); 750 if (ret = px_dma_type(px_p, dmareq, mp)) 751 goto freehandle; 752 if (ret = px_dma_pfn(px_p, dmareq, mp)) 753 goto freehandle; 754 755 switch (PX_DMA_TYPE(mp)) { 756 case DMAI_FLAGS_DVMA: /* LINTED E_EQUALITY_NOT_ASSIGNMENT */ 757 if ((ret = px_dvma_win(px_p, dmareq, mp)) || !handlep) 758 goto freehandle; 759 if (!PX_DMA_CANCACHE(mp)) { /* try fast track */ 760 if (PX_DMA_CANFAST(mp)) { 761 if (!px_dvma_map_fast(mmu_p, mp)) 762 break; 763 /* LINTED E_NOP_ELSE_STMT */ 764 } else { 765 PX_DVMA_FASTTRAK_PROF(mp); 766 } 767 } 768 if (ret = px_dvma_map(mp, dmareq, mmu_p)) 769 goto freehandle; 770 break; 771 case DMAI_FLAGS_PTP: /* LINTED E_EQUALITY_NOT_ASSIGNMENT */ 772 if ((ret = px_dma_physwin(px_p, dmareq, mp)) || !handlep) 773 goto freehandle; 774 break; 775 case DMAI_FLAGS_BYPASS: 776 default: 777 cmn_err(CE_PANIC, "%s%d: px_dma_setup: bad dma type 0x%x", 778 ddi_driver_name(rdip), ddi_get_instance(rdip), 779 PX_DMA_TYPE(mp)); 780 /*NOTREACHED*/ 781 } 782 *handlep = (ddi_dma_handle_t)mp; 783 mp->dmai_flags |= DMAI_FLAGS_INUSE; 784 px_dump_dma_handle(DBG_DMA_MAP, dip, mp); 785 786 return ((mp->dmai_nwin == 1) ? DDI_DMA_MAPPED : DDI_DMA_PARTIAL_MAP); 787 freehandle: 788 if (ret == DDI_DMA_NORESOURCES) 789 px_dma_freemp(mp); /* don't run_callback() */ 790 else 791 (void) px_dma_freehdl(dip, rdip, (ddi_dma_handle_t)mp); 792 return (ret); 793 } 794 795 796 /* 797 * bus dma alloc handle entry point: 798 */ 799 int 800 px_dma_allochdl(dev_info_t *dip, dev_info_t *rdip, ddi_dma_attr_t *attrp, 801 int (*waitfp)(caddr_t), caddr_t arg, ddi_dma_handle_t *handlep) 802 { 803 px_t *px_p = DIP_TO_STATE(dip); 804 ddi_dma_impl_t *mp; 805 int rval; 806 807 DBG(DBG_DMA_ALLOCH, dip, "rdip=%s%d\n", 808 ddi_driver_name(rdip), ddi_get_instance(rdip)); 809 810 if (attrp->dma_attr_version != DMA_ATTR_V0) 811 return (DDI_DMA_BADATTR); 812 813 if (!(mp = px_dma_allocmp(dip, rdip, waitfp, arg))) 814 return (DDI_DMA_NORESOURCES); 815 816 /* 817 * Save requestor's information 818 */ 819 mp->dmai_attr = *attrp; /* whole object - augmented later */ 820 *DEV_ATTR(mp) = *attrp; /* whole object - device orig attr */ 821 DBG(DBG_DMA_ALLOCH, dip, "mp=%p\n", mp); 822 823 /* check and convert dma attributes to handle parameters */ 824 if (rval = px_dma_attr2hdl(px_p, mp)) { 825 px_dma_freehdl(dip, rdip, (ddi_dma_handle_t)mp); 826 *handlep = NULL; 827 return (rval); 828 } 829 *handlep = (ddi_dma_handle_t)mp; 830 return (DDI_SUCCESS); 831 } 832 833 834 /* 835 * bus dma free handle entry point: 836 */ 837 /*ARGSUSED*/ 838 int 839 px_dma_freehdl(dev_info_t *dip, dev_info_t *rdip, ddi_dma_handle_t handle) 840 { 841 DBG(DBG_DMA_FREEH, dip, "rdip=%s%d mp=%p\n", 842 ddi_driver_name(rdip), ddi_get_instance(rdip), handle); 843 px_dma_freemp((ddi_dma_impl_t *)handle); 844 845 if (px_kmem_clid) { 846 DBG(DBG_DMA_FREEH, dip, "run handle callback\n"); 847 ddi_run_callback(&px_kmem_clid); 848 } 849 return (DDI_SUCCESS); 850 } 851 852 853 /* 854 * bus dma bind handle entry point: 855 */ 856 int 857 px_dma_bindhdl(dev_info_t *dip, dev_info_t *rdip, 858 ddi_dma_handle_t handle, ddi_dma_req_t *dmareq, 859 ddi_dma_cookie_t *cookiep, uint_t *ccountp) 860 { 861 px_t *px_p = DIP_TO_STATE(dip); 862 px_mmu_t *mmu_p = px_p->px_mmu_p; 863 ddi_dma_impl_t *mp = (ddi_dma_impl_t *)handle; 864 int ret; 865 866 DBG(DBG_DMA_BINDH, dip, "rdip=%s%d mp=%p dmareq=%p\n", 867 ddi_driver_name(rdip), ddi_get_instance(rdip), mp, dmareq); 868 869 if (mp->dmai_flags & DMAI_FLAGS_INUSE) 870 return (DDI_DMA_INUSE); 871 872 ASSERT((mp->dmai_flags & ~DMAI_FLAGS_PRESERVE) == 0); 873 mp->dmai_flags |= DMAI_FLAGS_INUSE; 874 875 if (ret = px_dma_type(px_p, dmareq, mp)) 876 goto err; 877 if (ret = px_dma_pfn(px_p, dmareq, mp)) 878 goto err; 879 880 switch (PX_DMA_TYPE(mp)) { 881 case DMAI_FLAGS_DVMA: 882 if (ret = px_dvma_win(px_p, dmareq, mp)) 883 goto map_err; 884 if (!PX_DMA_CANCACHE(mp)) { /* try fast track */ 885 if (PX_DMA_CANFAST(mp)) { 886 if (!px_dvma_map_fast(mmu_p, mp)) 887 goto mapped; /*LINTED E_NOP_ELSE_STMT*/ 888 } else { 889 PX_DVMA_FASTTRAK_PROF(mp); 890 } 891 } 892 if (ret = px_dvma_map(mp, dmareq, mmu_p)) 893 goto map_err; 894 mapped: 895 *ccountp = 1; 896 MAKE_DMA_COOKIE(cookiep, mp->dmai_mapping, mp->dmai_size); 897 break; 898 case DMAI_FLAGS_BYPASS: 899 case DMAI_FLAGS_PTP: 900 if (ret = px_dma_physwin(px_p, dmareq, mp)) 901 goto map_err; 902 *ccountp = WINLST(mp)->win_ncookies; 903 *cookiep = *(ddi_dma_cookie_t *)(WINLST(mp) + 1); /* wholeobj */ 904 break; 905 default: 906 cmn_err(CE_PANIC, "%s%d: px_dma_bindhdl(%p): bad dma type", 907 ddi_driver_name(rdip), ddi_get_instance(rdip), mp); 908 /*NOTREACHED*/ 909 } 910 DBG(DBG_DMA_BINDH, dip, "cookie %llx+%x\n", cookiep->dmac_address, 911 cookiep->dmac_size); 912 px_dump_dma_handle(DBG_DMA_MAP, dip, mp); 913 914 /* insert dma handle into FMA cache */ 915 if (mp->dmai_attr.dma_attr_flags & DDI_DMA_FLAGERR) 916 (void) ndi_fmc_insert(rdip, DMA_HANDLE, mp, NULL); 917 918 return (mp->dmai_nwin == 1 ? DDI_DMA_MAPPED : DDI_DMA_PARTIAL_MAP); 919 map_err: 920 px_dma_freepfn(mp); 921 err: 922 mp->dmai_flags &= DMAI_FLAGS_PRESERVE; 923 return (ret); 924 } 925 926 927 /* 928 * bus dma unbind handle entry point: 929 */ 930 /*ARGSUSED*/ 931 int 932 px_dma_unbindhdl(dev_info_t *dip, dev_info_t *rdip, ddi_dma_handle_t handle) 933 { 934 ddi_dma_impl_t *mp = (ddi_dma_impl_t *)handle; 935 px_t *px_p = DIP_TO_STATE(dip); 936 px_mmu_t *mmu_p = px_p->px_mmu_p; 937 938 DBG(DBG_DMA_UNBINDH, dip, "rdip=%s%d, mp=%p\n", 939 ddi_driver_name(rdip), ddi_get_instance(rdip), handle); 940 if ((mp->dmai_flags & DMAI_FLAGS_INUSE) == 0) { 941 DBG(DBG_DMA_UNBINDH, dip, "handle not inuse\n"); 942 return (DDI_FAILURE); 943 } 944 945 /* remove dma handle from FMA cache */ 946 if (mp->dmai_attr.dma_attr_flags & DDI_DMA_FLAGERR) { 947 if (DEVI(rdip)->devi_fmhdl != NULL && 948 DDI_FM_DMA_ERR_CAP(DEVI(rdip)->devi_fmhdl->fh_cap)) { 949 (void) ndi_fmc_remove(rdip, DMA_HANDLE, mp); 950 } 951 } 952 953 /* 954 * Here if the handle is using the iommu. Unload all the iommu 955 * translations. 956 */ 957 switch (PX_DMA_TYPE(mp)) { 958 case DMAI_FLAGS_DVMA: 959 px_mmu_unmap_window(mmu_p, mp); 960 px_dvma_unmap(mmu_p, mp); 961 px_dma_freepfn(mp); 962 break; 963 case DMAI_FLAGS_BYPASS: 964 case DMAI_FLAGS_PTP: 965 px_dma_freewin(mp); 966 break; 967 default: 968 cmn_err(CE_PANIC, "%s%d: px_dma_unbindhdl:bad dma type %p", 969 ddi_driver_name(rdip), ddi_get_instance(rdip), mp); 970 /*NOTREACHED*/ 971 } 972 if (mmu_p->mmu_dvma_clid != 0) { 973 DBG(DBG_DMA_UNBINDH, dip, "run dvma callback\n"); 974 ddi_run_callback(&mmu_p->mmu_dvma_clid); 975 } 976 if (px_kmem_clid) { 977 DBG(DBG_DMA_UNBINDH, dip, "run handle callback\n"); 978 ddi_run_callback(&px_kmem_clid); 979 } 980 mp->dmai_flags &= DMAI_FLAGS_PRESERVE; 981 982 return (DDI_SUCCESS); 983 } 984 985 /* 986 * bus dma win entry point: 987 */ 988 int 989 px_dma_win(dev_info_t *dip, dev_info_t *rdip, 990 ddi_dma_handle_t handle, uint_t win, off_t *offp, 991 size_t *lenp, ddi_dma_cookie_t *cookiep, uint_t *ccountp) 992 { 993 ddi_dma_impl_t *mp = (ddi_dma_impl_t *)handle; 994 int ret; 995 996 DBG(DBG_DMA_WIN, dip, "rdip=%s%d\n", 997 ddi_driver_name(rdip), ddi_get_instance(rdip)); 998 999 px_dump_dma_handle(DBG_DMA_WIN, dip, mp); 1000 if (win >= mp->dmai_nwin) { 1001 DBG(DBG_DMA_WIN, dip, "%x out of range\n", win); 1002 return (DDI_FAILURE); 1003 } 1004 1005 switch (PX_DMA_TYPE(mp)) { 1006 case DMAI_FLAGS_DVMA: 1007 if (win != PX_DMA_CURWIN(mp)) { 1008 px_t *px_p = DIP_TO_STATE(dip); 1009 px_mmu_t *mmu_p = px_p->px_mmu_p; 1010 px_mmu_unmap_window(mmu_p, mp); 1011 1012 /* map_window sets dmai_mapping/size/offset */ 1013 px_mmu_map_window(mmu_p, mp, win); 1014 if ((ret = px_mmu_map_window(mmu_p, 1015 mp, win)) != DDI_SUCCESS) 1016 return (ret); 1017 } 1018 if (cookiep) 1019 MAKE_DMA_COOKIE(cookiep, mp->dmai_mapping, 1020 mp->dmai_size); 1021 if (ccountp) 1022 *ccountp = 1; 1023 break; 1024 case DMAI_FLAGS_PTP: 1025 case DMAI_FLAGS_BYPASS: { 1026 int i; 1027 ddi_dma_cookie_t *ck_p; 1028 px_dma_win_t *win_p = mp->dmai_winlst; 1029 1030 for (i = 0; i < win; win_p = win_p->win_next, i++); 1031 ck_p = (ddi_dma_cookie_t *)(win_p + 1); 1032 *cookiep = *ck_p; 1033 mp->dmai_offset = win_p->win_offset; 1034 mp->dmai_size = win_p->win_size; 1035 mp->dmai_mapping = ck_p->dmac_laddress; 1036 mp->dmai_cookie = ck_p + 1; 1037 win_p->win_curseg = 0; 1038 if (ccountp) 1039 *ccountp = win_p->win_ncookies; 1040 } 1041 break; 1042 default: 1043 cmn_err(CE_WARN, "%s%d: px_dma_win:bad dma type 0x%x", 1044 ddi_driver_name(rdip), ddi_get_instance(rdip), 1045 PX_DMA_TYPE(mp)); 1046 return (DDI_FAILURE); 1047 } 1048 if (cookiep) 1049 DBG(DBG_DMA_WIN, dip, 1050 "cookie - dmac_address=%x dmac_size=%x\n", 1051 cookiep->dmac_address, cookiep->dmac_size); 1052 if (offp) 1053 *offp = (off_t)mp->dmai_offset; 1054 if (lenp) 1055 *lenp = mp->dmai_size; 1056 return (DDI_SUCCESS); 1057 } 1058 1059 #ifdef DEBUG 1060 static char *px_dmactl_str[] = { 1061 "DDI_DMA_FREE", 1062 "DDI_DMA_SYNC", 1063 "DDI_DMA_HTOC", 1064 "DDI_DMA_KVADDR", 1065 "DDI_DMA_MOVWIN", 1066 "DDI_DMA_REPWIN", 1067 "DDI_DMA_GETERR", 1068 "DDI_DMA_COFF", 1069 "DDI_DMA_NEXTWIN", 1070 "DDI_DMA_NEXTSEG", 1071 "DDI_DMA_SEGTOC", 1072 "DDI_DMA_RESERVE", 1073 "DDI_DMA_RELEASE", 1074 "DDI_DMA_RESETH", 1075 "DDI_DMA_CKSYNC", 1076 "DDI_DMA_IOPB_ALLOC", 1077 "DDI_DMA_IOPB_FREE", 1078 "DDI_DMA_SMEM_ALLOC", 1079 "DDI_DMA_SMEM_FREE", 1080 "DDI_DMA_SET_SBUS64" 1081 }; 1082 #endif /* DEBUG */ 1083 1084 /* 1085 * bus dma control entry point: 1086 */ 1087 /*ARGSUSED*/ 1088 int 1089 px_dma_ctlops(dev_info_t *dip, dev_info_t *rdip, ddi_dma_handle_t handle, 1090 enum ddi_dma_ctlops cmd, off_t *offp, size_t *lenp, caddr_t *objp, 1091 uint_t cache_flags) 1092 { 1093 ddi_dma_impl_t *mp = (ddi_dma_impl_t *)handle; 1094 1095 #ifdef DEBUG 1096 DBG(DBG_DMA_CTL, dip, "%s: rdip=%s%d\n", px_dmactl_str[cmd], 1097 ddi_driver_name(rdip), ddi_get_instance(rdip)); 1098 #endif /* DEBUG */ 1099 1100 switch (cmd) { 1101 case DDI_DMA_FREE: 1102 (void) px_dma_unbindhdl(dip, rdip, handle); 1103 (void) px_dma_freehdl(dip, rdip, handle); 1104 return (DDI_SUCCESS); 1105 case DDI_DMA_RESERVE: { 1106 px_t *px_p = DIP_TO_STATE(dip); 1107 return (px_fdvma_reserve(dip, rdip, px_p, 1108 (ddi_dma_req_t *)offp, (ddi_dma_handle_t *)objp)); 1109 } 1110 case DDI_DMA_RELEASE: { 1111 px_t *px_p = DIP_TO_STATE(dip); 1112 return (px_fdvma_release(dip, px_p, mp)); 1113 } 1114 default: 1115 break; 1116 } 1117 1118 switch (PX_DMA_TYPE(mp)) { 1119 case DMAI_FLAGS_DVMA: 1120 return (px_dvma_ctl(dip, rdip, mp, cmd, offp, lenp, objp, 1121 cache_flags)); 1122 case DMAI_FLAGS_PTP: 1123 case DMAI_FLAGS_BYPASS: 1124 return (px_dma_ctl(dip, rdip, mp, cmd, offp, lenp, objp, 1125 cache_flags)); 1126 default: 1127 cmn_err(CE_PANIC, "%s%d: px_dma_ctlops(%x):bad dma type %x", 1128 ddi_driver_name(rdip), ddi_get_instance(rdip), cmd, 1129 mp->dmai_flags); 1130 /*NOTREACHED*/ 1131 } 1132 } 1133 1134 /* 1135 * control ops entry point: 1136 * 1137 * Requests handled completely: 1138 * DDI_CTLOPS_INITCHILD see init_child() for details 1139 * DDI_CTLOPS_UNINITCHILD 1140 * DDI_CTLOPS_REPORTDEV see report_dev() for details 1141 * DDI_CTLOPS_XLATE_INTRS nothing to do 1142 * DDI_CTLOPS_IOMIN cache line size if streaming otherwise 1 1143 * DDI_CTLOPS_REGSIZE 1144 * DDI_CTLOPS_NREGS 1145 * DDI_CTLOPS_NINTRS 1146 * DDI_CTLOPS_DVMAPAGESIZE 1147 * DDI_CTLOPS_POKE 1148 * DDI_CTLOPS_PEEK 1149 * 1150 * All others passed to parent. 1151 */ 1152 int 1153 px_ctlops(dev_info_t *dip, dev_info_t *rdip, 1154 ddi_ctl_enum_t op, void *arg, void *result) 1155 { 1156 px_t *px_p = DIP_TO_STATE(dip); 1157 struct detachspec *ds; 1158 struct attachspec *as; 1159 1160 switch (op) { 1161 case DDI_CTLOPS_INITCHILD: 1162 return (px_init_child(px_p, (dev_info_t *)arg)); 1163 1164 case DDI_CTLOPS_UNINITCHILD: 1165 return (px_uninit_child(px_p, (dev_info_t *)arg)); 1166 1167 case DDI_CTLOPS_ATTACH: 1168 as = (struct attachspec *)arg; 1169 switch (as->when) { 1170 case DDI_PRE: 1171 if (as->cmd == DDI_ATTACH) { 1172 DBG(DBG_PWR, dip, "PRE_ATTACH for %s@%d\n", 1173 ddi_driver_name(rdip), 1174 ddi_get_instance(rdip)); 1175 return (pcie_pm_hold(dip)); 1176 } 1177 if (as->cmd == DDI_RESUME) { 1178 ddi_acc_handle_t config_handle; 1179 DBG(DBG_PWR, dip, "PRE_RESUME for %s@%d\n", 1180 ddi_driver_name(rdip), 1181 ddi_get_instance(rdip)); 1182 1183 if (pci_config_setup(rdip, &config_handle) == 1184 DDI_SUCCESS) { 1185 pcie_clear_errors(rdip, config_handle); 1186 pci_config_teardown(&config_handle); 1187 } 1188 } 1189 return (DDI_SUCCESS); 1190 1191 case DDI_POST: 1192 DBG(DBG_PWR, dip, "POST_ATTACH for %s@%d\n", 1193 ddi_driver_name(rdip), ddi_get_instance(rdip)); 1194 if (as->cmd == DDI_ATTACH && as->result != DDI_SUCCESS) 1195 pcie_pm_release(dip); 1196 return (DDI_SUCCESS); 1197 default: 1198 break; 1199 } 1200 break; 1201 1202 case DDI_CTLOPS_DETACH: 1203 ds = (struct detachspec *)arg; 1204 switch (ds->when) { 1205 case DDI_POST: 1206 if (ds->cmd == DDI_DETACH && 1207 ds->result == DDI_SUCCESS) { 1208 DBG(DBG_PWR, dip, "POST_DETACH for %s@%d\n", 1209 ddi_driver_name(rdip), 1210 ddi_get_instance(rdip)); 1211 return (pcie_pm_remove_child(dip, rdip)); 1212 } 1213 return (DDI_SUCCESS); 1214 default: 1215 break; 1216 } 1217 break; 1218 1219 case DDI_CTLOPS_REPORTDEV: 1220 return (px_report_dev(rdip)); 1221 1222 case DDI_CTLOPS_IOMIN: 1223 return (DDI_SUCCESS); 1224 1225 case DDI_CTLOPS_REGSIZE: 1226 *((off_t *)result) = px_get_reg_set_size(rdip, *((int *)arg)); 1227 return (*((off_t *)result) == 0 ? DDI_FAILURE : DDI_SUCCESS); 1228 1229 case DDI_CTLOPS_NREGS: 1230 *((uint_t *)result) = px_get_nreg_set(rdip); 1231 return (DDI_SUCCESS); 1232 1233 case DDI_CTLOPS_DVMAPAGESIZE: 1234 *((ulong_t *)result) = MMU_PAGE_SIZE; 1235 return (DDI_SUCCESS); 1236 1237 case DDI_CTLOPS_POKE: /* platform dependent implementation. */ 1238 return (px_lib_ctlops_poke(dip, rdip, 1239 (peekpoke_ctlops_t *)arg)); 1240 1241 case DDI_CTLOPS_PEEK: /* platform dependent implementation. */ 1242 return (px_lib_ctlops_peek(dip, rdip, 1243 (peekpoke_ctlops_t *)arg, result)); 1244 1245 case DDI_CTLOPS_POWER: 1246 default: 1247 break; 1248 } 1249 1250 /* 1251 * Now pass the request up to our parent. 1252 */ 1253 DBG(DBG_CTLOPS, dip, "passing request to parent: rdip=%s%d\n", 1254 ddi_driver_name(rdip), ddi_get_instance(rdip)); 1255 return (ddi_ctlops(dip, rdip, op, arg, result)); 1256 } 1257 1258 /* ARGSUSED */ 1259 int 1260 px_intr_ops(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t intr_op, 1261 ddi_intr_handle_impl_t *hdlp, void *result) 1262 { 1263 int intr_types, ret = DDI_SUCCESS; 1264 1265 DBG(DBG_INTROPS, dip, "px_intr_ops: rdip=%s%d\n", 1266 ddi_driver_name(rdip), ddi_get_instance(rdip)); 1267 1268 /* Process DDI_INTROP_SUPPORTED_TYPES request here */ 1269 if (intr_op == DDI_INTROP_SUPPORTED_TYPES) { 1270 px_t *px_p = DIP_TO_STATE(dip); 1271 px_msi_state_t *msi_state_p = &px_p->px_ib_p->ib_msi_state; 1272 1273 *(int *)result = i_ddi_get_nintrs(rdip) ? 1274 DDI_INTR_TYPE_FIXED : 0; 1275 1276 if ((pci_msi_get_supported_type(rdip, 1277 &intr_types)) == DDI_SUCCESS) { 1278 /* 1279 * Double check supported interrupt types vs. 1280 * what the host bridge supports. 1281 */ 1282 *(int *)result |= (intr_types & msi_state_p->msi_type); 1283 } 1284 1285 return (ret); 1286 } 1287 1288 /* 1289 * PCI-E nexus driver supports fixed, MSI and MSI-X interrupts. 1290 * Return failure if interrupt type is not supported. 1291 */ 1292 switch (hdlp->ih_type) { 1293 case DDI_INTR_TYPE_FIXED: 1294 ret = px_intx_ops(dip, rdip, intr_op, hdlp, result); 1295 break; 1296 case DDI_INTR_TYPE_MSI: 1297 case DDI_INTR_TYPE_MSIX: 1298 ret = px_msix_ops(dip, rdip, intr_op, hdlp, result); 1299 break; 1300 default: 1301 ret = DDI_ENOTSUP; 1302 break; 1303 } 1304 1305 return (ret); 1306 } 1307