nouveau_drv.h 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586
  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. #include "nouveau_util.h"
  49. struct nouveau_grctx;
  50. struct nouveau_mem;
  51. #include "nouveau_vm.h"
  52. #define MAX_NUM_DCB_ENTRIES 16
  53. #define NOUVEAU_MAX_CHANNEL_NR 128
  54. #define NOUVEAU_MAX_TILE_NR 15
  55. struct nouveau_mem {
  56. struct drm_device *dev;
  57. struct nouveau_vma bar_vma;
  58. struct nouveau_vma tmp_vma;
  59. u8 page_shift;
  60. struct drm_mm_node *tag;
  61. struct list_head regions;
  62. dma_addr_t *pages;
  63. u32 memtype;
  64. u64 offset;
  65. u64 size;
  66. };
  67. struct nouveau_tile_reg {
  68. bool used;
  69. uint32_t addr;
  70. uint32_t limit;
  71. uint32_t pitch;
  72. uint32_t zcomp;
  73. struct drm_mm_node *tag_mem;
  74. struct nouveau_fence *fence;
  75. };
  76. struct nouveau_bo {
  77. struct ttm_buffer_object bo;
  78. struct ttm_placement placement;
  79. u32 valid_domains;
  80. u32 placements[3];
  81. u32 busy_placements[3];
  82. struct ttm_bo_kmap_obj kmap;
  83. struct list_head head;
  84. /* protected by ttm_bo_reserve() */
  85. struct drm_file *reserved_by;
  86. struct list_head entry;
  87. int pbbo_index;
  88. bool validate_mapped;
  89. struct nouveau_channel *channel;
  90. struct nouveau_vma vma;
  91. uint32_t tile_mode;
  92. uint32_t tile_flags;
  93. struct nouveau_tile_reg *tile;
  94. struct drm_gem_object *gem;
  95. int pin_refcnt;
  96. };
  97. #define nouveau_bo_tile_layout(nvbo) \
  98. ((nvbo)->tile_flags & NOUVEAU_GEM_TILE_LAYOUT_MASK)
  99. static inline struct nouveau_bo *
  100. nouveau_bo(struct ttm_buffer_object *bo)
  101. {
  102. return container_of(bo, struct nouveau_bo, bo);
  103. }
  104. static inline struct nouveau_bo *
  105. nouveau_gem_object(struct drm_gem_object *gem)
  106. {
  107. return gem ? gem->driver_private : NULL;
  108. }
  109. /* TODO: submit equivalent to TTM generic API upstream? */
  110. static inline void __iomem *
  111. nvbo_kmap_obj_iovirtual(struct nouveau_bo *nvbo)
  112. {
  113. bool is_iomem;
  114. void __iomem *ioptr = (void __force __iomem *)ttm_kmap_obj_virtual(
  115. &nvbo->kmap, &is_iomem);
  116. WARN_ON_ONCE(ioptr && !is_iomem);
  117. return ioptr;
  118. }
  119. enum nouveau_flags {
  120. NV_NFORCE = 0x10000000,
  121. NV_NFORCE2 = 0x20000000
  122. };
  123. #define NVOBJ_ENGINE_SW 0
  124. #define NVOBJ_ENGINE_GR 1
  125. #define NVOBJ_ENGINE_CRYPT 2
  126. #define NVOBJ_ENGINE_COPY0 3
  127. #define NVOBJ_ENGINE_COPY1 4
  128. #define NVOBJ_ENGINE_MPEG 5
  129. #define NVOBJ_ENGINE_DISPLAY 15
  130. #define NVOBJ_ENGINE_NR 16
  131. #define NVOBJ_FLAG_DONT_MAP (1 << 0)
  132. #define NVOBJ_FLAG_ZERO_ALLOC (1 << 1)
  133. #define NVOBJ_FLAG_ZERO_FREE (1 << 2)
  134. #define NVOBJ_FLAG_VM (1 << 3)
  135. #define NVOBJ_FLAG_VM_USER (1 << 4)
  136. #define NVOBJ_CINST_GLOBAL 0xdeadbeef
  137. struct nouveau_gpuobj {
  138. struct drm_device *dev;
  139. struct kref refcount;
  140. struct list_head list;
  141. void *node;
  142. u32 *suspend;
  143. uint32_t flags;
  144. u32 size;
  145. u32 pinst; /* PRAMIN BAR offset */
  146. u32 cinst; /* Channel offset */
  147. u64 vinst; /* VRAM address */
  148. u64 linst; /* VM address */
  149. uint32_t engine;
  150. uint32_t class;
  151. void (*dtor)(struct drm_device *, struct nouveau_gpuobj *);
  152. void *priv;
  153. };
  154. struct nouveau_page_flip_state {
  155. struct list_head head;
  156. struct drm_pending_vblank_event *event;
  157. int crtc, bpp, pitch, x, y;
  158. uint64_t offset;
  159. };
  160. enum nouveau_channel_mutex_class {
  161. NOUVEAU_UCHANNEL_MUTEX,
  162. NOUVEAU_KCHANNEL_MUTEX
  163. };
  164. struct nouveau_channel {
  165. struct drm_device *dev;
  166. int id;
  167. /* references to the channel data structure */
  168. struct kref ref;
  169. /* users of the hardware channel resources, the hardware
  170. * context will be kicked off when it reaches zero. */
  171. atomic_t users;
  172. struct mutex mutex;
  173. /* owner of this fifo */
  174. struct drm_file *file_priv;
  175. /* mapping of the fifo itself */
  176. struct drm_local_map *map;
  177. /* mapping of the regs controlling the fifo */
  178. void __iomem *user;
  179. uint32_t user_get;
  180. uint32_t user_put;
  181. /* Fencing */
  182. struct {
  183. /* lock protects the pending list only */
  184. spinlock_t lock;
  185. struct list_head pending;
  186. uint32_t sequence;
  187. uint32_t sequence_ack;
  188. atomic_t last_sequence_irq;
  189. } fence;
  190. /* DMA push buffer */
  191. struct nouveau_gpuobj *pushbuf;
  192. struct nouveau_bo *pushbuf_bo;
  193. uint32_t pushbuf_base;
  194. /* Notifier memory */
  195. struct nouveau_bo *notifier_bo;
  196. struct drm_mm notifier_heap;
  197. /* PFIFO context */
  198. struct nouveau_gpuobj *ramfc;
  199. struct nouveau_gpuobj *cache;
  200. void *fifo_priv;
  201. /* Execution engine contexts */
  202. void *engctx[NVOBJ_ENGINE_NR];
  203. /* NV50 VM */
  204. struct nouveau_vm *vm;
  205. struct nouveau_gpuobj *vm_pd;
  206. /* Objects */
  207. struct nouveau_gpuobj *ramin; /* Private instmem */
  208. struct drm_mm ramin_heap; /* Private PRAMIN heap */
  209. struct nouveau_ramht *ramht; /* Hash table */
  210. /* GPU object info for stuff used in-kernel (mm_enabled) */
  211. uint32_t m2mf_ntfy;
  212. uint32_t vram_handle;
  213. uint32_t gart_handle;
  214. bool accel_done;
  215. /* Push buffer state (only for drm's channel on !mm_enabled) */
  216. struct {
  217. int max;
  218. int free;
  219. int cur;
  220. int put;
  221. /* access via pushbuf_bo */
  222. int ib_base;
  223. int ib_max;
  224. int ib_free;
  225. int ib_put;
  226. } dma;
  227. uint32_t sw_subchannel[8];
  228. struct {
  229. struct nouveau_gpuobj *vblsem;
  230. uint32_t vblsem_head;
  231. uint32_t vblsem_offset;
  232. uint32_t vblsem_rval;
  233. struct list_head vbl_wait;
  234. struct list_head flip;
  235. } nvsw;
  236. struct {
  237. bool active;
  238. char name[32];
  239. struct drm_info_list info;
  240. } debugfs;
  241. };
  242. struct nouveau_exec_engine {
  243. void (*destroy)(struct drm_device *, int engine);
  244. int (*init)(struct drm_device *, int engine);
  245. int (*fini)(struct drm_device *, int engine);
  246. int (*context_new)(struct nouveau_channel *, int engine);
  247. void (*context_del)(struct nouveau_channel *, int engine);
  248. int (*object_new)(struct nouveau_channel *, int engine,
  249. u32 handle, u16 class);
  250. void (*set_tile_region)(struct drm_device *dev, int i);
  251. void (*tlb_flush)(struct drm_device *, int engine);
  252. };
  253. struct nouveau_instmem_engine {
  254. void *priv;
  255. int (*init)(struct drm_device *dev);
  256. void (*takedown)(struct drm_device *dev);
  257. int (*suspend)(struct drm_device *dev);
  258. void (*resume)(struct drm_device *dev);
  259. int (*get)(struct nouveau_gpuobj *, u32 size, u32 align);
  260. void (*put)(struct nouveau_gpuobj *);
  261. int (*map)(struct nouveau_gpuobj *);
  262. void (*unmap)(struct nouveau_gpuobj *);
  263. void (*flush)(struct drm_device *);
  264. };
  265. struct nouveau_mc_engine {
  266. int (*init)(struct drm_device *dev);
  267. void (*takedown)(struct drm_device *dev);
  268. };
  269. struct nouveau_timer_engine {
  270. int (*init)(struct drm_device *dev);
  271. void (*takedown)(struct drm_device *dev);
  272. uint64_t (*read)(struct drm_device *dev);
  273. };
  274. struct nouveau_fb_engine {
  275. int num_tiles;
  276. struct drm_mm tag_heap;
  277. void *priv;
  278. int (*init)(struct drm_device *dev);
  279. void (*takedown)(struct drm_device *dev);
  280. void (*init_tile_region)(struct drm_device *dev, int i,
  281. uint32_t addr, uint32_t size,
  282. uint32_t pitch, uint32_t flags);
  283. void (*set_tile_region)(struct drm_device *dev, int i);
  284. void (*free_tile_region)(struct drm_device *dev, int i);
  285. };
  286. struct nouveau_fifo_engine {
  287. void *priv;
  288. int channels;
  289. struct nouveau_gpuobj *playlist[2];
  290. int cur_playlist;
  291. int (*init)(struct drm_device *);
  292. void (*takedown)(struct drm_device *);
  293. void (*disable)(struct drm_device *);
  294. void (*enable)(struct drm_device *);
  295. bool (*reassign)(struct drm_device *, bool enable);
  296. bool (*cache_pull)(struct drm_device *dev, bool enable);
  297. int (*channel_id)(struct drm_device *);
  298. int (*create_context)(struct nouveau_channel *);
  299. void (*destroy_context)(struct nouveau_channel *);
  300. int (*load_context)(struct nouveau_channel *);
  301. int (*unload_context)(struct drm_device *);
  302. void (*tlb_flush)(struct drm_device *dev);
  303. };
  304. struct nouveau_display_engine {
  305. void *priv;
  306. int (*early_init)(struct drm_device *);
  307. void (*late_takedown)(struct drm_device *);
  308. int (*create)(struct drm_device *);
  309. int (*init)(struct drm_device *);
  310. void (*destroy)(struct drm_device *);
  311. };
  312. struct nouveau_gpio_engine {
  313. void *priv;
  314. int (*init)(struct drm_device *);
  315. void (*takedown)(struct drm_device *);
  316. int (*get)(struct drm_device *, enum dcb_gpio_tag);
  317. int (*set)(struct drm_device *, enum dcb_gpio_tag, int state);
  318. int (*irq_register)(struct drm_device *, enum dcb_gpio_tag,
  319. void (*)(void *, int), void *);
  320. void (*irq_unregister)(struct drm_device *, enum dcb_gpio_tag,
  321. void (*)(void *, int), void *);
  322. bool (*irq_enable)(struct drm_device *, enum dcb_gpio_tag, bool on);
  323. };
  324. struct nouveau_pm_voltage_level {
  325. u8 voltage;
  326. u8 vid;
  327. };
  328. struct nouveau_pm_voltage {
  329. bool supported;
  330. u8 vid_mask;
  331. struct nouveau_pm_voltage_level *level;
  332. int nr_level;
  333. };
  334. struct nouveau_pm_memtiming {
  335. int id;
  336. u32 reg_100220;
  337. u32 reg_100224;
  338. u32 reg_100228;
  339. u32 reg_10022c;
  340. u32 reg_100230;
  341. u32 reg_100234;
  342. u32 reg_100238;
  343. u32 reg_10023c;
  344. u32 reg_100240;
  345. };
  346. #define NOUVEAU_PM_MAX_LEVEL 8
  347. struct nouveau_pm_level {
  348. struct device_attribute dev_attr;
  349. char name[32];
  350. int id;
  351. u32 core;
  352. u32 memory;
  353. u32 shader;
  354. u32 unk05;
  355. u32 unk0a;
  356. u8 voltage;
  357. u8 fanspeed;
  358. u16 memscript;
  359. struct nouveau_pm_memtiming *timing;
  360. };
  361. struct nouveau_pm_temp_sensor_constants {
  362. u16 offset_constant;
  363. s16 offset_mult;
  364. u16 offset_div;
  365. u16 slope_mult;
  366. u16 slope_div;
  367. };
  368. struct nouveau_pm_threshold_temp {
  369. s16 critical;
  370. s16 down_clock;
  371. s16 fan_boost;
  372. };
  373. struct nouveau_pm_memtimings {
  374. bool supported;
  375. struct nouveau_pm_memtiming *timing;
  376. int nr_timing;
  377. };
  378. struct nouveau_pm_engine {
  379. struct nouveau_pm_voltage voltage;
  380. struct nouveau_pm_level perflvl[NOUVEAU_PM_MAX_LEVEL];
  381. int nr_perflvl;
  382. struct nouveau_pm_memtimings memtimings;
  383. struct nouveau_pm_temp_sensor_constants sensor_constants;
  384. struct nouveau_pm_threshold_temp threshold_temp;
  385. struct nouveau_pm_level boot;
  386. struct nouveau_pm_level *cur;
  387. struct device *hwmon;
  388. struct notifier_block acpi_nb;
  389. int (*clock_get)(struct drm_device *, u32 id);
  390. void *(*clock_pre)(struct drm_device *, struct nouveau_pm_level *,
  391. u32 id, int khz);
  392. void (*clock_set)(struct drm_device *, void *);
  393. int (*voltage_get)(struct drm_device *);
  394. int (*voltage_set)(struct drm_device *, int voltage);
  395. int (*fanspeed_get)(struct drm_device *);
  396. int (*fanspeed_set)(struct drm_device *, int fanspeed);
  397. int (*temp_get)(struct drm_device *);
  398. };
  399. struct nouveau_vram_engine {
  400. int (*init)(struct drm_device *);
  401. int (*get)(struct drm_device *, u64, u32 align, u32 size_nc,
  402. u32 type, struct nouveau_mem **);
  403. void (*put)(struct drm_device *, struct nouveau_mem **);
  404. bool (*flags_valid)(struct drm_device *, u32 tile_flags);
  405. };
  406. struct nouveau_engine {
  407. struct nouveau_instmem_engine instmem;
  408. struct nouveau_mc_engine mc;
  409. struct nouveau_timer_engine timer;
  410. struct nouveau_fb_engine fb;
  411. struct nouveau_fifo_engine fifo;
  412. struct nouveau_display_engine display;
  413. struct nouveau_gpio_engine gpio;
  414. struct nouveau_pm_engine pm;
  415. struct nouveau_vram_engine vram;
  416. };
  417. struct nouveau_pll_vals {
  418. union {
  419. struct {
  420. #ifdef __BIG_ENDIAN
  421. uint8_t N1, M1, N2, M2;
  422. #else
  423. uint8_t M1, N1, M2, N2;
  424. #endif
  425. };
  426. struct {
  427. uint16_t NM1, NM2;
  428. } __attribute__((packed));
  429. };
  430. int log2P;
  431. int refclk;
  432. };
  433. enum nv04_fp_display_regs {
  434. FP_DISPLAY_END,
  435. FP_TOTAL,
  436. FP_CRTC,
  437. FP_SYNC_START,
  438. FP_SYNC_END,
  439. FP_VALID_START,
  440. FP_VALID_END
  441. };
  442. struct nv04_crtc_reg {
  443. unsigned char MiscOutReg;
  444. uint8_t CRTC[0xa0];
  445. uint8_t CR58[0x10];
  446. uint8_t Sequencer[5];
  447. uint8_t Graphics[9];
  448. uint8_t Attribute[21];
  449. unsigned char DAC[768];
  450. /* PCRTC regs */
  451. uint32_t fb_start;
  452. uint32_t crtc_cfg;
  453. uint32_t cursor_cfg;
  454. uint32_t gpio_ext;
  455. uint32_t crtc_830;
  456. uint32_t crtc_834;
  457. uint32_t crtc_850;
  458. uint32_t crtc_eng_ctrl;
  459. /* PRAMDAC regs */
  460. uint32_t nv10_cursync;
  461. struct nouveau_pll_vals pllvals;
  462. uint32_t ramdac_gen_ctrl;
  463. uint32_t ramdac_630;
  464. uint32_t ramdac_634;
  465. uint32_t tv_setup;
  466. uint32_t tv_vtotal;
  467. uint32_t tv_vskew;
  468. uint32_t tv_vsync_delay;
  469. uint32_t tv_htotal;
  470. uint32_t tv_hskew;
  471. uint32_t tv_hsync_delay;
  472. uint32_t tv_hsync_delay2;
  473. uint32_t fp_horiz_regs[7];
  474. uint32_t fp_vert_regs[7];
  475. uint32_t dither;
  476. uint32_t fp_control;
  477. uint32_t dither_regs[6];
  478. uint32_t fp_debug_0;
  479. uint32_t fp_debug_1;
  480. uint32_t fp_debug_2;
  481. uint32_t fp_margin_color;
  482. uint32_t ramdac_8c0;
  483. uint32_t ramdac_a20;
  484. uint32_t ramdac_a24;
  485. uint32_t ramdac_a34;
  486. uint32_t ctv_regs[38];
  487. };
  488. struct nv04_output_reg {
  489. uint32_t output;
  490. int head;
  491. };
  492. struct nv04_mode_state {
  493. struct nv04_crtc_reg crtc_reg[2];
  494. uint32_t pllsel;
  495. uint32_t sel_clk;
  496. };
  497. enum nouveau_card_type {
  498. NV_04 = 0x00,
  499. NV_10 = 0x10,
  500. NV_20 = 0x20,
  501. NV_30 = 0x30,
  502. NV_40 = 0x40,
  503. NV_50 = 0x50,
  504. NV_C0 = 0xc0,
  505. };
  506. struct drm_nouveau_private {
  507. struct drm_device *dev;
  508. bool noaccel;
  509. /* the card type, takes NV_* as values */
  510. enum nouveau_card_type card_type;
  511. /* exact chipset, derived from NV_PMC_BOOT_0 */
  512. int chipset;
  513. int stepping;
  514. int flags;
  515. void __iomem *mmio;
  516. spinlock_t ramin_lock;
  517. void __iomem *ramin;
  518. u32 ramin_size;
  519. u32 ramin_base;
  520. bool ramin_available;
  521. struct drm_mm ramin_heap;
  522. struct nouveau_exec_engine *eng[NVOBJ_ENGINE_NR];
  523. struct list_head gpuobj_list;
  524. struct list_head classes;
  525. struct nouveau_bo *vga_ram;
  526. /* interrupt handling */
  527. void (*irq_handler[32])(struct drm_device *);
  528. bool msi_enabled;
  529. struct list_head vbl_waiting;
  530. struct {
  531. struct drm_global_reference mem_global_ref;
  532. struct ttm_bo_global_ref bo_global_ref;
  533. struct ttm_bo_device bdev;
  534. atomic_t validate_sequence;
  535. } ttm;
  536. struct {
  537. spinlock_t lock;
  538. struct drm_mm heap;
  539. struct nouveau_bo *bo;
  540. } fence;
  541. struct {
  542. spinlock_t lock;
  543. struct nouveau_channel *ptr[NOUVEAU_MAX_CHANNEL_NR];
  544. } channels;
  545. struct nouveau_engine engine;
  546. struct nouveau_channel *channel;
  547. /* For PFIFO and PGRAPH. */
  548. spinlock_t context_switch_lock;
  549. /* VM/PRAMIN flush, legacy PRAMIN aperture */
  550. spinlock_t vm_lock;
  551. /* RAMIN configuration, RAMFC, RAMHT and RAMRO offsets */
  552. struct nouveau_ramht *ramht;
  553. struct nouveau_gpuobj *ramfc;
  554. struct nouveau_gpuobj *ramro;
  555. uint32_t ramin_rsvd_vram;
  556. struct {
  557. enum {
  558. NOUVEAU_GART_NONE = 0,
  559. NOUVEAU_GART_AGP, /* AGP */
  560. NOUVEAU_GART_PDMA, /* paged dma object */
  561. NOUVEAU_GART_HW /* on-chip gart/vm */
  562. } type;
  563. uint64_t aper_base;
  564. uint64_t aper_size;
  565. uint64_t aper_free;
  566. struct ttm_backend_func *func;
  567. struct {
  568. struct page *page;
  569. dma_addr_t addr;
  570. } dummy;
  571. struct nouveau_gpuobj *sg_ctxdma;
  572. } gart_info;
  573. /* nv10-nv40 tiling regions */
  574. struct {
  575. struct nouveau_tile_reg reg[NOUVEAU_MAX_TILE_NR];
  576. spinlock_t lock;
  577. } tile;
  578. /* VRAM/fb configuration */
  579. uint64_t vram_size;
  580. uint64_t vram_sys_base;
  581. u32 vram_rblock_size;
  582. uint64_t fb_phys;
  583. uint64_t fb_available_size;
  584. uint64_t fb_mappable_pages;
  585. uint64_t fb_aper_free;
  586. int fb_mtrr;
  587. /* BAR control (NV50-) */
  588. struct nouveau_vm *bar1_vm;
  589. struct nouveau_vm *bar3_vm;
  590. /* G8x/G9x virtual address space */
  591. struct nouveau_vm *chan_vm;
  592. struct nvbios vbios;
  593. struct nv04_mode_state mode_reg;
  594. struct nv04_mode_state saved_reg;
  595. uint32_t saved_vga_font[4][16384];
  596. uint32_t crtc_owner;
  597. uint32_t dac_users[4];
  598. struct backlight_device *backlight;
  599. struct {
  600. struct dentry *channel_root;
  601. } debugfs;
  602. struct nouveau_fbdev *nfbdev;
  603. struct apertures_struct *apertures;
  604. };
  605. static inline struct drm_nouveau_private *
  606. nouveau_private(struct drm_device *dev)
  607. {
  608. return dev->dev_private;
  609. }
  610. static inline struct drm_nouveau_private *
  611. nouveau_bdev(struct ttm_bo_device *bd)
  612. {
  613. return container_of(bd, struct drm_nouveau_private, ttm.bdev);
  614. }
  615. static inline int
  616. nouveau_bo_ref(struct nouveau_bo *ref, struct nouveau_bo **pnvbo)
  617. {
  618. struct nouveau_bo *prev;
  619. if (!pnvbo)
  620. return -EINVAL;
  621. prev = *pnvbo;
  622. *pnvbo = ref ? nouveau_bo(ttm_bo_reference(&ref->bo)) : NULL;
  623. if (prev) {
  624. struct ttm_buffer_object *bo = &prev->bo;
  625. ttm_bo_unref(&bo);
  626. }
  627. return 0;
  628. }
  629. /* nouveau_drv.c */
  630. extern int nouveau_agpmode;
  631. extern int nouveau_duallink;
  632. extern int nouveau_uscript_lvds;
  633. extern int nouveau_uscript_tmds;
  634. extern int nouveau_vram_pushbuf;
  635. extern int nouveau_vram_notify;
  636. extern int nouveau_fbpercrtc;
  637. extern int nouveau_tv_disable;
  638. extern char *nouveau_tv_norm;
  639. extern int nouveau_reg_debug;
  640. extern char *nouveau_vbios;
  641. extern int nouveau_ignorelid;
  642. extern int nouveau_nofbaccel;
  643. extern int nouveau_noaccel;
  644. extern int nouveau_force_post;
  645. extern int nouveau_override_conntype;
  646. extern char *nouveau_perflvl;
  647. extern int nouveau_perflvl_wr;
  648. extern int nouveau_msi;
  649. extern int nouveau_ctxfw;
  650. extern int nouveau_pci_suspend(struct pci_dev *pdev, pm_message_t pm_state);
  651. extern int nouveau_pci_resume(struct pci_dev *pdev);
  652. /* nouveau_state.c */
  653. extern void nouveau_preclose(struct drm_device *dev, struct drm_file *);
  654. extern int nouveau_load(struct drm_device *, unsigned long flags);
  655. extern int nouveau_firstopen(struct drm_device *);
  656. extern void nouveau_lastclose(struct drm_device *);
  657. extern int nouveau_unload(struct drm_device *);
  658. extern int nouveau_ioctl_getparam(struct drm_device *, void *data,
  659. struct drm_file *);
  660. extern int nouveau_ioctl_setparam(struct drm_device *, void *data,
  661. struct drm_file *);
  662. extern bool nouveau_wait_eq(struct drm_device *, uint64_t timeout,
  663. uint32_t reg, uint32_t mask, uint32_t val);
  664. extern bool nouveau_wait_ne(struct drm_device *, uint64_t timeout,
  665. uint32_t reg, uint32_t mask, uint32_t val);
  666. extern bool nouveau_wait_for_idle(struct drm_device *);
  667. extern int nouveau_card_init(struct drm_device *);
  668. /* nouveau_mem.c */
  669. extern int nouveau_mem_vram_init(struct drm_device *);
  670. extern void nouveau_mem_vram_fini(struct drm_device *);
  671. extern int nouveau_mem_gart_init(struct drm_device *);
  672. extern void nouveau_mem_gart_fini(struct drm_device *);
  673. extern int nouveau_mem_init_agp(struct drm_device *);
  674. extern int nouveau_mem_reset_agp(struct drm_device *);
  675. extern void nouveau_mem_close(struct drm_device *);
  676. extern int nouveau_mem_detect(struct drm_device *);
  677. extern bool nouveau_mem_flags_valid(struct drm_device *, u32 tile_flags);
  678. extern struct nouveau_tile_reg *nv10_mem_set_tiling(
  679. struct drm_device *dev, uint32_t addr, uint32_t size,
  680. uint32_t pitch, uint32_t flags);
  681. extern void nv10_mem_put_tile_region(struct drm_device *dev,
  682. struct nouveau_tile_reg *tile,
  683. struct nouveau_fence *fence);
  684. extern const struct ttm_mem_type_manager_func nouveau_vram_manager;
  685. extern const struct ttm_mem_type_manager_func nouveau_gart_manager;
  686. /* nouveau_notifier.c */
  687. extern int nouveau_notifier_init_channel(struct nouveau_channel *);
  688. extern void nouveau_notifier_takedown_channel(struct nouveau_channel *);
  689. extern int nouveau_notifier_alloc(struct nouveau_channel *, uint32_t handle,
  690. int cout, uint32_t start, uint32_t end,
  691. uint32_t *offset);
  692. extern int nouveau_notifier_offset(struct nouveau_gpuobj *, uint32_t *);
  693. extern int nouveau_ioctl_notifier_alloc(struct drm_device *, void *data,
  694. struct drm_file *);
  695. extern int nouveau_ioctl_notifier_free(struct drm_device *, void *data,
  696. struct drm_file *);
  697. /* nouveau_channel.c */
  698. extern struct drm_ioctl_desc nouveau_ioctls[];
  699. extern int nouveau_max_ioctl;
  700. extern void nouveau_channel_cleanup(struct drm_device *, struct drm_file *);
  701. extern int nouveau_channel_alloc(struct drm_device *dev,
  702. struct nouveau_channel **chan,
  703. struct drm_file *file_priv,
  704. uint32_t fb_ctxdma, uint32_t tt_ctxdma);
  705. extern struct nouveau_channel *
  706. nouveau_channel_get_unlocked(struct nouveau_channel *);
  707. extern struct nouveau_channel *
  708. nouveau_channel_get(struct drm_device *, struct drm_file *, int id);
  709. extern void nouveau_channel_put_unlocked(struct nouveau_channel **);
  710. extern void nouveau_channel_put(struct nouveau_channel **);
  711. extern void nouveau_channel_ref(struct nouveau_channel *chan,
  712. struct nouveau_channel **pchan);
  713. extern void nouveau_channel_idle(struct nouveau_channel *chan);
  714. /* nouveau_object.c */
  715. #define NVOBJ_ENGINE_ADD(d, e, p) do { \
  716. struct drm_nouveau_private *dev_priv = (d)->dev_private; \
  717. dev_priv->eng[NVOBJ_ENGINE_##e] = (p); \
  718. } while (0)
  719. #define NVOBJ_ENGINE_DEL(d, e) do { \
  720. struct drm_nouveau_private *dev_priv = (d)->dev_private; \
  721. dev_priv->eng[NVOBJ_ENGINE_##e] = NULL; \
  722. } while (0)
  723. #define NVOBJ_CLASS(d, c, e) do { \
  724. int ret = nouveau_gpuobj_class_new((d), (c), NVOBJ_ENGINE_##e); \
  725. if (ret) \
  726. return ret; \
  727. } while (0)
  728. #define NVOBJ_MTHD(d, c, m, e) do { \
  729. int ret = nouveau_gpuobj_mthd_new((d), (c), (m), (e)); \
  730. if (ret) \
  731. return ret; \
  732. } while (0)
  733. extern int nouveau_gpuobj_early_init(struct drm_device *);
  734. extern int nouveau_gpuobj_init(struct drm_device *);
  735. extern void nouveau_gpuobj_takedown(struct drm_device *);
  736. extern int nouveau_gpuobj_suspend(struct drm_device *dev);
  737. extern void nouveau_gpuobj_resume(struct drm_device *dev);
  738. extern int nouveau_gpuobj_class_new(struct drm_device *, u32 class, u32 eng);
  739. extern int nouveau_gpuobj_mthd_new(struct drm_device *, u32 class, u32 mthd,
  740. int (*exec)(struct nouveau_channel *,
  741. u32 class, u32 mthd, u32 data));
  742. extern int nouveau_gpuobj_mthd_call(struct nouveau_channel *, u32, u32, u32);
  743. extern int nouveau_gpuobj_mthd_call2(struct drm_device *, int, u32, u32, u32);
  744. extern int nouveau_gpuobj_channel_init(struct nouveau_channel *,
  745. uint32_t vram_h, uint32_t tt_h);
  746. extern void nouveau_gpuobj_channel_takedown(struct nouveau_channel *);
  747. extern int nouveau_gpuobj_new(struct drm_device *, struct nouveau_channel *,
  748. uint32_t size, int align, uint32_t flags,
  749. struct nouveau_gpuobj **);
  750. extern void nouveau_gpuobj_ref(struct nouveau_gpuobj *,
  751. struct nouveau_gpuobj **);
  752. extern int nouveau_gpuobj_new_fake(struct drm_device *, u32 pinst, u64 vinst,
  753. u32 size, u32 flags,
  754. struct nouveau_gpuobj **);
  755. extern int nouveau_gpuobj_dma_new(struct nouveau_channel *, int class,
  756. uint64_t offset, uint64_t size, int access,
  757. int target, struct nouveau_gpuobj **);
  758. extern int nouveau_gpuobj_gr_new(struct nouveau_channel *, u32 handle, int class);
  759. extern int nv50_gpuobj_dma_new(struct nouveau_channel *, int class, u64 base,
  760. u64 size, int target, int access, u32 type,
  761. u32 comp, struct nouveau_gpuobj **pobj);
  762. extern void nv50_gpuobj_dma_init(struct nouveau_gpuobj *, u32 offset,
  763. int class, u64 base, u64 size, int target,
  764. int access, u32 type, u32 comp);
  765. extern int nouveau_ioctl_grobj_alloc(struct drm_device *, void *data,
  766. struct drm_file *);
  767. extern int nouveau_ioctl_gpuobj_free(struct drm_device *, void *data,
  768. struct drm_file *);
  769. /* nouveau_irq.c */
  770. extern int nouveau_irq_init(struct drm_device *);
  771. extern void nouveau_irq_fini(struct drm_device *);
  772. extern irqreturn_t nouveau_irq_handler(DRM_IRQ_ARGS);
  773. extern void nouveau_irq_register(struct drm_device *, int status_bit,
  774. void (*)(struct drm_device *));
  775. extern void nouveau_irq_unregister(struct drm_device *, int status_bit);
  776. extern void nouveau_irq_preinstall(struct drm_device *);
  777. extern int nouveau_irq_postinstall(struct drm_device *);
  778. extern void nouveau_irq_uninstall(struct drm_device *);
  779. /* nouveau_sgdma.c */
  780. extern int nouveau_sgdma_init(struct drm_device *);
  781. extern void nouveau_sgdma_takedown(struct drm_device *);
  782. extern uint32_t nouveau_sgdma_get_physical(struct drm_device *,
  783. uint32_t offset);
  784. extern struct ttm_backend *nouveau_sgdma_init_ttm(struct drm_device *);
  785. /* nouveau_debugfs.c */
  786. #if defined(CONFIG_DRM_NOUVEAU_DEBUG)
  787. extern int nouveau_debugfs_init(struct drm_minor *);
  788. extern void nouveau_debugfs_takedown(struct drm_minor *);
  789. extern int nouveau_debugfs_channel_init(struct nouveau_channel *);
  790. extern void nouveau_debugfs_channel_fini(struct nouveau_channel *);
  791. #else
  792. static inline int
  793. nouveau_debugfs_init(struct drm_minor *minor)
  794. {
  795. return 0;
  796. }
  797. static inline void nouveau_debugfs_takedown(struct drm_minor *minor)
  798. {
  799. }
  800. static inline int
  801. nouveau_debugfs_channel_init(struct nouveau_channel *chan)
  802. {
  803. return 0;
  804. }
  805. static inline void
  806. nouveau_debugfs_channel_fini(struct nouveau_channel *chan)
  807. {
  808. }
  809. #endif
  810. /* nouveau_dma.c */
  811. extern void nouveau_dma_pre_init(struct nouveau_channel *);
  812. extern int nouveau_dma_init(struct nouveau_channel *);
  813. extern int nouveau_dma_wait(struct nouveau_channel *, int slots, int size);
  814. /* nouveau_acpi.c */
  815. #define ROM_BIOS_PAGE 4096
  816. #if defined(CONFIG_ACPI)
  817. void nouveau_register_dsm_handler(void);
  818. void nouveau_unregister_dsm_handler(void);
  819. int nouveau_acpi_get_bios_chunk(uint8_t *bios, int offset, int len);
  820. bool nouveau_acpi_rom_supported(struct pci_dev *pdev);
  821. int nouveau_acpi_edid(struct drm_device *, struct drm_connector *);
  822. #else
  823. static inline void nouveau_register_dsm_handler(void) {}
  824. static inline void nouveau_unregister_dsm_handler(void) {}
  825. static inline bool nouveau_acpi_rom_supported(struct pci_dev *pdev) { return false; }
  826. static inline int nouveau_acpi_get_bios_chunk(uint8_t *bios, int offset, int len) { return -EINVAL; }
  827. static inline int nouveau_acpi_edid(struct drm_device *dev, struct drm_connector *connector) { return -EINVAL; }
  828. #endif
  829. /* nouveau_backlight.c */
  830. #ifdef CONFIG_DRM_NOUVEAU_BACKLIGHT
  831. extern int nouveau_backlight_init(struct drm_connector *);
  832. extern void nouveau_backlight_exit(struct drm_connector *);
  833. #else
  834. static inline int nouveau_backlight_init(struct drm_connector *dev)
  835. {
  836. return 0;
  837. }
  838. static inline void nouveau_backlight_exit(struct drm_connector *dev) { }
  839. #endif
  840. /* nouveau_bios.c */
  841. extern int nouveau_bios_init(struct drm_device *);
  842. extern void nouveau_bios_takedown(struct drm_device *dev);
  843. extern int nouveau_run_vbios_init(struct drm_device *);
  844. extern void nouveau_bios_run_init_table(struct drm_device *, uint16_t table,
  845. struct dcb_entry *);
  846. extern struct dcb_gpio_entry *nouveau_bios_gpio_entry(struct drm_device *,
  847. enum dcb_gpio_tag);
  848. extern struct dcb_connector_table_entry *
  849. nouveau_bios_connector_entry(struct drm_device *, int index);
  850. extern u32 get_pll_register(struct drm_device *, enum pll_types);
  851. extern int get_pll_limits(struct drm_device *, uint32_t limit_match,
  852. struct pll_lims *);
  853. extern int nouveau_bios_run_display_table(struct drm_device *,
  854. struct dcb_entry *,
  855. uint32_t script, int pxclk);
  856. extern void *nouveau_bios_dp_table(struct drm_device *, struct dcb_entry *,
  857. int *length);
  858. extern bool nouveau_bios_fp_mode(struct drm_device *, struct drm_display_mode *);
  859. extern uint8_t *nouveau_bios_embedded_edid(struct drm_device *);
  860. extern int nouveau_bios_parse_lvds_table(struct drm_device *, int pxclk,
  861. bool *dl, bool *if_is_24bit);
  862. extern int run_tmds_table(struct drm_device *, struct dcb_entry *,
  863. int head, int pxclk);
  864. extern int call_lvds_script(struct drm_device *, struct dcb_entry *, int head,
  865. enum LVDS_script, int pxclk);
  866. /* nouveau_ttm.c */
  867. int nouveau_ttm_global_init(struct drm_nouveau_private *);
  868. void nouveau_ttm_global_release(struct drm_nouveau_private *);
  869. int nouveau_ttm_mmap(struct file *, struct vm_area_struct *);
  870. /* nouveau_dp.c */
  871. int nouveau_dp_auxch(struct nouveau_i2c_chan *auxch, int cmd, int addr,
  872. uint8_t *data, int data_nr);
  873. bool nouveau_dp_detect(struct drm_encoder *);
  874. bool nouveau_dp_link_train(struct drm_encoder *);
  875. /* nv04_fb.c */
  876. extern int nv04_fb_init(struct drm_device *);
  877. extern void nv04_fb_takedown(struct drm_device *);
  878. /* nv10_fb.c */
  879. extern int nv10_fb_init(struct drm_device *);
  880. extern void nv10_fb_takedown(struct drm_device *);
  881. extern void nv10_fb_init_tile_region(struct drm_device *dev, int i,
  882. uint32_t addr, uint32_t size,
  883. uint32_t pitch, uint32_t flags);
  884. extern void nv10_fb_set_tile_region(struct drm_device *dev, int i);
  885. extern void nv10_fb_free_tile_region(struct drm_device *dev, int i);
  886. /* nv30_fb.c */
  887. extern int nv30_fb_init(struct drm_device *);
  888. extern void nv30_fb_takedown(struct drm_device *);
  889. extern void nv30_fb_init_tile_region(struct drm_device *dev, int i,
  890. uint32_t addr, uint32_t size,
  891. uint32_t pitch, uint32_t flags);
  892. extern void nv30_fb_free_tile_region(struct drm_device *dev, int i);
  893. /* nv40_fb.c */
  894. extern int nv40_fb_init(struct drm_device *);
  895. extern void nv40_fb_takedown(struct drm_device *);
  896. extern void nv40_fb_set_tile_region(struct drm_device *dev, int i);
  897. /* nv50_fb.c */
  898. extern int nv50_fb_init(struct drm_device *);
  899. extern void nv50_fb_takedown(struct drm_device *);
  900. extern void nv50_fb_vm_trap(struct drm_device *, int display);
  901. /* nvc0_fb.c */
  902. extern int nvc0_fb_init(struct drm_device *);
  903. extern void nvc0_fb_takedown(struct drm_device *);
  904. /* nv04_fifo.c */
  905. extern int nv04_fifo_init(struct drm_device *);
  906. extern void nv04_fifo_fini(struct drm_device *);
  907. extern void nv04_fifo_disable(struct drm_device *);
  908. extern void nv04_fifo_enable(struct drm_device *);
  909. extern bool nv04_fifo_reassign(struct drm_device *, bool);
  910. extern bool nv04_fifo_cache_pull(struct drm_device *, bool);
  911. extern int nv04_fifo_channel_id(struct drm_device *);
  912. extern int nv04_fifo_create_context(struct nouveau_channel *);
  913. extern void nv04_fifo_destroy_context(struct nouveau_channel *);
  914. extern int nv04_fifo_load_context(struct nouveau_channel *);
  915. extern int nv04_fifo_unload_context(struct drm_device *);
  916. extern void nv04_fifo_isr(struct drm_device *);
  917. /* nv10_fifo.c */
  918. extern int nv10_fifo_init(struct drm_device *);
  919. extern int nv10_fifo_channel_id(struct drm_device *);
  920. extern int nv10_fifo_create_context(struct nouveau_channel *);
  921. extern int nv10_fifo_load_context(struct nouveau_channel *);
  922. extern int nv10_fifo_unload_context(struct drm_device *);
  923. /* nv40_fifo.c */
  924. extern int nv40_fifo_init(struct drm_device *);
  925. extern int nv40_fifo_create_context(struct nouveau_channel *);
  926. extern int nv40_fifo_load_context(struct nouveau_channel *);
  927. extern int nv40_fifo_unload_context(struct drm_device *);
  928. /* nv50_fifo.c */
  929. extern int nv50_fifo_init(struct drm_device *);
  930. extern void nv50_fifo_takedown(struct drm_device *);
  931. extern int nv50_fifo_channel_id(struct drm_device *);
  932. extern int nv50_fifo_create_context(struct nouveau_channel *);
  933. extern void nv50_fifo_destroy_context(struct nouveau_channel *);
  934. extern int nv50_fifo_load_context(struct nouveau_channel *);
  935. extern int nv50_fifo_unload_context(struct drm_device *);
  936. extern void nv50_fifo_tlb_flush(struct drm_device *dev);
  937. /* nvc0_fifo.c */
  938. extern int nvc0_fifo_init(struct drm_device *);
  939. extern void nvc0_fifo_takedown(struct drm_device *);
  940. extern void nvc0_fifo_disable(struct drm_device *);
  941. extern void nvc0_fifo_enable(struct drm_device *);
  942. extern bool nvc0_fifo_reassign(struct drm_device *, bool);
  943. extern bool nvc0_fifo_cache_pull(struct drm_device *, bool);
  944. extern int nvc0_fifo_channel_id(struct drm_device *);
  945. extern int nvc0_fifo_create_context(struct nouveau_channel *);
  946. extern void nvc0_fifo_destroy_context(struct nouveau_channel *);
  947. extern int nvc0_fifo_load_context(struct nouveau_channel *);
  948. extern int nvc0_fifo_unload_context(struct drm_device *);
  949. /* nv04_graph.c */
  950. extern int nv04_graph_create(struct drm_device *);
  951. extern void nv04_graph_fifo_access(struct drm_device *, bool);
  952. extern int nv04_graph_object_new(struct nouveau_channel *, int, u32, u16);
  953. extern int nv04_graph_mthd_page_flip(struct nouveau_channel *chan,
  954. u32 class, u32 mthd, u32 data);
  955. extern struct nouveau_bitfield nv04_graph_nsource[];
  956. /* nv10_graph.c */
  957. extern int nv10_graph_create(struct drm_device *);
  958. extern struct nouveau_channel *nv10_graph_channel(struct drm_device *);
  959. extern struct nouveau_bitfield nv10_graph_intr[];
  960. extern struct nouveau_bitfield nv10_graph_nstatus[];
  961. /* nv20_graph.c */
  962. extern int nv20_graph_create(struct drm_device *);
  963. /* nv40_graph.c */
  964. extern int nv40_graph_create(struct drm_device *);
  965. extern void nv40_grctx_init(struct nouveau_grctx *);
  966. /* nv50_graph.c */
  967. extern int nv50_graph_create(struct drm_device *);
  968. extern int nv50_grctx_init(struct nouveau_grctx *);
  969. extern struct nouveau_enum nv50_data_error_names[];
  970. extern int nv50_graph_isr_chid(struct drm_device *dev, u64 inst);
  971. /* nvc0_graph.c */
  972. extern int nvc0_graph_create(struct drm_device *);
  973. extern int nvc0_graph_isr_chid(struct drm_device *dev, u64 inst);
  974. /* nv84_crypt.c */
  975. extern int nv84_crypt_create(struct drm_device *);
  976. /* nva3_copy.c */
  977. extern int nva3_copy_create(struct drm_device *dev);
  978. /* nvc0_copy.c */
  979. extern int nvc0_copy_create(struct drm_device *dev, int engine);
  980. /* nv40_mpeg.c */
  981. extern int nv40_mpeg_create(struct drm_device *dev);
  982. /* nv50_mpeg.c */
  983. extern int nv50_mpeg_create(struct drm_device *dev);
  984. /* nv04_instmem.c */
  985. extern int nv04_instmem_init(struct drm_device *);
  986. extern void nv04_instmem_takedown(struct drm_device *);
  987. extern int nv04_instmem_suspend(struct drm_device *);
  988. extern void nv04_instmem_resume(struct drm_device *);
  989. extern int nv04_instmem_get(struct nouveau_gpuobj *, u32 size, u32 align);
  990. extern void nv04_instmem_put(struct nouveau_gpuobj *);
  991. extern int nv04_instmem_map(struct nouveau_gpuobj *);
  992. extern void nv04_instmem_unmap(struct nouveau_gpuobj *);
  993. extern void nv04_instmem_flush(struct drm_device *);
  994. /* nv50_instmem.c */
  995. extern int nv50_instmem_init(struct drm_device *);
  996. extern void nv50_instmem_takedown(struct drm_device *);
  997. extern int nv50_instmem_suspend(struct drm_device *);
  998. extern void nv50_instmem_resume(struct drm_device *);
  999. extern int nv50_instmem_get(struct nouveau_gpuobj *, u32 size, u32 align);
  1000. extern void nv50_instmem_put(struct nouveau_gpuobj *);
  1001. extern int nv50_instmem_map(struct nouveau_gpuobj *);
  1002. extern void nv50_instmem_unmap(struct nouveau_gpuobj *);
  1003. extern void nv50_instmem_flush(struct drm_device *);
  1004. extern void nv84_instmem_flush(struct drm_device *);
  1005. /* nvc0_instmem.c */
  1006. extern int nvc0_instmem_init(struct drm_device *);
  1007. extern void nvc0_instmem_takedown(struct drm_device *);
  1008. extern int nvc0_instmem_suspend(struct drm_device *);
  1009. extern void nvc0_instmem_resume(struct drm_device *);
  1010. /* nv04_mc.c */
  1011. extern int nv04_mc_init(struct drm_device *);
  1012. extern void nv04_mc_takedown(struct drm_device *);
  1013. /* nv40_mc.c */
  1014. extern int nv40_mc_init(struct drm_device *);
  1015. extern void nv40_mc_takedown(struct drm_device *);
  1016. /* nv50_mc.c */
  1017. extern int nv50_mc_init(struct drm_device *);
  1018. extern void nv50_mc_takedown(struct drm_device *);
  1019. /* nv04_timer.c */
  1020. extern int nv04_timer_init(struct drm_device *);
  1021. extern uint64_t nv04_timer_read(struct drm_device *);
  1022. extern void nv04_timer_takedown(struct drm_device *);
  1023. extern long nouveau_compat_ioctl(struct file *file, unsigned int cmd,
  1024. unsigned long arg);
  1025. /* nv04_dac.c */
  1026. extern int nv04_dac_create(struct drm_connector *, struct dcb_entry *);
  1027. extern uint32_t nv17_dac_sample_load(struct drm_encoder *encoder);
  1028. extern int nv04_dac_output_offset(struct drm_encoder *encoder);
  1029. extern void nv04_dac_update_dacclk(struct drm_encoder *encoder, bool enable);
  1030. extern bool nv04_dac_in_use(struct drm_encoder *encoder);
  1031. /* nv04_dfp.c */
  1032. extern int nv04_dfp_create(struct drm_connector *, struct dcb_entry *);
  1033. extern int nv04_dfp_get_bound_head(struct drm_device *dev, struct dcb_entry *dcbent);
  1034. extern void nv04_dfp_bind_head(struct drm_device *dev, struct dcb_entry *dcbent,
  1035. int head, bool dl);
  1036. extern void nv04_dfp_disable(struct drm_device *dev, int head);
  1037. extern void nv04_dfp_update_fp_control(struct drm_encoder *encoder, int mode);
  1038. /* nv04_tv.c */
  1039. extern int nv04_tv_identify(struct drm_device *dev, int i2c_index);
  1040. extern int nv04_tv_create(struct drm_connector *, struct dcb_entry *);
  1041. /* nv17_tv.c */
  1042. extern int nv17_tv_create(struct drm_connector *, struct dcb_entry *);
  1043. /* nv04_display.c */
  1044. extern int nv04_display_early_init(struct drm_device *);
  1045. extern void nv04_display_late_takedown(struct drm_device *);
  1046. extern int nv04_display_create(struct drm_device *);
  1047. extern int nv04_display_init(struct drm_device *);
  1048. extern void nv04_display_destroy(struct drm_device *);
  1049. /* nv04_crtc.c */
  1050. extern int nv04_crtc_create(struct drm_device *, int index);
  1051. /* nouveau_bo.c */
  1052. extern struct ttm_bo_driver nouveau_bo_driver;
  1053. extern int nouveau_bo_new(struct drm_device *, struct nouveau_channel *,
  1054. int size, int align, uint32_t flags,
  1055. uint32_t tile_mode, uint32_t tile_flags,
  1056. struct nouveau_bo **);
  1057. extern int nouveau_bo_pin(struct nouveau_bo *, uint32_t flags);
  1058. extern int nouveau_bo_unpin(struct nouveau_bo *);
  1059. extern int nouveau_bo_map(struct nouveau_bo *);
  1060. extern void nouveau_bo_unmap(struct nouveau_bo *);
  1061. extern void nouveau_bo_placement_set(struct nouveau_bo *, uint32_t type,
  1062. uint32_t busy);
  1063. extern u16 nouveau_bo_rd16(struct nouveau_bo *nvbo, unsigned index);
  1064. extern void nouveau_bo_wr16(struct nouveau_bo *nvbo, unsigned index, u16 val);
  1065. extern u32 nouveau_bo_rd32(struct nouveau_bo *nvbo, unsigned index);
  1066. extern void nouveau_bo_wr32(struct nouveau_bo *nvbo, unsigned index, u32 val);
  1067. extern void nouveau_bo_fence(struct nouveau_bo *, struct nouveau_fence *);
  1068. extern int nouveau_bo_validate(struct nouveau_bo *, bool interruptible,
  1069. bool no_wait_reserve, bool no_wait_gpu);
  1070. /* nouveau_fence.c */
  1071. struct nouveau_fence;
  1072. extern int nouveau_fence_init(struct drm_device *);
  1073. extern void nouveau_fence_fini(struct drm_device *);
  1074. extern int nouveau_fence_channel_init(struct nouveau_channel *);
  1075. extern void nouveau_fence_channel_fini(struct nouveau_channel *);
  1076. extern void nouveau_fence_update(struct nouveau_channel *);
  1077. extern int nouveau_fence_new(struct nouveau_channel *, struct nouveau_fence **,
  1078. bool emit);
  1079. extern int nouveau_fence_emit(struct nouveau_fence *);
  1080. extern void nouveau_fence_work(struct nouveau_fence *fence,
  1081. void (*work)(void *priv, bool signalled),
  1082. void *priv);
  1083. struct nouveau_channel *nouveau_fence_channel(struct nouveau_fence *);
  1084. extern bool __nouveau_fence_signalled(void *obj, void *arg);
  1085. extern int __nouveau_fence_wait(void *obj, void *arg, bool lazy, bool intr);
  1086. extern int __nouveau_fence_flush(void *obj, void *arg);
  1087. extern void __nouveau_fence_unref(void **obj);
  1088. extern void *__nouveau_fence_ref(void *obj);
  1089. static inline bool nouveau_fence_signalled(struct nouveau_fence *obj)
  1090. {
  1091. return __nouveau_fence_signalled(obj, NULL);
  1092. }
  1093. static inline int
  1094. nouveau_fence_wait(struct nouveau_fence *obj, bool lazy, bool intr)
  1095. {
  1096. return __nouveau_fence_wait(obj, NULL, lazy, intr);
  1097. }
  1098. extern int nouveau_fence_sync(struct nouveau_fence *, struct nouveau_channel *);
  1099. static inline int nouveau_fence_flush(struct nouveau_fence *obj)
  1100. {
  1101. return __nouveau_fence_flush(obj, NULL);
  1102. }
  1103. static inline void nouveau_fence_unref(struct nouveau_fence **obj)
  1104. {
  1105. __nouveau_fence_unref((void **)obj);
  1106. }
  1107. static inline struct nouveau_fence *nouveau_fence_ref(struct nouveau_fence *obj)
  1108. {
  1109. return __nouveau_fence_ref(obj);
  1110. }
  1111. /* nouveau_gem.c */
  1112. extern int nouveau_gem_new(struct drm_device *, struct nouveau_channel *,
  1113. int size, int align, uint32_t domain,
  1114. uint32_t tile_mode, uint32_t tile_flags,
  1115. struct nouveau_bo **);
  1116. extern int nouveau_gem_object_new(struct drm_gem_object *);
  1117. extern void nouveau_gem_object_del(struct drm_gem_object *);
  1118. extern int nouveau_gem_ioctl_new(struct drm_device *, void *,
  1119. struct drm_file *);
  1120. extern int nouveau_gem_ioctl_pushbuf(struct drm_device *, void *,
  1121. struct drm_file *);
  1122. extern int nouveau_gem_ioctl_cpu_prep(struct drm_device *, void *,
  1123. struct drm_file *);
  1124. extern int nouveau_gem_ioctl_cpu_fini(struct drm_device *, void *,
  1125. struct drm_file *);
  1126. extern int nouveau_gem_ioctl_info(struct drm_device *, void *,
  1127. struct drm_file *);
  1128. /* nouveau_display.c */
  1129. int nouveau_vblank_enable(struct drm_device *dev, int crtc);
  1130. void nouveau_vblank_disable(struct drm_device *dev, int crtc);
  1131. int nouveau_crtc_page_flip(struct drm_crtc *crtc, struct drm_framebuffer *fb,
  1132. struct drm_pending_vblank_event *event);
  1133. int nouveau_finish_page_flip(struct nouveau_channel *,
  1134. struct nouveau_page_flip_state *);
  1135. /* nv10_gpio.c */
  1136. int nv10_gpio_get(struct drm_device *dev, enum dcb_gpio_tag tag);
  1137. int nv10_gpio_set(struct drm_device *dev, enum dcb_gpio_tag tag, int state);
  1138. /* nv50_gpio.c */
  1139. int nv50_gpio_init(struct drm_device *dev);
  1140. void nv50_gpio_fini(struct drm_device *dev);
  1141. int nv50_gpio_get(struct drm_device *dev, enum dcb_gpio_tag tag);
  1142. int nv50_gpio_set(struct drm_device *dev, enum dcb_gpio_tag tag, int state);
  1143. int nv50_gpio_irq_register(struct drm_device *, enum dcb_gpio_tag,
  1144. void (*)(void *, int), void *);
  1145. void nv50_gpio_irq_unregister(struct drm_device *, enum dcb_gpio_tag,
  1146. void (*)(void *, int), void *);
  1147. bool nv50_gpio_irq_enable(struct drm_device *, enum dcb_gpio_tag, bool on);
  1148. /* nv50_calc. */
  1149. int nv50_calc_pll(struct drm_device *, struct pll_lims *, int clk,
  1150. int *N1, int *M1, int *N2, int *M2, int *P);
  1151. int nva3_calc_pll(struct drm_device *, struct pll_lims *,
  1152. int clk, int *N, int *fN, int *M, int *P);
  1153. #ifndef ioread32_native
  1154. #ifdef __BIG_ENDIAN
  1155. #define ioread16_native ioread16be
  1156. #define iowrite16_native iowrite16be
  1157. #define ioread32_native ioread32be
  1158. #define iowrite32_native iowrite32be
  1159. #else /* def __BIG_ENDIAN */
  1160. #define ioread16_native ioread16
  1161. #define iowrite16_native iowrite16
  1162. #define ioread32_native ioread32
  1163. #define iowrite32_native iowrite32
  1164. #endif /* def __BIG_ENDIAN else */
  1165. #endif /* !ioread32_native */
  1166. /* channel control reg access */
  1167. static inline u32 nvchan_rd32(struct nouveau_channel *chan, unsigned reg)
  1168. {
  1169. return ioread32_native(chan->user + reg);
  1170. }
  1171. static inline void nvchan_wr32(struct nouveau_channel *chan,
  1172. unsigned reg, u32 val)
  1173. {
  1174. iowrite32_native(val, chan->user + reg);
  1175. }
  1176. /* register access */
  1177. static inline u32 nv_rd32(struct drm_device *dev, unsigned reg)
  1178. {
  1179. struct drm_nouveau_private *dev_priv = dev->dev_private;
  1180. return ioread32_native(dev_priv->mmio + reg);
  1181. }
  1182. static inline void nv_wr32(struct drm_device *dev, unsigned reg, u32 val)
  1183. {
  1184. struct drm_nouveau_private *dev_priv = dev->dev_private;
  1185. iowrite32_native(val, dev_priv->mmio + reg);
  1186. }
  1187. static inline u32 nv_mask(struct drm_device *dev, u32 reg, u32 mask, u32 val)
  1188. {
  1189. u32 tmp = nv_rd32(dev, reg);
  1190. nv_wr32(dev, reg, (tmp & ~mask) | val);
  1191. return tmp;
  1192. }
  1193. static inline u8 nv_rd08(struct drm_device *dev, unsigned reg)
  1194. {
  1195. struct drm_nouveau_private *dev_priv = dev->dev_private;
  1196. return ioread8(dev_priv->mmio + reg);
  1197. }
  1198. static inline void nv_wr08(struct drm_device *dev, unsigned reg, u8 val)
  1199. {
  1200. struct drm_nouveau_private *dev_priv = dev->dev_private;
  1201. iowrite8(val, dev_priv->mmio + reg);
  1202. }
  1203. #define nv_wait(dev, reg, mask, val) \
  1204. nouveau_wait_eq(dev, 2000000000ULL, (reg), (mask), (val))
  1205. #define nv_wait_ne(dev, reg, mask, val) \
  1206. nouveau_wait_ne(dev, 2000000000ULL, (reg), (mask), (val))
  1207. /* PRAMIN access */
  1208. static inline u32 nv_ri32(struct drm_device *dev, unsigned offset)
  1209. {
  1210. struct drm_nouveau_private *dev_priv = dev->dev_private;
  1211. return ioread32_native(dev_priv->ramin + offset);
  1212. }
  1213. static inline void nv_wi32(struct drm_device *dev, unsigned offset, u32 val)
  1214. {
  1215. struct drm_nouveau_private *dev_priv = dev->dev_private;
  1216. iowrite32_native(val, dev_priv->ramin + offset);
  1217. }
  1218. /* object access */
  1219. extern u32 nv_ro32(struct nouveau_gpuobj *, u32 offset);
  1220. extern void nv_wo32(struct nouveau_gpuobj *, u32 offset, u32 val);
  1221. /*
  1222. * Logging
  1223. * Argument d is (struct drm_device *).
  1224. */
  1225. #define NV_PRINTK(level, d, fmt, arg...) \
  1226. printk(level "[" DRM_NAME "] " DRIVER_NAME " %s: " fmt, \
  1227. pci_name(d->pdev), ##arg)
  1228. #ifndef NV_DEBUG_NOTRACE
  1229. #define NV_DEBUG(d, fmt, arg...) do { \
  1230. if (drm_debug & DRM_UT_DRIVER) { \
  1231. NV_PRINTK(KERN_DEBUG, d, "%s:%d - " fmt, __func__, \
  1232. __LINE__, ##arg); \
  1233. } \
  1234. } while (0)
  1235. #define NV_DEBUG_KMS(d, fmt, arg...) do { \
  1236. if (drm_debug & DRM_UT_KMS) { \
  1237. NV_PRINTK(KERN_DEBUG, d, "%s:%d - " fmt, __func__, \
  1238. __LINE__, ##arg); \
  1239. } \
  1240. } while (0)
  1241. #else
  1242. #define NV_DEBUG(d, fmt, arg...) do { \
  1243. if (drm_debug & DRM_UT_DRIVER) \
  1244. NV_PRINTK(KERN_DEBUG, d, fmt, ##arg); \
  1245. } while (0)
  1246. #define NV_DEBUG_KMS(d, fmt, arg...) do { \
  1247. if (drm_debug & DRM_UT_KMS) \
  1248. NV_PRINTK(KERN_DEBUG, d, fmt, ##arg); \
  1249. } while (0)
  1250. #endif
  1251. #define NV_ERROR(d, fmt, arg...) NV_PRINTK(KERN_ERR, d, fmt, ##arg)
  1252. #define NV_INFO(d, fmt, arg...) NV_PRINTK(KERN_INFO, d, fmt, ##arg)
  1253. #define NV_TRACEWARN(d, fmt, arg...) NV_PRINTK(KERN_NOTICE, d, fmt, ##arg)
  1254. #define NV_TRACE(d, fmt, arg...) NV_PRINTK(KERN_INFO, d, fmt, ##arg)
  1255. #define NV_WARN(d, fmt, arg...) NV_PRINTK(KERN_WARNING, d, fmt, ##arg)
  1256. /* nouveau_reg_debug bitmask */
  1257. enum {
  1258. NOUVEAU_REG_DEBUG_MC = 0x1,
  1259. NOUVEAU_REG_DEBUG_VIDEO = 0x2,
  1260. NOUVEAU_REG_DEBUG_FB = 0x4,
  1261. NOUVEAU_REG_DEBUG_EXTDEV = 0x8,
  1262. NOUVEAU_REG_DEBUG_CRTC = 0x10,
  1263. NOUVEAU_REG_DEBUG_RAMDAC = 0x20,
  1264. NOUVEAU_REG_DEBUG_VGACRTC = 0x40,
  1265. NOUVEAU_REG_DEBUG_RMVIO = 0x80,
  1266. NOUVEAU_REG_DEBUG_VGAATTR = 0x100,
  1267. NOUVEAU_REG_DEBUG_EVO = 0x200,
  1268. };
  1269. #define NV_REG_DEBUG(type, dev, fmt, arg...) do { \
  1270. if (nouveau_reg_debug & NOUVEAU_REG_DEBUG_##type) \
  1271. NV_PRINTK(KERN_DEBUG, dev, "%s: " fmt, __func__, ##arg); \
  1272. } while (0)
  1273. static inline bool
  1274. nv_two_heads(struct drm_device *dev)
  1275. {
  1276. struct drm_nouveau_private *dev_priv = dev->dev_private;
  1277. const int impl = dev->pci_device & 0x0ff0;
  1278. if (dev_priv->card_type >= NV_10 && impl != 0x0100 &&
  1279. impl != 0x0150 && impl != 0x01a0 && impl != 0x0200)
  1280. return true;
  1281. return false;
  1282. }
  1283. static inline bool
  1284. nv_gf4_disp_arch(struct drm_device *dev)
  1285. {
  1286. return nv_two_heads(dev) && (dev->pci_device & 0x0ff0) != 0x0110;
  1287. }
  1288. static inline bool
  1289. nv_two_reg_pll(struct drm_device *dev)
  1290. {
  1291. struct drm_nouveau_private *dev_priv = dev->dev_private;
  1292. const int impl = dev->pci_device & 0x0ff0;
  1293. if (impl == 0x0310 || impl == 0x0340 || dev_priv->card_type >= NV_40)
  1294. return true;
  1295. return false;
  1296. }
  1297. static inline bool
  1298. nv_match_device(struct drm_device *dev, unsigned device,
  1299. unsigned sub_vendor, unsigned sub_device)
  1300. {
  1301. return dev->pdev->device == device &&
  1302. dev->pdev->subsystem_vendor == sub_vendor &&
  1303. dev->pdev->subsystem_device == sub_device;
  1304. }
  1305. static inline void *
  1306. nv_engine(struct drm_device *dev, int engine)
  1307. {
  1308. struct drm_nouveau_private *dev_priv = dev->dev_private;
  1309. return (void *)dev_priv->eng[engine];
  1310. }
  1311. /* returns 1 if device is one of the nv4x using the 0x4497 object class,
  1312. * helpful to determine a number of other hardware features
  1313. */
  1314. static inline int
  1315. nv44_graph_class(struct drm_device *dev)
  1316. {
  1317. struct drm_nouveau_private *dev_priv = dev->dev_private;
  1318. if ((dev_priv->chipset & 0xf0) == 0x60)
  1319. return 1;
  1320. return !(0x0baf & (1 << (dev_priv->chipset & 0x0f)));
  1321. }
  1322. /* memory type/access flags, do not match hardware values */
  1323. #define NV_MEM_ACCESS_RO 1
  1324. #define NV_MEM_ACCESS_WO 2
  1325. #define NV_MEM_ACCESS_RW (NV_MEM_ACCESS_RO | NV_MEM_ACCESS_WO)
  1326. #define NV_MEM_ACCESS_SYS 4
  1327. #define NV_MEM_ACCESS_VM 8
  1328. #define NV_MEM_TARGET_VRAM 0
  1329. #define NV_MEM_TARGET_PCI 1
  1330. #define NV_MEM_TARGET_PCI_NOSNOOP 2
  1331. #define NV_MEM_TARGET_VM 3
  1332. #define NV_MEM_TARGET_GART 4
  1333. #define NV_MEM_TYPE_VM 0x7f
  1334. #define NV_MEM_COMP_VM 0x03
  1335. /* NV_SW object class */
  1336. #define NV_SW 0x0000506e
  1337. #define NV_SW_DMA_SEMAPHORE 0x00000060
  1338. #define NV_SW_SEMAPHORE_OFFSET 0x00000064
  1339. #define NV_SW_SEMAPHORE_ACQUIRE 0x00000068
  1340. #define NV_SW_SEMAPHORE_RELEASE 0x0000006c
  1341. #define NV_SW_YIELD 0x00000080
  1342. #define NV_SW_DMA_VBLSEM 0x0000018c
  1343. #define NV_SW_VBLSEM_OFFSET 0x00000400
  1344. #define NV_SW_VBLSEM_RELEASE_VALUE 0x00000404
  1345. #define NV_SW_VBLSEM_RELEASE 0x00000408
  1346. #define NV_SW_PAGE_FLIP 0x00000500
  1347. #endif /* __NOUVEAU_DRV_H__ */