firmware: Add support for Qualcomm UEFI Secure Application
Subsystems (3)
v5 cover firmware: Add support for Qualcomm UEFI Secure Application
This series adds basic support for the QSEECOM interface used to communicate with secure applications running in the TrustZone on certain Qualcomm devices. In addition to that, it also provides a driver for "uefisecapp", the secure application managing access to UEFI variables on such platforms.
For a more detailed description, see the blurb of v1.
Previous versions:
- V4: https://lore.kernel.org/lkml/[email protected]/t/
- V3: https://lore.kernel.org/lkml/[email protected]/t/
- V2: https://lore.kernel.org/lkml/[email protected]/
- V1: https://lore.kernel.org/lkml/[email protected]/
Changes in v5:
- Re-introduce a dedicated platform device for managing QSEECOM client devices. The device is now added via qcom_scm.c instead of the device tree (as has been done in v3).
- Replace ucs2_strlcpy() with ucs2_strscpy()
- Drop "firmware: qcom_scm: Clear scm pointer on probe failure" and sort out probe-related issue.
- Clean up comments in qcom_qseecom_uefisecapp.c
Changes in v4:
- Integrate the QSEECOM interface into qcom_scm.c instead of instantiating a custom device and requiring device-tree bindings for it. With that, drop the respective patches exporting SCM call functions from qcom_scm.c and the DT bindings.
- Restructure management of DMA memory and move DMA mapping entirely into the app_send() command, removing the need for DMA handling in app client drivers.
- Add support for EFI's query_variable_info() call.
- Move UCS-2 string helpers to lib/ucs2_string.c (introduces patch 1).
- Add fix for related cleanup-issue in qcom_scm.c (introduces patch 2).
(Refer to individual patches for more details.)
Changes in v3:
- Fix doc comment in qcom_scm.c
- Rebase on top of latest changes to qcom_scm.
Changes in v2:
- Bind the qseecom interface to a device.
- Establish a device link between the new qseecom device and the SCM device to ensure proper PM and remove ordering.
- Remove the compatible for uefisecapp. Instead, introduce a compatible for the qseecom device. This directly reflects ACPI tables and the QCOM0476 device described therein, which is responsible for the secure app / qseecom interface (i.e., the same purpose).
Client devices representing apps handled by the kernel (such as uefisecapp) are now directly instantiated by the qseecom driver, based on the respective platform-specific compatible.
- Rename the base name (qctree -> qseecom) to allow differentiation between old (qseecom) and new (smcinvoke) interfaces to the trusted execution environment. This directly reflects downstream naming by Qualcomm.
Maximilian Luz (3):
lib/ucs2_string: Add UCS-2 strscpy function
firmware: qcom_scm: Add support for Qualcomm Secure Execution
Environment SCM interface
firmware: Add support for Qualcomm UEFI Secure Application
MAINTAINERS | 12 + drivers/firmware/Kconfig | 33 + drivers/firmware/Makefile | 2 + drivers/firmware/qcom_qseecom.c | 130 +++ drivers/firmware/qcom_qseecom_uefisecapp.c | 869 +++++++++++++++++++++ drivers/firmware/qcom_scm.c | 392 ++++++++++ include/linux/firmware/qcom/qcom_qseecom.h | 46 ++ include/linux/firmware/qcom/qcom_scm.h | 21 + include/linux/ucs2_string.h | 1 + lib/ucs2_string.c | 35 + 10 files changed, 1541 insertions(+) create mode 100644 drivers/firmware/qcom_qseecom.c create mode 100644 drivers/firmware/qcom_qseecom_uefisecapp.c create mode 100644 include/linux/firmware/qcom/qcom_qseecom.h
Signature · 1 line
2.41.0
PATCH v5 1/3 lib/ucs2_string: Add UCS-2 strscpy function
Add a ucs2_strscpy() function for UCS-2 strings. The behavior is equivalent to the standard strscpy() function, just for 16-bit character UCS-2 strings.
---
Changes in v5:
- Add ucs2_strscpy() instead of ucs2_strlcpy()
Patch introduced in v4.
--- include/linux/ucs2_string.h | 1 + lib/ucs2_string.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+)
include/linux/ucs2_string.h +1 -0
@@ -10,6 +10,7 @@ typedef u16 ucs2_char_t;unsigned long ucs2_strnlen (const ucs2_char_t *s,size_t maxlength);unsigned long ucs2_strlen (const ucs2_char_t *s);unsigned long ucs2_strsize (const ucs2_char_t *data,unsigned long maxlength); +ssize_t ucs2_strscpy (ucs2_char_t *dst,const ucs2_char_t *src,size_t count);int ucs2_strncmp (const ucs2_char_t *a,const ucs2_char_t *b,size_t len);unsigned long ucs2_utf8size (const ucs2_char_t *src);
lib/ucs2_string.c +35 -0
@@ -32,6 +32,41 @@ ucs2_strsize(const ucs2_char_t *data, unsigned long maxlength) }EXPORT_SYMBOL (ucs2_strsize); +ssize_t ucs2_strscpy (ucs2_char_t *dst,const ucs2_char_t *src,size_t count) +{ +long res; + +/* +* Ensure that we have a valid amount of space. We need to store at +* least one NUL-character. +*/ +if (count ==0 ||WARN_ON_ONCE (count >INT_MAX )) +return -E2BIG ; + +/* +* Copy at most 'count' bytes, return early if we find a +* NUL-terminator. +*/ +for (res =0 ; res < count; res++) { +ucs2_char_t c; + + c = src[res]; + dst[res] = c; + +if (!c) +return res; + } + +/* +* The loop above terminated without finding a NUL-terminator, +* exceeding the 'count': Enforce proper NUL-termination and return +* error. +*/ + dst[count -1 ] =0 ; +return -E2BIG ; +} +EXPORT_SYMBOL (ucs2_strscpy); +int ucs2_strncmp (const ucs2_char_t *a,const ucs2_char_t *b,size_t len) {
Signature · 1 line
2.41.0
Re: [PATCH v5 1/3] lib/ucs2_string: Add UCS-2 strscpy function
Quoted 5 lines · Maximilian Luz
Add a
ucs2_strscpy()function for UCS-2 strings. The behavior is equivalent to the standardstrscpy()function, just for 16-bit character UCS-2 strings.Signed-off-by Maximilian Luz <[email protected]>
Regards,
Bjorn
Re: [PATCH v5 1/3] lib/ucs2_string: Add UCS-2 strscpy function
In reply to Maximilian LuzQuoted 36 lines · Maximilian Luz
Add a
ucs2_strscpy()function for UCS-2 strings. The behavior is equivalent to the standardstrscpy()function, just for 16-bit character UCS-2 strings.Signed-off-by Maximilian Luz <[email protected]>---
Changes in v5:
- Adducs2_strscpy()instead ofucs2_strlcpy()Patch introduced in v4.
--- include/linux/ucs2_string.h | 1 + lib/ucs2_string.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+)include/linux/ucs2_string.h +1
-0@@ -10,6 +10,7 @@ typedef u16 ucs2_char_t;unsigned long ucs2_strnlen (const ucs2_char_t *s,size_t maxlength);unsigned long ucs2_strlen (const ucs2_char_t *s);unsigned long ucs2_strsize (const ucs2_char_t *data,unsigned long maxlength); +ssize_t ucs2_strscpy (ucs2_char_t *dst,const ucs2_char_t *src,size_t count);int ucs2_strncmp (const ucs2_char_t *a,const ucs2_char_t *b,size_t len);unsigned long ucs2_utf8size (const ucs2_char_t *src);lib/ucs2_string.c +0
-0@@ -32,6 +32,41 @@ ucs2_strsize(const ucs2_char_t *data, unsigned long maxlength) }EXPORT_SYMBOL (ucs2_strsize);
lib/ucs2_string.c ucs2_strsize(const ucs2_char_t *data, unsigned long maxlength) · line 43
Quoted 10 lines
lib/ucs2_string.c +9
-0+ssize_t ucs2_strscpy (ucs2_char_t *dst,const ucs2_char_t *src,size_t count) +{ +long res; + +/* +* Ensure that we have a valid amount of space. We need to store at +* least one NUL-character. +*/ +if (count ==0 ||WARN_ON_ONCE (count >INT_MAX ))
Is "count" a measure of bytes or characters? It seems to be characters. can you please add some kern-doc for this function to clarify this. Also, I wonder if the above check should be "count > INT_MAX / 2" since the INT_MAX is, generally, done in byte counts.
lib/ucs2_string.c ucs2_strsize(const ucs2_char_t *data, unsigned long maxlength) · line 47
Quoted 4 lines
lib/ucs2_string.c +4
-0+return -E2BIG ; + +/* +* Copy at most 'count' bytes, return early if we find a
If "count" is characters, this comment should not say "bytes". :)
Quoted 28 lines
lib/ucs2_string.c +22
-0+* NUL-terminator. +*/ +for (res =0 ; res < count; res++) { +ucs2_char_t c; + + c = src[res]; + dst[res] = c; + +if (!c) +return res; + } + +/* +* The loop above terminated without finding a NUL-terminator, +* exceeding the 'count': Enforce proper NUL-termination and return +* error. +*/ + dst[count -1 ] =0 ; +return -E2BIG ; +} +EXPORT_SYMBOL (ucs2_strscpy); +int ucs2_strncmp (const ucs2_char_t *a,const ucs2_char_t *b,size_t len) {Signature · 1 line
2.41.0
Otherwise looks good to me!
Signature · 1 line
Kees Cook
Re: [PATCH v5 1/3] lib/ucs2_string: Add UCS-2 strscpy function
Quoted 38 lines · Kees Cook
Quoted 37 lines · Maximilian Luz
Add a
ucs2_strscpy()function for UCS-2 strings. The behavior is equivalent to the standardstrscpy()function, just for 16-bit character UCS-2 strings.Signed-off-by Maximilian Luz <[email protected]>---
Changes in v5:
- Adducs2_strscpy()instead ofucs2_strlcpy()Patch introduced in v4.
--- include/linux/ucs2_string.h | 1 + lib/ucs2_string.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+)include/linux/ucs2_string.h +1
-0@@ -10,6 +10,7 @@ typedef u16 ucs2_char_t;unsigned long ucs2_strnlen (const ucs2_char_t *s,size_t maxlength);unsigned long ucs2_strlen (const ucs2_char_t *s);unsigned long ucs2_strsize (const ucs2_char_t *data,unsigned long maxlength); +ssize_t ucs2_strscpy (ucs2_char_t *dst,const ucs2_char_t *src,size_t count);int ucs2_strncmp (const ucs2_char_t *a,const ucs2_char_t *b,size_t len);unsigned long ucs2_utf8size (const ucs2_char_t *src);lib/ucs2_string.c +0
-0@@ -32,6 +32,41 @@ ucs2_strsize(const ucs2_char_t *data, unsigned long maxlength) }EXPORT_SYMBOL (ucs2_strsize);
Quoted 14 lines
lib/ucs2_string.c ucs2_strsize(const ucs2_char_t *data, unsigned long maxlength) · line 43
Quoted 9 lines
lib/ucs2_string.c +9
-0+ssize_t ucs2_strscpy (ucs2_char_t *dst,const ucs2_char_t *src,size_t count) +{ +long res; + +/* +* Ensure that we have a valid amount of space. We need to store at +* least one NUL-character. +*/ +if (count ==0 ||WARN_ON_ONCE (count >INT_MAX ))Is "count" a measure of bytes or characters? It seems to be characters. can you please add some kern-doc for this function to clarify this. Also, I wonder if the above check should be "count >
INT_MAX/ 2" since theINT_MAXis, generally, done in byte counts.
Count is a measure of characters. I'll add a doc-comment.
Regarding INT_MAX / 2: I'm fine with either. I'd change it to INT_MAX / sizeof(*dst) if you say it's generally enforced in bytes.
Quoted 6 lines
lib/ucs2_string.c ucs2_strsize(const ucs2_char_t *data, unsigned long maxlength) · line 47
Quoted 4 lines
lib/ucs2_string.c +4
-0+return -E2BIG ; + +/* +* Copy at most 'count' bytes, return early if we find a If "count" is characters, this comment should not say "bytes". :)
Correct. Will fix this.
Quoted 22 lines
Quoted 22 lines
lib/ucs2_string.c +22
-0+* NUL-terminator. +*/ +for (res =0 ; res < count; res++) { +ucs2_char_t c; + + c = src[res]; + dst[res] = c; + +if (!c) +return res; + } + +/* +* The loop above terminated without finding a NUL-terminator, +* exceeding the 'count': Enforce proper NUL-termination and return +* error. +*/ + dst[count -1 ] =0 ; +return -E2BIG ; +} +EXPORT_SYMBOL (ucs2_strscpy); +
Quoted 8 lines
Quoted 6 lines
lib/ucs2_string.c +0
-0int ucs2_strncmp (const ucs2_char_t *a,const ucs2_char_t *b,size_t len) {Signature · 1 line
2.41.0Otherwise looks good to me!
Thanks!
Regards
Max
PATCH v5 2/3 firmware: qcom_scm: Add support for Qualcomm Secure Execution Environment SCM interface
In reply to Maximilian LuzAdd support for SCM calls to Secure OS and the Secure Execution Environment (SEE) residing in the TrustZone (TZ) via the QSEECOM interface. This allows communication with Secure/TZ applications, for example 'uefisecapp' managing access to UEFI variables.
For better separation, make qcom_scm spin up a dedicated child (platform) device in case QSEECOM support has been detected. The corresponding driver for this device is then responsible for managing any QSEECOM clients. Specifically, this driver attempts to automatically detect known and supported applications, creating a client (auxiliary) device for each one. The respective client/auxiliary driver is then responsible for managing and communicating with the application.
While this patch introduces only a very basic interface without the more advanced features (such as re-entrant and blocking SCM calls and listeners/callbacks), this is enough to talk to the aforementioned 'uefisecapp'.
---
Changes in v5:
- Add a dedicated platform device and corresponding for managing the QSEECOM clients. Unlike before, this device is now instantiated by qcom_scm.c if it detects QSEECOM support.
Changes in v4:
- Remove instantiation of dedicated QSEECOM device and load the driver via qcom_scm instead. In particular:
- Add a list of tested devices to ensure that we don't run into any issues with the currently unimplemented re-entrant calls.
- Use the QSEECOM version to check for general availability of the interface.
- Attempt to automatically detect available QSEECOM applications (and instantiate respective clients) based on a fixed list.
- Use auxiliary bus and devices for clients instead of MFD.
- Restructure DMA allocations: Use dma_map_single() directly inside qcom_scm_qseecom_app_send() instead of requiring clients to allocate DMA memory themselves.
Changes in v3:
- Rebase ontop of latest qcom_scm changes (qcom_scm.h moved).
- Move qcom_qseecom.h in accordance with qcom_scm.
Changes in v2:
- Bind the interface to a device.
- Establish a device link to the SCM device to ensure proper ordering.
- Register client apps as child devices instead of requiring them to be specified in the device tree.
- Rename (qctree -> qseecom) to allow differentiation between old (qseecom) and new (smcinvoke) interfaces to the trusted execution environment.
--- MAINTAINERS | 6 + drivers/firmware/Kconfig | 16 + drivers/firmware/Makefile | 1 + drivers/firmware/qcom_qseecom.c | 128 +++++++ drivers/firmware/qcom_scm.c | 392 +++++++++++++++++++++ include/linux/firmware/qcom/qcom_qseecom.h | 46 +++ include/linux/firmware/qcom/qcom_scm.h | 21 ++ 7 files changed, 610 insertions(+) create mode 100644 drivers/firmware/qcom_qseecom.c create mode 100644 include/linux/firmware/qcom/qcom_qseecom.h
MAINTAINERS +6 -0
@@ -17689,6 +17689,12 @@ S: Maintained F: Documentation/devicetree/bindings/mtd/qcom,nandc.yaml F: drivers/mtd/nand/raw/qcom_nandc.c +QUALCOMM QSEECOM DRIVER +M: Maximilian Luz <[email protected]> +L: [email protected] +S: Maintained +F: drivers/firmware/qcom_qseecom.c + QUALCOMM RMNET DRIVER M: Subash Abhinov Kasiviswanathan <[email protected]> M: Sean Tranchetti <[email protected]>
drivers/firmware/Kconfig +16 -0
@@ -226,6 +226,22 @@ config QCOM_SCM_DOWNLOAD_MODE_DEFAULT Say Y here to enable "download mode" by default. +config QCOM_QSEECOM + bool "Qualcomm QSEECOM interface driver" + depends on QCOM_SCM + help + Various Qualcomm SoCs have a Secure Execution Environment (SEE) running + in the Trust Zone. This module provides an interface to that via the + QSEECOM mechanism, using SCM calls. + + The QSEECOM interface allows, among other things, access to applications + running in the SEE. An example of such an application is 'uefisecapp', + which is required to access UEFI variables on certain systems. If + selected, the interface will also attempt to detect and register client + devices for supported applications. + + Select Y here to enable the QSEECOM interface driver. + config SYSFB bool select BOOT_VESA_SUPPORT
drivers/firmware/Makefile +1 -0
@@ -20,6 +20,7 @@ obj-$(CONFIG_RASPBERRYPI_FIRMWARE) += raspberrypi.o obj-$(CONFIG_FW_CFG_SYSFS) += qemu_fw_cfg.o obj-$(CONFIG_QCOM_SCM) += qcom-scm.o qcom-scm-objs += qcom_scm.o qcom_scm-smc.o qcom_scm-legacy.o +obj-$(CONFIG_QCOM_QSEECOM) += qcom_qseecom.o obj-$(CONFIG_SYSFB) += sysfb.o obj-$(CONFIG_SYSFB_SIMPLEFB) += sysfb_simplefb.o obj-$(CONFIG_TI_SCI_PROTOCOL) += ti_sci.o
drivers/firmware/qcom_qseecom.c new file +128 -0
128 lines not on this page · raw message
drivers/firmware/qcom_scm.c +392 -0
410 lines not on this page · raw message
include/linux/firmware/qcom/qcom_qseecom.h new file +46 -0
46 lines not on this page · raw message
include/linux/firmware/qcom/qcom_scm.h +21 -0
@@ -122,4 +122,25 @@ extern int qcom_scm_lmh_dcvsh(u32 payload_fn, u32 payload_reg, u32 payload_val,extern int qcom_scm_lmh_profile_change (u32 profile_id);extern bool qcom_scm_lmh_dcvsh_available (void ); +#ifdef CONFIG_QCOM_QSEECOM + +int qcom_scm_qseecom_app_get_id (const char *app_name,u32 *app_id); +int qcom_scm_qseecom_app_send (u32 app_id,void *req,size_t req_size,void *rsp, +size_t rsp_size); + +#else /* CONFIG_QCOM_QSEECOM */ + +int qcom_scm_qseecom_app_get_id (const char *app_name,u32 *app_id) +{ +return -EINVAL ; +} + +int qcom_scm_qseecom_app_send (u32 app_id,void *req,size_t req_size,void *rsp, +size_t rsp_size) +{ +return -EINVAL ; +} + +#endif /* CONFIG_QCOM_QSEECOM */ +#endif
Signature · 1 line
2.41.0
kernel test robot
build botRe: [PATCH v5 2/3] firmware: qcom_scm: Add support for Qualcomm Secure Execution Environment SCM interface
kernel test robot noticed the following build errors:
Hi Maximilian,
kernel test robot noticed the following build errors:
[auto build test ERROR on linus/master]
[also build test ERROR on v6.5-rc3 next-20230728]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Maximilian-Luz/lib-ucs2_string-Add-UCS-2-strscpy-function/20230731-002132 base: linus/master patch link: https://lore.kernel.org/r/20230730161906.606163-3-luzmaximilian%40gmail.com patch subject: [PATCH v5 2/3] firmware: qcom_scm: Add support for Qualcomm Secure Execution Environment SCM interface config: nios2-randconfig-r011-20230730 (https://download.01.org/0day-ci/archive/20230731/[email protected]/config) compiler: nios2-linux-gcc (GCC) 12.3.0 reproduce: (https://download.01.org/0day-ci/archive/20230731/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All error/warnings (new ones prefixed by >>):
nios2-linux-ld: drivers/firmware/qcom_scm-smc.o: in function `qcom_scm_qseecom_app_get_id':
>> drivers/firmware/qcom_scm-smc.c:136: multiple definition of `qcom_scm_qseecom_app_get_id'; drivers/firmware/qcom_scm.o:qcom_scm.c:(.text+0xc2c): first defined here nios2-linux-ld: drivers/firmware/qcom_scm-smc.o: in function `qcom_scm_qseecom_app_send': >> drivers/firmware/qcom_scm-smc.c:142: multiple definition of `qcom_scm_qseecom_app_send'; drivers/firmware/qcom_scm.o:qcom_scm.c:(.text+0xc34): first defined here
nios2-linux-ld: drivers/firmware/qcom_scm-legacy.o: in function `qcom_scm_qseecom_app_get_id':
drivers/firmware/qcom_scm-legacy.c:136: multiple definition of `qcom_scm_qseecom_app_get_id'; drivers/firmware/qcom_scm.o:qcom_scm.c:(.text+0xc2c): first defined here
nios2-linux-ld: drivers/firmware/qcom_scm-legacy.o: in function `qcom_scm_qseecom_app_send':
drivers/firmware/qcom_scm-legacy.c:142: multiple definition of `qcom_scm_qseecom_app_send'; drivers/firmware/qcom_scm.o:qcom_scm.c:(.text+0xc34): first defined here
--
In file included from drivers/firmware/qcom_scm-smc.c:11:
>> include/linux/firmware/qcom/qcom_scm.h:133:5: warning: no previous prototype for 'qcom_scm_qseecom_app_get_id' [-Wmissing-prototypes]
133 | int qcom_scm_qseecom_app_get_id(const char *app_name, u32 *app_id)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
>> include/linux/firmware/qcom/qcom_scm.h:138:5: warning: no previous prototype for 'qcom_scm_qseecom_app_send' [-Wmissing-prototypes] 138 | int qcom_scm_qseecom_app_send(u32 app_id, void *req, size_t req_size, void *rsp,
| ^~~~~~~~~~~~~~~~~~~~~~~~~
vim +136 drivers/firmware/qcom_scm-smc.c
6bf32599223634 drivers/firmware/qcom_scm-smc.c Guru Das Srinagesh 2023-01-13 117
6bf32599223634 drivers/firmware/qcom_scm-smc.c Guru Das Srinagesh 2023-01-13 118 static int __scm_smc_do(struct device *dev, struct arm_smccc_args *smc,
3f951ea627dae8 drivers/firmware/qcom_scm-64.c Elliot Berman 2020-01-07 119 struct arm_smccc_res *res, bool atomic)
1a5ea3b7a6ac6c drivers/firmware/qcom_scm-64.c Vivek Gautam 2019-09-20 120 {
6bf32599223634 drivers/firmware/qcom_scm-smc.c Guru Das Srinagesh 2023-01-13 121 int ret, retry_count = 0;
1a5ea3b7a6ac6c drivers/firmware/qcom_scm-64.c Vivek Gautam 2019-09-20 122
1a5ea3b7a6ac6c drivers/firmware/qcom_scm-64.c Vivek Gautam 2019-09-20 123 if (atomic) {
3f951ea627dae8 drivers/firmware/qcom_scm-64.c Elliot Berman 2020-01-07 124 __scm_smc_do_quirk(smc, res);
6bf32599223634 drivers/firmware/qcom_scm-smc.c Guru Das Srinagesh 2023-01-13 125 return 0;
1a5ea3b7a6ac6c drivers/firmware/qcom_scm-64.c Vivek Gautam 2019-09-20 126 }
1a5ea3b7a6ac6c drivers/firmware/qcom_scm-64.c Vivek Gautam 2019-09-20 127
1a5ea3b7a6ac6c drivers/firmware/qcom_scm-64.c Vivek Gautam 2019-09-20 128 do {
1a5ea3b7a6ac6c drivers/firmware/qcom_scm-64.c Vivek Gautam 2019-09-20 129 mutex_lock(&qcom_scm_lock);
1a5ea3b7a6ac6c drivers/firmware/qcom_scm-64.c Vivek Gautam 2019-09-20 130
6bf32599223634 drivers/firmware/qcom_scm-smc.c Guru Das Srinagesh 2023-01-13 131 ret = __scm_smc_do_quirk_handle_waitq(dev, smc, res);
1a5ea3b7a6ac6c drivers/firmware/qcom_scm-64.c Vivek Gautam 2019-09-20 132
1a5ea3b7a6ac6c drivers/firmware/qcom_scm-64.c Vivek Gautam 2019-09-20 133 mutex_unlock(&qcom_scm_lock);
1a5ea3b7a6ac6c drivers/firmware/qcom_scm-64.c Vivek Gautam 2019-09-20 134
6bf32599223634 drivers/firmware/qcom_scm-smc.c Guru Das Srinagesh 2023-01-13 135 if (ret)
6bf32599223634 drivers/firmware/qcom_scm-smc.c Guru Das Srinagesh 2023-01-13 @136 return ret;
6bf32599223634 drivers/firmware/qcom_scm-smc.c Guru Das Srinagesh 2023-01-13 137
1a5ea3b7a6ac6c drivers/firmware/qcom_scm-64.c Vivek Gautam 2019-09-20 138 if (res->a0 == QCOM_SCM_V2_EBUSY) {
1a5ea3b7a6ac6c drivers/firmware/qcom_scm-64.c Vivek Gautam 2019-09-20 139 if (retry_count++ > QCOM_SCM_EBUSY_MAX_RETRY)
1a5ea3b7a6ac6c drivers/firmware/qcom_scm-64.c Vivek Gautam 2019-09-20 140 break;
1a5ea3b7a6ac6c drivers/firmware/qcom_scm-64.c Vivek Gautam 2019-09-20 141 msleep(QCOM_SCM_EBUSY_WAIT_MS);
1a5ea3b7a6ac6c drivers/firmware/qcom_scm-64.c Vivek Gautam 2019-09-20 @142 }
1a5ea3b7a6ac6c drivers/firmware/qcom_scm-64.c Vivek Gautam 2019-09-20 143 } while (res->a0 == QCOM_SCM_V2_EBUSY);
6bf32599223634 drivers/firmware/qcom_scm-smc.c Guru Das Srinagesh 2023-01-13 144
6bf32599223634 drivers/firmware/qcom_scm-smc.c Guru Das Srinagesh 2023-01-13 145 return 0;
1a5ea3b7a6ac6c drivers/firmware/qcom_scm-64.c Vivek Gautam 2019-09-20 146 }
1a5ea3b7a6ac6c drivers/firmware/qcom_scm-64.c Vivek Gautam 2019-09-20 147 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Re: [PATCH v5 2/3] firmware: qcom_scm: Add support for Qualcomm Secure Execution Environment SCM interface
In reply to Maximilian LuzOn 7/30/23 18:19, Maximilian Luz wrote:
[...]
Quoted 16 lines
include/linux/firmware/qcom/qcom_scm.h +8
-0@@ -122,4 +122,25 @@ extern int qcom_scm_lmh_dcvsh(u32 payload_fn, u32 payload_reg, u32 payload_val,extern int qcom_scm_lmh_profile_change (u32 profile_id);extern bool qcom_scm_lmh_dcvsh_available (void ); +#ifdef CONFIG_QCOM_QSEECOM + +int qcom_scm_qseecom_app_get_id (const char *app_name,u32 *app_id); +int qcom_scm_qseecom_app_send (u32 app_id,void *req,size_t req_size,void *rsp, +size_t rsp_size); + +#else /* CONFIG_QCOM_QSEECOM */ +
include/linux/firmware/qcom/qcom_scm.h extern int qcom_scm_lmh_dcvsh(u32 payload_fn, u32 payload_reg, u32 payload_val, · line 142
Quoted 10 lines
include/linux/firmware/qcom/qcom_scm.h +10
-0+int qcom_scm_qseecom_app_get_id (const char *app_name,u32 *app_id) +{ +return -EINVAL ; +} + +int qcom_scm_qseecom_app_send (u32 app_id,void *req,size_t req_size,void *rsp, +size_t rsp_size) +{ +return -EINVAL ; +}
As the kernel test robot rightfully complained: I forgot to static inline both functions above. Already fixed for v6.
Regards
Max
kernel test robot
build botRe: [PATCH v5 2/3] firmware: qcom_scm: Add support for Qualcomm Secure Execution Environment SCM interface
In reply to Maximilian Luzkernel test robot noticed the following build errors:
Hi Maximilian,
kernel test robot noticed the following build errors:
[auto build test ERROR on linus/master]
[also build test ERROR on v6.5-rc3 next-20230728]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Maximilian-Luz/lib-ucs2_string-Add-UCS-2-strscpy-function/20230731-002132 base: linus/master patch link: https://lore.kernel.org/r/20230730161906.606163-3-luzmaximilian%40gmail.com patch subject: [PATCH v5 2/3] firmware: qcom_scm: Add support for Qualcomm Secure Execution Environment SCM interface config: arc-randconfig-r023-20230731 (https://download.01.org/0day-ci/archive/20230731/[email protected]/config) compiler: arc-elf-gcc (GCC) 12.3.0 reproduce: (https://download.01.org/0day-ci/archive/20230731/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All error/warnings (new ones prefixed by >>):
drivers/firmware/qcom_qseecom.c: In function 'qseecom_client_release':
>> drivers/firmware/qcom_qseecom.c:24:9: error: implicit declaration of function 'kfree' [-Werror=implicit-function-declaration]
24 | kfree(client);
| ^~~~~
drivers/firmware/qcom_qseecom.c: In function 'qseecom_client_register':
>> drivers/firmware/qcom_qseecom.c:50:18: error: implicit declaration of function 'kzalloc' [-Werror=implicit-function-declaration]
50 | client = kzalloc(sizeof(*client), GFP_KERNEL);
| ^~~~~~~
>> drivers/firmware/qcom_qseecom.c:50:16: warning: assignment to 'struct qseecom_client *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
50 | client = kzalloc(sizeof(*client), GFP_KERNEL);
| ^cc1: some warnings being treated as errors
vim +/kfree +24 drivers/firmware/qcom_qseecom.c
19
20 static void qseecom_client_release(struct device *dev)
21 {
22 struct qseecom_client *client = container_of(dev, struct qseecom_client, aux_dev.dev);
23
> 24 kfree(client);
25 }
26
27 static void qseecom_client_remove(void *data)
28 {
29 struct qseecom_client *client = data;
30
31 auxiliary_device_delete(&client->aux_dev);
32 auxiliary_device_uninit(&client->aux_dev);
33 }
34
35 static int qseecom_client_register(struct platform_device *qseecom_dev,
36 const struct qseecom_app_desc *desc)
37 {
38 struct qseecom_client *client;
39 u32 app_id;
40 int ret;
41
42 /* Try to find the app ID, skip device if not found */
43 ret = qcom_scm_qseecom_app_get_id(desc->app_name, &app_id);
44 if (ret)
45 return ret == -ENOENT ? 0 : ret;
46
47 dev_info(&qseecom_dev->dev, "setting up client for %s\n", desc->app_name);
48
49 /* Allocate and set-up the client device */
> 50 client = kzalloc(sizeof(*client), GFP_KERNEL);
51 if (!client)
52 return -ENOMEM;
53
54 client->aux_dev.name = desc->dev_name;
55 client->aux_dev.dev.parent = &qseecom_dev->dev;
56 client->aux_dev.dev.release = qseecom_client_release;
57 client->app_id = app_id;
58
59 ret = auxiliary_device_init(&client->aux_dev);
60 if (ret) {
61 kfree(client);
62 return ret;
63 }
64
65 ret = auxiliary_device_add(&client->aux_dev);
66 if (ret) {
67 auxiliary_device_uninit(&client->aux_dev);
68 return ret;
69 }
70
71 ret = devm_add_action_or_reset(&qseecom_dev->dev, qseecom_client_remove, client);
72 if (ret)
73 return ret;
74
75 return 0;
76 }
77 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [PATCH v5 2/3] firmware: qcom_scm: Add support for Qualcomm Secure Execution Environment SCM interface
In reply to Maximilian Luzkernel test robot noticed the following build warnings:
Hi Maximilian,
kernel test robot noticed the following build warnings:
[auto build test WARNING on linus/master]
[also build test WARNING on v6.5-rc3 next-20230728]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Maximilian-Luz/lib-ucs2_string-Add-UCS-2-strscpy-function/20230731-002132 base: linus/master patch link: https://lore.kernel.org/r/20230730161906.606163-3-luzmaximilian%40gmail.com patch subject: [PATCH v5 2/3] firmware: qcom_scm: Add support for Qualcomm Secure Execution Environment SCM interface config: riscv-randconfig-r022-20230731 (https://download.01.org/0day-ci/archive/20230731/[email protected]/config) compiler: clang version 17.0.0 (https://github.com/llvm/llvm-project.git 4a5ac14ee968ff0ad5d2cc1ffa0299048db4c88a) reproduce: (https://download.01.org/0day-ci/archive/20230731/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
560 | val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr));
| ~~~~~~~~~~ ^
include/uapi/linux/byteorder/little_endian.h:37:51: note: expanded from macro '__le16_to_cpu'
37 | #define __le16_to_cpu(x) ((__force __u16)(__le16)(x))
| ^
In file included from drivers/misc/fastrpc.c:7:
In file included from include/linux/dma-buf.h:16:
In file included from include/linux/iosys-map.h:10:
In file included from include/linux/io.h:13:
In file included from arch/riscv/include/asm/io.h:136:
include/asm-generic/io.h:573:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
573 | val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
| ~~~~~~~~~~ ^
include/uapi/linux/byteorder/little_endian.h:35:51: note: expanded from macro '__le32_to_cpu'
35 | #define __le32_to_cpu(x) ((__force __u32)(__le32)(x))
| ^
In file included from drivers/misc/fastrpc.c:7:
In file included from include/linux/dma-buf.h:16:
In file included from include/linux/iosys-map.h:10:
In file included from include/linux/io.h:13:
In file included from arch/riscv/include/asm/io.h:136:
include/asm-generic/io.h:584:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
584 | __raw_writeb(value, PCI_IOBASE + addr);
| ~~~~~~~~~~ ^
include/asm-generic/io.h:594:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
594 | __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr);
| ~~~~~~~~~~ ^
include/asm-generic/io.h:604:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
604 | __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr);
| ~~~~~~~~~~ ^
include/asm-generic/io.h:743:2: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
743 | insb(addr, buffer, count);
| ^~~~~~~~~~~~~~~~~~~~~~~~~
arch/riscv/include/asm/io.h:104:53: note: expanded from macro 'insb'
104 | #define insb(addr, buffer, count) __insb(PCI_IOBASE + (addr), buffer, count)
| ~~~~~~~~~~ ^
In file included from drivers/misc/fastrpc.c:7:
In file included from include/linux/dma-buf.h:16:
In file included from include/linux/iosys-map.h:10:
In file included from include/linux/io.h:13:
In file included from arch/riscv/include/asm/io.h:136:
include/asm-generic/io.h:751:2: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
751 | insw(addr, buffer, count);
| ^~~~~~~~~~~~~~~~~~~~~~~~~
arch/riscv/include/asm/io.h:105:53: note: expanded from macro 'insw'
105 | #define insw(addr, buffer, count) __insw(PCI_IOBASE + (addr), buffer, count)
| ~~~~~~~~~~ ^
In file included from drivers/misc/fastrpc.c:7:
In file included from include/linux/dma-buf.h:16:
In file included from include/linux/iosys-map.h:10:
In file included from include/linux/io.h:13:
In file included from arch/riscv/include/asm/io.h:136:
include/asm-generic/io.h:759:2: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
759 | insl(addr, buffer, count);
| ^~~~~~~~~~~~~~~~~~~~~~~~~
arch/riscv/include/asm/io.h:106:53: note: expanded from macro 'insl'
106 | #define insl(addr, buffer, count) __insl(PCI_IOBASE + (addr), buffer, count)
| ~~~~~~~~~~ ^
In file included from drivers/misc/fastrpc.c:7:
In file included from include/linux/dma-buf.h:16:
In file included from include/linux/iosys-map.h:10:
In file included from include/linux/io.h:13:
In file included from arch/riscv/include/asm/io.h:136:
include/asm-generic/io.h:768:2: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
768 | outsb(addr, buffer, count);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
arch/riscv/include/asm/io.h:118:55: note: expanded from macro 'outsb'
118 | #define outsb(addr, buffer, count) __outsb(PCI_IOBASE + (addr), buffer, count)
| ~~~~~~~~~~ ^
In file included from drivers/misc/fastrpc.c:7:
In file included from include/linux/dma-buf.h:16:
In file included from include/linux/iosys-map.h:10:
In file included from include/linux/io.h:13:
In file included from arch/riscv/include/asm/io.h:136:
include/asm-generic/io.h:777:2: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
777 | outsw(addr, buffer, count);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
arch/riscv/include/asm/io.h:119:55: note: expanded from macro 'outsw'
119 | #define outsw(addr, buffer, count) __outsw(PCI_IOBASE + (addr), buffer, count)
| ~~~~~~~~~~ ^
In file included from drivers/misc/fastrpc.c:7:
In file included from include/linux/dma-buf.h:16:
In file included from include/linux/iosys-map.h:10:
In file included from include/linux/io.h:13:
In file included from arch/riscv/include/asm/io.h:136:
include/asm-generic/io.h:786:2: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
786 | outsl(addr, buffer, count);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
arch/riscv/include/asm/io.h:120:55: note: expanded from macro 'outsl'
120 | #define outsl(addr, buffer, count) __outsl(PCI_IOBASE + (addr), buffer, count)
| ~~~~~~~~~~ ^
In file included from drivers/misc/fastrpc.c:7:
In file included from include/linux/dma-buf.h:16:
In file included from include/linux/iosys-map.h:10:
In file included from include/linux/io.h:13:
In file included from arch/riscv/include/asm/io.h:136:
include/asm-generic/io.h:1134:55: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
1134 | return (port > MMIO_UPPER_LIMIT) ? NULL : PCI_IOBASE + port;
| ~~~~~~~~~~ ^
In file included from drivers/misc/fastrpc.c:21:
>> include/linux/firmware/qcom/qcom_scm.h:133:5: warning: no previous prototype for function 'qcom_scm_qseecom_app_get_id' [-Wmissing-prototypes]
133 | int qcom_scm_qseecom_app_get_id(const char *app_name, u32 *app_id)
| ^
include/linux/firmware/qcom/qcom_scm.h:133:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
133 | int qcom_scm_qseecom_app_get_id(const char *app_name, u32 *app_id)
| ^
| static
>> include/linux/firmware/qcom/qcom_scm.h:138:5: warning: no previous prototype for function 'qcom_scm_qseecom_app_send' [-Wmissing-prototypes]
138 | int qcom_scm_qseecom_app_send(u32 app_id, void *req, size_t req_size, void *rsp,
| ^
include/linux/firmware/qcom/qcom_scm.h:138:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
138 | int qcom_scm_qseecom_app_send(u32 app_id, void *req, size_t req_size, void *rsp,
| ^
| static 15 warnings generated.
vim +/qcom_scm_qseecom_app_get_id +133 include/linux/firmware/qcom/qcom_scm.h
132
> 133 int qcom_scm_qseecom_app_get_id(const char *app_name, u32 *app_id)
134 {
135 return -EINVAL;
136 }
137
> 138 int qcom_scm_qseecom_app_send(u32 app_id, void *req, size_t req_size, void *rsp, 139 size_t rsp_size)
140 {
141 return -EINVAL;
142 }
143
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Re: [PATCH v5 2/3] firmware: qcom_scm: Add support for Qualcomm Secure Execution Environment SCM interface
In reply to Maximilian LuzOn 7/30/23 18:19, Maximilian Luz wrote:
[...]
Quoted 6 lines
drivers/firmware/qcom_qseecom.c new file +0
-0
drivers/firmware/qcom_qseecom.c line 10
Quoted 10 lines
drivers/firmware/qcom_qseecom.c new file +10
-0@@ -0,0 +1,128 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Driver for Qualcomm Secure Execution Environment (SEE) interface (QSEECOM). +* Responsible for setting up and managing QSEECOM client devices. +* +* Copyright (C) 2023 Maximilian Luz <[email protected]> +*/ +#include <linux/auxiliary_bus.h> +#include <linux/platform_device.h> +#include <linux/types.h>
This is missing a linux/slab.h include for kzalloc() and kfree(). Fixed for v6 as well.
Kernel test robot caught this as well... I guess I need to look into building with more warnings enabled because I didn't catch that on my system.
Regards
Max
Re: [PATCH v5 2/3] firmware: qcom_scm: Add support for Qualcomm Secure Execution Environment SCM interface
In reply to Maximilian Luzdrivers/firmware/qcom_qseecom.c line 10
Quoted 11 lines · Maximilian Luz
drivers/firmware/qcom_qseecom.c new file +10
-0@@ -0,0 +1,128 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Driver for Qualcomm Secure Execution Environment (SEE) interface (QSEECOM). +* Responsible for setting up and managing QSEECOM client devices. +* +* Copyright (C) 2023 Maximilian Luz <[email protected]> +*/ +#include <linux/auxiliary_bus.h> +#include <linux/platform_device.h> +#include <linux/types.h>
Looks like you're missing some includes like module.h and slab.h.
drivers/firmware/qcom_qseecom.c line 22
Quoted 7 lines
drivers/firmware/qcom_qseecom.c new file +6
-0+ +#include <linux/firmware/qcom/qcom_qseecom.h> +#include <linux/firmware/qcom/qcom_scm.h> +static void qseecom_client_release (struct device *dev) +{ + struct qseecom_client *client = container_of(dev, struct qseecom_client, aux_dev.dev);
Nit: Perhaps you can separate declaration and initialisation here to stay within 80 columns.
drivers/firmware/qcom_qseecom.c line 103
Quoted 8 lines
drivers/firmware/qcom_qseecom.c new file +7
-0+ +kfree (client); +} +static int qcom_qseecom_remove (struct platform_device *qseecom_dev) +{ +return 0 ;/* Nothing to do here, all is managed via devm. */ +}
You should just drop this one (even if it serves as documentation).
Quoted 9 lines
drivers/firmware/qcom_qseecom.c new file +9
-0+static struct platform_driver qcom_qseecom_driver = { + .driver = { + .name ="qcom_qseecom" , + }, + .probe = qcom_qseecom_probe, + .remove = qcom_qseecom_remove, +}; + +static int __init qcom_qseecom_init (void )
drivers/firmware/qcom_qseecom.c line 123
Quoted 10 lines
drivers/firmware/qcom_qseecom.c new file +10
-0+{ +return platform_driver_register (&qcom_qseecom_driver); +} +subsys_initcall (qcom_qseecom_init); + +static void __exit qcom_qseecom_exit(void) +{ +platform_driver_unregister (&qcom_qseecom_driver); +} +module_exit (qcom_qseecom_exit);
No need for this one either since this driver can only be built-in now.
drivers/firmware/qcom_qseecom.c line 128
Quoted 4 lines
drivers/firmware/qcom_qseecom.c new file +4
-0+MODULE_AUTHOR ("Maximilian Luz <[email protected]>" ); +MODULE_DESCRIPTION ("Driver for the Qualcomm SEE (QSEECOM) interface" ); +MODULE_LICENSE ("GPL" ); +MODULE_ALIAS ("platform:qcom_qseecom" );
No need for MODULE_ALIAS() either.
drivers/firmware/qcom_scm.c static int qcom_scm_find_dload_address(struct device *dev, u64 *addr) · line 1645
Quoted 5 lines
drivers/firmware/qcom_scm.c +5
-0+static void qcom_scm_qseecom_free (void *data) +{ +struct platform_device *qseecom_dev = data; + +platform_device_unregister (qseecom_dev);
Perhaps use platform_device_del() and platform_device_put() for symmetry as you're not using platform_device_register() below.
Quoted 17 lines
drivers/firmware/qcom_scm.c +17
-0+} + +static int qcom_scm_qseecom_init (struct qcom_scm *scm) +{ +struct platform_device *qseecom_dev; +u32 version; +int ret; + +/* +* Note: We do two steps of validation here: First, we try to query the +* QSEECOM version as a check to see if the interface exists on this +* device. Second, we check against known good devices due to current +* driver limitations (see comment in qcom_scm_qseecom_allowlist). +* +* Note that we deliberately do the machine check after the version +* check so that we can log potentially supported devices. This should +* be safe as downstream sources indicate that the version query is
drivers/firmware/qcom_scm.c static int qcom_scm_find_dload_address(struct device *dev, u64 *addr) · line 1672
Quoted 10 lines
drivers/firmware/qcom_scm.c +10
-0+* neither blocking nor reentrant. +*/ + ret =qcom_scm_qseecom_get_version (&version); +if (ret) +return 0 ; + +dev_info (scm->dev,"qseecom: found qseecom with version 0x%x\n" , version); + +if (!qcom_scm_qseecom_machine_is_allowed ()) { +dev_info (scm->dev,"qseecom: untested device, skipping\n" );
untested "machine"?
Quoted 35 lines
drivers/firmware/qcom_scm.c +31
-0+ return 0; + } + +/* +* Set up QSEECOM interface device. All application clients will be +* set up and managed by the corresponding driver for it. +*/ + qseecom_dev =platform_device_alloc ("qcom_qseecom" ,-1 ); +if (!qseecom_dev) +return -ENOMEM ; + + qseecom_dev->dev.parent = scm->dev; + + ret =platform_device_add (qseecom_dev); +if (ret) { +platform_device_put (qseecom_dev); +return ret; + } + +return devm_add_action_or_reset (scm->dev, qcom_scm_qseecom_free, qseecom_dev); +} + +#else /* CONFIG_QCOM_QSEECOM */ + +static int qcom_scm_qseecom_init (struct qcom_scm *scm) +{ +return 0 ; +} + +#endif /* CONFIG_QCOM_QSEECOM */ +/** * qcom_scm_is_available() - Checks if SCM is available */
drivers/firmware/qcom_scm.c static int qcom_scm_probe(struct platform_device *pdev) · line 1852
Quoted 5 lines
drivers/firmware/qcom_scm.c +2
-0@@ -1468,6 +1848,18 @@ static int qcom_scm_probe(struct platform_device *pdev)if (download_mode)qcom_scm_set_download_mode (true); +/* +* Initialize the QSEECOM interface. Note: QSEECOM is fairly
Nit: I'd add a line break and an empty line before the "Note:".
drivers/firmware/qcom_scm.c static int qcom_scm_probe(struct platform_device *pdev) · line 1861
Quoted 9 lines
drivers/firmware/qcom_scm.c +9
-0+* self-contained and this only adds the interface device (the driver +* of which does most of the heavy lifting). So any errors returned +* here should be either -ENOMEM or -EINVAL (with the latter only in +* case there's a bug in our code). This means that there is no need to +* bring down the whole SCM driver. Just log the error instead and let +* SCM live. +*/ + ret =qcom_scm_qseecom_init (scm); +WARN (ret <0 ,"failed to initialize qseecom: %d" , ret);
Missing '\n'.
Quoted 13 lines
include/linux/firmware/qcom/qcom_scm.h +9
-0+return 0 ; } +#ifdef CONFIG_QCOM_QSEECOM + +int qcom_scm_qseecom_app_get_id (const char *app_name,u32 *app_id); +int qcom_scm_qseecom_app_send (u32 app_id,void *req,size_t req_size,void *rsp, +size_t rsp_size); + +#else /* CONFIG_QCOM_QSEECOM */ +
include/linux/firmware/qcom/qcom_scm.h extern int qcom_scm_lmh_dcvsh(u32 payload_fn, u32 payload_reg, u32 payload_val, · line 142
Quoted 10 lines
include/linux/firmware/qcom/qcom_scm.h +10
-0+int qcom_scm_qseecom_app_get_id (const char *app_name,u32 *app_id) +{ +return -EINVAL ; +} + +int qcom_scm_qseecom_app_send (u32 app_id,void *req,size_t req_size,void *rsp, +size_t rsp_size) +{ +return -EINVAL ; +}
These should be static inline as you already noticed.
include/linux/firmware/qcom/qcom_scm.h extern int qcom_scm_lmh_dcvsh(u32 payload_fn, u32 payload_reg, u32 payload_val, · line 146
Quoted 4 lines
include/linux/firmware/qcom/qcom_scm.h +3
-0+ +#endif /* CONFIG_QCOM_QSEECOM */ +#endif
With the above fixed you can add my
Johan
Re: [PATCH v5 2/3] firmware: qcom_scm: Add support for Qualcomm Secure Execution Environment SCM interface
Quoted 15 lines · Johan Hovold
drivers/firmware/qcom_qseecom.c line 10
Quoted 11 lines · Maximilian Luz
drivers/firmware/qcom_qseecom.c new file +10
-0@@ -0,0 +1,128 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Driver for Qualcomm Secure Execution Environment (SEE) interface (QSEECOM). +* Responsible for setting up and managing QSEECOM client devices. +* +* Copyright (C) 2023 Maximilian Luz <[email protected]> +*/ +#include <linux/auxiliary_bus.h> +#include <linux/platform_device.h> +#include <linux/types.h> Looks like you're missing some includes like
module.handslab.h.
Right. I'll add both for the next version.
Quoted 10 lines
drivers/firmware/qcom_qseecom.c line 22
Quoted 7 lines
drivers/firmware/qcom_qseecom.c new file +6
-0+ +#include <linux/firmware/qcom/qcom_qseecom.h> +#include <linux/firmware/qcom/qcom_scm.h> +static void qseecom_client_release (struct device *dev) +{ + struct qseecom_client *client = container_of(dev, struct qseecom_client, aux_dev.dev);Nit: Perhaps you can separate declaration and initialisation here to stay within 80 columns.
Sure, I'll do that.
Quoted 10 lines
drivers/firmware/qcom_qseecom.c line 103
Quoted 8 lines
drivers/firmware/qcom_qseecom.c new file +7
-0+ +kfree (client); +} +static int qcom_qseecom_remove (struct platform_device *qseecom_dev) +{ +return 0 ;/* Nothing to do here, all is managed via devm. */ +}You should just drop this one (even if it serves as documentation).
Okay.
Quoted 13 lines
Quoted 13 lines
drivers/firmware/qcom_qseecom.c new file +13
-0+static struct platform_driver qcom_qseecom_driver = { + .driver = { + .name ="qcom_qseecom" , + }, + .probe = qcom_qseecom_probe, + .remove = qcom_qseecom_remove, +}; + +static int __init qcom_qseecom_init (void ) +{ +return platform_driver_register (&qcom_qseecom_driver); +} +subsys_initcall (qcom_qseecom_init);
Quoted 8 lines
drivers/firmware/qcom_qseecom.c line 123
Quoted 6 lines
drivers/firmware/qcom_qseecom.c new file +6
-0+ +static void __exit qcom_qseecom_exit(void) +{ +platform_driver_unregister (&qcom_qseecom_driver); +} +module_exit (qcom_qseecom_exit);No need for this one either since this driver can only be built-in now.
Right.
Quoted 6 lines
drivers/firmware/qcom_qseecom.c line 128
Quoted 4 lines
drivers/firmware/qcom_qseecom.c new file +4
-0+MODULE_AUTHOR ("Maximilian Luz <[email protected]>" ); +MODULE_DESCRIPTION ("Driver for the Qualcomm SEE (QSEECOM) interface" ); +MODULE_LICENSE ("GPL" ); +MODULE_ALIAS ("platform:qcom_qseecom" );No need for
MODULE_ALIAS()either.
Oh right. As long as the module and device name match this should work automatically, correct? I forgot about that.
Quoted 8 lines
drivers/firmware/qcom_scm.c static int qcom_scm_find_dload_address(struct device *dev, u64 *addr) · line 1645
Quoted 5 lines
drivers/firmware/qcom_scm.c +5
-0+static void qcom_scm_qseecom_free (void *data) +{ +struct platform_device *qseecom_dev = data; + +platform_device_unregister (qseecom_dev);Perhaps use
platform_device_del()andplatform_device_put()for symmetry as you're not usingplatform_device_register()below.
Sure, I can do that.
Quoted 21 lines
Quoted 21 lines
drivers/firmware/qcom_scm.c +21
-0+} + +static int qcom_scm_qseecom_init (struct qcom_scm *scm) +{ +struct platform_device *qseecom_dev; +u32 version; +int ret; + +/* +* Note: We do two steps of validation here: First, we try to query the +* QSEECOM version as a check to see if the interface exists on this +* device. Second, we check against known good devices due to current +* driver limitations (see comment in qcom_scm_qseecom_allowlist). +* +* Note that we deliberately do the machine check after the version +* check so that we can log potentially supported devices. This should +* be safe as downstream sources indicate that the version query is +* neither blocking nor reentrant. +*/ + ret =qcom_scm_qseecom_get_version (&version); +if (ret)
Quoted 8 lines
drivers/firmware/qcom_scm.c static int qcom_scm_find_dload_address(struct device *dev, u64 *addr) · line 1672
Quoted 6 lines
drivers/firmware/qcom_scm.c +6
-0+return 0 ; + +dev_info (scm->dev,"qseecom: found qseecom with version 0x%x\n" , version); + +if (!qcom_scm_qseecom_machine_is_allowed ()) { +dev_info (scm->dev,"qseecom: untested device, skipping\n" );untested "machine"?
That would be more consistent, yes.
Quoted 38 lines
Quoted 38 lines
drivers/firmware/qcom_scm.c +31
-0+ return 0; + } + +/* +* Set up QSEECOM interface device. All application clients will be +* set up and managed by the corresponding driver for it. +*/ + qseecom_dev =platform_device_alloc ("qcom_qseecom" ,-1 ); +if (!qseecom_dev) +return -ENOMEM ; + + qseecom_dev->dev.parent = scm->dev; + + ret =platform_device_add (qseecom_dev); +if (ret) { +platform_device_put (qseecom_dev); +return ret; + } + +return devm_add_action_or_reset (scm->dev, qcom_scm_qseecom_free, qseecom_dev); +} + +#else /* CONFIG_QCOM_QSEECOM */ + +static int qcom_scm_qseecom_init (struct qcom_scm *scm) +{ +return 0 ; +} + +#endif /* CONFIG_QCOM_QSEECOM */ +/** * qcom_scm_is_available() - Checks if SCM is available */ @@ -1468,6 +1848,18 @@ static int qcom_scm_probe(struct platform_device *pdev)if (download_mode)qcom_scm_set_download_mode (true);
Quoted 4 lines
drivers/firmware/qcom_scm.c static int qcom_scm_probe(struct platform_device *pdev) · line 1852
Quoted 2 lines
drivers/firmware/qcom_scm.c +2
-0+/* +* Initialize the QSEECOM interface. Note: QSEECOM is fairly Nit: I'd add a line break and an empty line before the "Note:".
Sure, I'll do that.
Quoted 11 lines
drivers/firmware/qcom_scm.c static int qcom_scm_probe(struct platform_device *pdev) · line 1861
Quoted 9 lines
drivers/firmware/qcom_scm.c +9
-0+* self-contained and this only adds the interface device (the driver +* of which does most of the heavy lifting). So any errors returned +* here should be either -ENOMEM or -EINVAL (with the latter only in +* case there's a bug in our code). This means that there is no need to +* bring down the whole SCM driver. Just log the error instead and let +* SCM live. +*/ + ret =qcom_scm_qseecom_init (scm); +WARN (ret <0 ,"failed to initialize qseecom: %d" , ret);Missing '\n'.
Right.
Quoted 17 lines
Quoted 17 lines
include/linux/firmware/qcom/qcom_scm.h +13
-0+return 0 ; } +#ifdef CONFIG_QCOM_QSEECOM + +int qcom_scm_qseecom_app_get_id (const char *app_name,u32 *app_id); +int qcom_scm_qseecom_app_send (u32 app_id,void *req,size_t req_size,void *rsp, +size_t rsp_size); + +#else /* CONFIG_QCOM_QSEECOM */ + +int qcom_scm_qseecom_app_get_id (const char *app_name,u32 *app_id) +{ +return -EINVAL ; +}
Quoted 8 lines
include/linux/firmware/qcom/qcom_scm.h extern int qcom_scm_lmh_dcvsh(u32 payload_fn, u32 payload_reg, u32 payload_val, · line 142
Quoted 6 lines
include/linux/firmware/qcom/qcom_scm.h +6
-0+ +int qcom_scm_qseecom_app_send (u32 app_id,void *req,size_t req_size,void *rsp, +size_t rsp_size) +{ +return -EINVAL ; +}These should be static inline as you already noticed.
Already done :)
Quoted 8 lines
include/linux/firmware/qcom/qcom_scm.h extern int qcom_scm_lmh_dcvsh(u32 payload_fn, u32 payload_reg, u32 payload_val, · line 146
Quoted 4 lines
include/linux/firmware/qcom/qcom_scm.h +3
-0+ +#endif /* CONFIG_QCOM_QSEECOM */ +#endif With the above fixed you can add my
Reviewed-by Johan Hovold <[email protected]>
Thanks!
Regards
Max
Re: [PATCH v5 2/3] firmware: qcom_scm: Add support for Qualcomm Secure Execution Environment SCM interface
Quoted 9 lines · Maximilian Luz
Quoted 5 lines · Johan Hovold
Quoted 1 line · Maximilian Luz
+MODULE_ALIAS("platform:qcom_qseecom");
No need for
MODULE_ALIAS()either.Oh right. As long as the module and device name match this should work automatically, correct? I forgot about that.
Yeah, the module alias is only used when determining which modules to load.
The driver and platform device will still be matched and bound based on their names.
Johan
PATCH v5 3/3 firmware: Add support for Qualcomm UEFI Secure Application
In reply to Maximilian LuzOn platforms using the Qualcomm UEFI Secure Application (uefisecapp), EFI variables cannot be accessed via the standard interface in EFI runtime mode. The respective functions return EFI_UNSUPPORTED. On these platforms, we instead need to talk to uefisecapp. This commit provides support for this and registers the respective efivars operations to access EFI variables from the kernel.
Communication with uefisecapp follows the Qualcomm QSEECOM / Secure OS conventions via the respective SCM call interface. This is also the reason why variable access works normally while boot services are active. During this time, said SCM interface is managed by the boot services. When calling ExitBootServices(), the ownership is transferred to the kernel. Therefore, UEFI must not use that interface itself (as multiple parties accessing this interface at the same time may lead to complications) and cannot access variables for us.
---
Changes in v5:
- Clean up some comments inside functions and remove simple ones.
Changes in v4:
- Adapt to changes in DMA allocation in patch 3.
- Rework alignment: Use native alignment of types instead of a general 8 byte alignment. While the windows driver uses 8 byte alignment for GUIDs, the native (4 byte) alignment seems to work fine here.
- Add a helper macro for determining size and layout of request and response buffers, taking care of proper alignment.
- Implement support for EFI's query_variable_info() call, which is now supported by the kernel (and expected by efivarfs).
- Move UCS-2 string helpers to lib/ucs2_string.c
Changes in v3:
- No functional changes.
Changes in v2:
- Rename (qctree -> qseecom) to allow differentiation between old (qseecom) and new (smcinvoke) interfaces to the trusted execution environment.
--- MAINTAINERS | 6 + drivers/firmware/Kconfig | 17 + drivers/firmware/Makefile | 1 + drivers/firmware/qcom_qseecom.c | 4 +- drivers/firmware/qcom_qseecom_uefisecapp.c | 869 +++++++++++++++++++++ 5 files changed, 896 insertions(+), 1 deletion(-) create mode 100644 drivers/firmware/qcom_qseecom_uefisecapp.c
MAINTAINERS +6 -0
@@ -17695,6 +17695,12 @@ L: [email protected] S: Maintained F: drivers/firmware/qcom_qseecom.c +QUALCOMM QSEECOM UEFISECAPP DRIVER +M: Maximilian Luz <[email protected]> +L: [email protected] +S: Maintained +F: drivers/firmware/qcom_qseecom_uefisecapp.c + QUALCOMM RMNET DRIVER M: Subash Abhinov Kasiviswanathan <[email protected]> M: Sean Tranchetti <[email protected]>
drivers/firmware/Kconfig +17 -0
@@ -242,6 +242,23 @@ config QCOM_QSEECOM Select Y here to enable the QSEECOM interface driver. +config QCOM_QSEECOM_UEFISECAPP + bool "Qualcomm SEE UEFI Secure App client driver" + depends on QCOM_SCM + depends on QCOM_QSEECOM + depends on EFI + help + Various Qualcomm SoCs do not allow direct access to EFI variables. + Instead, these need to be accessed via the UEFI Secure Application + (uefisecapp), residing in the Secure Execution Environment (SEE). + + This module provides a client driver for uefisecapp, installing efivar + operations to allow the kernel accessing EFI variables, and via that also + provide user-space with access to EFI variables via efivarfs. + + Select Y here to provide access to EFI variables on the aforementioned + platforms. + config SYSFB bool select BOOT_VESA_SUPPORT
drivers/firmware/Makefile +1 -0
@@ -21,6 +21,7 @@ obj-$(CONFIG_FW_CFG_SYSFS) += qemu_fw_cfg.o obj-$(CONFIG_QCOM_SCM) += qcom-scm.o qcom-scm-objs += qcom_scm.o qcom_scm-smc.o qcom_scm-legacy.o obj-$(CONFIG_QCOM_QSEECOM) += qcom_qseecom.o +obj-$(CONFIG_QCOM_QSEECOM_UEFISECAPP) += qcom_qseecom_uefisecapp.o obj-$(CONFIG_SYSFB) += sysfb.o obj-$(CONFIG_SYSFB_SIMPLEFB) += sysfb_simplefb.o obj-$(CONFIG_TI_SCI_PROTOCOL) += ti_sci.o
drivers/firmware/qcom_qseecom.c +3 -1
@@ -80,7 +80,9 @@ static int qseecom_client_register(struct platform_device *qseecom_dev,* assuming the app has already been loaded (usually by firmware bootloaders) * and its ID can be queried successfully. */ -static const struct qseecom_app_desc qcom_qseecom_apps[] = {}; +static const struct qseecom_app_desc qcom_qseecom_apps[] = { + {"qcom.tz.uefisecapp" ,"uefisecapp" }, +};static int qcom_qseecom_probe (struct platform_device *qseecom_dev) {
drivers/firmware/qcom_qseecom_uefisecapp.c new file +869 -0
869 lines not on this page · raw message
Signature · 1 line
2.41.0
Quoted 42 lines · Maximilian Luz
On platforms using the Qualcomm UEFI Secure Application (uefisecapp), EFI variables cannot be accessed via the standard interface in EFI runtime mode. The respective functions return
EFI_UNSUPPORTED. On these platforms, we instead need to talk to uefisecapp. This commit provides support for this and registers the respective efivars operations to access EFI variables from the kernel.Communication with uefisecapp follows the Qualcomm QSEECOM / Secure OS conventions via the respective SCM call interface. This is also the reason why variable access works normally while boot services are active. During this time, said SCM interface is managed by the boot services. When calling
ExitBootServices(), the ownership is transferred to the kernel. Therefore, UEFI must not use that interface itself (as multiple parties accessing this interface at the same time may lead to complications) and cannot access variables for us.Signed-off-by Maximilian Luz <[email protected]>---
Changes in v5:
- Clean up some comments inside functions and remove simple ones.Changes in v4:
- Adapt to changes in DMA allocation in patch 3.
- Rework alignment: Use native alignment of types instead of a general 8 byte alignment. While the windows driver uses 8 byte alignment for GUIDs, the native (4 byte) alignment seems to work fine here.
- Add a helper macro for determining size and layout of request and response buffers, taking care of proper alignment.
- Implement support for EFI'squery_variable_info()call, which is now supported by the kernel (and expected by efivarfs).
- Move UCS-2 string helpers tolib/ucs2_string.cChanges in v3:
- No functional changes.Changes in v2:
- Rename (qctree -> qseecom) to allow differentiation between old (qseecom) and new (smcinvoke) interfaces to the trusted execution environment.
Quoted 6 lines
--- MAINTAINERS | 6 + drivers/firmware/Kconfig | 17 + drivers/firmware/Makefile | 1 + drivers/firmware/qcom_qseecom.c | 4 +- drivers/firmware/qcom_qseecom_uefisecapp.c | 869 +++++++++++++++++++++
Any chance we could move the existing qcom stuff into qcom/ before adding more?
Quoted 906 lines
5 files changed, 896 insertions(+), 1 deletion(-) create mode 100644 drivers/firmware/qcom_qseecom_uefisecapp.cMAINTAINERS +6
-0@@ -17695,6 +17695,12 @@ L: [email protected] S: Maintained F: drivers/firmware/qcom_qseecom.c +QUALCOMM QSEECOM UEFISECAPP DRIVER +M: Maximilian Luz <[email protected]> +L: [email protected] +S: Maintained +F: drivers/firmware/qcom_qseecom_uefisecapp.c + QUALCOMM RMNET DRIVER M: Subash Abhinov Kasiviswanathan <[email protected]> M: Sean Tranchetti <[email protected]>drivers/firmware/Kconfig +17
-0@@ -242,6 +242,23 @@ config QCOM_QSEECOM Select Y here to enable the QSEECOM interface driver. +config QCOM_QSEECOM_UEFISECAPP + bool "Qualcomm SEE UEFI Secure App client driver" + depends on QCOM_SCM + depends on QCOM_QSEECOM + depends on EFI + help + Various Qualcomm SoCs do not allow direct access to EFI variables. + Instead, these need to be accessed via the UEFI Secure Application + (uefisecapp), residing in the Secure Execution Environment (SEE). + + This module provides a client driver for uefisecapp, installing efivar + operations to allow the kernel accessing EFI variables, and via that also + provide user-space with access to EFI variables via efivarfs. + + Select Y here to provide access to EFI variables on the aforementioned + platforms. + config SYSFB bool select BOOT_VESA_SUPPORTdrivers/firmware/Makefile +1
-0@@ -21,6 +21,7 @@ obj-$(CONFIG_FW_CFG_SYSFS) += qemu_fw_cfg.o obj-$(CONFIG_QCOM_SCM) += qcom-scm.o qcom-scm-objs += qcom_scm.o qcom_scm-smc.o qcom_scm-legacy.o obj-$(CONFIG_QCOM_QSEECOM) += qcom_qseecom.o +obj-$(CONFIG_QCOM_QSEECOM_UEFISECAPP) += qcom_qseecom_uefisecapp.o obj-$(CONFIG_SYSFB) += sysfb.o obj-$(CONFIG_SYSFB_SIMPLEFB) += sysfb_simplefb.o obj-$(CONFIG_TI_SCI_PROTOCOL) += ti_sci.odrivers/firmware/qcom_qseecom.c +3
-1@@ -80,7 +80,9 @@ static int qseecom_client_register(struct platform_device *qseecom_dev,* assuming the app has already been loaded (usually by firmware bootloaders) * and its ID can be queried successfully. */ -static const struct qseecom_app_desc qcom_qseecom_apps[] = {}; +static const struct qseecom_app_desc qcom_qseecom_apps[] = { + {"qcom.tz.uefisecapp" ,"uefisecapp" }, +};static int qcom_qseecom_probe (struct platform_device *qseecom_dev) {drivers/firmware/qcom_qseecom_uefisecapp.c new file +825
-0@@ -0,0 +1,869 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Client driver for Qualcomm UEFI Secure Application (qcom.tz.uefisecapp). +* Provides access to UEFI variables on platforms where they are secured by the +* aforementioned Secure Execution Environment (SEE) application. +* +* Copyright (C) 2023 Maximilian Luz <[email protected]> +*/ + +#include <linux/efi.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/mutex.h> +#include <linux/of.h> +#include <linux/platform_device.h> +#include <linux/slab.h> +#include <linux/types.h> +#include <linux/ucs2_string.h> + +#include <linux/firmware/qcom/qcom_qseecom.h> + +/* -- Qualcomm "uefisecapp" interface definitions. -------------------------- */ + +/* Maximum length of name string with null-terminator */ +#define QSEE_MAX_NAME_LEN 1024 + +#define QSEE_CMD_UEFI (x) (0x8000 | (x)) +#define QSEE_CMD_UEFI_GET_VARIABLE QSEE_CMD_UEFI(0) +#define QSEE_CMD_UEFI_SET_VARIABLE QSEE_CMD_UEFI(1) +#define QSEE_CMD_UEFI_GET_NEXT_VARIABLE QSEE_CMD_UEFI(2) +#define QSEE_CMD_UEFI_QUERY_VARIABLE_INFO QSEE_CMD_UEFI(3) + +/** +* struct qsee_req_uefi_get_variable - Request for GetVariable command. +* @command_id: The ID of the command. Must be %QSEE_CMD_UEFI_GET_VARIABLE. +* @length: Length of the request in bytes, including this struct and any +* parameters (name, GUID) stored after it as well as any padding +* thereof for alignment. +* @name_offset: Offset from the start of this struct to where the variable +* name is stored (as utf-16 string), in bytes. +* @name_size: Size of the name parameter in bytes, including null-terminator. +* @guid_offset: Offset from the start of this struct to where the GUID +* parameter is stored, in bytes. +* @guid_size: Size of the GUID parameter in bytes, i.e. sizeof(efi_guid_t). +* @data_size: Size of the output buffer, in bytes. +*/ +struct qsee_req_uefi_get_variable { +u32 command_id; +u32 length; +u32 name_offset; +u32 name_size; +u32 guid_offset; +u32 guid_size; +u32 data_size; +} __packed; + +/** +* struct qsee_rsp_uefi_get_variable - Response for GetVariable command. +* @command_id: The ID of the command. Should be %QSEE_CMD_UEFI_GET_VARIABLE. +* @length: Length of the response in bytes, including this struct and the +* returned data. +* @status: Status of this command. +* @attributes: EFI variable attributes. +* @data_offset: Offset from the start of this struct to where the data is +* stored, in bytes. +* @data_size: Size of the returned data, in bytes. In case status indicates +* that the buffer is too small, this will be the size required +* to store the EFI variable data. +*/ +struct qsee_rsp_uefi_get_variable { +u32 command_id; +u32 length; +u32 status; +u32 attributes; +u32 data_offset; +u32 data_size; +} __packed; + +/** +* struct qsee_req_uefi_set_variable - Request for the SetVariable command. +* @command_id: The ID of the command. Must be %QSEE_CMD_UEFI_SET_VARIABLE. +* @length: Length of the request in bytes, including this struct and any +* parameters (name, GUID, data) stored after it as well as any +* padding thereof required for alignment. +* @name_offset: Offset from the start of this struct to where the variable +* name is stored (as utf-16 string), in bytes. +* @name_size: Size of the name parameter in bytes, including null-terminator. +* @guid_offset: Offset from the start of this struct to where the GUID +* parameter is stored, in bytes. +* @guid_size: Size of the GUID parameter in bytes, i.e. sizeof(efi_guid_t). +* @attributes: The EFI variable attributes to set for this variable. +* @data_offset: Offset from the start of this struct to where the EFI variable +* data is stored, in bytes. +* @data_size: Size of EFI variable data, in bytes. +* +*/ +struct qsee_req_uefi_set_variable { +u32 command_id; +u32 length; +u32 name_offset; +u32 name_size; +u32 guid_offset; +u32 guid_size; +u32 attributes; +u32 data_offset; +u32 data_size; +} __packed; + +/** +* struct qsee_rsp_uefi_set_variable - Response for the SetVariable command. +* @command_id: The ID of the command. Should be %QSEE_CMD_UEFI_SET_VARIABLE. +* @length: The length of this response, i.e. the size of this struct in +* bytes. +* @status: Status of this command. +* @_unknown1: Unknown response field. +* @_unknown2: Unknown response field. +*/ +struct qsee_rsp_uefi_set_variable { +u32 command_id; +u32 length; +u32 status; +u32 _unknown1; +u32 _unknown2; +} __packed; + +/** +* struct qsee_req_uefi_get_next_variable - Request for the +* GetNextVariableName command. +* @command_id: The ID of the command. Must be +* %QSEE_CMD_UEFI_GET_NEXT_VARIABLE. +* @length: Length of the request in bytes, including this struct and any +* parameters (name, GUID) stored after it as well as any padding +* thereof for alignment. +* @guid_offset: Offset from the start of this struct to where the GUID +* parameter is stored, in bytes. +* @guid_size: Size of the GUID parameter in bytes, i.e. sizeof(efi_guid_t). +* @name_offset: Offset from the start of this struct to where the variable +* name is stored (as utf-16 string), in bytes. +* @name_size: Size of the name parameter in bytes, including null-terminator. +*/ +struct qsee_req_uefi_get_next_variable { +u32 command_id; +u32 length; +u32 guid_offset; +u32 guid_size; +u32 name_offset; +u32 name_size; +} __packed; + +/** +* struct qsee_rsp_uefi_get_next_variable - Response for the +* GetNextVariableName command. +* @command_id: The ID of the command. Should be +* %QSEE_CMD_UEFI_GET_NEXT_VARIABLE. +* @length: Length of the response in bytes, including this struct and any +* parameters (name, GUID) stored after it as well as any padding +* thereof for alignment. +* @status: Status of this command. +* @guid_size: Size of the GUID parameter in bytes, i.e. sizeof(efi_guid_t). +* @name_offset: Offset from the start of this struct to where the variable +* name is stored (as utf-16 string), in bytes. +* @name_size: Size of the name parameter in bytes, including null-terminator. +*/ +struct qsee_rsp_uefi_get_next_variable { +u32 command_id; +u32 length; +u32 status; +u32 guid_offset; +u32 guid_size; +u32 name_offset; +u32 name_size; +} __packed; + +/** +* struct qsee_req_uefi_query_variable_info - Response for the +* GetNextVariableName command. +* @command_id: The ID of the command. Must be +* %QSEE_CMD_UEFI_QUERY_VARIABLE_INFO. +* @length: The length of this request, i.e. the size of this struct in +* bytes. +* @attributes: The storage attributes to query the info for. +*/ +struct qsee_req_uefi_query_variable_info { +u32 command_id; +u32 length; +u32 attributes; +} __packed; + +/** +* struct qsee_rsp_uefi_query_variable_info - Response for the +* GetNextVariableName command. +* @command_id: The ID of the command. Must be +* %QSEE_CMD_UEFI_QUERY_VARIABLE_INFO. +* @length: The length of this response, i.e. the size of this +* struct in bytes. +* @status: Status of this command. +* @_pad: Padding. +* @storage_space: Full storage space size, in bytes. +* @remaining_space: Free storage space available, in bytes. +* @max_variable_size: Maximum variable data size, in bytes. +*/ +struct qsee_rsp_uefi_query_variable_info { +u32 command_id; +u32 length; +u32 status; +u32 _pad; +u64 storage_space; +u64 remaining_space; +u64 max_variable_size; +} __packed; + +/* -- Alignment helpers ----------------------------------------------------- */ + +/* +* Helper macro to ensure proper alignment of types (fields and arrays) when +* stored in some (contiguous) buffer. +* +* Note: The driver from which this one has been reverse-engineered expects an +* alignment of 8 bytes (64 bits) for GUIDs. Our definition of efi_guid_t, +* however, has an alignment of 4 byte (32 bits). So far, this seems to work +* fine here. See also the comment on the typedef of efi_guid_t. +*/ +#define qcuefi_buf_align_fields(fields...) \ + ({ \ + size_t __len = 0; \ + fields \ + __len; \ + }) + +#define __field_impl (size, align, offset) \ + ({ \ + size_t *__offset = (offset); \ + size_t __aligned; \ + \ + __aligned = ALIGN(__len, align); \ + __len = __aligned + (size); \ + \ + if (__offset) \ + *__offset = __aligned; \ + }); + +#define __array_offs (type, count, offset) \ + __field_impl(sizeof(type) * (count), __alignof__(type), offset) + +#define __array (type, count) __array_offs(type, count, NULL) +#define __field_offs (type, offset) __array_offs(type, 1, offset) +#define __field (type) __array_offs(type, 1, NULL) + +/* -- UEFI app interface. --------------------------------------------------- */ + +struct qcuefi_client { +struct qseecom_client *client; +struct efivars efivars; +}; + +static struct device *qcuefi_dev (struct qcuefi_client *qcuefi) +{ +return &qcuefi->client->aux_dev.dev; +} + +static efi_status_t qsee_uefi_status_to_efi (u32 status) +{ +u64 category = status &0xf0000000 ; +u64 code = status &0x0fffffff ; + +return category << (BITS_PER_LONG -32 ) | code; +} + +static efi_status_t qsee_uefi_get_variable (struct qcuefi_client *qcuefi,const efi_char16_t *name, +const efi_guid_t *guid,u32 *attributes, +unsigned long *data_size,void *data) +{ +struct qsee_req_uefi_get_variable *req_data; +struct qsee_rsp_uefi_get_variable *rsp_data; +unsigned long buffer_size = *data_size; +efi_status_t efi_status =EFI_SUCCESS ; +unsigned long name_length; +size_t guid_offs; +size_t name_offs; +size_t req_size; +size_t rsp_size; +ssize_t status; + +if (!name || !guid) +return EFI_INVALID_PARAMETER ; + + name_length =ucs2_strnlen (name,QSEE_MAX_NAME_LEN ) +1 ; +if (name_length >QSEE_MAX_NAME_LEN ) +return EFI_INVALID_PARAMETER ; + +if (buffer_size && !data) +return EFI_INVALID_PARAMETER ; + + req_size =qcuefi_buf_align_fields ( + __field(*req_data) + __array_offs(*name, name_length, &name_offs) +__field_offs (*guid, &guid_offs) + ); + + rsp_size =qcuefi_buf_align_fields ( + __field(*rsp_data) +__array (u8, buffer_size) + ); + + req_data =kzalloc (req_size,GFP_KERNEL ); +if (!req_data) { + efi_status =EFI_OUT_OF_RESOURCES ; + goto out; + } + + rsp_data =kzalloc (rsp_size,GFP_KERNEL ); +if (!rsp_data) { + efi_status =EFI_OUT_OF_RESOURCES ; + goto out_free_req; + } + + req_data->command_id =QSEE_CMD_UEFI_GET_VARIABLE ; + req_data->data_size = buffer_size; + req_data->name_offset = name_offs; + req_data->name_size = name_length *sizeof (*name); + req_data->guid_offset = guid_offs; + req_data->guid_size =sizeof (*guid); + req_data->length = req_size; + + status =ucs2_strscpy (((void *)req_data) + req_data->name_offset, name, name_length); +if (status <0 ) +return EFI_INVALID_PARAMETER ; + +memcpy (((void *)req_data) + req_data->guid_offset, guid, req_data->guid_size); + + status =qcom_qseecom_app_send (qcuefi->client, req_data, req_size, rsp_data, rsp_size); +if (status) { + efi_status =EFI_DEVICE_ERROR ; + goto out_free; + } + +if (rsp_data->command_id !=QSEE_CMD_UEFI_GET_VARIABLE ) { + efi_status =EFI_DEVICE_ERROR ; + goto out_free; + } + +if (rsp_data->length <sizeof (*rsp_data)) { + efi_status =EFI_DEVICE_ERROR ; + goto out_free; + } + +if (rsp_data->status) { +dev_dbg (qcuefi_dev (qcuefi),"%s: uefisecapp error: 0x%x\n" , + __func__, rsp_data->status); + efi_status =qsee_uefi_status_to_efi (rsp_data->status); + +/* Update size and attributes in case buffer is too small. */ +if (efi_status ==EFI_BUFFER_TOO_SMALL ) { + *data_size = rsp_data->data_size; +if (attributes) + *attributes = rsp_data->attributes; + } + + goto out_free; + } + +if (rsp_data->length > rsp_size) { + efi_status =EFI_DEVICE_ERROR ; + goto out_free; + } + +if (rsp_data->data_offset + rsp_data->data_size > rsp_data->length) { + efi_status =EFI_DEVICE_ERROR ; + goto out_free; + } + +/* +* Note: We need to set attributes and data size even if the buffer is +* too small and we won't copy any data. This is described in spec, so +* that callers can either allocate a buffer properly (with two calls +* to this function) or just read back attributes withouth having to +* deal with that. +* +* Specifically: +* - If we have a buffer size of zero and no buffer, just return the +* attributes, required size, and indicate success. +* - If the buffer size is nonzero but too small, indicate that as an +* error. +* - Otherwise, we are good to copy the data. +* +* Note that we have already ensured above that the buffer pointer is +* non-NULL if its size is nonzero. +*/ + *data_size = rsp_data->data_size; +if (attributes) + *attributes = rsp_data->attributes; + +if (buffer_size ==0 && !data) { + efi_status =EFI_SUCCESS ; + goto out_free; + } + +if (buffer_size < rsp_data->data_size) { + efi_status =EFI_BUFFER_TOO_SMALL ; + goto out_free; + } + +memcpy (data, ((void *)rsp_data) + rsp_data->data_offset, rsp_data->data_size); + +out_free: +kfree (rsp_data); +out_free_req: +kfree (req_data); +out: +return efi_status; +} + +static efi_status_t qsee_uefi_set_variable (struct qcuefi_client *qcuefi,const efi_char16_t *name, +const efi_guid_t *guid,u32 attributes, +unsigned long data_size,const void *data) +{ +struct qsee_req_uefi_set_variable *req_data; +struct qsee_rsp_uefi_set_variable *rsp_data; +efi_status_t efi_status =EFI_SUCCESS ; +unsigned long name_length; +size_t name_offs; +size_t guid_offs; +size_t data_offs; +size_t req_size; +ssize_t status; + +if (!name || !guid) +return EFI_INVALID_PARAMETER ; + + name_length =ucs2_strnlen (name,QSEE_MAX_NAME_LEN ) +1 ; +if (name_length >QSEE_MAX_NAME_LEN ) +return EFI_INVALID_PARAMETER ; + +/* +* Make sure we have some data if data_size is nonzero. Note that using +* a size of zero is a valid use-case described in spec and deletes the +* variable. +*/ +if (data_size && !data) +return EFI_INVALID_PARAMETER ; + + req_size =qcuefi_buf_align_fields ( + __field(*req_data) + __array_offs(*name, name_length, &name_offs) + __field_offs(*guid, &guid_offs) +__array_offs (u8, data_size, &data_offs) + ); + + req_data =kzalloc (req_size,GFP_KERNEL ); +if (!req_data) { + efi_status =EFI_OUT_OF_RESOURCES ; + goto out; + } + + rsp_data =kzalloc (sizeof (*rsp_data),GFP_KERNEL ); +if (!rsp_data) { + efi_status =EFI_OUT_OF_RESOURCES ; + goto out_free_req; + } + + req_data->command_id =QSEE_CMD_UEFI_SET_VARIABLE ; + req_data->attributes = attributes; + req_data->name_offset = name_offs; + req_data->name_size = name_length *sizeof (*name); + req_data->guid_offset = guid_offs; + req_data->guid_size =sizeof (*guid); + req_data->data_offset = data_offs; + req_data->data_size = data_size; + req_data->length = req_size; + + status =ucs2_strscpy (((void *)req_data) + req_data->name_offset, name, name_length); +if (status <0 ) +return EFI_INVALID_PARAMETER ; + +memcpy (((void *)req_data) + req_data->guid_offset, guid, req_data->guid_size); + +if (data_size) +memcpy (((void *)req_data) + req_data->data_offset, data, req_data->data_size); + + status =qcom_qseecom_app_send (qcuefi->client, req_data, req_size, rsp_data, +sizeof (*rsp_data)); +if (status) { + efi_status =EFI_DEVICE_ERROR ; + goto out_free; + } + +if (rsp_data->command_id !=QSEE_CMD_UEFI_SET_VARIABLE ) { + efi_status =EFI_DEVICE_ERROR ; + goto out_free; + } + +if (rsp_data->length !=sizeof (*rsp_data)) { + efi_status =EFI_DEVICE_ERROR ; + goto out_free; + } + +if (rsp_data->status) { +dev_dbg (qcuefi_dev (qcuefi),"%s: uefisecapp error: 0x%x\n" , + __func__, rsp_data->status); + efi_status =qsee_uefi_status_to_efi (rsp_data->status); + } + +out_free: +kfree (rsp_data); +out_free_req: +kfree (req_data); +out: +return efi_status; +} + +static efi_status_t qsee_uefi_get_next_variable (struct qcuefi_client *qcuefi, +unsigned long *name_size,efi_char16_t *name, +efi_guid_t *guid) +{ +struct qsee_req_uefi_get_next_variable *req_data; +struct qsee_rsp_uefi_get_next_variable *rsp_data; +efi_status_t efi_status =EFI_SUCCESS ; +size_t guid_offs; +size_t name_offs; +size_t req_size; +size_t rsp_size; +ssize_t status; + +if (!name_size || !name || !guid) +return EFI_INVALID_PARAMETER ; + +if (*name_size ==0 ) +return EFI_INVALID_PARAMETER ; + + req_size =qcuefi_buf_align_fields ( + __field(*req_data) + __field_offs(*guid, &guid_offs) +__array_offs (*name, *name_size /sizeof (*name), &name_offs) + ); + + rsp_size =qcuefi_buf_align_fields ( + __field(*rsp_data) + __field(*guid) +__array (*name, *name_size /sizeof (*name)) + ); + + req_data =kzalloc (req_size,GFP_KERNEL ); +if (!req_data) { + efi_status =EFI_OUT_OF_RESOURCES ; + goto out; + } + + rsp_data =kzalloc (rsp_size,GFP_KERNEL ); +if (!rsp_data) { + efi_status =EFI_OUT_OF_RESOURCES ; + goto out_free_req; + } + + req_data->command_id =QSEE_CMD_UEFI_GET_NEXT_VARIABLE ; + req_data->guid_offset = guid_offs; + req_data->guid_size =sizeof (*guid); + req_data->name_offset = name_offs; + req_data->name_size = *name_size; + req_data->length = req_size; + +memcpy (((void *)req_data) + req_data->guid_offset, guid, req_data->guid_size); + status =ucs2_strscpy (((void *)req_data) + req_data->name_offset, name, + *name_size /sizeof (*name)); +if (status <0 ) +return EFI_INVALID_PARAMETER ; + + status =qcom_qseecom_app_send (qcuefi->client, req_data, req_size, rsp_data, rsp_size); +if (status) { + efi_status =EFI_DEVICE_ERROR ; + goto out_free; + } + +if (rsp_data->command_id !=QSEE_CMD_UEFI_GET_NEXT_VARIABLE ) { + efi_status =EFI_DEVICE_ERROR ; + goto out_free; + } + +if (rsp_data->length <sizeof (*rsp_data)) { + efi_status =EFI_DEVICE_ERROR ; + goto out_free; + } + +if (rsp_data->status) { +dev_dbg (qcuefi_dev (qcuefi),"%s: uefisecapp error: 0x%x\n" , + __func__, rsp_data->status); + efi_status =qsee_uefi_status_to_efi (rsp_data->status); + +/* +* If the buffer to hold the name is too small, update the +* name_size with the required size, so that callers can +* reallocate it accordingly. +*/ +if (efi_status ==EFI_BUFFER_TOO_SMALL ) + *name_size = rsp_data->name_size; + + goto out_free; + } + +if (rsp_data->length > rsp_size) { + efi_status =EFI_DEVICE_ERROR ; + goto out_free; + } + +if (rsp_data->name_offset + rsp_data->name_size > rsp_data->length) { + efi_status =EFI_DEVICE_ERROR ; + goto out_free; + } + +if (rsp_data->guid_offset + rsp_data->guid_size > rsp_data->length) { + efi_status =EFI_DEVICE_ERROR ; + goto out_free; + } + +if (rsp_data->name_size > *name_size) { + *name_size = rsp_data->name_size; + efi_status =EFI_BUFFER_TOO_SMALL ; + goto out_free; + } + +if (rsp_data->guid_size !=sizeof (*guid)) { + efi_status =EFI_DEVICE_ERROR ; + goto out_free; + } + +memcpy (guid, ((void *)rsp_data) + rsp_data->guid_offset, rsp_data->guid_size); + status =ucs2_strscpy (name, ((void *)rsp_data) + rsp_data->name_offset, + rsp_data->name_size /sizeof (*name)); + *name_size = rsp_data->name_size; + +if (status <0 ) { +/* +* Return EFI_DEVICE_ERROR here because the buffer size should +* have already been validated above, causing this function to +* bail with EFI_BUFFER_TOO_SMALL. +*/ +return EFI_DEVICE_ERROR ; + } + +out_free: +kfree (rsp_data); +out_free_req: +kfree (req_data); +out: +return efi_status; +} + +static efi_status_t qsee_uefi_query_variable_info (struct qcuefi_client *qcuefi,u32 attr, +u64 *storage_space,u64 *remaining_space, +u64 *max_variable_size) +{ +struct qsee_req_uefi_query_variable_info *req_data; +struct qsee_rsp_uefi_query_variable_info *rsp_data; +efi_status_t efi_status =EFI_SUCCESS ; +int status; + + req_data =kzalloc (sizeof (*req_data),GFP_KERNEL ); +if (!req_data) { + efi_status =EFI_OUT_OF_RESOURCES ; + goto out; + } + + rsp_data =kzalloc (sizeof (*rsp_data),GFP_KERNEL ); +if (!rsp_data) { + efi_status =EFI_OUT_OF_RESOURCES ; + goto out_free_req; + } + + req_data->command_id =QSEE_CMD_UEFI_QUERY_VARIABLE_INFO ; + req_data->attributes = attr; + req_data->length =sizeof (*req_data); + + status =qcom_qseecom_app_send (qcuefi->client, req_data,sizeof (*req_data), rsp_data, +sizeof (*rsp_data)); +if (status) { + efi_status =EFI_DEVICE_ERROR ; + goto out_free; + } + +if (rsp_data->command_id !=QSEE_CMD_UEFI_QUERY_VARIABLE_INFO ) { + efi_status =EFI_DEVICE_ERROR ; + goto out_free; + } + +if (rsp_data->length !=sizeof (*rsp_data)) { + efi_status =EFI_DEVICE_ERROR ; + goto out_free; + } + +if (rsp_data->status) { +dev_dbg (qcuefi_dev (qcuefi),"%s: uefisecapp error: 0x%x\n" , + __func__, rsp_data->status); + efi_status =qsee_uefi_status_to_efi (rsp_data->status); + goto out_free; + } + +if (storage_space) + *storage_space = rsp_data->storage_space; + +if (remaining_space) + *remaining_space = rsp_data->remaining_space; + +if (max_variable_size) + *max_variable_size = rsp_data->max_variable_size; + +out_free: +kfree (rsp_data); +out_free_req: +kfree (req_data); +out: +return efi_status; +} + +/* -- Global efivar interface. ---------------------------------------------- */ + +static struct qcuefi_client *__qcuefi; +static DEFINE_MUTEX (__qcuefi_lock); + +static int qcuefi_set_reference (struct qcuefi_client *qcuefi) +{ +mutex_lock (&__qcuefi_lock); + +if (qcuefi && __qcuefi) { +mutex_unlock (&__qcuefi_lock); +return -EEXIST ; + } + + __qcuefi = qcuefi; + +mutex_unlock (&__qcuefi_lock); +return 0 ; +} + +static struct qcuefi_client *qcuefi_acquire (void ) +{ +mutex_lock (&__qcuefi_lock); +return __qcuefi; +} + +static void qcuefi_release (void ) +{ +mutex_unlock (&__qcuefi_lock); +} + +static efi_status_t qcuefi_get_variable (efi_char16_t *name,efi_guid_t *vendor,u32 *attr, +unsigned long *data_size,void *data) +{ +struct qcuefi_client *qcuefi; +efi_status_t status; + + qcuefi =qcuefi_acquire (); +if (!qcuefi) +return EFI_NOT_READY ; + + status =qsee_uefi_get_variable (qcuefi, name, vendor, attr, data_size, data); + +qcuefi_release (); +return status; +} + +static efi_status_t qcuefi_set_variable (efi_char16_t *name,efi_guid_t *vendor, +u32 attr,unsigned long data_size,void *data) +{ +struct qcuefi_client *qcuefi; +efi_status_t status; + + qcuefi =qcuefi_acquire (); +if (!qcuefi) +return EFI_NOT_READY ; + + status =qsee_uefi_set_variable (qcuefi, name, vendor, attr, data_size, data); + +qcuefi_release (); +return status; +} + +static efi_status_t qcuefi_get_next_variable (unsigned long *name_size,efi_char16_t *name, +efi_guid_t *vendor) +{ +struct qcuefi_client *qcuefi; +efi_status_t status; + + qcuefi =qcuefi_acquire (); +if (!qcuefi) +return EFI_NOT_READY ; + + status =qsee_uefi_get_next_variable (qcuefi, name_size, name, vendor); + +qcuefi_release (); +return status; +} + +static efi_status_t qcuefi_query_variable_info (u32 attr,u64 *storage_space,u64 *remaining_space, +u64 *max_variable_size) +{ +struct qcuefi_client *qcuefi; +efi_status_t status; + + qcuefi =qcuefi_acquire (); +if (!qcuefi) +return EFI_NOT_READY ; + + status =qsee_uefi_query_variable_info (qcuefi, attr, storage_space, remaining_space, + max_variable_size); + +qcuefi_release (); +return status; +} + +static const struct efivar_operations qcom_efivar_ops = { + .get_variable = qcuefi_get_variable, + .set_variable = qcuefi_set_variable, + .get_next_variable = qcuefi_get_next_variable, + .query_variable_info = qcuefi_query_variable_info, +}; + +/* -- Driver setup. --------------------------------------------------------- */ + +static int qcom_uefisecapp_probe (struct auxiliary_device *aux_dev, +const struct auxiliary_device_id *aux_dev_id) +{ +struct qcuefi_client *qcuefi; +int status; + + qcuefi =devm_kzalloc (&aux_dev->dev,sizeof (*qcuefi),GFP_KERNEL ); +if (!qcuefi)
drivers/firmware/qcom_qseecom_uefisecapp.c line 835
Quoted 10 lines
drivers/firmware/qcom_qseecom_uefisecapp.c new file +10
-0+return -ENOMEM ; + + qcuefi->client = container_of(aux_dev, struct qseecom_client, aux_dev); + +auxiliary_set_drvdata (aux_dev, qcuefi); + status =qcuefi_set_reference (qcuefi); +if (status) +return status; + + status =efivars_register (&qcuefi->efivars, &qcom_efivar_ops);
Will this also work if the EFI runtime services were already registered by the time we reach this point?
Quoted 37 lines
drivers/firmware/qcom_qseecom_uefisecapp.c new file +34
-1+if (status) +qcuefi_set_reference (NULL ); + +return status; +} + +static void qcom_uefisecapp_remove (struct auxiliary_device *aux_dev) +{ +struct qcuefi_client *qcuefi =auxiliary_get_drvdata (aux_dev); + +efivars_unregister (&qcuefi->efivars); +qcuefi_set_reference (NULL ); +} + +static const struct auxiliary_device_id qcom_uefisecapp_id_table[] = { + { .name ="qcom_qseecom.uefisecapp" }, + {} +}; +MODULE_DEVICE_TABLE (auxiliary, qcom_uefisecapp_id_table); + +static struct auxiliary_driver qcom_uefisecapp_driver = { + .probe = qcom_uefisecapp_probe, + .remove = qcom_uefisecapp_remove, + .id_table = qcom_uefisecapp_id_table, + .driver = { + .name ="qcom_qseecom_uefisecapp" , + .probe_type =PROBE_PREFER_ASYNCHRONOUS , + }, +}; +module_auxiliary_driver (qcom_uefisecapp_driver); + +MODULE_AUTHOR ("Maximilian Luz <[email protected]>" ); +MODULE_DESCRIPTION ("Client driver for Qualcomm SEE UEFI Secure App" ); +MODULE_LICENSE ("GPL" ); --2.41.0
Quoted 1 line · Ard Biesheuvel
On Sun, 30 Jul 2023 at 18:19, Maximilian Luz <[email protected]> wrote:
[...]
Quoted 15 lines
Quoted 15 lines
drivers/firmware/qcom_qseecom_uefisecapp.c new file +15
-0+/* -- Driver setup. --------------------------------------------------------- */ + +static int qcom_uefisecapp_probe (struct auxiliary_device *aux_dev, +const struct auxiliary_device_id *aux_dev_id) +{ +struct qcuefi_client *qcuefi; +int status; + + qcuefi =devm_kzalloc (&aux_dev->dev,sizeof (*qcuefi),GFP_KERNEL ); +if (!qcuefi) +return -ENOMEM ; + + qcuefi->client = container_of(aux_dev, struct qseecom_client, aux_dev); + +auxiliary_set_drvdata (aux_dev, qcuefi);
Quoted 8 lines
drivers/firmware/qcom_qseecom_uefisecapp.c line 835
Quoted 5 lines
drivers/firmware/qcom_qseecom_uefisecapp.c new file +5
-0+ status =qcuefi_set_reference (qcuefi); +if (status) +return status; + + status =efivars_register (&qcuefi->efivars, &qcom_efivar_ops);Will this also work if the EFI runtime services were already registered by the time we reach this point?
That's actually a good question. In short: No. However, let me explain that a bit:
First, we assume that we're the only other non-generic provider (arguably, multiple non-generic providers don't make much sense on a single platform anyway, so I'd say in that case it's okay to fail here).
Second, we assume that the generic ops are not going to be registered at all on the platforms that this implementation is used. In particular, on the platforms I've tested and heard reports from so far, "standard" efivars either aren't actively advertised as "supported" or they return EFI_UNSUPPORTED for all calls. So we assume that either the check in efisubsys_init() or in generic_ops_supported() prevents registration of the generic ops.
Further, I'd hope that the uefisecapp would not be loaded if generic ops would be supported on such a platform, thus preventing instantiation of the respective client device.
So the only issue that I can see is that if uefisecapp is loaded and generic ops are supported, we would need a way to choose one over the other. But I think that is fairly unlikely to happen and I think it would probably be best to sort that out then (e.g. by refusing to load this new driver with some additional check).
Apart from that case, there should not be any timing issues that could cause registration to fail spuriously.
Regards
Max
Ard Biesheuvel
Acked-byQuoted 49 lines · Maximilian Luz
Quoted 1 line · Ard Biesheuvel
On Sun, 30 Jul 2023 at 18:19, Maximilian Luz <[email protected]> wrote:
[...]
Quoted 15 lines
Quoted 15 lines
drivers/firmware/qcom_qseecom_uefisecapp.c new file +15
-0+/* -- Driver setup. --------------------------------------------------------- */ + +static int qcom_uefisecapp_probe (struct auxiliary_device *aux_dev, +const struct auxiliary_device_id *aux_dev_id) +{ +struct qcuefi_client *qcuefi; +int status; + + qcuefi =devm_kzalloc (&aux_dev->dev,sizeof (*qcuefi),GFP_KERNEL ); +if (!qcuefi) +return -ENOMEM ; + + qcuefi->client = container_of(aux_dev, struct qseecom_client, aux_dev); + +auxiliary_set_drvdata (aux_dev, qcuefi);Quoted 8 lines
drivers/firmware/qcom_qseecom_uefisecapp.c line 835
Quoted 5 lines
drivers/firmware/qcom_qseecom_uefisecapp.c new file +5
-0+ status =qcuefi_set_reference (qcuefi); +if (status) +return status; + + status =efivars_register (&qcuefi->efivars, &qcom_efivar_ops);Will this also work if the EFI runtime services were already registered by the time we reach this point?
That's actually a good question. In short: No. However, let me explain that a bit:
First, we assume that we're the only other non-generic provider (arguably, multiple non-generic providers don't make much sense on a single platform anyway, so I'd say in that case it's okay to fail here).
Second, we assume that the generic ops are not going to be registered at all on the platforms that this implementation is used. In particular, on the platforms I've tested and heard reports from so far, "standard" efivars either aren't actively advertised as "supported" or they return
EFI_UNSUPPORTEDfor all calls. So we assume that either the check inefisubsys_init()or ingeneric_ops_supported()prevents registration of the generic ops.Further, I'd hope that the uefisecapp would not be loaded if generic ops would be supported on such a platform, thus preventing instantiation of the respective client device.
Quoted 9 lines
So the only issue that I can see is that if uefisecapp is loaded and generic ops are supported, we would need a way to choose one over the other. But I think that is fairly unlikely to happen and I think it would probably be best to sort that out then (e.g. by refusing to load this new driver with some additional check).
Apart from that case, there should not be any timing issues that could cause registration to fail spuriously.
Fair enough.
The series looks good to me.
I take it this will go via the QCOM tree?
drivers/firmware/Kconfig config QCOM_QSEECOM · line 247
Quoted 3 lines · Maximilian Luz
drivers/firmware/Kconfig +3
-0+config QCOM_QSEECOM_UEFISECAPP + bool "Qualcomm SEE UEFI Secure App client driver" + depends on QCOM_SCM
No need for this one.
drivers/firmware/Kconfig config QCOM_QSEECOM · line 249
Quoted 2 lines
drivers/firmware/Kconfig +2
-0+ depends on QCOM_QSEECOM + depends on EFI
Johan
Quoted 7 lines · Johan Hovold
drivers/firmware/Kconfig config QCOM_QSEECOM · line 247
Quoted 3 lines · Maximilian Luz
drivers/firmware/Kconfig +3
-0+config QCOM_QSEECOM_UEFISECAPP + bool "Qualcomm SEE UEFI Secure App client driver" + depends on QCOM_SCMNo need for this one.
Oh right, forgot to remove that.
Quoted 4 lines
drivers/firmware/Kconfig config QCOM_QSEECOM · line 249
Quoted 2 lines
drivers/firmware/Kconfig +2
-0+ depends on QCOM_QSEECOM + depends on EFIReviewed-by Johan Hovold <[email protected]>
Thanks!
Regards
Max