Merge tag 'lsk-android-14.04' into develop-3.10
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / arm / midgard / mali_kbase_cpuprops.c
1 /*
2  *
3  * (C) COPYRIGHT ARM Limited. All rights reserved.
4  *
5  * This program is free software and is provided to you under the terms of the
6  * GNU General Public License version 2 as published by the Free Software
7  * Foundation, and any use by you of this program is subject to the terms
8  * of such GNU licence.
9  *
10  * A copy of the licence is included with the program, and can also be obtained
11  * from Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
12  * Boston, MA  02110-1301, USA.
13  *
14  */
15
16
17
18 /**
19  * @file mali_kbase_cpuprops.c
20  * Base kernel property query APIs
21  */
22
23 #include "mali_kbase.h"
24 #include "mali_kbase_cpuprops.h"
25 #include "mali_kbase_uku.h"
26 #include <mali_kbase_config.h>
27 #include <linux/cache.h>
28 #include <linux/cpufreq.h>
29 #if defined(CONFIG_ARM) || defined(CONFIG_ARM64)
30 #include <asm/cputype.h>
31 #endif
32
33 #define KBASE_DEFAULT_CPU_NUM 0
34
35 #define L1_DCACHE_LINE_SIZE_LOG2 L1_CACHE_SHIFT
36
37 /**
38  * @brief Macros used to extract cpu id info
39  * @see Doc's for Main ID register
40  */
41 #define KBASE_CPUPROPS_ID_GET_REV(cpuid)    (  (cpuid) & 0x0F         )  /* [3:0]   Revision                            */
42 #define KBASE_CPUPROPS_ID_GET_PART_NR(cpuid)( ((cpuid) >>  4) & 0xFFF )  /* [15:4]  Part number                         */
43 #define KBASE_CPUPROPS_ID_GET_ARCH(cpuid)   ( ((cpuid) >> 16) & 0x0F  )  /* [19:16] Architecture                        */
44 #define KBASE_CPUPROPS_ID_GET_VARIANT(cpuid)( ((cpuid) >> 20) & 0x0F  )  /* [23:20] Variant                             */
45 #define KBASE_CPUPROPS_ID_GET_CODE(cpuid)   ( ((cpuid) >> 24) & 0xFF  )  /* [31:23] ASCII code of implementer trademark */
46
47 /*Below value sourced from OSK*/
48 #define L1_DCACHE_SIZE ((u32)0x00008000)
49
50
51 /**
52  * @brief Retrieves detailed CPU info from given cpu_val ( ID reg )
53  *
54  * @param kbase_props CPU props to be filled-in with cpu id info
55  *
56  */
57 #if defined(CONFIG_ARM) || defined(CONFIG_ARM64) 
58 static void kbasep_cpuprops_uk_get_cpu_id_info(kbase_uk_cpuprops * const kbase_props)
59 {
60         kbase_props->props.cpu_id.id           = read_cpuid_id();
61
62         kbase_props->props.cpu_id.valid        = 1;
63         kbase_props->props.cpu_id.rev          = KBASE_CPUPROPS_ID_GET_REV(kbase_props->props.cpu_id.id);
64         kbase_props->props.cpu_id.part         = KBASE_CPUPROPS_ID_GET_PART_NR(kbase_props->props.cpu_id.id);
65         kbase_props->props.cpu_id.arch         = KBASE_CPUPROPS_ID_GET_ARCH(kbase_props->props.cpu_id.id);
66         kbase_props->props.cpu_id.variant      = KBASE_CPUPROPS_ID_GET_VARIANT(kbase_props->props.cpu_id.id);
67         kbase_props->props.cpu_id.implementer  = KBASE_CPUPROPS_ID_GET_CODE(kbase_props->props.cpu_id.id);
68 }
69 #else
70 static void kbasep_cpuprops_uk_get_cpu_id_info(kbase_uk_cpuprops * const kbase_props)
71 {
72         kbase_props->props.cpu_id.id           = 0;
73         kbase_props->props.cpu_id.valid        = 0;
74         kbase_props->props.cpu_id.rev          = 0;
75         kbase_props->props.cpu_id.part         = 0;
76         kbase_props->props.cpu_id.arch         = 0;
77         kbase_props->props.cpu_id.variant      = 0;
78         kbase_props->props.cpu_id.implementer  = 'N';
79 }
80 #endif
81
82 int kbase_cpuprops_get_default_clock_speed(u32 * const clock_speed)
83 {
84         KBASE_DEBUG_ASSERT(NULL != clock_speed);
85
86         *clock_speed = 100;
87         return 0;
88 }
89
90 mali_error kbase_cpuprops_uk_get_props(kbase_context *kctx, kbase_uk_cpuprops * const kbase_props)
91 {
92         unsigned int max_cpu_freq;
93
94         kbase_props->props.cpu_l1_dcache_line_size_log2 = L1_DCACHE_LINE_SIZE_LOG2;
95         kbase_props->props.cpu_l1_dcache_size = L1_DCACHE_SIZE;
96         kbase_props->props.cpu_flags = BASE_CPU_PROPERTY_FLAG_LITTLE_ENDIAN;
97
98         kbase_props->props.nr_cores = NR_CPUS;
99         kbase_props->props.cpu_page_size_log2 = PAGE_SHIFT;
100         kbase_props->props.available_memory_size = totalram_pages << PAGE_SHIFT;
101
102         kbasep_cpuprops_uk_get_cpu_id_info(kbase_props);
103
104         /* check if kernel supports dynamic frequency scaling */
105         max_cpu_freq = cpufreq_quick_get_max( KBASE_DEFAULT_CPU_NUM );
106         if ( max_cpu_freq != 0 )
107         {
108                 /* convert from kHz to mHz */
109                 kbase_props->props.max_cpu_clock_speed_mhz = max_cpu_freq / 1000 ;
110         }
111         else 
112         {
113                 /* fallback if CONFIG_CPU_FREQ turned off */
114                 int result;
115                 kbase_cpuprops_clock_speed_function kbase_cpuprops_uk_get_clock_speed;
116
117                 kbase_cpuprops_uk_get_clock_speed = (kbase_cpuprops_clock_speed_function) kbasep_get_config_value(kctx->kbdev, kctx->kbdev->config_attributes, KBASE_CONFIG_ATTR_CPU_SPEED_FUNC);
118                 result = kbase_cpuprops_uk_get_clock_speed(&kbase_props->props.max_cpu_clock_speed_mhz);
119                 if (result != 0)
120                         return MALI_ERROR_FUNCTION_FAILED;
121         }
122
123         return MALI_ERROR_NONE;
124 }