The Pedigree Project 0.1
GicIts.h
1/* Copyright (c) 2026, Pedigree Developers. SPDX-License-Identifier: ISC */
2#ifndef KERNEL_MACHINE_VIRT_GICITS_H
3#define KERNEL_MACHINE_VIRT_GICITS_H
4
5#include "pedigree/kernel/Spinlock.h"
6#include "pedigree/kernel/processor/MemoryRegion.h"
7
8#include "DeviceTree.h"
9
10class GicIts {
11 public:
12 static constexpr uint32_t FirstLpi = 8192;
13 static constexpr size_t MaxMappings = 16;
14
15 GicIts();
16 bool initialise(const VirtMsiController& controller, uintptr_t redistributor,
17 uint64_t redistributorPhysical);
18 bool ready() const;
19 uint64_t messageAddress() const;
20 bool mapDevice(size_t slot, uint32_t deviceId, uint32_t lpi);
21 bool mapDeviceGroup(const size_t* slots, size_t count, uint32_t deviceId);
22 bool mappingActive(size_t slot) const;
23 bool unmapDevice(size_t slot);
24 bool setEnabled(uint32_t lpi, bool enabled);
25
26 private:
27 struct Mapping {
28 uint32_t deviceId;
29 uint32_t eventId;
30 uint64_t itt;
31 bool valid;
32 };
33
34 bool allocateAligned(MemoryRegion& region, size_t size, size_t alignment, uint64_t& physical,
35 uint8_t*& virtualAddress);
36 bool setupBaser(uint32_t type, MemoryRegion& region, size_t requiredEntries);
37 bool send(uint64_t word0, uint64_t word1, uint64_t word2);
38 bool sync();
39 void releaseTables();
40
41 MemoryRegion m_DeviceTable;
42 MemoryRegion m_CollectionTable;
43 MemoryRegion m_CommandQueue;
44 MemoryRegion m_Properties;
45 MemoryRegion m_Pending;
46 mutable Spinlock m_MappingLock;
47 Spinlock m_CommandLock;
48 Mapping m_Mappings[MaxMappings];
49 uintptr_t m_Base;
50 uintptr_t m_Redistributor;
51 uint64_t m_PhysicalBase;
52 uint64_t m_Target;
53 uint8_t* m_CommandVirtual;
54 uint8_t* m_PropertyVirtual;
55 size_t m_CommandWrite;
56 size_t m_CommandSize;
57 uint32_t m_DeviceLimit;
58 uint32_t m_EventBits;
59 bool m_Ready;
60};
61
62#endif
Special memory entity in the kernel's virtual address space.