I agree with the approach you suggest.
I planned to put the non-weak implementation in the same directory as spm_hal.c and target_cfg.c, etc. I’ll name the file “platform_svc_hal.c“ to reflect the common/platform_svc.c it is related to.
Alan
> On Oct 9, 2019, at 9:54 PM, Ken Liu (Arm Technology China) via TF-M <tf-m(a)lists.trustedfirmware.org> wrote:
>
> Well, I was trying to see the whole picture, but looks like they are platform specific and some part is not public.
>
> Back to focus the SVC proposal itself, the weak function looks well, can you considerate these:
>
> - Put the implementation of the weak function under: platform/ext/common/platform_svc.c?
>
> Before this, we need to:
>
> - Reserve a range for platform SVC, and let platform define it by themselves.
>
> The reason is:
>
> - These extended SVCs are from specific vendors, which means from specific platforms. So I think it is reasonable to put it into platform scope. Or do you think it is a common case out of platform scope?
>
> Thanks.
>
> /Ken
>
> -----Original Message-----
> From: DeMars, Alan <ademars(a)ti.com>
> Sent: Thursday, October 10, 2019 12:38 PM
> To: Ken Liu (Arm Technology China) <Ken.Liu(a)arm.com>
> Cc: tf-m(a)lists.trustedfirmware.org; nd <nd(a)arm.com>
> Subject: Re: [TF-M] [EXTERNAL] Re: augmenting the SVC_Handler_IPC() to support custom services
>
> I think I’ve already provided the changes I propose. The ‘default’ case will be for the SVC handler to invoke the provided weak defined function as shown. If a non-weak version of the function exists during the link process, the non-weak implementation will be invoked instead.
>
> My intent is to provide a proprietary non-weak implementation of “custom_ipc_svc_handlers()”.
>
> Alan
>
>> On Oct 9, 2019, at 9:22 PM, Ken Liu (Arm Technology China) via TF-M <tf-m(a)lists.trustedfirmware.org> wrote:
>>
>> Hi Alan,
>>
>> The example here is the worst case for APP RoT accessing the peripherals, so you are right with the latency issue in this case. In most cases, the service manipulating the secure hardware can be PSA RoT so they access the peripheral directly.
>>
>> I am curious about the requirements you are facing so I am eager to see the changes.
>>
>> Thanks.
>>
>> /Ken
>>
>>
>> -----Original Message-----
>> From: DeMars, Alan <ademars(a)ti.com>
>> Sent: Thursday, October 10, 2019 12:07 PM
>> To: Ken Liu (Arm Technology China) <Ken.Liu(a)arm.com>
>> Cc: tf-m(a)lists.trustedfirmware.org; nd <nd(a)arm.com>
>> Subject: Re: [EXTERNAL] Re: [TF-M] augmenting the SVC_Handler_IPC() to
>> support custom services
>>
>> Ken,
>>
>> If I understand the proposal, I’m afraid the latency and overhead associated with every peripheral register access (read or write) would be completely unacceptable for our requirements.
>>
>> Alan
>>
>>>> On Oct 9, 2019, at 8:47 PM, Ken Liu (Arm Technology China) via TF-M <tf-m(a)lists.trustedfirmware.org> wrote:
>>>
>>> Hi Alan,
>>>
>>> The secure service is allowed to access some peripherals they want (introduce them in the manifest file), which means if you want to access a I2C device you can just (ALL CODE HERE IS PSEUDO CODE AND IS NOT REAL):
>>>
>>> I2c_write (I2C_ADDR, SLAVE_ADDR, value);
>>>
>>> While:
>>> I2c_write(addr, value) { *host_reg_slave_addr = addr;
>>> *host_reg_slave_data = value; *host_reg_control_go = 1; }
>>>
>>> The reason of providing the SVC interface is because the APP RoT Service may want to access some registers but they could not because those registers may be set as privileged.
>>>
>>> The secure service needs to handle the hardware driver in their own domain instead of putting all drivers into core.
>>>
>>> So the in the handler there would be permission checking:
>>>
>>> case SVC_ACCESS_RESOUCE:
>>> If (spm_check_address_ownership(addr, CURRENT_SP))
>>> ret = do_access(addr, data, sz, flags);
>>>
>>> And the IIC_WRITE was implemented as:
>>> I2c_write(addr, value) { *host_reg_slave_addr = addr;
>>> *host_reg_slave_data = value; *host_reg_control_go = 1; }
>>>
>>> Now turned into:
>>> I2c_write(addr, value) { SVC_ACCESS(host_reg_slave_addr, addr, flag),
>>> SVC_ACCESS(host_reg_slave_data, value, flag),
>>> SVC_ACCESS(host_reg_control_go, 1, flag)}
>>>
>>> But if you are saying that, there are some even more complex logics for example some I2C devices can be accessed under privileged only while all the rest can be accessed freely, yes, the interface I proposed is limited. In this case you can introduce the customized logic into core with some new SVC.
>>>
>>> If the previous line is your case, please go on with the modification in the first mail, the modification looks okay, and let's discuss base on the patches.
>>>
>>> Thanks.
>>>
>>> /Ken
>>>
>>> -----Original Message-----
>>> From: DeMars, Alan <ademars(a)ti.com>
>>> Sent: Thursday, October 10, 2019 11:14 AM
>>> To: Ken Liu (Arm Technology China) <Ken.Liu(a)arm.com>
>>> Cc: nd <nd(a)arm.com>
>>> Subject: RE: augmenting the SVC_Handler_IPC() to support custom
>>> services
>>>
>>> I think the TFM_SVC_ACCESS_RESOURCE proposal is too limiting. What if (as is true in our case) there is a complex sequence of writes/reads and careful timing that must be performed to access a resource?
>>>
>>> I'm not sure why TF-M is wanting/needing to limit what I can do with the secure SVC handler. You've claimed ownership of the standard mechanism for entering secure privileged mode and are more-or-less dictating the set of APIs that can be provided/implemented with this standard mechanism.
>>>
>>> Alan
>>>
>>> -----Original Message-----
>>> From: Ken Liu (Arm Technology China) [mailto:Ken.Liu@arm.com]
>>> Sent: Wednesday, October 9, 2019 7:47 PM
>>> To: DeMars, Alan
>>> Cc: nd
>>> Subject: [EXTERNAL] RE: augmenting the SVC_Handler_IPC() to support
>>> custom services
>>>
>>> Hi Alan,
>>>
>>> Since the peripheral accessing functionality is missing now, the way you mentioned would be the only choice. We got a plan to implement some function for accessing privileged resources, can you promote your function into a common implementation so that we could re-use your code for future development?
>>>
>>> The proposed way would be:
>>> TFM_SVC_ACCESS_RESOURCE
>>>
>>> And the parameter would be:
>>>
>>> uintptr_t resource_addr /* The address you want to access */ void
>>> *p_user_buffer /* User-provided buffer */ size_t size /* size of user
>>> buffer */ uint32_t flags /* Flags, like read/write */
>>>
>>> Or you can define a customized structure for the parameter (if you put more than 4 parameters svc_handler need to dispatch customized aapcs which makes life hard) when you are accessing some serial connected devices?
>>>
>>> Thanks.
>>>
>>> /Ken
>>>
>>> -----Original Message-----
>>> From: DeMars, Alan <ademars(a)ti.com>
>>> Sent: Thursday, October 10, 2019 10:27 AM
>>> To: Ken Liu (Arm Technology China) <Ken.Liu(a)arm.com>
>>> Cc: nd <nd(a)arm.com>
>>> Subject: RE: augmenting the SVC_Handler_IPC() to support custom
>>> services
>>>
>>> Ken,
>>>
>>> There are certain resources that can only be interrogated in secure privilege mode on our platform. Nonetheless, unprivileged SP code (ie level 2) will need to be informed of content available in those privileged resources. As TFM has claimed ownership of the SVC handler, I need to extend that SVC handler to provide the functionality our SP services require.
>>>
>>> Alan
>>>
>>> -----Original Message-----
>>> From: TF-M [mailto:tf-m-bounces@lists.trustedfirmware.org] On Behalf
>>> Of Ken Liu (Arm Technology China) via TF-M
>>> Sent: Wednesday, October 9, 2019 7:04 PM
>>> To: tf-m(a)lists.trustedfirmware.org
>>> Cc: nd
>>> Subject: [EXTERNAL] Re: [TF-M] augmenting the SVC_Handler_IPC() to
>>> support custom services
>>>
>>> Hi Alan,
>>>
>>> Looks like you are working under IPC model, and you need something to do in core/spm. If you can provide more details then it will be great.
>>>
>>> From the code change itself, it has no problem, I am planning a re-structure on this part so if there are issues we can fix them later one. But when we look at the service programming model, we need to know the newly added SVC function is really an 'spm/core' function.
>>>
>>> Calling an SVC typically happen when we want to access privileged resource (registers or restricted memory), or some other customized behaviours.
>>> We need to be careful when we adding core functionalities because TF-M IPC model maintains a very small core and provide only necessary core functionalities (scheduling, spm). There are PSA RoT Services who has a higher privileged level already, and secure partition can access the peripheral they want.
>>>
>>> Thanks.
>>>
>>> /Ken
>>>
>>> -----Original Message-----
>>> From: TF-M <tf-m-bounces(a)lists.trustedfirmware.org> On Behalf Of
>>> DeMars, Alan via TF-M
>>> Sent: Thursday, October 10, 2019 4:38 AM
>>> To: 'tf-m(a)lists.trustedfirmware.org' <tf-m(a)lists.trustedfirmware.org>
>>> Subject: [TF-M] augmenting the SVC_Handler_IPC() to support custom
>>> services
>>>
>>> I need to add custom SPM APIs to augment our SP services. Consequently, I need to extend the set of SVCs supported in SVC_Handler_IPC().
>>>
>>> I propose to modify the SVC_Handler_IPC() function's 'default' handler to invoke a locally defined weak function such as below:
>>>
>>> default:
>>> return (custom_ipc_svc_handlers(svc_num, ctx, lr));
>>>
>>> __attribute__((weak))
>>> int32_t custom_ipc_svc_handlers(tfm_svc_number_t svc_num, uint32_t *ctx, uint32_t lr) {
>>> LOG_MSG("Unknown SVC number requested!");
>>> return PSA_ERROR_GENERIC_ERROR; }
>>>
>>> This will allow a 'strong'ly defined custom_ipc_svc_handlers() function to be invoked if provided.
>>>
>>> Is this OK?
>>>
>>> Another approach is for me to hijack the root SVC handler in the secure vector table, but this seems too heavy handed to me.
>>>
>>> Alan
>>> --
>>> TF-M mailing list
>>> TF-M(a)lists.trustedfirmware.org
>>> https://lists.trustedfirmware.org/mailman/listinfo/tf-m
>>> --
>>> TF-M mailing list
>>> TF-M(a)lists.trustedfirmware.org
>>> https://lists.trustedfirmware.org/mailman/listinfo/tf-m
>>> --
>>> TF-M mailing list
>>> TF-M(a)lists.trustedfirmware.org
>>> https://lists.trustedfirmware.org/mailman/listinfo/tf-m
>> --
>> TF-M mailing list
>> TF-M(a)lists.trustedfirmware.org
>> https://lists.trustedfirmware.org/mailman/listinfo/tf-m
> --
> TF-M mailing list
> TF-M(a)lists.trustedfirmware.org
> https://lists.trustedfirmware.org/mailman/listinfo/tf-m
I think I’ve already provided the changes I propose. The ‘default’ case will be for the SVC handler to invoke the provided weak defined function as shown. If a non-weak version of the function exists during the link process, the non-weak implementation will be invoked instead.
My intent is to provide a proprietary non-weak implementation of “custom_ipc_svc_handlers()”.
Alan
> On Oct 9, 2019, at 9:22 PM, Ken Liu (Arm Technology China) via TF-M <tf-m(a)lists.trustedfirmware.org> wrote:
>
> Hi Alan,
>
> The example here is the worst case for APP RoT accessing the peripherals, so you are right with the latency issue in this case. In most cases, the service manipulating the secure hardware can be PSA RoT so they access the peripheral directly.
>
> I am curious about the requirements you are facing so I am eager to see the changes.
>
> Thanks.
>
> /Ken
>
>
> -----Original Message-----
> From: DeMars, Alan <ademars(a)ti.com>
> Sent: Thursday, October 10, 2019 12:07 PM
> To: Ken Liu (Arm Technology China) <Ken.Liu(a)arm.com>
> Cc: tf-m(a)lists.trustedfirmware.org; nd <nd(a)arm.com>
> Subject: Re: [EXTERNAL] Re: [TF-M] augmenting the SVC_Handler_IPC() to support custom services
>
> Ken,
>
> If I understand the proposal, I’m afraid the latency and overhead associated with every peripheral register access (read or write) would be completely unacceptable for our requirements.
>
> Alan
>
>> On Oct 9, 2019, at 8:47 PM, Ken Liu (Arm Technology China) via TF-M <tf-m(a)lists.trustedfirmware.org> wrote:
>>
>> Hi Alan,
>>
>> The secure service is allowed to access some peripherals they want (introduce them in the manifest file), which means if you want to access a I2C device you can just (ALL CODE HERE IS PSEUDO CODE AND IS NOT REAL):
>>
>> I2c_write (I2C_ADDR, SLAVE_ADDR, value);
>>
>> While:
>> I2c_write(addr, value) { *host_reg_slave_addr = addr;
>> *host_reg_slave_data = value; *host_reg_control_go = 1; }
>>
>> The reason of providing the SVC interface is because the APP RoT Service may want to access some registers but they could not because those registers may be set as privileged.
>>
>> The secure service needs to handle the hardware driver in their own domain instead of putting all drivers into core.
>>
>> So the in the handler there would be permission checking:
>>
>> case SVC_ACCESS_RESOUCE:
>> If (spm_check_address_ownership(addr, CURRENT_SP))
>> ret = do_access(addr, data, sz, flags);
>>
>> And the IIC_WRITE was implemented as:
>> I2c_write(addr, value) { *host_reg_slave_addr = addr;
>> *host_reg_slave_data = value; *host_reg_control_go = 1; }
>>
>> Now turned into:
>> I2c_write(addr, value) { SVC_ACCESS(host_reg_slave_addr, addr, flag),
>> SVC_ACCESS(host_reg_slave_data, value, flag),
>> SVC_ACCESS(host_reg_control_go, 1, flag)}
>>
>> But if you are saying that, there are some even more complex logics for example some I2C devices can be accessed under privileged only while all the rest can be accessed freely, yes, the interface I proposed is limited. In this case you can introduce the customized logic into core with some new SVC.
>>
>> If the previous line is your case, please go on with the modification in the first mail, the modification looks okay, and let's discuss base on the patches.
>>
>> Thanks.
>>
>> /Ken
>>
>> -----Original Message-----
>> From: DeMars, Alan <ademars(a)ti.com>
>> Sent: Thursday, October 10, 2019 11:14 AM
>> To: Ken Liu (Arm Technology China) <Ken.Liu(a)arm.com>
>> Cc: nd <nd(a)arm.com>
>> Subject: RE: augmenting the SVC_Handler_IPC() to support custom
>> services
>>
>> I think the TFM_SVC_ACCESS_RESOURCE proposal is too limiting. What if (as is true in our case) there is a complex sequence of writes/reads and careful timing that must be performed to access a resource?
>>
>> I'm not sure why TF-M is wanting/needing to limit what I can do with the secure SVC handler. You've claimed ownership of the standard mechanism for entering secure privileged mode and are more-or-less dictating the set of APIs that can be provided/implemented with this standard mechanism.
>>
>> Alan
>>
>> -----Original Message-----
>> From: Ken Liu (Arm Technology China) [mailto:Ken.Liu@arm.com]
>> Sent: Wednesday, October 9, 2019 7:47 PM
>> To: DeMars, Alan
>> Cc: nd
>> Subject: [EXTERNAL] RE: augmenting the SVC_Handler_IPC() to support
>> custom services
>>
>> Hi Alan,
>>
>> Since the peripheral accessing functionality is missing now, the way you mentioned would be the only choice. We got a plan to implement some function for accessing privileged resources, can you promote your function into a common implementation so that we could re-use your code for future development?
>>
>> The proposed way would be:
>> TFM_SVC_ACCESS_RESOURCE
>>
>> And the parameter would be:
>>
>> uintptr_t resource_addr /* The address you want to access */ void
>> *p_user_buffer /* User-provided buffer */ size_t size /* size of user
>> buffer */ uint32_t flags /* Flags, like read/write */
>>
>> Or you can define a customized structure for the parameter (if you put more than 4 parameters svc_handler need to dispatch customized aapcs which makes life hard) when you are accessing some serial connected devices?
>>
>> Thanks.
>>
>> /Ken
>>
>> -----Original Message-----
>> From: DeMars, Alan <ademars(a)ti.com>
>> Sent: Thursday, October 10, 2019 10:27 AM
>> To: Ken Liu (Arm Technology China) <Ken.Liu(a)arm.com>
>> Cc: nd <nd(a)arm.com>
>> Subject: RE: augmenting the SVC_Handler_IPC() to support custom
>> services
>>
>> Ken,
>>
>> There are certain resources that can only be interrogated in secure privilege mode on our platform. Nonetheless, unprivileged SP code (ie level 2) will need to be informed of content available in those privileged resources. As TFM has claimed ownership of the SVC handler, I need to extend that SVC handler to provide the functionality our SP services require.
>>
>> Alan
>>
>> -----Original Message-----
>> From: TF-M [mailto:tf-m-bounces@lists.trustedfirmware.org] On Behalf
>> Of Ken Liu (Arm Technology China) via TF-M
>> Sent: Wednesday, October 9, 2019 7:04 PM
>> To: tf-m(a)lists.trustedfirmware.org
>> Cc: nd
>> Subject: [EXTERNAL] Re: [TF-M] augmenting the SVC_Handler_IPC() to
>> support custom services
>>
>> Hi Alan,
>>
>> Looks like you are working under IPC model, and you need something to do in core/spm. If you can provide more details then it will be great.
>>
>> From the code change itself, it has no problem, I am planning a re-structure on this part so if there are issues we can fix them later one. But when we look at the service programming model, we need to know the newly added SVC function is really an 'spm/core' function.
>>
>> Calling an SVC typically happen when we want to access privileged resource (registers or restricted memory), or some other customized behaviours.
>> We need to be careful when we adding core functionalities because TF-M IPC model maintains a very small core and provide only necessary core functionalities (scheduling, spm). There are PSA RoT Services who has a higher privileged level already, and secure partition can access the peripheral they want.
>>
>> Thanks.
>>
>> /Ken
>>
>> -----Original Message-----
>> From: TF-M <tf-m-bounces(a)lists.trustedfirmware.org> On Behalf Of
>> DeMars, Alan via TF-M
>> Sent: Thursday, October 10, 2019 4:38 AM
>> To: 'tf-m(a)lists.trustedfirmware.org' <tf-m(a)lists.trustedfirmware.org>
>> Subject: [TF-M] augmenting the SVC_Handler_IPC() to support custom
>> services
>>
>> I need to add custom SPM APIs to augment our SP services. Consequently, I need to extend the set of SVCs supported in SVC_Handler_IPC().
>>
>> I propose to modify the SVC_Handler_IPC() function's 'default' handler to invoke a locally defined weak function such as below:
>>
>> default:
>> return (custom_ipc_svc_handlers(svc_num, ctx, lr));
>>
>> __attribute__((weak))
>> int32_t custom_ipc_svc_handlers(tfm_svc_number_t svc_num, uint32_t *ctx, uint32_t lr) {
>> LOG_MSG("Unknown SVC number requested!");
>> return PSA_ERROR_GENERIC_ERROR; }
>>
>> This will allow a 'strong'ly defined custom_ipc_svc_handlers() function to be invoked if provided.
>>
>> Is this OK?
>>
>> Another approach is for me to hijack the root SVC handler in the secure vector table, but this seems too heavy handed to me.
>>
>> Alan
>> --
>> TF-M mailing list
>> TF-M(a)lists.trustedfirmware.org
>> https://lists.trustedfirmware.org/mailman/listinfo/tf-m
>> --
>> TF-M mailing list
>> TF-M(a)lists.trustedfirmware.org
>> https://lists.trustedfirmware.org/mailman/listinfo/tf-m
>> --
>> TF-M mailing list
>> TF-M(a)lists.trustedfirmware.org
>> https://lists.trustedfirmware.org/mailman/listinfo/tf-m
> --
> TF-M mailing list
> TF-M(a)lists.trustedfirmware.org
> https://lists.trustedfirmware.org/mailman/listinfo/tf-m
Ken,
If I understand the proposal, I’m afraid the latency and overhead associated with every peripheral register access (read or write) would be completely unacceptable for our requirements.
Alan
> On Oct 9, 2019, at 8:47 PM, Ken Liu (Arm Technology China) via TF-M <tf-m(a)lists.trustedfirmware.org> wrote:
>
> Hi Alan,
>
> The secure service is allowed to access some peripherals they want (introduce them in the manifest file), which means if you want to access a I2C device you can just (ALL CODE HERE IS PSEUDO CODE AND IS NOT REAL):
>
> I2c_write (I2C_ADDR, SLAVE_ADDR, value);
>
> While:
> I2c_write(addr, value) { *host_reg_slave_addr = addr; *host_reg_slave_data = value; *host_reg_control_go = 1; }
>
> The reason of providing the SVC interface is because the APP RoT Service may want to access some registers but they could not because those registers may be set as privileged.
>
> The secure service needs to handle the hardware driver in their own domain instead of putting all drivers into core.
>
> So the in the handler there would be permission checking:
>
> case SVC_ACCESS_RESOUCE:
> If (spm_check_address_ownership(addr, CURRENT_SP))
> ret = do_access(addr, data, sz, flags);
>
> And the IIC_WRITE was implemented as:
> I2c_write(addr, value) { *host_reg_slave_addr = addr; *host_reg_slave_data = value; *host_reg_control_go = 1; }
>
> Now turned into:
> I2c_write(addr, value) { SVC_ACCESS(host_reg_slave_addr, addr, flag), SVC_ACCESS(host_reg_slave_data, value, flag), SVC_ACCESS(host_reg_control_go, 1, flag)}
>
> But if you are saying that, there are some even more complex logics for example some I2C devices can be accessed under privileged only while all the rest can be accessed freely, yes, the interface I proposed is limited. In this case you can introduce the customized logic into core with some new SVC.
>
> If the previous line is your case, please go on with the modification in the first mail, the modification looks okay, and let's discuss base on the patches.
>
> Thanks.
>
> /Ken
>
> -----Original Message-----
> From: DeMars, Alan <ademars(a)ti.com>
> Sent: Thursday, October 10, 2019 11:14 AM
> To: Ken Liu (Arm Technology China) <Ken.Liu(a)arm.com>
> Cc: nd <nd(a)arm.com>
> Subject: RE: augmenting the SVC_Handler_IPC() to support custom services
>
> I think the TFM_SVC_ACCESS_RESOURCE proposal is too limiting. What if (as is true in our case) there is a complex sequence of writes/reads and careful timing that must be performed to access a resource?
>
> I'm not sure why TF-M is wanting/needing to limit what I can do with the secure SVC handler. You've claimed ownership of the standard mechanism for entering secure privileged mode and are more-or-less dictating the set of APIs that can be provided/implemented with this standard mechanism.
>
> Alan
>
> -----Original Message-----
> From: Ken Liu (Arm Technology China) [mailto:Ken.Liu@arm.com]
> Sent: Wednesday, October 9, 2019 7:47 PM
> To: DeMars, Alan
> Cc: nd
> Subject: [EXTERNAL] RE: augmenting the SVC_Handler_IPC() to support custom services
>
> Hi Alan,
>
> Since the peripheral accessing functionality is missing now, the way you mentioned would be the only choice. We got a plan to implement some function for accessing privileged resources, can you promote your function into a common implementation so that we could re-use your code for future development?
>
> The proposed way would be:
> TFM_SVC_ACCESS_RESOURCE
>
> And the parameter would be:
>
> uintptr_t resource_addr /* The address you want to access */ void *p_user_buffer /* User-provided buffer */ size_t size /* size of user buffer */ uint32_t flags /* Flags, like read/write */
>
> Or you can define a customized structure for the parameter (if you put more than 4 parameters svc_handler need to dispatch customized aapcs which makes life hard) when you are accessing some serial connected devices?
>
> Thanks.
>
> /Ken
>
> -----Original Message-----
> From: DeMars, Alan <ademars(a)ti.com>
> Sent: Thursday, October 10, 2019 10:27 AM
> To: Ken Liu (Arm Technology China) <Ken.Liu(a)arm.com>
> Cc: nd <nd(a)arm.com>
> Subject: RE: augmenting the SVC_Handler_IPC() to support custom services
>
> Ken,
>
> There are certain resources that can only be interrogated in secure privilege mode on our platform. Nonetheless, unprivileged SP code (ie level 2) will need to be informed of content available in those privileged resources. As TFM has claimed ownership of the SVC handler, I need to extend that SVC handler to provide the functionality our SP services require.
>
> Alan
>
> -----Original Message-----
> From: TF-M [mailto:tf-m-bounces@lists.trustedfirmware.org] On Behalf Of Ken Liu (Arm Technology China) via TF-M
> Sent: Wednesday, October 9, 2019 7:04 PM
> To: tf-m(a)lists.trustedfirmware.org
> Cc: nd
> Subject: [EXTERNAL] Re: [TF-M] augmenting the SVC_Handler_IPC() to support custom services
>
> Hi Alan,
>
> Looks like you are working under IPC model, and you need something to do in core/spm. If you can provide more details then it will be great.
>
> From the code change itself, it has no problem, I am planning a re-structure on this part so if there are issues we can fix them later one. But when we look at the service programming model, we need to know the newly added SVC function is really an 'spm/core' function.
>
> Calling an SVC typically happen when we want to access privileged resource (registers or restricted memory), or some other customized behaviours.
> We need to be careful when we adding core functionalities because TF-M IPC model maintains a very small core and provide only necessary core functionalities (scheduling, spm). There are PSA RoT Services who has a higher privileged level already, and secure partition can access the peripheral they want.
>
> Thanks.
>
> /Ken
>
> -----Original Message-----
> From: TF-M <tf-m-bounces(a)lists.trustedfirmware.org> On Behalf Of DeMars, Alan via TF-M
> Sent: Thursday, October 10, 2019 4:38 AM
> To: 'tf-m(a)lists.trustedfirmware.org' <tf-m(a)lists.trustedfirmware.org>
> Subject: [TF-M] augmenting the SVC_Handler_IPC() to support custom services
>
> I need to add custom SPM APIs to augment our SP services. Consequently, I need to extend the set of SVCs supported in SVC_Handler_IPC().
>
> I propose to modify the SVC_Handler_IPC() function's 'default' handler to invoke a locally defined weak function such as below:
>
> default:
> return (custom_ipc_svc_handlers(svc_num, ctx, lr));
>
> __attribute__((weak))
> int32_t custom_ipc_svc_handlers(tfm_svc_number_t svc_num, uint32_t *ctx, uint32_t lr) {
> LOG_MSG("Unknown SVC number requested!");
> return PSA_ERROR_GENERIC_ERROR;
> }
>
> This will allow a 'strong'ly defined custom_ipc_svc_handlers() function to be invoked if provided.
>
> Is this OK?
>
> Another approach is for me to hijack the root SVC handler in the secure vector table, but this seems too heavy handed to me.
>
> Alan
> --
> TF-M mailing list
> TF-M(a)lists.trustedfirmware.org
> https://lists.trustedfirmware.org/mailman/listinfo/tf-m
> --
> TF-M mailing list
> TF-M(a)lists.trustedfirmware.org
> https://lists.trustedfirmware.org/mailman/listinfo/tf-m
> --
> TF-M mailing list
> TF-M(a)lists.trustedfirmware.org
> https://lists.trustedfirmware.org/mailman/listinfo/tf-m
Hi Alan,
The secure service is allowed to access some peripherals they want (introduce them in the manifest file), which means if you want to access a I2C device you can just (ALL CODE HERE IS PSEUDO CODE AND IS NOT REAL):
I2c_write (I2C_ADDR, SLAVE_ADDR, value);
While:
I2c_write(addr, value) { *host_reg_slave_addr = addr; *host_reg_slave_data = value; *host_reg_control_go = 1; }
The reason of providing the SVC interface is because the APP RoT Service may want to access some registers but they could not because those registers may be set as privileged.
The secure service needs to handle the hardware driver in their own domain instead of putting all drivers into core.
So the in the handler there would be permission checking:
case SVC_ACCESS_RESOUCE:
If (spm_check_address_ownership(addr, CURRENT_SP))
ret = do_access(addr, data, sz, flags);
And the IIC_WRITE was implemented as:
I2c_write(addr, value) { *host_reg_slave_addr = addr; *host_reg_slave_data = value; *host_reg_control_go = 1; }
Now turned into:
I2c_write(addr, value) { SVC_ACCESS(host_reg_slave_addr, addr, flag), SVC_ACCESS(host_reg_slave_data, value, flag), SVC_ACCESS(host_reg_control_go, 1, flag)}
But if you are saying that, there are some even more complex logics for example some I2C devices can be accessed under privileged only while all the rest can be accessed freely, yes, the interface I proposed is limited. In this case you can introduce the customized logic into core with some new SVC.
If the previous line is your case, please go on with the modification in the first mail, the modification looks okay, and let's discuss base on the patches.
Thanks.
/Ken
-----Original Message-----
From: DeMars, Alan <ademars(a)ti.com>
Sent: Thursday, October 10, 2019 11:14 AM
To: Ken Liu (Arm Technology China) <Ken.Liu(a)arm.com>
Cc: nd <nd(a)arm.com>
Subject: RE: augmenting the SVC_Handler_IPC() to support custom services
I think the TFM_SVC_ACCESS_RESOURCE proposal is too limiting. What if (as is true in our case) there is a complex sequence of writes/reads and careful timing that must be performed to access a resource?
I'm not sure why TF-M is wanting/needing to limit what I can do with the secure SVC handler. You've claimed ownership of the standard mechanism for entering secure privileged mode and are more-or-less dictating the set of APIs that can be provided/implemented with this standard mechanism.
Alan
-----Original Message-----
From: Ken Liu (Arm Technology China) [mailto:Ken.Liu@arm.com]
Sent: Wednesday, October 9, 2019 7:47 PM
To: DeMars, Alan
Cc: nd
Subject: [EXTERNAL] RE: augmenting the SVC_Handler_IPC() to support custom services
Hi Alan,
Since the peripheral accessing functionality is missing now, the way you mentioned would be the only choice. We got a plan to implement some function for accessing privileged resources, can you promote your function into a common implementation so that we could re-use your code for future development?
The proposed way would be:
TFM_SVC_ACCESS_RESOURCE
And the parameter would be:
uintptr_t resource_addr /* The address you want to access */ void *p_user_buffer /* User-provided buffer */ size_t size /* size of user buffer */ uint32_t flags /* Flags, like read/write */
Or you can define a customized structure for the parameter (if you put more than 4 parameters svc_handler need to dispatch customized aapcs which makes life hard) when you are accessing some serial connected devices?
Thanks.
/Ken
-----Original Message-----
From: DeMars, Alan <ademars(a)ti.com>
Sent: Thursday, October 10, 2019 10:27 AM
To: Ken Liu (Arm Technology China) <Ken.Liu(a)arm.com>
Cc: nd <nd(a)arm.com>
Subject: RE: augmenting the SVC_Handler_IPC() to support custom services
Ken,
There are certain resources that can only be interrogated in secure privilege mode on our platform. Nonetheless, unprivileged SP code (ie level 2) will need to be informed of content available in those privileged resources. As TFM has claimed ownership of the SVC handler, I need to extend that SVC handler to provide the functionality our SP services require.
Alan
-----Original Message-----
From: TF-M [mailto:tf-m-bounces@lists.trustedfirmware.org] On Behalf Of Ken Liu (Arm Technology China) via TF-M
Sent: Wednesday, October 9, 2019 7:04 PM
To: tf-m(a)lists.trustedfirmware.org
Cc: nd
Subject: [EXTERNAL] Re: [TF-M] augmenting the SVC_Handler_IPC() to support custom services
Hi Alan,
Looks like you are working under IPC model, and you need something to do in core/spm. If you can provide more details then it will be great.
From the code change itself, it has no problem, I am planning a re-structure on this part so if there are issues we can fix them later one. But when we look at the service programming model, we need to know the newly added SVC function is really an 'spm/core' function.
Calling an SVC typically happen when we want to access privileged resource (registers or restricted memory), or some other customized behaviours.
We need to be careful when we adding core functionalities because TF-M IPC model maintains a very small core and provide only necessary core functionalities (scheduling, spm). There are PSA RoT Services who has a higher privileged level already, and secure partition can access the peripheral they want.
Thanks.
/Ken
-----Original Message-----
From: TF-M <tf-m-bounces(a)lists.trustedfirmware.org> On Behalf Of DeMars, Alan via TF-M
Sent: Thursday, October 10, 2019 4:38 AM
To: 'tf-m(a)lists.trustedfirmware.org' <tf-m(a)lists.trustedfirmware.org>
Subject: [TF-M] augmenting the SVC_Handler_IPC() to support custom services
I need to add custom SPM APIs to augment our SP services. Consequently, I need to extend the set of SVCs supported in SVC_Handler_IPC().
I propose to modify the SVC_Handler_IPC() function's 'default' handler to invoke a locally defined weak function such as below:
default:
return (custom_ipc_svc_handlers(svc_num, ctx, lr));
__attribute__((weak))
int32_t custom_ipc_svc_handlers(tfm_svc_number_t svc_num, uint32_t *ctx, uint32_t lr) {
LOG_MSG("Unknown SVC number requested!");
return PSA_ERROR_GENERIC_ERROR;
}
This will allow a 'strong'ly defined custom_ipc_svc_handlers() function to be invoked if provided.
Is this OK?
Another approach is for me to hijack the root SVC handler in the secure vector table, but this seems too heavy handed to me.
Alan
--
TF-M mailing list
TF-M(a)lists.trustedfirmware.org
https://lists.trustedfirmware.org/mailman/listinfo/tf-m
--
TF-M mailing list
TF-M(a)lists.trustedfirmware.org
https://lists.trustedfirmware.org/mailman/listinfo/tf-m
Hi Alan,
Looks like you are working under IPC model, and you need something to do in core/spm. If you can provide more details then it will be great.
From the code change itself, it has no problem, I am planning a re-structure on this part so if there are issues we can fix them later one. But when we look at the service programming model, we need to know the newly added SVC function is really an 'spm/core' function.
Calling an SVC typically happen when we want to access privileged resource (registers or restricted memory), or some other customized behaviours.
We need to be careful when we adding core functionalities because TF-M IPC model maintains a very small core and provide only necessary core functionalities (scheduling, spm). There are PSA RoT Services who has a higher privileged level already, and secure partition can access the peripheral they want.
Thanks.
/Ken
-----Original Message-----
From: TF-M <tf-m-bounces(a)lists.trustedfirmware.org> On Behalf Of DeMars, Alan via TF-M
Sent: Thursday, October 10, 2019 4:38 AM
To: 'tf-m(a)lists.trustedfirmware.org' <tf-m(a)lists.trustedfirmware.org>
Subject: [TF-M] augmenting the SVC_Handler_IPC() to support custom services
I need to add custom SPM APIs to augment our SP services. Consequently, I need to extend the set of SVCs supported in SVC_Handler_IPC().
I propose to modify the SVC_Handler_IPC() function's 'default' handler to invoke a locally defined weak function such as below:
default:
return (custom_ipc_svc_handlers(svc_num, ctx, lr));
__attribute__((weak))
int32_t custom_ipc_svc_handlers(tfm_svc_number_t svc_num, uint32_t *ctx, uint32_t lr) {
LOG_MSG("Unknown SVC number requested!");
return PSA_ERROR_GENERIC_ERROR;
}
This will allow a 'strong'ly defined custom_ipc_svc_handlers() function to be invoked if provided.
Is this OK?
Another approach is for me to hijack the root SVC handler in the secure vector table, but this seems too heavy handed to me.
Alan
--
TF-M mailing list
TF-M(a)lists.trustedfirmware.org
https://lists.trustedfirmware.org/mailman/listinfo/tf-m
I need to add custom SPM APIs to augment our SP services. Consequently, I need to extend the set of SVCs supported in SVC_Handler_IPC().
I propose to modify the SVC_Handler_IPC() function's 'default' handler to invoke a locally defined weak function such as below:
default:
return (custom_ipc_svc_handlers(svc_num, ctx, lr));
__attribute__((weak))
int32_t custom_ipc_svc_handlers(tfm_svc_number_t svc_num, uint32_t *ctx, uint32_t lr)
{
LOG_MSG("Unknown SVC number requested!");
return PSA_ERROR_GENERIC_ERROR;
}
This will allow a 'strong'ly defined custom_ipc_svc_handlers() function to be invoked if provided.
Is this OK?
Another approach is for me to hijack the root SVC handler in the secure vector table, but this seems too heavy handed to me.
Alan
Hi All,
I'm planning to change the way secure services are called in Library model.
The design proposal can be found here: https://review.trustedfirmware.org/#/c/trusted-firmware-m/+/2201/
Please note that the changes proposed by this document does not affect the PSA dev API, and does not affect IPC model.
Please share your opinion in gerrit comments
Thanks,
Mate
Hi,
This would test the interface for NS and S with the set, get and remove with maximum `SST_MAX_ASSET_SIZE` and different sizes for all platforms (including feature-twincpu targets in the near future).
It uses a common 4K buffer in total to assist with read and write of asset data.
We need to make sure we are able to perform this operation flawlessly on all the targets.
Patch Review Request:
https://review.trustedfirmware.org/c/trusted-firmware-m/+/2167https://review.trustedfirmware.org/c/trusted-firmware-m/+/2168
Thanks & Best Regards,
Vikas Katariya
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
Hi Thomas,
One way this can happen is if the QSPI driver is being executed in place from QSPI, so the device is never idle because instructions are being fetched from it.
On Musca-A, MCUboot is copied to Code SRAM before being executed to avoid this issue. There is some code in the Armclang/GCC scatter/startup files to support this. Is there something similar implemented for the IAR port?
Best wishes,
Jamie
-----Original Message-----
From: TF-M <tf-m-bounces(a)lists.trustedfirmware.org> On Behalf Of Thomas Törnblom via TF-M
Sent: 27 September 2019 15:40
To: tf-m(a)lists.trustedfirmware.org
Subject: [TF-M] Issues with qspi_ip6514e_set_spi_mode with IAR
I'm trying to bring up TF-M on the Musca A with IAR Embedded Workbench and I'm having issues in mcuboot where the boot hangs with the following
stack:
---
qspi_ip6514e_is_idle
qspi_ip6514e_set_spi_mode
set_spi_mode
mt25ql_config_mode
ARM_Flash_Initialize
main
[_call_main + 0xd]
---
Apparently the idle bit (31) in the qspi_cfg register (0x4010a000) never gets set so it loops there.
I have no programmers manual for the Cadence qspi ip6514e so I'm at a bit of a loss as to what the issue might be.
Obviously something is different between the images built with armclang and gcc, which works properly, and the image I've built with IAR.
Ideas anyone?
/Thomas
--
*Thomas Törnblom*, /Product Engineer/
IAR Systems AB
Box 23051, Strandbodgatan 1
SE-750 23 Uppsala, SWEDEN
Mobile: +46 76 180 17 80 Fax: +46 18 16 78 01
E-mail: thomas.tornblom(a)iar.com <mailto:thomas.tornblom@iar.com>
Website: www.iar.com <http://www.iar.com>
Twitter: www.twitter.com/iarsystems <http://www.twitter.com/iarsystems>
--
TF-M mailing list
TF-M(a)lists.trustedfirmware.org
https://lists.trustedfirmware.org/mailman/listinfo/tf-m