Skip to content

Conversation

@glneo
Copy link
Contributor

@glneo glneo commented Mar 18, 2024

The only difference is the DMA ops, which the generic ops turns into simple cache operation which zephyr does support.

@arnopo arnopo requested review from arnopo, edmooring and tnmysh April 2, 2024 08:26
@arnopo
Copy link
Contributor

arnopo commented Apr 2, 2024

Code around metal_generic_dev_xxx is quite old and odd
As you mention map/unmap operation in zephyr is not supported. So seems better to having a structure that points to the ops. Except if you see a blocking point that would require this update...

@glneo
Copy link
Contributor Author

glneo commented Apr 2, 2024

No blocking point, this was just a general cleanup I noticed while fixing other things.

I still think this is valid though, the default handler does work for Zephyr as it just assumes a 1:1 mapping. And the default does the memory fences and cache operations one would expect. Having this set as NULL causes the functions to just return -ENODEV instead.

Zephyr could support an actual implementation of this function, but maybe a better question first, why is metal_dma_(un)map() needed at all? Baremetal and RTOS will almost never have non-1:1 memory mapping, and any caching can be done with metal_cache_*(). HLOS will not allow this from userspace. So in both cases this will always be a NOP. And I see no users of these functions, maybe time to start the process to deprecate these out?

@arnopo
Copy link
Contributor

arnopo commented Apr 5, 2024

No blocking point, this was just a general cleanup I noticed while fixing other things.

I still think this is valid though, the default handler does work for Zephyr as it just assumes a 1:1 mapping. And the default does the memory fences and cache operations one would expect. Having this set as NULL causes the functions to just return -ENODEV instead.

I think it is ok to return -ENODEV as calling in such case metal_dma_map does not make sense.

Zephyr could support an actual implementation of this function, but maybe a better question first, why is metal_dma_(un)map() needed at all? Baremetal and RTOS will almost never have non-1:1 memory mapping, and any caching can be done with metal_cache_*(). HLOS will not allow this from userspace. So in both cases this will always be a NOP. And I see no users of these functions, maybe time to start the process to deprecate these out?

The support of the Linux userspace makes the libmetal quite complexe. This is an example: the map unmap is used here https://github.com/OpenAMP/libmetal/blob/main/lib/system/linux/device.c#L537

Apply here a deprecation process seems not simple here. We would have to put a warning in the release to inform user on a risk for cachable memory.

@tnmysh @edmooring any opinion?

@tnmysh
Copy link
Collaborator

tnmysh commented May 17, 2024

No blocking point, this was just a general cleanup I noticed while fixing other things.
I still think this is valid though, the default handler does work for Zephyr as it just assumes a 1:1 mapping. And the default does the memory fences and cache operations one would expect. Having this set as NULL causes the functions to just return -ENODEV instead.

I think it is ok to return -ENODEV as calling in such case metal_dma_map does not make sense.

Zephyr could support an actual implementation of this function, but maybe a better question first, why is metal_dma_(un)map() needed at all? Baremetal and RTOS will almost never have non-1:1 memory mapping, and any caching can be done with metal_cache_*(). HLOS will not allow this from userspace. So in both cases this will always be a NOP. And I see no users of these functions, maybe time to start the process to deprecate these out?

The support of the Linux userspace makes the libmetal quite complexe. This is an example: the map unmap is used here https://github.com/OpenAMP/libmetal/blob/main/lib/system/linux/device.c#L537

Apply here a deprecation process seems not simple here. We would have to put a warning in the release to inform user on a risk for cachable memory.

@tnmysh @edmooring any opinion?

Agree with Arnaud.

@edmooring
Copy link
Contributor

No blocking point, this was just a general cleanup I noticed while fixing other things.
I still think this is valid though, the default handler does work for Zephyr as it just assumes a 1:1 mapping. And the default does the memory fences and cache operations one would expect. Having this set as NULL causes the functions to just return -ENODEV instead.

I think it is ok to return -ENODEV as calling in such case metal_dma_map does not make sense.

Zephyr could support an actual implementation of this function, but maybe a better question first, why is metal_dma_(un)map() needed at all? Baremetal and RTOS will almost never have non-1:1 memory mapping, and any caching can be done with metal_cache_*(). HLOS will not allow this from userspace. So in both cases this will always be a NOP. And I see no users of these functions, maybe time to start the process to deprecate these out?

The support of the Linux userspace makes the libmetal quite complexe. This is an example: the map unmap is used here https://github.com/OpenAMP/libmetal/blob/main/lib/system/linux/device.c#L537

Apply here a deprecation process seems not simple here. We would have to put a warning in the release to inform user on a risk for cachable memory.

@tnmysh @edmooring any opinion?

