|
|
1.1 root 1: //
2: // nono
3: // Copyright (C) 2024 nono project
4: // Licensed under nono-license.txt
5: //
6:
7: //
8: // VirtIO エントロピーデバイス
9: //
10:
11: #include "virtio_entropy.h"
12: #include "virtio_def.h"
1.1.1.2 root 13: #include "monitor.h"
1.1 root 14:
15: // コンストラクタ
16: VirtIOEntropyDevice::VirtIOEntropyDevice(uint slot_)
17: : inherited(OBJ_VIRTIO_ENTROPY, slot_)
18: {
1.1.1.4 ! root 19: // 割り込み名(とログ名)
! 20: strlcpy(intrname, "VIOEnt", sizeof(intrname));
! 21: SetName(intrname);
! 22: ClearAlias();
! 23: AddAlias(intrname);
1.1 root 24:
25: device_id = VirtIO::DEVICE_ID_ENTROPY;
26: int num_max = 4;
1.1.1.2 root 27: vqueues.emplace_back(this, 0, "RequestQ", num_max);
1.1 root 28:
29: // 完了通知メッセージ
30: msgid = MessageID::VIRTIO_ENTROPY_DONE;
31:
1.1.1.2 root 32: monitor = gMonitorManager->Regist(ID_MONITOR_VIRTIO_ENTROPY, this);
1.1.1.4 ! root 33: monitor->SetCallback(&VirtIOEntropyDevice::MonitorScreen);
1.1.1.2 root 34: monitor->SetSize(MONITOR_WIDTH, 2 + 4 * 1 + num_max + 3);
1.1 root 35: }
36:
37: // デストラクタ
38: VirtIOEntropyDevice::~VirtIOEntropyDevice()
39: {
40: }
41:
42: void
1.1.1.4 ! root 43: VirtIOEntropyDevice::MonitorScreen(Monitor *, TextScreen& screen)
1.1 root 44: {
45: int y = 0;
46:
47: screen.Clear();
48:
1.1.1.4 ! root 49: y = MonitorScreenDev(screen, y);
1.1 root 50: y++;
1.1.1.4 ! root 51: y = MonitorScreenVirtQueue(screen, y, vqueues[0]);
1.1 root 52: y++;
1.1.1.4 ! root 53: y = MonitorScreenVirtQDesc(screen, y, vqueues[0]);
1.1 root 54: }
55:
56: // ディスクリプタを一つ処理する。
57: void
58: VirtIOEntropyDevice::ProcessDesc(VirtIOReq& req)
59: {
1.1.1.3 root 60: std::vector<uint32> buf(roundup(req.wlen, 4));
1.1 root 61:
1.1.1.3 root 62: for (auto&& d : buf) {
63: d = rnd();
1.1 root 64: }
1.1.1.3 root 65: ReqWriteRegion(req, (const uint8 *)buf.data(), req.wlen);
1.1 root 66: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.