Skip to content

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 10 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 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 soburi force-pushed the dt_map_properties branch from 21c854e to b4a6f6a Compare October 5, 2025 11:52
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.

@soburi thank you for your update. I think there is enough in here for me to give this a good review, which I will do as soon as I can. (I am traveling this week on a work trip so my availability will be a bit less than it was last week, but I want to prioritize your PR among other DT review requests I have.)

As an overall design question, I'm not sure that I think that ControllerAndData is an appropriate class to be using to represent the maps.

The zephyr phandle-array type is used when we have a list of (phandle, specifier) pairs. But in the case of generic maps, we don't have pairs, we have triples: (child_specifier, specifier_parent_phandle, parent_specifier). And in the case of interrupt maps, we have 5-tuples: (child_unit_address, child_interrupt_specifier, interrupt_parent, parent_unit_address, parent_interrupt_specifier).

I think that neither of these types of information is really a ControllerAndData due to the additional "child -> parent" information.

I am currently thinking it would make more sense to introduce two new types:

  1. NexusMapEntry: for the table entries contained in a <specifier>-map as documented in DTSpec section 2.5.1. This would contain attributes named child_specifier, parent, parent_specifier.
  2. InterruptMapEntry: similar, except for the interrupt-map property table entries in DTSpec 2.4.3.

This would match the same pattern we have done with the Range type used to represent elements of the standard ranges property. Experience has shown from that case that picking type names and designing APIs to match the specification leads to future-proof work.

What do you think about this idea?

@mbolivar
Copy link
Contributor

mbolivar commented Oct 5, 2025

I'm not sure that I think that ControllerAndData

#87595 (review)

cc @dottspina for his perspective as a consumer of this API

@soburi
Copy link
Member Author

soburi commented Oct 6, 2025

@mbolivar

I think that neither of these types of information is really a ControllerAndData due to the additional "child -> parent" information.

I am currently thinking it would make more sense to introduce two new types:

1. `NexusMapEntry`: for the table entries contained in a `<specifier>-map` as documented in DTSpec section 2.5.1. This would contain attributes named `child_specifier`, `parent`, `parent_specifier`.

2. `InterruptMapEntry`: similar, except for the `interrupt-map` property table entries in DTSpec 2.4.3.

This would match the same pattern we have done with the Range type used to represent elements of the standard ranges property. Experience has shown from that case that picking type names and designing APIs to match the specification leads to future-proof work.

What do you think about this idea?

This was possible with the current structure, so I did so, but
as mentioned in the comments, I think it would be clearer to define a new type.

There may be some room for debate as to whether to use NexusMapEntry/InterruptMapEntry or use MapEntry to make the interrupt property optional as needed for.

I'll move forward with it, but I might not have enough time this week.

@mbolivar
Copy link
Contributor

mbolivar commented Oct 6, 2025

There may be some room for debate as to whether to use NexusMapEntry/InterruptMapEntry or use MapEntry to make the interrupt property optional as needed for.

I agree there's room for debate. We could also use class inheritance to capture the specialization, perhaps. Thanks and looking forward to your next update.

@soburi soburi force-pushed the dt_map_properties branch from b4a6f6a to 028b898 Compare October 11, 2025 03:35
@zephyrbot zephyrbot requested a review from mbolivar October 11, 2025 03:37
@soburi soburi force-pushed the dt_map_properties branch 2 times, most recently from e6ff1b4 to 96619b5 Compare October 11, 2025 04:41
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 <[email protected]>
Add `GET_ARGS_FIRST_N` tests.

Signed-off-by: TOKITA Hiroshi <[email protected]>
They must be `array` type to match the existing `interrupt-map-mask`
and `interrupt-map-pass-thru`.

And also, updating descriptions.

Signed-off-by: TOKITA Hiroshi <[email protected]>
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 <[email protected]>
@soburi soburi force-pushed the dt_map_properties branch from 96619b5 to 8318abc Compare October 12, 2025 03:34
@soburi
Copy link
Member Author

