The Pedigree Project  0.1
UsbHub.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 USBHUB_H
21 #define USBHUB_H
22 
23 #include "modules/system/usb/Usb.h"
24 #include "pedigree/kernel/compiler.h"
25 #include "pedigree/kernel/machine/Device.h"
26 #include "pedigree/kernel/process/Semaphore.h"
27 #include "pedigree/kernel/processor/types.h"
28 #include "pedigree/kernel/utilities/ExtensibleBitmap.h"
29 
31 {
32  public:
33  UsbHub();
34  UsbHub(Device *p);
35 
36  virtual ~UsbHub();
37 
38  virtual Type getType();
39 
41  virtual void addTransferToTransaction(
42  uintptr_t pTransaction, bool bToggle, UsbPid pid, uintptr_t pBuffer,
43  size_t nBytes) = 0;
44 
46  virtual uintptr_t createTransaction(UsbEndpoint endpointInfo) = 0;
47 
50  virtual void doAsync(
51  uintptr_t pTransaction, void (*pCallback)(uintptr_t, ssize_t) = 0,
52  uintptr_t pParam = 0) = 0;
53 
55  virtual void addInterruptInHandler(
56  UsbEndpoint endpointInfo, uintptr_t pBuffer, uint16_t nBytes,
57  void (*pCallback)(uintptr_t, ssize_t), uintptr_t pParam = 0) = 0;
58 
60  bool deviceConnected(uint8_t nPort, UsbSpeed speed);
61 
63  void deviceDisconnected(uint8_t nPort);
64 
67  ssize_t doSync(uintptr_t nTransaction, uint32_t timeout = 5000);
68 
70  // void getDeviceByIds(size_t vendor, size_t product, void
71  // (*pCallback)(class UsbDevice *));
72 
80  virtual bool portReset(uint8_t nPort, bool bErrorResponse = false) = 0;
81 
85  void ignoreConnectionChanges(uint8_t nPort, bool bIgnore = true)
86  {
87  if (bIgnore)
88  m_IgnoredPorts.set(nPort);
89  else
90  m_IgnoredPorts.clear(nPort);
91  }
92 
93  private:
95  struct SyncParam
96  {
97  inline SyncParam() : semaphore(0), nResult(-1), timedOut(false)
98  {
99  }
100 
101  Semaphore semaphore;
102  ssize_t nResult;
103 
104  bool timedOut;
105  };
106 
108  static void syncCallback(uintptr_t pParam, ssize_t ret);
109 
113 
114  protected:
117 };
118 
119 #endif
ExtensibleBitmap m_UsedAddresses
Definition: UsbHub.h:112
Definition: Device.h:43
Structure used synchronous transactions.
Definition: UsbHub.h:95
Definition: UsbHub.h:30
virtual Type getType()
Definition: Device.h:163
ExtensibleBitmap m_IgnoredPorts
Bitmap of ports to ignore connection changes on.
Definition: UsbHub.h:116
Type
Definition: Device.h:50
void ignoreConnectionChanges(uint8_t nPort, bool bIgnore=true)
Definition: UsbHub.h:85