3 * (C) COPYRIGHT 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 * @file mali_kbase_cpuprops.c
20 * Base kernel property query APIs
23 #include "mali_kbase.h"
24 #include "mali_kbase_cpuprops.h"
25 #include "mali_kbase_uku.h"
26 #include <kbase/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>
33 #define KBASE_DEFAULT_CPU_NUM 0
35 #define L1_DCACHE_LINE_SIZE_LOG2 L1_CACHE_SHIFT
38 * @brief Macros used to extract cpu id info
39 * @see Doc's for Main ID register
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 */
47 /*Below value sourced from OSK*/
48 #define L1_DCACHE_SIZE ((u32)0x00008000)
52 * @brief Retrieves detailed CPU info from given cpu_val ( ID reg )
54 * @param kbase_props CPU props to be filled-in with cpu id info
57 #if defined(CONFIG_ARM) || defined(CONFIG_ARM64)
58 static void kbasep_cpuprops_uk_get_cpu_id_info(kbase_uk_cpuprops * const kbase_props)
60 kbase_props->props.cpu_id.id = read_cpuid_id();
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);
70 static void kbasep_cpuprops_uk_get_cpu_id_info(kbase_uk_cpuprops * const kbase_props)
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';
82 int kbase_cpuprops_get_default_clock_speed(u32 * const clock_speed)
84 KBASE_DEBUG_ASSERT(NULL != clock_speed);
90 mali_error kbase_cpuprops_uk_get_props(kbase_context *kctx, kbase_uk_cpuprops * const kbase_props)
92 unsigned int max_cpu_freq;
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;
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;
102 kbasep_cpuprops_uk_get_cpu_id_info(kbase_props);
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 )
108 /* convert from kHz to mHz */
109 kbase_props->props.max_cpu_clock_speed_mhz = max_cpu_freq / 1000 ;
113 /* fallback if CONFIG_CPU_FREQ turned off */
115 kbase_cpuprops_clock_speed_function kbase_cpuprops_uk_get_clock_speed;
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);
120 return MALI_ERROR_FUNCTION_FAILED;
123 return MALI_ERROR_NONE;