17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
528cdc3d7Sszhou  * Common Development and Distribution License (the "License").
628cdc3d7Sszhou  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
2277e51571Sgongtian zhao - Sun Microsystems - Beijing China  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
24*0d2006e4SRobert Mustacchi  * Copyright 2019, Joyent, Inc.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate /*
287c478bd9Sstevel@tonic-gate  * USBA: Solaris USB Architecture support
297c478bd9Sstevel@tonic-gate  *
307c478bd9Sstevel@tonic-gate  * ISSUES:
317c478bd9Sstevel@tonic-gate  */
327c478bd9Sstevel@tonic-gate #define	USBA_FRAMEWORK
337c478bd9Sstevel@tonic-gate #include <sys/usb/usba.h>
347c478bd9Sstevel@tonic-gate #include <sys/usb/usba/hcdi.h>
357c478bd9Sstevel@tonic-gate #include <sys/usb/usba/genconsole.h>
367c478bd9Sstevel@tonic-gate #include <sys/usb/usba/usba_types.h>
377c478bd9Sstevel@tonic-gate #include <sys/usb/usba/usba_impl.h>
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate /*
4028cdc3d7Sszhou  * Initialize USB polled support. This routine calls down to the lower
417c478bd9Sstevel@tonic-gate  * layers to initialize any state information.
427c478bd9Sstevel@tonic-gate  */
437c478bd9Sstevel@tonic-gate int
usb_console_input_init(dev_info_t * dip,usb_pipe_handle_t pipe_handle,uchar_t ** state_buf,usb_console_info_t * console_input_info)44*0d2006e4SRobert Mustacchi usb_console_input_init(dev_info_t *dip, usb_pipe_handle_t pipe_handle,
45*0d2006e4SRobert Mustacchi     uchar_t **state_buf, usb_console_info_t *console_input_info)
467c478bd9Sstevel@tonic-gate {
477c478bd9Sstevel@tonic-gate 	int			ret;
487c478bd9Sstevel@tonic-gate 	usba_device_t		*usba_device;
49bde2d83eSsl 	usba_pipe_handle_data_t	*ph_data;
50bde2d83eSsl 	usb_console_info_impl_t	*usb_console_input;
51bde2d83eSsl 
52bde2d83eSsl 	if (dip == NULL) {
53bde2d83eSsl 
54bde2d83eSsl 		return (USB_INVALID_ARGS);
55bde2d83eSsl 	}
56bde2d83eSsl 
57bde2d83eSsl 	if (DEVI_IS_DEVICE_REMOVED(dip)) {
58bde2d83eSsl 
59bde2d83eSsl 		return (USB_FAILURE);
60bde2d83eSsl 	}
61bde2d83eSsl 
62bde2d83eSsl 	usb_console_input = kmem_zalloc(
63bde2d83eSsl 	    sizeof (struct usb_console_info_impl), KM_SLEEP);
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate 	/*
667c478bd9Sstevel@tonic-gate 	 * Save the dip
677c478bd9Sstevel@tonic-gate 	 */
687c478bd9Sstevel@tonic-gate 	usb_console_input->uci_dip = dip;
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate 	/*
717c478bd9Sstevel@tonic-gate 	 * Translate the dip into a device.
727c478bd9Sstevel@tonic-gate 	 */
737c478bd9Sstevel@tonic-gate 	usba_device = usba_get_usba_device(dip);
747c478bd9Sstevel@tonic-gate 
75bde2d83eSsl 	/*
76bde2d83eSsl 	 * Get ph_data from pipe handle and hold the data
77bde2d83eSsl 	 */
78bde2d83eSsl 	if ((ph_data = usba_hold_ph_data(pipe_handle)) == NULL) {
79bde2d83eSsl 		kmem_free(usb_console_input,
80bde2d83eSsl 		    sizeof (struct usb_console_info_impl));
81bde2d83eSsl 
82bde2d83eSsl 		return (USB_INVALID_PIPE);
83bde2d83eSsl 	}
84bde2d83eSsl 
857c478bd9Sstevel@tonic-gate 	/*
867c478bd9Sstevel@tonic-gate 	 * Call the lower layer to initialize any state information
877c478bd9Sstevel@tonic-gate 	 */
887c478bd9Sstevel@tonic-gate 	ret = usba_device->usb_hcdi_ops->usba_hcdi_console_input_init(
89bde2d83eSsl 	    ph_data, state_buf, usb_console_input);
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate 	if (ret != USB_SUCCESS) {
927c478bd9Sstevel@tonic-gate 		kmem_free(usb_console_input,
93bde2d83eSsl 		    sizeof (struct usb_console_info_impl));
947c478bd9Sstevel@tonic-gate 	} else {
957c478bd9Sstevel@tonic-gate 		*console_input_info = (usb_console_info_t)usb_console_input;
967c478bd9Sstevel@tonic-gate 	}
977c478bd9Sstevel@tonic-gate 
98bde2d83eSsl 	usba_release_ph_data((usba_ph_impl_t *)pipe_handle);
99bde2d83eSsl 
1007c478bd9Sstevel@tonic-gate 	return (ret);
1017c478bd9Sstevel@tonic-gate }
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate /*
1057c478bd9Sstevel@tonic-gate  * Free up any resources that we allocated in the above initialization
1067c478bd9Sstevel@tonic-gate  * routine.
1077c478bd9Sstevel@tonic-gate  */
1087c478bd9Sstevel@tonic-gate int
usb_console_input_fini(usb_console_info_t console_input_info)1097c478bd9Sstevel@tonic-gate usb_console_input_fini(usb_console_info_t console_input_info)
1107c478bd9Sstevel@tonic-gate {
1117c478bd9Sstevel@tonic-gate 	usb_console_info_impl_t		*usb_console_input;
1127c478bd9Sstevel@tonic-gate 	usba_device_t			*usba_device;
1137c478bd9Sstevel@tonic-gate 	int				ret;
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate 	usb_console_input = (usb_console_info_impl_t *)console_input_info;
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate 	/*
1187c478bd9Sstevel@tonic-gate 	 * Translate the dip into a device.
1197c478bd9Sstevel@tonic-gate 	 */
1207c478bd9Sstevel@tonic-gate 	usba_device = usba_get_usba_device(usb_console_input->uci_dip);
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate 	/*
1237c478bd9Sstevel@tonic-gate 	 * Call the lower layer to free any state information.
1247c478bd9Sstevel@tonic-gate 	 */
1257c478bd9Sstevel@tonic-gate 	ret = usba_device->usb_hcdi_ops->usba_hcdi_console_input_fini(
12677e51571Sgongtian zhao - Sun Microsystems - Beijing China 	    usb_console_input);
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate 	if (ret == USB_FAILURE) {
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate 		return (ret);
1317c478bd9Sstevel@tonic-gate 	}
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate 	/*
1347c478bd9Sstevel@tonic-gate 	 * We won't be needing this information anymore.
1357c478bd9Sstevel@tonic-gate 	 */
1367c478bd9Sstevel@tonic-gate 	kmem_free(usb_console_input, sizeof (struct usb_console_info_impl));
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate 	return (USB_SUCCESS);
1397c478bd9Sstevel@tonic-gate }
1407c478bd9Sstevel@tonic-gate 
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate /*
1437c478bd9Sstevel@tonic-gate  * This is the routine that OBP calls to save the USB state information
1447c478bd9Sstevel@tonic-gate  * before using the USB keyboard as an input device.  This routine,
1457c478bd9Sstevel@tonic-gate  * and all of the routines that it calls, are responsible for saving
1467c478bd9Sstevel@tonic-gate  * any state information so that it can be restored when OBP mode is
1477c478bd9Sstevel@tonic-gate  * over.  At this layer, this code is mainly just a pass through.
1487c478bd9Sstevel@tonic-gate  *
1497c478bd9Sstevel@tonic-gate  * Warning:  this code runs in polled mode.
1507c478bd9Sstevel@tonic-gate  */
1517c478bd9Sstevel@tonic-gate int
usb_console_input_enter(usb_console_info_t console_input_info)1527c478bd9Sstevel@tonic-gate usb_console_input_enter(usb_console_info_t console_input_info)
1537c478bd9Sstevel@tonic-gate {
1547c478bd9Sstevel@tonic-gate 	usba_device_t				*usba_device;
1557c478bd9Sstevel@tonic-gate 	usb_console_info_impl_t			*usb_console_input;
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate 	usb_console_input = (usb_console_info_impl_t *)console_input_info;
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate 	/*
1607c478bd9Sstevel@tonic-gate 	 * Translate the dip into a device.
1617c478bd9Sstevel@tonic-gate 	 * Do this by directly looking at the dip, do not call
1627c478bd9Sstevel@tonic-gate 	 * usba_get_usba_device() because this function calls into the DDI.
1637c478bd9Sstevel@tonic-gate 	 * The ddi then tries to acquire a mutex and the machine hard hangs.
1647c478bd9Sstevel@tonic-gate 	 */
1657c478bd9Sstevel@tonic-gate 	usba_device = usba_polled_get_usba_device(usb_console_input->uci_dip);
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate 	/*
1687c478bd9Sstevel@tonic-gate 	 * Call the lower layer to save state information.
1697c478bd9Sstevel@tonic-gate 	 */
170*0d2006e4SRobert Mustacchi 	return (usba_device->usb_hcdi_ops->usba_hcdi_console_input_enter(
171*0d2006e4SRobert Mustacchi 	    usb_console_input));
1727c478bd9Sstevel@tonic-gate }
1737c478bd9Sstevel@tonic-gate 
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate /*
1767c478bd9Sstevel@tonic-gate  * This is the routine that OBP calls when it wants to read a character.
1777c478bd9Sstevel@tonic-gate  * We will call to the lower layers to see if there is any input data
1787c478bd9Sstevel@tonic-gate  * available.  At this layer, this code is mainly just a pass through.
1797c478bd9Sstevel@tonic-gate  *
1807c478bd9Sstevel@tonic-gate  * Warning: This code runs in polled mode.
1817c478bd9Sstevel@tonic-gate  */
1827c478bd9Sstevel@tonic-gate int
usb_console_read(usb_console_info_t console_input_info,uint_t * num_characters)1837c478bd9Sstevel@tonic-gate usb_console_read(usb_console_info_t console_input_info, uint_t *num_characters)
1847c478bd9Sstevel@tonic-gate {
1857c478bd9Sstevel@tonic-gate 	usba_device_t				*usba_device;
1867c478bd9Sstevel@tonic-gate 	usb_console_info_impl_t			*usb_console_input;
1877c478bd9Sstevel@tonic-gate 
1887c478bd9Sstevel@tonic-gate 	usb_console_input = (usb_console_info_impl_t *)console_input_info;
1897c478bd9Sstevel@tonic-gate 
1907c478bd9Sstevel@tonic-gate 	/*
1917c478bd9Sstevel@tonic-gate 	 * Translate the dip into a device.
1927c478bd9Sstevel@tonic-gate 	 * Do this by directly looking at the dip, do not call
1937c478bd9Sstevel@tonic-gate 	 * usba_get_usba_device() because this function calls into the DDI.
1947c478bd9Sstevel@tonic-gate 	 * The ddi then tries to acquire a mutex and the machine hard hangs.
1957c478bd9Sstevel@tonic-gate 	 */
1967c478bd9Sstevel@tonic-gate 	usba_device = usba_polled_get_usba_device(usb_console_input->uci_dip);
1977c478bd9Sstevel@tonic-gate 
1987c478bd9Sstevel@tonic-gate 	/*
1997c478bd9Sstevel@tonic-gate 	 * Call the lower layer to get a a character.  Return the number
2007c478bd9Sstevel@tonic-gate 	 * of characters read into the buffer.
2017c478bd9Sstevel@tonic-gate 	 */
2027c478bd9Sstevel@tonic-gate 	return (usba_device->usb_hcdi_ops->usba_hcdi_console_read(
20377e51571Sgongtian zhao - Sun Microsystems - Beijing China 	    usb_console_input, num_characters));
2047c478bd9Sstevel@tonic-gate }
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate 
2077c478bd9Sstevel@tonic-gate /*
2087c478bd9Sstevel@tonic-gate  * This is the routine that OBP calls when it is giving up control of the
2097c478bd9Sstevel@tonic-gate  * USB keyboard.  This routine, and the lower layer routines that it calls,
2107c478bd9Sstevel@tonic-gate  * are responsible for restoring the controller state to the state it was
2117c478bd9Sstevel@tonic-gate  * in before OBP took control. At this layer, this code is mainly just a
2127c478bd9Sstevel@tonic-gate  * pass through.
2137c478bd9Sstevel@tonic-gate  *
2147c478bd9Sstevel@tonic-gate  * Warning: This code runs in polled mode.
2157c478bd9Sstevel@tonic-gate  */
2167c478bd9Sstevel@tonic-gate int
usb_console_input_exit(usb_console_info_t console_input_info)2177c478bd9Sstevel@tonic-gate usb_console_input_exit(usb_console_info_t console_input_info)
2187c478bd9Sstevel@tonic-gate {
2197c478bd9Sstevel@tonic-gate 	usba_device_t				*usba_device;
2207c478bd9Sstevel@tonic-gate 	usb_console_info_impl_t			*usb_console_input;
2217c478bd9Sstevel@tonic-gate 
2227c478bd9Sstevel@tonic-gate 	usb_console_input = (usb_console_info_impl_t *)console_input_info;
2237c478bd9Sstevel@tonic-gate 
2247c478bd9Sstevel@tonic-gate 	/*
2257c478bd9Sstevel@tonic-gate 	 * Translate the dip into a device.
2267c478bd9Sstevel@tonic-gate 	 * Do this by directly looking at the dip, do not call
2277c478bd9Sstevel@tonic-gate 	 * usba_get_usba_device() because this function calls into the DDI.
2287c478bd9Sstevel@tonic-gate 	 * The ddi then tries to acquire a mutex and the machine hard hangs.
2297c478bd9Sstevel@tonic-gate 	 */
2307c478bd9Sstevel@tonic-gate 	usba_device = usba_polled_get_usba_device(usb_console_input->uci_dip);
2317c478bd9Sstevel@tonic-gate 
2327c478bd9Sstevel@tonic-gate 	/*
2337c478bd9Sstevel@tonic-gate 	 * Restore the state information.
2347c478bd9Sstevel@tonic-gate 	 */
235*0d2006e4SRobert Mustacchi 	return (usba_device->usb_hcdi_ops->usba_hcdi_console_input_exit(
236*0d2006e4SRobert Mustacchi 	    usb_console_input));
2377c478bd9Sstevel@tonic-gate }
23828cdc3d7Sszhou 
23928cdc3d7Sszhou /*
24077e51571Sgongtian zhao - Sun Microsystems - Beijing China  * Initialize USB OBP support.	This routine calls down to the lower
24128cdc3d7Sszhou  * layers to initialize any state information.
24228cdc3d7Sszhou  */
24328cdc3d7Sszhou int
usb_console_output_init(dev_info_t * dip,usb_pipe_handle_t pipe_handle,usb_console_info_t * console_output_info)24428cdc3d7Sszhou usb_console_output_init(
24528cdc3d7Sszhou 	dev_info_t		*dip,
24628cdc3d7Sszhou 	usb_pipe_handle_t	pipe_handle,
24728cdc3d7Sszhou 	usb_console_info_t	*console_output_info)
24828cdc3d7Sszhou {
24928cdc3d7Sszhou 	usba_device_t		*usb_device;
25028cdc3d7Sszhou 	usb_console_info_impl_t	*usb_console_output;
25128cdc3d7Sszhou 	int			ret;
25228cdc3d7Sszhou 
25328cdc3d7Sszhou 	/* Translate the dip into a device and check hcdi ops  */
25428cdc3d7Sszhou 	usb_device = usba_get_usba_device(dip);
25528cdc3d7Sszhou 	if (usb_device->usb_hcdi_ops->usba_hcdi_ops_version <
25628cdc3d7Sszhou 	    HCDI_OPS_VERSION_1 ||
25728cdc3d7Sszhou 	    usb_device->usb_hcdi_ops->usba_hcdi_console_output_init == NULL)
25828cdc3d7Sszhou 
25928cdc3d7Sszhou 		return (USB_FAILURE);
26028cdc3d7Sszhou 
26128cdc3d7Sszhou 	usb_console_output = kmem_zalloc(sizeof (struct usb_console_info_impl),
26277e51571Sgongtian zhao - Sun Microsystems - Beijing China 	    KM_SLEEP);
26328cdc3d7Sszhou 	usb_console_output->uci_dip = dip;
26428cdc3d7Sszhou 
26528cdc3d7Sszhou 	/*
26628cdc3d7Sszhou 	 * Call the lower layer to initialize any state information
26728cdc3d7Sszhou 	 */
26828cdc3d7Sszhou 	ret = usb_device->usb_hcdi_ops->usba_hcdi_console_output_init(
26977e51571Sgongtian zhao - Sun Microsystems - Beijing China 	    usba_get_ph_data(pipe_handle), usb_console_output);
27028cdc3d7Sszhou 
27128cdc3d7Sszhou 	if (ret == USB_FAILURE) {
27228cdc3d7Sszhou 		kmem_free(usb_console_output,
27377e51571Sgongtian zhao - Sun Microsystems - Beijing China 		    sizeof (struct usb_console_info_impl));
27428cdc3d7Sszhou 
27528cdc3d7Sszhou 		return (ret);
27628cdc3d7Sszhou 	}
27728cdc3d7Sszhou 
27828cdc3d7Sszhou 	*console_output_info = (usb_console_info_t)usb_console_output;
27928cdc3d7Sszhou 
28028cdc3d7Sszhou 	return (USB_SUCCESS);
28128cdc3d7Sszhou }
28228cdc3d7Sszhou 
28328cdc3d7Sszhou /*
28428cdc3d7Sszhou  * Free up any resources that we allocated in the above initialization
28528cdc3d7Sszhou  * routine.
28628cdc3d7Sszhou  */
28728cdc3d7Sszhou int
usb_console_output_fini(usb_console_info_t console_output_info)28828cdc3d7Sszhou usb_console_output_fini(usb_console_info_t console_output_info)
28928cdc3d7Sszhou {
29028cdc3d7Sszhou 	usb_console_info_impl_t	*usb_console_output;
29128cdc3d7Sszhou 	usba_device_t		*usb_device;
29228cdc3d7Sszhou 	int			ret;
29328cdc3d7Sszhou 
29428cdc3d7Sszhou 	usb_console_output = (usb_console_info_impl_t *)console_output_info;
29528cdc3d7Sszhou 
29628cdc3d7Sszhou 	/*
29728cdc3d7Sszhou 	 * Translate the dip into a device.
29828cdc3d7Sszhou 	 */
29928cdc3d7Sszhou 	usb_device = usba_polled_get_usba_device(usb_console_output->uci_dip);
30028cdc3d7Sszhou 
30128cdc3d7Sszhou 	/*
30228cdc3d7Sszhou 	 * Call the lower layer to free any state information.
30328cdc3d7Sszhou 	 */
30428cdc3d7Sszhou 	ret = usb_device->usb_hcdi_ops->usba_hcdi_console_output_fini(
30577e51571Sgongtian zhao - Sun Microsystems - Beijing China 	    usb_console_output);
30628cdc3d7Sszhou 
30728cdc3d7Sszhou 	if (ret == USB_FAILURE) {
30828cdc3d7Sszhou 
30928cdc3d7Sszhou 		return (ret);
31028cdc3d7Sszhou 	}
31128cdc3d7Sszhou 
31228cdc3d7Sszhou 	/*
31328cdc3d7Sszhou 	 * We won't be needing this information anymore.
31428cdc3d7Sszhou 	 */
31528cdc3d7Sszhou 	kmem_free(usb_console_output, sizeof (struct usb_console_info_impl));
31628cdc3d7Sszhou 
31728cdc3d7Sszhou 	return (USB_SUCCESS);
31828cdc3d7Sszhou }
31928cdc3d7Sszhou 
32028cdc3d7Sszhou /*
32128cdc3d7Sszhou  * This is the routine that OBP calls to save the USB state information
32228cdc3d7Sszhou  * before using the USB device as an output device.  This routine,
32328cdc3d7Sszhou  * and all of the routines that it calls, are responsible for saving
32428cdc3d7Sszhou  * any state information so that it can be restored when OBP mode is
32528cdc3d7Sszhou  * over.  At this layer, this code is mainly just a pass through.
32628cdc3d7Sszhou  */
32728cdc3d7Sszhou int
usb_console_output_enter(usb_console_info_t console_output_info)32828cdc3d7Sszhou usb_console_output_enter(usb_console_info_t console_output_info)
32928cdc3d7Sszhou {
33028cdc3d7Sszhou 	usba_device_t			    *usb_device;
33128cdc3d7Sszhou 	usb_console_info_impl_t		 *usb_console_output;
33228cdc3d7Sszhou 
33328cdc3d7Sszhou 	usb_console_output = (usb_console_info_impl_t *)console_output_info;
33428cdc3d7Sszhou 
33528cdc3d7Sszhou 	/*
33628cdc3d7Sszhou 	 * Translate the dip into a device.
33728cdc3d7Sszhou 	 */
33828cdc3d7Sszhou 	usb_device = usba_polled_get_usba_device(usb_console_output->uci_dip);
33928cdc3d7Sszhou 
34028cdc3d7Sszhou 	/*
34128cdc3d7Sszhou 	 * Call the lower layer to save state information.
34228cdc3d7Sszhou 	 */
343*0d2006e4SRobert Mustacchi 	return (usb_device->usb_hcdi_ops->usba_hcdi_console_output_enter(
344*0d2006e4SRobert Mustacchi 	    usb_console_output));
34528cdc3d7Sszhou }
34628cdc3d7Sszhou 
34728cdc3d7Sszhou /*
34828cdc3d7Sszhou  * This is the routine that OBP calls when it wants to write a character.
34928cdc3d7Sszhou  * We will call to the lower layers to write any data
35028cdc3d7Sszhou  * At this layer, this code is mainly just a pass through.
35128cdc3d7Sszhou  */
35228cdc3d7Sszhou int
usb_console_write(usb_console_info_t console_output_info,uchar_t * buf,uint_t num_characters,uint_t * num_characters_written)35328cdc3d7Sszhou usb_console_write(usb_console_info_t console_output_info,
354*0d2006e4SRobert Mustacchi     uchar_t *buf, uint_t num_characters, uint_t *num_characters_written)
35528cdc3d7Sszhou {
35628cdc3d7Sszhou 	usba_device_t		*usb_device;
35728cdc3d7Sszhou 	usb_console_info_impl_t	*usb_console_output;
35828cdc3d7Sszhou 
35928cdc3d7Sszhou 	usb_console_output = (usb_console_info_impl_t *)console_output_info;
36028cdc3d7Sszhou 
36128cdc3d7Sszhou 	/*
36228cdc3d7Sszhou 	 * Translate the dip into a device.
36328cdc3d7Sszhou 	 */
36428cdc3d7Sszhou 	usb_device = usba_polled_get_usba_device(usb_console_output->uci_dip);
36528cdc3d7Sszhou 
36628cdc3d7Sszhou 	/*
36728cdc3d7Sszhou 	 * Call the lower layer to get a a character.  Return the number
36828cdc3d7Sszhou 	 * of characters read into the buffer.
36928cdc3d7Sszhou 	 */
37028cdc3d7Sszhou 	return (usb_device->usb_hcdi_ops->usba_hcdi_console_write(
37177e51571Sgongtian zhao - Sun Microsystems - Beijing China 	    usb_console_output, buf, num_characters,
37277e51571Sgongtian zhao - Sun Microsystems - Beijing China 	    num_characters_written));
37328cdc3d7Sszhou }
37428cdc3d7Sszhou 
37528cdc3d7Sszhou /*
37628cdc3d7Sszhou  * This is the routine that OBP calls when it is giving up control of the
37728cdc3d7Sszhou  * USB output device.  This routine, and the lower layer routines that it
37828cdc3d7Sszhou  * calls, are responsible for restoring the controller state to the state
37928cdc3d7Sszhou  * it was in before OBP took control. At this layer, this code is mainly
38028cdc3d7Sszhou  * just a pass through.
38128cdc3d7Sszhou  */
38228cdc3d7Sszhou int
usb_console_output_exit(usb_console_info_t console_output_info)38328cdc3d7Sszhou usb_console_output_exit(usb_console_info_t console_output_info)
38428cdc3d7Sszhou {
38528cdc3d7Sszhou 	usba_device_t			 *usb_device;
38628cdc3d7Sszhou 	usb_console_info_impl_t		 *usb_console_output;
38728cdc3d7Sszhou 
38828cdc3d7Sszhou 	usb_console_output = (usb_console_info_impl_t *)console_output_info;
38928cdc3d7Sszhou 
39028cdc3d7Sszhou 	/*
39128cdc3d7Sszhou 	 * Translate the dip into a device.
39228cdc3d7Sszhou 	 */
39328cdc3d7Sszhou 	usb_device = usba_polled_get_usba_device(usb_console_output->uci_dip);
39428cdc3d7Sszhou 
39528cdc3d7Sszhou 	/*
39628cdc3d7Sszhou 	 * Restore the state information.
39728cdc3d7Sszhou 	 */
398*0d2006e4SRobert Mustacchi 	return (usb_device->usb_hcdi_ops->usba_hcdi_console_output_exit(
399*0d2006e4SRobert Mustacchi 	    usb_console_output));
40028cdc3d7Sszhou }
401