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 51624Spjha * Common Development and Distribution License (the "License"). 61624Spjha * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 229921SKrishna.Elango@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate /* 270Sstevel@tonic-gate * Sun4u PCI to PCI bus bridge nexus driver 280Sstevel@tonic-gate */ 290Sstevel@tonic-gate 300Sstevel@tonic-gate #include <sys/conf.h> 310Sstevel@tonic-gate #include <sys/kmem.h> 320Sstevel@tonic-gate #include <sys/debug.h> 330Sstevel@tonic-gate #include <sys/modctl.h> 340Sstevel@tonic-gate #include <sys/autoconf.h> 350Sstevel@tonic-gate #include <sys/ddi_impldefs.h> 360Sstevel@tonic-gate #include <sys/ddi_subrdefs.h> 37*10923SEvan.Yan@Sun.COM #include <sys/pci_impl.h> 383274Set142600 #include <sys/pcie_impl.h> 391624Spjha #include <sys/pci_cap.h> 400Sstevel@tonic-gate #include <sys/pci/pci_nexus.h> 410Sstevel@tonic-gate #include <sys/pci/pci_regs.h> 420Sstevel@tonic-gate #include <sys/ddi.h> 430Sstevel@tonic-gate #include <sys/sunndi.h> 440Sstevel@tonic-gate #include <sys/sunddi.h> 450Sstevel@tonic-gate #include <sys/fm/protocol.h> 460Sstevel@tonic-gate #include <sys/ddifm.h> 470Sstevel@tonic-gate #include <sys/pci/pci_pwr.h> 480Sstevel@tonic-gate #include <sys/pci/pci_debug.h> 49*10923SEvan.Yan@Sun.COM #include <sys/hotplug/pci/pcie_hp.h> 500Sstevel@tonic-gate #include <sys/hotplug/pci/pcihp.h> 510Sstevel@tonic-gate #include <sys/open.h> 520Sstevel@tonic-gate #include <sys/stat.h> 530Sstevel@tonic-gate #include <sys/file.h> 540Sstevel@tonic-gate 550Sstevel@tonic-gate #define NUM_LOGICAL_SLOTS 32 560Sstevel@tonic-gate 570Sstevel@tonic-gate #define PPB_RANGE_LEN 2 580Sstevel@tonic-gate 590Sstevel@tonic-gate #define PPB_32BIT_IO 1 600Sstevel@tonic-gate #define PPB_32bit_MEM 1 610Sstevel@tonic-gate 620Sstevel@tonic-gate #define PPB_MEMGRAIN 0x100000 630Sstevel@tonic-gate #define PPB_IOGRAIN 0x1000 640Sstevel@tonic-gate 650Sstevel@tonic-gate #define PPB_16bit_IOADDR(addr) ((uint16_t)(((uint8_t)(addr) & 0xF0) << 8)) 660Sstevel@tonic-gate #define PPB_LADDR(lo, hi) (((uint16_t)(hi) << 16) | (uint16_t)(lo)) 670Sstevel@tonic-gate #define PPB_32bit_MEMADDR(addr) (PPB_LADDR(0, ((uint16_t)(addr) & 0xFFF0))) 680Sstevel@tonic-gate 690Sstevel@tonic-gate typedef struct slot_table { 700Sstevel@tonic-gate uchar_t bus_id[128]; 710Sstevel@tonic-gate uchar_t slot_name[32]; 720Sstevel@tonic-gate uint8_t device_no; 730Sstevel@tonic-gate uint8_t phys_slot_num; 740Sstevel@tonic-gate } slot_table_t; 750Sstevel@tonic-gate 760Sstevel@tonic-gate /* 770Sstevel@tonic-gate * The variable controls the default setting of the command register 780Sstevel@tonic-gate * for pci devices. See ppb_initchild() for details. 790Sstevel@tonic-gate */ 800Sstevel@tonic-gate static ushort_t ppb_command_default = PCI_COMM_SERR_ENABLE | 810Sstevel@tonic-gate PCI_COMM_WAIT_CYC_ENAB | 820Sstevel@tonic-gate PCI_COMM_PARITY_DETECT | 830Sstevel@tonic-gate PCI_COMM_ME | 840Sstevel@tonic-gate PCI_COMM_MAE | 850Sstevel@tonic-gate PCI_COMM_IO; 860Sstevel@tonic-gate 870Sstevel@tonic-gate static int ppb_bus_map(dev_info_t *, dev_info_t *, ddi_map_req_t *, 880Sstevel@tonic-gate off_t, off_t, caddr_t *); 890Sstevel@tonic-gate static int ppb_ctlops(dev_info_t *, dev_info_t *, ddi_ctl_enum_t, 900Sstevel@tonic-gate void *, void *); 910Sstevel@tonic-gate static int ppb_intr_ops(dev_info_t *dip, dev_info_t *rdip, 920Sstevel@tonic-gate ddi_intr_op_t intr_op, ddi_intr_handle_impl_t *hdlp, void *result); 930Sstevel@tonic-gate 940Sstevel@tonic-gate /* 950Sstevel@tonic-gate * fm_init busop to initialize our children 960Sstevel@tonic-gate */ 970Sstevel@tonic-gate static int ppb_fm_init_child(dev_info_t *dip, dev_info_t *tdip, int cap, 980Sstevel@tonic-gate ddi_iblock_cookie_t *ibc); 990Sstevel@tonic-gate static void ppb_bus_enter(dev_info_t *dip, ddi_acc_handle_t handle); 1000Sstevel@tonic-gate static void ppb_bus_exit(dev_info_t *dip, ddi_acc_handle_t handle); 1010Sstevel@tonic-gate static int ppb_bus_power(dev_info_t *dip, void *impl_arg, pm_bus_power_op_t op, 1020Sstevel@tonic-gate void *arg, void *result); 1030Sstevel@tonic-gate 1040Sstevel@tonic-gate struct bus_ops ppb_bus_ops = { 1050Sstevel@tonic-gate BUSO_REV, 1060Sstevel@tonic-gate ppb_bus_map, 1070Sstevel@tonic-gate 0, 1080Sstevel@tonic-gate 0, 1090Sstevel@tonic-gate 0, 1100Sstevel@tonic-gate i_ddi_map_fault, 1110Sstevel@tonic-gate ddi_dma_map, 1120Sstevel@tonic-gate ddi_dma_allochdl, 1130Sstevel@tonic-gate ddi_dma_freehdl, 1140Sstevel@tonic-gate ddi_dma_bindhdl, 1150Sstevel@tonic-gate ddi_dma_unbindhdl, 1160Sstevel@tonic-gate ddi_dma_flush, 1170Sstevel@tonic-gate ddi_dma_win, 1180Sstevel@tonic-gate ddi_dma_mctl, 1190Sstevel@tonic-gate ppb_ctlops, 1200Sstevel@tonic-gate ddi_bus_prop_op, 1210Sstevel@tonic-gate ndi_busop_get_eventcookie, /* (*bus_get_eventcookie)(); */ 1220Sstevel@tonic-gate ndi_busop_add_eventcall, /* (*bus_add_eventcall)(); */ 1230Sstevel@tonic-gate ndi_busop_remove_eventcall, /* (*bus_remove_eventcall)(); */ 1240Sstevel@tonic-gate ndi_post_event, /* (*bus_post_event)(); */ 1250Sstevel@tonic-gate 0, /* (*bus_intr_ctl)(); */ 1260Sstevel@tonic-gate 0, /* (*bus_config)(); */ 1270Sstevel@tonic-gate 0, /* (*bus_unconfig)(); */ 1280Sstevel@tonic-gate ppb_fm_init_child, /* (*bus_fm_init)(); */ 1290Sstevel@tonic-gate NULL, /* (*bus_fm_fini)(); */ 1300Sstevel@tonic-gate ppb_bus_enter, /* (*bus_enter)() */ 1310Sstevel@tonic-gate ppb_bus_exit, /* (*bus_exit)() */ 1320Sstevel@tonic-gate ppb_bus_power, /* (*bus_power)() */ 133*10923SEvan.Yan@Sun.COM ppb_intr_ops, /* (*bus_intr_op)(); */ 134*10923SEvan.Yan@Sun.COM pcie_hp_common_ops /* (*bus_hp_op)(); */ 1350Sstevel@tonic-gate }; 1360Sstevel@tonic-gate 1370Sstevel@tonic-gate static int ppb_open(dev_t *devp, int flags, int otyp, cred_t *credp); 1380Sstevel@tonic-gate static int ppb_close(dev_t dev, int flags, int otyp, cred_t *credp); 1390Sstevel@tonic-gate static int ppb_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, 1400Sstevel@tonic-gate cred_t *credp, int *rvalp); 1410Sstevel@tonic-gate static int ppb_prop_op(dev_t dev, dev_info_t *dip, ddi_prop_op_t prop_op, 1420Sstevel@tonic-gate int flags, char *name, caddr_t valuep, int *lengthp); 1430Sstevel@tonic-gate 1440Sstevel@tonic-gate static struct cb_ops ppb_cb_ops = { 1450Sstevel@tonic-gate ppb_open, /* open */ 1460Sstevel@tonic-gate ppb_close, /* close */ 1470Sstevel@tonic-gate nulldev, /* strategy */ 1480Sstevel@tonic-gate nulldev, /* print */ 1490Sstevel@tonic-gate nulldev, /* dump */ 1500Sstevel@tonic-gate nulldev, /* read */ 1510Sstevel@tonic-gate nulldev, /* write */ 1520Sstevel@tonic-gate ppb_ioctl, /* ioctl */ 1530Sstevel@tonic-gate nodev, /* devmap */ 1540Sstevel@tonic-gate nodev, /* mmap */ 1550Sstevel@tonic-gate nodev, /* segmap */ 1560Sstevel@tonic-gate nochpoll, /* poll */ 1570Sstevel@tonic-gate ppb_prop_op, /* cb_prop_op */ 1580Sstevel@tonic-gate NULL, /* streamtab */ 1590Sstevel@tonic-gate D_NEW | D_MP | D_HOTPLUG, /* Driver compatibility flag */ 1600Sstevel@tonic-gate CB_REV, /* rev */ 1610Sstevel@tonic-gate nodev, /* int (*cb_aread)() */ 1620Sstevel@tonic-gate nodev /* int (*cb_awrite)() */ 1630Sstevel@tonic-gate }; 1640Sstevel@tonic-gate 1650Sstevel@tonic-gate static int ppb_probe(dev_info_t *); 1660Sstevel@tonic-gate static int ppb_attach(dev_info_t *devi, ddi_attach_cmd_t cmd); 1670Sstevel@tonic-gate static int ppb_detach(dev_info_t *devi, ddi_detach_cmd_t cmd); 168*10923SEvan.Yan@Sun.COM static int ppb_info(dev_info_t *dip, ddi_info_cmd_t cmd, 1690Sstevel@tonic-gate void *arg, void **result); 1700Sstevel@tonic-gate static int ppb_pwr(dev_info_t *dip, int component, int level); 1710Sstevel@tonic-gate 1720Sstevel@tonic-gate struct dev_ops ppb_ops = { 1730Sstevel@tonic-gate DEVO_REV, /* devo_rev */ 1740Sstevel@tonic-gate 0, /* refcnt */ 1750Sstevel@tonic-gate ppb_info, /* info */ 1760Sstevel@tonic-gate nulldev, /* identify */ 1770Sstevel@tonic-gate ppb_probe, /* probe */ 1780Sstevel@tonic-gate ppb_attach, /* attach */ 1790Sstevel@tonic-gate ppb_detach, /* detach */ 1800Sstevel@tonic-gate nulldev, /* reset */ 1810Sstevel@tonic-gate &ppb_cb_ops, /* driver operations */ 1820Sstevel@tonic-gate &ppb_bus_ops, /* bus operations */ 1837656SSherry.Moore@Sun.COM ppb_pwr, /* power */ 1847656SSherry.Moore@Sun.COM ddi_quiesce_not_needed, /* quiesce */ 1850Sstevel@tonic-gate }; 1860Sstevel@tonic-gate 1870Sstevel@tonic-gate /* 1880Sstevel@tonic-gate * Module linkage information for the kernel. 1890Sstevel@tonic-gate */ 1900Sstevel@tonic-gate 1910Sstevel@tonic-gate static struct modldrv modldrv = { 1920Sstevel@tonic-gate &mod_driverops, /* Type of module */ 1937656SSherry.Moore@Sun.COM "Standard PCI to PCI bridge nexus driver", 1940Sstevel@tonic-gate &ppb_ops, /* driver ops */ 1950Sstevel@tonic-gate }; 1960Sstevel@tonic-gate 1970Sstevel@tonic-gate static struct modlinkage modlinkage = { 1980Sstevel@tonic-gate MODREV_1, 1990Sstevel@tonic-gate (void *)&modldrv, 2000Sstevel@tonic-gate NULL 2010Sstevel@tonic-gate }; 2020Sstevel@tonic-gate 2030Sstevel@tonic-gate /* 2040Sstevel@tonic-gate * soft state pointer and structure template: 2050Sstevel@tonic-gate */ 2060Sstevel@tonic-gate static void *ppb_state; 2070Sstevel@tonic-gate 208946Smathue struct ppb_cfg_state { 2090Sstevel@tonic-gate dev_info_t *dip; 2100Sstevel@tonic-gate ushort_t command; 2110Sstevel@tonic-gate uchar_t cache_line_size; 2120Sstevel@tonic-gate uchar_t latency_timer; 2130Sstevel@tonic-gate uchar_t header_type; 2140Sstevel@tonic-gate uchar_t sec_latency_timer; 2150Sstevel@tonic-gate ushort_t bridge_control; 2160Sstevel@tonic-gate }; 2170Sstevel@tonic-gate 2180Sstevel@tonic-gate typedef struct { 2190Sstevel@tonic-gate 2200Sstevel@tonic-gate dev_info_t *dip; 2210Sstevel@tonic-gate 2220Sstevel@tonic-gate /* 2230Sstevel@tonic-gate * configuration register state for the bus: 2240Sstevel@tonic-gate */ 2250Sstevel@tonic-gate uchar_t ppb_cache_line_size; 2260Sstevel@tonic-gate uchar_t ppb_latency_timer; 2270Sstevel@tonic-gate 2280Sstevel@tonic-gate /* 2290Sstevel@tonic-gate * PM support 2300Sstevel@tonic-gate */ 2310Sstevel@tonic-gate ddi_acc_handle_t ppb_conf_hdl; 2321624Spjha uint16_t ppb_pm_cap_ptr; 2330Sstevel@tonic-gate pci_pwr_t *ppb_pwr_p; 2340Sstevel@tonic-gate 2350Sstevel@tonic-gate /* 2360Sstevel@tonic-gate * HP support 2370Sstevel@tonic-gate */ 2380Sstevel@tonic-gate boolean_t hotplug_capable; 2390Sstevel@tonic-gate 2400Sstevel@tonic-gate kmutex_t ppb_mutex; 2410Sstevel@tonic-gate uint_t ppb_soft_state; 2420Sstevel@tonic-gate int fm_cap; 2430Sstevel@tonic-gate ddi_iblock_cookie_t fm_ibc; 2443274Set142600 2459921SKrishna.Elango@Sun.COM uint16_t parent_bus; 2460Sstevel@tonic-gate } ppb_devstate_t; 2470Sstevel@tonic-gate 2480Sstevel@tonic-gate /* 2490Sstevel@tonic-gate * The following variable enables a workaround for the following obp bug: 2500Sstevel@tonic-gate * 2510Sstevel@tonic-gate * 1234181 - obp should set latency timer registers in pci 2520Sstevel@tonic-gate * configuration header 2530Sstevel@tonic-gate * 2540Sstevel@tonic-gate * Until this bug gets fixed in the obp, the following workaround should 2550Sstevel@tonic-gate * be enabled. 2560Sstevel@tonic-gate */ 2570Sstevel@tonic-gate static uint_t ppb_set_latency_timer_register = 1; 2580Sstevel@tonic-gate 2590Sstevel@tonic-gate /* 2600Sstevel@tonic-gate * The following variable enables a workaround for an obp bug to be 2610Sstevel@tonic-gate * submitted. A bug requesting a workaround fof this problem has 2620Sstevel@tonic-gate * been filed: 2630Sstevel@tonic-gate * 2640Sstevel@tonic-gate * 1235094 - need workarounds on positron nexus drivers to set cache 2650Sstevel@tonic-gate * line size registers 2660Sstevel@tonic-gate * 2670Sstevel@tonic-gate * Until this bug gets fixed in the obp, the following workaround should 2680Sstevel@tonic-gate * be enabled. 2690Sstevel@tonic-gate */ 2700Sstevel@tonic-gate static uint_t ppb_set_cache_line_size_register = 1; 2710Sstevel@tonic-gate 2720Sstevel@tonic-gate /* 2730Sstevel@tonic-gate * forward function declarations: 2740Sstevel@tonic-gate */ 2750Sstevel@tonic-gate 2760Sstevel@tonic-gate /* 2770Sstevel@tonic-gate * FMA error callback 2780Sstevel@tonic-gate * Register error handling callback with our parent. We will just call 2790Sstevel@tonic-gate * our children's error callbacks and return their status. 2800Sstevel@tonic-gate */ 2810Sstevel@tonic-gate static int ppb_err_callback(dev_info_t *dip, ddi_fm_error_t *derr, 2820Sstevel@tonic-gate const void *impl_data); 2830Sstevel@tonic-gate 2840Sstevel@tonic-gate /* 2850Sstevel@tonic-gate * init/fini routines to alloc/dealloc fm structures and 2860Sstevel@tonic-gate * register/unregister our callback. 2870Sstevel@tonic-gate */ 2880Sstevel@tonic-gate static void ppb_fm_init(ppb_devstate_t *ppb_p); 2890Sstevel@tonic-gate static void ppb_fm_fini(ppb_devstate_t *ppb_p); 2900Sstevel@tonic-gate 2910Sstevel@tonic-gate static void ppb_removechild(dev_info_t *); 2920Sstevel@tonic-gate static int ppb_initchild(dev_info_t *child); 2933274Set142600 static void ppb_uninitchild(dev_info_t *child); 2940Sstevel@tonic-gate static dev_info_t *get_my_childs_dip(dev_info_t *dip, dev_info_t *rdip); 2950Sstevel@tonic-gate static void ppb_pwr_setup(ppb_devstate_t *ppb, dev_info_t *dip); 2960Sstevel@tonic-gate static void ppb_pwr_teardown(ppb_devstate_t *ppb, dev_info_t *dip); 2970Sstevel@tonic-gate static void ppb_init_hotplug(ppb_devstate_t *ppb); 2980Sstevel@tonic-gate static void ppb_create_ranges_prop(dev_info_t *, ddi_acc_handle_t); 299964Smathue uint64_t pci_debug_flags = 0; 3000Sstevel@tonic-gate 3010Sstevel@tonic-gate int 3020Sstevel@tonic-gate _init(void) 3030Sstevel@tonic-gate { 3040Sstevel@tonic-gate int e; 3050Sstevel@tonic-gate if ((e = ddi_soft_state_init(&ppb_state, sizeof (ppb_devstate_t), 3060Sstevel@tonic-gate 1)) == 0 && (e = mod_install(&modlinkage)) != 0) 3070Sstevel@tonic-gate ddi_soft_state_fini(&ppb_state); 3080Sstevel@tonic-gate return (e); 3090Sstevel@tonic-gate } 3100Sstevel@tonic-gate 3110Sstevel@tonic-gate int 3120Sstevel@tonic-gate _fini(void) 3130Sstevel@tonic-gate { 3140Sstevel@tonic-gate int e; 3150Sstevel@tonic-gate 3160Sstevel@tonic-gate if ((e = mod_remove(&modlinkage)) == 0) 3170Sstevel@tonic-gate ddi_soft_state_fini(&ppb_state); 3180Sstevel@tonic-gate return (e); 3190Sstevel@tonic-gate } 3200Sstevel@tonic-gate 3210Sstevel@tonic-gate int 3220Sstevel@tonic-gate _info(struct modinfo *modinfop) 3230Sstevel@tonic-gate { 3240Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 3250Sstevel@tonic-gate } 3260Sstevel@tonic-gate 3270Sstevel@tonic-gate /*ARGSUSED*/ 3280Sstevel@tonic-gate static int 329*10923SEvan.Yan@Sun.COM ppb_info(dev_info_t *dip, ddi_info_cmd_t cmd, void *arg, void **result) 3300Sstevel@tonic-gate { 3310Sstevel@tonic-gate minor_t minor = getminor((dev_t)arg); 332*10923SEvan.Yan@Sun.COM int instance = PCI_MINOR_NUM_TO_INSTANCE(minor); 333*10923SEvan.Yan@Sun.COM ppb_devstate_t *ppb_p = (ppb_devstate_t *)ddi_get_soft_state(ppb_state, 3340Sstevel@tonic-gate instance); 3350Sstevel@tonic-gate 336*10923SEvan.Yan@Sun.COM 337*10923SEvan.Yan@Sun.COM if (ppb_p->parent_bus != PCIE_PCIECAP_DEV_TYPE_PCIE_DEV) 338*10923SEvan.Yan@Sun.COM return (pcihp_info(dip, cmd, arg, result)); 339*10923SEvan.Yan@Sun.COM 340*10923SEvan.Yan@Sun.COM switch (cmd) { 3410Sstevel@tonic-gate default: 3420Sstevel@tonic-gate return (DDI_FAILURE); 3430Sstevel@tonic-gate 3440Sstevel@tonic-gate case DDI_INFO_DEVT2INSTANCE: 345946Smathue *result = (void *)(uintptr_t)instance; 3460Sstevel@tonic-gate return (DDI_SUCCESS); 3470Sstevel@tonic-gate 3480Sstevel@tonic-gate case DDI_INFO_DEVT2DEVINFO: 3490Sstevel@tonic-gate if (ppb_p == NULL) 3500Sstevel@tonic-gate return (DDI_FAILURE); 3510Sstevel@tonic-gate *result = (void *)ppb_p->dip; 3520Sstevel@tonic-gate return (DDI_SUCCESS); 3530Sstevel@tonic-gate } 3540Sstevel@tonic-gate } 3550Sstevel@tonic-gate 3560Sstevel@tonic-gate /*ARGSUSED*/ 3570Sstevel@tonic-gate static int 3580Sstevel@tonic-gate ppb_probe(register dev_info_t *devi) 3590Sstevel@tonic-gate { 3600Sstevel@tonic-gate return (DDI_PROBE_SUCCESS); 3610Sstevel@tonic-gate } 3620Sstevel@tonic-gate 3630Sstevel@tonic-gate /*ARGSUSED*/ 3640Sstevel@tonic-gate static int 3650Sstevel@tonic-gate ppb_attach(dev_info_t *devi, ddi_attach_cmd_t cmd) 3660Sstevel@tonic-gate { 367*10923SEvan.Yan@Sun.COM dev_info_t *root = ddi_root_node(); 3680Sstevel@tonic-gate int instance; 3690Sstevel@tonic-gate ppb_devstate_t *ppb; 370*10923SEvan.Yan@Sun.COM dev_info_t *pdip; 3710Sstevel@tonic-gate ddi_acc_handle_t config_handle; 372*10923SEvan.Yan@Sun.COM char *bus; 3730Sstevel@tonic-gate 3740Sstevel@tonic-gate switch (cmd) { 3750Sstevel@tonic-gate case DDI_ATTACH: 3760Sstevel@tonic-gate 3770Sstevel@tonic-gate /* 3780Sstevel@tonic-gate * Make sure the "device_type" property exists. 3790Sstevel@tonic-gate */ 3800Sstevel@tonic-gate (void) ddi_prop_update_string(DDI_DEV_T_NONE, devi, 3810Sstevel@tonic-gate "device_type", "pci"); 3820Sstevel@tonic-gate 3830Sstevel@tonic-gate /* 3840Sstevel@tonic-gate * Allocate and get soft state structure. 3850Sstevel@tonic-gate */ 3860Sstevel@tonic-gate instance = ddi_get_instance(devi); 3870Sstevel@tonic-gate if (ddi_soft_state_zalloc(ppb_state, instance) != DDI_SUCCESS) 3880Sstevel@tonic-gate return (DDI_FAILURE); 3890Sstevel@tonic-gate ppb = (ppb_devstate_t *)ddi_get_soft_state(ppb_state, instance); 3900Sstevel@tonic-gate ppb->dip = devi; 3910Sstevel@tonic-gate mutex_init(&ppb->ppb_mutex, NULL, MUTEX_DRIVER, NULL); 392*10923SEvan.Yan@Sun.COM ppb->ppb_soft_state = PCI_SOFT_STATE_CLOSED; 3930Sstevel@tonic-gate if (pci_config_setup(devi, &config_handle) != DDI_SUCCESS) { 3940Sstevel@tonic-gate mutex_destroy(&ppb->ppb_mutex); 3950Sstevel@tonic-gate ddi_soft_state_free(ppb_state, instance); 3960Sstevel@tonic-gate return (DDI_FAILURE); 3970Sstevel@tonic-gate } 3980Sstevel@tonic-gate ppb_pwr_setup(ppb, devi); 3990Sstevel@tonic-gate 4000Sstevel@tonic-gate if (PM_CAPABLE(ppb->ppb_pwr_p)) { 4010Sstevel@tonic-gate mutex_enter(&ppb->ppb_pwr_p->pwr_mutex); 4020Sstevel@tonic-gate 4030Sstevel@tonic-gate /* 4040Sstevel@tonic-gate * Before reading config registers, make sure power is 4050Sstevel@tonic-gate * on, and remains on. 4060Sstevel@tonic-gate */ 4070Sstevel@tonic-gate ppb->ppb_pwr_p->pwr_fp++; 4080Sstevel@tonic-gate 4090Sstevel@tonic-gate pci_pwr_change(ppb->ppb_pwr_p, 4100Sstevel@tonic-gate ppb->ppb_pwr_p->current_lvl, 4110Sstevel@tonic-gate pci_pwr_new_lvl(ppb->ppb_pwr_p)); 4120Sstevel@tonic-gate } 4130Sstevel@tonic-gate 4140Sstevel@tonic-gate ppb->ppb_cache_line_size = 4150Sstevel@tonic-gate pci_config_get8(config_handle, PCI_CONF_CACHE_LINESZ); 4160Sstevel@tonic-gate ppb->ppb_latency_timer = 4170Sstevel@tonic-gate pci_config_get8(config_handle, PCI_CONF_LATENCY_TIMER); 4180Sstevel@tonic-gate 4190Sstevel@tonic-gate /* 4200Sstevel@tonic-gate * Check whether the "ranges" property is present. 4210Sstevel@tonic-gate * Otherwise create the ranges property by reading 4220Sstevel@tonic-gate * the configuration registers 4230Sstevel@tonic-gate */ 4240Sstevel@tonic-gate if (ddi_prop_exists(DDI_DEV_T_ANY, devi, DDI_PROP_DONTPASS, 4250Sstevel@tonic-gate "ranges") == 0) { 4260Sstevel@tonic-gate ppb_create_ranges_prop(devi, config_handle); 4270Sstevel@tonic-gate } 4280Sstevel@tonic-gate 4290Sstevel@tonic-gate pci_config_teardown(&config_handle); 4300Sstevel@tonic-gate 4310Sstevel@tonic-gate if (PM_CAPABLE(ppb->ppb_pwr_p)) { 4320Sstevel@tonic-gate ppb->ppb_pwr_p->pwr_fp--; 4330Sstevel@tonic-gate 4340Sstevel@tonic-gate pci_pwr_change(ppb->ppb_pwr_p, 4350Sstevel@tonic-gate ppb->ppb_pwr_p->current_lvl, 4360Sstevel@tonic-gate pci_pwr_new_lvl(ppb->ppb_pwr_p)); 4370Sstevel@tonic-gate 4380Sstevel@tonic-gate mutex_exit(&ppb->ppb_pwr_p->pwr_mutex); 4390Sstevel@tonic-gate } 4400Sstevel@tonic-gate 441*10923SEvan.Yan@Sun.COM ppb->parent_bus = PCIE_PCIECAP_DEV_TYPE_PCI_PSEUDO; 442*10923SEvan.Yan@Sun.COM for (pdip = ddi_get_parent(ppb->dip); pdip && (pdip != root) && 443*10923SEvan.Yan@Sun.COM (ppb->parent_bus != PCIE_PCIECAP_DEV_TYPE_PCIE_DEV); 444*10923SEvan.Yan@Sun.COM pdip = ddi_get_parent(pdip)) { 445*10923SEvan.Yan@Sun.COM if (ddi_prop_lookup_string(DDI_DEV_T_ANY, pdip, 446*10923SEvan.Yan@Sun.COM DDI_PROP_DONTPASS, "device_type", &bus) != 447*10923SEvan.Yan@Sun.COM DDI_PROP_SUCCESS) 448*10923SEvan.Yan@Sun.COM break; 449*10923SEvan.Yan@Sun.COM 450*10923SEvan.Yan@Sun.COM if (strcmp(bus, "pciex") == 0) 451*10923SEvan.Yan@Sun.COM ppb->parent_bus = 452*10923SEvan.Yan@Sun.COM PCIE_PCIECAP_DEV_TYPE_PCIE_DEV; 453*10923SEvan.Yan@Sun.COM 454*10923SEvan.Yan@Sun.COM ddi_prop_free(bus); 455*10923SEvan.Yan@Sun.COM } 456*10923SEvan.Yan@Sun.COM 4570Sstevel@tonic-gate /* 458*10923SEvan.Yan@Sun.COM * Initialize hotplug support on this bus. 4590Sstevel@tonic-gate */ 460*10923SEvan.Yan@Sun.COM if (ppb->parent_bus == PCIE_PCIECAP_DEV_TYPE_PCIE_DEV) 461*10923SEvan.Yan@Sun.COM if (pcie_init(devi, NULL) != DDI_SUCCESS) { 462*10923SEvan.Yan@Sun.COM (void) ppb_detach(devi, DDI_DETACH); 4630Sstevel@tonic-gate return (DDI_FAILURE); 4640Sstevel@tonic-gate } 465*10923SEvan.Yan@Sun.COM else 466*10923SEvan.Yan@Sun.COM ppb_init_hotplug(ppb); 4670Sstevel@tonic-gate 4680Sstevel@tonic-gate DEBUG1(DBG_ATTACH, devi, 4697656SSherry.Moore@Sun.COM "ppb_attach(): this nexus %s hotplug slots\n", 4707656SSherry.Moore@Sun.COM ppb->hotplug_capable == B_TRUE ? "has":"has no"); 4710Sstevel@tonic-gate 4720Sstevel@tonic-gate ppb_fm_init(ppb); 4730Sstevel@tonic-gate ddi_report_dev(devi); 4740Sstevel@tonic-gate 4750Sstevel@tonic-gate return (DDI_SUCCESS); 4760Sstevel@tonic-gate 4770Sstevel@tonic-gate case DDI_RESUME: 4780Sstevel@tonic-gate /* 4790Sstevel@tonic-gate * Get the soft state structure for the bridge. 4800Sstevel@tonic-gate */ 4810Sstevel@tonic-gate ppb = (ppb_devstate_t *) 4827656SSherry.Moore@Sun.COM ddi_get_soft_state(ppb_state, ddi_get_instance(devi)); 4830Sstevel@tonic-gate 4840Sstevel@tonic-gate pci_pwr_resume(devi, ppb->ppb_pwr_p); 4850Sstevel@tonic-gate 4860Sstevel@tonic-gate return (DDI_SUCCESS); 4870Sstevel@tonic-gate } 4880Sstevel@tonic-gate return (DDI_FAILURE); 4890Sstevel@tonic-gate } 4900Sstevel@tonic-gate 4910Sstevel@tonic-gate /*ARGSUSED*/ 4920Sstevel@tonic-gate static int 4930Sstevel@tonic-gate ppb_detach(dev_info_t *devi, ddi_detach_cmd_t cmd) 4940Sstevel@tonic-gate { 4950Sstevel@tonic-gate ppb_devstate_t *ppb; 496*10923SEvan.Yan@Sun.COM int ret = DDI_SUCCESS; 4970Sstevel@tonic-gate 4980Sstevel@tonic-gate switch (cmd) { 4990Sstevel@tonic-gate case DDI_DETACH: 5000Sstevel@tonic-gate /* 5010Sstevel@tonic-gate * And finally free the per-pci soft state after 5020Sstevel@tonic-gate * uninitializing hotplug support for this bus. 5030Sstevel@tonic-gate */ 5040Sstevel@tonic-gate ppb = (ppb_devstate_t *) 5050Sstevel@tonic-gate ddi_get_soft_state(ppb_state, ddi_get_instance(devi)); 5060Sstevel@tonic-gate 5070Sstevel@tonic-gate ppb_fm_fini(ppb); 5080Sstevel@tonic-gate 509*10923SEvan.Yan@Sun.COM if (ppb->parent_bus == PCIE_PCIECAP_DEV_TYPE_PCIE_DEV) 510*10923SEvan.Yan@Sun.COM ret = pcie_uninit(devi); 511*10923SEvan.Yan@Sun.COM else if (ppb->hotplug_capable == B_TRUE) 512*10923SEvan.Yan@Sun.COM ret = pcihp_init(devi); 5130Sstevel@tonic-gate else 5140Sstevel@tonic-gate ddi_remove_minor_node(devi, "devctl"); 5150Sstevel@tonic-gate 516*10923SEvan.Yan@Sun.COM if (ret != DDI_SUCCESS) 517*10923SEvan.Yan@Sun.COM return (DDI_FAILURE); 518*10923SEvan.Yan@Sun.COM 5190Sstevel@tonic-gate (void) ddi_prop_remove(DDI_DEV_T_NONE, devi, "device_type"); 5200Sstevel@tonic-gate 5210Sstevel@tonic-gate if (ppb->ppb_pwr_p != NULL) { 5220Sstevel@tonic-gate ppb_pwr_teardown(ppb, devi); 5230Sstevel@tonic-gate } 5240Sstevel@tonic-gate mutex_destroy(&ppb->ppb_mutex); 5250Sstevel@tonic-gate ddi_soft_state_free(ppb_state, ddi_get_instance(devi)); 5260Sstevel@tonic-gate 5270Sstevel@tonic-gate return (DDI_SUCCESS); 5280Sstevel@tonic-gate 5290Sstevel@tonic-gate case DDI_SUSPEND: 5300Sstevel@tonic-gate ppb = (ppb_devstate_t *) 5317656SSherry.Moore@Sun.COM ddi_get_soft_state(ppb_state, ddi_get_instance(devi)); 5320Sstevel@tonic-gate 5330Sstevel@tonic-gate pci_pwr_suspend(devi, ppb->ppb_pwr_p); 5340Sstevel@tonic-gate 5350Sstevel@tonic-gate return (DDI_SUCCESS); 5360Sstevel@tonic-gate } 5370Sstevel@tonic-gate return (DDI_FAILURE); 5380Sstevel@tonic-gate } 5390Sstevel@tonic-gate 5400Sstevel@tonic-gate /*ARGSUSED*/ 5410Sstevel@tonic-gate static int 5420Sstevel@tonic-gate ppb_bus_map(dev_info_t *dip, dev_info_t *rdip, ddi_map_req_t *mp, 5430Sstevel@tonic-gate off_t offset, off_t len, caddr_t *vaddrp) 5440Sstevel@tonic-gate { 5450Sstevel@tonic-gate register dev_info_t *pdip; 5460Sstevel@tonic-gate 5470Sstevel@tonic-gate pdip = (dev_info_t *)DEVI(dip)->devi_parent; 5480Sstevel@tonic-gate return ((DEVI(pdip)->devi_ops->devo_bus_ops->bus_map) 5490Sstevel@tonic-gate (pdip, rdip, mp, offset, len, vaddrp)); 5500Sstevel@tonic-gate } 5510Sstevel@tonic-gate 5520Sstevel@tonic-gate /*ARGSUSED*/ 5530Sstevel@tonic-gate static int 5540Sstevel@tonic-gate ppb_ctlops(dev_info_t *dip, dev_info_t *rdip, 5550Sstevel@tonic-gate ddi_ctl_enum_t ctlop, void *arg, void *result) 5560Sstevel@tonic-gate { 5570Sstevel@tonic-gate pci_regspec_t *drv_regp; 5580Sstevel@tonic-gate int reglen; 5590Sstevel@tonic-gate int rn; 5603274Set142600 struct attachspec *as; 5613274Set142600 struct detachspec *ds; 5623274Set142600 int totreg; 5633274Set142600 ppb_devstate_t *ppb_p; 5643272Sdduvall 5653274Set142600 ppb_p = (ppb_devstate_t *)ddi_get_soft_state(ppb_state, 5663274Set142600 ddi_get_instance(dip)); 5670Sstevel@tonic-gate 5680Sstevel@tonic-gate switch (ctlop) { 5690Sstevel@tonic-gate case DDI_CTLOPS_REPORTDEV: 5700Sstevel@tonic-gate if (rdip == (dev_info_t *)0) 5710Sstevel@tonic-gate return (DDI_FAILURE); 5720Sstevel@tonic-gate cmn_err(CE_CONT, "?PCI-device: %s@%s, %s%d\n", 5730Sstevel@tonic-gate ddi_node_name(rdip), ddi_get_name_addr(rdip), 5740Sstevel@tonic-gate ddi_driver_name(rdip), 5750Sstevel@tonic-gate ddi_get_instance(rdip)); 5760Sstevel@tonic-gate return (DDI_SUCCESS); 5770Sstevel@tonic-gate 5780Sstevel@tonic-gate case DDI_CTLOPS_INITCHILD: 5790Sstevel@tonic-gate return (ppb_initchild((dev_info_t *)arg)); 5800Sstevel@tonic-gate 5810Sstevel@tonic-gate case DDI_CTLOPS_UNINITCHILD: 5823274Set142600 ppb_uninitchild((dev_info_t *)arg); 5833274Set142600 return (DDI_SUCCESS); 5843274Set142600 5853274Set142600 case DDI_CTLOPS_ATTACH: 5863274Set142600 if (!pcie_is_child(dip, rdip)) 5873274Set142600 return (DDI_SUCCESS); 5883274Set142600 5893274Set142600 as = (struct attachspec *)arg; 5903274Set142600 if ((ppb_p->parent_bus == PCIE_PCIECAP_DEV_TYPE_PCIE_DEV) && 5914005Skrishnae (as->when == DDI_POST) && (as->result == DDI_SUCCESS)) 5923756Skrishnae pf_init(rdip, ppb_p->fm_ibc, as->cmd); 5933274Set142600 5943274Set142600 return (DDI_SUCCESS); 5953274Set142600 5963274Set142600 case DDI_CTLOPS_DETACH: 5973274Set142600 if (!pcie_is_child(dip, rdip)) 5983274Set142600 return (DDI_SUCCESS); 5993274Set142600 6003274Set142600 ds = (struct detachspec *)arg; 6013274Set142600 if ((ppb_p->parent_bus == PCIE_PCIECAP_DEV_TYPE_PCIE_DEV) && 6023274Set142600 (ds->when == DDI_PRE)) 6033756Skrishnae pf_fini(rdip, ds->cmd); 6043274Set142600 6050Sstevel@tonic-gate return (DDI_SUCCESS); 6060Sstevel@tonic-gate 6070Sstevel@tonic-gate case DDI_CTLOPS_SIDDEV: 6080Sstevel@tonic-gate return (DDI_SUCCESS); 6090Sstevel@tonic-gate 6100Sstevel@tonic-gate case DDI_CTLOPS_REGSIZE: 6110Sstevel@tonic-gate case DDI_CTLOPS_NREGS: 6120Sstevel@tonic-gate if (rdip == (dev_info_t *)0) 6130Sstevel@tonic-gate return (DDI_FAILURE); 6140Sstevel@tonic-gate break; 6150Sstevel@tonic-gate default: 6160Sstevel@tonic-gate return (ddi_ctlops(dip, rdip, ctlop, arg, result)); 6170Sstevel@tonic-gate } 6180Sstevel@tonic-gate 6190Sstevel@tonic-gate *(int *)result = 0; 620506Scth if (ddi_getlongprop(DDI_DEV_T_ANY, rdip, 6217656SSherry.Moore@Sun.COM DDI_PROP_DONTPASS | DDI_PROP_CANSLEEP, "reg", 6227656SSherry.Moore@Sun.COM (caddr_t)&drv_regp, ®len) != DDI_SUCCESS) 6230Sstevel@tonic-gate return (DDI_FAILURE); 6240Sstevel@tonic-gate 6250Sstevel@tonic-gate totreg = reglen / sizeof (pci_regspec_t); 6260Sstevel@tonic-gate if (ctlop == DDI_CTLOPS_NREGS) 6270Sstevel@tonic-gate *(int *)result = totreg; 6280Sstevel@tonic-gate else if (ctlop == DDI_CTLOPS_REGSIZE) { 6290Sstevel@tonic-gate rn = *(int *)arg; 6300Sstevel@tonic-gate if (rn >= totreg) { 6310Sstevel@tonic-gate kmem_free(drv_regp, reglen); 6320Sstevel@tonic-gate return (DDI_FAILURE); 6330Sstevel@tonic-gate } 6340Sstevel@tonic-gate *(off_t *)result = drv_regp[rn].pci_size_low | 6357656SSherry.Moore@Sun.COM ((uint64_t)drv_regp[rn].pci_size_hi << 32); 6360Sstevel@tonic-gate } 6370Sstevel@tonic-gate 6380Sstevel@tonic-gate kmem_free(drv_regp, reglen); 6390Sstevel@tonic-gate return (DDI_SUCCESS); 6400Sstevel@tonic-gate } 6410Sstevel@tonic-gate 6420Sstevel@tonic-gate 6430Sstevel@tonic-gate static dev_info_t * 6440Sstevel@tonic-gate get_my_childs_dip(dev_info_t *dip, dev_info_t *rdip) 6450Sstevel@tonic-gate { 6460Sstevel@tonic-gate dev_info_t *cdip = rdip; 6470Sstevel@tonic-gate 6480Sstevel@tonic-gate for (; ddi_get_parent(cdip) != dip; cdip = ddi_get_parent(cdip)) 6490Sstevel@tonic-gate ; 6500Sstevel@tonic-gate 6510Sstevel@tonic-gate return (cdip); 6520Sstevel@tonic-gate } 6530Sstevel@tonic-gate 6540Sstevel@tonic-gate 6550Sstevel@tonic-gate static int 6560Sstevel@tonic-gate ppb_intr_ops(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t intr_op, 6570Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp, void *result) 6580Sstevel@tonic-gate { 659693Sgovinda dev_info_t *cdip = rdip; 660693Sgovinda pci_regspec_t *pci_rp; 661693Sgovinda int reglen, len; 662693Sgovinda uint32_t d, intr; 6630Sstevel@tonic-gate 6644395Sgovinda if ((intr_op == DDI_INTROP_SUPPORTED_TYPES) || 6654395Sgovinda (hdlp->ih_type != DDI_INTR_TYPE_FIXED)) 6660Sstevel@tonic-gate goto done; 6670Sstevel@tonic-gate 6680Sstevel@tonic-gate /* 6690Sstevel@tonic-gate * If the interrupt-map property is defined at this 6700Sstevel@tonic-gate * node, it will have performed the interrupt 6710Sstevel@tonic-gate * translation as part of the property, so no 6720Sstevel@tonic-gate * rotation needs to be done. 6730Sstevel@tonic-gate */ 6740Sstevel@tonic-gate if (ddi_getproplen(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, 6750Sstevel@tonic-gate "interrupt-map", &len) == DDI_PROP_SUCCESS) 6760Sstevel@tonic-gate goto done; 6770Sstevel@tonic-gate 6780Sstevel@tonic-gate cdip = get_my_childs_dip(dip, rdip); 6790Sstevel@tonic-gate 6800Sstevel@tonic-gate /* 6810Sstevel@tonic-gate * Use the devices reg property to determine its 6820Sstevel@tonic-gate * PCI bus number and device number. 6830Sstevel@tonic-gate */ 684506Scth if (ddi_getlongprop(DDI_DEV_T_ANY, cdip, DDI_PROP_DONTPASS, 6850Sstevel@tonic-gate "reg", (caddr_t)&pci_rp, ®len) != DDI_SUCCESS) 6860Sstevel@tonic-gate return (DDI_FAILURE); 6870Sstevel@tonic-gate 688693Sgovinda intr = hdlp->ih_vector; 6890Sstevel@tonic-gate 6900Sstevel@tonic-gate /* Spin the interrupt */ 6910Sstevel@tonic-gate d = PCI_REG_DEV_G(pci_rp[0].pci_phys_hi); 6920Sstevel@tonic-gate 6930Sstevel@tonic-gate if ((intr >= PCI_INTA) && (intr <= PCI_INTD)) 694693Sgovinda hdlp->ih_vector = ((intr - 1 + (d % 4)) % 4 + 1); 6950Sstevel@tonic-gate else 6960Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d: %s: PCI intr=%x out of range", 6970Sstevel@tonic-gate ddi_driver_name(rdip), ddi_get_instance(rdip), 6980Sstevel@tonic-gate ddi_driver_name(dip), intr); 6990Sstevel@tonic-gate 7000Sstevel@tonic-gate kmem_free(pci_rp, reglen); 7010Sstevel@tonic-gate 7020Sstevel@tonic-gate done: 7030Sstevel@tonic-gate /* Pass up the request to our parent. */ 7040Sstevel@tonic-gate return (i_ddi_intr_ops(dip, rdip, intr_op, hdlp, result)); 7050Sstevel@tonic-gate } 7060Sstevel@tonic-gate 7070Sstevel@tonic-gate static int 7080Sstevel@tonic-gate ppb_bus_power(dev_info_t *dip, void *impl_arg, pm_bus_power_op_t op, 7090Sstevel@tonic-gate void *arg, void *result) 7100Sstevel@tonic-gate { 7110Sstevel@tonic-gate ppb_devstate_t *ppb; 7120Sstevel@tonic-gate 7130Sstevel@tonic-gate ppb = (ppb_devstate_t *)ddi_get_soft_state(ppb_state, 7140Sstevel@tonic-gate ddi_get_instance(dip)); 7150Sstevel@tonic-gate 7160Sstevel@tonic-gate return (pci_pwr_ops(ppb->ppb_pwr_p, dip, impl_arg, op, arg, result)); 7170Sstevel@tonic-gate } 7180Sstevel@tonic-gate 7190Sstevel@tonic-gate 7200Sstevel@tonic-gate /* 7210Sstevel@tonic-gate * name_child 7220Sstevel@tonic-gate * 7230Sstevel@tonic-gate * This function is called from init_child to name a node. It is 7240Sstevel@tonic-gate * also passed as a callback for node merging functions. 7250Sstevel@tonic-gate * 7260Sstevel@tonic-gate * return value: DDI_SUCCESS, DDI_FAILURE 7270Sstevel@tonic-gate */ 7280Sstevel@tonic-gate static int 7290Sstevel@tonic-gate ppb_name_child(dev_info_t *child, char *name, int namelen) 7300Sstevel@tonic-gate { 7310Sstevel@tonic-gate pci_regspec_t *pci_rp; 7320Sstevel@tonic-gate uint_t slot, func; 7330Sstevel@tonic-gate char **unit_addr; 7340Sstevel@tonic-gate uint_t n; 7350Sstevel@tonic-gate 7360Sstevel@tonic-gate /* 7370Sstevel@tonic-gate * Pseudo nodes indicate a prototype node with per-instance 7380Sstevel@tonic-gate * properties to be merged into the real h/w device node. 7390Sstevel@tonic-gate * The interpretation of the unit-address is DD[,F] 7400Sstevel@tonic-gate * where DD is the device id and F is the function. 7410Sstevel@tonic-gate */ 7420Sstevel@tonic-gate if (ndi_dev_is_persistent_node(child) == 0) { 7430Sstevel@tonic-gate if (ddi_prop_lookup_string_array(DDI_DEV_T_ANY, child, 7440Sstevel@tonic-gate DDI_PROP_DONTPASS, "unit-address", &unit_addr, &n) != 7450Sstevel@tonic-gate DDI_PROP_SUCCESS) { 7460Sstevel@tonic-gate cmn_err(CE_WARN, "cannot name node from %s.conf", 7470Sstevel@tonic-gate ddi_driver_name(child)); 7480Sstevel@tonic-gate return (DDI_FAILURE); 7490Sstevel@tonic-gate } 7500Sstevel@tonic-gate if (n != 1 || *unit_addr == NULL || **unit_addr == 0) { 7510Sstevel@tonic-gate cmn_err(CE_WARN, "unit-address property in %s.conf" 7520Sstevel@tonic-gate " not well-formed", ddi_driver_name(child)); 7530Sstevel@tonic-gate ddi_prop_free(unit_addr); 7540Sstevel@tonic-gate return (DDI_FAILURE); 7550Sstevel@tonic-gate } 7560Sstevel@tonic-gate (void) snprintf(name, namelen, "%s", *unit_addr); 7570Sstevel@tonic-gate ddi_prop_free(unit_addr); 7580Sstevel@tonic-gate return (DDI_SUCCESS); 7590Sstevel@tonic-gate } 7600Sstevel@tonic-gate 7610Sstevel@tonic-gate /* 7620Sstevel@tonic-gate * Get the address portion of the node name based on 7630Sstevel@tonic-gate * the function and device number. 7640Sstevel@tonic-gate */ 7650Sstevel@tonic-gate if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS, 7660Sstevel@tonic-gate "reg", (int **)&pci_rp, &n) != DDI_SUCCESS) { 7670Sstevel@tonic-gate return (DDI_FAILURE); 7680Sstevel@tonic-gate } 7690Sstevel@tonic-gate 7700Sstevel@tonic-gate slot = PCI_REG_DEV_G(pci_rp[0].pci_phys_hi); 7710Sstevel@tonic-gate func = PCI_REG_FUNC_G(pci_rp[0].pci_phys_hi); 7720Sstevel@tonic-gate 7730Sstevel@tonic-gate if (func != 0) 7740Sstevel@tonic-gate (void) snprintf(name, namelen, "%x,%x", slot, func); 7750Sstevel@tonic-gate else 7760Sstevel@tonic-gate (void) snprintf(name, namelen, "%x", slot); 7770Sstevel@tonic-gate 7780Sstevel@tonic-gate ddi_prop_free(pci_rp); 7790Sstevel@tonic-gate return (DDI_SUCCESS); 7800Sstevel@tonic-gate } 7810Sstevel@tonic-gate 7820Sstevel@tonic-gate static int 7830Sstevel@tonic-gate ppb_initchild(dev_info_t *child) 7840Sstevel@tonic-gate { 7850Sstevel@tonic-gate char name[MAXNAMELEN]; 7860Sstevel@tonic-gate ddi_acc_handle_t config_handle; 7870Sstevel@tonic-gate ushort_t command_preserve, command; 7880Sstevel@tonic-gate uint_t n; 7890Sstevel@tonic-gate ushort_t bcr; 7900Sstevel@tonic-gate uchar_t header_type; 7910Sstevel@tonic-gate uchar_t min_gnt, latency_timer; 7920Sstevel@tonic-gate ppb_devstate_t *ppb; 7930Sstevel@tonic-gate 7940Sstevel@tonic-gate /* 7950Sstevel@tonic-gate * Name the child 7960Sstevel@tonic-gate */ 7970Sstevel@tonic-gate if (ppb_name_child(child, name, MAXNAMELEN) != DDI_SUCCESS) 7980Sstevel@tonic-gate return (DDI_FAILURE); 7990Sstevel@tonic-gate 8000Sstevel@tonic-gate ddi_set_name_addr(child, name); 8010Sstevel@tonic-gate ddi_set_parent_data(child, NULL); 8020Sstevel@tonic-gate 8030Sstevel@tonic-gate /* 8040Sstevel@tonic-gate * Pseudo nodes indicate a prototype node with per-instance 8050Sstevel@tonic-gate * properties to be merged into the real h/w device node. 8060Sstevel@tonic-gate * The interpretation of the unit-address is DD[,F] 8070Sstevel@tonic-gate * where DD is the device id and F is the function. 8080Sstevel@tonic-gate */ 8090Sstevel@tonic-gate if (ndi_dev_is_persistent_node(child) == 0) { 8100Sstevel@tonic-gate extern int pci_allow_pseudo_children; 8110Sstevel@tonic-gate 8120Sstevel@tonic-gate /* 8130Sstevel@tonic-gate * Try to merge the properties from this prototype 8140Sstevel@tonic-gate * node into real h/w nodes. 8150Sstevel@tonic-gate */ 8160Sstevel@tonic-gate if (ndi_merge_node(child, ppb_name_child) == DDI_SUCCESS) { 8170Sstevel@tonic-gate /* 8180Sstevel@tonic-gate * Merged ok - return failure to remove the node. 8190Sstevel@tonic-gate */ 8200Sstevel@tonic-gate ppb_removechild(child); 8210Sstevel@tonic-gate return (DDI_FAILURE); 8220Sstevel@tonic-gate } 8230Sstevel@tonic-gate 8240Sstevel@tonic-gate /* workaround for ddivs to run under PCI */ 8250Sstevel@tonic-gate if (pci_allow_pseudo_children) 8260Sstevel@tonic-gate return (DDI_SUCCESS); 8270Sstevel@tonic-gate 8280Sstevel@tonic-gate /* 8290Sstevel@tonic-gate * The child was not merged into a h/w node, 8300Sstevel@tonic-gate * but there's not much we can do with it other 8310Sstevel@tonic-gate * than return failure to cause the node to be removed. 8320Sstevel@tonic-gate */ 8330Sstevel@tonic-gate cmn_err(CE_WARN, "!%s@%s: %s.conf properties not merged", 8340Sstevel@tonic-gate ddi_driver_name(child), ddi_get_name_addr(child), 8350Sstevel@tonic-gate ddi_driver_name(child)); 8360Sstevel@tonic-gate ppb_removechild(child); 8370Sstevel@tonic-gate return (DDI_NOT_WELL_FORMED); 8380Sstevel@tonic-gate } 8390Sstevel@tonic-gate 8400Sstevel@tonic-gate ppb = (ppb_devstate_t *)ddi_get_soft_state(ppb_state, 8410Sstevel@tonic-gate ddi_get_instance(ddi_get_parent(child))); 8420Sstevel@tonic-gate 8433274Set142600 ddi_set_parent_data(child, NULL); 8443274Set142600 8450Sstevel@tonic-gate /* 8460Sstevel@tonic-gate * If hardware is PM capable, set up the power info structure. 8470Sstevel@tonic-gate * This also ensures the the bus will not be off (0MHz) otherwise 8480Sstevel@tonic-gate * system panics during a bus access. 8490Sstevel@tonic-gate */ 8500Sstevel@tonic-gate if (PM_CAPABLE(ppb->ppb_pwr_p)) { 8510Sstevel@tonic-gate /* 8520Sstevel@tonic-gate * Create a pwr_info struct for child. Bus will be 8530Sstevel@tonic-gate * at full speed after creating info. 8540Sstevel@tonic-gate */ 8550Sstevel@tonic-gate pci_pwr_create_info(ppb->ppb_pwr_p, child); 8560Sstevel@tonic-gate #ifdef DEBUG 8570Sstevel@tonic-gate ASSERT(ppb->ppb_pwr_p->current_lvl == PM_LEVEL_B0); 8580Sstevel@tonic-gate #endif 8590Sstevel@tonic-gate } 8600Sstevel@tonic-gate 8610Sstevel@tonic-gate /* 8620Sstevel@tonic-gate * If configuration registers were previously saved by 8630Sstevel@tonic-gate * child (before it entered D3), then let the child do the 8640Sstevel@tonic-gate * restore to set up the config regs as it'll first need to 8650Sstevel@tonic-gate * power the device out of D3. 8660Sstevel@tonic-gate */ 8670Sstevel@tonic-gate if (ddi_prop_exists(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS, 8680Sstevel@tonic-gate "config-regs-saved-by-child") == 1) { 8690Sstevel@tonic-gate DEBUG2(DBG_PWR, ddi_get_parent(child), 8707656SSherry.Moore@Sun.COM "INITCHILD: config regs to be restored by child" 8717656SSherry.Moore@Sun.COM " for %s@%s\n", ddi_node_name(child), 8727656SSherry.Moore@Sun.COM ddi_get_name_addr(child)); 8730Sstevel@tonic-gate 8740Sstevel@tonic-gate return (DDI_SUCCESS); 8750Sstevel@tonic-gate } 8760Sstevel@tonic-gate 8770Sstevel@tonic-gate DEBUG2(DBG_PWR, ddi_get_parent(child), 8780Sstevel@tonic-gate "INITCHILD: config regs setup for %s@%s\n", 8790Sstevel@tonic-gate ddi_node_name(child), ddi_get_name_addr(child)); 8800Sstevel@tonic-gate 8810Sstevel@tonic-gate if (pci_config_setup(child, &config_handle) != DDI_SUCCESS) { 8820Sstevel@tonic-gate if (PM_CAPABLE(ppb->ppb_pwr_p)) { 8830Sstevel@tonic-gate pci_pwr_rm_info(ppb->ppb_pwr_p, child); 8840Sstevel@tonic-gate } 8850Sstevel@tonic-gate 8860Sstevel@tonic-gate return (DDI_FAILURE); 8870Sstevel@tonic-gate } 8880Sstevel@tonic-gate 8890Sstevel@tonic-gate /* 8900Sstevel@tonic-gate * Determine the configuration header type. 8910Sstevel@tonic-gate */ 8920Sstevel@tonic-gate header_type = pci_config_get8(config_handle, PCI_CONF_HEADER); 8930Sstevel@tonic-gate 8940Sstevel@tonic-gate /* 8950Sstevel@tonic-gate * Support for the "command-preserve" property. 8960Sstevel@tonic-gate */ 8970Sstevel@tonic-gate command_preserve = ddi_prop_get_int(DDI_DEV_T_ANY, child, 8987656SSherry.Moore@Sun.COM DDI_PROP_DONTPASS, "command-preserve", 0); 8990Sstevel@tonic-gate command = pci_config_get16(config_handle, PCI_CONF_COMM); 9000Sstevel@tonic-gate command &= (command_preserve | PCI_COMM_BACK2BACK_ENAB); 9010Sstevel@tonic-gate command |= (ppb_command_default & ~command_preserve); 9020Sstevel@tonic-gate pci_config_put16(config_handle, PCI_CONF_COMM, command); 9030Sstevel@tonic-gate 9040Sstevel@tonic-gate /* 9050Sstevel@tonic-gate * If the device has a bus control register then program it 9060Sstevel@tonic-gate * based on the settings in the command register. 9070Sstevel@tonic-gate */ 9083274Set142600 if ((header_type & PCI_HEADER_TYPE_M) == PCI_HEADER_ONE) { 9090Sstevel@tonic-gate bcr = pci_config_get8(config_handle, PCI_BCNF_BCNTRL); 9100Sstevel@tonic-gate if (ppb_command_default & PCI_COMM_PARITY_DETECT) 9110Sstevel@tonic-gate bcr |= PCI_BCNF_BCNTRL_PARITY_ENABLE; 9120Sstevel@tonic-gate if (ppb_command_default & PCI_COMM_SERR_ENABLE) 9130Sstevel@tonic-gate bcr |= PCI_BCNF_BCNTRL_SERR_ENABLE; 9140Sstevel@tonic-gate bcr |= PCI_BCNF_BCNTRL_MAST_AB_MODE; 9150Sstevel@tonic-gate pci_config_put8(config_handle, PCI_BCNF_BCNTRL, bcr); 9160Sstevel@tonic-gate } 9170Sstevel@tonic-gate 9180Sstevel@tonic-gate /* 9190Sstevel@tonic-gate * Initialize cache-line-size configuration register if needed. 9200Sstevel@tonic-gate */ 9210Sstevel@tonic-gate if (ppb_set_cache_line_size_register && 9220Sstevel@tonic-gate ddi_getprop(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS, 9237656SSherry.Moore@Sun.COM "cache-line-size", 0) == 0) { 9240Sstevel@tonic-gate pci_config_put8(config_handle, PCI_CONF_CACHE_LINESZ, 9257656SSherry.Moore@Sun.COM ppb->ppb_cache_line_size); 9260Sstevel@tonic-gate n = pci_config_get8(config_handle, PCI_CONF_CACHE_LINESZ); 9270Sstevel@tonic-gate if (n != 0) { 9280Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, child, 9297656SSherry.Moore@Sun.COM "cache-line-size", n); 9300Sstevel@tonic-gate } 9310Sstevel@tonic-gate } 9320Sstevel@tonic-gate 9330Sstevel@tonic-gate /* 9340Sstevel@tonic-gate * Initialize latency timer configuration registers if needed. 9350Sstevel@tonic-gate */ 9360Sstevel@tonic-gate if (ppb_set_latency_timer_register && 9370Sstevel@tonic-gate ddi_getprop(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS, 9387656SSherry.Moore@Sun.COM "latency-timer", 0) == 0) { 9390Sstevel@tonic-gate 9400Sstevel@tonic-gate if ((header_type & PCI_HEADER_TYPE_M) == PCI_HEADER_ONE) { 9410Sstevel@tonic-gate latency_timer = ppb->ppb_latency_timer; 9420Sstevel@tonic-gate pci_config_put8(config_handle, PCI_BCNF_LATENCY_TIMER, 9437656SSherry.Moore@Sun.COM ppb->ppb_latency_timer); 9440Sstevel@tonic-gate } else { 9450Sstevel@tonic-gate min_gnt = pci_config_get8(config_handle, 9467656SSherry.Moore@Sun.COM PCI_CONF_MIN_G); 9470Sstevel@tonic-gate latency_timer = min_gnt * 8; 9480Sstevel@tonic-gate } 9490Sstevel@tonic-gate pci_config_put8(config_handle, PCI_CONF_LATENCY_TIMER, 9507656SSherry.Moore@Sun.COM latency_timer); 9510Sstevel@tonic-gate n = pci_config_get8(config_handle, PCI_CONF_LATENCY_TIMER); 9520Sstevel@tonic-gate if (n != 0) { 9530Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, child, 9547656SSherry.Moore@Sun.COM "latency-timer", n); 9550Sstevel@tonic-gate } 9560Sstevel@tonic-gate } 9570Sstevel@tonic-gate 9580Sstevel@tonic-gate /* 9593274Set142600 * SPARC PCIe FMA specific 9603274Set142600 * 9613274Set142600 * Note: parent_data for parent is created only if this is sparc PCI-E 9623274Set142600 * platform, for which, SG take a different route to handle device 9633274Set142600 * errors. 9643274Set142600 */ 9653274Set142600 if (ppb->parent_bus == PCIE_PCIECAP_DEV_TYPE_PCIE_DEV) { 9666313Skrishnae if (pcie_init_bus(child) == NULL) { 9673724Srameshc pci_config_teardown(&config_handle); 9683274Set142600 return (DDI_FAILURE); 9693724Srameshc } 9703274Set142600 } 9713274Set142600 9723274Set142600 /* 9730Sstevel@tonic-gate * Check to see if the XMITS/PCI-X workaround applies. 9740Sstevel@tonic-gate */ 9750Sstevel@tonic-gate n = ddi_getprop(DDI_DEV_T_ANY, child, DDI_PROP_NOTPROM, 9760Sstevel@tonic-gate "pcix-update-cmd-reg", -1); 9770Sstevel@tonic-gate 9780Sstevel@tonic-gate if (n != -1) { 9790Sstevel@tonic-gate extern void pcix_set_cmd_reg(dev_info_t *child, uint16_t value); 9800Sstevel@tonic-gate DEBUG1(DBG_INIT_CLD, child, "Turning on XMITS NCPQ " 9810Sstevel@tonic-gate "Workaround: value = %x\n", n); 9820Sstevel@tonic-gate pcix_set_cmd_reg(child, n); 9830Sstevel@tonic-gate } 9843724Srameshc pci_config_teardown(&config_handle); 9853274Set142600 return (DDI_SUCCESS); 9863274Set142600 } 9873274Set142600 9883274Set142600 static void 9893274Set142600 ppb_uninitchild(dev_info_t *child) 9903274Set142600 { 9913274Set142600 ppb_devstate_t *ppb; 9923274Set142600 9933274Set142600 ppb = (ppb_devstate_t *)ddi_get_soft_state(ppb_state, 9943274Set142600 ddi_get_instance(ddi_get_parent(child))); 9953156Sgirish 9963156Sgirish /* 9973274Set142600 * SG OPL FMA specific 9983156Sgirish */ 9993274Set142600 if (ppb->parent_bus == PCIE_PCIECAP_DEV_TYPE_PCIE_DEV) 10006313Skrishnae pcie_fini_bus(child); 10013156Sgirish 10023274Set142600 ppb_removechild(child); 10030Sstevel@tonic-gate } 10040Sstevel@tonic-gate 10050Sstevel@tonic-gate static void 10060Sstevel@tonic-gate ppb_removechild(dev_info_t *dip) 10070Sstevel@tonic-gate { 10080Sstevel@tonic-gate ppb_devstate_t *ppb; 10090Sstevel@tonic-gate 10100Sstevel@tonic-gate ppb = (ppb_devstate_t *)ddi_get_soft_state(ppb_state, 10110Sstevel@tonic-gate ddi_get_instance(ddi_get_parent(dip))); 10120Sstevel@tonic-gate 10130Sstevel@tonic-gate if (PM_CAPABLE(ppb->ppb_pwr_p)) { 10140Sstevel@tonic-gate 10150Sstevel@tonic-gate DEBUG2(DBG_PWR, ddi_get_parent(dip), 10160Sstevel@tonic-gate "UNINITCHILD: removing pwr_info for %s@%s\n", 10170Sstevel@tonic-gate ddi_node_name(dip), ddi_get_name_addr(dip)); 10180Sstevel@tonic-gate pci_pwr_rm_info(ppb->ppb_pwr_p, dip); 10190Sstevel@tonic-gate } 10200Sstevel@tonic-gate 10210Sstevel@tonic-gate ddi_set_name_addr(dip, NULL); 10220Sstevel@tonic-gate 10230Sstevel@tonic-gate /* 10240Sstevel@tonic-gate * Strip the node to properly convert it back to prototype form 10250Sstevel@tonic-gate */ 10260Sstevel@tonic-gate ddi_remove_minor_node(dip, NULL); 10270Sstevel@tonic-gate 10280Sstevel@tonic-gate impl_rem_dev_props(dip); 10290Sstevel@tonic-gate } 10300Sstevel@tonic-gate 10310Sstevel@tonic-gate /* 10320Sstevel@tonic-gate * If bridge is PM capable, set up PM state for nexus. 10330Sstevel@tonic-gate */ 10340Sstevel@tonic-gate static void 10350Sstevel@tonic-gate ppb_pwr_setup(ppb_devstate_t *ppb, dev_info_t *pdip) 10360Sstevel@tonic-gate { 10370Sstevel@tonic-gate char *comp_array[5]; 10380Sstevel@tonic-gate int i; 10390Sstevel@tonic-gate ddi_acc_handle_t conf_hdl; 10400Sstevel@tonic-gate uint8_t pmcsr_bse; 10410Sstevel@tonic-gate uint16_t pmcap; 10420Sstevel@tonic-gate 10430Sstevel@tonic-gate /* 10440Sstevel@tonic-gate * Determine if bridge is PM capable. If not, leave ppb_pwr_p NULL 10450Sstevel@tonic-gate * and return. 10460Sstevel@tonic-gate */ 10470Sstevel@tonic-gate if (pci_config_setup(pdip, &ppb->ppb_conf_hdl) != DDI_SUCCESS) { 10480Sstevel@tonic-gate 10490Sstevel@tonic-gate return; 10500Sstevel@tonic-gate } 10510Sstevel@tonic-gate 10520Sstevel@tonic-gate conf_hdl = ppb->ppb_conf_hdl; 10530Sstevel@tonic-gate 10540Sstevel@tonic-gate /* 10551624Spjha * Locate and store the power management cap_ptr for future references. 10560Sstevel@tonic-gate */ 10571624Spjha if ((PCI_CAP_LOCATE(conf_hdl, PCI_CAP_ID_PM, &ppb->ppb_pm_cap_ptr)) 10587656SSherry.Moore@Sun.COM == DDI_FAILURE) { 10590Sstevel@tonic-gate DEBUG0(DBG_PWR, pdip, "bridge does not support PM. PCI" 10600Sstevel@tonic-gate " PM data structure not found in config header\n"); 10610Sstevel@tonic-gate pci_config_teardown(&conf_hdl); 10620Sstevel@tonic-gate 10630Sstevel@tonic-gate return; 10640Sstevel@tonic-gate } 10650Sstevel@tonic-gate 10660Sstevel@tonic-gate /* 10670Sstevel@tonic-gate * Allocate PM state structure for ppb. 10680Sstevel@tonic-gate */ 10690Sstevel@tonic-gate ppb->ppb_pwr_p = (pci_pwr_t *) 10700Sstevel@tonic-gate kmem_zalloc(sizeof (pci_pwr_t), KM_SLEEP); 10710Sstevel@tonic-gate ppb->ppb_pwr_p->pwr_fp = 0; 10720Sstevel@tonic-gate 10731624Spjha pmcsr_bse = PCI_CAP_GET8(conf_hdl, NULL, ppb->ppb_pm_cap_ptr, 10747656SSherry.Moore@Sun.COM PCI_PMCSR_BSE); 10750Sstevel@tonic-gate 10761624Spjha pmcap = PCI_CAP_GET16(conf_hdl, NULL, ppb->ppb_pm_cap_ptr, 10777656SSherry.Moore@Sun.COM PCI_PMCAP); 10780Sstevel@tonic-gate 10791774Spjha if (pmcap == PCI_CAP_EINVAL16 || pmcsr_bse == PCI_CAP_EINVAL8) { 10801624Spjha pci_config_teardown(&conf_hdl); 10811624Spjha return; 10821624Spjha } 10830Sstevel@tonic-gate 10840Sstevel@tonic-gate if (pmcap & PCI_PMCAP_D1) { 10850Sstevel@tonic-gate DEBUG0(DBG_PWR, pdip, "setup: B1 state supported\n"); 10860Sstevel@tonic-gate ppb->ppb_pwr_p->pwr_flags |= PCI_PWR_B1_CAPABLE; 10870Sstevel@tonic-gate } else { 10880Sstevel@tonic-gate DEBUG0(DBG_PWR, pdip, "setup: B1 state NOT supported\n"); 10890Sstevel@tonic-gate } 10900Sstevel@tonic-gate if (pmcap & PCI_PMCAP_D2) { 10910Sstevel@tonic-gate DEBUG0(DBG_PWR, pdip, "setup: B2 state supported\n"); 10920Sstevel@tonic-gate ppb->ppb_pwr_p->pwr_flags |= PCI_PWR_B2_CAPABLE; 10930Sstevel@tonic-gate } else { 10940Sstevel@tonic-gate DEBUG0(DBG_PWR, pdip, "setup: B2 via D2 NOT supported\n"); 10950Sstevel@tonic-gate } 10960Sstevel@tonic-gate 10970Sstevel@tonic-gate if (pmcsr_bse & PCI_PMCSR_BSE_BPCC_EN) { 10980Sstevel@tonic-gate DEBUG0(DBG_PWR, pdip, 10991624Spjha "setup: bridge power/clock control enable\n"); 11000Sstevel@tonic-gate } else { 11010Sstevel@tonic-gate DEBUG0(DBG_PWR, pdip, 11021624Spjha "setup: bridge power/clock control disabled\n"); 11030Sstevel@tonic-gate 11040Sstevel@tonic-gate kmem_free(ppb->ppb_pwr_p, sizeof (pci_pwr_t)); 11050Sstevel@tonic-gate ppb->ppb_pwr_p = NULL; 11060Sstevel@tonic-gate pci_config_teardown(&conf_hdl); 11070Sstevel@tonic-gate 11080Sstevel@tonic-gate return; 11090Sstevel@tonic-gate } 11100Sstevel@tonic-gate 11110Sstevel@tonic-gate /* 11120Sstevel@tonic-gate * PCI states D0 and D3 always are supported for normal PCI 11130Sstevel@tonic-gate * devices. D1 and D2 are optional which are checked for above. 11140Sstevel@tonic-gate * Bridge function states D0-D3 correspond to secondary bus states 11150Sstevel@tonic-gate * B0-B3, EXCEPT if PCI_PMCSR_BSE_B2_B3 is set. In this case, setting 11160Sstevel@tonic-gate * the bridge function to D3 will set the bridge bus to state B2 instead 11170Sstevel@tonic-gate * of B3. D2 will not correspond to B2 (and in fact, probably 11180Sstevel@tonic-gate * won't be D2 capable). Implicitly, this means that if 11190Sstevel@tonic-gate * PCI_PMCSR_BSE_B2_B3 is set, the bus will not be B3 capable. 11200Sstevel@tonic-gate */ 11210Sstevel@tonic-gate if (pmcsr_bse & PCI_PMCSR_BSE_B2_B3) { 11220Sstevel@tonic-gate ppb->ppb_pwr_p->pwr_flags |= PCI_PWR_B2_CAPABLE; 11230Sstevel@tonic-gate DEBUG0(DBG_PWR, pdip, "B2 supported via D3\n"); 11240Sstevel@tonic-gate } else { 11250Sstevel@tonic-gate ppb->ppb_pwr_p->pwr_flags |= PCI_PWR_B3_CAPABLE; 11260Sstevel@tonic-gate DEBUG0(DBG_PWR, pdip, "B3 supported via D3\n"); 11270Sstevel@tonic-gate } 11280Sstevel@tonic-gate 11290Sstevel@tonic-gate ppb->ppb_pwr_p->pwr_dip = pdip; 11300Sstevel@tonic-gate mutex_init(&ppb->ppb_pwr_p->pwr_mutex, NULL, MUTEX_DRIVER, NULL); 11310Sstevel@tonic-gate 11320Sstevel@tonic-gate i = 0; 11330Sstevel@tonic-gate comp_array[i++] = "NAME=PCI bridge PM"; 11340Sstevel@tonic-gate if (ppb->ppb_pwr_p->pwr_flags & PCI_PWR_B3_CAPABLE) { 11350Sstevel@tonic-gate comp_array[i++] = "0=Clock/Power Off (B3)"; 11360Sstevel@tonic-gate } 11370Sstevel@tonic-gate if (ppb->ppb_pwr_p->pwr_flags & PCI_PWR_B2_CAPABLE) { 11380Sstevel@tonic-gate comp_array[i++] = "1=Clock Off (B2)"; 11390Sstevel@tonic-gate } 11400Sstevel@tonic-gate if (ppb->ppb_pwr_p->pwr_flags & PCI_PWR_B1_CAPABLE) { 11410Sstevel@tonic-gate comp_array[i++] = "2=Bus Inactive (B1)"; 11420Sstevel@tonic-gate } 11430Sstevel@tonic-gate comp_array[i++] = "3=Full Power (B0)"; 11440Sstevel@tonic-gate 11450Sstevel@tonic-gate /* 11460Sstevel@tonic-gate * Create pm-components property. It does not already exist. 11470Sstevel@tonic-gate */ 11480Sstevel@tonic-gate if (ddi_prop_update_string_array(DDI_DEV_T_NONE, pdip, 11490Sstevel@tonic-gate "pm-components", comp_array, i) != DDI_PROP_SUCCESS) { 11500Sstevel@tonic-gate cmn_err(CE_WARN, 11510Sstevel@tonic-gate "%s%d pm-components prop update failed", 11520Sstevel@tonic-gate ddi_driver_name(pdip), ddi_get_instance(pdip)); 11530Sstevel@tonic-gate pci_config_teardown(&conf_hdl); 11540Sstevel@tonic-gate mutex_destroy(&ppb->ppb_pwr_p->pwr_mutex); 11550Sstevel@tonic-gate kmem_free(ppb->ppb_pwr_p, sizeof (pci_pwr_t)); 11560Sstevel@tonic-gate ppb->ppb_pwr_p = NULL; 11570Sstevel@tonic-gate 11580Sstevel@tonic-gate return; 11590Sstevel@tonic-gate } 11600Sstevel@tonic-gate 11610Sstevel@tonic-gate if (ddi_prop_create(DDI_DEV_T_NONE, pdip, DDI_PROP_CANSLEEP, 11620Sstevel@tonic-gate "pm-want-child-notification?", NULL, NULL) != DDI_PROP_SUCCESS) { 11630Sstevel@tonic-gate cmn_err(CE_WARN, 11647656SSherry.Moore@Sun.COM "%s%d fail to create pm-want-child-notification? prop", 11657656SSherry.Moore@Sun.COM ddi_driver_name(pdip), ddi_get_instance(pdip)); 11660Sstevel@tonic-gate 11670Sstevel@tonic-gate (void) ddi_prop_remove(DDI_DEV_T_NONE, pdip, "pm-components"); 11680Sstevel@tonic-gate pci_config_teardown(&conf_hdl); 11690Sstevel@tonic-gate mutex_destroy(&ppb->ppb_pwr_p->pwr_mutex); 11700Sstevel@tonic-gate kmem_free(ppb->ppb_pwr_p, sizeof (pci_pwr_t)); 11710Sstevel@tonic-gate ppb->ppb_pwr_p = NULL; 11720Sstevel@tonic-gate 11730Sstevel@tonic-gate return; 11740Sstevel@tonic-gate } 11750Sstevel@tonic-gate 11760Sstevel@tonic-gate ppb->ppb_pwr_p->current_lvl = 11777656SSherry.Moore@Sun.COM pci_pwr_current_lvl(ppb->ppb_pwr_p); 11780Sstevel@tonic-gate } 11790Sstevel@tonic-gate 11800Sstevel@tonic-gate /* 11810Sstevel@tonic-gate * Remove PM state for nexus. 11820Sstevel@tonic-gate */ 11830Sstevel@tonic-gate static void 11840Sstevel@tonic-gate ppb_pwr_teardown(ppb_devstate_t *ppb, dev_info_t *dip) 11850Sstevel@tonic-gate { 11860Sstevel@tonic-gate int low_lvl; 11870Sstevel@tonic-gate 11880Sstevel@tonic-gate /* 11890Sstevel@tonic-gate * Determine the lowest power level supported. 11900Sstevel@tonic-gate */ 11910Sstevel@tonic-gate if (ppb->ppb_pwr_p->pwr_flags & PCI_PWR_B3_CAPABLE) { 11920Sstevel@tonic-gate low_lvl = PM_LEVEL_B3; 11930Sstevel@tonic-gate } else { 11940Sstevel@tonic-gate low_lvl = PM_LEVEL_B2; 11950Sstevel@tonic-gate } 11960Sstevel@tonic-gate 11970Sstevel@tonic-gate if (pm_lower_power(dip, PCI_PM_COMP_0, low_lvl) != DDI_SUCCESS) { 11980Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d failed to lower power", 11990Sstevel@tonic-gate ddi_driver_name(dip), ddi_get_instance(dip)); 12000Sstevel@tonic-gate } 12010Sstevel@tonic-gate 12020Sstevel@tonic-gate pci_config_teardown(&ppb->ppb_conf_hdl); 12030Sstevel@tonic-gate mutex_destroy(&ppb->ppb_pwr_p->pwr_mutex); 12040Sstevel@tonic-gate kmem_free(ppb->ppb_pwr_p, sizeof (pci_pwr_t)); 12050Sstevel@tonic-gate 12060Sstevel@tonic-gate if (ddi_prop_remove(DDI_DEV_T_NONE, dip, "pm-components") != 12077656SSherry.Moore@Sun.COM DDI_PROP_SUCCESS) { 12080Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d unable to remove prop pm-components", 12090Sstevel@tonic-gate ddi_driver_name(dip), ddi_get_instance(dip)); 12100Sstevel@tonic-gate } 12110Sstevel@tonic-gate 12120Sstevel@tonic-gate if (ddi_prop_remove(DDI_DEV_T_NONE, dip, 12130Sstevel@tonic-gate "pm-want-child-notification?") != DDI_PROP_SUCCESS) { 12140Sstevel@tonic-gate cmn_err(CE_WARN, 12150Sstevel@tonic-gate "%s%d unable to remove prop pm-want_child_notification?", 12160Sstevel@tonic-gate ddi_driver_name(dip), ddi_get_instance(dip)); 12170Sstevel@tonic-gate } 12180Sstevel@tonic-gate } 12190Sstevel@tonic-gate 12200Sstevel@tonic-gate /* 12210Sstevel@tonic-gate * Examine the pmcsr register and return the software defined 12220Sstevel@tonic-gate * state (the difference being whether D3 means B2 or B3). 12230Sstevel@tonic-gate */ 12240Sstevel@tonic-gate int 12250Sstevel@tonic-gate pci_pwr_current_lvl(pci_pwr_t *pwr_p) 12260Sstevel@tonic-gate { 12270Sstevel@tonic-gate ppb_devstate_t *ppb; 12280Sstevel@tonic-gate uint16_t pmcsr; 12290Sstevel@tonic-gate 12300Sstevel@tonic-gate /* 12310Sstevel@tonic-gate * Find out current power level 12320Sstevel@tonic-gate */ 12330Sstevel@tonic-gate ppb = (ppb_devstate_t *)ddi_get_soft_state(ppb_state, 12340Sstevel@tonic-gate ddi_get_instance(pwr_p->pwr_dip)); 12350Sstevel@tonic-gate 12361624Spjha if ((pmcsr = PCI_CAP_GET16(ppb->ppb_conf_hdl, NULL, 12377656SSherry.Moore@Sun.COM ppb->ppb_pm_cap_ptr, PCI_PMCSR)) == PCI_CAP_EINVAL16) 12381624Spjha return (DDI_FAILURE); 12390Sstevel@tonic-gate 12400Sstevel@tonic-gate switch (pmcsr & PCI_PMCSR_STATE_MASK) { 12410Sstevel@tonic-gate case PCI_PMCSR_D0: 12420Sstevel@tonic-gate 12430Sstevel@tonic-gate return (PM_LEVEL_B0); 12440Sstevel@tonic-gate case PCI_PMCSR_D1: 12450Sstevel@tonic-gate 12460Sstevel@tonic-gate return (PM_LEVEL_B1); 12470Sstevel@tonic-gate case PCI_PMCSR_D2: 12480Sstevel@tonic-gate 12490Sstevel@tonic-gate return (PM_LEVEL_B2); 12500Sstevel@tonic-gate case PCI_PMCSR_D3HOT: 12510Sstevel@tonic-gate if ((ppb->ppb_pwr_p->pwr_flags & PCI_PWR_B3_CAPABLE) == 0) { 12520Sstevel@tonic-gate 12530Sstevel@tonic-gate return (PM_LEVEL_B2); 12540Sstevel@tonic-gate } else { 12550Sstevel@tonic-gate 12560Sstevel@tonic-gate return (PM_LEVEL_B3); 12570Sstevel@tonic-gate } 12580Sstevel@tonic-gate } 1259946Smathue /*NOTREACHED*/ 1260946Smathue return (PM_LEVEL_B3); 12610Sstevel@tonic-gate } 12620Sstevel@tonic-gate 12630Sstevel@tonic-gate /* 12640Sstevel@tonic-gate * Power entry point. Called by the PM framework to change the 12650Sstevel@tonic-gate * current power state of the bus. This function must first verify that 12660Sstevel@tonic-gate * the requested power change is still valid. 12670Sstevel@tonic-gate */ 12680Sstevel@tonic-gate /*ARGSUSED*/ 12690Sstevel@tonic-gate static int 12700Sstevel@tonic-gate ppb_pwr(dev_info_t *dip, int component, int lvl) 12710Sstevel@tonic-gate { 12720Sstevel@tonic-gate ppb_devstate_t *ppb; 12730Sstevel@tonic-gate uint16_t pmcsr; 12740Sstevel@tonic-gate char *str; 12750Sstevel@tonic-gate int lowest_lvl; 12760Sstevel@tonic-gate int old_lvl; 12770Sstevel@tonic-gate int new_lvl; 12780Sstevel@tonic-gate 12790Sstevel@tonic-gate ppb = (ppb_devstate_t *)ddi_get_soft_state(ppb_state, 12800Sstevel@tonic-gate ddi_get_instance(dip)); 12810Sstevel@tonic-gate if (ppb == NULL) { 12820Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d ppb_pwr: can't get soft state", 12830Sstevel@tonic-gate ddi_driver_name(dip), ddi_get_instance(dip)); 12840Sstevel@tonic-gate 12850Sstevel@tonic-gate return (DDI_FAILURE); 12860Sstevel@tonic-gate } 12870Sstevel@tonic-gate 12880Sstevel@tonic-gate DEBUG1(DBG_PWR, dip, "ppb_pwr(): ENTER level = %d\n", lvl); 12890Sstevel@tonic-gate 12900Sstevel@tonic-gate mutex_enter(&ppb->ppb_pwr_p->pwr_mutex); 12910Sstevel@tonic-gate 12920Sstevel@tonic-gate /* 12930Sstevel@tonic-gate * Find out if the power setting is possible. If it is not, 12940Sstevel@tonic-gate * set component busy and return failure. If it is possible, 12950Sstevel@tonic-gate * and it is the lowest pwr setting possible, set component 12960Sstevel@tonic-gate * busy so that the framework does not try to lower any further. 12970Sstevel@tonic-gate */ 12980Sstevel@tonic-gate lowest_lvl = pci_pwr_new_lvl(ppb->ppb_pwr_p); 12990Sstevel@tonic-gate if (lowest_lvl > lvl) { 13000Sstevel@tonic-gate pci_pwr_component_busy(ppb->ppb_pwr_p); 13010Sstevel@tonic-gate DEBUG2(DBG_PWR, dip, "ppb_pwr: failing power request " 13027656SSherry.Moore@Sun.COM "lowest allowed is %d requested is %d\n", 13037656SSherry.Moore@Sun.COM lowest_lvl, lvl); 13040Sstevel@tonic-gate mutex_exit(&ppb->ppb_pwr_p->pwr_mutex); 13050Sstevel@tonic-gate 13060Sstevel@tonic-gate return (DDI_FAILURE); 13070Sstevel@tonic-gate } else if (lowest_lvl == lvl) { 13080Sstevel@tonic-gate pci_pwr_component_busy(ppb->ppb_pwr_p); 13090Sstevel@tonic-gate } else { 13100Sstevel@tonic-gate pci_pwr_component_idle(ppb->ppb_pwr_p); 13110Sstevel@tonic-gate } 13120Sstevel@tonic-gate 13131624Spjha if ((pmcsr = PCI_CAP_GET16(ppb->ppb_conf_hdl, NULL, 13147656SSherry.Moore@Sun.COM ppb->ppb_pm_cap_ptr, PCI_PMCSR)) == PCI_CAP_EINVAL16) 13151624Spjha return (DDI_FAILURE); 13160Sstevel@tonic-gate 13170Sstevel@tonic-gate /* 13180Sstevel@tonic-gate * Save the current power level. This is the actual function level, 13190Sstevel@tonic-gate * not the translated bridge level stored in pwr_p->current_lvl 13200Sstevel@tonic-gate */ 13210Sstevel@tonic-gate old_lvl = pmcsr & PCI_PMCSR_STATE_MASK; 13220Sstevel@tonic-gate 13230Sstevel@tonic-gate pmcsr &= ~PCI_PMCSR_STATE_MASK; 13240Sstevel@tonic-gate switch (lvl) { 13250Sstevel@tonic-gate case PM_LEVEL_B0: 13260Sstevel@tonic-gate str = "PM_LEVEL_B0 (full speed)"; 13270Sstevel@tonic-gate pmcsr |= PCI_PMCSR_D0; 13280Sstevel@tonic-gate break; 13290Sstevel@tonic-gate case PM_LEVEL_B1: 13300Sstevel@tonic-gate str = "PM_LEVEL_B1 (light sleep. No bus traffic allowed)"; 13310Sstevel@tonic-gate if ((ppb->ppb_pwr_p->pwr_flags & PCI_PWR_B1_CAPABLE) == 0) { 13320Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d PCI PM state B1 not supported", 13330Sstevel@tonic-gate ddi_driver_name(dip), ddi_get_instance(dip)); 13340Sstevel@tonic-gate 13350Sstevel@tonic-gate mutex_exit(&ppb->ppb_pwr_p->pwr_mutex); 13360Sstevel@tonic-gate return (DDI_FAILURE); 13370Sstevel@tonic-gate } 13380Sstevel@tonic-gate pmcsr |= PCI_PMCSR_D1; 13390Sstevel@tonic-gate break; 13400Sstevel@tonic-gate case PM_LEVEL_B2: 13410Sstevel@tonic-gate str = "PM_LEVEL_B2 (clock off)"; 13420Sstevel@tonic-gate if ((ppb->ppb_pwr_p->pwr_flags & PCI_PWR_B2_CAPABLE) == 0) { 13430Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d PM state B2 not supported...", 13440Sstevel@tonic-gate ddi_driver_name(dip), 13450Sstevel@tonic-gate ddi_get_instance(dip)); 13460Sstevel@tonic-gate mutex_exit(&ppb->ppb_pwr_p->pwr_mutex); 13470Sstevel@tonic-gate 13480Sstevel@tonic-gate return (DDI_FAILURE); 13490Sstevel@tonic-gate } 13500Sstevel@tonic-gate 13510Sstevel@tonic-gate if ((ppb->ppb_pwr_p->pwr_flags & PCI_PWR_B3_CAPABLE) == 0) { 13520Sstevel@tonic-gate /* 13530Sstevel@tonic-gate * If B3 isn't supported, use D3 for B2 to avoid the 13540Sstevel@tonic-gate * possible case that D2 for B2 isn't supported. 13550Sstevel@tonic-gate * Saves and extra check and state flag.. 13560Sstevel@tonic-gate */ 13570Sstevel@tonic-gate pmcsr |= PCI_PMCSR_D3HOT; 13580Sstevel@tonic-gate } else { 13590Sstevel@tonic-gate pmcsr |= PCI_PMCSR_D2; 13600Sstevel@tonic-gate } 13610Sstevel@tonic-gate break; 13620Sstevel@tonic-gate case PM_LEVEL_B3: 13630Sstevel@tonic-gate str = "PM_LEVEL_B30 (clock and power off)"; 13640Sstevel@tonic-gate if ((ppb->ppb_pwr_p->pwr_flags & PCI_PWR_B3_CAPABLE) == 0) { 13650Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d PM state B3 not supported...", 13660Sstevel@tonic-gate ddi_driver_name(dip), 13670Sstevel@tonic-gate ddi_get_instance(dip)); 13680Sstevel@tonic-gate mutex_exit(&ppb->ppb_pwr_p->pwr_mutex); 13690Sstevel@tonic-gate 13700Sstevel@tonic-gate return (DDI_FAILURE); 13710Sstevel@tonic-gate } 13720Sstevel@tonic-gate pmcsr |= PCI_PMCSR_D3HOT; 13730Sstevel@tonic-gate 13740Sstevel@tonic-gate break; 13750Sstevel@tonic-gate 13760Sstevel@tonic-gate default: 13770Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d Unknown PM state %d", 13780Sstevel@tonic-gate ddi_driver_name(dip), ddi_get_instance(dip), lvl); 13790Sstevel@tonic-gate mutex_exit(&ppb->ppb_pwr_p->pwr_mutex); 13800Sstevel@tonic-gate 13810Sstevel@tonic-gate return (DDI_FAILURE); 13820Sstevel@tonic-gate } 13830Sstevel@tonic-gate 13840Sstevel@tonic-gate new_lvl = pmcsr & PCI_PMCSR_STATE_MASK; 13850Sstevel@tonic-gate 13860Sstevel@tonic-gate /* 13870Sstevel@tonic-gate * Save config regs if going into HW state D3 (B2 or B3) 13880Sstevel@tonic-gate */ 13890Sstevel@tonic-gate if ((old_lvl != PCI_PMCSR_D3HOT) && (new_lvl == PCI_PMCSR_D3HOT)) { 13900Sstevel@tonic-gate DEBUG0(DBG_PWR, dip, "ppb_pwr(): SAVING CONFIG REGS\n"); 13910Sstevel@tonic-gate if (pci_save_config_regs(dip) != DDI_SUCCESS) { 13920Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d Save config regs failed", 13937656SSherry.Moore@Sun.COM ddi_driver_name(dip), ddi_get_instance(dip)); 13940Sstevel@tonic-gate mutex_exit(&ppb->ppb_pwr_p->pwr_mutex); 13950Sstevel@tonic-gate 13960Sstevel@tonic-gate return (DDI_FAILURE); 13970Sstevel@tonic-gate } 13980Sstevel@tonic-gate } 13990Sstevel@tonic-gate 14001624Spjha PCI_CAP_PUT16(ppb->ppb_conf_hdl, NULL, ppb->ppb_pm_cap_ptr, PCI_PMCSR, 14017656SSherry.Moore@Sun.COM pmcsr); 14020Sstevel@tonic-gate 14030Sstevel@tonic-gate /* 14040Sstevel@tonic-gate * No bus transactions should occur without waiting for 14050Sstevel@tonic-gate * settle time specified in PCI PM spec rev 2.1 sec 5.6.1 14060Sstevel@tonic-gate * To make things simple, just use the max time specified for 14070Sstevel@tonic-gate * all state transitions. 14080Sstevel@tonic-gate */ 14090Sstevel@tonic-gate delay(drv_usectohz(PCI_CLK_SETTLE_TIME)); 14100Sstevel@tonic-gate 14110Sstevel@tonic-gate /* 14120Sstevel@tonic-gate * Restore configuration registers if coming out of HW state D3 14130Sstevel@tonic-gate */ 14140Sstevel@tonic-gate if ((old_lvl == PCI_PMCSR_D3HOT) && (new_lvl != PCI_PMCSR_D3HOT)) { 14150Sstevel@tonic-gate DEBUG0(DBG_PWR, dip, "ppb_pwr(): RESTORING CONFIG REGS\n"); 14160Sstevel@tonic-gate if (pci_restore_config_regs(dip) != DDI_SUCCESS) { 14170Sstevel@tonic-gate panic("%s%d restore config regs failed", 14180Sstevel@tonic-gate ddi_driver_name(dip), ddi_get_instance(dip)); 14190Sstevel@tonic-gate } 14200Sstevel@tonic-gate /*NOTREACHED*/ 14210Sstevel@tonic-gate } 14220Sstevel@tonic-gate 14230Sstevel@tonic-gate ppb->ppb_pwr_p->current_lvl = lvl; 14240Sstevel@tonic-gate 14250Sstevel@tonic-gate mutex_exit(&ppb->ppb_pwr_p->pwr_mutex); 14260Sstevel@tonic-gate 14270Sstevel@tonic-gate DEBUG1(DBG_PWR, dip, "ppb_set_pwr: set PM state to %s\n\n", str); 14280Sstevel@tonic-gate 14290Sstevel@tonic-gate return (DDI_SUCCESS); 14300Sstevel@tonic-gate } 14310Sstevel@tonic-gate 14320Sstevel@tonic-gate /* 14330Sstevel@tonic-gate * Initialize hotplug framework if we are hotpluggable. 14340Sstevel@tonic-gate * Sets flag in the soft state if Hot Plug is supported and initialized 14350Sstevel@tonic-gate * properly. 14360Sstevel@tonic-gate */ 14370Sstevel@tonic-gate /*ARGSUSED*/ 14380Sstevel@tonic-gate static void 14390Sstevel@tonic-gate ppb_init_hotplug(ppb_devstate_t *ppb) 14400Sstevel@tonic-gate { 1441*10923SEvan.Yan@Sun.COM ppb->hotplug_capable = B_FALSE; 1442*10923SEvan.Yan@Sun.COM 14430Sstevel@tonic-gate if (ddi_prop_exists(DDI_DEV_T_ANY, ppb->dip, DDI_PROP_DONTPASS, 14440Sstevel@tonic-gate "hotplug-capable")) { 14450Sstevel@tonic-gate (void) modload("misc", "pcihp"); 14460Sstevel@tonic-gate 14470Sstevel@tonic-gate if (pcihp_init(ppb->dip) != DDI_SUCCESS) { 14480Sstevel@tonic-gate cmn_err(CE_WARN, 14490Sstevel@tonic-gate "%s #%d: Failed setting hotplug framework", 14500Sstevel@tonic-gate ddi_driver_name(ppb->dip), 14510Sstevel@tonic-gate ddi_get_instance(ppb->dip)); 14520Sstevel@tonic-gate } else 14530Sstevel@tonic-gate ppb->hotplug_capable = B_TRUE; 14540Sstevel@tonic-gate } 14550Sstevel@tonic-gate 1456*10923SEvan.Yan@Sun.COM if (ppb->hotplug_capable == B_FALSE) { 1457*10923SEvan.Yan@Sun.COM /* 1458*10923SEvan.Yan@Sun.COM * create minor node for devctl interfaces 1459*10923SEvan.Yan@Sun.COM */ 1460*10923SEvan.Yan@Sun.COM if (ddi_create_minor_node(ppb->dip, "devctl", S_IFCHR, 1461*10923SEvan.Yan@Sun.COM PCI_MINOR_NUM(ddi_get_instance(ppb->dip), PCI_DEVCTL_MINOR), 1462*10923SEvan.Yan@Sun.COM DDI_NT_NEXUS, 0) != DDI_SUCCESS) 1463*10923SEvan.Yan@Sun.COM cmn_err(CE_WARN, 1464*10923SEvan.Yan@Sun.COM "%s #%d: Failed to create a minor node", 1465*10923SEvan.Yan@Sun.COM ddi_driver_name(ppb->dip), 1466*10923SEvan.Yan@Sun.COM ddi_get_instance(ppb->dip)); 1467*10923SEvan.Yan@Sun.COM } 14680Sstevel@tonic-gate } 14690Sstevel@tonic-gate 14700Sstevel@tonic-gate static void 14710Sstevel@tonic-gate ppb_create_ranges_prop(dev_info_t *dip, 14720Sstevel@tonic-gate ddi_acc_handle_t config_handle) 14730Sstevel@tonic-gate { 14740Sstevel@tonic-gate uint32_t base, limit; 14750Sstevel@tonic-gate ppb_ranges_t ranges[PPB_RANGE_LEN]; 14760Sstevel@tonic-gate uint8_t io_base_lo, io_limit_lo; 14770Sstevel@tonic-gate uint16_t io_base_hi, io_limit_hi, mem_base, mem_limit; 14780Sstevel@tonic-gate int i = 0, rangelen = sizeof (ppb_ranges_t)/sizeof (int); 14790Sstevel@tonic-gate 14800Sstevel@tonic-gate io_base_lo = pci_config_get8(config_handle, PCI_BCNF_IO_BASE_LOW); 14810Sstevel@tonic-gate io_limit_lo = pci_config_get8(config_handle, PCI_BCNF_IO_LIMIT_LOW); 14820Sstevel@tonic-gate io_base_hi = pci_config_get16(config_handle, PCI_BCNF_IO_BASE_HI); 14830Sstevel@tonic-gate io_limit_hi = pci_config_get16(config_handle, PCI_BCNF_IO_LIMIT_HI); 14840Sstevel@tonic-gate mem_base = pci_config_get16(config_handle, PCI_BCNF_MEM_BASE); 14850Sstevel@tonic-gate mem_limit = pci_config_get16(config_handle, PCI_BCNF_MEM_LIMIT); 14860Sstevel@tonic-gate 14870Sstevel@tonic-gate /* 14880Sstevel@tonic-gate * Create ranges for IO space 14890Sstevel@tonic-gate */ 14900Sstevel@tonic-gate ranges[i].size_low = ranges[i].size_high = 0; 14910Sstevel@tonic-gate ranges[i].parent_mid = ranges[i].child_mid = 14927656SSherry.Moore@Sun.COM ranges[i].parent_high = 0; 14930Sstevel@tonic-gate ranges[i].child_high = ranges[i].parent_high |= 14947656SSherry.Moore@Sun.COM (PCI_REG_REL_M | PCI_ADDR_IO); 14950Sstevel@tonic-gate base = PPB_16bit_IOADDR(io_base_lo); 14960Sstevel@tonic-gate limit = PPB_16bit_IOADDR(io_limit_lo); 14970Sstevel@tonic-gate 149810548SPavel.Potoplyak@Sun.COM /* 149910548SPavel.Potoplyak@Sun.COM * Check for 32-bit I/O support as per PCI-to-PCI Bridge Arch Spec 150010548SPavel.Potoplyak@Sun.COM */ 15010Sstevel@tonic-gate if ((io_base_lo & 0xf) == PPB_32BIT_IO) { 15020Sstevel@tonic-gate base = PPB_LADDR(base, io_base_hi); 15030Sstevel@tonic-gate limit = PPB_LADDR(limit, io_limit_hi); 15040Sstevel@tonic-gate } 15050Sstevel@tonic-gate 150610548SPavel.Potoplyak@Sun.COM /* 150710548SPavel.Potoplyak@Sun.COM * Check if the bridge implements an I/O address range as per 150810548SPavel.Potoplyak@Sun.COM * PCI-to-PCI Bridge Arch Spec 150910548SPavel.Potoplyak@Sun.COM */ 151010548SPavel.Potoplyak@Sun.COM if ((io_base_lo != 0 || io_limit_lo != 0) && limit >= base) { 151110548SPavel.Potoplyak@Sun.COM ranges[i].parent_low = ranges[i].child_low = 151210548SPavel.Potoplyak@Sun.COM base; 151310548SPavel.Potoplyak@Sun.COM ranges[i].size_low = limit - base + PPB_IOGRAIN; 151410548SPavel.Potoplyak@Sun.COM i++; 15150Sstevel@tonic-gate } 15160Sstevel@tonic-gate 15170Sstevel@tonic-gate /* 15180Sstevel@tonic-gate * Create ranges for 32bit memory space 15190Sstevel@tonic-gate */ 15200Sstevel@tonic-gate base = PPB_32bit_MEMADDR(mem_base); 15210Sstevel@tonic-gate limit = PPB_32bit_MEMADDR(mem_limit); 15220Sstevel@tonic-gate ranges[i].size_low = ranges[i].size_high = 0; 15230Sstevel@tonic-gate ranges[i].parent_mid = ranges[i].child_mid = 15247656SSherry.Moore@Sun.COM ranges[i].parent_high = 0; 15250Sstevel@tonic-gate ranges[i].child_high = ranges[i].parent_high |= 15267656SSherry.Moore@Sun.COM (PCI_REG_REL_M | PCI_ADDR_MEM32); 15270Sstevel@tonic-gate ranges[i].child_low = ranges[i].parent_low = base; 15280Sstevel@tonic-gate if (limit >= base) { 15290Sstevel@tonic-gate ranges[i].size_low = limit - base + PPB_MEMGRAIN; 15300Sstevel@tonic-gate i++; 15310Sstevel@tonic-gate } 15320Sstevel@tonic-gate 15330Sstevel@tonic-gate if (i) { 15340Sstevel@tonic-gate (void) ndi_prop_update_int_array(DDI_DEV_T_NONE, dip, "ranges", 15350Sstevel@tonic-gate (int *)ranges, i * rangelen); 15360Sstevel@tonic-gate } 15370Sstevel@tonic-gate } 15380Sstevel@tonic-gate 15390Sstevel@tonic-gate /* ARGSUSED */ 15400Sstevel@tonic-gate static int 15410Sstevel@tonic-gate ppb_open(dev_t *devp, int flags, int otyp, cred_t *credp) 15420Sstevel@tonic-gate { 1543*10923SEvan.Yan@Sun.COM int instance = PCI_MINOR_NUM_TO_INSTANCE(getminor(*devp)); 1544*10923SEvan.Yan@Sun.COM ppb_devstate_t *ppb_p = ddi_get_soft_state(ppb_state, instance); 15450Sstevel@tonic-gate 15460Sstevel@tonic-gate /* 15470Sstevel@tonic-gate * Make sure the open is for the right file type. 15480Sstevel@tonic-gate */ 15490Sstevel@tonic-gate if (otyp != OTYP_CHR) 15500Sstevel@tonic-gate return (EINVAL); 15510Sstevel@tonic-gate 15520Sstevel@tonic-gate if (ppb_p == NULL) 15530Sstevel@tonic-gate return (ENXIO); 15540Sstevel@tonic-gate 1555*10923SEvan.Yan@Sun.COM mutex_enter(&ppb_p->ppb_mutex); 1556*10923SEvan.Yan@Sun.COM 1557*10923SEvan.Yan@Sun.COM /* 1558*10923SEvan.Yan@Sun.COM * Ioctls will be handled by SPARC PCI Express framework for all 1559*10923SEvan.Yan@Sun.COM * PCIe platforms 1560*10923SEvan.Yan@Sun.COM */ 1561*10923SEvan.Yan@Sun.COM if (ppb_p->parent_bus == PCIE_PCIECAP_DEV_TYPE_PCIE_DEV) { 1562*10923SEvan.Yan@Sun.COM int rv; 1563*10923SEvan.Yan@Sun.COM 1564*10923SEvan.Yan@Sun.COM rv = pcie_open(ppb_p->dip, devp, flags, otyp, credp); 1565*10923SEvan.Yan@Sun.COM mutex_exit(&ppb_p->ppb_mutex); 1566*10923SEvan.Yan@Sun.COM 1567*10923SEvan.Yan@Sun.COM return (rv); 1568*10923SEvan.Yan@Sun.COM } else if (ppb_p->hotplug_capable == B_TRUE) { 1569*10923SEvan.Yan@Sun.COM mutex_exit(&ppb_p->ppb_mutex); 1570*10923SEvan.Yan@Sun.COM 1571*10923SEvan.Yan@Sun.COM return ((pcihp_get_cb_ops())->cb_open(devp, flags, otyp, 1572*10923SEvan.Yan@Sun.COM credp)); 1573*10923SEvan.Yan@Sun.COM } 15740Sstevel@tonic-gate 15750Sstevel@tonic-gate /* 15760Sstevel@tonic-gate * Handle the open by tracking the device state. 15770Sstevel@tonic-gate */ 15780Sstevel@tonic-gate if (flags & FEXCL) { 1579*10923SEvan.Yan@Sun.COM if (ppb_p->ppb_soft_state != PCI_SOFT_STATE_CLOSED) { 15800Sstevel@tonic-gate mutex_exit(&ppb_p->ppb_mutex); 15810Sstevel@tonic-gate return (EBUSY); 15820Sstevel@tonic-gate } 1583*10923SEvan.Yan@Sun.COM ppb_p->ppb_soft_state = PCI_SOFT_STATE_OPEN_EXCL; 15840Sstevel@tonic-gate } else { 1585*10923SEvan.Yan@Sun.COM if (ppb_p->ppb_soft_state == PCI_SOFT_STATE_OPEN_EXCL) { 15860Sstevel@tonic-gate mutex_exit(&ppb_p->ppb_mutex); 15870Sstevel@tonic-gate return (EBUSY); 15880Sstevel@tonic-gate } 1589*10923SEvan.Yan@Sun.COM ppb_p->ppb_soft_state = PCI_SOFT_STATE_OPEN; 15900Sstevel@tonic-gate } 15910Sstevel@tonic-gate mutex_exit(&ppb_p->ppb_mutex); 15920Sstevel@tonic-gate return (0); 15930Sstevel@tonic-gate } 15940Sstevel@tonic-gate 15950Sstevel@tonic-gate 15960Sstevel@tonic-gate /* ARGSUSED */ 15970Sstevel@tonic-gate static int 15980Sstevel@tonic-gate ppb_close(dev_t dev, int flags, int otyp, cred_t *credp) 15990Sstevel@tonic-gate { 1600*10923SEvan.Yan@Sun.COM int instance = PCI_MINOR_NUM_TO_INSTANCE(getminor(dev)); 1601*10923SEvan.Yan@Sun.COM ppb_devstate_t *ppb_p = ddi_get_soft_state(ppb_state, instance); 16020Sstevel@tonic-gate 16030Sstevel@tonic-gate if (otyp != OTYP_CHR) 16040Sstevel@tonic-gate return (EINVAL); 16050Sstevel@tonic-gate 16060Sstevel@tonic-gate if (ppb_p == NULL) 16070Sstevel@tonic-gate return (ENXIO); 16080Sstevel@tonic-gate 1609*10923SEvan.Yan@Sun.COM mutex_enter(&ppb_p->ppb_mutex); 1610*10923SEvan.Yan@Sun.COM /* 1611*10923SEvan.Yan@Sun.COM * Ioctls will be handled by SPARC PCI Express framework for all 1612*10923SEvan.Yan@Sun.COM * PCIe platforms 1613*10923SEvan.Yan@Sun.COM */ 1614*10923SEvan.Yan@Sun.COM if (ppb_p->parent_bus == PCIE_PCIECAP_DEV_TYPE_PCIE_DEV) { 1615*10923SEvan.Yan@Sun.COM int rv; 16160Sstevel@tonic-gate 1617*10923SEvan.Yan@Sun.COM rv = pcie_close(ppb_p->dip, dev, flags, otyp, credp); 1618*10923SEvan.Yan@Sun.COM mutex_exit(&ppb_p->ppb_mutex); 1619*10923SEvan.Yan@Sun.COM 1620*10923SEvan.Yan@Sun.COM return (rv); 1621*10923SEvan.Yan@Sun.COM } else if (ppb_p->hotplug_capable == B_TRUE) { 1622*10923SEvan.Yan@Sun.COM mutex_exit(&ppb_p->ppb_mutex); 1623*10923SEvan.Yan@Sun.COM return ((pcihp_get_cb_ops())->cb_close(dev, flags, otyp, 1624*10923SEvan.Yan@Sun.COM credp)); 1625*10923SEvan.Yan@Sun.COM } 1626*10923SEvan.Yan@Sun.COM 1627*10923SEvan.Yan@Sun.COM ppb_p->ppb_soft_state = PCI_SOFT_STATE_CLOSED; 16280Sstevel@tonic-gate mutex_exit(&ppb_p->ppb_mutex); 16290Sstevel@tonic-gate return (0); 16300Sstevel@tonic-gate } 16310Sstevel@tonic-gate 16320Sstevel@tonic-gate 16330Sstevel@tonic-gate /* 16340Sstevel@tonic-gate * ppb_ioctl: devctl hotplug controls 16350Sstevel@tonic-gate */ 16360Sstevel@tonic-gate /* ARGSUSED */ 16370Sstevel@tonic-gate static int 16380Sstevel@tonic-gate ppb_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, cred_t *credp, 16390Sstevel@tonic-gate int *rvalp) 16400Sstevel@tonic-gate { 1641*10923SEvan.Yan@Sun.COM int instance = PCI_MINOR_NUM_TO_INSTANCE(getminor(dev)); 1642*10923SEvan.Yan@Sun.COM ppb_devstate_t *ppb_p = ddi_get_soft_state(ppb_state, instance); 16430Sstevel@tonic-gate struct devctl_iocdata *dcp; 1644*10923SEvan.Yan@Sun.COM uint_t bus_state; 1645*10923SEvan.Yan@Sun.COM dev_info_t *self; 1646*10923SEvan.Yan@Sun.COM int rv = 0; 16470Sstevel@tonic-gate 16480Sstevel@tonic-gate if (ppb_p == NULL) 16490Sstevel@tonic-gate return (ENXIO); 16500Sstevel@tonic-gate 1651*10923SEvan.Yan@Sun.COM /* 1652*10923SEvan.Yan@Sun.COM * Ioctls will be handled by SPARC PCI Express framework for all 1653*10923SEvan.Yan@Sun.COM * PCIe platforms 1654*10923SEvan.Yan@Sun.COM */ 1655*10923SEvan.Yan@Sun.COM if (ppb_p->parent_bus == PCIE_PCIECAP_DEV_TYPE_PCIE_DEV) 1656*10923SEvan.Yan@Sun.COM return (pcie_ioctl(ppb_p->dip, dev, cmd, arg, mode, credp, 1657*10923SEvan.Yan@Sun.COM rvalp)); 1658*10923SEvan.Yan@Sun.COM else if (ppb_p->hotplug_capable == B_TRUE) 1659*10923SEvan.Yan@Sun.COM return ((pcihp_get_cb_ops())->cb_ioctl(dev, cmd, arg, mode, 1660*10923SEvan.Yan@Sun.COM credp, rvalp)); 16610Sstevel@tonic-gate 16620Sstevel@tonic-gate self = ppb_p->dip; 16630Sstevel@tonic-gate 16640Sstevel@tonic-gate /* 16650Sstevel@tonic-gate * We can use the generic implementation for these ioctls 16660Sstevel@tonic-gate */ 16670Sstevel@tonic-gate switch (cmd) { 16680Sstevel@tonic-gate case DEVCTL_DEVICE_GETSTATE: 16690Sstevel@tonic-gate case DEVCTL_DEVICE_ONLINE: 16700Sstevel@tonic-gate case DEVCTL_DEVICE_OFFLINE: 16710Sstevel@tonic-gate case DEVCTL_BUS_GETSTATE: 16720Sstevel@tonic-gate return (ndi_devctl_ioctl(self, cmd, arg, mode, 0)); 16730Sstevel@tonic-gate } 16740Sstevel@tonic-gate 16750Sstevel@tonic-gate /* 16760Sstevel@tonic-gate * read devctl ioctl data 16770Sstevel@tonic-gate */ 16780Sstevel@tonic-gate if (ndi_dc_allochdl((void *)arg, &dcp) != NDI_SUCCESS) 16790Sstevel@tonic-gate return (EFAULT); 16800Sstevel@tonic-gate 16810Sstevel@tonic-gate switch (cmd) { 16820Sstevel@tonic-gate 16830Sstevel@tonic-gate case DEVCTL_DEVICE_RESET: 16840Sstevel@tonic-gate rv = ENOTSUP; 16850Sstevel@tonic-gate break; 16860Sstevel@tonic-gate 16870Sstevel@tonic-gate case DEVCTL_BUS_QUIESCE: 16880Sstevel@tonic-gate if (ndi_get_bus_state(self, &bus_state) == NDI_SUCCESS) 16890Sstevel@tonic-gate if (bus_state == BUS_QUIESCED) 16900Sstevel@tonic-gate break; 16910Sstevel@tonic-gate (void) ndi_set_bus_state(self, BUS_QUIESCED); 16920Sstevel@tonic-gate break; 16930Sstevel@tonic-gate 16940Sstevel@tonic-gate case DEVCTL_BUS_UNQUIESCE: 16950Sstevel@tonic-gate if (ndi_get_bus_state(self, &bus_state) == NDI_SUCCESS) 16960Sstevel@tonic-gate if (bus_state == BUS_ACTIVE) 16970Sstevel@tonic-gate break; 16980Sstevel@tonic-gate (void) ndi_set_bus_state(self, BUS_ACTIVE); 16990Sstevel@tonic-gate break; 17000Sstevel@tonic-gate 17010Sstevel@tonic-gate case DEVCTL_BUS_RESET: 17020Sstevel@tonic-gate rv = ENOTSUP; 17030Sstevel@tonic-gate break; 17040Sstevel@tonic-gate 17050Sstevel@tonic-gate case DEVCTL_BUS_RESETALL: 17060Sstevel@tonic-gate rv = ENOTSUP; 17070Sstevel@tonic-gate break; 17080Sstevel@tonic-gate 17090Sstevel@tonic-gate default: 17100Sstevel@tonic-gate rv = ENOTTY; 17110Sstevel@tonic-gate } 17120Sstevel@tonic-gate 17130Sstevel@tonic-gate ndi_dc_freehdl(dcp); 17140Sstevel@tonic-gate return (rv); 17150Sstevel@tonic-gate } 17160Sstevel@tonic-gate 1717*10923SEvan.Yan@Sun.COM static int 1718*10923SEvan.Yan@Sun.COM ppb_prop_op(dev_t dev, dev_info_t *dip, ddi_prop_op_t prop_op, int flags, 1719*10923SEvan.Yan@Sun.COM char *name, caddr_t valuep, int *lengthp) 17200Sstevel@tonic-gate { 1721*10923SEvan.Yan@Sun.COM int instance = PCI_MINOR_NUM_TO_INSTANCE(getminor(dev)); 1722*10923SEvan.Yan@Sun.COM ppb_devstate_t *ppb_p = (ppb_devstate_t *) 1723*10923SEvan.Yan@Sun.COM ddi_get_soft_state(ppb_state, instance); 17240Sstevel@tonic-gate 17250Sstevel@tonic-gate if (ppb_p == NULL) 17260Sstevel@tonic-gate return (ENXIO); 17270Sstevel@tonic-gate 1728*10923SEvan.Yan@Sun.COM if (ppb_p->parent_bus == PCIE_PCIECAP_DEV_TYPE_PCIE_DEV) 1729*10923SEvan.Yan@Sun.COM return (pcie_prop_op(dev, dip, prop_op, flags, name, 1730*10923SEvan.Yan@Sun.COM valuep, lengthp)); 17310Sstevel@tonic-gate 1732*10923SEvan.Yan@Sun.COM return ((pcihp_get_cb_ops())->cb_prop_op(dev, dip, prop_op, flags, 1733*10923SEvan.Yan@Sun.COM name, valuep, lengthp)); 17340Sstevel@tonic-gate } 17350Sstevel@tonic-gate 17360Sstevel@tonic-gate /* 17370Sstevel@tonic-gate * Initialize our FMA resources 17380Sstevel@tonic-gate */ 17390Sstevel@tonic-gate static void 17400Sstevel@tonic-gate ppb_fm_init(ppb_devstate_t *ppb_p) 17410Sstevel@tonic-gate { 17420Sstevel@tonic-gate ppb_p->fm_cap = DDI_FM_EREPORT_CAPABLE | DDI_FM_ERRCB_CAPABLE | 17437656SSherry.Moore@Sun.COM DDI_FM_ACCCHK_CAPABLE | DDI_FM_DMACHK_CAPABLE; 17440Sstevel@tonic-gate 17450Sstevel@tonic-gate /* 17460Sstevel@tonic-gate * Request our capability level and get our parents capability 17470Sstevel@tonic-gate * and ibc. 17480Sstevel@tonic-gate */ 17490Sstevel@tonic-gate ddi_fm_init(ppb_p->dip, &ppb_p->fm_cap, &ppb_p->fm_ibc); 17500Sstevel@tonic-gate ASSERT((ppb_p->fm_cap & DDI_FM_EREPORT_CAPABLE) && 17510Sstevel@tonic-gate (ppb_p->fm_cap & DDI_FM_ERRCB_CAPABLE)); 17520Sstevel@tonic-gate 17530Sstevel@tonic-gate pci_ereport_setup(ppb_p->dip); 17540Sstevel@tonic-gate 17550Sstevel@tonic-gate /* 17560Sstevel@tonic-gate * Register error callback with our parent. 17570Sstevel@tonic-gate */ 17580Sstevel@tonic-gate ddi_fm_handler_register(ppb_p->dip, ppb_err_callback, NULL); 17590Sstevel@tonic-gate } 17600Sstevel@tonic-gate 17610Sstevel@tonic-gate /* 17620Sstevel@tonic-gate * Breakdown our FMA resources 17630Sstevel@tonic-gate */ 17640Sstevel@tonic-gate static void 17650Sstevel@tonic-gate ppb_fm_fini(ppb_devstate_t *ppb_p) 17660Sstevel@tonic-gate { 17670Sstevel@tonic-gate /* 17680Sstevel@tonic-gate * Clean up allocated fm structures 17690Sstevel@tonic-gate */ 17700Sstevel@tonic-gate ddi_fm_handler_unregister(ppb_p->dip); 17710Sstevel@tonic-gate pci_ereport_teardown(ppb_p->dip); 17720Sstevel@tonic-gate ddi_fm_fini(ppb_p->dip); 17730Sstevel@tonic-gate } 17740Sstevel@tonic-gate 17750Sstevel@tonic-gate /* 17760Sstevel@tonic-gate * Initialize FMA resources for children devices. Called when 17770Sstevel@tonic-gate * child calls ddi_fm_init(). 17780Sstevel@tonic-gate */ 17790Sstevel@tonic-gate /*ARGSUSED*/ 17800Sstevel@tonic-gate static int 17810Sstevel@tonic-gate ppb_fm_init_child(dev_info_t *dip, dev_info_t *tdip, int cap, 17820Sstevel@tonic-gate ddi_iblock_cookie_t *ibc) 17830Sstevel@tonic-gate { 17840Sstevel@tonic-gate ppb_devstate_t *ppb_p = (ppb_devstate_t *)ddi_get_soft_state(ppb_state, 17857656SSherry.Moore@Sun.COM ddi_get_instance(dip)); 17860Sstevel@tonic-gate *ibc = ppb_p->fm_ibc; 17870Sstevel@tonic-gate return (ppb_p->fm_cap); 17880Sstevel@tonic-gate } 17890Sstevel@tonic-gate 17900Sstevel@tonic-gate /* 17910Sstevel@tonic-gate * FMA registered error callback 17920Sstevel@tonic-gate */ 17930Sstevel@tonic-gate static int 17940Sstevel@tonic-gate ppb_err_callback(dev_info_t *dip, ddi_fm_error_t *derr, const void *impl_data) 17950Sstevel@tonic-gate { 17963274Set142600 ppb_devstate_t *ppb_p = (ppb_devstate_t *)ddi_get_soft_state(ppb_state, 17977656SSherry.Moore@Sun.COM ddi_get_instance(dip)); 17983274Set142600 17993274Set142600 /* 18003274Set142600 * errors handled by SPARC PCI-E framework for PCIe platforms 18013274Set142600 */ 18023274Set142600 if (ppb_p->parent_bus == PCIE_PCIECAP_DEV_TYPE_PCIE_DEV) 18033274Set142600 return (DDI_FM_OK); 18043274Set142600 18053274Set142600 /* 18063274Set142600 * do the following for SPARC PCI platforms 18073274Set142600 */ 18080Sstevel@tonic-gate ASSERT(impl_data == NULL); 18091865Sdilpreet pci_ereport_post(dip, derr, NULL); 18101865Sdilpreet return (derr->fme_status); 18110Sstevel@tonic-gate } 18120Sstevel@tonic-gate 18130Sstevel@tonic-gate static void 18140Sstevel@tonic-gate ppb_bus_enter(dev_info_t *dip, ddi_acc_handle_t handle) 18150Sstevel@tonic-gate { 18160Sstevel@tonic-gate i_ndi_busop_access_enter(dip, handle); 18170Sstevel@tonic-gate } 18180Sstevel@tonic-gate 18190Sstevel@tonic-gate /* ARGSUSED */ 18200Sstevel@tonic-gate static void 18210Sstevel@tonic-gate ppb_bus_exit(dev_info_t *dip, ddi_acc_handle_t handle) 18220Sstevel@tonic-gate { 18230Sstevel@tonic-gate i_ndi_busop_access_exit(dip, handle); 18240Sstevel@tonic-gate } 1825