Commit graph

7906 commits

Author SHA1 Message Date
Humberto Alves f6eb155167 Kernel: Support more clocks in sys$clock_getres()
Support all the available clocks in clock_getres(). Also, fix this
function to use the actual ticks per second value, not the constant
`_SC_CLK_TCK` (which is always equal to 8) and move the resolution
computation logic to TimeManagement.
2023-02-21 01:00:06 +01:00
Andreas Kling 0cdd227e9b Kernel: Fix const-correctness issue in StorageManagement
We have to take the StorageDevice as a mutable reference, otherwise
we can't perform any interesting I/O operations on it.
2023-02-21 00:54:04 +01:00
Andreas Kling b5cef78e35 Kernel: Make NVMeQueue const-correct internally
Store the DMA R/W page PhysicalPage object as an NNRP<T const>.
2023-02-21 00:54:04 +01:00
Andreas Kling 68c9781299 Kernel: Fix const-correctness of PCI::DeviceIdentifier usage 2023-02-21 00:54:04 +01:00
Andreas Kling 8bf248a046 Kernel: Make NNRP<PhysicalPage const> possible
This wasn't possible before as ref() and unref() were non-const.
2023-02-21 00:54:04 +01:00
Liav A ac4829cc50 Kernel/IntelGraphics: Move PLL handling code to a different file
Dealing with the specific details of how to program a PLL should be done
in a separate file to ensure we can easily expand it to support future
generations of the Intel graphics device.
2023-02-19 15:01:01 -07:00
Liav A 9eab59c42b Kernel/Graphics: Return ENODEV if there's no valid EDID to return
ENODEV better represents the fact that there might be no display device
(e.g. a monitor) connected to the connector, therefore we should return
this error.
Another reason to not use ENOTIMPL is that it's a requirement for all
DisplayConnectors to put a valid EDID in place even for a hardware we
don't currently support mode-setting in runtime.
2023-02-19 15:01:01 -07:00
Liav A b2da5d3e62 Kernel/Graphics: Allow Intel DisplayConnector to not have console 2023-02-19 15:01:01 -07:00
Liav A 016fedbd20 Kernel/IntelGraphics: Move DisplayPlane enable code to derived classes
Instead of doing that on the IntelDisplayPlane class, let's have this in
derived classes so these classes can decide how to use the settings that
were provided before calling the enable method.
2023-02-19 15:01:01 -07:00
Liav A e393071a9b Kernel/IntelGraphics: Add Generation enum to the Definitions file
This will be used to annotate which Generation is being used for each
Intel iGPU we discover.
2023-02-19 15:01:01 -07:00
Liav A 8042ae43c3 Kernel/IntelGraphics: Move pipe management to the Transcoder class
It became apparent to me that future generations of the Intel graphics
chipset utilize the same register set as part of the Transcoder register
set. Therefore, it should be included now in the Transcoder class.
2023-02-19 15:01:01 -07:00
Liav A 2def16a3d2 Kernel/Graphics: Introduce the IntelDisplayConnectorGroup class
In the real world, graphics hardware tend to have multiple display
connectors. However, usually the connectors share one register space but
still keeping different PLL timings and display lanes.
This new class should represent a group of multiple display connectors
working together in the same Intel graphics adapter. This opens an
opportunity to abstract the interface so we could support future Intel
iGPU generations.

