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

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

xhci: event rings && hc initialization (WIP)

  • Property mode set to 100644
File size: 4.8 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 XHCI_TRB_TYPE_MAX
88};
89
90/**
91 * TRB template: section 4.11.1
92 */
93typedef struct xhci_trb {
94 xhci_qword_t parameter;
95 xhci_dword_t status;
96 xhci_dword_t control;
97} __attribute__((packed)) xhci_trb_t;
98
99#define TRB_TYPE(trb) XHCI_DWORD_EXTRACT((trb).control, 15, 10)
100#define TRB_CYCLE(trb) XHCI_DWORD_EXTRACT((trb).control, 0, 0)
101#define TRB_LINK_TC(trb) XHCI_DWORD_EXTRACT((trb).control, 1, 1)
102
103/**
104 * The Chain bit is valid only in specific TRB types.
105 */
106static inline bool xhci_trb_is_chained(xhci_trb_t *trb) {
107 const int type = TRB_TYPE(*trb);
108 const bool chain_bit = XHCI_DWORD_EXTRACT(trb->control, 4, 4);
109
110 return chain_bit &&
111 (type == XHCI_TRB_TYPE_NORMAL
112 || type == XHCI_TRB_TYPE_DATA_STAGE
113 || type == XHCI_TRB_TYPE_STATUS_STAGE
114 || type == XHCI_TRB_TYPE_ISOCH);
115}
116
117static inline void xhci_trb_set_cycle(xhci_trb_t *trb, bool cycle)
118{
119 xhci_dword_set_bits(&trb->control, cycle, 0, 0);
120}
121
122static inline void xhci_trb_link_fill(xhci_trb_t *trb, uintptr_t next_phys)
123{
124 // TRBs require 16-byte alignment
125 assert((next_phys & 0xf) == 0);
126
127 xhci_dword_set_bits(&trb->control, XHCI_TRB_TYPE_LINK, 15, 10);
128 xhci_qword_set(&trb->parameter, next_phys);
129}
130
131static inline void xhci_trb_copy(xhci_trb_t *dst, xhci_trb_t *src)
132{
133 /*
134 * As we do not know, whether our architecture is capable of copying 16
135 * bytes atomically, let's copy the fields one by one.
136 */
137 dst->parameter = src->parameter;
138 dst->status = src->status;
139 dst->control = src->control;
140}
141
142/**
143 * Event Ring Segment Table: section 6.5
144 */
145typedef struct xhci_erst_entry {
146 xhci_qword_t rs_base_ptr; /* 64B aligned */
147 xhci_dword_t size; /* only low 16 bits, the rest is RsvdZ */
148 xhci_dword_t _reserved;
149} xhci_erst_entry_t;
150
151static inline void xhci_fill_erst_entry(xhci_erst_entry_t *entry, uintptr_t phys, int segments)
152{
153 xhci_qword_set(&entry->rs_base_ptr, phys);
154 xhci_dword_set_bits(&entry->size, segments, 16, 0);
155}
156
157#endif
Note: See TracBrowser for help on using the repository browser.