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 50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 70Sstevel@tonic-gate * with the License. 80Sstevel@tonic-gate * 90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 110Sstevel@tonic-gate * See the License for the specific language governing permissions 120Sstevel@tonic-gate * and limitations under the License. 130Sstevel@tonic-gate * 140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 190Sstevel@tonic-gate * 200Sstevel@tonic-gate * CDDL HEADER END 210Sstevel@tonic-gate */ 220Sstevel@tonic-gate /* 230Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 280Sstevel@tonic-gate 290Sstevel@tonic-gate /* 300Sstevel@tonic-gate * Host to PCI local bus driver 310Sstevel@tonic-gate */ 320Sstevel@tonic-gate 330Sstevel@tonic-gate #include <sys/conf.h> 340Sstevel@tonic-gate #include <sys/kmem.h> 350Sstevel@tonic-gate #include <sys/debug.h> 360Sstevel@tonic-gate #include <sys/modctl.h> 370Sstevel@tonic-gate #include <sys/autoconf.h> 380Sstevel@tonic-gate #include <sys/ddi_impldefs.h> 390Sstevel@tonic-gate #include <sys/ddi_subrdefs.h> 400Sstevel@tonic-gate #include <sys/pci.h> 410Sstevel@tonic-gate #include <sys/pci_impl.h> 420Sstevel@tonic-gate #include <sys/ddi.h> 430Sstevel@tonic-gate #include <sys/sunddi.h> 440Sstevel@tonic-gate #include <sys/sunndi.h> 450Sstevel@tonic-gate #include <sys/hotplug/pci/pcihp.h> 460Sstevel@tonic-gate #include <sys/pci_cfgspace.h> 470Sstevel@tonic-gate #include <sys/avintr.h> 480Sstevel@tonic-gate #include <sys/psm.h> 490Sstevel@tonic-gate #include <sys/pci_intr_lib.h> 500Sstevel@tonic-gate #include <sys/policy.h> 510Sstevel@tonic-gate #include <sys/pci_tools.h> 520Sstevel@tonic-gate #include <sys/pci_tools_var.h> 530Sstevel@tonic-gate #include "pci_var.h" 540Sstevel@tonic-gate 550Sstevel@tonic-gate /* Save minimal state. */ 560Sstevel@tonic-gate void *pci_statep; 570Sstevel@tonic-gate 580Sstevel@tonic-gate /* 590Sstevel@tonic-gate * Bus Operation functions 600Sstevel@tonic-gate */ 610Sstevel@tonic-gate static int pci_bus_map(dev_info_t *, dev_info_t *, ddi_map_req_t *, 620Sstevel@tonic-gate off_t, off_t, caddr_t *); 630Sstevel@tonic-gate static int pci_ctlops(dev_info_t *, dev_info_t *, ddi_ctl_enum_t, 640Sstevel@tonic-gate void *, void *); 650Sstevel@tonic-gate static int pci_intr_ops(dev_info_t *, dev_info_t *, ddi_intr_op_t, 660Sstevel@tonic-gate ddi_intr_handle_impl_t *, void *); 670Sstevel@tonic-gate static int pci_get_priority(dev_info_t *, int, int *); 680Sstevel@tonic-gate static int pci_get_nintrs(dev_info_t *, int, int *); 690Sstevel@tonic-gate static int pci_enable_intr(dev_info_t *, dev_info_t *, 700Sstevel@tonic-gate ddi_intr_handle_impl_t *, uint32_t); 710Sstevel@tonic-gate static void pci_disable_intr(dev_info_t *, dev_info_t *, 720Sstevel@tonic-gate ddi_intr_handle_impl_t *, uint32_t); 730Sstevel@tonic-gate 740Sstevel@tonic-gate /* Extern decalrations */ 750Sstevel@tonic-gate extern int (*psm_intr_ops)(dev_info_t *, ddi_intr_handle_impl_t *, 760Sstevel@tonic-gate psm_intr_op_t, int *); 770Sstevel@tonic-gate 780Sstevel@tonic-gate struct bus_ops pci_bus_ops = { 790Sstevel@tonic-gate BUSO_REV, 800Sstevel@tonic-gate pci_bus_map, 810Sstevel@tonic-gate NULL, 820Sstevel@tonic-gate NULL, 830Sstevel@tonic-gate NULL, 840Sstevel@tonic-gate i_ddi_map_fault, 850Sstevel@tonic-gate ddi_dma_map, 860Sstevel@tonic-gate ddi_dma_allochdl, 870Sstevel@tonic-gate ddi_dma_freehdl, 880Sstevel@tonic-gate ddi_dma_bindhdl, 890Sstevel@tonic-gate ddi_dma_unbindhdl, 900Sstevel@tonic-gate ddi_dma_flush, 910Sstevel@tonic-gate ddi_dma_win, 920Sstevel@tonic-gate ddi_dma_mctl, 930Sstevel@tonic-gate pci_ctlops, 940Sstevel@tonic-gate ddi_bus_prop_op, 950Sstevel@tonic-gate 0, /* (*bus_get_eventcookie)(); */ 960Sstevel@tonic-gate 0, /* (*bus_add_eventcall)(); */ 970Sstevel@tonic-gate 0, /* (*bus_remove_eventcall)(); */ 980Sstevel@tonic-gate 0, /* (*bus_post_event)(); */ 990Sstevel@tonic-gate 0, /* (*bus_intr_ctl)(); */ 1000Sstevel@tonic-gate 0, /* (*bus_config)(); */ 1010Sstevel@tonic-gate 0, /* (*bus_unconfig)(); */ 1020Sstevel@tonic-gate NULL, /* (*bus_fm_init)(); */ 1030Sstevel@tonic-gate NULL, /* (*bus_fm_fini)(); */ 1040Sstevel@tonic-gate NULL, /* (*bus_fm_access_enter)(); */ 1050Sstevel@tonic-gate NULL, /* (*bus_fm_access_exit)(); */ 1060Sstevel@tonic-gate NULL, /* (*bus_power)(); */ 1070Sstevel@tonic-gate pci_intr_ops /* (*bus_intr_op)(); */ 1080Sstevel@tonic-gate }; 1090Sstevel@tonic-gate 1100Sstevel@tonic-gate static int pci_open(dev_t *devp, int flags, int otyp, cred_t *credp); 1110Sstevel@tonic-gate static int pci_close(dev_t dev, int flags, int otyp, cred_t *credp); 1120Sstevel@tonic-gate static int pci_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, cred_t *credp, 1130Sstevel@tonic-gate int *rvalp); 1140Sstevel@tonic-gate static int pci_prop_op(dev_t dev, dev_info_t *devi, ddi_prop_op_t prop_op, 1150Sstevel@tonic-gate int flags, char *name, caddr_t valuep, int *lengthp); 1160Sstevel@tonic-gate 1170Sstevel@tonic-gate /* 1180Sstevel@tonic-gate * One goal here is to leverage off of the pcihp.c source without making 1190Sstevel@tonic-gate * changes to it. Call into it's cb_ops directly if needed, piggybacking 1200Sstevel@tonic-gate * anything else needed by the pci_tools.c module. Only pci_tools and pcihp 121*117Sschwartz * will be opening PCI nexus driver file descriptors. 1220Sstevel@tonic-gate */ 1230Sstevel@tonic-gate 1240Sstevel@tonic-gate struct cb_ops pci_cb_ops = { 1250Sstevel@tonic-gate pci_open, /* open */ 1260Sstevel@tonic-gate pci_close, /* close */ 1270Sstevel@tonic-gate nodev, /* strategy */ 1280Sstevel@tonic-gate nodev, /* print */ 1290Sstevel@tonic-gate nodev, /* dump */ 1300Sstevel@tonic-gate nodev, /* read */ 1310Sstevel@tonic-gate nodev, /* write */ 1320Sstevel@tonic-gate pci_ioctl, /* ioctl */ 1330Sstevel@tonic-gate nodev, /* devmap */ 1340Sstevel@tonic-gate nodev, /* mmap */ 1350Sstevel@tonic-gate nodev, /* segmap */ 1360Sstevel@tonic-gate nochpoll, /* poll */ 1370Sstevel@tonic-gate pci_prop_op, /* cb_prop_op */ 1380Sstevel@tonic-gate NULL, /* streamtab */ 1390Sstevel@tonic-gate D_NEW | D_MP | D_HOTPLUG, /* Driver compatibility flag */ 1400Sstevel@tonic-gate CB_REV, /* rev */ 1410Sstevel@tonic-gate nodev, /* int (*cb_aread)() */ 1420Sstevel@tonic-gate nodev /* int (*cb_awrite)() */ 1430Sstevel@tonic-gate }; 1440Sstevel@tonic-gate 1450Sstevel@tonic-gate /* 1460Sstevel@tonic-gate * Device Node Operation functions 1470Sstevel@tonic-gate */ 1480Sstevel@tonic-gate static int pci_info(dev_info_t *devi, ddi_info_cmd_t cmd, void *arg, 1490Sstevel@tonic-gate void **result); 1500Sstevel@tonic-gate static int pci_attach(dev_info_t *devi, ddi_attach_cmd_t cmd); 1510Sstevel@tonic-gate static int pci_detach(dev_info_t *devi, ddi_detach_cmd_t cmd); 1520Sstevel@tonic-gate 1530Sstevel@tonic-gate struct dev_ops pci_ops = { 1540Sstevel@tonic-gate DEVO_REV, /* devo_rev */ 1550Sstevel@tonic-gate 0, /* refcnt */ 1560Sstevel@tonic-gate pci_info, /* info */ 1570Sstevel@tonic-gate nulldev, /* identify */ 1580Sstevel@tonic-gate nulldev, /* probe */ 1590Sstevel@tonic-gate pci_attach, /* attach */ 1600Sstevel@tonic-gate pci_detach, /* detach */ 1610Sstevel@tonic-gate nulldev, /* reset */ 1620Sstevel@tonic-gate &pci_cb_ops, /* driver operations */ 1630Sstevel@tonic-gate &pci_bus_ops /* bus operations */ 1640Sstevel@tonic-gate }; 1650Sstevel@tonic-gate 1660Sstevel@tonic-gate /* 1670Sstevel@tonic-gate * Internal routines in support of particular pci_ctlops. 1680Sstevel@tonic-gate */ 1690Sstevel@tonic-gate static int pci_removechild(dev_info_t *child); 1700Sstevel@tonic-gate static int pci_initchild(dev_info_t *child); 1710Sstevel@tonic-gate 1720Sstevel@tonic-gate /* 173*117Sschwartz * Miscellaneous internal functions 1740Sstevel@tonic-gate */ 1750Sstevel@tonic-gate static int pci_get_reg_prop(dev_info_t *dip, pci_regspec_t *pci_rp); 1760Sstevel@tonic-gate 1770Sstevel@tonic-gate /* 1780Sstevel@tonic-gate * These are the access routines. The pci_bus_map sets the handle 1790Sstevel@tonic-gate * to point to these. 1800Sstevel@tonic-gate */ 1810Sstevel@tonic-gate static uint8_t pci_config_rd8(ddi_acc_impl_t *hdlp, uint8_t *addr); 1820Sstevel@tonic-gate static uint16_t pci_config_rd16(ddi_acc_impl_t *hdlp, uint16_t *addr); 1830Sstevel@tonic-gate static uint32_t pci_config_rd32(ddi_acc_impl_t *hdlp, uint32_t *addr); 1840Sstevel@tonic-gate static uint64_t pci_config_rd64(ddi_acc_impl_t *hdlp, uint64_t *addr); 1850Sstevel@tonic-gate 1860Sstevel@tonic-gate static void pci_config_wr8(ddi_acc_impl_t *hdlp, uint8_t *addr, 1870Sstevel@tonic-gate uint8_t value); 1880Sstevel@tonic-gate static void pci_config_wr16(ddi_acc_impl_t *hdlp, uint16_t *addr, 1890Sstevel@tonic-gate uint16_t value); 1900Sstevel@tonic-gate static void pci_config_wr32(ddi_acc_impl_t *hdlp, uint32_t *addr, 1910Sstevel@tonic-gate uint32_t value); 1920Sstevel@tonic-gate static void pci_config_wr64(ddi_acc_impl_t *hdlp, uint64_t *addr, 1930Sstevel@tonic-gate uint64_t value); 1940Sstevel@tonic-gate 1950Sstevel@tonic-gate static void pci_config_rep_rd8(ddi_acc_impl_t *hdlp, uint8_t *host_addr, 1960Sstevel@tonic-gate uint8_t *dev_addr, size_t repcount, uint_t flags); 1970Sstevel@tonic-gate static void pci_config_rep_rd16(ddi_acc_impl_t *hdlp, uint16_t *host_addr, 1980Sstevel@tonic-gate uint16_t *dev_addr, size_t repcount, uint_t flags); 1990Sstevel@tonic-gate static void pci_config_rep_rd32(ddi_acc_impl_t *hdlp, uint32_t *host_addr, 2000Sstevel@tonic-gate uint32_t *dev_addr, size_t repcount, uint_t flags); 2010Sstevel@tonic-gate static void pci_config_rep_rd64(ddi_acc_impl_t *hdlp, uint64_t *host_addr, 2020Sstevel@tonic-gate uint64_t *dev_addr, size_t repcount, uint_t flags); 2030Sstevel@tonic-gate 2040Sstevel@tonic-gate static void pci_config_rep_wr8(ddi_acc_impl_t *hdlp, uint8_t *host_addr, 2050Sstevel@tonic-gate uint8_t *dev_addr, size_t repcount, uint_t flags); 2060Sstevel@tonic-gate static void pci_config_rep_wr16(ddi_acc_impl_t *hdlp, uint16_t *host_addr, 2070Sstevel@tonic-gate uint16_t *dev_addr, size_t repcount, uint_t flags); 2080Sstevel@tonic-gate static void pci_config_rep_wr32(ddi_acc_impl_t *hdlp, uint32_t *host_addr, 2090Sstevel@tonic-gate uint32_t *dev_addr, size_t repcount, uint_t flags); 2100Sstevel@tonic-gate static void pci_config_rep_wr64(ddi_acc_impl_t *hdlp, uint64_t *host_addr, 2110Sstevel@tonic-gate uint64_t *dev_addr, size_t repcount, uint_t flags); 2120Sstevel@tonic-gate 2130Sstevel@tonic-gate /* 2140Sstevel@tonic-gate * Module linkage information for the kernel. 2150Sstevel@tonic-gate */ 2160Sstevel@tonic-gate 2170Sstevel@tonic-gate static struct modldrv modldrv = { 2180Sstevel@tonic-gate &mod_driverops, /* Type of module */ 2190Sstevel@tonic-gate "host to PCI nexus driver %I%", 2200Sstevel@tonic-gate &pci_ops, /* driver ops */ 2210Sstevel@tonic-gate }; 2220Sstevel@tonic-gate 2230Sstevel@tonic-gate static struct modlinkage modlinkage = { 2240Sstevel@tonic-gate MODREV_1, 2250Sstevel@tonic-gate (void *)&modldrv, 2260Sstevel@tonic-gate NULL 2270Sstevel@tonic-gate }; 2280Sstevel@tonic-gate 2290Sstevel@tonic-gate int 2300Sstevel@tonic-gate _init(void) 2310Sstevel@tonic-gate { 2320Sstevel@tonic-gate int e; 2330Sstevel@tonic-gate 2340Sstevel@tonic-gate /* 2350Sstevel@tonic-gate * Initialize per-pci bus soft state pointer. 2360Sstevel@tonic-gate */ 2370Sstevel@tonic-gate e = ddi_soft_state_init(&pci_statep, sizeof (pci_state_t), 1); 2380Sstevel@tonic-gate if (e != 0) 2390Sstevel@tonic-gate return (e); 2400Sstevel@tonic-gate 2410Sstevel@tonic-gate if ((e = mod_install(&modlinkage)) != 0) 2420Sstevel@tonic-gate ddi_soft_state_fini(&pci_statep); 2430Sstevel@tonic-gate 2440Sstevel@tonic-gate return (e); 2450Sstevel@tonic-gate } 2460Sstevel@tonic-gate 2470Sstevel@tonic-gate int 2480Sstevel@tonic-gate _fini(void) 2490Sstevel@tonic-gate { 2500Sstevel@tonic-gate int rc; 2510Sstevel@tonic-gate 2520Sstevel@tonic-gate rc = mod_remove(&modlinkage); 2530Sstevel@tonic-gate if (rc != 0) 2540Sstevel@tonic-gate return (rc); 2550Sstevel@tonic-gate 2560Sstevel@tonic-gate ddi_soft_state_fini(&pci_statep); 2570Sstevel@tonic-gate 2580Sstevel@tonic-gate return (rc); 2590Sstevel@tonic-gate } 2600Sstevel@tonic-gate 2610Sstevel@tonic-gate int 2620Sstevel@tonic-gate _info(struct modinfo *modinfop) 2630Sstevel@tonic-gate { 2640Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 2650Sstevel@tonic-gate } 2660Sstevel@tonic-gate 2670Sstevel@tonic-gate /*ARGSUSED*/ 2680Sstevel@tonic-gate static int 2690Sstevel@tonic-gate pci_attach(dev_info_t *devi, ddi_attach_cmd_t cmd) 2700Sstevel@tonic-gate { 2710Sstevel@tonic-gate /* 2720Sstevel@tonic-gate * Use the minor number as constructed by pcihp, as the index value to 2730Sstevel@tonic-gate * ddi_soft_state_zalloc. 2740Sstevel@tonic-gate */ 275*117Sschwartz int instance = ddi_get_instance(devi); 2760Sstevel@tonic-gate pci_state_t *pcip = NULL; 2770Sstevel@tonic-gate 2780Sstevel@tonic-gate if (ddi_prop_update_string(DDI_DEV_T_NONE, devi, "device_type", "pci") 2790Sstevel@tonic-gate != DDI_PROP_SUCCESS) { 2800Sstevel@tonic-gate cmn_err(CE_WARN, "pci: 'device_type' prop create failed"); 2810Sstevel@tonic-gate } 2820Sstevel@tonic-gate 283*117Sschwartz if (ddi_soft_state_zalloc(pci_statep, instance) == DDI_SUCCESS) { 284*117Sschwartz pcip = ddi_get_soft_state(pci_statep, instance); 2850Sstevel@tonic-gate } 2860Sstevel@tonic-gate 2870Sstevel@tonic-gate if (pcip == NULL) { 288*117Sschwartz goto bad_soft_state; 2890Sstevel@tonic-gate } 2900Sstevel@tonic-gate 2910Sstevel@tonic-gate pcip->pci_dip = devi; 2920Sstevel@tonic-gate 2930Sstevel@tonic-gate /* 2940Sstevel@tonic-gate * Initialize hotplug support on this bus. At minimum 2950Sstevel@tonic-gate * (for non hotplug bus) this would create ":devctl" minor 2960Sstevel@tonic-gate * node to support DEVCTL_DEVICE_* and DEVCTL_BUS_* ioctls 2970Sstevel@tonic-gate * to this bus. 2980Sstevel@tonic-gate */ 2990Sstevel@tonic-gate if (pcihp_init(devi) != DDI_SUCCESS) { 3000Sstevel@tonic-gate cmn_err(CE_WARN, "pci: Failed to setup hotplug framework"); 301*117Sschwartz goto bad_pcihp_init; 302*117Sschwartz } 303*117Sschwartz 304*117Sschwartz if (pcitool_init(devi) != DDI_SUCCESS) { 305*117Sschwartz goto bad_pcitool_init; 3060Sstevel@tonic-gate } 3070Sstevel@tonic-gate 3080Sstevel@tonic-gate ddi_report_dev(devi); 3090Sstevel@tonic-gate 3100Sstevel@tonic-gate return (DDI_SUCCESS); 311*117Sschwartz 312*117Sschwartz bad_pcitool_init: 313*117Sschwartz (void) pcihp_uninit(devi); 314*117Sschwartz bad_pcihp_init: 315*117Sschwartz ddi_soft_state_free(pci_statep, instance); 316*117Sschwartz bad_soft_state: 317*117Sschwartz return (DDI_FAILURE); 3180Sstevel@tonic-gate } 3190Sstevel@tonic-gate 3200Sstevel@tonic-gate /*ARGSUSED*/ 3210Sstevel@tonic-gate static int 3220Sstevel@tonic-gate pci_detach(dev_info_t *devi, ddi_detach_cmd_t cmd) 3230Sstevel@tonic-gate { 324*117Sschwartz /* Uninitialize pcitool support. */ 325*117Sschwartz pcitool_uninit(devi); 326*117Sschwartz 327*117Sschwartz /* Uninitialize hotplug support on this bus. */ 3280Sstevel@tonic-gate (void) pcihp_uninit(devi); 329*117Sschwartz 3300Sstevel@tonic-gate ddi_soft_state_free(pci_statep, DIP_TO_MINOR(devi)); 3310Sstevel@tonic-gate 3320Sstevel@tonic-gate return (DDI_SUCCESS); 3330Sstevel@tonic-gate } 3340Sstevel@tonic-gate 3350Sstevel@tonic-gate static int 3360Sstevel@tonic-gate pci_get_reg_prop(dev_info_t *dip, pci_regspec_t *pci_rp) 3370Sstevel@tonic-gate { 3380Sstevel@tonic-gate pci_regspec_t *assigned_addr; 3390Sstevel@tonic-gate int assigned_addr_len; 3400Sstevel@tonic-gate uint_t phys_hi; 3410Sstevel@tonic-gate int i; 3420Sstevel@tonic-gate int rc; 3430Sstevel@tonic-gate int number; 3440Sstevel@tonic-gate 3450Sstevel@tonic-gate phys_hi = pci_rp->pci_phys_hi; 3460Sstevel@tonic-gate if (((phys_hi & PCI_REG_ADDR_M) == PCI_ADDR_CONFIG) || 3470Sstevel@tonic-gate (phys_hi & PCI_RELOCAT_B)) 3480Sstevel@tonic-gate return (DDI_SUCCESS); 3490Sstevel@tonic-gate 3500Sstevel@tonic-gate /* 3510Sstevel@tonic-gate * the "reg" property specifies relocatable, get and interpret the 3520Sstevel@tonic-gate * "assigned-addresses" property. 3530Sstevel@tonic-gate */ 3540Sstevel@tonic-gate rc = ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 3550Sstevel@tonic-gate DDI_PROP_DONTPASS, "assigned-addresses", 3560Sstevel@tonic-gate (int **)&assigned_addr, (uint_t *)&assigned_addr_len); 3570Sstevel@tonic-gate if (rc != DDI_PROP_SUCCESS) 3580Sstevel@tonic-gate return (DDI_FAILURE); 3590Sstevel@tonic-gate 3600Sstevel@tonic-gate /* 3610Sstevel@tonic-gate * Scan the "assigned-addresses" for one that matches the specified 3620Sstevel@tonic-gate * "reg" property entry. 3630Sstevel@tonic-gate */ 3640Sstevel@tonic-gate phys_hi &= PCI_CONF_ADDR_MASK; 3650Sstevel@tonic-gate number = assigned_addr_len / (sizeof (pci_regspec_t) / sizeof (int)); 3660Sstevel@tonic-gate for (i = 0; i < number; i++) { 3670Sstevel@tonic-gate if ((assigned_addr[i].pci_phys_hi & PCI_CONF_ADDR_MASK) == 3680Sstevel@tonic-gate phys_hi) { 3690Sstevel@tonic-gate pci_rp->pci_phys_mid = assigned_addr[i].pci_phys_mid; 3700Sstevel@tonic-gate pci_rp->pci_phys_low = assigned_addr[i].pci_phys_low; 3710Sstevel@tonic-gate ddi_prop_free(assigned_addr); 3720Sstevel@tonic-gate return (DDI_SUCCESS); 3730Sstevel@tonic-gate } 3740Sstevel@tonic-gate } 3750Sstevel@tonic-gate 3760Sstevel@tonic-gate ddi_prop_free(assigned_addr); 3770Sstevel@tonic-gate return (DDI_FAILURE); 3780Sstevel@tonic-gate } 3790Sstevel@tonic-gate 3800Sstevel@tonic-gate static int 3810Sstevel@tonic-gate pci_bus_map(dev_info_t *dip, dev_info_t *rdip, ddi_map_req_t *mp, 3820Sstevel@tonic-gate off_t offset, off_t len, caddr_t *vaddrp) 3830Sstevel@tonic-gate { 3840Sstevel@tonic-gate struct regspec reg; 3850Sstevel@tonic-gate ddi_map_req_t mr; 3860Sstevel@tonic-gate ddi_acc_hdl_t *hp; 3870Sstevel@tonic-gate ddi_acc_impl_t *ap; 3880Sstevel@tonic-gate pci_regspec_t pci_reg; 3890Sstevel@tonic-gate pci_regspec_t *pci_rp; 3900Sstevel@tonic-gate int rnumber; 3910Sstevel@tonic-gate int length; 3920Sstevel@tonic-gate int rc; 3930Sstevel@tonic-gate pci_acc_cfblk_t *cfp; 3940Sstevel@tonic-gate int space; 3950Sstevel@tonic-gate 3960Sstevel@tonic-gate 3970Sstevel@tonic-gate mr = *mp; /* Get private copy of request */ 3980Sstevel@tonic-gate mp = &mr; 3990Sstevel@tonic-gate 4000Sstevel@tonic-gate /* 4010Sstevel@tonic-gate * check for register number 4020Sstevel@tonic-gate */ 4030Sstevel@tonic-gate switch (mp->map_type) { 4040Sstevel@tonic-gate case DDI_MT_REGSPEC: 4050Sstevel@tonic-gate pci_reg = *(pci_regspec_t *)(mp->map_obj.rp); 4060Sstevel@tonic-gate pci_rp = &pci_reg; 4070Sstevel@tonic-gate if (pci_get_reg_prop(rdip, pci_rp) != DDI_SUCCESS) 4080Sstevel@tonic-gate return (DDI_FAILURE); 4090Sstevel@tonic-gate break; 4100Sstevel@tonic-gate case DDI_MT_RNUMBER: 4110Sstevel@tonic-gate rnumber = mp->map_obj.rnumber; 4120Sstevel@tonic-gate /* 4130Sstevel@tonic-gate * get ALL "reg" properties for dip, select the one of 4140Sstevel@tonic-gate * of interest. In x86, "assigned-addresses" property 4150Sstevel@tonic-gate * is identical to the "reg" property, so there is no 4160Sstevel@tonic-gate * need to cross check the two to determine the physical 4170Sstevel@tonic-gate * address of the registers. 4180Sstevel@tonic-gate * This routine still performs some validity checks to 4190Sstevel@tonic-gate * make sure that everything is okay. 4200Sstevel@tonic-gate */ 4210Sstevel@tonic-gate rc = ddi_prop_lookup_int_array(DDI_DEV_T_ANY, rdip, 4220Sstevel@tonic-gate DDI_PROP_DONTPASS, "reg", (int **)&pci_rp, 4230Sstevel@tonic-gate (uint_t *)&length); 4240Sstevel@tonic-gate if (rc != DDI_PROP_SUCCESS) { 4250Sstevel@tonic-gate return (DDI_FAILURE); 4260Sstevel@tonic-gate } 4270Sstevel@tonic-gate 4280Sstevel@tonic-gate /* 4290Sstevel@tonic-gate * validate the register number. 4300Sstevel@tonic-gate */ 4310Sstevel@tonic-gate length /= (sizeof (pci_regspec_t) / sizeof (int)); 4320Sstevel@tonic-gate if (rnumber >= length) { 4330Sstevel@tonic-gate ddi_prop_free(pci_rp); 4340Sstevel@tonic-gate return (DDI_FAILURE); 4350Sstevel@tonic-gate } 4360Sstevel@tonic-gate 4370Sstevel@tonic-gate /* 4380Sstevel@tonic-gate * copy the required entry. 4390Sstevel@tonic-gate */ 4400Sstevel@tonic-gate pci_reg = pci_rp[rnumber]; 4410Sstevel@tonic-gate 4420Sstevel@tonic-gate /* 4430Sstevel@tonic-gate * free the memory allocated by ddi_prop_lookup_int_array 4440Sstevel@tonic-gate */ 4450Sstevel@tonic-gate ddi_prop_free(pci_rp); 4460Sstevel@tonic-gate 4470Sstevel@tonic-gate pci_rp = &pci_reg; 4480Sstevel@tonic-gate if (pci_get_reg_prop(rdip, pci_rp) != DDI_SUCCESS) 4490Sstevel@tonic-gate return (DDI_FAILURE); 4500Sstevel@tonic-gate mp->map_type = DDI_MT_REGSPEC; 4510Sstevel@tonic-gate break; 4520Sstevel@tonic-gate default: 4530Sstevel@tonic-gate return (DDI_ME_INVAL); 4540Sstevel@tonic-gate } 4550Sstevel@tonic-gate 4560Sstevel@tonic-gate space = pci_rp->pci_phys_hi & PCI_REG_ADDR_M; 4570Sstevel@tonic-gate 4580Sstevel@tonic-gate /* 4590Sstevel@tonic-gate * check for unmap and unlock of address space 4600Sstevel@tonic-gate */ 4610Sstevel@tonic-gate if ((mp->map_op == DDI_MO_UNMAP) || (mp->map_op == DDI_MO_UNLOCK)) { 4620Sstevel@tonic-gate /* 4630Sstevel@tonic-gate * Adjust offset and length 4640Sstevel@tonic-gate * A non-zero length means override the one in the regspec. 4650Sstevel@tonic-gate */ 4660Sstevel@tonic-gate pci_rp->pci_phys_low += (uint_t)offset; 4670Sstevel@tonic-gate if (len != 0) 4680Sstevel@tonic-gate pci_rp->pci_size_low = len; 4690Sstevel@tonic-gate 4700Sstevel@tonic-gate switch (space) { 4710Sstevel@tonic-gate case PCI_ADDR_CONFIG: 4720Sstevel@tonic-gate /* No work required on unmap of Config space */ 4730Sstevel@tonic-gate return (DDI_SUCCESS); 4740Sstevel@tonic-gate 4750Sstevel@tonic-gate case PCI_ADDR_IO: 4760Sstevel@tonic-gate reg.regspec_bustype = 1; 4770Sstevel@tonic-gate break; 4780Sstevel@tonic-gate 4790Sstevel@tonic-gate case PCI_ADDR_MEM64: 4800Sstevel@tonic-gate /* 4810Sstevel@tonic-gate * MEM64 requires special treatment on map, to check 4820Sstevel@tonic-gate * that the device is below 4G. On unmap, however, 4830Sstevel@tonic-gate * we can assume that everything is OK... the map 4840Sstevel@tonic-gate * must have succeeded. 4850Sstevel@tonic-gate */ 4860Sstevel@tonic-gate /* FALLTHROUGH */ 4870Sstevel@tonic-gate case PCI_ADDR_MEM32: 4880Sstevel@tonic-gate reg.regspec_bustype = 0; 4890Sstevel@tonic-gate break; 4900Sstevel@tonic-gate 4910Sstevel@tonic-gate default: 4920Sstevel@tonic-gate return (DDI_FAILURE); 4930Sstevel@tonic-gate } 4940Sstevel@tonic-gate reg.regspec_addr = pci_rp->pci_phys_low; 4950Sstevel@tonic-gate reg.regspec_size = pci_rp->pci_size_low; 4960Sstevel@tonic-gate 4970Sstevel@tonic-gate mp->map_obj.rp = ® 4980Sstevel@tonic-gate return (ddi_map(dip, mp, (off_t)0, (off_t)0, vaddrp)); 4990Sstevel@tonic-gate 5000Sstevel@tonic-gate } 5010Sstevel@tonic-gate 5020Sstevel@tonic-gate /* check for user mapping request - not legal for Config */ 5030Sstevel@tonic-gate if (mp->map_op == DDI_MO_MAP_HANDLE && space == PCI_ADDR_CONFIG) { 5040Sstevel@tonic-gate return (DDI_FAILURE); 5050Sstevel@tonic-gate } 5060Sstevel@tonic-gate 5070Sstevel@tonic-gate /* 5080Sstevel@tonic-gate * check for config space 5090Sstevel@tonic-gate * On x86, CONFIG is not mapped via MMU and there is 5100Sstevel@tonic-gate * no endian-ness issues. Set the attr field in the handle to 5110Sstevel@tonic-gate * indicate that the common routines to call the nexus driver. 5120Sstevel@tonic-gate */ 5130Sstevel@tonic-gate if (space == PCI_ADDR_CONFIG) { 5140Sstevel@tonic-gate hp = (ddi_acc_hdl_t *)mp->map_handlep; 5150Sstevel@tonic-gate 5160Sstevel@tonic-gate if (hp == NULL) { 5170Sstevel@tonic-gate /* Can't map config space without a handle */ 5180Sstevel@tonic-gate return (DDI_FAILURE); 5190Sstevel@tonic-gate } 5200Sstevel@tonic-gate 5210Sstevel@tonic-gate ap = (ddi_acc_impl_t *)hp->ah_platform_private; 5220Sstevel@tonic-gate 5230Sstevel@tonic-gate /* endian-ness check */ 5240Sstevel@tonic-gate if (hp->ah_acc.devacc_attr_endian_flags == DDI_STRUCTURE_BE_ACC) 5250Sstevel@tonic-gate return (DDI_FAILURE); 5260Sstevel@tonic-gate 5270Sstevel@tonic-gate /* 5280Sstevel@tonic-gate * range check 5290Sstevel@tonic-gate */ 5300Sstevel@tonic-gate if ((offset >= 256) || (len > 256) || (offset + len > 256)) 5310Sstevel@tonic-gate return (DDI_FAILURE); 5320Sstevel@tonic-gate *vaddrp = (caddr_t)offset; 5330Sstevel@tonic-gate 5340Sstevel@tonic-gate ap->ahi_acc_attr |= DDI_ACCATTR_CONFIG_SPACE; 5350Sstevel@tonic-gate ap->ahi_put8 = pci_config_wr8; 5360Sstevel@tonic-gate ap->ahi_get8 = pci_config_rd8; 5370Sstevel@tonic-gate ap->ahi_put64 = pci_config_wr64; 5380Sstevel@tonic-gate ap->ahi_get64 = pci_config_rd64; 5390Sstevel@tonic-gate ap->ahi_rep_put8 = pci_config_rep_wr8; 5400Sstevel@tonic-gate ap->ahi_rep_get8 = pci_config_rep_rd8; 5410Sstevel@tonic-gate ap->ahi_rep_put64 = pci_config_rep_wr64; 5420Sstevel@tonic-gate ap->ahi_rep_get64 = pci_config_rep_rd64; 5430Sstevel@tonic-gate ap->ahi_get16 = pci_config_rd16; 5440Sstevel@tonic-gate ap->ahi_get32 = pci_config_rd32; 5450Sstevel@tonic-gate ap->ahi_put16 = pci_config_wr16; 5460Sstevel@tonic-gate ap->ahi_put32 = pci_config_wr32; 5470Sstevel@tonic-gate ap->ahi_rep_get16 = pci_config_rep_rd16; 5480Sstevel@tonic-gate ap->ahi_rep_get32 = pci_config_rep_rd32; 5490Sstevel@tonic-gate ap->ahi_rep_put16 = pci_config_rep_wr16; 5500Sstevel@tonic-gate ap->ahi_rep_put32 = pci_config_rep_wr32; 5510Sstevel@tonic-gate 5520Sstevel@tonic-gate /* Initialize to default check/notify functions */ 5530Sstevel@tonic-gate ap->ahi_fault_check = i_ddi_acc_fault_check; 5540Sstevel@tonic-gate ap->ahi_fault_notify = i_ddi_acc_fault_notify; 5550Sstevel@tonic-gate ap->ahi_fault = 0; 5560Sstevel@tonic-gate impl_acc_err_init(hp); 5570Sstevel@tonic-gate 5580Sstevel@tonic-gate /* record the device address for future reference */ 5590Sstevel@tonic-gate cfp = (pci_acc_cfblk_t *)&hp->ah_bus_private; 5600Sstevel@tonic-gate cfp->c_busnum = PCI_REG_BUS_G(pci_rp->pci_phys_hi); 5610Sstevel@tonic-gate cfp->c_devnum = PCI_REG_DEV_G(pci_rp->pci_phys_hi); 5620Sstevel@tonic-gate cfp->c_funcnum = PCI_REG_FUNC_G(pci_rp->pci_phys_hi); 5630Sstevel@tonic-gate 5640Sstevel@tonic-gate return (DDI_SUCCESS); 5650Sstevel@tonic-gate } 5660Sstevel@tonic-gate 5670Sstevel@tonic-gate /* 5680Sstevel@tonic-gate * range check 5690Sstevel@tonic-gate */ 5700Sstevel@tonic-gate if ((offset >= pci_rp->pci_size_low) || 5710Sstevel@tonic-gate (len > pci_rp->pci_size_low) || 5720Sstevel@tonic-gate (offset + len > pci_rp->pci_size_low)) { 5730Sstevel@tonic-gate return (DDI_FAILURE); 5740Sstevel@tonic-gate } 5750Sstevel@tonic-gate 5760Sstevel@tonic-gate /* 5770Sstevel@tonic-gate * Adjust offset and length 5780Sstevel@tonic-gate * A non-zero length means override the one in the regspec. 5790Sstevel@tonic-gate */ 5800Sstevel@tonic-gate pci_rp->pci_phys_low += (uint_t)offset; 5810Sstevel@tonic-gate if (len != 0) 5820Sstevel@tonic-gate pci_rp->pci_size_low = len; 5830Sstevel@tonic-gate 5840Sstevel@tonic-gate /* 5850Sstevel@tonic-gate * convert the pci regsec into the generic regspec used by the 5860Sstevel@tonic-gate * parent root nexus driver. 5870Sstevel@tonic-gate */ 5880Sstevel@tonic-gate switch (space) { 5890Sstevel@tonic-gate case PCI_ADDR_IO: 5900Sstevel@tonic-gate reg.regspec_bustype = 1; 5910Sstevel@tonic-gate break; 5920Sstevel@tonic-gate case PCI_ADDR_MEM64: 5930Sstevel@tonic-gate /* 5940Sstevel@tonic-gate * We can't handle 64-bit devices that are mapped above 5950Sstevel@tonic-gate * 4G or that are larger than 4G. 5960Sstevel@tonic-gate */ 5970Sstevel@tonic-gate if (pci_rp->pci_phys_mid != 0 || 5980Sstevel@tonic-gate pci_rp->pci_size_hi != 0) 5990Sstevel@tonic-gate return (DDI_FAILURE); 6000Sstevel@tonic-gate /* 6010Sstevel@tonic-gate * Other than that, we can treat them as 32-bit mappings 6020Sstevel@tonic-gate */ 6030Sstevel@tonic-gate /* FALLTHROUGH */ 6040Sstevel@tonic-gate case PCI_ADDR_MEM32: 6050Sstevel@tonic-gate reg.regspec_bustype = 0; 6060Sstevel@tonic-gate break; 6070Sstevel@tonic-gate default: 6080Sstevel@tonic-gate return (DDI_FAILURE); 6090Sstevel@tonic-gate } 6100Sstevel@tonic-gate reg.regspec_addr = pci_rp->pci_phys_low; 6110Sstevel@tonic-gate reg.regspec_size = pci_rp->pci_size_low; 6120Sstevel@tonic-gate 6130Sstevel@tonic-gate mp->map_obj.rp = ® 6140Sstevel@tonic-gate return (ddi_map(dip, mp, (off_t)0, (off_t)0, vaddrp)); 6150Sstevel@tonic-gate } 6160Sstevel@tonic-gate 6170Sstevel@tonic-gate 6180Sstevel@tonic-gate /* 6190Sstevel@tonic-gate * pci_get_priority: 6200Sstevel@tonic-gate * Figure out the priority of the device 6210Sstevel@tonic-gate */ 6220Sstevel@tonic-gate static int 6230Sstevel@tonic-gate pci_get_priority(dev_info_t *dip, int inum, int *pri) 6240Sstevel@tonic-gate { 6250Sstevel@tonic-gate struct intrspec *ispec; 6260Sstevel@tonic-gate 6270Sstevel@tonic-gate DDI_INTR_NEXDBG((CE_CONT, "pci_get_priority: dip = 0x%p\n", 6280Sstevel@tonic-gate (void *)dip)); 6290Sstevel@tonic-gate 6300Sstevel@tonic-gate if ((ispec = (struct intrspec *)pci_intx_get_ispec(dip, dip, inum)) == 6310Sstevel@tonic-gate NULL) 6320Sstevel@tonic-gate return (DDI_FAILURE); 6330Sstevel@tonic-gate 6340Sstevel@tonic-gate *pri = ispec->intrspec_pri; 6350Sstevel@tonic-gate 6360Sstevel@tonic-gate return (DDI_SUCCESS); 6370Sstevel@tonic-gate } 6380Sstevel@tonic-gate 6390Sstevel@tonic-gate 6400Sstevel@tonic-gate /* 6410Sstevel@tonic-gate * pci_get_nintrs: 6420Sstevel@tonic-gate * Figure out how many interrupts the device supports 6430Sstevel@tonic-gate */ 6440Sstevel@tonic-gate static int 6450Sstevel@tonic-gate pci_get_nintrs(dev_info_t *dip, int type, int *nintrs) 6460Sstevel@tonic-gate { 6470Sstevel@tonic-gate int ret; 6480Sstevel@tonic-gate 6490Sstevel@tonic-gate *nintrs = 0; 6500Sstevel@tonic-gate 6510Sstevel@tonic-gate if (DDI_INTR_IS_MSI_OR_MSIX(type)) 6520Sstevel@tonic-gate ret = pci_msi_get_nintrs(dip, type, nintrs); 6530Sstevel@tonic-gate else { 6540Sstevel@tonic-gate ret = DDI_FAILURE; 6550Sstevel@tonic-gate if (ddi_prop_get_int(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, 6560Sstevel@tonic-gate "interrupts", -1) != -1) { 6570Sstevel@tonic-gate *nintrs = 1; 6580Sstevel@tonic-gate ret = DDI_SUCCESS; 6590Sstevel@tonic-gate } 6600Sstevel@tonic-gate } 6610Sstevel@tonic-gate 6620Sstevel@tonic-gate return (ret); 6630Sstevel@tonic-gate } 6640Sstevel@tonic-gate 6650Sstevel@tonic-gate 6660Sstevel@tonic-gate /* 6670Sstevel@tonic-gate * pci_intr_ops: bus_intr_op() function for interrupt support 6680Sstevel@tonic-gate */ 6690Sstevel@tonic-gate /* ARGSUSED */ 6700Sstevel@tonic-gate static int 6710Sstevel@tonic-gate pci_intr_ops(dev_info_t *pdip, dev_info_t *rdip, ddi_intr_op_t intr_op, 672*117Sschwartz ddi_intr_handle_impl_t *hdlp, void *result) 6730Sstevel@tonic-gate { 6740Sstevel@tonic-gate int priority = 0; 6750Sstevel@tonic-gate int psm_status = 0; 6760Sstevel@tonic-gate int pci_status = 0; 6770Sstevel@tonic-gate int pci_rval, psm_rval = PSM_FAILURE; 6780Sstevel@tonic-gate int types = 0; 6790Sstevel@tonic-gate int i, j; 6800Sstevel@tonic-gate int behavior; 6810Sstevel@tonic-gate ddi_intrspec_t isp; 6820Sstevel@tonic-gate struct intrspec *ispec; 6830Sstevel@tonic-gate ddi_intr_handle_impl_t tmp_hdl; 6840Sstevel@tonic-gate ddi_intr_msix_t *msix_p; 6850Sstevel@tonic-gate 6860Sstevel@tonic-gate DDI_INTR_NEXDBG((CE_CONT, 6870Sstevel@tonic-gate "pci_intr_ops: pdip 0x%p, rdip 0x%p, op %x handle 0x%p\n", 6880Sstevel@tonic-gate (void *)pdip, (void *)rdip, intr_op, (void *)hdlp)); 6890Sstevel@tonic-gate 6900Sstevel@tonic-gate /* Process the request */ 6910Sstevel@tonic-gate switch (intr_op) { 6920Sstevel@tonic-gate case DDI_INTROP_SUPPORTED_TYPES: 6930Sstevel@tonic-gate /* Fixed supported by default */ 6940Sstevel@tonic-gate *(int *)result = DDI_INTR_TYPE_FIXED; 6950Sstevel@tonic-gate 6960Sstevel@tonic-gate /* Figure out if MSI or MSI-X is supported? */ 6970Sstevel@tonic-gate if (pci_msi_get_supported_type(rdip, &types) != DDI_SUCCESS) 6980Sstevel@tonic-gate return (DDI_SUCCESS); 6990Sstevel@tonic-gate 7000Sstevel@tonic-gate if (psm_intr_ops != NULL) { 7010Sstevel@tonic-gate /* MSI or MSI-X is supported, OR it in */ 7020Sstevel@tonic-gate *(int *)result |= types; 7030Sstevel@tonic-gate 7040Sstevel@tonic-gate tmp_hdl.ih_type = *(int *)result; 7050Sstevel@tonic-gate (void) (*psm_intr_ops)(rdip, &tmp_hdl, 7060Sstevel@tonic-gate PSM_INTR_OP_CHECK_MSI, result); 7070Sstevel@tonic-gate DDI_INTR_NEXDBG((CE_CONT, "pci_intr_ops: rdip: 0x%p " 7080Sstevel@tonic-gate "supported types: 0x%x\n", (void *)rdip, 7090Sstevel@tonic-gate *(int *)result)); 7100Sstevel@tonic-gate } 7110Sstevel@tonic-gate break; 7120Sstevel@tonic-gate case DDI_INTROP_NINTRS: 7130Sstevel@tonic-gate if (pci_get_nintrs(rdip, hdlp->ih_type, result) != DDI_SUCCESS) 7140Sstevel@tonic-gate return (DDI_FAILURE); 7150Sstevel@tonic-gate break; 7160Sstevel@tonic-gate case DDI_INTROP_ALLOC: 7170Sstevel@tonic-gate /* 7180Sstevel@tonic-gate * MSI or MSIX (figure out number of vectors available) 7190Sstevel@tonic-gate * FIXED interrupts: just return available interrupts 7200Sstevel@tonic-gate */ 7210Sstevel@tonic-gate if (DDI_INTR_IS_MSI_OR_MSIX(hdlp->ih_type) && 7220Sstevel@tonic-gate (psm_intr_ops != NULL) && 7230Sstevel@tonic-gate (pci_get_priority(rdip, hdlp->ih_inum, 7240Sstevel@tonic-gate &priority) == DDI_SUCCESS)) { 7250Sstevel@tonic-gate hdlp->ih_pri = priority; 7260Sstevel@tonic-gate behavior = hdlp->ih_scratch2; 7270Sstevel@tonic-gate (void) (*psm_intr_ops)(rdip, hdlp, 7280Sstevel@tonic-gate PSM_INTR_OP_ALLOC_VECTORS, result); 7290Sstevel@tonic-gate 7300Sstevel@tonic-gate /* verify behavior flag and take appropriate action */ 7310Sstevel@tonic-gate if ((behavior == DDI_INTR_ALLOC_STRICT) && 7320Sstevel@tonic-gate (*(int *)result < hdlp->ih_scratch1)) { 7330Sstevel@tonic-gate DDI_INTR_NEXDBG((CE_CONT, "pci_intr_ops: " 7340Sstevel@tonic-gate "behavior %x, couldn't get enough intrs\n", 7350Sstevel@tonic-gate behavior)); 7360Sstevel@tonic-gate hdlp->ih_scratch1 = *(int *)result; 7370Sstevel@tonic-gate (void) (*psm_intr_ops)(rdip, hdlp, 7380Sstevel@tonic-gate PSM_INTR_OP_FREE_VECTORS, NULL); 7390Sstevel@tonic-gate return (DDI_EAGAIN); 7400Sstevel@tonic-gate } 7410Sstevel@tonic-gate 7420Sstevel@tonic-gate if (hdlp->ih_type == DDI_INTR_TYPE_MSIX) { 7430Sstevel@tonic-gate if (!(msix_p = i_ddi_get_msix(hdlp->ih_dip))) { 7440Sstevel@tonic-gate msix_p = pci_msix_init(hdlp->ih_dip); 7450Sstevel@tonic-gate if (msix_p) 7460Sstevel@tonic-gate i_ddi_set_msix(hdlp->ih_dip, 7470Sstevel@tonic-gate msix_p); 7480Sstevel@tonic-gate } 7490Sstevel@tonic-gate msix_p->msix_intrs_in_use += *(int *)result; 7500Sstevel@tonic-gate } 7510Sstevel@tonic-gate 7520Sstevel@tonic-gate } else if (hdlp->ih_type == DDI_INTR_TYPE_FIXED) { 7530Sstevel@tonic-gate /* Figure out if this device supports MASKING */ 7540Sstevel@tonic-gate pci_rval = pci_intx_get_cap(rdip, &pci_status); 7550Sstevel@tonic-gate if (pci_rval == DDI_SUCCESS && pci_status) 7560Sstevel@tonic-gate hdlp->ih_cap |= pci_status; 7570Sstevel@tonic-gate *(int *)result = 1; /* DDI_INTR_TYPE_FIXED */ 7580Sstevel@tonic-gate } else 7590Sstevel@tonic-gate return (DDI_FAILURE); 7600Sstevel@tonic-gate break; 7610Sstevel@tonic-gate case DDI_INTROP_FREE: 7620Sstevel@tonic-gate if (DDI_INTR_IS_MSI_OR_MSIX(hdlp->ih_type) && 7630Sstevel@tonic-gate (psm_intr_ops != NULL)) { 7640Sstevel@tonic-gate (void) (*psm_intr_ops)(rdip, hdlp, 7650Sstevel@tonic-gate PSM_INTR_OP_FREE_VECTORS, NULL); 7660Sstevel@tonic-gate 7670Sstevel@tonic-gate if (hdlp->ih_type == DDI_INTR_TYPE_MSIX) { 7680Sstevel@tonic-gate msix_p = i_ddi_get_msix(hdlp->ih_dip); 7690Sstevel@tonic-gate if (msix_p && 7700Sstevel@tonic-gate --msix_p->msix_intrs_in_use == 0) { 7710Sstevel@tonic-gate pci_msix_fini(msix_p); 7720Sstevel@tonic-gate i_ddi_set_msix(hdlp->ih_dip, NULL); 7730Sstevel@tonic-gate } 7740Sstevel@tonic-gate } 7750Sstevel@tonic-gate } 7760Sstevel@tonic-gate break; 7770Sstevel@tonic-gate case DDI_INTROP_GETPRI: 7780Sstevel@tonic-gate if (pci_get_priority(rdip, hdlp->ih_inum, &priority) != 7790Sstevel@tonic-gate DDI_SUCCESS) /* Get the priority */ 7800Sstevel@tonic-gate return (DDI_FAILURE); 7810Sstevel@tonic-gate DDI_INTR_NEXDBG((CE_CONT, "pci_intr_ops: priority = 0x%x\n", 7820Sstevel@tonic-gate priority)); 7830Sstevel@tonic-gate *(int *)result = priority; 7840Sstevel@tonic-gate break; 7850Sstevel@tonic-gate case DDI_INTROP_SETPRI: 7860Sstevel@tonic-gate /* Validate the interrupt priority passed */ 7870Sstevel@tonic-gate if (*(int *)result > LOCK_LEVEL) 7880Sstevel@tonic-gate return (DDI_FAILURE); 7890Sstevel@tonic-gate 7900Sstevel@tonic-gate /* Ensure that PSM is all initialized */ 7910Sstevel@tonic-gate if (psm_intr_ops == NULL) 7920Sstevel@tonic-gate return (DDI_FAILURE); 7930Sstevel@tonic-gate 7940Sstevel@tonic-gate /* Change the priority */ 7950Sstevel@tonic-gate if ((*psm_intr_ops)(rdip, hdlp, PSM_INTR_OP_SET_PRI, result) == 7960Sstevel@tonic-gate PSM_FAILURE) 7970Sstevel@tonic-gate return (DDI_FAILURE); 7980Sstevel@tonic-gate 7990Sstevel@tonic-gate /* update ispec */ 8000Sstevel@tonic-gate isp = pci_intx_get_ispec(pdip, rdip, (int)hdlp->ih_inum); 8010Sstevel@tonic-gate ispec = (struct intrspec *)isp; 8020Sstevel@tonic-gate ispec->intrspec_pri = *(int *)result; 8030Sstevel@tonic-gate break; 8040Sstevel@tonic-gate case DDI_INTROP_ADDISR: 8050Sstevel@tonic-gate /* update ispec */ 8060Sstevel@tonic-gate isp = pci_intx_get_ispec(pdip, rdip, (int)hdlp->ih_inum); 8070Sstevel@tonic-gate ispec = (struct intrspec *)isp; 8080Sstevel@tonic-gate ispec->intrspec_func = hdlp->ih_cb_func; 8090Sstevel@tonic-gate break; 8100Sstevel@tonic-gate case DDI_INTROP_REMISR: 8110Sstevel@tonic-gate /* Get the interrupt structure pointer */ 8120Sstevel@tonic-gate isp = pci_intx_get_ispec(pdip, rdip, (int)hdlp->ih_inum); 8130Sstevel@tonic-gate ispec = (struct intrspec *)isp; 8140Sstevel@tonic-gate ispec->intrspec_func = (uint_t (*)()) 0; 8150Sstevel@tonic-gate break; 8160Sstevel@tonic-gate case DDI_INTROP_GETCAP: 8170Sstevel@tonic-gate /* 8180Sstevel@tonic-gate * First check the config space and/or 8190Sstevel@tonic-gate * MSI capability register(s) 8200Sstevel@tonic-gate */ 8210Sstevel@tonic-gate if (DDI_INTR_IS_MSI_OR_MSIX(hdlp->ih_type)) 8220Sstevel@tonic-gate pci_rval = pci_msi_get_cap(rdip, hdlp->ih_type, 8230Sstevel@tonic-gate &pci_status); 8240Sstevel@tonic-gate else if (hdlp->ih_type == DDI_INTR_TYPE_FIXED) 8250Sstevel@tonic-gate pci_rval = pci_intx_get_cap(rdip, &pci_status); 8260Sstevel@tonic-gate 8270Sstevel@tonic-gate /* next check with pcplusmp */ 8280Sstevel@tonic-gate if (psm_intr_ops != NULL) 8290Sstevel@tonic-gate psm_rval = (*psm_intr_ops)(rdip, hdlp, 8300Sstevel@tonic-gate PSM_INTR_OP_GET_CAP, &psm_status); 8310Sstevel@tonic-gate 8320Sstevel@tonic-gate DDI_INTR_NEXDBG((CE_CONT, "pci: GETCAP returned psm_rval = %x, " 8330Sstevel@tonic-gate "psm_status = %x, pci_rval = %x, pci_status = %x\n", 8340Sstevel@tonic-gate psm_rval, psm_status, pci_rval, pci_status)); 8350Sstevel@tonic-gate 8360Sstevel@tonic-gate if (psm_rval == PSM_FAILURE && pci_rval == DDI_FAILURE) { 8370Sstevel@tonic-gate *(int *)result = 0; 8380Sstevel@tonic-gate return (DDI_FAILURE); 8390Sstevel@tonic-gate } 8400Sstevel@tonic-gate 8410Sstevel@tonic-gate if (psm_rval == PSM_SUCCESS) 8420Sstevel@tonic-gate *(int *)result = psm_status; 8430Sstevel@tonic-gate 8440Sstevel@tonic-gate if (pci_rval == DDI_SUCCESS) 8450Sstevel@tonic-gate *(int *)result |= pci_status; 8460Sstevel@tonic-gate 8470Sstevel@tonic-gate DDI_INTR_NEXDBG((CE_CONT, "pci: GETCAP returned = %x\n", 8480Sstevel@tonic-gate *(int *)result)); 8490Sstevel@tonic-gate break; 8500Sstevel@tonic-gate case DDI_INTROP_SETCAP: 8510Sstevel@tonic-gate DDI_INTR_NEXDBG((CE_CONT, "pci_intr_ops: SETCAP cap=0x%x\n", 8520Sstevel@tonic-gate *(int *)result)); 8530Sstevel@tonic-gate if (psm_intr_ops == NULL) 8540Sstevel@tonic-gate return (DDI_FAILURE); 8550Sstevel@tonic-gate 8560Sstevel@tonic-gate if ((*psm_intr_ops)(rdip, hdlp, PSM_INTR_OP_SET_CAP, result)) { 8570Sstevel@tonic-gate DDI_INTR_NEXDBG((CE_CONT, "GETCAP: psm_intr_ops" 8580Sstevel@tonic-gate " returned failure\n")); 8590Sstevel@tonic-gate return (DDI_FAILURE); 8600Sstevel@tonic-gate } 8610Sstevel@tonic-gate break; 8620Sstevel@tonic-gate case DDI_INTROP_ENABLE: 8630Sstevel@tonic-gate DDI_INTR_NEXDBG((CE_CONT, "pci_intr_ops: ENABLE\n")); 8640Sstevel@tonic-gate if (psm_intr_ops == NULL) 8650Sstevel@tonic-gate return (DDI_FAILURE); 8660Sstevel@tonic-gate 8670Sstevel@tonic-gate if (pci_enable_intr(pdip, rdip, hdlp, hdlp->ih_inum) != 8680Sstevel@tonic-gate DDI_SUCCESS) 8690Sstevel@tonic-gate return (DDI_FAILURE); 8700Sstevel@tonic-gate 8710Sstevel@tonic-gate DDI_INTR_NEXDBG((CE_CONT, "pci_intr_ops: ENABLE vector=0x%x\n", 8720Sstevel@tonic-gate hdlp->ih_vector)); 8730Sstevel@tonic-gate break; 8740Sstevel@tonic-gate case DDI_INTROP_DISABLE: 8750Sstevel@tonic-gate DDI_INTR_NEXDBG((CE_CONT, "pci_intr_ops: DISABLE\n")); 8760Sstevel@tonic-gate if (psm_intr_ops == NULL) 8770Sstevel@tonic-gate return (DDI_FAILURE); 8780Sstevel@tonic-gate 8790Sstevel@tonic-gate pci_disable_intr(pdip, rdip, hdlp, hdlp->ih_inum); 8800Sstevel@tonic-gate DDI_INTR_NEXDBG((CE_CONT, "pci_intr_ops: DISABLE vector = %x\n", 8810Sstevel@tonic-gate hdlp->ih_vector)); 8820Sstevel@tonic-gate break; 8830Sstevel@tonic-gate case DDI_INTROP_BLOCKENABLE: 8840Sstevel@tonic-gate DDI_INTR_NEXDBG((CE_CONT, "pci_intr_ops: BLOCKENABLE\n")); 8850Sstevel@tonic-gate if (hdlp->ih_type != DDI_INTR_TYPE_MSI) { 8860Sstevel@tonic-gate DDI_INTR_NEXDBG((CE_CONT, "BLOCKENABLE: not MSI\n")); 8870Sstevel@tonic-gate return (DDI_FAILURE); 8880Sstevel@tonic-gate } 8890Sstevel@tonic-gate 8900Sstevel@tonic-gate /* Check if psm_intr_ops is NULL? */ 8910Sstevel@tonic-gate if (psm_intr_ops == NULL) 8920Sstevel@tonic-gate return (DDI_FAILURE); 8930Sstevel@tonic-gate 8940Sstevel@tonic-gate for (i = 0; i < hdlp->ih_scratch1; i++) { 8950Sstevel@tonic-gate if (pci_enable_intr(pdip, rdip, hdlp, 8960Sstevel@tonic-gate hdlp->ih_inum + i) != DDI_SUCCESS) { 8970Sstevel@tonic-gate DDI_INTR_NEXDBG((CE_CONT, "BLOCKENABLE: " 8980Sstevel@tonic-gate "pci_enable_intr failed for %d\n", i)); 8990Sstevel@tonic-gate for (j = 0; j < i; j++) 9000Sstevel@tonic-gate pci_disable_intr(pdip, rdip, hdlp, 9010Sstevel@tonic-gate hdlp->ih_inum + j); 9020Sstevel@tonic-gate return (DDI_FAILURE); 9030Sstevel@tonic-gate } 9040Sstevel@tonic-gate DDI_INTR_NEXDBG((CE_CONT, "pci_intr_ops: BLOCKENABLE " 9050Sstevel@tonic-gate "inum %x done\n", hdlp->ih_inum + i)); 9060Sstevel@tonic-gate } 9070Sstevel@tonic-gate break; 9080Sstevel@tonic-gate case DDI_INTROP_BLOCKDISABLE: 9090Sstevel@tonic-gate DDI_INTR_NEXDBG((CE_CONT, "pci_intr_ops: BLOCKDISABLE\n")); 9100Sstevel@tonic-gate if (hdlp->ih_type != DDI_INTR_TYPE_MSI) { 9110Sstevel@tonic-gate DDI_INTR_NEXDBG((CE_CONT, "BLOCKDISABLE: not MSI\n")); 9120Sstevel@tonic-gate return (DDI_FAILURE); 9130Sstevel@tonic-gate } 9140Sstevel@tonic-gate 9150Sstevel@tonic-gate /* Check if psm_intr_ops is present */ 9160Sstevel@tonic-gate if (psm_intr_ops == NULL) 9170Sstevel@tonic-gate return (DDI_FAILURE); 9180Sstevel@tonic-gate 9190Sstevel@tonic-gate for (i = 0; i < hdlp->ih_scratch1; i++) { 9200Sstevel@tonic-gate pci_disable_intr(pdip, rdip, hdlp, hdlp->ih_inum + i); 9210Sstevel@tonic-gate DDI_INTR_NEXDBG((CE_CONT, "pci_intr_ops: BLOCKDISABLE " 9220Sstevel@tonic-gate "inum %x done\n", hdlp->ih_inum + i)); 9230Sstevel@tonic-gate } 9240Sstevel@tonic-gate break; 9250Sstevel@tonic-gate case DDI_INTROP_SETMASK: 9260Sstevel@tonic-gate case DDI_INTROP_CLRMASK: 9270Sstevel@tonic-gate /* 9280Sstevel@tonic-gate * First handle in the config space 9290Sstevel@tonic-gate */ 9300Sstevel@tonic-gate if (intr_op == DDI_INTROP_SETMASK) { 9310Sstevel@tonic-gate if (DDI_INTR_IS_MSI_OR_MSIX(hdlp->ih_type)) 9320Sstevel@tonic-gate pci_status = pci_msi_set_mask(rdip, 9330Sstevel@tonic-gate hdlp->ih_type, hdlp->ih_inum); 9340Sstevel@tonic-gate else if (hdlp->ih_type == DDI_INTR_TYPE_FIXED) 9350Sstevel@tonic-gate pci_status = pci_intx_set_mask(rdip); 9360Sstevel@tonic-gate } else { 9370Sstevel@tonic-gate if (DDI_INTR_IS_MSI_OR_MSIX(hdlp->ih_type)) 9380Sstevel@tonic-gate pci_status = pci_msi_clr_mask(rdip, 9390Sstevel@tonic-gate hdlp->ih_type, hdlp->ih_inum); 9400Sstevel@tonic-gate else if (hdlp->ih_type == DDI_INTR_TYPE_FIXED) 9410Sstevel@tonic-gate pci_status = pci_intx_clr_mask(rdip); 9420Sstevel@tonic-gate } 9430Sstevel@tonic-gate 9440Sstevel@tonic-gate /* For MSI/X; no need to check with pcplusmp */ 9450Sstevel@tonic-gate if (hdlp->ih_type != DDI_INTR_TYPE_FIXED) 9460Sstevel@tonic-gate return (pci_status); 9470Sstevel@tonic-gate 9480Sstevel@tonic-gate /* For fixed interrupts only: handle config space first */ 9490Sstevel@tonic-gate if (hdlp->ih_type == DDI_INTR_TYPE_FIXED && 9500Sstevel@tonic-gate pci_status == DDI_SUCCESS) 9510Sstevel@tonic-gate break; 9520Sstevel@tonic-gate 9530Sstevel@tonic-gate /* For fixed interrupts only: confer with pcplusmp next */ 9540Sstevel@tonic-gate if (psm_intr_ops != NULL) { 9550Sstevel@tonic-gate /* If interrupt is shared; do nothing */ 9560Sstevel@tonic-gate psm_rval = (*psm_intr_ops)(rdip, hdlp, 9570Sstevel@tonic-gate PSM_INTR_OP_GET_SHARED, &psm_status); 9580Sstevel@tonic-gate 9590Sstevel@tonic-gate if (psm_rval == PSM_FAILURE || psm_status == 1) 9600Sstevel@tonic-gate return (pci_status); 9610Sstevel@tonic-gate 9620Sstevel@tonic-gate /* Now, pcplusmp should try to set/clear the mask */ 9630Sstevel@tonic-gate if (intr_op == DDI_INTROP_SETMASK) 9640Sstevel@tonic-gate psm_rval = (*psm_intr_ops)(rdip, hdlp, 9650Sstevel@tonic-gate PSM_INTR_OP_SET_MASK, NULL); 9660Sstevel@tonic-gate else 9670Sstevel@tonic-gate psm_rval = (*psm_intr_ops)(rdip, hdlp, 9680Sstevel@tonic-gate PSM_INTR_OP_CLEAR_MASK, NULL); 9690Sstevel@tonic-gate } 9700Sstevel@tonic-gate return ((psm_rval == PSM_FAILURE) ? DDI_FAILURE : DDI_SUCCESS); 9710Sstevel@tonic-gate case DDI_INTROP_GETPENDING: 9720Sstevel@tonic-gate /* 9730Sstevel@tonic-gate * First check the config space and/or 9740Sstevel@tonic-gate * MSI capability register(s) 9750Sstevel@tonic-gate */ 9760Sstevel@tonic-gate if (DDI_INTR_IS_MSI_OR_MSIX(hdlp->ih_type)) 9770Sstevel@tonic-gate pci_rval = pci_msi_get_pending(rdip, hdlp->ih_type, 9780Sstevel@tonic-gate hdlp->ih_inum, &pci_status); 9790Sstevel@tonic-gate else if (hdlp->ih_type == DDI_INTR_TYPE_FIXED) 9800Sstevel@tonic-gate pci_rval = pci_intx_get_pending(rdip, &pci_status); 9810Sstevel@tonic-gate 9820Sstevel@tonic-gate /* On failure; next try with pcplusmp */ 9830Sstevel@tonic-gate if (pci_rval != DDI_SUCCESS && psm_intr_ops != NULL) 9840Sstevel@tonic-gate psm_rval = (*psm_intr_ops)(rdip, hdlp, 9850Sstevel@tonic-gate PSM_INTR_OP_GET_PENDING, &psm_status); 9860Sstevel@tonic-gate 9870Sstevel@tonic-gate DDI_INTR_NEXDBG((CE_CONT, "pci: GETPENDING returned " 9880Sstevel@tonic-gate "psm_rval = %x, psm_status = %x, pci_rval = %x, " 9890Sstevel@tonic-gate "pci_status = %x\n", psm_rval, psm_status, pci_rval, 9900Sstevel@tonic-gate pci_status)); 9910Sstevel@tonic-gate if (psm_rval == PSM_FAILURE && pci_rval == DDI_FAILURE) { 9920Sstevel@tonic-gate *(int *)result = 0; 9930Sstevel@tonic-gate return (DDI_FAILURE); 9940Sstevel@tonic-gate } 9950Sstevel@tonic-gate 9960Sstevel@tonic-gate if (psm_rval != PSM_FAILURE) 9970Sstevel@tonic-gate *(int *)result = psm_status; 9980Sstevel@tonic-gate else if (pci_rval != DDI_FAILURE) 9990Sstevel@tonic-gate *(int *)result = pci_status; 10000Sstevel@tonic-gate DDI_INTR_NEXDBG((CE_CONT, "pci: GETPENDING returned = %x\n", 10010Sstevel@tonic-gate *(int *)result)); 10020Sstevel@tonic-gate break; 10030Sstevel@tonic-gate case DDI_INTROP_NAVAIL: 10040Sstevel@tonic-gate if ((psm_intr_ops != NULL) && (pci_get_priority(rdip, 10050Sstevel@tonic-gate hdlp->ih_inum, &priority) == DDI_SUCCESS)) { 10060Sstevel@tonic-gate /* Priority in the handle not initialized yet */ 10070Sstevel@tonic-gate hdlp->ih_pri = priority; 10080Sstevel@tonic-gate (void) (*psm_intr_ops)(rdip, hdlp, 10090Sstevel@tonic-gate PSM_INTR_OP_NAVAIL_VECTORS, result); 10100Sstevel@tonic-gate } else { 10110Sstevel@tonic-gate *(int *)result = 1; 10120Sstevel@tonic-gate } 10130Sstevel@tonic-gate DDI_INTR_NEXDBG((CE_CONT, "pci: NAVAIL returned = %x\n", 10140Sstevel@tonic-gate *(int *)result)); 10150Sstevel@tonic-gate break; 10160Sstevel@tonic-gate default: 10170Sstevel@tonic-gate return (i_ddi_intr_ops(pdip, rdip, intr_op, hdlp, result)); 10180Sstevel@tonic-gate } 10190Sstevel@tonic-gate 10200Sstevel@tonic-gate return (DDI_SUCCESS); 10210Sstevel@tonic-gate } 10220Sstevel@tonic-gate 10230Sstevel@tonic-gate 10240Sstevel@tonic-gate static int 10250Sstevel@tonic-gate pci_enable_intr(dev_info_t *pdip, dev_info_t *rdip, 1026*117Sschwartz ddi_intr_handle_impl_t *hdlp, uint32_t inum) 10270Sstevel@tonic-gate { 10280Sstevel@tonic-gate int vector; 10290Sstevel@tonic-gate struct intrspec *ispec; 10300Sstevel@tonic-gate 10310Sstevel@tonic-gate DDI_INTR_NEXDBG((CE_CONT, "pci_enable_intr: hdlp %p inum %x\n", 10320Sstevel@tonic-gate (void *)hdlp, inum)); 10330Sstevel@tonic-gate 10340Sstevel@tonic-gate /* Translate the interrupt if needed */ 10350Sstevel@tonic-gate ispec = (struct intrspec *)pci_intx_get_ispec(pdip, rdip, (int)inum); 10360Sstevel@tonic-gate if (DDI_INTR_IS_MSI_OR_MSIX(hdlp->ih_type)) 10370Sstevel@tonic-gate ispec->intrspec_vec = inum; 10380Sstevel@tonic-gate hdlp->ih_private = (void *)ispec; 10390Sstevel@tonic-gate 10400Sstevel@tonic-gate /* translate the interrupt if needed */ 10410Sstevel@tonic-gate (void) (*psm_intr_ops)(rdip, hdlp, PSM_INTR_OP_XLATE_VECTOR, &vector); 10420Sstevel@tonic-gate DDI_INTR_NEXDBG((CE_CONT, "pci_enable_intr: priority=%x vector=%x\n", 10430Sstevel@tonic-gate hdlp->ih_pri, vector)); 10440Sstevel@tonic-gate 10450Sstevel@tonic-gate /* Add the interrupt handler */ 10460Sstevel@tonic-gate if (!add_avintr((void *)hdlp, hdlp->ih_pri, hdlp->ih_cb_func, 10470Sstevel@tonic-gate DEVI(rdip)->devi_name, vector, hdlp->ih_cb_arg1, 10480Sstevel@tonic-gate hdlp->ih_cb_arg2, rdip)) 10490Sstevel@tonic-gate return (DDI_FAILURE); 10500Sstevel@tonic-gate 10510Sstevel@tonic-gate return (DDI_SUCCESS); 10520Sstevel@tonic-gate } 10530Sstevel@tonic-gate 10540Sstevel@tonic-gate 10550Sstevel@tonic-gate static void 10560Sstevel@tonic-gate pci_disable_intr(dev_info_t *pdip, dev_info_t *rdip, 1057*117Sschwartz ddi_intr_handle_impl_t *hdlp, uint32_t inum) 10580Sstevel@tonic-gate { 10590Sstevel@tonic-gate int vector; 10600Sstevel@tonic-gate struct intrspec *ispec; 10610Sstevel@tonic-gate 10620Sstevel@tonic-gate DDI_INTR_NEXDBG((CE_CONT, "pci_disable_intr: \n")); 10630Sstevel@tonic-gate ispec = (struct intrspec *)pci_intx_get_ispec(pdip, rdip, (int)inum); 10640Sstevel@tonic-gate if (DDI_INTR_IS_MSI_OR_MSIX(hdlp->ih_type)) 10650Sstevel@tonic-gate ispec->intrspec_vec = inum; 10660Sstevel@tonic-gate hdlp->ih_private = (void *)ispec; 10670Sstevel@tonic-gate 10680Sstevel@tonic-gate /* translate the interrupt if needed */ 10690Sstevel@tonic-gate (void) (*psm_intr_ops)(rdip, hdlp, PSM_INTR_OP_XLATE_VECTOR, &vector); 10700Sstevel@tonic-gate 10710Sstevel@tonic-gate /* Disable the interrupt handler */ 10720Sstevel@tonic-gate rem_avintr((void *)hdlp, hdlp->ih_pri, hdlp->ih_cb_func, vector); 10730Sstevel@tonic-gate } 10740Sstevel@tonic-gate 10750Sstevel@tonic-gate 10760Sstevel@tonic-gate /*ARGSUSED*/ 10770Sstevel@tonic-gate static int 10780Sstevel@tonic-gate pci_ctlops(dev_info_t *dip, dev_info_t *rdip, 10790Sstevel@tonic-gate ddi_ctl_enum_t ctlop, void *arg, void *result) 10800Sstevel@tonic-gate { 10810Sstevel@tonic-gate pci_regspec_t *drv_regp; 10820Sstevel@tonic-gate uint_t reglen; 10830Sstevel@tonic-gate int rn; 10840Sstevel@tonic-gate int totreg; 10850Sstevel@tonic-gate 10860Sstevel@tonic-gate switch (ctlop) { 10870Sstevel@tonic-gate case DDI_CTLOPS_REPORTDEV: 10880Sstevel@tonic-gate if (rdip == (dev_info_t *)0) 10890Sstevel@tonic-gate return (DDI_FAILURE); 10900Sstevel@tonic-gate cmn_err(CE_CONT, "?PCI-device: %s@%s, %s%d\n", 10910Sstevel@tonic-gate ddi_node_name(rdip), ddi_get_name_addr(rdip), 10920Sstevel@tonic-gate ddi_driver_name(rdip), 10930Sstevel@tonic-gate ddi_get_instance(rdip)); 10940Sstevel@tonic-gate return (DDI_SUCCESS); 10950Sstevel@tonic-gate 10960Sstevel@tonic-gate case DDI_CTLOPS_INITCHILD: 10970Sstevel@tonic-gate return (pci_initchild((dev_info_t *)arg)); 10980Sstevel@tonic-gate 10990Sstevel@tonic-gate case DDI_CTLOPS_UNINITCHILD: 11000Sstevel@tonic-gate return (pci_removechild((dev_info_t *)arg)); 11010Sstevel@tonic-gate 11020Sstevel@tonic-gate case DDI_CTLOPS_NINTRS: 11030Sstevel@tonic-gate if (ddi_get_parent_data(rdip)) 11040Sstevel@tonic-gate *(int *)result = 1; 11050Sstevel@tonic-gate else 11060Sstevel@tonic-gate *(int *)result = 0; 11070Sstevel@tonic-gate return (DDI_SUCCESS); 11080Sstevel@tonic-gate 11090Sstevel@tonic-gate case DDI_CTLOPS_XLATE_INTRS: 11100Sstevel@tonic-gate return (DDI_SUCCESS); 11110Sstevel@tonic-gate 11120Sstevel@tonic-gate case DDI_CTLOPS_SIDDEV: 11130Sstevel@tonic-gate return (DDI_SUCCESS); 11140Sstevel@tonic-gate 11150Sstevel@tonic-gate case DDI_CTLOPS_REGSIZE: 11160Sstevel@tonic-gate case DDI_CTLOPS_NREGS: 11170Sstevel@tonic-gate if (rdip == (dev_info_t *)0) 11180Sstevel@tonic-gate return (DDI_FAILURE); 11190Sstevel@tonic-gate 11200Sstevel@tonic-gate *(int *)result = 0; 11210Sstevel@tonic-gate if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, rdip, 11220Sstevel@tonic-gate DDI_PROP_DONTPASS, "reg", (int **)&drv_regp, 11230Sstevel@tonic-gate ®len) != DDI_PROP_SUCCESS) { 11240Sstevel@tonic-gate return (DDI_FAILURE); 11250Sstevel@tonic-gate } 11260Sstevel@tonic-gate 11270Sstevel@tonic-gate totreg = (reglen * sizeof (int)) / sizeof (pci_regspec_t); 11280Sstevel@tonic-gate if (ctlop == DDI_CTLOPS_NREGS) 11290Sstevel@tonic-gate *(int *)result = totreg; 11300Sstevel@tonic-gate else if (ctlop == DDI_CTLOPS_REGSIZE) { 11310Sstevel@tonic-gate rn = *(int *)arg; 11320Sstevel@tonic-gate if (rn >= totreg) { 11330Sstevel@tonic-gate ddi_prop_free(drv_regp); 11340Sstevel@tonic-gate return (DDI_FAILURE); 11350Sstevel@tonic-gate } 11360Sstevel@tonic-gate *(off_t *)result = drv_regp[rn].pci_size_low; 11370Sstevel@tonic-gate } 11380Sstevel@tonic-gate ddi_prop_free(drv_regp); 11390Sstevel@tonic-gate 11400Sstevel@tonic-gate return (DDI_SUCCESS); 11410Sstevel@tonic-gate 11420Sstevel@tonic-gate case DDI_CTLOPS_POWER: { 11430Sstevel@tonic-gate power_req_t *reqp = (power_req_t *)arg; 11440Sstevel@tonic-gate /* 11450Sstevel@tonic-gate * We currently understand reporting of PCI_PM_IDLESPEED 11460Sstevel@tonic-gate * capability. Everything else is passed up. 11470Sstevel@tonic-gate */ 11480Sstevel@tonic-gate if ((reqp->request_type == PMR_REPORT_PMCAP) && 11490Sstevel@tonic-gate (reqp->req.report_pmcap_req.cap == PCI_PM_IDLESPEED)) { 11500Sstevel@tonic-gate 11510Sstevel@tonic-gate return (DDI_SUCCESS); 11520Sstevel@tonic-gate } 11530Sstevel@tonic-gate return (ddi_ctlops(dip, rdip, ctlop, arg, result)); 11540Sstevel@tonic-gate } 11550Sstevel@tonic-gate 11560Sstevel@tonic-gate default: 11570Sstevel@tonic-gate return (ddi_ctlops(dip, rdip, ctlop, arg, result)); 11580Sstevel@tonic-gate } 11590Sstevel@tonic-gate 11600Sstevel@tonic-gate /* NOTREACHED */ 11610Sstevel@tonic-gate 11620Sstevel@tonic-gate } 11630Sstevel@tonic-gate 11640Sstevel@tonic-gate /* 11650Sstevel@tonic-gate * Assign the address portion of the node name 11660Sstevel@tonic-gate */ 11670Sstevel@tonic-gate static int 11680Sstevel@tonic-gate pci_name_child(dev_info_t *child, char *name, int namelen) 11690Sstevel@tonic-gate { 11700Sstevel@tonic-gate pci_regspec_t *pci_rp; 11710Sstevel@tonic-gate char **unit_addr; 11720Sstevel@tonic-gate int dev, func, length; 11730Sstevel@tonic-gate uint_t n; 11740Sstevel@tonic-gate 11750Sstevel@tonic-gate if (ndi_dev_is_persistent_node(child) == 0) { 11760Sstevel@tonic-gate /* 11770Sstevel@tonic-gate * For .conf node, use "unit-address" property 11780Sstevel@tonic-gate */ 11790Sstevel@tonic-gate if (ddi_prop_lookup_string_array(DDI_DEV_T_ANY, child, 11800Sstevel@tonic-gate DDI_PROP_DONTPASS, "unit-address", &unit_addr, &n) != 11810Sstevel@tonic-gate DDI_PROP_SUCCESS) { 11820Sstevel@tonic-gate cmn_err(CE_WARN, 11830Sstevel@tonic-gate "cannot find unit-address in %s.conf", 11840Sstevel@tonic-gate ddi_get_name(child)); 11850Sstevel@tonic-gate return (DDI_FAILURE); 11860Sstevel@tonic-gate } 11870Sstevel@tonic-gate if (n != 1 || *unit_addr == NULL || **unit_addr == 0) { 11880Sstevel@tonic-gate cmn_err(CE_WARN, "unit-address property in %s.conf" 11890Sstevel@tonic-gate " not well-formed", ddi_get_name(child)); 11900Sstevel@tonic-gate ddi_prop_free(unit_addr); 11910Sstevel@tonic-gate return (DDI_FAILURE); 11920Sstevel@tonic-gate } 11930Sstevel@tonic-gate (void) snprintf(name, namelen, "%s", *unit_addr); 11940Sstevel@tonic-gate ddi_prop_free(unit_addr); 11950Sstevel@tonic-gate return (DDI_SUCCESS); 11960Sstevel@tonic-gate } 11970Sstevel@tonic-gate 11980Sstevel@tonic-gate if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, child, 11990Sstevel@tonic-gate DDI_PROP_DONTPASS, "reg", (int **)&pci_rp, 12000Sstevel@tonic-gate (uint_t *)&length) != DDI_PROP_SUCCESS) { 12010Sstevel@tonic-gate cmn_err(CE_WARN, "cannot find reg property in %s", 12020Sstevel@tonic-gate ddi_get_name(child)); 12030Sstevel@tonic-gate return (DDI_FAILURE); 12040Sstevel@tonic-gate } 12050Sstevel@tonic-gate 12060Sstevel@tonic-gate /* copy the device identifications */ 12070Sstevel@tonic-gate dev = PCI_REG_DEV_G(pci_rp->pci_phys_hi); 12080Sstevel@tonic-gate func = PCI_REG_FUNC_G(pci_rp->pci_phys_hi); 12090Sstevel@tonic-gate 12100Sstevel@tonic-gate /* 12110Sstevel@tonic-gate * free the memory allocated by ddi_prop_lookup_int_array 12120Sstevel@tonic-gate */ 12130Sstevel@tonic-gate ddi_prop_free(pci_rp); 12140Sstevel@tonic-gate 12150Sstevel@tonic-gate if (func != 0) { 12160Sstevel@tonic-gate (void) snprintf(name, namelen, "%x,%x", dev, func); 12170Sstevel@tonic-gate } else { 12180Sstevel@tonic-gate (void) snprintf(name, namelen, "%x", dev); 12190Sstevel@tonic-gate } 12200Sstevel@tonic-gate 12210Sstevel@tonic-gate return (DDI_SUCCESS); 12220Sstevel@tonic-gate } 12230Sstevel@tonic-gate 12240Sstevel@tonic-gate static int 12250Sstevel@tonic-gate pci_initchild(dev_info_t *child) 12260Sstevel@tonic-gate { 12270Sstevel@tonic-gate struct ddi_parent_private_data *pdptr; 12280Sstevel@tonic-gate char name[80]; 12290Sstevel@tonic-gate 12300Sstevel@tonic-gate if (pci_name_child(child, name, 80) != DDI_SUCCESS) { 12310Sstevel@tonic-gate return (DDI_FAILURE); 12320Sstevel@tonic-gate } 12330Sstevel@tonic-gate ddi_set_name_addr(child, name); 12340Sstevel@tonic-gate 12350Sstevel@tonic-gate /* 12360Sstevel@tonic-gate * Pseudo nodes indicate a prototype node with per-instance 12370Sstevel@tonic-gate * properties to be merged into the real h/w device node. 12380Sstevel@tonic-gate * The interpretation of the unit-address is DD[,F] 12390Sstevel@tonic-gate * where DD is the device id and F is the function. 12400Sstevel@tonic-gate */ 12410Sstevel@tonic-gate if (ndi_dev_is_persistent_node(child) == 0) { 12420Sstevel@tonic-gate extern int pci_allow_pseudo_children; 12430Sstevel@tonic-gate 12440Sstevel@tonic-gate ddi_set_parent_data(child, NULL); 12450Sstevel@tonic-gate 12460Sstevel@tonic-gate /* 12470Sstevel@tonic-gate * Try to merge the properties from this prototype 12480Sstevel@tonic-gate * node into real h/w nodes. 12490Sstevel@tonic-gate */ 12500Sstevel@tonic-gate if (ndi_merge_node(child, pci_name_child) == DDI_SUCCESS) { 12510Sstevel@tonic-gate /* 12520Sstevel@tonic-gate * Merged ok - return failure to remove the node. 12530Sstevel@tonic-gate */ 12540Sstevel@tonic-gate ddi_set_name_addr(child, NULL); 12550Sstevel@tonic-gate return (DDI_FAILURE); 12560Sstevel@tonic-gate } 12570Sstevel@tonic-gate 12580Sstevel@tonic-gate /* workaround for ddivs to run under PCI */ 12590Sstevel@tonic-gate if (pci_allow_pseudo_children) { 12600Sstevel@tonic-gate /* 12610Sstevel@tonic-gate * If the "interrupts" property doesn't exist, 12620Sstevel@tonic-gate * this must be the ddivs no-intr case, and it returns 12630Sstevel@tonic-gate * DDI_SUCCESS instead of DDI_FAILURE. 12640Sstevel@tonic-gate */ 12650Sstevel@tonic-gate if (ddi_prop_get_int(DDI_DEV_T_ANY, child, 12660Sstevel@tonic-gate DDI_PROP_DONTPASS, "interrupts", -1) == -1) 12670Sstevel@tonic-gate return (DDI_SUCCESS); 12680Sstevel@tonic-gate /* 12690Sstevel@tonic-gate * Create the ddi_parent_private_data for a pseudo 12700Sstevel@tonic-gate * child. 12710Sstevel@tonic-gate */ 12720Sstevel@tonic-gate pdptr = (struct ddi_parent_private_data *)kmem_zalloc( 12730Sstevel@tonic-gate (sizeof (struct ddi_parent_private_data) + 12740Sstevel@tonic-gate sizeof (struct intrspec)), KM_SLEEP); 12750Sstevel@tonic-gate pdptr->par_intr = (struct intrspec *)(pdptr + 1); 12760Sstevel@tonic-gate pdptr->par_nintr = 1; 12770Sstevel@tonic-gate ddi_set_parent_data(child, pdptr); 12780Sstevel@tonic-gate return (DDI_SUCCESS); 12790Sstevel@tonic-gate } 12800Sstevel@tonic-gate 12810Sstevel@tonic-gate /* 12820Sstevel@tonic-gate * The child was not merged into a h/w node, 12830Sstevel@tonic-gate * but there's not much we can do with it other 12840Sstevel@tonic-gate * than return failure to cause the node to be removed. 12850Sstevel@tonic-gate */ 12860Sstevel@tonic-gate cmn_err(CE_WARN, "!%s@%s: %s.conf properties not merged", 12870Sstevel@tonic-gate ddi_get_name(child), ddi_get_name_addr(child), 12880Sstevel@tonic-gate ddi_get_name(child)); 12890Sstevel@tonic-gate ddi_set_name_addr(child, NULL); 12900Sstevel@tonic-gate return (DDI_NOT_WELL_FORMED); 12910Sstevel@tonic-gate } 12920Sstevel@tonic-gate 12930Sstevel@tonic-gate if (ddi_prop_get_int(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS, 12940Sstevel@tonic-gate "interrupts", -1) != -1) { 12950Sstevel@tonic-gate pdptr = (struct ddi_parent_private_data *) 12960Sstevel@tonic-gate kmem_zalloc((sizeof (struct ddi_parent_private_data) + 12970Sstevel@tonic-gate sizeof (struct intrspec)), KM_SLEEP); 12980Sstevel@tonic-gate pdptr->par_intr = (struct intrspec *)(pdptr + 1); 12990Sstevel@tonic-gate pdptr->par_nintr = 1; 13000Sstevel@tonic-gate ddi_set_parent_data(child, pdptr); 13010Sstevel@tonic-gate } else 13020Sstevel@tonic-gate ddi_set_parent_data(child, NULL); 13030Sstevel@tonic-gate 13040Sstevel@tonic-gate return (DDI_SUCCESS); 13050Sstevel@tonic-gate } 13060Sstevel@tonic-gate 13070Sstevel@tonic-gate static int 13080Sstevel@tonic-gate pci_removechild(dev_info_t *dip) 13090Sstevel@tonic-gate { 13100Sstevel@tonic-gate struct ddi_parent_private_data *pdptr; 13110Sstevel@tonic-gate 13120Sstevel@tonic-gate if ((pdptr = ddi_get_parent_data(dip)) != NULL) { 13130Sstevel@tonic-gate kmem_free(pdptr, (sizeof (*pdptr) + sizeof (struct intrspec))); 13140Sstevel@tonic-gate ddi_set_parent_data(dip, NULL); 13150Sstevel@tonic-gate } 13160Sstevel@tonic-gate ddi_set_name_addr(dip, NULL); 13170Sstevel@tonic-gate 13180Sstevel@tonic-gate /* 13190Sstevel@tonic-gate * Strip the node to properly convert it back to prototype form 13200Sstevel@tonic-gate */ 13210Sstevel@tonic-gate ddi_remove_minor_node(dip, NULL); 13220Sstevel@tonic-gate 13230Sstevel@tonic-gate impl_rem_dev_props(dip); 13240Sstevel@tonic-gate 13250Sstevel@tonic-gate return (DDI_SUCCESS); 13260Sstevel@tonic-gate } 13270Sstevel@tonic-gate 13280Sstevel@tonic-gate 13290Sstevel@tonic-gate /* 13300Sstevel@tonic-gate * These are the get and put functions to be shared with drivers. The 13310Sstevel@tonic-gate * mutex locking is done inside the functions referenced, rather than 13320Sstevel@tonic-gate * here, and is thus shared across PCI child drivers and any other 13330Sstevel@tonic-gate * consumers of PCI config space (such as the ACPI subsystem). 13340Sstevel@tonic-gate * 13350Sstevel@tonic-gate * The configuration space addresses come in as pointers. This is fine on 13360Sstevel@tonic-gate * a 32-bit system, where the VM space and configuration space are the same 13370Sstevel@tonic-gate * size. It's not such a good idea on a 64-bit system, where memory 13380Sstevel@tonic-gate * addresses are twice as large as configuration space addresses. At some 13390Sstevel@tonic-gate * point in the call tree we need to take a stand and say "you are 32-bit 13400Sstevel@tonic-gate * from this time forth", and this seems like a nice self-contained place. 13410Sstevel@tonic-gate */ 13420Sstevel@tonic-gate 13430Sstevel@tonic-gate static uint8_t 13440Sstevel@tonic-gate pci_config_rd8(ddi_acc_impl_t *hdlp, uint8_t *addr) 13450Sstevel@tonic-gate { 13460Sstevel@tonic-gate pci_acc_cfblk_t *cfp; 13470Sstevel@tonic-gate uint8_t rval; 13480Sstevel@tonic-gate int reg; 13490Sstevel@tonic-gate 13500Sstevel@tonic-gate ASSERT64(((uintptr_t)addr >> 32) == 0); 13510Sstevel@tonic-gate 13520Sstevel@tonic-gate reg = (int)(uintptr_t)addr; 13530Sstevel@tonic-gate 13540Sstevel@tonic-gate cfp = (pci_acc_cfblk_t *)&hdlp->ahi_common.ah_bus_private; 13550Sstevel@tonic-gate 13560Sstevel@tonic-gate rval = (*pci_getb_func)(cfp->c_busnum, cfp->c_devnum, cfp->c_funcnum, 13570Sstevel@tonic-gate reg); 13580Sstevel@tonic-gate 13590Sstevel@tonic-gate return (rval); 13600Sstevel@tonic-gate } 13610Sstevel@tonic-gate 13620Sstevel@tonic-gate static void 13630Sstevel@tonic-gate pci_config_rep_rd8(ddi_acc_impl_t *hdlp, uint8_t *host_addr, 13640Sstevel@tonic-gate uint8_t *dev_addr, size_t repcount, uint_t flags) 13650Sstevel@tonic-gate { 13660Sstevel@tonic-gate uint8_t *h, *d; 13670Sstevel@tonic-gate 13680Sstevel@tonic-gate h = host_addr; 13690Sstevel@tonic-gate d = dev_addr; 13700Sstevel@tonic-gate 13710Sstevel@tonic-gate if (flags == DDI_DEV_AUTOINCR) 13720Sstevel@tonic-gate for (; repcount; repcount--) 13730Sstevel@tonic-gate *h++ = pci_config_rd8(hdlp, d++); 13740Sstevel@tonic-gate else 13750Sstevel@tonic-gate for (; repcount; repcount--) 13760Sstevel@tonic-gate *h++ = pci_config_rd8(hdlp, d); 13770Sstevel@tonic-gate } 13780Sstevel@tonic-gate 13790Sstevel@tonic-gate static uint16_t 13800Sstevel@tonic-gate pci_config_rd16(ddi_acc_impl_t *hdlp, uint16_t *addr) 13810Sstevel@tonic-gate { 13820Sstevel@tonic-gate pci_acc_cfblk_t *cfp; 13830Sstevel@tonic-gate uint16_t rval; 13840Sstevel@tonic-gate int reg; 13850Sstevel@tonic-gate 13860Sstevel@tonic-gate ASSERT64(((uintptr_t)addr >> 32) == 0); 13870Sstevel@tonic-gate 13880Sstevel@tonic-gate reg = (int)(uintptr_t)addr; 13890Sstevel@tonic-gate 13900Sstevel@tonic-gate cfp = (pci_acc_cfblk_t *)&hdlp->ahi_common.ah_bus_private; 13910Sstevel@tonic-gate 13920Sstevel@tonic-gate rval = (*pci_getw_func)(cfp->c_busnum, cfp->c_devnum, cfp->c_funcnum, 13930Sstevel@tonic-gate reg); 13940Sstevel@tonic-gate 13950Sstevel@tonic-gate return (rval); 13960Sstevel@tonic-gate } 13970Sstevel@tonic-gate 13980Sstevel@tonic-gate static void 13990Sstevel@tonic-gate pci_config_rep_rd16(ddi_acc_impl_t *hdlp, uint16_t *host_addr, 14000Sstevel@tonic-gate uint16_t *dev_addr, size_t repcount, uint_t flags) 14010Sstevel@tonic-gate { 14020Sstevel@tonic-gate uint16_t *h, *d; 14030Sstevel@tonic-gate 14040Sstevel@tonic-gate h = host_addr; 14050Sstevel@tonic-gate d = dev_addr; 14060Sstevel@tonic-gate 14070Sstevel@tonic-gate if (flags == DDI_DEV_AUTOINCR) 14080Sstevel@tonic-gate for (; repcount; repcount--) 14090Sstevel@tonic-gate *h++ = pci_config_rd16(hdlp, d++); 14100Sstevel@tonic-gate else 14110Sstevel@tonic-gate for (; repcount; repcount--) 14120Sstevel@tonic-gate *h++ = pci_config_rd16(hdlp, d); 14130Sstevel@tonic-gate } 14140Sstevel@tonic-gate 14150Sstevel@tonic-gate static uint32_t 14160Sstevel@tonic-gate pci_config_rd32(ddi_acc_impl_t *hdlp, uint32_t *addr) 14170Sstevel@tonic-gate { 14180Sstevel@tonic-gate pci_acc_cfblk_t *cfp; 14190Sstevel@tonic-gate uint32_t rval; 14200Sstevel@tonic-gate int reg; 14210Sstevel@tonic-gate 14220Sstevel@tonic-gate ASSERT64(((uintptr_t)addr >> 32) == 0); 14230Sstevel@tonic-gate 14240Sstevel@tonic-gate reg = (int)(uintptr_t)addr; 14250Sstevel@tonic-gate 14260Sstevel@tonic-gate cfp = (pci_acc_cfblk_t *)&hdlp->ahi_common.ah_bus_private; 14270Sstevel@tonic-gate 14280Sstevel@tonic-gate rval = (*pci_getl_func)(cfp->c_busnum, cfp->c_devnum, 14290Sstevel@tonic-gate cfp->c_funcnum, reg); 14300Sstevel@tonic-gate 14310Sstevel@tonic-gate return (rval); 14320Sstevel@tonic-gate } 14330Sstevel@tonic-gate 14340Sstevel@tonic-gate static void 14350Sstevel@tonic-gate pci_config_rep_rd32(ddi_acc_impl_t *hdlp, uint32_t *host_addr, 14360Sstevel@tonic-gate uint32_t *dev_addr, size_t repcount, uint_t flags) 14370Sstevel@tonic-gate { 14380Sstevel@tonic-gate uint32_t *h, *d; 14390Sstevel@tonic-gate 14400Sstevel@tonic-gate h = host_addr; 14410Sstevel@tonic-gate d = dev_addr; 14420Sstevel@tonic-gate 14430Sstevel@tonic-gate if (flags == DDI_DEV_AUTOINCR) 14440Sstevel@tonic-gate for (; repcount; repcount--) 14450Sstevel@tonic-gate *h++ = pci_config_rd32(hdlp, d++); 14460Sstevel@tonic-gate else 14470Sstevel@tonic-gate for (; repcount; repcount--) 14480Sstevel@tonic-gate *h++ = pci_config_rd32(hdlp, d); 14490Sstevel@tonic-gate } 14500Sstevel@tonic-gate 14510Sstevel@tonic-gate 14520Sstevel@tonic-gate static void 14530Sstevel@tonic-gate pci_config_wr8(ddi_acc_impl_t *hdlp, uint8_t *addr, uint8_t value) 14540Sstevel@tonic-gate { 14550Sstevel@tonic-gate pci_acc_cfblk_t *cfp; 14560Sstevel@tonic-gate int reg; 14570Sstevel@tonic-gate 14580Sstevel@tonic-gate ASSERT64(((uintptr_t)addr >> 32) == 0); 14590Sstevel@tonic-gate 14600Sstevel@tonic-gate reg = (int)(uintptr_t)addr; 14610Sstevel@tonic-gate 14620Sstevel@tonic-gate cfp = (pci_acc_cfblk_t *)&hdlp->ahi_common.ah_bus_private; 14630Sstevel@tonic-gate 14640Sstevel@tonic-gate (*pci_putb_func)(cfp->c_busnum, cfp->c_devnum, 14650Sstevel@tonic-gate cfp->c_funcnum, reg, value); 14660Sstevel@tonic-gate } 14670Sstevel@tonic-gate 14680Sstevel@tonic-gate static void 14690Sstevel@tonic-gate pci_config_rep_wr8(ddi_acc_impl_t *hdlp, uint8_t *host_addr, 14700Sstevel@tonic-gate uint8_t *dev_addr, size_t repcount, uint_t flags) 14710Sstevel@tonic-gate { 14720Sstevel@tonic-gate uint8_t *h, *d; 14730Sstevel@tonic-gate 14740Sstevel@tonic-gate h = host_addr; 14750Sstevel@tonic-gate d = dev_addr; 14760Sstevel@tonic-gate 14770Sstevel@tonic-gate if (flags == DDI_DEV_AUTOINCR) 14780Sstevel@tonic-gate for (; repcount; repcount--) 14790Sstevel@tonic-gate pci_config_wr8(hdlp, d++, *h++); 14800Sstevel@tonic-gate else 14810Sstevel@tonic-gate for (; repcount; repcount--) 14820Sstevel@tonic-gate pci_config_wr8(hdlp, d, *h++); 14830Sstevel@tonic-gate } 14840Sstevel@tonic-gate 14850Sstevel@tonic-gate static void 14860Sstevel@tonic-gate pci_config_wr16(ddi_acc_impl_t *hdlp, uint16_t *addr, uint16_t value) 14870Sstevel@tonic-gate { 14880Sstevel@tonic-gate pci_acc_cfblk_t *cfp; 14890Sstevel@tonic-gate int reg; 14900Sstevel@tonic-gate 14910Sstevel@tonic-gate ASSERT64(((uintptr_t)addr >> 32) == 0); 14920Sstevel@tonic-gate 14930Sstevel@tonic-gate reg = (int)(uintptr_t)addr; 14940Sstevel@tonic-gate 14950Sstevel@tonic-gate cfp = (pci_acc_cfblk_t *)&hdlp->ahi_common.ah_bus_private; 14960Sstevel@tonic-gate 14970Sstevel@tonic-gate (*pci_putw_func)(cfp->c_busnum, cfp->c_devnum, 14980Sstevel@tonic-gate cfp->c_funcnum, reg, value); 14990Sstevel@tonic-gate } 15000Sstevel@tonic-gate 15010Sstevel@tonic-gate static void 15020Sstevel@tonic-gate pci_config_rep_wr16(ddi_acc_impl_t *hdlp, uint16_t *host_addr, 15030Sstevel@tonic-gate uint16_t *dev_addr, size_t repcount, uint_t flags) 15040Sstevel@tonic-gate { 15050Sstevel@tonic-gate uint16_t *h, *d; 15060Sstevel@tonic-gate 15070Sstevel@tonic-gate h = host_addr; 15080Sstevel@tonic-gate d = dev_addr; 15090Sstevel@tonic-gate 15100Sstevel@tonic-gate if (flags == DDI_DEV_AUTOINCR) 15110Sstevel@tonic-gate for (; repcount; repcount--) 15120Sstevel@tonic-gate pci_config_wr16(hdlp, d++, *h++); 15130Sstevel@tonic-gate else 15140Sstevel@tonic-gate for (; repcount; repcount--) 15150Sstevel@tonic-gate pci_config_wr16(hdlp, d, *h++); 15160Sstevel@tonic-gate } 15170Sstevel@tonic-gate 15180Sstevel@tonic-gate static void 15190Sstevel@tonic-gate pci_config_wr32(ddi_acc_impl_t *hdlp, uint32_t *addr, uint32_t value) 15200Sstevel@tonic-gate { 15210Sstevel@tonic-gate pci_acc_cfblk_t *cfp; 15220Sstevel@tonic-gate int reg; 15230Sstevel@tonic-gate 15240Sstevel@tonic-gate ASSERT64(((uintptr_t)addr >> 32) == 0); 15250Sstevel@tonic-gate 15260Sstevel@tonic-gate reg = (int)(uintptr_t)addr; 15270Sstevel@tonic-gate 15280Sstevel@tonic-gate cfp = (pci_acc_cfblk_t *)&hdlp->ahi_common.ah_bus_private; 15290Sstevel@tonic-gate 15300Sstevel@tonic-gate (*pci_putl_func)(cfp->c_busnum, cfp->c_devnum, 15310Sstevel@tonic-gate cfp->c_funcnum, reg, value); 15320Sstevel@tonic-gate } 15330Sstevel@tonic-gate 15340Sstevel@tonic-gate static void 15350Sstevel@tonic-gate pci_config_rep_wr32(ddi_acc_impl_t *hdlp, uint32_t *host_addr, 15360Sstevel@tonic-gate uint32_t *dev_addr, size_t repcount, uint_t flags) 15370Sstevel@tonic-gate { 15380Sstevel@tonic-gate uint32_t *h, *d; 15390Sstevel@tonic-gate 15400Sstevel@tonic-gate h = host_addr; 15410Sstevel@tonic-gate d = dev_addr; 15420Sstevel@tonic-gate 15430Sstevel@tonic-gate if (flags == DDI_DEV_AUTOINCR) 15440Sstevel@tonic-gate for (; repcount; repcount--) 15450Sstevel@tonic-gate pci_config_wr32(hdlp, d++, *h++); 15460Sstevel@tonic-gate else 15470Sstevel@tonic-gate for (; repcount; repcount--) 15480Sstevel@tonic-gate pci_config_wr32(hdlp, d, *h++); 15490Sstevel@tonic-gate } 15500Sstevel@tonic-gate 15510Sstevel@tonic-gate static uint64_t 15520Sstevel@tonic-gate pci_config_rd64(ddi_acc_impl_t *hdlp, uint64_t *addr) 15530Sstevel@tonic-gate { 15540Sstevel@tonic-gate uint32_t lw_val; 15550Sstevel@tonic-gate uint32_t hi_val; 15560Sstevel@tonic-gate uint32_t *dp; 15570Sstevel@tonic-gate uint64_t val; 15580Sstevel@tonic-gate 15590Sstevel@tonic-gate dp = (uint32_t *)addr; 15600Sstevel@tonic-gate lw_val = pci_config_rd32(hdlp, dp); 15610Sstevel@tonic-gate dp++; 15620Sstevel@tonic-gate hi_val = pci_config_rd32(hdlp, dp); 15630Sstevel@tonic-gate val = ((uint64_t)hi_val << 32) | lw_val; 15640Sstevel@tonic-gate return (val); 15650Sstevel@tonic-gate } 15660Sstevel@tonic-gate 15670Sstevel@tonic-gate static void 15680Sstevel@tonic-gate pci_config_wr64(ddi_acc_impl_t *hdlp, uint64_t *addr, uint64_t value) 15690Sstevel@tonic-gate { 15700Sstevel@tonic-gate uint32_t lw_val; 15710Sstevel@tonic-gate uint32_t hi_val; 15720Sstevel@tonic-gate uint32_t *dp; 15730Sstevel@tonic-gate 15740Sstevel@tonic-gate dp = (uint32_t *)addr; 15750Sstevel@tonic-gate lw_val = (uint32_t)(value & 0xffffffff); 15760Sstevel@tonic-gate hi_val = (uint32_t)(value >> 32); 15770Sstevel@tonic-gate pci_config_wr32(hdlp, dp, lw_val); 15780Sstevel@tonic-gate dp++; 15790Sstevel@tonic-gate pci_config_wr32(hdlp, dp, hi_val); 15800Sstevel@tonic-gate } 15810Sstevel@tonic-gate 15820Sstevel@tonic-gate static void 15830Sstevel@tonic-gate pci_config_rep_rd64(ddi_acc_impl_t *hdlp, uint64_t *host_addr, 15840Sstevel@tonic-gate uint64_t *dev_addr, size_t repcount, uint_t flags) 15850Sstevel@tonic-gate { 15860Sstevel@tonic-gate if (flags == DDI_DEV_AUTOINCR) { 15870Sstevel@tonic-gate for (; repcount; repcount--) 15880Sstevel@tonic-gate *host_addr++ = pci_config_rd64(hdlp, dev_addr++); 15890Sstevel@tonic-gate } else { 15900Sstevel@tonic-gate for (; repcount; repcount--) 15910Sstevel@tonic-gate *host_addr++ = pci_config_rd64(hdlp, dev_addr); 15920Sstevel@tonic-gate } 15930Sstevel@tonic-gate } 15940Sstevel@tonic-gate 15950Sstevel@tonic-gate static void 15960Sstevel@tonic-gate pci_config_rep_wr64(ddi_acc_impl_t *hdlp, uint64_t *host_addr, 15970Sstevel@tonic-gate uint64_t *dev_addr, size_t repcount, uint_t flags) 15980Sstevel@tonic-gate { 15990Sstevel@tonic-gate if (flags == DDI_DEV_AUTOINCR) { 16000Sstevel@tonic-gate for (; repcount; repcount--) 16010Sstevel@tonic-gate pci_config_wr64(hdlp, host_addr++, *dev_addr++); 16020Sstevel@tonic-gate } else { 16030Sstevel@tonic-gate for (; repcount; repcount--) 16040Sstevel@tonic-gate pci_config_wr64(hdlp, host_addr++, *dev_addr); 16050Sstevel@tonic-gate } 16060Sstevel@tonic-gate } 16070Sstevel@tonic-gate 16080Sstevel@tonic-gate /* 16090Sstevel@tonic-gate * When retrofitting this module for pci_tools, functions such as open, close, 16100Sstevel@tonic-gate * and ioctl are now pulled into this module. Before this, the functions in 16110Sstevel@tonic-gate * the pcihp module were referenced directly. Now they are called or 16120Sstevel@tonic-gate * referenced through the pcihp cb_ops structure from functions in this module. 16130Sstevel@tonic-gate */ 16140Sstevel@tonic-gate 16150Sstevel@tonic-gate static int 16160Sstevel@tonic-gate pci_open(dev_t *devp, int flags, int otyp, cred_t *credp) 16170Sstevel@tonic-gate { 16180Sstevel@tonic-gate return ((pcihp_cb_ops.cb_open)(devp, flags, otyp, credp)); 16190Sstevel@tonic-gate } 16200Sstevel@tonic-gate 16210Sstevel@tonic-gate static int 16220Sstevel@tonic-gate pci_close(dev_t dev, int flags, int otyp, cred_t *credp) 16230Sstevel@tonic-gate { 16240Sstevel@tonic-gate return ((pcihp_cb_ops.cb_close)(dev, flags, otyp, credp)); 16250Sstevel@tonic-gate } 16260Sstevel@tonic-gate 16270Sstevel@tonic-gate static int 16280Sstevel@tonic-gate pci_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, cred_t *credp, 16290Sstevel@tonic-gate int *rvalp) 16300Sstevel@tonic-gate { 16310Sstevel@tonic-gate int rv = ENOTTY; 16320Sstevel@tonic-gate 1633*117Sschwartz minor_t minor = getminor(dev); 16340Sstevel@tonic-gate 1635*117Sschwartz switch (PCIHP_AP_MINOR_NUM_TO_PCI_DEVNUM(minor)) { 1636*117Sschwartz case PCIHP_DEVCTL_MINOR: 1637*117Sschwartz if (IS_DEVCTL(cmd)) 1638*117Sschwartz rv = (pcihp_cb_ops.cb_ioctl)(dev, cmd, arg, mode, 1639*117Sschwartz credp, rvalp); 1640*117Sschwartz break; 16410Sstevel@tonic-gate 1642*117Sschwartz case PCI_TOOL_REG_MINOR_NUM: 1643*117Sschwartz 16440Sstevel@tonic-gate switch (cmd) { 16450Sstevel@tonic-gate case PCITOOL_DEVICE_SET_REG: 16460Sstevel@tonic-gate case PCITOOL_DEVICE_GET_REG: 16470Sstevel@tonic-gate 16480Sstevel@tonic-gate /* Require full privileges. */ 16490Sstevel@tonic-gate if (secpolicy_kmdb(credp)) 16500Sstevel@tonic-gate rv = EPERM; 16510Sstevel@tonic-gate else 16520Sstevel@tonic-gate rv = pcitool_dev_reg_ops( 16530Sstevel@tonic-gate dev, (void *)arg, cmd, mode); 16540Sstevel@tonic-gate break; 16550Sstevel@tonic-gate 16560Sstevel@tonic-gate case PCITOOL_NEXUS_SET_REG: 16570Sstevel@tonic-gate case PCITOOL_NEXUS_GET_REG: 16580Sstevel@tonic-gate 16590Sstevel@tonic-gate /* Require full privileges. */ 16600Sstevel@tonic-gate if (secpolicy_kmdb(credp)) 16610Sstevel@tonic-gate rv = EPERM; 16620Sstevel@tonic-gate else 16630Sstevel@tonic-gate rv = pcitool_bus_reg_ops( 16640Sstevel@tonic-gate dev, (void *)arg, cmd, mode); 16650Sstevel@tonic-gate break; 1666*117Sschwartz } 1667*117Sschwartz break; 16680Sstevel@tonic-gate 1669*117Sschwartz case PCI_TOOL_INTR_MINOR_NUM: 1670*117Sschwartz 1671*117Sschwartz switch (cmd) { 16720Sstevel@tonic-gate case PCITOOL_DEVICE_SET_INTR: 16730Sstevel@tonic-gate 1674*117Sschwartz /* Require PRIV_SYS_RES_CONFIG, same as psradm */ 16750Sstevel@tonic-gate if (secpolicy_ponline(credp)) { 16760Sstevel@tonic-gate rv = EPERM; 16770Sstevel@tonic-gate break; 16780Sstevel@tonic-gate } 16790Sstevel@tonic-gate 16800Sstevel@tonic-gate /*FALLTHRU*/ 16810Sstevel@tonic-gate /* These require no special privileges. */ 16820Sstevel@tonic-gate case PCITOOL_DEVICE_GET_INTR: 16830Sstevel@tonic-gate case PCITOOL_DEVICE_NUM_INTR: 16840Sstevel@tonic-gate rv = pcitool_intr_admn(dev, (void *)arg, cmd, mode); 16850Sstevel@tonic-gate break; 1686*117Sschwartz } 1687*117Sschwartz break; 16880Sstevel@tonic-gate 1689*117Sschwartz default: 1690*117Sschwartz break; 16910Sstevel@tonic-gate } 16920Sstevel@tonic-gate 16930Sstevel@tonic-gate return (rv); 16940Sstevel@tonic-gate } 16950Sstevel@tonic-gate 16960Sstevel@tonic-gate static int 16970Sstevel@tonic-gate pci_prop_op(dev_t dev, dev_info_t *dip, ddi_prop_op_t prop_op, 1698*117Sschwartz int flags, char *name, caddr_t valuep, int *lengthp) 16990Sstevel@tonic-gate { 17000Sstevel@tonic-gate return ((pcihp_cb_ops.cb_prop_op)(dev, dip, prop_op, flags, 17010Sstevel@tonic-gate name, valuep, lengthp)); 17020Sstevel@tonic-gate } 17030Sstevel@tonic-gate 17040Sstevel@tonic-gate static int 17050Sstevel@tonic-gate pci_info(dev_info_t *dip, ddi_info_cmd_t cmd, void *arg, void **result) 17060Sstevel@tonic-gate { 17070Sstevel@tonic-gate return (pcihp_info(dip, cmd, arg, result)); 17080Sstevel@tonic-gate } 1709