nouveau_drv.h 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566
  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 "nouveau@lists.freedesktop.org"
  28. #define DRIVER_NAME "nouveau"
  29. #define DRIVER_DESC "nVidia Riva/TNT/GeForce"
  30. #define DRIVER_DATE "20120316"
  31. #define DRIVER_MAJOR 1
  32. #define DRIVER_MINOR 0
  33. #define DRIVER_PATCHLEVEL 0
  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. spinlock_t lock;
  43. struct list_head channels;
  44. struct nouveau_vm *vm;
  45. };
  46. static inline struct nouveau_fpriv *
  47. nouveau_fpriv(struct drm_file *file_priv)
  48. {
  49. return file_priv ? file_priv->driver_priv : NULL;
  50. }
  51. #define DRM_FILE_PAGE_OFFSET (0x100000000ULL >> PAGE_SHIFT)
  52. #include <nouveau_drm.h>
  53. #include "nouveau_reg.h"
  54. #include <nouveau_bios.h>
  55. #include "nouveau_util.h"
  56. struct nouveau_grctx;
  57. struct nouveau_mem;
  58. #include <subdev/vm.h>
  59. #include <subdev/bios/pll.h>
  60. #include "nouveau_compat.h"
  61. #define MAX_NUM_DCB_ENTRIES 16
  62. #define NOUVEAU_MAX_CHANNEL_NR 4096
  63. #define NOUVEAU_MAX_TILE_NR 15
  64. struct nouveau_mem {
  65. struct drm_device *dev;
  66. struct nouveau_vma bar_vma;
  67. struct nouveau_vma vma[2];
  68. u8 page_shift;
  69. struct drm_mm_node *tag;
  70. struct list_head regions;
  71. dma_addr_t *pages;
  72. u32 memtype;
  73. u64 offset;
  74. u64 size;
  75. struct sg_table *sg;
  76. };
  77. struct nouveau_tile_reg {
  78. bool used;
  79. uint32_t addr;
  80. uint32_t limit;
  81. uint32_t pitch;
  82. uint32_t zcomp;
  83. struct drm_mm_node *tag_mem;
  84. struct nouveau_fence *fence;
  85. };
  86. struct nouveau_bo {
  87. struct ttm_buffer_object bo;
  88. struct ttm_placement placement;
  89. u32 valid_domains;
  90. u32 placements[3];
  91. u32 busy_placements[3];
  92. struct ttm_bo_kmap_obj kmap;
  93. struct list_head head;
  94. /* protected by ttm_bo_reserve() */
  95. struct drm_file *reserved_by;
  96. struct list_head entry;
  97. int pbbo_index;
  98. bool validate_mapped;
  99. struct list_head vma_list;
  100. unsigned page_shift;
  101. uint32_t tile_mode;
  102. uint32_t tile_flags;
  103. struct nouveau_tile_reg *tile;
  104. struct drm_gem_object *gem;
  105. int pin_refcnt;
  106. struct ttm_bo_kmap_obj dma_buf_vmap;
  107. int vmapping_count;
  108. };
  109. #define nouveau_bo_tile_layout(nvbo) \
  110. ((nvbo)->tile_flags & NOUVEAU_GEM_TILE_LAYOUT_MASK)
  111. static inline struct nouveau_bo *
  112. nouveau_bo(struct ttm_buffer_object *bo)
  113. {
  114. return container_of(bo, struct nouveau_bo, bo);
  115. }
  116. static inline struct nouveau_bo *
  117. nouveau_gem_object(struct drm_gem_object *gem)
  118. {
  119. return gem ? gem->driver_private : NULL;
  120. }
  121. /* TODO: submit equivalent to TTM generic API upstream? */
  122. static inline void __iomem *
  123. nvbo_kmap_obj_iovirtual(struct nouveau_bo *nvbo)
  124. {
  125. bool is_iomem;
  126. void __iomem *ioptr = (void __force __iomem *)ttm_kmap_obj_virtual(
  127. &nvbo->kmap, &is_iomem);
  128. WARN_ON_ONCE(ioptr && !is_iomem);
  129. return ioptr;
  130. }
  131. enum nouveau_flags {
  132. NV_NFORCE = 0x10000000,
  133. NV_NFORCE2 = 0x20000000
  134. };
  135. #define NVOBJ_ENGINE_SW 0
  136. #define NVOBJ_ENGINE_GR 1
  137. #define NVOBJ_ENGINE_CRYPT 2
  138. #define NVOBJ_ENGINE_COPY0 3
  139. #define NVOBJ_ENGINE_COPY1 4
  140. #define NVOBJ_ENGINE_MPEG 5
  141. #define NVOBJ_ENGINE_PPP NVOBJ_ENGINE_MPEG
  142. #define NVOBJ_ENGINE_BSP 6
  143. #define NVOBJ_ENGINE_VP 7
  144. #define NVOBJ_ENGINE_FIFO 14
  145. #define NVOBJ_ENGINE_FENCE 15
  146. #define NVOBJ_ENGINE_NR 16
  147. #define NVOBJ_ENGINE_DISPLAY (NVOBJ_ENGINE_NR + 0) /*XXX*/
  148. #define NVOBJ_FLAG_DONT_MAP (1 << 0)
  149. #define NVOBJ_FLAG_ZERO_ALLOC (1 << 1)
  150. #define NVOBJ_FLAG_ZERO_FREE (1 << 2)
  151. #define NVOBJ_FLAG_VM (1 << 3)
  152. #define NVOBJ_FLAG_VM_USER (1 << 4)
  153. #define NVOBJ_CINST_GLOBAL 0xdeadbeef
  154. struct nouveau_gpuobj {
  155. struct drm_device *dev;
  156. struct kref refcount;
  157. struct list_head list;
  158. void *node;
  159. u32 *suspend;
  160. uint32_t flags;
  161. u32 size;
  162. u32 pinst; /* PRAMIN BAR offset */
  163. u32 cinst; /* Channel offset */
  164. u64 vinst; /* VRAM address */
  165. u64 linst; /* VM address */
  166. uint32_t engine;
  167. uint32_t class;
  168. void (*dtor)(struct drm_device *, struct nouveau_gpuobj *);
  169. void *priv;
  170. };
  171. struct nouveau_page_flip_state {
  172. struct list_head head;
  173. struct drm_pending_vblank_event *event;
  174. int crtc, bpp, pitch, x, y;
  175. uint64_t offset;
  176. };
  177. enum nouveau_channel_mutex_class {
  178. NOUVEAU_UCHANNEL_MUTEX,
  179. NOUVEAU_KCHANNEL_MUTEX
  180. };
  181. struct nouveau_channel {
  182. struct drm_device *dev;
  183. struct list_head list;
  184. int id;
  185. /* references to the channel data structure */
  186. struct kref ref;
  187. /* users of the hardware channel resources, the hardware
  188. * context will be kicked off when it reaches zero. */
  189. atomic_t users;
  190. struct mutex mutex;
  191. /* owner of this fifo */
  192. struct drm_file *file_priv;
  193. /* mapping of the fifo itself */
  194. struct drm_local_map *map;
  195. /* mapping of the regs controlling the fifo */
  196. void __iomem *user;
  197. uint32_t user_get;
  198. uint32_t user_get_hi;
  199. uint32_t user_put;
  200. /* DMA push buffer */
  201. struct nouveau_gpuobj *pushbuf;
  202. struct nouveau_bo *pushbuf_bo;
  203. struct nouveau_vma pushbuf_vma;
  204. uint64_t pushbuf_base;
  205. /* Notifier memory */
  206. struct nouveau_bo *notifier_bo;
  207. struct nouveau_vma notifier_vma;
  208. struct drm_mm notifier_heap;
  209. /* PFIFO context */
  210. struct nouveau_gpuobj *ramfc;
  211. /* Execution engine contexts */
  212. void *engctx[NVOBJ_ENGINE_NR];
  213. /* NV50 VM */
  214. struct nouveau_vm *vm;
  215. struct nouveau_gpuobj *vm_pd;
  216. /* Objects */
  217. struct nouveau_gpuobj *ramin; /* Private instmem */
  218. struct drm_mm ramin_heap; /* Private PRAMIN heap */
  219. struct nouveau_ramht *ramht; /* Hash table */
  220. /* GPU object info for stuff used in-kernel (mm_enabled) */
  221. uint32_t m2mf_ntfy;
  222. uint32_t vram_handle;
  223. uint32_t gart_handle;
  224. bool accel_done;
  225. /* Push buffer state (only for drm's channel on !mm_enabled) */
  226. struct {
  227. int max;
  228. int free;
  229. int cur;
  230. int put;
  231. /* access via pushbuf_bo */
  232. int ib_base;
  233. int ib_max;
  234. int ib_free;
  235. int ib_put;
  236. } dma;
  237. struct {
  238. bool active;
  239. char name[32];
  240. struct drm_info_list info;
  241. } debugfs;
  242. };
  243. struct nouveau_exec_engine {
  244. void (*destroy)(struct drm_device *, int engine);
  245. int (*init)(struct drm_device *, int engine);
  246. int (*fini)(struct drm_device *, int engine, bool suspend);
  247. int (*context_new)(struct nouveau_channel *, int engine);
  248. void (*context_del)(struct nouveau_channel *, int engine);
  249. int (*object_new)(struct nouveau_channel *, int engine,
  250. u32 handle, u16 class);
  251. void (*set_tile_region)(struct drm_device *dev, int i);
  252. void (*tlb_flush)(struct drm_device *, int engine);
  253. };
  254. struct nouveau_instmem_engine {
  255. void *priv;
  256. int (*init)(struct drm_device *dev);
  257. void (*takedown)(struct drm_device *dev);
  258. int (*suspend)(struct drm_device *dev);
  259. void (*resume)(struct drm_device *dev);
  260. int (*get)(struct nouveau_gpuobj *, struct nouveau_channel *,
  261. u32 size, u32 align);
  262. void (*put)(struct nouveau_gpuobj *);
  263. int (*map)(struct nouveau_gpuobj *);
  264. void (*unmap)(struct nouveau_gpuobj *);
  265. void (*flush)(struct drm_device *);
  266. };
  267. struct nouveau_timer_engine {
  268. int (*init)(struct drm_device *dev);
  269. void (*takedown)(struct drm_device *dev);
  270. uint64_t (*read)(struct drm_device *dev);
  271. };
  272. struct nouveau_fb_engine {
  273. int num_tiles;
  274. struct drm_mm tag_heap;
  275. void *priv;
  276. int (*init)(struct drm_device *dev);
  277. void (*takedown)(struct drm_device *dev);
  278. void (*init_tile_region)(struct drm_device *dev, int i,
  279. uint32_t addr, uint32_t size,
  280. uint32_t pitch, uint32_t flags);
  281. void (*set_tile_region)(struct drm_device *dev, int i);
  282. void (*free_tile_region)(struct drm_device *dev, int i);
  283. };
  284. struct nouveau_display_engine {
  285. void *priv;
  286. int (*early_init)(struct drm_device *);
  287. void (*late_takedown)(struct drm_device *);
  288. int (*create)(struct drm_device *);
  289. void (*destroy)(struct drm_device *);
  290. int (*init)(struct drm_device *);
  291. void (*fini)(struct drm_device *);
  292. struct drm_property *dithering_mode;
  293. struct drm_property *dithering_depth;
  294. struct drm_property *underscan_property;
  295. struct drm_property *underscan_hborder_property;
  296. struct drm_property *underscan_vborder_property;
  297. /* not really hue and saturation: */
  298. struct drm_property *vibrant_hue_property;
  299. struct drm_property *color_vibrance_property;
  300. };
  301. struct nouveau_pm_voltage_level {
  302. u32 voltage; /* microvolts */
  303. u8 vid;
  304. };
  305. struct nouveau_pm_voltage {
  306. bool supported;
  307. u8 version;
  308. u8 vid_mask;
  309. struct nouveau_pm_voltage_level *level;
  310. int nr_level;
  311. };
  312. /* Exclusive upper limits */
  313. #define NV_MEM_CL_DDR2_MAX 8
  314. #define NV_MEM_WR_DDR2_MAX 9
  315. #define NV_MEM_CL_DDR3_MAX 17
  316. #define NV_MEM_WR_DDR3_MAX 17
  317. #define NV_MEM_CL_GDDR3_MAX 16
  318. #define NV_MEM_WR_GDDR3_MAX 18
  319. #define NV_MEM_CL_GDDR5_MAX 21
  320. #define NV_MEM_WR_GDDR5_MAX 20
  321. struct nouveau_pm_memtiming {
  322. int id;
  323. u32 reg[9];
  324. u32 mr[4];
  325. u8 tCWL;
  326. u8 odt;
  327. u8 drive_strength;
  328. };
  329. struct nouveau_pm_tbl_header {
  330. u8 version;
  331. u8 header_len;
  332. u8 entry_cnt;
  333. u8 entry_len;
  334. };
  335. struct nouveau_pm_tbl_entry {
  336. u8 tWR;
  337. u8 tWTR;
  338. u8 tCL;
  339. u8 tRC;
  340. u8 empty_4;
  341. u8 tRFC; /* Byte 5 */
  342. u8 empty_6;
  343. u8 tRAS; /* Byte 7 */
  344. u8 empty_8;
  345. u8 tRP; /* Byte 9 */
  346. u8 tRCDRD;
  347. u8 tRCDWR;
  348. u8 tRRD;
  349. u8 tUNK_13;
  350. u8 RAM_FT1; /* 14, a bitmask of random RAM features */
  351. u8 empty_15;
  352. u8 tUNK_16;
  353. u8 empty_17;
  354. u8 tUNK_18;
  355. u8 tCWL;
  356. u8 tUNK_20, tUNK_21;
  357. };
  358. struct nouveau_pm_profile;
  359. struct nouveau_pm_profile_func {
  360. void (*destroy)(struct nouveau_pm_profile *);
  361. void (*init)(struct nouveau_pm_profile *);
  362. void (*fini)(struct nouveau_pm_profile *);
  363. struct nouveau_pm_level *(*select)(struct nouveau_pm_profile *);
  364. };
  365. struct nouveau_pm_profile {
  366. const struct nouveau_pm_profile_func *func;
  367. struct list_head head;
  368. char name[8];
  369. };
  370. #define NOUVEAU_PM_MAX_LEVEL 8
  371. struct nouveau_pm_level {
  372. struct nouveau_pm_profile profile;
  373. struct device_attribute dev_attr;
  374. char name[32];
  375. int id;
  376. struct nouveau_pm_memtiming timing;
  377. u32 memory;
  378. u16 memscript;
  379. u32 core;
  380. u32 shader;
  381. u32 rop;
  382. u32 copy;
  383. u32 daemon;
  384. u32 vdec;
  385. u32 dom6;
  386. u32 unka0; /* nva3:nvc0 */
  387. u32 hub01; /* nvc0- */
  388. u32 hub06; /* nvc0- */
  389. u32 hub07; /* nvc0- */
  390. u32 volt_min; /* microvolts */
  391. u32 volt_max;
  392. u8 fanspeed;
  393. };
  394. struct nouveau_pm_temp_sensor_constants {
  395. u16 offset_constant;
  396. s16 offset_mult;
  397. s16 offset_div;
  398. s16 slope_mult;
  399. s16 slope_div;
  400. };
  401. struct nouveau_pm_threshold_temp {
  402. s16 critical;
  403. s16 down_clock;
  404. s16 fan_boost;
  405. };
  406. struct nouveau_pm_fan {
  407. u32 percent;
  408. u32 min_duty;
  409. u32 max_duty;
  410. u32 pwm_freq;
  411. u32 pwm_divisor;
  412. };
  413. struct nouveau_pm_engine {
  414. struct nouveau_pm_voltage voltage;
  415. struct nouveau_pm_level perflvl[NOUVEAU_PM_MAX_LEVEL];
  416. int nr_perflvl;
  417. struct nouveau_pm_temp_sensor_constants sensor_constants;
  418. struct nouveau_pm_threshold_temp threshold_temp;
  419. struct nouveau_pm_fan fan;
  420. struct nouveau_pm_profile *profile_ac;
  421. struct nouveau_pm_profile *profile_dc;
  422. struct nouveau_pm_profile *profile;
  423. struct list_head profiles;
  424. struct nouveau_pm_level boot;
  425. struct nouveau_pm_level *cur;
  426. struct device *hwmon;
  427. struct notifier_block acpi_nb;
  428. int (*clocks_get)(struct drm_device *, struct nouveau_pm_level *);
  429. void *(*clocks_pre)(struct drm_device *, struct nouveau_pm_level *);
  430. int (*clocks_set)(struct drm_device *, void *);
  431. int (*voltage_get)(struct drm_device *);
  432. int (*voltage_set)(struct drm_device *, int voltage);
  433. int (*pwm_get)(struct drm_device *, int line, u32*, u32*);
  434. int (*pwm_set)(struct drm_device *, int line, u32, u32);
  435. int (*temp_get)(struct drm_device *);
  436. };
  437. struct nouveau_vram_engine {
  438. struct nouveau_mm mm;
  439. int (*init)(struct drm_device *);
  440. void (*takedown)(struct drm_device *dev);
  441. int (*get)(struct drm_device *, u64, u32 align, u32 size_nc,
  442. u32 type, struct nouveau_mem **);
  443. void (*put)(struct drm_device *, struct nouveau_mem **);
  444. bool (*flags_valid)(struct drm_device *, u32 tile_flags);
  445. };
  446. struct nouveau_engine {
  447. struct nouveau_instmem_engine instmem;
  448. struct nouveau_timer_engine timer;
  449. struct nouveau_fb_engine fb;
  450. struct nouveau_display_engine display;
  451. struct nouveau_pm_engine pm;
  452. struct nouveau_vram_engine vram;
  453. };
  454. enum nv04_fp_display_regs {
  455. FP_DISPLAY_END,
  456. FP_TOTAL,
  457. FP_CRTC,
  458. FP_SYNC_START,
  459. FP_SYNC_END,
  460. FP_VALID_START,
  461. FP_VALID_END
  462. };
  463. struct nv04_crtc_reg {
  464. unsigned char MiscOutReg;
  465. uint8_t CRTC[0xa0];
  466. uint8_t CR58[0x10];
  467. uint8_t Sequencer[5];
  468. uint8_t Graphics[9];
  469. uint8_t Attribute[21];
  470. unsigned char DAC[768];
  471. /* PCRTC regs */
  472. uint32_t fb_start;
  473. uint32_t crtc_cfg;
  474. uint32_t cursor_cfg;
  475. uint32_t gpio_ext;
  476. uint32_t crtc_830;
  477. uint32_t crtc_834;
  478. uint32_t crtc_850;
  479. uint32_t crtc_eng_ctrl;
  480. /* PRAMDAC regs */
  481. uint32_t nv10_cursync;
  482. struct nouveau_pll_vals pllvals;
  483. uint32_t ramdac_gen_ctrl;
  484. uint32_t ramdac_630;
  485. uint32_t ramdac_634;
  486. uint32_t tv_setup;
  487. uint32_t tv_vtotal;
  488. uint32_t tv_vskew;
  489. uint32_t tv_vsync_delay;
  490. uint32_t tv_htotal;
  491. uint32_t tv_hskew;
  492. uint32_t tv_hsync_delay;
  493. uint32_t tv_hsync_delay2;
  494. uint32_t fp_horiz_regs[7];
  495. uint32_t fp_vert_regs[7];
  496. uint32_t dither;
  497. uint32_t fp_control;
  498. uint32_t dither_regs[6];
  499. uint32_t fp_debug_0;
  500. uint32_t fp_debug_1;
  501. uint32_t fp_debug_2;
  502. uint32_t fp_margin_color;
  503. uint32_t ramdac_8c0;
  504. uint32_t ramdac_a20;
  505. uint32_t ramdac_a24;
  506. uint32_t ramdac_a34;
  507. uint32_t ctv_regs[38];
  508. };
  509. struct nv04_output_reg {
  510. uint32_t output;
  511. int head;
  512. };
  513. struct nv04_mode_state {
  514. struct nv04_crtc_reg crtc_reg[2];
  515. uint32_t pllsel;
  516. uint32_t sel_clk;
  517. };
  518. enum nouveau_card_type {
  519. NV_04 = 0x04,
  520. NV_10 = 0x10,
  521. NV_20 = 0x20,
  522. NV_30 = 0x30,
  523. NV_40 = 0x40,
  524. NV_50 = 0x50,
  525. NV_C0 = 0xc0,
  526. NV_D0 = 0xd0,
  527. NV_E0 = 0xe0,
  528. };
  529. struct drm_nouveau_private {
  530. struct drm_device *dev;
  531. bool noaccel;
  532. void *newpriv;
  533. /* the card type, takes NV_* as values */
  534. enum nouveau_card_type card_type;
  535. /* exact chipset, derived from NV_PMC_BOOT_0 */
  536. int chipset;
  537. int flags;
  538. u32 crystal;
  539. spinlock_t ramin_lock;
  540. void __iomem *ramin;
  541. u32 ramin_size;
  542. u32 ramin_base;
  543. bool ramin_available;
  544. struct drm_mm ramin_heap;
  545. struct nouveau_exec_engine *eng[NVOBJ_ENGINE_NR];
  546. struct list_head gpuobj_list;
  547. struct list_head classes;
  548. struct nouveau_bo *vga_ram;
  549. /* interrupt handling */
  550. void (*irq_handler[32])(struct drm_device *);
  551. bool msi_enabled;
  552. struct {
  553. struct drm_global_reference mem_global_ref;
  554. struct ttm_bo_global_ref bo_global_ref;
  555. struct ttm_bo_device bdev;
  556. atomic_t validate_sequence;
  557. int (*move)(struct nouveau_channel *,
  558. struct ttm_buffer_object *,
  559. struct ttm_mem_reg *, struct ttm_mem_reg *);
  560. } ttm;
  561. struct {
  562. spinlock_t lock;
  563. struct drm_mm heap;
  564. struct nouveau_bo *bo;
  565. } fence;
  566. struct {
  567. spinlock_t lock;
  568. struct nouveau_channel *ptr[NOUVEAU_MAX_CHANNEL_NR];
  569. } channels;
  570. struct nouveau_engine engine;
  571. struct nouveau_channel *channel;
  572. /* For PFIFO and PGRAPH. */
  573. spinlock_t context_switch_lock;
  574. /* VM/PRAMIN flush, legacy PRAMIN aperture */
  575. spinlock_t vm_lock;
  576. /* RAMIN configuration, RAMFC, RAMHT and RAMRO offsets */
  577. struct nouveau_ramht *ramht;
  578. struct nouveau_gpuobj *ramfc;
  579. struct nouveau_gpuobj *ramro;
  580. uint32_t ramin_rsvd_vram;
  581. struct {
  582. enum {
  583. NOUVEAU_GART_NONE = 0,
  584. NOUVEAU_GART_AGP, /* AGP */
  585. NOUVEAU_GART_PDMA, /* paged dma object */
  586. NOUVEAU_GART_HW /* on-chip gart/vm */
  587. } type;
  588. uint64_t aper_base;
  589. uint64_t aper_size;
  590. uint64_t aper_free;
  591. struct ttm_backend_func *func;
  592. struct {
  593. struct page *page;
  594. dma_addr_t addr;
  595. } dummy;
  596. struct nouveau_gpuobj *sg_ctxdma;
  597. } gart_info;
  598. /* nv10-nv40 tiling regions */
  599. struct {
  600. struct nouveau_tile_reg reg[NOUVEAU_MAX_TILE_NR];
  601. spinlock_t lock;
  602. } tile;
  603. /* VRAM/fb configuration */
  604. enum {
  605. NV_MEM_TYPE_UNKNOWN = 0,
  606. NV_MEM_TYPE_STOLEN,
  607. NV_MEM_TYPE_SGRAM,
  608. NV_MEM_TYPE_SDRAM,
  609. NV_MEM_TYPE_DDR1,
  610. NV_MEM_TYPE_DDR2,
  611. NV_MEM_TYPE_DDR3,
  612. NV_MEM_TYPE_GDDR2,
  613. NV_MEM_TYPE_GDDR3,
  614. NV_MEM_TYPE_GDDR4,
  615. NV_MEM_TYPE_GDDR5
  616. } vram_type;
  617. uint64_t vram_size;
  618. uint64_t vram_sys_base;
  619. bool vram_rank_B;
  620. uint64_t fb_available_size;
  621. uint64_t fb_mappable_pages;
  622. uint64_t fb_aper_free;
  623. int fb_mtrr;
  624. /* BAR control (NV50-) */
  625. struct nouveau_vm *bar1_vm;
  626. struct nouveau_vm *bar3_vm;
  627. /* G8x/G9x virtual address space */
  628. struct nouveau_vm *chan_vm;
  629. struct nvbios vbios;
  630. u8 *mxms;
  631. struct list_head i2c_ports;
  632. struct nv04_mode_state mode_reg;
  633. struct nv04_mode_state saved_reg;
  634. uint32_t saved_vga_font[4][16384];
  635. uint32_t crtc_owner;
  636. uint32_t dac_users[4];
  637. struct backlight_device *backlight;
  638. struct {
  639. struct dentry *channel_root;
  640. } debugfs;
  641. struct nouveau_fbdev *nfbdev;
  642. struct apertures_struct *apertures;
  643. };
  644. static inline struct drm_nouveau_private *
  645. nouveau_private(struct drm_device *dev)
  646. {
  647. return dev->dev_private;
  648. }
  649. static inline struct drm_nouveau_private *
  650. nouveau_bdev(struct ttm_bo_device *bd)
  651. {
  652. return container_of(bd, struct drm_nouveau_private, ttm.bdev);
  653. }
  654. static inline int
  655. nouveau_bo_ref(struct nouveau_bo *ref, struct nouveau_bo **pnvbo)
  656. {
  657. struct nouveau_bo *prev;
  658. if (!pnvbo)
  659. return -EINVAL;
  660. prev = *pnvbo;
  661. *pnvbo = ref ? nouveau_bo(ttm_bo_reference(&ref->bo)) : NULL;
  662. if (prev) {
  663. struct ttm_buffer_object *bo = &prev->bo;
  664. ttm_bo_unref(&bo);
  665. }
  666. return 0;
  667. }
  668. /* nouveau_drv.c */
  669. extern int nouveau_modeset;
  670. extern int nouveau_duallink;
  671. extern int nouveau_uscript_lvds;
  672. extern int nouveau_uscript_tmds;
  673. extern int nouveau_vram_pushbuf;
  674. extern int nouveau_vram_notify;
  675. extern char *nouveau_vram_type;
  676. extern int nouveau_fbpercrtc;
  677. extern int nouveau_tv_disable;
  678. extern char *nouveau_tv_norm;
  679. extern int nouveau_reg_debug;
  680. extern int nouveau_ignorelid;
  681. extern int nouveau_nofbaccel;
  682. extern int nouveau_noaccel;
  683. extern int nouveau_force_post;
  684. extern int nouveau_override_conntype;
  685. extern char *nouveau_perflvl;
  686. extern int nouveau_perflvl_wr;
  687. extern int nouveau_msi;
  688. extern int nouveau_ctxfw;
  689. extern int nouveau_mxmdcb;
  690. extern int nouveau_pci_suspend(struct pci_dev *pdev, pm_message_t pm_state);
  691. extern int nouveau_pci_resume(struct pci_dev *pdev);
  692. /* nouveau_state.c */
  693. extern int nouveau_open(struct drm_device *, struct drm_file *);
  694. extern void nouveau_preclose(struct drm_device *dev, struct drm_file *);
  695. extern void nouveau_postclose(struct drm_device *, struct drm_file *);
  696. extern int nouveau_load(struct drm_device *, unsigned long flags);
  697. extern int nouveau_firstopen(struct drm_device *);
  698. extern void nouveau_lastclose(struct drm_device *);
  699. extern int nouveau_unload(struct drm_device *);
  700. extern bool nouveau_wait_eq(struct drm_device *, uint64_t timeout,
  701. uint32_t reg, uint32_t mask, uint32_t val);
  702. extern bool nouveau_wait_ne(struct drm_device *, uint64_t timeout,
  703. uint32_t reg, uint32_t mask, uint32_t val);
  704. extern bool nouveau_wait_cb(struct drm_device *, u64 timeout,
  705. bool (*cond)(void *), void *);
  706. extern bool nouveau_wait_for_idle(struct drm_device *);
  707. extern int nouveau_card_init(struct drm_device *);
  708. /* nouveau_mem.c */
  709. extern int nouveau_mem_vram_init(struct drm_device *);
  710. extern void nouveau_mem_vram_fini(struct drm_device *);
  711. extern int nouveau_mem_gart_init(struct drm_device *);
  712. extern void nouveau_mem_gart_fini(struct drm_device *);
  713. extern void nouveau_mem_close(struct drm_device *);
  714. extern bool nouveau_mem_flags_valid(struct drm_device *, u32 tile_flags);
  715. extern int nouveau_mem_timing_calc(struct drm_device *, u32 freq,
  716. struct nouveau_pm_memtiming *);
  717. extern void nouveau_mem_timing_read(struct drm_device *,
  718. struct nouveau_pm_memtiming *);
  719. extern int nouveau_mem_vbios_type(struct drm_device *);
  720. extern struct nouveau_tile_reg *nv10_mem_set_tiling(
  721. struct drm_device *dev, uint32_t addr, uint32_t size,
  722. uint32_t pitch, uint32_t flags);
  723. extern void nv10_mem_put_tile_region(struct drm_device *dev,
  724. struct nouveau_tile_reg *tile,
  725. struct nouveau_fence *fence);
  726. extern const struct ttm_mem_type_manager_func nouveau_vram_manager;
  727. extern const struct ttm_mem_type_manager_func nouveau_gart_manager;
  728. /* nouveau_notifier.c */
  729. extern int nouveau_notifier_init_channel(struct nouveau_channel *);
  730. extern void nouveau_notifier_takedown_channel(struct nouveau_channel *);
  731. extern int nouveau_notifier_alloc(struct nouveau_channel *, uint32_t handle,
  732. int cout, uint32_t start, uint32_t end,
  733. uint32_t *offset);
  734. /* nouveau_channel.c */
  735. extern void nouveau_channel_cleanup(struct drm_device *, struct drm_file *);
  736. extern int nouveau_channel_alloc(struct drm_device *dev,
  737. struct nouveau_channel **chan,
  738. struct drm_file *file_priv,
  739. uint32_t fb_ctxdma, uint32_t tt_ctxdma);
  740. extern struct nouveau_channel *
  741. nouveau_channel_get_unlocked(struct nouveau_channel *);
  742. extern struct nouveau_channel *
  743. nouveau_channel_get(struct drm_file *, int id);
  744. extern void nouveau_channel_put_unlocked(struct nouveau_channel **);
  745. extern void nouveau_channel_put(struct nouveau_channel **);
  746. extern void nouveau_channel_ref(struct nouveau_channel *chan,
  747. struct nouveau_channel **pchan);
  748. extern int nouveau_channel_idle(struct nouveau_channel *chan);
  749. /* nouveau_gpuobj.c */
  750. #define NVOBJ_ENGINE_ADD(d, e, p) do { \
  751. struct drm_nouveau_private *dev_priv = (d)->dev_private; \
  752. dev_priv->eng[NVOBJ_ENGINE_##e] = (p); \
  753. } while (0)
  754. #define NVOBJ_ENGINE_DEL(d, e) do { \
  755. struct drm_nouveau_private *dev_priv = (d)->dev_private; \
  756. dev_priv->eng[NVOBJ_ENGINE_##e] = NULL; \
  757. } while (0)
  758. #define NVOBJ_CLASS(d, c, e) do { \
  759. int ret = nouveau_gpuobj_class_new((d), (c), NVOBJ_ENGINE_##e); \
  760. if (ret) \
  761. return ret; \
  762. } while (0)
  763. #define NVOBJ_MTHD(d, c, m, e) do { \
  764. int ret = nouveau_gpuobj_mthd_new((d), (c), (m), (e)); \
  765. if (ret) \
  766. return ret; \
  767. } while (0)
  768. extern int nouveau_gpuobj_early_init(struct drm_device *);
  769. extern int nouveau_gpuobj_init(struct drm_device *);
  770. extern void nouveau_gpuobj_takedown(struct drm_device *);
  771. extern int nouveau_gpuobj_suspend(struct drm_device *dev);
  772. extern void nouveau_gpuobj_resume(struct drm_device *dev);
  773. extern int nouveau_gpuobj_class_new(struct drm_device *, u32 class, u32 eng);
  774. extern int nouveau_gpuobj_mthd_new(struct drm_device *, u32 class, u32 mthd,
  775. int (*exec)(struct nouveau_channel *,
  776. u32 class, u32 mthd, u32 data));
  777. extern int nouveau_gpuobj_mthd_call(struct nouveau_channel *, u32, u32, u32);
  778. extern int nouveau_gpuobj_mthd_call2(struct drm_device *, int, u32, u32, u32);
  779. extern int nouveau_gpuobj_channel_init(struct nouveau_channel *,
  780. uint32_t vram_h, uint32_t tt_h);
  781. extern void nouveau_gpuobj_channel_takedown(struct nouveau_channel *);
  782. extern int nouveau_gpuobj_new(struct drm_device *, struct nouveau_channel *,
  783. uint32_t size, int align, uint32_t flags,
  784. struct nouveau_gpuobj **);
  785. extern void nouveau_gpuobj_ref(struct nouveau_gpuobj *,
  786. struct nouveau_gpuobj **);
  787. extern int nouveau_gpuobj_new_fake(struct drm_device *, u32 pinst, u64 vinst,
  788. u32 size, u32 flags,
  789. struct nouveau_gpuobj **);
  790. extern int nouveau_gpuobj_dma_new(struct nouveau_channel *, int class,
  791. uint64_t offset, uint64_t size, int access,
  792. int target, struct nouveau_gpuobj **);
  793. extern int nouveau_gpuobj_gr_new(struct nouveau_channel *, u32 handle, int class);
  794. extern int nv50_gpuobj_dma_new(struct nouveau_channel *, int class, u64 base,
  795. u64 size, int target, int access, u32 type,
  796. u32 comp, struct nouveau_gpuobj **pobj);
  797. extern void nv50_gpuobj_dma_init(struct nouveau_gpuobj *, u32 offset,
  798. int class, u64 base, u64 size, int target,
  799. int access, u32 type, u32 comp);
  800. /* nouveau_irq.c */
  801. extern int nouveau_irq_init(struct drm_device *);
  802. extern void nouveau_irq_fini(struct drm_device *);
  803. extern irqreturn_t nouveau_irq_handler(DRM_IRQ_ARGS);
  804. extern void nouveau_irq_register(struct drm_device *, int status_bit,
  805. void (*)(struct drm_device *));
  806. extern void nouveau_irq_unregister(struct drm_device *, int status_bit);
  807. extern void nouveau_irq_preinstall(struct drm_device *);
  808. extern int nouveau_irq_postinstall(struct drm_device *);
  809. extern void nouveau_irq_uninstall(struct drm_device *);
  810. /* nouveau_sgdma.c */
  811. extern int nouveau_sgdma_init(struct drm_device *);
  812. extern void nouveau_sgdma_takedown(struct drm_device *);
  813. extern uint32_t nouveau_sgdma_get_physical(struct drm_device *,
  814. uint32_t offset);
  815. extern struct ttm_tt *nouveau_sgdma_create_ttm(struct ttm_bo_device *bdev,
  816. unsigned long size,
  817. uint32_t page_flags,
  818. struct page *dummy_read_page);
  819. /* nouveau_debugfs.c */
  820. #if defined(CONFIG_DRM_NOUVEAU_DEBUG)
  821. extern int nouveau_debugfs_init(struct drm_minor *);
  822. extern void nouveau_debugfs_takedown(struct drm_minor *);
  823. extern int nouveau_debugfs_channel_init(struct nouveau_channel *);
  824. extern void nouveau_debugfs_channel_fini(struct nouveau_channel *);
  825. #else
  826. static inline int
  827. nouveau_debugfs_init(struct drm_minor *minor)
  828. {
  829. return 0;
  830. }
  831. static inline void nouveau_debugfs_takedown(struct drm_minor *minor)
  832. {
  833. }
  834. static inline int
  835. nouveau_debugfs_channel_init(struct nouveau_channel *chan)
  836. {
  837. return 0;
  838. }
  839. static inline void
  840. nouveau_debugfs_channel_fini(struct nouveau_channel *chan)
  841. {
  842. }
  843. #endif
  844. /* nouveau_dma.c */
  845. extern void nouveau_dma_init(struct nouveau_channel *);
  846. extern int nouveau_dma_wait(struct nouveau_channel *, int slots, int size);
  847. /* nouveau_acpi.c */
  848. #define ROM_BIOS_PAGE 4096
  849. #if defined(CONFIG_ACPI)
  850. void nouveau_register_dsm_handler(void);
  851. void nouveau_unregister_dsm_handler(void);
  852. void nouveau_switcheroo_optimus_dsm(void);
  853. int nouveau_acpi_get_bios_chunk(uint8_t *bios, int offset, int len);
  854. bool nouveau_acpi_rom_supported(struct pci_dev *pdev);
  855. int nouveau_acpi_edid(struct drm_device *, struct drm_connector *);
  856. #else
  857. static inline void nouveau_register_dsm_handler(void) {}
  858. static inline void nouveau_unregister_dsm_handler(void) {}
  859. static inline void nouveau_switcheroo_optimus_dsm(void) {}
  860. static inline bool nouveau_acpi_rom_supported(struct pci_dev *pdev) { return false; }
  861. static inline int nouveau_acpi_get_bios_chunk(uint8_t *bios, int offset, int len) { return -EINVAL; }
  862. static inline int nouveau_acpi_edid(struct drm_device *dev, struct drm_connector *connector) { return -EINVAL; }
  863. #endif
  864. /* nouveau_backlight.c */
  865. #ifdef CONFIG_DRM_NOUVEAU_BACKLIGHT
  866. extern int nouveau_backlight_init(struct drm_device *);
  867. extern void nouveau_backlight_exit(struct drm_device *);
  868. #else
  869. static inline int nouveau_backlight_init(struct drm_device *dev)
  870. {
  871. return 0;
  872. }
  873. static inline void nouveau_backlight_exit(struct drm_device *dev) { }
  874. #endif
  875. /* nouveau_bios.c */
  876. extern int nouveau_bios_init(struct drm_device *);
  877. extern void nouveau_bios_takedown(struct drm_device *dev);
  878. extern int nouveau_run_vbios_init(struct drm_device *);
  879. extern struct dcb_connector_table_entry *
  880. nouveau_bios_connector_entry(struct drm_device *, int index);
  881. extern int nouveau_bios_run_display_table(struct drm_device *, u16 id, int clk,
  882. struct dcb_output *, int crtc);
  883. extern bool nouveau_bios_fp_mode(struct drm_device *, struct drm_display_mode *);
  884. extern uint8_t *nouveau_bios_embedded_edid(struct drm_device *);
  885. extern int nouveau_bios_parse_lvds_table(struct drm_device *, int pxclk,
  886. bool *dl, bool *if_is_24bit);
  887. extern int run_tmds_table(struct drm_device *, struct dcb_output *,
  888. int head, int pxclk);
  889. extern int call_lvds_script(struct drm_device *, struct dcb_output *, int head,
  890. enum LVDS_script, int pxclk);
  891. bool bios_encoder_match(struct dcb_output *, u32 hash);
  892. /* nouveau_mxm.c */
  893. int nouveau_mxm_init(struct drm_device *dev);
  894. void nouveau_mxm_fini(struct drm_device *dev);
  895. /* nouveau_ttm.c */
  896. int nouveau_ttm_global_init(struct drm_nouveau_private *);
  897. void nouveau_ttm_global_release(struct drm_nouveau_private *);
  898. int nouveau_ttm_mmap(struct file *, struct vm_area_struct *);
  899. /* nouveau_hdmi.c */
  900. void nouveau_hdmi_mode_set(struct drm_encoder *, struct drm_display_mode *);
  901. /* nv04_fb.c */
  902. extern int nv04_fb_vram_init(struct drm_device *);
  903. extern int nv04_fb_init(struct drm_device *);
  904. extern void nv04_fb_takedown(struct drm_device *);
  905. /* nv10_fb.c */
  906. extern int nv10_fb_vram_init(struct drm_device *dev);
  907. extern int nv1a_fb_vram_init(struct drm_device *dev);
  908. extern int nv10_fb_init(struct drm_device *);
  909. extern void nv10_fb_takedown(struct drm_device *);
  910. extern void nv10_fb_init_tile_region(struct drm_device *dev, int i,
  911. uint32_t addr, uint32_t size,
  912. uint32_t pitch, uint32_t flags);
  913. extern void nv10_fb_set_tile_region(struct drm_device *dev, int i);
  914. extern void nv10_fb_free_tile_region(struct drm_device *dev, int i);
  915. /* nv20_fb.c */
  916. extern int nv20_fb_vram_init(struct drm_device *dev);
  917. extern int nv20_fb_init(struct drm_device *);
  918. extern void nv20_fb_takedown(struct drm_device *);
  919. extern void nv20_fb_init_tile_region(struct drm_device *dev, int i,
  920. uint32_t addr, uint32_t size,
  921. uint32_t pitch, uint32_t flags);
  922. extern void nv20_fb_set_tile_region(struct drm_device *dev, int i);
  923. extern void nv20_fb_free_tile_region(struct drm_device *dev, int i);
  924. /* nv30_fb.c */
  925. extern int nv30_fb_init(struct drm_device *);
  926. extern void nv30_fb_takedown(struct drm_device *);
  927. extern void nv30_fb_init_tile_region(struct drm_device *dev, int i,
  928. uint32_t addr, uint32_t size,
  929. uint32_t pitch, uint32_t flags);
  930. extern void nv30_fb_free_tile_region(struct drm_device *dev, int i);
  931. /* nv40_fb.c */
  932. extern int nv40_fb_vram_init(struct drm_device *dev);
  933. extern int nv40_fb_init(struct drm_device *);
  934. extern void nv40_fb_takedown(struct drm_device *);
  935. extern void nv40_fb_set_tile_region(struct drm_device *dev, int i);
  936. /* nv50_fb.c */
  937. extern int nv50_fb_init(struct drm_device *);
  938. extern void nv50_fb_takedown(struct drm_device *);
  939. extern void nv50_fb_vm_trap(struct drm_device *, int display);
  940. /* nvc0_fb.c */
  941. extern int nvc0_fb_init(struct drm_device *);
  942. extern void nvc0_fb_takedown(struct drm_device *);
  943. /* nv04_graph.c */
  944. extern int nv04_graph_create(struct drm_device *);
  945. extern int nv04_graph_object_new(struct nouveau_channel *, int, u32, u16);
  946. extern int nv04_graph_mthd_page_flip(struct nouveau_channel *chan,
  947. u32 class, u32 mthd, u32 data);
  948. extern struct nouveau_bitfield nv04_graph_nsource[];
  949. /* nv10_graph.c */
  950. extern int nv10_graph_create(struct drm_device *);
  951. extern struct nouveau_channel *nv10_graph_channel(struct drm_device *);
  952. extern struct nouveau_bitfield nv10_graph_intr[];
  953. extern struct nouveau_bitfield nv10_graph_nstatus[];
  954. /* nv20_graph.c */
  955. extern int nv20_graph_create(struct drm_device *);
  956. /* nv40_graph.c */
  957. extern int nv40_graph_create(struct drm_device *);
  958. extern void nv40_grctx_init(struct drm_device *, u32 *size);
  959. extern void nv40_grctx_fill(struct drm_device *, struct nouveau_gpuobj *);
  960. /* nv50_graph.c */
  961. extern int nv50_graph_create(struct drm_device *);
  962. extern struct nouveau_enum nv50_data_error_names[];
  963. extern int nv50_graph_isr_chid(struct drm_device *dev, u64 inst);
  964. extern int nv50_grctx_init(struct drm_device *, u32 *, u32, u32 *, u32 *);
  965. extern void nv50_grctx_fill(struct drm_device *, struct nouveau_gpuobj *);
  966. /* nvc0_graph.c */
  967. extern int nvc0_graph_create(struct drm_device *);
  968. extern int nvc0_graph_isr_chid(struct drm_device *dev, u64 inst);
  969. /* nve0_graph.c */
  970. extern int nve0_graph_create(struct drm_device *);
  971. /* nv84_crypt.c */
  972. extern int nv84_crypt_create(struct drm_device *);
  973. /* nv98_crypt.c */
  974. extern int nv98_crypt_create(struct drm_device *dev);
  975. /* nva3_copy.c */
  976. extern int nva3_copy_create(struct drm_device *dev);
  977. /* nvc0_copy.c */
  978. extern int nvc0_copy_create(struct drm_device *dev, int engine);
  979. /* nv31_mpeg.c */
  980. extern int nv31_mpeg_create(struct drm_device *dev);
  981. /* nv50_mpeg.c */
  982. extern int nv50_mpeg_create(struct drm_device *dev);
  983. /* nv84_bsp.c */
  984. /* nv98_bsp.c */
  985. extern int nv84_bsp_create(struct drm_device *dev);
  986. /* nv84_vp.c */
  987. /* nv98_vp.c */
  988. extern int nv84_vp_create(struct drm_device *dev);
  989. /* nv98_ppp.c */
  990. extern int nv98_ppp_create(struct drm_device *dev);
  991. /* nv04_instmem.c */
  992. extern int nv04_instmem_init(struct drm_device *);
  993. extern void nv04_instmem_takedown(struct drm_device *);
  994. extern int nv04_instmem_suspend(struct drm_device *);
  995. extern void nv04_instmem_resume(struct drm_device *);
  996. extern int nv04_instmem_get(struct nouveau_gpuobj *, struct nouveau_channel *,
  997. u32 size, u32 align);
  998. extern void nv04_instmem_put(struct nouveau_gpuobj *);
  999. extern int nv04_instmem_map(struct nouveau_gpuobj *);
  1000. extern void nv04_instmem_unmap(struct nouveau_gpuobj *);
  1001. extern void nv04_instmem_flush(struct drm_device *);
  1002. /* nv50_instmem.c */
  1003. extern int nv50_instmem_init(struct drm_device *);
  1004. extern void nv50_instmem_takedown(struct drm_device *);
  1005. extern int nv50_instmem_suspend(struct drm_device *);
  1006. extern void nv50_instmem_resume(struct drm_device *);
  1007. extern int nv50_instmem_get(struct nouveau_gpuobj *, struct nouveau_channel *,
  1008. u32 size, u32 align);
  1009. extern void nv50_instmem_put(struct nouveau_gpuobj *);
  1010. extern int nv50_instmem_map(struct nouveau_gpuobj *);
  1011. extern void nv50_instmem_unmap(struct nouveau_gpuobj *);
  1012. extern void nv50_instmem_flush(struct drm_device *);
  1013. extern void nv84_instmem_flush(struct drm_device *);
  1014. /* nvc0_instmem.c */
  1015. extern int nvc0_instmem_init(struct drm_device *);
  1016. extern void nvc0_instmem_takedown(struct drm_device *);
  1017. extern int nvc0_instmem_suspend(struct drm_device *);
  1018. extern void nvc0_instmem_resume(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_output *);
  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_output *);
  1033. extern int nv04_dfp_get_bound_head(struct drm_device *dev, struct dcb_output *dcbent);
  1034. extern void nv04_dfp_bind_head(struct drm_device *dev, struct dcb_output *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_output *);
  1041. /* nv17_tv.c */
  1042. extern int nv17_tv_create(struct drm_connector *, struct dcb_output *);
  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 void nv04_display_destroy(struct drm_device *);
  1048. extern int nv04_display_init(struct drm_device *);
  1049. extern void nv04_display_fini(struct drm_device *);
  1050. /* nvd0_display.c */
  1051. extern int nvd0_display_create(struct drm_device *);
  1052. extern void nvd0_display_destroy(struct drm_device *);
  1053. extern int nvd0_display_init(struct drm_device *);
  1054. extern void nvd0_display_fini(struct drm_device *);
  1055. struct nouveau_bo *nvd0_display_crtc_sema(struct drm_device *, int crtc);
  1056. void nvd0_display_flip_stop(struct drm_crtc *);
  1057. int nvd0_display_flip_next(struct drm_crtc *, struct drm_framebuffer *,
  1058. struct nouveau_channel *, u32 swap_interval);
  1059. /* nv04_crtc.c */
  1060. extern int nv04_crtc_create(struct drm_device *, int index);
  1061. /* nouveau_bo.c */
  1062. extern struct ttm_bo_driver nouveau_bo_driver;
  1063. extern void nouveau_bo_move_init(struct nouveau_channel *);
  1064. extern int nouveau_bo_new(struct drm_device *, int size, int align,
  1065. uint32_t flags, uint32_t tile_mode,
  1066. uint32_t tile_flags,
  1067. struct sg_table *sg,
  1068. struct nouveau_bo **);
  1069. extern int nouveau_bo_pin(struct nouveau_bo *, uint32_t flags);
  1070. extern int nouveau_bo_unpin(struct nouveau_bo *);
  1071. extern int nouveau_bo_map(struct nouveau_bo *);
  1072. extern void nouveau_bo_unmap(struct nouveau_bo *);
  1073. extern void nouveau_bo_placement_set(struct nouveau_bo *, uint32_t type,
  1074. uint32_t busy);
  1075. extern u16 nouveau_bo_rd16(struct nouveau_bo *nvbo, unsigned index);
  1076. extern void nouveau_bo_wr16(struct nouveau_bo *nvbo, unsigned index, u16 val);
  1077. extern u32 nouveau_bo_rd32(struct nouveau_bo *nvbo, unsigned index);
  1078. extern void nouveau_bo_wr32(struct nouveau_bo *nvbo, unsigned index, u32 val);
  1079. extern void nouveau_bo_fence(struct nouveau_bo *, struct nouveau_fence *);
  1080. extern int nouveau_bo_validate(struct nouveau_bo *, bool interruptible,
  1081. bool no_wait_reserve, bool no_wait_gpu);
  1082. extern struct nouveau_vma *
  1083. nouveau_bo_vma_find(struct nouveau_bo *, struct nouveau_vm *);
  1084. extern int nouveau_bo_vma_add(struct nouveau_bo *, struct nouveau_vm *,
  1085. struct nouveau_vma *);
  1086. extern void nouveau_bo_vma_del(struct nouveau_bo *, struct nouveau_vma *);
  1087. /* nouveau_gem.c */
  1088. extern int nouveau_gem_new(struct drm_device *, int size, int align,
  1089. uint32_t domain, uint32_t tile_mode,
  1090. uint32_t tile_flags, struct nouveau_bo **);
  1091. extern int nouveau_gem_object_new(struct drm_gem_object *);
  1092. extern void nouveau_gem_object_del(struct drm_gem_object *);
  1093. extern int nouveau_gem_object_open(struct drm_gem_object *, struct drm_file *);
  1094. extern void nouveau_gem_object_close(struct drm_gem_object *,
  1095. struct drm_file *);
  1096. extern int nouveau_gem_ioctl_new(struct drm_device *, void *,
  1097. struct drm_file *);
  1098. extern int nouveau_gem_ioctl_pushbuf(struct drm_device *, void *,
  1099. struct drm_file *);
  1100. extern int nouveau_gem_ioctl_cpu_prep(struct drm_device *, void *,
  1101. struct drm_file *);
  1102. extern int nouveau_gem_ioctl_cpu_fini(struct drm_device *, void *,
  1103. struct drm_file *);
  1104. extern int nouveau_gem_ioctl_info(struct drm_device *, void *,
  1105. struct drm_file *);
  1106. extern struct dma_buf *nouveau_gem_prime_export(struct drm_device *dev,
  1107. struct drm_gem_object *obj, int flags);
  1108. extern struct drm_gem_object *nouveau_gem_prime_import(struct drm_device *dev,
  1109. struct dma_buf *dma_buf);
  1110. /* nouveau_display.c */
  1111. int nouveau_display_create(struct drm_device *dev);
  1112. void nouveau_display_destroy(struct drm_device *dev);
  1113. int nouveau_display_init(struct drm_device *dev);
  1114. void nouveau_display_fini(struct drm_device *dev);
  1115. int nouveau_vblank_enable(struct drm_device *dev, int crtc);
  1116. void nouveau_vblank_disable(struct drm_device *dev, int crtc);
  1117. int nouveau_crtc_page_flip(struct drm_crtc *crtc, struct drm_framebuffer *fb,
  1118. struct drm_pending_vblank_event *event);
  1119. int nouveau_finish_page_flip(struct nouveau_channel *,
  1120. struct nouveau_page_flip_state *);
  1121. int nouveau_display_dumb_create(struct drm_file *, struct drm_device *,
  1122. struct drm_mode_create_dumb *args);
  1123. int nouveau_display_dumb_map_offset(struct drm_file *, struct drm_device *,
  1124. uint32_t handle, uint64_t *offset);
  1125. int nouveau_display_dumb_destroy(struct drm_file *, struct drm_device *,
  1126. uint32_t handle);
  1127. #ifndef ioread32_native
  1128. #ifdef __BIG_ENDIAN
  1129. #define ioread16_native ioread16be
  1130. #define iowrite16_native iowrite16be
  1131. #define ioread32_native ioread32be
  1132. #define iowrite32_native iowrite32be
  1133. #else /* def __BIG_ENDIAN */
  1134. #define ioread16_native ioread16
  1135. #define iowrite16_native iowrite16
  1136. #define ioread32_native ioread32
  1137. #define iowrite32_native iowrite32
  1138. #endif /* def __BIG_ENDIAN else */
  1139. #endif /* !ioread32_native */
  1140. /* channel control reg access */
  1141. static inline u32 nvchan_rd32(struct nouveau_channel *chan, unsigned reg)
  1142. {
  1143. return ioread32_native(chan->user + reg);
  1144. }
  1145. static inline void nvchan_wr32(struct nouveau_channel *chan,
  1146. unsigned reg, u32 val)
  1147. {
  1148. iowrite32_native(val, chan->user + reg);
  1149. }
  1150. /* register access */
  1151. #define nv_rd08 _nv_rd08
  1152. #define nv_wr08 _nv_wr08
  1153. #define nv_rd32 _nv_rd32
  1154. #define nv_wr32 _nv_wr32
  1155. #define nv_mask _nv_mask
  1156. #define nv_wait(dev, reg, mask, val) \
  1157. nouveau_wait_eq(dev, 2000000000ULL, (reg), (mask), (val))
  1158. #define nv_wait_ne(dev, reg, mask, val) \
  1159. nouveau_wait_ne(dev, 2000000000ULL, (reg), (mask), (val))
  1160. #define nv_wait_cb(dev, func, data) \
  1161. nouveau_wait_cb(dev, 2000000000ULL, (func), (data))
  1162. /* PRAMIN access */
  1163. static inline u32 nv_ri32(struct drm_device *dev, unsigned offset)
  1164. {
  1165. struct drm_nouveau_private *dev_priv = dev->dev_private;
  1166. return ioread32_native(dev_priv->ramin + offset);
  1167. }
  1168. static inline void nv_wi32(struct drm_device *dev, unsigned offset, u32 val)
  1169. {
  1170. struct drm_nouveau_private *dev_priv = dev->dev_private;
  1171. iowrite32_native(val, dev_priv->ramin + offset);
  1172. }
  1173. /* object access */
  1174. extern u32 nv_ro32(struct nouveau_gpuobj *, u32 offset);
  1175. extern void nv_wo32(struct nouveau_gpuobj *, u32 offset, u32 val);
  1176. /*
  1177. * Logging
  1178. * Argument d is (struct drm_device *).
  1179. */
  1180. #define NV_PRINTK(level, d, fmt, arg...) \
  1181. printk(level "[" DRM_NAME "] " DRIVER_NAME " %s: " fmt, \
  1182. pci_name(d->pdev), ##arg)
  1183. #ifndef NV_DEBUG_NOTRACE
  1184. #define NV_DEBUG(d, fmt, arg...) do { \
  1185. if (drm_debug & DRM_UT_DRIVER) { \
  1186. NV_PRINTK(KERN_DEBUG, d, "%s:%d - " fmt, __func__, \
  1187. __LINE__, ##arg); \
  1188. } \
  1189. } while (0)
  1190. #define NV_DEBUG_KMS(d, fmt, arg...) do { \
  1191. if (drm_debug & DRM_UT_KMS) { \
  1192. NV_PRINTK(KERN_DEBUG, d, "%s:%d - " fmt, __func__, \
  1193. __LINE__, ##arg); \
  1194. } \
  1195. } while (0)
  1196. #else
  1197. #define NV_DEBUG(d, fmt, arg...) do { \
  1198. if (drm_debug & DRM_UT_DRIVER) \
  1199. NV_PRINTK(KERN_DEBUG, d, fmt, ##arg); \
  1200. } while (0)
  1201. #define NV_DEBUG_KMS(d, fmt, arg...) do { \
  1202. if (drm_debug & DRM_UT_KMS) \
  1203. NV_PRINTK(KERN_DEBUG, d, fmt, ##arg); \
  1204. } while (0)
  1205. #endif
  1206. #define NV_ERROR(d, fmt, arg...) NV_PRINTK(KERN_ERR, d, fmt, ##arg)
  1207. #define NV_INFO(d, fmt, arg...) NV_PRINTK(KERN_INFO, d, fmt, ##arg)
  1208. #define NV_TRACEWARN(d, fmt, arg...) NV_PRINTK(KERN_NOTICE, d, fmt, ##arg)
  1209. #define NV_TRACE(d, fmt, arg...) NV_PRINTK(KERN_INFO, d, fmt, ##arg)
  1210. #define NV_WARN(d, fmt, arg...) NV_PRINTK(KERN_WARNING, d, fmt, ##arg)
  1211. #define NV_WARNONCE(d, fmt, arg...) do { \
  1212. static int _warned = 0; \
  1213. if (!_warned) { \
  1214. NV_WARN(d, fmt, ##arg); \
  1215. _warned = 1; \
  1216. } \
  1217. } while(0)
  1218. /* nouveau_reg_debug bitmask */
  1219. enum {
  1220. NOUVEAU_REG_DEBUG_MC = 0x1,
  1221. NOUVEAU_REG_DEBUG_VIDEO = 0x2,
  1222. NOUVEAU_REG_DEBUG_FB = 0x4,
  1223. NOUVEAU_REG_DEBUG_EXTDEV = 0x8,
  1224. NOUVEAU_REG_DEBUG_CRTC = 0x10,
  1225. NOUVEAU_REG_DEBUG_RAMDAC = 0x20,
  1226. NOUVEAU_REG_DEBUG_VGACRTC = 0x40,
  1227. NOUVEAU_REG_DEBUG_RMVIO = 0x80,
  1228. NOUVEAU_REG_DEBUG_VGAATTR = 0x100,
  1229. NOUVEAU_REG_DEBUG_EVO = 0x200,
  1230. NOUVEAU_REG_DEBUG_AUXCH = 0x400
  1231. };
  1232. #define NV_REG_DEBUG(type, dev, fmt, arg...) do { \
  1233. if (nouveau_reg_debug & NOUVEAU_REG_DEBUG_##type) \
  1234. NV_PRINTK(KERN_DEBUG, dev, "%s: " fmt, __func__, ##arg); \
  1235. } while (0)
  1236. static inline bool
  1237. nv_two_heads(struct drm_device *dev)
  1238. {
  1239. struct drm_nouveau_private *dev_priv = dev->dev_private;
  1240. const int impl = dev->pci_device & 0x0ff0;
  1241. if (dev_priv->card_type >= NV_10 && impl != 0x0100 &&
  1242. impl != 0x0150 && impl != 0x01a0 && impl != 0x0200)
  1243. return true;
  1244. return false;
  1245. }
  1246. static inline bool
  1247. nv_gf4_disp_arch(struct drm_device *dev)
  1248. {
  1249. return nv_two_heads(dev) && (dev->pci_device & 0x0ff0) != 0x0110;
  1250. }
  1251. static inline bool
  1252. nv_two_reg_pll(struct drm_device *dev)
  1253. {
  1254. struct drm_nouveau_private *dev_priv = dev->dev_private;
  1255. const int impl = dev->pci_device & 0x0ff0;
  1256. if (impl == 0x0310 || impl == 0x0340 || dev_priv->card_type >= NV_40)
  1257. return true;
  1258. return false;
  1259. }
  1260. static inline bool
  1261. nv_match_device(struct drm_device *dev, unsigned device,
  1262. unsigned sub_vendor, unsigned sub_device)
  1263. {
  1264. return dev->pdev->device == device &&
  1265. dev->pdev->subsystem_vendor == sub_vendor &&
  1266. dev->pdev->subsystem_device == sub_device;
  1267. }
  1268. static inline void *
  1269. nv_engine(struct drm_device *dev, int engine)
  1270. {
  1271. struct drm_nouveau_private *dev_priv = dev->dev_private;
  1272. return (void *)dev_priv->eng[engine];
  1273. }
  1274. /* returns 1 if device is one of the nv4x using the 0x4497 object class,
  1275. * helpful to determine a number of other hardware features
  1276. */
  1277. static inline int
  1278. nv44_graph_class(struct drm_device *dev)
  1279. {
  1280. struct drm_nouveau_private *dev_priv = dev->dev_private;
  1281. if ((dev_priv->chipset & 0xf0) == 0x60)
  1282. return 1;
  1283. return !(0x0baf & (1 << (dev_priv->chipset & 0x0f)));
  1284. }
  1285. int nv50_vram_init(struct drm_device *);
  1286. void nv50_vram_fini(struct drm_device *);
  1287. int nv50_vram_new(struct drm_device *, u64 size, u32 align, u32 size_nc,
  1288. u32 memtype, struct nouveau_mem **);
  1289. void nv50_vram_del(struct drm_device *, struct nouveau_mem **);
  1290. bool nv50_vram_flags_valid(struct drm_device *, u32 tile_flags);
  1291. int nvc0_vram_init(struct drm_device *);
  1292. int nvc0_vram_new(struct drm_device *, u64 size, u32 align, u32 ncmin,
  1293. u32 memtype, struct nouveau_mem **);
  1294. bool nvc0_vram_flags_valid(struct drm_device *, u32 tile_flags);
  1295. /* memory type/access flags, do not match hardware values */
  1296. #define NV_MEM_ACCESS_RO 1
  1297. #define NV_MEM_ACCESS_WO 2
  1298. #define NV_MEM_ACCESS_RW (NV_MEM_ACCESS_RO | NV_MEM_ACCESS_WO)
  1299. #define NV_MEM_ACCESS_SYS 4
  1300. #define NV_MEM_ACCESS_VM 8
  1301. #define NV_MEM_ACCESS_NOSNOOP 16
  1302. #define NV_MEM_TARGET_VRAM 0
  1303. #define NV_MEM_TARGET_PCI 1
  1304. #define NV_MEM_TARGET_PCI_NOSNOOP 2
  1305. #define NV_MEM_TARGET_VM 3
  1306. #define NV_MEM_TARGET_GART 4
  1307. #define NV_MEM_TYPE_VM 0x7f
  1308. #define NV_MEM_COMP_VM 0x03
  1309. /* FIFO methods */
  1310. #define NV01_SUBCHAN_OBJECT 0x00000000
  1311. #define NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH 0x00000010
  1312. #define NV84_SUBCHAN_SEMAPHORE_ADDRESS_LOW 0x00000014
  1313. #define NV84_SUBCHAN_SEMAPHORE_SEQUENCE 0x00000018
  1314. #define NV84_SUBCHAN_SEMAPHORE_TRIGGER 0x0000001c
  1315. #define NV84_SUBCHAN_SEMAPHORE_TRIGGER_ACQUIRE_EQUAL 0x00000001
  1316. #define NV84_SUBCHAN_SEMAPHORE_TRIGGER_WRITE_LONG 0x00000002
  1317. #define NV84_SUBCHAN_SEMAPHORE_TRIGGER_ACQUIRE_GEQUAL 0x00000004
  1318. #define NVC0_SUBCHAN_SEMAPHORE_TRIGGER_YIELD 0x00001000
  1319. #define NV84_SUBCHAN_NOTIFY_INTR 0x00000020
  1320. #define NV84_SUBCHAN_WRCACHE_FLUSH 0x00000024
  1321. #define NV10_SUBCHAN_REF_CNT 0x00000050
  1322. #define NVSW_SUBCHAN_PAGE_FLIP 0x00000054
  1323. #define NV11_SUBCHAN_DMA_SEMAPHORE 0x00000060
  1324. #define NV11_SUBCHAN_SEMAPHORE_OFFSET 0x00000064
  1325. #define NV11_SUBCHAN_SEMAPHORE_ACQUIRE 0x00000068
  1326. #define NV11_SUBCHAN_SEMAPHORE_RELEASE 0x0000006c
  1327. #define NV40_SUBCHAN_YIELD 0x00000080
  1328. /* NV_SW object class */
  1329. #define NV_SW 0x0000506e
  1330. #define NV_SW_DMA_VBLSEM 0x0000018c
  1331. #define NV_SW_VBLSEM_OFFSET 0x00000400
  1332. #define NV_SW_VBLSEM_RELEASE_VALUE 0x00000404
  1333. #define NV_SW_VBLSEM_RELEASE 0x00000408
  1334. #define NV_SW_PAGE_FLIP 0x00000500
  1335. #endif /* __NOUVEAU_DRV_H__ */