source: mainline/uspace/drv/bus/usb/vhc/vhcd.h

Last change on this file was 36795edf, checked in by Martin Decky <martin@…>, 4 years ago

Improve lists and other data structures

Provide more standard-compliant member_to_inst implementation that uses
offsetof. Avoid potential undefined behavior in list_foreach and
list_foreach_rev by avoiding assinging an unaligned pointer value. Use
size_t instead of unsigned long for list length.

  • Property mode set to 100644
File size: 3.0 KB
Line 
1/*
2 * Copyright (c) 2010 Vojtech Horky
3 * Copyright (c) 2018 Ondrej Hlavaty
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30/** @addtogroup drvusbvhc
31 * @{
32 */
33/** @file
34 * @brief Virtual USB host controller common definitions.
35 */
36
37#ifndef VHCD_VHCD_H_
38#define VHCD_VHCD_H_
39
40#include <usbvirt/device.h>
41#include <async.h>
42#include <macros.h>
43#include <member.h>
44
45#include <usb/host/hcd.h>
46#include <usb/host/usb2_bus.h>
47#include <usb/host/usb_transfer_batch.h>
48
49#define NAME "vhc"
50
51typedef struct {
52 link_t link;
53 async_sess_t *dev_sess;
54 usbvirt_device_t *dev_local;
55 bool plugged;
56 usb_address_t address;
57 fibril_mutex_t guard;
58 list_t transfer_queue;
59} vhc_virtdev_t;
60
61typedef struct {
62 hc_device_t base;
63
64 bus_t bus;
65 usb2_bus_helper_t bus_helper;
66
67 ddf_fun_t *virtual_fun;
68 list_t devices;
69 fibril_mutex_t guard;
70 usbvirt_device_t hub;
71} vhc_data_t;
72
73typedef struct {
74 usb_transfer_batch_t batch;
75 link_t link;
76} vhc_transfer_t;
77
78static inline vhc_data_t *hcd_to_vhc(hc_device_t *hcd)
79{
80 assert(hcd);
81 return (vhc_data_t *) hcd;
82}
83
84static inline vhc_data_t *bus_to_vhc(bus_t *bus)
85{
86 assert(bus);
87 return member_to_inst(bus, vhc_data_t, bus);
88}
89
90void on_client_close(ddf_fun_t *fun);
91void default_connection_handler(ddf_fun_t *fun, ipc_call_t *icall);
92
93errno_t vhc_virtdev_plug(vhc_data_t *, async_sess_t *, uintptr_t *);
94errno_t vhc_virtdev_plug_local(vhc_data_t *, usbvirt_device_t *, uintptr_t *);
95errno_t vhc_virtdev_plug_hub(vhc_data_t *, usbvirt_device_t *, uintptr_t *,
96 usb_address_t address);
97void vhc_virtdev_unplug(vhc_data_t *, uintptr_t);
98
99errno_t vhc_init(vhc_data_t *);
100errno_t vhc_schedule(usb_transfer_batch_t *);
101errno_t vhc_transfer_queue_processor(void *arg);
102
103#endif
104
105/**
106 * @}
107 */
Note: See TracBrowser for help on using the repository browser.