gpu-sunxi: initial package

This commit is contained in:
Lukas Rusak 2017-09-11 12:53:28 -07:00 committed by Jernej Skrabec
parent 55b5492d0f
commit a54e52af18
5 changed files with 772 additions and 0 deletions

View File

@ -0,0 +1,28 @@
# SPDX-License-Identifier: GPL-2.0
# Copyright (C) 2016-present Team LibreELEC (https://libreelec.tv)
PKG_NAME="gpu-sunxi"
PKG_VERSION="r9p0-01rel0"
PKG_SHA256="7a67127341d17640c1fff5dad80258fb2a37c8a2121b81525fe2327e4532ce2b"
PKG_ARCH="arm aarch64"
PKG_LICENSE="GPL"
PKG_SITE="https://developer.arm.com/products/software/mali-drivers/utgard-kernel"
PKG_URL="https://developer.arm.com/-/media/Files/downloads/mali-drivers/kernel/mali-utgard-gpu/DX910-SW-99002-$PKG_VERSION.tgz"
PKG_DEPENDS_TARGET="toolchain linux"
PKG_NEED_UNPACK="$LINUX_DEPENDS"
PKG_LONGDESC="gpu-sunxi: Linux drivers for Mali GPUs found in Allwinner SoCs"
PKG_TOOLCHAIN="manual"
PKG_IS_KERNEL_PKG="yes"
make_target() {
kernel_make -C $(kernel_path) M=$PKG_BUILD/driver/src/devicedrv/mali/ \
MALI_PLATFORM_FILES=platform/sunxi/sunxi.c \
EXTRA_CFLAGS="-DMALI_FAKE_PLATFORM_DEVICE=1 -DCONFIG_MALI_DMA_BUF_MAP_ON_ATTACH" \
CONFIG_MALI400=m
}
makeinstall_target() {
kernel_make -C $(kernel_path) M=$PKG_BUILD/driver/src/devicedrv/mali/ \
INSTALL_MOD_PATH=$INSTALL/$(get_kernel_overlay_dir) INSTALL_MOD_STRIP=1 DEPMOD=: \
modules_install
}

View File

