summaryrefslogtreecommitdiff
path: root/Kernel/Devices
AgeCommit message (Collapse)Author
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-26Kernel: Use generic functions to change interrupt state of ProcessorTimon Kruiper
This allows these files to be built for aarch64.
2022-10-25Kernel: Introduce global variables and stats in /sys/kernel directoryLiav A
The ProcFS is an utter mess currently, so let's start move things that are not related to processes-info. To ensure it's done in a sane manner, we start by duplicating all /proc/ global nodes to the /sys/kernel/ directory, then we will move Userland to use the new directory so the old directory nodes can be removed from the /proc directory.
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: Move x86-specific HID code to the Arch/x86 directoryLiav A
The i8042 controller with its attached devices, the PS2 keyboard and mouse, rely on x86-specific IO instructions to work. Therefore, move them to the Arch/x86 directory to make it easier to omit the handling code of these devices.
2022-09-20Kernel/PCI: Convert PCI BAR number to a strong typed enum classLiav A
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 VMWare backdoor communication code to the x86 directoryLiav A
The VMWare backdoor handling code involves many x86-specific instructions and therefore should be in the Arch/x86 directory. This ensures we can easily omit the code in compile-time for non-x86 builds.
2022-09-20Kernel: Don't blindly compile Bochs debug output code in ConsoleDeviceLiav A
Only use the Bochs debug output if we compile a x86 build since bochs debug output relies on x86 specific instructions. We also remove the CONSOLE_OUT_TO_BOCHS_DEBUG_PORT flag as we always compile bochs debug output for x86 builds and we always want to include the bochs debug output capability as it is very handy and doesn't hurt bare metal hardware or do any other problem besides taking a small amount of CPU cycles.
2022-09-20Kernel: Move PCSpeaker code to the x86-specific architecture directoryLiav A
The PCSpeaker code is specific to x86 platforms, thus it makes sense to put in the Arch/x86 subdirectory.
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-14Everywhere: Fix a variety of typosBrian Gianforcaro
Spelling fixes found by `codespell`.
2022-08-24Kernel: Simplify the File memory-mapping APIAndreas Kling
Before this change, we had File::mmap() which did all the work of setting up a VMObject, and then creating a Region in the current process's address space. This patch simplifies the interface by removing the region part. Files now only have to return a suitable VMObject from vmobject_for_mmap(), and then sys$mmap() itself will take care of actually mapping it into the address space. This fixes an issue where we'd try to block on I/O (for inode metadata lookup) while holding the address space spinlock. It also reduces time spent holding the address space lock.
2022-08-24Kernel: Wrap process address spaces in SpinlockProtectedAndreas Kling
This forces anyone who wants to look into and/or manipulate an address space to lock it. And this replaces the previous, more flimsy, manual spinlock use. Note that pointers *into* the address space are not safe to use after you unlock the space. We've got many issues like this, and we'll have to track those down as wlel.
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-30Kernel: Detect the Insert keygggggg-gggggg
2022-07-19Kernel/Devices: Abstract SysFS Device add/remove methods more properlyLiav A
It is starting to get a little messy with how each device can try to add or remove itself to either /sys/dev/block or /sys/dev/char directories. To better do this, we introduce 4 virtual methods to take care of that, so until we ensure all nodes in /sys/dev/block and /sys/dev/char are actual symlinks, we allow the Device base class to call virtual methods upon insertion or before being destroying, so it add itself elegantly to either of these directories or remove itself when needed. For special cases where we need to create symlinks, we have two virtual methods to be called otherwise to do almost the same thing mentioned before, but to use symlinks instead.
2022-07-15Kernel/SysFS: Add /sys/devices/storage directoryLiav A
This change in fact does the following: 1. Use support for symlinks between /sys/dev/block/ storage device identifier nodes and devices in /sys/devices/storage/{LUN}. 2. Add basic nodes in a /sys/devices/storage/{LUN} directory, to let userspace to know about the device and its details.
2022-07-15Kernel/Devices: Add two protected methods for DeviceManagement functionsLiav A
These methods are essentially splitted from the after_inserting method and the will_be_destroyed method so later on we can allow Storage devices to override the after_inserting method and the will_be_destroyed method while still being able to use shared functionality as before, such as adding the device to and removing it from the device list.
2022-07-15Kernel: Declare BlockDevice::is_block_device method protectedLiav A
2022-07-15Kernel/SysFS: Reduce the responsibilities of the Registry objectLiav A
Instead, let the /sys/dev/block and /sys/dev/char directories to handle the registering part of SysFSDeviceComponents by themselves.
2022-07-15Kernel/SysFS: Rename Devices code folder => DeviceIdentifiersLiav A
This folder in the SysFS code represents everything related to /sys/dev, which is a directory meant to be a convenient interface to track all IDs of all block and character devices (ID = major:minor numbers).
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-10Kernel+SystemServer: Make KCOVDevice a character deviceLiav A
This device should not be a block device, as in Serenity, block devices represent an interface to either disk partitions or storage devices.
2022-06-23Kernel/Audio: Fix buffer size underflow for non-page-aligned sizeskleines Filmröllchen
When the size of the audio data was not a multiple of a page size, subtracting the page size from this unsigned variable would underflow it close to 2^32 and be clamped to the page size again. This would lead to writes into garbage addresses because of an incorrect write size, interestingly only causing the write() call to error out. Using saturating math neatly fixes this problem and allows buffer lengths that are not a multiple of a page size.
2022-06-17Kernel/SysFS: Migrate components code from SysFS.cpp to the SysFS folderLiav A
2022-06-17Kerenl/Firmware: Add map_ebda and map_bios methods in the original placeLiav A
In a previous commit I moved everything into the new subdirectories in FileSystem/SysFS directory without trying to actually make changes in the code itself too much. Now it's time to split the code to make it more readable and understandable, hence this change occurs now.
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-15Kernel: Don't VERIFY that the DMA channel is running on AC'97 interruptkleines Filmröllchen
Fixes #13771; as discussed it's not really a problem to receive an interrupt while the DMA channel is not running, but we do want to log it.
2022-05-06Kernel/HID: Take a spinlock when calling KeyboardClient::on_key_pressedLiav A
The KeyboardClient class member could be updated due to TTY switch, so we must ensure we always use a valid pointer.
2022-04-20Kernel: Allow WorkQueue items allocation failures propagationLiav A
In most cases it's safe to abort the requested operation and go forward, however, in some places it's not clear yet how to handle these failures, therefore, we use the MUST() wrapper to force a kernel panic for now.
2022-04-20Kernel: Move VMWareBackdoor to new directory in the Firmware directoryLiav A
2022-04-18Kernel: Enable PS2 keyboard scan code translation if not already enabledLiav A
On the QEMU microvm machine type, it became apparent that the BIOS was not setting the i8042 controller to function as expected. To ensure that the controller is always outputting correct scan codes, set it to scan code 2 and enable first port translation to ensure all scan codes are translated to scan code set 1. This is the expected behavior when using SeaBIOS, but on qboot (the BIOS for the QEMU microvm machine type), the firmware doesn't take care of this so we need to do this ourselves.
2022-04-01Everywhere: Run clang-formatIdan Horowitz
2022-04-01Kernel: Stop debug spam when using read on /dev/mem deviceLiav A
This is not really useful and quite annoying so let's disable it by default.
2022-04-01Kernel: Stop debug spam when using mmap on /dev/mem deviceLiav A
This is not really useful and quite annoying so let's disable it by default.
2022-04-01Kernel: Declare Device major and minor data member numbers as constLiav A
This is just another "safety guard" to ensure these numbers don't ever change after being set for a certain Device at construction time.
2022-03-28Kernel: Propagate HIDManagement initialisation error to initLorenz Steinert
Initialisation errors for HIDManagement are now returned to the init. In the init we assert by MUST if we get an error.
2022-03-28Kernel/Devices/HID: Propagate errors of HIDDevices properlyLorenz Steinert
Some error indication was done by returning bool. This was changed to propagate the error by ErrorOr from the underlying functions. The returntype of the underlying functions was also changed to propagate the error.
2022-03-27Kernel: Expose block size in AsyncBlockDeviceRequest structPankaj Raghav
Expose the block size variable via a member function in the AsyncBlockDeviceRequest so that the driver doesn't need to assume any value such as 512 bytes.
2022-03-22Kernel: Create SelfTTYDevice class to help replace /dev/tty symlinkLiav A
This will replace the /dev/tty symlink created by SystemServer, so instead of a symlink, a character device will be created. When doing read(2), write(2) and ioctl(2) on this device, it will "redirect" these operations to the attached TTY of the current process.
2022-03-19Kernel: Increase i8042 timeout when writing and reading from deviceLiav A
This proved to be crucial on my ICH7 test machine because it takes a bit more time to do IO on its i8042 controller.
2022-03-18Kernel: Default initialize AC97::m_codec_revisionBrian 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-03-07Kernel: Wrap HIDManagement keymap data in SpinlockProtectedAndreas Kling
This serializes access to the current keymap data everywhere in the kernel, allowing to mark sys$setkeymap() as not needing the big lock.
2022-03-04Kernel: Report AC'97 vendor and device IDJelle Raaijmakers
2022-03-02Kernel/Audio: Don't try to enumerate PCI adapters if PCI is disabledLiav A