source: mainline/uspace/drv/bus/usb/xhci/commands.h

Last change on this file was 09ab0a9a, checked in by Jiri Svoboda <jiri@…>, 7 years ago

Fix vertical spacing with new Ccheck revision.

  • Property mode set to 100644
File size: 4.5 KB
Line 
1/*
2 * Copyright (c) 2018 Jaroslav Jindrak, Petr Manek, Ondrej Hlavaty, Jan Hrach
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 drvusbxhci
30 * @{
31 */
32/** @file
33 * Utility functions used to place TRBs onto the command ring.
34 */
35
36#ifndef XHCI_COMMANDS_H
37#define XHCI_COMMANDS_H
38
39#include <adt/list.h>
40#include <stdbool.h>
41#include <fibril_synch.h>
42#include <usb/dma_buffer.h>
43#include "hw_struct/trb.h"
44#include "trb_ring.h"
45
46#define XHCI_COMMAND_TIMEOUT 10000000
47#define XHCI_CR_ABORT_TIMEOUT 5000000
48
49typedef struct xhci_hc xhci_hc_t;
50typedef struct xhci_input_ctx xhci_input_ctx_t;
51typedef struct xhci_port_bandwidth_ctx xhci_port_bandwidth_ctx_t;
52
53typedef enum xhci_cmd_type {
54 XHCI_CMD_ENABLE_SLOT,
55 XHCI_CMD_DISABLE_SLOT,
56 XHCI_CMD_ADDRESS_DEVICE,
57 XHCI_CMD_CONFIGURE_ENDPOINT,
58 XHCI_CMD_EVALUATE_CONTEXT,
59 XHCI_CMD_RESET_ENDPOINT,
60 XHCI_CMD_STOP_ENDPOINT,
61 XHCI_CMD_SET_TR_DEQUEUE_POINTER,
62 XHCI_CMD_RESET_DEVICE,
63 XHCI_CMD_FORCE_EVENT,
64 XHCI_CMD_NEGOTIATE_BANDWIDTH,
65 XHCI_CMD_SET_LATENCY_TOLERANCE_VALUE,
66 XHCI_CMD_GET_PORT_BANDWIDTH,
67 XHCI_CMD_FORCE_HEADER,
68 XHCI_CMD_NO_OP,
69} xhci_cmd_type_t;
70
71typedef enum {
72 XHCI_CR_STATE_CLOSED, /**< Commands are rejected with ENAK. */
73 XHCI_CR_STATE_OPEN, /**< Commands are enqueued normally. */
74 XHCI_CR_STATE_CHANGING, /**< Commands wait until state changes. */
75 XHCI_CR_STATE_FULL, /**< Commands wait until something completes. */
76} xhci_cr_state_t;
77
78typedef struct xhci_command_ring {
79 xhci_trb_ring_t trb_ring;
80
81 /** Guard access to this structure. */
82 fibril_mutex_t guard;
83 list_t cmd_list;
84
85 /** Whether commands are allowed to be added. */
86 xhci_cr_state_t state;
87 /** For waiting on CR state change. */
88 fibril_condvar_t state_cv;
89
90 /** For waiting on CR stopped event. */
91 fibril_condvar_t stopped_cv;
92} xhci_cmd_ring_t;
93
94typedef struct xhci_command {
95 /** Internal fields used for bookkeeping. Need not worry about these. */
96 struct {
97 link_t link;
98
99 xhci_cmd_type_t cmd;
100
101 xhci_trb_t trb;
102 uintptr_t trb_phys;
103
104 bool async;
105 bool completed;
106
107 /* Will broadcast after command completes. */
108 fibril_mutex_t completed_mtx;
109 fibril_condvar_t completed_cv;
110 } _header;
111
112 /** Below are arguments of all commands mixed together.
113 * Be sure to know which command accepts what arguments.
114 */
115
116 uint32_t slot_id;
117 uint32_t endpoint_id;
118 uint16_t stream_id;
119
120 dma_buffer_t input_ctx, bandwidth_ctx;
121 uintptr_t dequeue_ptr;
122
123 bool tsp;
124 uint8_t susp;
125 uint8_t device_speed;
126 uint32_t status;
127 bool deconfigure;
128} xhci_cmd_t;
129
130/* Command handling control */
131extern errno_t xhci_init_commands(xhci_hc_t *);
132extern void xhci_fini_commands(xhci_hc_t *);
133
134extern void xhci_nuke_command_ring(xhci_hc_t *);
135extern void xhci_stop_command_ring(xhci_hc_t *);
136extern void xhci_abort_command_ring(xhci_hc_t *);
137extern void xhci_start_command_ring(xhci_hc_t *);
138
139extern errno_t xhci_handle_command_completion(xhci_hc_t *, xhci_trb_t *);
140
141/* Command lifecycle */
142extern void xhci_cmd_init(xhci_cmd_t *, xhci_cmd_type_t);
143extern void xhci_cmd_fini(xhci_cmd_t *);
144
145/* Issuing commands */
146extern errno_t xhci_cmd_sync(xhci_hc_t *, xhci_cmd_t *);
147extern errno_t xhci_cmd_sync_fini(xhci_hc_t *, xhci_cmd_t *);
148extern errno_t xhci_cmd_async_fini(xhci_hc_t *, xhci_cmd_t *);
149
150#endif
151
152/**
153 * @}
154 */
Note: See TracBrowser for help on using the repository browser.