Skip to content

Commit b0b6739

Browse files
committed
Merge tag 'drm-etnaviv-next-2024-03-07' of https://git.pengutronix.de/git/lst/linux into drm-next
- various code cleanups - enhancements for NPU and MRT support Signed-off-by: Dave Airlie <airlied@redhat.com> From: Lucas Stach <l.stach@pengutronix.de> Link: https://patchwork.freedesktop.org/patch/msgid/72a783cd98d60f6ebb43b90a6b453eea87224409.camel@pengutronix.de
2 parents 5794d2f + b735ee1 commit b0b6739

File tree

9 files changed

+163
-44
lines changed

9 files changed

+163
-44
lines changed

drivers/gpu/drm/etnaviv/etnaviv_cmd_parser.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ static const struct {
5454
ST(0x1480, 8),
5555
ST(0x1500, 8),
5656
ST(0x1520, 8),
57+
ST(0x1540, 8),
5758
ST(0x1608, 1),
5859
ST(0x1610, 1),
5960
ST(0x1658, 1),

drivers/gpu/drm/etnaviv/etnaviv_drv.c

Lines changed: 61 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@
2929
* DRM operations:
3030
*/
3131

32+
static struct device_node *etnaviv_of_first_available_node(void)
33+
{
34+
struct device_node *np;
35+
36+
for_each_compatible_node(np, NULL, "vivante,gc") {
37+
if (of_device_is_available(np))
38+
return np;
39+
}
40+
41+
return NULL;
42+
}
3243

3344
static void load_gpu(struct drm_device *dev)
3445
{
@@ -79,7 +90,7 @@ static int etnaviv_open(struct drm_device *dev, struct drm_file *file)
7990
drm_sched_entity_init(&ctx->sched_entity[i],
8091
DRM_SCHED_PRIORITY_NORMAL, &sched,
8192
1, NULL);
82-
}
93+
}
8394
}
8495

8596
file->driver_priv = ctx;
@@ -233,11 +244,11 @@ static int show_each_gpu(struct seq_file *m, void *arg)
233244
}
234245

235246
static struct drm_info_list etnaviv_debugfs_list[] = {
236-
{"gpu", show_each_gpu, 0, etnaviv_gpu_debugfs},
237-
{"gem", show_unlocked, 0, etnaviv_gem_show},
238-
{ "mm", show_unlocked, 0, etnaviv_mm_show },
239-
{"mmu", show_each_gpu, 0, etnaviv_mmu_show},
240-
{"ring", show_each_gpu, 0, etnaviv_ring_show},
247+
{"gpu", show_each_gpu, 0, etnaviv_gpu_debugfs},
248+
{"gem", show_unlocked, 0, etnaviv_gem_show},
249+
{ "mm", show_unlocked, 0, etnaviv_mm_show },
250+
{"mmu", show_each_gpu, 0, etnaviv_mmu_show},
251+
{"ring", show_each_gpu, 0, etnaviv_ring_show},
241252
};
242253

243254
static void etnaviv_debugfs_init(struct drm_minor *minor)
@@ -494,7 +505,7 @@ static const struct drm_driver etnaviv_drm_driver = {
494505
.desc = "etnaviv DRM",
495506
.date = "20151214",
496507
.major = 1,
497-
.minor = 3,
508+
.minor = 4,
498509
};
499510

500511
/*
@@ -597,9 +608,6 @@ static int etnaviv_pdev_probe(struct platform_device *pdev)
597608
if (!of_device_is_available(core_node))
598609
continue;
599610

600-
if (!first_node)
601-
first_node = core_node;
602-
603611
drm_of_component_match_add(&pdev->dev, &match,
604612
component_compare_of, core_node);
605613
}
@@ -634,8 +642,11 @@ static int etnaviv_pdev_probe(struct platform_device *pdev)
634642
* device as the GPU we found. This assumes that all Vivante
635643
* GPUs in the system share the same DMA constraints.
636644
*/
637-
if (first_node)
645+
first_node = etnaviv_of_first_available_node();
646+
if (first_node) {
638647
of_dma_configure(&pdev->dev, first_node, true);
648+
of_node_put(first_node);
649+
}
639650

640651
return component_master_add_with_match(dev, &etnaviv_master_ops, match);
641652
}
@@ -653,11 +664,43 @@ static struct platform_driver etnaviv_platform_driver = {
653664
},
654665
};
655666

