Skip to content
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: sam: update sama7g5 configurations for wakeup from low-power #6831

Merged
merged 5 commits into from
May 28, 2024

Conversation

TonyHan11
Copy link
Contributor

No description provided.

* configure regions with write permission with not forced to
* XN (Execute-never) attribute.
*/
if (read_id_pfr1() & GENMASK_32(15, 12))
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add and use proper defines for both the mask and the bit below.

Copy link
Contributor

Choose a reason for hiding this comment

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

Where do you restore the XN bit?

@@ -395,7 +395,7 @@ static TEE_Result at91_pm_sram_init(const void *fdt)
at91_suspend_sram_pbase = virt_to_phys((void *)at91_suspend_sram_base);

/* Map the secure ram suspend code to be executable */
Copy link
Contributor

Choose a reason for hiding this comment

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

Please update this comment to match what you're doing.

Copy link
Contributor

Choose a reason for hiding this comment

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

This comment is not addressed.

@@ -236,6 +236,7 @@ static int at91_pm_config_ws_ulp1(bool set)
*/
static bool at91_pm_verify_clocks(void)
{
int pck_cnt = 4;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add and use an AT91_PMC_PKC_COUNT define depending on CFG_SAMA7G5 instead of using magic numbers here.

@TonyHan11
Copy link
Contributor Author

Thank you @jenswi-linaro . Code & commit message updated according to the comments.

@@ -298,6 +311,7 @@ static TEE_Result at91_enter_backup(void)
TEE_Result atmel_pm_suspend(uintptr_t entry, struct sm_nsec_ctx *nsec)
{
TEE_Result res = TEE_ERROR_GENERIC;
int sctlr = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be of an unsigned type, either uint32_t or perhaps unsigned long.

* configure regions with write permission with not forced to
* XN (Execute-never) attribute.
*/
if (read_id_pfr1() & IDPFR1_VIRT_MASK) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't it make sense to read SCTLR and if SCTLR_WXN is set clear it, regardless of ID_PFR1?
The bit is reserved as 0 if not supported.

*/
if (read_id_pfr1() & IDPFR1_VIRT_MASK) {
sctlr = read_sctlr();
write_sctlr(sctlr & ~SCTLR_WXN);
Copy link
Contributor

Choose a reason for hiding this comment

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

From the Arm ARM it looks like you need to invalidate the TLB also.

if (soc_pm.mode == AT91_PM_BACKUP) {
res = at91_enter_backup();
} else {
at91_suspend_sram_fn(&soc_pm);
res = TEE_SUCCESS;
}

/* Restore the XN attribute */
if (read_id_pfr1() & IDPFR1_VIRT_MASK)
Copy link
Contributor

Choose a reason for hiding this comment

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

How about checking if SCTLR_WXN is set in the sctlr variable and only write it then?
I believe the TLB should be invalidated if SCTLR_WXN is changed in SCTLR here too.

@@ -395,7 +395,7 @@ static TEE_Result at91_pm_sram_init(const void *fdt)
at91_suspend_sram_pbase = virt_to_phys((void *)at91_suspend_sram_base);

/* Map the secure ram suspend code to be executable */
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment is not addressed.

@TonyHan11
Copy link
Contributor Author

Updated according to the comments, thank you.

Copy link
Contributor

@jenswi-linaro jenswi-linaro left a comment

Choose a reason for hiding this comment

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

Acked-by: Jens Wiklander <jens.wiklander@linaro.org>

sctlr = read_sctlr();
if (sctlr & SCTLR_WXN) {
write_sctlr(sctlr & ~SCTLR_WXN);
tlbi_all();
Copy link
Contributor

Choose a reason for hiding this comment

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

Given that we restore the WXN bit below without changing ASID we could optimize this by using tlbi_asid() with the current ASID instead. But it may be useless depending on what the CPU does with the TLB during suspend, I leave it to you to decide if it's worth the effort.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rebased with the review tags added and thank you for you suggestion. Currently we do not consider about the ASID and just use tlbi_all() as the simplest way to make it work.

Configure regions with write permission with not forced to
XN (Execute-never) attribute when implementation includes
the Virtualization Extensions.

Signed-off-by: Tony Han <tony.han@microchip.com>
Acked-by: Jens Wiklander <jens.wiklander@linaro.org>
Mapping with memory area type MEM_AREA_TEE_RAM would enable cacheable
attribute, it might cause abort in same cases. Here change the memory
area type to MEM_AREA_TEE_COHERENT to map SRAM with non-cacheable
attribute to avoid the aborts in the low-power process.

Signed-off-by: Tony Han <tony.han@microchip.com>
Acked-by: Jens Wiklander <jens.wiklander@linaro.org>
Rename the names of functions for adding the configuration of sama7g5
wakeup sources.
Add and configure the wakeup sources for sama7g5.

Signed-off-by: Tony Han <tony.han@microchip.com>
Acked-by: Jens Wiklander <jens.wiklander@linaro.org>
Add definition "AT91_PMC_PCK_COUNT", in sama7g5 there're 8 PCK clocks
and for sama5d2 there're 4 PCK clocks.

Signed-off-by: Tony Han <tony.han@microchip.com>
Acked-by: Jens Wiklander <jens.wiklander@linaro.org>
The offset of "PMC CPU Clock Register" for sama7g5 is different from
the one for sama5d2.

Signed-off-by: Tony Han <tony.han@microchip.com>
Acked-by: Jens Wiklander <jens.wiklander@linaro.org>
@jforissier jforissier merged commit 6b82794 into OP-TEE:master May 28, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants