Commit graph

41 commits

Author SHA1 Message Date
Andreas Kling e475263113 AK+Kernel: Add AK::AtomicRefCounted and use everywhere in the kernel
Instead of having two separate implementations of AK::RefCounted, one
for userspace and one for kernelspace, there is now RefCounted and
AtomicRefCounted.
2022-08-20 17:15:52 +02:00
Liav A 70afa0b171 Kernel/SysFS: Mark SysFSDirectory traverse and lookup methods as final
This enforces us to remove duplicated code across the SysFS code. This
results in great simplification of how the SysFS works now, because we
enforce one way to treat SysFSDirectory objects.
2022-07-15 12:29:23 +02:00
sin-ack 3f3f45580a Everywhere: Add sv suffix to strings relying on StringView(char const*)
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-12 23:11:35 +02:00
Tim Schumacher 3b3af58cf6 Kernel: Annotate all KBuffer and DoubleBuffer with a custom name 2022-07-12 00:55:31 +01:00
Liav A 9c6834698f Kerenl/Firmware: Add map_ebda and map_bios methods in the original place
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-17 11:01:27 +02:00
Liav A 290eb53cb5 Kernel/SysFS: Stop cluttering the codebase with pieces of SysFS parts
Instead, start to put everything in one place to resemble the directory
structure of the SysFS when actually using it.
2022-06-17 11:01:27 +02:00
Timon Kruiper a4534678f9 Kernel: Implement InterruptDisabler using generic Processor functions
Now that the code does not use architectural specific code, it is moved
to the generic Arch directory and the paths are modified accordingly.
2022-06-02 13:14:12 +01:00
Liav A 02566d8091 Kernel: Move VMWareBackdoor to new directory in the Firmware directory 2022-04-20 19:21:32 +02:00
Idan Horowitz 086969277e Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
Liav A ae2ec45e78 Kernel: Allow SysFS components to have non-zero size
This is important for dmidecode because it does an fstat on the DMI
blobs, trying to figure out their size. Because we already know the size
of the blobs when creating the SysFS components, there's no performance
penalty whatsoever, and this allows dmidecode to not use the /dev/mem
device as a fallback.
2022-04-01 11:27:19 +02:00
Liav A 66ff60db07 Kernel: Declare DMI SysFS BIOS classes as final 2022-04-01 11:27:19 +02:00
Liav A 338b4b27eb Kernel: Declare blob sizes of SysFS BIOS classes as const 2022-04-01 11:27:19 +02:00
Liav A 96aae59e9c Kernel: Initialize primitive data members of SysFS BIOS classes 2022-04-01 11:27:19 +02:00
Lenny Maiorani c6acf64558 Kernel: Change static constexpr variables to constexpr where possible
Function-local `static constexpr` variables can be `constexpr`. This
can reduce memory consumption, binary size, and offer additional
compiler optimizations.

These changes result in a stripped x86_64 kernel binary size reduction
of 592 bytes.
2022-02-09 21:04:51 +00:00
Idan Horowitz d5189b6677 Kernel: Replace {String => KString}::formatted in ACPISysFSDirectory 2022-01-21 16:27:21 +01:00
Idan Horowitz fdfdb5bd1c Kernel: Make ACPI reboot OOM-fallible 2022-01-21 16:27:21 +01:00
Idan Horowitz 3945e239e1 Kernel: Don't populate the ACPI SysFS directory with a disabled ACPI
This would cause a nullptr dereference on ACPI::Parser::the().
2022-01-18 21:00:46 +02:00
Idan Horowitz fb3e46e930 Kernel: Make map_typed() & map_typed_writable() fallible using ErrorOr
This mostly just moved the problem, as a lot of the callers are not
capable of propagating the errors themselves, but it's a step in the
right direction.
2022-01-13 22:40:25 +01:00
Idan Horowitz e2e5d4da16 Kernel: Make map_bios() and map_ebda() fallible using ErrorOr 2022-01-13 22:40:25 +01:00
mjz19910 3102d8e160 Everywhere: Fix many spelling errors 2022-01-07 10:56:59 +01:00
Brian Gianforcaro 6c66311ade Kernel: Use MUST + Vector::try_empend instead of Vector::empend
In preparation for making Vector::empend unavailable during
compilation of the Kernel.
2022-01-05 14:04:18 +01:00
Brian Gianforcaro 24066ba5ef Kernel: Use MUST + Vector::try_append instead of Vector::append
In preparation for making Vector::append unavailable during
compilation of the Kernel.
2022-01-05 14:04:18 +01:00
Tom 10efbfb09e Kernel: Scan ACPI memory ranges for the RSDP table
On some systems the ACPI RSDP table may be located in ACPI reserved
memory ranges rather than in the EBDA or BIOS areas.
2022-01-04 17:46:36 +00:00
Tom e70aa690d2 Kernel: Fix determining EBDA size
The first byte of the EBDA structure contains the size of the EBDA
in 1 KiB units. We were incorrectly using the word at offset 0x413
of the BDA which specifies the number of KiB before the EBDA structure.
2022-01-04 17:46:36 +00:00
Guilherme Goncalves 33b78915d3 Kernel: Propagate overflow errors from Memory::page_round_up
Fixes #11402.
2021-12-28 23:08:50 +01:00
Liav A 52e01b46eb Kernel: Move Multi Processor Parser code to a separate directory 2021-12-23 23:18:58 -08:00
Liav A bbdb55126c Kernel/SysFS: Don't allocate ACPISysFS components in constructors
Instead defer it to a method to be called after the construction of
ACPISysFSDirectory.
2021-12-14 09:01:33 +01:00
Liav A 381fdaa163 Kernel/SysFS: Make it clear that some components must be created in boot
Using the phrase "create" doesn't give information on whether the object
must be allocated or a failure to do so can be handled gracefully.
Therefore, we must use better phrase for such purpose, so "must_create"
for the allocate-and-construct static methods is definitely good choice.
2021-12-14 09:01:33 +01:00
Liav A 478f543899 Kernel/SysFS: Prevent allocation for component name during construction
Instead, allocate before constructing the object and pass NonnullOwnPtr
of KString to the object if needed. Some classes can determine their
names as they have a known attribute to look for or have a static name.
2021-12-14 09:01:33 +01:00
Daniel Bertalan 4a81b33c07 Everywhere: Fix -Winconsistent-missing-override warnings from Clang
This option is already enabled when building Lagom, so let's enable it
for the main build too. We will no longer be surprised by Lagom Clang
CI builds failing while everything compiles locally.

