source: mainline/uspace/drv/usbhub/usbhub_private.h@ 4f380d06

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

little bit codelifting

  • Property mode set to 100644
File size: 4.6 KB
RevLine 
[b5ec347]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
[f40a1e2]33 * @brief Hub driver private definitions
[b5ec347]34 */
35
36#ifndef USBHUB_PRIVATE_H
37#define USBHUB_PRIVATE_H
38
39#include "usbhub.h"
[e080332]40#include "usblist.h"
41
[b5ec347]42#include <adt/list.h>
43#include <bool.h>
44#include <driver.h>
[5097bed4]45#include <futex.h>
46
[b5ec347]47#include <usb/usb.h>
[e080332]48#include <usb/usbdrv.h>
[10096231]49#include <usb/classes/hub.h>
[b5ec347]50#include <usb/devreq.h>
[e080332]51#include <usb/debug.h>
[b5ec347]52
53//************
54//
55// convenience define for malloc
56//
57//************
58#define usb_new(type) (type*)malloc(sizeof(type))
59
60
61//************
62//
[e080332]63// convenience debug printf
[b5ec347]64//
65//************
[e080332]66#define dprintf(level, format, ...) \
67 usb_dprintf(NAME, (level), format "\n", ##__VA_ARGS__)
[b5ec347]68
69/**
[f40a1e2]70 * Create hub structure instance
[b5ec347]71 *
[98d06b8]72 * Set the address and port count information most importantly.
73 *
[b5ec347]74 * @param device
[98d06b8]75 * @param hc host controller phone
[b5ec347]76 * @return
77 */
[98d06b8]78usb_hub_info_t * usb_create_hub_info(device_t * device, int hc);
[b5ec347]79
[f40a1e2]80/** List of hubs maanged by this driver */
[b5ec347]81extern usb_general_list_t usb_hub_list;
82
[f40a1e2]83/** Lock for hub list*/
[5097bed4]84extern futex_t usb_hub_list_lock;
85
[b5ec347]86
87/**
[f40a1e2]88 * Perform complete control read transaction
[b5ec347]89 *
[f40a1e2]90 * Manages all three steps of transaction: setup, read and finalize
[b5ec347]91 * @param phone
92 * @param target
[f40a1e2]93 * @param request Request packet
94 * @param rcvd_buffer Received data
[b5ec347]95 * @param rcvd_size
[f40a1e2]96 * @param actual_size Actual size of received data
[b5ec347]97 * @return error code
98 */
99int usb_drv_sync_control_read(
100 int phone, usb_target_t target,
101 usb_device_request_setup_packet_t * request,
102 void * rcvd_buffer, size_t rcvd_size, size_t * actual_size
103);
104
105/**
[f40a1e2]106 * Perform complete control write transaction
[b5ec347]107 *
[f40a1e2]108 * Manages all three steps of transaction: setup, write and finalize
[b5ec347]109 * @param phone
110 * @param target
[f40a1e2]111 * @param request Request packet to send data
[b5ec347]112 * @param sent_buffer
113 * @param sent_size
114 * @return error code
115 */
116int usb_drv_sync_control_write(
117 int phone, usb_target_t target,
118 usb_device_request_setup_packet_t * request,
119 void * sent_buffer, size_t sent_size
120);
121
[98d06b8]122/**
[f40a1e2]123 * Set the device request to be a get hub descriptor request.
[98d06b8]124 * @warning the size is allways set to USB_HUB_MAX_DESCRIPTOR_SIZE
125 * @param request
126 * @param addr
127 */
[10096231]128static inline void usb_hub_set_descriptor_request(
[98d06b8]129usb_device_request_setup_packet_t * request
130){
131 request->index = 0;
132 request->request_type = USB_HUB_REQ_TYPE_GET_DESCRIPTOR;
133 request->request = USB_HUB_REQUEST_GET_DESCRIPTOR;
[10096231]134 request->value_high = USB_DESCTYPE_HUB;
135 request->value_low = 0;
[98d06b8]136 request->length = USB_HUB_MAX_DESCRIPTOR_SIZE;
137}
138
[f40a1e2]139/**
140 * Clear feature on hub port.
141 *
142 * @param hc Host controller telephone
143 * @param address Hub address
144 * @param port_index Port
145 * @param feature Feature selector
146 * @return Operation result
147 */
[f9a0cef]148static inline int usb_hub_clear_port_feature(int hc, usb_address_t address,
149 int port_index,
150 usb_hub_class_feature_t feature) {
151 usb_target_t target = {
152 .address = address,
153 .endpoint = 0
154 };
155 usb_device_request_setup_packet_t clear_request = {
156 .request_type = USB_HUB_REQ_TYPE_CLEAR_PORT_FEATURE,
157 .request = USB_DEVREQ_CLEAR_FEATURE,
158 .length = 0,
159 .index = port_index
160 };
161 clear_request.value = feature;
162 return usb_drv_psync_control_write(hc, target, &clear_request,
163 sizeof(clear_request), NULL, 0);
164}
165
[98d06b8]166
[b5ec347]167
168#endif /* USBHUB_PRIVATE_H */
169
170/**
171 * @}
172 */
Note: See TracBrowser for help on using the repository browser.