10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
51540Skini * Common Development and Distribution License (the "License").
61540Skini * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
2112341SDavid.Woods@Sun.COM
220Sstevel@tonic-gate /*
2312341SDavid.Woods@Sun.COM * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate /*
2710923SEvan.Yan@Sun.COM * SPARC Host to PCI Express nexus driver
280Sstevel@tonic-gate */
290Sstevel@tonic-gate
300Sstevel@tonic-gate #include <sys/types.h>
310Sstevel@tonic-gate #include <sys/conf.h> /* nulldev */
320Sstevel@tonic-gate #include <sys/stat.h> /* devctl */
330Sstevel@tonic-gate #include <sys/kmem.h>
340Sstevel@tonic-gate #include <sys/sunddi.h>
350Sstevel@tonic-gate #include <sys/sunndi.h>
360Sstevel@tonic-gate #include <sys/ddi_subrdefs.h>
37118Sjchu #include <sys/spl.h>
380Sstevel@tonic-gate #include <sys/epm.h>
390Sstevel@tonic-gate #include <sys/iommutsb.h>
400Sstevel@tonic-gate #include "px_obj.h"
4110923SEvan.Yan@Sun.COM #include <sys/hotplug/pci/pcie_hp.h>
42624Sschwartz #include <sys/pci_tools.h>
43777Sschwartz #include "px_tools_ext.h"
4410187SKrishna.Elango@Sun.COM #include <sys/pcie_pwr.h>
4511245SZhijun.Fu@Sun.COM #include <sys/pci_cfgacc.h>
460Sstevel@tonic-gate
470Sstevel@tonic-gate /*LINTLIBRARY*/
480Sstevel@tonic-gate
490Sstevel@tonic-gate /*
500Sstevel@tonic-gate * function prototypes for dev ops routines:
510Sstevel@tonic-gate */
520Sstevel@tonic-gate static int px_attach(dev_info_t *dip, ddi_attach_cmd_t cmd);
530Sstevel@tonic-gate static int px_detach(dev_info_t *dip, ddi_detach_cmd_t cmd);
54*12458SErwin.Tsaur@Sun.COM static int px_enable_err_intr(px_t *px_p);
55*12458SErwin.Tsaur@Sun.COM static void px_disable_err_intr(px_t *px_p);
560Sstevel@tonic-gate static int px_info(dev_info_t *dip, ddi_info_cmd_t infocmd,
570Sstevel@tonic-gate void *arg, void **result);
581648Sjchu static int px_cb_attach(px_t *);
590Sstevel@tonic-gate static int px_pwr_setup(dev_info_t *dip);
600Sstevel@tonic-gate static void px_pwr_teardown(dev_info_t *dip);
617596SAlan.Adamson@Sun.COM static void px_set_mps(px_t *px_p);
627596SAlan.Adamson@Sun.COM
6311245SZhijun.Fu@Sun.COM extern void pci_cfgacc_acc(pci_cfgacc_req_t *);
647596SAlan.Adamson@Sun.COM extern int pcie_max_mps;
6511245SZhijun.Fu@Sun.COM extern void (*pci_cfgacc_acc_p)(pci_cfgacc_req_t *);
660Sstevel@tonic-gate /*
670Sstevel@tonic-gate * bus ops and dev ops structures:
680Sstevel@tonic-gate */
690Sstevel@tonic-gate static struct bus_ops px_bus_ops = {
700Sstevel@tonic-gate BUSO_REV,
710Sstevel@tonic-gate px_map,
720Sstevel@tonic-gate 0,
730Sstevel@tonic-gate 0,
740Sstevel@tonic-gate 0,
750Sstevel@tonic-gate i_ddi_map_fault,
760Sstevel@tonic-gate px_dma_setup,
770Sstevel@tonic-gate px_dma_allochdl,
780Sstevel@tonic-gate px_dma_freehdl,
790Sstevel@tonic-gate px_dma_bindhdl,
800Sstevel@tonic-gate px_dma_unbindhdl,
810Sstevel@tonic-gate px_lib_dma_sync,
820Sstevel@tonic-gate px_dma_win,
830Sstevel@tonic-gate px_dma_ctlops,
840Sstevel@tonic-gate px_ctlops,
850Sstevel@tonic-gate ddi_bus_prop_op,
860Sstevel@tonic-gate ndi_busop_get_eventcookie,
870Sstevel@tonic-gate ndi_busop_add_eventcall,
880Sstevel@tonic-gate ndi_busop_remove_eventcall,
890Sstevel@tonic-gate ndi_post_event,
900Sstevel@tonic-gate NULL,
910Sstevel@tonic-gate NULL, /* (*bus_config)(); */
920Sstevel@tonic-gate NULL, /* (*bus_unconfig)(); */
930Sstevel@tonic-gate px_fm_init_child, /* (*bus_fm_init)(); */
940Sstevel@tonic-gate NULL, /* (*bus_fm_fini)(); */
9527Sjchu px_bus_enter, /* (*bus_fm_access_enter)(); */
9627Sjchu px_bus_exit, /* (*bus_fm_access_fini)(); */
970Sstevel@tonic-gate pcie_bus_power, /* (*bus_power)(); */
9810923SEvan.Yan@Sun.COM px_intr_ops, /* (*bus_intr_op)(); */
9910923SEvan.Yan@Sun.COM pcie_hp_common_ops /* (*bus_hp_op)(); */
1000Sstevel@tonic-gate };
1010Sstevel@tonic-gate
1020Sstevel@tonic-gate extern struct cb_ops px_cb_ops;
1030Sstevel@tonic-gate
1040Sstevel@tonic-gate static struct dev_ops px_ops = {
1050Sstevel@tonic-gate DEVO_REV,
1060Sstevel@tonic-gate 0,
1070Sstevel@tonic-gate px_info,
1080Sstevel@tonic-gate nulldev,
1090Sstevel@tonic-gate 0,
1100Sstevel@tonic-gate px_attach,
1110Sstevel@tonic-gate px_detach,
1120Sstevel@tonic-gate nodev,
1130Sstevel@tonic-gate &px_cb_ops,
1140Sstevel@tonic-gate &px_bus_ops,
1157656SSherry.Moore@Sun.COM nulldev,
1167656SSherry.Moore@Sun.COM ddi_quiesce_not_needed, /* quiesce */
1170Sstevel@tonic-gate };
1180Sstevel@tonic-gate
1190Sstevel@tonic-gate /*
1200Sstevel@tonic-gate * module definitions:
1210Sstevel@tonic-gate */
1220Sstevel@tonic-gate #include <sys/modctl.h>
1230Sstevel@tonic-gate extern struct mod_ops mod_driverops;
1240Sstevel@tonic-gate
1250Sstevel@tonic-gate static struct modldrv modldrv = {
12610923SEvan.Yan@Sun.COM &mod_driverops, /* Type of module - driver */
12710923SEvan.Yan@Sun.COM #if defined(sun4u)
12810923SEvan.Yan@Sun.COM "Sun4u Host to PCIe nexus driver", /* Name of module. */
12910923SEvan.Yan@Sun.COM #elif defined(sun4v)
13010923SEvan.Yan@Sun.COM "Sun4v Host to PCIe nexus driver", /* Name of module. */
13110923SEvan.Yan@Sun.COM #endif
13210923SEvan.Yan@Sun.COM &px_ops, /* driver ops */
1330Sstevel@tonic-gate };
1340Sstevel@tonic-gate
1350Sstevel@tonic-gate static struct modlinkage modlinkage = {
1360Sstevel@tonic-gate MODREV_1, (void *)&modldrv, NULL
1370Sstevel@tonic-gate };
1380Sstevel@tonic-gate
1390Sstevel@tonic-gate /* driver soft state */
1400Sstevel@tonic-gate void *px_state_p;
1410Sstevel@tonic-gate
14212341SDavid.Woods@Sun.COM int px_force_intx_support = 1;
14312341SDavid.Woods@Sun.COM
1440Sstevel@tonic-gate int
_init(void)1450Sstevel@tonic-gate _init(void)
1460Sstevel@tonic-gate {
1470Sstevel@tonic-gate int e;
1480Sstevel@tonic-gate
1490Sstevel@tonic-gate /*
1500Sstevel@tonic-gate * Initialize per-px bus soft state pointer.
1510Sstevel@tonic-gate */
1520Sstevel@tonic-gate e = ddi_soft_state_init(&px_state_p, sizeof (px_t), 1);
1530Sstevel@tonic-gate if (e != DDI_SUCCESS)
1540Sstevel@tonic-gate return (e);
1550Sstevel@tonic-gate
1560Sstevel@tonic-gate /*
1570Sstevel@tonic-gate * Install the module.
1580Sstevel@tonic-gate */
1590Sstevel@tonic-gate e = mod_install(&modlinkage);
1600Sstevel@tonic-gate if (e != DDI_SUCCESS)
1610Sstevel@tonic-gate ddi_soft_state_fini(&px_state_p);
1620Sstevel@tonic-gate return (e);
1630Sstevel@tonic-gate }
1640Sstevel@tonic-gate
1650Sstevel@tonic-gate int
_fini(void)1660Sstevel@tonic-gate _fini(void)
1670Sstevel@tonic-gate {
1680Sstevel@tonic-gate int e;
1690Sstevel@tonic-gate
1700Sstevel@tonic-gate /*
1710Sstevel@tonic-gate * Remove the module.
1720Sstevel@tonic-gate */
1730Sstevel@tonic-gate e = mod_remove(&modlinkage);
1740Sstevel@tonic-gate if (e != DDI_SUCCESS)
1750Sstevel@tonic-gate return (e);
1760Sstevel@tonic-gate
1770Sstevel@tonic-gate /* Free px soft state */
1780Sstevel@tonic-gate ddi_soft_state_fini(&px_state_p);
1790Sstevel@tonic-gate
1800Sstevel@tonic-gate return (e);
1810Sstevel@tonic-gate }
1820Sstevel@tonic-gate
1830Sstevel@tonic-gate int
_info(struct modinfo * modinfop)1840Sstevel@tonic-gate _info(struct modinfo *modinfop)
1850Sstevel@tonic-gate {
1860Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop));
1870Sstevel@tonic-gate }
1880Sstevel@tonic-gate
1890Sstevel@tonic-gate /* ARGSUSED */
1900Sstevel@tonic-gate static int
px_info(dev_info_t * dip,ddi_info_cmd_t infocmd,void * arg,void ** result)1910Sstevel@tonic-gate px_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result)
1920Sstevel@tonic-gate {
19310923SEvan.Yan@Sun.COM minor_t minor = getminor((dev_t)arg);
19410923SEvan.Yan@Sun.COM int instance = PCI_MINOR_NUM_TO_INSTANCE(minor);
1950Sstevel@tonic-gate px_t *px_p = INST_TO_STATE(instance);
19610923SEvan.Yan@Sun.COM int ret = DDI_SUCCESS;
1970Sstevel@tonic-gate
1980Sstevel@tonic-gate switch (infocmd) {
1990Sstevel@tonic-gate case DDI_INFO_DEVT2INSTANCE:
200671Skrishnae *result = (void *)(intptr_t)instance;
20110923SEvan.Yan@Sun.COM break;
2020Sstevel@tonic-gate case DDI_INFO_DEVT2DEVINFO:
20310923SEvan.Yan@Sun.COM if (px_p == NULL) {
20410923SEvan.Yan@Sun.COM ret = DDI_FAILURE;
20510923SEvan.Yan@Sun.COM break;
20610923SEvan.Yan@Sun.COM }
20710923SEvan.Yan@Sun.COM
2080Sstevel@tonic-gate *result = (void *)px_p->px_dip;
20910923SEvan.Yan@Sun.COM break;
2100Sstevel@tonic-gate default:
21110923SEvan.Yan@Sun.COM ret = DDI_FAILURE;
21210923SEvan.Yan@Sun.COM break;
2130Sstevel@tonic-gate }
21410923SEvan.Yan@Sun.COM
21510923SEvan.Yan@Sun.COM return (ret);
2160Sstevel@tonic-gate }
2170Sstevel@tonic-gate
2180Sstevel@tonic-gate /* device driver entry points */
2190Sstevel@tonic-gate /*
2200Sstevel@tonic-gate * attach entry point:
2210Sstevel@tonic-gate */
2220Sstevel@tonic-gate /*ARGSUSED*/
2230Sstevel@tonic-gate static int
px_attach(dev_info_t * dip,ddi_attach_cmd_t cmd)2240Sstevel@tonic-gate px_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
2250Sstevel@tonic-gate {
2260Sstevel@tonic-gate px_t *px_p; /* per bus state pointer */
2270Sstevel@tonic-gate int instance = DIP_TO_INST(dip);
2280Sstevel@tonic-gate int ret = DDI_SUCCESS;
2290Sstevel@tonic-gate devhandle_t dev_hdl = NULL;
23010923SEvan.Yan@Sun.COM pcie_hp_regops_t regops;
23111245SZhijun.Fu@Sun.COM pcie_bus_t *bus_p;
2320Sstevel@tonic-gate
2330Sstevel@tonic-gate switch (cmd) {
2340Sstevel@tonic-gate case DDI_ATTACH:
2350Sstevel@tonic-gate DBG(DBG_ATTACH, dip, "DDI_ATTACH\n");
2360Sstevel@tonic-gate
23711245SZhijun.Fu@Sun.COM /* See pci_cfgacc.c */
23811245SZhijun.Fu@Sun.COM pci_cfgacc_acc_p = pci_cfgacc_acc;
23911245SZhijun.Fu@Sun.COM
2400Sstevel@tonic-gate /*
2410Sstevel@tonic-gate * Allocate and get the per-px soft state structure.
2420Sstevel@tonic-gate */
2430Sstevel@tonic-gate if (ddi_soft_state_zalloc(px_state_p, instance)
2440Sstevel@tonic-gate != DDI_SUCCESS) {
2450Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d: can't allocate px state",
2466313Skrishnae ddi_driver_name(dip), instance);
2470Sstevel@tonic-gate goto err_bad_px_softstate;
2480Sstevel@tonic-gate }
2490Sstevel@tonic-gate px_p = INST_TO_STATE(instance);
2500Sstevel@tonic-gate px_p->px_dip = dip;
2510Sstevel@tonic-gate mutex_init(&px_p->px_mutex, NULL, MUTEX_DRIVER, NULL);
25210923SEvan.Yan@Sun.COM px_p->px_soft_state = PCI_SOFT_STATE_CLOSED;
2530Sstevel@tonic-gate
2541531Skini (void) ddi_prop_update_string(DDI_DEV_T_NONE, dip,
2556313Skrishnae "device_type", "pciex");
2563274Set142600
2573274Set142600 /* Initialize px_dbg for high pil printing */
2583274Set142600 px_dbg_attach(dip, &px_p->px_dbg_hdl);
25910923SEvan.Yan@Sun.COM pcie_rc_init_bus(dip);
2603274Set142600
2610Sstevel@tonic-gate /*
2620Sstevel@tonic-gate * Get key properties of the pci bridge node and
2630Sstevel@tonic-gate * determine it's type (psycho, schizo, etc ...).
2640Sstevel@tonic-gate */
2650Sstevel@tonic-gate if (px_get_props(px_p, dip) == DDI_FAILURE)
2660Sstevel@tonic-gate goto err_bad_px_prop;
2670Sstevel@tonic-gate
2680Sstevel@tonic-gate if (px_lib_dev_init(dip, &dev_hdl) != DDI_SUCCESS)
2690Sstevel@tonic-gate goto err_bad_dev_init;
2700Sstevel@tonic-gate
2711725Segillett /* Initialize device handle */
2720Sstevel@tonic-gate px_p->px_dev_hdl = dev_hdl;
2730Sstevel@tonic-gate
2743613Set142600 /* Cache the BDF of the root port nexus */
2753613Set142600 px_p->px_bdf = px_lib_get_bdf(px_p);
2763613Set142600
2770Sstevel@tonic-gate /*
2780Sstevel@tonic-gate * Initialize interrupt block. Note that this
2790Sstevel@tonic-gate * initialize error handling for the PEC as well.
2800Sstevel@tonic-gate */
2810Sstevel@tonic-gate if ((ret = px_ib_attach(px_p)) != DDI_SUCCESS)
2820Sstevel@tonic-gate goto err_bad_ib;
2830Sstevel@tonic-gate
2840Sstevel@tonic-gate if (px_cb_attach(px_p) != DDI_SUCCESS)
2850Sstevel@tonic-gate goto err_bad_cb;
2860Sstevel@tonic-gate
2870Sstevel@tonic-gate /*
2880Sstevel@tonic-gate * Start creating the modules.
2890Sstevel@tonic-gate * Note that attach() routines should
2900Sstevel@tonic-gate * register and enable their own interrupts.
2910Sstevel@tonic-gate */
2920Sstevel@tonic-gate
2930Sstevel@tonic-gate if ((px_mmu_attach(px_p)) != DDI_SUCCESS)
2940Sstevel@tonic-gate goto err_bad_mmu;
2950Sstevel@tonic-gate
2960Sstevel@tonic-gate if ((px_msiq_attach(px_p)) != DDI_SUCCESS)
2970Sstevel@tonic-gate goto err_bad_msiq;
2980Sstevel@tonic-gate
2990Sstevel@tonic-gate if ((px_msi_attach(px_p)) != DDI_SUCCESS)
3000Sstevel@tonic-gate goto err_bad_msi;
3010Sstevel@tonic-gate
3020Sstevel@tonic-gate if ((px_pec_attach(px_p)) != DDI_SUCCESS)
3030Sstevel@tonic-gate goto err_bad_pec;
3040Sstevel@tonic-gate
3050Sstevel@tonic-gate if ((px_dma_attach(px_p)) != DDI_SUCCESS)
3062510Sjchu goto err_bad_dma; /* nothing to uninitialize on DMA */
3070Sstevel@tonic-gate
3082587Spjha if ((px_fm_attach(px_p)) != DDI_SUCCESS)
3092587Spjha goto err_bad_dma;
3102587Spjha
3110Sstevel@tonic-gate /*
3120Sstevel@tonic-gate * All of the error handlers have been registered
313*12458SErwin.Tsaur@Sun.COM * by now so it's time to activate all the interrupt.
3140Sstevel@tonic-gate */
315*12458SErwin.Tsaur@Sun.COM if ((px_enable_err_intr(px_p)) != DDI_SUCCESS)
3162587Spjha goto err_bad_intr;
3170Sstevel@tonic-gate
31810923SEvan.Yan@Sun.COM if (px_lib_hotplug_init(dip, (void *)®ops) == DDI_SUCCESS) {
31910923SEvan.Yan@Sun.COM pcie_bus_t *bus_p = PCIE_DIP2BUS(dip);
32010923SEvan.Yan@Sun.COM
32110923SEvan.Yan@Sun.COM bus_p->bus_hp_sup_modes |= PCIE_NATIVE_HP_MODE;
32210923SEvan.Yan@Sun.COM }
3231531Skini
3247596SAlan.Adamson@Sun.COM (void) px_set_mps(px_p);
3257596SAlan.Adamson@Sun.COM
32610923SEvan.Yan@Sun.COM if (pcie_init(dip, (caddr_t)®ops) != DDI_SUCCESS)
32710923SEvan.Yan@Sun.COM goto err_bad_hotplug;
328624Sschwartz
32911445SEvan.Yan@Sun.COM (void) pcie_hpintr_enable(dip);
33011445SEvan.Yan@Sun.COM
331624Sschwartz if (pxtool_init(dip) != DDI_SUCCESS)
332624Sschwartz goto err_bad_pcitool_node;
333624Sschwartz
3340Sstevel@tonic-gate /*
3350Sstevel@tonic-gate * power management setup. Even if it fails, attach will
3360Sstevel@tonic-gate * succeed as this is a optional feature. Since we are
3370Sstevel@tonic-gate * always at full power, this is not critical.
3380Sstevel@tonic-gate */
3390Sstevel@tonic-gate if (pwr_common_setup(dip) != DDI_SUCCESS) {
3400Sstevel@tonic-gate DBG(DBG_PWR, dip, "pwr_common_setup failed\n");
3410Sstevel@tonic-gate } else if (px_pwr_setup(dip) != DDI_SUCCESS) {
3420Sstevel@tonic-gate DBG(DBG_PWR, dip, "px_pwr_setup failed \n");
3430Sstevel@tonic-gate pwr_common_teardown(dip);
3440Sstevel@tonic-gate }
3450Sstevel@tonic-gate
346435Sjchu /*
347435Sjchu * add cpr callback
348435Sjchu */
349435Sjchu px_cpr_add_callb(px_p);
350435Sjchu
35111596SJason.Beloro@Sun.COM /*
35211596SJason.Beloro@Sun.COM * do fabric sync in case we don't need to wait for
35311596SJason.Beloro@Sun.COM * any bridge driver to be ready
35411596SJason.Beloro@Sun.COM */
35511596SJason.Beloro@Sun.COM (void) px_lib_fabric_sync(dip);
35611596SJason.Beloro@Sun.COM
3570Sstevel@tonic-gate ddi_report_dev(dip);
3580Sstevel@tonic-gate
3590Sstevel@tonic-gate px_p->px_state = PX_ATTACHED;
36011245SZhijun.Fu@Sun.COM
36111245SZhijun.Fu@Sun.COM /*
36211245SZhijun.Fu@Sun.COM * save base addr in bus_t for pci_cfgacc_xxx(), this
36311245SZhijun.Fu@Sun.COM * depends of px structure being properly initialized.
36411245SZhijun.Fu@Sun.COM */
36511245SZhijun.Fu@Sun.COM bus_p = PCIE_DIP2BUS(dip);
36611245SZhijun.Fu@Sun.COM bus_p->bus_cfgacc_base = px_lib_get_cfgacc_base(dip);
36711245SZhijun.Fu@Sun.COM
36811245SZhijun.Fu@Sun.COM /*
36911245SZhijun.Fu@Sun.COM * Partially populate bus_t for all devices in this fabric
37011245SZhijun.Fu@Sun.COM * for device type macros to work.
37111245SZhijun.Fu@Sun.COM */
37211245SZhijun.Fu@Sun.COM /*
37311245SZhijun.Fu@Sun.COM * Populate bus_t for all devices in this fabric, after FMA
37411245SZhijun.Fu@Sun.COM * is initializated, so that config access errors could
37511245SZhijun.Fu@Sun.COM * trigger panic.
37611245SZhijun.Fu@Sun.COM */
37711245SZhijun.Fu@Sun.COM pcie_fab_init_bus(dip, PCIE_BUS_ALL);
37811245SZhijun.Fu@Sun.COM
3790Sstevel@tonic-gate DBG(DBG_ATTACH, dip, "attach success\n");
3800Sstevel@tonic-gate break;
3810Sstevel@tonic-gate
382624Sschwartz err_bad_pcitool_node:
38311445SEvan.Yan@Sun.COM (void) pcie_hpintr_disable(dip);
38410923SEvan.Yan@Sun.COM (void) pcie_uninit(dip);
38510923SEvan.Yan@Sun.COM err_bad_hotplug:
38610923SEvan.Yan@Sun.COM (void) px_lib_hotplug_uninit(dip);
387*12458SErwin.Tsaur@Sun.COM px_disable_err_intr(px_p);
3882587Spjha err_bad_intr:
3892510Sjchu px_fm_detach(px_p);
3902510Sjchu err_bad_dma:
3910Sstevel@tonic-gate px_pec_detach(px_p);
3920Sstevel@tonic-gate err_bad_pec:
3930Sstevel@tonic-gate px_msi_detach(px_p);
3940Sstevel@tonic-gate err_bad_msi:
3950Sstevel@tonic-gate px_msiq_detach(px_p);
3960Sstevel@tonic-gate err_bad_msiq:
3970Sstevel@tonic-gate px_mmu_detach(px_p);
3980Sstevel@tonic-gate err_bad_mmu:
3990Sstevel@tonic-gate err_bad_cb:
4000Sstevel@tonic-gate px_ib_detach(px_p);
4010Sstevel@tonic-gate err_bad_ib:
4027124Sanbui if (px_lib_dev_fini(dip) != DDI_SUCCESS) {
4037124Sanbui DBG(DBG_ATTACH, dip, "px_lib_dev_fini failed\n");
4047124Sanbui }
4050Sstevel@tonic-gate err_bad_dev_init:
4060Sstevel@tonic-gate px_free_props(px_p);
4070Sstevel@tonic-gate err_bad_px_prop:
40810923SEvan.Yan@Sun.COM pcie_rc_fini_bus(dip);
4093274Set142600 px_dbg_detach(dip, &px_p->px_dbg_hdl);
4100Sstevel@tonic-gate mutex_destroy(&px_p->px_mutex);
4110Sstevel@tonic-gate ddi_soft_state_free(px_state_p, instance);
4120Sstevel@tonic-gate err_bad_px_softstate:
4130Sstevel@tonic-gate ret = DDI_FAILURE;
4140Sstevel@tonic-gate break;
4150Sstevel@tonic-gate
4160Sstevel@tonic-gate case DDI_RESUME:
4170Sstevel@tonic-gate DBG(DBG_ATTACH, dip, "DDI_RESUME\n");
4180Sstevel@tonic-gate
4190Sstevel@tonic-gate px_p = INST_TO_STATE(instance);
4200Sstevel@tonic-gate
4210Sstevel@tonic-gate mutex_enter(&px_p->px_mutex);
4220Sstevel@tonic-gate
4230Sstevel@tonic-gate /* suspend might have not succeeded */
4240Sstevel@tonic-gate if (px_p->px_state != PX_SUSPENDED) {
4250Sstevel@tonic-gate DBG(DBG_ATTACH, px_p->px_dip,
4260Sstevel@tonic-gate "instance NOT suspended\n");
4270Sstevel@tonic-gate ret = DDI_FAILURE;
4280Sstevel@tonic-gate break;
4290Sstevel@tonic-gate }
4300Sstevel@tonic-gate
4312588Segillett px_msiq_resume(px_p);
4320Sstevel@tonic-gate px_lib_resume(dip);
4330Sstevel@tonic-gate (void) pcie_pwr_resume(dip);
4340Sstevel@tonic-gate px_p->px_state = PX_ATTACHED;
4350Sstevel@tonic-gate
4360Sstevel@tonic-gate mutex_exit(&px_p->px_mutex);
4370Sstevel@tonic-gate
4380Sstevel@tonic-gate break;
4390Sstevel@tonic-gate default:
4400Sstevel@tonic-gate DBG(DBG_ATTACH, dip, "unsupported attach op\n");
4410Sstevel@tonic-gate ret = DDI_FAILURE;
4420Sstevel@tonic-gate break;
4430Sstevel@tonic-gate }
4440Sstevel@tonic-gate
4450Sstevel@tonic-gate return (ret);
4460Sstevel@tonic-gate }
4470Sstevel@tonic-gate
4480Sstevel@tonic-gate /*
4490Sstevel@tonic-gate * detach entry point:
4500Sstevel@tonic-gate */
4510Sstevel@tonic-gate /*ARGSUSED*/
4520Sstevel@tonic-gate static int
px_detach(dev_info_t * dip,ddi_detach_cmd_t cmd)4530Sstevel@tonic-gate px_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
4540Sstevel@tonic-gate {
45510923SEvan.Yan@Sun.COM int instance = ddi_get_instance(dip);
45610923SEvan.Yan@Sun.COM px_t *px_p = INST_TO_STATE(instance);
45710923SEvan.Yan@Sun.COM pcie_bus_t *bus_p = PCIE_DIP2BUS(dip);
45810923SEvan.Yan@Sun.COM int ret;
4590Sstevel@tonic-gate
4600Sstevel@tonic-gate /*
4610Sstevel@tonic-gate * Make sure we are currently attached
4620Sstevel@tonic-gate */
4630Sstevel@tonic-gate if (px_p->px_state != PX_ATTACHED) {
4641648Sjchu DBG(DBG_DETACH, dip, "Instance not attached\n");
4650Sstevel@tonic-gate return (DDI_FAILURE);
4660Sstevel@tonic-gate }
4670Sstevel@tonic-gate
4680Sstevel@tonic-gate mutex_enter(&px_p->px_mutex);
4690Sstevel@tonic-gate
4700Sstevel@tonic-gate switch (cmd) {
4710Sstevel@tonic-gate case DDI_DETACH:
4720Sstevel@tonic-gate DBG(DBG_DETACH, dip, "DDI_DETACH\n");
4730Sstevel@tonic-gate
474435Sjchu /*
475435Sjchu * remove cpr callback
476435Sjchu */
477435Sjchu px_cpr_rem_callb(px_p);
478435Sjchu
47911445SEvan.Yan@Sun.COM (void) pcie_hpintr_disable(dip);
48011445SEvan.Yan@Sun.COM
48110923SEvan.Yan@Sun.COM if (PCIE_IS_PCIE_HOTPLUG_ENABLED(bus_p))
48210923SEvan.Yan@Sun.COM (void) px_lib_hotplug_uninit(dip);
48310923SEvan.Yan@Sun.COM
48410923SEvan.Yan@Sun.COM if (pcie_uninit(dip) != DDI_SUCCESS) {
48510923SEvan.Yan@Sun.COM mutex_exit(&px_p->px_mutex);
48610923SEvan.Yan@Sun.COM return (DDI_FAILURE);
48710923SEvan.Yan@Sun.COM }
4880Sstevel@tonic-gate
48911245SZhijun.Fu@Sun.COM /* Destroy bus_t for the whole fabric */
49011245SZhijun.Fu@Sun.COM pcie_fab_fini_bus(dip, PCIE_BUS_ALL);
49111245SZhijun.Fu@Sun.COM
4920Sstevel@tonic-gate /*
4930Sstevel@tonic-gate * things which used to be done in obj_destroy
4940Sstevel@tonic-gate * are now in-lined here.
4950Sstevel@tonic-gate */
4960Sstevel@tonic-gate
4970Sstevel@tonic-gate px_p->px_state = PX_DETACHED;
4980Sstevel@tonic-gate
499624Sschwartz pxtool_uninit(dip);
500624Sschwartz
501*12458SErwin.Tsaur@Sun.COM px_disable_err_intr(px_p);
5022510Sjchu px_fm_detach(px_p);
5030Sstevel@tonic-gate px_pec_detach(px_p);
504965Sgovinda px_pwr_teardown(dip);
505965Sgovinda pwr_common_teardown(dip);
5060Sstevel@tonic-gate px_msi_detach(px_p);
5070Sstevel@tonic-gate px_msiq_detach(px_p);
5080Sstevel@tonic-gate px_mmu_detach(px_p);
5090Sstevel@tonic-gate px_ib_detach(px_p);
5107124Sanbui if (px_lib_dev_fini(dip) != DDI_SUCCESS) {
5117124Sanbui DBG(DBG_DETACH, dip, "px_lib_dev_fini failed\n");
5127124Sanbui }
5130Sstevel@tonic-gate
5140Sstevel@tonic-gate /*
5150Sstevel@tonic-gate * Free the px soft state structure and the rest of the
5160Sstevel@tonic-gate * resources it's using.
5170Sstevel@tonic-gate */
5180Sstevel@tonic-gate px_free_props(px_p);
51910923SEvan.Yan@Sun.COM pcie_rc_fini_bus(dip);
5203274Set142600 px_dbg_detach(dip, &px_p->px_dbg_hdl);
5210Sstevel@tonic-gate mutex_exit(&px_p->px_mutex);
5220Sstevel@tonic-gate mutex_destroy(&px_p->px_mutex);
5230Sstevel@tonic-gate
5240Sstevel@tonic-gate px_p->px_dev_hdl = NULL;
5251064Sschwartz ddi_soft_state_free(px_state_p, instance);
5260Sstevel@tonic-gate
5270Sstevel@tonic-gate return (DDI_SUCCESS);
5280Sstevel@tonic-gate
5290Sstevel@tonic-gate case DDI_SUSPEND:
5300Sstevel@tonic-gate if (pcie_pwr_suspend(dip) != DDI_SUCCESS) {
5310Sstevel@tonic-gate mutex_exit(&px_p->px_mutex);
5320Sstevel@tonic-gate return (DDI_FAILURE);
5330Sstevel@tonic-gate }
5340Sstevel@tonic-gate if ((ret = px_lib_suspend(dip)) == DDI_SUCCESS)
5350Sstevel@tonic-gate px_p->px_state = PX_SUSPENDED;
5360Sstevel@tonic-gate mutex_exit(&px_p->px_mutex);
5370Sstevel@tonic-gate
5380Sstevel@tonic-gate return (ret);
5390Sstevel@tonic-gate
5400Sstevel@tonic-gate default:
5410Sstevel@tonic-gate DBG(DBG_DETACH, dip, "unsupported detach op\n");
5420Sstevel@tonic-gate mutex_exit(&px_p->px_mutex);
5430Sstevel@tonic-gate return (DDI_FAILURE);
5440Sstevel@tonic-gate }
5450Sstevel@tonic-gate }
5460Sstevel@tonic-gate
547*12458SErwin.Tsaur@Sun.COM static int
px_enable_err_intr(px_t * px_p)548*12458SErwin.Tsaur@Sun.COM px_enable_err_intr(px_t *px_p)
549*12458SErwin.Tsaur@Sun.COM {
550*12458SErwin.Tsaur@Sun.COM /* Add FMA Callback handler for failed PIO Loads */
551*12458SErwin.Tsaur@Sun.COM px_fm_cb_enable(px_p);
552*12458SErwin.Tsaur@Sun.COM
553*12458SErwin.Tsaur@Sun.COM /* Add Common Block mondo handler */
554*12458SErwin.Tsaur@Sun.COM if (px_cb_add_intr(&px_p->px_cb_fault) != DDI_SUCCESS)
555*12458SErwin.Tsaur@Sun.COM goto cb_bad;
556*12458SErwin.Tsaur@Sun.COM
557*12458SErwin.Tsaur@Sun.COM /* Add PEU Block Mondo Handler */
558*12458SErwin.Tsaur@Sun.COM if (px_err_add_intr(&px_p->px_fault) != DDI_SUCCESS)
559*12458SErwin.Tsaur@Sun.COM goto peu_bad;
560*12458SErwin.Tsaur@Sun.COM
561*12458SErwin.Tsaur@Sun.COM /* Enable interrupt handler for PCIE Fabric Error Messages */
562*12458SErwin.Tsaur@Sun.COM if (px_pec_msg_add_intr(px_p) != DDI_SUCCESS)
563*12458SErwin.Tsaur@Sun.COM goto msg_bad;
564*12458SErwin.Tsaur@Sun.COM
565*12458SErwin.Tsaur@Sun.COM return (DDI_SUCCESS);
566*12458SErwin.Tsaur@Sun.COM
567*12458SErwin.Tsaur@Sun.COM msg_bad:
568*12458SErwin.Tsaur@Sun.COM px_err_rem_intr(&px_p->px_fault);
569*12458SErwin.Tsaur@Sun.COM peu_bad:
570*12458SErwin.Tsaur@Sun.COM px_cb_rem_intr(&px_p->px_cb_fault);
571*12458SErwin.Tsaur@Sun.COM cb_bad:
572*12458SErwin.Tsaur@Sun.COM px_fm_cb_disable(px_p);
573*12458SErwin.Tsaur@Sun.COM
574*12458SErwin.Tsaur@Sun.COM return (DDI_FAILURE);
575*12458SErwin.Tsaur@Sun.COM }
576*12458SErwin.Tsaur@Sun.COM
577*12458SErwin.Tsaur@Sun.COM static void
px_disable_err_intr(px_t * px_p)578*12458SErwin.Tsaur@Sun.COM px_disable_err_intr(px_t *px_p)
579*12458SErwin.Tsaur@Sun.COM {
580*12458SErwin.Tsaur@Sun.COM px_pec_msg_rem_intr(px_p);
581*12458SErwin.Tsaur@Sun.COM px_err_rem_intr(&px_p->px_fault);
582*12458SErwin.Tsaur@Sun.COM px_cb_rem_intr(&px_p->px_cb_fault);
583*12458SErwin.Tsaur@Sun.COM px_fm_cb_disable(px_p);
584*12458SErwin.Tsaur@Sun.COM }
585*12458SErwin.Tsaur@Sun.COM
5861648Sjchu int
px_cb_attach(px_t * px_p)5871648Sjchu px_cb_attach(px_t *px_p)
5881648Sjchu {
5891648Sjchu px_fault_t *fault_p = &px_p->px_cb_fault;
5901648Sjchu dev_info_t *dip = px_p->px_dip;
5911648Sjchu sysino_t sysino;
5921648Sjchu
5931648Sjchu if (px_lib_intr_devino_to_sysino(dip,
5941648Sjchu px_p->px_inos[PX_INTR_XBC], &sysino) != DDI_SUCCESS)
5951648Sjchu return (DDI_FAILURE);
5961648Sjchu
5971648Sjchu fault_p->px_fh_dip = dip;
5981648Sjchu fault_p->px_fh_sysino = sysino;
5991648Sjchu fault_p->px_err_func = px_err_cb_intr;
6001648Sjchu fault_p->px_intr_ino = px_p->px_inos[PX_INTR_XBC];
6011648Sjchu
602*12458SErwin.Tsaur@Sun.COM return (DDI_SUCCESS);
6031648Sjchu }
6041648Sjchu
6050Sstevel@tonic-gate /*
6060Sstevel@tonic-gate * power management related initialization specific to px
6070Sstevel@tonic-gate * called by px_attach()
6080Sstevel@tonic-gate */
6090Sstevel@tonic-gate static int
px_pwr_setup(dev_info_t * dip)6100Sstevel@tonic-gate px_pwr_setup(dev_info_t *dip)
6110Sstevel@tonic-gate {
6120Sstevel@tonic-gate pcie_pwr_t *pwr_p;
613118Sjchu int instance = ddi_get_instance(dip);
614118Sjchu px_t *px_p = INST_TO_STATE(instance);
6150Sstevel@tonic-gate ddi_intr_handle_impl_t hdl;
6160Sstevel@tonic-gate
6170Sstevel@tonic-gate ASSERT(PCIE_PMINFO(dip));
6180Sstevel@tonic-gate pwr_p = PCIE_NEXUS_PMINFO(dip);
6190Sstevel@tonic-gate ASSERT(pwr_p);
6200Sstevel@tonic-gate
6210Sstevel@tonic-gate /*
6220Sstevel@tonic-gate * indicate support LDI (Layered Driver Interface)
6230Sstevel@tonic-gate * Create the property, if it is not already there
6240Sstevel@tonic-gate */
6250Sstevel@tonic-gate if (!ddi_prop_exists(DDI_DEV_T_NONE, dip, DDI_PROP_DONTPASS,
6260Sstevel@tonic-gate DDI_KERNEL_IOCTL)) {
6270Sstevel@tonic-gate if (ddi_prop_create(DDI_DEV_T_NONE, dip, DDI_PROP_CANSLEEP,
6280Sstevel@tonic-gate DDI_KERNEL_IOCTL, NULL, 0) != DDI_PROP_SUCCESS) {
6290Sstevel@tonic-gate DBG(DBG_PWR, dip, "can't create kernel ioctl prop\n");
6300Sstevel@tonic-gate return (DDI_FAILURE);
6310Sstevel@tonic-gate }
6320Sstevel@tonic-gate }
6330Sstevel@tonic-gate /* No support for device PM. We are always at full power */
6340Sstevel@tonic-gate pwr_p->pwr_func_lvl = PM_LEVEL_D0;
6350Sstevel@tonic-gate
636118Sjchu mutex_init(&px_p->px_l23ready_lock, NULL, MUTEX_DRIVER,
637693Sgovinda DDI_INTR_PRI(px_pwr_pil));
638118Sjchu cv_init(&px_p->px_l23ready_cv, NULL, CV_DRIVER, NULL);
639118Sjchu
6401725Segillett /* Initialize handle */
6411725Segillett bzero(&hdl, sizeof (ddi_intr_handle_impl_t));
642118Sjchu hdl.ih_cb_arg1 = px_p;
6430Sstevel@tonic-gate hdl.ih_ver = DDI_INTR_VERSION;
6440Sstevel@tonic-gate hdl.ih_state = DDI_IHDL_STATE_ALLOC;
6450Sstevel@tonic-gate hdl.ih_dip = dip;
6460Sstevel@tonic-gate hdl.ih_pri = px_pwr_pil;
6470Sstevel@tonic-gate
6480Sstevel@tonic-gate /* Add PME_TO_ACK message handler */
649118Sjchu hdl.ih_cb_func = (ddi_intr_handler_t *)px_pmeq_intr;
6500Sstevel@tonic-gate if (px_add_msiq_intr(dip, dip, &hdl, MSG_REC,
65110053SEvan.Yan@Sun.COM (msgcode_t)PCIE_PME_ACK_MSG, -1,
65210053SEvan.Yan@Sun.COM &px_p->px_pm_msiq_id) != DDI_SUCCESS) {
653118Sjchu DBG(DBG_PWR, dip, "px_pwr_setup: couldn't add "
654118Sjchu " PME_TO_ACK intr\n");
6551147Sjchu goto pwr_setup_err1;
6560Sstevel@tonic-gate }
657118Sjchu px_lib_msg_setmsiq(dip, PCIE_PME_ACK_MSG, px_p->px_pm_msiq_id);
6580Sstevel@tonic-gate px_lib_msg_setvalid(dip, PCIE_PME_ACK_MSG, PCIE_MSG_VALID);
6590Sstevel@tonic-gate
660909Segillett if (px_ib_update_intr_state(px_p, px_p->px_dip, hdl.ih_inum,
6612973Sgovinda px_msiqid_to_devino(px_p, px_p->px_pm_msiq_id), px_pwr_pil,
662909Segillett PX_INTR_STATE_ENABLE, MSG_REC, PCIE_PME_ACK_MSG) != DDI_SUCCESS) {
663909Segillett DBG(DBG_PWR, dip, "px_pwr_setup: PME_TO_ACK update interrupt"
664909Segillett " state failed\n");
665909Segillett goto px_pwrsetup_err_state;
666909Segillett }
667909Segillett
6680Sstevel@tonic-gate return (DDI_SUCCESS);
6690Sstevel@tonic-gate
670909Segillett px_pwrsetup_err_state:
671909Segillett px_lib_msg_setvalid(dip, PCIE_PME_ACK_MSG, PCIE_MSG_INVALID);
672909Segillett (void) px_rem_msiq_intr(dip, dip, &hdl, MSG_REC, PCIE_PME_ACK_MSG,
673909Segillett px_p->px_pm_msiq_id);
674118Sjchu pwr_setup_err1:
675118Sjchu mutex_destroy(&px_p->px_l23ready_lock);
676118Sjchu cv_destroy(&px_p->px_l23ready_cv);
677118Sjchu
6780Sstevel@tonic-gate return (DDI_FAILURE);
6790Sstevel@tonic-gate }
6800Sstevel@tonic-gate
6810Sstevel@tonic-gate /*
6820Sstevel@tonic-gate * undo whatever is done in px_pwr_setup. called by px_detach()
6830Sstevel@tonic-gate */
6840Sstevel@tonic-gate static void
px_pwr_teardown(dev_info_t * dip)6850Sstevel@tonic-gate px_pwr_teardown(dev_info_t *dip)
6860Sstevel@tonic-gate {
687118Sjchu int instance = ddi_get_instance(dip);
688118Sjchu px_t *px_p = INST_TO_STATE(instance);
689118Sjchu ddi_intr_handle_impl_t hdl;
6900Sstevel@tonic-gate
691118Sjchu if (!PCIE_PMINFO(dip) || !PCIE_NEXUS_PMINFO(dip))
6920Sstevel@tonic-gate return;
6930Sstevel@tonic-gate
6941725Segillett /* Initialize handle */
6951725Segillett bzero(&hdl, sizeof (ddi_intr_handle_impl_t));
6960Sstevel@tonic-gate hdl.ih_ver = DDI_INTR_VERSION;
6970Sstevel@tonic-gate hdl.ih_state = DDI_IHDL_STATE_ALLOC;
6980Sstevel@tonic-gate hdl.ih_dip = dip;
6993162Sgovinda hdl.ih_pri = px_pwr_pil;
7000Sstevel@tonic-gate
7010Sstevel@tonic-gate px_lib_msg_setvalid(dip, PCIE_PME_ACK_MSG, PCIE_MSG_INVALID);
7020Sstevel@tonic-gate (void) px_rem_msiq_intr(dip, dip, &hdl, MSG_REC, PCIE_PME_ACK_MSG,
703118Sjchu px_p->px_pm_msiq_id);
704118Sjchu
705909Segillett (void) px_ib_update_intr_state(px_p, px_p->px_dip, hdl.ih_inum,
7062973Sgovinda px_msiqid_to_devino(px_p, px_p->px_pm_msiq_id), px_pwr_pil,
707909Segillett PX_INTR_STATE_DISABLE, MSG_REC, PCIE_PME_ACK_MSG);
708909Segillett
7092840Scarlsonj px_p->px_pm_msiq_id = (msiqid_t)-1;
7100Sstevel@tonic-gate
711118Sjchu cv_destroy(&px_p->px_l23ready_cv);
712118Sjchu mutex_destroy(&px_p->px_l23ready_lock);
7130Sstevel@tonic-gate }
7140Sstevel@tonic-gate
7150Sstevel@tonic-gate /* bus driver entry points */
7160Sstevel@tonic-gate
7170Sstevel@tonic-gate /*
7180Sstevel@tonic-gate * bus map entry point:
7190Sstevel@tonic-gate *
7200Sstevel@tonic-gate * if map request is for an rnumber
7210Sstevel@tonic-gate * get the corresponding regspec from device node
7220Sstevel@tonic-gate * build a new regspec in our parent's format
7230Sstevel@tonic-gate * build a new map_req with the new regspec
7240Sstevel@tonic-gate * call up the tree to complete the mapping
7250Sstevel@tonic-gate */
7260Sstevel@tonic-gate int
px_map(dev_info_t * dip,dev_info_t * rdip,ddi_map_req_t * mp,off_t off,off_t len,caddr_t * addrp)7270Sstevel@tonic-gate px_map(dev_info_t *dip, dev_info_t *rdip, ddi_map_req_t *mp,
7280Sstevel@tonic-gate off_t off, off_t len, caddr_t *addrp)
7290Sstevel@tonic-gate {
7300Sstevel@tonic-gate px_t *px_p = DIP_TO_STATE(dip);
7310Sstevel@tonic-gate struct regspec p_regspec;
7320Sstevel@tonic-gate ddi_map_req_t p_mapreq;
7330Sstevel@tonic-gate int reglen, rval, r_no;
7340Sstevel@tonic-gate pci_regspec_t reloc_reg, *rp = &reloc_reg;
7350Sstevel@tonic-gate
7360Sstevel@tonic-gate DBG(DBG_MAP, dip, "rdip=%s%d:",
7376313Skrishnae ddi_driver_name(rdip), ddi_get_instance(rdip));
7380Sstevel@tonic-gate
7390Sstevel@tonic-gate if (mp->map_flags & DDI_MF_USER_MAPPING)
7400Sstevel@tonic-gate return (DDI_ME_UNIMPLEMENTED);
7410Sstevel@tonic-gate
7420Sstevel@tonic-gate switch (mp->map_type) {
7430Sstevel@tonic-gate case DDI_MT_REGSPEC:
7440Sstevel@tonic-gate reloc_reg = *(pci_regspec_t *)mp->map_obj.rp; /* dup whole */
7450Sstevel@tonic-gate break;
7460Sstevel@tonic-gate
7470Sstevel@tonic-gate case DDI_MT_RNUMBER:
7480Sstevel@tonic-gate r_no = mp->map_obj.rnumber;
7490Sstevel@tonic-gate DBG(DBG_MAP | DBG_CONT, dip, " r#=%x", r_no);
7500Sstevel@tonic-gate
751506Scth if (ddi_getlongprop(DDI_DEV_T_ANY, rdip, DDI_PROP_DONTPASS,
7526313Skrishnae "reg", (caddr_t)&rp, ®len) != DDI_SUCCESS)
7536313Skrishnae return (DDI_ME_RNUMBER_RANGE);
7540Sstevel@tonic-gate
7550Sstevel@tonic-gate if (r_no < 0 || r_no >= reglen / sizeof (pci_regspec_t)) {
7560Sstevel@tonic-gate kmem_free(rp, reglen);
7570Sstevel@tonic-gate return (DDI_ME_RNUMBER_RANGE);
7580Sstevel@tonic-gate }
7590Sstevel@tonic-gate rp += r_no;
7600Sstevel@tonic-gate break;
7610Sstevel@tonic-gate
7620Sstevel@tonic-gate default:
7630Sstevel@tonic-gate return (DDI_ME_INVAL);
7640Sstevel@tonic-gate }
7650Sstevel@tonic-gate DBG(DBG_MAP | DBG_CONT, dip, "\n");
7660Sstevel@tonic-gate
7670Sstevel@tonic-gate if ((rp->pci_phys_hi & PCI_REG_ADDR_M) == PCI_ADDR_CONFIG) {
7680Sstevel@tonic-gate /*
7690Sstevel@tonic-gate * There may be a need to differentiate between PCI
7700Sstevel@tonic-gate * and PCI-Ex devices so the following range check is
7710Sstevel@tonic-gate * done correctly, depending on the implementation of
77210187SKrishna.Elango@Sun.COM * pcieb bridge nexus driver.
7730Sstevel@tonic-gate */
7740Sstevel@tonic-gate if ((off >= PCIE_CONF_HDR_SIZE) ||
7756313Skrishnae (len > PCIE_CONF_HDR_SIZE) ||
7766313Skrishnae (off + len > PCIE_CONF_HDR_SIZE))
7770Sstevel@tonic-gate return (DDI_ME_INVAL);
7780Sstevel@tonic-gate /*
7790Sstevel@tonic-gate * the following function returning a DDI_FAILURE assumes
7800Sstevel@tonic-gate * that there are no virtual config space access services
7810Sstevel@tonic-gate * defined in this layer. Otherwise it is availed right
7820Sstevel@tonic-gate * here and we return.
7830Sstevel@tonic-gate */
7840Sstevel@tonic-gate rval = px_lib_map_vconfig(dip, mp, off, rp, addrp);
7850Sstevel@tonic-gate if (rval == DDI_SUCCESS)
7860Sstevel@tonic-gate goto done;
7870Sstevel@tonic-gate }
7880Sstevel@tonic-gate
7890Sstevel@tonic-gate /*
7900Sstevel@tonic-gate * No virtual config space services or we are mapping
7910Sstevel@tonic-gate * a region of memory mapped config/IO/memory space, so proceed
7920Sstevel@tonic-gate * to the parent.
7930Sstevel@tonic-gate */
7940Sstevel@tonic-gate
7950Sstevel@tonic-gate /* relocate within 64-bit pci space through "assigned-addresses" */
7960Sstevel@tonic-gate if (rval = px_reloc_reg(dip, rdip, px_p, rp))
7970Sstevel@tonic-gate goto done;
7980Sstevel@tonic-gate
7990Sstevel@tonic-gate if (len) /* adjust regspec according to mapping request */
8000Sstevel@tonic-gate rp->pci_size_low = len; /* MIN ? */
8010Sstevel@tonic-gate rp->pci_phys_low += off;
8020Sstevel@tonic-gate
8030Sstevel@tonic-gate /* translate relocated pci regspec into parent space through "ranges" */
8040Sstevel@tonic-gate if (rval = px_xlate_reg(px_p, rp, &p_regspec))
8050Sstevel@tonic-gate goto done;
8060Sstevel@tonic-gate
8070Sstevel@tonic-gate p_mapreq = *mp; /* dup the whole structure */
8080Sstevel@tonic-gate p_mapreq.map_type = DDI_MT_REGSPEC;
8090Sstevel@tonic-gate p_mapreq.map_obj.rp = &p_regspec;
810677Sjchu px_lib_map_attr_check(&p_mapreq);
8110Sstevel@tonic-gate rval = ddi_map(dip, &p_mapreq, 0, 0, addrp);
8120Sstevel@tonic-gate
8130Sstevel@tonic-gate if (rval == DDI_SUCCESS) {
8140Sstevel@tonic-gate /*
8150Sstevel@tonic-gate * Set-up access functions for FM access error capable drivers.
8160Sstevel@tonic-gate */
8176313Skrishnae if (DDI_FM_ACC_ERR_CAP(ddi_fm_capable(rdip)))
8186313Skrishnae px_fm_acc_setup(mp, rdip, rp);
8190Sstevel@tonic-gate }
8200Sstevel@tonic-gate
8210Sstevel@tonic-gate done:
8220Sstevel@tonic-gate if (mp->map_type == DDI_MT_RNUMBER)
8230Sstevel@tonic-gate kmem_free(rp - r_no, reglen);
8240Sstevel@tonic-gate
8250Sstevel@tonic-gate return (rval);
8260Sstevel@tonic-gate }
8270Sstevel@tonic-gate
8280Sstevel@tonic-gate /*
8290Sstevel@tonic-gate * bus dma map entry point
8300Sstevel@tonic-gate * return value:
8310Sstevel@tonic-gate * DDI_DMA_PARTIAL_MAP 1
8320Sstevel@tonic-gate * DDI_DMA_MAPOK 0
8330Sstevel@tonic-gate * DDI_DMA_MAPPED 0
8340Sstevel@tonic-gate * DDI_DMA_NORESOURCES -1
8350Sstevel@tonic-gate * DDI_DMA_NOMAPPING -2
8360Sstevel@tonic-gate * DDI_DMA_TOOBIG -3
8370Sstevel@tonic-gate */
8380Sstevel@tonic-gate int
px_dma_setup(dev_info_t * dip,dev_info_t * rdip,ddi_dma_req_t * dmareq,ddi_dma_handle_t * handlep)8390Sstevel@tonic-gate px_dma_setup(dev_info_t *dip, dev_info_t *rdip, ddi_dma_req_t *dmareq,
8400Sstevel@tonic-gate ddi_dma_handle_t *handlep)
8410Sstevel@tonic-gate {
8420Sstevel@tonic-gate px_t *px_p = DIP_TO_STATE(dip);
8430Sstevel@tonic-gate px_mmu_t *mmu_p = px_p->px_mmu_p;
8440Sstevel@tonic-gate ddi_dma_impl_t *mp;
8450Sstevel@tonic-gate int ret;
8460Sstevel@tonic-gate
8470Sstevel@tonic-gate DBG(DBG_DMA_MAP, dip, "mapping - rdip=%s%d type=%s\n",
8486313Skrishnae ddi_driver_name(rdip), ddi_get_instance(rdip),
8496313Skrishnae handlep ? "alloc" : "advisory");
8500Sstevel@tonic-gate
8510Sstevel@tonic-gate if (!(mp = px_dma_lmts2hdl(dip, rdip, mmu_p, dmareq)))
8520Sstevel@tonic-gate return (DDI_DMA_NORESOURCES);
8530Sstevel@tonic-gate if (mp == (ddi_dma_impl_t *)DDI_DMA_NOMAPPING)
8540Sstevel@tonic-gate return (DDI_DMA_NOMAPPING);
8550Sstevel@tonic-gate if (ret = px_dma_type(px_p, dmareq, mp))
8560Sstevel@tonic-gate goto freehandle;
8570Sstevel@tonic-gate if (ret = px_dma_pfn(px_p, dmareq, mp))
8580Sstevel@tonic-gate goto freehandle;
8590Sstevel@tonic-gate
8600Sstevel@tonic-gate switch (PX_DMA_TYPE(mp)) {
861909Segillett case PX_DMAI_FLAGS_DVMA: /* LINTED E_EQUALITY_NOT_ASSIGNMENT */
8620Sstevel@tonic-gate if ((ret = px_dvma_win(px_p, dmareq, mp)) || !handlep)
8630Sstevel@tonic-gate goto freehandle;
8640Sstevel@tonic-gate if (!PX_DMA_CANCACHE(mp)) { /* try fast track */
8650Sstevel@tonic-gate if (PX_DMA_CANFAST(mp)) {
8660Sstevel@tonic-gate if (!px_dvma_map_fast(mmu_p, mp))
8670Sstevel@tonic-gate break;
8680Sstevel@tonic-gate /* LINTED E_NOP_ELSE_STMT */
8690Sstevel@tonic-gate } else {
8700Sstevel@tonic-gate PX_DVMA_FASTTRAK_PROF(mp);
8710Sstevel@tonic-gate }
8720Sstevel@tonic-gate }
8730Sstevel@tonic-gate if (ret = px_dvma_map(mp, dmareq, mmu_p))
8740Sstevel@tonic-gate goto freehandle;
8750Sstevel@tonic-gate break;
876909Segillett case PX_DMAI_FLAGS_PTP: /* LINTED E_EQUALITY_NOT_ASSIGNMENT */
8770Sstevel@tonic-gate if ((ret = px_dma_physwin(px_p, dmareq, mp)) || !handlep)
8780Sstevel@tonic-gate goto freehandle;
8790Sstevel@tonic-gate break;
880909Segillett case PX_DMAI_FLAGS_BYPASS:
8810Sstevel@tonic-gate default:
8820Sstevel@tonic-gate cmn_err(CE_PANIC, "%s%d: px_dma_setup: bad dma type 0x%x",
8836313Skrishnae ddi_driver_name(rdip), ddi_get_instance(rdip),
8846313Skrishnae PX_DMA_TYPE(mp));
8850Sstevel@tonic-gate /*NOTREACHED*/
8860Sstevel@tonic-gate }
8870Sstevel@tonic-gate *handlep = (ddi_dma_handle_t)mp;
888909Segillett mp->dmai_flags |= PX_DMAI_FLAGS_INUSE;
8890Sstevel@tonic-gate px_dump_dma_handle(DBG_DMA_MAP, dip, mp);
8900Sstevel@tonic-gate
8910Sstevel@tonic-gate return ((mp->dmai_nwin == 1) ? DDI_DMA_MAPPED : DDI_DMA_PARTIAL_MAP);
8920Sstevel@tonic-gate freehandle:
8930Sstevel@tonic-gate if (ret == DDI_DMA_NORESOURCES)
8940Sstevel@tonic-gate px_dma_freemp(mp); /* don't run_callback() */
8950Sstevel@tonic-gate else
8960Sstevel@tonic-gate (void) px_dma_freehdl(dip, rdip, (ddi_dma_handle_t)mp);
8970Sstevel@tonic-gate return (ret);
8980Sstevel@tonic-gate }
8990Sstevel@tonic-gate
9000Sstevel@tonic-gate
9010Sstevel@tonic-gate /*
9020Sstevel@tonic-gate * bus dma alloc handle entry point:
9030Sstevel@tonic-gate */
9040Sstevel@tonic-gate int
px_dma_allochdl(dev_info_t * dip,dev_info_t * rdip,ddi_dma_attr_t * attrp,int (* waitfp)(caddr_t),caddr_t arg,ddi_dma_handle_t * handlep)9050Sstevel@tonic-gate px_dma_allochdl(dev_info_t *dip, dev_info_t *rdip, ddi_dma_attr_t *attrp,
9060Sstevel@tonic-gate int (*waitfp)(caddr_t), caddr_t arg, ddi_dma_handle_t *handlep)
9070Sstevel@tonic-gate {
9080Sstevel@tonic-gate px_t *px_p = DIP_TO_STATE(dip);
9090Sstevel@tonic-gate ddi_dma_impl_t *mp;
9100Sstevel@tonic-gate int rval;
9110Sstevel@tonic-gate
9120Sstevel@tonic-gate DBG(DBG_DMA_ALLOCH, dip, "rdip=%s%d\n",
9136313Skrishnae ddi_driver_name(rdip), ddi_get_instance(rdip));
9140Sstevel@tonic-gate
9150Sstevel@tonic-gate if (attrp->dma_attr_version != DMA_ATTR_V0)
9160Sstevel@tonic-gate return (DDI_DMA_BADATTR);
9170Sstevel@tonic-gate
9180Sstevel@tonic-gate if (!(mp = px_dma_allocmp(dip, rdip, waitfp, arg)))
9190Sstevel@tonic-gate return (DDI_DMA_NORESOURCES);
9200Sstevel@tonic-gate
9210Sstevel@tonic-gate /*
9220Sstevel@tonic-gate * Save requestor's information
9230Sstevel@tonic-gate */
9240Sstevel@tonic-gate mp->dmai_attr = *attrp; /* whole object - augmented later */
925909Segillett *PX_DEV_ATTR(mp) = *attrp; /* whole object - device orig attr */
9260Sstevel@tonic-gate DBG(DBG_DMA_ALLOCH, dip, "mp=%p\n", mp);
9270Sstevel@tonic-gate
9280Sstevel@tonic-gate /* check and convert dma attributes to handle parameters */
9290Sstevel@tonic-gate if (rval = px_dma_attr2hdl(px_p, mp)) {
9300Sstevel@tonic-gate px_dma_freehdl(dip, rdip, (ddi_dma_handle_t)mp);
9310Sstevel@tonic-gate *handlep = NULL;
9320Sstevel@tonic-gate return (rval);
9330Sstevel@tonic-gate }
9340Sstevel@tonic-gate *handlep = (ddi_dma_handle_t)mp;
9350Sstevel@tonic-gate return (DDI_SUCCESS);
9360Sstevel@tonic-gate }
9370Sstevel@tonic-gate
9380Sstevel@tonic-gate
9390Sstevel@tonic-gate /*
9400Sstevel@tonic-gate * bus dma free handle entry point:
9410Sstevel@tonic-gate */
9420Sstevel@tonic-gate /*ARGSUSED*/
9430Sstevel@tonic-gate int
px_dma_freehdl(dev_info_t * dip,dev_info_t * rdip,ddi_dma_handle_t handle)9440Sstevel@tonic-gate px_dma_freehdl(dev_info_t *dip, dev_info_t *rdip, ddi_dma_handle_t handle)
9450Sstevel@tonic-gate {
9460Sstevel@tonic-gate DBG(DBG_DMA_FREEH, dip, "rdip=%s%d mp=%p\n",
9476313Skrishnae ddi_driver_name(rdip), ddi_get_instance(rdip), handle);
9480Sstevel@tonic-gate px_dma_freemp((ddi_dma_impl_t *)handle);
9490Sstevel@tonic-gate
9500Sstevel@tonic-gate if (px_kmem_clid) {
9510Sstevel@tonic-gate DBG(DBG_DMA_FREEH, dip, "run handle callback\n");
9520Sstevel@tonic-gate ddi_run_callback(&px_kmem_clid);
9530Sstevel@tonic-gate }
9540Sstevel@tonic-gate return (DDI_SUCCESS);
9550Sstevel@tonic-gate }
9560Sstevel@tonic-gate
9570Sstevel@tonic-gate
9580Sstevel@tonic-gate /*
9590Sstevel@tonic-gate * bus dma bind handle entry point:
9600Sstevel@tonic-gate */
9610Sstevel@tonic-gate int
px_dma_bindhdl(dev_info_t * dip,dev_info_t * rdip,ddi_dma_handle_t handle,ddi_dma_req_t * dmareq,ddi_dma_cookie_t * cookiep,uint_t * ccountp)9620Sstevel@tonic-gate px_dma_bindhdl(dev_info_t *dip, dev_info_t *rdip,
9630Sstevel@tonic-gate ddi_dma_handle_t handle, ddi_dma_req_t *dmareq,
9640Sstevel@tonic-gate ddi_dma_cookie_t *cookiep, uint_t *ccountp)
9650Sstevel@tonic-gate {
9660Sstevel@tonic-gate px_t *px_p = DIP_TO_STATE(dip);
9670Sstevel@tonic-gate px_mmu_t *mmu_p = px_p->px_mmu_p;
9680Sstevel@tonic-gate ddi_dma_impl_t *mp = (ddi_dma_impl_t *)handle;
9690Sstevel@tonic-gate int ret;
9700Sstevel@tonic-gate
9710Sstevel@tonic-gate DBG(DBG_DMA_BINDH, dip, "rdip=%s%d mp=%p dmareq=%p\n",
9726313Skrishnae ddi_driver_name(rdip), ddi_get_instance(rdip), mp, dmareq);
9730Sstevel@tonic-gate
974909Segillett if (mp->dmai_flags & PX_DMAI_FLAGS_INUSE)
9750Sstevel@tonic-gate return (DDI_DMA_INUSE);
9760Sstevel@tonic-gate
977909Segillett ASSERT((mp->dmai_flags & ~PX_DMAI_FLAGS_PRESERVE) == 0);
978909Segillett mp->dmai_flags |= PX_DMAI_FLAGS_INUSE;
9790Sstevel@tonic-gate
9800Sstevel@tonic-gate if (ret = px_dma_type(px_p, dmareq, mp))
9810Sstevel@tonic-gate goto err;
9820Sstevel@tonic-gate if (ret = px_dma_pfn(px_p, dmareq, mp))
9830Sstevel@tonic-gate goto err;
9840Sstevel@tonic-gate
9850Sstevel@tonic-gate switch (PX_DMA_TYPE(mp)) {
986909Segillett case PX_DMAI_FLAGS_DVMA:
9870Sstevel@tonic-gate if (ret = px_dvma_win(px_p, dmareq, mp))
9880Sstevel@tonic-gate goto map_err;
9890Sstevel@tonic-gate if (!PX_DMA_CANCACHE(mp)) { /* try fast track */
9900Sstevel@tonic-gate if (PX_DMA_CANFAST(mp)) {
9910Sstevel@tonic-gate if (!px_dvma_map_fast(mmu_p, mp))
9920Sstevel@tonic-gate goto mapped; /*LINTED E_NOP_ELSE_STMT*/
9930Sstevel@tonic-gate } else {
9940Sstevel@tonic-gate PX_DVMA_FASTTRAK_PROF(mp);
9950Sstevel@tonic-gate }
9960Sstevel@tonic-gate }
9970Sstevel@tonic-gate if (ret = px_dvma_map(mp, dmareq, mmu_p))
9980Sstevel@tonic-gate goto map_err;
9990Sstevel@tonic-gate mapped:
10000Sstevel@tonic-gate *ccountp = 1;
10010Sstevel@tonic-gate MAKE_DMA_COOKIE(cookiep, mp->dmai_mapping, mp->dmai_size);
10020Sstevel@tonic-gate break;
1003909Segillett case PX_DMAI_FLAGS_BYPASS:
1004909Segillett case PX_DMAI_FLAGS_PTP:
10050Sstevel@tonic-gate if (ret = px_dma_physwin(px_p, dmareq, mp))
10060Sstevel@tonic-gate goto map_err;
1007909Segillett *ccountp = PX_WINLST(mp)->win_ncookies;
1008909Segillett *cookiep =
1009909Segillett *(ddi_dma_cookie_t *)(PX_WINLST(mp) + 1); /* wholeobj */
10100Sstevel@tonic-gate break;
10110Sstevel@tonic-gate default:
10120Sstevel@tonic-gate cmn_err(CE_PANIC, "%s%d: px_dma_bindhdl(%p): bad dma type",
10136313Skrishnae ddi_driver_name(rdip), ddi_get_instance(rdip), mp);
10140Sstevel@tonic-gate /*NOTREACHED*/
10150Sstevel@tonic-gate }
1016624Sschwartz DBG(DBG_DMA_BINDH, dip, "cookie %" PRIx64 "+%x\n",
10176313Skrishnae cookiep->dmac_address, cookiep->dmac_size);
10180Sstevel@tonic-gate px_dump_dma_handle(DBG_DMA_MAP, dip, mp);
101927Sjchu
102027Sjchu /* insert dma handle into FMA cache */
102112027SStephen.Hanson@Sun.COM if (mp->dmai_attr.dma_attr_flags & DDI_DMA_FLAGERR)
10226313Skrishnae mp->dmai_error.err_cf = px_err_dma_hdl_check;
102327Sjchu
10240Sstevel@tonic-gate return (mp->dmai_nwin == 1 ? DDI_DMA_MAPPED : DDI_DMA_PARTIAL_MAP);
10250Sstevel@tonic-gate map_err:
10260Sstevel@tonic-gate px_dma_freepfn(mp);
10270Sstevel@tonic-gate err:
1028909Segillett mp->dmai_flags &= PX_DMAI_FLAGS_PRESERVE;
10290Sstevel@tonic-gate return (ret);
10300Sstevel@tonic-gate }
10310Sstevel@tonic-gate
10320Sstevel@tonic-gate
10330Sstevel@tonic-gate /*
10340Sstevel@tonic-gate * bus dma unbind handle entry point:
10350Sstevel@tonic-gate */
10360Sstevel@tonic-gate /*ARGSUSED*/
10370Sstevel@tonic-gate int
px_dma_unbindhdl(dev_info_t * dip,dev_info_t * rdip,ddi_dma_handle_t handle)10380Sstevel@tonic-gate px_dma_unbindhdl(dev_info_t *dip, dev_info_t *rdip, ddi_dma_handle_t handle)
10390Sstevel@tonic-gate {
10400Sstevel@tonic-gate ddi_dma_impl_t *mp = (ddi_dma_impl_t *)handle;
10410Sstevel@tonic-gate px_t *px_p = DIP_TO_STATE(dip);
10420Sstevel@tonic-gate px_mmu_t *mmu_p = px_p->px_mmu_p;
10430Sstevel@tonic-gate
10440Sstevel@tonic-gate DBG(DBG_DMA_UNBINDH, dip, "rdip=%s%d, mp=%p\n",
10456313Skrishnae ddi_driver_name(rdip), ddi_get_instance(rdip), handle);
1046909Segillett if ((mp->dmai_flags & PX_DMAI_FLAGS_INUSE) == 0) {
10470Sstevel@tonic-gate DBG(DBG_DMA_UNBINDH, dip, "handle not inuse\n");
10480Sstevel@tonic-gate return (DDI_FAILURE);
10490Sstevel@tonic-gate }
10500Sstevel@tonic-gate
105112027SStephen.Hanson@Sun.COM mp->dmai_error.err_cf = NULL;
105227Sjchu
10530Sstevel@tonic-gate /*
10540Sstevel@tonic-gate * Here if the handle is using the iommu. Unload all the iommu
10550Sstevel@tonic-gate * translations.
10560Sstevel@tonic-gate */
10570Sstevel@tonic-gate switch (PX_DMA_TYPE(mp)) {
1058909Segillett case PX_DMAI_FLAGS_DVMA:
10590Sstevel@tonic-gate px_mmu_unmap_window(mmu_p, mp);
10600Sstevel@tonic-gate px_dvma_unmap(mmu_p, mp);
10610Sstevel@tonic-gate px_dma_freepfn(mp);
10620Sstevel@tonic-gate break;
1063909Segillett case PX_DMAI_FLAGS_BYPASS:
1064909Segillett case PX_DMAI_FLAGS_PTP:
10650Sstevel@tonic-gate px_dma_freewin(mp);
10660Sstevel@tonic-gate break;
10670Sstevel@tonic-gate default:
10680Sstevel@tonic-gate cmn_err(CE_PANIC, "%s%d: px_dma_unbindhdl:bad dma type %p",
10696313Skrishnae ddi_driver_name(rdip), ddi_get_instance(rdip), mp);
10700Sstevel@tonic-gate /*NOTREACHED*/
10710Sstevel@tonic-gate }
10720Sstevel@tonic-gate if (mmu_p->mmu_dvma_clid != 0) {
10730Sstevel@tonic-gate DBG(DBG_DMA_UNBINDH, dip, "run dvma callback\n");
10740Sstevel@tonic-gate ddi_run_callback(&mmu_p->mmu_dvma_clid);
10750Sstevel@tonic-gate }
10760Sstevel@tonic-gate if (px_kmem_clid) {
10770Sstevel@tonic-gate DBG(DBG_DMA_UNBINDH, dip, "run handle callback\n");
10780Sstevel@tonic-gate ddi_run_callback(&px_kmem_clid);
10790Sstevel@tonic-gate }
1080909Segillett mp->dmai_flags &= PX_DMAI_FLAGS_PRESERVE;
108127Sjchu
10820Sstevel@tonic-gate return (DDI_SUCCESS);
10830Sstevel@tonic-gate }
10840Sstevel@tonic-gate
10850Sstevel@tonic-gate /*
10860Sstevel@tonic-gate * bus dma win entry point:
10870Sstevel@tonic-gate */
10880Sstevel@tonic-gate int
px_dma_win(dev_info_t * dip,dev_info_t * rdip,ddi_dma_handle_t handle,uint_t win,off_t * offp,size_t * lenp,ddi_dma_cookie_t * cookiep,uint_t * ccountp)10890Sstevel@tonic-gate px_dma_win(dev_info_t *dip, dev_info_t *rdip,
10900Sstevel@tonic-gate ddi_dma_handle_t handle, uint_t win, off_t *offp,
10910Sstevel@tonic-gate size_t *lenp, ddi_dma_cookie_t *cookiep, uint_t *ccountp)
10920Sstevel@tonic-gate {
10930Sstevel@tonic-gate ddi_dma_impl_t *mp = (ddi_dma_impl_t *)handle;
10940Sstevel@tonic-gate int ret;
10950Sstevel@tonic-gate
10960Sstevel@tonic-gate DBG(DBG_DMA_WIN, dip, "rdip=%s%d\n",
10976313Skrishnae ddi_driver_name(rdip), ddi_get_instance(rdip));
10980Sstevel@tonic-gate
10990Sstevel@tonic-gate px_dump_dma_handle(DBG_DMA_WIN, dip, mp);
11000Sstevel@tonic-gate if (win >= mp->dmai_nwin) {
11010Sstevel@tonic-gate DBG(DBG_DMA_WIN, dip, "%x out of range\n", win);
11020Sstevel@tonic-gate return (DDI_FAILURE);
11030Sstevel@tonic-gate }
11040Sstevel@tonic-gate
11050Sstevel@tonic-gate switch (PX_DMA_TYPE(mp)) {
1106909Segillett case PX_DMAI_FLAGS_DVMA:
11070Sstevel@tonic-gate if (win != PX_DMA_CURWIN(mp)) {
11080Sstevel@tonic-gate px_t *px_p = DIP_TO_STATE(dip);
11090Sstevel@tonic-gate px_mmu_t *mmu_p = px_p->px_mmu_p;
11100Sstevel@tonic-gate px_mmu_unmap_window(mmu_p, mp);
11110Sstevel@tonic-gate
11120Sstevel@tonic-gate /* map_window sets dmai_mapping/size/offset */
11130Sstevel@tonic-gate px_mmu_map_window(mmu_p, mp, win);
11140Sstevel@tonic-gate if ((ret = px_mmu_map_window(mmu_p,
11150Sstevel@tonic-gate mp, win)) != DDI_SUCCESS)
11160Sstevel@tonic-gate return (ret);
11170Sstevel@tonic-gate }
11180Sstevel@tonic-gate if (cookiep)
11190Sstevel@tonic-gate MAKE_DMA_COOKIE(cookiep, mp->dmai_mapping,
11206313Skrishnae mp->dmai_size);
11210Sstevel@tonic-gate if (ccountp)
11220Sstevel@tonic-gate *ccountp = 1;
11230Sstevel@tonic-gate break;
1124909Segillett case PX_DMAI_FLAGS_PTP:
1125909Segillett case PX_DMAI_FLAGS_BYPASS: {
11260Sstevel@tonic-gate int i;
11270Sstevel@tonic-gate ddi_dma_cookie_t *ck_p;
11280Sstevel@tonic-gate px_dma_win_t *win_p = mp->dmai_winlst;
11290Sstevel@tonic-gate
11306313Skrishnae for (i = 0; i < win; win_p = win_p->win_next, i++) {};
11310Sstevel@tonic-gate ck_p = (ddi_dma_cookie_t *)(win_p + 1);
11320Sstevel@tonic-gate *cookiep = *ck_p;
11330Sstevel@tonic-gate mp->dmai_offset = win_p->win_offset;
11340Sstevel@tonic-gate mp->dmai_size = win_p->win_size;
11350Sstevel@tonic-gate mp->dmai_mapping = ck_p->dmac_laddress;
11360Sstevel@tonic-gate mp->dmai_cookie = ck_p + 1;
11370Sstevel@tonic-gate win_p->win_curseg = 0;
11380Sstevel@tonic-gate if (ccountp)
11390Sstevel@tonic-gate *ccountp = win_p->win_ncookies;
11400Sstevel@tonic-gate }
11410Sstevel@tonic-gate break;
11420Sstevel@tonic-gate default:
11430Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d: px_dma_win:bad dma type 0x%x",
11446313Skrishnae ddi_driver_name(rdip), ddi_get_instance(rdip),
11456313Skrishnae PX_DMA_TYPE(mp));
11460Sstevel@tonic-gate return (DDI_FAILURE);
11470Sstevel@tonic-gate }
11480Sstevel@tonic-gate if (cookiep)
11490Sstevel@tonic-gate DBG(DBG_DMA_WIN, dip,
11506313Skrishnae "cookie - dmac_address=%x dmac_size=%x\n",
11516313Skrishnae cookiep->dmac_address, cookiep->dmac_size);
11520Sstevel@tonic-gate if (offp)
11530Sstevel@tonic-gate *offp = (off_t)mp->dmai_offset;
11540Sstevel@tonic-gate if (lenp)
11550Sstevel@tonic-gate *lenp = mp->dmai_size;
11560Sstevel@tonic-gate return (DDI_SUCCESS);
11570Sstevel@tonic-gate }
11580Sstevel@tonic-gate
11590Sstevel@tonic-gate #ifdef DEBUG
11600Sstevel@tonic-gate static char *px_dmactl_str[] = {
11610Sstevel@tonic-gate "DDI_DMA_FREE",
11620Sstevel@tonic-gate "DDI_DMA_SYNC",
11630Sstevel@tonic-gate "DDI_DMA_HTOC",
11640Sstevel@tonic-gate "DDI_DMA_KVADDR",
11650Sstevel@tonic-gate "DDI_DMA_MOVWIN",
11660Sstevel@tonic-gate "DDI_DMA_REPWIN",
11670Sstevel@tonic-gate "DDI_DMA_GETERR",
11680Sstevel@tonic-gate "DDI_DMA_COFF",
11690Sstevel@tonic-gate "DDI_DMA_NEXTWIN",
11700Sstevel@tonic-gate "DDI_DMA_NEXTSEG",
11710Sstevel@tonic-gate "DDI_DMA_SEGTOC",
11720Sstevel@tonic-gate "DDI_DMA_RESERVE",
11730Sstevel@tonic-gate "DDI_DMA_RELEASE",
11740Sstevel@tonic-gate "DDI_DMA_RESETH",
11750Sstevel@tonic-gate "DDI_DMA_CKSYNC",
11760Sstevel@tonic-gate "DDI_DMA_IOPB_ALLOC",
11770Sstevel@tonic-gate "DDI_DMA_IOPB_FREE",
11780Sstevel@tonic-gate "DDI_DMA_SMEM_ALLOC",
11790Sstevel@tonic-gate "DDI_DMA_SMEM_FREE",
11800Sstevel@tonic-gate "DDI_DMA_SET_SBUS64"
11810Sstevel@tonic-gate };
11820Sstevel@tonic-gate #endif /* DEBUG */
11830Sstevel@tonic-gate
11840Sstevel@tonic-gate /*
11850Sstevel@tonic-gate * bus dma control entry point:
11860Sstevel@tonic-gate */
11870Sstevel@tonic-gate /*ARGSUSED*/
11880Sstevel@tonic-gate int
px_dma_ctlops(dev_info_t * dip,dev_info_t * rdip,ddi_dma_handle_t handle,enum ddi_dma_ctlops cmd,off_t * offp,size_t * lenp,caddr_t * objp,uint_t cache_flags)11890Sstevel@tonic-gate px_dma_ctlops(dev_info_t *dip, dev_info_t *rdip, ddi_dma_handle_t handle,
11900Sstevel@tonic-gate enum ddi_dma_ctlops cmd, off_t *offp, size_t *lenp, caddr_t *objp,
11910Sstevel@tonic-gate uint_t cache_flags)
11920Sstevel@tonic-gate {
11930Sstevel@tonic-gate ddi_dma_impl_t *mp = (ddi_dma_impl_t *)handle;
11940Sstevel@tonic-gate
11950Sstevel@tonic-gate #ifdef DEBUG
11960Sstevel@tonic-gate DBG(DBG_DMA_CTL, dip, "%s: rdip=%s%d\n", px_dmactl_str[cmd],
11976313Skrishnae ddi_driver_name(rdip), ddi_get_instance(rdip));
11980Sstevel@tonic-gate #endif /* DEBUG */
11990Sstevel@tonic-gate
12000Sstevel@tonic-gate switch (cmd) {
12010Sstevel@tonic-gate case DDI_DMA_FREE:
12020Sstevel@tonic-gate (void) px_dma_unbindhdl(dip, rdip, handle);
12030Sstevel@tonic-gate (void) px_dma_freehdl(dip, rdip, handle);
12040Sstevel@tonic-gate return (DDI_SUCCESS);
12050Sstevel@tonic-gate case DDI_DMA_RESERVE: {
12060Sstevel@tonic-gate px_t *px_p = DIP_TO_STATE(dip);
12070Sstevel@tonic-gate return (px_fdvma_reserve(dip, rdip, px_p,
12086313Skrishnae (ddi_dma_req_t *)offp, (ddi_dma_handle_t *)objp));
12090Sstevel@tonic-gate }
12100Sstevel@tonic-gate case DDI_DMA_RELEASE: {
12110Sstevel@tonic-gate px_t *px_p = DIP_TO_STATE(dip);
12120Sstevel@tonic-gate return (px_fdvma_release(dip, px_p, mp));
12130Sstevel@tonic-gate }
12140Sstevel@tonic-gate default:
12150Sstevel@tonic-gate break;
12160Sstevel@tonic-gate }
12170Sstevel@tonic-gate
12180Sstevel@tonic-gate switch (PX_DMA_TYPE(mp)) {
1219909Segillett case PX_DMAI_FLAGS_DVMA:
12200Sstevel@tonic-gate return (px_dvma_ctl(dip, rdip, mp, cmd, offp, lenp, objp,
12216313Skrishnae cache_flags));
1222909Segillett case PX_DMAI_FLAGS_PTP:
1223909Segillett case PX_DMAI_FLAGS_BYPASS:
12240Sstevel@tonic-gate return (px_dma_ctl(dip, rdip, mp, cmd, offp, lenp, objp,
12256313Skrishnae cache_flags));
12260Sstevel@tonic-gate default:
12270Sstevel@tonic-gate cmn_err(CE_PANIC, "%s%d: px_dma_ctlops(%x):bad dma type %x",
12286313Skrishnae ddi_driver_name(rdip), ddi_get_instance(rdip), cmd,
12296313Skrishnae mp->dmai_flags);
12300Sstevel@tonic-gate /*NOTREACHED*/
12310Sstevel@tonic-gate }
1232671Skrishnae return (0);
12330Sstevel@tonic-gate }
12340Sstevel@tonic-gate
12350Sstevel@tonic-gate /*
12360Sstevel@tonic-gate * control ops entry point:
12370Sstevel@tonic-gate *
12380Sstevel@tonic-gate * Requests handled completely:
12390Sstevel@tonic-gate * DDI_CTLOPS_INITCHILD see init_child() for details
12400Sstevel@tonic-gate * DDI_CTLOPS_UNINITCHILD
12410Sstevel@tonic-gate * DDI_CTLOPS_REPORTDEV see report_dev() for details
12420Sstevel@tonic-gate * DDI_CTLOPS_IOMIN cache line size if streaming otherwise 1
12430Sstevel@tonic-gate * DDI_CTLOPS_REGSIZE
12440Sstevel@tonic-gate * DDI_CTLOPS_NREGS
12450Sstevel@tonic-gate * DDI_CTLOPS_DVMAPAGESIZE
12460Sstevel@tonic-gate * DDI_CTLOPS_POKE
12470Sstevel@tonic-gate * DDI_CTLOPS_PEEK
12480Sstevel@tonic-gate *
12490Sstevel@tonic-gate * All others passed to parent.
12500Sstevel@tonic-gate */
12510Sstevel@tonic-gate int
px_ctlops(dev_info_t * dip,dev_info_t * rdip,ddi_ctl_enum_t op,void * arg,void * result)12520Sstevel@tonic-gate px_ctlops(dev_info_t *dip, dev_info_t *rdip,
12530Sstevel@tonic-gate ddi_ctl_enum_t op, void *arg, void *result)
12540Sstevel@tonic-gate {
12550Sstevel@tonic-gate px_t *px_p = DIP_TO_STATE(dip);
12560Sstevel@tonic-gate struct detachspec *ds;
12570Sstevel@tonic-gate struct attachspec *as;
12580Sstevel@tonic-gate
12590Sstevel@tonic-gate switch (op) {
12600Sstevel@tonic-gate case DDI_CTLOPS_INITCHILD:
12610Sstevel@tonic-gate return (px_init_child(px_p, (dev_info_t *)arg));
12620Sstevel@tonic-gate
12630Sstevel@tonic-gate case DDI_CTLOPS_UNINITCHILD:
12640Sstevel@tonic-gate return (px_uninit_child(px_p, (dev_info_t *)arg));
12650Sstevel@tonic-gate
12660Sstevel@tonic-gate case DDI_CTLOPS_ATTACH:
12673421Sjchu if (!pcie_is_child(dip, rdip))
12683421Sjchu return (DDI_SUCCESS);
12693421Sjchu
12700Sstevel@tonic-gate as = (struct attachspec *)arg;
12710Sstevel@tonic-gate switch (as->when) {
12720Sstevel@tonic-gate case DDI_PRE:
12730Sstevel@tonic-gate if (as->cmd == DDI_ATTACH) {
12740Sstevel@tonic-gate DBG(DBG_PWR, dip, "PRE_ATTACH for %s@%d\n",
12750Sstevel@tonic-gate ddi_driver_name(rdip),
12760Sstevel@tonic-gate ddi_get_instance(rdip));
12770Sstevel@tonic-gate return (pcie_pm_hold(dip));
12780Sstevel@tonic-gate }
1279383Set142600 if (as->cmd == DDI_RESUME) {
1280383Set142600 DBG(DBG_PWR, dip, "PRE_RESUME for %s@%d\n",
1281383Set142600 ddi_driver_name(rdip),
1282383Set142600 ddi_get_instance(rdip));
1283383Set142600
12846313Skrishnae pcie_clear_errors(rdip);
1285383Set142600 }
12860Sstevel@tonic-gate return (DDI_SUCCESS);
12870Sstevel@tonic-gate
12880Sstevel@tonic-gate case DDI_POST:
12890Sstevel@tonic-gate DBG(DBG_PWR, dip, "POST_ATTACH for %s@%d\n",
12900Sstevel@tonic-gate ddi_driver_name(rdip), ddi_get_instance(rdip));
129110768SRamesh.Chitrothu@Sun.COM if (as->cmd == DDI_ATTACH &&
129210768SRamesh.Chitrothu@Sun.COM as->result != DDI_SUCCESS) {
129310768SRamesh.Chitrothu@Sun.COM /*
129410768SRamesh.Chitrothu@Sun.COM * Attach failed for the child device. The child
129510768SRamesh.Chitrothu@Sun.COM * driver may have made PM calls before the
129610768SRamesh.Chitrothu@Sun.COM * attach failed. pcie_pm_remove_child() should
129710768SRamesh.Chitrothu@Sun.COM * cleanup PM state and holds (if any)
129810768SRamesh.Chitrothu@Sun.COM * associated with the child device.
129910768SRamesh.Chitrothu@Sun.COM */
130010768SRamesh.Chitrothu@Sun.COM return (pcie_pm_remove_child(dip, rdip));
130110768SRamesh.Chitrothu@Sun.COM }
13022738Skrishnae
13034005Skrishnae if (as->result == DDI_SUCCESS)
13044005Skrishnae pf_init(rdip, (void *)px_p->px_fm_ibc, as->cmd);
13053274Set142600
13062738Skrishnae (void) pcie_postattach_child(rdip);
13072738Skrishnae
13080Sstevel@tonic-gate return (DDI_SUCCESS);
13090Sstevel@tonic-gate default:
13100Sstevel@tonic-gate break;
13110Sstevel@tonic-gate }
13120Sstevel@tonic-gate break;
13130Sstevel@tonic-gate
13140Sstevel@tonic-gate case DDI_CTLOPS_DETACH:
13153714Sjchu if (!pcie_is_child(dip, rdip))
13163714Sjchu return (DDI_SUCCESS);
13173714Sjchu
13180Sstevel@tonic-gate ds = (struct detachspec *)arg;
13190Sstevel@tonic-gate switch (ds->when) {
13200Sstevel@tonic-gate case DDI_POST:
13210Sstevel@tonic-gate if (ds->cmd == DDI_DETACH &&
13220Sstevel@tonic-gate ds->result == DDI_SUCCESS) {
13230Sstevel@tonic-gate DBG(DBG_PWR, dip, "POST_DETACH for %s@%d\n",
13240Sstevel@tonic-gate ddi_driver_name(rdip),
13250Sstevel@tonic-gate ddi_get_instance(rdip));
13260Sstevel@tonic-gate return (pcie_pm_remove_child(dip, rdip));
13270Sstevel@tonic-gate }
13280Sstevel@tonic-gate return (DDI_SUCCESS);
13293274Set142600 case DDI_PRE:
13303756Skrishnae pf_fini(rdip, ds->cmd);
13313274Set142600 return (DDI_SUCCESS);
13320Sstevel@tonic-gate default:
13330Sstevel@tonic-gate break;
13340Sstevel@tonic-gate }
13350Sstevel@tonic-gate break;
13360Sstevel@tonic-gate
13370Sstevel@tonic-gate case DDI_CTLOPS_REPORTDEV:
133811596SJason.Beloro@Sun.COM if (ddi_get_parent(rdip) == dip)
133911596SJason.Beloro@Sun.COM return (px_report_dev(rdip));
134011596SJason.Beloro@Sun.COM
134111596SJason.Beloro@Sun.COM (void) px_lib_fabric_sync(rdip);
134211596SJason.Beloro@Sun.COM return (DDI_SUCCESS);
13430Sstevel@tonic-gate
13440Sstevel@tonic-gate case DDI_CTLOPS_IOMIN:
13450Sstevel@tonic-gate return (DDI_SUCCESS);
13460Sstevel@tonic-gate
13470Sstevel@tonic-gate case DDI_CTLOPS_REGSIZE:
13480Sstevel@tonic-gate *((off_t *)result) = px_get_reg_set_size(rdip, *((int *)arg));
134927Sjchu return (*((off_t *)result) == 0 ? DDI_FAILURE : DDI_SUCCESS);
13500Sstevel@tonic-gate
13510Sstevel@tonic-gate case DDI_CTLOPS_NREGS:
13520Sstevel@tonic-gate *((uint_t *)result) = px_get_nreg_set(rdip);
13530Sstevel@tonic-gate return (DDI_SUCCESS);
13540Sstevel@tonic-gate
13550Sstevel@tonic-gate case DDI_CTLOPS_DVMAPAGESIZE:
13560Sstevel@tonic-gate *((ulong_t *)result) = MMU_PAGE_SIZE;
13570Sstevel@tonic-gate return (DDI_SUCCESS);
13580Sstevel@tonic-gate
13590Sstevel@tonic-gate case DDI_CTLOPS_POKE: /* platform dependent implementation. */
13600Sstevel@tonic-gate return (px_lib_ctlops_poke(dip, rdip,
13610Sstevel@tonic-gate (peekpoke_ctlops_t *)arg));
13620Sstevel@tonic-gate
13630Sstevel@tonic-gate case DDI_CTLOPS_PEEK: /* platform dependent implementation. */
13640Sstevel@tonic-gate return (px_lib_ctlops_peek(dip, rdip,
13650Sstevel@tonic-gate (peekpoke_ctlops_t *)arg, result));
13660Sstevel@tonic-gate
13670Sstevel@tonic-gate case DDI_CTLOPS_POWER:
13680Sstevel@tonic-gate default:
13690Sstevel@tonic-gate break;
13700Sstevel@tonic-gate }
13710Sstevel@tonic-gate
13720Sstevel@tonic-gate /*
13730Sstevel@tonic-gate * Now pass the request up to our parent.
13740Sstevel@tonic-gate */
13750Sstevel@tonic-gate DBG(DBG_CTLOPS, dip, "passing request to parent: rdip=%s%d\n",
13766313Skrishnae ddi_driver_name(rdip), ddi_get_instance(rdip));
13770Sstevel@tonic-gate return (ddi_ctlops(dip, rdip, op, arg, result));
13780Sstevel@tonic-gate }
13790Sstevel@tonic-gate
13800Sstevel@tonic-gate /* ARGSUSED */
13810Sstevel@tonic-gate int
px_intr_ops(dev_info_t * dip,dev_info_t * rdip,ddi_intr_op_t intr_op,ddi_intr_handle_impl_t * hdlp,void * result)13820Sstevel@tonic-gate px_intr_ops(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t intr_op,
13830Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp, void *result)
13840Sstevel@tonic-gate {
13850Sstevel@tonic-gate int intr_types, ret = DDI_SUCCESS;
138611596SJason.Beloro@Sun.COM px_t *px_p = DIP_TO_STATE(dip);
13870Sstevel@tonic-gate
13880Sstevel@tonic-gate DBG(DBG_INTROPS, dip, "px_intr_ops: rdip=%s%d\n",
13890Sstevel@tonic-gate ddi_driver_name(rdip), ddi_get_instance(rdip));
13900Sstevel@tonic-gate
13910Sstevel@tonic-gate /* Process DDI_INTROP_SUPPORTED_TYPES request here */
13920Sstevel@tonic-gate if (intr_op == DDI_INTROP_SUPPORTED_TYPES) {
13932580Sanish *(int *)result = i_ddi_get_intx_nintrs(rdip) ?
13940Sstevel@tonic-gate DDI_INTR_TYPE_FIXED : 0;
13950Sstevel@tonic-gate
13960Sstevel@tonic-gate if ((pci_msi_get_supported_type(rdip,
13970Sstevel@tonic-gate &intr_types)) == DDI_SUCCESS) {
13980Sstevel@tonic-gate /*
13990Sstevel@tonic-gate * Double check supported interrupt types vs.
14000Sstevel@tonic-gate * what the host bridge supports.
14010Sstevel@tonic-gate */
14021725Segillett *(int *)result |= intr_types;
14030Sstevel@tonic-gate }
14040Sstevel@tonic-gate
140512341SDavid.Woods@Sun.COM *(int *)result &=
140612341SDavid.Woods@Sun.COM (px_force_intx_support ?
140712341SDavid.Woods@Sun.COM (px_p->px_supp_intr_types | DDI_INTR_TYPE_FIXED) :
140812341SDavid.Woods@Sun.COM px_p->px_supp_intr_types);
140911596SJason.Beloro@Sun.COM return (*(int *)result ? DDI_SUCCESS : DDI_FAILURE);
14100Sstevel@tonic-gate }
14110Sstevel@tonic-gate
14120Sstevel@tonic-gate /*
14130Sstevel@tonic-gate * PCI-E nexus driver supports fixed, MSI and MSI-X interrupts.
14140Sstevel@tonic-gate * Return failure if interrupt type is not supported.
14150Sstevel@tonic-gate */
14160Sstevel@tonic-gate switch (hdlp->ih_type) {
14170Sstevel@tonic-gate case DDI_INTR_TYPE_FIXED:
14180Sstevel@tonic-gate ret = px_intx_ops(dip, rdip, intr_op, hdlp, result);
14190Sstevel@tonic-gate break;
14200Sstevel@tonic-gate case DDI_INTR_TYPE_MSI:
14210Sstevel@tonic-gate case DDI_INTR_TYPE_MSIX:
14220Sstevel@tonic-gate ret = px_msix_ops(dip, rdip, intr_op, hdlp, result);
14230Sstevel@tonic-gate break;
14240Sstevel@tonic-gate default:
14250Sstevel@tonic-gate ret = DDI_ENOTSUP;
14260Sstevel@tonic-gate break;
14270Sstevel@tonic-gate }
14280Sstevel@tonic-gate
14290Sstevel@tonic-gate return (ret);
14300Sstevel@tonic-gate }
14311531Skini
14327596SAlan.Adamson@Sun.COM static void
px_set_mps(px_t * px_p)14337596SAlan.Adamson@Sun.COM px_set_mps(px_t *px_p)
14347596SAlan.Adamson@Sun.COM {
14357596SAlan.Adamson@Sun.COM dev_info_t *dip;
14367596SAlan.Adamson@Sun.COM pcie_bus_t *bus_p;
14377596SAlan.Adamson@Sun.COM int max_supported;
14387596SAlan.Adamson@Sun.COM
14397596SAlan.Adamson@Sun.COM dip = px_p->px_dip;
14407596SAlan.Adamson@Sun.COM bus_p = PCIE_DIP2BUS(dip);
14417596SAlan.Adamson@Sun.COM
14427596SAlan.Adamson@Sun.COM bus_p->bus_mps = -1;
14437596SAlan.Adamson@Sun.COM
14447596SAlan.Adamson@Sun.COM if (pcie_root_port(dip) == DDI_FAILURE) {
14457596SAlan.Adamson@Sun.COM if (px_lib_get_root_complex_mps(px_p, dip,
14467596SAlan.Adamson@Sun.COM &max_supported) < 0) {
14477596SAlan.Adamson@Sun.COM
14487596SAlan.Adamson@Sun.COM DBG(DBG_MPS, dip, "MPS: Can not get RC MPS\n");
14497596SAlan.Adamson@Sun.COM return;
14507596SAlan.Adamson@Sun.COM }
14517596SAlan.Adamson@Sun.COM
14527596SAlan.Adamson@Sun.COM DBG(DBG_MPS, dip, "MPS: Root Complex MPS Cap of = %x\n",
14537596SAlan.Adamson@Sun.COM max_supported);
14547596SAlan.Adamson@Sun.COM
14557596SAlan.Adamson@Sun.COM if (pcie_max_mps < max_supported)
14567596SAlan.Adamson@Sun.COM max_supported = pcie_max_mps;
14577596SAlan.Adamson@Sun.COM
14587596SAlan.Adamson@Sun.COM (void) pcie_get_fabric_mps(dip, ddi_get_child(dip),
14597596SAlan.Adamson@Sun.COM &max_supported);
14607596SAlan.Adamson@Sun.COM
14617596SAlan.Adamson@Sun.COM bus_p->bus_mps = max_supported;
14627596SAlan.Adamson@Sun.COM
14637596SAlan.Adamson@Sun.COM (void) px_lib_set_root_complex_mps(px_p, dip, bus_p->bus_mps);
14647596SAlan.Adamson@Sun.COM
14657596SAlan.Adamson@Sun.COM DBG(DBG_MPS, dip, "MPS: Root Complex MPS Set to = %x\n",
14667596SAlan.Adamson@Sun.COM bus_p->bus_mps);
14677596SAlan.Adamson@Sun.COM }
14687596SAlan.Adamson@Sun.COM }
1469