2 * drivers/video/tegra/host/nvhost_cpuaccess.c
4 * Tegra Graphics Host Cpu Register Access
6 * Copyright (c) 2010, NVIDIA Corporation.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #include "nvhost_cpuaccess.h"
25 #include <linux/string.h>
27 #define cpuaccess_to_dev(ctx) container_of(ctx, struct nvhost_master, cpuaccess)
29 int nvhost_cpuaccess_init(struct nvhost_cpuaccess *ctx,
30 struct platform_device *pdev)
33 for (i = 0; i < NVHOST_MODULE_NUM; i++) {
35 mem = platform_get_resource(pdev, IORESOURCE_MEM, i+1);
37 dev_err(&pdev->dev, "missing module memory resource\n");
41 ctx->regs[i] = ioremap(mem->start, resource_size(mem));
43 dev_err(&pdev->dev, "failed to map module registers\n");
51 void nvhost_cpuaccess_deinit(struct nvhost_cpuaccess *ctx)
54 for (i = 0; i < NVHOST_MODULE_NUM; i++) {
55 iounmap(ctx->regs[i]);
56 release_resource(ctx->reg_mem[i]);
60 int nvhost_mutex_try_lock(struct nvhost_cpuaccess *ctx, unsigned int idx)
62 struct nvhost_master *dev = cpuaccess_to_dev(ctx);
63 void __iomem *sync_regs = dev->sync_aperture;
66 /* mlock registers returns 0 when the lock is aquired.
67 * writing 0 clears the lock. */
68 nvhost_module_busy(&dev->mod);
69 reg = readl(sync_regs + (HOST1X_SYNC_MLOCK_0 + idx * 4));
71 nvhost_module_idle(&dev->mod);
77 void nvhost_mutex_unlock(struct nvhost_cpuaccess *ctx, unsigned int idx)
79 struct nvhost_master *dev = cpuaccess_to_dev(ctx);
80 void __iomem *sync_regs = dev->sync_aperture;
81 writel(0, sync_regs + (HOST1X_SYNC_MLOCK_0 + idx * 4));
82 nvhost_module_idle(&dev->mod);
85 void nvhost_read_module_regs(struct nvhost_cpuaccess *ctx, u32 module,
86 u32 offset, size_t size, void *values)
88 struct nvhost_master *dev = cpuaccess_to_dev(ctx);
89 void __iomem *p = ctx->regs[module] + offset;
90 u32* out = (u32*)values;
93 nvhost_module_busy(&dev->mod);
99 nvhost_module_idle(&dev->mod);
102 void nvhost_write_module_regs(struct nvhost_cpuaccess *ctx, u32 module,
103 u32 offset, size_t size, const void *values)
105 struct nvhost_master *dev = cpuaccess_to_dev(ctx);
106 void __iomem *p = ctx->regs[module] + offset;
107 const u32* in = (const u32*)values;
110 nvhost_module_busy(&dev->mod);
116 nvhost_module_idle(&dev->mod);