aboutsummaryrefslogtreecommitdiff
path: root/drivers/gpu/drm/nouveau/nouveau_compat.c
blob: 0403f2b94fa66cb8678e687388628928adaadeec (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
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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
#include "nouveau_drm.h"
#include "nouveau_compat.h"

#include <subdev/bios.h>
#include <subdev/bios/dcb.h>
#include <subdev/bios/init.h>
#include <subdev/bios/pll.h>
#include <subdev/gpio.h>
#include <subdev/i2c.h>
#include <subdev/clock.h>
#include <subdev/mc.h>
#include <subdev/timer.h>
#include <subdev/fb.h>
#include <subdev/bar.h>
#include <subdev/vm.h>

void *nouveau_newpriv(struct drm_device *);

int
nvdrm_gart_init(struct drm_device *dev, u64 *base, u64 *size)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	if (drm->agp.stat == ENABLED) {
		*base = drm->agp.base;
		*size = drm->agp.base;
		return 0;
	}
	return -ENODEV;
}

u8
_nv_rd08(struct drm_device *dev, u32 reg)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	return nv_ro08(drm->device, reg);
}

void
_nv_wr08(struct drm_device *dev, u32 reg, u8 val)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	nv_wo08(drm->device, reg, val);
}

u32
_nv_rd32(struct drm_device *dev, u32 reg)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	return nv_ro32(drm->device, reg);
}

void
_nv_wr32(struct drm_device *dev, u32 reg, u32 val)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	nv_wo32(drm->device, reg, val);
}

u32
_nv_mask(struct drm_device *dev, u32 reg, u32 mask, u32 val)
{
	u32 tmp = _nv_rd32(dev, reg);
	_nv_wr32(dev, reg, (tmp & ~mask) | val);
	return tmp;
}

bool
_nv_bios(struct drm_device *dev, u8 **data, u32 *size)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	struct nouveau_bios *bios = nouveau_bios(drm->device);
	*data = bios->data;
	*size = bios->size;
	return true;
}

void
nouveau_gpio_reset(struct drm_device *dev)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
	gpio->reset(gpio);
}

int
nouveau_gpio_find(struct drm_device *dev, int idx, u8 tag, u8 line,
		  struct dcb_gpio_func *func)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	struct nouveau_gpio *gpio = nouveau_gpio(drm->device);

	return gpio->find(gpio, idx, tag, line, func);
}

bool
nouveau_gpio_func_valid(struct drm_device *dev, u8 tag)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
	struct dcb_gpio_func func;

	return gpio->find(gpio, 0, tag, 0xff, &func) == 0;
}

int
nouveau_gpio_func_set(struct drm_device *dev, u8 tag, int state)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
	if (gpio && gpio->get)
		return gpio->set(gpio, 0, tag, 0xff, state);
	return -ENODEV;
}

int
nouveau_gpio_func_get(struct drm_device *dev, u8 tag)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
	if (gpio && gpio->get)
		return gpio->get(gpio, 0, tag, 0xff);
	return -ENODEV;
}

int
nouveau_gpio_irq(struct drm_device *dev, int idx, u8 tag, u8 line, bool on)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
	if (gpio && gpio->irq)
		return gpio->irq(gpio, idx, tag, line, on);
	return -ENODEV;
}

int
nouveau_gpio_isr_add(struct drm_device *dev, int idx, u8 tag, u8 line,
		     void (*exec)(void *, int state), void *data)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
	if (gpio && gpio->isr_add)
		return gpio->isr_add(gpio, idx, tag, line, exec, data);
	return -ENODEV;
}

void
nouveau_gpio_isr_del(struct drm_device *dev, int idx, u8 tag, u8 line,
		     void (*exec)(void *, int state), void *data)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	struct nouveau_gpio *gpio = nouveau_gpio(drm->device);
	if (gpio && gpio->isr_del)
		gpio->isr_del(gpio, idx, tag, line, exec, data);
}

