1 | /*
|
---|
2 | * Copyright (c) 2017 Ondrej Hlavaty <aearsis@eideo.cz>
|
---|
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 | * Context data structures of the xHC.
|
---|
34 | *
|
---|
35 | * Most of them are to be initialized to zero and passed ownership to the HC,
|
---|
36 | * so they are mostly read-only.
|
---|
37 | *
|
---|
38 | * Feel free to write a setter when in need.
|
---|
39 | */
|
---|
40 |
|
---|
41 | #ifndef XHCI_CONTEXT_H
|
---|
42 | #define XHCI_CONTEXT_H
|
---|
43 |
|
---|
44 | #include <stdint.h>
|
---|
45 | #include "common.h"
|
---|
46 |
|
---|
47 | /**
|
---|
48 | * Endpoint context: section 6.2.3
|
---|
49 | */
|
---|
50 | typedef struct xhci_endpoint_ctx {
|
---|
51 | xhci_dword_t data[5];
|
---|
52 | xhci_dword_t reserved[3];
|
---|
53 |
|
---|
54 | #define XHCI_EP_STATE(ctx) XHCI_DWORD_EXTRACT((ctx).data[0], 2, 0)
|
---|
55 | #define XHCI_EP_MULT(ctx) XHCI_DWORD_EXTRACT((ctx).data[0], 9, 8)
|
---|
56 | #define XHCI_EP_MAX_P_STREAMS(ctx) XHCI_DWORD_EXTRACT((ctx).data[0], 14, 10)
|
---|
57 | #define XHCI_EP_LSA(ctx) XHCI_DWORD_EXTRACT((ctx).data[0], 15, 15)
|
---|
58 | #define XHCI_EP_INTERVAL(ctx) XHCI_DWORD_EXTRACT((ctx).data[0], 23, 16)
|
---|
59 |
|
---|
60 | #define XHCI_EP_ERROR_COUNT(ctx) XHCI_DWORD_EXTRACT((ctx).data[1], 2, 1)
|
---|
61 | #define XHCI_EP_TYPE(ctx) XHCI_DWORD_EXTRACT((ctx).data[1], 5, 3)
|
---|
62 | #define XHCI_EP_HID(ctx) XHCI_DWORD_EXTRACT((ctx).data[1], 7, 7)
|
---|
63 | #define XHCI_EP_MAX_BURST_SIZE(ctx) XHCI_DWORD_EXTRACT((ctx).data[1], 15, 8)
|
---|
64 | #define XHCI_EP_MAX_PACKET_SIZE(ctx) XHCI_DWORD_EXTRACT((ctx).data[1], 31, 16)
|
---|
65 |
|
---|
66 | #define XHCI_EP_DCS(ctx) XHCI_DWORD_EXTRACT((ctx).data[2], 0, 0)
|
---|
67 | #define XHCI_EP_TR_DPTR(ctx) XHCI_DWORD_EXTRACT((ctx).data[2], 63, 4)
|
---|
68 |
|
---|
69 | } __attribute__((packed)) xhci_ep_ctx_t;
|
---|
70 |
|
---|
71 | /**
|
---|
72 | * Slot context: section 6.2.2
|
---|
73 | */
|
---|
74 | typedef struct xhci_slot_ctx {
|
---|
75 | xhci_dword_t data [4];
|
---|
76 | xhci_dword_t reserved [4];
|
---|
77 |
|
---|
78 | #define XHCI_SLOT_ROUTE_STRING(ctx) XHCI_DWORD_EXTRACT((ctx).data[0], 19, 0)
|
---|
79 | #define XHCI_SLOT_SPEED(ctx) XHCI_DWORD_EXTRACT((ctx).data[0], 23, 20)
|
---|
80 | #define XHCI_SLOT_MTT(ctx) XHCI_DWORD_EXTRACT((ctx).data[0], 25, 25)
|
---|
81 | #define XHCI_SLOT_CTX_ENTRIES(ctx) XHCI_DWORD_EXTRACT((ctx).data[0], 31, 27)
|
---|
82 |
|
---|
83 | #define XHCI_SLOT_MAX_EXIT_LATENCY(ctx) XHCI_DWORD_EXTRACT((ctx).data[1], 15, 0)
|
---|
84 | #define XHCI_SLOT_ROOT_HUB_PORT(ctx) XHCI_DWORD_EXTRACT((ctx).data[1], 23, 16)
|
---|
85 | #define XHCI_SLOT_NUM_OF_PORTS(ctx) XHCI_DWORD_EXTRACT((ctx).data[1], 31, 24)
|
---|
86 |
|
---|
87 | #define XHCI_SLOT_TT_HUB_SLOT_ID(ctx) XHCI_DWORD_EXTRACT((ctx).data[2], 7, 0)
|
---|
88 | #define XHCI_SLOT_TT_PORT_NUM(ctx) XHCI_DWORD_EXTRACT((ctx).data[2], 15, 8)
|
---|
89 | #define XHCI_SLOT_TT_THINK_TIME(ctx) XHCI_DWORD_EXTRACT((ctx).data[2], 17, 16)
|
---|
90 | #define XHCI_SLOT_INTERRUPTER(ctx) XHCI_DWORD_EXTRACT((ctx).data[2], 31, 22)
|
---|
91 |
|
---|
92 | #define XHCI_SLOT_DEVICE_ADDRESS(ctx) XHCI_DWORD_EXTRACT((ctx).data[3], 7, 0)
|
---|
93 | #define XHCI_SLOT_SLOT_STATE(ctx) XHCI_DWORD_EXTRACT((ctx).data[3], 31, 27)
|
---|
94 |
|
---|
95 | } __attribute__((packed)) xhci_slot_ctx_t;
|
---|
96 |
|
---|
97 | /**
|
---|
98 | * Device context: section 6.2.1
|
---|
99 | */
|
---|
100 | typedef struct xhci_device_ctx {
|
---|
101 | xhci_slot_ctx_t slot_ctx;
|
---|
102 | xhci_ep_ctx_t endpoint_ctx [31];
|
---|
103 | } __attribute__((packed)) xhci_device_ctx_t;
|
---|
104 |
|
---|
105 | /**
|
---|
106 | * Stream context: section 6.2.4 {
|
---|
107 | */
|
---|
108 | typedef struct xhci_stream_ctx {
|
---|
109 | uint64_t data [2];
|
---|
110 | #define XHCI_STREAM_DCS(ctx) XHCI_QWORD_EXTRACT((ctx).data[0], 0, 0)
|
---|
111 | #define XHCI_STREAM_SCT(ctx) XHCI_QWORD_EXTRACT((ctx).data[0], 3, 1)
|
---|
112 | #define XHCI_STREAM_DEQ_PTR(ctx) XHCI_QWORD_EXTRACT((ctx).data[0], 63, 4)
|
---|
113 | #define XHCI_STREAM_EDTLA(ctx) XHCI_QWORD_EXTRACT((ctx).data[1], 24, 0)
|
---|
114 | } __attribute__((packed)) xhci_stream_ctx_t;
|
---|
115 |
|
---|
116 | /**
|
---|
117 | * Input control context: section 6.2.5.1
|
---|
118 | * Note: According to section 6.2.5.1 figure 78,
|
---|
119 | * the context size register value in hccparams1
|
---|
120 | * dictates whether input control context shall have
|
---|
121 | * 32 or 64 bytes, but in any case only dwords 0, 1 and 7
|
---|
122 | * are used, the rest are reserved.
|
---|
123 | */
|
---|
124 | typedef struct xhci_input_ctrl_ctx {
|
---|
125 | uint32_t data [16];
|
---|
126 | #define XHCI_INPUT_CTRL_CTX_DROP(ctx, idx) \
|
---|
127 | (assert((idx) > 1 && (idx) < 32), XHCI_DWORD_EXTRACT((ctx).data[0], (idx), (idx)))
|
---|
128 | #define XHCI_INPUT_CTRL_CTX_ADD(ctx, idx) \
|
---|
129 | (assert((idx) >= 0 && (idx) < 32), XHCI_DWORD_EXTRACT((ctx).data[1], (idx), (idx)))
|
---|
130 | #define XHCI_INPUT_CTRL_CTX_CONFIG_VALUE(ctx) XHCI_DWORD_EXTRACT((ctx).data[7], 7, 0)
|
---|
131 | #define XHCI_INPUT_CTRL_CTX_IFACE_NUMBER(ctx) XHCI_DWORD_EXTRACT((ctx).data[7], 15, 8)
|
---|
132 | #define XHCI_INPUT_CTRL_CTX_ALTER_SETTING(ctx) XHCI_DWORD_EXTRACT((ctx).data[7], 23, 16)
|
---|
133 | } __attribute__((packed)) xhci_input_ctrl_ctx_t;
|
---|
134 |
|
---|
135 | /**
|
---|
136 | * Input context: section 6.2.5
|
---|
137 | */
|
---|
138 | typedef struct xhci_input_ctx {
|
---|
139 | xhci_input_ctrl_ctx_t ctr_ctx;
|
---|
140 | xhci_slot_ctx_t slot_ctx;
|
---|
141 | xhci_ep_ctx_t endpoint_ctx [31];
|
---|
142 | } __attribute__((packed)) xhci_input_ctx_t;
|
---|
143 |
|
---|
144 | #endif
|
---|