aboutsummaryrefslogtreecommitdiff
AgeCommit message (Collapse)AuthorFilesLines
51 min.kernel/bus: add PCI matching contractfmorgner/pci-device-treeFelix Morgner4-0/+845
This change implements the PCI matching contract for devices and drivers. Device-driver pairings are ranked based on the specificity of the match between a pci_id and a function_info object. An exact match of the vendor_id and device_id of a pci_id and a function_info object scores 0x10. Each matching class_code, subclass_code, and programming_interface adds 1 point to the score. Matching is performed independently for each entry in a driver's match table, with the highest scoring entry determining the final match score for a single driver. Any malformed entries in the match tables are ignored. Specifically, an entry is considered malformed if it names a vendor_id without a device_id or vice versa. An entry is also considered malformed if it names a programming_interface without a subclass_code or a subclass_code without a class_code. An entry naming no fields is also considered malformed. This change also introduces the following types for PCI devices, drivers, and buses: pci_id, pci_claim, pci_signature, and pci_protocol. pci_protocol is an abstract class because the host bridge and PCI-to-PCI bridges will differ in their implementations of pci_protocol::enumerate. Both bridge types will share the same ranking algorithm for device-driver pairings. The included tests exercise the PCI matching algorithm, including scoring of valid matches, malformed entries, and driver selection through the global driver registry.
16 hoursMerge branch 'fmorgner/pcie-scan' into 'develop'HEADdevelopFelix Morgner57-191/+4162
dev/pci: implement basic PCI detection See merge request teachos/kernel!74
17 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.
20 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.
26 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.
26 hourstests: let ecam_builder set bridge bus numbersFelix Morgner4-46/+106
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.
2 dayskernel/devices: extract bus scanning implementationFelix Morgner10-50/+1008
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.
2 dayskernel/devices: introduce PCI function_infoFelix Morgner3-0/+211
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.
2 dayskernel/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.
2 dayskernel/devices: introduce PCI ecam_segment abstractionFelix Morgner11-129/+606
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.
2 dayskapi/memory: replace mmio_region API with mmio_windowFelix Morgner10-192/+818
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.
2 dayskapi/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.
2 daystests: add support for MMIO mappingFelix Morgner8-44/+233
2 dayskapi/memory: carry hw_base offset forward in mappingFelix Morgner2-4/+6
2 daysmemory: harden MMIO mappings and update docs.Felix Morgner5-17/+50
2 daysmemory: improve MMIO allocation/mapping robustnessFelix Morgner6-42/+104
2 daysx86_64/memory: panic on huge page mappingsFelix Morgner1-0/+10
The x86_64 platform's higher half memory mapper currently has not support for huge page mappings. However, the previous implementation did not explicitly exclude huge page mappings, instead potentially corrupting the contents of huge pages by treating them as regular pages. The kernel now panics whenever an attempt is made to map a page inside a region covered by a huge page, or when trying to unmap a huge page or a range covered by a huge page.
2 daysx86_64/memory: check leaf entry before unmappingFelix Morgner1-0/+8
2 daysx86_64/memory: flush TLB on page unmapFelix Morgner2-1/+3
2 dayskapi/memory: map MMIO regions more securelyFelix Morgner1-1/+1
2 daysdev/pcie: hide implementation detailsFelix Morgner2-54/+56
2 daysdev/pcie: release absent MMIO regions during enumFelix Morgner1-9/+15
2 dayskapi/memory: unmap MMIO regions on releaseFelix Morgner1-0/+10
2 dayskapi/memory: fix page unmap logicFelix Morgner8-30/+62
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.
2 daysdev/pcie: introduce config space typeFelix Morgner2-8/+28
2 daysx86_64/pcie: fix bus group numberFelix Morgner1-2/+2
2 daysdev/pcie: extend segment descriptorFelix Morgner3-11/+28
2 daystests: fix test buildFelix Morgner1-0/+13
2 daysdev/pcie: implement basic enumeration algorithmFelix Morgner2-5/+72
2 daysdev/pcie: implement initial detectionFelix Morgner8-0/+113
2 dayside: update devcontainer imageFelix Morgner1-1/+1
2 daysbuild: remove unused clang-tidy optionFelix Morgner1-23/+1
4 daysbuild: ensure clang-tidy uses the correct pathsFelix Morgner3-23/+54
Previously, clang-tidy would fall back to the global GCC toolchain and its include paths, meaning that any custom patches would be ignored. A partial solution had already been implemented for header checks, but the regular cpp file checks did not use the new flags. This change extracts the GCC toolchain location determination into the platform's CMake toolchain file and then applies those flags to both header and cpp file checks consistently.
11 daysagents: implement basic rules and skillsFelix Morgner6-0/+502
12 daysMerge branch 'fmorgner/acpi-extension-1' into 'develop'Felix Morgner26-133/+797
libs/acpi: implement MCFG table support See merge request teachos/kernel!72
12 daysbuild: fix test executablesFelix Morgner2-3/+14
12 dayscmake: clean up test target generationFelix Morgner1-86/+49
12 daysbuild: fix stress test linkingFelix Morgner1-2/+16
12 dayslibs/acpi: clean up MCFG entry reading codeFelix Morgner2-31/+25
12 dayslibs/acpi: don't convert addresses to pointerFelix Morgner8-19/+13
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.
12 dayslibs/acpi: improve data docsFelix Morgner5-8/+99
12 dayslibs/acpi: improve common documentationFelix Morgner4-23/+183
12 dayslibs/acpi: improve vla_table interfaceFelix Morgner9-83/+221
12 dayslibs/acpi: extend MCFG table interfaceFelix Morgner7-21/+132
12 dayslibs/acpi: implement MCFG table supportFelix Morgner5-0/+160
12 dayslibs/acpi: add basic test data for MCFG tableFelix Morgner4-0/+28
12 daysMerge branch 'feature/catch2-string-makers-develop' into 'develop'Felix Morgner10-2/+488
kstd: add Catch2 string makers for printable test output source from develop branch See merge request teachos/kernel!69
12 daystest: apply review feedback for Catch2 string makersmanuel5-29/+27
- 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 daysdoc: require StringMaker instead of formatter for test printingmanuel2-7/+6
12 daysdoc: describe how to make types printable in test failuresmanuel1-0/+10
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>