blob: 0657c85580cb43f3e16ca9879bea227e8ff1bf6e [file] [log] [blame]
Robin Murphyfc058d32019-08-15 19:37:33 +01001// SPDX-License-Identifier: GPL-2.0-only
2// Miscellaneous Arm SMMU implementation and integration quirks
3// Copyright (C) 2019 Arm Limited
4
5#define pr_fmt(fmt) "arm-smmu: " fmt
6
Robin Murphy6d7dff62019-08-15 19:37:34 +01007#include <linux/of.h>
8
Robin Murphyfc058d32019-08-15 19:37:33 +01009#include "arm-smmu.h"
10
11
Robin Murphy6d7dff62019-08-15 19:37:34 +010012static int arm_smmu_gr0_ns(int offset)
13{
14 switch(offset) {
15 case ARM_SMMU_GR0_sCR0:
16 case ARM_SMMU_GR0_sACR:
17 case ARM_SMMU_GR0_sGFSR:
18 case ARM_SMMU_GR0_sGFSYNR0:
19 case ARM_SMMU_GR0_sGFSYNR1:
20 case ARM_SMMU_GR0_sGFSYNR2:
21 return offset + 0x400;
22 default:
23 return offset;
24 }
25}
26
27static u32 arm_smmu_read_ns(struct arm_smmu_device *smmu, int page,
28 int offset)
29{
30 if (page == ARM_SMMU_GR0)
31 offset = arm_smmu_gr0_ns(offset);
32 return readl_relaxed(arm_smmu_page(smmu, page) + offset);
33}
34
35static void arm_smmu_write_ns(struct arm_smmu_device *smmu, int page,
36 int offset, u32 val)
37{
38 if (page == ARM_SMMU_GR0)
39 offset = arm_smmu_gr0_ns(offset);
40 writel_relaxed(val, arm_smmu_page(smmu, page) + offset);
41}
42
43/* Since we don't care for sGFAR, we can do without 64-bit accessors */
44const struct arm_smmu_impl calxeda_impl = {
45 .read_reg = arm_smmu_read_ns,
46 .write_reg = arm_smmu_write_ns,
47};
48
49
Robin Murphyfc058d32019-08-15 19:37:33 +010050struct arm_smmu_device *arm_smmu_impl_init(struct arm_smmu_device *smmu)
51{
Robin Murphy6d7dff62019-08-15 19:37:34 +010052 if (of_property_read_bool(smmu->dev->of_node,
53 "calxeda,smmu-secure-config-access"))
54 smmu->impl = &calxeda_impl;
55
Robin Murphyfc058d32019-08-15 19:37:33 +010056 return smmu;
57}