-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
add get_base and get_io_base helper function #1570
Conversation
+1 |
Is the |
@jenswi-linaro Currently not. In my local repo, I use get_base for suspend/resume case, it could make code looks clean. You mean change the function name to core_mmu_get_base and core_mmu_get_io_base? |
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.
+1 with Jens' comment, core_mmu_
is a good prefix IMO.
I'm not sure about the word "base": what does it mean? Any address can be passed. It's not like you would return the base for some area given any address in the area (that's how it sounds to me). How about core_mmu_get_va(paddr_t pa)
and core_mmu_get_io_va(paddr_t pa)
?
Last thing: I am a bit reluctant to merge something that's not used yet. Because, sometimes we do some cleanup and we do remove unused code. So, I think these patches would be fine as part of a bigger series.
@@ -106,4 +106,9 @@ void *phys_to_virt_io(paddr_t pa); | |||
*/ | |||
paddr_t virt_to_phys(void *va); | |||
|
|||
/* | |||
* Return runtime usable address |
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.
"Return runtime usable address, irrespective of whether the MMU is enabled or not"
@@ -111,4 +111,9 @@ paddr_t virt_to_phys(void *va); | |||
*/ | |||
vaddr_t get_base(paddr_t base, enum teecore_memtypes type); | |||
|
|||
/* | |||
* Return runtime usable io address |
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.
"Return runtime usable io address, irrespective of whether the MMU is enabled or not. @base has to be in a memory area of type MEM_AREA_IO_SEC or MEM_AREA_IO_NSEC. Returns NULL on failure."
@jforissier Thanks for comments. I'll drop the get_base patch. the get_io_base will be used in my following up patch. |
@jenswi-linaro @jforissier Updated, drop the get_base code, rename get_io_base to core_mmu_get_io_va and use core_mmu_get_io_va to cleanup the imx code. |
Thanks @MrVan , looks good. |
|
/* | ||
* Return runtime usable io address | ||
*/ | ||
vaddr_t get_io_base(paddr_t base); |
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.
get_io_base seems ok for devices that may have a non secure status with any impact on the core behaviour. I.e uart-like console for debug.
I understand the get_base()
as it provides the target memtype hence to expected attributes.
Some core_mmu_aware_phys_to_virt().
with some shorter name :)
core/arch/arm/plat-imx/imx_pl310.c
Outdated
return (vaddr_t)va; | ||
} | ||
return PL310_BASE; | ||
return core_mmu_get_io_va(PL310_BASE); |
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 think we should assert pl310 is secure and use the memtype
way.
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 could not follow you about using memtype and assert pl310 is secure. the phys_to_virt_io will find the map in secure mapping, then non-secure if not found in secure.
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.
Ok, I did not look back few lines above. This source file does register the pl310 physical iomem range as MEM_AREA_IO_SEC
. So ok, not need to crosscheck this, as the previous implementation did by explicitly providing MEM_AREA_IO_SEC
type as argument.
But... I feel it is more simple to call core_mmu_get_va(PL310_BASE, MEM_AREA_IO_SEC);
. This is why I liked the previously proposed core_mmu_get_va()
: caller explicitly specific to required state.
More generally, I think the phys_to_virt_io()
api should be reserved to iomem for which the secure state does not really matter. @jforissier ?
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.
Another point. previous code used a local static storage for the va. Hence conversion is done only once.
With this change, phys_to_virt_io()
is called each time pl310 is used.
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.
@etienne-lms +1 with your statement: "phys_to_virt_io()
api should be reserved to iomem for which the secure state does not really matter", that's exactly the purpose of the function (otherwise use phys_to_virt()
), and in my mind it was the meaning of the "_io" suffix: it means "any of the _IO_
memtyptes (secure or non-secure)".
So, for consistency with this naming scheme, we should have core_mmu_get_io_va()
without a memtype parameter. And it's OK to use it here (imx_pl310.c
) since as you said above the mem range is registered secure above.
Now, I don't mind also having core_mmu_get_va(pa, type)
to complete the picture... but that can be added when needed.
core/arch/arm/plat-imx/main.c
Outdated
gicd_base = (vaddr_t)phys_to_virt(GIC_BASE + GICD_OFFSET, | ||
MEM_AREA_IO_SEC); | ||
gicc_base = core_mmu_get_io_va(GIC_BASE + GICC_OFFSET); | ||
gicd_base = core_mmu_get_io_va(GIC_BASE + GICD_OFFSET); |
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 feel we could insure gic is secure.
Some assert should check gic was mapped secure. may at gic inits.
(edited) from the discussions: Ok, here no need to assert GIC secure state registration. I will remove my comment.
core/arch/arm/plat-imx/psci.c
Outdated
int psci_cpu_on(uint32_t core_idx, uint32_t entry, | ||
uint32_t context_id __attribute__((unused))) | ||
{ | ||
uint32_t val; | ||
vaddr_t va = src_base(); | ||
vaddr_t va = core_mmu_get_io_va(SRC_BASE); |
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.
Same comment. I think you should at least assert somewhere that va is MEM_AREA_IO_SEC
. Or use the previously proposed core_mmu_get_va(paddr_t, enum memarea_type)
. Sound like a early_virt_to_phys()
.
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.
Complementary to discussions above, here register_phys_mem(SRC_BASE, ...);
is externally defined.
So if SRC_BASE
is really expected secure, this generic psci.c should at least assert the secure state of the target ram. If the secure state does not matter, then fine.
And same remark, why not simply call a generic core_mmu_get_va(SRC_BASE, MEM_AREA_IO_SEC)
?
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.
@etienne-lms ha! yes maybe here core_mmu_get_va(SRC_BASE, MEM_AREA_IO_SEC)
would be nice (if we want to check the secure state that is, I have no strong opinion on this).
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.
@etienne-lms I thought core_mmu_get_va_io is ok, but not take secure state into consideration. Then I may need to add back core_mmu_get_va. And use core_mmu_get_va.
@etienne-lms I updated the code with your comments addressed, using core_mmu_get_va. |
|
So we have |
@jforissier Updated with review tags applied. Thanks. |
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.
Frankly i don't like core_mmu_get_io_va()
. That's label buiness only but such sec-or-nonsec devices are, up to my experience, only supported on debug purpose. I would rather rename core_mmu_get_iodbg_va()
. And same for phys_to_virt_io().
so that's a separate P-R maybe. And that is only but labels.
@MrVan if you need core_mmu_get_io_va()
then include it in the P-R. If not, prefer don't include.
Fix needed in a comment.
* Return runtime usable io address, irrespective of whether | ||
* the MMU is enabled or not. | ||
* @base has to be in a memory area of type MEM_AREA_IO_SEC or | ||
* MEM_AREA_IO_NSEC. Returns NULL on failure. |
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.
base
should be pa
.
Suggestion for the description, inspired from from phys_to_virt_io()
)
- * @base has to be in a memory area of type MEM_AREA_IO_SEC or
- * MEM_AREA_IO_NSEC. Returns NULL on failure.
+ * Translate physical address to virtual address trying MEM_AREA_IO_SEC
+ * first then MEM_AREA_IO_NSEC if not found.
+ * Returns NULL on failure or a valid virtual address on success.
@etienne-lms The phys_to_virt_io is used by the uart functions. I do not want to change that in this patch set. I could drop it. |
Add core_mmu_get_va helper function. Signed-off-by: Peng Fan <peng.fan@nxp.com> Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org> Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org>
Use core_mmu_get_va to simplify the code. Signed-off-by: Peng Fan <peng.fan@nxp.com> Reviewed-by: Jerome Forissier <jerome.forissier@linaro.org> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org> Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
Updated with the get_io_va patch dropped, since not used by this patch set. |
Add get_base and get_io_base function helper function. These two functions are only to wrap phys_to_virt and phy_to_virt_io and add cpu_mmu_enabled checking.