This is also a preparation before the driver can support newer devices
and utilize their capabilities.
The mentioned preparation is applied in a these aspects:
1. The code is splitted into more classes to adjust to future expansion.
2 classes are introduced: IntelDisplayPlane and IntelDisplayTranscoder,
so the IntelDisplayPlane controls the plane registers and second class
controls the pipeline (transcoder, encoder) registers. On gen4 it's not
really useful because there are probably one plane and one encoder to
care about, but in future generations, there are likely to be multiple
transcoders and planes to accommodate multi head support.
2. The set_edid_bytes method in the DisplayConnector class can now be
told to not assume the provided EDID bytes are always invalid. Therefore
it can refrain from printing error messages if this flag parameter is
true. This is useful for supporting real hardware situation when on boot
not all ports are connected to a monitor, which can result in floating
bus condition (essentially all the bytes we read are 0xFF).
3. An IntelNativeDisplayConnector could now be set to flag other types
of connections such as eDP (embedded DisplayPort), Analog output, etc.
This is important because on the Intel gen4 graphics we could assume to
have one analog output connector, but on future generations this is very
likely to not be the case, as there might be no VGA outputs, but rather
only an eDP connector which is converted to VGA by a design choice of
the motherboard manufacturer.
4. Add ConnectorIndex to IntelNativeDisplayConnector class - Currently
this is used to verify we always handle the correct connector when doing
modesetting.
Later, it will be used to locate special settings needed when handling
connector requests.
5. Prepare to support more types of display planes. For example, the
Intel Skylake register set for display planes is a bit different, so
let's ensure we can properly support it in the near future.
2023-02-19 15:01:01 -07:00
Liav A 61f4914d6e Kernel+Userland: Add constants subdirectory at /sys/kernel directory
This subdirectory is meant to hold all constant data related to the
kernel. This means that this data is never meant to updated and is
relevant from system boot to system shutdown.
Move the inodes of "load_base", "cmdline" and "system_mode" to that
directory. All nodes under this new subdirectory are generated during
boot, and therefore don't require calling kmalloc each time we need to
read them. Locking is also not necessary, because these nodes and their
data are completely static once being generated.
2023-02-19 13:47:11 +01:00
Liav A 1acd679775 Kernel: Remove unnecessary include from SysFS PowerStateSwitch code
I added that include in 2e55956784 by a
mistake, so we should get rid of it as soon as possible.
2023-02-19 08:13:04 +00:00
Liav A 8266e40b35 Kernel/FileSystem: Don't assume flags for root filesystem mount flags
This is considered somewhat an abstraction layer violation, because we
should always let userspace to decide on the root filesystem mount flags
because it allows the user to configure the mount table to preferences
that they desire.
Now that SystemServer is modified to re-mount the root mount with the
desired flags, we can just mount the root filesystem without assuming
special flags.
2023-02-19 01:20:10 +01:00
Liav A 4a14138230 Kernel/FileSystem: Fix check of read offset for the RAMFSInode code
The check of ensuring we are not trying to read beyond the end of the
inode data buffer is already there, it's just that we need to disallow
further reading if the read offset equals to the inode data size.
2023-02-19 01:01:45 +01:00
Liav A 9790b81959 Kernel/FileSystem: Add check of read offset for the FATInode code
Apparently we lacked this important check from the beginning of this
piece of code. This check is crucial to ensure we only give back data
being related to the FATInode data buffer and nothing beyond it.
2023-02-19 01:01:45 +01:00
Peter Elliott f20902deb3 Kernel: Support sending filedescriptors with sendmsg(2) and SCM_RIGHTS
This is necessary to support the wayland protocol.
I also moved the CMSG_* macros to the kernel API since they are used in
both kernel and userspace.
this does not break ntpquery/SCM_TIMESTAMP.
2023-02-19 00:37:37 +01:00
Peter Elliott ae5d7f542c Kernel: Change polarity of weak ownership between Inode and LocalSocket
There was a bug in which bound Inodes would lose all their references
(because localsocket does not reference them), and they would be
deallocated, and clients would get ECONNREFUSED as a result. now
LocalSocket has a strong reference to inode so that the inode will live
as long as the socket, and Inode has a weak reference to the socket,
because if the socket stops being referenced anywhere it should not be
bound.

