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