2 This file is part of PulseAudio.
4 Copyright 2004-2006 Lennart Poettering
5 Copyright 2009 Wim Taymans <wim.taymans@collabora.co.uk>
7 PulseAudio is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published
9 by the Free Software Foundation; either version 2.1 of the License,
10 or (at your option) any later version.
12 PulseAudio is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public License
18 along with PulseAudio; if not, see <http://www.gnu.org/licenses/>.
26 #include <sys/types.h>
29 #include <pulse/xmalloc.h>
30 #include <pulsecore/core-util.h>
31 #include <pulsecore/log.h>
35 #if defined (__arm__) && defined (__linux__)
37 #define MAX_BUFFER 4096
39 get_cpuinfo_line(char *cpuinfo, const char *tag) {
40 char *line, *end, *colon;
42 if (!(line = strstr(cpuinfo, tag)))
45 if (!(end = strchr(line, '\n')))
48 if (!(colon = strchr(line, ':')))
54 return pa_xstrndup(colon, end - colon);
57 static char *get_cpuinfo(void) {
61 cpuinfo = pa_xmalloc(MAX_BUFFER);
63 if ((fd = pa_open_cloexec("/proc/cpuinfo", O_RDONLY, 0)) < 0) {
68 if ((n = pa_read(fd, cpuinfo, MAX_BUFFER-1, NULL)) < 0) {
78 #endif /* defined (__arm__) && defined (__linux__) */
80 void pa_cpu_get_arm_flags(pa_cpu_arm_flag_t *flags) {
81 #if defined (__arm__) && defined (__linux__)
85 /* We need to read the CPU flags from /proc/cpuinfo because there is no user
86 * space support to get the CPU features. This only works on linux AFAIK. */
87 if (!(cpuinfo = get_cpuinfo())) {
88 pa_log("Can't read cpuinfo");
94 /* get the CPU architecture */
95 if ((line = get_cpuinfo_line(cpuinfo, "CPU architecture"))) {
96 arch = strtoul(line, NULL, 0);
98 *flags |= PA_CPU_ARM_V6;
100 *flags |= PA_CPU_ARM_V7;
105 /* get the CPU features */
106 if ((line = get_cpuinfo_line(cpuinfo, "Features"))) {
107 const char *state = NULL;
110 while ((current = pa_split_spaces(line, &state))) {
111 if (pa_streq(current, "vfp"))
112 *flags |= PA_CPU_ARM_VFP;
113 else if (pa_streq(current, "edsp"))
114 *flags |= PA_CPU_ARM_EDSP;
115 else if (pa_streq(current, "neon"))
116 *flags |= PA_CPU_ARM_NEON;
117 else if (pa_streq(current, "vfpv3"))
118 *flags |= PA_CPU_ARM_VFPV3;
125 /* get the CPU part number */
126 if ((line = get_cpuinfo_line(cpuinfo, "CPU part"))) {
127 part = strtoul(line, NULL, 0);
129 *flags |= PA_CPU_ARM_CORTEX_A8;
134 pa_log_info("CPU flags: %s%s%s%s%s%s%s",
135 (*flags & PA_CPU_ARM_V6) ? "V6 " : "",
136 (*flags & PA_CPU_ARM_V7) ? "V7 " : "",
137 (*flags & PA_CPU_ARM_VFP) ? "VFP " : "",
138 (*flags & PA_CPU_ARM_EDSP) ? "EDSP " : "",
139 (*flags & PA_CPU_ARM_NEON) ? "NEON " : "",
140 (*flags & PA_CPU_ARM_VFPV3) ? "VFPV3 " : "",
141 (*flags & PA_CPU_ARM_CORTEX_A8) ? "Cortex-A8 " : "");
145 bool pa_cpu_init_arm(pa_cpu_arm_flag_t *flags) {
146 #if defined (__arm__)
147 #if defined (__linux__)
148 pa_cpu_get_arm_flags(flags);
150 if (*flags & PA_CPU_ARM_V6)
151 pa_volume_func_init_arm(*flags);
154 if (*flags & PA_CPU_ARM_NEON) {
155 pa_convert_func_init_neon(*flags);
156 pa_mix_func_init_neon(*flags);
157 pa_remap_func_init_neon(*flags);
163 #else /* defined (__linux__) */
164 pa_log("Reading ARM CPU features not yet supported on this OS");
165 #endif /* defined (__linux__) */
167 #else /* defined (__arm__) */
169 #endif /* defined (__arm__) */