38 Commits
Author SHA1 Message Date
Undefine adede105a1 LibDeviceTree: Switch two calls to try_appendff
The rest of the calls used the fallible APIs already, but those were
missed.
2026-11-06 20:34:06 +01:00
Sönke Holz ad60de702e LibDeviceTree: Add Node::get_{u32,u64}_property()
This allows you to more easily implement fallback values with
`device.node().get_u32_property("foo"sv).value_or(0)`.
2026-01-15 17:58:20 +01:00
Sönke Holz c382e2acb5 LibDeviceTree+Kernel: Rename interrupt_{identifier => specifier}
The correct term from the devicetree spec is "interrupt specifier".
2025-11-24 16:56:52 +01:00
Sönke Holz fbb63faa1d AK+Kernel+Userland: Don't allow Vector::resize() in the kernel
This function doesn't propagate allocation failures.

Replace all current usages of this function by using `try_resize()`
instead.
2025-11-22 19:51:20 +01:00
Sönke Holz 5542998a79 AK+Kernel+Userland: Don't allow Vector copy constructors in the kernel
The copy constructors and copy assignment operators can't propagate
allocation failures.

As a replacement, introduce a new member function, Vector::clone() that
returns an ErrorOr<Vector>.

This commit replaces most usages of the Vector copy constructor by
either using .clone() or avoiding copies in the first place.
2025-11-22 19:51:20 +01:00
Sönke Holz 6f37142afe AK+Userland: Don't allow ReadonlySpan Vector constructor in the kernel
This constructor can't propagate allocation failures.

As a replacement, add a static `from_span` function that returns an
error on allocation failures.
2025-11-22 19:51:20 +01:00
Sönke HolzandHendiadyoin1 633e44e83a LibDeviceTree: Add Ranges::{begin,end}()
This makes it possible to use range-based for loops on Node::ranges().

Co-authored-by: Hendiadyoin1 <[email protected]>
2025-05-10 14:12:43 +02:00
Sönke Holz c97719f4cb LibDeviceTree: Add Address::as<T>() helper 2025-05-10 14:12:43 +02:00
Sönke Holz 89e4f890d2 LibDeviceTree: Add support for the "interrupts-extended" property 2025-03-23 18:18:25 +01:00
roadshop c74f659ebd LibDeviceTree: Fix a typo in comment 2024-12-31 16:56:13 +01:00
Sönke Holz 5aa6136e02 LibDeviceTree: Add functions for accessing common interrupt properties 2024-12-10 16:25:46 +01:00
Sönke Holz ddd9ab21e6 LibDeviceTree: Add functions for getting and translating addresses
I created this test file by running the following command:

    dtc -o address-translation.dtb <<EOF
    /dts-v1/;

    / {
        compatible = "serenity,address-translation-test";
        #address-cells = <2>;
        #size-cells = <1>;

        soc {
            compatible = "simple-bus";
            #address-cells = <1>;
            #size-cells = <1>;
            ranges = <0xa0000000 0xfe 0xd0000000 0x40000000>;

            usb@a0010000 {
                reg = <0xa0010000 0x100000>;
            };

            some-bus@b0000000 {
                compatible = "simple-bus";
                #address-cells = <2>;
                #size-cells = <2>;
                ranges = <0x02 0x00 0xb0000000 0x00 0x200000>;

                leds@200100000 {
                    reg = <0x02 0x100000 0x00 0x1000>;
                };
            };
        };
    };
    EOF
