summaryrefslogtreecommitdiff
path: root/Kernel/Bus/VirtIO/RNG.h
blob: a77b284a395025c225079db9a305338013c027e5 (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::DeviceIdentifier const&);
    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::DeviceIdentifier const&);
    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;
};

}