intel_drv.h 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036
  1. /*
  2. * Copyright (c) 2006 Dave Airlie <airlied@linux.ie>
  3. * Copyright (c) 2007-2008 Intel Corporation
  4. * Jesse Barnes <jesse.barnes@intel.com>
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the "Software"),
  8. * to deal in the Software without restriction, including without limitation
  9. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10. * and/or sell copies of the Software, and to permit persons to whom the
  11. * Software is furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice (including the next
  14. * paragraph) shall be included in all copies or substantial portions of the
  15. * Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  20. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  22. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  23. * IN THE SOFTWARE.
  24. */
  25. #ifndef __INTEL_DRV_H__
  26. #define __INTEL_DRV_H__
  27. #include <linux/i2c.h>
  28. #include <linux/hdmi.h>
  29. #include <drm/i915_drm.h>
  30. #include "i915_drv.h"
  31. #include <drm/drm_crtc.h>
  32. #include <drm/drm_crtc_helper.h>
  33. #include <drm/drm_fb_helper.h>
  34. #include <drm/drm_dp_helper.h>
  35. /**
  36. * _wait_for - magic (register) wait macro
  37. *
  38. * Does the right thing for modeset paths when run under kdgb or similar atomic
  39. * contexts. Note that it's important that we check the condition again after
  40. * having timed out, since the timeout could be due to preemption or similar and
  41. * we've never had a chance to check the condition before the timeout.
  42. */
  43. #define _wait_for(COND, MS, W) ({ \
  44. unsigned long timeout__ = jiffies + msecs_to_jiffies(MS) + 1; \
  45. int ret__ = 0; \
  46. while (!(COND)) { \
  47. if (time_after(jiffies, timeout__)) { \
  48. if (!(COND)) \
  49. ret__ = -ETIMEDOUT; \
  50. break; \
  51. } \
  52. if (W && drm_can_sleep()) { \
  53. msleep(W); \
  54. } else { \
  55. cpu_relax(); \
  56. } \
  57. } \
  58. ret__; \
  59. })
  60. #define wait_for(COND, MS) _wait_for(COND, MS, 1)
  61. #define wait_for_atomic(COND, MS) _wait_for(COND, MS, 0)
  62. #define wait_for_atomic_us(COND, US) _wait_for((COND), \
  63. DIV_ROUND_UP((US), 1000), 0)
  64. #define KHz(x) (1000 * (x))
  65. #define MHz(x) KHz(1000 * (x))
  66. /*
  67. * Display related stuff
  68. */
  69. /* store information about an Ixxx DVO */
  70. /* The i830->i865 use multiple DVOs with multiple i2cs */
  71. /* the i915, i945 have a single sDVO i2c bus - which is different */
  72. #define MAX_OUTPUTS 6
  73. /* maximum connectors per crtcs in the mode set */
  74. /* Maximum cursor sizes */
  75. #define GEN2_CURSOR_WIDTH 64
  76. #define GEN2_CURSOR_HEIGHT 64
  77. #define MAX_CURSOR_WIDTH 256
  78. #define MAX_CURSOR_HEIGHT 256
  79. #define INTEL_I2C_BUS_DVO 1
  80. #define INTEL_I2C_BUS_SDVO 2
  81. /* these are outputs from the chip - integrated only
  82. external chips are via DVO or SDVO output */
  83. #define INTEL_OUTPUT_UNUSED 0
  84. #define INTEL_OUTPUT_ANALOG 1
  85. #define INTEL_OUTPUT_DVO 2
  86. #define INTEL_OUTPUT_SDVO 3
  87. #define INTEL_OUTPUT_LVDS 4
  88. #define INTEL_OUTPUT_TVOUT 5
  89. #define INTEL_OUTPUT_HDMI 6
  90. #define INTEL_OUTPUT_DISPLAYPORT 7
  91. #define INTEL_OUTPUT_EDP 8
  92. #define INTEL_OUTPUT_DSI 9
  93. #define INTEL_OUTPUT_UNKNOWN 10
  94. #define INTEL_DVO_CHIP_NONE 0
  95. #define INTEL_DVO_CHIP_LVDS 1
  96. #define INTEL_DVO_CHIP_TMDS 2
  97. #define INTEL_DVO_CHIP_TVOUT 4
  98. #define INTEL_DSI_VIDEO_MODE 0
  99. #define INTEL_DSI_COMMAND_MODE 1
  100. struct intel_framebuffer {
  101. struct drm_framebuffer base;
  102. struct drm_i915_gem_object *obj;
  103. };
  104. struct intel_fbdev {
  105. struct drm_fb_helper helper;
  106. struct intel_framebuffer *fb;
  107. struct list_head fbdev_list;
  108. struct drm_display_mode *our_mode;
  109. int preferred_bpp;
  110. };
  111. struct intel_encoder {
  112. struct drm_encoder base;
  113. /*
  114. * The new crtc this encoder will be driven from. Only differs from
  115. * base->crtc while a modeset is in progress.
  116. */
  117. struct intel_crtc *new_crtc;
  118. int type;
  119. unsigned int cloneable;
  120. bool connectors_active;
  121. void (*hot_plug)(struct intel_encoder *);
  122. bool (*compute_config)(struct intel_encoder *,
  123. struct intel_crtc_config *);
  124. void (*pre_pll_enable)(struct intel_encoder *);
  125. void (*pre_enable)(struct intel_encoder *);
  126. void (*enable)(struct intel_encoder *);
  127. void (*mode_set)(struct intel_encoder *intel_encoder);
  128. void (*disable)(struct intel_encoder *);
  129. void (*post_disable)(struct intel_encoder *);
  130. /* Read out the current hw state of this connector, returning true if
  131. * the encoder is active. If the encoder is enabled it also set the pipe
  132. * it is connected to in the pipe parameter. */
  133. bool (*get_hw_state)(struct intel_encoder *, enum pipe *pipe);
  134. /* Reconstructs the equivalent mode flags for the current hardware
  135. * state. This must be called _after_ display->get_pipe_config has
  136. * pre-filled the pipe config. Note that intel_encoder->base.crtc must
  137. * be set correctly before calling this function. */
  138. void (*get_config)(struct intel_encoder *,
  139. struct intel_crtc_config *pipe_config);
  140. int crtc_mask;
  141. enum hpd_pin hpd_pin;
  142. };
  143. struct intel_panel {
  144. struct drm_display_mode *fixed_mode;
  145. struct drm_display_mode *downclock_mode;
  146. int fitting_mode;
  147. /* backlight */
  148. struct {
  149. bool present;
  150. u32 level;
  151. u32 max;
  152. bool enabled;
  153. bool combination_mode; /* gen 2/4 only */
  154. bool active_low_pwm;
  155. struct backlight_device *device;
  156. } backlight;
  157. };
  158. struct intel_connector {
  159. struct drm_connector base;
  160. /*
  161. * The fixed encoder this connector is connected to.
  162. */
  163. struct intel_encoder *encoder;
  164. /*
  165. * The new encoder this connector will be driven. Only differs from
  166. * encoder while a modeset is in progress.
  167. */
  168. struct intel_encoder *new_encoder;
  169. /* Reads out the current hw, returning true if the connector is enabled
  170. * and active (i.e. dpms ON state). */
  171. bool (*get_hw_state)(struct intel_connector *);
  172. /*
  173. * Removes all interfaces through which the connector is accessible
  174. * - like sysfs, debugfs entries -, so that no new operations can be
  175. * started on the connector. Also makes sure all currently pending
  176. * operations finish before returing.
  177. */
  178. void (*unregister)(struct intel_connector *);
  179. /* Panel info for eDP and LVDS */
  180. struct intel_panel panel;
  181. /* Cached EDID for eDP and LVDS. May hold ERR_PTR for invalid EDID. */
  182. struct edid *edid;
  183. /* since POLL and HPD connectors may use the same HPD line keep the native
  184. state of connector->polled in case hotplug storm detection changes it */
  185. u8 polled;
  186. };
  187. typedef struct dpll {
  188. /* given values */
  189. int n;
  190. int m1, m2;
  191. int p1, p2;
  192. /* derived values */
  193. int dot;
  194. int vco;
  195. int m;
  196. int p;
  197. } intel_clock_t;
  198. struct intel_plane_config {
  199. bool tiled;
  200. int size;
  201. u32 base;
  202. };
  203. struct intel_crtc_config {
  204. /**
  205. * quirks - bitfield with hw state readout quirks
  206. *
  207. * For various reasons the hw state readout code might not be able to
  208. * completely faithfully read out the current state. These cases are
  209. * tracked with quirk flags so that fastboot and state checker can act
  210. * accordingly.
  211. */
  212. #define PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS (1<<0) /* unreliable sync mode.flags */
  213. #define PIPE_CONFIG_QUIRK_INHERITED_MODE (1<<1) /* mode inherited from firmware */
  214. unsigned long quirks;
  215. /* User requested mode, only valid as a starting point to
  216. * compute adjusted_mode, except in the case of (S)DVO where
  217. * it's also for the output timings of the (S)DVO chip.
  218. * adjusted_mode will then correspond to the S(DVO) chip's
  219. * preferred input timings. */
  220. struct drm_display_mode requested_mode;
  221. /* Actual pipe timings ie. what we program into the pipe timing
  222. * registers. adjusted_mode.crtc_clock is the pipe pixel clock. */
  223. struct drm_display_mode adjusted_mode;
  224. /* Pipe source size (ie. panel fitter input size)
  225. * All planes will be positioned inside this space,
  226. * and get clipped at the edges. */
  227. int pipe_src_w, pipe_src_h;
  228. /* Whether to set up the PCH/FDI. Note that we never allow sharing
  229. * between pch encoders and cpu encoders. */
  230. bool has_pch_encoder;
  231. /* CPU Transcoder for the pipe. Currently this can only differ from the
  232. * pipe on Haswell (where we have a special eDP transcoder). */
  233. enum transcoder cpu_transcoder;
  234. /*
  235. * Use reduced/limited/broadcast rbg range, compressing from the full
  236. * range fed into the crtcs.
  237. */
  238. bool limited_color_range;
  239. /* DP has a bunch of special case unfortunately, so mark the pipe
  240. * accordingly. */
  241. bool has_dp_encoder;
  242. /* Whether we should send NULL infoframes. Required for audio. */
  243. bool has_hdmi_sink;
  244. /* Audio enabled on this pipe. Only valid if either has_hdmi_sink or
  245. * has_dp_encoder is set. */
  246. bool has_audio;
  247. /*
  248. * Enable dithering, used when the selected pipe bpp doesn't match the
  249. * plane bpp.
  250. */
  251. bool dither;
  252. /* Controls for the clock computation, to override various stages. */
  253. bool clock_set;
  254. /* SDVO TV has a bunch of special case. To make multifunction encoders
  255. * work correctly, we need to track this at runtime.*/
  256. bool sdvo_tv_clock;
  257. /*
  258. * crtc bandwidth limit, don't increase pipe bpp or clock if not really
  259. * required. This is set in the 2nd loop of calling encoder's
  260. * ->compute_config if the first pick doesn't work out.
  261. */
  262. bool bw_constrained;
  263. /* Settings for the intel dpll used on pretty much everything but
  264. * haswell. */
  265. struct dpll dpll;
  266. /* Selected dpll when shared or DPLL_ID_PRIVATE. */
  267. enum intel_dpll_id shared_dpll;
  268. /* PORT_CLK_SEL for DDI ports. */
  269. uint32_t ddi_pll_sel;
  270. /* Actual register state of the dpll, for shared dpll cross-checking. */
  271. struct intel_dpll_hw_state dpll_hw_state;
  272. int pipe_bpp;
  273. struct intel_link_m_n dp_m_n;
  274. /* m2_n2 for eDP downclock */
  275. struct intel_link_m_n dp_m2_n2;
  276. /*
  277. * Frequence the dpll for the port should run at. Differs from the
  278. * adjusted dotclock e.g. for DP or 12bpc hdmi mode. This is also
  279. * already multiplied by pixel_multiplier.
  280. */
  281. int port_clock;
  282. /* Used by SDVO (and if we ever fix it, HDMI). */
  283. unsigned pixel_multiplier;
  284. /* Panel fitter controls for gen2-gen4 + VLV */
  285. struct {
  286. u32 control;
  287. u32 pgm_ratios;
  288. u32 lvds_border_bits;
  289. } gmch_pfit;
  290. /* Panel fitter placement and size for Ironlake+ */
  291. struct {
  292. u32 pos;
  293. u32 size;
  294. bool enabled;
  295. bool force_thru;
  296. } pch_pfit;
  297. /* FDI configuration, only valid if has_pch_encoder is set. */
  298. int fdi_lanes;
  299. struct intel_link_m_n fdi_m_n;
  300. bool ips_enabled;
  301. bool double_wide;
  302. };
  303. struct intel_pipe_wm {
  304. struct intel_wm_level wm[5];
  305. uint32_t linetime;
  306. bool fbc_wm_enabled;
  307. bool pipe_enabled;
  308. bool sprites_enabled;
  309. bool sprites_scaled;
  310. };
  311. struct intel_mmio_flip {
  312. u32 seqno;
  313. u32 ring_id;
  314. };
  315. struct intel_crtc {
  316. struct drm_crtc base;
  317. enum pipe pipe;
  318. enum plane plane;
  319. u8 lut_r[256], lut_g[256], lut_b[256];
  320. /*
  321. * Whether the crtc and the connected output pipeline is active. Implies
  322. * that crtc->enabled is set, i.e. the current mode configuration has
  323. * some outputs connected to this crtc.
  324. */
  325. bool active;
  326. unsigned long enabled_power_domains;
  327. bool primary_enabled; /* is the primary plane (partially) visible? */
  328. bool lowfreq_avail;
  329. struct intel_overlay *overlay;
  330. struct intel_unpin_work *unpin_work;
  331. atomic_t unpin_work_count;
  332. /* Display surface base address adjustement for pageflips. Note that on
  333. * gen4+ this only adjusts up to a tile, offsets within a tile are
  334. * handled in the hw itself (with the TILEOFF register). */
  335. unsigned long dspaddr_offset;
  336. struct drm_i915_gem_object *cursor_bo;
  337. uint32_t cursor_addr;
  338. int16_t cursor_width, cursor_height;
  339. uint32_t cursor_cntl;
  340. uint32_t cursor_base;
  341. struct intel_plane_config plane_config;
  342. struct intel_crtc_config config;
  343. struct intel_crtc_config *new_config;
  344. bool new_enabled;
  345. /* reset counter value when the last flip was submitted */
  346. unsigned int reset_counter;
  347. /* Access to these should be protected by dev_priv->irq_lock. */
  348. bool cpu_fifo_underrun_disabled;
  349. bool pch_fifo_underrun_disabled;
  350. /* per-pipe watermark state */
  351. struct {
  352. /* watermarks currently being used */
  353. struct intel_pipe_wm active;
  354. } wm;
  355. wait_queue_head_t vbl_wait;
  356. int scanline_offset;
  357. struct intel_mmio_flip mmio_flip;
  358. };
  359. struct intel_plane_wm_parameters {
  360. uint32_t horiz_pixels;
  361. uint8_t bytes_per_pixel;
  362. bool enabled;
  363. bool scaled;
  364. };
  365. struct intel_plane {
  366. struct drm_plane base;
  367. int plane;
  368. enum pipe pipe;
  369. struct drm_i915_gem_object *obj;
  370. bool can_scale;
  371. int max_downscale;
  372. int crtc_x, crtc_y;
  373. unsigned int crtc_w, crtc_h;
  374. uint32_t src_x, src_y;
  375. uint32_t src_w, src_h;
  376. /* Since we need to change the watermarks before/after
  377. * enabling/disabling the planes, we need to store the parameters here
  378. * as the other pieces of the struct may not reflect the values we want
  379. * for the watermark calculations. Currently only Haswell uses this.
  380. */
  381. struct intel_plane_wm_parameters wm;
  382. void (*update_plane)(struct drm_plane *plane,
  383. struct drm_crtc *crtc,
  384. struct drm_framebuffer *fb,
  385. struct drm_i915_gem_object *obj,
  386. int crtc_x, int crtc_y,
  387. unsigned int crtc_w, unsigned int crtc_h,
  388. uint32_t x, uint32_t y,
  389. uint32_t src_w, uint32_t src_h);
  390. void (*disable_plane)(struct drm_plane *plane,
  391. struct drm_crtc *crtc);
  392. int (*update_colorkey)(struct drm_plane *plane,
  393. struct drm_intel_sprite_colorkey *key);
  394. void (*get_colorkey)(struct drm_plane *plane,
  395. struct drm_intel_sprite_colorkey *key);
  396. };
  397. struct intel_watermark_params {
  398. unsigned long fifo_size;
  399. unsigned long max_wm;
  400. unsigned long default_wm;
  401. unsigned long guard_size;
  402. unsigned long cacheline_size;
  403. };
  404. struct cxsr_latency {
  405. int is_desktop;
  406. int is_ddr3;
  407. unsigned long fsb_freq;
  408. unsigned long mem_freq;
  409. unsigned long display_sr;
  410. unsigned long display_hpll_disable;
  411. unsigned long cursor_sr;
  412. unsigned long cursor_hpll_disable;
  413. };
  414. #define to_intel_crtc(x) container_of(x, struct intel_crtc, base)
  415. #define to_intel_connector(x) container_of(x, struct intel_connector, base)
  416. #define to_intel_encoder(x) container_of(x, struct intel_encoder, base)
  417. #define to_intel_framebuffer(x) container_of(x, struct intel_framebuffer, base)
  418. #define to_intel_plane(x) container_of(x, struct intel_plane, base)
  419. #define intel_fb_obj(x) (x ? to_intel_framebuffer(x)->obj : NULL)
  420. struct intel_hdmi {
  421. u32 hdmi_reg;
  422. int ddc_bus;
  423. uint32_t color_range;
  424. bool color_range_auto;
  425. bool has_hdmi_sink;
  426. bool has_audio;
  427. enum hdmi_force_audio force_audio;
  428. bool rgb_quant_range_selectable;
  429. void (*write_infoframe)(struct drm_encoder *encoder,
  430. enum hdmi_infoframe_type type,
  431. const void *frame, ssize_t len);
  432. void (*set_infoframes)(struct drm_encoder *encoder,
  433. bool enable,
  434. struct drm_display_mode *adjusted_mode);
  435. };
  436. #define DP_MAX_DOWNSTREAM_PORTS 0x10
  437. /**
  438. * HIGH_RR is the highest eDP panel refresh rate read from EDID
  439. * LOW_RR is the lowest eDP panel refresh rate found from EDID
  440. * parsing for same resolution.
  441. */
  442. enum edp_drrs_refresh_rate_type {
  443. DRRS_HIGH_RR,
  444. DRRS_LOW_RR,
  445. DRRS_MAX_RR, /* RR count */
  446. };
  447. struct intel_dp {
  448. uint32_t output_reg;
  449. uint32_t aux_ch_ctl_reg;
  450. uint32_t DP;
  451. bool has_audio;
  452. enum hdmi_force_audio force_audio;
  453. uint32_t color_range;
  454. bool color_range_auto;
  455. uint8_t link_bw;
  456. uint8_t lane_count;
  457. uint8_t dpcd[DP_RECEIVER_CAP_SIZE];
  458. uint8_t psr_dpcd[EDP_PSR_RECEIVER_CAP_SIZE];
  459. uint8_t downstream_ports[DP_MAX_DOWNSTREAM_PORTS];
  460. struct drm_dp_aux aux;
  461. uint8_t train_set[4];
  462. int panel_power_up_delay;
  463. int panel_power_down_delay;
  464. int panel_power_cycle_delay;
  465. int backlight_on_delay;
  466. int backlight_off_delay;
  467. struct delayed_work panel_vdd_work;
  468. bool want_panel_vdd;
  469. unsigned long last_power_cycle;
  470. unsigned long last_power_on;
  471. unsigned long last_backlight_off;
  472. bool use_tps3;
  473. struct intel_connector *attached_connector;
  474. uint32_t (*get_aux_clock_divider)(struct intel_dp *dp, int index);
  475. /*
  476. * This function returns the value we have to program the AUX_CTL
  477. * register with to kick off an AUX transaction.
  478. */
  479. uint32_t (*get_aux_send_ctl)(struct intel_dp *dp,
  480. bool has_aux_irq,
  481. int send_bytes,
  482. uint32_t aux_clock_divider);
  483. struct {
  484. enum drrs_support_type type;
  485. enum edp_drrs_refresh_rate_type refresh_rate_type;
  486. struct mutex mutex;
  487. } drrs_state;
  488. };
  489. struct intel_digital_port {
  490. struct intel_encoder base;
  491. enum port port;
  492. u32 saved_port_bits;
  493. struct intel_dp dp;
  494. struct intel_hdmi hdmi;
  495. bool (*hpd_pulse)(struct intel_digital_port *, bool);
  496. };
  497. static inline int
  498. vlv_dport_to_channel(struct intel_digital_port *dport)
  499. {
  500. switch (dport->port) {
  501. case PORT_B:
  502. case PORT_D:
  503. return DPIO_CH0;
  504. case PORT_C:
  505. return DPIO_CH1;
  506. default:
  507. BUG();
  508. }
  509. }
  510. static inline int
  511. vlv_pipe_to_channel(enum pipe pipe)
  512. {
  513. switch (pipe) {
  514. case PIPE_A:
  515. case PIPE_C:
  516. return DPIO_CH0;
  517. case PIPE_B:
  518. return DPIO_CH1;
  519. default:
  520. BUG();
  521. }
  522. }
  523. static inline struct drm_crtc *
  524. intel_get_crtc_for_pipe(struct drm_device *dev, int pipe)
  525. {
  526. struct drm_i915_private *dev_priv = dev->dev_private;
  527. return dev_priv->pipe_to_crtc_mapping[pipe];
  528. }
  529. static inline struct drm_crtc *
  530. intel_get_crtc_for_plane(struct drm_device *dev, int plane)
  531. {
  532. struct drm_i915_private *dev_priv = dev->dev_private;
  533. return dev_priv->plane_to_crtc_mapping[plane];
  534. }
  535. struct intel_unpin_work {
  536. struct work_struct work;
  537. struct drm_crtc *crtc;
  538. struct drm_i915_gem_object *old_fb_obj;
  539. struct drm_i915_gem_object *pending_flip_obj;
  540. struct drm_pending_vblank_event *event;
  541. atomic_t pending;
  542. #define INTEL_FLIP_INACTIVE 0
  543. #define INTEL_FLIP_PENDING 1
  544. #define INTEL_FLIP_COMPLETE 2
  545. u32 flip_count;
  546. u32 gtt_offset;
  547. bool enable_stall_check;
  548. };
  549. struct intel_set_config {
  550. struct drm_encoder **save_connector_encoders;
  551. struct drm_crtc **save_encoder_crtcs;
  552. bool *save_crtc_enabled;
  553. bool fb_changed;
  554. bool mode_changed;
  555. };
  556. struct intel_load_detect_pipe {
  557. struct drm_framebuffer *release_fb;
  558. bool load_detect_temp;
  559. int dpms_mode;
  560. };
  561. static inline struct intel_encoder *
  562. intel_attached_encoder(struct drm_connector *connector)
  563. {
  564. return to_intel_connector(connector)->encoder;
  565. }
  566. static inline struct intel_digital_port *
  567. enc_to_dig_port(struct drm_encoder *encoder)
  568. {
  569. return container_of(encoder, struct intel_digital_port, base.base);
  570. }
  571. static inline struct intel_dp *enc_to_intel_dp(struct drm_encoder *encoder)
  572. {
  573. return &enc_to_dig_port(encoder)->dp;
  574. }
  575. static inline struct intel_digital_port *
  576. dp_to_dig_port(struct intel_dp *intel_dp)
  577. {
  578. return container_of(intel_dp, struct intel_digital_port, dp);
  579. }
  580. static inline struct intel_digital_port *
  581. hdmi_to_dig_port(struct intel_hdmi *intel_hdmi)
  582. {
  583. return container_of(intel_hdmi, struct intel_digital_port, hdmi);
  584. }
  585. /* i915_irq.c */
  586. bool intel_set_cpu_fifo_underrun_reporting(struct drm_device *dev,
  587. enum pipe pipe, bool enable);
  588. bool intel_set_pch_fifo_underrun_reporting(struct drm_device *dev,
  589. enum transcoder pch_transcoder,
  590. bool enable);
  591. void ilk_enable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask);
  592. void ilk_disable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask);
  593. void snb_enable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask);
  594. void snb_disable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask);
  595. void bdw_enable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask);
  596. void bdw_disable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask);
  597. void intel_runtime_pm_disable_interrupts(struct drm_device *dev);
  598. void intel_runtime_pm_restore_interrupts(struct drm_device *dev);
  599. int intel_get_crtc_scanline(struct intel_crtc *crtc);
  600. void i9xx_check_fifo_underruns(struct drm_device *dev);
  601. /* intel_crt.c */
  602. void intel_crt_init(struct drm_device *dev);
  603. /* intel_ddi.c */
  604. void intel_prepare_ddi(struct drm_device *dev);
  605. void hsw_fdi_link_train(struct drm_crtc *crtc);
  606. void intel_ddi_init(struct drm_device *dev, enum port port);
  607. enum port intel_ddi_get_encoder_port(struct intel_encoder *intel_encoder);
  608. bool intel_ddi_get_hw_state(struct intel_encoder *encoder, enum pipe *pipe);
  609. int intel_ddi_get_cdclk_freq(struct drm_i915_private *dev_priv);
  610. void intel_ddi_pll_init(struct drm_device *dev);
  611. void intel_ddi_enable_transcoder_func(struct drm_crtc *crtc);
  612. void intel_ddi_disable_transcoder_func(struct drm_i915_private *dev_priv,
  613. enum transcoder cpu_transcoder);
  614. void intel_ddi_enable_pipe_clock(struct intel_crtc *intel_crtc);
  615. void intel_ddi_disable_pipe_clock(struct intel_crtc *intel_crtc);
  616. bool intel_ddi_pll_select(struct intel_crtc *crtc);
  617. void intel_ddi_set_pipe_settings(struct drm_crtc *crtc);
  618. void intel_ddi_prepare_link_retrain(struct drm_encoder *encoder);
  619. bool intel_ddi_connector_get_hw_state(struct intel_connector *intel_connector);
  620. void intel_ddi_fdi_disable(struct drm_crtc *crtc);
  621. void intel_ddi_get_config(struct intel_encoder *encoder,
  622. struct intel_crtc_config *pipe_config);
  623. void intel_ddi_init_dp_buf_reg(struct intel_encoder *encoder);
  624. /* intel_display.c */
  625. const char *intel_output_name(int output);
  626. bool intel_has_pending_fb_unpin(struct drm_device *dev);
  627. int intel_pch_rawclk(struct drm_device *dev);
  628. void intel_mark_busy(struct drm_device *dev);
  629. void intel_fb_obj_invalidate(struct drm_i915_gem_object *obj,
  630. struct intel_engine_cs *ring);
  631. void intel_frontbuffer_flip_prepare(struct drm_device *dev,
  632. unsigned frontbuffer_bits);
  633. void intel_frontbuffer_flip_complete(struct drm_device *dev,
  634. unsigned frontbuffer_bits);
  635. void intel_frontbuffer_flush(struct drm_device *dev,
  636. unsigned frontbuffer_bits);
  637. /**
  638. * intel_frontbuffer_flip - prepare frontbuffer flip
  639. * @dev: DRM device
  640. * @frontbuffer_bits: frontbuffer plane tracking bits
  641. *
  642. * This function gets called after scheduling a flip on @obj. This is for
  643. * synchronous plane updates which will happen on the next vblank and which will
  644. * not get delayed by pending gpu rendering.
  645. *
  646. * Can be called without any locks held.
  647. */
  648. static inline
  649. void intel_frontbuffer_flip(struct drm_device *dev,
  650. unsigned frontbuffer_bits)
  651. {
  652. intel_frontbuffer_flush(dev, frontbuffer_bits);
  653. }
  654. void intel_fb_obj_flush(struct drm_i915_gem_object *obj, bool retire);
  655. void intel_mark_idle(struct drm_device *dev);
  656. void intel_crtc_restore_mode(struct drm_crtc *crtc);
  657. void intel_crtc_update_dpms(struct drm_crtc *crtc);
  658. void intel_encoder_destroy(struct drm_encoder *encoder);
  659. void intel_connector_dpms(struct drm_connector *, int mode);
  660. bool intel_connector_get_hw_state(struct intel_connector *connector);
  661. void intel_modeset_check_state(struct drm_device *dev);
  662. bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
  663. struct intel_digital_port *port);
  664. void intel_connector_attach_encoder(struct intel_connector *connector,
  665. struct intel_encoder *encoder);
  666. struct drm_encoder *intel_best_encoder(struct drm_connector *connector);
  667. struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev,
  668. struct drm_crtc *crtc);
  669. enum pipe intel_get_pipe_from_connector(struct intel_connector *connector);
  670. int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data,
  671. struct drm_file *file_priv);
  672. enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv,
  673. enum pipe pipe);
  674. void intel_wait_for_vblank(struct drm_device *dev, int pipe);
  675. void intel_wait_for_pipe_off(struct drm_device *dev, int pipe);
  676. int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp);
  677. void vlv_wait_port_ready(struct drm_i915_private *dev_priv,
  678. struct intel_digital_port *dport);
  679. bool intel_get_load_detect_pipe(struct drm_connector *connector,
  680. struct drm_display_mode *mode,
  681. struct intel_load_detect_pipe *old,
  682. struct drm_modeset_acquire_ctx *ctx);
  683. void intel_release_load_detect_pipe(struct drm_connector *connector,
  684. struct intel_load_detect_pipe *old,
  685. struct drm_modeset_acquire_ctx *ctx);
  686. int intel_pin_and_fence_fb_obj(struct drm_device *dev,
  687. struct drm_i915_gem_object *obj,
  688. struct intel_engine_cs *pipelined);
  689. void intel_unpin_fb_obj(struct drm_i915_gem_object *obj);
  690. struct drm_framebuffer *
  691. __intel_framebuffer_create(struct drm_device *dev,
  692. struct drm_mode_fb_cmd2 *mode_cmd,
  693. struct drm_i915_gem_object *obj);
  694. void intel_prepare_page_flip(struct drm_device *dev, int plane);
  695. void intel_finish_page_flip(struct drm_device *dev, int pipe);
  696. void intel_finish_page_flip_plane(struct drm_device *dev, int plane);
  697. /* shared dpll functions */
  698. struct intel_shared_dpll *intel_crtc_to_shared_dpll(struct intel_crtc *crtc);
  699. void assert_shared_dpll(struct drm_i915_private *dev_priv,
  700. struct intel_shared_dpll *pll,
  701. bool state);
  702. #define assert_shared_dpll_enabled(d, p) assert_shared_dpll(d, p, true)
  703. #define assert_shared_dpll_disabled(d, p) assert_shared_dpll(d, p, false)
  704. struct intel_shared_dpll *intel_get_shared_dpll(struct intel_crtc *crtc);
  705. void intel_put_shared_dpll(struct intel_crtc *crtc);
  706. /* modesetting asserts */
  707. void assert_pll(struct drm_i915_private *dev_priv,
  708. enum pipe pipe, bool state);
  709. #define assert_pll_enabled(d, p) assert_pll(d, p, true)
  710. #define assert_pll_disabled(d, p) assert_pll(d, p, false)
  711. void assert_fdi_rx_pll(struct drm_i915_private *dev_priv,
  712. enum pipe pipe, bool state);
  713. #define assert_fdi_rx_pll_enabled(d, p) assert_fdi_rx_pll(d, p, true)
  714. #define assert_fdi_rx_pll_disabled(d, p) assert_fdi_rx_pll(d, p, false)
  715. void assert_pipe(struct drm_i915_private *dev_priv, enum pipe pipe, bool state);
  716. #define assert_pipe_enabled(d, p) assert_pipe(d, p, true)
  717. #define assert_pipe_disabled(d, p) assert_pipe(d, p, false)
  718. void intel_write_eld(struct drm_encoder *encoder,
  719. struct drm_display_mode *mode);
  720. unsigned long intel_gen4_compute_page_offset(int *x, int *y,
  721. unsigned int tiling_mode,
  722. unsigned int bpp,
  723. unsigned int pitch);
  724. void intel_display_handle_reset(struct drm_device *dev);
  725. void hsw_enable_pc8(struct drm_i915_private *dev_priv);
  726. void hsw_disable_pc8(struct drm_i915_private *dev_priv);
  727. void intel_dp_get_m_n(struct intel_crtc *crtc,
  728. struct intel_crtc_config *pipe_config);
  729. int intel_dotclock_calculate(int link_freq, const struct intel_link_m_n *m_n);
  730. void
  731. ironlake_check_encoder_dotclock(const struct intel_crtc_config *pipe_config,
  732. int dotclock);
  733. bool intel_crtc_active(struct drm_crtc *crtc);
  734. void hsw_enable_ips(struct intel_crtc *crtc);
  735. void hsw_disable_ips(struct intel_crtc *crtc);
  736. void intel_display_set_init_power(struct drm_i915_private *dev, bool enable);
  737. enum intel_display_power_domain
  738. intel_display_port_power_domain(struct intel_encoder *intel_encoder);
  739. void intel_mode_from_pipe_config(struct drm_display_mode *mode,
  740. struct intel_crtc_config *pipe_config);
  741. int intel_format_to_fourcc(int format);
  742. void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc);
  743. /* intel_dp.c */
  744. void intel_dp_init(struct drm_device *dev, int output_reg, enum port port);
  745. bool intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
  746. struct intel_connector *intel_connector);
  747. void intel_dp_start_link_train(struct intel_dp *intel_dp);
  748. void intel_dp_complete_link_train(struct intel_dp *intel_dp);
  749. void intel_dp_stop_link_train(struct intel_dp *intel_dp);
  750. void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode);
  751. void intel_dp_encoder_destroy(struct drm_encoder *encoder);
  752. void intel_dp_check_link_status(struct intel_dp *intel_dp);
  753. int intel_dp_sink_crc(struct intel_dp *intel_dp, u8 *crc);
  754. bool intel_dp_compute_config(struct intel_encoder *encoder,
  755. struct intel_crtc_config *pipe_config);
  756. bool intel_dp_is_edp(struct drm_device *dev, enum port port);
  757. bool intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port,
  758. bool long_hpd);
  759. void intel_edp_backlight_on(struct intel_dp *intel_dp);
  760. void intel_edp_backlight_off(struct intel_dp *intel_dp);
  761. void intel_edp_panel_vdd_on(struct intel_dp *intel_dp);
  762. void intel_edp_panel_on(struct intel_dp *intel_dp);
  763. void intel_edp_panel_off(struct intel_dp *intel_dp);
  764. void intel_edp_psr_enable(struct intel_dp *intel_dp);
  765. void intel_edp_psr_disable(struct intel_dp *intel_dp);
  766. void intel_dp_set_drrs_state(struct drm_device *dev, int refresh_rate);
  767. void intel_edp_psr_exit(struct drm_device *dev);
  768. void intel_edp_psr_init(struct drm_device *dev);
  769. /* intel_dsi.c */
  770. void intel_dsi_init(struct drm_device *dev);
  771. /* intel_dvo.c */
  772. void intel_dvo_init(struct drm_device *dev);
  773. /* legacy fbdev emulation in intel_fbdev.c */
  774. #ifdef CONFIG_DRM_I915_FBDEV
  775. extern int intel_fbdev_init(struct drm_device *dev);
  776. extern void intel_fbdev_initial_config(struct drm_device *dev);
  777. extern void intel_fbdev_fini(struct drm_device *dev);
  778. extern void intel_fbdev_set_suspend(struct drm_device *dev, int state);
  779. extern void intel_fbdev_output_poll_changed(struct drm_device *dev);
  780. extern void intel_fbdev_restore_mode(struct drm_device *dev);
  781. #else
  782. static inline int intel_fbdev_init(struct drm_device *dev)
  783. {
  784. return 0;
  785. }
  786. static inline void intel_fbdev_initial_config(struct drm_device *dev)
  787. {
  788. }
  789. static inline void intel_fbdev_fini(struct drm_device *dev)
  790. {
  791. }
  792. static inline void intel_fbdev_set_suspend(struct drm_device *dev, int state)
  793. {
  794. }
  795. static inline void intel_fbdev_restore_mode(struct drm_device *dev)
  796. {
  797. }
  798. #endif
  799. /* intel_hdmi.c */
  800. void intel_hdmi_init(struct drm_device *dev, int hdmi_reg, enum port port);
  801. void intel_hdmi_init_connector(struct intel_digital_port *intel_dig_port,
  802. struct intel_connector *intel_connector);
  803. struct intel_hdmi *enc_to_intel_hdmi(struct drm_encoder *encoder);
  804. bool intel_hdmi_compute_config(struct intel_encoder *encoder,
  805. struct intel_crtc_config *pipe_config);
  806. /* intel_lvds.c */
  807. void intel_lvds_init(struct drm_device *dev);
  808. bool intel_is_dual_link_lvds(struct drm_device *dev);
  809. /* intel_modes.c */
  810. int intel_connector_update_modes(struct drm_connector *connector,
  811. struct edid *edid);
  812. int intel_ddc_get_modes(struct drm_connector *c, struct i2c_adapter *adapter);
  813. void intel_attach_force_audio_property(struct drm_connector *connector);
  814. void intel_attach_broadcast_rgb_property(struct drm_connector *connector);
  815. /* intel_overlay.c */
  816. void intel_setup_overlay(struct drm_device *dev);
  817. void intel_cleanup_overlay(struct drm_device *dev);
  818. int intel_overlay_switch_off(struct intel_overlay *overlay);
  819. int intel_overlay_put_image(struct drm_device *dev, void *data,
  820. struct drm_file *file_priv);
  821. int intel_overlay_attrs(struct drm_device *dev, void *data,
  822. struct drm_file *file_priv);
  823. /* intel_panel.c */
  824. int intel_panel_init(struct intel_panel *panel,
  825. struct drm_display_mode *fixed_mode,
  826. struct drm_display_mode *downclock_mode);
  827. void intel_panel_fini(struct intel_panel *panel);
  828. void intel_fixed_panel_mode(const struct drm_display_mode *fixed_mode,
  829. struct drm_display_mode *adjusted_mode);
  830. void intel_pch_panel_fitting(struct intel_crtc *crtc,
  831. struct intel_crtc_config *pipe_config,
  832. int fitting_mode);
  833. void intel_gmch_panel_fitting(struct intel_crtc *crtc,
  834. struct intel_crtc_config *pipe_config,
  835. int fitting_mode);
  836. void intel_panel_set_backlight(struct intel_connector *connector, u32 level,
  837. u32 max);
  838. int intel_panel_setup_backlight(struct drm_connector *connector);
  839. void intel_panel_enable_backlight(struct intel_connector *connector);
  840. void intel_panel_disable_backlight(struct intel_connector *connector);
  841. void intel_panel_destroy_backlight(struct drm_connector *connector);
  842. void intel_panel_init_backlight_funcs(struct drm_device *dev);
  843. enum drm_connector_status intel_panel_detect(struct drm_device *dev);
  844. extern struct drm_display_mode *intel_find_panel_downclock(
  845. struct drm_device *dev,
  846. struct drm_display_mode *fixed_mode,
  847. struct drm_connector *connector);
  848. /* intel_pm.c */
  849. void intel_init_clock_gating(struct drm_device *dev);
  850. void intel_suspend_hw(struct drm_device *dev);
  851. int ilk_wm_max_level(const struct drm_device *dev);
  852. void intel_update_watermarks(struct drm_crtc *crtc);
  853. void intel_update_sprite_watermarks(struct drm_plane *plane,
  854. struct drm_crtc *crtc,
  855. uint32_t sprite_width, int pixel_size,
  856. bool enabled, bool scaled);
  857. void intel_init_pm(struct drm_device *dev);
  858. void intel_pm_setup(struct drm_device *dev);
  859. bool intel_fbc_enabled(struct drm_device *dev);
  860. void intel_update_fbc(struct drm_device *dev);
  861. void intel_gpu_ips_init(struct drm_i915_private *dev_priv);
  862. void intel_gpu_ips_teardown(void);
  863. int intel_power_domains_init(struct drm_i915_private *);
  864. void intel_power_domains_remove(struct drm_i915_private *);
  865. bool intel_display_power_enabled(struct drm_i915_private *dev_priv,
  866. enum intel_display_power_domain domain);
  867. bool intel_display_power_enabled_unlocked(struct drm_i915_private *dev_priv,
  868. enum intel_display_power_domain domain);
  869. void intel_display_power_get(struct drm_i915_private *dev_priv,
  870. enum intel_display_power_domain domain);
  871. void intel_display_power_put(struct drm_i915_private *dev_priv,
  872. enum intel_display_power_domain domain);
  873. void intel_power_domains_init_hw(struct drm_i915_private *dev_priv);
  874. void intel_init_gt_powersave(struct drm_device *dev);
  875. void intel_cleanup_gt_powersave(struct drm_device *dev);
  876. void intel_enable_gt_powersave(struct drm_device *dev);
  877. void intel_disable_gt_powersave(struct drm_device *dev);
  878. void intel_suspend_gt_powersave(struct drm_device *dev);
  879. void intel_reset_gt_powersave(struct drm_device *dev);
  880. void ironlake_teardown_rc6(struct drm_device *dev);
  881. void gen6_update_ring_freq(struct drm_device *dev);
  882. void gen6_rps_idle(struct drm_i915_private *dev_priv);
  883. void gen6_rps_boost(struct drm_i915_private *dev_priv);
  884. void intel_aux_display_runtime_get(struct drm_i915_private *dev_priv);
  885. void intel_aux_display_runtime_put(struct drm_i915_private *dev_priv);
  886. void intel_runtime_pm_get(struct drm_i915_private *dev_priv);
  887. void intel_runtime_pm_get_noresume(struct drm_i915_private *dev_priv);
  888. void intel_runtime_pm_put(struct drm_i915_private *dev_priv);
  889. void intel_init_runtime_pm(struct drm_i915_private *dev_priv);
  890. void intel_fini_runtime_pm(struct drm_i915_private *dev_priv);
  891. void ilk_wm_get_hw_state(struct drm_device *dev);
  892. /* intel_sdvo.c */
  893. bool intel_sdvo_init(struct drm_device *dev, uint32_t sdvo_reg, bool is_sdvob);
  894. /* intel_sprite.c */
  895. int intel_plane_init(struct drm_device *dev, enum pipe pipe, int plane);
  896. void intel_flush_primary_plane(struct drm_i915_private *dev_priv,
  897. enum plane plane);
  898. void intel_plane_restore(struct drm_plane *plane);
  899. void intel_plane_disable(struct drm_plane *plane);
  900. int intel_sprite_set_colorkey(struct drm_device *dev, void *data,
  901. struct drm_file *file_priv);
  902. int intel_sprite_get_colorkey(struct drm_device *dev, void *data,
  903. struct drm_file *file_priv);
  904. /* intel_tv.c */
  905. void intel_tv_init(struct drm_device *dev);
  906. #endif /* __INTEL_DRV_H__ */