xref: /illumos-gate/usr/src/uts/common/sys/usb/hcd/uhci/uhciutil.h (revision 1a220b56b93ff1dc80855691548503117af4cc10)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _SYS_USB_UHCIUTIL_H
27 #define	_SYS_USB_UHCIUTIL_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 /*
36  * Universal Host Controller Driver(UHCI)
37  *
38  * The UHCI driver is a software driver which interfaces to the Universal
39  * Serial Bus Driver(USBA) and the Host Controller(HC). The interface to
40  * the Host Controller is defined by the UHCI.
41  */
42 int	uhci_hcdi_pipe_open(usba_pipe_handle_data_t *pipe_handle,
43 		    usb_flags_t flags);
44 int	uhci_hcdi_pipe_close(usba_pipe_handle_data_t *pipe_handle,
45 		    usb_flags_t flags);
46 int	uhci_hcdi_pipe_reset(usba_pipe_handle_data_t *pipe_handle,
47 		    usb_flags_t usb_flags);
48 int	uhci_hcdi_pipe_ctrl_xfer(usba_pipe_handle_data_t *,
49 		    usb_ctrl_req_t *, usb_flags_t);
50 int	uhci_hcdi_pipe_bulk_xfer(usba_pipe_handle_data_t *,
51 		    usb_bulk_req_t *, usb_flags_t);
52 int	uhci_hcdi_pipe_isoc_xfer(usba_pipe_handle_data_t *,
53 		    usb_isoc_req_t *, usb_flags_t);
54 int	uhci_hcdi_pipe_intr_xfer(usba_pipe_handle_data_t *,
55 		    usb_intr_req_t *, usb_flags_t);
56 int	uhci_hcdi_bulk_transfer_size(usba_device_t *usba_device,
57 		    size_t  *size);
58 int	uhci_hcdi_pipe_stop_intr_polling(
59 		    usba_pipe_handle_data_t *pipe_handle, usb_flags_t flags);
60 int	uhci_hcdi_pipe_stop_isoc_polling(usba_pipe_handle_data_t *ph,
61 		    usb_flags_t flags);
62 usb_frame_number_t uhci_hcdi_get_current_frame_number(
63 		    usba_device_t *usba_device);
64 uint_t	uhci_hcdi_get_max_isoc_pkts(usba_device_t *usba_device);
65 
66 /* Root hub prototypes */
67 int	uhci_handle_root_hub_request(
68 		    uhci_state_t		*uhcip,
69 		    usba_pipe_handle_data_t	*pipe_handle,
70 		    usb_ctrl_req_t	*req);
71 
72 void	uhci_handle_ctrl_td(uhci_state_t *uhcip, uhci_td_t *td);
73 int	uhci_insert_bulk_td(uhci_state_t *uhcip,
74 		    usba_pipe_handle_data_t *ph,
75 		    usb_bulk_req_t *req, usb_flags_t flags);
76 void	uhci_handle_intr_td(uhci_state_t *uhcip, uhci_td_t *td);
77 void	uhci_sendup_td_message(uhci_state_t *uhcip, usb_cr_t,
78 		    uhci_trans_wrapper_t *tw);
79 usb_cr_t uhci_parse_td_error(uhci_state_t *uhcip,
80 		    uhci_pipe_private_t *pp, uhci_td_t *td);
81 void	uhci_process_submitted_td_queue(uhci_state_t *uhcip);
82 void	uhci_delete_td(uhci_state_t *uhcip, uhci_td_t *td);
83 
84 /* global HCDI prototypes */
85 usba_hcdi_ops_t	*uhci_alloc_hcdi_ops(uhci_state_t *uhcip);
86 int	uhci_hcdi_polled_input_init(
87 		    usba_pipe_handle_data_t *uhcip,
88 		    uchar_t **polledbuf, usb_console_info_impl_t *info);
89 int	uhci_hcdi_polled_input_enter(usb_console_info_impl_t *info);
90 int	uhci_hcdi_polled_read(usb_console_info_impl_t *info, uint_t *num);
91 int	uhci_hcdi_polled_input_exit(usb_console_info_impl_t *info);
92 int	uhci_hcdi_polled_input_fini(usb_console_info_impl_t *info);
93 void	uhci_hcdi_callback(uhci_state_t *uhcip,
94 		    uhci_pipe_private_t *pp,
95 		    usba_pipe_handle_data_t *ph, uhci_trans_wrapper_t *tw,
96 		    usb_cr_t cr);
97 
98 void	uhci_set_dma_attributes(uhci_state_t *uhcip);
99 void	uhci_remove_qh(uhci_state_t *uhcip, uhci_pipe_private_t *pp);
100 void	uhci_insert_qh(uhci_state_t *uhcip,
101 		    usba_pipe_handle_data_t *pipe_handle);
102 void	uhci_decode_ddi_dma_addr_bind_handle_result(uhci_state_t *uhcip,
103 		    int result);
104 int	uhci_allocate_pools(uhci_state_t *uhcip);
105 void	uhci_free_pools(uhci_state_t *uhcip);
106 int	uhci_init_ctlr(uhci_state_t *uhcip);
107 void	uhci_uninit_ctlr(uhci_state_t *uhcip);
108 int	uhci_map_regs(uhci_state_t *uhcip);
109 void	uhci_unmap_regs(uhci_state_t *uhcip);
110 int	uhci_insert_hc_td(uhci_state_t *uhcip,
111 		    uint32_t buffer_address, size_t hcgtd_length,
112 		    uhci_pipe_private_t	*pp, uhci_trans_wrapper_t *tw,
113 		    uchar_t PID, usb_req_attrs_t attrs);
114 
115 int	uhci_allocate_periodic_in_resource(uhci_state_t *uhcip,
116 		    uhci_pipe_private_t *pp, uhci_trans_wrapper_t *tw,
117 		    usb_flags_t flags);
118 void	uhci_deallocate_periodic_in_resource(uhci_state_t *uhcip,
119 		    uhci_pipe_private_t *pp, uhci_trans_wrapper_t *tw);
120 void	uhci_do_intrs_stats(uhci_state_t *uhcip, int val);
121 void	uhci_do_byte_stats(uhci_state_t *, size_t, uint8_t, uint8_t);
122 void	uhci_deallocate_tw(uhci_state_t *uhcip, uhci_pipe_private_t *pp,
123 		    uhci_trans_wrapper_t *tw);
124 
125 /* other generic global prototypes */
126 uhci_state_t	*uhci_obtain_state(dev_info_t *dip);
127 queue_head_t	*uhci_alloc_queue_head(uhci_state_t *uhcip);
128 void	uhci_save_data_toggle(uhci_pipe_private_t *pp);
129 int	uhci_wait_for_sof(uhci_state_t *uhcip);
130 void	uhci_modify_td_active_bits(uhci_state_t *uhcip,
131 	    uhci_pipe_private_t *pp);
132 void	uhci_deallocate_bandwidth(uhci_state_t *uhcip,
133 		usba_pipe_handle_data_t *pipe_handle);
134 int	uhci_allocate_bandwidth(uhci_state_t *uhcip,
135 		    usba_pipe_handle_data_t *pipe_handle, uint_t *node);
136 void	uhci_remove_tds_tws(uhci_state_t *uhcip,
137 		usba_pipe_handle_data_t *ph);
138 void	uhci_free_tw(uhci_state_t *uhcip, uhci_trans_wrapper_t *tw);
139 void	uhci_insert_qh(uhci_state_t *uhcip,
140 		usba_pipe_handle_data_t *pipe_handle);
141 void	uhci_cmd_timeout_hdlr(void *arg);
142 
143 /* Control prototypes */
144 int	uhci_insert_ctrl_td(uhci_state_t *uhcip,
145 		usba_pipe_handle_data_t *pipe_handle,
146 		usb_ctrl_req_t *req, usb_flags_t flags);
147 
148 /* Intr prototypes */
149 int	uhci_insert_intr_td(uhci_state_t *uhcip,
150 		usba_pipe_handle_data_t *pipe_handle,
151 		usb_intr_req_t *req, usb_flags_t flags);
152 
153 /* Bulk prototypes */
154 void	uhci_handle_bulk_td(uhci_state_t *uhcip, uhci_td_t *td);
155 void	uhci_fill_in_bulk_isoc_td(uhci_state_t *uhcip,
156 		uhci_td_t *current_td, uhci_td_t *next_td,
157 		uint32_t next_td_paddr, usba_pipe_handle_data_t *ph,
158 		uint_t offset, uint_t length,
159 		uhci_trans_wrapper_t *tw);
160 void	uhci_remove_bulk_tds_tws(uhci_state_t *uhcip,
161 		uhci_pipe_private_t *pp, int);
162 
163 /* Isoc prototypes */
164 int	uhci_insert_isoc_td(uhci_state_t *uhcip,
165 		usba_pipe_handle_data_t *ph, usb_isoc_req_t *isoc_req,
166 		size_t length, usb_flags_t usb_flags);
167 void	uhci_handle_isoc_td(uhci_state_t *uhcip, uhci_td_t *td);
168 int	uhci_start_isoc_receive_polling(
169 		uhci_state_t *uhcip, usba_pipe_handle_data_t *ph,
170 		usb_isoc_req_t *isoc_req, usb_flags_t usb_flags);
171 void	uhci_remove_isoc_tds_tws(uhci_state_t *uhcip,
172 		uhci_pipe_private_t *ph);
173 uint64_t uhci_get_sw_frame_number(uhci_state_t *uhcip);
174 void	uhci_isoc_update_sw_frame_number(uhci_state_t *uhcip);
175 
176 /* kstat support */
177 void	uhci_create_stats(uhci_state_t *uhcip);
178 void	uhci_destroy_stats(uhci_state_t *uhcip);
179 
180 /* arithmetic goodies */
181 uint_t  pow_2(unsigned int x);
182 uint_t  log_2(unsigned int x);
183 
184 #ifdef __cplusplus
185 }
186 #endif
187 
188 #endif /* _SYS_USB_UHCIUTIL_H */
189