aboutsummaryrefslogtreecommitdiff
path: root/kernel
AgeCommit message (Collapse)AuthorFilesLines
4 hourskernel/devices: implement depth-first PCI scanFelix Morgner7-26/+621
This change introduces a new depth-first PCI scan algorithm. This new algorithm is implemented in kernel::devices::pci::scan_segment. The scan traverse the PCI hierarchy by following bridges before moving on to the next device function. The result is a vector that presents the data so that each bridge directly precedes its subordinate devices in the vector. During the traversal, the following preconditions are checked before descending into subordinate devices. - The bridge has a non-zero secondary bus number. - The segment contains the bridge's secondary bus number. - The secondary bus number is greater than the primary bus number. - The subordinate bus range is greater or equal to the secondary bus number. If any of these preconditions are not met, the scan will does not descend down the detected bridge, and a kernel warning is issued. If a bus on a segment has already been scanned, it will not be scanned again and a kernel warning is issued. Additionally, this change transitions the PCI initialization to use the new depth-first scan algorithm, ensuring that the PCI hierarchy is traversed in a consistent and predictable manner. The change adds a set of tests to verify the contract established for scan_segment, including ensuring the correct kernel warnings are issued when preconditions are not met. To support the testing of error messages, the ecam_fixture clears the kernel log buffer before each leaf. A new function, kernel::tests::require_log_message, is introduced to assert the presence of specific log messages in the kernel log buffer.
7 hourskernel/devices: record PCI bridge information in scanFelix Morgner4-1/+109
Previously, no special handling was implemented when encountering PCI-to-PCI bridges, thus neither the secondary nor the subordinate bus numbers were recorded. This change extends the function_info type by two fields: secondary_bus and subordinate_bus, in preparation for the upcoming depth-first PCI bus scan. The fields are only read from ECAM space if the PCI function is a PCI-to-PCI bridge (including multifunction bridges), as reported by function_info::type. In all other cases, including CardBus bridges, the fields are set to zero. This change also includes the required constants in registers.hpp. The tests are extended to check that the secondary_bus and subordinate_bus fields are only read for PCI-to-PCI bridges, and left as zero otherwise.
13 hourstests: introduce ecam_fixture for PCI scan testsFelix Morgner10-199/+386
This change introduces the ecam_fixture to support and simplify writing of PCI scan tests. The ecam_fixture ensures that every leaf starts out with an empty ECAM space by filling the MMIO space with 0xff to ensure all vendor IDs read as 0xffff (the invalid vendor ID). The fixture uses the new kernel::tests::memory::fill_mmio seam function, via simulated_memory::fill, to fill the MMIO space. Clearing four buses per leaf through the builder made the scan scenario take about 3.2 s. Filling the backing memory brings it to about 38 ms. In support of the new fixture type, this change also introduces the following vocabulary additions in kernel::tests::devices::pci: - function_spec - ecam_fixture::place - ecam_fixture::endpoint - ecam_fixture::bridge - ecam_fixture::multifunction - ecam_fixture::make_descriptor - function_location - addresses - addresses_of The existing scan tests now use the ecam_fixture and the new vocabulary additions in their implementation. The function factories of the test suite now return function_spec objects to describe the PCI functions and allow them to be adjusted inside a test case using the new vocabulary functions.
13 hourstests: let ecam_builder set bridge bus numbersFelix Morgner3-46/+73
This change extends the ecam_builder to support additional configuration data for PCI bridges, namely the secondary and subordinate bus numbers. This extension is required to support upcoming PCI bridge walk tests by allowing the tests to configure PCI bridge topologies. The builder test reads both of the new bus numbers to verify they are set correctly. Additionally, this change introduces a new test support function in kstd, called require_ok. require_ok asserts that a kstd::result contains a success value and moves that value out of the result. In the case of a failed result, the source location of the require_ok call as well as the error message are reported and the test case is aborted. Both ecam_builder::window_for and the ecam_builder tests use this new function.
35 hourskernel/devices: extract bus scanning implementationFelix 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.
35 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.
35 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.
35 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.
35 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.
35 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.
35 hourstests: add support for MMIO mappingFelix Morgner8-44/+233
35 hourskapi/memory: carry hw_base offset forward in mappingFelix Morgner1-1/+2
35 hoursmemory: harden MMIO mappings and update docs.Felix Morgner1-0/+7
35 hoursmemory: improve MMIO allocation/mapping robustnessFelix Morgner4-35/+81
35 hourskapi/memory: map MMIO regions more securelyFelix Morgner1-1/+1
35 hoursdev/pcie: hide implementation detailsFelix Morgner2-54/+56
35 hoursdev/pcie: release absent MMIO regions during enumFelix Morgner1-9/+15
35 hourskapi/memory: unmap MMIO regions on releaseFelix Morgner1-0/+10
35 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.
35 hoursdev/pcie: introduce config space typeFelix Morgner2-8/+28
35 hoursdev/pcie: extend segment descriptorFelix Morgner1-5/+4
35 hourstests: fix test buildFelix Morgner1-0/+13
35 hoursdev/pcie: implement basic enumeration algorithmFelix Morgner1-5/+63
35 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
12 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>
12 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