1 #include "nouveau_drm.h"
2 #include "nouveau_chan.h"
3 #include "nouveau_compat.h"
5 #include <subdev/bios.h>
6 #include <subdev/bios/dcb.h>
7 #include <subdev/bios/init.h>
8 #include <subdev/bios/pll.h>
9 #include <subdev/gpio.h>
10 #include <subdev/i2c.h>
11 #include <subdev/clock.h>
12 #include <subdev/mc.h>
13 #include <subdev/timer.h>
14 #include <subdev/fb.h>
15 #include <subdev/bar.h>
16 #include <subdev/vm.h>
19 nvdrm_gart_init(struct drm_device
*dev
, u64
*base
, u64
*size
)
21 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
22 if (drm
->agp
.stat
== ENABLED
) {
23 *base
= drm
->agp
.base
;
24 *size
= drm
->agp
.base
;
31 _nv_rd08(struct drm_device
*dev
, u32 reg
)
33 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
34 return nv_ro08(drm
->device
, reg
);
38 _nv_wr08(struct drm_device
*dev
, u32 reg
, u8 val
)
40 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
41 nv_wo08(drm
->device
, reg
, val
);
45 _nv_rd32(struct drm_device
*dev
, u32 reg
)
47 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
48 return nv_ro32(drm
->device
, reg
);
52 _nv_wr32(struct drm_device
*dev
, u32 reg
, u32 val
)
54 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
55 nv_wo32(drm
->device
, reg
, val
);
59 _nv_mask(struct drm_device
*dev
, u32 reg
, u32 mask
, u32 val
)
61 u32 tmp
= _nv_rd32(dev
, reg
);
62 _nv_wr32(dev
, reg
, (tmp
& ~mask
) | val
);
67 _nv_bios(struct drm_device
*dev
, u8
**data
, u32
*size
)
69 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
70 struct nouveau_bios
*bios
= nouveau_bios(drm
->device
);
77 nouveau_gpio_reset(struct drm_device
*dev
)
79 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
80 struct nouveau_gpio
*gpio
= nouveau_gpio(drm
->device
);
85 nouveau_gpio_find(struct drm_device
*dev
, int idx
, u8 tag
, u8 line
,
86 struct dcb_gpio_func
*func
)
88 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
89 struct nouveau_gpio
*gpio
= nouveau_gpio(drm
->device
);
91 return gpio
->find(gpio
, idx
, tag
, line
, func
);
95 nouveau_gpio_func_valid(struct drm_device
*dev
, u8 tag
)
97 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
98 struct nouveau_gpio
*gpio
= nouveau_gpio(drm
->device
);
99 struct dcb_gpio_func func
;
101 return gpio
->find(gpio
, 0, tag
, 0xff, &func
) == 0;
105 nouveau_gpio_func_set(struct drm_device
*dev
, u8 tag
, int state
)
107 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
108 struct nouveau_gpio
*gpio
= nouveau_gpio(drm
->device
);
109 if (gpio
&& gpio
->get
)
110 return gpio
->set(gpio
, 0, tag
, 0xff, state
);
115 nouveau_gpio_func_get(struct drm_device
*dev
, u8 tag
)
117 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
118 struct nouveau_gpio
*gpio
= nouveau_gpio(drm
->device
);
119 if (gpio
&& gpio
->get
)
120 return gpio
->get(gpio
, 0, tag
, 0xff);
125 nouveau_gpio_irq(struct drm_device
*dev
, int idx
, u8 tag
, u8 line
, bool on
)
127 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
128 struct nouveau_gpio
*gpio
= nouveau_gpio(drm
->device
);
129 if (gpio
&& gpio
->irq
)
130 return gpio
->irq(gpio
, idx
, tag
, line
, on
);
135 nouveau_gpio_isr_add(struct drm_device
*dev
, int idx
, u8 tag
, u8 line
,
136 void (*exec
)(void *, int state
), void *data
)
138 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
139 struct nouveau_gpio
*gpio
= nouveau_gpio(drm
->device
);
140 if (gpio
&& gpio
->isr_add
)
141 return gpio
->isr_add(gpio
, idx
, tag
, line
, exec
, data
);
146 nouveau_gpio_isr_del(struct drm_device
*dev
, int idx
, u8 tag
, u8 line
,
147 void (*exec
)(void *, int state
), void *data
)
149 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
150 struct nouveau_gpio
*gpio
= nouveau_gpio(drm
->device
);
151 if (gpio
&& gpio
->isr_del
)
152 gpio
->isr_del(gpio
, idx
, tag
, line
, exec
, data
);
155 struct nouveau_i2c_port
*
156 nouveau_i2c_find(struct drm_device
*dev
, u8 index
)
158 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
159 struct nouveau_i2c
*i2c
= nouveau_i2c(drm
->device
);
161 return i2c
->find(i2c
, index
);
165 nouveau_probe_i2c_addr(struct nouveau_i2c_port
*port
, int addr
)
167 return nv_probe_i2c(port
, addr
);
171 nouveau_i2c_adapter(struct nouveau_i2c_port
*port
)
173 return &port
->adapter
;
178 nouveau_i2c_identify(struct drm_device
*dev
, const char *what
,
179 struct i2c_board_info
*info
,
180 bool (*match
)(struct nouveau_i2c_port
*,
181 struct i2c_board_info
*),
184 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
185 struct nouveau_i2c
*i2c
= nouveau_i2c(drm
->device
);
187 return i2c
->identify(i2c
, index
, what
, info
, match
);
191 auxch_rd(struct drm_device
*dev
, struct nouveau_i2c_port
*port
,
192 u32 addr
, u8
*data
, u8 size
)
194 return nv_rdaux(port
, addr
, data
, size
);
198 auxch_wr(struct drm_device
*dev
, struct nouveau_i2c_port
*port
,
199 u32 addr
, u8
*data
, u8 size
)
201 return nv_wraux(port
, addr
, data
, size
);
205 get_pll_register(struct drm_device
*dev
, u32 type
)
207 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
208 struct nouveau_bios
*bios
= nouveau_bios(drm
->device
);
209 struct nvbios_pll info
;
211 if (nvbios_pll_parse(bios
, type
, &info
))
217 get_pll_limits(struct drm_device
*dev
, u32 type
, struct nvbios_pll
*info
)
219 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
220 struct nouveau_bios
*bios
= nouveau_bios(drm
->device
);
222 return nvbios_pll_parse(bios
, type
, info
);
226 setPLL(struct drm_device
*dev
, u32 reg
, u32 freq
)
228 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
229 struct nouveau_clock
*clk
= nouveau_clock(drm
->device
);
233 ret
= clk
->pll_set(clk
, reg
, freq
);
239 nouveau_calc_pll_mnp(struct drm_device
*dev
, struct nvbios_pll
*info
,
240 int freq
, struct nouveau_pll_vals
*pv
)
242 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
243 struct nouveau_clock
*clk
= nouveau_clock(drm
->device
);
247 ret
= clk
->pll_calc(clk
, info
, freq
, pv
);
252 nouveau_hw_setpll(struct drm_device
*dev
, u32 reg1
,
253 struct nouveau_pll_vals
*pv
)
255 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
256 struct nouveau_clock
*clk
= nouveau_clock(drm
->device
);
260 ret
= clk
->pll_prog(clk
, reg1
, pv
);
264 int nva3_pll_calc(struct nouveau_clock
*, struct nvbios_pll
*, u32 freq
,
265 int *N
, int *fN
, int *M
, int *P
);
268 nva3_calc_pll(struct drm_device
*dev
, struct nvbios_pll
*info
, u32 freq
,
269 int *N
, int *fN
, int *M
, int *P
)
271 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
272 struct nouveau_clock
*clk
= nouveau_clock(drm
->device
);
274 return nva3_pll_calc(clk
, info
, freq
, N
, fN
, M
, P
);
278 nouveau_bios_run_init_table(struct drm_device
*dev
, uint16_t table
,
279 struct dcb_output
*dcbent
, int crtc
)
281 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
282 struct nouveau_bios
*bios
= nouveau_bios(drm
->device
);
283 struct nvbios_init init
= {
284 .subdev
= nv_subdev(bios
),
296 nouveau_bios_init_exec(struct drm_device
*dev
, uint16_t table
)
298 nouveau_bios_run_init_table(dev
, table
, NULL
, 0);
302 nv_intr(struct drm_device
*dev
)
304 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
305 struct nouveau_mc
*pmc
= nouveau_mc(drm
->device
);
306 nv_subdev(pmc
)->intr(&pmc
->base
);
309 bool nouveau_wait_eq(struct drm_device
*dev
, uint64_t timeout
,
310 uint32_t reg
, uint32_t mask
, uint32_t val
)
312 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
313 return nouveau_timer_wait_eq(drm
->device
, timeout
, reg
, mask
, val
);
316 bool nouveau_wait_ne(struct drm_device
*dev
, uint64_t timeout
,
317 uint32_t reg
, uint32_t mask
, uint32_t val
)
319 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
320 return nouveau_timer_wait_ne(drm
->device
, timeout
, reg
, mask
, val
);
323 bool nouveau_wait_cb(struct drm_device
*dev
, u64 timeout
,
324 bool (*cond
)(void *), void *data
)
326 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
327 return nouveau_timer_wait_cb(drm
->device
, timeout
, cond
, data
);
331 nv_timer_read(struct drm_device
*dev
)
333 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
334 struct nouveau_timer
*ptimer
= nouveau_timer(drm
->device
);
335 return ptimer
->read(ptimer
);
339 nvfb_tile_nr(struct drm_device
*dev
)
341 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
342 struct nouveau_fb
*pfb
= nouveau_fb(drm
->device
);
343 return pfb
->tile
.regions
;
346 struct nouveau_fb_tile
*
347 nvfb_tile(struct drm_device
*dev
, int i
)
349 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
350 struct nouveau_fb
*pfb
= nouveau_fb(drm
->device
);
351 return &pfb
->tile
.region
[i
];
355 nvfb_tile_init(struct drm_device
*dev
, int i
, u32 a
, u32 b
, u32 c
, u32 d
)
357 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
358 struct nouveau_fb
*pfb
= nouveau_fb(drm
->device
);
359 pfb
->tile
.init(pfb
, i
, a
, b
, c
, d
, &pfb
->tile
.region
[i
]);
363 nvfb_tile_fini(struct drm_device
*dev
, int i
)
365 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
366 struct nouveau_fb
*pfb
= nouveau_fb(drm
->device
);
367 pfb
->tile
.fini(pfb
, i
, &pfb
->tile
.region
[i
]);
371 nvfb_tile_prog(struct drm_device
*dev
, int i
)
373 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
374 struct nouveau_fb
*pfb
= nouveau_fb(drm
->device
);
375 pfb
->tile
.prog(pfb
, i
, &pfb
->tile
.region
[i
]);
379 nvfb_flags_valid(struct drm_device
*dev
, u32 flags
)
381 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
382 struct nouveau_fb
*pfb
= nouveau_fb(drm
->device
);
383 return pfb
->memtype_valid(pfb
, flags
);
387 nvfb_vram_get(struct drm_device
*dev
, u64 size
, u32 align
, u32 ncmin
,
388 u32 memtype
, struct nouveau_mem
**pmem
)
390 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
391 struct nouveau_fb
*pfb
= nouveau_fb(drm
->device
);
392 int ret
= pfb
->ram
.get(pfb
, size
, align
, ncmin
, memtype
, pmem
);
400 nvfb_vram_put(struct drm_device
*dev
, struct nouveau_mem
**pmem
)
402 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
403 struct nouveau_fb
*pfb
= nouveau_fb(drm
->device
);
404 pfb
->ram
.put(pfb
, pmem
);
408 u64
nvfb_vram_sys_base(struct drm_device
*dev
)
410 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
411 struct nouveau_fb
*pfb
= nouveau_fb(drm
->device
);
412 return pfb
->ram
.stolen
;
415 u64
nvfb_vram_size(struct drm_device
*dev
)
417 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
418 struct nouveau_fb
*pfb
= nouveau_fb(drm
->device
);
419 return pfb
->ram
.size
;
422 int nvfb_vram_type(struct drm_device
*dev
)
424 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
425 struct nouveau_fb
*pfb
= nouveau_fb(drm
->device
);
426 return pfb
->ram
.type
;
429 int nvfb_vram_rank_B(struct drm_device
*dev
)
431 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
432 struct nouveau_fb
*pfb
= nouveau_fb(drm
->device
);
433 return pfb
->ram
.ranks
> 1;
437 nv50_fb_vm_trap(struct drm_device
*dev
, int disp
)
439 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
440 nv50_fb_trap(nouveau_fb(drm
->device
), disp
);
443 #include <core/subdev/instmem/nv04.h>
445 struct nouveau_gpuobj
*
446 nvimem_ramro(struct drm_device
*dev
)
448 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
449 struct nv04_instmem_priv
*imem
= (void *)nouveau_instmem(drm
->device
);
453 struct nouveau_gpuobj
*
454 nvimem_ramfc(struct drm_device
*dev
)
456 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
457 struct nv04_instmem_priv
*imem
= (void *)nouveau_instmem(drm
->device
);
461 int _nouveau_gpuobj_new(struct drm_device
*dev
, struct nouveau_gpuobj
*par
,
462 int size
, int align
, u32 flags
,
463 struct nouveau_gpuobj
**pobj
)
465 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
469 flags
|= NVOBJ_FLAG_HEAP
;
471 ret
= nouveau_gpuobj_new(drm
->device
, nv_object(par
), size
, align
,
480 u32
nv_ri32(struct drm_device
*dev
, u32 addr
)
482 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
483 struct nouveau_instmem
*imem
= nouveau_instmem(drm
->device
);
484 return nv_ro32(imem
, addr
);
487 void nv_wi32(struct drm_device
*dev
, u32 addr
, u32 data
)
489 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
490 struct nouveau_instmem
*imem
= nouveau_instmem(drm
->device
);
491 nv_wo32(imem
, addr
, data
);
494 u32
nvimem_reserved(struct drm_device
*dev
)
496 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
497 struct nouveau_instmem
*imem
= nouveau_instmem(drm
->device
);
498 return imem
->reserved
;
502 nvbar_map(struct drm_device
*dev
, struct nouveau_mem
*mem
, u32 flags
,
503 struct nouveau_vma
*vma
)
505 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
506 struct nouveau_bar
*bar
= nouveau_bar(drm
->device
);
507 return bar
->umap(bar
, mem
, flags
, vma
);
511 nvbar_unmap(struct drm_device
*dev
, struct nouveau_vma
*vma
)
513 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
514 struct nouveau_bar
*bar
= nouveau_bar(drm
->device
);
515 bar
->unmap(bar
, vma
);
519 nouveau_gpuobj_map_bar(struct nouveau_gpuobj
*gpuobj
, u32 flags
,
520 struct nouveau_vma
*vma
)
522 struct nouveau_drm
*drm
= nouveau_newpriv(gpuobj
->dev
);
523 struct nouveau_bar
*bar
= nouveau_bar(drm
->device
);
524 struct nouveau_instobj
*iobj
= (void *)
525 nv_pclass(nv_object(gpuobj
), NV_MEMOBJ_CLASS
);
526 struct nouveau_mem
**mem
= (void *)(iobj
+ 1);
527 struct nouveau_mem
*node
= *mem
;
529 return bar
->umap(bar
, node
, flags
, vma
);
533 nvimem_flush(struct drm_device
*dev
)
537 void _nv50_vm_flush_engine(struct drm_device
*dev
, int engine
)
539 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
540 nv50_vm_flush_engine(nv_subdev(drm
->device
), engine
);
543 int _nouveau_vm_new(struct drm_device
*dev
, u64 offset
, u64 length
,
544 u64 mm_offset
, struct nouveau_vm
**pvm
)
546 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
547 return nouveau_vm_new(nv_device(drm
->device
), offset
, length
, mm_offset
, pvm
);
550 #include <core/subdev/vm/nv04.h>
552 nv04vm_ref(struct drm_device
*dev
)
554 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
555 struct nouveau_vmmgr
*vmm
= nouveau_vmmgr(drm
->device
);
556 struct nv04_vmmgr_priv
*priv
= (void *)vmm
;
560 struct nouveau_gpuobj
*
561 nv04vm_refdma(struct drm_device
*dev
)
563 struct nouveau_gpuobj
*gpuobj
= NULL
;
564 nouveau_gpuobj_ref(nv04vm_ref(dev
)->pgt
[0].obj
[0], &gpuobj
);
569 nvvm_engref(struct nouveau_vm
*vm
, int eng
, int ref
)
571 atomic_add(ref
, &vm
->engref
[eng
]);
575 nvvm_spg_shift(struct nouveau_vm
*vm
)
577 return vm
->vmm
->spg_shift
;
581 nvvm_lpg_shift(struct nouveau_vm
*vm
)
583 return vm
->vmm
->lpg_shift
;
586 u64
nvgpuobj_addr(struct nouveau_object
*object
)
588 return nv_gpuobj(object
)->addr
;
592 nouveau_drv(void *ptr
)
594 struct nouveau_drm
*drm
= ptr
;
598 struct nouveau_channel
*
599 nvdrm_channel(struct drm_device
*dev
)
601 struct nouveau_drm
*drm
= nouveau_newpriv(dev
);
606 nvchan_mutex(struct nouveau_channel
*chan
)
608 return &chan
->cli
->mutex
;
This page took 0.053956 seconds and 5 git commands to generate.