source: mainline/uspace/drv/bus/usb/xhci/hw_struct/trb.h@ 5cbccd4

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 5cbccd4 was f4eb6c93, checked in by Ondřej Hlavatý <aearsis@…>, 8 years ago

xhci: hardware data structures and trb ring management

  • Property mode set to 100644
File size: 4.4 KB
Line 
1/*
2 * Copyright (c) 2017 Ondrej Hlavaty
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 * TRB-related structures of the xHC.
34 *
35 * This file contains all the types of TRB and the TRB ring handling.
36 */
37
38#ifndef XHCI_TRB_H
39#define XHCI_TRB_H
40
41#include "common.h"
42
43/**
44 * TRB types: section 6.4.6, table 139
45 */
46enum xhci_trb_type {
47 XHCI_TRB_TYPE_RESERVED = 0,
48
49// Transfer ring:
50 XHCI_TRB_TYPE_NORMAL,
51 XHCI_TRB_TYPE_SETUP_STAGE,
52 XHCI_TRB_TYPE_DATA_STAGE,
53 XHCI_TRB_TYPE_STATUS_STAGE,
54 XHCI_TRB_TYPE_ISOCH,
55 XHCI_TRB_TYPE_LINK,
56 XHCI_TRB_TYPE_EVENT_DATA,
57 XHCI_TRB_TYPE_NO_OP,
58
59// Command ring:
60 XHCI_TRB_TYPE_ENABLE_SLOT_CMD,
61 XHCI_TRB_TYPE_DISABLE_SLOT_CMD,
62 XHCI_TRB_TYPE_ADDRESS_DEVICE_CMD,
63 XHCI_TRB_TYPE_CONFIGURE_ENDPOINT_CMD,
64 XHCI_TRB_TYPE_EVALUATE_CONTEXT_CMD,
65 XHCI_TRB_TYPE_RESET_ENDPOINT_CMD,
66 XHCI_TRB_TYPE_STOP_ENDPOINT_CMD,
67 XHCI_TRB_TYPE_SET_TR_DEQUEUE_POINTER_CMD,
68 XHCI_TRB_TYPE_RESET_DEVICE_CMD,
69 XHCI_TRB_TYPE_FORCE_EVENT_CMD,
70 XHCI_TRB_TYPE_NEGOTIATE_BANDWIDTH_CMD,
71 XHCI_TRB_TYPE_SET_LATENCY_TOLERANCE_VALUE_CMD,
72 XHCI_TRB_TYPE_GET_PORT_BANDWIDTH_CMD,
73 XHCI_TRB_TYPE_FORCE_HEADER_CMD,
74 XHCI_TRB_TYPE_NO_OP_CMD,
75// Reserved: 24-31
76
77// Event ring:
78 XHCI_TRB_TYPE_TRANSFER_EVENT = 32,
79 XHCI_TRB_TYPE_COMMAND_COMPLETION_EVENT,
80 XHCI_TRB_TYPE_PORT_STATUS_CHANGE_EVENT,
81 XHCI_TRB_TYPE_BANDWIDTH_REQUEST_EVENT,
82 XHCI_TRB_TYPE_DOORBELL_EVENT,
83 XHCI_TRB_TYPE_HOST_CONTROLLER_EVENT,
84 XHCI_TRB_TYPE_DEVICE_NOTIFICATION_EVENT,
85 XHCI_TRB_TYPE_MFINDEX_WRAP_EVENT,
86};
87
88/**
89 * TRB template: section 4.11.1
90 */
91typedef struct xhci_trb {
92 xhci_qword_t parameter;
93 xhci_dword_t status;
94 xhci_dword_t control;
95} xhci_trb_t;
96
97#define TRB_TYPE(trb) XHCI_DWORD_EXTRACT((trb).control, 15, 10)
98#define TRB_LINK_TC(trb) XHCI_DWORD_EXTRACT((trb).control, 1, 1)
99
100/**
101 * The Chain bit is valid only in specific TRB types.
102 */
103static inline bool xhci_trb_is_chained(xhci_trb_t *trb) {
104 const int type = TRB_TYPE(*trb);
105 const bool chain_bit = XHCI_DWORD_EXTRACT(trb->control, 4, 4);
106
107 return chain_bit &&
108 (type == XHCI_TRB_TYPE_NORMAL
109 || type == XHCI_TRB_TYPE_DATA_STAGE
110 || type == XHCI_TRB_TYPE_STATUS_STAGE
111 || type == XHCI_TRB_TYPE_ISOCH);
112}
113
114static inline void xhci_trb_set_cycle(xhci_trb_t *trb, bool cycle)
115{
116 xhci_dword_set_bits(&trb->control, cycle, 1, 1);
117}
118
119static inline void xhci_trb_link_fill(xhci_trb_t *trb, uintptr_t next_phys)
120{
121 // TRBs require 16-byte alignment
122 assert((next_phys & 0xf) == 0);
123
124 xhci_dword_set_bits(&trb->control, XHCI_TRB_TYPE_LINK, 15, 10);
125 xhci_qword_set(&trb->parameter, next_phys);
126}
127
128static inline void xhci_trb_copy(xhci_trb_t *dst, xhci_trb_t *src)
129{
130 /*
131 * As we do not know, whether our architecture is capable of copying 16
132 * bytes atomically, let's copy the fields one by one.
133 */
134 dst->parameter = src->parameter;
135 dst->status = src->status;
136 dst->control = src->control;
137}
138
139
140/**
141 * Event Ring Segment Table: section 6.5
142 */
143typedef struct xhci_erst_entry {
144 xhci_qword_t rs_base_ptr; // sans bits 0-6
145 xhci_dword_t size; // only low 16 bits, the rest is reserved
146} xhci_erst_entry_t;
147
148#endif
Note: See TracBrowser for help on using the repository browser.