The Pedigree Project 0.1
modules/drivers/common/virtio-input/main.cc
1/* Copyright (c) 2026, Pedigree Developers. SPDX-License-Identifier: ISC */
2#include "pedigree/kernel/machine/Device.h"
3#include "pedigree/kernel/utilities/List.h"
4#include "pedigree/kernel/utilities/new"
5
6#include "VirtioInput.h"
7#include "modules/Module.h"
8
9namespace {
10List<Device*> candidates;
12
13void collect(Device* pci) {
14 for (size_t i = 0; i < pci->getNumChildren(); ++i) {
15 if (pci->getChild(i)->getSpecificType() == String("virtio-input-device")) {
16 return;
17 }
18 }
19 candidates.pushBack(pci);
20}
21
22bool entry() {
23 Device::searchByVendorIdAndDeviceId(0x1af4, 0x1052, collect);
24 while (candidates.count()) {
25 Device* pci = candidates.popFront();
26 auto* device = new VirtioInputDevice(pci);
27 if (!device->initialise()) {
28 delete device;
29 continue;
30 }
31 {
33 device->setParent(pci);
34 pci->addChild(device);
35 }
36 devices.pushBack(device);
37 }
38 return devices.count() != 0;
39}
40
41void exit() {
42 while (devices.count()) {
43 auto* device = devices.popFront();
44 {
46 device->getParent()->removeChild(device);
47 device->setParent(nullptr);
48 }
49 delete device;
50 }
51}
52} // namespace
53
54MODULE_INFO("virtio-input", &entry, &exit, "pci", "virtio-pci");
size_t getNumChildren()
Definition Device.cc:143
Device * getChild(size_t n)
Definition Device.cc:139
void addChild(Device *pDevice)
Definition Device.cc:135
virtual const String & getSpecificType()
Definition Device.h:183
Definition List.h:61
T popFront()
Definition List.h:330
size_t count() const
Definition List.h:212
void pushBack(const T &value)
Definition List.h:216