Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

include: devicetree: Generate defines for map property #87595

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

soburi
Copy link
Member

@soburi soburi commented Mar 24, 2025

This change introduces generating definitions corresponding to
*-map property, which was currently discarded.

The *-map data is like a two-dimensional array, so it is difficult to
handle with the existing APIs, so we will also provide new APIs.


Common utilities have been separated into a separate PR.
Please take a look at this first. #84190


I noticed this problem while developing https://github.com/zephyrproject-rtos/gsoc-2022-arduino-core.

Since map is used to associate with the physical layout, there is a need to know the "physical pin names".

Since the mapping process is performed during the generation of devicetree-generated.h, I don't think there are many cases where information about the mapping source is needed. However, there are such cases, however rare, and it is not desirable for the information written in the devicetree to be discarded, so I would like to introduce this.

@soburi soburi force-pushed the dt_map_properties branch 2 times, most recently from cea82a5 to 7bd4e36 Compare March 24, 2025 22:39
soburi added 2 commits March 25, 2025 12:20
Gets the specified number of elements from the beginning of the list.
This is the symmetircal operation as `GET_ARGS_LESS_N`.

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
Add `GET_ARGS_FIRST_N` tests.

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
@soburi soburi force-pushed the dt_map_properties branch 8 times, most recently from 32aac28 to 6f69749 Compare March 26, 2025 05:03
@soburi soburi changed the title include: devicetree: Generate defines for map-related properties include: devicetree: Generate defines for map property Mar 26, 2025
soburi added 4 commits March 26, 2025 14:15
They must be `array` type to match the existing `interrupt-map-mask`
and `interrupt-map-pass-thru`.

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
Add a base binding for interrupt and io-channel nexus nodes.
This makes the implicit definitions explicit.
Replace existing individual map definitions with this.

This file does not define a specific `compatible` on its own,
So you should include this file before using it practically.

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
Making generalized the `_interrupt_cells` to be able to use for
any `#...-cells` property.

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
Add a method `to_compould()` to get a compound type value
consisting of a number and a phandle, like `...-map`.

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
@soburi soburi force-pushed the dt_map_properties branch from 6f69749 to 812c000 Compare March 26, 2025 05:16
@soburi soburi marked this pull request as ready for review March 26, 2025 06:02
@github-actions github-actions bot added area: Testsuite Testsuite area: ADC Analog-to-Digital Converter (ADC) area: Base OS Base OS Library (lib/os) area: GPIO area: Interrupt Controller area: Devicetree area: PCI Peripheral Component Interconnect labels Mar 26, 2025
soburi added 2 commits March 28, 2025 06:15
Add Map dataclass to store `*-map` property.

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
This change introduces generating definitions corresponding to
`*-map` property, which was currently discarded.

The `*-map` data is like a two-dimensional array, so it is difficult to
handle with the existing APIs, so we will also provide new APIs.

Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
@soburi soburi force-pushed the dt_map_properties branch from 812c000 to e5f0587 Compare March 27, 2025 21:15
Copy link
Contributor

@mbolivar mbolivar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, @soburi . The first 5/8 patches look good to me, with one minor comment.

I have some concerns about the last 3/8 patches. I think I understand the goal and exposing the map properties as first-class citizens makes sense to me. However, the approach using to_compound() feels a little bit error-prone and I want to discuss the implementation.

Devicetree Specification v0.4 section 2.5, "Nexus Nodes and Specifier Mapping" is where the semantics are defined. There, it says:

A nexus node shall have a #<specifier>-cells property, where <specifier> is some specifier space such as ‘gpio’, ‘clock’, ‘reset’, etc

The description of the <specifier>-map property then says:

child specifier

The specifier of the child node being mapped. The number of 32-bit cells required to specify this component is described by the #<specifier>-cells property of this node—the nexus node containing the <specifier>-map property

It also says:

parent specifier

The specifier in the parent domain. The number of 32-bit cells required to specify this component is described by the #<specifier>-cells property of the specifier parent node.

Combining these, I think that we should be able to decode each <specifier>-map property without needing to_compound(). We can make a loop like this:

  1. Read #<specifier>-cells * 4 bytes from the current position in the <specifier>-map property. This is the child specifier. We can convert it to <u32> cells using existing dtlib features.
  2. Read the next 4 bytes. This is the "specifier parent" phandle from section 2.5 of the specification. We can convert it to a "specifier parent node" using phandle2node.
  3. Read the #<specifier>-cells property from the specifier parent node. This is the number of <u32> cells after the phandle which makes the "parent specifier"
  4. Read the parent specifier bytes and convert them to cells.

What I mean is, by using the #<specifier>-cells properties in the parent and child nodes, we can iterate through the <specifier>-map property and convert it into a lookup table without to_compound().

I am concerned that to_compound() is:

  • not checking the proper #<specifier>-cells values we expect to find, and instead just uses the source encoding to guess where the table entry elements are in <specifier>-map
  • adding a feature for strings that does not seem to be needed to handle <speciifer>-map properties -- this feels like it might be trying to do more than it needs to, and might have to be revisited over time as we add more heuristics

I'd be more comfortable with an approach that relied on the strict definitions in section 2.5 of the specification to decode the values of <specifier>-map properties. We can be sure that this will not change and the code will stand the test of time.

"#io-channel-cells":
type: int
required: true
description: Number of items to expect in a ADC specifier
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, strictly speaking, that these are derived from the Linux iio bindings. The iio bindings are useful for ADCs but are not limited to ADCs. So perhaps this should be moved to dts/bindings/iio, and this "ADC specifier" portion should be changed to "channel specifier, e.g. ADC channel" or something similar?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: ADC Analog-to-Digital Converter (ADC) area: Base OS Base OS Library (lib/os) area: Devicetree area: GPIO area: Interrupt Controller area: PCI Peripheral Component Interconnect area: Testsuite Testsuite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants