1 // SPDX-License-Identifier: BSD-2-Clause 2 /* 3 * Copyright (C) 2019 Bryan O'Donoghue 4 * Copyright 2019 NXP 5 * 6 * Bryan O'Donoghue <bryan.odonoghue@linaro.org> 7 */ 8 9 #include <initcall.h> 10 #include <io.h> 11 #include <mm/core_memprot.h> 12 13 #include "imx_caam.h" 14 15 register_phys_mem_pgdir(MEM_AREA_IO_SEC, CAAM_BASE, CORE_MMU_PGDIR_SIZE); 16 init_caam(void)17static TEE_Result init_caam(void) 18 { 19 struct imx_caam_ctrl *caam; 20 uint32_t reg; 21 int i; 22 23 caam = (struct imx_caam_ctrl *) 24 core_mmu_get_va(CAAM_BASE, MEM_AREA_IO_SEC, 25 sizeof(struct imx_caam_ctrl)); 26 if (!caam) 27 return TEE_ERROR_GENERIC; 28 29 /* 30 * Set job-ring ownership to non-secure by default. 31 * A Linux kernel that runs after OP-TEE will run in normal-world 32 * so we want to enable that kernel to have total ownership of the 33 * CAAM job-rings. 34 * 35 * It is possible to use CAAM job-rings inside of OP-TEE i.e. in 36 * secure world code but, to do that OP-TEE and kernel should agree 37 * via a DTB which job-rings are owned by OP-TEE and which are 38 * owned by Kernel, something that the OP-TEE CAAM driver should 39 * set up. 40 * 41 * This code below simply sets a default for the case where no 42 * runtime OP-TEE CAAM code will be run 43 */ 44 for (i = 0; i < CAAM_NUM_JOB_RINGS; i++) { 45 reg = io_read32((vaddr_t)&caam->jr[i].jrmidr_ms); 46 reg |= JROWN_NS | JROWN_MID; 47 io_write32((vaddr_t)&caam->jr[i].jrmidr_ms, reg); 48 } 49 50 return TEE_SUCCESS; 51 } 52 53 driver_init(init_caam); 54