Agreed. We are between a rock and a hard place because of the demands of supporting Linux user space. It may be that the kernel's support for userspace drivers has advanced enough in the 8 years since libmetal was originally implemented that there is a simpler way now, but that is far out of the scope of what this PR is doing.

Copy link
Contributor

@edmooring edmooring left a comment

Choose a reason for hiding this comment

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

This looks good to go.

@github-actions
Copy link

This pull request has been marked as a stale pull request because it has been open (more than) 45 days with no activity.

@github-actions github-actions bot added the Stale label Aug 13, 2024
The only difference is the DMA ops, which the generic ops turns into
simple cache operation which zephyr does support.

Signed-off-by: Andrew Davis <afd@ti.com>
@arnopo arnopo requested a review from edmooring June 20, 2025 08:12
@arnopo
Copy link
Contributor

arnopo commented Jun 20, 2025

Hi @glneo,

Sorry for the delay...

Reviewing this PR i still not convince of the benefit. Look to me that it just introduces opacity by defining dev_dma_map/unmap ops, with associated useless extra footprint (even if low).

@tnmysh, @edmooring , could you have a look?

@tnmysh
Copy link
Collaborator

tnmysh commented Jun 20, 2025

If we don't have a real user that actually needs dma_map/unmap ops, then it makes sense not to introduce them. User can override them as needed in their respective application.

@glneo
Copy link
Contributor Author

glneo commented Jun 20, 2025

It is useless, yes, but so is all the metal_generic_dev_xxx() and metal_shmem_xxx() APIs for all users outside of that one Linux userspace demo.

Plan is to chip away at this, maybe move the bits needed for that Linux userspace demo into that demo and out of libmetal. But I'm taking it one bit at a time (unless you want to me to rip that all out in one go, I don't mind either way).

@tnmysh
Copy link
Collaborator

tnmysh commented Jun 20, 2025

It is useless, yes, but so is all the metal_generic_dev_xxx() and metal_shmem_xxx() APIs for all users outside of that one Linux userspace demo.

Plan is to chip away at this, maybe move the bits needed for that Linux userspace demo into that demo and out of libmetal. But I'm taking it one bit at a time (unless you want to me to rip that all out in one go, I don't mind either way).

Instead of ripping things out it should be possible to provide compile time switch(es) to get what's needed for open-amp and keep rest of it as it is so it doesn't break backward compatibility.

@github-actions github-actions bot removed the Stale label Jun 21, 2025
@glneo
Copy link
Contributor Author

glneo commented Jul 31, 2025

Instead of ripping things out it should be possible to provide compile time switch(es) to get what's needed for open-amp and keep rest of it as it is so it doesn't break backward compatibility.

For anything that would change backwards compat I will follow the usual deprecation processes. For this series that is not an issue as the behavior is not changed.

@github-actions
Copy link

This pull request has been marked as a stale pull request because it has been open (more than) 45 days with no activity.

@github-actions github-actions bot added the Stale label Sep 15, 2025
@glneo
Copy link
Contributor Author

glneo commented Sep 15, 2025

Not stale.

@tnmysh
Copy link
Collaborator

tnmysh commented Sep 15, 2025

@glneo Is there active user or example where metal_dma_(un)map() are used via metal device in zephyr?

@github-actions github-actions bot removed the Stale label Sep 16, 2025
@glneo
Copy link
Contributor Author

glneo commented Sep 17, 2025

There can't be any users on Zephyr right now as calling metal_dma_map() would fail with ENODEV, that is what this series fixes.

@tnmysh
Copy link
Collaborator

tnmysh commented Sep 26, 2025

@glneo ,

We don't expect libmetal bus usage a lot on zephyr. As usually zephyr has its own device structure. And so it is preferred to use zephyr device over metal device and metal bus. In my opinion we can keep this PR open until we see actual requirement. Feel free to link a use case where default ops are overridden and dma ops are assigned. Others can ack and merge this PR if they see fit.

@glneo
Copy link
Contributor Author

glneo commented Sep 30, 2025

I agree with you, it is not used, neither as it is now, or with the default ops, it will not be used, it is dead code, hence this PR removing it. And yes when this struct is removed it will fall back to a different set of code that will also never be used in Zephyr. Stating that this is never used so it cannot be removed does not make sense to me.

@tnmysh
Copy link
Collaborator

tnmysh commented Sep 30, 2025

@glneo , only problem is it will contribute to increase in final binary size of libmetal because now dma-ops are included that will never be used. So it's better to keep the code in place and having less binary size than to remove the code and increase the binary size. @arnopo has raised the same concern as well.

@github-actions
Copy link

This pull request has been marked as a stale pull request because it has been open (more than) 45 days with no activity.

@github-actions github-actions bot added the Stale label Nov 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants