drm/lima: driver for ARM Mali4xx GPUs
Subsystems (3)
Qiang Yu
maintainerPATCH v4 2/2 drm/lima: driver for ARM Mali4xx GPUs
- Mali 4xx GPUs have two kinds of processors GP and PP. GP is for OpenGL vertex shader processing and PP is for fragment shader processing. Each processor has its own MMU so prcessors work in virtual address space.
- There's only one GP but multiple PP (max 4 for mali 400 and 8 for mali 450) in the same mali 4xx GPU. All PPs are grouped togather to handle a single fragment shader task divided by FB output tiled pixels. Mali 400 user space driver is responsible for assign target tiled pixels to each PP, but mali 450 has a HW module called DLBU to dynamically balance each PP's load.
- User space driver allocate buffer object and map into GPU virtual address space, upload command stream and draw data with CPU mmap of the buffer object, then submit task to GP/PP with a register frame indicating where is the command stream and misc settings.
- There's no command stream validation/relocation due to each user process has its own GPU virtual address space. GP/PP's MMU switch virtual address space before running two tasks from different user process. Error or evil user space code just get MMU fault or GP/PP error IRQ, then the HW/SW will be recovered.
- Use GEM+shmem for MM. Currently just alloc and pin memory when gem object creation. GPU vm map of the buffer is also done in the alloc stage in kernel space. We may delay the memory allocation and real GPU vm map to command submition stage in the furture as improvement.
- Use drm_sched for GPU task schedule. Each OpenGL context should have a lima context object in the kernel to distinguish tasks from different user. drm_sched gets task from each lima context in a fair way.
v4:
- use get param interface to get info
- separate context create/free ioctl
- remove unused max sched task param
- update copyright time
- use xarray instead of idr
- stop using drmP.h
v3:
- fix comments from kbuild robot
- restrict supported arch to tested ones
v2:
- fix syscall argument check
- fix job finish fence leak since kernel 5.0
- use drm syncobj to replace native fence
- move buffer object GPU va map into kernel
- reserve syscall argument space for future info
- remove kernel gem modifier
- switch TTM back to GEM+shmem MM
- use time based io poll
- use whole register name
- adopt gem reservation obj integration
- use drm_timeout_abs_to_jiffies
--- drivers/gpu/drm/Kconfig | 2 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/lima/Kconfig | 10 + drivers/gpu/drm/lima/Makefile | 21 ++ drivers/gpu/drm/lima/lima_bcast.c | 46 +++ drivers/gpu/drm/lima/lima_bcast.h | 14 + drivers/gpu/drm/lima/lima_ctx.c | 97 ++++++ drivers/gpu/drm/lima/lima_ctx.h | 30 ++ drivers/gpu/drm/lima/lima_device.c | 376 +++++++++++++++++++++++ drivers/gpu/drm/lima/lima_device.h | 129 ++++++++ drivers/gpu/drm/lima/lima_dlbu.c | 56 ++++ drivers/gpu/drm/lima/lima_dlbu.h | 18 ++ drivers/gpu/drm/lima/lima_drv.c | 358 ++++++++++++++++++++++ drivers/gpu/drm/lima/lima_drv.h | 45 +++ drivers/gpu/drm/lima/lima_gem.c | 381 +++++++++++++++++++++++ drivers/gpu/drm/lima/lima_gem.h | 25 ++ drivers/gpu/drm/lima/lima_gem_prime.c | 47 +++ drivers/gpu/drm/lima/lima_gem_prime.h | 13 + drivers/gpu/drm/lima/lima_gp.c | 282 +++++++++++++++++ drivers/gpu/drm/lima/lima_gp.h | 16 + drivers/gpu/drm/lima/lima_l2_cache.c | 80 +++++ drivers/gpu/drm/lima/lima_l2_cache.h | 14 + drivers/gpu/drm/lima/lima_mmu.c | 142 +++++++++ drivers/gpu/drm/lima/lima_mmu.h | 16 + drivers/gpu/drm/lima/lima_object.c | 124 ++++++++ drivers/gpu/drm/lima/lima_object.h | 36 +++ drivers/gpu/drm/lima/lima_pmu.c | 59 ++++ drivers/gpu/drm/lima/lima_pmu.h | 12 + drivers/gpu/drm/lima/lima_pp.c | 423 ++++++++++++++++++++++++++ drivers/gpu/drm/lima/lima_pp.h | 19 ++ drivers/gpu/drm/lima/lima_regs.h | 298 ++++++++++++++++++ drivers/gpu/drm/lima/lima_sched.c | 398 ++++++++++++++++++++++++ drivers/gpu/drm/lima/lima_sched.h | 104 +++++++ drivers/gpu/drm/lima/lima_vm.c | 280 +++++++++++++++++ drivers/gpu/drm/lima/lima_vm.h | 62 ++++ include/uapi/drm/lima_drm.h | 137 +++++++++ 36 files changed, 4171 insertions(+) create mode 100644 drivers/gpu/drm/lima/Kconfig create mode 100644 drivers/gpu/drm/lima/Makefile create mode 100644 drivers/gpu/drm/lima/lima_bcast.c create mode 100644 drivers/gpu/drm/lima/lima_bcast.h create mode 100644 drivers/gpu/drm/lima/lima_ctx.c create mode 100644 drivers/gpu/drm/lima/lima_ctx.h create mode 100644 drivers/gpu/drm/lima/lima_device.c create mode 100644 drivers/gpu/drm/lima/lima_device.h create mode 100644 drivers/gpu/drm/lima/lima_dlbu.c create mode 100644 drivers/gpu/drm/lima/lima_dlbu.h create mode 100644 drivers/gpu/drm/lima/lima_drv.c create mode 100644 drivers/gpu/drm/lima/lima_drv.h create mode 100644 drivers/gpu/drm/lima/lima_gem.c create mode 100644 drivers/gpu/drm/lima/lima_gem.h create mode 100644 drivers/gpu/drm/lima/lima_gem_prime.c create mode 100644 drivers/gpu/drm/lima/lima_gem_prime.h create mode 100644 drivers/gpu/drm/lima/lima_gp.c create mode 100644 drivers/gpu/drm/lima/lima_gp.h create mode 100644 drivers/gpu/drm/lima/lima_l2_cache.c create mode 100644 drivers/gpu/drm/lima/lima_l2_cache.h create mode 100644 drivers/gpu/drm/lima/lima_mmu.c create mode 100644 drivers/gpu/drm/lima/lima_mmu.h create mode 100644 drivers/gpu/drm/lima/lima_object.c create mode 100644 drivers/gpu/drm/lima/lima_object.h create mode 100644 drivers/gpu/drm/lima/lima_pmu.c create mode 100644 drivers/gpu/drm/lima/lima_pmu.h create mode 100644 drivers/gpu/drm/lima/lima_pp.c create mode 100644 drivers/gpu/drm/lima/lima_pp.h create mode 100644 drivers/gpu/drm/lima/lima_regs.h create mode 100644 drivers/gpu/drm/lima/lima_sched.c create mode 100644 drivers/gpu/drm/lima/lima_sched.h create mode 100644 drivers/gpu/drm/lima/lima_vm.c create mode 100644 drivers/gpu/drm/lima/lima_vm.h create mode 100644 include/uapi/drm/lima_drm.h
drivers/gpu/drm/Kconfig +2 -0
@@ -333,6 +333,8 @@ source "drivers/gpu/drm/tve200/Kconfig" source "drivers/gpu/drm/xen/Kconfig" +source "drivers/gpu/drm/lima/Kconfig" + # Keep legacy drivers last menuconfig DRM_LEGACY
drivers/gpu/drm/Makefile +1 -0
@@ -109,3 +109,4 @@ obj-$(CONFIG_DRM_TINYDRM) += tinydrm/ obj-$(CONFIG_DRM_PL111) += pl111/ obj-$(CONFIG_DRM_TVE200) += tve200/ obj-$(CONFIG_DRM_XEN) += xen/ +obj-$(CONFIG_DRM_LIMA) += lima/
drivers/gpu/drm/lima/Kconfig new file +10 -0
@@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0 OR MIT +# Copyright 2017-2019 Qiang Yu <[email protected]> + +config DRM_LIMA + tristate "LIMA (DRM support for ARM Mali 400/450 GPU)" + depends on DRM + depends on ARM || ARM64 || COMPILE_TEST + select DRM_SCHED + help + DRM driver for ARM Mali 400/450 GPUs.
drivers/gpu/drm/lima/Makefile new file +21 -0
@@ -0,0 +1,21 @@ +# SPDX-License-Identifier: GPL-2.0 OR MIT +# Copyright 2017-2019 Qiang Yu <[email protected]> + +lima-y := \ + lima_drv.o \ + lima_device.o \ + lima_pmu.o \ + lima_l2_cache.o \ + lima_mmu.o \ + lima_gp.o \ + lima_pp.o \ + lima_gem.o \ + lima_vm.o \ + lima_sched.o \ + lima_ctx.o \ + lima_gem_prime.o \ + lima_dlbu.o \ + lima_bcast.o \ + lima_object.o + +obj-$(CONFIG_DRM_LIMA) += lima.o
drivers/gpu/drm/lima/lima_bcast.c new file +46 -0
46 lines not on this page · raw message
drivers/gpu/drm/lima/lima_bcast.h new file +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 OR MIT */ +/* Copyright 2018-2019 Qiang Yu <[email protected]> */ + +#ifndef __LIMA_BCAST_H__ +#define __LIMA_BCAST_H__ + +struct lima_ip ; + +int lima_bcast_init (struct lima_ip *ip); +void lima_bcast_fini (struct lima_ip *ip); + +void lima_bcast_enable (struct lima_device *dev,int num_pp); + +#endif
drivers/gpu/drm/lima/lima_ctx.c new file +97 -0
97 lines not on this page · raw message
drivers/gpu/drm/lima/lima_ctx.h new file +30 -0
@@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0 OR MIT */ +/* Copyright 2018-2019 Qiang Yu <[email protected]> */ + +#ifndef __LIMA_CTX_H__ +#define __LIMA_CTX_H__ + +#include <linux/xarray.h> + +#include "lima_device.h" + +struct lima_ctx { +struct kref refcnt; +struct lima_device *dev; +struct lima_sched_context context[lima_pipe_num]; +atomic_t guilty; +}; + +struct lima_ctx_mgr { +struct mutex lock; +struct xarray handles; +}; + +int lima_ctx_create (struct lima_device *dev,struct lima_ctx_mgr *mgr,u32 *id); +int lima_ctx_free (struct lima_ctx_mgr *mgr,u32 id); +struct lima_ctx *lima_ctx_get (struct lima_ctx_mgr *mgr,u32 id); +void lima_ctx_put (struct lima_ctx *ctx); +void lima_ctx_mgr_init (struct lima_ctx_mgr *mgr); +void lima_ctx_mgr_fini (struct lima_ctx_mgr *mgr); + +#endif
drivers/gpu/drm/lima/lima_device.c new file +376 -0
376 lines not on this page · raw message
drivers/gpu/drm/lima/lima_device.h new file +129 -0
129 lines not on this page · raw message
drivers/gpu/drm/lima/lima_dlbu.c new file +56 -0
56 lines not on this page · raw message
drivers/gpu/drm/lima/lima_dlbu.h new file +18 -0
@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0 OR MIT */ +/* Copyright 2018-2019 Qiang Yu <[email protected]> */ + +#ifndef __LIMA_DLBU_H__ +#define __LIMA_DLBU_H__ + +struct lima_ip ; +struct lima_device ; + +void lima_dlbu_enable (struct lima_device *dev,int num_pp); +void lima_dlbu_disable (struct lima_device *dev); + +void lima_dlbu_set_reg (struct lima_ip *ip,u32 *reg); + +int lima_dlbu_init (struct lima_ip *ip); +void lima_dlbu_fini (struct lima_ip *ip); + +#endif
drivers/gpu/drm/lima/lima_drv.c new file +358 -0
358 lines not on this page · raw message
drivers/gpu/drm/lima/lima_drv.h new file +45 -0
45 lines not on this page · raw message
drivers/gpu/drm/lima/lima_gem.c new file +381 -0
381 lines not on this page · raw message
drivers/gpu/drm/lima/lima_gem.h new file +25 -0
@@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0 OR MIT */ +/* Copyright 2017-2019 Qiang Yu <[email protected]> */ + +#ifndef __LIMA_GEM_H__ +#define __LIMA_GEM_H__ + +struct lima_bo ; +struct lima_submit ; + +extern const struct vm_operations_struct lima_gem_vm_ops; + +struct lima_bo *lima_gem_create_bo (struct drm_device *dev,u32 size,u32 flags); +int lima_gem_create_handle (struct drm_device *dev,struct drm_file *file, +u32 size,u32 flags,u32 *handle); +void lima_gem_free_object (struct drm_gem_object *obj); +int lima_gem_object_open (struct drm_gem_object *obj,struct drm_file *file); +void lima_gem_object_close (struct drm_gem_object *obj,struct drm_file *file); +int lima_gem_get_info (struct drm_file *file,u32 handle,u32 *va,u64 *offset); +int lima_gem_mmap (struct file *filp,struct vm_area_struct *vma); +int lima_gem_submit (struct drm_file *file,struct lima_submit *submit); +int lima_gem_wait (struct drm_file *file,u32 handle,u32 op,s64 timeout_ns); + +void lima_set_vma_flags (struct vm_area_struct *vma); + +#endif
drivers/gpu/drm/lima/lima_gem_prime.c new file +47 -0
47 lines not on this page · raw message
drivers/gpu/drm/lima/lima_gem_prime.h new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 OR MIT */ +/* Copyright 2018-2019 Qiang Yu <[email protected]> */ + +#ifndef __LIMA_GEM_PRIME_H__ +#define __LIMA_GEM_PRIME_H__ + +struct drm_gem_object *lima_gem_prime_import_sg_table ( +struct drm_device *dev,struct dma_buf_attachment *attach, +struct sg_table *sgt); +struct sg_table *lima_gem_prime_get_sg_table (struct drm_gem_object *obj); +int lima_gem_prime_mmap (struct drm_gem_object *obj,struct vm_area_struct *vma); + +#endif
drivers/gpu/drm/lima/lima_gp.c new file +282 -0
282 lines not on this page · raw message
drivers/gpu/drm/lima/lima_gp.h new file +16 -0
@@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0 OR MIT */ +/* Copyright 2017-2019 Qiang Yu <[email protected]> */ + +#ifndef __LIMA_GP_H__ +#define __LIMA_GP_H__ + +struct lima_ip ; +struct lima_device ; + +int lima_gp_init (struct lima_ip *ip); +void lima_gp_fini (struct lima_ip *ip); + +int lima_gp_pipe_init (struct lima_device *dev); +void lima_gp_pipe_fini (struct lima_device *dev); + +#endif
drivers/gpu/drm/lima/lima_l2_cache.c new file +80 -0
80 lines not on this page · raw message
drivers/gpu/drm/lima/lima_l2_cache.h new file +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0 OR MIT */ +/* Copyright 2017-2019 Qiang Yu <[email protected]> */ + +#ifndef __LIMA_L2_CACHE_H__ +#define __LIMA_L2_CACHE_H__ + +struct lima_ip ; + +int lima_l2_cache_init (struct lima_ip *ip); +void lima_l2_cache_fini (struct lima_ip *ip); + +int lima_l2_cache_flush (struct lima_ip *ip); + +#endif
drivers/gpu/drm/lima/lima_mmu.c new file +142 -0
142 lines not on this page · raw message
drivers/gpu/drm/lima/lima_mmu.h new file +16 -0
@@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0 OR MIT */ +/* Copyright 2017-2019 Qiang Yu <[email protected]> */ + +#ifndef __LIMA_MMU_H__ +#define __LIMA_MMU_H__ + +struct lima_ip ; +struct lima_vm ; + +int lima_mmu_init (struct lima_ip *ip); +void lima_mmu_fini (struct lima_ip *ip); + +void lima_mmu_switch_vm (struct lima_ip *ip,struct lima_vm *vm); +void lima_mmu_page_fault_resume (struct lima_ip *ip); + +#endif
drivers/gpu/drm/lima/lima_object.c new file +124 -0
124 lines not on this page · raw message
drivers/gpu/drm/lima/lima_object.h new file +36 -0
@@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: GPL-2.0 OR MIT */ +/* Copyright 2018-2019 Qiang Yu <[email protected]> */ + +#ifndef __LIMA_OBJECT_H__ +#define __LIMA_OBJECT_H__ + +#include <drm/drm_gem.h> + +#include "lima_device.h" + +struct lima_bo { +struct drm_gem_object gem; + +struct page **pages; +dma_addr_t *pages_dma_addr; +struct sg_table *sgt; +void *vaddr; + +struct mutex lock; +struct list_head va; +}; + +static inline struct lima_bo * +to_lima_bo (struct drm_gem_object *obj) +{ + return container_of(obj, struct lima_bo, gem); +} + +struct lima_bo *lima_bo_create (struct lima_device *dev,u32 size, +u32 flags,struct sg_table *sgt, +struct reservation_object *resv); +void lima_bo_destroy (struct lima_bo *bo); +void *lima_bo_vmap (struct lima_bo *bo); +void lima_bo_vunmap (struct lima_bo *bo); + +#endif
drivers/gpu/drm/lima/lima_pmu.c new file +59 -0
59 lines not on this page · raw message
drivers/gpu/drm/lima/lima_pmu.h new file +12 -0
@@ -0,0 +1,12 @@ +/* SPDX-License-Identifier: GPL-2.0 OR MIT */ +/* Copyright 2017-2019 Qiang Yu <[email protected]> */ + +#ifndef __LIMA_PMU_H__ +#define __LIMA_PMU_H__ + +struct lima_ip ; + +int lima_pmu_init (struct lima_ip *ip); +void lima_pmu_fini (struct lima_ip *ip); + +#endif
drivers/gpu/drm/lima/lima_pp.c new file +423 -0
423 lines not on this page · raw message
drivers/gpu/drm/lima/lima_pp.h new file +19 -0
@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 OR MIT */ +/* Copyright 2017-2019 Qiang Yu <[email protected]> */ + +#ifndef __LIMA_PP_H__ +#define __LIMA_PP_H__ + +struct lima_ip ; +struct lima_device ; + +int lima_pp_init (struct lima_ip *ip); +void lima_pp_fini (struct lima_ip *ip); + +int lima_pp_bcast_init (struct lima_ip *ip); +void lima_pp_bcast_fini (struct lima_ip *ip); + +int lima_pp_pipe_init (struct lima_device *dev); +void lima_pp_pipe_fini (struct lima_device *dev); + +#endif
drivers/gpu/drm/lima/lima_regs.h new file +298 -0
99 lines not on this page · raw message
drivers/gpu/drm/lima/lima_sched.c new file +398 -0
398 lines not on this page · raw message
drivers/gpu/drm/lima/lima_sched.h new file +104 -0
104 lines not on this page · raw message
drivers/gpu/drm/lima/lima_vm.c new file +280 -0
280 lines not on this page · raw message
drivers/gpu/drm/lima/lima_vm.h new file +62 -0
62 lines not on this page · raw message
include/uapi/drm/lima_drm.h new file +137 -0
137 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 6 lines
2.17.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Part of the diff is not shown here. View the raw message.