xref: /rk3399_ARM-atf/services/std_svc/drtm/drtm_dma_prot.c (revision 2a1cdee4f5e6fe0b90399e442075880acad1869e)
1 /*
2  * Copyright (c) 2022 Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier:    BSD-3-Clause
5  *
6  * DRTM DMA protection.
7  *
8  * Authors:
9  *      Lucian Paul-Trifu <lucian.paultrifu@gmail.com>
10  *
11  */
12 
13 #include <stdint.h>
14 #include <string.h>
15 
16 #include <common/debug.h>
17 
18 #include "drtm_dma_prot.h"
19 #include <plat/common/platform.h>
20 
21 /*
22  * This function checks that platform supports complete DMA protection.
23  * and returns false - if the platform supports complete DMA protection.
24  * and returns true - if the platform does not support complete DMA protection.
25  */
26 bool drtm_dma_prot_init(void)
27 {
28 	bool must_init_fail = false;
29 	const uintptr_t *smmus;
30 	size_t num_smmus = 0;
31 	unsigned int total_smmus;
32 
33 	/* Warns presence of non-host platforms */
34 	if (plat_has_non_host_platforms()) {
35 		WARN("DRTM: the platform includes trusted DMA-capable devices"
36 				" (non-host platforms)\n");
37 	}
38 
39 	/*
40 	 * DLME protection is uncertain on platforms with peripherals whose
41 	 * DMA is not managed by an SMMU. DRTM doesn't work on such platforms.
42 	 */
43 	if (plat_has_unmanaged_dma_peripherals()) {
44 		ERROR("DRTM: this platform does not provide DMA protection\n");
45 		must_init_fail = true;
46 	}
47 
48 	/*
49 	 * Check that the platform reported all SMMUs.
50 	 * It is acceptable if the platform doesn't have any SMMUs when it
51 	 * doesn't have any DMA-capable devices.
52 	 */
53 	total_smmus = plat_get_total_smmus();
54 	plat_enumerate_smmus(&smmus, &num_smmus);
55 	if (num_smmus != total_smmus) {
56 		ERROR("DRTM: could not discover all SMMUs\n");
57 		must_init_fail = true;
58 	}
59 
60 	return must_init_fail;
61 }
62