summaryrefslogtreecommitdiff
path: root/Kernel/Devices/USB
AgeCommit message (Collapse)Author
2021-07-02Kernel/USB: Move the USB components as a subfolder to the Bus directoryLiav A
2021-07-02Kernel/PCI: Move the PCI components as a subfolder to the Bus directoryLiav A
2021-06-29Kernel: Remove some unnecessary JSON related includesAndreas Kling
2021-06-29Kernel: Introduce the new ProcFS designLiav A
The new ProcFS design consists of two main parts: 1. The representative ProcFS class, which is derived from the FS class. The ProcFS and its inodes are much more lean - merely 3 classes to represent the common type of inodes - regular files, symbolic links and directories. They're backed by a ProcFSExposedComponent object, which is responsible for the functional operation behind the scenes. 2. The backend of the ProcFS - the ProcFSComponentsRegistrar class and all derived classes from the ProcFSExposedComponent class. These together form the entire backend and handle all the functions you can expect from the ProcFS. The ProcFSExposedComponent derived classes split to 3 types in the manner of lifetime in the kernel: 1. Persistent objects - this category includes all basic objects, like the root folder, /proc/bus folder, main blob files in the root folders, etc. These objects are persistent and cannot die ever. 2. Semi-persistent objects - this category includes all PID folders, and subdirectories to the PID folders. It also includes exposed objects like the unveil JSON'ed blob. These object are persistent as long as the the responsible process they represent is still alive. 3. Dynamic objects - this category includes files in the subdirectories of a PID folder, like /proc/PID/fd/* or /proc/PID/stacks/*. Essentially, these objects are always created dynamically and when no longer in need after being used, they're deallocated. Nevertheless, the new allocated backend objects and inodes try to use the same InodeIndex if possible - this might change only when a thread dies and a new thread is born with a new thread stack, or when a file descriptor is closed and a new one within the same file descriptor number is opened. This is needed to actually be able to do something useful with these objects. The new design assures that many ProcFS instances can be used at once, with one backend for usage for all instances.
2021-06-24Everywhere: Use nothrow new with `adopt_{ref,own}_if_nonnull`Daniel Bertalan
This commit converts naked `new`s to `AK::try_make` and `AK::try_create` wherever possible. If the called constructor is private, this can not be done, so we instead now use the standard-defined and compiler-agnostic `new (nothrow)`.
2021-06-24Kernel: Move special sections into Sections.hHendiadyoin1
This also removes a lot of CPU.h includes infavor for Sections.h
2021-06-18USB: Store device descriptor on enumerationJesse Buhagiar
We now store the device descriptor obtained from the device during enumeration in the device's object in memory instead of exposing all of the different members contained within it.
2021-06-18USB: Store devices in globally accessible arrayJesse Buhagiar
USB Devices are now stored so that they may be later retrieved and operated on (i.e, fetching their assigned device address via ProcFS)
2021-06-17Kernel/Interrupts: Return boolean on whether we handled the interruptLiav A
If we are in a shared interrupt handler, the called handlers might indicate it was not their interrupt, so we should not increment the call counter of these handlers.
2021-06-17Kernel/Interrupts: Add sensible purposes to VirtIO and USB devicesLiav A
When we enumerate the interrupt handlers, it's a good idea to show a meaningful name to the user instead of "IRQ Handler".
2021-06-12USB: Further Implement USB StructuresJesse Buhagiar
These are the actual structures that allow USB to work (i.e the ones actually defined in the specification). This should provide us enough of a baseline implementation that we can build on to support different types of USB device.
2021-05-15Kernel: Fix UHCIController singleton startup null-deref race condition.Brian Gianforcaro
The following KUBSAN crash on startup was reported on discord: ``` UHCI: Started KUBSAN: reference binding to null pointer of type struct UHCIController KUBSAN: at ../../Kernel/Devices/USB/UHCIController.cpp, line 67 ``` After inspecting the code, it became clear that there's a window of time where the kernel task which monitors the UHCI port can startup and start executing before the UHCIController constructor completes. This leaves the singleton pointing to nullptr, thus in the duration of this race window the "UHCI port proc" thread will go an and de-reference the null pointer when trying to read for status changes on the UHCI root ports. Reported-by: @stelar7 Reported-by: @bcoles Fixes: #6154
2021-05-01Everywhere: Turn #if *_DEBUG into dbgln_if/if constexprGunnar Beutner
2021-04-22Everything: Move to SPDX license identifiers in all files.Brian Gianforcaro
SPDX License Identifiers are a more compact / standardized way of representing file license information. See: https://spdx.dev/resources/use/#identifiers This was done with the `ambr` search and replace tool. ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-18Kernel: Add boot argument to disable the UHCI ControllerLuke
Helps with bare metal debugging, as we can't be sure our implementation will work with a given machine. As reported by someone on Discord, their machine hangs when we attempt the dummy transfer.
2021-04-07Kernel: Remove unused UHCI_ENABLED flagAndreas Kling
2021-03-21Kernel: Renable UHCIController on 64-bit processorsHendiadyoin1
2021-03-12Kernel: Convert klog() => AK::Format in UHCIControllerAndreas Kling
2021-03-04Kernel: Make the kernel compile & link for x86_64Andreas Kling
It's now possible to build the whole kernel with an x86_64 toolchain. There's no bootstrap code so it doesn't work yet (obviously.)
2021-03-02Kernel: Make Thread use AK::Time internallyBen Wiederhake
This commit is very invasive, because Thread likes to take a pointer and write to it. This means that translating between timespec/timeval/Time would have been more difficult than just changing everything that hands a raw pointer to Thread, in bulk.
2021-02-23Everywhere: Rename ASSERT => VERIFYAndreas Kling
(...and ASSERT_NOT_REACHED => VERIFY_NOT_REACHED) Since all of these checks are done in release builds as well, let's rename them to VERIFY to prevent confusion, as everyone is used to assertions being compiled out in release. We can introduce a new ASSERT macro that is specifically for debug checks, but I'm doing this wholesale conversion first since we've accumulated thousands of these already, and it's not immediately obvious which ones are suitable for ASSERT.
2021-02-19Kernel: Slap UNMAP_AFTER_INIT on a bunch more functionsAndreas Kling
We're now able to unmap 100 KiB of kernel text after init. :^)
2021-02-17Kernel: Convert dbgprintf()/klog() => dbgln()/dmesgln() in UHCI codeAndreas Kling
2021-02-15Kernel: Ignore unobserved BlockResult from Thread::SleepBrian Gianforcaro
Suppress these in preparation for making BlockResult [[nodiscard]].
2021-01-26Meta: Split debug defines into multiple headers.asynts
The following script was used to make these changes: #!/bin/bash set -e tmp=$(mktemp -d) echo "tmp=$tmp" find Kernel \( -name '*.cpp' -o -name '*.h' \) | sort > $tmp/Kernel.files find . \( -path ./Toolchain -prune -o -path ./Build -prune -o -path ./Kernel -prune \) -o \( -name '*.cpp' -o -name '*.h' \) -print | sort > $tmp/EverythingExceptKernel.files cat $tmp/Kernel.files | xargs grep -Eho '[A-Z0-9_]+_DEBUG' | sort | uniq > $tmp/Kernel.macros cat $tmp/EverythingExceptKernel.files | xargs grep -Eho '[A-Z0-9_]+_DEBUG' | sort | uniq > $tmp/EverythingExceptKernel.macros comm -23 $tmp/Kernel.macros $tmp/EverythingExceptKernel.macros > $tmp/Kernel.unique comm -1 $tmp/Kernel.macros $tmp/EverythingExceptKernel.macros > $tmp/EverythingExceptKernel.unique cat $tmp/Kernel.unique | awk '{ print "#cmakedefine01 "$1 }' > $tmp/Kernel.header cat $tmp/EverythingExceptKernel.unique | awk '{ print "#cmakedefine01 "$1 }' > $tmp/EverythingExceptKernel.header for macro in $(cat $tmp/Kernel.unique) do cat $tmp/Kernel.files | xargs grep -l $macro >> $tmp/Kernel.new-includes ||: done cat $tmp/Kernel.new-includes | sort > $tmp/Kernel.new-includes.sorted for macro in $(cat $tmp/EverythingExceptKernel.unique) do cat $tmp/Kernel.files | xargs grep -l $macro >> $tmp/Kernel.old-includes ||: done cat $tmp/Kernel.old-includes | sort > $tmp/Kernel.old-includes.sorted comm -23 $tmp/Kernel.new-includes.sorted $tmp/Kernel.old-includes.sorted > $tmp/Kernel.includes.new comm -13 $tmp/Kernel.new-includes.sorted $tmp/Kernel.old-includes.sorted > $tmp/Kernel.includes.old comm -12 $tmp/Kernel.new-includes.sorted $tmp/Kernel.old-includes.sorted > $tmp/Kernel.includes.mixed for file in $(cat $tmp/Kernel.includes.new) do sed -i -E 's/#include <AK\/Debug\.h>/#include <Kernel\/Debug\.h>/' $file done for file in $(cat $tmp/Kernel.includes.mixed) do echo "mixed include in $file, requires manual editing." done
2021-01-25Everywhere: Hook up remaining debug macros to Debug.h.asynts
2021-01-25Everywhere: Remove unnecessary debug comments.asynts
It would be tempting to uncomment these statements, but that won't work with the new changes. This was done with the following commands: find . \( -name '*.cpp' -o -name '*.h' -o -name '*.in' \) -not -path './Toolchain/*' -not -path './Build/*' -exec awk -i inplace '$0 !~ /\/\/#define/ { if (!toggle) { print; } else { toggle = !toggle } } ; $0 ~/\/\/#define/ { toggle = 1 }' {} \; find . \( -name '*.cpp' -o -name '*.h' -o -name '*.in' \) -not -path './Toolchain/*' -not -path './Build/*' -exec awk -i inplace '$0 !~ /\/\/ #define/ { if (!toggle) { print; } else { toggle = !toggle } } ; $0 ~/\/\/ #define/ { toggle = 1 }' {} \;
2021-01-22Everywhere: Replace a bundle of dbg with dbgln.asynts
These changes are arbitrarily divided into multiple commits to make it easier to find potentially introduced bugs with git bisect.
2021-01-09Kernel: Don't put gratuitous cursing in kernel logAndreas Kling
2021-01-09Kernel/USB: Implement test transferJesse Buhagiar
We can now test a _very_ basic transaction via `do_debug_transfer()`. This function merely attaches some TDs to the LSCTRL queue head and points some input and output buffers. We then sense an interrupt with USBSTS value of 1, meaning Interrupt On Completion (of the transaction). At this point, the input buffer is filled with some data.
2021-01-09Kernel/USB: Simplify scheduleJesse Buhagiar
It seems like Haiku and Grub do this, so let's not bother with any fancy timing stuff for now (to at least get _something_ working...)
2021-01-09Kernel/USB: Ignore shared IRQsJesse Buhagiar
According the USB spec/UHCI datasheet (as well as the Linux and BSD source code), if we receive an IRQ and USBSTS is 0, then the IRQ does not belong to us and we should immediately jump out of the handler.
2021-01-09Kernel/USB: Add basic root port detection/managementJesse Buhagiar
We can now read/write to the two root ports exposed to the UHCI controller, and detect when a device is plugged in or out via a kernel process that constantly scans the port for any changes. This is very basic, but is a bit of fun to see the kernel detecting hardware on the fly :^)
2021-01-09Kernel/USB: Implement UHCI Data structuresJesse Buhagiar
Implemented both Queue Heads and Transfer Descriptors. These are required to actually perform USB transactions. The UHCI driver sets up a pool of these that can be allocated when we need them. It seems some drivers have these statically allocated, so it might be worth looking into that, but for now, the simple way seems to be to allocate them on the fly as we need them, and then release them.
2021-01-09Kernel/USB: Prevent system crash via correct UHCI inititilisationJesse Buhagiar
It seems that not setting the framelist address register was causing the entire system to lock up as it generated an insane interrupt storm in the IRQ handler for the UHCI controller. We now allocate a 4KiB aligned page via `MemoryManager::allocate_supervisor_physical_page()` and set every value to 1. In effect, this creates a framelist with each entry being a "TERMINATE" entry in which the controller stalls until its' 1mS time slice is up. Some more registers have also been set for consistency, though it seems like this don't need to be set explicitly in software.
2021-01-09Kernel/USB: Move USB classes into `USB` namespaceJesse Buhagiar
The entire USB spec involves more than just UHCI, so let's put everything into it's own nice namespace :^)
2021-01-09Kernel/USB: Move USB related files to into specific directoryJesse Buhagiar
As the USB/UHCI driver grows in size, it'll be much cleaner to have all of the USB related files in one folder where they can be easily accessed :^)