xref: /titanic_51/usr/src/uts/common/io/usb/usba/genconsole.c (revision 77e515715b61e28fcf0c3f30936492888cecfd8b)
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 /*
22*77e51571Sgongtian zhao - Sun Microsystems - Beijing China  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*
277c478bd9Sstevel@tonic-gate  * USBA: Solaris USB Architecture support
287c478bd9Sstevel@tonic-gate  *
297c478bd9Sstevel@tonic-gate  * ISSUES:
307c478bd9Sstevel@tonic-gate  */
317c478bd9Sstevel@tonic-gate #define	USBA_FRAMEWORK
327c478bd9Sstevel@tonic-gate #include <sys/usb/usba.h>
337c478bd9Sstevel@tonic-gate #include <sys/usb/usba/hcdi.h>
347c478bd9Sstevel@tonic-gate #include <sys/usb/usba/genconsole.h>
357c478bd9Sstevel@tonic-gate #include <sys/usb/usba/usba_types.h>
367c478bd9Sstevel@tonic-gate #include <sys/usb/usba/usba_impl.h>
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate /*
3928cdc3d7Sszhou  * Initialize USB polled support. This routine calls down to the lower
407c478bd9Sstevel@tonic-gate  * layers to initialize any state information.
417c478bd9Sstevel@tonic-gate  */
427c478bd9Sstevel@tonic-gate int
437c478bd9Sstevel@tonic-gate usb_console_input_init(dev_info_t		*dip,
447c478bd9Sstevel@tonic-gate 			usb_pipe_handle_t	pipe_handle,
4528cdc3d7Sszhou 			uchar_t			**state_buf,
467c478bd9Sstevel@tonic-gate 			usb_console_info_t	*console_input_info)
477c478bd9Sstevel@tonic-gate {
487c478bd9Sstevel@tonic-gate 	int			ret;
497c478bd9Sstevel@tonic-gate 	usba_device_t		*usba_device;
50bde2d83eSsl147100 	usba_pipe_handle_data_t	*ph_data;
51bde2d83eSsl147100 	usb_console_info_impl_t	*usb_console_input;
52bde2d83eSsl147100 
53bde2d83eSsl147100 	if (dip == NULL) {
54bde2d83eSsl147100 
55bde2d83eSsl147100 		return (USB_INVALID_ARGS);
56bde2d83eSsl147100 	}
57bde2d83eSsl147100 
58bde2d83eSsl147100 	if (DEVI_IS_DEVICE_REMOVED(dip)) {
59bde2d83eSsl147100 
60bde2d83eSsl147100 		return (USB_FAILURE);
61bde2d83eSsl147100 	}
62bde2d83eSsl147100 
63bde2d83eSsl147100 	usb_console_input = kmem_zalloc(
647c478bd9Sstevel@tonic-gate 	    sizeof (struct usb_console_info_impl), KM_SLEEP);
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate 	/*
677c478bd9Sstevel@tonic-gate 	 * Save the dip
687c478bd9Sstevel@tonic-gate 	 */
697c478bd9Sstevel@tonic-gate 	usb_console_input->uci_dip = dip;
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate 	/*
727c478bd9Sstevel@tonic-gate 	 * Translate the dip into a device.
737c478bd9Sstevel@tonic-gate 	 */
747c478bd9Sstevel@tonic-gate 	usba_device = usba_get_usba_device(dip);
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate 	/*
77bde2d83eSsl147100 	 * Get ph_data from pipe handle and hold the data
78bde2d83eSsl147100 	 */
79bde2d83eSsl147100 	if ((ph_data = usba_hold_ph_data(pipe_handle)) == NULL) {
80bde2d83eSsl147100 		kmem_free(usb_console_input,
81bde2d83eSsl147100 		    sizeof (struct usb_console_info_impl));
82bde2d83eSsl147100 
83bde2d83eSsl147100 		return (USB_INVALID_PIPE);
84bde2d83eSsl147100 	}
85bde2d83eSsl147100 
86bde2d83eSsl147100 	/*
877c478bd9Sstevel@tonic-gate 	 * Call the lower layer to initialize any state information
887c478bd9Sstevel@tonic-gate 	 */
897c478bd9Sstevel@tonic-gate 	ret = usba_device->usb_hcdi_ops->usba_hcdi_console_input_init(
90bde2d83eSsl147100 	    ph_data, state_buf, usb_console_input);
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate 	if (ret != USB_SUCCESS) {
937c478bd9Sstevel@tonic-gate 		kmem_free(usb_console_input,
947c478bd9Sstevel@tonic-gate 		    sizeof (struct usb_console_info_impl));
957c478bd9Sstevel@tonic-gate 	} else {
967c478bd9Sstevel@tonic-gate 		*console_input_info = (usb_console_info_t)usb_console_input;
977c478bd9Sstevel@tonic-gate 	}
987c478bd9Sstevel@tonic-gate 
99bde2d83eSsl147100 	usba_release_ph_data((usba_ph_impl_t *)pipe_handle);
100bde2d83eSsl147100 
1017c478bd9Sstevel@tonic-gate 	return (ret);
1027c478bd9Sstevel@tonic-gate }
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate /*
1067c478bd9Sstevel@tonic-gate  * Free up any resources that we allocated in the above initialization
1077c478bd9Sstevel@tonic-gate  * routine.
1087c478bd9Sstevel@tonic-gate  */
1097c478bd9Sstevel@tonic-gate int
1107c478bd9Sstevel@tonic-gate usb_console_input_fini(usb_console_info_t console_input_info)
1117c478bd9Sstevel@tonic-gate {
1127c478bd9Sstevel@tonic-gate 	usb_console_info_impl_t		*usb_console_input;
1137c478bd9Sstevel@tonic-gate 	usba_device_t			*usba_device;
1147c478bd9Sstevel@tonic-gate 	int				ret;
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate 	usb_console_input = (usb_console_info_impl_t *)console_input_info;
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate 	/*
1197c478bd9Sstevel@tonic-gate 	 * Translate the dip into a device.
1207c478bd9Sstevel@tonic-gate 	 */
1217c478bd9Sstevel@tonic-gate 	usba_device = usba_get_usba_device(usb_console_input->uci_dip);
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate 	/*
1247c478bd9Sstevel@tonic-gate 	 * Call the lower layer to free any state information.
1257c478bd9Sstevel@tonic-gate 	 */
1267c478bd9Sstevel@tonic-gate 	ret = usba_device->usb_hcdi_ops->usba_hcdi_console_input_fini(
1277c478bd9Sstevel@tonic-gate 	    usb_console_input);
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate 	if (ret == USB_FAILURE) {
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate 		return (ret);
1327c478bd9Sstevel@tonic-gate 	}
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate 	/*
1357c478bd9Sstevel@tonic-gate 	 * We won't be needing this information anymore.
1367c478bd9Sstevel@tonic-gate 	 */
1377c478bd9Sstevel@tonic-gate 	kmem_free(usb_console_input, sizeof (struct usb_console_info_impl));
1387c478bd9Sstevel@tonic-gate 
1397c478bd9Sstevel@tonic-gate 	return (USB_SUCCESS);
1407c478bd9Sstevel@tonic-gate }
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate /*
1447c478bd9Sstevel@tonic-gate  * This is the routine that OBP calls to save the USB state information
1457c478bd9Sstevel@tonic-gate  * before using the USB keyboard as an input device.  This routine,
1467c478bd9Sstevel@tonic-gate  * and all of the routines that it calls, are responsible for saving
1477c478bd9Sstevel@tonic-gate  * any state information so that it can be restored when OBP mode is
1487c478bd9Sstevel@tonic-gate  * over.  At this layer, this code is mainly just a pass through.
1497c478bd9Sstevel@tonic-gate  *
1507c478bd9Sstevel@tonic-gate  * Warning:  this code runs in polled mode.
1517c478bd9Sstevel@tonic-gate  */
1527c478bd9Sstevel@tonic-gate int
1537c478bd9Sstevel@tonic-gate usb_console_input_enter(usb_console_info_t console_input_info)
1547c478bd9Sstevel@tonic-gate {
1557c478bd9Sstevel@tonic-gate 	usba_device_t				*usba_device;
1567c478bd9Sstevel@tonic-gate 	usb_console_info_impl_t			*usb_console_input;
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate 	usb_console_input = (usb_console_info_impl_t *)console_input_info;
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate 	/*
1617c478bd9Sstevel@tonic-gate 	 * Translate the dip into a device.
1627c478bd9Sstevel@tonic-gate 	 * Do this by directly looking at the dip, do not call
1637c478bd9Sstevel@tonic-gate 	 * usba_get_usba_device() because this function calls into the DDI.
1647c478bd9Sstevel@tonic-gate 	 * The ddi then tries to acquire a mutex and the machine hard hangs.
1657c478bd9Sstevel@tonic-gate 	 */
1667c478bd9Sstevel@tonic-gate 	usba_device = usba_polled_get_usba_device(usb_console_input->uci_dip);
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate 	/*
1697c478bd9Sstevel@tonic-gate 	 * Call the lower layer to save state information.
1707c478bd9Sstevel@tonic-gate 	 */
1717c478bd9Sstevel@tonic-gate 	usba_device->usb_hcdi_ops->usba_hcdi_console_input_enter(
1727c478bd9Sstevel@tonic-gate 	    usb_console_input);
1737c478bd9Sstevel@tonic-gate 
1747c478bd9Sstevel@tonic-gate 	return (USB_SUCCESS);
1757c478bd9Sstevel@tonic-gate }
1767c478bd9Sstevel@tonic-gate 
1777c478bd9Sstevel@tonic-gate 
1787c478bd9Sstevel@tonic-gate /*
1797c478bd9Sstevel@tonic-gate  * This is the routine that OBP calls when it wants to read a character.
1807c478bd9Sstevel@tonic-gate  * We will call to the lower layers to see if there is any input data
1817c478bd9Sstevel@tonic-gate  * available.  At this layer, this code is mainly just a pass through.
1827c478bd9Sstevel@tonic-gate  *
1837c478bd9Sstevel@tonic-gate  * Warning: This code runs in polled mode.
1847c478bd9Sstevel@tonic-gate  */
1857c478bd9Sstevel@tonic-gate int
1867c478bd9Sstevel@tonic-gate usb_console_read(usb_console_info_t console_input_info, uint_t *num_characters)
1877c478bd9Sstevel@tonic-gate {
1887c478bd9Sstevel@tonic-gate 	usba_device_t				*usba_device;
1897c478bd9Sstevel@tonic-gate 	usb_console_info_impl_t			*usb_console_input;
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate 	usb_console_input = (usb_console_info_impl_t *)console_input_info;
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate 	/*
1947c478bd9Sstevel@tonic-gate 	 * Translate the dip into a device.
1957c478bd9Sstevel@tonic-gate 	 * Do this by directly looking at the dip, do not call
1967c478bd9Sstevel@tonic-gate 	 * usba_get_usba_device() because this function calls into the DDI.
1977c478bd9Sstevel@tonic-gate 	 * The ddi then tries to acquire a mutex and the machine hard hangs.
1987c478bd9Sstevel@tonic-gate 	 */
1997c478bd9Sstevel@tonic-gate 	usba_device = usba_polled_get_usba_device(usb_console_input->uci_dip);
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate 	/*
2027c478bd9Sstevel@tonic-gate 	 * Call the lower layer to get a a character.  Return the number
2037c478bd9Sstevel@tonic-gate 	 * of characters read into the buffer.
2047c478bd9Sstevel@tonic-gate 	 */
2057c478bd9Sstevel@tonic-gate 	return (usba_device->usb_hcdi_ops->usba_hcdi_console_read(
2067c478bd9Sstevel@tonic-gate 	    usb_console_input, num_characters));
2077c478bd9Sstevel@tonic-gate }
2087c478bd9Sstevel@tonic-gate 
2097c478bd9Sstevel@tonic-gate 
2107c478bd9Sstevel@tonic-gate /*
2117c478bd9Sstevel@tonic-gate  * This is the routine that OBP calls when it is giving up control of the
2127c478bd9Sstevel@tonic-gate  * USB keyboard.  This routine, and the lower layer routines that it calls,
2137c478bd9Sstevel@tonic-gate  * are responsible for restoring the controller state to the state it was
2147c478bd9Sstevel@tonic-gate  * in before OBP took control. At this layer, this code is mainly just a
2157c478bd9Sstevel@tonic-gate  * pass through.
2167c478bd9Sstevel@tonic-gate  *
2177c478bd9Sstevel@tonic-gate  * Warning: This code runs in polled mode.
2187c478bd9Sstevel@tonic-gate  */
2197c478bd9Sstevel@tonic-gate int
2207c478bd9Sstevel@tonic-gate usb_console_input_exit(usb_console_info_t console_input_info)
2217c478bd9Sstevel@tonic-gate {
2227c478bd9Sstevel@tonic-gate 	usba_device_t				*usba_device;
2237c478bd9Sstevel@tonic-gate 	usb_console_info_impl_t			*usb_console_input;
2247c478bd9Sstevel@tonic-gate 
2257c478bd9Sstevel@tonic-gate 	usb_console_input = (usb_console_info_impl_t *)console_input_info;
2267c478bd9Sstevel@tonic-gate 
2277c478bd9Sstevel@tonic-gate 	/*
2287c478bd9Sstevel@tonic-gate 	 * Translate the dip into a device.
2297c478bd9Sstevel@tonic-gate 	 * Do this by directly looking at the dip, do not call
2307c478bd9Sstevel@tonic-gate 	 * usba_get_usba_device() because this function calls into the DDI.
2317c478bd9Sstevel@tonic-gate 	 * The ddi then tries to acquire a mutex and the machine hard hangs.
2327c478bd9Sstevel@tonic-gate 	 */
2337c478bd9Sstevel@tonic-gate 	usba_device = usba_polled_get_usba_device(usb_console_input->uci_dip);
2347c478bd9Sstevel@tonic-gate 
2357c478bd9Sstevel@tonic-gate 	/*
2367c478bd9Sstevel@tonic-gate 	 * Restore the state information.
2377c478bd9Sstevel@tonic-gate 	 */
2387c478bd9Sstevel@tonic-gate 	usba_device->usb_hcdi_ops->usba_hcdi_console_input_exit(
2397c478bd9Sstevel@tonic-gate 	    usb_console_input);
2407c478bd9Sstevel@tonic-gate 
2417c478bd9Sstevel@tonic-gate 	return (USB_SUCCESS);
2427c478bd9Sstevel@tonic-gate }
24328cdc3d7Sszhou 
24428cdc3d7Sszhou /*
24528cdc3d7Sszhou  * Initialize USB OBP support.	This routine calls down to the lower
24628cdc3d7Sszhou  * layers to initialize any state information.
24728cdc3d7Sszhou  */
24828cdc3d7Sszhou int
24928cdc3d7Sszhou usb_console_output_init(
25028cdc3d7Sszhou 	dev_info_t		*dip,
25128cdc3d7Sszhou 	usb_pipe_handle_t	pipe_handle,
25228cdc3d7Sszhou 	usb_console_info_t	*console_output_info)
25328cdc3d7Sszhou {
25428cdc3d7Sszhou 	usba_device_t		*usb_device;
25528cdc3d7Sszhou 	usb_console_info_impl_t	*usb_console_output;
25628cdc3d7Sszhou 	int			ret;
25728cdc3d7Sszhou 
25828cdc3d7Sszhou 	/* Translate the dip into a device and check hcdi ops  */
25928cdc3d7Sszhou 	usb_device = usba_get_usba_device(dip);
26028cdc3d7Sszhou 	if (usb_device->usb_hcdi_ops->usba_hcdi_ops_version <
26128cdc3d7Sszhou 	    HCDI_OPS_VERSION_1 ||
26228cdc3d7Sszhou 	    usb_device->usb_hcdi_ops->usba_hcdi_console_output_init == NULL)
26328cdc3d7Sszhou 
26428cdc3d7Sszhou 		return (USB_FAILURE);
26528cdc3d7Sszhou 
26628cdc3d7Sszhou 	usb_console_output = kmem_zalloc(sizeof (struct usb_console_info_impl),
26728cdc3d7Sszhou 	    KM_SLEEP);
26828cdc3d7Sszhou 	usb_console_output->uci_dip = dip;
26928cdc3d7Sszhou 
27028cdc3d7Sszhou 	/*
27128cdc3d7Sszhou 	 * Call the lower layer to initialize any state information
27228cdc3d7Sszhou 	 */
27328cdc3d7Sszhou 	ret = usb_device->usb_hcdi_ops->usba_hcdi_console_output_init(
27428cdc3d7Sszhou 	    usba_get_ph_data(pipe_handle), usb_console_output);
27528cdc3d7Sszhou 
27628cdc3d7Sszhou 	if (ret == USB_FAILURE) {
27728cdc3d7Sszhou 		kmem_free(usb_console_output,
27828cdc3d7Sszhou 		    sizeof (struct usb_console_info_impl));
27928cdc3d7Sszhou 
28028cdc3d7Sszhou 		return (ret);
28128cdc3d7Sszhou 	}
28228cdc3d7Sszhou 
28328cdc3d7Sszhou 	*console_output_info = (usb_console_info_t)usb_console_output;
28428cdc3d7Sszhou 
28528cdc3d7Sszhou 	return (USB_SUCCESS);
28628cdc3d7Sszhou }
28728cdc3d7Sszhou 
28828cdc3d7Sszhou /*
28928cdc3d7Sszhou  * Free up any resources that we allocated in the above initialization
29028cdc3d7Sszhou  * routine.
29128cdc3d7Sszhou  */
29228cdc3d7Sszhou int
29328cdc3d7Sszhou usb_console_output_fini(usb_console_info_t console_output_info)
29428cdc3d7Sszhou {
29528cdc3d7Sszhou 	usb_console_info_impl_t	*usb_console_output;
29628cdc3d7Sszhou 	usba_device_t		*usb_device;
29728cdc3d7Sszhou 	int			ret;
29828cdc3d7Sszhou 
29928cdc3d7Sszhou 	usb_console_output = (usb_console_info_impl_t *)console_output_info;
30028cdc3d7Sszhou 
30128cdc3d7Sszhou 	/*
30228cdc3d7Sszhou 	 * Translate the dip into a device.
30328cdc3d7Sszhou 	 */
30428cdc3d7Sszhou 	usb_device = usba_polled_get_usba_device(usb_console_output->uci_dip);
30528cdc3d7Sszhou 
30628cdc3d7Sszhou 	/*
30728cdc3d7Sszhou 	 * Call the lower layer to free any state information.
30828cdc3d7Sszhou 	 */
30928cdc3d7Sszhou 	ret = usb_device->usb_hcdi_ops->usba_hcdi_console_output_fini(
31028cdc3d7Sszhou 	    usb_console_output);
31128cdc3d7Sszhou 
31228cdc3d7Sszhou 	if (ret == USB_FAILURE) {
31328cdc3d7Sszhou 
31428cdc3d7Sszhou 		return (ret);
31528cdc3d7Sszhou 	}
31628cdc3d7Sszhou 
31728cdc3d7Sszhou 	/*
31828cdc3d7Sszhou 	 * We won't be needing this information anymore.
31928cdc3d7Sszhou 	 */
32028cdc3d7Sszhou 	kmem_free(usb_console_output, sizeof (struct usb_console_info_impl));
32128cdc3d7Sszhou 
32228cdc3d7Sszhou 	return (USB_SUCCESS);
32328cdc3d7Sszhou }
32428cdc3d7Sszhou 
32528cdc3d7Sszhou /*
32628cdc3d7Sszhou  * This is the routine that OBP calls to save the USB state information
32728cdc3d7Sszhou  * before using the USB device as an output device.  This routine,
32828cdc3d7Sszhou  * and all of the routines that it calls, are responsible for saving
32928cdc3d7Sszhou  * any state information so that it can be restored when OBP mode is
33028cdc3d7Sszhou  * over.  At this layer, this code is mainly just a pass through.
33128cdc3d7Sszhou  */
33228cdc3d7Sszhou int
33328cdc3d7Sszhou usb_console_output_enter(usb_console_info_t console_output_info)
33428cdc3d7Sszhou {
33528cdc3d7Sszhou 	usba_device_t			    *usb_device;
33628cdc3d7Sszhou 	usb_console_info_impl_t		 *usb_console_output;
33728cdc3d7Sszhou 
33828cdc3d7Sszhou 	usb_console_output = (usb_console_info_impl_t *)console_output_info;
33928cdc3d7Sszhou 
34028cdc3d7Sszhou 	/*
34128cdc3d7Sszhou 	 * Translate the dip into a device.
34228cdc3d7Sszhou 	 */
34328cdc3d7Sszhou 	usb_device = usba_polled_get_usba_device(usb_console_output->uci_dip);
34428cdc3d7Sszhou 
34528cdc3d7Sszhou 	/*
34628cdc3d7Sszhou 	 * Call the lower layer to save state information.
34728cdc3d7Sszhou 	 */
34828cdc3d7Sszhou 	usb_device->usb_hcdi_ops->usba_hcdi_console_output_enter(
34928cdc3d7Sszhou 	    usb_console_output);
35028cdc3d7Sszhou 
35128cdc3d7Sszhou 	return (USB_SUCCESS);
35228cdc3d7Sszhou }
35328cdc3d7Sszhou 
35428cdc3d7Sszhou /*
35528cdc3d7Sszhou  * This is the routine that OBP calls when it wants to write a character.
35628cdc3d7Sszhou  * We will call to the lower layers to write any data
35728cdc3d7Sszhou  * At this layer, this code is mainly just a pass through.
35828cdc3d7Sszhou  */
35928cdc3d7Sszhou int
36028cdc3d7Sszhou usb_console_write(usb_console_info_t console_output_info,
36128cdc3d7Sszhou 	uchar_t *buf, uint_t num_characters, uint_t *num_characters_written)
36228cdc3d7Sszhou {
36328cdc3d7Sszhou 	usba_device_t		*usb_device;
36428cdc3d7Sszhou 	usb_console_info_impl_t	*usb_console_output;
36528cdc3d7Sszhou 
36628cdc3d7Sszhou 	usb_console_output = (usb_console_info_impl_t *)console_output_info;
36728cdc3d7Sszhou 
36828cdc3d7Sszhou 	/*
36928cdc3d7Sszhou 	 * Translate the dip into a device.
37028cdc3d7Sszhou 	 */
37128cdc3d7Sszhou 	usb_device = usba_polled_get_usba_device(usb_console_output->uci_dip);
37228cdc3d7Sszhou 
37328cdc3d7Sszhou 	/*
37428cdc3d7Sszhou 	 * Call the lower layer to get a a character.  Return the number
37528cdc3d7Sszhou 	 * of characters read into the buffer.
37628cdc3d7Sszhou 	 */
37728cdc3d7Sszhou 	return (usb_device->usb_hcdi_ops->usba_hcdi_console_write(
37828cdc3d7Sszhou 	    usb_console_output, buf, num_characters,
37928cdc3d7Sszhou 	    num_characters_written));
38028cdc3d7Sszhou }
38128cdc3d7Sszhou 
38228cdc3d7Sszhou /*
38328cdc3d7Sszhou  * This is the routine that OBP calls when it is giving up control of the
38428cdc3d7Sszhou  * USB output device.  This routine, and the lower layer routines that it
38528cdc3d7Sszhou  * calls, are responsible for restoring the controller state to the state
38628cdc3d7Sszhou  * it was in before OBP took control. At this layer, this code is mainly
38728cdc3d7Sszhou  * just a pass through.
38828cdc3d7Sszhou  */
38928cdc3d7Sszhou int
39028cdc3d7Sszhou usb_console_output_exit(usb_console_info_t console_output_info)
39128cdc3d7Sszhou {
39228cdc3d7Sszhou 	usba_device_t			 *usb_device;
39328cdc3d7Sszhou 	usb_console_info_impl_t		 *usb_console_output;
39428cdc3d7Sszhou 
39528cdc3d7Sszhou 	usb_console_output = (usb_console_info_impl_t *)console_output_info;
39628cdc3d7Sszhou 
39728cdc3d7Sszhou 	/*
39828cdc3d7Sszhou 	 * Translate the dip into a device.
39928cdc3d7Sszhou 	 */
40028cdc3d7Sszhou 	usb_device = usba_polled_get_usba_device(usb_console_output->uci_dip);
40128cdc3d7Sszhou 
40228cdc3d7Sszhou 	/*
40328cdc3d7Sszhou 	 * Restore the state information.
40428cdc3d7Sszhou 	 */
40528cdc3d7Sszhou 	usb_device->usb_hcdi_ops->usba_hcdi_console_output_exit(
40628cdc3d7Sszhou 	    usb_console_output);
40728cdc3d7Sszhou 
40828cdc3d7Sszhou 	return (USB_SUCCESS);
40928cdc3d7Sszhou }
410