-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Requirements for driver devices generation using device tree #10904
Comments
@galak , @carlescufi, @mbolivar, @MaureenHelm, @nashif, feel free editing these lines. |
@b0661 mentioned use for out of tree drivers, so wondering what requirements that drives |
One template file per driver .c file (if I have, |
Should be standalone from Zephyr (usable by other projects). |
Performance of rendering (Are we invoking python once for all files that need to be rendered or per file)? |
Once per file in parallel. Note that this has already been implemented. |
Thanks, updated the description now |
This is complex. |
Added information about driver <> compatible binding: |
EDTS should be decoupled from extract_dts_includes.py. It should have it´s own extraction function that directly extracts from the compiled DTS file (see #10885). Benefit:
|
Must be detailed. 'compatible' is the same for all instances of a device.
|
Does that mean:
|
These are rules how to structure a driver. Code generation should not be restricted to this model. Code genration should be versatile and generate any file type (not only *.h.in -> *.h). |
Template faults shall be easy to debug with a clear indication of the fault location in the template. |
Excluding a major set of known use cases from the requirments analysis is the wrong method. By this you do not identify the shortcomings of the tools. In a tool evaluation you still may decide to use the tool just because you are only targeting the limited scope - but then you know about the implications. The use cases I ran in so far:
The requirements will only cover the last use case. Shortcomings or possible solutions for the first 3 will not be identified. |
I don't get this requirement. Have there been actual real interest from other projects to reuse what's being done by @b0661 and @erwango ? (This is something deeply tied to zephyr, making it "generic" will just add-up a big amount of work). |
@b0661 so are you saying that these usecases are not covered by the requirements because we will need code generation inside the |
We are trying to limit the scope here, solving one problem at a time to try and make progress. Code generation itself is limitless, but we do want to try and work on a subset of issues that we need to fix now. All of the code generation options proposed are flexible enough in the end to generate any file types. |
@galak I've removed the "should be standalone" requirement because it's not clear what exactly you mean by that, as pointed out by several people on this thread. |
Yes, there's real interesting other projects like the TFM (https://www.trustedfirmware.org/). The CMake integration is obviously going to be Zephyr specific, but going from a set of YAML files & dts, plus whatever template generation solution should be able to be used by any project. |
So what I think we are a missing is a different issue where we can discuss high level requirements for code generation in general. Because some of the statements in this issue is very generic while others are very concrete/specific to the driver instantiation use-case. To avoid that the high level requirements diverges between different code generation use-case discussion, all of these discussions should refer to this high level issue. |
No, I don´t say that. For the C compiler it is regardless where the C code comes from. The way you are forcing *.h files is just a matter of taste no technical requirement. What I´m saying is that by restricting the scope before elaborating requirement makes you miss the requirements that are related to the use cases that you left out because of the restriction. |
My purpose is how do we establish the list of devices (or instances of device) that should be generated against a particular driver template. In Linux, the equivalent operation is done using 'compatible' field at run time. Even if we're doing this operation at pre-compilation, we should use the same approach. |
For device_get_binding you always have to use the 'compatible' property. The question is how do you identify a specific instance of a device type (e.g. UART0 of all the UARTs of a SOC that are of the same type and therefor have the same 'compatible')? I propose to use the 'label' property to identify a specific instance of a device type - would be 'UART0' in the example above. The 'compatible' does not provide an unique identification because it is shared by all device instances of the same type. The 'label' should be unique for a SOC device instance (no other device instance is called 'UART0' on the same SOC). So the 'label' alone is already unique and sufficient to identify the device instance. |
I haven't managed to make myself clear enough. You're raising another question. |
So lets make it clear:
|
I'm not thrilled with this use of the The specification does say "The binding specifies the exact meaning for the device", but Zephyr's YAML files all have no more than "(used by Zephyr for the API name)". I think we should use a different property, such as
to Second, I think each binding description should clearly document the format for the |
@pabigot , IIUC your recent comments, you changed your mind about use of binding-name. |
@erwango No, I didn't change my mind about |
It's very hard to see what the requirements are in this issue, but I think this one is missing: There are chips that provide features that are covered by multiple subsystem driver APIs. An example is the SX1509B IO extender, which is currently in Zephyr as a GPIO device, but also has an LED controller capability that appears to be compatible with PWM devices. The nrf52_pca20020 has LEDs that are normally driven through the extender. So:
Or an alternative solution to this problem must be proposed. This issue also arises wrt #12097 though there I prefer the opposite approach (single device instance that interacts with multiple nodes). At this time I expect to manage by using string token catenation in both the driver and the source, something like:
which is not sustainable. |
I think this is not about "multiple distinct device instances associated with a single node" but about a device that combines different "sub-devices" of different type. This can already be described by creating a sub-node for each sub-device. A combi-driver still can handle all the sub-devices. |
@b0661 example? In zephyr or in linux? Note that this might not naturally be thought of as multiple devices bundled into one IC. The PWM operations use the same IO signals as the GPIO, so using them in one blocks them from use in the other. |
Yes. If you blindly activate both you might have a clash. But there is the pinctrl-[x] directive to do fine grained control on the usage of pins. pinctrl-[x] should be used for the pin allocation in such situations. Linux does have the pin control subsystem where you can manage pin allocation and can detect such clashes at initialisation time or run time. Zephyr is currently missing it. My conclusion: DTS provides ways to manage the combi-devices. We should not invent our own way of DTS definition but extend Zephyr to handle it completely. |
Yes. So part of the requirements for extending Zephyr, which is the point of this issue, will be to identify what it means to handle it completely. The pin case might be handled if there were a plan beyond "we should" to support pinmux in Zephyr. What about a PMIC that provides battery voltage, for which the SENSOR api would be the way to provide it? Maybe we'd do something like:
Regardless of how it's expressed in the device tree, the tooling has to provide both the drivers and the application with information on named resources. I think there's a general concept of how to deal with "device on a bus" which is currently trending to "use aliases", but not for "apis within a device on a bus". I just want to make sure that gets handled. I don't (at this point) care how. |
The initial reason why I suggested code genereration was to enable pin control using DTS (for pin initialisation and during runtime). The "plan beyond "we should"" is already implemented and working but needs code generation to be upstream. |
Hi I would like to jump into the discussion just to be sure that this issue is also solving my problem or not. As Zephyr is moving everything to the DT then the kernel peripheral driver need to know if his peripheral is enabled or not. For example I have a 3x I2C peripherals so I write one driver which will initialize each peripheral if is is enabled in DT. However in current DT generation scheme (at 1.14.0) there is no stable define which I can use. DT is using relative indexing so when I enable only i2c-1 then the DT generate something like DT_I2C_0_xxxx . Currently there is only one partially stable point in the DT and that is DT_I2C_BASE_ADDRES_xyz however the peripheral address is not the same across various MCU from the same MCU series so it is more like workaround. Will this issue solve this problem or I should start new issue? |
@kubiaj, the issue you mention is common across various archs and socs, it is indeed taken into account. |
Hi, |
@erwango in this comment, I think you are saying you are not in favor of codegen anymore: Can you close this issue if that's right? |
Closing since the initial goals have been achieved (available in code base today). |
Aim of this issue is to settle on requirements for code generation solution that should be used to generate devices code for a driver configured by device tree. Most of the elements that will be listed here were discussed during OpenIoT 2018 in Edinburgh last week.
DEVICE_AND_API_INIT
macro.edts.json
directly in order to avoid reliance on the JSON formattingi2c_foo.c
file with the driver implementation (not used by the templating engine, here for completeness)i2c_foo_devices.h.in
with the templated device structures.i2c_foo_devices.h
inbuild/zephyr/drivers/<driver>/
i2c_foo.c
(#include i2c_foo_devices.h
)zephyr_library_sources_codegen_ifdef(CONFIG_I2C_STM32 i2c_ll_stm32.c)
ninja
timeNote:
While being targeted in the long term, pinmux generation using device tree input is not addressed here. It is likely this is one element of the discussion, but aim of the ticket is to sum up what we know/want on driver devices.
The text was updated successfully, but these errors were encountered: