Commit graph

335 commits

Author SHA1 Message Date
Hendiadyoin1 b17f080dcc Kernel/riscv: Use new DeviceTree helpers in PCI initializations
This also changes the PCI interface slightly to be a bit nicer to work
with.
2024-05-02 07:44:13 -06:00
Idan Horowitz 002bba4a97 Kernel: Configure PCI interrupt routing based on the FDT 2024-04-30 06:01:26 -06:00
Liav A. b9df8deba2 Kernel/USB: Don't include UHCIController.h in USBPipe.h
The USB::Pipe is abstracted from the actual USB host controller
implementation, so don't include the UHCIController.h file.
Also, we missed an include to UserOrKernelBuffer.h, so this is added to
ensure the code can still compile.
2024-04-28 22:30:48 +02:00
Liav A. 2bba9411ca Kernel: Use the AK SetOnce container class in various cases
We have many places in the kernel code that we have boolean flags that
are only set once, and never reset again but are checked multiple times
before and after the time they're being set, which matches the purpose
of the SetOnce class.
2024-04-26 23:46:23 -06:00
Idan Horowitz 543fc4d0fc Kernel: Support automatic configuration of PCI bridges based on the FDT
This let's us actually boot with RISC-V.
2024-04-26 09:52:56 +02:00
Idan Horowitz 08d4b231e1 Kernel: Take EnumerableDeviceIdentifier by const ref instead of by value
It's 48 bytes.
2024-04-26 09:52:56 +02:00
Idan Horowitz f6ae9f8a6d Kernel: Reset enumerated buses bitmap before enumerating PCI devices
This allows this method to be used more than once.
2024-04-26 09:52:56 +02:00
Idan Horowitz 95aff1cf13 Kernel: Remove unused IterationDecision in enumerate_attached_devices 2024-04-26 09:52:56 +02:00
Idan Horowitz e350d3b2c6 Kernel: Use PCI:Class:ID::Bridge instead of magic value 2024-04-26 09:52:56 +02:00
Idan Horowitz 519be6e626 Kernel: Use correctly-sized read when checking PCI host bridge function
We were accidentally doing a 16-bit read instead of an 8-bit read,
meaning we would also read the 'CACHE_LINE_SIZE' field immediately
following it, and never actually continue.
2024-04-26 09:52:56 +02:00
Timothy Flynn ec492a1a08 Everywhere: Run clang-format
The following command was used to clang-format these files:

    clang-format-18 -i $(find . \
        -not \( -path "./\.*" -prune \) \
        -not \( -path "./Base/*" -prune \) \
        -not \( -path "./Build/*" -prune \) \
        -not \( -path "./Toolchain/*" -prune \) \
        -not \( -path "./Ports/*" -prune \) \
        -type f -name "*.cpp" -o -name "*.mm" -o -name "*.h")

