summaryrefslogtreecommitdiff
path: root/Kernel/Bus/USB
AgeCommit message (Collapse)Author
2023-01-05Kernel: Add dmesgln_pci logging for Kernel::PCIEvan Smal
A virtual method named device_name() was added to Kernel::PCI to support logging the PCI::Device name and address using dmesgln_pci. Previously, PCI::Device did not store the device name. All devices inheriting from PCI::Device now use dmesgln_pci where they previously used dmesgln.
2023-01-02Kernel: Turn lock ranks into template parameterskleines Filmröllchen
This step would ideally not have been necessary (increases amount of refactoring and templates necessary, which in turn increases build times), but it gives us a couple of nice properties: - SpinlockProtected inside Singleton (a very common combination) can now obtain any lock rank just via the template parameter. It was not previously possible to do this with SingletonInstanceCreator magic. - SpinlockProtected's lock rank is now mandatory; this is the majority of cases and allows us to see where we're still missing proper ranks. - The type already informs us what lock rank a lock has, which aids code readability and (possibly, if gdb cooperates) lock mismatch debugging. - The rank of a lock can no longer be dynamic, which is not something we wanted in the first place (or made use of). Locks randomly changing their rank sounds like a disaster waiting to happen. - In some places, we might be able to statically check that locks are taken in the right order (with the right lock rank checking implementation) as rank information is fully statically known. This refactoring even more exposes the fact that Mutex has no lock rank capabilites, which is not fixed here.
2022-11-12Kernel/USB: Use proper verbs for Pipe transfer methodsb14ckcat
2022-11-12Kernel/USB: Add support for async & interrupt transfersb14ckcat
Add support for async transfers by using a separate kernel task to poll a list of active async transfers on a set time interval, and invoke their user-provided callback function when they are complete. Also add support for the interrupt class of transfers, building off of this async functionality.
2022-10-26Kernel: Include missing headers for various filesTimon Kruiper
With these missing header files, we can now build these files for aarch64.
2022-10-22Kernel+USB: Move descriptor bookkeeping into seperate structure(s)Jesse Buhagiar
We now have a seperately allocated structure for the bookkeeping information in the QueueHead and TransferDescriptor UHCI strucutres. This way, we can support 64-bit pointers in UHCI, fixing a problem where 32-bit pointers would truncate the upper 32-bits of the (virtual) address of the descriptor, causing a crash. Co-authored-by: b14ckcat <b14ckcat@protonmail.com>
2022-10-18Kernel/USB: Refactor USB Pipeb14ckcat
Decompose the current monolithic USBD Pipe interface into several subclasses, one for each pair of endpoint type & direction. This is to make it more clear what data and functionality belongs to which Pipe type, and prevent nonsensical things like trying to execute a control transfer on a non-control pipe. This is important, because the Pipe class is the interface by which USB device drivers will interact with the HCD, so the clearer and more explicit this interface is the better.
2022-10-18Kernel/USB: Adjust USB Pipe bufferb14ckcat
Allocate DMA buffer pages for use within the USBD Pipe class, and allow for the user to specify the size of this buffer, rounding up to the next page boundary.
2022-09-23Kernel: Introduce the IOWindow classLiav A
This class is intended to replace all IOAddress usages in the Kernel codebase altogether. The idea is to ensure IO can be done in arch-specific manner that is determined mostly in compile-time, but to still be able to use most of the Kernel code in non-x86 builds. Specific devices that rely on x86-specific IO instructions are already placed in the Arch/x86 directory and are omitted for non-x86 builds. The reason this works so well is the fact that x86 IO space acts in a similar fashion to the traditional memory space being available in most CPU architectures - the x86 IO space is essentially just an array of bytes like the physical memory address space, but requires x86 IO instructions to load and store data. Therefore, many devices allow host software to interact with the hardware registers in both ways, with a noticeable trend even in the modern x86 hardware to move away from the old x86 IO space to exclusively using memory-mapped IO. Therefore, the IOWindow class encapsulates both methods for x86 builds. The idea is to allow PCI devices to be used in either way in x86 builds, so when trying to map an IOWindow on a PCI BAR, the Kernel will try to find the proper method being declared with the PCI BAR flags. For old PCI hardware on non-x86 builds this might turn into a problem as we can't use port mapped IO, so the Kernel will gracefully fail with ENOTSUP error code if that's the case, as there's really nothing we can do within such case. For general IO, the read{8,16,32} and write{8,16,32} methods are available as a convenient API for other places in the Kernel. There are simply no direct 64-bit IO API methods yet, as it's not needed right now and is not considered to be Arch-agnostic too - the x86 IO space doesn't support generating 64 bit cycle on IO bus and instead requires two 2 32-bit accesses. If for whatever reason it appears to be necessary to do IO in such manner, it could probably be added with some neat tricks to do so. It is recommended to use Memory::TypedMapping struct if direct 64 bit IO is actually needed.
2022-09-20Kernel: Remove stale includes of x86 IO header fileLiav A
The AHCI code doesn't rely on x86 IO at all as it only uses memory mapped IO so we can simply remove the header. We also simply don't use x86 IO in the Intel graphics driver, so we can simply remove the include of the x86 IO header there too. Everything else was a bunch of stale includes to the x86 IO header and are actually not necessary, so let's remove them to make it easier to compile non-x86 Kernel builds.
2022-09-20Kernel: Move IO delay code to x86 architecture subdirectoryLiav A
Many code patterns and hardware procedures rely on reliable delay in the microseconds granularity, and since they are using such delays which are valid cases, but should not rely on x86 specific code, we allow to determine in compile time the proper platform-specific code to use to invoke such delays.
2022-09-17Kernel/USB: Hotplug multiple USB device crash hotfixb14ckcat
2022-08-28Kernel/USB: Rework UHCI interrupt transfer scheduleb14ckcat
This reworks the way the UHCI schedule is set up to handle interrupt transfers, creating 11 queue heads each assigned a different period/latency, so that interrupt transfers can be linked into the schedule with their specified period more easily.
2022-08-28Kernel/USB: Rework queued transfer scheduleb14ckcat
Modifies the way the UHCI schedule is set up & modified to allow for multiple transfers of the same type, from one or more devices, to be queued up and handled simultaneously.
2022-08-20Kernel: Make self-contained locking smart pointers their own classesAndreas Kling
Until now, our kernel has reimplemented a number of AK classes to provide automatic internal locking: - RefPtr - NonnullRefPtr - WeakPtr - Weakable This patch renames the Kernel classes so that they can coexist with the original AK classes: - RefPtr => LockRefPtr - NonnullRefPtr => NonnullLockRefPtr - WeakPtr => LockWeakPtr - Weakable => LockWeakable The goal here is to eventually get rid of the Lock* classes in favor of using external locking.
2022-08-20AK+Kernel: Add AK::AtomicRefCounted and use everywhere in the kernelAndreas Kling
Instead of having two separate implementations of AK::RefCounted, one for userspace and one for kernelspace, there is now RefCounted and AtomicRefCounted.
2022-08-19Kernel: Require lock rank for Spinlock constructionkleines Filmröllchen
All users which relied on the default constructor use a None lock rank for now. This will make it easier to in the future remove LockRank and actually annotate the ranks by searching for None.
2022-07-27Kernel: Fix USB hotplug crashb14ckcat
Currently the SysFS node for USB devices is only initialized for USB hubs, which means it will cause a kernel crash upon being dereferenced in a non-hub device. This fixes the problem by making initialization happen for all USB devices.
2022-07-19Kernel/USB: Make UHCI descriptor pool thread-safeb14ckcat
Right now the TD and QH descriptor pools look to be susceptible to a race condition in the event they are accessed simultaneously by separate threads making USB transfers. This fix does not seem to add any noticeable overhead.
2022-07-15Kernel/SysFS: Adapt USB plug code to work with SysFS patternsLiav A
2022-07-15Kernel/USB: Support UHCI full speed bandwidth reclamationb14ckcat
2022-07-12Everywhere: Add sv suffix to strings relying on StringView(char const*)sin-ack
Each of these strings would previously rely on StringView's char const* constructor overload, which would call __builtin_strlen on the string. Since we now have operator ""sv, we can replace these with much simpler versions. This opens the door to being able to remove StringView(char const*). No functional changes.
2022-07-03Kernel/USB: Move buffer allocation from USB transfer to USB pipeb14ckcat
Currently when allocating buffers for USB transfers, it is done once for every transfer rather than once upon creation of the USB device. This commit changes that by moving allocation of buffers to the USB Pipe class where they can be reused.
2022-06-29Kernel/USB: Use proper error codes for UHCI transfersb14ckcat
2022-06-17Kernel/SysFS: Split bulky SysFSUSB file into two separate class filesLiav A
2022-06-17Kernel/SysFS: Stop cluttering the codebase with pieces of SysFS partsLiav A
Instead, start to put everything in one place to resemble the directory structure of the SysFS when actually using it.
2022-06-05Kernel: Unify Kernel task names for consistencyBrian Gianforcaro
This change unifies the naming convention for kernel tasks. The goal of this change is to: - Make the task names more descriptive, so users can more easily understand their purpose in System Monitor. - Unify the naming convention so they are consistent.
2022-06-02Kernel/USB: Rename `get_interfaces` to something more sensibleJesse Buhagiar
This name was misleading, as it wasn't really "getting" anything. It has hence been renamed to `enumerate_interfaces` to reflect what it's actually doing.
2022-06-02Kernel/USB: Flesh out USB SysFS objectsJesse Buhagiar
Each USB object now contains the entire descriptor chain for the device instead of just info from the device descriptor.
2022-06-02Kernel/USB: Add interface descriptor accessorJesse Buhagiar
2022-06-02Kernel/USB: Add configuration descriptor accessorJesse Buhagiar
2022-06-02Kernel/USB: Make USBInterface endpoints accessibleJesse Buhagiar
These weren't accessible by an accessor, so let's fix that :^)
2022-06-02Kernel/USB: Make USBConfiguration interfaces accessibleJesse Buhagiar
These weren't accessible by an accessor, so let's fix that :^)
2022-05-21Kernel/USB: Add support for bulk transfersb14ckcat
2022-04-26Kernel: Put USB request constants in namespaceb14ckcat
Moved constants in USBRequest.h from global scope to the Kernel::USB namespace.
2022-04-22Kernel/USB: Send correct data for Root Hub Configuration DescriptorJesse Buhagiar
A request of `GET_DESCRIPTOR` should be sending the entire configuration chain, and not just the configuration descriptor.
2022-04-22Kernel/USB: Get all interface descriptors on enumerationJesse Buhagiar
This creates all interfaces when the device is enumerated, with a link to the configuration that it is a part of. As such, a new class, `USBInterface` has been introduced to express this state.
2022-04-22Kernel/USB: Add new `USBHIDDescriptor` typeJesse Buhagiar
2022-04-22Kernel/USB: Add `control_transfer()` function `USB::Device`Jesse Buhagiar
Some other parts of the USB stack may require us to perform a control transfer. Instead of abusing `friend` to expose the default pipe, let's just expose it via a function.
2022-04-22Kernel/USB: Fetch configuration descriptors on enumerationJesse Buhagiar
This also introduces a new class, `USBConfiguration` that stores a configuration. The device, when instructed, sets this configuration and holds a pointer to it so we have a record of what configuration is currently active.
2022-04-01Everywhere: Run clang-formatIdan Horowitz
2022-03-18Kernel: Zero initialize USBDevice::m_device_descriptorBrian Gianforcaro
Found by PVS-Studio.
2022-03-17Kernel: Use default constructors/destructorsLenny Maiorani
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#cother-other-default-operation-rules "The compiler is more likely to get the default semantics right and you cannot implement these functions better than the compiler."
2022-03-14Kernel/PCI: Don't hold spinlocks when doing fast device enumerationLiav A
Instead, hold the lock while we copy the contents to a stack-based Vector then iterate on it without any locking. Because we rely on heap allocations, we need to propagate errors back in case of OOM condition, therefore, both PCI::enumerate API function and PCI::Access::add_host_controller_and_enumerate_attached_devices use now a ErrorOr<void> return value to propagate errors. OOM Error can only occur when enumerating the m_device_identifiers vector under a spinlock and trying to expand the temporary Vector which will be used locklessly to actually iterate over the PCI::DeviceIdentifiers objects.
2022-02-27Everywhere: Make JSON serialization fallibleIdan Horowitz
This allows us to eliminate a major source of infallible allocation in the Kernel, as well as lay down the groundwork for OOM fallibility in userland.
2022-01-28Kernel: Make UHCIController::spawn_port_process OOM-fallibleIdan Horowitz
2022-01-28Kernel: Rename UHCIController::{spawn_port_proc => spawn_port_process}Idan Horowitz
There's no need to use this non-standard shorthand mnemonic. (This commit also removes the unimplemented do_debug_transfer while we're here.)
2022-01-12Kernel: Replace all usages of String::number with KString::numberIdan Horowitz
2022-01-09Kernel: Use DMA helper everywherePankaj Raghav
Port UCHI, AC97, SB16, BMIDEChannel and AHCIPort to use the helper to allocate DMA buffers.
2022-01-07Everywhere: Fix many spelling errorsmjz19910