2024-12-10 16:25:46 +01:00
Sönke Holz 7d41d5191b LibDeviceTree: Rename DeviceTreeNodeView to Node
The class is in the DeviceTree namespace, so the prefix is redundant.
Calling it a 'View' is also somewhat misleading, as it is not simply a
cheap-to-copy reference to the underlying memory but is instead marked
as AK_MAKE_NONCOPYABLE.
2024-12-10 16:25:46 +01:00
Sönke Holz 81ede84131 LibDeviceTree: Rename DeviceTreeProperty to Property
The struct is in the DeviceTree namespace, so the prefix is redundant.
2024-12-10 16:25:46 +01:00
Sönke Holz ed097d87da LibDeviceTree: Make FlattenedDeviceTreeTokenType an enum class
This will be necessary in the next commit to avoid a name conflict.
2024-12-10 16:25:46 +01:00
Sönke Holz fe6d785e91 LibDeviceTree: Remove DeviceTreeNodeView::child()
This (confusingly named) function will probably never be used, since you
normally should know whether you are looking for a child or property.
2024-12-10 16:25:46 +01:00
Sönke Holz 4c9b798543 LibDeviceTree: Add DeviceTreeNodeView::is_compatible_with 2024-11-02 13:53:10 -04:00
kleines Filmröllchen a3077203fe AK: Don't implicitly convert Optional<T&> to Optional<T>
C++ will jovially select the implicit conversion operator, even if it's
complete bogus, such as for unknown-size types or non-destructible
types. Therefore, all such conversions (which incur a copy) must
(unfortunately) be explicit so that non-copyable types continue to work.
2024-09-14 13:30:27 +02:00
Hendiadyoin1 b17f080dcc Kernel/riscv: Use new DeviceTree helpers in PCI initializations
This also changes the PCI interface slightly to be a bit nicer to work
with.
2024-05-02 07:44:13 -06:00
Hendiadyoin1 e014296092 LibDeviceTree: Make DeviceTreeProperty::as_stream return a ValueStream
This new Stream class adds an interface to work in cell-sized chunks,
which is useful for parsing the data in a DeviceTreeProperty.
2024-05-02 07:44:13 -06:00
Hendiadyoin1 ffa9875fa6 LibDeviceTree: Fix stale pointers in phandle and parent handling
We need to set them after we've created the full tree, as otherwise the
HashMap containing the nodes may reallocate and invalidate the pointers.
2024-05-02 07:44:13 -06:00
Hediadyoin1 21a21c6a11 LibDeviceTree: Add a simple DeviceTree class
This makes it easier to work with device tree nodes and properties, then
writing simple state machines to parse the device tree.
This also makes the old slow traversal methods use the
DeviceTreeProperty helper class, and adds a simple test.
2024-02-24 16:43:44 -07:00
Hendiadyoin1 d6bb5579ad LibDeviceTree: Make the dump more akin to the original fdtdump
This also makes it possible to compile the library in the Kernel
2024-02-24 16:43:44 -07:00
Nico Weber 24a469f521 Everywhere: Prefer {:#x} over 0x{:x} in format strings
The former automatically adapts the prefix to binary and octal
output, and is what we already use in the majority of cases.

Patch generated by:

    rg -l '0x\{' | xargs sed -i '' -e 's/0x{:/{:#/'

I ran it 4 times (until it stopped changing things) since each
invocation only converted one instance per line.

No behavior change.
2024-02-21 17:54:38 +01:00
Timothy Flynn aa0a6d58b2 Userland: Remove LibCore dependency from libraries that do not use it 2024-01-22 08:48:34 -05:00
Ben Wiederhake 560133a0c6 Everywhere: Remove unused DeprecatedString includes 2023-04-09 22:00:54 +02:00
MacDue f8bdb584f8 LibDeviceTree: Use unchecked_append() in path parsing
try_append() checks if the vector should increase capacity and if
so grows the vector. unchecked_append() verifies the vector already
has enough capacity, and will never grow the vector.
2023-02-24 23:56:37 +01:00
Linus Groh 69f0339bac Revert "LibDeviceTree: Propagate try_append() errors while parsing paths"
This reverts commit f064f5f36e.

As Andrew points out, this append is not actually fallible in practice,
since the loop is terminated once the vector size reaches its inline
capacity.

https://github.com/SerenityOS/serenity/pull/17606#discussion_r1117662246
2023-02-24 23:40:23 +01:00
MacDue f064f5f36e LibDeviceTree: Propagate try_append() errors while parsing paths 2023-02-24 22:18:25 +01:00
Andrew Kaster 613cfb31b1 LibDeviceTree: Add a slow, allocation-free property fetch API
Using the walk_device_tree helper, we can walk the device tree from the
beginning looking for a specific property node. It's still missing the
ability to get property lists, string lists, and property-specific data.
2023-02-19 13:49:07 +01:00
Andrew Kaster e9e279bb77 LibDeviceTree: Add walk_device_tree and use it to dump structured data
We can use this simple parser and its callbacks to implement more
complex parsing in later commits.
2023-02-19 13:49:07 +01:00
Andrew Kaster 895f54f487 LibDeviceTree: Refactor dump() to return ErrorOr, and use ReadonlyBytes
ReadonlyBytes is much nicer to use than a u8 const* + size_t.
2023-02-19 13:49:07 +01:00
Andrew Kaster 01f32a22b4 LibDeviceTree: Print the StringsBlock size properly when bounds checking 2023-02-19 13:49:07 +01:00
Linus Groh 6e19ab2bbc AK+Everywhere: Rename String to DeprecatedString
We have a new, improved string type coming up in AK (OOM aware, no null
state), and while it's going to use UTF-8, the name UTF8String is a
mouthful - so let's free up the String name by renaming the existing
class.
Making the old one have an annoying name will hopefully also help with
quick adoption :^)
2022-12-06 08:54:33 +01:00
Daniel Bertalan 4296425bd8 Everywhere: Remove redundant inequality comparison operators
C++20 can automatically synthesize `operator!=` from `operator==`, so
there is no point in writing such functions by hand if all they do is
call through to `operator==`.

This fixes a compile error with compilers that implement P2468 (Clang
16 currently). This paper restores the C++17 behavior that if both
`T::operator==(U)` and `T::operator!=(U)` exist, `U == T` won't be
rewritten in reverse to call `T::operator==(U)`. Removing `!=` operators
makes the rewriting possible again.
See https://reviews.llvm.org/D134529#3853062
2022-11-06 10:25:08 -07:00
Tim Schumacher ce2f1b845f Everywhere: Mark dependencies of most targets as PRIVATE
Otherwise, we end up propagating those dependencies into targets that
link against that library, which creates unnecessary link-time
dependencies.

Also included are changes to readd now missing dependencies to tools
that actually need them.
2022-11-01 14:49:09 +00:00
Tim Schumacher 7834e26ddb Everywhere: Explicitly link all binaries against the LibC target
Even though the toolchain implicitly links against -lc, it does not know
where it should get LibC from except for the sysroot. In the case of
Clang this causes it to pick up the LibC stub instead, which might be
slightly outdated and feature missing symbols.

This is currently not an issue that manifests because we pass through
the dependency on LibC and other libraries by accident, which causes
CMake to link against the LibC target (instead of just the library),
and thus points the linker at the build output directory.

Since we are looking to fix that in the upcoming commits, let's make
sure that everything will still be able to find the proper LibC first.
2022-11-01 14:49:09 +00:00
Andrew Kaster 644928314a Libraries: Add LibDeviceTree for manipulating OpenFirmware Device Trees
Starting with header validation and a dump() method that can be used to
debug future parsing work.
2021-10-21 19:20:03 -07:00