There are a couple of weird cases where clang-format now thinks that a
pointer access in an initializer list, e.g. `m_member(ptr->foo)`, is a
lambda return statement, and it puts spaces around the `->`.
2024-04-24 16:50:01 -04:00
Dan Klishch 5ed7cd6e32 Everywhere: Use east const in more places
These changes are compatible with clang-format 16 and will be mandatory
when we eventually bump clang-format version. So, since there are no
real downsides, let's commit them now.
2024-04-19 06:31:19 -04:00
Hendiadyoin1 b0fc5bea91 Kernel/PCI: Prefer structured bindings when iterating over HashMaps
This makes `Access::rescan_hardware` look a bit nicer.
2024-03-01 14:05:53 -07:00
Hendiadyoin1 a99bd8eda6 Kernel/riscv64: Initialize PCI controllers using the device tree
Currently the search path is limited to `/soc/pci*` but this is enough
to get it to work on qemu.
2024-02-24 16:43:44 -07:00
Sönke Holz 6fd02d2a04 Kernel: Add PCI::map_bar overloads that don't take an explicit size
These overloads map the entire BAR space instead.
2024-02-24 16:36:47 -07:00
Sönke Holz 06a32b6e16 Kernel/USB: Handle non-page aligned EHCI controller BARs correctly
BARs don't have to be page-aligned. This patch correctly calculates the
needed memory range and register base address in that region.
2024-02-22 07:36:45 +01:00
Nico Weber 24a469f521 Everywhere: Prefer {:#x} over 0x{:x} in format strings
The former automatically adapts the prefix to binary and octal
output, and is what we already use in the majority of cases.

Patch generated by:

    rg -l '0x\{' | xargs sed -i '' -e 's/0x{:/{:#/'

I ran it 4 times (until it stopped changing things) since each
invocation only converted one instance per line.

No behavior change.
2024-02-21 17:54:38 +01:00
Tim Ledbetter 532f2b644c Kernel: Propagate errors with TRY() where possible 2024-02-14 17:46:06 -05:00
Hendiadyoin1 2dc20f9e39 Kernel: Use the new API to query and map BAR spaces in most places
This might be a bit overkill in some instances, but it's nice to be
consistent
2024-01-12 15:59:47 -07:00
Hendiadyoin1 c65455e122 Kernel: Expand BAR address mask up to 64 bit
Otherwise we would end up truncating the address when applying the mask

Co-Authored-By: Sönke Holz <sholz8530@gmail.com>
2024-01-12 15:59:47 -07:00
Hendiadyoin1 2f98c7d470 Kernel: Add convenience helpers for mapping PCI BAR spaces 2024-01-12 15:59:47 -07:00
Hendiadyoin1 f4bfd0468b Kernel/USB: Add a rudimentary interrogation only EHCI driver
This adds a simple EHCI driver that currently only interrogates the
device and checks if all ports are addressable via associated legacy
controllers (companion controllers), and warns if this is not the case.

This also adds a lot of the other data structures needed for actually
driving the controller, but these are currently not hooked up to
anything.

To test this run with `SERENITY_EXTRA_QEMU_ARGS="--device usb-ehci"`
or the q35 machine type
2023-12-28 17:08:34 +01:00
Sönke Holz da88d766b2 Kernel/riscv64: Make the kernel compile
This commits inserts TODOs into all necessary places to make the kernel
compile on riscv64!
2023-11-10 15:51:31 -07:00
Andrew Kaster 91816c15f8 Kernel: Don't register USB devices if USBManagement is not initialized 2023-10-17 11:02:25 -06:00
Edwin Rijkee 8388fe51b5 Kernel: Add a framebuffer driver for 3Dfx Voodoo 3
A bit old but a relatively uncomplicated device capable of outputting
1920x1080 video with 32-bit color. Tested with a Voodoo 3 3000 16MB
PCI card. Resolution switching from DisplaySettings also works.

If the requested mode contains timing information, it is used directly.
Otherwise, display timing values are selected from the EDID. First the
detailed timings are checked, and then standard and established
timings for which there is a matching DMT mode. The driver does not
(yet) read the actual EDID, so the generic EDID in DisplayConnector now
includes a set of common display modes to make this work.

The driver should also be compatible with the Voodoo Banshee, 4 and 5
but I don't have these cards to test this with. The PCI IDs of these
cards are included as a commented line in case someone wants to give it
a try.
2023-10-16 01:25:45 +02:00
Liav A 77441079dd Kernel/HID: Introduce initial USB mouse support 2023-10-15 22:56:30 +02:00
Liav A 430e987078 Kernel/USB: Don't invoke async callback if transfer data size is 0
We can't do anything valuable with such "transfer" so just discard it.
2023-10-15 22:56:30 +02:00
Liav A e7c1148ec6 Kernel/USB: Handle NAK correctly in a transfer status bits 2023-10-15 22:56:30 +02:00
Hendiadyoin1 29292bbdbf Kernel/USB: Add a crude USB MassStorage driver :^) 2023-09-29 16:14:47 -06:00
Hendiadyoin1 c230a0d96f Kernel: Avoid some copies during USBInterface enumeration/creation 2023-09-29 16:14:47 -06:00
Hendiadyoin1 b857c6b92f Kernel/USB: Make USBControllers pseudo StorageControllers
This will be needed in the next commit to generate valid LUNs
2023-09-29 16:14:47 -06:00
Hendiadyoin1 4b327bdc95 Kernel/USB: Add UKBuffer variants of certain BulkPipe/Transfer functions
These will be useful for directly accessing the source/destination
buffers, without going through a third buffer first.
2023-09-29 16:14:47 -06:00
Hendiadyoin1 8335803045 Kernel/USB: Explicitely copy descriptor.hub_characteristics for printing
This field is in a packed struct, which makes it possibly misaligned.
This knowledge is lost when invoking `dbgln` triggering an unaligned
access to it, aka UB. By explicitely copying it we avoid this issue.
2023-09-29 16:14:47 -06:00
Hendiadyoin1 c9a4ab9987 Kernel/USB: Add missing include in USBInterface.h 2023-09-29 16:14:47 -06:00
Hendiadyoin1 d39acfb908 Kernel/USB: Copy device configurations when copying devices 2023-09-29 16:14:47 -06:00
Liav A 7718842829 Kernel/VirtIO: Ensure proper error propagation in core methods
Simplify core methods in the VirtIO bus handling code by ensuring proper
error propagation. This makes initialization of queues, handling changes
in device configuration, and other core patterns more readable as well.

