Commit graph

220 commits

Author SHA1 Message Date
Andreas Kling 11eee67b85 Kernel: Make self-contained locking smart pointers their own classes
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-20 17:20:43 +02:00
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
kleines Filmröllchen 4314c25cf2 Kernel: Require lock rank for Spinlock construction
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-08-19 20:26:47 -07:00
Filiph Sandström 99ae4fa161 Kernel: Move TrapFrame into its own header on aarch64 2022-08-14 09:44:48 +01:00
Liav A 60f7d61ad2 Kernel/SysFS: Fix parent directory hierarchy with symbolic links
We should actually start counting from the parent directory and not from
the symbolic link as it will represent a wrong count of hops from the
actual mountpoint.

The symlinks in /sys/dev/block and /sys/dev/char worked only by luck,
because I have set it to the wrong parent directory which is the
/sys/dev directory, so with the symlink it was 3 hops to /sys, together
with the root directory, therefore, everything seemed to work.

Now that the device symlinks in /sys/dev/block and /sys/dev/char are set
to the right parent directory and we start measure hops from root
directory with the parent directory of a symlink, everything seem to
work correctly now.
2022-07-24 13:38:24 +01:00
Liav A 977aa81310 Kernel+Userland: Add ioctl to set process ownership of DisplayConnector
Now that the infrastructure of the Graphics subsystem is quite stable,
it is time to try to fix a long-standing problem, which is the lack of
locking on display connector devices. Reading and writing from multiple
processes to a framebuffer controlled by the display connector is not a
huge problem - it could be solved with POSIX locking.

The real problem is some program that will try to do ioctl operations on
a display connector without the WindowServer being aware of that which
can lead to very bad situations, for example - assuming a framebuffer is
encoded at a known resolution and certain display timings, but another
process changed the ModeSetting of the display connector, leading to
inconsistency on the properties of the current ModeSetting.

To solve this, there's a new "master" ioctl to take "ownership" and
another one to release that ownership of a display connector device. To
ensure we will not hold a Process object forever just because it has an
ownership over a display connector, we hold it with a weak reference,
and if the process is gone, someone else can take an ownership.
2022-07-23 10:42:08 +01:00
Liav A b7d0b5d745 Kernel/Graphics: Remove out-of-context comment note 2022-07-23 10:42:08 +01:00
Linus Groh 8150d71821 Everywhere: Prefix 'TYPEDEF_DISTINCT_ORDERED_ID' with 'AK_' 2022-07-22 23:09:43 +01:00
Liav A 412a5999d0 Kernel+Userland: Remove GRAPHICS_IOCTL_GET_HEAD_EDID ioctl
We are able to read the EDID from SysFS, therefore there's no need to
provide this ioctl on a DisplayConnector anymore.
Also, now we can simply require the video pledge to be set before doing
any ioctl on a DisplayConnector.
2022-07-19 11:02:37 +01:00
Liav A 3af70cb0fc Kernel/Devices: Abstract SysFS Device add/remove methods more properly
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-19 11:02:37 +01:00
Liav A da8d18b263 Kernel/SysFS: Add exposing interface for DisplayConnectors
Under normal conditions (when mounting SysFS in /sys), there will be a
new directory in the /sys/devices directory called "graphics".
For now, under that directory there will be only a sub-directory called
"connectors" which will contain all DisplayConnectors' details, each in
its own sub-directory too, distinguished in naming with its minor
number.

Therefore, /sys/devices/graphics/connectors/MINOR_NUMBER/ will contain:
- General device attributes such as mutable_mode_setting_capable,
  double_buffering_capable, flush_support, partial_flush_support and
  refresh_rate_support. These values are exposed in the ioctl interface
  of the DisplayConnector class too, but these can be useful later on
  for command line utilities that want/need to expose these basic
  settings.
- The EDID blob, simply named "edid". This will help userspace to fetch
  the edid without the need of using the ioctl interface later on.
2022-07-19 11:02:37 +01:00
Liav A ebbc38cd2a Kernel/Graphics: Remove GenericGraphicsAdapter::vga_compatible method
There's no point in keeping this method as we don't really care if a
graphics adapter is VGA compatible or not because we don't use this
method anymore.
2022-07-15 12:23:22 +02:00
Liav A cd8bcd06c6 Kernel/Graphics: Allocate VGA window region according to the usual rules
We should not allocate a kernel region inside the constructor of the
VGATextModeConsole class. We do use MUST() because allocation cannot
fail at this point, but that happens in the static factory method
instead.
2022-07-13 19:15:17 +01:00
Liav A f052b9574c Kernel/Graphics: Rename m_vga_region => m_vga_window_region 2022-07-13 19:15:17 +01:00
Liav A 00dbd667d5 Kernel/Graphics: Rename TextModeConsole => VGATextModeConsole
This change represents well the fact that the text mode console is based
on VGA text mode.
2022-07-13 19:15:17 +01:00
Liav A 97a769d2a9 Kernel/Graphics: Remove unnecessary VGAConsole class abstraction
The original intention was to support other types of consoles based on
standard VGA modes, but it never came to an implementation, nor we need
such feature at all.
Therefore, this class is not needed and can be removed.
2022-07-13 19:15:17 +01: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
Liav A 4771917184 Kernel/Graphics: Simplify initialization flow explanation comment
Most of it was not relevant anymore to what we do in the initialization
method anyway, and now it represents it quite well and "to the point".
2022-07-12 19:54:48 +01:00
Liav A 5824f30752 Kernel/Graphics: Fix comparison of framebuffer type in initialization 2022-07-12 19:54:48 +01:00
Liav A 3bd0106755 Kernel/Graphics: Remove VGA folder and its content
We never supported VGA framebuffers and that folder was a big misleading
part of the graphics subsystem.