This still prevents the reference loop that
220b7dd779 was trying to fix.
2023-02-19 00:37:37 +01:00
Peter Elliott 2808b03764 Kernel: Support F_DUPFD_CLOEXEC command to fcntl(2)
Specified by POSIX:
https://pubs.opengroup.org/onlinepubs/9699919799/functions/fcntl.html
2023-02-19 00:37:37 +01:00
Undefine ab298ca106 Kernel: Dont crash if power states gets set to an invalid value 2023-02-18 23:52:20 +01:00
Timon Kruiper 13f5aa81e3 Kernel/aarch64: Disable memory access alignment check
Even though we currently build all of Userland and the Kernel with the
-mstrict-align flag, the compiler will still emit unaligned memory
accesses. To work around this, we disable the check for now. See
https://github.com/SerenityOS/serenity/issues/17516 for the relevant
issue.
2023-02-18 19:17:21 +01:00
Timon Kruiper 5d587ea562 Kernel/aarch64: Call handle_crash on unknown exceptions
This is useful for debugging, as it will now print out a userspace
backtrace, and optionally also dump the memory regions of the process.
2023-02-18 19:17:21 +01:00
Andrew Kaster 3a01573350 Revert "Kernel: Migrate ‘main id registerʼ access in Aarch64 MMIO"
This patch needed more review than it got.

This reverts commit a6526cd90c.
2023-02-17 11:29:33 -07:00
Andrew Kaster aac122ab17 Revert "Kernel: Remove old ‘main id register accessorʼ for Aarch64"
This patch needed more review than it got.

This reverts commit 84e8d5f418.
2023-02-17 11:29:33 -07:00
Ben Wiederhake 9a7b3c145f Everywhere: Change all XXX into FIXME or remove as appropriate 2023-02-15 23:33:25 +01:00
Timon Kruiper cfd73e5d9f Kernel/aarch64: Implement Thread Local Storage
This commit adds Processor::set_thread_specific_data, and this function
is used to factor out architecture specific implementation of setting
the thread specific data. This function is implemented for
aarch64 and x86_64, and the callsites are changed to use this function
instead.
2023-02-15 22:53:19 +01:00
Timon Kruiper 7d0917f50b Kernel/aarch64: Remove tpidr_el0 from RegisterState
In the next commit, this register will be populated by directly writing
to it, instead of using the RegisterState mechanism.
2023-02-15 22:53:19 +01:00
Timon Kruiper a98c0c3e51 Kernel/aarch64: Add implementations for safe_memset and safe_strnlen
They currently do not actually implement a safe memset or safe strnlen,
but this initial implementation works fine for now.
2023-02-15 22:53:19 +01:00
Timon Kruiper d1eec20773 Kernel/aarch64: Implement storing and restoring floating-point registers 2023-02-15 22:53:19 +01:00
Timon Kruiper e57d35ff53 Kernel/aarch64: Do not trap floating-point instructions
This requires setting the FPEN field of the Architectural Feature Access
Control Register (CPACR_EL1) to 0b11.
2023-02-15 22:53:19 +01:00
Timon Kruiper d5262a540c Kernel/aarch64: Handle SVC exception by calling syscall_handler
The SVC (supervisor call) instruction is used in userland to do
syscalls, and this commit adds the handling of syscalls to
Interrupts.cpp.
2023-02-15 22:53:19 +01:00
Ollrogge 361df6eff8 AK: Add conversion functions for packed DOS time format
This also adjusts the FATFS code to use the new functions and removes
the now redundant old conversion functions.
2023-02-12 13:13:15 -07:00
konrad 84e8d5f418 Kernel: Remove old ‘main id register accessorʼ for Aarch64 2023-02-10 11:51:47 -07:00
konrad a6526cd90c Kernel: Migrate ‘main id registerʼ access in Aarch64 MMIO 2023-02-10 11:51:47 -07:00
konrad d6c620dc4f Kernel: Provide better types in MIDR register accessor for Aarch64
This avoids unnecessary and-masks during reading.
2023-02-10 11:51:47 -07:00
Liav A ab27fce86f AK: Add a new method to propagate errno while printing errors in Kernel
This new method is meant to be used in both userspace and kernel code.
The idea is to allow printing of a verbose message and then returning an
errno code which is the proper mechanism for kernel code because we
should almost always assume that such error will be propagated back to
userspace in some way, so the userspace code could reasonably decode it.

