Commit ca6444f3 authored by Dave Airlie's avatar Dave Airlie

Merge branch 'etnaviv/next' of https://git.pengutronix.de/git/lst/linux into drm-next

So what we have for this cycle is a bit of spring cleaning with removal
of unused register logging code and getting rid of the license text in
favor of SPDX, a few smaller MMU handling improvements and a timeout
calculation change, fixing premature fence wait timeouts after 50 days
of uptime.
Signed-off-by: default avatarDave Airlie <airlied@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/1526652437.28565.2.camel@pengutronix.de
parents 1dd6eb88 f6ffbd4f
...@@ -22,11 +22,3 @@ config DRM_ETNAVIV_THERMAL ...@@ -22,11 +22,3 @@ config DRM_ETNAVIV_THERMAL
help help
Compile in support for thermal throttling. Compile in support for thermal throttling.
Say Y unless you want to risk burning your SoC. Say Y unless you want to risk burning your SoC.
config DRM_ETNAVIV_REGISTER_LOGGING
bool "enable ETNAVIV register logging"
depends on DRM_ETNAVIV
help
Compile in support for logging register reads/writes in a format
that can be parsed by envytools demsm tool. If enabled, register
logging can be switched on via etnaviv.reglog=y module param.
// SPDX-License-Identifier: GPL-2.0
/* /*
* Copyright (C) 2014 Etnaviv Project * Copyright (C) 2014-2018 Etnaviv Project
* Author: Christian Gmeiner <christian.gmeiner@gmail.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "etnaviv_cmdbuf.h" #include "etnaviv_cmdbuf.h"
......
// SPDX-License-Identifier: GPL-2.0
/* /*
* Copyright (C) 2015 Etnaviv Project * Copyright (C) 2015-2018 Etnaviv Project
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <linux/kernel.h> #include <linux/kernel.h>
......
// SPDX-License-Identifier: GPL-2.0
/* /*
* Copyright (C) 2017 Etnaviv Project * Copyright (C) 2017-2018 Etnaviv Project
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <drm/drm_mm.h> #include <drm/drm_mm.h>
......
/* SPDX-License-Identifier: GPL-2.0 */
/* /*
* Copyright (C) 2017 Etnaviv Project * Copyright (C) 2017 Etnaviv Project
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __ETNAVIV_CMDBUF_H__ #ifndef __ETNAVIV_CMDBUF_H__
......
// SPDX-License-Identifier: GPL-2.0
/* /*
* Copyright (C) 2015 Etnaviv Project * Copyright (C) 2015-2018 Etnaviv Project
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <linux/component.h> #include <linux/component.h>
...@@ -25,57 +14,6 @@ ...@@ -25,57 +14,6 @@
#include "etnaviv_mmu.h" #include "etnaviv_mmu.h"
#include "etnaviv_perfmon.h" #include "etnaviv_perfmon.h"
#ifdef CONFIG_DRM_ETNAVIV_REGISTER_LOGGING
static bool reglog;
MODULE_PARM_DESC(reglog, "Enable register read/write logging");
module_param(reglog, bool, 0600);
#else
#define reglog 0
#endif
void __iomem *etnaviv_ioremap(struct platform_device *pdev, const char *name,
const char *dbgname)
{
struct resource *res;
void __iomem *ptr;
if (name)
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, name);
else
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
ptr = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(ptr)) {
dev_err(&pdev->dev, "failed to ioremap %s: %ld\n", name,
PTR_ERR(ptr));
return ptr;
}
if (reglog)
dev_printk(KERN_DEBUG, &pdev->dev, "IO:region %s 0x%p %08zx\n",
dbgname, ptr, (size_t)resource_size(res));
return ptr;
}
void etnaviv_writel(u32 data, void __iomem *addr)
{
if (reglog)
printk(KERN_DEBUG "IO:W %p %08x\n", addr, data);
writel(data, addr);
}
u32 etnaviv_readl(const void __iomem *addr)
{
u32 val = readl(addr);
if (reglog)
printk(KERN_DEBUG "IO:R %p %08x\n", addr, val);
return val;
}
/* /*
* DRM operations: * DRM operations:
*/ */
......
/* SPDX-License-Identifier: GPL-2.0 */
/* /*
* Copyright (C) 2015 Etnaviv Project * Copyright (C) 2015-2018 Etnaviv Project
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __ETNAVIV_DRV_H__ #ifndef __ETNAVIV_DRV_H__
...@@ -26,6 +15,7 @@ ...@@ -26,6 +15,7 @@
#include <linux/pm_runtime.h> #include <linux/pm_runtime.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/list.h> #include <linux/list.h>
#include <linux/time64.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/sizes.h> #include <linux/sizes.h>
...@@ -101,11 +91,6 @@ void etnaviv_gem_describe_objects(struct etnaviv_drm_private *priv, ...@@ -101,11 +91,6 @@ void etnaviv_gem_describe_objects(struct etnaviv_drm_private *priv,
struct seq_file *m); struct seq_file *m);
#endif #endif
void __iomem *etnaviv_ioremap(struct platform_device *pdev, const char *name,
const char *dbgname);
void etnaviv_writel(u32 data, void __iomem *addr);
u32 etnaviv_readl(const void __iomem *addr);
#define DBG(fmt, ...) DRM_DEBUG(fmt"\n", ##__VA_ARGS__) #define DBG(fmt, ...) DRM_DEBUG(fmt"\n", ##__VA_ARGS__)
#define VERB(fmt, ...) if (0) DRM_DEBUG(fmt"\n", ##__VA_ARGS__) #define VERB(fmt, ...) if (0) DRM_DEBUG(fmt"\n", ##__VA_ARGS__)
...@@ -132,19 +117,27 @@ static inline bool fence_after_eq(u32 a, u32 b) ...@@ -132,19 +117,27 @@ static inline bool fence_after_eq(u32 a, u32 b)
return (s32)(a - b) >= 0; return (s32)(a - b) >= 0;
} }
/*
* Etnaviv timeouts are specified wrt CLOCK_MONOTONIC, not jiffies.
* We need to calculate the timeout in terms of number of jiffies
* between the specified timeout and the current CLOCK_MONOTONIC time.
*/
static inline unsigned long etnaviv_timeout_to_jiffies( static inline unsigned long etnaviv_timeout_to_jiffies(
const struct timespec *timeout) const struct timespec *timeout)
{ {
unsigned long timeout_jiffies = timespec_to_jiffies(timeout); struct timespec64 ts, to;
unsigned long start_jiffies = jiffies;
unsigned long remaining_jiffies; to = timespec_to_timespec64(*timeout);
ktime_get_ts64(&ts);
/* timeouts before "now" have already expired */
if (timespec64_compare(&to, &ts) <= 0)
return 0;
if (time_after(start_jiffies, timeout_jiffies)) ts = timespec64_sub(to, ts);
remaining_jiffies = 0;
else
remaining_jiffies = timeout_jiffies - start_jiffies;
return remaining_jiffies; return timespec64_to_jiffies(&ts);
} }
#endif /* __ETNAVIV_DRV_H__ */ #endif /* __ETNAVIV_DRV_H__ */
// SPDX-License-Identifier: GPL-2.0
/* /*
* Copyright (C) 2015 Etnaviv Project * Copyright (C) 2015-2018 Etnaviv Project
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <linux/devcoredump.h> #include <linux/devcoredump.h>
......
/* SPDX-License-Identifier: GPL-2.0 */
/* /*
* Copyright (C) 2015 Etnaviv Project * Copyright (C) 2015 Etnaviv Project
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*
* Etnaviv devcoredump file definitions
*/ */
#ifndef ETNAVIV_DUMP_H #ifndef ETNAVIV_DUMP_H
#define ETNAVIV_DUMP_H #define ETNAVIV_DUMP_H
......
// SPDX-License-Identifier: GPL-2.0
/* /*
* Copyright (C) 2015 Etnaviv Project * Copyright (C) 2015-2018 Etnaviv Project
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <linux/spinlock.h> #include <linux/spinlock.h>
......
/* SPDX-License-Identifier: GPL-2.0 */
/* /*
* Copyright (C) 2015 Etnaviv Project * Copyright (C) 2015-2018 Etnaviv Project
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __ETNAVIV_GEM_H__ #ifndef __ETNAVIV_GEM_H__
......
// SPDX-License-Identifier: GPL-2.0
/* /*
* Copyright (C) 2013 Red Hat * Copyright (C) 2014-2018 Etnaviv Project
* Author: Rob Clark <robdclark@gmail.com>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <linux/dma-buf.h> #include <linux/dma-buf.h>
......
// SPDX-License-Identifier: GPL-2.0
/* /*
* Copyright (C) 2015 Etnaviv Project * Copyright (C) 2015-2018 Etnaviv Project
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <linux/component.h> #include <linux/component.h>
...@@ -1735,6 +1724,7 @@ static int etnaviv_gpu_platform_probe(struct platform_device *pdev) ...@@ -1735,6 +1724,7 @@ static int etnaviv_gpu_platform_probe(struct platform_device *pdev)
{ {
struct device *dev = &pdev->dev; struct device *dev = &pdev->dev;
struct etnaviv_gpu *gpu; struct etnaviv_gpu *gpu;
struct resource *res;
int err; int err;
gpu = devm_kzalloc(dev, sizeof(*gpu), GFP_KERNEL); gpu = devm_kzalloc(dev, sizeof(*gpu), GFP_KERNEL);
...@@ -1746,7 +1736,8 @@ static int etnaviv_gpu_platform_probe(struct platform_device *pdev) ...@@ -1746,7 +1736,8 @@ static int etnaviv_gpu_platform_probe(struct platform_device *pdev)
mutex_init(&gpu->fence_idr_lock); mutex_init(&gpu->fence_idr_lock);
/* Map registers: */ /* Map registers: */
gpu->mmio = etnaviv_ioremap(pdev, NULL, dev_name(gpu->dev)); res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
gpu->mmio = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(gpu->mmio)) if (IS_ERR(gpu->mmio))
return PTR_ERR(gpu->mmio); return PTR_ERR(gpu->mmio);
......
/* SPDX-License-Identifier: GPL-2.0 */
/* /*
* Copyright (C) 2015 Etnaviv Project * Copyright (C) 2015-2018 Etnaviv Project
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __ETNAVIV_GPU_H__ #ifndef __ETNAVIV_GPU_H__
...@@ -161,12 +150,12 @@ struct etnaviv_gpu { ...@@ -161,12 +150,12 @@ struct etnaviv_gpu {
static inline void gpu_write(struct etnaviv_gpu *gpu, u32 reg, u32 data) static inline void gpu_write(struct etnaviv_gpu *gpu, u32 reg, u32 data)
{ {
etnaviv_writel(data, gpu->mmio + reg); writel(data, gpu->mmio + reg);
} }
static inline u32 gpu_read(struct etnaviv_gpu *gpu, u32 reg) static inline u32 gpu_read(struct etnaviv_gpu *gpu, u32 reg)
{ {
return etnaviv_readl(gpu->mmio + reg); return readl(gpu->mmio + reg);
} }
static inline bool fence_completed(struct etnaviv_gpu *gpu, u32 fence) static inline bool fence_completed(struct etnaviv_gpu *gpu, u32 fence)
......
// SPDX-License-Identifier: GPL-2.0
/* /*
* Copyright (C) 2018 Etnaviv Project * Copyright (C) 2018 Etnaviv Project
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "etnaviv_gpu.h" #include "etnaviv_gpu.h"
......
// SPDX-License-Identifier: GPL-2.0
/* /*
* Copyright (C) 2014 Christian Gmeiner <christian.gmeiner@gmail.com> * Copyright (C) 2014-2018 Etnaviv Project
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <linux/platform_device.h> #include <linux/platform_device.h>
...@@ -47,9 +36,8 @@ static int __etnaviv_iommu_init(struct etnaviv_iommuv1_domain *etnaviv_domain) ...@@ -47,9 +36,8 @@ static int __etnaviv_iommu_init(struct etnaviv_iommuv1_domain *etnaviv_domain)
u32 *p; u32 *p;
int i; int i;
etnaviv_domain->base.bad_page_cpu = dma_alloc_coherent( etnaviv_domain->base.bad_page_cpu =
etnaviv_domain->base.dev, dma_alloc_wc(etnaviv_domain->base.dev, SZ_4K,
SZ_4K,
&etnaviv_domain->base.bad_page_dma, &etnaviv_domain->base.bad_page_dma,
GFP_KERNEL); GFP_KERNEL);
if (!etnaviv_domain->base.bad_page_cpu) if (!etnaviv_domain->base.bad_page_cpu)
...@@ -59,12 +47,12 @@ static int __etnaviv_iommu_init(struct etnaviv_iommuv1_domain *etnaviv_domain) ...@@ -59,12 +47,12 @@ static int __etnaviv_iommu_init(struct etnaviv_iommuv1_domain *etnaviv_domain)
for (i = 0; i < SZ_4K / 4; i++) for (i = 0; i < SZ_4K / 4; i++)
*p++ = 0xdead55aa; *p++ = 0xdead55aa;
etnaviv_domain->pgtable_cpu = etnaviv_domain->pgtable_cpu = dma_alloc_wc(etnaviv_domain->base.dev,
dma_alloc_coherent(etnaviv_domain->base.dev, PT_SIZE, PT_SIZE,
&etnaviv_domain->pgtable_dma, &etnaviv_domain->pgtable_dma,
GFP_KERNEL); GFP_KERNEL);
if (!etnaviv_domain->pgtable_cpu) { if (!etnaviv_domain->pgtable_cpu) {
dma_free_coherent(etnaviv_domain->base.dev, SZ_4K, dma_free_wc(etnaviv_domain->base.dev, SZ_4K,
etnaviv_domain->base.bad_page_cpu, etnaviv_domain->base.bad_page_cpu,
etnaviv_domain->base.bad_page_dma); etnaviv_domain->base.bad_page_dma);
return -ENOMEM; return -ENOMEM;
...@@ -81,11 +69,10 @@ static void etnaviv_iommuv1_domain_free(struct etnaviv_iommu_domain *domain) ...@@ -81,11 +69,10 @@ static void etnaviv_iommuv1_domain_free(struct etnaviv_iommu_domain *domain)
struct etnaviv_iommuv1_domain *etnaviv_domain = struct etnaviv_iommuv1_domain *etnaviv_domain =
to_etnaviv_domain(domain); to_etnaviv_domain(domain);
dma_free_coherent(etnaviv_domain->base.dev, PT_SIZE, dma_free_wc(etnaviv_domain->base.dev, PT_SIZE,
etnaviv_domain->pgtable_cpu, etnaviv_domain->pgtable_cpu, etnaviv_domain->pgtable_dma);
etnaviv_domain->pgtable_dma);
dma_free_coherent(etnaviv_domain->base.dev, SZ_4K, dma_free_wc(etnaviv_domain->base.dev, SZ_4K,
etnaviv_domain->base.bad_page_cpu, etnaviv_domain->base.bad_page_cpu,
etnaviv_domain->base.bad_page_dma); etnaviv_domain->base.bad_page_dma);
......
/* SPDX-License-Identifier: GPL-2.0 */
/* /*
* Copyright (C) 2014 Christian Gmeiner <christian.gmeiner@gmail.com> * Copyright (C) 2014-2018 Etnaviv Project
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __ETNAVIV_IOMMU_H__ #ifndef __ETNAVIV_IOMMU_H__
......
// SPDX-License-Identifier: GPL-2.0
/* /*
* Copyright (C) 2016 Etnaviv Project * Copyright (C) 2016-2018 Etnaviv Project
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <linux/platform_device.h> #include <linux/platform_device.h>
...@@ -47,8 +36,8 @@ struct etnaviv_iommuv2_domain { ...@@ -47,8 +36,8 @@ struct etnaviv_iommuv2_domain {
u32 *mtlb_cpu; u32 *mtlb_cpu;
dma_addr_t mtlb_dma; dma_addr_t mtlb_dma;
/* S(lave) TLB aka second level pagetable */ /* S(lave) TLB aka second level pagetable */
u32 *stlb_cpu[1024]; u32 *stlb_cpu[MMUv2_MAX_STLB_ENTRIES];
dma_addr_t stlb_dma[1024]; dma_addr_t stlb_dma[MMUv2_MAX_STLB_ENTRIES];
}; };
static struct etnaviv_iommuv2_domain * static struct etnaviv_iommuv2_domain *
...@@ -57,24 +46,54 @@ to_etnaviv_domain(struct etnaviv_iommu_domain *domain) ...@@ -57,24 +46,54 @@ to_etnaviv_domain(struct etnaviv_iommu_domain *domain)
return container_of(domain, struct etnaviv_iommuv2_domain, base); return container_of(domain, struct etnaviv_iommuv2_domain, base);
} }
static int
etnaviv_iommuv2_ensure_stlb(struct etnaviv_iommuv2_domain *etnaviv_domain,
int stlb)
{
if (etnaviv_domain->stlb_cpu[stlb])
return 0;
etnaviv_domain->stlb_cpu[stlb] =
dma_alloc_wc(etnaviv_domain->base.dev, SZ_4K,
&etnaviv_domain->stlb_dma[stlb],
GFP_KERNEL);
if (!etnaviv_domain->stlb_cpu[stlb])
return -ENOMEM;
memset32(etnaviv_domain->stlb_cpu[stlb], MMUv2_PTE_EXCEPTION,
SZ_4K / sizeof(u32));
etnaviv_domain->mtlb_cpu[stlb] = etnaviv_domain->stlb_dma[stlb] |
MMUv2_PTE_PRESENT;
return 0;
}
static int etnaviv_iommuv2_map(struct etnaviv_iommu_domain *domain, static int etnaviv_iommuv2_map(struct etnaviv_iommu_domain *domain,
unsigned long iova, phys_addr_t paddr, unsigned long iova, phys_addr_t paddr,
size_t size, int prot) size_t size, int prot)
{ {
struct etnaviv_iommuv2_domain *etnaviv_domain = struct etnaviv_iommuv2_domain *etnaviv_domain =
to_etnaviv_domain(domain); to_etnaviv_domain(domain);
int mtlb_entry, stlb_entry; int mtlb_entry, stlb_entry, ret;
u32 entry = (u32)paddr | MMUv2_PTE_PRESENT; u32 entry = lower_32_bits(paddr) | MMUv2_PTE_PRESENT;
if (size != SZ_4K) if (size != SZ_4K)
return -EINVAL; return -EINVAL;
if (IS_ENABLED(CONFIG_PHYS_ADDR_T_64BIT))
entry |= (upper_32_bits(paddr) & 0xff) << 4;
if (prot & ETNAVIV_PROT_WRITE) if (prot & ETNAVIV_PROT_WRITE)
entry |= MMUv2_PTE_WRITEABLE; entry |= MMUv2_PTE_WRITEABLE;
mtlb_entry = (iova & MMUv2_MTLB_MASK) >> MMUv2_MTLB_SHIFT; mtlb_entry = (iova & MMUv2_MTLB_MASK) >> MMUv2_MTLB_SHIFT;
stlb_entry = (iova & MMUv2_STLB_MASK) >> MMUv2_STLB_SHIFT; stlb_entry = (iova & MMUv2_STLB_MASK) >> MMUv2_STLB_SHIFT;
ret = etnaviv_iommuv2_ensure_stlb(etnaviv_domain, mtlb_entry);
if (ret)
return ret;
etnaviv_domain->stlb_cpu[mtlb_entry][stlb_entry] = entry; etnaviv_domain->stlb_cpu[mtlb_entry][stlb_entry] = entry;
return 0; return 0;
...@@ -101,12 +120,11 @@ static size_t etnaviv_iommuv2_unmap(struct etnaviv_iommu_domain *domain, ...@@ -101,12 +120,11 @@ static size_t etnaviv_iommuv2_unmap(struct etnaviv_iommu_domain *domain,
static int etnaviv_iommuv2_init(struct etnaviv_iommuv2_domain *etnaviv_domain) static int etnaviv_iommuv2_init(struct etnaviv_iommuv2_domain *etnaviv_domain)
{ {
u32 *p; u32 *p;
int ret, i, j; int ret, i;
/* allocate scratch page */ /* allocate scratch page */
etnaviv_domain->base.bad_page_cpu = dma_alloc_coherent( etnaviv_domain->base.bad_page_cpu =
etnaviv_domain->base.dev, dma_alloc_wc(etnaviv_domain->base.dev, SZ_4K,
SZ_4K,
&etnaviv_domain->base.bad_page_dma, &etnaviv_domain->base.bad_page_dma,
GFP_KERNEL); GFP_KERNEL);
if (!etnaviv_domain->base.bad_page_cpu) { if (!etnaviv_domain->base.bad_page_cpu) {
...@@ -117,67 +135,40 @@ static int etnaviv_iommuv2_init(struct etnaviv_iommuv2_domain *etnaviv_domain) ...@@ -117,67 +135,40 @@ static int etnaviv_iommuv2_init(struct etnaviv_iommuv2_domain *etnaviv_domain)
for (i = 0; i < SZ_4K / 4; i++) for (i = 0; i < SZ_4K / 4; i++)
*p++ = 0xdead55aa; *p++ = 0xdead55aa;
etnaviv_domain->pta_cpu = dma_alloc_coherent(etnaviv_domain->base.dev, etnaviv_domain->pta_cpu = dma_alloc_wc(etnaviv_domain->base.dev,
SZ_4K, SZ_4K, &etnaviv_domain->pta_dma,
&etnaviv_domain->pta_dma,
GFP_KERNEL); GFP_KERNEL);
if (!etnaviv_domain->pta_cpu) { if (!etnaviv_domain->pta_cpu) {
ret = -ENOMEM; ret = -ENOMEM;
goto fail_mem; goto fail_mem;
} }
etnaviv_domain->mtlb_cpu = dma_alloc_coherent(etnaviv_domain->base.dev, etnaviv_domain->mtlb_cpu = dma_alloc_wc(etnaviv_domain->base.dev,
SZ_4K, SZ_4K, &etnaviv_domain->mtlb_dma,
&etnaviv_domain->mtlb_dma,
GFP_KERNEL); GFP_KERNEL);
if (!etnaviv_domain->mtlb_cpu) { if (!etnaviv_domain->mtlb_cpu) {
ret = -ENOMEM; ret = -ENOMEM;
goto fail_mem; goto fail_mem;
} }
/* pre-populate STLB pages (may want to switch to on-demand later) */ memset32(etnaviv_domain->mtlb_cpu, MMUv2_PTE_EXCEPTION,
for (i = 0; i < MMUv2_MAX_STLB_ENTRIES; i++) { MMUv2_MAX_STLB_ENTRIES);
etnaviv_domain->stlb_cpu[i] =
dma_alloc_coherent(etnaviv_domain->base.dev,
SZ_4K,
&etnaviv_domain->stlb_dma[i],
GFP_KERNEL);
if (!etnaviv_domain->stlb_cpu[i]) {
ret = -ENOMEM;
goto fail_mem;
}
p = etnaviv_domain->stlb_cpu[i];
for (j = 0; j < SZ_4K / 4; j++)
*p++ = MMUv2_PTE_EXCEPTION;
etnaviv_domain->mtlb_cpu[i] = etnaviv_domain->stlb_dma[i] |
MMUv2_PTE_PRESENT;
}
return 0; return 0;
fail_mem: fail_mem:
if (etnaviv_domain->base.bad_page_cpu) if (etnaviv_domain->base.bad_page_cpu)
dma_free_coherent(etnaviv_domain->base.dev, SZ_4K, dma_free_wc(etnaviv_domain->base.dev, SZ_4K,
etnaviv_domain->base.bad_page_cpu, etnaviv_domain->base.bad_page_cpu,
etnaviv_domain->base.bad_page_dma); etnaviv_domain->base.bad_page_dma);
if (etnaviv_domain->pta_cpu) if (etnaviv_domain->pta_cpu)
dma_free_coherent(etnaviv_domain->base.dev, SZ_4K, dma_free_wc(etnaviv_domain->base.dev, SZ_4K,
etnaviv_domain->pta_cpu, etnaviv_domain->pta_cpu, etnaviv_domain->pta_dma);
etnaviv_domain->pta_dma);
if (etnaviv_domain->mtlb_cpu) if (etnaviv_domain->mtlb_cpu)
dma_free_coherent(etnaviv_domain->base.dev, SZ_4K, dma_free_wc(etnaviv_domain->base.dev, SZ_4K,
etnaviv_domain->mtlb_cpu, etnaviv_domain->mtlb_cpu, etnaviv_domain->mtlb_dma);
etnaviv_domain->mtlb_dma);
for (i = 0; i < MMUv2_MAX_STLB_ENTRIES; i++) {
if (etnaviv_domain->stlb_cpu[i])
dma_free_coherent(etnaviv_domain->base.dev, SZ_4K,
etnaviv_domain->stlb_cpu[i],
etnaviv_domain->stlb_dma[i]);
}
return ret; return ret;
} }
...@@ -188,21 +179,19 @@ static void etnaviv_iommuv2_domain_free(struct etnaviv_iommu_domain *domain) ...@@ -188,21 +179,19 @@ static void etnaviv_iommuv2_domain_free(struct etnaviv_iommu_domain *domain)
to_etnaviv_domain(domain); to_etnaviv_domain(domain);
int i; int i;
dma_free_coherent(etnaviv_domain->base.dev, SZ_4K, dma_free_wc(etnaviv_domain->base.dev, SZ_4K,
etnaviv_domain->base.bad_page_cpu, etnaviv_domain->base.bad_page_cpu,
etnaviv_domain->base.bad_page_dma); etnaviv_domain->base.bad_page_dma);
dma_free_coherent(etnaviv_domain->base.dev, SZ_4K, dma_free_wc(etnaviv_domain->base.dev, SZ_4K,
etnaviv_domain->pta_cpu, etnaviv_domain->pta_cpu, etnaviv_domain->pta_dma);
etnaviv_domain->pta_dma);
dma_free_coherent(etnaviv_domain->base.dev, SZ_4K, dma_free_wc(etnaviv_domain->base.dev, SZ_4K,
etnaviv_domain->mtlb_cpu, etnaviv_domain->mtlb_cpu, etnaviv_domain->mtlb_dma);
etnaviv_domain->mtlb_dma);
for (i = 0; i < MMUv2_MAX_STLB_ENTRIES; i++) { for (i = 0; i < MMUv2_MAX_STLB_ENTRIES; i++) {
if (etnaviv_domain->stlb_cpu[i]) if (etnaviv_domain->stlb_cpu[i])
dma_free_coherent(etnaviv_domain->base.dev, SZ_4K, dma_free_wc(etnaviv_domain->base.dev, SZ_4K,
etnaviv_domain->stlb_cpu[i], etnaviv_domain->stlb_cpu[i],
etnaviv_domain->stlb_dma[i]); etnaviv_domain->stlb_dma[i]);
} }
......
// SPDX-License-Identifier: GPL-2.0
/* /*
* Copyright (C) 2015 Etnaviv Project * Copyright (C) 2015-2018 Etnaviv Project
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "common.xml.h" #include "common.xml.h"
...@@ -162,22 +151,10 @@ static int etnaviv_iommu_find_iova(struct etnaviv_iommu *mmu, ...@@ -162,22 +151,10 @@ static int etnaviv_iommu_find_iova(struct etnaviv_iommu *mmu,
bool found; bool found;
ret = drm_mm_insert_node_in_range(&mmu->mm, node, ret = drm_mm_insert_node_in_range(&mmu->mm, node,
size, 0, 0, size, 0, 0, 0, U64_MAX, mode);
mmu->last_iova, U64_MAX,
mode);
if (ret != -ENOSPC) if (ret != -ENOSPC)
break; break;
/*
* If we did not search from the start of the MMU region,
* try again in case there are free slots.
*/
if (mmu->last_iova) {
mmu->last_iova = 0;
mmu->need_flush = true;
continue;
}
/* Try to retire some entries */ /* Try to retire some entries */
drm_mm_scan_init(&scan, &mmu->mm, size, 0, 0, mode); drm_mm_scan_init(&scan, &mmu->mm, size, 0, 0, mode);
...@@ -274,7 +251,6 @@ int etnaviv_iommu_map_gem(struct etnaviv_iommu *mmu, ...@@ -274,7 +251,6 @@ int etnaviv_iommu_map_gem(struct etnaviv_iommu *mmu,
if (ret < 0) if (ret < 0)
goto unlock; goto unlock;
mmu->last_iova = node->start + etnaviv_obj->base.size;
mapping->iova = node->start; mapping->iova = node->start;
ret = etnaviv_iommu_map(mmu, node->start, sgt, etnaviv_obj->base.size, ret = etnaviv_iommu_map(mmu, node->start, sgt, etnaviv_obj->base.size,
ETNAVIV_PROT_READ | ETNAVIV_PROT_WRITE); ETNAVIV_PROT_READ | ETNAVIV_PROT_WRITE);
...@@ -381,7 +357,6 @@ int etnaviv_iommu_get_suballoc_va(struct etnaviv_gpu *gpu, dma_addr_t paddr, ...@@ -381,7 +357,6 @@ int etnaviv_iommu_get_suballoc_va(struct etnaviv_gpu *gpu, dma_addr_t paddr,
mutex_unlock(&mmu->lock); mutex_unlock(&mmu->lock);
return ret; return ret;
} }
mmu->last_iova = vram_node->start + size;
gpu->mmu->need_flush = true; gpu->mmu->need_flush = true;
mutex_unlock(&mmu->lock); mutex_unlock(&mmu->lock);
......
/* SPDX-License-Identifier: GPL-2.0 */
/* /*
* Copyright (C) 2015 Etnaviv Project * Copyright (C) 2015-2018 Etnaviv Project
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __ETNAVIV_MMU_H__ #ifndef __ETNAVIV_MMU_H__
...@@ -59,7 +48,6 @@ struct etnaviv_iommu { ...@@ -59,7 +48,6 @@ struct etnaviv_iommu {
struct mutex lock; struct mutex lock;
struct list_head mappings; struct list_head mappings;
struct drm_mm mm; struct drm_mm mm;
u32 last_iova;
bool need_flush; bool need_flush;
}; };
......
// SPDX-License-Identifier: GPL-2.0
/* /*
* Copyright (C) 2017 Etnaviv Project * Copyright (C) 2017 Etnaviv Project
* Copyright (C) 2017 Zodiac Inflight Innovations * Copyright (C) 2017 Zodiac Inflight Innovations
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "etnaviv_gpu.h" #include "etnaviv_gpu.h"
......
/* SPDX-License-Identifier: GPL-2.0 */
/* /*
* Copyright (C) 2017 Etnaviv Project * Copyright (C) 2017 Etnaviv Project
* Copyright (C) 2017 Zodiac Inflight Innovations * Copyright (C) 2017 Zodiac Inflight Innovations
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __ETNAVIV_PERFMON_H__ #ifndef __ETNAVIV_PERFMON_H__
......
// SPDX-License-Identifier: GPL-2.0
/* /*
* Copyright (C) 2017 Etnaviv Project * Copyright (C) 2017 Etnaviv Project
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <linux/kthread.h> #include <linux/kthread.h>
......
/* SPDX-License-Identifier: GPL-2.0 */
/* /*
* Copyright (C) 2017 Etnaviv Project * Copyright (C) 2017 Etnaviv Project
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __ETNAVIV_SCHED_H__ #ifndef __ETNAVIV_SCHED_H__
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment