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 "modules/system/usb/Usb.h"
24 #include "modules/system/usb/UsbConstants.h"
25 #include "modules/system/usb/UsbDevice.h"
26 #include "modules/system/usb/UsbHub.h"
27 #include "pedigree/kernel/compiler.h"
28 #include "pedigree/kernel/processor/types.h"
29 #include "pedigree/kernel/utilities/String.h"
30 
31 class UsbHubDevice : public UsbDevice, public UsbHub
32 {
33  public:
34  UsbHubDevice(UsbDevice *dev);
35  virtual ~UsbHubDevice();
36 
37  virtual void initialiseDriver();
38 
39  virtual void getName(String &str)
40  {
41  str = "USB Hub Device";
42  }
43 
44  virtual void addTransferToTransaction(
45  uintptr_t pTransaction, bool bToggle, UsbPid pid, uintptr_t pBuffer,
46  size_t nBytes);
47  virtual uintptr_t createTransaction(UsbEndpoint endpointInfo);
48  virtual void doAsync(
49  uintptr_t pTransaction, void (*pCallback)(uintptr_t, ssize_t) = 0,
50  uintptr_t pParam = 0);
51  virtual void addInterruptInHandler(
52  UsbEndpoint endpointInfo, uintptr_t pBuffer, uint16_t nBytes,
53  void (*pCallback)(uintptr_t, ssize_t), uintptr_t pParam = 0);
54 
55  virtual bool portReset(uint8_t nPort, bool bErrorResponse = false);
56 
57  private:
58  enum HubFeatureSelectors
59  {
60  HubLocalPower = 0,
61  HubOverCurrent = 1,
62  };
63 
64  enum PortFeatureSelectors
65  {
66  PortConnection = 0,
67  PortEnable = 1,
68  PortSuspend = 2,
69  PortOverCurrent = 3,
70  PortReset = 4,
71  PortPower = 8,
72  PortLowSpeed = 9,
73  CPortConnection = 16,
74  CPortEnable = 17,
75  CPortSuspend = 18,
76  CPortOverCurrent = 19,
77  CPortReset = 20,
78  PortTest = 21,
79  PortIndicator = 22,
80  };
81 
82  enum HubRequests
83  {
84  HubPortRequest = UsbRequestType::Class | UsbRequestRecipient::Other
85  };
86 
87  bool setPortFeature(size_t port, PortFeatureSelectors feature);
88  bool clearPortFeature(size_t port, PortFeatureSelectors feature);
89 
91  uint32_t getPortStatus(size_t port);
92 
94  {
95  inline HubDescriptor(void *pBuffer)
96  : pDescriptor(static_cast<Descriptor *>(pBuffer)),
97  nPorts(pDescriptor->nPorts),
98  hubCharacteristics(pDescriptor->hubCharacteristics)
99  {
100  }
101 
102  struct Descriptor
103  {
104  uint8_t nLength;
105  uint8_t nType;
106  uint8_t nPorts;
107  uint16_t hubCharacteristics;
108  } PACKED *pDescriptor;
109 
110  uint8_t nPorts;
111  uint16_t hubCharacteristics;
112  };
113 
114  size_t m_nPorts;
115 };
116 
117 #endif
virtual void addTransferToTransaction(uintptr_t pTransaction, bool bToggle, UsbPid pid, uintptr_t pBuffer, size_t nBytes)
Adds a new transfer to an existent transaction.
Definition: String.h:49
virtual void initialiseDriver()
Implemented by the driver class, initialises driver-specific stuff.
Definition: UsbHubDevice.cc:36
uint32_t getPortStatus(size_t port)
Top 32 bits hold change status.
virtual void addInterruptInHandler(UsbEndpoint endpointInfo, uintptr_t pBuffer, uint16_t nBytes, void(*pCallback)(uintptr_t, ssize_t), uintptr_t pParam=0)
Adds a new handler for an interrupt IN transaction.
virtual void getName(String &str)
Definition: UsbHubDevice.h:39
Definition: UsbHub.h:30
virtual void 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.
virtual uintptr_t createTransaction(UsbEndpoint endpointInfo)
Creates a new transaction with the given endpoint data.