nouveau_drv.h 57 KB

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