Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

firmware: qcom_scm: Add qcom_scm_pas_get_rsc_table() to get resource table

Qualcomm remote processor may rely on Static and Dynamic resources for
it to be functional. Static resources are fixed like for example,
memory-mapped addresses required by the subsystem and dynamic
resources, such as shared memory in DDR etc., are determined at
runtime during the boot process.

For most of the Qualcomm SoCs, when run with Gunyah or older QHEE
hypervisor, all the resources whether it is static or dynamic, is
managed by the hypervisor. Dynamic resources if it is present for a
remote processor will always be coming from secure world via SMC call
while static resources may be present in remote processor firmware
binary or it may be coming qcom_scm_pas_get_rsc_table() SMC call along
with dynamic resources.

Some of the remote processor drivers, such as video, GPU, IPA, etc., do
not check whether resources are present in their remote processor
firmware binary. In such cases, the caller of this function should set
input_rt and input_rt_size as NULL and zero respectively. Remoteproc
framework has method to check whether firmware binary contain resources
or not and they should be pass resource table pointer to input_rt and
resource table size to input_rt_size and this will be forwarded to
TrustZone for authentication. TrustZone will then append the dynamic
resources and return the complete resource table in the passed output
buffer.

More about documentation on resource table format can be found in
include/linux/remoteproc.h

Signed-off-by: Mukesh Ojha <mukesh.ojha@oss.qualcomm.com>
Link: https://lore.kernel.org/r/20260105-kvmrprocv10-v10-11-022e96815380@oss.qualcomm.com
Signed-off-by: Bjorn Andersson <andersson@kernel.org>

authored by

Mukesh Ojha and committed by
Bjorn Andersson
8b9d2050 b0199258

