The Pedigree Project  0.1
modules/drivers/common/usb-hcd/main.cc
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 #include "Ehci.h"
21 #include "Ohci.h"
22 #include "Uhci.h"
23 #include "modules/Module.h"
24 #include "pedigree/kernel/Log.h"
25 #include "pedigree/kernel/machine/Device.h"
26 #include "pedigree/kernel/processor/Processor.h"
27 #include "pedigree/kernel/utilities/new"
28 
29 enum HcdConstants
30 {
31  HCI_CLASS = 0x0C, // Host Controller PCI class
32  HCI_SUBCLASS = 0x03, // Host Controller PCI subclass
33  HCI_PROGIF_UHCI = 0x00, // UHCI PCI programming interface
34  HCI_PROGIF_OHCI = 0x10, // OHCI PCI programming interface
35  HCI_PROGIF_EHCI = 0x20, // EHCI PCI programming interface
36  HCI_PROGIF_XHCI = 0x30, // xHCI PCI programming interface
37 };
38 
39 static bool bFound = false;
40 
41 static void probeXhci(Device *pDev)
42 {
43  WARNING("USB: xHCI found, not implemented yet!");
44  /*
45  // Create a new Xhci node
46  Xhci *pXhci = new Xhci(pDev);
47 
48  // Replace pDev with pXhci, then delete pDev
49  pDev->getParent()->replaceChild(pDev, pXhci);
50  delete pDev;
51  */
52 }
53 
54 static void probeEhci(Device *pDev)
55 {
56  NOTICE("USB: EHCI found");
57 
58  // Create a new Ehci node
59  Ehci *pEhci = new Ehci(pDev);
60  bool success = pEhci->initialiseController();
61  if (!success)
62  {
63  NOTICE("USB: EHCI failed to initialise");
64  return;
65  }
66 
67  // Replace pDev with pEhci, then delete pDev
68  pDev->getParent()->replaceChild(pDev, pEhci);
69  delete pDev;
70 
71  bFound = true;
72 }
73 
74 static void probeOhci(Device *pDev)
75 {
76  NOTICE("USB: OHCI found");
77 
78  // Create a new Ohci node
79  Ohci *pOhci = new Ohci(pDev);
80 
81  // Replace pDev with pOhci, then delete pDev
82  pDev->getParent()->replaceChild(pDev, pOhci);
83  delete pDev;
84 
85  bFound = true;
86 }
87 
88 #ifdef X86_COMMON
89 static void probeUhci(Device *pDev)
90 {
91  NOTICE("USB: UHCI found");
92 
93  // Create a new Uhci node
94  Uhci *pUhci = new Uhci(pDev);
95 
96  // Replace pDev with pUhci, then delete pDev
97  pDev->getParent()->replaceChild(pDev, pUhci);
98  delete pDev;
99 
100  bFound = true;
101 }
102 #endif
103 
104 static bool entry()
105 {
106  // Interrupts may get disabled on the way here, so make sure they are
107  // enabled
109  Device::searchByClassSubclassAndProgInterface(
110  HCI_CLASS, HCI_SUBCLASS, HCI_PROGIF_XHCI, probeXhci);
111  Device::searchByClassSubclassAndProgInterface(
112  HCI_CLASS, HCI_SUBCLASS, HCI_PROGIF_EHCI, probeEhci);
113  Device::searchByClassSubclassAndProgInterface(
114  HCI_CLASS, HCI_SUBCLASS, HCI_PROGIF_OHCI, probeOhci);
115 #ifdef X86_COMMON
116  Device::searchByClassSubclassAndProgInterface(
117  HCI_CLASS, HCI_SUBCLASS, HCI_PROGIF_UHCI, probeUhci);
118 #endif
119 
120  return bFound;
121 }
122 
123 static void exit()
124 {
125 }
126 
127 #ifdef X86_COMMON
128 MODULE_INFO("usb-hcd", &entry, &exit, "pci", "usb");
129 #else
130 #ifdef ARM_COMMON
131 MODULE_INFO("usb-hcd", &entry, &exit, "usb-glue", "usb");
132 #else
133 MODULE_INFO("usb-hcd", &entry, &exit, "usb");
134 #endif
135 #endif
Definition: Ehci.h:41
void replaceChild(Device *src, Device *dest)
Definition: Device.cc:168
Definition: Device.h:43
#define WARNING(text)
Definition: Log.h:78
#define NOTICE(text)
Definition: Log.h:74
static void setInterrupts(bool bEnable)
bool initialiseController()
Definition: Ehci.cc:86
Definition: Uhci.h:47
Definition: Ohci.h:44
Device * getParent() const
Definition: Device.h:149