Furthermore, the stronger `-Wsuggest-override` warning is enabled in
this commit, which enforces the use of the `override` keyword in all
classes, not just those which already have some methods marked as
`override`. This works with both GCC and Clang.
2021-12-11 13:14:15 -08:00
Hendiadyoin1 21c5c4026b Kernel: Mark ACPI::Parser's empty destructor as default 2021-12-09 22:53:42 -08:00
Andreas Kling 8b1108e485 Everywhere: Pass AK::StringView by value 2021-11-11 01:27:46 +01:00
Andreas Kling 5f7d008791 AK+Everywhere: Stop including Vector.h from StringView.h
Preparation for using Error.h from Vector.h. This required moving some
things out of line.
2021-11-10 21:58:58 +01:00
Andreas Kling 79fa9765ca Kernel: Replace KResult and KResultOr<T> with Error and ErrorOr<T>
We now use AK::Error and AK::ErrorOr<T> in both kernel and userspace!
This was a slightly tedious refactoring that took a long time, so it's
not unlikely that some bugs crept in.

Nevertheless, it does pass basic functionality testing, and it's just
real nice to finally see the same pattern in all contexts. :^)
2021-11-08 01:10:53 +01:00
Brian Gianforcaro 2c85f65519 Kernel: Switch BIOSSysFSComponent constructor to AK::StringView
These are constants, they don't need to be dynamically allocated.
Another minor step towards removing `AK::String` from the Kernel
and improving OOM safety.
2021-11-02 11:34:31 +01:00
Liav A f8489da8ee Kernel/SysFS: Provide a way to "truncate" and "set" mtime on inodes
Normally, trying to truncate a SysFSInode should result in EPERM error.
However, as suggested by Ali (@alimpfard), we can allow the PowerState
node to be "truncated" so one can open that file with O_TRUNC option.
Likewise, we also need to provide a way to set modified time on SysFS
inodes. For most inodes, we should return ENOTIMPL error, but for the
power state switch, we ignore the modified time setting and just return
KSuccess.

These fixes allow to do "echo -n 1 > /sys/firmware/power_state" in Shell
after gaining root permissions, to switch the power state.
2021-10-09 12:07:56 +02:00
Brian Gianforcaro 3a945051fc Kernel: Use operator ""sv in all purpose() implementations
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-03 13:36:10 +02:00
Liav A 4974727dbb Kernel: Move x86 IO instructions code into the x86 specific folder 2021-10-01 12:27:20 +02:00
Liav A 8d0dbdeaac Kernel+Userland: Introduce a new way to reboot and poweroff the machine
This change removes the halt and reboot syscalls, and create a new
mechanism to change the power state of the machine.
Instead of how power state was changed until now, put a SysFS node as
writable only for the superuser, that with a defined value, can result
in either reboot or poweroff.
In the future, a power group can be assigned to this node (which will be
the GroupID responsible for power management).

This opens an opportunity to permit to shutdown/reboot without superuser
permissions, so in the future, a userspace daemon can take control of
this node to perform power management operations without superuser
permissions, if we enforce different UserID/GroupID on that node.
2021-09-12 11:52:16 +02:00
Liav A 33f033066c Kernel: Unify BIOS and ACPI components in the SysFS firmware directory
Both should reside in the SysFS firmware directory which is normally
located in /sys/firmware.
Also, apply some OOM-safety patterns when creating the BIOS and ACPI
directories.
2021-09-12 11:52:16 +02:00
Liav A 9132596b8e Kernel: Move ACPI and BIOS code into the new Firmware directory
This will somwhat help unify them also under the same SysFS directory in
the commit.
Also, it feels much more like this change reflects the reality that both
ACPI and the BIOS are part of the firmware on x86 computers.
2021-09-12 11:52:16 +02:00