summaryrefslogtreecommitdiff
path: root/nvhw.c
blob: 6b1b4bb72c281a0ebe55306f38cdf05be19f6a06 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
 * 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;
}