michael@0: /* michael@0: * Copyright © 2000 SuSE, Inc. michael@0: * Copyright © 2007 Red Hat, Inc. michael@0: * michael@0: * Permission to use, copy, modify, distribute, and sell this software and its michael@0: * documentation for any purpose is hereby granted without fee, provided that michael@0: * the above copyright notice appear in all copies and that both that michael@0: * copyright notice and this permission notice appear in supporting michael@0: * documentation, and that the name of SuSE not be used in advertising or michael@0: * publicity pertaining to distribution of the software without specific, michael@0: * written prior permission. SuSE makes no representations about the michael@0: * suitability of this software for any purpose. It is provided "as is" michael@0: * without express or implied warranty. michael@0: * michael@0: * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL michael@0: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE michael@0: * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES michael@0: * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION michael@0: * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN michael@0: * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. michael@0: */ michael@0: #ifdef HAVE_CONFIG_H michael@0: #include michael@0: #endif michael@0: michael@0: #include "pixman-private.h" michael@0: michael@0: #if defined(USE_MIPS_DSPR2) || defined(USE_LOONGSON_MMI) michael@0: michael@0: #include michael@0: #include michael@0: michael@0: static pixman_bool_t michael@0: have_feature (const char *search_string) michael@0: { michael@0: #if defined (__linux__) /* linux ELF */ michael@0: /* Simple detection of MIPS features at runtime for Linux. michael@0: * It is based on /proc/cpuinfo, which reveals hardware configuration michael@0: * to user-space applications. According to MIPS (early 2010), no similar michael@0: * facility is universally available on the MIPS architectures, so it's up michael@0: * to individual OSes to provide such. michael@0: */ michael@0: const char *file_name = "/proc/cpuinfo"; michael@0: char cpuinfo_line[256]; michael@0: FILE *f = NULL; michael@0: michael@0: if ((f = fopen (file_name, "r")) == NULL) michael@0: return FALSE; michael@0: michael@0: while (fgets (cpuinfo_line, sizeof (cpuinfo_line), f) != NULL) michael@0: { michael@0: if (strstr (cpuinfo_line, search_string) != NULL) michael@0: { michael@0: fclose (f); michael@0: return TRUE; michael@0: } michael@0: } michael@0: michael@0: fclose (f); michael@0: #endif michael@0: michael@0: /* Did not find string in the proc file, or not Linux ELF. */ michael@0: return FALSE; michael@0: } michael@0: michael@0: #endif michael@0: michael@0: pixman_implementation_t * michael@0: _pixman_mips_get_implementations (pixman_implementation_t *imp) michael@0: { michael@0: #ifdef USE_LOONGSON_MMI michael@0: /* I really don't know if some Loongson CPUs don't have MMI. */ michael@0: if (!_pixman_disabled ("loongson-mmi") && have_feature ("Loongson")) michael@0: imp = _pixman_implementation_create_mmx (imp); michael@0: #endif michael@0: michael@0: #ifdef USE_MIPS_DSPR2 michael@0: if (!_pixman_disabled ("mips-dspr2")) michael@0: { michael@0: int already_compiling_everything_for_dspr2 = 0; michael@0: #if defined(__mips_dsp) && (__mips_dsp_rev >= 2) michael@0: already_compiling_everything_for_dspr2 = 1; michael@0: #endif michael@0: if (already_compiling_everything_for_dspr2 || michael@0: /* Only currently available MIPS core that supports DSPr2 is 74K. */ michael@0: have_feature ("MIPS 74K")) michael@0: { michael@0: imp = _pixman_implementation_create_mips_dspr2 (imp); michael@0: } michael@0: } michael@0: #endif michael@0: michael@0: return imp; michael@0: }