blob: e82dff4008c91658dee02b4e4f5c581db6068861 [file] [log] [blame]
Ben Skeggs6ee73862009-12-11 19:24:15 +10001/*
2 * Copyright 2005 Stephane Marchesin.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25#ifndef __NOUVEAU_DRV_H__
26#define __NOUVEAU_DRV_H__
27
28#define DRIVER_AUTHOR "Stephane Marchesin"
29#define DRIVER_EMAIL "dri-devel@lists.sourceforge.net"
30
31#define DRIVER_NAME "nouveau"
32#define DRIVER_DESC "nVidia Riva/TNT/GeForce"
33#define DRIVER_DATE "20090420"
34
35#define DRIVER_MAJOR 0
36#define DRIVER_MINOR 0
Ben Skeggsa1606a92010-02-12 10:27:35 +100037#define DRIVER_PATCHLEVEL 16
Ben Skeggs6ee73862009-12-11 19:24:15 +100038
39#define NOUVEAU_FAMILY 0x0000FFFF
40#define NOUVEAU_FLAGS 0xFFFF0000
41
42#include "ttm/ttm_bo_api.h"
43#include "ttm/ttm_bo_driver.h"
44#include "ttm/ttm_placement.h"
45#include "ttm/ttm_memory.h"
46#include "ttm/ttm_module.h"
47
48struct nouveau_fpriv {
49 struct ttm_object_file *tfile;
50};
51
52#define DRM_FILE_PAGE_OFFSET (0x100000000ULL >> PAGE_SHIFT)
53
54#include "nouveau_drm.h"
55#include "nouveau_reg.h"
56#include "nouveau_bios.h"
Ben Skeggs274fec92010-11-03 13:16:18 +100057#include "nouveau_util.h"
Ben Skeggs054b93e2009-12-15 22:02:47 +100058struct nouveau_grctx;
Ben Skeggs6ee73862009-12-11 19:24:15 +100059
60#define MAX_NUM_DCB_ENTRIES 16
61
62#define NOUVEAU_MAX_CHANNEL_NR 128
Francisco Jereza0af9ad2009-12-11 16:51:09 +010063#define NOUVEAU_MAX_TILE_NR 15
Ben Skeggs6ee73862009-12-11 19:24:15 +100064
65#define NV50_VM_MAX_VRAM (2*1024*1024*1024ULL)
66#define NV50_VM_BLOCK (512*1024*1024ULL)
67#define NV50_VM_VRAM_NR (NV50_VM_MAX_VRAM / NV50_VM_BLOCK)
68
Francisco Jereza0af9ad2009-12-11 16:51:09 +010069struct nouveau_tile_reg {
Francisco Jereza0af9ad2009-12-11 16:51:09 +010070 bool used;
Francisco Jereza5cf68b2010-10-24 16:14:41 +020071 uint32_t addr;
72 uint32_t limit;
73 uint32_t pitch;
Francisco Jerez87a326a2010-10-24 16:36:12 +020074 uint32_t zcomp;
75 struct drm_mm_node *tag_mem;
Francisco Jereza5cf68b2010-10-24 16:14:41 +020076 struct nouveau_fence *fence;
Francisco Jereza0af9ad2009-12-11 16:51:09 +010077};
78
Ben Skeggs6ee73862009-12-11 19:24:15 +100079struct nouveau_bo {
80 struct ttm_buffer_object bo;
81 struct ttm_placement placement;
82 u32 placements[3];
Francisco Jerez78ad0f72010-03-18 13:07:47 +010083 u32 busy_placements[3];
Ben Skeggs6ee73862009-12-11 19:24:15 +100084 struct ttm_bo_kmap_obj kmap;
85 struct list_head head;
86
87 /* protected by ttm_bo_reserve() */
88 struct drm_file *reserved_by;
89 struct list_head entry;
90 int pbbo_index;
Ben Skeggsa1606a92010-02-12 10:27:35 +100091 bool validate_mapped;
Ben Skeggs6ee73862009-12-11 19:24:15 +100092
93 struct nouveau_channel *channel;
94
95 bool mappable;
96 bool no_vm;
97
98 uint32_t tile_mode;
99 uint32_t tile_flags;
Francisco Jereza0af9ad2009-12-11 16:51:09 +0100100 struct nouveau_tile_reg *tile;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000101
102 struct drm_gem_object *gem;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000103 int pin_refcnt;
104};
105
Francisco Jerezf13b3262010-10-10 06:01:08 +0200106#define nouveau_bo_tile_layout(nvbo) \
107 ((nvbo)->tile_flags & NOUVEAU_GEM_TILE_LAYOUT_MASK)
108
Ben Skeggs6ee73862009-12-11 19:24:15 +1000109static inline struct nouveau_bo *
110nouveau_bo(struct ttm_buffer_object *bo)
111{
112 return container_of(bo, struct nouveau_bo, bo);
113}
114
115static inline struct nouveau_bo *
116nouveau_gem_object(struct drm_gem_object *gem)
117{
118 return gem ? gem->driver_private : NULL;
119}
120
121/* TODO: submit equivalent to TTM generic API upstream? */
122static inline void __iomem *
123nvbo_kmap_obj_iovirtual(struct nouveau_bo *nvbo)
124{
125 bool is_iomem;
126 void __iomem *ioptr = (void __force __iomem *)ttm_kmap_obj_virtual(
127 &nvbo->kmap, &is_iomem);
128 WARN_ON_ONCE(ioptr && !is_iomem);
129 return ioptr;
130}
131
Ben Skeggs6ee73862009-12-11 19:24:15 +1000132enum nouveau_flags {
133 NV_NFORCE = 0x10000000,
134 NV_NFORCE2 = 0x20000000
135};
136
137#define NVOBJ_ENGINE_SW 0
138#define NVOBJ_ENGINE_GR 1
Ben Skeggsbd2e5972010-10-19 20:06:01 +1000139#define NVOBJ_ENGINE_PPP 2
140#define NVOBJ_ENGINE_COPY 3
141#define NVOBJ_ENGINE_VP 4
142#define NVOBJ_ENGINE_CRYPT 5
143#define NVOBJ_ENGINE_BSP 6
Ben Skeggs50536942010-10-19 19:47:06 +1000144#define NVOBJ_ENGINE_DISPLAY 0xcafe0001
Ben Skeggs6ee73862009-12-11 19:24:15 +1000145#define NVOBJ_ENGINE_INT 0xdeadbeef
146
Ben Skeggs6ee73862009-12-11 19:24:15 +1000147#define NVOBJ_FLAG_ZERO_ALLOC (1 << 1)
148#define NVOBJ_FLAG_ZERO_FREE (1 << 2)
Ben Skeggse41115d2010-11-01 11:45:02 +1000149
150#define NVOBJ_CINST_GLOBAL 0xdeadbeef
151
Ben Skeggs6ee73862009-12-11 19:24:15 +1000152struct nouveau_gpuobj {
Ben Skeggsb3beb162010-09-01 15:24:29 +1000153 struct drm_device *dev;
Ben Skeggseb9bcbd2010-09-01 15:24:37 +1000154 struct kref refcount;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000155 struct list_head list;
156
Ben Skeggse41115d2010-11-01 11:45:02 +1000157 void *node;
Ben Skeggsdc1e5c02010-10-25 15:23:59 +1000158 u32 *suspend;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000159
160 uint32_t flags;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000161
Ben Skeggs43efc9c2010-09-01 15:24:32 +1000162 u32 size;
Ben Skeggsde3a6c02010-09-01 15:24:30 +1000163 u32 pinst;
164 u32 cinst;
165 u64 vinst;
166
Ben Skeggs6ee73862009-12-11 19:24:15 +1000167 uint32_t engine;
168 uint32_t class;
169
170 void (*dtor)(struct drm_device *, struct nouveau_gpuobj *);
171 void *priv;
172};
173
Francisco Jerez332b2422010-10-20 23:35:40 +0200174struct nouveau_page_flip_state {
175 struct list_head head;
176 struct drm_pending_vblank_event *event;
177 int crtc, bpp, pitch, x, y;
178 uint64_t offset;
179};
180
Francisco Jereze419cf02010-10-25 23:38:59 +0200181enum nouveau_channel_mutex_class {
182 NOUVEAU_UCHANNEL_MUTEX,
183 NOUVEAU_KCHANNEL_MUTEX
184};
185
Ben Skeggs6ee73862009-12-11 19:24:15 +1000186struct nouveau_channel {
187 struct drm_device *dev;
188 int id;
189
Francisco Jerezf091a3d2010-10-18 03:55:48 +0200190 /* references to the channel data structure */
191 struct kref ref;
192 /* users of the hardware channel resources, the hardware
193 * context will be kicked off when it reaches zero. */
194 atomic_t users;
Ben Skeggs6a6b73f2010-10-05 16:53:48 +1000195 struct mutex mutex;
196
Ben Skeggs6ee73862009-12-11 19:24:15 +1000197 /* owner of this fifo */
198 struct drm_file *file_priv;
199 /* mapping of the fifo itself */
200 struct drm_local_map *map;
201
202 /* mapping of the regs controling the fifo */
203 void __iomem *user;
204 uint32_t user_get;
205 uint32_t user_put;
206
207 /* Fencing */
208 struct {
209 /* lock protects the pending list only */
210 spinlock_t lock;
211 struct list_head pending;
212 uint32_t sequence;
213 uint32_t sequence_ack;
Ben Skeggs047d1d32010-05-31 12:00:43 +1000214 atomic_t last_sequence_irq;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000215 } fence;
216
217 /* DMA push buffer */
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000218 struct nouveau_gpuobj *pushbuf;
219 struct nouveau_bo *pushbuf_bo;
220 uint32_t pushbuf_base;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000221
222 /* Notifier memory */
223 struct nouveau_bo *notifier_bo;
Ben Skeggsb833ac22010-06-01 15:32:24 +1000224 struct drm_mm notifier_heap;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000225
226 /* PFIFO context */
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000227 struct nouveau_gpuobj *ramfc;
228 struct nouveau_gpuobj *cache;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000229
230 /* PGRAPH context */
231 /* XXX may be merge 2 pointers as private data ??? */
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000232 struct nouveau_gpuobj *ramin_grctx;
Ben Skeggsbd2e5972010-10-19 20:06:01 +1000233 struct nouveau_gpuobj *crypt_ctx;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000234 void *pgraph_ctx;
235
236 /* NV50 VM */
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000237 struct nouveau_gpuobj *vm_pd;
238 struct nouveau_gpuobj *vm_gart_pt;
239 struct nouveau_gpuobj *vm_vram_pt[NV50_VM_VRAM_NR];
Ben Skeggs6ee73862009-12-11 19:24:15 +1000240
241 /* Objects */
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000242 struct nouveau_gpuobj *ramin; /* Private instmem */
243 struct drm_mm ramin_heap; /* Private PRAMIN heap */
244 struct nouveau_ramht *ramht; /* Hash table */
Ben Skeggs6ee73862009-12-11 19:24:15 +1000245
246 /* GPU object info for stuff used in-kernel (mm_enabled) */
247 uint32_t m2mf_ntfy;
248 uint32_t vram_handle;
249 uint32_t gart_handle;
250 bool accel_done;
251
252 /* Push buffer state (only for drm's channel on !mm_enabled) */
253 struct {
254 int max;
255 int free;
256 int cur;
257 int put;
258 /* access via pushbuf_bo */
Ben Skeggs9a391ad2010-02-11 16:37:26 +1000259
260 int ib_base;
261 int ib_max;
262 int ib_free;
263 int ib_put;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000264 } dma;
265
266 uint32_t sw_subchannel[8];
267
268 struct {
269 struct nouveau_gpuobj *vblsem;
Francisco Jerez1f6d2de2010-10-24 14:15:58 +0200270 uint32_t vblsem_head;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000271 uint32_t vblsem_offset;
272 uint32_t vblsem_rval;
273 struct list_head vbl_wait;
Francisco Jerez332b2422010-10-20 23:35:40 +0200274 struct list_head flip;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000275 } nvsw;
276
277 struct {
278 bool active;
279 char name[32];
280 struct drm_info_list info;
281 } debugfs;
282};
283
284struct nouveau_instmem_engine {
285 void *priv;
286
287 int (*init)(struct drm_device *dev);
288 void (*takedown)(struct drm_device *dev);
289 int (*suspend)(struct drm_device *dev);
290 void (*resume)(struct drm_device *dev);
291
Ben Skeggse41115d2010-11-01 11:45:02 +1000292 int (*get)(struct nouveau_gpuobj *, u32 size, u32 align);
293 void (*put)(struct nouveau_gpuobj *);
294 int (*map)(struct nouveau_gpuobj *);
295 void (*unmap)(struct nouveau_gpuobj *);
296
Ben Skeggsf56cb862010-07-08 11:29:10 +1000297 void (*flush)(struct drm_device *);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000298};
299
300struct nouveau_mc_engine {
301 int (*init)(struct drm_device *dev);
302 void (*takedown)(struct drm_device *dev);
303};
304
305struct nouveau_timer_engine {
306 int (*init)(struct drm_device *dev);
307 void (*takedown)(struct drm_device *dev);
308 uint64_t (*read)(struct drm_device *dev);
309};
310
311struct nouveau_fb_engine {
Francisco Jerezcb00f7c2009-12-16 12:12:27 +0100312 int num_tiles;
Francisco Jerez87a326a2010-10-24 16:36:12 +0200313 struct drm_mm tag_heap;
Ben Skeggs20f63af2010-11-15 12:50:50 +1000314 void *priv;
Francisco Jerezcb00f7c2009-12-16 12:12:27 +0100315
Ben Skeggs6ee73862009-12-11 19:24:15 +1000316 int (*init)(struct drm_device *dev);
317 void (*takedown)(struct drm_device *dev);
Francisco Jerezcb00f7c2009-12-16 12:12:27 +0100318
Francisco Jereza5cf68b2010-10-24 16:14:41 +0200319 void (*init_tile_region)(struct drm_device *dev, int i,
320 uint32_t addr, uint32_t size,
321 uint32_t pitch, uint32_t flags);
322 void (*set_tile_region)(struct drm_device *dev, int i);
323 void (*free_tile_region)(struct drm_device *dev, int i);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000324};
325
326struct nouveau_fifo_engine {
Ben Skeggs6ee73862009-12-11 19:24:15 +1000327 int channels;
328
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000329 struct nouveau_gpuobj *playlist[2];
Ben Skeggsac94a342010-07-08 15:28:48 +1000330 int cur_playlist;
331
Ben Skeggs6ee73862009-12-11 19:24:15 +1000332 int (*init)(struct drm_device *);
333 void (*takedown)(struct drm_device *);
334
335 void (*disable)(struct drm_device *);
336 void (*enable)(struct drm_device *);
337 bool (*reassign)(struct drm_device *, bool enable);
Francisco Jerez588d7d12009-12-13 20:07:42 +0100338 bool (*cache_pull)(struct drm_device *dev, bool enable);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000339
340 int (*channel_id)(struct drm_device *);
341
342 int (*create_context)(struct nouveau_channel *);
343 void (*destroy_context)(struct nouveau_channel *);
344 int (*load_context)(struct nouveau_channel *);
345 int (*unload_context)(struct drm_device *);
Ben Skeggs56ac7472010-10-22 10:26:24 +1000346 void (*tlb_flush)(struct drm_device *dev);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000347};
348
Ben Skeggs6ee73862009-12-11 19:24:15 +1000349struct nouveau_pgraph_engine {
Ben Skeggs6ee73862009-12-11 19:24:15 +1000350 bool accel_blocked;
Ben Skeggsb8c157d2010-10-20 10:39:35 +1000351 bool registered;
Ben Skeggs054b93e2009-12-15 22:02:47 +1000352 int grctx_size;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000353
Ben Skeggsc50a5682010-07-08 15:40:18 +1000354 /* NV2x/NV3x context table (0x400780) */
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000355 struct nouveau_gpuobj *ctx_table;
Ben Skeggsc50a5682010-07-08 15:40:18 +1000356
Ben Skeggs6ee73862009-12-11 19:24:15 +1000357 int (*init)(struct drm_device *);
358 void (*takedown)(struct drm_device *);
359
360 void (*fifo_access)(struct drm_device *, bool);
361
362 struct nouveau_channel *(*channel)(struct drm_device *);
363 int (*create_context)(struct nouveau_channel *);
364 void (*destroy_context)(struct nouveau_channel *);
365 int (*load_context)(struct nouveau_channel *);
366 int (*unload_context)(struct drm_device *);
Ben Skeggs56ac7472010-10-22 10:26:24 +1000367 void (*tlb_flush)(struct drm_device *dev);
Francisco Jerezcb00f7c2009-12-16 12:12:27 +0100368
Francisco Jereza5cf68b2010-10-24 16:14:41 +0200369 void (*set_tile_region)(struct drm_device *dev, int i);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000370};
371
Francisco Jerezc88c2e02010-07-24 17:37:33 +0200372struct nouveau_display_engine {
373 int (*early_init)(struct drm_device *);
374 void (*late_takedown)(struct drm_device *);
375 int (*create)(struct drm_device *);
376 int (*init)(struct drm_device *);
377 void (*destroy)(struct drm_device *);
378};
379
Ben Skeggsee2e0132010-07-26 09:28:25 +1000380struct nouveau_gpio_engine {
Ben Skeggsfce2bad2010-11-11 16:14:56 +1000381 void *priv;
382
Ben Skeggsee2e0132010-07-26 09:28:25 +1000383 int (*init)(struct drm_device *);
384 void (*takedown)(struct drm_device *);
385
386 int (*get)(struct drm_device *, enum dcb_gpio_tag);
387 int (*set)(struct drm_device *, enum dcb_gpio_tag, int state);
388
Ben Skeggsfce2bad2010-11-11 16:14:56 +1000389 int (*irq_register)(struct drm_device *, enum dcb_gpio_tag,
390 void (*)(void *, int), void *);
391 void (*irq_unregister)(struct drm_device *, enum dcb_gpio_tag,
392 void (*)(void *, int), void *);
393 bool (*irq_enable)(struct drm_device *, enum dcb_gpio_tag, bool on);
Ben Skeggsee2e0132010-07-26 09:28:25 +1000394};
395
Ben Skeggs330c5982010-09-16 15:39:49 +1000396struct nouveau_pm_voltage_level {
397 u8 voltage;
398 u8 vid;
399};
400
401struct nouveau_pm_voltage {
402 bool supported;
403 u8 vid_mask;
404
405 struct nouveau_pm_voltage_level *level;
406 int nr_level;
407};
408
409#define NOUVEAU_PM_MAX_LEVEL 8
410struct nouveau_pm_level {
411 struct device_attribute dev_attr;
412 char name[32];
413 int id;
414
415 u32 core;
416 u32 memory;
417 u32 shader;
418 u32 unk05;
419
420 u8 voltage;
421 u8 fanspeed;
Ben Skeggsaee582d2010-09-27 10:13:23 +1000422
423 u16 memscript;
Ben Skeggs330c5982010-09-16 15:39:49 +1000424};
425
Martin Peres34e9d852010-09-22 20:54:22 +0200426struct nouveau_pm_temp_sensor_constants {
427 u16 offset_constant;
428 s16 offset_mult;
429 u16 offset_div;
430 u16 slope_mult;
431 u16 slope_div;
432};
433
434struct nouveau_pm_threshold_temp {
435 s16 critical;
436 s16 down_clock;
437 s16 fan_boost;
438};
439
Roy Spliet7760fcb2010-09-17 23:17:24 +0200440struct nouveau_pm_memtiming {
441 u32 reg_100220;
442 u32 reg_100224;
443 u32 reg_100228;
444 u32 reg_10022c;
445 u32 reg_100230;
446 u32 reg_100234;
447 u32 reg_100238;
448 u32 reg_10023c;
449};
450
451struct nouveau_pm_memtimings {
452 bool supported;
453 struct nouveau_pm_memtiming *timing;
454 int nr_timing;
455};
456
Ben Skeggs330c5982010-09-16 15:39:49 +1000457struct nouveau_pm_engine {
458 struct nouveau_pm_voltage voltage;
459 struct nouveau_pm_level perflvl[NOUVEAU_PM_MAX_LEVEL];
460 int nr_perflvl;
Roy Spliet7760fcb2010-09-17 23:17:24 +0200461 struct nouveau_pm_memtimings memtimings;
Martin Peres34e9d852010-09-22 20:54:22 +0200462 struct nouveau_pm_temp_sensor_constants sensor_constants;
463 struct nouveau_pm_threshold_temp threshold_temp;
Ben Skeggs330c5982010-09-16 15:39:49 +1000464
465 struct nouveau_pm_level boot;
466 struct nouveau_pm_level *cur;
467
Francisco Jerez8155cac2010-09-23 20:58:38 +0200468 struct device *hwmon;
Ben Skeggs60326492010-10-12 12:31:32 +1000469 struct notifier_block acpi_nb;
Francisco Jerez8155cac2010-09-23 20:58:38 +0200470
Ben Skeggs330c5982010-09-16 15:39:49 +1000471 int (*clock_get)(struct drm_device *, u32 id);
Ben Skeggs5c6dc652010-09-27 09:47:56 +1000472 void *(*clock_pre)(struct drm_device *, struct nouveau_pm_level *,
473 u32 id, int khz);
Ben Skeggs330c5982010-09-16 15:39:49 +1000474 void (*clock_set)(struct drm_device *, void *);
475 int (*voltage_get)(struct drm_device *);
476 int (*voltage_set)(struct drm_device *, int voltage);
477 int (*fanspeed_get)(struct drm_device *);
478 int (*fanspeed_set)(struct drm_device *, int fanspeed);
Francisco Jerez8155cac2010-09-23 20:58:38 +0200479 int (*temp_get)(struct drm_device *);
Ben Skeggs330c5982010-09-16 15:39:49 +1000480};
481
Ben Skeggsbd2e5972010-10-19 20:06:01 +1000482struct nouveau_crypt_engine {
483 bool registered;
484
485 int (*init)(struct drm_device *);
486 void (*takedown)(struct drm_device *);
487 int (*create_context)(struct nouveau_channel *);
488 void (*destroy_context)(struct nouveau_channel *);
489 void (*tlb_flush)(struct drm_device *dev);
490};
491
Ben Skeggs6ee73862009-12-11 19:24:15 +1000492struct nouveau_engine {
493 struct nouveau_instmem_engine instmem;
494 struct nouveau_mc_engine mc;
495 struct nouveau_timer_engine timer;
496 struct nouveau_fb_engine fb;
497 struct nouveau_pgraph_engine graph;
498 struct nouveau_fifo_engine fifo;
Francisco Jerezc88c2e02010-07-24 17:37:33 +0200499 struct nouveau_display_engine display;
Ben Skeggsee2e0132010-07-26 09:28:25 +1000500 struct nouveau_gpio_engine gpio;
Ben Skeggs330c5982010-09-16 15:39:49 +1000501 struct nouveau_pm_engine pm;
Ben Skeggsbd2e5972010-10-19 20:06:01 +1000502 struct nouveau_crypt_engine crypt;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000503};
504
505struct nouveau_pll_vals {
506 union {
507 struct {
508#ifdef __BIG_ENDIAN
509 uint8_t N1, M1, N2, M2;
510#else
511 uint8_t M1, N1, M2, N2;
512#endif
513 };
514 struct {
515 uint16_t NM1, NM2;
516 } __attribute__((packed));
517 };
518 int log2P;
519
520 int refclk;
521};
522
523enum nv04_fp_display_regs {
524 FP_DISPLAY_END,
525 FP_TOTAL,
526 FP_CRTC,
527 FP_SYNC_START,
528 FP_SYNC_END,
529 FP_VALID_START,
530 FP_VALID_END
531};
532
533struct nv04_crtc_reg {
Francisco Jerezcbab95d2010-10-11 03:43:58 +0200534 unsigned char MiscOutReg;
Francisco Jerez4a9f8222010-07-20 16:48:08 +0200535 uint8_t CRTC[0xa0];
Ben Skeggs6ee73862009-12-11 19:24:15 +1000536 uint8_t CR58[0x10];
537 uint8_t Sequencer[5];
538 uint8_t Graphics[9];
539 uint8_t Attribute[21];
Francisco Jerezcbab95d2010-10-11 03:43:58 +0200540 unsigned char DAC[768];
Ben Skeggs6ee73862009-12-11 19:24:15 +1000541
542 /* PCRTC regs */
543 uint32_t fb_start;
544 uint32_t crtc_cfg;
545 uint32_t cursor_cfg;
546 uint32_t gpio_ext;
547 uint32_t crtc_830;
548 uint32_t crtc_834;
549 uint32_t crtc_850;
550 uint32_t crtc_eng_ctrl;
551
552 /* PRAMDAC regs */
553 uint32_t nv10_cursync;
554 struct nouveau_pll_vals pllvals;
555 uint32_t ramdac_gen_ctrl;
556 uint32_t ramdac_630;
557 uint32_t ramdac_634;
558 uint32_t tv_setup;
559 uint32_t tv_vtotal;
560 uint32_t tv_vskew;
561 uint32_t tv_vsync_delay;
562 uint32_t tv_htotal;
563 uint32_t tv_hskew;
564 uint32_t tv_hsync_delay;
565 uint32_t tv_hsync_delay2;
566 uint32_t fp_horiz_regs[7];
567 uint32_t fp_vert_regs[7];
568 uint32_t dither;
569 uint32_t fp_control;
570 uint32_t dither_regs[6];
571 uint32_t fp_debug_0;
572 uint32_t fp_debug_1;
573 uint32_t fp_debug_2;
574 uint32_t fp_margin_color;
575 uint32_t ramdac_8c0;
576 uint32_t ramdac_a20;
577 uint32_t ramdac_a24;
578 uint32_t ramdac_a34;
579 uint32_t ctv_regs[38];
580};
581
582struct nv04_output_reg {
583 uint32_t output;
584 int head;
585};
586
587struct nv04_mode_state {
Francisco Jerezcbab95d2010-10-11 03:43:58 +0200588 struct nv04_crtc_reg crtc_reg[2];
Ben Skeggs6ee73862009-12-11 19:24:15 +1000589 uint32_t pllsel;
590 uint32_t sel_clk;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000591};
592
593enum nouveau_card_type {
594 NV_04 = 0x00,
595 NV_10 = 0x10,
596 NV_20 = 0x20,
597 NV_30 = 0x30,
598 NV_40 = 0x40,
599 NV_50 = 0x50,
Ben Skeggs4b223ee2010-08-03 10:00:56 +1000600 NV_C0 = 0xc0,
Ben Skeggs6ee73862009-12-11 19:24:15 +1000601};
602
603struct drm_nouveau_private {
604 struct drm_device *dev;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000605
606 /* the card type, takes NV_* as values */
607 enum nouveau_card_type card_type;
608 /* exact chipset, derived from NV_PMC_BOOT_0 */
609 int chipset;
610 int flags;
611
612 void __iomem *mmio;
Ben Skeggs5125bfd2010-09-01 15:24:33 +1000613
Ben Skeggse05d7ea2010-09-01 15:24:38 +1000614 spinlock_t ramin_lock;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000615 void __iomem *ramin;
Ben Skeggs5125bfd2010-09-01 15:24:33 +1000616 u32 ramin_size;
617 u32 ramin_base;
618 bool ramin_available;
Ben Skeggse05d7ea2010-09-01 15:24:38 +1000619 struct drm_mm ramin_heap;
620 struct list_head gpuobj_list;
Ben Skeggsb8c157d2010-10-20 10:39:35 +1000621 struct list_head classes;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000622
Ben Skeggsac8fb972010-01-15 09:24:20 +1000623 struct nouveau_bo *vga_ram;
624
Ben Skeggs35fa2f22010-10-21 14:07:03 +1000625 /* interrupt handling */
Ben Skeggs8f8a5442010-11-03 09:57:28 +1000626 void (*irq_handler[32])(struct drm_device *);
Ben Skeggs35fa2f22010-10-21 14:07:03 +1000627 bool msi_enabled;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000628 struct workqueue_struct *wq;
629 struct work_struct irq_work;
Andy Lutomirskiab838332010-11-16 18:40:52 -0500630
Ben Skeggs6ee73862009-12-11 19:24:15 +1000631 struct list_head vbl_waiting;
632
633 struct {
Dave Airlieba4420c2010-03-09 10:56:52 +1000634 struct drm_global_reference mem_global_ref;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000635 struct ttm_bo_global_ref bo_global_ref;
636 struct ttm_bo_device bdev;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000637 atomic_t validate_sequence;
638 } ttm;
639
Francisco Jerez0c6c1c22010-09-22 00:58:54 +0200640 struct {
641 spinlock_t lock;
642 struct drm_mm heap;
643 struct nouveau_bo *bo;
644 } fence;
645
Ben Skeggscff5c132010-10-06 16:16:59 +1000646 struct {
647 spinlock_t lock;
648 struct nouveau_channel *ptr[NOUVEAU_MAX_CHANNEL_NR];
649 } channels;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000650
651 struct nouveau_engine engine;
652 struct nouveau_channel *channel;
653
Maarten Maathuisff9e5272010-02-01 20:58:27 +0100654 /* For PFIFO and PGRAPH. */
655 spinlock_t context_switch_lock;
656
Ben Skeggs6ee73862009-12-11 19:24:15 +1000657 /* RAMIN configuration, RAMFC, RAMHT and RAMRO offsets */
Ben Skeggse05c5a32010-09-01 15:24:35 +1000658 struct nouveau_ramht *ramht;
659 struct nouveau_gpuobj *ramfc;
660 struct nouveau_gpuobj *ramro;
661
Ben Skeggs6ee73862009-12-11 19:24:15 +1000662 uint32_t ramin_rsvd_vram;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000663
Ben Skeggs6ee73862009-12-11 19:24:15 +1000664 struct {
665 enum {
666 NOUVEAU_GART_NONE = 0,
667 NOUVEAU_GART_AGP,
668 NOUVEAU_GART_SGDMA
669 } type;
670 uint64_t aper_base;
671 uint64_t aper_size;
672 uint64_t aper_free;
673
674 struct nouveau_gpuobj *sg_ctxdma;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000675 } gart_info;
676
Francisco Jereza0af9ad2009-12-11 16:51:09 +0100677 /* nv10-nv40 tiling regions */
Francisco Jereza5cf68b2010-10-24 16:14:41 +0200678 struct {
679 struct nouveau_tile_reg reg[NOUVEAU_MAX_TILE_NR];
680 spinlock_t lock;
681 } tile;
Francisco Jereza0af9ad2009-12-11 16:51:09 +0100682
Ben Skeggsa76fb4e2010-03-18 09:45:20 +1000683 /* VRAM/fb configuration */
684 uint64_t vram_size;
685 uint64_t vram_sys_base;
Ben Skeggs6c3d7ef2010-08-12 12:37:28 +1000686 u32 vram_rblock_size;
Ben Skeggsa76fb4e2010-03-18 09:45:20 +1000687
688 uint64_t fb_phys;
689 uint64_t fb_available_size;
690 uint64_t fb_mappable_pages;
691 uint64_t fb_aper_free;
692 int fb_mtrr;
693
Ben Skeggs6ee73862009-12-11 19:24:15 +1000694 /* G8x/G9x virtual address space */
695 uint64_t vm_gart_base;
696 uint64_t vm_gart_size;
697 uint64_t vm_vram_base;
698 uint64_t vm_vram_size;
699 uint64_t vm_end;
700 struct nouveau_gpuobj *vm_vram_pt[NV50_VM_VRAM_NR];
701 int vm_vram_pt_nr;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000702
Ben Skeggs04a39c52010-02-24 10:03:05 +1000703 struct nvbios vbios;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000704
705 struct nv04_mode_state mode_reg;
706 struct nv04_mode_state saved_reg;
707 uint32_t saved_vga_font[4][16384];
708 uint32_t crtc_owner;
709 uint32_t dac_users[4];
710
711 struct nouveau_suspend_resume {
Ben Skeggs6ee73862009-12-11 19:24:15 +1000712 uint32_t *ramin_copy;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000713 } susres;
714
715 struct backlight_device *backlight;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000716
717 struct nouveau_channel *evo;
Ben Skeggs1e962682010-10-19 14:18:06 +1000718 u32 evo_alloc;
Ben Skeggs87c0e0e2010-07-06 08:54:34 +1000719 struct {
720 struct dcb_entry *dcb;
721 u16 script;
722 u32 pclk;
723 } evo_irq;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000724
725 struct {
726 struct dentry *channel_root;
727 } debugfs;
Dave Airlie38651672010-03-30 05:34:13 +0000728
Dave Airlie8be48d92010-03-30 05:34:14 +0000729 struct nouveau_fbdev *nfbdev;
Marcin Slusarz06415c52010-05-16 17:29:56 +0200730 struct apertures_struct *apertures;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000731};
732
733static inline struct drm_nouveau_private *
Francisco Jerez27307232010-09-21 18:57:11 +0200734nouveau_private(struct drm_device *dev)
735{
736 return dev->dev_private;
737}
738
739static inline struct drm_nouveau_private *
Ben Skeggs6ee73862009-12-11 19:24:15 +1000740nouveau_bdev(struct ttm_bo_device *bd)
741{
742 return container_of(bd, struct drm_nouveau_private, ttm.bdev);
743}
744
745static inline int
746nouveau_bo_ref(struct nouveau_bo *ref, struct nouveau_bo **pnvbo)
747{
748 struct nouveau_bo *prev;
749
750 if (!pnvbo)
751 return -EINVAL;
752 prev = *pnvbo;
753
754 *pnvbo = ref ? nouveau_bo(ttm_bo_reference(&ref->bo)) : NULL;
755 if (prev) {
756 struct ttm_buffer_object *bo = &prev->bo;
757
758 ttm_bo_unref(&bo);
759 }
760
761 return 0;
762}
763
Ben Skeggs6ee73862009-12-11 19:24:15 +1000764/* nouveau_drv.c */
Francisco Jerezde5899b2010-09-08 02:28:23 +0200765extern int nouveau_agpmode;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000766extern int nouveau_duallink;
767extern int nouveau_uscript_lvds;
768extern int nouveau_uscript_tmds;
769extern int nouveau_vram_pushbuf;
770extern int nouveau_vram_notify;
771extern int nouveau_fbpercrtc;
Ben Skeggsf4053502010-03-15 09:43:51 +1000772extern int nouveau_tv_disable;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000773extern char *nouveau_tv_norm;
774extern int nouveau_reg_debug;
775extern char *nouveau_vbios;
Ben Skeggsa1470892010-01-18 11:42:37 +1000776extern int nouveau_ignorelid;
Marcin Kościelnickia32ed692010-01-26 14:00:42 +0000777extern int nouveau_nofbaccel;
778extern int nouveau_noaccel;
Marcin Kościelnicki0cba1b72010-09-29 11:15:01 +0000779extern int nouveau_force_post;
Ben Skeggsda647d52010-03-04 12:00:39 +1000780extern int nouveau_override_conntype;
Ben Skeggs6f876982010-09-16 16:47:14 +1000781extern char *nouveau_perflvl;
782extern int nouveau_perflvl_wr;
Ben Skeggs35fa2f22010-10-21 14:07:03 +1000783extern int nouveau_msi;
Ben Skeggs6ee73862009-12-11 19:24:15 +1000784
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000785extern int nouveau_pci_suspend(struct pci_dev *pdev, pm_message_t pm_state);
786extern int nouveau_pci_resume(struct pci_dev *pdev);
787
Ben Skeggs6ee73862009-12-11 19:24:15 +1000788/* nouveau_state.c */
789extern void nouveau_preclose(struct drm_device *dev, struct drm_file *);
790extern int nouveau_load(struct drm_device *, unsigned long flags);
791extern int nouveau_firstopen(struct drm_device *);
792extern void nouveau_lastclose(struct drm_device *);
793extern int nouveau_unload(struct drm_device *);
794extern int nouveau_ioctl_getparam(struct drm_device *, void *data,
795 struct drm_file *);
796extern int nouveau_ioctl_setparam(struct drm_device *, void *data,
797 struct drm_file *);
Ben Skeggs12fb9522010-11-19 14:32:56 +1000798extern bool nouveau_wait_eq(struct drm_device *, uint64_t timeout,
799 uint32_t reg, uint32_t mask, uint32_t val);
800extern bool nouveau_wait_ne(struct drm_device *, uint64_t timeout,
801 uint32_t reg, uint32_t mask, uint32_t val);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000802extern bool nouveau_wait_for_idle(struct drm_device *);
803extern int nouveau_card_init(struct drm_device *);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000804
805/* nouveau_mem.c */
Ben Skeggsfbd28952010-09-01 15:24:34 +1000806extern int nouveau_mem_vram_init(struct drm_device *);
807extern void nouveau_mem_vram_fini(struct drm_device *);
808extern int nouveau_mem_gart_init(struct drm_device *);
809extern void nouveau_mem_gart_fini(struct drm_device *);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000810extern int nouveau_mem_init_agp(struct drm_device *);
Francisco Jereze04d8e82010-07-23 20:29:13 +0200811extern int nouveau_mem_reset_agp(struct drm_device *);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000812extern void nouveau_mem_close(struct drm_device *);
Francisco Jereza5cf68b2010-10-24 16:14:41 +0200813extern struct nouveau_tile_reg *nv10_mem_set_tiling(
814 struct drm_device *dev, uint32_t addr, uint32_t size,
815 uint32_t pitch, uint32_t flags);
816extern void nv10_mem_put_tile_region(struct drm_device *dev,
817 struct nouveau_tile_reg *tile,
818 struct nouveau_fence *fence);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000819extern int nv50_mem_vm_bind_linear(struct drm_device *, uint64_t virt,
820 uint32_t size, uint32_t flags,
821 uint64_t phys);
822extern void nv50_mem_vm_unbind(struct drm_device *, uint64_t virt,
823 uint32_t size);
824
825/* nouveau_notifier.c */
826extern int nouveau_notifier_init_channel(struct nouveau_channel *);
827extern void nouveau_notifier_takedown_channel(struct nouveau_channel *);
828extern int nouveau_notifier_alloc(struct nouveau_channel *, uint32_t handle,
829 int cout, uint32_t *offset);
830extern int nouveau_notifier_offset(struct nouveau_gpuobj *, uint32_t *);
831extern int nouveau_ioctl_notifier_alloc(struct drm_device *, void *data,
832 struct drm_file *);
833extern int nouveau_ioctl_notifier_free(struct drm_device *, void *data,
834 struct drm_file *);
835
836/* nouveau_channel.c */
837extern struct drm_ioctl_desc nouveau_ioctls[];
838extern int nouveau_max_ioctl;
839extern void nouveau_channel_cleanup(struct drm_device *, struct drm_file *);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000840extern int nouveau_channel_alloc(struct drm_device *dev,
841 struct nouveau_channel **chan,
842 struct drm_file *file_priv,
843 uint32_t fb_ctxdma, uint32_t tt_ctxdma);
Ben Skeggscff5c132010-10-06 16:16:59 +1000844extern struct nouveau_channel *
Francisco Jerezfeeb0ae2010-10-18 02:58:04 +0200845nouveau_channel_get_unlocked(struct nouveau_channel *);
846extern struct nouveau_channel *
Ben Skeggscff5c132010-10-06 16:16:59 +1000847nouveau_channel_get(struct drm_device *, struct drm_file *, int id);
Francisco Jerezfeeb0ae2010-10-18 02:58:04 +0200848extern void nouveau_channel_put_unlocked(struct nouveau_channel **);
Ben Skeggscff5c132010-10-06 16:16:59 +1000849extern void nouveau_channel_put(struct nouveau_channel **);
Francisco Jerezf091a3d2010-10-18 03:55:48 +0200850extern void nouveau_channel_ref(struct nouveau_channel *chan,
851 struct nouveau_channel **pchan);
Francisco Jerez6dccd312010-11-18 23:57:46 +0100852extern void nouveau_channel_idle(struct nouveau_channel *chan);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000853
854/* nouveau_object.c */
Ben Skeggsb8c157d2010-10-20 10:39:35 +1000855#define NVOBJ_CLASS(d,c,e) do { \
856 int ret = nouveau_gpuobj_class_new((d), (c), NVOBJ_ENGINE_##e); \
857 if (ret) \
858 return ret; \
859} while(0)
860
861#define NVOBJ_MTHD(d,c,m,e) do { \
862 int ret = nouveau_gpuobj_mthd_new((d), (c), (m), (e)); \
863 if (ret) \
864 return ret; \
865} while(0)
866
Ben Skeggs6ee73862009-12-11 19:24:15 +1000867extern int nouveau_gpuobj_early_init(struct drm_device *);
868extern int nouveau_gpuobj_init(struct drm_device *);
869extern void nouveau_gpuobj_takedown(struct drm_device *);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000870extern int nouveau_gpuobj_suspend(struct drm_device *dev);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000871extern void nouveau_gpuobj_resume(struct drm_device *dev);
Ben Skeggsb8c157d2010-10-20 10:39:35 +1000872extern int nouveau_gpuobj_class_new(struct drm_device *, u32 class, u32 eng);
873extern int nouveau_gpuobj_mthd_new(struct drm_device *, u32 class, u32 mthd,
874 int (*exec)(struct nouveau_channel *,
875 u32 class, u32 mthd, u32 data));
876extern int nouveau_gpuobj_mthd_call(struct nouveau_channel *, u32, u32, u32);
Ben Skeggs274fec92010-11-03 13:16:18 +1000877extern int nouveau_gpuobj_mthd_call2(struct drm_device *, int, u32, u32, u32);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000878extern int nouveau_gpuobj_channel_init(struct nouveau_channel *,
879 uint32_t vram_h, uint32_t tt_h);
880extern void nouveau_gpuobj_channel_takedown(struct nouveau_channel *);
881extern int nouveau_gpuobj_new(struct drm_device *, struct nouveau_channel *,
882 uint32_t size, int align, uint32_t flags,
883 struct nouveau_gpuobj **);
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000884extern void nouveau_gpuobj_ref(struct nouveau_gpuobj *,
885 struct nouveau_gpuobj **);
Ben Skeggs43efc9c2010-09-01 15:24:32 +1000886extern int nouveau_gpuobj_new_fake(struct drm_device *, u32 pinst, u64 vinst,
887 u32 size, u32 flags,
Ben Skeggsa8eaebc2010-09-01 15:24:31 +1000888 struct nouveau_gpuobj **);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000889extern int nouveau_gpuobj_dma_new(struct nouveau_channel *, int class,
890 uint64_t offset, uint64_t size, int access,
891 int target, struct nouveau_gpuobj **);
Ben Skeggsceac3092010-11-23 10:10:24 +1000892extern int nouveau_gpuobj_gr_new(struct nouveau_channel *, u32 handle, int class);
Ben Skeggs7f4a1952010-11-16 11:50:09 +1000893extern int nv50_gpuobj_dma_new(struct nouveau_channel *, int class, u64 base,
894 u64 size, int target, int access, u32 type,
895 u32 comp, struct nouveau_gpuobj **pobj);
896extern void nv50_gpuobj_dma_init(struct nouveau_gpuobj *, u32 offset,
897 int class, u64 base, u64 size, int target,
898 int access, u32 type, u32 comp);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000899extern int nouveau_ioctl_grobj_alloc(struct drm_device *, void *data,
900 struct drm_file *);
901extern int nouveau_ioctl_gpuobj_free(struct drm_device *, void *data,
902 struct drm_file *);
903
904/* nouveau_irq.c */
Ben Skeggs35fa2f22010-10-21 14:07:03 +1000905extern int nouveau_irq_init(struct drm_device *);
906extern void nouveau_irq_fini(struct drm_device *);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000907extern irqreturn_t nouveau_irq_handler(DRM_IRQ_ARGS);
Ben Skeggs8f8a5442010-11-03 09:57:28 +1000908extern void nouveau_irq_register(struct drm_device *, int status_bit,
909 void (*)(struct drm_device *));
910extern void nouveau_irq_unregister(struct drm_device *, int status_bit);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000911extern void nouveau_irq_preinstall(struct drm_device *);
912extern int nouveau_irq_postinstall(struct drm_device *);
913extern void nouveau_irq_uninstall(struct drm_device *);
914
915/* nouveau_sgdma.c */
916extern int nouveau_sgdma_init(struct drm_device *);
917extern void nouveau_sgdma_takedown(struct drm_device *);
918extern int nouveau_sgdma_get_page(struct drm_device *, uint32_t offset,
919 uint32_t *page);
920extern struct ttm_backend *nouveau_sgdma_init_ttm(struct drm_device *);
921
922/* nouveau_debugfs.c */
923#if defined(CONFIG_DRM_NOUVEAU_DEBUG)
924extern int nouveau_debugfs_init(struct drm_minor *);
925extern void nouveau_debugfs_takedown(struct drm_minor *);
926extern int nouveau_debugfs_channel_init(struct nouveau_channel *);
927extern void nouveau_debugfs_channel_fini(struct nouveau_channel *);
928#else
929static inline int
930nouveau_debugfs_init(struct drm_minor *minor)
931{
932 return 0;
933}
934
935static inline void nouveau_debugfs_takedown(struct drm_minor *minor)
936{
937}
938
939static inline int
940nouveau_debugfs_channel_init(struct nouveau_channel *chan)
941{
942 return 0;
943}
944
945static inline void
946nouveau_debugfs_channel_fini(struct nouveau_channel *chan)
947{
948}
949#endif
950
951/* nouveau_dma.c */
Ben Skeggs75c99da2010-01-08 10:57:39 +1000952extern void nouveau_dma_pre_init(struct nouveau_channel *);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000953extern int nouveau_dma_init(struct nouveau_channel *);
Ben Skeggs9a391ad2010-02-11 16:37:26 +1000954extern int nouveau_dma_wait(struct nouveau_channel *, int slots, int size);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000955
956/* nouveau_acpi.c */
Dave Airlieafeb3e12010-04-07 13:55:09 +1000957#define ROM_BIOS_PAGE 4096
Dave Airlie2f41a7f2010-03-03 09:20:25 +1000958#if defined(CONFIG_ACPI)
Dave Airlie6a9ee8a2010-02-01 15:38:10 +1000959void nouveau_register_dsm_handler(void);
960void nouveau_unregister_dsm_handler(void);
Dave Airlieafeb3e12010-04-07 13:55:09 +1000961int nouveau_acpi_get_bios_chunk(uint8_t *bios, int offset, int len);
962bool nouveau_acpi_rom_supported(struct pci_dev *pdev);
Ben Skeggsa6ed76d2010-07-12 15:33:07 +1000963int nouveau_acpi_edid(struct drm_device *, struct drm_connector *);
Dave Airlie8edb3812010-03-01 21:50:01 +1100964#else
965static inline void nouveau_register_dsm_handler(void) {}
966static inline void nouveau_unregister_dsm_handler(void) {}
Dave Airlieafeb3e12010-04-07 13:55:09 +1000967static inline bool nouveau_acpi_rom_supported(struct pci_dev *pdev) { return false; }
968static inline int nouveau_acpi_get_bios_chunk(uint8_t *bios, int offset, int len) { return -EINVAL; }
Ben Skeggs5620ba42010-07-23 10:00:12 +1000969static inline int nouveau_acpi_edid(struct drm_device *dev, struct drm_connector *connector) { return -EINVAL; }
Dave Airlie8edb3812010-03-01 21:50:01 +1100970#endif
Ben Skeggs6ee73862009-12-11 19:24:15 +1000971
972/* nouveau_backlight.c */
973#ifdef CONFIG_DRM_NOUVEAU_BACKLIGHT
974extern int nouveau_backlight_init(struct drm_device *);
975extern void nouveau_backlight_exit(struct drm_device *);
976#else
977static inline int nouveau_backlight_init(struct drm_device *dev)
978{
979 return 0;
980}
981
982static inline void nouveau_backlight_exit(struct drm_device *dev) { }
983#endif
984
985/* nouveau_bios.c */
986extern int nouveau_bios_init(struct drm_device *);
987extern void nouveau_bios_takedown(struct drm_device *dev);
988extern int nouveau_run_vbios_init(struct drm_device *);
989extern void nouveau_bios_run_init_table(struct drm_device *, uint16_t table,
990 struct dcb_entry *);
991extern struct dcb_gpio_entry *nouveau_bios_gpio_entry(struct drm_device *,
992 enum dcb_gpio_tag);
993extern struct dcb_connector_table_entry *
994nouveau_bios_connector_entry(struct drm_device *, int index);
Ben Skeggs855a95e2010-09-16 15:25:25 +1000995extern u32 get_pll_register(struct drm_device *, enum pll_types);
Ben Skeggs6ee73862009-12-11 19:24:15 +1000996extern int get_pll_limits(struct drm_device *, uint32_t limit_match,
997 struct pll_lims *);
998extern int nouveau_bios_run_display_table(struct drm_device *,
999 struct dcb_entry *,
1000 uint32_t script, int pxclk);
1001extern void *nouveau_bios_dp_table(struct drm_device *, struct dcb_entry *,
1002 int *length);
1003extern bool nouveau_bios_fp_mode(struct drm_device *, struct drm_display_mode *);
1004extern uint8_t *nouveau_bios_embedded_edid(struct drm_device *);
1005extern int nouveau_bios_parse_lvds_table(struct drm_device *, int pxclk,
1006 bool *dl, bool *if_is_24bit);
1007extern int run_tmds_table(struct drm_device *, struct dcb_entry *,
1008 int head, int pxclk);
1009extern int call_lvds_script(struct drm_device *, struct dcb_entry *, int head,
1010 enum LVDS_script, int pxclk);
1011
1012/* nouveau_ttm.c */
1013int nouveau_ttm_global_init(struct drm_nouveau_private *);
1014void nouveau_ttm_global_release(struct drm_nouveau_private *);
1015int nouveau_ttm_mmap(struct file *, struct vm_area_struct *);
1016
1017/* nouveau_dp.c */
1018int nouveau_dp_auxch(struct nouveau_i2c_chan *auxch, int cmd, int addr,
1019 uint8_t *data, int data_nr);
1020bool nouveau_dp_detect(struct drm_encoder *);
1021bool nouveau_dp_link_train(struct drm_encoder *);
1022
1023/* nv04_fb.c */
1024extern int nv04_fb_init(struct drm_device *);
1025extern void nv04_fb_takedown(struct drm_device *);
1026
1027/* nv10_fb.c */
1028extern int nv10_fb_init(struct drm_device *);
1029extern void nv10_fb_takedown(struct drm_device *);
Francisco Jereza5cf68b2010-10-24 16:14:41 +02001030extern void nv10_fb_init_tile_region(struct drm_device *dev, int i,
1031 uint32_t addr, uint32_t size,
1032 uint32_t pitch, uint32_t flags);
1033extern void nv10_fb_set_tile_region(struct drm_device *dev, int i);
1034extern void nv10_fb_free_tile_region(struct drm_device *dev, int i);
Ben Skeggs6ee73862009-12-11 19:24:15 +10001035
Francisco Jerez8bded182010-07-21 21:08:11 +02001036/* nv30_fb.c */
1037extern int nv30_fb_init(struct drm_device *);
1038extern void nv30_fb_takedown(struct drm_device *);
Francisco Jereza5cf68b2010-10-24 16:14:41 +02001039extern void nv30_fb_init_tile_region(struct drm_device *dev, int i,
1040 uint32_t addr, uint32_t size,
1041 uint32_t pitch, uint32_t flags);
1042extern void nv30_fb_free_tile_region(struct drm_device *dev, int i);
Francisco Jerez8bded182010-07-21 21:08:11 +02001043
Ben Skeggs6ee73862009-12-11 19:24:15 +10001044/* nv40_fb.c */
1045extern int nv40_fb_init(struct drm_device *);
1046extern void nv40_fb_takedown(struct drm_device *);
Francisco Jereza5cf68b2010-10-24 16:14:41 +02001047extern void nv40_fb_set_tile_region(struct drm_device *dev, int i);
1048
Marcin Kościelnicki304424e2010-03-01 00:18:39 +00001049/* nv50_fb.c */
1050extern int nv50_fb_init(struct drm_device *);
1051extern void nv50_fb_takedown(struct drm_device *);
Ben Skeggsd96773e2010-09-03 15:46:58 +10001052extern void nv50_fb_vm_trap(struct drm_device *, int display, const char *);
Marcin Kościelnicki304424e2010-03-01 00:18:39 +00001053
Ben Skeggs4b223ee2010-08-03 10:00:56 +10001054/* nvc0_fb.c */
1055extern int nvc0_fb_init(struct drm_device *);
1056extern void nvc0_fb_takedown(struct drm_device *);
1057
Ben Skeggs6ee73862009-12-11 19:24:15 +10001058/* nv04_fifo.c */
1059extern int nv04_fifo_init(struct drm_device *);
Ben Skeggs5178d402010-11-03 10:56:05 +10001060extern void nv04_fifo_fini(struct drm_device *);
Ben Skeggs6ee73862009-12-11 19:24:15 +10001061extern void nv04_fifo_disable(struct drm_device *);
1062extern void nv04_fifo_enable(struct drm_device *);
1063extern bool nv04_fifo_reassign(struct drm_device *, bool);
Francisco Jerez588d7d12009-12-13 20:07:42 +01001064extern bool nv04_fifo_cache_pull(struct drm_device *, bool);
Ben Skeggs6ee73862009-12-11 19:24:15 +10001065extern int nv04_fifo_channel_id(struct drm_device *);
1066extern int nv04_fifo_create_context(struct nouveau_channel *);
1067extern void nv04_fifo_destroy_context(struct nouveau_channel *);
1068extern int nv04_fifo_load_context(struct nouveau_channel *);
1069extern int nv04_fifo_unload_context(struct drm_device *);
Ben Skeggs5178d402010-11-03 10:56:05 +10001070extern void nv04_fifo_isr(struct drm_device *);
Ben Skeggs6ee73862009-12-11 19:24:15 +10001071
1072/* nv10_fifo.c */
1073extern int nv10_fifo_init(struct drm_device *);
1074extern int nv10_fifo_channel_id(struct drm_device *);
1075extern int nv10_fifo_create_context(struct nouveau_channel *);
Ben Skeggs6ee73862009-12-11 19:24:15 +10001076extern int nv10_fifo_load_context(struct nouveau_channel *);
1077extern int nv10_fifo_unload_context(struct drm_device *);
1078
1079/* nv40_fifo.c */
1080extern int nv40_fifo_init(struct drm_device *);
1081extern int nv40_fifo_create_context(struct nouveau_channel *);
Ben Skeggs6ee73862009-12-11 19:24:15 +10001082extern int nv40_fifo_load_context(struct nouveau_channel *);
1083extern int nv40_fifo_unload_context(struct drm_device *);
1084
1085/* nv50_fifo.c */
1086extern int nv50_fifo_init(struct drm_device *);
1087extern void nv50_fifo_takedown(struct drm_device *);
1088extern int nv50_fifo_channel_id(struct drm_device *);
1089extern int nv50_fifo_create_context(struct nouveau_channel *);
1090extern void nv50_fifo_destroy_context(struct nouveau_channel *);
1091extern int nv50_fifo_load_context(struct nouveau_channel *);
1092extern int nv50_fifo_unload_context(struct drm_device *);
Ben Skeggs56ac7472010-10-22 10:26:24 +10001093extern void nv50_fifo_tlb_flush(struct drm_device *dev);
Ben Skeggs6ee73862009-12-11 19:24:15 +10001094
Ben Skeggs4b223ee2010-08-03 10:00:56 +10001095/* nvc0_fifo.c */
1096extern int nvc0_fifo_init(struct drm_device *);
1097extern void nvc0_fifo_takedown(struct drm_device *);
1098extern void nvc0_fifo_disable(struct drm_device *);
1099extern void nvc0_fifo_enable(struct drm_device *);
1100extern bool nvc0_fifo_reassign(struct drm_device *, bool);
Ben Skeggs4b223ee2010-08-03 10:00:56 +10001101extern bool nvc0_fifo_cache_pull(struct drm_device *, bool);
1102extern int nvc0_fifo_channel_id(struct drm_device *);
1103extern int nvc0_fifo_create_context(struct nouveau_channel *);
1104extern void nvc0_fifo_destroy_context(struct nouveau_channel *);
1105extern int nvc0_fifo_load_context(struct nouveau_channel *);
1106extern int nvc0_fifo_unload_context(struct drm_device *);
1107
Ben Skeggs6ee73862009-12-11 19:24:15 +10001108/* nv04_graph.c */
Ben Skeggs6ee73862009-12-11 19:24:15 +10001109extern int nv04_graph_init(struct drm_device *);
1110extern void nv04_graph_takedown(struct drm_device *);
1111extern void nv04_graph_fifo_access(struct drm_device *, bool);
1112extern struct nouveau_channel *nv04_graph_channel(struct drm_device *);
1113extern int nv04_graph_create_context(struct nouveau_channel *);
1114extern void nv04_graph_destroy_context(struct nouveau_channel *);
1115extern int nv04_graph_load_context(struct nouveau_channel *);
1116extern int nv04_graph_unload_context(struct drm_device *);
Francisco Jerez332b2422010-10-20 23:35:40 +02001117extern int nv04_graph_mthd_page_flip(struct nouveau_channel *chan,
1118 u32 class, u32 mthd, u32 data);
Ben Skeggs274fec92010-11-03 13:16:18 +10001119extern struct nouveau_bitfield nv04_graph_nsource[];
Ben Skeggs6ee73862009-12-11 19:24:15 +10001120
1121/* nv10_graph.c */
Ben Skeggs6ee73862009-12-11 19:24:15 +10001122extern int nv10_graph_init(struct drm_device *);
1123extern void nv10_graph_takedown(struct drm_device *);
1124extern struct nouveau_channel *nv10_graph_channel(struct drm_device *);
1125extern int nv10_graph_create_context(struct nouveau_channel *);
1126extern void nv10_graph_destroy_context(struct nouveau_channel *);
1127extern int nv10_graph_load_context(struct nouveau_channel *);
1128extern int nv10_graph_unload_context(struct drm_device *);
Francisco Jereza5cf68b2010-10-24 16:14:41 +02001129extern void nv10_graph_set_tile_region(struct drm_device *dev, int i);
Ben Skeggs274fec92010-11-03 13:16:18 +10001130extern struct nouveau_bitfield nv10_graph_intr[];
1131extern struct nouveau_bitfield nv10_graph_nstatus[];
Ben Skeggs6ee73862009-12-11 19:24:15 +10001132
1133/* nv20_graph.c */
Ben Skeggs6ee73862009-12-11 19:24:15 +10001134extern int nv20_graph_create_context(struct nouveau_channel *);
1135extern void nv20_graph_destroy_context(struct nouveau_channel *);
1136extern int nv20_graph_load_context(struct nouveau_channel *);
1137extern int nv20_graph_unload_context(struct drm_device *);
1138extern int nv20_graph_init(struct drm_device *);
1139extern void nv20_graph_takedown(struct drm_device *);
1140extern int nv30_graph_init(struct drm_device *);
Francisco Jereza5cf68b2010-10-24 16:14:41 +02001141extern void nv20_graph_set_tile_region(struct drm_device *dev, int i);
Ben Skeggs6ee73862009-12-11 19:24:15 +10001142
1143/* nv40_graph.c */
Ben Skeggs6ee73862009-12-11 19:24:15 +10001144extern int nv40_graph_init(struct drm_device *);
1145extern void nv40_graph_takedown(struct drm_device *);
1146extern struct nouveau_channel *nv40_graph_channel(struct drm_device *);
1147extern int nv40_graph_create_context(struct nouveau_channel *);
1148extern void nv40_graph_destroy_context(struct nouveau_channel *);
1149extern int nv40_graph_load_context(struct nouveau_channel *);
1150extern int nv40_graph_unload_context(struct drm_device *);
Ben Skeggs054b93e2009-12-15 22:02:47 +10001151extern void nv40_grctx_init(struct nouveau_grctx *);
Francisco Jereza5cf68b2010-10-24 16:14:41 +02001152extern void nv40_graph_set_tile_region(struct drm_device *dev, int i);
Ben Skeggs6ee73862009-12-11 19:24:15 +10001153
1154/* nv50_graph.c */
Ben Skeggs6ee73862009-12-11 19:24:15 +10001155extern int nv50_graph_init(struct drm_device *);
1156extern void nv50_graph_takedown(struct drm_device *);
1157extern void nv50_graph_fifo_access(struct drm_device *, bool);
1158extern struct nouveau_channel *nv50_graph_channel(struct drm_device *);
1159extern int nv50_graph_create_context(struct nouveau_channel *);
1160extern void nv50_graph_destroy_context(struct nouveau_channel *);
1161extern int nv50_graph_load_context(struct nouveau_channel *);
1162extern int nv50_graph_unload_context(struct drm_device *);
Marcin Kościelnickid5f3c902010-02-25 00:54:02 +00001163extern int nv50_grctx_init(struct nouveau_grctx *);
Ben Skeggs56ac7472010-10-22 10:26:24 +10001164extern void nv50_graph_tlb_flush(struct drm_device *dev);
1165extern void nv86_graph_tlb_flush(struct drm_device *dev);
Ben Skeggs6ee73862009-12-11 19:24:15 +10001166
Ben Skeggs4b223ee2010-08-03 10:00:56 +10001167/* nvc0_graph.c */
1168extern int nvc0_graph_init(struct drm_device *);
1169extern void nvc0_graph_takedown(struct drm_device *);
1170extern void nvc0_graph_fifo_access(struct drm_device *, bool);
1171extern struct nouveau_channel *nvc0_graph_channel(struct drm_device *);
1172extern int nvc0_graph_create_context(struct nouveau_channel *);
1173extern void nvc0_graph_destroy_context(struct nouveau_channel *);
1174extern int nvc0_graph_load_context(struct nouveau_channel *);
1175extern int nvc0_graph_unload_context(struct drm_device *);
1176
Ben Skeggsbd2e5972010-10-19 20:06:01 +10001177/* nv84_crypt.c */
1178extern int nv84_crypt_init(struct drm_device *dev);
1179extern void nv84_crypt_fini(struct drm_device *dev);
1180extern int nv84_crypt_create_context(struct nouveau_channel *);
1181extern void nv84_crypt_destroy_context(struct nouveau_channel *);
1182extern void nv84_crypt_tlb_flush(struct drm_device *dev);
1183
Ben Skeggs6ee73862009-12-11 19:24:15 +10001184/* nv04_instmem.c */
1185extern int nv04_instmem_init(struct drm_device *);
1186extern void nv04_instmem_takedown(struct drm_device *);
1187extern int nv04_instmem_suspend(struct drm_device *);
1188extern void nv04_instmem_resume(struct drm_device *);
Ben Skeggse41115d2010-11-01 11:45:02 +10001189extern int nv04_instmem_get(struct nouveau_gpuobj *, u32 size, u32 align);
1190extern void nv04_instmem_put(struct nouveau_gpuobj *);
1191extern int nv04_instmem_map(struct nouveau_gpuobj *);
1192extern void nv04_instmem_unmap(struct nouveau_gpuobj *);
Ben Skeggsf56cb862010-07-08 11:29:10 +10001193extern void nv04_instmem_flush(struct drm_device *);
Ben Skeggs6ee73862009-12-11 19:24:15 +10001194
1195/* nv50_instmem.c */
1196extern int nv50_instmem_init(struct drm_device *);
1197extern void nv50_instmem_takedown(struct drm_device *);
1198extern int nv50_instmem_suspend(struct drm_device *);
1199extern void nv50_instmem_resume(struct drm_device *);
Ben Skeggse41115d2010-11-01 11:45:02 +10001200extern int nv50_instmem_get(struct nouveau_gpuobj *, u32 size, u32 align);
1201extern void nv50_instmem_put(struct nouveau_gpuobj *);
1202extern int nv50_instmem_map(struct nouveau_gpuobj *);
1203extern void nv50_instmem_unmap(struct nouveau_gpuobj *);
Ben Skeggsf56cb862010-07-08 11:29:10 +10001204extern void nv50_instmem_flush(struct drm_device *);
Ben Skeggs734ee832010-07-15 11:02:54 +10001205extern void nv84_instmem_flush(struct drm_device *);
Ben Skeggs63187212010-07-08 11:39:18 +10001206extern void nv50_vm_flush(struct drm_device *, int engine);
Ben Skeggs6ee73862009-12-11 19:24:15 +10001207
Ben Skeggs4b223ee2010-08-03 10:00:56 +10001208/* nvc0_instmem.c */
1209extern int nvc0_instmem_init(struct drm_device *);
1210extern void nvc0_instmem_takedown(struct drm_device *);
1211extern int nvc0_instmem_suspend(struct drm_device *);
1212extern void nvc0_instmem_resume(struct drm_device *);
Ben Skeggse41115d2010-11-01 11:45:02 +10001213extern int nvc0_instmem_get(struct nouveau_gpuobj *, u32 size, u32 align);
1214extern void nvc0_instmem_put(struct nouveau_gpuobj *);
1215extern int nvc0_instmem_map(struct nouveau_gpuobj *);
1216extern void nvc0_instmem_unmap(struct nouveau_gpuobj *);
Ben Skeggs4b223ee2010-08-03 10:00:56 +10001217extern void nvc0_instmem_flush(struct drm_device *);
1218
Ben Skeggs6ee73862009-12-11 19:24:15 +10001219/* nv04_mc.c */
1220extern int nv04_mc_init(struct drm_device *);
1221extern void nv04_mc_takedown(struct drm_device *);
1222
1223/* nv40_mc.c */
1224extern int nv40_mc_init(struct drm_device *);
1225extern void nv40_mc_takedown(struct drm_device *);
1226
1227/* nv50_mc.c */
1228extern int nv50_mc_init(struct drm_device *);
1229extern void nv50_mc_takedown(struct drm_device *);
1230
1231/* nv04_timer.c */
1232extern int nv04_timer_init(struct drm_device *);
1233extern uint64_t nv04_timer_read(struct drm_device *);
1234extern void nv04_timer_takedown(struct drm_device *);
1235
1236extern long nouveau_compat_ioctl(struct file *file, unsigned int cmd,
1237 unsigned long arg);
1238
1239/* nv04_dac.c */
Ben Skeggs8f1a6082010-06-28 14:35:50 +10001240extern int nv04_dac_create(struct drm_connector *, struct dcb_entry *);
Francisco Jerez11d6eb22009-12-17 18:52:44 +01001241extern uint32_t nv17_dac_sample_load(struct drm_encoder *encoder);
Ben Skeggs6ee73862009-12-11 19:24:15 +10001242extern int nv04_dac_output_offset(struct drm_encoder *encoder);
1243extern void nv04_dac_update_dacclk(struct drm_encoder *encoder, bool enable);
Francisco Jerez8ccfe9e2010-07-04 16:14:42 +02001244extern bool nv04_dac_in_use(struct drm_encoder *encoder);
Ben Skeggs6ee73862009-12-11 19:24:15 +10001245
1246/* nv04_dfp.c */
Ben Skeggs8f1a6082010-06-28 14:35:50 +10001247extern int nv04_dfp_create(struct drm_connector *, struct dcb_entry *);
Ben Skeggs6ee73862009-12-11 19:24:15 +10001248extern int nv04_dfp_get_bound_head(struct drm_device *dev, struct dcb_entry *dcbent);
1249extern void nv04_dfp_bind_head(struct drm_device *dev, struct dcb_entry *dcbent,
1250 int head, bool dl);
1251extern void nv04_dfp_disable(struct drm_device *dev, int head);
1252extern void nv04_dfp_update_fp_control(struct drm_encoder *encoder, int mode);
1253
1254/* nv04_tv.c */
1255extern int nv04_tv_identify(struct drm_device *dev, int i2c_index);
Ben Skeggs8f1a6082010-06-28 14:35:50 +10001256extern int nv04_tv_create(struct drm_connector *, struct dcb_entry *);
Ben Skeggs6ee73862009-12-11 19:24:15 +10001257
1258/* nv17_tv.c */
Ben Skeggs8f1a6082010-06-28 14:35:50 +10001259extern int nv17_tv_create(struct drm_connector *, struct dcb_entry *);
Ben Skeggs6ee73862009-12-11 19:24:15 +10001260
1261/* nv04_display.c */
Francisco Jerezc88c2e02010-07-24 17:37:33 +02001262extern int nv04_display_early_init(struct drm_device *);
1263extern void nv04_display_late_takedown(struct drm_device *);
Ben Skeggs6ee73862009-12-11 19:24:15 +10001264extern int nv04_display_create(struct drm_device *);
Francisco Jerezc88c2e02010-07-24 17:37:33 +02001265extern int nv04_display_init(struct drm_device *);
Ben Skeggs6ee73862009-12-11 19:24:15 +10001266extern void nv04_display_destroy(struct drm_device *);
Ben Skeggs6ee73862009-12-11 19:24:15 +10001267
1268/* nv04_crtc.c */
1269extern int nv04_crtc_create(struct drm_device *, int index);
1270
1271/* nouveau_bo.c */
1272extern struct ttm_bo_driver nouveau_bo_driver;
1273extern int nouveau_bo_new(struct drm_device *, struct nouveau_channel *,
1274 int size, int align, uint32_t flags,
1275 uint32_t tile_mode, uint32_t tile_flags,
1276 bool no_vm, bool mappable, struct nouveau_bo **);
1277extern int nouveau_bo_pin(struct nouveau_bo *, uint32_t flags);
1278extern int nouveau_bo_unpin(struct nouveau_bo *);
1279extern int nouveau_bo_map(struct nouveau_bo *);
1280extern void nouveau_bo_unmap(struct nouveau_bo *);
Francisco Jerez78ad0f72010-03-18 13:07:47 +01001281extern void nouveau_bo_placement_set(struct nouveau_bo *, uint32_t type,
1282 uint32_t busy);
Ben Skeggs6ee73862009-12-11 19:24:15 +10001283extern u16 nouveau_bo_rd16(struct nouveau_bo *nvbo, unsigned index);
1284extern void nouveau_bo_wr16(struct nouveau_bo *nvbo, unsigned index, u16 val);
1285extern u32 nouveau_bo_rd32(struct nouveau_bo *nvbo, unsigned index);
1286extern void nouveau_bo_wr32(struct nouveau_bo *nvbo, unsigned index, u32 val);
Francisco Jerez332b2422010-10-20 23:35:40 +02001287extern void nouveau_bo_fence(struct nouveau_bo *, struct nouveau_fence *);
Ben Skeggs6ee73862009-12-11 19:24:15 +10001288
1289/* nouveau_fence.c */
1290struct nouveau_fence;
Francisco Jerez0c6c1c22010-09-22 00:58:54 +02001291extern int nouveau_fence_init(struct drm_device *);
1292extern void nouveau_fence_fini(struct drm_device *);
Francisco Jerez27307232010-09-21 18:57:11 +02001293extern int nouveau_fence_channel_init(struct nouveau_channel *);
1294extern void nouveau_fence_channel_fini(struct nouveau_channel *);
Ben Skeggs6ee73862009-12-11 19:24:15 +10001295extern void nouveau_fence_update(struct nouveau_channel *);
1296extern int nouveau_fence_new(struct nouveau_channel *, struct nouveau_fence **,
1297 bool emit);
1298extern int nouveau_fence_emit(struct nouveau_fence *);
Francisco Jerez8ac38912010-09-21 20:49:39 +02001299extern void nouveau_fence_work(struct nouveau_fence *fence,
1300 void (*work)(void *priv, bool signalled),
1301 void *priv);
Ben Skeggs6ee73862009-12-11 19:24:15 +10001302struct nouveau_channel *nouveau_fence_channel(struct nouveau_fence *);
Marcin Slusarz382d62e2010-10-20 21:50:24 +02001303
1304extern bool __nouveau_fence_signalled(void *obj, void *arg);
1305extern int __nouveau_fence_wait(void *obj, void *arg, bool lazy, bool intr);
1306extern int __nouveau_fence_flush(void *obj, void *arg);
1307extern void __nouveau_fence_unref(void **obj);
1308extern void *__nouveau_fence_ref(void *obj);
1309
1310static inline bool nouveau_fence_signalled(struct nouveau_fence *obj)
1311{
1312 return __nouveau_fence_signalled(obj, NULL);
1313}
1314static inline int
1315nouveau_fence_wait(struct nouveau_fence *obj, bool lazy, bool intr)
1316{
1317 return __nouveau_fence_wait(obj, NULL, lazy, intr);
1318}
Francisco Jerez27307232010-09-21 18:57:11 +02001319extern int nouveau_fence_sync(struct nouveau_fence *, struct nouveau_channel *);
Marcin Slusarz382d62e2010-10-20 21:50:24 +02001320static inline int nouveau_fence_flush(struct nouveau_fence *obj)
1321{
1322 return __nouveau_fence_flush(obj, NULL);
1323}
1324static inline void nouveau_fence_unref(struct nouveau_fence **obj)
1325{
1326 __nouveau_fence_unref((void **)obj);
1327}
1328static inline struct nouveau_fence *nouveau_fence_ref(struct nouveau_fence *obj)
1329{
1330 return __nouveau_fence_ref(obj);
1331}
Ben Skeggs6ee73862009-12-11 19:24:15 +10001332
1333/* nouveau_gem.c */
1334extern int nouveau_gem_new(struct drm_device *, struct nouveau_channel *,
1335 int size, int align, uint32_t flags,
1336 uint32_t tile_mode, uint32_t tile_flags,
1337 bool no_vm, bool mappable, struct nouveau_bo **);
1338extern int nouveau_gem_object_new(struct drm_gem_object *);
1339extern void nouveau_gem_object_del(struct drm_gem_object *);
1340extern int nouveau_gem_ioctl_new(struct drm_device *, void *,
1341 struct drm_file *);
1342extern int nouveau_gem_ioctl_pushbuf(struct drm_device *, void *,
1343 struct drm_file *);
Ben Skeggs6ee73862009-12-11 19:24:15 +10001344extern int nouveau_gem_ioctl_cpu_prep(struct drm_device *, void *,
1345 struct drm_file *);
1346extern int nouveau_gem_ioctl_cpu_fini(struct drm_device *, void *,
1347 struct drm_file *);
1348extern int nouveau_gem_ioctl_info(struct drm_device *, void *,
1349 struct drm_file *);
1350
Francisco Jerez042206c2010-10-21 18:19:29 +02001351/* nouveau_display.c */
1352int nouveau_vblank_enable(struct drm_device *dev, int crtc);
1353void nouveau_vblank_disable(struct drm_device *dev, int crtc);
Francisco Jerez332b2422010-10-20 23:35:40 +02001354int nouveau_crtc_page_flip(struct drm_crtc *crtc, struct drm_framebuffer *fb,
1355 struct drm_pending_vblank_event *event);
1356int nouveau_finish_page_flip(struct nouveau_channel *,
1357 struct nouveau_page_flip_state *);
Francisco Jerez042206c2010-10-21 18:19:29 +02001358
Ben Skeggsee2e0132010-07-26 09:28:25 +10001359/* nv10_gpio.c */
1360int nv10_gpio_get(struct drm_device *dev, enum dcb_gpio_tag tag);
1361int nv10_gpio_set(struct drm_device *dev, enum dcb_gpio_tag tag, int state);
Ben Skeggs6ee73862009-12-11 19:24:15 +10001362
Ben Skeggs45284162010-04-07 12:57:35 +10001363/* nv50_gpio.c */
Ben Skeggsee2e0132010-07-26 09:28:25 +10001364int nv50_gpio_init(struct drm_device *dev);
Ben Skeggs2cbd4c82010-11-03 10:18:04 +10001365void nv50_gpio_fini(struct drm_device *dev);
Ben Skeggs45284162010-04-07 12:57:35 +10001366int nv50_gpio_get(struct drm_device *dev, enum dcb_gpio_tag tag);
1367int nv50_gpio_set(struct drm_device *dev, enum dcb_gpio_tag tag, int state);
Ben Skeggsfce2bad2010-11-11 16:14:56 +10001368int nv50_gpio_irq_register(struct drm_device *, enum dcb_gpio_tag,
1369 void (*)(void *, int), void *);
1370void nv50_gpio_irq_unregister(struct drm_device *, enum dcb_gpio_tag,
1371 void (*)(void *, int), void *);
1372bool nv50_gpio_irq_enable(struct drm_device *, enum dcb_gpio_tag, bool on);
Ben Skeggs45284162010-04-07 12:57:35 +10001373
Ben Skeggse9ebb682010-04-28 14:07:06 +10001374/* nv50_calc. */
1375int nv50_calc_pll(struct drm_device *, struct pll_lims *, int clk,
1376 int *N1, int *M1, int *N2, int *M2, int *P);
1377int nv50_calc_pll2(struct drm_device *, struct pll_lims *,
1378 int clk, int *N, int *fN, int *M, int *P);
1379
Ben Skeggs6ee73862009-12-11 19:24:15 +10001380#ifndef ioread32_native
1381#ifdef __BIG_ENDIAN
1382#define ioread16_native ioread16be
1383#define iowrite16_native iowrite16be
1384#define ioread32_native ioread32be
1385#define iowrite32_native iowrite32be
1386#else /* def __BIG_ENDIAN */
1387#define ioread16_native ioread16
1388#define iowrite16_native iowrite16
1389#define ioread32_native ioread32
1390#define iowrite32_native iowrite32
1391#endif /* def __BIG_ENDIAN else */
1392#endif /* !ioread32_native */
1393
1394/* channel control reg access */
1395static inline u32 nvchan_rd32(struct nouveau_channel *chan, unsigned reg)
1396{
1397 return ioread32_native(chan->user + reg);
1398}
1399
1400static inline void nvchan_wr32(struct nouveau_channel *chan,
1401 unsigned reg, u32 val)
1402{
1403 iowrite32_native(val, chan->user + reg);
1404}
1405
1406/* register access */
1407static inline u32 nv_rd32(struct drm_device *dev, unsigned reg)
1408{
1409 struct drm_nouveau_private *dev_priv = dev->dev_private;
1410 return ioread32_native(dev_priv->mmio + reg);
1411}
1412
1413static inline void nv_wr32(struct drm_device *dev, unsigned reg, u32 val)
1414{
1415 struct drm_nouveau_private *dev_priv = dev->dev_private;
1416 iowrite32_native(val, dev_priv->mmio + reg);
1417}
1418
Ben Skeggs2a7fdb2b2010-08-30 16:14:51 +10001419static inline u32 nv_mask(struct drm_device *dev, u32 reg, u32 mask, u32 val)
Ben Skeggs49eed802010-07-23 11:17:57 +10001420{
1421 u32 tmp = nv_rd32(dev, reg);
Ben Skeggs2a7fdb2b2010-08-30 16:14:51 +10001422 nv_wr32(dev, reg, (tmp & ~mask) | val);
1423 return tmp;
Ben Skeggs49eed802010-07-23 11:17:57 +10001424}
1425
Ben Skeggs6ee73862009-12-11 19:24:15 +10001426static inline u8 nv_rd08(struct drm_device *dev, unsigned reg)
1427{
1428 struct drm_nouveau_private *dev_priv = dev->dev_private;
1429 return ioread8(dev_priv->mmio + reg);
1430}
1431
1432static inline void nv_wr08(struct drm_device *dev, unsigned reg, u8 val)
1433{
1434 struct drm_nouveau_private *dev_priv = dev->dev_private;
1435 iowrite8(val, dev_priv->mmio + reg);
1436}
1437
Francisco Jerez4b5c1522010-09-07 17:34:44 +02001438#define nv_wait(dev, reg, mask, val) \
Ben Skeggs12fb9522010-11-19 14:32:56 +10001439 nouveau_wait_eq(dev, 2000000000ULL, (reg), (mask), (val))
1440#define nv_wait_ne(dev, reg, mask, val) \
1441 nouveau_wait_ne(dev, 2000000000ULL, (reg), (mask), (val))
Ben Skeggs6ee73862009-12-11 19:24:15 +10001442
1443/* PRAMIN access */
1444static inline u32 nv_ri32(struct drm_device *dev, unsigned offset)
1445{
1446 struct drm_nouveau_private *dev_priv = dev->dev_private;
1447 return ioread32_native(dev_priv->ramin + offset);
1448}
1449
1450static inline void nv_wi32(struct drm_device *dev, unsigned offset, u32 val)
1451{
1452 struct drm_nouveau_private *dev_priv = dev->dev_private;
1453 iowrite32_native(val, dev_priv->ramin + offset);
1454}
1455
1456/* object access */
Ben Skeggsb3beb162010-09-01 15:24:29 +10001457extern u32 nv_ro32(struct nouveau_gpuobj *, u32 offset);
1458extern void nv_wo32(struct nouveau_gpuobj *, u32 offset, u32 val);
Ben Skeggs6ee73862009-12-11 19:24:15 +10001459
1460/*
1461 * Logging
1462 * Argument d is (struct drm_device *).
1463 */
1464#define NV_PRINTK(level, d, fmt, arg...) \
1465 printk(level "[" DRM_NAME "] " DRIVER_NAME " %s: " fmt, \
1466 pci_name(d->pdev), ##arg)
1467#ifndef NV_DEBUG_NOTRACE
1468#define NV_DEBUG(d, fmt, arg...) do { \
Maarten Maathuisef2bb502009-12-13 16:53:12 +01001469 if (drm_debug & DRM_UT_DRIVER) { \
1470 NV_PRINTK(KERN_DEBUG, d, "%s:%d - " fmt, __func__, \
1471 __LINE__, ##arg); \
1472 } \
1473} while (0)
1474#define NV_DEBUG_KMS(d, fmt, arg...) do { \
1475 if (drm_debug & DRM_UT_KMS) { \
Ben Skeggs6ee73862009-12-11 19:24:15 +10001476 NV_PRINTK(KERN_DEBUG, d, "%s:%d - " fmt, __func__, \
1477 __LINE__, ##arg); \
1478 } \
1479} while (0)
1480#else
1481#define NV_DEBUG(d, fmt, arg...) do { \
Maarten Maathuisef2bb502009-12-13 16:53:12 +01001482 if (drm_debug & DRM_UT_DRIVER) \
1483 NV_PRINTK(KERN_DEBUG, d, fmt, ##arg); \
1484} while (0)
1485#define NV_DEBUG_KMS(d, fmt, arg...) do { \
1486 if (drm_debug & DRM_UT_KMS) \
Ben Skeggs6ee73862009-12-11 19:24:15 +10001487 NV_PRINTK(KERN_DEBUG, d, fmt, ##arg); \
1488} while (0)
1489#endif
1490#define NV_ERROR(d, fmt, arg...) NV_PRINTK(KERN_ERR, d, fmt, ##arg)
1491#define NV_INFO(d, fmt, arg...) NV_PRINTK(KERN_INFO, d, fmt, ##arg)
1492#define NV_TRACEWARN(d, fmt, arg...) NV_PRINTK(KERN_NOTICE, d, fmt, ##arg)
1493#define NV_TRACE(d, fmt, arg...) NV_PRINTK(KERN_INFO, d, fmt, ##arg)
1494#define NV_WARN(d, fmt, arg...) NV_PRINTK(KERN_WARNING, d, fmt, ##arg)
1495
1496/* nouveau_reg_debug bitmask */
1497enum {
1498 NOUVEAU_REG_DEBUG_MC = 0x1,
1499 NOUVEAU_REG_DEBUG_VIDEO = 0x2,
1500 NOUVEAU_REG_DEBUG_FB = 0x4,
1501 NOUVEAU_REG_DEBUG_EXTDEV = 0x8,
1502 NOUVEAU_REG_DEBUG_CRTC = 0x10,
1503 NOUVEAU_REG_DEBUG_RAMDAC = 0x20,
1504 NOUVEAU_REG_DEBUG_VGACRTC = 0x40,
1505 NOUVEAU_REG_DEBUG_RMVIO = 0x80,
1506 NOUVEAU_REG_DEBUG_VGAATTR = 0x100,
1507 NOUVEAU_REG_DEBUG_EVO = 0x200,
1508};
1509
1510#define NV_REG_DEBUG(type, dev, fmt, arg...) do { \
1511 if (nouveau_reg_debug & NOUVEAU_REG_DEBUG_##type) \
1512 NV_PRINTK(KERN_DEBUG, dev, "%s: " fmt, __func__, ##arg); \
1513} while (0)
1514
1515static inline bool
1516nv_two_heads(struct drm_device *dev)
1517{
1518 struct drm_nouveau_private *dev_priv = dev->dev_private;
1519 const int impl = dev->pci_device & 0x0ff0;
1520
1521 if (dev_priv->card_type >= NV_10 && impl != 0x0100 &&
1522 impl != 0x0150 && impl != 0x01a0 && impl != 0x0200)
1523 return true;
1524
1525 return false;
1526}
1527
1528static inline bool
1529nv_gf4_disp_arch(struct drm_device *dev)
1530{
1531 return nv_two_heads(dev) && (dev->pci_device & 0x0ff0) != 0x0110;
1532}
1533
1534static inline bool
1535nv_two_reg_pll(struct drm_device *dev)
1536{
1537 struct drm_nouveau_private *dev_priv = dev->dev_private;
1538 const int impl = dev->pci_device & 0x0ff0;
1539
1540 if (impl == 0x0310 || impl == 0x0340 || dev_priv->card_type >= NV_40)
1541 return true;
1542 return false;
1543}
1544
Francisco Jerezacae1162010-08-15 14:31:31 +02001545static inline bool
1546nv_match_device(struct drm_device *dev, unsigned device,
1547 unsigned sub_vendor, unsigned sub_device)
1548{
1549 return dev->pdev->device == device &&
1550 dev->pdev->subsystem_vendor == sub_vendor &&
1551 dev->pdev->subsystem_device == sub_device;
1552}
1553
Ben Skeggs7f4a1952010-11-16 11:50:09 +10001554/* memory type/access flags, do not match hardware values */
1555#define NV_MEM_ACCESS_RO 1
1556#define NV_MEM_ACCESS_WO 2
1557#define NV_MEM_ACCESS_RW (NV_MEM_ACCESS_RO | NV_MEM_ACCESS_WO)
1558#define NV_MEM_ACCESS_VM 4
1559
1560#define NV_MEM_TARGET_VRAM 0
1561#define NV_MEM_TARGET_PCI 1
1562#define NV_MEM_TARGET_PCI_NOSNOOP 2
1563#define NV_MEM_TARGET_VM 3
1564#define NV_MEM_TARGET_GART 4
1565
1566#define NV_MEM_TYPE_VM 0x7f
1567#define NV_MEM_COMP_VM 0x03
1568
1569/* NV_SW object class */
Francisco Jerezf03a3142009-12-26 02:42:45 +01001570#define NV_SW 0x0000506e
1571#define NV_SW_DMA_SEMAPHORE 0x00000060
1572#define NV_SW_SEMAPHORE_OFFSET 0x00000064
1573#define NV_SW_SEMAPHORE_ACQUIRE 0x00000068
1574#define NV_SW_SEMAPHORE_RELEASE 0x0000006c
Francisco Jerez8af29cc2010-10-02 17:04:46 +02001575#define NV_SW_YIELD 0x00000080
Francisco Jerezf03a3142009-12-26 02:42:45 +01001576#define NV_SW_DMA_VBLSEM 0x0000018c
1577#define NV_SW_VBLSEM_OFFSET 0x00000400
1578#define NV_SW_VBLSEM_RELEASE_VALUE 0x00000404
1579#define NV_SW_VBLSEM_RELEASE 0x00000408
Francisco Jerez332b2422010-10-20 23:35:40 +02001580#define NV_SW_PAGE_FLIP 0x00000500
Ben Skeggs6ee73862009-12-11 19:24:15 +10001581
1582#endif /* __NOUVEAU_DRV_H__ */