tee: ACPI support for optee driver
Subsystems (3)
PATCH 1/1 tee: ACPI support for optee driver
This patch modifies the optee driver to add support for parsing the conduit method from an ACPI node.
--- drivers/tee/optee/core.c | 112 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 77 insertions(+), 35 deletions(-)
drivers/tee/optee/core.c +77 -35
@@ -14,6 +14,7 @@#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt +#include <linux/acpi.h> #include <linux/arm-smccc.h> #include <linux/errno.h> #include <linux/io.h>
@@ -30,6 +31,7 @@#include "optee_smc.h" #define DRIVER_NAME "optee" +#define OPTEE_DEVICE "\\_SB.OPTE"#define OPTEE_SHM_NUM_PRIV_PAGES 1
@@ -425,29 +427,87 @@ static void optee_smccc_hvc(unsigned long a0, unsigned long a1,arm_smccc_hvc (a0, a1, a2, a3, a4, a5, a6, a7, res); } -static optee_invoke_fn *get_invoke_func (struct device_node *np) +static const struct of_device_id optee_match[] = { + { .compatible ="linaro,optee-tz" }, + {}, +}; + +#ifdef CONFIG_ACPI +static const char *get_invoke_str_acpi (void ) { -const char *method; +struct acpi_device_info *info; +const union acpi_object *obj; +struct acpi_device *adev; +acpi_status status; +acpi_handle handle; -pr_info ("probing for conduit method from DT.\n" ); + status =acpi_get_handle (ACPI_ROOT_OBJECT ,OPTEE_DEVICE , &handle); +if (ACPI_FAILURE (status)) +return NULL ; -if (of_property_read_string (np,"method" , &method)) { + status =acpi_get_object_info (handle, &info); +if (ACPI_FAILURE (status) || !(info->valid &ACPI_VALID_HID )) +return NULL ; + +if (acpi_bus_get_device (handle, &adev)) +return NULL ; + +if (acpi_dev_get_property (adev,"method" , +ACPI_TYPE_ANY , &obj)) +return NULL ; + +return obj->string.pointer; +} +#endif + +static const char *get_invoke_str_of (void ) +{ +struct device_node *fw_np; +const char *method =NULL ; +struct device_node *np; + +/* Node is supposed to be below /firmware */ + fw_np =of_find_node_by_name (NULL ,"firmware" ); +if (!fw_np) +return NULL ; + + np =of_find_matching_node (fw_np, optee_match); +of_node_put (fw_np); +if (!np) +return NULL ; + +pr_info ("probing for conduit method from DT.\n" ); +if (of_property_read_string (np,"method" , &method))pr_warn ("missing \"method\" property\n" ); -return ERR_PTR (-ENXIO ); - } -if (!strcmp ("hvc" , method)) -return optee_smccc_hvc; -else if (!strcmp ("smc" , method)) -return optee_smccc_smc; +of_node_put (np); +return method; +} + +static optee_invoke_fn *get_invoke_func (void ) +{ +const char *method; + +#ifdef CONFIG_ACPI +if (!acpi_disabled) + method =get_invoke_str_acpi (); + else +#endif + method =get_invoke_str_of (); + +if (method) { +if (!strcmp ("hvc" , method)) +return optee_smccc_hvc; +else if (!strcmp ("smc" , method)) +return optee_smccc_smc; + }pr_warn ("invalid \"method\" property: %s\n" , method);return ERR_PTR (-EINVAL ); } -static struct optee *optee_probe (struct device_node *np) +static struct optee *optee_probe (optee_invoke_fn *invoke_fn) { -optee_invoke_fn *invoke_fn;struct tee_shm_pool *pool;struct optee *optee =NULL ;void *memremaped_shm =NULL ;
@@ -455,10 +515,6 @@ static struct optee *optee_probe(struct device_node *np)u32 sec_caps;int rc; - invoke_fn =get_invoke_func (np); -if (IS_ERR (invoke_fn)) -return (void *)invoke_fn; -if (!optee_msg_api_uid_is_optee_api (invoke_fn)) {pr_warn ("api uid mismatch\n" );return ERR_PTR (-EINVAL );
@@ -570,32 +626,18 @@ static void optee_remove(struct optee *optee)kfree (optee); } -static const struct of_device_id optee_match[] = { - { .compatible ="linaro,optee-tz" }, - {}, -}; -static struct optee *optee_svc;static int __init optee_driver_init (void ) { -struct device_node *fw_np; -struct device_node *np; +optee_invoke_fn *invoke_fn;struct optee *optee; -/* Node is supposed to be below /firmware */ - fw_np =of_find_node_by_name (NULL ,"firmware" ); -if (!fw_np) -return -ENODEV ; - - np =of_find_matching_node (fw_np, optee_match); -of_node_put (fw_np); -if (!np) -return -ENODEV ; - - optee =optee_probe (np); -of_node_put (np); + invoke_fn =get_invoke_func (); +if (IS_ERR (invoke_fn)) +return PTR_ERR (invoke_fn); + optee =optee_probe (invoke_fn);if (IS_ERR (optee))return PTR_ERR (optee);
Signature · 1 line
1.9.1
Quoted 2 lines · Mayuresh Chitale
This patch modifies the optee driver to add support for parsing the conduit method from an ACPI node.
Sorry I didn't involve this earlier, but I think this is a wrong approach, in ACPI 5.1+ spec, there is a bit in FADT table which indicates PSCI using SMC or HVC, please see ACPI 6.2 [1], Table 5-37 Fixed ACPI Description Table ARM Boot Architecture Flags.
Can we just use that to get the conduit method for optee driver too?
[1]: http://www.uefi.org/sites/default/files/resources/ACPI_6_2.pdf
Thanks
Hanjun
Quoted 10 lines · Hanjun Guo
Quoted 2 lines · Mayuresh Chitale
This patch modifies the optee driver to add support for parsing the conduit method from an ACPI node.
Sorry I didn't involve this earlier, but I think this is a wrong approach, in ACPI 5.1+ spec, there is a bit in FADT table which indicates PSCI using SMC or HVC, please see ACPI 6.2 [1], Table 5-37 Fixed ACPI Description Table ARM Boot Architecture Flags.
Can we just use that to get the conduit method for optee driver too?
Thanks for the comment. I will check it out.
Quoted 11 lines
[1]: http://www.uefi.org/sites/default/files/resources/ACPI_6_2.pdf
Thanks
Hanjun--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 4 lines · Hanjun Guo
Quoted 2 lines · Mayuresh Chitale
This patch modifies the optee driver to add support for parsing the conduit method from an ACPI node.
Quoted 8 lines
Sorry I didn't involve this earlier, but I think this is a wrong approach, in ACPI 5.1+ spec, there is a bit in FADT table which indicates PSCI using SMC or HVC, please see ACPI 6.2 [1], Table 5-37 Fixed ACPI Description Table ARM Boot Architecture Flags.
Can we just use that to get the conduit method for optee driver too?
[1]: http://www.uefi.org/sites/default/files/resources/ACPI_6_2.pdf
It is just not a matter of conduit method but also to define how OPTEE should be detected. It is up to Linaro (who owns OP-TEE) to put forward a binding at ACPI (ARM) spec level.
We do not define ACPI bindings on a kernel mailing list.
NAK on this patch.
Lorenzo
Quoted 14 lines · Lorenzo Pieralisi
Quoted 4 lines · Hanjun Guo
Quoted 2 lines · Mayuresh Chitale
This patch modifies the optee driver to add support for parsing the conduit method from an ACPI node.
Quoted 8 lines
Sorry I didn't involve this earlier, but I think this is a wrong approach, in ACPI 5.1+ spec, there is a bit in FADT table which indicates PSCI using SMC or HVC, please see ACPI 6.2 [1], Table 5-37 Fixed ACPI Description Table ARM Boot Architecture Flags.
Can we just use that to get the conduit method for optee driver too?
[1]: http://www.uefi.org/sites/default/files/resources/ACPI_6_2.pdf
Quoted 7 lines
It is just not a matter of conduit method but also to define how OPTEE should be detected. It is up to Linaro (who owns OP-TEE) to put forward a binding at ACPI (ARM) spec level.
We do not define ACPI bindings on a kernel mailing list.
NAK on this patch.
Is this actively being tracked by Linaro? If not, can Applied folks ping me off-list and I will proxy your request into Linaro.
Jon.
Signature · 1 line
Computer Architect | Sent from my Fedora powered laptop