-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
drivers: Add external address translation module and TI RAT support #60028
drivers: Add external address translation module and TI RAT support #60028
Conversation
9262ce7
to
8fd98a7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is the way we should go.
Either we fix / adapt the current system_mm
API and we add a new RAT driver using this API so that we can simply use sys_mm_drv_map_region()
in device_mmio.h
or we add an entirely new class for this use-case, outside the system_mm
API (and directories).
@dcpleung the system_mm
is a bit of an odd-ball, is this a use case that you envisioned for this API?
I am not sure, does RAT play a role like an SMMU but based on Regions? |
RAT is a TI specific module that a few TI SoCs require to be able to access peripherals due to the change in bus size from a 48 bit SoC address to a 32 bit local address (for example in the Cortex M4F in the AM62X SoC). |
So, it translates the accesses from the core to the peripherals, right? The initiator is still core? Like, add another region based translation layer under MMU/MPU? |
Yes, but this must me somehow integrated into our current MMIO API. Also, we could do that but we do not currently have a proper MMU/MPU API so that should be again some custom / soc-specific code so I was wondering whether we could instead leverage the |
The initiator is the core, yes. However, the main requirement in the case of RAT is being able to get a certain local address when given a physical address using the mapping function. "It translates a 32-bit input address into a 48-bit output address. Any input transaction that starts inside of a programmed region will have its address translated, if the region is enabled." -> This is from the TRM linked in the commit here. It works on a transaction basis, and hence, a function like |
Thank you, I got it now. |
My only concern is, if there will be an issue when this RAT and MMU exist at the same time? And will RAT be configured dynamically? I mean configuring it at runtime, mapping the same 32-bit address to 2 devices alternatively? |
That API is for interfacing with external MMU/MPU-like hardware that is not architecture specific (e.g. MMU/MPU for ARM and x86). |
So I guess it is a good match for the RAT then? |
Hm... from what I can skim through the doc... for example, K3 is based on Cortex-R5, which has MPU. How would the RAT module and MPU work together? Unless you add a Correct me if I am wrong (as I have only skimmed through the doc), RAT module seems like a limited scope MMU where you can map some (limited) memory region to another memory region (so... "translating" the address from one to another). However, there is no access control, and this is pure address translation. It would help to know what kind of use cases are out there, which would help us to review this. |
Possibly... I would like to see use cases to help me understand the bigger picture. |
@dcpleung @povergoing @carlocaione , Thank you for the review, feedback, adding some notes to address your questions:
RAT will be primarily be used by the M4 cores in the K3 SoCs where there is no MMU available, but from a hardware perspective the R5 in these devices which has MPU can also make use of RAT, but there is no use case where both MPU/MMU and RAT is configured at same time and we would like to support use cases where RAT is enabled independently like for M4. From hardware perspective dynamic reconfiguration of RAT is possible, but again this is also not a valid use case we have seen in the past.
Just clarifying a few pieces, your description is correct, RAT can be thought of as a limited scope MMU which performs only address translation. This FAQ also describes the primary use cases with RAT : https://e2e.ti.com/support/processors-group/processors/f/processors-forum/1192281/faq-am62x-am64x-updating-the-region-based-address-translation-rat-settings Looking at the system_mm description you and @carlocaione provided and https://github.com/zephyrproject-rtos/zephyr/blob/main/include/zephyr/drivers/mm/system_mm.h#L12 , it seems like that is where the RAT implementation belongs, please let us know if the understanding is correct. |
In my opinion (not sure what @dcpleung thinks) but you can use the |
It would be great if you can make it work with the existing |
b5b0fc9
to
f71f706
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, properly squash the commits.
@carlocaione Apologies, I pushed the new files from my local system without squashing, hence the multiple changes in files created in this commit. Will rebase and push. |
f71f706
to
0943a6d
Compare
I have made the changes to use the system_mm API, and this implementation should be functional. It is all in one commit as there is no extension to an API now. @carlocaione I will rebase and push a fix for the typedefs after implementing a workaround. Apologies for the previous commits. |
0943a6d
to
3ff40d6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this file select KERNEL_VM_SUPPORT
should be moved out of menuconfig
now?
@@ -101,8 +105,11 @@ static inline void device_map(mm_reg_t *virt_addr, uintptr_t phys_addr, | |||
#else | |||
ARG_UNUSED(size); | |||
ARG_UNUSED(flags); | |||
|
|||
#ifdef CONFIG_EXTERNAL_ADDRESS_TRANSLATION | |||
sys_mm_drv_page_phys_get((void *) phys_addr, virt_addr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no objection to this since this is the only use case for now?
Just raise my concern for the future as this is a system API:
- MMU/MPU and RAT (or alternative technologies) exist at the same time which is hard to handle.
- Suppose we remove the exclusive macro (like
z_phys_map
firstly, and thensys_mm_drv_page_phys_get
, it's still annoying that if we want to remap RAT only, however, we inevitably call MMU remap again. - How do we deal with similar techniques like Arm ATU?
Fortunately, we could think about it later. MMU and RAT existing simultaneously seem like a 2 stage translation which is definitely a tricky thing.
3ff40d6
to
ccca323
Compare
ccca323
to
78ee739
Compare
78ee739
to
814565f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a couple of minor comments.
Added Region based Address Translation (RAT) module driver. Required by a few Texas Instruments SoCs to fucntion. Uses sys_mm_drv_page_phys_get() API with device_map() for address translation. Signed-off-by: L Lakshmanan <l-lakshmanan@ti.com>
814565f
to
90e654d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @KarthikL1729!
Congratulations on getting your very first Zephyr pull request merged 🎉🥳. This is a fantastic achievement, and we're thrilled to have you as part of our community!
To celebrate this milestone and showcase your contribution, we'd love to award you the Zephyr Technical Contributor badge. If you're interested, please claim your badge by filling out this form: Claim Your Zephyr Badge.
Thank you for your valuable input, and we look forward to seeing more of your contributions in the future! 🪁
This PR adds support for external address translation modules by using the
sys_mm_drv_page_phys_get()
function in the system_mm API. Texas Instruments SoCs (specifically the K3 family) require a Region based Address Translation (RAT) module to be able to access peripherals such as UART, and this PR includes the driver for RAT as well, which utilises the aforementioned API.Signed off by: l-lakshmanan@ti.com