summaryrefslogtreecommitdiff
path: root/Kernel/VirtIO/VirtIORNG.h
blob: 8a4cd931488ebf996a390347c924eae1e776a3bb (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
/*
 * Copyright (c) 2021, the SerenityOS developers.
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <Kernel/Devices/CharacterDevice.h>
#include <Kernel/Random.h>
#include <Kernel/VirtIO/VirtIO.h>

namespace Kernel {

#define REQUESTQ 0

class VirtIORNG final : public CharacterDevice
    , public VirtIODevice {
public:
    virtual StringView purpose() const override { return class_name(); }
    virtual StringView class_name() const override { return m_class_name; }

    virtual bool can_read(const FileDescription&, size_t) const override { return false; }
    virtual KResultOr<size_t> read(FileDescription&, u64, UserOrKernelBuffer&, size_t) override { return 0; }
    virtual bool can_write(const FileDescription&, size_t) const override { return false; }
    virtual KResultOr<size_t> write(FileDescription&, u64, const UserOrKernelBuffer&, size_t) override { return 0; }

    virtual mode_t required_mode() const override { return 0666; }
    virtual String device_name() const override { return "hwrng"; }

    VirtIORNG(PCI::Address);
    virtual ~VirtIORNG() override;

private:
    virtual bool handle_device_config_change() override;
    virtual void handle_queue_update(u16 queue_index) override;
    void request_entropy_from_host();

    OwnPtr<Memory::Region> m_entropy_buffer;
    EntropySource m_entropy_source;
};

}