1af69d88dSmrg/*
2af69d88dSmrg * Copyright 2014 Ilia Mirkin
3af69d88dSmrg *
4af69d88dSmrg * Permission is hereby granted, free of charge, to any person obtaining a
5af69d88dSmrg * copy of this software and associated documentation files (the "Software"),
6af69d88dSmrg * to deal in the Software without restriction, including without limitation
7af69d88dSmrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8af69d88dSmrg * and/or sell copies of the Software, and to permit persons to whom the
9af69d88dSmrg * Software is furnished to do so, subject to the following conditions:
10af69d88dSmrg *
11af69d88dSmrg * The above copyright notice and this permission notice (including the next
12af69d88dSmrg * paragraph) shall be included in all copies or substantial portions of the
13af69d88dSmrg * Software.
14af69d88dSmrg *
15af69d88dSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16af69d88dSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17af69d88dSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18af69d88dSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19af69d88dSmrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20af69d88dSmrg * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21af69d88dSmrg * SOFTWARE.
22af69d88dSmrg */
23af69d88dSmrg
247ec681f3Smrg#include <stdbool.h>
257ec681f3Smrg
267ec681f3Smrgbool is_nouveau_vieux(int fd);
27af69d88dSmrg
2801e04c3fSmrg#ifdef HAVE_LIBDRM
29af69d88dSmrg
3001e04c3fSmrg#include <stdlib.h>
31af69d88dSmrg#include <xf86drm.h>
32af69d88dSmrg#include <nouveau_drm.h>
33af69d88dSmrg
34af69d88dSmrgstatic int
35af69d88dSmrgnouveau_chipset(int fd)
36af69d88dSmrg{
37af69d88dSmrg   struct drm_nouveau_getparam gp = { NOUVEAU_GETPARAM_CHIPSET_ID, 0 };
38af69d88dSmrg   int ret;
39af69d88dSmrg
40af69d88dSmrg   ret = drmCommandWriteRead(fd, DRM_NOUVEAU_GETPARAM, &gp, sizeof(gp));
41af69d88dSmrg   if (ret)
42af69d88dSmrg      return -1;
43af69d88dSmrg
44af69d88dSmrg   return gp.value;
45af69d88dSmrg}
46af69d88dSmrg
477ec681f3Smrgbool
48af69d88dSmrgis_nouveau_vieux(int fd)
49af69d88dSmrg{
50af69d88dSmrg   int chipset = nouveau_chipset(fd);
5101e04c3fSmrg   return (chipset > 0 && chipset < 0x30) ||
5201e04c3fSmrg      (chipset < 0x40 && getenv("NOUVEAU_VIEUX") != NULL);
53af69d88dSmrg}
54af69d88dSmrg
55af69d88dSmrg#else
56af69d88dSmrg
577ec681f3Smrgbool is_nouveau_vieux(int fd) { return false; }
58af69d88dSmrg
59af69d88dSmrg#endif
60