The Pedigree Project 0.1
XhciRing.h
1/* Copyright (c) 2026, Pedigree Developers. SPDX-License-Identifier: ISC */
2#ifndef XHCI_RING_H
3#define XHCI_RING_H
4#include "pedigree/kernel/processor/MemoryRegion.h"
5#include "pedigree/kernel/processor/types.h"
6namespace XhciHw {
7constexpr size_t PageBytes = 4096, RingEntries = 256, MaxTransfer = 65536;
8constexpr size_t MaxSlots = 16, MaxPorts = 32, MaxTransactions = 64;
9constexpr uint32_t Cycle = 1, Chain = 1U << 4, Ioc = 1U << 5, Isp = 1U << 2;
10constexpr uint32_t PortChanges = 0x00fe0000U;
11struct Trb {
12 uint64_t parameter;
13 uint32_t status;
14 uint32_t control;
15};
16static_assert(sizeof(Trb) == 16);
17bool allocate(MemoryRegion& region, size_t pages, bool contiguous = true);
18class Ring {
19 public:
20 Ring();
21 bool initialise();
22 bool enqueue(const Trb* entries, size_t count, uint64_t* addresses);
23 void retire(size_t count);
24 uint64_t address() const {
25 return m_Memory.physicalAddress();
26 }
27 uint64_t enqueuePointer() const {
28 return address() + m_Tail * sizeof(Trb) + m_Cycle;
29 }
30 size_t wraps() const {
31 return m_Wraps;
32 }
33
34 private:
35 MemoryRegion m_Memory;
36 size_t m_Tail;
37 size_t m_Used;
38 bool m_Cycle;
39 size_t m_Wraps;
40};
41} // namespace XhciHw
42#endif
Special memory entity in the kernel's virtual address space.
physical_uintptr_t physicalAddress() const