We do support bare-bones VGA text console (80x25), but that only happens
to be supported because we can't be 100% sure we can always initialize
framebuffer so in the worst scenario we default to plain old VGA console
so the user can still use its own machine.

Therefore, the only remaining parts of VGA is in the GraphicsManagement
code to help driving the VGA text console if needed.
2022-07-12 19:54:48 +01:00
Liav A cd115270fc Kernel/Graphics: Move GenericDisplayConnector code to a new sub-folder
In the same fashion like in the Linux kernel, we support pre-initialized
framebuffers that were set up by either the BIOS or the bootloader.
These framebuffers can be backed by any kind of video hardware, and are
not tied to VGA hardware at all. Therefore, this code should be in a
separate sub-folder in the Graphics subsystem to indicate this.
2022-06-25 11:32:09 +01:00
MacDue 1dcdcc7efb Kernel/Console: Fix gaps between background glyph color 2022-06-11 12:19:29 +01:00
Liav A 20c9e4c05c Kernel/Graphics: Ensure VMWare and VirtualBox EDIDs have manufacturer ID 2022-06-10 22:32:54 +01:00
Liav A 3d36b194d1 Kernel/Graphics: Ensure generic EDID always has correct checksum 2022-06-10 22:32:54 +01:00
Liav A 938d579d16 Kernel/Graphics: Re-organize the DisplayConnector class a bit
Move methods that are overriding the virtual methods in the File class,
to a private access scope in the DisplayConnector class because nobody
tries to access them in any derived class of this class.
2022-06-10 22:32:54 +01:00
MacDue 348750a9f4 Kernel/Console: Tidy up code a little
- Remove some magic numbers
- Remove some duplicate branches
- Reduce the amount of casting between u8* and u32*
- Some renaming of confusing variables
2022-06-09 22:06:46 +02:00
MacDue 805a3d5b29 Kernel/Console: Factor out framebuffer offset and support glyph_spacing
This allows the 9px width of Cathode to be preserved without increasing
the bitmap size.
2022-06-09 22:06:46 +02:00
MacDue adef79b793 Kernel/Console: Replace QEMU bitmap font with Cathode
This has very similar look, but was invented here :^)
2022-06-09 22:06:46 +02:00
Liav A b4e409f721 Kernel/Graphics: Drop support for the DisplayConnector write interface
The WindowServer doesn't use this interface anymore and therefore it's
not used by any userspace application, so let's remove this stale method
to ensure we don't have to bother with it anymore.
2022-06-06 20:11:05 +01:00
Liav A e2ed6ef741 Kernel/Graphics: Bring back the mmap interface for DisplayConnectors
The mmap interface was removed when we introduced the DisplayConnector
class, as it was quite unsafe to use and didn't handle switching between
graphical and text modes safely. By using the SharedFramebufferVMObject,
we are able to elegantly coordinate the switch by remapping the attached
mmap'ed-Memory::Region(s) with different mappings, therefore, keeping
WindowServer to think that the mappings it has are still valid, while
they are going to a different physical range until we are back to the
graphical mode (after a switch from text mode).

Most drivers take advantage of the fact that we know where is the actual
framebuffer in physical memory space, the SharedFramebufferVMObject is
created with that information. However, the VirtIO driver is different
in that aspect, because it relies on DMA transactions to show graphics
on the framebuffer, so the SharedFramebufferVMObject is created with
that mindset to support the arbitrary framebuffer location in physical
memory space.
2022-06-06 20:11:05 +01:00
Liav A d84d81fc4e Kernel/Graphics: Flush the entire buffer if using VirtIO console
Keeping the exact details of a dirty rectangle doesn't make any sense
when we just flush the entire screen, so just keep a simple boolean
value to know if the screen needs to be flushed or not.
2022-06-06 20:11:05 +01:00
Liav A 9bec9c2b78 Kernel: Force y offset 0 when switching between console & graphics modes
This fixes a weird bug that when sometimes a user tried to switch to
console mode, the screen was frozen on graphics mode. After a hour of
debugging this, it became apparent that the problem was that we left the
y offset of the bochs graphics device in an invalid state, so it was not
zero because the WindowServer changed it, and the framebuffer console
code is not aware of horizontal and vertical offsets of the framebuffer
screen, leading to the problem that the framebuffer console updates the
first framebuffer (y offset = 0), but hardware was indicated to show the
second framebuffer (y offset = first framebuffer height).

