summaryrefslogtreecommitdiff
path: root/nvhw.h
blob: 4e6b291b2e6514219e6ae0c248acca5f86996b62 (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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*
 * 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.
 *
 */

#ifndef __NVHW_H__
#define __NVHW_H__

#include <stdbool.h>
#include <errno.h>
#include "nvreg.h"

#define NV04_CLASS		(1 << 0)
#define NV10_CLASS		(1 << 1)
#define NV20_CLASS		(1 << 2)
#define NV30_CLASS		(1 << 3)
#define NV40_CLASS		(1 << 4)
#define NV50_CLASS		(1 << 5)
#define NVC0_CLASS		(1 << 6)
#define DUALHEAD_CLASS		(1 << 7)
#define TWOREG_PLL_CLASS	(1 << 8)
#define TWOSTAGE_PLL_CLASS	(1 << 9)
#define NV04_OVERLAY_CLASS	(1 << 10)
#define NV17_DISPLAY_CLASS	(1 << 11)
#define NV17_TVOUT_CLASS	(1 << 12)
#define NV04_DISPLAY_CLASS	(NV04_CLASS | NV10_CLASS | NV20_CLASS |	\
				 NV30_CLASS | NV40_CLASS)

extern uint32_t chipset;
extern uint64_t class;

int nv_detect_chipset(void *regs);

static inline bool
nv_class(uint64_t ks)
{
	return ks & class;
}

static inline uint8_t
nv_rd08(void *regs, uint32_t reg)
{
	return *(volatile uint8_t *)((char *)regs + reg);
}

static inline uint32_t
nv_rd32(void *regs, uint32_t reg)
{
	return *(volatile uint32_t *)((char *)regs + reg);
}

static inline void
nv_wr08(void *regs, uint32_t reg, uint8_t val)
{
	*(volatile uint8_t *)((char *)regs + reg) = val;
}

static inline void
nv_wr32(void *regs, uint32_t reg, uint32_t val)
{
	*(volatile uint32_t *)((char *)regs + reg) = val;
}

static inline uint8_t
head_rd08(void *regs, int head, uint32_t reg)
{
	if (head)
		reg += 0x2000;
	return nv_rd08(regs, reg);
}

static inline uint32_t
head_rd32(void *regs, int head, uint32_t reg)
{
	if (head)
		reg += 0x2000;
	return nv_rd32(regs, reg);
}

static inline void
head_wr08(void *regs, int head, uint32_t reg, uint8_t val)
{
	if (head)
		reg += 0x2000;
	nv_wr08(regs, reg, val);
}

static inline void
head_wr32(void *regs, int head, uint32_t reg, uint32_t val)
{
	if (head)
		reg += 0x2000;
	nv_wr32(regs, reg, val);
}

static inline uint8_t
read_prmvio(void *regs, int head, uint32_t reg)
{
	return head_rd08(regs, (nv_class(NV40_CLASS) ? head : 0), reg);
}

static inline void
write_prmvio(void *regs, int head, uint32_t reg, uint8_t val)
{
	head_wr08(regs, (nv_class(NV40_CLASS) ? head : 0), reg, val);
}

static inline uint8_t
read_vga_crtc(void *regs, int head, uint8_t idx)
{
	head_wr08(regs, head, NV_PRMCIO_CRX__COLOR, idx);
	return head_rd08(regs, head, NV_PRMCIO_CR__COLOR);
}

static inline void
write_vga_crtc(void *regs, int head, uint8_t idx, uint8_t val)
{
	head_wr08(regs, head, NV_PRMCIO_CRX__COLOR, idx);
	head_wr08(regs, head, NV_PRMCIO_CR__COLOR, val);
}

static inline uint8_t
read_vga_seq(void *regs, int head, uint8_t idx)
{
	write_prmvio(regs, head, NV_PRMVIO_SRX, idx);
	return read_prmvio(regs, head, NV_PRMVIO_SR);
}

static inline void
write_vga_seq(void *regs, int head, uint8_t idx, uint8_t val)
{
	write_prmvio(regs, head, NV_PRMVIO_SRX, idx);
	write_prmvio(regs, head, NV_PRMVIO_SR, val);
}

static inline uint8_t
read_tmds(void *regs, int ramdac, int dl, uint8_t idx)
{
	head_wr32(regs, ramdac, 0x6808b0 + dl * 8, 0x10000 | idx);
	return head_rd32(regs, ramdac, 0x6808b4 + dl * 8);
}

static inline void
write_tmds(void *regs, int ramdac, int dl, uint8_t idx, uint8_t val)
{
        head_wr32(regs, ramdac, 0x6808b4 + dl * 8, val);
        head_wr32(regs, ramdac, 0x6808b0 + dl * 8, idx);
}

static inline uint8_t
read_itv(void *regs, uint8_t idx)
{
	nv_wr32(regs, 0xd220, idx);
	return nv_rd32(regs, 0xd224);
}

static inline void
write_itv(void *regs, uint8_t idx, uint8_t val)
{
	nv_wr32(regs, 0xd220, idx);
	nv_wr32(regs, 0xd224, val);
}

#endif