xref: /onnv-gate/usr/src/uts/common/pcmcia/pcs/pcs.c (revision 7656:2621e50fdf4a)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57151Srw148561  * Common Development and Distribution License (the "License").
67151Srw148561  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
227151Srw148561  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #include <sys/types.h>
280Sstevel@tonic-gate #include <sys/byteorder.h>
290Sstevel@tonic-gate #include <sys/systm.h>
300Sstevel@tonic-gate #include <sys/ddi.h>
310Sstevel@tonic-gate #include <sys/sunddi.h>
320Sstevel@tonic-gate 
330Sstevel@tonic-gate int pcs_getinfo(dev_info_t *, ddi_info_cmd_t, void *, void **);
340Sstevel@tonic-gate int pcs_attach(dev_info_t *, ddi_attach_cmd_t);
350Sstevel@tonic-gate int pcs_detach(dev_info_t *, ddi_detach_cmd_t);
360Sstevel@tonic-gate dev_info_t *pcs_dip;
370Sstevel@tonic-gate 
380Sstevel@tonic-gate static struct dev_ops pcs_devops = {
390Sstevel@tonic-gate 	DEVO_REV,
400Sstevel@tonic-gate 	0,
410Sstevel@tonic-gate 	pcs_getinfo,
420Sstevel@tonic-gate 	nulldev,
430Sstevel@tonic-gate 	nulldev,
440Sstevel@tonic-gate 	pcs_attach,
450Sstevel@tonic-gate 	pcs_detach,
460Sstevel@tonic-gate 	nulldev,
470Sstevel@tonic-gate 	NULL,
48*7656SSherry.Moore@Sun.COM 	NULL,
49*7656SSherry.Moore@Sun.COM 	NULL,
50*7656SSherry.Moore@Sun.COM 	ddi_quiesce_not_needed,		/* quiesce */
510Sstevel@tonic-gate };
520Sstevel@tonic-gate /*
530Sstevel@tonic-gate  * This is the loadable module wrapper.
540Sstevel@tonic-gate  */
550Sstevel@tonic-gate #include <sys/modctl.h>
560Sstevel@tonic-gate 
570Sstevel@tonic-gate extern struct mod_ops mod_driverops;
580Sstevel@tonic-gate 
590Sstevel@tonic-gate static struct modldrv modldrv = {
600Sstevel@tonic-gate 	&mod_driverops,		/* Type of module. This one is a driver */
61*7656SSherry.Moore@Sun.COM 	"PCMCIA Socket Driver",	/* Name of the module. */
620Sstevel@tonic-gate 	&pcs_devops,		/* driver ops */
630Sstevel@tonic-gate };
640Sstevel@tonic-gate 
650Sstevel@tonic-gate static struct modlinkage modlinkage = {
660Sstevel@tonic-gate 	MODREV_1, (void *)&modldrv, NULL
670Sstevel@tonic-gate };
680Sstevel@tonic-gate 
690Sstevel@tonic-gate struct pcs_inst {
700Sstevel@tonic-gate 	dev_info_t *dip;
710Sstevel@tonic-gate } *pcs_instances;
720Sstevel@tonic-gate 
730Sstevel@tonic-gate int
_init()740Sstevel@tonic-gate _init()
750Sstevel@tonic-gate {
760Sstevel@tonic-gate 	int ret;
770Sstevel@tonic-gate 	if ((ret = ddi_soft_state_init((void **)&pcs_instances,
78*7656SSherry.Moore@Sun.COM 	    sizeof (struct pcs_inst), 1)) != 0)
790Sstevel@tonic-gate 		return (ret);
800Sstevel@tonic-gate 	if ((ret = mod_install(&modlinkage)) != 0) {
810Sstevel@tonic-gate 		ddi_soft_state_fini((void **)&pcs_instances);
820Sstevel@tonic-gate 	}
830Sstevel@tonic-gate 	return (ret);
840Sstevel@tonic-gate }
850Sstevel@tonic-gate 
860Sstevel@tonic-gate int
_fini()870Sstevel@tonic-gate _fini()
880Sstevel@tonic-gate {
890Sstevel@tonic-gate 	int ret;
900Sstevel@tonic-gate 	ret = mod_remove(&modlinkage);
910Sstevel@tonic-gate 	if (ret == 0) {
920Sstevel@tonic-gate 		ddi_soft_state_fini((void **)&pcs_instances);
930Sstevel@tonic-gate 	}
940Sstevel@tonic-gate 	return (ret);
950Sstevel@tonic-gate }
960Sstevel@tonic-gate 
970Sstevel@tonic-gate int
_info(struct modinfo * modinfop)980Sstevel@tonic-gate _info(struct modinfo *modinfop)
990Sstevel@tonic-gate {
1000Sstevel@tonic-gate 	return (mod_info(&modlinkage, modinfop));
1010Sstevel@tonic-gate }
1020Sstevel@tonic-gate 
1030Sstevel@tonic-gate int
pcs_getinfo(dev_info_t * dip,ddi_info_cmd_t cmd,void * arg,void ** result)1040Sstevel@tonic-gate pcs_getinfo(dev_info_t *dip, ddi_info_cmd_t cmd, void *arg, void **result)
1050Sstevel@tonic-gate {
1060Sstevel@tonic-gate 	int error = DDI_SUCCESS;
1070Sstevel@tonic-gate 	int inum;
1080Sstevel@tonic-gate 	struct pcs_inst *inst;
1090Sstevel@tonic-gate #ifdef lint
1100Sstevel@tonic-gate 	dip = dip;
1110Sstevel@tonic-gate #endif
1120Sstevel@tonic-gate 
1130Sstevel@tonic-gate 	switch (cmd) {
1140Sstevel@tonic-gate 	case DDI_INFO_DEVT2DEVINFO:
1150Sstevel@tonic-gate 		inum = getminor((dev_t)arg);
1160Sstevel@tonic-gate 		inst = (struct pcs_inst *)ddi_get_soft_state(pcs_instances,
117*7656SSherry.Moore@Sun.COM 		    inum);
1180Sstevel@tonic-gate 		if (inst == NULL)
1190Sstevel@tonic-gate 			error = DDI_FAILURE;
1200Sstevel@tonic-gate 		else
1210Sstevel@tonic-gate 			*result = inst->dip;
1220Sstevel@tonic-gate 		break;
1230Sstevel@tonic-gate 	case DDI_INFO_DEVT2INSTANCE:
1240Sstevel@tonic-gate 		inum = getminor((dev_t)arg);
1250Sstevel@tonic-gate 		inst = (struct pcs_inst *)ddi_get_soft_state(pcs_instances,
126*7656SSherry.Moore@Sun.COM 		    inum);
1270Sstevel@tonic-gate 		if (inst == NULL)
1280Sstevel@tonic-gate 			error = DDI_FAILURE;
1290Sstevel@tonic-gate 		else
1300Sstevel@tonic-gate 			*result = (void *)(uintptr_t)inum;
1310Sstevel@tonic-gate 		break;
1320Sstevel@tonic-gate 	default:
1330Sstevel@tonic-gate 		error = DDI_FAILURE;
1340Sstevel@tonic-gate 	}
1350Sstevel@tonic-gate 	return (error);
1360Sstevel@tonic-gate }
1370Sstevel@tonic-gate 
1380Sstevel@tonic-gate int
pcs_attach(dev_info_t * dip,ddi_attach_cmd_t cmd)1390Sstevel@tonic-gate pcs_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
1400Sstevel@tonic-gate {
1410Sstevel@tonic-gate 	int ret = DDI_SUCCESS;
1420Sstevel@tonic-gate 	int inum;
1430Sstevel@tonic-gate 	struct pcs_inst *inst;
1447151Srw148561 
1457151Srw148561 	switch (cmd) {
1467151Srw148561 	case DDI_RESUME:
1477151Srw148561 		return (DDI_SUCCESS);
1487151Srw148561 	case DDI_ATTACH:
1497151Srw148561 		break;
1507151Srw148561 	default:
1517151Srw148561 		return (DDI_FAILURE);
1527151Srw148561 	}
1530Sstevel@tonic-gate 
1540Sstevel@tonic-gate 	inum = ddi_get_instance(dip);
1550Sstevel@tonic-gate 
1560Sstevel@tonic-gate 	if (ddi_soft_state_zalloc(pcs_instances, inum) == DDI_SUCCESS) {
1570Sstevel@tonic-gate 		inst = (struct pcs_inst *)ddi_get_soft_state(pcs_instances,
158*7656SSherry.Moore@Sun.COM 		    inum);
1590Sstevel@tonic-gate 		if (inst == NULL)
1600Sstevel@tonic-gate 			ret = DDI_FAILURE;
1610Sstevel@tonic-gate 		else
1620Sstevel@tonic-gate 			inst->dip = dip;
1630Sstevel@tonic-gate 	}
1640Sstevel@tonic-gate 
1650Sstevel@tonic-gate 	return (ret);
1660Sstevel@tonic-gate }
1670Sstevel@tonic-gate 
1680Sstevel@tonic-gate int
pcs_detach(dev_info_t * dip,ddi_detach_cmd_t cmd)1690Sstevel@tonic-gate pcs_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
1700Sstevel@tonic-gate {
1717151Srw148561 	switch (cmd) {
1727151Srw148561 	case DDI_DETACH:
1730Sstevel@tonic-gate 		ddi_soft_state_free(pcs_instances, ddi_get_instance(dip));
1740Sstevel@tonic-gate 		return (DDI_SUCCESS);
1757151Srw148561 
1767151Srw148561 	case DDI_SUSPEND:
1777151Srw148561 	case DDI_PM_SUSPEND:
1787151Srw148561 		return (DDI_SUCCESS);
1797151Srw148561 	default:
1807151Srw148561 		break;
1810Sstevel@tonic-gate 	}
1820Sstevel@tonic-gate 	return (DDI_FAILURE);
1830Sstevel@tonic-gate }
184