source: mainline/uspace/drv/usbhub/usbhub_private.h@ 94c19b8

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 94c19b8 was 10096231, checked in by Matus Dekanek <smekideki@…>, 15 years ago

hub is successfully initialized

  • Property mode set to 100644
File size: 5.2 KB
Line 
1/*
2 * Copyright (c) 2010 Matus Dekanek
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup usb
30 * @{
31 */
32/** @file
33 * @brief Hub driver.
34 */
35
36#ifndef USBHUB_PRIVATE_H
37#define USBHUB_PRIVATE_H
38
39#include "usbhub.h"
40#include <adt/list.h>
41#include <bool.h>
42#include <driver.h>
43#include <usb/usb.h>
44#include <usb/classes/hub.h>
45#include <usb/devreq.h>
46
47//************
48//
49// convenience define for malloc
50//
51//************
52#define usb_new(type) (type*)malloc(sizeof(type))
53
54
55//************
56//
57// My private list implementation; I did not like the original helenos list
58//
59// This one does not depend on the structure of stored data
60//
61//************
62
63/** general list structure */
64
65
66typedef struct usb_general_list{
67 void * data;
68 struct usb_general_list * prev, * next;
69} usb_general_list_t;
70
71/** create head of usb general list */
72usb_general_list_t * usb_lst_create(void);
73
74/** initialize head of usb general list */
75void usb_lst_init(usb_general_list_t * lst);
76
77
78/** is the list empty? */
79static inline bool usb_lst_empty(usb_general_list_t * lst){
80 return lst?(lst->next==lst):true;
81}
82
83/** append data behind item */
84void usb_lst_append(usb_general_list_t * lst, void * data);
85
86/** prepend data beore item */
87void usb_lst_prepend(usb_general_list_t * lst, void * data);
88
89/** remove list item from list */
90void usb_lst_remove(usb_general_list_t * item);
91
92/** get data o specified type from list item */
93#define usb_lst_get_data(item, type) (type *) (item->data)
94
95/** get usb_hub_info_t data from list item */
96static inline usb_hub_info_t * usb_hub_lst_get_data(usb_general_list_t * item) {
97 return usb_lst_get_data(item,usb_hub_info_t);
98}
99
100/**
101 * @brief create hub structure instance
102 *
103 * Set the address and port count information most importantly.
104 *
105 * @param device
106 * @param hc host controller phone
107 * @return
108 */
109usb_hub_info_t * usb_create_hub_info(device_t * device, int hc);
110
111/** list of hubs maanged by this driver */
112extern usb_general_list_t usb_hub_list;
113
114
115/**
116 * @brief perform complete control read transaction
117 *
118 * manages all three steps of transaction: setup, read and finalize
119 * @param phone
120 * @param target
121 * @param request request for data
122 * @param rcvd_buffer received data
123 * @param rcvd_size
124 * @param actual_size actual size of received data
125 * @return error code
126 */
127int usb_drv_sync_control_read(
128 int phone, usb_target_t target,
129 usb_device_request_setup_packet_t * request,
130 void * rcvd_buffer, size_t rcvd_size, size_t * actual_size
131);
132
133/**
134 * @brief perform complete control write transaction
135 *
136 * maanges all three steps of transaction: setup, write and finalize
137 * @param phone
138 * @param target
139 * @param request request to send data
140 * @param sent_buffer
141 * @param sent_size
142 * @return error code
143 */
144int usb_drv_sync_control_write(
145 int phone, usb_target_t target,
146 usb_device_request_setup_packet_t * request,
147 void * sent_buffer, size_t sent_size
148);
149
150
151/**
152 * set the device request to be a set address request
153 * @param request
154 * @param addr
155 * \TODO this will be obsolete see usb/dev_req.h
156 */
157static inline void usb_hub_set_set_address_request(
158usb_device_request_setup_packet_t * request, uint16_t addr
159){
160 request->index = 0;
161 request->request_type = 0;/// \TODO this is not very nice sollution, we ned constant
162 request->request = USB_DEVREQ_SET_ADDRESS;
163 request->value = addr;
164 request->length = 0;
165}
166
167/**
168 * set the device request to be a get hub descriptor request.
169 * @warning the size is allways set to USB_HUB_MAX_DESCRIPTOR_SIZE
170 * @param request
171 * @param addr
172 */
173static inline void usb_hub_set_descriptor_request(
174usb_device_request_setup_packet_t * request
175){
176 request->index = 0;
177 request->request_type = USB_HUB_REQ_TYPE_GET_DESCRIPTOR;
178 request->request = USB_HUB_REQUEST_GET_DESCRIPTOR;
179 request->value_high = USB_DESCTYPE_HUB;
180 request->value_low = 0;
181 request->length = USB_HUB_MAX_DESCRIPTOR_SIZE;
182}
183
184
185
186#endif /* USBHUB_PRIVATE_H */
187
188/**
189 * @}
190 */
Note: See TracBrowser for help on using the repository browser.