npe.c revision 00d0963faf2e861a4aef6b1bf28f99a5b2b20755
70025d765b044c6d8594bb965a2247a61e991a99johnny * CDDL HEADER START
70025d765b044c6d8594bb965a2247a61e991a99johnny * The contents of this file are subject to the terms of the
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet * Common Development and Distribution License (the "License").
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet * You may not use this file except in compliance with the License.
70025d765b044c6d8594bb965a2247a61e991a99johnny * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
70025d765b044c6d8594bb965a2247a61e991a99johnny * See the License for the specific language governing permissions
70025d765b044c6d8594bb965a2247a61e991a99johnny * and limitations under the License.
70025d765b044c6d8594bb965a2247a61e991a99johnny * When distributing Covered Code, include this CDDL HEADER in each
70025d765b044c6d8594bb965a2247a61e991a99johnny * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
70025d765b044c6d8594bb965a2247a61e991a99johnny * If applicable, add the following below this CDDL HEADER, with the
70025d765b044c6d8594bb965a2247a61e991a99johnny * fields enclosed by brackets "[]" replaced with your own identifying
70025d765b044c6d8594bb965a2247a61e991a99johnny * information: Portions Copyright [yyyy] [name of copyright owner]
70025d765b044c6d8594bb965a2247a61e991a99johnny * CDDL HEADER END
247980bee8b0de250570942681f1567bd54ad984anish * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
70025d765b044c6d8594bb965a2247a61e991a99johnny * Use is subject to license terms.
70025d765b044c6d8594bb965a2247a61e991a99johnny#pragma ident "%Z%%M% %I% %E% SMI"
70025d765b044c6d8594bb965a2247a61e991a99johnny * Host to PCI-Express local bus driver
70025d765b044c6d8594bb965a2247a61e991a99johnny * Bus Operation functions
70025d765b044c6d8594bb965a2247a61e991a99johnnystatic int npe_bus_map(dev_info_t *, dev_info_t *, ddi_map_req_t *,
70025d765b044c6d8594bb965a2247a61e991a99johnnystatic int npe_ctlops(dev_info_t *, dev_info_t *, ddi_ctl_enum_t,
70025d765b044c6d8594bb965a2247a61e991a99johnny void *, void *);
70025d765b044c6d8594bb965a2247a61e991a99johnnystatic int npe_intr_ops(dev_info_t *, dev_info_t *, ddi_intr_op_t,
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreetstatic int npe_fm_init(dev_info_t *, dev_info_t *, int,
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreetstatic int npe_fm_callback(dev_info_t *, ddi_fm_error_t *, const void *);
70025d765b044c6d8594bb965a2247a61e991a99johnny 0, /* (*bus_get_eventcookie)(); */
70025d765b044c6d8594bb965a2247a61e991a99johnny 0, /* (*bus_add_eventcall)(); */
70025d765b044c6d8594bb965a2247a61e991a99johnny 0, /* (*bus_remove_eventcall)(); */
70025d765b044c6d8594bb965a2247a61e991a99johnny 0, /* (*bus_post_event)(); */
70025d765b044c6d8594bb965a2247a61e991a99johnny 0, /* (*bus_intr_ctl)(); */
70025d765b044c6d8594bb965a2247a61e991a99johnny 0, /* (*bus_config)(); */
70025d765b044c6d8594bb965a2247a61e991a99johnny 0, /* (*bus_unconfig)(); */
70025d765b044c6d8594bb965a2247a61e991a99johnny * One goal here is to leverage off of the pcihp.c source without making
70025d765b044c6d8594bb965a2247a61e991a99johnny * changes to it. Call into it's cb_ops directly if needed, piggybacking
70025d765b044c6d8594bb965a2247a61e991a99johnny * anything else needed by the pci_tools.c module. Only pci_tools and pcihp
70025d765b044c6d8594bb965a2247a61e991a99johnny * will be using the PCI devctl node.
70025d765b044c6d8594bb965a2247a61e991a99johnnystatic int npe_ioctl(dev_t, int, intptr_t, int, cred_t *, int *);
70025d765b044c6d8594bb965a2247a61e991a99johnnystatic int npe_prop_op(dev_t, dev_info_t *, ddi_prop_op_t, int, char *,
70025d765b044c6d8594bb965a2247a61e991a99johnnystatic int npe_info(dev_info_t *, ddi_info_cmd_t, void *, void **);
70025d765b044c6d8594bb965a2247a61e991a99johnny D_NEW | D_MP | D_HOTPLUG, /* Driver compatibility flag */
70025d765b044c6d8594bb965a2247a61e991a99johnny * Device Node Operation functions
70025d765b044c6d8594bb965a2247a61e991a99johnnystatic int npe_attach(dev_info_t *devi, ddi_attach_cmd_t cmd);
70025d765b044c6d8594bb965a2247a61e991a99johnnystatic int npe_detach(dev_info_t *devi, ddi_detach_cmd_t cmd);
70025d765b044c6d8594bb965a2247a61e991a99johnny 0, /* refcnt */
70025d765b044c6d8594bb965a2247a61e991a99johnny * Internal routines in support of particular npe_ctlops.
70025d765b044c6d8594bb965a2247a61e991a99johnny * External support routine
70025d765b044c6d8594bb965a2247a61e991a99johnny * Module linkage information for the kernel.
70025d765b044c6d8594bb965a2247a61e991a99johnny "Host to PCIe nexus driver %I%",
70025d765b044c6d8594bb965a2247a61e991a99johnny/* Save minimal state. */
70025d765b044c6d8594bb965a2247a61e991a99johnny * Initialize per-pci bus soft state pointer.
70025d765b044c6d8594bb965a2247a61e991a99johnny e = ddi_soft_state_init(&npe_statep, sizeof (pci_state_t), 1);
70025d765b044c6d8594bb965a2247a61e991a99johnny if (e != 0)
70025d765b044c6d8594bb965a2247a61e991a99johnny return (e);
70025d765b044c6d8594bb965a2247a61e991a99johnny return (e);
70025d765b044c6d8594bb965a2247a61e991a99johnny/*ARGSUSED*/
70025d765b044c6d8594bb965a2247a61e991a99johnny * Use the minor number as constructed by pcihp, as the index value to
70025d765b044c6d8594bb965a2247a61e991a99johnny * ddi_soft_state_zalloc.
70025d765b044c6d8594bb965a2247a61e991a99johnny if (ddi_prop_update_string(DDI_DEV_T_NONE, devi, "device_type",
70025d765b044c6d8594bb965a2247a61e991a99johnny cmn_err(CE_WARN, "npe: 'device_type' prop create failed");
70025d765b044c6d8594bb965a2247a61e991a99johnny if (ddi_soft_state_zalloc(npe_statep, instance) == DDI_SUCCESS)
70025d765b044c6d8594bb965a2247a61e991a99johnny * Initialize hotplug support on this bus. At minimum
70025d765b044c6d8594bb965a2247a61e991a99johnny * (for non hotplug bus) this would create ":devctl" minor
70025d765b044c6d8594bb965a2247a61e991a99johnny * node to support DEVCTL_DEVICE_* and DEVCTL_BUS_* ioctls
70025d765b044c6d8594bb965a2247a61e991a99johnny * to this bus.
70025d765b044c6d8594bb965a2247a61e991a99johnny cmn_err(CE_WARN, "npe: Failed to setup hotplug framework");
7a364d25fde47aa82704b12b5251bf7fac37f02eschwartz /* Second arg: initialize for pci_express root nexus */
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet pcip->pci_fmcap = DDI_FM_EREPORT_CAPABLE | DDI_FM_ERRCB_CAPABLE |
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet ddi_fm_init(devi, &pcip->pci_fmcap, &pcip->pci_fm_ibc);
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet ddi_fm_handler_register(devi, npe_fm_callback, NULL);
70025d765b044c6d8594bb965a2247a61e991a99johnny/*ARGSUSED*/
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet pcip = ddi_get_soft_state(npe_statep, ddi_get_instance(devi));
70025d765b044c6d8594bb965a2247a61e991a99johnny /* Uninitialize pcitool support. */
70025d765b044c6d8594bb965a2247a61e991a99johnny * Uninitialize hotplug support on this bus.
70025d765b044c6d8594bb965a2247a61e991a99johnnynpe_bus_map(dev_info_t *dip, dev_info_t *rdip, ddi_map_req_t *mp,
70025d765b044c6d8594bb965a2247a61e991a99johnny * check for register number
70025d765b044c6d8594bb965a2247a61e991a99johnny if (pci_common_get_reg_prop(rdip, pci_rp) != DDI_SUCCESS)
70025d765b044c6d8594bb965a2247a61e991a99johnny * get ALL "reg" properties for dip, select the one of
70025d765b044c6d8594bb965a2247a61e991a99johnny * of interest. In x86, "assigned-addresses" property
70025d765b044c6d8594bb965a2247a61e991a99johnny * is identical to the "reg" property, so there is no
70025d765b044c6d8594bb965a2247a61e991a99johnny * need to cross check the two to determine the physical
70025d765b044c6d8594bb965a2247a61e991a99johnny * address of the registers.
70025d765b044c6d8594bb965a2247a61e991a99johnny * This routine still performs some validity checks to
70025d765b044c6d8594bb965a2247a61e991a99johnny * make sure that everything is okay.
70025d765b044c6d8594bb965a2247a61e991a99johnny * validate the register number.
70025d765b044c6d8594bb965a2247a61e991a99johnny * copy the required entry.
70025d765b044c6d8594bb965a2247a61e991a99johnny * free the memory allocated by ddi_prop_lookup_int_array
70025d765b044c6d8594bb965a2247a61e991a99johnny if (pci_common_get_reg_prop(rdip, pci_rp) != DDI_SUCCESS)
70025d765b044c6d8594bb965a2247a61e991a99johnny * check for unmap and unlock of address space
70025d765b044c6d8594bb965a2247a61e991a99johnny if ((mp->map_op == DDI_MO_UNMAP) || (mp->map_op == DDI_MO_UNLOCK)) {
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet * Check for AMD's northbridges
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet * for any PCI device.
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet * This is a workaround fix for
247980bee8b0de250570942681f1567bd54ad984anish * AMD-8132's inability to handle MMCFG
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet * accesses on Galaxy's PE servers
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet * to disable MMCFG for any PCI device.
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet * If a device is *not* found to have PCIe
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet * capability, then assume it is a PCI device.
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet PCI_CAP_NEXT_PTR_NULL) == PCI_CAP_NEXT_PTR_NULL)) {
649d4cce0c8ba57f2c399df82be95a0395cfeef2anish /* FALLTHROUGH */
70025d765b044c6d8594bb965a2247a61e991a99johnny * MEM64 requires special treatment on map, to check
70025d765b044c6d8594bb965a2247a61e991a99johnny * that the device is below 4G. On unmap, however,
70025d765b044c6d8594bb965a2247a61e991a99johnny * we can assume that everything is OK... the map
70025d765b044c6d8594bb965a2247a61e991a99johnny * must have succeeded.
70025d765b044c6d8594bb965a2247a61e991a99johnny /* FALLTHROUGH */
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet * Adjust offset and length
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet * A non-zero length means override the one in the regspec.
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet retval = ddi_map(dip, mp, (off_t)0, (off_t)0, vaddrp);
70025d765b044c6d8594bb965a2247a61e991a99johnny /* check for user mapping request - not legal for Config */
70025d765b044c6d8594bb965a2247a61e991a99johnny if (mp->map_op == DDI_MO_MAP_HANDLE && space == PCI_ADDR_CONFIG) {
70025d765b044c6d8594bb965a2247a61e991a99johnny cmn_err(CE_NOTE, "npe: Config mapping request from user\n");
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet * Note that pci_fm_acc_setup() is called to serve two purposes
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet * i) enable legacy PCI I/O style config space access
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet * ii) register with FMA
70025d765b044c6d8594bb965a2247a61e991a99johnny /* Can't map config space without a handle */
70025d765b044c6d8594bb965a2247a61e991a99johnny /* record the device address for future reference */
70025d765b044c6d8594bb965a2247a61e991a99johnny cfp->c_funcnum = PCI_REG_FUNC_G(pci_rp->pci_phys_hi);
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet * Check for AMD's northbridges, pci devices and
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet * devices underneath a pci bridge. This is to setup
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet * I/O based config space access.
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet (ddi_prop_get_int(DDI_DEV_T_ANY, rdip, DDI_PROP_DONTPASS,
649d4cce0c8ba57f2c399df82be95a0395cfeef2anish pci_rp->pci_phys_low = ddi_prop_get_int64(DDI_DEV_T_ANY,
70025d765b044c6d8594bb965a2247a61e991a99johnny * range check
70025d765b044c6d8594bb965a2247a61e991a99johnny if ((offset >= length) || (len > length) || (offset + len > length))
70025d765b044c6d8594bb965a2247a61e991a99johnny * Adjust offset and length
70025d765b044c6d8594bb965a2247a61e991a99johnny * A non-zero length means override the one in the regspec.
70025d765b044c6d8594bb965a2247a61e991a99johnny * convert the pci regsec into the generic regspec used by the
70025d765b044c6d8594bb965a2247a61e991a99johnny * parent root nexus driver.
70025d765b044c6d8594bb965a2247a61e991a99johnny * We can't handle 64-bit devices that are mapped above
70025d765b044c6d8594bb965a2247a61e991a99johnny * 4G or that are larger than 4G.
70025d765b044c6d8594bb965a2247a61e991a99johnny if (pci_rp->pci_phys_mid != 0 || pci_rp->pci_size_hi != 0)
70025d765b044c6d8594bb965a2247a61e991a99johnny * Other than that, we can treat them as 32-bit mappings
70025d765b044c6d8594bb965a2247a61e991a99johnny /* FALLTHROUGH */
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet retval = ddi_map(dip, mp, (off_t)0, (off_t)0, vaddrp);
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet * For config space gets force use of cautious access routines.
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet * These will handle default and protected mode accesses too.
70025d765b044c6d8594bb965a2247a61e991a99johnny/*ARGSUSED*/
70025d765b044c6d8594bb965a2247a61e991a99johnny cmn_err(CE_CONT, "?PCI Express-device: %s@%s, %s%d\n",
70025d765b044c6d8594bb965a2247a61e991a99johnny *(int *)result = 0;
70025d765b044c6d8594bb965a2247a61e991a99johnny totreg = (reglen * sizeof (int)) / sizeof (pci_regspec_t);
70025d765b044c6d8594bb965a2247a61e991a99johnny * We currently understand reporting of PCI_PM_IDLESPEED
70025d765b044c6d8594bb965a2247a61e991a99johnny * capability. Everything else is passed up.
70025d765b044c6d8594bb965a2247a61e991a99johnny (reqp->req.report_pmcap_req.cap == PCI_PM_IDLESPEED))
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet return (pci_common_peekpoke(dip, rdip, ctlop, arg, result));
70025d765b044c6d8594bb965a2247a61e991a99johnny * npe_intr_ops
70025d765b044c6d8594bb965a2247a61e991a99johnnynpe_intr_ops(dev_info_t *pdip, dev_info_t *rdip, ddi_intr_op_t intr_op,
70025d765b044c6d8594bb965a2247a61e991a99johnny return (pci_common_intr_ops(pdip, rdip, intr_op, hdlp, result));
70025d765b044c6d8594bb965a2247a61e991a99johnny if (pci_common_name_child(child, name, 80) != DDI_SUCCESS)
70025d765b044c6d8594bb965a2247a61e991a99johnny * Pseudo nodes indicate a prototype node with per-instance
70025d765b044c6d8594bb965a2247a61e991a99johnny * properties to be merged into the real h/w device node.
70025d765b044c6d8594bb965a2247a61e991a99johnny * The interpretation of the unit-address is DD[,F]
70025d765b044c6d8594bb965a2247a61e991a99johnny * where DD is the device id and F is the function.
70025d765b044c6d8594bb965a2247a61e991a99johnny * Try to merge the properties from this prototype
70025d765b044c6d8594bb965a2247a61e991a99johnny * node into real h/w nodes.
70025d765b044c6d8594bb965a2247a61e991a99johnny * Merged ok - return failure to remove the node.
70025d765b044c6d8594bb965a2247a61e991a99johnny /* workaround for DDIVS to run under PCI Express */
70025d765b044c6d8594bb965a2247a61e991a99johnny * If the "interrupts" property doesn't exist,
70025d765b044c6d8594bb965a2247a61e991a99johnny * this must be the ddivs no-intr case, and it returns
70025d765b044c6d8594bb965a2247a61e991a99johnny * DDI_SUCCESS instead of DDI_FAILURE.
70025d765b044c6d8594bb965a2247a61e991a99johnny * Create the ddi_parent_private_data for a pseudo
70025d765b044c6d8594bb965a2247a61e991a99johnny * The child was not merged into a h/w node,
70025d765b044c6d8594bb965a2247a61e991a99johnny * but there's not much we can do with it other
70025d765b044c6d8594bb965a2247a61e991a99johnny * than return failure to cause the node to be removed.
70025d765b044c6d8594bb965a2247a61e991a99johnny cmn_err(CE_WARN, "!%s@%s: %s.conf properties not merged",
70025d765b044c6d8594bb965a2247a61e991a99johnny if (ddi_prop_get_int(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS,
70025d765b044c6d8594bb965a2247a61e991a99johnny * Enable AER next pointer being displayed
70025d765b044c6d8594bb965a2247a61e991a99johnny * Do it way early.
70025d765b044c6d8594bb965a2247a61e991a99johnny * Otherwise ddi_map() call form pcie_error_fini crashes
70025d765b044c6d8594bb965a2247a61e991a99johnny kmem_free(pdptr, (sizeof (*pdptr) + sizeof (struct intrspec)));
70025d765b044c6d8594bb965a2247a61e991a99johnny * Strip the node to properly convert it back to prototype form
70025d765b044c6d8594bb965a2247a61e991a99johnny * When retrofitting this module for pci_tools, functions such as open, close,
70025d765b044c6d8594bb965a2247a61e991a99johnny * and ioctl are now pulled into this module. Before this, the functions in
70025d765b044c6d8594bb965a2247a61e991a99johnny * the pcihp module were referenced directly. Now they are called or
70025d765b044c6d8594bb965a2247a61e991a99johnny * referenced through the pcihp cb_ops structure from functions in this module.
70025d765b044c6d8594bb965a2247a61e991a99johnnynpe_open(dev_t *devp, int flags, int otyp, cred_t *credp)
70025d765b044c6d8594bb965a2247a61e991a99johnny return ((pcihp_get_cb_ops())->cb_open(devp, flags, otyp, credp));
70025d765b044c6d8594bb965a2247a61e991a99johnnynpe_close(dev_t dev, int flags, int otyp, cred_t *credp)
70025d765b044c6d8594bb965a2247a61e991a99johnny return ((pcihp_get_cb_ops())->cb_close(dev, flags, otyp, credp));
70025d765b044c6d8594bb965a2247a61e991a99johnnynpe_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, cred_t *credp, int *rvalp)
70025d765b044c6d8594bb965a2247a61e991a99johnny int instance = PCIHP_AP_MINOR_NUM_TO_INSTANCE(minor);
70025d765b044c6d8594bb965a2247a61e991a99johnny pci_state_t *pci_p = ddi_get_soft_state(npe_statep, instance);
70025d765b044c6d8594bb965a2247a61e991a99johnny return (pci_common_ioctl(dip, dev, cmd, arg, mode, credp, rvalp));
70025d765b044c6d8594bb965a2247a61e991a99johnnynpe_prop_op(dev_t dev, dev_info_t *dip, ddi_prop_op_t prop_op,
70025d765b044c6d8594bb965a2247a61e991a99johnny return ((pcihp_get_cb_ops())->cb_prop_op(dev, dip, prop_op, flags,
70025d765b044c6d8594bb965a2247a61e991a99johnnynpe_info(dev_info_t *dip, ddi_info_cmd_t cmd, void *arg, void **result)
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet/*ARGSUSED*/
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreetnpe_fm_init(dev_info_t *dip, dev_info_t *tdip, int cap,
00d0963faf2e861a4aef6b1bf28f99a5b2b20755dilpreet/*ARGSUSED*/