-
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
RTC: add basic RTC support in OP-TEE #5179
Conversation
d59cf83
to
335bc00
Compare
New version:
|
core/pta/rtc.c
Outdated
if (!time) | ||
return TEE_ERROR_BAD_PARAMETERS; | ||
|
||
rtc_set_time(time); |
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.
What happens if the info in time
doesn't make sense?
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.
It actually depends on the driver. The AT91 RTC will actually return an error while programming it. Maybe I could add a sanity check to at least avoid total non sense but it will probably be a bit difficult (leap year, february duration and so on)
a9267ad
to
b3d791c
Compare
New version:
|
lib/libutee/include/rtc_pta_client.h
Outdated
/* | ||
* PTA_CMD_RTC_SET_OFFSET - Set RTC offset | ||
* | ||
* param[0] (in value) - value.a: RTC offset to be set |
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.
Can the offset be negative?
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.
Yes the offset can be negative.
core/pta/rtc.c
Outdated
return TEE_ERROR_BAD_PARAMETERS; | ||
} | ||
|
||
rtc_set_offset(params[0].value.a); |
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.
Since an offset can be negative I suppose that even though the value is a uint32_t
it should be casted into a int32_t
in order to be properly upgraded to a long
on 64bit platforms.
New version:
|
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.
Some comments. The API looks good to me, only some descriptions are missing.
As for file rtc_pta_client.h. most PTA header file (where their API/ABI is defined) are named pta_foo.h. Prefer renaming it to pta_rtc.h?
I named it after the rng pta one which is name Edit: But since all others are named differently, I will rename it |
New version:
|
New version:
|
Also, renamed |
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 @clementleger, I though I posted some comments but they were still drafts. Here there are. Only minor comments.
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.
The ability the set date and offset is opened to any client application invoking the PTA. I wonder if should there be some identification passed to restrict such accesses upon 'root' or like login identification?
lib/libutee/include/pta_rtc.h
Outdated
uint32_t tm_mon; | ||
uint32_t tm_year; | ||
uint32_t tm_wday; | ||
} __packed; |
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.
is __packed
needed? I remember @jenswi-linaro worrying about such useless attribute.
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.
No, it's not needed since both OP-TEE and the OS runs on the same platform. I added them because I was asked to on some other PR which add the same kind of communication pattern.
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.
Will wait for @jenswi-linaro answer before removing them.
Hum I'm not sure how I could do that properly. Do you have any example that I could look at if needed ? |
On Linux side, we can see 2 ways to set the RTC data. Either using a kernel driver plugged to /dev/rtc* standard tools or an application that would straight invoke the PTA. |
Ok great, thanks for the explanations ! I already have a kernel driver for that RTC curently using |
New version:
|
New version:
|
|
New version:
|
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.
Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org>
for commits
"drivers: rtc: add RTC API"
"pta: add PTA for RTC"
Acked-by: Etienne Carriere <etienne.carriere@linaro.org>
for commits:
"driver: atmel_rtc: add driver for atmel RTC" (with minor comment)
"dts: sama5d2: set RTC as secure"
"plat-sam: enable RTC support"
core/drivers/atmel_rtc.c
Outdated
static struct rtc atmel_rtc = { | ||
.ops = &atmel_rtc_ops, | ||
.range_min = {1900, 1, 1, 0, 0, 0, 0}, | ||
.range_max = {2099, 12, 31, 23, 59, 59, 0}, |
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.
minor: add space char in braces:
.range_min = { 1900, 1, 1, 0, 0, 0, 0 },
.range_max = { 2099, 12, 31, 23, 59, 59, 0 },
This API allows to interact with a RTC registered as the system RTC. Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org> Acked-by: Jens Wiklander <jens.wiklander@linaro.org> Signed-off-by: Clément Léger <clement.leger@bootlin.com>
On some systems, when the RTC is secured, there is no way for the normal world to access it. This PTA uses the RTC API to allow a Linux OP-TEE based RTC driver to communicate with the RTC that is secured. Reviewed-by: Etienne Carriere <etienne.carriere@linaro.org> Acked-by: Jens Wiklander <jens.wiklander@linaro.org> Signed-off-by: Clément Léger <clement.leger@bootlin.com>
On sama5d2, the RTC is included in a larger block of devices that can only be secured as a whole (RSTC, WDT, etc). Since these other peripherals needs to be secured, in order to still allow the RTC to be used from non-secure world, add a driver for the RTC which will be registered as the system RTC. The RTc PTA will then used this RTC to set/get time from Linux using a RTC driver that uses the TEE subsystem. Acked-by: Etienne Carriere <etienne.carriere@linaro.org> Acked-by: Jens Wiklander <jens.wiklander@linaro.org> Signed-off-by: Clément Léger <clement.leger@bootlin.com>
The RTC on sama5d2 is actually securing both RSTC, WDT and RTC register access. Enable secure mode for the RTC to ensure the WDT register accesses are secured. Acked-by: Etienne Carriere <etienne.carriere@linaro.org> Acked-by: Jens Wiklander <jens.wiklander@linaro.org> Signed-off-by: Clément Léger <clement.leger@bootlin.com>
Enable RTC API, RTC PTA and Atmel RTC driver for sama5d2. Acked-by: Etienne Carriere <etienne.carriere@linaro.org> Acked-by: Jens Wiklander <jens.wiklander@linaro.org> Signed-off-by: Clément Léger <clement.leger@bootlin.com>
New version:
|
@clementleger thanks! |
This drivers allows to communicate with a RTC PTA handled by OP-TEE [1]. This PTA allows to query RTC information, set/get time and set/get offset depending on the supported features. [1] OP-TEE/optee_os#5179 Signed-off-by: Clément Léger <clement.leger@bootlin.com>
This drivers allows to communicate with a RTC PTA handled by OP-TEE [1]. This PTA allows to query RTC information, set/get time and set/get offset depending on the supported features. [1] OP-TEE/optee_os#5179 Signed-off-by: Clément Léger <clement.leger@bootlin.com>
This drivers allows to communicate with a RTC PTA handled by OP-TEE [1]. This PTA allows to query RTC information, set/get time and set/get offset depending on the supported features. [1] OP-TEE/optee_os#5179 Signed-off-by: Clément Léger <clement.leger@bootlin.com> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Link: https://lore.kernel.org/r/20220308133505.471601-1-clement.leger@bootlin.com
This drivers allows to communicate with a RTC PTA handled by OP-TEE [1]. This PTA allows to query RTC information, set/get time and set/get offset depending on the supported features. [1] OP-TEE/optee_os#5179 Signed-off-by: Clément Léger <clement.leger@bootlin.com> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Link: https://lore.kernel.org/r/20220308133505.471601-1-clement.leger@bootlin.com (cherry picked from commit 81c2f05) Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com>
This drivers allows to communicate with a RTC PTA handled by OP-TEE [1]. This PTA allows to query RTC information, set/get time and set/get offset depending on the supported features. [1] OP-TEE/optee_os#5179 Signed-off-by: Clément Léger <clement.leger@bootlin.com> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Link: https://lore.kernel.org/r/20220308133505.471601-1-clement.leger@bootlin.com (cherry picked from commit 81c2f05) Signed-off-by: Tudor Ambarus <tudor.ambarus@microchip.com> Signed-off-by: Isaac True <isaac.true@canonical.com>
This PR adds support for the following:
On sama5d2, the RTC is contained in a SYS peripheral group which contains the WDT, the RSTC, the PIT and the RTC. This group can only be set secure as a whole and if doing so, the RTC won't be accessible anymore by the non-secure world. This PR adds support to expose the RTC through a PTA which will allow to communicate with a non-secure world driver (see [1]).
[1] (clementleger/linux@78c118b)