struct nouveau_i2c_port *
nouveau_i2c_find(struct drm_device *dev, u8 index)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	struct nouveau_i2c *i2c = nouveau_i2c(drm->device);

	return i2c->find(i2c, index);
}

bool
nouveau_probe_i2c_addr(struct nouveau_i2c_port *port, int addr)
{
	return nv_probe_i2c(port, addr);
}

struct i2c_adapter *
nouveau_i2c_adapter(struct nouveau_i2c_port *port)
{
	return &port->adapter;
}


int
nouveau_i2c_identify(struct drm_device *dev, const char *what,
		     struct i2c_board_info *info,
		     bool (*match)(struct nouveau_i2c_port *,
			           struct i2c_board_info *),
		     int index)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	struct nouveau_i2c *i2c = nouveau_i2c(drm->device);

	return i2c->identify(i2c, index, what, info, match);
}

int
auxch_rd(struct drm_device *dev, struct nouveau_i2c_port *port,
	 u32 addr, u8 *data, u8 size)
{
	return nv_rdaux(port, addr, data, size);
}

int
auxch_wr(struct drm_device *dev, struct nouveau_i2c_port *port,
	 u32 addr, u8 *data, u8 size)
{
	return nv_wraux(port, addr, data, size);
}

u32
get_pll_register(struct drm_device *dev, u32 type)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	struct nouveau_bios *bios = nouveau_bios(drm->device);
	struct nvbios_pll info;

	if (nvbios_pll_parse(bios, type, &info))
		return 0;
	return info.reg;
}

int
get_pll_limits(struct drm_device *dev, u32 type, struct nvbios_pll *info)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	struct nouveau_bios *bios = nouveau_bios(drm->device);

	return nvbios_pll_parse(bios, type, info);
}

int
setPLL(struct drm_device *dev, u32 reg, u32 freq)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	struct nouveau_clock *clk = nouveau_clock(drm->device);
	int ret = -ENODEV;

	if (clk->pll_set)
		ret = clk->pll_set(clk, reg, freq);
	return ret;
}


int
nouveau_calc_pll_mnp(struct drm_device *dev, struct nvbios_pll *info,
		     int freq, struct nouveau_pll_vals *pv)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	struct nouveau_clock *clk = nouveau_clock(drm->device);
	int ret = 0;

	if (clk->pll_calc)
		ret = clk->pll_calc(clk, info, freq, pv);
	return ret;
}

int
nouveau_hw_setpll(struct drm_device *dev, u32 reg1,
		  struct nouveau_pll_vals *pv)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	struct nouveau_clock *clk = nouveau_clock(drm->device);
	int ret = -ENODEV;

	if (clk->pll_prog)
		ret = clk->pll_prog(clk, reg1, pv);
	return ret;
}

int nva3_pll_calc(struct nouveau_clock *, struct nvbios_pll *, u32 freq,
		  int *N, int *fN, int *M, int *P);

int
nva3_calc_pll(struct drm_device *dev, struct nvbios_pll *info, u32 freq,
	      int *N, int *fN, int *M, int *P)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	struct nouveau_clock *clk = nouveau_clock(drm->device);

	return nva3_pll_calc(clk, info, freq, N, fN, M, P);
}

void
nouveau_bios_run_init_table(struct drm_device *dev, uint16_t table,
			    struct dcb_output *dcbent, int crtc)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	struct nouveau_bios *bios = nouveau_bios(drm->device);
	struct nvbios_init init = {
		.subdev = nv_subdev(bios),
		.bios = bios,
		.offset = table,
		.outp = dcbent,
		.crtc = crtc,
		.execute = 1
	};

	nvbios_exec(&init);
}

void
nouveau_bios_init_exec(struct drm_device *dev, uint16_t table)
{
	nouveau_bios_run_init_table(dev, table, NULL, 0);
}

void
nv_intr(struct drm_device *dev)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	struct nouveau_mc *pmc = nouveau_mc(drm->device);
	nv_subdev(pmc)->intr(&pmc->base);
}

