summaryrefslogtreecommitdiff
path: root/Kernel/Graphics/VirtIOGPU/VirtIOFrameBufferDevice.h
blob: f918bdbc69dfedcdab51b7e43158cac5136d2ae0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
 * Copyright (c) 2021, Sahan Fernando <sahan.h.fernando@gmail.com>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <Kernel/Devices/BlockDevice.h>
#include <Kernel/Graphics/VirtIOGPU/VirtIOGPU.h>
#include <Kernel/VirtIO/VirtIO.h>
#include <Kernel/VirtIO/VirtIOQueue.h>

namespace Kernel::Graphics {

class VirtIOFrameBufferDevice final : public BlockDevice {
public:
    VirtIOFrameBufferDevice(RefPtr<VirtIOGPU> virtio_gpu);
    virtual ~VirtIOFrameBufferDevice() override;

    virtual void deactivate_writes();
    virtual void activate_writes();

private:
    virtual const char* class_name() const override { return "VirtIOFrameBuffer"; }

    virtual int ioctl(FileDescription&, unsigned request, FlatPtr arg) override;
    virtual KResultOr<Region*> mmap(Process&, FileDescription&, const Range&, u64 offset, int prot, bool shared) override;
    virtual bool can_read(const FileDescription&, size_t) const override { return true; }
    virtual KResultOr<size_t> read(FileDescription&, u64, UserOrKernelBuffer&, size_t) override { return EINVAL; }
    virtual bool can_write(const FileDescription&, size_t) const override { return true; }
    virtual KResultOr<size_t> write(FileDescription&, u64, const UserOrKernelBuffer&, size_t) override { return EINVAL; };
    virtual void start_request(AsyncBlockDeviceRequest& request) override { request.complete(AsyncDeviceRequest::Failure); }

    virtual mode_t required_mode() const override { return 0666; }
    virtual String device_name() const override { return String::formatted("fb{}", minor()); }

    RefPtr<VirtIOGPU> m_gpu;
    RefPtr<VMObject> m_framebuffer_sink_vmobject;
    bool m_are_writes_active { true };
    // FIXME: This needs to be cleaned up if the WindowServer exits while we are in a tty
    WeakPtr<Region> m_userspace_mmap_region;
};

}