xref: /illumos-gate/usr/src/uts/common/sys/usb/hcd/uhci/uhciutil.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SYS_USB_UHCIUTIL_H
28 #define	_SYS_USB_UHCIUTIL_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 /*
37  * Universal Host Controller Driver(UHCI)
38  *
39  * The UHCI driver is a software driver which interfaces to the Universal
40  * Serial Bus Driver(USBA) and the Host Controller(HC). The interface to
41  * the Host Controller is defined by the UHCI.
42  */
43 int	uhci_hcdi_pipe_open(usba_pipe_handle_data_t *pipe_handle,
44 		    usb_flags_t flags);
45 int	uhci_hcdi_pipe_close(usba_pipe_handle_data_t *pipe_handle,
46 		    usb_flags_t flags);
47 int	uhci_hcdi_pipe_reset(usba_pipe_handle_data_t *pipe_handle,
48 		    usb_flags_t usb_flags);
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 usb_frame_number_t uhci_hcdi_get_current_frame_number(
64 		    usba_device_t *usba_device);
65 uint_t	uhci_hcdi_get_max_isoc_pkts(usba_device_t *usba_device);
66 
67 /* Root hub prototypes */
68 int	uhci_handle_root_hub_request(
69 		    uhci_state_t		*uhcip,
70 		    usba_pipe_handle_data_t	*pipe_handle,
71 		    usb_ctrl_req_t	*req);
72 
73 void	uhci_handle_ctrl_td(uhci_state_t *uhcip, uhci_td_t *td);
74 int	uhci_insert_bulk_td(uhci_state_t *uhcip,
75 		    usba_pipe_handle_data_t *ph,
76 		    usb_bulk_req_t *req, usb_flags_t flags);
77 void	uhci_handle_intr_td(uhci_state_t *uhcip, uhci_td_t *td);
78 void	uhci_sendup_td_message(uhci_state_t *uhcip, usb_cr_t,
79 		    uhci_trans_wrapper_t *tw);
80 usb_cr_t uhci_parse_td_error(uhci_state_t *uhcip,
81 		    uhci_pipe_private_t *pp, uhci_td_t *td);
82 void	uhci_process_submitted_td_queue(uhci_state_t *uhcip);
83 void	uhci_delete_td(uhci_state_t *uhcip, uhci_td_t *td);
84 
85 /* global HCDI prototypes */
86 usba_hcdi_ops_t	*uhci_alloc_hcdi_ops(uhci_state_t *uhcip);
87 int	uhci_hcdi_polled_input_init(
88 		    usba_pipe_handle_data_t *uhcip,
89 		    uchar_t **polledbuf, usb_console_info_impl_t *info);
90 int	uhci_hcdi_polled_input_enter(usb_console_info_impl_t *info);
91 int	uhci_hcdi_polled_read(usb_console_info_impl_t *info, uint_t *num);
92 int	uhci_hcdi_polled_input_exit(usb_console_info_impl_t *info);
93 int	uhci_hcdi_polled_input_fini(usb_console_info_impl_t *info);
94 void	uhci_hcdi_callback(uhci_state_t *uhcip,
95 		    uhci_pipe_private_t *pp,
96 		    usba_pipe_handle_data_t *ph, uhci_trans_wrapper_t *tw,
97 		    usb_cr_t cr);
98 
99 void	uhci_set_dma_attributes(uhci_state_t *uhcip);
100 void	uhci_remove_qh(uhci_state_t *uhcip, uhci_pipe_private_t *pp);
101 void	uhci_insert_qh(uhci_state_t *uhcip,
102 		    usba_pipe_handle_data_t *pipe_handle);
103 void	uhci_decode_ddi_dma_addr_bind_handle_result(uhci_state_t *uhcip,
104 		    int result);
105 int	uhci_allocate_pools(uhci_state_t *uhcip);
106 void	uhci_free_pools(uhci_state_t *uhcip);
107 int	uhci_init_ctlr(uhci_state_t *uhcip);
108 void	uhci_uninit_ctlr(uhci_state_t *uhcip);
109 int	uhci_map_regs(uhci_state_t *uhcip);
110 void	uhci_unmap_regs(uhci_state_t *uhcip);
111 int	uhci_insert_hc_td(uhci_state_t *uhcip,
112 		    uint32_t buffer_address, size_t hcgtd_length,
113 		    uhci_pipe_private_t	*pp, uhci_trans_wrapper_t *tw,
114 		    uchar_t PID, usb_req_attrs_t attrs);
115 
116 int	uhci_allocate_periodic_in_resource(uhci_state_t *uhcip,
117 		    uhci_pipe_private_t *pp, uhci_trans_wrapper_t *tw,
118 		    usb_flags_t flags);
119 void	uhci_deallocate_periodic_in_resource(uhci_state_t *uhcip,
120 		    uhci_pipe_private_t *pp, uhci_trans_wrapper_t *tw);
121 void	uhci_do_intrs_stats(uhci_state_t *uhcip, int val);
122 void	uhci_do_byte_stats(uhci_state_t *, size_t, uint8_t, uint8_t);
123 void	uhci_deallocate_tw(uhci_state_t *uhcip, uhci_pipe_private_t *pp,
124 		    uhci_trans_wrapper_t *tw);
125 
126 /* other generic global prototypes */
127 uhci_state_t	*uhci_obtain_state(dev_info_t *dip);
128 queue_head_t	*uhci_alloc_queue_head(uhci_state_t *uhcip);
129 void	uhci_save_data_toggle(uhci_pipe_private_t *pp);
130 int	uhci_wait_for_sof(uhci_state_t *uhcip);
131 void	uhci_modify_td_active_bits(uhci_state_t *uhcip,
132 	    uhci_pipe_private_t *pp);
133 void	uhci_deallocate_bandwidth(uhci_state_t *uhcip,
134 		usba_pipe_handle_data_t *pipe_handle);
135 int	uhci_allocate_bandwidth(uhci_state_t *uhcip,
136 		    usba_pipe_handle_data_t *pipe_handle, uint_t *node);
137 void	uhci_remove_tds_tws(uhci_state_t *uhcip,
138 		usba_pipe_handle_data_t *ph);
139 void	uhci_free_tw(uhci_state_t *uhcip, uhci_trans_wrapper_t *tw);
140 void	uhci_insert_qh(uhci_state_t *uhcip,
141 		usba_pipe_handle_data_t *pipe_handle);
142 void	uhci_cmd_timeout_hdlr(void *arg);
143 
144 /* Control prototypes */
145 int	uhci_insert_ctrl_td(uhci_state_t *uhcip,
146 		usba_pipe_handle_data_t *pipe_handle,
147 		usb_ctrl_req_t *req, usb_flags_t flags);
148 
149 /* Intr prototypes */
150 int	uhci_insert_intr_td(uhci_state_t *uhcip,
151 		usba_pipe_handle_data_t *pipe_handle,
152 		usb_intr_req_t *req, usb_flags_t flags);
153 
154 /* Bulk prototypes */
155 void	uhci_handle_bulk_td(uhci_state_t *uhcip, uhci_td_t *td);
156 void	uhci_fill_in_bulk_isoc_td(uhci_state_t *uhcip,
157 		uhci_td_t *current_td, uhci_td_t *next_td,
158 		uint32_t next_td_paddr, usba_pipe_handle_data_t *ph,
159 		uint_t buffer_address, uint_t length,
160 		uhci_trans_wrapper_t *tw);
161 void	uhci_remove_bulk_tds_tws(uhci_state_t *uhcip,
162 		uhci_pipe_private_t *pp, int);
163 
164 /* Isoc prototypes */
165 int	uhci_insert_isoc_td(uhci_state_t *uhcip,
166 		usba_pipe_handle_data_t *ph, usb_isoc_req_t *isoc_req,
167 		size_t length, usb_flags_t usb_flags);
168 void	uhci_handle_isoc_td(uhci_state_t *uhcip, uhci_td_t *td);
169 int	uhci_start_isoc_receive_polling(
170 		uhci_state_t *uhcip, usba_pipe_handle_data_t *ph,
171 		usb_isoc_req_t *isoc_req, usb_flags_t usb_flags);
172 void	uhci_remove_isoc_tds_tws(uhci_state_t *uhcip,
173 		uhci_pipe_private_t *ph);
174 uint64_t uhci_get_sw_frame_number(uhci_state_t *uhcip);
175 void	uhci_isoc_update_sw_frame_number(uhci_state_t *uhcip);
176 
177 /* kstat support */
178 void	uhci_create_stats(uhci_state_t *uhcip);
179 void	uhci_destroy_stats(uhci_state_t *uhcip);
180 
181 /* arithmetic goodies */
182 uint_t  pow_2(unsigned int x);
183 uint_t  log_2(unsigned int x);
184 
185 #ifdef __cplusplus
186 }
187 #endif
188 
189 #endif /* _SYS_USB_UHCIUTIL_H */
190