Commit fe1229b9 authored by Joerg Roedel's avatar Joerg Roedel
Browse files

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: default avatarJoerg Roedel <joro@8bytes.org>
parent a6870e92
Loading
Loading
Loading
Loading
+18 −17
Original line number Diff line number Diff line
@@ -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;

	for (i = 0; i < smmu->nregs; i++) {
	void __iomem *addr = smmu->regbase + offs;

		BUG_ON(addr < smmu->regs[i]);
		if (addr <= smmu->rege[i]) {
			writel(val, addr);
			return;
		}
	BUG_ON(!smmu_valid_reg(smmu, addr));

	return readl(addr);
}

	BUG();
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));

	writel(val, addr);
}

#define VA_PAGE_TO_PA(va, page)	\