Commit graph

393 commits

Author SHA1 Message Date
Hendiadyoin1
16a5c8a181 Kernel: Remove unused ScatterGatherList.h include from VirtIO/Queue.h 2024-11-27 22:16:45 +01:00
Sönke Holz
19258d8980 Kernel/USB: Let register_driver work before USBManagement initialization
This will be needed in the next commit, which moves the driver init
functions calling code earlier into the boot process.
2024-11-02 13:53:10 -04:00
Hendiadyoin1
92e2e309d3 Kernel/USB: Add and use a shared function to set a device's interface 2024-10-30 18:47:50 -04:00
Hendiadyoin1
66cfe47ed8 Kernel/USBMS: Add a basic UAS driver
For now we only support USB <3.0 devices, as we don't support streams.
We also don't leverage the benefits of UAS, as we pretend to have a
queue depth of 1, ie are single threaded.

To test this driver, you can use the following command:
```
SERENITY_BOOT_DRIVE=usb-uas Meta/serenity.sh run x86_64 Clang
```
2024-10-30 18:47:50 -04:00
Hendiadyoin1
1db4da93eb Kernel/USB: Save all USB descriptors and allow iterating over them
This makes it easier to access class specific descriptors, which
are sometimes dependent on the descriptors immediately before them.
2024-10-30 18:47:50 -04:00
Hendiadyoin1
435d78c575 Kernel/USBMS: Move the BOT/BBB driver to its own directory 2024-10-30 18:47:50 -04:00
Liav A.
96e1391c23 Kernel/Devices: Remove the DeviceManagement singleton
This change has many improvements:
- We don't use `LockRefPtr` to hold instances of many base devices as
  with the DeviceManagement class. Instead, we have a saner pattern of
  holding them in a `NonnullRefPtr<T> const`, in a small-text footprint
  class definition in the `Device.cpp` file.
- The awkwardness of using `::the()` each time we need to get references
  to mostly-static objects (like the Event queue) in runtime is now gone
  in the migration to using the `Device` class.
- Acquiring a device feel more obvious because we use now the Device
  class for this method. The method name is improved as well.
2024-10-05 12:26:48 +02:00
Sönke Holz
a088af5fb4 Kernel/USB: Correct the calculation of the xHCI TD Size Normal TRB field
The "TD Size" field should contain the number of packets after this TRB
that belong to the current TD.
2024-09-28 07:56:46 -04:00
Sönke Holz
ad0a8caf54 Kernel/USB: Clean up xHCIController::prepare_normal_transfer
While this is Feng Shui programming, the old code was IMHO a bit
unreadable due to the lack of whitespace.
2024-09-28 07:56:46 -04:00
Sönke Holz
0aa8731b94 Kernel/USB: VERIFY that the USB::Pipe endpoint number is valid 2024-09-25 14:41:23 -04:00
Sönke Holz
fe27198994 Kernel/USBMS: Print the USB VID:PID in a nicer format 2024-09-25 14:41:23 -04:00
Sönke Holz
54709af2f5 Kernel/USBMS: Perform a Reset Recovery when CSW transport fails twice
This requires storing a const reference to the interface, as the
Bulk-Only Mass Storage Reset request takes the interface number as an
argument.
2024-09-25 14:41:23 -04:00
Sönke Holz
7173a02728 Kernel/USBMS: Move device initialization to BulkSCSIInterface 2024-09-25 14:41:23 -04:00
Sönke Holz
c5f4469b32 Kernel/USBMS: Move StorageDevice functions into a separate class
This will allow us to make send_scsi_command a member function. This is
necessary because we need to execute some SCSI commands
(with send_scsi_command) to get all arguments necessary for the
StorageDevice constructor.

