Merge branch linux-linaro-lsk-v3.10-android
[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 #ifdef BASE_LEGACY_UK7_SUPPORT
25
26 #include "mali_kbase_cpuprops.h"
27 #include "mali_kbase_uku.h"
28 #include <mali_kbase_config.h>
29 #include <linux/cache.h>
30 #include <linux/cpufreq.h>
31 #if defined(CONFIG_ARM) || defined(CONFIG_ARM64)
32 #include <asm/cputype.h>
33 #endif
34
35 #define KBASE_DEFAULT_CPU_NUM 0
36
37 #define L1_DCACHE_LINE_SIZE_LOG2 L1_CACHE_SHIFT
38
39 /**
40  * @brief Macros used to extract cpu id info
41  * @see Doc's for Main ID register
42  */
43 #define KBASE_CPUPROPS_ID_GET_REV(cpuid)    ((cpuid) & 0x0F)          /* [3:0]   Revision                            */
44 #define KBASE_CPUPROPS_ID_GET_PART_NR(cpuid)(((cpuid) >>  4) & 0xFFF) /* [15:4]  Part number                         */
45 #define KBASE_CPUPROPS_ID_GET_ARCH(cpuid)   (((cpuid) >> 16) & 0x0F)  /* [19:16] Architecture                        */
46 #define KBASE_CPUPROPS_ID_GET_VARIANT(cpuid)(((cpuid) >> 20) & 0x0F)  /* [23:20] Variant                             */
47 #define KBASE_CPUPROPS_ID_GET_CODE(cpuid)   (((cpuid) >> 24) & 0xFF)  /* [31:23] ASCII code of implementer trademark */
48
49 /*Below value sourced from OSK*/
50 #define L1_DCACHE_SIZE ((u32)0x00008000)
51
52 /**
53  * @brief Retrieves detailed CPU info from given cpu_val ( ID reg )
54  *
55  * @param kbase_props CPU props to be filled-in with cpu id info
56  *
57  */
58 #if defined(CONFIG_ARM) || defined(CONFIG_ARM64) 
59 static void kbasep_cpuprops_uk_get_cpu_id_info(struct kbase_uk_cpuprops * const kbase_props)
60 {
61         kbase_props->props.cpu_id.id           = read_cpuid_id();
62
63         kbase_props->props.cpu_id.valid        = 1;
64         kbase_props->props.cpu_id.rev          = KBASE_CPUPROPS_ID_GET_REV(kbase_props->props.cpu_id.id);
65         kbase_props->props.cpu_id.part         = KBASE_CPUPROPS_ID_GET_PART_NR(kbase_props->props.cpu_id.id);
66         kbase_props->props.cpu_id.arch         = KBASE_CPUPROPS_ID_GET_ARCH(kbase_props->props.cpu_id.id);
67         kbase_props->props.cpu_id.variant      = KBASE_CPUPROPS_ID_GET_VARIANT(kbase_props->props.cpu_id.id);
68         kbase_props->props.cpu_id.implementer  = KBASE_CPUPROPS_ID_GET_CODE(kbase_props->props.cpu_id.id);
69 }
70 #else
71 static void kbasep_cpuprops_uk_get_cpu_id_info(struct kbase_uk_cpuprops * const kbase_props)
72 {
73         kbase_props->props.cpu_id.id           = 0;
74         kbase_props->props.cpu_id.valid        = 0;
75         kbase_props->props.cpu_id.rev          = 0;
76         kbase_props->props.cpu_id.part         = 0;
77         kbase_props->props.cpu_id.arch         = 0;
78         kbase_props->props.cpu_id.variant      = 0;
79         kbase_props->props.cpu_id.implementer  = 'N';
80 }
81 #endif
82
83 /**
84  * This function (and file!) is kept for the backward compatibility reasons.
85  * It shall be removed as soon as KBASE_FUNC_CPU_PROPS_REG_DUMP_OBSOLETE
86  * (previously KBASE_FUNC_CPU_PROPS_REG_DUMP) ioctl call
87  * is removed. Removal of KBASE_FUNC_CPU_PROPS_REG_DUMP is part of having
88  * the function for reading cpu properties moved from base to osu.
89  */
90
91 mali_error kbase_cpuprops_uk_get_props(struct kbase_context *kctx, struct kbase_uk_cpuprops * const kbase_props)
92 {
93         unsigned int max_cpu_freq;
94
95         kbase_props->props.cpu_l1_dcache_line_size_log2 = L1_DCACHE_LINE_SIZE_LOG2;
96         kbase_props->props.cpu_l1_dcache_size = L1_DCACHE_SIZE;
97         kbase_props->props.cpu_flags = BASE_CPU_PROPERTY_FLAG_LITTLE_ENDIAN;
98
99         kbase_props->props.nr_cores = NR_CPUS;
100         kbase_props->props.cpu_page_size_log2 = PAGE_SHIFT;
101         kbase_props->props.available_memory_size = totalram_pages << PAGE_SHIFT;
102
103         kbasep_cpuprops_uk_get_cpu_id_info(kbase_props);
104
105         /* check if kernel supports dynamic frequency scaling */
106         max_cpu_freq = cpufreq_quick_get_max(KBASE_DEFAULT_CPU_NUM);
107         if (max_cpu_freq != 0) {
108                 /* convert from kHz to mHz */
109                 kbase_props->props.max_cpu_clock_speed_mhz = max_cpu_freq / 1000;
110         } else {
111                 /* fallback if CONFIG_CPU_FREQ turned off */
112                 int result;
113                 kbase_cpuprops_clock_speed_function kbase_cpuprops_uk_get_clock_speed;
114
115                 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);
116                 result = kbase_cpuprops_uk_get_clock_speed(&kbase_props->props.max_cpu_clock_speed_mhz);
117                 if (result != 0)
118                         return MALI_ERROR_FUNCTION_FAILED;
119         }
120
121         return MALI_ERROR_NONE;
122 }
123
124 #endif /* BASE_LEGACY_UK7_SUPPORT */