Skip to content

Commit 6ec692d

Browse files
committed
Merge tag 'drm-etnaviv-next-2025-01-08' of https://git.pengutronix.de/git/lst/linux into drm-next
- cleanups - add fdinfo memory support - add explicit reset handling Signed-off-by: Dave Airlie <[email protected]> From: Lucas Stach <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
2 parents 4695a9c + 6bde14b commit 6ec692d

File tree

7 files changed

+92
-22
lines changed

7 files changed

+92
-22
lines changed

drivers/gpu/drm/etnaviv/etnaviv_cmdbuf.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include "etnaviv_gem.h"
1010
#include "etnaviv_gpu.h"
1111
#include "etnaviv_mmu.h"
12-
#include "etnaviv_perfmon.h"
1312

1413
#define SUBALLOC_SIZE SZ_512K
1514
#define SUBALLOC_GRANULE SZ_4K
@@ -100,7 +99,7 @@ int etnaviv_cmdbuf_init(struct etnaviv_cmdbuf_suballoc *suballoc,
10099
mutex_unlock(&suballoc->lock);
101100
ret = wait_event_interruptible_timeout(suballoc->free_event,
102101
suballoc->free_space,
103-
msecs_to_jiffies(10 * 1000));
102+
secs_to_jiffies(10));
104103
if (!ret) {
105104
dev_err(suballoc->dev,
106105
"Timeout waiting for cmdbuf space\n");

drivers/gpu/drm/etnaviv/etnaviv_drv.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,16 @@ static const struct drm_ioctl_desc etnaviv_ioctls[] = {
488488
ETNA_IOCTL(PM_QUERY_SIG, pm_query_sig, DRM_RENDER_ALLOW),
489489
};
490490

491-
DEFINE_DRM_GEM_FOPS(fops);
491+
static void etnaviv_show_fdinfo(struct drm_printer *p, struct drm_file *file)
492+
{
493+
drm_show_memory_stats(p, file);
494+
}
495+
496+
static const struct file_operations fops = {
497+
.owner = THIS_MODULE,
498+
DRM_GEM_FOPS,
499+
.show_fdinfo = drm_show_fdinfo,
500+
};
492501

493502
static const struct drm_driver etnaviv_drm_driver = {
494503
.driver_features = DRIVER_GEM | DRIVER_RENDER,
@@ -498,6 +507,7 @@ static const struct drm_driver etnaviv_drm_driver = {
498507
#ifdef CONFIG_DEBUG_FS
499508
.debugfs_init = etnaviv_debugfs_init,
500509
#endif
510+
.show_fdinfo = etnaviv_show_fdinfo,
501511
.ioctls = etnaviv_ioctls,
502512
.num_ioctls = DRM_ETNAVIV_NUM_IOCTLS,
503513
.fops = &fops,

drivers/gpu/drm/etnaviv/etnaviv_gem.c

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,15 +342,27 @@ void *etnaviv_gem_vmap(struct drm_gem_object *obj)
342342
static void *etnaviv_gem_vmap_impl(struct etnaviv_gem_object *obj)
343343
{
344344
struct page **pages;
345+
pgprot_t prot;
345346

346347
lockdep_assert_held(&obj->lock);
347348

348349
pages = etnaviv_gem_get_pages(obj);
349350
if (IS_ERR(pages))
350351
return NULL;
351352

352-
return vmap(pages, obj->base.size >> PAGE_SHIFT,
353-
VM_MAP, pgprot_writecombine(PAGE_KERNEL));
353+
switch (obj->flags & ETNA_BO_CACHE_MASK) {
354+
case ETNA_BO_CACHED:
355+
prot = PAGE_KERNEL;
356+
break;
357+
case ETNA_BO_UNCACHED:
358+
prot = pgprot_noncached(PAGE_KERNEL);
359+
break;
360+
case ETNA_BO_WC:
361+
default:
362+
prot = pgprot_writecombine(PAGE_KERNEL);
363+
}
364+
365+
return vmap(pages, obj->base.size >> PAGE_SHIFT, VM_MAP, prot);
354366
}
355367

356368
static inline enum dma_data_direction etnaviv_op_to_dma_dir(u32 op)
@@ -528,6 +540,17 @@ void etnaviv_gem_obj_add(struct drm_device *dev, struct drm_gem_object *obj)
528540
mutex_unlock(&priv->gem_lock);
529541
}
530542

543+
static enum drm_gem_object_status etnaviv_gem_status(struct drm_gem_object *obj)
544+
{
545+
struct etnaviv_gem_object *etnaviv_obj = to_etnaviv_bo(obj);
546+
enum drm_gem_object_status status = 0;
547+
548+
if (etnaviv_obj->pages)
549+
status |= DRM_GEM_OBJECT_RESIDENT;
550+
551+
return status;
552+
}
553+
531554
static const struct vm_operations_struct vm_ops = {
532555
.fault = etnaviv_gem_fault,
533556
.open = drm_gem_vm_open,
@@ -541,6 +564,7 @@ static const struct drm_gem_object_funcs etnaviv_gem_object_funcs = {
541564
.get_sg_table = etnaviv_gem_prime_get_sg_table,
542565
.vmap = etnaviv_gem_prime_vmap,
543566
.mmap = etnaviv_gem_mmap,
567+
.status = etnaviv_gem_status,
544568
.vm_ops = &vm_ops,
545569
};
546570

drivers/gpu/drm/etnaviv/etnaviv_gem.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,7 @@ struct etnaviv_gem_object {
4444
u32 flags;
4545

4646
struct list_head gem_node;
47-
struct etnaviv_gpu *gpu; /* non-null if active */
4847
atomic_t gpu_active;
49-
u32 access;
5048

5149
struct page **pages;
5250
struct sg_table *sgt;

drivers/gpu/drm/etnaviv/etnaviv_gpu.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/platform_device.h>
1414
#include <linux/pm_runtime.h>
1515
#include <linux/regulator/consumer.h>
16+
#include <linux/reset.h>
1617
#include <linux/thermal.h>
1718

1819
#include "etnaviv_cmdbuf.h"
@@ -172,6 +173,29 @@ int etnaviv_gpu_get_param(struct etnaviv_gpu *gpu, u32 param, u64 *value)
172173
return 0;
173174
}
174175

176+
static int etnaviv_gpu_reset_deassert(struct etnaviv_gpu *gpu)
177+
{
178+
int ret;
179+
180+
/*
181+
* 32 core clock cycles (slowest clock) required before deassertion
182+
* 1 microsecond might match all implementations without computation
183+
*/
184+
usleep_range(1, 2);
185+
186+
ret = reset_control_deassert(gpu->rst);
187+
if (ret)
188+
return ret;
189+
190+
/*
191+
* 128 core clock cycles (slowest clock) required before any activity on AHB
192+
* 1 microsecond might match all implementations without computation
193+
*/
194+
usleep_range(1, 2);
195+
196+
return 0;
197+
}
198+
175199
static inline bool etnaviv_is_model_rev(struct etnaviv_gpu *gpu, u32 model, u32 revision)
176200
{
177201
return gpu->identity.model == model &&
@@ -799,6 +823,12 @@ int etnaviv_gpu_init(struct etnaviv_gpu *gpu)
799823
goto pm_put;
800824
}
801825

826+
ret = etnaviv_gpu_reset_deassert(gpu);
827+
if (ret) {
828+
dev_err(gpu->dev, "GPU reset deassert failed\n");
829+
goto fail;
830+
}
831+
802832
etnaviv_hw_identify(gpu);
803833

804834
if (gpu->identity.model == 0) {
@@ -1860,6 +1890,17 @@ static int etnaviv_gpu_platform_probe(struct platform_device *pdev)
18601890
if (IS_ERR(gpu->mmio))
18611891
return PTR_ERR(gpu->mmio);
18621892

1893+
1894+
/* Get Reset: */
1895+
gpu->rst = devm_reset_control_get_optional_exclusive(&pdev->dev, NULL);
1896+
if (IS_ERR(gpu->rst))
1897+
return dev_err_probe(dev, PTR_ERR(gpu->rst),
1898+
"failed to get reset\n");
1899+
1900+
err = reset_control_assert(gpu->rst);
1901+
if (err)
1902+
return dev_err_probe(dev, err, "failed to assert reset\n");
1903+
18631904
/* Get Interrupt: */
18641905
gpu->irq = platform_get_irq(pdev, 0);
18651906
if (gpu->irq < 0)

drivers/gpu/drm/etnaviv/etnaviv_gpu.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ struct etnaviv_event {
9393
struct etnaviv_cmdbuf_suballoc;
9494
struct regulator;
9595
struct clk;
96+
struct reset_control;
9697

9798
#define ETNA_NR_EVENTS 30
9899

@@ -158,6 +159,7 @@ struct etnaviv_gpu {
158159
struct clk *clk_reg;
159160
struct clk *clk_core;
160161
struct clk *clk_shader;
162+
struct reset_control *rst;
161163

162164
unsigned int freq_scale;
163165
unsigned int fe_waitcycles;

drivers/gpu/drm/etnaviv/etnaviv_mmu.c

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@ static void etnaviv_context_unmap(struct etnaviv_iommu_context *context,
1919
size_t unmapped_page, unmapped = 0;
2020
size_t pgsize = SZ_4K;
2121

22-
if (!IS_ALIGNED(iova | size, pgsize)) {
23-
pr_err("unaligned: iova 0x%lx size 0x%zx min_pagesz 0x%zx\n",
24-
iova, size, pgsize);
25-
return;
26-
}
27-
2822
while (unmapped < size) {
2923
unmapped_page = context->global->ops->unmap(context, iova,
3024
pgsize);
@@ -45,12 +39,6 @@ static int etnaviv_context_map(struct etnaviv_iommu_context *context,
4539
size_t orig_size = size;
4640
int ret = 0;
4741

48-
if (!IS_ALIGNED(iova | paddr | size, pgsize)) {
49-
pr_err("unaligned: iova 0x%lx pa %pa size 0x%zx min_pagesz 0x%zx\n",
50-
iova, &paddr, size, pgsize);
51-
return -EINVAL;
52-
}
53-
5442
while (size) {
5543
ret = context->global->ops->map(context, iova, paddr, pgsize,
5644
prot);
@@ -82,11 +70,19 @@ static int etnaviv_iommu_map(struct etnaviv_iommu_context *context,
8270
return -EINVAL;
8371

8472
for_each_sgtable_dma_sg(sgt, sg, i) {
85-
phys_addr_t pa = sg_dma_address(sg) - sg->offset;
86-
unsigned int da_len = sg_dma_len(sg) + sg->offset;
73+
phys_addr_t pa = sg_dma_address(sg);
74+
unsigned int da_len = sg_dma_len(sg);
8775
unsigned int bytes = min_t(unsigned int, da_len, va_len);
8876

89-
VERB("map[%d]: %08x %pap(%x)", i, iova, &pa, bytes);
77+
VERB("map[%d]: %08x %pap(%x)", i, da, &pa, bytes);
78+
79+
if (!IS_ALIGNED(iova | pa | bytes, SZ_4K)) {
80+
dev_err(context->global->dev,
81+
"unaligned: iova 0x%x pa %pa size 0x%x\n",
82+
iova, &pa, bytes);
83+
ret = -EINVAL;
84+
goto fail;
85+
}
9086

9187
ret = etnaviv_context_map(context, da, pa, bytes, prot);
9288
if (ret)

0 commit comments

Comments
 (0)