This change should will likely also be necessary to support USB mass
storage devices with multiple LUNs.
2024-09-25 14:41:23 -04:00
Sönke Holz
e2919f92ff Kernel/USBMS: Accept SCSI version 0
Some devices seem to have this field set to 0.
0 means "The device does not claim conformance to any standard."
2024-09-25 14:41:23 -04:00
Sönke Holz
42c355f4cb Kernel/USB: Return ESHUTDOWN on stall errors 2024-09-25 14:41:23 -04:00
Sönke Holz
878d149ec9 Kernel/USB: Add a function to clear the endpoint halt condition
This is done by issuing a ClearFeature(ENDPOINT_HALT) request.
On xHCI, some extra steps are needed.
2024-09-25 14:41:23 -04:00
Sönke Holz
cb2c0c630b Kernel/USB: Make USB::Pipe hold a non-const reference to the USB::Device
This will be necessary in the next commit.
2024-09-25 14:41:23 -04:00
Sönke Holz
632afcf822 Kernel/USB: Don't treat xHCI Short Packet Completion Codes as errors
The Short Packet Completion Code just means that the xHC received fewer
bytes than expected.
We shouldn't treat them as errors, since our transfer functions already
return the actual transfer size.
2024-09-25 14:41:23 -04:00
Sönke Holz
e8ebdf804e Kernel/USB: Clear the direction bit of the HID interrupt endpoint number
InterruptInPipe::create() expects an endpoint number, not the entire
address.
2024-09-25 14:41:23 -04:00
Sönke Holz
7e3dc5b721 Kernel/USB: Rename endpoint_address to endpoint_number where appropriate
"Endpoint Address" refers to "[t]he combination of an endpoint number
and an endpoint direction on a USB device."
(USB 2.0 Specification, Chapter 2)

The USB::Pipe m_endpoint_address member doesn't have the direction part,
so rename it and all variables/functions associated with it
appropriately.
2024-09-25 14:41:23 -04:00
Hendiadyoin1
b5c6e656f8 Kernel/USB: Only create SysFS node after device is fully initialized
Otherwise all devices would report as address 0 to the SysFS, which
is nonsense.
2024-09-22 19:16:19 -04:00
Hendiadyoin1
67a13ad786 Kernel: Be a bit more judicious about how we copy USB structures
A lot of USB structures contain back pointers to their parents,
so we need to be careful about how we copy them around, and update
the back pointers as necessary.
2024-09-22 19:16:19 -04:00
Sönke Holz
1d83f73ec5 Kernel/PCI: Stop using a dangling pointer in dmesgln_pci
VariadicFormatParams only stores pointers to the parameters, so
the device.device_name() parameter will dangle.

This fixes broken dmesgln_pci output on riscv64 GCC.
2024-09-07 12:52:52 -04:00
Liav A.
0482f4e117 Kernel: Remove passing of register state to IRQ handlers
Linux did the same thing 18 years ago and their reasons for the change
are similar to ours - https://github.com/torvalds/linux/commit/7d12e78

Most interrupt handlers (i.e. IRQ handlers) never used the register
state reference anywhere so there's simply no need of passing it around.
I didn't measure the performance boost but surely this change can't make
things worse anyway.
2024-09-01 21:00:18 +02:00
Hendiadyoin1
0d2e8ec96f Kernel/USBMS: Inquire and wait for the storage device to become ready
This is apparently what bootloaders do before using a USB storage device
so we should likely do so as well, especially when no BIOS is present,
like on riscv.

Co-Authored-By: Sönke Holz <sholz8530@gmail.com>
2024-08-20 22:06:51 -04:00
Hendiadyoin1
e3567969d4 Kernel/USBMS: Add and use a send_scsi_command helper
This makes sending commands less repetitive
2024-08-20 22:06:51 -04:00
Hendiadyoin1
0866adde12 Kernel/USB: Be a bit more const-correct with USB transfers 2024-08-20 22:06:51 -04:00
Sönke Holz
c3c5378c82 Kernel/USB: Always check for the Intel xHCI port routing quirk
The quirk previously only worked when USBLEGSUP was present and the BIOS
owned the host controller.
2024-08-12 10:54:00 -04:00
Sönke Holz
6a195b6616 Kernel/USB: Add support for xHCI bulk transfers
Bulk transfers also use Normal TRBs, so move the reusable normal TRB
setup code from submit_async_interrupt_transfer into a new function
prepare_normal_transfer.

