xref: /illumos-gate/usr/src/uts/common/io/pcic.c (revision ae5a8bed)
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 /*
2311c2b4c0Srw  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
243db86aabSstevel  * Use is subject to license terms.
2548bbca81SDaniel Hoffman  * Copyright (c) 2016 by Delphix. All rights reserved.
263db86aabSstevel  */
273db86aabSstevel 
283db86aabSstevel /*
293db86aabSstevel  * PCIC device/interrupt handler
303db86aabSstevel  *	The "pcic" driver handles the Intel 82365SL, Cirrus Logic
313db86aabSstevel  *	and Toshiba (and possibly other clones) PCMCIA adapter chip
323db86aabSstevel  *	sets.  It implements a subset of Socket Services as defined
333db86aabSstevel  *	in the Solaris PCMCIA design documents
343db86aabSstevel  */
353db86aabSstevel 
363db86aabSstevel /*
373db86aabSstevel  * currently defined "properties"
383db86aabSstevel  *
393db86aabSstevel  * clock-frequency		bus clock frequency
403db86aabSstevel  * smi				system management interrupt override
413db86aabSstevel  * need-mult-irq		need status IRQ for each pair of sockets
423db86aabSstevel  * disable-audio		don't route audio signal to speaker
433db86aabSstevel  */
443db86aabSstevel 
453db86aabSstevel 
463db86aabSstevel #include <sys/types.h>
473db86aabSstevel #include <sys/inttypes.h>
483db86aabSstevel #include <sys/param.h>
493db86aabSstevel #include <sys/systm.h>
503db86aabSstevel #include <sys/user.h>
513db86aabSstevel #include <sys/buf.h>
523db86aabSstevel #include <sys/file.h>
533db86aabSstevel #include <sys/uio.h>
543db86aabSstevel #include <sys/conf.h>
553db86aabSstevel #include <sys/stat.h>
563db86aabSstevel #include <sys/autoconf.h>
573db86aabSstevel #include <sys/vtoc.h>
583db86aabSstevel #include <sys/dkio.h>
593db86aabSstevel #include <sys/ddi.h>
603db86aabSstevel #include <sys/sunddi.h>
613db86aabSstevel #include <sys/sunndi.h>
623db86aabSstevel #include <sys/var.h>
633db86aabSstevel #include <sys/callb.h>
643db86aabSstevel #include <sys/open.h>
653db86aabSstevel #include <sys/ddidmareq.h>
663db86aabSstevel #include <sys/dma_engine.h>
673db86aabSstevel #include <sys/kstat.h>
683db86aabSstevel #include <sys/kmem.h>
693db86aabSstevel #include <sys/modctl.h>
703db86aabSstevel #include <sys/pci.h>
713db86aabSstevel #include <sys/pci_impl.h>
723db86aabSstevel 
733db86aabSstevel #include <sys/pctypes.h>
743db86aabSstevel #include <sys/pcmcia.h>
753db86aabSstevel #include <sys/sservice.h>
763db86aabSstevel 
773db86aabSstevel #include <sys/note.h>
783db86aabSstevel 
793db86aabSstevel #include <sys/pcic_reg.h>
803db86aabSstevel #include <sys/pcic_var.h>
813db86aabSstevel 
8286ef0a63SRichard Lowe #if defined(__x86)
83e12b469aSrui wang - Sun Microsystems - Beijing China #include <sys/pci_cfgspace.h>
84e12b469aSrui wang - Sun Microsystems - Beijing China #endif
85e12b469aSrui wang - Sun Microsystems - Beijing China 
863db86aabSstevel #if defined(__sparc)
873db86aabSstevel #include <sys/pci/pci_nexus.h>
883db86aabSstevel #endif
893db86aabSstevel 
900d282d13Srw #include <sys/hotplug/hpcsvc.h>
913db86aabSstevel #include "cardbus/cardbus.h"
923db86aabSstevel 
933db86aabSstevel #define	SOFTC_SIZE	(sizeof (anp_t))
943db86aabSstevel 
953db86aabSstevel static int pcic_getinfo(dev_info_t *, ddi_info_cmd_t, void *, void **);
963db86aabSstevel static int pcic_attach(dev_info_t *, ddi_attach_cmd_t);
973db86aabSstevel static int pcic_detach(dev_info_t *, ddi_detach_cmd_t);
985644143aSQuaker Fang static int32_t pcic_quiesce(dev_info_t *);
993db86aabSstevel static uint_t pcic_intr(caddr_t, caddr_t);
1003db86aabSstevel static int pcic_do_io_intr(pcicdev_t *, uint32_t);
1013db86aabSstevel static int pcic_probe(dev_info_t *);
1023db86aabSstevel 
1033db86aabSstevel static int pcic_open(dev_t *, int, int, cred_t *);
1043db86aabSstevel static int pcic_close(dev_t, int, int, cred_t *);
1053db86aabSstevel static int pcic_ioctl(dev_t, int, intptr_t, int, cred_t *, int *);
1063db86aabSstevel 
1073db86aabSstevel typedef struct pcm_regs pcm_regs_t;
1083db86aabSstevel 
1093db86aabSstevel static void pcic_init_assigned(dev_info_t *);
1103db86aabSstevel static int pcic_apply_avail_ranges(dev_info_t *, pcm_regs_t *,
1113db86aabSstevel 	pci_regspec_t *, int);
1123db86aabSstevel int pci_resource_setup_avail(dev_info_t *, pci_regspec_t *, int);
1133db86aabSstevel 
1143db86aabSstevel /*
1153db86aabSstevel  * On x86 platforms the ddi_iobp_alloc(9F) and ddi_mem_alloc(9F) calls
1163db86aabSstevel  * are xlated into DMA ctlops. To make this nexus work on x86, we
1173db86aabSstevel  * need to have the default ddi_dma_mctl ctlops in the bus_ops
1183db86aabSstevel  * structure, just to pass the request to the parent. The correct
1193db86aabSstevel  * ctlops should be ddi_no_dma_mctl because so far we don't do DMA.
1203db86aabSstevel  */
1213db86aabSstevel static
1223db86aabSstevel struct bus_ops pcmciabus_ops = {
1233db86aabSstevel 	BUSO_REV,
1243db86aabSstevel 	pcmcia_bus_map,
1253db86aabSstevel 	NULL,
1263db86aabSstevel 	NULL,
1273db86aabSstevel 	NULL,
1283db86aabSstevel 	i_ddi_map_fault,
1293db86aabSstevel 	ddi_no_dma_map,
1303db86aabSstevel 	ddi_no_dma_allochdl,
1313db86aabSstevel 	ddi_no_dma_freehdl,
1323db86aabSstevel 	ddi_no_dma_bindhdl,
1333db86aabSstevel 	ddi_no_dma_unbindhdl,
1343db86aabSstevel 	ddi_no_dma_flush,
1353db86aabSstevel 	ddi_no_dma_win,
1363db86aabSstevel 	ddi_dma_mctl,
1373db86aabSstevel 	pcmcia_ctlops,
1383db86aabSstevel 	pcmcia_prop_op,
1393db86aabSstevel 	NULL,				/* (*bus_get_eventcookie)();	*/
1403db86aabSstevel 	NULL,				/* (*bus_add_eventcall)();	*/
1413db86aabSstevel 	NULL,				/* (*bus_remove_eventcall)();	*/
1423db86aabSstevel 	NULL,				/* (*bus_post_event)();		*/
1433db86aabSstevel 	NULL,				/* (*bus_intr_ctl)();		*/
144f6c5b045SToomas Soome 	NULL,				/* (*bus_config)();		*/
145f6c5b045SToomas Soome 	NULL,				/* (*bus_unconfig)();		*/
146f6c5b045SToomas Soome 	NULL,				/* (*bus_fm_init)();		*/
147f6c5b045SToomas Soome 	NULL,				/* (*bus_fm_fini)();		*/
1483db86aabSstevel 	NULL,				/* (*bus_enter)()		*/
1493db86aabSstevel 	NULL,				/* (*bus_exit)()		*/
1503db86aabSstevel 	NULL,				/* (*bus_power)()		*/
151f6c5b045SToomas Soome 	pcmcia_intr_ops			/* (*bus_intr_op)();		*/
1523db86aabSstevel };
1533db86aabSstevel 
1543db86aabSstevel static struct cb_ops pcic_cbops = {
1553db86aabSstevel 	pcic_open,
1563db86aabSstevel 	pcic_close,
1573db86aabSstevel 	nodev,
1583db86aabSstevel 	nodev,
1593db86aabSstevel 	nodev,
1603db86aabSstevel 	nodev,
1613db86aabSstevel 	nodev,
1623db86aabSstevel 	pcic_ioctl,
1633db86aabSstevel 	nodev,
1643db86aabSstevel 	nodev,
1653db86aabSstevel 	nodev,
1663db86aabSstevel 	nochpoll,
1673db86aabSstevel 	ddi_prop_op,
1683db86aabSstevel 	NULL,
1693db86aabSstevel #ifdef CARDBUS
1703db86aabSstevel 	D_NEW | D_MP | D_HOTPLUG
1713db86aabSstevel #else
1723db86aabSstevel 	D_NEW | D_MP
1733db86aabSstevel #endif
1743db86aabSstevel };
1753db86aabSstevel 
1763db86aabSstevel static struct dev_ops pcic_devops = {
1773db86aabSstevel 	DEVO_REV,
1783db86aabSstevel 	0,
1793db86aabSstevel 	pcic_getinfo,
1803db86aabSstevel 	nulldev,
1813db86aabSstevel 	pcic_probe,
1823db86aabSstevel 	pcic_attach,
1833db86aabSstevel 	pcic_detach,
1843db86aabSstevel 	nulldev,
1853db86aabSstevel 	&pcic_cbops,
1863db86aabSstevel 	&pcmciabus_ops,
18719397407SSherry Moore 	NULL,
1885644143aSQuaker Fang 	pcic_quiesce,	/* devo_quiesce */
1893db86aabSstevel };
1903db86aabSstevel 
1913db86aabSstevel void *pcic_soft_state_p = NULL;
1923db86aabSstevel static int pcic_maxinst = -1;
1933db86aabSstevel 
1943db86aabSstevel int pcic_do_insertion = 1;
1953db86aabSstevel int pcic_do_removal = 1;
1963db86aabSstevel 
1973db86aabSstevel struct irqmap {
1983db86aabSstevel 	int irq;
1993db86aabSstevel 	int count;
2003db86aabSstevel } pcic_irq_map[16];
2013db86aabSstevel 
2023db86aabSstevel 
2033db86aabSstevel int pcic_debug = 0x0;
2043db86aabSstevel static  void    pcic_err(dev_info_t *dip, int level, const char *fmt, ...);
2053db86aabSstevel extern void cardbus_dump_pci_config(dev_info_t *dip);
2063db86aabSstevel extern void cardbus_dump_socket(dev_info_t *dip);
2073db86aabSstevel extern int cardbus_validate_iline(dev_info_t *dip, ddi_acc_handle_t handle);
2083db86aabSstevel static void pcic_dump_debqueue(char *msg);
2093db86aabSstevel 
2103db86aabSstevel #if defined(PCIC_DEBUG)
2113db86aabSstevel static void xxdmp_all_regs(pcicdev_t *, int, uint32_t);
2123db86aabSstevel 
2133db86aabSstevel #define	pcic_mutex_enter(a)	\
2143db86aabSstevel 	{ \
2153db86aabSstevel 		pcic_err(NULL, 10, "Set lock at %d\n", __LINE__); \
2163db86aabSstevel 		mutex_enter(a); \
2173db86aabSstevel 	};
2183db86aabSstevel 
2193db86aabSstevel #define	pcic_mutex_exit(a)	\
2203db86aabSstevel 	{ \
2213db86aabSstevel 		pcic_err(NULL, 10, "Clear lock at %d\n", __LINE__); \
2223db86aabSstevel 		mutex_exit(a); \
2233db86aabSstevel 	};
2243db86aabSstevel 
2253db86aabSstevel #else
2263db86aabSstevel #define	pcic_mutex_enter(a)	mutex_enter(a)
2273db86aabSstevel #define	pcic_mutex_exit(a)	mutex_exit(a)
2283db86aabSstevel #endif
2293db86aabSstevel 
2303db86aabSstevel #define	PCIC_VCC_3VLEVEL	1
2313db86aabSstevel #define	PCIC_VCC_5VLEVEL	2
2323db86aabSstevel #define	PCIC_VCC_12LEVEL	3
2333db86aabSstevel 
2343db86aabSstevel /* bit patterns to select voltage levels */
2353db86aabSstevel int pcic_vpp_levels[13] = {
2363db86aabSstevel 	0, 0, 0,
2373db86aabSstevel 	1,	/* 3.3V */
2383db86aabSstevel 	0,
2393db86aabSstevel 	1,	/* 5V */
2403db86aabSstevel 	0, 0, 0, 0, 0, 0,
2413db86aabSstevel 	2	/* 12V */
2423db86aabSstevel };
2433db86aabSstevel 
2443db86aabSstevel uint8_t pcic_cbv_levels[13] = {
2453db86aabSstevel 	0, 0, 0,
2463db86aabSstevel 	3,			/* 3.3V */
2473db86aabSstevel 	0,
2483db86aabSstevel 	2,			/* 5V */
2493db86aabSstevel 	0, 0, 0, 0, 0, 0,
2503db86aabSstevel 	1			/* 12V */
2513db86aabSstevel };
2523db86aabSstevel 
2533db86aabSstevel struct power_entry pcic_power[4] = {
2543db86aabSstevel 	{
2553db86aabSstevel 		0, VCC|VPP1|VPP2
2563db86aabSstevel 	},
2573db86aabSstevel 	{
2583db86aabSstevel 		33,		/* 3.3Volt */
2593db86aabSstevel 		VCC|VPP1|VPP2
2603db86aabSstevel 	},
2613db86aabSstevel 	{
2623db86aabSstevel 		5*10,		/* 5Volt */
2633db86aabSstevel 		VCC|VPP1|VPP2	/* currently only know about this */
2643db86aabSstevel 	},
2653db86aabSstevel 	{
2663db86aabSstevel 		12*10,		/* 12Volt */
2673db86aabSstevel 		VPP1|VPP2
2683db86aabSstevel 	}
2693db86aabSstevel };
2703db86aabSstevel 
2713db86aabSstevel /*
2723db86aabSstevel  * Base used to allocate ranges of PCI memory on x86 systems
2733db86aabSstevel  * Each instance gets a chunk above the base that is used to map
2743db86aabSstevel  * in the memory and I/O windows for that device.
2753db86aabSstevel  * Pages below the base are also allocated for the EXCA registers,
2763db86aabSstevel  * one per instance.
2773db86aabSstevel  */
2783db86aabSstevel #define	PCIC_PCI_MEMCHUNK	0x1000000
2793db86aabSstevel 
2803db86aabSstevel static int pcic_wait_insert_time = 5000000;	/* In micro-seconds */
2813db86aabSstevel static int pcic_debounce_time = 200000; /* In micro-seconds */
2823db86aabSstevel 
2833db86aabSstevel struct debounce {
2843db86aabSstevel 	pcic_socket_t *pcs;
2853db86aabSstevel 	clock_t expire;
2863db86aabSstevel 	struct debounce *next;
2873db86aabSstevel };
2883db86aabSstevel 
2893db86aabSstevel static struct debounce *pcic_deb_queue = NULL;
2903db86aabSstevel static kmutex_t pcic_deb_mtx;
2913db86aabSstevel static kcondvar_t pcic_deb_cv;
2923db86aabSstevel static kthread_t *pcic_deb_threadid;
2933db86aabSstevel 
2943db86aabSstevel static inthandler_t *pcic_handlers;
2953db86aabSstevel 
2963db86aabSstevel static void pcic_setup_adapter(pcicdev_t *);
2973db86aabSstevel static int pcic_change(pcicdev_t *, int);
2983db86aabSstevel static int pcic_ll_reset(pcicdev_t *, int);
2993db86aabSstevel static void pcic_mswait(pcicdev_t *, int, int);
3003db86aabSstevel static boolean_t pcic_check_ready(pcicdev_t *, int);
3013db86aabSstevel static void pcic_set_cdtimers(pcicdev_t *, int, uint32_t, int);
3023db86aabSstevel static void pcic_ready_wait(pcicdev_t *, int);
3033db86aabSstevel extern int pcmcia_get_intr(dev_info_t *, int);
3043db86aabSstevel extern int pcmcia_return_intr(dev_info_t *, int);
30511c2b4c0Srw extern void pcmcia_cb_suspended(int);
30611c2b4c0Srw extern void pcmcia_cb_resumed(int);
3073db86aabSstevel 
3083db86aabSstevel static int pcic_callback(dev_info_t *, int (*)(), int);
3093db86aabSstevel static int pcic_inquire_adapter(dev_info_t *, inquire_adapter_t *);
3103db86aabSstevel static int pcic_get_adapter(dev_info_t *, get_adapter_t *);
3113db86aabSstevel static int pcic_get_page(dev_info_t *, get_page_t *);
3123db86aabSstevel static int pcic_get_socket(dev_info_t *, get_socket_t *);
3133db86aabSstevel static int pcic_get_status(dev_info_t *, get_ss_status_t *);
3143db86aabSstevel static int pcic_get_window(dev_info_t *, get_window_t *);
3153db86aabSstevel static int pcic_inquire_socket(dev_info_t *, inquire_socket_t *);
3163db86aabSstevel static int pcic_inquire_window(dev_info_t *, inquire_window_t *);
3173db86aabSstevel static int pcic_reset_socket(dev_info_t *, int, int);
3183db86aabSstevel static int pcic_set_page(dev_info_t *, set_page_t *);
3193db86aabSstevel static int pcic_set_window(dev_info_t *, set_window_t *);
3203db86aabSstevel static int pcic_set_socket(dev_info_t *, set_socket_t *);
3213db86aabSstevel static int pcic_set_interrupt(dev_info_t *, set_irq_handler_t *);
3223db86aabSstevel static int pcic_clear_interrupt(dev_info_t *, clear_irq_handler_t *);
3233db86aabSstevel static void pcic_pm_detection(void *);
3243db86aabSstevel static void pcic_iomem_pci_ctl(ddi_acc_handle_t, uchar_t *, unsigned);
3253db86aabSstevel static int clext_reg_read(pcicdev_t *, int, uchar_t);
3263db86aabSstevel static void clext_reg_write(pcicdev_t *, int, uchar_t, uchar_t);
3273db86aabSstevel static int pcic_calc_speed(pcicdev_t *, uint32_t);
3283db86aabSstevel static int pcic_card_state(pcicdev_t *, pcic_socket_t *);
3293db86aabSstevel static int pcic_find_pci_type(pcicdev_t *);
3303db86aabSstevel static void pcic_82092_smiirq_ctl(pcicdev_t *, int, int, int);
3313db86aabSstevel static void pcic_handle_cd_change(pcicdev_t *, pcic_socket_t *, uint8_t);
3323db86aabSstevel static uint_t pcic_cd_softint(caddr_t, caddr_t);
3333db86aabSstevel static uint8_t pcic_getb(pcicdev_t *, int, int);
3343db86aabSstevel static void pcic_putb(pcicdev_t *, int, int, int8_t);
3353db86aabSstevel static int pcic_set_vcc_level(pcicdev_t *, set_socket_t *);
3363db86aabSstevel static uint_t pcic_softintr(caddr_t, caddr_t);
3373db86aabSstevel 
3383db86aabSstevel static void pcic_debounce(pcic_socket_t *);
33911c2b4c0Srw static void pcic_do_resume(pcicdev_t *);
3403db86aabSstevel static void *pcic_add_debqueue(pcic_socket_t *, int);
3413db86aabSstevel static void pcic_rm_debqueue(void *);
3423db86aabSstevel static void pcic_deb_thread();
3433db86aabSstevel 
3443db86aabSstevel static boolean_t pcic_load_cardbus(pcicdev_t *pcic, const pcic_socket_t *sockp);
3453db86aabSstevel static void pcic_unload_cardbus(pcicdev_t *pcic, const pcic_socket_t *sockp);
3463db86aabSstevel static uint32_t pcic_getcb(pcicdev_t *pcic, int reg);
3473db86aabSstevel static void pcic_putcb(pcicdev_t *pcic, int reg, uint32_t value);
3483db86aabSstevel static void pcic_cb_enable_intr(dev_info_t *);
3493db86aabSstevel static void pcic_cb_disable_intr(dev_info_t *);
3503db86aabSstevel static void pcic_enable_io_intr(pcicdev_t *pcic, int socket, int irq);
3513db86aabSstevel static void pcic_disable_io_intr(pcicdev_t *pcic, int socket);
3523db86aabSstevel 
3533db86aabSstevel static cb_nexus_cb_t pcic_cbnexus_ops = {
3543db86aabSstevel 	pcic_cb_enable_intr,
3553db86aabSstevel 	pcic_cb_disable_intr
3563db86aabSstevel };
3573db86aabSstevel 
3583db86aabSstevel static int pcic_exca_powerctl(pcicdev_t *pcic, int socket, int powerlevel);
3593db86aabSstevel static int pcic_cbus_powerctl(pcicdev_t *pcic, int socket);
3603db86aabSstevel 
3613db86aabSstevel #if defined(__sparc)
3623db86aabSstevel static int pcic_fault(enum pci_fault_ops op, void *arg);
3633db86aabSstevel #endif
3643db86aabSstevel 
3653db86aabSstevel 
3663db86aabSstevel /*
3673db86aabSstevel  * pcmcia interface operations structure
3683db86aabSstevel  * this is the private interface that is exported to the nexus
3693db86aabSstevel  */
3703db86aabSstevel pcmcia_if_t pcic_if_ops = {
3713db86aabSstevel 	PCIF_MAGIC,
3723db86aabSstevel 	PCIF_VERSION,
3733db86aabSstevel 	pcic_callback,
3743db86aabSstevel 	pcic_get_adapter,
3753db86aabSstevel 	pcic_get_page,
3763db86aabSstevel 	pcic_get_socket,
3773db86aabSstevel 	pcic_get_status,
3783db86aabSstevel 	pcic_get_window,
3793db86aabSstevel 	pcic_inquire_adapter,
3803db86aabSstevel 	pcic_inquire_socket,
3813db86aabSstevel 	pcic_inquire_window,
3823db86aabSstevel 	pcic_reset_socket,
3833db86aabSstevel 	pcic_set_page,
3843db86aabSstevel 	pcic_set_window,
3853db86aabSstevel 	pcic_set_socket,
3863db86aabSstevel 	pcic_set_interrupt,
3873db86aabSstevel 	pcic_clear_interrupt,
3883db86aabSstevel 	NULL,
3893db86aabSstevel };
3903db86aabSstevel 
3913db86aabSstevel /*
3923db86aabSstevel  * chip type identification routines
3933db86aabSstevel  * this list of functions is searched until one of them succeeds
3943db86aabSstevel  * or all fail.  i82365SL is assumed if failed.
3953db86aabSstevel  */
3963db86aabSstevel static int pcic_ci_cirrus(pcicdev_t *);
3973db86aabSstevel static int pcic_ci_vadem(pcicdev_t *);
3983db86aabSstevel static int pcic_ci_ricoh(pcicdev_t *);
3993db86aabSstevel 
4003db86aabSstevel int (*pcic_ci_funcs[])(pcicdev_t *) = {
4013db86aabSstevel 	pcic_ci_cirrus,
4023db86aabSstevel 	pcic_ci_vadem,
4033db86aabSstevel 	pcic_ci_ricoh,
4043db86aabSstevel 	NULL
4053db86aabSstevel };
4063db86aabSstevel 
4073db86aabSstevel static struct modldrv modldrv = {
4083db86aabSstevel 	&mod_driverops,		/* Type of module. This one is a driver */
409903a11ebSrh 	"PCIC PCMCIA adapter driver",	/* Name of the module. */
4103db86aabSstevel 	&pcic_devops,		/* driver ops */
4113db86aabSstevel };
4123db86aabSstevel 
4133db86aabSstevel static struct modlinkage modlinkage = {
4143db86aabSstevel 	MODREV_1, (void *)&modldrv, NULL
4153db86aabSstevel };
4163db86aabSstevel 
4173db86aabSstevel int
_init()4183db86aabSstevel _init()
4193db86aabSstevel {
4203db86aabSstevel 	int stat;
4213db86aabSstevel 
4223db86aabSstevel 	/* Allocate soft state */
4233db86aabSstevel 	if ((stat = ddi_soft_state_init(&pcic_soft_state_p,
4243db86aabSstevel 	    SOFTC_SIZE, 2)) != DDI_SUCCESS)
4253db86aabSstevel 		return (stat);
4263db86aabSstevel 
4273db86aabSstevel 	if ((stat = mod_install(&modlinkage)) != 0)
4283db86aabSstevel 		ddi_soft_state_fini(&pcic_soft_state_p);
4293db86aabSstevel 
4303db86aabSstevel 	return (stat);
4313db86aabSstevel }
4323db86aabSstevel 
4333db86aabSstevel int
_fini()4343db86aabSstevel _fini()
4353db86aabSstevel {
4363db86aabSstevel 	int stat = 0;
4373db86aabSstevel 
4383db86aabSstevel 	if ((stat = mod_remove(&modlinkage)) != 0)
4393db86aabSstevel 		return (stat);
4403db86aabSstevel 
4413db86aabSstevel 	if (pcic_deb_threadid) {
4423db86aabSstevel 		mutex_enter(&pcic_deb_mtx);
4433db86aabSstevel 		pcic_deb_threadid = 0;
4443db86aabSstevel 		while (!pcic_deb_threadid)
4453db86aabSstevel 			cv_wait(&pcic_deb_cv, &pcic_deb_mtx);
4463db86aabSstevel 		pcic_deb_threadid = 0;
4473db86aabSstevel 		mutex_exit(&pcic_deb_mtx);
4483db86aabSstevel 
4493db86aabSstevel 		mutex_destroy(&pcic_deb_mtx);
4503db86aabSstevel 		cv_destroy(&pcic_deb_cv);
4513db86aabSstevel 	}
4523db86aabSstevel 
4533db86aabSstevel 	ddi_soft_state_fini(&pcic_soft_state_p);
4543db86aabSstevel 
4553db86aabSstevel 	return (stat);
4563db86aabSstevel }
4573db86aabSstevel 
4583db86aabSstevel int
_info(struct modinfo * modinfop)4593db86aabSstevel _info(struct modinfo *modinfop)
4603db86aabSstevel {
4613db86aabSstevel 	return (mod_info(&modlinkage, modinfop));
4623db86aabSstevel }
4633db86aabSstevel 
4643db86aabSstevel /*
4653db86aabSstevel  * pcic_getinfo()
4663db86aabSstevel  *	provide instance/device information about driver
4673db86aabSstevel  */
4683db86aabSstevel /*ARGSUSED*/
4693db86aabSstevel static int
pcic_getinfo(dev_info_t * dip,ddi_info_cmd_t cmd,void * arg,void ** result)4703db86aabSstevel pcic_getinfo(dev_info_t *dip, ddi_info_cmd_t cmd, void *arg, void **result)
4713db86aabSstevel {
4723db86aabSstevel 	anp_t *anp;
4733db86aabSstevel 	int error = DDI_SUCCESS;
4743db86aabSstevel 	minor_t minor;
4753db86aabSstevel 
4763db86aabSstevel 	switch (cmd) {
47719397407SSherry Moore 		case DDI_INFO_DEVT2DEVINFO:
4783db86aabSstevel 		minor = getminor((dev_t)arg);
479459fbba0Sgd 		minor &= 0x7f;
4803db86aabSstevel 		if (!(anp = ddi_get_soft_state(pcic_soft_state_p, minor)))
4813db86aabSstevel 			*result = NULL;
4823db86aabSstevel 		else
4833db86aabSstevel 			*result = anp->an_dip;
4843db86aabSstevel 		break;
48519397407SSherry Moore 		case DDI_INFO_DEVT2INSTANCE:
4863db86aabSstevel 		minor = getminor((dev_t)arg);
487459fbba0Sgd 		minor &= 0x7f;
4883db86aabSstevel 		*result = (void *)((long)minor);
4893db86aabSstevel 		break;
49019397407SSherry Moore 		default:
4913db86aabSstevel 		error = DDI_FAILURE;
4923db86aabSstevel 		break;
4933db86aabSstevel 	}
4943db86aabSstevel 	return (error);
4953db86aabSstevel }
4963db86aabSstevel 
4973db86aabSstevel static int
pcic_probe(dev_info_t * dip)4983db86aabSstevel pcic_probe(dev_info_t *dip)
4993db86aabSstevel {
5003db86aabSstevel 	int value;
5013db86aabSstevel 	ddi_device_acc_attr_t attr;
5023db86aabSstevel 	ddi_acc_handle_t handle;
5033db86aabSstevel 	uchar_t *index, *data;
5043db86aabSstevel 
5053db86aabSstevel 	if (ddi_dev_is_sid(dip) == DDI_SUCCESS)
50619397407SSherry Moore 		return (DDI_PROBE_DONTCARE);
5073db86aabSstevel 
5083db86aabSstevel 	/*
5093db86aabSstevel 	 * find a PCIC device (any vendor)
5103db86aabSstevel 	 * while there can be up to 4 such devices in
5113db86aabSstevel 	 * a system, we currently only look for 1
5123db86aabSstevel 	 * per probe.  There will be up to 2 chips per
5133db86aabSstevel 	 * instance since they share I/O space
5143db86aabSstevel 	 */
5153db86aabSstevel 	attr.devacc_attr_version = DDI_DEVICE_ATTR_V0;
5163db86aabSstevel 	attr.devacc_attr_endian_flags = DDI_NEVERSWAP_ACC;
5173db86aabSstevel 	attr.devacc_attr_dataorder = DDI_STRICTORDER_ACC;
5183db86aabSstevel 
5193db86aabSstevel 	if (ddi_regs_map_setup(dip, PCIC_ISA_CONTROL_REG_NUM,
52019397407SSherry Moore 	    (caddr_t *)&index,
52119397407SSherry Moore 	    PCIC_ISA_CONTROL_REG_OFFSET,
52219397407SSherry Moore 	    PCIC_ISA_CONTROL_REG_LENGTH,
52319397407SSherry Moore 	    &attr, &handle) != DDI_SUCCESS)
52419397407SSherry Moore 		return (DDI_PROBE_FAILURE);
5253db86aabSstevel 
5263db86aabSstevel 	data = index + 1;
5273db86aabSstevel 
5283db86aabSstevel #if defined(PCIC_DEBUG)
5293db86aabSstevel 	if (pcic_debug)
5303db86aabSstevel 		cmn_err(CE_CONT, "pcic_probe: entered\n");
5313db86aabSstevel 	if (pcic_debug)
5323db86aabSstevel 		cmn_err(CE_CONT, "\tindex=%p\n", (void *)index);
5333db86aabSstevel #endif
5343db86aabSstevel 	ddi_put8(handle, index, PCIC_CHIP_REVISION);
5353db86aabSstevel 	ddi_put8(handle, data, 0);
5363db86aabSstevel 	value = ddi_get8(handle, data);
5373db86aabSstevel #if defined(PCIC_DEBUG)
5383db86aabSstevel 	if (pcic_debug)
5393db86aabSstevel 		cmn_err(CE_CONT, "\tchip revision register = %x\n", value);
5403db86aabSstevel #endif
5413db86aabSstevel 	if ((value & PCIC_REV_MASK) >= PCIC_REV_LEVEL_LOW &&
5423db86aabSstevel 	    (value & 0x30) == 0) {
5433db86aabSstevel 		/*
5443db86aabSstevel 		 * we probably have a PCIC chip in the system
5453db86aabSstevel 		 * do a little more checking.  If we find one,
5463db86aabSstevel 		 * reset everything in case of softboot
5473db86aabSstevel 		 */
5483db86aabSstevel 		ddi_put8(handle, index, PCIC_MAPPING_ENABLE);
5493db86aabSstevel 		ddi_put8(handle, data, 0);
5503db86aabSstevel 		value = ddi_get8(handle, data);
5513db86aabSstevel #if defined(PCIC_DEBUG)
5523db86aabSstevel 		if (pcic_debug)
5533db86aabSstevel 			cmn_err(CE_CONT, "\tzero test = %x\n", value);
5543db86aabSstevel #endif
5553db86aabSstevel 		/* should read back as zero */
5563db86aabSstevel 		if (value == 0) {
5573db86aabSstevel 			/*
5583db86aabSstevel 			 * we do have one and it is off the bus
5593db86aabSstevel 			 */
5603db86aabSstevel #if defined(PCIC_DEBUG)
5613db86aabSstevel 			if (pcic_debug)
5623db86aabSstevel 				cmn_err(CE_CONT, "pcic_probe: success\n");
5633db86aabSstevel #endif
5643db86aabSstevel 			ddi_regs_map_free(&handle);
5653db86aabSstevel 			return (DDI_PROBE_SUCCESS);
5663db86aabSstevel 		}
5673db86aabSstevel 	}
5683db86aabSstevel #if defined(PCIC_DEBUG)
5693db86aabSstevel 	if (pcic_debug)
5703db86aabSstevel 		cmn_err(CE_CONT, "pcic_probe: failed\n");
5713db86aabSstevel #endif
5723db86aabSstevel 	ddi_regs_map_free(&handle);
5733db86aabSstevel 	return (DDI_PROBE_FAILURE);
5743db86aabSstevel }
5753db86aabSstevel 
5763db86aabSstevel /*
5773db86aabSstevel  * These are just defaults they can also be changed via a property in the
5783db86aabSstevel  * conf file.
5793db86aabSstevel  */
5803db86aabSstevel static int pci_config_reg_num = PCIC_PCI_CONFIG_REG_NUM;
5813db86aabSstevel static int pci_control_reg_num = PCIC_PCI_CONTROL_REG_NUM;
58211c2b4c0Srw static int pcic_do_pcmcia_sr = 1;
5833db86aabSstevel static int pcic_use_cbpwrctl = PCF_CBPWRCTL;
5843db86aabSstevel 
5853db86aabSstevel /*
5863db86aabSstevel  * enable insertion/removal interrupt for 32bit cards
5873db86aabSstevel  */
5883db86aabSstevel static int
cardbus_enable_cd_intr(dev_info_t * dip)5893db86aabSstevel cardbus_enable_cd_intr(dev_info_t *dip)
5903db86aabSstevel {
5913db86aabSstevel 	ddi_acc_handle_t	iohandle;
5923db86aabSstevel 	caddr_t	ioaddr;
5933db86aabSstevel 	ddi_device_acc_attr_t attr;
5943db86aabSstevel 	attr.devacc_attr_version = DDI_DEVICE_ATTR_V0;
5953db86aabSstevel 	attr.devacc_attr_endian_flags = DDI_STRUCTURE_LE_ACC;
5963db86aabSstevel 	attr.devacc_attr_dataorder = DDI_STRICTORDER_ACC;
5973db86aabSstevel 	(void) ddi_regs_map_setup(dip, 1,
59819397407SSherry Moore 	    (caddr_t *)&ioaddr,
59919397407SSherry Moore 	    0,
60019397407SSherry Moore 	    4096,
60119397407SSherry Moore 	    &attr, &iohandle);
6023db86aabSstevel 
6033db86aabSstevel 	/* CSC Interrupt: Card detect interrupt on */
6043db86aabSstevel 	ddi_put32(iohandle, (uint32_t *)(ioaddr+CB_STATUS_MASK),
60519397407SSherry Moore 	    ddi_get32(iohandle,
60619397407SSherry Moore 	    (uint32_t *)(ioaddr+CB_STATUS_MASK)) | CB_SE_CCDMASK);
6073db86aabSstevel 
6083db86aabSstevel 	ddi_put32(iohandle, (uint32_t *)(ioaddr+CB_STATUS_EVENT),
60919397407SSherry Moore 	    ddi_get32(iohandle, (uint32_t *)(ioaddr+CB_STATUS_EVENT)));
6103db86aabSstevel 
6113db86aabSstevel 	ddi_regs_map_free(&iohandle);
6123db86aabSstevel 	return (1);
6133db86aabSstevel }
6143db86aabSstevel 
6155644143aSQuaker Fang /*
6165644143aSQuaker Fang  * quiesce(9E) entry point.
6175644143aSQuaker Fang  *
6185644143aSQuaker Fang  * This function is called when the system is single-threaded at high
6195644143aSQuaker Fang  * PIL with preemption disabled. Therefore, this function must not be
6205644143aSQuaker Fang  * blocked.
6215644143aSQuaker Fang  *
6225644143aSQuaker Fang  * This function returns DDI_SUCCESS on success, or DDI_FAILURE on failure.
6235644143aSQuaker Fang  * DDI_FAILURE indicates an error condition and should almost never happen.
6245644143aSQuaker Fang  */
6255644143aSQuaker Fang static int32_t
pcic_quiesce(dev_info_t * dip)6265644143aSQuaker Fang pcic_quiesce(dev_info_t *dip)
6275644143aSQuaker Fang {
6285644143aSQuaker Fang 	anp_t *anp = ddi_get_driver_private(dip);
6295644143aSQuaker Fang 	pcicdev_t *pcic = anp->an_private;
6305644143aSQuaker Fang 	int i;
6315644143aSQuaker Fang 
6325644143aSQuaker Fang 	for (i = 0; i < pcic->pc_numsockets; i++) {
6335644143aSQuaker Fang 		pcic_putb(pcic, i, PCIC_MANAGEMENT_INT, 0);
6345644143aSQuaker Fang 		pcic_putb(pcic, i, PCIC_CARD_DETECT, 0);
6355644143aSQuaker Fang 		pcic_putb(pcic, i, PCIC_MAPPING_ENABLE, 0);
6365644143aSQuaker Fang 		/* disable interrupts and put card into RESET */
6375644143aSQuaker Fang 		pcic_putb(pcic, i, PCIC_INTERRUPT, 0);
6385644143aSQuaker Fang 		/* poweroff socket */
6395644143aSQuaker Fang 		pcic_putb(pcic, i, PCIC_POWER_CONTROL, 0);
6405644143aSQuaker Fang 		pcic_putcb(pcic, CB_CONTROL, 0);
6415644143aSQuaker Fang 	}
6425644143aSQuaker Fang 
6435644143aSQuaker Fang 	return (DDI_SUCCESS);
6445644143aSQuaker Fang }
6455644143aSQuaker Fang 
6463db86aabSstevel /*
6473db86aabSstevel  * pcic_attach()
6483db86aabSstevel  *	attach the PCIC (Intel 82365SL/CirrusLogic/Toshiba) driver
6493db86aabSstevel  *	to the system.  This is a child of "sysbus" since that is where
6503db86aabSstevel  *	the hardware lives, but it provides services to the "pcmcia"
6513db86aabSstevel  *	nexus driver.  It gives a pointer back via its private data
6523db86aabSstevel  *	structure which contains both the dip and socket services entry
6533db86aabSstevel  *	points
6543db86aabSstevel  */
6553db86aabSstevel static int
pcic_attach(dev_info_t * dip,ddi_attach_cmd_t cmd)6563db86aabSstevel pcic_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
6573db86aabSstevel {
6583db86aabSstevel 	anp_t *pcic_nexus;
6593db86aabSstevel 	pcicdev_t *pcic;
6603db86aabSstevel 	int irqlevel, value;
6613db86aabSstevel 	int pci_cfrn, pci_ctrn;
6623db86aabSstevel 	int i, j, smi, actual;
6633db86aabSstevel 	char *typename;
6643db86aabSstevel 	char bus_type[16] = "(unknown)";
6653db86aabSstevel 	int len = sizeof (bus_type);
6663db86aabSstevel 	ddi_device_acc_attr_t attr;
6673db86aabSstevel 	anp_t *anp = ddi_get_driver_private(dip);
6683db86aabSstevel 	uint_t	pri;
6693db86aabSstevel 
6703db86aabSstevel #if defined(PCIC_DEBUG)
6713db86aabSstevel 	if (pcic_debug) {
6723db86aabSstevel 		cmn_err(CE_CONT, "pcic_attach: entered\n");
6733db86aabSstevel 	}
6743db86aabSstevel #endif
6753db86aabSstevel 	switch (cmd) {
6763db86aabSstevel 	case DDI_ATTACH:
6773db86aabSstevel 		break;
6783db86aabSstevel 	case DDI_RESUME:
6793db86aabSstevel 		pcic = anp->an_private;
6803db86aabSstevel 		/*
6813db86aabSstevel 		 * for now, this is a simulated resume.
6823db86aabSstevel 		 * a real one may need different things.
6833db86aabSstevel 		 */
6843db86aabSstevel 		if (pcic != NULL && pcic->pc_flags & PCF_SUSPENDED) {
6853db86aabSstevel 			mutex_enter(&pcic->pc_lock);
6863db86aabSstevel 			/* should probe for new sockets showing up */
6873db86aabSstevel 			pcic_setup_adapter(pcic);
6883db86aabSstevel 			pcic->pc_flags &= ~PCF_SUSPENDED;
6893db86aabSstevel 			mutex_exit(&pcic->pc_lock);
6903db86aabSstevel 			(void) pcmcia_begin_resume(dip);
69111c2b4c0Srw 
69211c2b4c0Srw 			pcic_do_resume(pcic);
69311c2b4c0Srw #ifdef CARDBUS
69411c2b4c0Srw 			cardbus_restore_children(ddi_get_child(dip));
69511c2b4c0Srw #endif
6963db86aabSstevel 
6973db86aabSstevel 			/*
6983db86aabSstevel 			 * for complete implementation need END_RESUME (later)
6993db86aabSstevel 			 */
7003db86aabSstevel 			return (DDI_SUCCESS);
7013db86aabSstevel 
7023db86aabSstevel 		}
7033db86aabSstevel 		return (DDI_SUCCESS);
7043db86aabSstevel 	default:
7053db86aabSstevel 		return (DDI_FAILURE);
7063db86aabSstevel 	}
7073db86aabSstevel 
7083db86aabSstevel 	/*
7093db86aabSstevel 	 * Allocate soft state associated with this instance.
7103db86aabSstevel 	 */
7113db86aabSstevel 	if (ddi_soft_state_zalloc(pcic_soft_state_p,
71219397407SSherry Moore 	    ddi_get_instance(dip)) != DDI_SUCCESS) {
7133db86aabSstevel 		cmn_err(CE_CONT, "pcic%d: Unable to alloc state\n",
71419397407SSherry Moore 		    ddi_get_instance(dip));
7153db86aabSstevel 		return (DDI_FAILURE);
7163db86aabSstevel 	}
7173db86aabSstevel 
7183db86aabSstevel 	pcic_nexus = ddi_get_soft_state(pcic_soft_state_p,
7193db86aabSstevel 	    ddi_get_instance(dip));
7203db86aabSstevel 
7213db86aabSstevel 	pcic = kmem_zalloc(sizeof (pcicdev_t), KM_SLEEP);
7223db86aabSstevel 
7233db86aabSstevel 	pcic->dip = dip;
7243db86aabSstevel 	pcic_nexus->an_dip = dip;
7253db86aabSstevel 	pcic_nexus->an_if = &pcic_if_ops;
7263db86aabSstevel 	pcic_nexus->an_private = pcic;
7273db86aabSstevel 	pcic->pc_numpower = sizeof (pcic_power)/sizeof (pcic_power[0]);
7283db86aabSstevel 	pcic->pc_power = pcic_power;
7293db86aabSstevel 
7303db86aabSstevel 	pci_ctrn = ddi_getprop(DDI_DEV_T_ANY, dip, DDI_PROP_CANSLEEP,
7313db86aabSstevel 	    "pci-control-reg-number", pci_control_reg_num);
7323db86aabSstevel 	pci_cfrn = ddi_getprop(DDI_DEV_T_ANY, dip, DDI_PROP_CANSLEEP,
7333db86aabSstevel 	    "pci-config-reg-number", pci_config_reg_num);
7343db86aabSstevel 
7353db86aabSstevel 	ddi_set_driver_private(dip, pcic_nexus);
7363db86aabSstevel 
7373db86aabSstevel 	/*
7383db86aabSstevel 	 * pcic->pc_irq is really the IPL level we want to run at
7393db86aabSstevel 	 * set the default values here and override from intr spec
7403db86aabSstevel 	 */
7413db86aabSstevel 	pcic->pc_irq = ddi_getprop(DDI_DEV_T_ANY, dip, DDI_PROP_CANSLEEP,
74219397407SSherry Moore 	    "interrupt-priorities", -1);
7433db86aabSstevel 
7443db86aabSstevel 	if (pcic->pc_irq == -1) {
7453db86aabSstevel 		int			actual;
7463db86aabSstevel 		uint_t			pri;
7473db86aabSstevel 		ddi_intr_handle_t	hdl;
7483db86aabSstevel 
7493db86aabSstevel 		/* see if intrspec tells us different */
7503db86aabSstevel 		if (ddi_intr_alloc(dip, &hdl, DDI_INTR_TYPE_FIXED,
7513db86aabSstevel 		    0, 1, &actual, DDI_INTR_ALLOC_NORMAL) == DDI_SUCCESS) {
7523db86aabSstevel 			if (ddi_intr_get_pri(hdl, &pri) == DDI_SUCCESS)
7533db86aabSstevel 				pcic->pc_irq = pri;
7543db86aabSstevel 			else
7553db86aabSstevel 				pcic->pc_irq = LOCK_LEVEL + 1;
7563db86aabSstevel 			(void) ddi_intr_free(hdl);
7573db86aabSstevel 		}
7583db86aabSstevel 	}
7593db86aabSstevel 	pcic_nexus->an_ipl = pcic->pc_irq;
7603db86aabSstevel 
7613db86aabSstevel 	/*
7623db86aabSstevel 	 * Check our parent bus type. We do different things based on which
7633db86aabSstevel 	 * bus we're on.
7643db86aabSstevel 	 */
7653db86aabSstevel 	if (ddi_prop_op(DDI_DEV_T_ANY, ddi_get_parent(dip),
76619397407SSherry Moore 	    PROP_LEN_AND_VAL_BUF, DDI_PROP_CANSLEEP,
76719397407SSherry Moore 	    "device_type", (caddr_t)&bus_type[0], &len) !=
76819397407SSherry Moore 	    DDI_PROP_SUCCESS) {
7693db86aabSstevel 		if (ddi_prop_op(DDI_DEV_T_ANY, ddi_get_parent(dip),
77019397407SSherry Moore 		    PROP_LEN_AND_VAL_BUF, DDI_PROP_CANSLEEP,
77119397407SSherry Moore 		    "bus-type", (caddr_t)&bus_type[0], &len) !=
77219397407SSherry Moore 		    DDI_PROP_SUCCESS) {
7733db86aabSstevel 
7743db86aabSstevel 			cmn_err(CE_CONT,
77519397407SSherry Moore 			    "pcic%d: can't find parent bus type\n",
77619397407SSherry Moore 			    ddi_get_instance(dip));
7773db86aabSstevel 
7783db86aabSstevel 			kmem_free(pcic, sizeof (pcicdev_t));
779b8a60a54Srw 			ddi_soft_state_free(pcic_soft_state_p,
78019397407SSherry Moore 			    ddi_get_instance(dip));
7813db86aabSstevel 			return (DDI_FAILURE);
7823db86aabSstevel 		}
7833db86aabSstevel 	} /* ddi_prop_op("device_type") */
7843db86aabSstevel 
7858134ee03Srw 	if (strcmp(bus_type, DEVI_PCI_NEXNAME) == 0 ||
78619397407SSherry Moore 	    strcmp(bus_type, DEVI_PCIEX_NEXNAME) == 0) {
7873db86aabSstevel 		pcic->pc_flags = PCF_PCIBUS;
7883db86aabSstevel 	} else {
789b8a60a54Srw 		cmn_err(CE_WARN, "!pcic%d: non-pci mode (%s) not supported, "
79019397407SSherry Moore 		    "set BIOS to yenta mode if applicable\n",
79119397407SSherry Moore 		    ddi_get_instance(dip), bus_type);
7923db86aabSstevel 		kmem_free(pcic, sizeof (pcicdev_t));
793b8a60a54Srw 		ddi_soft_state_free(pcic_soft_state_p,
79419397407SSherry Moore 		    ddi_get_instance(dip));
7953db86aabSstevel 		return (DDI_FAILURE);
7963db86aabSstevel 	}
7973db86aabSstevel 
7983db86aabSstevel 	if ((pcic->bus_speed = ddi_getprop(DDI_DEV_T_ANY, ddi_get_parent(dip),
79919397407SSherry Moore 	    DDI_PROP_CANSLEEP,
80019397407SSherry Moore 	    "clock-frequency", 0)) == 0) {
8013db86aabSstevel 		if (pcic->pc_flags & PCF_PCIBUS)
8023db86aabSstevel 			pcic->bus_speed = PCIC_PCI_DEF_SYSCLK;
8033db86aabSstevel 		else
8043db86aabSstevel 			pcic->bus_speed = PCIC_ISA_DEF_SYSCLK;
8053db86aabSstevel 	} else {
8063db86aabSstevel 		/*
8073db86aabSstevel 		 * OBP can declare the speed in Hz...
8083db86aabSstevel 		 */
8093db86aabSstevel 		if (pcic->bus_speed > 1000000)
8103db86aabSstevel 			pcic->bus_speed /= 1000000;
8113db86aabSstevel 	} /* ddi_prop_op("clock-frequency") */
8123db86aabSstevel 
8133db86aabSstevel 	pcic->pc_io_type = PCIC_IO_TYPE_82365SL; /* default mode */
8143db86aabSstevel 
8153db86aabSstevel #ifdef	PCIC_DEBUG
8163db86aabSstevel 	if (pcic_debug) {
8173db86aabSstevel 		cmn_err(CE_CONT,
81819397407SSherry Moore 		    "pcic%d: parent bus type = [%s], speed = %d MHz\n",
81919397407SSherry Moore 		    ddi_get_instance(dip),
82019397407SSherry Moore 		    bus_type, pcic->bus_speed);
8213db86aabSstevel 	}
8223db86aabSstevel #endif
8233db86aabSstevel 
8243db86aabSstevel 	/*
8253db86aabSstevel 	 * The reg properties on a PCI node are different than those
8263db86aabSstevel 	 *	on a non-PCI node. Handle that difference here.
8273db86aabSstevel 	 *	If it turns out to be a CardBus chip, we have even more
8283db86aabSstevel 	 *	differences.
8293db86aabSstevel 	 */
8303db86aabSstevel 	if (pcic->pc_flags & PCF_PCIBUS) {
8313db86aabSstevel 		int class_code;
83286ef0a63SRichard Lowe #if defined(__x86)
8333db86aabSstevel 		pcic->pc_base = 0x1000000;
8343db86aabSstevel 		pcic->pc_bound = (uint32_t)~0;
8353db86aabSstevel 		pcic->pc_iobase = 0x1000;
8363db86aabSstevel 		pcic->pc_iobound = 0xefff;
8373db86aabSstevel #elif defined(__sparc)
8383db86aabSstevel 		pcic->pc_base = 0x0;
8393db86aabSstevel 		pcic->pc_bound = (uint32_t)~0;
8403db86aabSstevel 		pcic->pc_iobase = 0x00000;
8413db86aabSstevel 		pcic->pc_iobound = 0xffff;
8423db86aabSstevel #endif
8433db86aabSstevel 
8443db86aabSstevel 		/* usually need to get at config space so map first */
8453db86aabSstevel 		attr.devacc_attr_version = DDI_DEVICE_ATTR_V0;
8463db86aabSstevel 		attr.devacc_attr_endian_flags = DDI_STRUCTURE_LE_ACC;
8473db86aabSstevel 		attr.devacc_attr_dataorder = DDI_STRICTORDER_ACC;
8483db86aabSstevel 
8493db86aabSstevel 		if (ddi_regs_map_setup(dip, pci_cfrn,
85019397407SSherry Moore 		    (caddr_t *)&pcic->cfgaddr,
85119397407SSherry Moore 		    PCIC_PCI_CONFIG_REG_OFFSET,
85219397407SSherry Moore 		    PCIC_PCI_CONFIG_REG_LENGTH,
85319397407SSherry Moore 		    &attr,
85419397407SSherry Moore 		    &pcic->cfg_handle) !=
8553db86aabSstevel 		    DDI_SUCCESS) {
8563db86aabSstevel 			cmn_err(CE_CONT,
85719397407SSherry Moore 			    "pcic%d: unable to map config space"
85819397407SSherry Moore 			    "regs\n",
85919397407SSherry Moore 			    ddi_get_instance(dip));
8603db86aabSstevel 
8613db86aabSstevel 			kmem_free(pcic, sizeof (pcicdev_t));
8623db86aabSstevel 			return (DDI_FAILURE);
8633db86aabSstevel 		} /* ddi_regs_map_setup */
8643db86aabSstevel 
8653db86aabSstevel 		class_code = ddi_getprop(DDI_DEV_T_ANY, dip,
86619397407SSherry Moore 		    DDI_PROP_CANSLEEP|DDI_PROP_DONTPASS,
86719397407SSherry Moore 		    "class-code", -1);
8683db86aabSstevel #ifdef  PCIC_DEBUG
8693db86aabSstevel 		if (pcic_debug) {
8703db86aabSstevel 			cmn_err(CE_CONT, "pcic_attach class_code=%x\n",
8713db86aabSstevel 			    class_code);
8723db86aabSstevel 		}
8733db86aabSstevel #endif
8743db86aabSstevel 
8753db86aabSstevel 		switch (class_code) {
8763db86aabSstevel 		case PCIC_PCI_CARDBUS:
8773db86aabSstevel 			pcic->pc_flags |= PCF_CARDBUS;
8783db86aabSstevel 			pcic->pc_io_type = PCIC_IO_TYPE_YENTA;
8793db86aabSstevel 			/*
8803db86aabSstevel 			 * Get access to the adapter registers on the
8813db86aabSstevel 			 * PCI bus.  A 4K memory page
8823db86aabSstevel 			 */
8833db86aabSstevel #if defined(PCIC_DEBUG)
8843db86aabSstevel 			pcic_err(dip, 8, "Is Cardbus device\n");
8853db86aabSstevel 			if (pcic_debug) {
8863db86aabSstevel 				int nr;
8873db86aabSstevel 				long rs;
8883db86aabSstevel 				(void) ddi_dev_nregs(dip, &nr);
8893db86aabSstevel 				pcic_err(dip, 9, "\tdev, cfgaddr 0x%p,"
8903db86aabSstevel 				    "cfghndl 0x%p nregs %d",
8913db86aabSstevel 				    (void *)pcic->cfgaddr,
8923db86aabSstevel 				    (void *)pcic->cfg_handle, nr);
8933db86aabSstevel 
8943db86aabSstevel 				(void) ddi_dev_regsize(dip,
8953db86aabSstevel 				    PCIC_PCI_CONTROL_REG_NUM, &rs);
8963db86aabSstevel 
8973db86aabSstevel 				pcic_err(dip, 9, "\tsize of reg %d is 0x%x\n",
8983db86aabSstevel 				    PCIC_PCI_CONTROL_REG_NUM, (int)rs);
8993db86aabSstevel 			}
9003db86aabSstevel #endif
9013db86aabSstevel 			attr.devacc_attr_version = DDI_DEVICE_ATTR_V0;
9023db86aabSstevel 			attr.devacc_attr_endian_flags = DDI_STRUCTURE_LE_ACC;
9033db86aabSstevel 			attr.devacc_attr_dataorder = DDI_STRICTORDER_ACC;
9043db86aabSstevel 
9053db86aabSstevel 			if (ddi_regs_map_setup(dip, pci_ctrn,
90619397407SSherry Moore 			    (caddr_t *)&pcic->ioaddr,
90719397407SSherry Moore 			    PCIC_PCI_CONTROL_REG_OFFSET,
90819397407SSherry Moore 			    PCIC_CB_CONTROL_REG_LENGTH,
90919397407SSherry Moore 			    &attr, &pcic->handle) !=
9103db86aabSstevel 			    DDI_SUCCESS) {
9113db86aabSstevel 				cmn_err(CE_CONT,
91219397407SSherry Moore 				    "pcic%d: unable to map PCI regs\n",
91319397407SSherry Moore 				    ddi_get_instance(dip));
9143db86aabSstevel 				ddi_regs_map_free(&pcic->cfg_handle);
9153db86aabSstevel 				kmem_free(pcic, sizeof (pcicdev_t));
9163db86aabSstevel 				return (DDI_FAILURE);
9173db86aabSstevel 			} /* ddi_regs_map_setup */
9183db86aabSstevel 
9193db86aabSstevel 			/*
9203db86aabSstevel 			 * Find out the chip type - If we're on a PCI bus,
9213db86aabSstevel 			 *	the adapter has that information in the PCI
9223db86aabSstevel 			 *	config space.
9233db86aabSstevel 			 * Note that we call pcic_find_pci_type here since
9243db86aabSstevel 			 *	it needs a valid mapped pcic->handle to
9253db86aabSstevel 			 *	access some of the adapter registers in
9263db86aabSstevel 			 *	some cases.
9273db86aabSstevel 			 */
9283db86aabSstevel 			if (pcic_find_pci_type(pcic) != DDI_SUCCESS) {
9293db86aabSstevel 				ddi_regs_map_free(&pcic->handle);
9303db86aabSstevel 				ddi_regs_map_free(&pcic->cfg_handle);
9313db86aabSstevel 				kmem_free(pcic, sizeof (pcicdev_t));
9323db86aabSstevel 				cmn_err(CE_WARN, "pcic: %s: unsupported "
93319397407SSherry Moore 				    "bridge\n", ddi_get_name_addr(dip));
9343db86aabSstevel 				return (DDI_FAILURE);
9353db86aabSstevel 			}
9363db86aabSstevel 			break;
9373db86aabSstevel 
9383db86aabSstevel 		default:
9393db86aabSstevel 		case PCIC_PCI_PCMCIA:
9403db86aabSstevel 			/*
9413db86aabSstevel 			 * Get access to the adapter IO registers on the
9423db86aabSstevel 			 * PCI bus config space.
9433db86aabSstevel 			 */
9443db86aabSstevel 			attr.devacc_attr_version = DDI_DEVICE_ATTR_V0;
9453db86aabSstevel 			attr.devacc_attr_endian_flags = DDI_STRUCTURE_LE_ACC;
9463db86aabSstevel 			attr.devacc_attr_dataorder = DDI_STRICTORDER_ACC;
9473db86aabSstevel 
9483db86aabSstevel 			/*
9493db86aabSstevel 			 * We need a default mapping to the adapter's IO
9503db86aabSstevel 			 *	control register space. For most adapters
9513db86aabSstevel 			 *	that are of class PCIC_PCI_PCMCIA (or of
9523db86aabSstevel 			 *	a default class) the control registers
9533db86aabSstevel 			 *	will be using the 82365-type control/data
9543db86aabSstevel 			 *	format.
9553db86aabSstevel 			 */
9563db86aabSstevel 			if (ddi_regs_map_setup(dip, pci_ctrn,
95719397407SSherry Moore 			    (caddr_t *)&pcic->ioaddr,
95819397407SSherry Moore 			    PCIC_PCI_CONTROL_REG_OFFSET,
95919397407SSherry Moore 			    PCIC_PCI_CONTROL_REG_LENGTH,
96019397407SSherry Moore 			    &attr,
96119397407SSherry Moore 			    &pcic->handle) != DDI_SUCCESS) {
9623db86aabSstevel 				cmn_err(CE_CONT,
96319397407SSherry Moore 				    "pcic%d: unable to map PCI regs\n",
96419397407SSherry Moore 				    ddi_get_instance(dip));
9653db86aabSstevel 				ddi_regs_map_free(&pcic->cfg_handle);
9663db86aabSstevel 				kmem_free(pcic, sizeof (pcicdev_t));
9673db86aabSstevel 				return (DDI_FAILURE);
9683db86aabSstevel 			} /* ddi_regs_map_setup */
9693db86aabSstevel 
9703db86aabSstevel 			/*
9713db86aabSstevel 			 * Find out the chip type - If we're on a PCI bus,
9723db86aabSstevel 			 *	the adapter has that information in the PCI
9733db86aabSstevel 			 *	config space.
9743db86aabSstevel 			 * Note that we call pcic_find_pci_type here since
9753db86aabSstevel 			 *	it needs a valid mapped pcic->handle to
9763db86aabSstevel 			 *	access some of the adapter registers in
9773db86aabSstevel 			 *	some cases.
9783db86aabSstevel 			 */
9793db86aabSstevel 			if (pcic_find_pci_type(pcic) != DDI_SUCCESS) {
9803db86aabSstevel 				ddi_regs_map_free(&pcic->handle);
9813db86aabSstevel 				ddi_regs_map_free(&pcic->cfg_handle);
9823db86aabSstevel 				kmem_free(pcic, sizeof (pcicdev_t));
9833db86aabSstevel 				cmn_err(CE_WARN, "pcic: %s: unsupported "
98419397407SSherry Moore 				    "bridge\n",
98519397407SSherry Moore 				    ddi_get_name_addr(dip));
9863db86aabSstevel 				return (DDI_FAILURE);
9873db86aabSstevel 			}
9883db86aabSstevel 
9893db86aabSstevel 			/*
9903db86aabSstevel 			 * Some PCI-PCMCIA(R2) adapters are Yenta-compliant
9913db86aabSstevel 			 *	for extended registers even though they are
9923db86aabSstevel 			 *	not CardBus adapters. For those adapters,
9933db86aabSstevel 			 *	re-map pcic->handle to be large enough to
9943db86aabSstevel 			 *	encompass the Yenta registers.
9953db86aabSstevel 			 */
9963db86aabSstevel 			switch (pcic->pc_type) {
99719397407SSherry Moore 				case PCIC_TI_PCI1031:
9983db86aabSstevel 				ddi_regs_map_free(&pcic->handle);
9993db86aabSstevel 
10003db86aabSstevel 				if (ddi_regs_map_setup(dip,
100119397407SSherry Moore 				    PCIC_PCI_CONTROL_REG_NUM,
100219397407SSherry Moore 				    (caddr_t *)&pcic->ioaddr,
100319397407SSherry Moore 				    PCIC_PCI_CONTROL_REG_OFFSET,
100419397407SSherry Moore 				    PCIC_CB_CONTROL_REG_LENGTH,
100519397407SSherry Moore 				    &attr,
100619397407SSherry Moore 				    &pcic->handle) != DDI_SUCCESS) {
10073db86aabSstevel 					cmn_err(CE_CONT,
100819397407SSherry Moore 					    "pcic%d: unable to map "
100919397407SSherry Moore 					"PCI regs\n",
101019397407SSherry Moore 					    ddi_get_instance(dip));
10113db86aabSstevel 					ddi_regs_map_free(&pcic->cfg_handle);
10123db86aabSstevel 					kmem_free(pcic, sizeof (pcicdev_t));
10133db86aabSstevel 					return (DDI_FAILURE);
10143db86aabSstevel 				} /* ddi_regs_map_setup */
10153db86aabSstevel 				break;
101619397407SSherry Moore 				default:
10173db86aabSstevel 				break;
10183db86aabSstevel 			} /* switch (pcic->pc_type) */
10193db86aabSstevel 			break;
10203db86aabSstevel 		} /* switch (class_code) */
10213db86aabSstevel 	} else {
10223db86aabSstevel 		/*
10233db86aabSstevel 		 * We're not on a PCI bus, so assume an ISA bus type
10243db86aabSstevel 		 * register property. Get access to the adapter IO
10253db86aabSstevel 		 * registers on a non-PCI bus.
10263db86aabSstevel 		 */
10273db86aabSstevel 		attr.devacc_attr_version = DDI_DEVICE_ATTR_V0;
10283db86aabSstevel 		attr.devacc_attr_endian_flags = DDI_NEVERSWAP_ACC;
10293db86aabSstevel 		attr.devacc_attr_dataorder = DDI_STRICTORDER_ACC;
10303db86aabSstevel 		pcic->mem_reg_num = PCIC_ISA_MEM_REG_NUM;
10313db86aabSstevel 		pcic->io_reg_num = PCIC_ISA_IO_REG_NUM;
10323db86aabSstevel 
10333db86aabSstevel 		if (ddi_regs_map_setup(dip, PCIC_ISA_CONTROL_REG_NUM,
103419397407SSherry Moore 		    (caddr_t *)&pcic->ioaddr,
103519397407SSherry Moore 		    PCIC_ISA_CONTROL_REG_OFFSET,
103619397407SSherry Moore 		    PCIC_ISA_CONTROL_REG_LENGTH,
103719397407SSherry Moore 		    &attr,
103819397407SSherry Moore 		    &pcic->handle) != DDI_SUCCESS) {
10393db86aabSstevel 			cmn_err(CE_CONT,
104019397407SSherry Moore 			    "pcic%d: unable to map ISA registers\n",
104119397407SSherry Moore 			    ddi_get_instance(dip));
10423db86aabSstevel 
10433db86aabSstevel 			kmem_free(pcic, sizeof (pcicdev_t));
10443db86aabSstevel 			return (DDI_FAILURE);
10453db86aabSstevel 		} /* ddi_regs_map_setup */
10463db86aabSstevel 
10473db86aabSstevel 		/* ISA bus is limited to 24-bits, but not first 640K */
10483db86aabSstevel 		pcic->pc_base = 0xd0000;
10493db86aabSstevel 		pcic->pc_bound = (uint32_t)~0;
10503db86aabSstevel 		pcic->pc_iobase = 0x1000;
10513db86aabSstevel 		pcic->pc_iobound = 0xefff;
10523db86aabSstevel 	} /* !PCF_PCIBUS */
10533db86aabSstevel 
10543db86aabSstevel #ifdef  PCIC_DEBUG
10553db86aabSstevel 	if (pcic_debug) {
10563db86aabSstevel 		cmn_err(CE_CONT, "pcic_attach pc_flags=%x pc_type=%x\n",
10573db86aabSstevel 		    pcic->pc_flags, pcic->pc_type);
10583db86aabSstevel 	}
10593db86aabSstevel #endif
10603db86aabSstevel 
10613db86aabSstevel 	/*
10623db86aabSstevel 	 * Setup various adapter registers for the PCI case. For the
10633db86aabSstevel 	 * non-PCI case, find out the chip type.
10643db86aabSstevel 	 */
10653db86aabSstevel 	if (pcic->pc_flags & PCF_PCIBUS) {
10663db86aabSstevel 		int iline;
10673db86aabSstevel #if defined(__sparc)
10683db86aabSstevel 		iline = 0;
10693db86aabSstevel #else
10703db86aabSstevel 		iline = cardbus_validate_iline(dip, pcic->cfg_handle);
10713db86aabSstevel #endif
10723db86aabSstevel 
10733db86aabSstevel 		/* set flags and socket counts based on chip type */
10743db86aabSstevel 		switch (pcic->pc_type) {
10753db86aabSstevel 			uint32_t cfg;
10763db86aabSstevel 		case PCIC_INTEL_i82092:
10773db86aabSstevel 			cfg = ddi_get8(pcic->cfg_handle,
107819397407SSherry Moore 			    pcic->cfgaddr + PCIC_82092_PCICON);
10793db86aabSstevel 			/* we can only support 4 Socket version */
10803db86aabSstevel 			if (cfg & PCIC_82092_4_SOCKETS) {
108119397407SSherry Moore 				pcic->pc_numsockets = 4;
108219397407SSherry Moore 				pcic->pc_type = PCIC_INTEL_i82092;
108319397407SSherry Moore 				if (iline != 0xFF)
108419397407SSherry Moore 					pcic->pc_intr_mode =
108519397407SSherry Moore 					    PCIC_INTR_MODE_PCI_1;
108619397407SSherry Moore 				else
108719397407SSherry Moore 					pcic->pc_intr_mode = PCIC_INTR_MODE_ISA;
10883db86aabSstevel 			} else {
108919397407SSherry Moore 				cmn_err(CE_CONT,
10903db86aabSstevel 				    "pcic%d: Intel 82092 adapter "
10913db86aabSstevel 				    "in unsupported configuration: 0x%x",
10923db86aabSstevel 				    ddi_get_instance(pcic->dip), cfg);
109319397407SSherry Moore 				pcic->pc_numsockets = 0;
10943db86aabSstevel 			} /* PCIC_82092_4_SOCKETS */
10953db86aabSstevel 			break;
10963db86aabSstevel 		case PCIC_CL_PD6730:
10973db86aabSstevel 		case PCIC_CL_PD6729:
10983db86aabSstevel 			pcic->pc_intr_mode = PCIC_INTR_MODE_PCI_1;
10993db86aabSstevel 			cfg = ddi_getprop(DDI_DEV_T_ANY, dip,
110019397407SSherry Moore 			    DDI_PROP_CANSLEEP,
110119397407SSherry Moore 			    "interrupts", 0);
11023db86aabSstevel 			/* if not interrupt pin then must use ISA style IRQs */
11033db86aabSstevel 			if (cfg == 0 || iline == 0xFF)
11043db86aabSstevel 				pcic->pc_intr_mode = PCIC_INTR_MODE_ISA;
11053db86aabSstevel 			else {
11063db86aabSstevel 				/*
11073db86aabSstevel 				 * we have the option to use PCI interrupts.
11083db86aabSstevel 				 * this might not be optimal but in some cases
11093db86aabSstevel 				 * is the only thing possible (sparc case).
11103db86aabSstevel 				 * we now deterine what is possible.
11113db86aabSstevel 				 */
11123db86aabSstevel 				pcic->pc_intr_mode = PCIC_INTR_MODE_PCI_1;
11133db86aabSstevel 			}
11143db86aabSstevel 			pcic->pc_numsockets = 2;
11153db86aabSstevel 			pcic->pc_flags |= PCF_IO_REMAP;
11163db86aabSstevel 			break;
11173db86aabSstevel 		case PCIC_TI_PCI1031:
11183db86aabSstevel 			/* this chip doesn't do CardBus but looks like one */
11193db86aabSstevel 			pcic->pc_flags &= ~PCF_CARDBUS;
11203db86aabSstevel 			/* FALLTHROUGH */
11213db86aabSstevel 		default:
11223db86aabSstevel 			pcic->pc_flags |= PCF_IO_REMAP;
11233db86aabSstevel 			/* FALLTHROUGH */
11243db86aabSstevel 			/* indicate feature even if not supported */
11253db86aabSstevel 			pcic->pc_flags |= PCF_DMA | PCF_ZV;
11263db86aabSstevel 			/* Not sure if these apply to all these chips */
11273db86aabSstevel 			pcic->pc_flags |= (PCF_VPPX|PCF_33VCAP);
11283db86aabSstevel 			pcic->pc_flags |= pcic_use_cbpwrctl;
11293db86aabSstevel 
11303db86aabSstevel 			pcic->pc_numsockets = 1; /* one per function */
11313db86aabSstevel 			if (iline != 0xFF) {
11323db86aabSstevel 				uint8_t cfg;
11333db86aabSstevel 				pcic->pc_intr_mode = PCIC_INTR_MODE_PCI_1;
11343db86aabSstevel 
11353db86aabSstevel 				cfg = ddi_get8(pcic->cfg_handle,
113619397407SSherry Moore 				    (pcic->cfgaddr + PCIC_BRIDGE_CTL_REG));
11373db86aabSstevel 				cfg &= (~PCIC_FUN_INT_MOD_ISA);
11383db86aabSstevel 				ddi_put8(pcic->cfg_handle, (pcic->cfgaddr +
113919397407SSherry Moore 				    PCIC_BRIDGE_CTL_REG), cfg);
11403db86aabSstevel 			}
11413db86aabSstevel 			else
11423db86aabSstevel 				pcic->pc_intr_mode = PCIC_INTR_MODE_ISA;
11433db86aabSstevel 			pcic->pc_io_type = PCIC_IOTYPE_YENTA;
11443db86aabSstevel 			break;
11453db86aabSstevel 		}
11463db86aabSstevel 	} else {
11473db86aabSstevel 		/*
11483db86aabSstevel 		 * We're not on a PCI bus so do some more
11493db86aabSstevel 		 *	checking for adapter type here.
11503db86aabSstevel 		 * For the non-PCI bus case:
11513db86aabSstevel 		 * It could be any one of a number of different chips
11523db86aabSstevel 		 * If we can't determine anything else, it is assumed
11533db86aabSstevel 		 * to be an Intel 82365SL.  The Cirrus Logic PD6710
11543db86aabSstevel 		 * has an extension register that provides unique
11553db86aabSstevel 		 * identification. Toshiba chip isn't detailed as yet.
11563db86aabSstevel 		 */
11573db86aabSstevel 
11583db86aabSstevel 		/* Init the CL id mode */
11593db86aabSstevel 		pcic_putb(pcic, 0, PCIC_CHIP_INFO, 0);
11603db86aabSstevel 		value = pcic_getb(pcic, 0, PCIC_CHIP_INFO);
11613db86aabSstevel 
11623db86aabSstevel 		/* default to Intel i82365SL and then refine */
11633db86aabSstevel 		pcic->pc_type = PCIC_I82365SL;
11643db86aabSstevel 		pcic->pc_chipname = PCIC_TYPE_I82365SL;
11653db86aabSstevel 		for (value = 0; pcic_ci_funcs[value] != NULL; value++) {
11663db86aabSstevel 			/* go until one succeeds or none left */
11673db86aabSstevel 			if (pcic_ci_funcs[value](pcic))
11683db86aabSstevel 				break;
11693db86aabSstevel 		}
11703db86aabSstevel 
11713db86aabSstevel 		/* any chip specific flags get set here */
11723db86aabSstevel 		switch (pcic->pc_type) {
11733db86aabSstevel 		case PCIC_CL_PD6722:
11743db86aabSstevel 			pcic->pc_flags |= PCF_DMA;
11753db86aabSstevel 		}
11763db86aabSstevel 
11773db86aabSstevel 		for (i = 0; i < PCIC_MAX_SOCKETS; i++) {
11783db86aabSstevel 			/*
11793db86aabSstevel 			 * look for total number of sockets.
11803db86aabSstevel 			 * basically check each possible socket for
11813db86aabSstevel 			 * presence like in probe
11823db86aabSstevel 			 */
11833db86aabSstevel 
11843db86aabSstevel 			/* turn all windows off */
11853db86aabSstevel 			pcic_putb(pcic, i, PCIC_MAPPING_ENABLE, 0);
11863db86aabSstevel 			value = pcic_getb(pcic, i, PCIC_MAPPING_ENABLE);
11873db86aabSstevel 
11883db86aabSstevel 			/*
11893db86aabSstevel 			 * if a zero is read back, then this socket
11903db86aabSstevel 			 * might be present. It would be except for
11913db86aabSstevel 			 * some systems that map the secondary PCIC
11923db86aabSstevel 			 * chip space back to the first.
11933db86aabSstevel 			 */
11943db86aabSstevel 			if (value != 0) {
11953db86aabSstevel 				/* definitely not so skip */
11963db86aabSstevel 				/* note: this is for Compaq support */
11973db86aabSstevel 				continue;
11983db86aabSstevel 			}
11993db86aabSstevel 
12003db86aabSstevel 			/* further tests */
12013db86aabSstevel 			value = pcic_getb(pcic, i, PCIC_CHIP_REVISION) &
120219397407SSherry Moore 			    PCIC_REV_MASK;
12033db86aabSstevel 			if (!(value >= PCIC_REV_LEVEL_LOW &&
120419397407SSherry Moore 			    value <= PCIC_REV_LEVEL_HI))
12053db86aabSstevel 				break;
12063db86aabSstevel 
12073db86aabSstevel 			pcic_putb(pcic, i, PCIC_SYSMEM_0_STARTLOW, 0xaa);
12083db86aabSstevel 			pcic_putb(pcic, i, PCIC_SYSMEM_1_STARTLOW, 0x55);
12093db86aabSstevel 			value = pcic_getb(pcic, i, PCIC_SYSMEM_0_STARTLOW);
12103db86aabSstevel 
12113db86aabSstevel 			j = pcic_getb(pcic, i, PCIC_SYSMEM_1_STARTLOW);
12123db86aabSstevel 			if (value != 0xaa || j != 0x55)
12133db86aabSstevel 				break;
12143db86aabSstevel 
12153db86aabSstevel 			/*
12163db86aabSstevel 			 * at this point we know if we have hardware
12173db86aabSstevel 			 * of some type and not just the bus holding
12183db86aabSstevel 			 * a pattern for us. We still have to determine
12193db86aabSstevel 			 * the case where more than 2 sockets are
12203db86aabSstevel 			 * really the same due to peculiar mappings of
12213db86aabSstevel 			 * hardware.
12223db86aabSstevel 			 */
12233db86aabSstevel 			j = pcic->pc_numsockets++;
12243db86aabSstevel 			pcic->pc_sockets[j].pcs_flags = 0;
12253db86aabSstevel 			pcic->pc_sockets[j].pcs_io = pcic->ioaddr;
12263db86aabSstevel 			pcic->pc_sockets[j].pcs_socket = i;
12273db86aabSstevel 
12283db86aabSstevel 			/* put PC Card into RESET, just in case */
12293db86aabSstevel 			value = pcic_getb(pcic, i, PCIC_INTERRUPT);
12303db86aabSstevel 			pcic_putb(pcic, i, PCIC_INTERRUPT,
123119397407SSherry Moore 			    value & ~PCIC_RESET);
12323db86aabSstevel 		}
12333db86aabSstevel 
12343db86aabSstevel #if defined(PCIC_DEBUG)
12353db86aabSstevel 		if (pcic_debug)
12363db86aabSstevel 			cmn_err(CE_CONT, "num sockets = %d\n",
123719397407SSherry Moore 			    pcic->pc_numsockets);
12383db86aabSstevel #endif
12393db86aabSstevel 		if (pcic->pc_numsockets == 0) {
12403db86aabSstevel 			ddi_regs_map_free(&pcic->handle);
12413db86aabSstevel 			kmem_free(pcic, sizeof (pcicdev_t));
12423db86aabSstevel 			return (DDI_FAILURE);
12433db86aabSstevel 		}
12443db86aabSstevel 
12453db86aabSstevel 		/*
12463db86aabSstevel 		 * need to think this through again in light of
12473db86aabSstevel 		 * Compaq not following the model that all the
12483db86aabSstevel 		 * chip vendors recommend.  IBM 755 seems to be
12493db86aabSstevel 		 * afflicted as well.  Basically, if the vendor
12503db86aabSstevel 		 * wired things wrong, socket 0 responds for socket 2
12513db86aabSstevel 		 * accesses, etc.
12523db86aabSstevel 		 */
12533db86aabSstevel 		if (pcic->pc_numsockets > 2) {
12543db86aabSstevel 			int count = pcic->pc_numsockets / 4;
12553db86aabSstevel 			for (i = 0; i < count; i++) {
12563db86aabSstevel 				/* put pattern into socket 0 */
12573db86aabSstevel 				pcic_putb(pcic, i,
125819397407SSherry Moore 				    PCIC_SYSMEM_0_STARTLOW, 0x11);
12593db86aabSstevel 
12603db86aabSstevel 				/* put pattern into socket 2 */
12613db86aabSstevel 				pcic_putb(pcic, i + 2,
126219397407SSherry Moore 				    PCIC_SYSMEM_0_STARTLOW, 0x33);
12633db86aabSstevel 
12643db86aabSstevel 				/* read back socket 0 */
12653db86aabSstevel 				value = pcic_getb(pcic, i,
126619397407SSherry Moore 				    PCIC_SYSMEM_0_STARTLOW);
12673db86aabSstevel 
12683db86aabSstevel 				/* read back chip 1 socket 0 */
12693db86aabSstevel 				j = pcic_getb(pcic, i + 2,
127019397407SSherry Moore 				    PCIC_SYSMEM_0_STARTLOW);
12713db86aabSstevel 				if (j == value) {
12723db86aabSstevel 					pcic->pc_numsockets -= 2;
12733db86aabSstevel 				}
12743db86aabSstevel 			}
12753db86aabSstevel 		}
12763db86aabSstevel 
12773db86aabSstevel 		smi = 0xff;	/* no more override */
12783db86aabSstevel 
12793db86aabSstevel 		if (ddi_getprop(DDI_DEV_T_NONE, dip,
128019397407SSherry Moore 		    DDI_PROP_DONTPASS, "need-mult-irq",
128119397407SSherry Moore 		    0xffff) != 0xffff)
12823db86aabSstevel 			pcic->pc_flags |= PCF_MULT_IRQ;
12833db86aabSstevel 
12843db86aabSstevel 	} /* !PCF_PCIBUS */
12853db86aabSstevel 
12863db86aabSstevel 	/*
12873db86aabSstevel 	 * some platforms/busses need to have resources setup
12883db86aabSstevel 	 * this is temporary until a real resource allocator is
12893db86aabSstevel 	 * implemented.
12903db86aabSstevel 	 */
12913db86aabSstevel 
12923db86aabSstevel 	pcic_init_assigned(dip);
12933db86aabSstevel 
12943db86aabSstevel 	typename = pcic->pc_chipname;
12953db86aabSstevel 
12963db86aabSstevel #ifdef	PCIC_DEBUG
12973db86aabSstevel 	if (pcic_debug) {
12983db86aabSstevel 		int nregs, nintrs;
12993db86aabSstevel 
13003db86aabSstevel 		if (ddi_dev_nregs(dip, &nregs) != DDI_SUCCESS)
13013db86aabSstevel 			nregs = 0;
13023db86aabSstevel 
13033db86aabSstevel 		if (ddi_dev_nintrs(dip, &nintrs) != DDI_SUCCESS)
13043db86aabSstevel 			nintrs = 0;
13053db86aabSstevel 
13063db86aabSstevel 		cmn_err(CE_CONT,
130719397407SSherry Moore 		    "pcic%d: %d register sets, %d interrupts\n",
130819397407SSherry Moore 		    ddi_get_instance(dip), nregs, nintrs);
13093db86aabSstevel 
13103db86aabSstevel 		nintrs = 0;
13113db86aabSstevel 		while (nregs--) {
13123db86aabSstevel 			off_t size;
13133db86aabSstevel 
13143db86aabSstevel 			if (ddi_dev_regsize(dip, nintrs, &size) ==
13153db86aabSstevel 			    DDI_SUCCESS) {
13163db86aabSstevel 				cmn_err(CE_CONT,
131719397407SSherry Moore 				    "\tregnum %d size %ld (0x%lx)"
131819397407SSherry Moore 				    "bytes",
131919397407SSherry Moore 				    nintrs, size, size);
13203db86aabSstevel 				if (nintrs ==
13213db86aabSstevel 				    (pcic->pc_io_type == PCIC_IO_TYPE_82365SL ?
13223db86aabSstevel 				    PCIC_ISA_CONTROL_REG_NUM :
13233db86aabSstevel 				    PCIC_PCI_CONTROL_REG_NUM))
13243db86aabSstevel 					cmn_err(CE_CONT,
132519397407SSherry Moore 					    " mapped at: 0x%p\n",
132619397407SSherry Moore 					    (void *)pcic->ioaddr);
13273db86aabSstevel 				else
13283db86aabSstevel 					cmn_err(CE_CONT, "\n");
13293db86aabSstevel 			} else {
13303db86aabSstevel 				cmn_err(CE_CONT,
133119397407SSherry Moore 				    "\tddi_dev_regsize(rnumber"
133219397407SSherry Moore 				    "= %d) returns DDI_FAILURE\n",
133319397407SSherry Moore 				    nintrs);
13343db86aabSstevel 			}
13353db86aabSstevel 			nintrs++;
13363db86aabSstevel 		} /* while */
13373db86aabSstevel 	} /* if (pcic_debug) */
13383db86aabSstevel #endif
13393db86aabSstevel 
13403db86aabSstevel 	cv_init(&pcic->pm_cv, NULL, CV_DRIVER, NULL);
13413db86aabSstevel 
13423db86aabSstevel 	if (!ddi_getprop(DDI_DEV_T_NONE, dip, DDI_PROP_DONTPASS,
134319397407SSherry Moore 	    "disable-audio", 0))
13443db86aabSstevel 		pcic->pc_flags |= PCF_AUDIO;
13453db86aabSstevel 
13463db86aabSstevel 	if (ddi_getprop(DDI_DEV_T_ANY, dip, DDI_PROP_CANSLEEP,
13473db86aabSstevel 	    "disable-cardbus", 0))
13483db86aabSstevel 		pcic->pc_flags &= ~PCF_CARDBUS;
13493db86aabSstevel 
13503db86aabSstevel 	(void) ddi_prop_update_string(DDI_DEV_T_NONE, dip, PCICPROP_CTL,
13513db86aabSstevel 	    typename);
13523db86aabSstevel 
13533db86aabSstevel 	/*
13543db86aabSstevel 	 * Init all socket SMI levels to 0 (no SMI)
13553db86aabSstevel 	 */
13563db86aabSstevel 	for (i = 0; i < PCIC_MAX_SOCKETS; i++) {
135719397407SSherry Moore 		pcic->pc_sockets[i].pcs_smi = 0;
135819397407SSherry Moore 		pcic->pc_sockets[i].pcs_debounce_id = 0;
135919397407SSherry Moore 		pcic->pc_sockets[i].pcs_pcic = pcic;
13603db86aabSstevel 	}
13613db86aabSstevel 	pcic->pc_lastreg = -1; /* just to make sure we are in sync */
13623db86aabSstevel 
13633db86aabSstevel 	/*
13643db86aabSstevel 	 * Setup the IRQ handler(s)
13653db86aabSstevel 	 */
13663db86aabSstevel 	switch (pcic->pc_intr_mode) {
13673db86aabSstevel 		int xx;
13683db86aabSstevel 	case PCIC_INTR_MODE_ISA:
13693db86aabSstevel 	/*
13703db86aabSstevel 	 * On a non-PCI bus, we just use whatever SMI IRQ level was
13713db86aabSstevel 	 *	specified above, and the IO IRQ levels are allocated
13723db86aabSstevel 	 *	dynamically.
13733db86aabSstevel 	 */
13743db86aabSstevel 		for (xx = 15, smi = 0; xx >= 0; xx--) {
13753db86aabSstevel 			if (PCIC_IRQ(xx) &
13763db86aabSstevel 			    PCIC_AVAIL_IRQS) {
13773db86aabSstevel 				smi = pcmcia_get_intr(dip, xx);
13783db86aabSstevel 				if (smi >= 0)
13793db86aabSstevel 					break;
13803db86aabSstevel 			}
13813db86aabSstevel 		}
13823db86aabSstevel #if defined(PCIC_DEBUG)
13833db86aabSstevel 		if (pcic_debug)
13843db86aabSstevel 			cmn_err(CE_NOTE, "\tselected IRQ %d as SMI\n", smi);
13853db86aabSstevel #endif
13863db86aabSstevel 		/* init to same so share is easy */
13873db86aabSstevel 		for (i = 0; i < pcic->pc_numsockets; i++)
13883db86aabSstevel 			pcic->pc_sockets[i].pcs_smi = smi;
13893db86aabSstevel 		/* any special handling of IRQ levels */
13903db86aabSstevel 		if (pcic->pc_flags & PCF_MULT_IRQ) {
13913db86aabSstevel 			for (i = 2; i < pcic->pc_numsockets; i++) {
13923db86aabSstevel 				if ((i & 1) == 0) {
13933db86aabSstevel 					int xx;
13943db86aabSstevel 					for (xx = 15, smi = 0; xx >= 0; xx--) {
13953db86aabSstevel 						if (PCIC_IRQ(xx) &
13963db86aabSstevel 						    PCIC_AVAIL_IRQS) {
13973db86aabSstevel 							smi =
13983db86aabSstevel 							    pcmcia_get_intr(dip,
139919397407SSherry Moore 							    xx);
14003db86aabSstevel 							if (smi >= 0)
14013db86aabSstevel 								break;
14023db86aabSstevel 						}
14033db86aabSstevel 					}
14043db86aabSstevel 				}
14053db86aabSstevel 				if (smi >= 0)
14063db86aabSstevel 					pcic->pc_sockets[i].pcs_smi = smi;
14073db86aabSstevel 			}
14083db86aabSstevel 		}
14093db86aabSstevel 		pcic->pc_intr_htblp = kmem_alloc(pcic->pc_numsockets *
14103db86aabSstevel 		    sizeof (ddi_intr_handle_t), KM_SLEEP);
14113db86aabSstevel 		for (i = 0, irqlevel = -1; i < pcic->pc_numsockets; i++) {
14123db86aabSstevel 			struct intrspec *ispecp;
14133db86aabSstevel 			struct ddi_parent_private_data *pdp;
14143db86aabSstevel 
14153db86aabSstevel 			if (irqlevel == pcic->pc_sockets[i].pcs_smi)
14163db86aabSstevel 				continue;
14173db86aabSstevel 			else {
14183db86aabSstevel 				irqlevel = pcic->pc_sockets[i].pcs_smi;
14193db86aabSstevel 			}
14203db86aabSstevel 			/*
14213db86aabSstevel 			 * now convert the allocated IRQ into an intrspec
14223db86aabSstevel 			 * and ask our parent to add it.  Don't use
14233db86aabSstevel 			 * the ddi_add_intr since we don't have a
14243db86aabSstevel 			 * default intrspec in all cases.
14253db86aabSstevel 			 *
14263db86aabSstevel 			 * note: this sort of violates DDI but we don't
14273db86aabSstevel 			 *	 get hardware intrspecs for many of the devices.
14283db86aabSstevel 			 *	 at the same time, we know how to allocate them
14293db86aabSstevel 			 *	 so we do the right thing.
14303db86aabSstevel 			 */
14313db86aabSstevel 			if (ddi_intr_alloc(dip, &pcic->pc_intr_htblp[i],
14323db86aabSstevel 			    DDI_INTR_TYPE_FIXED, 0, 1, &actual,
14333db86aabSstevel 			    DDI_INTR_ALLOC_NORMAL) != DDI_SUCCESS) {
14343db86aabSstevel 				cmn_err(CE_WARN, "%s: ddi_intr_alloc failed",
14353db86aabSstevel 				    ddi_get_name(dip));
14363db86aabSstevel 				goto isa_exit1;
14373db86aabSstevel 			}
14383db86aabSstevel 
14393db86aabSstevel 			/*
14403db86aabSstevel 			 * See earlier note:
14413db86aabSstevel 			 * Since some devices don't have 'intrspec'
14423db86aabSstevel 			 * we make one up in rootnex.
14433db86aabSstevel 			 *
14443db86aabSstevel 			 * However, it is not properly initialized as
14453db86aabSstevel 			 * the data it needs is present in this driver
14463db86aabSstevel 			 * and there is no interface to pass that up.
14473db86aabSstevel 			 * Specially 'irqlevel' is very important and
14483db86aabSstevel 			 * it is part of pcic struct.
14493db86aabSstevel 			 *
14503db86aabSstevel 			 * Set 'intrspec' up here; otherwise adding the
14513db86aabSstevel 			 * interrupt will fail.
14523db86aabSstevel 			 */
14533db86aabSstevel 			pdp = ddi_get_parent_data(dip);
14543db86aabSstevel 			ispecp = (struct intrspec *)&pdp->par_intr[0];
14553db86aabSstevel 			ispecp->intrspec_vec = irqlevel;
14563db86aabSstevel 			ispecp->intrspec_pri = pcic->pc_irq;
14573db86aabSstevel 
14583db86aabSstevel 			/* Stay compatible w/ PCMCIA */
14593db86aabSstevel 			pcic->pc_pri = (ddi_iblock_cookie_t)
14603db86aabSstevel 			    (uintptr_t)pcic->pc_irq;
14613db86aabSstevel 			pcic->pc_dcookie.idev_priority =
14623db86aabSstevel 			    (uintptr_t)pcic->pc_pri;
14633db86aabSstevel 			pcic->pc_dcookie.idev_vector = (ushort_t)irqlevel;
14643db86aabSstevel 
14653db86aabSstevel 			(void) ddi_intr_set_pri(pcic->pc_intr_htblp[i],
14663db86aabSstevel 			    pcic->pc_irq);
14673db86aabSstevel 
14683db86aabSstevel 			if (i == 0) {
14693db86aabSstevel 				mutex_init(&pcic->intr_lock, NULL, MUTEX_DRIVER,
14703db86aabSstevel 				    DDI_INTR_PRI(pcic->pc_irq));
14713db86aabSstevel 				mutex_init(&pcic->pc_lock, NULL, MUTEX_DRIVER,
14723db86aabSstevel 				    NULL);
14733db86aabSstevel 			}
14743db86aabSstevel 
14753db86aabSstevel 			if (ddi_intr_add_handler(pcic->pc_intr_htblp[i],
14763db86aabSstevel 			    pcic_intr, (caddr_t)pcic, NULL)) {
14773db86aabSstevel 				cmn_err(CE_WARN,
14783db86aabSstevel 				    "%s: ddi_intr_add_handler failed",
14793db86aabSstevel 				    ddi_get_name(dip));
14803db86aabSstevel 				goto isa_exit2;
14813db86aabSstevel 			}
14823db86aabSstevel 
14833db86aabSstevel 			if (ddi_intr_enable(pcic->pc_intr_htblp[i])) {
14843db86aabSstevel 				cmn_err(CE_WARN, "%s: ddi_intr_enable failed",
14853db86aabSstevel 				    ddi_get_name(dip));
14863db86aabSstevel 				for (j = i; j < 0; j--)
14873db86aabSstevel 					(void) ddi_intr_remove_handler(
14883db86aabSstevel 					    pcic->pc_intr_htblp[j]);
14893db86aabSstevel 				goto isa_exit2;
14903db86aabSstevel 			}
14913db86aabSstevel 		}
14923db86aabSstevel 		break;
14933db86aabSstevel 	case PCIC_INTR_MODE_PCI_1:
14943db86aabSstevel 	case PCIC_INTR_MODE_PCI:
14953db86aabSstevel 		/*
14963db86aabSstevel 		 * If we're on a PCI bus, we route all interrupts, both SMI
14973db86aabSstevel 		 * and IO interrupts, through a single interrupt line.
14983db86aabSstevel 		 * Assign the SMI IRQ level to the IO IRQ level here.
14993db86aabSstevel 		 */
15003db86aabSstevel 		pcic->pc_pci_intr_hdlp = kmem_alloc(sizeof (ddi_intr_handle_t),
15013db86aabSstevel 		    KM_SLEEP);
15023db86aabSstevel 		if (ddi_intr_alloc(dip, pcic->pc_pci_intr_hdlp,
15033db86aabSstevel 		    DDI_INTR_TYPE_FIXED, 0, 1, &actual,
15043db86aabSstevel 		    DDI_INTR_ALLOC_NORMAL) != DDI_SUCCESS)
15053db86aabSstevel 			goto pci_exit1;
15063db86aabSstevel 
15073db86aabSstevel 		if (ddi_intr_get_pri(pcic->pc_pci_intr_hdlp[0],
15083db86aabSstevel 		    &pri) != DDI_SUCCESS) {
15093db86aabSstevel 			(void) ddi_intr_free(pcic->pc_pci_intr_hdlp[0]);
15103db86aabSstevel 			goto pci_exit1;
15113db86aabSstevel 		}
15123db86aabSstevel 
15133db86aabSstevel 		pcic->pc_pri = (void *)(uintptr_t)pri;
15143db86aabSstevel 		mutex_init(&pcic->intr_lock, NULL, MUTEX_DRIVER, pcic->pc_pri);
15153db86aabSstevel 		mutex_init(&pcic->pc_lock, NULL, MUTEX_DRIVER, NULL);
15163db86aabSstevel 
15173db86aabSstevel 		if (ddi_intr_add_handler(pcic->pc_pci_intr_hdlp[0],
15183db86aabSstevel 		    pcic_intr, (caddr_t)pcic, NULL))
15193db86aabSstevel 			goto pci_exit2;
15203db86aabSstevel 
15213db86aabSstevel 		if (ddi_intr_enable(pcic->pc_pci_intr_hdlp[0])) {
15223db86aabSstevel 			(void) ddi_intr_remove_handler(
15233db86aabSstevel 			    pcic->pc_pci_intr_hdlp[0]);
15243db86aabSstevel 			goto pci_exit2;
15253db86aabSstevel 		}
15263db86aabSstevel 
15273db86aabSstevel 		/* Stay compatible w/ PCMCIA */
15283db86aabSstevel 		pcic->pc_dcookie.idev_priority = (ushort_t)pri;
15293db86aabSstevel 
15303db86aabSstevel 		/* init to same (PCI) so share is easy */
15313db86aabSstevel 		for (i = 0; i < pcic->pc_numsockets; i++)
15323db86aabSstevel 			pcic->pc_sockets[i].pcs_smi = 0xF; /* any valid */
15333db86aabSstevel 		break;
15343db86aabSstevel 	}
15353db86aabSstevel 
15363db86aabSstevel 	/*
15373db86aabSstevel 	 * Setup the adapter hardware to some reasonable defaults.
15383db86aabSstevel 	 */
15393db86aabSstevel 	mutex_enter(&pcic->pc_lock);
15403db86aabSstevel 	/* mark the driver state as attached */
15413db86aabSstevel 	pcic->pc_flags |= PCF_ATTACHED;
15423db86aabSstevel 	pcic_setup_adapter(pcic);
15433db86aabSstevel 
15443db86aabSstevel 	for (j = 0; j < pcic->pc_numsockets; j++)
15453db86aabSstevel 		if (ddi_intr_add_softint(dip,
15463db86aabSstevel 		    &pcic->pc_sockets[j].pcs_cd_softint_hdl,
15473db86aabSstevel 		    PCIC_SOFTINT_PRI_VAL, pcic_cd_softint,
15483db86aabSstevel 		    (caddr_t)&pcic->pc_sockets[j]) != DDI_SUCCESS)
15493db86aabSstevel 			goto pci_exit2;
15503db86aabSstevel 
15513db86aabSstevel #if defined(PCIC_DEBUG)
15523db86aabSstevel 	if (pcic_debug)
15533db86aabSstevel 		cmn_err(CE_CONT, "type = %s sockets = %d\n", typename,
155419397407SSherry Moore 		    pcic->pc_numsockets);
15553db86aabSstevel #endif
15563db86aabSstevel 
15573db86aabSstevel 	pcic_nexus->an_iblock = &pcic->pc_pri;
15583db86aabSstevel 	pcic_nexus->an_idev = &pcic->pc_dcookie;
15593db86aabSstevel 
15603db86aabSstevel 	mutex_exit(&pcic->pc_lock);
15613db86aabSstevel 
15623db86aabSstevel #ifdef CARDBUS
15633db86aabSstevel 	(void) cardbus_enable_cd_intr(dip);
15643db86aabSstevel 	if (pcic_debug) {
15653db86aabSstevel 
15663db86aabSstevel 		cardbus_dump_pci_config(dip);
15673db86aabSstevel 		cardbus_dump_socket(dip);
15683db86aabSstevel 	}
15693db86aabSstevel 
15703db86aabSstevel 	/*
15713db86aabSstevel 	 * Give the Cardbus misc module a chance to do it's per-adapter
15723db86aabSstevel 	 * instance setup. Note that there is no corresponding detach()
15733db86aabSstevel 	 * call.
15743db86aabSstevel 	 */
15753db86aabSstevel 	if (pcic->pc_flags & PCF_CARDBUS)
15763db86aabSstevel 		if (cardbus_attach(dip, &pcic_cbnexus_ops) != DDI_SUCCESS) {
15773db86aabSstevel 			cmn_err(CE_CONT,
15783db86aabSstevel 			    "pcic_attach: cardbus_attach failed\n");
15793db86aabSstevel 			goto pci_exit2;
15803db86aabSstevel 		}
15813db86aabSstevel #endif
15823db86aabSstevel 
15833db86aabSstevel 	/*
15843db86aabSstevel 	 * Give the PCMCIA misc module a chance to do it's per-adapter
15853db86aabSstevel 	 *	instance setup.
15863db86aabSstevel 	 */
15873db86aabSstevel 	if ((i = pcmcia_attach(dip, pcic_nexus)) != DDI_SUCCESS)
15883db86aabSstevel 		goto pci_exit2;
15893db86aabSstevel 
15903db86aabSstevel 	if (pcic_maxinst == -1) {
15913db86aabSstevel 		/* This assumes that all instances run at the same IPL. */
15923db86aabSstevel 		mutex_init(&pcic_deb_mtx, NULL, MUTEX_DRIVER, NULL);
15933db86aabSstevel 		cv_init(&pcic_deb_cv, NULL, CV_DRIVER, NULL);
15943db86aabSstevel 		pcic_deb_threadid = thread_create((caddr_t)NULL, 0,
15953db86aabSstevel 		    pcic_deb_thread, (caddr_t)NULL, 0, &p0, TS_RUN,
15963db86aabSstevel 		    v.v_maxsyspri - 2);
15973db86aabSstevel 	}
15983db86aabSstevel 	pcic_maxinst = max(pcic_maxinst, ddi_get_instance(dip));
15993db86aabSstevel 	/*
16003db86aabSstevel 	 * Setup a debounce timeout to do an initial card detect
16013db86aabSstevel 	 * and enable interrupts.
16023db86aabSstevel 	 */
16033db86aabSstevel 	for (j = 0; j < pcic->pc_numsockets; j++) {
16043db86aabSstevel 		pcic->pc_sockets[j].pcs_debounce_id =
16053db86aabSstevel 		    pcic_add_debqueue(&pcic->pc_sockets[j],
160619397407SSherry Moore 		    drv_usectohz(pcic_debounce_time));
16073db86aabSstevel 	}
16083db86aabSstevel 
16093db86aabSstevel 	return (i);
16103db86aabSstevel 
16113db86aabSstevel isa_exit2:
16123db86aabSstevel 	mutex_destroy(&pcic->intr_lock);
16133db86aabSstevel 	mutex_destroy(&pcic->pc_lock);
16143db86aabSstevel 	for (j = i; j < 0; j--)
16153db86aabSstevel 		(void) ddi_intr_free(pcic->pc_intr_htblp[j]);
16163db86aabSstevel isa_exit1:
16173db86aabSstevel 	(void) pcmcia_return_intr(dip, pcic->pc_sockets[i].pcs_smi);
16183db86aabSstevel 	ddi_regs_map_free(&pcic->handle);
16193db86aabSstevel 	if (pcic->pc_flags & PCF_PCIBUS)
16203db86aabSstevel 		ddi_regs_map_free(&pcic->cfg_handle);
16213db86aabSstevel 	kmem_free(pcic->pc_intr_htblp, pcic->pc_numsockets *
16223db86aabSstevel 	    sizeof (ddi_intr_handle_t));
16233db86aabSstevel 	kmem_free(pcic, sizeof (pcicdev_t));
16243db86aabSstevel 		return (DDI_FAILURE);
16253db86aabSstevel 
16263db86aabSstevel pci_exit2:
16273db86aabSstevel 	mutex_destroy(&pcic->intr_lock);
16283db86aabSstevel 	mutex_destroy(&pcic->pc_lock);
16293db86aabSstevel 	(void) ddi_intr_free(pcic->pc_pci_intr_hdlp[0]);
16303db86aabSstevel pci_exit1:
16313db86aabSstevel 	ddi_regs_map_free(&pcic->handle);
16323db86aabSstevel 	if (pcic->pc_flags & PCF_PCIBUS)
16333db86aabSstevel 		ddi_regs_map_free(&pcic->cfg_handle);
16343db86aabSstevel 	kmem_free(pcic->pc_pci_intr_hdlp, sizeof (ddi_intr_handle_t));
16353db86aabSstevel 	kmem_free(pcic, sizeof (pcicdev_t));
16363db86aabSstevel 	return (DDI_FAILURE);
16373db86aabSstevel }
16383db86aabSstevel 
16393db86aabSstevel /*
16403db86aabSstevel  * pcic_detach()
16413db86aabSstevel  *	request to detach from the system
16423db86aabSstevel  */
16433db86aabSstevel static int
pcic_detach(dev_info_t * dip,ddi_detach_cmd_t cmd)16443db86aabSstevel pcic_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
16453db86aabSstevel {
16463db86aabSstevel 	anp_t *anp = ddi_get_driver_private(dip);
16473db86aabSstevel 	pcicdev_t *pcic = anp->an_private;
16483db86aabSstevel 	int i;
16493db86aabSstevel 
16503db86aabSstevel 	switch (cmd) {
16513db86aabSstevel 	case DDI_DETACH:
16523db86aabSstevel 		/* don't detach if the nexus still talks to us */
16533db86aabSstevel 		if (pcic->pc_callback != NULL)
16543db86aabSstevel 			return (DDI_FAILURE);
16553db86aabSstevel 
16563db86aabSstevel 		/* kill off the pm simulation */
16573db86aabSstevel 		if (pcic->pc_pmtimer)
16583db86aabSstevel 			(void) untimeout(pcic->pc_pmtimer);
16593db86aabSstevel 
16603db86aabSstevel 		/* turn everything off for all sockets and chips */
16613db86aabSstevel 		for (i = 0; i < pcic->pc_numsockets; i++) {
16623db86aabSstevel 			if (pcic->pc_sockets[i].pcs_debounce_id)
16633db86aabSstevel 				pcic_rm_debqueue(
16643db86aabSstevel 				    pcic->pc_sockets[i].pcs_debounce_id);
16653db86aabSstevel 			pcic->pc_sockets[i].pcs_debounce_id = 0;
16663db86aabSstevel 
16673db86aabSstevel 			pcic_putb(pcic, i, PCIC_MANAGEMENT_INT, 0);
16683db86aabSstevel 			pcic_putb(pcic, i, PCIC_CARD_DETECT, 0);
16693db86aabSstevel 			pcic_putb(pcic, i, PCIC_MAPPING_ENABLE, 0);
16703db86aabSstevel 			/* disable interrupts and put card into RESET */
16713db86aabSstevel 			pcic_putb(pcic, i, PCIC_INTERRUPT, 0);
16723db86aabSstevel 		}
16733db86aabSstevel 		(void) ddi_intr_disable(pcic->pc_pci_intr_hdlp[0]);
16743db86aabSstevel 		(void) ddi_intr_remove_handler(pcic->pc_pci_intr_hdlp[0]);
16753db86aabSstevel 		(void) ddi_intr_free(pcic->pc_pci_intr_hdlp[0]);
16763db86aabSstevel 		kmem_free(pcic->pc_pci_intr_hdlp, sizeof (ddi_intr_handle_t));
16773db86aabSstevel 		pcic->pc_flags = 0;
16783db86aabSstevel 		mutex_destroy(&pcic->pc_lock);
16793db86aabSstevel 		mutex_destroy(&pcic->intr_lock);
16803db86aabSstevel 		cv_destroy(&pcic->pm_cv);
16813db86aabSstevel 		if (pcic->pc_flags & PCF_PCIBUS)
168219397407SSherry Moore 			ddi_regs_map_free(&pcic->cfg_handle);
16833db86aabSstevel 		if (pcic->handle)
168419397407SSherry Moore 			ddi_regs_map_free(&pcic->handle);
16853db86aabSstevel 		kmem_free(pcic, sizeof (pcicdev_t));
16863db86aabSstevel 		ddi_soft_state_free(pcic_soft_state_p, ddi_get_instance(dip));
16873db86aabSstevel 		return (DDI_SUCCESS);
16883db86aabSstevel 
16893db86aabSstevel 	case DDI_SUSPEND:
16903db86aabSstevel 	case DDI_PM_SUSPEND:
16913db86aabSstevel 		/*
16923db86aabSstevel 		 * we got a suspend event (either real or imagined)
16933db86aabSstevel 		 * so notify the nexus proper that all existing cards
16943db86aabSstevel 		 * should go away.
16953db86aabSstevel 		 */
16963db86aabSstevel 		mutex_enter(&pcic->pc_lock);
16973db86aabSstevel #ifdef CARDBUS
169811c2b4c0Srw 		if (pcic->pc_flags & PCF_CARDBUS) {
169911c2b4c0Srw 			for (i = 0; i < pcic->pc_numsockets; i++) {
17003db86aabSstevel 				if ((pcic->pc_sockets[i].pcs_flags &
17013db86aabSstevel 				    (PCS_CARD_PRESENT|PCS_CARD_ISCARDBUS)) ==
170211c2b4c0Srw 				    (PCS_CARD_PRESENT|PCS_CARD_ISCARDBUS)) {
170311c2b4c0Srw 
170411c2b4c0Srw 					pcmcia_cb_suspended(
170519397407SSherry Moore 					    pcic->pc_sockets[i].pcs_socket);
170611c2b4c0Srw 				}
170711c2b4c0Srw 			}
170811c2b4c0Srw 
170911c2b4c0Srw 			cardbus_save_children(ddi_get_child(dip));
171011c2b4c0Srw 		}
17113db86aabSstevel #endif
17123db86aabSstevel 		/* turn everything off for all sockets and chips */
17133db86aabSstevel 		for (i = 0; i < pcic->pc_numsockets; i++) {
17143db86aabSstevel 			if (pcic->pc_sockets[i].pcs_debounce_id)
17153db86aabSstevel 				pcic_rm_debqueue(
17163db86aabSstevel 				    pcic->pc_sockets[i].pcs_debounce_id);
17173db86aabSstevel 			pcic->pc_sockets[i].pcs_debounce_id = 0;
17183db86aabSstevel 
17193db86aabSstevel 			pcic_putb(pcic, i, PCIC_MANAGEMENT_INT, 0);
17203db86aabSstevel 			pcic_putb(pcic, i, PCIC_CARD_DETECT, 0);
17213db86aabSstevel 			pcic_putb(pcic, i, PCIC_MAPPING_ENABLE, 0);
17223db86aabSstevel 			/* disable interrupts and put card into RESET */
17233db86aabSstevel 			pcic_putb(pcic, i, PCIC_INTERRUPT, 0);
17243db86aabSstevel 			pcic_putb(pcic, i, PCIC_POWER_CONTROL, 0);
17253db86aabSstevel 			if (pcic->pc_flags & PCF_CBPWRCTL)
17263db86aabSstevel 				pcic_putcb(pcic, CB_CONTROL, 0);
17273db86aabSstevel 
17283db86aabSstevel 			if (pcic->pc_sockets[i].pcs_flags & PCS_CARD_PRESENT) {
17293db86aabSstevel 				pcic->pc_sockets[i].pcs_flags = PCS_STARTING;
17303db86aabSstevel 				/*
17313db86aabSstevel 				 * Because we are half way through a save
17323db86aabSstevel 				 * all this does is schedule a removal event
17333db86aabSstevel 				 * to cs for when the system comes back.
17343db86aabSstevel 				 * This doesn't actually matter.
17353db86aabSstevel 				 */
17363db86aabSstevel 				if (!pcic_do_pcmcia_sr && pcic_do_removal &&
17373db86aabSstevel 				    pcic->pc_callback) {
17383db86aabSstevel 					PC_CALLBACK(pcic->dip, pcic->pc_cb_arg,
17393db86aabSstevel 					    PCE_CARD_REMOVAL,
17403db86aabSstevel 					    pcic->pc_sockets[i].pcs_socket);
17413db86aabSstevel 				}
17423db86aabSstevel 			}
17433db86aabSstevel 		}
17443db86aabSstevel 
17453db86aabSstevel 		pcic->pc_flags |= PCF_SUSPENDED;
17463db86aabSstevel 		mutex_exit(&pcic->pc_lock);
17473db86aabSstevel 
17483db86aabSstevel 		/*
17493db86aabSstevel 		 * when true power management exists, save the adapter
17503db86aabSstevel 		 * state here to enable a recovery.  For the emulation
17513db86aabSstevel 		 * condition, the state is gone
17523db86aabSstevel 		 */
17533db86aabSstevel 		return (DDI_SUCCESS);
17543db86aabSstevel 
17553db86aabSstevel 	default:
17563db86aabSstevel 		return (EINVAL);
17573db86aabSstevel 	}
17583db86aabSstevel }
17593db86aabSstevel 
17603db86aabSstevel static uint32_t pcic_tisysctl_onbits = ((1<<27) | (1<<15) | (1<<14));
17613db86aabSstevel static uint32_t pcic_tisysctl_offbits = 0;
17623db86aabSstevel static uint32_t pcic_default_latency = 0x40;
17633db86aabSstevel 
17643db86aabSstevel static void
pcic_setup_adapter(pcicdev_t * pcic)17653db86aabSstevel pcic_setup_adapter(pcicdev_t *pcic)
17663db86aabSstevel {
17673db86aabSstevel 	int i;
17683db86aabSstevel 	int value, flags;
17693db86aabSstevel 
177086ef0a63SRichard Lowe #if defined(__x86)
1771e12b469aSrui wang - Sun Microsystems - Beijing China 	pci_regspec_t *reg;
1772e12b469aSrui wang - Sun Microsystems - Beijing China 	uchar_t bus, dev, func;
1773e12b469aSrui wang - Sun Microsystems - Beijing China 	uint_t classcode;
1774e12b469aSrui wang - Sun Microsystems - Beijing China 	int length;
1775e12b469aSrui wang - Sun Microsystems - Beijing China #endif
1776e12b469aSrui wang - Sun Microsystems - Beijing China 
17773db86aabSstevel 	if (pcic->pc_flags & PCF_PCIBUS) {
17783db86aabSstevel 		/*
17793db86aabSstevel 		 * all PCI-to-PCMCIA bus bridges need memory and I/O enabled
17803db86aabSstevel 		 */
17813db86aabSstevel 		flags = (PCIC_ENABLE_IO | PCIC_ENABLE_MEM);
17823db86aabSstevel 		pcic_iomem_pci_ctl(pcic->cfg_handle, pcic->cfgaddr, flags);
17833db86aabSstevel 	}
17843db86aabSstevel 	/* enable each socket */
17853db86aabSstevel 	for (i = 0; i < pcic->pc_numsockets; i++) {
17863db86aabSstevel 		pcic->pc_sockets[i].pcs_flags = 0;
17873db86aabSstevel 		/* find out the socket capabilities (I/O vs memory) */
17883db86aabSstevel 		value = pcic_getb(pcic, i,
178919397407SSherry Moore 		    PCIC_CHIP_REVISION) & PCIC_REV_ID_MASK;
17903db86aabSstevel 		if (value == PCIC_REV_ID_IO || value == PCIC_REV_ID_BOTH)
17913db86aabSstevel 			pcic->pc_sockets[i].pcs_flags |= PCS_SOCKET_IO;
17923db86aabSstevel 
17933db86aabSstevel 		/* disable all windows just in case */
17943db86aabSstevel 		pcic_putb(pcic, i, PCIC_MAPPING_ENABLE, 0);
17953db86aabSstevel 
17963db86aabSstevel 		switch (pcic->pc_type) {
17973db86aabSstevel 			uint32_t cfg32;
17983db86aabSstevel 			uint16_t cfg16;
17993db86aabSstevel 			uint8_t cfg;
18003db86aabSstevel 
18013db86aabSstevel 		    /* enable extended registers for Vadem */
180219397407SSherry Moore 			case PCIC_VADEM_VG469:
180319397407SSherry Moore 			case PCIC_VADEM:
18043db86aabSstevel 
18053db86aabSstevel 			/* enable card status change interrupt for socket */
18063db86aabSstevel 			break;
18073db86aabSstevel 
180819397407SSherry Moore 			case PCIC_I82365SL:
18093db86aabSstevel 			break;
18103db86aabSstevel 
181119397407SSherry Moore 			case PCIC_CL_PD6710:
18123db86aabSstevel 			pcic_putb(pcic, 0, PCIC_MISC_CTL_2, PCIC_LED_ENABLE);
18133db86aabSstevel 			break;
18143db86aabSstevel 
18153db86aabSstevel 			/*
18163db86aabSstevel 			 * On the CL_6730, we need to set up the interrupt
18173db86aabSstevel 			 * signalling mode (PCI mode) and set the SMI and
18183db86aabSstevel 			 * IRQ interrupt lines to PCI/level-mode.
18193db86aabSstevel 			 */
182019397407SSherry Moore 			case PCIC_CL_PD6730:
18213db86aabSstevel 			switch (pcic->pc_intr_mode) {
18223db86aabSstevel 			case PCIC_INTR_MODE_PCI_1:
18233db86aabSstevel 				clext_reg_write(pcic, i, PCIC_CLEXT_MISC_CTL_3,
182419397407SSherry Moore 				    ((clext_reg_read(pcic, i,
182519397407SSherry Moore 				    PCIC_CLEXT_MISC_CTL_3) &
182619397407SSherry Moore 				    ~PCIC_CLEXT_INT_PCI) |
182719397407SSherry Moore 				    PCIC_CLEXT_INT_PCI));
18283db86aabSstevel 				clext_reg_write(pcic, i, PCIC_CLEXT_EXT_CTL_1,
182919397407SSherry Moore 				    (PCIC_CLEXT_IRQ_LVL_MODE |
183019397407SSherry Moore 				    PCIC_CLEXT_SMI_LVL_MODE));
18313db86aabSstevel 				cfg = PCIC_CL_LP_DYN_MODE;
18323db86aabSstevel 				pcic_putb(pcic, i, PCIC_MISC_CTL_2, cfg);
18333db86aabSstevel 				break;
18343db86aabSstevel 			case PCIC_INTR_MODE_ISA:
18353db86aabSstevel 				break;
18363db86aabSstevel 			}
18373db86aabSstevel 			break;
18383db86aabSstevel 			/*
18393db86aabSstevel 			 * On the CL_6729, we set the SMI and IRQ interrupt
18403db86aabSstevel 			 *	lines to PCI/level-mode. as well as program the
18413db86aabSstevel 			 *	correct clock speed divider bit.
18423db86aabSstevel 			 */
184319397407SSherry Moore 			case PCIC_CL_PD6729:
18443db86aabSstevel 			switch (pcic->pc_intr_mode) {
18453db86aabSstevel 			case PCIC_INTR_MODE_PCI_1:
18463db86aabSstevel 				clext_reg_write(pcic, i, PCIC_CLEXT_EXT_CTL_1,
184719397407SSherry Moore 				    (PCIC_CLEXT_IRQ_LVL_MODE |
184819397407SSherry Moore 				    PCIC_CLEXT_SMI_LVL_MODE));
18493db86aabSstevel 
18503db86aabSstevel 				break;
18513db86aabSstevel 			case PCIC_INTR_MODE_ISA:
18523db86aabSstevel 				break;
18533db86aabSstevel 			}
18543db86aabSstevel 			if (pcic->bus_speed > PCIC_PCI_25MHZ && i == 0) {
18553db86aabSstevel 				cfg = 0;
18563db86aabSstevel 				cfg |= PCIC_CL_TIMER_CLK_DIV;
18573db86aabSstevel 				pcic_putb(pcic, i, PCIC_MISC_CTL_2, cfg);
18583db86aabSstevel 			}
18593db86aabSstevel 			break;
186019397407SSherry Moore 			case PCIC_INTEL_i82092:
18613db86aabSstevel 			cfg = PCIC_82092_EN_TIMING;
18623db86aabSstevel 			if (pcic->bus_speed < PCIC_SYSCLK_33MHZ)
186319397407SSherry Moore 				cfg |= PCIC_82092_PCICLK_25MHZ;
18643db86aabSstevel 			ddi_put8(pcic->cfg_handle, pcic->cfgaddr +
186519397407SSherry Moore 			    PCIC_82092_PCICON, cfg);
18663db86aabSstevel 			break;
186719397407SSherry Moore 			case PCIC_TI_PCI1130:
186819397407SSherry Moore 			case PCIC_TI_PCI1131:
186919397407SSherry Moore 			case PCIC_TI_PCI1250:
187019397407SSherry Moore 			case PCIC_TI_PCI1031:
18713db86aabSstevel 			cfg = ddi_get8(pcic->cfg_handle,
187219397407SSherry Moore 			    pcic->cfgaddr + PCIC_DEVCTL_REG);
18733db86aabSstevel 			cfg &= ~PCIC_DEVCTL_INTR_MASK;
18743db86aabSstevel 			switch (pcic->pc_intr_mode) {
18753db86aabSstevel 			case PCIC_INTR_MODE_ISA:
18763db86aabSstevel 				cfg |= PCIC_DEVCTL_INTR_ISA;
18773db86aabSstevel 				break;
18783db86aabSstevel 			}
18793db86aabSstevel #ifdef PCIC_DEBUG
18803db86aabSstevel 			if (pcic_debug) {
18813db86aabSstevel 				cmn_err(CE_CONT, "pcic_setup_adapter: "
18823db86aabSstevel 				    "write reg 0x%x=%x \n",
18833db86aabSstevel 				    PCIC_DEVCTL_REG, cfg);
18843db86aabSstevel 			}
18853db86aabSstevel #endif
18863db86aabSstevel 			ddi_put8(pcic->cfg_handle,
188719397407SSherry Moore 			    pcic->cfgaddr + PCIC_DEVCTL_REG,
188819397407SSherry Moore 			    cfg);
18893db86aabSstevel 
18903db86aabSstevel 			cfg = ddi_get8(pcic->cfg_handle,
189119397407SSherry Moore 			    pcic->cfgaddr + PCIC_CRDCTL_REG);
18923db86aabSstevel 			cfg &= ~(PCIC_CRDCTL_PCIINTR|PCIC_CRDCTL_PCICSC|
189319397407SSherry Moore 			    PCIC_CRDCTL_PCIFUNC);
18943db86aabSstevel 			switch (pcic->pc_intr_mode) {
18953db86aabSstevel 			case PCIC_INTR_MODE_PCI_1:
18963db86aabSstevel 				cfg |= PCIC_CRDCTL_PCIINTR |
189719397407SSherry Moore 				    PCIC_CRDCTL_PCICSC |
189819397407SSherry Moore 				    PCIC_CRDCTL_PCIFUNC;
18993db86aabSstevel 				pcic->pc_flags |= PCF_USE_SMI;
19003db86aabSstevel 				break;
19013db86aabSstevel 			}
19023db86aabSstevel #ifdef PCIC_DEBUG
19033db86aabSstevel 			if (pcic_debug) {
19043db86aabSstevel 				cmn_err(CE_CONT, "pcic_setup_adapter: "
19053db86aabSstevel 				    " write reg 0x%x=%x \n",
19063db86aabSstevel 				    PCIC_CRDCTL_REG, cfg);
19073db86aabSstevel 			}
19083db86aabSstevel #endif
19093db86aabSstevel 			ddi_put8(pcic->cfg_handle,
191019397407SSherry Moore 			    pcic->cfgaddr + PCIC_CRDCTL_REG,
191119397407SSherry Moore 			    cfg);
19123db86aabSstevel 			break;
191319397407SSherry Moore 			case PCIC_TI_PCI1221:
191419397407SSherry Moore 			case PCIC_TI_PCI1225:
19153db86aabSstevel 			cfg = ddi_get8(pcic->cfg_handle,
19163db86aabSstevel 			    pcic->cfgaddr + PCIC_DEVCTL_REG);
19173db86aabSstevel 			cfg |= (PCIC_DEVCTL_INTR_DFLT | PCIC_DEVCTL_3VCAPABLE);
19183db86aabSstevel #ifdef PCIC_DEBUG
19193db86aabSstevel 			if (pcic_debug) {
19203db86aabSstevel 				cmn_err(CE_CONT, "pcic_setup_adapter: "
19213db86aabSstevel 				    " write reg 0x%x=%x \n",
19223db86aabSstevel 				    PCIC_DEVCTL_REG, cfg);
19233db86aabSstevel 			}
19243db86aabSstevel #endif
19253db86aabSstevel 			ddi_put8(pcic->cfg_handle,
19263db86aabSstevel 			    pcic->cfgaddr + PCIC_DEVCTL_REG, cfg);
19273db86aabSstevel 
19283db86aabSstevel 			cfg = ddi_get8(pcic->cfg_handle,
19293db86aabSstevel 			    pcic->cfgaddr + PCIC_DIAG_REG);
19303db86aabSstevel 			if (pcic->pc_type == PCIC_TI_PCI1225) {
19313db86aabSstevel 				cfg |= (PCIC_DIAG_CSC | PCIC_DIAG_ASYNC);
19323db86aabSstevel 			} else {
19333db86aabSstevel 				cfg |= PCIC_DIAG_ASYNC;
19343db86aabSstevel 			}
19353db86aabSstevel 			pcic->pc_flags |= PCF_USE_SMI;
19363db86aabSstevel #ifdef PCIC_DEBUG
19373db86aabSstevel 			if (pcic_debug) {
19383db86aabSstevel 				cmn_err(CE_CONT, "pcic_setup_adapter: "
19393db86aabSstevel 				    " write reg 0x%x=%x \n",
19403db86aabSstevel 				    PCIC_DIAG_REG, cfg);
19413db86aabSstevel 			}
19423db86aabSstevel #endif
19433db86aabSstevel 			ddi_put8(pcic->cfg_handle,
19443db86aabSstevel 			    pcic->cfgaddr + PCIC_DIAG_REG, cfg);
19453db86aabSstevel 			break;
194619397407SSherry Moore 			case PCIC_TI_PCI1520:
194719397407SSherry Moore 			case PCIC_TI_PCI1510:
194819397407SSherry Moore 			case PCIC_TI_VENDOR:
19493db86aabSstevel 			if (pcic->pc_intr_mode == PCIC_INTR_MODE_ISA) {
1950e12b469aSrui wang - Sun Microsystems - Beijing China 				/* functional intr routed by ExCA register */
19513db86aabSstevel 				cfg = ddi_get8(pcic->cfg_handle,
195219397407SSherry Moore 				    pcic->cfgaddr + PCIC_BRIDGE_CTL_REG);
19533db86aabSstevel 				cfg |= PCIC_FUN_INT_MOD_ISA;
19543db86aabSstevel 				ddi_put8(pcic->cfg_handle,
195519397407SSherry Moore 				    pcic->cfgaddr + PCIC_BRIDGE_CTL_REG,
195619397407SSherry Moore 				    cfg);
1957e12b469aSrui wang - Sun Microsystems - Beijing China 
1958e12b469aSrui wang - Sun Microsystems - Beijing China 				/* IRQ serialized interrupts */
1959e12b469aSrui wang - Sun Microsystems - Beijing China 				cfg = ddi_get8(pcic->cfg_handle,
196019397407SSherry Moore 				    pcic->cfgaddr + PCIC_DEVCTL_REG);
1961e12b469aSrui wang - Sun Microsystems - Beijing China 				cfg &= ~PCIC_DEVCTL_INTR_MASK;
1962e12b469aSrui wang - Sun Microsystems - Beijing China 				cfg |= PCIC_DEVCTL_INTR_ISA;
1963e12b469aSrui wang - Sun Microsystems - Beijing China 				ddi_put8(pcic->cfg_handle,
196419397407SSherry Moore 				    pcic->cfgaddr + PCIC_DEVCTL_REG,
196519397407SSherry Moore 				    cfg);
1966e12b469aSrui wang - Sun Microsystems - Beijing China 				break;
1967e12b469aSrui wang - Sun Microsystems - Beijing China 			}
1968e12b469aSrui wang - Sun Microsystems - Beijing China 
1969e12b469aSrui wang - Sun Microsystems - Beijing China 			/* CSC interrupt routed to PCI */
1970e12b469aSrui wang - Sun Microsystems - Beijing China 			cfg = ddi_get8(pcic->cfg_handle,
1971e12b469aSrui wang - Sun Microsystems - Beijing China 			    pcic->cfgaddr + PCIC_DIAG_REG);
1972e12b469aSrui wang - Sun Microsystems - Beijing China 			cfg |= (PCIC_DIAG_CSC | PCIC_DIAG_ASYNC);
1973e12b469aSrui wang - Sun Microsystems - Beijing China 			ddi_put8(pcic->cfg_handle,
1974e12b469aSrui wang - Sun Microsystems - Beijing China 			    pcic->cfgaddr + PCIC_DIAG_REG, cfg);
1975e12b469aSrui wang - Sun Microsystems - Beijing China 
197686ef0a63SRichard Lowe #if defined(__x86)
1977e12b469aSrui wang - Sun Microsystems - Beijing China 			/*
1978e12b469aSrui wang - Sun Microsystems - Beijing China 			 * Some TI chips have 2 cardbus slots(function0 and
1979e12b469aSrui wang - Sun Microsystems - Beijing China 			 * function1), and others may have just 1 cardbus slot.
1980e12b469aSrui wang - Sun Microsystems - Beijing China 			 * The interrupt routing register is shared between the
1981e12b469aSrui wang - Sun Microsystems - Beijing China 			 * 2 functions and can only be accessed through
1982e12b469aSrui wang - Sun Microsystems - Beijing China 			 * function0. Here we check the presence of the second
1983e12b469aSrui wang - Sun Microsystems - Beijing China 			 * cardbus slot and do the right thing.
1984e12b469aSrui wang - Sun Microsystems - Beijing China 			 */
1985e12b469aSrui wang - Sun Microsystems - Beijing China 
1986e12b469aSrui wang - Sun Microsystems - Beijing China 			if (ddi_getlongprop(DDI_DEV_T_ANY, pcic->dip,
1987e12b469aSrui wang - Sun Microsystems - Beijing China 			    DDI_PROP_DONTPASS, "reg", (caddr_t)&reg,
1988e12b469aSrui wang - Sun Microsystems - Beijing China 			    &length) != DDI_PROP_SUCCESS) {
198919397407SSherry Moore 				cmn_err(CE_WARN,
199019397407SSherry Moore 				    "pcic_setup_adapter(), failed to"
199119397407SSherry Moore 				    " read reg property\n");
1992e12b469aSrui wang - Sun Microsystems - Beijing China 				break;
1993e12b469aSrui wang - Sun Microsystems - Beijing China 			}
1994e12b469aSrui wang - Sun Microsystems - Beijing China 
1995e12b469aSrui wang - Sun Microsystems - Beijing China 			bus = PCI_REG_BUS_G(reg->pci_phys_hi);
1996e12b469aSrui wang - Sun Microsystems - Beijing China 			dev = PCI_REG_DEV_G(reg->pci_phys_hi);
1997e12b469aSrui wang - Sun Microsystems - Beijing China 			func = PCI_REG_FUNC_G(reg->pci_phys_hi);
1998e12b469aSrui wang - Sun Microsystems - Beijing China 			kmem_free((caddr_t)reg, length);
1999e12b469aSrui wang - Sun Microsystems - Beijing China 
2000e12b469aSrui wang - Sun Microsystems - Beijing China 			if (func != 0) {
2001e12b469aSrui wang - Sun Microsystems - Beijing China 				break;
2002e12b469aSrui wang - Sun Microsystems - Beijing China 			}
2003e12b469aSrui wang - Sun Microsystems - Beijing China 
2004e12b469aSrui wang - Sun Microsystems - Beijing China 			classcode = (*pci_getl_func)(bus, dev, 1,
200519397407SSherry Moore 			    PCI_CONF_REVID);
2006e12b469aSrui wang - Sun Microsystems - Beijing China 			classcode >>= 8;
2007e12b469aSrui wang - Sun Microsystems - Beijing China 			if (classcode != 0x060700 &&
2008e12b469aSrui wang - Sun Microsystems - Beijing China 			    classcode != 0x060500) {
2009e12b469aSrui wang - Sun Microsystems - Beijing China 				break;
20103db86aabSstevel 			}
2011e12b469aSrui wang - Sun Microsystems - Beijing China 
2012e12b469aSrui wang - Sun Microsystems - Beijing China 			/* Parallel PCI interrupts only */
20133db86aabSstevel 			cfg = ddi_get8(pcic->cfg_handle,
201419397407SSherry Moore 			    pcic->cfgaddr + PCIC_DEVCTL_REG);
20153db86aabSstevel 			cfg &= ~PCIC_DEVCTL_INTR_MASK;
20163db86aabSstevel 			ddi_put8(pcic->cfg_handle,
201719397407SSherry Moore 			    pcic->cfgaddr + PCIC_DEVCTL_REG,
201819397407SSherry Moore 			    cfg);
20193db86aabSstevel 
20203db86aabSstevel 			/* tie INTA and INTB together */
20213db86aabSstevel 			cfg = ddi_get8(pcic->cfg_handle,
202219397407SSherry Moore 			    (pcic->cfgaddr + PCIC_SYSCTL_REG + 3));
20233db86aabSstevel 			cfg |= PCIC_SYSCTL_INTRTIE;
20243db86aabSstevel 			ddi_put8(pcic->cfg_handle, (pcic->cfgaddr +
202519397407SSherry Moore 			    PCIC_SYSCTL_REG + 3), cfg);
2026e12b469aSrui wang - Sun Microsystems - Beijing China #endif
2027e12b469aSrui wang - Sun Microsystems - Beijing China 
20283db86aabSstevel 			break;
202919397407SSherry Moore 			case PCIC_TI_PCI1410:
20303db86aabSstevel 			cfg = ddi_get8(pcic->cfg_handle,
20313db86aabSstevel 			    pcic->cfgaddr + PCIC_DIAG_REG);
20323db86aabSstevel 			cfg |= (PCIC_DIAG_CSC | PCIC_DIAG_ASYNC);
20333db86aabSstevel 			ddi_put8(pcic->cfg_handle,
20343db86aabSstevel 			    pcic->cfgaddr + PCIC_DIAG_REG, cfg);
20353db86aabSstevel 			break;
203619397407SSherry Moore 			case PCIC_TOSHIBA_TOPIC100:
203719397407SSherry Moore 			case PCIC_TOSHIBA_TOPIC95:
203819397407SSherry Moore 			case PCIC_TOSHIBA_VENDOR:
20393db86aabSstevel 			cfg = ddi_get8(pcic->cfg_handle, pcic->cfgaddr +
204019397407SSherry Moore 			    PCIC_TOSHIBA_SLOT_CTL_REG);
20413db86aabSstevel 			cfg |= (PCIC_TOSHIBA_SCR_SLOTON |
204219397407SSherry Moore 			    PCIC_TOSHIBA_SCR_SLOTEN);
20433db86aabSstevel 			cfg &= (~PCIC_TOSHIBA_SCR_PRT_MASK);
20443db86aabSstevel 			cfg |= PCIC_TOSHIBA_SCR_PRT_3E2;
20453db86aabSstevel 			ddi_put8(pcic->cfg_handle, pcic->cfgaddr +
204619397407SSherry Moore 			    PCIC_TOSHIBA_SLOT_CTL_REG, cfg);
20473db86aabSstevel 			cfg = ddi_get8(pcic->cfg_handle, pcic->cfgaddr +
204819397407SSherry Moore 			    PCIC_TOSHIBA_INTR_CTL_REG);
20493db86aabSstevel 			switch (pcic->pc_intr_mode) {
20503db86aabSstevel 			case PCIC_INTR_MODE_ISA:
20513db86aabSstevel 				cfg &= ~PCIC_TOSHIBA_ICR_SRC;
20523db86aabSstevel 				ddi_put8(pcic->cfg_handle,
205319397407SSherry Moore 				    pcic->cfgaddr +
205419397407SSherry Moore 				    PCIC_TOSHIBA_INTR_CTL_REG, cfg);
20553db86aabSstevel 
20563db86aabSstevel 				cfg = ddi_get8(pcic->cfg_handle,
205719397407SSherry Moore 				    pcic->cfgaddr + PCIC_BRIDGE_CTL_REG);
20583db86aabSstevel 				cfg |= PCIC_FUN_INT_MOD_ISA;
20593db86aabSstevel 				ddi_put8(pcic->cfg_handle,
206019397407SSherry Moore 				    pcic->cfgaddr + PCIC_BRIDGE_CTL_REG,
206119397407SSherry Moore 				    cfg);
20623db86aabSstevel 				break;
20633db86aabSstevel 			case PCIC_INTR_MODE_PCI_1:
20643db86aabSstevel 				cfg |= PCIC_TOSHIBA_ICR_SRC;
20653db86aabSstevel 				cfg &= (~PCIC_TOSHIBA_ICR_PIN_MASK);
20663db86aabSstevel 				cfg |= PCIC_TOSHIBA_ICR_PIN_INTA;
20673db86aabSstevel 				ddi_put8(pcic->cfg_handle,
206819397407SSherry Moore 				    pcic->cfgaddr +
206919397407SSherry Moore 				    PCIC_TOSHIBA_INTR_CTL_REG, cfg);
20703db86aabSstevel 				break;
20713db86aabSstevel 			}
20723db86aabSstevel 			break;
207319397407SSherry Moore 			case PCIC_O2MICRO_VENDOR:
20743db86aabSstevel 			cfg32 = ddi_get32(pcic->cfg_handle,
207519397407SSherry Moore 			    (uint32_t *)(pcic->cfgaddr +
207619397407SSherry Moore 			    PCIC_O2MICRO_MISC_CTL));
20773db86aabSstevel 			switch (pcic->pc_intr_mode) {
20783db86aabSstevel 			case PCIC_INTR_MODE_ISA:
20793db86aabSstevel 				cfg32 |= (PCIC_O2MICRO_ISA_LEGACY |
208019397407SSherry Moore 				    PCIC_O2MICRO_INT_MOD_PCI);
20813db86aabSstevel 				ddi_put32(pcic->cfg_handle,
208219397407SSherry Moore 				    (uint32_t *)(pcic->cfgaddr +
208319397407SSherry Moore 				    PCIC_O2MICRO_MISC_CTL),
208419397407SSherry Moore 				    cfg32);
20853db86aabSstevel 				cfg = ddi_get8(pcic->cfg_handle,
208619397407SSherry Moore 				    pcic->cfgaddr + PCIC_BRIDGE_CTL_REG);
20873db86aabSstevel 				cfg |= PCIC_FUN_INT_MOD_ISA;
20883db86aabSstevel 				ddi_put8(pcic->cfg_handle,
208919397407SSherry Moore 				    pcic->cfgaddr + PCIC_BRIDGE_CTL_REG,
209019397407SSherry Moore 				    cfg);
20913db86aabSstevel 				break;
20923db86aabSstevel 			case PCIC_INTR_MODE_PCI_1:
20933db86aabSstevel 				cfg32 &= ~PCIC_O2MICRO_ISA_LEGACY;
20943db86aabSstevel 				cfg32 |= PCIC_O2MICRO_INT_MOD_PCI;
20953db86aabSstevel 				ddi_put32(pcic->cfg_handle,
209619397407SSherry Moore 				    (uint32_t *)(pcic->cfgaddr +
209719397407SSherry Moore 				    PCIC_O2MICRO_MISC_CTL),
209819397407SSherry Moore 				    cfg32);
20993db86aabSstevel 				break;
21003db86aabSstevel 			}
21013db86aabSstevel 			break;
210219397407SSherry Moore 			case PCIC_RICOH_VENDOR:
21033db86aabSstevel 			if (pcic->pc_intr_mode == PCIC_INTR_MODE_ISA) {
21043db86aabSstevel 				cfg16 = ddi_get16(pcic->cfg_handle,
210519397407SSherry Moore 				    (uint16_t *)(pcic->cfgaddr +
210619397407SSherry Moore 				    PCIC_RICOH_MISC_CTL_2));
21073db86aabSstevel 				cfg16 |= (PCIC_RICOH_CSC_INT_MOD |
210819397407SSherry Moore 				    PCIC_RICOH_FUN_INT_MOD);
21093db86aabSstevel 				ddi_put16(pcic->cfg_handle,
211019397407SSherry Moore 				    (uint16_t *)(pcic->cfgaddr +
211119397407SSherry Moore 				    PCIC_RICOH_MISC_CTL_2),
211219397407SSherry Moore 				    cfg16);
21133db86aabSstevel 
21143db86aabSstevel 				cfg16 = ddi_get16(pcic->cfg_handle,
211519397407SSherry Moore 				    (uint16_t *)(pcic->cfgaddr +
211619397407SSherry Moore 				    PCIC_RICOH_MISC_CTL));
21173db86aabSstevel 				cfg16 |= PCIC_RICOH_SIRQ_EN;
21183db86aabSstevel 				ddi_put16(pcic->cfg_handle,
211919397407SSherry Moore 				    (uint16_t *)(pcic->cfgaddr +
212019397407SSherry Moore 				    PCIC_RICOH_MISC_CTL),
212119397407SSherry Moore 				    cfg16);
21223db86aabSstevel 
21233db86aabSstevel 				cfg = ddi_get8(pcic->cfg_handle,
212419397407SSherry Moore 				    pcic->cfgaddr + PCIC_BRIDGE_CTL_REG);
21253db86aabSstevel 				cfg |= PCIC_FUN_INT_MOD_ISA;
21263db86aabSstevel 				ddi_put8(pcic->cfg_handle,
212719397407SSherry Moore 				    pcic->cfgaddr + PCIC_BRIDGE_CTL_REG,
212819397407SSherry Moore 				    cfg);
21293db86aabSstevel 			}
21303db86aabSstevel 			break;
213119397407SSherry Moore 			default:
21323db86aabSstevel 			break;
21333db86aabSstevel 		} /* switch */
21343db86aabSstevel 
2135bb3a048dSrw 		/*
2136bb3a048dSrw 		 * The default value in the EEPROM (loaded on reset) for
2137bb3a048dSrw 		 * MFUNC0/MFUNC1 may be incorrect. Here we make sure that
2138bb3a048dSrw 		 * MFUNC0 is connected to INTA, and MFUNC1 is connected to
2139bb3a048dSrw 		 * INTB. This applies to all TI CardBus controllers.
2140bb3a048dSrw 		 */
2141bb3a048dSrw 		if ((pcic->pc_type >> 16) == PCIC_TI_VENDORID &&
214219397407SSherry Moore 		    pcic->pc_intr_mode == PCIC_INTR_MODE_PCI_1) {
2143bb3a048dSrw 			value = ddi_get32(pcic->cfg_handle,
2144bb3a048dSrw 			    (uint32_t *)(pcic->cfgaddr + PCIC_MFROUTE_REG));
2145bb3a048dSrw 			value &= ~0xff;
2146bb3a048dSrw 			ddi_put32(pcic->cfg_handle, (uint32_t *)(pcic->cfgaddr +
21478134ee03Srw 			    PCIC_MFROUTE_REG), value|PCIC_TI_MFUNC_SEL);
2148bb3a048dSrw 		}
2149bb3a048dSrw 
21503db86aabSstevel 		/* setup general card status change interrupt */
21513db86aabSstevel 		switch (pcic->pc_type) {
21523db86aabSstevel 			case PCIC_TI_PCI1225:
21533db86aabSstevel 			case PCIC_TI_PCI1221:
21543db86aabSstevel 			case PCIC_TI_PCI1031:
21553db86aabSstevel 			case PCIC_TI_PCI1520:
21563db86aabSstevel 			case PCIC_TI_PCI1410:
21573db86aabSstevel 				pcic_putb(pcic, i, PCIC_MANAGEMENT_INT,
21583db86aabSstevel 				    PCIC_CHANGE_DEFAULT);
21593db86aabSstevel 				break;
21603db86aabSstevel 			default:
21613db86aabSstevel 				if (pcic->pc_intr_mode ==
216219397407SSherry Moore 				    PCIC_INTR_MODE_PCI_1) {
21633db86aabSstevel 					pcic_putb(pcic, i, PCIC_MANAGEMENT_INT,
216419397407SSherry Moore 					    PCIC_CHANGE_DEFAULT);
21653db86aabSstevel 					break;
21663db86aabSstevel 				} else {
21673db86aabSstevel 					pcic_putb(pcic, i, PCIC_MANAGEMENT_INT,
216819397407SSherry Moore 					    PCIC_CHANGE_DEFAULT |
216919397407SSherry Moore 					    (pcic->pc_sockets[i].pcs_smi << 4));
21703db86aabSstevel 					break;
21713db86aabSstevel 				}
21723db86aabSstevel 		}
21733db86aabSstevel 
21743db86aabSstevel 		pcic->pc_flags |= PCF_INTRENAB;
21753db86aabSstevel 
21763db86aabSstevel 		/* take card out of RESET */
21773db86aabSstevel 		pcic_putb(pcic, i, PCIC_INTERRUPT, PCIC_RESET);
21783db86aabSstevel 		/* turn power off and let CS do this */
21793db86aabSstevel 		pcic_putb(pcic, i, PCIC_POWER_CONTROL, 0);
21803db86aabSstevel 
21813db86aabSstevel 		/* final chip specific initialization */
21823db86aabSstevel 		switch (pcic->pc_type) {
218319397407SSherry Moore 			case PCIC_VADEM:
21843db86aabSstevel 			pcic_putb(pcic, i, PCIC_VG_CONTROL,
218519397407SSherry Moore 			    PCIC_VC_DELAYENABLE);
21863db86aabSstevel 			pcic->pc_flags |= PCF_DEBOUNCE;
21873db86aabSstevel 			/* FALLTHROUGH */
218819397407SSherry Moore 			case PCIC_I82365SL:
21893db86aabSstevel 			pcic_putb(pcic, i, PCIC_GLOBAL_CONTROL,
219019397407SSherry Moore 			    PCIC_GC_CSC_WRITE);
21913db86aabSstevel 			/* clear any pending interrupts */
21923db86aabSstevel 			value = pcic_getb(pcic, i, PCIC_CARD_STATUS_CHANGE);
21933db86aabSstevel 			pcic_putb(pcic, i, PCIC_CARD_STATUS_CHANGE, value);
21943db86aabSstevel 			break;
21953db86aabSstevel 		    /* The 82092 uses PCI config space to enable interrupts */
219619397407SSherry Moore 			case PCIC_INTEL_i82092:
21973db86aabSstevel 			pcic_82092_smiirq_ctl(pcic, i, PCIC_82092_CTL_SMI,
219819397407SSherry Moore 			    PCIC_82092_INT_ENABLE);
21993db86aabSstevel 			break;
220019397407SSherry Moore 			case PCIC_CL_PD6729:
22013db86aabSstevel 			if (pcic->bus_speed >= PCIC_PCI_DEF_SYSCLK && i == 0) {
22023db86aabSstevel 				value = pcic_getb(pcic, i, PCIC_MISC_CTL_2);
22033db86aabSstevel 				pcic_putb(pcic, i, PCIC_MISC_CTL_2,
220419397407SSherry Moore 				    value | PCIC_CL_TIMER_CLK_DIV);
22053db86aabSstevel 			}
22063db86aabSstevel 			break;
22073db86aabSstevel 		} /* switch */
22083db86aabSstevel 
22093db86aabSstevel #if defined(PCIC_DEBUG)
22103db86aabSstevel 		if (pcic_debug)
22113db86aabSstevel 			cmn_err(CE_CONT,
221219397407SSherry Moore 			    "socket %d value=%x, flags = %x (%s)\n",
221319397407SSherry Moore 			    i, value, pcic->pc_sockets[i].pcs_flags,
221419397407SSherry Moore 			    (pcic->pc_sockets[i].pcs_flags &
221519397407SSherry Moore 			    PCS_CARD_PRESENT) ?
221619397407SSherry Moore 			"card present" : "no card");
22173db86aabSstevel #endif
22183db86aabSstevel 	}
22193db86aabSstevel }
22203db86aabSstevel 
22213db86aabSstevel /*
22223db86aabSstevel  * pcic_intr(caddr_t, caddr_t)
22233db86aabSstevel  *	interrupt handler for the PCIC style adapter
22243db86aabSstevel  *	handles all basic interrupts and also checks
22253db86aabSstevel  *	for status changes and notifies the nexus if
22263db86aabSstevel  *	necessary
22273db86aabSstevel  *
22283db86aabSstevel  *	On PCI bus adapters, also handles all card
22293db86aabSstevel  *	IO interrupts.
22303db86aabSstevel  */
22313db86aabSstevel /*ARGSUSED*/
22323db86aabSstevel uint32_t
pcic_intr(caddr_t arg1,caddr_t arg2)22333db86aabSstevel pcic_intr(caddr_t arg1, caddr_t arg2)
22343db86aabSstevel {
22353db86aabSstevel 	pcicdev_t *pcic = (pcicdev_t *)arg1;
22363db86aabSstevel 	int value = 0, i, ret = DDI_INTR_UNCLAIMED;
22373db86aabSstevel 	uint8_t status;
22383db86aabSstevel 	uint_t io_ints;
22393db86aabSstevel 
22403db86aabSstevel #if defined(PCIC_DEBUG)
22413db86aabSstevel 	pcic_err(pcic->dip, 0xf,
224219397407SSherry Moore 	    "pcic_intr: enter pc_flags=0x%x PCF_ATTACHED=0x%x"
224319397407SSherry Moore 	    " pc_numsockets=%d \n",
224419397407SSherry Moore 	    pcic->pc_flags, PCF_ATTACHED, pcic->pc_numsockets);
22453db86aabSstevel #endif
22463db86aabSstevel 
22473db86aabSstevel 	if (!(pcic->pc_flags & PCF_ATTACHED))
224819397407SSherry Moore 		return (DDI_INTR_UNCLAIMED);
22493db86aabSstevel 
22503db86aabSstevel 	mutex_enter(&pcic->intr_lock);
22513db86aabSstevel 
22523db86aabSstevel 	if (pcic->pc_flags & PCF_SUSPENDED) {
22533db86aabSstevel 		mutex_exit(&pcic->intr_lock);
22543db86aabSstevel 		return (ret);
22553db86aabSstevel 	}
22563db86aabSstevel 
22573db86aabSstevel 	/*
22583db86aabSstevel 	 * need to change to only ACK and touch the slot that
22593db86aabSstevel 	 * actually caused the interrupt.  Currently everything
22603db86aabSstevel 	 * is acked
22613db86aabSstevel 	 *
22623db86aabSstevel 	 * we need to look at all known sockets to determine
22633db86aabSstevel 	 * what might have happened, so step through the list
22643db86aabSstevel 	 * of them
22653db86aabSstevel 	 */
22663db86aabSstevel 
22673db86aabSstevel 	/*
22683db86aabSstevel 	 * Set the bitmask for IO interrupts to initially include all sockets
22693db86aabSstevel 	 */
22703db86aabSstevel 	io_ints = (1 << pcic->pc_numsockets) - 1;
22713db86aabSstevel 
22723db86aabSstevel 	for (i = 0; i < pcic->pc_numsockets; i++) {
22733db86aabSstevel 		int card_type;
22743db86aabSstevel 		pcic_socket_t *sockp;
22753db86aabSstevel 		int value_cb = 0;
22763db86aabSstevel 
22773db86aabSstevel 		sockp = &pcic->pc_sockets[i];
22783db86aabSstevel 		/* get the socket's I/O addresses */
22793db86aabSstevel 
22803db86aabSstevel 		if (sockp->pcs_flags & PCS_WAITING) {
22813db86aabSstevel 			io_ints &= ~(1 << i);
22823db86aabSstevel 			continue;
22833db86aabSstevel 		}
22843db86aabSstevel 
22853db86aabSstevel 		if (sockp->pcs_flags & PCS_CARD_IO)
22863db86aabSstevel 			card_type = IF_IO;
22873db86aabSstevel 		else
22883db86aabSstevel 			card_type = IF_MEMORY;
22893db86aabSstevel 
22903db86aabSstevel 		if (pcic->pc_io_type == PCIC_IO_TYPE_YENTA)
22913db86aabSstevel 			value_cb = pcic_getcb(pcic, CB_STATUS_EVENT);
22923db86aabSstevel 
22933db86aabSstevel 		value = pcic_change(pcic, i);
22943db86aabSstevel 
22953db86aabSstevel 		if ((value != 0) || (value_cb != 0)) {
22963db86aabSstevel 			int x = pcic->pc_cb_arg;
22973db86aabSstevel 
22983db86aabSstevel 			ret = DDI_INTR_CLAIMED;
22993db86aabSstevel 
23003db86aabSstevel #if defined(PCIC_DEBUG)
23013db86aabSstevel 			pcic_err(pcic->dip, 0x9,
23023db86aabSstevel 			    "card_type = %d, value_cb = 0x%x\n",
23033db86aabSstevel 			    card_type,
23043db86aabSstevel 			    value_cb ? value_cb :
230519397407SSherry Moore 			    pcic_getcb(pcic, CB_STATUS_EVENT));
23063db86aabSstevel 			if (pcic_debug)
23073db86aabSstevel 				cmn_err(CE_CONT,
230819397407SSherry Moore 				    "\tchange on socket %d (%x)\n", i,
230919397407SSherry Moore 				    value);
23103db86aabSstevel #endif
23113db86aabSstevel 			/* find out what happened */
23123db86aabSstevel 			status = pcic_getb(pcic, i, PCIC_INTERFACE_STATUS);
23133db86aabSstevel 
23143db86aabSstevel 			/* acknowledge the interrupt */
23153db86aabSstevel 			if (value_cb)
23163db86aabSstevel 				pcic_putcb(pcic, CB_STATUS_EVENT, value_cb);
23173db86aabSstevel 
23183db86aabSstevel 			if (value)
23193db86aabSstevel 				pcic_putb(pcic, i, PCIC_CARD_STATUS_CHANGE,
23203db86aabSstevel 				    value);
23213db86aabSstevel 
23223db86aabSstevel 			if (pcic->pc_callback == NULL) {
23233db86aabSstevel 				/* if not callback handler, nothing to do */
23243db86aabSstevel 				continue;
23253db86aabSstevel 			}
23263db86aabSstevel 
23273db86aabSstevel 			/* Card Detect */
23283db86aabSstevel 			if (value & PCIC_CD_DETECT ||
23293db86aabSstevel 			    value_cb & CB_PS_CCDMASK) {
23303db86aabSstevel 				uint8_t irq;
23313db86aabSstevel #if defined(PCIC_DEBUG)
23323db86aabSstevel 				if (pcic_debug)
23333db86aabSstevel 					cmn_err(CE_CONT,
233419397407SSherry Moore 					    "\tcd_detect: status=%x,"
233519397407SSherry Moore 					    " flags=%x\n",
233619397407SSherry Moore 					    status, sockp->pcs_flags);
23373db86aabSstevel #else
23383db86aabSstevel #ifdef lint
23393db86aabSstevel 				if (status == 0)
234019397407SSherry Moore 					status++;
23413db86aabSstevel #endif
23423db86aabSstevel #endif
23433db86aabSstevel 				/*
23443db86aabSstevel 				 * Turn off all interrupts for this socket here.
23453db86aabSstevel 				 */
23463db86aabSstevel 				irq = pcic_getb(pcic, sockp->pcs_socket,
23473db86aabSstevel 				    PCIC_MANAGEMENT_INT);
23483db86aabSstevel 				irq &= ~PCIC_CHANGE_MASK;
23493db86aabSstevel 				pcic_putb(pcic, sockp->pcs_socket,
23503db86aabSstevel 				    PCIC_MANAGEMENT_INT, irq);
23513db86aabSstevel 
23523db86aabSstevel 				pcic_putcb(pcic, CB_STATUS_MASK, 0x0);
23533db86aabSstevel 
23540d282d13Srw 				/*
23550d282d13Srw 				 * Put the socket in debouncing state so that
23560d282d13Srw 				 * the leaf driver won't receive interrupts.
23570d282d13Srw 				 * Crucial for handling surprise-removal.
23580d282d13Srw 				 */
23590d282d13Srw 				sockp->pcs_flags |= PCS_DEBOUNCING;
23600d282d13Srw 
23613db86aabSstevel 				if (!sockp->pcs_cd_softint_flg) {
23623db86aabSstevel 					sockp->pcs_cd_softint_flg = 1;
23633db86aabSstevel 					(void) ddi_intr_trigger_softint(
23643db86aabSstevel 					    sockp->pcs_cd_softint_hdl, NULL);
23653db86aabSstevel 				}
23663db86aabSstevel 
23673db86aabSstevel 				io_ints &= ~(1 << i);
23683db86aabSstevel 			} /* PCIC_CD_DETECT */
23693db86aabSstevel 
23703db86aabSstevel 			/* Ready/Change Detect */
23713db86aabSstevel 			sockp->pcs_state ^= SBM_RDYBSY;
23723db86aabSstevel 			if (card_type == IF_MEMORY && value & PCIC_RD_DETECT) {
23733db86aabSstevel 				sockp->pcs_flags |= PCS_READY;
23743db86aabSstevel 				PC_CALLBACK(pcic->dip, x, PCE_CARD_READY, i);
23753db86aabSstevel 			}
23763db86aabSstevel 
23773db86aabSstevel 			/* Battery Warn Detect */
23783db86aabSstevel 			if (card_type == IF_MEMORY &&
23793db86aabSstevel 			    value & PCIC_BW_DETECT &&
23803db86aabSstevel 			    !(sockp->pcs_state & SBM_BVD2)) {
23813db86aabSstevel 				sockp->pcs_state |= SBM_BVD2;
23823db86aabSstevel 				PC_CALLBACK(pcic->dip, x,
238319397407SSherry Moore 				    PCE_CARD_BATTERY_WARN, i);
23843db86aabSstevel 			}
23853db86aabSstevel 
23863db86aabSstevel 			/* Battery Dead Detect */
23873db86aabSstevel 			if (value & PCIC_BD_DETECT) {
23883db86aabSstevel 				/*
23893db86aabSstevel 				 * need to work out event if RI not enabled
23903db86aabSstevel 				 * and card_type == IF_IO
23913db86aabSstevel 				 */
23923db86aabSstevel 				if (card_type == IF_MEMORY &&
239319397407SSherry Moore 				    !(sockp->pcs_state & SBM_BVD1)) {
23943db86aabSstevel 					sockp->pcs_state |= SBM_BVD1;
23953db86aabSstevel 					PC_CALLBACK(pcic->dip, x,
239619397407SSherry Moore 					    PCE_CARD_BATTERY_DEAD,
239719397407SSherry Moore 					    i);
23983db86aabSstevel 				} else {
23993db86aabSstevel 					/*
24003db86aabSstevel 					 * information in pin replacement
24013db86aabSstevel 					 * register if one is available
24023db86aabSstevel 					 */
24033db86aabSstevel 					PC_CALLBACK(pcic->dip, x,
240419397407SSherry Moore 					    PCE_CARD_STATUS_CHANGE,
240519397407SSherry Moore 					    i);
24063db86aabSstevel 				} /* IF_MEMORY */
24073db86aabSstevel 			} /* PCIC_BD_DETECT */
24083db86aabSstevel 		} /* if pcic_change */
24093db86aabSstevel 		/*
24103db86aabSstevel 		 * for any controllers that we can detect whether a socket
24113db86aabSstevel 		 * had an interrupt for the PC Card, we should sort that out
24123db86aabSstevel 		 * here.
24133db86aabSstevel 		 */
24143db86aabSstevel 	} /* for pc_numsockets */
24153db86aabSstevel 
24163db86aabSstevel 	/*
24173db86aabSstevel 	 * If we're on a PCI bus, we may need to cycle through each IO
24183db86aabSstevel 	 *	interrupt handler that is registered since they all
24193db86aabSstevel 	 *	share the same interrupt line.
24203db86aabSstevel 	 */
24213db86aabSstevel 
24223db86aabSstevel 
24233db86aabSstevel #if defined(PCIC_DEBUG)
24243db86aabSstevel 	pcic_err(pcic->dip, 0xf,
24253db86aabSstevel 	    "pcic_intr: pc_intr_mode=%d pc_type=%x io_ints=0x%x\n",
24263db86aabSstevel 	    pcic->pc_intr_mode, pcic->pc_type, io_ints);
24273db86aabSstevel #endif
24283db86aabSstevel 
24290d282d13Srw 	if (io_ints) {
24300d282d13Srw 		if (pcic_do_io_intr(pcic, io_ints) == DDI_INTR_CLAIMED)
24313db86aabSstevel 			ret = DDI_INTR_CLAIMED;
24323db86aabSstevel 	}
24333db86aabSstevel 
24343db86aabSstevel 	mutex_exit(&pcic->intr_lock);
24353db86aabSstevel 
24363db86aabSstevel #if defined(PCIC_DEBUG)
24373db86aabSstevel 	pcic_err(pcic->dip, 0xf,
24383db86aabSstevel 	    "pcic_intr: ret=%d value=%d DDI_INTR_CLAIMED=%d\n",
24393db86aabSstevel 	    ret, value, DDI_INTR_CLAIMED);
24403db86aabSstevel #endif
24413db86aabSstevel 
24423db86aabSstevel 	return (ret);
24433db86aabSstevel }
24443db86aabSstevel 
24453db86aabSstevel /*
24463db86aabSstevel  * pcic_change()
24473db86aabSstevel  *	check to see if this socket had a change in state
24483db86aabSstevel  *	by checking the status change register
24493db86aabSstevel  */
24503db86aabSstevel static int
pcic_change(pcicdev_t * pcic,int socket)24513db86aabSstevel pcic_change(pcicdev_t *pcic, int socket)
24523db86aabSstevel {
24533db86aabSstevel 	return (pcic_getb(pcic, socket, PCIC_CARD_STATUS_CHANGE));
24543db86aabSstevel }
24553db86aabSstevel 
24563db86aabSstevel /*
24573db86aabSstevel  * pcic_do_io_intr - calls client interrupt handlers
24583db86aabSstevel  */
24593db86aabSstevel static int
pcic_do_io_intr(pcicdev_t * pcic,uint32_t sockets)24603db86aabSstevel pcic_do_io_intr(pcicdev_t *pcic, uint32_t sockets)
24613db86aabSstevel {
24623db86aabSstevel 	inthandler_t *tmp;
24633db86aabSstevel 	int ret = DDI_INTR_UNCLAIMED;
24643db86aabSstevel 
24653db86aabSstevel #if defined(PCIC_DEBUG)
24663db86aabSstevel 	pcic_err(pcic->dip, 0xf,
246719397407SSherry Moore 	    "pcic_do_io_intr: pcic=%p sockets=%d irq_top=%p\n",
246819397407SSherry Moore 	    (void *)pcic, (int)sockets, (void *)pcic->irq_top);
24693db86aabSstevel #endif
24703db86aabSstevel 
24713db86aabSstevel 	if (pcic->irq_top != NULL) {
247219397407SSherry Moore 		tmp = pcic->irq_current;
24733db86aabSstevel 
247419397407SSherry Moore 		do {
24753db86aabSstevel 		int cur = pcic->irq_current->socket;
24763db86aabSstevel 		pcic_socket_t *sockp =
247719397407SSherry Moore 		    &pcic->pc_sockets[cur];
24783db86aabSstevel 
24793db86aabSstevel #if defined(PCIC_DEBUG)
24803db86aabSstevel 		pcic_err(pcic->dip, 0xf,
24813db86aabSstevel 		    "\t pcs_flags=0x%x PCS_CARD_PRESENT=0x%x\n",
24823db86aabSstevel 		    sockp->pcs_flags, PCS_CARD_PRESENT);
24833db86aabSstevel 		pcic_err(pcic->dip, 0xf,
24843db86aabSstevel 		    "\t sockets=%d cur=%d intr=%p arg1=%p "
24853db86aabSstevel 		    "arg2=%p\n",
24863db86aabSstevel 		    sockets, cur, (void *)pcic->irq_current->intr,
24873db86aabSstevel 		    pcic->irq_current->arg1,
24883db86aabSstevel 		    pcic->irq_current->arg2);
24893db86aabSstevel #endif
24900d282d13Srw 		if ((sockp->pcs_flags & PCS_CARD_PRESENT) &&
24910d282d13Srw 		    !(sockp->pcs_flags & PCS_DEBOUNCING) &&
24920d282d13Srw 		    (sockets & (1 << cur))) {
24933db86aabSstevel 
24943db86aabSstevel 			if ((*pcic->irq_current->intr)(pcic->irq_current->arg1,
24953db86aabSstevel 			    pcic->irq_current->arg2) == DDI_INTR_CLAIMED)
24963db86aabSstevel 				ret = DDI_INTR_CLAIMED;
24973db86aabSstevel 
24983db86aabSstevel #if defined(PCIC_DEBUG)
24993db86aabSstevel 			pcic_err(pcic->dip, 0xf,
25003db86aabSstevel 			    "\t ret=%d DDI_INTR_CLAIMED=%d\n",
25013db86aabSstevel 			    ret, DDI_INTR_CLAIMED);
25023db86aabSstevel #endif
25033db86aabSstevel 		}
25043db86aabSstevel 
25053db86aabSstevel 
25063db86aabSstevel 		if ((pcic->irq_current = pcic->irq_current->next) == NULL)
25073db86aabSstevel 					pcic->irq_current = pcic->irq_top;
25083db86aabSstevel 
250919397407SSherry Moore 		} while (pcic->irq_current != tmp);
25103db86aabSstevel 
251119397407SSherry Moore 		if ((pcic->irq_current = pcic->irq_current->next) == NULL)
25123db86aabSstevel 					pcic->irq_current = pcic->irq_top;
25133db86aabSstevel 
25143db86aabSstevel 	} else {
25153db86aabSstevel 		ret = DDI_INTR_UNCLAIMED;
25163db86aabSstevel 	}
25173db86aabSstevel 
25183db86aabSstevel #if defined(PCIC_DEBUG)
25193db86aabSstevel 	pcic_err(pcic->dip, 0xf,
252019397407SSherry Moore 	    "pcic_do_io_intr: exit ret=%d DDI_INTR_CLAIMED=%d\n",
252119397407SSherry Moore 	    ret, DDI_INTR_CLAIMED);
25223db86aabSstevel #endif
25233db86aabSstevel 
25243db86aabSstevel 	return (ret);
25253db86aabSstevel 
25263db86aabSstevel }
25273db86aabSstevel 
25283db86aabSstevel /*
25293db86aabSstevel  * pcic_inquire_adapter()
25303db86aabSstevel  *	SocketServices InquireAdapter function
25313db86aabSstevel  *	get characteristics of the physical adapter
25323db86aabSstevel  */
25333db86aabSstevel /*ARGSUSED*/
25343db86aabSstevel static int
pcic_inquire_adapter(dev_info_t * dip,inquire_adapter_t * config)25353db86aabSstevel pcic_inquire_adapter(dev_info_t *dip, inquire_adapter_t *config)
25363db86aabSstevel {
25373db86aabSstevel 	anp_t *anp = ddi_get_driver_private(dip);
25383db86aabSstevel 	pcicdev_t *pcic = anp->an_private;
25393db86aabSstevel 
25403db86aabSstevel 	config->NumSockets = pcic->pc_numsockets;
25413db86aabSstevel 	config->NumWindows = pcic->pc_numsockets * PCIC_NUMWINSOCK;
25423db86aabSstevel 	config->NumEDCs = 0;
25433db86aabSstevel 	config->AdpCaps = 0;
25443db86aabSstevel 	config->ActiveHigh = 0;
25453db86aabSstevel 	config->ActiveLow = PCIC_AVAIL_IRQS;
25463db86aabSstevel 	config->NumPower = pcic->pc_numpower;
25473db86aabSstevel 	config->power_entry = pcic->pc_power; /* until we resolve this */
25483db86aabSstevel #if defined(PCIC_DEBUG)
25493db86aabSstevel 	if (pcic_debug) {
25503db86aabSstevel 		cmn_err(CE_CONT, "pcic_inquire_adapter:\n");
25513db86aabSstevel 		cmn_err(CE_CONT, "\tNumSockets=%d\n", config->NumSockets);
25523db86aabSstevel 		cmn_err(CE_CONT, "\tNumWindows=%d\n", config->NumWindows);
25533db86aabSstevel 	}
25543db86aabSstevel #endif
25553db86aabSstevel 	config->ResourceFlags = 0;
25563db86aabSstevel 	switch (pcic->pc_intr_mode) {
25573db86aabSstevel 	case PCIC_INTR_MODE_PCI_1:
25583db86aabSstevel 		config->ResourceFlags |= RES_OWN_IRQ | RES_IRQ_NEXUS |
255919397407SSherry Moore 		    RES_IRQ_SHAREABLE;
25603db86aabSstevel 		break;
25613db86aabSstevel 	}
25623db86aabSstevel 	return (SUCCESS);
25633db86aabSstevel }
25643db86aabSstevel 
25653db86aabSstevel /*
25663db86aabSstevel  * pcic_callback()
25673db86aabSstevel  *	The PCMCIA nexus calls us via this function
25683db86aabSstevel  *	in order to set the callback function we are
25693db86aabSstevel  *	to call the nexus with
25703db86aabSstevel  */
25713db86aabSstevel /*ARGSUSED*/
25723db86aabSstevel static int
pcic_callback(dev_info_t * dip,int (* handler)(),int arg)25733db86aabSstevel pcic_callback(dev_info_t *dip, int (*handler)(), int arg)
25743db86aabSstevel {
25753db86aabSstevel 	anp_t *anp = ddi_get_driver_private(dip);
25763db86aabSstevel 	pcicdev_t *pcic = anp->an_private;
25773db86aabSstevel 
25783db86aabSstevel 	if (handler != NULL) {
25793db86aabSstevel 		pcic->pc_callback = handler;
25803db86aabSstevel 		pcic->pc_cb_arg  = arg;
25813db86aabSstevel 		pcic->pc_flags |= PCF_CALLBACK;
25823db86aabSstevel 	} else {
25833db86aabSstevel 		pcic->pc_callback = NULL;
25843db86aabSstevel 		pcic->pc_cb_arg = 0;
25853db86aabSstevel 		pcic->pc_flags &= ~PCF_CALLBACK;
25863db86aabSstevel 	}
25873db86aabSstevel 	/*
25883db86aabSstevel 	 * we're now registered with the nexus
25893db86aabSstevel 	 * it is acceptable to do callbacks at this point.
25903db86aabSstevel 	 * don't call back from here though since it could block
25913db86aabSstevel 	 */
25923db86aabSstevel 	return (PC_SUCCESS);
25933db86aabSstevel }
25943db86aabSstevel 
25953db86aabSstevel /*
25963db86aabSstevel  * pcic_calc_speed (pcicdev_t *pcic, uint32_t speed)
25973db86aabSstevel  *	calculate the speed bits from the specified memory speed
25983db86aabSstevel  *	there may be more to do here
25993db86aabSstevel  */
26003db86aabSstevel 
26013db86aabSstevel static int
pcic_calc_speed(pcicdev_t * pcic,uint32_t speed)26023db86aabSstevel pcic_calc_speed(pcicdev_t *pcic, uint32_t speed)
26033db86aabSstevel {
26043db86aabSstevel 	uint32_t wspeed = 1;	/* assume 1 wait state when unknown */
26053db86aabSstevel 	uint32_t bspeed = PCIC_ISA_DEF_SYSCLK;
26063db86aabSstevel 
26073db86aabSstevel 	switch (pcic->pc_type) {
260819397407SSherry Moore 		case PCIC_I82365SL:
260919397407SSherry Moore 		case PCIC_VADEM:
261019397407SSherry Moore 		case PCIC_VADEM_VG469:
261119397407SSherry Moore 		default:
26123db86aabSstevel 		/* Intel chip wants it in waitstates */
26133db86aabSstevel 		wspeed = mhztons(PCIC_ISA_DEF_SYSCLK) * 3;
26143db86aabSstevel 		if (speed <= wspeed)
26153db86aabSstevel 			wspeed = 0;
26163db86aabSstevel 		else if (speed <= (wspeed += mhztons(bspeed)))
26173db86aabSstevel 			wspeed = 1;
26183db86aabSstevel 		else if (speed <= (wspeed += mhztons(bspeed)))
26193db86aabSstevel 			wspeed = 2;
26203db86aabSstevel 		else
26213db86aabSstevel 			wspeed = 3;
26223db86aabSstevel 		wspeed <<= 6; /* put in right bit positions */
26233db86aabSstevel 		break;
26243db86aabSstevel 
262519397407SSherry Moore 		case PCIC_INTEL_i82092:
26263db86aabSstevel 		wspeed = SYSMEM_82092_80NS;
26273db86aabSstevel 		if (speed > 80)
262819397407SSherry Moore 			wspeed = SYSMEM_82092_100NS;
26293db86aabSstevel 		if (speed > 100)
263019397407SSherry Moore 			wspeed = SYSMEM_82092_150NS;
26313db86aabSstevel 		if (speed > 150)
263219397407SSherry Moore 			wspeed = SYSMEM_82092_200NS;
26333db86aabSstevel 		if (speed > 200)
263419397407SSherry Moore 			wspeed = SYSMEM_82092_250NS;
26353db86aabSstevel 		if (speed > 250)
263619397407SSherry Moore 			wspeed = SYSMEM_82092_600NS;
26373db86aabSstevel 		wspeed <<= 5;	/* put in right bit positions */
26383db86aabSstevel 		break;
26393db86aabSstevel 
26403db86aabSstevel 	} /* switch */
26413db86aabSstevel 
26423db86aabSstevel 	return (wspeed);
26433db86aabSstevel }
26443db86aabSstevel 
26453db86aabSstevel /*
26463db86aabSstevel  * These values are taken from the PC Card Standard Electrical Specification.
26473db86aabSstevel  * Generally the larger value is taken if 2 are possible.
26483db86aabSstevel  */
26493db86aabSstevel static struct pcic_card_times {
265048bbca81SDaniel Hoffman 	uint16_t cycle;	/* Speed as found in the atribute space of the card. */
26513db86aabSstevel 	uint16_t setup;	/* Corresponding address setup time. */
26523db86aabSstevel 	uint16_t width;	/* Corresponding width, OE or WE. */
26533db86aabSstevel 	uint16_t hold;	/* Corresponding data or address hold time. */
26543db86aabSstevel } pcic_card_times[] = {
26553db86aabSstevel 
26563db86aabSstevel /*
26573db86aabSstevel  * Note: The rounded up times for 250, 200 & 150 have been increased
26583db86aabSstevel  * due to problems with the 3-Com ethernet cards (pcelx) on UBIIi.
26593db86aabSstevel  * See BugID 00663.
26603db86aabSstevel  */
26613db86aabSstevel 
26623db86aabSstevel /*
26633db86aabSstevel  * Rounded up times           Original times from
26643db86aabSstevel  * that add up to the         the PCMCIA Spec.
26653db86aabSstevel  * cycle time.
26663db86aabSstevel  */
26673db86aabSstevel 	{600, 180, 370, 140},	/* 100, 300,  70 */
26683db86aabSstevel 	{400, 120, 300, 90},	/* Made this one up */
26693db86aabSstevel 	{250, 100, 190, 70},	/*  30, 150,  30 */
26703db86aabSstevel 	{200, 80, 170, 70},	/*  20, 120,  30 */
26713db86aabSstevel 	{150, 50, 110, 40},	/*  20,  80,  20 */
26723db86aabSstevel 	{100, 40, 80, 40},	/*  10,  60,  15 */
26733db86aabSstevel 	{0, 10, 60, 15}		/*  10,  60,  15 */
26743db86aabSstevel };
26753db86aabSstevel 
26763db86aabSstevel /*
26773db86aabSstevel  * pcic_set_cdtimers
26783db86aabSstevel  *	This is specific to several Cirrus Logic chips
26793db86aabSstevel  */
26803db86aabSstevel static void
pcic_set_cdtimers(pcicdev_t * pcic,int socket,uint32_t speed,int tset)26813db86aabSstevel pcic_set_cdtimers(pcicdev_t *pcic, int socket, uint32_t speed, int tset)
26823db86aabSstevel {
26833db86aabSstevel 	int cmd, set, rec, offset, clk_pulse;
26843db86aabSstevel 	struct pcic_card_times *ctp;
26853db86aabSstevel 
26863db86aabSstevel 	if ((tset == IOMEM_CLTIMER_SET_1) || (tset == SYSMEM_CLTIMER_SET_1))
26873db86aabSstevel 		offset = 3;
26883db86aabSstevel 	else
26893db86aabSstevel 		offset = 0;
26903db86aabSstevel 
26913db86aabSstevel 	clk_pulse = mhztons(pcic->bus_speed);
269219397407SSherry Moore 	for (ctp = pcic_card_times; speed < ctp->cycle; ctp++)
269319397407SSherry Moore 		;
26943db86aabSstevel 
26953db86aabSstevel 	/*
26963db86aabSstevel 	 * Add (clk_pulse/2) and an extra 1 to account for rounding errors.
26973db86aabSstevel 	 */
26983db86aabSstevel 	set = ((ctp->setup + 10 + 1 + (clk_pulse/2))/clk_pulse) - 1;
26993db86aabSstevel 	if (set < 0)
27003db86aabSstevel 		set = 0;
27013db86aabSstevel 
27023db86aabSstevel 	cmd = ((ctp->width + 10 + 1 + (clk_pulse/2))/clk_pulse) - 1;
27033db86aabSstevel 	if (cmd < 0)
27043db86aabSstevel 		cmd = 0;
27053db86aabSstevel 
27063db86aabSstevel 	rec = ((ctp->hold + 10 + 1 + (clk_pulse/2))/clk_pulse) - 2;
27073db86aabSstevel 	if (rec < 0)
27083db86aabSstevel 		rec = 0;
27093db86aabSstevel 
27103db86aabSstevel #if defined(PCIC_DEBUG)
27113db86aabSstevel 	pcic_err(pcic->dip, 8, "pcic_set_cdtimers(%d, Timer Set %d)\n"
27123db86aabSstevel 	    "ct=%d, cp=%d, cmd=0x%x, setup=0x%x, rec=0x%x\n",
27133db86aabSstevel 	    (unsigned)speed, offset == 3 ? 1 : 0,
27143db86aabSstevel 	    ctp->cycle, clk_pulse, cmd, set, rec);
27153db86aabSstevel #endif
27163db86aabSstevel 
27173db86aabSstevel 	pcic_putb(pcic, socket, PCIC_TIME_COMMAND_0 + offset, cmd);
27183db86aabSstevel 	pcic_putb(pcic, socket, PCIC_TIME_SETUP_0 + offset, set);
27193db86aabSstevel 	pcic_putb(pcic, socket, PCIC_TIME_RECOVER_0 + offset, rec);
27203db86aabSstevel }
27213db86aabSstevel 
27223db86aabSstevel /*
27233db86aabSstevel  * pcic_set_window
27243db86aabSstevel  *	essentially the same as the Socket Services specification
27253db86aabSstevel  *	We use socket and not adapter since they are identifiable
27263db86aabSstevel  *	but the rest is the same
27273db86aabSstevel  *
27283db86aabSstevel  *	dip	pcic driver's device information
27293db86aabSstevel  *	window	parameters for the request
27303db86aabSstevel  */
27313db86aabSstevel static int
pcic_set_window(dev_info_t * dip,set_window_t * window)27323db86aabSstevel pcic_set_window(dev_info_t *dip, set_window_t *window)
27333db86aabSstevel {
27343db86aabSstevel 	anp_t *anp = ddi_get_driver_private(dip);
27353db86aabSstevel 	pcicdev_t *pcic = anp->an_private;
27363db86aabSstevel 	int select;
27373db86aabSstevel 	int socket, pages, which, ret;
27383db86aabSstevel 	pcic_socket_t *sockp = &pcic->pc_sockets[window->socket];
27393db86aabSstevel 	ra_return_t res;
27403db86aabSstevel 	ndi_ra_request_t req;
27413db86aabSstevel 	uint32_t base = window->base;
27423db86aabSstevel 
27433db86aabSstevel #if defined(PCIC_DEBUG)
27443db86aabSstevel 	if (pcic_debug) {
27453db86aabSstevel 		cmn_err(CE_CONT, "pcic_set_window: entered\n");
27463db86aabSstevel 		cmn_err(CE_CONT,
274719397407SSherry Moore 		    "\twindow=%d, socket=%d, WindowSize=%d, speed=%d\n",
274819397407SSherry Moore 		    window->window, window->socket, window->WindowSize,
274919397407SSherry Moore 		    window->speed);
27503db86aabSstevel 		cmn_err(CE_CONT,
275119397407SSherry Moore 		    "\tbase=%x, state=%x\n", (unsigned)window->base,
275219397407SSherry Moore 		    (unsigned)window->state);
27533db86aabSstevel 	}
27543db86aabSstevel #endif
27553db86aabSstevel 
27563db86aabSstevel 	/*
27573db86aabSstevel 	 * do some basic sanity checking on what we support
27583db86aabSstevel 	 * we don't do paged mode
27593db86aabSstevel 	 */
27603db86aabSstevel 	if (window->state & WS_PAGED) {
27613db86aabSstevel 		cmn_err(CE_WARN, "pcic_set_window: BAD_ATTRIBUTE\n");
27623db86aabSstevel 		return (BAD_ATTRIBUTE);
27633db86aabSstevel 	}
27643db86aabSstevel 
27653db86aabSstevel 	/*
27663db86aabSstevel 	 * we don't care about previous mappings.
27673db86aabSstevel 	 * Card Services will deal with that so don't
27683db86aabSstevel 	 * even check
27693db86aabSstevel 	 */
27703db86aabSstevel 
27713db86aabSstevel 	socket = window->socket;
27723db86aabSstevel 
27733db86aabSstevel 	if (!(window->state & WS_IO)) {
27743db86aabSstevel 		int win, tmp;
27753db86aabSstevel 		pcs_memwin_t *memp;
27763db86aabSstevel #if defined(PCIC_DEBUG)
27773db86aabSstevel 		if (pcic_debug)
27783db86aabSstevel 			cmn_err(CE_CONT, "\twindow type is memory\n");
27793db86aabSstevel #endif
27803db86aabSstevel 		/* this is memory window mapping */
27813db86aabSstevel 		win = window->window % PCIC_NUMWINSOCK;
27823db86aabSstevel 		tmp = window->window / PCIC_NUMWINSOCK;
27833db86aabSstevel 
27843db86aabSstevel 		/* only windows 2-6 can do memory mapping */
27853db86aabSstevel 		if (tmp != window->socket || win < PCIC_IOWINDOWS) {
27863db86aabSstevel 			cmn_err(CE_CONT,
278719397407SSherry Moore 			    "\tattempt to map to non-mem window\n");
27883db86aabSstevel 			return (BAD_WINDOW);
27893db86aabSstevel 		}
27903db86aabSstevel 
27913db86aabSstevel 		if (window->WindowSize == 0)
27923db86aabSstevel 			window->WindowSize = MEM_MIN;
27933db86aabSstevel 		else if ((window->WindowSize & (PCIC_PAGE-1)) != 0) {
27943db86aabSstevel 			cmn_err(CE_WARN, "pcic_set_window: BAD_SIZE\n");
27953db86aabSstevel 			return (BAD_SIZE);
27963db86aabSstevel 		}
27973db86aabSstevel 
27983db86aabSstevel 		mutex_enter(&pcic->pc_lock); /* protect the registers */
27993db86aabSstevel 
28003db86aabSstevel 		memp = &sockp->pcs_windows[win].mem;
28013db86aabSstevel 		memp->pcw_speed = window->speed;
28023db86aabSstevel 
28033db86aabSstevel 		win -= PCIC_IOWINDOWS; /* put in right range */
28043db86aabSstevel 
28053db86aabSstevel 		if (window->WindowSize != memp->pcw_len)
28063db86aabSstevel 			which = memp->pcw_len;
28073db86aabSstevel 		else
28083db86aabSstevel 			which = 0;
28093db86aabSstevel 
28103db86aabSstevel 		if (window->state & WS_ENABLED) {
28113db86aabSstevel 			uint32_t wspeed;
28123db86aabSstevel #if defined(PCIC_DEBUG)
28133db86aabSstevel 			if (pcic_debug) {
28143db86aabSstevel 				cmn_err(CE_CONT,
281519397407SSherry Moore 				    "\tbase=%x, win=%d\n", (unsigned)base,
281619397407SSherry Moore 				    win);
28173db86aabSstevel 				if (which)
28183db86aabSstevel 					cmn_err(CE_CONT,
281919397407SSherry Moore 					    "\tneed to remap window\n");
28203db86aabSstevel 			}
28213db86aabSstevel #endif
28223db86aabSstevel 
28233db86aabSstevel 			if (which && (memp->pcw_status & PCW_MAPPED)) {
28243db86aabSstevel 				ddi_regs_map_free(&memp->pcw_handle);
28253db86aabSstevel 				res.ra_addr_lo = memp->pcw_base;
28263db86aabSstevel 				res.ra_len = memp->pcw_len;
28278134ee03Srw 				(void) pcmcia_free_mem(memp->res_dip, &res);
28283db86aabSstevel 				memp->pcw_status &= ~(PCW_MAPPED|PCW_ENABLED);
28293db86aabSstevel 				memp->pcw_hostmem = NULL;
2830f6c5b045SToomas Soome 				memp->pcw_base = 0;
28313db86aabSstevel 				memp->pcw_len = 0;
28323db86aabSstevel 			}
28333db86aabSstevel 
28343db86aabSstevel 			which = window->WindowSize >> PAGE_SHIFT;
28353db86aabSstevel 
28363db86aabSstevel 			if (!(memp->pcw_status & PCW_MAPPED)) {
28373db86aabSstevel 				ret = 0;
28383db86aabSstevel 
28393db86aabSstevel 				memp->pcw_base = base;
28403db86aabSstevel 				bzero(&req, sizeof (req));
28413db86aabSstevel 				req.ra_len = which << PAGE_SHIFT;
28423db86aabSstevel 				req.ra_addr = (uint64_t)memp->pcw_base;
28433db86aabSstevel 				req.ra_boundbase = pcic->pc_base;
28443db86aabSstevel 				req.ra_boundlen  = pcic->pc_bound;
28453db86aabSstevel 				req.ra_flags = (memp->pcw_base ?
284619397407SSherry Moore 				    NDI_RA_ALLOC_SPECIFIED : 0) |
284719397407SSherry Moore 				    NDI_RA_ALLOC_BOUNDED;
28483db86aabSstevel 				req.ra_align_mask =
284919397407SSherry Moore 				    (PAGESIZE - 1) | (PCIC_PAGE - 1);
28503db86aabSstevel #if defined(PCIC_DEBUG)
285119397407SSherry Moore 					pcic_err(dip, 8,
28523db86aabSstevel 					    "\tlen 0x%"PRIx64
28533db86aabSstevel 					    "addr 0x%"PRIx64"bbase 0x%"PRIx64
28543db86aabSstevel 					    " blen 0x%"PRIx64" flags 0x%x"
28553db86aabSstevel 					    " algn 0x%"PRIx64"\n",
28563db86aabSstevel 					    req.ra_len, req.ra_addr,
28573db86aabSstevel 					    req.ra_boundbase,
28583db86aabSstevel 					    req.ra_boundlen, req.ra_flags,
28593db86aabSstevel 					    req.ra_align_mask);
28603db86aabSstevel #endif
28613db86aabSstevel 
28628134ee03Srw 				ret = pcmcia_alloc_mem(dip, &req, &res,
286319397407SSherry Moore 				    &memp->res_dip);
28643db86aabSstevel 				if (ret == DDI_FAILURE) {
28653db86aabSstevel 					mutex_exit(&pcic->pc_lock);
28663db86aabSstevel 					cmn_err(CE_WARN,
28673db86aabSstevel 					"\tpcmcia_alloc_mem() failed\n");
28683db86aabSstevel 					return (BAD_SIZE);
28693db86aabSstevel 				}
28703db86aabSstevel 				memp->pcw_base = res.ra_addr_lo;
28713db86aabSstevel 				base = memp->pcw_base;
28723db86aabSstevel 
28733db86aabSstevel #if defined(PCIC_DEBUG)
28743db86aabSstevel 				if (pcic_debug)
28753db86aabSstevel 					cmn_err(CE_CONT,
287619397407SSherry Moore 					    "\tsetwindow: new base=%x\n",
287719397407SSherry Moore 					    (unsigned)memp->pcw_base);
28783db86aabSstevel #endif
28793db86aabSstevel 				memp->pcw_len = window->WindowSize;
28803db86aabSstevel 
28813db86aabSstevel 				which = pcmcia_map_reg(pcic->dip,
288219397407SSherry Moore 				    window->child,
288319397407SSherry Moore 				    &res,
288419397407SSherry Moore 				    (uint32_t)(window->state &
288519397407SSherry Moore 				    0xffff) |
288619397407SSherry Moore 				    (window->socket << 16),
288719397407SSherry Moore 				    (caddr_t *)&memp->pcw_hostmem,
288819397407SSherry Moore 				    &memp->pcw_handle,
2889f6c5b045SToomas Soome 				    &window->attr, 0);
28903db86aabSstevel 
28913db86aabSstevel 				if (which != DDI_SUCCESS) {
28923db86aabSstevel 
28933db86aabSstevel 					cmn_err(CE_WARN, "\tpcmcia_map_reg() "
289419397407SSherry Moore 					    "failed\n");
28953db86aabSstevel 
289619397407SSherry Moore 					res.ra_addr_lo = memp->pcw_base;
289719397407SSherry Moore 					res.ra_len = memp->pcw_len;
289819397407SSherry Moore 					(void) pcmcia_free_mem(memp->res_dip,
289919397407SSherry Moore 					    &res);
29003db86aabSstevel 
290119397407SSherry Moore 					mutex_exit(&pcic->pc_lock);
29023db86aabSstevel 
290319397407SSherry Moore 					return (BAD_WINDOW);
29043db86aabSstevel 				}
29053db86aabSstevel 				memp->pcw_status |= PCW_MAPPED;
29063db86aabSstevel #if defined(PCIC_DEBUG)
29073db86aabSstevel 				if (pcic_debug)
29083db86aabSstevel 					cmn_err(CE_CONT,
290919397407SSherry Moore 					    "\tmap=%x, hostmem=%p\n",
291019397407SSherry Moore 					    which,
291119397407SSherry Moore 					    (void *)memp->pcw_hostmem);
29123db86aabSstevel #endif
29133db86aabSstevel 			} else {
29143db86aabSstevel 				base = memp->pcw_base;
29153db86aabSstevel 			}
29163db86aabSstevel 
29173db86aabSstevel 			/* report the handle back to caller */
29183db86aabSstevel 			window->handle = memp->pcw_handle;
29193db86aabSstevel 
29203db86aabSstevel #if defined(PCIC_DEBUG)
29213db86aabSstevel 			if (pcic_debug) {
29223db86aabSstevel 				cmn_err(CE_CONT,
292319397407SSherry Moore 				    "\twindow mapped to %x@%x len=%d\n",
292419397407SSherry Moore 				    (unsigned)window->base,
292519397407SSherry Moore 				    (unsigned)memp->pcw_base,
292619397407SSherry Moore 				    memp->pcw_len);
29273db86aabSstevel 			}
29283db86aabSstevel #endif
29293db86aabSstevel 
29303db86aabSstevel 			/* find the register set offset */
29313db86aabSstevel 			select = win * PCIC_MEM_1_OFFSET;
29323db86aabSstevel #if defined(PCIC_DEBUG)
29333db86aabSstevel 			if (pcic_debug)
29343db86aabSstevel 				cmn_err(CE_CONT, "\tselect=%x\n", select);
29353db86aabSstevel #endif
29363db86aabSstevel 
29373db86aabSstevel 			/*
29383db86aabSstevel 			 * at this point, the register window indicator has
29393db86aabSstevel 			 * been converted to be an offset from the first
29403db86aabSstevel 			 * set of registers that are used for programming
29413db86aabSstevel 			 * the window mapping and the offset used to select
29423db86aabSstevel 			 * the correct set of registers to access the
29433db86aabSstevel 			 * specified socket.  This allows basing everything
29443db86aabSstevel 			 * off the _0 window
29453db86aabSstevel 			 */
29463db86aabSstevel 
29473db86aabSstevel 			/* map the physical page base address */
29483db86aabSstevel 			which = (window->state & WS_16BIT) ? SYSMEM_DATA_16 : 0;
29493db86aabSstevel 			which |= (window->speed <= MEM_SPEED_MIN) ?
295019397407SSherry Moore 			    SYSMEM_ZERO_WAIT : 0;
29513db86aabSstevel 
29523db86aabSstevel 			/* need to select register set */
29533db86aabSstevel 			select = PCIC_MEM_1_OFFSET * win;
29543db86aabSstevel 
29553db86aabSstevel 			pcic_putb(pcic, socket,
295619397407SSherry Moore 			    PCIC_SYSMEM_0_STARTLOW + select,
295719397407SSherry Moore 			    SYSMEM_LOW(base));
29583db86aabSstevel 			pcic_putb(pcic, socket,
295919397407SSherry Moore 			    PCIC_SYSMEM_0_STARTHI + select,
296019397407SSherry Moore 			    SYSMEM_HIGH(base) | which);
29613db86aabSstevel 
29623db86aabSstevel 			/*
29633db86aabSstevel 			 * Some adapters can decode window addresses greater
29643db86aabSstevel 			 * than 16-bits worth, so handle them here.
29653db86aabSstevel 			 */
29663db86aabSstevel 			switch (pcic->pc_type) {
29673db86aabSstevel 			case PCIC_INTEL_i82092:
29683db86aabSstevel 				pcic_putb(pcic, socket,
296919397407SSherry Moore 				    PCIC_82092_CPAGE,
297019397407SSherry Moore 				    SYSMEM_EXT(base));
29713db86aabSstevel 				break;
29723db86aabSstevel 			case PCIC_CL_PD6729:
29733db86aabSstevel 			case PCIC_CL_PD6730:
29743db86aabSstevel 				clext_reg_write(pcic, socket,
297519397407SSherry Moore 				    PCIC_CLEXT_MMAP0_UA + win,
297619397407SSherry Moore 				    SYSMEM_EXT(base));
29773db86aabSstevel 				break;
29783db86aabSstevel 			case PCIC_TI_PCI1130:
29793db86aabSstevel 				/*
29803db86aabSstevel 				 * Note that the TI chip has one upper byte
29813db86aabSstevel 				 * per socket so all windows get bound to a
29823db86aabSstevel 				 * 16MB segment.  This must be detected and
29833db86aabSstevel 				 * handled appropriately.  We can detect that
29843db86aabSstevel 				 * it is done by seeing if the pc_base has
29853db86aabSstevel 				 * changed and changing when the register
29863db86aabSstevel 				 * is first set.  This will force the bounds
29873db86aabSstevel 				 * to be correct.
29883db86aabSstevel 				 */
29893db86aabSstevel 				if (pcic->pc_bound == 0xffffffff) {
29903db86aabSstevel 					pcic_putb(pcic, socket,
299119397407SSherry Moore 					    PCIC_TI_WINDOW_PAGE_PCI,
299219397407SSherry Moore 					    SYSMEM_EXT(base));
29933db86aabSstevel 					pcic->pc_base = SYSMEM_EXT(base) << 24;
29943db86aabSstevel 					pcic->pc_bound = 0x1000000;
29953db86aabSstevel 				}
29963db86aabSstevel 				break;
29973db86aabSstevel 			case PCIC_TI_PCI1031:
29983db86aabSstevel 			case PCIC_TI_PCI1131:
29993db86aabSstevel 			case PCIC_TI_PCI1250:
30003db86aabSstevel 			case PCIC_TI_PCI1225:
30013db86aabSstevel 			case PCIC_TI_PCI1221:
30023db86aabSstevel 			case PCIC_SMC_34C90:
30033db86aabSstevel 			case PCIC_CL_PD6832:
30043db86aabSstevel 			case PCIC_RICOH_RL5C466:
30053db86aabSstevel 			case PCIC_TI_PCI1410:
30063db86aabSstevel 			case PCIC_ENE_1410:
30073db86aabSstevel 			case PCIC_TI_PCI1510:
30083db86aabSstevel 			case PCIC_TI_PCI1520:
30093db86aabSstevel 			case PCIC_O2_OZ6912:
30103db86aabSstevel 			case PCIC_TI_PCI1420:
30113db86aabSstevel 			case PCIC_ENE_1420:
30123db86aabSstevel 			case PCIC_TI_VENDOR:
30133db86aabSstevel 			case PCIC_TOSHIBA_TOPIC100:
30143db86aabSstevel 			case PCIC_TOSHIBA_TOPIC95:
30153db86aabSstevel 			case PCIC_TOSHIBA_VENDOR:
30163db86aabSstevel 			case PCIC_RICOH_VENDOR:
30173db86aabSstevel 			case PCIC_O2MICRO_VENDOR:
30183db86aabSstevel 				pcic_putb(pcic, socket,
301919397407SSherry Moore 				    PCIC_YENTA_MEM_PAGE + win,
302019397407SSherry Moore 				    SYSMEM_EXT(base));
30213db86aabSstevel 				break;
30223db86aabSstevel 			default:
30233db86aabSstevel 				cmn_err(CE_NOTE, "pcic_set_window: unknown "
302419397407SSherry Moore 				    "cardbus vendor:0x%X\n",
302519397407SSherry Moore 				    pcic->pc_type);
30263db86aabSstevel 				pcic_putb(pcic, socket,
302719397407SSherry Moore 				    PCIC_YENTA_MEM_PAGE + win,
302819397407SSherry Moore 				    SYSMEM_EXT(base));
30293db86aabSstevel 
30303db86aabSstevel 				break;
30313db86aabSstevel 			} /* switch */
30323db86aabSstevel 
30333db86aabSstevel 			/*
30343db86aabSstevel 			 * specify the length of the mapped range
30353db86aabSstevel 			 * we convert to pages (rounding up) so that
30363db86aabSstevel 			 * the hardware gets the right thing
30373db86aabSstevel 			 */
30383db86aabSstevel 			pages = (window->WindowSize+PCIC_PAGE-1)/PCIC_PAGE;
30393db86aabSstevel 
30403db86aabSstevel 			/*
30413db86aabSstevel 			 * Setup this window's timing.
30423db86aabSstevel 			 */
30433db86aabSstevel 			switch (pcic->pc_type) {
30443db86aabSstevel 			case PCIC_CL_PD6729:
30453db86aabSstevel 			case PCIC_CL_PD6730:
30463db86aabSstevel 			case PCIC_CL_PD6710:
30473db86aabSstevel 			case PCIC_CL_PD6722:
30483db86aabSstevel 				wspeed = SYSMEM_CLTIMER_SET_0;
30493db86aabSstevel 				pcic_set_cdtimers(pcic, socket,
305019397407SSherry Moore 				    window->speed,
305119397407SSherry Moore 				    wspeed);
30523db86aabSstevel 				break;
30533db86aabSstevel 
30543db86aabSstevel 			case PCIC_INTEL_i82092:
30553db86aabSstevel 			default:
30563db86aabSstevel 				wspeed = pcic_calc_speed(pcic, window->speed);
30573db86aabSstevel 				break;
30583db86aabSstevel 			} /* switch */
30593db86aabSstevel 
30603db86aabSstevel #if defined(PCIC_DEBUG)
30613db86aabSstevel 			if (pcic_debug)
30623db86aabSstevel 				cmn_err(CE_CONT,
306319397407SSherry Moore 				    "\twindow %d speed bits = %x for "
306419397407SSherry Moore 				    "%dns\n",
306519397407SSherry Moore 				    win, (unsigned)wspeed, window->speed);
30663db86aabSstevel #endif
30673db86aabSstevel 
30683db86aabSstevel 			pcic_putb(pcic, socket, PCIC_SYSMEM_0_STOPLOW + select,
306919397407SSherry Moore 			    SYSMEM_LOW(base +
307019397407SSherry Moore 			    (pages * PCIC_PAGE)-1));
30713db86aabSstevel 
30723db86aabSstevel 			wspeed |= SYSMEM_HIGH(base + (pages * PCIC_PAGE)-1);
30733db86aabSstevel 			pcic_putb(pcic, socket, PCIC_SYSMEM_0_STOPHI + select,
307419397407SSherry Moore 			    wspeed);
30753db86aabSstevel 
30763db86aabSstevel 			/*
30773db86aabSstevel 			 * now map the card's memory pages - we start with page
30783db86aabSstevel 			 * 0
30793db86aabSstevel 			 * we also default to AM -- set page might change it
30803db86aabSstevel 			 */
30813db86aabSstevel 			base = memp->pcw_base;
30823db86aabSstevel 			pcic_putb(pcic, socket,
308319397407SSherry Moore 			    PCIC_CARDMEM_0_LOW + select,
308419397407SSherry Moore 			    CARDMEM_LOW(0 - (uint32_t)base));
30853db86aabSstevel 
30863db86aabSstevel 			pcic_putb(pcic, socket,
308719397407SSherry Moore 			    PCIC_CARDMEM_0_HI + select,
308819397407SSherry Moore 			    CARDMEM_HIGH(0 - (uint32_t)base) |
308919397407SSherry Moore 			    CARDMEM_REG_ACTIVE);
30903db86aabSstevel 
30913db86aabSstevel 			/*
30923db86aabSstevel 			 * enable the window even though redundant
30933db86aabSstevel 			 * and SetPage may do it again.
30943db86aabSstevel 			 */
30953db86aabSstevel 			select = pcic_getb(pcic, socket,
309619397407SSherry Moore 			    PCIC_MAPPING_ENABLE);
30973db86aabSstevel 			select |= SYSMEM_WINDOW(win);
30983db86aabSstevel 			pcic_putb(pcic, socket, PCIC_MAPPING_ENABLE, select);
30993db86aabSstevel 			memp->pcw_offset = 0;
31003db86aabSstevel 			memp->pcw_status |= PCW_ENABLED;
31013db86aabSstevel 		} else {
31023db86aabSstevel 			/*
31033db86aabSstevel 			 * not only do we unmap the memory, the
31043db86aabSstevel 			 * window has been turned off.
31053db86aabSstevel 			 */
31063db86aabSstevel 			if (which && memp->pcw_status & PCW_MAPPED) {
31073db86aabSstevel 				ddi_regs_map_free(&memp->pcw_handle);
31083db86aabSstevel 				res.ra_addr_lo = memp->pcw_base;
31093db86aabSstevel 				res.ra_len = memp->pcw_len;
31108134ee03Srw 				(void) pcmcia_free_mem(memp->res_dip, &res);
31113db86aabSstevel 				memp->pcw_hostmem = NULL;
31123db86aabSstevel 				memp->pcw_status &= ~PCW_MAPPED;
31133db86aabSstevel 			}
31143db86aabSstevel 
31153db86aabSstevel 			/* disable current mapping */
31163db86aabSstevel 			select = pcic_getb(pcic, socket, PCIC_MAPPING_ENABLE);
31173db86aabSstevel 			select &= ~SYSMEM_WINDOW(win);
31183db86aabSstevel 			pcic_putb(pcic, socket, PCIC_MAPPING_ENABLE, select);
31193db86aabSstevel 			memp->pcw_status &= ~PCW_ENABLED;
31203db86aabSstevel 		}
31213db86aabSstevel 		memp->pcw_len = window->WindowSize;
31223db86aabSstevel 		window->handle = memp->pcw_handle;
31233db86aabSstevel #if defined(PCIC_DEBUG)
31243db86aabSstevel 		if (pcic_debug)
31253db86aabSstevel 			xxdmp_all_regs(pcic, window->socket, -1);
31263db86aabSstevel #endif
31273db86aabSstevel 	} else {
31283db86aabSstevel 		/*
31293db86aabSstevel 		 * This is a request for an IO window
31303db86aabSstevel 		 */
31313db86aabSstevel 		int win, tmp;
31323db86aabSstevel 		pcs_iowin_t *winp;
31333db86aabSstevel 				/* I/O windows */
31343db86aabSstevel #if defined(PCIC_DEBUG)
31353db86aabSstevel 		if (pcic_debug)
31363db86aabSstevel 			cmn_err(CE_CONT, "\twindow type is I/O\n");
31373db86aabSstevel #endif
31383db86aabSstevel 
31393db86aabSstevel 		/* only windows 0 and 1 can do I/O */
31403db86aabSstevel 		win = window->window % PCIC_NUMWINSOCK;
31413db86aabSstevel 		tmp = window->window / PCIC_NUMWINSOCK;
31423db86aabSstevel 
31433db86aabSstevel 		if (win >= PCIC_IOWINDOWS || tmp != window->socket) {
31443db86aabSstevel 			cmn_err(CE_WARN,
314519397407SSherry Moore 			    "\twindow is out of range (%d)\n",
314619397407SSherry Moore 			    window->window);
31473db86aabSstevel 			return (BAD_WINDOW);
31483db86aabSstevel 		}
31493db86aabSstevel 
31503db86aabSstevel 		mutex_enter(&pcic->pc_lock); /* protect the registers */
31513db86aabSstevel 
31523db86aabSstevel 		winp = &sockp->pcs_windows[win].io;
31533db86aabSstevel 		winp->pcw_speed = window->speed;
31543db86aabSstevel 		if (window->WindowSize != 1 && window->WindowSize & 1) {
31553db86aabSstevel 			/* we don't want an odd-size window */
31563db86aabSstevel 			window->WindowSize++;
31573db86aabSstevel 		}
31583db86aabSstevel 		winp->pcw_len = window->WindowSize;
31593db86aabSstevel 
31603db86aabSstevel 		if (window->state & WS_ENABLED) {
31613db86aabSstevel 			if (winp->pcw_status & PCW_MAPPED) {
31623db86aabSstevel 				ddi_regs_map_free(&winp->pcw_handle);
31633db86aabSstevel 				res.ra_addr_lo = winp->pcw_base;
31643db86aabSstevel 				res.ra_len = winp->pcw_len;
31658134ee03Srw 				(void) pcmcia_free_io(winp->res_dip, &res);
31663db86aabSstevel 				winp->pcw_status &= ~(PCW_MAPPED|PCW_ENABLED);
31673db86aabSstevel 			}
31683db86aabSstevel 
31693db86aabSstevel 			/*
31703db86aabSstevel 			 * if the I/O address wasn't allocated, allocate
31713db86aabSstevel 			 *	it now. If it was allocated, it better
31723db86aabSstevel 			 *	be free to use.
31733db86aabSstevel 			 * The winp->pcw_offset value is set and used
31743db86aabSstevel 			 *	later on if the particular adapter
31753db86aabSstevel 			 *	that we're running on has the ability
31763db86aabSstevel 			 *	to translate IO accesses to the card
31773db86aabSstevel 			 *	(such as some adapters  in the Cirrus
31783db86aabSstevel 			 *	Logic family).
31793db86aabSstevel 			 */
31803db86aabSstevel 			winp->pcw_offset = 0;
31813db86aabSstevel 
31823db86aabSstevel 			/*
31833db86aabSstevel 			 * Setup the request parameters for the
31843db86aabSstevel 			 *	requested base and length. If
31853db86aabSstevel 			 *	we're on an adapter that has
31863db86aabSstevel 			 *	IO window offset registers, then
31873db86aabSstevel 			 *	we don't need a specific base
31883db86aabSstevel 			 *	address, just a length, and then
31893db86aabSstevel 			 *	we'll cause the correct IO address
31903db86aabSstevel 			 *	to be generated on the socket by
31913db86aabSstevel 			 *	setting up the IO window offset
31923db86aabSstevel 			 *	registers.
31933db86aabSstevel 			 * For adapters that support this capability, we
31943db86aabSstevel 			 *	always use the IO window offset registers,
31953db86aabSstevel 			 *	even if the passed base/length would be in
31963db86aabSstevel 			 *	range.
31973db86aabSstevel 			 */
31983db86aabSstevel 			base = window->base;
31993db86aabSstevel 			bzero(&req, sizeof (req));
32003db86aabSstevel 			req.ra_len = window->WindowSize;
32013db86aabSstevel 
32023db86aabSstevel 			req.ra_addr = (uint64_t)
320319397407SSherry Moore 			    ((pcic->pc_flags & PCF_IO_REMAP) ? 0 : base);
32043db86aabSstevel 			req.ra_flags = (req.ra_addr) ?
320519397407SSherry Moore 			    NDI_RA_ALLOC_SPECIFIED : 0;
32063db86aabSstevel 
32073db86aabSstevel 			req.ra_flags |= NDI_RA_ALIGN_SIZE;
32083db86aabSstevel 			/* need to rethink this */
32093db86aabSstevel 			req.ra_boundbase = pcic->pc_iobase;
32103db86aabSstevel 			req.ra_boundlen = pcic->pc_iobound;
32113db86aabSstevel 			req.ra_flags |= NDI_RA_ALLOC_BOUNDED;
32123db86aabSstevel 
32133db86aabSstevel #if defined(PCIC_DEBUG)
321419397407SSherry Moore 				pcic_err(dip, 8,
321519397407SSherry Moore 				    "\tlen 0x%"PRIx64" addr 0x%"PRIx64
321619397407SSherry Moore 				    "bbase 0x%"PRIx64
321719397407SSherry Moore 				    "blen 0x%"PRIx64" flags 0x%x algn 0x%"
321819397407SSherry Moore 				    PRIx64"\n",
321919397407SSherry Moore 				    req.ra_len, (uint64_t)req.ra_addr,
322019397407SSherry Moore 				    req.ra_boundbase,
322119397407SSherry Moore 				    req.ra_boundlen, req.ra_flags,
322219397407SSherry Moore 				    req.ra_align_mask);
32233db86aabSstevel #endif
32243db86aabSstevel 
32253db86aabSstevel 			/*
32263db86aabSstevel 			 * Try to allocate the space. If we fail this,
32273db86aabSstevel 			 *	return the appropriate error depending
32283db86aabSstevel 			 *	on whether the caller specified a
32293db86aabSstevel 			 *	specific base address or not.
32303db86aabSstevel 			 */
32318134ee03Srw 			if (pcmcia_alloc_io(dip, &req, &res,
323219397407SSherry Moore 			    &winp->res_dip) == DDI_FAILURE) {
32333db86aabSstevel 				winp->pcw_status &= ~PCW_ENABLED;
32343db86aabSstevel 				mutex_exit(&pcic->pc_lock);
32353db86aabSstevel 				cmn_err(CE_WARN, "Failed to alloc I/O:\n"
323619397407SSherry Moore 				    "\tlen 0x%" PRIx64 " addr 0x%" PRIx64
323719397407SSherry Moore 				    "bbase 0x%" PRIx64
323819397407SSherry Moore 				    "blen 0x%" PRIx64 "flags 0x%x"
323919397407SSherry Moore 				    "algn 0x%" PRIx64 "\n",
324019397407SSherry Moore 				    req.ra_len, req.ra_addr,
324119397407SSherry Moore 				    req.ra_boundbase,
324219397407SSherry Moore 				    req.ra_boundlen, req.ra_flags,
324319397407SSherry Moore 				    req.ra_align_mask);
32443db86aabSstevel 
32453db86aabSstevel 				return (base?BAD_BASE:BAD_SIZE);
32463db86aabSstevel 			} /* pcmcia_alloc_io */
32473db86aabSstevel 
32483db86aabSstevel 			/*
32493db86aabSstevel 			 * Don't change the original base. Either we use
32503db86aabSstevel 			 * the offset registers below (PCF_IO_REMAP is set)
32513db86aabSstevel 			 * or it was allocated correctly anyway.
32523db86aabSstevel 			 */
32533db86aabSstevel 			winp->pcw_base = res.ra_addr_lo;
32543db86aabSstevel 
32553db86aabSstevel #if defined(PCIC_DEBUG)
325619397407SSherry Moore 				pcic_err(dip, 8,
32573db86aabSstevel 				    "\tsetwindow: new base=%x orig base 0x%x\n",
32583db86aabSstevel 				    (unsigned)winp->pcw_base, base);
32593db86aabSstevel #endif
32603db86aabSstevel 
32613db86aabSstevel 			if ((which = pcmcia_map_reg(pcic->dip,
326219397407SSherry Moore 			    window->child,
326319397407SSherry Moore 			    &res,
326419397407SSherry Moore 			    (uint32_t)(window->state &
326519397407SSherry Moore 			    0xffff) |
326619397407SSherry Moore 			    (window->socket << 16),
326719397407SSherry Moore 			    (caddr_t *)&winp->pcw_hostmem,
326819397407SSherry Moore 			    &winp->pcw_handle,
326919397407SSherry Moore 			    &window->attr,
327019397407SSherry Moore 			    base)) != DDI_SUCCESS) {
327119397407SSherry Moore 
327219397407SSherry Moore 				cmn_err(CE_WARN, "pcmcia_map_reg()"
327319397407SSherry Moore 				    "failed\n");
327419397407SSherry Moore 
327519397407SSherry Moore 					res.ra_addr_lo = winp->pcw_base;
327619397407SSherry Moore 					res.ra_len = winp->pcw_len;
327719397407SSherry Moore 					(void) pcmcia_free_io(winp->res_dip,
327819397407SSherry Moore 					    &res);
327919397407SSherry Moore 
328019397407SSherry Moore 					mutex_exit(&pcic->pc_lock);
328119397407SSherry Moore 					return (BAD_WINDOW);
32823db86aabSstevel 			}
32833db86aabSstevel 
32843db86aabSstevel 			window->handle = winp->pcw_handle;
32853db86aabSstevel 			winp->pcw_status |= PCW_MAPPED;
32863db86aabSstevel 
32873db86aabSstevel 			/* find the register set offset */
32883db86aabSstevel 			select = win * PCIC_IO_OFFSET;
32893db86aabSstevel 
32903db86aabSstevel #if defined(PCIC_DEBUG)
32913db86aabSstevel 			if (pcic_debug) {
32923db86aabSstevel 				cmn_err(CE_CONT,
329319397407SSherry Moore 				    "\tenable: window=%d, select=%x, "
329419397407SSherry Moore 				    "base=%x, handle=%p\n",
329519397407SSherry Moore 				    win, select,
329619397407SSherry Moore 				    (unsigned)window->base,
329719397407SSherry Moore 				    (void *)window->handle);
32983db86aabSstevel 			}
32993db86aabSstevel #endif
33003db86aabSstevel 			/*
33013db86aabSstevel 			 * at this point, the register window indicator has
33023db86aabSstevel 			 * been converted to be an offset from the first
33033db86aabSstevel 			 * set of registers that are used for programming
33043db86aabSstevel 			 * the window mapping and the offset used to select
33053db86aabSstevel 			 * the correct set of registers to access the
33063db86aabSstevel 			 * specified socket.  This allows basing everything
33073db86aabSstevel 			 * off the _0 window
33083db86aabSstevel 			 */
33093db86aabSstevel 
33103db86aabSstevel 			/* map the I/O base in */
33113db86aabSstevel 			pcic_putb(pcic, socket,
331219397407SSherry Moore 			    PCIC_IO_ADDR_0_STARTLOW + select,
331319397407SSherry Moore 			    LOW_BYTE((uint32_t)winp->pcw_base));
33143db86aabSstevel 			pcic_putb(pcic, socket,
331519397407SSherry Moore 			    PCIC_IO_ADDR_0_STARTHI + select,
331619397407SSherry Moore 			    HIGH_BYTE((uint32_t)winp->pcw_base));
33173db86aabSstevel 
33183db86aabSstevel 			pcic_putb(pcic, socket,
331919397407SSherry Moore 			    PCIC_IO_ADDR_0_STOPLOW + select,
332019397407SSherry Moore 			    LOW_BYTE((uint32_t)winp->pcw_base +
332119397407SSherry Moore 			    window->WindowSize - 1));
33223db86aabSstevel 			pcic_putb(pcic, socket,
332319397407SSherry Moore 			    PCIC_IO_ADDR_0_STOPHI + select,
332419397407SSherry Moore 			    HIGH_BYTE((uint32_t)winp->pcw_base +
332519397407SSherry Moore 			    window->WindowSize - 1));
33263db86aabSstevel 
33273db86aabSstevel 			/*
33283db86aabSstevel 			 * We've got the requested IO space, now see if we
33293db86aabSstevel 			 *	need to adjust the IO window offset registers
33303db86aabSstevel 			 *	so that the correct IO address is generated
33313db86aabSstevel 			 *	at the socket. If this window doesn't have
33323db86aabSstevel 			 *	this capability, then we're all done setting
33333db86aabSstevel 			 *	up the IO resources.
33343db86aabSstevel 			 */
33353db86aabSstevel 			if (pcic->pc_flags & PCF_IO_REMAP) {
33363db86aabSstevel 
33373db86aabSstevel 
33383db86aabSstevel 				/*
33393db86aabSstevel 				 * Note that only 16 bits are used to program
33403db86aabSstevel 				 * the registers but leave 32 bits on pcw_offset
33413db86aabSstevel 				 * so that we can generate the original base
33423db86aabSstevel 				 * in get_window()
33433db86aabSstevel 				 */
33443db86aabSstevel 				winp->pcw_offset = (base - winp->pcw_base);
33453db86aabSstevel 
33463db86aabSstevel 				pcic_putb(pcic, socket,
334719397407SSherry Moore 				    PCIC_IO_OFFSET_LOW +
334819397407SSherry Moore 				    (win * PCIC_IO_OFFSET_OFFSET),
334919397407SSherry Moore 				    winp->pcw_offset & 0x0ff);
33503db86aabSstevel 				pcic_putb(pcic, socket,
335119397407SSherry Moore 				    PCIC_IO_OFFSET_HI +
335219397407SSherry Moore 				    (win * PCIC_IO_OFFSET_OFFSET),
335319397407SSherry Moore 				    (winp->pcw_offset >> 8) & 0x0ff);
33543db86aabSstevel 
33553db86aabSstevel 			} /* PCF_IO_REMAP */
33563db86aabSstevel 
33573db86aabSstevel 			/* now get the other details (size, etc) right */
33583db86aabSstevel 
33593db86aabSstevel 			/*
33603db86aabSstevel 			 * Set the data size control bits here. Most of the
33613db86aabSstevel 			 *	adapters will ignore IOMEM_16BIT when
33623db86aabSstevel 			 *	IOMEM_IOCS16 is set, except for the Intel
33633db86aabSstevel 			 *	82092, which only pays attention to the
33643db86aabSstevel 			 *	IOMEM_16BIT bit. Sigh... Intel can't even
33653db86aabSstevel 			 *	make a proper clone of their own chip.
33663db86aabSstevel 			 * The 82092 also apparently can't set the timing
33673db86aabSstevel 			 *	of I/O windows.
33683db86aabSstevel 			 */
33693db86aabSstevel 			which = (window->state & WS_16BIT) ?
337019397407SSherry Moore 			    (IOMEM_16BIT | IOMEM_IOCS16) : 0;
33713db86aabSstevel 
33723db86aabSstevel 			switch (pcic->pc_type) {
33733db86aabSstevel 			case PCIC_CL_PD6729:
33743db86aabSstevel 			case PCIC_CL_PD6730:
33753db86aabSstevel 			case PCIC_CL_PD6710:
33763db86aabSstevel 			case PCIC_CL_PD6722:
33773db86aabSstevel 			case PCIC_CL_PD6832:
33783db86aabSstevel 				/*
33793db86aabSstevel 				 * Select Timer Set 1 - this will take
33803db86aabSstevel 				 *	effect when the PCIC_IO_CONTROL
33813db86aabSstevel 				 *	register is written to later on;
33823db86aabSstevel 				 *	the call to pcic_set_cdtimers
33833db86aabSstevel 				 *	just sets up the timer itself.
33843db86aabSstevel 				 */
33853db86aabSstevel 				which |= IOMEM_CLTIMER_SET_1;
33863db86aabSstevel 				pcic_set_cdtimers(pcic, socket,
338719397407SSherry Moore 				    window->speed,
338819397407SSherry Moore 				    IOMEM_CLTIMER_SET_1);
33893db86aabSstevel 				which |= IOMEM_IOCS16;
33903db86aabSstevel 				break;
33913db86aabSstevel 			case PCIC_TI_PCI1031:
33923db86aabSstevel 
33933db86aabSstevel 				if (window->state & WS_16BIT)
339419397407SSherry Moore 					which |= IOMEM_WAIT16;
33953db86aabSstevel 
33963db86aabSstevel 				break;
33973db86aabSstevel 			case PCIC_TI_PCI1130:
33983db86aabSstevel 
33993db86aabSstevel 				if (window->state & WS_16BIT)
340019397407SSherry Moore 					which |= IOMEM_WAIT16;
34013db86aabSstevel 
34023db86aabSstevel 				break;
34033db86aabSstevel 			case PCIC_INTEL_i82092:
34043db86aabSstevel 				break;
34053db86aabSstevel 			default:
34063db86aabSstevel 				if (window->speed >
340719397407SSherry Moore 				    mhztons(pcic->bus_speed) * 3)
340819397407SSherry Moore 					which |= IOMEM_WAIT16;
34093db86aabSstevel #ifdef notdef
34103db86aabSstevel 				if (window->speed <
341119397407SSherry Moore 				    mhztons(pcic->bus_speed) * 6)
341219397407SSherry Moore 					which |= IOMEM_ZERO_WAIT;
34133db86aabSstevel #endif
34143db86aabSstevel 				break;
34153db86aabSstevel 			} /* switch (pc_type) */
34163db86aabSstevel 
34173db86aabSstevel 			/*
34183db86aabSstevel 			 * Setup the data width and timing
34193db86aabSstevel 			 */
34203db86aabSstevel 			select = pcic_getb(pcic, socket, PCIC_IO_CONTROL);
34213db86aabSstevel 			select &= ~(PCIC_IO_WIN_MASK << (win * 4));
34223db86aabSstevel 			select |= IOMEM_SETWIN(win, which);
34233db86aabSstevel 			pcic_putb(pcic, socket, PCIC_IO_CONTROL, select);
34243db86aabSstevel 
34253db86aabSstevel 			/*
34263db86aabSstevel 			 * Enable the IO window
34273db86aabSstevel 			 */
34283db86aabSstevel 			select = pcic_getb(pcic, socket, PCIC_MAPPING_ENABLE);
34293db86aabSstevel 			pcic_putb(pcic, socket, PCIC_MAPPING_ENABLE,
343019397407SSherry Moore 			    select | IOMEM_WINDOW(win));
34313db86aabSstevel 
34323db86aabSstevel 			winp->pcw_status |= PCW_ENABLED;
34333db86aabSstevel 
34343db86aabSstevel #if defined(PCIC_DEBUG)
34353db86aabSstevel 			if (pcic_debug) {
34363db86aabSstevel 				cmn_err(CE_CONT,
343719397407SSherry Moore 				    "\twhich = %x, select = %x (%x)\n",
343819397407SSherry Moore 				    which, select,
343919397407SSherry Moore 				    IOMEM_SETWIN(win, which));
34403db86aabSstevel 				xxdmp_all_regs(pcic, window->socket * 0x40, 24);
34413db86aabSstevel 			}
34423db86aabSstevel #endif
34433db86aabSstevel 		} else {
34443db86aabSstevel 			/*
34453db86aabSstevel 			 * not only do we unmap the IO space, the
34463db86aabSstevel 			 * window has been turned off.
34473db86aabSstevel 			 */
34483db86aabSstevel 			if (winp->pcw_status & PCW_MAPPED) {
34493db86aabSstevel 				ddi_regs_map_free(&winp->pcw_handle);
34503db86aabSstevel 				res.ra_addr_lo = winp->pcw_base;
34513db86aabSstevel 				res.ra_len = winp->pcw_len;
34528134ee03Srw 				(void) pcmcia_free_io(winp->res_dip, &res);
34533db86aabSstevel 				winp->pcw_status &= ~PCW_MAPPED;
34543db86aabSstevel 			}
34553db86aabSstevel 
34563db86aabSstevel 			/* disable current mapping */
34573db86aabSstevel 			select = pcic_getb(pcic, socket,
345819397407SSherry Moore 			    PCIC_MAPPING_ENABLE);
34593db86aabSstevel 			pcic_putb(pcic, socket, PCIC_MAPPING_ENABLE,
346019397407SSherry Moore 			    select &= ~IOMEM_WINDOW(win));
34613db86aabSstevel 			winp->pcw_status &= ~PCW_ENABLED;
34623db86aabSstevel 
34633db86aabSstevel 			winp->pcw_base = 0;
34643db86aabSstevel 			winp->pcw_len = 0;
34653db86aabSstevel 			winp->pcw_offset = 0;
34663db86aabSstevel 			window->base = 0;
34673db86aabSstevel 			/* now make sure we don't accidentally re-enable */
34683db86aabSstevel 			/* find the register set offset */
34693db86aabSstevel 			select = win * PCIC_IO_OFFSET;
34703db86aabSstevel 			pcic_putb(pcic, socket,
347119397407SSherry Moore 			    PCIC_IO_ADDR_0_STARTLOW + select, 0);
34723db86aabSstevel 			pcic_putb(pcic, socket,
347319397407SSherry Moore 			    PCIC_IO_ADDR_0_STARTHI + select, 0);
34743db86aabSstevel 			pcic_putb(pcic, socket,
347519397407SSherry Moore 			    PCIC_IO_ADDR_0_STOPLOW + select, 0);
34763db86aabSstevel 			pcic_putb(pcic, socket,
347719397407SSherry Moore 			    PCIC_IO_ADDR_0_STOPHI + select, 0);
34783db86aabSstevel 		}
34793db86aabSstevel 	}
34803db86aabSstevel 	mutex_exit(&pcic->pc_lock);
34813db86aabSstevel 
34823db86aabSstevel 	return (SUCCESS);
34833db86aabSstevel }
34843db86aabSstevel 
34853db86aabSstevel /*
34863db86aabSstevel  * pcic_card_state()
34873db86aabSstevel  *	compute the instantaneous Card State information
34883db86aabSstevel  */
34893db86aabSstevel static int
pcic_card_state(pcicdev_t * pcic,pcic_socket_t * sockp)34903db86aabSstevel pcic_card_state(pcicdev_t *pcic, pcic_socket_t *sockp)
34913db86aabSstevel {
34923db86aabSstevel 	int value, result;
34933db86aabSstevel #if defined(PCIC_DEBUG)
34943db86aabSstevel 	int orig_value;
34953db86aabSstevel #endif
34963db86aabSstevel 
34973db86aabSstevel 	mutex_enter(&pcic->pc_lock); /* protect the registers */
34983db86aabSstevel 
34993db86aabSstevel 	value = pcic_getb(pcic, sockp->pcs_socket, PCIC_INTERFACE_STATUS);
35003db86aabSstevel 
35013db86aabSstevel #if defined(PCIC_DEBUG)
35023db86aabSstevel 	orig_value = value;
35033db86aabSstevel 	if (pcic_debug >= 8)
35043db86aabSstevel 		cmn_err(CE_CONT, "pcic_card_state(%p) if status = %b for %d\n",
350519397407SSherry Moore 		    (void *)sockp,
350619397407SSherry Moore 		    value,
350719397407SSherry Moore 		    "\020\1BVD1\2BVD2\3CD1\4CD2\5WP\6RDY\7PWR\10~GPI",
350819397407SSherry Moore 		    sockp->pcs_socket);
35093db86aabSstevel #endif
35103db86aabSstevel 	/*
35113db86aabSstevel 	 * Lie to socket services if we are not ready.
35123db86aabSstevel 	 * This is when we are starting up or during debounce timeouts
35133db86aabSstevel 	 * or if the card is a cardbus card.
35143db86aabSstevel 	 */
35153db86aabSstevel 	if (!(sockp->pcs_flags & (PCS_STARTING|PCS_CARD_ISCARDBUS)) &&
35163db86aabSstevel 	    !sockp->pcs_debounce_id &&
35173db86aabSstevel 	    (value & PCIC_ISTAT_CD_MASK) == PCIC_CD_PRESENT_OK) {
35183db86aabSstevel 		result = SBM_CD;
35193db86aabSstevel 
35203db86aabSstevel 		if (value & PCIC_WRITE_PROTECT || !(value & PCIC_POWER_ON))
35213db86aabSstevel 			result |= SBM_WP;
35223db86aabSstevel 		if (value & PCIC_POWER_ON) {
35233db86aabSstevel 			if (value & PCIC_READY)
35243db86aabSstevel 				result |= SBM_RDYBSY;
35253db86aabSstevel 			value = (~value) & (PCIC_BVD1 | PCIC_BVD2);
35263db86aabSstevel 			if (value & PCIC_BVD1)
35273db86aabSstevel 				result |= SBM_BVD1;
35283db86aabSstevel 			if (value & PCIC_BVD2)
35293db86aabSstevel 				result |= SBM_BVD2;
35303db86aabSstevel 		}
35313db86aabSstevel 	} else
35323db86aabSstevel 		result = 0;
35333db86aabSstevel 
35343db86aabSstevel 	mutex_exit(&pcic->pc_lock);
35353db86aabSstevel 
35363db86aabSstevel #if defined(PCIC_DEBUG)
35373db86aabSstevel 	pcic_err(pcic->dip, 8,
35383db86aabSstevel 	    "pcic_card_state(%p) if status = %b for %d (rval=0x%x)\n",
35393db86aabSstevel 	    (void *) sockp, orig_value,
35403db86aabSstevel 	    "\020\1BVD1\2BVD2\3CD1\4CD2\5WP\6RDY\7PWR\10~GPI",
35413db86aabSstevel 	    sockp->pcs_socket, result);
35423db86aabSstevel #endif
35433db86aabSstevel 
35443db86aabSstevel 	return (result);
35453db86aabSstevel }
35463db86aabSstevel 
35473db86aabSstevel /*
35483db86aabSstevel  * pcic_set_page()
35493db86aabSstevel  *	SocketServices SetPage function
35503db86aabSstevel  *	set the page of PC Card memory that should be in the mapped
35513db86aabSstevel  *	window
35523db86aabSstevel  */
35533db86aabSstevel /*ARGSUSED*/
35543db86aabSstevel static int
pcic_set_page(dev_info_t * dip,set_page_t * page)35553db86aabSstevel pcic_set_page(dev_info_t *dip, set_page_t *page)
35563db86aabSstevel {
35573db86aabSstevel 	anp_t *anp = ddi_get_driver_private(dip);
35583db86aabSstevel 	pcicdev_t *pcic = anp->an_private;
35593db86aabSstevel 	int select;
35603db86aabSstevel 	int which, socket, window;
35613db86aabSstevel 	uint32_t base;
35623db86aabSstevel 	pcs_memwin_t *memp;
35633db86aabSstevel 
35643db86aabSstevel 	/* get real socket/window numbers */
35653db86aabSstevel 	window = page->window % PCIC_NUMWINSOCK;
35663db86aabSstevel 	socket = page->window / PCIC_NUMWINSOCK;
35673db86aabSstevel 
35683db86aabSstevel #if defined(PCIC_DEBUG)
35693db86aabSstevel 	if (pcic_debug) {
35703db86aabSstevel 		cmn_err(CE_CONT,
357119397407SSherry Moore 		    "pcic_set_page: window=%d, socket=%d, page=%d\n",
357219397407SSherry Moore 		    window, socket, page->page);
35733db86aabSstevel 	}
35743db86aabSstevel #endif
35753db86aabSstevel 	/* only windows 2-6 work on memory */
35763db86aabSstevel 	if (window < PCIC_IOWINDOWS)
35773db86aabSstevel 		return (BAD_WINDOW);
35783db86aabSstevel 
35793db86aabSstevel 	/* only one page supported (but any size) */
35803db86aabSstevel 	if (page->page != 0)
35813db86aabSstevel 		return (BAD_PAGE);
35823db86aabSstevel 
35833db86aabSstevel 	mutex_enter(&pcic->pc_lock); /* protect the registers */
35843db86aabSstevel 
35853db86aabSstevel 	memp = &pcic->pc_sockets[socket].pcs_windows[window].mem;
35863db86aabSstevel 	window -= PCIC_IOWINDOWS;
35873db86aabSstevel 
35883db86aabSstevel #if defined(PCIC_DEBUG)
35893db86aabSstevel 	if (pcic_debug)
35903db86aabSstevel 		cmn_err(CE_CONT, "\tpcw_base=%x, pcw_hostmem=%p, pcw_len=%x\n",
359119397407SSherry Moore 		    (uint32_t)memp->pcw_base,
359219397407SSherry Moore 		    (void *)memp->pcw_hostmem, memp->pcw_len);
35933db86aabSstevel #endif
35943db86aabSstevel 
35953db86aabSstevel 	/* window must be enabled */
35963db86aabSstevel 	if (!(memp->pcw_status & PCW_ENABLED))
35973db86aabSstevel 		return (BAD_ATTRIBUTE);
35983db86aabSstevel 
35993db86aabSstevel 	/* find the register set offset */
36003db86aabSstevel 	select = window * PCIC_MEM_1_OFFSET;
36013db86aabSstevel #if defined(PCIC_DEBUG)
36023db86aabSstevel 	if (pcic_debug)
36033db86aabSstevel 		cmn_err(CE_CONT, "\tselect=%x\n", select);
36043db86aabSstevel #endif
36053db86aabSstevel 
36063db86aabSstevel 	/*
36073db86aabSstevel 	 * now map the card's memory pages - we start with page 0
36083db86aabSstevel 	 */
36093db86aabSstevel 
36103db86aabSstevel 	which = 0;		/* assume simple case */
36113db86aabSstevel 	if (page->state & PS_ATTRIBUTE) {
36123db86aabSstevel 		which |= CARDMEM_REG_ACTIVE;
36133db86aabSstevel 		memp->pcw_status |= PCW_ATTRIBUTE;
36143db86aabSstevel 	} else {
36153db86aabSstevel 		memp->pcw_status &= ~PCW_ATTRIBUTE;
36163db86aabSstevel 	}
36173db86aabSstevel 
36183db86aabSstevel 	/*
36193db86aabSstevel 	 * if caller says Write Protect, enforce it.
36203db86aabSstevel 	 */
36213db86aabSstevel 	if (page->state & PS_WP) {
36223db86aabSstevel 		which |= CARDMEM_WRITE_PROTECT;
36233db86aabSstevel 		memp->pcw_status |= PCW_WP;
36243db86aabSstevel 	} else {
36253db86aabSstevel 		memp->pcw_status &= ~PCW_WP;
36263db86aabSstevel 	}
36273db86aabSstevel #if defined(PCIC_DEBUG)
36283db86aabSstevel 	if (pcic_debug) {
36293db86aabSstevel 		cmn_err(CE_CONT, "\tmemory type = %s\n",
363019397407SSherry Moore 		    (which & CARDMEM_REG_ACTIVE) ? "attribute" : "common");
36313db86aabSstevel 		if (which & CARDMEM_WRITE_PROTECT)
36323db86aabSstevel 			cmn_err(CE_CONT, "\twrite protect\n");
36333db86aabSstevel 		cmn_err(CE_CONT, "\tpage offset=%x pcw_base=%x (%x)\n",
363419397407SSherry Moore 		    (unsigned)page->offset,
363519397407SSherry Moore 		    (unsigned)memp->pcw_base,
363619397407SSherry Moore 		    (int)page->offset - (int)memp->pcw_base & 0xffffff);
36373db86aabSstevel 	}
36383db86aabSstevel #endif
36393db86aabSstevel 	/* address computation based on 64MB range and not larger */
36403db86aabSstevel 	base = (uint32_t)memp->pcw_base & 0x3ffffff;
36413db86aabSstevel 	pcic_putb(pcic, socket, PCIC_CARDMEM_0_LOW + select,
36423db86aabSstevel 	    CARDMEM_LOW((int)page->offset - (int)base));
36433db86aabSstevel 	(void) pcic_getb(pcic, socket, PCIC_CARDMEM_0_LOW + select);
36443db86aabSstevel 	pcic_putb(pcic, socket, PCIC_CARDMEM_0_HI + select,
36453db86aabSstevel 	    CARDMEM_HIGH((int)page->offset - base) | which);
36463db86aabSstevel 	(void) pcic_getb(pcic, socket, PCIC_CARDMEM_0_HI + select);
36473db86aabSstevel 
36483db86aabSstevel 	/*
36493db86aabSstevel 	 * while not really necessary, this just makes sure
36503db86aabSstevel 	 * nothing turned the window off behind our backs
36513db86aabSstevel 	 */
36523db86aabSstevel 	which = pcic_getb(pcic, socket, PCIC_MAPPING_ENABLE);
36533db86aabSstevel 	which |= SYSMEM_WINDOW(window);
36543db86aabSstevel 	pcic_putb(pcic, socket, PCIC_MAPPING_ENABLE, which);
36553db86aabSstevel 	(void) pcic_getb(pcic, socket, PCIC_MAPPING_ENABLE);
36563db86aabSstevel 
36573db86aabSstevel 	memp->pcw_offset = (off_t)page->offset;
36583db86aabSstevel 
36593db86aabSstevel #if defined(PCIC_DEBUG)
36603db86aabSstevel 	if (pcic_debug) {
36613db86aabSstevel 		cmn_err(CE_CONT, "\tbase=%p, *base=%x\n",
366219397407SSherry Moore 		    (void *)memp->pcw_hostmem,
366319397407SSherry Moore 		    (uint32_t)*memp->pcw_hostmem);
36643db86aabSstevel 
36653db86aabSstevel 		xxdmp_all_regs(pcic, socket, -1);
36663db86aabSstevel 
36673db86aabSstevel 		cmn_err(CE_CONT, "\tbase=%p, *base=%x\n",
366819397407SSherry Moore 		    (void *)memp->pcw_hostmem,
366919397407SSherry Moore 		    (uint32_t)*memp->pcw_hostmem);
36703db86aabSstevel 	}
36713db86aabSstevel #endif
36723db86aabSstevel 
36733db86aabSstevel 	if (which & PCW_ATTRIBUTE)
36743db86aabSstevel 		pcic_mswait(pcic, socket, 2);
36753db86aabSstevel 
36763db86aabSstevel 	mutex_exit(&pcic->pc_lock);
36773db86aabSstevel 
36783db86aabSstevel 	return (SUCCESS);
36793db86aabSstevel }
36803db86aabSstevel 
36813db86aabSstevel /*
36823db86aabSstevel  * pcic_set_vcc_level()
36833db86aabSstevel  *
36843db86aabSstevel  *	set voltage based on adapter information
36853db86aabSstevel  *
36863db86aabSstevel  *	this routine implements a limited solution for support of 3.3v cards.
36873db86aabSstevel  *	the general solution, which would fully support the pcmcia spec
36883db86aabSstevel  *	as far as allowing client drivers to request which voltage levels
36893db86aabSstevel  *	to be set, requires more framework support and driver changes - ess
36903db86aabSstevel  */
36913db86aabSstevel static int
pcic_set_vcc_level(pcicdev_t * pcic,set_socket_t * socket)36923db86aabSstevel pcic_set_vcc_level(pcicdev_t *pcic, set_socket_t *socket)
36933db86aabSstevel {
36943db86aabSstevel 	uint32_t socket_present_state;
36953db86aabSstevel 
36963db86aabSstevel #if defined(PCIC_DEBUG)
36973db86aabSstevel 	if (pcic_debug) {
36983db86aabSstevel 		cmn_err(CE_CONT,
369919397407SSherry Moore 		    "pcic_set_vcc_level(pcic=%p, VccLevel=%d)\n",
370019397407SSherry Moore 		    (void *)pcic, socket->VccLevel);
37013db86aabSstevel 	}
37023db86aabSstevel #endif
37033db86aabSstevel 
37043db86aabSstevel 	/*
37053db86aabSstevel 	 * check VccLevel
37063db86aabSstevel 	 * if this is zero, power is being turned off
37073db86aabSstevel 	 * if it is non-zero, power is being turned on.
37083db86aabSstevel 	 */
37093db86aabSstevel 	if (socket->VccLevel == 0) {
37103db86aabSstevel 		return (0);
37113db86aabSstevel 	}
37123db86aabSstevel 
37133db86aabSstevel 	/*
37143db86aabSstevel 	 * range checking for sanity's sake
37153db86aabSstevel 	 */
37163db86aabSstevel 	if (socket->VccLevel >= pcic->pc_numpower) {
37173db86aabSstevel 		return (BAD_VCC);
37183db86aabSstevel 	}
37193db86aabSstevel 
37203db86aabSstevel 	switch (pcic->pc_io_type) {
37213db86aabSstevel 	/*
37223db86aabSstevel 	 * Yenta-compliant adapters have vcc info in the extended registers
37233db86aabSstevel 	 * Other adapters can be added as needed, but the 'default' case
37243db86aabSstevel 	 * has been left as it was previously so as not to break existing
37253db86aabSstevel 	 * adapters.
37263db86aabSstevel 	 */
37273db86aabSstevel 	case PCIC_IO_TYPE_YENTA:
37283db86aabSstevel 		/*
37293db86aabSstevel 		 * Here we ignore the VccLevel passed in and read the
37303db86aabSstevel 		 * card type from the adapter socket present state register
37313db86aabSstevel 		 */
37323db86aabSstevel 		socket_present_state =
373319397407SSherry Moore 		    ddi_get32(pcic->handle, (uint32_t *)(pcic->ioaddr +
373419397407SSherry Moore 		    PCIC_PRESENT_STATE_REG));
37353db86aabSstevel #if defined(PCIC_DEBUG)
37363db86aabSstevel 		if (pcic_debug) {
37373db86aabSstevel 			cmn_err(CE_CONT,
373819397407SSherry Moore 			    "socket present state = 0x%x\n",
373919397407SSherry Moore 			    socket_present_state);
37403db86aabSstevel 		}
37413db86aabSstevel #endif
37423db86aabSstevel 		switch (socket_present_state & PCIC_VCC_MASK) {
37433db86aabSstevel 			case PCIC_VCC_3VCARD:
37443db86aabSstevel 				/* fall through */
37453db86aabSstevel 			case PCIC_VCC_3VCARD|PCIC_VCC_5VCARD:
37463db86aabSstevel 				socket->VccLevel = PCIC_VCC_3VLEVEL;
37473db86aabSstevel 				return
37483db86aabSstevel 				    (POWER_3VCARD_ENABLE|POWER_OUTPUT_ENABLE);
37493db86aabSstevel 			case PCIC_VCC_5VCARD:
37503db86aabSstevel 				socket->VccLevel = PCIC_VCC_5VLEVEL;
37513db86aabSstevel 				return
37523db86aabSstevel 				    (POWER_CARD_ENABLE|POWER_OUTPUT_ENABLE);
37533db86aabSstevel 			default:
37543db86aabSstevel 				/*
37553db86aabSstevel 				 * if no card is present, this can be the
37563db86aabSstevel 				 * case of a client making a SetSocket call
37573db86aabSstevel 				 * after card removal. In this case we return
37583db86aabSstevel 				 * the current power level
37593db86aabSstevel 				 */
37603db86aabSstevel 				return ((unsigned)ddi_get8(pcic->handle,
37613db86aabSstevel 				    pcic->ioaddr + CB_R2_OFFSET +
376219397407SSherry Moore 				    PCIC_POWER_CONTROL));
37633db86aabSstevel 		}
37643db86aabSstevel 
37653db86aabSstevel 	default:
37663db86aabSstevel 
37673db86aabSstevel 		switch (socket->VccLevel) {
37683db86aabSstevel 		case PCIC_VCC_3VLEVEL:
37693db86aabSstevel 			return (BAD_VCC);
37703db86aabSstevel 		case PCIC_VCC_5VLEVEL:
37713db86aabSstevel 			/* enable Vcc */
37723db86aabSstevel 			return (POWER_CARD_ENABLE|POWER_OUTPUT_ENABLE);
37733db86aabSstevel 		default:
37743db86aabSstevel 			return (BAD_VCC);
37753db86aabSstevel 		}
37763db86aabSstevel 	}
37773db86aabSstevel }
37783db86aabSstevel 
37793db86aabSstevel 
37803db86aabSstevel /*
37813db86aabSstevel  * pcic_set_socket()
37823db86aabSstevel  *	Socket Services SetSocket call
37833db86aabSstevel  *	sets basic socket configuration
37843db86aabSstevel  */
37853db86aabSstevel static int
pcic_set_socket(dev_info_t * dip,set_socket_t * socket)37863db86aabSstevel pcic_set_socket(dev_info_t *dip, set_socket_t *socket)
37873db86aabSstevel {
37883db86aabSstevel 	anp_t *anp = ddi_get_driver_private(dip);
37893db86aabSstevel 	pcicdev_t *pcic = anp->an_private;
37903db86aabSstevel 	pcic_socket_t *sockp = &pcic->pc_sockets[socket->socket];
37913db86aabSstevel 	int irq, interrupt, mirq;
37923db86aabSstevel 	int powerlevel = 0;
37933db86aabSstevel 	int ind, value, orig_pwrctl;
37943db86aabSstevel 
37953db86aabSstevel #if defined(PCIC_DEBUG)
37963db86aabSstevel 	if (pcic_debug) {
37973db86aabSstevel 		cmn_err(CE_CONT,
37983db86aabSstevel 		    "pcic_set_socket(dip=%p, socket=%d)"
37993db86aabSstevel 		    " Vcc=%d Vpp1=%d Vpp2=%d\n", (void *)dip,
38003db86aabSstevel 		    socket->socket, socket->VccLevel, socket->Vpp1Level,
38013db86aabSstevel 		    socket->Vpp2Level);
38023db86aabSstevel 	}
38033db86aabSstevel #endif
38043db86aabSstevel 	/*
38053db86aabSstevel 	 * check VccLevel, etc. before setting mutex
38063db86aabSstevel 	 * if this is zero, power is being turned off
38073db86aabSstevel 	 * if it is non-zero, power is being turned on.
38083db86aabSstevel 	 * the default case is to assume Vcc only.
38093db86aabSstevel 	 */
38103db86aabSstevel 
38113db86aabSstevel 	/* this appears to be very implementation specific */
38123db86aabSstevel 
38133db86aabSstevel 	if (socket->Vpp1Level != socket->Vpp2Level)
38143db86aabSstevel 		return (BAD_VPP);
38153db86aabSstevel 
38163db86aabSstevel 	if (socket->VccLevel == 0 || !(sockp->pcs_flags & PCS_CARD_PRESENT)) {
38173db86aabSstevel 		powerlevel = 0;
38183db86aabSstevel 		sockp->pcs_vcc = 0;
38193db86aabSstevel 		sockp->pcs_vpp1 = 0;
38203db86aabSstevel 		sockp->pcs_vpp2 = 0;
38213db86aabSstevel 	} else {
38223db86aabSstevel #if defined(PCIC_DEBUG)
38233db86aabSstevel 		pcic_err(dip, 9, "\tVcc=%d Vpp1Level=%d, Vpp2Level=%d\n",
38243db86aabSstevel 		    socket->VccLevel, socket->Vpp1Level, socket->Vpp2Level);
38253db86aabSstevel #endif
38263db86aabSstevel 		/* valid Vcc power level? */
38273db86aabSstevel 		if (socket->VccLevel >= pcic->pc_numpower)
38283db86aabSstevel 			return (BAD_VCC);
38293db86aabSstevel 
38303db86aabSstevel 		switch (pcic_power[socket->VccLevel].PowerLevel) {
38313db86aabSstevel 		case 33:	/* 3.3V */
38323db86aabSstevel 		case 60:	/* for bad CIS in Option GPRS card */
38333db86aabSstevel 			if (!(pcic->pc_flags & PCF_33VCAP)) {
38343db86aabSstevel 				cmn_err(CE_WARN,
38353db86aabSstevel 				    "%s%d: Bad Request for 3.3V "
38363db86aabSstevel 				    "(Controller incapable)\n",
38373db86aabSstevel 				    ddi_get_name(pcic->dip),
38383db86aabSstevel 				    ddi_get_instance(pcic->dip));
38393db86aabSstevel 				return (BAD_VCC);
38403db86aabSstevel 			}
38413db86aabSstevel 			/* FALLTHROUGH */
38423db86aabSstevel 		case 50:	/* 5V */
38433db86aabSstevel 			if ((pcic->pc_io_type == PCIC_IO_TYPE_YENTA) &&
38443db86aabSstevel 			    pcic_getcb(pcic, CB_PRESENT_STATE) &
38453db86aabSstevel 			    CB_PS_33VCARD) {
38463db86aabSstevel 				/*
38473db86aabSstevel 				 * This is actually a 3.3V card.
38483db86aabSstevel 				 * Solaris Card Services
38493db86aabSstevel 				 * doesn't understand 3.3V
38503db86aabSstevel 				 * so we cheat and change
38513db86aabSstevel 				 * the setting to the one appropriate to 3.3V.
38523db86aabSstevel 				 * Note that this is the entry number
38533db86aabSstevel 				 * in the pcic_power[] array.
38543db86aabSstevel 				 */
38553db86aabSstevel 				sockp->pcs_vcc = PCIC_VCC_3VLEVEL;
38563db86aabSstevel 			} else
38573db86aabSstevel 				sockp->pcs_vcc = socket->VccLevel;
38583db86aabSstevel 			break;
38593db86aabSstevel 		default:
38603db86aabSstevel 			return (BAD_VCC);
38613db86aabSstevel 		}
38623db86aabSstevel 
38633db86aabSstevel 		/* enable Vcc */
38643db86aabSstevel 		powerlevel = POWER_CARD_ENABLE;
38653db86aabSstevel 
38663db86aabSstevel #if defined(PCIC_DEBUG)
38673db86aabSstevel 		if (pcic_debug) {
38683db86aabSstevel 			cmn_err(CE_CONT, "\tVcc=%d powerlevel=%x\n",
38693db86aabSstevel 			    socket->VccLevel, powerlevel);
38703db86aabSstevel 		}
38713db86aabSstevel #endif
38723db86aabSstevel 		ind = 0;		/* default index to 0 power */
38733db86aabSstevel 		if ((int)socket->Vpp1Level >= 0 &&
38743db86aabSstevel 		    socket->Vpp1Level < pcic->pc_numpower) {
38753db86aabSstevel 			if (!(pcic_power[socket->Vpp1Level].ValidSignals
38763db86aabSstevel 			    & VPP1)) {
38773db86aabSstevel 				return (BAD_VPP);
38783db86aabSstevel 			}
38793db86aabSstevel 			ind = pcic_power[socket->Vpp1Level].PowerLevel/10;
38803db86aabSstevel 			powerlevel |= pcic_vpp_levels[ind];
38813db86aabSstevel 			sockp->pcs_vpp1 = socket->Vpp1Level;
38823db86aabSstevel 		}
38833db86aabSstevel 		if ((int)socket->Vpp2Level >= 0 &&
38843db86aabSstevel 		    socket->Vpp2Level < pcic->pc_numpower) {
38853db86aabSstevel 			if (!(pcic_power[socket->Vpp2Level].ValidSignals
38863db86aabSstevel 			    & VPP2)) {
38873db86aabSstevel 				return (BAD_VPP);
38883db86aabSstevel 			}
38893db86aabSstevel 			ind = pcic_power[socket->Vpp2Level].PowerLevel/10;
38903db86aabSstevel 			powerlevel |= (pcic_vpp_levels[ind] << 2);
38913db86aabSstevel 			sockp->pcs_vpp2 = socket->Vpp2Level;
38923db86aabSstevel 		}
38933db86aabSstevel 
38943db86aabSstevel 		if (pcic->pc_flags & PCF_VPPX) {
38953db86aabSstevel 			/*
38963db86aabSstevel 			 * this adapter doesn't allow separate Vpp1/Vpp2
38973db86aabSstevel 			 * if one is turned on, both are turned on and only
38983db86aabSstevel 			 * the Vpp1 bits should be set
38993db86aabSstevel 			 */
39003db86aabSstevel 			if (sockp->pcs_vpp2 != sockp->pcs_vpp1) {
39013db86aabSstevel 				/* must be the same if one not zero */
39023db86aabSstevel 				if (sockp->pcs_vpp1 != 0 &&
39033db86aabSstevel 				    sockp->pcs_vpp2 != 0) {
39043db86aabSstevel 					cmn_err(CE_WARN,
39053db86aabSstevel 					    "%s%d: Bad Power Request "
39063db86aabSstevel 					    "(Vpp1/2 not the same)\n",
39073db86aabSstevel 					    ddi_get_name(pcic->dip),
39083db86aabSstevel 					    ddi_get_instance(pcic->dip));
39093db86aabSstevel 					return (BAD_VPP);
39103db86aabSstevel 				}
39113db86aabSstevel 			}
39123db86aabSstevel 			powerlevel &= ~(3<<2);
39133db86aabSstevel 		}
39143db86aabSstevel 
39153db86aabSstevel #if defined(PCIC_DEBUG)
39163db86aabSstevel 		if (pcic_debug) {
39173db86aabSstevel 			cmn_err(CE_CONT, "\tpowerlevel=%x, ind=%x\n",
39183db86aabSstevel 			    powerlevel, ind);
39193db86aabSstevel 		}
39203db86aabSstevel #endif
39213db86aabSstevel 	}
39223db86aabSstevel 	mutex_enter(&pcic->pc_lock); /* protect the registers */
39233db86aabSstevel 
39243db86aabSstevel 	/* turn socket->IREQRouting off while programming */
39253db86aabSstevel 	interrupt = pcic_getb(pcic, socket->socket, PCIC_INTERRUPT);
39263db86aabSstevel 	interrupt &= ~PCIC_INTR_MASK;
39273db86aabSstevel 	if (pcic->pc_flags & PCF_USE_SMI)
39283db86aabSstevel 		interrupt |= PCIC_INTR_ENABLE;
39293db86aabSstevel 	pcic_putb(pcic, socket->socket, PCIC_INTERRUPT, interrupt);
39303db86aabSstevel 
39313db86aabSstevel 	switch (pcic->pc_type) {
393219397407SSherry Moore 		case PCIC_INTEL_i82092:
39333db86aabSstevel 		pcic_82092_smiirq_ctl(pcic, socket->socket, PCIC_82092_CTL_IRQ,
393419397407SSherry Moore 		    PCIC_82092_INT_DISABLE);
39353db86aabSstevel 		break;
393619397407SSherry Moore 		default:
39373db86aabSstevel 		break;
39383db86aabSstevel 	} /* switch */
39393db86aabSstevel 
39403db86aabSstevel 	/* the SCIntMask specifies events to detect */
39413db86aabSstevel 	mirq = pcic_getb(pcic, socket->socket, PCIC_MANAGEMENT_INT);
39423db86aabSstevel 
39433db86aabSstevel #if defined(PCIC_DEBUG)
39443db86aabSstevel 	if (pcic_debug)
39453db86aabSstevel 		cmn_err(CE_CONT,
394619397407SSherry Moore 		    "\tSCIntMask=%x, interrupt=%x, mirq=%x\n",
394719397407SSherry Moore 		    socket->SCIntMask, interrupt, mirq);
39483db86aabSstevel #endif
39493db86aabSstevel 	mirq &= ~(PCIC_BD_DETECT|PCIC_BW_DETECT|PCIC_RD_DETECT);
39503db86aabSstevel 	pcic_putb(pcic, socket->socket, PCIC_MANAGEMENT_INT,
39513db86aabSstevel 	    mirq & ~PCIC_CHANGE_MASK);
39523db86aabSstevel 
39533db86aabSstevel 	/* save the mask we want to use */
39543db86aabSstevel 	sockp->pcs_intmask = socket->SCIntMask;
39553db86aabSstevel 
39563db86aabSstevel 	/*
39573db86aabSstevel 	 * Until there is a card present it's not worth enabling
39583db86aabSstevel 	 * any interrupts except "Card detect". This is done
39593db86aabSstevel 	 * elsewhere in the driver so don't change things if
39603db86aabSstevel 	 * there is no card!
39613db86aabSstevel 	 */
39623db86aabSstevel 	if (sockp->pcs_flags & PCS_CARD_PRESENT) {
39633db86aabSstevel 
39643db86aabSstevel 		/* now update the hardware to reflect events desired */
39653db86aabSstevel 		if (sockp->pcs_intmask & SBM_BVD1 || socket->IFType == IF_IO)
39663db86aabSstevel 			mirq |= PCIC_BD_DETECT;
39673db86aabSstevel 
39683db86aabSstevel 		if (sockp->pcs_intmask & SBM_BVD2)
39693db86aabSstevel 			mirq |= PCIC_BW_DETECT;
39703db86aabSstevel 
39713db86aabSstevel 		if (sockp->pcs_intmask & SBM_RDYBSY)
39723db86aabSstevel 			mirq |= PCIC_RD_DETECT;
39733db86aabSstevel 
39743db86aabSstevel 		if (sockp->pcs_intmask & SBM_CD)
39753db86aabSstevel 			mirq |= PCIC_CD_DETECT;
39763db86aabSstevel 	}
39773db86aabSstevel 
39783db86aabSstevel 	if (sockp->pcs_flags & PCS_READY) {
39793db86aabSstevel 		/*
39803db86aabSstevel 		 * card just came ready.
39813db86aabSstevel 		 * make sure enough time elapses
39823db86aabSstevel 		 * before touching it.
39833db86aabSstevel 		 */
39843db86aabSstevel 		sockp->pcs_flags &= ~PCS_READY;
39853db86aabSstevel 		pcic_mswait(pcic, socket->socket, 10);
39863db86aabSstevel 	}
39873db86aabSstevel 
39883db86aabSstevel #if defined(PCIC_DEBUG)
39893db86aabSstevel 	if (pcic_debug) {
39903db86aabSstevel 		cmn_err(CE_CONT, "\tstatus change set to %x\n", mirq);
39913db86aabSstevel 	}
39923db86aabSstevel #endif
39933db86aabSstevel 
39943db86aabSstevel 	switch (pcic->pc_type) {
399519397407SSherry Moore 		case PCIC_I82365SL:
399619397407SSherry Moore 		case PCIC_VADEM:
399719397407SSherry Moore 		case PCIC_VADEM_VG469:
39983db86aabSstevel 		/*
39993db86aabSstevel 		 * The Intel version has different options. This is a
40003db86aabSstevel 		 * special case of GPI which might be used for eject
40013db86aabSstevel 		 */
40023db86aabSstevel 
40033db86aabSstevel 		irq = pcic_getb(pcic, socket->socket, PCIC_CARD_DETECT);
40043db86aabSstevel 		if (sockp->pcs_intmask & (SBM_EJECT|SBM_INSERT) &&
40053db86aabSstevel 		    pcic->pc_flags & PCF_GPI_EJECT) {
40063db86aabSstevel 			irq |= PCIC_GPI_ENABLE;
40073db86aabSstevel 		} else {
40083db86aabSstevel 			irq &= ~PCIC_GPI_ENABLE;
40093db86aabSstevel 		}
40103db86aabSstevel 		pcic_putb(pcic, socket->socket, PCIC_CARD_DETECT, irq);
40113db86aabSstevel 		break;
401219397407SSherry Moore 		case PCIC_CL_PD6710:
401319397407SSherry Moore 		case PCIC_CL_PD6722:
40143db86aabSstevel 		if (socket->IFType == IF_IO) {
40153db86aabSstevel 			pcic_putb(pcic, socket->socket, PCIC_MISC_CTL_2, 0x0);
40163db86aabSstevel 			value = pcic_getb(pcic, socket->socket,
401719397407SSherry Moore 			    PCIC_MISC_CTL_1);
40183db86aabSstevel 			if (pcic->pc_flags & PCF_AUDIO)
40193db86aabSstevel 				value |= PCIC_MC_SPEAKER_ENB;
40203db86aabSstevel 			pcic_putb(pcic, socket->socket, PCIC_MISC_CTL_1,
402119397407SSherry Moore 			    value);
40223db86aabSstevel 		} else {
40233db86aabSstevel 			value = pcic_getb(pcic, socket->socket,
402419397407SSherry Moore 			    PCIC_MISC_CTL_1);
40253db86aabSstevel 			value &= ~PCIC_MC_SPEAKER_ENB;
40263db86aabSstevel 			pcic_putb(pcic, socket->socket, PCIC_MISC_CTL_1,
402719397407SSherry Moore 			    value);
40283db86aabSstevel 		}
40293db86aabSstevel 		break;
403019397407SSherry Moore 		case PCIC_CL_PD6729:
403119397407SSherry Moore 		case PCIC_CL_PD6730:
403219397407SSherry Moore 		case PCIC_CL_PD6832:
40333db86aabSstevel 		value = pcic_getb(pcic, socket->socket, PCIC_MISC_CTL_1);
40343db86aabSstevel 		if ((socket->IFType == IF_IO) && (pcic->pc_flags & PCF_AUDIO)) {
403519397407SSherry Moore 			value |= PCIC_MC_SPEAKER_ENB;
40363db86aabSstevel 		} else {
403719397407SSherry Moore 			value &= ~PCIC_MC_SPEAKER_ENB;
40383db86aabSstevel 		}
40393db86aabSstevel 
40403db86aabSstevel 		if (pcic_power[sockp->pcs_vcc].PowerLevel == 33)
40413db86aabSstevel 			value |= PCIC_MC_3VCC;
40423db86aabSstevel 		else
40433db86aabSstevel 			value &= ~PCIC_MC_3VCC;
40443db86aabSstevel 
40453db86aabSstevel 		pcic_putb(pcic, socket->socket, PCIC_MISC_CTL_1, value);
40463db86aabSstevel 		break;
40473db86aabSstevel 
404819397407SSherry Moore 		case PCIC_O2_OZ6912:
40493db86aabSstevel 		value = pcic_getcb(pcic, CB_MISCCTRL);
40503db86aabSstevel 		if ((socket->IFType == IF_IO) && (pcic->pc_flags & PCF_AUDIO))
40513db86aabSstevel 			value |= (1<<25);
40523db86aabSstevel 		else
40533db86aabSstevel 			value &= ~(1<<25);
40543db86aabSstevel 		pcic_putcb(pcic, CB_MISCCTRL, value);
40553db86aabSstevel 		if (pcic_power[sockp->pcs_vcc].PowerLevel == 33)
40563db86aabSstevel 			powerlevel |= 0x08;
40573db86aabSstevel 		break;
40583db86aabSstevel 
405919397407SSherry Moore 		case PCIC_TI_PCI1250:
406019397407SSherry Moore 		case PCIC_TI_PCI1221:
406119397407SSherry Moore 		case PCIC_TI_PCI1225:
406219397407SSherry Moore 		case PCIC_TI_PCI1410:
406319397407SSherry Moore 		case PCIC_ENE_1410:
406419397407SSherry Moore 		case PCIC_TI_PCI1510:
406519397407SSherry Moore 		case PCIC_TI_PCI1520:
406619397407SSherry Moore 		case PCIC_TI_PCI1420:
406719397407SSherry Moore 		case PCIC_ENE_1420:
40683db86aabSstevel 		value = ddi_get8(pcic->cfg_handle,
40693db86aabSstevel 		    pcic->cfgaddr + PCIC_CRDCTL_REG);
40703db86aabSstevel 		if ((socket->IFType == IF_IO) && (pcic->pc_flags & PCF_AUDIO)) {
40713db86aabSstevel 			value |= PCIC_CRDCTL_SPKR_ENBL;
40723db86aabSstevel 		} else {
40733db86aabSstevel 			value &= ~PCIC_CRDCTL_SPKR_ENBL;
40743db86aabSstevel 		}
40753db86aabSstevel 		ddi_put8(pcic->cfg_handle,
40763db86aabSstevel 		    pcic->cfgaddr + PCIC_CRDCTL_REG, value);
40773db86aabSstevel 		if (pcic_power[sockp->pcs_vcc].PowerLevel == 33)
40783db86aabSstevel 			powerlevel |= 0x08;
40793db86aabSstevel 		break;
40803db86aabSstevel 	}
40813db86aabSstevel 
40823db86aabSstevel 	/*
40833db86aabSstevel 	 * ctlind processing -- we can ignore this
40843db86aabSstevel 	 * there aren't any outputs on the chip for this and
40853db86aabSstevel 	 * the GUI will display what it thinks is correct
40863db86aabSstevel 	 */
40873db86aabSstevel 
40883db86aabSstevel 	/*
40893db86aabSstevel 	 * If outputs are enabled and the power is going off
40903db86aabSstevel 	 * turn off outputs first.
40913db86aabSstevel 	 */
40923db86aabSstevel 
40933db86aabSstevel 	/* power setup -- if necessary */
40943db86aabSstevel 	orig_pwrctl = pcic_getb(pcic, socket->socket, PCIC_POWER_CONTROL);
40953db86aabSstevel 	if ((orig_pwrctl & POWER_OUTPUT_ENABLE) && sockp->pcs_vcc == 0) {
40963db86aabSstevel 		orig_pwrctl &= ~POWER_OUTPUT_ENABLE;
40973db86aabSstevel 		pcic_putb(pcic, socket->socket,
40983db86aabSstevel 		    PCIC_POWER_CONTROL, orig_pwrctl);
40993db86aabSstevel 		(void) pcic_getb(pcic, socket->socket, PCIC_POWER_CONTROL);
41003db86aabSstevel 	}
41013db86aabSstevel 
41023db86aabSstevel 	if (pcic->pc_flags & PCF_CBPWRCTL) {
41033db86aabSstevel 		value = pcic_cbus_powerctl(pcic, socket->socket);
41043db86aabSstevel 		powerlevel = 0;
41053db86aabSstevel 	} else
41063db86aabSstevel 		value = pcic_exca_powerctl(pcic, socket->socket, powerlevel);
41073db86aabSstevel 
41083db86aabSstevel 	if (value != SUCCESS) {
41093db86aabSstevel 		mutex_exit(&pcic->pc_lock);
41103db86aabSstevel 		return (value);
41113db86aabSstevel 	}
41123db86aabSstevel 
41133db86aabSstevel 	/*
41143db86aabSstevel 	 * If outputs were disabled and the power is going on
41153db86aabSstevel 	 * turn on outputs afterwards.
41163db86aabSstevel 	 */
41173db86aabSstevel 	if (!(orig_pwrctl & POWER_OUTPUT_ENABLE) && sockp->pcs_vcc != 0) {
41183db86aabSstevel 		orig_pwrctl = pcic_getb(pcic, socket->socket,
41193db86aabSstevel 		    PCIC_POWER_CONTROL);
41203db86aabSstevel 		orig_pwrctl |= POWER_OUTPUT_ENABLE;
41213db86aabSstevel 		pcic_putb(pcic, socket->socket,
41223db86aabSstevel 		    PCIC_POWER_CONTROL, orig_pwrctl);
41233db86aabSstevel 		(void) pcic_getb(pcic, socket->socket, PCIC_POWER_CONTROL);
41243db86aabSstevel 	}
41253db86aabSstevel 
41263db86aabSstevel 	/*
41273db86aabSstevel 	 * Once we have done the power stuff can re-enable management
41283db86aabSstevel 	 * interrupts.
41293db86aabSstevel 	 */
41303db86aabSstevel 	pcic_putb(pcic, socket->socket, PCIC_MANAGEMENT_INT, mirq);
41313db86aabSstevel 
41323db86aabSstevel #if defined(PCIC_DEBUG)
41333db86aabSstevel 	pcic_err(dip, 8, "\tmanagement int set to %x pwrctl to 0x%x "
41343db86aabSstevel 	    "cbctl 0x%x\n",
41353db86aabSstevel 	    mirq, pcic_getb(pcic, socket->socket, PCIC_POWER_CONTROL),
41363db86aabSstevel 	    pcic_getcb(pcic, CB_CONTROL));
41373db86aabSstevel #endif
41383db86aabSstevel 
41393db86aabSstevel 	/* irq processing */
41403db86aabSstevel 	if (socket->IFType == IF_IO) {
41413db86aabSstevel 		/* IRQ only for I/O */
41423db86aabSstevel 		irq = socket->IREQRouting & PCIC_INTR_MASK;
41433db86aabSstevel 		value = pcic_getb(pcic, socket->socket, PCIC_INTERRUPT);
41443db86aabSstevel 		value &= ~PCIC_INTR_MASK;
41453db86aabSstevel 
41463db86aabSstevel 		/* to enable I/O operation */
41473db86aabSstevel 		value |= PCIC_IO_CARD | PCIC_RESET;
41483db86aabSstevel 		sockp->pcs_flags |= PCS_CARD_IO;
41493db86aabSstevel 		if (irq != sockp->pcs_irq) {
41503db86aabSstevel 			if (sockp->pcs_irq != 0)
41513db86aabSstevel 				cmn_err(CE_CONT,
415219397407SSherry Moore 				    "SetSocket: IRQ mismatch %x != %x!\n",
415319397407SSherry Moore 				    irq, sockp->pcs_irq);
41543db86aabSstevel 			else
41553db86aabSstevel 				sockp->pcs_irq = irq;
41563db86aabSstevel 		}
41573db86aabSstevel 		irq = sockp->pcs_irq;
41583db86aabSstevel 
41593db86aabSstevel 		pcic_putb(pcic, socket->socket, PCIC_INTERRUPT, value);
41603db86aabSstevel 		if (socket->IREQRouting & IRQ_ENABLE) {
41613db86aabSstevel 			pcic_enable_io_intr(pcic, socket->socket, irq);
41623db86aabSstevel 			sockp->pcs_flags |= PCS_IRQ_ENABLED;
41633db86aabSstevel 		} else {
41643db86aabSstevel 			pcic_disable_io_intr(pcic, socket->socket);
41653db86aabSstevel 			sockp->pcs_flags &= ~PCS_IRQ_ENABLED;
41663db86aabSstevel 		}
41673db86aabSstevel #if defined(PCIC_DEBUG)
41683db86aabSstevel 		if (pcic_debug) {
41693db86aabSstevel 			cmn_err(CE_CONT,
417019397407SSherry Moore 			    "\tsocket type is I/O and irq %x is %s\n", irq,
417119397407SSherry Moore 			    (socket->IREQRouting & IRQ_ENABLE) ?
417219397407SSherry Moore 			    "enabled" : "not enabled");
41733db86aabSstevel 			xxdmp_all_regs(pcic, socket->socket, 20);
41743db86aabSstevel 		}
41753db86aabSstevel #endif
41763db86aabSstevel 	} else {
41773db86aabSstevel 		/* make sure I/O mode is off */
41783db86aabSstevel 
41793db86aabSstevel 		sockp->pcs_irq = 0;
41803db86aabSstevel 
41813db86aabSstevel 		value = pcic_getb(pcic, socket->socket, PCIC_INTERRUPT);
41823db86aabSstevel 		value &= ~PCIC_IO_CARD;
41833db86aabSstevel 		pcic_putb(pcic, socket->socket, PCIC_INTERRUPT, value);
41843db86aabSstevel 		pcic_disable_io_intr(pcic, socket->socket);
41853db86aabSstevel 		sockp->pcs_flags &= ~(PCS_CARD_IO|PCS_IRQ_ENABLED);
41863db86aabSstevel 	}
41873db86aabSstevel 
41883db86aabSstevel 	sockp->pcs_state &= ~socket->State;
41893db86aabSstevel 
41903db86aabSstevel 	mutex_exit(&pcic->pc_lock);
41913db86aabSstevel 	return (SUCCESS);
41923db86aabSstevel }
41933db86aabSstevel 
41943db86aabSstevel /*
41953db86aabSstevel  * pcic_inquire_socket()
41963db86aabSstevel  *	SocketServices InquireSocket function
41973db86aabSstevel  *	returns basic characteristics of the socket
41983db86aabSstevel  */
41993db86aabSstevel /*ARGSUSED*/
42003db86aabSstevel static int
pcic_inquire_socket(dev_info_t * dip,inquire_socket_t * socket)42013db86aabSstevel pcic_inquire_socket(dev_info_t *dip, inquire_socket_t *socket)
42023db86aabSstevel {
42033db86aabSstevel 	anp_t *anp = ddi_get_driver_private(dip);
42043db86aabSstevel 	pcicdev_t *pcic = anp->an_private;
42053db86aabSstevel 	int value;
42063db86aabSstevel 
42073db86aabSstevel 	socket->SCIntCaps = PCIC_DEFAULT_INT_CAPS;
42083db86aabSstevel 	socket->SCRptCaps = PCIC_DEFAULT_RPT_CAPS;
42093db86aabSstevel 	socket->CtlIndCaps = PCIC_DEFAULT_CTL_CAPS;
42103db86aabSstevel 	value = pcic->pc_sockets[socket->socket].pcs_flags;
42113db86aabSstevel 	socket->SocketCaps = (value & PCS_SOCKET_IO) ? IF_IO : IF_MEMORY;
42123db86aabSstevel 	socket->ActiveHigh = 0;
42133db86aabSstevel 	/* these are the usable IRQs */
42143db86aabSstevel 	socket->ActiveLow = 0xfff0;
42153db86aabSstevel 	return (SUCCESS);
42163db86aabSstevel }
42173db86aabSstevel 
42183db86aabSstevel /*
42193db86aabSstevel  * pcic_inquire_window()
42203db86aabSstevel  *	SocketServices InquireWindow function
42213db86aabSstevel  *	returns detailed characteristics of the window
42223db86aabSstevel  *	this is where windows get tied to sockets
42233db86aabSstevel  */
42243db86aabSstevel /*ARGSUSED*/
42253db86aabSstevel static int
pcic_inquire_window(dev_info_t * dip,inquire_window_t * window)42263db86aabSstevel pcic_inquire_window(dev_info_t *dip, inquire_window_t *window)
42273db86aabSstevel {
42283db86aabSstevel 	int type, socket;
42293db86aabSstevel 
42303db86aabSstevel 	type = window->window % PCIC_NUMWINSOCK;
42313db86aabSstevel 	socket = window->window / PCIC_NUMWINSOCK;
42323db86aabSstevel 
42333db86aabSstevel #if defined(PCIC_DEBUG)
42343db86aabSstevel 	if (pcic_debug >= 8)
42353db86aabSstevel 		cmn_err(CE_CONT,
423619397407SSherry Moore 		    "pcic_inquire_window: window = %d/%d socket=%d\n",
423719397407SSherry Moore 		    window->window, type, socket);
42383db86aabSstevel #endif
42393db86aabSstevel 	if (type < PCIC_IOWINDOWS) {
42403db86aabSstevel 		window->WndCaps = WC_IO|WC_WAIT;
42413db86aabSstevel 		type = IF_IO;
42423db86aabSstevel 	} else {
42433db86aabSstevel 		window->WndCaps = WC_COMMON|WC_ATTRIBUTE|WC_WAIT;
42443db86aabSstevel 		type = IF_MEMORY;
42453db86aabSstevel 	}
42463db86aabSstevel 
42473db86aabSstevel 	/* initialize the socket map - one socket per window */
42483db86aabSstevel 	PR_ZERO(window->Sockets);
42493db86aabSstevel 	PR_SET(window->Sockets, socket);
42503db86aabSstevel 
42513db86aabSstevel 	if (type == IF_IO) {
42523db86aabSstevel 		iowin_char_t *io;
42533db86aabSstevel 		io = &window->iowin_char;
42543db86aabSstevel 		io->IOWndCaps = WC_BASE|WC_SIZE|WC_WENABLE|WC_8BIT|
425519397407SSherry Moore 		    WC_16BIT;
42563db86aabSstevel 		io->FirstByte = (baseaddr_t)IOMEM_FIRST;
42573db86aabSstevel 		io->LastByte = (baseaddr_t)IOMEM_LAST;
42583db86aabSstevel 		io->MinSize = IOMEM_MIN;
42593db86aabSstevel 		io->MaxSize = IOMEM_MAX;
42603db86aabSstevel 		io->ReqGran = IOMEM_GRAN;
42613db86aabSstevel 		io->AddrLines = IOMEM_DECODE;
42623db86aabSstevel 		io->EISASlot = 0;
42633db86aabSstevel 	} else {
42643db86aabSstevel 		mem_win_char_t *mem;
42653db86aabSstevel 		mem = &window->mem_win_char;
42663db86aabSstevel 		mem->MemWndCaps = WC_BASE|WC_SIZE|WC_WENABLE|WC_8BIT|
426719397407SSherry Moore 		    WC_16BIT|WC_WP;
42683db86aabSstevel 
42693db86aabSstevel 		mem->FirstByte = (baseaddr_t)MEM_FIRST;
42703db86aabSstevel 		mem->LastByte = (baseaddr_t)MEM_LAST;
42713db86aabSstevel 
42723db86aabSstevel 		mem->MinSize = MEM_MIN;
42733db86aabSstevel 		mem->MaxSize = MEM_MAX;
42743db86aabSstevel 		mem->ReqGran = PCIC_PAGE;
42753db86aabSstevel 		mem->ReqBase = 0;
42763db86aabSstevel 		mem->ReqOffset = PCIC_PAGE;
42773db86aabSstevel 		mem->Slowest = MEM_SPEED_MAX;
42783db86aabSstevel 		mem->Fastest = MEM_SPEED_MIN;
42793db86aabSstevel 	}
42803db86aabSstevel 	return (SUCCESS);
42813db86aabSstevel }
42823db86aabSstevel 
42833db86aabSstevel /*
42843db86aabSstevel  * pcic_get_adapter()
42853db86aabSstevel  *	SocketServices GetAdapter function
42863db86aabSstevel  *	this is nearly a no-op.
42873db86aabSstevel  */
42883db86aabSstevel /*ARGSUSED*/
42893db86aabSstevel static int
pcic_get_adapter(dev_info_t * dip,get_adapter_t * adapt)42903db86aabSstevel pcic_get_adapter(dev_info_t *dip, get_adapter_t *adapt)
42913db86aabSstevel {
42923db86aabSstevel 	anp_t *anp = ddi_get_driver_private(dip);
42933db86aabSstevel 	pcicdev_t *pcic = anp->an_private;
42943db86aabSstevel 
42953db86aabSstevel 	if (pcic->pc_flags & PCF_INTRENAB)
42963db86aabSstevel 		adapt->SCRouting = IRQ_ENABLE;
42973db86aabSstevel 	adapt->state = 0;
42983db86aabSstevel 	return (SUCCESS);
42993db86aabSstevel }
43003db86aabSstevel 
43013db86aabSstevel /*
43023db86aabSstevel  * pcic_get_page()
43033db86aabSstevel  *	SocketServices GetPage function
43043db86aabSstevel  *	returns info about the window
43053db86aabSstevel  */
43063db86aabSstevel /*ARGSUSED*/
43073db86aabSstevel static int
pcic_get_page(dev_info_t * dip,get_page_t * page)43083db86aabSstevel pcic_get_page(dev_info_t *dip, get_page_t *page)
43093db86aabSstevel {
43103db86aabSstevel 	anp_t *anp = ddi_get_driver_private(dip);
43113db86aabSstevel 	pcicdev_t *pcic = anp->an_private;
43123db86aabSstevel 	int socket, window;
43133db86aabSstevel 	pcs_memwin_t *winp;
43143db86aabSstevel 
43153db86aabSstevel 	socket = page->window / PCIC_NUMWINSOCK;
43163db86aabSstevel 	window = page->window % PCIC_NUMWINSOCK;
43173db86aabSstevel 
43183db86aabSstevel 	/* I/O windows are the first two */
43193db86aabSstevel 	if (window < PCIC_IOWINDOWS || socket >= pcic->pc_numsockets) {
43203db86aabSstevel 		return (BAD_WINDOW);
43213db86aabSstevel 	}
43223db86aabSstevel 
43233db86aabSstevel 	winp = &pcic->pc_sockets[socket].pcs_windows[window].mem;
43243db86aabSstevel 
43253db86aabSstevel 	if (page->page != 0)
43263db86aabSstevel 		return (BAD_PAGE);
43273db86aabSstevel 
43283db86aabSstevel 	page->state = 0;
43293db86aabSstevel 	if (winp->pcw_status & PCW_ENABLED)
43303db86aabSstevel 		page->state |= PS_ENABLED;
43313db86aabSstevel 	if (winp->pcw_status & PCW_ATTRIBUTE)
43323db86aabSstevel 		page->state |= PS_ATTRIBUTE;
43333db86aabSstevel 	if (winp->pcw_status & PCW_WP)
43343db86aabSstevel 		page->state |= PS_WP;
43353db86aabSstevel 
43363db86aabSstevel 	page->offset = (off_t)winp->pcw_offset;
43373db86aabSstevel 
43383db86aabSstevel 	return (SUCCESS);
43393db86aabSstevel }
43403db86aabSstevel 
43413db86aabSstevel /*
43423db86aabSstevel  * pcic_get_socket()
43433db86aabSstevel  *	SocketServices GetSocket
43443db86aabSstevel  *	returns information about the current socket setting
43453db86aabSstevel  */
43463db86aabSstevel /*ARGSUSED*/
43473db86aabSstevel static int
pcic_get_socket(dev_info_t * dip,get_socket_t * socket)43483db86aabSstevel pcic_get_socket(dev_info_t *dip, get_socket_t *socket)
43493db86aabSstevel {
43503db86aabSstevel 	anp_t *anp = ddi_get_driver_private(dip);
43513db86aabSstevel 	pcicdev_t *pcic = anp->an_private;
43523db86aabSstevel 	int socknum, irq_enabled;
43533db86aabSstevel 	pcic_socket_t *sockp;
43543db86aabSstevel 
43553db86aabSstevel 	socknum = socket->socket;
43563db86aabSstevel 	sockp = &pcic->pc_sockets[socknum];
43573db86aabSstevel 
43583db86aabSstevel 	socket->SCIntMask = sockp->pcs_intmask;
43593db86aabSstevel 	sockp->pcs_state = pcic_card_state(pcic, sockp);
43603db86aabSstevel 
43613db86aabSstevel 	socket->state = sockp->pcs_state;
43623db86aabSstevel 	if (socket->state & SBM_CD) {
43633db86aabSstevel 		socket->VccLevel = sockp->pcs_vcc;
43643db86aabSstevel 		socket->Vpp1Level = sockp->pcs_vpp1;
43653db86aabSstevel 		socket->Vpp2Level = sockp->pcs_vpp2;
43663db86aabSstevel 		irq_enabled = (sockp->pcs_flags & PCS_IRQ_ENABLED) ?
43673db86aabSstevel 		    IRQ_ENABLE : 0;
43683db86aabSstevel 		socket->IRQRouting = sockp->pcs_irq | irq_enabled;
43693db86aabSstevel 		socket->IFType = (sockp->pcs_flags & PCS_CARD_IO) ?
43703db86aabSstevel 		    IF_IO : IF_MEMORY;
43713db86aabSstevel 	} else {
43723db86aabSstevel 		socket->VccLevel = 0;
43733db86aabSstevel 		socket->Vpp1Level = 0;
43743db86aabSstevel 		socket->Vpp2Level = 0;
43753db86aabSstevel 		socket->IRQRouting = 0;
43763db86aabSstevel 		socket->IFType = IF_MEMORY;
43773db86aabSstevel 	}
43783db86aabSstevel 	socket->CtlInd = 0;	/* no indicators */
43793db86aabSstevel 
43803db86aabSstevel 	return (SUCCESS);
43813db86aabSstevel }
43823db86aabSstevel 
43833db86aabSstevel /*
43843db86aabSstevel  * pcic_get_status()
43853db86aabSstevel  *	SocketServices GetStatus
43863db86aabSstevel  *	returns status information about the PC Card in
43873db86aabSstevel  *	the selected socket
43883db86aabSstevel  */
43893db86aabSstevel /*ARGSUSED*/
43903db86aabSstevel static int
pcic_get_status(dev_info_t * dip,get_ss_status_t * status)43913db86aabSstevel pcic_get_status(dev_info_t *dip, get_ss_status_t *status)
43923db86aabSstevel {
43933db86aabSstevel 	anp_t *anp = ddi_get_driver_private(dip);
43943db86aabSstevel 	pcicdev_t *pcic = anp->an_private;
43953db86aabSstevel 	int socknum, irq_enabled;
43963db86aabSstevel 	pcic_socket_t *sockp;
43973db86aabSstevel 
43983db86aabSstevel 	socknum = status->socket;
43993db86aabSstevel 	sockp = &pcic->pc_sockets[socknum];
44003db86aabSstevel 
44013db86aabSstevel 	status->CardState = pcic_card_state(pcic, sockp);
44023db86aabSstevel 	status->SocketState = sockp->pcs_state;
44033db86aabSstevel 	status->CtlInd = 0;	/* no indicators */
44043db86aabSstevel 
44053db86aabSstevel 	if (sockp->pcs_flags & PCS_CARD_PRESENT)
44063db86aabSstevel 		status->SocketState |= SBM_CD;
44073db86aabSstevel 	if (status->CardState & SBM_CD) {
44083db86aabSstevel 		irq_enabled = (sockp->pcs_flags & PCS_CARD_ENABLED) ?
44093db86aabSstevel 		    IRQ_ENABLE : 0;
44103db86aabSstevel 		status->IRQRouting = sockp->pcs_irq | irq_enabled;
44113db86aabSstevel 		status->IFType = (sockp->pcs_flags & PCS_CARD_IO) ?
44123db86aabSstevel 		    IF_IO : IF_MEMORY;
44133db86aabSstevel 	} else {
44143db86aabSstevel 		status->IRQRouting = 0;
44153db86aabSstevel 		status->IFType = IF_MEMORY;
44163db86aabSstevel 	}
44173db86aabSstevel 
44183db86aabSstevel #if defined(PCIC_DEBUG)
44193db86aabSstevel 	if (pcic_debug >= 8)
44203db86aabSstevel 		cmn_err(CE_CONT, "pcic_get_status: socket=%d, CardState=%x,"
442119397407SSherry Moore 		    "SocketState=%x\n",
442219397407SSherry Moore 		    socknum, status->CardState, status->SocketState);
44233db86aabSstevel #endif
44243db86aabSstevel 	switch (pcic->pc_type) {
44253db86aabSstevel 	uint32_t present_state;
44263db86aabSstevel 	case PCIC_TI_PCI1410:
44273db86aabSstevel 	case PCIC_TI_PCI1520:
44283db86aabSstevel 	case PCIC_TI_PCI1420:
44293db86aabSstevel 	case PCIC_ENE_1420:
44303db86aabSstevel 	case PCIC_TOSHIBA_TOPIC100:
44313db86aabSstevel 	case PCIC_TOSHIBA_TOPIC95:
44323db86aabSstevel 	case PCIC_TOSHIBA_VENDOR:
44333db86aabSstevel 	case PCIC_O2MICRO_VENDOR:
44343db86aabSstevel 	case PCIC_TI_VENDOR:
44353db86aabSstevel 	case PCIC_RICOH_VENDOR:
44363db86aabSstevel 		present_state = pcic_getcb(pcic, CB_PRESENT_STATE);
44373db86aabSstevel 		if (present_state & PCIC_CB_CARD)
44383db86aabSstevel 			status->IFType = IF_CARDBUS;
44393db86aabSstevel #if defined(PCIC_DEBUG)
44403db86aabSstevel 		if (pcic_debug >= 8)
444119397407SSherry Moore 			cmn_err(CE_CONT,
444219397407SSherry Moore 			    "pcic_get_status: present_state=0x%x\n",
444319397407SSherry Moore 			    present_state);
44443db86aabSstevel #endif
44453db86aabSstevel 		break;
44463db86aabSstevel 	default:
44473db86aabSstevel 		break;
44483db86aabSstevel 	}
44493db86aabSstevel 
44503db86aabSstevel 	return (SUCCESS);
44513db86aabSstevel }
44523db86aabSstevel 
44533db86aabSstevel /*
44543db86aabSstevel  * pcic_get_window()
44553db86aabSstevel  *	SocketServices GetWindow function
44563db86aabSstevel  *	returns state information about the specified window
44573db86aabSstevel  */
44583db86aabSstevel /*ARGSUSED*/
44593db86aabSstevel static int
pcic_get_window(dev_info_t * dip,get_window_t * window)44603db86aabSstevel pcic_get_window(dev_info_t *dip, get_window_t *window)
44613db86aabSstevel {
44623db86aabSstevel 	anp_t *anp = ddi_get_driver_private(dip);
44633db86aabSstevel 	pcicdev_t *pcic = anp->an_private;
44643db86aabSstevel 	int socket, win;
44653db86aabSstevel 	pcic_socket_t *sockp;
44663db86aabSstevel 	pcs_memwin_t *winp;
44673db86aabSstevel 
44683db86aabSstevel 	socket = window->window / PCIC_NUMWINSOCK;
44693db86aabSstevel 	win = window->window % PCIC_NUMWINSOCK;
44703db86aabSstevel #if defined(PCIC_DEBUG)
44713db86aabSstevel 	if (pcic_debug) {
44723db86aabSstevel 		cmn_err(CE_CONT, "pcic_get_window(socket=%d, window=%d)\n",
447319397407SSherry Moore 		    socket, win);
44743db86aabSstevel 	}
44753db86aabSstevel #endif
44763db86aabSstevel 
44773db86aabSstevel 	if (socket > pcic->pc_numsockets)
44783db86aabSstevel 		return (BAD_WINDOW);
44793db86aabSstevel 
44803db86aabSstevel 	sockp = &pcic->pc_sockets[socket];
44813db86aabSstevel 	winp = &sockp->pcs_windows[win].mem;
44823db86aabSstevel 
44833db86aabSstevel 	window->socket = socket;
44843db86aabSstevel 	window->size = winp->pcw_len;
44853db86aabSstevel 	window->speed = winp->pcw_speed;
44863db86aabSstevel 	window->handle = (ddi_acc_handle_t)winp->pcw_handle;
44873db86aabSstevel 	window->base = (uint32_t)winp->pcw_base + winp->pcw_offset;
44883db86aabSstevel 
44893db86aabSstevel 	if (win >= PCIC_IOWINDOWS) {
44903db86aabSstevel 		window->state = 0;
44913db86aabSstevel 	} else {
44923db86aabSstevel 		window->state = WS_IO;
44933db86aabSstevel 	}
44943db86aabSstevel 	if (winp->pcw_status & PCW_ENABLED)
44953db86aabSstevel 		window->state |= WS_ENABLED;
44963db86aabSstevel 
44973db86aabSstevel 	if (winp->pcw_status & PCS_CARD_16BIT)
44983db86aabSstevel 		window->state |= WS_16BIT;
44993db86aabSstevel #if defined(PCIC_DEBUG)
45003db86aabSstevel 	if (pcic_debug)
45013db86aabSstevel 		cmn_err(CE_CONT, "\tsize=%d, speed=%d, base=%p, state=%x\n",
450219397407SSherry Moore 		    window->size, (unsigned)window->speed,
450319397407SSherry Moore 		    (void *)window->handle, window->state);
45043db86aabSstevel #endif
45053db86aabSstevel 
45063db86aabSstevel 	return (SUCCESS);
45073db86aabSstevel }
45083db86aabSstevel 
45093db86aabSstevel /*
45103db86aabSstevel  * pcic_ll_reset
45113db86aabSstevel  *	low level reset
45123db86aabSstevel  *	separated out so it can be called when already locked
45133db86aabSstevel  *
45143db86aabSstevel  *	There are two variables that control the RESET timing:
45153db86aabSstevel  *		pcic_prereset_time - time in mS before asserting RESET
45163db86aabSstevel  *		pcic_reset_time - time in mS to assert RESET
45173db86aabSstevel  *
45183db86aabSstevel  */
45193db86aabSstevel int pcic_prereset_time = 1;
45203db86aabSstevel int pcic_reset_time = 10;
45213db86aabSstevel int pcic_postreset_time = 20;
45223db86aabSstevel int pcic_vpp_is_vcc_during_reset = 0;
45233db86aabSstevel 
45243db86aabSstevel static int
pcic_ll_reset(pcicdev_t * pcic,int socket)45253db86aabSstevel pcic_ll_reset(pcicdev_t *pcic, int socket)
45263db86aabSstevel {
45273db86aabSstevel 	int windowbits, iobits;
45283db86aabSstevel 	uint32_t pwr;
45293db86aabSstevel 
45303db86aabSstevel 	/* save windows that were on */
45313db86aabSstevel 	windowbits = pcic_getb(pcic, socket, PCIC_MAPPING_ENABLE);
45323db86aabSstevel 	if (pcic_reset_time == 0)
453319397407SSherry Moore 		return (windowbits);
45343db86aabSstevel 	/* turn all windows off */
45353db86aabSstevel 	pcic_putb(pcic, socket, PCIC_MAPPING_ENABLE, 0);
45363db86aabSstevel 
45373db86aabSstevel #if defined(PCIC_DEBUG)
45383db86aabSstevel 	pcic_err(pcic->dip, 6,
453919397407SSherry Moore 	    "pcic_ll_reset(socket %d) powerlevel=%x cbctl 0x%x cbps 0x%x\n",
454019397407SSherry Moore 	    socket, pcic_getb(pcic, socket, PCIC_POWER_CONTROL),
454119397407SSherry Moore 	    pcic_getcb(pcic, CB_CONTROL),
454219397407SSherry Moore 	    pcic_getcb(pcic, CB_PRESENT_STATE));
45433db86aabSstevel #endif
45443db86aabSstevel 
45453db86aabSstevel 	if (pcic_vpp_is_vcc_during_reset) {
45463db86aabSstevel 
45473db86aabSstevel 	/*
45483db86aabSstevel 	 * Set VPP to VCC for the duration of the reset - for aironet
45493db86aabSstevel 	 * card.
45503db86aabSstevel 	 */
455119397407SSherry Moore 		if (pcic->pc_flags & PCF_CBPWRCTL) {
45523db86aabSstevel 		pwr = pcic_getcb(pcic, CB_CONTROL);
45533db86aabSstevel 		pcic_putcb(pcic, CB_CONTROL, (pwr&~CB_C_VPPMASK)|CB_C_VPPVCC);
45543db86aabSstevel 		(void) pcic_getcb(pcic, CB_CONTROL);
455519397407SSherry Moore 		} else {
45563db86aabSstevel 		pwr = pcic_getb(pcic, socket, PCIC_POWER_CONTROL);
45573db86aabSstevel 		pcic_putb(pcic, socket, PCIC_POWER_CONTROL,
45583db86aabSstevel 		    pwr | 1);
45593db86aabSstevel 		(void) pcic_getb(pcic, socket, PCIC_POWER_CONTROL);
456019397407SSherry Moore 		}
45613db86aabSstevel 	}
45623db86aabSstevel 
45633db86aabSstevel 	if (pcic_prereset_time > 0) {
45643db86aabSstevel 		pcic_err(pcic->dip, 8, "pcic_ll_reset pre_wait %d mS\n",
45653db86aabSstevel 		    pcic_prereset_time);
45663db86aabSstevel 		pcic_mswait(pcic, socket, pcic_prereset_time);
45673db86aabSstevel 	}
45683db86aabSstevel 
45693db86aabSstevel 	/* turn interrupts off and start a reset */
45703db86aabSstevel 	pcic_err(pcic->dip, 8,
457119397407SSherry Moore 	    "pcic_ll_reset turn interrupts off and start a reset\n");
45723db86aabSstevel 	iobits = pcic_getb(pcic, socket, PCIC_INTERRUPT);
45733db86aabSstevel 	iobits &= ~(PCIC_INTR_MASK | PCIC_RESET);
45743db86aabSstevel 	pcic_putb(pcic, socket, PCIC_INTERRUPT, iobits);
45753db86aabSstevel 	(void) pcic_getb(pcic, socket, PCIC_INTERRUPT);
45763db86aabSstevel 
45773db86aabSstevel 	switch (pcic->pc_type) {
457819397407SSherry Moore 		case PCIC_INTEL_i82092:
45793db86aabSstevel 		pcic_82092_smiirq_ctl(pcic, socket, PCIC_82092_CTL_IRQ,
458019397407SSherry Moore 		    PCIC_82092_INT_DISABLE);
45813db86aabSstevel 		break;
458219397407SSherry Moore 		default:
45833db86aabSstevel 		break;
45843db86aabSstevel 	} /* switch */
45853db86aabSstevel 
45863db86aabSstevel 	pcic->pc_sockets[socket].pcs_state = 0;
45873db86aabSstevel 
45883db86aabSstevel 	if (pcic_reset_time > 0) {
45893db86aabSstevel 		pcic_err(pcic->dip, 8, "pcic_ll_reset reset_wait %d mS\n",
45903db86aabSstevel 		    pcic_reset_time);
45913db86aabSstevel 		pcic_mswait(pcic, socket, pcic_reset_time);
45923db86aabSstevel 	}
45933db86aabSstevel 
45943db86aabSstevel 	pcic_err(pcic->dip, 8, "pcic_ll_reset take it out of reset now\n");
45953db86aabSstevel 
45963db86aabSstevel 	/* take it out of RESET now */
45973db86aabSstevel 	pcic_putb(pcic, socket, PCIC_INTERRUPT, PCIC_RESET | iobits);
45983db86aabSstevel 	(void) pcic_getb(pcic, socket, PCIC_INTERRUPT);
45993db86aabSstevel 
46003db86aabSstevel 	/*
46013db86aabSstevel 	 * can't access the card for 20ms, but we really don't
46023db86aabSstevel 	 * want to sit around that long. The pcic is still usable.
46033db86aabSstevel 	 * memory accesses must wait for RDY to come up.
46043db86aabSstevel 	 */
46053db86aabSstevel 	if (pcic_postreset_time > 0) {
46063db86aabSstevel 		pcic_err(pcic->dip, 8, "pcic_ll_reset post_wait %d mS\n",
46073db86aabSstevel 		    pcic_postreset_time);
46083db86aabSstevel 		pcic_mswait(pcic, socket, pcic_postreset_time);
46093db86aabSstevel 	}
46103db86aabSstevel 
46113db86aabSstevel 	if (pcic_vpp_is_vcc_during_reset > 1) {
46123db86aabSstevel 
46133db86aabSstevel 	/*
46143db86aabSstevel 	 * Return VPP power to whatever it was before.
46153db86aabSstevel 	 */
461619397407SSherry Moore 		if (pcic->pc_flags & PCF_CBPWRCTL) {
46173db86aabSstevel 		pcic_putcb(pcic, CB_CONTROL, pwr);
46183db86aabSstevel 		(void) pcic_getcb(pcic, CB_CONTROL);
461919397407SSherry Moore 		} else {
46203db86aabSstevel 		pcic_putb(pcic, socket, PCIC_POWER_CONTROL, pwr);
46213db86aabSstevel 		(void) pcic_getb(pcic, socket, PCIC_POWER_CONTROL);
462219397407SSherry Moore 		}
46233db86aabSstevel 	}
46243db86aabSstevel 
46253db86aabSstevel 	pcic_err(pcic->dip, 7, "pcic_ll_reset returning 0x%x\n", windowbits);
46263db86aabSstevel 
46273db86aabSstevel 	return (windowbits);
46283db86aabSstevel }
46293db86aabSstevel 
46303db86aabSstevel /*
46313db86aabSstevel  * pcic_reset_socket()
46323db86aabSstevel  *	SocketServices ResetSocket function
46333db86aabSstevel  *	puts the PC Card in the socket into the RESET state
46343db86aabSstevel  *	and then takes it out after the the cycle time
46353db86aabSstevel  *	The socket is back to initial state when done
46363db86aabSstevel  */
46373db86aabSstevel static int
pcic_reset_socket(dev_info_t * dip,int socket,int mode)46383db86aabSstevel pcic_reset_socket(dev_info_t *dip, int socket, int mode)
46393db86aabSstevel {
46403db86aabSstevel 	anp_t *anp = ddi_get_driver_private(dip);
46413db86aabSstevel 	pcicdev_t *pcic = anp->an_private;
46423db86aabSstevel 	int value;
46433db86aabSstevel 	int i, mint;
46443db86aabSstevel 	pcic_socket_t *sockp;
46453db86aabSstevel 
46463db86aabSstevel #if defined(PCIC_DEBUG)
46473db86aabSstevel 	if (pcic_debug >= 8)
46483db86aabSstevel 		cmn_err(CE_CONT, "pcic_reset_socket(%p, %d, %d/%s)\n",
46493db86aabSstevel 		    (void *)dip, socket, mode,
465019397407SSherry Moore 		    mode == RESET_MODE_FULL ? "full" : "partial");
46513db86aabSstevel #endif
46523db86aabSstevel 
46533db86aabSstevel 	mutex_enter(&pcic->pc_lock); /* protect the registers */
46543db86aabSstevel 
46553db86aabSstevel 	/* Turn off management interupts. */
46563db86aabSstevel 	mint = pcic_getb(pcic, socket, PCIC_MANAGEMENT_INT);
46573db86aabSstevel 	pcic_putb(pcic, socket, PCIC_MANAGEMENT_INT, mint & ~PCIC_CHANGE_MASK);
46583db86aabSstevel 
46593db86aabSstevel 	sockp = &pcic->pc_sockets[socket];
46603db86aabSstevel 
46613db86aabSstevel 	value = pcic_ll_reset(pcic, socket);
46623db86aabSstevel 	if (mode == RESET_MODE_FULL) {
46633db86aabSstevel 		/* disable and unmap all mapped windows */
46643db86aabSstevel 		for (i = 0; i < PCIC_NUMWINSOCK; i++) {
46653db86aabSstevel 			if (i < PCIC_IOWINDOWS) {
46663db86aabSstevel 				if (sockp->pcs_windows[i].io.pcw_status &
46673db86aabSstevel 				    PCW_MAPPED) {
46683db86aabSstevel 					pcs_iowin_t *io;
46693db86aabSstevel 					io = &sockp->pcs_windows[i].io;
46703db86aabSstevel 					io->pcw_status &= ~PCW_ENABLED;
46713db86aabSstevel 				}
46723db86aabSstevel 			} else {
46733db86aabSstevel 				if (sockp->pcs_windows[i].mem.pcw_status &
46743db86aabSstevel 				    PCW_MAPPED) {
46753db86aabSstevel 					pcs_memwin_t *mem;
46763db86aabSstevel 					mem = &sockp->pcs_windows[i].mem;
46773db86aabSstevel 					mem->pcw_status &= ~PCW_ENABLED;
46783db86aabSstevel 				}
46793db86aabSstevel 			}
46803db86aabSstevel 		}
46813db86aabSstevel 	} else {
46823db86aabSstevel 				/* turn windows back on */
46833db86aabSstevel 		pcic_putb(pcic, socket, PCIC_MAPPING_ENABLE, value);
46843db86aabSstevel 		/* wait the rest of the time here */
46853db86aabSstevel 		pcic_mswait(pcic, socket, 10);
46863db86aabSstevel 	}
46873db86aabSstevel 	pcic_putb(pcic, socket, PCIC_MANAGEMENT_INT, mint);
46883db86aabSstevel 	mutex_exit(&pcic->pc_lock);
46893db86aabSstevel 	return (SUCCESS);
46903db86aabSstevel }
46913db86aabSstevel 
46923db86aabSstevel /*
46933db86aabSstevel  * pcic_set_interrupt()
46943db86aabSstevel  *	SocketServices SetInterrupt function
46953db86aabSstevel  */
46963db86aabSstevel static int
pcic_set_interrupt(dev_info_t * dip,set_irq_handler_t * handler)46973db86aabSstevel pcic_set_interrupt(dev_info_t *dip, set_irq_handler_t *handler)
46983db86aabSstevel {
46993db86aabSstevel 	anp_t *anp = ddi_get_driver_private(dip);
47003db86aabSstevel 	pcicdev_t *pcic = anp->an_private;
47013db86aabSstevel 	int value = DDI_SUCCESS;
47023db86aabSstevel 	inthandler_t *intr;
47033db86aabSstevel 
47043db86aabSstevel #if defined(PCIC_DEBUG)
47053db86aabSstevel 	if (pcic_debug) {
47063db86aabSstevel 		cmn_err(CE_CONT,
470719397407SSherry Moore 		    "pcic_set_interrupt: entered pc_intr_mode=0x%x\n",
470819397407SSherry Moore 		    pcic->pc_intr_mode);
47093db86aabSstevel 		cmn_err(CE_CONT,
471019397407SSherry Moore 		    "\t irq_top=%p handler=%p handler_id=%x\n",
471119397407SSherry Moore 		    (void *)pcic->irq_top, (void *)handler->handler,
471219397407SSherry Moore 		    handler->handler_id);
47133db86aabSstevel 	}
47143db86aabSstevel #endif
47153db86aabSstevel 
47163db86aabSstevel 	/*
47173db86aabSstevel 	 * If we're on a PCI bus, we route all IO IRQs through a single
47183db86aabSstevel 	 *	PCI interrupt (typically INT A#) so we don't have to do
47193db86aabSstevel 	 *	much other than add the caller to general interrupt handler
47203db86aabSstevel 	 *	and set some state.
47213db86aabSstevel 	 */
47223db86aabSstevel 
47233db86aabSstevel 	intr = kmem_zalloc(sizeof (inthandler_t), KM_NOSLEEP);
47243db86aabSstevel 	if (intr == NULL)
47253db86aabSstevel 		return (NO_RESOURCE);
47263db86aabSstevel 
47273db86aabSstevel 	switch (pcic->pc_intr_mode) {
47283db86aabSstevel 	case PCIC_INTR_MODE_PCI_1:
47293db86aabSstevel 		/*
47303db86aabSstevel 		 * We only allow above-lock-level IO IRQ handlers
47313db86aabSstevel 		 *	in the PCI bus case.
47323db86aabSstevel 		 */
47333db86aabSstevel 
47343db86aabSstevel 		mutex_enter(&pcic->intr_lock);
47353db86aabSstevel 
47363db86aabSstevel 		if (pcic->irq_top == NULL) {
473719397407SSherry Moore 			pcic->irq_top = intr;
473819397407SSherry Moore 			pcic->irq_current = pcic->irq_top;
47393db86aabSstevel 		} else {
474019397407SSherry Moore 			while (pcic->irq_current->next != NULL)
474119397407SSherry Moore 			pcic->irq_current = pcic->irq_current->next;
474219397407SSherry Moore 			pcic->irq_current->next = intr;
47433db86aabSstevel 			pcic->irq_current = pcic->irq_current->next;
47443db86aabSstevel 		}
47453db86aabSstevel 
47463db86aabSstevel 		pcic->irq_current->intr =
47477a2e057dSToomas Soome 		    (ddi_intr_handler_t *)(uintptr_t)handler->handler;
47483db86aabSstevel 		pcic->irq_current->handler_id = handler->handler_id;
47493db86aabSstevel 		pcic->irq_current->arg1 = handler->arg1;
47503db86aabSstevel 		pcic->irq_current->arg2 = handler->arg2;
47513db86aabSstevel 		pcic->irq_current->socket = handler->socket;
47523db86aabSstevel 
47533db86aabSstevel 		mutex_exit(&pcic->intr_lock);
47543db86aabSstevel 
47553db86aabSstevel 		handler->iblk_cookie = &pcic->pc_pri;
47563db86aabSstevel 		handler->idev_cookie = &pcic->pc_dcookie;
47573db86aabSstevel 		break;
47583db86aabSstevel 
47593db86aabSstevel 	default:
47607a2e057dSToomas Soome 		intr->intr = (ddi_intr_handler_t *)(uintptr_t)handler->handler;
47613db86aabSstevel 		intr->handler_id = handler->handler_id;
47623db86aabSstevel 		intr->arg1 = handler->arg1;
47633db86aabSstevel 		intr->arg2 = handler->arg2;
47643db86aabSstevel 		intr->socket = handler->socket;
47653db86aabSstevel 		intr->irq = handler->irq;
47663db86aabSstevel 
47673db86aabSstevel 		/*
47683db86aabSstevel 		 * need to revisit this to see if interrupts can be
47693db86aabSstevel 		 * shared someday. Note that IRQ is set in the common
47703db86aabSstevel 		 * code.
47713db86aabSstevel 		 */
47723db86aabSstevel 		mutex_enter(&pcic->pc_lock);
47733db86aabSstevel 		if (pcic->pc_handlers == NULL) {
47743db86aabSstevel 			pcic->pc_handlers = intr;
47753db86aabSstevel 			intr->next = intr->prev = intr;
47763db86aabSstevel 		} else {
47773db86aabSstevel 			insque(intr, pcic->pc_handlers);
47783db86aabSstevel 		}
47793db86aabSstevel 		mutex_exit(&pcic->pc_lock);
47803db86aabSstevel 
47813db86aabSstevel 		break;
47823db86aabSstevel 	}
47833db86aabSstevel 
47843db86aabSstevel 	/*
47853db86aabSstevel 	 * need to fill in cookies in event of multiple high priority
47863db86aabSstevel 	 * interrupt handlers on same IRQ
47873db86aabSstevel 	 */
47883db86aabSstevel 
47893db86aabSstevel #if defined(PCIC_DEBUG)
47903db86aabSstevel 	if (pcic_debug) {
47913db86aabSstevel 		cmn_err(CE_CONT,
479219397407SSherry Moore 		    "pcic_set_interrupt: exit irq_top=%p value=%d\n",
479319397407SSherry Moore 		    (void *)pcic->irq_top, value);
47943db86aabSstevel 	}
47953db86aabSstevel #endif
47963db86aabSstevel 
47973db86aabSstevel 	if (value == DDI_SUCCESS) {
47983db86aabSstevel 		return (SUCCESS);
47993db86aabSstevel 	} else {
48003db86aabSstevel 		return (BAD_IRQ);
48013db86aabSstevel 	}
48023db86aabSstevel }
48033db86aabSstevel 
48043db86aabSstevel /*
48053db86aabSstevel  * pcic_clear_interrupt()
48063db86aabSstevel  *	SocketServices ClearInterrupt function
48073db86aabSstevel  *
48083db86aabSstevel  *	Interrupts for PCIC are complicated by the fact that we must
48093db86aabSstevel  *	follow several different models for interrupts.
48103db86aabSstevel  *	ISA: there is an interrupt per adapter and per socket and
48113db86aabSstevel  *		they can't be shared.
48123db86aabSstevel  *	PCI: some adapters have one PCI interrupt available while others
48133db86aabSstevel  *		have up to 4.  Solaris may or may not allow us to use more
48143db86aabSstevel  *		than 1 so we essentially share them all at this point.
48153db86aabSstevel  *	Hybrid: PCI bridge but interrupts wired to host interrupt controller.
48163db86aabSstevel  *		This is like ISA but we have to fudge and create an intrspec
48173db86aabSstevel  *		that PCI's parent understands and bypass the PCI nexus.
48183db86aabSstevel  *	multifunction: this requires sharing the interrupts on a per-socket
48193db86aabSstevel  *		basis.
48203db86aabSstevel  */
48213db86aabSstevel static int
pcic_clear_interrupt(dev_info_t * dip,clear_irq_handler_t * handler)48223db86aabSstevel pcic_clear_interrupt(dev_info_t *dip, clear_irq_handler_t *handler)
48233db86aabSstevel {
48243db86aabSstevel 	anp_t *anp = ddi_get_driver_private(dip);
48253db86aabSstevel 	pcicdev_t *pcic = anp->an_private;
48263db86aabSstevel 	inthandler_t *intr, *prev, *current;
48273db86aabSstevel 	int i;
48283db86aabSstevel 
48293db86aabSstevel 	/*
48303db86aabSstevel 	 * If we're on a PCI bus, we route all IO IRQs through a single
48313db86aabSstevel 	 *	PCI interrupt (typically INT A#) so we don't have to do
48323db86aabSstevel 	 *	much other than remove the caller from the general
48333db86aabSstevel 	 *	interrupt handler callout list.
48343db86aabSstevel 	 */
48353db86aabSstevel 
48363db86aabSstevel #if defined(PCIC_DEBUG)
48373db86aabSstevel 	if (pcic_debug) {
48383db86aabSstevel 		cmn_err(CE_CONT,
483919397407SSherry Moore 		    "pcic_clear_interrupt: entered pc_intr_mode=0x%x\n",
484019397407SSherry Moore 		    pcic->pc_intr_mode);
48413db86aabSstevel 		cmn_err(CE_CONT,
484219397407SSherry Moore 		    "\t irq_top=%p handler=%p handler_id=%x\n",
484319397407SSherry Moore 		    (void *)pcic->irq_top, (void *)handler->handler,
484419397407SSherry Moore 		    handler->handler_id);
48453db86aabSstevel 	}
48463db86aabSstevel #endif
48473db86aabSstevel 
48483db86aabSstevel 	switch (pcic->pc_intr_mode) {
48493db86aabSstevel 	case PCIC_INTR_MODE_PCI_1:
48503db86aabSstevel 
48513db86aabSstevel 		mutex_enter(&pcic->intr_lock);
48523db86aabSstevel 		if (pcic->irq_top == NULL) {
48533db86aabSstevel 			mutex_exit(&pcic->intr_lock);
48543db86aabSstevel 			return (BAD_IRQ);
48553db86aabSstevel 		}
48563db86aabSstevel 
48573db86aabSstevel 		intr = NULL;
48583db86aabSstevel 		pcic->irq_current = pcic->irq_top;
48593db86aabSstevel 
48603db86aabSstevel 		while ((pcic->irq_current != NULL) &&
486119397407SSherry Moore 		    (pcic->irq_current->handler_id !=
486219397407SSherry Moore 		    handler->handler_id)) {
48633db86aabSstevel 			intr = pcic->irq_current;
48643db86aabSstevel 			pcic->irq_current = pcic->irq_current->next;
48653db86aabSstevel 		}
48663db86aabSstevel 
48673db86aabSstevel 		if (pcic->irq_current == NULL) {
48683db86aabSstevel 			mutex_exit(&pcic->intr_lock);
48693db86aabSstevel 			return (BAD_IRQ);
48703db86aabSstevel 		}
48713db86aabSstevel 
48723db86aabSstevel 		if (intr != NULL) {
48733db86aabSstevel 			intr->next = pcic->irq_current->next;
48743db86aabSstevel 		} else {
48753db86aabSstevel 			pcic->irq_top = pcic->irq_current->next;
48763db86aabSstevel 		}
48773db86aabSstevel 
48783db86aabSstevel 		current = pcic->irq_current;
48793db86aabSstevel 		pcic->irq_current = pcic->irq_top;
48803db86aabSstevel 		mutex_exit(&pcic->intr_lock);
48813db86aabSstevel 		kmem_free(current, sizeof (inthandler_t));
48823db86aabSstevel 
48833db86aabSstevel 		break;
48843db86aabSstevel 
48853db86aabSstevel 	default:
48863db86aabSstevel 
48873db86aabSstevel 		mutex_enter(&pcic->pc_lock);
48883db86aabSstevel 		intr = pcic_handlers;
48893db86aabSstevel 		prev = (inthandler_t *)&pcic_handlers;
48903db86aabSstevel 
48913db86aabSstevel 		while (intr != NULL) {
489219397407SSherry Moore 			if (intr->handler_id == handler->handler_id) {
48933db86aabSstevel 			i = intr->irq & PCIC_INTR_MASK;
48943db86aabSstevel 			if (--pcic_irq_map[i].count == 0) {
48953db86aabSstevel 				/* multi-handler form */
48963db86aabSstevel 				(void) ddi_intr_disable(pcic->pc_intr_htblp[i]);
48973db86aabSstevel 				(void) ddi_intr_remove_handler(
48983db86aabSstevel 				    pcic->pc_intr_htblp[i]);
48993db86aabSstevel 				(void) ddi_intr_free(pcic->pc_intr_htblp[i]);
49003db86aabSstevel 				(void) pcmcia_return_intr(pcic->dip, i);
49013db86aabSstevel #if defined(PCIC_DEBUG)
49023db86aabSstevel 				if (pcic_debug) {
49033db86aabSstevel 					cmn_err(CE_CONT,
490419397407SSherry Moore 					    "removing interrupt %d at %s "
490519397407SSherry Moore 					    "priority\n", i, "high");
49063db86aabSstevel 					cmn_err(CE_CONT,
490719397407SSherry Moore 					    "ddi_remove_intr(%p, %x, %p)\n",
490819397407SSherry Moore 					    (void *)dip,
490919397407SSherry Moore 					    0,
491019397407SSherry Moore 					    (void *)intr->iblk_cookie);
49113db86aabSstevel 				}
49123db86aabSstevel #endif
49133db86aabSstevel 			}
49143db86aabSstevel 			prev->next = intr->next;
49153db86aabSstevel 			kmem_free(intr, sizeof (inthandler_t));
49163db86aabSstevel 			intr = prev->next;
491719397407SSherry Moore 			} else {
49183db86aabSstevel 			prev = intr;
49193db86aabSstevel 			intr = intr->next;
492019397407SSherry Moore 			} /* if (handler_id) */
49213db86aabSstevel 		} /* while */
49223db86aabSstevel 
49233db86aabSstevel 		mutex_exit(&pcic->pc_lock);
49243db86aabSstevel 	}
49253db86aabSstevel 
49263db86aabSstevel #if defined(PCIC_DEBUG)
49273db86aabSstevel 	if (pcic_debug) {
49283db86aabSstevel 		cmn_err(CE_CONT,
492919397407SSherry Moore 		    "pcic_clear_interrupt: exit irq_top=%p\n",
493019397407SSherry Moore 		    (void *)pcic->irq_top);
49313db86aabSstevel 	}
49323db86aabSstevel #endif
49333db86aabSstevel 
49343db86aabSstevel 
49353db86aabSstevel 	return (SUCCESS);
49363db86aabSstevel }
49373db86aabSstevel 
49383db86aabSstevel struct intel_regs {
49393db86aabSstevel 	char *name;
49403db86aabSstevel 	int   off;
49413db86aabSstevel 	char *fmt;
49423db86aabSstevel } iregs[] = {
49433db86aabSstevel 	{"ident     ", 0},
49443db86aabSstevel 	{"if-status ", 1, "\020\1BVD1\2BVD2\3CD1\4CD2\5WP\6RDY\7PWR\10~GPI"},
49453db86aabSstevel 	{"power     ", 2, "\020\1Vpp1c0\2Vpp1c1\3Vpp2c0\4Vpp2c1\5PE\6AUTO"
49463db86aabSstevel 		"\7DRD\10OE"},
49473db86aabSstevel 	{"cardstatus", 4, "\020\1BD\2BW\3RC\4CD\5GPI\6R1\7R2\010R3"},
49483db86aabSstevel 	{"enable    ", 6, "\020\1MW0\2MW1\3MW2\4MW3\5MW4\6MEM16\7IO0\10IO1"},
49493db86aabSstevel 	{"cd-gcr    ", 0x16, "\020\1MDI16\2CRE\3GPIE\4GPIT\5CDR\6S/W"},
49503db86aabSstevel 	{"GCR       ", 0x1e, "\020\1PD\2LEVEL\3WCSC\4PLS14"},
49513db86aabSstevel 	{"int-gcr   ", 3, "\020\5INTR\6IO\7~RST\10RI"},
49523db86aabSstevel 	{"management", 5, "\020\1BDE\2BWE\3RE\4CDE"},
49533db86aabSstevel 	{"volt-sense", 0x1f, "\020\1A_VS1\2A_VS2\3B_VS1\4B_VS2"},
49543db86aabSstevel 	{"volt-sel  ", 0x2f, "\020\5EXTCONF\6BUSSELECT\7MIXEDV\10ISAV"},
49553db86aabSstevel 	{"VG ext A  ", 0x3c, "\20\3IVS\4CABLE\5CSTEP\6TEST\7RIO"},
49563db86aabSstevel 	{"io-ctrl   ", 7, "\020\1DS0\2IOCS0\3ZWS0\4WS0\5DS1\6IOS1\7ZWS1\10WS1"},
49573db86aabSstevel 	{"io0-slow  ", 8},
49583db86aabSstevel 	{"io0-shi   ", 9},
49593db86aabSstevel 	{"io0-elow  ", 0xa},
49603db86aabSstevel 	{"io0-ehi   ", 0xb},
49613db86aabSstevel 	{"io1-slow  ", 0xc},
49623db86aabSstevel 	{"io1-shi   ", 0xd},
49633db86aabSstevel 	{"io1-elow  ", 0xe},
49643db86aabSstevel 	{"io1-ehi   ", 0xf},
49653db86aabSstevel 	{"mem0-slow ", 0x10},
49663db86aabSstevel 	{"mem0-shi  ", 0x11, "\020\7ZW\10DS"},
49673db86aabSstevel 	{"mem0-elow ", 0x12},
49683db86aabSstevel 	{"mem0-ehi  ", 0x13, "\020\7WS0\10WS1"},
49693db86aabSstevel 	{"card0-low ", 0x14},
49703db86aabSstevel 	{"card0-hi  ", 0x15, "\020\7AM\10WP"},
49713db86aabSstevel 	{"mem1-slow ", 0x18},
49723db86aabSstevel 	{"mem1-shi  ", 0x19, "\020\7ZW\10DS"},
49733db86aabSstevel 	{"mem1-elow ", 0x1a},
49743db86aabSstevel 	{"mem1-ehi  ", 0x1b, "\020\7WS0\10WS1"},
49753db86aabSstevel 	{"card1-low ", 0x1c},
49763db86aabSstevel 	{"card1-hi  ", 0x1d, "\020\7AM\10WP"},
49773db86aabSstevel 	{"mem2-slow ", 0x20},
49783db86aabSstevel 	{"mem2-shi  ", 0x21, "\020\7ZW\10DS"},
49793db86aabSstevel 	{"mem2-elow ", 0x22},
49803db86aabSstevel 	{"mem2-ehi  ", 0x23, "\020\7WS0\10WS1"},
49813db86aabSstevel 	{"card2-low ", 0x24},
49823db86aabSstevel 	{"card2-hi  ", 0x25, "\020\7AM\10WP"},
49833db86aabSstevel 	{"mem3-slow ", 0x28},
49843db86aabSstevel 	{"mem3-shi  ", 0x29, "\020\7ZW\10DS"},
49853db86aabSstevel 	{"mem3-elow ", 0x2a},
49863db86aabSstevel 	{"mem3-ehi  ", 0x2b, "\020\7WS0\10WS1"},
49873db86aabSstevel 	{"card3-low ", 0x2c},
49883db86aabSstevel 	{"card3-hi  ", 0x2d, "\020\7AM\10WP"},
49893db86aabSstevel 
49903db86aabSstevel 	{"mem4-slow ", 0x30},
49913db86aabSstevel 	{"mem4-shi  ", 0x31, "\020\7ZW\10DS"},
49923db86aabSstevel 	{"mem4-elow ", 0x32},
49933db86aabSstevel 	{"mem4-ehi  ", 0x33, "\020\7WS0\10WS1"},
49943db86aabSstevel 	{"card4-low ", 0x34},
49953db86aabSstevel 	{"card4-hi  ", 0x35, "\020\7AM\10WP"},
49963db86aabSstevel 	{"mpage0    ", 0x40},
49973db86aabSstevel 	{"mpage1    ", 0x41},
49983db86aabSstevel 	{"mpage2    ", 0x42},
49993db86aabSstevel 	{"mpage3    ", 0x43},
50003db86aabSstevel 	{"mpage4    ", 0x44},
50013db86aabSstevel 	{NULL},
50023db86aabSstevel };
50033db86aabSstevel 
50043db86aabSstevel static struct intel_regs cregs[] = {
50053db86aabSstevel 	{"misc-ctl1 ", 0x16, "\20\2VCC3\3PMI\4PSI\5SPKR\10INPACK"},
50063db86aabSstevel 	{"fifo      ", 0x17, "\20\6DIOP\7DMEMP\10EMPTY"},
50073db86aabSstevel 	{"misc-ctl2 ", 0x1e, "\20\1XCLK\2LOW\3SUSP\4CORE5V\5TCD\10RIOUT"},
50083db86aabSstevel 	{"chip-info ", 0x1f, "\20\6DUAL"},
50093db86aabSstevel 	{"IO-offlow0", 0x36},
50103db86aabSstevel 	{"IO-offhi0 ", 0x37},
50113db86aabSstevel 	{"IO-offlow1", 0x38},
50123db86aabSstevel 	{"IO-offhi1 ", 0x39},
50133db86aabSstevel 	NULL,
50143db86aabSstevel };
50153db86aabSstevel 
50163db86aabSstevel static struct intel_regs cxregs[] = {
50173db86aabSstevel 	{"ext-ctl-1 ", 0x03,
50183db86aabSstevel 		"\20\1VCCLCK\2AUTOCLR\3LED\4INVIRQC\5INVIRQM\6PUC"},
50193db86aabSstevel 	{"misc-ctl3 ", 0x25, "\20\5HWSUSP"},
50203db86aabSstevel 	{"mem0-up   ", 0x05},
50213db86aabSstevel 	{"mem1-up   ", 0x06},
50223db86aabSstevel 	{"mem2-up   ", 0x07},
50233db86aabSstevel 	{"mem3-up   ", 0x08},
50243db86aabSstevel 	{"mem4-up   ", 0x09},
50253db86aabSstevel 	{NULL}
50263db86aabSstevel };
50273db86aabSstevel 
50283db86aabSstevel void
xxdmp_cl_regs(pcicdev_t * pcic,int socket,uint32_t len)50293db86aabSstevel xxdmp_cl_regs(pcicdev_t *pcic, int socket, uint32_t len)
50303db86aabSstevel {
50313db86aabSstevel 	int i, value, j;
50323db86aabSstevel 	char buff[256];
50333db86aabSstevel 	char *fmt;
50343db86aabSstevel 
50353db86aabSstevel 	cmn_err(CE_CONT, "--------- Cirrus Logic Registers --------\n");
50363db86aabSstevel 	for (buff[0] = '\0', i = 0; cregs[i].name != NULL && len-- != 0; i++) {
50373db86aabSstevel 		int sval;
50383db86aabSstevel 		if (cregs[i].off == PCIC_MISC_CTL_2)
50393db86aabSstevel 			sval = 0;
50403db86aabSstevel 		else
50413db86aabSstevel 			sval = socket;
50423db86aabSstevel 		value = pcic_getb(pcic, sval, cregs[i].off);
50433db86aabSstevel 		if (i & 1) {
50443db86aabSstevel 			if (cregs[i].fmt)
50453db86aabSstevel 				fmt = "%s\t%s\t%b\n";
50463db86aabSstevel 			else
50473db86aabSstevel 				fmt = "%s\t%s\t%x\n";
50483db86aabSstevel 			cmn_err(CE_CONT, fmt, buff,
504919397407SSherry Moore 			    cregs[i].name, value, cregs[i].fmt);
50503db86aabSstevel 			buff[0] = '\0';
50513db86aabSstevel 		} else {
50523db86aabSstevel 			if (cregs[i].fmt)
50533db86aabSstevel 				fmt = "\t%s\t%b";
50543db86aabSstevel 			else
50553db86aabSstevel 				fmt = "\t%s\t%x";
50563db86aabSstevel 			(void) sprintf(buff, fmt,
505719397407SSherry Moore 			    cregs[i].name, value, cregs[i].fmt);
50583db86aabSstevel 			for (j = strlen(buff); j < 40; j++)
50593db86aabSstevel 				buff[j] = ' ';
50603db86aabSstevel 			buff[40] = '\0';
50613db86aabSstevel 		}
50623db86aabSstevel 	}
50633db86aabSstevel 	cmn_err(CE_CONT, "%s\n", buff);
50643db86aabSstevel 
50653db86aabSstevel 	i = pcic_getb(pcic, socket, PCIC_TIME_SETUP_0);
50663db86aabSstevel 	j = pcic_getb(pcic, socket, PCIC_TIME_SETUP_1);
50673db86aabSstevel 	cmn_err(CE_CONT, "\tsetup-tim0\t%x\tsetup-tim1\t%x\n", i, j);
50683db86aabSstevel 
50693db86aabSstevel 	i = pcic_getb(pcic, socket, PCIC_TIME_COMMAND_0);
50703db86aabSstevel 	j = pcic_getb(pcic, socket, PCIC_TIME_COMMAND_1);
50713db86aabSstevel 	cmn_err(CE_CONT, "\tcmd-tim0  \t%x\tcmd-tim1  \t%x\n", i, j);
50723db86aabSstevel 
50733db86aabSstevel 	i = pcic_getb(pcic, socket, PCIC_TIME_RECOVER_0);
50743db86aabSstevel 	j = pcic_getb(pcic, socket, PCIC_TIME_RECOVER_1);
50753db86aabSstevel 	cmn_err(CE_CONT, "\trcvr-tim0 \t%x\trcvr-tim1 \t%x\n", i, j);
50763db86aabSstevel 
50773db86aabSstevel 	cmn_err(CE_CONT, "--------- Extended Registers  --------\n");
50783db86aabSstevel 
50793db86aabSstevel 	for (buff[0] = '\0', i = 0; cxregs[i].name != NULL && len-- != 0; i++) {
50803db86aabSstevel 		value = clext_reg_read(pcic, socket, cxregs[i].off);
50813db86aabSstevel 		if (i & 1) {
50823db86aabSstevel 			if (cxregs[i].fmt)
50833db86aabSstevel 				fmt = "%s\t%s\t%b\n";
50843db86aabSstevel 			else
50853db86aabSstevel 				fmt = "%s\t%s\t%x\n";
50863db86aabSstevel 			cmn_err(CE_CONT, fmt, buff,
508719397407SSherry Moore 			    cxregs[i].name, value, cxregs[i].fmt);
50883db86aabSstevel 			buff[0] = '\0';
50893db86aabSstevel 		} else {
50903db86aabSstevel 			if (cxregs[i].fmt)
50913db86aabSstevel 				fmt = "\t%s\t%b";
50923db86aabSstevel 			else
50933db86aabSstevel 				fmt = "\t%s\t%x";
50943db86aabSstevel 			(void) sprintf(buff, fmt,
509519397407SSherry Moore 			    cxregs[i].name, value, cxregs[i].fmt);
50963db86aabSstevel 			for (j = strlen(buff); j < 40; j++)
50973db86aabSstevel 				buff[j] = ' ';
50983db86aabSstevel 			buff[40] = '\0';
50993db86aabSstevel 		}
51003db86aabSstevel 	}
51013db86aabSstevel }
51023db86aabSstevel 
51033db86aabSstevel #if defined(PCIC_DEBUG)
51043db86aabSstevel static void
xxdmp_all_regs(pcicdev_t * pcic,int socket,uint32_t len)51053db86aabSstevel xxdmp_all_regs(pcicdev_t *pcic, int socket, uint32_t len)
51063db86aabSstevel {
51073db86aabSstevel 	int i, value, j;
51083db86aabSstevel 	char buff[256];
51093db86aabSstevel 	char *fmt;
51103db86aabSstevel 
51113db86aabSstevel #if defined(PCIC_DEBUG)
51123db86aabSstevel 	if (pcic_debug < 2)
51133db86aabSstevel 		return;
51143db86aabSstevel #endif
51153db86aabSstevel 	cmn_err(CE_CONT,
511619397407SSherry Moore 	    "----------- PCIC Registers for socket %d---------\n",
511719397407SSherry Moore 	    socket);
51183db86aabSstevel 	cmn_err(CE_CONT,
511919397407SSherry Moore 	    "\tname       value	                name       value\n");
51203db86aabSstevel 
51213db86aabSstevel 	for (buff[0] = '\0', i = 0; iregs[i].name != NULL && len-- != 0; i++) {
51223db86aabSstevel 		value = pcic_getb(pcic, socket, iregs[i].off);
51233db86aabSstevel 		if (i & 1) {
51243db86aabSstevel 			if (iregs[i].fmt)
51253db86aabSstevel 				fmt = "%s\t%s\t%b\n";
51263db86aabSstevel 			else
51273db86aabSstevel 				fmt = "%s\t%s\t%x\n";
51283db86aabSstevel 			cmn_err(CE_CONT, fmt, buff,
512919397407SSherry Moore 			    iregs[i].name, value, iregs[i].fmt);
51303db86aabSstevel 			buff[0] = '\0';
51313db86aabSstevel 		} else {
51323db86aabSstevel 			if (iregs[i].fmt)
51333db86aabSstevel 				fmt = "\t%s\t%b";
51343db86aabSstevel 			else
51353db86aabSstevel 				fmt = "\t%s\t%x";
51363db86aabSstevel 			(void) sprintf(buff, fmt,
513719397407SSherry Moore 			    iregs[i].name, value, iregs[i].fmt);
51383db86aabSstevel 			for (j = strlen(buff); j < 40; j++)
51393db86aabSstevel 				buff[j] = ' ';
51403db86aabSstevel 			buff[40] = '\0';
51413db86aabSstevel 		}
51423db86aabSstevel 	}
51433db86aabSstevel 	switch (pcic->pc_type) {
51443db86aabSstevel 	case PCIC_CL_PD6710:
51453db86aabSstevel 	case PCIC_CL_PD6722:
51463db86aabSstevel 	case PCIC_CL_PD6729:
51473db86aabSstevel 	case PCIC_CL_PD6832:
51483db86aabSstevel 		(void) xxdmp_cl_regs(pcic, socket, 0xFFFF);
51493db86aabSstevel 		break;
51503db86aabSstevel 	}
51513db86aabSstevel 	cmn_err(CE_CONT, "%s\n", buff);
51523db86aabSstevel }
51533db86aabSstevel #endif
51543db86aabSstevel 
51553db86aabSstevel /*
51563db86aabSstevel  * pcic_mswait(ms)
51573db86aabSstevel  *	sleep ms milliseconds
51583db86aabSstevel  *	call drv_usecwait once for each ms
51593db86aabSstevel  */
51603db86aabSstevel static void
pcic_mswait(pcicdev_t * pcic,int socket,int ms)51613db86aabSstevel pcic_mswait(pcicdev_t *pcic, int socket, int ms)
51623db86aabSstevel {
51633db86aabSstevel 	if (ms) {
51643db86aabSstevel 		pcic->pc_sockets[socket].pcs_flags |= PCS_WAITING;
51653db86aabSstevel 		pcic_mutex_exit(&pcic->pc_lock);
51663db86aabSstevel 		delay(drv_usectohz(ms*1000));
51673db86aabSstevel 		pcic_mutex_enter(&pcic->pc_lock);
51683db86aabSstevel 		pcic->pc_sockets[socket].pcs_flags &= ~PCS_WAITING;
51693db86aabSstevel 	}
51703db86aabSstevel }
51713db86aabSstevel 
51723db86aabSstevel /*
51733db86aabSstevel  * pcic_check_ready(pcic, index, off)
51743db86aabSstevel  *      Wait for card to come ready
51753db86aabSstevel  *      We only wait if the card is NOT in RESET
51763db86aabSstevel  *      and power is on.
51773db86aabSstevel  */
51783db86aabSstevel static boolean_t
pcic_check_ready(pcicdev_t * pcic,int socket)51793db86aabSstevel pcic_check_ready(pcicdev_t *pcic, int socket)
51803db86aabSstevel {
51813db86aabSstevel 	int ifstate, intstate;
51823db86aabSstevel 
51833db86aabSstevel 	intstate = pcic_getb(pcic, socket, PCIC_INTERRUPT);
51843db86aabSstevel 	ifstate = pcic_getb(pcic, socket, PCIC_INTERFACE_STATUS);
51853db86aabSstevel 
51863db86aabSstevel 	if ((intstate & PCIC_RESET) &&
51873db86aabSstevel 	    ((ifstate & (PCIC_READY|PCIC_POWER_ON|PCIC_ISTAT_CD_MASK)) ==
51883db86aabSstevel 	    (PCIC_READY|PCIC_POWER_ON|PCIC_CD_PRESENT_OK)))
51893db86aabSstevel 		return (B_TRUE);
51903db86aabSstevel 
51913db86aabSstevel #ifdef  PCIC_DEBUG
51923db86aabSstevel 	pcic_err(NULL, 5, "pcic_check_read: Card not ready, intstate = 0x%x, "
51933db86aabSstevel 	    "ifstate = 0x%x\n", intstate, ifstate);
51943db86aabSstevel 	if (pcic_debug) {
51953db86aabSstevel 		pcic_debug += 4;
51963db86aabSstevel 		xxdmp_all_regs(pcic, socket, -1);
51973db86aabSstevel 		pcic_debug -= 4;
51983db86aabSstevel 	}
51993db86aabSstevel #endif
52003db86aabSstevel 	return (B_FALSE);
52013db86aabSstevel }
52023db86aabSstevel 
52033db86aabSstevel /*
52043db86aabSstevel  * Cirrus Logic extended register read/write routines
52053db86aabSstevel  */
52063db86aabSstevel static int
clext_reg_read(pcicdev_t * pcic,int sn,uchar_t ext_reg)52073db86aabSstevel clext_reg_read(pcicdev_t *pcic, int sn, uchar_t ext_reg)
52083db86aabSstevel {
52093db86aabSstevel 	int val;
52103db86aabSstevel 
52113db86aabSstevel 	switch (pcic->pc_io_type) {
52123db86aabSstevel 	case PCIC_IO_TYPE_YENTA:
52133db86aabSstevel 		val = ddi_get8(pcic->handle,
52143db86aabSstevel 		    pcic->ioaddr + CB_CLEXT_OFFSET + ext_reg);
52153db86aabSstevel 		break;
52163db86aabSstevel 	default:
52173db86aabSstevel 		pcic_putb(pcic, sn, PCIC_CL_EXINDEX, ext_reg);
52183db86aabSstevel 		val = pcic_getb(pcic, sn, PCIC_CL_EXINDEX + 1);
52193db86aabSstevel 		break;
52203db86aabSstevel 	}
52213db86aabSstevel 
52223db86aabSstevel 	return (val);
52233db86aabSstevel }
52243db86aabSstevel 
52253db86aabSstevel static void
clext_reg_write(pcicdev_t * pcic,int sn,uchar_t ext_reg,uchar_t value)52263db86aabSstevel clext_reg_write(pcicdev_t *pcic, int sn, uchar_t ext_reg, uchar_t value)
52273db86aabSstevel {
52283db86aabSstevel 	switch (pcic->pc_io_type) {
52293db86aabSstevel 	case PCIC_IO_TYPE_YENTA:
52303db86aabSstevel 		ddi_put8(pcic->handle,
52313db86aabSstevel 		    pcic->ioaddr + CB_CLEXT_OFFSET + ext_reg, value);
52323db86aabSstevel 		break;
52333db86aabSstevel 	default:
52343db86aabSstevel 		pcic_putb(pcic, sn, PCIC_CL_EXINDEX, ext_reg);
52353db86aabSstevel 		pcic_putb(pcic, sn, PCIC_CL_EXINDEX + 1, value);
52363db86aabSstevel 		break;
52373db86aabSstevel 	}
52383db86aabSstevel }
52393db86aabSstevel 
52403db86aabSstevel /*
52413db86aabSstevel  * Misc PCI functions
52423db86aabSstevel  */
52433db86aabSstevel static void
pcic_iomem_pci_ctl(ddi_acc_handle_t handle,uchar_t * cfgaddr,unsigned flags)52443db86aabSstevel pcic_iomem_pci_ctl(ddi_acc_handle_t handle, uchar_t *cfgaddr, unsigned flags)
52453db86aabSstevel {
52463db86aabSstevel 	unsigned cmd;
52473db86aabSstevel 
52483db86aabSstevel 	if (flags & (PCIC_ENABLE_IO | PCIC_ENABLE_MEM)) {
52493db86aabSstevel 		cmd = ddi_get16(handle, (ushort_t *)(cfgaddr + 4));
52503db86aabSstevel 		if ((cmd & (PCI_COMM_IO|PCI_COMM_MAE)) ==
52513db86aabSstevel 		    (PCI_COMM_IO|PCI_COMM_MAE))
52523db86aabSstevel 			return;
52533db86aabSstevel 
52543db86aabSstevel 		if (flags & PCIC_ENABLE_IO)
525519397407SSherry Moore 			cmd |= PCI_COMM_IO;
52563db86aabSstevel 
52573db86aabSstevel 		if (flags & PCIC_ENABLE_MEM)
525819397407SSherry Moore 			cmd |= PCI_COMM_MAE;
52593db86aabSstevel 
52603db86aabSstevel 		ddi_put16(handle, (ushort_t *)(cfgaddr + 4), cmd);
52613db86aabSstevel 	} /* if (PCIC_ENABLE_IO | PCIC_ENABLE_MEM) */
52623db86aabSstevel }
52633db86aabSstevel 
52643db86aabSstevel /*
52653db86aabSstevel  * pcic_find_pci_type - Find and return PCI-PCMCIA adapter type
52663db86aabSstevel  */
52673db86aabSstevel static int
pcic_find_pci_type(pcicdev_t * pcic)52683db86aabSstevel pcic_find_pci_type(pcicdev_t *pcic)
52693db86aabSstevel {
52703db86aabSstevel 	uint32_t vend, device;
52713db86aabSstevel 
52723db86aabSstevel 	vend = ddi_getprop(DDI_DEV_T_ANY, pcic->dip,
527319397407SSherry Moore 	    DDI_PROP_CANSLEEP|DDI_PROP_DONTPASS,
527419397407SSherry Moore 	    "vendor-id", -1);
52753db86aabSstevel 	device = ddi_getprop(DDI_DEV_T_ANY, pcic->dip,
527619397407SSherry Moore 	    DDI_PROP_CANSLEEP|DDI_PROP_DONTPASS,
527719397407SSherry Moore 	    "device-id", -1);
52783db86aabSstevel 
52793db86aabSstevel 	device = PCI_ID(vend, device);
52803db86aabSstevel 	pcic->pc_type = device;
52813db86aabSstevel 	pcic->pc_chipname = "PCI:unknown";
52823db86aabSstevel 
52833db86aabSstevel 	switch (device) {
52843db86aabSstevel 	case PCIC_INTEL_i82092:
52853db86aabSstevel 		pcic->pc_chipname = PCIC_TYPE_i82092;
52863db86aabSstevel 		break;
52873db86aabSstevel 	case PCIC_CL_PD6729:
52883db86aabSstevel 		pcic->pc_chipname = PCIC_TYPE_PD6729;
52893db86aabSstevel 		/*
52903db86aabSstevel 		 * Some 6730's incorrectly identify themselves
52913db86aabSstevel 		 *	as a 6729, so we need to do some more tests
52923db86aabSstevel 		 *	here to see if the device that's claiming
52933db86aabSstevel 		 *	to be a 6729 is really a 6730.
52943db86aabSstevel 		 */
52953db86aabSstevel 		if ((clext_reg_read(pcic, 0, PCIC_CLEXT_MISC_CTL_3) &
529619397407SSherry Moore 		    PCIC_CLEXT_MISC_CTL_3_REV_MASK) ==
529719397407SSherry Moore 		    0) {
52983db86aabSstevel 			pcic->pc_chipname = PCIC_TYPE_PD6730;
52993db86aabSstevel 			pcic->pc_type = PCIC_CL_PD6730;
53003db86aabSstevel 		}
53013db86aabSstevel 		break;
53023db86aabSstevel 	case PCIC_CL_PD6730:
53033db86aabSstevel 		pcic->pc_chipname = PCIC_TYPE_PD6730;
53043db86aabSstevel 		break;
53053db86aabSstevel 	case PCIC_CL_PD6832:
53063db86aabSstevel 		pcic->pc_chipname = PCIC_TYPE_PD6832;
53073db86aabSstevel 		break;
53083db86aabSstevel 	case PCIC_SMC_34C90:
53093db86aabSstevel 		pcic->pc_chipname = PCIC_TYPE_34C90;
53103db86aabSstevel 		break;
53113db86aabSstevel 	case PCIC_TOSHIBA_TOPIC95:
53123db86aabSstevel 		pcic->pc_chipname = PCIC_TYPE_TOPIC95;
53133db86aabSstevel 		break;
53143db86aabSstevel 	case PCIC_TOSHIBA_TOPIC100:
53153db86aabSstevel 		pcic->pc_chipname = PCIC_TYPE_TOPIC100;
53163db86aabSstevel 		break;
53173db86aabSstevel 	case PCIC_TI_PCI1031:
53183db86aabSstevel 		pcic->pc_chipname = PCIC_TYPE_PCI1031;
53193db86aabSstevel 		break;
53203db86aabSstevel 	case PCIC_TI_PCI1130:
53213db86aabSstevel 		pcic->pc_chipname = PCIC_TYPE_PCI1130;
53223db86aabSstevel 		break;
53233db86aabSstevel 	case PCIC_TI_PCI1131:
53243db86aabSstevel 		pcic->pc_chipname = PCIC_TYPE_PCI1131;
53253db86aabSstevel 		break;
53263db86aabSstevel 	case PCIC_TI_PCI1250:
53273db86aabSstevel 		pcic->pc_chipname = PCIC_TYPE_PCI1250;
53283db86aabSstevel 		break;
53293db86aabSstevel 	case PCIC_TI_PCI1225:
53303db86aabSstevel 		pcic->pc_chipname = PCIC_TYPE_PCI1225;
53313db86aabSstevel 		break;
53323db86aabSstevel 	case PCIC_TI_PCI1410:
53333db86aabSstevel 		pcic->pc_chipname = PCIC_TYPE_PCI1410;
53343db86aabSstevel 		break;
53353db86aabSstevel 	case PCIC_TI_PCI1510:
53363db86aabSstevel 		pcic->pc_chipname = PCIC_TYPE_PCI1510;
53373db86aabSstevel 		break;
53383db86aabSstevel 	case PCIC_TI_PCI1520:
53393db86aabSstevel 		pcic->pc_chipname = PCIC_TYPE_PCI1520;
53403db86aabSstevel 		break;
53413db86aabSstevel 	case PCIC_TI_PCI1221:
53423db86aabSstevel 		pcic->pc_chipname = PCIC_TYPE_PCI1221;
53433db86aabSstevel 		break;
53443db86aabSstevel 	case PCIC_TI_PCI1050:
53453db86aabSstevel 		pcic->pc_chipname = PCIC_TYPE_PCI1050;
53463db86aabSstevel 		break;
53473db86aabSstevel 	case PCIC_ENE_1410:
53483db86aabSstevel 		pcic->pc_chipname = PCIC_TYPE_1410;
53493db86aabSstevel 		break;
53503db86aabSstevel 	case PCIC_O2_OZ6912:
53513db86aabSstevel 		pcic->pc_chipname = PCIC_TYPE_OZ6912;
53523db86aabSstevel 		break;
53533db86aabSstevel 	case PCIC_RICOH_RL5C466:
53543db86aabSstevel 		pcic->pc_chipname = PCIC_TYPE_RL5C466;
53553db86aabSstevel 		break;
53563db86aabSstevel 	case PCIC_TI_PCI1420:
53573db86aabSstevel 		pcic->pc_chipname = PCIC_TYPE_PCI1420;
53583db86aabSstevel 		break;
53593db86aabSstevel 	case PCIC_ENE_1420:
53603db86aabSstevel 		pcic->pc_chipname = PCIC_TYPE_1420;
53613db86aabSstevel 		break;
53623db86aabSstevel 	default:
53633db86aabSstevel 		switch (PCI_ID(vend, (uint32_t)0)) {
53643db86aabSstevel 		case PCIC_TOSHIBA_VENDOR:
53653db86aabSstevel 			pcic->pc_chipname = PCIC_TYPE_TOSHIBA;
53663db86aabSstevel 			pcic->pc_type = PCIC_TOSHIBA_VENDOR;
53673db86aabSstevel 			break;
53683db86aabSstevel 		case PCIC_TI_VENDOR:
53693db86aabSstevel 			pcic->pc_chipname = PCIC_TYPE_TI;
53703db86aabSstevel 			pcic->pc_type = PCIC_TI_VENDOR;
53713db86aabSstevel 			break;
53723db86aabSstevel 		case PCIC_O2MICRO_VENDOR:
53733db86aabSstevel 			pcic->pc_chipname = PCIC_TYPE_O2MICRO;
53743db86aabSstevel 			pcic->pc_type = PCIC_O2MICRO_VENDOR;
53753db86aabSstevel 			break;
53763db86aabSstevel 		case PCIC_RICOH_VENDOR:
53773db86aabSstevel 			pcic->pc_chipname = PCIC_TYPE_RICOH;
53783db86aabSstevel 			pcic->pc_type = PCIC_RICOH_VENDOR;
53793db86aabSstevel 			break;
53803db86aabSstevel 		default:
53813db86aabSstevel 			if (!(pcic->pc_flags & PCF_CARDBUS))
53823db86aabSstevel 				return (DDI_FAILURE);
53833db86aabSstevel 			pcic->pc_chipname = PCIC_TYPE_YENTA;
53843db86aabSstevel 			break;
53853db86aabSstevel 		}
53863db86aabSstevel 	}
53873db86aabSstevel 	return (DDI_SUCCESS);
53883db86aabSstevel }
53893db86aabSstevel 
53903db86aabSstevel static void
pcic_82092_smiirq_ctl(pcicdev_t * pcic,int socket,int intr,int state)53913db86aabSstevel pcic_82092_smiirq_ctl(pcicdev_t *pcic, int socket, int intr, int state)
53923db86aabSstevel {
53933db86aabSstevel 	uchar_t ppirr = ddi_get8(pcic->cfg_handle,
539419397407SSherry Moore 	    pcic->cfgaddr + PCIC_82092_PPIRR);
53953db86aabSstevel 	uchar_t val;
53963db86aabSstevel 
53973db86aabSstevel 	if (intr == PCIC_82092_CTL_SMI) {
53983db86aabSstevel 		val = PCIC_82092_SMI_CTL(socket,
539919397407SSherry Moore 		    PCIC_82092_INT_DISABLE);
54003db86aabSstevel 		ppirr &= ~val;
54013db86aabSstevel 		val = PCIC_82092_SMI_CTL(socket, state);
54023db86aabSstevel 		ppirr |= val;
54033db86aabSstevel 	} else {
54043db86aabSstevel 		val = PCIC_82092_IRQ_CTL(socket,
540519397407SSherry Moore 		    PCIC_82092_INT_DISABLE);
54063db86aabSstevel 		ppirr &= ~val;
54073db86aabSstevel 		val = PCIC_82092_IRQ_CTL(socket, state);
54083db86aabSstevel 		ppirr |= val;
54093db86aabSstevel 	}
54103db86aabSstevel 	ddi_put8(pcic->cfg_handle, pcic->cfgaddr + PCIC_82092_PPIRR,
541119397407SSherry Moore 	    ppirr);
54123db86aabSstevel }
54133db86aabSstevel 
54143db86aabSstevel static uint_t
pcic_cd_softint(caddr_t arg1,caddr_t arg2)54153db86aabSstevel pcic_cd_softint(caddr_t arg1, caddr_t arg2)
54163db86aabSstevel {
54173db86aabSstevel 	pcic_socket_t *sockp = (pcic_socket_t *)arg1;
54183db86aabSstevel 	uint_t rc = DDI_INTR_UNCLAIMED;
54193db86aabSstevel 
54203db86aabSstevel 	_NOTE(ARGUNUSED(arg2))
54213db86aabSstevel 
54223db86aabSstevel 	mutex_enter(&sockp->pcs_pcic->pc_lock);
54233db86aabSstevel 	if (sockp->pcs_cd_softint_flg) {
54243db86aabSstevel 		uint8_t status;
54253db86aabSstevel 		sockp->pcs_cd_softint_flg = 0;
54263db86aabSstevel 		rc = DDI_INTR_CLAIMED;
54273db86aabSstevel 		status = pcic_getb(sockp->pcs_pcic, sockp->pcs_socket,
542819397407SSherry Moore 		    PCIC_INTERFACE_STATUS);
54293db86aabSstevel 		pcic_handle_cd_change(sockp->pcs_pcic, sockp, status);
54303db86aabSstevel 	}
54313db86aabSstevel 	mutex_exit(&sockp->pcs_pcic->pc_lock);
54323db86aabSstevel 	return (rc);
54333db86aabSstevel }
54343db86aabSstevel 
54353db86aabSstevel int pcic_debounce_cnt = PCIC_REM_DEBOUNCE_CNT;
54363db86aabSstevel int pcic_debounce_intr_time = PCIC_REM_DEBOUNCE_TIME;
54373db86aabSstevel int pcic_debounce_cnt_ok = PCIC_DEBOUNCE_OK_CNT;
54383db86aabSstevel 
54393db86aabSstevel #ifdef CARDBUS
54403db86aabSstevel static uint32_t pcic_cbps_on = 0;
54413db86aabSstevel static uint32_t pcic_cbps_off = CB_PS_NOTACARD | CB_PS_CCDMASK |
54423db86aabSstevel 				CB_PS_XVCARD | CB_PS_YVCARD;
54433db86aabSstevel #else
54443db86aabSstevel static uint32_t pcic_cbps_on = CB_PS_16BITCARD;
54453db86aabSstevel static uint32_t pcic_cbps_off = CB_PS_NOTACARD | CB_PS_CCDMASK |
54463db86aabSstevel 				CB_PS_CBCARD |
54473db86aabSstevel 				CB_PS_XVCARD | CB_PS_YVCARD;
54483db86aabSstevel #endif
54493db86aabSstevel static void
pcic_handle_cd_change(pcicdev_t * pcic,pcic_socket_t * sockp,uint8_t status)54503db86aabSstevel pcic_handle_cd_change(pcicdev_t *pcic, pcic_socket_t *sockp, uint8_t status)
54513db86aabSstevel {
54523db86aabSstevel 	boolean_t	do_debounce = B_FALSE;
54533db86aabSstevel 	int		debounce_time = drv_usectohz(pcic_debounce_time);
54543db86aabSstevel 	uint8_t		irq;
54553db86aabSstevel 	timeout_id_t	debounce;
54563db86aabSstevel 
54573db86aabSstevel 	/*
54583db86aabSstevel 	 * Always reset debounce but may need to check original state later.
54593db86aabSstevel 	 */
54603db86aabSstevel 	debounce = sockp->pcs_debounce_id;
54613db86aabSstevel 	sockp->pcs_debounce_id = 0;
54623db86aabSstevel 
54633db86aabSstevel 	/*
54643db86aabSstevel 	 * Check to see whether a card is present or not. There are
54653db86aabSstevel 	 *	only two states that we are concerned with - the state
54663db86aabSstevel 	 *	where both CD pins are asserted, which means that the
54673db86aabSstevel 	 *	card is fully seated, and the state where neither CD
54683db86aabSstevel 	 *	pin is asserted, which means that the card is not
54693db86aabSstevel 	 *	present.
54703db86aabSstevel 	 * The CD signals are generally very noisy and cause a lot of
54713db86aabSstevel 	 *	contact bounce as the card is being inserted and
54723db86aabSstevel 	 *	removed, so we need to do some software debouncing.
54733db86aabSstevel 	 */
54743db86aabSstevel 
54753db86aabSstevel #ifdef PCIC_DEBUG
547619397407SSherry Moore 		pcic_err(pcic->dip, 6,
54773db86aabSstevel 		    "pcic%d handle_cd_change: socket %d card status 0x%x"
54783db86aabSstevel 		    " deb 0x%p\n", ddi_get_instance(pcic->dip),
54793db86aabSstevel 		    sockp->pcs_socket, status, debounce);
54803db86aabSstevel #endif
54813db86aabSstevel 	switch (status & PCIC_ISTAT_CD_MASK) {
54823db86aabSstevel 	case PCIC_CD_PRESENT_OK:
548319397407SSherry Moore 		sockp->pcs_flags &= ~(PCS_CARD_REMOVED|PCS_CARD_CBREM);
548419397407SSherry Moore 		if (!(sockp->pcs_flags & PCS_CARD_PRESENT)) {
54853db86aabSstevel 		uint32_t cbps;
54863db86aabSstevel #ifdef PCIC_DEBUG
54873db86aabSstevel 		pcic_err(pcic->dip, 8, "New card (0x%x)\n", sockp->pcs_flags);
54883db86aabSstevel #endif
54893db86aabSstevel 		cbps = pcic_getcb(pcic, CB_PRESENT_STATE);
54903db86aabSstevel #ifdef PCIC_DEBUG
54913db86aabSstevel 		pcic_err(pcic->dip, 8, "CBus PS (0x%x)\n", cbps);
54923db86aabSstevel #endif
54933db86aabSstevel 		/*
54943db86aabSstevel 		 * Check the CB bits are sane.
54953db86aabSstevel 		 */
54963db86aabSstevel 		if ((cbps & pcic_cbps_on) != pcic_cbps_on ||
54973db86aabSstevel 		    cbps & pcic_cbps_off) {
549819397407SSherry Moore 			cmn_err(CE_WARN,
54993db86aabSstevel 			    "%s%d: Odd Cardbus Present State 0x%x\n",
55003db86aabSstevel 			    ddi_get_name(pcic->dip),
55013db86aabSstevel 			    ddi_get_instance(pcic->dip),
55023db86aabSstevel 			    cbps);
550319397407SSherry Moore 			pcic_putcb(pcic, CB_EVENT_FORCE, CB_EF_CVTEST);
550419397407SSherry Moore 			debounce = 0;
550519397407SSherry Moore 			debounce_time = drv_usectohz(1000000);
55063db86aabSstevel 		}
55073db86aabSstevel 		if (debounce) {
550819397407SSherry Moore 			sockp->pcs_flags |= PCS_CARD_PRESENT;
550919397407SSherry Moore 			if (pcic_do_insertion) {
551019397407SSherry Moore 
551119397407SSherry Moore 				cbps = pcic_getcb(pcic, CB_PRESENT_STATE);
551219397407SSherry Moore 
551319397407SSherry Moore 				if (cbps & CB_PS_16BITCARD) {
551419397407SSherry Moore 					pcic_err(pcic->dip,
551519397407SSherry Moore 					    8, "16 bit card inserted\n");
551619397407SSherry Moore 					sockp->pcs_flags |= PCS_CARD_IS16BIT;
551719397407SSherry Moore 					/* calls pcm_adapter_callback() */
551819397407SSherry Moore 					if (pcic->pc_callback) {
551919397407SSherry Moore 
552019397407SSherry Moore 						(void) ddi_prop_update_string(
552119397407SSherry Moore 						    DDI_DEV_T_NONE,
552219397407SSherry Moore 						    pcic->dip, PCM_DEVICETYPE,
552319397407SSherry Moore 						    "pccard");
552419397407SSherry Moore 						PC_CALLBACK(pcic->dip,
552519397407SSherry Moore 						    pcic->pc_cb_arg,
552619397407SSherry Moore 						    PCE_CARD_INSERT,
552719397407SSherry Moore 						    sockp->pcs_socket);
552819397407SSherry Moore 					}
552919397407SSherry Moore 				} else if (cbps & CB_PS_CBCARD) {
553019397407SSherry Moore 					pcic_err(pcic->dip,
553119397407SSherry Moore 					    8, "32 bit card inserted\n");
55323db86aabSstevel 
553319397407SSherry Moore 					if (pcic->pc_flags & PCF_CARDBUS) {
553419397407SSherry Moore 						sockp->pcs_flags |=
553519397407SSherry Moore 						    PCS_CARD_ISCARDBUS;
55363db86aabSstevel #ifdef CARDBUS
553719397407SSherry Moore 						if (!pcic_load_cardbus(pcic,
553819397407SSherry Moore 						    sockp)) {
553919397407SSherry Moore 							pcic_unload_cardbus(
554019397407SSherry Moore 							    pcic, sockp);
554119397407SSherry Moore 						}
55423db86aabSstevel 
55433db86aabSstevel #else
554419397407SSherry Moore 						cmn_err(CE_NOTE,
554519397407SSherry Moore 						    "32 bit Cardbus not"
554619397407SSherry Moore 						    " supported in"
554719397407SSherry Moore 						    " this device driver\n");
55483db86aabSstevel #endif
554919397407SSherry Moore 					} else {
555019397407SSherry Moore 						/*
555119397407SSherry Moore 						 * Ignore the card
555219397407SSherry Moore 						 */
555319397407SSherry Moore 						cmn_err(CE_NOTE,
555419397407SSherry Moore 						    "32 bit Cardbus not"
555519397407SSherry Moore 						    " supported on this"
555619397407SSherry Moore 						    " device\n");
555719397407SSherry Moore 					}
555819397407SSherry Moore 				} else {
555919397407SSherry Moore 					cmn_err(CE_NOTE,
556019397407SSherry Moore 					    "Unsupported PCMCIA card"
556119397407SSherry Moore 					    " inserted\n");
556219397407SSherry Moore 				}
55633db86aabSstevel 			}
55643db86aabSstevel 		} else {
556519397407SSherry Moore 			do_debounce = B_TRUE;
55663db86aabSstevel 		}
556719397407SSherry Moore 		} else {
55683db86aabSstevel 		/*
55693db86aabSstevel 		 * It is possible to come through here if the system
55703db86aabSstevel 		 * starts up with cards already inserted. Do nothing
55713db86aabSstevel 		 * and don't worry about it.
55723db86aabSstevel 		 */
55733db86aabSstevel #ifdef PCIC_DEBUG
55743db86aabSstevel 		pcic_err(pcic->dip, 5,
557519397407SSherry Moore 		    "pcic%d: Odd card insertion indication on socket %d\n",
557619397407SSherry Moore 		    ddi_get_instance(pcic->dip),
557719397407SSherry Moore 		    sockp->pcs_socket);
55783db86aabSstevel #endif
557919397407SSherry Moore 		}
558019397407SSherry Moore 		break;
55813db86aabSstevel 
55823db86aabSstevel 	default:
558319397407SSherry Moore 		if (!(sockp->pcs_flags & PCS_CARD_PRESENT)) {
55843db86aabSstevel 		/*
55853db86aabSstevel 		 * Someone has started to insert a card so delay a while.
55863db86aabSstevel 		 */
55873db86aabSstevel 		do_debounce = B_TRUE;
55883db86aabSstevel 		break;
558919397407SSherry Moore 		}
55903db86aabSstevel 		/*
55913db86aabSstevel 		 * Otherwise this is basically the same as not present
55923db86aabSstevel 		 * so fall through.
55933db86aabSstevel 		 */
55943db86aabSstevel 
55953db86aabSstevel 		/* FALLTHRU */
55963db86aabSstevel 	case 0:
559719397407SSherry Moore 		if (sockp->pcs_flags & PCS_CARD_PRESENT) {
559819397407SSherry Moore 			if (pcic->pc_flags & PCF_CBPWRCTL) {
559919397407SSherry Moore 				pcic_putcb(pcic, CB_CONTROL, 0);
560019397407SSherry Moore 			} else {
560119397407SSherry Moore 				pcic_putb(pcic, sockp->pcs_socket,
560219397407SSherry Moore 				    PCIC_POWER_CONTROL, 0);
560319397407SSherry Moore 			(void) pcic_getb(pcic, sockp->pcs_socket,
560419397407SSherry Moore 			    PCIC_POWER_CONTROL);
56053db86aabSstevel 		}
56063db86aabSstevel #ifdef PCIC_DEBUG
56073db86aabSstevel 		pcic_err(pcic->dip, 8, "Card removed\n");
56083db86aabSstevel #endif
56093db86aabSstevel 		sockp->pcs_flags &= ~PCS_CARD_PRESENT;
56103db86aabSstevel 
56113db86aabSstevel 		if (sockp->pcs_flags & PCS_CARD_IS16BIT) {
561219397407SSherry Moore 			sockp->pcs_flags &= ~PCS_CARD_IS16BIT;
561319397407SSherry Moore 			if (pcic_do_removal && pcic->pc_callback) {
561419397407SSherry Moore 				PC_CALLBACK(pcic->dip, pcic->pc_cb_arg,
56153db86aabSstevel 				    PCE_CARD_REMOVAL, sockp->pcs_socket);
561619397407SSherry Moore 			}
56173db86aabSstevel 		}
56183db86aabSstevel 		if (sockp->pcs_flags & PCS_CARD_ISCARDBUS) {
561919397407SSherry Moore 			sockp->pcs_flags &= ~PCS_CARD_ISCARDBUS;
562019397407SSherry Moore 			sockp->pcs_flags |= PCS_CARD_CBREM;
56213db86aabSstevel 		}
56223db86aabSstevel 		sockp->pcs_flags |= PCS_CARD_REMOVED;
56233db86aabSstevel 
56243db86aabSstevel 		do_debounce = B_TRUE;
562519397407SSherry Moore 		}
562619397407SSherry Moore 		if (debounce && (sockp->pcs_flags & PCS_CARD_REMOVED)) {
562719397407SSherry Moore 			if (sockp->pcs_flags & PCS_CARD_CBREM) {
56283db86aabSstevel 		/*
56293db86aabSstevel 		 * Ensure that we do the unloading in the
56303db86aabSstevel 		 * debounce handler, that way we're not doing
56313db86aabSstevel 		 * nasty things in an interrupt handler. e.g.
56323db86aabSstevel 		 * a USB device will wait for data which will
56333db86aabSstevel 		 * obviously never come because we've
56343db86aabSstevel 		 * unplugged the device, but the wait will
56353db86aabSstevel 		 * wait forever because no interrupts can
56363db86aabSstevel 		 * come in...
56373db86aabSstevel 		 */
56383db86aabSstevel #ifdef CARDBUS
563919397407SSherry Moore 			pcic_unload_cardbus(pcic, sockp);
564019397407SSherry Moore 			/* pcic_dump_all(pcic); */
56413db86aabSstevel #endif
564219397407SSherry Moore 			sockp->pcs_flags &= ~PCS_CARD_CBREM;
564319397407SSherry Moore 			}
564419397407SSherry Moore 			sockp->pcs_flags &= ~PCS_CARD_REMOVED;
56453db86aabSstevel 		}
564619397407SSherry Moore 		break;
56473db86aabSstevel 	} /* switch */
56483db86aabSstevel 
56493db86aabSstevel 	if (do_debounce) {
56503db86aabSstevel 	/*
56513db86aabSstevel 	 * Delay doing
56523db86aabSstevel 	 * anything for a while so that things can settle
56533db86aabSstevel 	 * down a little. Interrupts are already disabled.
56543db86aabSstevel 	 * Reset the state and we'll reevaluate the
56553db86aabSstevel 	 * whole kit 'n kaboodle when the timeout fires
56563db86aabSstevel 	 */
56573db86aabSstevel #ifdef PCIC_DEBUG
56583db86aabSstevel 		pcic_err(pcic->dip, 8, "Queueing up debounce timeout for "
565919397407SSherry Moore 		    "socket %d.%d\n",
566019397407SSherry Moore 		    ddi_get_instance(pcic->dip),
566119397407SSherry Moore 		    sockp->pcs_socket);
56623db86aabSstevel #endif
566319397407SSherry Moore 		sockp->pcs_debounce_id =
566419397407SSherry Moore 		    pcic_add_debqueue(sockp, debounce_time);
56653db86aabSstevel 
56663db86aabSstevel 	/*
56673db86aabSstevel 	 * We bug out here without re-enabling interrupts. They will
56683db86aabSstevel 	 * be re-enabled when the debounce timeout swings through
56693db86aabSstevel 	 * here.
56703db86aabSstevel 	 */
567119397407SSherry Moore 		return;
56723db86aabSstevel 	}
56733db86aabSstevel 
56743db86aabSstevel 	/*
56753db86aabSstevel 	 * Turn on Card detect interrupts. Other interrupts will be
56763db86aabSstevel 	 * enabled during set_socket calls.
56773db86aabSstevel 	 *
56783db86aabSstevel 	 * Note that set_socket only changes interrupt settings when there
56793db86aabSstevel 	 * is a card present.
56803db86aabSstevel 	 */
56813db86aabSstevel 	irq = pcic_getb(pcic, sockp->pcs_socket, PCIC_MANAGEMENT_INT);
56823db86aabSstevel 	irq |= PCIC_CD_DETECT;
56833db86aabSstevel 	pcic_putb(pcic, sockp->pcs_socket, PCIC_MANAGEMENT_INT, irq);
56840e995c33Srw 	pcic_putcb(pcic, CB_STATUS_MASK, CB_SE_CCDMASK);
56853db86aabSstevel 
56860d282d13Srw 	/* Out from debouncing state */
56870d282d13Srw 	sockp->pcs_flags &= ~PCS_DEBOUNCING;
56880d282d13Srw 
56893db86aabSstevel 	pcic_err(pcic->dip, 7, "Leaving pcic_handle_cd_change\n");
56903db86aabSstevel }
56913db86aabSstevel 
56923db86aabSstevel /*
56933db86aabSstevel  * pcic_getb()
56943db86aabSstevel  *	get an I/O byte based on the yardware decode method
56953db86aabSstevel  */
56963db86aabSstevel static uint8_t
pcic_getb(pcicdev_t * pcic,int socket,int reg)56973db86aabSstevel pcic_getb(pcicdev_t *pcic, int socket, int reg)
56983db86aabSstevel {
56993db86aabSstevel 	int work;
57003db86aabSstevel 
57013db86aabSstevel #if defined(PCIC_DEBUG)
57023db86aabSstevel 	if (pcic_debug == 0x7fff) {
57033db86aabSstevel 		cmn_err(CE_CONT, "pcic_getb0: pcic=%p socket=%d reg=%d\n",
570419397407SSherry Moore 		    (void *)pcic, socket, reg);
57053db86aabSstevel 		cmn_err(CE_CONT, "pcic_getb1: type=%d handle=%p ioaddr=%p \n",
570619397407SSherry Moore 		    pcic->pc_io_type, (void *)pcic->handle,
570719397407SSherry Moore 		    (void *)pcic->ioaddr);
57083db86aabSstevel 	}
57093db86aabSstevel #endif
57103db86aabSstevel 
57113db86aabSstevel 	switch (pcic->pc_io_type) {
57123db86aabSstevel 	case PCIC_IO_TYPE_YENTA:
57133db86aabSstevel 		return (ddi_get8(pcic->handle,
57143db86aabSstevel 		    pcic->ioaddr + CB_R2_OFFSET + reg));
57153db86aabSstevel 	default:
57163db86aabSstevel 		work = (socket * PCIC_SOCKET_1) | reg;
57173db86aabSstevel 		ddi_put8(pcic->handle, pcic->ioaddr, work);
57183db86aabSstevel 		return (ddi_get8(pcic->handle, pcic->ioaddr + 1));
57193db86aabSstevel 	}
57203db86aabSstevel }
57213db86aabSstevel 
57223db86aabSstevel static void
pcic_putb(pcicdev_t * pcic,int socket,int reg,int8_t value)57233db86aabSstevel pcic_putb(pcicdev_t *pcic, int socket, int reg, int8_t value)
57243db86aabSstevel {
57253db86aabSstevel 	int work;
57263db86aabSstevel 
57273db86aabSstevel #if defined(PCIC_DEBUG)
57283db86aabSstevel 	if (pcic_debug == 0x7fff) {
57293db86aabSstevel 		cmn_err(CE_CONT,
573019397407SSherry Moore 		    "pcic_putb0: pcic=%p socket=%d reg=%d value=%x \n",
573119397407SSherry Moore 		    (void *)pcic, socket, reg, value);
57323db86aabSstevel 		cmn_err(CE_CONT,
573319397407SSherry Moore 		    "pcic_putb1: type=%d handle=%p ioaddr=%p \n",
573419397407SSherry Moore 		    pcic->pc_io_type, (void *)pcic->handle,
573519397407SSherry Moore 		    (void *)pcic->ioaddr);
57363db86aabSstevel 	}
57373db86aabSstevel #endif
57383db86aabSstevel 
57393db86aabSstevel 
57403db86aabSstevel 	switch (pcic->pc_io_type) {
57413db86aabSstevel 	case PCIC_IO_TYPE_YENTA:
57423db86aabSstevel 		ddi_put8(pcic->handle, pcic->ioaddr + CB_R2_OFFSET + reg,
574319397407SSherry Moore 		    value);
57443db86aabSstevel 		break;
57453db86aabSstevel 	default:
57463db86aabSstevel 		work = (socket * PCIC_SOCKET_1) | reg;
57473db86aabSstevel 		ddi_put8(pcic->handle, pcic->ioaddr, work);
57483db86aabSstevel 		ddi_put8(pcic->handle, pcic->ioaddr + 1, value);
57493db86aabSstevel 		break;
57503db86aabSstevel 	}
57513db86aabSstevel }
57523db86aabSstevel 
57533db86aabSstevel /*
57543db86aabSstevel  * chip identification functions
57553db86aabSstevel  */
57563db86aabSstevel 
57573db86aabSstevel /*
57583db86aabSstevel  * chip identification: Cirrus Logic PD6710/6720/6722
57593db86aabSstevel  */
57603db86aabSstevel static int
pcic_ci_cirrus(pcicdev_t * pcic)57613db86aabSstevel pcic_ci_cirrus(pcicdev_t *pcic)
57623db86aabSstevel {
57633db86aabSstevel 	int value1, value2;
57643db86aabSstevel 
57653db86aabSstevel 	/* Init the CL id mode */
57663db86aabSstevel 	value1 = pcic_getb(pcic, 0, PCIC_CHIP_INFO);
57673db86aabSstevel 	pcic_putb(pcic, 0, PCIC_CHIP_INFO, 0);
57683db86aabSstevel 	value1 = pcic_getb(pcic, 0, PCIC_CHIP_INFO);
57693db86aabSstevel 	value2 = pcic_getb(pcic, 0, PCIC_CHIP_INFO);
57703db86aabSstevel 
57713db86aabSstevel 	if ((value1 & PCIC_CI_ID) == PCIC_CI_ID &&
57723db86aabSstevel 	    (value2 & PCIC_CI_ID) == 0) {
57733db86aabSstevel 		/* chip is a Cirrus Logic and not Intel */
57743db86aabSstevel 		pcic->pc_type = PCIC_CL_PD6710;
57753db86aabSstevel 		if (value1 & PCIC_CI_SLOTS)
57763db86aabSstevel 			pcic->pc_chipname = PCIC_TYPE_PD6720;
57773db86aabSstevel 		else
57783db86aabSstevel 			pcic->pc_chipname = PCIC_TYPE_PD6710;
57793db86aabSstevel 		/* now fine tune things just in case a 6722 */
57803db86aabSstevel 		value1 = clext_reg_read(pcic, 0, PCIC_CLEXT_DMASK_0);
57813db86aabSstevel 		if (value1 == 0) {
57823db86aabSstevel 			clext_reg_write(pcic, 0, PCIC_CLEXT_SCRATCH, 0x55);
57833db86aabSstevel 			value1 = clext_reg_read(pcic, 0, PCIC_CLEXT_SCRATCH);
57843db86aabSstevel 			if (value1 == 0x55) {
57853db86aabSstevel 				pcic->pc_chipname = PCIC_TYPE_PD6722;
57863db86aabSstevel 				pcic->pc_type = PCIC_CL_PD6722;
57873db86aabSstevel 				clext_reg_write(pcic, 0, PCIC_CLEXT_SCRATCH, 0);
57883db86aabSstevel 			}
57893db86aabSstevel 		}
57903db86aabSstevel 		return (1);
57913db86aabSstevel 	}
57923db86aabSstevel 	return (0);
57933db86aabSstevel }
57943db86aabSstevel 
57953db86aabSstevel /*
57963db86aabSstevel  * chip identification: Vadem (VG365/465/468/469)
57973db86aabSstevel  */
57983db86aabSstevel 
57993db86aabSstevel static void
pcic_vadem_enable(pcicdev_t * pcic)58003db86aabSstevel pcic_vadem_enable(pcicdev_t *pcic)
58013db86aabSstevel {
58023db86aabSstevel 	ddi_put8(pcic->handle, pcic->ioaddr, PCIC_VADEM_P1);
58033db86aabSstevel 	ddi_put8(pcic->handle, pcic->ioaddr, PCIC_VADEM_P2);
58043db86aabSstevel 	ddi_put8(pcic->handle, pcic->ioaddr, pcic->pc_lastreg);
58053db86aabSstevel }
58063db86aabSstevel 
58073db86aabSstevel static int
pcic_ci_vadem(pcicdev_t * pcic)58083db86aabSstevel pcic_ci_vadem(pcicdev_t *pcic)
58093db86aabSstevel {
58103db86aabSstevel 	int value;
58113db86aabSstevel 
58123db86aabSstevel 	pcic_vadem_enable(pcic);
58133db86aabSstevel 	value = pcic_getb(pcic, 0, PCIC_CHIP_REVISION);
58143db86aabSstevel 	pcic_putb(pcic, 0, PCIC_CHIP_REVISION, 0xFF);
58153db86aabSstevel 	if (pcic_getb(pcic, 0, PCIC_CHIP_REVISION) ==
58163db86aabSstevel 	    (value | PCIC_VADEM_D3) ||
58173db86aabSstevel 	    (pcic_getb(pcic, 0, PCIC_CHIP_REVISION) & PCIC_REV_MASK) ==
58183db86aabSstevel 	    PCIC_VADEM_469) {
58193db86aabSstevel 		int vadem, new;
58203db86aabSstevel 		pcic_vadem_enable(pcic);
58213db86aabSstevel 		vadem = pcic_getb(pcic, 0, PCIC_VG_DMA) &
582219397407SSherry Moore 		    ~(PCIC_V_UNLOCK | PCIC_V_VADEMREV);
58233db86aabSstevel 		new = vadem | (PCIC_V_VADEMREV|PCIC_V_UNLOCK);
58243db86aabSstevel 		pcic_putb(pcic, 0, PCIC_VG_DMA, new);
58253db86aabSstevel 		value = pcic_getb(pcic, 0, PCIC_CHIP_REVISION);
58263db86aabSstevel 
58273db86aabSstevel 		/* want to lock but leave mouse or other on */
58283db86aabSstevel 		pcic_putb(pcic, 0, PCIC_VG_DMA, vadem);
58293db86aabSstevel 		switch (value & PCIC_REV_MASK) {
58303db86aabSstevel 		case PCIC_VADEM_365:
58313db86aabSstevel 			pcic->pc_chipname = PCIC_VG_365;
58323db86aabSstevel 			pcic->pc_type = PCIC_VADEM;
58333db86aabSstevel 			break;
58343db86aabSstevel 		case PCIC_VADEM_465:
58353db86aabSstevel 			pcic->pc_chipname = PCIC_VG_465;
58363db86aabSstevel 			pcic->pc_type = PCIC_VADEM;
58373db86aabSstevel 			pcic->pc_flags |= PCF_1SOCKET;
58383db86aabSstevel 			break;
58393db86aabSstevel 		case PCIC_VADEM_468:
58403db86aabSstevel 			pcic->pc_chipname = PCIC_VG_468;
58413db86aabSstevel 			pcic->pc_type = PCIC_VADEM;
58423db86aabSstevel 			break;
58433db86aabSstevel 		case PCIC_VADEM_469:
58443db86aabSstevel 			pcic->pc_chipname = PCIC_VG_469;
58453db86aabSstevel 			pcic->pc_type = PCIC_VADEM_VG469;
58463db86aabSstevel 			break;
58473db86aabSstevel 		}
58483db86aabSstevel 		return (1);
58493db86aabSstevel 	}
58503db86aabSstevel 	return (0);
58513db86aabSstevel }
58523db86aabSstevel 
58533db86aabSstevel /*
58543db86aabSstevel  * chip identification: Ricoh
58553db86aabSstevel  */
58563db86aabSstevel static int
pcic_ci_ricoh(pcicdev_t * pcic)58573db86aabSstevel pcic_ci_ricoh(pcicdev_t *pcic)
58583db86aabSstevel {
58593db86aabSstevel 	int value;
58603db86aabSstevel 
58613db86aabSstevel 	value = pcic_getb(pcic, 0, PCIC_RF_CHIP_IDENT);
58623db86aabSstevel 	switch (value) {
58633db86aabSstevel 	case PCIC_RF_296:
58643db86aabSstevel 		pcic->pc_type = PCIC_RICOH;
58653db86aabSstevel 		pcic->pc_chipname = PCIC_TYPE_RF5C296;
58663db86aabSstevel 		return (1);
58673db86aabSstevel 	case PCIC_RF_396:
58683db86aabSstevel 		pcic->pc_type = PCIC_RICOH;
58693db86aabSstevel 		pcic->pc_chipname = PCIC_TYPE_RF5C396;
58703db86aabSstevel 		return (1);
58713db86aabSstevel 	}
58723db86aabSstevel 	return (0);
58733db86aabSstevel }
58743db86aabSstevel 
58753db86aabSstevel 
58763db86aabSstevel /*
58773db86aabSstevel  * set up available address spaces in busra
58783db86aabSstevel  */
58793db86aabSstevel static void
pcic_init_assigned(dev_info_t * dip)58803db86aabSstevel pcic_init_assigned(dev_info_t *dip)
58813db86aabSstevel {
58823db86aabSstevel 	pcm_regs_t *pcic_avail_p;
58833db86aabSstevel 	pci_regspec_t *pci_avail_p, *regs;
58843db86aabSstevel 	int len, entries, rlen;
58853db86aabSstevel 	dev_info_t *pdip;
58863db86aabSstevel 
58873db86aabSstevel 	if (ddi_getlongprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS,
58883db86aabSstevel 	    "available", (caddr_t)&pcic_avail_p, &len) == DDI_PROP_SUCCESS) {
58893db86aabSstevel 		/*
58903db86aabSstevel 		 * found "available" property at the cardbus/pcmcia node
58913db86aabSstevel 		 * need to translate address space entries from pcmcia
58923db86aabSstevel 		 * format to pci format
58933db86aabSstevel 		 */
58943db86aabSstevel 		entries = len / sizeof (pcm_regs_t);
58953db86aabSstevel 		pci_avail_p = kmem_alloc(sizeof (pci_regspec_t) * entries,
589619397407SSherry Moore 		    KM_SLEEP);
58973db86aabSstevel 		if (pcic_apply_avail_ranges(dip, pcic_avail_p, pci_avail_p,
58983db86aabSstevel 		    entries) == DDI_SUCCESS)
58993db86aabSstevel 			(void) pci_resource_setup_avail(dip, pci_avail_p,
590019397407SSherry Moore 			    entries);
59013db86aabSstevel 		kmem_free(pcic_avail_p, len);
59023db86aabSstevel 		kmem_free(pci_avail_p, entries * sizeof (pci_regspec_t));
59033db86aabSstevel 		return;
59043db86aabSstevel 	}
59053db86aabSstevel 
59063db86aabSstevel 	/*
59073db86aabSstevel 	 * "legacy" platforms will have "available" property in pci node
59083db86aabSstevel 	 */
59093db86aabSstevel 	for (pdip = ddi_get_parent(dip); pdip; pdip = ddi_get_parent(pdip)) {
59103db86aabSstevel 		if (ddi_getlongprop(DDI_DEV_T_ANY, pdip, DDI_PROP_DONTPASS,
59113db86aabSstevel 		    "available", (caddr_t)&pci_avail_p, &len) ==
59123db86aabSstevel 		    DDI_PROP_SUCCESS) {
59133db86aabSstevel 			/* (void) pci_resource_setup(pdip); */
59143db86aabSstevel 			kmem_free(pci_avail_p, len);
59153db86aabSstevel 			break;
59163db86aabSstevel 		}
59173db86aabSstevel 	}
59183db86aabSstevel 
59193db86aabSstevel 	if (pdip == NULL) {
59203db86aabSstevel 		int len;
59213db86aabSstevel 		char bus_type[16] = "(unknown)";
59223db86aabSstevel 		dev_info_t *par;
59233db86aabSstevel 
59243db86aabSstevel 		cmn_err(CE_CONT,
59253db86aabSstevel 		    "?pcic_init_assigned: no available property for pcmcia\n");
59263db86aabSstevel 
59273db86aabSstevel 		/*
59283db86aabSstevel 		 * This code is taken from pci_resource_setup() but does
59293db86aabSstevel 		 * not attempt to use the "available" property to populate
59303db86aabSstevel 		 * the ndi maps that are created.
59313db86aabSstevel 		 * The fact that we will actually
59323db86aabSstevel 		 * free some resource below (that was allocated by OBP)
59333db86aabSstevel 		 * should be enough to be going on with.
59343db86aabSstevel 		 */
59353db86aabSstevel 		for (par = dip; par != NULL; par = ddi_get_parent(par)) {
59363db86aabSstevel 			len = sizeof (bus_type);
59373db86aabSstevel 
59383db86aabSstevel 			if ((ddi_prop_op(DDI_DEV_T_ANY, par,
59393db86aabSstevel 			    PROP_LEN_AND_VAL_BUF,
59403db86aabSstevel 			    DDI_PROP_CANSLEEP | DDI_PROP_DONTPASS,
59413db86aabSstevel 			    "device_type",
59423db86aabSstevel 			    (caddr_t)&bus_type, &len) == DDI_SUCCESS) &&
59438134ee03Srw 			    (strcmp(bus_type, DEVI_PCI_NEXNAME) == 0 ||
594419397407SSherry Moore 			    strcmp(bus_type, DEVI_PCIEX_NEXNAME) == 0))
59453db86aabSstevel 				break;
59463db86aabSstevel 		}
59473db86aabSstevel 		if (par != NULL &&
59483db86aabSstevel 		    (ndi_ra_map_setup(par, NDI_RA_TYPE_MEM) != NDI_SUCCESS ||
59493db86aabSstevel 		    ndi_ra_map_setup(par, NDI_RA_TYPE_IO) != NDI_SUCCESS))
59503db86aabSstevel 			par = NULL;
59513db86aabSstevel 	} else {
59523db86aabSstevel #ifdef CARDBUS
59533db86aabSstevel 		cardbus_bus_range_t *bus_range;
59543db86aabSstevel 		int k;
59553db86aabSstevel 
59563db86aabSstevel 		if (ddi_getlongprop(DDI_DEV_T_ANY, pdip, 0, "bus-range",
59573db86aabSstevel 		    (caddr_t)&bus_range, &k) == DDI_PROP_SUCCESS) {
59583db86aabSstevel 			if (bus_range->lo != bus_range->hi)
59593db86aabSstevel 				pcic_err(pdip, 9, "allowable bus range is "
59603db86aabSstevel 				    "%u->%u\n", bus_range->lo, bus_range->hi);
59613db86aabSstevel 			else {
59623db86aabSstevel 				pcic_err(pdip, 0,
59633db86aabSstevel 				    "!No spare PCI bus numbers, range is "
59643db86aabSstevel 				    "%u->%u, cardbus isn't usable\n",
59653db86aabSstevel 				    bus_range->lo, bus_range->hi);
59663db86aabSstevel 			}
59673db86aabSstevel 			kmem_free(bus_range, k);
59683db86aabSstevel 		} else
59693db86aabSstevel 			pcic_err(pdip, 0, "!No bus-range property seems to "
59703db86aabSstevel 			    "have been set up\n");
59713db86aabSstevel #endif
59723db86aabSstevel 		/*
59733db86aabSstevel 		 * Have a valid parent with the "available" property
59743db86aabSstevel 		 */
59753db86aabSstevel 		(void) pci_resource_setup(pdip);
59763db86aabSstevel 	}
59773db86aabSstevel 
59783db86aabSstevel 	if ((strcmp(ddi_get_name(dip), "pcma") == 0) &&
59793db86aabSstevel 	    ddi_getlongprop(DDI_DEV_T_NONE, dip, DDI_PROP_DONTPASS,
59803db86aabSstevel 	    "assigned-addresses",
59813db86aabSstevel 	    (caddr_t)&regs, &rlen) == DDI_SUCCESS) {
59823db86aabSstevel 		ra_return_t ra;
59833db86aabSstevel 
59843db86aabSstevel 		/*
59853db86aabSstevel 		 * On the UltraBook IIi the ranges are assigned under
59863db86aabSstevel 		 * openboot. If we don't free them here the first I/O
59873db86aabSstevel 		 * space that can be used is up above 0x10000 which
59883db86aabSstevel 		 * doesn't work for this driver due to restrictions
59893db86aabSstevel 		 * on the PCI I/O addresses the controllers can cope with.
59903db86aabSstevel 		 * They are never going to be used by anything else
59913db86aabSstevel 		 * so free them up to the general pool. AG.
59923db86aabSstevel 		 */
59933db86aabSstevel 		pcic_err(dip, 1, "Free assigned addresses\n");
59943db86aabSstevel 
59953db86aabSstevel 		if ((PCI_REG_ADDR_G(regs[0].pci_phys_hi) ==
59963db86aabSstevel 		    PCI_REG_ADDR_G(PCI_ADDR_MEM32)) &&
59973db86aabSstevel 		    regs[0].pci_size_low == 0x1000000) {
59983db86aabSstevel 			ra.ra_addr_lo = regs[0].pci_phys_low;
59993db86aabSstevel 			ra.ra_len = regs[0].pci_size_low;
60003db86aabSstevel 			(void) pcmcia_free_mem(dip, &ra);
60013db86aabSstevel 		}
60023db86aabSstevel 		if ((PCI_REG_ADDR_G(regs[1].pci_phys_hi) ==
60033db86aabSstevel 		    PCI_REG_ADDR_G(PCI_ADDR_IO)) &&
60043db86aabSstevel 		    (regs[1].pci_size_low == 0x8000 ||
60053db86aabSstevel 		    regs[1].pci_size_low == 0x4000))   /* UB-IIi || UB-I */
60063db86aabSstevel 		{
60073db86aabSstevel 			ra.ra_addr_lo = regs[1].pci_phys_low;
60083db86aabSstevel 			ra.ra_len = regs[1].pci_size_low;
60093db86aabSstevel 			(void) pcmcia_free_io(dip, &ra);
60103db86aabSstevel 		}
60113db86aabSstevel 		kmem_free((caddr_t)regs, rlen);
60123db86aabSstevel 	}
60133db86aabSstevel }
60143db86aabSstevel 
60153db86aabSstevel /*
60163db86aabSstevel  * translate "available" from pcmcia format to pci format
60173db86aabSstevel  */
60183db86aabSstevel static int
pcic_apply_avail_ranges(dev_info_t * dip,pcm_regs_t * pcic_p,pci_regspec_t * pci_p,int entries)60193db86aabSstevel pcic_apply_avail_ranges(dev_info_t *dip, pcm_regs_t *pcic_p,
60203db86aabSstevel     pci_regspec_t *pci_p, int entries)
60213db86aabSstevel {
60223db86aabSstevel 	int i, range_len, range_entries;
60233db86aabSstevel 	pcic_ranges_t *pcic_range_p;
60243db86aabSstevel 
60253db86aabSstevel 	if (ddi_getlongprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, "ranges",
602619397407SSherry Moore 	    (caddr_t)&pcic_range_p, &range_len) != DDI_PROP_SUCCESS) {
60273db86aabSstevel 		cmn_err(CE_CONT, "?pcic_apply_avail_ranges: "
602819397407SSherry Moore 		    "no ranges property for pcmcia\n");
60293db86aabSstevel 		return (DDI_FAILURE);
60303db86aabSstevel 	}
60313db86aabSstevel 
60323db86aabSstevel 	range_entries = range_len / sizeof (pcic_ranges_t);
60333db86aabSstevel 
60343db86aabSstevel 	/* for each "available" entry to be translated */
60353db86aabSstevel 	for (i = 0; i < entries; i++, pcic_p++, pci_p++) {
60363db86aabSstevel 		int j;
60373db86aabSstevel 		pcic_ranges_t *range_p = pcic_range_p;
60383db86aabSstevel 		pci_p->pci_phys_hi = -1u; /* default invalid value */
60393db86aabSstevel 
60403db86aabSstevel 		/* for each "ranges" entry to be searched */
60413db86aabSstevel 		for (j = 0; j < range_entries; j++, range_p++) {
60423db86aabSstevel 			uint64_t range_end = range_p->pcic_range_caddrlo +
604319397407SSherry Moore 			    range_p->pcic_range_size;
60443db86aabSstevel 			uint64_t avail_end = pcic_p->phys_lo + pcic_p->phys_len;
60453db86aabSstevel 
60463db86aabSstevel 			if ((range_p->pcic_range_caddrhi != pcic_p->phys_hi) ||
60473db86aabSstevel 			    (range_p->pcic_range_caddrlo > pcic_p->phys_lo) ||
60483db86aabSstevel 			    (range_end < avail_end))
60493db86aabSstevel 				continue;
60503db86aabSstevel 
60513db86aabSstevel 			pci_p->pci_phys_hi = range_p->pcic_range_paddrhi;
60523db86aabSstevel 			pci_p->pci_phys_mid = range_p->pcic_range_paddrmid;
60533db86aabSstevel 			pci_p->pci_phys_low = range_p->pcic_range_paddrlo
60543db86aabSstevel 			    + (pcic_p->phys_lo - range_p->pcic_range_caddrlo);
60553db86aabSstevel 			pci_p->pci_size_hi = 0;
60563db86aabSstevel 			pci_p->pci_size_low = pcic_p->phys_len;
60573db86aabSstevel 		}
60583db86aabSstevel 	}
60593db86aabSstevel 	kmem_free(pcic_range_p, range_len);
60603db86aabSstevel 	return (DDI_SUCCESS);
60613db86aabSstevel }
60623db86aabSstevel 
60633db86aabSstevel static int
pcic_open(dev_t * dev,int flag,int otyp,cred_t * cred)60643db86aabSstevel pcic_open(dev_t *dev, int flag, int otyp, cred_t *cred)
60653db86aabSstevel {
60663db86aabSstevel #ifdef CARDBUS
60673db86aabSstevel 	if (cardbus_is_cb_minor(*dev))
60683db86aabSstevel 		return (cardbus_open(dev, flag, otyp, cred));
60693db86aabSstevel #endif
60703db86aabSstevel 	return (EINVAL);
60713db86aabSstevel }
60723db86aabSstevel 
60733db86aabSstevel static int
pcic_close(dev_t dev,int flag,int otyp,cred_t * cred)60743db86aabSstevel pcic_close(dev_t dev, int flag, int otyp, cred_t *cred)
60753db86aabSstevel {
60763db86aabSstevel #ifdef CARDBUS
60773db86aabSstevel 	if (cardbus_is_cb_minor(dev))
60783db86aabSstevel 		return (cardbus_close(dev, flag, otyp, cred));
60793db86aabSstevel #endif
60803db86aabSstevel 	return (EINVAL);
60813db86aabSstevel }
60823db86aabSstevel 
60833db86aabSstevel static int
pcic_ioctl(dev_t dev,int cmd,intptr_t arg,int mode,cred_t * cred,int * rval)60843db86aabSstevel pcic_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, cred_t *cred,
6085f6c5b045SToomas Soome     int *rval)
60863db86aabSstevel {
60873db86aabSstevel #ifdef CARDBUS
60883db86aabSstevel 	if (cardbus_is_cb_minor(dev))
60893db86aabSstevel 		return (cardbus_ioctl(dev, cmd, arg, mode, cred, rval));
60903db86aabSstevel #endif
60913db86aabSstevel 	return (EINVAL);
60923db86aabSstevel }
60933db86aabSstevel 
60943db86aabSstevel 
60953db86aabSstevel static boolean_t
pcic_load_cardbus(pcicdev_t * pcic,const pcic_socket_t * sockp)60963db86aabSstevel pcic_load_cardbus(pcicdev_t *pcic, const pcic_socket_t *sockp)
60973db86aabSstevel {
60983db86aabSstevel 	uint32_t present_state;
60993db86aabSstevel 	dev_info_t *dip = pcic->dip;
61003db86aabSstevel 	set_socket_t s;
61013db86aabSstevel 	get_socket_t g;
61023db86aabSstevel 	boolean_t retval;
61033db86aabSstevel 	unsigned vccLevel;
61043db86aabSstevel 
61053db86aabSstevel 	pcic_err(dip, 8, "entering pcic_load_cardbus\n");
61063db86aabSstevel 
61073db86aabSstevel 	pcic_mutex_exit(&pcic->pc_lock);
61083db86aabSstevel 
61093db86aabSstevel 	bzero(&s, sizeof (set_socket_t));
61103db86aabSstevel 	s.socket = sockp->pcs_socket;
61113db86aabSstevel 	s.SCIntMask = SBM_CD|SBM_RDYBSY;
61123db86aabSstevel 	s.IFType = IF_CARDBUS;
61133db86aabSstevel 	s.State = (unsigned)~0;
61143db86aabSstevel 
61153db86aabSstevel 	present_state = pcic_getcb(pcic, CB_PRESENT_STATE);
61163db86aabSstevel 	if (present_state & PCIC_VCC_3VCARD)
61173db86aabSstevel 		s.VccLevel = PCIC_VCC_3VLEVEL;
61183db86aabSstevel 	else if (present_state & PCIC_VCC_5VCARD)
61193db86aabSstevel 		s.VccLevel = PCIC_VCC_5VLEVEL;
61203db86aabSstevel 	else {
61213db86aabSstevel 		cmn_err(CE_CONT,
61223db86aabSstevel 		    "pcic_load_cardbus: unsupported card voltage\n");
61233db86aabSstevel 		goto failure;
61243db86aabSstevel 	}
61253db86aabSstevel 	vccLevel = s.VccLevel;
61263db86aabSstevel 	s.Vpp1Level = s.Vpp2Level = 0;
61273db86aabSstevel 
61283db86aabSstevel 	if (pcic_set_socket(dip, &s) != SUCCESS)
61293db86aabSstevel 		goto failure;
61303db86aabSstevel 
61313db86aabSstevel 	if (pcic_reset_socket(dip, sockp->pcs_socket,
61323db86aabSstevel 	    RESET_MODE_CARD_ONLY) != SUCCESS)
61333db86aabSstevel 		goto failure;
61343db86aabSstevel 
61353db86aabSstevel 	bzero(&g, sizeof (get_socket_t));
61363db86aabSstevel 	g.socket = sockp->pcs_socket;
61373db86aabSstevel 	if (pcic_get_socket(dip, &g) != SUCCESS)
61383db86aabSstevel 		goto failure;
61393db86aabSstevel 
61403db86aabSstevel 	bzero(&s, sizeof (set_socket_t));
61413db86aabSstevel 	s.socket = sockp->pcs_socket;
61423db86aabSstevel 	s.SCIntMask = SBM_CD;
61433db86aabSstevel 	s.IREQRouting = g.IRQRouting;
61443db86aabSstevel 	s.IFType = g.IFType;
61453db86aabSstevel 	s.CtlInd = g.CtlInd;
61463db86aabSstevel 	s.State = (unsigned)~0;
61473db86aabSstevel 	s.VccLevel = vccLevel;
61483db86aabSstevel 	s.Vpp1Level = s.Vpp2Level = 0;
61493db86aabSstevel 
615011c2b4c0Srw 	retval = pcic_set_socket(dip, &s);
615111c2b4c0Srw 	pcmcia_cb_resumed(s.socket);
615211c2b4c0Srw 	if (retval != SUCCESS)
61533db86aabSstevel 		goto failure;
61543db86aabSstevel 
61553db86aabSstevel 	retval = cardbus_load_cardbus(dip, sockp->pcs_socket, pcic->pc_base);
61563db86aabSstevel 	goto exit;
61573db86aabSstevel 
61583db86aabSstevel failure:
61593db86aabSstevel 	retval = B_FALSE;
61603db86aabSstevel 
61613db86aabSstevel exit:
61623db86aabSstevel 	pcic_mutex_enter(&pcic->pc_lock);
61633db86aabSstevel 	pcic_err(dip, 8, "exit pcic_load_cardbus (%s)\n",
61643db86aabSstevel 	    retval ? "success" : "failure");
61653db86aabSstevel 	return (retval);
61663db86aabSstevel }
61673db86aabSstevel 
61683db86aabSstevel static void
pcic_unload_cardbus(pcicdev_t * pcic,const pcic_socket_t * sockp)61693db86aabSstevel pcic_unload_cardbus(pcicdev_t *pcic, const pcic_socket_t *sockp)
61703db86aabSstevel {
61713db86aabSstevel 	dev_info_t *dip = pcic->dip;
61723db86aabSstevel 	set_socket_t s;
61733db86aabSstevel 
61743db86aabSstevel 	pcic_mutex_exit(&pcic->pc_lock);
61753db86aabSstevel 
61763db86aabSstevel 	cardbus_unload_cardbus(dip);
61773db86aabSstevel 
61783db86aabSstevel 	bzero(&s, sizeof (set_socket_t));
61793db86aabSstevel 	s.socket = sockp->pcs_socket;
61803db86aabSstevel 	s.SCIntMask = SBM_CD|SBM_RDYBSY;
61813db86aabSstevel 	s.IREQRouting = 0;
61823db86aabSstevel 	s.IFType = IF_MEMORY;
61833db86aabSstevel 	s.CtlInd = 0;
61843db86aabSstevel 	s.State = 0;
61853db86aabSstevel 	s.VccLevel = s.Vpp1Level = s.Vpp2Level = 0;
61863db86aabSstevel 
61873db86aabSstevel 	(void) pcic_set_socket(dip, &s);
61883db86aabSstevel 
61893db86aabSstevel 	pcic_mutex_enter(&pcic->pc_lock);
61903db86aabSstevel }
61913db86aabSstevel 
61923db86aabSstevel static uint32_t
pcic_getcb(pcicdev_t * pcic,int reg)61933db86aabSstevel pcic_getcb(pcicdev_t *pcic, int reg)
61943db86aabSstevel {
61953db86aabSstevel 	ASSERT(pcic->pc_io_type == PCIC_IO_TYPE_YENTA);
61963db86aabSstevel 
61973db86aabSstevel 	return (ddi_get32(pcic->handle,
61983db86aabSstevel 	    (uint32_t *)(pcic->ioaddr + CB_CB_OFFSET + reg)));
61993db86aabSstevel }
62003db86aabSstevel 
62013db86aabSstevel static void
pcic_putcb(pcicdev_t * pcic,int reg,uint32_t value)62023db86aabSstevel pcic_putcb(pcicdev_t *pcic, int reg, uint32_t value)
62033db86aabSstevel {
62043db86aabSstevel 	ASSERT(pcic->pc_io_type == PCIC_IO_TYPE_YENTA);
62053db86aabSstevel 
62063db86aabSstevel 	ddi_put32(pcic->handle,
62073db86aabSstevel 	    (uint32_t *)(pcic->ioaddr + CB_CB_OFFSET + reg), value);
62083db86aabSstevel }
62093db86aabSstevel 
62103db86aabSstevel static void
pcic_enable_io_intr(pcicdev_t * pcic,int socket,int irq)62113db86aabSstevel pcic_enable_io_intr(pcicdev_t *pcic, int socket, int irq)
62123db86aabSstevel {
62133db86aabSstevel 	uint8_t value;
62143db86aabSstevel 	uint16_t brdgctl;
62153db86aabSstevel 
62163db86aabSstevel 	value = pcic_getb(pcic, socket, PCIC_INTERRUPT) & ~PCIC_INTR_MASK;
62173db86aabSstevel 	pcic_putb(pcic, socket, PCIC_INTERRUPT, value | irq);
62183db86aabSstevel 
62193db86aabSstevel 	switch (pcic->pc_type) {
62203db86aabSstevel 	case PCIC_INTEL_i82092:
62213db86aabSstevel 		pcic_82092_smiirq_ctl(pcic, socket, PCIC_82092_CTL_IRQ,
62223db86aabSstevel 		    PCIC_82092_INT_ENABLE);
62233db86aabSstevel 		break;
62243db86aabSstevel 	case PCIC_O2_OZ6912:
62253db86aabSstevel 		value = pcic_getb(pcic, 0, PCIC_CENTDMA);
62263db86aabSstevel 		value |= 0x8;
62273db86aabSstevel 		pcic_putb(pcic, 0, PCIC_CENTDMA, value);
62283db86aabSstevel 		break;
62293db86aabSstevel 	case PCIC_CL_PD6832:
62303db86aabSstevel 	case PCIC_TI_PCI1250:
62313db86aabSstevel 	case PCIC_TI_PCI1221:
62323db86aabSstevel 	case PCIC_TI_PCI1225:
62333db86aabSstevel 	case PCIC_TI_PCI1410:
62343db86aabSstevel 	case PCIC_ENE_1410:
62353db86aabSstevel 	case PCIC_TI_PCI1510:
62363db86aabSstevel 	case PCIC_TI_PCI1520:
62373db86aabSstevel 	case PCIC_TI_PCI1420:
62383db86aabSstevel 	case PCIC_ENE_1420:
62393db86aabSstevel 		/* route card functional interrupts to PCI interrupts */
62403db86aabSstevel 		brdgctl = ddi_get16(pcic->cfg_handle,
62413db86aabSstevel 		    (uint16_t *)(pcic->cfgaddr + PCI_CBUS_BRIDGE_CTRL));
62423db86aabSstevel 		pcic_err(NULL, 1,
62433db86aabSstevel 		    "pcic_enable_io_intr brdgctl(0x%x) was: 0x%x\n",
62443db86aabSstevel 		    PCI_CBUS_BRIDGE_CTRL, brdgctl);
62453db86aabSstevel 		brdgctl &= ~PCIC_BRDGCTL_INTR_MASK;
62463db86aabSstevel 		ddi_put16(pcic->cfg_handle,
62473db86aabSstevel 		    (uint16_t *)(pcic->cfgaddr + PCI_CBUS_BRIDGE_CTRL),
62483db86aabSstevel 		    brdgctl);
62493db86aabSstevel 		/* Flush the write */
62503db86aabSstevel 		(void) ddi_get16(pcic->cfg_handle,
62513db86aabSstevel 		    (uint16_t *)(pcic->cfgaddr + PCI_CBUS_BRIDGE_CTRL));
62523db86aabSstevel 		break;
62533db86aabSstevel 	default:
62543db86aabSstevel 		break;
62553db86aabSstevel 	}
62563db86aabSstevel }
62573db86aabSstevel 
62583db86aabSstevel static void
pcic_disable_io_intr(pcicdev_t * pcic,int socket)62593db86aabSstevel pcic_disable_io_intr(pcicdev_t *pcic, int socket)
62603db86aabSstevel {
62613db86aabSstevel 	uint8_t value;
62623db86aabSstevel 	uint16_t brdgctl;
62633db86aabSstevel 
62643db86aabSstevel 	value = pcic_getb(pcic, socket, PCIC_INTERRUPT) & ~PCIC_INTR_MASK;
62653db86aabSstevel 	pcic_putb(pcic, socket, PCIC_INTERRUPT, value);
62663db86aabSstevel 
62673db86aabSstevel 	switch (pcic->pc_type) {
62683db86aabSstevel 	case PCIC_INTEL_i82092:
62693db86aabSstevel 		pcic_82092_smiirq_ctl(pcic, socket, PCIC_82092_CTL_IRQ,
62703db86aabSstevel 		    PCIC_82092_INT_DISABLE);
62713db86aabSstevel 		break;
62723db86aabSstevel 	case PCIC_O2_OZ6912:
62733db86aabSstevel 		value = pcic_getb(pcic, 0, PCIC_CENTDMA);
62743db86aabSstevel 		value &= ~0x8;
62753db86aabSstevel 		pcic_putb(pcic, 0, PCIC_CENTDMA, value);
62763db86aabSstevel 		/* Flush the write */
62773db86aabSstevel 		(void) pcic_getb(pcic, 0, PCIC_CENTDMA);
62783db86aabSstevel 		break;
62793db86aabSstevel 	case PCIC_CL_PD6832:
62803db86aabSstevel 	case PCIC_TI_PCI1250:
62813db86aabSstevel 	case PCIC_TI_PCI1221:
62823db86aabSstevel 	case PCIC_TI_PCI1225:
62833db86aabSstevel 	case PCIC_TI_PCI1410:
62843db86aabSstevel 	case PCIC_ENE_1410:
62853db86aabSstevel 	case PCIC_TI_PCI1510:
62863db86aabSstevel 	case PCIC_TI_PCI1520:
62873db86aabSstevel 	case PCIC_TI_PCI1420:
62883db86aabSstevel 	case PCIC_ENE_1420:
62893db86aabSstevel 		/*
62903db86aabSstevel 		 * This maps I/O interrupts to ExCA which
62913db86aabSstevel 		 * have been turned off by the write to
62923db86aabSstevel 		 * PCIC_INTERRUPT above. It would appear to
62933db86aabSstevel 		 * be the only way to actually turn I/O Ints off
62943db86aabSstevel 		 * while retaining CS Ints.
62953db86aabSstevel 		 */
62963db86aabSstevel 		brdgctl = ddi_get16(pcic->cfg_handle,
62973db86aabSstevel 		    (uint16_t *)(pcic->cfgaddr + PCI_CBUS_BRIDGE_CTRL));
62983db86aabSstevel 		pcic_err(NULL, 1,
62993db86aabSstevel 		    "pcic_disable_io_intr brdgctl(0x%x) was: 0x%x\n",
63003db86aabSstevel 		    PCI_CBUS_BRIDGE_CTRL, brdgctl);
63013db86aabSstevel 		brdgctl |= PCIC_BRDGCTL_INTR_MASK;
63023db86aabSstevel 		ddi_put16(pcic->cfg_handle,
63033db86aabSstevel 		    (uint16_t *)(pcic->cfgaddr + PCI_CBUS_BRIDGE_CTRL),
63043db86aabSstevel 		    brdgctl);
63053db86aabSstevel 		/* Flush the write */
63063db86aabSstevel 		(void) ddi_get16(pcic->cfg_handle,
63073db86aabSstevel 		    (uint16_t *)(pcic->cfgaddr + PCI_CBUS_BRIDGE_CTRL));
63083db86aabSstevel 		break;
63093db86aabSstevel 	default:
63103db86aabSstevel 		break;
63113db86aabSstevel 	}
63123db86aabSstevel }
63133db86aabSstevel 
63143db86aabSstevel static void
pcic_cb_enable_intr(dev_info_t * dip)63153db86aabSstevel pcic_cb_enable_intr(dev_info_t *dip)
63163db86aabSstevel {
63173db86aabSstevel 	anp_t *anp = ddi_get_driver_private(dip);
63183db86aabSstevel 	pcicdev_t *pcic = anp->an_private;
63193db86aabSstevel 
63203db86aabSstevel 	mutex_enter(&pcic->pc_lock);
63213db86aabSstevel 	pcic_enable_io_intr(pcic, 0, pcic->pc_sockets[0].pcs_irq);
63223db86aabSstevel 	mutex_exit(&pcic->pc_lock);
63233db86aabSstevel }
63243db86aabSstevel 
63253db86aabSstevel static void
pcic_cb_disable_intr(dev_info_t * dip)63263db86aabSstevel pcic_cb_disable_intr(dev_info_t *dip)
63273db86aabSstevel {
63283db86aabSstevel 	anp_t *anp = ddi_get_driver_private(dip);
63293db86aabSstevel 	pcicdev_t *pcic = anp->an_private;
63303db86aabSstevel 
63313db86aabSstevel 	mutex_enter(&pcic->pc_lock);
63323db86aabSstevel 	pcic_disable_io_intr(pcic, 0);
63333db86aabSstevel 	mutex_exit(&pcic->pc_lock);
63343db86aabSstevel }
63353db86aabSstevel 
6336*ae5a8bedSAndy Fiddaman #if defined(__sparc)
63373db86aabSstevel static int
log_pci_cfg_err(ushort_t e,int bridge_secondary)63383db86aabSstevel log_pci_cfg_err(ushort_t e, int bridge_secondary)
63393db86aabSstevel {
63403db86aabSstevel 	int	nerr = 0;
63413db86aabSstevel 	if (e & PCI_STAT_PERROR) {
63423db86aabSstevel 		nerr++;
63433db86aabSstevel 		cmn_err(CE_CONT, "detected parity error.\n");
63443db86aabSstevel 	}
63453db86aabSstevel 	if (e & PCI_STAT_S_SYSERR) {
63463db86aabSstevel 		nerr++;
63473db86aabSstevel 		if (bridge_secondary)
63483db86aabSstevel 			cmn_err(CE_CONT, "received system error.\n");
63493db86aabSstevel 		else
63503db86aabSstevel 			cmn_err(CE_CONT, "signalled system error.\n");
63513db86aabSstevel 	}
63523db86aabSstevel 	if (e & PCI_STAT_R_MAST_AB) {
63533db86aabSstevel 		nerr++;
63543db86aabSstevel 		cmn_err(CE_CONT, "received master abort.\n");
63553db86aabSstevel 	}
63563db86aabSstevel 	if (e & PCI_STAT_R_TARG_AB)
63573db86aabSstevel 		cmn_err(CE_CONT, "received target abort.\n");
63583db86aabSstevel 	if (e & PCI_STAT_S_TARG_AB)
63593db86aabSstevel 		cmn_err(CE_CONT, "signalled target abort\n");
63603db86aabSstevel 	if (e & PCI_STAT_S_PERROR) {
63613db86aabSstevel 		nerr++;
63623db86aabSstevel 		cmn_err(CE_CONT, "signalled parity error\n");
63633db86aabSstevel 	}
63643db86aabSstevel 	return (nerr);
63653db86aabSstevel }
63663db86aabSstevel 
63673db86aabSstevel static int
pcic_fault(enum pci_fault_ops op,void * arg)63683db86aabSstevel pcic_fault(enum pci_fault_ops op, void *arg)
63693db86aabSstevel {
63703db86aabSstevel 	pcicdev_t *pcic = (pcicdev_t *)arg;
63713db86aabSstevel 	ushort_t pci_cfg_stat =
63723db86aabSstevel 	    pci_config_get16(pcic->cfg_handle, PCI_CONF_STAT);
63733db86aabSstevel 	ushort_t pci_cfg_sec_stat =
63743db86aabSstevel 	    pci_config_get16(pcic->cfg_handle, 0x16);
63753db86aabSstevel 	char	nm[24];
63763db86aabSstevel 	int	nerr = 0;
63773db86aabSstevel 
63783db86aabSstevel 	cardbus_dump_pci_config(pcic->dip);
63793db86aabSstevel 
63803db86aabSstevel 	switch (op) {
63813db86aabSstevel 	case FAULT_LOG:
63823db86aabSstevel 		(void) sprintf(nm, "%s-%d", ddi_driver_name(pcic->dip),
63833db86aabSstevel 		    ddi_get_instance(pcic->dip));
63843db86aabSstevel 
63853db86aabSstevel 		cmn_err(CE_WARN, "%s: PCIC fault log start:\n", nm);
63863db86aabSstevel 		cmn_err(CE_WARN, "%s: primary err (%x):\n", nm, pci_cfg_stat);
63873db86aabSstevel 		nerr += log_pci_cfg_err(pci_cfg_stat, 0);
63883db86aabSstevel 		cmn_err(CE_WARN, "%s: sec err (%x):\n", nm, pci_cfg_sec_stat);
63893db86aabSstevel 		nerr += log_pci_cfg_err(pci_cfg_sec_stat, 1);
63903db86aabSstevel 		cmn_err(CE_CONT, "%s: PCI fault log end.\n", nm);
63913db86aabSstevel 		return (nerr);
63923db86aabSstevel 	case FAULT_POKEFINI:
63933db86aabSstevel 	case FAULT_RESET:
63943db86aabSstevel 		pci_config_put16(pcic->cfg_handle,
63953db86aabSstevel 		    PCI_CONF_STAT, pci_cfg_stat);
63963db86aabSstevel 		pci_config_put16(pcic->cfg_handle, 0x16, pci_cfg_sec_stat);
63973db86aabSstevel 		break;
63983db86aabSstevel 	case FAULT_POKEFLT:
63993db86aabSstevel 		if (!(pci_cfg_stat & PCI_STAT_S_SYSERR))
64003db86aabSstevel 			return (1);
64013db86aabSstevel 		if (!(pci_cfg_sec_stat & PCI_STAT_R_MAST_AB))
64023db86aabSstevel 			return (1);
64033db86aabSstevel 		break;
64043db86aabSstevel 	default:
64053db86aabSstevel 		break;
64063db86aabSstevel 	}
64073db86aabSstevel 	return (DDI_SUCCESS);
64083db86aabSstevel }
64093db86aabSstevel #endif
64103db86aabSstevel 
64113db86aabSstevel static void
pcic_do_resume(pcicdev_t * pcic)641211c2b4c0Srw pcic_do_resume(pcicdev_t *pcic)
64133db86aabSstevel {
641411c2b4c0Srw 	int	i, interrupt;
641511c2b4c0Srw 	uint8_t cfg;
64163db86aabSstevel 
64173db86aabSstevel 
64183db86aabSstevel #if defined(PCIC_DEBUG)
641911c2b4c0Srw 	pcic_err(NULL, 6, "pcic_do_resume(): entered\n");
64203db86aabSstevel #endif
64213db86aabSstevel 
642211c2b4c0Srw 	pcic_mutex_enter(&pcic->pc_lock); /* protect the registers */
642311c2b4c0Srw 	for (i = 0; i < pcic->pc_numsockets; i++) {
642411c2b4c0Srw 		/* Enable interrupts  on PCI if needs be */
642511c2b4c0Srw 		interrupt = pcic_getb(pcic, i, PCIC_INTERRUPT);
642611c2b4c0Srw 		if (pcic->pc_flags & PCF_USE_SMI)
642711c2b4c0Srw 			interrupt |= PCIC_INTR_ENABLE;
642811c2b4c0Srw 		pcic_putb(pcic, i, PCIC_INTERRUPT,
642911c2b4c0Srw 		    PCIC_RESET | interrupt);
643011c2b4c0Srw 		pcic->pc_sockets[i].pcs_debounce_id =
643111c2b4c0Srw 		    pcic_add_debqueue(&pcic->pc_sockets[i],
643211c2b4c0Srw 		    drv_usectohz(pcic_debounce_time));
643311c2b4c0Srw 	}
643411c2b4c0Srw 	pcic_mutex_exit(&pcic->pc_lock); /* protect the registers */
643511c2b4c0Srw 	if (pcic_do_pcmcia_sr)
643611c2b4c0Srw 		(void) pcmcia_wait_insert(pcic->dip);
643711c2b4c0Srw 	/*
643811c2b4c0Srw 	 * The CardBus controller may be in RESET state after the
643911c2b4c0Srw 	 * system is resumed from sleeping. The RESET bit is in
644011c2b4c0Srw 	 * the Bridge Control register. This is true for all(TI,
644111c2b4c0Srw 	 * Toshiba ToPIC95/97, RICOH, and O2Micro) CardBus
644211c2b4c0Srw 	 * controllers. Need to clear the RESET bit explicitly.
644311c2b4c0Srw 	 */
644411c2b4c0Srw 	cfg = ddi_get8(pcic->cfg_handle,
644519397407SSherry Moore 	    pcic->cfgaddr + PCIC_BRIDGE_CTL_REG);
644611c2b4c0Srw 	if (cfg & (1<<6)) {
644711c2b4c0Srw 		cfg &= ~(1<<6);
644811c2b4c0Srw 		ddi_put8(pcic->cfg_handle,
644919397407SSherry Moore 		    pcic->cfgaddr + PCIC_BRIDGE_CTL_REG,
645019397407SSherry Moore 		    cfg);
645111c2b4c0Srw 		cfg = ddi_get8(pcic->cfg_handle,
645219397407SSherry Moore 		    pcic->cfgaddr + PCIC_BRIDGE_CTL_REG);
645311c2b4c0Srw 		if (cfg & (1<<6)) {
645419397407SSherry Moore 			pcic_err(pcic->dip, 1,
645519397407SSherry Moore 			    "Failed to take pcic out of reset");
64563db86aabSstevel 		}
64573db86aabSstevel 	}
645811c2b4c0Srw 
64593db86aabSstevel }
64603db86aabSstevel 
64613db86aabSstevel static void
pcic_debounce(pcic_socket_t * pcs)64623db86aabSstevel pcic_debounce(pcic_socket_t *pcs)
64633db86aabSstevel {
64643db86aabSstevel 	uint8_t status, stschng;
64653db86aabSstevel 
64663db86aabSstevel 	pcic_mutex_enter(&pcs->pcs_pcic->pc_lock);
64673db86aabSstevel 	pcs->pcs_flags &= ~PCS_STARTING;
64683db86aabSstevel 	stschng = pcic_getb(pcs->pcs_pcic, pcs->pcs_socket,
64693db86aabSstevel 	    PCIC_CARD_STATUS_CHANGE);
64703db86aabSstevel 	status = pcic_getb(pcs->pcs_pcic, pcs->pcs_socket,
64713db86aabSstevel 	    PCIC_INTERFACE_STATUS);
64723db86aabSstevel #ifdef PCIC_DEBUG
64733db86aabSstevel 	pcic_err(pcs->pcs_pcic->dip, 8,
64743db86aabSstevel 	    "pcic_debounce(0x%p, dip=0x%p) socket %d st 0x%x "
64753db86aabSstevel 	    "chg 0x%x flg 0x%x\n",
64763db86aabSstevel 	    (void *)pcs, (void *) pcs->pcs_pcic->dip, pcs->pcs_socket,
64773db86aabSstevel 	    status, stschng, pcs->pcs_flags);
64783db86aabSstevel #endif
64793db86aabSstevel 
64803db86aabSstevel 	pcic_putb(pcs->pcs_pcic, pcs->pcs_socket, PCIC_CARD_STATUS_CHANGE,
64813db86aabSstevel 	    PCIC_CD_DETECT);
64823db86aabSstevel 	pcic_handle_cd_change(pcs->pcs_pcic, pcs, status);
64833db86aabSstevel 	pcic_mutex_exit(&pcs->pcs_pcic->pc_lock);
64843db86aabSstevel }
64853db86aabSstevel 
64863db86aabSstevel static void
pcic_deb_thread()64873db86aabSstevel pcic_deb_thread()
64883db86aabSstevel {
64893db86aabSstevel 	callb_cpr_t cprinfo;
64903db86aabSstevel 	struct debounce *debp;
64913db86aabSstevel 	clock_t lastt;
64923db86aabSstevel 
64933db86aabSstevel 	CALLB_CPR_INIT(&cprinfo, &pcic_deb_mtx,
64943db86aabSstevel 	    callb_generic_cpr, "pcic debounce thread");
64953db86aabSstevel 	mutex_enter(&pcic_deb_mtx);
64963db86aabSstevel 	while (pcic_deb_threadid) {
64973db86aabSstevel 		while (pcic_deb_queue) {
64983db86aabSstevel #ifdef PCIC_DEBUG
64993db86aabSstevel 			pcic_dump_debqueue("Thread");
65003db86aabSstevel #endif
65013db86aabSstevel 			debp = pcic_deb_queue;
65023db86aabSstevel 			(void) drv_getparm(LBOLT, &lastt);
65033db86aabSstevel 			if (lastt >= debp->expire) {
65043db86aabSstevel 				pcic_deb_queue = debp->next;
65053db86aabSstevel 				mutex_exit(&pcic_deb_mtx);
65063db86aabSstevel 				pcic_debounce(debp->pcs);
65073db86aabSstevel 				mutex_enter(&pcic_deb_mtx);
65083db86aabSstevel 				kmem_free(debp, sizeof (*debp));
65093db86aabSstevel 			} else {
65103db86aabSstevel 				(void) cv_timedwait(&pcic_deb_cv,
65113db86aabSstevel 				    &pcic_deb_mtx, debp->expire);
65123db86aabSstevel 			}
65133db86aabSstevel 		}
65143db86aabSstevel 		CALLB_CPR_SAFE_BEGIN(&cprinfo);
65153db86aabSstevel 		cv_wait(&pcic_deb_cv, &pcic_deb_mtx);
65163db86aabSstevel 		CALLB_CPR_SAFE_END(&cprinfo, &pcic_deb_mtx);
65173db86aabSstevel 	}
65183db86aabSstevel 	pcic_deb_threadid = (kthread_t *)1;
65193db86aabSstevel 	cv_signal(&pcic_deb_cv);
65203db86aabSstevel 	CALLB_CPR_EXIT(&cprinfo);	/* Also exits the mutex */
65213db86aabSstevel 	thread_exit();
65223db86aabSstevel }
65233db86aabSstevel 
65243db86aabSstevel static void *
pcic_add_debqueue(pcic_socket_t * pcs,int clocks)65253db86aabSstevel pcic_add_debqueue(pcic_socket_t *pcs, int clocks)
65263db86aabSstevel {
65273db86aabSstevel 	clock_t lbolt;
65283db86aabSstevel 	struct debounce *dbp, **dbpp = &pcic_deb_queue;
65293db86aabSstevel 
65303db86aabSstevel 	(void) drv_getparm(LBOLT, &lbolt);
65318134ee03Srw 	dbp = kmem_alloc(sizeof (struct debounce), KM_SLEEP);
65323db86aabSstevel 
65333db86aabSstevel 	dbp->expire = lbolt + clocks;
65343db86aabSstevel 	dbp->pcs = pcs;
65353db86aabSstevel 	mutex_enter(&pcic_deb_mtx);
65363db86aabSstevel 	while (*dbpp) {
65373db86aabSstevel 		if (dbp->expire > (*dbpp)->expire)
65383db86aabSstevel 			dbpp = &((*dbpp)->next);
65393db86aabSstevel 		else
65403db86aabSstevel 			break;
65413db86aabSstevel 	}
65423db86aabSstevel 	dbp->next = *dbpp;
65433db86aabSstevel 	*dbpp = dbp;
65443db86aabSstevel #ifdef PCIC_DEBUG
65453db86aabSstevel 	pcic_dump_debqueue("Add");
65463db86aabSstevel #endif
65473db86aabSstevel 	cv_signal(&pcic_deb_cv);
65483db86aabSstevel 	mutex_exit(&pcic_deb_mtx);
65493db86aabSstevel 	return (dbp);
65503db86aabSstevel }
65513db86aabSstevel 
65523db86aabSstevel static void
pcic_rm_debqueue(void * id)65533db86aabSstevel pcic_rm_debqueue(void *id)
65543db86aabSstevel {
65553db86aabSstevel 	struct debounce *dbp, **dbpp = &pcic_deb_queue;
65563db86aabSstevel 
65573db86aabSstevel 	dbp = (struct debounce *)id;
65583db86aabSstevel 	mutex_enter(&pcic_deb_mtx);
65593db86aabSstevel 	while (*dbpp) {
65603db86aabSstevel 		if (*dbpp == dbp) {
65613db86aabSstevel 			*dbpp = dbp->next;
65623db86aabSstevel 			kmem_free(dbp, sizeof (*dbp));
65633db86aabSstevel #ifdef PCIC_DEBUG
65643db86aabSstevel 			pcic_dump_debqueue("Remove");
65653db86aabSstevel #endif
65663db86aabSstevel 			cv_signal(&pcic_deb_cv);
65673db86aabSstevel 			mutex_exit(&pcic_deb_mtx);
65683db86aabSstevel 			return;
65693db86aabSstevel 		}
65703db86aabSstevel 		dbpp = &((*dbpp)->next);
65713db86aabSstevel 	}
65723db86aabSstevel 	pcic_err(NULL, 6, "pcic: Failed to find debounce id 0x%p\n", id);
65733db86aabSstevel 	mutex_exit(&pcic_deb_mtx);
65743db86aabSstevel }
65753db86aabSstevel 
65763db86aabSstevel 
65773db86aabSstevel static int	pcic_powerdelay = 0;
65783db86aabSstevel 
65793db86aabSstevel static int
pcic_exca_powerctl(pcicdev_t * pcic,int socket,int powerlevel)65803db86aabSstevel pcic_exca_powerctl(pcicdev_t *pcic, int socket, int powerlevel)
65813db86aabSstevel {
65823db86aabSstevel 	int	ind, value, orig_pwrctl;
65833db86aabSstevel 
65843db86aabSstevel 	/* power setup -- if necessary */
65853db86aabSstevel 	orig_pwrctl = pcic_getb(pcic, socket, PCIC_POWER_CONTROL);
65863db86aabSstevel 
65873db86aabSstevel #if defined(PCIC_DEBUG)
65883db86aabSstevel 	pcic_err(pcic->dip, 6,
65893db86aabSstevel 	    "pcic_exca_powerctl(socket %d) powerlevel=%x orig 0x%x\n",
65903db86aabSstevel 	    socket, powerlevel, orig_pwrctl);
65913db86aabSstevel #endif
65923db86aabSstevel 	/* Preserve the PCIC_OUTPUT_ENABLE (control lines output enable) bit. */
65933db86aabSstevel 	powerlevel = (powerlevel & ~POWER_OUTPUT_ENABLE) |
65943db86aabSstevel 	    (orig_pwrctl & POWER_OUTPUT_ENABLE);
65953db86aabSstevel 	if (powerlevel != orig_pwrctl) {
65963db86aabSstevel 		if (powerlevel & ~POWER_OUTPUT_ENABLE) {
65973db86aabSstevel 			int	ifs;
65983db86aabSstevel 			/*
65993db86aabSstevel 			 * set power to socket
66003db86aabSstevel 			 * note that the powerlevel was calculated earlier
66013db86aabSstevel 			 */
66023db86aabSstevel 			pcic_putb(pcic, socket, PCIC_POWER_CONTROL, powerlevel);
66033db86aabSstevel 			(void) pcic_getb(pcic, socket, PCIC_POWER_CONTROL);
66043db86aabSstevel 
66053db86aabSstevel 			/*
66063db86aabSstevel 			 * this second write to the power control register
66073db86aabSstevel 			 * is needed to resolve a problem on
66083db86aabSstevel 			 * the IBM ThinkPad 750
66093db86aabSstevel 			 * where the first write doesn't latch.
66103db86aabSstevel 			 * The second write appears to always work and
66113db86aabSstevel 			 * doesn't hurt the operation of other chips
66123db86aabSstevel 			 * so we can just use it -- this is good since we can't
66133db86aabSstevel 			 * determine what chip the 750 actually uses
66143db86aabSstevel 			 * (I suspect an early Ricoh).
66153db86aabSstevel 			 */
66163db86aabSstevel 			pcic_putb(pcic, socket, PCIC_POWER_CONTROL, powerlevel);
66173db86aabSstevel 
66183db86aabSstevel 			value = pcic_getb(pcic, socket, PCIC_POWER_CONTROL);
66193db86aabSstevel 			pcic_mswait(pcic, socket, pcic_powerdelay);
66203db86aabSstevel #if defined(PCIC_DEBUG)
66213db86aabSstevel 			pcic_err(pcic->dip, 8,
66223db86aabSstevel 			    "\tpowerlevel reg = %x (ifs %x)\n",
66233db86aabSstevel 			    value, pcic_getb(pcic, socket,
66243db86aabSstevel 			    PCIC_INTERFACE_STATUS));
66253db86aabSstevel 			pcic_err(pcic->dip, 8,
66263db86aabSstevel 			    "CBus regs: PS 0x%x, Control 0x%x\n",
66273db86aabSstevel 			    pcic_getcb(pcic, CB_PRESENT_STATE),
66283db86aabSstevel 			    pcic_getcb(pcic, CB_CONTROL));
66293db86aabSstevel #endif
66303db86aabSstevel 			/*
66313db86aabSstevel 			 * since power was touched, make sure it says it
66323db86aabSstevel 			 * is on.  This lets it become stable.
66333db86aabSstevel 			 */
66343db86aabSstevel 			for (ind = 0; ind < 20; ind++) {
66353db86aabSstevel 				ifs = pcic_getb(pcic, socket,
66363db86aabSstevel 				    PCIC_INTERFACE_STATUS);
66373db86aabSstevel 				if (ifs & PCIC_POWER_ON)
66383db86aabSstevel 					break;
66393db86aabSstevel 				else {
66403db86aabSstevel 					pcic_putb(pcic, socket,
66413db86aabSstevel 					    PCIC_POWER_CONTROL, 0);
66423db86aabSstevel 					(void) pcic_getb(pcic, socket,
66433db86aabSstevel 					    PCIC_POWER_CONTROL);
66443db86aabSstevel 					pcic_mswait(pcic, socket, 40);
66453db86aabSstevel 					if (ind == 10) {
66463db86aabSstevel 						pcic_putcb(pcic, CB_EVENT_FORCE,
66473db86aabSstevel 						    CB_EF_CVTEST);
66483db86aabSstevel 						pcic_mswait(pcic, socket, 100);
66493db86aabSstevel 					}
66503db86aabSstevel 					pcic_putb(pcic, socket,
66513db86aabSstevel 					    PCIC_POWER_CONTROL,
66523db86aabSstevel 					    powerlevel & ~POWER_OUTPUT_ENABLE);
66533db86aabSstevel 					(void) pcic_getb(pcic, socket,
66543db86aabSstevel 					    PCIC_POWER_CONTROL);
66553db86aabSstevel 					pcic_mswait(pcic, socket,
66563db86aabSstevel 					    pcic_powerdelay);
66573db86aabSstevel 					pcic_putb(pcic, socket,
66583db86aabSstevel 					    PCIC_POWER_CONTROL, powerlevel);
66593db86aabSstevel 					(void) pcic_getb(pcic, socket,
66603db86aabSstevel 					    PCIC_POWER_CONTROL);
66613db86aabSstevel 					pcic_mswait(pcic, socket,
66623db86aabSstevel 					    pcic_powerdelay);
66633db86aabSstevel 				}
66643db86aabSstevel 			}
66653db86aabSstevel 
66663db86aabSstevel 			if (!(ifs & PCIC_POWER_ON)) {
66673db86aabSstevel 				cmn_err(CE_WARN,
66683db86aabSstevel 				    "pcic socket %d: Power didn't get turned"
66693db86aabSstevel 				    "on!\nif status 0x%x pwrc 0x%x(x%x) "
66703db86aabSstevel 				    "misc1 0x%x igc 0x%x ind %d\n",
66713db86aabSstevel 				    socket, ifs,
66723db86aabSstevel 				    pcic_getb(pcic, socket, PCIC_POWER_CONTROL),
66733db86aabSstevel 				    orig_pwrctl,
66743db86aabSstevel 				    pcic_getb(pcic, socket, PCIC_MISC_CTL_1),
66753db86aabSstevel 				    pcic_getb(pcic, socket, PCIC_INTERRUPT),
66763db86aabSstevel 				    ind);
66773db86aabSstevel 				return (BAD_VCC);
66783db86aabSstevel 			}
66793db86aabSstevel #if defined(PCIC_DEBUG)
66803db86aabSstevel 			pcic_err(pcic->dip, 8,
66813db86aabSstevel 			    "\tind = %d, if status %x pwrc 0x%x "
66823db86aabSstevel 			    "misc1 0x%x igc 0x%x\n",
66833db86aabSstevel 			    ind, ifs,
66843db86aabSstevel 			    pcic_getb(pcic, socket, PCIC_POWER_CONTROL),
66853db86aabSstevel 			    pcic_getb(pcic, socket, PCIC_MISC_CTL_1),
66863db86aabSstevel 			    pcic_getb(pcic, socket, PCIC_INTERRUPT));
66873db86aabSstevel #endif
66883db86aabSstevel 		} else {
66893db86aabSstevel 			/* explicitly turned off the power */
66903db86aabSstevel 			pcic_putb(pcic, socket, PCIC_POWER_CONTROL, powerlevel);
66913db86aabSstevel 			(void) pcic_getb(pcic, socket, PCIC_POWER_CONTROL);
66923db86aabSstevel 		}
66933db86aabSstevel 	}
66943db86aabSstevel 	return (SUCCESS);
66953db86aabSstevel }
66963db86aabSstevel 
66973db86aabSstevel static int pcic_cbdoreset_during_poweron = 1;
66983db86aabSstevel static int
pcic_cbus_powerctl(pcicdev_t * pcic,int socket)66993db86aabSstevel pcic_cbus_powerctl(pcicdev_t *pcic, int socket)
67003db86aabSstevel {
67013db86aabSstevel 	uint32_t cbctl = 0, orig_cbctl, cbstev, cbps;
67023db86aabSstevel 	int ind, iobits;
67033db86aabSstevel 	pcic_socket_t *sockp = &pcic->pc_sockets[socket];
67043db86aabSstevel 
67053db86aabSstevel 	pcic_putcb(pcic, CB_STATUS_EVENT, CB_SE_POWER_CYCLE);
67063db86aabSstevel 
67073db86aabSstevel 	ind = pcic_power[sockp->pcs_vpp1].PowerLevel/10;
67083db86aabSstevel 	cbctl |= pcic_cbv_levels[ind];
67093db86aabSstevel 
67103db86aabSstevel 	ind = pcic_power[sockp->pcs_vcc].PowerLevel/10;
67113db86aabSstevel 	cbctl |= (pcic_cbv_levels[ind]<<4);
67123db86aabSstevel 
67133db86aabSstevel 	orig_cbctl = pcic_getcb(pcic, CB_CONTROL);
67143db86aabSstevel 
67153db86aabSstevel #if defined(PCIC_DEBUG)
67163db86aabSstevel 	pcic_err(pcic->dip, 6,
67173db86aabSstevel 	    "pcic_cbus_powerctl(socket %d) vcc %d vpp1 %d "
67183db86aabSstevel 	    "cbctl 0x%x->0x%x\n",
67193db86aabSstevel 	    socket, sockp->pcs_vcc, sockp->pcs_vpp1, orig_cbctl, cbctl);
67203db86aabSstevel #endif
67213db86aabSstevel 	if (cbctl != orig_cbctl) {
672219397407SSherry Moore 		if (pcic_cbdoreset_during_poweron &&
672319397407SSherry Moore 		    (orig_cbctl & (CB_C_VCCMASK|CB_C_VPPMASK)) == 0) {
672419397407SSherry Moore 			iobits = pcic_getb(pcic, socket, PCIC_INTERRUPT);
672519397407SSherry Moore 			pcic_putb(pcic, socket, PCIC_INTERRUPT,
672619397407SSherry Moore 			    iobits & ~PCIC_RESET);
672719397407SSherry Moore 		}
672819397407SSherry Moore 		pcic_putcb(pcic, CB_CONTROL, cbctl);
672919397407SSherry Moore 
673019397407SSherry Moore 		if ((cbctl & CB_C_VCCMASK) == (orig_cbctl & CB_C_VCCMASK)) {
67313db86aabSstevel 		pcic_mswait(pcic, socket, pcic_powerdelay);
67323db86aabSstevel 		return (SUCCESS);
673319397407SSherry Moore 		}
673419397407SSherry Moore 		for (ind = 0; ind < 20; ind++) {
67353db86aabSstevel 		cbstev = pcic_getcb(pcic, CB_STATUS_EVENT);
67363db86aabSstevel 
67373db86aabSstevel 		if (cbstev & CB_SE_POWER_CYCLE) {
67383db86aabSstevel 
67393db86aabSstevel 		/*
67403db86aabSstevel 		 * delay 400 ms: though the standard defines that the Vcc
67413db86aabSstevel 		 * set-up time is 20 ms, some PC-Card bridge requires longer
67423db86aabSstevel 		 * duration.
67433db86aabSstevel 		 * Note: We should check the status AFTER the delay to give time
67443db86aabSstevel 		 * for things to stabilize.
67453db86aabSstevel 		 */
674619397407SSherry Moore 			pcic_mswait(pcic, socket, 400);
67473db86aabSstevel 
674819397407SSherry Moore 			cbps = pcic_getcb(pcic, CB_PRESENT_STATE);
674919397407SSherry Moore 			if (cbctl && !(cbps & CB_PS_POWER_CYCLE)) {
67503db86aabSstevel 			/* break; */
67513db86aabSstevel 			cmn_err(CE_WARN, "cbus_powerctl: power off??\n");
675219397407SSherry Moore 			}
675319397407SSherry Moore 			if (cbctl & CB_PS_BADVCC) {
67543db86aabSstevel 			cmn_err(CE_WARN, "cbus_powerctl: bad power request\n");
67553db86aabSstevel 			break;
675619397407SSherry Moore 			}
67573db86aabSstevel 
67583db86aabSstevel #if defined(PCIC_DEBUG)
675919397407SSherry Moore 			pcic_err(pcic->dip, 8,
676019397407SSherry Moore 			    "cbstev = 0x%x cbps = 0x%x cbctl 0x%x(0x%x)",
676119397407SSherry Moore 			    cbstev, pcic_getcb(pcic, CB_PRESENT_STATE),
676219397407SSherry Moore 			    cbctl, orig_cbctl);
67633db86aabSstevel #endif
676419397407SSherry Moore 			if (pcic_cbdoreset_during_poweron &&
676519397407SSherry Moore 			    (orig_cbctl & (CB_C_VCCMASK|CB_C_VPPMASK)) == 0) {
676619397407SSherry Moore 				pcic_putb(pcic, socket, PCIC_INTERRUPT, iobits);
676719397407SSherry Moore 			}
676819397407SSherry Moore 			return (SUCCESS);
67693db86aabSstevel 		}
67703db86aabSstevel 		pcic_mswait(pcic, socket, 40);
677119397407SSherry Moore 		}
677219397407SSherry Moore 		if (pcic_cbdoreset_during_poweron &&
677319397407SSherry Moore 		    (orig_cbctl & (CB_C_VCCMASK|CB_C_VPPMASK)) == 0) {
677419397407SSherry Moore 			pcic_putb(pcic, socket, PCIC_INTERRUPT, iobits);
677519397407SSherry Moore 		}
677619397407SSherry Moore 		cmn_err(CE_WARN,
67773db86aabSstevel 		    "pcic socket %d: Power didn't get turned on/off!\n"
67783db86aabSstevel 		    "cbstev = 0x%x cbps = 0x%x cbctl 0x%x(0x%x) "
67793db86aabSstevel 		    "vcc %d vpp1 %d", socket, cbstev,
67803db86aabSstevel 		    pcic_getcb(pcic, CB_PRESENT_STATE),
67813db86aabSstevel 		    cbctl, orig_cbctl, sockp->pcs_vcc, sockp->pcs_vpp1);
678219397407SSherry Moore 		return (BAD_VCC);
67833db86aabSstevel 	}
67843db86aabSstevel 	return (SUCCESS);
67853db86aabSstevel }
67863db86aabSstevel 
67873db86aabSstevel static int	pcic_do_pprintf = 0;
67883db86aabSstevel 
6789*ae5a8bedSAndy Fiddaman #ifdef PCIC_DEBUG
67903db86aabSstevel static void
pcic_dump_debqueue(char * msg)67913db86aabSstevel pcic_dump_debqueue(char *msg)
67923db86aabSstevel {
67933db86aabSstevel 	struct debounce *debp = pcic_deb_queue;
67943db86aabSstevel 	clock_t lbolt;
67953db86aabSstevel 
67963db86aabSstevel 	(void) drv_getparm(LBOLT, &lbolt);
67973db86aabSstevel 	pcic_err(NULL, 6, debp ? "pcic debounce list (%s) lbolt 0x%x:\n" :
67983db86aabSstevel 	    "pcic debounce_list (%s) EMPTY lbolt 0x%x\n", msg, lbolt);
67993db86aabSstevel 	while (debp) {
68003db86aabSstevel 		pcic_err(NULL, 6, "%p: exp 0x%x next 0x%p id 0x%p\n",
68013db86aabSstevel 		    (void *) debp, (int)debp->expire, (void *) debp->next,
68023db86aabSstevel 		    debp->pcs->pcs_debounce_id);
68033db86aabSstevel 		debp = debp->next;
68043db86aabSstevel 	}
68053db86aabSstevel }
6806*ae5a8bedSAndy Fiddaman #endif /* PCIC_DEBUG */
68073db86aabSstevel 
68083db86aabSstevel 
68093db86aabSstevel /* PRINTFLIKE3 */
68103db86aabSstevel static void
pcic_err(dev_info_t * dip,int level,const char * fmt,...)68113db86aabSstevel pcic_err(dev_info_t *dip, int level, const char *fmt, ...)
68123db86aabSstevel {
68133db86aabSstevel 	if (pcic_debug && (level <= pcic_debug)) {
68143db86aabSstevel 		va_list adx;
68153db86aabSstevel 		int	instance;
68163db86aabSstevel 		char	buf[256];
68173db86aabSstevel 		const char	*name;
68183db86aabSstevel #if !defined(PCIC_DEBUG)
68193db86aabSstevel 		int	ce;
68203db86aabSstevel 		char	qmark = 0;
68213db86aabSstevel 
68223db86aabSstevel 		if (level <= 3)
68233db86aabSstevel 			ce = CE_WARN;
68243db86aabSstevel 		else
68253db86aabSstevel 			ce = CE_CONT;
68263db86aabSstevel 		if (level == 4)
68273db86aabSstevel 			qmark = 1;
68283db86aabSstevel #endif
68293db86aabSstevel 
68303db86aabSstevel 		if (dip) {
68313db86aabSstevel 			instance = ddi_get_instance(dip);
68323db86aabSstevel 			/* name = ddi_binding_name(dip); */
68333db86aabSstevel 			name = ddi_driver_name(dip);
68343db86aabSstevel 		} else {
68353db86aabSstevel 			instance = 0;
68363db86aabSstevel 			name = "";
68373db86aabSstevel 		}
68383db86aabSstevel 
68393db86aabSstevel 		va_start(adx, fmt);
68403db86aabSstevel 		(void) vsprintf(buf, fmt, adx);
68413db86aabSstevel 		va_end(adx);
68423db86aabSstevel 
68433db86aabSstevel #if defined(PCIC_DEBUG)
68443db86aabSstevel 		if (pcic_do_pprintf) {
68453db86aabSstevel 			if (dip) {
68463db86aabSstevel 				if (instance >= 0)
68473db86aabSstevel 					prom_printf("%s(%d),0x%p: %s", name,
6848903a11ebSrh 					    instance, (void *)dip, buf);
68493db86aabSstevel 				else
68503db86aabSstevel 					prom_printf("%s,0x%p: %s",
6851903a11ebSrh 					    name, (void *)dip, buf);
68523db86aabSstevel 			} else
68533db86aabSstevel 				prom_printf(buf);
68543db86aabSstevel 		} else {
68553db86aabSstevel 			if (dip) {
68563db86aabSstevel 				if (instance >= 0)
68573db86aabSstevel 					cmn_err(CE_CONT, "%s(%d),0x%p: %s",
68583db86aabSstevel 					    name, instance, (void *) dip, buf);
68593db86aabSstevel 				else
68603db86aabSstevel 					cmn_err(CE_CONT, "%s,0x%p: %s",
68613db86aabSstevel 					    name, (void *) dip, buf);
68623db86aabSstevel 			} else
68633db86aabSstevel 				cmn_err(CE_CONT, buf);
68643db86aabSstevel 		}
68653db86aabSstevel #else
68663db86aabSstevel 		if (dip)
68673db86aabSstevel 			cmn_err(ce, qmark ? "?%s%d: %s" : "%s%d: %s", name,
68683db86aabSstevel 			    instance, buf);
68693db86aabSstevel 		else
68703db86aabSstevel 			cmn_err(ce, qmark ? "?%s" : buf, buf);
68713db86aabSstevel #endif
68723db86aabSstevel 	}
68733db86aabSstevel }
6874