13db86aabSstevel /* 23db86aabSstevel * CDDL HEADER START 33db86aabSstevel * 43db86aabSstevel * The contents of this file are subject to the terms of the 53db86aabSstevel * Common Development and Distribution License (the "License"). 63db86aabSstevel * You may not use this file except in compliance with the License. 73db86aabSstevel * 83db86aabSstevel * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 93db86aabSstevel * or http://www.opensolaris.org/os/licensing. 103db86aabSstevel * See the License for the specific language governing permissions 113db86aabSstevel * and limitations under the License. 123db86aabSstevel * 133db86aabSstevel * When distributing Covered Code, include this CDDL HEADER in each 143db86aabSstevel * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 153db86aabSstevel * If applicable, add the following below this CDDL HEADER, with the 163db86aabSstevel * fields enclosed by brackets "[]" replaced with your own identifying 173db86aabSstevel * information: Portions Copyright [yyyy] [name of copyright owner] 183db86aabSstevel * 193db86aabSstevel * CDDL HEADER END 203db86aabSstevel */ 213db86aabSstevel 223db86aabSstevel /* 2311c2b4c0Srw148561 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 243db86aabSstevel * Use is subject to license terms. 253db86aabSstevel */ 263db86aabSstevel 273db86aabSstevel #pragma ident "%Z%%M% %I% %E% SMI" 283db86aabSstevel 293db86aabSstevel /* 303db86aabSstevel * PCIC device/interrupt handler 313db86aabSstevel * The "pcic" driver handles the Intel 82365SL, Cirrus Logic 323db86aabSstevel * and Toshiba (and possibly other clones) PCMCIA adapter chip 333db86aabSstevel * sets. It implements a subset of Socket Services as defined 343db86aabSstevel * in the Solaris PCMCIA design documents 353db86aabSstevel */ 363db86aabSstevel 373db86aabSstevel /* 383db86aabSstevel * currently defined "properties" 393db86aabSstevel * 403db86aabSstevel * clock-frequency bus clock frequency 413db86aabSstevel * smi system management interrupt override 423db86aabSstevel * need-mult-irq need status IRQ for each pair of sockets 433db86aabSstevel * disable-audio don't route audio signal to speaker 443db86aabSstevel */ 453db86aabSstevel 463db86aabSstevel 473db86aabSstevel #include <sys/types.h> 483db86aabSstevel #include <sys/inttypes.h> 493db86aabSstevel #include <sys/param.h> 503db86aabSstevel #include <sys/systm.h> 513db86aabSstevel #include <sys/user.h> 523db86aabSstevel #include <sys/buf.h> 533db86aabSstevel #include <sys/file.h> 543db86aabSstevel #include <sys/uio.h> 553db86aabSstevel #include <sys/conf.h> 563db86aabSstevel #include <sys/stat.h> 573db86aabSstevel #include <sys/autoconf.h> 583db86aabSstevel #include <sys/vtoc.h> 593db86aabSstevel #include <sys/dkio.h> 603db86aabSstevel #include <sys/ddi.h> 613db86aabSstevel #include <sys/sunddi.h> 623db86aabSstevel #include <sys/sunndi.h> 633db86aabSstevel #include <sys/var.h> 643db86aabSstevel #include <sys/callb.h> 653db86aabSstevel #include <sys/open.h> 663db86aabSstevel #include <sys/ddidmareq.h> 673db86aabSstevel #include <sys/dma_engine.h> 683db86aabSstevel #include <sys/kstat.h> 693db86aabSstevel #include <sys/kmem.h> 703db86aabSstevel #include <sys/modctl.h> 713db86aabSstevel #include <sys/pci.h> 723db86aabSstevel #include <sys/pci_impl.h> 733db86aabSstevel 743db86aabSstevel #include <sys/pctypes.h> 753db86aabSstevel #include <sys/pcmcia.h> 763db86aabSstevel #include <sys/sservice.h> 773db86aabSstevel 783db86aabSstevel #include <sys/note.h> 793db86aabSstevel 803db86aabSstevel #include <sys/pcic_reg.h> 813db86aabSstevel #include <sys/pcic_var.h> 823db86aabSstevel 833db86aabSstevel #if defined(__sparc) 843db86aabSstevel #include <sys/pci/pci_nexus.h> 853db86aabSstevel #endif 863db86aabSstevel 870d282d13Srw148561 #include <sys/hotplug/hpcsvc.h> 883db86aabSstevel #include "cardbus/cardbus.h" 893db86aabSstevel 903db86aabSstevel #define SOFTC_SIZE (sizeof (anp_t)) 913db86aabSstevel 923db86aabSstevel static int pcic_getinfo(dev_info_t *, ddi_info_cmd_t, void *, void **); 933db86aabSstevel static int pcic_attach(dev_info_t *, ddi_attach_cmd_t); 943db86aabSstevel static int pcic_detach(dev_info_t *, ddi_detach_cmd_t); 953db86aabSstevel static uint_t pcic_intr(caddr_t, caddr_t); 963db86aabSstevel static int pcic_do_io_intr(pcicdev_t *, uint32_t); 973db86aabSstevel static int pcic_probe(dev_info_t *); 983db86aabSstevel 993db86aabSstevel static int pcic_open(dev_t *, int, int, cred_t *); 1003db86aabSstevel static int pcic_close(dev_t, int, int, cred_t *); 1013db86aabSstevel static int pcic_ioctl(dev_t, int, intptr_t, int, cred_t *, int *); 1023db86aabSstevel 1033db86aabSstevel typedef struct pcm_regs pcm_regs_t; 1043db86aabSstevel 1053db86aabSstevel static void pcic_init_assigned(dev_info_t *); 1063db86aabSstevel static int pcic_apply_avail_ranges(dev_info_t *, pcm_regs_t *, 1073db86aabSstevel pci_regspec_t *, int); 1083db86aabSstevel int pci_resource_setup_avail(dev_info_t *, pci_regspec_t *, int); 1093db86aabSstevel 1103db86aabSstevel /* 1113db86aabSstevel * On x86 platforms the ddi_iobp_alloc(9F) and ddi_mem_alloc(9F) calls 1123db86aabSstevel * are xlated into DMA ctlops. To make this nexus work on x86, we 1133db86aabSstevel * need to have the default ddi_dma_mctl ctlops in the bus_ops 1143db86aabSstevel * structure, just to pass the request to the parent. The correct 1153db86aabSstevel * ctlops should be ddi_no_dma_mctl because so far we don't do DMA. 1163db86aabSstevel */ 1173db86aabSstevel static 1183db86aabSstevel struct bus_ops pcmciabus_ops = { 1193db86aabSstevel BUSO_REV, 1203db86aabSstevel pcmcia_bus_map, 1213db86aabSstevel NULL, 1223db86aabSstevel NULL, 1233db86aabSstevel NULL, 1243db86aabSstevel i_ddi_map_fault, 1253db86aabSstevel ddi_no_dma_map, 1263db86aabSstevel ddi_no_dma_allochdl, 1273db86aabSstevel ddi_no_dma_freehdl, 1283db86aabSstevel ddi_no_dma_bindhdl, 1293db86aabSstevel ddi_no_dma_unbindhdl, 1303db86aabSstevel ddi_no_dma_flush, 1313db86aabSstevel ddi_no_dma_win, 1323db86aabSstevel ddi_dma_mctl, 1333db86aabSstevel pcmcia_ctlops, 1343db86aabSstevel pcmcia_prop_op, 1353db86aabSstevel NULL, /* (*bus_get_eventcookie)(); */ 1363db86aabSstevel NULL, /* (*bus_add_eventcall)(); */ 1373db86aabSstevel NULL, /* (*bus_remove_eventcall)(); */ 1383db86aabSstevel NULL, /* (*bus_post_event)(); */ 1393db86aabSstevel NULL, /* (*bus_intr_ctl)(); */ 1403db86aabSstevel NULL, /* (*bus_config)(); */ 1413db86aabSstevel NULL, /* (*bus_unconfig)(); */ 1423db86aabSstevel NULL, /* (*bus_fm_init)(); */ 1433db86aabSstevel NULL, /* (*bus_fm_fini)(); */ 1443db86aabSstevel NULL, /* (*bus_enter)() */ 1453db86aabSstevel NULL, /* (*bus_exit)() */ 1463db86aabSstevel NULL, /* (*bus_power)() */ 1473db86aabSstevel pcmcia_intr_ops /* (*bus_intr_op)(); */ 1483db86aabSstevel }; 1493db86aabSstevel 1503db86aabSstevel static struct cb_ops pcic_cbops = { 1513db86aabSstevel pcic_open, 1523db86aabSstevel pcic_close, 1533db86aabSstevel nodev, 1543db86aabSstevel nodev, 1553db86aabSstevel nodev, 1563db86aabSstevel nodev, 1573db86aabSstevel nodev, 1583db86aabSstevel pcic_ioctl, 1593db86aabSstevel nodev, 1603db86aabSstevel nodev, 1613db86aabSstevel nodev, 1623db86aabSstevel nochpoll, 1633db86aabSstevel ddi_prop_op, 1643db86aabSstevel NULL, 1653db86aabSstevel #ifdef CARDBUS 1663db86aabSstevel D_NEW | D_MP | D_HOTPLUG 1673db86aabSstevel #else 1683db86aabSstevel D_NEW | D_MP 1693db86aabSstevel #endif 1703db86aabSstevel }; 1713db86aabSstevel 1723db86aabSstevel static struct dev_ops pcic_devops = { 1733db86aabSstevel DEVO_REV, 1743db86aabSstevel 0, 1753db86aabSstevel pcic_getinfo, 1763db86aabSstevel nulldev, 1773db86aabSstevel pcic_probe, 1783db86aabSstevel pcic_attach, 1793db86aabSstevel pcic_detach, 1803db86aabSstevel nulldev, 1813db86aabSstevel &pcic_cbops, 1823db86aabSstevel &pcmciabus_ops, 1833db86aabSstevel NULL 1843db86aabSstevel }; 1853db86aabSstevel 1863db86aabSstevel void *pcic_soft_state_p = NULL; 1873db86aabSstevel static int pcic_maxinst = -1; 1883db86aabSstevel 1893db86aabSstevel int pcic_do_insertion = 1; 1903db86aabSstevel int pcic_do_removal = 1; 1913db86aabSstevel 1923db86aabSstevel struct irqmap { 1933db86aabSstevel int irq; 1943db86aabSstevel int count; 1953db86aabSstevel } pcic_irq_map[16]; 1963db86aabSstevel 1973db86aabSstevel 1983db86aabSstevel int pcic_debug = 0x0; 1993db86aabSstevel static void pcic_err(dev_info_t *dip, int level, const char *fmt, ...); 2003db86aabSstevel extern void cardbus_dump_pci_config(dev_info_t *dip); 2013db86aabSstevel extern void cardbus_dump_socket(dev_info_t *dip); 2023db86aabSstevel extern int cardbus_validate_iline(dev_info_t *dip, ddi_acc_handle_t handle); 2033db86aabSstevel static void pcic_dump_debqueue(char *msg); 2043db86aabSstevel 2053db86aabSstevel #if defined(PCIC_DEBUG) 2063db86aabSstevel static void xxdmp_all_regs(pcicdev_t *, int, uint32_t); 2073db86aabSstevel 2083db86aabSstevel #define pcic_mutex_enter(a) \ 2093db86aabSstevel { \ 2103db86aabSstevel pcic_err(NULL, 10, "Set lock at %d\n", __LINE__); \ 2113db86aabSstevel mutex_enter(a); \ 2123db86aabSstevel }; 2133db86aabSstevel 2143db86aabSstevel #define pcic_mutex_exit(a) \ 2153db86aabSstevel { \ 2163db86aabSstevel pcic_err(NULL, 10, "Clear lock at %d\n", __LINE__); \ 2173db86aabSstevel mutex_exit(a); \ 2183db86aabSstevel }; 2193db86aabSstevel 2203db86aabSstevel #else 2213db86aabSstevel #define pcic_mutex_enter(a) mutex_enter(a) 2223db86aabSstevel #define pcic_mutex_exit(a) mutex_exit(a) 2233db86aabSstevel #endif 2243db86aabSstevel 2253db86aabSstevel #define PCIC_VCC_3VLEVEL 1 2263db86aabSstevel #define PCIC_VCC_5VLEVEL 2 2273db86aabSstevel #define PCIC_VCC_12LEVEL 3 2283db86aabSstevel 2293db86aabSstevel /* bit patterns to select voltage levels */ 2303db86aabSstevel int pcic_vpp_levels[13] = { 2313db86aabSstevel 0, 0, 0, 2323db86aabSstevel 1, /* 3.3V */ 2333db86aabSstevel 0, 2343db86aabSstevel 1, /* 5V */ 2353db86aabSstevel 0, 0, 0, 0, 0, 0, 2363db86aabSstevel 2 /* 12V */ 2373db86aabSstevel }; 2383db86aabSstevel 2393db86aabSstevel uint8_t pcic_cbv_levels[13] = { 2403db86aabSstevel 0, 0, 0, 2413db86aabSstevel 3, /* 3.3V */ 2423db86aabSstevel 0, 2433db86aabSstevel 2, /* 5V */ 2443db86aabSstevel 0, 0, 0, 0, 0, 0, 2453db86aabSstevel 1 /* 12V */ 2463db86aabSstevel }; 2473db86aabSstevel 2483db86aabSstevel struct power_entry pcic_power[4] = { 2493db86aabSstevel { 2503db86aabSstevel 0, VCC|VPP1|VPP2 2513db86aabSstevel }, 2523db86aabSstevel { 2533db86aabSstevel 33, /* 3.3Volt */ 2543db86aabSstevel VCC|VPP1|VPP2 2553db86aabSstevel }, 2563db86aabSstevel { 2573db86aabSstevel 5*10, /* 5Volt */ 2583db86aabSstevel VCC|VPP1|VPP2 /* currently only know about this */ 2593db86aabSstevel }, 2603db86aabSstevel { 2613db86aabSstevel 12*10, /* 12Volt */ 2623db86aabSstevel VPP1|VPP2 2633db86aabSstevel } 2643db86aabSstevel }; 2653db86aabSstevel 2663db86aabSstevel /* 2673db86aabSstevel * Base used to allocate ranges of PCI memory on x86 systems 2683db86aabSstevel * Each instance gets a chunk above the base that is used to map 2693db86aabSstevel * in the memory and I/O windows for that device. 2703db86aabSstevel * Pages below the base are also allocated for the EXCA registers, 2713db86aabSstevel * one per instance. 2723db86aabSstevel */ 2733db86aabSstevel #define PCIC_PCI_MEMCHUNK 0x1000000 2743db86aabSstevel 2753db86aabSstevel static int pcic_wait_insert_time = 5000000; /* In micro-seconds */ 2763db86aabSstevel static int pcic_debounce_time = 200000; /* In micro-seconds */ 2773db86aabSstevel 2783db86aabSstevel struct debounce { 2793db86aabSstevel pcic_socket_t *pcs; 2803db86aabSstevel clock_t expire; 2813db86aabSstevel struct debounce *next; 2823db86aabSstevel }; 2833db86aabSstevel 2843db86aabSstevel static struct debounce *pcic_deb_queue = NULL; 2853db86aabSstevel static kmutex_t pcic_deb_mtx; 2863db86aabSstevel static kcondvar_t pcic_deb_cv; 2873db86aabSstevel static kthread_t *pcic_deb_threadid; 2883db86aabSstevel 2893db86aabSstevel static inthandler_t *pcic_handlers; 2903db86aabSstevel 2913db86aabSstevel static void pcic_setup_adapter(pcicdev_t *); 2923db86aabSstevel static int pcic_change(pcicdev_t *, int); 2933db86aabSstevel static int pcic_ll_reset(pcicdev_t *, int); 2943db86aabSstevel static void pcic_mswait(pcicdev_t *, int, int); 2953db86aabSstevel static boolean_t pcic_check_ready(pcicdev_t *, int); 2963db86aabSstevel static void pcic_set_cdtimers(pcicdev_t *, int, uint32_t, int); 2973db86aabSstevel static void pcic_ready_wait(pcicdev_t *, int); 2983db86aabSstevel extern int pcmcia_get_intr(dev_info_t *, int); 2993db86aabSstevel extern int pcmcia_return_intr(dev_info_t *, int); 30011c2b4c0Srw148561 extern void pcmcia_cb_suspended(int); 30111c2b4c0Srw148561 extern void pcmcia_cb_resumed(int); 3023db86aabSstevel 3033db86aabSstevel static int pcic_callback(dev_info_t *, int (*)(), int); 3043db86aabSstevel static int pcic_inquire_adapter(dev_info_t *, inquire_adapter_t *); 3053db86aabSstevel static int pcic_get_adapter(dev_info_t *, get_adapter_t *); 3063db86aabSstevel static int pcic_get_page(dev_info_t *, get_page_t *); 3073db86aabSstevel static int pcic_get_socket(dev_info_t *, get_socket_t *); 3083db86aabSstevel static int pcic_get_status(dev_info_t *, get_ss_status_t *); 3093db86aabSstevel static int pcic_get_window(dev_info_t *, get_window_t *); 3103db86aabSstevel static int pcic_inquire_socket(dev_info_t *, inquire_socket_t *); 3113db86aabSstevel static int pcic_inquire_window(dev_info_t *, inquire_window_t *); 3123db86aabSstevel static int pcic_reset_socket(dev_info_t *, int, int); 3133db86aabSstevel static int pcic_set_page(dev_info_t *, set_page_t *); 3143db86aabSstevel static int pcic_set_window(dev_info_t *, set_window_t *); 3153db86aabSstevel static int pcic_set_socket(dev_info_t *, set_socket_t *); 3163db86aabSstevel static int pcic_set_interrupt(dev_info_t *, set_irq_handler_t *); 3173db86aabSstevel static int pcic_clear_interrupt(dev_info_t *, clear_irq_handler_t *); 3183db86aabSstevel static void pcic_pm_detection(void *); 3193db86aabSstevel static void pcic_iomem_pci_ctl(ddi_acc_handle_t, uchar_t *, unsigned); 3203db86aabSstevel static int clext_reg_read(pcicdev_t *, int, uchar_t); 3213db86aabSstevel static void clext_reg_write(pcicdev_t *, int, uchar_t, uchar_t); 3223db86aabSstevel static int pcic_calc_speed(pcicdev_t *, uint32_t); 3233db86aabSstevel static int pcic_card_state(pcicdev_t *, pcic_socket_t *); 3243db86aabSstevel static int pcic_find_pci_type(pcicdev_t *); 3253db86aabSstevel static void pcic_82092_smiirq_ctl(pcicdev_t *, int, int, int); 3263db86aabSstevel static void pcic_handle_cd_change(pcicdev_t *, pcic_socket_t *, uint8_t); 3273db86aabSstevel static uint_t pcic_cd_softint(caddr_t, caddr_t); 3283db86aabSstevel static uint8_t pcic_getb(pcicdev_t *, int, int); 3293db86aabSstevel static void pcic_putb(pcicdev_t *, int, int, int8_t); 3303db86aabSstevel static int pcic_set_vcc_level(pcicdev_t *, set_socket_t *); 3313db86aabSstevel static uint_t pcic_softintr(caddr_t, caddr_t); 3323db86aabSstevel 3333db86aabSstevel static void pcic_debounce(pcic_socket_t *); 33411c2b4c0Srw148561 static void pcic_do_resume(pcicdev_t *); 3353db86aabSstevel static void *pcic_add_debqueue(pcic_socket_t *, int); 3363db86aabSstevel static void pcic_rm_debqueue(void *); 3373db86aabSstevel static void pcic_deb_thread(); 3383db86aabSstevel 3393db86aabSstevel static boolean_t pcic_load_cardbus(pcicdev_t *pcic, const pcic_socket_t *sockp); 3403db86aabSstevel static void pcic_unload_cardbus(pcicdev_t *pcic, const pcic_socket_t *sockp); 3413db86aabSstevel static uint32_t pcic_getcb(pcicdev_t *pcic, int reg); 3423db86aabSstevel static void pcic_putcb(pcicdev_t *pcic, int reg, uint32_t value); 3433db86aabSstevel static void pcic_cb_enable_intr(dev_info_t *); 3443db86aabSstevel static void pcic_cb_disable_intr(dev_info_t *); 3453db86aabSstevel static void pcic_enable_io_intr(pcicdev_t *pcic, int socket, int irq); 3463db86aabSstevel static void pcic_disable_io_intr(pcicdev_t *pcic, int socket); 3473db86aabSstevel 3483db86aabSstevel static cb_nexus_cb_t pcic_cbnexus_ops = { 3493db86aabSstevel pcic_cb_enable_intr, 3503db86aabSstevel pcic_cb_disable_intr 3513db86aabSstevel }; 3523db86aabSstevel 3533db86aabSstevel static int pcic_exca_powerctl(pcicdev_t *pcic, int socket, int powerlevel); 3543db86aabSstevel static int pcic_cbus_powerctl(pcicdev_t *pcic, int socket); 3553db86aabSstevel 3563db86aabSstevel #if defined(__sparc) 3573db86aabSstevel static int pcic_fault(enum pci_fault_ops op, void *arg); 3583db86aabSstevel #endif 3593db86aabSstevel 3603db86aabSstevel 3613db86aabSstevel /* 3623db86aabSstevel * pcmcia interface operations structure 3633db86aabSstevel * this is the private interface that is exported to the nexus 3643db86aabSstevel */ 3653db86aabSstevel pcmcia_if_t pcic_if_ops = { 3663db86aabSstevel PCIF_MAGIC, 3673db86aabSstevel PCIF_VERSION, 3683db86aabSstevel pcic_callback, 3693db86aabSstevel pcic_get_adapter, 3703db86aabSstevel pcic_get_page, 3713db86aabSstevel pcic_get_socket, 3723db86aabSstevel pcic_get_status, 3733db86aabSstevel pcic_get_window, 3743db86aabSstevel pcic_inquire_adapter, 3753db86aabSstevel pcic_inquire_socket, 3763db86aabSstevel pcic_inquire_window, 3773db86aabSstevel pcic_reset_socket, 3783db86aabSstevel pcic_set_page, 3793db86aabSstevel pcic_set_window, 3803db86aabSstevel pcic_set_socket, 3813db86aabSstevel pcic_set_interrupt, 3823db86aabSstevel pcic_clear_interrupt, 3833db86aabSstevel NULL, 3843db86aabSstevel }; 3853db86aabSstevel 3863db86aabSstevel /* 3873db86aabSstevel * chip type identification routines 3883db86aabSstevel * this list of functions is searched until one of them succeeds 3893db86aabSstevel * or all fail. i82365SL is assumed if failed. 3903db86aabSstevel */ 3913db86aabSstevel static int pcic_ci_cirrus(pcicdev_t *); 3923db86aabSstevel static int pcic_ci_vadem(pcicdev_t *); 3933db86aabSstevel static int pcic_ci_ricoh(pcicdev_t *); 3943db86aabSstevel 3953db86aabSstevel int (*pcic_ci_funcs[])(pcicdev_t *) = { 3963db86aabSstevel pcic_ci_cirrus, 3973db86aabSstevel pcic_ci_vadem, 3983db86aabSstevel pcic_ci_ricoh, 3993db86aabSstevel NULL 4003db86aabSstevel }; 4013db86aabSstevel 4023db86aabSstevel static struct modldrv modldrv = { 4033db86aabSstevel &mod_driverops, /* Type of module. This one is a driver */ 404*903a11ebSrh87107 "PCIC PCMCIA adapter driver", /* Name of the module. */ 4053db86aabSstevel &pcic_devops, /* driver ops */ 4063db86aabSstevel }; 4073db86aabSstevel 4083db86aabSstevel static struct modlinkage modlinkage = { 4093db86aabSstevel MODREV_1, (void *)&modldrv, NULL 4103db86aabSstevel }; 4113db86aabSstevel 4123db86aabSstevel int 4133db86aabSstevel _init() 4143db86aabSstevel { 4153db86aabSstevel int stat; 4163db86aabSstevel 4173db86aabSstevel /* Allocate soft state */ 4183db86aabSstevel if ((stat = ddi_soft_state_init(&pcic_soft_state_p, 4193db86aabSstevel SOFTC_SIZE, 2)) != DDI_SUCCESS) 4203db86aabSstevel return (stat); 4213db86aabSstevel 4223db86aabSstevel if ((stat = mod_install(&modlinkage)) != 0) 4233db86aabSstevel ddi_soft_state_fini(&pcic_soft_state_p); 4243db86aabSstevel 4253db86aabSstevel return (stat); 4263db86aabSstevel } 4273db86aabSstevel 4283db86aabSstevel int 4293db86aabSstevel _fini() 4303db86aabSstevel { 4313db86aabSstevel int stat = 0; 4323db86aabSstevel 4333db86aabSstevel if ((stat = mod_remove(&modlinkage)) != 0) 4343db86aabSstevel return (stat); 4353db86aabSstevel 4363db86aabSstevel if (pcic_deb_threadid) { 4373db86aabSstevel mutex_enter(&pcic_deb_mtx); 4383db86aabSstevel pcic_deb_threadid = 0; 4393db86aabSstevel while (!pcic_deb_threadid) 4403db86aabSstevel cv_wait(&pcic_deb_cv, &pcic_deb_mtx); 4413db86aabSstevel pcic_deb_threadid = 0; 4423db86aabSstevel mutex_exit(&pcic_deb_mtx); 4433db86aabSstevel 4443db86aabSstevel mutex_destroy(&pcic_deb_mtx); 4453db86aabSstevel cv_destroy(&pcic_deb_cv); 4463db86aabSstevel } 4473db86aabSstevel 4483db86aabSstevel ddi_soft_state_fini(&pcic_soft_state_p); 4493db86aabSstevel 4503db86aabSstevel return (stat); 4513db86aabSstevel } 4523db86aabSstevel 4533db86aabSstevel int 4543db86aabSstevel _info(struct modinfo *modinfop) 4553db86aabSstevel { 4563db86aabSstevel return (mod_info(&modlinkage, modinfop)); 4573db86aabSstevel } 4583db86aabSstevel 4593db86aabSstevel /* 4603db86aabSstevel * pcic_getinfo() 4613db86aabSstevel * provide instance/device information about driver 4623db86aabSstevel */ 4633db86aabSstevel /*ARGSUSED*/ 4643db86aabSstevel static int 4653db86aabSstevel pcic_getinfo(dev_info_t *dip, ddi_info_cmd_t cmd, void *arg, void **result) 4663db86aabSstevel { 4673db86aabSstevel anp_t *anp; 4683db86aabSstevel int error = DDI_SUCCESS; 4693db86aabSstevel minor_t minor; 4703db86aabSstevel 4713db86aabSstevel switch (cmd) { 4723db86aabSstevel case DDI_INFO_DEVT2DEVINFO: 4733db86aabSstevel minor = getminor((dev_t)arg); 4743db86aabSstevel minor &= 0x7f; 4753db86aabSstevel if (!(anp = ddi_get_soft_state(pcic_soft_state_p, minor))) 4763db86aabSstevel *result = NULL; 4773db86aabSstevel else 4783db86aabSstevel *result = anp->an_dip; 4793db86aabSstevel break; 4803db86aabSstevel case DDI_INFO_DEVT2INSTANCE: 4813db86aabSstevel minor = getminor((dev_t)arg); 4823db86aabSstevel minor &= 0x7f; 4833db86aabSstevel *result = (void *)((long)minor); 4843db86aabSstevel break; 4853db86aabSstevel default: 4863db86aabSstevel error = DDI_FAILURE; 4873db86aabSstevel break; 4883db86aabSstevel } 4893db86aabSstevel return (error); 4903db86aabSstevel } 4913db86aabSstevel 4923db86aabSstevel static int 4933db86aabSstevel pcic_probe(dev_info_t *dip) 4943db86aabSstevel { 4953db86aabSstevel int value; 4963db86aabSstevel ddi_device_acc_attr_t attr; 4973db86aabSstevel ddi_acc_handle_t handle; 4983db86aabSstevel uchar_t *index, *data; 4993db86aabSstevel 5003db86aabSstevel if (ddi_dev_is_sid(dip) == DDI_SUCCESS) 5013db86aabSstevel return (DDI_PROBE_DONTCARE); 5023db86aabSstevel 5033db86aabSstevel /* 5043db86aabSstevel * find a PCIC device (any vendor) 5053db86aabSstevel * while there can be up to 4 such devices in 5063db86aabSstevel * a system, we currently only look for 1 5073db86aabSstevel * per probe. There will be up to 2 chips per 5083db86aabSstevel * instance since they share I/O space 5093db86aabSstevel */ 5103db86aabSstevel attr.devacc_attr_version = DDI_DEVICE_ATTR_V0; 5113db86aabSstevel attr.devacc_attr_endian_flags = DDI_NEVERSWAP_ACC; 5123db86aabSstevel attr.devacc_attr_dataorder = DDI_STRICTORDER_ACC; 5133db86aabSstevel 5143db86aabSstevel if (ddi_regs_map_setup(dip, PCIC_ISA_CONTROL_REG_NUM, 5153db86aabSstevel (caddr_t *)&index, 5163db86aabSstevel PCIC_ISA_CONTROL_REG_OFFSET, 5173db86aabSstevel PCIC_ISA_CONTROL_REG_LENGTH, 5183db86aabSstevel &attr, &handle) != DDI_SUCCESS) 5193db86aabSstevel return (DDI_PROBE_FAILURE); 5203db86aabSstevel 5213db86aabSstevel data = index + 1; 5223db86aabSstevel 5233db86aabSstevel #if defined(PCIC_DEBUG) 5243db86aabSstevel if (pcic_debug) 5253db86aabSstevel cmn_err(CE_CONT, "pcic_probe: entered\n"); 5263db86aabSstevel if (pcic_debug) 5273db86aabSstevel cmn_err(CE_CONT, "\tindex=%p\n", (void *)index); 5283db86aabSstevel #endif 5293db86aabSstevel ddi_put8(handle, index, PCIC_CHIP_REVISION); 5303db86aabSstevel ddi_put8(handle, data, 0); 5313db86aabSstevel value = ddi_get8(handle, data); 5323db86aabSstevel #if defined(PCIC_DEBUG) 5333db86aabSstevel if (pcic_debug) 5343db86aabSstevel cmn_err(CE_CONT, "\tchip revision register = %x\n", value); 5353db86aabSstevel #endif 5363db86aabSstevel if ((value & PCIC_REV_MASK) >= PCIC_REV_LEVEL_LOW && 5373db86aabSstevel (value & 0x30) == 0) { 5383db86aabSstevel /* 5393db86aabSstevel * we probably have a PCIC chip in the system 5403db86aabSstevel * do a little more checking. If we find one, 5413db86aabSstevel * reset everything in case of softboot 5423db86aabSstevel */ 5433db86aabSstevel ddi_put8(handle, index, PCIC_MAPPING_ENABLE); 5443db86aabSstevel ddi_put8(handle, data, 0); 5453db86aabSstevel value = ddi_get8(handle, data); 5463db86aabSstevel #if defined(PCIC_DEBUG) 5473db86aabSstevel if (pcic_debug) 5483db86aabSstevel cmn_err(CE_CONT, "\tzero test = %x\n", value); 5493db86aabSstevel #endif 5503db86aabSstevel /* should read back as zero */ 5513db86aabSstevel if (value == 0) { 5523db86aabSstevel /* 5533db86aabSstevel * we do have one and it is off the bus 5543db86aabSstevel */ 5553db86aabSstevel #if defined(PCIC_DEBUG) 5563db86aabSstevel if (pcic_debug) 5573db86aabSstevel cmn_err(CE_CONT, "pcic_probe: success\n"); 5583db86aabSstevel #endif 5593db86aabSstevel ddi_regs_map_free(&handle); 5603db86aabSstevel return (DDI_PROBE_SUCCESS); 5613db86aabSstevel } 5623db86aabSstevel } 5633db86aabSstevel #if defined(PCIC_DEBUG) 5643db86aabSstevel if (pcic_debug) 5653db86aabSstevel cmn_err(CE_CONT, "pcic_probe: failed\n"); 5663db86aabSstevel #endif 5673db86aabSstevel ddi_regs_map_free(&handle); 5683db86aabSstevel return (DDI_PROBE_FAILURE); 5693db86aabSstevel } 5703db86aabSstevel 5713db86aabSstevel /* 5723db86aabSstevel * These are just defaults they can also be changed via a property in the 5733db86aabSstevel * conf file. 5743db86aabSstevel */ 5753db86aabSstevel static int pci_config_reg_num = PCIC_PCI_CONFIG_REG_NUM; 5763db86aabSstevel static int pci_control_reg_num = PCIC_PCI_CONTROL_REG_NUM; 57711c2b4c0Srw148561 static int pcic_do_pcmcia_sr = 1; 5783db86aabSstevel static int pcic_use_cbpwrctl = PCF_CBPWRCTL; 5793db86aabSstevel 5803db86aabSstevel /* 5813db86aabSstevel * enable insertion/removal interrupt for 32bit cards 5823db86aabSstevel */ 5833db86aabSstevel static int 5843db86aabSstevel cardbus_enable_cd_intr(dev_info_t *dip) 5853db86aabSstevel { 5863db86aabSstevel ddi_acc_handle_t iohandle; 5873db86aabSstevel caddr_t ioaddr; 5883db86aabSstevel ddi_device_acc_attr_t attr; 5893db86aabSstevel attr.devacc_attr_version = DDI_DEVICE_ATTR_V0; 5903db86aabSstevel attr.devacc_attr_endian_flags = DDI_STRUCTURE_LE_ACC; 5913db86aabSstevel attr.devacc_attr_dataorder = DDI_STRICTORDER_ACC; 5923db86aabSstevel (void) ddi_regs_map_setup(dip, 1, 5933db86aabSstevel (caddr_t *)&ioaddr, 5943db86aabSstevel 0, 5953db86aabSstevel 4096, 5963db86aabSstevel &attr, &iohandle); 5973db86aabSstevel 5983db86aabSstevel /* CSC Interrupt: Card detect interrupt on */ 5993db86aabSstevel ddi_put32(iohandle, (uint32_t *)(ioaddr+CB_STATUS_MASK), 6003db86aabSstevel ddi_get32(iohandle, 6013db86aabSstevel (uint32_t *)(ioaddr+CB_STATUS_MASK)) | CB_SE_CCDMASK); 6023db86aabSstevel 6033db86aabSstevel ddi_put32(iohandle, (uint32_t *)(ioaddr+CB_STATUS_EVENT), 6043db86aabSstevel ddi_get32(iohandle, (uint32_t *)(ioaddr+CB_STATUS_EVENT))); 6053db86aabSstevel 6063db86aabSstevel ddi_regs_map_free(&iohandle); 6073db86aabSstevel return (1); 6083db86aabSstevel } 6093db86aabSstevel 6103db86aabSstevel /* 6113db86aabSstevel * pcic_attach() 6123db86aabSstevel * attach the PCIC (Intel 82365SL/CirrusLogic/Toshiba) driver 6133db86aabSstevel * to the system. This is a child of "sysbus" since that is where 6143db86aabSstevel * the hardware lives, but it provides services to the "pcmcia" 6153db86aabSstevel * nexus driver. It gives a pointer back via its private data 6163db86aabSstevel * structure which contains both the dip and socket services entry 6173db86aabSstevel * points 6183db86aabSstevel */ 6193db86aabSstevel static int 6203db86aabSstevel pcic_attach(dev_info_t *dip, ddi_attach_cmd_t cmd) 6213db86aabSstevel { 6223db86aabSstevel anp_t *pcic_nexus; 6233db86aabSstevel pcicdev_t *pcic; 6243db86aabSstevel int irqlevel, value; 6253db86aabSstevel int pci_cfrn, pci_ctrn; 6263db86aabSstevel int i, j, smi, actual; 6273db86aabSstevel char *typename; 6283db86aabSstevel char bus_type[16] = "(unknown)"; 6293db86aabSstevel int len = sizeof (bus_type); 6303db86aabSstevel ddi_device_acc_attr_t attr; 6313db86aabSstevel anp_t *anp = ddi_get_driver_private(dip); 6323db86aabSstevel uint_t pri; 6333db86aabSstevel 6343db86aabSstevel #if defined(PCIC_DEBUG) 6353db86aabSstevel if (pcic_debug) { 6363db86aabSstevel cmn_err(CE_CONT, "pcic_attach: entered\n"); 6373db86aabSstevel } 6383db86aabSstevel #endif 6393db86aabSstevel switch (cmd) { 6403db86aabSstevel case DDI_ATTACH: 6413db86aabSstevel break; 6423db86aabSstevel case DDI_RESUME: 6433db86aabSstevel pcic = anp->an_private; 6443db86aabSstevel /* 6453db86aabSstevel * for now, this is a simulated resume. 6463db86aabSstevel * a real one may need different things. 6473db86aabSstevel */ 6483db86aabSstevel if (pcic != NULL && pcic->pc_flags & PCF_SUSPENDED) { 6493db86aabSstevel mutex_enter(&pcic->pc_lock); 6503db86aabSstevel /* should probe for new sockets showing up */ 6513db86aabSstevel pcic_setup_adapter(pcic); 6523db86aabSstevel pcic->pc_flags &= ~PCF_SUSPENDED; 6533db86aabSstevel mutex_exit(&pcic->pc_lock); 6543db86aabSstevel (void) pcmcia_begin_resume(dip); 65511c2b4c0Srw148561 65611c2b4c0Srw148561 pcic_do_resume(pcic); 65711c2b4c0Srw148561 #ifdef CARDBUS 65811c2b4c0Srw148561 cardbus_restore_children(ddi_get_child(dip)); 65911c2b4c0Srw148561 #endif 6603db86aabSstevel 6613db86aabSstevel /* 6623db86aabSstevel * for complete implementation need END_RESUME (later) 6633db86aabSstevel */ 6643db86aabSstevel return (DDI_SUCCESS); 6653db86aabSstevel 6663db86aabSstevel } 6673db86aabSstevel return (DDI_SUCCESS); 6683db86aabSstevel default: 6693db86aabSstevel return (DDI_FAILURE); 6703db86aabSstevel } 6713db86aabSstevel 6723db86aabSstevel /* 6733db86aabSstevel * Allocate soft state associated with this instance. 6743db86aabSstevel */ 6753db86aabSstevel if (ddi_soft_state_zalloc(pcic_soft_state_p, 6763db86aabSstevel ddi_get_instance(dip)) != DDI_SUCCESS) { 6773db86aabSstevel cmn_err(CE_CONT, "pcic%d: Unable to alloc state\n", 6783db86aabSstevel ddi_get_instance(dip)); 6793db86aabSstevel return (DDI_FAILURE); 6803db86aabSstevel } 6813db86aabSstevel 6823db86aabSstevel pcic_nexus = ddi_get_soft_state(pcic_soft_state_p, 6833db86aabSstevel ddi_get_instance(dip)); 6843db86aabSstevel 6853db86aabSstevel pcic = kmem_zalloc(sizeof (pcicdev_t), KM_SLEEP); 6863db86aabSstevel 6873db86aabSstevel pcic->dip = dip; 6883db86aabSstevel pcic_nexus->an_dip = dip; 6893db86aabSstevel pcic_nexus->an_if = &pcic_if_ops; 6903db86aabSstevel pcic_nexus->an_private = pcic; 6913db86aabSstevel pcic->pc_numpower = sizeof (pcic_power)/sizeof (pcic_power[0]); 6923db86aabSstevel pcic->pc_power = pcic_power; 6933db86aabSstevel 6943db86aabSstevel pci_ctrn = ddi_getprop(DDI_DEV_T_ANY, dip, DDI_PROP_CANSLEEP, 6953db86aabSstevel "pci-control-reg-number", pci_control_reg_num); 6963db86aabSstevel pci_cfrn = ddi_getprop(DDI_DEV_T_ANY, dip, DDI_PROP_CANSLEEP, 6973db86aabSstevel "pci-config-reg-number", pci_config_reg_num); 6983db86aabSstevel 6993db86aabSstevel ddi_set_driver_private(dip, pcic_nexus); 7003db86aabSstevel 7013db86aabSstevel /* 7023db86aabSstevel * pcic->pc_irq is really the IPL level we want to run at 7033db86aabSstevel * set the default values here and override from intr spec 7043db86aabSstevel */ 7053db86aabSstevel pcic->pc_irq = ddi_getprop(DDI_DEV_T_ANY, dip, DDI_PROP_CANSLEEP, 7063db86aabSstevel "interrupt-priorities", -1); 7073db86aabSstevel 7083db86aabSstevel if (pcic->pc_irq == -1) { 7093db86aabSstevel int actual; 7103db86aabSstevel uint_t pri; 7113db86aabSstevel ddi_intr_handle_t hdl; 7123db86aabSstevel 7133db86aabSstevel /* see if intrspec tells us different */ 7143db86aabSstevel if (ddi_intr_alloc(dip, &hdl, DDI_INTR_TYPE_FIXED, 7153db86aabSstevel 0, 1, &actual, DDI_INTR_ALLOC_NORMAL) == DDI_SUCCESS) { 7163db86aabSstevel if (ddi_intr_get_pri(hdl, &pri) == DDI_SUCCESS) 7173db86aabSstevel pcic->pc_irq = pri; 7183db86aabSstevel else 7193db86aabSstevel pcic->pc_irq = LOCK_LEVEL + 1; 7203db86aabSstevel (void) ddi_intr_free(hdl); 7213db86aabSstevel } 7223db86aabSstevel } 7233db86aabSstevel pcic_nexus->an_ipl = pcic->pc_irq; 7243db86aabSstevel 7253db86aabSstevel /* 7263db86aabSstevel * Check our parent bus type. We do different things based on which 7273db86aabSstevel * bus we're on. 7283db86aabSstevel */ 7293db86aabSstevel if (ddi_prop_op(DDI_DEV_T_ANY, ddi_get_parent(dip), 7303db86aabSstevel PROP_LEN_AND_VAL_BUF, DDI_PROP_CANSLEEP, 7313db86aabSstevel "device_type", (caddr_t)&bus_type[0], &len) != 7323db86aabSstevel DDI_PROP_SUCCESS) { 7333db86aabSstevel if (ddi_prop_op(DDI_DEV_T_ANY, ddi_get_parent(dip), 7343db86aabSstevel PROP_LEN_AND_VAL_BUF, DDI_PROP_CANSLEEP, 7353db86aabSstevel "bus-type", (caddr_t)&bus_type[0], &len) != 7363db86aabSstevel DDI_PROP_SUCCESS) { 7373db86aabSstevel 7383db86aabSstevel cmn_err(CE_CONT, 7393db86aabSstevel "pcic%d: can't find parent bus type\n", 7403db86aabSstevel ddi_get_instance(dip)); 7413db86aabSstevel 7423db86aabSstevel kmem_free(pcic, sizeof (pcicdev_t)); 743b8a60a54Srw148561 ddi_soft_state_free(pcic_soft_state_p, 744b8a60a54Srw148561 ddi_get_instance(dip)); 7453db86aabSstevel return (DDI_FAILURE); 7463db86aabSstevel } 7473db86aabSstevel } /* ddi_prop_op("device_type") */ 7483db86aabSstevel 7498134ee03Srw148561 if (strcmp(bus_type, DEVI_PCI_NEXNAME) == 0 || 7508134ee03Srw148561 strcmp(bus_type, DEVI_PCIEX_NEXNAME) == 0) { 7513db86aabSstevel pcic->pc_flags = PCF_PCIBUS; 7523db86aabSstevel } else { 753b8a60a54Srw148561 cmn_err(CE_WARN, "!pcic%d: non-pci mode (%s) not supported, " 754b8a60a54Srw148561 "set BIOS to yenta mode if applicable\n", 7553db86aabSstevel ddi_get_instance(dip), bus_type); 7563db86aabSstevel kmem_free(pcic, sizeof (pcicdev_t)); 757b8a60a54Srw148561 ddi_soft_state_free(pcic_soft_state_p, 758b8a60a54Srw148561 ddi_get_instance(dip)); 7593db86aabSstevel return (DDI_FAILURE); 7603db86aabSstevel } 7613db86aabSstevel 7623db86aabSstevel if ((pcic->bus_speed = ddi_getprop(DDI_DEV_T_ANY, ddi_get_parent(dip), 7633db86aabSstevel DDI_PROP_CANSLEEP, 7643db86aabSstevel "clock-frequency", 0)) == 0) { 7653db86aabSstevel if (pcic->pc_flags & PCF_PCIBUS) 7663db86aabSstevel pcic->bus_speed = PCIC_PCI_DEF_SYSCLK; 7673db86aabSstevel else 7683db86aabSstevel pcic->bus_speed = PCIC_ISA_DEF_SYSCLK; 7693db86aabSstevel } else { 7703db86aabSstevel /* 7713db86aabSstevel * OBP can declare the speed in Hz... 7723db86aabSstevel */ 7733db86aabSstevel if (pcic->bus_speed > 1000000) 7743db86aabSstevel pcic->bus_speed /= 1000000; 7753db86aabSstevel } /* ddi_prop_op("clock-frequency") */ 7763db86aabSstevel 7773db86aabSstevel pcic->pc_io_type = PCIC_IO_TYPE_82365SL; /* default mode */ 7783db86aabSstevel 7793db86aabSstevel #ifdef PCIC_DEBUG 7803db86aabSstevel if (pcic_debug) { 7813db86aabSstevel cmn_err(CE_CONT, 7823db86aabSstevel "pcic%d: parent bus type = [%s], speed = %d MHz\n", 7833db86aabSstevel ddi_get_instance(dip), 7843db86aabSstevel bus_type, pcic->bus_speed); 7853db86aabSstevel } 7863db86aabSstevel #endif 7873db86aabSstevel 7883db86aabSstevel /* 7893db86aabSstevel * The reg properties on a PCI node are different than those 7903db86aabSstevel * on a non-PCI node. Handle that difference here. 7913db86aabSstevel * If it turns out to be a CardBus chip, we have even more 7923db86aabSstevel * differences. 7933db86aabSstevel */ 7943db86aabSstevel if (pcic->pc_flags & PCF_PCIBUS) { 7953db86aabSstevel int class_code; 7963db86aabSstevel #if defined(__i386) || defined(__amd64) 7973db86aabSstevel pcic->pc_base = 0x1000000; 7983db86aabSstevel pcic->pc_bound = (uint32_t)~0; 7993db86aabSstevel pcic->pc_iobase = 0x1000; 8003db86aabSstevel pcic->pc_iobound = 0xefff; 8013db86aabSstevel #elif defined(__sparc) 8023db86aabSstevel pcic->pc_base = 0x0; 8033db86aabSstevel pcic->pc_bound = (uint32_t)~0; 8043db86aabSstevel pcic->pc_iobase = 0x00000; 8053db86aabSstevel pcic->pc_iobound = 0xffff; 8063db86aabSstevel #endif 8073db86aabSstevel 8083db86aabSstevel /* usually need to get at config space so map first */ 8093db86aabSstevel attr.devacc_attr_version = DDI_DEVICE_ATTR_V0; 8103db86aabSstevel attr.devacc_attr_endian_flags = DDI_STRUCTURE_LE_ACC; 8113db86aabSstevel attr.devacc_attr_dataorder = DDI_STRICTORDER_ACC; 8123db86aabSstevel 8133db86aabSstevel if (ddi_regs_map_setup(dip, pci_cfrn, 8143db86aabSstevel (caddr_t *)&pcic->cfgaddr, 8153db86aabSstevel PCIC_PCI_CONFIG_REG_OFFSET, 8163db86aabSstevel PCIC_PCI_CONFIG_REG_LENGTH, 8173db86aabSstevel &attr, 8183db86aabSstevel &pcic->cfg_handle) != 8193db86aabSstevel DDI_SUCCESS) { 8203db86aabSstevel cmn_err(CE_CONT, 8213db86aabSstevel "pcic%d: unable to map config space" 8223db86aabSstevel "regs\n", 8233db86aabSstevel ddi_get_instance(dip)); 8243db86aabSstevel 8253db86aabSstevel kmem_free(pcic, sizeof (pcicdev_t)); 8263db86aabSstevel return (DDI_FAILURE); 8273db86aabSstevel } /* ddi_regs_map_setup */ 8283db86aabSstevel 8293db86aabSstevel class_code = ddi_getprop(DDI_DEV_T_ANY, dip, 8303db86aabSstevel DDI_PROP_CANSLEEP|DDI_PROP_DONTPASS, 8313db86aabSstevel "class-code", -1); 8323db86aabSstevel #ifdef PCIC_DEBUG 8333db86aabSstevel if (pcic_debug) { 8343db86aabSstevel cmn_err(CE_CONT, "pcic_attach class_code=%x\n", 8353db86aabSstevel class_code); 8363db86aabSstevel } 8373db86aabSstevel #endif 8383db86aabSstevel 8393db86aabSstevel switch (class_code) { 8403db86aabSstevel case PCIC_PCI_CARDBUS: 8413db86aabSstevel pcic->pc_flags |= PCF_CARDBUS; 8423db86aabSstevel pcic->pc_io_type = PCIC_IO_TYPE_YENTA; 8433db86aabSstevel /* 8443db86aabSstevel * Get access to the adapter registers on the 8453db86aabSstevel * PCI bus. A 4K memory page 8463db86aabSstevel */ 8473db86aabSstevel #if defined(PCIC_DEBUG) 8483db86aabSstevel pcic_err(dip, 8, "Is Cardbus device\n"); 8493db86aabSstevel if (pcic_debug) { 8503db86aabSstevel int nr; 8513db86aabSstevel long rs; 8523db86aabSstevel (void) ddi_dev_nregs(dip, &nr); 8533db86aabSstevel pcic_err(dip, 9, "\tdev, cfgaddr 0x%p," 8543db86aabSstevel "cfghndl 0x%p nregs %d", 8553db86aabSstevel (void *)pcic->cfgaddr, 8563db86aabSstevel (void *)pcic->cfg_handle, nr); 8573db86aabSstevel 8583db86aabSstevel (void) ddi_dev_regsize(dip, 8593db86aabSstevel PCIC_PCI_CONTROL_REG_NUM, &rs); 8603db86aabSstevel 8613db86aabSstevel pcic_err(dip, 9, "\tsize of reg %d is 0x%x\n", 8623db86aabSstevel PCIC_PCI_CONTROL_REG_NUM, (int)rs); 8633db86aabSstevel } 8643db86aabSstevel #endif 8653db86aabSstevel attr.devacc_attr_version = DDI_DEVICE_ATTR_V0; 8663db86aabSstevel attr.devacc_attr_endian_flags = DDI_STRUCTURE_LE_ACC; 8673db86aabSstevel attr.devacc_attr_dataorder = DDI_STRICTORDER_ACC; 8683db86aabSstevel 8693db86aabSstevel if (ddi_regs_map_setup(dip, pci_ctrn, 8703db86aabSstevel (caddr_t *)&pcic->ioaddr, 8713db86aabSstevel PCIC_PCI_CONTROL_REG_OFFSET, 8723db86aabSstevel PCIC_CB_CONTROL_REG_LENGTH, 8733db86aabSstevel &attr, &pcic->handle) != 8743db86aabSstevel DDI_SUCCESS) { 8753db86aabSstevel cmn_err(CE_CONT, 8763db86aabSstevel "pcic%d: unable to map PCI regs\n", 8773db86aabSstevel ddi_get_instance(dip)); 8783db86aabSstevel ddi_regs_map_free(&pcic->cfg_handle); 8793db86aabSstevel kmem_free(pcic, sizeof (pcicdev_t)); 8803db86aabSstevel return (DDI_FAILURE); 8813db86aabSstevel } /* ddi_regs_map_setup */ 8823db86aabSstevel 8833db86aabSstevel /* 8843db86aabSstevel * Find out the chip type - If we're on a PCI bus, 8853db86aabSstevel * the adapter has that information in the PCI 8863db86aabSstevel * config space. 8873db86aabSstevel * Note that we call pcic_find_pci_type here since 8883db86aabSstevel * it needs a valid mapped pcic->handle to 8893db86aabSstevel * access some of the adapter registers in 8903db86aabSstevel * some cases. 8913db86aabSstevel */ 8923db86aabSstevel if (pcic_find_pci_type(pcic) != DDI_SUCCESS) { 8933db86aabSstevel ddi_regs_map_free(&pcic->handle); 8943db86aabSstevel ddi_regs_map_free(&pcic->cfg_handle); 8953db86aabSstevel kmem_free(pcic, sizeof (pcicdev_t)); 8963db86aabSstevel cmn_err(CE_WARN, "pcic: %s: unsupported " 8973db86aabSstevel "bridge\n", 8983db86aabSstevel ddi_get_name_addr(dip)); 8993db86aabSstevel return (DDI_FAILURE); 9003db86aabSstevel } 9013db86aabSstevel break; 9023db86aabSstevel 9033db86aabSstevel default: 9043db86aabSstevel case PCIC_PCI_PCMCIA: 9053db86aabSstevel /* 9063db86aabSstevel * Get access to the adapter IO registers on the 9073db86aabSstevel * PCI bus config space. 9083db86aabSstevel */ 9093db86aabSstevel attr.devacc_attr_version = DDI_DEVICE_ATTR_V0; 9103db86aabSstevel attr.devacc_attr_endian_flags = DDI_STRUCTURE_LE_ACC; 9113db86aabSstevel attr.devacc_attr_dataorder = DDI_STRICTORDER_ACC; 9123db86aabSstevel 9133db86aabSstevel /* 9143db86aabSstevel * We need a default mapping to the adapter's IO 9153db86aabSstevel * control register space. For most adapters 9163db86aabSstevel * that are of class PCIC_PCI_PCMCIA (or of 9173db86aabSstevel * a default class) the control registers 9183db86aabSstevel * will be using the 82365-type control/data 9193db86aabSstevel * format. 9203db86aabSstevel */ 9213db86aabSstevel if (ddi_regs_map_setup(dip, pci_ctrn, 9223db86aabSstevel (caddr_t *)&pcic->ioaddr, 9233db86aabSstevel PCIC_PCI_CONTROL_REG_OFFSET, 9243db86aabSstevel PCIC_PCI_CONTROL_REG_LENGTH, 9253db86aabSstevel &attr, 9263db86aabSstevel &pcic->handle) != DDI_SUCCESS) { 9273db86aabSstevel cmn_err(CE_CONT, 9283db86aabSstevel "pcic%d: unable to map PCI regs\n", 9293db86aabSstevel ddi_get_instance(dip)); 9303db86aabSstevel ddi_regs_map_free(&pcic->cfg_handle); 9313db86aabSstevel kmem_free(pcic, sizeof (pcicdev_t)); 9323db86aabSstevel return (DDI_FAILURE); 9333db86aabSstevel } /* ddi_regs_map_setup */ 9343db86aabSstevel 9353db86aabSstevel /* 9363db86aabSstevel * Find out the chip type - If we're on a PCI bus, 9373db86aabSstevel * the adapter has that information in the PCI 9383db86aabSstevel * config space. 9393db86aabSstevel * Note that we call pcic_find_pci_type here since 9403db86aabSstevel * it needs a valid mapped pcic->handle to 9413db86aabSstevel * access some of the adapter registers in 9423db86aabSstevel * some cases. 9433db86aabSstevel */ 9443db86aabSstevel if (pcic_find_pci_type(pcic) != DDI_SUCCESS) { 9453db86aabSstevel ddi_regs_map_free(&pcic->handle); 9463db86aabSstevel ddi_regs_map_free(&pcic->cfg_handle); 9473db86aabSstevel kmem_free(pcic, sizeof (pcicdev_t)); 9483db86aabSstevel cmn_err(CE_WARN, "pcic: %s: unsupported " 9493db86aabSstevel "bridge\n", 9503db86aabSstevel ddi_get_name_addr(dip)); 9513db86aabSstevel return (DDI_FAILURE); 9523db86aabSstevel } 9533db86aabSstevel 9543db86aabSstevel /* 9553db86aabSstevel * Some PCI-PCMCIA(R2) adapters are Yenta-compliant 9563db86aabSstevel * for extended registers even though they are 9573db86aabSstevel * not CardBus adapters. For those adapters, 9583db86aabSstevel * re-map pcic->handle to be large enough to 9593db86aabSstevel * encompass the Yenta registers. 9603db86aabSstevel */ 9613db86aabSstevel switch (pcic->pc_type) { 9623db86aabSstevel case PCIC_TI_PCI1031: 9633db86aabSstevel ddi_regs_map_free(&pcic->handle); 9643db86aabSstevel 9653db86aabSstevel if (ddi_regs_map_setup(dip, 9663db86aabSstevel PCIC_PCI_CONTROL_REG_NUM, 9673db86aabSstevel (caddr_t *)&pcic->ioaddr, 9683db86aabSstevel PCIC_PCI_CONTROL_REG_OFFSET, 9693db86aabSstevel PCIC_CB_CONTROL_REG_LENGTH, 9703db86aabSstevel &attr, 9713db86aabSstevel &pcic->handle) != DDI_SUCCESS) { 9723db86aabSstevel cmn_err(CE_CONT, 9733db86aabSstevel "pcic%d: unable to map " 9743db86aabSstevel "PCI regs\n", 9753db86aabSstevel ddi_get_instance(dip)); 9763db86aabSstevel ddi_regs_map_free(&pcic->cfg_handle); 9773db86aabSstevel kmem_free(pcic, sizeof (pcicdev_t)); 9783db86aabSstevel return (DDI_FAILURE); 9793db86aabSstevel } /* ddi_regs_map_setup */ 9803db86aabSstevel break; 9813db86aabSstevel default: 9823db86aabSstevel break; 9833db86aabSstevel } /* switch (pcic->pc_type) */ 9843db86aabSstevel break; 9853db86aabSstevel } /* switch (class_code) */ 9863db86aabSstevel } else { 9873db86aabSstevel /* 9883db86aabSstevel * We're not on a PCI bus, so assume an ISA bus type 9893db86aabSstevel * register property. Get access to the adapter IO 9903db86aabSstevel * registers on a non-PCI bus. 9913db86aabSstevel */ 9923db86aabSstevel attr.devacc_attr_version = DDI_DEVICE_ATTR_V0; 9933db86aabSstevel attr.devacc_attr_endian_flags = DDI_NEVERSWAP_ACC; 9943db86aabSstevel attr.devacc_attr_dataorder = DDI_STRICTORDER_ACC; 9953db86aabSstevel pcic->mem_reg_num = PCIC_ISA_MEM_REG_NUM; 9963db86aabSstevel pcic->io_reg_num = PCIC_ISA_IO_REG_NUM; 9973db86aabSstevel 9983db86aabSstevel if (ddi_regs_map_setup(dip, PCIC_ISA_CONTROL_REG_NUM, 9993db86aabSstevel (caddr_t *)&pcic->ioaddr, 10003db86aabSstevel PCIC_ISA_CONTROL_REG_OFFSET, 10013db86aabSstevel PCIC_ISA_CONTROL_REG_LENGTH, 10023db86aabSstevel &attr, 10033db86aabSstevel &pcic->handle) != DDI_SUCCESS) { 10043db86aabSstevel cmn_err(CE_CONT, 10053db86aabSstevel "pcic%d: unable to map ISA registers\n", 10063db86aabSstevel ddi_get_instance(dip)); 10073db86aabSstevel 10083db86aabSstevel kmem_free(pcic, sizeof (pcicdev_t)); 10093db86aabSstevel return (DDI_FAILURE); 10103db86aabSstevel } /* ddi_regs_map_setup */ 10113db86aabSstevel 10123db86aabSstevel /* ISA bus is limited to 24-bits, but not first 640K */ 10133db86aabSstevel pcic->pc_base = 0xd0000; 10143db86aabSstevel pcic->pc_bound = (uint32_t)~0; 10153db86aabSstevel pcic->pc_iobase = 0x1000; 10163db86aabSstevel pcic->pc_iobound = 0xefff; 10173db86aabSstevel } /* !PCF_PCIBUS */ 10183db86aabSstevel 10193db86aabSstevel #ifdef PCIC_DEBUG 10203db86aabSstevel if (pcic_debug) { 10213db86aabSstevel cmn_err(CE_CONT, "pcic_attach pc_flags=%x pc_type=%x\n", 10223db86aabSstevel pcic->pc_flags, pcic->pc_type); 10233db86aabSstevel } 10243db86aabSstevel #endif 10253db86aabSstevel 10263db86aabSstevel /* 10273db86aabSstevel * Setup various adapter registers for the PCI case. For the 10283db86aabSstevel * non-PCI case, find out the chip type. 10293db86aabSstevel */ 10303db86aabSstevel if (pcic->pc_flags & PCF_PCIBUS) { 10313db86aabSstevel int iline; 10323db86aabSstevel #if defined(__sparc) 10333db86aabSstevel iline = 0; 10343db86aabSstevel #else 10353db86aabSstevel iline = cardbus_validate_iline(dip, pcic->cfg_handle); 10363db86aabSstevel #endif 10373db86aabSstevel 10383db86aabSstevel /* set flags and socket counts based on chip type */ 10393db86aabSstevel switch (pcic->pc_type) { 10403db86aabSstevel uint32_t cfg; 10413db86aabSstevel case PCIC_INTEL_i82092: 10423db86aabSstevel cfg = ddi_get8(pcic->cfg_handle, 10433db86aabSstevel pcic->cfgaddr + PCIC_82092_PCICON); 10443db86aabSstevel /* we can only support 4 Socket version */ 10453db86aabSstevel if (cfg & PCIC_82092_4_SOCKETS) { 10463db86aabSstevel pcic->pc_numsockets = 4; 10473db86aabSstevel pcic->pc_type = PCIC_INTEL_i82092; 10483db86aabSstevel if (iline != 0xFF) 10493db86aabSstevel pcic->pc_intr_mode = PCIC_INTR_MODE_PCI_1; 10503db86aabSstevel else 10513db86aabSstevel pcic->pc_intr_mode = PCIC_INTR_MODE_ISA; 10523db86aabSstevel } else { 10533db86aabSstevel cmn_err(CE_CONT, 10543db86aabSstevel "pcic%d: Intel 82092 adapter " 10553db86aabSstevel "in unsupported configuration: 0x%x", 10563db86aabSstevel ddi_get_instance(pcic->dip), cfg); 10573db86aabSstevel pcic->pc_numsockets = 0; 10583db86aabSstevel } /* PCIC_82092_4_SOCKETS */ 10593db86aabSstevel break; 10603db86aabSstevel case PCIC_CL_PD6730: 10613db86aabSstevel case PCIC_CL_PD6729: 10623db86aabSstevel pcic->pc_intr_mode = PCIC_INTR_MODE_PCI_1; 10633db86aabSstevel cfg = ddi_getprop(DDI_DEV_T_ANY, dip, 10643db86aabSstevel DDI_PROP_CANSLEEP, 10653db86aabSstevel "interrupts", 0); 10663db86aabSstevel /* if not interrupt pin then must use ISA style IRQs */ 10673db86aabSstevel if (cfg == 0 || iline == 0xFF) 10683db86aabSstevel pcic->pc_intr_mode = PCIC_INTR_MODE_ISA; 10693db86aabSstevel else { 10703db86aabSstevel /* 10713db86aabSstevel * we have the option to use PCI interrupts. 10723db86aabSstevel * this might not be optimal but in some cases 10733db86aabSstevel * is the only thing possible (sparc case). 10743db86aabSstevel * we now deterine what is possible. 10753db86aabSstevel */ 10763db86aabSstevel pcic->pc_intr_mode = PCIC_INTR_MODE_PCI_1; 10773db86aabSstevel } 10783db86aabSstevel pcic->pc_numsockets = 2; 10793db86aabSstevel pcic->pc_flags |= PCF_IO_REMAP; 10803db86aabSstevel break; 10813db86aabSstevel case PCIC_TI_PCI1031: 10823db86aabSstevel /* this chip doesn't do CardBus but looks like one */ 10833db86aabSstevel pcic->pc_flags &= ~PCF_CARDBUS; 10843db86aabSstevel /* FALLTHROUGH */ 10853db86aabSstevel default: 10863db86aabSstevel pcic->pc_flags |= PCF_IO_REMAP; 10873db86aabSstevel /* FALLTHROUGH */ 10883db86aabSstevel /* indicate feature even if not supported */ 10893db86aabSstevel pcic->pc_flags |= PCF_DMA | PCF_ZV; 10903db86aabSstevel /* Not sure if these apply to all these chips */ 10913db86aabSstevel pcic->pc_flags |= (PCF_VPPX|PCF_33VCAP); 10923db86aabSstevel pcic->pc_flags |= pcic_use_cbpwrctl; 10933db86aabSstevel 10943db86aabSstevel pcic->pc_numsockets = 1; /* one per function */ 10953db86aabSstevel if (iline != 0xFF) { 10963db86aabSstevel uint8_t cfg; 10973db86aabSstevel pcic->pc_intr_mode = PCIC_INTR_MODE_PCI_1; 10983db86aabSstevel 10993db86aabSstevel cfg = ddi_get8(pcic->cfg_handle, 11003db86aabSstevel (pcic->cfgaddr + PCIC_BRIDGE_CTL_REG)); 11013db86aabSstevel cfg &= (~PCIC_FUN_INT_MOD_ISA); 11023db86aabSstevel ddi_put8(pcic->cfg_handle, (pcic->cfgaddr + 11033db86aabSstevel PCIC_BRIDGE_CTL_REG), cfg); 11043db86aabSstevel } 11053db86aabSstevel else 11063db86aabSstevel pcic->pc_intr_mode = PCIC_INTR_MODE_ISA; 11073db86aabSstevel pcic->pc_io_type = PCIC_IOTYPE_YENTA; 11083db86aabSstevel break; 11093db86aabSstevel } 11103db86aabSstevel } else { 11113db86aabSstevel /* 11123db86aabSstevel * We're not on a PCI bus so do some more 11133db86aabSstevel * checking for adapter type here. 11143db86aabSstevel * For the non-PCI bus case: 11153db86aabSstevel * It could be any one of a number of different chips 11163db86aabSstevel * If we can't determine anything else, it is assumed 11173db86aabSstevel * to be an Intel 82365SL. The Cirrus Logic PD6710 11183db86aabSstevel * has an extension register that provides unique 11193db86aabSstevel * identification. Toshiba chip isn't detailed as yet. 11203db86aabSstevel */ 11213db86aabSstevel 11223db86aabSstevel /* Init the CL id mode */ 11233db86aabSstevel pcic_putb(pcic, 0, PCIC_CHIP_INFO, 0); 11243db86aabSstevel value = pcic_getb(pcic, 0, PCIC_CHIP_INFO); 11253db86aabSstevel 11263db86aabSstevel /* default to Intel i82365SL and then refine */ 11273db86aabSstevel pcic->pc_type = PCIC_I82365SL; 11283db86aabSstevel pcic->pc_chipname = PCIC_TYPE_I82365SL; 11293db86aabSstevel for (value = 0; pcic_ci_funcs[value] != NULL; value++) { 11303db86aabSstevel /* go until one succeeds or none left */ 11313db86aabSstevel if (pcic_ci_funcs[value](pcic)) 11323db86aabSstevel break; 11333db86aabSstevel } 11343db86aabSstevel 11353db86aabSstevel /* any chip specific flags get set here */ 11363db86aabSstevel switch (pcic->pc_type) { 11373db86aabSstevel case PCIC_CL_PD6722: 11383db86aabSstevel pcic->pc_flags |= PCF_DMA; 11393db86aabSstevel } 11403db86aabSstevel 11413db86aabSstevel for (i = 0; i < PCIC_MAX_SOCKETS; i++) { 11423db86aabSstevel /* 11433db86aabSstevel * look for total number of sockets. 11443db86aabSstevel * basically check each possible socket for 11453db86aabSstevel * presence like in probe 11463db86aabSstevel */ 11473db86aabSstevel 11483db86aabSstevel /* turn all windows off */ 11493db86aabSstevel pcic_putb(pcic, i, PCIC_MAPPING_ENABLE, 0); 11503db86aabSstevel value = pcic_getb(pcic, i, PCIC_MAPPING_ENABLE); 11513db86aabSstevel 11523db86aabSstevel /* 11533db86aabSstevel * if a zero is read back, then this socket 11543db86aabSstevel * might be present. It would be except for 11553db86aabSstevel * some systems that map the secondary PCIC 11563db86aabSstevel * chip space back to the first. 11573db86aabSstevel */ 11583db86aabSstevel if (value != 0) { 11593db86aabSstevel /* definitely not so skip */ 11603db86aabSstevel /* note: this is for Compaq support */ 11613db86aabSstevel continue; 11623db86aabSstevel } 11633db86aabSstevel 11643db86aabSstevel /* further tests */ 11653db86aabSstevel value = pcic_getb(pcic, i, PCIC_CHIP_REVISION) & 11663db86aabSstevel PCIC_REV_MASK; 11673db86aabSstevel if (!(value >= PCIC_REV_LEVEL_LOW && 11683db86aabSstevel value <= PCIC_REV_LEVEL_HI)) 11693db86aabSstevel break; 11703db86aabSstevel 11713db86aabSstevel pcic_putb(pcic, i, PCIC_SYSMEM_0_STARTLOW, 0xaa); 11723db86aabSstevel pcic_putb(pcic, i, PCIC_SYSMEM_1_STARTLOW, 0x55); 11733db86aabSstevel value = pcic_getb(pcic, i, PCIC_SYSMEM_0_STARTLOW); 11743db86aabSstevel 11753db86aabSstevel j = pcic_getb(pcic, i, PCIC_SYSMEM_1_STARTLOW); 11763db86aabSstevel if (value != 0xaa || j != 0x55) 11773db86aabSstevel break; 11783db86aabSstevel 11793db86aabSstevel /* 11803db86aabSstevel * at this point we know if we have hardware 11813db86aabSstevel * of some type and not just the bus holding 11823db86aabSstevel * a pattern for us. We still have to determine 11833db86aabSstevel * the case where more than 2 sockets are 11843db86aabSstevel * really the same due to peculiar mappings of 11853db86aabSstevel * hardware. 11863db86aabSstevel */ 11873db86aabSstevel j = pcic->pc_numsockets++; 11883db86aabSstevel pcic->pc_sockets[j].pcs_flags = 0; 11893db86aabSstevel pcic->pc_sockets[j].pcs_io = pcic->ioaddr; 11903db86aabSstevel pcic->pc_sockets[j].pcs_socket = i; 11913db86aabSstevel 11923db86aabSstevel /* put PC Card into RESET, just in case */ 11933db86aabSstevel value = pcic_getb(pcic, i, PCIC_INTERRUPT); 11943db86aabSstevel pcic_putb(pcic, i, PCIC_INTERRUPT, 11953db86aabSstevel value & ~PCIC_RESET); 11963db86aabSstevel } 11973db86aabSstevel 11983db86aabSstevel #if defined(PCIC_DEBUG) 11993db86aabSstevel if (pcic_debug) 12003db86aabSstevel cmn_err(CE_CONT, "num sockets = %d\n", 12013db86aabSstevel pcic->pc_numsockets); 12023db86aabSstevel #endif 12033db86aabSstevel if (pcic->pc_numsockets == 0) { 12043db86aabSstevel ddi_regs_map_free(&pcic->handle); 12053db86aabSstevel kmem_free(pcic, sizeof (pcicdev_t)); 12063db86aabSstevel return (DDI_FAILURE); 12073db86aabSstevel } 12083db86aabSstevel 12093db86aabSstevel /* 12103db86aabSstevel * need to think this through again in light of 12113db86aabSstevel * Compaq not following the model that all the 12123db86aabSstevel * chip vendors recommend. IBM 755 seems to be 12133db86aabSstevel * afflicted as well. Basically, if the vendor 12143db86aabSstevel * wired things wrong, socket 0 responds for socket 2 12153db86aabSstevel * accesses, etc. 12163db86aabSstevel */ 12173db86aabSstevel if (pcic->pc_numsockets > 2) { 12183db86aabSstevel int count = pcic->pc_numsockets / 4; 12193db86aabSstevel for (i = 0; i < count; i++) { 12203db86aabSstevel /* put pattern into socket 0 */ 12213db86aabSstevel pcic_putb(pcic, i, 12223db86aabSstevel PCIC_SYSMEM_0_STARTLOW, 0x11); 12233db86aabSstevel 12243db86aabSstevel /* put pattern into socket 2 */ 12253db86aabSstevel pcic_putb(pcic, i + 2, 12263db86aabSstevel PCIC_SYSMEM_0_STARTLOW, 0x33); 12273db86aabSstevel 12283db86aabSstevel /* read back socket 0 */ 12293db86aabSstevel value = pcic_getb(pcic, i, 12303db86aabSstevel PCIC_SYSMEM_0_STARTLOW); 12313db86aabSstevel 12323db86aabSstevel /* read back chip 1 socket 0 */ 12333db86aabSstevel j = pcic_getb(pcic, i + 2, 12343db86aabSstevel PCIC_SYSMEM_0_STARTLOW); 12353db86aabSstevel if (j == value) { 12363db86aabSstevel pcic->pc_numsockets -= 2; 12373db86aabSstevel } 12383db86aabSstevel } 12393db86aabSstevel } 12403db86aabSstevel 12413db86aabSstevel smi = 0xff; /* no more override */ 12423db86aabSstevel 12433db86aabSstevel if (ddi_getprop(DDI_DEV_T_NONE, dip, 12443db86aabSstevel DDI_PROP_DONTPASS, "need-mult-irq", 12453db86aabSstevel 0xffff) != 0xffff) 12463db86aabSstevel pcic->pc_flags |= PCF_MULT_IRQ; 12473db86aabSstevel 12483db86aabSstevel } /* !PCF_PCIBUS */ 12493db86aabSstevel 12503db86aabSstevel /* 12513db86aabSstevel * some platforms/busses need to have resources setup 12523db86aabSstevel * this is temporary until a real resource allocator is 12533db86aabSstevel * implemented. 12543db86aabSstevel */ 12553db86aabSstevel 12563db86aabSstevel pcic_init_assigned(dip); 12573db86aabSstevel 12583db86aabSstevel typename = pcic->pc_chipname; 12593db86aabSstevel 12603db86aabSstevel #ifdef PCIC_DEBUG 12613db86aabSstevel if (pcic_debug) { 12623db86aabSstevel int nregs, nintrs; 12633db86aabSstevel 12643db86aabSstevel if (ddi_dev_nregs(dip, &nregs) != DDI_SUCCESS) 12653db86aabSstevel nregs = 0; 12663db86aabSstevel 12673db86aabSstevel if (ddi_dev_nintrs(dip, &nintrs) != DDI_SUCCESS) 12683db86aabSstevel nintrs = 0; 12693db86aabSstevel 12703db86aabSstevel cmn_err(CE_CONT, 12713db86aabSstevel "pcic%d: %d register sets, %d interrupts\n", 12723db86aabSstevel ddi_get_instance(dip), nregs, nintrs); 12733db86aabSstevel 12743db86aabSstevel nintrs = 0; 12753db86aabSstevel while (nregs--) { 12763db86aabSstevel off_t size; 12773db86aabSstevel 12783db86aabSstevel if (ddi_dev_regsize(dip, nintrs, &size) == 12793db86aabSstevel DDI_SUCCESS) { 12803db86aabSstevel cmn_err(CE_CONT, 12813db86aabSstevel "\tregnum %d size %ld (0x%lx)" 12823db86aabSstevel "bytes", 12833db86aabSstevel nintrs, size, size); 12843db86aabSstevel if (nintrs == 12853db86aabSstevel (pcic->pc_io_type == PCIC_IO_TYPE_82365SL ? 12863db86aabSstevel PCIC_ISA_CONTROL_REG_NUM : 12873db86aabSstevel PCIC_PCI_CONTROL_REG_NUM)) 12883db86aabSstevel cmn_err(CE_CONT, 12893db86aabSstevel " mapped at: 0x%p\n", 12903db86aabSstevel (void *)pcic->ioaddr); 12913db86aabSstevel else 12923db86aabSstevel cmn_err(CE_CONT, "\n"); 12933db86aabSstevel } else { 12943db86aabSstevel cmn_err(CE_CONT, 12953db86aabSstevel "\tddi_dev_regsize(rnumber" 12963db86aabSstevel "= %d) returns DDI_FAILURE\n", 12973db86aabSstevel nintrs); 12983db86aabSstevel } 12993db86aabSstevel nintrs++; 13003db86aabSstevel } /* while */ 13013db86aabSstevel } /* if (pcic_debug) */ 13023db86aabSstevel #endif 13033db86aabSstevel 13043db86aabSstevel cv_init(&pcic->pm_cv, NULL, CV_DRIVER, NULL); 13053db86aabSstevel 13063db86aabSstevel if (!ddi_getprop(DDI_DEV_T_NONE, dip, DDI_PROP_DONTPASS, 13073db86aabSstevel "disable-audio", 0)) 13083db86aabSstevel pcic->pc_flags |= PCF_AUDIO; 13093db86aabSstevel 13103db86aabSstevel if (ddi_getprop(DDI_DEV_T_ANY, dip, DDI_PROP_CANSLEEP, 13113db86aabSstevel "disable-cardbus", 0)) 13123db86aabSstevel pcic->pc_flags &= ~PCF_CARDBUS; 13133db86aabSstevel 13143db86aabSstevel (void) ddi_prop_update_string(DDI_DEV_T_NONE, dip, PCICPROP_CTL, 13153db86aabSstevel typename); 13163db86aabSstevel 13173db86aabSstevel /* 13183db86aabSstevel * Init all socket SMI levels to 0 (no SMI) 13193db86aabSstevel */ 13203db86aabSstevel for (i = 0; i < PCIC_MAX_SOCKETS; i++) { 13213db86aabSstevel pcic->pc_sockets[i].pcs_smi = 0; 13223db86aabSstevel pcic->pc_sockets[i].pcs_debounce_id = 0; 13233db86aabSstevel pcic->pc_sockets[i].pcs_pcic = pcic; 13243db86aabSstevel } 13253db86aabSstevel pcic->pc_lastreg = -1; /* just to make sure we are in sync */ 13263db86aabSstevel 13273db86aabSstevel /* 13283db86aabSstevel * Setup the IRQ handler(s) 13293db86aabSstevel */ 13303db86aabSstevel switch (pcic->pc_intr_mode) { 13313db86aabSstevel int xx; 13323db86aabSstevel case PCIC_INTR_MODE_ISA: 13333db86aabSstevel /* 13343db86aabSstevel * On a non-PCI bus, we just use whatever SMI IRQ level was 13353db86aabSstevel * specified above, and the IO IRQ levels are allocated 13363db86aabSstevel * dynamically. 13373db86aabSstevel */ 13383db86aabSstevel for (xx = 15, smi = 0; xx >= 0; xx--) { 13393db86aabSstevel if (PCIC_IRQ(xx) & 13403db86aabSstevel PCIC_AVAIL_IRQS) { 13413db86aabSstevel smi = pcmcia_get_intr(dip, xx); 13423db86aabSstevel if (smi >= 0) 13433db86aabSstevel break; 13443db86aabSstevel } 13453db86aabSstevel } 13463db86aabSstevel #if defined(PCIC_DEBUG) 13473db86aabSstevel if (pcic_debug) 13483db86aabSstevel cmn_err(CE_NOTE, "\tselected IRQ %d as SMI\n", smi); 13493db86aabSstevel #endif 13503db86aabSstevel /* init to same so share is easy */ 13513db86aabSstevel for (i = 0; i < pcic->pc_numsockets; i++) 13523db86aabSstevel pcic->pc_sockets[i].pcs_smi = smi; 13533db86aabSstevel /* any special handling of IRQ levels */ 13543db86aabSstevel if (pcic->pc_flags & PCF_MULT_IRQ) { 13553db86aabSstevel for (i = 2; i < pcic->pc_numsockets; i++) { 13563db86aabSstevel if ((i & 1) == 0) { 13573db86aabSstevel int xx; 13583db86aabSstevel for (xx = 15, smi = 0; xx >= 0; xx--) { 13593db86aabSstevel if (PCIC_IRQ(xx) & 13603db86aabSstevel PCIC_AVAIL_IRQS) { 13613db86aabSstevel smi = 13623db86aabSstevel pcmcia_get_intr(dip, 13633db86aabSstevel xx); 13643db86aabSstevel if (smi >= 0) 13653db86aabSstevel break; 13663db86aabSstevel } 13673db86aabSstevel } 13683db86aabSstevel } 13693db86aabSstevel if (smi >= 0) 13703db86aabSstevel pcic->pc_sockets[i].pcs_smi = smi; 13713db86aabSstevel } 13723db86aabSstevel } 13733db86aabSstevel pcic->pc_intr_htblp = kmem_alloc(pcic->pc_numsockets * 13743db86aabSstevel sizeof (ddi_intr_handle_t), KM_SLEEP); 13753db86aabSstevel for (i = 0, irqlevel = -1; i < pcic->pc_numsockets; i++) { 13763db86aabSstevel struct intrspec *ispecp; 13773db86aabSstevel struct ddi_parent_private_data *pdp; 13783db86aabSstevel 13793db86aabSstevel if (irqlevel == pcic->pc_sockets[i].pcs_smi) 13803db86aabSstevel continue; 13813db86aabSstevel else { 13823db86aabSstevel irqlevel = pcic->pc_sockets[i].pcs_smi; 13833db86aabSstevel } 13843db86aabSstevel /* 13853db86aabSstevel * now convert the allocated IRQ into an intrspec 13863db86aabSstevel * and ask our parent to add it. Don't use 13873db86aabSstevel * the ddi_add_intr since we don't have a 13883db86aabSstevel * default intrspec in all cases. 13893db86aabSstevel * 13903db86aabSstevel * note: this sort of violates DDI but we don't 13913db86aabSstevel * get hardware intrspecs for many of the devices. 13923db86aabSstevel * at the same time, we know how to allocate them 13933db86aabSstevel * so we do the right thing. 13943db86aabSstevel */ 13953db86aabSstevel if (ddi_intr_alloc(dip, &pcic->pc_intr_htblp[i], 13963db86aabSstevel DDI_INTR_TYPE_FIXED, 0, 1, &actual, 13973db86aabSstevel DDI_INTR_ALLOC_NORMAL) != DDI_SUCCESS) { 13983db86aabSstevel cmn_err(CE_WARN, "%s: ddi_intr_alloc failed", 13993db86aabSstevel ddi_get_name(dip)); 14003db86aabSstevel goto isa_exit1; 14013db86aabSstevel } 14023db86aabSstevel 14033db86aabSstevel /* 14043db86aabSstevel * See earlier note: 14053db86aabSstevel * Since some devices don't have 'intrspec' 14063db86aabSstevel * we make one up in rootnex. 14073db86aabSstevel * 14083db86aabSstevel * However, it is not properly initialized as 14093db86aabSstevel * the data it needs is present in this driver 14103db86aabSstevel * and there is no interface to pass that up. 14113db86aabSstevel * Specially 'irqlevel' is very important and 14123db86aabSstevel * it is part of pcic struct. 14133db86aabSstevel * 14143db86aabSstevel * Set 'intrspec' up here; otherwise adding the 14153db86aabSstevel * interrupt will fail. 14163db86aabSstevel */ 14173db86aabSstevel pdp = ddi_get_parent_data(dip); 14183db86aabSstevel ispecp = (struct intrspec *)&pdp->par_intr[0]; 14193db86aabSstevel ispecp->intrspec_vec = irqlevel; 14203db86aabSstevel ispecp->intrspec_pri = pcic->pc_irq; 14213db86aabSstevel 14223db86aabSstevel /* Stay compatible w/ PCMCIA */ 14233db86aabSstevel pcic->pc_pri = (ddi_iblock_cookie_t) 14243db86aabSstevel (uintptr_t)pcic->pc_irq; 14253db86aabSstevel pcic->pc_dcookie.idev_priority = 14263db86aabSstevel (uintptr_t)pcic->pc_pri; 14273db86aabSstevel pcic->pc_dcookie.idev_vector = (ushort_t)irqlevel; 14283db86aabSstevel 14293db86aabSstevel (void) ddi_intr_set_pri(pcic->pc_intr_htblp[i], 14303db86aabSstevel pcic->pc_irq); 14313db86aabSstevel 14323db86aabSstevel if (i == 0) { 14333db86aabSstevel mutex_init(&pcic->intr_lock, NULL, MUTEX_DRIVER, 14343db86aabSstevel DDI_INTR_PRI(pcic->pc_irq)); 14353db86aabSstevel mutex_init(&pcic->pc_lock, NULL, MUTEX_DRIVER, 14363db86aabSstevel NULL); 14373db86aabSstevel } 14383db86aabSstevel 14393db86aabSstevel if (ddi_intr_add_handler(pcic->pc_intr_htblp[i], 14403db86aabSstevel pcic_intr, (caddr_t)pcic, NULL)) { 14413db86aabSstevel cmn_err(CE_WARN, 14423db86aabSstevel "%s: ddi_intr_add_handler failed", 14433db86aabSstevel ddi_get_name(dip)); 14443db86aabSstevel goto isa_exit2; 14453db86aabSstevel } 14463db86aabSstevel 14473db86aabSstevel if (ddi_intr_enable(pcic->pc_intr_htblp[i])) { 14483db86aabSstevel cmn_err(CE_WARN, "%s: ddi_intr_enable failed", 14493db86aabSstevel ddi_get_name(dip)); 14503db86aabSstevel for (j = i; j < 0; j--) 14513db86aabSstevel (void) ddi_intr_remove_handler( 14523db86aabSstevel pcic->pc_intr_htblp[j]); 14533db86aabSstevel goto isa_exit2; 14543db86aabSstevel } 14553db86aabSstevel } 14563db86aabSstevel break; 14573db86aabSstevel case PCIC_INTR_MODE_PCI_1: 14583db86aabSstevel case PCIC_INTR_MODE_PCI: 14593db86aabSstevel /* 14603db86aabSstevel * If we're on a PCI bus, we route all interrupts, both SMI 14613db86aabSstevel * and IO interrupts, through a single interrupt line. 14623db86aabSstevel * Assign the SMI IRQ level to the IO IRQ level here. 14633db86aabSstevel */ 14643db86aabSstevel pcic->pc_pci_intr_hdlp = kmem_alloc(sizeof (ddi_intr_handle_t), 14653db86aabSstevel KM_SLEEP); 14663db86aabSstevel if (ddi_intr_alloc(dip, pcic->pc_pci_intr_hdlp, 14673db86aabSstevel DDI_INTR_TYPE_FIXED, 0, 1, &actual, 14683db86aabSstevel DDI_INTR_ALLOC_NORMAL) != DDI_SUCCESS) 14693db86aabSstevel goto pci_exit1; 14703db86aabSstevel 14713db86aabSstevel if (ddi_intr_get_pri(pcic->pc_pci_intr_hdlp[0], 14723db86aabSstevel &pri) != DDI_SUCCESS) { 14733db86aabSstevel (void) ddi_intr_free(pcic->pc_pci_intr_hdlp[0]); 14743db86aabSstevel goto pci_exit1; 14753db86aabSstevel } 14763db86aabSstevel 14773db86aabSstevel pcic->pc_pri = (void *)(uintptr_t)pri; 14783db86aabSstevel mutex_init(&pcic->intr_lock, NULL, MUTEX_DRIVER, pcic->pc_pri); 14793db86aabSstevel mutex_init(&pcic->pc_lock, NULL, MUTEX_DRIVER, NULL); 14803db86aabSstevel 14813db86aabSstevel if (ddi_intr_add_handler(pcic->pc_pci_intr_hdlp[0], 14823db86aabSstevel pcic_intr, (caddr_t)pcic, NULL)) 14833db86aabSstevel goto pci_exit2; 14843db86aabSstevel 14853db86aabSstevel if (ddi_intr_enable(pcic->pc_pci_intr_hdlp[0])) { 14863db86aabSstevel (void) ddi_intr_remove_handler( 14873db86aabSstevel pcic->pc_pci_intr_hdlp[0]); 14883db86aabSstevel goto pci_exit2; 14893db86aabSstevel } 14903db86aabSstevel 14913db86aabSstevel /* Stay compatible w/ PCMCIA */ 14923db86aabSstevel pcic->pc_dcookie.idev_priority = (ushort_t)pri; 14933db86aabSstevel 14943db86aabSstevel /* init to same (PCI) so share is easy */ 14953db86aabSstevel for (i = 0; i < pcic->pc_numsockets; i++) 14963db86aabSstevel pcic->pc_sockets[i].pcs_smi = 0xF; /* any valid */ 14973db86aabSstevel break; 14983db86aabSstevel } 14993db86aabSstevel 15003db86aabSstevel /* 15013db86aabSstevel * Setup the adapter hardware to some reasonable defaults. 15023db86aabSstevel */ 15033db86aabSstevel mutex_enter(&pcic->pc_lock); 15043db86aabSstevel /* mark the driver state as attached */ 15053db86aabSstevel pcic->pc_flags |= PCF_ATTACHED; 15063db86aabSstevel pcic_setup_adapter(pcic); 15073db86aabSstevel 15083db86aabSstevel for (j = 0; j < pcic->pc_numsockets; j++) 15093db86aabSstevel if (ddi_intr_add_softint(dip, 15103db86aabSstevel &pcic->pc_sockets[j].pcs_cd_softint_hdl, 15113db86aabSstevel PCIC_SOFTINT_PRI_VAL, pcic_cd_softint, 15123db86aabSstevel (caddr_t)&pcic->pc_sockets[j]) != DDI_SUCCESS) 15133db86aabSstevel goto pci_exit2; 15143db86aabSstevel 15153db86aabSstevel #if defined(PCIC_DEBUG) 15163db86aabSstevel if (pcic_debug) 15173db86aabSstevel cmn_err(CE_CONT, "type = %s sockets = %d\n", typename, 15183db86aabSstevel pcic->pc_numsockets); 15193db86aabSstevel #endif 15203db86aabSstevel 15213db86aabSstevel pcic_nexus->an_iblock = &pcic->pc_pri; 15223db86aabSstevel pcic_nexus->an_idev = &pcic->pc_dcookie; 15233db86aabSstevel 15243db86aabSstevel mutex_exit(&pcic->pc_lock); 15253db86aabSstevel 15263db86aabSstevel #ifdef CARDBUS 15273db86aabSstevel (void) cardbus_enable_cd_intr(dip); 15283db86aabSstevel if (pcic_debug) { 15293db86aabSstevel 15303db86aabSstevel cardbus_dump_pci_config(dip); 15313db86aabSstevel cardbus_dump_socket(dip); 15323db86aabSstevel } 15333db86aabSstevel 15343db86aabSstevel /* 15353db86aabSstevel * Give the Cardbus misc module a chance to do it's per-adapter 15363db86aabSstevel * instance setup. Note that there is no corresponding detach() 15373db86aabSstevel * call. 15383db86aabSstevel */ 15393db86aabSstevel if (pcic->pc_flags & PCF_CARDBUS) 15403db86aabSstevel if (cardbus_attach(dip, &pcic_cbnexus_ops) != DDI_SUCCESS) { 15413db86aabSstevel cmn_err(CE_CONT, 15423db86aabSstevel "pcic_attach: cardbus_attach failed\n"); 15433db86aabSstevel goto pci_exit2; 15443db86aabSstevel } 15453db86aabSstevel #endif 15463db86aabSstevel 15473db86aabSstevel /* 15483db86aabSstevel * Give the PCMCIA misc module a chance to do it's per-adapter 15493db86aabSstevel * instance setup. 15503db86aabSstevel */ 15513db86aabSstevel if ((i = pcmcia_attach(dip, pcic_nexus)) != DDI_SUCCESS) 15523db86aabSstevel goto pci_exit2; 15533db86aabSstevel 15543db86aabSstevel if (pcic_maxinst == -1) { 15553db86aabSstevel /* This assumes that all instances run at the same IPL. */ 15563db86aabSstevel mutex_init(&pcic_deb_mtx, NULL, MUTEX_DRIVER, NULL); 15573db86aabSstevel cv_init(&pcic_deb_cv, NULL, CV_DRIVER, NULL); 15583db86aabSstevel pcic_deb_threadid = thread_create((caddr_t)NULL, 0, 15593db86aabSstevel pcic_deb_thread, (caddr_t)NULL, 0, &p0, TS_RUN, 15603db86aabSstevel v.v_maxsyspri - 2); 15613db86aabSstevel } 15623db86aabSstevel pcic_maxinst = max(pcic_maxinst, ddi_get_instance(dip)); 15633db86aabSstevel /* 15643db86aabSstevel * Setup a debounce timeout to do an initial card detect 15653db86aabSstevel * and enable interrupts. 15663db86aabSstevel */ 15673db86aabSstevel for (j = 0; j < pcic->pc_numsockets; j++) { 15683db86aabSstevel pcic->pc_sockets[j].pcs_debounce_id = 15693db86aabSstevel pcic_add_debqueue(&pcic->pc_sockets[j], 15703db86aabSstevel drv_usectohz(pcic_debounce_time)); 15713db86aabSstevel } 15723db86aabSstevel 15733db86aabSstevel return (i); 15743db86aabSstevel 15753db86aabSstevel isa_exit2: 15763db86aabSstevel mutex_destroy(&pcic->intr_lock); 15773db86aabSstevel mutex_destroy(&pcic->pc_lock); 15783db86aabSstevel for (j = i; j < 0; j--) 15793db86aabSstevel (void) ddi_intr_free(pcic->pc_intr_htblp[j]); 15803db86aabSstevel isa_exit1: 15813db86aabSstevel (void) pcmcia_return_intr(dip, pcic->pc_sockets[i].pcs_smi); 15823db86aabSstevel ddi_regs_map_free(&pcic->handle); 15833db86aabSstevel if (pcic->pc_flags & PCF_PCIBUS) 15843db86aabSstevel ddi_regs_map_free(&pcic->cfg_handle); 15853db86aabSstevel kmem_free(pcic->pc_intr_htblp, pcic->pc_numsockets * 15863db86aabSstevel sizeof (ddi_intr_handle_t)); 15873db86aabSstevel kmem_free(pcic, sizeof (pcicdev_t)); 15883db86aabSstevel return (DDI_FAILURE); 15893db86aabSstevel 15903db86aabSstevel pci_exit2: 15913db86aabSstevel mutex_destroy(&pcic->intr_lock); 15923db86aabSstevel mutex_destroy(&pcic->pc_lock); 15933db86aabSstevel (void) ddi_intr_free(pcic->pc_pci_intr_hdlp[0]); 15943db86aabSstevel pci_exit1: 15953db86aabSstevel ddi_regs_map_free(&pcic->handle); 15963db86aabSstevel if (pcic->pc_flags & PCF_PCIBUS) 15973db86aabSstevel ddi_regs_map_free(&pcic->cfg_handle); 15983db86aabSstevel kmem_free(pcic->pc_pci_intr_hdlp, sizeof (ddi_intr_handle_t)); 15993db86aabSstevel kmem_free(pcic, sizeof (pcicdev_t)); 16003db86aabSstevel return (DDI_FAILURE); 16013db86aabSstevel } 16023db86aabSstevel 16033db86aabSstevel /* 16043db86aabSstevel * pcic_detach() 16053db86aabSstevel * request to detach from the system 16063db86aabSstevel */ 16073db86aabSstevel static int 16083db86aabSstevel pcic_detach(dev_info_t *dip, ddi_detach_cmd_t cmd) 16093db86aabSstevel { 16103db86aabSstevel anp_t *anp = ddi_get_driver_private(dip); 16113db86aabSstevel pcicdev_t *pcic = anp->an_private; 16123db86aabSstevel int i; 16133db86aabSstevel 16143db86aabSstevel switch (cmd) { 16153db86aabSstevel case DDI_DETACH: 16163db86aabSstevel /* don't detach if the nexus still talks to us */ 16173db86aabSstevel if (pcic->pc_callback != NULL) 16183db86aabSstevel return (DDI_FAILURE); 16193db86aabSstevel 16203db86aabSstevel /* kill off the pm simulation */ 16213db86aabSstevel if (pcic->pc_pmtimer) 16223db86aabSstevel (void) untimeout(pcic->pc_pmtimer); 16233db86aabSstevel 16243db86aabSstevel /* turn everything off for all sockets and chips */ 16253db86aabSstevel for (i = 0; i < pcic->pc_numsockets; i++) { 16263db86aabSstevel if (pcic->pc_sockets[i].pcs_debounce_id) 16273db86aabSstevel pcic_rm_debqueue( 16283db86aabSstevel pcic->pc_sockets[i].pcs_debounce_id); 16293db86aabSstevel pcic->pc_sockets[i].pcs_debounce_id = 0; 16303db86aabSstevel 16313db86aabSstevel pcic_putb(pcic, i, PCIC_MANAGEMENT_INT, 0); 16323db86aabSstevel pcic_putb(pcic, i, PCIC_CARD_DETECT, 0); 16333db86aabSstevel pcic_putb(pcic, i, PCIC_MAPPING_ENABLE, 0); 16343db86aabSstevel /* disable interrupts and put card into RESET */ 16353db86aabSstevel pcic_putb(pcic, i, PCIC_INTERRUPT, 0); 16363db86aabSstevel } 16373db86aabSstevel (void) ddi_intr_disable(pcic->pc_pci_intr_hdlp[0]); 16383db86aabSstevel (void) ddi_intr_remove_handler(pcic->pc_pci_intr_hdlp[0]); 16393db86aabSstevel (void) ddi_intr_free(pcic->pc_pci_intr_hdlp[0]); 16403db86aabSstevel kmem_free(pcic->pc_pci_intr_hdlp, sizeof (ddi_intr_handle_t)); 16413db86aabSstevel pcic->pc_flags = 0; 16423db86aabSstevel mutex_destroy(&pcic->pc_lock); 16433db86aabSstevel mutex_destroy(&pcic->intr_lock); 16443db86aabSstevel cv_destroy(&pcic->pm_cv); 16453db86aabSstevel if (pcic->pc_flags & PCF_PCIBUS) 16463db86aabSstevel ddi_regs_map_free(&pcic->cfg_handle); 16473db86aabSstevel if (pcic->handle) 16483db86aabSstevel ddi_regs_map_free(&pcic->handle); 16493db86aabSstevel kmem_free(pcic, sizeof (pcicdev_t)); 16503db86aabSstevel ddi_soft_state_free(pcic_soft_state_p, ddi_get_instance(dip)); 16513db86aabSstevel return (DDI_SUCCESS); 16523db86aabSstevel 16533db86aabSstevel case DDI_SUSPEND: 16543db86aabSstevel case DDI_PM_SUSPEND: 16553db86aabSstevel /* 16563db86aabSstevel * we got a suspend event (either real or imagined) 16573db86aabSstevel * so notify the nexus proper that all existing cards 16583db86aabSstevel * should go away. 16593db86aabSstevel */ 16603db86aabSstevel mutex_enter(&pcic->pc_lock); 16613db86aabSstevel #ifdef CARDBUS 166211c2b4c0Srw148561 if (pcic->pc_flags & PCF_CARDBUS) { 166311c2b4c0Srw148561 for (i = 0; i < pcic->pc_numsockets; i++) { 16643db86aabSstevel if ((pcic->pc_sockets[i].pcs_flags & 16653db86aabSstevel (PCS_CARD_PRESENT|PCS_CARD_ISCARDBUS)) == 166611c2b4c0Srw148561 (PCS_CARD_PRESENT|PCS_CARD_ISCARDBUS)) { 166711c2b4c0Srw148561 166811c2b4c0Srw148561 pcmcia_cb_suspended( 166911c2b4c0Srw148561 pcic->pc_sockets[i].pcs_socket); 167011c2b4c0Srw148561 } 167111c2b4c0Srw148561 } 167211c2b4c0Srw148561 167311c2b4c0Srw148561 cardbus_save_children(ddi_get_child(dip)); 16743db86aabSstevel } 16753db86aabSstevel #endif 16763db86aabSstevel /* turn everything off for all sockets and chips */ 16773db86aabSstevel for (i = 0; i < pcic->pc_numsockets; i++) { 16783db86aabSstevel if (pcic->pc_sockets[i].pcs_debounce_id) 16793db86aabSstevel pcic_rm_debqueue( 16803db86aabSstevel pcic->pc_sockets[i].pcs_debounce_id); 16813db86aabSstevel pcic->pc_sockets[i].pcs_debounce_id = 0; 16823db86aabSstevel 16833db86aabSstevel pcic_putb(pcic, i, PCIC_MANAGEMENT_INT, 0); 16843db86aabSstevel pcic_putb(pcic, i, PCIC_CARD_DETECT, 0); 16853db86aabSstevel pcic_putb(pcic, i, PCIC_MAPPING_ENABLE, 0); 16863db86aabSstevel /* disable interrupts and put card into RESET */ 16873db86aabSstevel pcic_putb(pcic, i, PCIC_INTERRUPT, 0); 16883db86aabSstevel pcic_putb(pcic, i, PCIC_POWER_CONTROL, 0); 16893db86aabSstevel if (pcic->pc_flags & PCF_CBPWRCTL) 16903db86aabSstevel pcic_putcb(pcic, CB_CONTROL, 0); 16913db86aabSstevel 16923db86aabSstevel if (pcic->pc_sockets[i].pcs_flags & PCS_CARD_PRESENT) { 16933db86aabSstevel pcic->pc_sockets[i].pcs_flags = PCS_STARTING; 16943db86aabSstevel /* 16953db86aabSstevel * Because we are half way through a save 16963db86aabSstevel * all this does is schedule a removal event 16973db86aabSstevel * to cs for when the system comes back. 16983db86aabSstevel * This doesn't actually matter. 16993db86aabSstevel */ 17003db86aabSstevel if (!pcic_do_pcmcia_sr && pcic_do_removal && 17013db86aabSstevel pcic->pc_callback) { 17023db86aabSstevel PC_CALLBACK(pcic->dip, pcic->pc_cb_arg, 17033db86aabSstevel PCE_CARD_REMOVAL, 17043db86aabSstevel pcic->pc_sockets[i].pcs_socket); 17053db86aabSstevel } 17063db86aabSstevel } 17073db86aabSstevel } 17083db86aabSstevel 17093db86aabSstevel pcic->pc_flags |= PCF_SUSPENDED; 17103db86aabSstevel mutex_exit(&pcic->pc_lock); 17113db86aabSstevel 17123db86aabSstevel /* 17133db86aabSstevel * when true power management exists, save the adapter 17143db86aabSstevel * state here to enable a recovery. For the emulation 17153db86aabSstevel * condition, the state is gone 17163db86aabSstevel */ 17173db86aabSstevel return (DDI_SUCCESS); 17183db86aabSstevel 17193db86aabSstevel default: 17203db86aabSstevel return (EINVAL); 17213db86aabSstevel } 17223db86aabSstevel } 17233db86aabSstevel 17243db86aabSstevel static uint32_t pcic_tisysctl_onbits = ((1<<27) | (1<<15) | (1<<14)); 17253db86aabSstevel static uint32_t pcic_tisysctl_offbits = 0; 17263db86aabSstevel static uint32_t pcic_default_latency = 0x40; 17273db86aabSstevel 17283db86aabSstevel static void 17293db86aabSstevel pcic_setup_adapter(pcicdev_t *pcic) 17303db86aabSstevel { 17313db86aabSstevel int i; 17323db86aabSstevel int value, flags; 17333db86aabSstevel 17343db86aabSstevel if (pcic->pc_flags & PCF_PCIBUS) { 17353db86aabSstevel /* 17363db86aabSstevel * all PCI-to-PCMCIA bus bridges need memory and I/O enabled 17373db86aabSstevel */ 17383db86aabSstevel flags = (PCIC_ENABLE_IO | PCIC_ENABLE_MEM); 17393db86aabSstevel pcic_iomem_pci_ctl(pcic->cfg_handle, pcic->cfgaddr, flags); 17403db86aabSstevel } 17413db86aabSstevel /* enable each socket */ 17423db86aabSstevel for (i = 0; i < pcic->pc_numsockets; i++) { 17433db86aabSstevel pcic->pc_sockets[i].pcs_flags = 0; 17443db86aabSstevel /* find out the socket capabilities (I/O vs memory) */ 17453db86aabSstevel value = pcic_getb(pcic, i, 17463db86aabSstevel PCIC_CHIP_REVISION) & PCIC_REV_ID_MASK; 17473db86aabSstevel if (value == PCIC_REV_ID_IO || value == PCIC_REV_ID_BOTH) 17483db86aabSstevel pcic->pc_sockets[i].pcs_flags |= PCS_SOCKET_IO; 17493db86aabSstevel 17503db86aabSstevel /* disable all windows just in case */ 17513db86aabSstevel pcic_putb(pcic, i, PCIC_MAPPING_ENABLE, 0); 17523db86aabSstevel 17533db86aabSstevel switch (pcic->pc_type) { 17543db86aabSstevel uint32_t cfg32; 17553db86aabSstevel uint16_t cfg16; 17563db86aabSstevel uint8_t cfg; 17573db86aabSstevel 17583db86aabSstevel /* enable extended registers for Vadem */ 17593db86aabSstevel case PCIC_VADEM_VG469: 17603db86aabSstevel case PCIC_VADEM: 17613db86aabSstevel 17623db86aabSstevel /* enable card status change interrupt for socket */ 17633db86aabSstevel break; 17643db86aabSstevel 17653db86aabSstevel case PCIC_I82365SL: 17663db86aabSstevel break; 17673db86aabSstevel 17683db86aabSstevel case PCIC_CL_PD6710: 17693db86aabSstevel pcic_putb(pcic, 0, PCIC_MISC_CTL_2, PCIC_LED_ENABLE); 17703db86aabSstevel break; 17713db86aabSstevel 17723db86aabSstevel /* 17733db86aabSstevel * On the CL_6730, we need to set up the interrupt 17743db86aabSstevel * signalling mode (PCI mode) and set the SMI and 17753db86aabSstevel * IRQ interrupt lines to PCI/level-mode. 17763db86aabSstevel */ 17773db86aabSstevel case PCIC_CL_PD6730: 17783db86aabSstevel switch (pcic->pc_intr_mode) { 17793db86aabSstevel case PCIC_INTR_MODE_PCI_1: 17803db86aabSstevel clext_reg_write(pcic, i, PCIC_CLEXT_MISC_CTL_3, 17813db86aabSstevel ((clext_reg_read(pcic, i, 17823db86aabSstevel PCIC_CLEXT_MISC_CTL_3) & 17833db86aabSstevel ~PCIC_CLEXT_INT_PCI) | 17843db86aabSstevel PCIC_CLEXT_INT_PCI)); 17853db86aabSstevel clext_reg_write(pcic, i, PCIC_CLEXT_EXT_CTL_1, 17863db86aabSstevel (PCIC_CLEXT_IRQ_LVL_MODE | 17873db86aabSstevel PCIC_CLEXT_SMI_LVL_MODE)); 17883db86aabSstevel cfg = PCIC_CL_LP_DYN_MODE; 17893db86aabSstevel pcic_putb(pcic, i, PCIC_MISC_CTL_2, cfg); 17903db86aabSstevel break; 17913db86aabSstevel case PCIC_INTR_MODE_ISA: 17923db86aabSstevel break; 17933db86aabSstevel } 17943db86aabSstevel break; 17953db86aabSstevel /* 17963db86aabSstevel * On the CL_6729, we set the SMI and IRQ interrupt 17973db86aabSstevel * lines to PCI/level-mode. as well as program the 17983db86aabSstevel * correct clock speed divider bit. 17993db86aabSstevel */ 18003db86aabSstevel case PCIC_CL_PD6729: 18013db86aabSstevel switch (pcic->pc_intr_mode) { 18023db86aabSstevel case PCIC_INTR_MODE_PCI_1: 18033db86aabSstevel clext_reg_write(pcic, i, PCIC_CLEXT_EXT_CTL_1, 18043db86aabSstevel (PCIC_CLEXT_IRQ_LVL_MODE | 18053db86aabSstevel PCIC_CLEXT_SMI_LVL_MODE)); 18063db86aabSstevel 18073db86aabSstevel break; 18083db86aabSstevel case PCIC_INTR_MODE_ISA: 18093db86aabSstevel break; 18103db86aabSstevel } 18113db86aabSstevel if (pcic->bus_speed > PCIC_PCI_25MHZ && i == 0) { 18123db86aabSstevel cfg = 0; 18133db86aabSstevel cfg |= PCIC_CL_TIMER_CLK_DIV; 18143db86aabSstevel pcic_putb(pcic, i, PCIC_MISC_CTL_2, cfg); 18153db86aabSstevel } 18163db86aabSstevel break; 18173db86aabSstevel case PCIC_INTEL_i82092: 18183db86aabSstevel cfg = PCIC_82092_EN_TIMING; 18193db86aabSstevel if (pcic->bus_speed < PCIC_SYSCLK_33MHZ) 18203db86aabSstevel cfg |= PCIC_82092_PCICLK_25MHZ; 18213db86aabSstevel ddi_put8(pcic->cfg_handle, pcic->cfgaddr + 18223db86aabSstevel PCIC_82092_PCICON, cfg); 18233db86aabSstevel break; 18243db86aabSstevel case PCIC_TI_PCI1130: 18253db86aabSstevel case PCIC_TI_PCI1131: 18263db86aabSstevel case PCIC_TI_PCI1250: 18273db86aabSstevel case PCIC_TI_PCI1031: 18283db86aabSstevel cfg = ddi_get8(pcic->cfg_handle, 18293db86aabSstevel pcic->cfgaddr + PCIC_DEVCTL_REG); 18303db86aabSstevel cfg &= ~PCIC_DEVCTL_INTR_MASK; 18313db86aabSstevel switch (pcic->pc_intr_mode) { 18323db86aabSstevel case PCIC_INTR_MODE_ISA: 18333db86aabSstevel cfg |= PCIC_DEVCTL_INTR_ISA; 18343db86aabSstevel break; 18353db86aabSstevel } 18363db86aabSstevel #ifdef PCIC_DEBUG 18373db86aabSstevel if (pcic_debug) { 18383db86aabSstevel cmn_err(CE_CONT, "pcic_setup_adapter: " 18393db86aabSstevel "write reg 0x%x=%x \n", 18403db86aabSstevel PCIC_DEVCTL_REG, cfg); 18413db86aabSstevel } 18423db86aabSstevel #endif 18433db86aabSstevel ddi_put8(pcic->cfg_handle, 18443db86aabSstevel pcic->cfgaddr + PCIC_DEVCTL_REG, 18453db86aabSstevel cfg); 18463db86aabSstevel 18473db86aabSstevel cfg = ddi_get8(pcic->cfg_handle, 18483db86aabSstevel pcic->cfgaddr + PCIC_CRDCTL_REG); 18493db86aabSstevel cfg &= ~(PCIC_CRDCTL_PCIINTR|PCIC_CRDCTL_PCICSC| 18503db86aabSstevel PCIC_CRDCTL_PCIFUNC); 18513db86aabSstevel switch (pcic->pc_intr_mode) { 18523db86aabSstevel case PCIC_INTR_MODE_PCI_1: 18533db86aabSstevel cfg |= PCIC_CRDCTL_PCIINTR | 18543db86aabSstevel PCIC_CRDCTL_PCICSC | 18553db86aabSstevel PCIC_CRDCTL_PCIFUNC; 18563db86aabSstevel pcic->pc_flags |= PCF_USE_SMI; 18573db86aabSstevel break; 18583db86aabSstevel } 18593db86aabSstevel #ifdef PCIC_DEBUG 18603db86aabSstevel if (pcic_debug) { 18613db86aabSstevel cmn_err(CE_CONT, "pcic_setup_adapter: " 18623db86aabSstevel " write reg 0x%x=%x \n", 18633db86aabSstevel PCIC_CRDCTL_REG, cfg); 18643db86aabSstevel } 18653db86aabSstevel #endif 18663db86aabSstevel ddi_put8(pcic->cfg_handle, 18673db86aabSstevel pcic->cfgaddr + PCIC_CRDCTL_REG, 18683db86aabSstevel cfg); 18693db86aabSstevel break; 18703db86aabSstevel case PCIC_TI_PCI1221: 18713db86aabSstevel case PCIC_TI_PCI1225: 18723db86aabSstevel cfg = ddi_get8(pcic->cfg_handle, 18733db86aabSstevel pcic->cfgaddr + PCIC_DEVCTL_REG); 18743db86aabSstevel cfg |= (PCIC_DEVCTL_INTR_DFLT | PCIC_DEVCTL_3VCAPABLE); 18753db86aabSstevel #ifdef PCIC_DEBUG 18763db86aabSstevel if (pcic_debug) { 18773db86aabSstevel cmn_err(CE_CONT, "pcic_setup_adapter: " 18783db86aabSstevel " write reg 0x%x=%x \n", 18793db86aabSstevel PCIC_DEVCTL_REG, cfg); 18803db86aabSstevel } 18813db86aabSstevel #endif 18823db86aabSstevel ddi_put8(pcic->cfg_handle, 18833db86aabSstevel pcic->cfgaddr + PCIC_DEVCTL_REG, cfg); 18843db86aabSstevel 18853db86aabSstevel cfg = ddi_get8(pcic->cfg_handle, 18863db86aabSstevel pcic->cfgaddr + PCIC_DIAG_REG); 18873db86aabSstevel if (pcic->pc_type == PCIC_TI_PCI1225) { 18883db86aabSstevel cfg |= (PCIC_DIAG_CSC | PCIC_DIAG_ASYNC); 18893db86aabSstevel } else { 18903db86aabSstevel cfg |= PCIC_DIAG_ASYNC; 18913db86aabSstevel } 18923db86aabSstevel pcic->pc_flags |= PCF_USE_SMI; 18933db86aabSstevel #ifdef PCIC_DEBUG 18943db86aabSstevel if (pcic_debug) { 18953db86aabSstevel cmn_err(CE_CONT, "pcic_setup_adapter: " 18963db86aabSstevel " write reg 0x%x=%x \n", 18973db86aabSstevel PCIC_DIAG_REG, cfg); 18983db86aabSstevel } 18993db86aabSstevel #endif 19003db86aabSstevel ddi_put8(pcic->cfg_handle, 19013db86aabSstevel pcic->cfgaddr + PCIC_DIAG_REG, cfg); 19023db86aabSstevel break; 19033db86aabSstevel case PCIC_TI_PCI1520: 19040e995c33Srw148561 case PCIC_TI_PCI1510: 19053db86aabSstevel case PCIC_TI_VENDOR: 19063db86aabSstevel if (pcic->pc_intr_mode == PCIC_INTR_MODE_ISA) { 19073db86aabSstevel cfg = ddi_get8(pcic->cfg_handle, 19083db86aabSstevel pcic->cfgaddr + PCIC_BRIDGE_CTL_REG); 19093db86aabSstevel cfg |= PCIC_FUN_INT_MOD_ISA; 19103db86aabSstevel ddi_put8(pcic->cfg_handle, 19113db86aabSstevel pcic->cfgaddr + PCIC_BRIDGE_CTL_REG, 19123db86aabSstevel cfg); 19133db86aabSstevel } 19143db86aabSstevel cfg = ddi_get8(pcic->cfg_handle, 19153db86aabSstevel pcic->cfgaddr + PCIC_DEVCTL_REG); 19163db86aabSstevel cfg &= ~PCIC_DEVCTL_INTR_MASK; 19173db86aabSstevel if (pcic->pc_intr_mode == PCIC_INTR_MODE_ISA) 19183db86aabSstevel cfg |= PCIC_DEVCTL_INTR_ISA; 19193db86aabSstevel ddi_put8(pcic->cfg_handle, 19203db86aabSstevel pcic->cfgaddr + PCIC_DEVCTL_REG, 19213db86aabSstevel cfg); 19223db86aabSstevel 19233db86aabSstevel /* tie INTA and INTB together */ 19243db86aabSstevel cfg = ddi_get8(pcic->cfg_handle, 19253db86aabSstevel (pcic->cfgaddr + PCIC_SYSCTL_REG + 3)); 19263db86aabSstevel cfg |= PCIC_SYSCTL_INTRTIE; 19273db86aabSstevel ddi_put8(pcic->cfg_handle, (pcic->cfgaddr + 19283db86aabSstevel PCIC_SYSCTL_REG + 3), cfg); 19293db86aabSstevel cfg = ddi_get8(pcic->cfg_handle, 19303db86aabSstevel pcic->cfgaddr + PCIC_DIAG_REG); 19313db86aabSstevel cfg |= (PCIC_DIAG_CSC | PCIC_DIAG_ASYNC); 19323db86aabSstevel ddi_put8(pcic->cfg_handle, 19333db86aabSstevel pcic->cfgaddr + PCIC_DIAG_REG, cfg); 19343db86aabSstevel break; 19353db86aabSstevel case PCIC_TI_PCI1410: 19363db86aabSstevel cfg = ddi_get8(pcic->cfg_handle, 19373db86aabSstevel pcic->cfgaddr + PCIC_DIAG_REG); 19383db86aabSstevel cfg |= (PCIC_DIAG_CSC | PCIC_DIAG_ASYNC); 19393db86aabSstevel ddi_put8(pcic->cfg_handle, 19403db86aabSstevel pcic->cfgaddr + PCIC_DIAG_REG, cfg); 19413db86aabSstevel break; 19423db86aabSstevel case PCIC_TOSHIBA_TOPIC100: 19433db86aabSstevel case PCIC_TOSHIBA_TOPIC95: 19443db86aabSstevel case PCIC_TOSHIBA_VENDOR: 19453db86aabSstevel cfg = ddi_get8(pcic->cfg_handle, pcic->cfgaddr + 19463db86aabSstevel PCIC_TOSHIBA_SLOT_CTL_REG); 19473db86aabSstevel cfg |= (PCIC_TOSHIBA_SCR_SLOTON | 19483db86aabSstevel PCIC_TOSHIBA_SCR_SLOTEN); 19493db86aabSstevel cfg &= (~PCIC_TOSHIBA_SCR_PRT_MASK); 19503db86aabSstevel cfg |= PCIC_TOSHIBA_SCR_PRT_3E2; 19513db86aabSstevel ddi_put8(pcic->cfg_handle, pcic->cfgaddr + 19523db86aabSstevel PCIC_TOSHIBA_SLOT_CTL_REG, cfg); 19533db86aabSstevel cfg = ddi_get8(pcic->cfg_handle, pcic->cfgaddr + 19543db86aabSstevel PCIC_TOSHIBA_INTR_CTL_REG); 19553db86aabSstevel switch (pcic->pc_intr_mode) { 19563db86aabSstevel case PCIC_INTR_MODE_ISA: 19573db86aabSstevel cfg &= ~PCIC_TOSHIBA_ICR_SRC; 19583db86aabSstevel ddi_put8(pcic->cfg_handle, 19593db86aabSstevel pcic->cfgaddr + 19603db86aabSstevel PCIC_TOSHIBA_INTR_CTL_REG, cfg); 19613db86aabSstevel 19623db86aabSstevel cfg = ddi_get8(pcic->cfg_handle, 19633db86aabSstevel pcic->cfgaddr + PCIC_BRIDGE_CTL_REG); 19643db86aabSstevel cfg |= PCIC_FUN_INT_MOD_ISA; 19653db86aabSstevel ddi_put8(pcic->cfg_handle, 19663db86aabSstevel pcic->cfgaddr + PCIC_BRIDGE_CTL_REG, 19673db86aabSstevel cfg); 19683db86aabSstevel break; 19693db86aabSstevel case PCIC_INTR_MODE_PCI_1: 19703db86aabSstevel cfg |= PCIC_TOSHIBA_ICR_SRC; 19713db86aabSstevel cfg &= (~PCIC_TOSHIBA_ICR_PIN_MASK); 19723db86aabSstevel cfg |= PCIC_TOSHIBA_ICR_PIN_INTA; 19733db86aabSstevel ddi_put8(pcic->cfg_handle, 19743db86aabSstevel pcic->cfgaddr + 19753db86aabSstevel PCIC_TOSHIBA_INTR_CTL_REG, cfg); 19763db86aabSstevel break; 19773db86aabSstevel } 19783db86aabSstevel break; 19793db86aabSstevel case PCIC_O2MICRO_VENDOR: 19803db86aabSstevel cfg32 = ddi_get32(pcic->cfg_handle, 19813db86aabSstevel (uint32_t *)(pcic->cfgaddr + 19823db86aabSstevel PCIC_O2MICRO_MISC_CTL)); 19833db86aabSstevel switch (pcic->pc_intr_mode) { 19843db86aabSstevel case PCIC_INTR_MODE_ISA: 19853db86aabSstevel cfg32 |= (PCIC_O2MICRO_ISA_LEGACY | 19863db86aabSstevel PCIC_O2MICRO_INT_MOD_PCI); 19873db86aabSstevel ddi_put32(pcic->cfg_handle, 19883db86aabSstevel (uint32_t *)(pcic->cfgaddr + 19893db86aabSstevel PCIC_O2MICRO_MISC_CTL), 19903db86aabSstevel cfg32); 19913db86aabSstevel cfg = ddi_get8(pcic->cfg_handle, 19923db86aabSstevel pcic->cfgaddr + PCIC_BRIDGE_CTL_REG); 19933db86aabSstevel cfg |= PCIC_FUN_INT_MOD_ISA; 19943db86aabSstevel ddi_put8(pcic->cfg_handle, 19953db86aabSstevel pcic->cfgaddr + PCIC_BRIDGE_CTL_REG, 19963db86aabSstevel cfg); 19973db86aabSstevel break; 19983db86aabSstevel case PCIC_INTR_MODE_PCI_1: 19993db86aabSstevel cfg32 &= ~PCIC_O2MICRO_ISA_LEGACY; 20003db86aabSstevel cfg32 |= PCIC_O2MICRO_INT_MOD_PCI; 20013db86aabSstevel ddi_put32(pcic->cfg_handle, 20023db86aabSstevel (uint32_t *)(pcic->cfgaddr + 20033db86aabSstevel PCIC_O2MICRO_MISC_CTL), 20043db86aabSstevel cfg32); 20053db86aabSstevel break; 20063db86aabSstevel } 20073db86aabSstevel break; 20083db86aabSstevel case PCIC_RICOH_VENDOR: 20093db86aabSstevel if (pcic->pc_intr_mode == PCIC_INTR_MODE_ISA) { 20103db86aabSstevel cfg16 = ddi_get16(pcic->cfg_handle, 20113db86aabSstevel (uint16_t *)(pcic->cfgaddr + 20123db86aabSstevel PCIC_RICOH_MISC_CTL_2)); 20133db86aabSstevel cfg16 |= (PCIC_RICOH_CSC_INT_MOD | 20143db86aabSstevel PCIC_RICOH_FUN_INT_MOD); 20153db86aabSstevel ddi_put16(pcic->cfg_handle, 20163db86aabSstevel (uint16_t *)(pcic->cfgaddr + 20173db86aabSstevel PCIC_RICOH_MISC_CTL_2), 20183db86aabSstevel cfg16); 20193db86aabSstevel 20203db86aabSstevel cfg16 = ddi_get16(pcic->cfg_handle, 20213db86aabSstevel (uint16_t *)(pcic->cfgaddr + 20223db86aabSstevel PCIC_RICOH_MISC_CTL)); 20233db86aabSstevel cfg16 |= PCIC_RICOH_SIRQ_EN; 20243db86aabSstevel ddi_put16(pcic->cfg_handle, 20253db86aabSstevel (uint16_t *)(pcic->cfgaddr + 20263db86aabSstevel PCIC_RICOH_MISC_CTL), 20273db86aabSstevel cfg16); 20283db86aabSstevel 20293db86aabSstevel cfg = ddi_get8(pcic->cfg_handle, 20303db86aabSstevel pcic->cfgaddr + PCIC_BRIDGE_CTL_REG); 20313db86aabSstevel cfg |= PCIC_FUN_INT_MOD_ISA; 20323db86aabSstevel ddi_put8(pcic->cfg_handle, 20333db86aabSstevel pcic->cfgaddr + PCIC_BRIDGE_CTL_REG, 20343db86aabSstevel cfg); 20353db86aabSstevel } 20363db86aabSstevel break; 20373db86aabSstevel default: 20383db86aabSstevel break; 20393db86aabSstevel } /* switch */ 20403db86aabSstevel 2041bb3a048dSrw148561 /* 2042bb3a048dSrw148561 * The default value in the EEPROM (loaded on reset) for 2043bb3a048dSrw148561 * MFUNC0/MFUNC1 may be incorrect. Here we make sure that 2044bb3a048dSrw148561 * MFUNC0 is connected to INTA, and MFUNC1 is connected to 2045bb3a048dSrw148561 * INTB. This applies to all TI CardBus controllers. 2046bb3a048dSrw148561 */ 2047bb3a048dSrw148561 if ((pcic->pc_type >> 16) == PCIC_TI_VENDORID && 2048bb3a048dSrw148561 pcic->pc_intr_mode == PCIC_INTR_MODE_PCI_1) { 2049bb3a048dSrw148561 value = ddi_get32(pcic->cfg_handle, 2050bb3a048dSrw148561 (uint32_t *)(pcic->cfgaddr + PCIC_MFROUTE_REG)); 2051bb3a048dSrw148561 value &= ~0xff; 2052bb3a048dSrw148561 ddi_put32(pcic->cfg_handle, (uint32_t *)(pcic->cfgaddr + 20538134ee03Srw148561 PCIC_MFROUTE_REG), value|PCIC_TI_MFUNC_SEL); 2054bb3a048dSrw148561 } 2055bb3a048dSrw148561 20563db86aabSstevel /* setup general card status change interrupt */ 20573db86aabSstevel switch (pcic->pc_type) { 20583db86aabSstevel case PCIC_TI_PCI1225: 20593db86aabSstevel case PCIC_TI_PCI1221: 20603db86aabSstevel case PCIC_TI_PCI1031: 20613db86aabSstevel case PCIC_TI_PCI1520: 20623db86aabSstevel case PCIC_TI_PCI1410: 20633db86aabSstevel pcic_putb(pcic, i, PCIC_MANAGEMENT_INT, 20643db86aabSstevel PCIC_CHANGE_DEFAULT); 20653db86aabSstevel break; 20663db86aabSstevel default: 20673db86aabSstevel if (pcic->pc_intr_mode == 20683db86aabSstevel PCIC_INTR_MODE_PCI_1) { 20693db86aabSstevel pcic_putb(pcic, i, PCIC_MANAGEMENT_INT, 20703db86aabSstevel PCIC_CHANGE_DEFAULT); 20713db86aabSstevel break; 20723db86aabSstevel } else { 20733db86aabSstevel pcic_putb(pcic, i, PCIC_MANAGEMENT_INT, 20743db86aabSstevel PCIC_CHANGE_DEFAULT | 20753db86aabSstevel (pcic->pc_sockets[i].pcs_smi << 4)); 20763db86aabSstevel break; 20773db86aabSstevel } 20783db86aabSstevel } 20793db86aabSstevel 20803db86aabSstevel pcic->pc_flags |= PCF_INTRENAB; 20813db86aabSstevel 20823db86aabSstevel /* take card out of RESET */ 20833db86aabSstevel pcic_putb(pcic, i, PCIC_INTERRUPT, PCIC_RESET); 20843db86aabSstevel /* turn power off and let CS do this */ 20853db86aabSstevel pcic_putb(pcic, i, PCIC_POWER_CONTROL, 0); 20863db86aabSstevel 20873db86aabSstevel /* final chip specific initialization */ 20883db86aabSstevel switch (pcic->pc_type) { 20893db86aabSstevel case PCIC_VADEM: 20903db86aabSstevel pcic_putb(pcic, i, PCIC_VG_CONTROL, 20913db86aabSstevel PCIC_VC_DELAYENABLE); 20923db86aabSstevel pcic->pc_flags |= PCF_DEBOUNCE; 20933db86aabSstevel /* FALLTHROUGH */ 20943db86aabSstevel case PCIC_I82365SL: 20953db86aabSstevel pcic_putb(pcic, i, PCIC_GLOBAL_CONTROL, 20963db86aabSstevel PCIC_GC_CSC_WRITE); 20973db86aabSstevel /* clear any pending interrupts */ 20983db86aabSstevel value = pcic_getb(pcic, i, PCIC_CARD_STATUS_CHANGE); 20993db86aabSstevel pcic_putb(pcic, i, PCIC_CARD_STATUS_CHANGE, value); 21003db86aabSstevel break; 21013db86aabSstevel /* The 82092 uses PCI config space to enable interrupts */ 21023db86aabSstevel case PCIC_INTEL_i82092: 21033db86aabSstevel pcic_82092_smiirq_ctl(pcic, i, PCIC_82092_CTL_SMI, 21043db86aabSstevel PCIC_82092_INT_ENABLE); 21053db86aabSstevel break; 21063db86aabSstevel case PCIC_CL_PD6729: 21073db86aabSstevel if (pcic->bus_speed >= PCIC_PCI_DEF_SYSCLK && i == 0) { 21083db86aabSstevel value = pcic_getb(pcic, i, PCIC_MISC_CTL_2); 21093db86aabSstevel pcic_putb(pcic, i, PCIC_MISC_CTL_2, 21103db86aabSstevel value | PCIC_CL_TIMER_CLK_DIV); 21113db86aabSstevel } 21123db86aabSstevel break; 21133db86aabSstevel } /* switch */ 21143db86aabSstevel 21153db86aabSstevel #if defined(PCIC_DEBUG) 21163db86aabSstevel if (pcic_debug) 21173db86aabSstevel cmn_err(CE_CONT, 21183db86aabSstevel "socket %d value=%x, flags = %x (%s)\n", 21193db86aabSstevel i, value, pcic->pc_sockets[i].pcs_flags, 21203db86aabSstevel (pcic->pc_sockets[i].pcs_flags & 21213db86aabSstevel PCS_CARD_PRESENT) ? 21223db86aabSstevel "card present" : "no card"); 21233db86aabSstevel #endif 21243db86aabSstevel } 21253db86aabSstevel } 21263db86aabSstevel 21273db86aabSstevel /* 21283db86aabSstevel * pcic_intr(caddr_t, caddr_t) 21293db86aabSstevel * interrupt handler for the PCIC style adapter 21303db86aabSstevel * handles all basic interrupts and also checks 21313db86aabSstevel * for status changes and notifies the nexus if 21323db86aabSstevel * necessary 21333db86aabSstevel * 21343db86aabSstevel * On PCI bus adapters, also handles all card 21353db86aabSstevel * IO interrupts. 21363db86aabSstevel */ 21373db86aabSstevel /*ARGSUSED*/ 21383db86aabSstevel uint32_t 21393db86aabSstevel pcic_intr(caddr_t arg1, caddr_t arg2) 21403db86aabSstevel { 21413db86aabSstevel pcicdev_t *pcic = (pcicdev_t *)arg1; 21423db86aabSstevel int value = 0, i, ret = DDI_INTR_UNCLAIMED; 21433db86aabSstevel uint8_t status; 21443db86aabSstevel uint_t io_ints; 21453db86aabSstevel 21463db86aabSstevel #if defined(PCIC_DEBUG) 21473db86aabSstevel pcic_err(pcic->dip, 0xf, 21483db86aabSstevel "pcic_intr: enter pc_flags=0x%x PCF_ATTACHED=0x%x" 21493db86aabSstevel " pc_numsockets=%d \n", 21503db86aabSstevel pcic->pc_flags, PCF_ATTACHED, pcic->pc_numsockets); 21513db86aabSstevel #endif 21523db86aabSstevel 21533db86aabSstevel if (!(pcic->pc_flags & PCF_ATTACHED)) 21543db86aabSstevel return (DDI_INTR_UNCLAIMED); 21553db86aabSstevel 21563db86aabSstevel mutex_enter(&pcic->intr_lock); 21573db86aabSstevel 21583db86aabSstevel if (pcic->pc_flags & PCF_SUSPENDED) { 21593db86aabSstevel mutex_exit(&pcic->intr_lock); 21603db86aabSstevel return (ret); 21613db86aabSstevel } 21623db86aabSstevel 21633db86aabSstevel /* 21643db86aabSstevel * need to change to only ACK and touch the slot that 21653db86aabSstevel * actually caused the interrupt. Currently everything 21663db86aabSstevel * is acked 21673db86aabSstevel * 21683db86aabSstevel * we need to look at all known sockets to determine 21693db86aabSstevel * what might have happened, so step through the list 21703db86aabSstevel * of them 21713db86aabSstevel */ 21723db86aabSstevel 21733db86aabSstevel /* 21743db86aabSstevel * Set the bitmask for IO interrupts to initially include all sockets 21753db86aabSstevel */ 21763db86aabSstevel io_ints = (1 << pcic->pc_numsockets) - 1; 21773db86aabSstevel 21783db86aabSstevel for (i = 0; i < pcic->pc_numsockets; i++) { 21793db86aabSstevel int card_type; 21803db86aabSstevel pcic_socket_t *sockp; 21813db86aabSstevel int value_cb = 0; 21823db86aabSstevel 21833db86aabSstevel sockp = &pcic->pc_sockets[i]; 21843db86aabSstevel /* get the socket's I/O addresses */ 21853db86aabSstevel 21863db86aabSstevel if (sockp->pcs_flags & PCS_WAITING) { 21873db86aabSstevel io_ints &= ~(1 << i); 21883db86aabSstevel continue; 21893db86aabSstevel } 21903db86aabSstevel 21913db86aabSstevel if (sockp->pcs_flags & PCS_CARD_IO) 21923db86aabSstevel card_type = IF_IO; 21933db86aabSstevel else 21943db86aabSstevel card_type = IF_MEMORY; 21953db86aabSstevel 21963db86aabSstevel if (pcic->pc_io_type == PCIC_IO_TYPE_YENTA) 21973db86aabSstevel value_cb = pcic_getcb(pcic, CB_STATUS_EVENT); 21983db86aabSstevel 21993db86aabSstevel value = pcic_change(pcic, i); 22003db86aabSstevel 22013db86aabSstevel if ((value != 0) || (value_cb != 0)) { 22023db86aabSstevel int x = pcic->pc_cb_arg; 22033db86aabSstevel 22043db86aabSstevel ret = DDI_INTR_CLAIMED; 22053db86aabSstevel 22063db86aabSstevel #if defined(PCIC_DEBUG) 22073db86aabSstevel pcic_err(pcic->dip, 0x9, 22083db86aabSstevel "card_type = %d, value_cb = 0x%x\n", 22093db86aabSstevel card_type, 22103db86aabSstevel value_cb ? value_cb : 22113db86aabSstevel pcic_getcb(pcic, CB_STATUS_EVENT)); 22123db86aabSstevel if (pcic_debug) 22133db86aabSstevel cmn_err(CE_CONT, 22143db86aabSstevel "\tchange on socket %d (%x)\n", i, 22153db86aabSstevel value); 22163db86aabSstevel #endif 22173db86aabSstevel /* find out what happened */ 22183db86aabSstevel status = pcic_getb(pcic, i, PCIC_INTERFACE_STATUS); 22193db86aabSstevel 22203db86aabSstevel /* acknowledge the interrupt */ 22213db86aabSstevel if (value_cb) 22223db86aabSstevel pcic_putcb(pcic, CB_STATUS_EVENT, value_cb); 22233db86aabSstevel 22243db86aabSstevel if (value) 22253db86aabSstevel pcic_putb(pcic, i, PCIC_CARD_STATUS_CHANGE, 22263db86aabSstevel value); 22273db86aabSstevel 22283db86aabSstevel if (pcic->pc_callback == NULL) { 22293db86aabSstevel /* if not callback handler, nothing to do */ 22303db86aabSstevel continue; 22313db86aabSstevel } 22323db86aabSstevel 22333db86aabSstevel /* Card Detect */ 22343db86aabSstevel if (value & PCIC_CD_DETECT || 22353db86aabSstevel value_cb & CB_PS_CCDMASK) { 22363db86aabSstevel uint8_t irq; 22373db86aabSstevel #if defined(PCIC_DEBUG) 22383db86aabSstevel if (pcic_debug) 22393db86aabSstevel cmn_err(CE_CONT, 22403db86aabSstevel "\tcd_detect: status=%x," 22413db86aabSstevel " flags=%x\n", 22423db86aabSstevel status, sockp->pcs_flags); 22433db86aabSstevel #else 22443db86aabSstevel #ifdef lint 22453db86aabSstevel if (status == 0) 22463db86aabSstevel status++; 22473db86aabSstevel #endif 22483db86aabSstevel #endif 22493db86aabSstevel /* 22503db86aabSstevel * Turn off all interrupts for this socket here. 22513db86aabSstevel */ 22523db86aabSstevel irq = pcic_getb(pcic, sockp->pcs_socket, 22533db86aabSstevel PCIC_MANAGEMENT_INT); 22543db86aabSstevel irq &= ~PCIC_CHANGE_MASK; 22553db86aabSstevel pcic_putb(pcic, sockp->pcs_socket, 22563db86aabSstevel PCIC_MANAGEMENT_INT, irq); 22573db86aabSstevel 22583db86aabSstevel pcic_putcb(pcic, CB_STATUS_MASK, 0x0); 22593db86aabSstevel 22600d282d13Srw148561 /* 22610d282d13Srw148561 * Put the socket in debouncing state so that 22620d282d13Srw148561 * the leaf driver won't receive interrupts. 22630d282d13Srw148561 * Crucial for handling surprise-removal. 22640d282d13Srw148561 */ 22650d282d13Srw148561 sockp->pcs_flags |= PCS_DEBOUNCING; 22660d282d13Srw148561 22673db86aabSstevel if (!sockp->pcs_cd_softint_flg) { 22683db86aabSstevel sockp->pcs_cd_softint_flg = 1; 22693db86aabSstevel (void) ddi_intr_trigger_softint( 22703db86aabSstevel sockp->pcs_cd_softint_hdl, NULL); 22713db86aabSstevel } 22723db86aabSstevel 22733db86aabSstevel io_ints &= ~(1 << i); 22743db86aabSstevel } /* PCIC_CD_DETECT */ 22753db86aabSstevel 22763db86aabSstevel /* Ready/Change Detect */ 22773db86aabSstevel sockp->pcs_state ^= SBM_RDYBSY; 22783db86aabSstevel if (card_type == IF_MEMORY && value & PCIC_RD_DETECT) { 22793db86aabSstevel sockp->pcs_flags |= PCS_READY; 22803db86aabSstevel PC_CALLBACK(pcic->dip, x, PCE_CARD_READY, i); 22813db86aabSstevel } 22823db86aabSstevel 22833db86aabSstevel /* Battery Warn Detect */ 22843db86aabSstevel if (card_type == IF_MEMORY && 22853db86aabSstevel value & PCIC_BW_DETECT && 22863db86aabSstevel !(sockp->pcs_state & SBM_BVD2)) { 22873db86aabSstevel sockp->pcs_state |= SBM_BVD2; 22883db86aabSstevel PC_CALLBACK(pcic->dip, x, 22893db86aabSstevel PCE_CARD_BATTERY_WARN, i); 22903db86aabSstevel } 22913db86aabSstevel 22923db86aabSstevel /* Battery Dead Detect */ 22933db86aabSstevel if (value & PCIC_BD_DETECT) { 22943db86aabSstevel /* 22953db86aabSstevel * need to work out event if RI not enabled 22963db86aabSstevel * and card_type == IF_IO 22973db86aabSstevel */ 22983db86aabSstevel if (card_type == IF_MEMORY && 22993db86aabSstevel !(sockp->pcs_state & SBM_BVD1)) { 23003db86aabSstevel sockp->pcs_state |= SBM_BVD1; 23013db86aabSstevel PC_CALLBACK(pcic->dip, x, 23023db86aabSstevel PCE_CARD_BATTERY_DEAD, 23033db86aabSstevel i); 23043db86aabSstevel } else { 23053db86aabSstevel /* 23063db86aabSstevel * information in pin replacement 23073db86aabSstevel * register if one is available 23083db86aabSstevel */ 23093db86aabSstevel PC_CALLBACK(pcic->dip, x, 23103db86aabSstevel PCE_CARD_STATUS_CHANGE, 23113db86aabSstevel i); 23123db86aabSstevel } /* IF_MEMORY */ 23133db86aabSstevel } /* PCIC_BD_DETECT */ 23143db86aabSstevel } /* if pcic_change */ 23153db86aabSstevel /* 23163db86aabSstevel * for any controllers that we can detect whether a socket 23173db86aabSstevel * had an interrupt for the PC Card, we should sort that out 23183db86aabSstevel * here. 23193db86aabSstevel */ 23203db86aabSstevel } /* for pc_numsockets */ 23213db86aabSstevel 23223db86aabSstevel /* 23233db86aabSstevel * If we're on a PCI bus, we may need to cycle through each IO 23243db86aabSstevel * interrupt handler that is registered since they all 23253db86aabSstevel * share the same interrupt line. 23263db86aabSstevel */ 23273db86aabSstevel 23283db86aabSstevel 23293db86aabSstevel #if defined(PCIC_DEBUG) 23303db86aabSstevel pcic_err(pcic->dip, 0xf, 23313db86aabSstevel "pcic_intr: pc_intr_mode=%d pc_type=%x io_ints=0x%x\n", 23323db86aabSstevel pcic->pc_intr_mode, pcic->pc_type, io_ints); 23333db86aabSstevel #endif 23343db86aabSstevel 23350d282d13Srw148561 if (io_ints) { 23360d282d13Srw148561 if (pcic_do_io_intr(pcic, io_ints) == DDI_INTR_CLAIMED) 23373db86aabSstevel ret = DDI_INTR_CLAIMED; 23383db86aabSstevel } 23393db86aabSstevel 23403db86aabSstevel mutex_exit(&pcic->intr_lock); 23413db86aabSstevel 23423db86aabSstevel #if defined(PCIC_DEBUG) 23433db86aabSstevel pcic_err(pcic->dip, 0xf, 23443db86aabSstevel "pcic_intr: ret=%d value=%d DDI_INTR_CLAIMED=%d\n", 23453db86aabSstevel ret, value, DDI_INTR_CLAIMED); 23463db86aabSstevel #endif 23473db86aabSstevel 23483db86aabSstevel return (ret); 23493db86aabSstevel } 23503db86aabSstevel 23513db86aabSstevel /* 23523db86aabSstevel * pcic_change() 23533db86aabSstevel * check to see if this socket had a change in state 23543db86aabSstevel * by checking the status change register 23553db86aabSstevel */ 23563db86aabSstevel static int 23573db86aabSstevel pcic_change(pcicdev_t *pcic, int socket) 23583db86aabSstevel { 23593db86aabSstevel return (pcic_getb(pcic, socket, PCIC_CARD_STATUS_CHANGE)); 23603db86aabSstevel } 23613db86aabSstevel 23623db86aabSstevel /* 23633db86aabSstevel * pcic_do_io_intr - calls client interrupt handlers 23643db86aabSstevel */ 23653db86aabSstevel static int 23663db86aabSstevel pcic_do_io_intr(pcicdev_t *pcic, uint32_t sockets) 23673db86aabSstevel { 23683db86aabSstevel inthandler_t *tmp; 23693db86aabSstevel int ret = DDI_INTR_UNCLAIMED; 23703db86aabSstevel 23713db86aabSstevel #if defined(PCIC_DEBUG) 23723db86aabSstevel pcic_err(pcic->dip, 0xf, 23733db86aabSstevel "pcic_do_io_intr: pcic=%p sockets=%d irq_top=%p\n", 23743db86aabSstevel (void *)pcic, (int)sockets, (void *)pcic->irq_top); 23753db86aabSstevel #endif 23763db86aabSstevel 23773db86aabSstevel if (pcic->irq_top != NULL) { 23783db86aabSstevel tmp = pcic->irq_current; 23793db86aabSstevel 23803db86aabSstevel do { 23813db86aabSstevel int cur = pcic->irq_current->socket; 23823db86aabSstevel pcic_socket_t *sockp = 23833db86aabSstevel &pcic->pc_sockets[cur]; 23843db86aabSstevel 23853db86aabSstevel #if defined(PCIC_DEBUG) 23863db86aabSstevel pcic_err(pcic->dip, 0xf, 23873db86aabSstevel "\t pcs_flags=0x%x PCS_CARD_PRESENT=0x%x\n", 23883db86aabSstevel sockp->pcs_flags, PCS_CARD_PRESENT); 23893db86aabSstevel pcic_err(pcic->dip, 0xf, 23903db86aabSstevel "\t sockets=%d cur=%d intr=%p arg1=%p " 23913db86aabSstevel "arg2=%p\n", 23923db86aabSstevel sockets, cur, (void *)pcic->irq_current->intr, 23933db86aabSstevel pcic->irq_current->arg1, 23943db86aabSstevel pcic->irq_current->arg2); 23953db86aabSstevel #endif 23960d282d13Srw148561 if ((sockp->pcs_flags & PCS_CARD_PRESENT) && 23970d282d13Srw148561 !(sockp->pcs_flags & PCS_DEBOUNCING) && 23980d282d13Srw148561 (sockets & (1 << cur))) { 23993db86aabSstevel 24003db86aabSstevel if ((*pcic->irq_current->intr)(pcic->irq_current->arg1, 24013db86aabSstevel pcic->irq_current->arg2) == DDI_INTR_CLAIMED) 24023db86aabSstevel ret = DDI_INTR_CLAIMED; 24033db86aabSstevel 24043db86aabSstevel #if defined(PCIC_DEBUG) 24053db86aabSstevel pcic_err(pcic->dip, 0xf, 24063db86aabSstevel "\t ret=%d DDI_INTR_CLAIMED=%d\n", 24073db86aabSstevel ret, DDI_INTR_CLAIMED); 24083db86aabSstevel #endif 24093db86aabSstevel } 24103db86aabSstevel 24113db86aabSstevel 24123db86aabSstevel if ((pcic->irq_current = pcic->irq_current->next) == NULL) 24133db86aabSstevel pcic->irq_current = pcic->irq_top; 24143db86aabSstevel 24153db86aabSstevel } while (pcic->irq_current != tmp); 24163db86aabSstevel 24173db86aabSstevel if ((pcic->irq_current = pcic->irq_current->next) == NULL) 24183db86aabSstevel pcic->irq_current = pcic->irq_top; 24193db86aabSstevel 24203db86aabSstevel } else { 24213db86aabSstevel ret = DDI_INTR_UNCLAIMED; 24223db86aabSstevel } 24233db86aabSstevel 24243db86aabSstevel #if defined(PCIC_DEBUG) 24253db86aabSstevel pcic_err(pcic->dip, 0xf, 24263db86aabSstevel "pcic_do_io_intr: exit ret=%d DDI_INTR_CLAIMED=%d\n", 24273db86aabSstevel ret, DDI_INTR_CLAIMED); 24283db86aabSstevel #endif 24293db86aabSstevel 24303db86aabSstevel return (ret); 24313db86aabSstevel 24323db86aabSstevel } 24333db86aabSstevel 24343db86aabSstevel /* 24353db86aabSstevel * pcic_inquire_adapter() 24363db86aabSstevel * SocketServices InquireAdapter function 24373db86aabSstevel * get characteristics of the physical adapter 24383db86aabSstevel */ 24393db86aabSstevel /*ARGSUSED*/ 24403db86aabSstevel static int 24413db86aabSstevel pcic_inquire_adapter(dev_info_t *dip, inquire_adapter_t *config) 24423db86aabSstevel { 24433db86aabSstevel anp_t *anp = ddi_get_driver_private(dip); 24443db86aabSstevel pcicdev_t *pcic = anp->an_private; 24453db86aabSstevel 24463db86aabSstevel config->NumSockets = pcic->pc_numsockets; 24473db86aabSstevel config->NumWindows = pcic->pc_numsockets * PCIC_NUMWINSOCK; 24483db86aabSstevel config->NumEDCs = 0; 24493db86aabSstevel config->AdpCaps = 0; 24503db86aabSstevel config->ActiveHigh = 0; 24513db86aabSstevel config->ActiveLow = PCIC_AVAIL_IRQS; 24523db86aabSstevel config->NumPower = pcic->pc_numpower; 24533db86aabSstevel config->power_entry = pcic->pc_power; /* until we resolve this */ 24543db86aabSstevel #if defined(PCIC_DEBUG) 24553db86aabSstevel if (pcic_debug) { 24563db86aabSstevel cmn_err(CE_CONT, "pcic_inquire_adapter:\n"); 24573db86aabSstevel cmn_err(CE_CONT, "\tNumSockets=%d\n", config->NumSockets); 24583db86aabSstevel cmn_err(CE_CONT, "\tNumWindows=%d\n", config->NumWindows); 24593db86aabSstevel } 24603db86aabSstevel #endif 24613db86aabSstevel config->ResourceFlags = 0; 24623db86aabSstevel switch (pcic->pc_intr_mode) { 24633db86aabSstevel case PCIC_INTR_MODE_PCI_1: 24643db86aabSstevel config->ResourceFlags |= RES_OWN_IRQ | RES_IRQ_NEXUS | 24653db86aabSstevel RES_IRQ_SHAREABLE; 24663db86aabSstevel break; 24673db86aabSstevel } 24683db86aabSstevel return (SUCCESS); 24693db86aabSstevel } 24703db86aabSstevel 24713db86aabSstevel /* 24723db86aabSstevel * pcic_callback() 24733db86aabSstevel * The PCMCIA nexus calls us via this function 24743db86aabSstevel * in order to set the callback function we are 24753db86aabSstevel * to call the nexus with 24763db86aabSstevel */ 24773db86aabSstevel /*ARGSUSED*/ 24783db86aabSstevel static int 24793db86aabSstevel pcic_callback(dev_info_t *dip, int (*handler)(), int arg) 24803db86aabSstevel { 24813db86aabSstevel anp_t *anp = ddi_get_driver_private(dip); 24823db86aabSstevel pcicdev_t *pcic = anp->an_private; 24833db86aabSstevel 24843db86aabSstevel if (handler != NULL) { 24853db86aabSstevel pcic->pc_callback = handler; 24863db86aabSstevel pcic->pc_cb_arg = arg; 24873db86aabSstevel pcic->pc_flags |= PCF_CALLBACK; 24883db86aabSstevel } else { 24893db86aabSstevel pcic->pc_callback = NULL; 24903db86aabSstevel pcic->pc_cb_arg = 0; 24913db86aabSstevel pcic->pc_flags &= ~PCF_CALLBACK; 24923db86aabSstevel } 24933db86aabSstevel /* 24943db86aabSstevel * we're now registered with the nexus 24953db86aabSstevel * it is acceptable to do callbacks at this point. 24963db86aabSstevel * don't call back from here though since it could block 24973db86aabSstevel */ 24983db86aabSstevel return (PC_SUCCESS); 24993db86aabSstevel } 25003db86aabSstevel 25013db86aabSstevel /* 25023db86aabSstevel * pcic_calc_speed (pcicdev_t *pcic, uint32_t speed) 25033db86aabSstevel * calculate the speed bits from the specified memory speed 25043db86aabSstevel * there may be more to do here 25053db86aabSstevel */ 25063db86aabSstevel 25073db86aabSstevel static int 25083db86aabSstevel pcic_calc_speed(pcicdev_t *pcic, uint32_t speed) 25093db86aabSstevel { 25103db86aabSstevel uint32_t wspeed = 1; /* assume 1 wait state when unknown */ 25113db86aabSstevel uint32_t bspeed = PCIC_ISA_DEF_SYSCLK; 25123db86aabSstevel 25133db86aabSstevel switch (pcic->pc_type) { 25143db86aabSstevel case PCIC_I82365SL: 25153db86aabSstevel case PCIC_VADEM: 25163db86aabSstevel case PCIC_VADEM_VG469: 25173db86aabSstevel default: 25183db86aabSstevel /* Intel chip wants it in waitstates */ 25193db86aabSstevel wspeed = mhztons(PCIC_ISA_DEF_SYSCLK) * 3; 25203db86aabSstevel if (speed <= wspeed) 25213db86aabSstevel wspeed = 0; 25223db86aabSstevel else if (speed <= (wspeed += mhztons(bspeed))) 25233db86aabSstevel wspeed = 1; 25243db86aabSstevel else if (speed <= (wspeed += mhztons(bspeed))) 25253db86aabSstevel wspeed = 2; 25263db86aabSstevel else 25273db86aabSstevel wspeed = 3; 25283db86aabSstevel wspeed <<= 6; /* put in right bit positions */ 25293db86aabSstevel break; 25303db86aabSstevel 25313db86aabSstevel case PCIC_INTEL_i82092: 25323db86aabSstevel wspeed = SYSMEM_82092_80NS; 25333db86aabSstevel if (speed > 80) 25343db86aabSstevel wspeed = SYSMEM_82092_100NS; 25353db86aabSstevel if (speed > 100) 25363db86aabSstevel wspeed = SYSMEM_82092_150NS; 25373db86aabSstevel if (speed > 150) 25383db86aabSstevel wspeed = SYSMEM_82092_200NS; 25393db86aabSstevel if (speed > 200) 25403db86aabSstevel wspeed = SYSMEM_82092_250NS; 25413db86aabSstevel if (speed > 250) 25423db86aabSstevel wspeed = SYSMEM_82092_600NS; 25433db86aabSstevel wspeed <<= 5; /* put in right bit positions */ 25443db86aabSstevel break; 25453db86aabSstevel 25463db86aabSstevel } /* switch */ 25473db86aabSstevel 25483db86aabSstevel return (wspeed); 25493db86aabSstevel } 25503db86aabSstevel 25513db86aabSstevel /* 25523db86aabSstevel * These values are taken from the PC Card Standard Electrical Specification. 25533db86aabSstevel * Generally the larger value is taken if 2 are possible. 25543db86aabSstevel */ 25553db86aabSstevel static struct pcic_card_times { 25563db86aabSstevel uint16_t cycle; /* Speed as found in the atribute space of he card. */ 25573db86aabSstevel uint16_t setup; /* Corresponding address setup time. */ 25583db86aabSstevel uint16_t width; /* Corresponding width, OE or WE. */ 25593db86aabSstevel uint16_t hold; /* Corresponding data or address hold time. */ 25603db86aabSstevel } pcic_card_times[] = { 25613db86aabSstevel 25623db86aabSstevel /* 25633db86aabSstevel * Note: The rounded up times for 250, 200 & 150 have been increased 25643db86aabSstevel * due to problems with the 3-Com ethernet cards (pcelx) on UBIIi. 25653db86aabSstevel * See BugID 00663. 25663db86aabSstevel */ 25673db86aabSstevel 25683db86aabSstevel /* 25693db86aabSstevel * Rounded up times Original times from 25703db86aabSstevel * that add up to the the PCMCIA Spec. 25713db86aabSstevel * cycle time. 25723db86aabSstevel */ 25733db86aabSstevel {600, 180, 370, 140}, /* 100, 300, 70 */ 25743db86aabSstevel {400, 120, 300, 90}, /* Made this one up */ 25753db86aabSstevel {250, 100, 190, 70}, /* 30, 150, 30 */ 25763db86aabSstevel {200, 80, 170, 70}, /* 20, 120, 30 */ 25773db86aabSstevel {150, 50, 110, 40}, /* 20, 80, 20 */ 25783db86aabSstevel {100, 40, 80, 40}, /* 10, 60, 15 */ 25793db86aabSstevel {0, 10, 60, 15} /* 10, 60, 15 */ 25803db86aabSstevel }; 25813db86aabSstevel 25823db86aabSstevel /* 25833db86aabSstevel * pcic_set_cdtimers 25843db86aabSstevel * This is specific to several Cirrus Logic chips 25853db86aabSstevel */ 25863db86aabSstevel static void 25873db86aabSstevel pcic_set_cdtimers(pcicdev_t *pcic, int socket, uint32_t speed, int tset) 25883db86aabSstevel { 25893db86aabSstevel int cmd, set, rec, offset, clk_pulse; 25903db86aabSstevel struct pcic_card_times *ctp; 25913db86aabSstevel 25923db86aabSstevel if ((tset == IOMEM_CLTIMER_SET_1) || (tset == SYSMEM_CLTIMER_SET_1)) 25933db86aabSstevel offset = 3; 25943db86aabSstevel else 25953db86aabSstevel offset = 0; 25963db86aabSstevel 25973db86aabSstevel clk_pulse = mhztons(pcic->bus_speed); 25983db86aabSstevel for (ctp = pcic_card_times; speed < ctp->cycle; ctp++); 25993db86aabSstevel 26003db86aabSstevel /* 26013db86aabSstevel * Add (clk_pulse/2) and an extra 1 to account for rounding errors. 26023db86aabSstevel */ 26033db86aabSstevel set = ((ctp->setup + 10 + 1 + (clk_pulse/2))/clk_pulse) - 1; 26043db86aabSstevel if (set < 0) 26053db86aabSstevel set = 0; 26063db86aabSstevel 26073db86aabSstevel cmd = ((ctp->width + 10 + 1 + (clk_pulse/2))/clk_pulse) - 1; 26083db86aabSstevel if (cmd < 0) 26093db86aabSstevel cmd = 0; 26103db86aabSstevel 26113db86aabSstevel rec = ((ctp->hold + 10 + 1 + (clk_pulse/2))/clk_pulse) - 2; 26123db86aabSstevel if (rec < 0) 26133db86aabSstevel rec = 0; 26143db86aabSstevel 26153db86aabSstevel #if defined(PCIC_DEBUG) 26163db86aabSstevel pcic_err(pcic->dip, 8, "pcic_set_cdtimers(%d, Timer Set %d)\n" 26173db86aabSstevel "ct=%d, cp=%d, cmd=0x%x, setup=0x%x, rec=0x%x\n", 26183db86aabSstevel (unsigned)speed, offset == 3 ? 1 : 0, 26193db86aabSstevel ctp->cycle, clk_pulse, cmd, set, rec); 26203db86aabSstevel #endif 26213db86aabSstevel 26223db86aabSstevel pcic_putb(pcic, socket, PCIC_TIME_COMMAND_0 + offset, cmd); 26233db86aabSstevel pcic_putb(pcic, socket, PCIC_TIME_SETUP_0 + offset, set); 26243db86aabSstevel pcic_putb(pcic, socket, PCIC_TIME_RECOVER_0 + offset, rec); 26253db86aabSstevel } 26263db86aabSstevel 26273db86aabSstevel /* 26283db86aabSstevel * pcic_set_window 26293db86aabSstevel * essentially the same as the Socket Services specification 26303db86aabSstevel * We use socket and not adapter since they are identifiable 26313db86aabSstevel * but the rest is the same 26323db86aabSstevel * 26333db86aabSstevel * dip pcic driver's device information 26343db86aabSstevel * window parameters for the request 26353db86aabSstevel */ 26363db86aabSstevel static int 26373db86aabSstevel pcic_set_window(dev_info_t *dip, set_window_t *window) 26383db86aabSstevel { 26393db86aabSstevel anp_t *anp = ddi_get_driver_private(dip); 26403db86aabSstevel pcicdev_t *pcic = anp->an_private; 26413db86aabSstevel int select; 26423db86aabSstevel int socket, pages, which, ret; 26433db86aabSstevel pcic_socket_t *sockp = &pcic->pc_sockets[window->socket]; 26443db86aabSstevel ra_return_t res; 26453db86aabSstevel ndi_ra_request_t req; 26463db86aabSstevel uint32_t base = window->base; 26473db86aabSstevel 26483db86aabSstevel #if defined(PCIC_DEBUG) 26493db86aabSstevel if (pcic_debug) { 26503db86aabSstevel cmn_err(CE_CONT, "pcic_set_window: entered\n"); 26513db86aabSstevel cmn_err(CE_CONT, 26523db86aabSstevel "\twindow=%d, socket=%d, WindowSize=%d, speed=%d\n", 26533db86aabSstevel window->window, window->socket, window->WindowSize, 26543db86aabSstevel window->speed); 26553db86aabSstevel cmn_err(CE_CONT, 26563db86aabSstevel "\tbase=%x, state=%x\n", (unsigned)window->base, 26573db86aabSstevel (unsigned)window->state); 26583db86aabSstevel } 26593db86aabSstevel #endif 26603db86aabSstevel 26613db86aabSstevel /* 26623db86aabSstevel * do some basic sanity checking on what we support 26633db86aabSstevel * we don't do paged mode 26643db86aabSstevel */ 26653db86aabSstevel if (window->state & WS_PAGED) { 26663db86aabSstevel cmn_err(CE_WARN, "pcic_set_window: BAD_ATTRIBUTE\n"); 26673db86aabSstevel return (BAD_ATTRIBUTE); 26683db86aabSstevel } 26693db86aabSstevel 26703db86aabSstevel /* 26713db86aabSstevel * we don't care about previous mappings. 26723db86aabSstevel * Card Services will deal with that so don't 26733db86aabSstevel * even check 26743db86aabSstevel */ 26753db86aabSstevel 26763db86aabSstevel socket = window->socket; 26773db86aabSstevel 26783db86aabSstevel if (!(window->state & WS_IO)) { 26793db86aabSstevel int win, tmp; 26803db86aabSstevel pcs_memwin_t *memp; 26813db86aabSstevel #if defined(PCIC_DEBUG) 26823db86aabSstevel if (pcic_debug) 26833db86aabSstevel cmn_err(CE_CONT, "\twindow type is memory\n"); 26843db86aabSstevel #endif 26853db86aabSstevel /* this is memory window mapping */ 26863db86aabSstevel win = window->window % PCIC_NUMWINSOCK; 26873db86aabSstevel tmp = window->window / PCIC_NUMWINSOCK; 26883db86aabSstevel 26893db86aabSstevel /* only windows 2-6 can do memory mapping */ 26903db86aabSstevel if (tmp != window->socket || win < PCIC_IOWINDOWS) { 26913db86aabSstevel cmn_err(CE_CONT, 26923db86aabSstevel "\tattempt to map to non-mem window\n"); 26933db86aabSstevel return (BAD_WINDOW); 26943db86aabSstevel } 26953db86aabSstevel 26963db86aabSstevel if (window->WindowSize == 0) 26973db86aabSstevel window->WindowSize = MEM_MIN; 26983db86aabSstevel else if ((window->WindowSize & (PCIC_PAGE-1)) != 0) { 26993db86aabSstevel cmn_err(CE_WARN, "pcic_set_window: BAD_SIZE\n"); 27003db86aabSstevel return (BAD_SIZE); 27013db86aabSstevel } 27023db86aabSstevel 27033db86aabSstevel mutex_enter(&pcic->pc_lock); /* protect the registers */ 27043db86aabSstevel 27053db86aabSstevel memp = &sockp->pcs_windows[win].mem; 27063db86aabSstevel memp->pcw_speed = window->speed; 27073db86aabSstevel 27083db86aabSstevel win -= PCIC_IOWINDOWS; /* put in right range */ 27093db86aabSstevel 27103db86aabSstevel if (window->WindowSize != memp->pcw_len) 27113db86aabSstevel which = memp->pcw_len; 27123db86aabSstevel else 27133db86aabSstevel which = 0; 27143db86aabSstevel 27153db86aabSstevel if (window->state & WS_ENABLED) { 27163db86aabSstevel uint32_t wspeed; 27173db86aabSstevel #if defined(PCIC_DEBUG) 27183db86aabSstevel if (pcic_debug) { 27193db86aabSstevel cmn_err(CE_CONT, 27203db86aabSstevel "\tbase=%x, win=%d\n", (unsigned)base, 27213db86aabSstevel win); 27223db86aabSstevel if (which) 27233db86aabSstevel cmn_err(CE_CONT, 27243db86aabSstevel "\tneed to remap window\n"); 27253db86aabSstevel } 27263db86aabSstevel #endif 27273db86aabSstevel 27283db86aabSstevel if (which && (memp->pcw_status & PCW_MAPPED)) { 27293db86aabSstevel ddi_regs_map_free(&memp->pcw_handle); 27303db86aabSstevel res.ra_addr_lo = memp->pcw_base; 27313db86aabSstevel res.ra_len = memp->pcw_len; 27328134ee03Srw148561 (void) pcmcia_free_mem(memp->res_dip, &res); 27333db86aabSstevel memp->pcw_status &= ~(PCW_MAPPED|PCW_ENABLED); 27343db86aabSstevel memp->pcw_hostmem = NULL; 27353db86aabSstevel memp->pcw_base = NULL; 27363db86aabSstevel memp->pcw_len = 0; 27373db86aabSstevel } 27383db86aabSstevel 27393db86aabSstevel which = window->WindowSize >> PAGE_SHIFT; 27403db86aabSstevel 27413db86aabSstevel if (!(memp->pcw_status & PCW_MAPPED)) { 27423db86aabSstevel ret = 0; 27433db86aabSstevel 27443db86aabSstevel memp->pcw_base = base; 27453db86aabSstevel bzero(&req, sizeof (req)); 27463db86aabSstevel req.ra_len = which << PAGE_SHIFT; 27473db86aabSstevel req.ra_addr = (uint64_t)memp->pcw_base; 27483db86aabSstevel req.ra_boundbase = pcic->pc_base; 27493db86aabSstevel req.ra_boundlen = pcic->pc_bound; 27503db86aabSstevel req.ra_flags = (memp->pcw_base ? 27513db86aabSstevel NDI_RA_ALLOC_SPECIFIED : 0) | 27523db86aabSstevel NDI_RA_ALLOC_BOUNDED; 27533db86aabSstevel req.ra_align_mask = 27543db86aabSstevel (PAGESIZE - 1) | (PCIC_PAGE - 1); 27553db86aabSstevel #if defined(PCIC_DEBUG) 27563db86aabSstevel pcic_err(dip, 8, 27573db86aabSstevel "\tlen 0x%"PRIx64 27583db86aabSstevel "addr 0x%"PRIx64"bbase 0x%"PRIx64 27593db86aabSstevel " blen 0x%"PRIx64" flags 0x%x" 27603db86aabSstevel " algn 0x%"PRIx64"\n", 27613db86aabSstevel req.ra_len, req.ra_addr, 27623db86aabSstevel req.ra_boundbase, 27633db86aabSstevel req.ra_boundlen, req.ra_flags, 27643db86aabSstevel req.ra_align_mask); 27653db86aabSstevel #endif 27663db86aabSstevel 27678134ee03Srw148561 ret = pcmcia_alloc_mem(dip, &req, &res, 27688134ee03Srw148561 &memp->res_dip); 27693db86aabSstevel if (ret == DDI_FAILURE) { 27703db86aabSstevel mutex_exit(&pcic->pc_lock); 27713db86aabSstevel cmn_err(CE_WARN, 27723db86aabSstevel "\tpcmcia_alloc_mem() failed\n"); 27733db86aabSstevel return (BAD_SIZE); 27743db86aabSstevel } 27753db86aabSstevel memp->pcw_base = res.ra_addr_lo; 27763db86aabSstevel base = memp->pcw_base; 27773db86aabSstevel 27783db86aabSstevel #if defined(PCIC_DEBUG) 27793db86aabSstevel if (pcic_debug) 27803db86aabSstevel cmn_err(CE_CONT, 27813db86aabSstevel "\tsetwindow: new base=%x\n", 27823db86aabSstevel (unsigned)memp->pcw_base); 27833db86aabSstevel #endif 27843db86aabSstevel memp->pcw_len = window->WindowSize; 27853db86aabSstevel 27863db86aabSstevel which = pcmcia_map_reg(pcic->dip, 27873db86aabSstevel window->child, 27883db86aabSstevel &res, 27893db86aabSstevel (uint32_t)(window->state & 27903db86aabSstevel 0xffff) | 27913db86aabSstevel (window->socket << 16), 27923db86aabSstevel (caddr_t *)&memp->pcw_hostmem, 27933db86aabSstevel &memp->pcw_handle, 27943db86aabSstevel &window->attr, NULL); 27953db86aabSstevel 27963db86aabSstevel if (which != DDI_SUCCESS) { 27973db86aabSstevel 27983db86aabSstevel cmn_err(CE_WARN, "\tpcmcia_map_reg() " 27993db86aabSstevel "failed\n"); 28003db86aabSstevel 28013db86aabSstevel res.ra_addr_lo = memp->pcw_base; 28023db86aabSstevel res.ra_len = memp->pcw_len; 28038134ee03Srw148561 (void) pcmcia_free_mem(memp->res_dip, &res); 28043db86aabSstevel 28053db86aabSstevel mutex_exit(&pcic->pc_lock); 28063db86aabSstevel 28073db86aabSstevel return (BAD_WINDOW); 28083db86aabSstevel } 28093db86aabSstevel memp->pcw_status |= PCW_MAPPED; 28103db86aabSstevel #if defined(PCIC_DEBUG) 28113db86aabSstevel if (pcic_debug) 28123db86aabSstevel cmn_err(CE_CONT, 28133db86aabSstevel "\tmap=%x, hostmem=%p\n", 28143db86aabSstevel which, 28153db86aabSstevel (void *)memp->pcw_hostmem); 28163db86aabSstevel #endif 28173db86aabSstevel } else { 28183db86aabSstevel base = memp->pcw_base; 28193db86aabSstevel } 28203db86aabSstevel 28213db86aabSstevel /* report the handle back to caller */ 28223db86aabSstevel window->handle = memp->pcw_handle; 28233db86aabSstevel 28243db86aabSstevel #if defined(PCIC_DEBUG) 28253db86aabSstevel if (pcic_debug) { 28263db86aabSstevel cmn_err(CE_CONT, 28273db86aabSstevel "\twindow mapped to %x@%x len=%d\n", 28283db86aabSstevel (unsigned)window->base, 28293db86aabSstevel (unsigned)memp->pcw_base, 28303db86aabSstevel memp->pcw_len); 28313db86aabSstevel } 28323db86aabSstevel #endif 28333db86aabSstevel 28343db86aabSstevel /* find the register set offset */ 28353db86aabSstevel select = win * PCIC_MEM_1_OFFSET; 28363db86aabSstevel #if defined(PCIC_DEBUG) 28373db86aabSstevel if (pcic_debug) 28383db86aabSstevel cmn_err(CE_CONT, "\tselect=%x\n", select); 28393db86aabSstevel #endif 28403db86aabSstevel 28413db86aabSstevel /* 28423db86aabSstevel * at this point, the register window indicator has 28433db86aabSstevel * been converted to be an offset from the first 28443db86aabSstevel * set of registers that are used for programming 28453db86aabSstevel * the window mapping and the offset used to select 28463db86aabSstevel * the correct set of registers to access the 28473db86aabSstevel * specified socket. This allows basing everything 28483db86aabSstevel * off the _0 window 28493db86aabSstevel */ 28503db86aabSstevel 28513db86aabSstevel /* map the physical page base address */ 28523db86aabSstevel which = (window->state & WS_16BIT) ? SYSMEM_DATA_16 : 0; 28533db86aabSstevel which |= (window->speed <= MEM_SPEED_MIN) ? 28543db86aabSstevel SYSMEM_ZERO_WAIT : 0; 28553db86aabSstevel 28563db86aabSstevel /* need to select register set */ 28573db86aabSstevel select = PCIC_MEM_1_OFFSET * win; 28583db86aabSstevel 28593db86aabSstevel pcic_putb(pcic, socket, 28603db86aabSstevel PCIC_SYSMEM_0_STARTLOW + select, 28613db86aabSstevel SYSMEM_LOW(base)); 28623db86aabSstevel pcic_putb(pcic, socket, 28633db86aabSstevel PCIC_SYSMEM_0_STARTHI + select, 28643db86aabSstevel SYSMEM_HIGH(base) | which); 28653db86aabSstevel 28663db86aabSstevel /* 28673db86aabSstevel * Some adapters can decode window addresses greater 28683db86aabSstevel * than 16-bits worth, so handle them here. 28693db86aabSstevel */ 28703db86aabSstevel switch (pcic->pc_type) { 28713db86aabSstevel case PCIC_INTEL_i82092: 28723db86aabSstevel pcic_putb(pcic, socket, 28733db86aabSstevel PCIC_82092_CPAGE, 28743db86aabSstevel SYSMEM_EXT(base)); 28753db86aabSstevel break; 28763db86aabSstevel case PCIC_CL_PD6729: 28773db86aabSstevel case PCIC_CL_PD6730: 28783db86aabSstevel clext_reg_write(pcic, socket, 28793db86aabSstevel PCIC_CLEXT_MMAP0_UA + win, 28803db86aabSstevel SYSMEM_EXT(base)); 28813db86aabSstevel break; 28823db86aabSstevel case PCIC_TI_PCI1130: 28833db86aabSstevel /* 28843db86aabSstevel * Note that the TI chip has one upper byte 28853db86aabSstevel * per socket so all windows get bound to a 28863db86aabSstevel * 16MB segment. This must be detected and 28873db86aabSstevel * handled appropriately. We can detect that 28883db86aabSstevel * it is done by seeing if the pc_base has 28893db86aabSstevel * changed and changing when the register 28903db86aabSstevel * is first set. This will force the bounds 28913db86aabSstevel * to be correct. 28923db86aabSstevel */ 28933db86aabSstevel if (pcic->pc_bound == 0xffffffff) { 28943db86aabSstevel pcic_putb(pcic, socket, 28953db86aabSstevel PCIC_TI_WINDOW_PAGE_PCI, 28963db86aabSstevel SYSMEM_EXT(base)); 28973db86aabSstevel pcic->pc_base = SYSMEM_EXT(base) << 24; 28983db86aabSstevel pcic->pc_bound = 0x1000000; 28993db86aabSstevel } 29003db86aabSstevel break; 29013db86aabSstevel case PCIC_TI_PCI1031: 29023db86aabSstevel case PCIC_TI_PCI1131: 29033db86aabSstevel case PCIC_TI_PCI1250: 29043db86aabSstevel case PCIC_TI_PCI1225: 29053db86aabSstevel case PCIC_TI_PCI1221: 29063db86aabSstevel case PCIC_SMC_34C90: 29073db86aabSstevel case PCIC_CL_PD6832: 29083db86aabSstevel case PCIC_RICOH_RL5C466: 29093db86aabSstevel case PCIC_TI_PCI1410: 29103db86aabSstevel case PCIC_ENE_1410: 29113db86aabSstevel case PCIC_TI_PCI1510: 29123db86aabSstevel case PCIC_TI_PCI1520: 29133db86aabSstevel case PCIC_O2_OZ6912: 29143db86aabSstevel case PCIC_TI_PCI1420: 29153db86aabSstevel case PCIC_ENE_1420: 29163db86aabSstevel case PCIC_TI_VENDOR: 29173db86aabSstevel case PCIC_TOSHIBA_TOPIC100: 29183db86aabSstevel case PCIC_TOSHIBA_TOPIC95: 29193db86aabSstevel case PCIC_TOSHIBA_VENDOR: 29203db86aabSstevel case PCIC_RICOH_VENDOR: 29213db86aabSstevel case PCIC_O2MICRO_VENDOR: 29223db86aabSstevel pcic_putb(pcic, socket, 29233db86aabSstevel PCIC_YENTA_MEM_PAGE + win, 29243db86aabSstevel SYSMEM_EXT(base)); 29253db86aabSstevel break; 29263db86aabSstevel default: 29273db86aabSstevel cmn_err(CE_NOTE, "pcic_set_window: unknown " 29283db86aabSstevel "cardbus vendor:0x%X\n", 29293db86aabSstevel pcic->pc_type); 29303db86aabSstevel pcic_putb(pcic, socket, 29313db86aabSstevel PCIC_YENTA_MEM_PAGE + win, 29323db86aabSstevel SYSMEM_EXT(base)); 29333db86aabSstevel 29343db86aabSstevel break; 29353db86aabSstevel } /* switch */ 29363db86aabSstevel 29373db86aabSstevel /* 29383db86aabSstevel * specify the length of the mapped range 29393db86aabSstevel * we convert to pages (rounding up) so that 29403db86aabSstevel * the hardware gets the right thing 29413db86aabSstevel */ 29423db86aabSstevel pages = (window->WindowSize+PCIC_PAGE-1)/PCIC_PAGE; 29433db86aabSstevel 29443db86aabSstevel /* 29453db86aabSstevel * Setup this window's timing. 29463db86aabSstevel */ 29473db86aabSstevel switch (pcic->pc_type) { 29483db86aabSstevel case PCIC_CL_PD6729: 29493db86aabSstevel case PCIC_CL_PD6730: 29503db86aabSstevel case PCIC_CL_PD6710: 29513db86aabSstevel case PCIC_CL_PD6722: 29523db86aabSstevel wspeed = SYSMEM_CLTIMER_SET_0; 29533db86aabSstevel pcic_set_cdtimers(pcic, socket, 29543db86aabSstevel window->speed, 29553db86aabSstevel wspeed); 29563db86aabSstevel break; 29573db86aabSstevel 29583db86aabSstevel case PCIC_INTEL_i82092: 29593db86aabSstevel default: 29603db86aabSstevel wspeed = pcic_calc_speed(pcic, window->speed); 29613db86aabSstevel break; 29623db86aabSstevel } /* switch */ 29633db86aabSstevel 29643db86aabSstevel #if defined(PCIC_DEBUG) 29653db86aabSstevel if (pcic_debug) 29663db86aabSstevel cmn_err(CE_CONT, 29673db86aabSstevel "\twindow %d speed bits = %x for " 29683db86aabSstevel "%dns\n", 29693db86aabSstevel win, (unsigned)wspeed, window->speed); 29703db86aabSstevel #endif 29713db86aabSstevel 29723db86aabSstevel pcic_putb(pcic, socket, PCIC_SYSMEM_0_STOPLOW + select, 29733db86aabSstevel SYSMEM_LOW(base + 29743db86aabSstevel (pages * PCIC_PAGE)-1)); 29753db86aabSstevel 29763db86aabSstevel wspeed |= SYSMEM_HIGH(base + (pages * PCIC_PAGE)-1); 29773db86aabSstevel pcic_putb(pcic, socket, PCIC_SYSMEM_0_STOPHI + select, 29783db86aabSstevel wspeed); 29793db86aabSstevel 29803db86aabSstevel /* 29813db86aabSstevel * now map the card's memory pages - we start with page 29823db86aabSstevel * 0 29833db86aabSstevel * we also default to AM -- set page might change it 29843db86aabSstevel */ 29853db86aabSstevel base = memp->pcw_base; 29863db86aabSstevel pcic_putb(pcic, socket, 29873db86aabSstevel PCIC_CARDMEM_0_LOW + select, 29883db86aabSstevel CARDMEM_LOW(0 - (uint32_t)base)); 29893db86aabSstevel 29903db86aabSstevel pcic_putb(pcic, socket, 29913db86aabSstevel PCIC_CARDMEM_0_HI + select, 29923db86aabSstevel CARDMEM_HIGH(0 - (uint32_t)base) | 29933db86aabSstevel CARDMEM_REG_ACTIVE); 29943db86aabSstevel 29953db86aabSstevel /* 29963db86aabSstevel * enable the window even though redundant 29973db86aabSstevel * and SetPage may do it again. 29983db86aabSstevel */ 29993db86aabSstevel select = pcic_getb(pcic, socket, 30003db86aabSstevel PCIC_MAPPING_ENABLE); 30013db86aabSstevel select |= SYSMEM_WINDOW(win); 30023db86aabSstevel pcic_putb(pcic, socket, PCIC_MAPPING_ENABLE, select); 30033db86aabSstevel memp->pcw_offset = 0; 30043db86aabSstevel memp->pcw_status |= PCW_ENABLED; 30053db86aabSstevel } else { 30063db86aabSstevel /* 30073db86aabSstevel * not only do we unmap the memory, the 30083db86aabSstevel * window has been turned off. 30093db86aabSstevel */ 30103db86aabSstevel if (which && memp->pcw_status & PCW_MAPPED) { 30113db86aabSstevel ddi_regs_map_free(&memp->pcw_handle); 30123db86aabSstevel res.ra_addr_lo = memp->pcw_base; 30133db86aabSstevel res.ra_len = memp->pcw_len; 30148134ee03Srw148561 (void) pcmcia_free_mem(memp->res_dip, &res); 30153db86aabSstevel memp->pcw_hostmem = NULL; 30163db86aabSstevel memp->pcw_status &= ~PCW_MAPPED; 30173db86aabSstevel } 30183db86aabSstevel 30193db86aabSstevel /* disable current mapping */ 30203db86aabSstevel select = pcic_getb(pcic, socket, PCIC_MAPPING_ENABLE); 30213db86aabSstevel select &= ~SYSMEM_WINDOW(win); 30223db86aabSstevel pcic_putb(pcic, socket, PCIC_MAPPING_ENABLE, select); 30233db86aabSstevel memp->pcw_status &= ~PCW_ENABLED; 30243db86aabSstevel } 30253db86aabSstevel memp->pcw_len = window->WindowSize; 30263db86aabSstevel window->handle = memp->pcw_handle; 30273db86aabSstevel #if defined(PCIC_DEBUG) 30283db86aabSstevel if (pcic_debug) 30293db86aabSstevel xxdmp_all_regs(pcic, window->socket, -1); 30303db86aabSstevel #endif 30313db86aabSstevel } else { 30323db86aabSstevel /* 30333db86aabSstevel * This is a request for an IO window 30343db86aabSstevel */ 30353db86aabSstevel int win, tmp; 30363db86aabSstevel pcs_iowin_t *winp; 30373db86aabSstevel /* I/O windows */ 30383db86aabSstevel #if defined(PCIC_DEBUG) 30393db86aabSstevel if (pcic_debug) 30403db86aabSstevel cmn_err(CE_CONT, "\twindow type is I/O\n"); 30413db86aabSstevel #endif 30423db86aabSstevel 30433db86aabSstevel /* only windows 0 and 1 can do I/O */ 30443db86aabSstevel win = window->window % PCIC_NUMWINSOCK; 30453db86aabSstevel tmp = window->window / PCIC_NUMWINSOCK; 30463db86aabSstevel 30473db86aabSstevel if (win >= PCIC_IOWINDOWS || tmp != window->socket) { 30483db86aabSstevel cmn_err(CE_WARN, 30493db86aabSstevel "\twindow is out of range (%d)\n", 30503db86aabSstevel window->window); 30513db86aabSstevel return (BAD_WINDOW); 30523db86aabSstevel } 30533db86aabSstevel 30543db86aabSstevel mutex_enter(&pcic->pc_lock); /* protect the registers */ 30553db86aabSstevel 30563db86aabSstevel winp = &sockp->pcs_windows[win].io; 30573db86aabSstevel winp->pcw_speed = window->speed; 30583db86aabSstevel if (window->WindowSize != 1 && window->WindowSize & 1) { 30593db86aabSstevel /* we don't want an odd-size window */ 30603db86aabSstevel window->WindowSize++; 30613db86aabSstevel } 30623db86aabSstevel winp->pcw_len = window->WindowSize; 30633db86aabSstevel 30643db86aabSstevel if (window->state & WS_ENABLED) { 30653db86aabSstevel if (winp->pcw_status & PCW_MAPPED) { 30663db86aabSstevel ddi_regs_map_free(&winp->pcw_handle); 30673db86aabSstevel res.ra_addr_lo = winp->pcw_base; 30683db86aabSstevel res.ra_len = winp->pcw_len; 30698134ee03Srw148561 (void) pcmcia_free_io(winp->res_dip, &res); 30703db86aabSstevel winp->pcw_status &= ~(PCW_MAPPED|PCW_ENABLED); 30713db86aabSstevel } 30723db86aabSstevel 30733db86aabSstevel /* 30743db86aabSstevel * if the I/O address wasn't allocated, allocate 30753db86aabSstevel * it now. If it was allocated, it better 30763db86aabSstevel * be free to use. 30773db86aabSstevel * The winp->pcw_offset value is set and used 30783db86aabSstevel * later on if the particular adapter 30793db86aabSstevel * that we're running on has the ability 30803db86aabSstevel * to translate IO accesses to the card 30813db86aabSstevel * (such as some adapters in the Cirrus 30823db86aabSstevel * Logic family). 30833db86aabSstevel */ 30843db86aabSstevel winp->pcw_offset = 0; 30853db86aabSstevel 30863db86aabSstevel /* 30873db86aabSstevel * Setup the request parameters for the 30883db86aabSstevel * requested base and length. If 30893db86aabSstevel * we're on an adapter that has 30903db86aabSstevel * IO window offset registers, then 30913db86aabSstevel * we don't need a specific base 30923db86aabSstevel * address, just a length, and then 30933db86aabSstevel * we'll cause the correct IO address 30943db86aabSstevel * to be generated on the socket by 30953db86aabSstevel * setting up the IO window offset 30963db86aabSstevel * registers. 30973db86aabSstevel * For adapters that support this capability, we 30983db86aabSstevel * always use the IO window offset registers, 30993db86aabSstevel * even if the passed base/length would be in 31003db86aabSstevel * range. 31013db86aabSstevel */ 31023db86aabSstevel base = window->base; 31033db86aabSstevel bzero(&req, sizeof (req)); 31043db86aabSstevel req.ra_len = window->WindowSize; 31053db86aabSstevel 31063db86aabSstevel req.ra_addr = (uint64_t) 31073db86aabSstevel ((pcic->pc_flags & PCF_IO_REMAP) ? 0 : base); 31083db86aabSstevel req.ra_flags = (req.ra_addr) ? 31093db86aabSstevel NDI_RA_ALLOC_SPECIFIED : 0; 31103db86aabSstevel 31113db86aabSstevel req.ra_flags |= NDI_RA_ALIGN_SIZE; 31123db86aabSstevel /* need to rethink this */ 31133db86aabSstevel req.ra_boundbase = pcic->pc_iobase; 31143db86aabSstevel req.ra_boundlen = pcic->pc_iobound; 31153db86aabSstevel req.ra_flags |= NDI_RA_ALLOC_BOUNDED; 31163db86aabSstevel 31173db86aabSstevel #if defined(PCIC_DEBUG) 31183db86aabSstevel pcic_err(dip, 8, 31193db86aabSstevel "\tlen 0x%"PRIx64" addr 0x%"PRIx64 31203db86aabSstevel "bbase 0x%"PRIx64 31213db86aabSstevel "blen 0x%"PRIx64" flags 0x%x algn 0x%" 31223db86aabSstevel PRIx64"\n", 31233db86aabSstevel req.ra_len, (uint64_t)req.ra_addr, 31243db86aabSstevel req.ra_boundbase, 31253db86aabSstevel req.ra_boundlen, req.ra_flags, 31263db86aabSstevel req.ra_align_mask); 31273db86aabSstevel #endif 31283db86aabSstevel 31293db86aabSstevel /* 31303db86aabSstevel * Try to allocate the space. If we fail this, 31313db86aabSstevel * return the appropriate error depending 31323db86aabSstevel * on whether the caller specified a 31333db86aabSstevel * specific base address or not. 31343db86aabSstevel */ 31358134ee03Srw148561 if (pcmcia_alloc_io(dip, &req, &res, 31368134ee03Srw148561 &winp->res_dip) == DDI_FAILURE) { 31373db86aabSstevel winp->pcw_status &= ~PCW_ENABLED; 31383db86aabSstevel mutex_exit(&pcic->pc_lock); 31393db86aabSstevel cmn_err(CE_WARN, "Failed to alloc I/O:\n" 31403db86aabSstevel "\tlen 0x%" PRIx64 " addr 0x%" PRIx64 31413db86aabSstevel "bbase 0x%" PRIx64 31423db86aabSstevel "blen 0x%" PRIx64 "flags 0x%x" 31433db86aabSstevel "algn 0x%" PRIx64 "\n", 31443db86aabSstevel req.ra_len, req.ra_addr, 31453db86aabSstevel req.ra_boundbase, 31463db86aabSstevel req.ra_boundlen, req.ra_flags, 31473db86aabSstevel req.ra_align_mask); 31483db86aabSstevel 31493db86aabSstevel return (base?BAD_BASE:BAD_SIZE); 31503db86aabSstevel } /* pcmcia_alloc_io */ 31513db86aabSstevel 31523db86aabSstevel /* 31533db86aabSstevel * Don't change the original base. Either we use 31543db86aabSstevel * the offset registers below (PCF_IO_REMAP is set) 31553db86aabSstevel * or it was allocated correctly anyway. 31563db86aabSstevel */ 31573db86aabSstevel winp->pcw_base = res.ra_addr_lo; 31583db86aabSstevel 31593db86aabSstevel #if defined(PCIC_DEBUG) 31603db86aabSstevel pcic_err(dip, 8, 31613db86aabSstevel "\tsetwindow: new base=%x orig base 0x%x\n", 31623db86aabSstevel (unsigned)winp->pcw_base, base); 31633db86aabSstevel #endif 31643db86aabSstevel 31653db86aabSstevel if ((which = pcmcia_map_reg(pcic->dip, 31663db86aabSstevel window->child, 31673db86aabSstevel &res, 31683db86aabSstevel (uint32_t)(window->state & 31693db86aabSstevel 0xffff) | 31703db86aabSstevel (window->socket << 16), 31713db86aabSstevel (caddr_t *)&winp->pcw_hostmem, 31723db86aabSstevel &winp->pcw_handle, 31733db86aabSstevel &window->attr, 31743db86aabSstevel base)) != DDI_SUCCESS) { 31753db86aabSstevel 31763db86aabSstevel cmn_err(CE_WARN, "pcmcia_map_reg()" 31773db86aabSstevel "failed\n"); 31783db86aabSstevel 31793db86aabSstevel res.ra_addr_lo = winp->pcw_base; 31803db86aabSstevel res.ra_len = winp->pcw_len; 31818134ee03Srw148561 (void) pcmcia_free_io(winp->res_dip, &res); 31823db86aabSstevel 31833db86aabSstevel mutex_exit(&pcic->pc_lock); 31843db86aabSstevel return (BAD_WINDOW); 31853db86aabSstevel } 31863db86aabSstevel 31873db86aabSstevel window->handle = winp->pcw_handle; 31883db86aabSstevel winp->pcw_status |= PCW_MAPPED; 31893db86aabSstevel 31903db86aabSstevel /* find the register set offset */ 31913db86aabSstevel select = win * PCIC_IO_OFFSET; 31923db86aabSstevel 31933db86aabSstevel #if defined(PCIC_DEBUG) 31943db86aabSstevel if (pcic_debug) { 31953db86aabSstevel cmn_err(CE_CONT, 31963db86aabSstevel "\tenable: window=%d, select=%x, " 31973db86aabSstevel "base=%x, handle=%p\n", 31983db86aabSstevel win, select, 31993db86aabSstevel (unsigned)window->base, 32003db86aabSstevel (void *)window->handle); 32013db86aabSstevel } 32023db86aabSstevel #endif 32033db86aabSstevel /* 32043db86aabSstevel * at this point, the register window indicator has 32053db86aabSstevel * been converted to be an offset from the first 32063db86aabSstevel * set of registers that are used for programming 32073db86aabSstevel * the window mapping and the offset used to select 32083db86aabSstevel * the correct set of registers to access the 32093db86aabSstevel * specified socket. This allows basing everything 32103db86aabSstevel * off the _0 window 32113db86aabSstevel */ 32123db86aabSstevel 32133db86aabSstevel /* map the I/O base in */ 32143db86aabSstevel pcic_putb(pcic, socket, 32153db86aabSstevel PCIC_IO_ADDR_0_STARTLOW + select, 32163db86aabSstevel LOW_BYTE((uint32_t)winp->pcw_base)); 32173db86aabSstevel pcic_putb(pcic, socket, 32183db86aabSstevel PCIC_IO_ADDR_0_STARTHI + select, 32193db86aabSstevel HIGH_BYTE((uint32_t)winp->pcw_base)); 32203db86aabSstevel 32213db86aabSstevel pcic_putb(pcic, socket, 32223db86aabSstevel PCIC_IO_ADDR_0_STOPLOW + select, 32233db86aabSstevel LOW_BYTE((uint32_t)winp->pcw_base + 32243db86aabSstevel window->WindowSize - 1)); 32253db86aabSstevel pcic_putb(pcic, socket, 32263db86aabSstevel PCIC_IO_ADDR_0_STOPHI + select, 32273db86aabSstevel HIGH_BYTE((uint32_t)winp->pcw_base + 32283db86aabSstevel window->WindowSize - 1)); 32293db86aabSstevel 32303db86aabSstevel /* 32313db86aabSstevel * We've got the requested IO space, now see if we 32323db86aabSstevel * need to adjust the IO window offset registers 32333db86aabSstevel * so that the correct IO address is generated 32343db86aabSstevel * at the socket. If this window doesn't have 32353db86aabSstevel * this capability, then we're all done setting 32363db86aabSstevel * up the IO resources. 32373db86aabSstevel */ 32383db86aabSstevel if (pcic->pc_flags & PCF_IO_REMAP) { 32393db86aabSstevel 32403db86aabSstevel 32413db86aabSstevel /* 32423db86aabSstevel * Note that only 16 bits are used to program 32433db86aabSstevel * the registers but leave 32 bits on pcw_offset 32443db86aabSstevel * so that we can generate the original base 32453db86aabSstevel * in get_window() 32463db86aabSstevel */ 32473db86aabSstevel winp->pcw_offset = (base - winp->pcw_base); 32483db86aabSstevel 32493db86aabSstevel pcic_putb(pcic, socket, 32503db86aabSstevel PCIC_IO_OFFSET_LOW + 32513db86aabSstevel (win * PCIC_IO_OFFSET_OFFSET), 32523db86aabSstevel winp->pcw_offset & 0x0ff); 32533db86aabSstevel pcic_putb(pcic, socket, 32543db86aabSstevel PCIC_IO_OFFSET_HI + 32553db86aabSstevel (win * PCIC_IO_OFFSET_OFFSET), 32563db86aabSstevel (winp->pcw_offset >> 8) & 0x0ff); 32573db86aabSstevel 32583db86aabSstevel } /* PCF_IO_REMAP */ 32593db86aabSstevel 32603db86aabSstevel /* now get the other details (size, etc) right */ 32613db86aabSstevel 32623db86aabSstevel /* 32633db86aabSstevel * Set the data size control bits here. Most of the 32643db86aabSstevel * adapters will ignore IOMEM_16BIT when 32653db86aabSstevel * IOMEM_IOCS16 is set, except for the Intel 32663db86aabSstevel * 82092, which only pays attention to the 32673db86aabSstevel * IOMEM_16BIT bit. Sigh... Intel can't even 32683db86aabSstevel * make a proper clone of their own chip. 32693db86aabSstevel * The 82092 also apparently can't set the timing 32703db86aabSstevel * of I/O windows. 32713db86aabSstevel */ 32723db86aabSstevel which = (window->state & WS_16BIT) ? 32733db86aabSstevel (IOMEM_16BIT | IOMEM_IOCS16) : 0; 32743db86aabSstevel 32753db86aabSstevel switch (pcic->pc_type) { 32763db86aabSstevel case PCIC_CL_PD6729: 32773db86aabSstevel case PCIC_CL_PD6730: 32783db86aabSstevel case PCIC_CL_PD6710: 32793db86aabSstevel case PCIC_CL_PD6722: 32803db86aabSstevel case PCIC_CL_PD6832: 32813db86aabSstevel /* 32823db86aabSstevel * Select Timer Set 1 - this will take 32833db86aabSstevel * effect when the PCIC_IO_CONTROL 32843db86aabSstevel * register is written to later on; 32853db86aabSstevel * the call to pcic_set_cdtimers 32863db86aabSstevel * just sets up the timer itself. 32873db86aabSstevel */ 32883db86aabSstevel which |= IOMEM_CLTIMER_SET_1; 32893db86aabSstevel pcic_set_cdtimers(pcic, socket, 32903db86aabSstevel window->speed, 32913db86aabSstevel IOMEM_CLTIMER_SET_1); 32923db86aabSstevel which |= IOMEM_IOCS16; 32933db86aabSstevel break; 32943db86aabSstevel case PCIC_TI_PCI1031: 32953db86aabSstevel 32963db86aabSstevel if (window->state & WS_16BIT) 32973db86aabSstevel which |= IOMEM_WAIT16; 32983db86aabSstevel 32993db86aabSstevel break; 33003db86aabSstevel case PCIC_TI_PCI1130: 33013db86aabSstevel 33023db86aabSstevel if (window->state & WS_16BIT) 33033db86aabSstevel which |= IOMEM_WAIT16; 33043db86aabSstevel 33053db86aabSstevel break; 33063db86aabSstevel case PCIC_INTEL_i82092: 33073db86aabSstevel break; 33083db86aabSstevel default: 33093db86aabSstevel if (window->speed > 33103db86aabSstevel mhztons(pcic->bus_speed) * 3) 33113db86aabSstevel which |= IOMEM_WAIT16; 33123db86aabSstevel #ifdef notdef 33133db86aabSstevel if (window->speed < 33143db86aabSstevel mhztons(pcic->bus_speed) * 6) 33153db86aabSstevel which |= IOMEM_ZERO_WAIT; 33163db86aabSstevel #endif 33173db86aabSstevel break; 33183db86aabSstevel } /* switch (pc_type) */ 33193db86aabSstevel 33203db86aabSstevel /* 33213db86aabSstevel * Setup the data width and timing 33223db86aabSstevel */ 33233db86aabSstevel select = pcic_getb(pcic, socket, PCIC_IO_CONTROL); 33243db86aabSstevel select &= ~(PCIC_IO_WIN_MASK << (win * 4)); 33253db86aabSstevel select |= IOMEM_SETWIN(win, which); 33263db86aabSstevel pcic_putb(pcic, socket, PCIC_IO_CONTROL, select); 33273db86aabSstevel 33283db86aabSstevel /* 33293db86aabSstevel * Enable the IO window 33303db86aabSstevel */ 33313db86aabSstevel select = pcic_getb(pcic, socket, PCIC_MAPPING_ENABLE); 33323db86aabSstevel pcic_putb(pcic, socket, PCIC_MAPPING_ENABLE, 33333db86aabSstevel select | IOMEM_WINDOW(win)); 33343db86aabSstevel 33353db86aabSstevel winp->pcw_status |= PCW_ENABLED; 33363db86aabSstevel 33373db86aabSstevel #if defined(PCIC_DEBUG) 33383db86aabSstevel if (pcic_debug) { 33393db86aabSstevel cmn_err(CE_CONT, 33403db86aabSstevel "\twhich = %x, select = %x (%x)\n", 33413db86aabSstevel which, select, 33423db86aabSstevel IOMEM_SETWIN(win, which)); 33433db86aabSstevel xxdmp_all_regs(pcic, window->socket * 0x40, 24); 33443db86aabSstevel } 33453db86aabSstevel #endif 33463db86aabSstevel } else { 33473db86aabSstevel /* 33483db86aabSstevel * not only do we unmap the IO space, the 33493db86aabSstevel * window has been turned off. 33503db86aabSstevel */ 33513db86aabSstevel if (winp->pcw_status & PCW_MAPPED) { 33523db86aabSstevel ddi_regs_map_free(&winp->pcw_handle); 33533db86aabSstevel res.ra_addr_lo = winp->pcw_base; 33543db86aabSstevel res.ra_len = winp->pcw_len; 33558134ee03Srw148561 (void) pcmcia_free_io(winp->res_dip, &res); 33563db86aabSstevel winp->pcw_status &= ~PCW_MAPPED; 33573db86aabSstevel } 33583db86aabSstevel 33593db86aabSstevel /* disable current mapping */ 33603db86aabSstevel select = pcic_getb(pcic, socket, 33613db86aabSstevel PCIC_MAPPING_ENABLE); 33623db86aabSstevel pcic_putb(pcic, socket, PCIC_MAPPING_ENABLE, 33633db86aabSstevel select &= ~IOMEM_WINDOW(win)); 33643db86aabSstevel winp->pcw_status &= ~PCW_ENABLED; 33653db86aabSstevel 33663db86aabSstevel winp->pcw_base = 0; 33673db86aabSstevel winp->pcw_len = 0; 33683db86aabSstevel winp->pcw_offset = 0; 33693db86aabSstevel window->base = 0; 33703db86aabSstevel /* now make sure we don't accidentally re-enable */ 33713db86aabSstevel /* find the register set offset */ 33723db86aabSstevel select = win * PCIC_IO_OFFSET; 33733db86aabSstevel pcic_putb(pcic, socket, 33743db86aabSstevel PCIC_IO_ADDR_0_STARTLOW + select, 0); 33753db86aabSstevel pcic_putb(pcic, socket, 33763db86aabSstevel PCIC_IO_ADDR_0_STARTHI + select, 0); 33773db86aabSstevel pcic_putb(pcic, socket, 33783db86aabSstevel PCIC_IO_ADDR_0_STOPLOW + select, 0); 33793db86aabSstevel pcic_putb(pcic, socket, 33803db86aabSstevel PCIC_IO_ADDR_0_STOPHI + select, 0); 33813db86aabSstevel } 33823db86aabSstevel } 33833db86aabSstevel mutex_exit(&pcic->pc_lock); 33843db86aabSstevel 33853db86aabSstevel return (SUCCESS); 33863db86aabSstevel } 33873db86aabSstevel 33883db86aabSstevel /* 33893db86aabSstevel * pcic_card_state() 33903db86aabSstevel * compute the instantaneous Card State information 33913db86aabSstevel */ 33923db86aabSstevel static int 33933db86aabSstevel pcic_card_state(pcicdev_t *pcic, pcic_socket_t *sockp) 33943db86aabSstevel { 33953db86aabSstevel int value, result; 33963db86aabSstevel #if defined(PCIC_DEBUG) 33973db86aabSstevel int orig_value; 33983db86aabSstevel #endif 33993db86aabSstevel 34003db86aabSstevel mutex_enter(&pcic->pc_lock); /* protect the registers */ 34013db86aabSstevel 34023db86aabSstevel value = pcic_getb(pcic, sockp->pcs_socket, PCIC_INTERFACE_STATUS); 34033db86aabSstevel 34043db86aabSstevel #if defined(PCIC_DEBUG) 34053db86aabSstevel orig_value = value; 34063db86aabSstevel if (pcic_debug >= 8) 34073db86aabSstevel cmn_err(CE_CONT, "pcic_card_state(%p) if status = %b for %d\n", 34083db86aabSstevel (void *)sockp, 34093db86aabSstevel value, 34103db86aabSstevel "\020\1BVD1\2BVD2\3CD1\4CD2\5WP\6RDY\7PWR\10~GPI", 34113db86aabSstevel sockp->pcs_socket); 34123db86aabSstevel #endif 34133db86aabSstevel /* 34143db86aabSstevel * Lie to socket services if we are not ready. 34153db86aabSstevel * This is when we are starting up or during debounce timeouts 34163db86aabSstevel * or if the card is a cardbus card. 34173db86aabSstevel */ 34183db86aabSstevel if (!(sockp->pcs_flags & (PCS_STARTING|PCS_CARD_ISCARDBUS)) && 34193db86aabSstevel !sockp->pcs_debounce_id && 34203db86aabSstevel (value & PCIC_ISTAT_CD_MASK) == PCIC_CD_PRESENT_OK) { 34213db86aabSstevel result = SBM_CD; 34223db86aabSstevel 34233db86aabSstevel if (value & PCIC_WRITE_PROTECT || !(value & PCIC_POWER_ON)) 34243db86aabSstevel result |= SBM_WP; 34253db86aabSstevel if (value & PCIC_POWER_ON) { 34263db86aabSstevel if (value & PCIC_READY) 34273db86aabSstevel result |= SBM_RDYBSY; 34283db86aabSstevel value = (~value) & (PCIC_BVD1 | PCIC_BVD2); 34293db86aabSstevel if (value & PCIC_BVD1) 34303db86aabSstevel result |= SBM_BVD1; 34313db86aabSstevel if (value & PCIC_BVD2) 34323db86aabSstevel result |= SBM_BVD2; 34333db86aabSstevel } 34343db86aabSstevel } else 34353db86aabSstevel result = 0; 34363db86aabSstevel 34373db86aabSstevel mutex_exit(&pcic->pc_lock); 34383db86aabSstevel 34393db86aabSstevel #if defined(PCIC_DEBUG) 34403db86aabSstevel pcic_err(pcic->dip, 8, 34413db86aabSstevel "pcic_card_state(%p) if status = %b for %d (rval=0x%x)\n", 34423db86aabSstevel (void *) sockp, orig_value, 34433db86aabSstevel "\020\1BVD1\2BVD2\3CD1\4CD2\5WP\6RDY\7PWR\10~GPI", 34443db86aabSstevel sockp->pcs_socket, result); 34453db86aabSstevel #endif 34463db86aabSstevel 34473db86aabSstevel return (result); 34483db86aabSstevel } 34493db86aabSstevel 34503db86aabSstevel /* 34513db86aabSstevel * pcic_set_page() 34523db86aabSstevel * SocketServices SetPage function 34533db86aabSstevel * set the page of PC Card memory that should be in the mapped 34543db86aabSstevel * window 34553db86aabSstevel */ 34563db86aabSstevel /*ARGSUSED*/ 34573db86aabSstevel static int 34583db86aabSstevel pcic_set_page(dev_info_t *dip, set_page_t *page) 34593db86aabSstevel { 34603db86aabSstevel anp_t *anp = ddi_get_driver_private(dip); 34613db86aabSstevel pcicdev_t *pcic = anp->an_private; 34623db86aabSstevel int select; 34633db86aabSstevel int which, socket, window; 34643db86aabSstevel uint32_t base; 34653db86aabSstevel pcs_memwin_t *memp; 34663db86aabSstevel 34673db86aabSstevel /* get real socket/window numbers */ 34683db86aabSstevel window = page->window % PCIC_NUMWINSOCK; 34693db86aabSstevel socket = page->window / PCIC_NUMWINSOCK; 34703db86aabSstevel 34713db86aabSstevel #if defined(PCIC_DEBUG) 34723db86aabSstevel if (pcic_debug) { 34733db86aabSstevel cmn_err(CE_CONT, 34743db86aabSstevel "pcic_set_page: window=%d, socket=%d, page=%d\n", 34753db86aabSstevel window, socket, page->page); 34763db86aabSstevel } 34773db86aabSstevel #endif 34783db86aabSstevel /* only windows 2-6 work on memory */ 34793db86aabSstevel if (window < PCIC_IOWINDOWS) 34803db86aabSstevel return (BAD_WINDOW); 34813db86aabSstevel 34823db86aabSstevel /* only one page supported (but any size) */ 34833db86aabSstevel if (page->page != 0) 34843db86aabSstevel return (BAD_PAGE); 34853db86aabSstevel 34863db86aabSstevel mutex_enter(&pcic->pc_lock); /* protect the registers */ 34873db86aabSstevel 34883db86aabSstevel memp = &pcic->pc_sockets[socket].pcs_windows[window].mem; 34893db86aabSstevel window -= PCIC_IOWINDOWS; 34903db86aabSstevel 34913db86aabSstevel #if defined(PCIC_DEBUG) 34923db86aabSstevel if (pcic_debug) 34933db86aabSstevel cmn_err(CE_CONT, "\tpcw_base=%x, pcw_hostmem=%p, pcw_len=%x\n", 34943db86aabSstevel (uint32_t)memp->pcw_base, 34953db86aabSstevel (void *)memp->pcw_hostmem, memp->pcw_len); 34963db86aabSstevel #endif 34973db86aabSstevel 34983db86aabSstevel /* window must be enabled */ 34993db86aabSstevel if (!(memp->pcw_status & PCW_ENABLED)) 35003db86aabSstevel return (BAD_ATTRIBUTE); 35013db86aabSstevel 35023db86aabSstevel /* find the register set offset */ 35033db86aabSstevel select = window * PCIC_MEM_1_OFFSET; 35043db86aabSstevel #if defined(PCIC_DEBUG) 35053db86aabSstevel if (pcic_debug) 35063db86aabSstevel cmn_err(CE_CONT, "\tselect=%x\n", select); 35073db86aabSstevel #endif 35083db86aabSstevel 35093db86aabSstevel /* 35103db86aabSstevel * now map the card's memory pages - we start with page 0 35113db86aabSstevel */ 35123db86aabSstevel 35133db86aabSstevel which = 0; /* assume simple case */ 35143db86aabSstevel if (page->state & PS_ATTRIBUTE) { 35153db86aabSstevel which |= CARDMEM_REG_ACTIVE; 35163db86aabSstevel memp->pcw_status |= PCW_ATTRIBUTE; 35173db86aabSstevel } else { 35183db86aabSstevel memp->pcw_status &= ~PCW_ATTRIBUTE; 35193db86aabSstevel } 35203db86aabSstevel 35213db86aabSstevel /* 35223db86aabSstevel * if caller says Write Protect, enforce it. 35233db86aabSstevel */ 35243db86aabSstevel if (page->state & PS_WP) { 35253db86aabSstevel which |= CARDMEM_WRITE_PROTECT; 35263db86aabSstevel memp->pcw_status |= PCW_WP; 35273db86aabSstevel } else { 35283db86aabSstevel memp->pcw_status &= ~PCW_WP; 35293db86aabSstevel } 35303db86aabSstevel #if defined(PCIC_DEBUG) 35313db86aabSstevel if (pcic_debug) { 35323db86aabSstevel cmn_err(CE_CONT, "\tmemory type = %s\n", 35333db86aabSstevel (which & CARDMEM_REG_ACTIVE) ? "attribute" : "common"); 35343db86aabSstevel if (which & CARDMEM_WRITE_PROTECT) 35353db86aabSstevel cmn_err(CE_CONT, "\twrite protect\n"); 35363db86aabSstevel cmn_err(CE_CONT, "\tpage offset=%x pcw_base=%x (%x)\n", 35373db86aabSstevel (unsigned)page->offset, 35383db86aabSstevel (unsigned)memp->pcw_base, 35393db86aabSstevel (int)page->offset - (int)memp->pcw_base & 0xffffff); 35403db86aabSstevel } 35413db86aabSstevel #endif 35423db86aabSstevel /* address computation based on 64MB range and not larger */ 35433db86aabSstevel base = (uint32_t)memp->pcw_base & 0x3ffffff; 35443db86aabSstevel pcic_putb(pcic, socket, PCIC_CARDMEM_0_LOW + select, 35453db86aabSstevel CARDMEM_LOW((int)page->offset - (int)base)); 35463db86aabSstevel (void) pcic_getb(pcic, socket, PCIC_CARDMEM_0_LOW + select); 35473db86aabSstevel pcic_putb(pcic, socket, PCIC_CARDMEM_0_HI + select, 35483db86aabSstevel CARDMEM_HIGH((int)page->offset - base) | which); 35493db86aabSstevel (void) pcic_getb(pcic, socket, PCIC_CARDMEM_0_HI + select); 35503db86aabSstevel 35513db86aabSstevel /* 35523db86aabSstevel * while not really necessary, this just makes sure 35533db86aabSstevel * nothing turned the window off behind our backs 35543db86aabSstevel */ 35553db86aabSstevel which = pcic_getb(pcic, socket, PCIC_MAPPING_ENABLE); 35563db86aabSstevel which |= SYSMEM_WINDOW(window); 35573db86aabSstevel pcic_putb(pcic, socket, PCIC_MAPPING_ENABLE, which); 35583db86aabSstevel (void) pcic_getb(pcic, socket, PCIC_MAPPING_ENABLE); 35593db86aabSstevel 35603db86aabSstevel memp->pcw_offset = (off_t)page->offset; 35613db86aabSstevel 35623db86aabSstevel #if defined(PCIC_DEBUG) 35633db86aabSstevel if (pcic_debug) { 35643db86aabSstevel cmn_err(CE_CONT, "\tbase=%p, *base=%x\n", 35653db86aabSstevel (void *)memp->pcw_hostmem, 35663db86aabSstevel (uint32_t)*memp->pcw_hostmem); 35673db86aabSstevel 35683db86aabSstevel xxdmp_all_regs(pcic, socket, -1); 35693db86aabSstevel 35703db86aabSstevel cmn_err(CE_CONT, "\tbase=%p, *base=%x\n", 35713db86aabSstevel (void *)memp->pcw_hostmem, 35723db86aabSstevel (uint32_t)*memp->pcw_hostmem); 35733db86aabSstevel } 35743db86aabSstevel #endif 35753db86aabSstevel 35763db86aabSstevel if (which & PCW_ATTRIBUTE) 35773db86aabSstevel pcic_mswait(pcic, socket, 2); 35783db86aabSstevel 35793db86aabSstevel mutex_exit(&pcic->pc_lock); 35803db86aabSstevel 35813db86aabSstevel return (SUCCESS); 35823db86aabSstevel } 35833db86aabSstevel 35843db86aabSstevel /* 35853db86aabSstevel * pcic_set_vcc_level() 35863db86aabSstevel * 35873db86aabSstevel * set voltage based on adapter information 35883db86aabSstevel * 35893db86aabSstevel * this routine implements a limited solution for support of 3.3v cards. 35903db86aabSstevel * the general solution, which would fully support the pcmcia spec 35913db86aabSstevel * as far as allowing client drivers to request which voltage levels 35923db86aabSstevel * to be set, requires more framework support and driver changes - ess 35933db86aabSstevel */ 35943db86aabSstevel static int 35953db86aabSstevel pcic_set_vcc_level(pcicdev_t *pcic, set_socket_t *socket) 35963db86aabSstevel { 35973db86aabSstevel uint32_t socket_present_state; 35983db86aabSstevel 35993db86aabSstevel #if defined(PCIC_DEBUG) 36003db86aabSstevel if (pcic_debug) { 36013db86aabSstevel cmn_err(CE_CONT, 36023db86aabSstevel "pcic_set_vcc_level(pcic=%p, VccLevel=%d)\n", 36033db86aabSstevel (void *)pcic, socket->VccLevel); 36043db86aabSstevel } 36053db86aabSstevel #endif 36063db86aabSstevel 36073db86aabSstevel /* 36083db86aabSstevel * check VccLevel 36093db86aabSstevel * if this is zero, power is being turned off 36103db86aabSstevel * if it is non-zero, power is being turned on. 36113db86aabSstevel */ 36123db86aabSstevel if (socket->VccLevel == 0) { 36133db86aabSstevel return (0); 36143db86aabSstevel } 36153db86aabSstevel 36163db86aabSstevel /* 36173db86aabSstevel * range checking for sanity's sake 36183db86aabSstevel */ 36193db86aabSstevel if (socket->VccLevel >= pcic->pc_numpower) { 36203db86aabSstevel return (BAD_VCC); 36213db86aabSstevel } 36223db86aabSstevel 36233db86aabSstevel switch (pcic->pc_io_type) { 36243db86aabSstevel /* 36253db86aabSstevel * Yenta-compliant adapters have vcc info in the extended registers 36263db86aabSstevel * Other adapters can be added as needed, but the 'default' case 36273db86aabSstevel * has been left as it was previously so as not to break existing 36283db86aabSstevel * adapters. 36293db86aabSstevel */ 36303db86aabSstevel case PCIC_IO_TYPE_YENTA: 36313db86aabSstevel /* 36323db86aabSstevel * Here we ignore the VccLevel passed in and read the 36333db86aabSstevel * card type from the adapter socket present state register 36343db86aabSstevel */ 36353db86aabSstevel socket_present_state = 36363db86aabSstevel ddi_get32(pcic->handle, (uint32_t *)(pcic->ioaddr + 36373db86aabSstevel PCIC_PRESENT_STATE_REG)); 36383db86aabSstevel #if defined(PCIC_DEBUG) 36393db86aabSstevel if (pcic_debug) { 36403db86aabSstevel cmn_err(CE_CONT, 36413db86aabSstevel "socket present state = 0x%x\n", 36423db86aabSstevel socket_present_state); 36433db86aabSstevel } 36443db86aabSstevel #endif 36453db86aabSstevel switch (socket_present_state & PCIC_VCC_MASK) { 36463db86aabSstevel case PCIC_VCC_3VCARD: 36473db86aabSstevel /* fall through */ 36483db86aabSstevel case PCIC_VCC_3VCARD|PCIC_VCC_5VCARD: 36493db86aabSstevel socket->VccLevel = PCIC_VCC_3VLEVEL; 36503db86aabSstevel return 36513db86aabSstevel (POWER_3VCARD_ENABLE|POWER_OUTPUT_ENABLE); 36523db86aabSstevel case PCIC_VCC_5VCARD: 36533db86aabSstevel socket->VccLevel = PCIC_VCC_5VLEVEL; 36543db86aabSstevel return 36553db86aabSstevel (POWER_CARD_ENABLE|POWER_OUTPUT_ENABLE); 36563db86aabSstevel default: 36573db86aabSstevel /* 36583db86aabSstevel * if no card is present, this can be the 36593db86aabSstevel * case of a client making a SetSocket call 36603db86aabSstevel * after card removal. In this case we return 36613db86aabSstevel * the current power level 36623db86aabSstevel */ 36633db86aabSstevel return ((unsigned)ddi_get8(pcic->handle, 36643db86aabSstevel pcic->ioaddr + CB_R2_OFFSET + 36653db86aabSstevel PCIC_POWER_CONTROL)); 36663db86aabSstevel } 36673db86aabSstevel 36683db86aabSstevel default: 36693db86aabSstevel 36703db86aabSstevel switch (socket->VccLevel) { 36713db86aabSstevel case PCIC_VCC_3VLEVEL: 36723db86aabSstevel return (BAD_VCC); 36733db86aabSstevel case PCIC_VCC_5VLEVEL: 36743db86aabSstevel /* enable Vcc */ 36753db86aabSstevel return (POWER_CARD_ENABLE|POWER_OUTPUT_ENABLE); 36763db86aabSstevel default: 36773db86aabSstevel return (BAD_VCC); 36783db86aabSstevel } 36793db86aabSstevel } 36803db86aabSstevel } 36813db86aabSstevel 36823db86aabSstevel 36833db86aabSstevel /* 36843db86aabSstevel * pcic_set_socket() 36853db86aabSstevel * Socket Services SetSocket call 36863db86aabSstevel * sets basic socket configuration 36873db86aabSstevel */ 36883db86aabSstevel static int 36893db86aabSstevel pcic_set_socket(dev_info_t *dip, set_socket_t *socket) 36903db86aabSstevel { 36913db86aabSstevel anp_t *anp = ddi_get_driver_private(dip); 36923db86aabSstevel pcicdev_t *pcic = anp->an_private; 36933db86aabSstevel pcic_socket_t *sockp = &pcic->pc_sockets[socket->socket]; 36943db86aabSstevel int irq, interrupt, mirq; 36953db86aabSstevel int powerlevel = 0; 36963db86aabSstevel int ind, value, orig_pwrctl; 36973db86aabSstevel 36983db86aabSstevel #if defined(PCIC_DEBUG) 36993db86aabSstevel if (pcic_debug) { 37003db86aabSstevel cmn_err(CE_CONT, 37013db86aabSstevel "pcic_set_socket(dip=%p, socket=%d)" 37023db86aabSstevel " Vcc=%d Vpp1=%d Vpp2=%d\n", (void *)dip, 37033db86aabSstevel socket->socket, socket->VccLevel, socket->Vpp1Level, 37043db86aabSstevel socket->Vpp2Level); 37053db86aabSstevel } 37063db86aabSstevel #endif 37073db86aabSstevel /* 37083db86aabSstevel * check VccLevel, etc. before setting mutex 37093db86aabSstevel * if this is zero, power is being turned off 37103db86aabSstevel * if it is non-zero, power is being turned on. 37113db86aabSstevel * the default case is to assume Vcc only. 37123db86aabSstevel */ 37133db86aabSstevel 37143db86aabSstevel /* this appears to be very implementation specific */ 37153db86aabSstevel 37163db86aabSstevel if (socket->Vpp1Level != socket->Vpp2Level) 37173db86aabSstevel return (BAD_VPP); 37183db86aabSstevel 37193db86aabSstevel if (socket->VccLevel == 0 || !(sockp->pcs_flags & PCS_CARD_PRESENT)) { 37203db86aabSstevel powerlevel = 0; 37213db86aabSstevel sockp->pcs_vcc = 0; 37223db86aabSstevel sockp->pcs_vpp1 = 0; 37233db86aabSstevel sockp->pcs_vpp2 = 0; 37243db86aabSstevel } else { 37253db86aabSstevel #if defined(PCIC_DEBUG) 37263db86aabSstevel pcic_err(dip, 9, "\tVcc=%d Vpp1Level=%d, Vpp2Level=%d\n", 37273db86aabSstevel socket->VccLevel, socket->Vpp1Level, socket->Vpp2Level); 37283db86aabSstevel #endif 37293db86aabSstevel /* valid Vcc power level? */ 37303db86aabSstevel if (socket->VccLevel >= pcic->pc_numpower) 37313db86aabSstevel return (BAD_VCC); 37323db86aabSstevel 37333db86aabSstevel switch (pcic_power[socket->VccLevel].PowerLevel) { 37343db86aabSstevel case 33: /* 3.3V */ 37353db86aabSstevel case 60: /* for bad CIS in Option GPRS card */ 37363db86aabSstevel if (!(pcic->pc_flags & PCF_33VCAP)) { 37373db86aabSstevel cmn_err(CE_WARN, 37383db86aabSstevel "%s%d: Bad Request for 3.3V " 37393db86aabSstevel "(Controller incapable)\n", 37403db86aabSstevel ddi_get_name(pcic->dip), 37413db86aabSstevel ddi_get_instance(pcic->dip)); 37423db86aabSstevel return (BAD_VCC); 37433db86aabSstevel } 37443db86aabSstevel /* FALLTHROUGH */ 37453db86aabSstevel case 50: /* 5V */ 37463db86aabSstevel if ((pcic->pc_io_type == PCIC_IO_TYPE_YENTA) && 37473db86aabSstevel pcic_getcb(pcic, CB_PRESENT_STATE) & 37483db86aabSstevel CB_PS_33VCARD) { 37493db86aabSstevel /* 37503db86aabSstevel * This is actually a 3.3V card. 37513db86aabSstevel * Solaris Card Services 37523db86aabSstevel * doesn't understand 3.3V 37533db86aabSstevel * so we cheat and change 37543db86aabSstevel * the setting to the one appropriate to 3.3V. 37553db86aabSstevel * Note that this is the entry number 37563db86aabSstevel * in the pcic_power[] array. 37573db86aabSstevel */ 37583db86aabSstevel sockp->pcs_vcc = PCIC_VCC_3VLEVEL; 37593db86aabSstevel } else 37603db86aabSstevel sockp->pcs_vcc = socket->VccLevel; 37613db86aabSstevel break; 37623db86aabSstevel default: 37633db86aabSstevel return (BAD_VCC); 37643db86aabSstevel } 37653db86aabSstevel 37663db86aabSstevel /* enable Vcc */ 37673db86aabSstevel powerlevel = POWER_CARD_ENABLE; 37683db86aabSstevel 37693db86aabSstevel #if defined(PCIC_DEBUG) 37703db86aabSstevel if (pcic_debug) { 37713db86aabSstevel cmn_err(CE_CONT, "\tVcc=%d powerlevel=%x\n", 37723db86aabSstevel socket->VccLevel, powerlevel); 37733db86aabSstevel } 37743db86aabSstevel #endif 37753db86aabSstevel ind = 0; /* default index to 0 power */ 37763db86aabSstevel if ((int)socket->Vpp1Level >= 0 && 37773db86aabSstevel socket->Vpp1Level < pcic->pc_numpower) { 37783db86aabSstevel if (!(pcic_power[socket->Vpp1Level].ValidSignals 37793db86aabSstevel & VPP1)) { 37803db86aabSstevel return (BAD_VPP); 37813db86aabSstevel } 37823db86aabSstevel ind = pcic_power[socket->Vpp1Level].PowerLevel/10; 37833db86aabSstevel powerlevel |= pcic_vpp_levels[ind]; 37843db86aabSstevel sockp->pcs_vpp1 = socket->Vpp1Level; 37853db86aabSstevel } 37863db86aabSstevel if ((int)socket->Vpp2Level >= 0 && 37873db86aabSstevel socket->Vpp2Level < pcic->pc_numpower) { 37883db86aabSstevel if (!(pcic_power[socket->Vpp2Level].ValidSignals 37893db86aabSstevel & VPP2)) { 37903db86aabSstevel return (BAD_VPP); 37913db86aabSstevel } 37923db86aabSstevel ind = pcic_power[socket->Vpp2Level].PowerLevel/10; 37933db86aabSstevel powerlevel |= (pcic_vpp_levels[ind] << 2); 37943db86aabSstevel sockp->pcs_vpp2 = socket->Vpp2Level; 37953db86aabSstevel } 37963db86aabSstevel 37973db86aabSstevel if (pcic->pc_flags & PCF_VPPX) { 37983db86aabSstevel /* 37993db86aabSstevel * this adapter doesn't allow separate Vpp1/Vpp2 38003db86aabSstevel * if one is turned on, both are turned on and only 38013db86aabSstevel * the Vpp1 bits should be set 38023db86aabSstevel */ 38033db86aabSstevel if (sockp->pcs_vpp2 != sockp->pcs_vpp1) { 38043db86aabSstevel /* must be the same if one not zero */ 38053db86aabSstevel if (sockp->pcs_vpp1 != 0 && 38063db86aabSstevel sockp->pcs_vpp2 != 0) { 38073db86aabSstevel cmn_err(CE_WARN, 38083db86aabSstevel "%s%d: Bad Power Request " 38093db86aabSstevel "(Vpp1/2 not the same)\n", 38103db86aabSstevel ddi_get_name(pcic->dip), 38113db86aabSstevel ddi_get_instance(pcic->dip)); 38123db86aabSstevel return (BAD_VPP); 38133db86aabSstevel } 38143db86aabSstevel } 38153db86aabSstevel powerlevel &= ~(3<<2); 38163db86aabSstevel } 38173db86aabSstevel 38183db86aabSstevel #if defined(PCIC_DEBUG) 38193db86aabSstevel if (pcic_debug) { 38203db86aabSstevel cmn_err(CE_CONT, "\tpowerlevel=%x, ind=%x\n", 38213db86aabSstevel powerlevel, ind); 38223db86aabSstevel } 38233db86aabSstevel #endif 38243db86aabSstevel } 38253db86aabSstevel mutex_enter(&pcic->pc_lock); /* protect the registers */ 38263db86aabSstevel 38273db86aabSstevel /* turn socket->IREQRouting off while programming */ 38283db86aabSstevel interrupt = pcic_getb(pcic, socket->socket, PCIC_INTERRUPT); 38293db86aabSstevel interrupt &= ~PCIC_INTR_MASK; 38303db86aabSstevel if (pcic->pc_flags & PCF_USE_SMI) 38313db86aabSstevel interrupt |= PCIC_INTR_ENABLE; 38323db86aabSstevel pcic_putb(pcic, socket->socket, PCIC_INTERRUPT, interrupt); 38333db86aabSstevel 38343db86aabSstevel switch (pcic->pc_type) { 38353db86aabSstevel case PCIC_INTEL_i82092: 38363db86aabSstevel pcic_82092_smiirq_ctl(pcic, socket->socket, PCIC_82092_CTL_IRQ, 38373db86aabSstevel PCIC_82092_INT_DISABLE); 38383db86aabSstevel break; 38393db86aabSstevel default: 38403db86aabSstevel break; 38413db86aabSstevel } /* switch */ 38423db86aabSstevel 38433db86aabSstevel /* the SCIntMask specifies events to detect */ 38443db86aabSstevel mirq = pcic_getb(pcic, socket->socket, PCIC_MANAGEMENT_INT); 38453db86aabSstevel 38463db86aabSstevel #if defined(PCIC_DEBUG) 38473db86aabSstevel if (pcic_debug) 38483db86aabSstevel cmn_err(CE_CONT, 38493db86aabSstevel "\tSCIntMask=%x, interrupt=%x, mirq=%x\n", 38503db86aabSstevel socket->SCIntMask, interrupt, mirq); 38513db86aabSstevel #endif 38523db86aabSstevel mirq &= ~(PCIC_BD_DETECT|PCIC_BW_DETECT|PCIC_RD_DETECT); 38533db86aabSstevel pcic_putb(pcic, socket->socket, PCIC_MANAGEMENT_INT, 38543db86aabSstevel mirq & ~PCIC_CHANGE_MASK); 38553db86aabSstevel 38563db86aabSstevel /* save the mask we want to use */ 38573db86aabSstevel sockp->pcs_intmask = socket->SCIntMask; 38583db86aabSstevel 38593db86aabSstevel /* 38603db86aabSstevel * Until there is a card present it's not worth enabling 38613db86aabSstevel * any interrupts except "Card detect". This is done 38623db86aabSstevel * elsewhere in the driver so don't change things if 38633db86aabSstevel * there is no card! 38643db86aabSstevel */ 38653db86aabSstevel if (sockp->pcs_flags & PCS_CARD_PRESENT) { 38663db86aabSstevel 38673db86aabSstevel /* now update the hardware to reflect events desired */ 38683db86aabSstevel if (sockp->pcs_intmask & SBM_BVD1 || socket->IFType == IF_IO) 38693db86aabSstevel mirq |= PCIC_BD_DETECT; 38703db86aabSstevel 38713db86aabSstevel if (sockp->pcs_intmask & SBM_BVD2) 38723db86aabSstevel mirq |= PCIC_BW_DETECT; 38733db86aabSstevel 38743db86aabSstevel if (sockp->pcs_intmask & SBM_RDYBSY) 38753db86aabSstevel mirq |= PCIC_RD_DETECT; 38763db86aabSstevel 38773db86aabSstevel if (sockp->pcs_intmask & SBM_CD) 38783db86aabSstevel mirq |= PCIC_CD_DETECT; 38793db86aabSstevel } 38803db86aabSstevel 38813db86aabSstevel if (sockp->pcs_flags & PCS_READY) { 38823db86aabSstevel /* 38833db86aabSstevel * card just came ready. 38843db86aabSstevel * make sure enough time elapses 38853db86aabSstevel * before touching it. 38863db86aabSstevel */ 38873db86aabSstevel sockp->pcs_flags &= ~PCS_READY; 38883db86aabSstevel pcic_mswait(pcic, socket->socket, 10); 38893db86aabSstevel } 38903db86aabSstevel 38913db86aabSstevel #if defined(PCIC_DEBUG) 38923db86aabSstevel if (pcic_debug) { 38933db86aabSstevel cmn_err(CE_CONT, "\tstatus change set to %x\n", mirq); 38943db86aabSstevel } 38953db86aabSstevel #endif 38963db86aabSstevel 38973db86aabSstevel switch (pcic->pc_type) { 38983db86aabSstevel case PCIC_I82365SL: 38993db86aabSstevel case PCIC_VADEM: 39003db86aabSstevel case PCIC_VADEM_VG469: 39013db86aabSstevel /* 39023db86aabSstevel * The Intel version has different options. This is a 39033db86aabSstevel * special case of GPI which might be used for eject 39043db86aabSstevel */ 39053db86aabSstevel 39063db86aabSstevel irq = pcic_getb(pcic, socket->socket, PCIC_CARD_DETECT); 39073db86aabSstevel if (sockp->pcs_intmask & (SBM_EJECT|SBM_INSERT) && 39083db86aabSstevel pcic->pc_flags & PCF_GPI_EJECT) { 39093db86aabSstevel irq |= PCIC_GPI_ENABLE; 39103db86aabSstevel } else { 39113db86aabSstevel irq &= ~PCIC_GPI_ENABLE; 39123db86aabSstevel } 39133db86aabSstevel pcic_putb(pcic, socket->socket, PCIC_CARD_DETECT, irq); 39143db86aabSstevel break; 39153db86aabSstevel case PCIC_CL_PD6710: 39163db86aabSstevel case PCIC_CL_PD6722: 39173db86aabSstevel if (socket->IFType == IF_IO) { 39183db86aabSstevel pcic_putb(pcic, socket->socket, PCIC_MISC_CTL_2, 0x0); 39193db86aabSstevel value = pcic_getb(pcic, socket->socket, 39203db86aabSstevel PCIC_MISC_CTL_1); 39213db86aabSstevel if (pcic->pc_flags & PCF_AUDIO) 39223db86aabSstevel value |= PCIC_MC_SPEAKER_ENB; 39233db86aabSstevel pcic_putb(pcic, socket->socket, PCIC_MISC_CTL_1, 39243db86aabSstevel value); 39253db86aabSstevel } else { 39263db86aabSstevel value = pcic_getb(pcic, socket->socket, 39273db86aabSstevel PCIC_MISC_CTL_1); 39283db86aabSstevel value &= ~PCIC_MC_SPEAKER_ENB; 39293db86aabSstevel pcic_putb(pcic, socket->socket, PCIC_MISC_CTL_1, 39303db86aabSstevel value); 39313db86aabSstevel } 39323db86aabSstevel break; 39333db86aabSstevel case PCIC_CL_PD6729: 39343db86aabSstevel case PCIC_CL_PD6730: 39353db86aabSstevel case PCIC_CL_PD6832: 39363db86aabSstevel value = pcic_getb(pcic, socket->socket, PCIC_MISC_CTL_1); 39373db86aabSstevel if ((socket->IFType == IF_IO) && (pcic->pc_flags & PCF_AUDIO)) { 39383db86aabSstevel value |= PCIC_MC_SPEAKER_ENB; 39393db86aabSstevel } else { 39403db86aabSstevel value &= ~PCIC_MC_SPEAKER_ENB; 39413db86aabSstevel } 39423db86aabSstevel 39433db86aabSstevel if (pcic_power[sockp->pcs_vcc].PowerLevel == 33) 39443db86aabSstevel value |= PCIC_MC_3VCC; 39453db86aabSstevel else 39463db86aabSstevel value &= ~PCIC_MC_3VCC; 39473db86aabSstevel 39483db86aabSstevel pcic_putb(pcic, socket->socket, PCIC_MISC_CTL_1, value); 39493db86aabSstevel break; 39503db86aabSstevel 39513db86aabSstevel case PCIC_O2_OZ6912: 39523db86aabSstevel value = pcic_getcb(pcic, CB_MISCCTRL); 39533db86aabSstevel if ((socket->IFType == IF_IO) && (pcic->pc_flags & PCF_AUDIO)) 39543db86aabSstevel value |= (1<<25); 39553db86aabSstevel else 39563db86aabSstevel value &= ~(1<<25); 39573db86aabSstevel pcic_putcb(pcic, CB_MISCCTRL, value); 39583db86aabSstevel if (pcic_power[sockp->pcs_vcc].PowerLevel == 33) 39593db86aabSstevel powerlevel |= 0x08; 39603db86aabSstevel break; 39613db86aabSstevel 39623db86aabSstevel case PCIC_TI_PCI1250: 39633db86aabSstevel case PCIC_TI_PCI1221: 39643db86aabSstevel case PCIC_TI_PCI1225: 39653db86aabSstevel case PCIC_TI_PCI1410: 39663db86aabSstevel case PCIC_ENE_1410: 39673db86aabSstevel case PCIC_TI_PCI1510: 39683db86aabSstevel case PCIC_TI_PCI1520: 39693db86aabSstevel case PCIC_TI_PCI1420: 39703db86aabSstevel case PCIC_ENE_1420: 39713db86aabSstevel value = ddi_get8(pcic->cfg_handle, 39723db86aabSstevel pcic->cfgaddr + PCIC_CRDCTL_REG); 39733db86aabSstevel if ((socket->IFType == IF_IO) && (pcic->pc_flags & PCF_AUDIO)) { 39743db86aabSstevel value |= PCIC_CRDCTL_SPKR_ENBL; 39753db86aabSstevel } else { 39763db86aabSstevel value &= ~PCIC_CRDCTL_SPKR_ENBL; 39773db86aabSstevel } 39783db86aabSstevel ddi_put8(pcic->cfg_handle, 39793db86aabSstevel pcic->cfgaddr + PCIC_CRDCTL_REG, value); 39803db86aabSstevel if (pcic_power[sockp->pcs_vcc].PowerLevel == 33) 39813db86aabSstevel powerlevel |= 0x08; 39823db86aabSstevel break; 39833db86aabSstevel } 39843db86aabSstevel 39853db86aabSstevel /* 39863db86aabSstevel * ctlind processing -- we can ignore this 39873db86aabSstevel * there aren't any outputs on the chip for this and 39883db86aabSstevel * the GUI will display what it thinks is correct 39893db86aabSstevel */ 39903db86aabSstevel 39913db86aabSstevel /* 39923db86aabSstevel * If outputs are enabled and the power is going off 39933db86aabSstevel * turn off outputs first. 39943db86aabSstevel */ 39953db86aabSstevel 39963db86aabSstevel /* power setup -- if necessary */ 39973db86aabSstevel orig_pwrctl = pcic_getb(pcic, socket->socket, PCIC_POWER_CONTROL); 39983db86aabSstevel if ((orig_pwrctl & POWER_OUTPUT_ENABLE) && sockp->pcs_vcc == 0) { 39993db86aabSstevel orig_pwrctl &= ~POWER_OUTPUT_ENABLE; 40003db86aabSstevel pcic_putb(pcic, socket->socket, 40013db86aabSstevel PCIC_POWER_CONTROL, orig_pwrctl); 40023db86aabSstevel (void) pcic_getb(pcic, socket->socket, PCIC_POWER_CONTROL); 40033db86aabSstevel } 40043db86aabSstevel 40053db86aabSstevel if (pcic->pc_flags & PCF_CBPWRCTL) { 40063db86aabSstevel value = pcic_cbus_powerctl(pcic, socket->socket); 40073db86aabSstevel powerlevel = 0; 40083db86aabSstevel } else 40093db86aabSstevel value = pcic_exca_powerctl(pcic, socket->socket, powerlevel); 40103db86aabSstevel 40113db86aabSstevel if (value != SUCCESS) { 40123db86aabSstevel mutex_exit(&pcic->pc_lock); 40133db86aabSstevel return (value); 40143db86aabSstevel } 40153db86aabSstevel 40163db86aabSstevel /* 40173db86aabSstevel * If outputs were disabled and the power is going on 40183db86aabSstevel * turn on outputs afterwards. 40193db86aabSstevel */ 40203db86aabSstevel if (!(orig_pwrctl & POWER_OUTPUT_ENABLE) && sockp->pcs_vcc != 0) { 40213db86aabSstevel orig_pwrctl = pcic_getb(pcic, socket->socket, 40223db86aabSstevel PCIC_POWER_CONTROL); 40233db86aabSstevel orig_pwrctl |= POWER_OUTPUT_ENABLE; 40243db86aabSstevel pcic_putb(pcic, socket->socket, 40253db86aabSstevel PCIC_POWER_CONTROL, orig_pwrctl); 40263db86aabSstevel (void) pcic_getb(pcic, socket->socket, PCIC_POWER_CONTROL); 40273db86aabSstevel } 40283db86aabSstevel 40293db86aabSstevel /* 40303db86aabSstevel * Once we have done the power stuff can re-enable management 40313db86aabSstevel * interrupts. 40323db86aabSstevel */ 40333db86aabSstevel pcic_putb(pcic, socket->socket, PCIC_MANAGEMENT_INT, mirq); 40343db86aabSstevel 40353db86aabSstevel #if defined(PCIC_DEBUG) 40363db86aabSstevel pcic_err(dip, 8, "\tmanagement int set to %x pwrctl to 0x%x " 40373db86aabSstevel "cbctl 0x%x\n", 40383db86aabSstevel mirq, pcic_getb(pcic, socket->socket, PCIC_POWER_CONTROL), 40393db86aabSstevel pcic_getcb(pcic, CB_CONTROL)); 40403db86aabSstevel #endif 40413db86aabSstevel 40423db86aabSstevel /* irq processing */ 40433db86aabSstevel if (socket->IFType == IF_IO) { 40443db86aabSstevel /* IRQ only for I/O */ 40453db86aabSstevel irq = socket->IREQRouting & PCIC_INTR_MASK; 40463db86aabSstevel value = pcic_getb(pcic, socket->socket, PCIC_INTERRUPT); 40473db86aabSstevel value &= ~PCIC_INTR_MASK; 40483db86aabSstevel 40493db86aabSstevel /* to enable I/O operation */ 40503db86aabSstevel value |= PCIC_IO_CARD | PCIC_RESET; 40513db86aabSstevel sockp->pcs_flags |= PCS_CARD_IO; 40523db86aabSstevel if (irq != sockp->pcs_irq) { 40533db86aabSstevel if (sockp->pcs_irq != 0) 40543db86aabSstevel cmn_err(CE_CONT, 40553db86aabSstevel "SetSocket: IRQ mismatch %x != %x!\n", 40563db86aabSstevel irq, sockp->pcs_irq); 40573db86aabSstevel else 40583db86aabSstevel sockp->pcs_irq = irq; 40593db86aabSstevel } 40603db86aabSstevel irq = sockp->pcs_irq; 40613db86aabSstevel 40623db86aabSstevel pcic_putb(pcic, socket->socket, PCIC_INTERRUPT, value); 40633db86aabSstevel if (socket->IREQRouting & IRQ_ENABLE) { 40643db86aabSstevel pcic_enable_io_intr(pcic, socket->socket, irq); 40653db86aabSstevel sockp->pcs_flags |= PCS_IRQ_ENABLED; 40663db86aabSstevel } else { 40673db86aabSstevel pcic_disable_io_intr(pcic, socket->socket); 40683db86aabSstevel sockp->pcs_flags &= ~PCS_IRQ_ENABLED; 40693db86aabSstevel } 40703db86aabSstevel #if defined(PCIC_DEBUG) 40713db86aabSstevel if (pcic_debug) { 40723db86aabSstevel cmn_err(CE_CONT, 40733db86aabSstevel "\tsocket type is I/O and irq %x is %s\n", irq, 40743db86aabSstevel (socket->IREQRouting & IRQ_ENABLE) ? 40753db86aabSstevel "enabled" : "not enabled"); 40763db86aabSstevel xxdmp_all_regs(pcic, socket->socket, 20); 40773db86aabSstevel } 40783db86aabSstevel #endif 40793db86aabSstevel } else { 40803db86aabSstevel /* make sure I/O mode is off */ 40813db86aabSstevel 40823db86aabSstevel sockp->pcs_irq = 0; 40833db86aabSstevel 40843db86aabSstevel value = pcic_getb(pcic, socket->socket, PCIC_INTERRUPT); 40853db86aabSstevel value &= ~PCIC_IO_CARD; 40863db86aabSstevel pcic_putb(pcic, socket->socket, PCIC_INTERRUPT, value); 40873db86aabSstevel pcic_disable_io_intr(pcic, socket->socket); 40883db86aabSstevel sockp->pcs_flags &= ~(PCS_CARD_IO|PCS_IRQ_ENABLED); 40893db86aabSstevel } 40903db86aabSstevel 40913db86aabSstevel sockp->pcs_state &= ~socket->State; 40923db86aabSstevel 40933db86aabSstevel mutex_exit(&pcic->pc_lock); 40943db86aabSstevel return (SUCCESS); 40953db86aabSstevel } 40963db86aabSstevel 40973db86aabSstevel /* 40983db86aabSstevel * pcic_inquire_socket() 40993db86aabSstevel * SocketServices InquireSocket function 41003db86aabSstevel * returns basic characteristics of the socket 41013db86aabSstevel */ 41023db86aabSstevel /*ARGSUSED*/ 41033db86aabSstevel static int 41043db86aabSstevel pcic_inquire_socket(dev_info_t *dip, inquire_socket_t *socket) 41053db86aabSstevel { 41063db86aabSstevel anp_t *anp = ddi_get_driver_private(dip); 41073db86aabSstevel pcicdev_t *pcic = anp->an_private; 41083db86aabSstevel int value; 41093db86aabSstevel 41103db86aabSstevel socket->SCIntCaps = PCIC_DEFAULT_INT_CAPS; 41113db86aabSstevel socket->SCRptCaps = PCIC_DEFAULT_RPT_CAPS; 41123db86aabSstevel socket->CtlIndCaps = PCIC_DEFAULT_CTL_CAPS; 41133db86aabSstevel value = pcic->pc_sockets[socket->socket].pcs_flags; 41143db86aabSstevel socket->SocketCaps = (value & PCS_SOCKET_IO) ? IF_IO : IF_MEMORY; 41153db86aabSstevel socket->ActiveHigh = 0; 41163db86aabSstevel /* these are the usable IRQs */ 41173db86aabSstevel socket->ActiveLow = 0xfff0; 41183db86aabSstevel return (SUCCESS); 41193db86aabSstevel } 41203db86aabSstevel 41213db86aabSstevel /* 41223db86aabSstevel * pcic_inquire_window() 41233db86aabSstevel * SocketServices InquireWindow function 41243db86aabSstevel * returns detailed characteristics of the window 41253db86aabSstevel * this is where windows get tied to sockets 41263db86aabSstevel */ 41273db86aabSstevel /*ARGSUSED*/ 41283db86aabSstevel static int 41293db86aabSstevel pcic_inquire_window(dev_info_t *dip, inquire_window_t *window) 41303db86aabSstevel { 41313db86aabSstevel int type, socket; 41323db86aabSstevel 41333db86aabSstevel type = window->window % PCIC_NUMWINSOCK; 41343db86aabSstevel socket = window->window / PCIC_NUMWINSOCK; 41353db86aabSstevel 41363db86aabSstevel #if defined(PCIC_DEBUG) 41373db86aabSstevel if (pcic_debug >= 8) 41383db86aabSstevel cmn_err(CE_CONT, 41393db86aabSstevel "pcic_inquire_window: window = %d/%d socket=%d\n", 41403db86aabSstevel window->window, type, socket); 41413db86aabSstevel #endif 41423db86aabSstevel if (type < PCIC_IOWINDOWS) { 41433db86aabSstevel window->WndCaps = WC_IO|WC_WAIT; 41443db86aabSstevel type = IF_IO; 41453db86aabSstevel } else { 41463db86aabSstevel window->WndCaps = WC_COMMON|WC_ATTRIBUTE|WC_WAIT; 41473db86aabSstevel type = IF_MEMORY; 41483db86aabSstevel } 41493db86aabSstevel 41503db86aabSstevel /* initialize the socket map - one socket per window */ 41513db86aabSstevel PR_ZERO(window->Sockets); 41523db86aabSstevel PR_SET(window->Sockets, socket); 41533db86aabSstevel 41543db86aabSstevel if (type == IF_IO) { 41553db86aabSstevel iowin_char_t *io; 41563db86aabSstevel io = &window->iowin_char; 41573db86aabSstevel io->IOWndCaps = WC_BASE|WC_SIZE|WC_WENABLE|WC_8BIT| 41583db86aabSstevel WC_16BIT; 41593db86aabSstevel io->FirstByte = (baseaddr_t)IOMEM_FIRST; 41603db86aabSstevel io->LastByte = (baseaddr_t)IOMEM_LAST; 41613db86aabSstevel io->MinSize = IOMEM_MIN; 41623db86aabSstevel io->MaxSize = IOMEM_MAX; 41633db86aabSstevel io->ReqGran = IOMEM_GRAN; 41643db86aabSstevel io->AddrLines = IOMEM_DECODE; 41653db86aabSstevel io->EISASlot = 0; 41663db86aabSstevel } else { 41673db86aabSstevel mem_win_char_t *mem; 41683db86aabSstevel mem = &window->mem_win_char; 41693db86aabSstevel mem->MemWndCaps = WC_BASE|WC_SIZE|WC_WENABLE|WC_8BIT| 41703db86aabSstevel WC_16BIT|WC_WP; 41713db86aabSstevel 41723db86aabSstevel mem->FirstByte = (baseaddr_t)MEM_FIRST; 41733db86aabSstevel mem->LastByte = (baseaddr_t)MEM_LAST; 41743db86aabSstevel 41753db86aabSstevel mem->MinSize = MEM_MIN; 41763db86aabSstevel mem->MaxSize = MEM_MAX; 41773db86aabSstevel mem->ReqGran = PCIC_PAGE; 41783db86aabSstevel mem->ReqBase = 0; 41793db86aabSstevel mem->ReqOffset = PCIC_PAGE; 41803db86aabSstevel mem->Slowest = MEM_SPEED_MAX; 41813db86aabSstevel mem->Fastest = MEM_SPEED_MIN; 41823db86aabSstevel } 41833db86aabSstevel return (SUCCESS); 41843db86aabSstevel } 41853db86aabSstevel 41863db86aabSstevel /* 41873db86aabSstevel * pcic_get_adapter() 41883db86aabSstevel * SocketServices GetAdapter function 41893db86aabSstevel * this is nearly a no-op. 41903db86aabSstevel */ 41913db86aabSstevel /*ARGSUSED*/ 41923db86aabSstevel static int 41933db86aabSstevel pcic_get_adapter(dev_info_t *dip, get_adapter_t *adapt) 41943db86aabSstevel { 41953db86aabSstevel anp_t *anp = ddi_get_driver_private(dip); 41963db86aabSstevel pcicdev_t *pcic = anp->an_private; 41973db86aabSstevel 41983db86aabSstevel if (pcic->pc_flags & PCF_INTRENAB) 41993db86aabSstevel adapt->SCRouting = IRQ_ENABLE; 42003db86aabSstevel adapt->state = 0; 42013db86aabSstevel return (SUCCESS); 42023db86aabSstevel } 42033db86aabSstevel 42043db86aabSstevel /* 42053db86aabSstevel * pcic_get_page() 42063db86aabSstevel * SocketServices GetPage function 42073db86aabSstevel * returns info about the window 42083db86aabSstevel */ 42093db86aabSstevel /*ARGSUSED*/ 42103db86aabSstevel static int 42113db86aabSstevel pcic_get_page(dev_info_t *dip, get_page_t *page) 42123db86aabSstevel { 42133db86aabSstevel anp_t *anp = ddi_get_driver_private(dip); 42143db86aabSstevel pcicdev_t *pcic = anp->an_private; 42153db86aabSstevel int socket, window; 42163db86aabSstevel pcs_memwin_t *winp; 42173db86aabSstevel 42183db86aabSstevel socket = page->window / PCIC_NUMWINSOCK; 42193db86aabSstevel window = page->window % PCIC_NUMWINSOCK; 42203db86aabSstevel 42213db86aabSstevel /* I/O windows are the first two */ 42223db86aabSstevel if (window < PCIC_IOWINDOWS || socket >= pcic->pc_numsockets) { 42233db86aabSstevel return (BAD_WINDOW); 42243db86aabSstevel } 42253db86aabSstevel 42263db86aabSstevel winp = &pcic->pc_sockets[socket].pcs_windows[window].mem; 42273db86aabSstevel 42283db86aabSstevel if (page->page != 0) 42293db86aabSstevel return (BAD_PAGE); 42303db86aabSstevel 42313db86aabSstevel page->state = 0; 42323db86aabSstevel if (winp->pcw_status & PCW_ENABLED) 42333db86aabSstevel page->state |= PS_ENABLED; 42343db86aabSstevel if (winp->pcw_status & PCW_ATTRIBUTE) 42353db86aabSstevel page->state |= PS_ATTRIBUTE; 42363db86aabSstevel if (winp->pcw_status & PCW_WP) 42373db86aabSstevel page->state |= PS_WP; 42383db86aabSstevel 42393db86aabSstevel page->offset = (off_t)winp->pcw_offset; 42403db86aabSstevel 42413db86aabSstevel return (SUCCESS); 42423db86aabSstevel } 42433db86aabSstevel 42443db86aabSstevel /* 42453db86aabSstevel * pcic_get_socket() 42463db86aabSstevel * SocketServices GetSocket 42473db86aabSstevel * returns information about the current socket setting 42483db86aabSstevel */ 42493db86aabSstevel /*ARGSUSED*/ 42503db86aabSstevel static int 42513db86aabSstevel pcic_get_socket(dev_info_t *dip, get_socket_t *socket) 42523db86aabSstevel { 42533db86aabSstevel anp_t *anp = ddi_get_driver_private(dip); 42543db86aabSstevel pcicdev_t *pcic = anp->an_private; 42553db86aabSstevel int socknum, irq_enabled; 42563db86aabSstevel pcic_socket_t *sockp; 42573db86aabSstevel 42583db86aabSstevel socknum = socket->socket; 42593db86aabSstevel sockp = &pcic->pc_sockets[socknum]; 42603db86aabSstevel 42613db86aabSstevel socket->SCIntMask = sockp->pcs_intmask; 42623db86aabSstevel sockp->pcs_state = pcic_card_state(pcic, sockp); 42633db86aabSstevel 42643db86aabSstevel socket->state = sockp->pcs_state; 42653db86aabSstevel if (socket->state & SBM_CD) { 42663db86aabSstevel socket->VccLevel = sockp->pcs_vcc; 42673db86aabSstevel socket->Vpp1Level = sockp->pcs_vpp1; 42683db86aabSstevel socket->Vpp2Level = sockp->pcs_vpp2; 42693db86aabSstevel irq_enabled = (sockp->pcs_flags & PCS_IRQ_ENABLED) ? 42703db86aabSstevel IRQ_ENABLE : 0; 42713db86aabSstevel socket->IRQRouting = sockp->pcs_irq | irq_enabled; 42723db86aabSstevel socket->IFType = (sockp->pcs_flags & PCS_CARD_IO) ? 42733db86aabSstevel IF_IO : IF_MEMORY; 42743db86aabSstevel } else { 42753db86aabSstevel socket->VccLevel = 0; 42763db86aabSstevel socket->Vpp1Level = 0; 42773db86aabSstevel socket->Vpp2Level = 0; 42783db86aabSstevel socket->IRQRouting = 0; 42793db86aabSstevel socket->IFType = IF_MEMORY; 42803db86aabSstevel } 42813db86aabSstevel socket->CtlInd = 0; /* no indicators */ 42823db86aabSstevel 42833db86aabSstevel return (SUCCESS); 42843db86aabSstevel } 42853db86aabSstevel 42863db86aabSstevel /* 42873db86aabSstevel * pcic_get_status() 42883db86aabSstevel * SocketServices GetStatus 42893db86aabSstevel * returns status information about the PC Card in 42903db86aabSstevel * the selected socket 42913db86aabSstevel */ 42923db86aabSstevel /*ARGSUSED*/ 42933db86aabSstevel static int 42943db86aabSstevel pcic_get_status(dev_info_t *dip, get_ss_status_t *status) 42953db86aabSstevel { 42963db86aabSstevel anp_t *anp = ddi_get_driver_private(dip); 42973db86aabSstevel pcicdev_t *pcic = anp->an_private; 42983db86aabSstevel int socknum, irq_enabled; 42993db86aabSstevel pcic_socket_t *sockp; 43003db86aabSstevel 43013db86aabSstevel socknum = status->socket; 43023db86aabSstevel sockp = &pcic->pc_sockets[socknum]; 43033db86aabSstevel 43043db86aabSstevel status->CardState = pcic_card_state(pcic, sockp); 43053db86aabSstevel status->SocketState = sockp->pcs_state; 43063db86aabSstevel status->CtlInd = 0; /* no indicators */ 43073db86aabSstevel 43083db86aabSstevel if (sockp->pcs_flags & PCS_CARD_PRESENT) 43093db86aabSstevel status->SocketState |= SBM_CD; 43103db86aabSstevel if (status->CardState & SBM_CD) { 43113db86aabSstevel irq_enabled = (sockp->pcs_flags & PCS_CARD_ENABLED) ? 43123db86aabSstevel IRQ_ENABLE : 0; 43133db86aabSstevel status->IRQRouting = sockp->pcs_irq | irq_enabled; 43143db86aabSstevel status->IFType = (sockp->pcs_flags & PCS_CARD_IO) ? 43153db86aabSstevel IF_IO : IF_MEMORY; 43163db86aabSstevel } else { 43173db86aabSstevel status->IRQRouting = 0; 43183db86aabSstevel status->IFType = IF_MEMORY; 43193db86aabSstevel } 43203db86aabSstevel 43213db86aabSstevel #if defined(PCIC_DEBUG) 43223db86aabSstevel if (pcic_debug >= 8) 43233db86aabSstevel cmn_err(CE_CONT, "pcic_get_status: socket=%d, CardState=%x," 43243db86aabSstevel "SocketState=%x\n", 43253db86aabSstevel socknum, status->CardState, status->SocketState); 43263db86aabSstevel #endif 43273db86aabSstevel switch (pcic->pc_type) { 43283db86aabSstevel uint32_t present_state; 43293db86aabSstevel case PCIC_TI_PCI1410: 43303db86aabSstevel case PCIC_TI_PCI1520: 43313db86aabSstevel case PCIC_TI_PCI1420: 43323db86aabSstevel case PCIC_ENE_1420: 43333db86aabSstevel case PCIC_TOSHIBA_TOPIC100: 43343db86aabSstevel case PCIC_TOSHIBA_TOPIC95: 43353db86aabSstevel case PCIC_TOSHIBA_VENDOR: 43363db86aabSstevel case PCIC_O2MICRO_VENDOR: 43373db86aabSstevel case PCIC_TI_VENDOR: 43383db86aabSstevel case PCIC_RICOH_VENDOR: 43393db86aabSstevel present_state = pcic_getcb(pcic, CB_PRESENT_STATE); 43403db86aabSstevel if (present_state & PCIC_CB_CARD) 43413db86aabSstevel status->IFType = IF_CARDBUS; 43423db86aabSstevel #if defined(PCIC_DEBUG) 43433db86aabSstevel if (pcic_debug >= 8) 43443db86aabSstevel cmn_err(CE_CONT, "pcic_get_status: present_state=0x%x\n", 43453db86aabSstevel present_state); 43463db86aabSstevel #endif 43473db86aabSstevel break; 43483db86aabSstevel default: 43493db86aabSstevel break; 43503db86aabSstevel } 43513db86aabSstevel 43523db86aabSstevel return (SUCCESS); 43533db86aabSstevel } 43543db86aabSstevel 43553db86aabSstevel /* 43563db86aabSstevel * pcic_get_window() 43573db86aabSstevel * SocketServices GetWindow function 43583db86aabSstevel * returns state information about the specified window 43593db86aabSstevel */ 43603db86aabSstevel /*ARGSUSED*/ 43613db86aabSstevel static int 43623db86aabSstevel pcic_get_window(dev_info_t *dip, get_window_t *window) 43633db86aabSstevel { 43643db86aabSstevel anp_t *anp = ddi_get_driver_private(dip); 43653db86aabSstevel pcicdev_t *pcic = anp->an_private; 43663db86aabSstevel int socket, win; 43673db86aabSstevel pcic_socket_t *sockp; 43683db86aabSstevel pcs_memwin_t *winp; 43693db86aabSstevel 43703db86aabSstevel socket = window->window / PCIC_NUMWINSOCK; 43713db86aabSstevel win = window->window % PCIC_NUMWINSOCK; 43723db86aabSstevel #if defined(PCIC_DEBUG) 43733db86aabSstevel if (pcic_debug) { 43743db86aabSstevel cmn_err(CE_CONT, "pcic_get_window(socket=%d, window=%d)\n", 43753db86aabSstevel socket, win); 43763db86aabSstevel } 43773db86aabSstevel #endif 43783db86aabSstevel 43793db86aabSstevel if (socket > pcic->pc_numsockets) 43803db86aabSstevel return (BAD_WINDOW); 43813db86aabSstevel 43823db86aabSstevel sockp = &pcic->pc_sockets[socket]; 43833db86aabSstevel winp = &sockp->pcs_windows[win].mem; 43843db86aabSstevel 43853db86aabSstevel window->socket = socket; 43863db86aabSstevel window->size = winp->pcw_len; 43873db86aabSstevel window->speed = winp->pcw_speed; 43883db86aabSstevel window->handle = (ddi_acc_handle_t)winp->pcw_handle; 43893db86aabSstevel window->base = (uint32_t)winp->pcw_base + winp->pcw_offset; 43903db86aabSstevel 43913db86aabSstevel if (win >= PCIC_IOWINDOWS) { 43923db86aabSstevel window->state = 0; 43933db86aabSstevel } else { 43943db86aabSstevel window->state = WS_IO; 43953db86aabSstevel } 43963db86aabSstevel if (winp->pcw_status & PCW_ENABLED) 43973db86aabSstevel window->state |= WS_ENABLED; 43983db86aabSstevel 43993db86aabSstevel if (winp->pcw_status & PCS_CARD_16BIT) 44003db86aabSstevel window->state |= WS_16BIT; 44013db86aabSstevel #if defined(PCIC_DEBUG) 44023db86aabSstevel if (pcic_debug) 44033db86aabSstevel cmn_err(CE_CONT, "\tsize=%d, speed=%d, base=%p, state=%x\n", 44043db86aabSstevel window->size, (unsigned)window->speed, 44053db86aabSstevel (void *)window->handle, window->state); 44063db86aabSstevel #endif 44073db86aabSstevel 44083db86aabSstevel return (SUCCESS); 44093db86aabSstevel } 44103db86aabSstevel 44113db86aabSstevel /* 44123db86aabSstevel * pcic_ll_reset 44133db86aabSstevel * low level reset 44143db86aabSstevel * separated out so it can be called when already locked 44153db86aabSstevel * 44163db86aabSstevel * There are two variables that control the RESET timing: 44173db86aabSstevel * pcic_prereset_time - time in mS before asserting RESET 44183db86aabSstevel * pcic_reset_time - time in mS to assert RESET 44193db86aabSstevel * 44203db86aabSstevel */ 44213db86aabSstevel int pcic_prereset_time = 1; 44223db86aabSstevel int pcic_reset_time = 10; 44233db86aabSstevel int pcic_postreset_time = 20; 44243db86aabSstevel int pcic_vpp_is_vcc_during_reset = 0; 44253db86aabSstevel 44263db86aabSstevel static int 44273db86aabSstevel pcic_ll_reset(pcicdev_t *pcic, int socket) 44283db86aabSstevel { 44293db86aabSstevel int windowbits, iobits; 44303db86aabSstevel uint32_t pwr; 44313db86aabSstevel 44323db86aabSstevel /* save windows that were on */ 44333db86aabSstevel windowbits = pcic_getb(pcic, socket, PCIC_MAPPING_ENABLE); 44343db86aabSstevel if (pcic_reset_time == 0) 44353db86aabSstevel return (windowbits); 44363db86aabSstevel /* turn all windows off */ 44373db86aabSstevel pcic_putb(pcic, socket, PCIC_MAPPING_ENABLE, 0); 44383db86aabSstevel 44393db86aabSstevel #if defined(PCIC_DEBUG) 44403db86aabSstevel pcic_err(pcic->dip, 6, 44413db86aabSstevel "pcic_ll_reset(socket %d) powerlevel=%x cbctl 0x%x cbps 0x%x\n", 44423db86aabSstevel socket, pcic_getb(pcic, socket, PCIC_POWER_CONTROL), 44433db86aabSstevel pcic_getcb(pcic, CB_CONTROL), 44443db86aabSstevel pcic_getcb(pcic, CB_PRESENT_STATE)); 44453db86aabSstevel #endif 44463db86aabSstevel 44473db86aabSstevel if (pcic_vpp_is_vcc_during_reset) { 44483db86aabSstevel 44493db86aabSstevel /* 44503db86aabSstevel * Set VPP to VCC for the duration of the reset - for aironet 44513db86aabSstevel * card. 44523db86aabSstevel */ 44533db86aabSstevel if (pcic->pc_flags & PCF_CBPWRCTL) { 44543db86aabSstevel pwr = pcic_getcb(pcic, CB_CONTROL); 44553db86aabSstevel pcic_putcb(pcic, CB_CONTROL, (pwr&~CB_C_VPPMASK)|CB_C_VPPVCC); 44563db86aabSstevel (void) pcic_getcb(pcic, CB_CONTROL); 44573db86aabSstevel } else { 44583db86aabSstevel pwr = pcic_getb(pcic, socket, PCIC_POWER_CONTROL); 44593db86aabSstevel pcic_putb(pcic, socket, PCIC_POWER_CONTROL, 44603db86aabSstevel pwr | 1); 44613db86aabSstevel (void) pcic_getb(pcic, socket, PCIC_POWER_CONTROL); 44623db86aabSstevel } 44633db86aabSstevel } 44643db86aabSstevel 44653db86aabSstevel if (pcic_prereset_time > 0) { 44663db86aabSstevel pcic_err(pcic->dip, 8, "pcic_ll_reset pre_wait %d mS\n", 44673db86aabSstevel pcic_prereset_time); 44683db86aabSstevel pcic_mswait(pcic, socket, pcic_prereset_time); 44693db86aabSstevel } 44703db86aabSstevel 44713db86aabSstevel /* turn interrupts off and start a reset */ 44723db86aabSstevel pcic_err(pcic->dip, 8, 44733db86aabSstevel "pcic_ll_reset turn interrupts off and start a reset\n"); 44743db86aabSstevel iobits = pcic_getb(pcic, socket, PCIC_INTERRUPT); 44753db86aabSstevel iobits &= ~(PCIC_INTR_MASK | PCIC_RESET); 44763db86aabSstevel pcic_putb(pcic, socket, PCIC_INTERRUPT, iobits); 44773db86aabSstevel (void) pcic_getb(pcic, socket, PCIC_INTERRUPT); 44783db86aabSstevel 44793db86aabSstevel switch (pcic->pc_type) { 44803db86aabSstevel case PCIC_INTEL_i82092: 44813db86aabSstevel pcic_82092_smiirq_ctl(pcic, socket, PCIC_82092_CTL_IRQ, 44823db86aabSstevel PCIC_82092_INT_DISABLE); 44833db86aabSstevel break; 44843db86aabSstevel default: 44853db86aabSstevel break; 44863db86aabSstevel } /* switch */ 44873db86aabSstevel 44883db86aabSstevel pcic->pc_sockets[socket].pcs_state = 0; 44893db86aabSstevel 44903db86aabSstevel if (pcic_reset_time > 0) { 44913db86aabSstevel pcic_err(pcic->dip, 8, "pcic_ll_reset reset_wait %d mS\n", 44923db86aabSstevel pcic_reset_time); 44933db86aabSstevel pcic_mswait(pcic, socket, pcic_reset_time); 44943db86aabSstevel } 44953db86aabSstevel 44963db86aabSstevel pcic_err(pcic->dip, 8, "pcic_ll_reset take it out of reset now\n"); 44973db86aabSstevel 44983db86aabSstevel /* take it out of RESET now */ 44993db86aabSstevel pcic_putb(pcic, socket, PCIC_INTERRUPT, PCIC_RESET | iobits); 45003db86aabSstevel (void) pcic_getb(pcic, socket, PCIC_INTERRUPT); 45013db86aabSstevel 45023db86aabSstevel /* 45033db86aabSstevel * can't access the card for 20ms, but we really don't 45043db86aabSstevel * want to sit around that long. The pcic is still usable. 45053db86aabSstevel * memory accesses must wait for RDY to come up. 45063db86aabSstevel */ 45073db86aabSstevel if (pcic_postreset_time > 0) { 45083db86aabSstevel pcic_err(pcic->dip, 8, "pcic_ll_reset post_wait %d mS\n", 45093db86aabSstevel pcic_postreset_time); 45103db86aabSstevel pcic_mswait(pcic, socket, pcic_postreset_time); 45113db86aabSstevel } 45123db86aabSstevel 45133db86aabSstevel if (pcic_vpp_is_vcc_during_reset > 1) { 45143db86aabSstevel 45153db86aabSstevel /* 45163db86aabSstevel * Return VPP power to whatever it was before. 45173db86aabSstevel */ 45183db86aabSstevel if (pcic->pc_flags & PCF_CBPWRCTL) { 45193db86aabSstevel pcic_putcb(pcic, CB_CONTROL, pwr); 45203db86aabSstevel (void) pcic_getcb(pcic, CB_CONTROL); 45213db86aabSstevel } else { 45223db86aabSstevel pcic_putb(pcic, socket, PCIC_POWER_CONTROL, pwr); 45233db86aabSstevel (void) pcic_getb(pcic, socket, PCIC_POWER_CONTROL); 45243db86aabSstevel } 45253db86aabSstevel } 45263db86aabSstevel 45273db86aabSstevel pcic_err(pcic->dip, 7, "pcic_ll_reset returning 0x%x\n", windowbits); 45283db86aabSstevel 45293db86aabSstevel return (windowbits); 45303db86aabSstevel } 45313db86aabSstevel 45323db86aabSstevel /* 45333db86aabSstevel * pcic_reset_socket() 45343db86aabSstevel * SocketServices ResetSocket function 45353db86aabSstevel * puts the PC Card in the socket into the RESET state 45363db86aabSstevel * and then takes it out after the the cycle time 45373db86aabSstevel * The socket is back to initial state when done 45383db86aabSstevel */ 45393db86aabSstevel static int 45403db86aabSstevel pcic_reset_socket(dev_info_t *dip, int socket, int mode) 45413db86aabSstevel { 45423db86aabSstevel anp_t *anp = ddi_get_driver_private(dip); 45433db86aabSstevel pcicdev_t *pcic = anp->an_private; 45443db86aabSstevel int value; 45453db86aabSstevel int i, mint; 45463db86aabSstevel pcic_socket_t *sockp; 45473db86aabSstevel 45483db86aabSstevel #if defined(PCIC_DEBUG) 45493db86aabSstevel if (pcic_debug >= 8) 45503db86aabSstevel cmn_err(CE_CONT, "pcic_reset_socket(%p, %d, %d/%s)\n", 45513db86aabSstevel (void *)dip, socket, mode, 45523db86aabSstevel mode == RESET_MODE_FULL ? "full" : "partial"); 45533db86aabSstevel #endif 45543db86aabSstevel 45553db86aabSstevel mutex_enter(&pcic->pc_lock); /* protect the registers */ 45563db86aabSstevel 45573db86aabSstevel /* Turn off management interupts. */ 45583db86aabSstevel mint = pcic_getb(pcic, socket, PCIC_MANAGEMENT_INT); 45593db86aabSstevel pcic_putb(pcic, socket, PCIC_MANAGEMENT_INT, mint & ~PCIC_CHANGE_MASK); 45603db86aabSstevel 45613db86aabSstevel sockp = &pcic->pc_sockets[socket]; 45623db86aabSstevel 45633db86aabSstevel value = pcic_ll_reset(pcic, socket); 45643db86aabSstevel if (mode == RESET_MODE_FULL) { 45653db86aabSstevel /* disable and unmap all mapped windows */ 45663db86aabSstevel for (i = 0; i < PCIC_NUMWINSOCK; i++) { 45673db86aabSstevel if (i < PCIC_IOWINDOWS) { 45683db86aabSstevel if (sockp->pcs_windows[i].io.pcw_status & 45693db86aabSstevel PCW_MAPPED) { 45703db86aabSstevel pcs_iowin_t *io; 45713db86aabSstevel io = &sockp->pcs_windows[i].io; 45723db86aabSstevel io->pcw_status &= ~PCW_ENABLED; 45733db86aabSstevel } 45743db86aabSstevel } else { 45753db86aabSstevel if (sockp->pcs_windows[i].mem.pcw_status & 45763db86aabSstevel PCW_MAPPED) { 45773db86aabSstevel pcs_memwin_t *mem; 45783db86aabSstevel mem = &sockp->pcs_windows[i].mem; 45793db86aabSstevel mem->pcw_status &= ~PCW_ENABLED; 45803db86aabSstevel } 45813db86aabSstevel } 45823db86aabSstevel } 45833db86aabSstevel } else { 45843db86aabSstevel /* turn windows back on */ 45853db86aabSstevel pcic_putb(pcic, socket, PCIC_MAPPING_ENABLE, value); 45863db86aabSstevel /* wait the rest of the time here */ 45873db86aabSstevel pcic_mswait(pcic, socket, 10); 45883db86aabSstevel } 45893db86aabSstevel pcic_putb(pcic, socket, PCIC_MANAGEMENT_INT, mint); 45903db86aabSstevel mutex_exit(&pcic->pc_lock); 45913db86aabSstevel return (SUCCESS); 45923db86aabSstevel } 45933db86aabSstevel 45943db86aabSstevel /* 45953db86aabSstevel * pcic_set_interrupt() 45963db86aabSstevel * SocketServices SetInterrupt function 45973db86aabSstevel */ 45983db86aabSstevel static int 45993db86aabSstevel pcic_set_interrupt(dev_info_t *dip, set_irq_handler_t *handler) 46003db86aabSstevel { 46013db86aabSstevel anp_t *anp = ddi_get_driver_private(dip); 46023db86aabSstevel pcicdev_t *pcic = anp->an_private; 46033db86aabSstevel int value = DDI_SUCCESS; 46043db86aabSstevel inthandler_t *intr; 46053db86aabSstevel 46063db86aabSstevel #if defined(PCIC_DEBUG) 46073db86aabSstevel if (pcic_debug) { 46083db86aabSstevel cmn_err(CE_CONT, 46093db86aabSstevel "pcic_set_interrupt: entered pc_intr_mode=0x%x\n", 46103db86aabSstevel pcic->pc_intr_mode); 46113db86aabSstevel cmn_err(CE_CONT, 46123db86aabSstevel "\t irq_top=%p handler=%p handler_id=%x\n", 46133db86aabSstevel (void *)pcic->irq_top, (void *)handler->handler, 46143db86aabSstevel handler->handler_id); 46153db86aabSstevel } 46163db86aabSstevel #endif 46173db86aabSstevel 46183db86aabSstevel /* 46193db86aabSstevel * If we're on a PCI bus, we route all IO IRQs through a single 46203db86aabSstevel * PCI interrupt (typically INT A#) so we don't have to do 46213db86aabSstevel * much other than add the caller to general interrupt handler 46223db86aabSstevel * and set some state. 46233db86aabSstevel */ 46243db86aabSstevel 46253db86aabSstevel intr = kmem_zalloc(sizeof (inthandler_t), KM_NOSLEEP); 46263db86aabSstevel if (intr == NULL) 46273db86aabSstevel return (NO_RESOURCE); 46283db86aabSstevel 46293db86aabSstevel switch (pcic->pc_intr_mode) { 46303db86aabSstevel case PCIC_INTR_MODE_PCI_1: 46313db86aabSstevel /* 46323db86aabSstevel * We only allow above-lock-level IO IRQ handlers 46333db86aabSstevel * in the PCI bus case. 46343db86aabSstevel */ 46353db86aabSstevel 46363db86aabSstevel mutex_enter(&pcic->intr_lock); 46373db86aabSstevel 46383db86aabSstevel if (pcic->irq_top == NULL) { 46393db86aabSstevel pcic->irq_top = intr; 46403db86aabSstevel pcic->irq_current = pcic->irq_top; 46413db86aabSstevel } else { 46423db86aabSstevel while (pcic->irq_current->next != NULL) 46433db86aabSstevel pcic->irq_current = pcic->irq_current->next; 46443db86aabSstevel pcic->irq_current->next = intr; 46453db86aabSstevel pcic->irq_current = pcic->irq_current->next; 46463db86aabSstevel } 46473db86aabSstevel 46483db86aabSstevel pcic->irq_current->intr = 46493db86aabSstevel (ddi_intr_handler_t *)handler->handler; 46503db86aabSstevel pcic->irq_current->handler_id = handler->handler_id; 46513db86aabSstevel pcic->irq_current->arg1 = handler->arg1; 46523db86aabSstevel pcic->irq_current->arg2 = handler->arg2; 46533db86aabSstevel pcic->irq_current->socket = handler->socket; 46543db86aabSstevel 46553db86aabSstevel mutex_exit(&pcic->intr_lock); 46563db86aabSstevel 46573db86aabSstevel handler->iblk_cookie = &pcic->pc_pri; 46583db86aabSstevel handler->idev_cookie = &pcic->pc_dcookie; 46593db86aabSstevel break; 46603db86aabSstevel 46613db86aabSstevel default: 46623db86aabSstevel intr->intr = (ddi_intr_handler_t *)handler->handler; 46633db86aabSstevel intr->handler_id = handler->handler_id; 46643db86aabSstevel intr->arg1 = handler->arg1; 46653db86aabSstevel intr->arg2 = handler->arg2; 46663db86aabSstevel intr->socket = handler->socket; 46673db86aabSstevel intr->irq = handler->irq; 46683db86aabSstevel 46693db86aabSstevel /* 46703db86aabSstevel * need to revisit this to see if interrupts can be 46713db86aabSstevel * shared someday. Note that IRQ is set in the common 46723db86aabSstevel * code. 46733db86aabSstevel */ 46743db86aabSstevel mutex_enter(&pcic->pc_lock); 46753db86aabSstevel if (pcic->pc_handlers == NULL) { 46763db86aabSstevel pcic->pc_handlers = intr; 46773db86aabSstevel intr->next = intr->prev = intr; 46783db86aabSstevel } else { 46793db86aabSstevel insque(intr, pcic->pc_handlers); 46803db86aabSstevel } 46813db86aabSstevel mutex_exit(&pcic->pc_lock); 46823db86aabSstevel 46833db86aabSstevel break; 46843db86aabSstevel } 46853db86aabSstevel 46863db86aabSstevel /* 46873db86aabSstevel * need to fill in cookies in event of multiple high priority 46883db86aabSstevel * interrupt handlers on same IRQ 46893db86aabSstevel */ 46903db86aabSstevel 46913db86aabSstevel #if defined(PCIC_DEBUG) 46923db86aabSstevel if (pcic_debug) { 46933db86aabSstevel cmn_err(CE_CONT, 46943db86aabSstevel "pcic_set_interrupt: exit irq_top=%p value=%d\n", 46953db86aabSstevel (void *)pcic->irq_top, value); 46963db86aabSstevel } 46973db86aabSstevel #endif 46983db86aabSstevel 46993db86aabSstevel if (value == DDI_SUCCESS) { 47003db86aabSstevel return (SUCCESS); 47013db86aabSstevel } else { 47023db86aabSstevel return (BAD_IRQ); 47033db86aabSstevel } 47043db86aabSstevel } 47053db86aabSstevel 47063db86aabSstevel /* 47073db86aabSstevel * pcic_clear_interrupt() 47083db86aabSstevel * SocketServices ClearInterrupt function 47093db86aabSstevel * 47103db86aabSstevel * Interrupts for PCIC are complicated by the fact that we must 47113db86aabSstevel * follow several different models for interrupts. 47123db86aabSstevel * ISA: there is an interrupt per adapter and per socket and 47133db86aabSstevel * they can't be shared. 47143db86aabSstevel * PCI: some adapters have one PCI interrupt available while others 47153db86aabSstevel * have up to 4. Solaris may or may not allow us to use more 47163db86aabSstevel * than 1 so we essentially share them all at this point. 47173db86aabSstevel * Hybrid: PCI bridge but interrupts wired to host interrupt controller. 47183db86aabSstevel * This is like ISA but we have to fudge and create an intrspec 47193db86aabSstevel * that PCI's parent understands and bypass the PCI nexus. 47203db86aabSstevel * multifunction: this requires sharing the interrupts on a per-socket 47213db86aabSstevel * basis. 47223db86aabSstevel */ 47233db86aabSstevel static int 47243db86aabSstevel pcic_clear_interrupt(dev_info_t *dip, clear_irq_handler_t *handler) 47253db86aabSstevel { 47263db86aabSstevel anp_t *anp = ddi_get_driver_private(dip); 47273db86aabSstevel pcicdev_t *pcic = anp->an_private; 47283db86aabSstevel inthandler_t *intr, *prev, *current; 47293db86aabSstevel int i; 47303db86aabSstevel 47313db86aabSstevel /* 47323db86aabSstevel * If we're on a PCI bus, we route all IO IRQs through a single 47333db86aabSstevel * PCI interrupt (typically INT A#) so we don't have to do 47343db86aabSstevel * much other than remove the caller from the general 47353db86aabSstevel * interrupt handler callout list. 47363db86aabSstevel */ 47373db86aabSstevel 47383db86aabSstevel #if defined(PCIC_DEBUG) 47393db86aabSstevel if (pcic_debug) { 47403db86aabSstevel cmn_err(CE_CONT, 47413db86aabSstevel "pcic_clear_interrupt: entered pc_intr_mode=0x%x\n", 47423db86aabSstevel pcic->pc_intr_mode); 47433db86aabSstevel cmn_err(CE_CONT, 47443db86aabSstevel "\t irq_top=%p handler=%p handler_id=%x\n", 47453db86aabSstevel (void *)pcic->irq_top, (void *)handler->handler, 47463db86aabSstevel handler->handler_id); 47473db86aabSstevel } 47483db86aabSstevel #endif 47493db86aabSstevel 47503db86aabSstevel switch (pcic->pc_intr_mode) { 47513db86aabSstevel case PCIC_INTR_MODE_PCI_1: 47523db86aabSstevel 47533db86aabSstevel mutex_enter(&pcic->intr_lock); 47543db86aabSstevel if (pcic->irq_top == NULL) { 47553db86aabSstevel mutex_exit(&pcic->intr_lock); 47563db86aabSstevel return (BAD_IRQ); 47573db86aabSstevel } 47583db86aabSstevel 47593db86aabSstevel intr = NULL; 47603db86aabSstevel pcic->irq_current = pcic->irq_top; 47613db86aabSstevel 47623db86aabSstevel while ((pcic->irq_current != NULL) && 47633db86aabSstevel (pcic->irq_current->handler_id != 47643db86aabSstevel handler->handler_id)) { 47653db86aabSstevel intr = pcic->irq_current; 47663db86aabSstevel pcic->irq_current = pcic->irq_current->next; 47673db86aabSstevel } 47683db86aabSstevel 47693db86aabSstevel if (pcic->irq_current == NULL) { 47703db86aabSstevel mutex_exit(&pcic->intr_lock); 47713db86aabSstevel return (BAD_IRQ); 47723db86aabSstevel } 47733db86aabSstevel 47743db86aabSstevel if (intr != NULL) { 47753db86aabSstevel intr->next = pcic->irq_current->next; 47763db86aabSstevel } else { 47773db86aabSstevel pcic->irq_top = pcic->irq_current->next; 47783db86aabSstevel } 47793db86aabSstevel 47803db86aabSstevel current = pcic->irq_current; 47813db86aabSstevel pcic->irq_current = pcic->irq_top; 47823db86aabSstevel mutex_exit(&pcic->intr_lock); 47833db86aabSstevel kmem_free(current, sizeof (inthandler_t)); 47843db86aabSstevel 47853db86aabSstevel break; 47863db86aabSstevel 47873db86aabSstevel default: 47883db86aabSstevel 47893db86aabSstevel mutex_enter(&pcic->pc_lock); 47903db86aabSstevel intr = pcic_handlers; 47913db86aabSstevel prev = (inthandler_t *)&pcic_handlers; 47923db86aabSstevel 47933db86aabSstevel while (intr != NULL) { 47943db86aabSstevel if (intr->handler_id == handler->handler_id) { 47953db86aabSstevel i = intr->irq & PCIC_INTR_MASK; 47963db86aabSstevel if (--pcic_irq_map[i].count == 0) { 47973db86aabSstevel /* multi-handler form */ 47983db86aabSstevel (void) ddi_intr_disable(pcic->pc_intr_htblp[i]); 47993db86aabSstevel (void) ddi_intr_remove_handler( 48003db86aabSstevel pcic->pc_intr_htblp[i]); 48013db86aabSstevel (void) ddi_intr_free(pcic->pc_intr_htblp[i]); 48023db86aabSstevel (void) pcmcia_return_intr(pcic->dip, i); 48033db86aabSstevel #if defined(PCIC_DEBUG) 48043db86aabSstevel if (pcic_debug) { 48053db86aabSstevel cmn_err(CE_CONT, 48063db86aabSstevel "removing interrupt %d at %s " 48073db86aabSstevel "priority\n", i, "high"); 48083db86aabSstevel cmn_err(CE_CONT, 48093db86aabSstevel "ddi_remove_intr(%p, %x, %p)\n", 48103db86aabSstevel (void *)dip, 48113db86aabSstevel 0, 48123db86aabSstevel (void *)intr->iblk_cookie); 48133db86aabSstevel } 48143db86aabSstevel #endif 48153db86aabSstevel } 48163db86aabSstevel prev->next = intr->next; 48173db86aabSstevel kmem_free(intr, sizeof (inthandler_t)); 48183db86aabSstevel intr = prev->next; 48193db86aabSstevel } else { 48203db86aabSstevel prev = intr; 48213db86aabSstevel intr = intr->next; 48223db86aabSstevel } /* if (handler_id) */ 48233db86aabSstevel } /* while */ 48243db86aabSstevel 48253db86aabSstevel mutex_exit(&pcic->pc_lock); 48263db86aabSstevel } 48273db86aabSstevel 48283db86aabSstevel #if defined(PCIC_DEBUG) 48293db86aabSstevel if (pcic_debug) { 48303db86aabSstevel cmn_err(CE_CONT, 48313db86aabSstevel "pcic_clear_interrupt: exit irq_top=%p\n", 48323db86aabSstevel (void *)pcic->irq_top); 48333db86aabSstevel } 48343db86aabSstevel #endif 48353db86aabSstevel 48363db86aabSstevel 48373db86aabSstevel return (SUCCESS); 48383db86aabSstevel } 48393db86aabSstevel 48403db86aabSstevel struct intel_regs { 48413db86aabSstevel char *name; 48423db86aabSstevel int off; 48433db86aabSstevel char *fmt; 48443db86aabSstevel } iregs[] = { 48453db86aabSstevel {"ident ", 0}, 48463db86aabSstevel {"if-status ", 1, "\020\1BVD1\2BVD2\3CD1\4CD2\5WP\6RDY\7PWR\10~GPI"}, 48473db86aabSstevel {"power ", 2, "\020\1Vpp1c0\2Vpp1c1\3Vpp2c0\4Vpp2c1\5PE\6AUTO" 48483db86aabSstevel "\7DRD\10OE"}, 48493db86aabSstevel {"cardstatus", 4, "\020\1BD\2BW\3RC\4CD\5GPI\6R1\7R2\010R3"}, 48503db86aabSstevel {"enable ", 6, "\020\1MW0\2MW1\3MW2\4MW3\5MW4\6MEM16\7IO0\10IO1"}, 48513db86aabSstevel {"cd-gcr ", 0x16, "\020\1MDI16\2CRE\3GPIE\4GPIT\5CDR\6S/W"}, 48523db86aabSstevel {"GCR ", 0x1e, "\020\1PD\2LEVEL\3WCSC\4PLS14"}, 48533db86aabSstevel {"int-gcr ", 3, "\020\5INTR\6IO\7~RST\10RI"}, 48543db86aabSstevel {"management", 5, "\020\1BDE\2BWE\3RE\4CDE"}, 48553db86aabSstevel {"volt-sense", 0x1f, "\020\1A_VS1\2A_VS2\3B_VS1\4B_VS2"}, 48563db86aabSstevel {"volt-sel ", 0x2f, "\020\5EXTCONF\6BUSSELECT\7MIXEDV\10ISAV"}, 48573db86aabSstevel {"VG ext A ", 0x3c, "\20\3IVS\4CABLE\5CSTEP\6TEST\7RIO"}, 48583db86aabSstevel {"io-ctrl ", 7, "\020\1DS0\2IOCS0\3ZWS0\4WS0\5DS1\6IOS1\7ZWS1\10WS1"}, 48593db86aabSstevel {"io0-slow ", 8}, 48603db86aabSstevel {"io0-shi ", 9}, 48613db86aabSstevel {"io0-elow ", 0xa}, 48623db86aabSstevel {"io0-ehi ", 0xb}, 48633db86aabSstevel {"io1-slow ", 0xc}, 48643db86aabSstevel {"io1-shi ", 0xd}, 48653db86aabSstevel {"io1-elow ", 0xe}, 48663db86aabSstevel {"io1-ehi ", 0xf}, 48673db86aabSstevel {"mem0-slow ", 0x10}, 48683db86aabSstevel {"mem0-shi ", 0x11, "\020\7ZW\10DS"}, 48693db86aabSstevel {"mem0-elow ", 0x12}, 48703db86aabSstevel {"mem0-ehi ", 0x13, "\020\7WS0\10WS1"}, 48713db86aabSstevel {"card0-low ", 0x14}, 48723db86aabSstevel {"card0-hi ", 0x15, "\020\7AM\10WP"}, 48733db86aabSstevel {"mem1-slow ", 0x18}, 48743db86aabSstevel {"mem1-shi ", 0x19, "\020\7ZW\10DS"}, 48753db86aabSstevel {"mem1-elow ", 0x1a}, 48763db86aabSstevel {"mem1-ehi ", 0x1b, "\020\7WS0\10WS1"}, 48773db86aabSstevel {"card1-low ", 0x1c}, 48783db86aabSstevel {"card1-hi ", 0x1d, "\020\7AM\10WP"}, 48793db86aabSstevel {"mem2-slow ", 0x20}, 48803db86aabSstevel {"mem2-shi ", 0x21, "\020\7ZW\10DS"}, 48813db86aabSstevel {"mem2-elow ", 0x22}, 48823db86aabSstevel {"mem2-ehi ", 0x23, "\020\7WS0\10WS1"}, 48833db86aabSstevel {"card2-low ", 0x24}, 48843db86aabSstevel {"card2-hi ", 0x25, "\020\7AM\10WP"}, 48853db86aabSstevel {"mem3-slow ", 0x28}, 48863db86aabSstevel {"mem3-shi ", 0x29, "\020\7ZW\10DS"}, 48873db86aabSstevel {"mem3-elow ", 0x2a}, 48883db86aabSstevel {"mem3-ehi ", 0x2b, "\020\7WS0\10WS1"}, 48893db86aabSstevel {"card3-low ", 0x2c}, 48903db86aabSstevel {"card3-hi ", 0x2d, "\020\7AM\10WP"}, 48913db86aabSstevel 48923db86aabSstevel {"mem4-slow ", 0x30}, 48933db86aabSstevel {"mem4-shi ", 0x31, "\020\7ZW\10DS"}, 48943db86aabSstevel {"mem4-elow ", 0x32}, 48953db86aabSstevel {"mem4-ehi ", 0x33, "\020\7WS0\10WS1"}, 48963db86aabSstevel {"card4-low ", 0x34}, 48973db86aabSstevel {"card4-hi ", 0x35, "\020\7AM\10WP"}, 48983db86aabSstevel {"mpage0 ", 0x40}, 48993db86aabSstevel {"mpage1 ", 0x41}, 49003db86aabSstevel {"mpage2 ", 0x42}, 49013db86aabSstevel {"mpage3 ", 0x43}, 49023db86aabSstevel {"mpage4 ", 0x44}, 49033db86aabSstevel {NULL}, 49043db86aabSstevel }; 49053db86aabSstevel 49063db86aabSstevel static struct intel_regs cregs[] = { 49073db86aabSstevel {"misc-ctl1 ", 0x16, "\20\2VCC3\3PMI\4PSI\5SPKR\10INPACK"}, 49083db86aabSstevel {"fifo ", 0x17, "\20\6DIOP\7DMEMP\10EMPTY"}, 49093db86aabSstevel {"misc-ctl2 ", 0x1e, "\20\1XCLK\2LOW\3SUSP\4CORE5V\5TCD\10RIOUT"}, 49103db86aabSstevel {"chip-info ", 0x1f, "\20\6DUAL"}, 49113db86aabSstevel {"IO-offlow0", 0x36}, 49123db86aabSstevel {"IO-offhi0 ", 0x37}, 49133db86aabSstevel {"IO-offlow1", 0x38}, 49143db86aabSstevel {"IO-offhi1 ", 0x39}, 49153db86aabSstevel NULL, 49163db86aabSstevel }; 49173db86aabSstevel 49183db86aabSstevel static struct intel_regs cxregs[] = { 49193db86aabSstevel {"ext-ctl-1 ", 0x03, 49203db86aabSstevel "\20\1VCCLCK\2AUTOCLR\3LED\4INVIRQC\5INVIRQM\6PUC"}, 49213db86aabSstevel {"misc-ctl3 ", 0x25, "\20\5HWSUSP"}, 49223db86aabSstevel {"mem0-up ", 0x05}, 49233db86aabSstevel {"mem1-up ", 0x06}, 49243db86aabSstevel {"mem2-up ", 0x07}, 49253db86aabSstevel {"mem3-up ", 0x08}, 49263db86aabSstevel {"mem4-up ", 0x09}, 49273db86aabSstevel {NULL} 49283db86aabSstevel }; 49293db86aabSstevel 49303db86aabSstevel void 49313db86aabSstevel xxdmp_cl_regs(pcicdev_t *pcic, int socket, uint32_t len) 49323db86aabSstevel { 49333db86aabSstevel int i, value, j; 49343db86aabSstevel char buff[256]; 49353db86aabSstevel char *fmt; 49363db86aabSstevel 49373db86aabSstevel cmn_err(CE_CONT, "--------- Cirrus Logic Registers --------\n"); 49383db86aabSstevel for (buff[0] = '\0', i = 0; cregs[i].name != NULL && len-- != 0; i++) { 49393db86aabSstevel int sval; 49403db86aabSstevel if (cregs[i].off == PCIC_MISC_CTL_2) 49413db86aabSstevel sval = 0; 49423db86aabSstevel else 49433db86aabSstevel sval = socket; 49443db86aabSstevel value = pcic_getb(pcic, sval, cregs[i].off); 49453db86aabSstevel if (i & 1) { 49463db86aabSstevel if (cregs[i].fmt) 49473db86aabSstevel fmt = "%s\t%s\t%b\n"; 49483db86aabSstevel else 49493db86aabSstevel fmt = "%s\t%s\t%x\n"; 49503db86aabSstevel cmn_err(CE_CONT, fmt, buff, 49513db86aabSstevel cregs[i].name, value, cregs[i].fmt); 49523db86aabSstevel buff[0] = '\0'; 49533db86aabSstevel } else { 49543db86aabSstevel if (cregs[i].fmt) 49553db86aabSstevel fmt = "\t%s\t%b"; 49563db86aabSstevel else 49573db86aabSstevel fmt = "\t%s\t%x"; 49583db86aabSstevel (void) sprintf(buff, fmt, 49593db86aabSstevel cregs[i].name, value, cregs[i].fmt); 49603db86aabSstevel for (j = strlen(buff); j < 40; j++) 49613db86aabSstevel buff[j] = ' '; 49623db86aabSstevel buff[40] = '\0'; 49633db86aabSstevel } 49643db86aabSstevel } 49653db86aabSstevel cmn_err(CE_CONT, "%s\n", buff); 49663db86aabSstevel 49673db86aabSstevel i = pcic_getb(pcic, socket, PCIC_TIME_SETUP_0); 49683db86aabSstevel j = pcic_getb(pcic, socket, PCIC_TIME_SETUP_1); 49693db86aabSstevel cmn_err(CE_CONT, "\tsetup-tim0\t%x\tsetup-tim1\t%x\n", i, j); 49703db86aabSstevel 49713db86aabSstevel i = pcic_getb(pcic, socket, PCIC_TIME_COMMAND_0); 49723db86aabSstevel j = pcic_getb(pcic, socket, PCIC_TIME_COMMAND_1); 49733db86aabSstevel cmn_err(CE_CONT, "\tcmd-tim0 \t%x\tcmd-tim1 \t%x\n", i, j); 49743db86aabSstevel 49753db86aabSstevel i = pcic_getb(pcic, socket, PCIC_TIME_RECOVER_0); 49763db86aabSstevel j = pcic_getb(pcic, socket, PCIC_TIME_RECOVER_1); 49773db86aabSstevel cmn_err(CE_CONT, "\trcvr-tim0 \t%x\trcvr-tim1 \t%x\n", i, j); 49783db86aabSstevel 49793db86aabSstevel cmn_err(CE_CONT, "--------- Extended Registers --------\n"); 49803db86aabSstevel 49813db86aabSstevel for (buff[0] = '\0', i = 0; cxregs[i].name != NULL && len-- != 0; i++) { 49823db86aabSstevel value = clext_reg_read(pcic, socket, cxregs[i].off); 49833db86aabSstevel if (i & 1) { 49843db86aabSstevel if (cxregs[i].fmt) 49853db86aabSstevel fmt = "%s\t%s\t%b\n"; 49863db86aabSstevel else 49873db86aabSstevel fmt = "%s\t%s\t%x\n"; 49883db86aabSstevel cmn_err(CE_CONT, fmt, buff, 49893db86aabSstevel cxregs[i].name, value, cxregs[i].fmt); 49903db86aabSstevel buff[0] = '\0'; 49913db86aabSstevel } else { 49923db86aabSstevel if (cxregs[i].fmt) 49933db86aabSstevel fmt = "\t%s\t%b"; 49943db86aabSstevel else 49953db86aabSstevel fmt = "\t%s\t%x"; 49963db86aabSstevel (void) sprintf(buff, fmt, 49973db86aabSstevel cxregs[i].name, value, cxregs[i].fmt); 49983db86aabSstevel for (j = strlen(buff); j < 40; j++) 49993db86aabSstevel buff[j] = ' '; 50003db86aabSstevel buff[40] = '\0'; 50013db86aabSstevel } 50023db86aabSstevel } 50033db86aabSstevel } 50043db86aabSstevel 50053db86aabSstevel #if defined(PCIC_DEBUG) 50063db86aabSstevel static void 50073db86aabSstevel xxdmp_all_regs(pcicdev_t *pcic, int socket, uint32_t len) 50083db86aabSstevel { 50093db86aabSstevel int i, value, j; 50103db86aabSstevel char buff[256]; 50113db86aabSstevel char *fmt; 50123db86aabSstevel 50133db86aabSstevel #if defined(PCIC_DEBUG) 50143db86aabSstevel if (pcic_debug < 2) 50153db86aabSstevel return; 50163db86aabSstevel #endif 50173db86aabSstevel cmn_err(CE_CONT, 50183db86aabSstevel "----------- PCIC Registers for socket %d---------\n", 50193db86aabSstevel socket); 50203db86aabSstevel cmn_err(CE_CONT, 50213db86aabSstevel "\tname value name value\n"); 50223db86aabSstevel 50233db86aabSstevel for (buff[0] = '\0', i = 0; iregs[i].name != NULL && len-- != 0; i++) { 50243db86aabSstevel value = pcic_getb(pcic, socket, iregs[i].off); 50253db86aabSstevel if (i & 1) { 50263db86aabSstevel if (iregs[i].fmt) 50273db86aabSstevel fmt = "%s\t%s\t%b\n"; 50283db86aabSstevel else 50293db86aabSstevel fmt = "%s\t%s\t%x\n"; 50303db86aabSstevel cmn_err(CE_CONT, fmt, buff, 50313db86aabSstevel iregs[i].name, value, iregs[i].fmt); 50323db86aabSstevel buff[0] = '\0'; 50333db86aabSstevel } else { 50343db86aabSstevel if (iregs[i].fmt) 50353db86aabSstevel fmt = "\t%s\t%b"; 50363db86aabSstevel else 50373db86aabSstevel fmt = "\t%s\t%x"; 50383db86aabSstevel (void) sprintf(buff, fmt, 50393db86aabSstevel iregs[i].name, value, iregs[i].fmt); 50403db86aabSstevel for (j = strlen(buff); j < 40; j++) 50413db86aabSstevel buff[j] = ' '; 50423db86aabSstevel buff[40] = '\0'; 50433db86aabSstevel } 50443db86aabSstevel } 50453db86aabSstevel switch (pcic->pc_type) { 50463db86aabSstevel case PCIC_CL_PD6710: 50473db86aabSstevel case PCIC_CL_PD6722: 50483db86aabSstevel case PCIC_CL_PD6729: 50493db86aabSstevel case PCIC_CL_PD6832: 50503db86aabSstevel (void) xxdmp_cl_regs(pcic, socket, 0xFFFF); 50513db86aabSstevel break; 50523db86aabSstevel } 50533db86aabSstevel cmn_err(CE_CONT, "%s\n", buff); 50543db86aabSstevel } 50553db86aabSstevel #endif 50563db86aabSstevel 50573db86aabSstevel /* 50583db86aabSstevel * pcic_mswait(ms) 50593db86aabSstevel * sleep ms milliseconds 50603db86aabSstevel * call drv_usecwait once for each ms 50613db86aabSstevel */ 50623db86aabSstevel static void 50633db86aabSstevel pcic_mswait(pcicdev_t *pcic, int socket, int ms) 50643db86aabSstevel { 50653db86aabSstevel if (ms) { 50663db86aabSstevel pcic->pc_sockets[socket].pcs_flags |= PCS_WAITING; 50673db86aabSstevel pcic_mutex_exit(&pcic->pc_lock); 50683db86aabSstevel delay(drv_usectohz(ms*1000)); 50693db86aabSstevel pcic_mutex_enter(&pcic->pc_lock); 50703db86aabSstevel pcic->pc_sockets[socket].pcs_flags &= ~PCS_WAITING; 50713db86aabSstevel } 50723db86aabSstevel } 50733db86aabSstevel 50743db86aabSstevel /* 50753db86aabSstevel * pcic_check_ready(pcic, index, off) 50763db86aabSstevel * Wait for card to come ready 50773db86aabSstevel * We only wait if the card is NOT in RESET 50783db86aabSstevel * and power is on. 50793db86aabSstevel */ 50803db86aabSstevel static boolean_t 50813db86aabSstevel pcic_check_ready(pcicdev_t *pcic, int socket) 50823db86aabSstevel { 50833db86aabSstevel int ifstate, intstate; 50843db86aabSstevel 50853db86aabSstevel intstate = pcic_getb(pcic, socket, PCIC_INTERRUPT); 50863db86aabSstevel ifstate = pcic_getb(pcic, socket, PCIC_INTERFACE_STATUS); 50873db86aabSstevel 50883db86aabSstevel if ((intstate & PCIC_RESET) && 50893db86aabSstevel ((ifstate & (PCIC_READY|PCIC_POWER_ON|PCIC_ISTAT_CD_MASK)) == 50903db86aabSstevel (PCIC_READY|PCIC_POWER_ON|PCIC_CD_PRESENT_OK))) 50913db86aabSstevel return (B_TRUE); 50923db86aabSstevel 50933db86aabSstevel #ifdef PCIC_DEBUG 50943db86aabSstevel pcic_err(NULL, 5, "pcic_check_read: Card not ready, intstate = 0x%x, " 50953db86aabSstevel "ifstate = 0x%x\n", intstate, ifstate); 50963db86aabSstevel if (pcic_debug) { 50973db86aabSstevel pcic_debug += 4; 50983db86aabSstevel xxdmp_all_regs(pcic, socket, -1); 50993db86aabSstevel pcic_debug -= 4; 51003db86aabSstevel } 51013db86aabSstevel #endif 51023db86aabSstevel return (B_FALSE); 51033db86aabSstevel } 51043db86aabSstevel 51053db86aabSstevel /* 51063db86aabSstevel * Cirrus Logic extended register read/write routines 51073db86aabSstevel */ 51083db86aabSstevel static int 51093db86aabSstevel clext_reg_read(pcicdev_t *pcic, int sn, uchar_t ext_reg) 51103db86aabSstevel { 51113db86aabSstevel int val; 51123db86aabSstevel 51133db86aabSstevel switch (pcic->pc_io_type) { 51143db86aabSstevel case PCIC_IO_TYPE_YENTA: 51153db86aabSstevel val = ddi_get8(pcic->handle, 51163db86aabSstevel pcic->ioaddr + CB_CLEXT_OFFSET + ext_reg); 51173db86aabSstevel break; 51183db86aabSstevel default: 51193db86aabSstevel pcic_putb(pcic, sn, PCIC_CL_EXINDEX, ext_reg); 51203db86aabSstevel val = pcic_getb(pcic, sn, PCIC_CL_EXINDEX + 1); 51213db86aabSstevel break; 51223db86aabSstevel } 51233db86aabSstevel 51243db86aabSstevel return (val); 51253db86aabSstevel } 51263db86aabSstevel 51273db86aabSstevel static void 51283db86aabSstevel clext_reg_write(pcicdev_t *pcic, int sn, uchar_t ext_reg, uchar_t value) 51293db86aabSstevel { 51303db86aabSstevel switch (pcic->pc_io_type) { 51313db86aabSstevel case PCIC_IO_TYPE_YENTA: 51323db86aabSstevel ddi_put8(pcic->handle, 51333db86aabSstevel pcic->ioaddr + CB_CLEXT_OFFSET + ext_reg, value); 51343db86aabSstevel break; 51353db86aabSstevel default: 51363db86aabSstevel pcic_putb(pcic, sn, PCIC_CL_EXINDEX, ext_reg); 51373db86aabSstevel pcic_putb(pcic, sn, PCIC_CL_EXINDEX + 1, value); 51383db86aabSstevel break; 51393db86aabSstevel } 51403db86aabSstevel } 51413db86aabSstevel 51423db86aabSstevel /* 51433db86aabSstevel * Misc PCI functions 51443db86aabSstevel */ 51453db86aabSstevel static void 51463db86aabSstevel pcic_iomem_pci_ctl(ddi_acc_handle_t handle, uchar_t *cfgaddr, unsigned flags) 51473db86aabSstevel { 51483db86aabSstevel unsigned cmd; 51493db86aabSstevel 51503db86aabSstevel if (flags & (PCIC_ENABLE_IO | PCIC_ENABLE_MEM)) { 51513db86aabSstevel cmd = ddi_get16(handle, (ushort_t *)(cfgaddr + 4)); 51523db86aabSstevel if ((cmd & (PCI_COMM_IO|PCI_COMM_MAE)) == 51533db86aabSstevel (PCI_COMM_IO|PCI_COMM_MAE)) 51543db86aabSstevel return; 51553db86aabSstevel 51563db86aabSstevel if (flags & PCIC_ENABLE_IO) 51573db86aabSstevel cmd |= PCI_COMM_IO; 51583db86aabSstevel 51593db86aabSstevel if (flags & PCIC_ENABLE_MEM) 51603db86aabSstevel cmd |= PCI_COMM_MAE; 51613db86aabSstevel 51623db86aabSstevel ddi_put16(handle, (ushort_t *)(cfgaddr + 4), cmd); 51633db86aabSstevel } /* if (PCIC_ENABLE_IO | PCIC_ENABLE_MEM) */ 51643db86aabSstevel } 51653db86aabSstevel 51663db86aabSstevel /* 51673db86aabSstevel * pcic_find_pci_type - Find and return PCI-PCMCIA adapter type 51683db86aabSstevel */ 51693db86aabSstevel static int 51703db86aabSstevel pcic_find_pci_type(pcicdev_t *pcic) 51713db86aabSstevel { 51723db86aabSstevel uint32_t vend, device; 51733db86aabSstevel 51743db86aabSstevel vend = ddi_getprop(DDI_DEV_T_ANY, pcic->dip, 51753db86aabSstevel DDI_PROP_CANSLEEP|DDI_PROP_DONTPASS, 51763db86aabSstevel "vendor-id", -1); 51773db86aabSstevel device = ddi_getprop(DDI_DEV_T_ANY, pcic->dip, 51783db86aabSstevel DDI_PROP_CANSLEEP|DDI_PROP_DONTPASS, 51793db86aabSstevel "device-id", -1); 51803db86aabSstevel 51813db86aabSstevel device = PCI_ID(vend, device); 51823db86aabSstevel pcic->pc_type = device; 51833db86aabSstevel pcic->pc_chipname = "PCI:unknown"; 51843db86aabSstevel 51853db86aabSstevel switch (device) { 51863db86aabSstevel case PCIC_INTEL_i82092: 51873db86aabSstevel pcic->pc_chipname = PCIC_TYPE_i82092; 51883db86aabSstevel break; 51893db86aabSstevel case PCIC_CL_PD6729: 51903db86aabSstevel pcic->pc_chipname = PCIC_TYPE_PD6729; 51913db86aabSstevel /* 51923db86aabSstevel * Some 6730's incorrectly identify themselves 51933db86aabSstevel * as a 6729, so we need to do some more tests 51943db86aabSstevel * here to see if the device that's claiming 51953db86aabSstevel * to be a 6729 is really a 6730. 51963db86aabSstevel */ 51973db86aabSstevel if ((clext_reg_read(pcic, 0, PCIC_CLEXT_MISC_CTL_3) & 51983db86aabSstevel PCIC_CLEXT_MISC_CTL_3_REV_MASK) == 51993db86aabSstevel 0) { 52003db86aabSstevel pcic->pc_chipname = PCIC_TYPE_PD6730; 52013db86aabSstevel pcic->pc_type = PCIC_CL_PD6730; 52023db86aabSstevel } 52033db86aabSstevel break; 52043db86aabSstevel case PCIC_CL_PD6730: 52053db86aabSstevel pcic->pc_chipname = PCIC_TYPE_PD6730; 52063db86aabSstevel break; 52073db86aabSstevel case PCIC_CL_PD6832: 52083db86aabSstevel pcic->pc_chipname = PCIC_TYPE_PD6832; 52093db86aabSstevel break; 52103db86aabSstevel case PCIC_SMC_34C90: 52113db86aabSstevel pcic->pc_chipname = PCIC_TYPE_34C90; 52123db86aabSstevel break; 52133db86aabSstevel case PCIC_TOSHIBA_TOPIC95: 52143db86aabSstevel pcic->pc_chipname = PCIC_TYPE_TOPIC95; 52153db86aabSstevel break; 52163db86aabSstevel case PCIC_TOSHIBA_TOPIC100: 52173db86aabSstevel pcic->pc_chipname = PCIC_TYPE_TOPIC100; 52183db86aabSstevel break; 52193db86aabSstevel case PCIC_TI_PCI1031: 52203db86aabSstevel pcic->pc_chipname = PCIC_TYPE_PCI1031; 52213db86aabSstevel break; 52223db86aabSstevel case PCIC_TI_PCI1130: 52233db86aabSstevel pcic->pc_chipname = PCIC_TYPE_PCI1130; 52243db86aabSstevel break; 52253db86aabSstevel case PCIC_TI_PCI1131: 52263db86aabSstevel pcic->pc_chipname = PCIC_TYPE_PCI1131; 52273db86aabSstevel break; 52283db86aabSstevel case PCIC_TI_PCI1250: 52293db86aabSstevel pcic->pc_chipname = PCIC_TYPE_PCI1250; 52303db86aabSstevel break; 52313db86aabSstevel case PCIC_TI_PCI1225: 52323db86aabSstevel pcic->pc_chipname = PCIC_TYPE_PCI1225; 52333db86aabSstevel break; 52343db86aabSstevel case PCIC_TI_PCI1410: 52353db86aabSstevel pcic->pc_chipname = PCIC_TYPE_PCI1410; 52363db86aabSstevel break; 52373db86aabSstevel case PCIC_TI_PCI1510: 52383db86aabSstevel pcic->pc_chipname = PCIC_TYPE_PCI1510; 52393db86aabSstevel break; 52403db86aabSstevel case PCIC_TI_PCI1520: 52413db86aabSstevel pcic->pc_chipname = PCIC_TYPE_PCI1520; 52423db86aabSstevel break; 52433db86aabSstevel case PCIC_TI_PCI1221: 52443db86aabSstevel pcic->pc_chipname = PCIC_TYPE_PCI1221; 52453db86aabSstevel break; 52463db86aabSstevel case PCIC_TI_PCI1050: 52473db86aabSstevel pcic->pc_chipname = PCIC_TYPE_PCI1050; 52483db86aabSstevel break; 52493db86aabSstevel case PCIC_ENE_1410: 52503db86aabSstevel pcic->pc_chipname = PCIC_TYPE_1410; 52513db86aabSstevel break; 52523db86aabSstevel case PCIC_O2_OZ6912: 52533db86aabSstevel pcic->pc_chipname = PCIC_TYPE_OZ6912; 52543db86aabSstevel break; 52553db86aabSstevel case PCIC_RICOH_RL5C466: 52563db86aabSstevel pcic->pc_chipname = PCIC_TYPE_RL5C466; 52573db86aabSstevel break; 52583db86aabSstevel case PCIC_TI_PCI1420: 52593db86aabSstevel pcic->pc_chipname = PCIC_TYPE_PCI1420; 52603db86aabSstevel break; 52613db86aabSstevel case PCIC_ENE_1420: 52623db86aabSstevel pcic->pc_chipname = PCIC_TYPE_1420; 52633db86aabSstevel break; 52643db86aabSstevel default: 52653db86aabSstevel switch (PCI_ID(vend, (uint32_t)0)) { 52663db86aabSstevel case PCIC_TOSHIBA_VENDOR: 52673db86aabSstevel pcic->pc_chipname = PCIC_TYPE_TOSHIBA; 52683db86aabSstevel pcic->pc_type = PCIC_TOSHIBA_VENDOR; 52693db86aabSstevel break; 52703db86aabSstevel case PCIC_TI_VENDOR: 52713db86aabSstevel pcic->pc_chipname = PCIC_TYPE_TI; 52723db86aabSstevel pcic->pc_type = PCIC_TI_VENDOR; 52733db86aabSstevel break; 52743db86aabSstevel case PCIC_O2MICRO_VENDOR: 52753db86aabSstevel pcic->pc_chipname = PCIC_TYPE_O2MICRO; 52763db86aabSstevel pcic->pc_type = PCIC_O2MICRO_VENDOR; 52773db86aabSstevel break; 52783db86aabSstevel case PCIC_RICOH_VENDOR: 52793db86aabSstevel pcic->pc_chipname = PCIC_TYPE_RICOH; 52803db86aabSstevel pcic->pc_type = PCIC_RICOH_VENDOR; 52813db86aabSstevel break; 52823db86aabSstevel default: 52833db86aabSstevel if (!(pcic->pc_flags & PCF_CARDBUS)) 52843db86aabSstevel return (DDI_FAILURE); 52853db86aabSstevel pcic->pc_chipname = PCIC_TYPE_YENTA; 52863db86aabSstevel break; 52873db86aabSstevel } 52883db86aabSstevel } 52893db86aabSstevel return (DDI_SUCCESS); 52903db86aabSstevel } 52913db86aabSstevel 52923db86aabSstevel static void 52933db86aabSstevel pcic_82092_smiirq_ctl(pcicdev_t *pcic, int socket, int intr, int state) 52943db86aabSstevel { 52953db86aabSstevel uchar_t ppirr = ddi_get8(pcic->cfg_handle, 52963db86aabSstevel pcic->cfgaddr + PCIC_82092_PPIRR); 52973db86aabSstevel uchar_t val; 52983db86aabSstevel 52993db86aabSstevel if (intr == PCIC_82092_CTL_SMI) { 53003db86aabSstevel val = PCIC_82092_SMI_CTL(socket, 53013db86aabSstevel PCIC_82092_INT_DISABLE); 53023db86aabSstevel ppirr &= ~val; 53033db86aabSstevel val = PCIC_82092_SMI_CTL(socket, state); 53043db86aabSstevel ppirr |= val; 53053db86aabSstevel } else { 53063db86aabSstevel val = PCIC_82092_IRQ_CTL(socket, 53073db86aabSstevel PCIC_82092_INT_DISABLE); 53083db86aabSstevel ppirr &= ~val; 53093db86aabSstevel val = PCIC_82092_IRQ_CTL(socket, state); 53103db86aabSstevel ppirr |= val; 53113db86aabSstevel } 53123db86aabSstevel ddi_put8(pcic->cfg_handle, pcic->cfgaddr + PCIC_82092_PPIRR, 53133db86aabSstevel ppirr); 53143db86aabSstevel } 53153db86aabSstevel 53163db86aabSstevel static uint_t 53173db86aabSstevel pcic_cd_softint(caddr_t arg1, caddr_t arg2) 53183db86aabSstevel { 53193db86aabSstevel pcic_socket_t *sockp = (pcic_socket_t *)arg1; 53203db86aabSstevel uint_t rc = DDI_INTR_UNCLAIMED; 53213db86aabSstevel 53223db86aabSstevel _NOTE(ARGUNUSED(arg2)) 53233db86aabSstevel 53243db86aabSstevel mutex_enter(&sockp->pcs_pcic->pc_lock); 53253db86aabSstevel if (sockp->pcs_cd_softint_flg) { 53263db86aabSstevel uint8_t status; 53273db86aabSstevel sockp->pcs_cd_softint_flg = 0; 53283db86aabSstevel rc = DDI_INTR_CLAIMED; 53293db86aabSstevel status = pcic_getb(sockp->pcs_pcic, sockp->pcs_socket, 53303db86aabSstevel PCIC_INTERFACE_STATUS); 53313db86aabSstevel pcic_handle_cd_change(sockp->pcs_pcic, sockp, status); 53323db86aabSstevel } 53333db86aabSstevel mutex_exit(&sockp->pcs_pcic->pc_lock); 53343db86aabSstevel return (rc); 53353db86aabSstevel } 53363db86aabSstevel 53373db86aabSstevel int pcic_debounce_cnt = PCIC_REM_DEBOUNCE_CNT; 53383db86aabSstevel int pcic_debounce_intr_time = PCIC_REM_DEBOUNCE_TIME; 53393db86aabSstevel int pcic_debounce_cnt_ok = PCIC_DEBOUNCE_OK_CNT; 53403db86aabSstevel 53413db86aabSstevel #ifdef CARDBUS 53423db86aabSstevel static uint32_t pcic_cbps_on = 0; 53433db86aabSstevel static uint32_t pcic_cbps_off = CB_PS_NOTACARD | CB_PS_CCDMASK | 53443db86aabSstevel CB_PS_XVCARD | CB_PS_YVCARD; 53453db86aabSstevel #else 53463db86aabSstevel static uint32_t pcic_cbps_on = CB_PS_16BITCARD; 53473db86aabSstevel static uint32_t pcic_cbps_off = CB_PS_NOTACARD | CB_PS_CCDMASK | 53483db86aabSstevel CB_PS_CBCARD | 53493db86aabSstevel CB_PS_XVCARD | CB_PS_YVCARD; 53503db86aabSstevel #endif 53513db86aabSstevel static void 53523db86aabSstevel pcic_handle_cd_change(pcicdev_t *pcic, pcic_socket_t *sockp, uint8_t status) 53533db86aabSstevel { 53543db86aabSstevel boolean_t do_debounce = B_FALSE; 53553db86aabSstevel int debounce_time = drv_usectohz(pcic_debounce_time); 53563db86aabSstevel uint8_t irq; 53573db86aabSstevel timeout_id_t debounce; 53583db86aabSstevel 53593db86aabSstevel /* 53603db86aabSstevel * Always reset debounce but may need to check original state later. 53613db86aabSstevel */ 53623db86aabSstevel debounce = sockp->pcs_debounce_id; 53633db86aabSstevel sockp->pcs_debounce_id = 0; 53643db86aabSstevel 53653db86aabSstevel /* 53663db86aabSstevel * Check to see whether a card is present or not. There are 53673db86aabSstevel * only two states that we are concerned with - the state 53683db86aabSstevel * where both CD pins are asserted, which means that the 53693db86aabSstevel * card is fully seated, and the state where neither CD 53703db86aabSstevel * pin is asserted, which means that the card is not 53713db86aabSstevel * present. 53723db86aabSstevel * The CD signals are generally very noisy and cause a lot of 53733db86aabSstevel * contact bounce as the card is being inserted and 53743db86aabSstevel * removed, so we need to do some software debouncing. 53753db86aabSstevel */ 53763db86aabSstevel 53773db86aabSstevel #ifdef PCIC_DEBUG 53783db86aabSstevel pcic_err(pcic->dip, 6, 53793db86aabSstevel "pcic%d handle_cd_change: socket %d card status 0x%x" 53803db86aabSstevel " deb 0x%p\n", ddi_get_instance(pcic->dip), 53813db86aabSstevel sockp->pcs_socket, status, debounce); 53823db86aabSstevel #endif 53833db86aabSstevel switch (status & PCIC_ISTAT_CD_MASK) { 53843db86aabSstevel case PCIC_CD_PRESENT_OK: 53853db86aabSstevel sockp->pcs_flags &= ~(PCS_CARD_REMOVED|PCS_CARD_CBREM); 53863db86aabSstevel if (!(sockp->pcs_flags & PCS_CARD_PRESENT)) { 53873db86aabSstevel uint32_t cbps; 53883db86aabSstevel #ifdef PCIC_DEBUG 53893db86aabSstevel pcic_err(pcic->dip, 8, "New card (0x%x)\n", sockp->pcs_flags); 53903db86aabSstevel #endif 53913db86aabSstevel cbps = pcic_getcb(pcic, CB_PRESENT_STATE); 53923db86aabSstevel #ifdef PCIC_DEBUG 53933db86aabSstevel pcic_err(pcic->dip, 8, "CBus PS (0x%x)\n", cbps); 53943db86aabSstevel #endif 53953db86aabSstevel /* 53963db86aabSstevel * Check the CB bits are sane. 53973db86aabSstevel */ 53983db86aabSstevel if ((cbps & pcic_cbps_on) != pcic_cbps_on || 53993db86aabSstevel cbps & pcic_cbps_off) { 54003db86aabSstevel cmn_err(CE_WARN, 54013db86aabSstevel "%s%d: Odd Cardbus Present State 0x%x\n", 54023db86aabSstevel ddi_get_name(pcic->dip), 54033db86aabSstevel ddi_get_instance(pcic->dip), 54043db86aabSstevel cbps); 54053db86aabSstevel pcic_putcb(pcic, CB_EVENT_FORCE, CB_EF_CVTEST); 54063db86aabSstevel debounce = 0; 54073db86aabSstevel debounce_time = drv_usectohz(1000000); 54083db86aabSstevel } 54093db86aabSstevel if (debounce) { 54103db86aabSstevel sockp->pcs_flags |= PCS_CARD_PRESENT; 54113db86aabSstevel if (pcic_do_insertion) { 54123db86aabSstevel 54133db86aabSstevel cbps = pcic_getcb(pcic, CB_PRESENT_STATE); 54143db86aabSstevel 54153db86aabSstevel if (cbps & CB_PS_16BITCARD) { 54163db86aabSstevel pcic_err(pcic->dip, 8, "16 bit card inserted\n"); 54173db86aabSstevel sockp->pcs_flags |= PCS_CARD_IS16BIT; 54183db86aabSstevel /* calls pcm_adapter_callback() */ 54193db86aabSstevel if (pcic->pc_callback) { 54203db86aabSstevel 54213db86aabSstevel (void) ddi_prop_update_string(DDI_DEV_T_NONE, 54223db86aabSstevel pcic->dip, PCM_DEVICETYPE, 54233db86aabSstevel "pccard"); 54243db86aabSstevel PC_CALLBACK(pcic->dip, pcic->pc_cb_arg, 54253db86aabSstevel PCE_CARD_INSERT, 54263db86aabSstevel sockp->pcs_socket); 54273db86aabSstevel } 54283db86aabSstevel } else if (cbps & CB_PS_CBCARD) { 54293db86aabSstevel pcic_err(pcic->dip, 8, "32 bit card inserted\n"); 54303db86aabSstevel 54313db86aabSstevel if (pcic->pc_flags & PCF_CARDBUS) { 54323db86aabSstevel sockp->pcs_flags |= PCS_CARD_ISCARDBUS; 54333db86aabSstevel #ifdef CARDBUS 54343db86aabSstevel if (!pcic_load_cardbus(pcic, sockp)) { 54353db86aabSstevel pcic_unload_cardbus(pcic, sockp); 54363db86aabSstevel } 54373db86aabSstevel 54383db86aabSstevel #else 54393db86aabSstevel cmn_err(CE_NOTE, 54403db86aabSstevel "32 bit Cardbus not supported in" 54413db86aabSstevel " this device driver\n"); 54423db86aabSstevel #endif 54433db86aabSstevel } else { 54443db86aabSstevel /* 54453db86aabSstevel * Ignore the card 54463db86aabSstevel */ 54473db86aabSstevel cmn_err(CE_NOTE, 54483db86aabSstevel "32 bit Cardbus not supported on this" 54493db86aabSstevel " device\n"); 54503db86aabSstevel } 54513db86aabSstevel } else { 54523db86aabSstevel cmn_err(CE_NOTE, 54533db86aabSstevel "Unsupported PCMCIA card inserted\n"); 54543db86aabSstevel } 54553db86aabSstevel } 54563db86aabSstevel } else { 54573db86aabSstevel do_debounce = B_TRUE; 54583db86aabSstevel } 54593db86aabSstevel } else { 54603db86aabSstevel /* 54613db86aabSstevel * It is possible to come through here if the system 54623db86aabSstevel * starts up with cards already inserted. Do nothing 54633db86aabSstevel * and don't worry about it. 54643db86aabSstevel */ 54653db86aabSstevel #ifdef PCIC_DEBUG 54663db86aabSstevel pcic_err(pcic->dip, 5, 54673db86aabSstevel "pcic%d: Odd card insertion indication on socket %d\n", 54683db86aabSstevel ddi_get_instance(pcic->dip), 54693db86aabSstevel sockp->pcs_socket); 54703db86aabSstevel #endif 54713db86aabSstevel } 54723db86aabSstevel break; 54733db86aabSstevel 54743db86aabSstevel default: 54753db86aabSstevel if (!(sockp->pcs_flags & PCS_CARD_PRESENT)) { 54763db86aabSstevel /* 54773db86aabSstevel * Someone has started to insert a card so delay a while. 54783db86aabSstevel */ 54793db86aabSstevel do_debounce = B_TRUE; 54803db86aabSstevel break; 54813db86aabSstevel } 54823db86aabSstevel /* 54833db86aabSstevel * Otherwise this is basically the same as not present 54843db86aabSstevel * so fall through. 54853db86aabSstevel */ 54863db86aabSstevel 54873db86aabSstevel /* FALLTHRU */ 54883db86aabSstevel case 0: 54893db86aabSstevel if (sockp->pcs_flags & PCS_CARD_PRESENT) { 54903db86aabSstevel if (pcic->pc_flags & PCF_CBPWRCTL) { 54913db86aabSstevel pcic_putcb(pcic, CB_CONTROL, 0); 54923db86aabSstevel } else { 54933db86aabSstevel pcic_putb(pcic, sockp->pcs_socket, PCIC_POWER_CONTROL, 0); 54943db86aabSstevel (void) pcic_getb(pcic, sockp->pcs_socket, 54953db86aabSstevel PCIC_POWER_CONTROL); 54963db86aabSstevel } 54973db86aabSstevel #ifdef PCIC_DEBUG 54983db86aabSstevel pcic_err(pcic->dip, 8, "Card removed\n"); 54993db86aabSstevel #endif 55003db86aabSstevel sockp->pcs_flags &= ~PCS_CARD_PRESENT; 55013db86aabSstevel 55023db86aabSstevel if (sockp->pcs_flags & PCS_CARD_IS16BIT) { 55033db86aabSstevel sockp->pcs_flags &= ~PCS_CARD_IS16BIT; 55043db86aabSstevel if (pcic_do_removal && pcic->pc_callback) { 55053db86aabSstevel PC_CALLBACK(pcic->dip, pcic->pc_cb_arg, 55063db86aabSstevel PCE_CARD_REMOVAL, sockp->pcs_socket); 55073db86aabSstevel } 55083db86aabSstevel } 55093db86aabSstevel if (sockp->pcs_flags & PCS_CARD_ISCARDBUS) { 55103db86aabSstevel sockp->pcs_flags &= ~PCS_CARD_ISCARDBUS; 55113db86aabSstevel sockp->pcs_flags |= PCS_CARD_CBREM; 55123db86aabSstevel } 55133db86aabSstevel sockp->pcs_flags |= PCS_CARD_REMOVED; 55143db86aabSstevel 55153db86aabSstevel do_debounce = B_TRUE; 55163db86aabSstevel } 55173db86aabSstevel if (debounce && (sockp->pcs_flags & PCS_CARD_REMOVED)) { 55183db86aabSstevel if (sockp->pcs_flags & PCS_CARD_CBREM) { 55193db86aabSstevel /* 55203db86aabSstevel * Ensure that we do the unloading in the 55213db86aabSstevel * debounce handler, that way we're not doing 55223db86aabSstevel * nasty things in an interrupt handler. e.g. 55233db86aabSstevel * a USB device will wait for data which will 55243db86aabSstevel * obviously never come because we've 55253db86aabSstevel * unplugged the device, but the wait will 55263db86aabSstevel * wait forever because no interrupts can 55273db86aabSstevel * come in... 55283db86aabSstevel */ 55293db86aabSstevel #ifdef CARDBUS 55303db86aabSstevel pcic_unload_cardbus(pcic, sockp); 55313db86aabSstevel /* pcic_dump_all(pcic); */ 55323db86aabSstevel #endif 55333db86aabSstevel sockp->pcs_flags &= ~PCS_CARD_CBREM; 55343db86aabSstevel } 55353db86aabSstevel sockp->pcs_flags &= ~PCS_CARD_REMOVED; 55363db86aabSstevel } 55373db86aabSstevel break; 55383db86aabSstevel } /* switch */ 55393db86aabSstevel 55403db86aabSstevel if (do_debounce) { 55413db86aabSstevel /* 55423db86aabSstevel * Delay doing 55433db86aabSstevel * anything for a while so that things can settle 55443db86aabSstevel * down a little. Interrupts are already disabled. 55453db86aabSstevel * Reset the state and we'll reevaluate the 55463db86aabSstevel * whole kit 'n kaboodle when the timeout fires 55473db86aabSstevel */ 55483db86aabSstevel #ifdef PCIC_DEBUG 55493db86aabSstevel pcic_err(pcic->dip, 8, "Queueing up debounce timeout for " 55503db86aabSstevel "socket %d.%d\n", 55513db86aabSstevel ddi_get_instance(pcic->dip), 55523db86aabSstevel sockp->pcs_socket); 55533db86aabSstevel #endif 55543db86aabSstevel sockp->pcs_debounce_id = pcic_add_debqueue(sockp, debounce_time); 55553db86aabSstevel 55563db86aabSstevel /* 55573db86aabSstevel * We bug out here without re-enabling interrupts. They will 55583db86aabSstevel * be re-enabled when the debounce timeout swings through 55593db86aabSstevel * here. 55603db86aabSstevel */ 55613db86aabSstevel return; 55623db86aabSstevel } 55633db86aabSstevel 55643db86aabSstevel /* 55653db86aabSstevel * Turn on Card detect interrupts. Other interrupts will be 55663db86aabSstevel * enabled during set_socket calls. 55673db86aabSstevel * 55683db86aabSstevel * Note that set_socket only changes interrupt settings when there 55693db86aabSstevel * is a card present. 55703db86aabSstevel */ 55713db86aabSstevel irq = pcic_getb(pcic, sockp->pcs_socket, PCIC_MANAGEMENT_INT); 55723db86aabSstevel irq |= PCIC_CD_DETECT; 55733db86aabSstevel pcic_putb(pcic, sockp->pcs_socket, PCIC_MANAGEMENT_INT, irq); 55740e995c33Srw148561 pcic_putcb(pcic, CB_STATUS_MASK, CB_SE_CCDMASK); 55753db86aabSstevel 55760d282d13Srw148561 /* Out from debouncing state */ 55770d282d13Srw148561 sockp->pcs_flags &= ~PCS_DEBOUNCING; 55780d282d13Srw148561 55793db86aabSstevel pcic_err(pcic->dip, 7, "Leaving pcic_handle_cd_change\n"); 55803db86aabSstevel } 55813db86aabSstevel 55823db86aabSstevel /* 55833db86aabSstevel * pcic_getb() 55843db86aabSstevel * get an I/O byte based on the yardware decode method 55853db86aabSstevel */ 55863db86aabSstevel static uint8_t 55873db86aabSstevel pcic_getb(pcicdev_t *pcic, int socket, int reg) 55883db86aabSstevel { 55893db86aabSstevel int work; 55903db86aabSstevel 55913db86aabSstevel #if defined(PCIC_DEBUG) 55923db86aabSstevel if (pcic_debug == 0x7fff) { 55933db86aabSstevel cmn_err(CE_CONT, "pcic_getb0: pcic=%p socket=%d reg=%d\n", 55943db86aabSstevel (void *)pcic, socket, reg); 55953db86aabSstevel cmn_err(CE_CONT, "pcic_getb1: type=%d handle=%p ioaddr=%p \n", 55963db86aabSstevel pcic->pc_io_type, (void *)pcic->handle, 55973db86aabSstevel (void *)pcic->ioaddr); 55983db86aabSstevel } 55993db86aabSstevel #endif 56003db86aabSstevel 56013db86aabSstevel switch (pcic->pc_io_type) { 56023db86aabSstevel case PCIC_IO_TYPE_YENTA: 56033db86aabSstevel return (ddi_get8(pcic->handle, 56043db86aabSstevel pcic->ioaddr + CB_R2_OFFSET + reg)); 56053db86aabSstevel default: 56063db86aabSstevel work = (socket * PCIC_SOCKET_1) | reg; 56073db86aabSstevel ddi_put8(pcic->handle, pcic->ioaddr, work); 56083db86aabSstevel return (ddi_get8(pcic->handle, pcic->ioaddr + 1)); 56093db86aabSstevel } 56103db86aabSstevel } 56113db86aabSstevel 56123db86aabSstevel static void 56133db86aabSstevel pcic_putb(pcicdev_t *pcic, int socket, int reg, int8_t value) 56143db86aabSstevel { 56153db86aabSstevel int work; 56163db86aabSstevel 56173db86aabSstevel #if defined(PCIC_DEBUG) 56183db86aabSstevel if (pcic_debug == 0x7fff) { 56193db86aabSstevel cmn_err(CE_CONT, 56203db86aabSstevel "pcic_putb0: pcic=%p socket=%d reg=%d value=%x \n", 56213db86aabSstevel (void *)pcic, socket, reg, value); 56223db86aabSstevel cmn_err(CE_CONT, 56233db86aabSstevel "pcic_putb1: type=%d handle=%p ioaddr=%p \n", 56243db86aabSstevel pcic->pc_io_type, (void *)pcic->handle, 56253db86aabSstevel (void *)pcic->ioaddr); 56263db86aabSstevel } 56273db86aabSstevel #endif 56283db86aabSstevel 56293db86aabSstevel 56303db86aabSstevel switch (pcic->pc_io_type) { 56313db86aabSstevel case PCIC_IO_TYPE_YENTA: 56323db86aabSstevel ddi_put8(pcic->handle, pcic->ioaddr + CB_R2_OFFSET + reg, 56333db86aabSstevel value); 56343db86aabSstevel break; 56353db86aabSstevel default: 56363db86aabSstevel work = (socket * PCIC_SOCKET_1) | reg; 56373db86aabSstevel ddi_put8(pcic->handle, pcic->ioaddr, work); 56383db86aabSstevel ddi_put8(pcic->handle, pcic->ioaddr + 1, value); 56393db86aabSstevel break; 56403db86aabSstevel } 56413db86aabSstevel } 56423db86aabSstevel 56433db86aabSstevel /* 56443db86aabSstevel * chip identification functions 56453db86aabSstevel */ 56463db86aabSstevel 56473db86aabSstevel /* 56483db86aabSstevel * chip identification: Cirrus Logic PD6710/6720/6722 56493db86aabSstevel */ 56503db86aabSstevel static int 56513db86aabSstevel pcic_ci_cirrus(pcicdev_t *pcic) 56523db86aabSstevel { 56533db86aabSstevel int value1, value2; 56543db86aabSstevel 56553db86aabSstevel /* Init the CL id mode */ 56563db86aabSstevel value1 = pcic_getb(pcic, 0, PCIC_CHIP_INFO); 56573db86aabSstevel pcic_putb(pcic, 0, PCIC_CHIP_INFO, 0); 56583db86aabSstevel value1 = pcic_getb(pcic, 0, PCIC_CHIP_INFO); 56593db86aabSstevel value2 = pcic_getb(pcic, 0, PCIC_CHIP_INFO); 56603db86aabSstevel 56613db86aabSstevel if ((value1 & PCIC_CI_ID) == PCIC_CI_ID && 56623db86aabSstevel (value2 & PCIC_CI_ID) == 0) { 56633db86aabSstevel /* chip is a Cirrus Logic and not Intel */ 56643db86aabSstevel pcic->pc_type = PCIC_CL_PD6710; 56653db86aabSstevel if (value1 & PCIC_CI_SLOTS) 56663db86aabSstevel pcic->pc_chipname = PCIC_TYPE_PD6720; 56673db86aabSstevel else 56683db86aabSstevel pcic->pc_chipname = PCIC_TYPE_PD6710; 56693db86aabSstevel /* now fine tune things just in case a 6722 */ 56703db86aabSstevel value1 = clext_reg_read(pcic, 0, PCIC_CLEXT_DMASK_0); 56713db86aabSstevel if (value1 == 0) { 56723db86aabSstevel clext_reg_write(pcic, 0, PCIC_CLEXT_SCRATCH, 0x55); 56733db86aabSstevel value1 = clext_reg_read(pcic, 0, PCIC_CLEXT_SCRATCH); 56743db86aabSstevel if (value1 == 0x55) { 56753db86aabSstevel pcic->pc_chipname = PCIC_TYPE_PD6722; 56763db86aabSstevel pcic->pc_type = PCIC_CL_PD6722; 56773db86aabSstevel clext_reg_write(pcic, 0, PCIC_CLEXT_SCRATCH, 0); 56783db86aabSstevel } 56793db86aabSstevel } 56803db86aabSstevel return (1); 56813db86aabSstevel } 56823db86aabSstevel return (0); 56833db86aabSstevel } 56843db86aabSstevel 56853db86aabSstevel /* 56863db86aabSstevel * chip identification: Vadem (VG365/465/468/469) 56873db86aabSstevel */ 56883db86aabSstevel 56893db86aabSstevel static void 56903db86aabSstevel pcic_vadem_enable(pcicdev_t *pcic) 56913db86aabSstevel { 56923db86aabSstevel ddi_put8(pcic->handle, pcic->ioaddr, PCIC_VADEM_P1); 56933db86aabSstevel ddi_put8(pcic->handle, pcic->ioaddr, PCIC_VADEM_P2); 56943db86aabSstevel ddi_put8(pcic->handle, pcic->ioaddr, pcic->pc_lastreg); 56953db86aabSstevel } 56963db86aabSstevel 56973db86aabSstevel static int 56983db86aabSstevel pcic_ci_vadem(pcicdev_t *pcic) 56993db86aabSstevel { 57003db86aabSstevel int value; 57013db86aabSstevel 57023db86aabSstevel pcic_vadem_enable(pcic); 57033db86aabSstevel value = pcic_getb(pcic, 0, PCIC_CHIP_REVISION); 57043db86aabSstevel pcic_putb(pcic, 0, PCIC_CHIP_REVISION, 0xFF); 57053db86aabSstevel if (pcic_getb(pcic, 0, PCIC_CHIP_REVISION) == 57063db86aabSstevel (value | PCIC_VADEM_D3) || 57073db86aabSstevel (pcic_getb(pcic, 0, PCIC_CHIP_REVISION) & PCIC_REV_MASK) == 57083db86aabSstevel PCIC_VADEM_469) { 57093db86aabSstevel int vadem, new; 57103db86aabSstevel pcic_vadem_enable(pcic); 57113db86aabSstevel vadem = pcic_getb(pcic, 0, PCIC_VG_DMA) & 57123db86aabSstevel ~(PCIC_V_UNLOCK | PCIC_V_VADEMREV); 57133db86aabSstevel new = vadem | (PCIC_V_VADEMREV|PCIC_V_UNLOCK); 57143db86aabSstevel pcic_putb(pcic, 0, PCIC_VG_DMA, new); 57153db86aabSstevel value = pcic_getb(pcic, 0, PCIC_CHIP_REVISION); 57163db86aabSstevel 57173db86aabSstevel /* want to lock but leave mouse or other on */ 57183db86aabSstevel pcic_putb(pcic, 0, PCIC_VG_DMA, vadem); 57193db86aabSstevel switch (value & PCIC_REV_MASK) { 57203db86aabSstevel case PCIC_VADEM_365: 57213db86aabSstevel pcic->pc_chipname = PCIC_VG_365; 57223db86aabSstevel pcic->pc_type = PCIC_VADEM; 57233db86aabSstevel break; 57243db86aabSstevel case PCIC_VADEM_465: 57253db86aabSstevel pcic->pc_chipname = PCIC_VG_465; 57263db86aabSstevel pcic->pc_type = PCIC_VADEM; 57273db86aabSstevel pcic->pc_flags |= PCF_1SOCKET; 57283db86aabSstevel break; 57293db86aabSstevel case PCIC_VADEM_468: 57303db86aabSstevel pcic->pc_chipname = PCIC_VG_468; 57313db86aabSstevel pcic->pc_type = PCIC_VADEM; 57323db86aabSstevel break; 57333db86aabSstevel case PCIC_VADEM_469: 57343db86aabSstevel pcic->pc_chipname = PCIC_VG_469; 57353db86aabSstevel pcic->pc_type = PCIC_VADEM_VG469; 57363db86aabSstevel break; 57373db86aabSstevel } 57383db86aabSstevel return (1); 57393db86aabSstevel } 57403db86aabSstevel return (0); 57413db86aabSstevel } 57423db86aabSstevel 57433db86aabSstevel /* 57443db86aabSstevel * chip identification: Ricoh 57453db86aabSstevel */ 57463db86aabSstevel static int 57473db86aabSstevel pcic_ci_ricoh(pcicdev_t *pcic) 57483db86aabSstevel { 57493db86aabSstevel int value; 57503db86aabSstevel 57513db86aabSstevel value = pcic_getb(pcic, 0, PCIC_RF_CHIP_IDENT); 57523db86aabSstevel switch (value) { 57533db86aabSstevel case PCIC_RF_296: 57543db86aabSstevel pcic->pc_type = PCIC_RICOH; 57553db86aabSstevel pcic->pc_chipname = PCIC_TYPE_RF5C296; 57563db86aabSstevel return (1); 57573db86aabSstevel case PCIC_RF_396: 57583db86aabSstevel pcic->pc_type = PCIC_RICOH; 57593db86aabSstevel pcic->pc_chipname = PCIC_TYPE_RF5C396; 57603db86aabSstevel return (1); 57613db86aabSstevel } 57623db86aabSstevel return (0); 57633db86aabSstevel } 57643db86aabSstevel 57653db86aabSstevel 57663db86aabSstevel /* 57673db86aabSstevel * set up available address spaces in busra 57683db86aabSstevel */ 57693db86aabSstevel static void 57703db86aabSstevel pcic_init_assigned(dev_info_t *dip) 57713db86aabSstevel { 57723db86aabSstevel pcm_regs_t *pcic_avail_p; 57733db86aabSstevel pci_regspec_t *pci_avail_p, *regs; 57743db86aabSstevel int len, entries, rlen; 57753db86aabSstevel dev_info_t *pdip; 57763db86aabSstevel 57773db86aabSstevel if (ddi_getlongprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, 57783db86aabSstevel "available", (caddr_t)&pcic_avail_p, &len) == DDI_PROP_SUCCESS) { 57793db86aabSstevel /* 57803db86aabSstevel * found "available" property at the cardbus/pcmcia node 57813db86aabSstevel * need to translate address space entries from pcmcia 57823db86aabSstevel * format to pci format 57833db86aabSstevel */ 57843db86aabSstevel entries = len / sizeof (pcm_regs_t); 57853db86aabSstevel pci_avail_p = kmem_alloc(sizeof (pci_regspec_t) * entries, 57863db86aabSstevel KM_SLEEP); 57873db86aabSstevel if (pcic_apply_avail_ranges(dip, pcic_avail_p, pci_avail_p, 57883db86aabSstevel entries) == DDI_SUCCESS) 57893db86aabSstevel (void) pci_resource_setup_avail(dip, pci_avail_p, 57903db86aabSstevel entries); 57913db86aabSstevel kmem_free(pcic_avail_p, len); 57923db86aabSstevel kmem_free(pci_avail_p, entries * sizeof (pci_regspec_t)); 57933db86aabSstevel return; 57943db86aabSstevel } 57953db86aabSstevel 57963db86aabSstevel /* 57973db86aabSstevel * "legacy" platforms will have "available" property in pci node 57983db86aabSstevel */ 57993db86aabSstevel for (pdip = ddi_get_parent(dip); pdip; pdip = ddi_get_parent(pdip)) { 58003db86aabSstevel if (ddi_getlongprop(DDI_DEV_T_ANY, pdip, DDI_PROP_DONTPASS, 58013db86aabSstevel "available", (caddr_t)&pci_avail_p, &len) == 58023db86aabSstevel DDI_PROP_SUCCESS) { 58033db86aabSstevel /* (void) pci_resource_setup(pdip); */ 58043db86aabSstevel kmem_free(pci_avail_p, len); 58053db86aabSstevel break; 58063db86aabSstevel } 58073db86aabSstevel } 58083db86aabSstevel 58093db86aabSstevel if (pdip == NULL) { 58103db86aabSstevel int len; 58113db86aabSstevel char bus_type[16] = "(unknown)"; 58123db86aabSstevel dev_info_t *par; 58133db86aabSstevel 58143db86aabSstevel cmn_err(CE_CONT, 58153db86aabSstevel "?pcic_init_assigned: no available property for pcmcia\n"); 58163db86aabSstevel 58173db86aabSstevel /* 58183db86aabSstevel * This code is taken from pci_resource_setup() but does 58193db86aabSstevel * not attempt to use the "available" property to populate 58203db86aabSstevel * the ndi maps that are created. 58213db86aabSstevel * The fact that we will actually 58223db86aabSstevel * free some resource below (that was allocated by OBP) 58233db86aabSstevel * should be enough to be going on with. 58243db86aabSstevel */ 58253db86aabSstevel for (par = dip; par != NULL; par = ddi_get_parent(par)) { 58263db86aabSstevel len = sizeof (bus_type); 58273db86aabSstevel 58283db86aabSstevel if ((ddi_prop_op(DDI_DEV_T_ANY, par, 58293db86aabSstevel PROP_LEN_AND_VAL_BUF, 58303db86aabSstevel DDI_PROP_CANSLEEP | DDI_PROP_DONTPASS, 58313db86aabSstevel "device_type", 58323db86aabSstevel (caddr_t)&bus_type, &len) == DDI_SUCCESS) && 58338134ee03Srw148561 (strcmp(bus_type, DEVI_PCI_NEXNAME) == 0 || 58348134ee03Srw148561 strcmp(bus_type, DEVI_PCIEX_NEXNAME) == 0)) 58353db86aabSstevel break; 58363db86aabSstevel } 58373db86aabSstevel if (par != NULL && 58383db86aabSstevel (ndi_ra_map_setup(par, NDI_RA_TYPE_MEM) != NDI_SUCCESS || 58393db86aabSstevel ndi_ra_map_setup(par, NDI_RA_TYPE_IO) != NDI_SUCCESS)) 58403db86aabSstevel par = NULL; 58413db86aabSstevel } else { 58423db86aabSstevel #ifdef CARDBUS 58433db86aabSstevel cardbus_bus_range_t *bus_range; 58443db86aabSstevel int k; 58453db86aabSstevel 58463db86aabSstevel if (ddi_getlongprop(DDI_DEV_T_ANY, pdip, 0, "bus-range", 58473db86aabSstevel (caddr_t)&bus_range, &k) == DDI_PROP_SUCCESS) { 58483db86aabSstevel if (bus_range->lo != bus_range->hi) 58493db86aabSstevel pcic_err(pdip, 9, "allowable bus range is " 58503db86aabSstevel "%u->%u\n", bus_range->lo, bus_range->hi); 58513db86aabSstevel else { 58523db86aabSstevel pcic_err(pdip, 0, 58533db86aabSstevel "!No spare PCI bus numbers, range is " 58543db86aabSstevel "%u->%u, cardbus isn't usable\n", 58553db86aabSstevel bus_range->lo, bus_range->hi); 58563db86aabSstevel } 58573db86aabSstevel kmem_free(bus_range, k); 58583db86aabSstevel } else 58593db86aabSstevel pcic_err(pdip, 0, "!No bus-range property seems to " 58603db86aabSstevel "have been set up\n"); 58613db86aabSstevel #endif 58623db86aabSstevel /* 58633db86aabSstevel * Have a valid parent with the "available" property 58643db86aabSstevel */ 58653db86aabSstevel (void) pci_resource_setup(pdip); 58663db86aabSstevel } 58673db86aabSstevel 58683db86aabSstevel if ((strcmp(ddi_get_name(dip), "pcma") == 0) && 58693db86aabSstevel ddi_getlongprop(DDI_DEV_T_NONE, dip, DDI_PROP_DONTPASS, 58703db86aabSstevel "assigned-addresses", 58713db86aabSstevel (caddr_t)®s, &rlen) == DDI_SUCCESS) { 58723db86aabSstevel ra_return_t ra; 58733db86aabSstevel 58743db86aabSstevel /* 58753db86aabSstevel * On the UltraBook IIi the ranges are assigned under 58763db86aabSstevel * openboot. If we don't free them here the first I/O 58773db86aabSstevel * space that can be used is up above 0x10000 which 58783db86aabSstevel * doesn't work for this driver due to restrictions 58793db86aabSstevel * on the PCI I/O addresses the controllers can cope with. 58803db86aabSstevel * They are never going to be used by anything else 58813db86aabSstevel * so free them up to the general pool. AG. 58823db86aabSstevel */ 58833db86aabSstevel pcic_err(dip, 1, "Free assigned addresses\n"); 58843db86aabSstevel 58853db86aabSstevel if ((PCI_REG_ADDR_G(regs[0].pci_phys_hi) == 58863db86aabSstevel PCI_REG_ADDR_G(PCI_ADDR_MEM32)) && 58873db86aabSstevel regs[0].pci_size_low == 0x1000000) { 58883db86aabSstevel ra.ra_addr_lo = regs[0].pci_phys_low; 58893db86aabSstevel ra.ra_len = regs[0].pci_size_low; 58903db86aabSstevel (void) pcmcia_free_mem(dip, &ra); 58913db86aabSstevel } 58923db86aabSstevel if ((PCI_REG_ADDR_G(regs[1].pci_phys_hi) == 58933db86aabSstevel PCI_REG_ADDR_G(PCI_ADDR_IO)) && 58943db86aabSstevel (regs[1].pci_size_low == 0x8000 || 58953db86aabSstevel regs[1].pci_size_low == 0x4000)) /* UB-IIi || UB-I */ 58963db86aabSstevel { 58973db86aabSstevel ra.ra_addr_lo = regs[1].pci_phys_low; 58983db86aabSstevel ra.ra_len = regs[1].pci_size_low; 58993db86aabSstevel (void) pcmcia_free_io(dip, &ra); 59003db86aabSstevel } 59013db86aabSstevel kmem_free((caddr_t)regs, rlen); 59023db86aabSstevel } 59033db86aabSstevel } 59043db86aabSstevel 59053db86aabSstevel /* 59063db86aabSstevel * translate "available" from pcmcia format to pci format 59073db86aabSstevel */ 59083db86aabSstevel static int 59093db86aabSstevel pcic_apply_avail_ranges(dev_info_t *dip, pcm_regs_t *pcic_p, 59103db86aabSstevel pci_regspec_t *pci_p, int entries) 59113db86aabSstevel { 59123db86aabSstevel int i, range_len, range_entries; 59133db86aabSstevel pcic_ranges_t *pcic_range_p; 59143db86aabSstevel 59153db86aabSstevel if (ddi_getlongprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, "ranges", 59163db86aabSstevel (caddr_t)&pcic_range_p, &range_len) != DDI_PROP_SUCCESS) { 59173db86aabSstevel cmn_err(CE_CONT, "?pcic_apply_avail_ranges: " 59183db86aabSstevel "no ranges property for pcmcia\n"); 59193db86aabSstevel return (DDI_FAILURE); 59203db86aabSstevel } 59213db86aabSstevel 59223db86aabSstevel range_entries = range_len / sizeof (pcic_ranges_t); 59233db86aabSstevel 59243db86aabSstevel /* for each "available" entry to be translated */ 59253db86aabSstevel for (i = 0; i < entries; i++, pcic_p++, pci_p++) { 59263db86aabSstevel int j; 59273db86aabSstevel pcic_ranges_t *range_p = pcic_range_p; 59283db86aabSstevel pci_p->pci_phys_hi = -1u; /* default invalid value */ 59293db86aabSstevel 59303db86aabSstevel /* for each "ranges" entry to be searched */ 59313db86aabSstevel for (j = 0; j < range_entries; j++, range_p++) { 59323db86aabSstevel uint64_t range_end = range_p->pcic_range_caddrlo + 59333db86aabSstevel range_p->pcic_range_size; 59343db86aabSstevel uint64_t avail_end = pcic_p->phys_lo + pcic_p->phys_len; 59353db86aabSstevel 59363db86aabSstevel if ((range_p->pcic_range_caddrhi != pcic_p->phys_hi) || 59373db86aabSstevel (range_p->pcic_range_caddrlo > pcic_p->phys_lo) || 59383db86aabSstevel (range_end < avail_end)) 59393db86aabSstevel continue; 59403db86aabSstevel 59413db86aabSstevel pci_p->pci_phys_hi = range_p->pcic_range_paddrhi; 59423db86aabSstevel pci_p->pci_phys_mid = range_p->pcic_range_paddrmid; 59433db86aabSstevel pci_p->pci_phys_low = range_p->pcic_range_paddrlo 59443db86aabSstevel + (pcic_p->phys_lo - range_p->pcic_range_caddrlo); 59453db86aabSstevel pci_p->pci_size_hi = 0; 59463db86aabSstevel pci_p->pci_size_low = pcic_p->phys_len; 59473db86aabSstevel } 59483db86aabSstevel } 59493db86aabSstevel kmem_free(pcic_range_p, range_len); 59503db86aabSstevel return (DDI_SUCCESS); 59513db86aabSstevel } 59523db86aabSstevel 59533db86aabSstevel static int 59543db86aabSstevel pcic_open(dev_t *dev, int flag, int otyp, cred_t *cred) 59553db86aabSstevel { 59563db86aabSstevel #ifdef CARDBUS 59573db86aabSstevel if (cardbus_is_cb_minor(*dev)) 59583db86aabSstevel return (cardbus_open(dev, flag, otyp, cred)); 59593db86aabSstevel #endif 59603db86aabSstevel return (EINVAL); 59613db86aabSstevel } 59623db86aabSstevel 59633db86aabSstevel static int 59643db86aabSstevel pcic_close(dev_t dev, int flag, int otyp, cred_t *cred) 59653db86aabSstevel { 59663db86aabSstevel #ifdef CARDBUS 59673db86aabSstevel if (cardbus_is_cb_minor(dev)) 59683db86aabSstevel return (cardbus_close(dev, flag, otyp, cred)); 59693db86aabSstevel #endif 59703db86aabSstevel return (EINVAL); 59713db86aabSstevel } 59723db86aabSstevel 59733db86aabSstevel static int 59743db86aabSstevel pcic_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, cred_t *cred, 59753db86aabSstevel int *rval) 59763db86aabSstevel { 59773db86aabSstevel #ifdef CARDBUS 59783db86aabSstevel if (cardbus_is_cb_minor(dev)) 59793db86aabSstevel return (cardbus_ioctl(dev, cmd, arg, mode, cred, rval)); 59803db86aabSstevel #endif 59813db86aabSstevel return (EINVAL); 59823db86aabSstevel } 59833db86aabSstevel 59843db86aabSstevel 59853db86aabSstevel static boolean_t 59863db86aabSstevel pcic_load_cardbus(pcicdev_t *pcic, const pcic_socket_t *sockp) 59873db86aabSstevel { 59883db86aabSstevel uint32_t present_state; 59893db86aabSstevel dev_info_t *dip = pcic->dip; 59903db86aabSstevel set_socket_t s; 59913db86aabSstevel get_socket_t g; 59923db86aabSstevel boolean_t retval; 59933db86aabSstevel unsigned vccLevel; 59943db86aabSstevel 59953db86aabSstevel pcic_err(dip, 8, "entering pcic_load_cardbus\n"); 59963db86aabSstevel 59973db86aabSstevel pcic_mutex_exit(&pcic->pc_lock); 59983db86aabSstevel 59993db86aabSstevel bzero(&s, sizeof (set_socket_t)); 60003db86aabSstevel s.socket = sockp->pcs_socket; 60013db86aabSstevel s.SCIntMask = SBM_CD|SBM_RDYBSY; 60023db86aabSstevel s.IFType = IF_CARDBUS; 60033db86aabSstevel s.State = (unsigned)~0; 60043db86aabSstevel 60053db86aabSstevel present_state = pcic_getcb(pcic, CB_PRESENT_STATE); 60063db86aabSstevel if (present_state & PCIC_VCC_3VCARD) 60073db86aabSstevel s.VccLevel = PCIC_VCC_3VLEVEL; 60083db86aabSstevel else if (present_state & PCIC_VCC_5VCARD) 60093db86aabSstevel s.VccLevel = PCIC_VCC_5VLEVEL; 60103db86aabSstevel else { 60113db86aabSstevel cmn_err(CE_CONT, 60123db86aabSstevel "pcic_load_cardbus: unsupported card voltage\n"); 60133db86aabSstevel goto failure; 60143db86aabSstevel } 60153db86aabSstevel vccLevel = s.VccLevel; 60163db86aabSstevel s.Vpp1Level = s.Vpp2Level = 0; 60173db86aabSstevel 60183db86aabSstevel if (pcic_set_socket(dip, &s) != SUCCESS) 60193db86aabSstevel goto failure; 60203db86aabSstevel 60213db86aabSstevel if (pcic_reset_socket(dip, sockp->pcs_socket, 60223db86aabSstevel RESET_MODE_CARD_ONLY) != SUCCESS) 60233db86aabSstevel goto failure; 60243db86aabSstevel 60253db86aabSstevel bzero(&g, sizeof (get_socket_t)); 60263db86aabSstevel g.socket = sockp->pcs_socket; 60273db86aabSstevel if (pcic_get_socket(dip, &g) != SUCCESS) 60283db86aabSstevel goto failure; 60293db86aabSstevel 60303db86aabSstevel bzero(&s, sizeof (set_socket_t)); 60313db86aabSstevel s.socket = sockp->pcs_socket; 60323db86aabSstevel s.SCIntMask = SBM_CD; 60333db86aabSstevel s.IREQRouting = g.IRQRouting; 60343db86aabSstevel s.IFType = g.IFType; 60353db86aabSstevel s.CtlInd = g.CtlInd; 60363db86aabSstevel s.State = (unsigned)~0; 60373db86aabSstevel s.VccLevel = vccLevel; 60383db86aabSstevel s.Vpp1Level = s.Vpp2Level = 0; 60393db86aabSstevel 604011c2b4c0Srw148561 retval = pcic_set_socket(dip, &s); 604111c2b4c0Srw148561 pcmcia_cb_resumed(s.socket); 604211c2b4c0Srw148561 if (retval != SUCCESS) 60433db86aabSstevel goto failure; 60443db86aabSstevel 60453db86aabSstevel retval = cardbus_load_cardbus(dip, sockp->pcs_socket, pcic->pc_base); 60463db86aabSstevel goto exit; 60473db86aabSstevel 60483db86aabSstevel failure: 60493db86aabSstevel retval = B_FALSE; 60503db86aabSstevel 60513db86aabSstevel exit: 60523db86aabSstevel pcic_mutex_enter(&pcic->pc_lock); 60533db86aabSstevel pcic_err(dip, 8, "exit pcic_load_cardbus (%s)\n", 60543db86aabSstevel retval ? "success" : "failure"); 60553db86aabSstevel return (retval); 60563db86aabSstevel } 60573db86aabSstevel 60583db86aabSstevel static void 60593db86aabSstevel pcic_unload_cardbus(pcicdev_t *pcic, const pcic_socket_t *sockp) 60603db86aabSstevel { 60613db86aabSstevel dev_info_t *dip = pcic->dip; 60623db86aabSstevel set_socket_t s; 60633db86aabSstevel 60643db86aabSstevel pcic_mutex_exit(&pcic->pc_lock); 60653db86aabSstevel 60663db86aabSstevel cardbus_unload_cardbus(dip); 60673db86aabSstevel 60683db86aabSstevel bzero(&s, sizeof (set_socket_t)); 60693db86aabSstevel s.socket = sockp->pcs_socket; 60703db86aabSstevel s.SCIntMask = SBM_CD|SBM_RDYBSY; 60713db86aabSstevel s.IREQRouting = 0; 60723db86aabSstevel s.IFType = IF_MEMORY; 60733db86aabSstevel s.CtlInd = 0; 60743db86aabSstevel s.State = 0; 60753db86aabSstevel s.VccLevel = s.Vpp1Level = s.Vpp2Level = 0; 60763db86aabSstevel 60773db86aabSstevel (void) pcic_set_socket(dip, &s); 60783db86aabSstevel 60793db86aabSstevel pcic_mutex_enter(&pcic->pc_lock); 60803db86aabSstevel } 60813db86aabSstevel 60823db86aabSstevel static uint32_t 60833db86aabSstevel pcic_getcb(pcicdev_t *pcic, int reg) 60843db86aabSstevel { 60853db86aabSstevel ASSERT(pcic->pc_io_type == PCIC_IO_TYPE_YENTA); 60863db86aabSstevel 60873db86aabSstevel return (ddi_get32(pcic->handle, 60883db86aabSstevel (uint32_t *)(pcic->ioaddr + CB_CB_OFFSET + reg))); 60893db86aabSstevel } 60903db86aabSstevel 60913db86aabSstevel static void 60923db86aabSstevel pcic_putcb(pcicdev_t *pcic, int reg, uint32_t value) 60933db86aabSstevel { 60943db86aabSstevel ASSERT(pcic->pc_io_type == PCIC_IO_TYPE_YENTA); 60953db86aabSstevel 60963db86aabSstevel ddi_put32(pcic->handle, 60973db86aabSstevel (uint32_t *)(pcic->ioaddr + CB_CB_OFFSET + reg), value); 60983db86aabSstevel } 60993db86aabSstevel 61003db86aabSstevel static void 61013db86aabSstevel pcic_enable_io_intr(pcicdev_t *pcic, int socket, int irq) 61023db86aabSstevel { 61033db86aabSstevel uint8_t value; 61043db86aabSstevel uint16_t brdgctl; 61053db86aabSstevel 61063db86aabSstevel value = pcic_getb(pcic, socket, PCIC_INTERRUPT) & ~PCIC_INTR_MASK; 61073db86aabSstevel pcic_putb(pcic, socket, PCIC_INTERRUPT, value | irq); 61083db86aabSstevel 61093db86aabSstevel switch (pcic->pc_type) { 61103db86aabSstevel case PCIC_INTEL_i82092: 61113db86aabSstevel pcic_82092_smiirq_ctl(pcic, socket, PCIC_82092_CTL_IRQ, 61123db86aabSstevel PCIC_82092_INT_ENABLE); 61133db86aabSstevel break; 61143db86aabSstevel case PCIC_O2_OZ6912: 61153db86aabSstevel value = pcic_getb(pcic, 0, PCIC_CENTDMA); 61163db86aabSstevel value |= 0x8; 61173db86aabSstevel pcic_putb(pcic, 0, PCIC_CENTDMA, value); 61183db86aabSstevel break; 61193db86aabSstevel case PCIC_CL_PD6832: 61203db86aabSstevel case PCIC_TI_PCI1250: 61213db86aabSstevel case PCIC_TI_PCI1221: 61223db86aabSstevel case PCIC_TI_PCI1225: 61233db86aabSstevel case PCIC_TI_PCI1410: 61243db86aabSstevel case PCIC_ENE_1410: 61253db86aabSstevel case PCIC_TI_PCI1510: 61263db86aabSstevel case PCIC_TI_PCI1520: 61273db86aabSstevel case PCIC_TI_PCI1420: 61283db86aabSstevel case PCIC_ENE_1420: 61293db86aabSstevel /* route card functional interrupts to PCI interrupts */ 61303db86aabSstevel brdgctl = ddi_get16(pcic->cfg_handle, 61313db86aabSstevel (uint16_t *)(pcic->cfgaddr + PCI_CBUS_BRIDGE_CTRL)); 61323db86aabSstevel pcic_err(NULL, 1, 61333db86aabSstevel "pcic_enable_io_intr brdgctl(0x%x) was: 0x%x\n", 61343db86aabSstevel PCI_CBUS_BRIDGE_CTRL, brdgctl); 61353db86aabSstevel brdgctl &= ~PCIC_BRDGCTL_INTR_MASK; 61363db86aabSstevel ddi_put16(pcic->cfg_handle, 61373db86aabSstevel (uint16_t *)(pcic->cfgaddr + PCI_CBUS_BRIDGE_CTRL), 61383db86aabSstevel brdgctl); 61393db86aabSstevel /* Flush the write */ 61403db86aabSstevel (void) ddi_get16(pcic->cfg_handle, 61413db86aabSstevel (uint16_t *)(pcic->cfgaddr + PCI_CBUS_BRIDGE_CTRL)); 61423db86aabSstevel break; 61433db86aabSstevel default: 61443db86aabSstevel break; 61453db86aabSstevel } 61463db86aabSstevel } 61473db86aabSstevel 61483db86aabSstevel static void 61493db86aabSstevel pcic_disable_io_intr(pcicdev_t *pcic, int socket) 61503db86aabSstevel { 61513db86aabSstevel uint8_t value; 61523db86aabSstevel uint16_t brdgctl; 61533db86aabSstevel 61543db86aabSstevel value = pcic_getb(pcic, socket, PCIC_INTERRUPT) & ~PCIC_INTR_MASK; 61553db86aabSstevel pcic_putb(pcic, socket, PCIC_INTERRUPT, value); 61563db86aabSstevel 61573db86aabSstevel switch (pcic->pc_type) { 61583db86aabSstevel case PCIC_INTEL_i82092: 61593db86aabSstevel pcic_82092_smiirq_ctl(pcic, socket, PCIC_82092_CTL_IRQ, 61603db86aabSstevel PCIC_82092_INT_DISABLE); 61613db86aabSstevel break; 61623db86aabSstevel case PCIC_O2_OZ6912: 61633db86aabSstevel value = pcic_getb(pcic, 0, PCIC_CENTDMA); 61643db86aabSstevel value &= ~0x8; 61653db86aabSstevel pcic_putb(pcic, 0, PCIC_CENTDMA, value); 61663db86aabSstevel /* Flush the write */ 61673db86aabSstevel (void) pcic_getb(pcic, 0, PCIC_CENTDMA); 61683db86aabSstevel break; 61693db86aabSstevel case PCIC_CL_PD6832: 61703db86aabSstevel case PCIC_TI_PCI1250: 61713db86aabSstevel case PCIC_TI_PCI1221: 61723db86aabSstevel case PCIC_TI_PCI1225: 61733db86aabSstevel case PCIC_TI_PCI1410: 61743db86aabSstevel case PCIC_ENE_1410: 61753db86aabSstevel case PCIC_TI_PCI1510: 61763db86aabSstevel case PCIC_TI_PCI1520: 61773db86aabSstevel case PCIC_TI_PCI1420: 61783db86aabSstevel case PCIC_ENE_1420: 61793db86aabSstevel /* 61803db86aabSstevel * This maps I/O interrupts to ExCA which 61813db86aabSstevel * have been turned off by the write to 61823db86aabSstevel * PCIC_INTERRUPT above. It would appear to 61833db86aabSstevel * be the only way to actually turn I/O Ints off 61843db86aabSstevel * while retaining CS Ints. 61853db86aabSstevel */ 61863db86aabSstevel brdgctl = ddi_get16(pcic->cfg_handle, 61873db86aabSstevel (uint16_t *)(pcic->cfgaddr + PCI_CBUS_BRIDGE_CTRL)); 61883db86aabSstevel pcic_err(NULL, 1, 61893db86aabSstevel "pcic_disable_io_intr brdgctl(0x%x) was: 0x%x\n", 61903db86aabSstevel PCI_CBUS_BRIDGE_CTRL, brdgctl); 61913db86aabSstevel brdgctl |= PCIC_BRDGCTL_INTR_MASK; 61923db86aabSstevel ddi_put16(pcic->cfg_handle, 61933db86aabSstevel (uint16_t *)(pcic->cfgaddr + PCI_CBUS_BRIDGE_CTRL), 61943db86aabSstevel brdgctl); 61953db86aabSstevel /* Flush the write */ 61963db86aabSstevel (void) ddi_get16(pcic->cfg_handle, 61973db86aabSstevel (uint16_t *)(pcic->cfgaddr + PCI_CBUS_BRIDGE_CTRL)); 61983db86aabSstevel break; 61993db86aabSstevel default: 62003db86aabSstevel break; 62013db86aabSstevel } 62023db86aabSstevel } 62033db86aabSstevel 62043db86aabSstevel static void 62053db86aabSstevel pcic_cb_enable_intr(dev_info_t *dip) 62063db86aabSstevel { 62073db86aabSstevel anp_t *anp = ddi_get_driver_private(dip); 62083db86aabSstevel pcicdev_t *pcic = anp->an_private; 62093db86aabSstevel 62103db86aabSstevel mutex_enter(&pcic->pc_lock); 62113db86aabSstevel pcic_enable_io_intr(pcic, 0, pcic->pc_sockets[0].pcs_irq); 62123db86aabSstevel mutex_exit(&pcic->pc_lock); 62133db86aabSstevel } 62143db86aabSstevel 62153db86aabSstevel static void 62163db86aabSstevel pcic_cb_disable_intr(dev_info_t *dip) 62173db86aabSstevel { 62183db86aabSstevel anp_t *anp = ddi_get_driver_private(dip); 62193db86aabSstevel pcicdev_t *pcic = anp->an_private; 62203db86aabSstevel 62213db86aabSstevel mutex_enter(&pcic->pc_lock); 62223db86aabSstevel pcic_disable_io_intr(pcic, 0); 62233db86aabSstevel mutex_exit(&pcic->pc_lock); 62243db86aabSstevel } 62253db86aabSstevel 62263db86aabSstevel static int 62273db86aabSstevel log_pci_cfg_err(ushort_t e, int bridge_secondary) 62283db86aabSstevel { 62293db86aabSstevel int nerr = 0; 62303db86aabSstevel if (e & PCI_STAT_PERROR) { 62313db86aabSstevel nerr++; 62323db86aabSstevel cmn_err(CE_CONT, "detected parity error.\n"); 62333db86aabSstevel } 62343db86aabSstevel if (e & PCI_STAT_S_SYSERR) { 62353db86aabSstevel nerr++; 62363db86aabSstevel if (bridge_secondary) 62373db86aabSstevel cmn_err(CE_CONT, "received system error.\n"); 62383db86aabSstevel else 62393db86aabSstevel cmn_err(CE_CONT, "signalled system error.\n"); 62403db86aabSstevel } 62413db86aabSstevel if (e & PCI_STAT_R_MAST_AB) { 62423db86aabSstevel nerr++; 62433db86aabSstevel cmn_err(CE_CONT, "received master abort.\n"); 62443db86aabSstevel } 62453db86aabSstevel if (e & PCI_STAT_R_TARG_AB) 62463db86aabSstevel cmn_err(CE_CONT, "received target abort.\n"); 62473db86aabSstevel if (e & PCI_STAT_S_TARG_AB) 62483db86aabSstevel cmn_err(CE_CONT, "signalled target abort\n"); 62493db86aabSstevel if (e & PCI_STAT_S_PERROR) { 62503db86aabSstevel nerr++; 62513db86aabSstevel cmn_err(CE_CONT, "signalled parity error\n"); 62523db86aabSstevel } 62533db86aabSstevel return (nerr); 62543db86aabSstevel } 62553db86aabSstevel 62563db86aabSstevel #if defined(__sparc) 62573db86aabSstevel static int 62583db86aabSstevel pcic_fault(enum pci_fault_ops op, void *arg) 62593db86aabSstevel { 62603db86aabSstevel pcicdev_t *pcic = (pcicdev_t *)arg; 62613db86aabSstevel ushort_t pci_cfg_stat = 62623db86aabSstevel pci_config_get16(pcic->cfg_handle, PCI_CONF_STAT); 62633db86aabSstevel ushort_t pci_cfg_sec_stat = 62643db86aabSstevel pci_config_get16(pcic->cfg_handle, 0x16); 62653db86aabSstevel char nm[24]; 62663db86aabSstevel int nerr = 0; 62673db86aabSstevel 62683db86aabSstevel cardbus_dump_pci_config(pcic->dip); 62693db86aabSstevel 62703db86aabSstevel switch (op) { 62713db86aabSstevel case FAULT_LOG: 62723db86aabSstevel (void) sprintf(nm, "%s-%d", ddi_driver_name(pcic->dip), 62733db86aabSstevel ddi_get_instance(pcic->dip)); 62743db86aabSstevel 62753db86aabSstevel cmn_err(CE_WARN, "%s: PCIC fault log start:\n", nm); 62763db86aabSstevel cmn_err(CE_WARN, "%s: primary err (%x):\n", nm, pci_cfg_stat); 62773db86aabSstevel nerr += log_pci_cfg_err(pci_cfg_stat, 0); 62783db86aabSstevel cmn_err(CE_WARN, "%s: sec err (%x):\n", nm, pci_cfg_sec_stat); 62793db86aabSstevel nerr += log_pci_cfg_err(pci_cfg_sec_stat, 1); 62803db86aabSstevel cmn_err(CE_CONT, "%s: PCI fault log end.\n", nm); 62813db86aabSstevel return (nerr); 62823db86aabSstevel case FAULT_POKEFINI: 62833db86aabSstevel case FAULT_RESET: 62843db86aabSstevel pci_config_put16(pcic->cfg_handle, 62853db86aabSstevel PCI_CONF_STAT, pci_cfg_stat); 62863db86aabSstevel pci_config_put16(pcic->cfg_handle, 0x16, pci_cfg_sec_stat); 62873db86aabSstevel break; 62883db86aabSstevel case FAULT_POKEFLT: 62893db86aabSstevel if (!(pci_cfg_stat & PCI_STAT_S_SYSERR)) 62903db86aabSstevel return (1); 62913db86aabSstevel if (!(pci_cfg_sec_stat & PCI_STAT_R_MAST_AB)) 62923db86aabSstevel return (1); 62933db86aabSstevel break; 62943db86aabSstevel default: 62953db86aabSstevel break; 62963db86aabSstevel } 62973db86aabSstevel return (DDI_SUCCESS); 62983db86aabSstevel } 62993db86aabSstevel #endif 63003db86aabSstevel 63013db86aabSstevel static void 630211c2b4c0Srw148561 pcic_do_resume(pcicdev_t *pcic) 63033db86aabSstevel { 630411c2b4c0Srw148561 int i, interrupt; 630511c2b4c0Srw148561 uint8_t cfg; 63063db86aabSstevel 63073db86aabSstevel 63083db86aabSstevel #if defined(PCIC_DEBUG) 630911c2b4c0Srw148561 pcic_err(NULL, 6, "pcic_do_resume(): entered\n"); 63103db86aabSstevel #endif 63113db86aabSstevel 63123db86aabSstevel pcic_mutex_enter(&pcic->pc_lock); /* protect the registers */ 63133db86aabSstevel for (i = 0; i < pcic->pc_numsockets; i++) { 63143db86aabSstevel /* Enable interrupts on PCI if needs be */ 63153db86aabSstevel interrupt = pcic_getb(pcic, i, PCIC_INTERRUPT); 63163db86aabSstevel if (pcic->pc_flags & PCF_USE_SMI) 63173db86aabSstevel interrupt |= PCIC_INTR_ENABLE; 63183db86aabSstevel pcic_putb(pcic, i, PCIC_INTERRUPT, 63193db86aabSstevel PCIC_RESET | interrupt); 63203db86aabSstevel pcic->pc_sockets[i].pcs_debounce_id = 63213db86aabSstevel pcic_add_debqueue(&pcic->pc_sockets[i], 63223db86aabSstevel drv_usectohz(pcic_debounce_time)); 63233db86aabSstevel } 63243db86aabSstevel pcic_mutex_exit(&pcic->pc_lock); /* protect the registers */ 63253db86aabSstevel if (pcic_do_pcmcia_sr) 63263db86aabSstevel (void) pcmcia_wait_insert(pcic->dip); 632711c2b4c0Srw148561 /* 632811c2b4c0Srw148561 * The CardBus controller may be in RESET state after the 632911c2b4c0Srw148561 * system is resumed from sleeping. The RESET bit is in 633011c2b4c0Srw148561 * the Bridge Control register. This is true for all(TI, 633111c2b4c0Srw148561 * Toshiba ToPIC95/97, RICOH, and O2Micro) CardBus 633211c2b4c0Srw148561 * controllers. Need to clear the RESET bit explicitly. 633311c2b4c0Srw148561 */ 633411c2b4c0Srw148561 cfg = ddi_get8(pcic->cfg_handle, 633511c2b4c0Srw148561 pcic->cfgaddr + PCIC_BRIDGE_CTL_REG); 633611c2b4c0Srw148561 if (cfg & (1<<6)) { 633711c2b4c0Srw148561 cfg &= ~(1<<6); 633811c2b4c0Srw148561 ddi_put8(pcic->cfg_handle, 633911c2b4c0Srw148561 pcic->cfgaddr + PCIC_BRIDGE_CTL_REG, 634011c2b4c0Srw148561 cfg); 634111c2b4c0Srw148561 cfg = ddi_get8(pcic->cfg_handle, 634211c2b4c0Srw148561 pcic->cfgaddr + PCIC_BRIDGE_CTL_REG); 634311c2b4c0Srw148561 if (cfg & (1<<6)) { 634411c2b4c0Srw148561 pcic_err(pcic->dip, 1, "Failed to take pcic out of reset"); 63453db86aabSstevel } 63463db86aabSstevel } 63473db86aabSstevel 634811c2b4c0Srw148561 } 634911c2b4c0Srw148561 63503db86aabSstevel static void 63513db86aabSstevel pcic_debounce(pcic_socket_t *pcs) 63523db86aabSstevel { 63533db86aabSstevel uint8_t status, stschng; 63543db86aabSstevel 63553db86aabSstevel pcic_mutex_enter(&pcs->pcs_pcic->pc_lock); 63563db86aabSstevel pcs->pcs_flags &= ~PCS_STARTING; 63573db86aabSstevel stschng = pcic_getb(pcs->pcs_pcic, pcs->pcs_socket, 63583db86aabSstevel PCIC_CARD_STATUS_CHANGE); 63593db86aabSstevel status = pcic_getb(pcs->pcs_pcic, pcs->pcs_socket, 63603db86aabSstevel PCIC_INTERFACE_STATUS); 63613db86aabSstevel #ifdef PCIC_DEBUG 63623db86aabSstevel pcic_err(pcs->pcs_pcic->dip, 8, 63633db86aabSstevel "pcic_debounce(0x%p, dip=0x%p) socket %d st 0x%x " 63643db86aabSstevel "chg 0x%x flg 0x%x\n", 63653db86aabSstevel (void *)pcs, (void *) pcs->pcs_pcic->dip, pcs->pcs_socket, 63663db86aabSstevel status, stschng, pcs->pcs_flags); 63673db86aabSstevel #endif 63683db86aabSstevel 63693db86aabSstevel pcic_putb(pcs->pcs_pcic, pcs->pcs_socket, PCIC_CARD_STATUS_CHANGE, 63703db86aabSstevel PCIC_CD_DETECT); 63713db86aabSstevel pcic_handle_cd_change(pcs->pcs_pcic, pcs, status); 63723db86aabSstevel pcic_mutex_exit(&pcs->pcs_pcic->pc_lock); 63733db86aabSstevel } 63743db86aabSstevel 63753db86aabSstevel static void 63763db86aabSstevel pcic_deb_thread() 63773db86aabSstevel { 63783db86aabSstevel callb_cpr_t cprinfo; 63793db86aabSstevel struct debounce *debp; 63803db86aabSstevel clock_t lastt; 63813db86aabSstevel 63823db86aabSstevel CALLB_CPR_INIT(&cprinfo, &pcic_deb_mtx, 63833db86aabSstevel callb_generic_cpr, "pcic debounce thread"); 63843db86aabSstevel mutex_enter(&pcic_deb_mtx); 63853db86aabSstevel while (pcic_deb_threadid) { 63863db86aabSstevel while (pcic_deb_queue) { 63873db86aabSstevel #ifdef PCIC_DEBUG 63883db86aabSstevel pcic_dump_debqueue("Thread"); 63893db86aabSstevel #endif 63903db86aabSstevel debp = pcic_deb_queue; 63913db86aabSstevel (void) drv_getparm(LBOLT, &lastt); 63923db86aabSstevel if (lastt >= debp->expire) { 63933db86aabSstevel pcic_deb_queue = debp->next; 63943db86aabSstevel mutex_exit(&pcic_deb_mtx); 63953db86aabSstevel pcic_debounce(debp->pcs); 63963db86aabSstevel mutex_enter(&pcic_deb_mtx); 63973db86aabSstevel kmem_free(debp, sizeof (*debp)); 63983db86aabSstevel } else { 63993db86aabSstevel (void) cv_timedwait(&pcic_deb_cv, 64003db86aabSstevel &pcic_deb_mtx, debp->expire); 64013db86aabSstevel } 64023db86aabSstevel } 64033db86aabSstevel CALLB_CPR_SAFE_BEGIN(&cprinfo); 64043db86aabSstevel cv_wait(&pcic_deb_cv, &pcic_deb_mtx); 64053db86aabSstevel CALLB_CPR_SAFE_END(&cprinfo, &pcic_deb_mtx); 64063db86aabSstevel } 64073db86aabSstevel pcic_deb_threadid = (kthread_t *)1; 64083db86aabSstevel cv_signal(&pcic_deb_cv); 64093db86aabSstevel CALLB_CPR_EXIT(&cprinfo); /* Also exits the mutex */ 64103db86aabSstevel thread_exit(); 64113db86aabSstevel } 64123db86aabSstevel 64133db86aabSstevel static void * 64143db86aabSstevel pcic_add_debqueue(pcic_socket_t *pcs, int clocks) 64153db86aabSstevel { 64163db86aabSstevel clock_t lbolt; 64173db86aabSstevel struct debounce *dbp, **dbpp = &pcic_deb_queue; 64183db86aabSstevel 64193db86aabSstevel (void) drv_getparm(LBOLT, &lbolt); 64208134ee03Srw148561 dbp = kmem_alloc(sizeof (struct debounce), KM_SLEEP); 64213db86aabSstevel 64223db86aabSstevel dbp->expire = lbolt + clocks; 64233db86aabSstevel dbp->pcs = pcs; 64243db86aabSstevel mutex_enter(&pcic_deb_mtx); 64253db86aabSstevel while (*dbpp) { 64263db86aabSstevel if (dbp->expire > (*dbpp)->expire) 64273db86aabSstevel dbpp = &((*dbpp)->next); 64283db86aabSstevel else 64293db86aabSstevel break; 64303db86aabSstevel } 64313db86aabSstevel dbp->next = *dbpp; 64323db86aabSstevel *dbpp = dbp; 64333db86aabSstevel #ifdef PCIC_DEBUG 64343db86aabSstevel pcic_dump_debqueue("Add"); 64353db86aabSstevel #endif 64363db86aabSstevel cv_signal(&pcic_deb_cv); 64373db86aabSstevel mutex_exit(&pcic_deb_mtx); 64383db86aabSstevel return (dbp); 64393db86aabSstevel } 64403db86aabSstevel 64413db86aabSstevel static void 64423db86aabSstevel pcic_rm_debqueue(void *id) 64433db86aabSstevel { 64443db86aabSstevel struct debounce *dbp, **dbpp = &pcic_deb_queue; 64453db86aabSstevel 64463db86aabSstevel dbp = (struct debounce *)id; 64473db86aabSstevel mutex_enter(&pcic_deb_mtx); 64483db86aabSstevel while (*dbpp) { 64493db86aabSstevel if (*dbpp == dbp) { 64503db86aabSstevel *dbpp = dbp->next; 64513db86aabSstevel kmem_free(dbp, sizeof (*dbp)); 64523db86aabSstevel #ifdef PCIC_DEBUG 64533db86aabSstevel pcic_dump_debqueue("Remove"); 64543db86aabSstevel #endif 64553db86aabSstevel cv_signal(&pcic_deb_cv); 64563db86aabSstevel mutex_exit(&pcic_deb_mtx); 64573db86aabSstevel return; 64583db86aabSstevel } 64593db86aabSstevel dbpp = &((*dbpp)->next); 64603db86aabSstevel } 64613db86aabSstevel pcic_err(NULL, 6, "pcic: Failed to find debounce id 0x%p\n", id); 64623db86aabSstevel mutex_exit(&pcic_deb_mtx); 64633db86aabSstevel } 64643db86aabSstevel 64653db86aabSstevel 64663db86aabSstevel static int pcic_powerdelay = 0; 64673db86aabSstevel 64683db86aabSstevel static int 64693db86aabSstevel pcic_exca_powerctl(pcicdev_t *pcic, int socket, int powerlevel) 64703db86aabSstevel { 64713db86aabSstevel int ind, value, orig_pwrctl; 64723db86aabSstevel 64733db86aabSstevel /* power setup -- if necessary */ 64743db86aabSstevel orig_pwrctl = pcic_getb(pcic, socket, PCIC_POWER_CONTROL); 64753db86aabSstevel 64763db86aabSstevel #if defined(PCIC_DEBUG) 64773db86aabSstevel pcic_err(pcic->dip, 6, 64783db86aabSstevel "pcic_exca_powerctl(socket %d) powerlevel=%x orig 0x%x\n", 64793db86aabSstevel socket, powerlevel, orig_pwrctl); 64803db86aabSstevel #endif 64813db86aabSstevel /* Preserve the PCIC_OUTPUT_ENABLE (control lines output enable) bit. */ 64823db86aabSstevel powerlevel = (powerlevel & ~POWER_OUTPUT_ENABLE) | 64833db86aabSstevel (orig_pwrctl & POWER_OUTPUT_ENABLE); 64843db86aabSstevel if (powerlevel != orig_pwrctl) { 64853db86aabSstevel if (powerlevel & ~POWER_OUTPUT_ENABLE) { 64863db86aabSstevel int ifs; 64873db86aabSstevel /* 64883db86aabSstevel * set power to socket 64893db86aabSstevel * note that the powerlevel was calculated earlier 64903db86aabSstevel */ 64913db86aabSstevel pcic_putb(pcic, socket, PCIC_POWER_CONTROL, powerlevel); 64923db86aabSstevel (void) pcic_getb(pcic, socket, PCIC_POWER_CONTROL); 64933db86aabSstevel 64943db86aabSstevel /* 64953db86aabSstevel * this second write to the power control register 64963db86aabSstevel * is needed to resolve a problem on 64973db86aabSstevel * the IBM ThinkPad 750 64983db86aabSstevel * where the first write doesn't latch. 64993db86aabSstevel * The second write appears to always work and 65003db86aabSstevel * doesn't hurt the operation of other chips 65013db86aabSstevel * so we can just use it -- this is good since we can't 65023db86aabSstevel * determine what chip the 750 actually uses 65033db86aabSstevel * (I suspect an early Ricoh). 65043db86aabSstevel */ 65053db86aabSstevel pcic_putb(pcic, socket, PCIC_POWER_CONTROL, powerlevel); 65063db86aabSstevel 65073db86aabSstevel value = pcic_getb(pcic, socket, PCIC_POWER_CONTROL); 65083db86aabSstevel pcic_mswait(pcic, socket, pcic_powerdelay); 65093db86aabSstevel #if defined(PCIC_DEBUG) 65103db86aabSstevel pcic_err(pcic->dip, 8, 65113db86aabSstevel "\tpowerlevel reg = %x (ifs %x)\n", 65123db86aabSstevel value, pcic_getb(pcic, socket, 65133db86aabSstevel PCIC_INTERFACE_STATUS)); 65143db86aabSstevel pcic_err(pcic->dip, 8, 65153db86aabSstevel "CBus regs: PS 0x%x, Control 0x%x\n", 65163db86aabSstevel pcic_getcb(pcic, CB_PRESENT_STATE), 65173db86aabSstevel pcic_getcb(pcic, CB_CONTROL)); 65183db86aabSstevel #endif 65193db86aabSstevel /* 65203db86aabSstevel * since power was touched, make sure it says it 65213db86aabSstevel * is on. This lets it become stable. 65223db86aabSstevel */ 65233db86aabSstevel for (ind = 0; ind < 20; ind++) { 65243db86aabSstevel ifs = pcic_getb(pcic, socket, 65253db86aabSstevel PCIC_INTERFACE_STATUS); 65263db86aabSstevel if (ifs & PCIC_POWER_ON) 65273db86aabSstevel break; 65283db86aabSstevel else { 65293db86aabSstevel pcic_putb(pcic, socket, 65303db86aabSstevel PCIC_POWER_CONTROL, 0); 65313db86aabSstevel (void) pcic_getb(pcic, socket, 65323db86aabSstevel PCIC_POWER_CONTROL); 65333db86aabSstevel pcic_mswait(pcic, socket, 40); 65343db86aabSstevel if (ind == 10) { 65353db86aabSstevel pcic_putcb(pcic, CB_EVENT_FORCE, 65363db86aabSstevel CB_EF_CVTEST); 65373db86aabSstevel pcic_mswait(pcic, socket, 100); 65383db86aabSstevel } 65393db86aabSstevel pcic_putb(pcic, socket, 65403db86aabSstevel PCIC_POWER_CONTROL, 65413db86aabSstevel powerlevel & ~POWER_OUTPUT_ENABLE); 65423db86aabSstevel (void) pcic_getb(pcic, socket, 65433db86aabSstevel PCIC_POWER_CONTROL); 65443db86aabSstevel pcic_mswait(pcic, socket, 65453db86aabSstevel pcic_powerdelay); 65463db86aabSstevel pcic_putb(pcic, socket, 65473db86aabSstevel PCIC_POWER_CONTROL, powerlevel); 65483db86aabSstevel (void) pcic_getb(pcic, socket, 65493db86aabSstevel PCIC_POWER_CONTROL); 65503db86aabSstevel pcic_mswait(pcic, socket, 65513db86aabSstevel pcic_powerdelay); 65523db86aabSstevel } 65533db86aabSstevel } 65543db86aabSstevel 65553db86aabSstevel if (!(ifs & PCIC_POWER_ON)) { 65563db86aabSstevel cmn_err(CE_WARN, 65573db86aabSstevel "pcic socket %d: Power didn't get turned" 65583db86aabSstevel "on!\nif status 0x%x pwrc 0x%x(x%x) " 65593db86aabSstevel "misc1 0x%x igc 0x%x ind %d\n", 65603db86aabSstevel socket, ifs, 65613db86aabSstevel pcic_getb(pcic, socket, PCIC_POWER_CONTROL), 65623db86aabSstevel orig_pwrctl, 65633db86aabSstevel pcic_getb(pcic, socket, PCIC_MISC_CTL_1), 65643db86aabSstevel pcic_getb(pcic, socket, PCIC_INTERRUPT), 65653db86aabSstevel ind); 65663db86aabSstevel return (BAD_VCC); 65673db86aabSstevel } 65683db86aabSstevel #if defined(PCIC_DEBUG) 65693db86aabSstevel pcic_err(pcic->dip, 8, 65703db86aabSstevel "\tind = %d, if status %x pwrc 0x%x " 65713db86aabSstevel "misc1 0x%x igc 0x%x\n", 65723db86aabSstevel ind, ifs, 65733db86aabSstevel pcic_getb(pcic, socket, PCIC_POWER_CONTROL), 65743db86aabSstevel pcic_getb(pcic, socket, PCIC_MISC_CTL_1), 65753db86aabSstevel pcic_getb(pcic, socket, PCIC_INTERRUPT)); 65763db86aabSstevel #endif 65773db86aabSstevel } else { 65783db86aabSstevel /* explicitly turned off the power */ 65793db86aabSstevel pcic_putb(pcic, socket, PCIC_POWER_CONTROL, powerlevel); 65803db86aabSstevel (void) pcic_getb(pcic, socket, PCIC_POWER_CONTROL); 65813db86aabSstevel } 65823db86aabSstevel } 65833db86aabSstevel return (SUCCESS); 65843db86aabSstevel } 65853db86aabSstevel 65863db86aabSstevel static int pcic_cbdoreset_during_poweron = 1; 65873db86aabSstevel static int 65883db86aabSstevel pcic_cbus_powerctl(pcicdev_t *pcic, int socket) 65893db86aabSstevel { 65903db86aabSstevel uint32_t cbctl = 0, orig_cbctl, cbstev, cbps; 65913db86aabSstevel int ind, iobits; 65923db86aabSstevel pcic_socket_t *sockp = &pcic->pc_sockets[socket]; 65933db86aabSstevel 65943db86aabSstevel pcic_putcb(pcic, CB_STATUS_EVENT, CB_SE_POWER_CYCLE); 65953db86aabSstevel 65963db86aabSstevel ind = pcic_power[sockp->pcs_vpp1].PowerLevel/10; 65973db86aabSstevel cbctl |= pcic_cbv_levels[ind]; 65983db86aabSstevel 65993db86aabSstevel ind = pcic_power[sockp->pcs_vcc].PowerLevel/10; 66003db86aabSstevel cbctl |= (pcic_cbv_levels[ind]<<4); 66013db86aabSstevel 66023db86aabSstevel orig_cbctl = pcic_getcb(pcic, CB_CONTROL); 66033db86aabSstevel 66043db86aabSstevel #if defined(PCIC_DEBUG) 66053db86aabSstevel pcic_err(pcic->dip, 6, 66063db86aabSstevel "pcic_cbus_powerctl(socket %d) vcc %d vpp1 %d " 66073db86aabSstevel "cbctl 0x%x->0x%x\n", 66083db86aabSstevel socket, sockp->pcs_vcc, sockp->pcs_vpp1, orig_cbctl, cbctl); 66093db86aabSstevel #endif 66103db86aabSstevel if (cbctl != orig_cbctl) { 66113db86aabSstevel if (pcic_cbdoreset_during_poweron && 66123db86aabSstevel (orig_cbctl & (CB_C_VCCMASK|CB_C_VPPMASK)) == 0) { 66133db86aabSstevel iobits = pcic_getb(pcic, socket, PCIC_INTERRUPT); 66143db86aabSstevel pcic_putb(pcic, socket, PCIC_INTERRUPT, iobits & ~PCIC_RESET); 66153db86aabSstevel } 66163db86aabSstevel pcic_putcb(pcic, CB_CONTROL, cbctl); 66173db86aabSstevel 66183db86aabSstevel if ((cbctl & CB_C_VCCMASK) == (orig_cbctl & CB_C_VCCMASK)) { 66193db86aabSstevel pcic_mswait(pcic, socket, pcic_powerdelay); 66203db86aabSstevel return (SUCCESS); 66213db86aabSstevel } 66223db86aabSstevel for (ind = 0; ind < 20; ind++) { 66233db86aabSstevel cbstev = pcic_getcb(pcic, CB_STATUS_EVENT); 66243db86aabSstevel 66253db86aabSstevel if (cbstev & CB_SE_POWER_CYCLE) { 66263db86aabSstevel 66273db86aabSstevel /* 66283db86aabSstevel * delay 400 ms: though the standard defines that the Vcc 66293db86aabSstevel * set-up time is 20 ms, some PC-Card bridge requires longer 66303db86aabSstevel * duration. 66313db86aabSstevel * Note: We should check the status AFTER the delay to give time 66323db86aabSstevel * for things to stabilize. 66333db86aabSstevel */ 66343db86aabSstevel pcic_mswait(pcic, socket, 400); 66353db86aabSstevel 66363db86aabSstevel cbps = pcic_getcb(pcic, CB_PRESENT_STATE); 66373db86aabSstevel if (cbctl && !(cbps & CB_PS_POWER_CYCLE)) { 66383db86aabSstevel /* break; */ 66393db86aabSstevel cmn_err(CE_WARN, "cbus_powerctl: power off??\n"); 66403db86aabSstevel } 66413db86aabSstevel if (cbctl & CB_PS_BADVCC) { 66423db86aabSstevel cmn_err(CE_WARN, "cbus_powerctl: bad power request\n"); 66433db86aabSstevel break; 66443db86aabSstevel } 66453db86aabSstevel 66463db86aabSstevel #if defined(PCIC_DEBUG) 66473db86aabSstevel pcic_err(pcic->dip, 8, 66483db86aabSstevel "cbstev = 0x%x cbps = 0x%x cbctl 0x%x(0x%x)", 66493db86aabSstevel cbstev, pcic_getcb(pcic, CB_PRESENT_STATE), 66503db86aabSstevel cbctl, orig_cbctl); 66513db86aabSstevel #endif 66523db86aabSstevel if (pcic_cbdoreset_during_poweron && 66533db86aabSstevel (orig_cbctl & (CB_C_VCCMASK|CB_C_VPPMASK)) == 0) { 66543db86aabSstevel pcic_putb(pcic, socket, PCIC_INTERRUPT, iobits); 66553db86aabSstevel } 66563db86aabSstevel return (SUCCESS); 66573db86aabSstevel } 66583db86aabSstevel pcic_mswait(pcic, socket, 40); 66593db86aabSstevel } 66603db86aabSstevel if (pcic_cbdoreset_during_poweron && 66613db86aabSstevel (orig_cbctl & (CB_C_VCCMASK|CB_C_VPPMASK)) == 0) { 66623db86aabSstevel pcic_putb(pcic, socket, PCIC_INTERRUPT, iobits); 66633db86aabSstevel } 66643db86aabSstevel cmn_err(CE_WARN, 66653db86aabSstevel "pcic socket %d: Power didn't get turned on/off!\n" 66663db86aabSstevel "cbstev = 0x%x cbps = 0x%x cbctl 0x%x(0x%x) " 66673db86aabSstevel "vcc %d vpp1 %d", socket, cbstev, 66683db86aabSstevel pcic_getcb(pcic, CB_PRESENT_STATE), 66693db86aabSstevel cbctl, orig_cbctl, sockp->pcs_vcc, sockp->pcs_vpp1); 66703db86aabSstevel return (BAD_VCC); 66713db86aabSstevel } 66723db86aabSstevel return (SUCCESS); 66733db86aabSstevel } 66743db86aabSstevel 66753db86aabSstevel static int pcic_do_pprintf = 0; 66763db86aabSstevel 66773db86aabSstevel static void 66783db86aabSstevel pcic_dump_debqueue(char *msg) 66793db86aabSstevel { 66803db86aabSstevel struct debounce *debp = pcic_deb_queue; 66813db86aabSstevel clock_t lbolt; 66823db86aabSstevel 66833db86aabSstevel (void) drv_getparm(LBOLT, &lbolt); 66843db86aabSstevel pcic_err(NULL, 6, debp ? "pcic debounce list (%s) lbolt 0x%x:\n" : 66853db86aabSstevel "pcic debounce_list (%s) EMPTY lbolt 0x%x\n", msg, lbolt); 66863db86aabSstevel while (debp) { 66873db86aabSstevel pcic_err(NULL, 6, "%p: exp 0x%x next 0x%p id 0x%p\n", 66883db86aabSstevel (void *) debp, (int)debp->expire, (void *) debp->next, 66893db86aabSstevel debp->pcs->pcs_debounce_id); 66903db86aabSstevel debp = debp->next; 66913db86aabSstevel } 66923db86aabSstevel } 66933db86aabSstevel 66943db86aabSstevel 66953db86aabSstevel /* PRINTFLIKE3 */ 66963db86aabSstevel static void 66973db86aabSstevel pcic_err(dev_info_t *dip, int level, const char *fmt, ...) 66983db86aabSstevel { 66993db86aabSstevel if (pcic_debug && (level <= pcic_debug)) { 67003db86aabSstevel va_list adx; 67013db86aabSstevel int instance; 67023db86aabSstevel char buf[256]; 67033db86aabSstevel const char *name; 67043db86aabSstevel #if !defined(PCIC_DEBUG) 67053db86aabSstevel int ce; 67063db86aabSstevel char qmark = 0; 67073db86aabSstevel 67083db86aabSstevel if (level <= 3) 67093db86aabSstevel ce = CE_WARN; 67103db86aabSstevel else 67113db86aabSstevel ce = CE_CONT; 67123db86aabSstevel if (level == 4) 67133db86aabSstevel qmark = 1; 67143db86aabSstevel #endif 67153db86aabSstevel 67163db86aabSstevel if (dip) { 67173db86aabSstevel instance = ddi_get_instance(dip); 67183db86aabSstevel /* name = ddi_binding_name(dip); */ 67193db86aabSstevel name = ddi_driver_name(dip); 67203db86aabSstevel } else { 67213db86aabSstevel instance = 0; 67223db86aabSstevel name = ""; 67233db86aabSstevel } 67243db86aabSstevel 67253db86aabSstevel va_start(adx, fmt); 67263db86aabSstevel (void) vsprintf(buf, fmt, adx); 67273db86aabSstevel va_end(adx); 67283db86aabSstevel 67293db86aabSstevel #if defined(PCIC_DEBUG) 67303db86aabSstevel if (pcic_do_pprintf) { 67313db86aabSstevel if (dip) { 67323db86aabSstevel if (instance >= 0) 67333db86aabSstevel prom_printf("%s(%d),0x%p: %s", name, 6734*903a11ebSrh87107 instance, (void *)dip, buf); 67353db86aabSstevel else 67363db86aabSstevel prom_printf("%s,0x%p: %s", 6737*903a11ebSrh87107 name, (void *)dip, buf); 67383db86aabSstevel } else 67393db86aabSstevel prom_printf(buf); 67403db86aabSstevel } else { 67413db86aabSstevel if (dip) { 67423db86aabSstevel if (instance >= 0) 67433db86aabSstevel cmn_err(CE_CONT, "%s(%d),0x%p: %s", 67443db86aabSstevel name, instance, (void *) dip, buf); 67453db86aabSstevel else 67463db86aabSstevel cmn_err(CE_CONT, "%s,0x%p: %s", 67473db86aabSstevel name, (void *) dip, buf); 67483db86aabSstevel } else 67493db86aabSstevel cmn_err(CE_CONT, buf); 67503db86aabSstevel } 67513db86aabSstevel #else 67523db86aabSstevel if (dip) 67533db86aabSstevel cmn_err(ce, qmark ? "?%s%d: %s" : "%s%d: %s", name, 67543db86aabSstevel instance, buf); 67553db86aabSstevel else 67563db86aabSstevel cmn_err(ce, qmark ? "?%s" : buf, buf); 67573db86aabSstevel #endif 67583db86aabSstevel } 67593db86aabSstevel } 6760