blob: ddb99634e71ea10cdcd8f10aca318f92eb6eb2c7 [file] [log] [blame]
Jeenu Viswambharan5c503042017-05-26 14:15:40 +01001/*
Antonio Nino Diazfeacba32018-08-21 16:12:29 +01002 * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
Jeenu Viswambharan5c503042017-05-26 14:15:40 +01003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <mmio.h>
8#include <smmu_v3.h>
Antonio Nino Diazfeacba32018-08-21 16:12:29 +01009#include <stdbool.h>
Jeenu Viswambharan5c503042017-05-26 14:15:40 +010010
11static inline uint32_t smmuv3_read_s_idr1(uintptr_t base)
12{
13 return mmio_read_32(base + SMMU_S_IDR1);
14}
15
16static inline uint32_t smmuv3_read_s_init(uintptr_t base)
17{
18 return mmio_read_32(base + SMMU_S_INIT);
19}
20
21static inline void smmuv3_write_s_init(uintptr_t base, uint32_t value)
22{
23 mmio_write_32(base + SMMU_S_INIT, value);
24}
25
Antonio Nino Diazfeacba32018-08-21 16:12:29 +010026/* Test for pending invalidate */
27static inline bool smmuv3_inval_pending(uintptr_t base)
28{
29 return (smmuv3_read_s_init(base) & SMMU_S_INIT_INV_ALL_MASK) != 0U;
30}
31
Jeenu Viswambharan5c503042017-05-26 14:15:40 +010032/*
33 * Initialize the SMMU by invalidating all secure caches and TLBs.
34 *
35 * Returns 0 on success, and -1 on failure.
36 */
37int smmuv3_init(uintptr_t smmu_base)
38{
39 uint32_t idr1_reg;
40
41 /*
42 * Invalidation of secure caches and TLBs is required only if the SMMU
43 * supports secure state. If not, it's implementation defined as to how
44 * SMMU_S_INIT register is accessed.
45 */
46 idr1_reg = smmuv3_read_s_idr1(smmu_base);
Antonio Nino Diazfeacba32018-08-21 16:12:29 +010047 if (((idr1_reg >> SMMU_S_IDR1_SECURE_IMPL_SHIFT) &
48 SMMU_S_IDR1_SECURE_IMPL_MASK) == 0U) {
Jeenu Viswambharan5c503042017-05-26 14:15:40 +010049 return -1;
50 }
51
52 /* Initiate invalidation, and wait for it to finish */
53 smmuv3_write_s_init(smmu_base, SMMU_S_INIT_INV_ALL_MASK);
Antonio Nino Diazfeacba32018-08-21 16:12:29 +010054 while (smmuv3_inval_pending(smmu_base))
Jeenu Viswambharan5c503042017-05-26 14:15:40 +010055 ;
56
57 return 0;
58}