diff options
author | Joerg Roedel <joro@8bytes.org> | 2013-02-04 20:40:58 +0100 |
---|---|---|
committer | Joerg Roedel <joro@8bytes.org> | 2013-02-05 14:18:24 +0100 |
commit | fe1229b968e1bd391ce7a89bff51aed10d02b578 (patch) | |
tree | 95d3ccbf29ae844884a4e1a9e2279ed4141dcad4 /drivers/iommu | |
parent | a6870e928d1b2a97d95e7bf1aaefd3da34b83a85 (diff) | |
download | linux-3.10-fe1229b968e1bd391ce7a89bff51aed10d02b578.tar.gz linux-3.10-fe1229b968e1bd391ce7a89bff51aed10d02b578.tar.bz2 linux-3.10-fe1229b968e1bd391ce7a89bff51aed10d02b578.zip |
iommu/tegra: smmu: Use helper function to check for valid register offset
Do not repeat the checking loop in the read and write
functions. Use a single helper function for that check and
call it in both accessors.
Signed-off-by: Joerg Roedel <joro@8bytes.org>
Diffstat (limited to 'drivers/iommu')
-rw-r--r-- | drivers/iommu/tegra-smmu.c | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/drivers/iommu/tegra-smmu.c b/drivers/iommu/tegra-smmu.c index 2fecbe7fd7f..774728313f5 100644 --- a/drivers/iommu/tegra-smmu.c +++ b/drivers/iommu/tegra-smmu.c @@ -327,36 +327,37 @@ static struct smmu_device *smmu_handle; /* unique for a system */ /* * SMMU register accessors */ -static inline u32 smmu_read(struct smmu_device *smmu, size_t offs) +static bool inline smmu_valid_reg(struct smmu_device *smmu, + void __iomem *addr) { int i; for (i = 0; i < smmu->nregs; i++) { - void __iomem *addr = smmu->regbase + offs; - - BUG_ON(addr < smmu->regs[i]); + if (addr < smmu->regs[i]) + break; if (addr <= smmu->rege[i]) - return readl(addr); + return true; } - BUG(); + return false; } -static inline void smmu_write(struct smmu_device *smmu, u32 val, size_t offs) +static inline u32 smmu_read(struct smmu_device *smmu, size_t offs) { - int i; + void __iomem *addr = smmu->regbase + offs; - for (i = 0; i < smmu->nregs; i++) { - void __iomem *addr = smmu->regbase + offs; + BUG_ON(!smmu_valid_reg(smmu, addr)); - BUG_ON(addr < smmu->regs[i]); - if (addr <= smmu->rege[i]) { - writel(val, addr); - return; - } - } + return readl(addr); +} + +static inline void smmu_write(struct smmu_device *smmu, u32 val, size_t offs) +{ + void __iomem *addr = smmu->regbase + offs; + + BUG_ON(!smmu_valid_reg(smmu, addr)); - BUG(); + writel(val, addr); } #define VA_PAGE_TO_PA(va, page) \ |