+176
+171
drivers/firmware/qcom/qcom_scm.c
··· 27 27 #include <linux/of_reserved_mem.h> 28 28 #include <linux/platform_device.h> 29 29 #include <linux/reset-controller.h> 30 + #include <linux/remoteproc.h> 30 31 #include <linux/sizes.h> 31 32 #include <linux/types.h> 32 33 ··· 111 110 enum qcom_scm_qseecom_tz_cmd_info { 112 111 QSEECOM_TZ_CMD_INFO_VERSION = 3, 113 112 }; 113 + 114 + #define RSCTABLE_BUFFER_NOT_SUFFICIENT 20 114 115 115 116 #define QSEECOM_MAX_APP_NAME_SIZE 64 116 117 #define SHMBRIDGE_RESULT_NOTSUPP 4 ··· 768 765 return ret ? : res.result[0]; 769 766 } 770 767 EXPORT_SYMBOL_GPL(qcom_scm_pas_mem_setup); 768 + 769 + static void *__qcom_scm_pas_get_rsc_table(u32 pas_id, void *input_rt_tzm, 770 + size_t input_rt_size, 771 + size_t *output_rt_size) 772 + { 773 + struct qcom_scm_desc desc = { 774 + .svc = QCOM_SCM_SVC_PIL, 775 + .cmd = QCOM_SCM_PIL_PAS_GET_RSCTABLE, 776 + .arginfo = QCOM_SCM_ARGS(5, QCOM_SCM_VAL, QCOM_SCM_RO, QCOM_SCM_VAL, 777 + QCOM_SCM_RW, QCOM_SCM_VAL), 778 + .args[0] = pas_id, 779 + .owner = ARM_SMCCC_OWNER_SIP, 780 + }; 781 + struct qcom_scm_res res; 782 + void *output_rt_tzm; 783 + int ret; 784 + 785 + output_rt_tzm = qcom_tzmem_alloc(__scm->mempool, *output_rt_size, GFP_KERNEL); 786 + if (!output_rt_tzm) 787 + return ERR_PTR(-ENOMEM); 788 + 789 + desc.args[1] = qcom_tzmem_to_phys(input_rt_tzm); 790 + desc.args[2] = input_rt_size; 791 + desc.args[3] = qcom_tzmem_to_phys(output_rt_tzm); 792 + desc.args[4] = *output_rt_size; 793 + 794 + /* 795 + * Whether SMC fail or pass, res.result[2] will hold actual resource table 796 + * size. 797 + * 798 + * If passed 'output_rt_size' buffer size is not sufficient to hold the 799 + * resource table TrustZone sends, response code in res.result[1] as 800 + * RSCTABLE_BUFFER_NOT_SUFFICIENT so that caller can retry this SMC call 801 + * with output_rt_tzm buffer with res.result[2] size however, It should not 802 + * be of unresonable size. 803 + */ 804 + ret = qcom_scm_call(__scm->dev, &desc, &res); 805 + if (!ret && res.result[2] > SZ_1G) { 806 + ret = -E2BIG; 807 + goto free_output_rt; 808 + } 809 + 810 + *output_rt_size = res.result[2]; 811 + if (ret && res.result[1] == RSCTABLE_BUFFER_NOT_SUFFICIENT) 812 + ret = -EOVERFLOW; 813 + 814 + free_output_rt: 815 + if (ret) 816 + qcom_tzmem_free(output_rt_tzm); 817 + 818 + return ret ? ERR_PTR(ret) : output_rt_tzm; 819 + } 820 + 821 + /** 822 + * qcom_scm_pas_get_rsc_table() - Retrieve the resource table in passed output buffer 823 + * for a given peripheral. 824 + * 825 + * Qualcomm remote processor may rely on both static and dynamic resources for 826 + * its functionality. Static resources typically refer to memory-mapped addresses 827 + * required by the subsystem and are often embedded within the firmware binary 828 + * and dynamic resources, such as shared memory in DDR etc., are determined at 829 + * runtime during the boot process. 830 + * 831 + * On Qualcomm Technologies devices, it's possible that static resources are not 832 + * embedded in the firmware binary and instead are provided by TrustZone However, 833 + * dynamic resources are always expected to come from TrustZone. This indicates 834 + * that for Qualcomm devices, all resources (static and dynamic) will be provided 835 + * by TrustZone via the SMC call. 836 + * 837 + * If the remote processor firmware binary does contain static resources, they 838 + * should be passed in input_rt. These will be forwarded to TrustZone for 839 + * authentication. TrustZone will then append the dynamic resources and return 840 + * the complete resource table in output_rt_tzm. 841 + * 842 + * If the remote processor firmware binary does not include a resource table, 843 + * the caller of this function should set input_rt as NULL and input_rt_size 844 + * as zero respectively. 845 + * 846 + * More about documentation on resource table data structures can be found in 847 + * include/linux/remoteproc.h 848 + * 849 + * @ctx: PAS context 850 + * @pas_id: peripheral authentication service id 851 + * @input_rt: resource table buffer which is present in firmware binary 852 + * @input_rt_size: size of the resource table present in firmware binary 853 + * @output_rt_size: TrustZone expects caller should pass worst case size for 854 + * the output_rt_tzm. 855 + * 856 + * Return: 857 + * On success, returns a pointer to the allocated buffer containing the final 858 + * resource table and output_rt_size will have actual resource table size from 859 + * TrustZone. The caller is responsible for freeing the buffer. On failure, 860 + * returns ERR_PTR(-errno). 861 + */ 862 + struct resource_table *qcom_scm_pas_get_rsc_table(struct qcom_scm_pas_context *ctx, 863 + void *input_rt, 864 + size_t input_rt_size, 865 + size_t *output_rt_size) 866 + { 867 + struct resource_table empty_rsc = {}; 868 + size_t size = SZ_16K; 869 + void *output_rt_tzm; 870 + void *input_rt_tzm; 871 + void *tbl_ptr; 872 + int ret; 873 + 874 + ret = qcom_scm_clk_enable(); 875 + if (ret) 876 + return ERR_PTR(ret); 877 + 878 + ret = qcom_scm_bw_enable(); 879 + if (ret) 880 + goto disable_clk; 881 + 882 + /* 883 + * TrustZone can not accept buffer as NULL value as argument hence, 884 + * we need to pass a input buffer indicating that subsystem firmware 885 + * does not have resource table by filling resource table structure. 886 + */ 887 + if (!input_rt) { 888 + input_rt = &empty_rsc; 889 + input_rt_size = sizeof(empty_rsc); 890 + } 891 + 892 + input_rt_tzm = qcom_tzmem_alloc(__scm->mempool, input_rt_size, GFP_KERNEL); 893 + if (!input_rt_tzm) { 894 + ret = -ENOMEM; 895 + goto disable_scm_bw; 896 + } 897 + 898 + memcpy(input_rt_tzm, input_rt, input_rt_size); 899 + 900 + output_rt_tzm = __qcom_scm_pas_get_rsc_table(ctx->pas_id, input_rt_tzm, 901 + input_rt_size, &size); 902 + if (PTR_ERR(output_rt_tzm) == -EOVERFLOW) 903 + /* Try again with the size requested by the TZ */ 904 + output_rt_tzm = __qcom_scm_pas_get_rsc_table(ctx->pas_id, 905 + input_rt_tzm, 906 + input_rt_size, 907 + &size); 908 + if (IS_ERR(output_rt_tzm)) { 909 + ret = PTR_ERR(output_rt_tzm); 910 + goto free_input_rt; 911 + } 912 + 913 + tbl_ptr = kzalloc(size, GFP_KERNEL); 914 + if (!tbl_ptr) { 915 + qcom_tzmem_free(output_rt_tzm); 916 + ret = -ENOMEM; 917 + goto free_input_rt; 918 + } 919 + 920 + memcpy(tbl_ptr, output_rt_tzm, size); 921 + *output_rt_size = size; 922 + qcom_tzmem_free(output_rt_tzm); 923 + 924 + free_input_rt: 925 + qcom_tzmem_free(input_rt_tzm); 926 + 927 + disable_scm_bw: 928 + qcom_scm_bw_disable(); 929 + 930 + disable_clk: 931 + qcom_scm_clk_disable(); 932 + 933 + return ret ? ERR_PTR(ret) : tbl_ptr; 934 + } 935 + EXPORT_SYMBOL_GPL(qcom_scm_pas_get_rsc_table); 771 936 772 937 /** 773 938 * qcom_scm_pas_auth_and_reset() - Authenticate the given peripheral firmware
+1
drivers/firmware/qcom/qcom_scm.h
··· 105 105 #define QCOM_SCM_PIL_PAS_SHUTDOWN 0x06 106 106 #define QCOM_SCM_PIL_PAS_IS_SUPPORTED 0x07 107 107 #define QCOM_SCM_PIL_PAS_MSS_RESET 0x0a 108 + #define QCOM_SCM_PIL_PAS_GET_RSCTABLE 0x21 108 109 109 110 #define QCOM_SCM_SVC_IO 0x05 110 111 #define QCOM_SCM_IO_READ 0x01
+4
include/linux/firmware/qcom/qcom_scm.h
··· 88 88 int qcom_scm_pas_auth_and_reset(u32 pas_id); 89 89 int qcom_scm_pas_shutdown(u32 pas_id); 90 90 bool qcom_scm_pas_supported(u32 pas_id); 91 + struct resource_table *qcom_scm_pas_get_rsc_table(struct qcom_scm_pas_context *ctx, 92 + void *input_rt, size_t input_rt_size, 93 + size_t *output_rt_size); 94 + 91 95 int qcom_scm_pas_prepare_and_auth_reset(struct qcom_scm_pas_context *ctx); 92 96 93 97 int qcom_scm_io_readl(phys_addr_t addr, unsigned int *val);