source: mainline/uspace/drv/usbhub/usbhub_private.h@ 7964475

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

various convenience definitions
removing of usb_hcd_hub_info_t from public declarations
usb-side implementation of adding a new device (assign addressand enable port)

  • Property mode set to 100644
File size: 4.5 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/devreq.h>
45
46//************
47//
48// convenience define for malloc
49//
50//************
51#define usb_new(type) (type*)malloc(sizeof(type))
52
53
54//************
55//
56// My private list implementation; I did not like the original helenos list
57//
58// This one does not depend on the structure of stored data
59//
60//************
61
62/** general list structure */
63
64
65typedef struct usb_general_list{
66 void * data;
67 struct usb_general_list * prev, * next;
68} usb_general_list_t;
69
70/** create head of usb general list */
71usb_general_list_t * usb_lst_create(void);
72
73/** initialize head of usb general list */
74void usb_lst_init(usb_general_list_t * lst);
75
76
77/** is the list empty? */
78static inline bool usb_lst_empty(usb_general_list_t * lst){
79 return lst?(lst->next==lst):true;
80}
81
82/** append data behind item */
83void usb_lst_append(usb_general_list_t * lst, void * data);
84
85/** prepend data beore item */
86void usb_lst_prepend(usb_general_list_t * lst, void * data);
87
88/** remove list item from list */
89void usb_lst_remove(usb_general_list_t * item);
90
91/** get data o specified type from list item */
92#define usb_lst_get_data(item, type) (type *) (item->data)
93
94/** get usb_hub_info_t data from list item */
95static inline usb_hub_info_t * usb_hub_lst_get_data(usb_general_list_t * item) {
96 return usb_lst_get_data(item,usb_hub_info_t);
97}
98
99/**
100 * @brief create hub structure instance
101 *
102 * @param device
103 * @return
104 */
105usb_hub_info_t * usb_create_hub_info(device_t * device);
106
107/** list of hubs maanged by this driver */
108extern usb_general_list_t usb_hub_list;
109
110
111/**
112 * @brief perform complete control read transaction
113 *
114 * manages all three steps of transaction: setup, read and finalize
115 * @param phone
116 * @param target
117 * @param request request for data
118 * @param rcvd_buffer received data
119 * @param rcvd_size
120 * @param actual_size actual size of received data
121 * @return error code
122 */
123int usb_drv_sync_control_read(
124 int phone, usb_target_t target,
125 usb_device_request_setup_packet_t * request,
126 void * rcvd_buffer, size_t rcvd_size, size_t * actual_size
127);
128
129/**
130 * @brief perform complete control write transaction
131 *
132 * maanges all three steps of transaction: setup, write and finalize
133 * @param phone
134 * @param target
135 * @param request request to send data
136 * @param sent_buffer
137 * @param sent_size
138 * @return error code
139 */
140int usb_drv_sync_control_write(
141 int phone, usb_target_t target,
142 usb_device_request_setup_packet_t * request,
143 void * sent_buffer, size_t sent_size
144);
145
146
147/**
148 * set the device requsst to be a set address request
149 * @param request
150 * @param addr
151 */
152static inline void usb_hub_set_set_address_request(
153usb_device_request_setup_packet_t * request, uint16_t addr
154){
155 request->index = 0;
156 request->request_type = 0;/// \TODO this is not very nice sollution
157 request->request = USB_DEVREQ_SET_ADDRESS;
158 request->value = addr;
159 request->length = 0;
160}
161
162
163#endif /* USBHUB_PRIVATE_H */
164
165/**
166 * @}
167 */
Note: See TracBrowser for help on using the repository browser.