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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
|
/*
* Copyright 2008 Stuart Bennett
*
* 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 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 AUTHORS 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 __NOUVEAU_HW_H__
#define __NOUVEAU_HW_H__
#include "drmP.h"
#include "nouveau_drv.h"
#include "nv04_display.h"
#define MASK(field) ( \
(0xffffffff >> (31 - ((1 ? field) - (0 ? field)))) << (0 ? field))
#define XLATE(src, srclowbit, outfield) ( \
(((src) >> (srclowbit)) << (0 ? outfield)) & MASK(outfield))
void NVWriteVgaSeq(struct nouveau_device *, int head, u8 index, u8 value);
u8 NVReadVgaSeq(struct nouveau_device *, int head, u8 index);
void NVWriteVgaGr(struct nouveau_device *, int head, u8 index, u8 value);
u8 NVReadVgaGr(struct nouveau_device *, int head, u8 index);
void NVSetOwner(struct nouveau_device *, int owner);
void NVBlankScreen(struct nouveau_device *, int head, bool blank);
void nouveau_hw_setpll(struct nouveau_device *, u32 reg1,
struct nouveau_pll_vals *pv);
int nouveau_hw_get_pllvals(struct nouveau_device *, enum pll_types plltype,
struct nouveau_pll_vals *pllvals);
int nouveau_hw_pllvals_to_clk(struct nouveau_pll_vals *pllvals);
int nouveau_hw_get_clock(struct nouveau_device *, enum pll_types plltype);
void nouveau_hw_save_vga_fonts(struct nouveau_device *, bool save);
void nouveau_hw_save_state(struct nouveau_device *, int head,
struct nv04_mode_state *state);
void nouveau_hw_load_state(struct nouveau_device *, int head,
struct nv04_mode_state *state);
void nouveau_hw_load_state_palette(struct nouveau_device *, int head,
struct nv04_mode_state *state);
/* nouveau_calc.c */
void nouveau_calc_arb(struct nouveau_device *, int vclk, int bpp,
int *burst, int *lwm);
int nouveau_calc_pll_mnp(struct nouveau_device *, struct pll_lims *pll_lim,
int clk, struct nouveau_pll_vals *pv);
static inline u32
NVReadCRTC(struct nouveau_device *ndev, int head, u32 reg)
{
u32 val;
if (head)
reg += NV_PCRTC0_SIZE;
val = nv_rd32(ndev, reg);
return val;
}
static inline void
NVWriteCRTC(struct nouveau_device *ndev, int head, u32 reg, u32 val)
{
if (head)
reg += NV_PCRTC0_SIZE;
nv_wr32(ndev, reg, val);
}
static inline u32
NVReadRAMDAC(struct nouveau_device *ndev, int head, u32 reg)
{
u32 val;
if (head)
reg += NV_PRAMDAC0_SIZE;
val = nv_rd32(ndev, reg);
return val;
}
static inline void
NVWriteRAMDAC(struct nouveau_device *ndev, int head, u32 reg, u32 val)
{
if (head)
reg += NV_PRAMDAC0_SIZE;
nv_wr32(ndev, reg, val);
}
static inline u8
nv_read_tmds(struct nouveau_device *ndev, int or, int dl, u8 address)
{
int ramdac = (or & OUTPUT_C) >> 2;
NVWriteRAMDAC(ndev, ramdac, NV_PRAMDAC_FP_TMDS_CONTROL + dl * 8,
NV_PRAMDAC_FP_TMDS_CONTROL_WRITE_DISABLE | address);
return NVReadRAMDAC(ndev, ramdac, NV_PRAMDAC_FP_TMDS_DATA + dl * 8);
}
static inline void
nv_write_tmds(struct nouveau_device *ndev, int or, int dl, u8 address, u8 data)
{
int ramdac = (or & OUTPUT_C) >> 2;
NVWriteRAMDAC(ndev, ramdac, NV_PRAMDAC_FP_TMDS_DATA + dl * 8, data);
NVWriteRAMDAC(ndev, ramdac, NV_PRAMDAC_FP_TMDS_CONTROL + dl * 8, address);
}
static inline void
NVWriteVgaCrtc(struct nouveau_device *ndev, int head, u8 index, u8 value)
{
nv_wr08(ndev, NV_PRMCIO_CRX__COLOR + head * NV_PRMCIO_SIZE, index);
nv_wr08(ndev, NV_PRMCIO_CR__COLOR + head * NV_PRMCIO_SIZE, value);
}
static inline u8
NVReadVgaCrtc(struct nouveau_device *ndev, int head, u8 index)
{
u8 val;
nv_wr08(ndev, NV_PRMCIO_CRX__COLOR + head * NV_PRMCIO_SIZE, index);
val = nv_rd08(ndev, NV_PRMCIO_CR__COLOR + head * NV_PRMCIO_SIZE);
return val;
}
/* CR57 and CR58 are a fun pair of regs. CR57 provides an index (0-0xf) for CR58
* I suspect they in fact do nothing, but are merely a way to carry useful
* per-head variables around
*
* Known uses:
* CR57 CR58
* 0x00 index to the appropriate dcb entry (or 7f for inactive)
* 0x02 dcb entry's "or" value (or 00 for inactive)
* 0x03 bit0 set for dual link (LVDS, possibly elsewhere too)
* 0x08 or 0x09 pxclk in MHz
* 0x0f laptop panel info - low nibble for PEXTDEV_BOOT_0 strap
* high nibble for xlat strap value
*/
static inline void
NVWriteVgaCrtc5758(struct nouveau_device *ndev, int head, u8 index, u8 value)
{
NVWriteVgaCrtc(ndev, head, NV_CIO_CRE_57, index);
NVWriteVgaCrtc(ndev, head, NV_CIO_CRE_58, value);
}
static inline u8
NVReadVgaCrtc5758(struct nouveau_device *ndev, int head, u8 index)
{
NVWriteVgaCrtc(ndev, head, NV_CIO_CRE_57, index);
return NVReadVgaCrtc(ndev, head, NV_CIO_CRE_58);
}
static inline u8
NVReadPRMVIO(struct nouveau_device *ndev, int head, u32 reg)
{
u8 val;
/* Only NV4x have two pvio ranges; other twoHeads cards MUST call
* NVSetOwner for the relevant head to be programmed */
if (head && ndev->card_type == NV_40)
reg += NV_PRMVIO_SIZE;
val = nv_rd08(ndev, reg);
return val;
}
static inline void
NVWritePRMVIO(struct nouveau_device *ndev, int head, u32 reg, u8 value)
{
/* Only NV4x have two pvio ranges; other twoHeads cards MUST call
* NVSetOwner for the relevant head to be programmed */
if (head && ndev->card_type == NV_40)
reg += NV_PRMVIO_SIZE;
nv_wr08(ndev, reg, value);
}
static inline void
NVSetEnablePalette(struct nouveau_device *ndev, int head, bool enable)
{
nv_rd08(ndev, NV_PRMCIO_INP0__COLOR + head * NV_PRMCIO_SIZE);
nv_wr08(ndev, NV_PRMCIO_ARX + head * NV_PRMCIO_SIZE, enable ? 0 : 0x20);
}
static inline bool
NVGetEnablePalette(struct nouveau_device *ndev, int head)
{
nv_rd08(ndev, NV_PRMCIO_INP0__COLOR + head * NV_PRMCIO_SIZE);
return !(nv_rd08(ndev, NV_PRMCIO_ARX + head * NV_PRMCIO_SIZE) & 0x20);
}
static inline void
NVWriteVgaAttr(struct nouveau_device *ndev, int head, u8 index, u8 value)
{
if (NVGetEnablePalette(ndev, head))
index &= ~0x20;
else
index |= 0x20;
nv_rd08(ndev, NV_PRMCIO_INP0__COLOR + head * NV_PRMCIO_SIZE);
nv_wr08(ndev, NV_PRMCIO_ARX + head * NV_PRMCIO_SIZE, index);
nv_wr08(ndev, NV_PRMCIO_AR__WRITE + head * NV_PRMCIO_SIZE, value);
}
static inline u8
NVReadVgaAttr(struct nouveau_device *ndev, int head, u8 index)
{
u8 val;
if (NVGetEnablePalette(ndev, head))
index &= ~0x20;
else
index |= 0x20;
nv_rd08(ndev, NV_PRMCIO_INP0__COLOR + head * NV_PRMCIO_SIZE);
nv_wr08(ndev, NV_PRMCIO_ARX + head * NV_PRMCIO_SIZE, index);
val = nv_rd08(ndev, NV_PRMCIO_AR__READ + head * NV_PRMCIO_SIZE);
return val;
}
static inline void
NVVgaSeqReset(struct nouveau_device *ndev, int head, bool start)
{
NVWriteVgaSeq(ndev, head, NV_VIO_SR_RESET_INDEX, start ? 0x1 : 0x3);
}
static inline void
NVVgaProtect(struct nouveau_device *ndev, int head, bool protect)
{
u8 seq1 = NVReadVgaSeq(ndev, head, NV_VIO_SR_CLOCK_INDEX);
if (protect) {
NVVgaSeqReset(ndev, head, true);
NVWriteVgaSeq(ndev, head, NV_VIO_SR_CLOCK_INDEX, seq1 | 0x20);
} else {
/* Reenable sequencer, then turn on screen */
NVWriteVgaSeq(ndev, head, NV_VIO_SR_CLOCK_INDEX, seq1 & ~0x20); /* reenable display */
NVVgaSeqReset(ndev, head, false);
}
NVSetEnablePalette(ndev, head, protect);
}
static inline bool
nv_heads_tied(struct nouveau_device *ndev)
{
if (ndev->chipset == 0x11)
return !!(nv_rd32(ndev, NV_PBUS_DEBUG_1) & (1 << 28));
return NVReadVgaCrtc(ndev, 0, NV_CIO_CRE_44) & 0x4;
}
/* makes cr0-7 on the specified head read-only */
static inline bool
nv_lock_vga_crtc_base(struct nouveau_device *ndev, int head, bool lock)
{
u8 cr11 = NVReadVgaCrtc(ndev, head, NV_CIO_CR_VRE_INDEX);
bool waslocked = cr11 & 0x80;
if (lock)
cr11 |= 0x80;
else
cr11 &= ~0x80;
NVWriteVgaCrtc(ndev, head, NV_CIO_CR_VRE_INDEX, cr11);
return waslocked;
}
static inline void
nv_lock_vga_crtc_shadow(struct nouveau_device *ndev, int head, int lock)
{
/* shadow lock: connects 0x60?3d? regs to "real" 0x3d? regs
* bit7: unlocks HDT, HBS, HBE, HRS, HRE, HEB
* bit6: seems to have some effect on CR09 (double scan, VBS_9)
* bit5: unlocks HDE
* bit4: unlocks VDE
* bit3: unlocks VDT, OVL, VRS, ?VRE?, VBS, VBE, LSR, EBR
* bit2: same as bit 1 of 0x60?804
* bit0: same as bit 0 of 0x60?804
*/
u8 cr21 = lock;
if (lock < 0)
/* 0xfa is generic "unlock all" mask */
cr21 = NVReadVgaCrtc(ndev, head, NV_CIO_CRE_21) | 0xfa;
NVWriteVgaCrtc(ndev, head, NV_CIO_CRE_21, cr21);
}
/* renders the extended crtc regs (cr19+) on all crtcs impervious:
* immutable and unreadable
*/
static inline bool
NVLockVgaCrtcs(struct nouveau_device *ndev, bool lock)
{
bool waslocked = !NVReadVgaCrtc(ndev, 0, NV_CIO_SR_LOCK_INDEX);
NVWriteVgaCrtc(ndev, 0, NV_CIO_SR_LOCK_INDEX,
lock ? NV_CIO_SR_LOCK_VALUE : NV_CIO_SR_UNLOCK_RW_VALUE);
/* NV11 has independently lockable extended crtcs, except when tied */
if (ndev->chipset == 0x11 && !nv_heads_tied(ndev))
NVWriteVgaCrtc(ndev, 1, NV_CIO_SR_LOCK_INDEX,
lock ? NV_CIO_SR_LOCK_VALUE :
NV_CIO_SR_UNLOCK_RW_VALUE);
return waslocked;
}
/* nv04 cursor max dimensions of 32x32 (A1R5G5B5) */
#define NV04_CURSOR_SIZE 32
/* limit nv10 cursors to 64x64 (ARGB8) (we could go to 64x255) */
#define NV10_CURSOR_SIZE 64
static inline int
nv_cursor_width(struct nouveau_device *ndev)
{
return ndev->card_type >= NV_10 ? NV10_CURSOR_SIZE : NV04_CURSOR_SIZE;
}
static inline void
nv_fix_nv40_hw_cursor(struct nouveau_device *ndev, int head)
{
/* on some nv40 (such as the "true" (in the NV_PFB_BOOT_0 sense) nv40,
* the gf6800gt) a hardware bug requires a write to PRAMDAC_CURSOR_POS
* for changes to the CRTC CURCTL regs to take effect, whether changing
* the pixmap location, or just showing/hiding the cursor
*/
u32 curpos = NVReadRAMDAC(ndev, head, NV_PRAMDAC_CU_START_POS);
NVWriteRAMDAC(ndev, head, NV_PRAMDAC_CU_START_POS, curpos);
}
static inline void
nv_set_crtc_base(struct nouveau_device *ndev, int head, u32 offset)
{
NVWriteCRTC(ndev, head, NV_PCRTC_START, offset);
if (ndev->card_type == NV_04) {
/*
* Hilarious, the 24th bit doesn't want to stick to
* PCRTC_START...
*/
int cre_heb = NVReadVgaCrtc(ndev, head, NV_CIO_CRE_HEB__INDEX);
NVWriteVgaCrtc(ndev, head, NV_CIO_CRE_HEB__INDEX,
(cre_heb & ~0x40) | ((offset >> 18) & 0x40));
}
}
static inline void
nv_show_cursor(struct nouveau_device *ndev, int head, bool show)
{
struct nv04_display *disp = nv04_display(ndev);
u8 *curctl1 =
&disp->mode_reg.crtc_reg[head].CRTC[NV_CIO_CRE_HCUR_ADDR1_INDEX];
if (show)
*curctl1 |= MASK(NV_CIO_CRE_HCUR_ADDR1_ENABLE);
else
*curctl1 &= ~MASK(NV_CIO_CRE_HCUR_ADDR1_ENABLE);
NVWriteVgaCrtc(ndev, head, NV_CIO_CRE_HCUR_ADDR1_INDEX, *curctl1);
if (ndev->card_type == NV_40)
nv_fix_nv40_hw_cursor(ndev, head);
}
static inline u32
nv_pitch_align(struct nouveau_device *ndev, u32 width, int bpp)
{
int mask;
if (bpp == 15)
bpp = 16;
if (bpp == 24)
bpp = 8;
/* Alignment requirements taken from the Haiku driver */
if (ndev->card_type == NV_04)
mask = 128 / bpp - 1;
else
mask = 512 / bpp - 1;
return (width + mask) & ~mask;
}
#endif /* __NOUVEAU_HW_H__ */
|