Therefore, when doing a switch between these modes, always set the y
offset to be zero.
2022-05-06 18:05:14 +02:00
Liav A b8493bf70f Kernel/Graphics: Protect the list of display connectors with a Spinlock
This list could be updated in runtime if an hotplug event occurs, so we
must protect it with a spin lock to avoid corruption of the list.
2022-05-06 18:05:14 +02:00
Liav A 340773ddb7 Kernel/Graphics: Implement basic support for VMWare SVGA adapter 2022-05-06 18:04:57 +02:00
Liav A a0a1ac0656 Kernel/Graphics: Use boot console if the subsystem is disabled
This lets us actually to initialize VirtualConsoles later on.
2022-05-06 12:28:19 +02:00
Liav A 0d784de3a6 Kernel/Graphics: Implement basic cursor for FramebufferConsole 2022-05-06 12:28:02 +02:00
Liav A 969e5fa163 Kernel/Console: Use 8x16 character font bitmap instead of old 8x8 bitmap
This in turn makes the built-in kernel console much more nicer to look
into, so let's remove the support for 8x8 bitmap and instead add 8x16
font bitmap.
2022-05-05 21:51:57 +02:00
Liav A b96b2fb9be Kernel/Graphics: Simplify the GenericGraphicsAdapter class
The old methods are already can be considered deprecated, and now after
we removed framebuffer devices entirely, we can safely remove these
methods too, which simplfies the GenericGraphicsAdapter class a lot.
2022-05-05 20:55:57 +02:00
Liav A d49a35df31 Kernel/Graphics: Simplify the feature level of the Graphics subsystem
Instead of letting the user to determine whether framebuffer devices
will be created (which is useless because they are gone by now), let's
simplify the flow by allowing the user to choose between full, limited
or disabled functionality. The determination happens only once, so, if
the user decided to disable graphics support, the initialize method
exits immediately. If limited functionality is chosen, then a generic
DisplayConnector is initialized with the preset framebuffer resolution,
if present, and then the initialize method exits. As a default, the code
proceeds to initialize all drivers as usual.
2022-05-05 20:55:57 +02:00
Liav A e301af8352 Everywhere: Purge all support and usage of framebuffer devices
Long live the DisplayConnector object!
2022-05-05 20:55:57 +02:00
Liav A 10adc27eda Everywhere: Rename FB prefix structure names => Graphics 2022-05-05 20:55:57 +02:00
Liav A d2e93ec50a Everywhere: Rename FB prefix name ioctls => GRAPHICS 2022-05-05 20:55:57 +02:00
Liav A f15b93c9a1 Kernel/Graphics: Use DisplayConnector design with generic framebuffers 2022-05-05 20:55:57 +02:00
Liav A c27c414ed1 Kernel/Graphics: Apply DisplayConnector design on the VirtIO driver 2022-05-05 20:55:57 +02:00
Liav A 41283a2de6 Kernel/Graphics: Use VirtIO GPU3DDevice constructor indirectly
We shouldn't expose the VirtIO GPU3DDevice constructor as public method,
so instead, let's use the usual pattern of a static construction method
that uses the constructor within the method.
2022-05-05 20:55:57 +02:00
Liav A 728358c599 Kernel/Graphics: Migrate Intel driver to use the DisplayConnector design 2022-05-05 20:55:57 +02:00
Liav A e9a74cbefb Kernel/Graphics: Use DisplayConnector design for the Bochs driver 2022-05-05 20:55:57 +02:00
Liav A 9f0b5b04ff Kernel/Graphics: Export Bochs definitions to a header file
These definitions will be used later when applying the DisplayConnector
design on the Bochs driver.
2022-05-05 20:55:57 +02:00
Liav A 912b8ab965 Kernel/Graphics: Introduce the DisplayConnector class
The DisplayConnector class is meant to replace the FramebufferDevice
class. The advantage of this class over the FramebufferDevice class is:
1. It removes the mmap interface entirely. This interface is unsafe, as
multiple processes could try to use it, and when switching to and from
text console mode, there's no "good" way to revoke a memory mapping from
this interface, let alone when there are multiple processes that call
this interface. Therefore, in the DisplayConnector class there's no
implementation for this method at all.
2. The class uses a new real-world structure called ModeSetting, which
takes into account the fact that real hardware requires more than width,
height and pitch settings to mode-set the display resolution.
3. The class assumes all instances should supply some sort of EDID,
so it facilitates such mechanism to do so. Even if a given driver does
not know what is the actual EDID, it will ask to create default-generic
EDID blob.
3. This class shifts the responsibilies of switching between console
mode and graphical mode from a GraphicsAdapter to the DisplayConnector
class, so when doing the switch, the GraphicsManagement code actually
asks each DisplayConnector object to do the switch and doesn't rely on
the GraphicsAdapter objects at all.
2022-05-05 20:55:57 +02:00
Liav A ebf7225728 Kernel/Graphics: Declare BochsGraphicsAdapter::get_edid private method 2022-05-05 20:55:57 +02:00