Skip to content

Commit

Permalink
Merge tag 'drm-etnaviv-next-2024-03-07' of https://git.pengutronix.de…
Browse files Browse the repository at this point in the history
…/git/lst/linux into drm-next

- various code cleanups
- enhancements for NPU and MRT support

Signed-off-by: Dave Airlie <[email protected]>

From: Lucas Stach <[email protected]>
Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
  • Loading branch information
airlied committed Mar 8, 2024
2 parents 5794d2f + b735ee1 commit b0b6739
Show file tree
Hide file tree
Showing 9 changed files with 163 additions and 44 deletions.
1 change: 1 addition & 0 deletions drivers/gpu/drm/etnaviv/etnaviv_cmd_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ static const struct {
ST(0x1480, 8),
ST(0x1500, 8),
ST(0x1520, 8),
ST(0x1540, 8),
ST(0x1608, 1),
ST(0x1610, 1),
ST(0x1658, 1),
Expand Down
93 changes: 61 additions & 32 deletions drivers/gpu/drm/etnaviv/etnaviv_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@
* DRM operations:
*/

static struct device_node *etnaviv_of_first_available_node(void)
{
struct device_node *np;

for_each_compatible_node(np, NULL, "vivante,gc") {
if (of_device_is_available(np))
return np;
}

return NULL;
}

static void load_gpu(struct drm_device *dev)
{
Expand Down Expand Up @@ -79,7 +90,7 @@ static int etnaviv_open(struct drm_device *dev, struct drm_file *file)
drm_sched_entity_init(&ctx->sched_entity[i],
DRM_SCHED_PRIORITY_NORMAL, &sched,
1, NULL);
}
}
}

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

static struct drm_info_list etnaviv_debugfs_list[] = {
{"gpu", show_each_gpu, 0, etnaviv_gpu_debugfs},
{"gem", show_unlocked, 0, etnaviv_gem_show},
{ "mm", show_unlocked, 0, etnaviv_mm_show },
{"mmu", show_each_gpu, 0, etnaviv_mmu_show},
{"ring", show_each_gpu, 0, etnaviv_ring_show},
{"gpu", show_each_gpu, 0, etnaviv_gpu_debugfs},
{"gem", show_unlocked, 0, etnaviv_gem_show},
{ "mm", show_unlocked, 0, etnaviv_mm_show },
{"mmu", show_each_gpu, 0, etnaviv_mmu_show},
{"ring", show_each_gpu, 0, etnaviv_ring_show},
};

static void etnaviv_debugfs_init(struct drm_minor *minor)
Expand Down Expand Up @@ -494,7 +505,7 @@ static const struct drm_driver etnaviv_drm_driver = {
.desc = "etnaviv DRM",
.date = "20151214",
.major = 1,
.minor = 3,
.minor = 4,
};

/*
Expand Down Expand Up @@ -597,9 +608,6 @@ static int etnaviv_pdev_probe(struct platform_device *pdev)
if (!of_device_is_available(core_node))
continue;

if (!first_node)
first_node = core_node;

drm_of_component_match_add(&pdev->dev, &match,
component_compare_of, core_node);
}
Expand Down Expand Up @@ -634,8 +642,11 @@ static int etnaviv_pdev_probe(struct platform_device *pdev)
* device as the GPU we found. This assumes that all Vivante
* GPUs in the system share the same DMA constraints.
*/
if (first_node)
first_node = etnaviv_of_first_available_node();
if (first_node) {
of_dma_configure(&pdev->dev, first_node, true);
of_node_put(first_node);
}

return component_master_add_with_match(dev, &etnaviv_master_ops, match);
}
Expand All @@ -653,11 +664,43 @@ static struct platform_driver etnaviv_platform_driver = {
},
};

static int etnaviv_create_platform_device(const char *name,
struct platform_device **ppdev)
{
struct platform_device *pdev;
int ret;

pdev = platform_device_alloc(name, PLATFORM_DEVID_NONE);
if (!pdev)
return -ENOMEM;

ret = platform_device_add(pdev);
if (ret) {
platform_device_put(pdev);
return ret;
}

*ppdev = pdev;

return 0;
}

