Merge tag 'lsk-v3.10-15.09-android'
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / arm / midgard / mali_kbase_cpuprops.c
1 /*
2  *
3  * (C) COPYRIGHT 2011-2015 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  * Base kernel property query APIs
20  */
21
22 #include "mali_kbase.h"
23 #ifdef BASE_LEGACY_UK7_SUPPORT
24
25 #include "mali_kbase_cpuprops.h"
26 #include "mali_kbase_uku.h"
27 #include <mali_kbase_config.h>
28 #include <mali_kbase_config_defaults.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  * Macros used to extract cpu id info
41  * see documentation 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  * kbasep_cpuprops_uk_get_cpu_id_info - Retrieves detailed CPU info from given
54  *                                      cpu_val ( ID reg )
55  * @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 int kbase_cpuprops_uk_get_props(struct kbase_context *kctx,
92                 struct kbase_uk_cpuprops * const props)
93 {
94         unsigned int max_cpu_freq;
95
96         props->props.cpu_l1_dcache_line_size_log2 = L1_DCACHE_LINE_SIZE_LOG2;
97         props->props.cpu_l1_dcache_size = L1_DCACHE_SIZE;
98         props->props.cpu_flags = BASE_CPU_PROPERTY_FLAG_LITTLE_ENDIAN;
99
100         props->props.nr_cores = num_possible_cpus();
101         props->props.cpu_page_size_log2 = PAGE_SHIFT;
102         props->props.available_memory_size = totalram_pages << PAGE_SHIFT;
103
104         kbasep_cpuprops_uk_get_cpu_id_info(props);
105
106         /* check if kernel supports dynamic frequency scaling */
107         max_cpu_freq = cpufreq_quick_get_max(KBASE_DEFAULT_CPU_NUM);
108         if (max_cpu_freq != 0) {
109                 /* convert from kHz to mHz */
110                 props->props.max_cpu_clock_speed_mhz = max_cpu_freq / 1000;
111         } else {
112                 /* fallback if CONFIG_CPU_FREQ turned off */
113                 int err;
114                 kbase_cpu_clk_speed_func get_clock_speed;
115
116                 get_clock_speed = (kbase_cpu_clk_speed_func) CPU_SPEED_FUNC;
117                 err = get_clock_speed(&props->props.max_cpu_clock_speed_mhz);
118                 if (err)
119                         return err;
120         }
121
122         return 0;
123 }
124
125 #endif /* BASE_LEGACY_UK7_SUPPORT */