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 * PCI nexus utility routines: 310Sstevel@tonic-gate * property and config routines for attach() 320Sstevel@tonic-gate * reg/intr/range/assigned-address property routines for bus_map() 330Sstevel@tonic-gate * init_child() 340Sstevel@tonic-gate * fault handling 350Sstevel@tonic-gate */ 360Sstevel@tonic-gate 370Sstevel@tonic-gate #include <sys/types.h> 380Sstevel@tonic-gate #include <sys/kmem.h> 390Sstevel@tonic-gate #include <sys/async.h> 400Sstevel@tonic-gate #include <sys/sysmacros.h> 410Sstevel@tonic-gate #include <sys/sunddi.h> 420Sstevel@tonic-gate #include <sys/sunndi.h> 430Sstevel@tonic-gate #include <sys/ddi_impldefs.h> 440Sstevel@tonic-gate #include "px_obj.h" 450Sstevel@tonic-gate #include "pcie_pwr.h" 460Sstevel@tonic-gate 470Sstevel@tonic-gate /*LINTLIBRARY*/ 480Sstevel@tonic-gate 490Sstevel@tonic-gate /* 500Sstevel@tonic-gate * px_get_props 510Sstevel@tonic-gate * 520Sstevel@tonic-gate * This function is called from the attach routine to get the key 530Sstevel@tonic-gate * properties of the pci nodes. 540Sstevel@tonic-gate * 550Sstevel@tonic-gate * used by: px_attach() 560Sstevel@tonic-gate * 570Sstevel@tonic-gate * return value: DDI_FAILURE on failure 580Sstevel@tonic-gate */ 590Sstevel@tonic-gate int 600Sstevel@tonic-gate px_get_props(px_t *px_p, dev_info_t *dip) 610Sstevel@tonic-gate { 620Sstevel@tonic-gate int i, no_of_intrs; 630Sstevel@tonic-gate 640Sstevel@tonic-gate /* 650Sstevel@tonic-gate * Get the bus-ranges property. 660Sstevel@tonic-gate */ 670Sstevel@tonic-gate i = sizeof (px_p->px_bus_range); 680Sstevel@tonic-gate if (ddi_getlongprop_buf(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, 690Sstevel@tonic-gate "bus-range", (caddr_t)&px_p->px_bus_range, &i) != DDI_SUCCESS) { 700Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d: no bus-range property\n", 710Sstevel@tonic-gate ddi_driver_name(dip), ddi_get_instance(dip)); 720Sstevel@tonic-gate return (DDI_FAILURE); 730Sstevel@tonic-gate } 740Sstevel@tonic-gate DBG(DBG_ATTACH, dip, "get_px_properties: bus-range (%x,%x)\n", 750Sstevel@tonic-gate px_p->px_bus_range.lo, px_p->px_bus_range.hi); 760Sstevel@tonic-gate 770Sstevel@tonic-gate /* 780Sstevel@tonic-gate * Get the interrupts property. 790Sstevel@tonic-gate */ 800Sstevel@tonic-gate if (ddi_getlongprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, 810Sstevel@tonic-gate "interrupts", (caddr_t)&px_p->px_inos, 820Sstevel@tonic-gate &px_p->px_inos_len) != DDI_SUCCESS) { 830Sstevel@tonic-gate 840Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d: no interrupts property\n", 850Sstevel@tonic-gate ddi_driver_name(dip), ddi_get_instance(dip)); 860Sstevel@tonic-gate return (DDI_FAILURE); 870Sstevel@tonic-gate } 880Sstevel@tonic-gate 890Sstevel@tonic-gate /* 900Sstevel@tonic-gate * figure out number of interrupts in the "interrupts" property 910Sstevel@tonic-gate * and convert them all into ino. 920Sstevel@tonic-gate */ 930Sstevel@tonic-gate i = ddi_getprop(DDI_DEV_T_ANY, dip, 0, "#interrupt-cells", 1); 940Sstevel@tonic-gate i = CELLS_1275_TO_BYTES(i); 950Sstevel@tonic-gate no_of_intrs = px_p->px_inos_len / i; 960Sstevel@tonic-gate for (i = 0; i < no_of_intrs; i++) 970Sstevel@tonic-gate px_p->px_inos[i] = px_p->px_inos[i] & 0x3F; 980Sstevel@tonic-gate 990Sstevel@tonic-gate /* 1000Sstevel@tonic-gate * Get the ranges property. 1010Sstevel@tonic-gate */ 1020Sstevel@tonic-gate if (ddi_getlongprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, "ranges", 1030Sstevel@tonic-gate (caddr_t)&px_p->px_ranges_p, &px_p->px_ranges_length) != 1040Sstevel@tonic-gate DDI_SUCCESS) { 1050Sstevel@tonic-gate 1060Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d: no ranges property\n", 1070Sstevel@tonic-gate ddi_driver_name(dip), ddi_get_instance(dip)); 1080Sstevel@tonic-gate kmem_free(px_p->px_inos, px_p->px_inos_len); 1090Sstevel@tonic-gate return (DDI_FAILURE); 1100Sstevel@tonic-gate } 1110Sstevel@tonic-gate 1120Sstevel@tonic-gate px_p->px_thermal_interrupt = 1130Sstevel@tonic-gate ddi_getprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, 1140Sstevel@tonic-gate "thermal-interrupt", -1); 1150Sstevel@tonic-gate DBG(DBG_ATTACH, dip, "get_px_properties: thermal_interrupt=%d\n", 1160Sstevel@tonic-gate px_p->px_thermal_interrupt); 1170Sstevel@tonic-gate return (DDI_SUCCESS); 1180Sstevel@tonic-gate } 1190Sstevel@tonic-gate 1200Sstevel@tonic-gate /* 1210Sstevel@tonic-gate * px_free_props: 1220Sstevel@tonic-gate * 1230Sstevel@tonic-gate * This routine frees the memory used to cache the "interrupts" 1240Sstevel@tonic-gate * and "ranges" properties of the pci bus device node. 1250Sstevel@tonic-gate * 1260Sstevel@tonic-gate * used by: px_detach() 1270Sstevel@tonic-gate * 1280Sstevel@tonic-gate * return value: none 1290Sstevel@tonic-gate */ 1300Sstevel@tonic-gate void 1310Sstevel@tonic-gate px_free_props(px_t *px_p) 1320Sstevel@tonic-gate { 1330Sstevel@tonic-gate kmem_free(px_p->px_inos, px_p->px_inos_len); 1340Sstevel@tonic-gate kmem_free(px_p->px_ranges_p, px_p->px_ranges_length); 1350Sstevel@tonic-gate } 1360Sstevel@tonic-gate 1370Sstevel@tonic-gate /* 1380Sstevel@tonic-gate * px_reloc_reg 1390Sstevel@tonic-gate * 1400Sstevel@tonic-gate * If the "reg" entry (*px_rp) is relocatable, lookup "assigned-addresses" 1410Sstevel@tonic-gate * property to fetch corresponding relocated address. 1420Sstevel@tonic-gate * 1430Sstevel@tonic-gate * used by: px_map() 1440Sstevel@tonic-gate * 1450Sstevel@tonic-gate * return value: 1460Sstevel@tonic-gate * 1470Sstevel@tonic-gate * DDI_SUCCESS - on success 1480Sstevel@tonic-gate * DDI_ME_INVAL - regspec is invalid 1490Sstevel@tonic-gate */ 1500Sstevel@tonic-gate int 1510Sstevel@tonic-gate px_reloc_reg(dev_info_t *dip, dev_info_t *rdip, px_t *px_p, 1520Sstevel@tonic-gate pci_regspec_t *rp) 1530Sstevel@tonic-gate { 1540Sstevel@tonic-gate int assign_len, assign_entries, i; 1550Sstevel@tonic-gate pci_regspec_t *assign_p; 1560Sstevel@tonic-gate uint32_t phys_hi = rp->pci_phys_hi; 1570Sstevel@tonic-gate uint32_t space_type = phys_hi & PCI_REG_ADDR_M; /* 28-bit */ 1580Sstevel@tonic-gate 1590Sstevel@tonic-gate DBG(DBG_MAP | DBG_CONT, dip, "\tpx_reloc_reg fr: %x.%x.%x %x.%x\n", 1600Sstevel@tonic-gate rp->pci_phys_hi, rp->pci_phys_mid, rp->pci_phys_low, 1610Sstevel@tonic-gate rp->pci_size_hi, rp->pci_size_low); 1620Sstevel@tonic-gate 1630Sstevel@tonic-gate if (space_type == PCI_ADDR_CONFIG || phys_hi & PCI_RELOCAT_B) 1640Sstevel@tonic-gate return (DDI_SUCCESS); 1650Sstevel@tonic-gate 1660Sstevel@tonic-gate /* 1670Sstevel@tonic-gate * Hot plug will be taken care of later 1680Sstevel@tonic-gate * if (px_p->hotplug_capable == B_FALSE) 1690Sstevel@tonic-gate */ 1700Sstevel@tonic-gate { 1710Sstevel@tonic-gate uint32_t bus = PCI_REG_BUS_G(phys_hi); 1720Sstevel@tonic-gate if (bus < px_p->px_bus_range.lo || 1730Sstevel@tonic-gate bus > px_p->px_bus_range.hi) { 1740Sstevel@tonic-gate DBG(DBG_MAP | DBG_CONT, dip, "bad bus# (%x)\n", bus); 1750Sstevel@tonic-gate return (DDI_ME_INVAL); 1760Sstevel@tonic-gate } 1770Sstevel@tonic-gate } 1780Sstevel@tonic-gate 1790Sstevel@tonic-gate i = ddi_getlongprop(DDI_DEV_T_ANY, rdip, DDI_PROP_DONTPASS, 1800Sstevel@tonic-gate "assigned-addresses", (caddr_t)&assign_p, &assign_len); 1810Sstevel@tonic-gate if (i) { 1820Sstevel@tonic-gate DBG(DBG_MAP | DBG_CONT, dip, "%s%d: assigned-addresses %d\n", 1830Sstevel@tonic-gate ddi_driver_name(rdip), ddi_get_instance(rdip), i); 1840Sstevel@tonic-gate return (DDI_ME_INVAL); 1850Sstevel@tonic-gate } 1860Sstevel@tonic-gate 1870Sstevel@tonic-gate assign_entries = assign_len / sizeof (pci_regspec_t); 1880Sstevel@tonic-gate for (i = 0; i < assign_entries; i++, assign_p++) { 1890Sstevel@tonic-gate uint32_t assign_type = assign_p->pci_phys_hi & PCI_REG_ADDR_M; 1900Sstevel@tonic-gate uint32_t assign_addr = PCI_REG_BDFR_G(assign_p->pci_phys_hi); 1910Sstevel@tonic-gate 1920Sstevel@tonic-gate if (PCI_REG_BDFR_G(phys_hi) != assign_addr) 1930Sstevel@tonic-gate continue; 1940Sstevel@tonic-gate if (space_type == assign_type) { /* exact match */ 1950Sstevel@tonic-gate rp->pci_phys_low += assign_p->pci_phys_low; 1960Sstevel@tonic-gate break; 1970Sstevel@tonic-gate } 1980Sstevel@tonic-gate if (space_type == PCI_ADDR_MEM64 && 1990Sstevel@tonic-gate assign_type == PCI_ADDR_MEM32) { 2000Sstevel@tonic-gate rp->pci_phys_low += assign_p->pci_phys_low; 2010Sstevel@tonic-gate rp->pci_phys_hi ^= PCI_ADDR_MEM64 ^ PCI_ADDR_MEM32; 2020Sstevel@tonic-gate break; 2030Sstevel@tonic-gate } 2040Sstevel@tonic-gate } 2050Sstevel@tonic-gate kmem_free(assign_p - i, assign_len); 2060Sstevel@tonic-gate DBG(DBG_MAP | DBG_CONT, dip, "\tpx_reloc_reg to: %x.%x.%x %x.%x <%d>\n", 2070Sstevel@tonic-gate rp->pci_phys_hi, rp->pci_phys_mid, rp->pci_phys_low, 2080Sstevel@tonic-gate rp->pci_size_hi, rp->pci_size_low, i); 2090Sstevel@tonic-gate return (i < assign_entries ? DDI_SUCCESS : DDI_ME_INVAL); 2100Sstevel@tonic-gate } 2110Sstevel@tonic-gate 2120Sstevel@tonic-gate /* 2130Sstevel@tonic-gate * use "ranges" to translate relocated pci regspec into parent space 2140Sstevel@tonic-gate */ 2150Sstevel@tonic-gate int 2160Sstevel@tonic-gate px_xlate_reg(px_t *px_p, pci_regspec_t *px_rp, struct regspec *new_rp) 2170Sstevel@tonic-gate { 2180Sstevel@tonic-gate int n; 2190Sstevel@tonic-gate px_ranges_t *rng_p = px_p->px_ranges_p; 2200Sstevel@tonic-gate int rng_n = px_p->px_ranges_length / sizeof (px_ranges_t); 2210Sstevel@tonic-gate 2220Sstevel@tonic-gate uint32_t space_type = PCI_REG_ADDR_G(px_rp->pci_phys_hi); 2230Sstevel@tonic-gate uint32_t reg_end, reg_begin = px_rp->pci_phys_low; 2240Sstevel@tonic-gate uint32_t sz = px_rp->pci_size_low; 2250Sstevel@tonic-gate 2260Sstevel@tonic-gate uint32_t rng_begin, rng_end; 2270Sstevel@tonic-gate 2280Sstevel@tonic-gate if (space_type == PCI_REG_ADDR_G(PCI_ADDR_CONFIG)) { 2290Sstevel@tonic-gate if (reg_begin > PCI_CONF_HDR_SIZE) 2300Sstevel@tonic-gate return (DDI_ME_INVAL); 2310Sstevel@tonic-gate sz = sz ? MIN(sz, PCI_CONF_HDR_SIZE) : PCI_CONF_HDR_SIZE; 2320Sstevel@tonic-gate reg_begin += px_rp->pci_phys_hi << 4; 2330Sstevel@tonic-gate } 2340Sstevel@tonic-gate reg_end = reg_begin + sz - 1; 2350Sstevel@tonic-gate 2360Sstevel@tonic-gate for (n = 0; n < rng_n; n++, rng_p++) { 2370Sstevel@tonic-gate if (space_type != PCI_REG_ADDR_G(rng_p->child_high)) 2380Sstevel@tonic-gate continue; /* not the same space type */ 2390Sstevel@tonic-gate 2400Sstevel@tonic-gate rng_begin = rng_p->child_low; 2410Sstevel@tonic-gate if (space_type == PCI_REG_ADDR_G(PCI_ADDR_CONFIG)) 2420Sstevel@tonic-gate rng_begin += rng_p->child_high; 2430Sstevel@tonic-gate 2440Sstevel@tonic-gate rng_end = rng_begin + rng_p->size_low - 1; 2450Sstevel@tonic-gate if (reg_begin >= rng_begin && reg_end <= rng_end) 2460Sstevel@tonic-gate break; 2470Sstevel@tonic-gate } 2480Sstevel@tonic-gate if (n >= rng_n) 2490Sstevel@tonic-gate return (DDI_ME_REGSPEC_RANGE); 2500Sstevel@tonic-gate 2510Sstevel@tonic-gate new_rp->regspec_addr = reg_begin - rng_begin + rng_p->parent_low; 2520Sstevel@tonic-gate new_rp->regspec_bustype = rng_p->parent_high; 2530Sstevel@tonic-gate new_rp->regspec_size = sz; 2540Sstevel@tonic-gate DBG(DBG_MAP | DBG_CONT, px_p->px_dip, 2550Sstevel@tonic-gate "\tpx_xlate_reg: entry %d new_rp %x.%x %x\n", 2560Sstevel@tonic-gate n, new_rp->regspec_bustype, new_rp->regspec_addr, sz); 2570Sstevel@tonic-gate 2580Sstevel@tonic-gate return (DDI_SUCCESS); 2590Sstevel@tonic-gate } 2600Sstevel@tonic-gate 2610Sstevel@tonic-gate /* 2620Sstevel@tonic-gate * px_report_dev 2630Sstevel@tonic-gate * 2640Sstevel@tonic-gate * This function is called from our control ops routine on a 2650Sstevel@tonic-gate * DDI_CTLOPS_REPORTDEV request. 2660Sstevel@tonic-gate * 2670Sstevel@tonic-gate * The display format is 2680Sstevel@tonic-gate * 2690Sstevel@tonic-gate * <name><inst> at <pname><pinst> device <dev> function <func> 2700Sstevel@tonic-gate * 2710Sstevel@tonic-gate * where 2720Sstevel@tonic-gate * 2730Sstevel@tonic-gate * <name> this device's name property 2740Sstevel@tonic-gate * <inst> this device's instance number 2750Sstevel@tonic-gate * <name> parent device's name property 2760Sstevel@tonic-gate * <inst> parent device's instance number 2770Sstevel@tonic-gate * <dev> this device's device number 2780Sstevel@tonic-gate * <func> this device's function number 2790Sstevel@tonic-gate */ 2800Sstevel@tonic-gate int 2810Sstevel@tonic-gate px_report_dev(dev_info_t *dip) 2820Sstevel@tonic-gate { 2830Sstevel@tonic-gate if (dip == (dev_info_t *)0) 2840Sstevel@tonic-gate return (DDI_FAILURE); 2850Sstevel@tonic-gate cmn_err(CE_CONT, "?PCI Express-device: %s@%s, %s%d\n", 2860Sstevel@tonic-gate ddi_node_name(dip), ddi_get_name_addr(dip), 2870Sstevel@tonic-gate ddi_driver_name(dip), 2880Sstevel@tonic-gate ddi_get_instance(dip)); 2890Sstevel@tonic-gate return (DDI_SUCCESS); 2900Sstevel@tonic-gate } 2910Sstevel@tonic-gate 2920Sstevel@tonic-gate 2930Sstevel@tonic-gate /* 2940Sstevel@tonic-gate * reg property for pcimem nodes that covers the entire address 2950Sstevel@tonic-gate * space for the node: config, io, or memory. 2960Sstevel@tonic-gate */ 2970Sstevel@tonic-gate pci_regspec_t pci_pcimem_reg[3] = 2980Sstevel@tonic-gate { 2990Sstevel@tonic-gate {PCI_ADDR_CONFIG, 0, 0, 0, 0x800000 }, 3000Sstevel@tonic-gate {(uint_t)(PCI_ADDR_IO|PCI_RELOCAT_B), 0, 0, 0, PX_IO_SIZE }, 3010Sstevel@tonic-gate {(uint_t)(PCI_ADDR_MEM32|PCI_RELOCAT_B), 0, 0, 0, PX_MEM_SIZE } 3020Sstevel@tonic-gate }; 3030Sstevel@tonic-gate 3040Sstevel@tonic-gate /* 3050Sstevel@tonic-gate * px_name_child 3060Sstevel@tonic-gate * 3070Sstevel@tonic-gate * This function is called from init_child to name a node. It is 3080Sstevel@tonic-gate * also passed as a callback for node merging functions. 3090Sstevel@tonic-gate * 3100Sstevel@tonic-gate * return value: DDI_SUCCESS, DDI_FAILURE 3110Sstevel@tonic-gate */ 3120Sstevel@tonic-gate static int 3130Sstevel@tonic-gate px_name_child(dev_info_t *child, char *name, int namelen) 3140Sstevel@tonic-gate { 3150Sstevel@tonic-gate pci_regspec_t *pci_rp; 3160Sstevel@tonic-gate int reglen; 3170Sstevel@tonic-gate uint_t func; 3180Sstevel@tonic-gate char **unit_addr; 3190Sstevel@tonic-gate uint_t n; 3200Sstevel@tonic-gate 3210Sstevel@tonic-gate /* 3220Sstevel@tonic-gate * Set the address portion of the node name based on 3230Sstevel@tonic-gate * unit-address property, if it exists. 3240Sstevel@tonic-gate * The interpretation of the unit-address is DD[,F] 3250Sstevel@tonic-gate * where DD is the device id and F is the function. 3260Sstevel@tonic-gate */ 3270Sstevel@tonic-gate if (ddi_prop_lookup_string_array(DDI_DEV_T_ANY, child, 3280Sstevel@tonic-gate DDI_PROP_DONTPASS, "unit-address", &unit_addr, &n) == 3290Sstevel@tonic-gate DDI_PROP_SUCCESS) { 3300Sstevel@tonic-gate if (n != 1 || *unit_addr == NULL || **unit_addr == 0) { 3310Sstevel@tonic-gate cmn_err(CE_WARN, "unit-address property in %s.conf" 3320Sstevel@tonic-gate " not well-formed", ddi_driver_name(child)); 3330Sstevel@tonic-gate ddi_prop_free(unit_addr); 3340Sstevel@tonic-gate return (DDI_FAILURE); 3350Sstevel@tonic-gate } 3360Sstevel@tonic-gate (void) snprintf(name, namelen, "%s", *unit_addr); 3370Sstevel@tonic-gate ddi_prop_free(unit_addr); 3380Sstevel@tonic-gate return (DDI_SUCCESS); 3390Sstevel@tonic-gate } 3400Sstevel@tonic-gate 3410Sstevel@tonic-gate /* 3420Sstevel@tonic-gate * The unit-address property is does not exist. Set the address 3430Sstevel@tonic-gate * portion of the node name based on the function and device number. 3440Sstevel@tonic-gate */ 3450Sstevel@tonic-gate if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS, 3460Sstevel@tonic-gate "reg", (int **)&pci_rp, (uint_t *)®len) == DDI_SUCCESS) { 3470Sstevel@tonic-gate if (((reglen * sizeof (int)) % sizeof (pci_regspec_t)) != 0) { 3480Sstevel@tonic-gate cmn_err(CE_WARN, "reg property not well-formed"); 3490Sstevel@tonic-gate return (DDI_FAILURE); 3500Sstevel@tonic-gate } 3510Sstevel@tonic-gate 3520Sstevel@tonic-gate func = PCI_REG_FUNC_G(pci_rp[0].pci_phys_hi); 3530Sstevel@tonic-gate if (func != 0) 3540Sstevel@tonic-gate (void) snprintf(name, namelen, "%x,%x", 3550Sstevel@tonic-gate PCI_REG_DEV_G(pci_rp[0].pci_phys_hi), func); 3560Sstevel@tonic-gate else 3570Sstevel@tonic-gate (void) snprintf(name, namelen, "%x", 3580Sstevel@tonic-gate PCI_REG_DEV_G(pci_rp[0].pci_phys_hi)); 3590Sstevel@tonic-gate ddi_prop_free(pci_rp); 3600Sstevel@tonic-gate return (DDI_SUCCESS); 3610Sstevel@tonic-gate } 3620Sstevel@tonic-gate 3630Sstevel@tonic-gate cmn_err(CE_WARN, "cannot name pci child '%s'", ddi_node_name(child)); 3640Sstevel@tonic-gate return (DDI_FAILURE); 3650Sstevel@tonic-gate } 3660Sstevel@tonic-gate 3670Sstevel@tonic-gate int 3680Sstevel@tonic-gate px_uninit_child(px_t *px_p, dev_info_t *child) 3690Sstevel@tonic-gate { 3700Sstevel@tonic-gate DBG(DBG_INIT_CLD, px_p->px_dip, 3710Sstevel@tonic-gate "DDI_CTLOPS_UNINITCHILD: arg=%s%d\n", 3720Sstevel@tonic-gate ddi_driver_name(child), ddi_get_instance(child)); 3730Sstevel@tonic-gate 3740Sstevel@tonic-gate ddi_set_name_addr(child, NULL); 3750Sstevel@tonic-gate ddi_remove_minor_node(child, NULL); 3760Sstevel@tonic-gate impl_rem_dev_props(child); 377*27Sjchu 378*27Sjchu DBG(DBG_PWR, ddi_get_parent(child), "\n\n"); 3790Sstevel@tonic-gate 380*27Sjchu pcie_uninitchild(child); 381*27Sjchu 382*27Sjchu return (DDI_SUCCESS); 3830Sstevel@tonic-gate } 3840Sstevel@tonic-gate 3850Sstevel@tonic-gate /* 3860Sstevel@tonic-gate * px_init_child 3870Sstevel@tonic-gate * 3880Sstevel@tonic-gate * This function is called from our control ops routine on a 3890Sstevel@tonic-gate * DDI_CTLOPS_INITCHILD request. It builds and sets the device's 3900Sstevel@tonic-gate * parent private data area. 3910Sstevel@tonic-gate * 3920Sstevel@tonic-gate * used by: pci_ctlops() 3930Sstevel@tonic-gate * 3940Sstevel@tonic-gate * return value: none 3950Sstevel@tonic-gate */ 3960Sstevel@tonic-gate int 3970Sstevel@tonic-gate px_init_child(px_t *px_p, dev_info_t *child) 3980Sstevel@tonic-gate { 399*27Sjchu dev_info_t *parent_dip = px_p->px_dip; 400*27Sjchu pci_regspec_t *pci_rp; 401*27Sjchu char name[10]; 402*27Sjchu int i, no_config; 4030Sstevel@tonic-gate 4040Sstevel@tonic-gate /* 4050Sstevel@tonic-gate * The following is a special case for pcimem nodes. 4060Sstevel@tonic-gate * For these nodes we create a reg property with a 4070Sstevel@tonic-gate * single entry that covers the entire address space 4080Sstevel@tonic-gate * for the node (config, io or memory). 4090Sstevel@tonic-gate */ 4100Sstevel@tonic-gate if (strcmp(ddi_driver_name(child), "pcimem") == 0) { 4110Sstevel@tonic-gate (void) ddi_prop_create(DDI_DEV_T_NONE, child, 4120Sstevel@tonic-gate DDI_PROP_CANSLEEP, "reg", (caddr_t)pci_pcimem_reg, 4130Sstevel@tonic-gate sizeof (pci_pcimem_reg)); 4140Sstevel@tonic-gate ddi_set_name_addr(child, "0"); 4150Sstevel@tonic-gate ddi_set_parent_data(child, NULL); 4160Sstevel@tonic-gate return (DDI_SUCCESS); 4170Sstevel@tonic-gate } 4180Sstevel@tonic-gate 4190Sstevel@tonic-gate /* 4200Sstevel@tonic-gate * Check whether the node has config space or is a hard decode 4210Sstevel@tonic-gate * node (possibly created by a driver.conf file). 4220Sstevel@tonic-gate */ 4230Sstevel@tonic-gate no_config = ddi_prop_get_int(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS, 4240Sstevel@tonic-gate "no-config", 0); 4250Sstevel@tonic-gate 4260Sstevel@tonic-gate /* 4270Sstevel@tonic-gate * Pseudo nodes indicate a prototype node with per-instance 4280Sstevel@tonic-gate * properties to be merged into the real h/w device node. 4290Sstevel@tonic-gate * However, do not merge if the no-config property is set 4300Sstevel@tonic-gate * (see PSARC 2000/088). 4310Sstevel@tonic-gate */ 4320Sstevel@tonic-gate if ((ndi_dev_is_persistent_node(child) == 0) && (no_config == 0)) { 4330Sstevel@tonic-gate extern int pci_allow_pseudo_children; 4340Sstevel@tonic-gate 4350Sstevel@tonic-gate if (ddi_getlongprop(DDI_DEV_T_ANY, child, 4360Sstevel@tonic-gate DDI_PROP_DONTPASS, "reg", (caddr_t)&pci_rp, &i) == 4370Sstevel@tonic-gate DDI_SUCCESS) { 4380Sstevel@tonic-gate cmn_err(CE_WARN, "cannot merge prototype from %s.conf", 4390Sstevel@tonic-gate ddi_driver_name(child)); 4400Sstevel@tonic-gate kmem_free(pci_rp, i); 4410Sstevel@tonic-gate return (DDI_NOT_WELL_FORMED); 4420Sstevel@tonic-gate } 4430Sstevel@tonic-gate /* 4440Sstevel@tonic-gate * Name the child 4450Sstevel@tonic-gate */ 4460Sstevel@tonic-gate if (px_name_child(child, name, 10) != DDI_SUCCESS) 4470Sstevel@tonic-gate return (DDI_FAILURE); 4480Sstevel@tonic-gate 4490Sstevel@tonic-gate ddi_set_name_addr(child, name); 4500Sstevel@tonic-gate ddi_set_parent_data(child, NULL); 4510Sstevel@tonic-gate 4520Sstevel@tonic-gate /* 4530Sstevel@tonic-gate * Try to merge the properties from this prototype 4540Sstevel@tonic-gate * node into real h/w nodes. 4550Sstevel@tonic-gate */ 4560Sstevel@tonic-gate if (ndi_merge_node(child, px_name_child) == DDI_SUCCESS) { 4570Sstevel@tonic-gate /* 4580Sstevel@tonic-gate * Merged ok - return failure to remove the node. 4590Sstevel@tonic-gate */ 4600Sstevel@tonic-gate ddi_set_name_addr(child, NULL); 4610Sstevel@tonic-gate return (DDI_FAILURE); 4620Sstevel@tonic-gate } 4630Sstevel@tonic-gate 4640Sstevel@tonic-gate /* workaround for ddivs to run under PCI */ 4650Sstevel@tonic-gate if (pci_allow_pseudo_children) 4660Sstevel@tonic-gate return (DDI_SUCCESS); 4670Sstevel@tonic-gate 4680Sstevel@tonic-gate cmn_err(CE_WARN, "!%s@%s: %s.conf properties not merged", 4690Sstevel@tonic-gate ddi_driver_name(child), ddi_get_name_addr(child), 4700Sstevel@tonic-gate ddi_driver_name(child)); 4710Sstevel@tonic-gate ddi_set_name_addr(child, NULL); 4720Sstevel@tonic-gate return (DDI_NOT_WELL_FORMED); 4730Sstevel@tonic-gate } 4740Sstevel@tonic-gate 4750Sstevel@tonic-gate if (px_name_child(child, name, 10) != DDI_SUCCESS) 4760Sstevel@tonic-gate return (DDI_FAILURE); 4770Sstevel@tonic-gate ddi_set_name_addr(child, name); 4780Sstevel@tonic-gate 4790Sstevel@tonic-gate if (no_config != 0) { 4800Sstevel@tonic-gate /* 4810Sstevel@tonic-gate * There is no config space so there's nothing more to do. 4820Sstevel@tonic-gate */ 4830Sstevel@tonic-gate return (DDI_SUCCESS); 4840Sstevel@tonic-gate } 4850Sstevel@tonic-gate 486*27Sjchu if (pcie_pm_hold(parent_dip) != DDI_SUCCESS) { 487*27Sjchu DBG(DBG_PWR, parent_dip, 4880Sstevel@tonic-gate "INITCHILD: px_pm_hold failed\n"); 4890Sstevel@tonic-gate return (DDI_FAILURE); 4900Sstevel@tonic-gate } 4910Sstevel@tonic-gate /* Any return of DDI_FAILURE after this must call px_pm_release */ 4920Sstevel@tonic-gate 4930Sstevel@tonic-gate /* 4940Sstevel@tonic-gate * If configuration registers were previously saved by 4950Sstevel@tonic-gate * child (before it went to D3), then let the child do the 4960Sstevel@tonic-gate * restore to set up the config regs as it'll first need to 4970Sstevel@tonic-gate * power the device out of D3. 4980Sstevel@tonic-gate */ 4990Sstevel@tonic-gate if (ddi_prop_exists(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS, 5000Sstevel@tonic-gate "config-regs-saved-by-child") == 1) { 5010Sstevel@tonic-gate DBG(DBG_PWR, child, 5020Sstevel@tonic-gate "INITCHILD: config regs to be restored by child\n"); 5030Sstevel@tonic-gate 5040Sstevel@tonic-gate return (DDI_SUCCESS); 5050Sstevel@tonic-gate } 5060Sstevel@tonic-gate 507*27Sjchu DBG(DBG_PWR, parent_dip, 5080Sstevel@tonic-gate "INITCHILD: config regs setup for %s@%s\n", 5090Sstevel@tonic-gate ddi_node_name(child), ddi_get_name_addr(child)); 5100Sstevel@tonic-gate 511*27Sjchu pcie_initchild(child); 5120Sstevel@tonic-gate 5130Sstevel@tonic-gate /* 5140Sstevel@tonic-gate * Handle chip specific init-child tasks. 5150Sstevel@tonic-gate */ 516*27Sjchu pcie_pm_release(parent_dip); 5170Sstevel@tonic-gate 5180Sstevel@tonic-gate return (DDI_SUCCESS); 5190Sstevel@tonic-gate } 5200Sstevel@tonic-gate 5210Sstevel@tonic-gate /* 5220Sstevel@tonic-gate * px_get_reg_set_size 5230Sstevel@tonic-gate * 5240Sstevel@tonic-gate * Given a dev info pointer to a pci child and a register number, this 5250Sstevel@tonic-gate * routine returns the size element of that reg set property. 5260Sstevel@tonic-gate * 5270Sstevel@tonic-gate * used by: pci_ctlops() - DDI_CTLOPS_REGSIZE 5280Sstevel@tonic-gate * 529*27Sjchu * return value: size of reg set on success, 0 on error 5300Sstevel@tonic-gate */ 5310Sstevel@tonic-gate off_t 5320Sstevel@tonic-gate px_get_reg_set_size(dev_info_t *child, int rnumber) 5330Sstevel@tonic-gate { 5340Sstevel@tonic-gate pci_regspec_t *pci_rp; 535*27Sjchu off_t size = 0; 5360Sstevel@tonic-gate int i; 5370Sstevel@tonic-gate 5380Sstevel@tonic-gate if (rnumber < 0) 539*27Sjchu return (0); 5400Sstevel@tonic-gate 5410Sstevel@tonic-gate /* 5420Sstevel@tonic-gate * Get the reg property for the device. 5430Sstevel@tonic-gate */ 5440Sstevel@tonic-gate if (ddi_getlongprop(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS, "reg", 5450Sstevel@tonic-gate (caddr_t)&pci_rp, &i) != DDI_SUCCESS) 546*27Sjchu return (0); 5470Sstevel@tonic-gate 5480Sstevel@tonic-gate if (rnumber >= (i / (int)sizeof (pci_regspec_t))) 5490Sstevel@tonic-gate goto done; 5500Sstevel@tonic-gate 5510Sstevel@tonic-gate size = pci_rp[rnumber].pci_size_low | 5520Sstevel@tonic-gate ((uint64_t)pci_rp[rnumber].pci_size_hi << 32); 5530Sstevel@tonic-gate done: 5540Sstevel@tonic-gate kmem_free(pci_rp, i); 5550Sstevel@tonic-gate return (size); 5560Sstevel@tonic-gate } 5570Sstevel@tonic-gate 5580Sstevel@tonic-gate 5590Sstevel@tonic-gate /* 5600Sstevel@tonic-gate * px_get_nreg_set 5610Sstevel@tonic-gate * 5620Sstevel@tonic-gate * Given a dev info pointer to a pci child, this routine returns the 5630Sstevel@tonic-gate * number of sets in its "reg" property. 5640Sstevel@tonic-gate * 5650Sstevel@tonic-gate * used by: pci_ctlops() - DDI_CTLOPS_NREGS 5660Sstevel@tonic-gate * 5670Sstevel@tonic-gate * return value: # of reg sets on success, zero on error 5680Sstevel@tonic-gate */ 5690Sstevel@tonic-gate uint_t 5700Sstevel@tonic-gate px_get_nreg_set(dev_info_t *child) 5710Sstevel@tonic-gate { 5720Sstevel@tonic-gate pci_regspec_t *pci_rp; 5730Sstevel@tonic-gate int i, n; 5740Sstevel@tonic-gate 5750Sstevel@tonic-gate /* 5760Sstevel@tonic-gate * Get the reg property for the device. 5770Sstevel@tonic-gate */ 5780Sstevel@tonic-gate if (ddi_getlongprop(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS, "reg", 5790Sstevel@tonic-gate (caddr_t)&pci_rp, &i) != DDI_SUCCESS) 5800Sstevel@tonic-gate return (0); 5810Sstevel@tonic-gate 5820Sstevel@tonic-gate n = i / (int)sizeof (pci_regspec_t); 5830Sstevel@tonic-gate kmem_free(pci_rp, i); 5840Sstevel@tonic-gate return (n); 5850Sstevel@tonic-gate } 5860Sstevel@tonic-gate 5870Sstevel@tonic-gate 5880Sstevel@tonic-gate /* 5890Sstevel@tonic-gate * px_get_nintr 5900Sstevel@tonic-gate * 5910Sstevel@tonic-gate * Given a dev info pointer to a pci child, this routine returns the 5920Sstevel@tonic-gate * number of items in its "interrupts" property. 5930Sstevel@tonic-gate * 5940Sstevel@tonic-gate * used by: pci_ctlops() - DDI_CTLOPS_NREGS 5950Sstevel@tonic-gate * 5960Sstevel@tonic-gate * return value: # of interrupts on success, zero on error 5970Sstevel@tonic-gate */ 5980Sstevel@tonic-gate uint_t 5990Sstevel@tonic-gate px_get_nintr(dev_info_t *child) 6000Sstevel@tonic-gate { 6010Sstevel@tonic-gate int *pci_ip; 6020Sstevel@tonic-gate int i, n; 6030Sstevel@tonic-gate 6040Sstevel@tonic-gate if (ddi_getlongprop(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS, 6050Sstevel@tonic-gate "interrupts", (caddr_t)&pci_ip, &i) != DDI_SUCCESS) 6060Sstevel@tonic-gate return (0); 6070Sstevel@tonic-gate 6080Sstevel@tonic-gate n = i / (int)sizeof (uint_t); 6090Sstevel@tonic-gate kmem_free(pci_ip, i); 6100Sstevel@tonic-gate return (n); 6110Sstevel@tonic-gate } 6120Sstevel@tonic-gate 6130Sstevel@tonic-gate uint64_t 6140Sstevel@tonic-gate px_get_cfg_pabase(px_t *px_p) 6150Sstevel@tonic-gate { 6160Sstevel@tonic-gate int i; 6170Sstevel@tonic-gate px_ranges_t *rangep = px_p->px_ranges_p; 6180Sstevel@tonic-gate int nrange = px_p->px_ranges_length / sizeof (px_ranges_t); 6190Sstevel@tonic-gate uint32_t cfg_space_type = PCI_REG_ADDR_G(PCI_ADDR_CONFIG); 6200Sstevel@tonic-gate 6210Sstevel@tonic-gate ASSERT(cfg_space_type == 0); 6220Sstevel@tonic-gate 6230Sstevel@tonic-gate for (i = 0; i < nrange; i++, rangep++) { 6240Sstevel@tonic-gate if (PCI_REG_ADDR_G(rangep->child_high) == cfg_space_type) 6250Sstevel@tonic-gate break; 6260Sstevel@tonic-gate } 6270Sstevel@tonic-gate 6280Sstevel@tonic-gate if (i >= nrange) 6290Sstevel@tonic-gate cmn_err(CE_PANIC, "no cfg space in px(%x) ranges prop.\n", 6300Sstevel@tonic-gate (void *)px_p); 6310Sstevel@tonic-gate 6320Sstevel@tonic-gate return (((uint64_t)rangep->parent_high << 32) | rangep->parent_low); 6330Sstevel@tonic-gate } 6340Sstevel@tonic-gate 6350Sstevel@tonic-gate /* 6360Sstevel@tonic-gate * decodes standard PCI config space 16bit error status reg 6370Sstevel@tonic-gate */ 6380Sstevel@tonic-gate int 6390Sstevel@tonic-gate px_log_cfg_err(dev_info_t *dip, ushort_t status_reg, char *err_msg) 6400Sstevel@tonic-gate { 6410Sstevel@tonic-gate int nerr = ddi_get_instance(dip); /* temp for instance */ 6420Sstevel@tonic-gate uint64_t perr_fatal = px_perr_fatal & (1 << nerr); 6430Sstevel@tonic-gate uint64_t serr_fatal = px_serr_fatal & (1 << nerr); 6440Sstevel@tonic-gate nerr = 0; 6450Sstevel@tonic-gate 6460Sstevel@tonic-gate if ((status_reg & PCI_STAT_PERROR) && perr_fatal) 6470Sstevel@tonic-gate nerr++; 6480Sstevel@tonic-gate if ((status_reg & PCI_STAT_S_SYSERR) && serr_fatal) 6490Sstevel@tonic-gate nerr++; 6500Sstevel@tonic-gate if (status_reg & PCI_STAT_R_MAST_AB) 6510Sstevel@tonic-gate nerr++; 6520Sstevel@tonic-gate if ((status_reg & PCI_STAT_S_PERROR) && perr_fatal) 6530Sstevel@tonic-gate nerr++; 6540Sstevel@tonic-gate 6550Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d: %sPCI Express config space CSR=0x%b", 6560Sstevel@tonic-gate ddi_driver_name(dip), ddi_get_instance(dip), err_msg, 6570Sstevel@tonic-gate (uint32_t)status_reg, PX_STATUS_BITS); 6580Sstevel@tonic-gate 6590Sstevel@tonic-gate return (nerr); 6600Sstevel@tonic-gate } 661