2020-01-18 11:38:21 +03:00
|
|
|
/*
|
2021-03-05 15:23:08 +03:00
|
|
|
* Copyright (c) 2021, Liav A. <liavalb@hotmail.co.il>
|
2020-01-18 11:38:21 +03:00
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 11:38:21 +03:00
|
|
|
*/
|
|
|
|
|
2019-08-18 07:54:52 +03:00
|
|
|
#pragma once
|
|
|
|
|
2021-04-16 22:58:51 +03:00
|
|
|
#include <AK/NonnullOwnPtr.h>
|
2019-09-06 16:34:26 +03:00
|
|
|
#include <AK/String.h>
|
2019-08-18 07:54:52 +03:00
|
|
|
#include <AK/Types.h>
|
|
|
|
#include <Kernel/Devices/BlockDevice.h>
|
2021-03-05 15:23:08 +03:00
|
|
|
#include <Kernel/Graphics/GraphicsDevice.h>
|
2021-08-22 02:37:17 +03:00
|
|
|
#include <Kernel/Locking/Spinlock.h>
|
2021-08-06 11:45:34 +03:00
|
|
|
#include <Kernel/Memory/AnonymousVMObject.h>
|
2020-05-16 13:00:04 +03:00
|
|
|
#include <Kernel/PhysicalAddress.h>
|
2019-08-18 07:54:52 +03:00
|
|
|
|
2020-02-16 03:27:42 +03:00
|
|
|
namespace Kernel {
|
|
|
|
|
2021-03-05 15:23:08 +03:00
|
|
|
class FramebufferDevice : public BlockDevice {
|
2019-08-18 07:54:52 +03:00
|
|
|
AK_MAKE_ETERNAL
|
2021-09-11 09:19:20 +03:00
|
|
|
friend class DeviceManagement;
|
|
|
|
|
2019-08-18 07:54:52 +03:00
|
|
|
public:
|
2021-05-22 09:51:55 +03:00
|
|
|
static NonnullRefPtr<FramebufferDevice> create(const GraphicsDevice&, size_t, PhysicalAddress, size_t, size_t, size_t);
|
|
|
|
|
2021-09-07 14:39:11 +03:00
|
|
|
virtual KResult ioctl(OpenFileDescription&, unsigned request, Userspace<void*> arg) override;
|
|
|
|
virtual KResultOr<Memory::Region*> mmap(Process&, OpenFileDescription&, Memory::VirtualRange const&, u64 offset, int prot, bool shared) override;
|
2019-08-18 07:54:52 +03:00
|
|
|
|
2021-05-21 06:53:31 +03:00
|
|
|
virtual void deactivate_writes();
|
2021-04-16 22:58:51 +03:00
|
|
|
virtual void activate_writes();
|
2021-05-22 09:51:55 +03:00
|
|
|
size_t framebuffer_size_in_bytes() const;
|
2021-03-05 15:23:08 +03:00
|
|
|
|
|
|
|
virtual ~FramebufferDevice() {};
|
2021-08-15 12:07:59 +03:00
|
|
|
KResult initialize();
|
2021-03-05 15:23:08 +03:00
|
|
|
|
2021-09-11 09:19:20 +03:00
|
|
|
private:
|
2021-09-10 14:44:46 +03:00
|
|
|
FramebufferDevice(const GraphicsDevice&, size_t, PhysicalAddress, size_t, size_t, size_t);
|
|
|
|
|
2021-05-22 09:51:55 +03:00
|
|
|
// ^File
|
2021-10-03 01:24:00 +03:00
|
|
|
virtual StringView class_name() const override { return "FramebufferDevice"sv; }
|
2021-03-05 15:23:08 +03:00
|
|
|
|
2021-09-07 14:39:11 +03:00
|
|
|
virtual bool can_read(const OpenFileDescription&, size_t) const override final { return true; }
|
|
|
|
virtual bool can_write(const OpenFileDescription&, size_t) const override final { return true; }
|
2021-03-05 15:23:08 +03:00
|
|
|
virtual void start_request(AsyncBlockDeviceRequest& request) override final { request.complete(AsyncDeviceRequest::Failure); }
|
2021-09-07 14:39:11 +03:00
|
|
|
virtual KResultOr<size_t> read(OpenFileDescription&, u64, UserOrKernelBuffer&, size_t) override { return EINVAL; }
|
|
|
|
virtual KResultOr<size_t> write(OpenFileDescription&, u64, const UserOrKernelBuffer&, size_t) override { return EINVAL; }
|
2019-08-18 07:54:52 +03:00
|
|
|
|
|
|
|
PhysicalAddress m_framebuffer_address;
|
2020-04-29 10:35:19 +03:00
|
|
|
size_t m_framebuffer_pitch { 0 };
|
|
|
|
size_t m_framebuffer_width { 0 };
|
|
|
|
size_t m_framebuffer_height { 0 };
|
2021-04-16 22:58:51 +03:00
|
|
|
|
2021-09-05 20:02:03 +03:00
|
|
|
Spinlock m_activation_lock;
|
2021-04-16 22:58:51 +03:00
|
|
|
|
2021-08-06 14:49:36 +03:00
|
|
|
RefPtr<Memory::AnonymousVMObject> m_real_framebuffer_vmobject;
|
|
|
|
RefPtr<Memory::AnonymousVMObject> m_swapped_framebuffer_vmobject;
|
|
|
|
OwnPtr<Memory::Region> m_real_framebuffer_region;
|
|
|
|
OwnPtr<Memory::Region> m_swapped_framebuffer_region;
|
2021-04-16 22:58:51 +03:00
|
|
|
|
2021-05-20 21:28:18 +03:00
|
|
|
bool m_graphical_writes_enabled { true };
|
|
|
|
|
2021-08-06 14:49:36 +03:00
|
|
|
RefPtr<Memory::AnonymousVMObject> m_userspace_real_framebuffer_vmobject;
|
|
|
|
Memory::Region* m_userspace_framebuffer_region { nullptr };
|
2021-05-22 09:51:55 +03:00
|
|
|
|
|
|
|
size_t m_y_offset { 0 };
|
|
|
|
size_t m_output_port_index;
|
|
|
|
NonnullRefPtr<GraphicsDevice> m_graphics_adapter;
|
2019-08-18 07:54:52 +03:00
|
|
|
};
|
2020-02-16 03:27:42 +03:00
|
|
|
|
|
|
|
}
|