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

arm: init CNTVOFF #2052

Merged
merged 1 commit into from
Jan 17, 2018
Merged

arm: init CNTVOFF #2052

merged 1 commit into from
Jan 17, 2018

Conversation

MrVan
Copy link
Contributor

@MrVan MrVan commented Jan 5, 2018

There is an property "arm,cpu-registers-not-fw-configured" in Linux side,
that could workaround the issue that firmare initialize CNTVOFF.

But if use that property, virtualization support will be break in linux.

Also without CNTVOFF or that property no defined, kernel could not
boot up on i.MX7D with two cores.

So we init CNTVOFF in OP-TEE to make kernel work well.

I did not find a better place to do this, so add it in sm_init and configure SCR.NS.

Signed-off-by: Peng Fan peng.fan@nxp.com

Copy link
Contributor

@etienne-lms etienne-lms left a comment

Choose a reason for hiding this comment

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

@igoropaniuk, is this init fine to you (applies to armv7 only) ?

* So test VIRT and GENTIMER Mask both here.
*/
read_idpfr1 r2
ands r2, r2, #(IDPFR1_GENTIMER_MASK | 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.

You need both ID_PFR1[generic timer] != 0 and ID_PFR1[virtualization extensions] != 0 to access the register, no?
The proposed test requires only 1 of them to be non null to init the register.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fix in next version.

* If the implementation includes the Virtualization Extensions
* this is a RW register, accessible from Hyp mode, and
* from Monitor mode when SCR.NS is set to 1.
* If the implementation includes the Security Extensions
Copy link
Contributor

Choose a reason for hiding this comment

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

here replace Security Extensions with Generic Timers?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This comments are directly from ARM architecture reference mannual. So keep Security extensions.

ands r2, r2, #(IDPFR1_GENTIMER_MASK | IDPFR1_VIRT_MASK)
movne r2, #0
/* Reset CNTVOFF to 0 */
mcrrne p15, 4, r2, r2, c14
Copy link
Contributor

Choose a reason for hiding this comment

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

Can be define a macro write_cntvoff from arm32_macros.S ? (comment a previous line would become redundant).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

mcrr could be used in write_cntvoff, but I am afraid mcrrne could not.

Copy link
Contributor

Choose a reason for hiding this comment

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

On the other hand, this isn't optimized code so we could perhaps bear the cost of a bne for the benefit of more readable code.

@MrVan MrVan force-pushed the cntvoff branch 2 times, most recently from cc93963 to d6d18d1 Compare January 12, 2018 09:54
@MrVan
Copy link
Contributor Author

MrVan commented Jan 12, 2018

@etienne-lms @jenswi-linaro Updated with adding write_cntvoff macro, only test generic timer mask and use beq.

@jenswi-linaro
Copy link
Contributor

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

* mode, regardless of the value of SCR.NS.
*/
read_idpfr1 r2
ands r2, r2, #IDPFR1_GENTIMER_MASK
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't you test also IDPFR1[virtualiation] ?

	read_idpfr1	r2
	ands		r2, r2, #IDPFR1_GENTIMER_MASK
+	andsne		r2, r2, #IDPFR1_VIRT_MASK
	beq		.no_gentimer
	mov		r2, #0
	write_cntvoff 	r2, r2

Copy link
Contributor Author

Choose a reason for hiding this comment

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

use this ands r2, r2, #(IDPFR1_GENTIMER_MASK | 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.

I think you need (r2 & (gentimer_flag | virt_flag)) == (gentimer_flag | virt_flag).
Is my proposal wrong? It should do:

	if (idpfr1[gentimer_flag] != 0 &&
	    idpfr1[virt_flag] != 0)
		write_cntvoff(0);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My mistake. You are right. Thanks.

#ifdef CFG_INIT_CNTVOFF
read_scr r0
orr r0, r0, #SCR_NS /* Set NS bit in SCR */
write_scr r0
Copy link
Contributor

Choose a reason for hiding this comment

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

Need an ISB after setting (and clearing) SCR[NS]?

Also, maybe use a sequence where we switch in non secure only if CNTVOFF is accessed. Yet, this is not a big issue: we're booting, no perf penalty...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ISB is needed. I'll add it.

@MrVan
Copy link
Contributor Author

MrVan commented Jan 15, 2018

@etienne-lms Updated with isb added after write_scr. Fix the IDPFR1_GENTIMER_MASK and IDPFR1_VIRT_MASK check with such logic:

+       read_idpfr1 r2
+       mov     r3, r2
+       ands    r3, r3, #IDPFR1_GENTIMER_MASK
+       beq     .no_gentimer
+       ands    r2, r2, #IDPFR1_VIRT_MASK
+       beq     .no_gentimer
+       mov     r2, #0
+       write_cntvoff r2, r2
+
+.no_gentimer:

Add @jenswi-linaro 's ack tag.

@jforissier
Copy link
Contributor

Please make the subject prefix: "arm32: sm: ...", since this applies to secure monitor only.
@etienne-lms ping
I will probably tag 3.0.0-rc1 today and I think this should go into the RC.

There is an property "arm,cpu-registers-not-fw-configured" in Linux side,
that could workaround the issue that firmare initialize CNTVOFF.

But if use that property, virtualization support will be break in linux.

Also without CNTVOFF or that property no defined, kernel could not
boot up on i.MX7D with two cores.

So we init CNTVOFF in OP-TEE to make kernel work well.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Acked-by: Jens Wiklander <jens.wiklander@linaro.org>
@MrVan
Copy link
Contributor Author

MrVan commented Jan 17, 2018

Updated with subject prefix "arm32: sm: xx"

@jforissier jforissier merged commit 5051b51 into OP-TEE:master Jan 17, 2018
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.

4 participants