diff options
| author | Joerg Roedel <joro@8bytes.org> | 2013-02-04 14:40:58 -0500 |
|---|---|---|
| committer | Joerg Roedel <joro@8bytes.org> | 2013-02-05 08:18:24 -0500 |
| commit | fe1229b968e1bd391ce7a89bff51aed10d02b578 (patch) | |
| tree | 95d3ccbf29ae844884a4e1a9e2279ed4141dcad4 | |
| parent | a6870e928d1b2a97d95e7bf1aaefd3da34b83a85 (diff) | |
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>
| -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 2fecbe7fd7fd..774728313f51 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 */ | |||
| 327 | /* | 327 | /* |
| 328 | * SMMU register accessors | 328 | * SMMU register accessors |
| 329 | */ | 329 | */ |
| 330 | static inline u32 smmu_read(struct smmu_device *smmu, size_t offs) | 330 | static bool inline smmu_valid_reg(struct smmu_device *smmu, |
| 331 | void __iomem *addr) | ||
| 331 | { | 332 | { |
| 332 | int i; | 333 | int i; |
| 333 | 334 | ||
| 334 | for (i = 0; i < smmu->nregs; i++) { | 335 | for (i = 0; i < smmu->nregs; i++) { |
| 335 | void __iomem *addr = smmu->regbase + offs; | 336 | if (addr < smmu->regs[i]) |
| 336 | 337 | break; | |
| 337 | BUG_ON(addr < smmu->regs[i]); | ||
| 338 | if (addr <= smmu->rege[i]) | 338 | if (addr <= smmu->rege[i]) |
| 339 | return readl(addr); | 339 | return true; |
| 340 | } | 340 | } |
| 341 | 341 | ||
| 342 | BUG(); | 342 | return false; |
| 343 | } | 343 | } |
| 344 | 344 | ||
| 345 | static inline void smmu_write(struct smmu_device *smmu, u32 val, size_t offs) | 345 | static inline u32 smmu_read(struct smmu_device *smmu, size_t offs) |
| 346 | { | 346 | { |
| 347 | int i; | 347 | void __iomem *addr = smmu->regbase + offs; |
| 348 | 348 | ||
| 349 | for (i = 0; i < smmu->nregs; i++) { | 349 | BUG_ON(!smmu_valid_reg(smmu, addr)); |
| 350 | void __iomem *addr = smmu->regbase + offs; | ||
| 351 | 350 | ||
| 352 | BUG_ON(addr < smmu->regs[i]); | 351 | return readl(addr); |
| 353 | if (addr <= smmu->rege[i]) { | 352 | } |
| 354 | writel(val, addr); | 353 | |
| 355 | return; | 354 | static inline void smmu_write(struct smmu_device *smmu, u32 val, size_t offs) |
| 356 | } | 355 | { |
| 357 | } | 356 | void __iomem *addr = smmu->regbase + offs; |
| 357 | |||
| 358 | BUG_ON(!smmu_valid_reg(smmu, addr)); | ||
| 358 | 359 | ||
| 359 | BUG(); | 360 | writel(val, addr); |
| 360 | } | 361 | } |
| 361 | 362 | ||
| 362 | #define VA_PAGE_TO_PA(va, page) \ | 363 | #define VA_PAGE_TO_PA(va, page) \ |
