1 From 0beed8c190b27a07e7f1145a46a7ca8a75864263 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Andreas=20M=C3=BCller?= <schnitzeltony@googlemail.com>
3 Date: Thu, 23 Aug 2012 18:10:57 +0200
4 Subject: [PATCH] ARM: qemu related workarounds in cpu features detection code
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
9 This was ported from meta-oe's patch [1]. The original pixman patch is found
12 [1] http://cgit.openembedded.org/meta-openembedded/tree/meta-oe/recipes-graphics/xorg-lib/pixman-0.26.2/0001-ARM-qemu-related-workarounds-in-cpu-features-detecti.patch
13 [2] http://lists.freedesktop.org/archives/pixman/2011-January/000906.html
15 Upstream-Status: Inappropriate [other] qemu fix
17 Signed-off-by: Andreas Müller <schnitzeltony@googlemail.com>
19 pixman/pixman-arm.c | 77 ++++++++++++++++++++++++++++++++++++---------
20 1 file changed, 62 insertions(+), 15 deletions(-)
22 diff --git a/pixman/pixman-arm.c b/pixman/pixman-arm.c
23 index d271e96..8f6e241 100644
24 --- a/pixman/pixman-arm.c
25 +++ b/pixman/pixman-arm.c
26 @@ -128,16 +128,34 @@ detect_cpu_features (void)
27 #include <sys/types.h>
30 +#include <sys/utsname.h>
36 + * The whole CPU capabilities detection is a bit ugly: when running in
37 + * userspace qemu, we see /proc/self/auxv from the host system. To make
38 + * everything even worse, the size of each value is 64-bit when running
39 + * on a 64-bit host system. So the data is totally bogus because we expect
40 + * 32-bit values. As AT_PLATFORM value is used as a pointer, it may cause
41 + * segfault (null pointer dereference on x86-64 host). So in order to be
42 + * on a safe side, we require that AT_PLATFORM value is found only once,
43 + * and it has non-zero value (this is still not totally reliable for a big
44 + * endian 64-bit host system running qemu and may theoretically fail).
46 +#define ARM_HWCAP_VFP 64
47 +#define ARM_HWCAP_NEON 4096
49 static arm_cpu_features_t
50 detect_cpu_features (void)
52 arm_cpu_features_t features = 0;
56 + const char *plat = NULL;
59 fd = open ("/proc/self/auxv", O_RDONLY);
61 @@ -146,30 +164,59 @@ detect_cpu_features (void)
63 if (aux.a_type == AT_HWCAP)
65 - uint32_t hwcap = aux.a_un.a_val;
67 - /* hardcode these values to avoid depending on specific
68 - * versions of the hwcap header, e.g. HWCAP_NEON
70 - if ((hwcap & 64) != 0)
71 - features |= ARM_VFP;
72 - /* this flag is only present on kernel 2.6.29 */
73 - if ((hwcap & 4096) != 0)
74 - features |= ARM_NEON;
75 + hwcap = aux.a_un.a_val;
77 else if (aux.a_type == AT_PLATFORM)
79 - const char *plat = (const char*) aux.a_un.a_val;
81 - if (strncmp (plat, "v7l", 3) == 0)
82 + plat = (const char*) aux.a_un.a_val;
87 + if (plat == NULL || plat_cnt != 1 || *plat != 'v')
90 + * Something seems to be really wrong, most likely we are
91 + * running under qemu. Let's use machine type from "uname" for
92 + * CPU capabilities detection:
93 + * http://www.mail-archive.com/qemu-devel at nongnu.org/msg22212.html
96 + hwcap = 0; /* clear hwcap, because it is bogus */
97 + if (uname (&u) == 0)
99 + if (strcmp (u.machine, "armv7l") == 0)
101 features |= (ARM_V7 | ARM_V6);
102 - else if (strncmp (plat, "v6l", 3) == 0)
103 + hwcap |= ARM_HWCAP_VFP; /* qemu is supposed to emulate vfp */
104 + hwcap |= ARM_HWCAP_NEON; /* qemu is supposed to emulate neon */
106 + else if (strcmp (u.machine, "armv6l") == 0)
109 + hwcap |= ARM_HWCAP_VFP; /* qemu is supposed to emulate vfp */
114 + else if (strncmp (plat, "v7l", 3) == 0)
116 + features |= (ARM_V7 | ARM_V6);
118 + else if (strncmp (plat, "v6l", 3) == 0)
120 + features |= ARM_V6;
124 + /* hardcode these values to avoid depending on specific
125 + * versions of the hwcap header, e.g. HWCAP_NEON
127 + if ((hwcap & ARM_HWCAP_VFP) != 0)
128 + features |= ARM_VFP;
129 + /* this flag is only present on kernel 2.6.29 */
130 + if ((hwcap & ARM_HWCAP_NEON) != 0)
131 + features |= ARM_NEON;