nouveau_drv.h 49 KB

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