Skip to content

Commit 4010e72

Browse files
committed
gpu: host1x: Use SMMU on Tegra124 and Tegra210
Tegra124 and Tegra210 support addressing more than 32 bits of physical memory. However, since their host1x does not support the wide GATHER opcode, they should use the SMMU if at all possible to ensure that all the system memory can be used for command buffers, irrespective of whether or not the host1x firewall is enabled. Tested-by: Jon Hunter <jonathanh@nvidia.com> Signed-off-by: Thierry Reding <treding@nvidia.com>
1 parent 501be6c commit 4010e72

1 file changed

Lines changed: 42 additions & 4 deletions

File tree

‎drivers/gpu/host1x/dev.c‎

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,17 +192,55 @@ static void host1x_setup_sid_table(struct host1x *host)
192192
}
193193
}
194194

195+
static bool host1x_wants_iommu(struct host1x *host1x)
196+
{
197+
/*
198+
* If we support addressing a maximum of 32 bits of physical memory
199+
* and if the host1x firewall is enabled, there's no need to enable
200+
* IOMMU support. This can happen for example on Tegra20, Tegra30
201+
* and Tegra114.
202+
*
203+
* Tegra124 and later can address up to 34 bits of physical memory and
204+
* many platforms come equipped with more than 2 GiB of system memory,
205+
* which requires crossing the 4 GiB boundary. But there's a catch: on
206+
* SoCs before Tegra186 (i.e. Tegra124 and Tegra210), the host1x can
207+
* only address up to 32 bits of memory in GATHER opcodes, which means
208+
* that command buffers need to either be in the first 2 GiB of system
209+
* memory (which could quickly lead to memory exhaustion), or command
210+
* buffers need to be treated differently from other buffers (which is
211+
* not possible with the current ABI).
212+
*
213+
* A third option is to use the IOMMU in these cases to make sure all
214+
* buffers will be mapped into a 32-bit IOVA space that host1x can
215+
* address. This allows all of the system memory to be used and works
216+
* within the limitations of the host1x on these SoCs.
217+
*
218+
* In summary, default to enable IOMMU on Tegra124 and later. For any
219+
* of the earlier SoCs, only use the IOMMU for additional safety when
220+
* the host1x firewall is disabled.
221+
*/
222+
if (host1x->info->dma_mask <= DMA_BIT_MASK(32)) {
223+
if (IS_ENABLED(CONFIG_TEGRA_HOST1X_FIREWALL))
224+
return false;
225+
}
226+
227+
return true;
228+
}
229+
195230
static struct iommu_domain *host1x_iommu_attach(struct host1x *host)
196231
{
197232
struct iommu_domain *domain = iommu_get_domain_for_dev(host->dev);
198233
int err;
199234

200235
/*
201-
* If the host1x firewall is enabled, there's no need to enable IOMMU
202-
* support. Similarly, if host1x is already attached to an IOMMU (via
203-
* the DMA API), don't try to attach again.
236+
* We may not always want to enable IOMMU support (for example if the
237+
* host1x firewall is already enabled and we don't support addressing
238+
* more than 32 bits of physical memory), so check for that first.
239+
*
240+
* Similarly, if host1x is already attached to an IOMMU (via the DMA
241+
* API), don't try to attach again.
204242
*/
205-
if (IS_ENABLED(CONFIG_TEGRA_HOST1X_FIREWALL) || domain)
243+
if (!host1x_wants_iommu(host) || domain)
206244
return domain;
207245

208246
host->group = iommu_group_get(host->dev);

0 commit comments

Comments
 (0)