17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 527255037Spjha * Common Development and Distribution License (the "License"). 627255037Spjha * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22fc256490SJason Beloro * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 25*cd21e7c5SGarrett D'Amore /* 26*cd21e7c5SGarrett D'Amore * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. 27*cd21e7c5SGarrett D'Amore */ 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate /* 307c478bd9Sstevel@tonic-gate * Sun4u PCI to PCI bus bridge nexus driver 317c478bd9Sstevel@tonic-gate */ 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate #include <sys/conf.h> 347c478bd9Sstevel@tonic-gate #include <sys/kmem.h> 357c478bd9Sstevel@tonic-gate #include <sys/debug.h> 367c478bd9Sstevel@tonic-gate #include <sys/modctl.h> 377c478bd9Sstevel@tonic-gate #include <sys/autoconf.h> 387c478bd9Sstevel@tonic-gate #include <sys/ddi_impldefs.h> 397c478bd9Sstevel@tonic-gate #include <sys/ddi_subrdefs.h> 4026947304SEvan Yan #include <sys/pci_impl.h> 41bf8fc234Set142600 #include <sys/pcie_impl.h> 4227255037Spjha #include <sys/pci_cap.h> 437c478bd9Sstevel@tonic-gate #include <sys/pci/pci_nexus.h> 447c478bd9Sstevel@tonic-gate #include <sys/pci/pci_regs.h> 457c478bd9Sstevel@tonic-gate #include <sys/ddi.h> 467c478bd9Sstevel@tonic-gate #include <sys/sunndi.h> 477c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 487c478bd9Sstevel@tonic-gate #include <sys/fm/protocol.h> 497c478bd9Sstevel@tonic-gate #include <sys/ddifm.h> 507c478bd9Sstevel@tonic-gate #include <sys/pci/pci_pwr.h> 517c478bd9Sstevel@tonic-gate #include <sys/pci/pci_debug.h> 5226947304SEvan Yan #include <sys/hotplug/pci/pcie_hp.h> 537c478bd9Sstevel@tonic-gate #include <sys/hotplug/pci/pcihp.h> 547c478bd9Sstevel@tonic-gate #include <sys/open.h> 557c478bd9Sstevel@tonic-gate #include <sys/stat.h> 567c478bd9Sstevel@tonic-gate #include <sys/file.h> 577c478bd9Sstevel@tonic-gate 587c478bd9Sstevel@tonic-gate #define NUM_LOGICAL_SLOTS 32 597c478bd9Sstevel@tonic-gate 607c478bd9Sstevel@tonic-gate #define PPB_RANGE_LEN 2 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate #define PPB_32BIT_IO 1 637c478bd9Sstevel@tonic-gate #define PPB_32bit_MEM 1 647c478bd9Sstevel@tonic-gate 657c478bd9Sstevel@tonic-gate #define PPB_MEMGRAIN 0x100000 667c478bd9Sstevel@tonic-gate #define PPB_IOGRAIN 0x1000 677c478bd9Sstevel@tonic-gate 687c478bd9Sstevel@tonic-gate #define PPB_16bit_IOADDR(addr) ((uint16_t)(((uint8_t)(addr) & 0xF0) << 8)) 697c478bd9Sstevel@tonic-gate #define PPB_LADDR(lo, hi) (((uint16_t)(hi) << 16) | (uint16_t)(lo)) 707c478bd9Sstevel@tonic-gate #define PPB_32bit_MEMADDR(addr) (PPB_LADDR(0, ((uint16_t)(addr) & 0xFFF0))) 717c478bd9Sstevel@tonic-gate 727c478bd9Sstevel@tonic-gate typedef struct slot_table { 737c478bd9Sstevel@tonic-gate uchar_t bus_id[128]; 747c478bd9Sstevel@tonic-gate uchar_t slot_name[32]; 757c478bd9Sstevel@tonic-gate uint8_t device_no; 767c478bd9Sstevel@tonic-gate uint8_t phys_slot_num; 777c478bd9Sstevel@tonic-gate } slot_table_t; 787c478bd9Sstevel@tonic-gate 797c478bd9Sstevel@tonic-gate /* 807c478bd9Sstevel@tonic-gate * The variable controls the default setting of the command register 817c478bd9Sstevel@tonic-gate * for pci devices. See ppb_initchild() for details. 827c478bd9Sstevel@tonic-gate */ 837c478bd9Sstevel@tonic-gate static ushort_t ppb_command_default = PCI_COMM_SERR_ENABLE | 847c478bd9Sstevel@tonic-gate PCI_COMM_WAIT_CYC_ENAB | 857c478bd9Sstevel@tonic-gate PCI_COMM_PARITY_DETECT | 867c478bd9Sstevel@tonic-gate PCI_COMM_ME | 877c478bd9Sstevel@tonic-gate PCI_COMM_MAE | 887c478bd9Sstevel@tonic-gate PCI_COMM_IO; 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate static int ppb_bus_map(dev_info_t *, dev_info_t *, ddi_map_req_t *, 917c478bd9Sstevel@tonic-gate off_t, off_t, caddr_t *); 927c478bd9Sstevel@tonic-gate static int ppb_ctlops(dev_info_t *, dev_info_t *, ddi_ctl_enum_t, 937c478bd9Sstevel@tonic-gate void *, void *); 947c478bd9Sstevel@tonic-gate static int ppb_intr_ops(dev_info_t *dip, dev_info_t *rdip, 957c478bd9Sstevel@tonic-gate ddi_intr_op_t intr_op, ddi_intr_handle_impl_t *hdlp, void *result); 967c478bd9Sstevel@tonic-gate 977c478bd9Sstevel@tonic-gate /* 987c478bd9Sstevel@tonic-gate * fm_init busop to initialize our children 997c478bd9Sstevel@tonic-gate */ 1007c478bd9Sstevel@tonic-gate static int ppb_fm_init_child(dev_info_t *dip, dev_info_t *tdip, int cap, 1017c478bd9Sstevel@tonic-gate ddi_iblock_cookie_t *ibc); 1027c478bd9Sstevel@tonic-gate static void ppb_bus_enter(dev_info_t *dip, ddi_acc_handle_t handle); 1037c478bd9Sstevel@tonic-gate static void ppb_bus_exit(dev_info_t *dip, ddi_acc_handle_t handle); 1047c478bd9Sstevel@tonic-gate static int ppb_bus_power(dev_info_t *dip, void *impl_arg, pm_bus_power_op_t op, 1057c478bd9Sstevel@tonic-gate void *arg, void *result); 1067c478bd9Sstevel@tonic-gate 1077c478bd9Sstevel@tonic-gate struct bus_ops ppb_bus_ops = { 1087c478bd9Sstevel@tonic-gate BUSO_REV, 1097c478bd9Sstevel@tonic-gate ppb_bus_map, 1107c478bd9Sstevel@tonic-gate 0, 1117c478bd9Sstevel@tonic-gate 0, 1127c478bd9Sstevel@tonic-gate 0, 1137c478bd9Sstevel@tonic-gate i_ddi_map_fault, 114*cd21e7c5SGarrett D'Amore 0, 1157c478bd9Sstevel@tonic-gate ddi_dma_allochdl, 1167c478bd9Sstevel@tonic-gate ddi_dma_freehdl, 1177c478bd9Sstevel@tonic-gate ddi_dma_bindhdl, 1187c478bd9Sstevel@tonic-gate ddi_dma_unbindhdl, 1197c478bd9Sstevel@tonic-gate ddi_dma_flush, 1207c478bd9Sstevel@tonic-gate ddi_dma_win, 1217c478bd9Sstevel@tonic-gate ddi_dma_mctl, 1227c478bd9Sstevel@tonic-gate ppb_ctlops, 1237c478bd9Sstevel@tonic-gate ddi_bus_prop_op, 1247c478bd9Sstevel@tonic-gate ndi_busop_get_eventcookie, /* (*bus_get_eventcookie)(); */ 1257c478bd9Sstevel@tonic-gate ndi_busop_add_eventcall, /* (*bus_add_eventcall)(); */ 1267c478bd9Sstevel@tonic-gate ndi_busop_remove_eventcall, /* (*bus_remove_eventcall)(); */ 1277c478bd9Sstevel@tonic-gate ndi_post_event, /* (*bus_post_event)(); */ 1287c478bd9Sstevel@tonic-gate 0, /* (*bus_intr_ctl)(); */ 1297c478bd9Sstevel@tonic-gate 0, /* (*bus_config)(); */ 1307c478bd9Sstevel@tonic-gate 0, /* (*bus_unconfig)(); */ 1317c478bd9Sstevel@tonic-gate ppb_fm_init_child, /* (*bus_fm_init)(); */ 1327c478bd9Sstevel@tonic-gate NULL, /* (*bus_fm_fini)(); */ 1337c478bd9Sstevel@tonic-gate ppb_bus_enter, /* (*bus_enter)() */ 1347c478bd9Sstevel@tonic-gate ppb_bus_exit, /* (*bus_exit)() */ 1357c478bd9Sstevel@tonic-gate ppb_bus_power, /* (*bus_power)() */ 13626947304SEvan Yan ppb_intr_ops, /* (*bus_intr_op)(); */ 13726947304SEvan Yan pcie_hp_common_ops /* (*bus_hp_op)(); */ 1387c478bd9Sstevel@tonic-gate }; 1397c478bd9Sstevel@tonic-gate 1407c478bd9Sstevel@tonic-gate static int ppb_open(dev_t *devp, int flags, int otyp, cred_t *credp); 1417c478bd9Sstevel@tonic-gate static int ppb_close(dev_t dev, int flags, int otyp, cred_t *credp); 1427c478bd9Sstevel@tonic-gate static int ppb_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, 1437c478bd9Sstevel@tonic-gate cred_t *credp, int *rvalp); 1447c478bd9Sstevel@tonic-gate static int ppb_prop_op(dev_t dev, dev_info_t *dip, ddi_prop_op_t prop_op, 1457c478bd9Sstevel@tonic-gate int flags, char *name, caddr_t valuep, int *lengthp); 1467c478bd9Sstevel@tonic-gate 1477c478bd9Sstevel@tonic-gate static struct cb_ops ppb_cb_ops = { 1487c478bd9Sstevel@tonic-gate ppb_open, /* open */ 1497c478bd9Sstevel@tonic-gate ppb_close, /* close */ 1507c478bd9Sstevel@tonic-gate nulldev, /* strategy */ 1517c478bd9Sstevel@tonic-gate nulldev, /* print */ 1527c478bd9Sstevel@tonic-gate nulldev, /* dump */ 1537c478bd9Sstevel@tonic-gate nulldev, /* read */ 1547c478bd9Sstevel@tonic-gate nulldev, /* write */ 1557c478bd9Sstevel@tonic-gate ppb_ioctl, /* ioctl */ 1567c478bd9Sstevel@tonic-gate nodev, /* devmap */ 1577c478bd9Sstevel@tonic-gate nodev, /* mmap */ 1587c478bd9Sstevel@tonic-gate nodev, /* segmap */ 1597c478bd9Sstevel@tonic-gate nochpoll, /* poll */ 1607c478bd9Sstevel@tonic-gate ppb_prop_op, /* cb_prop_op */ 1617c478bd9Sstevel@tonic-gate NULL, /* streamtab */ 1627c478bd9Sstevel@tonic-gate D_NEW | D_MP | D_HOTPLUG, /* Driver compatibility flag */ 1637c478bd9Sstevel@tonic-gate CB_REV, /* rev */ 1647c478bd9Sstevel@tonic-gate nodev, /* int (*cb_aread)() */ 1657c478bd9Sstevel@tonic-gate nodev /* int (*cb_awrite)() */ 1667c478bd9Sstevel@tonic-gate }; 1677c478bd9Sstevel@tonic-gate 1687c478bd9Sstevel@tonic-gate static int ppb_probe(dev_info_t *); 1697c478bd9Sstevel@tonic-gate static int ppb_attach(dev_info_t *devi, ddi_attach_cmd_t cmd); 1707c478bd9Sstevel@tonic-gate static int ppb_detach(dev_info_t *devi, ddi_detach_cmd_t cmd); 17126947304SEvan Yan static int ppb_info(dev_info_t *dip, ddi_info_cmd_t cmd, 1727c478bd9Sstevel@tonic-gate void *arg, void **result); 1737c478bd9Sstevel@tonic-gate static int ppb_pwr(dev_info_t *dip, int component, int level); 1747c478bd9Sstevel@tonic-gate 1757c478bd9Sstevel@tonic-gate struct dev_ops ppb_ops = { 1767c478bd9Sstevel@tonic-gate DEVO_REV, /* devo_rev */ 1777c478bd9Sstevel@tonic-gate 0, /* refcnt */ 1787c478bd9Sstevel@tonic-gate ppb_info, /* info */ 1797c478bd9Sstevel@tonic-gate nulldev, /* identify */ 1807c478bd9Sstevel@tonic-gate ppb_probe, /* probe */ 1817c478bd9Sstevel@tonic-gate ppb_attach, /* attach */ 1827c478bd9Sstevel@tonic-gate ppb_detach, /* detach */ 1837c478bd9Sstevel@tonic-gate nulldev, /* reset */ 1847c478bd9Sstevel@tonic-gate &ppb_cb_ops, /* driver operations */ 1857c478bd9Sstevel@tonic-gate &ppb_bus_ops, /* bus operations */ 18619397407SSherry Moore ppb_pwr, /* power */ 18719397407SSherry Moore ddi_quiesce_not_needed, /* quiesce */ 1887c478bd9Sstevel@tonic-gate }; 1897c478bd9Sstevel@tonic-gate 1907c478bd9Sstevel@tonic-gate /* 1917c478bd9Sstevel@tonic-gate * Module linkage information for the kernel. 1927c478bd9Sstevel@tonic-gate */ 1937c478bd9Sstevel@tonic-gate 1947c478bd9Sstevel@tonic-gate static struct modldrv modldrv = { 1957c478bd9Sstevel@tonic-gate &mod_driverops, /* Type of module */ 19619397407SSherry Moore "Standard PCI to PCI bridge nexus driver", 1977c478bd9Sstevel@tonic-gate &ppb_ops, /* driver ops */ 1987c478bd9Sstevel@tonic-gate }; 1997c478bd9Sstevel@tonic-gate 2007c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = { 2017c478bd9Sstevel@tonic-gate MODREV_1, 2027c478bd9Sstevel@tonic-gate (void *)&modldrv, 2037c478bd9Sstevel@tonic-gate NULL 2047c478bd9Sstevel@tonic-gate }; 2057c478bd9Sstevel@tonic-gate 2067c478bd9Sstevel@tonic-gate /* 2077c478bd9Sstevel@tonic-gate * soft state pointer and structure template: 2087c478bd9Sstevel@tonic-gate */ 2097c478bd9Sstevel@tonic-gate static void *ppb_state; 2107c478bd9Sstevel@tonic-gate 211f47a9c50Smathue struct ppb_cfg_state { 2127c478bd9Sstevel@tonic-gate dev_info_t *dip; 2137c478bd9Sstevel@tonic-gate ushort_t command; 2147c478bd9Sstevel@tonic-gate uchar_t cache_line_size; 2157c478bd9Sstevel@tonic-gate uchar_t latency_timer; 2167c478bd9Sstevel@tonic-gate uchar_t header_type; 2177c478bd9Sstevel@tonic-gate uchar_t sec_latency_timer; 2187c478bd9Sstevel@tonic-gate ushort_t bridge_control; 2197c478bd9Sstevel@tonic-gate }; 2207c478bd9Sstevel@tonic-gate 2217c478bd9Sstevel@tonic-gate typedef struct { 2227c478bd9Sstevel@tonic-gate 2237c478bd9Sstevel@tonic-gate dev_info_t *dip; 2247c478bd9Sstevel@tonic-gate 2257c478bd9Sstevel@tonic-gate /* 2267c478bd9Sstevel@tonic-gate * configuration register state for the bus: 2277c478bd9Sstevel@tonic-gate */ 2287c478bd9Sstevel@tonic-gate uchar_t ppb_cache_line_size; 2297c478bd9Sstevel@tonic-gate uchar_t ppb_latency_timer; 2307c478bd9Sstevel@tonic-gate 2317c478bd9Sstevel@tonic-gate /* 2327c478bd9Sstevel@tonic-gate * PM support 2337c478bd9Sstevel@tonic-gate */ 2347c478bd9Sstevel@tonic-gate ddi_acc_handle_t ppb_conf_hdl; 23527255037Spjha uint16_t ppb_pm_cap_ptr; 2367c478bd9Sstevel@tonic-gate pci_pwr_t *ppb_pwr_p; 2377c478bd9Sstevel@tonic-gate 2387c478bd9Sstevel@tonic-gate /* 2397c478bd9Sstevel@tonic-gate * HP support 2407c478bd9Sstevel@tonic-gate */ 2417c478bd9Sstevel@tonic-gate boolean_t hotplug_capable; 2427c478bd9Sstevel@tonic-gate 2437c478bd9Sstevel@tonic-gate kmutex_t ppb_mutex; 2447c478bd9Sstevel@tonic-gate uint_t ppb_soft_state; 2457c478bd9Sstevel@tonic-gate int fm_cap; 2467c478bd9Sstevel@tonic-gate ddi_iblock_cookie_t fm_ibc; 247bf8fc234Set142600 248c85864d8SKrishna Elango uint16_t parent_bus; 2497c478bd9Sstevel@tonic-gate } ppb_devstate_t; 2507c478bd9Sstevel@tonic-gate 2517c478bd9Sstevel@tonic-gate /* 2527c478bd9Sstevel@tonic-gate * The following variable enables a workaround for the following obp bug: 2537c478bd9Sstevel@tonic-gate * 2547c478bd9Sstevel@tonic-gate * 1234181 - obp should set latency timer registers in pci 2557c478bd9Sstevel@tonic-gate * configuration header 2567c478bd9Sstevel@tonic-gate * 2577c478bd9Sstevel@tonic-gate * Until this bug gets fixed in the obp, the following workaround should 2587c478bd9Sstevel@tonic-gate * be enabled. 2597c478bd9Sstevel@tonic-gate */ 2607c478bd9Sstevel@tonic-gate static uint_t ppb_set_latency_timer_register = 1; 2617c478bd9Sstevel@tonic-gate 2627c478bd9Sstevel@tonic-gate /* 2637c478bd9Sstevel@tonic-gate * The following variable enables a workaround for an obp bug to be 2647c478bd9Sstevel@tonic-gate * submitted. A bug requesting a workaround fof this problem has 2657c478bd9Sstevel@tonic-gate * been filed: 2667c478bd9Sstevel@tonic-gate * 2677c478bd9Sstevel@tonic-gate * 1235094 - need workarounds on positron nexus drivers to set cache 2687c478bd9Sstevel@tonic-gate * line size registers 2697c478bd9Sstevel@tonic-gate * 2707c478bd9Sstevel@tonic-gate * Until this bug gets fixed in the obp, the following workaround should 2717c478bd9Sstevel@tonic-gate * be enabled. 2727c478bd9Sstevel@tonic-gate */ 2737c478bd9Sstevel@tonic-gate static uint_t ppb_set_cache_line_size_register = 1; 2747c478bd9Sstevel@tonic-gate 2757c478bd9Sstevel@tonic-gate /* 2767c478bd9Sstevel@tonic-gate * forward function declarations: 2777c478bd9Sstevel@tonic-gate */ 2787c478bd9Sstevel@tonic-gate 2797c478bd9Sstevel@tonic-gate /* 2807c478bd9Sstevel@tonic-gate * FMA error callback 2817c478bd9Sstevel@tonic-gate * Register error handling callback with our parent. We will just call 2827c478bd9Sstevel@tonic-gate * our children's error callbacks and return their status. 2837c478bd9Sstevel@tonic-gate */ 2847c478bd9Sstevel@tonic-gate static int ppb_err_callback(dev_info_t *dip, ddi_fm_error_t *derr, 2857c478bd9Sstevel@tonic-gate const void *impl_data); 2867c478bd9Sstevel@tonic-gate 2877c478bd9Sstevel@tonic-gate /* 2887c478bd9Sstevel@tonic-gate * init/fini routines to alloc/dealloc fm structures and 2897c478bd9Sstevel@tonic-gate * register/unregister our callback. 2907c478bd9Sstevel@tonic-gate */ 2917c478bd9Sstevel@tonic-gate static void ppb_fm_init(ppb_devstate_t *ppb_p); 2927c478bd9Sstevel@tonic-gate static void ppb_fm_fini(ppb_devstate_t *ppb_p); 2937c478bd9Sstevel@tonic-gate 2947c478bd9Sstevel@tonic-gate static void ppb_removechild(dev_info_t *); 2957c478bd9Sstevel@tonic-gate static int ppb_initchild(dev_info_t *child); 296bf8fc234Set142600 static void ppb_uninitchild(dev_info_t *child); 2977c478bd9Sstevel@tonic-gate static dev_info_t *get_my_childs_dip(dev_info_t *dip, dev_info_t *rdip); 2987c478bd9Sstevel@tonic-gate static void ppb_pwr_setup(ppb_devstate_t *ppb, dev_info_t *dip); 2997c478bd9Sstevel@tonic-gate static void ppb_pwr_teardown(ppb_devstate_t *ppb, dev_info_t *dip); 3007c478bd9Sstevel@tonic-gate static void ppb_init_hotplug(ppb_devstate_t *ppb); 3017c478bd9Sstevel@tonic-gate static void ppb_create_ranges_prop(dev_info_t *, ddi_acc_handle_t); 302e487bac0Smathue uint64_t pci_debug_flags = 0; 3037c478bd9Sstevel@tonic-gate 3047c478bd9Sstevel@tonic-gate int 3057c478bd9Sstevel@tonic-gate _init(void) 3067c478bd9Sstevel@tonic-gate { 3077c478bd9Sstevel@tonic-gate int e; 3087c478bd9Sstevel@tonic-gate if ((e = ddi_soft_state_init(&ppb_state, sizeof (ppb_devstate_t), 3097c478bd9Sstevel@tonic-gate 1)) == 0 && (e = mod_install(&modlinkage)) != 0) 3107c478bd9Sstevel@tonic-gate ddi_soft_state_fini(&ppb_state); 3117c478bd9Sstevel@tonic-gate return (e); 3127c478bd9Sstevel@tonic-gate } 3137c478bd9Sstevel@tonic-gate 3147c478bd9Sstevel@tonic-gate int 3157c478bd9Sstevel@tonic-gate _fini(void) 3167c478bd9Sstevel@tonic-gate { 3177c478bd9Sstevel@tonic-gate int e; 3187c478bd9Sstevel@tonic-gate 3197c478bd9Sstevel@tonic-gate if ((e = mod_remove(&modlinkage)) == 0) 3207c478bd9Sstevel@tonic-gate ddi_soft_state_fini(&ppb_state); 3217c478bd9Sstevel@tonic-gate return (e); 3227c478bd9Sstevel@tonic-gate } 3237c478bd9Sstevel@tonic-gate 3247c478bd9Sstevel@tonic-gate int 3257c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop) 3267c478bd9Sstevel@tonic-gate { 3277c478bd9Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 3287c478bd9Sstevel@tonic-gate } 3297c478bd9Sstevel@tonic-gate 3307c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 3317c478bd9Sstevel@tonic-gate static int 33226947304SEvan Yan ppb_info(dev_info_t *dip, ddi_info_cmd_t cmd, void *arg, void **result) 3337c478bd9Sstevel@tonic-gate { 3347c478bd9Sstevel@tonic-gate minor_t minor = getminor((dev_t)arg); 33526947304SEvan Yan int instance = PCI_MINOR_NUM_TO_INSTANCE(minor); 33626947304SEvan Yan ppb_devstate_t *ppb_p = (ppb_devstate_t *)ddi_get_soft_state(ppb_state, 3377c478bd9Sstevel@tonic-gate instance); 3387c478bd9Sstevel@tonic-gate 33926947304SEvan Yan 34026947304SEvan Yan if (ppb_p->parent_bus != PCIE_PCIECAP_DEV_TYPE_PCIE_DEV) 34126947304SEvan Yan return (pcihp_info(dip, cmd, arg, result)); 34226947304SEvan Yan 34326947304SEvan Yan switch (cmd) { 3447c478bd9Sstevel@tonic-gate default: 3457c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 3467c478bd9Sstevel@tonic-gate 3477c478bd9Sstevel@tonic-gate case DDI_INFO_DEVT2INSTANCE: 348f47a9c50Smathue *result = (void *)(uintptr_t)instance; 3497c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 3507c478bd9Sstevel@tonic-gate 3517c478bd9Sstevel@tonic-gate case DDI_INFO_DEVT2DEVINFO: 3527c478bd9Sstevel@tonic-gate if (ppb_p == NULL) 3537c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 3547c478bd9Sstevel@tonic-gate *result = (void *)ppb_p->dip; 3557c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 3567c478bd9Sstevel@tonic-gate } 3577c478bd9Sstevel@tonic-gate } 3587c478bd9Sstevel@tonic-gate 3597c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 3607c478bd9Sstevel@tonic-gate static int 3617c478bd9Sstevel@tonic-gate ppb_probe(register dev_info_t *devi) 3627c478bd9Sstevel@tonic-gate { 3637c478bd9Sstevel@tonic-gate return (DDI_PROBE_SUCCESS); 3647c478bd9Sstevel@tonic-gate } 3657c478bd9Sstevel@tonic-gate 3667c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 3677c478bd9Sstevel@tonic-gate static int 3687c478bd9Sstevel@tonic-gate ppb_attach(dev_info_t *devi, ddi_attach_cmd_t cmd) 3697c478bd9Sstevel@tonic-gate { 37026947304SEvan Yan dev_info_t *root = ddi_root_node(); 3717c478bd9Sstevel@tonic-gate int instance; 3727c478bd9Sstevel@tonic-gate ppb_devstate_t *ppb; 37326947304SEvan Yan dev_info_t *pdip; 3747c478bd9Sstevel@tonic-gate ddi_acc_handle_t config_handle; 37526947304SEvan Yan char *bus; 3767c478bd9Sstevel@tonic-gate 3777c478bd9Sstevel@tonic-gate switch (cmd) { 3787c478bd9Sstevel@tonic-gate case DDI_ATTACH: 3797c478bd9Sstevel@tonic-gate 3807c478bd9Sstevel@tonic-gate /* 3817c478bd9Sstevel@tonic-gate * Make sure the "device_type" property exists. 3827c478bd9Sstevel@tonic-gate */ 3837c478bd9Sstevel@tonic-gate (void) ddi_prop_update_string(DDI_DEV_T_NONE, devi, 3847c478bd9Sstevel@tonic-gate "device_type", "pci"); 3857c478bd9Sstevel@tonic-gate 3867c478bd9Sstevel@tonic-gate /* 3877c478bd9Sstevel@tonic-gate * Allocate and get soft state structure. 3887c478bd9Sstevel@tonic-gate */ 3897c478bd9Sstevel@tonic-gate instance = ddi_get_instance(devi); 3907c478bd9Sstevel@tonic-gate if (ddi_soft_state_zalloc(ppb_state, instance) != DDI_SUCCESS) 3917c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 3927c478bd9Sstevel@tonic-gate ppb = (ppb_devstate_t *)ddi_get_soft_state(ppb_state, instance); 3937c478bd9Sstevel@tonic-gate ppb->dip = devi; 3947c478bd9Sstevel@tonic-gate mutex_init(&ppb->ppb_mutex, NULL, MUTEX_DRIVER, NULL); 39526947304SEvan Yan ppb->ppb_soft_state = PCI_SOFT_STATE_CLOSED; 3967c478bd9Sstevel@tonic-gate if (pci_config_setup(devi, &config_handle) != DDI_SUCCESS) { 3977c478bd9Sstevel@tonic-gate mutex_destroy(&ppb->ppb_mutex); 3987c478bd9Sstevel@tonic-gate ddi_soft_state_free(ppb_state, instance); 3997c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 4007c478bd9Sstevel@tonic-gate } 4017c478bd9Sstevel@tonic-gate ppb_pwr_setup(ppb, devi); 4027c478bd9Sstevel@tonic-gate 4037c478bd9Sstevel@tonic-gate if (PM_CAPABLE(ppb->ppb_pwr_p)) { 4047c478bd9Sstevel@tonic-gate mutex_enter(&ppb->ppb_pwr_p->pwr_mutex); 4057c478bd9Sstevel@tonic-gate 4067c478bd9Sstevel@tonic-gate /* 4077c478bd9Sstevel@tonic-gate * Before reading config registers, make sure power is 4087c478bd9Sstevel@tonic-gate * on, and remains on. 4097c478bd9Sstevel@tonic-gate */ 4107c478bd9Sstevel@tonic-gate ppb->ppb_pwr_p->pwr_fp++; 4117c478bd9Sstevel@tonic-gate 4127c478bd9Sstevel@tonic-gate pci_pwr_change(ppb->ppb_pwr_p, 4137c478bd9Sstevel@tonic-gate ppb->ppb_pwr_p->current_lvl, 4147c478bd9Sstevel@tonic-gate pci_pwr_new_lvl(ppb->ppb_pwr_p)); 4157c478bd9Sstevel@tonic-gate } 4167c478bd9Sstevel@tonic-gate 4177c478bd9Sstevel@tonic-gate ppb->ppb_cache_line_size = 4187c478bd9Sstevel@tonic-gate pci_config_get8(config_handle, PCI_CONF_CACHE_LINESZ); 4197c478bd9Sstevel@tonic-gate ppb->ppb_latency_timer = 4207c478bd9Sstevel@tonic-gate pci_config_get8(config_handle, PCI_CONF_LATENCY_TIMER); 4217c478bd9Sstevel@tonic-gate 4227c478bd9Sstevel@tonic-gate /* 4237c478bd9Sstevel@tonic-gate * Check whether the "ranges" property is present. 4247c478bd9Sstevel@tonic-gate * Otherwise create the ranges property by reading 4257c478bd9Sstevel@tonic-gate * the configuration registers 4267c478bd9Sstevel@tonic-gate */ 4277c478bd9Sstevel@tonic-gate if (ddi_prop_exists(DDI_DEV_T_ANY, devi, DDI_PROP_DONTPASS, 4287c478bd9Sstevel@tonic-gate "ranges") == 0) { 4297c478bd9Sstevel@tonic-gate ppb_create_ranges_prop(devi, config_handle); 4307c478bd9Sstevel@tonic-gate } 4317c478bd9Sstevel@tonic-gate 4327c478bd9Sstevel@tonic-gate pci_config_teardown(&config_handle); 4337c478bd9Sstevel@tonic-gate 4347c478bd9Sstevel@tonic-gate if (PM_CAPABLE(ppb->ppb_pwr_p)) { 4357c478bd9Sstevel@tonic-gate ppb->ppb_pwr_p->pwr_fp--; 4367c478bd9Sstevel@tonic-gate 4377c478bd9Sstevel@tonic-gate pci_pwr_change(ppb->ppb_pwr_p, 4387c478bd9Sstevel@tonic-gate ppb->ppb_pwr_p->current_lvl, 4397c478bd9Sstevel@tonic-gate pci_pwr_new_lvl(ppb->ppb_pwr_p)); 4407c478bd9Sstevel@tonic-gate 4417c478bd9Sstevel@tonic-gate mutex_exit(&ppb->ppb_pwr_p->pwr_mutex); 4427c478bd9Sstevel@tonic-gate } 4437c478bd9Sstevel@tonic-gate 44426947304SEvan Yan ppb->parent_bus = PCIE_PCIECAP_DEV_TYPE_PCI_PSEUDO; 44526947304SEvan Yan for (pdip = ddi_get_parent(ppb->dip); pdip && (pdip != root) && 44626947304SEvan Yan (ppb->parent_bus != PCIE_PCIECAP_DEV_TYPE_PCIE_DEV); 44726947304SEvan Yan pdip = ddi_get_parent(pdip)) { 44826947304SEvan Yan if (ddi_prop_lookup_string(DDI_DEV_T_ANY, pdip, 44926947304SEvan Yan DDI_PROP_DONTPASS, "device_type", &bus) != 45026947304SEvan Yan DDI_PROP_SUCCESS) 45126947304SEvan Yan break; 45226947304SEvan Yan 45326947304SEvan Yan if (strcmp(bus, "pciex") == 0) 45426947304SEvan Yan ppb->parent_bus = 45526947304SEvan Yan PCIE_PCIECAP_DEV_TYPE_PCIE_DEV; 45626947304SEvan Yan 45726947304SEvan Yan ddi_prop_free(bus); 4587c478bd9Sstevel@tonic-gate } 45926947304SEvan Yan 46026947304SEvan Yan /* 46126947304SEvan Yan * Initialize hotplug support on this bus. 46226947304SEvan Yan */ 46326947304SEvan Yan if (ppb->parent_bus == PCIE_PCIECAP_DEV_TYPE_PCIE_DEV) 46426947304SEvan Yan if (pcie_init(devi, NULL) != DDI_SUCCESS) { 46526947304SEvan Yan (void) ppb_detach(devi, DDI_DETACH); 4667c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 4677c478bd9Sstevel@tonic-gate } 46826947304SEvan Yan else 46926947304SEvan Yan ppb_init_hotplug(ppb); 4707c478bd9Sstevel@tonic-gate 4717c478bd9Sstevel@tonic-gate DEBUG1(DBG_ATTACH, devi, 4727c478bd9Sstevel@tonic-gate "ppb_attach(): this nexus %s hotplug slots\n", 4737c478bd9Sstevel@tonic-gate ppb->hotplug_capable == B_TRUE ? "has":"has no"); 4747c478bd9Sstevel@tonic-gate 4757c478bd9Sstevel@tonic-gate ppb_fm_init(ppb); 4767c478bd9Sstevel@tonic-gate ddi_report_dev(devi); 4777c478bd9Sstevel@tonic-gate 4787c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 4797c478bd9Sstevel@tonic-gate 4807c478bd9Sstevel@tonic-gate case DDI_RESUME: 4817c478bd9Sstevel@tonic-gate /* 4827c478bd9Sstevel@tonic-gate * Get the soft state structure for the bridge. 4837c478bd9Sstevel@tonic-gate */ 4847c478bd9Sstevel@tonic-gate ppb = (ppb_devstate_t *) 4857c478bd9Sstevel@tonic-gate ddi_get_soft_state(ppb_state, ddi_get_instance(devi)); 4867c478bd9Sstevel@tonic-gate 4877c478bd9Sstevel@tonic-gate pci_pwr_resume(devi, ppb->ppb_pwr_p); 4887c478bd9Sstevel@tonic-gate 4897c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 4907c478bd9Sstevel@tonic-gate } 4917c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 4927c478bd9Sstevel@tonic-gate } 4937c478bd9Sstevel@tonic-gate 4947c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 4957c478bd9Sstevel@tonic-gate static int 4967c478bd9Sstevel@tonic-gate ppb_detach(dev_info_t *devi, ddi_detach_cmd_t cmd) 4977c478bd9Sstevel@tonic-gate { 4987c478bd9Sstevel@tonic-gate ppb_devstate_t *ppb; 49926947304SEvan Yan int ret = DDI_SUCCESS; 5007c478bd9Sstevel@tonic-gate 5017c478bd9Sstevel@tonic-gate switch (cmd) { 5027c478bd9Sstevel@tonic-gate case DDI_DETACH: 5037c478bd9Sstevel@tonic-gate /* 5047c478bd9Sstevel@tonic-gate * And finally free the per-pci soft state after 5057c478bd9Sstevel@tonic-gate * uninitializing hotplug support for this bus. 5067c478bd9Sstevel@tonic-gate */ 5077c478bd9Sstevel@tonic-gate ppb = (ppb_devstate_t *) 5087c478bd9Sstevel@tonic-gate ddi_get_soft_state(ppb_state, ddi_get_instance(devi)); 5097c478bd9Sstevel@tonic-gate 5107c478bd9Sstevel@tonic-gate ppb_fm_fini(ppb); 5117c478bd9Sstevel@tonic-gate 51226947304SEvan Yan if (ppb->parent_bus == PCIE_PCIECAP_DEV_TYPE_PCIE_DEV) 51326947304SEvan Yan ret = pcie_uninit(devi); 51426947304SEvan Yan else if (ppb->hotplug_capable == B_TRUE) 51526947304SEvan Yan ret = pcihp_init(devi); 5167c478bd9Sstevel@tonic-gate else 5177c478bd9Sstevel@tonic-gate ddi_remove_minor_node(devi, "devctl"); 5187c478bd9Sstevel@tonic-gate 51926947304SEvan Yan if (ret != DDI_SUCCESS) 52026947304SEvan Yan return (DDI_FAILURE); 52126947304SEvan Yan 5227c478bd9Sstevel@tonic-gate (void) ddi_prop_remove(DDI_DEV_T_NONE, devi, "device_type"); 5237c478bd9Sstevel@tonic-gate 5247c478bd9Sstevel@tonic-gate if (ppb->ppb_pwr_p != NULL) { 5257c478bd9Sstevel@tonic-gate ppb_pwr_teardown(ppb, devi); 5267c478bd9Sstevel@tonic-gate } 5277c478bd9Sstevel@tonic-gate mutex_destroy(&ppb->ppb_mutex); 5287c478bd9Sstevel@tonic-gate ddi_soft_state_free(ppb_state, ddi_get_instance(devi)); 5297c478bd9Sstevel@tonic-gate 5307c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 5317c478bd9Sstevel@tonic-gate 5327c478bd9Sstevel@tonic-gate case DDI_SUSPEND: 5337c478bd9Sstevel@tonic-gate ppb = (ppb_devstate_t *) 5347c478bd9Sstevel@tonic-gate ddi_get_soft_state(ppb_state, ddi_get_instance(devi)); 5357c478bd9Sstevel@tonic-gate 5367c478bd9Sstevel@tonic-gate pci_pwr_suspend(devi, ppb->ppb_pwr_p); 5377c478bd9Sstevel@tonic-gate 5387c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 5397c478bd9Sstevel@tonic-gate } 5407c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 5417c478bd9Sstevel@tonic-gate } 5427c478bd9Sstevel@tonic-gate 5437c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 5447c478bd9Sstevel@tonic-gate static int 5457c478bd9Sstevel@tonic-gate ppb_bus_map(dev_info_t *dip, dev_info_t *rdip, ddi_map_req_t *mp, 5467c478bd9Sstevel@tonic-gate off_t offset, off_t len, caddr_t *vaddrp) 5477c478bd9Sstevel@tonic-gate { 5487c478bd9Sstevel@tonic-gate register dev_info_t *pdip; 5497c478bd9Sstevel@tonic-gate 5507c478bd9Sstevel@tonic-gate pdip = (dev_info_t *)DEVI(dip)->devi_parent; 5517c478bd9Sstevel@tonic-gate return ((DEVI(pdip)->devi_ops->devo_bus_ops->bus_map) 5527c478bd9Sstevel@tonic-gate (pdip, rdip, mp, offset, len, vaddrp)); 5537c478bd9Sstevel@tonic-gate } 5547c478bd9Sstevel@tonic-gate 5557c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 5567c478bd9Sstevel@tonic-gate static int 5577c478bd9Sstevel@tonic-gate ppb_ctlops(dev_info_t *dip, dev_info_t *rdip, 5587c478bd9Sstevel@tonic-gate ddi_ctl_enum_t ctlop, void *arg, void *result) 5597c478bd9Sstevel@tonic-gate { 5607c478bd9Sstevel@tonic-gate pci_regspec_t *drv_regp; 5617c478bd9Sstevel@tonic-gate int reglen; 5627c478bd9Sstevel@tonic-gate int rn; 563bf8fc234Set142600 struct attachspec *as; 564bf8fc234Set142600 struct detachspec *ds; 565e51949e6Sdduvall int totreg; 566bf8fc234Set142600 ppb_devstate_t *ppb_p; 567bf8fc234Set142600 568bf8fc234Set142600 ppb_p = (ppb_devstate_t *)ddi_get_soft_state(ppb_state, 569bf8fc234Set142600 ddi_get_instance(dip)); 5707c478bd9Sstevel@tonic-gate 5717c478bd9Sstevel@tonic-gate switch (ctlop) { 5727c478bd9Sstevel@tonic-gate case DDI_CTLOPS_REPORTDEV: 5737c478bd9Sstevel@tonic-gate if (rdip == (dev_info_t *)0) 5747c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 5757c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "?PCI-device: %s@%s, %s%d\n", 5767c478bd9Sstevel@tonic-gate ddi_node_name(rdip), ddi_get_name_addr(rdip), 5777c478bd9Sstevel@tonic-gate ddi_driver_name(rdip), 5787c478bd9Sstevel@tonic-gate ddi_get_instance(rdip)); 5797c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 5807c478bd9Sstevel@tonic-gate 5817c478bd9Sstevel@tonic-gate case DDI_CTLOPS_INITCHILD: 5827c478bd9Sstevel@tonic-gate return (ppb_initchild((dev_info_t *)arg)); 5837c478bd9Sstevel@tonic-gate 5847c478bd9Sstevel@tonic-gate case DDI_CTLOPS_UNINITCHILD: 585bf8fc234Set142600 ppb_uninitchild((dev_info_t *)arg); 586bf8fc234Set142600 return (DDI_SUCCESS); 587bf8fc234Set142600 588bf8fc234Set142600 case DDI_CTLOPS_ATTACH: 589bf8fc234Set142600 if (!pcie_is_child(dip, rdip)) 590bf8fc234Set142600 return (DDI_SUCCESS); 591bf8fc234Set142600 592bf8fc234Set142600 as = (struct attachspec *)arg; 593bf8fc234Set142600 if ((ppb_p->parent_bus == PCIE_PCIECAP_DEV_TYPE_PCIE_DEV) && 594e0d05aa9Skrishnae (as->when == DDI_POST) && (as->result == DDI_SUCCESS)) 5950c5eba8cSkrishnae pf_init(rdip, ppb_p->fm_ibc, as->cmd); 596bf8fc234Set142600 597bf8fc234Set142600 return (DDI_SUCCESS); 598bf8fc234Set142600 599bf8fc234Set142600 case DDI_CTLOPS_DETACH: 600bf8fc234Set142600 if (!pcie_is_child(dip, rdip)) 601bf8fc234Set142600 return (DDI_SUCCESS); 602bf8fc234Set142600 603bf8fc234Set142600 ds = (struct detachspec *)arg; 604bf8fc234Set142600 if ((ppb_p->parent_bus == PCIE_PCIECAP_DEV_TYPE_PCIE_DEV) && 605bf8fc234Set142600 (ds->when == DDI_PRE)) 6060c5eba8cSkrishnae pf_fini(rdip, ds->cmd); 607bf8fc234Set142600 6087c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 6097c478bd9Sstevel@tonic-gate 6107c478bd9Sstevel@tonic-gate case DDI_CTLOPS_SIDDEV: 6117c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 6127c478bd9Sstevel@tonic-gate 6137c478bd9Sstevel@tonic-gate case DDI_CTLOPS_REGSIZE: 6147c478bd9Sstevel@tonic-gate case DDI_CTLOPS_NREGS: 6157c478bd9Sstevel@tonic-gate if (rdip == (dev_info_t *)0) 6167c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 6177c478bd9Sstevel@tonic-gate break; 6187c478bd9Sstevel@tonic-gate default: 6197c478bd9Sstevel@tonic-gate return (ddi_ctlops(dip, rdip, ctlop, arg, result)); 6207c478bd9Sstevel@tonic-gate } 6217c478bd9Sstevel@tonic-gate 6227c478bd9Sstevel@tonic-gate *(int *)result = 0; 623a3282898Scth if (ddi_getlongprop(DDI_DEV_T_ANY, rdip, 6247c478bd9Sstevel@tonic-gate DDI_PROP_DONTPASS | DDI_PROP_CANSLEEP, "reg", 6257c478bd9Sstevel@tonic-gate (caddr_t)&drv_regp, ®len) != DDI_SUCCESS) 6267c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 6277c478bd9Sstevel@tonic-gate 6287c478bd9Sstevel@tonic-gate totreg = reglen / sizeof (pci_regspec_t); 6297c478bd9Sstevel@tonic-gate if (ctlop == DDI_CTLOPS_NREGS) 6307c478bd9Sstevel@tonic-gate *(int *)result = totreg; 6317c478bd9Sstevel@tonic-gate else if (ctlop == DDI_CTLOPS_REGSIZE) { 6327c478bd9Sstevel@tonic-gate rn = *(int *)arg; 6337c478bd9Sstevel@tonic-gate if (rn >= totreg) { 6347c478bd9Sstevel@tonic-gate kmem_free(drv_regp, reglen); 6357c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 6367c478bd9Sstevel@tonic-gate } 6377c478bd9Sstevel@tonic-gate *(off_t *)result = drv_regp[rn].pci_size_low | 6387c478bd9Sstevel@tonic-gate ((uint64_t)drv_regp[rn].pci_size_hi << 32); 6397c478bd9Sstevel@tonic-gate } 6407c478bd9Sstevel@tonic-gate 6417c478bd9Sstevel@tonic-gate kmem_free(drv_regp, reglen); 6427c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 6437c478bd9Sstevel@tonic-gate } 6447c478bd9Sstevel@tonic-gate 6457c478bd9Sstevel@tonic-gate 6467c478bd9Sstevel@tonic-gate static dev_info_t * 6477c478bd9Sstevel@tonic-gate get_my_childs_dip(dev_info_t *dip, dev_info_t *rdip) 6487c478bd9Sstevel@tonic-gate { 6497c478bd9Sstevel@tonic-gate dev_info_t *cdip = rdip; 6507c478bd9Sstevel@tonic-gate 6517c478bd9Sstevel@tonic-gate for (; ddi_get_parent(cdip) != dip; cdip = ddi_get_parent(cdip)) 6527c478bd9Sstevel@tonic-gate ; 6537c478bd9Sstevel@tonic-gate 6547c478bd9Sstevel@tonic-gate return (cdip); 6557c478bd9Sstevel@tonic-gate } 6567c478bd9Sstevel@tonic-gate 6577c478bd9Sstevel@tonic-gate 6587c478bd9Sstevel@tonic-gate static int 6597c478bd9Sstevel@tonic-gate ppb_intr_ops(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t intr_op, 6607c478bd9Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp, void *result) 6617c478bd9Sstevel@tonic-gate { 6627c478bd9Sstevel@tonic-gate dev_info_t *cdip = rdip; 6637c478bd9Sstevel@tonic-gate pci_regspec_t *pci_rp; 6647c478bd9Sstevel@tonic-gate int reglen, len; 6657c478bd9Sstevel@tonic-gate uint32_t d, intr; 6667c478bd9Sstevel@tonic-gate 6671f4643f9Sgovinda if ((intr_op == DDI_INTROP_SUPPORTED_TYPES) || 6681f4643f9Sgovinda (hdlp->ih_type != DDI_INTR_TYPE_FIXED)) 6697c478bd9Sstevel@tonic-gate goto done; 6707c478bd9Sstevel@tonic-gate 6717c478bd9Sstevel@tonic-gate /* 6727c478bd9Sstevel@tonic-gate * If the interrupt-map property is defined at this 6737c478bd9Sstevel@tonic-gate * node, it will have performed the interrupt 6747c478bd9Sstevel@tonic-gate * translation as part of the property, so no 6757c478bd9Sstevel@tonic-gate * rotation needs to be done. 6767c478bd9Sstevel@tonic-gate */ 6777c478bd9Sstevel@tonic-gate if (ddi_getproplen(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, 6787c478bd9Sstevel@tonic-gate "interrupt-map", &len) == DDI_PROP_SUCCESS) 6797c478bd9Sstevel@tonic-gate goto done; 6807c478bd9Sstevel@tonic-gate 6817c478bd9Sstevel@tonic-gate cdip = get_my_childs_dip(dip, rdip); 6827c478bd9Sstevel@tonic-gate 6837c478bd9Sstevel@tonic-gate /* 6847c478bd9Sstevel@tonic-gate * Use the devices reg property to determine its 6857c478bd9Sstevel@tonic-gate * PCI bus number and device number. 6867c478bd9Sstevel@tonic-gate */ 687a3282898Scth if (ddi_getlongprop(DDI_DEV_T_ANY, cdip, DDI_PROP_DONTPASS, 6887c478bd9Sstevel@tonic-gate "reg", (caddr_t)&pci_rp, ®len) != DDI_SUCCESS) 6897c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 6907c478bd9Sstevel@tonic-gate 691a195726fSgovinda intr = hdlp->ih_vector; 6927c478bd9Sstevel@tonic-gate 6937c478bd9Sstevel@tonic-gate /* Spin the interrupt */ 6947c478bd9Sstevel@tonic-gate d = PCI_REG_DEV_G(pci_rp[0].pci_phys_hi); 6957c478bd9Sstevel@tonic-gate 6967c478bd9Sstevel@tonic-gate if ((intr >= PCI_INTA) && (intr <= PCI_INTD)) 697a195726fSgovinda hdlp->ih_vector = ((intr - 1 + (d % 4)) % 4 + 1); 6987c478bd9Sstevel@tonic-gate else 6997c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d: %s: PCI intr=%x out of range", 7007c478bd9Sstevel@tonic-gate ddi_driver_name(rdip), ddi_get_instance(rdip), 7017c478bd9Sstevel@tonic-gate ddi_driver_name(dip), intr); 7027c478bd9Sstevel@tonic-gate 7037c478bd9Sstevel@tonic-gate kmem_free(pci_rp, reglen); 7047c478bd9Sstevel@tonic-gate 7057c478bd9Sstevel@tonic-gate done: 7067c478bd9Sstevel@tonic-gate /* Pass up the request to our parent. */ 7077c478bd9Sstevel@tonic-gate return (i_ddi_intr_ops(dip, rdip, intr_op, hdlp, result)); 7087c478bd9Sstevel@tonic-gate } 7097c478bd9Sstevel@tonic-gate 7107c478bd9Sstevel@tonic-gate static int 7117c478bd9Sstevel@tonic-gate ppb_bus_power(dev_info_t *dip, void *impl_arg, pm_bus_power_op_t op, 7127c478bd9Sstevel@tonic-gate void *arg, void *result) 7137c478bd9Sstevel@tonic-gate { 7147c478bd9Sstevel@tonic-gate ppb_devstate_t *ppb; 7157c478bd9Sstevel@tonic-gate 7167c478bd9Sstevel@tonic-gate ppb = (ppb_devstate_t *)ddi_get_soft_state(ppb_state, 7177c478bd9Sstevel@tonic-gate ddi_get_instance(dip)); 7187c478bd9Sstevel@tonic-gate 7197c478bd9Sstevel@tonic-gate return (pci_pwr_ops(ppb->ppb_pwr_p, dip, impl_arg, op, arg, result)); 7207c478bd9Sstevel@tonic-gate } 7217c478bd9Sstevel@tonic-gate 7227c478bd9Sstevel@tonic-gate 7237c478bd9Sstevel@tonic-gate /* 7247c478bd9Sstevel@tonic-gate * name_child 7257c478bd9Sstevel@tonic-gate * 7267c478bd9Sstevel@tonic-gate * This function is called from init_child to name a node. It is 7277c478bd9Sstevel@tonic-gate * also passed as a callback for node merging functions. 7287c478bd9Sstevel@tonic-gate * 7297c478bd9Sstevel@tonic-gate * return value: DDI_SUCCESS, DDI_FAILURE 7307c478bd9Sstevel@tonic-gate */ 7317c478bd9Sstevel@tonic-gate static int 7327c478bd9Sstevel@tonic-gate ppb_name_child(dev_info_t *child, char *name, int namelen) 7337c478bd9Sstevel@tonic-gate { 7347c478bd9Sstevel@tonic-gate pci_regspec_t *pci_rp; 7357c478bd9Sstevel@tonic-gate uint_t slot, func; 7367c478bd9Sstevel@tonic-gate char **unit_addr; 7377c478bd9Sstevel@tonic-gate uint_t n; 7387c478bd9Sstevel@tonic-gate 7397c478bd9Sstevel@tonic-gate /* 7407c478bd9Sstevel@tonic-gate * Pseudo nodes indicate a prototype node with per-instance 7417c478bd9Sstevel@tonic-gate * properties to be merged into the real h/w device node. 7427c478bd9Sstevel@tonic-gate * The interpretation of the unit-address is DD[,F] 7437c478bd9Sstevel@tonic-gate * where DD is the device id and F is the function. 7447c478bd9Sstevel@tonic-gate */ 7457c478bd9Sstevel@tonic-gate if (ndi_dev_is_persistent_node(child) == 0) { 7467c478bd9Sstevel@tonic-gate if (ddi_prop_lookup_string_array(DDI_DEV_T_ANY, child, 7477c478bd9Sstevel@tonic-gate DDI_PROP_DONTPASS, "unit-address", &unit_addr, &n) != 7487c478bd9Sstevel@tonic-gate DDI_PROP_SUCCESS) { 7497c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "cannot name node from %s.conf", 7507c478bd9Sstevel@tonic-gate ddi_driver_name(child)); 7517c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 7527c478bd9Sstevel@tonic-gate } 7537c478bd9Sstevel@tonic-gate if (n != 1 || *unit_addr == NULL || **unit_addr == 0) { 7547c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "unit-address property in %s.conf" 7557c478bd9Sstevel@tonic-gate " not well-formed", ddi_driver_name(child)); 7567c478bd9Sstevel@tonic-gate ddi_prop_free(unit_addr); 7577c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 7587c478bd9Sstevel@tonic-gate } 7597c478bd9Sstevel@tonic-gate (void) snprintf(name, namelen, "%s", *unit_addr); 7607c478bd9Sstevel@tonic-gate ddi_prop_free(unit_addr); 7617c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 7627c478bd9Sstevel@tonic-gate } 7637c478bd9Sstevel@tonic-gate 7647c478bd9Sstevel@tonic-gate /* 7657c478bd9Sstevel@tonic-gate * Get the address portion of the node name based on 7667c478bd9Sstevel@tonic-gate * the function and device number. 7677c478bd9Sstevel@tonic-gate */ 7687c478bd9Sstevel@tonic-gate if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS, 7697c478bd9Sstevel@tonic-gate "reg", (int **)&pci_rp, &n) != DDI_SUCCESS) { 7707c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 7717c478bd9Sstevel@tonic-gate } 7727c478bd9Sstevel@tonic-gate 7737c478bd9Sstevel@tonic-gate slot = PCI_REG_DEV_G(pci_rp[0].pci_phys_hi); 7747c478bd9Sstevel@tonic-gate func = PCI_REG_FUNC_G(pci_rp[0].pci_phys_hi); 7757c478bd9Sstevel@tonic-gate 7767c478bd9Sstevel@tonic-gate if (func != 0) 7777c478bd9Sstevel@tonic-gate (void) snprintf(name, namelen, "%x,%x", slot, func); 7787c478bd9Sstevel@tonic-gate else 7797c478bd9Sstevel@tonic-gate (void) snprintf(name, namelen, "%x", slot); 7807c478bd9Sstevel@tonic-gate 7817c478bd9Sstevel@tonic-gate ddi_prop_free(pci_rp); 7827c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 7837c478bd9Sstevel@tonic-gate } 7847c478bd9Sstevel@tonic-gate 7857c478bd9Sstevel@tonic-gate static int 7867c478bd9Sstevel@tonic-gate ppb_initchild(dev_info_t *child) 7877c478bd9Sstevel@tonic-gate { 7887c478bd9Sstevel@tonic-gate char name[MAXNAMELEN]; 7897c478bd9Sstevel@tonic-gate ddi_acc_handle_t config_handle; 7907c478bd9Sstevel@tonic-gate ushort_t command_preserve, command; 7917c478bd9Sstevel@tonic-gate uint_t n; 7927c478bd9Sstevel@tonic-gate ushort_t bcr; 7937c478bd9Sstevel@tonic-gate uchar_t header_type; 7947c478bd9Sstevel@tonic-gate uchar_t min_gnt, latency_timer; 7957c478bd9Sstevel@tonic-gate ppb_devstate_t *ppb; 7967c478bd9Sstevel@tonic-gate 7977c478bd9Sstevel@tonic-gate /* 7987c478bd9Sstevel@tonic-gate * Name the child 7997c478bd9Sstevel@tonic-gate */ 8007c478bd9Sstevel@tonic-gate if (ppb_name_child(child, name, MAXNAMELEN) != DDI_SUCCESS) 8017c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 8027c478bd9Sstevel@tonic-gate 8037c478bd9Sstevel@tonic-gate ddi_set_name_addr(child, name); 8047c478bd9Sstevel@tonic-gate ddi_set_parent_data(child, NULL); 8057c478bd9Sstevel@tonic-gate 8067c478bd9Sstevel@tonic-gate /* 8077c478bd9Sstevel@tonic-gate * Pseudo nodes indicate a prototype node with per-instance 8087c478bd9Sstevel@tonic-gate * properties to be merged into the real h/w device node. 8097c478bd9Sstevel@tonic-gate * The interpretation of the unit-address is DD[,F] 8107c478bd9Sstevel@tonic-gate * where DD is the device id and F is the function. 8117c478bd9Sstevel@tonic-gate */ 8127c478bd9Sstevel@tonic-gate if (ndi_dev_is_persistent_node(child) == 0) { 8137c478bd9Sstevel@tonic-gate extern int pci_allow_pseudo_children; 8147c478bd9Sstevel@tonic-gate 8157c478bd9Sstevel@tonic-gate /* 8167c478bd9Sstevel@tonic-gate * Try to merge the properties from this prototype 8177c478bd9Sstevel@tonic-gate * node into real h/w nodes. 8187c478bd9Sstevel@tonic-gate */ 8197c478bd9Sstevel@tonic-gate if (ndi_merge_node(child, ppb_name_child) == DDI_SUCCESS) { 8207c478bd9Sstevel@tonic-gate /* 8217c478bd9Sstevel@tonic-gate * Merged ok - return failure to remove the node. 8227c478bd9Sstevel@tonic-gate */ 8237c478bd9Sstevel@tonic-gate ppb_removechild(child); 8247c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 8257c478bd9Sstevel@tonic-gate } 8267c478bd9Sstevel@tonic-gate 8277c478bd9Sstevel@tonic-gate /* workaround for ddivs to run under PCI */ 8287c478bd9Sstevel@tonic-gate if (pci_allow_pseudo_children) 8297c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 8307c478bd9Sstevel@tonic-gate 8317c478bd9Sstevel@tonic-gate /* 8327c478bd9Sstevel@tonic-gate * The child was not merged into a h/w node, 8337c478bd9Sstevel@tonic-gate * but there's not much we can do with it other 8347c478bd9Sstevel@tonic-gate * than return failure to cause the node to be removed. 8357c478bd9Sstevel@tonic-gate */ 8367c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "!%s@%s: %s.conf properties not merged", 8377c478bd9Sstevel@tonic-gate ddi_driver_name(child), ddi_get_name_addr(child), 8387c478bd9Sstevel@tonic-gate ddi_driver_name(child)); 8397c478bd9Sstevel@tonic-gate ppb_removechild(child); 8407c478bd9Sstevel@tonic-gate return (DDI_NOT_WELL_FORMED); 8417c478bd9Sstevel@tonic-gate } 8427c478bd9Sstevel@tonic-gate 8437c478bd9Sstevel@tonic-gate ppb = (ppb_devstate_t *)ddi_get_soft_state(ppb_state, 8447c478bd9Sstevel@tonic-gate ddi_get_instance(ddi_get_parent(child))); 8457c478bd9Sstevel@tonic-gate 846bf8fc234Set142600 ddi_set_parent_data(child, NULL); 847bf8fc234Set142600 8487c478bd9Sstevel@tonic-gate /* 8497c478bd9Sstevel@tonic-gate * If hardware is PM capable, set up the power info structure. 8507c478bd9Sstevel@tonic-gate * This also ensures the the bus will not be off (0MHz) otherwise 8517c478bd9Sstevel@tonic-gate * system panics during a bus access. 8527c478bd9Sstevel@tonic-gate */ 8537c478bd9Sstevel@tonic-gate if (PM_CAPABLE(ppb->ppb_pwr_p)) { 8547c478bd9Sstevel@tonic-gate /* 8557c478bd9Sstevel@tonic-gate * Create a pwr_info struct for child. Bus will be 8567c478bd9Sstevel@tonic-gate * at full speed after creating info. 8577c478bd9Sstevel@tonic-gate */ 8587c478bd9Sstevel@tonic-gate pci_pwr_create_info(ppb->ppb_pwr_p, child); 8597c478bd9Sstevel@tonic-gate #ifdef DEBUG 8607c478bd9Sstevel@tonic-gate ASSERT(ppb->ppb_pwr_p->current_lvl == PM_LEVEL_B0); 8617c478bd9Sstevel@tonic-gate #endif 8627c478bd9Sstevel@tonic-gate } 8637c478bd9Sstevel@tonic-gate 8647c478bd9Sstevel@tonic-gate /* 8657c478bd9Sstevel@tonic-gate * If configuration registers were previously saved by 8667c478bd9Sstevel@tonic-gate * child (before it entered D3), then let the child do the 8677c478bd9Sstevel@tonic-gate * restore to set up the config regs as it'll first need to 8687c478bd9Sstevel@tonic-gate * power the device out of D3. 8697c478bd9Sstevel@tonic-gate */ 8707c478bd9Sstevel@tonic-gate if (ddi_prop_exists(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS, 8717c478bd9Sstevel@tonic-gate "config-regs-saved-by-child") == 1) { 8727c478bd9Sstevel@tonic-gate DEBUG2(DBG_PWR, ddi_get_parent(child), 8737c478bd9Sstevel@tonic-gate "INITCHILD: config regs to be restored by child" 8747c478bd9Sstevel@tonic-gate " for %s@%s\n", ddi_node_name(child), 8757c478bd9Sstevel@tonic-gate ddi_get_name_addr(child)); 8767c478bd9Sstevel@tonic-gate 8777c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 8787c478bd9Sstevel@tonic-gate } 8797c478bd9Sstevel@tonic-gate 8807c478bd9Sstevel@tonic-gate DEBUG2(DBG_PWR, ddi_get_parent(child), 8817c478bd9Sstevel@tonic-gate "INITCHILD: config regs setup for %s@%s\n", 8827c478bd9Sstevel@tonic-gate ddi_node_name(child), ddi_get_name_addr(child)); 8837c478bd9Sstevel@tonic-gate 8847c478bd9Sstevel@tonic-gate if (pci_config_setup(child, &config_handle) != DDI_SUCCESS) { 8857c478bd9Sstevel@tonic-gate if (PM_CAPABLE(ppb->ppb_pwr_p)) { 8867c478bd9Sstevel@tonic-gate pci_pwr_rm_info(ppb->ppb_pwr_p, child); 8877c478bd9Sstevel@tonic-gate } 8887c478bd9Sstevel@tonic-gate 8897c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 8907c478bd9Sstevel@tonic-gate } 8917c478bd9Sstevel@tonic-gate 8927c478bd9Sstevel@tonic-gate /* 8937c478bd9Sstevel@tonic-gate * Determine the configuration header type. 8947c478bd9Sstevel@tonic-gate */ 8957c478bd9Sstevel@tonic-gate header_type = pci_config_get8(config_handle, PCI_CONF_HEADER); 8967c478bd9Sstevel@tonic-gate 8977c478bd9Sstevel@tonic-gate /* 8987c478bd9Sstevel@tonic-gate * Support for the "command-preserve" property. 8997c478bd9Sstevel@tonic-gate */ 9007c478bd9Sstevel@tonic-gate command_preserve = ddi_prop_get_int(DDI_DEV_T_ANY, child, 9017c478bd9Sstevel@tonic-gate DDI_PROP_DONTPASS, "command-preserve", 0); 9027c478bd9Sstevel@tonic-gate command = pci_config_get16(config_handle, PCI_CONF_COMM); 9037c478bd9Sstevel@tonic-gate command &= (command_preserve | PCI_COMM_BACK2BACK_ENAB); 9047c478bd9Sstevel@tonic-gate command |= (ppb_command_default & ~command_preserve); 9057c478bd9Sstevel@tonic-gate pci_config_put16(config_handle, PCI_CONF_COMM, command); 9067c478bd9Sstevel@tonic-gate 9077c478bd9Sstevel@tonic-gate /* 9087c478bd9Sstevel@tonic-gate * If the device has a bus control register then program it 9097c478bd9Sstevel@tonic-gate * based on the settings in the command register. 9107c478bd9Sstevel@tonic-gate */ 9117c478bd9Sstevel@tonic-gate if ((header_type & PCI_HEADER_TYPE_M) == PCI_HEADER_ONE) { 9127c478bd9Sstevel@tonic-gate bcr = pci_config_get8(config_handle, PCI_BCNF_BCNTRL); 9137c478bd9Sstevel@tonic-gate if (ppb_command_default & PCI_COMM_PARITY_DETECT) 9147c478bd9Sstevel@tonic-gate bcr |= PCI_BCNF_BCNTRL_PARITY_ENABLE; 9157c478bd9Sstevel@tonic-gate if (ppb_command_default & PCI_COMM_SERR_ENABLE) 9167c478bd9Sstevel@tonic-gate bcr |= PCI_BCNF_BCNTRL_SERR_ENABLE; 9177c478bd9Sstevel@tonic-gate bcr |= PCI_BCNF_BCNTRL_MAST_AB_MODE; 9187c478bd9Sstevel@tonic-gate pci_config_put8(config_handle, PCI_BCNF_BCNTRL, bcr); 9197c478bd9Sstevel@tonic-gate } 9207c478bd9Sstevel@tonic-gate 9217c478bd9Sstevel@tonic-gate /* 9227c478bd9Sstevel@tonic-gate * Initialize cache-line-size configuration register if needed. 9237c478bd9Sstevel@tonic-gate */ 9247c478bd9Sstevel@tonic-gate if (ppb_set_cache_line_size_register && 9257c478bd9Sstevel@tonic-gate ddi_getprop(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS, 9267c478bd9Sstevel@tonic-gate "cache-line-size", 0) == 0) { 9277c478bd9Sstevel@tonic-gate pci_config_put8(config_handle, PCI_CONF_CACHE_LINESZ, 9287c478bd9Sstevel@tonic-gate ppb->ppb_cache_line_size); 9297c478bd9Sstevel@tonic-gate n = pci_config_get8(config_handle, PCI_CONF_CACHE_LINESZ); 9307c478bd9Sstevel@tonic-gate if (n != 0) { 9317c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, child, 9327c478bd9Sstevel@tonic-gate "cache-line-size", n); 9337c478bd9Sstevel@tonic-gate } 9347c478bd9Sstevel@tonic-gate } 9357c478bd9Sstevel@tonic-gate 9367c478bd9Sstevel@tonic-gate /* 9377c478bd9Sstevel@tonic-gate * Initialize latency timer configuration registers if needed. 9387c478bd9Sstevel@tonic-gate */ 9397c478bd9Sstevel@tonic-gate if (ppb_set_latency_timer_register && 9407c478bd9Sstevel@tonic-gate ddi_getprop(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS, 9417c478bd9Sstevel@tonic-gate "latency-timer", 0) == 0) { 9427c478bd9Sstevel@tonic-gate 9437c478bd9Sstevel@tonic-gate if ((header_type & PCI_HEADER_TYPE_M) == PCI_HEADER_ONE) { 9447c478bd9Sstevel@tonic-gate latency_timer = ppb->ppb_latency_timer; 9457c478bd9Sstevel@tonic-gate pci_config_put8(config_handle, PCI_BCNF_LATENCY_TIMER, 9467c478bd9Sstevel@tonic-gate ppb->ppb_latency_timer); 9477c478bd9Sstevel@tonic-gate } else { 9487c478bd9Sstevel@tonic-gate min_gnt = pci_config_get8(config_handle, 9497c478bd9Sstevel@tonic-gate PCI_CONF_MIN_G); 9507c478bd9Sstevel@tonic-gate latency_timer = min_gnt * 8; 9517c478bd9Sstevel@tonic-gate } 9527c478bd9Sstevel@tonic-gate pci_config_put8(config_handle, PCI_CONF_LATENCY_TIMER, 9537c478bd9Sstevel@tonic-gate latency_timer); 9547c478bd9Sstevel@tonic-gate n = pci_config_get8(config_handle, PCI_CONF_LATENCY_TIMER); 9557c478bd9Sstevel@tonic-gate if (n != 0) { 9567c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, child, 9577c478bd9Sstevel@tonic-gate "latency-timer", n); 9587c478bd9Sstevel@tonic-gate } 9597c478bd9Sstevel@tonic-gate } 9607c478bd9Sstevel@tonic-gate 9617c478bd9Sstevel@tonic-gate /* 962bf8fc234Set142600 * SPARC PCIe FMA specific 963bf8fc234Set142600 * 964bf8fc234Set142600 * Note: parent_data for parent is created only if this is sparc PCI-E 965bf8fc234Set142600 * platform, for which, SG take a different route to handle device 966bf8fc234Set142600 * errors. 967bf8fc234Set142600 */ 968bf8fc234Set142600 if (ppb->parent_bus == PCIE_PCIECAP_DEV_TYPE_PCIE_DEV) { 969c0da6274SZhi-Jun Robin Fu if (pcie_init_cfghdl(child) != DDI_SUCCESS) { 970651d856bSrameshc pci_config_teardown(&config_handle); 971bf8fc234Set142600 return (DDI_FAILURE); 972bf8fc234Set142600 } 973fc256490SJason Beloro pcie_init_dom(child); 974651d856bSrameshc } 975bf8fc234Set142600 976bf8fc234Set142600 /* 9777c478bd9Sstevel@tonic-gate * Check to see if the XMITS/PCI-X workaround applies. 9787c478bd9Sstevel@tonic-gate */ 9797c478bd9Sstevel@tonic-gate n = ddi_getprop(DDI_DEV_T_ANY, child, DDI_PROP_NOTPROM, 9807c478bd9Sstevel@tonic-gate "pcix-update-cmd-reg", -1); 9817c478bd9Sstevel@tonic-gate 9827c478bd9Sstevel@tonic-gate if (n != -1) { 9837c478bd9Sstevel@tonic-gate extern void pcix_set_cmd_reg(dev_info_t *child, uint16_t value); 9847c478bd9Sstevel@tonic-gate DEBUG1(DBG_INIT_CLD, child, "Turning on XMITS NCPQ " 9857c478bd9Sstevel@tonic-gate "Workaround: value = %x\n", n); 9867c478bd9Sstevel@tonic-gate pcix_set_cmd_reg(child, n); 9877c478bd9Sstevel@tonic-gate } 988651d856bSrameshc pci_config_teardown(&config_handle); 989bf8fc234Set142600 return (DDI_SUCCESS); 990e51949e6Sdduvall } 9913d9c56a1Set142600 992bf8fc234Set142600 static void 993bf8fc234Set142600 ppb_uninitchild(dev_info_t *child) 994bf8fc234Set142600 { 995bf8fc234Set142600 ppb_devstate_t *ppb; 996e51949e6Sdduvall 997bf8fc234Set142600 ppb = (ppb_devstate_t *)ddi_get_soft_state(ppb_state, 998bf8fc234Set142600 ddi_get_instance(ddi_get_parent(child))); 999e51949e6Sdduvall 1000bf8fc234Set142600 /* 1001bf8fc234Set142600 * SG OPL FMA specific 1002bf8fc234Set142600 */ 1003fc256490SJason Beloro if (ppb->parent_bus == PCIE_PCIECAP_DEV_TYPE_PCIE_DEV) { 1004fc256490SJason Beloro pcie_fini_dom(child); 1005c0da6274SZhi-Jun Robin Fu pcie_fini_cfghdl(child); 1006fc256490SJason Beloro } 1007bf8fc234Set142600 1008bf8fc234Set142600 ppb_removechild(child); 10097c478bd9Sstevel@tonic-gate } 10107c478bd9Sstevel@tonic-gate 10117c478bd9Sstevel@tonic-gate static void 10127c478bd9Sstevel@tonic-gate ppb_removechild(dev_info_t *dip) 10137c478bd9Sstevel@tonic-gate { 10147c478bd9Sstevel@tonic-gate ppb_devstate_t *ppb; 10157c478bd9Sstevel@tonic-gate 10167c478bd9Sstevel@tonic-gate ppb = (ppb_devstate_t *)ddi_get_soft_state(ppb_state, 10177c478bd9Sstevel@tonic-gate ddi_get_instance(ddi_get_parent(dip))); 10187c478bd9Sstevel@tonic-gate 10197c478bd9Sstevel@tonic-gate if (PM_CAPABLE(ppb->ppb_pwr_p)) { 10207c478bd9Sstevel@tonic-gate 10217c478bd9Sstevel@tonic-gate DEBUG2(DBG_PWR, ddi_get_parent(dip), 10227c478bd9Sstevel@tonic-gate "UNINITCHILD: removing pwr_info for %s@%s\n", 10237c478bd9Sstevel@tonic-gate ddi_node_name(dip), ddi_get_name_addr(dip)); 10247c478bd9Sstevel@tonic-gate pci_pwr_rm_info(ppb->ppb_pwr_p, dip); 10257c478bd9Sstevel@tonic-gate } 10267c478bd9Sstevel@tonic-gate 10277c478bd9Sstevel@tonic-gate ddi_set_name_addr(dip, NULL); 10287c478bd9Sstevel@tonic-gate 10297c478bd9Sstevel@tonic-gate /* 10307c478bd9Sstevel@tonic-gate * Strip the node to properly convert it back to prototype form 10317c478bd9Sstevel@tonic-gate */ 10327c478bd9Sstevel@tonic-gate ddi_remove_minor_node(dip, NULL); 10337c478bd9Sstevel@tonic-gate 10347c478bd9Sstevel@tonic-gate impl_rem_dev_props(dip); 10357c478bd9Sstevel@tonic-gate } 10367c478bd9Sstevel@tonic-gate 10377c478bd9Sstevel@tonic-gate /* 10387c478bd9Sstevel@tonic-gate * If bridge is PM capable, set up PM state for nexus. 10397c478bd9Sstevel@tonic-gate */ 10407c478bd9Sstevel@tonic-gate static void 10417c478bd9Sstevel@tonic-gate ppb_pwr_setup(ppb_devstate_t *ppb, dev_info_t *pdip) 10427c478bd9Sstevel@tonic-gate { 10437c478bd9Sstevel@tonic-gate char *comp_array[5]; 10447c478bd9Sstevel@tonic-gate int i; 10457c478bd9Sstevel@tonic-gate ddi_acc_handle_t conf_hdl; 10467c478bd9Sstevel@tonic-gate uint8_t pmcsr_bse; 10477c478bd9Sstevel@tonic-gate uint16_t pmcap; 10487c478bd9Sstevel@tonic-gate 10497c478bd9Sstevel@tonic-gate /* 10507c478bd9Sstevel@tonic-gate * Determine if bridge is PM capable. If not, leave ppb_pwr_p NULL 10517c478bd9Sstevel@tonic-gate * and return. 10527c478bd9Sstevel@tonic-gate */ 10537c478bd9Sstevel@tonic-gate if (pci_config_setup(pdip, &ppb->ppb_conf_hdl) != DDI_SUCCESS) { 10547c478bd9Sstevel@tonic-gate 10557c478bd9Sstevel@tonic-gate return; 10567c478bd9Sstevel@tonic-gate } 10577c478bd9Sstevel@tonic-gate 10587c478bd9Sstevel@tonic-gate conf_hdl = ppb->ppb_conf_hdl; 10597c478bd9Sstevel@tonic-gate 10607c478bd9Sstevel@tonic-gate /* 106127255037Spjha * Locate and store the power management cap_ptr for future references. 10627c478bd9Sstevel@tonic-gate */ 106327255037Spjha if ((PCI_CAP_LOCATE(conf_hdl, PCI_CAP_ID_PM, &ppb->ppb_pm_cap_ptr)) 106427255037Spjha == DDI_FAILURE) { 10657c478bd9Sstevel@tonic-gate DEBUG0(DBG_PWR, pdip, "bridge does not support PM. PCI" 10667c478bd9Sstevel@tonic-gate " PM data structure not found in config header\n"); 10677c478bd9Sstevel@tonic-gate pci_config_teardown(&conf_hdl); 10687c478bd9Sstevel@tonic-gate 10697c478bd9Sstevel@tonic-gate return; 10707c478bd9Sstevel@tonic-gate } 10717c478bd9Sstevel@tonic-gate 10727c478bd9Sstevel@tonic-gate /* 10737c478bd9Sstevel@tonic-gate * Allocate PM state structure for ppb. 10747c478bd9Sstevel@tonic-gate */ 10757c478bd9Sstevel@tonic-gate ppb->ppb_pwr_p = (pci_pwr_t *) 10767c478bd9Sstevel@tonic-gate kmem_zalloc(sizeof (pci_pwr_t), KM_SLEEP); 10777c478bd9Sstevel@tonic-gate ppb->ppb_pwr_p->pwr_fp = 0; 10787c478bd9Sstevel@tonic-gate 107927255037Spjha pmcsr_bse = PCI_CAP_GET8(conf_hdl, NULL, ppb->ppb_pm_cap_ptr, 108027255037Spjha PCI_PMCSR_BSE); 10817c478bd9Sstevel@tonic-gate 108227255037Spjha pmcap = PCI_CAP_GET16(conf_hdl, NULL, ppb->ppb_pm_cap_ptr, 108327255037Spjha PCI_PMCAP); 10847c478bd9Sstevel@tonic-gate 1085dc5d169bSpjha if (pmcap == PCI_CAP_EINVAL16 || pmcsr_bse == PCI_CAP_EINVAL8) { 108627255037Spjha pci_config_teardown(&conf_hdl); 108727255037Spjha return; 108827255037Spjha } 10897c478bd9Sstevel@tonic-gate 10907c478bd9Sstevel@tonic-gate if (pmcap & PCI_PMCAP_D1) { 10917c478bd9Sstevel@tonic-gate DEBUG0(DBG_PWR, pdip, "setup: B1 state supported\n"); 10927c478bd9Sstevel@tonic-gate ppb->ppb_pwr_p->pwr_flags |= PCI_PWR_B1_CAPABLE; 10937c478bd9Sstevel@tonic-gate } else { 10947c478bd9Sstevel@tonic-gate DEBUG0(DBG_PWR, pdip, "setup: B1 state NOT supported\n"); 10957c478bd9Sstevel@tonic-gate } 10967c478bd9Sstevel@tonic-gate if (pmcap & PCI_PMCAP_D2) { 10977c478bd9Sstevel@tonic-gate DEBUG0(DBG_PWR, pdip, "setup: B2 state supported\n"); 10987c478bd9Sstevel@tonic-gate ppb->ppb_pwr_p->pwr_flags |= PCI_PWR_B2_CAPABLE; 10997c478bd9Sstevel@tonic-gate } else { 11007c478bd9Sstevel@tonic-gate DEBUG0(DBG_PWR, pdip, "setup: B2 via D2 NOT supported\n"); 11017c478bd9Sstevel@tonic-gate } 11027c478bd9Sstevel@tonic-gate 11037c478bd9Sstevel@tonic-gate if (pmcsr_bse & PCI_PMCSR_BSE_BPCC_EN) { 11047c478bd9Sstevel@tonic-gate DEBUG0(DBG_PWR, pdip, 11057c478bd9Sstevel@tonic-gate "setup: bridge power/clock control enable\n"); 11067c478bd9Sstevel@tonic-gate } else { 11077c478bd9Sstevel@tonic-gate DEBUG0(DBG_PWR, pdip, 11087c478bd9Sstevel@tonic-gate "setup: bridge power/clock control disabled\n"); 11097c478bd9Sstevel@tonic-gate 11107c478bd9Sstevel@tonic-gate kmem_free(ppb->ppb_pwr_p, sizeof (pci_pwr_t)); 11117c478bd9Sstevel@tonic-gate ppb->ppb_pwr_p = NULL; 11127c478bd9Sstevel@tonic-gate pci_config_teardown(&conf_hdl); 11137c478bd9Sstevel@tonic-gate 11147c478bd9Sstevel@tonic-gate return; 11157c478bd9Sstevel@tonic-gate } 11167c478bd9Sstevel@tonic-gate 11177c478bd9Sstevel@tonic-gate /* 11187c478bd9Sstevel@tonic-gate * PCI states D0 and D3 always are supported for normal PCI 11197c478bd9Sstevel@tonic-gate * devices. D1 and D2 are optional which are checked for above. 11207c478bd9Sstevel@tonic-gate * Bridge function states D0-D3 correspond to secondary bus states 11217c478bd9Sstevel@tonic-gate * B0-B3, EXCEPT if PCI_PMCSR_BSE_B2_B3 is set. In this case, setting 11227c478bd9Sstevel@tonic-gate * the bridge function to D3 will set the bridge bus to state B2 instead 11237c478bd9Sstevel@tonic-gate * of B3. D2 will not correspond to B2 (and in fact, probably 11247c478bd9Sstevel@tonic-gate * won't be D2 capable). Implicitly, this means that if 11257c478bd9Sstevel@tonic-gate * PCI_PMCSR_BSE_B2_B3 is set, the bus will not be B3 capable. 11267c478bd9Sstevel@tonic-gate */ 11277c478bd9Sstevel@tonic-gate if (pmcsr_bse & PCI_PMCSR_BSE_B2_B3) { 11287c478bd9Sstevel@tonic-gate ppb->ppb_pwr_p->pwr_flags |= PCI_PWR_B2_CAPABLE; 11297c478bd9Sstevel@tonic-gate DEBUG0(DBG_PWR, pdip, "B2 supported via D3\n"); 11307c478bd9Sstevel@tonic-gate } else { 11317c478bd9Sstevel@tonic-gate ppb->ppb_pwr_p->pwr_flags |= PCI_PWR_B3_CAPABLE; 11327c478bd9Sstevel@tonic-gate DEBUG0(DBG_PWR, pdip, "B3 supported via D3\n"); 11337c478bd9Sstevel@tonic-gate } 11347c478bd9Sstevel@tonic-gate 11357c478bd9Sstevel@tonic-gate ppb->ppb_pwr_p->pwr_dip = pdip; 11367c478bd9Sstevel@tonic-gate mutex_init(&ppb->ppb_pwr_p->pwr_mutex, NULL, MUTEX_DRIVER, NULL); 11377c478bd9Sstevel@tonic-gate 11387c478bd9Sstevel@tonic-gate i = 0; 11397c478bd9Sstevel@tonic-gate comp_array[i++] = "NAME=PCI bridge PM"; 11407c478bd9Sstevel@tonic-gate if (ppb->ppb_pwr_p->pwr_flags & PCI_PWR_B3_CAPABLE) { 11417c478bd9Sstevel@tonic-gate comp_array[i++] = "0=Clock/Power Off (B3)"; 11427c478bd9Sstevel@tonic-gate } 11437c478bd9Sstevel@tonic-gate if (ppb->ppb_pwr_p->pwr_flags & PCI_PWR_B2_CAPABLE) { 11447c478bd9Sstevel@tonic-gate comp_array[i++] = "1=Clock Off (B2)"; 11457c478bd9Sstevel@tonic-gate } 11467c478bd9Sstevel@tonic-gate if (ppb->ppb_pwr_p->pwr_flags & PCI_PWR_B1_CAPABLE) { 11477c478bd9Sstevel@tonic-gate comp_array[i++] = "2=Bus Inactive (B1)"; 11487c478bd9Sstevel@tonic-gate } 11497c478bd9Sstevel@tonic-gate comp_array[i++] = "3=Full Power (B0)"; 11507c478bd9Sstevel@tonic-gate 11517c478bd9Sstevel@tonic-gate /* 11527c478bd9Sstevel@tonic-gate * Create pm-components property. It does not already exist. 11537c478bd9Sstevel@tonic-gate */ 11547c478bd9Sstevel@tonic-gate if (ddi_prop_update_string_array(DDI_DEV_T_NONE, pdip, 11557c478bd9Sstevel@tonic-gate "pm-components", comp_array, i) != DDI_PROP_SUCCESS) { 11567c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, 11577c478bd9Sstevel@tonic-gate "%s%d pm-components prop update failed", 11587c478bd9Sstevel@tonic-gate ddi_driver_name(pdip), ddi_get_instance(pdip)); 11597c478bd9Sstevel@tonic-gate pci_config_teardown(&conf_hdl); 11607c478bd9Sstevel@tonic-gate mutex_destroy(&ppb->ppb_pwr_p->pwr_mutex); 11617c478bd9Sstevel@tonic-gate kmem_free(ppb->ppb_pwr_p, sizeof (pci_pwr_t)); 11627c478bd9Sstevel@tonic-gate ppb->ppb_pwr_p = NULL; 11637c478bd9Sstevel@tonic-gate 11647c478bd9Sstevel@tonic-gate return; 11657c478bd9Sstevel@tonic-gate } 11667c478bd9Sstevel@tonic-gate 11677c478bd9Sstevel@tonic-gate if (ddi_prop_create(DDI_DEV_T_NONE, pdip, DDI_PROP_CANSLEEP, 11687c478bd9Sstevel@tonic-gate "pm-want-child-notification?", NULL, NULL) != DDI_PROP_SUCCESS) { 11697c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, 11707c478bd9Sstevel@tonic-gate "%s%d fail to create pm-want-child-notification? prop", 11717c478bd9Sstevel@tonic-gate ddi_driver_name(pdip), ddi_get_instance(pdip)); 11727c478bd9Sstevel@tonic-gate 11737c478bd9Sstevel@tonic-gate (void) ddi_prop_remove(DDI_DEV_T_NONE, pdip, "pm-components"); 11747c478bd9Sstevel@tonic-gate pci_config_teardown(&conf_hdl); 11757c478bd9Sstevel@tonic-gate mutex_destroy(&ppb->ppb_pwr_p->pwr_mutex); 11767c478bd9Sstevel@tonic-gate kmem_free(ppb->ppb_pwr_p, sizeof (pci_pwr_t)); 11777c478bd9Sstevel@tonic-gate ppb->ppb_pwr_p = NULL; 11787c478bd9Sstevel@tonic-gate 11797c478bd9Sstevel@tonic-gate return; 11807c478bd9Sstevel@tonic-gate } 11817c478bd9Sstevel@tonic-gate 11827c478bd9Sstevel@tonic-gate ppb->ppb_pwr_p->current_lvl = 11837c478bd9Sstevel@tonic-gate pci_pwr_current_lvl(ppb->ppb_pwr_p); 11847c478bd9Sstevel@tonic-gate } 11857c478bd9Sstevel@tonic-gate 11867c478bd9Sstevel@tonic-gate /* 11877c478bd9Sstevel@tonic-gate * Remove PM state for nexus. 11887c478bd9Sstevel@tonic-gate */ 11897c478bd9Sstevel@tonic-gate static void 11907c478bd9Sstevel@tonic-gate ppb_pwr_teardown(ppb_devstate_t *ppb, dev_info_t *dip) 11917c478bd9Sstevel@tonic-gate { 11927c478bd9Sstevel@tonic-gate int low_lvl; 11937c478bd9Sstevel@tonic-gate 11947c478bd9Sstevel@tonic-gate /* 11957c478bd9Sstevel@tonic-gate * Determine the lowest power level supported. 11967c478bd9Sstevel@tonic-gate */ 11977c478bd9Sstevel@tonic-gate if (ppb->ppb_pwr_p->pwr_flags & PCI_PWR_B3_CAPABLE) { 11987c478bd9Sstevel@tonic-gate low_lvl = PM_LEVEL_B3; 11997c478bd9Sstevel@tonic-gate } else { 12007c478bd9Sstevel@tonic-gate low_lvl = PM_LEVEL_B2; 12017c478bd9Sstevel@tonic-gate } 12027c478bd9Sstevel@tonic-gate 12037c478bd9Sstevel@tonic-gate if (pm_lower_power(dip, PCI_PM_COMP_0, low_lvl) != DDI_SUCCESS) { 12047c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d failed to lower power", 12057c478bd9Sstevel@tonic-gate ddi_driver_name(dip), ddi_get_instance(dip)); 12067c478bd9Sstevel@tonic-gate } 12077c478bd9Sstevel@tonic-gate 12087c478bd9Sstevel@tonic-gate pci_config_teardown(&ppb->ppb_conf_hdl); 12097c478bd9Sstevel@tonic-gate mutex_destroy(&ppb->ppb_pwr_p->pwr_mutex); 12107c478bd9Sstevel@tonic-gate kmem_free(ppb->ppb_pwr_p, sizeof (pci_pwr_t)); 12117c478bd9Sstevel@tonic-gate 12127c478bd9Sstevel@tonic-gate if (ddi_prop_remove(DDI_DEV_T_NONE, dip, "pm-components") != 12137c478bd9Sstevel@tonic-gate DDI_PROP_SUCCESS) { 12147c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d unable to remove prop pm-components", 12157c478bd9Sstevel@tonic-gate ddi_driver_name(dip), ddi_get_instance(dip)); 12167c478bd9Sstevel@tonic-gate } 12177c478bd9Sstevel@tonic-gate 12187c478bd9Sstevel@tonic-gate if (ddi_prop_remove(DDI_DEV_T_NONE, dip, 12197c478bd9Sstevel@tonic-gate "pm-want-child-notification?") != DDI_PROP_SUCCESS) { 12207c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, 12217c478bd9Sstevel@tonic-gate "%s%d unable to remove prop pm-want_child_notification?", 12227c478bd9Sstevel@tonic-gate ddi_driver_name(dip), ddi_get_instance(dip)); 12237c478bd9Sstevel@tonic-gate } 12247c478bd9Sstevel@tonic-gate } 12257c478bd9Sstevel@tonic-gate 12267c478bd9Sstevel@tonic-gate /* 12277c478bd9Sstevel@tonic-gate * Examine the pmcsr register and return the software defined 12287c478bd9Sstevel@tonic-gate * state (the difference being whether D3 means B2 or B3). 12297c478bd9Sstevel@tonic-gate */ 12307c478bd9Sstevel@tonic-gate int 12317c478bd9Sstevel@tonic-gate pci_pwr_current_lvl(pci_pwr_t *pwr_p) 12327c478bd9Sstevel@tonic-gate { 12337c478bd9Sstevel@tonic-gate ppb_devstate_t *ppb; 12347c478bd9Sstevel@tonic-gate uint16_t pmcsr; 12357c478bd9Sstevel@tonic-gate 12367c478bd9Sstevel@tonic-gate /* 12377c478bd9Sstevel@tonic-gate * Find out current power level 12387c478bd9Sstevel@tonic-gate */ 12397c478bd9Sstevel@tonic-gate ppb = (ppb_devstate_t *)ddi_get_soft_state(ppb_state, 12407c478bd9Sstevel@tonic-gate ddi_get_instance(pwr_p->pwr_dip)); 12417c478bd9Sstevel@tonic-gate 124227255037Spjha if ((pmcsr = PCI_CAP_GET16(ppb->ppb_conf_hdl, NULL, 1243dc5d169bSpjha ppb->ppb_pm_cap_ptr, PCI_PMCSR)) == PCI_CAP_EINVAL16) 124427255037Spjha return (DDI_FAILURE); 12457c478bd9Sstevel@tonic-gate 12467c478bd9Sstevel@tonic-gate switch (pmcsr & PCI_PMCSR_STATE_MASK) { 12477c478bd9Sstevel@tonic-gate case PCI_PMCSR_D0: 12487c478bd9Sstevel@tonic-gate 12497c478bd9Sstevel@tonic-gate return (PM_LEVEL_B0); 12507c478bd9Sstevel@tonic-gate case PCI_PMCSR_D1: 12517c478bd9Sstevel@tonic-gate 12527c478bd9Sstevel@tonic-gate return (PM_LEVEL_B1); 12537c478bd9Sstevel@tonic-gate case PCI_PMCSR_D2: 12547c478bd9Sstevel@tonic-gate 12557c478bd9Sstevel@tonic-gate return (PM_LEVEL_B2); 12567c478bd9Sstevel@tonic-gate case PCI_PMCSR_D3HOT: 12577c478bd9Sstevel@tonic-gate if ((ppb->ppb_pwr_p->pwr_flags & PCI_PWR_B3_CAPABLE) == 0) { 12587c478bd9Sstevel@tonic-gate 12597c478bd9Sstevel@tonic-gate return (PM_LEVEL_B2); 12607c478bd9Sstevel@tonic-gate } else { 12617c478bd9Sstevel@tonic-gate 12627c478bd9Sstevel@tonic-gate return (PM_LEVEL_B3); 12637c478bd9Sstevel@tonic-gate } 12647c478bd9Sstevel@tonic-gate } 12657c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 1266f47a9c50Smathue return (PM_LEVEL_B3); 12677c478bd9Sstevel@tonic-gate } 12687c478bd9Sstevel@tonic-gate 12697c478bd9Sstevel@tonic-gate /* 12707c478bd9Sstevel@tonic-gate * Power entry point. Called by the PM framework to change the 12717c478bd9Sstevel@tonic-gate * current power state of the bus. This function must first verify that 12727c478bd9Sstevel@tonic-gate * the requested power change is still valid. 12737c478bd9Sstevel@tonic-gate */ 12747c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 12757c478bd9Sstevel@tonic-gate static int 12767c478bd9Sstevel@tonic-gate ppb_pwr(dev_info_t *dip, int component, int lvl) 12777c478bd9Sstevel@tonic-gate { 12787c478bd9Sstevel@tonic-gate ppb_devstate_t *ppb; 12797c478bd9Sstevel@tonic-gate uint16_t pmcsr; 12807c478bd9Sstevel@tonic-gate char *str; 12817c478bd9Sstevel@tonic-gate int lowest_lvl; 12827c478bd9Sstevel@tonic-gate int old_lvl; 12837c478bd9Sstevel@tonic-gate int new_lvl; 12847c478bd9Sstevel@tonic-gate 12857c478bd9Sstevel@tonic-gate ppb = (ppb_devstate_t *)ddi_get_soft_state(ppb_state, 12867c478bd9Sstevel@tonic-gate ddi_get_instance(dip)); 12877c478bd9Sstevel@tonic-gate if (ppb == NULL) { 12887c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d ppb_pwr: can't get soft state", 12897c478bd9Sstevel@tonic-gate ddi_driver_name(dip), ddi_get_instance(dip)); 12907c478bd9Sstevel@tonic-gate 12917c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 12927c478bd9Sstevel@tonic-gate } 12937c478bd9Sstevel@tonic-gate 12947c478bd9Sstevel@tonic-gate DEBUG1(DBG_PWR, dip, "ppb_pwr(): ENTER level = %d\n", lvl); 12957c478bd9Sstevel@tonic-gate 12967c478bd9Sstevel@tonic-gate mutex_enter(&ppb->ppb_pwr_p->pwr_mutex); 12977c478bd9Sstevel@tonic-gate 12987c478bd9Sstevel@tonic-gate /* 12997c478bd9Sstevel@tonic-gate * Find out if the power setting is possible. If it is not, 13007c478bd9Sstevel@tonic-gate * set component busy and return failure. If it is possible, 13017c478bd9Sstevel@tonic-gate * and it is the lowest pwr setting possible, set component 13027c478bd9Sstevel@tonic-gate * busy so that the framework does not try to lower any further. 13037c478bd9Sstevel@tonic-gate */ 13047c478bd9Sstevel@tonic-gate lowest_lvl = pci_pwr_new_lvl(ppb->ppb_pwr_p); 13057c478bd9Sstevel@tonic-gate if (lowest_lvl > lvl) { 13067c478bd9Sstevel@tonic-gate pci_pwr_component_busy(ppb->ppb_pwr_p); 13077c478bd9Sstevel@tonic-gate DEBUG2(DBG_PWR, dip, "ppb_pwr: failing power request " 13087c478bd9Sstevel@tonic-gate "lowest allowed is %d requested is %d\n", 13097c478bd9Sstevel@tonic-gate lowest_lvl, lvl); 13107c478bd9Sstevel@tonic-gate mutex_exit(&ppb->ppb_pwr_p->pwr_mutex); 13117c478bd9Sstevel@tonic-gate 13127c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 13137c478bd9Sstevel@tonic-gate } else if (lowest_lvl == lvl) { 13147c478bd9Sstevel@tonic-gate pci_pwr_component_busy(ppb->ppb_pwr_p); 13157c478bd9Sstevel@tonic-gate } else { 13167c478bd9Sstevel@tonic-gate pci_pwr_component_idle(ppb->ppb_pwr_p); 13177c478bd9Sstevel@tonic-gate } 13187c478bd9Sstevel@tonic-gate 131927255037Spjha if ((pmcsr = PCI_CAP_GET16(ppb->ppb_conf_hdl, NULL, 1320dc5d169bSpjha ppb->ppb_pm_cap_ptr, PCI_PMCSR)) == PCI_CAP_EINVAL16) 132127255037Spjha return (DDI_FAILURE); 13227c478bd9Sstevel@tonic-gate 13237c478bd9Sstevel@tonic-gate /* 13247c478bd9Sstevel@tonic-gate * Save the current power level. This is the actual function level, 13257c478bd9Sstevel@tonic-gate * not the translated bridge level stored in pwr_p->current_lvl 13267c478bd9Sstevel@tonic-gate */ 13277c478bd9Sstevel@tonic-gate old_lvl = pmcsr & PCI_PMCSR_STATE_MASK; 13287c478bd9Sstevel@tonic-gate 13297c478bd9Sstevel@tonic-gate pmcsr &= ~PCI_PMCSR_STATE_MASK; 13307c478bd9Sstevel@tonic-gate switch (lvl) { 13317c478bd9Sstevel@tonic-gate case PM_LEVEL_B0: 13327c478bd9Sstevel@tonic-gate str = "PM_LEVEL_B0 (full speed)"; 13337c478bd9Sstevel@tonic-gate pmcsr |= PCI_PMCSR_D0; 13347c478bd9Sstevel@tonic-gate break; 13357c478bd9Sstevel@tonic-gate case PM_LEVEL_B1: 13367c478bd9Sstevel@tonic-gate str = "PM_LEVEL_B1 (light sleep. No bus traffic allowed)"; 13377c478bd9Sstevel@tonic-gate if ((ppb->ppb_pwr_p->pwr_flags & PCI_PWR_B1_CAPABLE) == 0) { 13387c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d PCI PM state B1 not supported", 13397c478bd9Sstevel@tonic-gate ddi_driver_name(dip), ddi_get_instance(dip)); 13407c478bd9Sstevel@tonic-gate 13417c478bd9Sstevel@tonic-gate mutex_exit(&ppb->ppb_pwr_p->pwr_mutex); 13427c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 13437c478bd9Sstevel@tonic-gate } 13447c478bd9Sstevel@tonic-gate pmcsr |= PCI_PMCSR_D1; 13457c478bd9Sstevel@tonic-gate break; 13467c478bd9Sstevel@tonic-gate case PM_LEVEL_B2: 13477c478bd9Sstevel@tonic-gate str = "PM_LEVEL_B2 (clock off)"; 13487c478bd9Sstevel@tonic-gate if ((ppb->ppb_pwr_p->pwr_flags & PCI_PWR_B2_CAPABLE) == 0) { 13497c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d PM state B2 not supported...", 13507c478bd9Sstevel@tonic-gate ddi_driver_name(dip), 13517c478bd9Sstevel@tonic-gate ddi_get_instance(dip)); 13527c478bd9Sstevel@tonic-gate mutex_exit(&ppb->ppb_pwr_p->pwr_mutex); 13537c478bd9Sstevel@tonic-gate 13547c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 13557c478bd9Sstevel@tonic-gate } 13567c478bd9Sstevel@tonic-gate 13577c478bd9Sstevel@tonic-gate if ((ppb->ppb_pwr_p->pwr_flags & PCI_PWR_B3_CAPABLE) == 0) { 13587c478bd9Sstevel@tonic-gate /* 13597c478bd9Sstevel@tonic-gate * If B3 isn't supported, use D3 for B2 to avoid the 13607c478bd9Sstevel@tonic-gate * possible case that D2 for B2 isn't supported. 13617c478bd9Sstevel@tonic-gate * Saves and extra check and state flag.. 13627c478bd9Sstevel@tonic-gate */ 13637c478bd9Sstevel@tonic-gate pmcsr |= PCI_PMCSR_D3HOT; 13647c478bd9Sstevel@tonic-gate } else { 13657c478bd9Sstevel@tonic-gate pmcsr |= PCI_PMCSR_D2; 13667c478bd9Sstevel@tonic-gate } 13677c478bd9Sstevel@tonic-gate break; 13687c478bd9Sstevel@tonic-gate case PM_LEVEL_B3: 13697c478bd9Sstevel@tonic-gate str = "PM_LEVEL_B30 (clock and power off)"; 13707c478bd9Sstevel@tonic-gate if ((ppb->ppb_pwr_p->pwr_flags & PCI_PWR_B3_CAPABLE) == 0) { 13717c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d PM state B3 not supported...", 13727c478bd9Sstevel@tonic-gate ddi_driver_name(dip), 13737c478bd9Sstevel@tonic-gate ddi_get_instance(dip)); 13747c478bd9Sstevel@tonic-gate mutex_exit(&ppb->ppb_pwr_p->pwr_mutex); 13757c478bd9Sstevel@tonic-gate 13767c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 13777c478bd9Sstevel@tonic-gate } 13787c478bd9Sstevel@tonic-gate pmcsr |= PCI_PMCSR_D3HOT; 13797c478bd9Sstevel@tonic-gate 13807c478bd9Sstevel@tonic-gate break; 13817c478bd9Sstevel@tonic-gate 13827c478bd9Sstevel@tonic-gate default: 13837c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d Unknown PM state %d", 13847c478bd9Sstevel@tonic-gate ddi_driver_name(dip), ddi_get_instance(dip), lvl); 13857c478bd9Sstevel@tonic-gate mutex_exit(&ppb->ppb_pwr_p->pwr_mutex); 13867c478bd9Sstevel@tonic-gate 13877c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 13887c478bd9Sstevel@tonic-gate } 13897c478bd9Sstevel@tonic-gate 13907c478bd9Sstevel@tonic-gate new_lvl = pmcsr & PCI_PMCSR_STATE_MASK; 13917c478bd9Sstevel@tonic-gate 13927c478bd9Sstevel@tonic-gate /* 13937c478bd9Sstevel@tonic-gate * Save config regs if going into HW state D3 (B2 or B3) 13947c478bd9Sstevel@tonic-gate */ 13957c478bd9Sstevel@tonic-gate if ((old_lvl != PCI_PMCSR_D3HOT) && (new_lvl == PCI_PMCSR_D3HOT)) { 13967c478bd9Sstevel@tonic-gate DEBUG0(DBG_PWR, dip, "ppb_pwr(): SAVING CONFIG REGS\n"); 13977c478bd9Sstevel@tonic-gate if (pci_save_config_regs(dip) != DDI_SUCCESS) { 13987c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d Save config regs failed", 13997c478bd9Sstevel@tonic-gate ddi_driver_name(dip), ddi_get_instance(dip)); 14007c478bd9Sstevel@tonic-gate mutex_exit(&ppb->ppb_pwr_p->pwr_mutex); 14017c478bd9Sstevel@tonic-gate 14027c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 14037c478bd9Sstevel@tonic-gate } 14047c478bd9Sstevel@tonic-gate } 14057c478bd9Sstevel@tonic-gate 140627255037Spjha PCI_CAP_PUT16(ppb->ppb_conf_hdl, NULL, ppb->ppb_pm_cap_ptr, PCI_PMCSR, 140727255037Spjha pmcsr); 14087c478bd9Sstevel@tonic-gate 14097c478bd9Sstevel@tonic-gate /* 14107c478bd9Sstevel@tonic-gate * No bus transactions should occur without waiting for 14117c478bd9Sstevel@tonic-gate * settle time specified in PCI PM spec rev 2.1 sec 5.6.1 14127c478bd9Sstevel@tonic-gate * To make things simple, just use the max time specified for 14137c478bd9Sstevel@tonic-gate * all state transitions. 14147c478bd9Sstevel@tonic-gate */ 14157c478bd9Sstevel@tonic-gate delay(drv_usectohz(PCI_CLK_SETTLE_TIME)); 14167c478bd9Sstevel@tonic-gate 14177c478bd9Sstevel@tonic-gate /* 14187c478bd9Sstevel@tonic-gate * Restore configuration registers if coming out of HW state D3 14197c478bd9Sstevel@tonic-gate */ 14207c478bd9Sstevel@tonic-gate if ((old_lvl == PCI_PMCSR_D3HOT) && (new_lvl != PCI_PMCSR_D3HOT)) { 14217c478bd9Sstevel@tonic-gate DEBUG0(DBG_PWR, dip, "ppb_pwr(): RESTORING CONFIG REGS\n"); 14227c478bd9Sstevel@tonic-gate if (pci_restore_config_regs(dip) != DDI_SUCCESS) { 14237c478bd9Sstevel@tonic-gate panic("%s%d restore config regs failed", 14247c478bd9Sstevel@tonic-gate ddi_driver_name(dip), ddi_get_instance(dip)); 14257c478bd9Sstevel@tonic-gate } 14267c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 14277c478bd9Sstevel@tonic-gate } 14287c478bd9Sstevel@tonic-gate 14297c478bd9Sstevel@tonic-gate ppb->ppb_pwr_p->current_lvl = lvl; 14307c478bd9Sstevel@tonic-gate 14317c478bd9Sstevel@tonic-gate mutex_exit(&ppb->ppb_pwr_p->pwr_mutex); 14327c478bd9Sstevel@tonic-gate 14337c478bd9Sstevel@tonic-gate DEBUG1(DBG_PWR, dip, "ppb_set_pwr: set PM state to %s\n\n", str); 14347c478bd9Sstevel@tonic-gate 14357c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 14367c478bd9Sstevel@tonic-gate } 14377c478bd9Sstevel@tonic-gate 14387c478bd9Sstevel@tonic-gate /* 14397c478bd9Sstevel@tonic-gate * Initialize hotplug framework if we are hotpluggable. 14407c478bd9Sstevel@tonic-gate * Sets flag in the soft state if Hot Plug is supported and initialized 14417c478bd9Sstevel@tonic-gate * properly. 14427c478bd9Sstevel@tonic-gate */ 14437c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 14447c478bd9Sstevel@tonic-gate static void 14457c478bd9Sstevel@tonic-gate ppb_init_hotplug(ppb_devstate_t *ppb) 14467c478bd9Sstevel@tonic-gate { 144726947304SEvan Yan ppb->hotplug_capable = B_FALSE; 144826947304SEvan Yan 14497c478bd9Sstevel@tonic-gate if (ddi_prop_exists(DDI_DEV_T_ANY, ppb->dip, DDI_PROP_DONTPASS, 14507c478bd9Sstevel@tonic-gate "hotplug-capable")) { 14517c478bd9Sstevel@tonic-gate (void) modload("misc", "pcihp"); 14527c478bd9Sstevel@tonic-gate 14537c478bd9Sstevel@tonic-gate if (pcihp_init(ppb->dip) != DDI_SUCCESS) { 14547c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, 14557c478bd9Sstevel@tonic-gate "%s #%d: Failed setting hotplug framework", 14567c478bd9Sstevel@tonic-gate ddi_driver_name(ppb->dip), 14577c478bd9Sstevel@tonic-gate ddi_get_instance(ppb->dip)); 14587c478bd9Sstevel@tonic-gate } else 14597c478bd9Sstevel@tonic-gate ppb->hotplug_capable = B_TRUE; 14607c478bd9Sstevel@tonic-gate } 14617c478bd9Sstevel@tonic-gate 146226947304SEvan Yan if (ppb->hotplug_capable == B_FALSE) { 146326947304SEvan Yan /* 146426947304SEvan Yan * create minor node for devctl interfaces 146526947304SEvan Yan */ 146626947304SEvan Yan if (ddi_create_minor_node(ppb->dip, "devctl", S_IFCHR, 146726947304SEvan Yan PCI_MINOR_NUM(ddi_get_instance(ppb->dip), PCI_DEVCTL_MINOR), 146826947304SEvan Yan DDI_NT_NEXUS, 0) != DDI_SUCCESS) 146926947304SEvan Yan cmn_err(CE_WARN, 147026947304SEvan Yan "%s #%d: Failed to create a minor node", 147126947304SEvan Yan ddi_driver_name(ppb->dip), 147226947304SEvan Yan ddi_get_instance(ppb->dip)); 147326947304SEvan Yan } 14747c478bd9Sstevel@tonic-gate } 14757c478bd9Sstevel@tonic-gate 14767c478bd9Sstevel@tonic-gate static void 14777c478bd9Sstevel@tonic-gate ppb_create_ranges_prop(dev_info_t *dip, 14787c478bd9Sstevel@tonic-gate ddi_acc_handle_t config_handle) 14797c478bd9Sstevel@tonic-gate { 14807c478bd9Sstevel@tonic-gate uint32_t base, limit; 14817c478bd9Sstevel@tonic-gate ppb_ranges_t ranges[PPB_RANGE_LEN]; 14827c478bd9Sstevel@tonic-gate uint8_t io_base_lo, io_limit_lo; 14837c478bd9Sstevel@tonic-gate uint16_t io_base_hi, io_limit_hi, mem_base, mem_limit; 14847c478bd9Sstevel@tonic-gate int i = 0, rangelen = sizeof (ppb_ranges_t)/sizeof (int); 14857c478bd9Sstevel@tonic-gate 14867c478bd9Sstevel@tonic-gate io_base_lo = pci_config_get8(config_handle, PCI_BCNF_IO_BASE_LOW); 14877c478bd9Sstevel@tonic-gate io_limit_lo = pci_config_get8(config_handle, PCI_BCNF_IO_LIMIT_LOW); 14887c478bd9Sstevel@tonic-gate io_base_hi = pci_config_get16(config_handle, PCI_BCNF_IO_BASE_HI); 14897c478bd9Sstevel@tonic-gate io_limit_hi = pci_config_get16(config_handle, PCI_BCNF_IO_LIMIT_HI); 14907c478bd9Sstevel@tonic-gate mem_base = pci_config_get16(config_handle, PCI_BCNF_MEM_BASE); 14917c478bd9Sstevel@tonic-gate mem_limit = pci_config_get16(config_handle, PCI_BCNF_MEM_LIMIT); 14927c478bd9Sstevel@tonic-gate 14937c478bd9Sstevel@tonic-gate /* 14947c478bd9Sstevel@tonic-gate * Create ranges for IO space 14957c478bd9Sstevel@tonic-gate */ 14967c478bd9Sstevel@tonic-gate ranges[i].size_low = ranges[i].size_high = 0; 14977c478bd9Sstevel@tonic-gate ranges[i].parent_mid = ranges[i].child_mid = 14987c478bd9Sstevel@tonic-gate ranges[i].parent_high = 0; 14997c478bd9Sstevel@tonic-gate ranges[i].child_high = ranges[i].parent_high |= 15007c478bd9Sstevel@tonic-gate (PCI_REG_REL_M | PCI_ADDR_IO); 15017c478bd9Sstevel@tonic-gate base = PPB_16bit_IOADDR(io_base_lo); 15027c478bd9Sstevel@tonic-gate limit = PPB_16bit_IOADDR(io_limit_lo); 15037c478bd9Sstevel@tonic-gate 150445091ee1SPavel Potoplyak /* 150545091ee1SPavel Potoplyak * Check for 32-bit I/O support as per PCI-to-PCI Bridge Arch Spec 150645091ee1SPavel Potoplyak */ 15077c478bd9Sstevel@tonic-gate if ((io_base_lo & 0xf) == PPB_32BIT_IO) { 15087c478bd9Sstevel@tonic-gate base = PPB_LADDR(base, io_base_hi); 15097c478bd9Sstevel@tonic-gate limit = PPB_LADDR(limit, io_limit_hi); 15107c478bd9Sstevel@tonic-gate } 15117c478bd9Sstevel@tonic-gate 151245091ee1SPavel Potoplyak /* 151345091ee1SPavel Potoplyak * Check if the bridge implements an I/O address range as per 151445091ee1SPavel Potoplyak * PCI-to-PCI Bridge Arch Spec 151545091ee1SPavel Potoplyak */ 151645091ee1SPavel Potoplyak if ((io_base_lo != 0 || io_limit_lo != 0) && limit >= base) { 151745091ee1SPavel Potoplyak ranges[i].parent_low = ranges[i].child_low = 151845091ee1SPavel Potoplyak base; 151945091ee1SPavel Potoplyak ranges[i].size_low = limit - base + PPB_IOGRAIN; 152045091ee1SPavel Potoplyak i++; 15217c478bd9Sstevel@tonic-gate } 15227c478bd9Sstevel@tonic-gate 15237c478bd9Sstevel@tonic-gate /* 15247c478bd9Sstevel@tonic-gate * Create ranges for 32bit memory space 15257c478bd9Sstevel@tonic-gate */ 15267c478bd9Sstevel@tonic-gate base = PPB_32bit_MEMADDR(mem_base); 15277c478bd9Sstevel@tonic-gate limit = PPB_32bit_MEMADDR(mem_limit); 15287c478bd9Sstevel@tonic-gate ranges[i].size_low = ranges[i].size_high = 0; 15297c478bd9Sstevel@tonic-gate ranges[i].parent_mid = ranges[i].child_mid = 15307c478bd9Sstevel@tonic-gate ranges[i].parent_high = 0; 15317c478bd9Sstevel@tonic-gate ranges[i].child_high = ranges[i].parent_high |= 15327c478bd9Sstevel@tonic-gate (PCI_REG_REL_M | PCI_ADDR_MEM32); 15337c478bd9Sstevel@tonic-gate ranges[i].child_low = ranges[i].parent_low = base; 15347c478bd9Sstevel@tonic-gate if (limit >= base) { 15357c478bd9Sstevel@tonic-gate ranges[i].size_low = limit - base + PPB_MEMGRAIN; 15367c478bd9Sstevel@tonic-gate i++; 15377c478bd9Sstevel@tonic-gate } 15387c478bd9Sstevel@tonic-gate 15397c478bd9Sstevel@tonic-gate if (i) { 15407c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int_array(DDI_DEV_T_NONE, dip, "ranges", 15417c478bd9Sstevel@tonic-gate (int *)ranges, i * rangelen); 15427c478bd9Sstevel@tonic-gate } 15437c478bd9Sstevel@tonic-gate } 15447c478bd9Sstevel@tonic-gate 15457c478bd9Sstevel@tonic-gate /* ARGSUSED */ 15467c478bd9Sstevel@tonic-gate static int 15477c478bd9Sstevel@tonic-gate ppb_open(dev_t *devp, int flags, int otyp, cred_t *credp) 15487c478bd9Sstevel@tonic-gate { 154926947304SEvan Yan int instance = PCI_MINOR_NUM_TO_INSTANCE(getminor(*devp)); 155026947304SEvan Yan ppb_devstate_t *ppb_p = ddi_get_soft_state(ppb_state, instance); 15517c478bd9Sstevel@tonic-gate 15527c478bd9Sstevel@tonic-gate /* 15537c478bd9Sstevel@tonic-gate * Make sure the open is for the right file type. 15547c478bd9Sstevel@tonic-gate */ 15557c478bd9Sstevel@tonic-gate if (otyp != OTYP_CHR) 15567c478bd9Sstevel@tonic-gate return (EINVAL); 15577c478bd9Sstevel@tonic-gate 15587c478bd9Sstevel@tonic-gate if (ppb_p == NULL) 15597c478bd9Sstevel@tonic-gate return (ENXIO); 15607c478bd9Sstevel@tonic-gate 156126947304SEvan Yan mutex_enter(&ppb_p->ppb_mutex); 156226947304SEvan Yan 156326947304SEvan Yan /* 156426947304SEvan Yan * Ioctls will be handled by SPARC PCI Express framework for all 156526947304SEvan Yan * PCIe platforms 156626947304SEvan Yan */ 156726947304SEvan Yan if (ppb_p->parent_bus == PCIE_PCIECAP_DEV_TYPE_PCIE_DEV) { 156826947304SEvan Yan int rv; 156926947304SEvan Yan 157026947304SEvan Yan rv = pcie_open(ppb_p->dip, devp, flags, otyp, credp); 157126947304SEvan Yan mutex_exit(&ppb_p->ppb_mutex); 157226947304SEvan Yan 157326947304SEvan Yan return (rv); 157426947304SEvan Yan } else if (ppb_p->hotplug_capable == B_TRUE) { 157526947304SEvan Yan mutex_exit(&ppb_p->ppb_mutex); 157626947304SEvan Yan 157726947304SEvan Yan return ((pcihp_get_cb_ops())->cb_open(devp, flags, otyp, 157826947304SEvan Yan credp)); 157926947304SEvan Yan } 15807c478bd9Sstevel@tonic-gate 15817c478bd9Sstevel@tonic-gate /* 15827c478bd9Sstevel@tonic-gate * Handle the open by tracking the device state. 15837c478bd9Sstevel@tonic-gate */ 15847c478bd9Sstevel@tonic-gate if (flags & FEXCL) { 158526947304SEvan Yan if (ppb_p->ppb_soft_state != PCI_SOFT_STATE_CLOSED) { 15867c478bd9Sstevel@tonic-gate mutex_exit(&ppb_p->ppb_mutex); 15877c478bd9Sstevel@tonic-gate return (EBUSY); 15887c478bd9Sstevel@tonic-gate } 158926947304SEvan Yan ppb_p->ppb_soft_state = PCI_SOFT_STATE_OPEN_EXCL; 15907c478bd9Sstevel@tonic-gate } else { 159126947304SEvan Yan if (ppb_p->ppb_soft_state == PCI_SOFT_STATE_OPEN_EXCL) { 15927c478bd9Sstevel@tonic-gate mutex_exit(&ppb_p->ppb_mutex); 15937c478bd9Sstevel@tonic-gate return (EBUSY); 15947c478bd9Sstevel@tonic-gate } 159526947304SEvan Yan ppb_p->ppb_soft_state = PCI_SOFT_STATE_OPEN; 15967c478bd9Sstevel@tonic-gate } 15977c478bd9Sstevel@tonic-gate mutex_exit(&ppb_p->ppb_mutex); 15987c478bd9Sstevel@tonic-gate return (0); 15997c478bd9Sstevel@tonic-gate } 16007c478bd9Sstevel@tonic-gate 16017c478bd9Sstevel@tonic-gate 16027c478bd9Sstevel@tonic-gate /* ARGSUSED */ 16037c478bd9Sstevel@tonic-gate static int 16047c478bd9Sstevel@tonic-gate ppb_close(dev_t dev, int flags, int otyp, cred_t *credp) 16057c478bd9Sstevel@tonic-gate { 160626947304SEvan Yan int instance = PCI_MINOR_NUM_TO_INSTANCE(getminor(dev)); 160726947304SEvan Yan ppb_devstate_t *ppb_p = ddi_get_soft_state(ppb_state, instance); 16087c478bd9Sstevel@tonic-gate 16097c478bd9Sstevel@tonic-gate if (otyp != OTYP_CHR) 16107c478bd9Sstevel@tonic-gate return (EINVAL); 16117c478bd9Sstevel@tonic-gate 16127c478bd9Sstevel@tonic-gate if (ppb_p == NULL) 16137c478bd9Sstevel@tonic-gate return (ENXIO); 16147c478bd9Sstevel@tonic-gate 16157c478bd9Sstevel@tonic-gate mutex_enter(&ppb_p->ppb_mutex); 161626947304SEvan Yan /* 161726947304SEvan Yan * Ioctls will be handled by SPARC PCI Express framework for all 161826947304SEvan Yan * PCIe platforms 161926947304SEvan Yan */ 162026947304SEvan Yan if (ppb_p->parent_bus == PCIE_PCIECAP_DEV_TYPE_PCIE_DEV) { 162126947304SEvan Yan int rv; 162226947304SEvan Yan 162326947304SEvan Yan rv = pcie_close(ppb_p->dip, dev, flags, otyp, credp); 162426947304SEvan Yan mutex_exit(&ppb_p->ppb_mutex); 162526947304SEvan Yan 162626947304SEvan Yan return (rv); 162726947304SEvan Yan } else if (ppb_p->hotplug_capable == B_TRUE) { 162826947304SEvan Yan mutex_exit(&ppb_p->ppb_mutex); 162926947304SEvan Yan return ((pcihp_get_cb_ops())->cb_close(dev, flags, otyp, 163026947304SEvan Yan credp)); 163126947304SEvan Yan } 163226947304SEvan Yan 163326947304SEvan Yan ppb_p->ppb_soft_state = PCI_SOFT_STATE_CLOSED; 16347c478bd9Sstevel@tonic-gate mutex_exit(&ppb_p->ppb_mutex); 16357c478bd9Sstevel@tonic-gate return (0); 16367c478bd9Sstevel@tonic-gate } 16377c478bd9Sstevel@tonic-gate 16387c478bd9Sstevel@tonic-gate 16397c478bd9Sstevel@tonic-gate /* 16407c478bd9Sstevel@tonic-gate * ppb_ioctl: devctl hotplug controls 16417c478bd9Sstevel@tonic-gate */ 16427c478bd9Sstevel@tonic-gate /* ARGSUSED */ 16437c478bd9Sstevel@tonic-gate static int 16447c478bd9Sstevel@tonic-gate ppb_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, cred_t *credp, 16457c478bd9Sstevel@tonic-gate int *rvalp) 16467c478bd9Sstevel@tonic-gate { 164726947304SEvan Yan int instance = PCI_MINOR_NUM_TO_INSTANCE(getminor(dev)); 164826947304SEvan Yan ppb_devstate_t *ppb_p = ddi_get_soft_state(ppb_state, instance); 16497c478bd9Sstevel@tonic-gate struct devctl_iocdata *dcp; 16507c478bd9Sstevel@tonic-gate uint_t bus_state; 165126947304SEvan Yan dev_info_t *self; 16527c478bd9Sstevel@tonic-gate int rv = 0; 16537c478bd9Sstevel@tonic-gate 16547c478bd9Sstevel@tonic-gate if (ppb_p == NULL) 16557c478bd9Sstevel@tonic-gate return (ENXIO); 16567c478bd9Sstevel@tonic-gate 165726947304SEvan Yan /* 165826947304SEvan Yan * Ioctls will be handled by SPARC PCI Express framework for all 165926947304SEvan Yan * PCIe platforms 166026947304SEvan Yan */ 166126947304SEvan Yan if (ppb_p->parent_bus == PCIE_PCIECAP_DEV_TYPE_PCIE_DEV) 166226947304SEvan Yan return (pcie_ioctl(ppb_p->dip, dev, cmd, arg, mode, credp, 166326947304SEvan Yan rvalp)); 166426947304SEvan Yan else if (ppb_p->hotplug_capable == B_TRUE) 166526947304SEvan Yan return ((pcihp_get_cb_ops())->cb_ioctl(dev, cmd, arg, mode, 166626947304SEvan Yan credp, rvalp)); 16677c478bd9Sstevel@tonic-gate 16687c478bd9Sstevel@tonic-gate self = ppb_p->dip; 16697c478bd9Sstevel@tonic-gate 16707c478bd9Sstevel@tonic-gate /* 16717c478bd9Sstevel@tonic-gate * We can use the generic implementation for these ioctls 16727c478bd9Sstevel@tonic-gate */ 16737c478bd9Sstevel@tonic-gate switch (cmd) { 16747c478bd9Sstevel@tonic-gate case DEVCTL_DEVICE_GETSTATE: 16757c478bd9Sstevel@tonic-gate case DEVCTL_DEVICE_ONLINE: 16767c478bd9Sstevel@tonic-gate case DEVCTL_DEVICE_OFFLINE: 16777c478bd9Sstevel@tonic-gate case DEVCTL_BUS_GETSTATE: 16787c478bd9Sstevel@tonic-gate return (ndi_devctl_ioctl(self, cmd, arg, mode, 0)); 16797c478bd9Sstevel@tonic-gate } 16807c478bd9Sstevel@tonic-gate 16817c478bd9Sstevel@tonic-gate /* 16827c478bd9Sstevel@tonic-gate * read devctl ioctl data 16837c478bd9Sstevel@tonic-gate */ 16847c478bd9Sstevel@tonic-gate if (ndi_dc_allochdl((void *)arg, &dcp) != NDI_SUCCESS) 16857c478bd9Sstevel@tonic-gate return (EFAULT); 16867c478bd9Sstevel@tonic-gate 16877c478bd9Sstevel@tonic-gate switch (cmd) { 16887c478bd9Sstevel@tonic-gate 16897c478bd9Sstevel@tonic-gate case DEVCTL_DEVICE_RESET: 16907c478bd9Sstevel@tonic-gate rv = ENOTSUP; 16917c478bd9Sstevel@tonic-gate break; 16927c478bd9Sstevel@tonic-gate 16937c478bd9Sstevel@tonic-gate case DEVCTL_BUS_QUIESCE: 16947c478bd9Sstevel@tonic-gate if (ndi_get_bus_state(self, &bus_state) == NDI_SUCCESS) 16957c478bd9Sstevel@tonic-gate if (bus_state == BUS_QUIESCED) 16967c478bd9Sstevel@tonic-gate break; 16977c478bd9Sstevel@tonic-gate (void) ndi_set_bus_state(self, BUS_QUIESCED); 16987c478bd9Sstevel@tonic-gate break; 16997c478bd9Sstevel@tonic-gate 17007c478bd9Sstevel@tonic-gate case DEVCTL_BUS_UNQUIESCE: 17017c478bd9Sstevel@tonic-gate if (ndi_get_bus_state(self, &bus_state) == NDI_SUCCESS) 17027c478bd9Sstevel@tonic-gate if (bus_state == BUS_ACTIVE) 17037c478bd9Sstevel@tonic-gate break; 17047c478bd9Sstevel@tonic-gate (void) ndi_set_bus_state(self, BUS_ACTIVE); 17057c478bd9Sstevel@tonic-gate break; 17067c478bd9Sstevel@tonic-gate 17077c478bd9Sstevel@tonic-gate case DEVCTL_BUS_RESET: 17087c478bd9Sstevel@tonic-gate rv = ENOTSUP; 17097c478bd9Sstevel@tonic-gate break; 17107c478bd9Sstevel@tonic-gate 17117c478bd9Sstevel@tonic-gate case DEVCTL_BUS_RESETALL: 17127c478bd9Sstevel@tonic-gate rv = ENOTSUP; 17137c478bd9Sstevel@tonic-gate break; 17147c478bd9Sstevel@tonic-gate 17157c478bd9Sstevel@tonic-gate default: 17167c478bd9Sstevel@tonic-gate rv = ENOTTY; 17177c478bd9Sstevel@tonic-gate } 17187c478bd9Sstevel@tonic-gate 17197c478bd9Sstevel@tonic-gate ndi_dc_freehdl(dcp); 17207c478bd9Sstevel@tonic-gate return (rv); 17217c478bd9Sstevel@tonic-gate } 17227c478bd9Sstevel@tonic-gate 172326947304SEvan Yan static int 172426947304SEvan Yan ppb_prop_op(dev_t dev, dev_info_t *dip, ddi_prop_op_t prop_op, int flags, 172526947304SEvan Yan char *name, caddr_t valuep, int *lengthp) 17267c478bd9Sstevel@tonic-gate { 172726947304SEvan Yan int instance = PCI_MINOR_NUM_TO_INSTANCE(getminor(dev)); 172826947304SEvan Yan ppb_devstate_t *ppb_p = (ppb_devstate_t *) 172926947304SEvan Yan ddi_get_soft_state(ppb_state, instance); 17307c478bd9Sstevel@tonic-gate 17317c478bd9Sstevel@tonic-gate if (ppb_p == NULL) 17327c478bd9Sstevel@tonic-gate return (ENXIO); 17337c478bd9Sstevel@tonic-gate 173426947304SEvan Yan if (ppb_p->parent_bus == PCIE_PCIECAP_DEV_TYPE_PCIE_DEV) 173526947304SEvan Yan return (pcie_prop_op(dev, dip, prop_op, flags, name, 173626947304SEvan Yan valuep, lengthp)); 17377c478bd9Sstevel@tonic-gate 173826947304SEvan Yan return ((pcihp_get_cb_ops())->cb_prop_op(dev, dip, prop_op, flags, 173926947304SEvan Yan name, valuep, lengthp)); 17407c478bd9Sstevel@tonic-gate } 17417c478bd9Sstevel@tonic-gate 17427c478bd9Sstevel@tonic-gate /* 17437c478bd9Sstevel@tonic-gate * Initialize our FMA resources 17447c478bd9Sstevel@tonic-gate */ 17457c478bd9Sstevel@tonic-gate static void 17467c478bd9Sstevel@tonic-gate ppb_fm_init(ppb_devstate_t *ppb_p) 17477c478bd9Sstevel@tonic-gate { 17487c478bd9Sstevel@tonic-gate ppb_p->fm_cap = DDI_FM_EREPORT_CAPABLE | DDI_FM_ERRCB_CAPABLE | 17497c478bd9Sstevel@tonic-gate DDI_FM_ACCCHK_CAPABLE | DDI_FM_DMACHK_CAPABLE; 17507c478bd9Sstevel@tonic-gate 17517c478bd9Sstevel@tonic-gate /* 17527c478bd9Sstevel@tonic-gate * Request our capability level and get our parents capability 17537c478bd9Sstevel@tonic-gate * and ibc. 17547c478bd9Sstevel@tonic-gate */ 17557c478bd9Sstevel@tonic-gate ddi_fm_init(ppb_p->dip, &ppb_p->fm_cap, &ppb_p->fm_ibc); 17567c478bd9Sstevel@tonic-gate ASSERT((ppb_p->fm_cap & DDI_FM_EREPORT_CAPABLE) && 17577c478bd9Sstevel@tonic-gate (ppb_p->fm_cap & DDI_FM_ERRCB_CAPABLE)); 17587c478bd9Sstevel@tonic-gate 17597c478bd9Sstevel@tonic-gate pci_ereport_setup(ppb_p->dip); 17607c478bd9Sstevel@tonic-gate 17617c478bd9Sstevel@tonic-gate /* 17627c478bd9Sstevel@tonic-gate * Register error callback with our parent. 17637c478bd9Sstevel@tonic-gate */ 17647c478bd9Sstevel@tonic-gate ddi_fm_handler_register(ppb_p->dip, ppb_err_callback, NULL); 17657c478bd9Sstevel@tonic-gate } 17667c478bd9Sstevel@tonic-gate 17677c478bd9Sstevel@tonic-gate /* 17687c478bd9Sstevel@tonic-gate * Breakdown our FMA resources 17697c478bd9Sstevel@tonic-gate */ 17707c478bd9Sstevel@tonic-gate static void 17717c478bd9Sstevel@tonic-gate ppb_fm_fini(ppb_devstate_t *ppb_p) 17727c478bd9Sstevel@tonic-gate { 17737c478bd9Sstevel@tonic-gate /* 17747c478bd9Sstevel@tonic-gate * Clean up allocated fm structures 17757c478bd9Sstevel@tonic-gate */ 17767c478bd9Sstevel@tonic-gate ddi_fm_handler_unregister(ppb_p->dip); 17777c478bd9Sstevel@tonic-gate pci_ereport_teardown(ppb_p->dip); 17787c478bd9Sstevel@tonic-gate ddi_fm_fini(ppb_p->dip); 17797c478bd9Sstevel@tonic-gate } 17807c478bd9Sstevel@tonic-gate 17817c478bd9Sstevel@tonic-gate /* 17827c478bd9Sstevel@tonic-gate * Initialize FMA resources for children devices. Called when 17837c478bd9Sstevel@tonic-gate * child calls ddi_fm_init(). 17847c478bd9Sstevel@tonic-gate */ 17857c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 17867c478bd9Sstevel@tonic-gate static int 17877c478bd9Sstevel@tonic-gate ppb_fm_init_child(dev_info_t *dip, dev_info_t *tdip, int cap, 17887c478bd9Sstevel@tonic-gate ddi_iblock_cookie_t *ibc) 17897c478bd9Sstevel@tonic-gate { 17907c478bd9Sstevel@tonic-gate ppb_devstate_t *ppb_p = (ppb_devstate_t *)ddi_get_soft_state(ppb_state, 17917c478bd9Sstevel@tonic-gate ddi_get_instance(dip)); 17927c478bd9Sstevel@tonic-gate *ibc = ppb_p->fm_ibc; 17937c478bd9Sstevel@tonic-gate return (ppb_p->fm_cap); 17947c478bd9Sstevel@tonic-gate } 17957c478bd9Sstevel@tonic-gate 17967c478bd9Sstevel@tonic-gate /* 17977c478bd9Sstevel@tonic-gate * FMA registered error callback 17987c478bd9Sstevel@tonic-gate */ 17997c478bd9Sstevel@tonic-gate static int 18007c478bd9Sstevel@tonic-gate ppb_err_callback(dev_info_t *dip, ddi_fm_error_t *derr, const void *impl_data) 18017c478bd9Sstevel@tonic-gate { 1802bf8fc234Set142600 ppb_devstate_t *ppb_p = (ppb_devstate_t *)ddi_get_soft_state(ppb_state, 1803bf8fc234Set142600 ddi_get_instance(dip)); 1804bf8fc234Set142600 1805bf8fc234Set142600 /* 1806bf8fc234Set142600 * errors handled by SPARC PCI-E framework for PCIe platforms 1807bf8fc234Set142600 */ 1808bf8fc234Set142600 if (ppb_p->parent_bus == PCIE_PCIECAP_DEV_TYPE_PCIE_DEV) 1809bf8fc234Set142600 return (DDI_FM_OK); 1810bf8fc234Set142600 1811bf8fc234Set142600 /* 1812bf8fc234Set142600 * do the following for SPARC PCI platforms 1813bf8fc234Set142600 */ 18147c478bd9Sstevel@tonic-gate ASSERT(impl_data == NULL); 181500d0963fSdilpreet pci_ereport_post(dip, derr, NULL); 181600d0963fSdilpreet return (derr->fme_status); 18177c478bd9Sstevel@tonic-gate } 18187c478bd9Sstevel@tonic-gate 18197c478bd9Sstevel@tonic-gate static void 18207c478bd9Sstevel@tonic-gate ppb_bus_enter(dev_info_t *dip, ddi_acc_handle_t handle) 18217c478bd9Sstevel@tonic-gate { 18227c478bd9Sstevel@tonic-gate i_ndi_busop_access_enter(dip, handle); 18237c478bd9Sstevel@tonic-gate } 18247c478bd9Sstevel@tonic-gate 18257c478bd9Sstevel@tonic-gate /* ARGSUSED */ 18267c478bd9Sstevel@tonic-gate static void 18277c478bd9Sstevel@tonic-gate ppb_bus_exit(dev_info_t *dip, ddi_acc_handle_t handle) 18287c478bd9Sstevel@tonic-gate { 18297c478bd9Sstevel@tonic-gate i_ndi_busop_access_exit(dip, handle); 18307c478bd9Sstevel@tonic-gate } 1831