The Pedigree Project 0.1
modules/drivers/common/virtio-gpu/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 "VirtioGpu.h"
7#include "modules/Module.h"
8
9namespace {
10List<Device*> candidates;
11List<VirtioGpu*> displays;
12
13void collect(Device* pci) {
14 for (size_t i = 0; i < pci->getNumChildren(); ++i) {
15 if (pci->getChild(i)->getSpecificType() == String("virtio-gpu-display")) {
16 return;
17 }
18 }
19 candidates.pushBack(pci);
20}
21
22bool entry() {
23 Device::searchByVendorIdAndDeviceId(0x1af4, 0x1050, collect);
24 while (candidates.count()) {
25 Device* pci = candidates.popFront();
26 auto* display = new VirtioGpu(pci);
27 if (!display) {
28 continue;
29 }
30 if (!display->initialise()) {
31 delete display;
32 continue;
33 }
34 {
36 display->setParent(pci);
37 pci->addChild(display);
38 }
39 displays.pushBack(display);
40 }
41 return displays.count() != 0;
42}
43
44void exit() {
45 while (displays.count()) {
46 auto* display = displays.popFront();
47 display->shutdown();
48 {
50 display->getParent()->removeChild(display);
51 display->setParent(nullptr);
52 }
53 delete display;
54 }
55}
56} // namespace
57
58MODULE_INFO("virtio-gpu", &entry, &exit, "pci", "virtio-pci");
size_t getNumChildren()
Definition Device.cc:131
Device * getChild(size_t n)
Definition Device.cc:127
void addChild(Device *pDevice)
Definition Device.cc:123
virtual const String & getSpecificType()
Definition Device.h:178
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