nouveau_drv.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  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. #define XXX_THIS_IS_A_HACK
  42. #include <subdev/vm.h>
  43. #include <subdev/fb.h>
  44. #include <core/gpuobj.h>
  45. enum blah {
  46. NV_MEM_TYPE_UNKNOWN = 0,
  47. NV_MEM_TYPE_STOLEN,
  48. NV_MEM_TYPE_SGRAM,
  49. NV_MEM_TYPE_SDRAM,
  50. NV_MEM_TYPE_DDR1,
  51. NV_MEM_TYPE_DDR2,
  52. NV_MEM_TYPE_DDR3,
  53. NV_MEM_TYPE_GDDR2,
  54. NV_MEM_TYPE_GDDR3,
  55. NV_MEM_TYPE_GDDR4,
  56. NV_MEM_TYPE_GDDR5
  57. };
  58. #include <nouveau_drm.h>
  59. #include "nouveau_reg.h"
  60. #include <nouveau_bios.h>
  61. #include <subdev/bios/pll.h>
  62. #include "nouveau_compat.h"
  63. #define nouveau_gpuobj_new(d,c,s,a,f,o) \
  64. _nouveau_gpuobj_new((d), NULL, (s), (a), (f), (o))
  65. #define nouveau_vm_new(d,o,l,m,v) \
  66. _nouveau_vm_new((d), (o), (l), (m), (v))
  67. #define nv50_vm_flush_engine(d,e) \
  68. _nv50_vm_flush_engine((d), (e))
  69. #include "nouveau_bo.h"
  70. #include "nouveau_gem.h"
  71. struct nouveau_page_flip_state {
  72. struct list_head head;
  73. struct drm_pending_vblank_event *event;
  74. int crtc, bpp, pitch, x, y;
  75. uint64_t offset;
  76. };
  77. struct nouveau_display_engine {
  78. void *priv;
  79. int (*early_init)(struct drm_device *);
  80. void (*late_takedown)(struct drm_device *);
  81. int (*create)(struct drm_device *);
  82. void (*destroy)(struct drm_device *);
  83. int (*init)(struct drm_device *);
  84. void (*fini)(struct drm_device *);
  85. struct drm_property *dithering_mode;
  86. struct drm_property *dithering_depth;
  87. struct drm_property *underscan_property;
  88. struct drm_property *underscan_hborder_property;
  89. struct drm_property *underscan_vborder_property;
  90. /* not really hue and saturation: */
  91. struct drm_property *vibrant_hue_property;
  92. struct drm_property *color_vibrance_property;
  93. };
  94. struct nouveau_pm_voltage_level {
  95. u32 voltage; /* microvolts */
  96. u8 vid;
  97. };
  98. struct nouveau_pm_voltage {
  99. bool supported;
  100. u8 version;
  101. u8 vid_mask;
  102. struct nouveau_pm_voltage_level *level;
  103. int nr_level;
  104. };
  105. /* Exclusive upper limits */
  106. #define NV_MEM_CL_DDR2_MAX 8
  107. #define NV_MEM_WR_DDR2_MAX 9
  108. #define NV_MEM_CL_DDR3_MAX 17
  109. #define NV_MEM_WR_DDR3_MAX 17
  110. #define NV_MEM_CL_GDDR3_MAX 16
  111. #define NV_MEM_WR_GDDR3_MAX 18
  112. #define NV_MEM_CL_GDDR5_MAX 21
  113. #define NV_MEM_WR_GDDR5_MAX 20
  114. struct nouveau_pm_memtiming {
  115. int id;
  116. u32 reg[9];
  117. u32 mr[4];
  118. u8 tCWL;
  119. u8 odt;
  120. u8 drive_strength;
  121. };
  122. struct nouveau_pm_tbl_header {
  123. u8 version;
  124. u8 header_len;
  125. u8 entry_cnt;
  126. u8 entry_len;
  127. };
  128. struct nouveau_pm_tbl_entry {
  129. u8 tWR;
  130. u8 tWTR;
  131. u8 tCL;
  132. u8 tRC;
  133. u8 empty_4;
  134. u8 tRFC; /* Byte 5 */
  135. u8 empty_6;
  136. u8 tRAS; /* Byte 7 */
  137. u8 empty_8;
  138. u8 tRP; /* Byte 9 */
  139. u8 tRCDRD;
  140. u8 tRCDWR;
  141. u8 tRRD;
  142. u8 tUNK_13;
  143. u8 RAM_FT1; /* 14, a bitmask of random RAM features */
  144. u8 empty_15;
  145. u8 tUNK_16;
  146. u8 empty_17;
  147. u8 tUNK_18;
  148. u8 tCWL;
  149. u8 tUNK_20, tUNK_21;
  150. };
  151. struct nouveau_pm_profile;
  152. struct nouveau_pm_profile_func {
  153. void (*destroy)(struct nouveau_pm_profile *);
  154. void (*init)(struct nouveau_pm_profile *);
  155. void (*fini)(struct nouveau_pm_profile *);
  156. struct nouveau_pm_level *(*select)(struct nouveau_pm_profile *);
  157. };
  158. struct nouveau_pm_profile {
  159. const struct nouveau_pm_profile_func *func;
  160. struct list_head head;
  161. char name[8];
  162. };
  163. #define NOUVEAU_PM_MAX_LEVEL 8
  164. struct nouveau_pm_level {
  165. struct nouveau_pm_profile profile;
  166. struct device_attribute dev_attr;
  167. char name[32];
  168. int id;
  169. struct nouveau_pm_memtiming timing;
  170. u32 memory;
  171. u16 memscript;
  172. u32 core;
  173. u32 shader;
  174. u32 rop;
  175. u32 copy;
  176. u32 daemon;
  177. u32 vdec;
  178. u32 dom6;
  179. u32 unka0; /* nva3:nvc0 */
  180. u32 hub01; /* nvc0- */
  181. u32 hub06; /* nvc0- */
  182. u32 hub07; /* nvc0- */
  183. u32 volt_min; /* microvolts */
  184. u32 volt_max;
  185. u8 fanspeed;
  186. };
  187. struct nouveau_pm_temp_sensor_constants {
  188. u16 offset_constant;
  189. s16 offset_mult;
  190. s16 offset_div;
  191. s16 slope_mult;
  192. s16 slope_div;
  193. };
  194. struct nouveau_pm_threshold_temp {
  195. s16 critical;
  196. s16 down_clock;
  197. s16 fan_boost;
  198. };
  199. struct nouveau_pm_fan {
  200. u32 percent;
  201. u32 min_duty;
  202. u32 max_duty;
  203. u32 pwm_freq;
  204. u32 pwm_divisor;
  205. };
  206. struct nouveau_pm_engine {
  207. struct nouveau_pm_voltage voltage;
  208. struct nouveau_pm_level perflvl[NOUVEAU_PM_MAX_LEVEL];
  209. int nr_perflvl;
  210. struct nouveau_pm_temp_sensor_constants sensor_constants;
  211. struct nouveau_pm_threshold_temp threshold_temp;
  212. struct nouveau_pm_fan fan;
  213. struct nouveau_pm_profile *profile_ac;
  214. struct nouveau_pm_profile *profile_dc;
  215. struct nouveau_pm_profile *profile;
  216. struct list_head profiles;
  217. struct nouveau_pm_level boot;
  218. struct nouveau_pm_level *cur;
  219. struct device *hwmon;
  220. struct notifier_block acpi_nb;
  221. int (*clocks_get)(struct drm_device *, struct nouveau_pm_level *);
  222. void *(*clocks_pre)(struct drm_device *, struct nouveau_pm_level *);
  223. int (*clocks_set)(struct drm_device *, void *);
  224. int (*voltage_get)(struct drm_device *);
  225. int (*voltage_set)(struct drm_device *, int voltage);
  226. int (*pwm_get)(struct drm_device *, int line, u32*, u32*);
  227. int (*pwm_set)(struct drm_device *, int line, u32, u32);
  228. int (*temp_get)(struct drm_device *);
  229. };
  230. struct nouveau_engine {
  231. struct nouveau_display_engine display;
  232. struct nouveau_pm_engine pm;
  233. };
  234. enum nouveau_card_type {
  235. NV_04 = 0x04,
  236. NV_10 = 0x10,
  237. NV_20 = 0x20,
  238. NV_30 = 0x30,
  239. NV_40 = 0x40,
  240. NV_50 = 0x50,
  241. NV_C0 = 0xc0,
  242. NV_D0 = 0xd0,
  243. NV_E0 = 0xe0,
  244. };
  245. struct drm_nouveau_private {
  246. struct drm_device *dev;
  247. void *newpriv;
  248. /* the card type, takes NV_* as values */
  249. enum nouveau_card_type card_type;
  250. /* exact chipset, derived from NV_PMC_BOOT_0 */
  251. int chipset;
  252. u32 crystal;
  253. /* interrupt handling */
  254. void (*irq_handler[32])(struct drm_device *);
  255. bool msi_enabled;
  256. struct nouveau_engine engine;
  257. /* For PFIFO and PGRAPH. */
  258. spinlock_t context_switch_lock;
  259. struct nvbios vbios;
  260. };
  261. static inline struct drm_nouveau_private *
  262. nouveau_private(struct drm_device *dev)
  263. {
  264. return dev->dev_private;
  265. }
  266. /* nouveau_drv.c */
  267. extern int nouveau_modeset;
  268. extern int nouveau_duallink;
  269. extern int nouveau_uscript_lvds;
  270. extern int nouveau_uscript_tmds;
  271. extern int nouveau_vram_pushbuf;
  272. extern int nouveau_vram_notify;
  273. extern char *nouveau_vram_type;
  274. extern int nouveau_fbpercrtc;
  275. extern int nouveau_tv_disable;
  276. extern char *nouveau_tv_norm;
  277. extern int nouveau_ignorelid;
  278. extern int nouveau_force_post;
  279. extern int nouveau_override_conntype;
  280. extern char *nouveau_perflvl;
  281. extern int nouveau_perflvl_wr;
  282. extern int nouveau_msi;
  283. extern int nouveau_ctxfw;
  284. extern int nouveau_mxmdcb;
  285. extern int nouveau_pci_suspend(struct pci_dev *pdev, pm_message_t pm_state);
  286. extern int nouveau_pci_resume(struct pci_dev *pdev);
  287. /* nouveau_state.c */
  288. extern int nouveau_load(struct drm_device *, unsigned long flags);
  289. extern int nouveau_firstopen(struct drm_device *);
  290. extern void nouveau_lastclose(struct drm_device *);
  291. extern int nouveau_unload(struct drm_device *);
  292. extern int nouveau_card_init(struct drm_device *);
  293. /* nouveau_mem.c */
  294. extern int nouveau_mem_timing_calc(struct drm_device *, u32 freq,
  295. struct nouveau_pm_memtiming *);
  296. extern void nouveau_mem_timing_read(struct drm_device *,
  297. struct nouveau_pm_memtiming *);
  298. /* nouveau_irq.c */
  299. extern int nouveau_irq_init(struct drm_device *);
  300. extern void nouveau_irq_fini(struct drm_device *);
  301. extern irqreturn_t nouveau_irq_handler(DRM_IRQ_ARGS);
  302. extern void nouveau_irq_register(struct drm_device *, int status_bit,
  303. void (*)(struct drm_device *));
  304. extern void nouveau_irq_unregister(struct drm_device *, int status_bit);
  305. extern void nouveau_irq_preinstall(struct drm_device *);
  306. extern int nouveau_irq_postinstall(struct drm_device *);
  307. extern void nouveau_irq_uninstall(struct drm_device *);
  308. /* nouveau_backlight.c */
  309. #ifdef CONFIG_DRM_NOUVEAU_BACKLIGHT
  310. extern int nouveau_backlight_init(struct drm_device *);
  311. extern void nouveau_backlight_exit(struct drm_device *);
  312. #else
  313. static inline int nouveau_backlight_init(struct drm_device *dev)
  314. {
  315. return 0;
  316. }
  317. static inline void nouveau_backlight_exit(struct drm_device *dev) { }
  318. #endif
  319. /* nouveau_bios.c */
  320. extern int nouveau_bios_init(struct drm_device *);
  321. extern void nouveau_bios_takedown(struct drm_device *dev);
  322. extern int nouveau_run_vbios_init(struct drm_device *);
  323. extern struct dcb_connector_table_entry *
  324. nouveau_bios_connector_entry(struct drm_device *, int index);
  325. extern int nouveau_bios_run_display_table(struct drm_device *, u16 id, int clk,
  326. struct dcb_output *, int crtc);
  327. extern bool nouveau_bios_fp_mode(struct drm_device *, struct drm_display_mode *);
  328. extern uint8_t *nouveau_bios_embedded_edid(struct drm_device *);
  329. extern int nouveau_bios_parse_lvds_table(struct drm_device *, int pxclk,
  330. bool *dl, bool *if_is_24bit);
  331. extern int run_tmds_table(struct drm_device *, struct dcb_output *,
  332. int head, int pxclk);
  333. extern int call_lvds_script(struct drm_device *, struct dcb_output *, int head,
  334. enum LVDS_script, int pxclk);
  335. bool bios_encoder_match(struct dcb_output *, u32 hash);
  336. /* nouveau_ttm.c */
  337. int nouveau_ttm_global_init(struct drm_nouveau_private *);
  338. void nouveau_ttm_global_release(struct drm_nouveau_private *);
  339. int nouveau_ttm_mmap(struct file *, struct vm_area_struct *);
  340. /* nouveau_hdmi.c */
  341. void nouveau_hdmi_mode_set(struct drm_encoder *, struct drm_display_mode *);
  342. /* nvd0_display.c */
  343. extern int nvd0_display_create(struct drm_device *);
  344. extern void nvd0_display_destroy(struct drm_device *);
  345. extern int nvd0_display_init(struct drm_device *);
  346. extern void nvd0_display_fini(struct drm_device *);
  347. struct nouveau_bo *nvd0_display_crtc_sema(struct drm_device *, int crtc);
  348. void nvd0_display_flip_stop(struct drm_crtc *);
  349. int nvd0_display_flip_next(struct drm_crtc *, struct drm_framebuffer *,
  350. struct nouveau_channel *, u32 swap_interval);
  351. /* nouveau_display.c */
  352. int nouveau_display_create(struct drm_device *dev);
  353. void nouveau_display_destroy(struct drm_device *dev);
  354. int nouveau_display_init(struct drm_device *dev);
  355. void nouveau_display_fini(struct drm_device *dev);
  356. int nouveau_vblank_enable(struct drm_device *dev, int crtc);
  357. void nouveau_vblank_disable(struct drm_device *dev, int crtc);
  358. int nouveau_crtc_page_flip(struct drm_crtc *crtc, struct drm_framebuffer *fb,
  359. struct drm_pending_vblank_event *event);
  360. int nouveau_finish_page_flip(struct nouveau_channel *,
  361. struct nouveau_page_flip_state *);
  362. int nouveau_display_dumb_create(struct drm_file *, struct drm_device *,
  363. struct drm_mode_create_dumb *args);
  364. int nouveau_display_dumb_map_offset(struct drm_file *, struct drm_device *,
  365. uint32_t handle, uint64_t *offset);
  366. int nouveau_display_dumb_destroy(struct drm_file *, struct drm_device *,
  367. uint32_t handle);
  368. #ifndef ioread32_native
  369. #ifdef __BIG_ENDIAN
  370. #define ioread16_native ioread16be
  371. #define iowrite16_native iowrite16be
  372. #define ioread32_native ioread32be
  373. #define iowrite32_native iowrite32be
  374. #else /* def __BIG_ENDIAN */
  375. #define ioread16_native ioread16
  376. #define iowrite16_native iowrite16
  377. #define ioread32_native ioread32
  378. #define iowrite32_native iowrite32
  379. #endif /* def __BIG_ENDIAN else */
  380. #endif /* !ioread32_native */
  381. /* register access */
  382. #define nv_rd08 _nv_rd08
  383. #define nv_wr08 _nv_wr08
  384. #define nv_rd32 _nv_rd32
  385. #define nv_wr32 _nv_wr32
  386. #define nv_mask _nv_mask
  387. #define nv_wait(dev, reg, mask, val) \
  388. nouveau_wait_eq(dev, 2000000000ULL, (reg), (mask), (val))
  389. #define nv_wait_ne(dev, reg, mask, val) \
  390. nouveau_wait_ne(dev, 2000000000ULL, (reg), (mask), (val))
  391. #define nv_wait_cb(dev, func, data) \
  392. nouveau_wait_cb(dev, 2000000000ULL, (func), (data))
  393. /*
  394. * Logging
  395. * Argument d is (struct drm_device *).
  396. */
  397. #define NV_PRINTK(level, d, fmt, arg...) \
  398. printk(level "[" DRM_NAME "] " DRIVER_NAME " %s: " fmt, \
  399. pci_name(d->pdev), ##arg)
  400. #ifndef NV_DEBUG_NOTRACE
  401. #define NV_DEBUG(d, fmt, arg...) do { \
  402. if (drm_debug & DRM_UT_DRIVER) { \
  403. NV_PRINTK(KERN_DEBUG, d, "%s:%d - " fmt, __func__, \
  404. __LINE__, ##arg); \
  405. } \
  406. } while (0)
  407. #define NV_DEBUG_KMS(d, fmt, arg...) do { \
  408. if (drm_debug & DRM_UT_KMS) { \
  409. NV_PRINTK(KERN_DEBUG, d, "%s:%d - " fmt, __func__, \
  410. __LINE__, ##arg); \
  411. } \
  412. } while (0)
  413. #else
  414. #define NV_DEBUG(d, fmt, arg...) do { \
  415. if (drm_debug & DRM_UT_DRIVER) \
  416. NV_PRINTK(KERN_DEBUG, d, fmt, ##arg); \
  417. } while (0)
  418. #define NV_DEBUG_KMS(d, fmt, arg...) do { \
  419. if (drm_debug & DRM_UT_KMS) \
  420. NV_PRINTK(KERN_DEBUG, d, fmt, ##arg); \
  421. } while (0)
  422. #endif
  423. #define NV_ERROR(d, fmt, arg...) NV_PRINTK(KERN_ERR, d, fmt, ##arg)
  424. #define NV_INFO(d, fmt, arg...) NV_PRINTK(KERN_INFO, d, fmt, ##arg)
  425. #define NV_TRACEWARN(d, fmt, arg...) NV_PRINTK(KERN_NOTICE, d, fmt, ##arg)
  426. #define NV_TRACE(d, fmt, arg...) NV_PRINTK(KERN_INFO, d, fmt, ##arg)
  427. #define NV_WARN(d, fmt, arg...) NV_PRINTK(KERN_WARNING, d, fmt, ##arg)
  428. #define NV_WARNONCE(d, fmt, arg...) do { \
  429. static int _warned = 0; \
  430. if (!_warned) { \
  431. NV_WARN(d, fmt, ##arg); \
  432. _warned = 1; \
  433. } \
  434. } while(0)
  435. static inline bool
  436. nv_two_heads(struct drm_device *dev)
  437. {
  438. struct drm_nouveau_private *dev_priv = dev->dev_private;
  439. const int impl = dev->pci_device & 0x0ff0;
  440. if (dev_priv->card_type >= NV_10 && impl != 0x0100 &&
  441. impl != 0x0150 && impl != 0x01a0 && impl != 0x0200)
  442. return true;
  443. return false;
  444. }
  445. static inline bool
  446. nv_gf4_disp_arch(struct drm_device *dev)
  447. {
  448. return nv_two_heads(dev) && (dev->pci_device & 0x0ff0) != 0x0110;
  449. }
  450. static inline bool
  451. nv_two_reg_pll(struct drm_device *dev)
  452. {
  453. struct drm_nouveau_private *dev_priv = dev->dev_private;
  454. const int impl = dev->pci_device & 0x0ff0;
  455. if (impl == 0x0310 || impl == 0x0340 || dev_priv->card_type >= NV_40)
  456. return true;
  457. return false;
  458. }
  459. static inline bool
  460. nv_match_device(struct drm_device *dev, unsigned device,
  461. unsigned sub_vendor, unsigned sub_device)
  462. {
  463. return dev->pdev->device == device &&
  464. dev->pdev->subsystem_vendor == sub_vendor &&
  465. dev->pdev->subsystem_device == sub_device;
  466. }
  467. static inline struct nv04_display *
  468. nv04_display(struct drm_device *dev)
  469. {
  470. struct drm_nouveau_private *dev_priv = dev->dev_private;
  471. return dev_priv->engine.display.priv;
  472. }
  473. #endif /* __NOUVEAU_DRV_H__ */