| Age | Commit message (Collapse) | Author | Files | Lines |
|
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.
|
|
dev/pci: implement basic PCI detection
See merge request teachos/kernel!74
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
In testing, the mmio_allocator gets replaced for every scenario
requiring all heap allocations to be properly cleaned up before the
replacement.
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
libs/acpi: implement MCFG table support
See merge request teachos/kernel!72
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
kstd: add Catch2 string makers for printable test output source from develop branch
See merge request teachos/kernel!69
|
|
- 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>
|
|
|
|
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|