3 * (C) COPYRIGHT 2011-2015 ARM Limited. All rights reserved.
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
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.
19 * Base kernel property query APIs
22 #include "mali_kbase.h"
23 #ifdef BASE_LEGACY_UK7_SUPPORT
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>
35 #define KBASE_DEFAULT_CPU_NUM 0
37 #define L1_DCACHE_LINE_SIZE_LOG2 L1_CACHE_SHIFT
40 * Macros used to extract cpu id info
41 * see documentation for Main ID register
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 */
49 /*Below value sourced from OSK*/
50 #define L1_DCACHE_SIZE ((u32)0x00008000)
53 * kbasep_cpuprops_uk_get_cpu_id_info - Retrieves detailed CPU info from given
55 * @kbase_props: CPU props to be filled-in with cpu id info
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)
61 kbase_props->props.cpu_id.id = read_cpuid_id();
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);
71 static void kbasep_cpuprops_uk_get_cpu_id_info(struct kbase_uk_cpuprops * const kbase_props)
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';
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.
91 int kbase_cpuprops_uk_get_props(struct kbase_context *kctx,
92 struct kbase_uk_cpuprops * const props)
94 unsigned int max_cpu_freq;
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;
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;
104 kbasep_cpuprops_uk_get_cpu_id_info(props);
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;
112 /* fallback if CONFIG_CPU_FREQ turned off */
114 kbase_cpu_clk_speed_func get_clock_speed;
116 get_clock_speed = (kbase_cpu_clk_speed_func) CPU_SPEED_FUNC;
117 err = get_clock_speed(&props->props.max_cpu_clock_speed_mhz);
125 #endif /* BASE_LEGACY_UK7_SUPPORT */