Merge remote-tracking branch 'origin/master'
[unleashed/lotheac.git] / usr / src / uts / common / io / 1394 / adapters / hci1394_misc.c
blobfe15e8868e94d12156c415a373a71400303b87e4
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright (c) 1999-2000 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * hci1394_misc.c
31 * Misc. HBA functions. These include getinfo, open, close, shutdown, and
32 * overall driver state control functions.
35 #include <sys/conf.h>
36 #include <sys/ddi.h>
37 #include <sys/modctl.h>
38 #include <sys/sunddi.h>
39 #include <sys/types.h>
40 #include <sys/mkdev.h>
42 #include <sys/1394/adapters/hci1394.h>
43 #include <sys/1394/adapters/hci1394_extern.h>
47 /* ARGSUSED */
48 int
49 hci1394_getinfo(dev_info_t *dip, ddi_info_cmd_t cmd, void *arg, void **result)
51 dev_t dev;
52 hci1394_state_t *soft_state;
53 minor_t instance;
54 int status;
56 switch (cmd) {
57 case DDI_INFO_DEVT2DEVINFO:
58 dev = (dev_t)arg;
59 instance = getminor(dev);
60 soft_state = ddi_get_soft_state(hci1394_statep, instance);
61 if (soft_state == NULL) {
62 return (DDI_FAILURE);
64 *result = (void *)soft_state->drvinfo.di_dip;
65 status = DDI_SUCCESS;
66 break;
68 case DDI_INFO_DEVT2INSTANCE:
69 dev = (dev_t)arg;
70 instance = getminor(dev);
71 *result = (void *)(uintptr_t)instance;
72 status = DDI_SUCCESS;
73 break;
75 default:
76 status = DDI_FAILURE;
79 return (status);
83 /* ARGSUSED */
84 int
85 hci1394_open(dev_t *devp, int flag, int otyp, cred_t *credp)
87 hci1394_state_t *soft_state;
89 soft_state = ddi_get_soft_state(hci1394_statep, getminor(*devp));
90 if (soft_state == NULL) {
91 return (ENXIO);
94 return (0);
98 /* ARGSUSED */
99 int
100 hci1394_close(dev_t dev, int flag, int otyp, cred_t *credp)
102 return (0);
107 * hci1394_shutdown()
108 * Shutdown the HW. Something bad that we cannot recover from happened.
110 void
111 hci1394_shutdown(dev_info_t *dip)
113 hci1394_state_t *soft_state;
117 * In the debug version of the driver, we want to do an assert here so
118 * that we don't reset the hardware and can look and see what happened
119 * to cause the shutdown.
121 #ifndef TEST_SHUTDOWN
122 ASSERT(0);
123 #endif
125 soft_state = ddi_get_soft_state(hci1394_statep, ddi_get_instance(dip));
126 if (soft_state == NULL) {
127 return;
131 * Don't allow the HW to generate any more interrupts. Make sure we
132 * disable interrupts before setting the driver state to shutdown.
134 hci1394_ohci_intr_master_disable(soft_state->ohci);
136 /* don't accept anymore commands from services layer */
137 (void) hci1394_state_set(&soft_state->drvinfo, HCI1394_SHUTDOWN);
139 /* Reset the OHCI HW */
140 (void) hci1394_ohci_soft_reset(soft_state->ohci);
142 /* Flush out async DMA Q's (cancels pendingQ timeouts too) */
143 hci1394_async_flush(soft_state->async);
148 * hci1394_state()
149 * returns the current state of the driver
151 hci1394_statevar_t
152 hci1394_state(hci1394_drvinfo_t *drvinfo)
154 hci1394_statevar_t hal_state;
156 mutex_enter(&drvinfo->di_drvstate.ds_mutex);
157 hal_state = drvinfo->di_drvstate.ds_state;
158 mutex_exit(&drvinfo->di_drvstate.ds_mutex);
160 return (hal_state);
165 * hci1394_state_set()
166 * Set the current state of the driver. This routine will return failure
167 * if the driver state is currently set to HCI1394_SHUTDOWN. We do not
168 * allow a transition out of shutdown.
171 hci1394_state_set(hci1394_drvinfo_t *drvinfo, hci1394_statevar_t state)
173 mutex_enter(&drvinfo->di_drvstate.ds_mutex);
175 /* Do not allow a transition out of shutdown */
176 if (drvinfo->di_drvstate.ds_state == HCI1394_SHUTDOWN) {
177 mutex_exit(&drvinfo->di_drvstate.ds_mutex);
178 return (DDI_FAILURE);
181 drvinfo->di_drvstate.ds_state = state;
182 mutex_exit(&drvinfo->di_drvstate.ds_mutex);
184 return (DDI_SUCCESS);