Lines Matching +full:peripheral +full:- +full:to +full:- +full:memory
1 // SPDX-License-Identifier: GPL-2.0-only
11 #include <linux/dma-mapping.h>
21 #include <linux/reset-controller.h>
22 #include <linux/arm-smccc.h>
38 /* control access to the interconnect path */
82 ret = clk_prepare_enable(__scm->core_clk); in qcom_scm_clk_enable()
86 ret = clk_prepare_enable(__scm->iface_clk); in qcom_scm_clk_enable()
90 ret = clk_prepare_enable(__scm->bus_clk); in qcom_scm_clk_enable()
97 clk_disable_unprepare(__scm->iface_clk); in qcom_scm_clk_enable()
99 clk_disable_unprepare(__scm->core_clk); in qcom_scm_clk_enable()
106 clk_disable_unprepare(__scm->core_clk); in qcom_scm_clk_disable()
107 clk_disable_unprepare(__scm->iface_clk); in qcom_scm_clk_disable()
108 clk_disable_unprepare(__scm->bus_clk); in qcom_scm_clk_disable()
115 if (!__scm->path) in qcom_scm_bw_enable()
118 if (IS_ERR(__scm->path)) in qcom_scm_bw_enable()
119 return -EINVAL; in qcom_scm_bw_enable()
121 mutex_lock(&__scm->scm_bw_lock); in qcom_scm_bw_enable()
122 if (!__scm->scm_vote_count) { in qcom_scm_bw_enable()
123 ret = icc_set_bw(__scm->path, 0, UINT_MAX); in qcom_scm_bw_enable()
125 dev_err(__scm->dev, "failed to set bandwidth request\n"); in qcom_scm_bw_enable()
129 __scm->scm_vote_count++; in qcom_scm_bw_enable()
131 mutex_unlock(&__scm->scm_bw_lock); in qcom_scm_bw_enable()
138 if (IS_ERR_OR_NULL(__scm->path)) in qcom_scm_bw_disable()
141 mutex_lock(&__scm->scm_bw_lock); in qcom_scm_bw_disable()
142 if (__scm->scm_vote_count-- == 1) in qcom_scm_bw_disable()
143 icc_set_bw(__scm->path, 0, 0); in qcom_scm_bw_disable()
144 mutex_unlock(&__scm->scm_bw_lock); in qcom_scm_bw_disable()
171 * Per the "SMC calling convention specification", the 64-bit calling in __get_convention()
172 * convention can only be used when the client is 64-bit, otherwise in __get_convention()
177 * Device isn't required as there is only one argument - no device in __get_convention()
178 * needed to dma_map_single to secure world in __get_convention()
187 * QCOM_SCM_INFO_IS_CALL_AVAIL call, so we fallback to forcing ARM_64 in __get_convention()
190 * will be valid here to check if the compatible matches. in __get_convention()
192 if (of_device_is_compatible(__scm ? __scm->dev->of_node : NULL, "qcom,scm-sc7180")) { in __get_convention()
218 * qcom_scm_call() - Invoke a syscall in the secure world
223 * Sends a command to the SCM and waits for the command to finish processing.
224 * This should *only* be called in pre-emptible context.
238 return -EINVAL; in qcom_scm_call()
243 * qcom_scm_call_atomic() - atomic variation of qcom_scm_call()
248 * Sends a command to the SCM and waits for the command to finish processing.
263 return -EINVAL; in qcom_scm_call_atomic()
311 return -EINVAL; in qcom_scm_set_boot_addr()
318 return qcom_scm_call_atomic(__scm ? __scm->dev : NULL, &desc, NULL); in qcom_scm_set_boot_addr()
330 /* Apply to all CPUs in all affinity levels */ in qcom_scm_set_boot_addr_mc()
338 return -EOPNOTSUPP; in qcom_scm_set_boot_addr_mc()
340 return qcom_scm_call(__scm->dev, &desc, NULL); in qcom_scm_set_boot_addr_mc()
344 * qcom_scm_set_warm_boot_addr() - Set the warm boot address for all cpus
347 * Set the Linux entry point for the SCM to transfer control to when coming
353 /* Fallback to old SCM call */ in qcom_scm_set_warm_boot_addr()
360 * qcom_scm_set_cold_boot_addr() - Set the cold boot address for all cpus
366 /* Fallback to old SCM call */ in qcom_scm_set_cold_boot_addr()
373 * qcom_scm_cpu_power_down() - Power down the cpu
374 * @flags: Flags to flush cache
376 * This is an end point to power down cpu. If there was a pending interrupt,
377 * the control would return from this function, otherwise, the cpu jumps to the
390 qcom_scm_call_atomic(__scm ? __scm->dev : NULL, &desc, NULL); in qcom_scm_cpu_power_down()
407 ret = qcom_scm_call(__scm->dev, &desc, &res); in qcom_scm_set_remote_state()
425 return qcom_scm_call_atomic(__scm->dev, &desc, NULL); in __qcom_scm_set_dload_mode()
433 avail = __qcom_scm_is_call_available(__scm->dev, in qcom_scm_set_download_mode()
437 ret = __qcom_scm_set_dload_mode(__scm->dev, enable); in qcom_scm_set_download_mode()
438 } else if (__scm->dload_mode_addr) { in qcom_scm_set_download_mode()
439 ret = qcom_scm_io_writel(__scm->dload_mode_addr, in qcom_scm_set_download_mode()
442 dev_err(__scm->dev, in qcom_scm_set_download_mode()
447 dev_err(__scm->dev, "failed to set download mode: %d\n", ret); in qcom_scm_set_download_mode()
451 * qcom_scm_pas_init_image() - Initialize peripheral authentication service
452 * state machine for a given peripheral, using the
454 * @peripheral: peripheral id
455 * @metadata: pointer to memory containing ELF header, program header table
463 * Upon successful return, the PAS metadata context (@ctx) will be used to
464 * track the metadata allocation, this needs to be released by invoking
467 int qcom_scm_pas_init_image(u32 peripheral, const void *metadata, size_t size, in qcom_scm_pas_init_image() argument
477 .args[0] = peripheral, in qcom_scm_pas_init_image()
483 * During the scm call memory protection will be enabled for the meta in qcom_scm_pas_init_image()
485 * non-cachable to avoid XPU violations. in qcom_scm_pas_init_image()
487 mdata_buf = dma_alloc_coherent(__scm->dev, size, &mdata_phys, in qcom_scm_pas_init_image()
490 dev_err(__scm->dev, "Allocation of metadata buffer failed.\n"); in qcom_scm_pas_init_image()
491 return -ENOMEM; in qcom_scm_pas_init_image()
505 ret = qcom_scm_call(__scm->dev, &desc, &res); in qcom_scm_pas_init_image()
512 dma_free_coherent(__scm->dev, size, mdata_buf, mdata_phys); in qcom_scm_pas_init_image()
514 ctx->ptr = mdata_buf; in qcom_scm_pas_init_image()
515 ctx->phys = mdata_phys; in qcom_scm_pas_init_image()
516 ctx->size = size; in qcom_scm_pas_init_image()
524 * qcom_scm_pas_metadata_release() - release metadata context
529 if (!ctx->ptr) in qcom_scm_pas_metadata_release()
532 dma_free_coherent(__scm->dev, ctx->size, ctx->ptr, ctx->phys); in qcom_scm_pas_metadata_release()
534 ctx->ptr = NULL; in qcom_scm_pas_metadata_release()
535 ctx->phys = 0; in qcom_scm_pas_metadata_release()
536 ctx->size = 0; in qcom_scm_pas_metadata_release()
541 * qcom_scm_pas_mem_setup() - Prepare the memory related to a given peripheral
543 * @peripheral: peripheral id
544 * @addr: start address of memory area to prepare
545 * @size: size of the memory area to prepare
549 int qcom_scm_pas_mem_setup(u32 peripheral, phys_addr_t addr, phys_addr_t size) in qcom_scm_pas_mem_setup() argument
556 .args[0] = peripheral, in qcom_scm_pas_mem_setup()
571 ret = qcom_scm_call(__scm->dev, &desc, &res); in qcom_scm_pas_mem_setup()
580 * qcom_scm_pas_auth_and_reset() - Authenticate the given peripheral firmware
582 * @peripheral: peripheral id
586 int qcom_scm_pas_auth_and_reset(u32 peripheral) in qcom_scm_pas_auth_and_reset() argument
593 .args[0] = peripheral, in qcom_scm_pas_auth_and_reset()
606 ret = qcom_scm_call(__scm->dev, &desc, &res); in qcom_scm_pas_auth_and_reset()
615 * qcom_scm_pas_shutdown() - Shut down the remote processor
616 * @peripheral: peripheral id
620 int qcom_scm_pas_shutdown(u32 peripheral) in qcom_scm_pas_shutdown() argument
627 .args[0] = peripheral, in qcom_scm_pas_shutdown()
640 ret = qcom_scm_call(__scm->dev, &desc, &res); in qcom_scm_pas_shutdown()
650 * qcom_scm_pas_supported() - Check if the peripheral authentication service is
652 * @peripheral: peripheral id
654 * Returns true if PAS is supported for this peripheral, otherwise false.
656 bool qcom_scm_pas_supported(u32 peripheral) in qcom_scm_pas_supported() argument
663 .args[0] = peripheral, in qcom_scm_pas_supported()
668 if (!__qcom_scm_is_call_available(__scm->dev, QCOM_SCM_SVC_PIL, in qcom_scm_pas_supported()
672 ret = qcom_scm_call(__scm->dev, &desc, &res); in qcom_scm_pas_supported()
691 ret = qcom_scm_call(__scm->dev, &desc, &res); in __qcom_scm_pas_mss_reset()
700 return -EINVAL; in qcom_scm_pas_reset_assert()
702 return __qcom_scm_pas_mss_reset(__scm->dev, 1); in qcom_scm_pas_reset_assert()
709 return -EINVAL; in qcom_scm_pas_reset_deassert()
711 return __qcom_scm_pas_mss_reset(__scm->dev, 0); in qcom_scm_pas_reset_deassert()
732 ret = qcom_scm_call_atomic(__scm->dev, &desc, &res); in qcom_scm_io_readl()
751 return qcom_scm_call_atomic(__scm->dev, &desc, NULL); in qcom_scm_io_writel()
756 * qcom_scm_restore_sec_cfg_available() - Check if secure environment
759 * Return true if restore-cfg interface is supported, false if not.
763 return __qcom_scm_is_call_available(__scm->dev, QCOM_SCM_SVC_MP, in qcom_scm_restore_sec_cfg_available()
781 ret = qcom_scm_call(__scm->dev, &desc, &res); in qcom_scm_restore_sec_cfg()
799 ret = qcom_scm_call(__scm->dev, &desc, &res); in qcom_scm_iommu_secure_ptbl_size()
822 ret = qcom_scm_call(__scm->dev, &desc, NULL); in qcom_scm_iommu_secure_ptbl_init()
825 if (ret == -EPERM) in qcom_scm_iommu_secure_ptbl_init()
843 return qcom_scm_call(__scm->dev, &desc, NULL); in qcom_scm_iommu_set_cp_pool_size()
865 ret = qcom_scm_call(__scm->dev, &desc, &res); in qcom_scm_mem_protect_video_var()
899 * qcom_scm_assign_mem() - Make a secure call to reassign memory ownership
900 * @mem_addr: mem region whose ownership need to be reassigned
936 ptr = dma_alloc_coherent(__scm->dev, ptr_sz, &ptr_phys, GFP_KERNEL); in qcom_scm_assign_mem()
938 return -ENOMEM; in qcom_scm_assign_mem()
948 /* Fill details of mem buff to map */ in qcom_scm_assign_mem()
951 mem_to_map->mem_addr = cpu_to_le64(mem_addr); in qcom_scm_assign_mem()
952 mem_to_map->mem_size = cpu_to_le64(mem_sz); in qcom_scm_assign_mem()
959 destvm->vmid = cpu_to_le32(newvm->vmid); in qcom_scm_assign_mem()
960 destvm->perm = cpu_to_le32(newvm->perm); in qcom_scm_assign_mem()
961 destvm->ctx = 0; in qcom_scm_assign_mem()
962 destvm->ctx_size = 0; in qcom_scm_assign_mem()
963 next_vm |= BIT(newvm->vmid); in qcom_scm_assign_mem()
966 ret = __qcom_scm_assign_mem(__scm->dev, mem_to_map_phys, mem_to_map_sz, in qcom_scm_assign_mem()
968 dma_free_coherent(__scm->dev, ptr_sz, ptr, ptr_phys); in qcom_scm_assign_mem()
970 dev_err(__scm->dev, in qcom_scm_assign_mem()
971 "Assign memory protection call failed %d\n", ret); in qcom_scm_assign_mem()
972 return -EINVAL; in qcom_scm_assign_mem()
981 * qcom_scm_ocmem_lock_available() - is OCMEM lock/unlock interface available
985 return __qcom_scm_is_call_available(__scm->dev, QCOM_SCM_SVC_OCMEM, in qcom_scm_ocmem_lock_available()
991 * qcom_scm_ocmem_lock() - call OCMEM lock interface to assign an OCMEM
992 * region to the specified initiator
1012 return qcom_scm_call(__scm->dev, &desc, NULL); in qcom_scm_ocmem_lock()
1017 * qcom_scm_ocmem_unlock() - call OCMEM unlock interface to release an OCMEM
1035 return qcom_scm_call(__scm->dev, &desc, NULL); in qcom_scm_ocmem_unlock()
1040 * qcom_scm_ice_available() - Is the ICE key programming interface available?
1047 return __qcom_scm_is_call_available(__scm->dev, QCOM_SCM_SVC_ES, in qcom_scm_ice_available()
1049 __qcom_scm_is_call_available(__scm->dev, QCOM_SCM_SVC_ES, in qcom_scm_ice_available()
1055 * qcom_scm_ice_invalidate_key() - Invalidate an inline encryption key
1056 * @index: the keyslot to invalidate
1058 * The UFSHCI and eMMC standards define a standard way to do this, but it
1062 * call doesn't specify which ICE instance the keyslot belongs to.
1064 * Return: 0 on success; -errno on failure.
1076 return qcom_scm_call(__scm->dev, &desc, NULL); in qcom_scm_ice_invalidate_key()
1081 * qcom_scm_ice_set_key() - Set an inline encryption key
1082 * @index: the keyslot into which to set the key
1083 * @key: the key to program
1087 * individual plaintext and ciphertext. Given in 512-byte
1091 * can then be used to encrypt/decrypt UFS or eMMC I/O requests inline.
1093 * The UFSHCI and eMMC standards define a standard way to do this, but it
1097 * call doesn't specify which ICE instance the keyslot belongs to.
1099 * Return: 0 on success; -errno on failure.
1121 * 'key' may point to vmalloc()'ed memory, but we need to pass a in qcom_scm_ice_set_key()
1122 * physical address that's been properly flushed. The sanctioned way to in qcom_scm_ice_set_key()
1127 * keys is normally rare and thus not performance-critical. in qcom_scm_ice_set_key()
1130 keybuf = dma_alloc_coherent(__scm->dev, key_size, &key_phys, in qcom_scm_ice_set_key()
1133 return -ENOMEM; in qcom_scm_ice_set_key()
1137 ret = qcom_scm_call(__scm->dev, &desc, NULL); in qcom_scm_ice_set_key()
1141 dma_free_coherent(__scm->dev, key_size, keybuf, key_phys); in qcom_scm_ice_set_key()
1147 * qcom_scm_hdcp_available() - Check if secure environment supports HDCP.
1159 avail = __qcom_scm_is_call_available(__scm->dev, QCOM_SCM_SVC_HDCP, in qcom_scm_hdcp_available()
1169 * qcom_scm_hdcp_req() - Send HDCP request.
1172 * @resp: response buffer passed to SCM
1200 return -ERANGE; in qcom_scm_hdcp_req()
1206 ret = qcom_scm_call(__scm->dev, &desc, &res); in qcom_scm_hdcp_req()
1223 .args[2] = pt_fmt, /* 0: LPAE AArch32 - 1: AArch64 */ in qcom_scm_iommu_set_pt_format()
1227 return qcom_scm_call(__scm->dev, &desc, NULL); in qcom_scm_iommu_set_pt_format()
1243 return qcom_scm_call_atomic(__scm->dev, &desc, NULL); in qcom_scm_qsmmu500_wait_safe_toggle()
1249 return __qcom_scm_is_call_available(__scm->dev, QCOM_SCM_SVC_LMH, QCOM_SCM_LMH_LIMIT_DCVSH); in qcom_scm_lmh_dcvsh_available()
1263 return qcom_scm_call(__scm->dev, &desc, NULL); in qcom_scm_lmh_profile_change()
1286 payload_buf = dma_alloc_coherent(__scm->dev, payload_size, &payload_phys, GFP_KERNEL); in qcom_scm_lmh_dcvsh()
1288 return -ENOMEM; in qcom_scm_lmh_dcvsh()
1298 ret = qcom_scm_call(__scm->dev, &desc, NULL); in qcom_scm_lmh_dcvsh()
1300 dma_free_coherent(__scm->dev, payload_size, payload_buf, payload_phys); in qcom_scm_lmh_dcvsh()
1308 struct device_node *np = dev->of_node; in qcom_scm_find_dload_address()
1313 tcsr = of_parse_phandle(np, "qcom,dload-mode", 0); in qcom_scm_find_dload_address()
1322 ret = of_property_read_u32_index(np, "qcom,dload-mode", 1, &offset); in qcom_scm_find_dload_address()
1332 * qcom_scm_is_available() - Checks if SCM is available
1343 * TODO: Update this logic to include dynamic allocation and lookup of in qcom_scm_assert_valid_wq_ctx()
1347 dev_err(__scm->dev, "Firmware unexpectedly passed non-zero wq_ctx\n"); in qcom_scm_assert_valid_wq_ctx()
1348 return -EINVAL; in qcom_scm_assert_valid_wq_ctx()
1362 wait_for_completion(&__scm->waitq_comp); in qcom_scm_wait_for_wq_completion()
1375 complete(&__scm->waitq_comp); in qcom_scm_waitq_wakeup()
1389 dev_err(scm->dev, "GET_WQ_CTX SMC call failed: %d\n", ret); in qcom_scm_irq_handler()
1395 dev_err(scm->dev, "Invalid flags found for wq_ctx: %u\n", flags); in qcom_scm_irq_handler()
1413 scm = devm_kzalloc(&pdev->dev, sizeof(*scm), GFP_KERNEL); in qcom_scm_probe()
1415 return -ENOMEM; in qcom_scm_probe()
1417 ret = qcom_scm_find_dload_address(&pdev->dev, &scm->dload_mode_addr); in qcom_scm_probe()
1421 mutex_init(&scm->scm_bw_lock); in qcom_scm_probe()
1423 scm->path = devm_of_icc_get(&pdev->dev, NULL); in qcom_scm_probe()
1424 if (IS_ERR(scm->path)) in qcom_scm_probe()
1425 return dev_err_probe(&pdev->dev, PTR_ERR(scm->path), in qcom_scm_probe()
1426 "failed to acquire interconnect path\n"); in qcom_scm_probe()
1428 scm->core_clk = devm_clk_get_optional(&pdev->dev, "core"); in qcom_scm_probe()
1429 if (IS_ERR(scm->core_clk)) in qcom_scm_probe()
1430 return PTR_ERR(scm->core_clk); in qcom_scm_probe()
1432 scm->iface_clk = devm_clk_get_optional(&pdev->dev, "iface"); in qcom_scm_probe()
1433 if (IS_ERR(scm->iface_clk)) in qcom_scm_probe()
1434 return PTR_ERR(scm->iface_clk); in qcom_scm_probe()
1436 scm->bus_clk = devm_clk_get_optional(&pdev->dev, "bus"); in qcom_scm_probe()
1437 if (IS_ERR(scm->bus_clk)) in qcom_scm_probe()
1438 return PTR_ERR(scm->bus_clk); in qcom_scm_probe()
1440 scm->reset.ops = &qcom_scm_pas_reset_ops; in qcom_scm_probe()
1441 scm->reset.nr_resets = 1; in qcom_scm_probe()
1442 scm->reset.of_node = pdev->dev.of_node; in qcom_scm_probe()
1443 ret = devm_reset_controller_register(&pdev->dev, &scm->reset); in qcom_scm_probe()
1448 ret = clk_set_rate(scm->core_clk, INT_MAX); in qcom_scm_probe()
1453 __scm->dev = &pdev->dev; in qcom_scm_probe()
1455 init_completion(&__scm->waitq_comp); in qcom_scm_probe()
1459 if (irq != -ENXIO) in qcom_scm_probe()
1462 ret = devm_request_threaded_irq(__scm->dev, irq, NULL, qcom_scm_irq_handler, in qcom_scm_probe()
1463 IRQF_ONESHOT, "qcom-scm", __scm); in qcom_scm_probe()
1465 return dev_err_probe(scm->dev, ret, "Failed to request qcom-scm irq\n"); in qcom_scm_probe()
1472 * will cause the boot stages to enter download mode, unless in qcom_scm_probe()
1483 /* Clean shutdown, disable download mode to allow normal restart */ in qcom_scm_shutdown()
1491 { .compatible = "qcom,scm-apq8064" },
1492 { .compatible = "qcom,scm-apq8084" },
1493 { .compatible = "qcom,scm-ipq4019" },
1494 { .compatible = "qcom,scm-msm8953" },
1495 { .compatible = "qcom,scm-msm8974" },
1496 { .compatible = "qcom,scm-msm8996" },