blob: 04eb14adedd5c01f1ba8fbb869a7a9d84632af78 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
/*
* Copyright (c) 2021, Luke Wilde <lukew@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/Singleton.h>
#include <Kernel/Bus/PCI/API.h>
#include <Kernel/Bus/USB/SysFSUSB.h>
#include <Kernel/Bus/USB/UHCI/UHCIController.h>
#include <Kernel/Bus/USB/USBManagement.h>
#include <Kernel/CommandLine.h>
#include <Kernel/Sections.h>
namespace Kernel::USB {
static Singleton<USBManagement> s_the;
READONLY_AFTER_INIT bool s_initialized_sys_fs_directory = false;
UNMAP_AFTER_INIT USBManagement::USBManagement()
{
enumerate_controllers();
}
UNMAP_AFTER_INIT void USBManagement::enumerate_controllers()
{
if (kernel_command_line().disable_usb())
return;
PCI::enumerate([this](PCI::Address const& address, PCI::DeviceIdentifier const& device_identifier) {
if (!(device_identifier.class_code().value() == 0xc && device_identifier.subclass_code().value() == 0x3))
return;
if (device_identifier.prog_if().value() == 0x0) {
if (kernel_command_line().disable_uhci_controller())
return;
if (auto uhci_controller_or_error = UHCIController::try_to_initialize(address); !uhci_controller_or_error.is_error())
m_controllers.append(uhci_controller_or_error.release_value());
return;
}
if (device_identifier.prog_if().value() == 0x10) {
dmesgln("USBManagement: OHCI controller found at {} is not currently supported.", address);
return;
}
if (device_identifier.prog_if().value() == 0x20) {
dmesgln("USBManagement: EHCI controller found at {} is not currently supported.", address);
return;
}
if (device_identifier.prog_if().value() == 0x30) {
dmesgln("USBManagement: xHCI controller found at {} is not currently supported.", address);
return;
}
dmesgln("USBManagement: Unknown/unsupported controller at {} with programming interface 0x{:02x}", address, device_identifier.prog_if().value());
});
}
bool USBManagement::initialized()
{
return s_the.is_initialized();
}
UNMAP_AFTER_INIT void USBManagement::initialize()
{
if (!s_initialized_sys_fs_directory) {
USB::SysFSUSBBusDirectory::initialize();
s_initialized_sys_fs_directory = true;
}
s_the.ensure_instance();
}
USBManagement& USBManagement::the()
{
return *s_the;
}
}
|