]>
code.delx.au - pulseaudio/blob - src/pulsecore/cpu-arm.c
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, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
28 #include <sys/types.h>
32 #include <pulse/xmalloc.h>
33 #include <pulsecore/log.h>
37 #if defined (__arm__) && defined (__linux__)
39 #define MAX_BUFFER 4096
41 get_cpuinfo_line (char *cpuinfo
, const char *tag
) {
42 char *line
, *end
, *colon
;
44 if (!(line
= strstr (cpuinfo
, tag
)))
47 if (!(end
= strchr (line
, '\n')))
50 if (!(colon
= strchr (line
, ':')))
56 return pa_xstrndup (colon
, end
- colon
);
59 static char *get_cpuinfo(void) {
63 if (!(cpuinfo
= malloc(MAX_BUFFER
)))
66 if ((fd
= open("/proc/cpuinfo", O_RDONLY
)) < 0) {
71 if ((n
= read(fd
, cpuinfo
, MAX_BUFFER
-1)) < 0) {
81 #endif /* defined (__arm__) && defined (__linux__) */
83 void pa_cpu_init_arm (void) {
85 #if defined (__linux__)
88 pa_cpu_arm_flag_t flags
= 0;
90 /* We need to read the CPU flags from /proc/cpuinfo because there is no user
91 * space support to get the CPU features. This only works on linux AFAIK. */
92 if (!(cpuinfo
= get_cpuinfo ())) {
93 pa_log ("Can't read cpuinfo");
97 /* get the CPU architecture */
98 if ((line
= get_cpuinfo_line (cpuinfo
, "CPU architecture"))) {
99 arch
= strtoul (line
, NULL
, 0);
101 flags
|= PA_CPU_ARM_V6
;
103 flags
|= PA_CPU_ARM_V7
;
107 /* get the CPU features */
108 if ((line
= get_cpuinfo_line (cpuinfo
, "Features"))) {
109 char *state
= NULL
, *current
;
111 while ((current
= pa_split_spaces (line
, &state
))) {
112 if (!strcmp (current
, "vfp"))
113 flags
|= PA_CPU_ARM_VFP
;
114 else if (!strcmp (current
, "edsp"))
115 flags
|= PA_CPU_ARM_EDSP
;
116 else if (!strcmp (current
, "neon"))
117 flags
|= PA_CPU_ARM_NEON
;
118 else if (!strcmp (current
, "vfpv3"))
119 flags
|= PA_CPU_ARM_VFPV3
;
126 pa_log_info ("CPU flags: %s%s%s%s%s%s",
127 (flags
& PA_CPU_ARM_V6
) ? "V6 " : "",
128 (flags
& PA_CPU_ARM_V7
) ? "V7 " : "",
129 (flags
& PA_CPU_ARM_VFP
) ? "VFP " : "",
130 (flags
& PA_CPU_ARM_EDSP
) ? "EDSP " : "",
131 (flags
& PA_CPU_ARM_NEON
) ? "NEON " : "",
132 (flags
& PA_CPU_ARM_VFPV3
) ? "VFPV3 " : "");
133 #else /* defined (__linux__) */
134 pa_log ("ARM cpu features not yet supported on this OS");
135 #endif /* defined (__linux__) */
137 if (flags
& PA_CPU_ARM_V6
)
138 pa_volume_func_init_arm (flags
);
139 #endif /* defined (__arm__) */