bool nouveau_wait_eq(struct drm_device *dev, uint64_t timeout,
			    uint32_t reg, uint32_t mask, uint32_t val)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	return nouveau_timer_wait_eq(drm->device, timeout, reg, mask, val);
}

bool nouveau_wait_ne(struct drm_device *dev, uint64_t timeout,
			    uint32_t reg, uint32_t mask, uint32_t val)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	return nouveau_timer_wait_ne(drm->device, timeout, reg, mask, val);
}

bool nouveau_wait_cb(struct drm_device *dev, u64 timeout,
			    bool (*cond)(void *), void *data)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	return nouveau_timer_wait_cb(drm->device, timeout, cond, data);
}

u64
nv_timer_read(struct drm_device *dev)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	struct nouveau_timer *ptimer = nouveau_timer(drm->device);
	return ptimer->read(ptimer);
}

int
nvfb_tile_nr(struct drm_device *dev)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	struct nouveau_fb *pfb = nouveau_fb(drm->device);
	return pfb->tile.regions;
}

struct nouveau_fb_tile *
nvfb_tile(struct drm_device *dev, int i)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	struct nouveau_fb *pfb = nouveau_fb(drm->device);
	return &pfb->tile.region[i];
}

void
nvfb_tile_init(struct drm_device *dev, int i, u32 a, u32 b, u32 c, u32 d)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	struct nouveau_fb *pfb = nouveau_fb(drm->device);
	pfb->tile.init(pfb, i, a, b, c, d, &pfb->tile.region[i]);
}

void
nvfb_tile_fini(struct drm_device *dev, int i)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	struct nouveau_fb *pfb = nouveau_fb(drm->device);
	pfb->tile.fini(pfb, i, &pfb->tile.region[i]);
}

void
nvfb_tile_prog(struct drm_device *dev, int i)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	struct nouveau_fb *pfb = nouveau_fb(drm->device);
	pfb->tile.prog(pfb, i, &pfb->tile.region[i]);
}

bool
nvfb_flags_valid(struct drm_device *dev, u32 flags)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	struct nouveau_fb *pfb = nouveau_fb(drm->device);
	return pfb->memtype_valid(pfb, flags);
}

int
nvfb_vram_get(struct drm_device *dev, u64 size, u32 align, u32 ncmin,
	      u32 memtype, struct nouveau_mem **pmem)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	struct nouveau_fb *pfb = nouveau_fb(drm->device);
	int ret = pfb->ram.get(pfb, size, align, ncmin, memtype, pmem);
	if (ret)
		return ret;
	(*pmem)->dev = dev;
	return 0;
}

void
nvfb_vram_put(struct drm_device *dev, struct nouveau_mem **pmem)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	struct nouveau_fb *pfb = nouveau_fb(drm->device);
	pfb->ram.put(pfb, pmem);
}


u64 nvfb_vram_sys_base(struct drm_device *dev)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	struct nouveau_fb *pfb = nouveau_fb(drm->device);
	return pfb->ram.stolen;
}

u64 nvfb_vram_size(struct drm_device *dev)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	struct nouveau_fb *pfb = nouveau_fb(drm->device);
	return pfb->ram.size;
}

int nvfb_vram_type(struct drm_device *dev)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	struct nouveau_fb *pfb = nouveau_fb(drm->device);
	return pfb->ram.type;
}

int nvfb_vram_rank_B(struct drm_device *dev)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	struct nouveau_fb *pfb = nouveau_fb(drm->device);
	return pfb->ram.ranks > 1;
}

void
nv50_fb_vm_trap(struct drm_device *dev, int disp)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	nv50_fb_trap(nouveau_fb(drm->device), disp);
}

#include <core/subdev/instmem/nv04.h>

struct nouveau_gpuobj *
nvimem_ramro(struct drm_device *dev)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	struct nv04_instmem_priv *imem = (void *)nouveau_instmem(drm->device);
	return imem->ramro;
}

