The Pedigree Project 0.1
Usb.h
1/*
2 * Copyright (c) 2008-2014, Pedigree Developers
3 *
4 * Please see the CONTRIB file in the root of the source tree for a full
5 * list of contributors.
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
20#ifndef USB_H
21#define USB_H
22
23#include "pedigree/kernel/processor/types.h"
24
25#ifdef USB_VERBOSE_DEBUG
26inline constexpr bool UsbVerboseDebug = true;
27#else
28inline constexpr bool UsbVerboseDebug = false;
29#endif
30
31// PID types, ordered as they appear in the EHCI spec
32enum UsbPid {
33 // Token PID Types
34 UsbPidOut = 0xe1,
35 UsbPidIn = 0x69,
36 UsbPidSOF = 0xa5,
37 UsbPidSetup = 0x2d,
38
39 // Data PID Types
40 UsbPidData0 = 0xc3,
41 UsbPidData1 = 0x4b,
42 UsbPidData2 = 0x87,
43 UsbPidMdata = 0x0f,
44
45 // Handshake PID Types
46 UsbPidAck = 0xd2,
47 UsbPidNak = 0x5a,
48 UsbPidStall = 0x1e,
49 UsbPidNyet = 0x96,
50
51 // Special PID Types
52 UsbPidPre = 0x3c, // Token
53 UsbPidErr = 0x3c, // Handshake
54 UsbPidSplit = 0x78,
55 UsbPidPing = 0xb4,
56 UsbPidRsvd = 0xf0
57};
58
59enum UsbSpeed { LowSpeed = 0, FullSpeed, HighSpeed, SuperSpeed };
60
61enum UsbError { Stall = 1, NakNyet, Timeout, Babble, CrcError, TransactionError };
62
64 inline UsbEndpoint()
65 : nAddress(0),
66 nEndpoint(0),
67 speed(LowSpeed),
68 nMaxPacketSize(8),
69 nInterval(1),
70 nTransferType(0),
71 nIn(false),
72 nMaxBurst(0),
73 nStreams(0),
74 nBytesPerInterval(0),
75 nHubAddress(0),
76 nHubPort(0),
77 nRootPort(0xff),
78 nRootPortGeneration(0) {}
79 inline UsbEndpoint(uint8_t address, uint8_t hubPort, uint8_t endpoint, UsbSpeed _speed,
80 size_t maxPacketSize)
81 : nAddress(address),
82 nEndpoint(endpoint),
83 speed(_speed),
84 nMaxPacketSize(maxPacketSize),
85 nInterval(1),
86 nTransferType(0),
87 nIn(false),
88 nMaxBurst(0),
89 nStreams(0),
90 nBytesPerInterval(0),
91 nHubAddress(0),
92 nHubPort(hubPort),
93 nRootPort(0xff),
94 nRootPortGeneration(0) {}
95
96 uint8_t nAddress;
97 uint8_t nEndpoint;
98 UsbSpeed speed;
99 size_t nMaxPacketSize;
100 uint8_t nInterval;
101 uint8_t nTransferType;
102 bool nIn;
103 uint8_t nMaxBurst;
104 uint8_t nStreams;
105 uint16_t nBytesPerInterval;
106 uint8_t nHubAddress;
107 uint8_t nHubPort;
108 uint8_t nRootPort;
109 size_t nRootPortGeneration;
110};
111
112#endif