From 25b0332fe62be1cbb384bb1094aa30848d4a5c0c Mon Sep 17 00:00:00 2001 From: chenzhen Date: Thu, 10 Mar 2016 17:31:51 +0800 Subject: [PATCH] MALI: utgard: upgrade DDK to r6p1-01rel0 Change-Id: I88e8aba740ec223c1107def64eb004390b7fd940 Signed-off-by: chenzhen --- drivers/gpu/arm/mali400/mali/Kbuild | 27 ++ drivers/gpu/arm/mali400/mali/Kconfig | 13 +- drivers/gpu/arm/mali400/mali/Makefile | 12 +- .../arm/mali400/mali/common/mali_broadcast.c | 2 +- .../arm/mali400/mali/common/mali_broadcast.h | 2 +- .../mali400/mali/common/mali_control_timer.c | 2 +- .../mali400/mali/common/mali_control_timer.h | 2 +- .../gpu/arm/mali400/mali/common/mali_dlbu.c | 2 +- .../gpu/arm/mali400/mali/common/mali_dlbu.h | 2 +- .../mali400/mali/common/mali_dvfs_policy.c | 2 +- .../mali400/mali/common/mali_dvfs_policy.h | 2 +- .../arm/mali400/mali/common/mali_executor.c | 177 +++++++--- drivers/gpu/arm/mali400/mali/common/mali_gp.c | 6 + drivers/gpu/arm/mali400/mali/common/mali_gp.h | 2 +- .../gpu/arm/mali400/mali/common/mali_gp_job.c | 17 +- .../gpu/arm/mali400/mali/common/mali_gp_job.h | 2 +- .../gpu/arm/mali400/mali/common/mali_group.c | 44 +-- .../arm/mali400/mali/common/mali_hw_core.c | 2 +- .../arm/mali400/mali/common/mali_hw_core.h | 2 +- .../mali400/mali/common/mali_kernel_common.h | 2 +- .../mali400/mali/common/mali_kernel_core.c | 5 + .../mali400/mali/common/mali_kernel_core.h | 2 +- .../mali/common/mali_kernel_utilization.c | 2 +- .../mali/common/mali_kernel_utilization.h | 2 +- .../mali400/mali/common/mali_kernel_vsync.c | 2 +- .../arm/mali400/mali/common/mali_l2_cache.c | 2 +- .../arm/mali400/mali/common/mali_l2_cache.h | 2 +- .../mali400/mali/common/mali_mem_validation.c | 2 +- .../mali400/mali/common/mali_mem_validation.h | 2 +- .../gpu/arm/mali400/mali/common/mali_mmu.c | 2 +- .../gpu/arm/mali400/mali/common/mali_mmu.h | 1 + .../mali/common/mali_mmu_page_directory.c | 2 +- .../mali/common/mali_mmu_page_directory.h | 2 +- .../gpu/arm/mali400/mali/common/mali_osk.h | 16 +- .../arm/mali400/mali/common/mali_osk_bitops.h | 2 +- .../arm/mali400/mali/common/mali_osk_list.h | 2 +- .../arm/mali400/mali/common/mali_osk_mali.h | 56 +++- .../mali400/mali/common/mali_osk_profiling.h | 2 +- .../arm/mali400/mali/common/mali_osk_types.h | 2 +- drivers/gpu/arm/mali400/mali/common/mali_pm.c | 2 +- drivers/gpu/arm/mali400/mali/common/mali_pm.h | 2 +- .../arm/mali400/mali/common/mali_pm_domain.c | 2 +- .../arm/mali400/mali/common/mali_pm_domain.h | 2 +- .../arm/mali400/mali/common/mali_pm_metrics.c | 255 ++++++++++++++ .../arm/mali400/mali/common/mali_pm_metrics.h | 74 +++++ .../gpu/arm/mali400/mali/common/mali_pmu.c | 2 +- .../gpu/arm/mali400/mali/common/mali_pmu.h | 2 +- drivers/gpu/arm/mali400/mali/common/mali_pp.c | 9 + drivers/gpu/arm/mali400/mali/common/mali_pp.h | 1 + .../gpu/arm/mali400/mali/common/mali_pp_job.c | 2 +- .../gpu/arm/mali400/mali/common/mali_pp_job.h | 7 + .../arm/mali400/mali/common/mali_scheduler.c | 79 ++++- .../arm/mali400/mali/common/mali_scheduler.h | 3 +- .../mali/common/mali_scheduler_types.h | 2 +- .../arm/mali400/mali/common/mali_session.c | 22 +- .../arm/mali400/mali/common/mali_soft_job.c | 2 +- .../arm/mali400/mali/common/mali_soft_job.h | 2 +- .../mali/common/mali_spinlock_reentrant.c | 2 +- .../mali/common/mali_spinlock_reentrant.h | 2 +- .../arm/mali400/mali/common/mali_timeline.c | 10 +- .../arm/mali400/mali/common/mali_timeline.h | 2 +- .../mali/common/mali_timeline_fence_wait.c | 2 +- .../mali/common/mali_timeline_fence_wait.h | 2 +- .../mali/common/mali_timeline_sync_fence.c | 2 +- .../mali/common/mali_timeline_sync_fence.h | 2 +- .../gpu/arm/mali400/mali/common/mali_ukk.h | 2 +- .../mali/common/mali_user_settings_db.c | 2 +- .../mali/common/mali_user_settings_db.h | 2 +- .../mali/include/linux/mali/mali_utgard.h | 21 +- .../include/linux/mali/mali_utgard_ioctl.h | 2 +- .../linux/mali/mali_utgard_profiling_events.h | 3 +- .../mali/mali_utgard_profiling_gator_api.h | 2 +- .../include/linux/mali/mali_utgard_uk_types.h | 11 +- .../linux/license/gpl/mali_kernel_license.h | 2 +- .../gpu/arm/mali400/mali/linux/mali_devfreq.c | 310 ++++++++++++++++++ .../gpu/arm/mali400/mali/linux/mali_devfreq.h | 17 + .../mali/linux/mali_device_pause_resume.c | 2 +- .../mali400/mali/linux/mali_kernel_linux.c | 195 ++++++++++- .../mali400/mali/linux/mali_kernel_sysfs.c | 2 +- .../mali400/mali/linux/mali_kernel_sysfs.h | 2 +- .../arm/mali400/mali/linux/mali_linux_trace.h | 2 +- .../gpu/arm/mali400/mali/linux/mali_memory.c | 12 + .../gpu/arm/mali400/mali/linux/mali_memory.h | 2 +- .../mali/linux/mali_memory_block_alloc.c | 2 +- .../mali/linux/mali_memory_block_alloc.h | 2 +- .../arm/mali400/mali/linux/mali_memory_cow.c | 4 +- .../arm/mali400/mali/linux/mali_memory_cow.h | 2 +- .../mali400/mali/linux/mali_memory_dma_buf.c | 2 +- .../mali400/mali/linux/mali_memory_dma_buf.h | 2 +- .../mali400/mali/linux/mali_memory_external.c | 2 +- .../mali400/mali/linux/mali_memory_external.h | 2 +- .../mali400/mali/linux/mali_memory_manager.c | 65 ++-- .../mali400/mali/linux/mali_memory_manager.h | 2 +- .../mali400/mali/linux/mali_memory_os_alloc.h | 2 +- .../mali400/mali/linux/mali_memory_secure.c | 169 ++++++++++ .../mali400/mali/linux/mali_memory_secure.h | 30 ++ .../mali/linux/mali_memory_swap_alloc.c | 2 +- .../mali/linux/mali_memory_swap_alloc.h | 2 +- .../mali400/mali/linux/mali_memory_types.h | 11 + .../arm/mali400/mali/linux/mali_memory_ump.c | 2 +- .../arm/mali400/mali/linux/mali_memory_ump.h | 2 +- .../arm/mali400/mali/linux/mali_memory_util.c | 13 +- .../arm/mali400/mali/linux/mali_memory_util.h | 2 +- .../mali400/mali/linux/mali_memory_virtual.c | 2 +- .../mali400/mali/linux/mali_memory_virtual.h | 2 +- .../arm/mali400/mali/linux/mali_osk_atomics.c | 2 +- .../arm/mali400/mali/linux/mali_osk_bitmap.c | 2 +- .../gpu/arm/mali400/mali/linux/mali_osk_irq.c | 2 +- .../arm/mali400/mali/linux/mali_osk_locks.c | 2 +- .../arm/mali400/mali/linux/mali_osk_locks.h | 2 +- .../mali/linux/mali_osk_low_level_mem.c | 2 +- .../arm/mali400/mali/linux/mali_osk_mali.c | 101 ++++++ .../arm/mali400/mali/linux/mali_osk_math.c | 2 +- .../arm/mali400/mali/linux/mali_osk_memory.c | 2 +- .../arm/mali400/mali/linux/mali_osk_misc.c | 13 +- .../mali/linux/mali_osk_notification.c | 2 +- .../mali400/mali/linux/mali_osk_profiling.c | 6 +- .../mali400/mali/linux/mali_osk_specific.h | 2 +- .../arm/mali400/mali/linux/mali_osk_time.c | 2 +- .../arm/mali400/mali/linux/mali_osk_timers.c | 2 +- .../mali400/mali/linux/mali_osk_wait_queue.c | 2 +- .../gpu/arm/mali400/mali/linux/mali_osk_wq.c | 2 +- .../mali/linux/mali_pmu_power_up_down.c | 2 +- .../mali/linux/mali_profiling_events.h | 2 +- .../mali/linux/mali_profiling_gator_api.h | 2 +- .../mali/linux/mali_profiling_internal.c | 2 +- .../mali/linux/mali_profiling_internal.h | 2 +- .../gpu/arm/mali400/mali/linux/mali_sync.c | 2 +- .../gpu/arm/mali400/mali/linux/mali_sync.h | 2 +- .../arm/mali400/mali/linux/mali_uk_types.h | 2 +- .../arm/mali400/mali/linux/mali_ukk_core.c | 2 +- .../gpu/arm/mali400/mali/linux/mali_ukk_gp.c | 2 +- .../gpu/arm/mali400/mali/linux/mali_ukk_mem.c | 2 +- .../gpu/arm/mali400/mali/linux/mali_ukk_pp.c | 2 +- .../mali400/mali/linux/mali_ukk_profiling.c | 2 +- .../mali400/mali/linux/mali_ukk_soft_job.c | 2 +- .../mali400/mali/linux/mali_ukk_timeline.c | 2 +- .../arm/mali400/mali/linux/mali_ukk_vsync.c | 2 +- .../mali400/mali/linux/mali_ukk_wrappers.h | 2 +- .../gpu/arm/mali400/mali/platform/arm/arm.c | 183 ++++++++++- .../mali/platform/arm/arm_core_scaling.c | 2 +- .../mali/platform/arm/arm_core_scaling.h | 2 +- .../arm/mali400/mali/platform/arm/juno_opp.c | 127 +++++++ .../gpu/arm/mali400/mali/regs/mali_200_regs.h | 2 +- .../gpu/arm/mali400/mali/regs/mali_gp_regs.h | 2 +- .../mali/timestamp-arm11-cc/mali_timestamp.c | 2 +- .../mali/timestamp-arm11-cc/mali_timestamp.h | 2 +- .../mali/timestamp-default/mali_timestamp.c | 2 +- .../mali/timestamp-default/mali_timestamp.h | 2 +- drivers/gpu/arm/mali400/ump/Kbuild | 17 +- drivers/gpu/arm/mali400/ump/Makefile | 2 +- drivers/gpu/arm/mali400/ump/Makefile.common | 2 +- .../gpu/arm/mali400/ump/arch-default/config.h | 2 +- .../arm/mali400/ump/arch-pb-virtex5/config.h | 2 +- .../arm/mali400/ump/common/ump_kernel_api.c | 2 +- .../mali400/ump/common/ump_kernel_common.c | 2 +- .../mali400/ump/common/ump_kernel_common.h | 4 +- .../common/ump_kernel_descriptor_mapping.c | 2 +- .../common/ump_kernel_descriptor_mapping.h | 2 +- .../ump/common/ump_kernel_memory_backend.h | 2 +- .../mali400/ump/common/ump_kernel_ref_drv.c | 2 +- .../arm/mali400/ump/common/ump_kernel_types.h | 9 +- drivers/gpu/arm/mali400/ump/common/ump_osk.h | 2 +- .../gpu/arm/mali400/ump/common/ump_uk_types.h | 11 +- drivers/gpu/arm/mali400/ump/common/ump_ukk.h | 2 +- .../linux/license/gpl/ump_kernel_license.h | 2 +- drivers/gpu/arm/mali400/ump/linux/ump_ioctl.h | 3 +- .../arm/mali400/ump/linux/ump_kernel_linux.c | 30 +- .../arm/mali400/ump/linux/ump_kernel_linux.h | 2 +- .../ump_kernel_memory_backend_dedicated.c | 2 +- .../ump_kernel_memory_backend_dedicated.h | 2 +- .../ump/linux/ump_kernel_memory_backend_os.c | 2 +- .../ump/linux/ump_kernel_memory_backend_os.h | 2 +- .../ump/linux/ump_kernel_random_mapping.c | 17 +- .../ump/linux/ump_kernel_random_mapping.h | 2 +- .../mali400/ump/linux/ump_memory_backend.c | 2 +- .../arm/mali400/ump/linux/ump_osk_atomics.c | 2 +- .../mali400/ump/linux/ump_osk_low_level_mem.c | 2 +- .../gpu/arm/mali400/ump/linux/ump_osk_misc.c | 2 +- .../mali400/ump/linux/ump_ukk_ref_wrappers.c | 163 ++++++++- .../mali400/ump/linux/ump_ukk_ref_wrappers.h | 6 +- .../arm/mali400/ump/linux/ump_ukk_wrappers.c | 8 +- .../arm/mali400/ump/linux/ump_ukk_wrappers.h | 2 +- drivers/gpu/arm/mali400/umplock/Makefile | 2 +- .../gpu/arm/mali400/umplock/umplock_driver.c | 2 +- .../gpu/arm/mali400/umplock/umplock_ioctl.h | 2 +- 186 files changed, 2327 insertions(+), 342 deletions(-) create mode 100644 drivers/gpu/arm/mali400/mali/common/mali_pm_metrics.c create mode 100644 drivers/gpu/arm/mali400/mali/common/mali_pm_metrics.h create mode 100644 drivers/gpu/arm/mali400/mali/linux/mali_devfreq.c create mode 100644 drivers/gpu/arm/mali400/mali/linux/mali_devfreq.h create mode 100644 drivers/gpu/arm/mali400/mali/linux/mali_memory_secure.c create mode 100644 drivers/gpu/arm/mali400/mali/linux/mali_memory_secure.h create mode 100644 drivers/gpu/arm/mali400/mali/platform/arm/juno_opp.c diff --git a/drivers/gpu/arm/mali400/mali/Kbuild b/drivers/gpu/arm/mali400/mali/Kbuild index ae42b53c8ad9..3b74bd15cda1 100755 --- a/drivers/gpu/arm/mali400/mali/Kbuild +++ b/drivers/gpu/arm/mali400/mali/Kbuild @@ -44,6 +44,15 @@ ifneq ($(MALI_PLATFORM),) platform/$(MALI_PLATFORM)/mali_dvfs.o endif +ifeq ($(MALI_PLATFORM_FILES),) +ifeq ($(CONFIG_ARCH_EXYNOS4),y) +EXTRA_DEFINES += -DMALI_FAKE_PLATFORM_DEVICE=1 +export MALI_PLATFORM=exynos4 +export MALI_PLATFORM_FILES_BUILDIN = $(notdir $(wildcard $(src)/platform/$(MALI_PLATFORM)/*.c)) +export MALI_PLATFORM_FILES_ADD_PREFIX = $(addprefix platform/$(MALI_PLATFORM)/,$(MALI_PLATFORM_FILES_BUILDIN)) +endif +endif + mali-y += \ linux/mali_osk_atomics.o \ linux/mali_osk_irq.o \ @@ -80,6 +89,10 @@ mali-y += \ linux/mali_ukk_soft_job.o \ linux/mali_ukk_timeline.o +mali-$(CONFIG_MALI_DEVFREQ) += \ + linux/mali_devfreq.o \ + common/mali_pm_metrics.o + # Source files which always are included in a build mali-y += \ common/mali_kernel_core.o \ @@ -118,10 +131,18 @@ mali-y += \ linux/mali_pmu_power_up_down.o \ __malidrv_build_info.o +ifneq ($(wildcard $(src)/linux/mali_slp_global_lock.c),) + mali-y += linux/mali_slp_global_lock.o +endif + ifneq ($(MALI_PLATFORM_FILES),) mali-y += $(MALI_PLATFORM_FILES:.c=.o) endif +ifneq ($(MALI_PLATFORM_FILES_ADD_PREFIX),) + mali-y += $(MALI_PLATFORM_FILES_ADD_PREFIX:.c=.o) +endif + mali-$(CONFIG_MALI400_PROFILING) += linux/mali_ukk_profiling.o mali-$(CONFIG_MALI400_PROFILING) += linux/mali_osk_profiling.o @@ -129,6 +150,7 @@ mali-$(CONFIG_MALI400_INTERNAL_PROFILING) += linux/mali_profiling_internal.o tim ccflags-$(CONFIG_MALI400_INTERNAL_PROFILING) += -I$(src)/timestamp-$(TIMESTAMP) mali-$(CONFIG_DMA_SHARED_BUFFER) += linux/mali_memory_dma_buf.o +mali-$(CONFIG_DMA_SHARED_BUFFER) += linux/mali_memory_secure.o mali-$(CONFIG_SYNC) += linux/mali_sync.o ccflags-$(CONFIG_SYNC) += -Idrivers/staging/android @@ -154,7 +176,12 @@ ifeq ($(MALI_UPPER_HALF_SCHEDULING),1) ccflags-y += -DMALI_UPPER_HALF_SCHEDULING endif +#build-in include path is different +ifeq ($(MALI_PLATFORM_FILES),) +ccflags-$(CONFIG_MALI400_UMP) += -I$(src)/../ump/include/ +else ccflags-$(CONFIG_MALI400_UMP) += -I$(src)/../../ump/include/ump +endif ccflags-$(CONFIG_MALI400_DEBUG) += -DDEBUG # Use our defines when compiling diff --git a/drivers/gpu/arm/mali400/mali/Kconfig b/drivers/gpu/arm/mali400/mali/Kconfig index f199123e6989..7b4e9fb2cf90 100755 --- a/drivers/gpu/arm/mali400/mali/Kconfig +++ b/drivers/gpu/arm/mali400/mali/Kconfig @@ -50,7 +50,7 @@ config MALI400_UMP config MALI_DVFS bool "Enable Mali dynamically frequency change" - depends on MALI400 + depends on MALI400 && !MALI_DEVFREQ default y ---help--- This enables support for dynamic change frequency of Mali with the goal of lowering power consumption. @@ -96,6 +96,17 @@ config MALI_DT device tree is enabled in kernel and corresponding hardware description is implemented properly in device DTS file. +config MALI_DEVFREQ + bool "Using devfreq to tuning frequency" + depends on MALI400 && PM_DEVFREQ + default n + ---help--- + Support devfreq for Mali. + + Using the devfreq framework and, by default, the simpleondemand + governor, the frequency of Mali will be dynamically selected from the + available OPPs. + config MALI_QUIET bool "Make Mali driver very quiet" depends on MALI400 && !MALI400_DEBUG diff --git a/drivers/gpu/arm/mali400/mali/Makefile b/drivers/gpu/arm/mali400/mali/Makefile index 44c7bb83981a..7f3f8aa940c3 100755 --- a/drivers/gpu/arm/mali400/mali/Makefile +++ b/drivers/gpu/arm/mali400/mali/Makefile @@ -1,5 +1,5 @@ # -# Copyright (C) 2010-2015 ARM Limited. All rights reserved. +# Copyright (C) 2010-2016 ARM Limited. All rights reserved. # # This program is free software and is provided to you under the terms of the GNU General Public License version 2 # as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. @@ -17,6 +17,7 @@ MALI_DMA_BUF_MAP_ON_ATTACH ?= 1 MALI_PMU_PARALLEL_POWER_UP ?= 0 USING_DT ?= 0 MALI_MEM_SWAP_TRACKING ?= 0 +USING_DEVFREQ ?= 0 # The Makefile sets up "arch" based on the CONFIG, creates the version info # string and the __malidrv_build_info.c file, and then call the Linux build @@ -158,6 +159,15 @@ export EXTRA_DEFINES += -DCONFIG_MALI_DT endif endif +ifeq ($(USING_DEVFREQ), 1) +ifdef CONFIG_PM_DEVFREQ +export CONFIG_MALI_DEVFREQ=y +export EXTRA_DEFINES += -DCONFIG_MALI_DEVFREQ=1 +else +$(warning "You want to support DEVFREQ but kernel didn't support DEVFREQ.") +endif +endif + ifneq ($(BUILD),release) # Debug export CONFIG_MALI400_DEBUG=y diff --git a/drivers/gpu/arm/mali400/mali/common/mali_broadcast.c b/drivers/gpu/arm/mali400/mali/common/mali_broadcast.c index 136db61ace4a..4c4b2bc9ee96 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_broadcast.c +++ b/drivers/gpu/arm/mali400/mali/common/mali_broadcast.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012-2015 ARM Limited. All rights reserved. + * Copyright (C) 2012-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/common/mali_broadcast.h b/drivers/gpu/arm/mali400/mali/common/mali_broadcast.h index efce44142ee9..e12e8a2b5902 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_broadcast.h +++ b/drivers/gpu/arm/mali400/mali/common/mali_broadcast.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012-2015 ARM Limited. All rights reserved. + * Copyright (C) 2012-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/common/mali_control_timer.c b/drivers/gpu/arm/mali400/mali/common/mali_control_timer.c index 2d1f579692ca..ddbf108c0b68 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_control_timer.c +++ b/drivers/gpu/arm/mali400/mali/common/mali_control_timer.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2012, 2014-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2012, 2014-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/common/mali_control_timer.h b/drivers/gpu/arm/mali400/mali/common/mali_control_timer.h index f829174de58e..16e7d7b912fc 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_control_timer.h +++ b/drivers/gpu/arm/mali400/mali/common/mali_control_timer.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2012, 2014-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2012, 2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/common/mali_dlbu.c b/drivers/gpu/arm/mali400/mali/common/mali_dlbu.c index efe1ab3ab5cc..4f2a121fc0e6 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_dlbu.c +++ b/drivers/gpu/arm/mali400/mali/common/mali_dlbu.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012-2015 ARM Limited. All rights reserved. + * Copyright (C) 2012-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/common/mali_dlbu.h b/drivers/gpu/arm/mali400/mali/common/mali_dlbu.h index 6b068884bd49..c031f1150b83 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_dlbu.h +++ b/drivers/gpu/arm/mali400/mali/common/mali_dlbu.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012-2015 ARM Limited. All rights reserved. + * Copyright (C) 2012-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/common/mali_dvfs_policy.c b/drivers/gpu/arm/mali400/mali/common/mali_dvfs_policy.c index 12ba069ec13b..1094f9df9dbe 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_dvfs_policy.c +++ b/drivers/gpu/arm/mali400/mali/common/mali_dvfs_policy.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2012, 2014-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2012, 2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/common/mali_dvfs_policy.h b/drivers/gpu/arm/mali400/mali/common/mali_dvfs_policy.h index 55e4b354c1a9..17704269b7aa 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_dvfs_policy.h +++ b/drivers/gpu/arm/mali400/mali/common/mali_dvfs_policy.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2012, 2014-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2012, 2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/common/mali_executor.c b/drivers/gpu/arm/mali400/mali/common/mali_executor.c index d8281822b6a4..4664f258c8e2 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_executor.c +++ b/drivers/gpu/arm/mali400/mali/common/mali_executor.c @@ -21,6 +21,7 @@ #include "mali_timeline.h" #include "mali_osk_profiling.h" #include "mali_session.h" +#include "mali_osk_mali.h" /*Add for voltage scan function*/ extern u32 mali_group_error; @@ -1497,6 +1498,75 @@ static mali_bool mali_executor_tackle_gp_bound(void) return MALI_FALSE; } +static mali_bool mali_executor_schedule_is_early_out(mali_bool *gpu_secure_mode_is_needed) +{ + struct mali_pp_job *next_pp_job_to_start = NULL; + struct mali_group *group; + struct mali_group *tmp_group; + struct mali_pp_job *physical_pp_job_working = NULL; + struct mali_pp_job *virtual_pp_job_working = NULL; + mali_bool gpu_working_in_protected_mode = MALI_FALSE; + mali_bool gpu_working_in_non_protected_mode = MALI_FALSE; + + MALI_DEBUG_ASSERT_LOCK_HELD(mali_scheduler_lock_obj); + + *gpu_secure_mode_is_needed = MALI_FALSE; + + /* Check if the gpu secure mode is supported, exit if not.*/ + if (MALI_FALSE == _mali_osk_gpu_secure_mode_is_supported()) { + return MALI_FALSE; + } + + /* Check if need to set gpu secure mode for the next pp job, + * get the next pp job that will be scheduled if exist. + */ + next_pp_job_to_start = mali_scheduler_job_pp_next(); + + /* Check current pp physical/virtual running job is protected job or not if exist.*/ + _MALI_OSK_LIST_FOREACHENTRY(group, tmp_group, &group_list_working, + struct mali_group, executor_list) { + physical_pp_job_working = group->pp_running_job; + break; + } + + if (EXEC_STATE_WORKING == virtual_group_state) { + virtual_pp_job_working = virtual_group->pp_running_job; + } + + if (NULL != physical_pp_job_working) { + if (MALI_TRUE == mali_pp_job_is_protected_job(physical_pp_job_working)) { + gpu_working_in_protected_mode = MALI_TRUE; + } else { + gpu_working_in_non_protected_mode = MALI_TRUE; + } + } else if (NULL != virtual_pp_job_working) { + if (MALI_TRUE == mali_pp_job_is_protected_job(virtual_pp_job_working)) { + gpu_working_in_protected_mode = MALI_TRUE; + } else { + gpu_working_in_non_protected_mode = MALI_TRUE; + } + } else if (EXEC_STATE_WORKING == gp_group_state) { + gpu_working_in_non_protected_mode = MALI_TRUE; + } + + /* If the next pp job is the protected pp job.*/ + if ((NULL != next_pp_job_to_start) && MALI_TRUE == mali_pp_job_is_protected_job(next_pp_job_to_start)) { + /* if gp is working or any non-protected pp job is working now, unable to schedule protected pp job. */ + if (MALI_TRUE == gpu_working_in_non_protected_mode) + return MALI_TRUE; + + *gpu_secure_mode_is_needed = MALI_TRUE; + return MALI_FALSE; + + } + + if (MALI_TRUE == gpu_working_in_protected_mode) { + /* Unable to schedule non-protected pp job/gp job if exist protected pp running jobs*/ + return MALI_TRUE; + } + + return MALI_FALSE; +} /* * This is where jobs are actually started. */ @@ -1507,6 +1577,7 @@ static void mali_executor_schedule(void) u32 num_physical_to_process = 0; mali_bool trigger_pm_update = MALI_FALSE; mali_bool deactivate_idle_group = MALI_TRUE; + mali_bool gpu_secure_mode_is_needed = MALI_FALSE; /* Physical groups + jobs to start in this function */ struct mali_group *groups_to_start[MALI_MAX_NUMBER_OF_PHYSICAL_PP_GROUPS]; @@ -1530,9 +1601,16 @@ static void mali_executor_schedule(void) /* Lock needed in order to safely handle the job queues */ mali_scheduler_lock(); - /* 1. Activate gp firstly if have gp job queued. */ - if (EXEC_STATE_INACTIVE == gp_group_state && - 0 < mali_scheduler_job_gp_count()) { + /* 1. Check the schedule if need to early out. */ + if (MALI_TRUE == mali_executor_schedule_is_early_out(&gpu_secure_mode_is_needed)) { + mali_scheduler_unlock(); + return; + } + + /* 2. Activate gp firstly if have gp job queued. */ + if ((EXEC_STATE_INACTIVE == gp_group_state) + && (0 < mali_scheduler_job_gp_count()) + && (gpu_secure_mode_is_needed == MALI_FALSE)) { enum mali_group_state state = mali_group_activate(gp_group); @@ -1544,9 +1622,9 @@ static void mali_executor_schedule(void) } } - /* 2. Prepare as many physical groups as needed/possible */ + /* 3. Prepare as many physical groups as needed/possible */ - num_physical_needed = mali_scheduler_job_physical_head_count(); + num_physical_needed = mali_scheduler_job_physical_head_count(gpu_secure_mode_is_needed); /* On mali-450 platform, we don't need to enter in this block frequently. */ if (0 < num_physical_needed) { @@ -1563,7 +1641,7 @@ static void mali_executor_schedule(void) if (0 < num_physical_needed) { - /* 2.1. Activate groups which are inactive */ + /* 3.1. Activate groups which are inactive */ struct mali_group *group; struct mali_group *temp; @@ -1595,7 +1673,7 @@ static void mali_executor_schedule(void) if (mali_executor_virtual_group_is_usable()) { /* - * 2.2. And finally, steal and activate groups + * 3.2. And finally, steal and activate groups * from virtual group if we need even more */ while (0 < num_physical_needed) { @@ -1638,7 +1716,7 @@ static void mali_executor_schedule(void) } } - /* 2.3. Assign physical jobs to groups */ + /* 3.3. Assign physical jobs to groups */ if (0 < num_physical_to_process) { struct mali_group *group; @@ -1653,24 +1731,30 @@ static void mali_executor_schedule(void) MALI_MAX_NUMBER_OF_PHYSICAL_PP_GROUPS); MALI_DEBUG_ASSERT(0 < - mali_scheduler_job_physical_head_count()); + mali_scheduler_job_physical_head_count(gpu_secure_mode_is_needed)); - if (mali_executor_hint_is_enabled( - MALI_EXECUTOR_HINT_GP_BOUND)) { - if (MALI_TRUE == mali_executor_tackle_gp_bound()) { - /* - * We're gp bound, - * don't start this right now. - */ - deactivate_idle_group = MALI_FALSE; - num_physical_to_process = 0; - break; - } + /* If the next pp job is non-protected, check if gp bound now. */ + if ((MALI_FALSE == gpu_secure_mode_is_needed) + && (mali_executor_hint_is_enabled(MALI_EXECUTOR_HINT_GP_BOUND)) + && (MALI_TRUE == mali_executor_tackle_gp_bound())) { + /* + * We're gp bound, + * don't start this right now. + */ + deactivate_idle_group = MALI_FALSE; + num_physical_to_process = 0; + break; } job = mali_scheduler_job_pp_physical_get( &sub_job); + if (MALI_FALSE == gpu_secure_mode_is_needed) { + MALI_DEBUG_ASSERT(MALI_FALSE == mali_pp_job_is_protected_job(job)); + } else { + MALI_DEBUG_ASSERT(MALI_TRUE == mali_pp_job_is_protected_job(job)); + } + MALI_DEBUG_ASSERT_POINTER(job); MALI_DEBUG_ASSERT(sub_job <= MALI_MAX_NUMBER_OF_PHYSICAL_PP_GROUPS); @@ -1697,8 +1781,7 @@ static void mali_executor_schedule(void) } } - - /* 3. Deactivate idle pp group , must put deactive here before active vitual group + /* 4. Deactivate idle pp group , must put deactive here before active vitual group * for cover case first only has physical job in normal queue but group inactive, * so delay the job start go to active group, when group activated, * call scheduler again, but now if we get high queue virtual job, @@ -1710,34 +1793,41 @@ static void mali_executor_schedule(void) trigger_pm_update = MALI_TRUE; } - /* 4. Activate virtual group, if needed */ - + /* 5. Activate virtual group, if needed */ if (EXEC_STATE_INACTIVE == virtual_group_state && - 0 < mali_scheduler_job_next_is_virtual()) { - enum mali_group_state state = - mali_group_activate(virtual_group); - if (MALI_GROUP_STATE_ACTIVE == state) { - /* Set virtual group state to idle */ - virtual_group_state = EXEC_STATE_IDLE; - } else { - trigger_pm_update = MALI_TRUE; + MALI_TRUE == mali_scheduler_job_next_is_virtual()) { + struct mali_pp_job *virtual_job = mali_scheduler_job_pp_virtual_peek(); + if ((MALI_FALSE == gpu_secure_mode_is_needed && MALI_FALSE == mali_pp_job_is_protected_job(virtual_job)) + || (MALI_TRUE == gpu_secure_mode_is_needed && MALI_TRUE == mali_pp_job_is_protected_job(virtual_job))) { + enum mali_group_state state = + mali_group_activate(virtual_group); + if (MALI_GROUP_STATE_ACTIVE == state) { + /* Set virtual group state to idle */ + virtual_group_state = EXEC_STATE_IDLE; + } else { + trigger_pm_update = MALI_TRUE; + } } } - /* 5. To power up group asap, we trigger pm update here. */ + /* 6. To power up group asap, we trigger pm update here. */ if (MALI_TRUE == trigger_pm_update) { trigger_pm_update = MALI_FALSE; mali_pm_update_async(); } - /* 6. Assign jobs to idle virtual group (or deactivate if no job) */ + /* 7. Assign jobs to idle virtual group (or deactivate if no job) */ if (EXEC_STATE_IDLE == virtual_group_state) { - if (0 < mali_scheduler_job_next_is_virtual()) { - virtual_job_to_start = - mali_scheduler_job_pp_virtual_get(); - virtual_group_state = EXEC_STATE_WORKING; + if (MALI_TRUE == mali_scheduler_job_next_is_virtual()) { + struct mali_pp_job *virtual_job = mali_scheduler_job_pp_virtual_peek(); + if ((MALI_FALSE == gpu_secure_mode_is_needed && MALI_FALSE == mali_pp_job_is_protected_job(virtual_job)) + || (MALI_TRUE == gpu_secure_mode_is_needed && MALI_TRUE == mali_pp_job_is_protected_job(virtual_job))) { + virtual_job_to_start = + mali_scheduler_job_pp_virtual_get(); + virtual_group_state = EXEC_STATE_WORKING; + } } else if (!mali_timeline_has_virtual_pp_job()) { virtual_group_state = EXEC_STATE_INACTIVE; @@ -1747,9 +1837,9 @@ static void mali_executor_schedule(void) } } - /* 7. Assign job to idle GP group (or deactivate if no job) */ + /* 8. Assign job to idle GP group (or deactivate if no job) */ - if (EXEC_STATE_IDLE == gp_group_state) { + if (EXEC_STATE_IDLE == gp_group_state && MALI_FALSE == gpu_secure_mode_is_needed) { if (0 < mali_scheduler_job_gp_count()) { gp_job_to_start = mali_scheduler_job_gp_get(); gp_group_state = EXEC_STATE_WORKING; @@ -1761,12 +1851,11 @@ static void mali_executor_schedule(void) } } - /* 8. We no longer need the schedule/queue lock */ + /* 9. We no longer need the schedule/queue lock */ mali_scheduler_unlock(); - /* 9. start jobs */ - + /* 10. start jobs */ if (NULL != virtual_job_to_start) { MALI_DEBUG_ASSERT(!mali_group_pp_is_active(virtual_group)); mali_group_start_pp_job(virtual_group, @@ -1788,7 +1877,7 @@ static void mali_executor_schedule(void) mali_group_start_gp_job(gp_group, gp_job_to_start); } - /* 10. Trigger any pending PM updates */ + /* 11. Trigger any pending PM updates */ if (MALI_TRUE == trigger_pm_update) { mali_pm_update_async(); } diff --git a/drivers/gpu/arm/mali400/mali/common/mali_gp.c b/drivers/gpu/arm/mali400/mali/common/mali_gp.c index a690781837e9..a918552162a8 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_gp.c +++ b/drivers/gpu/arm/mali400/mali/common/mali_gp.c @@ -12,6 +12,7 @@ #include "mali_hw_core.h" #include "mali_group.h" #include "mali_osk.h" +#include "mali_osk_mali.h" #include "regs/mali_gp_regs.h" #include "mali_kernel_common.h" #include "mali_kernel_core.h" @@ -199,6 +200,11 @@ void mali_gp_job_start(struct mali_gp_core *core, struct mali_gp_job *job) u32 counter_src0 = mali_gp_job_get_perf_counter_src0(job); u32 counter_src1 = mali_gp_job_get_perf_counter_src1(job); + /* Disable gpu secure mode. */ + if (MALI_TRUE == _mali_osk_gpu_secure_mode_is_enabled()) { + _mali_osk_gpu_secure_mode_disable(); + } + MALI_DEBUG_ASSERT_POINTER(core); if (mali_gp_job_has_vs_job(job)) { diff --git a/drivers/gpu/arm/mali400/mali/common/mali_gp.h b/drivers/gpu/arm/mali400/mali/common/mali_gp.h index 8d5f69c23229..ecbe70e940c3 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_gp.h +++ b/drivers/gpu/arm/mali400/mali/common/mali_gp.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2015 ARM Limited. All rights reserved. + * Copyright (C) 2011-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/common/mali_gp_job.c b/drivers/gpu/arm/mali400/mali/common/mali_gp_job.c index 81b46437af13..18e9f775ddbe 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_gp_job.c +++ b/drivers/gpu/arm/mali400/mali/common/mali_gp_job.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2015 ARM Limited. All rights reserved. + * Copyright (C) 2011-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. @@ -120,33 +120,32 @@ struct mali_gp_job *mali_gp_job_create(struct mali_session_data *session, _mali_ INIT_LIST_HEAD(&job->vary_todo); job->dmem = NULL; - if (job->uargs.varying_alloc_num > session->allocation_mgr.mali_allocation_num) { + if (job->uargs.deferred_mem_num > session->allocation_mgr.mali_allocation_num) { MALI_PRINT_ERROR(("Mali GP job: The number of varying buffer to defer bind is invalid !\n")); goto fail1; } /* add varying allocation list*/ - if (job->uargs.varying_alloc_num > 0) { + if (job->uargs.deferred_mem_num > 0) { /* copy varying list from user space*/ - job->varying_list = _mali_osk_calloc(1, sizeof(u32) * job->uargs.varying_alloc_num); + job->varying_list = _mali_osk_calloc(1, sizeof(u32) * job->uargs.deferred_mem_num); if (!job->varying_list) { - MALI_PRINT_ERROR(("Mali GP job: allocate varying_list failed varying_alloc_num = %d !\n", job->uargs.varying_alloc_num)); + MALI_PRINT_ERROR(("Mali GP job: allocate varying_list failed varying_alloc_num = %d !\n", job->uargs.deferred_mem_num)); goto fail1; } if (0 != _mali_osk_copy_from_user(©_of_uargs, uargs, sizeof(_mali_uk_gp_start_job_s))) { goto fail1; } + memory_list = (u32 __user *)(uintptr_t)copy_of_uargs.deferred_mem_list; - memory_list = (u32 __user *)(uintptr_t)copy_of_uargs.varying_alloc_list; - - if (0 != _mali_osk_copy_from_user(job->varying_list, memory_list, sizeof(u32) * job->uargs.varying_alloc_num)) { + if (0 != _mali_osk_copy_from_user(job->varying_list, memory_list, sizeof(u32) * job->uargs.deferred_mem_num)) { MALI_PRINT_ERROR(("Mali GP job: Failed to copy varying list from user space!\n")); goto fail; } if (unlikely(_mali_gp_add_varying_allocations(session, job, job->varying_list, - job->uargs.varying_alloc_num))) { + job->uargs.deferred_mem_num))) { MALI_PRINT_ERROR(("Mali GP job: _mali_gp_add_varying_allocations failed!\n")); goto fail; } diff --git a/drivers/gpu/arm/mali400/mali/common/mali_gp_job.h b/drivers/gpu/arm/mali400/mali/common/mali_gp_job.h index 5dd534155249..fbf8ee8fd605 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_gp_job.h +++ b/drivers/gpu/arm/mali400/mali/common/mali_gp_job.h @@ -73,7 +73,7 @@ struct mali_gp_job { u32 bind_flag; /** < flag for deferbind*/ u32 *varying_list; /**< varying memory list need to to defer bind*/ struct list_head vary_todo; /**< list of backend list need to do defer bind*/ - u32 required_varying_memsize; /** < size of varying memory to reallocate*/ + u32 required_varying_memsize; /** < size of varying memory to reallocate*/ u32 big_job; /** < if the gp job have large varying output and may take long time*/ }; diff --git a/drivers/gpu/arm/mali400/mali/common/mali_group.c b/drivers/gpu/arm/mali400/mali/common/mali_group.c index aface0757246..b9651a40e5b5 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_group.c +++ b/drivers/gpu/arm/mali400/mali/common/mali_group.c @@ -1468,19 +1468,19 @@ _mali_osk_errcode_t mali_group_upper_half_mmu(void *data) /* group complete and on job shedule on it, it already power off */ if (NULL != group->gp_core) { _mali_osk_profiling_add_event(MALI_PROFILING_EVENT_TYPE_STOP | - MALI_PROFILING_EVENT_CHANNEL_SOFTWARE | - MALI_PROFILING_EVENT_REASON_START_STOP_SW_UPPER_HALF, - 0, 0, /* No pid and tid for interrupt handler */ - MALI_PROFILING_MAKE_EVENT_DATA_CORE_GP_MMU(0), - 0xFFFFFFFF, 0); + MALI_PROFILING_EVENT_CHANNEL_SOFTWARE | + MALI_PROFILING_EVENT_REASON_START_STOP_SW_UPPER_HALF, + 0, 0, /* No pid and tid for interrupt handler */ + MALI_PROFILING_MAKE_EVENT_DATA_CORE_GP_MMU(0), + 0xFFFFFFFF, 0); } else { _mali_osk_profiling_add_event(MALI_PROFILING_EVENT_TYPE_STOP | - MALI_PROFILING_EVENT_CHANNEL_SOFTWARE | - MALI_PROFILING_EVENT_REASON_START_STOP_SW_UPPER_HALF, - 0, 0, /* No pid and tid for interrupt handler */ - MALI_PROFILING_MAKE_EVENT_DATA_CORE_PP_MMU( - mali_pp_core_get_id(group->pp_core)), - 0xFFFFFFFF, 0); + MALI_PROFILING_EVENT_CHANNEL_SOFTWARE | + MALI_PROFILING_EVENT_REASON_START_STOP_SW_UPPER_HALF, + 0, 0, /* No pid and tid for interrupt handler */ + MALI_PROFILING_MAKE_EVENT_DATA_CORE_PP_MMU( + mali_pp_core_get_id(group->pp_core)), + 0xFFFFFFFF, 0); } mali_executor_unlock(); @@ -1597,11 +1597,11 @@ _mali_osk_errcode_t mali_group_upper_half_gp(void *data) if (!mali_group_is_working(group) && (!mali_group_power_is_on(group))) { /* group complete and on job shedule on it, it already power off */ _mali_osk_profiling_add_event(MALI_PROFILING_EVENT_TYPE_STOP | - MALI_PROFILING_EVENT_CHANNEL_SOFTWARE | - MALI_PROFILING_EVENT_REASON_START_STOP_SW_UPPER_HALF, - 0, 0, /* No pid and tid for interrupt handler */ - MALI_PROFILING_MAKE_EVENT_DATA_CORE_GP(0), - 0xFFFFFFFF, 0); + MALI_PROFILING_EVENT_CHANNEL_SOFTWARE | + MALI_PROFILING_EVENT_REASON_START_STOP_SW_UPPER_HALF, + 0, 0, /* No pid and tid for interrupt handler */ + MALI_PROFILING_MAKE_EVENT_DATA_CORE_GP(0), + 0xFFFFFFFF, 0); mali_executor_unlock(); return ret; } @@ -1687,12 +1687,12 @@ _mali_osk_errcode_t mali_group_upper_half_pp(void *data) if (!mali_group_is_working(group) && (!mali_group_power_is_on(group))) { /* group complete and on job shedule on it, it already power off */ _mali_osk_profiling_add_event(MALI_PROFILING_EVENT_TYPE_STOP | - MALI_PROFILING_EVENT_CHANNEL_SOFTWARE | - MALI_PROFILING_EVENT_REASON_START_STOP_SW_UPPER_HALF, - 0, 0, /* No pid and tid for interrupt handler */ - MALI_PROFILING_MAKE_EVENT_DATA_CORE_PP( - mali_pp_core_get_id(group->pp_core)), - 0xFFFFFFFF, 0); + MALI_PROFILING_EVENT_CHANNEL_SOFTWARE | + MALI_PROFILING_EVENT_REASON_START_STOP_SW_UPPER_HALF, + 0, 0, /* No pid and tid for interrupt handler */ + MALI_PROFILING_MAKE_EVENT_DATA_CORE_PP( + mali_pp_core_get_id(group->pp_core)), + 0xFFFFFFFF, 0); mali_executor_unlock(); return ret; } diff --git a/drivers/gpu/arm/mali400/mali/common/mali_hw_core.c b/drivers/gpu/arm/mali400/mali/common/mali_hw_core.c index c90cf38d8516..dd10cfe89aeb 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_hw_core.c +++ b/drivers/gpu/arm/mali400/mali/common/mali_hw_core.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2015 ARM Limited. All rights reserved. + * Copyright (C) 2011-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/common/mali_hw_core.h b/drivers/gpu/arm/mali400/mali/common/mali_hw_core.h index ac2ffbedf308..e4357253998b 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_hw_core.h +++ b/drivers/gpu/arm/mali400/mali/common/mali_hw_core.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2015 ARM Limited. All rights reserved. + * Copyright (C) 2011-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/common/mali_kernel_common.h b/drivers/gpu/arm/mali400/mali/common/mali_kernel_common.h index 990cf3ac78e0..9bae26579866 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_kernel_common.h +++ b/drivers/gpu/arm/mali400/mali/common/mali_kernel_common.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010, 2012-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010, 2012-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/common/mali_kernel_core.c b/drivers/gpu/arm/mali400/mali/common/mali_kernel_core.c index 6dca53af2e47..6a62c9298f35 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_kernel_core.c +++ b/drivers/gpu/arm/mali400/mali/common/mali_kernel_core.c @@ -756,6 +756,9 @@ _mali_osk_errcode_t mali_initialize_subsystems(void) return err; } + /*Try to init gpu secure mode */ + _mali_osk_gpu_secure_mode_init(); + #if defined(CONFIG_MALI400_PROFILING) err = _mali_osk_profiling_init(mali_boot_profiling ? MALI_TRUE : MALI_FALSE); if (_MALI_OSK_ERR_OK != err) { @@ -939,6 +942,8 @@ void mali_terminate_subsystems(void) _mali_osk_profiling_term(); #endif + _mali_osk_gpu_secure_mode_deinit(); + mali_memory_terminate(); mali_session_terminate(); diff --git a/drivers/gpu/arm/mali400/mali/common/mali_kernel_core.h b/drivers/gpu/arm/mali400/mali/common/mali_kernel_core.h index 8cdbc5af3205..cf6af3263f0b 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_kernel_core.h +++ b/drivers/gpu/arm/mali400/mali/common/mali_kernel_core.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/common/mali_kernel_utilization.c b/drivers/gpu/arm/mali400/mali/common/mali_kernel_utilization.c index 63b941742249..ca7ebea4763b 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_kernel_utilization.c +++ b/drivers/gpu/arm/mali400/mali/common/mali_kernel_utilization.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/common/mali_kernel_utilization.h b/drivers/gpu/arm/mali400/mali/common/mali_kernel_utilization.h index 3c20b1983762..5206225ca2f1 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_kernel_utilization.h +++ b/drivers/gpu/arm/mali400/mali/common/mali_kernel_utilization.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/common/mali_kernel_vsync.c b/drivers/gpu/arm/mali400/mali/common/mali_kernel_vsync.c index 2eed4c88cf56..3b2b108c747a 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_kernel_vsync.c +++ b/drivers/gpu/arm/mali400/mali/common/mali_kernel_vsync.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2015 ARM Limited. All rights reserved. + * Copyright (C) 2011-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/common/mali_l2_cache.c b/drivers/gpu/arm/mali400/mali/common/mali_l2_cache.c index 494ba789cd08..4fbb51c870d7 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_l2_cache.c +++ b/drivers/gpu/arm/mali400/mali/common/mali_l2_cache.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/common/mali_l2_cache.h b/drivers/gpu/arm/mali400/mali/common/mali_l2_cache.h index 6dc8ec22d6de..de92ad63e9aa 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_l2_cache.h +++ b/drivers/gpu/arm/mali400/mali/common/mali_l2_cache.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/common/mali_mem_validation.c b/drivers/gpu/arm/mali400/mali/common/mali_mem_validation.c index 0ab35094004b..dbc68bd4c212 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_mem_validation.c +++ b/drivers/gpu/arm/mali400/mali/common/mali_mem_validation.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2015 ARM Limited. All rights reserved. + * Copyright (C) 2011-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/common/mali_mem_validation.h b/drivers/gpu/arm/mali400/mali/common/mali_mem_validation.h index 267720625d87..f7e6cb1009b3 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_mem_validation.h +++ b/drivers/gpu/arm/mali400/mali/common/mali_mem_validation.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2013, 2015 ARM Limited. All rights reserved. + * Copyright (C) 2011-2013, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/common/mali_mmu.c b/drivers/gpu/arm/mali400/mali/common/mali_mmu.c index b975c1468d67..fba534058b79 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_mmu.c +++ b/drivers/gpu/arm/mali400/mali/common/mali_mmu.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/common/mali_mmu.h b/drivers/gpu/arm/mali400/mali/common/mali_mmu.h index 101c968bd45d..398b2096c5d8 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_mmu.h +++ b/drivers/gpu/arm/mali400/mali/common/mali_mmu.h @@ -91,6 +91,7 @@ MALI_STATIC_INLINE enum mali_interrupt_result mali_mmu_get_interrupt_result(stru if (0 == rawstat_used) { return MALI_INTERRUPT_RESULT_NONE; } + return MALI_INTERRUPT_RESULT_ERROR; } diff --git a/drivers/gpu/arm/mali400/mali/common/mali_mmu_page_directory.c b/drivers/gpu/arm/mali400/mali/common/mali_mmu_page_directory.c index 126fd77ec9c9..74d8cc85bc8e 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_mmu_page_directory.c +++ b/drivers/gpu/arm/mali400/mali/common/mali_mmu_page_directory.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2015 ARM Limited. All rights reserved. + * Copyright (C) 2011-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/common/mali_mmu_page_directory.h b/drivers/gpu/arm/mali400/mali/common/mali_mmu_page_directory.h index 561fb60b9803..4fc1058d73f6 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_mmu_page_directory.h +++ b/drivers/gpu/arm/mali400/mali/common/mali_mmu_page_directory.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2015 ARM Limited. All rights reserved. + * Copyright (C) 2011-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/common/mali_osk.h b/drivers/gpu/arm/mali400/mali/common/mali_osk.h index 4c9e57cba18f..5c20fc32993f 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_osk.h +++ b/drivers/gpu/arm/mali400/mali/common/mali_osk.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. @@ -16,6 +16,7 @@ #ifndef __MALI_OSK_H__ #define __MALI_OSK_H__ +#include #include "mali_osk_types.h" #include "mali_osk_specific.h" /* include any per-os specifics */ #include "mali_osk_locks.h" @@ -50,6 +51,8 @@ extern "C" { #define MALI_DEBUG_ASSERT_LOCK_HELD(l) do {} while(0) #endif +#define _mali_osk_ctxprintf seq_printf + /** @} */ /* end group _mali_osk_lock */ /** @addtogroup _mali_osk_miscellaneous @@ -1237,17 +1240,6 @@ void _mali_osk_dbgmsg(const char *fmt, ...); */ u32 _mali_osk_snprintf(char *buf, u32 size, const char *fmt, ...); -/** @brief Print fmt into print_ctx. - * - * The interpretation of \a fmt is the same as the \c format parameter in - * _mali_osu_vsnprintf(). - * - * @param print_ctx a pointer to the result file buffer - * @param fmt a _mali_osu_vsnprintf() style format string - * @param ... a variable-number of parameters suitable for \a fmt - */ -void _mali_osk_ctxprintf(_mali_osk_print_ctx *print_ctx, const char *fmt, ...); - /** @brief Abnormal process abort. * * Terminates the caller-process if this function is called. diff --git a/drivers/gpu/arm/mali400/mali/common/mali_osk_bitops.h b/drivers/gpu/arm/mali400/mali/common/mali_osk_bitops.h index c1709f94c883..61e0a9110b3f 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_osk_bitops.h +++ b/drivers/gpu/arm/mali400/mali/common/mali_osk_bitops.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010, 2013-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010, 2013-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/common/mali_osk_list.h b/drivers/gpu/arm/mali400/mali/common/mali_osk_list.h index 22d22446d7a0..a41f5ab3e77b 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_osk_list.h +++ b/drivers/gpu/arm/mali400/mali/common/mali_osk_list.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/common/mali_osk_mali.h b/drivers/gpu/arm/mali400/mali/common/mali_osk_mali.h index 230dbecc2040..0d6906ad204b 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_osk_mali.h +++ b/drivers/gpu/arm/mali400/mali/common/mali_osk_mali.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. @@ -23,6 +23,28 @@ extern "C" { #endif +#ifdef CONFIG_MALI_DEVFREQ +struct mali_device { + struct device *dev; +#ifdef CONFIG_HAVE_CLK + struct clk *clock; +#endif +#ifdef CONFIG_REGULATOR + struct regulator *regulator; +#endif +#ifdef CONFIG_PM_DEVFREQ + struct devfreq_dev_profile devfreq_profile; + struct devfreq *devfreq; + unsigned long current_freq; + unsigned long current_voltage; +#ifdef CONFIG_DEVFREQ_THERMAL + struct thermal_cooling_device *devfreq_cooling; +#endif +#endif + struct mali_pm_metrics_data mali_metrics; +}; +#endif + /** @addtogroup _mali_osk_miscellaneous * @{ */ @@ -88,6 +110,38 @@ u32 _mali_osk_get_pmu_switch_delay(void); */ mali_bool _mali_osk_shared_interrupts(void); +/** @brief Initialize the gpu secure mode. + * The gpu secure mode will initially be in a disabled state. + * @return _MALI_OSK_ERR_OK on success, otherwise failure. + */ +_mali_osk_errcode_t _mali_osk_gpu_secure_mode_init(void); + +/** @brief Deinitialize the gpu secure mode. + * @return _MALI_OSK_ERR_OK on success, otherwise failure. + */ +_mali_osk_errcode_t _mali_osk_gpu_secure_mode_deinit(void); + +/** @brief Enable the gpu secure mode. + * @return _MALI_OSK_ERR_OK on success, otherwise failure. + */ +_mali_osk_errcode_t _mali_osk_gpu_secure_mode_enable(void); + +/** @brief Disable the gpu secure mode. + * @return _MALI_OSK_ERR_OK on success, otherwise failure. + */ +_mali_osk_errcode_t _mali_osk_gpu_secure_mode_disable(void); + +/** @brief Check if the gpu secure mode has been enabled. + * @return MALI_TRUE if enabled, otherwise MALI_FALSE. + */ +mali_bool _mali_osk_gpu_secure_mode_is_enabled(void); + +/** @brief Check if the gpu secure mode is supported. + * @return MALI_TRUE if supported, otherwise MALI_FALSE. + */ +mali_bool _mali_osk_gpu_secure_mode_is_supported(void); + + /** @} */ /* end group _mali_osk_miscellaneous */ #ifdef __cplusplus diff --git a/drivers/gpu/arm/mali400/mali/common/mali_osk_profiling.h b/drivers/gpu/arm/mali400/mali/common/mali_osk_profiling.h index 10f4dc552b03..eca6ad493c33 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_osk_profiling.h +++ b/drivers/gpu/arm/mali400/mali/common/mali_osk_profiling.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/common/mali_osk_types.h b/drivers/gpu/arm/mali400/mali/common/mali_osk_types.h index b65ad29e16c0..6e9a1336bf0b 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_osk_types.h +++ b/drivers/gpu/arm/mali400/mali/common/mali_osk_types.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/common/mali_pm.c b/drivers/gpu/arm/mali400/mali/common/mali_pm.c index dbd94d310741..1ef03a69a084 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_pm.c +++ b/drivers/gpu/arm/mali400/mali/common/mali_pm.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2015 ARM Limited. All rights reserved. + * Copyright (C) 2011-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/common/mali_pm.h b/drivers/gpu/arm/mali400/mali/common/mali_pm.h index d72c732e698d..3c11977f00fa 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_pm.h +++ b/drivers/gpu/arm/mali400/mali/common/mali_pm.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2015 ARM Limited. All rights reserved. + * Copyright (C) 2011-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/common/mali_pm_domain.c b/drivers/gpu/arm/mali400/mali/common/mali_pm_domain.c index dbf985e6d37b..9db848865a80 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_pm_domain.c +++ b/drivers/gpu/arm/mali400/mali/common/mali_pm_domain.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013-2015 ARM Limited. All rights reserved. + * Copyright (C) 2013-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/common/mali_pm_domain.h b/drivers/gpu/arm/mali400/mali/common/mali_pm_domain.h index aceb3449359a..2ac8c0d3068c 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_pm_domain.h +++ b/drivers/gpu/arm/mali400/mali/common/mali_pm_domain.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013-2015 ARM Limited. All rights reserved. + * Copyright (C) 2013-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/common/mali_pm_metrics.c b/drivers/gpu/arm/mali400/mali/common/mali_pm_metrics.c new file mode 100644 index 000000000000..981ec815d036 --- /dev/null +++ b/drivers/gpu/arm/mali400/mali/common/mali_pm_metrics.c @@ -0,0 +1,255 @@ +/* + * Copyright (C) 2010-2014, 2016 ARM Limited. All rights reserved. + * + * This program is free software and is provided to you under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. + * + * A copy of the licence is included with the program, and can also be obtained from Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#include "mali_pm_metrics.h" +#include "mali_osk_locks.h" +#include "mali_osk_mali.h" +#include + +#define MALI_PM_TIME_SHIFT 0 +#define MALI_UTILIZATION_MAX_PERIOD 80000000/* ns = 100ms */ + +_mali_osk_errcode_t mali_pm_metrics_init(struct mali_device *mdev) +{ + int i = 0; + + MALI_DEBUG_ASSERT(mdev != NULL); + + mdev->mali_metrics.time_period_start = ktime_get(); + mdev->mali_metrics.time_period_start_gp = mdev->mali_metrics.time_period_start; + mdev->mali_metrics.time_period_start_pp = mdev->mali_metrics.time_period_start; + + mdev->mali_metrics.time_busy = 0; + mdev->mali_metrics.time_idle = 0; + mdev->mali_metrics.prev_busy = 0; + mdev->mali_metrics.prev_idle = 0; + mdev->mali_metrics.num_running_gp_cores = 0; + mdev->mali_metrics.num_running_pp_cores = 0; + mdev->mali_metrics.time_busy_gp = 0; + mdev->mali_metrics.time_idle_gp = 0; + + for (i = 0; i < MALI_MAX_NUMBER_OF_PHYSICAL_PP_GROUPS; i++) { + mdev->mali_metrics.time_busy_pp[i] = 0; + mdev->mali_metrics.time_idle_pp[i] = 0; + } + mdev->mali_metrics.gpu_active = MALI_FALSE; + + mdev->mali_metrics.lock = _mali_osk_spinlock_irq_init(_MALI_OSK_LOCKFLAG_UNORDERED, _MALI_OSK_LOCK_ORDER_FIRST); + if (NULL == mdev->mali_metrics.lock) { + return _MALI_OSK_ERR_NOMEM; + } + + return _MALI_OSK_ERR_OK; +} + +void mali_pm_metrics_term(struct mali_device *mdev) +{ + _mali_osk_spinlock_irq_term(mdev->mali_metrics.lock); +} + +/*caller needs to hold mdev->mali_metrics.lock before calling this function*/ +void mali_pm_record_job_status(struct mali_device *mdev) +{ + ktime_t now; + ktime_t diff; + u64 ns_time; + + MALI_DEBUG_ASSERT(mdev != NULL); + + now = ktime_get(); + diff = ktime_sub(now, mdev->mali_metrics.time_period_start); + + ns_time = (u64)(ktime_to_ns(diff) >> MALI_PM_TIME_SHIFT); + mdev->mali_metrics.time_busy += ns_time; + mdev->mali_metrics.time_period_start = now; +} + +void mali_pm_record_gpu_idle(mali_bool is_gp) +{ + ktime_t now; + ktime_t diff; + u64 ns_time; + struct mali_device *mdev = dev_get_drvdata(&mali_platform_device->dev); + + MALI_DEBUG_ASSERT(mdev != NULL); + + _mali_osk_spinlock_irq_lock(mdev->mali_metrics.lock); + now = ktime_get(); + + if (MALI_TRUE == is_gp) { + --mdev->mali_metrics.num_running_gp_cores; + if (0 == mdev->mali_metrics.num_running_gp_cores) { + diff = ktime_sub(now, mdev->mali_metrics.time_period_start_gp); + ns_time = (u64)(ktime_to_ns(diff) >> MALI_PM_TIME_SHIFT); + mdev->mali_metrics.time_busy_gp += ns_time; + mdev->mali_metrics.time_period_start_gp = now; + + if (0 == mdev->mali_metrics.num_running_pp_cores) { + MALI_DEBUG_ASSERT(mdev->mali_metrics.gpu_active == MALI_TRUE); + diff = ktime_sub(now, mdev->mali_metrics.time_period_start); + ns_time = (u64)(ktime_to_ns(diff) >> MALI_PM_TIME_SHIFT); + mdev->mali_metrics.time_busy += ns_time; + mdev->mali_metrics.time_period_start = now; + mdev->mali_metrics.gpu_active = MALI_FALSE; + } + } + } else { + --mdev->mali_metrics.num_running_pp_cores; + if (0 == mdev->mali_metrics.num_running_pp_cores) { + diff = ktime_sub(now, mdev->mali_metrics.time_period_start_pp); + ns_time = (u64)(ktime_to_ns(diff) >> MALI_PM_TIME_SHIFT); + mdev->mali_metrics.time_busy_pp[0] += ns_time; + mdev->mali_metrics.time_period_start_pp = now; + + if (0 == mdev->mali_metrics.num_running_gp_cores) { + MALI_DEBUG_ASSERT(mdev->mali_metrics.gpu_active == MALI_TRUE); + diff = ktime_sub(now, mdev->mali_metrics.time_period_start); + ns_time = (u64)(ktime_to_ns(diff) >> MALI_PM_TIME_SHIFT); + mdev->mali_metrics.time_busy += ns_time; + mdev->mali_metrics.time_period_start = now; + mdev->mali_metrics.gpu_active = MALI_FALSE; + } + } + } + + _mali_osk_spinlock_irq_unlock(mdev->mali_metrics.lock); +} + +void mali_pm_record_gpu_active(mali_bool is_gp) +{ + ktime_t now; + ktime_t diff; + struct mali_device *mdev = dev_get_drvdata(&mali_platform_device->dev); + + MALI_DEBUG_ASSERT(mdev != NULL); + + _mali_osk_spinlock_irq_lock(mdev->mali_metrics.lock); + now = ktime_get(); + + if (MALI_TRUE == is_gp) { + mdev->mali_metrics.num_running_gp_cores++; + if (1 == mdev->mali_metrics.num_running_gp_cores) { + diff = ktime_sub(now, mdev->mali_metrics.time_period_start_gp); + mdev->mali_metrics.time_idle_gp += (u64)(ktime_to_ns(diff) >> MALI_PM_TIME_SHIFT); + mdev->mali_metrics.time_period_start_gp = now; + if (0 == mdev->mali_metrics.num_running_pp_cores) { + MALI_DEBUG_ASSERT(mdev->mali_metrics.gpu_active == MALI_FALSE); + diff = ktime_sub(now, mdev->mali_metrics.time_period_start); + mdev->mali_metrics.time_idle += (u64)(ktime_to_ns(diff) >> MALI_PM_TIME_SHIFT); + mdev->mali_metrics.time_period_start = now; + mdev->mali_metrics.gpu_active = MALI_TRUE; + } + } else { + MALI_DEBUG_ASSERT(mdev->mali_metrics.gpu_active == MALI_TRUE); + } + } else { + mdev->mali_metrics.num_running_pp_cores++; + if (1 == mdev->mali_metrics.num_running_pp_cores) { + diff = ktime_sub(now, mdev->mali_metrics.time_period_start_pp); + mdev->mali_metrics.time_idle_pp[0] += (u64)(ktime_to_ns(diff) >> MALI_PM_TIME_SHIFT); + mdev->mali_metrics.time_period_start_pp = now; + if (0 == mdev->mali_metrics.num_running_gp_cores) { + MALI_DEBUG_ASSERT(mdev->mali_metrics.gpu_active == MALI_FALSE); + diff = ktime_sub(now, mdev->mali_metrics.time_period_start); + mdev->mali_metrics.time_idle += (u64)(ktime_to_ns(diff) >> MALI_PM_TIME_SHIFT); + mdev->mali_metrics.time_period_start = now; + mdev->mali_metrics.gpu_active = MALI_TRUE; + } + } else { + MALI_DEBUG_ASSERT(mdev->mali_metrics.gpu_active == MALI_TRUE); + } + } + + _mali_osk_spinlock_irq_unlock(mdev->mali_metrics.lock); +} + + +/*caller needs to hold mdev->mali_metrics.lock before calling this function*/ +static void mali_pm_get_dvfs_utilisation_calc(struct mali_device *mdev, ktime_t now) +{ + ktime_t diff; + + MALI_DEBUG_ASSERT(mdev != NULL); + + diff = ktime_sub(now, mdev->mali_metrics.time_period_start); + + if (mdev->mali_metrics.gpu_active) { + mdev->mali_metrics.time_busy += (u64)(ktime_to_ns(diff) >> MALI_PM_TIME_SHIFT); + } else { + mdev->mali_metrics.time_idle += (u64)(ktime_to_ns(diff) >> MALI_PM_TIME_SHIFT); + } +} + +/* Caller needs to hold mdev->mali_metrics.lock before calling this function. */ +static void mali_pm_reset_dvfs_utilisation_unlocked(struct mali_device *mdev, ktime_t now) +{ + /* Store previous value */ + mdev->mali_metrics.prev_idle = mdev->mali_metrics.time_idle; + mdev->mali_metrics.prev_busy = mdev->mali_metrics.time_busy; + + /* Reset current values */ + mdev->mali_metrics.time_period_start = now; + mdev->mali_metrics.time_period_start_gp = now; + mdev->mali_metrics.time_period_start_pp = now; + mdev->mali_metrics.time_idle = 0; + mdev->mali_metrics.time_busy = 0; + + mdev->mali_metrics.time_busy_gp = 0; + mdev->mali_metrics.time_idle_gp = 0; + mdev->mali_metrics.time_busy_pp[0] = 0; + mdev->mali_metrics.time_idle_pp[0] = 0; +} + +void mali_pm_reset_dvfs_utilisation(struct mali_device *mdev) +{ + _mali_osk_spinlock_irq_lock(mdev->mali_metrics.lock); + mali_pm_reset_dvfs_utilisation_unlocked(mdev, ktime_get()); + _mali_osk_spinlock_irq_unlock(mdev->mali_metrics.lock); +} + +void mali_pm_get_dvfs_utilisation(struct mali_device *mdev, + unsigned long *total_out, unsigned long *busy_out) +{ + ktime_t now = ktime_get(); + u64 busy = 0; + u64 total = 0; + + _mali_osk_spinlock_irq_lock(mdev->mali_metrics.lock); + + mali_pm_get_dvfs_utilisation_calc(mdev, now); + + busy = mdev->mali_metrics.time_busy; + total = busy + mdev->mali_metrics.time_idle; + + /* Reset stats if older than MALI_UTILIZATION_MAX_PERIOD (default + * 100ms) */ + if (total >= MALI_UTILIZATION_MAX_PERIOD) { + mali_pm_reset_dvfs_utilisation_unlocked(mdev, now); + } else if (total < (MALI_UTILIZATION_MAX_PERIOD / 2)) { + total += mdev->mali_metrics.prev_idle + + mdev->mali_metrics.prev_busy; + busy += mdev->mali_metrics.prev_busy; + } + + *total_out = (unsigned long)total; + *busy_out = (unsigned long)busy; + _mali_osk_spinlock_irq_unlock(mdev->mali_metrics.lock); +} + +void mali_pm_metrics_spin_lock(void) +{ + struct mali_device *mdev = dev_get_drvdata(&mali_platform_device->dev); + _mali_osk_spinlock_irq_lock(mdev->mali_metrics.lock); +} + +void mali_pm_metrics_spin_unlock(void) +{ + struct mali_device *mdev = dev_get_drvdata(&mali_platform_device->dev); + _mali_osk_spinlock_irq_unlock(mdev->mali_metrics.lock); +} diff --git a/drivers/gpu/arm/mali400/mali/common/mali_pm_metrics.h b/drivers/gpu/arm/mali400/mali/common/mali_pm_metrics.h new file mode 100644 index 000000000000..256f4484a8a4 --- /dev/null +++ b/drivers/gpu/arm/mali400/mali/common/mali_pm_metrics.h @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2010-2014, 2016 ARM Limited. All rights reserved. + * + * This program is free software and is provided to you under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. + * + * A copy of the licence is included with the program, and can also be obtained from Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef __MALI_PM_METRICS_H__ +#define __MALI_PM_METRICS_H__ + +#ifdef CONFIG_MALI_DEVFREQ +#include "mali_osk_locks.h" +#include "mali_group.h" + +struct mali_device; + +/** + * Metrics data collected for use by the power management framework. + */ +struct mali_pm_metrics_data { + ktime_t time_period_start; + u64 time_busy; + u64 time_idle; + u64 prev_busy; + u64 prev_idle; + u32 num_running_gp_cores; + u32 num_running_pp_cores; + ktime_t time_period_start_gp; + u64 time_busy_gp; + u64 time_idle_gp; + ktime_t time_period_start_pp; + u64 time_busy_pp[MALI_MAX_NUMBER_OF_PHYSICAL_PP_GROUPS]; + u64 time_idle_pp[MALI_MAX_NUMBER_OF_PHYSICAL_PP_GROUPS]; + mali_bool gpu_active; + _mali_osk_spinlock_irq_t *lock; +}; + +/** + * Initialize/start the Mali GPU pm_metrics metrics reporting. + * + * @return _MALI_OSK_ERR_OK on success, otherwise failure. + */ +_mali_osk_errcode_t mali_pm_metrics_init(struct mali_device *mdev); + +/** + * Terminate the Mali GPU pm_metrics metrics reporting + */ +void mali_pm_metrics_term(struct mali_device *mdev); + +/** + * Should be called when a job is about to execute a GPU job + */ +void mali_pm_record_gpu_active(mali_bool is_gp); + +/** + * Should be called when a job is finished + */ +void mali_pm_record_gpu_idle(mali_bool is_gp); + +void mali_pm_reset_dvfs_utilisation(struct mali_device *mdev); + +void mali_pm_get_dvfs_utilisation(struct mali_device *mdev, unsigned long *total_out, unsigned long *busy_out); + +void mali_pm_metrics_spin_lock(void); + +void mali_pm_metrics_spin_unlock(void); +#else +void mali_pm_record_gpu_idle(mali_bool is_gp) {} +void mali_pm_record_gpu_active(mali_bool is_gp) {} +#endif +#endif /* __MALI_PM_METRICS_H__ */ diff --git a/drivers/gpu/arm/mali400/mali/common/mali_pmu.c b/drivers/gpu/arm/mali400/mali/common/mali_pmu.c index 2a3008a6dd83..bf0d41351599 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_pmu.c +++ b/drivers/gpu/arm/mali400/mali/common/mali_pmu.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/common/mali_pmu.h b/drivers/gpu/arm/mali400/mali/common/mali_pmu.h index 5ca78795f535..36ff58ea2d9f 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_pmu.h +++ b/drivers/gpu/arm/mali400/mali/common/mali_pmu.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/common/mali_pp.c b/drivers/gpu/arm/mali400/mali/common/mali_pp.c index 68bfd50bf9ae..fb890a7d3ee9 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_pp.c +++ b/drivers/gpu/arm/mali400/mali/common/mali_pp.c @@ -15,6 +15,8 @@ #include "regs/mali_200_regs.h" #include "mali_kernel_common.h" #include "mali_kernel_core.h" +#include "mali_osk_mali.h" + #if defined(CONFIG_MALI400_PROFILING) #include "mali_osk_profiling.h" #endif @@ -296,6 +298,13 @@ void mali_pp_job_start(struct mali_pp_core *core, struct mali_pp_job *job, u32 s MALI_DEBUG_ASSERT_POINTER(core); + /* Change gpu secure mode if needed. */ + if (MALI_TRUE == mali_pp_job_is_protected_job(job) && MALI_FALSE == _mali_osk_gpu_secure_mode_is_enabled()) { + _mali_osk_gpu_secure_mode_enable(); + } else if (MALI_FALSE == mali_pp_job_is_protected_job(job) && MALI_TRUE == _mali_osk_gpu_secure_mode_is_enabled()) { + _mali_osk_gpu_secure_mode_disable(); + } + /* Write frame registers */ /* diff --git a/drivers/gpu/arm/mali400/mali/common/mali_pp.h b/drivers/gpu/arm/mali400/mali/common/mali_pp.h index 45712a30e831..76f5bd0bedf6 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_pp.h +++ b/drivers/gpu/arm/mali400/mali/common/mali_pp.h @@ -93,6 +93,7 @@ MALI_STATIC_INLINE enum mali_interrupt_result mali_pp_get_interrupt_result(struc } else if (MALI200_REG_VAL_IRQ_END_OF_FRAME == rawstat_used) { return MALI_INTERRUPT_RESULT_SUCCESS; } + return MALI_INTERRUPT_RESULT_ERROR; } diff --git a/drivers/gpu/arm/mali400/mali/common/mali_pp_job.c b/drivers/gpu/arm/mali400/mali/common/mali_pp_job.c index 5528360841af..27349c9ca8d3 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_pp_job.c +++ b/drivers/gpu/arm/mali400/mali/common/mali_pp_job.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2015 ARM Limited. All rights reserved. + * Copyright (C) 2011-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/common/mali_pp_job.h b/drivers/gpu/arm/mali400/mali/common/mali_pp_job.h index 7b9d2efa3019..d033fa331415 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_pp_job.h +++ b/drivers/gpu/arm/mali400/mali/common/mali_pp_job.h @@ -495,6 +495,13 @@ MALI_STATIC_INLINE mali_bool mali_pp_job_is_window_surface( ? MALI_TRUE : MALI_FALSE; } +MALI_STATIC_INLINE mali_bool mali_pp_job_is_protected_job(struct mali_pp_job *job) +{ + MALI_DEBUG_ASSERT_POINTER(job); + return (job->uargs.flags & _MALI_PP_JOB_FLAG_PROTECTED) + ? MALI_TRUE : MALI_FALSE; +} + MALI_STATIC_INLINE u32 mali_pp_job_get_perf_counter_flag(struct mali_pp_job *job) { MALI_DEBUG_ASSERT_POINTER(job); diff --git a/drivers/gpu/arm/mali400/mali/common/mali_scheduler.c b/drivers/gpu/arm/mali400/mali/common/mali_scheduler.c index 5547159db94c..a4136ce1130e 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_scheduler.c +++ b/drivers/gpu/arm/mali400/mali/common/mali_scheduler.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012-2015 ARM Limited. All rights reserved. + * Copyright (C) 2012-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. @@ -20,7 +20,7 @@ #include "mali_group.h" #include #include - +#include "mali_pm_metrics.h" #if defined(CONFIG_DMA_SHARED_BUFFER) #include "mali_memory_dma_buf.h" @@ -191,7 +191,7 @@ void mali_scheduler_terminate(void) _mali_osk_atomic_term(&mali_job_id_autonumber); } -u32 mali_scheduler_job_physical_head_count(void) +u32 mali_scheduler_job_physical_head_count(mali_bool gpu_mode_is_secure) { /* * Count how many physical sub jobs are present from the head of queue @@ -216,16 +216,23 @@ u32 mali_scheduler_job_physical_head_count(void) * Remember; virtual jobs can't be queued and started * at the same time, so this must be a physical job */ - count += mali_pp_job_unstarted_sub_job_count(job); - if (MALI_MAX_NUMBER_OF_PHYSICAL_PP_GROUPS <= count) { - return MALI_MAX_NUMBER_OF_PHYSICAL_PP_GROUPS; + if ((MALI_FALSE == gpu_mode_is_secure && MALI_FALSE == mali_pp_job_is_protected_job(job)) + || (MALI_TRUE == gpu_mode_is_secure && MALI_TRUE == mali_pp_job_is_protected_job(job))) { + + count += mali_pp_job_unstarted_sub_job_count(job); + if (MALI_MAX_NUMBER_OF_PHYSICAL_PP_GROUPS <= count) { + return MALI_MAX_NUMBER_OF_PHYSICAL_PP_GROUPS; + } } } } _MALI_OSK_LIST_FOREACHENTRY(job, temp, &job_queue_pp.high_pri, struct mali_pp_job, list) { - if (MALI_FALSE == mali_pp_job_is_virtual(job)) { + if ((MALI_FALSE == mali_pp_job_is_virtual(job)) + && ((MALI_FALSE == gpu_mode_is_secure && MALI_FALSE == mali_pp_job_is_protected_job(job)) + || (MALI_TRUE == gpu_mode_is_secure && MALI_TRUE == mali_pp_job_is_protected_job(job)))) { + count += mali_pp_job_unstarted_sub_job_count(job); if (MALI_MAX_NUMBER_OF_PHYSICAL_PP_GROUPS <= count) { return MALI_MAX_NUMBER_OF_PHYSICAL_PP_GROUPS; @@ -238,24 +245,57 @@ u32 mali_scheduler_job_physical_head_count(void) _MALI_OSK_LIST_FOREACHENTRY(job, temp, &job_queue_pp.normal_pri, struct mali_pp_job, list) { - if (MALI_FALSE == mali_pp_job_is_virtual(job)) { - /* any partially started is already counted */ - if (MALI_FALSE == mali_pp_job_has_started_sub_jobs(job)) { - count += mali_pp_job_unstarted_sub_job_count(job); - if (MALI_MAX_NUMBER_OF_PHYSICAL_PP_GROUPS <= - count) { - return MALI_MAX_NUMBER_OF_PHYSICAL_PP_GROUPS; - } + if ((MALI_FALSE == mali_pp_job_is_virtual(job)) + && (MALI_FALSE == mali_pp_job_has_started_sub_jobs(job)) + && ((MALI_FALSE == gpu_mode_is_secure && MALI_FALSE == mali_pp_job_is_protected_job(job)) + || (MALI_TRUE == gpu_mode_is_secure && MALI_TRUE == mali_pp_job_is_protected_job(job)))) { + + count += mali_pp_job_unstarted_sub_job_count(job); + if (MALI_MAX_NUMBER_OF_PHYSICAL_PP_GROUPS <= count) { + return MALI_MAX_NUMBER_OF_PHYSICAL_PP_GROUPS; } } else { /* Came across a virtual job, so stop counting */ return count; } } - return count; } +struct mali_pp_job *mali_scheduler_job_pp_next(void) +{ + struct mali_pp_job *job; + struct mali_pp_job *temp; + + MALI_DEBUG_ASSERT_LOCK_HELD(mali_scheduler_lock_obj); + + /* Check for partially started normal pri jobs */ + if (!_mali_osk_list_empty(&job_queue_pp.normal_pri)) { + MALI_DEBUG_ASSERT(0 < job_queue_pp.depth); + + job = _MALI_OSK_LIST_ENTRY(job_queue_pp.normal_pri.next, + struct mali_pp_job, list); + + MALI_DEBUG_ASSERT_POINTER(job); + + if (MALI_TRUE == mali_pp_job_has_started_sub_jobs(job)) { + return job; + } + } + + _MALI_OSK_LIST_FOREACHENTRY(job, temp, &job_queue_pp.high_pri, + struct mali_pp_job, list) { + return job; + } + + _MALI_OSK_LIST_FOREACHENTRY(job, temp, &job_queue_pp.normal_pri, + struct mali_pp_job, list) { + return job; + } + + return NULL; +} + mali_bool mali_scheduler_job_next_is_virtual(void) { struct mali_pp_job *job; @@ -534,6 +574,7 @@ void mali_scheduler_complete_gp_job(struct mali_gp_job *job, if (mali_utilization_enabled()) { mali_utilization_gp_end(); } + mali_pm_record_gpu_idle(MALI_TRUE); } mali_gp_job_delete(job); @@ -561,6 +602,7 @@ void mali_scheduler_complete_pp_job(struct mali_pp_job *job, if (mali_utilization_enabled()) { mali_utilization_pp_end(); } + mali_pm_record_gpu_idle(MALI_FALSE); } /* With ZRAM feature enabled, all pp jobs will be force to use deferred delete. */ @@ -987,6 +1029,8 @@ static mali_bool mali_scheduler_queue_gp_job(struct mali_gp_job *job) mali_utilization_gp_start(); } + mali_pm_record_gpu_active(MALI_TRUE); + /* Add profiling events for job enqueued */ _mali_osk_profiling_add_event( MALI_PROFILING_EVENT_TYPE_SINGLE | @@ -1062,8 +1106,9 @@ static mali_bool mali_scheduler_queue_pp_job(struct mali_pp_job *job) mali_utilization_pp_start(); } - /* Add profiling events for job enqueued */ + mali_pm_record_gpu_active(MALI_FALSE); + /* Add profiling events for job enqueued */ _mali_osk_profiling_add_event( MALI_PROFILING_EVENT_TYPE_SINGLE | MALI_PROFILING_EVENT_CHANNEL_SOFTWARE | diff --git a/drivers/gpu/arm/mali400/mali/common/mali_scheduler.h b/drivers/gpu/arm/mali400/mali/common/mali_scheduler.h index f24cf42b8a79..0ab91776654f 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_scheduler.h +++ b/drivers/gpu/arm/mali400/mali/common/mali_scheduler.h @@ -60,9 +60,10 @@ MALI_STATIC_INLINE u32 mali_scheduler_job_gp_big_job_count(void) return job_queue_gp.big_job_num; } -u32 mali_scheduler_job_physical_head_count(void); +u32 mali_scheduler_job_physical_head_count(mali_bool gpu_mode_is_secure); mali_bool mali_scheduler_job_next_is_virtual(void); +struct mali_pp_job *mali_scheduler_job_pp_next(void); struct mali_gp_job *mali_scheduler_job_gp_get(void); struct mali_pp_job *mali_scheduler_job_pp_physical_peek(void); diff --git a/drivers/gpu/arm/mali400/mali/common/mali_scheduler_types.h b/drivers/gpu/arm/mali400/mali/common/mali_scheduler_types.h index f862961d146e..0819c590b4d2 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_scheduler_types.h +++ b/drivers/gpu/arm/mali400/mali/common/mali_scheduler_types.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013-2015 ARM Limited. All rights reserved. + * Copyright (C) 2013-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/common/mali_session.c b/drivers/gpu/arm/mali400/mali/common/mali_session.c index e0a2805b13d3..1b409619a639 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_session.c +++ b/drivers/gpu/arm/mali400/mali/common/mali_session.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012-2015 ARM Limited. All rights reserved. + * Copyright (C) 2012-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. @@ -116,20 +116,20 @@ void mali_session_memory_tracking(_mali_osk_print_ctx *print_ctx) _mali_osk_ctxprintf(print_ctx, " %-25s %-10u %-10u %-15u %-15u %-10u %-10u %-10u\n", session->comm, session->pid, (atomic_read(&session->mali_mem_allocated_pages)) * _MALI_OSK_MALI_PAGE_SIZE, - session->max_mali_mem_allocated_size, - (atomic_read(&session->mali_mem_array[MALI_MEM_EXTERNAL])) * _MALI_OSK_MALI_PAGE_SIZE, - (atomic_read(&session->mali_mem_array[MALI_MEM_UMP])) * _MALI_OSK_MALI_PAGE_SIZE, - (atomic_read(&session->mali_mem_array[MALI_MEM_DMA_BUF])) * _MALI_OSK_MALI_PAGE_SIZE, - (atomic_read(&session->mali_mem_array[MALI_MEM_SWAP])) * _MALI_OSK_MALI_PAGE_SIZE + (unsigned int)session->max_mali_mem_allocated_size, + (unsigned int)((atomic_read(&session->mali_mem_array[MALI_MEM_EXTERNAL])) * _MALI_OSK_MALI_PAGE_SIZE), + (unsigned int)((atomic_read(&session->mali_mem_array[MALI_MEM_UMP])) * _MALI_OSK_MALI_PAGE_SIZE), + (unsigned int)((atomic_read(&session->mali_mem_array[MALI_MEM_DMA_BUF])) * _MALI_OSK_MALI_PAGE_SIZE), + (unsigned int)((atomic_read(&session->mali_mem_array[MALI_MEM_SWAP])) * _MALI_OSK_MALI_PAGE_SIZE) ); #else _mali_osk_ctxprintf(print_ctx, " %-25s %-10u %-10u %-15u %-15u %-10u %-10u \n", session->comm, session->pid, - (atomic_read(&session->mali_mem_allocated_pages)) * _MALI_OSK_MALI_PAGE_SIZE, - session->max_mali_mem_allocated_size, - (atomic_read(&session->mali_mem_array[MALI_MEM_EXTERNAL])) * _MALI_OSK_MALI_PAGE_SIZE, - (atomic_read(&session->mali_mem_array[MALI_MEM_UMP])) * _MALI_OSK_MALI_PAGE_SIZE, - (atomic_read(&session->mali_mem_array[MALI_MEM_DMA_BUF])) * _MALI_OSK_MALI_PAGE_SIZE + (unsigned int)((atomic_read(&session->mali_mem_allocated_pages)) * _MALI_OSK_MALI_PAGE_SIZE), + (unsigned int)session->max_mali_mem_allocated_size, + (unsigned int)((atomic_read(&session->mali_mem_array[MALI_MEM_EXTERNAL])) * _MALI_OSK_MALI_PAGE_SIZE), + (unsigned int)((atomic_read(&session->mali_mem_array[MALI_MEM_UMP])) * _MALI_OSK_MALI_PAGE_SIZE), + (unsigned int)((atomic_read(&session->mali_mem_array[MALI_MEM_DMA_BUF])) * _MALI_OSK_MALI_PAGE_SIZE) ); #endif } diff --git a/drivers/gpu/arm/mali400/mali/common/mali_soft_job.c b/drivers/gpu/arm/mali400/mali/common/mali_soft_job.c index 36ac982e1df0..c76d1fef1ea7 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_soft_job.c +++ b/drivers/gpu/arm/mali400/mali/common/mali_soft_job.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013-2015 ARM Limited. All rights reserved. + * Copyright (C) 2013-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/common/mali_soft_job.h b/drivers/gpu/arm/mali400/mali/common/mali_soft_job.h index f35394e60384..4dd05897b2e0 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_soft_job.h +++ b/drivers/gpu/arm/mali400/mali/common/mali_soft_job.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013-2015 ARM Limited. All rights reserved. + * Copyright (C) 2013-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/common/mali_spinlock_reentrant.c b/drivers/gpu/arm/mali400/mali/common/mali_spinlock_reentrant.c index 178abaf43ba1..28e2e1711277 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_spinlock_reentrant.c +++ b/drivers/gpu/arm/mali400/mali/common/mali_spinlock_reentrant.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013, 2015 ARM Limited. All rights reserved. + * Copyright (C) 2013, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/common/mali_spinlock_reentrant.h b/drivers/gpu/arm/mali400/mali/common/mali_spinlock_reentrant.h index 6a62df850b2f..793875a0e7ed 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_spinlock_reentrant.h +++ b/drivers/gpu/arm/mali400/mali/common/mali_spinlock_reentrant.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013, 2015 ARM Limited. All rights reserved. + * Copyright (C) 2013, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/common/mali_timeline.c b/drivers/gpu/arm/mali400/mali/common/mali_timeline.c index dccc30348002..998ff5b9bb0f 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_timeline.c +++ b/drivers/gpu/arm/mali400/mali/common/mali_timeline.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013-2015 ARM Limited. All rights reserved. + * Copyright (C) 2013-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. @@ -1460,11 +1460,11 @@ void mali_timeline_debug_print_tracker(struct mali_timeline_tracker *tracker, _m is_waiting_on_timeline(tracker, MALI_TIMELINE_GP) ? "WaitGP" : " ", tracker->fence.points[0], is_waiting_on_timeline(tracker, MALI_TIMELINE_PP) ? "WaitPP" : " ", tracker->fence.points[1], is_waiting_on_timeline(tracker, MALI_TIMELINE_SOFT) ? "WaitSOFT" : " ", tracker->fence.points[2], - tracker->fence.sync_fd, tracker->sync_fence, tracker->job); + tracker->fence.sync_fd, (unsigned int)(uintptr_t)(tracker->sync_fence), (unsigned int)(uintptr_t)(tracker->job)); } else { _mali_osk_ctxprintf(print_ctx, "TL: %s %u %c fd:%d fence:(0x%08X) job:(0x%08X)\n", tracker_type, tracker->point, state_char, - tracker->fence.sync_fd, tracker->sync_fence, tracker->job); + tracker->fence.sync_fd, (unsigned int)(uintptr_t)(tracker->sync_fence), (unsigned int)(uintptr_t)(tracker->job)); } #else if (0 != tracker->trigger_ref_count) { @@ -1473,11 +1473,11 @@ void mali_timeline_debug_print_tracker(struct mali_timeline_tracker *tracker, _m is_waiting_on_timeline(tracker, MALI_TIMELINE_GP) ? "WaitGP" : " ", tracker->fence.points[0], is_waiting_on_timeline(tracker, MALI_TIMELINE_PP) ? "WaitPP" : " ", tracker->fence.points[1], is_waiting_on_timeline(tracker, MALI_TIMELINE_SOFT) ? "WaitSOFT" : " ", tracker->fence.points[2], - tracker->job); + (unsigned int)(uintptr_t)(tracker->job)); } else { _mali_osk_ctxprintf(print_ctx, "TL: %s %u %c job:(0x%08X)\n", tracker_type, tracker->point, state_char, - tracker->job); + (unsigned int)(uintptr_t)(tracker->job)); } #endif } diff --git a/drivers/gpu/arm/mali400/mali/common/mali_timeline.h b/drivers/gpu/arm/mali400/mali/common/mali_timeline.h index 58d83839f4fe..268676a6f2fa 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_timeline.h +++ b/drivers/gpu/arm/mali400/mali/common/mali_timeline.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013-2015 ARM Limited. All rights reserved. + * Copyright (C) 2013-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/common/mali_timeline_fence_wait.c b/drivers/gpu/arm/mali400/mali/common/mali_timeline_fence_wait.c index 3c58928dd3a2..1f5d42172c9f 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_timeline_fence_wait.c +++ b/drivers/gpu/arm/mali400/mali/common/mali_timeline_fence_wait.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013-2015 ARM Limited. All rights reserved. + * Copyright (C) 2013-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/common/mali_timeline_fence_wait.h b/drivers/gpu/arm/mali400/mali/common/mali_timeline_fence_wait.h index f5440ab6fc6d..348652b4446a 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_timeline_fence_wait.h +++ b/drivers/gpu/arm/mali400/mali/common/mali_timeline_fence_wait.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013, 2015 ARM Limited. All rights reserved. + * Copyright (C) 2013, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/common/mali_timeline_sync_fence.c b/drivers/gpu/arm/mali400/mali/common/mali_timeline_sync_fence.c index 73843f07c990..a83252b7f846 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_timeline_sync_fence.c +++ b/drivers/gpu/arm/mali400/mali/common/mali_timeline_sync_fence.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013, 2015 ARM Limited. All rights reserved. + * Copyright (C) 2013, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/common/mali_timeline_sync_fence.h b/drivers/gpu/arm/mali400/mali/common/mali_timeline_sync_fence.h index 29a3822457e9..6662b25b17be 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_timeline_sync_fence.h +++ b/drivers/gpu/arm/mali400/mali/common/mali_timeline_sync_fence.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013, 2015 ARM Limited. All rights reserved. + * Copyright (C) 2013, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/common/mali_ukk.h b/drivers/gpu/arm/mali400/mali/common/mali_ukk.h index 597685a53f3b..79829b9d891e 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_ukk.h +++ b/drivers/gpu/arm/mali400/mali/common/mali_ukk.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/common/mali_user_settings_db.c b/drivers/gpu/arm/mali400/mali/common/mali_user_settings_db.c index 54e1580fad1a..a1a613fde3a9 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_user_settings_db.c +++ b/drivers/gpu/arm/mali400/mali/common/mali_user_settings_db.c @@ -1,5 +1,5 @@ /** - * Copyright (C) 2012-2015 ARM Limited. All rights reserved. + * Copyright (C) 2012-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/common/mali_user_settings_db.h b/drivers/gpu/arm/mali400/mali/common/mali_user_settings_db.h index 0732c3e56e2a..6828dc7b30d5 100755 --- a/drivers/gpu/arm/mali400/mali/common/mali_user_settings_db.h +++ b/drivers/gpu/arm/mali400/mali/common/mali_user_settings_db.h @@ -1,5 +1,5 @@ /** - * Copyright (C) 2012-2013, 2015 ARM Limited. All rights reserved. + * Copyright (C) 2012-2013, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/include/linux/mali/mali_utgard.h b/drivers/gpu/arm/mali400/mali/include/linux/mali/mali_utgard.h index 4ea02fe65cb5..a2416a5724a7 100755 --- a/drivers/gpu/arm/mali400/mali/include/linux/mali/mali_utgard.h +++ b/drivers/gpu/arm/mali400/mali/include/linux/mali/mali_utgard.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012-2015 ARM Limited. All rights reserved. + * Copyright (C) 2012-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. @@ -17,6 +17,13 @@ #define __MALI_UTGARD_H__ #include "mali_osk_types.h" +#ifdef CONFIG_MALI_DEVFREQ +#include +#include "mali_pm_metrics.h" +#ifdef CONFIG_DEVFREQ_THERMAL +#include +#endif +#endif #define MALI_GPU_NAME_UTGARD "mali-utgard" @@ -480,6 +487,18 @@ void (*get_clock_info)(struct mali_gpu_clock **data); /* Function that get the current clock info, needed when CONFIG_MALI_DVFS enabled */ int (*get_freq)(void); + /* Function that init the mali gpu secure mode */ + int (*secure_mode_init)(void); + /* Function that deinit the mali gpu secure mode */ + void (*secure_mode_deinit)(void); + /* Function that enable the mali gpu secure mode */ + int (*secure_mode_enable)(void); + /* Function that disable the mali gpu secure mode */ + int (*secure_mode_disable)(void); + /* ipa related interface customer need register */ +#if defined(CONFIG_MALI_DEVFREQ) && defined(CONFIG_DEVFREQ_THERMAL) + struct devfreq_cooling_power *gpu_cooling_ops; +#endif }; /** diff --git a/drivers/gpu/arm/mali400/mali/include/linux/mali/mali_utgard_ioctl.h b/drivers/gpu/arm/mali400/mali/include/linux/mali/mali_utgard_ioctl.h index e8b96e271218..ea781903ca79 100755 --- a/drivers/gpu/arm/mali400/mali/include/linux/mali/mali_utgard_ioctl.h +++ b/drivers/gpu/arm/mali400/mali/include/linux/mali/mali_utgard_ioctl.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/include/linux/mali/mali_utgard_profiling_events.h b/drivers/gpu/arm/mali400/mali/include/linux/mali/mali_utgard_profiling_events.h index 279bf8ee38a4..eea6dac92dd0 100755 --- a/drivers/gpu/arm/mali400/mali/include/linux/mali/mali_utgard_profiling_events.h +++ b/drivers/gpu/arm/mali400/mali/include/linux/mali/mali_utgard_profiling_events.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. @@ -18,6 +18,7 @@ * If you do not wish to do so, delete this exception statement from your version. */ + #ifndef _MALI_UTGARD_PROFILING_EVENTS_H_ #define _MALI_UTGARD_PROFILING_EVENTS_H_ diff --git a/drivers/gpu/arm/mali400/mali/include/linux/mali/mali_utgard_profiling_gator_api.h b/drivers/gpu/arm/mali400/mali/include/linux/mali/mali_utgard_profiling_gator_api.h index b922187a0b88..c82d8b1557b6 100755 --- a/drivers/gpu/arm/mali400/mali/include/linux/mali/mali_utgard_profiling_gator_api.h +++ b/drivers/gpu/arm/mali400/mali/include/linux/mali/mali_utgard_profiling_gator_api.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013, 2015 ARM Limited. All rights reserved. + * Copyright (C) 2013, 2015-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/include/linux/mali/mali_utgard_uk_types.h b/drivers/gpu/arm/mali400/mali/include/linux/mali/mali_utgard_uk_types.h index 071585b34c95..a3ac3a51711d 100755 --- a/drivers/gpu/arm/mali400/mali/include/linux/mali/mali_utgard_uk_types.h +++ b/drivers/gpu/arm/mali400/mali/include/linux/mali/mali_utgard_uk_types.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. @@ -283,8 +283,8 @@ typedef struct { _mali_uk_fence_t fence; /**< [in] fence this job must wait on */ u64 timeline_point_ptr; /**< [in,out] pointer to u32: location where point on gp timeline for this job will be written */ u32 varying_memsize; /** < [in] size of varying memory to use deffer bind*/ - u32 varying_alloc_num; - u64 varying_alloc_list; /** < [in] memory hanlde list of varying buffer to use deffer bind */ + u32 deferred_mem_num; + u64 deferred_mem_list; /** < [in] memory hanlde list of varying buffer to use deffer bind */ } _mali_uk_gp_start_job_s; #define _MALI_PERFORMANCE_COUNTER_FLAG_SRC0_ENABLE (1<<0) /**< Enable performance counter SRC0 for a job */ @@ -324,6 +324,7 @@ typedef struct { /** Flag for _mali_uk_pp_start_job_s */ #define _MALI_PP_JOB_FLAG_NO_NOTIFICATION (1<<0) #define _MALI_PP_JOB_FLAG_IS_WINDOW_SURFACE (1<<1) +#define _MALI_PP_JOB_FLAG_PROTECTED (1<<2) /** @defgroup _mali_uk_ppstartjob_s Fragment Processor Start Job * @{ */ @@ -664,7 +665,7 @@ typedef struct { * The 16bit integer is stored twice in a 32bit integer * For example, for version 1 the value would be 0x00010001 */ -#define _MALI_API_VERSION 850 +#define _MALI_API_VERSION 900 #define _MALI_UK_API_VERSION _MAKE_VERSION_ID(_MALI_API_VERSION) /** @@ -770,6 +771,7 @@ typedef struct { #define _MALI_MEMORY_ALLOCATE_NO_BIND_GPU (1<<5) /*Not map to GPU when allocate, must call bind later*/ #define _MALI_MEMORY_ALLOCATE_SWAPPABLE (1<<6) /* Allocate swappale memory. */ #define _MALI_MEMORY_ALLOCATE_DEFER_BIND (1<<7) /*Not map to GPU when allocate, must call bind later*/ +#define _MALI_MEMORY_ALLOCATE_SECURE (1<<8) /* Allocate secure memory. */ typedef struct { @@ -779,6 +781,7 @@ typedef struct { u32 psize; /**< [in] physical size of the allocation */ u32 flags; u64 backend_handle; /**< [out] backend handle */ + s32 secure_shared_fd; /** < [in] the mem handle for secure mem */ struct { /* buffer types*/ /* CPU read/write info*/ diff --git a/drivers/gpu/arm/mali400/mali/linux/license/gpl/mali_kernel_license.h b/drivers/gpu/arm/mali400/mali/linux/license/gpl/mali_kernel_license.h index c88c992e859b..264555dda2cf 100755 --- a/drivers/gpu/arm/mali400/mali/linux/license/gpl/mali_kernel_license.h +++ b/drivers/gpu/arm/mali400/mali/linux/license/gpl/mali_kernel_license.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010, 2013, 2015 ARM Limited. All rights reserved. + * Copyright (C) 2010, 2013, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_devfreq.c b/drivers/gpu/arm/mali400/mali/linux/mali_devfreq.c new file mode 100644 index 000000000000..0b0ba1481eed --- /dev/null +++ b/drivers/gpu/arm/mali400/mali/linux/mali_devfreq.c @@ -0,0 +1,310 @@ +/* + * Copyright (C) 2011-2016 ARM Limited. All rights reserved. + * + * This program is free software and is provided to you under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. + * + * A copy of the licence is included with the program, and can also be obtained from Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "mali_osk_mali.h" +#include "mali_kernel_common.h" + +#include +#include +#include +#include +#ifdef CONFIG_DEVFREQ_THERMAL +#include +#endif + +#include +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0) +#include +#else /* Linux >= 3.13 */ +/* In 3.13 the OPP include header file, types, and functions were all + * renamed. Use the old filename for the include, and define the new names to + * the old, when an old kernel is detected. + */ +#include +#define dev_pm_opp opp +#define dev_pm_opp_get_voltage opp_get_voltage +#define dev_pm_opp_get_opp_count opp_get_opp_count +#define dev_pm_opp_find_freq_ceil opp_find_freq_ceil +#endif /* Linux >= 3.13 */ + +#include "mali_pm_metrics.h" + +static int +mali_devfreq_target(struct device *dev, unsigned long *target_freq, u32 flags) +{ + struct mali_device *mdev = dev_get_drvdata(dev); + struct dev_pm_opp *opp; + unsigned long freq = 0; + unsigned long voltage; + int err; + + freq = *target_freq; + + rcu_read_lock(); + opp = devfreq_recommended_opp(dev, &freq, flags); + voltage = dev_pm_opp_get_voltage(opp); + rcu_read_unlock(); + if (IS_ERR_OR_NULL(opp)) { + MALI_PRINT_ERROR(("Failed to get opp (%ld)\n", PTR_ERR(opp))); + return PTR_ERR(opp); + } + + MALI_DEBUG_PRINT(2, ("mali_devfreq_target:set_freq = %lld flags = 0x%x\n", freq, flags)); + /* + * Only update if there is a change of frequency + */ + if (mdev->current_freq == freq) { + *target_freq = freq; + mali_pm_reset_dvfs_utilisation(mdev); + return 0; + } + +#ifdef CONFIG_REGULATOR + if (mdev->regulator && mdev->current_voltage != voltage + && mdev->current_freq < freq) { + err = regulator_set_voltage(mdev->regulator, voltage, voltage); + if (err) { + MALI_PRINT_ERROR(("Failed to increase voltage (%d)\n", err)); + return err; + } + } +#endif + + err = clk_set_rate(mdev->clock, freq); + if (err) { + MALI_PRINT_ERROR(("Failed to set clock %lu (target %lu)\n", freq, *target_freq)); + return err; + } + +#ifdef CONFIG_REGULATOR + if (mdev->regulator && mdev->current_voltage != voltage + && mdev->current_freq > freq) { + err = regulator_set_voltage(mdev->regulator, voltage, voltage); + if (err) { + MALI_PRINT_ERROR(("Failed to decrease voltage (%d)\n", err)); + return err; + } + } +#endif + + *target_freq = freq; + mdev->current_voltage = voltage; + mdev->current_freq = freq; + + mali_pm_reset_dvfs_utilisation(mdev); + + return err; +} + +static int +mali_devfreq_cur_freq(struct device *dev, unsigned long *freq) +{ + struct mali_device *mdev = dev_get_drvdata(dev); + + *freq = mdev->current_freq; + + MALI_DEBUG_PRINT(2, ("mali_devfreq_cur_freq: freq = %d \n", *freq)); + return 0; +} + +static int +mali_devfreq_status(struct device *dev, struct devfreq_dev_status *stat) +{ + struct mali_device *mdev = dev_get_drvdata(dev); + + stat->current_frequency = mdev->current_freq; + + mali_pm_get_dvfs_utilisation(mdev, + &stat->total_time, &stat->busy_time); + + stat->private_data = NULL; + +#ifdef CONFIG_DEVFREQ_THERMAL + memcpy(&mdev->devfreq->last_status, stat, sizeof(*stat)); +#endif + + return 0; +} + +/* setup platform specific opp in platform.c*/ +int __weak setup_opps(void) +{ + return 0; +} + +/* term platform specific opp in platform.c*/ +int __weak term_opps(struct device *dev) +{ + return 0; +} + +static int mali_devfreq_init_freq_table(struct mali_device *mdev, + struct devfreq_dev_profile *dp) +{ + int err, count; + int i = 0; + unsigned long freq = 0; + struct dev_pm_opp *opp; + + err = setup_opps(); + if (err) + return err; + + rcu_read_lock(); + count = dev_pm_opp_get_opp_count(mdev->dev); + if (count < 0) { + rcu_read_unlock(); + return count; + } + rcu_read_unlock(); + + MALI_DEBUG_PRINT(2, ("mali devfreq table count %d\n", count)); + + dp->freq_table = kmalloc_array(count, sizeof(dp->freq_table[0]), + GFP_KERNEL); + if (!dp->freq_table) + return -ENOMEM; + + rcu_read_lock(); + for (i = 0; i < count; i++, freq++) { + opp = dev_pm_opp_find_freq_ceil(mdev->dev, &freq); + if (IS_ERR(opp)) + break; + + dp->freq_table[i] = freq; + MALI_DEBUG_PRINT(2, ("mali devfreq table array[%d] = %d\n", i, freq)); + } + rcu_read_unlock(); + + if (count != i) + MALI_PRINT_ERROR(("Unable to enumerate all OPPs (%d!=%d)\n", + count, i)); + + dp->max_state = i; + + return 0; +} + +static void mali_devfreq_term_freq_table(struct mali_device *mdev) +{ + struct devfreq_dev_profile *dp = mdev->devfreq->profile; + + kfree(dp->freq_table); + term_opps(mdev->dev); +} + +static void mali_devfreq_exit(struct device *dev) +{ + struct mali_device *mdev = dev_get_drvdata(dev); + + mali_devfreq_term_freq_table(mdev); +} + +int mali_devfreq_init(struct mali_device *mdev) +{ +#ifdef CONFIG_DEVFREQ_THERMAL + struct devfreq_cooling_power *callbacks = NULL; + _mali_osk_device_data data; +#endif + struct devfreq_dev_profile *dp; + int err; + + MALI_DEBUG_PRINT(2, ("Init Mali devfreq\n")); + + if (!mdev->clock) + return -ENODEV; + + mdev->current_freq = clk_get_rate(mdev->clock); + + dp = &mdev->devfreq_profile; + + dp->initial_freq = mdev->current_freq; + dp->polling_ms = 100; + dp->target = mali_devfreq_target; + dp->get_dev_status = mali_devfreq_status; + dp->get_cur_freq = mali_devfreq_cur_freq; + dp->exit = mali_devfreq_exit; + + if (mali_devfreq_init_freq_table(mdev, dp)) + return -EFAULT; + + mdev->devfreq = devfreq_add_device(mdev->dev, dp, + "simple_ondemand", NULL); + if (IS_ERR(mdev->devfreq)) { + mali_devfreq_term_freq_table(mdev); + return PTR_ERR(mdev->devfreq); + } + + err = devfreq_register_opp_notifier(mdev->dev, mdev->devfreq); + if (err) { + MALI_PRINT_ERROR(("Failed to register OPP notifier (%d)\n", err)); + goto opp_notifier_failed; + } + +#ifdef CONFIG_DEVFREQ_THERMAL + /* Initilization last_status it will be used when first power allocate called */ + mdev->devfreq->last_status.current_frequency = mdev->current_freq; + + if (_MALI_OSK_ERR_OK == _mali_osk_device_data_get(&data)) { + if (NULL != data.gpu_cooling_ops) { + callbacks = data.gpu_cooling_ops; + MALI_DEBUG_PRINT(2, ("Mali GPU Thermal: Callback handler installed \n")); + } + } + + if (callbacks) { + mdev->devfreq_cooling = of_devfreq_cooling_register_power( + mdev->dev->of_node, + mdev->devfreq, + callbacks); + if (IS_ERR_OR_NULL(mdev->devfreq_cooling)) { + err = PTR_ERR(mdev->devfreq_cooling); + MALI_PRINT_ERROR(("Failed to register cooling device (%d)\n", err)); + goto cooling_failed; + } else { + MALI_DEBUG_PRINT(2, ("Mali GPU Thermal Cooling installed \n")); + } + } +#endif + + return 0; + +#ifdef CONFIG_DEVFREQ_THERMAL +cooling_failed: + devfreq_unregister_opp_notifier(mdev->dev, mdev->devfreq); +#endif /* CONFIG_DEVFREQ_THERMAL */ +opp_notifier_failed: + err = devfreq_remove_device(mdev->devfreq); + if (err) + MALI_PRINT_ERROR(("Failed to terminate devfreq (%d)\n", err)); + else + mdev->devfreq = NULL; + + return err; +} + +void mali_devfreq_term(struct mali_device *mdev) +{ + int err; + + MALI_DEBUG_PRINT(2, ("Term Mali devfreq\n")); + +#ifdef CONFIG_DEVFREQ_THERMAL + devfreq_cooling_unregister(mdev->devfreq_cooling); +#endif + + devfreq_unregister_opp_notifier(mdev->dev, mdev->devfreq); + + err = devfreq_remove_device(mdev->devfreq); + if (err) + MALI_PRINT_ERROR(("Failed to terminate devfreq (%d)\n", err)); + else + mdev->devfreq = NULL; +} diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_devfreq.h b/drivers/gpu/arm/mali400/mali/linux/mali_devfreq.h new file mode 100644 index 000000000000..faf84f251d7d --- /dev/null +++ b/drivers/gpu/arm/mali400/mali/linux/mali_devfreq.h @@ -0,0 +1,17 @@ +/* + * Copyright (C) 2011-2016 ARM Limited. All rights reserved. + * + * This program is free software and is provided to you under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. + * + * A copy of the licence is included with the program, and can also be obtained from Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +#ifndef _MALI_DEVFREQ_H_ +#define _MALI_DEVFREQ_H_ + +int mali_devfreq_init(struct mali_device *mdev); + +void mali_devfreq_term(struct mali_device *mdev); + +#endif diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_device_pause_resume.c b/drivers/gpu/arm/mali400/mali/linux/mali_device_pause_resume.c index 37076a2eaf67..cb2f702f15ae 100755 --- a/drivers/gpu/arm/mali400/mali/linux/mali_device_pause_resume.c +++ b/drivers/gpu/arm/mali400/mali/linux/mali_device_pause_resume.c @@ -1,5 +1,5 @@ /** - * Copyright (C) 2010-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_kernel_linux.c b/drivers/gpu/arm/mali400/mali/linux/mali_kernel_linux.c index ae4fad8d7588..412ea80b637f 100755 --- a/drivers/gpu/arm/mali400/mali/linux/mali_kernel_linux.c +++ b/drivers/gpu/arm/mali400/mali/linux/mali_kernel_linux.c @@ -1,5 +1,5 @@ /** - * Copyright (C) 2010-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. @@ -28,6 +28,8 @@ #include #include #include +#include +#include #include #include "mali_kernel_common.h" @@ -67,6 +69,29 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(mali_hw_counter); EXPORT_TRACEPOINT_SYMBOL_GPL(mali_sw_counters); #endif /* CONFIG_TRACEPOINTS */ +#ifdef CONFIG_MALI_DEVFREQ +#include "mali_devfreq.h" +#include "mali_osk_mali.h" + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0) +#include +#else +/* In 3.13 the OPP include header file, types, and functions were all + * renamed. Use the old filename for the include, and define the new names to + * the old, when an old kernel is detected. + */ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0) +#include +#else +#include +#endif /* Linux >= 3.13*/ +#define dev_pm_opp_of_add_table of_init_opp_table +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0) +#define dev_pm_opp_of_remove_table of_free_opp_table +#endif /* Linux >= 3.19 */ +#endif /* Linux >= 4.4.0 */ +#endif + /* from the __malidrv_build_info.c file that is generated during build */ extern const char *__malidrv_build_info(void); @@ -476,9 +501,24 @@ void mali_module_exit(void) MALI_PRINT(("Mali device driver unloaded\n")); } +#ifdef CONFIG_MALI_DEVFREQ +struct mali_device *mali_device_alloc(void) +{ + return kzalloc(sizeof(struct mali_device), GFP_KERNEL); +} + +void mali_device_free(struct mali_device *mdev) +{ + kfree(mdev); +} +#endif + static int mali_probe(struct platform_device *pdev) { int err; +#ifdef CONFIG_MALI_DEVFREQ + struct mali_device *mdev; +#endif MALI_DEBUG_PRINT(2, ("mali_probe(): Called for platform device %s\n", pdev->name)); @@ -508,10 +548,66 @@ static int mali_probe(struct platform_device *pdev) err = mali_platform_device_init(mali_platform_device); if (0 != err) { MALI_PRINT_ERROR(("mali_probe(): Failed to initialize platform device.")); + mali_platform_device = NULL; return -EFAULT; } #endif +#ifdef CONFIG_MALI_DEVFREQ + mdev = mali_device_alloc(); + if (!mdev) { + MALI_PRINT_ERROR(("Can't allocate mali device private data\n")); + return -ENOMEM; + } + + mdev->dev = &pdev->dev; + dev_set_drvdata(mdev->dev, mdev); + + /*Initilization clock and regulator*/ +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 12, 0)) && defined(CONFIG_OF) \ + && defined(CONFIG_REGULATOR) + mdev->regulator = regulator_get_optional(mdev->dev, "mali"); + if (IS_ERR_OR_NULL(mdev->regulator)) { + MALI_DEBUG_PRINT(2, ("Continuing without Mali regulator control\n")); + mdev->regulator = NULL; + /* Allow probe to continue without regulator */ + } +#endif /* LINUX_VERSION_CODE >= 3, 12, 0 */ + +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0)) && defined(CONFIG_OF) \ + && defined(CONFIG_PM_OPP) + /* Register the OPPs if they are available in device tree */ + if (dev_pm_opp_of_add_table(mdev->dev) < 0) + MALI_DEBUG_PRINT(3, ("OPP table not found\n")); +#endif + + /* Need to name the gpu clock "clk_mali" in the device tree */ + mdev->clock = clk_get(mdev->dev, "clk_mali"); + if (IS_ERR_OR_NULL(mdev->clock)) { + MALI_DEBUG_PRINT(2, ("Continuing without Mali clock control\n")); + mdev->clock = NULL; + /* Allow probe to continue without clock. */ + } else { + err = clk_prepare_enable(mdev->clock); + if (err) { + MALI_PRINT_ERROR(("Failed to prepare and enable clock (%d)\n", err)); + goto clock_prepare_failed; + } + } + + /* initilize pm metrics related */ + if (mali_pm_metrics_init(mdev) < 0) { + MALI_DEBUG_PRINT(2, ("mali pm metrics init failed\n")); + goto pm_metrics_init_failed; + } + + if (mali_devfreq_init(mdev) < 0) { + MALI_DEBUG_PRINT(2, ("mali devfreq init failed\n")); + goto devfreq_init_failed; + } +#endif + + if (_MALI_OSK_ERR_OK == _mali_osk_wq_init()) { /* Initialize the Mali GPU HW specified by pdev */ if (_MALI_OSK_ERR_OK == mali_initialize_subsystems()) { @@ -539,17 +635,67 @@ static int mali_probe(struct platform_device *pdev) _mali_osk_wq_term(); } +#ifdef CONFIG_MALI_DEVFREQ + mali_devfreq_term(mdev); +devfreq_init_failed: + mali_pm_metrics_term(mdev); +pm_metrics_init_failed: + clk_disable_unprepare(mdev->clock); +clock_prepare_failed: + clk_put(mdev->clock); +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)) && defined(CONFIG_OF) \ + && defined(CONFIG_PM_OPP) + dev_pm_opp_of_remove_table(mdev->dev); +#endif + +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 12, 0)) && defined(CONFIG_OF) \ + && defined(CONFIG_REGULATOR) + regulator_put(mdev->regulator); +#endif /* LINUX_VERSION_CODE >= 3, 12, 0 */ + mali_device_free(mdev); +#endif + +#ifdef CONFIG_MALI_DT + mali_platform_device_deinit(mali_platform_device); +#endif mali_platform_device = NULL; return -EFAULT; } static int mali_remove(struct platform_device *pdev) { +#ifdef CONFIG_MALI_DEVFREQ + struct mali_device *mdev = dev_get_drvdata(&pdev->dev); +#endif + MALI_DEBUG_PRINT(2, ("mali_remove() called for platform device %s\n", pdev->name)); mali_sysfs_unregister(); mali_miscdevice_unregister(); mali_terminate_subsystems(); _mali_osk_wq_term(); + +#ifdef CONFIG_MALI_DEVFREQ + mali_devfreq_term(mdev); + + mali_pm_metrics_term(mdev); + + if (mdev->clock) { + clk_disable_unprepare(mdev->clock); + clk_put(mdev->clock); + mdev->clock = NULL; + } +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0)) && defined(CONFIG_OF) \ + && defined(CONFIG_PM_OPP) + dev_pm_opp_of_remove_table(mdev->dev); +#endif + +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 12, 0)) && defined(CONFIG_OF) \ + && defined(CONFIG_REGULATOR) + regulator_put(mdev->regulator); +#endif /* LINUX_VERSION_CODE >= 3, 12, 0 */ + mali_device_free(mdev); +#endif + #ifdef CONFIG_MALI_DT mali_platform_device_deinit(mali_platform_device); #endif @@ -581,6 +727,17 @@ static void mali_miscdevice_unregister(void) static int mali_driver_suspend_scheduler(struct device *dev) { +#ifdef CONFIG_MALI_DEVFREQ + struct mali_device *mdev = dev_get_drvdata(dev); + if (!mdev) + return -ENODEV; +#endif + +#if defined(CONFIG_MALI_DEVFREQ) && \ + (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0)) + devfreq_suspend_device(mdev->devfreq); +#endif + mali_pm_os_suspend(MALI_TRUE); /* Tracing the frequency and voltage after mali is suspended */ _mali_osk_profiling_add_event(MALI_PROFILING_EVENT_TYPE_SINGLE | @@ -594,6 +751,12 @@ static int mali_driver_suspend_scheduler(struct device *dev) static int mali_driver_resume_scheduler(struct device *dev) { +#ifdef CONFIG_MALI_DEVFREQ + struct mali_device *mdev = dev_get_drvdata(dev); + if (!mdev) + return -ENODEV; +#endif + /* Tracing the frequency and voltage after mali is resumed */ #if defined(CONFIG_MALI400_PROFILING) && defined(CONFIG_MALI_DVFS) /* Just call mali_get_current_gpu_clk_item() once,to record current clk info.*/ @@ -609,12 +772,24 @@ static int mali_driver_resume_scheduler(struct device *dev) 0, 0, 0); #endif mali_pm_os_resume(); + +#if defined(CONFIG_MALI_DEVFREQ) && \ + (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0)) + devfreq_resume_device(mdev->devfreq); +#endif + return 0; } #ifdef CONFIG_PM_RUNTIME static int mali_driver_runtime_suspend(struct device *dev) { +#ifdef CONFIG_MALI_DEVFREQ + struct mali_device *mdev = dev_get_drvdata(dev); + if (!mdev) + return -ENODEV; +#endif + if (MALI_TRUE == mali_pm_runtime_suspend()) { /* Tracing the frequency and voltage after mali is suspended */ _mali_osk_profiling_add_event(MALI_PROFILING_EVENT_TYPE_SINGLE | @@ -624,6 +799,12 @@ static int mali_driver_runtime_suspend(struct device *dev) 0, 0, 0, 0); +#if defined(CONFIG_MALI_DEVFREQ) && \ + (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0)) + MALI_DEBUG_PRINT(4, ("devfreq_suspend_device: stop devfreq monitor\n")); + devfreq_suspend_device(mdev->devfreq); +#endif + return 0; } else { return -EBUSY; @@ -632,6 +813,12 @@ static int mali_driver_runtime_suspend(struct device *dev) static int mali_driver_runtime_resume(struct device *dev) { +#ifdef CONFIG_MALI_DEVFREQ + struct mali_device *mdev = dev_get_drvdata(dev); + if (!mdev) + return -ENODEV; +#endif + /* Tracing the frequency and voltage after mali is resumed */ #if defined(CONFIG_MALI400_PROFILING) && defined(CONFIG_MALI_DVFS) /* Just call mali_get_current_gpu_clk_item() once,to record current clk info.*/ @@ -648,6 +835,12 @@ static int mali_driver_runtime_resume(struct device *dev) #endif mali_pm_runtime_resume(); + +#if defined(CONFIG_MALI_DEVFREQ) && \ + (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 0)) + MALI_DEBUG_PRINT(4, ("devfreq_resume_device: start devfreq monitor\n")); + devfreq_resume_device(mdev->devfreq); +#endif return 0; } diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_kernel_sysfs.c b/drivers/gpu/arm/mali400/mali/linux/mali_kernel_sysfs.c index 4f06ca14bf48..3b50af605667 100755 --- a/drivers/gpu/arm/mali400/mali/linux/mali_kernel_sysfs.c +++ b/drivers/gpu/arm/mali400/mali/linux/mali_kernel_sysfs.c @@ -1,5 +1,5 @@ /** - * Copyright (C) 2011-2015 ARM Limited. All rights reserved. + * Copyright (C) 2011-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_kernel_sysfs.h b/drivers/gpu/arm/mali400/mali/linux/mali_kernel_sysfs.h index a36a0cea9972..9dad7f24ccad 100755 --- a/drivers/gpu/arm/mali400/mali/linux/mali_kernel_sysfs.h +++ b/drivers/gpu/arm/mali400/mali/linux/mali_kernel_sysfs.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2013, 2015 ARM Limited. All rights reserved. + * Copyright (C) 2011-2013, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_linux_trace.h b/drivers/gpu/arm/mali400/mali/linux/mali_linux_trace.h index c6cd2bfb7217..2c91ddcd82e5 100755 --- a/drivers/gpu/arm/mali400/mali/linux/mali_linux_trace.h +++ b/drivers/gpu/arm/mali400/mali/linux/mali_linux_trace.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012-2015 ARM Limited. All rights reserved. + * Copyright (C) 2012-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_memory.c b/drivers/gpu/arm/mali400/mali/linux/mali_memory.c index 1e57bd674042..95f04ed02236 100755 --- a/drivers/gpu/arm/mali400/mali/linux/mali_memory.c +++ b/drivers/gpu/arm/mali400/mali/linux/mali_memory.c @@ -30,6 +30,9 @@ #include "mali_memory_cow.h" #include "mali_memory_swap_alloc.h" #include "mali_memory_defer_bind.h" +#if defined(CONFIG_DMA_SHARED_BUFFER) +#include "mali_memory_secure.h" +#endif extern unsigned int mali_dedicated_mem_size; extern unsigned int mali_shared_mem_size; @@ -121,6 +124,8 @@ static int mali_mem_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf) } } else { MALI_PRINT_ERROR(("Mali vma fault! It never happen, indicating some logic errors in caller.\n")); + /*NOT support yet or OOM*/ + return VM_FAULT_OOM; } return VM_FAULT_NOPAGE; } @@ -244,6 +249,13 @@ int mali_mmap(struct file *filp, struct vm_area_struct *vma) (MALI_MEM_BACKEND_FLAG_SWAP_COWED == (mem_bkend->flags & MALI_MEM_BACKEND_FLAG_SWAP_COWED)))) { /*For swappable memory, CPU page table will be created by page fault handler. */ ret = 0; + } else if (mem_bkend->type == MALI_MEM_SECURE) { +#if defined(CONFIG_DMA_SHARED_BUFFER) + ret = mali_mem_secure_cpu_map(mem_bkend, vma); +#else + MALI_DEBUG_PRINT(1, ("DMA not supported for mali secure memory\n")); + return -EFAULT; +#endif } else { /* Not support yet*/ MALI_DEBUG_PRINT_ERROR(("Invalid type of backend memory! \n")); diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_memory.h b/drivers/gpu/arm/mali400/mali/linux/mali_memory.h index 3140c6c98d2c..e5e4f66ec02e 100755 --- a/drivers/gpu/arm/mali400/mali/linux/mali_memory.h +++ b/drivers/gpu/arm/mali400/mali/linux/mali_memory.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013-2015 ARM Limited. All rights reserved. + * Copyright (C) 2013-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_memory_block_alloc.c b/drivers/gpu/arm/mali400/mali/linux/mali_memory_block_alloc.c index 453ddda3080f..deb2ee84f6e5 100755 --- a/drivers/gpu/arm/mali400/mali/linux/mali_memory_block_alloc.c +++ b/drivers/gpu/arm/mali400/mali/linux/mali_memory_block_alloc.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_memory_block_alloc.h b/drivers/gpu/arm/mali400/mali/linux/mali_memory_block_alloc.h index 129434de67df..3e11ef25888e 100755 --- a/drivers/gpu/arm/mali400/mali/linux/mali_memory_block_alloc.h +++ b/drivers/gpu/arm/mali400/mali/linux/mali_memory_block_alloc.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010, 2013, 2015 ARM Limited. All rights reserved. + * Copyright (C) 2010, 2013, 2015-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_memory_cow.c b/drivers/gpu/arm/mali400/mali/linux/mali_memory_cow.c index 65fb38b327b8..0a11f4b934be 100644 --- a/drivers/gpu/arm/mali400/mali/linux/mali_memory_cow.c +++ b/drivers/gpu/arm/mali400/mali/linux/mali_memory_cow.c @@ -600,8 +600,8 @@ u32 mali_mem_cow_release(mali_mem_backend *mem_bkend, mali_bool is_mali_mapped) alloc = mem_bkend->mali_allocation; MALI_DEBUG_ASSERT_POINTER(alloc); - session = alloc->session; - MALI_DEBUG_ASSERT_POINTER(session); + session = alloc->session; + MALI_DEBUG_ASSERT_POINTER(session); if (MALI_MEM_BACKEND_FLAG_SWAP_COWED != (MALI_MEM_BACKEND_FLAG_SWAP_COWED & mem_bkend->flags)) { /* Unmap the memory from the mali virtual address space. */ diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_memory_cow.h b/drivers/gpu/arm/mali400/mali/linux/mali_memory_cow.h index c16ec7633c0a..9b9e83491526 100644 --- a/drivers/gpu/arm/mali400/mali/linux/mali_memory_cow.h +++ b/drivers/gpu/arm/mali400/mali/linux/mali_memory_cow.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013-2015 ARM Limited. All rights reserved. + * Copyright (C) 2013-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_memory_dma_buf.c b/drivers/gpu/arm/mali400/mali/linux/mali_memory_dma_buf.c index 2fa5028d8342..f0d1e07be544 100755 --- a/drivers/gpu/arm/mali400/mali/linux/mali_memory_dma_buf.c +++ b/drivers/gpu/arm/mali400/mali/linux/mali_memory_dma_buf.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012-2015 ARM Limited. All rights reserved. + * Copyright (C) 2012-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_memory_dma_buf.h b/drivers/gpu/arm/mali400/mali/linux/mali_memory_dma_buf.h index 859d3849e6b3..37b6f6b43680 100755 --- a/drivers/gpu/arm/mali400/mali/linux/mali_memory_dma_buf.h +++ b/drivers/gpu/arm/mali400/mali/linux/mali_memory_dma_buf.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2015 ARM Limited. All rights reserved. + * Copyright (C) 2011-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_memory_external.c b/drivers/gpu/arm/mali400/mali/linux/mali_memory_external.c index dcc9a7590885..c0097f6706f8 100755 --- a/drivers/gpu/arm/mali400/mali/linux/mali_memory_external.c +++ b/drivers/gpu/arm/mali400/mali/linux/mali_memory_external.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013-2015 ARM Limited. All rights reserved. + * Copyright (C) 2013-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_memory_external.h b/drivers/gpu/arm/mali400/mali/linux/mali_memory_external.h index 645580b51fc9..ba387b8a270f 100644 --- a/drivers/gpu/arm/mali400/mali/linux/mali_memory_external.h +++ b/drivers/gpu/arm/mali400/mali/linux/mali_memory_external.h @@ -1,6 +1,6 @@ /* - * Copyright (C) 2011-2015 ARM Limited. All rights reserved. + * Copyright (C) 2011-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_memory_manager.c b/drivers/gpu/arm/mali400/mali/linux/mali_memory_manager.c index b7479940f461..178abcfae37d 100644 --- a/drivers/gpu/arm/mali400/mali/linux/mali_memory_manager.c +++ b/drivers/gpu/arm/mali400/mali/linux/mali_memory_manager.c @@ -31,6 +31,7 @@ #include "mali_memory_os_alloc.h" #if defined(CONFIG_DMA_SHARED_BUFFER) #include "mali_memory_dma_buf.h" +#include "mali_memory_secure.h" #endif #if defined(CONFIG_MALI400_UMP) #include "mali_memory_ump.h" @@ -439,6 +440,8 @@ _mali_osk_errcode_t _mali_ukk_mem_allocate(_mali_uk_alloc_mem_s *args) } else if (args->flags & _MALI_MEMORY_ALLOCATE_RESIZEABLE) { mali_allocation->type = MALI_MEM_OS; mali_allocation->flags |= MALI_MEM_FLAG_CAN_RESIZE; + } else if (args->flags & _MALI_MEMORY_ALLOCATE_SECURE) { + mali_allocation->type = MALI_MEM_SECURE; } else if (MALI_TRUE == mali_memory_have_dedicated_memory()) { mali_allocation->type = MALI_MEM_BLOCK; } else { @@ -495,31 +498,47 @@ _mali_osk_errcode_t _mali_ukk_mem_allocate(_mali_uk_alloc_mem_s *args) goto done; } - /** - *allocate physical memory - */ + if (likely(mali_allocation->psize > 0)) { - if (mem_backend->type == MALI_MEM_OS) { - retval = mali_mem_os_alloc_pages(&mem_backend->os_mem, mem_backend->size); - } else if (mem_backend->type == MALI_MEM_BLOCK) { - /* try to allocated from BLOCK memory first, then try OS memory if failed.*/ - if (mali_mem_block_alloc(&mem_backend->block_mem, mem_backend->size)) { - retval = mali_mem_os_alloc_pages(&mem_backend->os_mem, mem_backend->size); - mem_backend->type = MALI_MEM_OS; - mali_allocation->type = MALI_MEM_OS; + if (MALI_MEM_SECURE == mem_backend->type) { +#if defined(CONFIG_DMA_SHARED_BUFFER) + ret = mali_mem_secure_attach_dma_buf(&mem_backend->secure_mem, mem_backend->size, args->secure_shared_fd); + if (_MALI_OSK_ERR_OK != ret) { + MALI_DEBUG_PRINT(1, ("Failed to attach dma buf for secure memory! \n")); + goto failed_alloc_pages; } - } else if (MALI_MEM_SWAP == mem_backend->type) { - retval = mali_mem_swap_alloc_pages(&mem_backend->swap_mem, mali_allocation->mali_vma_node.vm_node.size, &mem_backend->start_idx); +#else + ret = _MALI_OSK_ERR_UNSUPPORTED; + MALI_DEBUG_PRINT(1, ("DMA not supported for mali secure memory! \n")); + goto failed_alloc_pages; +#endif } else { - /* ONLY support mem_os type */ - MALI_DEBUG_ASSERT(0); - } - if (retval) { - ret = _MALI_OSK_ERR_NOMEM; - MALI_DEBUG_PRINT(1, (" can't allocate enough pages! \n")); - goto failed_alloc_pages; + /** + *allocate physical memory + */ + if (mem_backend->type == MALI_MEM_OS) { + retval = mali_mem_os_alloc_pages(&mem_backend->os_mem, mem_backend->size); + } else if (mem_backend->type == MALI_MEM_BLOCK) { + /* try to allocated from BLOCK memory first, then try OS memory if failed.*/ + if (mali_mem_block_alloc(&mem_backend->block_mem, mem_backend->size)) { + retval = mali_mem_os_alloc_pages(&mem_backend->os_mem, mem_backend->size); + mem_backend->type = MALI_MEM_OS; + mali_allocation->type = MALI_MEM_OS; + } + } else if (MALI_MEM_SWAP == mem_backend->type) { + retval = mali_mem_swap_alloc_pages(&mem_backend->swap_mem, mali_allocation->mali_vma_node.vm_node.size, &mem_backend->start_idx); + } else { + /* ONLY support mem_os type */ + MALI_DEBUG_ASSERT(0); + } + + if (retval) { + ret = _MALI_OSK_ERR_NOMEM; + MALI_DEBUG_PRINT(1, (" can't allocate enough pages! \n")); + goto failed_alloc_pages; + } } } @@ -540,6 +559,10 @@ _mali_osk_errcode_t _mali_ukk_mem_allocate(_mali_uk_alloc_mem_s *args) } else if (mem_backend->type == MALI_MEM_SWAP) { ret = mali_mem_swap_mali_map(&mem_backend->swap_mem, session, args->gpu_vaddr, mali_allocation->mali_mapping.properties); + } else if (mem_backend->type == MALI_MEM_SECURE) { +#if defined(CONFIG_DMA_SHARED_BUFFER) + ret = mali_mem_secure_mali_map(&mem_backend->secure_mem, session, args->gpu_vaddr, mali_allocation->mali_mapping.properties); +#endif } else { /* unsupport type */ MALI_DEBUG_ASSERT(0); } @@ -551,6 +574,8 @@ done: atomic_add(mem_backend->os_mem.count, &session->mali_mem_allocated_pages); } else if (MALI_MEM_BLOCK == mem_backend->type) { atomic_add(mem_backend->block_mem.count, &session->mali_mem_allocated_pages); + } else if (MALI_MEM_SECURE == mem_backend->type) { + atomic_add(mem_backend->secure_mem.count, &session->mali_mem_allocated_pages); } else { MALI_DEBUG_ASSERT(MALI_MEM_SWAP == mem_backend->type); atomic_add(mem_backend->swap_mem.count, &session->mali_mem_allocated_pages); diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_memory_manager.h b/drivers/gpu/arm/mali400/mali/linux/mali_memory_manager.h index c454b9354676..0ced28026f3f 100644 --- a/drivers/gpu/arm/mali400/mali/linux/mali_memory_manager.h +++ b/drivers/gpu/arm/mali400/mali/linux/mali_memory_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013-2015 ARM Limited. All rights reserved. + * Copyright (C) 2013-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_memory_os_alloc.h b/drivers/gpu/arm/mali400/mali/linux/mali_memory_os_alloc.h index f9ead166c455..b92fffe0dfec 100755 --- a/drivers/gpu/arm/mali400/mali/linux/mali_memory_os_alloc.h +++ b/drivers/gpu/arm/mali400/mali/linux/mali_memory_os_alloc.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013-2015 ARM Limited. All rights reserved. + * Copyright (C) 2013-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_memory_secure.c b/drivers/gpu/arm/mali400/mali/linux/mali_memory_secure.c new file mode 100644 index 000000000000..7856ae6c74ce --- /dev/null +++ b/drivers/gpu/arm/mali400/mali/linux/mali_memory_secure.c @@ -0,0 +1,169 @@ +/* + * Copyright (C) 2010-2016 ARM Limited. All rights reserved. + * + * This program is free software and is provided to you under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. + * + * A copy of the licence is included with the program, and can also be obtained from Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "mali_kernel_common.h" +#include "mali_memory.h" +#include "mali_memory_secure.h" +#include "mali_osk.h" +#include +#include +#include + +_mali_osk_errcode_t mali_mem_secure_attach_dma_buf(mali_mem_secure *secure_mem, u32 size, int mem_fd) +{ + struct dma_buf *buf; + MALI_DEBUG_ASSERT_POINTER(secure_mem); + + /* get dma buffer */ + buf = dma_buf_get(mem_fd); + if (IS_ERR_OR_NULL(buf)) { + MALI_DEBUG_PRINT_ERROR(("Failed to get dma buf!\n")); + return _MALI_OSK_ERR_FAULT; + } + + if (size != buf->size) { + MALI_DEBUG_PRINT_ERROR(("The secure mem size not match to the dma buf size!\n")); + goto failed_alloc_mem; + } + + secure_mem->buf = buf; + secure_mem->attachment = dma_buf_attach(secure_mem->buf, &mali_platform_device->dev); + if (NULL == secure_mem->attachment) { + MALI_DEBUG_PRINT_ERROR(("Failed to get dma buf attachment!\n")); + goto failed_dma_attach; + } + + secure_mem->sgt = dma_buf_map_attachment(secure_mem->attachment, DMA_BIDIRECTIONAL); + if (IS_ERR_OR_NULL(secure_mem->sgt)) { + MALI_DEBUG_PRINT_ERROR(("Failed to map dma buf attachment\n")); + goto failed_dma_map; + } + + secure_mem->count = size / MALI_MMU_PAGE_SIZE; + + return _MALI_OSK_ERR_OK; + +failed_dma_map: + dma_buf_detach(secure_mem->buf, secure_mem->attachment); +failed_dma_attach: +failed_alloc_mem: + dma_buf_put(buf); + return _MALI_OSK_ERR_FAULT; +} + +_mali_osk_errcode_t mali_mem_secure_mali_map(mali_mem_secure *secure_mem, struct mali_session_data *session, u32 vaddr, u32 props) +{ + struct mali_page_directory *pagedir; + struct scatterlist *sg; + u32 virt = vaddr; + u32 prop = props; + int i; + + MALI_DEBUG_ASSERT_POINTER(secure_mem); + MALI_DEBUG_ASSERT_POINTER(secure_mem->sgt); + MALI_DEBUG_ASSERT_POINTER(session); + + pagedir = session->page_directory; + + for_each_sg(secure_mem->sgt->sgl, sg, secure_mem->sgt->nents, i) { + u32 size = sg_dma_len(sg); + dma_addr_t phys = sg_dma_address(sg); + + /* sg must be page aligned. */ + MALI_DEBUG_ASSERT(0 == size % MALI_MMU_PAGE_SIZE); + MALI_DEBUG_ASSERT(0 == (phys & ~(uintptr_t)0xFFFFFFFF)); + + mali_mmu_pagedir_update(pagedir, virt, phys, size, prop); + + MALI_DEBUG_PRINT(3, ("The secure mem physical address: 0x%x gpu virtual address: 0x%x! \n", phys, virt)); + virt += size; + } + + return _MALI_OSK_ERR_OK; +} + +void mali_mem_secure_mali_unmap(mali_mem_allocation *alloc) +{ + struct mali_session_data *session; + MALI_DEBUG_ASSERT_POINTER(alloc); + session = alloc->session; + MALI_DEBUG_ASSERT_POINTER(session); + + mali_session_memory_lock(session); + mali_mem_mali_map_free(session, alloc->psize, alloc->mali_vma_node.vm_node.start, + alloc->flags); + mali_session_memory_unlock(session); +} + + +int mali_mem_secure_cpu_map(mali_mem_backend *mem_bkend, struct vm_area_struct *vma) +{ + + int ret = 0; + struct scatterlist *sg; + mali_mem_secure *secure_mem = &mem_bkend->secure_mem; + unsigned long addr = vma->vm_start; + int i; + + MALI_DEBUG_ASSERT(mem_bkend->type == MALI_MEM_SECURE); + + for_each_sg(secure_mem->sgt->sgl, sg, secure_mem->sgt->nents, i) { + phys_addr_t phys; + dma_addr_t dev_addr; + u32 size, j; + dev_addr = sg_dma_address(sg); +#if defined(CONFIG_ARM64) ||LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0) + phys = dma_to_phys(&mali_platform_device->dev, dev_addr); +#else + phys = page_to_phys(pfn_to_page(dma_to_pfn(&mali_platform_device->dev, dev_addr))); +#endif + size = sg_dma_len(sg); + 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)); + + if (unlikely(0 != ret)) { + return -EFAULT; + } + addr += _MALI_OSK_MALI_PAGE_SIZE; + phys += _MALI_OSK_MALI_PAGE_SIZE; + + MALI_DEBUG_PRINT(3, ("The secure mem physical address: 0x%x , cpu virtual address: 0x%x! \n", phys, addr)); + } + } + return ret; +} + +u32 mali_mem_secure_release(mali_mem_backend *mem_bkend) +{ + struct mali_mem_secure *mem; + mali_mem_allocation *alloc = mem_bkend->mali_allocation; + u32 free_pages_nr = 0; + MALI_DEBUG_ASSERT(mem_bkend->type == MALI_MEM_SECURE); + + mem = &mem_bkend->secure_mem; + MALI_DEBUG_ASSERT_POINTER(mem->attachment); + MALI_DEBUG_ASSERT_POINTER(mem->buf); + MALI_DEBUG_ASSERT_POINTER(mem->sgt); + /* Unmap the memory from the mali virtual address space. */ + mali_mem_secure_mali_unmap(alloc); + mutex_lock(&mem_bkend->mutex); + dma_buf_unmap_attachment(mem->attachment, mem->sgt, DMA_BIDIRECTIONAL); + dma_buf_detach(mem->buf, mem->attachment); + dma_buf_put(mem->buf); + mutex_unlock(&mem_bkend->mutex); + + free_pages_nr = mem->count; + + return free_pages_nr; +} + + diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_memory_secure.h b/drivers/gpu/arm/mali400/mali/linux/mali_memory_secure.h new file mode 100644 index 000000000000..64f40d4fab04 --- /dev/null +++ b/drivers/gpu/arm/mali400/mali/linux/mali_memory_secure.h @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2010, 2013, 2015 ARM Limited. All rights reserved. + * + * This program is free software and is provided to you under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. + * + * A copy of the licence is included with the program, and can also be obtained from Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef __MALI_MEMORY_SECURE_H__ +#define __MALI_MEMORY_SECURE_H__ + +#include "mali_session.h" +#include "mali_memory.h" +#include + +#include "mali_memory_types.h" + +_mali_osk_errcode_t mali_mem_secure_attach_dma_buf(mali_mem_secure *secure_mem, u32 size, int mem_fd); + +_mali_osk_errcode_t mali_mem_secure_mali_map(mali_mem_secure *secure_mem, struct mali_session_data *session, u32 vaddr, u32 props); + +void mali_mem_secure_mali_unmap(mali_mem_allocation *alloc); + +int mali_mem_secure_cpu_map(mali_mem_backend *mem_bkend, struct vm_area_struct *vma); + +u32 mali_mem_secure_release(mali_mem_backend *mem_bkend); + +#endif /* __MALI_MEMORY_SECURE_H__ */ diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_memory_swap_alloc.c b/drivers/gpu/arm/mali400/mali/linux/mali_memory_swap_alloc.c index a46eb198c98f..47933283680c 100644 --- a/drivers/gpu/arm/mali400/mali/linux/mali_memory_swap_alloc.c +++ b/drivers/gpu/arm/mali400/mali/linux/mali_memory_swap_alloc.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013-2015 ARM Limited. All rights reserved. + * Copyright (C) 2013-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_memory_swap_alloc.h b/drivers/gpu/arm/mali400/mali/linux/mali_memory_swap_alloc.h index a393ecce3a00..3624d710d78b 100644 --- a/drivers/gpu/arm/mali400/mali/linux/mali_memory_swap_alloc.h +++ b/drivers/gpu/arm/mali400/mali/linux/mali_memory_swap_alloc.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013-2015 ARM Limited. All rights reserved. + * Copyright (C) 2013-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_memory_types.h b/drivers/gpu/arm/mali400/mali/linux/mali_memory_types.h index 82af8fed66c9..f3a825d6b8b6 100755 --- a/drivers/gpu/arm/mali400/mali/linux/mali_memory_types.h +++ b/drivers/gpu/arm/mali400/mali/linux/mali_memory_types.h @@ -27,6 +27,7 @@ typedef enum mali_mem_type { MALI_MEM_UMP, MALI_MEM_BLOCK, MALI_MEM_COW, + MALI_MEM_SECURE, MALI_MEM_TYPE_MAX, } mali_mem_type; @@ -170,6 +171,15 @@ typedef struct mali_mem_swap { u32 count; } mali_mem_swap; +typedef struct mali_mem_secure { +#if defined(CONFIG_DMA_SHARED_BUFFER) + struct dma_buf *buf; + struct dma_buf_attachment *attachment; + struct sg_table *sgt; +#endif + u32 count; +} mali_mem_secure; + #define MALI_MEM_BACKEND_FLAG_COWED (0x1) /* COW has happen on this backend */ #define MALI_MEM_BACKEND_FLAG_COW_CPU_NO_WRITE (0x2) /* This is an COW backend, mapped as not allowed cpu to write */ #define MALI_MEM_BACKEND_FLAG_SWAP_COWED (0x4) /* Mark the given backend is cowed from swappable memory. */ @@ -192,6 +202,7 @@ typedef struct mali_mem_backend { mali_mem_block_mem block_mem; /**< MALI_MEM_BLOCK */ mali_mem_cow cow_mem; mali_mem_swap swap_mem; + mali_mem_secure secure_mem; }; mali_mem_allocation *mali_allocation; struct mutex mutex; diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_memory_ump.c b/drivers/gpu/arm/mali400/mali/linux/mali_memory_ump.c index bacadc85e47e..e4a29930d963 100755 --- a/drivers/gpu/arm/mali400/mali/linux/mali_memory_ump.c +++ b/drivers/gpu/arm/mali400/mali/linux/mali_memory_ump.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012-2015 ARM Limited. All rights reserved. + * Copyright (C) 2012-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_memory_ump.h b/drivers/gpu/arm/mali400/mali/linux/mali_memory_ump.h index 4adb70df884e..7f03a49d8732 100644 --- a/drivers/gpu/arm/mali400/mali/linux/mali_memory_ump.h +++ b/drivers/gpu/arm/mali400/mali/linux/mali_memory_ump.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2015 ARM Limited. All rights reserved. + * Copyright (C) 2011-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_memory_util.c b/drivers/gpu/arm/mali400/mali/linux/mali_memory_util.c index bcca43c09f0b..d5b39a962905 100644 --- a/drivers/gpu/arm/mali400/mali/linux/mali_memory_util.c +++ b/drivers/gpu/arm/mali400/mali/linux/mali_memory_util.c @@ -25,6 +25,7 @@ #include "mali_memory_os_alloc.h" #if defined(CONFIG_DMA_SHARED_BUFFER) #include "mali_memory_dma_buf.h" +#include "mali_memory_secure.h" #endif #if defined(CONFIG_MALI400_UMP) #include "mali_memory_ump.h" @@ -67,7 +68,7 @@ static u32 _mali_free_allocation_mem(mali_mem_allocation *mali_alloc) mali_mem_unbind_ump_buf(mem_bkend); atomic_sub(mem_bkend->size / MALI_MMU_PAGE_SIZE, &session->mali_mem_array[mem_bkend->type]); #else - MALI_DEBUG_PRINT(2, ("UMP not supported\n")); + MALI_DEBUG_PRINT(1, ("UMP not supported\n")); #endif break; case MALI_MEM_DMA_BUF: @@ -75,7 +76,7 @@ static u32 _mali_free_allocation_mem(mali_mem_allocation *mali_alloc) mali_mem_unbind_dma_buf(mem_bkend); atomic_sub(mem_bkend->size / MALI_MMU_PAGE_SIZE, &session->mali_mem_array[mem_bkend->type]); #else - MALI_DEBUG_PRINT(2, ("DMA not supported\n")); + MALI_DEBUG_PRINT(1, ("DMA not supported\n")); #endif break; case MALI_MEM_EXTERNAL: @@ -101,6 +102,14 @@ static u32 _mali_free_allocation_mem(mali_mem_allocation *mali_alloc) atomic_sub(free_pages_nr, &session->mali_mem_allocated_pages); atomic_sub(free_pages_nr, &session->mali_mem_array[mem_bkend->type]); break; + case MALI_MEM_SECURE: +#if defined(CONFIG_DMA_SHARED_BUFFER) + free_pages_nr = mali_mem_secure_release(mem_bkend); + atomic_sub(free_pages_nr, &session->mali_mem_allocated_pages); +#else + MALI_DEBUG_PRINT(1, ("DMA not supported for mali secure memory\n")); +#endif + break; default: MALI_DEBUG_PRINT(1, ("mem type %d is not in the mali_mem_type enum.\n", mem_bkend->type)); break; diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_memory_util.h b/drivers/gpu/arm/mali400/mali/linux/mali_memory_util.h index 0d686979d7a8..b3cc7e9eaa62 100644 --- a/drivers/gpu/arm/mali400/mali/linux/mali_memory_util.h +++ b/drivers/gpu/arm/mali400/mali/linux/mali_memory_util.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013-2015 ARM Limited. All rights reserved. + * Copyright (C) 2013-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_memory_virtual.c b/drivers/gpu/arm/mali400/mali/linux/mali_memory_virtual.c index 35f8f90a444d..cb85ca23737d 100644 --- a/drivers/gpu/arm/mali400/mali/linux/mali_memory_virtual.c +++ b/drivers/gpu/arm/mali400/mali/linux/mali_memory_virtual.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013-2015 ARM Limited. All rights reserved. + * Copyright (C) 2013-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_memory_virtual.h b/drivers/gpu/arm/mali400/mali/linux/mali_memory_virtual.h index 3e2d48f44e28..9815f28f7ae1 100644 --- a/drivers/gpu/arm/mali400/mali/linux/mali_memory_virtual.h +++ b/drivers/gpu/arm/mali400/mali/linux/mali_memory_virtual.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013-2015 ARM Limited. All rights reserved. + * Copyright (C) 2013-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_osk_atomics.c b/drivers/gpu/arm/mali400/mali/linux/mali_osk_atomics.c index ba630e2730cf..03f4421ef1ea 100755 --- a/drivers/gpu/arm/mali400/mali/linux/mali_osk_atomics.c +++ b/drivers/gpu/arm/mali400/mali/linux/mali_osk_atomics.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010, 2013-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010, 2013-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_osk_bitmap.c b/drivers/gpu/arm/mali400/mali/linux/mali_osk_bitmap.c index 01ca38235b20..67cc7e42b83f 100644 --- a/drivers/gpu/arm/mali400/mali/linux/mali_osk_bitmap.c +++ b/drivers/gpu/arm/mali400/mali/linux/mali_osk_bitmap.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010, 2013-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010, 2013-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_osk_irq.c b/drivers/gpu/arm/mali400/mali/linux/mali_osk_irq.c index 539832d9125a..4a75845ab044 100755 --- a/drivers/gpu/arm/mali400/mali/linux/mali_osk_irq.c +++ b/drivers/gpu/arm/mali400/mali/linux/mali_osk_irq.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_osk_locks.c b/drivers/gpu/arm/mali400/mali/linux/mali_osk_locks.c index 50c0a9d23819..4fa93981858e 100755 --- a/drivers/gpu/arm/mali400/mali/linux/mali_osk_locks.c +++ b/drivers/gpu/arm/mali400/mali/linux/mali_osk_locks.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_osk_locks.h b/drivers/gpu/arm/mali400/mali/linux/mali_osk_locks.h index aa32a81e7496..a05586f0e12b 100755 --- a/drivers/gpu/arm/mali400/mali/linux/mali_osk_locks.h +++ b/drivers/gpu/arm/mali400/mali/linux/mali_osk_locks.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_osk_low_level_mem.c b/drivers/gpu/arm/mali400/mali/linux/mali_osk_low_level_mem.c index c14e872a7d63..bc713a175d20 100755 --- a/drivers/gpu/arm/mali400/mali/linux/mali_osk_low_level_mem.c +++ b/drivers/gpu/arm/mali400/mali/linux/mali_osk_low_level_mem.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_osk_mali.c b/drivers/gpu/arm/mali400/mali/linux/mali_osk_mali.c index 1a6d257baa5a..867814ef1489 100755 --- a/drivers/gpu/arm/mali400/mali/linux/mali_osk_mali.c +++ b/drivers/gpu/arm/mali400/mali/linux/mali_osk_mali.c @@ -27,6 +27,15 @@ #include "mali_osk.h" /* kernel side OS functions */ #include "mali_kernel_linux.h" +static mali_bool mali_secure_mode_enabled = MALI_FALSE; +static mali_bool mali_secure_mode_supported = MALI_FALSE; + +/* Function that init the mali gpu secure mode */ +void (*mali_secure_mode_deinit)(void) = NULL; +/* Function that enable the mali gpu secure mode */ +int (*mali_secure_mode_enable)(void) = NULL; +/* Function that disable the mali gpu secure mode */ +int (*mali_secure_mode_disable)(void) = NULL; #ifdef CONFIG_MALI_DT @@ -409,3 +418,95 @@ mali_bool _mali_osk_shared_interrupts(void) return MALI_FALSE; } + +_mali_osk_errcode_t _mali_osk_gpu_secure_mode_init(void) +{ + _mali_osk_device_data data = { 0, }; + + if (_MALI_OSK_ERR_OK == _mali_osk_device_data_get(&data)) { + if ((NULL != data.secure_mode_init) && (NULL != data.secure_mode_deinit) + && (NULL != data.secure_mode_enable) && (NULL != data.secure_mode_disable)) { + int err = data.secure_mode_init(); + if (err) { + MALI_DEBUG_PRINT(1, ("Failed to init gpu secure mode.\n")); + return _MALI_OSK_ERR_FAULT; + } + + mali_secure_mode_deinit = data.secure_mode_deinit; + mali_secure_mode_enable = data.secure_mode_enable; + mali_secure_mode_disable = data.secure_mode_disable; + + mali_secure_mode_supported = MALI_TRUE; + mali_secure_mode_enabled = MALI_FALSE; + return _MALI_OSK_ERR_OK; + } + } + MALI_DEBUG_PRINT(3, ("GPU secure mode not supported.\n")); + return _MALI_OSK_ERR_UNSUPPORTED; + +} + +_mali_osk_errcode_t _mali_osk_gpu_secure_mode_deinit(void) +{ + if (NULL != mali_secure_mode_deinit) { + mali_secure_mode_deinit(); + mali_secure_mode_enabled = MALI_FALSE; + mali_secure_mode_supported = MALI_FALSE; + return _MALI_OSK_ERR_OK; + } + MALI_DEBUG_PRINT(3, ("GPU secure mode not supported.\n")); + return _MALI_OSK_ERR_UNSUPPORTED; + +} + + +_mali_osk_errcode_t _mali_osk_gpu_secure_mode_enable(void) +{ + /* the mali executor lock must be held before enter this function. */ + + MALI_DEBUG_ASSERT(MALI_FALSE == mali_secure_mode_enabled); + + if (NULL != mali_secure_mode_enable) { + if (mali_secure_mode_enable()) { + MALI_DEBUG_PRINT(1, ("Failed to enable gpu secure mode.\n")); + return _MALI_OSK_ERR_FAULT; + } + mali_secure_mode_enabled = MALI_TRUE; + return _MALI_OSK_ERR_OK; + } + MALI_DEBUG_PRINT(1, ("GPU secure mode not supported.\n")); + return _MALI_OSK_ERR_UNSUPPORTED; +} + +_mali_osk_errcode_t _mali_osk_gpu_secure_mode_disable(void) +{ + /* the mali executor lock must be held before enter this function. */ + + MALI_DEBUG_ASSERT(MALI_TRUE == mali_secure_mode_enabled); + + if (NULL != mali_secure_mode_disable) { + if (mali_secure_mode_disable()) { + MALI_DEBUG_PRINT(1, ("Failed to disable gpu secure mode.\n")); + return _MALI_OSK_ERR_FAULT; + } + mali_secure_mode_enabled = MALI_FALSE; + + return _MALI_OSK_ERR_OK; + + } + MALI_DEBUG_PRINT(1, ("GPU secure mode not supported.\n")); + return _MALI_OSK_ERR_UNSUPPORTED; + +} + +mali_bool _mali_osk_gpu_secure_mode_is_enabled(void) +{ + return mali_secure_mode_enabled; +} + +mali_bool _mali_osk_gpu_secure_mode_is_supported(void) +{ + return mali_secure_mode_supported; +} + + diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_osk_math.c b/drivers/gpu/arm/mali400/mali/linux/mali_osk_math.c index 085ce76f7665..3f06723ad062 100755 --- a/drivers/gpu/arm/mali400/mali/linux/mali_osk_math.c +++ b/drivers/gpu/arm/mali400/mali/linux/mali_osk_math.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010, 2013-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010, 2013-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_osk_memory.c b/drivers/gpu/arm/mali400/mali/linux/mali_osk_memory.c index 390e613e186d..ad5494d338d3 100755 --- a/drivers/gpu/arm/mali400/mali/linux/mali_osk_memory.c +++ b/drivers/gpu/arm/mali400/mali/linux/mali_osk_memory.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2011, 2013-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2011, 2013-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_osk_misc.c b/drivers/gpu/arm/mali400/mali/linux/mali_osk_misc.c index 0a619e3fc27e..7dda2834c544 100755 --- a/drivers/gpu/arm/mali400/mali/linux/mali_osk_misc.c +++ b/drivers/gpu/arm/mali400/mali/linux/mali_osk_misc.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. @@ -42,17 +42,6 @@ u32 _mali_osk_snprintf(char *buf, u32 size, const char *fmt, ...) return res; } -void _mali_osk_ctxprintf(_mali_osk_print_ctx *print_ctx, const char *fmt, ...) -{ - va_list args; - char buf[512]; - - va_start(args, fmt); - vscnprintf(buf, 512, fmt, args); - seq_printf(print_ctx, buf); - va_end(args); -} - void _mali_osk_abort(void) { /* make a simple fault by dereferencing a NULL pointer */ diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_osk_notification.c b/drivers/gpu/arm/mali400/mali/linux/mali_osk_notification.c index e66fe83f3557..58678417b34f 100755 --- a/drivers/gpu/arm/mali400/mali/linux/mali_osk_notification.c +++ b/drivers/gpu/arm/mali400/mali/linux/mali_osk_notification.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_osk_profiling.c b/drivers/gpu/arm/mali400/mali/linux/mali_osk_profiling.c index 0201e1ab56c2..35d1abcb4964 100755 --- a/drivers/gpu/arm/mali400/mali/linux/mali_osk_profiling.c +++ b/drivers/gpu/arm/mali400/mali/linux/mali_osk_profiling.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012-2015 ARM Limited. All rights reserved. + * Copyright (C) 2012-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. @@ -254,8 +254,8 @@ static u32 _mali_profiling_read_packet_int(unsigned char *const buf, u32 *const u8 byte_value = ~0; while ((byte_value & 0x80) != 0) { - if ((*pos) >= packet_size); - return -1; + if ((*pos) >= packet_size) + return -1; byte_value = buf[*pos]; *pos += 1; int_value |= (u32)(byte_value & 0x7f) << shift; diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_osk_specific.h b/drivers/gpu/arm/mali400/mali/linux/mali_osk_specific.h index db034a5b3c70..adcca2937967 100755 --- a/drivers/gpu/arm/mali400/mali/linux/mali_osk_specific.h +++ b/drivers/gpu/arm/mali400/mali/linux/mali_osk_specific.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010, 2012-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010, 2012-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_osk_time.c b/drivers/gpu/arm/mali400/mali/linux/mali_osk_time.c index 4deaa101e48f..76876b61834f 100755 --- a/drivers/gpu/arm/mali400/mali/linux/mali_osk_time.c +++ b/drivers/gpu/arm/mali400/mali/linux/mali_osk_time.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010, 2013-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010, 2013-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_osk_timers.c b/drivers/gpu/arm/mali400/mali/linux/mali_osk_timers.c index 6bbaee749d64..8ada2da8d386 100755 --- a/drivers/gpu/arm/mali400/mali/linux/mali_osk_timers.c +++ b/drivers/gpu/arm/mali400/mali/linux/mali_osk_timers.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_osk_wait_queue.c b/drivers/gpu/arm/mali400/mali/linux/mali_osk_wait_queue.c index 15d5ce250eb1..caa3abe109fb 100755 --- a/drivers/gpu/arm/mali400/mali/linux/mali_osk_wait_queue.c +++ b/drivers/gpu/arm/mali400/mali/linux/mali_osk_wait_queue.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012-2015 ARM Limited. All rights reserved. + * Copyright (C) 2012-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_osk_wq.c b/drivers/gpu/arm/mali400/mali/linux/mali_osk_wq.c index 2c34c91a7922..06afa04032c5 100755 --- a/drivers/gpu/arm/mali400/mali/linux/mali_osk_wq.c +++ b/drivers/gpu/arm/mali400/mali/linux/mali_osk_wq.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_pmu_power_up_down.c b/drivers/gpu/arm/mali400/mali/linux/mali_pmu_power_up_down.c index 61ff5c8fdca8..48482a992dc5 100755 --- a/drivers/gpu/arm/mali400/mali/linux/mali_pmu_power_up_down.c +++ b/drivers/gpu/arm/mali400/mali/linux/mali_pmu_power_up_down.c @@ -1,5 +1,5 @@ /** - * Copyright (C) 2010, 2012-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010, 2012-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_profiling_events.h b/drivers/gpu/arm/mali400/mali/linux/mali_profiling_events.h index 0b90e8c5cf26..5e51095894e7 100755 --- a/drivers/gpu/arm/mali400/mali/linux/mali_profiling_events.h +++ b/drivers/gpu/arm/mali400/mali/linux/mali_profiling_events.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012, 2015 ARM Limited. All rights reserved. + * Copyright (C) 2012, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_profiling_gator_api.h b/drivers/gpu/arm/mali400/mali/linux/mali_profiling_gator_api.h index c98d127366ba..e37197138f8d 100755 --- a/drivers/gpu/arm/mali400/mali/linux/mali_profiling_gator_api.h +++ b/drivers/gpu/arm/mali400/mali/linux/mali_profiling_gator_api.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012-2013, 2015 ARM Limited. All rights reserved. + * Copyright (C) 2012-2013, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_profiling_internal.c b/drivers/gpu/arm/mali400/mali/linux/mali_profiling_internal.c index 12aef4194ff5..918caa07fd3b 100755 --- a/drivers/gpu/arm/mali400/mali/linux/mali_profiling_internal.c +++ b/drivers/gpu/arm/mali400/mali/linux/mali_profiling_internal.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_profiling_internal.h b/drivers/gpu/arm/mali400/mali/linux/mali_profiling_internal.h index 1c6f4da691d2..6e05ffdc927a 100755 --- a/drivers/gpu/arm/mali400/mali/linux/mali_profiling_internal.h +++ b/drivers/gpu/arm/mali400/mali/linux/mali_profiling_internal.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012-2015 ARM Limited. All rights reserved. + * Copyright (C) 2012-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_sync.c b/drivers/gpu/arm/mali400/mali/linux/mali_sync.c index 68868ca5b6bd..8bec3a404bf6 100755 --- a/drivers/gpu/arm/mali400/mali/linux/mali_sync.c +++ b/drivers/gpu/arm/mali400/mali/linux/mali_sync.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012-2015 ARM Limited. All rights reserved. + * Copyright (C) 2012-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_sync.h b/drivers/gpu/arm/mali400/mali/linux/mali_sync.h index 0c541ff9a2e0..79efb8e65274 100755 --- a/drivers/gpu/arm/mali400/mali/linux/mali_sync.h +++ b/drivers/gpu/arm/mali400/mali/linux/mali_sync.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012-2015 ARM Limited. All rights reserved. + * Copyright (C) 2012-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_uk_types.h b/drivers/gpu/arm/mali400/mali/linux/mali_uk_types.h index 1884cdbba424..00ba28b14300 100755 --- a/drivers/gpu/arm/mali400/mali/linux/mali_uk_types.h +++ b/drivers/gpu/arm/mali400/mali/linux/mali_uk_types.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012, 2015 ARM Limited. All rights reserved. + * Copyright (C) 2012, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_ukk_core.c b/drivers/gpu/arm/mali400/mali/linux/mali_ukk_core.c index 4ca85a8273e6..5531d9ebf9e4 100755 --- a/drivers/gpu/arm/mali400/mali/linux/mali_ukk_core.c +++ b/drivers/gpu/arm/mali400/mali/linux/mali_ukk_core.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_ukk_gp.c b/drivers/gpu/arm/mali400/mali/linux/mali_ukk_gp.c index d4144c0f5e48..d7c5d2f973e5 100755 --- a/drivers/gpu/arm/mali400/mali/linux/mali_ukk_gp.c +++ b/drivers/gpu/arm/mali400/mali/linux/mali_ukk_gp.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010, 2012-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010, 2012-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_ukk_mem.c b/drivers/gpu/arm/mali400/mali/linux/mali_ukk_mem.c index ca1cba0585b3..3dfe345f8483 100755 --- a/drivers/gpu/arm/mali400/mali/linux/mali_ukk_mem.c +++ b/drivers/gpu/arm/mali400/mali/linux/mali_ukk_mem.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_ukk_pp.c b/drivers/gpu/arm/mali400/mali/linux/mali_ukk_pp.c index 4c1c381cb90f..2c59bc72b6ad 100755 --- a/drivers/gpu/arm/mali400/mali/linux/mali_ukk_pp.c +++ b/drivers/gpu/arm/mali400/mali/linux/mali_ukk_pp.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010, 2012-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010, 2012-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_ukk_profiling.c b/drivers/gpu/arm/mali400/mali/linux/mali_ukk_profiling.c index 4f8bc92a2e02..2487bf3b505a 100755 --- a/drivers/gpu/arm/mali400/mali/linux/mali_ukk_profiling.c +++ b/drivers/gpu/arm/mali400/mali/linux/mali_ukk_profiling.c @@ -120,7 +120,7 @@ int profiling_control_set_wrapper(struct mali_session_data *session_data, _mali_ kargs.ctx = (uintptr_t)session_data; - + /* Sanity check about the size */ if (kargs.control_packet_size > PAGE_SIZE || kargs.response_packet_size > PAGE_SIZE) return -EINVAL; diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_ukk_soft_job.c b/drivers/gpu/arm/mali400/mali/linux/mali_ukk_soft_job.c index 11c70060e489..beeb7531a662 100755 --- a/drivers/gpu/arm/mali400/mali/linux/mali_ukk_soft_job.c +++ b/drivers/gpu/arm/mali400/mali/linux/mali_ukk_soft_job.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013-2015 ARM Limited. All rights reserved. + * Copyright (C) 2013-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_ukk_timeline.c b/drivers/gpu/arm/mali400/mali/linux/mali_ukk_timeline.c index 484d4041c869..f32d8b0d9cad 100755 --- a/drivers/gpu/arm/mali400/mali/linux/mali_ukk_timeline.c +++ b/drivers/gpu/arm/mali400/mali/linux/mali_ukk_timeline.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013, 2015 ARM Limited. All rights reserved. + * Copyright (C) 2013, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_ukk_vsync.c b/drivers/gpu/arm/mali400/mali/linux/mali_ukk_vsync.c index 487c2478df4d..5b54fb987241 100755 --- a/drivers/gpu/arm/mali400/mali/linux/mali_ukk_vsync.c +++ b/drivers/gpu/arm/mali400/mali/linux/mali_ukk_vsync.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2015 ARM Limited. All rights reserved. + * Copyright (C) 2011-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/linux/mali_ukk_wrappers.h b/drivers/gpu/arm/mali400/mali/linux/mali_ukk_wrappers.h index 504ed4be4123..f86a32ce9e6a 100755 --- a/drivers/gpu/arm/mali400/mali/linux/mali_ukk_wrappers.h +++ b/drivers/gpu/arm/mali400/mali/linux/mali_ukk_wrappers.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/platform/arm/arm.c b/drivers/gpu/arm/mali400/mali/platform/arm/arm.c index 011f242071d2..33f35bee7051 100755 --- a/drivers/gpu/arm/mali400/mali/platform/arm/arm.c +++ b/drivers/gpu/arm/mali400/mali/platform/arm/arm.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010, 2012-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010, 2012-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. @@ -30,6 +30,10 @@ #include "arm_core_scaling.h" #include "mali_executor.h" +#if defined(CONFIG_MALI_DEVFREQ) && defined(CONFIG_DEVFREQ_THERMAL) +#include +#include +#endif static int mali_core_scaling_enable = 0; @@ -39,6 +43,77 @@ static u32 mali_read_phys(u32 phys_addr); static void mali_write_phys(u32 phys_addr, u32 value); #endif +#if defined(CONFIG_ARCH_VEXPRESS) && defined(CONFIG_ARM64) + +#define SECURE_MODE_CONTROL_HANDLER 0x6F02006C +void *secure_mode_mapped_addr = NULL; +/** + * Enable/Disable Mali secure mode. + * @Return value: + * 0: success + * non-0: failure. + */ + +static int mali_secure_mode_enable_juno(void) +{ + u32 phys_offset = SECURE_MODE_CONTROL_HANDLER & 0x00001FFF; + MALI_DEBUG_ASSERT(NULL != secure_mode_mapped_addr); + + iowrite32(1, ((u8 *)secure_mode_mapped_addr) + phys_offset); + + if (1 == (u32)ioread32(((u8 *)secure_mode_mapped_addr) + phys_offset)) { + MALI_DEBUG_PRINT(3, ("Mali enables secured mode successfully! \n")); + return 0; + } + + MALI_PRINT_ERROR(("Failed to enable Mali secured mode !!! \n")); + + return -1; + +} + +static int mali_secure_mode_disable_juno(void) +{ + u32 phys_offset = SECURE_MODE_CONTROL_HANDLER & 0x00001FFF; + MALI_DEBUG_ASSERT(NULL != secure_mode_mapped_addr); + + iowrite32(0, ((u8 *)secure_mode_mapped_addr) + phys_offset); + + if (0 == (u32)ioread32(((u8 *)secure_mode_mapped_addr) + phys_offset)) { + MALI_DEBUG_PRINT(3, ("Mali disable secured mode successfully! \n")); + return 0; + } + + MALI_PRINT_ERROR(("Failed to disable mali secured mode !!! \n")); + return -1; +} + +static int mali_secure_mode_init_juno(void) +{ + u32 phys_addr_page = SECURE_MODE_CONTROL_HANDLER & 0xFFFFE000; + u32 phys_offset = SECURE_MODE_CONTROL_HANDLER & 0x00001FFF; + u32 map_size = phys_offset + sizeof(u32); + + MALI_DEBUG_ASSERT(NULL == secure_mode_mapped_addr); + + secure_mode_mapped_addr = ioremap_nocache(phys_addr_page, map_size); + if (NULL != secure_mode_mapped_addr) { + return mali_secure_mode_disable_juno(); + } + MALI_DEBUG_PRINT(2, ("Failed to ioremap for Mali secured mode! \n")); + return -1; +} + +static void mali_secure_mode_deinit_juno(void) +{ + if (NULL != secure_mode_mapped_addr) { + mali_secure_mode_disable_juno(); + iounmap(secure_mode_mapped_addr); + secure_mode_mapped_addr = NULL; + } +} +#endif + #ifndef CONFIG_MALI_DT static void mali_platform_device_release(struct device *device); @@ -101,14 +176,86 @@ static struct resource mali_gpu_resources_m400_mp2[] = { #endif #endif +#if defined(CONFIG_MALI_DEVFREQ) && defined(CONFIG_DEVFREQ_THERMAL) + +#define FALLBACK_STATIC_TEMPERATURE 55000 + +static struct thermal_zone_device *gpu_tz; + +/* Calculate gpu static power example for reference */ +static unsigned long arm_model_static_power(unsigned long voltage) +{ + int temperature, temp; + int temp_squared, temp_cubed, temp_scaling_factor; + const unsigned long coefficient = (410UL << 20) / (729000000UL >> 10); + const unsigned long voltage_cubed = (voltage * voltage * voltage) >> 10; + unsigned long static_power; + + if (gpu_tz) { + int ret; + + ret = gpu_tz->ops->get_temp(gpu_tz, &temperature); + if (ret) { + MALI_DEBUG_PRINT(2, ("Error reading temperature for gpu thermal zone: %d\n", ret)); + temperature = FALLBACK_STATIC_TEMPERATURE; + } + } else { + temperature = FALLBACK_STATIC_TEMPERATURE; + } + + /* Calculate the temperature scaling factor. To be applied to the + * voltage scaled power. + */ + temp = temperature / 1000; + temp_squared = temp * temp; + temp_cubed = temp_squared * temp; + temp_scaling_factor = + (2 * temp_cubed) + - (80 * temp_squared) + + (4700 * temp) + + 32000; + + static_power = (((coefficient * voltage_cubed) >> 20) + * temp_scaling_factor) + / 1000000; + + return static_power; +} + +/* Calculate gpu dynamic power example for reference */ +static unsigned long arm_model_dynamic_power(unsigned long freq, + unsigned long voltage) +{ + /* The inputs: freq (f) is in Hz, and voltage (v) in mV. + * The coefficient (c) is in mW/(MHz mV mV). + * + * This function calculates the dynamic power after this formula: + * Pdyn (mW) = c (mW/(MHz*mV*mV)) * v (mV) * v (mV) * f (MHz) + */ + const unsigned long v2 = (voltage * voltage) / 1000; /* m*(V*V) */ + const unsigned long f_mhz = freq / 1000000; /* MHz */ + const unsigned long coefficient = 3600; /* mW/(MHz*mV*mV) */ + unsigned long dynamic_power; + + dynamic_power = (coefficient * v2 * f_mhz) / 1000000; /* mW */ + + return dynamic_power; +} + +struct devfreq_cooling_power arm_cooling_ops = { + .get_static_power = arm_model_static_power, + .get_dynamic_power = arm_model_dynamic_power, +}; +#endif + static struct mali_gpu_device_data mali_gpu_data = { #ifndef CONFIG_MALI_DT .pmu_switch_delay = 0xFF, /* do not have to be this high on FPGA, but it is good for testing to have a delay */ - .max_job_runtime = 60000, /* 60 seconds */ #if defined(CONFIG_ARCH_VEXPRESS) .shared_mem_size = 256 * 1024 * 1024, /* 256MB */ #endif #endif + .max_job_runtime = 60000, /* 60 seconds */ #if defined(CONFIG_ARCH_REALVIEW) .dedicated_mem_start = 0x80000000, /* Physical start address (use 0xD0000000 for old indirect setup) */ @@ -129,6 +276,20 @@ static struct mali_gpu_device_data mali_gpu_data = { .get_clock_info = NULL, .get_freq = NULL, .set_freq = NULL, +#if defined(CONFIG_ARCH_VEXPRESS) && defined(CONFIG_ARM64) + .secure_mode_init = mali_secure_mode_init_juno, + .secure_mode_deinit = mali_secure_mode_deinit_juno, + .secure_mode_enable = mali_secure_mode_enable_juno, + .secure_mode_disable = mali_secure_mode_disable_juno, +#else + .secure_mode_init = NULL, + .secure_mode_deinit = NULL, + .secure_mode_enable = NULL, + .secure_mode_disable = NULL, +#endif +#if defined(CONFIG_MALI_DEVFREQ) && defined(CONFIG_DEVFREQ_THERMAL) + .gpu_cooling_ops = &arm_cooling_ops, +#endif }; #ifndef CONFIG_MALI_DT @@ -260,6 +421,9 @@ void mali_platform_device_unregister(void) MALI_DEBUG_PRINT(4, ("mali_platform_device_unregister() called\n")); mali_core_scaling_term(); +#ifdef CONFIG_PM_RUNTIME + pm_runtime_disable(&(mali_gpu_device.dev)); +#endif platform_device_unregister(&mali_gpu_device); platform_device_put(&mali_gpu_device); @@ -365,6 +529,18 @@ int mali_platform_device_init(struct platform_device *device) mali_core_scaling_init(num_pp_cores); } +#if defined(CONFIG_MALI_DEVFREQ) && defined(CONFIG_DEVFREQ_THERMAL) + /* Get thermal zone */ + gpu_tz = thermal_zone_get_zone_by_name("soc_thermal"); + if (IS_ERR(gpu_tz)) { + MALI_DEBUG_PRINT(2, ("Error getting gpu thermal zone (%ld), not yet ready?\n", + PTR_ERR(gpu_tz))); + gpu_tz = NULL; + + err = -EPROBE_DEFER; + } +#endif + return err; } @@ -375,6 +551,9 @@ int mali_platform_device_deinit(struct platform_device *device) MALI_DEBUG_PRINT(4, ("mali_platform_device_deinit() called\n")); mali_core_scaling_term(); +#ifdef CONFIG_PM_RUNTIME + pm_runtime_disable(&(device->dev)); +#endif #if defined(CONFIG_ARCH_REALVIEW) mali_write_phys(0xC0010020, 0x9); /* Restore default (legacy) memory mapping */ diff --git a/drivers/gpu/arm/mali400/mali/platform/arm/arm_core_scaling.c b/drivers/gpu/arm/mali400/mali/platform/arm/arm_core_scaling.c index 2c24742eb4de..37ab2ebf80e3 100755 --- a/drivers/gpu/arm/mali400/mali/platform/arm/arm_core_scaling.c +++ b/drivers/gpu/arm/mali400/mali/platform/arm/arm_core_scaling.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013-2015 ARM Limited. All rights reserved. + * Copyright (C) 2013-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/platform/arm/arm_core_scaling.h b/drivers/gpu/arm/mali400/mali/platform/arm/arm_core_scaling.h index 325b5b1c6894..b2ae3835bca0 100755 --- a/drivers/gpu/arm/mali400/mali/platform/arm/arm_core_scaling.h +++ b/drivers/gpu/arm/mali400/mali/platform/arm/arm_core_scaling.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2013, 2015 ARM Limited. All rights reserved. + * Copyright (C) 2013, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/platform/arm/juno_opp.c b/drivers/gpu/arm/mali400/mali/platform/arm/juno_opp.c new file mode 100644 index 000000000000..08be4e125d89 --- /dev/null +++ b/drivers/gpu/arm/mali400/mali/platform/arm/juno_opp.c @@ -0,0 +1,127 @@ +/* + * Copyright (C) 2010, 2012-2016 ARM Limited. All rights reserved. + * + * This program is free software and is provided to you under the terms of the GNU General Public License version 2 + * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. + * + * A copy of the licence is included with the program, and can also be obtained from Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +/** + * @file juno_opp.c + * Example: Set up opp table + * Using ARM64 juno specific SCPI_PROTOCOL get frequence inform + * Customer need implement your own platform releated logic + */ +#ifdef CONFIG_ARCH_VEXPRESS +#ifdef CONFIG_MALI_DEVFREQ +#ifdef CONFIG_ARM64 +#ifdef CONFIG_ARM_SCPI_PROTOCOL +#include +#include +#include +#include +#include +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0) +#include +#else /* Linux >= 3.13 */ +/* In 3.13 the OPP include header file, types, and functions were all + * renamed. Use the old filename for the include, and define the new names to + * the old, when an old kernel is detected. + */ +#include +#define dev_pm_opp_add opp_add +#define dev_pm_opp_remove opp_remove +#endif /* Linux >= 3.13 */ + +#include "mali_kernel_common.h" + +static int init_juno_opps_from_scpi(struct device *dev) +{ + struct scpi_dvfs_info *sinfo; + struct scpi_ops *sops; + + int i; + + sops = get_scpi_ops(); + if (NULL == sops) { + MALI_DEBUG_PRINT(2, ("Mali didn't get any scpi ops \n")); + return -1; + } + + /* Hard coded for Juno. 2 is GPU domain */ + sinfo = sops->dvfs_get_info(2); + if (IS_ERR_OR_NULL(sinfo)) + return PTR_ERR(sinfo); + + for (i = 0; i < sinfo->count; i++) { + struct scpi_opp *e = &sinfo->opps[i]; + + MALI_DEBUG_PRINT(2, ("Mali OPP from SCPI: %u Hz @ %u mV\n", e->freq, e->m_volt)); + + dev_pm_opp_add(dev, e->freq, e->m_volt * 1000); + } + + return 0; +} + +int setup_opps(void) +{ + struct device_node *np; + struct platform_device *pdev; + int err; + + np = of_find_node_by_name(NULL, "gpu"); + if (!np) { + pr_err("Failed to find DT entry for Mali\n"); + return -EFAULT; + } + + pdev = of_find_device_by_node(np); + if (!pdev) { + pr_err("Failed to find device for Mali\n"); + of_node_put(np); + return -EFAULT; + } + + err = init_juno_opps_from_scpi(&pdev->dev); + + of_node_put(np); + + return err; +} + +int term_opps(struct device *dev) +{ + struct scpi_dvfs_info *sinfo; + struct scpi_ops *sops; + + int i; + + sops = get_scpi_ops(); + if (NULL == sops) { + MALI_DEBUG_PRINT(2, ("Mali didn't get any scpi ops \n")); + return -1; + } + + /* Hard coded for Juno. 2 is GPU domain */ + sinfo = sops->dvfs_get_info(2); + if (IS_ERR_OR_NULL(sinfo)) + return PTR_ERR(sinfo); + + for (i = 0; i < sinfo->count; i++) { + struct scpi_opp *e = &sinfo->opps[i]; + + MALI_DEBUG_PRINT(2, ("Mali Remove OPP: %u Hz \n", e->freq)); + + dev_pm_opp_remove(dev, e->freq); + } + + return 0; + +} +#endif +#endif +#endif +#endif diff --git a/drivers/gpu/arm/mali400/mali/regs/mali_200_regs.h b/drivers/gpu/arm/mali400/mali/regs/mali_200_regs.h index e76f9926f5c0..c904ad23b28d 100755 --- a/drivers/gpu/arm/mali400/mali/regs/mali_200_regs.h +++ b/drivers/gpu/arm/mali400/mali/regs/mali_200_regs.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010, 2012-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010, 2012-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/regs/mali_gp_regs.h b/drivers/gpu/arm/mali400/mali/regs/mali_gp_regs.h index 9c101f9ddd22..435953d46e8b 100755 --- a/drivers/gpu/arm/mali400/mali/regs/mali_gp_regs.h +++ b/drivers/gpu/arm/mali400/mali/regs/mali_gp_regs.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010, 2012-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010, 2012-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/timestamp-arm11-cc/mali_timestamp.c b/drivers/gpu/arm/mali400/mali/timestamp-arm11-cc/mali_timestamp.c index a486e2f7684f..f7f7baf4d8be 100755 --- a/drivers/gpu/arm/mali400/mali/timestamp-arm11-cc/mali_timestamp.c +++ b/drivers/gpu/arm/mali400/mali/timestamp-arm11-cc/mali_timestamp.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2011, 2013, 2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2011, 2013, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/timestamp-arm11-cc/mali_timestamp.h b/drivers/gpu/arm/mali400/mali/timestamp-arm11-cc/mali_timestamp.h index 65f3ab274c09..757f6433bf3d 100755 --- a/drivers/gpu/arm/mali400/mali/timestamp-arm11-cc/mali_timestamp.h +++ b/drivers/gpu/arm/mali400/mali/timestamp-arm11-cc/mali_timestamp.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2011, 2013-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2011, 2013-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/timestamp-default/mali_timestamp.c b/drivers/gpu/arm/mali400/mali/timestamp-default/mali_timestamp.c index a486e2f7684f..f7f7baf4d8be 100755 --- a/drivers/gpu/arm/mali400/mali/timestamp-default/mali_timestamp.c +++ b/drivers/gpu/arm/mali400/mali/timestamp-default/mali_timestamp.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2011, 2013, 2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2011, 2013, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/mali/timestamp-default/mali_timestamp.h b/drivers/gpu/arm/mali400/mali/timestamp-default/mali_timestamp.h index 8ba47060828f..21700fe3216f 100755 --- a/drivers/gpu/arm/mali400/mali/timestamp-default/mali_timestamp.h +++ b/drivers/gpu/arm/mali400/mali/timestamp-default/mali_timestamp.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2011, 2013-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2011, 2013-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/ump/Kbuild b/drivers/gpu/arm/mali400/ump/Kbuild index 3342d7817561..a3067ba72459 100755 --- a/drivers/gpu/arm/mali400/ump/Kbuild +++ b/drivers/gpu/arm/mali400/ump/Kbuild @@ -50,7 +50,7 @@ endif ccflags-y += -DSVN_REV=$(SVN_REV) ccflags-y += -DSVN_REV_STRING=\"$(DRIVER_REV)\" -ccflags-y += -I$(src) -I$(src)/common -I$(src)/linux -I$(src)/../mali/common -I$(src)/../mali/linux -I$(src)/../../ump/include/ump +ccflags-y += -I$(src) -I$(src)/common -I$(src)/linux -I$(src)/../mali/common -I$(src)/../mali/linux -I$(src)/include -I$(src)/../../ump/include/ump ccflags-y += -DMALI_STATE_TRACKING=0 ccflags-y += -DMALI_ENABLE_CPU_CYCLES=0 ccflags-$(CONFIG_UMP_DEBUG) += -DDEBUG @@ -78,12 +78,15 @@ ump-y = common/ump_kernel_common.o \ linux/ump_osk_atomics.o \ linux/ump_osk_low_level_mem.o \ linux/ump_osk_misc.o \ - linux/ump_kernel_random_mapping.o \ - $(UDD_FILE_PREFIX)linux/mali_osk_atomics.o \ - $(UDD_FILE_PREFIX)linux/mali_osk_locks.o \ - $(UDD_FILE_PREFIX)linux/mali_osk_memory.o \ - $(UDD_FILE_PREFIX)linux/mali_osk_math.o \ - $(UDD_FILE_PREFIX)linux/mali_osk_misc.o + linux/ump_kernel_random_mapping.o + +ifneq ($(CONFIG_MALI400),y) +ump-y += $(UDD_FILE_PREFIX)linux/mali_osk_atomics.o \ + $(UDD_FILE_PREFIX)linux/mali_osk_locks.o \ + $(UDD_FILE_PREFIX)linux/mali_osk_memory.o \ + $(UDD_FILE_PREFIX)linux/mali_osk_math.o \ + $(UDD_FILE_PREFIX)linux/mali_osk_misc.o +endif obj-$(CONFIG_UMP) := ump.o diff --git a/drivers/gpu/arm/mali400/ump/Makefile b/drivers/gpu/arm/mali400/ump/Makefile index f24bc6c82a0f..4d4f02b0fb6b 100755 --- a/drivers/gpu/arm/mali400/ump/Makefile +++ b/drivers/gpu/arm/mali400/ump/Makefile @@ -1,5 +1,5 @@ # -# Copyright (C) 2010-2012, 2014-2015 ARM Limited. All rights reserved. +# Copyright (C) 2010-2012, 2014, 2016 ARM Limited. All rights reserved. # # This program is free software and is provided to you under the terms of the GNU General Public License version 2 # as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/ump/Makefile.common b/drivers/gpu/arm/mali400/ump/Makefile.common index 6b3b8d1efde4..00153ded9f98 100755 --- a/drivers/gpu/arm/mali400/ump/Makefile.common +++ b/drivers/gpu/arm/mali400/ump/Makefile.common @@ -1,5 +1,5 @@ # -# Copyright (C) 2010-2011, 2013, 2015 ARM Limited. All rights reserved. +# Copyright (C) 2010-2011, 2013, 2016 ARM Limited. All rights reserved. # # This program is free software and is provided to you under the terms of the GNU General Public License version 2 # as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/ump/arch-default/config.h b/drivers/gpu/arm/mali400/ump/arch-default/config.h index cfd2b34b5334..ddecfbb91f0c 100755 --- a/drivers/gpu/arm/mali400/ump/arch-default/config.h +++ b/drivers/gpu/arm/mali400/ump/arch-default/config.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010, 2012, 2014-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010, 2012, 2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/ump/arch-pb-virtex5/config.h b/drivers/gpu/arm/mali400/ump/arch-pb-virtex5/config.h index c2c56cf1c009..9160ce1cee80 100755 --- a/drivers/gpu/arm/mali400/ump/arch-pb-virtex5/config.h +++ b/drivers/gpu/arm/mali400/ump/arch-pb-virtex5/config.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2013, 2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2013, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/ump/common/ump_kernel_api.c b/drivers/gpu/arm/mali400/ump/common/ump_kernel_api.c index 21dde81ef419..2ad4ae5780fb 100755 --- a/drivers/gpu/arm/mali400/ump/common/ump_kernel_api.c +++ b/drivers/gpu/arm/mali400/ump/common/ump_kernel_api.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/ump/common/ump_kernel_common.c b/drivers/gpu/arm/mali400/ump/common/ump_kernel_common.c index ca410a8916c0..1f5ba4712725 100755 --- a/drivers/gpu/arm/mali400/ump/common/ump_kernel_common.c +++ b/drivers/gpu/arm/mali400/ump/common/ump_kernel_common.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/ump/common/ump_kernel_common.h b/drivers/gpu/arm/mali400/ump/common/ump_kernel_common.h index 2efe1ed1e789..1969c9734c87 100755 --- a/drivers/gpu/arm/mali400/ump/common/ump_kernel_common.h +++ b/drivers/gpu/arm/mali400/ump/common/ump_kernel_common.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. @@ -110,7 +110,7 @@ extern struct ump_dev device; _mali_osk_errcode_t ump_kernel_constructor(void); void ump_kernel_destructor(void); -int map_errcode(_mali_osk_errcode_t err); +int ump_map_errcode(_mali_osk_errcode_t err); /** * variables from user space cannot be dereferenced from kernel space; tagging them diff --git a/drivers/gpu/arm/mali400/ump/common/ump_kernel_descriptor_mapping.c b/drivers/gpu/arm/mali400/ump/common/ump_kernel_descriptor_mapping.c index 45e2bb4f7bd7..d22c049f0aa0 100755 --- a/drivers/gpu/arm/mali400/ump/common/ump_kernel_descriptor_mapping.c +++ b/drivers/gpu/arm/mali400/ump/common/ump_kernel_descriptor_mapping.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2011, 2013-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2011, 2013-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/ump/common/ump_kernel_descriptor_mapping.h b/drivers/gpu/arm/mali400/ump/common/ump_kernel_descriptor_mapping.h index 60d691739c08..bad215ab87a4 100755 --- a/drivers/gpu/arm/mali400/ump/common/ump_kernel_descriptor_mapping.h +++ b/drivers/gpu/arm/mali400/ump/common/ump_kernel_descriptor_mapping.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2011, 2013-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2011, 2013-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/ump/common/ump_kernel_memory_backend.h b/drivers/gpu/arm/mali400/ump/common/ump_kernel_memory_backend.h index 056244ebe162..1b4fbc50f6df 100755 --- a/drivers/gpu/arm/mali400/ump/common/ump_kernel_memory_backend.h +++ b/drivers/gpu/arm/mali400/ump/common/ump_kernel_memory_backend.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2011, 2013-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2011, 2013-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/ump/common/ump_kernel_ref_drv.c b/drivers/gpu/arm/mali400/ump/common/ump_kernel_ref_drv.c index 37a682ac9ba4..39f32afdead6 100755 --- a/drivers/gpu/arm/mali400/ump/common/ump_kernel_ref_drv.c +++ b/drivers/gpu/arm/mali400/ump/common/ump_kernel_ref_drv.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/ump/common/ump_kernel_types.h b/drivers/gpu/arm/mali400/ump/common/ump_kernel_types.h index 098ce1412738..a1c9bd3449f3 100755 --- a/drivers/gpu/arm/mali400/ump/common/ump_kernel_types.h +++ b/drivers/gpu/arm/mali400/ump/common/ump_kernel_types.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. @@ -15,6 +15,9 @@ #include "mali_osk.h" #include +#ifdef CONFIG_DMA_SHARED_BUFFER +#include +#endif typedef enum { UMP_USED_BY_CPU = 0, @@ -44,6 +47,10 @@ typedef struct ump_dd_mem { int is_cached; ump_hw_usage hw_device; ump_lock_usage lock_usage; +#ifdef CONFIG_DMA_SHARED_BUFFER + struct dma_buf_attachment *import_attach; + struct sg_table *sgt; +#endif } ump_dd_mem; diff --git a/drivers/gpu/arm/mali400/ump/common/ump_osk.h b/drivers/gpu/arm/mali400/ump/common/ump_osk.h index 6fe73662c6ae..bd1aef5aab54 100755 --- a/drivers/gpu/arm/mali400/ump/common/ump_osk.h +++ b/drivers/gpu/arm/mali400/ump/common/ump_osk.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/ump/common/ump_uk_types.h b/drivers/gpu/arm/mali400/ump/common/ump_uk_types.h index d91b0707d936..0e42a89db013 100755 --- a/drivers/gpu/arm/mali400/ump/common/ump_uk_types.h +++ b/drivers/gpu/arm/mali400/ump/common/ump_uk_types.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010, 2012-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010, 2012-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. @@ -48,6 +48,7 @@ typedef enum _UMP_IOC_SWITCH_HW_USAGE, _UMP_IOC_LOCK, _UMP_IOC_UNLOCK, + _UMP_IOC_DMABUF_IMPORT, } _ump_uk_functions; typedef enum @@ -186,6 +187,14 @@ typedef struct _ump_uk_unlock_s u32 secure_id; /**< [in] secure_id that identifies the ump buffer */ } _ump_uk_unlock_s; +typedef struct _ump_uk_dmabuf_s +{ + void *ctx; /**< [in,out] user-kernel context (trashed on output) */ + int fd; /**< [in] dmabuf_fd that identifies the dmabuf buffer */ + size_t size; /**< [in] size of the buffer */ + u32 secure_id; /**< [out] secure_id that identifies the ump buffer */ +} _ump_uk_dmabuf_s; + #ifdef __cplusplus } #endif diff --git a/drivers/gpu/arm/mali400/ump/common/ump_ukk.h b/drivers/gpu/arm/mali400/ump/common/ump_ukk.h index ad097e8b209d..b8b1624b015f 100755 --- a/drivers/gpu/arm/mali400/ump/common/ump_ukk.h +++ b/drivers/gpu/arm/mali400/ump/common/ump_ukk.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/ump/linux/license/gpl/ump_kernel_license.h b/drivers/gpu/arm/mali400/ump/linux/license/gpl/ump_kernel_license.h index f562e5699e5f..c0a1b838c600 100755 --- a/drivers/gpu/arm/mali400/ump/linux/license/gpl/ump_kernel_license.h +++ b/drivers/gpu/arm/mali400/ump/linux/license/gpl/ump_kernel_license.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010, 2013, 2015 ARM Limited. All rights reserved. + * Copyright (C) 2010, 2013, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/ump/linux/ump_ioctl.h b/drivers/gpu/arm/mali400/ump/linux/ump_ioctl.h index 70db873c3d3b..b3fe7d3661c4 100755 --- a/drivers/gpu/arm/mali400/ump/linux/ump_ioctl.h +++ b/drivers/gpu/arm/mali400/ump/linux/ump_ioctl.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2013, 2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2013, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. @@ -55,6 +55,7 @@ extern "C" { #define UMP_IOC_LOCK _IOW(UMP_IOCTL_NR, _UMP_IOC_LOCK, _ump_uk_lock_s) #define UMP_IOC_UNLOCK _IOW(UMP_IOCTL_NR, _UMP_IOC_UNLOCK, _ump_uk_unlock_s) +#define UMP_IOC_DMABUF_IMPORT _IOW(UMP_IOCTL_NR, _UMP_IOC_DMABUF_IMPORT, _ump_uk_dmabuf_s) #ifdef __cplusplus } diff --git a/drivers/gpu/arm/mali400/ump/linux/ump_kernel_linux.c b/drivers/gpu/arm/mali400/ump/linux/ump_kernel_linux.c index 77a5b21564c0..32a42ca6b6f7 100755 --- a/drivers/gpu/arm/mali400/ump/linux/ump_kernel_linux.c +++ b/drivers/gpu/arm/mali400/ump/linux/ump_kernel_linux.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. @@ -73,7 +73,7 @@ struct ump_device { /* The global variable containing the global device data */ static struct ump_device ump_device; - +struct device *ump_global_mdev = NULL; /* Forward declare static functions */ static int ump_file_open(struct inode *inode, struct file *filp); @@ -112,7 +112,7 @@ static int ump_initialize_module(void) err = ump_kernel_constructor(); if (_MALI_OSK_ERR_OK != err) { MSG_ERR(("UMP device driver init failed\n")); - return map_errcode(err); + return ump_map_errcode(err); } MSG(("UMP device driver %s loaded\n", SVN_REV_STRING)); @@ -192,13 +192,12 @@ int ump_kernel_device_initialize(void) if (IS_ERR(ump_device.ump_class)) { err = PTR_ERR(ump_device.ump_class); } else { - struct device *mdev; - mdev = device_create(ump_device.ump_class, NULL, dev, NULL, ump_dev_name); - if (!IS_ERR(mdev)) { + ump_global_mdev = device_create(ump_device.ump_class, NULL, dev, NULL, ump_dev_name); + if (!IS_ERR(ump_global_mdev)) { return 0; } - err = PTR_ERR(mdev); + err = PTR_ERR(ump_global_mdev); } cdev_del(&ump_device.cdev); #else @@ -256,7 +255,7 @@ static int ump_file_open(struct inode *inode, struct file *filp) err = _ump_ukk_open((void **) &session_data); if (_MALI_OSK_ERR_OK != err) { MSG_ERR(("Ump failed to open a new session\n")); - return map_errcode(err); + return ump_map_errcode(err); } filp->private_data = (void *)session_data; @@ -276,7 +275,7 @@ static int ump_file_release(struct inode *inode, struct file *filp) err = _ump_ukk_close((void **) &filp->private_data); if (_MALI_OSK_ERR_OK != err) { - return map_errcode(err); + return ump_map_errcode(err); } return 0; /* success */ @@ -347,6 +346,15 @@ static int ump_file_ioctl(struct inode *inode, struct file *filp, unsigned int c err = ump_unlock_wrapper((u32 __user *)argument, session_data); break; + case UMP_IOC_DMABUF_IMPORT: + #ifdef CONFIG_DMA_SHARED_BUFFER + err = ump_dmabuf_import_wrapper((u32 __user *)argument, session_data); + #else + err = -EFAULT; + DBG_MSG(1, ("User space use dmabuf API, but kernel don't support DMA BUF\n")); + #endif + break; + default: DBG_MSG(1, ("No handler for IOCTL. cmd: 0x%08x, arg: 0x%08lx\n", cmd, arg)); err = -EFAULT; @@ -356,7 +364,7 @@ static int ump_file_ioctl(struct inode *inode, struct file *filp, unsigned int c return err; } -int map_errcode(_mali_osk_errcode_t err) +int ump_map_errcode(_mali_osk_errcode_t err) { switch (err) { case _MALI_OSK_ERR_OK : @@ -418,7 +426,7 @@ static int ump_file_mmap(struct file *filp, struct vm_area_struct *vma) err = _ump_ukk_map_mem(&args); if (_MALI_OSK_ERR_OK != err) { MSG_ERR(("_ump_ukk_map_mem() failed in function ump_file_mmap()")); - return map_errcode(err); + return ump_map_errcode(err); } return 0; /* success */ diff --git a/drivers/gpu/arm/mali400/ump/linux/ump_kernel_linux.h b/drivers/gpu/arm/mali400/ump/linux/ump_kernel_linux.h index 41dae7988c49..f7c0a96beddb 100755 --- a/drivers/gpu/arm/mali400/ump/linux/ump_kernel_linux.h +++ b/drivers/gpu/arm/mali400/ump/linux/ump_kernel_linux.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2013, 2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2013, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/ump/linux/ump_kernel_memory_backend_dedicated.c b/drivers/gpu/arm/mali400/ump/linux/ump_kernel_memory_backend_dedicated.c index 9f329e9524a1..517b46bbc04d 100755 --- a/drivers/gpu/arm/mali400/ump/linux/ump_kernel_memory_backend_dedicated.c +++ b/drivers/gpu/arm/mali400/ump/linux/ump_kernel_memory_backend_dedicated.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2011, 2013-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2011, 2013-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/ump/linux/ump_kernel_memory_backend_dedicated.h b/drivers/gpu/arm/mali400/ump/linux/ump_kernel_memory_backend_dedicated.h index 283dde793835..8c1ea1e749f6 100755 --- a/drivers/gpu/arm/mali400/ump/linux/ump_kernel_memory_backend_dedicated.h +++ b/drivers/gpu/arm/mali400/ump/linux/ump_kernel_memory_backend_dedicated.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010, 2014-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010, 2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/ump/linux/ump_kernel_memory_backend_os.c b/drivers/gpu/arm/mali400/ump/linux/ump_kernel_memory_backend_os.c index 763b6109e486..f7791b0c07d7 100755 --- a/drivers/gpu/arm/mali400/ump/linux/ump_kernel_memory_backend_os.c +++ b/drivers/gpu/arm/mali400/ump/linux/ump_kernel_memory_backend_os.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2011, 2013-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2011, 2013-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/ump/linux/ump_kernel_memory_backend_os.h b/drivers/gpu/arm/mali400/ump/linux/ump_kernel_memory_backend_os.h index 22666573bec7..2d62f4dd1448 100755 --- a/drivers/gpu/arm/mali400/ump/linux/ump_kernel_memory_backend_os.h +++ b/drivers/gpu/arm/mali400/ump/linux/ump_kernel_memory_backend_os.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010, 2014-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010, 2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/ump/linux/ump_kernel_random_mapping.c b/drivers/gpu/arm/mali400/ump/linux/ump_kernel_random_mapping.c index 8fed5c38508a..cd1c457ca75d 100755 --- a/drivers/gpu/arm/mali400/ump/linux/ump_kernel_random_mapping.c +++ b/drivers/gpu/arm/mali400/ump/linux/ump_kernel_random_mapping.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2011, 2013-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2011, 2013-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. @@ -186,6 +186,21 @@ void ump_random_mapping_put(ump_dd_mem *mem) if (0 == new_ref) { DBG_MSG(3, ("Final release of memory. ID: %u\n", mem->secure_id)); +#ifdef CONFIG_DMA_SHARED_BUFFER + if (mem->import_attach) { + struct dma_buf_attachment *attach = mem->import_attach; + struct dma_buf *dma_buf; + + if (mem->sgt) + dma_buf_unmap_attachment(attach, mem->sgt, + DMA_BIDIRECTIONAL); + + dma_buf = attach->dmabuf; + dma_buf_detach(attach->dmabuf, attach); + dma_buf_put(dma_buf); + + } +#endif ump_random_mapping_remove_internal(device.secure_id_map, mem->secure_id); mem->release_func(mem->ctx, mem); diff --git a/drivers/gpu/arm/mali400/ump/linux/ump_kernel_random_mapping.h b/drivers/gpu/arm/mali400/ump/linux/ump_kernel_random_mapping.h index d304157b1ffb..67d4a864bc47 100755 --- a/drivers/gpu/arm/mali400/ump/linux/ump_kernel_random_mapping.h +++ b/drivers/gpu/arm/mali400/ump/linux/ump_kernel_random_mapping.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2011, 2013-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2011, 2013-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/ump/linux/ump_memory_backend.c b/drivers/gpu/arm/mali400/ump/linux/ump_memory_backend.c index 3baa2ac4aa23..87b141904cf1 100755 --- a/drivers/gpu/arm/mali400/ump/linux/ump_memory_backend.c +++ b/drivers/gpu/arm/mali400/ump/linux/ump_memory_backend.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010, 2013-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010, 2013-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/ump/linux/ump_osk_atomics.c b/drivers/gpu/arm/mali400/ump/linux/ump_osk_atomics.c index 9fae2953308a..f9fc1943b140 100755 --- a/drivers/gpu/arm/mali400/ump/linux/ump_osk_atomics.c +++ b/drivers/gpu/arm/mali400/ump/linux/ump_osk_atomics.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010, 2014-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010, 2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/ump/linux/ump_osk_low_level_mem.c b/drivers/gpu/arm/mali400/ump/linux/ump_osk_low_level_mem.c index 0d81fbe326b0..ef35052f68bc 100755 --- a/drivers/gpu/arm/mali400/ump/linux/ump_osk_low_level_mem.c +++ b/drivers/gpu/arm/mali400/ump/linux/ump_osk_low_level_mem.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/ump/linux/ump_osk_misc.c b/drivers/gpu/arm/mali400/ump/linux/ump_osk_misc.c index bd985d3afb72..ce0ab06f8e41 100755 --- a/drivers/gpu/arm/mali400/ump/linux/ump_osk_misc.c +++ b/drivers/gpu/arm/mali400/ump/linux/ump_osk_misc.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010, 2013-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010, 2013-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/ump/linux/ump_ukk_ref_wrappers.c b/drivers/gpu/arm/mali400/ump/linux/ump_ukk_ref_wrappers.c index 8350d3e0b75b..4a58e93e60df 100755 --- a/drivers/gpu/arm/mali400/ump/linux/ump_ukk_ref_wrappers.c +++ b/drivers/gpu/arm/mali400/ump/linux/ump_ukk_ref_wrappers.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010, 2013-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010, 2013-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. @@ -20,6 +20,11 @@ #include "ump_uk_types.h" #include "ump_ukk.h" #include "ump_kernel_common.h" +#include +#include "ump_kernel_interface_ref_drv.h" +#include "mali_osk_list.h" + +extern struct device *ump_global_mdev; /* * IOCTL operation; Allocate UMP memory @@ -46,7 +51,7 @@ int ump_allocate_wrapper(u32 __user *argument, struct ump_session_data *sessio err = _ump_ukk_allocate(&user_interaction); if (_MALI_OSK_ERR_OK != err) { DBG_MSG(1, ("_ump_ukk_allocate() failed in ump_ioctl_allocate()\n")); - return map_errcode(err); + return ump_map_errcode(err); } user_interaction.ctx = NULL; @@ -69,3 +74,157 @@ int ump_allocate_wrapper(u32 __user *argument, struct ump_session_data *sessio return 0; /* success */ } + +#ifdef CONFIG_DMA_SHARED_BUFFER +static ump_dd_handle get_ump_handle_from_dmabuf(struct ump_session_data *session_data, + struct dma_buf *dmabuf) +{ + ump_session_memory_list_element *session_mem, *tmp; + struct dma_buf_attachment *attach; + ump_dd_handle ump_handle; + + DEBUG_ASSERT_POINTER(session_data); + + _mali_osk_mutex_wait(session_data->lock); + + _MALI_OSK_LIST_FOREACHENTRY(session_mem, tmp, + &session_data->list_head_session_memory_list, + ump_session_memory_list_element, list) { + if (session_mem->mem->import_attach) { + attach = session_mem->mem->import_attach; + if (attach->dmabuf == dmabuf) { + _mali_osk_mutex_signal(session_data->lock); + ump_handle = (ump_dd_handle)session_mem->mem; + ump_random_mapping_get(device.secure_id_map, ump_dd_secure_id_get(ump_handle)); + return ump_handle; + } + } + } + + _mali_osk_mutex_signal(session_data->lock); + + return NULL; +} + +int ump_dmabuf_import_wrapper(u32 __user *argument, + struct ump_session_data *session_data) +{ + ump_session_memory_list_element *session = NULL; + _ump_uk_dmabuf_s ump_dmabuf; + ump_dd_handle ump_handle; + ump_dd_physical_block *blocks = NULL; + struct dma_buf_attachment *attach = NULL; + struct dma_buf *dma_buf; + struct sg_table *sgt = NULL; + struct scatterlist *sgl; + unsigned int i = 0; + int ret = 0; + + /* Sanity check input parameters */ + if (!argument || !session_data) { + MSG_ERR(("NULL parameter.\n")); + return -EINVAL; + } + + if (copy_from_user(&ump_dmabuf, argument, + sizeof(_ump_uk_dmabuf_s))) { + MSG_ERR(("copy_from_user() failed.\n")); + return -EFAULT; + } + + dma_buf = dma_buf_get(ump_dmabuf.fd); + if (IS_ERR(dma_buf)) + return PTR_ERR(dma_buf); + + /* + * if already imported then increase a refcount to the ump descriptor + * and call dma_buf_put() and then go to found to return previous + * ump secure id. + */ + ump_handle = get_ump_handle_from_dmabuf(session_data, dma_buf); + if (ump_handle) { + dma_buf_put(dma_buf); + goto found; + } + + attach = dma_buf_attach(dma_buf, ump_global_mdev); + if (IS_ERR(attach)) { + ret = PTR_ERR(attach); + goto err_dma_buf_put; + } + + sgt = dma_buf_map_attachment(attach, DMA_BIDIRECTIONAL); + if (IS_ERR(sgt)) { + ret = PTR_ERR(sgt); + goto err_dma_buf_detach; + } + + blocks = (ump_dd_physical_block *)_mali_osk_malloc(sizeof(ump_dd_physical_block) * sgt->nents); + if (!blocks) { + DBG_MSG(1, ("Failed to allocate blocks.\n")); + ret = -EFAULT; + goto err_dma_buf_unmap; + } + for_each_sg(sgt->sgl, sgl, sgt->nents, i) { + blocks[i].addr = sg_phys(sgl); + blocks[i].size = sg_dma_len(sgl); + } + + /* + * Initialize the session memory list element, and add it + * to the session object + */ + session = _mali_osk_calloc(1, sizeof(*session)); + if (!session) { + DBG_MSG(1, ("Failed to allocate session.\n")); + ret = -EFAULT; + goto err_free_block; + } + + ump_handle = ump_dd_handle_create_from_phys_blocks(blocks, i); + if (UMP_DD_HANDLE_INVALID == ump_handle) { + DBG_MSG(1, ("Failed to create ump handle.\n")); + ret = -EFAULT; + goto err_free_session; + } + + session->mem = (ump_dd_mem *)ump_handle; + session->mem->import_attach = attach; + session->mem->sgt = sgt; + + _mali_osk_mutex_wait(session_data->lock); + _mali_osk_list_add(&(session->list), + &(session_data->list_head_session_memory_list)); + _mali_osk_mutex_signal(session_data->lock); + + _mali_osk_free(blocks); + +found: + ump_dmabuf.ctx = (void *)session_data; + ump_dmabuf.secure_id = ump_dd_secure_id_get(ump_handle); + ump_dmabuf.size = ump_dd_size_get(ump_handle); + + if (copy_to_user(argument, &ump_dmabuf, + sizeof(_ump_uk_dmabuf_s))) { + MSG_ERR(("copy_to_user() failed.\n")); + ret = -EFAULT; + goto err_release_ump_handle; + } + + return ret; + +err_release_ump_handle: + ump_dd_reference_release(ump_handle); +err_free_session: + _mali_osk_free(session); +err_free_block: + _mali_osk_free(blocks); +err_dma_buf_unmap: + dma_buf_unmap_attachment(attach, sgt, DMA_BIDIRECTIONAL); +err_dma_buf_detach: + dma_buf_detach(dma_buf, attach); +err_dma_buf_put: + dma_buf_put(dma_buf); + return ret; +} +#endif diff --git a/drivers/gpu/arm/mali400/ump/linux/ump_ukk_ref_wrappers.h b/drivers/gpu/arm/mali400/ump/linux/ump_ukk_ref_wrappers.h index d0cdbb5281ff..b8b2ccefe603 100755 --- a/drivers/gpu/arm/mali400/ump/linux/ump_ukk_ref_wrappers.h +++ b/drivers/gpu/arm/mali400/ump/linux/ump_ukk_ref_wrappers.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010, 2013-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010, 2013-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. @@ -25,7 +25,9 @@ extern "C" { int ump_allocate_wrapper(u32 __user *argument, struct ump_session_data *session_data); - +#ifdef CONFIG_DMA_SHARED_BUFFER +int ump_dmabuf_import_wrapper(u32 __user *argument, struct ump_session_data *session_data); +#endif #ifdef __cplusplus } diff --git a/drivers/gpu/arm/mali400/ump/linux/ump_ukk_wrappers.c b/drivers/gpu/arm/mali400/ump/linux/ump_ukk_wrappers.c index 2616ebf2c81f..2a88f50b545d 100755 --- a/drivers/gpu/arm/mali400/ump/linux/ump_ukk_wrappers.c +++ b/drivers/gpu/arm/mali400/ump/linux/ump_ukk_wrappers.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. @@ -44,7 +44,7 @@ int ump_get_api_version_wrapper(u32 __user *argument, struct ump_session_data *s err = _ump_uku_get_api_version(&version_info); if (_MALI_OSK_ERR_OK != err) { MSG_ERR(("_ump_uku_get_api_version() failed in ump_ioctl_get_api_version()\n")); - return map_errcode(err); + return ump_map_errcode(err); } version_info.ctx = NULL; @@ -83,7 +83,7 @@ int ump_release_wrapper(u32 __user *argument, struct ump_session_data *session err = _ump_ukk_release(&release_args); if (_MALI_OSK_ERR_OK != err) { MSG_ERR(("_ump_ukk_release() failed in ump_ioctl_release()\n")); - return map_errcode(err); + return ump_map_errcode(err); } @@ -113,7 +113,7 @@ int ump_size_get_wrapper(u32 __user *argument, struct ump_session_data *sessio err = _ump_ukk_size_get(&user_interaction); if (_MALI_OSK_ERR_OK != err) { MSG_ERR(("_ump_ukk_size_get() failed in ump_ioctl_size_get()\n")); - return map_errcode(err); + return ump_map_errcode(err); } user_interaction.ctx = NULL; diff --git a/drivers/gpu/arm/mali400/ump/linux/ump_ukk_wrappers.h b/drivers/gpu/arm/mali400/ump/linux/ump_ukk_wrappers.h index 05000804af0a..1adad5b798c9 100755 --- a/drivers/gpu/arm/mali400/ump/linux/ump_ukk_wrappers.h +++ b/drivers/gpu/arm/mali400/ump/linux/ump_ukk_wrappers.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010, 2012-2015 ARM Limited. All rights reserved. + * Copyright (C) 2010, 2012-2014, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/umplock/Makefile b/drivers/gpu/arm/mali400/umplock/Makefile index 8b5a6d9be821..d3dc0e3c0ad2 100755 --- a/drivers/gpu/arm/mali400/umplock/Makefile +++ b/drivers/gpu/arm/mali400/umplock/Makefile @@ -1,5 +1,5 @@ # -# Copyright (C) 2012, 2015 ARM Limited. All rights reserved. +# Copyright (C) 2012, 2016 ARM Limited. All rights reserved. # # This program is free software and is provided to you under the terms of the GNU General Public License version 2 # as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/umplock/umplock_driver.c b/drivers/gpu/arm/mali400/umplock/umplock_driver.c index f117177fcc3e..ccd96d3ecab8 100755 --- a/drivers/gpu/arm/mali400/umplock/umplock_driver.c +++ b/drivers/gpu/arm/mali400/umplock/umplock_driver.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012-2015 ARM Limited. All rights reserved. + * Copyright (C) 2012-2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. diff --git a/drivers/gpu/arm/mali400/umplock/umplock_ioctl.h b/drivers/gpu/arm/mali400/umplock/umplock_ioctl.h index f7d8176a7ed9..32462f32ec72 100755 --- a/drivers/gpu/arm/mali400/umplock/umplock_ioctl.h +++ b/drivers/gpu/arm/mali400/umplock/umplock_ioctl.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012-2013, 2015 ARM Limited. All rights reserved. + * Copyright (C) 2012-2013, 2016 ARM Limited. All rights reserved. * * This program is free software and is provided to you under the terms of the GNU General Public License version 2 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence. -- 2.34.1