xref: /optee_os/core/arch/arm/sm/pm.c (revision 1bb929836182ecb96d2d9d268daa807c67596396)
1 // SPDX-License-Identifier: BSD-2-Clause
2 /*
3  * Copyright 2017 NXP
4  *
5  * Peng Fan <peng.fan@nxp.com>
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright notice,
11  * this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright notice,
14  * this list of conditions and the following disclaimer in the documentation
15  * and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include <arm32.h>
31 #include <console.h>
32 #include <drivers/imx_uart.h>
33 #include <io.h>
34 #include <kernel/cache_helpers.h>
35 #include <kernel/generic_boot.h>
36 #include <kernel/misc.h>
37 #include <kernel/panic.h>
38 #include <kernel/pm_stubs.h>
39 #include <kernel/thread.h>
40 #include <kernel/tlb_helpers.h>
41 #include <kernel/tz_ssvce_pl310.h>
42 #include <mm/core_memprot.h>
43 #include <mm/core_mmu.h>
44 #include <platform_config.h>
45 #include <sm/optee_smc.h>
46 #include <sm/pm.h>
47 #include <sm/psci.h>
48 #include <sm/sm.h>
49 #include <stdint.h>
50 
51 #if CFG_TEE_CORE_NB_CORE > 4
52 #error "Max support 4 cores in one cluster now"
53 #endif
54 
55 void sm_pm_cpu_suspend_save(struct sm_pm_ctx *ctx, uint32_t sp)
56 {
57 	struct thread_core_local *p = thread_get_core_local();
58 
59 	p->sm_pm_ctx_phys = virt_to_phys((void *)ctx);
60 
61 	/* The content will be passed to sm_pm_cpu_do_resume as register sp */
62 	ctx->sp = sp;
63 	ctx->cpu_resume_addr =
64 		virt_to_phys((void *)(vaddr_t)sm_pm_cpu_do_resume);
65 
66 	sm_pm_cpu_do_suspend(ctx->suspend_regs);
67 
68 	dcache_op_level1(DCACHE_OP_CLEAN_INV);
69 
70 #ifdef CFG_PL310
71 	arm_cl2_cleanbyway(core_mmu_get_va(PL310_BASE, MEM_AREA_IO_SEC));
72 #endif
73 }
74