soburi commented Oct 12, 2025

@mbolivar

Update done.

There may be some room for debate as to whether to use NexusMapEntry/InterruptMapEntry or use MapEntry to make the interrupt property optional as needed for.

I decided to use MapEntry because there are no 'behavior' differences between these, so I think no need to split into a class hierarchy.
The difference is whether the length of the ADDRESS information is 0 or not.

I agree there's room for debate. We could also use class inheritance to capture the specialization, perhaps. Thanks and looking forward to your next update.

As a result, I updated macro generation rules and the APIs. It is mainly just a cleanup, but the structure makes it simple and reduces the code.

@soburi soburi force-pushed the dt_map_properties branch 2 times, most recently from 5a3869a to 6dd283e Compare October 12, 2025 07:02
@soburi soburi force-pushed the dt_map_properties branch from 6dd283e to 163e905 Compare October 13, 2025 04:37
@soburi soburi requested a review from rruuaanng October 13, 2025 06:01
@soburi soburi force-pushed the dt_map_properties branch from 163e905 to d973109 Compare October 13, 2025 10:27
Copy link
Contributor

@rruuaanng rruuaanng Oct 13, 2025

Choose a reason for hiding this comment

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

I noticed that in this file, some macros that require entry_idx include xxx_BY_IDX in their names, while others don't. They take the same parameters, but the suffixes used are not consistent, I think it would be better to make this consistent, e.g.:

#define DT_MAP_ENTRY_CHILD_ADDRESS_LEN(node_id, prop, entry_idx)                                   \
	DT_CAT6(node_id, _P_, prop, _MAP_ENTRY_, entry_idx, _CHILD_ADDRESS_LEN)

#define DT_MAP_HAS_ENTRY_BY_IDX(node_id, prop, entry_idx)                                          \
	IS_ENABLED(DT_CAT6(node_id, _P_, prop, _MAP_ENTRY_, entry_idx, _EXISTS))

And, it seems that when using these macros, you have to specify entry_idx even when it's 0. Therefore, I suggest adding wrapper macros similar to the existing ones, e.g.:

#define DT_REG_SIZE(node_id) DT_REG_SIZE_BY_IDX(node_id, 0)

#define DT_IRQ_HAS_CELL(node_id, cell) DT_IRQ_HAS_CELL_AT_IDX(node_id, 0, cell)

WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is done to prevent BY_IDX for map entries and
BY_IDX for lists of child/parent specifiers to appear simultaneously.
IMO, since "two-dimensional arrays" have not existed in devicetree until now,
applying the rules as is would make the code more difficult to read.

Copy link
Member Author

Choose a reason for hiding this comment

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

And, it seems that when using these macros, you have to specify entry_idx even when it's 0. Therefore, I suggest adding wrapper macros similar to the existing ones, e.g.:

This has also been addressed.

@rruuaanng
Copy link
Contributor

Looks good, let's be patient, we are almost done :)

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

For `*-map` properties are made able to be treated as a variation
of phandle-array, assign sequential cell names for each group of
specifiers (child_specifier_0, child_specifier_1, ...,
parent_specifier_0, ...).

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 <[email protected]>
Add a map property test for `test_edtlib.py`.

Signed-off-by: TOKITA Hiroshi <[email protected]>
Add tests for map property related macros.

Add `native_sim/native/64` to allowed platforms.

Signed-off-by: TOKITA Hiroshi <[email protected]>
@soburi soburi force-pushed the dt_map_properties branch from d973109 to 6974b3c Compare October 14, 2025 12:07
Copy link

@soburi soburi requested a review from rruuaanng October 14, 2025 20:51
@soburi
Copy link
Member Author

soburi commented Oct 15, 2025

@mbolivar

Update done.
Could you take a look, again?

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.

4 participants