1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-20 03:05:07 +00:00
serenity/Kernel/Bus/VirtIO/RNG.h
Liav A 87a32ab869 Kernel/VirtIO: Improve error handling during device initialization
Rename the initialize method to initialize_virtio_resources so it's
clear what this method is intended for.

To ensure healthier device initialization, we could also return the type
of ErrorOr<void> from this method, so in all overriden instances and in
the original method code, we could leverage TRY() pattern which also
does simplify the code a bit.
2023-04-30 06:03:47 +02:00

40 lines
1.1 KiB
C++

/*
* Copyright (c) 2021, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/AtomicRefCounted.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 AtomicRefCounted<RNG>
, public VirtIO::Device {
public:
static NonnullLockRefPtr<RNG> must_create(PCI::DeviceIdentifier const&);
virtual StringView purpose() const override { return class_name(); }
virtual StringView device_name() const override { return class_name(); }
virtual ~RNG() override = default;
virtual ErrorOr<void> initialize_virtio_resources() override;
private:
virtual StringView class_name() const override { return "VirtIORNG"sv; }
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;
};
}