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

#pragma once

#include <AK/RefCounted.h>
#include <Kernel/Bus/VirtIO/Device.h>
#include <Kernel/Devices/CharacterDevice.h>
#include <Kernel/Random.h>

namespace Kernel::VirtIO {

#define REQUESTQ 0

class RNG final
    : public RefCounted<RNG>
    , public VirtIO::Device {
public:
    static NonnullRefPtr<RNG> must_create(PCI::Address address);
    virtual StringView purpose() const override { return class_name(); }
    virtual ~RNG() override = default;

    virtual void initialize() override;

private:
    virtual StringView class_name() const override { return "VirtIOConsole"; }
    explicit RNG(PCI::Address);
    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;
};

}