It also allows us to remove the obnoxious pattern of checking for
boolean "success" and if we get false answer then returning an actual
errno code.
2023-09-24 19:54:23 -06:00
Hendiadyoin1 cfba182b61 Kernel/PCI: Make SATAProgIF comparable with ProgrammingInterface
This makes checking it a bit nicer
2023-09-22 18:39:37 -06:00
Hendiadyoin1 d64d03e0d6 Kernel: Make Graphics device detection a bit more idomatic 2023-09-22 18:39:37 -06:00
Hendiadyoin1 e7012a9245 Kernel: Use PCI/Definitions.h for PCI-USB controller magic numbers 2023-09-22 18:39:37 -06:00
Hendiadyoin1 693f3ad33e Kernel: Add some more PCI [Sub]Class IDs 2023-09-22 18:39:37 -06:00
Hendiadyoin1 66647b58d4 Kernel: Make PCI [Sub]ClassCode comparable to the corresponding ID enums 2023-09-22 18:39:37 -06:00
Hendiadyoin1 d168bfabc4 Kernel/USB: Detach devices from their driver when they are detached 2023-09-18 11:09:19 -06:00
Jesse Buhagiar b4cd354bae Kernel/USB: Add driver search on device plug
When a device is plugged into the machine (and hence, when
`Device::try_create()` is called), then we attempt to load a driver by
calling that driver's probe function.
2023-09-18 11:09:19 -06:00
Jesse Buhagiar b0ed126538 Kernel/USB: Expose USBConfiguration in USBInterface 2023-09-18 11:09:19 -06:00
Jesse Buhagiar 3cfdc6e363 Kernel/USB: Add get_driver_by_name helper in USBManagement 2023-09-18 11:09:19 -06:00
Jesse Buhagiar 2aa17f619c Kernel/USB: Add USB Driver register/unregister function 2023-09-18 11:09:19 -06:00
Jesse Buhagiar a0dd6ec6b1 Kernel/USB: Add driver_init section
At any one given time, there can be an abitrary number of USB drivers in
the system. The way driver mapping works (i.e, a device is inserted, and
a potentially matching driver is probed) requires us to have
instantiated driver objects _before_ a device is inserted. This leaves
us with a slight "chicken and egg" problem. We cannot call the probe
function before the driver is initialised, but we need to know _what_
driver to initialise.

This section is designed to store pointers to functions that are called
during the last stage of the early `_init` sequence in the Kernel. The
accompanying macro in `USBDriver` emits a symbol, based on the driver
name, into this table that is then automatically called.

This way, we enforce a "common" driver model; driver developers are not
only required to write their driver and inherit from `USB::Driver`, but
are also required to have a free floating init function that registers
their driver with the USB Core.
2023-09-18 11:09:19 -06:00
Jesse Buhagiar 8883da9586 Kernel/USB: Add new Driver base class
Co-Authored-By: Liav A <liavalb@gmail.com>
Co-Authored-By: Leon Albrecht <leon2002.la@gmail.com>
2023-09-18 11:09:19 -06:00
Liav A d61c23569e Kernel/VirtIO: Introduce the concept of transport options
The VirtIO specification defines many types of devices with different
purposes, and it also defines 3 possible transport mediums where devices
could be connected to the host machine.

We only care about the PCIe transport, but this commit puts the actual
foundations for supporting the lean MMIO transport too in the future.

To ensure things are kept abstracted but still functional, the VirtIO
transport code is responsible for what is deemed as related to an actual
transport type - allocation of interrupt handlers and tinkering with low
level transport-related registers, etc.
2023-09-16 14:04:17 -06:00
Liav A 3fd4997fc2 Kernel: Don't allocate memory for names of processes and threads
Instead, use the FixedCharBuffer class to ensure we always use a static
buffer storage for these names. This ensures that if a Process or a
Thread were created, there's a guarantee that setting a new name will
never fail, as only copying of strings should be done to that static
storage.

The limits which are set are 32 characters for processes' names and 64
characters for thread names - this is because threads' names could be
more verbose than processes' names.
2023-08-09 21:06:54 -06:00