4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
27 * USBA: Solaris USB Architecture support
31 #define USBA_FRAMEWORK
32 #include <sys/usb/usba.h>
33 #include <sys/usb/usba/hcdi.h>
34 #include <sys/usb/usba/genconsole.h>
35 #include <sys/usb/usba/usba_types.h>
36 #include <sys/usb/usba/usba_impl.h>
39 * Initialize USB polled support. This routine calls down to the lower
40 * layers to initialize any state information.
43 usb_console_input_init(dev_info_t
*dip
,
44 usb_pipe_handle_t pipe_handle
,
46 usb_console_info_t
*console_input_info
)
49 usba_device_t
*usba_device
;
50 usba_pipe_handle_data_t
*ph_data
;
51 usb_console_info_impl_t
*usb_console_input
;
55 return (USB_INVALID_ARGS
);
58 if (DEVI_IS_DEVICE_REMOVED(dip
)) {
63 usb_console_input
= kmem_zalloc(
64 sizeof (struct usb_console_info_impl
), KM_SLEEP
);
69 usb_console_input
->uci_dip
= dip
;
72 * Translate the dip into a device.
74 usba_device
= usba_get_usba_device(dip
);
77 * Get ph_data from pipe handle and hold the data
79 if ((ph_data
= usba_hold_ph_data(pipe_handle
)) == NULL
) {
80 kmem_free(usb_console_input
,
81 sizeof (struct usb_console_info_impl
));
83 return (USB_INVALID_PIPE
);
87 * Call the lower layer to initialize any state information
89 ret
= usba_device
->usb_hcdi_ops
->usba_hcdi_console_input_init(
90 ph_data
, state_buf
, usb_console_input
);
92 if (ret
!= USB_SUCCESS
) {
93 kmem_free(usb_console_input
,
94 sizeof (struct usb_console_info_impl
));
96 *console_input_info
= (usb_console_info_t
)usb_console_input
;
99 usba_release_ph_data((usba_ph_impl_t
*)pipe_handle
);
106 * Free up any resources that we allocated in the above initialization
110 usb_console_input_fini(usb_console_info_t console_input_info
)
112 usb_console_info_impl_t
*usb_console_input
;
113 usba_device_t
*usba_device
;
116 usb_console_input
= (usb_console_info_impl_t
*)console_input_info
;
119 * Translate the dip into a device.
121 usba_device
= usba_get_usba_device(usb_console_input
->uci_dip
);
124 * Call the lower layer to free any state information.
126 ret
= usba_device
->usb_hcdi_ops
->usba_hcdi_console_input_fini(
129 if (ret
== USB_FAILURE
) {
135 * We won't be needing this information anymore.
137 kmem_free(usb_console_input
, sizeof (struct usb_console_info_impl
));
139 return (USB_SUCCESS
);
144 * This is the routine that OBP calls to save the USB state information
145 * before using the USB keyboard as an input device. This routine,
146 * and all of the routines that it calls, are responsible for saving
147 * any state information so that it can be restored when OBP mode is
148 * over. At this layer, this code is mainly just a pass through.
150 * Warning: this code runs in polled mode.
153 usb_console_input_enter(usb_console_info_t console_input_info
)
155 usba_device_t
*usba_device
;
156 usb_console_info_impl_t
*usb_console_input
;
158 usb_console_input
= (usb_console_info_impl_t
*)console_input_info
;
161 * Translate the dip into a device.
162 * Do this by directly looking at the dip, do not call
163 * usba_get_usba_device() because this function calls into the DDI.
164 * The ddi then tries to acquire a mutex and the machine hard hangs.
166 usba_device
= usba_polled_get_usba_device(usb_console_input
->uci_dip
);
169 * Call the lower layer to save state information.
171 usba_device
->usb_hcdi_ops
->usba_hcdi_console_input_enter(
174 return (USB_SUCCESS
);
179 * This is the routine that OBP calls when it wants to read a character.
180 * We will call to the lower layers to see if there is any input data
181 * available. At this layer, this code is mainly just a pass through.
183 * Warning: This code runs in polled mode.
186 usb_console_read(usb_console_info_t console_input_info
, uint_t
*num_characters
)
188 usba_device_t
*usba_device
;
189 usb_console_info_impl_t
*usb_console_input
;
191 usb_console_input
= (usb_console_info_impl_t
*)console_input_info
;
194 * Translate the dip into a device.
195 * Do this by directly looking at the dip, do not call
196 * usba_get_usba_device() because this function calls into the DDI.
197 * The ddi then tries to acquire a mutex and the machine hard hangs.
199 usba_device
= usba_polled_get_usba_device(usb_console_input
->uci_dip
);
202 * Call the lower layer to get a a character. Return the number
203 * of characters read into the buffer.
205 return (usba_device
->usb_hcdi_ops
->usba_hcdi_console_read(
206 usb_console_input
, num_characters
));
211 * This is the routine that OBP calls when it is giving up control of the
212 * USB keyboard. This routine, and the lower layer routines that it calls,
213 * are responsible for restoring the controller state to the state it was
214 * in before OBP took control. At this layer, this code is mainly just a
217 * Warning: This code runs in polled mode.
220 usb_console_input_exit(usb_console_info_t console_input_info
)
222 usba_device_t
*usba_device
;
223 usb_console_info_impl_t
*usb_console_input
;
225 usb_console_input
= (usb_console_info_impl_t
*)console_input_info
;
228 * Translate the dip into a device.
229 * Do this by directly looking at the dip, do not call
230 * usba_get_usba_device() because this function calls into the DDI.
231 * The ddi then tries to acquire a mutex and the machine hard hangs.
233 usba_device
= usba_polled_get_usba_device(usb_console_input
->uci_dip
);
236 * Restore the state information.
238 usba_device
->usb_hcdi_ops
->usba_hcdi_console_input_exit(
241 return (USB_SUCCESS
);
245 * Initialize USB OBP support. This routine calls down to the lower
246 * layers to initialize any state information.
249 usb_console_output_init(
251 usb_pipe_handle_t pipe_handle
,
252 usb_console_info_t
*console_output_info
)
254 usba_device_t
*usb_device
;
255 usb_console_info_impl_t
*usb_console_output
;
258 /* Translate the dip into a device and check hcdi ops */
259 usb_device
= usba_get_usba_device(dip
);
260 if (usb_device
->usb_hcdi_ops
->usba_hcdi_ops_version
<
261 HCDI_OPS_VERSION_1
||
262 usb_device
->usb_hcdi_ops
->usba_hcdi_console_output_init
== NULL
)
264 return (USB_FAILURE
);
266 usb_console_output
= kmem_zalloc(sizeof (struct usb_console_info_impl
),
268 usb_console_output
->uci_dip
= dip
;
271 * Call the lower layer to initialize any state information
273 ret
= usb_device
->usb_hcdi_ops
->usba_hcdi_console_output_init(
274 usba_get_ph_data(pipe_handle
), usb_console_output
);
276 if (ret
== USB_FAILURE
) {
277 kmem_free(usb_console_output
,
278 sizeof (struct usb_console_info_impl
));
283 *console_output_info
= (usb_console_info_t
)usb_console_output
;
285 return (USB_SUCCESS
);
289 * Free up any resources that we allocated in the above initialization
293 usb_console_output_fini(usb_console_info_t console_output_info
)
295 usb_console_info_impl_t
*usb_console_output
;
296 usba_device_t
*usb_device
;
299 usb_console_output
= (usb_console_info_impl_t
*)console_output_info
;
302 * Translate the dip into a device.
304 usb_device
= usba_polled_get_usba_device(usb_console_output
->uci_dip
);
307 * Call the lower layer to free any state information.
309 ret
= usb_device
->usb_hcdi_ops
->usba_hcdi_console_output_fini(
312 if (ret
== USB_FAILURE
) {
318 * We won't be needing this information anymore.
320 kmem_free(usb_console_output
, sizeof (struct usb_console_info_impl
));
322 return (USB_SUCCESS
);
326 * This is the routine that OBP calls to save the USB state information
327 * before using the USB device as an output device. This routine,
328 * and all of the routines that it calls, are responsible for saving
329 * any state information so that it can be restored when OBP mode is
330 * over. At this layer, this code is mainly just a pass through.
333 usb_console_output_enter(usb_console_info_t console_output_info
)
335 usba_device_t
*usb_device
;
336 usb_console_info_impl_t
*usb_console_output
;
338 usb_console_output
= (usb_console_info_impl_t
*)console_output_info
;
341 * Translate the dip into a device.
343 usb_device
= usba_polled_get_usba_device(usb_console_output
->uci_dip
);
346 * Call the lower layer to save state information.
348 usb_device
->usb_hcdi_ops
->usba_hcdi_console_output_enter(
351 return (USB_SUCCESS
);
355 * This is the routine that OBP calls when it wants to write a character.
356 * We will call to the lower layers to write any data
357 * At this layer, this code is mainly just a pass through.
360 usb_console_write(usb_console_info_t console_output_info
,
361 uchar_t
*buf
, uint_t num_characters
, uint_t
*num_characters_written
)
363 usba_device_t
*usb_device
;
364 usb_console_info_impl_t
*usb_console_output
;
366 usb_console_output
= (usb_console_info_impl_t
*)console_output_info
;
369 * Translate the dip into a device.
371 usb_device
= usba_polled_get_usba_device(usb_console_output
->uci_dip
);
374 * Call the lower layer to get a a character. Return the number
375 * of characters read into the buffer.
377 return (usb_device
->usb_hcdi_ops
->usba_hcdi_console_write(
378 usb_console_output
, buf
, num_characters
,
379 num_characters_written
));
383 * This is the routine that OBP calls when it is giving up control of the
384 * USB output device. This routine, and the lower layer routines that it
385 * calls, are responsible for restoring the controller state to the state
386 * it was in before OBP took control. At this layer, this code is mainly
387 * just a pass through.
390 usb_console_output_exit(usb_console_info_t console_output_info
)
392 usba_device_t
*usb_device
;
393 usb_console_info_impl_t
*usb_console_output
;
395 usb_console_output
= (usb_console_info_impl_t
*)console_output_info
;
398 * Translate the dip into a device.
400 usb_device
= usba_polled_get_usba_device(usb_console_output
->uci_dip
);
403 * Restore the state information.
405 usb_device
->usb_hcdi_ops
->usba_hcdi_console_output_exit(
408 return (USB_SUCCESS
);