aboutsummaryrefslogtreecommitdiff
path: root/kernel
AgeCommit message (Collapse)AuthorFilesLines
24 hourskernel/devices: extract bus scanning implementationfmorgner/pcie-scanFelix Morgner9-50/+1006
This change extracts the PCI bus scanning logic, which previously was hidden inside an anonymous namespace, into a dedicated function. This allows for the implementation to be tested independently.
24 hourskernel/devices: introduce PCI function_infoFelix Morgner2-0/+210
Besides address information, each PCI function also has associated metadata. The function_info type carries the standard metadata for a PCI function: vendor and device IDs, the class code 3-tuple, and the header type. A bus scan reads those values when enumerating the PCI ECAM data, and returns it. The header type of the is stored in its raw form, encoding both the type of the PCI function header, as well as the multi-function flag. function_info provides two functions (type() and is_multifunction()) to extract those pieces of information from the raw header type value. In addition to the type extraction function, this change introduces an enumeration type (kernel::devices::pci::header_type) representing the standardized type values for PCI function headers. Unknown function types are presented as opaque values. Unit tests for derived attributes of a PCI function are provided.
24 hourskernel/devices: introduce PCI function_addressFelix Morgner2-0/+150
A PCI function is identified system-wide by its segment group, bus, device and function number. This identifier is represented by the new function_address type. It encapsulates the identifying 4-tuple (segment group, bus, device, function). This allows the kernel to reference a specific PCI function unambiguously within the system. The type is comparable and ordered by that tuple and formats as 'ssss:bb:dd.f'. The ordering is lexicographical based on the tuple (segment group, bus, device, function). Unit tests for the API surface of function_address are included.
24 hourskernel/devices: introduce PCI ecam_segment abstractionFelix Morgner10-129/+605
Previously, ECAM access was implemented "in-place" inside the PCI scan function. This meant that any checks were ad-hoc and not easily reusable or testable. Therefore, this change introduces a dedicated, reusable abstraction for ECAM segment access. It validates segment descriptors received from the platform and ensures no out-of-bounds buses are accessed at runtime. Construction of an ecam_segment will always succeed. If the firmware or platform data does not describe a valid segment, the ecam_segment will behave as if it had a size of zero, with a kernel log indicating the invalid segment. Attempting to map a bus that is out-of-bounds for a given ecam_segment will return a runtime error. If the system's MMIO space is insufficient to accommodate the mapping of a valid bus in an ecam_segment, a runtime error will be returned. Furthermore, this change introduces the kernel::devices::pci namespace. PCI initialization and scanning functionality, previously hosted in kernel/kernel/devices/pci_express.{cpp,hpp}, has been relocated and renamed to kernel/kernel/devices/pci/init.{cpp,hpp}. The initialization function of the PCI subsystem has been renamed from kernel::devices::init_pci_express_devices to kernel::devices::pci::init. The observable behavior of the PCI scan remains unchanged. Tests have been added to validate the behavior of ecam_segment against its contract.
24 hourskapi/memory: replace mmio_region API with mmio_windowFelix Morgner5-125/+607
Previously, allocation and mapping of MMIO regions was a multi-step process. The MMIO region API required its users to track and manage the lifetime of an MMIO region allocation manually. The new MMIO window API simplifies this by providing a single-step mapping interface and automatic lifetime management. Additionally, the new API adds strict bounds and alignment checks, to ensure that all MMIO accesses are within the requested range. The new API enforces these constraints at runtime via a system panic. Other contract violations, such as zero-sized mappings, are handled via runtime error codes. The new kapi::memory::mmio_window preserves the in-page offset of the hardware base within the window and bases all accesses on this offset. This means no user intervention is required to handle hardware ranges that are not aligned to a natural page boundary. The original pointer adjustment logic has been moved into the mmio_window class. Previous consumers of the region API (x86_64 LAPIC, PCIe) have been updated to the new mmio_window API. The behavior of the PCIe scan implementation has changed in that no windows are kept alive beyond the execution of the scan, since there are no consumers that would require persistent MMIO windows. Tests for the new infrastructure have been added, including a test support seam to allow for deinitialization of the MMIO subsystem in tests.
24 hourskapi/memory: add a destructor to mmio_allocatorFelix Morgner2-0/+13
In testing, the mmio_allocator gets replaced for every scenario requiring all heap allocations to be properly cleaned up before the replacement.
24 hourstests: add support for MMIO mappingFelix Morgner8-44/+233
24 hourskapi/memory: carry hw_base offset forward in mappingFelix Morgner1-1/+2
24 hoursmemory: harden MMIO mappings and update docs.Felix Morgner1-0/+7
24 hoursmemory: improve MMIO allocation/mapping robustnessFelix Morgner4-35/+81
24 hourskapi/memory: map MMIO regions more securelyFelix Morgner1-1/+1
24 hoursdev/pcie: hide implementation detailsFelix Morgner2-54/+56
24 hoursdev/pcie: release absent MMIO regions during enumFelix Morgner1-9/+15
24 hourskapi/memory: unmap MMIO regions on releaseFelix Morgner1-0/+10
24 hourskapi/memory: fix page unmap logicFelix Morgner4-13/+27
Previously, the page mapper was expected to automatically free all frames that had become unused. However, this only works if all mappings refer to plain memory frames. In the case of MMIO frames, the mapper would still try to release the frame via the global frame allocator, which is incorrect, leading to undefined behavior in the worst case. This problem was discovered during work the PCI/PCIe subsystem, since we want to unmap any unused buses during enumeration.
24 hoursdev/pcie: introduce config space typeFelix Morgner2-8/+28
24 hoursdev/pcie: extend segment descriptorFelix Morgner1-5/+4
24 hourstests: fix test buildFelix Morgner1-0/+13
24 hoursdev/pcie: implement basic enumeration algorithmFelix Morgner1-5/+63
24 hoursdev/pcie: implement initial detectionFelix Morgner4-0/+49
11 daysbuild: fix test executablesFelix Morgner1-0/+4
11 dayslibs/acpi: don't convert addresses to pointerFelix Morgner2-3/+1
Previously, ACPI table addresses in both the RSDT and XSDT were converted to pointers. However, this is not actually correct, since within the object model of the kernel, pointers always refer to objects by their linear address, and the addresses encoded in ACPI tables are, by necessity, physical addresses. The API should therefore be honest about the fact that the addresses returned by accessors of the RSDT and XSDT are physical addresses, not pointers to live objects.
11 dayslibs/acpi: extend MCFG table interfaceFelix Morgner1-18/+0
11 daystest: apply review feedback for Catch2 string makersmanuel3-17/+15
- restrict the -include force-include flag to GCC and Clang - drop the redundant explicit include in the kernel string maker tests - apply clang-format Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
11 dayskernel: add Catch2 string makers for printable test outputmanuel3-0/+197
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29kapi/interrupts: add testsFelix Morgner2-0/+254
2026-09-29kapi/interrupts: tests: fix state data raceFelix Morgner1-14/+3
2026-09-29kapi/interrupts: tests: make IRQ state thread specificFelix Morgner1-3/+12
2026-09-29kapi/interrupt: rework enablement APIFelix Morgner2-3/+15
2026-09-10kapi/system: reduce panic buffer sizeFelix Morgner1-5/+85
Previously, we allocated a 512-byte buffer for every call of the formatted panic function. This was heavily increasing the stack size for a number of functions. We now don't print to a statically allocated buffer, but rather use the iterator-based formatting facility and a proxy iterator with a small, self-flushing buffer. This reduces that static overhead of the formatted panic function to by almost 500 bytes, while increasing possible message fidelity, since we are not longer arbitrarily limited by the buffer.
2026-09-10kernel: replace some more plain pointersFelix Morgner10-35/+41
2026-09-10kernel/vfs: reduce number registry pruningFelix Morgner2-8/+1
Previously, the number registry did a pruning pass whenever elements, either all or a filtered subset, were queried by a consumer. This meant, that every access to elements did an additional O(n) scan of the entire registry, to ensure no expired devices were still registered. This used to be necessary, when the ownership model for devices was still in flux. With the established device ownership model, this has become obsolete. Additionally, devices get numbered automatically when a device gains a facet the is observed by the device number registry. Since registering this type of facet is the responsibility of the device driver, since only a driver can know how to implement that facet for any given device, it also becomes the responsibility of the driver to revoke that facet if and when a device is detached from the system. Any device is always owned by the bus it is attached to. This means it is the bus' responsibility to inform drivers about devices disappearing. This closes the chain of responsibility cleanly, meaning the device number registry will never have to prune itself in any accessors. Instead, it will be informed by the facet registry that a facet for a device has been revoked, allowing it to un-number that device if applicable.
2026-09-10x86_64: replace raw pointers with observer_ptrFelix Morgner5-21/+27
2026-09-09chore: replace some naked pointersFelix Morgner19-61/+71
The coding guidelines explicitly prohibit the use of "naked"/C-style pointers. However, there were some prominent examples in the kapi and the core kernel source. This changeset replaces them with the appropriate smart pointer types.
2026-09-03fs, devices: fix undefined behavior in registrationFelix Morgner2-10/+28
2026-09-03chore: fix header guardsFelix Morgner1-1/+1
2026-09-03chore: fix message prefixesFelix Morgner2-45/+43
2026-09-03chore: add missing [[nodiscard]] attributesFelix Morgner8-16/+23
2026-09-01kernel: fix broken readme symlinkFelix Morgner1-1/+1
2026-09-01chore: clean up facet idsFelix Morgner5-38/+41
2026-08-31chore: minor stylistic cleanupsFelix Morgner4-15/+16
2026-08-29chore: normalize panic messagesFelix Morgner18-50/+50
2026-08-29chore: apply stylistic cleanupsFelix Morgner30-209/+216
2026-08-28kernel/vfs: implement read_directory fixups.Felix Morgner6-2/+134
POSIX requires that the data returned by the readdir() function shows the inode number of the root of a mounted filesystem for its mount point. Additionally, the inode number of the '..' reference in the mounted filesystem must show the inode number of the mount point. We perform this fixup when computing the entries during read_directory on the fly. The implementation of the upward fixup will need to be revised once the kernel supports bind mounts.
2026-08-28kernel/fs: devfs: fix inode encodingFelix Morgner1-2/+1
2026-08-28fixup! kernel/fs: ext2: fix block allocation on 1 KiB fsFelix Morgner3-7/+12
2026-08-28fixup! kernel/vfs: add identity based mount removalFelix Morgner1-1/+1
2026-08-28kernel/vfs: implement root swivel and mount moveFelix Morgner9-71/+92
Previously, the device filesystem (devfs) was simply grafted on each root filesystem during boot. This caused the existence of an unreachable, dead devfs mount after the VFS instance had been initialized. This changeset implements the ability to relocate an active mount from one mount point to another. That way, no second devfs mount needs to be created. Instead, the existing devfs mount is relocated to a mount point in the persistent root filesystem that get mounted during initialization. Secondly, this changeset also alters the VFS initialization flow, so that only one root mount exists after initialization finishes.
2026-08-28fixup! kernel/vfs: mount: resolve return type todoFelix Morgner1-2/+2
2026-08-28kernel/fs: ext2: fix block allocation on 1 KiB fsFelix Morgner1-2/+2
When computing the actual block numbers for a filesystem, care must be taken to account for which block is the actual first data block. For 1 KiB block size filesystems, that block is actually block 1, not 0. This is because the first 1 KiB on any ext2 volume is reserved for bootloader data. Complicating matters, the bitmaps don't take this into account. They essentially reflect a logical view, describing which data blocks are already allocated. On a 1 KiB filesystem, this effectively means that bit 0 of the allocation bitmap references physical block 1. Luckily, we don't need to make that determination based on the block size at all. The superblock already carries the number of the first data block. That means one can simply add that number, which is 1 in the 1 KiB block size case and 0 otherwise, to the found block index. Interestingly, this was already caught by accident when locating the authoritative block group descriptor (BGD) table. A factor of two was multiplied into the calculation in the case of a 1 KiB block size. This factor arises because the primary BGD table follows the primary superblock. Since the superblock is located in physical block 0 in all cases except for a 1 KiB block size, the BGD table generally lands in block 1. This implies an offset of 1 block size from the volume start. In the 1 KiB case, the BGD table lands in block number 2, effectively at an offset of 2 blocks from the start of the volume. This changeset makes that calculation explicit in the BGD table locator code as well. This clarifies the previously obscure factor of 2.