X-Git-Url: http://plrg.eecs.uci.edu/git/?p=firefly-linux-kernel-4.4.55.git;a=blobdiff_plain;f=drivers%2Fgpu%2Farm%2Fmali400%2Fmali%2Flinux%2Fmali_kernel_linux.c;h=ae4fad8d7588cc8fd6e4284236e46691cf14c024;hp=57d8695d545e3196a4769315ddc31c89433f5aa8;hb=c0778d1eb7829ad92288004ae5bc18206aa7af43;hpb=e8c6610a9bbf478da8e5260fa69fb48cb120cd70 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 57d8695d545e..ae4fad8d7588 100755 --- a/drivers/gpu/arm/mali400/mali/linux/mali_kernel_linux.c +++ b/drivers/gpu/arm/mali400/mali/linux/mali_kernel_linux.c @@ -1,17 +1,21 @@ /** - * This confidential and proprietary software may be used only as - * authorised by a licensing agreement from ARM Limited - * (C) COPYRIGHT 2008-2013 ARM Limited - * ALL RIGHTS RESERVED - * The entire notice above must be reproduced on all authorised - * copies and copies may only be made to the extent permitted - * by a licensing agreement from ARM Limited. + * Copyright (C) 2010-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. */ + /** * @file mali_kernel_linux.c * Implementation of the Linux device driver entrypoints */ +#include "../platform/rk30/custom_log.h" +#include "../platform/rk30/rk_ext.h" + #include /* kernel module definitions */ #include /* file system operations */ #include /* character device definitions */ @@ -22,6 +26,9 @@ #include "mali_kernel_license.h" #include #include +#include +#include + #include #include "mali_kernel_common.h" #include "mali_session.h" @@ -35,16 +42,29 @@ #include "mali_kernel_license.h" #include "mali_memory.h" #include "mali_memory_dma_buf.h" +#include "mali_memory_manager.h" +#include "mali_memory_swap_alloc.h" #if defined(CONFIG_MALI400_INTERNAL_PROFILING) #include "mali_profiling_internal.h" #endif -#include +#if defined(CONFIG_MALI400_PROFILING) && defined(CONFIG_MALI_DVFS) +#include "mali_osk_profiling.h" +#include "mali_dvfs_policy.h" + +static int is_first_resume = 1; +/*Store the clk and vol for boot/insmod and mali_resume*/ +static struct mali_gpu_clk_item mali_gpu_clk[2]; +#endif /* Streamline support for the Mali driver */ #if defined(CONFIG_TRACEPOINTS) && defined(CONFIG_MALI400_PROFILING) /* Ask Linux to create the tracepoints */ #define CREATE_TRACE_POINTS #include "mali_linux_trace.h" + +EXPORT_TRACEPOINT_SYMBOL_GPL(mali_timeline_event); +EXPORT_TRACEPOINT_SYMBOL_GPL(mali_hw_counter); +EXPORT_TRACEPOINT_SYMBOL_GPL(mali_sw_counters); #endif /* CONFIG_TRACEPOINTS */ /* from the __malidrv_build_info.c file that is generated during build */ @@ -71,8 +91,8 @@ extern unsigned int mali_dedicated_mem_size; module_param(mali_dedicated_mem_size, uint, S_IRUSR | S_IRGRP | S_IROTH); MODULE_PARM_DESC(mali_dedicated_mem_size, "Size of dedicated Mali GPU memory."); -extern unsigned long mali_shared_mem_size; -module_param(mali_shared_mem_size, ulong, S_IRUSR | S_IRGRP | S_IROTH); +extern unsigned int mali_shared_mem_size; +module_param(mali_shared_mem_size, uint, S_IRUSR | S_IRGRP | S_IROTH); MODULE_PARM_DESC(mali_shared_mem_size, "Size of shared Mali GPU memory."); #if defined(CONFIG_MALI400_PROFILING) @@ -89,7 +109,11 @@ extern int mali_max_pp_cores_group_2; module_param(mali_max_pp_cores_group_2, int, S_IRUSR | S_IRGRP | S_IROTH); MODULE_PARM_DESC(mali_max_pp_cores_group_2, "Limit the number of PP cores to use from second PP group (Mali-450 only)."); -#if defined(CONFIG_MALI400_POWER_PERFORMANCE_POLICY) +extern unsigned int mali_mem_swap_out_threshold_value; +module_param(mali_mem_swap_out_threshold_value, uint, S_IRUSR | S_IRGRP | S_IROTH); +MODULE_PARM_DESC(mali_mem_swap_out_threshold_value, "Threshold value used to limit how much swappable memory cached in Mali driver."); + +#if defined(CONFIG_MALI_DVFS) /** the max fps the same as display vsync default 60, can set by module insert parameter */ extern int mali_max_system_fps; module_param(mali_max_system_fps, int, S_IRUSR | S_IWUSR | S_IWGRP | S_IRGRP | S_IROTH); @@ -146,13 +170,17 @@ static int mali_driver_runtime_idle(struct device *dev); #endif #if defined(MALI_FAKE_PLATFORM_DEVICE) -extern int mali_platform_device_register(struct platform_device *pdev); -extern int mali_platform_device_unregister(struct platform_device *pdev); +#if defined(CONFIG_MALI_DT) +extern int mali_platform_device_init(struct platform_device *device); +extern int mali_platform_device_deinit(struct platform_device *device); +#else +extern int mali_platform_device_register(void); +extern int mali_platform_device_unregister(void); +#endif #endif - /* Linux power management operations provided by the Mali device driver */ -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29)) +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29)) struct pm_ext_ops mali_dev_ext_pm_ops = { .base = { @@ -177,19 +205,27 @@ static const struct dev_pm_ops mali_dev_pm_ops = { }; #endif -#ifdef CONFIG_OF -static const struct of_device_id mali_dt_ids[] = { - { .compatible = "arm,mali400" }, - { /* sentinel */ } +#ifdef CONFIG_MALI_DT +static struct of_device_id base_dt_ids[] = { + {.compatible = "arm,mali-300"}, + /*-------------------------------------------------------*/ + /* rk_ext : to use dts_for_mali_ko_befor_r5p0-01rel0. */ + // {.compatible = "arm,mali-400"}, + {.compatible = "arm,mali400"}, + /*-------------------------------------------------------*/ + {.compatible = "arm,mali-450"}, + {.compatible = "arm,mali-470"}, + {}, }; -MODULE_DEVICE_TABLE(of, mali_dt_ids); + +MODULE_DEVICE_TABLE(of, base_dt_ids); #endif /* The Mali device driver struct */ static struct platform_driver mali_platform_driver = { .probe = mali_probe, .remove = mali_remove, -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29)) +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29)) .pm = &mali_dev_ext_pm_ops, #endif .driver = @@ -197,9 +233,11 @@ static struct platform_driver mali_platform_driver = { .name = MALI_GPU_NAME_UTGARD, .owner = THIS_MODULE, .bus = &platform_bus_type, -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29)) +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29)) .pm = &mali_dev_pm_ops, - .of_match_table = of_match_ptr(mali_dt_ids), +#endif +#ifdef CONFIG_MALI_DT + .of_match_table = of_match_ptr(base_dt_ids), #endif }, }; @@ -214,10 +252,10 @@ struct file_operations mali_fops = { #else .ioctl = mali_ioctl, #endif + .compat_ioctl = mali_ioctl, .mmap = mali_mmap }; - #if MALI_ENABLE_CPU_CYCLES void mali_init_cpu_time_counters(int reset, int enable_divide_by_64) { @@ -230,30 +268,31 @@ void mali_init_cpu_time_counters(int reset, int enable_divide_by_64) /* See B4.1.117 PMCR, Performance Monitors Control Register. Writing to p15, c9, c12, 0 */ - write_value = 1<<0; /* Bit 0 set. Enable counters */ + write_value = 1 << 0; /* Bit 0 set. Enable counters */ if (reset) { - write_value |= 1<<1; /* Reset event counters */ - write_value |= 1<<2; /* Reset cycle counter */ + write_value |= 1 << 1; /* Reset event counters */ + write_value |= 1 << 2; /* Reset cycle counter */ } if (enable_divide_by_64) { - write_value |= 1<<3; /* Enable the Clock divider by 64 */ + write_value |= 1 << 3; /* Enable the Clock divider by 64 */ } - write_value |= 1<<4; /* Export enable. Not needed */ - asm volatile ("MCR p15, 0, %0, c9, c12, 0\t\n" :: "r"(write_value )); + write_value |= 1 << 4; /* Export enable. Not needed */ + asm volatile("MCR p15, 0, %0, c9, c12, 0\t\n" :: "r"(write_value)); /* PMOVSR Overflow Flag Status Register - Clear Clock and Event overflows */ - asm volatile ("MCR p15, 0, %0, c9, c12, 3\t\n" :: "r"(0x8000000f)); + asm volatile("MCR p15, 0, %0, c9, c12, 3\t\n" :: "r"(0x8000000f)); /* See B4.1.124 PMUSERENR - setting p15 c9 c14 to 1" */ /* User mode access to the Performance Monitors enabled. */ /* Lets User space read cpu clock cycles */ - asm volatile( "mcr p15, 0, %0, c9, c14, 0" :: "r"(1) ); + asm volatile("mcr p15, 0, %0, c9, c14, 0" :: "r"(1)); } /** A timer function that configures the cycle clock counter on current CPU. - The function \a mali_init_cpu_time_counters_on_all_cpus sets up this function - to trigger on all Cpus during module load. */ + * The function \a mali_init_cpu_time_counters_on_all_cpus sets up this + * function to trigger on all Cpus during module load. + */ static void mali_init_cpu_clock_timer_func(unsigned long data) { int reset_counters, enable_divide_clock_counter_by_64; @@ -263,7 +302,7 @@ static void mali_init_cpu_clock_timer_func(unsigned long data) MALI_IGNORE(data); - reset_counters= 1; + reset_counters = 1; enable_divide_clock_counter_by_64 = 0; mali_init_cpu_time_counters(reset_counters, enable_divide_clock_counter_by_64); @@ -274,7 +313,8 @@ static void mali_init_cpu_clock_timer_func(unsigned long data) } /** A timer functions for storing current time on all cpus. - Used for checking if the clocks have similar values or if they are drifting. */ + * Used for checking if the clocks have similar values or if they are drifting. + */ static void mali_print_cpu_clock_timer_func(unsigned long data) { int current_cpu = raw_smp_processor_id(); @@ -282,14 +322,15 @@ static void mali_print_cpu_clock_timer_func(unsigned long data) MALI_IGNORE(data); sample0 = mali_get_cpu_cyclecount(); - if ( current_cpu<8 ) { + if (current_cpu < 8) { mali_cpu_clock_last_value[current_cpu] = sample0; } } /** Init the performance registers on all CPUs to count clock cycles. - For init \a print_only should be 0. - If \a print_only is 1, it will intead print the current clock value of all CPUs.*/ + * For init \a print_only should be 0. + * If \a print_only is 1, it will intead print the current clock value of all CPUs. + */ void mali_init_cpu_time_counters_on_all_cpus(int print_only) { int i = 0; @@ -300,14 +341,14 @@ void mali_init_cpu_time_counters_on_all_cpus(int print_only) jiffies_wait = 2; jiffies_trigger = jiffies + jiffies_wait; - for ( i=0 ; i < 8 ; i++ ) { + for (i = 0 ; i < 8 ; i++) { init_timer(&mali_init_cpu_clock_timers[i]); if (print_only) mali_init_cpu_clock_timers[i].function = mali_print_cpu_clock_timer_func; else mali_init_cpu_clock_timers[i].function = mali_init_cpu_clock_timer_func; mali_init_cpu_clock_timers[i].expires = jiffies_trigger ; } cpu_number = cpumask_first(cpu_online_mask); - for ( i=0 ; i < 8 ; i++ ) { + for (i = 0 ; i < 8 ; i++) { int next_cpu; add_timer_on(&mali_init_cpu_clock_timers[i], cpu_number); next_cpu = cpumask_next(cpu_number, cpu_online_mask); @@ -315,32 +356,37 @@ void mali_init_cpu_time_counters_on_all_cpus(int print_only) cpu_number = next_cpu; } - while (jiffies_wait) jiffies_wait= schedule_timeout_uninterruptible(jiffies_wait); + while (jiffies_wait) jiffies_wait = schedule_timeout_uninterruptible(jiffies_wait); - for ( i=0 ; i < 8 ; i++ ) { + for (i = 0 ; i < 8 ; i++) { del_timer_sync(&mali_init_cpu_clock_timers[i]); } if (print_only) { - if ( (0==mali_cpu_clock_last_value[2]) && (0==mali_cpu_clock_last_value[3]) ) { + if ((0 == mali_cpu_clock_last_value[2]) && (0 == mali_cpu_clock_last_value[3])) { /* Diff can be printed if we want to check if the clocks are in sync int diff = mali_cpu_clock_last_value[0] - mali_cpu_clock_last_value[1];*/ MALI_DEBUG_PRINT(2, ("CPU cycle counters readout all: %08x %08x\n", mali_cpu_clock_last_value[0], mali_cpu_clock_last_value[1])); } else { - MALI_DEBUG_PRINT(2, ("CPU cycle counters readout all: %08x %08x %08x %08x\n", mali_cpu_clock_last_value[0], mali_cpu_clock_last_value[1], mali_cpu_clock_last_value[2], mali_cpu_clock_last_value[3] )); + MALI_DEBUG_PRINT(2, ("CPU cycle counters readout all: %08x %08x %08x %08x\n", mali_cpu_clock_last_value[0], mali_cpu_clock_last_value[1], mali_cpu_clock_last_value[2], mali_cpu_clock_last_value[3])); } } } #endif - int mali_module_init(void) { int err = 0; - MALI_DEBUG_PRINT(2, ("Inserting Mali v%d device driver. \n",_MALI_API_VERSION)); + MALI_DEBUG_PRINT(2, ("Inserting Mali v%d device driver. \n", _MALI_API_VERSION)); MALI_DEBUG_PRINT(2, ("Compiled: %s, time: %s.\n", __DATE__, __TIME__)); MALI_DEBUG_PRINT(2, ("Driver revision: %s\n", SVN_REV_STRING)); + + I("svn_rev_string_from_arm of this mali_ko is '%s', rk_ko_ver is '%d', built at '%s', on '%s'.", + SVN_REV_STRING, + RK_KO_VER, + __TIME__, + __DATE__); #if MALI_ENABLE_CPU_CYCLES mali_init_cpu_time_counters_on_all_cpus(0); @@ -349,12 +395,28 @@ int mali_module_init(void) mali_init_cpu_time_counters_on_all_cpus(1); #endif - MALI_PRINT(("mali_module_init() registering driver\n")); + /* Initialize module wide settings */ +#ifdef MALI_FAKE_PLATFORM_DEVICE +#ifndef CONFIG_MALI_DT + MALI_DEBUG_PRINT(2, ("mali_module_init() registering device\n")); + err = mali_platform_device_register(); + if (0 != err) { + return err; + } +#endif +#endif + + MALI_DEBUG_PRINT(2, ("mali_module_init() registering driver\n")); err = platform_driver_register(&mali_platform_driver); if (0 != err) { - MALI_PRINT(("mali_module_init() Failed to register driver (%d)\n", err)); + MALI_DEBUG_PRINT(2, ("mali_module_init() Failed to register driver (%d)\n", err)); +#ifdef MALI_FAKE_PLATFORM_DEVICE +#ifndef CONFIG_MALI_DT + mali_platform_device_unregister(); +#endif +#endif mali_platform_device = NULL; return err; } @@ -367,6 +429,18 @@ int mali_module_init(void) } #endif + /* Tracing the current frequency and voltage from boot/insmod*/ +#if defined(CONFIG_MALI400_PROFILING) && defined(CONFIG_MALI_DVFS) + /* Just call mali_get_current_gpu_clk_item(),to record current clk info.*/ + mali_get_current_gpu_clk_item(&mali_gpu_clk[0]); + _mali_osk_profiling_add_event(MALI_PROFILING_EVENT_TYPE_SINGLE | + MALI_PROFILING_EVENT_CHANNEL_GPU | + MALI_PROFILING_EVENT_REASON_SINGLE_GPU_FREQ_VOLT_CHANGE, + mali_gpu_clk[0].clock, + mali_gpu_clk[0].vol / 1000, + 0, 0, 0); +#endif + MALI_PRINT(("Mali device driver loaded\n")); return 0; /* Success */ @@ -374,19 +448,29 @@ int mali_module_init(void) void mali_module_exit(void) { - MALI_DEBUG_PRINT(2, ("Unloading Mali v%d device driver.\n",_MALI_API_VERSION)); + MALI_DEBUG_PRINT(2, ("Unloading Mali v%d device driver.\n", _MALI_API_VERSION)); MALI_DEBUG_PRINT(2, ("mali_module_exit() unregistering driver\n")); -#if defined(CONFIG_MALI400_INTERNAL_PROFILING) - _mali_internal_profiling_term(); -#endif - platform_driver_unregister(&mali_platform_driver); #if defined(MALI_FAKE_PLATFORM_DEVICE) +#ifndef CONFIG_MALI_DT MALI_DEBUG_PRINT(2, ("mali_module_exit() unregistering device\n")); - mali_platform_device_unregister(mali_platform_device); + mali_platform_device_unregister(); +#endif +#endif + + /* Tracing the current frequency and voltage from rmmod*/ + _mali_osk_profiling_add_event(MALI_PROFILING_EVENT_TYPE_SINGLE | + MALI_PROFILING_EVENT_CHANNEL_GPU | + MALI_PROFILING_EVENT_REASON_SINGLE_GPU_FREQ_VOLT_CHANGE, + 0, + 0, + 0, 0, 0); + +#if defined(CONFIG_MALI400_INTERNAL_PROFILING) + _mali_internal_profiling_term(); #endif MALI_PRINT(("Mali device driver unloaded\n")); @@ -397,33 +481,34 @@ static int mali_probe(struct platform_device *pdev) int err; MALI_DEBUG_PRINT(2, ("mali_probe(): Called for platform device %s\n", pdev->name)); - + if (NULL != mali_platform_device) { /* Already connected to a device, return error */ MALI_PRINT_ERROR(("mali_probe(): The Mali driver is already connected with a Mali device.")); return -EEXIST; } - - mali_platform_device = pdev; - pr_info("mali_platform_device->num_resources = %d\n",mali_platform_device->num_resources); + mali_platform_device = pdev; + dev_info(&pdev->dev, "mali_platform_device->num_resources = %d\n", + mali_platform_device->num_resources); + { int i = 0; - for(i=0;inum_resources;i++) - { - pr_info("mali_platform_device->resource[%d].start = 0x%08x\n",i,mali_platform_device->resource[i].start); - } + + for(i = 0; i < mali_platform_device->num_resources; i++) + dev_info(&pdev->dev, + "resource[%d].start = 0x%pa\n", + i, + &mali_platform_device->resource[i].start); } - - -#if defined(MALI_FAKE_PLATFORM_DEVICE) - MALI_DEBUG_PRINT(2, ("mali_module_init() registering device\n")); - err = mali_platform_device_register(mali_platform_device); - if (0 != err) - { - mali_platform_device_unregister(mali_platform_device); - return err; + +#ifdef CONFIG_MALI_DT + /* If we use DT to initialize our DDK, we have to prepare somethings. */ + err = mali_platform_device_init(mali_platform_device); + if (0 != err) { + MALI_PRINT_ERROR(("mali_probe(): Failed to initialize platform device.")); + return -EFAULT; } #endif @@ -435,8 +520,10 @@ static int mali_probe(struct platform_device *pdev) if (0 == err) { /* Setup sysfs entries */ err = mali_sysfs_register(mali_dev_name); + if (0 == err) { MALI_DEBUG_PRINT(2, ("mali_probe(): Successfully initialized driver for platform device %s\n", pdev->name)); + return 0; } else { MALI_PRINT_ERROR(("mali_probe(): failed to register sysfs entries")); @@ -463,6 +550,9 @@ static int mali_remove(struct platform_device *pdev) mali_miscdevice_unregister(); mali_terminate_subsystems(); _mali_osk_wq_term(); +#ifdef CONFIG_MALI_DT + mali_platform_device_deinit(mali_platform_device); +#endif mali_platform_device = NULL; return 0; } @@ -491,12 +581,33 @@ static void mali_miscdevice_unregister(void) static int mali_driver_suspend_scheduler(struct device *dev) { - mali_pm_os_suspend(); + 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 | + MALI_PROFILING_EVENT_CHANNEL_GPU | + MALI_PROFILING_EVENT_REASON_SINGLE_GPU_FREQ_VOLT_CHANGE, + 0, + 0, + 0, 0, 0); return 0; } static int mali_driver_resume_scheduler(struct device *dev) { + /* 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.*/ + if (is_first_resume == 1) { + mali_get_current_gpu_clk_item(&mali_gpu_clk[1]); + is_first_resume = 0; + } + _mali_osk_profiling_add_event(MALI_PROFILING_EVENT_TYPE_SINGLE | + MALI_PROFILING_EVENT_CHANNEL_GPU | + MALI_PROFILING_EVENT_REASON_SINGLE_GPU_FREQ_VOLT_CHANGE, + mali_gpu_clk[1].clock, + mali_gpu_clk[1].vol / 1000, + 0, 0, 0); +#endif mali_pm_os_resume(); return 0; } @@ -504,12 +615,38 @@ static int mali_driver_resume_scheduler(struct device *dev) #ifdef CONFIG_PM_RUNTIME static int mali_driver_runtime_suspend(struct device *dev) { - mali_pm_runtime_suspend(); - return 0; + 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 | + MALI_PROFILING_EVENT_CHANNEL_GPU | + MALI_PROFILING_EVENT_REASON_SINGLE_GPU_FREQ_VOLT_CHANGE, + 0, + 0, + 0, 0, 0); + + return 0; + } else { + return -EBUSY; + } } static int mali_driver_runtime_resume(struct device *dev) { + /* 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.*/ + if (is_first_resume == 1) { + mali_get_current_gpu_clk_item(&mali_gpu_clk[1]); + is_first_resume = 0; + } + _mali_osk_profiling_add_event(MALI_PROFILING_EVENT_TYPE_SINGLE | + MALI_PROFILING_EVENT_CHANNEL_GPU | + MALI_PROFILING_EVENT_REASON_SINGLE_GPU_FREQ_VOLT_CHANGE, + mali_gpu_clk[1].clock, + mali_gpu_clk[1].vol / 1000, + 0, 0, 0); +#endif + mali_pm_runtime_resume(); return 0; } @@ -523,7 +660,7 @@ static int mali_driver_runtime_idle(struct device *dev) static int mali_open(struct inode *inode, struct file *filp) { - struct mali_session_data * session_data; + struct mali_session_data *session_data; _mali_osk_errcode_t err; /* input validation */ @@ -540,7 +677,9 @@ static int mali_open(struct inode *inode, struct file *filp) filp->f_pos = 0; /* link in our session data */ - filp->private_data = (void*)session_data; + filp->private_data = (void *)session_data; + + filp->f_mapping = mali_mem_swap_get_global_swap_file()->f_mapping; return 0; } @@ -560,10 +699,10 @@ static int mali_release(struct inode *inode, struct file *filp) return 0; } -#ifdef CONFIG_MALI400 -int map_errcode( _mali_osk_errcode_t err ) + +int map_errcode(_mali_osk_errcode_t err) { - switch(err) { + switch (err) { case _MALI_OSK_ERR_OK : return 0; case _MALI_OSK_ERR_FAULT: @@ -584,7 +723,6 @@ int map_errcode( _mali_osk_errcode_t err ) return -EFAULT; } } -#endif #ifdef HAVE_UNLOCKED_IOCTL static long mali_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) @@ -613,204 +751,217 @@ static int mali_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, return -ENOTTY; } - switch(cmd) { + switch (cmd) { case MALI_IOC_WAIT_FOR_NOTIFICATION: + BUILD_BUG_ON(!IS_ALIGNED(sizeof(_mali_uk_wait_for_notification_s), sizeof(u64))); err = wait_for_notification_wrapper(session_data, (_mali_uk_wait_for_notification_s __user *)arg); break; + case MALI_IOC_GET_API_VERSION_V2: + BUILD_BUG_ON(!IS_ALIGNED(sizeof(_mali_uk_get_api_version_v2_s), sizeof(u64))); + err = get_api_version_v2_wrapper(session_data, (_mali_uk_get_api_version_v2_s __user *)arg); + break; + case MALI_IOC_GET_API_VERSION: err = get_api_version_wrapper(session_data, (_mali_uk_get_api_version_s __user *)arg); break; case MALI_IOC_POST_NOTIFICATION: + BUILD_BUG_ON(!IS_ALIGNED(sizeof(_mali_uk_post_notification_s), sizeof(u64))); err = post_notification_wrapper(session_data, (_mali_uk_post_notification_s __user *)arg); break; - case MALI_IOC_GET_MALI_VERSION_IN_RK30: - err = get_mali_version_in_rk30_wrapper(session_data,(_mali_uk_get_mali_version_in_rk30_s __user *)arg); - break; + /* rk_ext : 从对 r5p0-01rel0 集成开始, 不再使用. */ +#if 0 + case MALI_IOC_GET_MALI_VERSION_IN_RK30: + err = get_mali_version_in_rk30_wrapper(session_data, (_mali_uk_get_mali_version_in_rk30_s __user *)arg); + break; +#else + case MALI_IOC_GET_RK_KO_VERSION: + err = get_rk_ko_version_wrapper(session_data, (_mali_rk_ko_version_s __user *)arg); + break; +#endif + case MALI_IOC_GET_USER_SETTINGS: + BUILD_BUG_ON(!IS_ALIGNED(sizeof(_mali_uk_get_user_settings_s), sizeof(u64))); err = get_user_settings_wrapper(session_data, (_mali_uk_get_user_settings_s __user *)arg); break; case MALI_IOC_REQUEST_HIGH_PRIORITY: + BUILD_BUG_ON(!IS_ALIGNED(sizeof(_mali_uk_request_high_priority_s), sizeof(u64))); err = request_high_priority_wrapper(session_data, (_mali_uk_request_high_priority_s __user *)arg); break; -#if defined(CONFIG_MALI400_PROFILING) - case MALI_IOC_PROFILING_START: - err = profiling_start_wrapper(session_data, (_mali_uk_profiling_start_s __user *)arg); + case MALI_IOC_PENDING_SUBMIT: + BUILD_BUG_ON(!IS_ALIGNED(sizeof(_mali_uk_pending_submit_s), sizeof(u64))); + err = pending_submit_wrapper(session_data, (_mali_uk_pending_submit_s __user *)arg); break; +#if defined(CONFIG_MALI400_PROFILING) case MALI_IOC_PROFILING_ADD_EVENT: + BUILD_BUG_ON(!IS_ALIGNED(sizeof(_mali_uk_profiling_add_event_s), sizeof(u64))); err = profiling_add_event_wrapper(session_data, (_mali_uk_profiling_add_event_s __user *)arg); break; - case MALI_IOC_PROFILING_STOP: - err = profiling_stop_wrapper(session_data, (_mali_uk_profiling_stop_s __user *)arg); - break; - - case MALI_IOC_PROFILING_GET_EVENT: - err = profiling_get_event_wrapper(session_data, (_mali_uk_profiling_get_event_s __user *)arg); - break; - - case MALI_IOC_PROFILING_CLEAR: - err = profiling_clear_wrapper(session_data, (_mali_uk_profiling_clear_s __user *)arg); + case MALI_IOC_PROFILING_REPORT_SW_COUNTERS: + BUILD_BUG_ON(!IS_ALIGNED(sizeof(_mali_uk_sw_counters_report_s), sizeof(u64))); + err = profiling_report_sw_counters_wrapper(session_data, (_mali_uk_sw_counters_report_s __user *)arg); break; - case MALI_IOC_PROFILING_GET_CONFIG: - /* Deprecated: still compatible with get_user_settings */ - err = get_user_settings_wrapper(session_data, (_mali_uk_get_user_settings_s __user *)arg); + case MALI_IOC_PROFILING_STREAM_FD_GET: + BUILD_BUG_ON(!IS_ALIGNED(sizeof(_mali_uk_profiling_stream_fd_get_s), sizeof(u64))); + err = profiling_get_stream_fd_wrapper(session_data, (_mali_uk_profiling_stream_fd_get_s __user *)arg); break; - case MALI_IOC_PROFILING_REPORT_SW_COUNTERS: - err = profiling_report_sw_counters_wrapper(session_data, (_mali_uk_sw_counters_report_s __user *)arg); + case MALI_IOC_PROILING_CONTROL_SET: + BUILD_BUG_ON(!IS_ALIGNED(sizeof(_mali_uk_profiling_control_set_s), sizeof(u64))); + err = profiling_control_set_wrapper(session_data, (_mali_uk_profiling_control_set_s __user *)arg); break; - #else - case MALI_IOC_PROFILING_START: /* FALL-THROUGH */ case MALI_IOC_PROFILING_ADD_EVENT: /* FALL-THROUGH */ - case MALI_IOC_PROFILING_STOP: /* FALL-THROUGH */ - case MALI_IOC_PROFILING_GET_EVENT: /* FALL-THROUGH */ - case MALI_IOC_PROFILING_CLEAR: /* FALL-THROUGH */ - case MALI_IOC_PROFILING_GET_CONFIG: /* FALL-THROUGH */ case MALI_IOC_PROFILING_REPORT_SW_COUNTERS: /* FALL-THROUGH */ MALI_DEBUG_PRINT(2, ("Profiling not supported\n")); err = -ENOTTY; break; - #endif - case MALI_IOC_MEM_WRITE_SAFE: - err = mem_write_safe_wrapper(session_data, (_mali_uk_mem_write_safe_s __user *)arg); + case MALI_IOC_PROFILING_MEMORY_USAGE_GET: + BUILD_BUG_ON(!IS_ALIGNED(sizeof(_mali_uk_profiling_memory_usage_get_s), sizeof(u64))); + err = mem_usage_get_wrapper(session_data, (_mali_uk_profiling_memory_usage_get_s __user *)arg); break; - case MALI_IOC_MEM_MAP_EXT: - err = mem_map_ext_wrapper(session_data, (_mali_uk_map_external_mem_s __user *)arg); + case MALI_IOC_MEM_ALLOC: + BUILD_BUG_ON(!IS_ALIGNED(sizeof(_mali_uk_alloc_mem_s), sizeof(u64))); + err = mem_alloc_wrapper(session_data, (_mali_uk_alloc_mem_s __user *)arg); break; - case MALI_IOC_MEM_UNMAP_EXT: - err = mem_unmap_ext_wrapper(session_data, (_mali_uk_unmap_external_mem_s __user *)arg); + case MALI_IOC_MEM_FREE: + BUILD_BUG_ON(!IS_ALIGNED(sizeof(_mali_uk_free_mem_s), sizeof(u64))); + err = mem_free_wrapper(session_data, (_mali_uk_free_mem_s __user *)arg); break; - case MALI_IOC_MEM_QUERY_MMU_PAGE_TABLE_DUMP_SIZE: - err = mem_query_mmu_page_table_dump_size_wrapper(session_data, (_mali_uk_query_mmu_page_table_dump_size_s __user *)arg); + case MALI_IOC_MEM_BIND: + BUILD_BUG_ON(!IS_ALIGNED(sizeof(_mali_uk_bind_mem_s), sizeof(u64))); + err = mem_bind_wrapper(session_data, (_mali_uk_bind_mem_s __user *)arg); break; - case MALI_IOC_MEM_DUMP_MMU_PAGE_TABLE: - err = mem_dump_mmu_page_table_wrapper(session_data, (_mali_uk_dump_mmu_page_table_s __user *)arg); + case MALI_IOC_MEM_UNBIND: + BUILD_BUG_ON(!IS_ALIGNED(sizeof(_mali_uk_unbind_mem_s), sizeof(u64))); + err = mem_unbind_wrapper(session_data, (_mali_uk_unbind_mem_s __user *)arg); break; -#if defined(CONFIG_MALI400_UMP) - - case MALI_IOC_MEM_ATTACH_UMP: - err = mem_attach_ump_wrapper(session_data, (_mali_uk_attach_ump_mem_s __user *)arg); + case MALI_IOC_MEM_COW: + BUILD_BUG_ON(!IS_ALIGNED(sizeof(_mali_uk_cow_mem_s), sizeof(u64))); + err = mem_cow_wrapper(session_data, (_mali_uk_cow_mem_s __user *)arg); break; - case MALI_IOC_MEM_RELEASE_UMP: - err = mem_release_ump_wrapper(session_data, (_mali_uk_release_ump_mem_s __user *)arg); + case MALI_IOC_MEM_COW_MODIFY_RANGE: + BUILD_BUG_ON(!IS_ALIGNED(sizeof(_mali_uk_cow_modify_range_s), sizeof(u64))); + err = mem_cow_modify_range_wrapper(session_data, (_mali_uk_cow_modify_range_s __user *)arg); break; -#else + case MALI_IOC_MEM_RESIZE: + BUILD_BUG_ON(!IS_ALIGNED(sizeof(_mali_uk_mem_resize_s), sizeof(u64))); + err = mem_resize_mem_wrapper(session_data, (_mali_uk_mem_resize_s __user *)arg); + break; - case MALI_IOC_MEM_ATTACH_UMP: - case MALI_IOC_MEM_RELEASE_UMP: /* FALL-THROUGH */ - MALI_DEBUG_PRINT(2, ("UMP not supported\n")); - err = -ENOTTY; + case MALI_IOC_MEM_WRITE_SAFE: + BUILD_BUG_ON(!IS_ALIGNED(sizeof(_mali_uk_mem_write_safe_s), sizeof(u64))); + err = mem_write_safe_wrapper(session_data, (_mali_uk_mem_write_safe_s __user *)arg); break; -#endif -#ifdef CONFIG_DMA_SHARED_BUFFER - case MALI_IOC_MEM_ATTACH_DMA_BUF: - err = mali_attach_dma_buf(session_data, (_mali_uk_attach_dma_buf_s __user *)arg); + case MALI_IOC_MEM_QUERY_MMU_PAGE_TABLE_DUMP_SIZE: + BUILD_BUG_ON(!IS_ALIGNED(sizeof(_mali_uk_query_mmu_page_table_dump_size_s), sizeof(u64))); + err = mem_query_mmu_page_table_dump_size_wrapper(session_data, (_mali_uk_query_mmu_page_table_dump_size_s __user *)arg); break; - case MALI_IOC_MEM_RELEASE_DMA_BUF: - err = mali_release_dma_buf(session_data, (_mali_uk_release_dma_buf_s __user *)arg); + case MALI_IOC_MEM_DUMP_MMU_PAGE_TABLE: + BUILD_BUG_ON(!IS_ALIGNED(sizeof(_mali_uk_dump_mmu_page_table_s), sizeof(u64))); + err = mem_dump_mmu_page_table_wrapper(session_data, (_mali_uk_dump_mmu_page_table_s __user *)arg); break; case MALI_IOC_MEM_DMA_BUF_GET_SIZE: +#ifdef CONFIG_DMA_SHARED_BUFFER + BUILD_BUG_ON(!IS_ALIGNED(sizeof(_mali_uk_dma_buf_get_size_s), sizeof(u64))); err = mali_dma_buf_get_size(session_data, (_mali_uk_dma_buf_get_size_s __user *)arg); - break; #else - - case MALI_IOC_MEM_ATTACH_DMA_BUF: /* FALL-THROUGH */ - case MALI_IOC_MEM_RELEASE_DMA_BUF: /* FALL-THROUGH */ - case MALI_IOC_MEM_DMA_BUF_GET_SIZE: /* FALL-THROUGH */ MALI_DEBUG_PRINT(2, ("DMA-BUF not supported\n")); err = -ENOTTY; - break; #endif + break; case MALI_IOC_PP_START_JOB: + BUILD_BUG_ON(!IS_ALIGNED(sizeof(_mali_uk_pp_start_job_s), sizeof(u64))); err = pp_start_job_wrapper(session_data, (_mali_uk_pp_start_job_s __user *)arg); break; case MALI_IOC_PP_AND_GP_START_JOB: + BUILD_BUG_ON(!IS_ALIGNED(sizeof(_mali_uk_pp_and_gp_start_job_s), sizeof(u64))); err = pp_and_gp_start_job_wrapper(session_data, (_mali_uk_pp_and_gp_start_job_s __user *)arg); break; case MALI_IOC_PP_NUMBER_OF_CORES_GET: + BUILD_BUG_ON(!IS_ALIGNED(sizeof(_mali_uk_get_pp_number_of_cores_s), sizeof(u64))); err = pp_get_number_of_cores_wrapper(session_data, (_mali_uk_get_pp_number_of_cores_s __user *)arg); break; case MALI_IOC_PP_CORE_VERSION_GET: + BUILD_BUG_ON(!IS_ALIGNED(sizeof(_mali_uk_get_pp_core_version_s), sizeof(u64))); err = pp_get_core_version_wrapper(session_data, (_mali_uk_get_pp_core_version_s __user *)arg); break; case MALI_IOC_PP_DISABLE_WB: + BUILD_BUG_ON(!IS_ALIGNED(sizeof(_mali_uk_pp_disable_wb_s), sizeof(u64))); err = pp_disable_wb_wrapper(session_data, (_mali_uk_pp_disable_wb_s __user *)arg); break; case MALI_IOC_GP2_START_JOB: + BUILD_BUG_ON(!IS_ALIGNED(sizeof(_mali_uk_gp_start_job_s), sizeof(u64))); err = gp_start_job_wrapper(session_data, (_mali_uk_gp_start_job_s __user *)arg); break; case MALI_IOC_GP2_NUMBER_OF_CORES_GET: + BUILD_BUG_ON(!IS_ALIGNED(sizeof(_mali_uk_get_gp_number_of_cores_s), sizeof(u64))); err = gp_get_number_of_cores_wrapper(session_data, (_mali_uk_get_gp_number_of_cores_s __user *)arg); break; case MALI_IOC_GP2_CORE_VERSION_GET: + BUILD_BUG_ON(!IS_ALIGNED(sizeof(_mali_uk_get_gp_core_version_s), sizeof(u64))); err = gp_get_core_version_wrapper(session_data, (_mali_uk_get_gp_core_version_s __user *)arg); break; case MALI_IOC_GP2_SUSPEND_RESPONSE: + BUILD_BUG_ON(!IS_ALIGNED(sizeof(_mali_uk_gp_suspend_response_s), sizeof(u64))); err = gp_suspend_response_wrapper(session_data, (_mali_uk_gp_suspend_response_s __user *)arg); break; case MALI_IOC_VSYNC_EVENT_REPORT: + BUILD_BUG_ON(!IS_ALIGNED(sizeof(_mali_uk_vsync_event_report_s), sizeof(u64))); err = vsync_event_report_wrapper(session_data, (_mali_uk_vsync_event_report_s __user *)arg); break; case MALI_IOC_TIMELINE_GET_LATEST_POINT: + BUILD_BUG_ON(!IS_ALIGNED(sizeof(_mali_uk_timeline_get_latest_point_s), sizeof(u64))); err = timeline_get_latest_point_wrapper(session_data, (_mali_uk_timeline_get_latest_point_s __user *)arg); break; case MALI_IOC_TIMELINE_WAIT: + BUILD_BUG_ON(!IS_ALIGNED(sizeof(_mali_uk_timeline_wait_s), sizeof(u64))); err = timeline_wait_wrapper(session_data, (_mali_uk_timeline_wait_s __user *)arg); break; case MALI_IOC_TIMELINE_CREATE_SYNC_FENCE: + BUILD_BUG_ON(!IS_ALIGNED(sizeof(_mali_uk_timeline_create_sync_fence_s), sizeof(u64))); err = timeline_create_sync_fence_wrapper(session_data, (_mali_uk_timeline_create_sync_fence_s __user *)arg); break; case MALI_IOC_SOFT_JOB_START: + BUILD_BUG_ON(!IS_ALIGNED(sizeof(_mali_uk_soft_job_start_s), sizeof(u64))); err = soft_job_start_wrapper(session_data, (_mali_uk_soft_job_start_s __user *)arg); break; case MALI_IOC_SOFT_JOB_SIGNAL: + BUILD_BUG_ON(!IS_ALIGNED(sizeof(_mali_uk_soft_job_signal_s), sizeof(u64))); err = soft_job_signal_wrapper(session_data, (_mali_uk_soft_job_signal_s __user *)arg); break; - case MALI_IOC_MEM_INIT: /* Fallthrough */ - case MALI_IOC_MEM_TERM: /* Fallthrough */ - MALI_DEBUG_PRINT(2, ("Deprecated ioctls called\n")); - err = -ENOTTY; - break; - - case MALI_IOC_MEM_GET_BIG_BLOCK: /* Fallthrough */ - case MALI_IOC_MEM_FREE_BIG_BLOCK: - MALI_PRINT_ERROR(("Non-MMU mode is no longer supported.\n")); - err = -ENOTTY; - break; - default: MALI_DEBUG_PRINT(2, ("No handler for ioctl 0x%08X 0x%08lX\n", cmd, arg)); err = -ENOTTY; @@ -819,8 +970,7 @@ static int mali_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, return err; } - -module_init(mali_module_init); +late_initcall_sync(mali_module_init); module_exit(mali_module_exit); MODULE_LICENSE(MALI_KERNEL_LINUX_LICENSE);