@ -0,0 +1,426 @@
From 2b56fc78a4acbffbdebf5b690035d1ba70ef592c Mon Sep 17 00:00:00 2001
From: Maxime Ripard <maxime.ripard@free-electrons.com>
Date: Tue, 29 Nov 2016 10:18:40 +0100
Subject: [PATCH 4/4] mali: Add sunxi platform
Add a platform for the Mali GPU integrated in the Allwinner SoCs.
Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
---
src/devicedrv/mali/platform/sunxi/sunxi.c | 404 +++++++++++++++++++++++
1 file changed, 404 insertions(+)
create mode 100644 src/devicedrv/mali/platform/sunxi/sunxi.c
--- /dev/null
+++ b/driver/src/devicedrv/mali/platform/sunxi/sunxi.c
@@ -0,0 +1,410 @@
+
+#include <linux/clk.h>
+#include <linux/clkdev.h>
+#include <linux/cma.h>
+#include <linux/delay.h>
+#include <linux/dma-contiguous.h>
+#include <linux/dma-mapping.h>
+#include <linux/io.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/of_address.h>
+#include <linux/of_device.h>
+#include <linux/of_irq.h>
+#include <linux/of_reserved_mem.h>
+#include <linux/pm_runtime.h>
+#include <linux/reset.h>
+#include <linux/slab.h>
+
+#include <linux/clk/clk-conf.h>
+
+#include <linux/mali/mali_utgard.h>
+
+#include "mali_kernel_linux.h"
+
+struct mali {
+ struct clk *bus_clk;
+ struct clk *core_clk;
+
+ struct reset_control *reset;
+
+ struct platform_device *dev;
+};
+
+struct mali *mali;
+
+struct resource *mali_create_mp1_resources(unsigned long address,
+ int irq_gp, int irq_gpmmu,
+ int irq_pp0, int irq_ppmmu0,
+ int *len)
+{
+ struct resource target[] = {
+ MALI_GPU_RESOURCES_MALI400_MP1_PMU(address,
+ irq_gp, irq_gpmmu,
+ irq_pp0, irq_ppmmu0)
+ };
+ struct resource *res;
+
+ res = kzalloc(sizeof(target), GFP_KERNEL);
+ if (!res)
+ return NULL;
+
+ memcpy(res, target, sizeof(target));
+
+ *len = ARRAY_SIZE(target);
+
+ return res;
+}
+
+struct resource *mali_create_mp2_resources(unsigned long address,
+ int irq_gp, int irq_gpmmu,
+ int irq_pp0, int irq_ppmmu0,
+ int irq_pp1, int irq_ppmmu1,
+ int *len)
+{
+ struct resource target[] = {
+ MALI_GPU_RESOURCES_MALI400_MP2_PMU(address,
+ irq_gp, irq_gpmmu,
+ irq_pp0, irq_ppmmu0,
+ irq_pp1, irq_ppmmu1)
+ };
+ struct resource *res;
+
+ res = kzalloc(sizeof(target), GFP_KERNEL);
+ if (!res)
+ return NULL;
+
+ memcpy(res, target, sizeof(target));
+
+ *len = ARRAY_SIZE(target);
+
+ return res;
+}
+
+struct resource *mali_create_450mp4_resources(unsigned long address,
+ int irq_gp, int irq_gpmmu,
+ int irq_pp0, int irq_ppmmu0,
+ int irq_pp1, int irq_ppmmu1,
+ int irq_pp2, int irq_ppmmu2,
+ int irq_pp3, int irq_ppmmu3,
+ int irq_pp, int *len)
+{
+ struct resource target[] = {
+ MALI_GPU_RESOURCES_MALI450_MP4(address,
+ irq_gp, irq_gpmmu,
+ irq_pp0, irq_ppmmu0,
+ irq_pp1, irq_ppmmu1,
+ irq_pp2, irq_ppmmu2,
+ irq_pp3, irq_ppmmu3,
+ irq_pp)
+ };
+ struct resource *res;
+
+ res = kzalloc(sizeof(target), GFP_KERNEL);
+ if (!res)
+ return NULL;
+
+ memcpy(res, target, sizeof(target));
+
+ *len = ARRAY_SIZE(target);
+
+ return res;
+}
+
+static const struct of_device_id mali_dt_ids[] = {
+ { .compatible = "allwinner,sun4i-a10-mali" },
+ { .compatible = "allwinner,sun7i-a20-mali" },
+ { .compatible = "allwinner,sun8i-h3-mali" },
+ { .compatible = "allwinner,sun50i-a64-mali" },
+ { .compatible = "allwinner,sun50i-h5-mali" },
+ { .compatible = "arm,mali-400" },
+ { .compatible = "arm,mali-450" },
+ { /* sentinel */ },
+};
+MODULE_DEVICE_TABLE(of, mali_dt_ids);
+
+static struct mali_gpu_device_data mali_gpu_data = {
+ .max_job_runtime = 60000,
+};
+int mali_platform_device_register(void)
+{
+ int irq_gp, irq_gpmmu;
+ int irq_pp0, irq_ppmmu0;
+ int irq_pp1 = -EINVAL, irq_ppmmu1 = -EINVAL;
+ int irq_pp2 = -EINVAL, irq_ppmmu2 = -EINVAL;
+ int irq_pp3 = -EINVAL, irq_ppmmu3 = -EINVAL;
+ int irq_pp = -EINVAL;
+ int irq_pmu;
+ struct resource *mali_res = NULL, res;
+ struct device_node *np;
+ struct device *dev;
+ int ret, len;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,0,0)
+ mali_gpu_data.shared_mem_size = totalram_pages() * PAGE_SIZE;
+#else
+ mali_gpu_data.shared_mem_size = totalram_pages * PAGE_SIZE;
+#endif
+
+ np = of_find_matching_node(NULL, mali_dt_ids);
+ if (!np) {
+ pr_err("Couldn't find the mali node\n");
+ return -ENODEV;
+ }
+
+ mali = kzalloc(sizeof(*mali), GFP_KERNEL);
+ if (!mali) {
+ ret = -ENOMEM;
+ goto err_put_node;
+ }
+
+ ret = of_clk_set_defaults(np, false);
+ if (ret) {
+ pr_err("Couldn't set clock defaults\n");
+ goto err_free_mem;
+ }
+
+ mali->bus_clk = of_clk_get_by_name(np, "bus");
+ if (IS_ERR(mali->bus_clk)) {
+ pr_err("Couldn't retrieve our bus clock\n");
+ ret = PTR_ERR(mali->bus_clk);
+ goto err_free_mem;
+ }
+ clk_prepare_enable(mali->bus_clk);
+
+ mali->core_clk = of_clk_get_by_name(np, "core");
+ if (IS_ERR(mali->core_clk)) {
+ pr_err("Couldn't retrieve our module clock\n");
+ ret = PTR_ERR(mali->core_clk);
+ goto err_put_bus;
+ }
+ clk_prepare_enable(mali->core_clk);
+
+ if (of_device_is_compatible(np, "allwinner,sun4i-a10-mali") ||
+ of_device_is_compatible(np, "allwinner,sun7i-a20-mali") ||
+ of_device_is_compatible(np, "allwinner,sun8i-h3-mali") ||
+ of_device_is_compatible(np, "allwinner,sun50i-a64-mali") ||
+ of_device_is_compatible(np, "allwinner,sun50i-h5-mali")) {
+ mali->reset = of_reset_control_get(np, NULL);
+ if (IS_ERR(mali->reset)) {
+ pr_err("Couldn't retrieve our reset handle\n");
+ ret = PTR_ERR(mali->reset);
+ goto err_put_mod;
+ }
+ reset_control_deassert(mali->reset);
+ }
+
+ ret = of_address_to_resource(np, 0, &res);
+ if (ret) {
+ pr_err("Couldn't retrieve our base address\n");
+ goto err_put_reset;
+ }
+
+ irq_gp = of_irq_get_byname(np, "gp");
+ if (irq_gp < 0) {
+ pr_err("Couldn't retrieve our GP interrupt\n");
+ ret = irq_gp;
+ goto err_put_reset;
+ }
+
+ irq_gpmmu = of_irq_get_byname(np, "gpmmu");
+ if (irq_gpmmu < 0) {
+ pr_err("Couldn't retrieve our GP MMU interrupt\n");
+ ret = irq_gpmmu;
+ goto err_put_reset;
+ }
+
+ irq_pp0 = of_irq_get_byname(np, "pp0");
+ if (irq_pp0 < 0) {
+ pr_err("Couldn't retrieve our PP0 interrupt %d\n", irq_pp0);
+ ret = irq_pp0;
+ goto err_put_reset;
+ }
+
+ irq_ppmmu0 = of_irq_get_byname(np, "ppmmu0");
+ if (irq_ppmmu0 < 0) {
+ pr_err("Couldn't retrieve our PP0 MMU interrupt\n");
+ ret = irq_ppmmu0;
+ goto err_put_reset;
+ }
+
+ irq_pp1 = of_irq_get_byname(np, "pp1");
+ irq_ppmmu1 = of_irq_get_byname(np, "ppmmu1");
+ if ((irq_pp1 < 0) ^ (irq_ppmmu1 < 0 )) {
+ pr_err("Couldn't retrieve our PP1 interrupts\n");
+ ret = (irq_pp1 < 0) ? irq_pp1 : irq_ppmmu1;
+ goto err_put_reset;
+ }
+
+ if (of_device_is_compatible(np, "allwinner,sun50i-h5-mali")) {
+ irq_pp2 = of_irq_get_byname(np, "pp2");
+ if (irq_pp2 < 0) {
+ pr_err("Couldn't retrieve our PP2 interrupt\n");
+ ret = irq_pp2;
+ goto err_put_reset;
+ }
+
+ irq_ppmmu2 = of_irq_get_byname(np, "ppmmu2");
+ if (irq_ppmmu2 < 0) {
+ pr_err("Couldn't retrieve our PP2 interrupts\n");
+ ret = irq_ppmmu2;
+ goto err_put_reset;
+ }
+
+ irq_pp3 = of_irq_get_byname(np, "pp3");
+ if (irq_pp3 < 0) {
+ pr_err("Couldn't retrieve our PP3 interrupt\n");
+ ret = irq_pp3;
+ goto err_put_reset;
+ }
+
+ irq_ppmmu3 = of_irq_get_byname(np, "ppmmu3");
+ if (irq_ppmmu3 < 0) {
+ pr_err("Couldn't retrieve our PP3 interrupts\n");
+ ret = irq_ppmmu3;
+ goto err_put_reset;
+ }
+
+ irq_pp = of_irq_get_byname(np, "pp");
+ if (irq_pp < 0) {
+ pr_err("Couldn't retrieve our PP broadcast interrupt\n");
+ ret = irq_pp;
+ goto err_put_reset;
+ }
+ } else {
+ irq_pmu = of_irq_get_byname(np, "pmu");
+ if (irq_pmu < 0) {
+ pr_err("Couldn't retrieve our PMU interrupt\n");
+ ret = irq_pmu;
+ goto err_put_reset;
+ }
+ }
+
+ mali->dev = platform_device_alloc("mali-utgard", 0);
+ if (!mali->dev) {
+ pr_err("Couldn't create platform device\n");
+ ret = -EINVAL;
+ goto err_put_reset;
+ }
+ dev = &mali->dev->dev;
+ dev_set_name(dev, "mali-utgard");
+ dev->of_node = np;
+ dev->coherent_dma_mask = DMA_BIT_MASK(32);
+ dev->dma_mask = &dev->coherent_dma_mask;
+ dev->bus = &platform_bus_type;
+
+ ret = of_reserved_mem_device_init(&mali->dev->dev);
+ if (ret && ret != -ENODEV) {
+ pr_err("Couldn't claim our reserved memory region\n");
+ goto err_free_mem_region;
+ }
+
+ if (of_device_is_compatible(np, "allwinner,sun50i-h5-mali"))
+ mali_res = mali_create_450mp4_resources(res.start,
+ irq_gp, irq_gpmmu,
+ irq_pp0, irq_ppmmu0,
+ irq_pp1, irq_ppmmu1,
+ irq_pp2, irq_ppmmu2,
+ irq_pp3, irq_ppmmu3,
+ irq_pp, &len);
+ else if ((irq_pp1 >= 0) && (irq_ppmmu1 >= 0))
+ mali_res = mali_create_mp2_resources(res.start,
+ irq_gp, irq_gpmmu,
+ irq_pp0, irq_ppmmu0,
+ irq_pp1, irq_ppmmu1,
+ &len);
+ else
+ mali_res = mali_create_mp1_resources(res.start,
+ irq_gp, irq_gpmmu,
+ irq_pp0, irq_ppmmu0,
+ &len);
+
+ if (!mali_res) {
+ pr_err("Couldn't create target resources\n");
+ ret = -EINVAL;
+ goto err_free_mem_region;
+ }
+
+ clk_register_clkdev(mali->core_clk, "clk_mali", NULL);
+
+ ret = platform_device_add_resources(mali->dev, mali_res, len);
+ kfree(mali_res);
+ if (ret) {
+ pr_err("Couldn't add our resources\n");
+ goto err_free_mem_region;
+ }
+
+ ret = platform_device_add_data(mali->dev, &mali_gpu_data,
+ sizeof(mali_gpu_data));
+ if (ret) {
+ pr_err("Couldn't add our platform data\n");
+ goto err_free_mem_region;
+ }
+
+ ret = platform_device_add(mali->dev);
+ if (ret) {
+ pr_err("Couldn't add our device\n");
+ goto err_free_mem_region;
+ }
+
+#ifdef CONFIG_PM_RUNTIME
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
+ pm_runtime_set_autosuspend_delay(&mali->dev->dev, 1000);
+ pm_runtime_use_autosuspend(&mali->dev->dev);
+#endif
+ pm_runtime_enable(&mali->dev->dev);
+#endif
+
+ pr_info("Allwinner sunXi mali glue initialized\n");
+
+ return 0;
+
+err_free_mem_region:
+ of_reserved_mem_device_release(dev);
+ platform_device_put(mali->dev);
+err_put_reset:
+ if (!IS_ERR_OR_NULL(mali->reset)) {
+ reset_control_assert(mali->reset);
+ reset_control_put(mali->reset);
+ }
+err_put_mod:
+ clk_disable_unprepare(mali->core_clk);
+ clk_put(mali->core_clk);
+err_put_bus:
+ clk_disable_unprepare(mali->bus_clk);
+ clk_put(mali->bus_clk);
+err_free_mem:
+ kfree(mali);
+err_put_node:
+ of_node_put(np);
+ return ret;
+}
+
+int mali_platform_device_unregister(void)
+{
+ struct device *dev = &mali->dev->dev;
+
+#ifdef CONFIG_PM_RUNTIME
+ pm_runtime_disable(dev);
+#endif
+
+ of_reserved_mem_device_release(dev);
+
+ platform_device_del(mali->dev);
+ of_node_put(dev->of_node);
+ platform_device_put(mali->dev);
+
+ if (!IS_ERR_OR_NULL(mali->reset)) {
+ reset_control_assert(mali->reset);
+ reset_control_put(mali->reset);
+ }
+
+ clk_disable_unprepare(mali->core_clk);
+ clk_put(mali->core_clk);
+
+ clk_disable_unprepare(mali->bus_clk);
+ clk_put(mali->bus_clk);
+
+ kfree(mali);
+
+ return 0;
+}