static void etnaviv_destroy_platform_device(struct platform_device **ppdev)
{
struct platform_device *pdev = *ppdev;

if (!pdev)
return;

platform_device_unregister(pdev);

*ppdev = NULL;
}

static struct platform_device *etnaviv_drm;

static int __init etnaviv_init(void)
{
struct platform_device *pdev;
int ret;
struct device_node *np;

Expand All @@ -675,27 +718,13 @@ static int __init etnaviv_init(void)
* If the DT contains at least one available GPU device, instantiate
* the DRM platform device.
*/
for_each_compatible_node(np, NULL, "vivante,gc") {
if (!of_device_is_available(np))
continue;

pdev = platform_device_alloc("etnaviv", PLATFORM_DEVID_NONE);
if (!pdev) {
ret = -ENOMEM;
of_node_put(np);
goto unregister_platform_driver;
}
np = etnaviv_of_first_available_node();
if (np) {
of_node_put(np);

ret = platform_device_add(pdev);
if (ret) {
platform_device_put(pdev);
of_node_put(np);
ret = etnaviv_create_platform_device("etnaviv", &etnaviv_drm);
if (ret)
goto unregister_platform_driver;
}

etnaviv_drm = pdev;
of_node_put(np);
break;
}

return 0;
Expand All @@ -710,7 +739,7 @@ module_init(etnaviv_init);

static void __exit etnaviv_exit(void)
{
platform_device_unregister(etnaviv_drm);
etnaviv_destroy_platform_device(&etnaviv_drm);
platform_driver_unregister(&etnaviv_platform_driver);
platform_driver_unregister(&etnaviv_gpu_driver);
}
Expand Down
12 changes: 5 additions & 7 deletions drivers/gpu/drm/etnaviv/etnaviv_gem.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,10 @@ struct page **etnaviv_gem_get_pages(struct etnaviv_gem_object *etnaviv_obj)

if (!etnaviv_obj->sgt) {
struct drm_device *dev = etnaviv_obj->base.dev;
int npages = etnaviv_obj->base.size >> PAGE_SHIFT;
unsigned int npages = etnaviv_obj->base.size >> PAGE_SHIFT;
struct sg_table *sgt;

sgt = drm_prime_pages_to_sg(etnaviv_obj->base.dev,
etnaviv_obj->pages, npages);
sgt = drm_prime_pages_to_sg(dev, etnaviv_obj->pages, npages);
if (IS_ERR(sgt)) {
dev_err(dev->dev, "failed to allocate sgt: %ld\n",
PTR_ERR(sgt));
Expand Down Expand Up @@ -542,7 +541,7 @@ static const struct drm_gem_object_funcs etnaviv_gem_object_funcs = {
.vm_ops = &vm_ops,
};

static int etnaviv_gem_new_impl(struct drm_device *dev, u32 size, u32 flags,
static int etnaviv_gem_new_impl(struct drm_device *dev, u32 flags,
const struct etnaviv_gem_ops *ops, struct drm_gem_object **obj)
{
struct etnaviv_gem_object *etnaviv_obj;
Expand Down Expand Up @@ -591,8 +590,7 @@ int etnaviv_gem_new_handle(struct drm_device *dev, struct drm_file *file,

size = PAGE_ALIGN(size);

ret = etnaviv_gem_new_impl(dev, size, flags,
&etnaviv_gem_shmem_ops, &obj);
ret = etnaviv_gem_new_impl(dev, flags, &etnaviv_gem_shmem_ops, &obj);
if (ret)
goto fail;

Expand Down Expand Up @@ -627,7 +625,7 @@ int etnaviv_gem_new_private(struct drm_device *dev, size_t size, u32 flags,
struct drm_gem_object *obj;
int ret;

ret = etnaviv_gem_new_impl(dev, size, flags, ops, &obj);
ret = etnaviv_gem_new_impl(dev, flags, ops, &obj);
if (ret)
return ret;

Expand Down
33 changes: 32 additions & 1 deletion drivers/gpu/drm/etnaviv/etnaviv_gpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,26 @@ int etnaviv_gpu_get_param(struct etnaviv_gpu *gpu, u32 param, u64 *value)
*value = gpu->identity.eco_id;
break;

case ETNAVIV_PARAM_GPU_NN_CORE_COUNT:
*value = gpu->identity.nn_core_count;
break;

case ETNAVIV_PARAM_GPU_NN_MAD_PER_CORE:
*value = gpu->identity.nn_mad_per_core;
break;

case ETNAVIV_PARAM_GPU_TP_CORE_COUNT:
*value = gpu->identity.tp_core_count;
break;

case ETNAVIV_PARAM_GPU_ON_CHIP_SRAM_SIZE:
*value = gpu->identity.on_chip_sram_size;
break;

case ETNAVIV_PARAM_GPU_AXI_SRAM_SIZE:
*value = gpu->identity.axi_sram_size;
break;

default:
DBG("%s: invalid param: %u", dev_name(gpu->dev), param);
return -EINVAL;
Expand Down Expand Up @@ -513,8 +533,19 @@ static int etnaviv_hw_reset(struct etnaviv_gpu *gpu)
timeout = jiffies + msecs_to_jiffies(1000);

while (time_is_after_jiffies(timeout)) {
/* enable clock */
unsigned int fscale = 1 << (6 - gpu->freq_scale);
u32 pulse_eater = 0x01590880;

/* disable clock gating */
gpu_write_power(gpu, VIVS_PM_POWER_CONTROLS, 0x0);

/* disable pulse eater */
pulse_eater |= BIT(17);
gpu_write_power(gpu, VIVS_PM_PULSE_EATER, pulse_eater);
pulse_eater |= BIT(0);
gpu_write_power(gpu, VIVS_PM_PULSE_EATER, pulse_eater);

/* enable clock */
control = VIVS_HI_CLOCK_CONTROL_FSCALE_VAL(fscale);
etnaviv_gpu_load_clock(gpu, control);

Expand Down
12 changes: 12 additions & 0 deletions drivers/gpu/drm/etnaviv/etnaviv_gpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ struct etnaviv_chip_identity {
/* Number of Neural Network cores. */
u32 nn_core_count;

/* Number of MAD units per Neural Network core. */
u32 nn_mad_per_core;

/* Number of Tensor Processing cores. */
u32 tp_core_count;

/* Size in bytes of the SRAM inside the NPU. */
u32 on_chip_sram_size;

/* Size in bytes of the SRAM across the AXI bus. */
u32 axi_sram_size;

/* Size of the vertex cache. */
u32 vertex_cache_size;

Expand Down
43 changes: 43 additions & 0 deletions drivers/gpu/drm/etnaviv/etnaviv_hwdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ static const struct etnaviv_chip_identity etnaviv_chip_identities[] = {
.thread_count = 128,
.shader_core_count = 1,
.nn_core_count = 0,
.nn_mad_per_core = 0,
.tp_core_count = 0,
.on_chip_sram_size = 0,
.axi_sram_size = 0,
.vertex_cache_size = 8,
.vertex_output_buffer_size = 1024,
.pixel_pipes = 1,
Expand Down Expand Up @@ -48,6 +52,11 @@ static const struct etnaviv_chip_identity etnaviv_chip_identities[] = {
.register_max = 64,
.thread_count = 256,
.shader_core_count = 1,
.nn_core_count = 0,
.nn_mad_per_core = 0,
.tp_core_count = 0,
.on_chip_sram_size = 0,
.axi_sram_size = 0,
.vertex_cache_size = 8,
.vertex_output_buffer_size = 512,
.pixel_pipes = 1,
Expand Down Expand Up @@ -80,6 +89,10 @@ static const struct etnaviv_chip_identity etnaviv_chip_identities[] = {
.thread_count = 512,
.shader_core_count = 2,
.nn_core_count = 0,
.nn_mad_per_core = 0,
.tp_core_count = 0,
.on_chip_sram_size = 0,
.axi_sram_size = 0,
.vertex_cache_size = 16,
.vertex_output_buffer_size = 1024,
.pixel_pipes = 1,
Expand Down Expand Up @@ -112,6 +125,10 @@ static const struct etnaviv_chip_identity etnaviv_chip_identities[] = {
.thread_count = 512,
.shader_core_count = 2,
.nn_core_count = 0,
.nn_mad_per_core = 0,
.tp_core_count = 0,
.on_chip_sram_size = 0,
.axi_sram_size = 0,
.vertex_cache_size = 16,
.vertex_output_buffer_size = 1024,
.pixel_pipes = 1,
Expand Down Expand Up @@ -143,6 +160,11 @@ static const struct etnaviv_chip_identity etnaviv_chip_identities[] = {
.register_max = 64,
.thread_count = 512,
.shader_core_count = 2,
.nn_core_count = 0,
.nn_mad_per_core = 0,
.tp_core_count = 0,
.on_chip_sram_size = 0,
.axi_sram_size = 0,
.vertex_cache_size = 16,
.vertex_output_buffer_size = 1024,
.pixel_pipes = 1,
Expand Down Expand Up @@ -175,6 +197,10 @@ static const struct etnaviv_chip_identity etnaviv_chip_identities[] = {
.thread_count = 1024,
.shader_core_count = 4,
.nn_core_count = 0,
.nn_mad_per_core = 0,
.tp_core_count = 0,
.on_chip_sram_size = 0,
.axi_sram_size = 0,
.vertex_cache_size = 16,
.vertex_output_buffer_size = 1024,
.pixel_pipes = 2,
Expand Down Expand Up @@ -207,6 +233,10 @@ static const struct etnaviv_chip_identity etnaviv_chip_identities[] = {
.thread_count = 256,
.shader_core_count = 1,
.nn_core_count = 8,
.nn_mad_per_core = 64,
.tp_core_count = 4,
.on_chip_sram_size = 524288,
.axi_sram_size = 1048576,
.vertex_cache_size = 16,
.vertex_output_buffer_size = 1024,
.pixel_pipes = 1,
Expand Down Expand Up @@ -239,6 +269,10 @@ static const struct etnaviv_chip_identity etnaviv_chip_identities[] = {
.thread_count = 256,
.shader_core_count = 1,
.nn_core_count = 6,
.nn_mad_per_core = 64,
.tp_core_count = 3,
.on_chip_sram_size = 262144,
.axi_sram_size = 0,
.vertex_cache_size = 16,
.vertex_output_buffer_size = 1024,
.pixel_pipes = 1,
Expand All @@ -265,6 +299,9 @@ static const struct etnaviv_chip_identity etnaviv_chip_identities[] = {
bool etnaviv_fill_identity_from_hwdb(struct etnaviv_gpu *gpu)
{
struct etnaviv_chip_identity *ident = &gpu->identity;
const u32 product_id = ident->product_id;
const u32 customer_id = ident->customer_id;
const u32 eco_id = ident->eco_id;
int i;

for (i = 0; i < ARRAY_SIZE(etnaviv_chip_identities); i++) {
Expand All @@ -278,6 +315,12 @@ bool etnaviv_fill_identity_from_hwdb(struct etnaviv_gpu *gpu)
etnaviv_chip_identities[i].eco_id == ~0U)) {
memcpy(ident, &etnaviv_chip_identities[i],
sizeof(*ident));

/* Restore some id values as ~0U aka 'don't care' might been used. */
ident->product_id = product_id;
ident->customer_id = customer_id;
ident->eco_id = eco_id;

return true;
}
}
Expand Down
Loading

0 comments on commit b0b6739

Please sign in to comment.