summaryrefslogtreecommitdiff
path: root/Kernel/Bus/USB
AgeCommit message (Collapse)Author
2021-10-14Kernel: Add per platform Processor.h headersJames Mintram
The platform independent Processor.h file includes the shared processor code and includes the specific platform header file. All references to the Arch/x86/Processor.h file have been replaced with a reference to Arch/Processor.h.
2021-10-14Kernel: Add header includes closer to their useJames Mintram
2021-10-03Kernel: Use `operator ""sv` in all purpose() implementationsBrian Gianforcaro
Previously there was a mix of returning plain strings and returning explicit string views using `operator ""sv`. This change switches them all to standardized on `operator ""sv` as it avoids a call to strlen.
2021-10-01Kernel: Move x86 IO instructions code into the x86 specific folderLiav A
2021-09-29Kernel/PCI: Remove Address from enumeration callbackLiav A
If we need that address, we can always get it from the DeviceIdentifier.
2021-09-29Kernel/PCI: Cache interrupt line and interrupt pin of a deviceLiav A
This allows us to remove the PCI::get_interrupt_line API function. As a result, this removes a bunch of not so great patterns that we used to cache PCI interrupt line in many IRQHandler derived classes instead of just using interrupt_number method of IRQHandler class.
2021-09-29Kernel/PCI: Propagate usage of DeviceIdentifier everywhereLiav A
This allows us to remove a bunch of PCI API functions, and instead to leverage the cached data from DeviceIdentifier object in many places.
2021-09-29Kernel: Rename two PCI componentsLiav A
Rename ID => HardwareID, and PhysicalID => DeviceIdentifier. This change merely does that to clarify what these objects really are.
2021-09-29Kernel/PCI: Cache more details about PCI devices when enumerating themLiav A
There's no good reason to fetch these values each time we need them.
2021-09-10AK+Everywhere: Reduce the number of template parameters of IntrusiveListAli Mohammad Pur
This makes the user-facing type only take the node member pointer, and lets the compiler figure out the other needed types from that.
2021-09-07Kernel: Make it possible for KBufferBuilder creation to failAndreas Kling
This patch adds KBufferBuilder::try_create() and treats it like anything else that can fail. And so, failure to allocate the initial internal buffer of the builder will now propagate an ENOMEM to the caller. :^)
2021-09-07Kernel: Rename FileDescription => OpenFileDescriptionAndreas Kling
Dr. POSIX really calls these "open file description", not just "file description", so let's call them exactly that. :^)
2021-09-07Everywhere: Behaviour => BehaviorAndreas Kling
2021-09-07Kernel: Store process names as KStringAndreas Kling
2021-09-07Kernel: Make UserOrKernelBuffer return KResult from read/write/memsetAndreas Kling
This allows us to simplify a whole bunch of call sites with TRY(). :^)
2021-09-07Kernel/PCI: Simplify the entire subsystemLiav A
A couple of things were changed: 1. Semantic changes - PCI segments are now called PCI domains, to better match what they are really. It's also the name that Linux gave, and it seems that Wikipedia also uses this name. We also remove PCI::ChangeableAddress, because it was used in the past but now it's no longer being used. 2. There are no WindowedMMIOAccess or MMIOAccess classes anymore, as they made a bunch of unnecessary complexity. Instead, Windowed access is removed entirely (this was tested, but never was benchmarked), so we are left with IO access and memory access options. The memory access option is essentially mapping the PCI bus (from the chosen PCI domain), to virtual memory as-is. This means that unless needed, at any time, there is only one PCI bus being mapped, and this is changed if access to another PCI bus in the same PCI domain is needed. For now, we don't support mapping of different PCI buses from different PCI domains at the same time, because basically it's still a non-issue for most machines out there. 2. OOM-safety is increased, especially when constructing the Access object. It means that we pre-allocating any needed resources, and we try to find PCI domains (if requested to initialize memory access) after we attempt to construct the Access object, so it's possible to fail at this point "gracefully". 3. All PCI API functions are now separated into a different header file, which means only "clients" of the PCI subsystem API will need to include that header file. 4. Functional changes - we only allow now to enumerate the bus after a hardware scan. This means that the old method "enumerate_hardware" is removed, so, when initializing an Access object, the initializing function must call rescan on it to force it to find devices. This makes it possible to fail rescan, and also to defer it after construction from both OOM-safety terms and hotplug capabilities.
2021-09-06Kernel: Make SysFS and ProcFS generator functions return KResultAndreas Kling
This allows us to propagate a whole bunch of KBufferBuilder errors.
2021-09-06Kernel/USB: Use TRY() and adopt_nonnull_own_or_enomem() some moreAndreas Kling
2021-09-06Kernel: Make kernel region allocators return KResultOr<NOP<Region>>Andreas Kling
This expands the reach of error propagation greatly throughout the kernel. Sadly, it also exposes the fact that we're allocating (and doing other fallible things) in constructors all over the place. This patch doesn't attempt to address that of course. That's work for our future selves.
2021-09-06Kernel/USB: Tidy up UHCIDescriptorPool constructionAndreas Kling
- Use KResultOr<NonnullRefPtr<UHCIDescriptorPool<T>> - Make the constructor private - Use TRY() at call sites
2021-09-06Kernel/USB: Tidy up USB::Transfer constructionAndreas Kling
2021-09-06Kernel: Use TRY() some more in USB::HubAndreas Kling
2021-09-05Kernel: Make all Spinlocks use u8 for storage, remove templateBrian Gianforcaro
The default template argument is only used in one place, and it looks like it was probably just an oversight. The rest of the Kernel code all uses u8 as the type. So lets make that the default and remove the unused template argument, as there doesn't seem to be a reason to allow the size to be customizable.
2021-09-05Kernel: Switch static_asserts of a type size to AK::AssertSizeBrian Gianforcaro
This will provide better debug ability when the size comparison fails.
2021-09-05Kernel/USB: Use TRY() in the various USB classesAndreas Kling
2021-09-05AK+Kernel: Move KResult.h to Kernel/API for userspace accesssin-ack
This commit moves the KResult and KResultOr objects to Kernel/API to signify that they may now be freely used by userspace code at points where a syscall-related error result is to be expected. It also exposes KResult and KResultOr to the global namespace to make it nicer to use for userspace code.
2021-09-04Kernel/SysFS: Ensure data stability when reading from InodesLiav A
Like with the ProcFS, description data can change at anytime, so it's wise to ensure that when the userland reads from an Inode, data is consistent unless the userland indicated it wants to refresh the data (by seeking to offset 0, or re-attaching the Inode). Otherwise, if the data changes in the middle of the reading, it can cause silent corruption in output which can lead to random crashes.
2021-09-03AK: Rename create<T> => make_ref_counted<T>Andreas Kling
And also try_create<T> => try_make_ref_counted<T>. A global "create" was a bit much. The new name matches make<T> better, which we've used for making single-owner objects since forever.
2021-08-31Kernel/Userland: Expose usb device address and use it in `lsusb`Jesse Buhagiar
We now expose the `USBDevice`'s address in the SysFS object. This means that device addresses are no longer determined by the name of the file in the `/bus/usb/` directory. This was an incorrect way of determining device address, as a standard PC can have multiple USB controllers (and hence multiple buses) that can have overlapping device IDs.
2021-08-23Kernel: Rename PCI::DeviceController => PCI::DeviceLiav A
Now that the old PCI::Device was removed, we can complete the PCI changes by making the PCI::DeviceController to be named PCI::Device. Really the entire purpose and the distinction between the two was about interrupts, but since this is no longer a problem, just rename it to simplify things further.
2021-08-23Kernel/PCI: Delete PCI::Device in its current formLiav A
I created this class a long time ago just to be able to quickly make a PCI device to also represent an interrupt handler (because PCI devices have this capability for most devices). Then after a while I introduced the PCI::DeviceController, which is really almost the same thing (a PCI device class that has Address member in it), but is not tied to interrupts so it can have no interrupts, or spawn interrupt handlers however it wants to seems fit. However I decided it's time to say goodbye for this class for a couple of reasons: 1. It made a whole bunch of weird patterns where you had a PCI::Device and a PCI::DeviceController being used in the topic of implementation, where originally, they meant to be used mutually exclusively (you can't and really don't want to use both). 2. We can really make all the classes that inherit from PCI::Device to inherit from IRQHandler at this point. Later on, when we have MSI interrupts support, we can go further and untie things even more. 3. It makes it possible to simplify the VirtIO implementation to a great extent. While this commit almost doesn't change it, future changes can untangle some complexity in the VirtIO code. For UHCIController, E1000NetworkAdapter, NE2000NetworkAdapter, RTL8139NetworkAdapter, RTL8168NetworkAdapter, E1000ENetworkAdapter we are simply making them to inherit the IRQHandler. This makes some sense, because the first 3 devices will never support anything besides IRQs. For the last 2, they might have MSI support, so when we start to utilize those, we might need to untie these classes from IRQHandler and spawn IRQHandler(s) or MSIHandler(s) as needed. The VirtIODevice class is also a case where we currently need to use both PCI::DeviceController and IRQHandler classes as parents, but it could also be untied from the latter.
2021-08-22Kernel: Rename ScopedSpinlock => SpinlockLockerAndreas Kling
This matches MutexLocker, and doesn't sound like it's a lock itself.
2021-08-22Kernel: Rename SpinLock => SpinlockAndreas Kling
2021-08-19Kernel/USB: Remove unused `free` function from QueueHeadJesse Buhagiar
This function is no longer required as the freeing is done inside of the controller class through the pool interface.
2021-08-19Kernel/USB: Harden Descriptor memory allocationJesse Buhagiar
The previous version of this was pretty bad and caused a lot of odd behevaiour to occur. We now abstract a lot of the allocation behind a `template`d pool class that handles all of the memory allocation.
2021-08-19Kernel/USB: Remove unused include from UHCIController.cppJesse Buhagiar
2021-08-19Kernel/USB: Move UHCI related structures to subdirectoryJesse Buhagiar
The number of UHCI related files is starting to expand to the point where it's best if we move this into their own subdirectory. It'll also make it easier to manage when we decide to add some more controller types (whenever that may be)
2021-08-17Kernel: Fix compilation with ClangTimothy Flynn
Co-Authored-By: Andrew Kaster <akaster@serenityos.org>
2021-08-15Kernel: Make Kernel::VMObject allocation functions return KResultOrsin-ack
This makes for nicer handling of errors compared to checking whether a RefPtr is null. Additionally, this will give way to return different types of errors in the future.
2021-08-14Kernel/USB: Remove UAF in device removalLuke
I was using a raw pointer instead of a RefPtr to keep the device alive during removal.
2021-08-14Kernel/USB: Update SysFS from the generic hub instead of from UHCILuke
2021-08-14Kernel/USB: Split SysFS code into its own fileLuke
This makes it controller agnostic and allows us to access it from the USB hub code. The copyright says "Liav A." because git blame says he wrote this.
2021-08-14Kernel/USB: Replace PortNumber enum with a raw u8Luke
A hub can technically have up to 255 ports, given that bNbrPorts is a u8 and the DeviceRemovable field is a VLA to support up to 255 ports. Source: USB 2.0 Specification Section 11.23.2.1 That means this enum is not going to scale well in terms of size. Replacing it with a raw u8 allows me to remove the two port assumption and a cast.
2021-08-14Kernel/USB: Remove get_device_{at_port,from_address}Luke
Nothing was using these. These can be put back in the future if required. This also allows removing the devices array in UHCI.
2021-08-14Kernel/USB: Add Hubs and the UHCI Root HubLuke
2021-08-14Kernel/USB: Add the USB 1.x/2.0 hub descriptorLuke
There is a different hub descriptor for USB 3.0, but this isn't included here.
2021-08-14Kernel/USB: Use allocate_kernel_region in Transfer buffer allocationsLuke
Previously it would create a contiguous AVMO manually and pass it to MM. This uses supervisor pages that quickly run out as they never get returned and crash the system. Instead, use allocate_kernel_region as we're only allocating a page so it will be contiguous and will be returned when destroyed. A potentially better solution would be to use a pool of transfers to avoid all the allocations. This just prevents the system from crashing within ~5 seconds from the continuous hub polling.
2021-08-14Kernel/USB: Pass in device address as last argument to Pipe constructorLuke
The order of poll_interval and device_address was flipped.
2021-08-14Kernel/USB: Use "Pipe" instead of "USBPipe" in USBEndpointLuke
This wasn't caught before because nothing was including this header.
2021-08-14Kernel/USB: Add endpoint directions and make endpoint constants publicLuke