The Pedigree Project 0.1
UsbHubDevice.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 USBHUBDEVICE_H
21#define USBHUBDEVICE_H
22
23#include "pedigree/kernel/compiler.h"
24#include "pedigree/kernel/processor/types.h"
25#include "pedigree/kernel/utilities/String.h"
26
27#include "modules/system/usb/Usb.h"
28#include "modules/system/usb/UsbConstants.h"
29#include "modules/system/usb/UsbDevice.h"
30#include "modules/system/usb/UsbHub.h"
31
32class UsbHubDevice : public UsbDevice, public UsbHub {
33 public:
35 virtual ~UsbHubDevice();
36
37 virtual void initialiseDriver();
38
39 virtual void getName(String& str) {
40 str.assign("USB Hub Device", 15);
41 }
42
43 bool hasSubtree() const override {
44 return true;
45 }
46
47 Device* getDevice() override {
48 return this;
49 }
50
51 void prepareForDriverRetirement() override;
52
53 virtual void addTransferToTransaction(uintptr_t pTransaction, bool bToggle, UsbPid pid,
54 uintptr_t pBuffer, size_t nBytes);
55 virtual uintptr_t createTransaction(UsbEndpoint endpointInfo);
56 MUST_USE_RESULT virtual bool doAsync(uintptr_t pTransaction,
57 void (*pCallback)(uintptr_t, ssize_t) = 0,
58 uintptr_t pParam = 0);
59 MUST_USE_RESULT virtual bool addInterruptInHandler(UsbEndpoint endpointInfo, uintptr_t pBuffer,
60 uint16_t nBytes,
61 void (*pCallback)(uintptr_t, ssize_t),
63 uintptr_t pParam = 0);
64
65 virtual bool portReset(uint8_t nPort, bool bErrorResponse = false);
66
67 protected:
68 virtual void cancelAsyncAndDrain(uintptr_t pTransaction, void (*pCallback)(uintptr_t, ssize_t),
69 uintptr_t pParam);
71 void (*callback)(uintptr_t, ssize_t),
72 uintptr_t parameter,
73 bool producerAlreadyStopped) override;
74
75 private:
76 enum HubFeatureSelectors {
77 HubLocalPower = 0,
78 HubOverCurrent = 1,
79 };
80
81 enum PortFeatureSelectors {
82 PortConnection = 0,
83 PortEnable = 1,
84 PortSuspend = 2,
85 PortOverCurrent = 3,
86 PortReset = 4,
87 PortPower = 8,
88 PortLowSpeed = 9,
89 CPortConnection = 16,
90 CPortEnable = 17,
91 CPortSuspend = 18,
92 CPortOverCurrent = 19,
93 CPortReset = 20,
94 PortTest = 21,
95 PortIndicator = 22,
96 };
97
98 enum HubRequests {
99 HubPortRequest = static_cast<uint8_t>(static_cast<uint8_t>(UsbRequestType::Class) |
100 static_cast<uint8_t>(UsbRequestRecipient::Other))
101 };
102
103 bool setPortFeature(size_t port, PortFeatureSelectors feature);
104 bool clearPortFeature(size_t port, PortFeatureSelectors feature);
105
107 bool getPortStatus(size_t port, uint32_t& status);
108
110 inline HubDescriptor(void* pBuffer)
111 : pDescriptor(static_cast<Descriptor*>(pBuffer)),
112 nPorts(pDescriptor->nPorts),
113 hubCharacteristics(pDescriptor->hubCharacteristics) {}
114
116 delete[] reinterpret_cast<uint8_t*>(pDescriptor);
117 }
118
119 struct Descriptor {
120 uint8_t nLength;
121 uint8_t nType;
122 uint8_t nPorts;
123 uint16_t hubCharacteristics;
124 } PACKED* pDescriptor;
125
126 uint8_t nPorts;
127 uint16_t hubCharacteristics;
128 };
129
130 size_t m_nPorts;
131};
132
133#endif
bool getPortStatus(size_t port, uint32_t &status)
Top 16 bits of status hold the port-change flags.
Device * getDevice() override
virtual void cancelAsyncAndDrain(uintptr_t pTransaction, void(*pCallback)(uintptr_t, ssize_t), uintptr_t pParam)
MUST_USE_RESULT bool cancelInterruptInAndDrain(const UsbInterruptInToken &token, void(*callback)(uintptr_t, ssize_t), uintptr_t parameter, bool producerAlreadyStopped) override
virtual void getName(String &str)
void prepareForDriverRetirement() override
virtual MUST_USE_RESULT bool doAsync(uintptr_t pTransaction, void(*pCallback)(uintptr_t, ssize_t)=0, uintptr_t pParam=0)
virtual bool portReset(uint8_t nPort, bool bErrorResponse=false)
Gets a UsbDevice from a given vendor:product pair.
bool hasSubtree() const override
Do we expose our own Device tree?
virtual void addTransferToTransaction(uintptr_t pTransaction, bool bToggle, UsbPid pid, uintptr_t pBuffer, size_t nBytes)
Adds a new transfer to an existent transaction.
virtual void initialiseDriver()
Implemented by the driver class, initialises driver-specific stuff.
virtual MUST_USE_RESULT bool addInterruptInHandler(UsbEndpoint endpointInfo, uintptr_t pBuffer, uint16_t nBytes, void(*pCallback)(uintptr_t, ssize_t), UsbInterruptInHandle &handle, uintptr_t pParam=0)
Adds an owned recurring interrupt-IN transaction.
virtual uintptr_t createTransaction(UsbEndpoint endpointInfo)
Creates a new transaction with the given endpoint data.