View File

@ -0,0 +1,155 @@
From 246fdac477cf109c354011c1ae0a7a8d928cb504 Mon Sep 17 00:00:00 2001
From: Jonas Karlman <jonas@kwiboo.se>
Date: Mon, 12 Mar 2018 23:02:55 +0100
Subject: [PATCH] v4.16 build fix
---
.../driver/src/devicedrv/mali/common/mali_control_timer.c | 2 +-
src/devicedrv/mali/common/mali_group.c | 8 ++++---
src/devicedrv/mali/common/mali_osk_types.h | 8 ++++++-
.../devicedrv/mali/linux/mali_memory_os_alloc.c | 6 +++++
.../driver/src/devicedrv/mali/linux/mali_memory_secure.c | 4 ++++
src/devicedrv/mali/linux/mali_osk_timers.c | 20 +++++++++++-----
11 files changed, 84 insertions(+), 14 deletions(-)
diff --git a/driver/src/devicedrv/mali/common/mali_control_timer.c b/driver/src/devicedrv/mali/common/mali_control_timer.c
index 1296ffe..bfe975f 100644
--- a/driver/src/devicedrv/mali/common/mali_control_timer.c
+++ b/driver/src/devicedrv/mali/common/mali_control_timer.c
@@ -28,7 +28,7 @@ void mali_control_timer_add(u32 timeout)
_mali_osk_timer_add(mali_control_timer, _mali_osk_time_mstoticks(timeout));
}
-static void mali_control_timer_callback(void *arg)
+static void mali_control_timer_callback(struct timer_list *t)
{
if (mali_utilization_enabled()) {
struct mali_gpu_utilization_data *util_data = NULL;
diff --git a/driver/src/devicedrv/mali/common/mali_group.c b/driver/src/devicedrv/mali/common/mali_group.c
index e9005e1..4a43753 100644
--- a/driver/src/devicedrv/mali/common/mali_group.c
+++ b/driver/src/devicedrv/mali/common/mali_group.c
@@ -44,7 +44,7 @@ int mali_max_job_runtime = MALI_MAX_JOB_RUNTIME_DEFAULT;
static void mali_group_bottom_half_mmu(void *data);
static void mali_group_bottom_half_gp(void *data);
static void mali_group_bottom_half_pp(void *data);
-static void mali_group_timeout(void *data);
+static void mali_group_timeout(struct timer_list *t);
static void mali_group_reset_pp(struct mali_group *group);
static void mali_group_reset_mmu(struct mali_group *group);
@@ -1761,9 +1761,11 @@ static void mali_group_bottom_half_pp(void *data)
0xFFFFFFFF, 0);
}
-static void mali_group_timeout(void *data)
+static void mali_group_timeout(struct timer_list *t)
{
- struct mali_group *group = (struct mali_group *)data;
+ _mali_osk_timer_t *tim = container_of(t, _mali_osk_timer_t, timer);
+ struct mali_group *group = container_of(&tim, struct mali_group, timeout_timer);
+
MALI_DEBUG_ASSERT_POINTER(group);
MALI_DEBUG_PRINT(2, ("Group: timeout handler for %s at %u\n",
diff --git a/driver/src/devicedrv/mali/common/mali_osk_types.h b/driver/src/devicedrv/mali/common/mali_osk_types.h
index 03161cf..c9d0fec 100644
--- a/driver/src/devicedrv/mali/common/mali_osk_types.h
+++ b/driver/src/devicedrv/mali/common/mali_osk_types.h
@@ -50,6 +50,7 @@ typedef unsigned long long u64;
#include <linux/types.h>
#endif
+#include <linux/timer.h>
/** @brief Mali Boolean type which uses MALI_TRUE and MALI_FALSE
*/
typedef unsigned long mali_bool;
@@ -395,7 +396,12 @@ typedef struct _mali_osk_notification_t_struct {
* by any callers of _mali_osk_timer_del(). Otherwise, a deadlock may occur.
*
* @param arg Function-specific data */
-typedef void (*_mali_osk_timer_callback_t)(void *arg);
+typedef void (*_mali_osk_timer_callback_t)(struct timer_list *t);
+
+
+struct _mali_osk_timer_t_struct {
+ struct timer_list timer;
+};
/** @brief Private type for Timer Callback Objects */
typedef struct _mali_osk_timer_t_struct _mali_osk_timer_t;
diff --git a/driver/src/devicedrv/mali/linux/mali_memory_os_alloc.c b/driver/src/devicedrv/mali/linux/mali_memory_os_alloc.c
index 5fe1270..92c245a 100644
--- a/driver/src/devicedrv/mali/linux/mali_memory_os_alloc.c
+++ b/driver/src/devicedrv/mali/linux/mali_memory_os_alloc.c
@@ -202,7 +202,9 @@ int mali_mem_os_alloc_pages(mali_mem_os_mem *os_mem, u32 size)
/* Allocate new pages, if needed. */
for (i = 0; i < remaining; i++) {
dma_addr_t dma_addr;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 15, 0)
+ gfp_t flags = __GFP_ZERO | __GFP_RETRY_MAYFAIL | __GFP_NOWARN;
+#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 13, 0)
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0)
gfp_t flags = __GFP_ZERO | __GFP_RETRY_MAYFAIL | __GFP_NOWARN | __GFP_COLD;
#else
gfp_t flags = __GFP_ZERO | __GFP_REPEAT | __GFP_NOWARN | __GFP_COLD;
diff --git a/driver/src/devicedrv/mali/linux/mali_memory_secure.c b/driver/src/devicedrv/mali/linux/mali_memory_secure.c
index 2836b1b..4f55fa5 100644
--- a/driver/src/devicedrv/mali/linux/mali_memory_secure.c
+++ b/driver/src/devicedrv/mali/linux/mali_memory_secure.c
@@ -13,7 +13,11 @@
#include "mali_memory_secure.h"
#include "mali_osk.h"
#include <linux/mutex.h>
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 16, 0)
+#include <linux/dma-direct.h>
+#else
#include <linux/dma-mapping.h>
+#endif
#include <linux/dma-buf.h>
_mali_osk_errcode_t mali_mem_secure_attach_dma_buf(mali_mem_secure *secure_mem, u32 size, int mem_fd)
diff --git a/driver/src/devicedrv/mali/linux/mali_osk_timers.c b/driver/src/devicedrv/mali/linux/mali_osk_timers.c
index e5d7238..701051a 100644
--- a/driver/src/devicedrv/mali/linux/mali_osk_timers.c
+++ b/driver/src/devicedrv/mali/linux/mali_osk_timers.c
@@ -18,16 +18,25 @@
#include "mali_osk.h"
#include "mali_kernel_common.h"
-struct _mali_osk_timer_t_struct {
- struct timer_list timer;
-};
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0)
+
+#define TIMER_DATA_TYPE unsigned long
+#define TIMER_FUNC_TYPE void (*)(TIMER_DATA_TYPE)
+
+static inline void timer_setup(struct timer_list *timer,
+ void (*callback)(struct timer_list *),
+ unsigned int flags)
+{
+ __setup_timer(timer, (TIMER_FUNC_TYPE)callback,
+ (TIMER_DATA_TYPE)timer, flags);
+}
+#endif
typedef void (*timer_timeout_function_t)(unsigned long);
_mali_osk_timer_t *_mali_osk_timer_init(void)
{
_mali_osk_timer_t *t = (_mali_osk_timer_t *)kmalloc(sizeof(_mali_osk_timer_t), GFP_KERNEL);
- if (NULL != t) init_timer(&t->timer);
return t;
}
@@ -65,8 +74,7 @@ mali_bool _mali_osk_timer_pending(_mali_osk_timer_t *tim)
void _mali_osk_timer_setcallback(_mali_osk_timer_t *tim, _mali_osk_timer_callback_t callback, void *data)
{
MALI_DEBUG_ASSERT_POINTER(tim);
- tim->timer.data = (unsigned long)data;
- tim->timer.function = (timer_timeout_function_t)callback;
+ timer_setup(&tim->timer, callback, 0);
}
void _mali_osk_timer_term(_mali_osk_timer_t *tim)

View File

@ -0,0 +1,128 @@
diff -Nur a/driver/src/devicedrv/mali/linux/mali_memory_block_alloc.c b/driver/src/devicedrv/mali/linux/mali_memory_block_alloc.c
--- a/driver/src/devicedrv/mali/linux/mali_memory_block_alloc.c 2018-09-13 08:52:20.000000000 +0200
+++ b/driver/src/devicedrv/mali/linux/mali_memory_block_alloc.c 2018-12-08 12:22:51.978513336 +0100
@@ -309,9 +309,9 @@
list_for_each_entry(m_page, &block_mem->pfns, list) {
MALI_DEBUG_ASSERT(m_page->type == MALI_PAGE_NODE_BLOCK);
- ret = vm_insert_pfn(vma, addr, _mali_page_node_get_pfn(m_page));
+ ret = vmf_insert_pfn(vma, addr, _mali_page_node_get_pfn(m_page));
- if (unlikely(0 != ret)) {
+ if (unlikely(ret & VM_FAULT_ERROR)) {
return -EFAULT;
}
addr += _MALI_OSK_MALI_PAGE_SIZE;
diff -Nur a/driver/src/devicedrv/mali/linux/mali_memory_cow.c b/driver/src/devicedrv/mali/linux/mali_memory_cow.c
--- a/driver/src/devicedrv/mali/linux/mali_memory_cow.c 2018-09-13 08:52:20.000000000 +0200
+++ b/driver/src/devicedrv/mali/linux/mali_memory_cow.c 2018-12-08 12:27:17.681815893 +0100
@@ -532,10 +532,10 @@
* flush which makes it way slower than remap_pfn_range or vm_insert_pfn.
ret = vm_insert_page(vma, addr, page);
*/
- ret = vm_insert_pfn(vma, addr, _mali_page_node_get_pfn(m_page));
+ ret = vmf_insert_pfn(vma, addr, _mali_page_node_get_pfn(m_page));
- if (unlikely(0 != ret)) {
- return ret;
+ if (unlikely(ret & VM_FAULT_ERROR)) {
+ return -EFAULT;
}
addr += _MALI_OSK_MALI_PAGE_SIZE;
}
@@ -569,9 +569,9 @@
list_for_each_entry(m_page, &cow->pages, list) {
if ((count >= offset) && (count < offset + num)) {
- ret = vm_insert_pfn(vma, vaddr, _mali_page_node_get_pfn(m_page));
+ ret = vmf_insert_pfn(vma, vaddr, _mali_page_node_get_pfn(m_page));
- if (unlikely(0 != ret)) {
+ if (unlikely(ret & VM_FAULT_ERROR)) {
if (count == offset) {
return _MALI_OSK_ERR_FAULT;
} else {
diff -Nur a/driver/src/devicedrv/mali/linux/mali_memory_os_alloc.c b/driver/src/devicedrv/mali/linux/mali_memory_os_alloc.c
--- a/driver/src/devicedrv/mali/linux/mali_memory_os_alloc.c 2018-12-08 12:15:38.000000000 +0100
+++ b/driver/src/devicedrv/mali/linux/mali_memory_os_alloc.c 2018-12-08 12:30:37.730811640 +0100
@@ -376,9 +376,9 @@
ret = vm_insert_page(vma, addr, page);
*/
page = m_page->page;
- ret = vm_insert_pfn(vma, addr, page_to_pfn(page));
+ ret = vmf_insert_pfn(vma, addr, page_to_pfn(page));
- if (unlikely(0 != ret)) {
+ if (unlikely(ret & VM_FAULT_ERROR)) {
return -EFAULT;
}
addr += _MALI_OSK_MALI_PAGE_SIZE;
@@ -414,16 +414,11 @@
vm_end -= _MALI_OSK_MALI_PAGE_SIZE;
if (mapping_page_num > 0) {
- ret = vm_insert_pfn(vma, vm_end, page_to_pfn(m_page->page));
+ ret = vmf_insert_pfn(vma, vm_end, page_to_pfn(m_page->page));
- if (unlikely(0 != ret)) {
- /*will return -EBUSY If the page has already been mapped into table, but it's OK*/
- if (-EBUSY == ret) {
- break;
- } else {
- MALI_DEBUG_PRINT(1, ("OS Mem: mali_mem_os_resize_cpu_map_locked failed, ret = %d, offset is %d,page_count is %d\n",
- ret, offset + mapping_page_num, os_mem->count));
- }
+ if (unlikely(ret & VM_FAULT_ERROR)) {
+ MALI_DEBUG_PRINT(1, ("OS Mem: mali_mem_os_resize_cpu_map_locked failed, ret = %d, offset is %d,page_count is %d\n",
+ ret, offset + mapping_page_num, os_mem->count));
return _MALI_OSK_ERR_FAULT;
}
} else {
@@ -437,16 +432,11 @@
list_for_each_entry(m_page, &os_mem->pages, list) {
if (count >= offset) {
- ret = vm_insert_pfn(vma, vstart, page_to_pfn(m_page->page));
+ ret = vmf_insert_pfn(vma, vstart, page_to_pfn(m_page->page));
- if (unlikely(0 != ret)) {
- /*will return -EBUSY If the page has already been mapped into table, but it's OK*/
- if (-EBUSY == ret) {
- break;
- } else {
- MALI_DEBUG_PRINT(1, ("OS Mem: mali_mem_os_resize_cpu_map_locked failed, ret = %d, count is %d, offset is %d,page_count is %d\n",
- ret, count, offset, os_mem->count));
- }
+ if (unlikely(ret & VM_FAULT_ERROR)) {
+ MALI_DEBUG_PRINT(1, ("OS Mem: mali_mem_os_resize_cpu_map_locked failed, ret = %d, count is %d, offset is %d,page_count is %d\n",
+ ret, count, offset, os_mem->count));
return _MALI_OSK_ERR_FAULT;
}
}
diff -Nur a/driver/src/devicedrv/mali/linux/mali_memory_secure.c b/driver/src/devicedrv/mali/linux/mali_memory_secure.c
--- a/driver/src/devicedrv/mali/linux/mali_memory_secure.c 2018-12-08 12:15:38.000000000 +0100
+++ b/driver/src/devicedrv/mali/linux/mali_memory_secure.c 2018-12-08 12:31:05.461174554 +0100
@@ -132,9 +132,9 @@
MALI_DEBUG_ASSERT(0 == size % _MALI_OSK_MALI_PAGE_SIZE);
for (j = 0; j < size / _MALI_OSK_MALI_PAGE_SIZE; j++) {
- ret = vm_insert_pfn(vma, addr, PFN_DOWN(phys));
+ ret = vmf_insert_pfn(vma, addr, PFN_DOWN(phys));
- if (unlikely(0 != ret)) {
+ if (unlikely(ret & VM_FAULT_ERROR)) {
return -EFAULT;
}
addr += _MALI_OSK_MALI_PAGE_SIZE;
diff -Nur a/driver/src/devicedrv/mali/linux/mali_osk_time.c b/driver/src/devicedrv/mali/linux/mali_osk_time.c
--- a/driver/src/devicedrv/mali/linux/mali_osk_time.c 2018-09-13 08:52:20.000000000 +0200
+++ b/driver/src/devicedrv/mali/linux/mali_osk_time.c 2018-12-08 12:32:12.632086846 +0100
@@ -53,7 +53,5 @@
u64 _mali_osk_boot_time_get_ns(void)
{
- struct timespec tsval;
- get_monotonic_boottime(&tsval);
- return (u64)timespec_to_ns(&tsval);
+ return (u64)ktime_to_ns(ktime_get_boottime());
}

View File

@ -0,0 +1,35 @@
diff -Nur a/driver/src/devicedrv/mali/linux/mali_ukk_mem.c b/driver/src/devicedrv/mali/linux/mali_ukk_mem.c
--- a/driver/src/devicedrv/mali/linux/mali_ukk_mem.c 2018-09-13 08:52:20.000000000 +0200
+++ b/driver/src/devicedrv/mali/linux/mali_ukk_mem.c 2019-02-09 20:10:06.867561465 +0100
@@ -207,10 +207,17 @@
kargs.ctx = (uintptr_t)session_data;
/* Check if we can access the buffers */
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,0,0)
+ if (!access_ok(kargs.dest, kargs.size)
+ || !access_ok(kargs.src, kargs.size)) {
+ return -EINVAL;
+ }
+#else
if (!access_ok(VERIFY_WRITE, kargs.dest, kargs.size)
|| !access_ok(VERIFY_READ, kargs.src, kargs.size)) {
return -EINVAL;
}
+#endif
/* Check if size wraps */
if ((kargs.size + kargs.dest) <= kargs.dest
@@ -266,8 +273,13 @@
goto err_exit;
user_buffer = (void __user *)(uintptr_t)kargs.buffer;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,0,0)
+ if (!access_ok(user_buffer, kargs.size))
+ goto err_exit;
+#else
if (!access_ok(VERIFY_WRITE, user_buffer, kargs.size))
goto err_exit;
+#endif
/* allocate temporary buffer (kernel side) to store mmu page table info */
if (kargs.size <= 0)