For userspace code however, this new method is meant to be a simple
wrapper for Error::from_string_view, because for most invocations, it's
much more useful to have a verbose & literal error than a errno code, so
we simply ignore that errno code completely in such context.
2023-02-10 09:14:20 +00:00
Liav A df72c9327b Kernel: Return proper errno codes from Coredump::write_regions method 2023-02-10 09:14:20 +00:00
Liav A 2d1719da73 Kernel/Net: Propagate proper errno codes from determine_network_device
Returning literal strings is not the proper action here, because we
should always assume that error could be propagated back to userland, so
we need to keep a valid errno when returning an Error.
2023-02-10 09:14:20 +00:00
Liav A 2715f91c92 Kernel/VirtIOGPU: Propagate proper errno codes from query_and_set_edid
Returning literal strings is not the proper action here, because we
should always assume that error could be propagated back to userland, so
we need to keep a valid errno when returning an Error.
2023-02-10 09:14:20 +00:00
Timothy Flynn 604d5f5bca AK+Everywhere: Do not implicitly copy variables in TRY macros
For example, consider cases where we want to propagate errors only in
specific instances:

    auto result = read_data(); // something like ErrorOr<ByteBuffer>
    if (result.is_error() && result.error().code() != EINTR)
        continue;
    auto bytes = TRY(result);

The TRY invocation will currently copy the byte buffer when the
expression (in this case, just a local variable) is stored into
_temporary_result.

This patch binds the expression to a reference to prevent such copies.
In less trival invocations (such as TRY(some_function()), this will
incur only temporary lifetime extensions, i.e. no functional change.
2023-02-10 09:08:52 +00:00
Timothy Flynn 4a916cd379 Everywhere: Remove needless copies of Error / ErrorOr instances
Either take the underlying objects with release_* methods or move() the
instances around.
2023-02-10 09:08:52 +00:00
Timothy Flynn 52687814ea Kernel: Explicitly copy Plan9FS read errors to registered delegates 2023-02-10 09:08:52 +00:00
Timothy Flynn bd4bddf31b Kernel: Store socket errors as errno codes rather than ErrorOr values 2023-02-10 09:08:52 +00:00
MacDue 63b11030f0 Everywhere: Use ReadonlySpan<T> instead of Span<T const> 2023-02-08 19:15:45 +00:00
Tim Schumacher 81863eaf57 Kernel: Use AK::Stream to write packed binary data 2023-02-08 18:50:31 +00:00
Tim Schumacher 23e10a30ad Kernel: Modernize Error handling when serializing directory entries 2023-02-08 18:50:31 +00:00
Itamar ddec9cb1f0 Kernel: Update stored registers in a thread's tracer on SIGSTOP
This is needed so we can retrieve the registers of a traced
thread that was attached to while it was running.

Attaching with ptrace to a running thread sends SIGSTOP to it.
2023-02-08 19:23:07 +01:00
Itamar 7544b35694 Kernel: Update registers in tracer when attaching to a stopped thread 2023-02-08 19:23:07 +01:00
Timon Kruiper 0f3e1668bb Kernel/aarch64: Execute first userspace process
This adds the necessary code to init.cpp to be able to execute the first
userspace process. To do this, first the filesystem code is initialized,
which will use the ramdisk embedded into the kernel image. Then the
first userspace process, /bin/SystemServer is executed. :^)

The ramdisk code is used as it is useful for the bring-up of the aarch64
port, however once the kernel has support for better ram-based
filesystems, the ramdisk code will be removed again.
2023-02-08 18:19:48 +00:00