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
|
|
|
*/
|
|
|
|
|
|
2021-03-05 14:23:08 +02:00
|
|
|
#include <AK/Checked.h>
|
|
|
|
|
#include <AK/Singleton.h>
|
|
|
|
|
#include <Kernel/Debug.h>
|
|
|
|
|
#include <Kernel/Graphics/FramebufferDevice.h>
|
|
|
|
|
#include <Kernel/Graphics/GraphicsManagement.h>
|
2019-08-18 14:54:52 +10:00
|
|
|
#include <Kernel/Process.h>
|
|
|
|
|
#include <Kernel/VM/AnonymousVMObject.h>
|
|
|
|
|
#include <Kernel/VM/MemoryManager.h>
|
2021-03-05 14:23:08 +02:00
|
|
|
#include <Kernel/VM/TypedMapping.h>
|
2019-08-18 14:54:52 +10:00
|
|
|
#include <LibC/errno_numbers.h>
|
|
|
|
|
#include <LibC/sys/ioctl_numbers.h>
|
|
|
|
|
|
2020-02-16 01:27:42 +01:00
|
|
|
namespace Kernel {
|
|
|
|
|
|
2021-03-05 14:23:08 +02:00
|
|
|
KResultOr<Region*> FramebufferDevice::mmap(Process& process, FileDescription&, const Range& range, u64 offset, int prot, bool shared)
|
2019-08-18 14:54:52 +10:00
|
|
|
{
|
2020-01-12 02:17:30 +01:00
|
|
|
REQUIRE_PROMISE(video);
|
2020-02-28 20:47:27 +01:00
|
|
|
if (!shared)
|
2021-01-20 23:11:17 +01:00
|
|
|
return ENODEV;
|
2021-01-27 21:23:20 -07:00
|
|
|
if (offset != 0)
|
|
|
|
|
return ENXIO;
|
2021-02-14 09:57:19 +01:00
|
|
|
if (range.size() != page_round_up(framebuffer_size_in_bytes()))
|
2021-01-27 21:23:20 -07:00
|
|
|
return EOVERFLOW;
|
|
|
|
|
|
2019-12-19 19:13:44 +01:00
|
|
|
auto vmobject = AnonymousVMObject::create_for_physical_range(m_framebuffer_address, framebuffer_size_in_bytes());
|
2020-01-28 20:48:07 +01:00
|
|
|
if (!vmobject)
|
2021-01-20 23:11:17 +01:00
|
|
|
return ENOMEM;
|
2021-02-08 15:45:40 +01:00
|
|
|
return process.space().allocate_region_with_vmobject(
|
2021-01-25 14:52:36 +01:00
|
|
|
range,
|
2020-01-28 20:48:07 +01:00
|
|
|
vmobject.release_nonnull(),
|
2019-08-18 14:54:52 +10:00
|
|
|
0,
|
2021-03-05 14:23:08 +02:00
|
|
|
"Framebuffer",
|
2021-01-02 16:38:05 +01:00
|
|
|
prot,
|
|
|
|
|
shared);
|
2019-08-18 14:54:52 +10:00
|
|
|
}
|
|
|
|
|
|
2021-03-05 14:23:08 +02:00
|
|
|
String FramebufferDevice::device_name() const
|
|
|
|
|
{
|
|
|
|
|
return String::formatted("fb{}", minor());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UNMAP_AFTER_INIT FramebufferDevice::FramebufferDevice(PhysicalAddress addr, size_t pitch, size_t width, size_t height)
|
|
|
|
|
: BlockDevice(29, GraphicsManagement::the().current_minor_number())
|
|
|
|
|
, m_framebuffer_address(addr)
|
|
|
|
|
, m_framebuffer_pitch(pitch)
|
|
|
|
|
, m_framebuffer_width(width)
|
|
|
|
|
, m_framebuffer_height(height)
|
|
|
|
|
{
|
|
|
|
|
dbgln("Framebuffer {}: address={}, pitch={}, width={}, height={}", minor(), addr, pitch, width, height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FramebufferDevice::set_resolution(size_t, size_t, size_t)
|
|
|
|
|
{
|
|
|
|
|
VERIFY_NOT_REACHED();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int FramebufferDevice::ioctl(FileDescription&, unsigned request, FlatPtr arg)
|
2019-08-18 14:54:52 +10:00
|
|
|
{
|
2020-01-12 02:17:30 +01:00
|
|
|
REQUIRE_PROMISE(video);
|
2019-08-18 14:54:52 +10:00
|
|
|
switch (request) {
|
|
|
|
|
case FB_IOCTL_GET_SIZE_IN_BYTES: {
|
|
|
|
|
auto* out = (size_t*)arg;
|
2020-07-31 00:17:25 +02:00
|
|
|
size_t value = framebuffer_size_in_bytes();
|
2020-09-11 21:11:07 -06:00
|
|
|
if (!copy_to_user(out, &value))
|
|
|
|
|
return -EFAULT;
|
2019-08-18 14:54:52 +10:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
case FB_IOCTL_GET_BUFFER: {
|
2021-03-05 14:23:08 +02:00
|
|
|
return -ENOTIMPL;
|
2019-08-18 14:54:52 +10:00
|
|
|
}
|
|
|
|
|
case FB_IOCTL_GET_RESOLUTION: {
|
2020-07-31 00:17:25 +02:00
|
|
|
auto* user_resolution = (FBResolution*)arg;
|
|
|
|
|
FBResolution resolution;
|
|
|
|
|
resolution.pitch = m_framebuffer_pitch;
|
|
|
|
|
resolution.width = m_framebuffer_width;
|
|
|
|
|
resolution.height = m_framebuffer_height;
|
2020-09-11 21:11:07 -06:00
|
|
|
if (!copy_to_user(user_resolution, &resolution))
|
|
|
|
|
return -EFAULT;
|
2019-08-18 14:54:52 +10:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
case FB_IOCTL_SET_RESOLUTION: {
|
2020-07-31 00:17:25 +02:00
|
|
|
auto* user_resolution = (FBResolution*)arg;
|
|
|
|
|
FBResolution resolution;
|
|
|
|
|
resolution.pitch = m_framebuffer_pitch;
|
|
|
|
|
resolution.width = m_framebuffer_width;
|
|
|
|
|
resolution.height = m_framebuffer_height;
|
2020-09-11 21:11:07 -06:00
|
|
|
if (!copy_to_user(user_resolution, &resolution))
|
|
|
|
|
return -EFAULT;
|
2019-08-18 14:54:52 +10:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
};
|
|
|
|
|
}
|
2020-02-16 01:27:42 +01:00
|
|
|
|
|
|
|
|
}
|