/* * Copyright 2005 Stephane Marchesin * Copyright 2008 Stuart Bennett * Copyright 2009-2010 Francisco Jerez * All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice (including the * next paragraph) shall be included in all copies or substantial * portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ #include "nvhw.h" uint32_t chipset = 0xff; uint64_t class; static bool have_class(void *regs, uint64_t k) { int arch = (chipset & 0xf0); switch (k) { case NV04_CLASS: return arch == 0x00; case NV10_CLASS: return arch == 0x10; case NV20_CLASS: return arch == 0x20; case NV30_CLASS: return arch == 0x30; case NV40_CLASS: return arch == 0x40 || arch == 0x60; case NV50_CLASS: return arch == 0x50 || arch == 0x80 || arch == 0x90 || arch == 0xa0; case NVC0_CLASS: return arch == 0xc0; case DUALHEAD_CLASS: return chipset > 0x10 && chipset != 0x15 && chipset != 0x1a && chipset != 0x20; case TWOREG_PLL_CLASS: return chipset == 0x31 || chipset == 0x36 || chipset >= 0x40; case TWOSTAGE_PLL_CLASS: return chipset >= 0x30 && chipset != 0x34; case NV04_OVERLAY_CLASS: return chipset <= 0x40 || chipset == 0x44; case NV17_DISPLAY_CLASS: return chipset >= 0x17 && (chipset != 0x1a && chipset != 0x20); case NV17_TVOUT_CLASS: return chipset >= 0x17 && (chipset != 0x1a && arch != 0x20); default: return false; } } int nv_detect_chipset(void *regs) { uint32_t reg0 = nv_rd32(regs, 0); uint64_t k; /* We're dealing with >= NV10 */ if ((reg0 & 0x0f000000) > 0) { /* Bit 27-20 contain the architecture in hex */ chipset = (reg0 & 0xff00000) >> 20; /* NV04 or NV05 */ } else if ((reg0 & 0xff00fff0) == 0x20004000) { if (reg0 & 0x00f00000) chipset = 0x05; else chipset = 0x04; } else { return -ENODEV; } for (k = 1; k; k <<= 1) { if (have_class(regs, k)) class |= k; } return 0; }