nouveau_drv.h 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340
  1. /*
  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. #ifndef __NOUVEAU_DRV_H__
  25. #define __NOUVEAU_DRV_H__
  26. #define DRIVER_AUTHOR "Stephane Marchesin"
  27. #define DRIVER_EMAIL "dri-devel@lists.sourceforge.net"
  28. #define DRIVER_NAME "nouveau"
  29. #define DRIVER_DESC "nVidia Riva/TNT/GeForce"
  30. #define DRIVER_DATE "20090420"
  31. #define DRIVER_MAJOR 0
  32. #define DRIVER_MINOR 0
  33. #define DRIVER_PATCHLEVEL 16
  34. #define NOUVEAU_FAMILY 0x0000FFFF
  35. #define NOUVEAU_FLAGS 0xFFFF0000
  36. #include "ttm/ttm_bo_api.h"
  37. #include "ttm/ttm_bo_driver.h"
  38. #include "ttm/ttm_placement.h"
  39. #include "ttm/ttm_memory.h"
  40. #include "ttm/ttm_module.h"
  41. struct nouveau_fpriv {
  42. struct ttm_object_file *tfile;
  43. };
  44. #define DRM_FILE_PAGE_OFFSET (0x100000000ULL >> PAGE_SHIFT)
  45. #include "nouveau_drm.h"
  46. #include "nouveau_reg.h"
  47. #include "nouveau_bios.h"
  48. struct nouveau_grctx;
  49. #define MAX_NUM_DCB_ENTRIES 16
  50. #define NOUVEAU_MAX_CHANNEL_NR 128
  51. #define NOUVEAU_MAX_TILE_NR 15
  52. #define NV50_VM_MAX_VRAM (2*1024*1024*1024ULL)
  53. #define NV50_VM_BLOCK (512*1024*1024ULL)
  54. #define NV50_VM_VRAM_NR (NV50_VM_MAX_VRAM / NV50_VM_BLOCK)
  55. struct nouveau_tile_reg {
  56. struct nouveau_fence *fence;
  57. uint32_t addr;
  58. uint32_t size;
  59. bool used;
  60. };
  61. struct nouveau_bo {
  62. struct ttm_buffer_object bo;
  63. struct ttm_placement placement;
  64. u32 placements[3];
  65. struct ttm_bo_kmap_obj kmap;
  66. struct list_head head;
  67. /* protected by ttm_bo_reserve() */
  68. struct drm_file *reserved_by;
  69. struct list_head entry;
  70. int pbbo_index;
  71. bool validate_mapped;
  72. struct nouveau_channel *channel;
  73. bool mappable;
  74. bool no_vm;
  75. uint32_t tile_mode;
  76. uint32_t tile_flags;
  77. struct nouveau_tile_reg *tile;
  78. struct drm_gem_object *gem;
  79. struct drm_file *cpu_filp;
  80. int pin_refcnt;
  81. };
  82. static inline struct nouveau_bo *
  83. nouveau_bo(struct ttm_buffer_object *bo)
  84. {
  85. return container_of(bo, struct nouveau_bo, bo);
  86. }
  87. static inline struct nouveau_bo *
  88. nouveau_gem_object(struct drm_gem_object *gem)
  89. {
  90. return gem ? gem->driver_private : NULL;
  91. }
  92. /* TODO: submit equivalent to TTM generic API upstream? */
  93. static inline void __iomem *
  94. nvbo_kmap_obj_iovirtual(struct nouveau_bo *nvbo)
  95. {
  96. bool is_iomem;
  97. void __iomem *ioptr = (void __force __iomem *)ttm_kmap_obj_virtual(
  98. &nvbo->kmap, &is_iomem);
  99. WARN_ON_ONCE(ioptr && !is_iomem);
  100. return ioptr;
  101. }
  102. struct mem_block {
  103. struct mem_block *next;
  104. struct mem_block *prev;
  105. uint64_t start;
  106. uint64_t size;
  107. struct drm_file *file_priv; /* NULL: free, -1: heap, other: real files */
  108. };
  109. enum nouveau_flags {
  110. NV_NFORCE = 0x10000000,
  111. NV_NFORCE2 = 0x20000000
  112. };
  113. #define NVOBJ_ENGINE_SW 0
  114. #define NVOBJ_ENGINE_GR 1
  115. #define NVOBJ_ENGINE_DISPLAY 2
  116. #define NVOBJ_ENGINE_INT 0xdeadbeef
  117. #define NVOBJ_FLAG_ALLOW_NO_REFS (1 << 0)
  118. #define NVOBJ_FLAG_ZERO_ALLOC (1 << 1)
  119. #define NVOBJ_FLAG_ZERO_FREE (1 << 2)
  120. #define NVOBJ_FLAG_FAKE (1 << 3)
  121. struct nouveau_gpuobj {
  122. struct list_head list;
  123. struct nouveau_channel *im_channel;
  124. struct mem_block *im_pramin;
  125. struct nouveau_bo *im_backing;
  126. uint32_t im_backing_start;
  127. uint32_t *im_backing_suspend;
  128. int im_bound;
  129. uint32_t flags;
  130. int refcount;
  131. uint32_t engine;
  132. uint32_t class;
  133. void (*dtor)(struct drm_device *, struct nouveau_gpuobj *);
  134. void *priv;
  135. };
  136. struct nouveau_gpuobj_ref {
  137. struct list_head list;
  138. struct nouveau_gpuobj *gpuobj;
  139. uint32_t instance;
  140. struct nouveau_channel *channel;
  141. int handle;
  142. };
  143. struct nouveau_channel {
  144. struct drm_device *dev;
  145. int id;
  146. /* owner of this fifo */
  147. struct drm_file *file_priv;
  148. /* mapping of the fifo itself */
  149. struct drm_local_map *map;
  150. /* mapping of the regs controling the fifo */
  151. void __iomem *user;
  152. uint32_t user_get;
  153. uint32_t user_put;
  154. /* Fencing */
  155. struct {
  156. /* lock protects the pending list only */
  157. spinlock_t lock;
  158. struct list_head pending;
  159. uint32_t sequence;
  160. uint32_t sequence_ack;
  161. uint32_t last_sequence_irq;
  162. } fence;
  163. /* DMA push buffer */
  164. struct nouveau_gpuobj_ref *pushbuf;
  165. struct nouveau_bo *pushbuf_bo;
  166. uint32_t pushbuf_base;
  167. /* Notifier memory */
  168. struct nouveau_bo *notifier_bo;
  169. struct mem_block *notifier_heap;
  170. /* PFIFO context */
  171. struct nouveau_gpuobj_ref *ramfc;
  172. struct nouveau_gpuobj_ref *cache;
  173. /* PGRAPH context */
  174. /* XXX may be merge 2 pointers as private data ??? */
  175. struct nouveau_gpuobj_ref *ramin_grctx;
  176. void *pgraph_ctx;
  177. /* NV50 VM */
  178. struct nouveau_gpuobj *vm_pd;
  179. struct nouveau_gpuobj_ref *vm_gart_pt;
  180. struct nouveau_gpuobj_ref *vm_vram_pt[NV50_VM_VRAM_NR];
  181. /* Objects */
  182. struct nouveau_gpuobj_ref *ramin; /* Private instmem */
  183. struct mem_block *ramin_heap; /* Private PRAMIN heap */
  184. struct nouveau_gpuobj_ref *ramht; /* Hash table */
  185. struct list_head ramht_refs; /* Objects referenced by RAMHT */
  186. /* GPU object info for stuff used in-kernel (mm_enabled) */
  187. uint32_t m2mf_ntfy;
  188. uint32_t vram_handle;
  189. uint32_t gart_handle;
  190. bool accel_done;
  191. /* Push buffer state (only for drm's channel on !mm_enabled) */
  192. struct {
  193. int max;
  194. int free;
  195. int cur;
  196. int put;
  197. /* access via pushbuf_bo */
  198. int ib_base;
  199. int ib_max;
  200. int ib_free;
  201. int ib_put;
  202. } dma;
  203. uint32_t sw_subchannel[8];
  204. struct {
  205. struct nouveau_gpuobj *vblsem;
  206. uint32_t vblsem_offset;
  207. uint32_t vblsem_rval;
  208. struct list_head vbl_wait;
  209. } nvsw;
  210. struct {
  211. bool active;
  212. char name[32];
  213. struct drm_info_list info;
  214. } debugfs;
  215. };
  216. struct nouveau_instmem_engine {
  217. void *priv;
  218. int (*init)(struct drm_device *dev);
  219. void (*takedown)(struct drm_device *dev);
  220. int (*suspend)(struct drm_device *dev);
  221. void (*resume)(struct drm_device *dev);
  222. int (*populate)(struct drm_device *, struct nouveau_gpuobj *,
  223. uint32_t *size);
  224. void (*clear)(struct drm_device *, struct nouveau_gpuobj *);
  225. int (*bind)(struct drm_device *, struct nouveau_gpuobj *);
  226. int (*unbind)(struct drm_device *, struct nouveau_gpuobj *);
  227. void (*prepare_access)(struct drm_device *, bool write);
  228. void (*finish_access)(struct drm_device *);
  229. };
  230. struct nouveau_mc_engine {
  231. int (*init)(struct drm_device *dev);
  232. void (*takedown)(struct drm_device *dev);
  233. };
  234. struct nouveau_timer_engine {
  235. int (*init)(struct drm_device *dev);
  236. void (*takedown)(struct drm_device *dev);
  237. uint64_t (*read)(struct drm_device *dev);
  238. };
  239. struct nouveau_fb_engine {
  240. int num_tiles;
  241. int (*init)(struct drm_device *dev);
  242. void (*takedown)(struct drm_device *dev);
  243. void (*set_region_tiling)(struct drm_device *dev, int i, uint32_t addr,
  244. uint32_t size, uint32_t pitch);
  245. };
  246. struct nouveau_fifo_engine {
  247. void *priv;
  248. int channels;
  249. int (*init)(struct drm_device *);
  250. void (*takedown)(struct drm_device *);
  251. void (*disable)(struct drm_device *);
  252. void (*enable)(struct drm_device *);
  253. bool (*reassign)(struct drm_device *, bool enable);
  254. bool (*cache_flush)(struct drm_device *dev);
  255. bool (*cache_pull)(struct drm_device *dev, bool enable);
  256. int (*channel_id)(struct drm_device *);
  257. int (*create_context)(struct nouveau_channel *);
  258. void (*destroy_context)(struct nouveau_channel *);
  259. int (*load_context)(struct nouveau_channel *);
  260. int (*unload_context)(struct drm_device *);
  261. };
  262. struct nouveau_pgraph_object_method {
  263. int id;
  264. int (*exec)(struct nouveau_channel *chan, int grclass, int mthd,
  265. uint32_t data);
  266. };
  267. struct nouveau_pgraph_object_class {
  268. int id;
  269. bool software;
  270. struct nouveau_pgraph_object_method *methods;
  271. };
  272. struct nouveau_pgraph_engine {
  273. struct nouveau_pgraph_object_class *grclass;
  274. bool accel_blocked;
  275. void *ctxprog;
  276. void *ctxvals;
  277. int grctx_size;
  278. int (*init)(struct drm_device *);
  279. void (*takedown)(struct drm_device *);
  280. void (*fifo_access)(struct drm_device *, bool);
  281. struct nouveau_channel *(*channel)(struct drm_device *);
  282. int (*create_context)(struct nouveau_channel *);
  283. void (*destroy_context)(struct nouveau_channel *);
  284. int (*load_context)(struct nouveau_channel *);
  285. int (*unload_context)(struct drm_device *);
  286. void (*set_region_tiling)(struct drm_device *dev, int i, uint32_t addr,
  287. uint32_t size, uint32_t pitch);
  288. };
  289. struct nouveau_engine {
  290. struct nouveau_instmem_engine instmem;
  291. struct nouveau_mc_engine mc;
  292. struct nouveau_timer_engine timer;
  293. struct nouveau_fb_engine fb;
  294. struct nouveau_pgraph_engine graph;
  295. struct nouveau_fifo_engine fifo;
  296. };
  297. struct nouveau_pll_vals {
  298. union {
  299. struct {
  300. #ifdef __BIG_ENDIAN
  301. uint8_t N1, M1, N2, M2;
  302. #else
  303. uint8_t M1, N1, M2, N2;
  304. #endif
  305. };
  306. struct {
  307. uint16_t NM1, NM2;
  308. } __attribute__((packed));
  309. };
  310. int log2P;
  311. int refclk;
  312. };
  313. enum nv04_fp_display_regs {
  314. FP_DISPLAY_END,
  315. FP_TOTAL,
  316. FP_CRTC,
  317. FP_SYNC_START,
  318. FP_SYNC_END,
  319. FP_VALID_START,
  320. FP_VALID_END
  321. };
  322. struct nv04_crtc_reg {
  323. unsigned char MiscOutReg; /* */
  324. uint8_t CRTC[0x9f];
  325. uint8_t CR58[0x10];
  326. uint8_t Sequencer[5];
  327. uint8_t Graphics[9];
  328. uint8_t Attribute[21];
  329. unsigned char DAC[768]; /* Internal Colorlookuptable */
  330. /* PCRTC regs */
  331. uint32_t fb_start;
  332. uint32_t crtc_cfg;
  333. uint32_t cursor_cfg;
  334. uint32_t gpio_ext;
  335. uint32_t crtc_830;
  336. uint32_t crtc_834;
  337. uint32_t crtc_850;
  338. uint32_t crtc_eng_ctrl;
  339. /* PRAMDAC regs */
  340. uint32_t nv10_cursync;
  341. struct nouveau_pll_vals pllvals;
  342. uint32_t ramdac_gen_ctrl;
  343. uint32_t ramdac_630;
  344. uint32_t ramdac_634;
  345. uint32_t tv_setup;
  346. uint32_t tv_vtotal;
  347. uint32_t tv_vskew;
  348. uint32_t tv_vsync_delay;
  349. uint32_t tv_htotal;
  350. uint32_t tv_hskew;
  351. uint32_t tv_hsync_delay;
  352. uint32_t tv_hsync_delay2;
  353. uint32_t fp_horiz_regs[7];
  354. uint32_t fp_vert_regs[7];
  355. uint32_t dither;
  356. uint32_t fp_control;
  357. uint32_t dither_regs[6];
  358. uint32_t fp_debug_0;
  359. uint32_t fp_debug_1;
  360. uint32_t fp_debug_2;
  361. uint32_t fp_margin_color;
  362. uint32_t ramdac_8c0;
  363. uint32_t ramdac_a20;
  364. uint32_t ramdac_a24;
  365. uint32_t ramdac_a34;
  366. uint32_t ctv_regs[38];
  367. };
  368. struct nv04_output_reg {
  369. uint32_t output;
  370. int head;
  371. };
  372. struct nv04_mode_state {
  373. uint32_t bpp;
  374. uint32_t width;
  375. uint32_t height;
  376. uint32_t interlace;
  377. uint32_t repaint0;
  378. uint32_t repaint1;
  379. uint32_t screen;
  380. uint32_t scale;
  381. uint32_t dither;
  382. uint32_t extra;
  383. uint32_t fifo;
  384. uint32_t pixel;
  385. uint32_t horiz;
  386. int arbitration0;
  387. int arbitration1;
  388. uint32_t pll;
  389. uint32_t pllB;
  390. uint32_t vpll;
  391. uint32_t vpll2;
  392. uint32_t vpllB;
  393. uint32_t vpll2B;
  394. uint32_t pllsel;
  395. uint32_t sel_clk;
  396. uint32_t general;
  397. uint32_t crtcOwner;
  398. uint32_t head;
  399. uint32_t head2;
  400. uint32_t cursorConfig;
  401. uint32_t cursor0;
  402. uint32_t cursor1;
  403. uint32_t cursor2;
  404. uint32_t timingH;
  405. uint32_t timingV;
  406. uint32_t displayV;
  407. uint32_t crtcSync;
  408. struct nv04_crtc_reg crtc_reg[2];
  409. };
  410. enum nouveau_card_type {
  411. NV_04 = 0x00,
  412. NV_10 = 0x10,
  413. NV_20 = 0x20,
  414. NV_30 = 0x30,
  415. NV_40 = 0x40,
  416. NV_50 = 0x50,
  417. };
  418. struct drm_nouveau_private {
  419. struct drm_device *dev;
  420. enum {
  421. NOUVEAU_CARD_INIT_DOWN,
  422. NOUVEAU_CARD_INIT_DONE,
  423. NOUVEAU_CARD_INIT_FAILED
  424. } init_state;
  425. /* the card type, takes NV_* as values */
  426. enum nouveau_card_type card_type;
  427. /* exact chipset, derived from NV_PMC_BOOT_0 */
  428. int chipset;
  429. int flags;
  430. void __iomem *mmio;
  431. void __iomem *ramin;
  432. uint32_t ramin_size;
  433. struct nouveau_bo *vga_ram;
  434. struct workqueue_struct *wq;
  435. struct work_struct irq_work;
  436. struct list_head vbl_waiting;
  437. struct {
  438. struct ttm_global_reference mem_global_ref;
  439. struct ttm_bo_global_ref bo_global_ref;
  440. struct ttm_bo_device bdev;
  441. spinlock_t bo_list_lock;
  442. struct list_head bo_list;
  443. atomic_t validate_sequence;
  444. } ttm;
  445. struct fb_info *fbdev_info;
  446. int fifo_alloc_count;
  447. struct nouveau_channel *fifos[NOUVEAU_MAX_CHANNEL_NR];
  448. struct nouveau_engine engine;
  449. struct nouveau_channel *channel;
  450. /* For PFIFO and PGRAPH. */
  451. spinlock_t context_switch_lock;
  452. /* RAMIN configuration, RAMFC, RAMHT and RAMRO offsets */
  453. struct nouveau_gpuobj *ramht;
  454. uint32_t ramin_rsvd_vram;
  455. uint32_t ramht_offset;
  456. uint32_t ramht_size;
  457. uint32_t ramht_bits;
  458. uint32_t ramfc_offset;
  459. uint32_t ramfc_size;
  460. uint32_t ramro_offset;
  461. uint32_t ramro_size;
  462. /* base physical adresses */
  463. uint64_t fb_phys;
  464. uint64_t fb_available_size;
  465. uint64_t fb_mappable_pages;
  466. uint64_t fb_aper_free;
  467. struct {
  468. enum {
  469. NOUVEAU_GART_NONE = 0,
  470. NOUVEAU_GART_AGP,
  471. NOUVEAU_GART_SGDMA
  472. } type;
  473. uint64_t aper_base;
  474. uint64_t aper_size;
  475. uint64_t aper_free;
  476. struct nouveau_gpuobj *sg_ctxdma;
  477. struct page *sg_dummy_page;
  478. dma_addr_t sg_dummy_bus;
  479. /* nottm hack */
  480. struct drm_ttm_backend *sg_be;
  481. unsigned long sg_handle;
  482. } gart_info;
  483. /* nv10-nv40 tiling regions */
  484. struct {
  485. struct nouveau_tile_reg reg[NOUVEAU_MAX_TILE_NR];
  486. spinlock_t lock;
  487. } tile;
  488. /* G8x/G9x virtual address space */
  489. uint64_t vm_gart_base;
  490. uint64_t vm_gart_size;
  491. uint64_t vm_vram_base;
  492. uint64_t vm_vram_size;
  493. uint64_t vm_end;
  494. struct nouveau_gpuobj *vm_vram_pt[NV50_VM_VRAM_NR];
  495. int vm_vram_pt_nr;
  496. uint64_t vram_sys_base;
  497. /* the mtrr covering the FB */
  498. int fb_mtrr;
  499. struct mem_block *ramin_heap;
  500. /* context table pointed to be NV_PGRAPH_CHANNEL_CTX_TABLE (0x400780) */
  501. uint32_t ctx_table_size;
  502. struct nouveau_gpuobj_ref *ctx_table;
  503. struct list_head gpuobj_list;
  504. struct nvbios vbios;
  505. struct nv04_mode_state mode_reg;
  506. struct nv04_mode_state saved_reg;
  507. uint32_t saved_vga_font[4][16384];
  508. uint32_t crtc_owner;
  509. uint32_t dac_users[4];
  510. struct nouveau_suspend_resume {
  511. uint32_t fifo_mode;
  512. uint32_t graph_ctx_control;
  513. uint32_t graph_state;
  514. uint32_t *ramin_copy;
  515. uint64_t ramin_size;
  516. } susres;
  517. struct backlight_device *backlight;
  518. struct nouveau_channel *evo;
  519. struct {
  520. struct dentry *channel_root;
  521. } debugfs;
  522. };
  523. static inline struct drm_nouveau_private *
  524. nouveau_bdev(struct ttm_bo_device *bd)
  525. {
  526. return container_of(bd, struct drm_nouveau_private, ttm.bdev);
  527. }
  528. static inline int
  529. nouveau_bo_ref(struct nouveau_bo *ref, struct nouveau_bo **pnvbo)
  530. {
  531. struct nouveau_bo *prev;
  532. if (!pnvbo)
  533. return -EINVAL;
  534. prev = *pnvbo;
  535. *pnvbo = ref ? nouveau_bo(ttm_bo_reference(&ref->bo)) : NULL;
  536. if (prev) {
  537. struct ttm_buffer_object *bo = &prev->bo;
  538. ttm_bo_unref(&bo);
  539. }
  540. return 0;
  541. }
  542. #define NOUVEAU_CHECK_INITIALISED_WITH_RETURN do { \
  543. struct drm_nouveau_private *nv = dev->dev_private; \
  544. if (nv->init_state != NOUVEAU_CARD_INIT_DONE) { \
  545. NV_ERROR(dev, "called without init\n"); \
  546. return -EINVAL; \
  547. } \
  548. } while (0)
  549. #define NOUVEAU_GET_USER_CHANNEL_WITH_RETURN(id, cl, ch) do { \
  550. struct drm_nouveau_private *nv = dev->dev_private; \
  551. if (!nouveau_channel_owner(dev, (cl), (id))) { \
  552. NV_ERROR(dev, "pid %d doesn't own channel %d\n", \
  553. DRM_CURRENTPID, (id)); \
  554. return -EPERM; \
  555. } \
  556. (ch) = nv->fifos[(id)]; \
  557. } while (0)
  558. /* nouveau_drv.c */
  559. extern int nouveau_noagp;
  560. extern int nouveau_duallink;
  561. extern int nouveau_uscript_lvds;
  562. extern int nouveau_uscript_tmds;
  563. extern int nouveau_vram_pushbuf;
  564. extern int nouveau_vram_notify;
  565. extern int nouveau_fbpercrtc;
  566. extern char *nouveau_tv_norm;
  567. extern int nouveau_reg_debug;
  568. extern char *nouveau_vbios;
  569. extern int nouveau_ctxfw;
  570. extern int nouveau_ignorelid;
  571. extern int nouveau_nofbaccel;
  572. extern int nouveau_noaccel;
  573. extern int nouveau_pci_suspend(struct pci_dev *pdev, pm_message_t pm_state);
  574. extern int nouveau_pci_resume(struct pci_dev *pdev);
  575. /* nouveau_state.c */
  576. extern void nouveau_preclose(struct drm_device *dev, struct drm_file *);
  577. extern int nouveau_load(struct drm_device *, unsigned long flags);
  578. extern int nouveau_firstopen(struct drm_device *);
  579. extern void nouveau_lastclose(struct drm_device *);
  580. extern int nouveau_unload(struct drm_device *);
  581. extern int nouveau_ioctl_getparam(struct drm_device *, void *data,
  582. struct drm_file *);
  583. extern int nouveau_ioctl_setparam(struct drm_device *, void *data,
  584. struct drm_file *);
  585. extern bool nouveau_wait_until(struct drm_device *, uint64_t timeout,
  586. uint32_t reg, uint32_t mask, uint32_t val);
  587. extern bool nouveau_wait_for_idle(struct drm_device *);
  588. extern int nouveau_card_init(struct drm_device *);
  589. /* nouveau_mem.c */
  590. extern int nouveau_mem_init_heap(struct mem_block **, uint64_t start,
  591. uint64_t size);
  592. extern struct mem_block *nouveau_mem_alloc_block(struct mem_block *,
  593. uint64_t size, int align2,
  594. struct drm_file *, int tail);
  595. extern void nouveau_mem_takedown(struct mem_block **heap);
  596. extern void nouveau_mem_free_block(struct mem_block *);
  597. extern uint64_t nouveau_mem_fb_amount(struct drm_device *);
  598. extern void nouveau_mem_release(struct drm_file *, struct mem_block *heap);
  599. extern int nouveau_mem_init(struct drm_device *);
  600. extern int nouveau_mem_init_agp(struct drm_device *);
  601. extern void nouveau_mem_close(struct drm_device *);
  602. extern struct nouveau_tile_reg *nv10_mem_set_tiling(struct drm_device *dev,
  603. uint32_t addr,
  604. uint32_t size,
  605. uint32_t pitch);
  606. extern void nv10_mem_expire_tiling(struct drm_device *dev,
  607. struct nouveau_tile_reg *tile,
  608. struct nouveau_fence *fence);
  609. extern int nv50_mem_vm_bind_linear(struct drm_device *, uint64_t virt,
  610. uint32_t size, uint32_t flags,
  611. uint64_t phys);
  612. extern void nv50_mem_vm_unbind(struct drm_device *, uint64_t virt,
  613. uint32_t size);
  614. /* nouveau_notifier.c */
  615. extern int nouveau_notifier_init_channel(struct nouveau_channel *);
  616. extern void nouveau_notifier_takedown_channel(struct nouveau_channel *);
  617. extern int nouveau_notifier_alloc(struct nouveau_channel *, uint32_t handle,
  618. int cout, uint32_t *offset);
  619. extern int nouveau_notifier_offset(struct nouveau_gpuobj *, uint32_t *);
  620. extern int nouveau_ioctl_notifier_alloc(struct drm_device *, void *data,
  621. struct drm_file *);
  622. extern int nouveau_ioctl_notifier_free(struct drm_device *, void *data,
  623. struct drm_file *);
  624. /* nouveau_channel.c */
  625. extern struct drm_ioctl_desc nouveau_ioctls[];
  626. extern int nouveau_max_ioctl;
  627. extern void nouveau_channel_cleanup(struct drm_device *, struct drm_file *);
  628. extern int nouveau_channel_owner(struct drm_device *, struct drm_file *,
  629. int channel);
  630. extern int nouveau_channel_alloc(struct drm_device *dev,
  631. struct nouveau_channel **chan,
  632. struct drm_file *file_priv,
  633. uint32_t fb_ctxdma, uint32_t tt_ctxdma);
  634. extern void nouveau_channel_free(struct nouveau_channel *);
  635. /* nouveau_object.c */
  636. extern int nouveau_gpuobj_early_init(struct drm_device *);
  637. extern int nouveau_gpuobj_init(struct drm_device *);
  638. extern void nouveau_gpuobj_takedown(struct drm_device *);
  639. extern void nouveau_gpuobj_late_takedown(struct drm_device *);
  640. extern int nouveau_gpuobj_suspend(struct drm_device *dev);
  641. extern void nouveau_gpuobj_suspend_cleanup(struct drm_device *dev);
  642. extern void nouveau_gpuobj_resume(struct drm_device *dev);
  643. extern int nouveau_gpuobj_channel_init(struct nouveau_channel *,
  644. uint32_t vram_h, uint32_t tt_h);
  645. extern void nouveau_gpuobj_channel_takedown(struct nouveau_channel *);
  646. extern int nouveau_gpuobj_new(struct drm_device *, struct nouveau_channel *,
  647. uint32_t size, int align, uint32_t flags,
  648. struct nouveau_gpuobj **);
  649. extern int nouveau_gpuobj_del(struct drm_device *, struct nouveau_gpuobj **);
  650. extern int nouveau_gpuobj_ref_add(struct drm_device *, struct nouveau_channel *,
  651. uint32_t handle, struct nouveau_gpuobj *,
  652. struct nouveau_gpuobj_ref **);
  653. extern int nouveau_gpuobj_ref_del(struct drm_device *,
  654. struct nouveau_gpuobj_ref **);
  655. extern int nouveau_gpuobj_ref_find(struct nouveau_channel *, uint32_t handle,
  656. struct nouveau_gpuobj_ref **ref_ret);
  657. extern int nouveau_gpuobj_new_ref(struct drm_device *,
  658. struct nouveau_channel *alloc_chan,
  659. struct nouveau_channel *ref_chan,
  660. uint32_t handle, uint32_t size, int align,
  661. uint32_t flags, struct nouveau_gpuobj_ref **);
  662. extern int nouveau_gpuobj_new_fake(struct drm_device *,
  663. uint32_t p_offset, uint32_t b_offset,
  664. uint32_t size, uint32_t flags,
  665. struct nouveau_gpuobj **,
  666. struct nouveau_gpuobj_ref**);
  667. extern int nouveau_gpuobj_dma_new(struct nouveau_channel *, int class,
  668. uint64_t offset, uint64_t size, int access,
  669. int target, struct nouveau_gpuobj **);
  670. extern int nouveau_gpuobj_gart_dma_new(struct nouveau_channel *,
  671. uint64_t offset, uint64_t size,
  672. int access, struct nouveau_gpuobj **,
  673. uint32_t *o_ret);
  674. extern int nouveau_gpuobj_gr_new(struct nouveau_channel *, int class,
  675. struct nouveau_gpuobj **);
  676. extern int nouveau_gpuobj_sw_new(struct nouveau_channel *, int class,
  677. struct nouveau_gpuobj **);
  678. extern int nouveau_ioctl_grobj_alloc(struct drm_device *, void *data,
  679. struct drm_file *);
  680. extern int nouveau_ioctl_gpuobj_free(struct drm_device *, void *data,
  681. struct drm_file *);
  682. /* nouveau_irq.c */
  683. extern irqreturn_t nouveau_irq_handler(DRM_IRQ_ARGS);
  684. extern void nouveau_irq_preinstall(struct drm_device *);
  685. extern int nouveau_irq_postinstall(struct drm_device *);
  686. extern void nouveau_irq_uninstall(struct drm_device *);
  687. /* nouveau_sgdma.c */
  688. extern int nouveau_sgdma_init(struct drm_device *);
  689. extern void nouveau_sgdma_takedown(struct drm_device *);
  690. extern int nouveau_sgdma_get_page(struct drm_device *, uint32_t offset,
  691. uint32_t *page);
  692. extern struct ttm_backend *nouveau_sgdma_init_ttm(struct drm_device *);
  693. /* nouveau_debugfs.c */
  694. #if defined(CONFIG_DRM_NOUVEAU_DEBUG)
  695. extern int nouveau_debugfs_init(struct drm_minor *);
  696. extern void nouveau_debugfs_takedown(struct drm_minor *);
  697. extern int nouveau_debugfs_channel_init(struct nouveau_channel *);
  698. extern void nouveau_debugfs_channel_fini(struct nouveau_channel *);
  699. #else
  700. static inline int
  701. nouveau_debugfs_init(struct drm_minor *minor)
  702. {
  703. return 0;
  704. }
  705. static inline void nouveau_debugfs_takedown(struct drm_minor *minor)
  706. {
  707. }
  708. static inline int
  709. nouveau_debugfs_channel_init(struct nouveau_channel *chan)
  710. {
  711. return 0;
  712. }
  713. static inline void
  714. nouveau_debugfs_channel_fini(struct nouveau_channel *chan)
  715. {
  716. }
  717. #endif
  718. /* nouveau_dma.c */
  719. extern void nouveau_dma_pre_init(struct nouveau_channel *);
  720. extern int nouveau_dma_init(struct nouveau_channel *);
  721. extern int nouveau_dma_wait(struct nouveau_channel *, int slots, int size);
  722. /* nouveau_acpi.c */
  723. #if defined(CONFIG_ACPI)
  724. void nouveau_register_dsm_handler(void);
  725. void nouveau_unregister_dsm_handler(void);
  726. #else
  727. static inline void nouveau_register_dsm_handler(void) {}
  728. static inline void nouveau_unregister_dsm_handler(void) {}
  729. #endif
  730. /* nouveau_backlight.c */
  731. #ifdef CONFIG_DRM_NOUVEAU_BACKLIGHT
  732. extern int nouveau_backlight_init(struct drm_device *);
  733. extern void nouveau_backlight_exit(struct drm_device *);
  734. #else
  735. static inline int nouveau_backlight_init(struct drm_device *dev)
  736. {
  737. return 0;
  738. }
  739. static inline void nouveau_backlight_exit(struct drm_device *dev) { }
  740. #endif
  741. /* nouveau_bios.c */
  742. extern int nouveau_bios_init(struct drm_device *);
  743. extern void nouveau_bios_takedown(struct drm_device *dev);
  744. extern int nouveau_run_vbios_init(struct drm_device *);
  745. extern void nouveau_bios_run_init_table(struct drm_device *, uint16_t table,
  746. struct dcb_entry *);
  747. extern struct dcb_gpio_entry *nouveau_bios_gpio_entry(struct drm_device *,
  748. enum dcb_gpio_tag);
  749. extern struct dcb_connector_table_entry *
  750. nouveau_bios_connector_entry(struct drm_device *, int index);
  751. extern int get_pll_limits(struct drm_device *, uint32_t limit_match,
  752. struct pll_lims *);
  753. extern int nouveau_bios_run_display_table(struct drm_device *,
  754. struct dcb_entry *,
  755. uint32_t script, int pxclk);
  756. extern void *nouveau_bios_dp_table(struct drm_device *, struct dcb_entry *,
  757. int *length);
  758. extern bool nouveau_bios_fp_mode(struct drm_device *, struct drm_display_mode *);
  759. extern uint8_t *nouveau_bios_embedded_edid(struct drm_device *);
  760. extern int nouveau_bios_parse_lvds_table(struct drm_device *, int pxclk,
  761. bool *dl, bool *if_is_24bit);
  762. extern int run_tmds_table(struct drm_device *, struct dcb_entry *,
  763. int head, int pxclk);
  764. extern int call_lvds_script(struct drm_device *, struct dcb_entry *, int head,
  765. enum LVDS_script, int pxclk);
  766. /* nouveau_ttm.c */
  767. int nouveau_ttm_global_init(struct drm_nouveau_private *);
  768. void nouveau_ttm_global_release(struct drm_nouveau_private *);
  769. int nouveau_ttm_mmap(struct file *, struct vm_area_struct *);
  770. /* nouveau_dp.c */
  771. int nouveau_dp_auxch(struct nouveau_i2c_chan *auxch, int cmd, int addr,
  772. uint8_t *data, int data_nr);
  773. bool nouveau_dp_detect(struct drm_encoder *);
  774. bool nouveau_dp_link_train(struct drm_encoder *);
  775. /* nv04_fb.c */
  776. extern int nv04_fb_init(struct drm_device *);
  777. extern void nv04_fb_takedown(struct drm_device *);
  778. /* nv10_fb.c */
  779. extern int nv10_fb_init(struct drm_device *);
  780. extern void nv10_fb_takedown(struct drm_device *);
  781. extern void nv10_fb_set_region_tiling(struct drm_device *, int, uint32_t,
  782. uint32_t, uint32_t);
  783. /* nv40_fb.c */
  784. extern int nv40_fb_init(struct drm_device *);
  785. extern void nv40_fb_takedown(struct drm_device *);
  786. extern void nv40_fb_set_region_tiling(struct drm_device *, int, uint32_t,
  787. uint32_t, uint32_t);
  788. /* nv04_fifo.c */
  789. extern int nv04_fifo_init(struct drm_device *);
  790. extern void nv04_fifo_disable(struct drm_device *);
  791. extern void nv04_fifo_enable(struct drm_device *);
  792. extern bool nv04_fifo_reassign(struct drm_device *, bool);
  793. extern bool nv04_fifo_cache_flush(struct drm_device *);
  794. extern bool nv04_fifo_cache_pull(struct drm_device *, bool);
  795. extern int nv04_fifo_channel_id(struct drm_device *);
  796. extern int nv04_fifo_create_context(struct nouveau_channel *);
  797. extern void nv04_fifo_destroy_context(struct nouveau_channel *);
  798. extern int nv04_fifo_load_context(struct nouveau_channel *);
  799. extern int nv04_fifo_unload_context(struct drm_device *);
  800. /* nv10_fifo.c */
  801. extern int nv10_fifo_init(struct drm_device *);
  802. extern int nv10_fifo_channel_id(struct drm_device *);
  803. extern int nv10_fifo_create_context(struct nouveau_channel *);
  804. extern void nv10_fifo_destroy_context(struct nouveau_channel *);
  805. extern int nv10_fifo_load_context(struct nouveau_channel *);
  806. extern int nv10_fifo_unload_context(struct drm_device *);
  807. /* nv40_fifo.c */
  808. extern int nv40_fifo_init(struct drm_device *);
  809. extern int nv40_fifo_create_context(struct nouveau_channel *);
  810. extern void nv40_fifo_destroy_context(struct nouveau_channel *);
  811. extern int nv40_fifo_load_context(struct nouveau_channel *);
  812. extern int nv40_fifo_unload_context(struct drm_device *);
  813. /* nv50_fifo.c */
  814. extern int nv50_fifo_init(struct drm_device *);
  815. extern void nv50_fifo_takedown(struct drm_device *);
  816. extern int nv50_fifo_channel_id(struct drm_device *);
  817. extern int nv50_fifo_create_context(struct nouveau_channel *);
  818. extern void nv50_fifo_destroy_context(struct nouveau_channel *);
  819. extern int nv50_fifo_load_context(struct nouveau_channel *);
  820. extern int nv50_fifo_unload_context(struct drm_device *);
  821. /* nv04_graph.c */
  822. extern struct nouveau_pgraph_object_class nv04_graph_grclass[];
  823. extern int nv04_graph_init(struct drm_device *);
  824. extern void nv04_graph_takedown(struct drm_device *);
  825. extern void nv04_graph_fifo_access(struct drm_device *, bool);
  826. extern struct nouveau_channel *nv04_graph_channel(struct drm_device *);
  827. extern int nv04_graph_create_context(struct nouveau_channel *);
  828. extern void nv04_graph_destroy_context(struct nouveau_channel *);
  829. extern int nv04_graph_load_context(struct nouveau_channel *);
  830. extern int nv04_graph_unload_context(struct drm_device *);
  831. extern void nv04_graph_context_switch(struct drm_device *);
  832. /* nv10_graph.c */
  833. extern struct nouveau_pgraph_object_class nv10_graph_grclass[];
  834. extern int nv10_graph_init(struct drm_device *);
  835. extern void nv10_graph_takedown(struct drm_device *);
  836. extern struct nouveau_channel *nv10_graph_channel(struct drm_device *);
  837. extern int nv10_graph_create_context(struct nouveau_channel *);
  838. extern void nv10_graph_destroy_context(struct nouveau_channel *);
  839. extern int nv10_graph_load_context(struct nouveau_channel *);
  840. extern int nv10_graph_unload_context(struct drm_device *);
  841. extern void nv10_graph_context_switch(struct drm_device *);
  842. extern void nv10_graph_set_region_tiling(struct drm_device *, int, uint32_t,
  843. uint32_t, uint32_t);
  844. /* nv20_graph.c */
  845. extern struct nouveau_pgraph_object_class nv20_graph_grclass[];
  846. extern struct nouveau_pgraph_object_class nv30_graph_grclass[];
  847. extern int nv20_graph_create_context(struct nouveau_channel *);
  848. extern void nv20_graph_destroy_context(struct nouveau_channel *);
  849. extern int nv20_graph_load_context(struct nouveau_channel *);
  850. extern int nv20_graph_unload_context(struct drm_device *);
  851. extern int nv20_graph_init(struct drm_device *);
  852. extern void nv20_graph_takedown(struct drm_device *);
  853. extern int nv30_graph_init(struct drm_device *);
  854. extern void nv20_graph_set_region_tiling(struct drm_device *, int, uint32_t,
  855. uint32_t, uint32_t);
  856. /* nv40_graph.c */
  857. extern struct nouveau_pgraph_object_class nv40_graph_grclass[];
  858. extern int nv40_graph_init(struct drm_device *);
  859. extern void nv40_graph_takedown(struct drm_device *);
  860. extern struct nouveau_channel *nv40_graph_channel(struct drm_device *);
  861. extern int nv40_graph_create_context(struct nouveau_channel *);
  862. extern void nv40_graph_destroy_context(struct nouveau_channel *);
  863. extern int nv40_graph_load_context(struct nouveau_channel *);
  864. extern int nv40_graph_unload_context(struct drm_device *);
  865. extern void nv40_grctx_init(struct nouveau_grctx *);
  866. extern void nv40_graph_set_region_tiling(struct drm_device *, int, uint32_t,
  867. uint32_t, uint32_t);
  868. /* nv50_graph.c */
  869. extern struct nouveau_pgraph_object_class nv50_graph_grclass[];
  870. extern int nv50_graph_init(struct drm_device *);
  871. extern void nv50_graph_takedown(struct drm_device *);
  872. extern void nv50_graph_fifo_access(struct drm_device *, bool);
  873. extern struct nouveau_channel *nv50_graph_channel(struct drm_device *);
  874. extern int nv50_graph_create_context(struct nouveau_channel *);
  875. extern void nv50_graph_destroy_context(struct nouveau_channel *);
  876. extern int nv50_graph_load_context(struct nouveau_channel *);
  877. extern int nv50_graph_unload_context(struct drm_device *);
  878. extern void nv50_graph_context_switch(struct drm_device *);
  879. extern int nv50_grctx_init(struct nouveau_grctx *);
  880. /* nouveau_grctx.c */
  881. extern int nouveau_grctx_prog_load(struct drm_device *);
  882. extern void nouveau_grctx_vals_load(struct drm_device *,
  883. struct nouveau_gpuobj *);
  884. extern void nouveau_grctx_fini(struct drm_device *);
  885. /* nv04_instmem.c */
  886. extern int nv04_instmem_init(struct drm_device *);
  887. extern void nv04_instmem_takedown(struct drm_device *);
  888. extern int nv04_instmem_suspend(struct drm_device *);
  889. extern void nv04_instmem_resume(struct drm_device *);
  890. extern int nv04_instmem_populate(struct drm_device *, struct nouveau_gpuobj *,
  891. uint32_t *size);
  892. extern void nv04_instmem_clear(struct drm_device *, struct nouveau_gpuobj *);
  893. extern int nv04_instmem_bind(struct drm_device *, struct nouveau_gpuobj *);
  894. extern int nv04_instmem_unbind(struct drm_device *, struct nouveau_gpuobj *);
  895. extern void nv04_instmem_prepare_access(struct drm_device *, bool write);
  896. extern void nv04_instmem_finish_access(struct drm_device *);
  897. /* nv50_instmem.c */
  898. extern int nv50_instmem_init(struct drm_device *);
  899. extern void nv50_instmem_takedown(struct drm_device *);
  900. extern int nv50_instmem_suspend(struct drm_device *);
  901. extern void nv50_instmem_resume(struct drm_device *);
  902. extern int nv50_instmem_populate(struct drm_device *, struct nouveau_gpuobj *,
  903. uint32_t *size);
  904. extern void nv50_instmem_clear(struct drm_device *, struct nouveau_gpuobj *);
  905. extern int nv50_instmem_bind(struct drm_device *, struct nouveau_gpuobj *);
  906. extern int nv50_instmem_unbind(struct drm_device *, struct nouveau_gpuobj *);
  907. extern void nv50_instmem_prepare_access(struct drm_device *, bool write);
  908. extern void nv50_instmem_finish_access(struct drm_device *);
  909. /* nv04_mc.c */
  910. extern int nv04_mc_init(struct drm_device *);
  911. extern void nv04_mc_takedown(struct drm_device *);
  912. /* nv40_mc.c */
  913. extern int nv40_mc_init(struct drm_device *);
  914. extern void nv40_mc_takedown(struct drm_device *);
  915. /* nv50_mc.c */
  916. extern int nv50_mc_init(struct drm_device *);
  917. extern void nv50_mc_takedown(struct drm_device *);
  918. /* nv04_timer.c */
  919. extern int nv04_timer_init(struct drm_device *);
  920. extern uint64_t nv04_timer_read(struct drm_device *);
  921. extern void nv04_timer_takedown(struct drm_device *);
  922. extern long nouveau_compat_ioctl(struct file *file, unsigned int cmd,
  923. unsigned long arg);
  924. /* nv04_dac.c */
  925. extern int nv04_dac_create(struct drm_device *dev, struct dcb_entry *entry);
  926. extern uint32_t nv17_dac_sample_load(struct drm_encoder *encoder);
  927. extern int nv04_dac_output_offset(struct drm_encoder *encoder);
  928. extern void nv04_dac_update_dacclk(struct drm_encoder *encoder, bool enable);
  929. /* nv04_dfp.c */
  930. extern int nv04_dfp_create(struct drm_device *dev, struct dcb_entry *entry);
  931. extern int nv04_dfp_get_bound_head(struct drm_device *dev, struct dcb_entry *dcbent);
  932. extern void nv04_dfp_bind_head(struct drm_device *dev, struct dcb_entry *dcbent,
  933. int head, bool dl);
  934. extern void nv04_dfp_disable(struct drm_device *dev, int head);
  935. extern void nv04_dfp_update_fp_control(struct drm_encoder *encoder, int mode);
  936. /* nv04_tv.c */
  937. extern int nv04_tv_identify(struct drm_device *dev, int i2c_index);
  938. extern int nv04_tv_create(struct drm_device *dev, struct dcb_entry *entry);
  939. /* nv17_tv.c */
  940. extern int nv17_tv_create(struct drm_device *dev, struct dcb_entry *entry);
  941. /* nv04_display.c */
  942. extern int nv04_display_create(struct drm_device *);
  943. extern void nv04_display_destroy(struct drm_device *);
  944. extern void nv04_display_restore(struct drm_device *);
  945. /* nv04_crtc.c */
  946. extern int nv04_crtc_create(struct drm_device *, int index);
  947. /* nouveau_bo.c */
  948. extern struct ttm_bo_driver nouveau_bo_driver;
  949. extern int nouveau_bo_new(struct drm_device *, struct nouveau_channel *,
  950. int size, int align, uint32_t flags,
  951. uint32_t tile_mode, uint32_t tile_flags,
  952. bool no_vm, bool mappable, struct nouveau_bo **);
  953. extern int nouveau_bo_pin(struct nouveau_bo *, uint32_t flags);
  954. extern int nouveau_bo_unpin(struct nouveau_bo *);
  955. extern int nouveau_bo_map(struct nouveau_bo *);
  956. extern void nouveau_bo_unmap(struct nouveau_bo *);
  957. extern void nouveau_bo_placement_set(struct nouveau_bo *, uint32_t memtype);
  958. extern u16 nouveau_bo_rd16(struct nouveau_bo *nvbo, unsigned index);
  959. extern void nouveau_bo_wr16(struct nouveau_bo *nvbo, unsigned index, u16 val);
  960. extern u32 nouveau_bo_rd32(struct nouveau_bo *nvbo, unsigned index);
  961. extern void nouveau_bo_wr32(struct nouveau_bo *nvbo, unsigned index, u32 val);
  962. /* nouveau_fence.c */
  963. struct nouveau_fence;
  964. extern int nouveau_fence_init(struct nouveau_channel *);
  965. extern void nouveau_fence_fini(struct nouveau_channel *);
  966. extern void nouveau_fence_update(struct nouveau_channel *);
  967. extern int nouveau_fence_new(struct nouveau_channel *, struct nouveau_fence **,
  968. bool emit);
  969. extern int nouveau_fence_emit(struct nouveau_fence *);
  970. struct nouveau_channel *nouveau_fence_channel(struct nouveau_fence *);
  971. extern bool nouveau_fence_signalled(void *obj, void *arg);
  972. extern int nouveau_fence_wait(void *obj, void *arg, bool lazy, bool intr);
  973. extern int nouveau_fence_flush(void *obj, void *arg);
  974. extern void nouveau_fence_unref(void **obj);
  975. extern void *nouveau_fence_ref(void *obj);
  976. extern void nouveau_fence_handler(struct drm_device *dev, int channel);
  977. /* nouveau_gem.c */
  978. extern int nouveau_gem_new(struct drm_device *, struct nouveau_channel *,
  979. int size, int align, uint32_t flags,
  980. uint32_t tile_mode, uint32_t tile_flags,
  981. bool no_vm, bool mappable, struct nouveau_bo **);
  982. extern int nouveau_gem_object_new(struct drm_gem_object *);
  983. extern void nouveau_gem_object_del(struct drm_gem_object *);
  984. extern int nouveau_gem_ioctl_new(struct drm_device *, void *,
  985. struct drm_file *);
  986. extern int nouveau_gem_ioctl_pushbuf(struct drm_device *, void *,
  987. struct drm_file *);
  988. extern int nouveau_gem_ioctl_cpu_prep(struct drm_device *, void *,
  989. struct drm_file *);
  990. extern int nouveau_gem_ioctl_cpu_fini(struct drm_device *, void *,
  991. struct drm_file *);
  992. extern int nouveau_gem_ioctl_info(struct drm_device *, void *,
  993. struct drm_file *);
  994. /* nv17_gpio.c */
  995. int nv17_gpio_get(struct drm_device *dev, enum dcb_gpio_tag tag);
  996. int nv17_gpio_set(struct drm_device *dev, enum dcb_gpio_tag tag, int state);
  997. #ifndef ioread32_native
  998. #ifdef __BIG_ENDIAN
  999. #define ioread16_native ioread16be
  1000. #define iowrite16_native iowrite16be
  1001. #define ioread32_native ioread32be
  1002. #define iowrite32_native iowrite32be
  1003. #else /* def __BIG_ENDIAN */
  1004. #define ioread16_native ioread16
  1005. #define iowrite16_native iowrite16
  1006. #define ioread32_native ioread32
  1007. #define iowrite32_native iowrite32
  1008. #endif /* def __BIG_ENDIAN else */
  1009. #endif /* !ioread32_native */
  1010. /* channel control reg access */
  1011. static inline u32 nvchan_rd32(struct nouveau_channel *chan, unsigned reg)
  1012. {
  1013. return ioread32_native(chan->user + reg);
  1014. }
  1015. static inline void nvchan_wr32(struct nouveau_channel *chan,
  1016. unsigned reg, u32 val)
  1017. {
  1018. iowrite32_native(val, chan->user + reg);
  1019. }
  1020. /* register access */
  1021. static inline u32 nv_rd32(struct drm_device *dev, unsigned reg)
  1022. {
  1023. struct drm_nouveau_private *dev_priv = dev->dev_private;
  1024. return ioread32_native(dev_priv->mmio + reg);
  1025. }
  1026. static inline void nv_wr32(struct drm_device *dev, unsigned reg, u32 val)
  1027. {
  1028. struct drm_nouveau_private *dev_priv = dev->dev_private;
  1029. iowrite32_native(val, dev_priv->mmio + reg);
  1030. }
  1031. static inline u8 nv_rd08(struct drm_device *dev, unsigned reg)
  1032. {
  1033. struct drm_nouveau_private *dev_priv = dev->dev_private;
  1034. return ioread8(dev_priv->mmio + reg);
  1035. }
  1036. static inline void nv_wr08(struct drm_device *dev, unsigned reg, u8 val)
  1037. {
  1038. struct drm_nouveau_private *dev_priv = dev->dev_private;
  1039. iowrite8(val, dev_priv->mmio + reg);
  1040. }
  1041. #define nv_wait(reg, mask, val) \
  1042. nouveau_wait_until(dev, 2000000000ULL, (reg), (mask), (val))
  1043. /* PRAMIN access */
  1044. static inline u32 nv_ri32(struct drm_device *dev, unsigned offset)
  1045. {
  1046. struct drm_nouveau_private *dev_priv = dev->dev_private;
  1047. return ioread32_native(dev_priv->ramin + offset);
  1048. }
  1049. static inline void nv_wi32(struct drm_device *dev, unsigned offset, u32 val)
  1050. {
  1051. struct drm_nouveau_private *dev_priv = dev->dev_private;
  1052. iowrite32_native(val, dev_priv->ramin + offset);
  1053. }
  1054. /* object access */
  1055. static inline u32 nv_ro32(struct drm_device *dev, struct nouveau_gpuobj *obj,
  1056. unsigned index)
  1057. {
  1058. return nv_ri32(dev, obj->im_pramin->start + index * 4);
  1059. }
  1060. static inline void nv_wo32(struct drm_device *dev, struct nouveau_gpuobj *obj,
  1061. unsigned index, u32 val)
  1062. {
  1063. nv_wi32(dev, obj->im_pramin->start + index * 4, val);
  1064. }
  1065. /*
  1066. * Logging
  1067. * Argument d is (struct drm_device *).
  1068. */
  1069. #define NV_PRINTK(level, d, fmt, arg...) \
  1070. printk(level "[" DRM_NAME "] " DRIVER_NAME " %s: " fmt, \
  1071. pci_name(d->pdev), ##arg)
  1072. #ifndef NV_DEBUG_NOTRACE
  1073. #define NV_DEBUG(d, fmt, arg...) do { \
  1074. if (drm_debug & DRM_UT_DRIVER) { \
  1075. NV_PRINTK(KERN_DEBUG, d, "%s:%d - " fmt, __func__, \
  1076. __LINE__, ##arg); \
  1077. } \
  1078. } while (0)
  1079. #define NV_DEBUG_KMS(d, fmt, arg...) do { \
  1080. if (drm_debug & DRM_UT_KMS) { \
  1081. NV_PRINTK(KERN_DEBUG, d, "%s:%d - " fmt, __func__, \
  1082. __LINE__, ##arg); \
  1083. } \
  1084. } while (0)
  1085. #else
  1086. #define NV_DEBUG(d, fmt, arg...) do { \
  1087. if (drm_debug & DRM_UT_DRIVER) \
  1088. NV_PRINTK(KERN_DEBUG, d, fmt, ##arg); \
  1089. } while (0)
  1090. #define NV_DEBUG_KMS(d, fmt, arg...) do { \
  1091. if (drm_debug & DRM_UT_KMS) \
  1092. NV_PRINTK(KERN_DEBUG, d, fmt, ##arg); \
  1093. } while (0)
  1094. #endif
  1095. #define NV_ERROR(d, fmt, arg...) NV_PRINTK(KERN_ERR, d, fmt, ##arg)
  1096. #define NV_INFO(d, fmt, arg...) NV_PRINTK(KERN_INFO, d, fmt, ##arg)
  1097. #define NV_TRACEWARN(d, fmt, arg...) NV_PRINTK(KERN_NOTICE, d, fmt, ##arg)
  1098. #define NV_TRACE(d, fmt, arg...) NV_PRINTK(KERN_INFO, d, fmt, ##arg)
  1099. #define NV_WARN(d, fmt, arg...) NV_PRINTK(KERN_WARNING, d, fmt, ##arg)
  1100. /* nouveau_reg_debug bitmask */
  1101. enum {
  1102. NOUVEAU_REG_DEBUG_MC = 0x1,
  1103. NOUVEAU_REG_DEBUG_VIDEO = 0x2,
  1104. NOUVEAU_REG_DEBUG_FB = 0x4,
  1105. NOUVEAU_REG_DEBUG_EXTDEV = 0x8,
  1106. NOUVEAU_REG_DEBUG_CRTC = 0x10,
  1107. NOUVEAU_REG_DEBUG_RAMDAC = 0x20,
  1108. NOUVEAU_REG_DEBUG_VGACRTC = 0x40,
  1109. NOUVEAU_REG_DEBUG_RMVIO = 0x80,
  1110. NOUVEAU_REG_DEBUG_VGAATTR = 0x100,
  1111. NOUVEAU_REG_DEBUG_EVO = 0x200,
  1112. };
  1113. #define NV_REG_DEBUG(type, dev, fmt, arg...) do { \
  1114. if (nouveau_reg_debug & NOUVEAU_REG_DEBUG_##type) \
  1115. NV_PRINTK(KERN_DEBUG, dev, "%s: " fmt, __func__, ##arg); \
  1116. } while (0)
  1117. static inline bool
  1118. nv_two_heads(struct drm_device *dev)
  1119. {
  1120. struct drm_nouveau_private *dev_priv = dev->dev_private;
  1121. const int impl = dev->pci_device & 0x0ff0;
  1122. if (dev_priv->card_type >= NV_10 && impl != 0x0100 &&
  1123. impl != 0x0150 && impl != 0x01a0 && impl != 0x0200)
  1124. return true;
  1125. return false;
  1126. }
  1127. static inline bool
  1128. nv_gf4_disp_arch(struct drm_device *dev)
  1129. {
  1130. return nv_two_heads(dev) && (dev->pci_device & 0x0ff0) != 0x0110;
  1131. }
  1132. static inline bool
  1133. nv_two_reg_pll(struct drm_device *dev)
  1134. {
  1135. struct drm_nouveau_private *dev_priv = dev->dev_private;
  1136. const int impl = dev->pci_device & 0x0ff0;
  1137. if (impl == 0x0310 || impl == 0x0340 || dev_priv->card_type >= NV_40)
  1138. return true;
  1139. return false;
  1140. }
  1141. #define NV_SW 0x0000506e
  1142. #define NV_SW_DMA_SEMAPHORE 0x00000060
  1143. #define NV_SW_SEMAPHORE_OFFSET 0x00000064
  1144. #define NV_SW_SEMAPHORE_ACQUIRE 0x00000068
  1145. #define NV_SW_SEMAPHORE_RELEASE 0x0000006c
  1146. #define NV_SW_DMA_VBLSEM 0x0000018c
  1147. #define NV_SW_VBLSEM_OFFSET 0x00000400
  1148. #define NV_SW_VBLSEM_RELEASE_VALUE 0x00000404
  1149. #define NV_SW_VBLSEM_RELEASE 0x00000408
  1150. #endif /* __NOUVEAU_DRV_H__ */