Robin Murphy | fc058d3 | 2019-08-15 19:37:33 +0100 | [diff] [blame] | 1 | // 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 Murphy | 6d7dff6 | 2019-08-15 19:37:34 +0100 | [diff] [blame^] | 7 | #include <linux/of.h> |
| 8 | |
Robin Murphy | fc058d3 | 2019-08-15 19:37:33 +0100 | [diff] [blame] | 9 | #include "arm-smmu.h" |
| 10 | |
| 11 | |
Robin Murphy | 6d7dff6 | 2019-08-15 19:37:34 +0100 | [diff] [blame^] | 12 | static 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 | |
| 27 | static 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 | |
| 35 | static 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 */ |
| 44 | const struct arm_smmu_impl calxeda_impl = { |
| 45 | .read_reg = arm_smmu_read_ns, |
| 46 | .write_reg = arm_smmu_write_ns, |
| 47 | }; |
| 48 | |
| 49 | |
Robin Murphy | fc058d3 | 2019-08-15 19:37:33 +0100 | [diff] [blame] | 50 | struct arm_smmu_device *arm_smmu_impl_init(struct arm_smmu_device *smmu) |
| 51 | { |
Robin Murphy | 6d7dff6 | 2019-08-15 19:37:34 +0100 | [diff] [blame^] | 52 | if (of_property_read_bool(smmu->dev->of_node, |
| 53 | "calxeda,smmu-secure-config-access")) |
| 54 | smmu->impl = &calxeda_impl; |
| 55 | |
Robin Murphy | fc058d3 | 2019-08-15 19:37:33 +0100 | [diff] [blame] | 56 | return smmu; |
| 57 | } |