struct nouveau_gpuobj *
nvimem_ramfc(struct drm_device *dev)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	struct nv04_instmem_priv *imem = (void *)nouveau_instmem(drm->device);
	return imem->ramfc;
}

int _nouveau_gpuobj_new(struct drm_device *dev, struct nouveau_gpuobj *par,
			int size, int align, u32 flags,
			struct nouveau_gpuobj **pobj)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	int ret;

	if (!par)
		flags |= NVOBJ_FLAG_HEAP;

	ret = nouveau_gpuobj_new(drm->device, nv_object(par), size, align,
				 flags, pobj);
	if (ret)
		return ret;

	(*pobj)->dev = dev;
	return 0;
}

u32 nv_ri32(struct drm_device *dev , u32 addr)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	struct nouveau_instmem *imem = nouveau_instmem(drm->device);
	return nv_ro32(imem, addr);
}

void nv_wi32(struct drm_device *dev, u32 addr, u32 data)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	struct nouveau_instmem *imem = nouveau_instmem(drm->device);
	nv_wo32(imem, addr, data);
}

u32 nvimem_reserved(struct drm_device *dev)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	struct nouveau_instmem *imem = nouveau_instmem(drm->device);
	return imem->reserved;
}

int
nvbar_map(struct drm_device *dev, struct nouveau_mem *mem, u32 flags,
	  struct nouveau_vma *vma)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	struct nouveau_bar *bar = nouveau_bar(drm->device);
	return bar->umap(bar, mem, flags, vma);
}

void
nvbar_unmap(struct drm_device *dev, struct nouveau_vma *vma)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	struct nouveau_bar *bar = nouveau_bar(drm->device);
	bar->unmap(bar, vma);
}

int
nouveau_gpuobj_map_bar(struct nouveau_gpuobj *gpuobj, u32 flags,
		       struct nouveau_vma *vma)
{
	struct nouveau_drm *drm = nouveau_newpriv(gpuobj->dev);
	struct nouveau_bar *bar = nouveau_bar(drm->device);
	struct nouveau_instobj *iobj = (void *)
		nv_pclass(nv_object(gpuobj), NV_MEMOBJ_CLASS);
	struct nouveau_mem **mem = (void *)(iobj + 1);
	struct nouveau_mem *node = *mem;

	return bar->umap(bar, node, flags, vma);
}

void
nvimem_flush(struct drm_device *dev)
{
}

void _nv50_vm_flush_engine(struct drm_device *dev, int engine)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	nv50_vm_flush_engine(nv_subdev(drm->device), engine);
}

int _nouveau_vm_new(struct drm_device *dev, u64 offset, u64 length,
		    u64 mm_offset, struct nouveau_vm **pvm)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	return nouveau_vm_new(nv_device(drm->device), offset, length, mm_offset, pvm);
}

#include <core/subdev/vm/nv04.h>
struct nouveau_vm *
nv04vm_ref(struct drm_device *dev)
{
	struct nouveau_drm *drm = nouveau_newpriv(dev);
	struct nouveau_vmmgr *vmm = nouveau_vmmgr(drm->device);
	struct nv04_vmmgr_priv *priv = (void *)vmm;
	return priv->vm;
}

struct nouveau_gpuobj *
nv04vm_refdma(struct drm_device *dev)
{
	struct nouveau_gpuobj *gpuobj = NULL;
	nouveau_gpuobj_ref(nv04vm_ref(dev)->pgt[0].obj[0], &gpuobj);
	return gpuobj;
}

void
nvvm_engref(struct nouveau_vm *vm, int eng, int ref)
{
	atomic_add(ref, &vm->engref[eng]);
}

int
nvvm_spg_shift(struct nouveau_vm *vm)
{
	return vm->vmm->spg_shift;
}

int
nvvm_lpg_shift(struct nouveau_vm *vm)
{
	return vm->vmm->lpg_shift;
}