summaryrefslogtreecommitdiff
path: root/Kernel/Devices
AgeCommit message (Collapse)Author
2023-06-04Kernel: Move InterruptDisabler to the Interrupts subdirectoryLiav A
2023-06-04Kernel: Move all boot-related code to the new Boot subdirectoryLiav A
2023-06-04Everywhere: Move global Kernel pattern code to Kernel/Library directoryLiav A
This has KString, KBuffer, DoubleBuffer, KBufferBuilder, IOWindow, UserOrKernelBuffer and ScopedCritical classes being moved to the Kernel/Library subdirectory. Also, move the panic and assertions handling code to that directory.
2023-06-04Kernel: Move {Virtual,Physical}Address classes to the Memory directoryLiav A
2023-06-04Kernel: Move Random.{h,cpp} code to Security subdirectoryLiav A
2023-06-04Kernel: Move all tasks-related code to the Tasks subdirectoryLiav A
2023-06-02Kernel: Move the Storage directory to be a new directory under DevicesLiav A
The Storage subsystem, like the Audio and HID subsystems, exposes Unix device files (for example, in the /dev directory). To ensure consistency across the repository, we should make the Storage subsystem to reside in the Kernel/Devices directory like the two other mentioned subsystems.
2023-05-24Everywhere: Use MonotonicTime instead of Durationkleines Filmröllchen
This is easily identifiable by anyone who uses Duration::now_monotonic, and any downstream users of that data.
2023-05-24Kernel: Use UnixDateTime wherever applicablekleines Filmröllchen
"Wherever applicable" = most places, actually :^), especially for networking and filesystem timestamps. This includes changes to unzip, which uses DOSPackedTime, since that is changed for the FAT file systems.
2023-05-24AK: Rename Time to Durationkleines Filmröllchen
That's what this class really is; in fact that's what the first line of the comment says it is. This commit does not rename the main files, since those will contain other time-related classes in a little bit.
2023-05-19Kernel: Move a bunch of generic devices code into new subdirectoryLiav A
2023-04-15Kernel/HID: Don't use *LockRefPtrs in the I8042Controller codeLiav A
2023-04-15Kernel: Re-organize header includes in the HID subsystem codeLiav A
Just a small clean-up in the I8042Controller and HIDManagement code so it will be easier to modify this code in future changes.
2023-04-14Kernel: Get rid of *LockRefPtr in the SysFS filesystem codeLiav A
To do this we also need to get rid of LockRefPtrs in the USB code as well. Most of the SysFS nodes are statically generated during boot and are not mutated afterwards. The same goes for general device code - once we generate the appropriate SysFS nodes, we almost never mutate the node pointers afterwards, making locking unnecessary.
2023-04-14Kernel/Audio: Propagate errors when creating AudioChannelsLiav A
While doing this, we can also just return a normal RefPtr instead of a LockRefPtr, because we create these channels when initializing an audio controller, and never change the pointer in AudioController instances after their initialization, hence no locking is necessary.
2023-04-14Kernel/Audio: Simplify initialization sequence for driversLiav A
Instead of enumerating all available controllers and then ask each to find its audio channels, we change the initialization sequence to match what happens in the Networking subsystem and Graphics subsystem - we essentially probe for a matching driver on a PCI device, create a device instance, and immediately initialize it. This in fact allows us to immediately find any hardware initialization issues and report it, and then dropping the created instance, as usually being done in other initialization paths in the Kernel. This also opens the opportunity to propagate errors when failed to initialize an AudioChannel instance, and it will be addressed in a future commit.
2023-04-09Kernel/HID: Untie the PS2 protocol, i8042 hardware and generic devicesLiav A
For a very long time, the kernel had only support for basic PS/2 devices such as the PS2 AT keyboard and regular PS2 mouse (with a scroll wheel). To adapt to this, we had very simple abstractions in place, essentially, the PS2 devices were registered as IRQ handlers (IRQ 1 and 12), and when an interrupt was triggered, we simply had to tell the I8042Controller to fetch a byte for us, then send it back to the appropriate device for further processing and queueing of either a key event, or a mouse packet so userspace can do something meaningful about it. When we added the VMWare mouse integration feature it was easily adapted to this paradigm, requiring small changes across the handling code for these devices. This patch is a major cleanup for any future advancements in the HID subsystem. It ensures we do things in a much more sane manner: - We stop using LockRefPtrs. Currently, after the initialization of the i8042 controller, we never have to change RefPtrs in that class, as we simply don't support PS2 hotplugging currently. Also, we remove the unnecessary getters for keyboard and mouse devices which also returned a LockRefPtr. - There's a clear separation between PS2 devices and the actual device nodes that normally exist in /dev. PS2 devices are not polled, because when the user uses these devices, they will trigger an IRQ which when is handled, could produce either a MousePacket or KeyEvent, depending on the device state. The separation is crucial for buses that are polled, for example - USB is a polled bus and will not generate an IRQ for HID devices. - There's a clear separation in roles of each structure. The PS2 devices which are attached to a I8042Controller object are managing the device state, while the generic MouseDevice and KeyboardDevice manage all related tasks of a CharacterDevice, as well as interpreting scan code events and mouse relative/absolute coordinates.
2023-04-09Kernel: Stop lock & unlock repeatedly while reading from a mouse deviceLiav A
This was a thing we needed to do in the days where we didn't have safe_memcpy and some wrappers around it to handle possible page faults safely.
2023-04-09Kernel: Move HIDDevice::enable_interrupts method to I8042Device classLiav A
It happens to be that only PS/2 devices that are connected via the i8042 controller can generate interrupt events, so it makes much more sense to have those devices to implement the enable_interrupts method because of the I8042Device class and not the HIDDevice class.
2023-04-09Kernel: Introduce a new super class called HIDControllerLiav A
Use the new class in HID code, because all other HID device controllers will be using this class as their parent class. Hence, we no longer keep a reference to any PS/2 device in HIDManagement and rely on HIDController derived classes to do this for us. It also means that we removed another instance of a LockRefPtr, which is designated to be removed and is replaced by the better pattern of SpinlockProtected<RefPtr<>> instead.
2023-04-09Kernel: Remove redundant HID name from all associated filesLiav A
2023-04-05Kernel: Stop using *LockRefPtr for TTYAndreas Kling
TTY was only stored in Process::m_tty, so make that a SpinlockProtected.
2023-04-04Kernel: Stop using *LockRefPtr for Process pointersAndreas Kling
The only persistent one of these was Thread::m_process and that never changes after initialization. Make it const to enforce this and switch everything over to RefPtr & NonnullRefPtr.
2023-03-31Kernel/HID: Don't update the remapped Ctrl modifier unconditionallyLiav A
Instead, only update it when the Caps Lock key event is generated and remapping to the Ctrl key is enabled. This fixes a bug that when enabling remapping Caps Lock key to the Ctrl key, the original Ctrl key is no longer usable.
2023-03-25Kernel: Add support for Intel HDAJelle Raaijmakers
This is an implementation that tries to follow the spec as closely as possible, and works with Qemu's Intel HDA and some bare metal HDA controllers out there. Compiling with `INTEL_HDA_DEBUG=on` will provide a lot of detailed information that could help us getting this to work on more bare metal controllers as well :^) Output format is limited to `i16` samples for now.
2023-03-25Kernel: Mention right parent class for AC'97's `device_name`Jelle Raaijmakers
2023-03-07Kernel: Use non-locking {Nonnull,}RefPtr for OpenFileDescriptionAndreas Kling
This patch switches away from {Nonnull,}LockRefPtr to the non-locking smart pointers throughout the kernel. I've looked at the handful of places where these were being persisted and I don't see any race situations. Note that the process file descriptor table (Process::m_fds) was already guarded via MutexProtected.
2023-03-06Kernel: Stop using NonnullLockRefPtrVectorAndreas Kling
2023-02-24Kernel+Userland: Unify declarations for KCOV in Kernel/API/kcov.hLiav A
2023-01-27Kernel: Remove declarations for non-existent methodsSam Atkins
2023-01-26Kernel/PCI: Hold a reference to DeviceIdentifier in the Device classLiav A
There are now 2 separate classes for almost the same object type: - EnumerableDeviceIdentifier, which is used in the enumeration code for all PCI host controller classes. This is allowed to be moved and copied, as it doesn't support ref-counting. - DeviceIdentifier, which inherits from EnumerableDeviceIdentifier. This class uses ref-counting, and is not allowed to be copied. It has a spinlock member in its structure to allow safely executing complicated IO sequences on a PCI device and its space configuration. There's a static method that allows a quick conversion from EnumerableDeviceIdentifier to DeviceIdentifier while creating a NonnullRefPtr out of it. The reason for doing this is for the sake of integrity and reliablity of the system in 2 places: - Ensure that "complicated" tasks that rely on manipulating PCI device registers are done in a safe manner. For example, determining a PCI BAR space size requires multiple read and writes to the same register, and if another CPU tries to do something else with our selected register, then the result will be a catastrophe. - Allow the PCI API to have a united form around a shared object which actually holds much more data than the PCI::Address structure. This is fundamental if we want to do certain types of optimizations, and be able to support more features of the PCI bus in the foreseeable future. This patch already has several implications: - All PCI::Device(s) hold a reference to a DeviceIdentifier structure being given originally from the PCI::Access singleton. This means that all instances of DeviceIdentifier structures are located in one place, and all references are pointing to that location. This ensures that locking the operation spinlock will take effect in all the appropriate places. - We no longer support adding PCI host controllers and then immediately allow for enumerating it with a lambda function. It was found that this method is extremely broken and too much complicated to work reliably with the new paradigm being introduced in this patch. This means that for Volume Management Devices (Intel VMD devices), we simply first enumerate the PCI bus for such devices in the storage code, and if we find a device, we attach it in the PCI::Access method which will scan for devices behind that bridge and will add new DeviceIdentifier(s) objects to its internal Vector. Afterwards, we just continue as usual with scanning for actual storage controllers, so we will find a corresponding NVMe controllers if there were any behind that VMD bridge.
2023-01-21Kernel+Userland: Move LibC/sys/ioctl_numbers to Kernel/API/Ioctl.hAndrew Kaster
This header has always been fundamentally a Kernel API file. Move it where it belongs. Include it directly in Kernel files, and make Userland applications include it via sys/ioctl.h rather than directly.
2023-01-13Kernel: Remove outdated FIXME in the DeviceManagement codeLiav A
2023-01-07Kernel: Make Device::after_inserting to return ErrorOr<void>Liav A
Instead of just returning nothing, let's return Error or nothing. This would help later on with error propagation in case of failure during this method. This also makes us more paranoid about failure in this method, so when initializing a DisplayConnector we safely tear down the internal members of the object. This applies the same for a StorageDevice object, but its after_inserting method is much smaller compared to the DisplayConnector overriden method.
2023-01-07Kernel: Mark Process::jail() method as constLiav A
We really don't want callers of this function to accidentally change the jail, or even worse - remove the Process from an attached jail. To ensure this never happens, we can just declare this method as const so nobody can mutate it this way.
2023-01-06Kernel: Make i8042 controller initialization sequence more robustLiav A
The setting of scan code set sequence is removed, as it's buggy and could lead the controller to fail immediately when doing self-test afterwards. We will restore it when we understand how to do so safely. Allow the user to determine a preferred detection path with a new kernel command line argument. The defualt option is to check i8042 presence with an ACPI check and if necessary - an "aggressive" test to determine i8042 existence in the system. Also, keep the i8042 controller pointer on the stack, so don't assign m_i8042_controller member pointer if it does not exist.
2023-01-05Kernel: Convert 2 instances of `dbgln` to `dmesgln_pci` in AC'97Jelle Raaijmakers
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-02Everywhere: Remove unused includes of AK/Memory.hBen Wiederhake
These instances were detected by searching for files that include AK/Memory.h, but don't match the regex: \\b(fast_u32_copy|fast_u32_fill|secure_zero|timing_safe_compare)\\b This regex is pessimistic, so there might be more files that don't actually use any memory function. In theory, one might use LibCPP to detect things like this automatically, but let's do this one step after another.
2023-01-02Everywhere: Remove unused includes of AK/StdLibExtras.hBen Wiederhake
These instances were detected by searching for files that include AK/StdLibExtras.h, but don't match the regex: \\b(abs|AK_REPLACED_STD_NAMESPACE|array_size|ceil_div|clamp|exchange|for ward|is_constant_evaluated|is_power_of_two|max|min|mix|move|_RawPtr|RawP tr|round_up_to_power_of_two|swap|to_underlying)\\b (Without the linebreaks.) This regex is pessimistic, so there might be more files that don't actually use any "extra stdlib" functions. In theory, one might use LibCPP to detect things like this automatically, but let's do this one step after another.
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.
2023-01-02Kernel: Remove unused includesBen Wiederhake
2022-12-28Kernel: Reorganize Arch/x86 directory to Arch/x86_64 after i686 removalLiav A
No functional change.
2022-12-28Kernel: Remove i686 supportLiav A
2022-12-09Kernel: Allow opening some device nodes sparingly for jailed processesLiav A
From now on, we don't allow jailed processes to open all device nodes in /dev, but only allow jailed processes to open /dev/full, /dev/zero, /dev/null, and various TTY and PTY devices (and not including virtual consoles) so we basically restrict applications to what they can do when they are in jail. The motivation for this type of restriction is to ensure that even if a remote code execution occurred, the damage that can be done is very small. We also don't restrict reading and writing on device nodes that were already opened, because that limit seems not useful, especially in the case where we do want to provide an OpenFileDescription to such device but nothing further than that.
2022-12-03Everywhere: Run clang-formatLinus Groh
2022-11-08Kernel: Split the SysFS core files into smaller componentsLiav A
2022-11-01AK+Kernel: Handle allocation failures in Device::try_make_requestGunnar Beutner
This adds try_* methods to AK::DoublyLinkedList and updates the Device class to use those to gracefully handle allocation failures. Refs #6369.
2022-11-01Kernel: Remove unused #includesGunnar Beutner
2022-10-26Kernel: Include missing headers for various filesTimon Kruiper
With these missing header files, we can now build these files for aarch64.