submit_bulk_transfer and submit_async_interrupt_transfer use this
function and then either block on the completion or submit it
asynchronously and wrap it into a PeriodicPendingTransfer.
2024-08-07 18:30:06 -04:00
Sönke Holz
d82148aae1 Kernel/USB: Don't truncate the max packet size in the MassStorage driver 2024-08-07 18:30:06 -04:00
Sönke Holz
640530dbed Kernel/PCI: Handle 64-bit MSI-X BARs
PCI::get_BAR just returns the raw BAR value and doesn't handle 64-bit
BARs.
2024-08-01 12:05:56 -07:00
Sönke Holz
26555baf53 Kernel/USB: Make USBHubDescriptor::hub_characteristics union packed
AArch64 Clang otherwise complains that this anonymous union is more
aligned than the struct.
2024-07-30 09:07:32 -04:00
Sönke Holz
137cb0029b Kernel/USB: Use a Stream to parse USB descriptors
This fixes incorrect assumptions about the layout of descriptors and
gets rid of all the pointer arithmetic.
The USB spec doesn't define a strict order for all descriptors to appear
in.
It just says that endpoint descriptors follow its interface descriptor.
We also have to skip all unknown descriptors (which also can appear
anywhere), not just HID descriptors.
2024-07-27 13:28:15 -04:00
Sönke Holz
594664d9b5 Kernel/USB: Add AssertSizes to USB descriptor definitions 2024-07-27 13:28:15 -04:00
Sönke Holz
8799524b00 Kernel/USB: Don't copy the USBConfiguration during device initialization 2024-07-27 09:40:09 -04:00
Sönke Holz
d8cfe3b4a8 Kernel/USB: Pass the configuration value in the GET_DESCRIPTOR request
The low byte of wValue is the configuration value for
GetDescriptor(Configuration) requests.
2024-07-27 09:40:09 -04:00
Sönke Holz
a5b33734f8 Kernel/USB: Explicitly request the boot protocol in the USB mouse driver
By default the report protocol is used.
2024-07-27 09:40:09 -04:00
Sönke Holz
4f573ebdc3 Kernel/USB: Add spec references to HID/Codes.h 2024-07-27 09:40:09 -04:00
Sönke Holz
345117e404 Kernel/USB: Handle USB mice with more than one interface
This simply looks for the first interface with the appropriate class,
subclass and protocol which we can initialize now.
2024-07-27 09:40:09 -04:00
Sönke Holz
ed73aa3364 Kernel/USB: Don't prepend "0x" to the logged VID/PID in the mouse driver
This just looks silly and USB VID/PIDs are typically formatted without
the prefix.
2024-07-27 09:40:09 -04:00
Sönke Holz
64f827dbc8 Kernel/USB: Correct the xHCI version check
0x102 would be 1.0.2, not 1.2.0.
2024-07-27 09:40:09 -04:00
Sönke Holz
c04f240398 Kernel: Set the configuration during USB Hub initialization
All USB Devices (including hubs) need to have a configuration set before
you can use them. We already do this in other USB drivers, but forgot to
do it for USB hubs as well.
2024-07-26 14:25:49 -04:00
Idan Horowitz
3dec9aa54e Kernel: Add a minimal xHCI driver implementation
This adds a minimal (that is, just enough to make USB mouse/keyboard
work) implementation of an xHCI driver, to let us use serenity on
modern baremetal machines.
2024-07-26 14:25:49 -04:00
Idan Horowitz
ccd614212f Kernel: Correct pointer math in USBConfiguration::enumerate_interfaces
Both the calculation for the interface descriptor address and the
endpoint descriptors addresses (for second interface and above) were
incorrect, and would read the wrong data (and go out-of-bounds as well)
2024-07-26 14:25:49 -04:00
Idan Horowitz
c35446b232 Kernel: Give USB::Pipe a reference to its owning USB::Device
Previously USB::Pipe would just try to poorly maintain copies of some
of the relevant properties of USB::Device. (address & speed)
Now it just holds a reference to it's owning device and can query them
when needed.
2024-07-26 14:25:49 -04:00
Idan Horowitz
c5956663f7 Kernel: Move USB device initialization to controllers
The current USB::Device::enumerate_device() implementation is UHCI
specific, and is not relevant for xHCI controllers.

Move it to a USBController virtual method to allow different
implementations for the other controller types.
2024-07-26 14:25:49 -04:00
Idan Horowitz
b4cdd6a55c Kernel: Prevent integer overflow in USB::Hub::check_for_port_updates()
The maximum valid value is 255, so max + 1 doesn't fit in a u8.
2024-05-27 17:35:42 +02:00
Sönke Holz
018a28cf4a Kernel/HID: Add support for virtio input devices 2024-05-23 11:16:57 -06:00
Kirill Nikolaev
99f6528009 Kernel: Implement virtio-blk driver 2024-05-23 00:59:39 -06:00