| Age | Commit message (Collapse) | Author | Files | Lines |
|
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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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, 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.
|
|
|
|
- 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>
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
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.
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
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.
|
|
|
|
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.
|