summaryrefslogtreecommitdiff
path: root/mali_kbase
diff options
context:
space:
mode:
authorJack Diver <diverj@google.com>2023-01-11 15:33:12 +0000
committerJack Diver <diverj@google.com>2023-03-23 12:11:40 +0000
commitc1bfc7dd8cc50224da90f2532be9102eeb3739a9 (patch)
tree57e0034fb3edb0bb84fd6ee48b4e636d29291844 /mali_kbase
parentf2d35cdfa9820257f8b6655c79d30f2d0802a275 (diff)
downloadgpu-c1bfc7dd8cc50224da90f2532be9102eeb3739a9.tar.gz
mali_kbase: Implement buffer liveness ioctl
Add SLC platform integration, and plumb custom ioctl through. Bug: 264990406 Test: Boot to home Test: Manual ioctl call Change-Id: I0009cec83f54cfed8e12477c5ebd7aa01cf50cc8 Signed-off-by: Jack Diver <diverj@google.com>
Diffstat (limited to 'mali_kbase')
-rw-r--r--mali_kbase/Makefile5
-rw-r--r--mali_kbase/mali_kbase_core_linux.c8
-rw-r--r--mali_kbase/platform/pixel/Kbuild3
-rw-r--r--mali_kbase/platform/pixel/pixel_gpu.c8
-rw-r--r--mali_kbase/platform/pixel/pixel_gpu_slc.c179
-rw-r--r--mali_kbase/platform/pixel/pixel_gpu_slc.h37
6 files changed, 235 insertions, 5 deletions
diff --git a/mali_kbase/Makefile b/mali_kbase/Makefile
index 4715c1a..a71d57d 100644
--- a/mali_kbase/Makefile
+++ b/mali_kbase/Makefile
@@ -46,6 +46,7 @@ CONFIG_MALI_PIXEL_GPU_QOS ?= y
CONFIG_MALI_PIXEL_GPU_BTS ?= y
CONFIG_MALI_PIXEL_GPU_SECURE_RENDERING ?= y
CONFIG_MALI_PIXEL_GPU_THERMAL ?= y
+CONFIG_MALI_PIXEL_GPU_SLC ?= y
#
# Default configuration values
@@ -221,8 +222,8 @@ CONFIGS += \
CONFIG_MALI_PIXEL_GPU_BTS \
CONFIG_MALI_PIXEL_GPU_THERMAL \
CONFIG_MALI_PIXEL_GPU_SECURE_RENDERING \
- CONFIG_MALI_HOST_CONTROLS_SC_RAILS
-
+ CONFIG_MALI_HOST_CONTROLS_SC_RAILS \
+ CONFIG_MALI_PIXEL_GPU_SLC
#
# MAKE_ARGS to pass the custom CONFIGs on out-of-tree build
diff --git a/mali_kbase/mali_kbase_core_linux.c b/mali_kbase/mali_kbase_core_linux.c
index b6b7d43..34ef134 100644
--- a/mali_kbase/mali_kbase_core_linux.c
+++ b/mali_kbase/mali_kbase_core_linux.c
@@ -80,6 +80,9 @@
#include "mali_kbase_pbha_debugfs.h"
#endif
+/* Pixel includes */
+#include "platform/pixel/pixel_gpu_slc.h"
+
#include <linux/module.h>
#include <linux/init.h>
#include <linux/poll.h>
@@ -825,9 +828,8 @@ static int kbase_api_apc_request(struct kbase_file *kfile,
static int kbase_api_buffer_liveness_update(struct kbase_context *kctx,
struct kbase_ioctl_buffer_liveness_update *update)
{
- CSTD_UNUSED(kctx);
- CSTD_UNUSED(update);
- return 0;
+ /* Defer handling to platform */
+ return gpu_pixel_handle_buffer_liveness_update_ioctl(kctx, update);
}
#if !MALI_USE_CSF
diff --git a/mali_kbase/platform/pixel/Kbuild b/mali_kbase/platform/pixel/Kbuild
index 1564463..bccf2d1 100644
--- a/mali_kbase/platform/pixel/Kbuild
+++ b/mali_kbase/platform/pixel/Kbuild
@@ -40,5 +40,8 @@ mali_kbase-y += \
platform/$(MALI_PLATFORM_DIR)/pixel_gpu_sscd.o
endif
+mali_kbase-$(CONFIG_MALI_PIXEL_GPU_SLC) += \
+ platform/$(MALI_PLATFORM_DIR)/pixel_gpu_slc.o
+
mali_kbase-$(CONFIG_MALI_CSF_SUPPORT) += \
platform/$(MALI_PLATFORM_DIR)/pixel_gpu_debug.o
diff --git a/mali_kbase/platform/pixel/pixel_gpu.c b/mali_kbase/platform/pixel/pixel_gpu.c
index c6800e2..c85311d 100644
--- a/mali_kbase/platform/pixel/pixel_gpu.c
+++ b/mali_kbase/platform/pixel/pixel_gpu.c
@@ -29,6 +29,7 @@
#include "mali_kbase_config_platform.h"
#include "pixel_gpu_control.h"
#include "pixel_gpu_sscd.h"
+#include "pixel_gpu_slc.h"
#define CREATE_TRACE_POINTS
#include "pixel_gpu_trace.h"
@@ -197,6 +198,12 @@ static int gpu_pixel_kctx_init(struct kbase_context *kctx)
goto done;
}
+ err = gpu_slc_kctx_init(kctx);
+ if (err) {
+ dev_err(kbdev->dev, "pixel: SLC kctx init failed\n");
+ goto done;
+ }
+
done:
return err;
}
@@ -208,6 +215,7 @@ done:
*/
static void gpu_pixel_kctx_term(struct kbase_context *kctx)
{
+ gpu_slc_kctx_term(kctx);
gpu_dvfs_kctx_term(kctx);
kfree(kctx->platform_data);
diff --git a/mali_kbase/platform/pixel/pixel_gpu_slc.c b/mali_kbase/platform/pixel/pixel_gpu_slc.c
new file mode 100644
index 0000000..240fa8e
--- /dev/null
+++ b/mali_kbase/platform/pixel/pixel_gpu_slc.c
@@ -0,0 +1,179 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright 2022-2023 Google LLC.
+ *
+ * Author: Jack Diver <diverj@google.com>
+ */
+
+/* Mali core includes */
+#include <mali_kbase.h>
+
+/* UAPI includes */
+#include <uapi/gpu/arm/midgard/platform/pixel/pixel_gpu_common_slc.h>
+
+/* Pixel integration includes */
+#include "mali_kbase_config_platform.h"
+#include "pixel_gpu_slc.h"
+
+
+/**
+ * struct gpu_slc_liveness_update_info - Buffer info, and live ranges
+ *
+ * @buffer_va: Array of buffer base virtual addresses
+ * @buffer_sizes: Array of buffer sizes
+ * @live_ranges: Array of &struct kbase_pixel_gpu_slc_liveness_mark denoting live ranges for
+ * each buffer
+ * @live_ranges_count: Number of elements in the live ranges buffer
+ */
+struct gpu_slc_liveness_update_info {
+ u64* buffer_va;
+ u64* buffer_sizes;
+ struct kbase_pixel_gpu_slc_liveness_mark* live_ranges;
+ u64 live_ranges_count;
+};
+
+/**
+ * gpu_slc_liveness_update - Respond to a liveness update by trying to put the new buffers into free
+ * SLC space, and resizing the partition to meet demand.
+ *
+ * @kctx: The &struct kbase_context corresponding to a user space context which sent the liveness
+ * update
+ * @info: See struct gpu_slc_liveness_update_info
+ */
+static void gpu_slc_liveness_update(struct kbase_context* kctx,
+ struct gpu_slc_liveness_update_info* info)
+{
+ struct kbase_device* kbdev = kctx->kbdev;
+ dev_dbg(kbdev->dev, "pixel: buffer liveness update received");
+ (void)info;
+}
+
+/**
+ * gpu_pixel_handle_buffer_liveness_update_ioctl() - See gpu_slc_liveness_update
+ *
+ * @kctx: The &struct kbase_context corresponding to a user space context which sent the liveness
+ * update
+ * @update: See struct kbase_ioctl_buffer_liveness_update
+ *
+ * Context: Process context. Takes and releases the GPU power domain lock. Expects the caller to
+ * hold the DVFS lock.
+ */
+int gpu_pixel_handle_buffer_liveness_update_ioctl(struct kbase_context* kctx,
+ struct kbase_ioctl_buffer_liveness_update* update)
+{
+ int err = 0;
+ struct gpu_slc_liveness_update_info info;
+ u64* buff;
+
+ /* Compute the sizes of the user space arrays that we need to copy */
+ u64 const buffer_info_size = sizeof(u64) * update->buffer_count;
+ u64 const live_ranges_size =
+ sizeof(struct kbase_pixel_gpu_slc_liveness_mark) * update->live_ranges_count;
+
+ /* Nothing to do */
+ if (!buffer_info_size || !live_ranges_size)
+ goto done;
+
+ /* Guard against nullptr */
+ if (!update->live_ranges_address || !update->buffer_va_address || !update->buffer_sizes_address)
+ goto done;
+
+ /* Allocate the memory we require to copy from user space */
+ buff = kmalloc(buffer_info_size * 2 + live_ranges_size, GFP_KERNEL);
+ if (buff == NULL) {
+ dev_err(kctx->kbdev->dev, "pixel: failed to allocate buffer for liveness update");
+ err = -ENOMEM;
+ goto done;
+ }
+
+ /* Set up the info struct by pointing into the allocation. All 8 byte aligned */
+ info = (struct gpu_slc_liveness_update_info){
+ .buffer_va = buff,
+ .buffer_sizes = buff + update->buffer_count,
+ .live_ranges = (struct kbase_pixel_gpu_slc_liveness_mark*)(buff + update->buffer_count * 2),
+ .live_ranges_count = update->live_ranges_count,
+ };
+
+ /* Copy the data from user space */
+ err =
+ copy_from_user(info.live_ranges, u64_to_user_ptr(update->live_ranges_address), live_ranges_size);
+ if (err) {
+ dev_err(kctx->kbdev->dev, "pixel: failed to copy live ranges");
+ err = -EFAULT;
+ goto done;
+ }
+
+ err = copy_from_user(
+ info.buffer_sizes, u64_to_user_ptr(update->buffer_sizes_address), buffer_info_size);
+ if (err) {
+ dev_err(kctx->kbdev->dev, "pixel: failed to copy buffer sizes");
+ err = -EFAULT;
+ goto done;
+ }
+
+ err = copy_from_user(info.buffer_va, u64_to_user_ptr(update->buffer_va_address), buffer_info_size);
+ if (err) {
+ dev_err(kctx->kbdev->dev, "pixel: failed to copy buffer addresses");
+ err = -EFAULT;
+ goto done;
+ }
+
+ /* Execute an slc update */
+ gpu_slc_liveness_update(kctx, &info);
+
+done:
+ kfree(buff);
+
+ return err;
+}
+
+/**
+ * gpu_slc_kctx_init() - Called when a kernel context is created
+ *
+ * @kctx: The &struct kbase_context that is being initialized
+ *
+ * This function is called when the GPU driver is initializing a new kernel context. This event is
+ * used to set up data structures that will be used to track this context's usage of the SLC.
+ *
+ * Return: Returns 0 on success, or an error code on failure.
+ */
+int gpu_slc_kctx_init(struct kbase_context *kctx)
+{
+ (void)kctx;
+ return 0;
+}
+
+/**
+ * gpu_slc_kctx_term() - Called when a kernel context is terminated
+ *
+ * @kctx: The &struct kbase_context that is being terminated
+ *
+ */
+void gpu_slc_kctx_term(struct kbase_context *kctx)
+{
+ (void)kctx;
+}
+
+
+/**
+ * gpu_slc_init - Initialize the SLC partition for the GPU
+ *
+ * @kbdev: The &struct kbase_device for the GPU.
+ *
+ * Return: On success, returns 0. On failure an error code is returned.
+ */
+int gpu_slc_init(struct kbase_device *kbdev)
+{
+ (void)kbdev;
+ return 0;
+}
+
+/**
+ * gpu_slc_term() - Terminates the Pixel GPU SLC partition.
+ *
+ * @kbdev: The &struct kbase_device for the GPU.
+ */
+void gpu_slc_term(struct kbase_device *kbdev)
+{
+ (void)kbdev;
+}
diff --git a/mali_kbase/platform/pixel/pixel_gpu_slc.h b/mali_kbase/platform/pixel/pixel_gpu_slc.h
new file mode 100644
index 0000000..29b4eb3
--- /dev/null
+++ b/mali_kbase/platform/pixel/pixel_gpu_slc.h
@@ -0,0 +1,37 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright 2022-2023 Google LLC.
+ *
+ * Author: Jack Diver <diverj@google.com>
+ */
+#ifndef _PIXEL_GPU_SLC_H_
+#define _PIXEL_GPU_SLC_H_
+
+#ifdef CONFIG_MALI_PIXEL_GPU_SLC
+int gpu_pixel_handle_buffer_liveness_update_ioctl(struct kbase_context* kctx,
+ struct kbase_ioctl_buffer_liveness_update* update);
+
+int gpu_slc_init(struct kbase_device *kbdev);
+
+void gpu_slc_term(struct kbase_device *kbdev);
+
+int gpu_slc_kctx_init(struct kbase_context *kctx);
+
+void gpu_slc_kctx_term(struct kbase_context *kctx);
+#else
+static int __maybe_unused gpu_pixel_handle_buffer_liveness_update_ioctl(struct kbase_context* kctx,
+ struct kbase_ioctl_buffer_liveness_update* update)
+{
+ return (void)kctx, (void)update, 0;
+}
+
+int __maybe_unused gpu_slc_init(struct kbase_device *kbdev) { return (void)kbdev, 0; }
+
+void __maybe_unused gpu_slc_term(struct kbase_device *kbdev) { (void)kbdev; }
+
+static int __maybe_unused gpu_slc_kctx_init(struct kbase_context *kctx) { return (void)kctx, 0; }
+
+static void __maybe_unused gpu_slc_kctx_term(struct kbase_context* kctx) { (void)kctx; }
+#endif /* CONFIG_MALI_PIXEL_GPU_SLC */
+
+#endif /* _PIXEL_GPU_SLC_H_ */