New DRM driver for Intel VPU
Subsystems (2)
v3 cover New DRM driver for Intel VPU
Hi,
This patchset contains a new Linux* Kernel Driver for Intel® VPUs.
VPU stands for Versatile Processing Unit and it is an AI inference accelerator integrated with Intel non-server CPUs starting from 14th generation. VPU enables efficient execution of Deep Learning applications like object detection, classification etc.
Driver is part of gpu/drm subsystem because VPU is similar in operation to an integrated GPU. Reusing drm driver init, ioctl handling, gem and prime helpers and drm_mm allows to minimize code duplication in the kernel.
The whole driver is licensed under GPL-2.0-only except for two headers imported from the firmware that are MIT licensed.
User mode driver stack consists of Level Zero API driver and OpenVINO plugin. Both should be open-sourced by the end of Q4.
The firmware for the VPU will be distributed as a closed source binary.
Regards,
Jacek
v3:
- Fixed alignment warning in ivpu_ipc.c when building with W=1
v2: https://lore.kernel.org/all/[email protected]/
- Rename the driver from "drm/vpu" to "drm/ivpu"
- Add a TODO file
- Add support for WC buffers
v1: https://lore.kernel.org/all/[email protected]/
Jacek Lawrynowicz (7):
drm/ivpu: Introduce a new DRM driver for Intel VPU drm/ivpu: Add Intel VPU MMU support drm/ivpu: Add GEM buffer object management drm/ivpu: Add IPC driver and JSM messages drm/ivpu: Implement firmware parsing and booting drm/ivpu: Add command buffer submission logic drm/ivpu: Add PM support
MAINTAINERS | 8 + drivers/gpu/drm/Kconfig | 2 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/ivpu/Kconfig | 12 + drivers/gpu/drm/ivpu/Makefile | 16 + drivers/gpu/drm/ivpu/TODO | 7 + drivers/gpu/drm/ivpu/ivpu_drv.c | 643 ++++++++++++++ drivers/gpu/drm/ivpu/ivpu_drv.h | 178 ++++ drivers/gpu/drm/ivpu/ivpu_fw.c | 426 +++++++++ drivers/gpu/drm/ivpu/ivpu_fw.h | 38 + drivers/gpu/drm/ivpu/ivpu_gem.c | 836 ++++++++++++++++++ drivers/gpu/drm/ivpu/ivpu_gem.h | 128 +++ drivers/gpu/drm/ivpu/ivpu_hw.h | 169 ++++ drivers/gpu/drm/ivpu/ivpu_hw_mtl.c | 1060 +++++++++++++++++++++++ drivers/gpu/drm/ivpu/ivpu_hw_mtl_reg.h | 468 ++++++++++ drivers/gpu/drm/ivpu/ivpu_hw_reg_io.h | 115 +++ drivers/gpu/drm/ivpu/ivpu_ipc.c | 508 +++++++++++ drivers/gpu/drm/ivpu/ivpu_ipc.h | 90 ++ drivers/gpu/drm/ivpu/ivpu_job.c | 629 ++++++++++++++ drivers/gpu/drm/ivpu/ivpu_job.h | 73 ++ drivers/gpu/drm/ivpu/ivpu_jsm_msg.c | 220 +++++ drivers/gpu/drm/ivpu/ivpu_jsm_msg.h | 25 + drivers/gpu/drm/ivpu/ivpu_mmu.c | 888 +++++++++++++++++++ drivers/gpu/drm/ivpu/ivpu_mmu.h | 53 ++ drivers/gpu/drm/ivpu/ivpu_mmu_context.c | 419 +++++++++ drivers/gpu/drm/ivpu/ivpu_mmu_context.h | 49 ++ drivers/gpu/drm/ivpu/ivpu_pm.c | 352 ++++++++ drivers/gpu/drm/ivpu/ivpu_pm.h | 38 + drivers/gpu/drm/ivpu/vpu_boot_api.h | 241 ++++++ drivers/gpu/drm/ivpu/vpu_jsm_api.h | 616 +++++++++++++ include/uapi/drm/ivpu_drm.h | 343 ++++++++ 31 files changed, 8651 insertions(+) create mode 100644 drivers/gpu/drm/ivpu/Kconfig create mode 100644 drivers/gpu/drm/ivpu/Makefile create mode 100644 drivers/gpu/drm/ivpu/TODO create mode 100644 drivers/gpu/drm/ivpu/ivpu_drv.c create mode 100644 drivers/gpu/drm/ivpu/ivpu_drv.h create mode 100644 drivers/gpu/drm/ivpu/ivpu_fw.c create mode 100644 drivers/gpu/drm/ivpu/ivpu_fw.h create mode 100644 drivers/gpu/drm/ivpu/ivpu_gem.c create mode 100644 drivers/gpu/drm/ivpu/ivpu_gem.h create mode 100644 drivers/gpu/drm/ivpu/ivpu_hw.h create mode 100644 drivers/gpu/drm/ivpu/ivpu_hw_mtl.c create mode 100644 drivers/gpu/drm/ivpu/ivpu_hw_mtl_reg.h create mode 100644 drivers/gpu/drm/ivpu/ivpu_hw_reg_io.h create mode 100644 drivers/gpu/drm/ivpu/ivpu_ipc.c create mode 100644 drivers/gpu/drm/ivpu/ivpu_ipc.h create mode 100644 drivers/gpu/drm/ivpu/ivpu_job.c create mode 100644 drivers/gpu/drm/ivpu/ivpu_job.h create mode 100644 drivers/gpu/drm/ivpu/ivpu_jsm_msg.c create mode 100644 drivers/gpu/drm/ivpu/ivpu_jsm_msg.h create mode 100644 drivers/gpu/drm/ivpu/ivpu_mmu.c create mode 100644 drivers/gpu/drm/ivpu/ivpu_mmu.h create mode 100644 drivers/gpu/drm/ivpu/ivpu_mmu_context.c create mode 100644 drivers/gpu/drm/ivpu/ivpu_mmu_context.h create mode 100644 drivers/gpu/drm/ivpu/ivpu_pm.c create mode 100644 drivers/gpu/drm/ivpu/ivpu_pm.h create mode 100644 drivers/gpu/drm/ivpu/vpu_boot_api.h create mode 100644 drivers/gpu/drm/ivpu/vpu_jsm_api.h create mode 100644 include/uapi/drm/ivpu_drm.h
--
2.34.1
PATCH v3 1/7 drm/ivpu: Introduce a new DRM driver for Intel VPU
VPU stands for Versatile Processing Unit and it's a CPU-integrated inference accelerator for Computer Vision and Deep Learning applications.
The VPU device consist of following componensts:
- Buttress - provides CPU to VPU integration, interrupt, frequency and power management.
- Memory Management Unit (based on ARM MMU-600) - translates VPU to host DMA addresses, isolates user workloads.
- RISC based microcontroller - executes firmware that provides job execution API for the kernel-mode driver
- Neural Compute Subsystem (NCS) - does the actual work, provides Compute and Copy engines.
- Network on Chip (NoC) - network fabric connecting all the components
This driver supports VPU IP v2.7 integrated into Intel Meteor Lake client CPUs (14th generation).
Module sources are at drivers/gpu/drm/ivpu and module name is "intel_vpu.ko".
This patch includes only very besic functionality:
- module, PCI device and IRQ initialization
- register definitions and low level register manipulation functions
- SET/GET_PARAM ioctls
- power up without firmware
--- MAINTAINERS | 8 + drivers/gpu/drm/Kconfig | 2 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/ivpu/Kconfig | 12 + drivers/gpu/drm/ivpu/Makefile | 8 + drivers/gpu/drm/ivpu/TODO | 7 + drivers/gpu/drm/ivpu/ivpu_drv.c | 392 +++++++++ drivers/gpu/drm/ivpu/ivpu_drv.h | 153 ++++ drivers/gpu/drm/ivpu/ivpu_hw.h | 169 ++++ drivers/gpu/drm/ivpu/ivpu_hw_mtl.c | 1021 ++++++++++++++++++++++++ drivers/gpu/drm/ivpu/ivpu_hw_mtl_reg.h | 468 +++++++++++ drivers/gpu/drm/ivpu/ivpu_hw_reg_io.h | 115 +++ include/uapi/drm/ivpu_drm.h | 95 +++ 13 files changed, 2451 insertions(+) create mode 100644 drivers/gpu/drm/ivpu/Kconfig create mode 100644 drivers/gpu/drm/ivpu/Makefile create mode 100644 drivers/gpu/drm/ivpu/TODO create mode 100644 drivers/gpu/drm/ivpu/ivpu_drv.c create mode 100644 drivers/gpu/drm/ivpu/ivpu_drv.h create mode 100644 drivers/gpu/drm/ivpu/ivpu_hw.h create mode 100644 drivers/gpu/drm/ivpu/ivpu_hw_mtl.c create mode 100644 drivers/gpu/drm/ivpu/ivpu_hw_mtl_reg.h create mode 100644 drivers/gpu/drm/ivpu/ivpu_hw_reg_io.h create mode 100644 include/uapi/drm/ivpu_drm.h
MAINTAINERS +8 -0
@@ -7046,6 +7046,14 @@ F: Documentation/devicetree/bindings/gpu/vivante,gc.yaml F: drivers/gpu/drm/etnaviv/ F: include/uapi/drm/etnaviv_drm.h +DRM DRIVERS FOR VPU +M: Jacek Lawrynowicz <[email protected]> +M: Stanislaw Gruszka <[email protected]> +S: Supported +T: git git://anongit.freedesktop.org/drm/drm-misc +F: drivers/gpu/drm/ivpu/ +F: include/uapi/drm/ivpu_drm.h + DRM DRIVERS FOR XEN M: Oleksandr Andrushchenko <[email protected]> L: [email protected]
drivers/gpu/drm/Kconfig +2 -0
@@ -364,6 +364,8 @@ source "drivers/gpu/drm/v3d/Kconfig" source "drivers/gpu/drm/vc4/Kconfig" +source "drivers/gpu/drm/ivpu/Kconfig" + source "drivers/gpu/drm/etnaviv/Kconfig" source "drivers/gpu/drm/hisilicon/Kconfig"
drivers/gpu/drm/Makefile +1 -0
@@ -94,6 +94,7 @@ obj-$(CONFIG_DRM_KMB_DISPLAY) += kmb/ obj-$(CONFIG_DRM_MGAG200) += mgag200/ obj-$(CONFIG_DRM_V3D) += v3d/ obj-$(CONFIG_DRM_VC4) += vc4/ +obj-$(CONFIG_DRM_IVPU) += ivpu/ obj-$(CONFIG_DRM_SIS) += sis/ obj-$(CONFIG_DRM_SAVAGE)+= savage/ obj-$(CONFIG_DRM_VMWGFX)+= vmwgfx/
drivers/gpu/drm/ivpu/Kconfig new file +12 -0
@@ -0,0 +1,12 @@ +# SPDX-License-Identifier: GPL-2.0-only +config DRM_IVPU + tristate "Intel VPU for Meteor Lake and newer" + depends on DRM + depends on X86_64 && PCI + select SHMEM + help + Choose this option if you have a system that has an 14th generation Intel CPU + or newer. VPU stands for Versatile Processing Unit and it's a CPU-integrated + inference accelerator for Computer Vision and Deep Learning applications. + + If "M" is selected, the module will be called intel_vpu.
drivers/gpu/drm/ivpu/Makefile new file +8 -0
@@ -0,0 +1,8 @@ +# SPDX-License-Identifier: GPL-2.0-only +# Copyright © 2022 Intel Corporation + +intel_vpu-y := \ + ivpu_drv.o \ + ivpu_hw_mtl.o + +obj-$(CONFIG_DRM_IVPU) += intel_vpu.o
drivers/gpu/drm/ivpu/TODO new file +7 -0
@@ -0,0 +1,7 @@ +- Implement support for BLOB IDs +- Add debugfs support to improve debugging and testing +- Add tracing events for performance debugging +- Implement HW based scheduling support +- Use syncobjs for submit/sync +- Refactor IPC protocol to improve message latency +- Implement BO cache and MADVISE IOCTL
drivers/gpu/drm/ivpu/ivpu_drv.c new file +392 -0
392 lines not on this page · raw message
drivers/gpu/drm/ivpu/ivpu_drv.h new file +153 -0
153 lines not on this page · raw message
drivers/gpu/drm/ivpu/ivpu_hw.h new file +169 -0
169 lines not on this page · raw message
drivers/gpu/drm/ivpu/ivpu_hw_mtl.c new file +1021 -0
1,021 lines not on this page · raw message
drivers/gpu/drm/ivpu/ivpu_hw_mtl_reg.h new file +468 -0
468 lines not on this page · raw message
drivers/gpu/drm/ivpu/ivpu_hw_reg_io.h new file +115 -0
115 lines not on this page · raw message
include/uapi/drm/ivpu_drm.h new file +95 -0
95 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v3 2/7 drm/ivpu: Add Intel VPU MMU support
In reply to Jacek LawrynowiczVPU Memory Management Unit is based on ARM MMU-600.
It allows to create multiple virtual address spaces for the device and map noncontinuous host memory (there is no dedicated memory on the VPU).
Address space is implemented as a struct ivpu_mmu_context, it has an ID, drm_mm allocator for VPU addresses and struct ivpu_mmu_pgtable that holds actual 3-level, 4KB page table.
Context with ID 0 (global context) is created upon driver initialization and it's mainly used for mapping memory required to execute the firmware.
Contexts with non-zero IDs are user contexts allocated each time the devices is open()-ed and they map command buffers and other workload-related memory.
Workloads executing in a given contexts have access only
to the memory mapped in this context.
This patch is has to main files:
- ivpu_mmu_context.c handles MMU page tables and memory mapping
- ivpu_mmu.c implements a driver that programs the MMU device
--- drivers/gpu/drm/ivpu/Makefile | 4 +- drivers/gpu/drm/ivpu/ivpu_drv.c | 59 +- drivers/gpu/drm/ivpu/ivpu_drv.h | 7 + drivers/gpu/drm/ivpu/ivpu_hw_mtl.c | 10 + drivers/gpu/drm/ivpu/ivpu_mmu.c | 883 ++++++++++++++++++++++++ drivers/gpu/drm/ivpu/ivpu_mmu.h | 53 ++ drivers/gpu/drm/ivpu/ivpu_mmu_context.c | 419 +++++++++++ drivers/gpu/drm/ivpu/ivpu_mmu_context.h | 49 ++ include/uapi/drm/ivpu_drm.h | 4 + 9 files changed, 1485 insertions(+), 3 deletions(-) create mode 100644 drivers/gpu/drm/ivpu/ivpu_mmu.c create mode 100644 drivers/gpu/drm/ivpu/ivpu_mmu.h create mode 100644 drivers/gpu/drm/ivpu/ivpu_mmu_context.c create mode 100644 drivers/gpu/drm/ivpu/ivpu_mmu_context.h
drivers/gpu/drm/ivpu/Makefile +3 -1
@@ -3,6 +3,8 @@ intel_vpu-y := \ ivpu_drv.o \ - ivpu_hw_mtl.o + ivpu_hw_mtl.o \ + ivpu_mmu.o \ + ivpu_mmu_context.o obj-$(CONFIG_DRM_IVPU) += intel_vpu.o
drivers/gpu/drm/ivpu/ivpu_drv.c +57 -2
136 lines not on this page · raw message
drivers/gpu/drm/ivpu/ivpu_drv.h +7 -0
@@ -14,6 +14,8 @@#include <linux/xarray.h> #include <uapi/drm/ivpu_drm.h> +#include "ivpu_mmu_context.h" +#define DRIVER_NAME "intel_vpu"#define DRIVER_DESC "Driver for Intel Versatile Processing Unit (VPU)"#define DRIVER_DATE "20220913"
@@ -70,6 +72,7 @@ struct ivpu_wa_table { };struct ivpu_hw_info ; +struct ivpu_mmu_info ;struct ivpu_device {struct drm_device drm;/* Must be first */
@@ -80,7 +83,9 @@ struct ivpu_device {struct ivpu_wa_table wa;struct ivpu_hw_info *hw; +struct ivpu_mmu_info *mmu; +struct ivpu_mmu_context gctx;struct xarray context_xa;struct xa_limit context_xa_limit;
@@ -95,6 +100,8 @@ struct ivpu_device {struct ivpu_file_priv {struct kref ref;struct ivpu_device *vdev; +struct mutex lock; +struct ivpu_mmu_context ctx;u32 priority; };
drivers/gpu/drm/ivpu/ivpu_hw_mtl.c +10 -0
@@ -7,6 +7,7 @@#include "ivpu_hw_mtl_reg.h" #include "ivpu_hw_reg_io.h" #include "ivpu_hw.h" +#include "ivpu_mmu.h" #define TILE_FUSE_ENABLE_BOTH 0x0#define TILE_FUSE_ENABLE_UPPER 0x1
@@ -930,6 +931,15 @@ static irqreturn_t ivpu_hw_mtl_irqv_handler(struct ivpu_device *vdev, int irq)REGV_WR32 (MTL_VPU_HOST_SS_ICB_CLEAR_0 , status); +if (REG_TEST_FLD (MTL_VPU_HOST_SS_ICB_STATUS_0 ,MMU_IRQ_0_INT , status)) + ret &=ivpu_mmu_irq_evtq_handler (vdev); + +if (REG_TEST_FLD (MTL_VPU_HOST_SS_ICB_STATUS_0 ,MMU_IRQ_1_INT , status)) +ivpu_dbg (IRQ ,"MMU sync complete\n" ); + +if (REG_TEST_FLD (MTL_VPU_HOST_SS_ICB_STATUS_0 ,MMU_IRQ_2_INT , status)) + ret &=ivpu_mmu_irq_gerr_handler (vdev); +if (REG_TEST_FLD (MTL_VPU_HOST_SS_ICB_STATUS_0 ,CPU_INT_REDIRECT_0_INT , status)) ret &=ivpu_hw_mtl_irq_wdt_mss_handler (vdev);
drivers/gpu/drm/ivpu/ivpu_mmu.c new file +883 -0
883 lines not on this page · raw message
drivers/gpu/drm/ivpu/ivpu_mmu.h new file +53 -0
53 lines not on this page · raw message
drivers/gpu/drm/ivpu/ivpu_mmu_context.c new file +419 -0
419 lines not on this page · raw message
drivers/gpu/drm/ivpu/ivpu_mmu_context.h new file +49 -0
49 lines not on this page · raw message
include/uapi/drm/ivpu_drm.h +4 -0
@@ -38,6 +38,7 @@ extern "C" {#define DRM_IVPU_PARAM_NUM_CONTEXTS 4#define DRM_IVPU_PARAM_CONTEXT_BASE_ADDRESS 5#define DRM_IVPU_PARAM_CONTEXT_PRIORITY 6 +#define DRM_IVPU_PARAM_CONTEXT_ID 7#define DRM_IVPU_PLATFORM_TYPE_SILICON 0
@@ -78,6 +79,9 @@ struct drm_ivpu_param {* Value of current context scheduling priority (read-write). * See DRM_IVPU_CONTEXT_PRIORITY_* for possible values. * +* %DRM_IVPU_PARAM_CONTEXT_ID: +* Current context ID, always greater than 0 (read-only) +* */ __u32 param;
Signature · 1 line
2.34.1
PATCH v3 3/7 drm/ivpu: Add GEM buffer object management
In reply to Jacek LawrynowiczAdds four types of GEM-based BOs for the VPU:
- shmem
- userptr
- internal
- prime
All types are implemented as struct ivpu_bo, based on
struct drm_gem_object. VPU address is allocated when buffer is created except for imported prime buffers that allocate it in BO_INFO IOCTL due to missing file_priv arg in gem_prime_import callback. Internal buffers are pinned on creation, the rest of buffers types can be pinned on demand (in SUBMIT IOCTL).
Buffer VPU address, allocated pages and mappings are relased when the buffer is destroyed.
Eviction mechism is planned for future versions.
Add three new IOCTLs: BO_CREATE, BO_INFO, BO_USERPTR
--- drivers/gpu/drm/ivpu/Makefile | 1 + drivers/gpu/drm/ivpu/ivpu_drv.c | 9 + drivers/gpu/drm/ivpu/ivpu_gem.c | 823 ++++++++++++++++++++++++++++++++ drivers/gpu/drm/ivpu/ivpu_gem.h | 128 +++++ include/uapi/drm/ivpu_drm.h | 127 +++++ 5 files changed, 1088 insertions(+) create mode 100644 drivers/gpu/drm/ivpu/ivpu_gem.c create mode 100644 drivers/gpu/drm/ivpu/ivpu_gem.h
drivers/gpu/drm/ivpu/Makefile +1 -0
@@ -3,6 +3,7 @@ intel_vpu-y := \ ivpu_drv.o \ + ivpu_gem.o \ ivpu_hw_mtl.o \ ivpu_mmu.o \ ivpu_mmu_context.o
drivers/gpu/drm/ivpu/ivpu_drv.c +9 -0
@@ -11,8 +11,10 @@#include <drm/drm_file.h> #include <drm/drm_gem.h> #include <drm/drm_ioctl.h> +#include <drm/drm_prime.h> #include "ivpu_drv.h" +#include "ivpu_gem.h" #include "ivpu_hw.h" #include "ivpu_mmu.h" #include "ivpu_mmu_context.h"
@@ -187,6 +189,9 @@ static void ivpu_postclose(struct drm_device *dev, struct drm_file *file)static const struct drm_ioctl_desc ivpu_drm_ioctls[] = {DRM_IOCTL_DEF_DRV (IVPU_GET_PARAM , ivpu_get_param_ioctl,DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (IVPU_SET_PARAM , ivpu_set_param_ioctl,DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (IVPU_BO_CREATE , ivpu_bo_create_ioctl,DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (IVPU_BO_INFO , ivpu_bo_info_ioctl,DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (IVPU_BO_USERPTR , ivpu_bo_userptr_ioctl,DRM_RENDER_ALLOW ), };DEFINE_DRM_GEM_FOPS (ivpu_fops);
@@ -210,6 +215,10 @@ static const struct drm_driver driver = { .open = ivpu_open, .postclose = ivpu_postclose, + .prime_handle_to_fd = drm_gem_prime_handle_to_fd, + .prime_fd_to_handle = drm_gem_prime_fd_to_handle, + .gem_prime_import = ivpu_gem_prime_import, + .gem_prime_mmap = drm_gem_prime_mmap, .ioctls = ivpu_drm_ioctls, .num_ioctls = ARRAY_SIZE(ivpu_drm_ioctls),
drivers/gpu/drm/ivpu/ivpu_gem.c new file +823 -0
823 lines not on this page · raw message
drivers/gpu/drm/ivpu/ivpu_gem.h new file +128 -0
128 lines not on this page · raw message
include/uapi/drm/ivpu_drm.h +127 -0
145 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v3 4/7 drm/ivpu: Add IPC driver and JSM messages
In reply to Jacek LawrynowiczThe IPC driver is used to send and receive messages to/from firmware running on the VPU.
The only supported IPC message format is Job Submission Model (JSM) defined in vpu_jsm_api.h header.
--- drivers/gpu/drm/ivpu/Makefile | 2 + drivers/gpu/drm/ivpu/ivpu_drv.c | 15 + drivers/gpu/drm/ivpu/ivpu_drv.h | 2 + drivers/gpu/drm/ivpu/ivpu_hw_mtl.c | 4 + drivers/gpu/drm/ivpu/ivpu_ipc.c | 499 ++++++++++++++++++++++ drivers/gpu/drm/ivpu/ivpu_ipc.h | 90 ++++ drivers/gpu/drm/ivpu/ivpu_jsm_msg.c | 220 ++++++++++ drivers/gpu/drm/ivpu/ivpu_jsm_msg.h | 25 ++ drivers/gpu/drm/ivpu/vpu_jsm_api.h | 616 ++++++++++++++++++++++++++++ 9 files changed, 1473 insertions(+) create mode 100644 drivers/gpu/drm/ivpu/ivpu_ipc.c create mode 100644 drivers/gpu/drm/ivpu/ivpu_ipc.h create mode 100644 drivers/gpu/drm/ivpu/ivpu_jsm_msg.c create mode 100644 drivers/gpu/drm/ivpu/ivpu_jsm_msg.h create mode 100644 drivers/gpu/drm/ivpu/vpu_jsm_api.h
drivers/gpu/drm/ivpu/Makefile +2 -0
@@ -5,6 +5,8 @@ intel_vpu-y := \ ivpu_drv.o \ ivpu_gem.o \ ivpu_hw_mtl.o \ + ivpu_ipc.o \ + ivpu_jsm_msg.o \ ivpu_mmu.o \ ivpu_mmu_context.o
drivers/gpu/drm/ivpu/ivpu_drv.c +15 -0
@@ -16,6 +16,7 @@#include "ivpu_drv.h" #include "ivpu_gem.h" #include "ivpu_hw.h" +#include "ivpu_ipc.h" #include "ivpu_mmu.h" #include "ivpu_mmu_context.h"
@@ -201,6 +202,7 @@ int ivpu_shutdown(struct ivpu_device *vdev)int ret;ivpu_hw_irq_disable (vdev); +ivpu_ipc_disable (vdev);ivpu_mmu_disable (vdev); ret =ivpu_hw_power_down (vdev);
@@ -318,6 +320,10 @@ static int ivpu_dev_init(struct ivpu_device *vdev)if (!vdev->mmu)return -ENOMEM ; + vdev->ipc =devm_kzalloc (vdev->drm.dev,sizeof (*vdev->ipc),GFP_KERNEL ); +if (!vdev->ipc) +return -ENOMEM ; + vdev->hw->ops = &ivpu_hw_mtl_ops; vdev->platform =IVPU_PLATFORM_INVALID ;
@@ -361,8 +367,16 @@ static int ivpu_dev_init(struct ivpu_device *vdev) goto err_mmu_gctx_fini; } + ret =ivpu_ipc_init (vdev); +if (ret) { +ivpu_err (vdev,"Failed to initialize IPC: %d\n" , ret); + goto err_mmu_fini; + } +return 0 ; +err_mmu_fini: +ivpu_mmu_fini (vdev); err_mmu_gctx_fini:ivpu_mmu_global_context_fini (vdev); err_power_down:
@@ -378,6 +392,7 @@ static void ivpu_dev_fini(struct ivpu_device *vdev) {ivpu_shutdown (vdev); +ivpu_ipc_fini (vdev);ivpu_mmu_fini (vdev);ivpu_mmu_global_context_fini (vdev);ivpu_irq_fini (vdev);
drivers/gpu/drm/ivpu/ivpu_drv.h +2 -0
@@ -73,6 +73,7 @@ struct ivpu_wa_table {struct ivpu_hw_info ;struct ivpu_mmu_info ; +struct ivpu_ipc_info ;struct ivpu_device {struct drm_device drm;/* Must be first */
@@ -84,6 +85,7 @@ struct ivpu_device {struct ivpu_wa_table wa;struct ivpu_hw_info *hw;struct ivpu_mmu_info *mmu; +struct ivpu_ipc_info *ipc;struct ivpu_mmu_context gctx;struct xarray context_xa;
drivers/gpu/drm/ivpu/ivpu_hw_mtl.c +4 -0
@@ -7,6 +7,7 @@#include "ivpu_hw_mtl_reg.h" #include "ivpu_hw_reg_io.h" #include "ivpu_hw.h" +#include "ivpu_ipc.h" #include "ivpu_mmu.h" #define TILE_FUSE_ENABLE_BOTH 0x0
@@ -931,6 +932,9 @@ static irqreturn_t ivpu_hw_mtl_irqv_handler(struct ivpu_device *vdev, int irq)REGV_WR32 (MTL_VPU_HOST_SS_ICB_CLEAR_0 , status); +if (REG_TEST_FLD (MTL_VPU_HOST_SS_ICB_STATUS_0 ,HOST_IPC_FIFO_INT , status)) + ret &=ivpu_ipc_irq_handler (vdev); +if (REG_TEST_FLD (MTL_VPU_HOST_SS_ICB_STATUS_0 ,MMU_IRQ_0_INT , status)) ret &=ivpu_mmu_irq_evtq_handler (vdev);
drivers/gpu/drm/ivpu/ivpu_ipc.c new file +499 -0
499 lines not on this page · raw message
drivers/gpu/drm/ivpu/ivpu_ipc.h new file +90 -0
90 lines not on this page · raw message
drivers/gpu/drm/ivpu/ivpu_jsm_msg.c new file +220 -0
220 lines not on this page · raw message
drivers/gpu/drm/ivpu/ivpu_jsm_msg.h new file +25 -0
@@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Copyright © 2020-2022 Intel Corporation +*/ + +#ifndef __IVPU_JSM_MSG_H__ +#define __IVPU_JSM_MSG_H__ + +#include "vpu_jsm_api.h" + +const char *ivpu_jsm_msg_type_to_str (enum vpu_ipc_msg_type type); + +int ivpu_jsm_register_db (struct ivpu_device *vdev,u32 ctx_id,u32 db_id, +u64 jobq_base,u32 jobq_size); +int ivpu_jsm_unregister_db (struct ivpu_device *vdev,u32 db_id); +int ivpu_jsm_get_heartbeat (struct ivpu_device *vdev,u32 engine,u64 *heartbeat); +int ivpu_jsm_reset_engine (struct ivpu_device *vdev,u32 engine); +int ivpu_jsm_preempt_engine (struct ivpu_device *vdev,u32 engine,u32 preempt_id); +int ivpu_jsm_dyndbg_control (struct ivpu_device *vdev,char *command,size_t size); +int ivpu_jsm_trace_get_capability (struct ivpu_device *vdev,u32 *trace_destination_mask, +u64 *trace_hw_component_mask); +int ivpu_jsm_trace_set_config (struct ivpu_device *vdev,u32 trace_level,u32 trace_destination_mask, +u64 trace_hw_component_mask); + +#endif
drivers/gpu/drm/ivpu/vpu_jsm_api.h new file +616 -0
616 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v3 5/7 drm/ivpu: Implement firmware parsing and booting
In reply to Jacek LawrynowiczRead, parse and boot VPU firmware image.
--- drivers/gpu/drm/ivpu/Makefile | 1 + drivers/gpu/drm/ivpu/ivpu_drv.c | 122 +++++++- drivers/gpu/drm/ivpu/ivpu_drv.h | 10 + drivers/gpu/drm/ivpu/ivpu_fw.c | 422 ++++++++++++++++++++++++++++ drivers/gpu/drm/ivpu/ivpu_fw.h | 38 +++ drivers/gpu/drm/ivpu/ivpu_hw_mtl.c | 11 + drivers/gpu/drm/ivpu/vpu_boot_api.h | 241 ++++++++++++++++ include/uapi/drm/ivpu_drm.h | 21 ++ 8 files changed, 865 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/ivpu/ivpu_fw.c create mode 100644 drivers/gpu/drm/ivpu/ivpu_fw.h create mode 100644 drivers/gpu/drm/ivpu/vpu_boot_api.h
drivers/gpu/drm/ivpu/Makefile +1 -0
@@ -3,6 +3,7 @@ intel_vpu-y := \ ivpu_drv.o \ + ivpu_fw.o \ ivpu_gem.o \ ivpu_hw_mtl.o \ ivpu_ipc.o \
drivers/gpu/drm/ivpu/ivpu_drv.c +121 -1
181 lines not on this page · raw message
drivers/gpu/drm/ivpu/ivpu_drv.h +10 -0
@@ -73,6 +73,7 @@ struct ivpu_wa_table {struct ivpu_hw_info ;struct ivpu_mmu_info ; +struct ivpu_fw_info ;struct ivpu_ipc_info ;struct ivpu_device {
@@ -85,12 +86,15 @@ struct ivpu_device {struct ivpu_wa_table wa;struct ivpu_hw_info *hw;struct ivpu_mmu_info *mmu; +struct ivpu_fw_info *fw;struct ivpu_ipc_info *ipc;struct ivpu_mmu_context gctx;struct xarray context_xa;struct xa_limit context_xa_limit; +atomic64_t unique_id_counter; +struct {int boot;int jsm;
@@ -111,9 +115,15 @@ extern int ivpu_dbg_mask;extern u8 ivpu_pll_min_ratio;extern u8 ivpu_pll_max_ratio; +#define IVPU_TEST_MODE_DISABLED 0 +#define IVPU_TEST_MODE_FW_TEST 1 +#define IVPU_TEST_MODE_NULL_HW 2 +extern int ivpu_test_mode; +void ivpu_file_priv_get (struct ivpu_file_priv *file_priv,struct ivpu_file_priv **link);void ivpu_file_priv_put (struct ivpu_file_priv **link);char *ivpu_platform_to_str (u32 platform); +int ivpu_boot (struct ivpu_device *vdev);int ivpu_shutdown (struct ivpu_device *vdev);static inline bool ivpu_is_mtl (struct ivpu_device *vdev)
drivers/gpu/drm/ivpu/ivpu_fw.c new file +422 -0
422 lines not on this page · raw message
drivers/gpu/drm/ivpu/ivpu_fw.h new file +38 -0
@@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Copyright © 2020-2022 Intel Corporation +*/ + +#ifndef __IVPU_FW_H__ +#define __IVPU_FW_H__ + +struct ivpu_device ; +struct ivpu_bo ; +struct vpu_boot_params ; + +struct ivpu_fw_info { +const struct firmware *file; +struct ivpu_bo *mem; +struct ivpu_bo *mem_shave_nn; +struct ivpu_bo *mem_log_crit; +struct ivpu_bo *mem_log_verb; +u64 runtime_addr; +u32 runtime_size; +u64 image_load_offset; +u32 image_size; +u32 shave_nn_size; +u64 entry_point;/* Cold or warm boot entry point for next boot */ +u64 cold_boot_entry_point; +}; + +int ivpu_fw_init (struct ivpu_device *vdev); +void ivpu_fw_fini (struct ivpu_device *vdev); +int ivpu_fw_load (struct ivpu_device *vdev); +void ivpu_fw_boot_params_setup (struct ivpu_device *vdev,struct vpu_boot_params *bp); + +static inline bool ivpu_fw_is_cold_boot (struct ivpu_device *vdev) +{ +return vdev->fw->entry_point == vdev->fw->cold_boot_entry_point; +} + +#endif /* __IVPU_FW_H__ */
drivers/gpu/drm/ivpu/ivpu_hw_mtl.c +11 -0
@@ -4,6 +4,7 @@*/ #include "ivpu_drv.h" +#include "ivpu_fw.h" #include "ivpu_hw_mtl_reg.h" #include "ivpu_hw_reg_io.h" #include "ivpu_hw.h"
@@ -583,6 +584,16 @@ static void ivpu_boot_soc_cpu_boot(struct ivpu_device *vdev) val =REG_CLR_FLD (MTL_VPU_CPU_SS_MSSCPU_CPR_LEON_RT_VEC ,IRQI_RESUME0 , val);REGV_WR32 (MTL_VPU_CPU_SS_MSSCPU_CPR_LEON_RT_VEC , val); + + val = vdev->fw->entry_point >>9 ; +REGV_WR32 (MTL_VPU_HOST_SS_LOADING_ADDRESS_LO , val); + + val =REG_SET_FLD (MTL_VPU_HOST_SS_LOADING_ADDRESS_LO ,DONE , val); +REGV_WR32 (MTL_VPU_HOST_SS_LOADING_ADDRESS_LO , val); + +ivpu_dbg (PM ,"Booting firmware, mode: %s\n" , + vdev->fw->entry_point == vdev->fw->cold_boot_entry_point ? +"cold boot" :"resume" ); }static int ivpu_boot_d0i3_drive (struct ivpu_device *vdev,bool enable)
drivers/gpu/drm/ivpu/vpu_boot_api.h new file +241 -0
241 lines not on this page · raw message
include/uapi/drm/ivpu_drm.h +21 -0
@@ -51,6 +51,11 @@ extern "C" {#define DRM_IVPU_PARAM_CONTEXT_BASE_ADDRESS 5#define DRM_IVPU_PARAM_CONTEXT_PRIORITY 6#define DRM_IVPU_PARAM_CONTEXT_ID 7 +#define DRM_IVPU_PARAM_FW_API_VERSION 8 +#define DRM_IVPU_PARAM_ENGINE_HEARTBEAT 9 +#define DRM_IVPU_PARAM_UNIQUE_INFERENCE_ID 10 +#define DRM_IVPU_PARAM_TILE_CONFIG 11 +#define DRM_IVPU_PARAM_SKU 12#define DRM_IVPU_PLATFORM_TYPE_SILICON 0
@@ -94,6 +99,22 @@ struct drm_ivpu_param {* %DRM_IVPU_PARAM_CONTEXT_ID: * Current context ID, always greater than 0 (read-only) * +* %DRM_IVPU_PARAM_FW_API_VERSION: +* Firmware API version array (read-only) +* +* %DRM_IVPU_PARAM_ENGINE_HEARTBEAT: +* Heartbeat value from an engine (read-only). +* Engine ID (i.e. DRM_IVPU_ENGINE_COMPUTE) is given via index. +* +* %DRM_IVPU_PARAM_UNIQUE_INFERENCE_ID: +* Device-unique inference ID (read-only) +* +* %DRM_IVPU_PARAM_TILE_CONFIG: +* VPU tile configuration (read-only) +* +* %DRM_IVPU_PARAM_SKU: +* VPU SKU ID (read-only) +* */ __u32 param;
Signature · 1 line
2.34.1
PATCH v3 6/7 drm/ivpu: Add command buffer submission logic
In reply to Jacek LawrynowiczEach of the user contexts has two command queues, one for compute engine and one for the copy engine. Command queues are allocated and registered in the device when the first job (command buffer) is submitted from the user space to the VPU device. The userspace provides a list of GEM buffer object handles to submit to the VPU, the driver resolves buffer handles, pins physical memory if needed, increments ref count for each buffer and stores pointers to buffer objects in
the ivpu_job objects that track jobs submitted to the device. The VPU signals job completion with an asynchronous message that contains the job id passed to firmware when the job was submitted.
Currently, the driver supports simple scheduling logic where jobs submitted from user space are immediately pushed to the VPU device command queues. In the future, it will be extended to use hardware base scheduling and/or drm_sched.
--- drivers/gpu/drm/ivpu/Makefile | 1 + drivers/gpu/drm/ivpu/ivpu_drv.c | 26 +- drivers/gpu/drm/ivpu/ivpu_drv.h | 6 +- drivers/gpu/drm/ivpu/ivpu_gem.c | 13 + drivers/gpu/drm/ivpu/ivpu_job.c | 617 ++++++++++++++++++++++++++++++++ drivers/gpu/drm/ivpu/ivpu_job.h | 73 ++++ include/uapi/drm/ivpu_drm.h | 96 +++++ 7 files changed, 828 insertions(+), 4 deletions(-) create mode 100644 drivers/gpu/drm/ivpu/ivpu_job.c create mode 100644 drivers/gpu/drm/ivpu/ivpu_job.h
drivers/gpu/drm/ivpu/Makefile +1 -0
@@ -7,6 +7,7 @@ intel_vpu-y := \ ivpu_gem.o \ ivpu_hw_mtl.o \ ivpu_ipc.o \ + ivpu_job.o \ ivpu_jsm_msg.o \ ivpu_mmu.o \ ivpu_mmu_context.o
drivers/gpu/drm/ivpu/ivpu_drv.c +23 -3
@@ -19,6 +19,7 @@#include "ivpu_gem.h" #include "ivpu_hw.h" #include "ivpu_ipc.h" +#include "ivpu_job.h" #include "ivpu_jsm_msg.h" #include "ivpu_mmu.h" #include "ivpu_mmu_context.h"
@@ -78,8 +79,11 @@ static void file_priv_release(struct kref *ref)ivpu_dbg (FILE ,"file_priv release: ctx %u\n" , file_priv->ctx.id); -if (file_priv->ctx.id) +if (file_priv->ctx.id) { +ivpu_cmdq_release_all (file_priv); +ivpu_bo_remove_all_bos_from_context (&file_priv->ctx);ivpu_mmu_user_context_fini (file_priv); + }kfree (file_priv); }
@@ -222,6 +226,8 @@ static const struct drm_ioctl_desc ivpu_drm_ioctls[] = {DRM_IOCTL_DEF_DRV (IVPU_BO_CREATE , ivpu_bo_create_ioctl,DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (IVPU_BO_INFO , ivpu_bo_info_ioctl,DRM_RENDER_ALLOW ),DRM_IOCTL_DEF_DRV (IVPU_BO_USERPTR , ivpu_bo_userptr_ioctl,DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (IVPU_SUBMIT , ivpu_submit_ioctl,DRM_RENDER_ALLOW ), +DRM_IOCTL_DEF_DRV (IVPU_BO_WAIT , ivpu_bo_wait_ioctl,DRM_RENDER_ALLOW ), };DEFINE_DRM_GEM_FOPS (ivpu_fops);
@@ -428,6 +434,7 @@ static int ivpu_dev_init(struct ivpu_device *vdev) vdev->context_xa_limit.min =IVPU_GLOBAL_CONTEXT_MMU_SSID +1 ; vdev->context_xa_limit.max =IVPU_CONTEXT_LIMIT ; +xa_init_flags (&vdev->submitted_jobs_xa,XA_FLAGS_ALLOC1 );atomic64_set (&vdev->unique_id_counter,0 ); ret =ivpu_pci_init (vdev);
@@ -478,20 +485,30 @@ static int ivpu_dev_init(struct ivpu_device *vdev) goto err_fw_fini; } + ret =ivpu_job_done_thread_init (vdev); +if (ret) { +ivpu_err (vdev,"Failed to initialize job done thread: %d\n" , ret); + goto err_ipc_fini; + } + ret =ivpu_fw_load (vdev);if (ret) {ivpu_err (vdev,"Failed to load firmware: %d\n" , ret); - goto err_fw_fini; + goto err_job_done_thread_fini; } ret =ivpu_boot (vdev);if (ret) {ivpu_err (vdev,"Failed to boot: %d\n" , ret); - goto err_fw_fini; + goto err_job_done_thread_fini; }return 0 ; +err_job_done_thread_fini: +ivpu_job_done_thread_fini (vdev); +err_ipc_fini: +ivpu_ipc_fini (vdev); err_fw_fini:ivpu_fw_fini (vdev); err_mmu_fini:
@@ -511,6 +528,7 @@ static void ivpu_dev_fini(struct ivpu_device *vdev) {ivpu_shutdown (vdev); +ivpu_job_done_thread_fini (vdev);ivpu_ipc_fini (vdev);ivpu_fw_fini (vdev);ivpu_mmu_fini (vdev);
@@ -520,6 +538,8 @@ static void ivpu_dev_fini(struct ivpu_device *vdev)WARN_ON (!xa_empty (&vdev->context_xa));xa_destroy (&vdev->context_xa); +WARN_ON (!xa_empty (&vdev->submitted_jobs_xa)); +xa_destroy (&vdev->submitted_jobs_xa); }static struct pci_device_id ivpu_pci_ids[] = {
drivers/gpu/drm/ivpu/ivpu_drv.h +5 -1
@@ -93,6 +93,9 @@ struct ivpu_device {struct xarray context_xa;struct xa_limit context_xa_limit; +struct xarray submitted_jobs_xa; +struct task_struct *job_done_thread; +atomic64_t unique_id_counter;struct {
@@ -106,7 +109,8 @@ struct ivpu_device {struct ivpu_file_priv {struct kref ref;struct ivpu_device *vdev; -struct mutex lock; +struct mutex lock;/* Protects cmdq and context init */ +struct ivpu_cmdq *cmdq[IVPU_NUM_ENGINES ];struct ivpu_mmu_context ctx;u32 priority; };
drivers/gpu/drm/ivpu/ivpu_gem.c +13 -0
@@ -776,6 +776,19 @@ int ivpu_bo_info_ioctl(struct drm_device *dev, void *data, struct drm_file *filereturn ret; } +int ivpu_bo_wait_ioctl (struct drm_device *dev,void *data,struct drm_file *file) +{ +struct drm_ivpu_bo_wait *args = data; +unsigned long timeout =drm_timeout_abs_to_jiffies (args->timeout_ns); +long ret; + + ret =drm_gem_dma_resv_wait (file, args->handle, true, timeout); +if (ret == -ETIME ) + ret = -ETIMEDOUT ; + +return ret; +} +static void ivpu_bo_print_info (struct ivpu_bo *bo,struct drm_printer *p) {unsigned long dma_refcount =0 ;
drivers/gpu/drm/ivpu/ivpu_job.c new file +617 -0
617 lines not on this page · raw message
drivers/gpu/drm/ivpu/ivpu_job.h new file +73 -0
73 lines not on this page · raw message
include/uapi/drm/ivpu_drm.h +96 -0
114 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v3 7/7 drm/ivpu: Add PM support
In reply to Jacek Lawrynowicz - Implement cold and warm firmware boot flows
- Add hang recovery support
- Add runtime power management support
--- drivers/gpu/drm/ivpu/Makefile | 3 +- drivers/gpu/drm/ivpu/ivpu_drv.c | 34 ++- drivers/gpu/drm/ivpu/ivpu_drv.h | 2 + drivers/gpu/drm/ivpu/ivpu_fw.c | 4 + drivers/gpu/drm/ivpu/ivpu_hw_mtl.c | 16 +- drivers/gpu/drm/ivpu/ivpu_ipc.c | 11 +- drivers/gpu/drm/ivpu/ivpu_job.c | 14 +- drivers/gpu/drm/ivpu/ivpu_mmu.c | 7 +- drivers/gpu/drm/ivpu/ivpu_pm.c | 352 +++++++++++++++++++++++++++++ drivers/gpu/drm/ivpu/ivpu_pm.h | 38 ++++ 10 files changed, 475 insertions(+), 6 deletions(-) create mode 100644 drivers/gpu/drm/ivpu/ivpu_pm.c create mode 100644 drivers/gpu/drm/ivpu/ivpu_pm.h
drivers/gpu/drm/ivpu/Makefile +2 -1
@@ -10,6 +10,7 @@ intel_vpu-y := \ ivpu_job.o \ ivpu_jsm_msg.o \ ivpu_mmu.o \ - ivpu_mmu_context.o + ivpu_mmu_context.o \ + ivpu_pm.o obj-$(CONFIG_DRM_IVPU) += intel_vpu.o
drivers/gpu/drm/ivpu/ivpu_drv.c +33 -1
@@ -23,6 +23,7 @@#include "ivpu_jsm_msg.h" #include "ivpu_mmu.h" #include "ivpu_mmu_context.h" +#include "ivpu_pm.h" #ifndef DRIVER_VERSION_STR #define DRIVER_VERSION_STR __stringify(DRM_IVPU_DRIVER_MAJOR) "." \
@@ -80,9 +81,11 @@ static void file_priv_release(struct kref *ref)ivpu_dbg (FILE ,"file_priv release: ctx %u\n" , file_priv->ctx.id);if (file_priv->ctx.id) { +ivpu_rpm_get (vdev);ivpu_cmdq_release_all (file_priv);ivpu_bo_remove_all_bos_from_context (&file_priv->ctx);ivpu_mmu_user_context_fini (file_priv); +ivpu_rpm_put (vdev); }kfree (file_priv);
@@ -273,6 +276,7 @@ static int ivpu_wait_for_ready(struct ivpu_device *vdev)int ivpu_boot (struct ivpu_device *vdev) { +struct ivpu_pm_info *pm = vdev->pm;int ret;/* Update boot params located at first 4KB of FW memory */
@@ -290,6 +294,7 @@ int ivpu_boot(struct ivpu_device *vdev)return ret; } +atomic_set (&pm->in_recovery,0 );ivpu_hw_irq_clear (vdev);ivpu_hw_irq_enable (vdev);ivpu_ipc_enable (vdev);
@@ -427,6 +432,10 @@ static int ivpu_dev_init(struct ivpu_device *vdev)if (!vdev->ipc)return -ENOMEM ; + vdev->pm =devm_kzalloc (vdev->drm.dev,sizeof (*vdev->pm),GFP_KERNEL ); +if (!vdev->pm) +return -ENOMEM ; + vdev->hw->ops = &ivpu_hw_mtl_ops; vdev->platform =IVPU_PLATFORM_INVALID ;
@@ -485,10 +494,16 @@ static int ivpu_dev_init(struct ivpu_device *vdev) goto err_fw_fini; } + ret =ivpu_pm_init (vdev); +if (ret) { +ivpu_err (vdev,"Failed to initialize PM: %d\n" , ret); + goto err_ipc_fini; + } + ret =ivpu_job_done_thread_init (vdev);if (ret) {ivpu_err (vdev,"Failed to initialize job done thread: %d\n" , ret); - goto err_ipc_fini; + goto err_pm_fini; } ret =ivpu_fw_load (vdev);
@@ -507,6 +522,8 @@ static int ivpu_dev_init(struct ivpu_device *vdev) err_job_done_thread_fini:ivpu_job_done_thread_fini (vdev); +err_pm_fini: +ivpu_pm_fini (vdev); err_ipc_fini:ivpu_ipc_fini (vdev); err_fw_fini:
@@ -529,6 +546,7 @@ static void ivpu_dev_fini(struct ivpu_device *vdev)ivpu_shutdown (vdev);ivpu_job_done_thread_fini (vdev); +ivpu_pm_fini (vdev);ivpu_ipc_fini (vdev);ivpu_fw_fini (vdev);ivpu_mmu_fini (vdev);
@@ -583,11 +601,25 @@ static void ivpu_remove(struct pci_dev *pdev)ivpu_dev_fini (vdev); } +static const struct dev_pm_ops ivpu_drv_pci_pm = { + SET_SYSTEM_SLEEP_PM_OPS(ivpu_pm_suspend_cb, ivpu_pm_resume_cb) +SET_RUNTIME_PM_OPS (ivpu_pm_runtime_suspend_cb, ivpu_pm_runtime_resume_cb,NULL ) +}; + +static const struct pci_error_handlers ivpu_drv_pci_err = { + .reset_prepare = ivpu_pm_reset_prepare_cb, + .reset_done = ivpu_pm_reset_done_cb, +}; +static struct pci_driver ivpu_pci_driver = { .name =KBUILD_MODNAME , .id_table = ivpu_pci_ids, .probe = ivpu_probe, .remove = ivpu_remove, + .driver = { + .pm = &ivpu_drv_pci_pm, + }, + .err_handler = &ivpu_drv_pci_err, };static __init int ivpu_init (void )
drivers/gpu/drm/ivpu/ivpu_drv.h +2 -0
@@ -75,6 +75,7 @@ struct ivpu_hw_info;struct ivpu_mmu_info ;struct ivpu_fw_info ;struct ivpu_ipc_info ; +struct ivpu_pm_info ;struct ivpu_device {struct drm_device drm;/* Must be first */
@@ -88,6 +89,7 @@ struct ivpu_device {struct ivpu_mmu_info *mmu;struct ivpu_fw_info *fw;struct ivpu_ipc_info *ipc; +struct ivpu_pm_info *pm;struct ivpu_mmu_context gctx;struct xarray context_xa;
drivers/gpu/drm/ivpu/ivpu_fw.c +4 -0
@@ -14,6 +14,7 @@#include "ivpu_gem.h" #include "ivpu_hw.h" #include "ivpu_ipc.h" +#include "ivpu_pm.h" #define FW_MAX_NAMES 3#define FW_GLOBAL_MEM_START (2ull * SZ_1G)
@@ -367,9 +368,12 @@ void ivpu_fw_boot_params_setup(struct ivpu_device *vdev, struct vpu_boot_params/* In case of warm boot we only have to reset the entrypoint addr */ if (!ivpu_fw_is_cold_boot (vdev)) { boot_params->save_restore_ret_address =0 ; + vdev->pm->is_warmboot = true;return ; } + vdev->pm->is_warmboot = false; + boot_params->magic =VPU_BOOT_PARAMS_MAGIC ; boot_params->vpu_id =to_pci_dev (vdev->drm.dev)->bus->number; boot_params->frequency =ivpu_hw_reg_pll_freq_get (vdev);
drivers/gpu/drm/ivpu/ivpu_hw_mtl.c +15 -1
@@ -10,6 +10,7 @@#include "ivpu_hw.h" #include "ivpu_ipc.h" #include "ivpu_mmu.h" +#include "ivpu_pm.h" #define TILE_FUSE_ENABLE_BOTH 0x0#define TILE_FUSE_ENABLE_UPPER 0x1
@@ -916,6 +917,8 @@ static irqreturn_t ivpu_hw_mtl_irq_wdt_nce_handler(struct ivpu_device *vdev) {ivpu_err_ratelimited (vdev,"WDT NCE irq\n" ); +ivpu_pm_schedule_recovery (vdev); +return IRQ_HANDLED ; }
@@ -924,6 +927,7 @@ static irqreturn_t ivpu_hw_mtl_irq_wdt_mss_handler(struct ivpu_device *vdev)ivpu_err_ratelimited (vdev,"WDT MSS irq\n" );ivpu_hw_wdt_disable (vdev); +ivpu_pm_schedule_recovery (vdev);return IRQ_HANDLED ; }
@@ -932,6 +936,8 @@ static irqreturn_t ivpu_hw_mtl_irq_noc_firewall_handler(struct ivpu_device *vdev {ivpu_err_ratelimited (vdev,"NOC Firewall irq\n" ); +ivpu_pm_schedule_recovery (vdev); +return IRQ_HANDLED ; }
@@ -970,6 +976,7 @@ static irqreturn_t ivpu_hw_mtl_irqv_handler(struct ivpu_device *vdev, int irq)/* Handler for IRQs from Buttress core (irqB) */ static irqreturn_t ivpu_hw_mtl_irqb_handler (struct ivpu_device *vdev,int irq) { +bool schedule_recovery = false;u32 status =REGB_RD32 (MTL_BUTTRESS_INTERRUPT_STAT ) &BUTTRESS_IRQ_MASK ;REGB_WR32 (MTL_BUTTRESS_INTERRUPT_STAT , status);
@@ -980,19 +987,25 @@ static irqreturn_t ivpu_hw_mtl_irqb_handler(struct ivpu_device *vdev, int irq)if (REG_TEST_FLD (MTL_BUTTRESS_INTERRUPT_STAT ,ATS_ERR , status)) {ivpu_dbg (IRQ ,"ATS_ERR 0x%016llx" ,REGB_RD64 (MTL_BUTTRESS_ATS_ERR_LOG_0 ));REGB_WR32 (MTL_BUTTRESS_ATS_ERR_CLEAR ,0x1 ); + schedule_recovery = true; }if (REG_TEST_FLD (MTL_BUTTRESS_INTERRUPT_STAT ,UFI_ERR , status)) {ivpu_dbg (IRQ ,"UFI_ERR 0x%08x" ,REGB_RD32 (MTL_BUTTRESS_UFI_ERR_LOG ));REGB_WR32 (MTL_BUTTRESS_UFI_ERR_CLEAR ,0x1 ); + schedule_recovery = true; } +if (schedule_recovery) +ivpu_pm_schedule_recovery (vdev); +return IRQ_HANDLED ; }static irqreturn_t ivpu_hw_mtl_irq_handler (int irq,void *ptr) {struct ivpu_device *vdev = ptr; +struct ivpu_pm_info *pm = vdev->pm;irqreturn_t ret_irqv;irqreturn_t ret_irqb;
@@ -1001,7 +1014,8 @@ static irqreturn_t ivpu_hw_mtl_irq_handler(int irq, void *ptr) ret_irqv =ivpu_hw_mtl_irqv_handler (vdev, irq); ret_irqb =ivpu_hw_mtl_irqb_handler (vdev, irq); -ivpu_hw_mtl_irq_enable (vdev); +if (!atomic_read (&pm->in_recovery)) +ivpu_hw_mtl_irq_enable (vdev);return ret_irqv & ret_irqb; }
drivers/gpu/drm/ivpu/ivpu_ipc.c +10 -1
@@ -14,6 +14,7 @@#include "ivpu_hw_reg_io.h" #include "ivpu_ipc.h" #include "ivpu_jsm_msg.h" +#include "ivpu_pm.h" #define IPC_MAX_RX_MSG 128#define IS_KTHREAD () (get_current()->flags & PF_KTHREAD)
@@ -264,6 +265,10 @@ ivpu_ipc_send_receive_internal(struct ivpu_device *vdev, struct vpu_jsm_msg *reqstruct ivpu_ipc_consumer cons;int ret; + ret =ivpu_rpm_get (vdev); +if (ret <0 ) +return ret; +ivpu_ipc_consumer_add (vdev, &cons, channel); ret =ivpu_ipc_send (vdev, &cons, req);
@@ -286,6 +291,8 @@ ivpu_ipc_send_receive_internal(struct ivpu_device *vdev, struct vpu_jsm_msg *req consumer_del:ivpu_ipc_consumer_del (vdev, &cons); +ivpu_rpm_put (vdev); +return ret; }
@@ -305,8 +312,10 @@ int ivpu_ipc_send_receive(struct ivpu_device *vdev, struct vpu_jsm_msg *req, ret =ivpu_ipc_send_receive_internal (vdev, &hb_req,VPU_JSM_MSG_QUERY_ENGINE_HB_DONE , &hb_resp,VPU_IPC_CHAN_ASYNC_CMD , vdev->timeout.jsm); -if (ret) +if (ret) {ivpu_hw_diagnose_tdr (vdev); +ivpu_pm_schedule_recovery (vdev); + }return ret; }
drivers/gpu/drm/ivpu/ivpu_job.c +13 -1
@@ -17,6 +17,7 @@#include "ivpu_ipc.h" #include "ivpu_job.h" #include "ivpu_jsm_msg.h" +#include "ivpu_pm.h" #define CMD_BUF_IDX 0#define JOB_ID_JOB_MASK GENMASK(7, 0)
@@ -264,6 +265,9 @@ static void job_release(struct kref *ref)ivpu_dbg (KREF ,"Job released: id %u\n" , job->job_id);kfree (job); + +/* Allow the VPU to get suspended, must be called after ivpu_file_priv_put() */ +ivpu_rpm_put (vdev); }static void job_put (struct ivpu_job *job)
@@ -280,11 +284,16 @@ ivpu_create_job(struct ivpu_file_priv *file_priv, u32 engine_idx, u32 bo_count)struct ivpu_device *vdev = file_priv->vdev;struct ivpu_job *job;size_t buf_size; +int ret; + + ret =ivpu_rpm_get (vdev); +if (ret <0 ) +return NULL ; buf_size =sizeof (*job) + bo_count *sizeof (struct ivpu_bo *); job =kzalloc (buf_size,GFP_KERNEL );if (!job) -return NULL ; + goto err_rpm_put;kref_init (&job->ref);
@@ -305,6 +314,8 @@ ivpu_create_job(struct ivpu_file_priv *file_priv, u32 engine_idx, u32 bo_count) err_free_job:kfree (job); +err_rpm_put: +ivpu_rpm_put (vdev);return NULL ; }
@@ -580,6 +591,7 @@ static int ivpu_job_done_thread(void *arg)if (jobs_submitted && !xa_empty (&vdev->submitted_jobs_xa)) {ivpu_err (vdev,"TDR detected, timeout %d ms" , timeout);ivpu_hw_diagnose_tdr (vdev); +ivpu_pm_schedule_recovery (vdev); } } }
drivers/gpu/drm/ivpu/ivpu_mmu.c +6 -1
@@ -11,6 +11,7 @@#include "ivpu_hw_reg_io.h" #include "ivpu_mmu.h" #include "ivpu_mmu_context.h" +#include "ivpu_pm.h" #define IVPU_MMU_IDR0_REF 0x080f3e0f#define IVPU_MMU_IDR0_REF_SIMICS 0x080f3e1f
@@ -827,6 +828,8 @@ irqreturn_t ivpu_mmu_irq_evtq_handler(struct ivpu_device *vdev) }while (evtq->prod != evtq->cons); +ivpu_pm_schedule_recovery (vdev); +return IRQ_HANDLED ; }
@@ -843,8 +846,10 @@ irqreturn_t ivpu_mmu_irq_gerr_handler(struct ivpu_device *vdev)if (!(active &IVPU_MMU_GERROR_ERR_MASK ))return IRQ_NONE ; -if (REG_TEST_FLD (MTL_VPU_HOST_MMU_GERROR ,SFM , active)) +if (REG_TEST_FLD (MTL_VPU_HOST_MMU_GERROR ,SFM , active)) {ivpu_err_ratelimited (vdev,"MMU has entered service failure mode\n" ); +ivpu_pm_schedule_recovery (vdev); + }if (REG_TEST_FLD (MTL_VPU_HOST_MMU_GERROR ,MSI_ABT , active))ivpu_warn_ratelimited (vdev,"MMU MSI ABT write aborted\n" );
drivers/gpu/drm/ivpu/ivpu_pm.c new file +352 -0
352 lines not on this page · raw message
drivers/gpu/drm/ivpu/ivpu_pm.h new file +38 -0
@@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Copyright © 2020-2022 Intel Corporation +*/ + +#ifndef __IVPU_PM_H__ +#define __IVPU_PM_H__ + +#include <linux/types.h> + +struct ivpu_device ; + +struct ivpu_pm_info { +struct ivpu_device *vdev; +struct mutex lock;/* Protects state transitions */ +struct work_struct recovery_work; +atomic_t in_recovery; +bool is_warmboot; +u32 suspend_reschedule_counter; +}; + +int ivpu_pm_init (struct ivpu_device *vdev); +void ivpu_pm_fini (struct ivpu_device *vdev); + +int ivpu_pm_suspend_cb (struct device *dev); +int ivpu_pm_resume_cb (struct device *dev); +int ivpu_pm_runtime_suspend_cb (struct device *dev); +int ivpu_pm_runtime_resume_cb (struct device *dev); + +void ivpu_pm_reset_prepare_cb (struct pci_dev *pdev); +void ivpu_pm_reset_done_cb (struct pci_dev *pdev); + +int ivpu_rpm_get (struct ivpu_device *vdev); +void ivpu_rpm_put (struct ivpu_device *vdev); + +void ivpu_pm_schedule_recovery (struct ivpu_device *vdev); + +#endif /* __IVPU_PM_H__ */
Signature · 1 line
2.34.1