667+
static int etnaviv_create_platform_device(const char *name,
668+
struct platform_device **ppdev)
669+
{
670+
struct platform_device *pdev;
671+
int ret;
672+
673+
pdev = platform_device_alloc(name, PLATFORM_DEVID_NONE);
674+
if (!pdev)
675+
return -ENOMEM;
676+
677+
ret = platform_device_add(pdev);
678+
if (ret) {
679+
platform_device_put(pdev);
680+
return ret;
681+
}
682+
683+
*ppdev = pdev;
684+
685+
return 0;
686+
}
687+
688+
static void etnaviv_destroy_platform_device(struct platform_device **ppdev)
689+
{
690+
struct platform_device *pdev = *ppdev;
691+
692+
if (!pdev)
693+
return;
694+
695+
platform_device_unregister(pdev);
696+
697+
*ppdev = NULL;
698+
}
699+
656700
static struct platform_device *etnaviv_drm;
657701

658702
static int __init etnaviv_init(void)
659703
{
660-
struct platform_device *pdev;
661704
int ret;
662705
struct device_node *np;
663706

@@ -675,27 +718,13 @@ static int __init etnaviv_init(void)
675718
* If the DT contains at least one available GPU device, instantiate
676719
* the DRM platform device.
677720
*/
678-
for_each_compatible_node(np, NULL, "vivante,gc") {
679-
if (!of_device_is_available(np))
680-
continue;
681-
682-
pdev = platform_device_alloc("etnaviv", PLATFORM_DEVID_NONE);
683-
if (!pdev) {
684-
ret = -ENOMEM;
685-
of_node_put(np);
686-
goto unregister_platform_driver;
687-
}
721+
np = etnaviv_of_first_available_node();
722+
if (np) {
723+
of_node_put(np);
688724

689-
ret = platform_device_add(pdev);
690-
if (ret) {
691-
platform_device_put(pdev);
692-
of_node_put(np);
725+
ret = etnaviv_create_platform_device("etnaviv", &etnaviv_drm);
726+
if (ret)
693727
goto unregister_platform_driver;
694-
}
695-
696-
etnaviv_drm = pdev;
697-
of_node_put(np);
698-
break;
699728
}
700729

701730
return 0;
@@ -710,7 +739,7 @@ module_init(etnaviv_init);
710739

711740
static void __exit etnaviv_exit(void)
712741
{
713-
platform_device_unregister(etnaviv_drm);
742+
etnaviv_destroy_platform_device(&etnaviv_drm);
714743
platform_driver_unregister(&etnaviv_platform_driver);
715744
platform_driver_unregister(&etnaviv_gpu_driver);
716745
}

drivers/gpu/drm/etnaviv/etnaviv_gem.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,10 @@ struct page **etnaviv_gem_get_pages(struct etnaviv_gem_object *etnaviv_obj)
100100

101101
if (!etnaviv_obj->sgt) {
102102
struct drm_device *dev = etnaviv_obj->base.dev;
103-
int npages = etnaviv_obj->base.size >> PAGE_SHIFT;
103+
unsigned int npages = etnaviv_obj->base.size >> PAGE_SHIFT;
104104
struct sg_table *sgt;
105105

106-
sgt = drm_prime_pages_to_sg(etnaviv_obj->base.dev,
107-
etnaviv_obj->pages, npages);
106+
sgt = drm_prime_pages_to_sg(dev, etnaviv_obj->pages, npages);
108107
if (IS_ERR(sgt)) {
109108
dev_err(dev->dev, "failed to allocate sgt: %ld\n",
110109
PTR_ERR(sgt));
@@ -542,7 +541,7 @@ static const struct drm_gem_object_funcs etnaviv_gem_object_funcs = {
542541
.vm_ops = &vm_ops,
543542
};
544543

545-
static int etnaviv_gem_new_impl(struct drm_device *dev, u32 size, u32 flags,
544+
static int etnaviv_gem_new_impl(struct drm_device *dev, u32 flags,
546545
const struct etnaviv_gem_ops *ops, struct drm_gem_object **obj)
547546
{
548547
struct etnaviv_gem_object *etnaviv_obj;
@@ -591,8 +590,7 @@ int etnaviv_gem_new_handle(struct drm_device *dev, struct drm_file *file,
591590

592591
size = PAGE_ALIGN(size);
593592

594-
ret = etnaviv_gem_new_impl(dev, size, flags,
595-
&etnaviv_gem_shmem_ops, &obj);
593+
ret = etnaviv_gem_new_impl(dev, flags, &etnaviv_gem_shmem_ops, &obj);
596594
if (ret)
597595
goto fail;
598596

@@ -627,7 +625,7 @@ int etnaviv_gem_new_private(struct drm_device *dev, size_t size, u32 flags,
627625
struct drm_gem_object *obj;
628626
int ret;
629627

630-
ret = etnaviv_gem_new_impl(dev, size, flags, ops, &obj);
628+
ret = etnaviv_gem_new_impl(dev, flags, ops, &obj);
631629
if (ret)
632630
return ret;
633631

drivers/gpu/drm/etnaviv/etnaviv_gpu.c

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,26 @@ int etnaviv_gpu_get_param(struct etnaviv_gpu *gpu, u32 param, u64 *value)
164164
*value = gpu->identity.eco_id;
165165
break;
166166

167+
case ETNAVIV_PARAM_GPU_NN_CORE_COUNT:
168+
*value = gpu->identity.nn_core_count;
169+
break;
170+
171+
case ETNAVIV_PARAM_GPU_NN_MAD_PER_CORE:
172+
*value = gpu->identity.nn_mad_per_core;
173+
break;
174+
175+
case ETNAVIV_PARAM_GPU_TP_CORE_COUNT:
176+
*value = gpu->identity.tp_core_count;
177+
break;
178+
179+
case ETNAVIV_PARAM_GPU_ON_CHIP_SRAM_SIZE:
180+
*value = gpu->identity.on_chip_sram_size;
181+
break;
182+
183+
case ETNAVIV_PARAM_GPU_AXI_SRAM_SIZE:
184+
*value = gpu->identity.axi_sram_size;
185+
break;
186+
167187
default:
168188
DBG("%s: invalid param: %u", dev_name(gpu->dev), param);
169189
return -EINVAL;
@@ -513,8 +533,19 @@ static int etnaviv_hw_reset(struct etnaviv_gpu *gpu)
513533
timeout = jiffies + msecs_to_jiffies(1000);
514534

515535
while (time_is_after_jiffies(timeout)) {
516-
/* enable clock */
517536
unsigned int fscale = 1 << (6 - gpu->freq_scale);
537+
u32 pulse_eater = 0x01590880;
538+
539+
/* disable clock gating */
540+
gpu_write_power(gpu, VIVS_PM_POWER_CONTROLS, 0x0);
541+
542+
/* disable pulse eater */
543+
pulse_eater |= BIT(17);
544+
gpu_write_power(gpu, VIVS_PM_PULSE_EATER, pulse_eater);
545+
pulse_eater |= BIT(0);
546+
gpu_write_power(gpu, VIVS_PM_PULSE_EATER, pulse_eater);
547+
548+
/* enable clock */
518549
control = VIVS_HI_CLOCK_CONTROL_FSCALE_VAL(fscale);
519550
etnaviv_gpu_load_clock(gpu, control);
520551

drivers/gpu/drm/etnaviv/etnaviv_gpu.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ struct etnaviv_chip_identity {
5454
/* Number of Neural Network cores. */
5555
u32 nn_core_count;
5656

57+
/* Number of MAD units per Neural Network core. */
58+
u32 nn_mad_per_core;
59+
60+
/* Number of Tensor Processing cores. */
61+
u32 tp_core_count;
62+
63+
/* Size in bytes of the SRAM inside the NPU. */
64+
u32 on_chip_sram_size;
65+
66+
/* Size in bytes of the SRAM across the AXI bus. */
67+
u32 axi_sram_size;
68+
5769
/* Size of the vertex cache. */
5870
u32 vertex_cache_size;
5971

drivers/gpu/drm/etnaviv/etnaviv_hwdb.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ static const struct etnaviv_chip_identity etnaviv_chip_identities[] = {
1717
.thread_count = 128,
1818
.shader_core_count = 1,
1919
.nn_core_count = 0,
20+
.nn_mad_per_core = 0,
21+
.tp_core_count = 0,
22+
.on_chip_sram_size = 0,
23+
.axi_sram_size = 0,
2024
.vertex_cache_size = 8,
2125
.vertex_output_buffer_size = 1024,
2226
.pixel_pipes = 1,
@@ -48,6 +52,11 @@ static const struct etnaviv_chip_identity etnaviv_chip_identities[] = {
4852
.register_max = 64,
4953
.thread_count = 256,
5054
.shader_core_count = 1,
55+
.nn_core_count = 0,
56+
.nn_mad_per_core = 0,
57+
.tp_core_count = 0,
58+
.on_chip_sram_size = 0,
59+
.axi_sram_size = 0,
5160
.vertex_cache_size = 8,
5261
.vertex_output_buffer_size = 512,
5362
.pixel_pipes = 1,
@@ -80,6 +89,10 @@ static const struct etnaviv_chip_identity etnaviv_chip_identities[] = {
8089
.thread_count = 512,
8190
.shader_core_count = 2,
8291
.nn_core_count = 0,
92+
.nn_mad_per_core = 0,
93+
.tp_core_count = 0,
94+
.on_chip_sram_size = 0,
95+
.axi_sram_size = 0,
8396
.vertex_cache_size = 16,
8497
.vertex_output_buffer_size = 1024,
8598
.pixel_pipes = 1,
@@ -112,6 +125,10 @@ static const struct etnaviv_chip_identity etnaviv_chip_identities[] = {
112125
.thread_count = 512,
113126
.shader_core_count = 2,
114127
.nn_core_count = 0,
128+
.nn_mad_per_core = 0,
129+
.tp_core_count = 0,
130+
.on_chip_sram_size = 0,
131+
.axi_sram_size = 0,
115132
.vertex_cache_size = 16,
116133
.vertex_output_buffer_size = 1024,
117134
.pixel_pipes = 1,
@@ -143,6 +160,11 @@ static const struct etnaviv_chip_identity etnaviv_chip_identities[] = {
143160
.register_max = 64,
144161
.thread_count = 512,
145162
.shader_core_count = 2,
163+
.nn_core_count = 0,
164+
.nn_mad_per_core = 0,
165+
.tp_core_count = 0,
166+
.on_chip_sram_size = 0,
167+
.axi_sram_size = 0,
146168
.vertex_cache_size = 16,
147169
.vertex_output_buffer_size = 1024,
148170
.pixel_pipes = 1,
@@ -175,6 +197,10 @@ static const struct etnaviv_chip_identity etnaviv_chip_identities[] = {
175197
.thread_count = 1024,
176198
.shader_core_count = 4,
177199
.nn_core_count = 0,
200+
.nn_mad_per_core = 0,
201+
.tp_core_count = 0,
202+
.on_chip_sram_size = 0,
203+
.axi_sram_size = 0,
178204
.vertex_cache_size = 16,
179205
.vertex_output_buffer_size = 1024,
180206
.pixel_pipes = 2,
@@ -207,6 +233,10 @@ static const struct etnaviv_chip_identity etnaviv_chip_identities[] = {
207233
.thread_count = 256,
208234
.shader_core_count = 1,
209235
.nn_core_count = 8,
236+
.nn_mad_per_core = 64,
237+
.tp_core_count = 4,
238+
.on_chip_sram_size = 524288,
239+
.axi_sram_size = 1048576,
210240
.vertex_cache_size = 16,
211241
.vertex_output_buffer_size = 1024,
212242
.pixel_pipes = 1,
@@ -239,6 +269,10 @@ static const struct etnaviv_chip_identity etnaviv_chip_identities[] = {
239269
.thread_count = 256,
240270
.shader_core_count = 1,
241271
.nn_core_count = 6,
272+
.nn_mad_per_core = 64,
273+
.tp_core_count = 3,
274+
.on_chip_sram_size = 262144,
275+
.axi_sram_size = 0,
242276
.vertex_cache_size = 16,
243277
.vertex_output_buffer_size = 1024,
244278
.pixel_pipes = 1,
@@ -265,6 +299,9 @@ static const struct etnaviv_chip_identity etnaviv_chip_identities[] = {
265299
bool etnaviv_fill_identity_from_hwdb(struct etnaviv_gpu *gpu)
266300
{
267301
struct etnaviv_chip_identity *ident = &gpu->identity;
302+
const u32 product_id = ident->product_id;
303+
const u32 customer_id = ident->customer_id;
304+
const u32 eco_id = ident->eco_id;
268305
int i;
269306

270307
for (i = 0; i < ARRAY_SIZE(etnaviv_chip_identities); i++) {
@@ -278,6 +315,12 @@ bool etnaviv_fill_identity_from_hwdb(struct etnaviv_gpu *gpu)
278315
etnaviv_chip_identities[i].eco_id == ~0U)) {
279316
memcpy(ident, &etnaviv_chip_identities[i],
280317
sizeof(*ident));
318+
319+
/* Restore some id values as ~0U aka 'don't care' might been used. */
320+
ident->product_id = product_id;
321+
ident->customer_id = customer_id;
322+
ident->eco_id = eco_id;
323+
281324
return true;
282325
}
283326
}

0 commit comments

Comments
 (0)