2020-01-18 09:38:21 +01:00
|
|
|
/*
|
2021-03-05 14:23:08 +02:00
|
|
|
* Copyright (c) 2021, Liav A. <liavalb@hotmail.co.il>
|
2020-01-18 09:38:21 +01:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
2019-08-18 14:54:52 +10:00
|
|
|
#pragma once
|
|
|
|
|
2021-04-16 22:58:51 +03:00
|
|
|
#include <AK/NonnullOwnPtr.h>
|
2019-09-06 15:34:26 +02:00
|
|
|
#include <AK/String.h>
|
2019-08-18 14:54:52 +10:00
|
|
|
#include <AK/Types.h>
|
|
|
|
#include <Kernel/Devices/BlockDevice.h>
|
2021-03-05 14:23:08 +02:00
|
|
|
#include <Kernel/Graphics/GraphicsDevice.h>
|
2020-05-16 12:00:04 +02:00
|
|
|
#include <Kernel/PhysicalAddress.h>
|
2021-04-16 22:58:51 +03:00
|
|
|
#include <Kernel/SpinLock.h>
|
|
|
|
#include <Kernel/VM/AnonymousVMObject.h>
|
2019-08-18 14:54:52 +10:00
|
|
|
|
2020-02-16 01:27:42 +01:00
|
|
|
namespace Kernel {
|
|
|
|
|
2021-03-05 14:23:08 +02:00
|
|
|
class FramebufferDevice : public BlockDevice {
|
2019-08-18 14:54:52 +10:00
|
|
|
AK_MAKE_ETERNAL
|
|
|
|
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-07-26 02:47:00 -07:00
|
|
|
virtual int ioctl(FileDescription&, unsigned request, Userspace<void*> arg) override;
|
2021-03-18 22:57:25 +01:00
|
|
|
virtual KResultOr<Region*> mmap(Process&, FileDescription&, const Range&, u64 offset, int prot, bool shared) override;
|
2019-08-18 14:54:52 +10:00
|
|
|
|
2020-12-25 19:01:19 +02:00
|
|
|
// ^Device
|
|
|
|
virtual mode_t required_mode() const override { return 0660; }
|
2021-01-21 18:49:56 +01:00
|
|
|
virtual String device_name() const override;
|
2020-12-25 19:01:19 +02: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 14:23:08 +02:00
|
|
|
|
|
|
|
virtual ~FramebufferDevice() {};
|
2021-04-16 22:58:51 +03:00
|
|
|
void initialize();
|
2021-03-05 14:23:08 +02:00
|
|
|
|
2021-05-22 09:51:55 +03:00
|
|
|
private:
|
|
|
|
// ^File
|
2021-07-11 01:46:09 +02:00
|
|
|
virtual StringView class_name() const override { return "FramebufferDevice"; }
|
2021-03-05 14:23:08 +02:00
|
|
|
|
|
|
|
virtual bool can_read(const FileDescription&, size_t) const override final { return true; }
|
|
|
|
virtual bool can_write(const FileDescription&, size_t) const override final { return true; }
|
|
|
|
virtual void start_request(AsyncBlockDeviceRequest& request) override final { request.complete(AsyncDeviceRequest::Failure); }
|
2021-03-17 13:18:51 +01:00
|
|
|
virtual KResultOr<size_t> read(FileDescription&, u64, UserOrKernelBuffer&, size_t) override { return -EINVAL; }
|
|
|
|
virtual KResultOr<size_t> write(FileDescription&, u64, const UserOrKernelBuffer&, size_t) override { return -EINVAL; }
|
2019-08-18 14:54:52 +10:00
|
|
|
|
2021-05-22 09:51:55 +03:00
|
|
|
FramebufferDevice(const GraphicsDevice&, size_t, PhysicalAddress, size_t, size_t, size_t);
|
|
|
|
|
2019-08-18 14:54:52 +10:00
|
|
|
PhysicalAddress m_framebuffer_address;
|
2020-04-29 09:35:19 +02: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
|
|
|
|
|
|
|
SpinLock<u8> m_activation_lock;
|
|
|
|
|
|
|
|
RefPtr<AnonymousVMObject> m_real_framebuffer_vmobject;
|
|
|
|
RefPtr<AnonymousVMObject> m_swapped_framebuffer_vmobject;
|
|
|
|
OwnPtr<Region> m_real_framebuffer_region;
|
|
|
|
OwnPtr<Region> m_swapped_framebuffer_region;
|
|
|
|
|
2021-05-20 21:28:18 +03:00
|
|
|
bool m_graphical_writes_enabled { true };
|
|
|
|
|
2021-04-16 22:58:51 +03:00
|
|
|
RefPtr<AnonymousVMObject> m_userspace_real_framebuffer_vmobject;
|
|
|
|
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 14:54:52 +10:00
|
|
|
};
|
2020-02-16 01:27:42 +01:00
|
|
|
|
|
|
|
}
|