17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 237c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate /* 307c478bd9Sstevel@tonic-gate * PCI Express nexus driver interface 317c478bd9Sstevel@tonic-gate */ 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate #include <sys/types.h> 347c478bd9Sstevel@tonic-gate #include <sys/conf.h> /* nulldev */ 357c478bd9Sstevel@tonic-gate #include <sys/stat.h> /* devctl */ 367c478bd9Sstevel@tonic-gate #include <sys/kmem.h> 377c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 387c478bd9Sstevel@tonic-gate #include <sys/sunndi.h> 397c478bd9Sstevel@tonic-gate #include <sys/hotplug/pci/pcihp.h> 407c478bd9Sstevel@tonic-gate #include <sys/ddi_impldefs.h> 417c478bd9Sstevel@tonic-gate #include <sys/ddi_subrdefs.h> 421a887b2eSjchu #include <sys/spl.h> 437c478bd9Sstevel@tonic-gate #include <sys/epm.h> 447c478bd9Sstevel@tonic-gate #include <sys/iommutsb.h> 457c478bd9Sstevel@tonic-gate #include "px_obj.h" 4669cd775fSschwartz #include <sys/pci_tools.h> 47d4476ccbSschwartz #include "px_tools_ext.h" 487c478bd9Sstevel@tonic-gate #include "pcie_pwr.h" 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate /*LINTLIBRARY*/ 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate /* 537c478bd9Sstevel@tonic-gate * function prototypes for dev ops routines: 547c478bd9Sstevel@tonic-gate */ 557c478bd9Sstevel@tonic-gate static int px_attach(dev_info_t *dip, ddi_attach_cmd_t cmd); 567c478bd9Sstevel@tonic-gate static int px_detach(dev_info_t *dip, ddi_detach_cmd_t cmd); 577c478bd9Sstevel@tonic-gate static int px_info(dev_info_t *dip, ddi_info_cmd_t infocmd, 587c478bd9Sstevel@tonic-gate void *arg, void **result); 597c478bd9Sstevel@tonic-gate static int px_pwr_setup(dev_info_t *dip); 607c478bd9Sstevel@tonic-gate static void px_pwr_teardown(dev_info_t *dip); 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate /* 637c478bd9Sstevel@tonic-gate * bus ops and dev ops structures: 647c478bd9Sstevel@tonic-gate */ 657c478bd9Sstevel@tonic-gate static struct bus_ops px_bus_ops = { 667c478bd9Sstevel@tonic-gate BUSO_REV, 677c478bd9Sstevel@tonic-gate px_map, 687c478bd9Sstevel@tonic-gate 0, 697c478bd9Sstevel@tonic-gate 0, 707c478bd9Sstevel@tonic-gate 0, 717c478bd9Sstevel@tonic-gate i_ddi_map_fault, 727c478bd9Sstevel@tonic-gate px_dma_setup, 737c478bd9Sstevel@tonic-gate px_dma_allochdl, 747c478bd9Sstevel@tonic-gate px_dma_freehdl, 757c478bd9Sstevel@tonic-gate px_dma_bindhdl, 767c478bd9Sstevel@tonic-gate px_dma_unbindhdl, 777c478bd9Sstevel@tonic-gate px_lib_dma_sync, 787c478bd9Sstevel@tonic-gate px_dma_win, 797c478bd9Sstevel@tonic-gate px_dma_ctlops, 807c478bd9Sstevel@tonic-gate px_ctlops, 817c478bd9Sstevel@tonic-gate ddi_bus_prop_op, 827c478bd9Sstevel@tonic-gate ndi_busop_get_eventcookie, 837c478bd9Sstevel@tonic-gate ndi_busop_add_eventcall, 847c478bd9Sstevel@tonic-gate ndi_busop_remove_eventcall, 857c478bd9Sstevel@tonic-gate ndi_post_event, 867c478bd9Sstevel@tonic-gate NULL, 877c478bd9Sstevel@tonic-gate NULL, /* (*bus_config)(); */ 887c478bd9Sstevel@tonic-gate NULL, /* (*bus_unconfig)(); */ 897c478bd9Sstevel@tonic-gate px_fm_init_child, /* (*bus_fm_init)(); */ 907c478bd9Sstevel@tonic-gate NULL, /* (*bus_fm_fini)(); */ 91f8d2de6bSjchu px_bus_enter, /* (*bus_fm_access_enter)(); */ 92f8d2de6bSjchu px_bus_exit, /* (*bus_fm_access_fini)(); */ 937c478bd9Sstevel@tonic-gate pcie_bus_power, /* (*bus_power)(); */ 947c478bd9Sstevel@tonic-gate px_intr_ops /* (*bus_intr_op)(); */ 957c478bd9Sstevel@tonic-gate }; 967c478bd9Sstevel@tonic-gate 977c478bd9Sstevel@tonic-gate extern struct cb_ops px_cb_ops; 987c478bd9Sstevel@tonic-gate 997c478bd9Sstevel@tonic-gate static struct dev_ops px_ops = { 1007c478bd9Sstevel@tonic-gate DEVO_REV, 1017c478bd9Sstevel@tonic-gate 0, 1027c478bd9Sstevel@tonic-gate px_info, 1037c478bd9Sstevel@tonic-gate nulldev, 1047c478bd9Sstevel@tonic-gate 0, 1057c478bd9Sstevel@tonic-gate px_attach, 1067c478bd9Sstevel@tonic-gate px_detach, 1077c478bd9Sstevel@tonic-gate nodev, 1087c478bd9Sstevel@tonic-gate &px_cb_ops, 1097c478bd9Sstevel@tonic-gate &px_bus_ops, 1107c478bd9Sstevel@tonic-gate nulldev 1117c478bd9Sstevel@tonic-gate }; 1127c478bd9Sstevel@tonic-gate 1137c478bd9Sstevel@tonic-gate /* 1147c478bd9Sstevel@tonic-gate * module definitions: 1157c478bd9Sstevel@tonic-gate */ 1167c478bd9Sstevel@tonic-gate #include <sys/modctl.h> 1177c478bd9Sstevel@tonic-gate extern struct mod_ops mod_driverops; 1187c478bd9Sstevel@tonic-gate 1197c478bd9Sstevel@tonic-gate static struct modldrv modldrv = { 1207c478bd9Sstevel@tonic-gate &mod_driverops, /* Type of module - driver */ 1217c478bd9Sstevel@tonic-gate "PCI Express nexus driver %I%", /* Name of module. */ 1227c478bd9Sstevel@tonic-gate &px_ops, /* driver ops */ 1237c478bd9Sstevel@tonic-gate }; 1247c478bd9Sstevel@tonic-gate 1257c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = { 1267c478bd9Sstevel@tonic-gate MODREV_1, (void *)&modldrv, NULL 1277c478bd9Sstevel@tonic-gate }; 1287c478bd9Sstevel@tonic-gate 1297c478bd9Sstevel@tonic-gate /* driver soft state */ 1307c478bd9Sstevel@tonic-gate void *px_state_p; 1317c478bd9Sstevel@tonic-gate 1327c478bd9Sstevel@tonic-gate int 1337c478bd9Sstevel@tonic-gate _init(void) 1347c478bd9Sstevel@tonic-gate { 1357c478bd9Sstevel@tonic-gate int e; 1367c478bd9Sstevel@tonic-gate 1377c478bd9Sstevel@tonic-gate /* 1387c478bd9Sstevel@tonic-gate * Initialize per-px bus soft state pointer. 1397c478bd9Sstevel@tonic-gate */ 1407c478bd9Sstevel@tonic-gate e = ddi_soft_state_init(&px_state_p, sizeof (px_t), 1); 1417c478bd9Sstevel@tonic-gate if (e != DDI_SUCCESS) 1427c478bd9Sstevel@tonic-gate return (e); 1437c478bd9Sstevel@tonic-gate 1447c478bd9Sstevel@tonic-gate /* 1457c478bd9Sstevel@tonic-gate * Install the module. 1467c478bd9Sstevel@tonic-gate */ 1477c478bd9Sstevel@tonic-gate e = mod_install(&modlinkage); 1487c478bd9Sstevel@tonic-gate if (e != DDI_SUCCESS) 1497c478bd9Sstevel@tonic-gate ddi_soft_state_fini(&px_state_p); 1507c478bd9Sstevel@tonic-gate return (e); 1517c478bd9Sstevel@tonic-gate } 1527c478bd9Sstevel@tonic-gate 1537c478bd9Sstevel@tonic-gate int 1547c478bd9Sstevel@tonic-gate _fini(void) 1557c478bd9Sstevel@tonic-gate { 1567c478bd9Sstevel@tonic-gate int e; 1577c478bd9Sstevel@tonic-gate 1587c478bd9Sstevel@tonic-gate /* 1597c478bd9Sstevel@tonic-gate * Remove the module. 1607c478bd9Sstevel@tonic-gate */ 1617c478bd9Sstevel@tonic-gate e = mod_remove(&modlinkage); 1627c478bd9Sstevel@tonic-gate if (e != DDI_SUCCESS) 1637c478bd9Sstevel@tonic-gate return (e); 1647c478bd9Sstevel@tonic-gate 1657c478bd9Sstevel@tonic-gate /* Free px soft state */ 1667c478bd9Sstevel@tonic-gate ddi_soft_state_fini(&px_state_p); 1677c478bd9Sstevel@tonic-gate 1687c478bd9Sstevel@tonic-gate return (e); 1697c478bd9Sstevel@tonic-gate } 1707c478bd9Sstevel@tonic-gate 1717c478bd9Sstevel@tonic-gate int 1727c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop) 1737c478bd9Sstevel@tonic-gate { 1747c478bd9Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 1757c478bd9Sstevel@tonic-gate } 1767c478bd9Sstevel@tonic-gate 1777c478bd9Sstevel@tonic-gate /* ARGSUSED */ 1787c478bd9Sstevel@tonic-gate static int 1797c478bd9Sstevel@tonic-gate px_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result) 1807c478bd9Sstevel@tonic-gate { 1817c478bd9Sstevel@tonic-gate int instance = getminor((dev_t)arg); 1827c478bd9Sstevel@tonic-gate px_t *px_p = INST_TO_STATE(instance); 1837c478bd9Sstevel@tonic-gate 1847c478bd9Sstevel@tonic-gate #ifdef HOTPLUG 1857c478bd9Sstevel@tonic-gate /* 1867c478bd9Sstevel@tonic-gate * Allow hotplug to deal with ones it manages 1877c478bd9Sstevel@tonic-gate * Hot Plug will be done later. 1887c478bd9Sstevel@tonic-gate */ 1897c478bd9Sstevel@tonic-gate if (px_p && (px_p->hotplug_capable == B_TRUE)) 1907c478bd9Sstevel@tonic-gate return (pcihp_info(dip, infocmd, arg, result)); 1917c478bd9Sstevel@tonic-gate #endif /* HOTPLUG */ 1927c478bd9Sstevel@tonic-gate 1937c478bd9Sstevel@tonic-gate /* non-hotplug or not attached */ 1947c478bd9Sstevel@tonic-gate switch (infocmd) { 1957c478bd9Sstevel@tonic-gate case DDI_INFO_DEVT2INSTANCE: 196b40cec45Skrishnae *result = (void *)(intptr_t)instance; 1977c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 1987c478bd9Sstevel@tonic-gate 1997c478bd9Sstevel@tonic-gate case DDI_INFO_DEVT2DEVINFO: 2007c478bd9Sstevel@tonic-gate if (px_p == NULL) 2017c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 2027c478bd9Sstevel@tonic-gate *result = (void *)px_p->px_dip; 2037c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 2047c478bd9Sstevel@tonic-gate 2057c478bd9Sstevel@tonic-gate default: 2067c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 2077c478bd9Sstevel@tonic-gate } 2087c478bd9Sstevel@tonic-gate } 2097c478bd9Sstevel@tonic-gate 2107c478bd9Sstevel@tonic-gate /* device driver entry points */ 2117c478bd9Sstevel@tonic-gate /* 2127c478bd9Sstevel@tonic-gate * attach entry point: 2137c478bd9Sstevel@tonic-gate */ 2147c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 2157c478bd9Sstevel@tonic-gate static int 2167c478bd9Sstevel@tonic-gate px_attach(dev_info_t *dip, ddi_attach_cmd_t cmd) 2177c478bd9Sstevel@tonic-gate { 2187c478bd9Sstevel@tonic-gate px_t *px_p; /* per bus state pointer */ 2197c478bd9Sstevel@tonic-gate int instance = DIP_TO_INST(dip); 2207c478bd9Sstevel@tonic-gate int ret = DDI_SUCCESS; 2217c478bd9Sstevel@tonic-gate devhandle_t dev_hdl = NULL; 2227c478bd9Sstevel@tonic-gate 2237c478bd9Sstevel@tonic-gate switch (cmd) { 2247c478bd9Sstevel@tonic-gate case DDI_ATTACH: 2257c478bd9Sstevel@tonic-gate DBG(DBG_ATTACH, dip, "DDI_ATTACH\n"); 2267c478bd9Sstevel@tonic-gate 2277c478bd9Sstevel@tonic-gate /* 2287c478bd9Sstevel@tonic-gate * Allocate and get the per-px soft state structure. 2297c478bd9Sstevel@tonic-gate */ 2307c478bd9Sstevel@tonic-gate if (ddi_soft_state_zalloc(px_state_p, instance) 2317c478bd9Sstevel@tonic-gate != DDI_SUCCESS) { 2327c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d: can't allocate px state", 2337c478bd9Sstevel@tonic-gate ddi_driver_name(dip), instance); 2347c478bd9Sstevel@tonic-gate goto err_bad_px_softstate; 2357c478bd9Sstevel@tonic-gate } 2367c478bd9Sstevel@tonic-gate px_p = INST_TO_STATE(instance); 2377c478bd9Sstevel@tonic-gate px_p->px_dip = dip; 2387c478bd9Sstevel@tonic-gate mutex_init(&px_p->px_mutex, NULL, MUTEX_DRIVER, NULL); 2397c478bd9Sstevel@tonic-gate px_p->px_soft_state = PX_SOFT_STATE_CLOSED; 2407c478bd9Sstevel@tonic-gate px_p->px_open_count = 0; 2417c478bd9Sstevel@tonic-gate 2427c478bd9Sstevel@tonic-gate /* 2437c478bd9Sstevel@tonic-gate * Get key properties of the pci bridge node and 2447c478bd9Sstevel@tonic-gate * determine it's type (psycho, schizo, etc ...). 2457c478bd9Sstevel@tonic-gate */ 2467c478bd9Sstevel@tonic-gate if (px_get_props(px_p, dip) == DDI_FAILURE) 2477c478bd9Sstevel@tonic-gate goto err_bad_px_prop; 2487c478bd9Sstevel@tonic-gate 2497c478bd9Sstevel@tonic-gate if ((px_fm_attach(px_p)) != DDI_SUCCESS) 2507c478bd9Sstevel@tonic-gate goto err_bad_fm; 2517c478bd9Sstevel@tonic-gate 2527c478bd9Sstevel@tonic-gate if (px_lib_dev_init(dip, &dev_hdl) != DDI_SUCCESS) 2537c478bd9Sstevel@tonic-gate goto err_bad_dev_init; 2547c478bd9Sstevel@tonic-gate 2557c478bd9Sstevel@tonic-gate /* Initilize device handle */ 2567c478bd9Sstevel@tonic-gate px_p->px_dev_hdl = dev_hdl; 2577c478bd9Sstevel@tonic-gate 2587c478bd9Sstevel@tonic-gate /* 2597c478bd9Sstevel@tonic-gate * Initialize interrupt block. Note that this 2607c478bd9Sstevel@tonic-gate * initialize error handling for the PEC as well. 2617c478bd9Sstevel@tonic-gate */ 2627c478bd9Sstevel@tonic-gate if ((ret = px_ib_attach(px_p)) != DDI_SUCCESS) 2637c478bd9Sstevel@tonic-gate goto err_bad_ib; 2647c478bd9Sstevel@tonic-gate 2657c478bd9Sstevel@tonic-gate if (px_cb_attach(px_p) != DDI_SUCCESS) 2667c478bd9Sstevel@tonic-gate goto err_bad_cb; 2677c478bd9Sstevel@tonic-gate 2687c478bd9Sstevel@tonic-gate /* 2697c478bd9Sstevel@tonic-gate * Start creating the modules. 2707c478bd9Sstevel@tonic-gate * Note that attach() routines should 2717c478bd9Sstevel@tonic-gate * register and enable their own interrupts. 2727c478bd9Sstevel@tonic-gate */ 2737c478bd9Sstevel@tonic-gate 2747c478bd9Sstevel@tonic-gate if ((px_mmu_attach(px_p)) != DDI_SUCCESS) 2757c478bd9Sstevel@tonic-gate goto err_bad_mmu; 2767c478bd9Sstevel@tonic-gate 2777c478bd9Sstevel@tonic-gate if ((px_msiq_attach(px_p)) != DDI_SUCCESS) 2787c478bd9Sstevel@tonic-gate goto err_bad_msiq; 2797c478bd9Sstevel@tonic-gate 2807c478bd9Sstevel@tonic-gate if ((px_msi_attach(px_p)) != DDI_SUCCESS) 2817c478bd9Sstevel@tonic-gate goto err_bad_msi; 2827c478bd9Sstevel@tonic-gate 2837c478bd9Sstevel@tonic-gate if ((px_pec_attach(px_p)) != DDI_SUCCESS) 2847c478bd9Sstevel@tonic-gate goto err_bad_pec; 2857c478bd9Sstevel@tonic-gate 2867c478bd9Sstevel@tonic-gate if ((px_dma_attach(px_p)) != DDI_SUCCESS) 2877c478bd9Sstevel@tonic-gate goto err_bad_pec; /* nothing to uninitialize on DMA */ 2887c478bd9Sstevel@tonic-gate 2897c478bd9Sstevel@tonic-gate /* 2907c478bd9Sstevel@tonic-gate * All of the error handlers have been registered 2917c478bd9Sstevel@tonic-gate * by now so it's time to activate the interrupt. 2927c478bd9Sstevel@tonic-gate */ 293f8d2de6bSjchu if ((ret = px_err_add_intr(&px_p->px_fault)) != DDI_SUCCESS) 2947c478bd9Sstevel@tonic-gate goto err_bad_pec_add_intr; 2957c478bd9Sstevel@tonic-gate 2967c478bd9Sstevel@tonic-gate /* 2977c478bd9Sstevel@tonic-gate * Create the "devctl" node for hotplug and pcitool support. 2987c478bd9Sstevel@tonic-gate * For non-hotplug bus, we still need ":devctl" to 2997c478bd9Sstevel@tonic-gate * support DEVCTL_DEVICE_* and DEVCTL_BUS_* ioctls. 3007c478bd9Sstevel@tonic-gate */ 3017c478bd9Sstevel@tonic-gate if (ddi_create_minor_node(dip, "devctl", S_IFCHR, 3027c478bd9Sstevel@tonic-gate PCIHP_AP_MINOR_NUM(instance, PCIHP_DEVCTL_MINOR), 3037c478bd9Sstevel@tonic-gate DDI_NT_NEXUS, 0) != DDI_SUCCESS) { 3047c478bd9Sstevel@tonic-gate goto err_bad_devctl_node; 3057c478bd9Sstevel@tonic-gate } 30669cd775fSschwartz 30769cd775fSschwartz if (pxtool_init(dip) != DDI_SUCCESS) 30869cd775fSschwartz goto err_bad_pcitool_node; 30969cd775fSschwartz 3107c478bd9Sstevel@tonic-gate /* 3117c478bd9Sstevel@tonic-gate * power management setup. Even if it fails, attach will 3127c478bd9Sstevel@tonic-gate * succeed as this is a optional feature. Since we are 3137c478bd9Sstevel@tonic-gate * always at full power, this is not critical. 3147c478bd9Sstevel@tonic-gate */ 3157c478bd9Sstevel@tonic-gate if (pwr_common_setup(dip) != DDI_SUCCESS) { 3167c478bd9Sstevel@tonic-gate DBG(DBG_PWR, dip, "pwr_common_setup failed\n"); 3177c478bd9Sstevel@tonic-gate } else if (px_pwr_setup(dip) != DDI_SUCCESS) { 3187c478bd9Sstevel@tonic-gate DBG(DBG_PWR, dip, "px_pwr_setup failed \n"); 3197c478bd9Sstevel@tonic-gate pwr_common_teardown(dip); 3207c478bd9Sstevel@tonic-gate } 3217c478bd9Sstevel@tonic-gate 322817a6df8Sjchu /* 323817a6df8Sjchu * add cpr callback 324817a6df8Sjchu */ 325817a6df8Sjchu px_cpr_add_callb(px_p); 326817a6df8Sjchu 3277c478bd9Sstevel@tonic-gate ddi_report_dev(dip); 3287c478bd9Sstevel@tonic-gate 3297c478bd9Sstevel@tonic-gate px_p->px_state = PX_ATTACHED; 3307c478bd9Sstevel@tonic-gate DBG(DBG_ATTACH, dip, "attach success\n"); 3317c478bd9Sstevel@tonic-gate break; 3327c478bd9Sstevel@tonic-gate 33369cd775fSschwartz err_bad_pcitool_node: 33469cd775fSschwartz ddi_remove_minor_node(dip, "devctl"); 3357c478bd9Sstevel@tonic-gate err_bad_devctl_node: 336f8d2de6bSjchu px_err_rem_intr(&px_p->px_fault); 3377c478bd9Sstevel@tonic-gate err_bad_pec_add_intr: 3387c478bd9Sstevel@tonic-gate px_pec_detach(px_p); 3397c478bd9Sstevel@tonic-gate err_bad_pec: 3407c478bd9Sstevel@tonic-gate px_msi_detach(px_p); 3417c478bd9Sstevel@tonic-gate err_bad_msi: 3427c478bd9Sstevel@tonic-gate px_msiq_detach(px_p); 3437c478bd9Sstevel@tonic-gate err_bad_msiq: 3447c478bd9Sstevel@tonic-gate px_mmu_detach(px_p); 3457c478bd9Sstevel@tonic-gate err_bad_mmu: 3467c478bd9Sstevel@tonic-gate px_cb_detach(px_p); 3477c478bd9Sstevel@tonic-gate err_bad_cb: 3487c478bd9Sstevel@tonic-gate px_ib_detach(px_p); 3497c478bd9Sstevel@tonic-gate err_bad_ib: 3507c478bd9Sstevel@tonic-gate (void) px_lib_dev_fini(dip); 3517c478bd9Sstevel@tonic-gate err_bad_dev_init: 3527c478bd9Sstevel@tonic-gate px_fm_detach(px_p); 3537c478bd9Sstevel@tonic-gate err_bad_fm: 3547c478bd9Sstevel@tonic-gate px_free_props(px_p); 3557c478bd9Sstevel@tonic-gate err_bad_px_prop: 3567c478bd9Sstevel@tonic-gate mutex_destroy(&px_p->px_mutex); 3577c478bd9Sstevel@tonic-gate ddi_soft_state_free(px_state_p, instance); 3587c478bd9Sstevel@tonic-gate err_bad_px_softstate: 3597c478bd9Sstevel@tonic-gate ret = DDI_FAILURE; 3607c478bd9Sstevel@tonic-gate break; 3617c478bd9Sstevel@tonic-gate 3627c478bd9Sstevel@tonic-gate case DDI_RESUME: 3637c478bd9Sstevel@tonic-gate DBG(DBG_ATTACH, dip, "DDI_RESUME\n"); 3647c478bd9Sstevel@tonic-gate 3657c478bd9Sstevel@tonic-gate px_p = INST_TO_STATE(instance); 3667c478bd9Sstevel@tonic-gate 3677c478bd9Sstevel@tonic-gate mutex_enter(&px_p->px_mutex); 3687c478bd9Sstevel@tonic-gate 3697c478bd9Sstevel@tonic-gate /* suspend might have not succeeded */ 3707c478bd9Sstevel@tonic-gate if (px_p->px_state != PX_SUSPENDED) { 3717c478bd9Sstevel@tonic-gate DBG(DBG_ATTACH, px_p->px_dip, 3727c478bd9Sstevel@tonic-gate "instance NOT suspended\n"); 3737c478bd9Sstevel@tonic-gate ret = DDI_FAILURE; 3747c478bd9Sstevel@tonic-gate break; 3757c478bd9Sstevel@tonic-gate } 3767c478bd9Sstevel@tonic-gate 3777c478bd9Sstevel@tonic-gate px_lib_resume(dip); 3787c478bd9Sstevel@tonic-gate (void) pcie_pwr_resume(dip); 3797c478bd9Sstevel@tonic-gate px_p->px_state = PX_ATTACHED; 3807c478bd9Sstevel@tonic-gate 3817c478bd9Sstevel@tonic-gate mutex_exit(&px_p->px_mutex); 3827c478bd9Sstevel@tonic-gate 3837c478bd9Sstevel@tonic-gate break; 3847c478bd9Sstevel@tonic-gate default: 3857c478bd9Sstevel@tonic-gate DBG(DBG_ATTACH, dip, "unsupported attach op\n"); 3867c478bd9Sstevel@tonic-gate ret = DDI_FAILURE; 3877c478bd9Sstevel@tonic-gate break; 3887c478bd9Sstevel@tonic-gate } 3897c478bd9Sstevel@tonic-gate 3907c478bd9Sstevel@tonic-gate return (ret); 3917c478bd9Sstevel@tonic-gate } 3927c478bd9Sstevel@tonic-gate 3937c478bd9Sstevel@tonic-gate /* 3947c478bd9Sstevel@tonic-gate * detach entry point: 3957c478bd9Sstevel@tonic-gate */ 3967c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 3977c478bd9Sstevel@tonic-gate static int 3987c478bd9Sstevel@tonic-gate px_detach(dev_info_t *dip, ddi_detach_cmd_t cmd) 3997c478bd9Sstevel@tonic-gate { 4007c478bd9Sstevel@tonic-gate int instance = ddi_get_instance(dip); 4017c478bd9Sstevel@tonic-gate px_t *px_p = INST_TO_STATE(instance); 4027c478bd9Sstevel@tonic-gate int ret; 4037c478bd9Sstevel@tonic-gate 4047c478bd9Sstevel@tonic-gate /* 4057c478bd9Sstevel@tonic-gate * Make sure we are currently attached 4067c478bd9Sstevel@tonic-gate */ 4077c478bd9Sstevel@tonic-gate if (px_p->px_state != PX_ATTACHED) { 4087c478bd9Sstevel@tonic-gate DBG(DBG_DETACH, dip, "failed - instance not attached\n"); 4097c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 4107c478bd9Sstevel@tonic-gate } 4117c478bd9Sstevel@tonic-gate 4127c478bd9Sstevel@tonic-gate mutex_enter(&px_p->px_mutex); 4137c478bd9Sstevel@tonic-gate 4147c478bd9Sstevel@tonic-gate switch (cmd) { 4157c478bd9Sstevel@tonic-gate case DDI_DETACH: 4167c478bd9Sstevel@tonic-gate DBG(DBG_DETACH, dip, "DDI_DETACH\n"); 4177c478bd9Sstevel@tonic-gate 418817a6df8Sjchu /* 419817a6df8Sjchu * remove cpr callback 420817a6df8Sjchu */ 421817a6df8Sjchu px_cpr_rem_callb(px_p); 422817a6df8Sjchu 4237c478bd9Sstevel@tonic-gate #ifdef HOTPLUG 4247c478bd9Sstevel@tonic-gate /* 4257c478bd9Sstevel@tonic-gate * Hot plug will be done later. 4267c478bd9Sstevel@tonic-gate */ 4277c478bd9Sstevel@tonic-gate if (px_p->hotplug_capable == B_TRUE) { 4287c478bd9Sstevel@tonic-gate if (pxhp_uninit(dip) == DDI_FAILURE) { 4297c478bd9Sstevel@tonic-gate mutex_exit(&px_p->px_mutex); 4307c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 4317c478bd9Sstevel@tonic-gate } 4327c478bd9Sstevel@tonic-gate } 4337c478bd9Sstevel@tonic-gate #endif /* HOTPLUG */ 4347c478bd9Sstevel@tonic-gate 4357c478bd9Sstevel@tonic-gate /* 4367c478bd9Sstevel@tonic-gate * things which used to be done in obj_destroy 4377c478bd9Sstevel@tonic-gate * are now in-lined here. 4387c478bd9Sstevel@tonic-gate */ 4397c478bd9Sstevel@tonic-gate 4407c478bd9Sstevel@tonic-gate px_p->px_state = PX_DETACHED; 4417c478bd9Sstevel@tonic-gate 44269cd775fSschwartz pxtool_uninit(dip); 44369cd775fSschwartz 4447c478bd9Sstevel@tonic-gate ddi_remove_minor_node(dip, "devctl"); 445f8d2de6bSjchu px_err_rem_intr(&px_p->px_fault); 4467c478bd9Sstevel@tonic-gate px_pec_detach(px_p); 4479c75c6bfSgovinda px_pwr_teardown(dip); 4489c75c6bfSgovinda pwr_common_teardown(dip); 4497c478bd9Sstevel@tonic-gate px_msi_detach(px_p); 4507c478bd9Sstevel@tonic-gate px_msiq_detach(px_p); 4517c478bd9Sstevel@tonic-gate px_mmu_detach(px_p); 4527c478bd9Sstevel@tonic-gate px_cb_detach(px_p); 4537c478bd9Sstevel@tonic-gate px_ib_detach(px_p); 4547c478bd9Sstevel@tonic-gate (void) px_lib_dev_fini(dip); 4557c478bd9Sstevel@tonic-gate px_fm_detach(px_p); 4567c478bd9Sstevel@tonic-gate 4577c478bd9Sstevel@tonic-gate /* 4587c478bd9Sstevel@tonic-gate * Free the px soft state structure and the rest of the 4597c478bd9Sstevel@tonic-gate * resources it's using. 4607c478bd9Sstevel@tonic-gate */ 4617c478bd9Sstevel@tonic-gate px_free_props(px_p); 4627c478bd9Sstevel@tonic-gate mutex_exit(&px_p->px_mutex); 4637c478bd9Sstevel@tonic-gate mutex_destroy(&px_p->px_mutex); 4647c478bd9Sstevel@tonic-gate 4657c478bd9Sstevel@tonic-gate /* Free the interrupt-priorities prop if we created it. */ { 4667c478bd9Sstevel@tonic-gate int len; 4677c478bd9Sstevel@tonic-gate 4687c478bd9Sstevel@tonic-gate if (ddi_getproplen(DDI_DEV_T_ANY, dip, 4697c478bd9Sstevel@tonic-gate DDI_PROP_NOTPROM | DDI_PROP_DONTPASS, 4707c478bd9Sstevel@tonic-gate "interrupt-priorities", &len) == DDI_PROP_SUCCESS) 4717c478bd9Sstevel@tonic-gate (void) ddi_prop_remove(DDI_DEV_T_NONE, dip, 4727c478bd9Sstevel@tonic-gate "interrupt-priorities"); 4737c478bd9Sstevel@tonic-gate } 4747c478bd9Sstevel@tonic-gate 4757c478bd9Sstevel@tonic-gate px_p->px_dev_hdl = NULL; 476dabea0dbSschwartz ddi_soft_state_free(px_state_p, instance); 4777c478bd9Sstevel@tonic-gate 4787c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 4797c478bd9Sstevel@tonic-gate 4807c478bd9Sstevel@tonic-gate case DDI_SUSPEND: 4817c478bd9Sstevel@tonic-gate if (pcie_pwr_suspend(dip) != DDI_SUCCESS) { 4827c478bd9Sstevel@tonic-gate mutex_exit(&px_p->px_mutex); 4837c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 4847c478bd9Sstevel@tonic-gate } 4857c478bd9Sstevel@tonic-gate if ((ret = px_lib_suspend(dip)) == DDI_SUCCESS) 4867c478bd9Sstevel@tonic-gate px_p->px_state = PX_SUSPENDED; 4877c478bd9Sstevel@tonic-gate mutex_exit(&px_p->px_mutex); 4887c478bd9Sstevel@tonic-gate 4897c478bd9Sstevel@tonic-gate return (ret); 4907c478bd9Sstevel@tonic-gate 4917c478bd9Sstevel@tonic-gate default: 4927c478bd9Sstevel@tonic-gate DBG(DBG_DETACH, dip, "unsupported detach op\n"); 4937c478bd9Sstevel@tonic-gate mutex_exit(&px_p->px_mutex); 4947c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 4957c478bd9Sstevel@tonic-gate } 4967c478bd9Sstevel@tonic-gate } 4977c478bd9Sstevel@tonic-gate 4987c478bd9Sstevel@tonic-gate /* 4997c478bd9Sstevel@tonic-gate * power management related initialization specific to px 5007c478bd9Sstevel@tonic-gate * called by px_attach() 5017c478bd9Sstevel@tonic-gate */ 5027c478bd9Sstevel@tonic-gate static int 5037c478bd9Sstevel@tonic-gate px_pwr_setup(dev_info_t *dip) 5047c478bd9Sstevel@tonic-gate { 5057c478bd9Sstevel@tonic-gate pcie_pwr_t *pwr_p; 5061a887b2eSjchu int instance = ddi_get_instance(dip); 5071a887b2eSjchu px_t *px_p = INST_TO_STATE(instance); 5087c478bd9Sstevel@tonic-gate ddi_intr_handle_impl_t hdl; 5097c478bd9Sstevel@tonic-gate 5107c478bd9Sstevel@tonic-gate ASSERT(PCIE_PMINFO(dip)); 5117c478bd9Sstevel@tonic-gate pwr_p = PCIE_NEXUS_PMINFO(dip); 5127c478bd9Sstevel@tonic-gate ASSERT(pwr_p); 5137c478bd9Sstevel@tonic-gate 5147c478bd9Sstevel@tonic-gate /* 5157c478bd9Sstevel@tonic-gate * indicate support LDI (Layered Driver Interface) 5167c478bd9Sstevel@tonic-gate * Create the property, if it is not already there 5177c478bd9Sstevel@tonic-gate */ 5187c478bd9Sstevel@tonic-gate if (!ddi_prop_exists(DDI_DEV_T_NONE, dip, DDI_PROP_DONTPASS, 5197c478bd9Sstevel@tonic-gate DDI_KERNEL_IOCTL)) { 5207c478bd9Sstevel@tonic-gate if (ddi_prop_create(DDI_DEV_T_NONE, dip, DDI_PROP_CANSLEEP, 5217c478bd9Sstevel@tonic-gate DDI_KERNEL_IOCTL, NULL, 0) != DDI_PROP_SUCCESS) { 5227c478bd9Sstevel@tonic-gate DBG(DBG_PWR, dip, "can't create kernel ioctl prop\n"); 5237c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 5247c478bd9Sstevel@tonic-gate } 5257c478bd9Sstevel@tonic-gate } 5267c478bd9Sstevel@tonic-gate /* No support for device PM. We are always at full power */ 5277c478bd9Sstevel@tonic-gate pwr_p->pwr_func_lvl = PM_LEVEL_D0; 5287c478bd9Sstevel@tonic-gate 5291a887b2eSjchu mutex_init(&px_p->px_l23ready_lock, NULL, MUTEX_DRIVER, 530a195726fSgovinda DDI_INTR_PRI(px_pwr_pil)); 5311a887b2eSjchu cv_init(&px_p->px_l23ready_cv, NULL, CV_DRIVER, NULL); 5321a887b2eSjchu 5337c478bd9Sstevel@tonic-gate /* Initilize handle */ 5341a887b2eSjchu hdl.ih_cb_arg1 = px_p; 5351a887b2eSjchu hdl.ih_cb_arg2 = NULL; 5367c478bd9Sstevel@tonic-gate hdl.ih_ver = DDI_INTR_VERSION; 5377c478bd9Sstevel@tonic-gate hdl.ih_state = DDI_IHDL_STATE_ALLOC; 5387c478bd9Sstevel@tonic-gate hdl.ih_dip = dip; 5397c478bd9Sstevel@tonic-gate hdl.ih_inum = 0; 5407c478bd9Sstevel@tonic-gate hdl.ih_pri = px_pwr_pil; 5417c478bd9Sstevel@tonic-gate 5427c478bd9Sstevel@tonic-gate /* Add PME_TO_ACK message handler */ 5431a887b2eSjchu hdl.ih_cb_func = (ddi_intr_handler_t *)px_pmeq_intr; 5447c478bd9Sstevel@tonic-gate if (px_add_msiq_intr(dip, dip, &hdl, MSG_REC, 5451a887b2eSjchu (msgcode_t)PCIE_PME_ACK_MSG, &px_p->px_pm_msiq_id) != DDI_SUCCESS) { 5461a887b2eSjchu DBG(DBG_PWR, dip, "px_pwr_setup: couldn't add " 5471a887b2eSjchu " PME_TO_ACK intr\n"); 548*f9721e07Sjchu goto pwr_setup_err1; 5497c478bd9Sstevel@tonic-gate } 5501a887b2eSjchu px_lib_msg_setmsiq(dip, PCIE_PME_ACK_MSG, px_p->px_pm_msiq_id); 5517c478bd9Sstevel@tonic-gate px_lib_msg_setvalid(dip, PCIE_PME_ACK_MSG, PCIE_MSG_VALID); 5527c478bd9Sstevel@tonic-gate 55336fe4a92Segillett if (px_ib_update_intr_state(px_p, px_p->px_dip, hdl.ih_inum, 55436fe4a92Segillett px_msiqid_to_devino(px_p, px_p->px_pm_msiq_id), 55536fe4a92Segillett PX_INTR_STATE_ENABLE, MSG_REC, PCIE_PME_ACK_MSG) != DDI_SUCCESS) { 55636fe4a92Segillett DBG(DBG_PWR, dip, "px_pwr_setup: PME_TO_ACK update interrupt" 55736fe4a92Segillett " state failed\n"); 55836fe4a92Segillett goto px_pwrsetup_err_state; 55936fe4a92Segillett } 56036fe4a92Segillett 5617c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 5627c478bd9Sstevel@tonic-gate 56336fe4a92Segillett px_pwrsetup_err_state: 56436fe4a92Segillett px_lib_msg_setvalid(dip, PCIE_PME_ACK_MSG, PCIE_MSG_INVALID); 56536fe4a92Segillett (void) px_rem_msiq_intr(dip, dip, &hdl, MSG_REC, PCIE_PME_ACK_MSG, 56636fe4a92Segillett px_p->px_pm_msiq_id); 5671a887b2eSjchu pwr_setup_err1: 5681a887b2eSjchu mutex_destroy(&px_p->px_l23ready_lock); 5691a887b2eSjchu cv_destroy(&px_p->px_l23ready_cv); 5701a887b2eSjchu 5717c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 5727c478bd9Sstevel@tonic-gate } 5737c478bd9Sstevel@tonic-gate 5747c478bd9Sstevel@tonic-gate /* 5757c478bd9Sstevel@tonic-gate * undo whatever is done in px_pwr_setup. called by px_detach() 5767c478bd9Sstevel@tonic-gate */ 5777c478bd9Sstevel@tonic-gate static void 5787c478bd9Sstevel@tonic-gate px_pwr_teardown(dev_info_t *dip) 5797c478bd9Sstevel@tonic-gate { 5801a887b2eSjchu int instance = ddi_get_instance(dip); 5811a887b2eSjchu px_t *px_p = INST_TO_STATE(instance); 5827c478bd9Sstevel@tonic-gate ddi_intr_handle_impl_t hdl; 5837c478bd9Sstevel@tonic-gate 5841a887b2eSjchu if (!PCIE_PMINFO(dip) || !PCIE_NEXUS_PMINFO(dip)) 5857c478bd9Sstevel@tonic-gate return; 5867c478bd9Sstevel@tonic-gate 5877c478bd9Sstevel@tonic-gate /* Initilize handle */ 5887c478bd9Sstevel@tonic-gate hdl.ih_ver = DDI_INTR_VERSION; 5897c478bd9Sstevel@tonic-gate hdl.ih_state = DDI_IHDL_STATE_ALLOC; 5907c478bd9Sstevel@tonic-gate hdl.ih_dip = dip; 5917c478bd9Sstevel@tonic-gate hdl.ih_inum = 0; 5927c478bd9Sstevel@tonic-gate 5937c478bd9Sstevel@tonic-gate px_lib_msg_setvalid(dip, PCIE_PME_ACK_MSG, PCIE_MSG_INVALID); 5947c478bd9Sstevel@tonic-gate (void) px_rem_msiq_intr(dip, dip, &hdl, MSG_REC, PCIE_PME_ACK_MSG, 5951a887b2eSjchu px_p->px_pm_msiq_id); 5967c478bd9Sstevel@tonic-gate 59736fe4a92Segillett (void) px_ib_update_intr_state(px_p, px_p->px_dip, hdl.ih_inum, 59836fe4a92Segillett px_msiqid_to_devino(px_p, px_p->px_pm_msiq_id), 59936fe4a92Segillett PX_INTR_STATE_DISABLE, MSG_REC, PCIE_PME_ACK_MSG); 60036fe4a92Segillett 6011a887b2eSjchu px_p->px_pm_msiq_id = -1; 6027c478bd9Sstevel@tonic-gate 6031a887b2eSjchu cv_destroy(&px_p->px_l23ready_cv); 6041a887b2eSjchu mutex_destroy(&px_p->px_l23ready_lock); 6057c478bd9Sstevel@tonic-gate } 6067c478bd9Sstevel@tonic-gate 6077c478bd9Sstevel@tonic-gate /* bus driver entry points */ 6087c478bd9Sstevel@tonic-gate 6097c478bd9Sstevel@tonic-gate /* 6107c478bd9Sstevel@tonic-gate * bus map entry point: 6117c478bd9Sstevel@tonic-gate * 6127c478bd9Sstevel@tonic-gate * if map request is for an rnumber 6137c478bd9Sstevel@tonic-gate * get the corresponding regspec from device node 6147c478bd9Sstevel@tonic-gate * build a new regspec in our parent's format 6157c478bd9Sstevel@tonic-gate * build a new map_req with the new regspec 6167c478bd9Sstevel@tonic-gate * call up the tree to complete the mapping 6177c478bd9Sstevel@tonic-gate */ 6187c478bd9Sstevel@tonic-gate int 6197c478bd9Sstevel@tonic-gate px_map(dev_info_t *dip, dev_info_t *rdip, ddi_map_req_t *mp, 6207c478bd9Sstevel@tonic-gate off_t off, off_t len, caddr_t *addrp) 6217c478bd9Sstevel@tonic-gate { 6227c478bd9Sstevel@tonic-gate px_t *px_p = DIP_TO_STATE(dip); 6237c478bd9Sstevel@tonic-gate struct regspec p_regspec; 6247c478bd9Sstevel@tonic-gate ddi_map_req_t p_mapreq; 6257c478bd9Sstevel@tonic-gate int reglen, rval, r_no; 6267c478bd9Sstevel@tonic-gate pci_regspec_t reloc_reg, *rp = &reloc_reg; 6277c478bd9Sstevel@tonic-gate 6287c478bd9Sstevel@tonic-gate DBG(DBG_MAP, dip, "rdip=%s%d:", 6297c478bd9Sstevel@tonic-gate ddi_driver_name(rdip), ddi_get_instance(rdip)); 6307c478bd9Sstevel@tonic-gate 6317c478bd9Sstevel@tonic-gate if (mp->map_flags & DDI_MF_USER_MAPPING) 6327c478bd9Sstevel@tonic-gate return (DDI_ME_UNIMPLEMENTED); 6337c478bd9Sstevel@tonic-gate 6347c478bd9Sstevel@tonic-gate switch (mp->map_type) { 6357c478bd9Sstevel@tonic-gate case DDI_MT_REGSPEC: 6367c478bd9Sstevel@tonic-gate reloc_reg = *(pci_regspec_t *)mp->map_obj.rp; /* dup whole */ 6377c478bd9Sstevel@tonic-gate break; 6387c478bd9Sstevel@tonic-gate 6397c478bd9Sstevel@tonic-gate case DDI_MT_RNUMBER: 6407c478bd9Sstevel@tonic-gate r_no = mp->map_obj.rnumber; 6417c478bd9Sstevel@tonic-gate DBG(DBG_MAP | DBG_CONT, dip, " r#=%x", r_no); 6427c478bd9Sstevel@tonic-gate 643a3282898Scth if (ddi_getlongprop(DDI_DEV_T_ANY, rdip, DDI_PROP_DONTPASS, 6447c478bd9Sstevel@tonic-gate "reg", (caddr_t)&rp, ®len) != DDI_SUCCESS) 6457c478bd9Sstevel@tonic-gate return (DDI_ME_RNUMBER_RANGE); 6467c478bd9Sstevel@tonic-gate 6477c478bd9Sstevel@tonic-gate if (r_no < 0 || r_no >= reglen / sizeof (pci_regspec_t)) { 6487c478bd9Sstevel@tonic-gate kmem_free(rp, reglen); 6497c478bd9Sstevel@tonic-gate return (DDI_ME_RNUMBER_RANGE); 6507c478bd9Sstevel@tonic-gate } 6517c478bd9Sstevel@tonic-gate rp += r_no; 6527c478bd9Sstevel@tonic-gate break; 6537c478bd9Sstevel@tonic-gate 6547c478bd9Sstevel@tonic-gate default: 6557c478bd9Sstevel@tonic-gate return (DDI_ME_INVAL); 6567c478bd9Sstevel@tonic-gate } 6577c478bd9Sstevel@tonic-gate DBG(DBG_MAP | DBG_CONT, dip, "\n"); 6587c478bd9Sstevel@tonic-gate 6597c478bd9Sstevel@tonic-gate if ((rp->pci_phys_hi & PCI_REG_ADDR_M) == PCI_ADDR_CONFIG) { 6607c478bd9Sstevel@tonic-gate /* 6617c478bd9Sstevel@tonic-gate * There may be a need to differentiate between PCI 6627c478bd9Sstevel@tonic-gate * and PCI-Ex devices so the following range check is 6637c478bd9Sstevel@tonic-gate * done correctly, depending on the implementation of 6647c478bd9Sstevel@tonic-gate * px_pci bridge nexus driver. 6657c478bd9Sstevel@tonic-gate */ 6667c478bd9Sstevel@tonic-gate if ((off >= PCIE_CONF_HDR_SIZE) || 6677c478bd9Sstevel@tonic-gate (len > PCIE_CONF_HDR_SIZE) || 6687c478bd9Sstevel@tonic-gate (off + len > PCIE_CONF_HDR_SIZE)) 6697c478bd9Sstevel@tonic-gate return (DDI_ME_INVAL); 6707c478bd9Sstevel@tonic-gate /* 6717c478bd9Sstevel@tonic-gate * the following function returning a DDI_FAILURE assumes 6727c478bd9Sstevel@tonic-gate * that there are no virtual config space access services 6737c478bd9Sstevel@tonic-gate * defined in this layer. Otherwise it is availed right 6747c478bd9Sstevel@tonic-gate * here and we return. 6757c478bd9Sstevel@tonic-gate */ 6767c478bd9Sstevel@tonic-gate rval = px_lib_map_vconfig(dip, mp, off, rp, addrp); 6777c478bd9Sstevel@tonic-gate if (rval == DDI_SUCCESS) 6787c478bd9Sstevel@tonic-gate goto done; 6797c478bd9Sstevel@tonic-gate } 6807c478bd9Sstevel@tonic-gate 6817c478bd9Sstevel@tonic-gate /* 6827c478bd9Sstevel@tonic-gate * No virtual config space services or we are mapping 6837c478bd9Sstevel@tonic-gate * a region of memory mapped config/IO/memory space, so proceed 6847c478bd9Sstevel@tonic-gate * to the parent. 6857c478bd9Sstevel@tonic-gate */ 6867c478bd9Sstevel@tonic-gate 6877c478bd9Sstevel@tonic-gate /* relocate within 64-bit pci space through "assigned-addresses" */ 6887c478bd9Sstevel@tonic-gate if (rval = px_reloc_reg(dip, rdip, px_p, rp)) 6897c478bd9Sstevel@tonic-gate goto done; 6907c478bd9Sstevel@tonic-gate 6917c478bd9Sstevel@tonic-gate if (len) /* adjust regspec according to mapping request */ 6927c478bd9Sstevel@tonic-gate rp->pci_size_low = len; /* MIN ? */ 6937c478bd9Sstevel@tonic-gate rp->pci_phys_low += off; 6947c478bd9Sstevel@tonic-gate 6957c478bd9Sstevel@tonic-gate /* translate relocated pci regspec into parent space through "ranges" */ 6967c478bd9Sstevel@tonic-gate if (rval = px_xlate_reg(px_p, rp, &p_regspec)) 6977c478bd9Sstevel@tonic-gate goto done; 6987c478bd9Sstevel@tonic-gate 6997c478bd9Sstevel@tonic-gate p_mapreq = *mp; /* dup the whole structure */ 7007c478bd9Sstevel@tonic-gate p_mapreq.map_type = DDI_MT_REGSPEC; 7017c478bd9Sstevel@tonic-gate p_mapreq.map_obj.rp = &p_regspec; 7024fbb58f6Sjchu px_lib_map_attr_check(&p_mapreq); 7037c478bd9Sstevel@tonic-gate rval = ddi_map(dip, &p_mapreq, 0, 0, addrp); 7047c478bd9Sstevel@tonic-gate 7057c478bd9Sstevel@tonic-gate if (rval == DDI_SUCCESS) { 7067c478bd9Sstevel@tonic-gate /* 7077c478bd9Sstevel@tonic-gate * Set-up access functions for FM access error capable drivers. 7087c478bd9Sstevel@tonic-gate */ 7097c478bd9Sstevel@tonic-gate if (DDI_FM_ACC_ERR_CAP(ddi_fm_capable(rdip)) && 7107c478bd9Sstevel@tonic-gate mp->map_handlep->ah_acc.devacc_attr_access != 7117c478bd9Sstevel@tonic-gate DDI_DEFAULT_ACC) 7127c478bd9Sstevel@tonic-gate px_fm_acc_setup(mp, rdip); 7137c478bd9Sstevel@tonic-gate } 7147c478bd9Sstevel@tonic-gate 7157c478bd9Sstevel@tonic-gate done: 7167c478bd9Sstevel@tonic-gate if (mp->map_type == DDI_MT_RNUMBER) 7177c478bd9Sstevel@tonic-gate kmem_free(rp - r_no, reglen); 7187c478bd9Sstevel@tonic-gate 7197c478bd9Sstevel@tonic-gate return (rval); 7207c478bd9Sstevel@tonic-gate } 7217c478bd9Sstevel@tonic-gate 7227c478bd9Sstevel@tonic-gate /* 7237c478bd9Sstevel@tonic-gate * bus dma map entry point 7247c478bd9Sstevel@tonic-gate * return value: 7257c478bd9Sstevel@tonic-gate * DDI_DMA_PARTIAL_MAP 1 7267c478bd9Sstevel@tonic-gate * DDI_DMA_MAPOK 0 7277c478bd9Sstevel@tonic-gate * DDI_DMA_MAPPED 0 7287c478bd9Sstevel@tonic-gate * DDI_DMA_NORESOURCES -1 7297c478bd9Sstevel@tonic-gate * DDI_DMA_NOMAPPING -2 7307c478bd9Sstevel@tonic-gate * DDI_DMA_TOOBIG -3 7317c478bd9Sstevel@tonic-gate */ 7327c478bd9Sstevel@tonic-gate int 7337c478bd9Sstevel@tonic-gate px_dma_setup(dev_info_t *dip, dev_info_t *rdip, ddi_dma_req_t *dmareq, 7347c478bd9Sstevel@tonic-gate ddi_dma_handle_t *handlep) 7357c478bd9Sstevel@tonic-gate { 7367c478bd9Sstevel@tonic-gate px_t *px_p = DIP_TO_STATE(dip); 7377c478bd9Sstevel@tonic-gate px_mmu_t *mmu_p = px_p->px_mmu_p; 7387c478bd9Sstevel@tonic-gate ddi_dma_impl_t *mp; 7397c478bd9Sstevel@tonic-gate int ret; 7407c478bd9Sstevel@tonic-gate 7417c478bd9Sstevel@tonic-gate DBG(DBG_DMA_MAP, dip, "mapping - rdip=%s%d type=%s\n", 7427c478bd9Sstevel@tonic-gate ddi_driver_name(rdip), ddi_get_instance(rdip), 7437c478bd9Sstevel@tonic-gate handlep ? "alloc" : "advisory"); 7447c478bd9Sstevel@tonic-gate 7457c478bd9Sstevel@tonic-gate if (!(mp = px_dma_lmts2hdl(dip, rdip, mmu_p, dmareq))) 7467c478bd9Sstevel@tonic-gate return (DDI_DMA_NORESOURCES); 7477c478bd9Sstevel@tonic-gate if (mp == (ddi_dma_impl_t *)DDI_DMA_NOMAPPING) 7487c478bd9Sstevel@tonic-gate return (DDI_DMA_NOMAPPING); 7497c478bd9Sstevel@tonic-gate if (ret = px_dma_type(px_p, dmareq, mp)) 7507c478bd9Sstevel@tonic-gate goto freehandle; 7517c478bd9Sstevel@tonic-gate if (ret = px_dma_pfn(px_p, dmareq, mp)) 7527c478bd9Sstevel@tonic-gate goto freehandle; 7537c478bd9Sstevel@tonic-gate 7547c478bd9Sstevel@tonic-gate switch (PX_DMA_TYPE(mp)) { 75536fe4a92Segillett case PX_DMAI_FLAGS_DVMA: /* LINTED E_EQUALITY_NOT_ASSIGNMENT */ 7567c478bd9Sstevel@tonic-gate if ((ret = px_dvma_win(px_p, dmareq, mp)) || !handlep) 7577c478bd9Sstevel@tonic-gate goto freehandle; 7587c478bd9Sstevel@tonic-gate if (!PX_DMA_CANCACHE(mp)) { /* try fast track */ 7597c478bd9Sstevel@tonic-gate if (PX_DMA_CANFAST(mp)) { 7607c478bd9Sstevel@tonic-gate if (!px_dvma_map_fast(mmu_p, mp)) 7617c478bd9Sstevel@tonic-gate break; 7627c478bd9Sstevel@tonic-gate /* LINTED E_NOP_ELSE_STMT */ 7637c478bd9Sstevel@tonic-gate } else { 7647c478bd9Sstevel@tonic-gate PX_DVMA_FASTTRAK_PROF(mp); 7657c478bd9Sstevel@tonic-gate } 7667c478bd9Sstevel@tonic-gate } 7677c478bd9Sstevel@tonic-gate if (ret = px_dvma_map(mp, dmareq, mmu_p)) 7687c478bd9Sstevel@tonic-gate goto freehandle; 7697c478bd9Sstevel@tonic-gate break; 77036fe4a92Segillett case PX_DMAI_FLAGS_PTP: /* LINTED E_EQUALITY_NOT_ASSIGNMENT */ 7717c478bd9Sstevel@tonic-gate if ((ret = px_dma_physwin(px_p, dmareq, mp)) || !handlep) 7727c478bd9Sstevel@tonic-gate goto freehandle; 7737c478bd9Sstevel@tonic-gate break; 77436fe4a92Segillett case PX_DMAI_FLAGS_BYPASS: 7757c478bd9Sstevel@tonic-gate default: 7767c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "%s%d: px_dma_setup: bad dma type 0x%x", 7777c478bd9Sstevel@tonic-gate ddi_driver_name(rdip), ddi_get_instance(rdip), 7787c478bd9Sstevel@tonic-gate PX_DMA_TYPE(mp)); 7797c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 7807c478bd9Sstevel@tonic-gate } 7817c478bd9Sstevel@tonic-gate *handlep = (ddi_dma_handle_t)mp; 78236fe4a92Segillett mp->dmai_flags |= PX_DMAI_FLAGS_INUSE; 7837c478bd9Sstevel@tonic-gate px_dump_dma_handle(DBG_DMA_MAP, dip, mp); 7847c478bd9Sstevel@tonic-gate 7857c478bd9Sstevel@tonic-gate return ((mp->dmai_nwin == 1) ? DDI_DMA_MAPPED : DDI_DMA_PARTIAL_MAP); 7867c478bd9Sstevel@tonic-gate freehandle: 7877c478bd9Sstevel@tonic-gate if (ret == DDI_DMA_NORESOURCES) 7887c478bd9Sstevel@tonic-gate px_dma_freemp(mp); /* don't run_callback() */ 7897c478bd9Sstevel@tonic-gate else 7907c478bd9Sstevel@tonic-gate (void) px_dma_freehdl(dip, rdip, (ddi_dma_handle_t)mp); 7917c478bd9Sstevel@tonic-gate return (ret); 7927c478bd9Sstevel@tonic-gate } 7937c478bd9Sstevel@tonic-gate 7947c478bd9Sstevel@tonic-gate 7957c478bd9Sstevel@tonic-gate /* 7967c478bd9Sstevel@tonic-gate * bus dma alloc handle entry point: 7977c478bd9Sstevel@tonic-gate */ 7987c478bd9Sstevel@tonic-gate int 7997c478bd9Sstevel@tonic-gate px_dma_allochdl(dev_info_t *dip, dev_info_t *rdip, ddi_dma_attr_t *attrp, 8007c478bd9Sstevel@tonic-gate int (*waitfp)(caddr_t), caddr_t arg, ddi_dma_handle_t *handlep) 8017c478bd9Sstevel@tonic-gate { 8027c478bd9Sstevel@tonic-gate px_t *px_p = DIP_TO_STATE(dip); 8037c478bd9Sstevel@tonic-gate ddi_dma_impl_t *mp; 8047c478bd9Sstevel@tonic-gate int rval; 8057c478bd9Sstevel@tonic-gate 8067c478bd9Sstevel@tonic-gate DBG(DBG_DMA_ALLOCH, dip, "rdip=%s%d\n", 8077c478bd9Sstevel@tonic-gate ddi_driver_name(rdip), ddi_get_instance(rdip)); 8087c478bd9Sstevel@tonic-gate 8097c478bd9Sstevel@tonic-gate if (attrp->dma_attr_version != DMA_ATTR_V0) 8107c478bd9Sstevel@tonic-gate return (DDI_DMA_BADATTR); 8117c478bd9Sstevel@tonic-gate 8127c478bd9Sstevel@tonic-gate if (!(mp = px_dma_allocmp(dip, rdip, waitfp, arg))) 8137c478bd9Sstevel@tonic-gate return (DDI_DMA_NORESOURCES); 8147c478bd9Sstevel@tonic-gate 8157c478bd9Sstevel@tonic-gate /* 8167c478bd9Sstevel@tonic-gate * Save requestor's information 8177c478bd9Sstevel@tonic-gate */ 8187c478bd9Sstevel@tonic-gate mp->dmai_attr = *attrp; /* whole object - augmented later */ 81936fe4a92Segillett *PX_DEV_ATTR(mp) = *attrp; /* whole object - device orig attr */ 8207c478bd9Sstevel@tonic-gate DBG(DBG_DMA_ALLOCH, dip, "mp=%p\n", mp); 8217c478bd9Sstevel@tonic-gate 8227c478bd9Sstevel@tonic-gate /* check and convert dma attributes to handle parameters */ 8237c478bd9Sstevel@tonic-gate if (rval = px_dma_attr2hdl(px_p, mp)) { 8247c478bd9Sstevel@tonic-gate px_dma_freehdl(dip, rdip, (ddi_dma_handle_t)mp); 8257c478bd9Sstevel@tonic-gate *handlep = NULL; 8267c478bd9Sstevel@tonic-gate return (rval); 8277c478bd9Sstevel@tonic-gate } 8287c478bd9Sstevel@tonic-gate *handlep = (ddi_dma_handle_t)mp; 8297c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 8307c478bd9Sstevel@tonic-gate } 8317c478bd9Sstevel@tonic-gate 8327c478bd9Sstevel@tonic-gate 8337c478bd9Sstevel@tonic-gate /* 8347c478bd9Sstevel@tonic-gate * bus dma free handle entry point: 8357c478bd9Sstevel@tonic-gate */ 8367c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 8377c478bd9Sstevel@tonic-gate int 8387c478bd9Sstevel@tonic-gate px_dma_freehdl(dev_info_t *dip, dev_info_t *rdip, ddi_dma_handle_t handle) 8397c478bd9Sstevel@tonic-gate { 8407c478bd9Sstevel@tonic-gate DBG(DBG_DMA_FREEH, dip, "rdip=%s%d mp=%p\n", 8417c478bd9Sstevel@tonic-gate ddi_driver_name(rdip), ddi_get_instance(rdip), handle); 8427c478bd9Sstevel@tonic-gate px_dma_freemp((ddi_dma_impl_t *)handle); 8437c478bd9Sstevel@tonic-gate 8447c478bd9Sstevel@tonic-gate if (px_kmem_clid) { 8457c478bd9Sstevel@tonic-gate DBG(DBG_DMA_FREEH, dip, "run handle callback\n"); 8467c478bd9Sstevel@tonic-gate ddi_run_callback(&px_kmem_clid); 8477c478bd9Sstevel@tonic-gate } 8487c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 8497c478bd9Sstevel@tonic-gate } 8507c478bd9Sstevel@tonic-gate 8517c478bd9Sstevel@tonic-gate 8527c478bd9Sstevel@tonic-gate /* 8537c478bd9Sstevel@tonic-gate * bus dma bind handle entry point: 8547c478bd9Sstevel@tonic-gate */ 8557c478bd9Sstevel@tonic-gate int 8567c478bd9Sstevel@tonic-gate px_dma_bindhdl(dev_info_t *dip, dev_info_t *rdip, 8577c478bd9Sstevel@tonic-gate ddi_dma_handle_t handle, ddi_dma_req_t *dmareq, 8587c478bd9Sstevel@tonic-gate ddi_dma_cookie_t *cookiep, uint_t *ccountp) 8597c478bd9Sstevel@tonic-gate { 8607c478bd9Sstevel@tonic-gate px_t *px_p = DIP_TO_STATE(dip); 8617c478bd9Sstevel@tonic-gate px_mmu_t *mmu_p = px_p->px_mmu_p; 8627c478bd9Sstevel@tonic-gate ddi_dma_impl_t *mp = (ddi_dma_impl_t *)handle; 8637c478bd9Sstevel@tonic-gate int ret; 8647c478bd9Sstevel@tonic-gate 8657c478bd9Sstevel@tonic-gate DBG(DBG_DMA_BINDH, dip, "rdip=%s%d mp=%p dmareq=%p\n", 8667c478bd9Sstevel@tonic-gate ddi_driver_name(rdip), ddi_get_instance(rdip), mp, dmareq); 8677c478bd9Sstevel@tonic-gate 86836fe4a92Segillett if (mp->dmai_flags & PX_DMAI_FLAGS_INUSE) 8697c478bd9Sstevel@tonic-gate return (DDI_DMA_INUSE); 8707c478bd9Sstevel@tonic-gate 87136fe4a92Segillett ASSERT((mp->dmai_flags & ~PX_DMAI_FLAGS_PRESERVE) == 0); 87236fe4a92Segillett mp->dmai_flags |= PX_DMAI_FLAGS_INUSE; 8737c478bd9Sstevel@tonic-gate 8747c478bd9Sstevel@tonic-gate if (ret = px_dma_type(px_p, dmareq, mp)) 8757c478bd9Sstevel@tonic-gate goto err; 8767c478bd9Sstevel@tonic-gate if (ret = px_dma_pfn(px_p, dmareq, mp)) 8777c478bd9Sstevel@tonic-gate goto err; 8787c478bd9Sstevel@tonic-gate 8797c478bd9Sstevel@tonic-gate switch (PX_DMA_TYPE(mp)) { 88036fe4a92Segillett case PX_DMAI_FLAGS_DVMA: 8817c478bd9Sstevel@tonic-gate if (ret = px_dvma_win(px_p, dmareq, mp)) 8827c478bd9Sstevel@tonic-gate goto map_err; 8837c478bd9Sstevel@tonic-gate if (!PX_DMA_CANCACHE(mp)) { /* try fast track */ 8847c478bd9Sstevel@tonic-gate if (PX_DMA_CANFAST(mp)) { 8857c478bd9Sstevel@tonic-gate if (!px_dvma_map_fast(mmu_p, mp)) 8867c478bd9Sstevel@tonic-gate goto mapped; /*LINTED E_NOP_ELSE_STMT*/ 8877c478bd9Sstevel@tonic-gate } else { 8887c478bd9Sstevel@tonic-gate PX_DVMA_FASTTRAK_PROF(mp); 8897c478bd9Sstevel@tonic-gate } 8907c478bd9Sstevel@tonic-gate } 8917c478bd9Sstevel@tonic-gate if (ret = px_dvma_map(mp, dmareq, mmu_p)) 8927c478bd9Sstevel@tonic-gate goto map_err; 8937c478bd9Sstevel@tonic-gate mapped: 8947c478bd9Sstevel@tonic-gate *ccountp = 1; 8957c478bd9Sstevel@tonic-gate MAKE_DMA_COOKIE(cookiep, mp->dmai_mapping, mp->dmai_size); 8967c478bd9Sstevel@tonic-gate break; 89736fe4a92Segillett case PX_DMAI_FLAGS_BYPASS: 89836fe4a92Segillett case PX_DMAI_FLAGS_PTP: 8997c478bd9Sstevel@tonic-gate if (ret = px_dma_physwin(px_p, dmareq, mp)) 9007c478bd9Sstevel@tonic-gate goto map_err; 90136fe4a92Segillett *ccountp = PX_WINLST(mp)->win_ncookies; 90236fe4a92Segillett *cookiep = 90336fe4a92Segillett *(ddi_dma_cookie_t *)(PX_WINLST(mp) + 1); /* wholeobj */ 9047c478bd9Sstevel@tonic-gate break; 9057c478bd9Sstevel@tonic-gate default: 9067c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "%s%d: px_dma_bindhdl(%p): bad dma type", 9077c478bd9Sstevel@tonic-gate ddi_driver_name(rdip), ddi_get_instance(rdip), mp); 9087c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 9097c478bd9Sstevel@tonic-gate } 91069cd775fSschwartz DBG(DBG_DMA_BINDH, dip, "cookie %" PRIx64 "+%x\n", 91169cd775fSschwartz cookiep->dmac_address, cookiep->dmac_size); 9127c478bd9Sstevel@tonic-gate px_dump_dma_handle(DBG_DMA_MAP, dip, mp); 913f8d2de6bSjchu 914f8d2de6bSjchu /* insert dma handle into FMA cache */ 915f8d2de6bSjchu if (mp->dmai_attr.dma_attr_flags & DDI_DMA_FLAGERR) 916f8d2de6bSjchu (void) ndi_fmc_insert(rdip, DMA_HANDLE, mp, NULL); 917f8d2de6bSjchu 9187c478bd9Sstevel@tonic-gate return (mp->dmai_nwin == 1 ? DDI_DMA_MAPPED : DDI_DMA_PARTIAL_MAP); 9197c478bd9Sstevel@tonic-gate map_err: 9207c478bd9Sstevel@tonic-gate px_dma_freepfn(mp); 9217c478bd9Sstevel@tonic-gate err: 92236fe4a92Segillett mp->dmai_flags &= PX_DMAI_FLAGS_PRESERVE; 9237c478bd9Sstevel@tonic-gate return (ret); 9247c478bd9Sstevel@tonic-gate } 9257c478bd9Sstevel@tonic-gate 9267c478bd9Sstevel@tonic-gate 9277c478bd9Sstevel@tonic-gate /* 9287c478bd9Sstevel@tonic-gate * bus dma unbind handle entry point: 9297c478bd9Sstevel@tonic-gate */ 9307c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 9317c478bd9Sstevel@tonic-gate int 9327c478bd9Sstevel@tonic-gate px_dma_unbindhdl(dev_info_t *dip, dev_info_t *rdip, ddi_dma_handle_t handle) 9337c478bd9Sstevel@tonic-gate { 9347c478bd9Sstevel@tonic-gate ddi_dma_impl_t *mp = (ddi_dma_impl_t *)handle; 9357c478bd9Sstevel@tonic-gate px_t *px_p = DIP_TO_STATE(dip); 9367c478bd9Sstevel@tonic-gate px_mmu_t *mmu_p = px_p->px_mmu_p; 9377c478bd9Sstevel@tonic-gate 9387c478bd9Sstevel@tonic-gate DBG(DBG_DMA_UNBINDH, dip, "rdip=%s%d, mp=%p\n", 9397c478bd9Sstevel@tonic-gate ddi_driver_name(rdip), ddi_get_instance(rdip), handle); 94036fe4a92Segillett if ((mp->dmai_flags & PX_DMAI_FLAGS_INUSE) == 0) { 9417c478bd9Sstevel@tonic-gate DBG(DBG_DMA_UNBINDH, dip, "handle not inuse\n"); 9427c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 9437c478bd9Sstevel@tonic-gate } 9447c478bd9Sstevel@tonic-gate 945f8d2de6bSjchu /* remove dma handle from FMA cache */ 946f8d2de6bSjchu if (mp->dmai_attr.dma_attr_flags & DDI_DMA_FLAGERR) { 947f8d2de6bSjchu if (DEVI(rdip)->devi_fmhdl != NULL && 948f8d2de6bSjchu DDI_FM_DMA_ERR_CAP(DEVI(rdip)->devi_fmhdl->fh_cap)) { 949f8d2de6bSjchu (void) ndi_fmc_remove(rdip, DMA_HANDLE, mp); 950f8d2de6bSjchu } 951f8d2de6bSjchu } 952f8d2de6bSjchu 9537c478bd9Sstevel@tonic-gate /* 9547c478bd9Sstevel@tonic-gate * Here if the handle is using the iommu. Unload all the iommu 9557c478bd9Sstevel@tonic-gate * translations. 9567c478bd9Sstevel@tonic-gate */ 9577c478bd9Sstevel@tonic-gate switch (PX_DMA_TYPE(mp)) { 95836fe4a92Segillett case PX_DMAI_FLAGS_DVMA: 9597c478bd9Sstevel@tonic-gate px_mmu_unmap_window(mmu_p, mp); 9607c478bd9Sstevel@tonic-gate px_dvma_unmap(mmu_p, mp); 9617c478bd9Sstevel@tonic-gate px_dma_freepfn(mp); 9627c478bd9Sstevel@tonic-gate break; 96336fe4a92Segillett case PX_DMAI_FLAGS_BYPASS: 96436fe4a92Segillett case PX_DMAI_FLAGS_PTP: 9657c478bd9Sstevel@tonic-gate px_dma_freewin(mp); 9667c478bd9Sstevel@tonic-gate break; 9677c478bd9Sstevel@tonic-gate default: 9687c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "%s%d: px_dma_unbindhdl:bad dma type %p", 9697c478bd9Sstevel@tonic-gate ddi_driver_name(rdip), ddi_get_instance(rdip), mp); 9707c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 9717c478bd9Sstevel@tonic-gate } 9727c478bd9Sstevel@tonic-gate if (mmu_p->mmu_dvma_clid != 0) { 9737c478bd9Sstevel@tonic-gate DBG(DBG_DMA_UNBINDH, dip, "run dvma callback\n"); 9747c478bd9Sstevel@tonic-gate ddi_run_callback(&mmu_p->mmu_dvma_clid); 9757c478bd9Sstevel@tonic-gate } 9767c478bd9Sstevel@tonic-gate if (px_kmem_clid) { 9777c478bd9Sstevel@tonic-gate DBG(DBG_DMA_UNBINDH, dip, "run handle callback\n"); 9787c478bd9Sstevel@tonic-gate ddi_run_callback(&px_kmem_clid); 9797c478bd9Sstevel@tonic-gate } 98036fe4a92Segillett mp->dmai_flags &= PX_DMAI_FLAGS_PRESERVE; 981f8d2de6bSjchu 9827c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 9837c478bd9Sstevel@tonic-gate } 9847c478bd9Sstevel@tonic-gate 9857c478bd9Sstevel@tonic-gate /* 9867c478bd9Sstevel@tonic-gate * bus dma win entry point: 9877c478bd9Sstevel@tonic-gate */ 9887c478bd9Sstevel@tonic-gate int 9897c478bd9Sstevel@tonic-gate px_dma_win(dev_info_t *dip, dev_info_t *rdip, 9907c478bd9Sstevel@tonic-gate ddi_dma_handle_t handle, uint_t win, off_t *offp, 9917c478bd9Sstevel@tonic-gate size_t *lenp, ddi_dma_cookie_t *cookiep, uint_t *ccountp) 9927c478bd9Sstevel@tonic-gate { 9937c478bd9Sstevel@tonic-gate ddi_dma_impl_t *mp = (ddi_dma_impl_t *)handle; 9947c478bd9Sstevel@tonic-gate int ret; 9957c478bd9Sstevel@tonic-gate 9967c478bd9Sstevel@tonic-gate DBG(DBG_DMA_WIN, dip, "rdip=%s%d\n", 9977c478bd9Sstevel@tonic-gate ddi_driver_name(rdip), ddi_get_instance(rdip)); 9987c478bd9Sstevel@tonic-gate 9997c478bd9Sstevel@tonic-gate px_dump_dma_handle(DBG_DMA_WIN, dip, mp); 10007c478bd9Sstevel@tonic-gate if (win >= mp->dmai_nwin) { 10017c478bd9Sstevel@tonic-gate DBG(DBG_DMA_WIN, dip, "%x out of range\n", win); 10027c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 10037c478bd9Sstevel@tonic-gate } 10047c478bd9Sstevel@tonic-gate 10057c478bd9Sstevel@tonic-gate switch (PX_DMA_TYPE(mp)) { 100636fe4a92Segillett case PX_DMAI_FLAGS_DVMA: 10077c478bd9Sstevel@tonic-gate if (win != PX_DMA_CURWIN(mp)) { 10087c478bd9Sstevel@tonic-gate px_t *px_p = DIP_TO_STATE(dip); 10097c478bd9Sstevel@tonic-gate px_mmu_t *mmu_p = px_p->px_mmu_p; 10107c478bd9Sstevel@tonic-gate px_mmu_unmap_window(mmu_p, mp); 10117c478bd9Sstevel@tonic-gate 10127c478bd9Sstevel@tonic-gate /* map_window sets dmai_mapping/size/offset */ 10137c478bd9Sstevel@tonic-gate px_mmu_map_window(mmu_p, mp, win); 10147c478bd9Sstevel@tonic-gate if ((ret = px_mmu_map_window(mmu_p, 10157c478bd9Sstevel@tonic-gate mp, win)) != DDI_SUCCESS) 10167c478bd9Sstevel@tonic-gate return (ret); 10177c478bd9Sstevel@tonic-gate } 10187c478bd9Sstevel@tonic-gate if (cookiep) 10197c478bd9Sstevel@tonic-gate MAKE_DMA_COOKIE(cookiep, mp->dmai_mapping, 10207c478bd9Sstevel@tonic-gate mp->dmai_size); 10217c478bd9Sstevel@tonic-gate if (ccountp) 10227c478bd9Sstevel@tonic-gate *ccountp = 1; 10237c478bd9Sstevel@tonic-gate break; 102436fe4a92Segillett case PX_DMAI_FLAGS_PTP: 102536fe4a92Segillett case PX_DMAI_FLAGS_BYPASS: { 10267c478bd9Sstevel@tonic-gate int i; 10277c478bd9Sstevel@tonic-gate ddi_dma_cookie_t *ck_p; 10287c478bd9Sstevel@tonic-gate px_dma_win_t *win_p = mp->dmai_winlst; 10297c478bd9Sstevel@tonic-gate 10307c478bd9Sstevel@tonic-gate for (i = 0; i < win; win_p = win_p->win_next, i++); 10317c478bd9Sstevel@tonic-gate ck_p = (ddi_dma_cookie_t *)(win_p + 1); 10327c478bd9Sstevel@tonic-gate *cookiep = *ck_p; 10337c478bd9Sstevel@tonic-gate mp->dmai_offset = win_p->win_offset; 10347c478bd9Sstevel@tonic-gate mp->dmai_size = win_p->win_size; 10357c478bd9Sstevel@tonic-gate mp->dmai_mapping = ck_p->dmac_laddress; 10367c478bd9Sstevel@tonic-gate mp->dmai_cookie = ck_p + 1; 10377c478bd9Sstevel@tonic-gate win_p->win_curseg = 0; 10387c478bd9Sstevel@tonic-gate if (ccountp) 10397c478bd9Sstevel@tonic-gate *ccountp = win_p->win_ncookies; 10407c478bd9Sstevel@tonic-gate } 10417c478bd9Sstevel@tonic-gate break; 10427c478bd9Sstevel@tonic-gate default: 10437c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d: px_dma_win:bad dma type 0x%x", 10447c478bd9Sstevel@tonic-gate ddi_driver_name(rdip), ddi_get_instance(rdip), 10457c478bd9Sstevel@tonic-gate PX_DMA_TYPE(mp)); 10467c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 10477c478bd9Sstevel@tonic-gate } 10487c478bd9Sstevel@tonic-gate if (cookiep) 10497c478bd9Sstevel@tonic-gate DBG(DBG_DMA_WIN, dip, 10507c478bd9Sstevel@tonic-gate "cookie - dmac_address=%x dmac_size=%x\n", 10517c478bd9Sstevel@tonic-gate cookiep->dmac_address, cookiep->dmac_size); 10527c478bd9Sstevel@tonic-gate if (offp) 10537c478bd9Sstevel@tonic-gate *offp = (off_t)mp->dmai_offset; 10547c478bd9Sstevel@tonic-gate if (lenp) 10557c478bd9Sstevel@tonic-gate *lenp = mp->dmai_size; 10567c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 10577c478bd9Sstevel@tonic-gate } 10587c478bd9Sstevel@tonic-gate 10597c478bd9Sstevel@tonic-gate #ifdef DEBUG 10607c478bd9Sstevel@tonic-gate static char *px_dmactl_str[] = { 10617c478bd9Sstevel@tonic-gate "DDI_DMA_FREE", 10627c478bd9Sstevel@tonic-gate "DDI_DMA_SYNC", 10637c478bd9Sstevel@tonic-gate "DDI_DMA_HTOC", 10647c478bd9Sstevel@tonic-gate "DDI_DMA_KVADDR", 10657c478bd9Sstevel@tonic-gate "DDI_DMA_MOVWIN", 10667c478bd9Sstevel@tonic-gate "DDI_DMA_REPWIN", 10677c478bd9Sstevel@tonic-gate "DDI_DMA_GETERR", 10687c478bd9Sstevel@tonic-gate "DDI_DMA_COFF", 10697c478bd9Sstevel@tonic-gate "DDI_DMA_NEXTWIN", 10707c478bd9Sstevel@tonic-gate "DDI_DMA_NEXTSEG", 10717c478bd9Sstevel@tonic-gate "DDI_DMA_SEGTOC", 10727c478bd9Sstevel@tonic-gate "DDI_DMA_RESERVE", 10737c478bd9Sstevel@tonic-gate "DDI_DMA_RELEASE", 10747c478bd9Sstevel@tonic-gate "DDI_DMA_RESETH", 10757c478bd9Sstevel@tonic-gate "DDI_DMA_CKSYNC", 10767c478bd9Sstevel@tonic-gate "DDI_DMA_IOPB_ALLOC", 10777c478bd9Sstevel@tonic-gate "DDI_DMA_IOPB_FREE", 10787c478bd9Sstevel@tonic-gate "DDI_DMA_SMEM_ALLOC", 10797c478bd9Sstevel@tonic-gate "DDI_DMA_SMEM_FREE", 10807c478bd9Sstevel@tonic-gate "DDI_DMA_SET_SBUS64" 10817c478bd9Sstevel@tonic-gate }; 10827c478bd9Sstevel@tonic-gate #endif /* DEBUG */ 10837c478bd9Sstevel@tonic-gate 10847c478bd9Sstevel@tonic-gate /* 10857c478bd9Sstevel@tonic-gate * bus dma control entry point: 10867c478bd9Sstevel@tonic-gate */ 10877c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 10887c478bd9Sstevel@tonic-gate int 10897c478bd9Sstevel@tonic-gate px_dma_ctlops(dev_info_t *dip, dev_info_t *rdip, ddi_dma_handle_t handle, 10907c478bd9Sstevel@tonic-gate enum ddi_dma_ctlops cmd, off_t *offp, size_t *lenp, caddr_t *objp, 10917c478bd9Sstevel@tonic-gate uint_t cache_flags) 10927c478bd9Sstevel@tonic-gate { 10937c478bd9Sstevel@tonic-gate ddi_dma_impl_t *mp = (ddi_dma_impl_t *)handle; 10947c478bd9Sstevel@tonic-gate 10957c478bd9Sstevel@tonic-gate #ifdef DEBUG 10967c478bd9Sstevel@tonic-gate DBG(DBG_DMA_CTL, dip, "%s: rdip=%s%d\n", px_dmactl_str[cmd], 10977c478bd9Sstevel@tonic-gate ddi_driver_name(rdip), ddi_get_instance(rdip)); 10987c478bd9Sstevel@tonic-gate #endif /* DEBUG */ 10997c478bd9Sstevel@tonic-gate 11007c478bd9Sstevel@tonic-gate switch (cmd) { 11017c478bd9Sstevel@tonic-gate case DDI_DMA_FREE: 11027c478bd9Sstevel@tonic-gate (void) px_dma_unbindhdl(dip, rdip, handle); 11037c478bd9Sstevel@tonic-gate (void) px_dma_freehdl(dip, rdip, handle); 11047c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 11057c478bd9Sstevel@tonic-gate case DDI_DMA_RESERVE: { 11067c478bd9Sstevel@tonic-gate px_t *px_p = DIP_TO_STATE(dip); 11077c478bd9Sstevel@tonic-gate return (px_fdvma_reserve(dip, rdip, px_p, 11087c478bd9Sstevel@tonic-gate (ddi_dma_req_t *)offp, (ddi_dma_handle_t *)objp)); 11097c478bd9Sstevel@tonic-gate } 11107c478bd9Sstevel@tonic-gate case DDI_DMA_RELEASE: { 11117c478bd9Sstevel@tonic-gate px_t *px_p = DIP_TO_STATE(dip); 11127c478bd9Sstevel@tonic-gate return (px_fdvma_release(dip, px_p, mp)); 11137c478bd9Sstevel@tonic-gate } 11147c478bd9Sstevel@tonic-gate default: 11157c478bd9Sstevel@tonic-gate break; 11167c478bd9Sstevel@tonic-gate } 11177c478bd9Sstevel@tonic-gate 11187c478bd9Sstevel@tonic-gate switch (PX_DMA_TYPE(mp)) { 111936fe4a92Segillett case PX_DMAI_FLAGS_DVMA: 11207c478bd9Sstevel@tonic-gate return (px_dvma_ctl(dip, rdip, mp, cmd, offp, lenp, objp, 11217c478bd9Sstevel@tonic-gate cache_flags)); 112236fe4a92Segillett case PX_DMAI_FLAGS_PTP: 112336fe4a92Segillett case PX_DMAI_FLAGS_BYPASS: 11247c478bd9Sstevel@tonic-gate return (px_dma_ctl(dip, rdip, mp, cmd, offp, lenp, objp, 11257c478bd9Sstevel@tonic-gate cache_flags)); 11267c478bd9Sstevel@tonic-gate default: 11277c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "%s%d: px_dma_ctlops(%x):bad dma type %x", 11287c478bd9Sstevel@tonic-gate ddi_driver_name(rdip), ddi_get_instance(rdip), cmd, 11297c478bd9Sstevel@tonic-gate mp->dmai_flags); 11307c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 11317c478bd9Sstevel@tonic-gate } 1132b40cec45Skrishnae return (0); 11337c478bd9Sstevel@tonic-gate } 11347c478bd9Sstevel@tonic-gate 11357c478bd9Sstevel@tonic-gate /* 11367c478bd9Sstevel@tonic-gate * control ops entry point: 11377c478bd9Sstevel@tonic-gate * 11387c478bd9Sstevel@tonic-gate * Requests handled completely: 11397c478bd9Sstevel@tonic-gate * DDI_CTLOPS_INITCHILD see init_child() for details 11407c478bd9Sstevel@tonic-gate * DDI_CTLOPS_UNINITCHILD 11417c478bd9Sstevel@tonic-gate * DDI_CTLOPS_REPORTDEV see report_dev() for details 11427c478bd9Sstevel@tonic-gate * DDI_CTLOPS_IOMIN cache line size if streaming otherwise 1 11437c478bd9Sstevel@tonic-gate * DDI_CTLOPS_REGSIZE 11447c478bd9Sstevel@tonic-gate * DDI_CTLOPS_NREGS 11457c478bd9Sstevel@tonic-gate * DDI_CTLOPS_DVMAPAGESIZE 11467c478bd9Sstevel@tonic-gate * DDI_CTLOPS_POKE 11477c478bd9Sstevel@tonic-gate * DDI_CTLOPS_PEEK 11487c478bd9Sstevel@tonic-gate * 11497c478bd9Sstevel@tonic-gate * All others passed to parent. 11507c478bd9Sstevel@tonic-gate */ 11517c478bd9Sstevel@tonic-gate int 11527c478bd9Sstevel@tonic-gate px_ctlops(dev_info_t *dip, dev_info_t *rdip, 11537c478bd9Sstevel@tonic-gate ddi_ctl_enum_t op, void *arg, void *result) 11547c478bd9Sstevel@tonic-gate { 11557c478bd9Sstevel@tonic-gate px_t *px_p = DIP_TO_STATE(dip); 11567c478bd9Sstevel@tonic-gate struct detachspec *ds; 11577c478bd9Sstevel@tonic-gate struct attachspec *as; 11587c478bd9Sstevel@tonic-gate 11597c478bd9Sstevel@tonic-gate switch (op) { 11607c478bd9Sstevel@tonic-gate case DDI_CTLOPS_INITCHILD: 11617c478bd9Sstevel@tonic-gate return (px_init_child(px_p, (dev_info_t *)arg)); 11627c478bd9Sstevel@tonic-gate 11637c478bd9Sstevel@tonic-gate case DDI_CTLOPS_UNINITCHILD: 11647c478bd9Sstevel@tonic-gate return (px_uninit_child(px_p, (dev_info_t *)arg)); 11657c478bd9Sstevel@tonic-gate 11667c478bd9Sstevel@tonic-gate case DDI_CTLOPS_ATTACH: 11677c478bd9Sstevel@tonic-gate as = (struct attachspec *)arg; 11687c478bd9Sstevel@tonic-gate switch (as->when) { 11697c478bd9Sstevel@tonic-gate case DDI_PRE: 11707c478bd9Sstevel@tonic-gate if (as->cmd == DDI_ATTACH) { 11717c478bd9Sstevel@tonic-gate DBG(DBG_PWR, dip, "PRE_ATTACH for %s@%d\n", 11727c478bd9Sstevel@tonic-gate ddi_driver_name(rdip), 11737c478bd9Sstevel@tonic-gate ddi_get_instance(rdip)); 11747c478bd9Sstevel@tonic-gate return (pcie_pm_hold(dip)); 11757c478bd9Sstevel@tonic-gate } 11768bc7d88aSet142600 if (as->cmd == DDI_RESUME) { 11778bc7d88aSet142600 ddi_acc_handle_t config_handle; 11788bc7d88aSet142600 DBG(DBG_PWR, dip, "PRE_RESUME for %s@%d\n", 11798bc7d88aSet142600 ddi_driver_name(rdip), 11808bc7d88aSet142600 ddi_get_instance(rdip)); 11818bc7d88aSet142600 11828bc7d88aSet142600 if (pci_config_setup(rdip, &config_handle) == 11838bc7d88aSet142600 DDI_SUCCESS) { 11848bc7d88aSet142600 pcie_clear_errors(rdip, config_handle); 11858bc7d88aSet142600 pci_config_teardown(&config_handle); 11868bc7d88aSet142600 } 11878bc7d88aSet142600 } 11887c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 11897c478bd9Sstevel@tonic-gate 11907c478bd9Sstevel@tonic-gate case DDI_POST: 11917c478bd9Sstevel@tonic-gate DBG(DBG_PWR, dip, "POST_ATTACH for %s@%d\n", 11927c478bd9Sstevel@tonic-gate ddi_driver_name(rdip), ddi_get_instance(rdip)); 11937c478bd9Sstevel@tonic-gate if (as->cmd == DDI_ATTACH && as->result != DDI_SUCCESS) 11947c478bd9Sstevel@tonic-gate pcie_pm_release(dip); 11957c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 11967c478bd9Sstevel@tonic-gate default: 11977c478bd9Sstevel@tonic-gate break; 11987c478bd9Sstevel@tonic-gate } 11997c478bd9Sstevel@tonic-gate break; 12007c478bd9Sstevel@tonic-gate 12017c478bd9Sstevel@tonic-gate case DDI_CTLOPS_DETACH: 12027c478bd9Sstevel@tonic-gate ds = (struct detachspec *)arg; 12037c478bd9Sstevel@tonic-gate switch (ds->when) { 12047c478bd9Sstevel@tonic-gate case DDI_POST: 12057c478bd9Sstevel@tonic-gate if (ds->cmd == DDI_DETACH && 12067c478bd9Sstevel@tonic-gate ds->result == DDI_SUCCESS) { 12077c478bd9Sstevel@tonic-gate DBG(DBG_PWR, dip, "POST_DETACH for %s@%d\n", 12087c478bd9Sstevel@tonic-gate ddi_driver_name(rdip), 12097c478bd9Sstevel@tonic-gate ddi_get_instance(rdip)); 12107c478bd9Sstevel@tonic-gate return (pcie_pm_remove_child(dip, rdip)); 12117c478bd9Sstevel@tonic-gate } 12127c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 12137c478bd9Sstevel@tonic-gate default: 12147c478bd9Sstevel@tonic-gate break; 12157c478bd9Sstevel@tonic-gate } 12167c478bd9Sstevel@tonic-gate break; 12177c478bd9Sstevel@tonic-gate 12187c478bd9Sstevel@tonic-gate case DDI_CTLOPS_REPORTDEV: 12197c478bd9Sstevel@tonic-gate return (px_report_dev(rdip)); 12207c478bd9Sstevel@tonic-gate 12217c478bd9Sstevel@tonic-gate case DDI_CTLOPS_IOMIN: 12227c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 12237c478bd9Sstevel@tonic-gate 12247c478bd9Sstevel@tonic-gate case DDI_CTLOPS_REGSIZE: 12257c478bd9Sstevel@tonic-gate *((off_t *)result) = px_get_reg_set_size(rdip, *((int *)arg)); 1226f8d2de6bSjchu return (*((off_t *)result) == 0 ? DDI_FAILURE : DDI_SUCCESS); 12277c478bd9Sstevel@tonic-gate 12287c478bd9Sstevel@tonic-gate case DDI_CTLOPS_NREGS: 12297c478bd9Sstevel@tonic-gate *((uint_t *)result) = px_get_nreg_set(rdip); 12307c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 12317c478bd9Sstevel@tonic-gate 12327c478bd9Sstevel@tonic-gate case DDI_CTLOPS_DVMAPAGESIZE: 12337c478bd9Sstevel@tonic-gate *((ulong_t *)result) = MMU_PAGE_SIZE; 12347c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 12357c478bd9Sstevel@tonic-gate 12367c478bd9Sstevel@tonic-gate case DDI_CTLOPS_POKE: /* platform dependent implementation. */ 12377c478bd9Sstevel@tonic-gate return (px_lib_ctlops_poke(dip, rdip, 12387c478bd9Sstevel@tonic-gate (peekpoke_ctlops_t *)arg)); 12397c478bd9Sstevel@tonic-gate 12407c478bd9Sstevel@tonic-gate case DDI_CTLOPS_PEEK: /* platform dependent implementation. */ 12417c478bd9Sstevel@tonic-gate return (px_lib_ctlops_peek(dip, rdip, 12427c478bd9Sstevel@tonic-gate (peekpoke_ctlops_t *)arg, result)); 12437c478bd9Sstevel@tonic-gate 12447c478bd9Sstevel@tonic-gate case DDI_CTLOPS_POWER: 12457c478bd9Sstevel@tonic-gate default: 12467c478bd9Sstevel@tonic-gate break; 12477c478bd9Sstevel@tonic-gate } 12487c478bd9Sstevel@tonic-gate 12497c478bd9Sstevel@tonic-gate /* 12507c478bd9Sstevel@tonic-gate * Now pass the request up to our parent. 12517c478bd9Sstevel@tonic-gate */ 12527c478bd9Sstevel@tonic-gate DBG(DBG_CTLOPS, dip, "passing request to parent: rdip=%s%d\n", 12537c478bd9Sstevel@tonic-gate ddi_driver_name(rdip), ddi_get_instance(rdip)); 12547c478bd9Sstevel@tonic-gate return (ddi_ctlops(dip, rdip, op, arg, result)); 12557c478bd9Sstevel@tonic-gate } 12567c478bd9Sstevel@tonic-gate 12577c478bd9Sstevel@tonic-gate /* ARGSUSED */ 12587c478bd9Sstevel@tonic-gate int 12597c478bd9Sstevel@tonic-gate px_intr_ops(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t intr_op, 12607c478bd9Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp, void *result) 12617c478bd9Sstevel@tonic-gate { 12627c478bd9Sstevel@tonic-gate int intr_types, ret = DDI_SUCCESS; 12637c478bd9Sstevel@tonic-gate 12647c478bd9Sstevel@tonic-gate DBG(DBG_INTROPS, dip, "px_intr_ops: rdip=%s%d\n", 12657c478bd9Sstevel@tonic-gate ddi_driver_name(rdip), ddi_get_instance(rdip)); 12667c478bd9Sstevel@tonic-gate 12677c478bd9Sstevel@tonic-gate /* Process DDI_INTROP_SUPPORTED_TYPES request here */ 12687c478bd9Sstevel@tonic-gate if (intr_op == DDI_INTROP_SUPPORTED_TYPES) { 12697c478bd9Sstevel@tonic-gate *(int *)result = i_ddi_get_nintrs(rdip) ? 12707c478bd9Sstevel@tonic-gate DDI_INTR_TYPE_FIXED : 0; 12717c478bd9Sstevel@tonic-gate 12727c478bd9Sstevel@tonic-gate if ((pci_msi_get_supported_type(rdip, 12737c478bd9Sstevel@tonic-gate &intr_types)) == DDI_SUCCESS) { 12747c478bd9Sstevel@tonic-gate /* 12757c478bd9Sstevel@tonic-gate * Double check supported interrupt types vs. 12767c478bd9Sstevel@tonic-gate * what the host bridge supports. 12779c75c6bfSgovinda * 12789c75c6bfSgovinda * NOTE: 12799c75c6bfSgovinda * Currently MSI-X is disabled since px driver 12809c75c6bfSgovinda * don't fully support this feature. 12817c478bd9Sstevel@tonic-gate */ 12829c75c6bfSgovinda *(int *)result |= (intr_types & DDI_INTR_TYPE_MSI); 12837c478bd9Sstevel@tonic-gate } 12847c478bd9Sstevel@tonic-gate 12857c478bd9Sstevel@tonic-gate return (ret); 12867c478bd9Sstevel@tonic-gate } 12877c478bd9Sstevel@tonic-gate 12887c478bd9Sstevel@tonic-gate /* 12897c478bd9Sstevel@tonic-gate * PCI-E nexus driver supports fixed, MSI and MSI-X interrupts. 12907c478bd9Sstevel@tonic-gate * Return failure if interrupt type is not supported. 12917c478bd9Sstevel@tonic-gate */ 12927c478bd9Sstevel@tonic-gate switch (hdlp->ih_type) { 12937c478bd9Sstevel@tonic-gate case DDI_INTR_TYPE_FIXED: 12947c478bd9Sstevel@tonic-gate ret = px_intx_ops(dip, rdip, intr_op, hdlp, result); 12957c478bd9Sstevel@tonic-gate break; 12967c478bd9Sstevel@tonic-gate case DDI_INTR_TYPE_MSI: 12977c478bd9Sstevel@tonic-gate case DDI_INTR_TYPE_MSIX: 12987c478bd9Sstevel@tonic-gate ret = px_msix_ops(dip, rdip, intr_op, hdlp, result); 12997c478bd9Sstevel@tonic-gate break; 13007c478bd9Sstevel@tonic-gate default: 13017c478bd9Sstevel@tonic-gate ret = DDI_ENOTSUP; 13027c478bd9Sstevel@tonic-gate break; 13037c478bd9Sstevel@tonic-gate } 13047c478bd9Sstevel@tonic-gate 13057c478bd9Sstevel@tonic-gate return (ret); 13067c478bd9Sstevel@tonic-gate } 1307