intel_drv.h 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044
  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. uint32_t vert_pixels;
  362. uint8_t bytes_per_pixel;
  363. bool enabled;
  364. bool scaled;
  365. };
  366. struct intel_plane {
  367. struct drm_plane base;
  368. int plane;
  369. enum pipe pipe;
  370. struct drm_i915_gem_object *obj;
  371. bool can_scale;
  372. int max_downscale;
  373. int crtc_x, crtc_y;
  374. unsigned int crtc_w, crtc_h;
  375. uint32_t src_x, src_y;
  376. uint32_t src_w, src_h;
  377. /* Since we need to change the watermarks before/after
  378. * enabling/disabling the planes, we need to store the parameters here
  379. * as the other pieces of the struct may not reflect the values we want
  380. * for the watermark calculations. Currently only Haswell uses this.
  381. */
  382. struct intel_plane_wm_parameters wm;
  383. void (*update_plane)(struct drm_plane *plane,
  384. struct drm_crtc *crtc,
  385. struct drm_framebuffer *fb,
  386. struct drm_i915_gem_object *obj,
  387. int crtc_x, int crtc_y,
  388. unsigned int crtc_w, unsigned int crtc_h,
  389. uint32_t x, uint32_t y,
  390. uint32_t src_w, uint32_t src_h);
  391. void (*disable_plane)(struct drm_plane *plane,
  392. struct drm_crtc *crtc);
  393. int (*update_colorkey)(struct drm_plane *plane,
  394. struct drm_intel_sprite_colorkey *key);
  395. void (*get_colorkey)(struct drm_plane *plane,
  396. struct drm_intel_sprite_colorkey *key);
  397. };
  398. struct intel_watermark_params {
  399. unsigned long fifo_size;
  400. unsigned long max_wm;
  401. unsigned long default_wm;
  402. unsigned long guard_size;
  403. unsigned long cacheline_size;
  404. };
  405. struct cxsr_latency {
  406. int is_desktop;
  407. int is_ddr3;
  408. unsigned long fsb_freq;
  409. unsigned long mem_freq;
  410. unsigned long display_sr;
  411. unsigned long display_hpll_disable;
  412. unsigned long cursor_sr;
  413. unsigned long cursor_hpll_disable;
  414. };
  415. #define to_intel_crtc(x) container_of(x, struct intel_crtc, base)
  416. #define to_intel_connector(x) container_of(x, struct intel_connector, base)
  417. #define to_intel_encoder(x) container_of(x, struct intel_encoder, base)
  418. #define to_intel_framebuffer(x) container_of(x, struct intel_framebuffer, base)
  419. #define to_intel_plane(x) container_of(x, struct intel_plane, base)
  420. #define intel_fb_obj(x) (x ? to_intel_framebuffer(x)->obj : NULL)
  421. struct intel_hdmi {
  422. u32 hdmi_reg;
  423. int ddc_bus;
  424. uint32_t color_range;
  425. bool color_range_auto;
  426. bool has_hdmi_sink;
  427. bool has_audio;
  428. enum hdmi_force_audio force_audio;
  429. bool rgb_quant_range_selectable;
  430. enum hdmi_picture_aspect aspect_ratio;
  431. void (*write_infoframe)(struct drm_encoder *encoder,
  432. enum hdmi_infoframe_type type,
  433. const void *frame, ssize_t len);
  434. void (*set_infoframes)(struct drm_encoder *encoder,
  435. bool enable,
  436. struct drm_display_mode *adjusted_mode);
  437. };
  438. #define DP_MAX_DOWNSTREAM_PORTS 0x10
  439. /**
  440. * HIGH_RR is the highest eDP panel refresh rate read from EDID
  441. * LOW_RR is the lowest eDP panel refresh rate found from EDID
  442. * parsing for same resolution.
  443. */
  444. enum edp_drrs_refresh_rate_type {
  445. DRRS_HIGH_RR,
  446. DRRS_LOW_RR,
  447. DRRS_MAX_RR, /* RR count */
  448. };
  449. struct intel_dp {
  450. uint32_t output_reg;
  451. uint32_t aux_ch_ctl_reg;
  452. uint32_t DP;
  453. bool has_audio;
  454. enum hdmi_force_audio force_audio;
  455. uint32_t color_range;
  456. bool color_range_auto;
  457. uint8_t link_bw;
  458. uint8_t lane_count;
  459. uint8_t dpcd[DP_RECEIVER_CAP_SIZE];
  460. uint8_t psr_dpcd[EDP_PSR_RECEIVER_CAP_SIZE];
  461. uint8_t downstream_ports[DP_MAX_DOWNSTREAM_PORTS];
  462. struct drm_dp_aux aux;
  463. uint8_t train_set[4];
  464. int panel_power_up_delay;
  465. int panel_power_down_delay;
  466. int panel_power_cycle_delay;
  467. int backlight_on_delay;
  468. int backlight_off_delay;
  469. struct delayed_work panel_vdd_work;
  470. bool want_panel_vdd;
  471. unsigned long last_power_cycle;
  472. unsigned long last_power_on;
  473. unsigned long last_backlight_off;
  474. bool use_tps3;
  475. struct intel_connector *attached_connector;
  476. uint32_t (*get_aux_clock_divider)(struct intel_dp *dp, int index);
  477. /*
  478. * This function returns the value we have to program the AUX_CTL
  479. * register with to kick off an AUX transaction.
  480. */
  481. uint32_t (*get_aux_send_ctl)(struct intel_dp *dp,
  482. bool has_aux_irq,
  483. int send_bytes,
  484. uint32_t aux_clock_divider);
  485. struct {
  486. enum drrs_support_type type;
  487. enum edp_drrs_refresh_rate_type refresh_rate_type;
  488. struct mutex mutex;
  489. } drrs_state;
  490. };
  491. struct intel_digital_port {
  492. struct intel_encoder base;
  493. enum port port;
  494. u32 saved_port_bits;
  495. struct intel_dp dp;
  496. struct intel_hdmi hdmi;
  497. bool (*hpd_pulse)(struct intel_digital_port *, bool);
  498. };
  499. static inline int
  500. vlv_dport_to_channel(struct intel_digital_port *dport)
  501. {
  502. switch (dport->port) {
  503. case PORT_B:
  504. case PORT_D:
  505. return DPIO_CH0;
  506. case PORT_C:
  507. return DPIO_CH1;
  508. default:
  509. BUG();
  510. }
  511. }
  512. static inline int
  513. vlv_pipe_to_channel(enum pipe pipe)
  514. {
  515. switch (pipe) {
  516. case PIPE_A:
  517. case PIPE_C:
  518. return DPIO_CH0;
  519. case PIPE_B:
  520. return DPIO_CH1;
  521. default:
  522. BUG();
  523. }
  524. }
  525. static inline struct drm_crtc *
  526. intel_get_crtc_for_pipe(struct drm_device *dev, int pipe)
  527. {
  528. struct drm_i915_private *dev_priv = dev->dev_private;
  529. return dev_priv->pipe_to_crtc_mapping[pipe];
  530. }
  531. static inline struct drm_crtc *
  532. intel_get_crtc_for_plane(struct drm_device *dev, int plane)
  533. {
  534. struct drm_i915_private *dev_priv = dev->dev_private;
  535. return dev_priv->plane_to_crtc_mapping[plane];
  536. }
  537. struct intel_unpin_work {
  538. struct work_struct work;
  539. struct drm_crtc *crtc;
  540. struct drm_i915_gem_object *old_fb_obj;
  541. struct drm_i915_gem_object *pending_flip_obj;
  542. struct drm_pending_vblank_event *event;
  543. atomic_t pending;
  544. #define INTEL_FLIP_INACTIVE 0
  545. #define INTEL_FLIP_PENDING 1
  546. #define INTEL_FLIP_COMPLETE 2
  547. u32 flip_count;
  548. u32 gtt_offset;
  549. bool enable_stall_check;
  550. };
  551. struct intel_set_config {
  552. struct drm_encoder **save_connector_encoders;
  553. struct drm_crtc **save_encoder_crtcs;
  554. bool *save_crtc_enabled;
  555. bool fb_changed;
  556. bool mode_changed;
  557. };
  558. struct intel_load_detect_pipe {
  559. struct drm_framebuffer *release_fb;
  560. bool load_detect_temp;
  561. int dpms_mode;
  562. };
  563. static inline struct intel_encoder *
  564. intel_attached_encoder(struct drm_connector *connector)
  565. {
  566. return to_intel_connector(connector)->encoder;
  567. }
  568. static inline struct intel_digital_port *
  569. enc_to_dig_port(struct drm_encoder *encoder)
  570. {
  571. return container_of(encoder, struct intel_digital_port, base.base);
  572. }
  573. static inline struct intel_dp *enc_to_intel_dp(struct drm_encoder *encoder)
  574. {
  575. return &enc_to_dig_port(encoder)->dp;
  576. }
  577. static inline struct intel_digital_port *
  578. dp_to_dig_port(struct intel_dp *intel_dp)
  579. {
  580. return container_of(intel_dp, struct intel_digital_port, dp);
  581. }
  582. static inline struct intel_digital_port *
  583. hdmi_to_dig_port(struct intel_hdmi *intel_hdmi)
  584. {
  585. return container_of(intel_hdmi, struct intel_digital_port, hdmi);
  586. }
  587. /* i915_irq.c */
  588. bool intel_set_cpu_fifo_underrun_reporting(struct drm_device *dev,
  589. enum pipe pipe, bool enable);
  590. bool intel_set_pch_fifo_underrun_reporting(struct drm_device *dev,
  591. enum transcoder pch_transcoder,
  592. bool enable);
  593. void gen5_enable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask);
  594. void gen5_disable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask);
  595. void gen6_enable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask);
  596. void gen6_disable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask);
  597. void gen8_enable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask);
  598. void gen8_disable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask);
  599. void intel_runtime_pm_disable_interrupts(struct drm_device *dev);
  600. void intel_runtime_pm_restore_interrupts(struct drm_device *dev);
  601. int intel_get_crtc_scanline(struct intel_crtc *crtc);
  602. void i9xx_check_fifo_underruns(struct drm_device *dev);
  603. void gen8_irq_power_well_post_enable(struct drm_i915_private *dev_priv);
  604. /* intel_crt.c */
  605. void intel_crt_init(struct drm_device *dev);
  606. /* intel_ddi.c */
  607. void intel_prepare_ddi(struct drm_device *dev);
  608. void hsw_fdi_link_train(struct drm_crtc *crtc);
  609. void intel_ddi_init(struct drm_device *dev, enum port port);
  610. enum port intel_ddi_get_encoder_port(struct intel_encoder *intel_encoder);
  611. bool intel_ddi_get_hw_state(struct intel_encoder *encoder, enum pipe *pipe);
  612. int intel_ddi_get_cdclk_freq(struct drm_i915_private *dev_priv);
  613. void intel_ddi_pll_init(struct drm_device *dev);
  614. void intel_ddi_enable_transcoder_func(struct drm_crtc *crtc);
  615. void intel_ddi_disable_transcoder_func(struct drm_i915_private *dev_priv,
  616. enum transcoder cpu_transcoder);
  617. void intel_ddi_enable_pipe_clock(struct intel_crtc *intel_crtc);
  618. void intel_ddi_disable_pipe_clock(struct intel_crtc *intel_crtc);
  619. bool intel_ddi_pll_select(struct intel_crtc *crtc);
  620. void intel_ddi_set_pipe_settings(struct drm_crtc *crtc);
  621. void intel_ddi_prepare_link_retrain(struct drm_encoder *encoder);
  622. bool intel_ddi_connector_get_hw_state(struct intel_connector *intel_connector);
  623. void intel_ddi_fdi_disable(struct drm_crtc *crtc);
  624. void intel_ddi_get_config(struct intel_encoder *encoder,
  625. struct intel_crtc_config *pipe_config);
  626. /* intel_display.c */
  627. const char *intel_output_name(int output);
  628. bool intel_has_pending_fb_unpin(struct drm_device *dev);
  629. int intel_pch_rawclk(struct drm_device *dev);
  630. void intel_mark_busy(struct drm_device *dev);
  631. void intel_fb_obj_invalidate(struct drm_i915_gem_object *obj,
  632. struct intel_engine_cs *ring);
  633. void intel_frontbuffer_flip_prepare(struct drm_device *dev,
  634. unsigned frontbuffer_bits);
  635. void intel_frontbuffer_flip_complete(struct drm_device *dev,
  636. unsigned frontbuffer_bits);
  637. void intel_frontbuffer_flush(struct drm_device *dev,
  638. unsigned frontbuffer_bits);
  639. /**
  640. * intel_frontbuffer_flip - prepare frontbuffer flip
  641. * @dev: DRM device
  642. * @frontbuffer_bits: frontbuffer plane tracking bits
  643. *
  644. * This function gets called after scheduling a flip on @obj. This is for
  645. * synchronous plane updates which will happen on the next vblank and which will
  646. * not get delayed by pending gpu rendering.
  647. *
  648. * Can be called without any locks held.
  649. */
  650. static inline
  651. void intel_frontbuffer_flip(struct drm_device *dev,
  652. unsigned frontbuffer_bits)
  653. {
  654. intel_frontbuffer_flush(dev, frontbuffer_bits);
  655. }
  656. void intel_fb_obj_flush(struct drm_i915_gem_object *obj, bool retire);
  657. void intel_mark_idle(struct drm_device *dev);
  658. void intel_crtc_restore_mode(struct drm_crtc *crtc);
  659. void intel_crtc_control(struct drm_crtc *crtc, bool enable);
  660. void intel_crtc_update_dpms(struct drm_crtc *crtc);
  661. void intel_encoder_destroy(struct drm_encoder *encoder);
  662. void intel_connector_dpms(struct drm_connector *, int mode);
  663. bool intel_connector_get_hw_state(struct intel_connector *connector);
  664. void intel_modeset_check_state(struct drm_device *dev);
  665. bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
  666. struct intel_digital_port *port);
  667. void intel_connector_attach_encoder(struct intel_connector *connector,
  668. struct intel_encoder *encoder);
  669. struct drm_encoder *intel_best_encoder(struct drm_connector *connector);
  670. struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev,
  671. struct drm_crtc *crtc);
  672. enum pipe intel_get_pipe_from_connector(struct intel_connector *connector);
  673. int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data,
  674. struct drm_file *file_priv);
  675. enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv,
  676. enum pipe pipe);
  677. void intel_wait_for_vblank(struct drm_device *dev, int pipe);
  678. void intel_wait_for_pipe_off(struct drm_device *dev, int pipe);
  679. int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp);
  680. void vlv_wait_port_ready(struct drm_i915_private *dev_priv,
  681. struct intel_digital_port *dport);
  682. bool intel_get_load_detect_pipe(struct drm_connector *connector,
  683. struct drm_display_mode *mode,
  684. struct intel_load_detect_pipe *old,
  685. struct drm_modeset_acquire_ctx *ctx);
  686. void intel_release_load_detect_pipe(struct drm_connector *connector,
  687. struct intel_load_detect_pipe *old,
  688. struct drm_modeset_acquire_ctx *ctx);
  689. int intel_pin_and_fence_fb_obj(struct drm_device *dev,
  690. struct drm_i915_gem_object *obj,
  691. struct intel_engine_cs *pipelined);
  692. void intel_unpin_fb_obj(struct drm_i915_gem_object *obj);
  693. struct drm_framebuffer *
  694. __intel_framebuffer_create(struct drm_device *dev,
  695. struct drm_mode_fb_cmd2 *mode_cmd,
  696. struct drm_i915_gem_object *obj);
  697. void intel_prepare_page_flip(struct drm_device *dev, int plane);
  698. void intel_finish_page_flip(struct drm_device *dev, int pipe);
  699. void intel_finish_page_flip_plane(struct drm_device *dev, int plane);
  700. /* shared dpll functions */
  701. struct intel_shared_dpll *intel_crtc_to_shared_dpll(struct intel_crtc *crtc);
  702. void assert_shared_dpll(struct drm_i915_private *dev_priv,
  703. struct intel_shared_dpll *pll,
  704. bool state);
  705. #define assert_shared_dpll_enabled(d, p) assert_shared_dpll(d, p, true)
  706. #define assert_shared_dpll_disabled(d, p) assert_shared_dpll(d, p, false)
  707. struct intel_shared_dpll *intel_get_shared_dpll(struct intel_crtc *crtc);
  708. void intel_put_shared_dpll(struct intel_crtc *crtc);
  709. /* modesetting asserts */
  710. void assert_pll(struct drm_i915_private *dev_priv,
  711. enum pipe pipe, bool state);
  712. #define assert_pll_enabled(d, p) assert_pll(d, p, true)
  713. #define assert_pll_disabled(d, p) assert_pll(d, p, false)
  714. void assert_fdi_rx_pll(struct drm_i915_private *dev_priv,
  715. enum pipe pipe, bool state);
  716. #define assert_fdi_rx_pll_enabled(d, p) assert_fdi_rx_pll(d, p, true)
  717. #define assert_fdi_rx_pll_disabled(d, p) assert_fdi_rx_pll(d, p, false)
  718. void assert_pipe(struct drm_i915_private *dev_priv, enum pipe pipe, bool state);
  719. #define assert_pipe_enabled(d, p) assert_pipe(d, p, true)
  720. #define assert_pipe_disabled(d, p) assert_pipe(d, p, false)
  721. void intel_write_eld(struct drm_encoder *encoder,
  722. struct drm_display_mode *mode);
  723. unsigned long intel_gen4_compute_page_offset(int *x, int *y,
  724. unsigned int tiling_mode,
  725. unsigned int bpp,
  726. unsigned int pitch);
  727. void intel_display_handle_reset(struct drm_device *dev);
  728. void hsw_enable_pc8(struct drm_i915_private *dev_priv);
  729. void hsw_disable_pc8(struct drm_i915_private *dev_priv);
  730. void intel_dp_get_m_n(struct intel_crtc *crtc,
  731. struct intel_crtc_config *pipe_config);
  732. int intel_dotclock_calculate(int link_freq, const struct intel_link_m_n *m_n);
  733. void
  734. ironlake_check_encoder_dotclock(const struct intel_crtc_config *pipe_config,
  735. int dotclock);
  736. bool intel_crtc_active(struct drm_crtc *crtc);
  737. void hsw_enable_ips(struct intel_crtc *crtc);
  738. void hsw_disable_ips(struct intel_crtc *crtc);
  739. void intel_display_set_init_power(struct drm_i915_private *dev, bool enable);
  740. enum intel_display_power_domain
  741. intel_display_port_power_domain(struct intel_encoder *intel_encoder);
  742. void intel_mode_from_pipe_config(struct drm_display_mode *mode,
  743. struct intel_crtc_config *pipe_config);
  744. int intel_format_to_fourcc(int format);
  745. void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc);
  746. /* intel_dp.c */
  747. void intel_dp_init(struct drm_device *dev, int output_reg, enum port port);
  748. bool intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
  749. struct intel_connector *intel_connector);
  750. void intel_dp_start_link_train(struct intel_dp *intel_dp);
  751. void intel_dp_complete_link_train(struct intel_dp *intel_dp);
  752. void intel_dp_stop_link_train(struct intel_dp *intel_dp);
  753. void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode);
  754. void intel_dp_encoder_destroy(struct drm_encoder *encoder);
  755. void intel_dp_check_link_status(struct intel_dp *intel_dp);
  756. int intel_dp_sink_crc(struct intel_dp *intel_dp, u8 *crc);
  757. bool intel_dp_compute_config(struct intel_encoder *encoder,
  758. struct intel_crtc_config *pipe_config);
  759. bool intel_dp_is_edp(struct drm_device *dev, enum port port);
  760. bool intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port,
  761. bool long_hpd);
  762. void intel_edp_backlight_on(struct intel_dp *intel_dp);
  763. void intel_edp_backlight_off(struct intel_dp *intel_dp);
  764. void intel_edp_panel_vdd_on(struct intel_dp *intel_dp);
  765. void intel_edp_panel_on(struct intel_dp *intel_dp);
  766. void intel_edp_panel_off(struct intel_dp *intel_dp);
  767. void intel_edp_psr_enable(struct intel_dp *intel_dp);
  768. void intel_edp_psr_disable(struct intel_dp *intel_dp);
  769. void intel_dp_set_drrs_state(struct drm_device *dev, int refresh_rate);
  770. void intel_edp_psr_invalidate(struct drm_device *dev,
  771. unsigned frontbuffer_bits);
  772. void intel_edp_psr_flush(struct drm_device *dev,
  773. unsigned frontbuffer_bits);
  774. void intel_edp_psr_init(struct drm_device *dev);
  775. /* intel_dsi.c */
  776. void intel_dsi_init(struct drm_device *dev);
  777. /* intel_dvo.c */
  778. void intel_dvo_init(struct drm_device *dev);
  779. /* legacy fbdev emulation in intel_fbdev.c */
  780. #ifdef CONFIG_DRM_I915_FBDEV
  781. extern int intel_fbdev_init(struct drm_device *dev);
  782. extern void intel_fbdev_initial_config(struct drm_device *dev);
  783. extern void intel_fbdev_fini(struct drm_device *dev);
  784. extern void intel_fbdev_set_suspend(struct drm_device *dev, int state);
  785. extern void intel_fbdev_output_poll_changed(struct drm_device *dev);
  786. extern void intel_fbdev_restore_mode(struct drm_device *dev);
  787. #else
  788. static inline int intel_fbdev_init(struct drm_device *dev)
  789. {
  790. return 0;
  791. }
  792. static inline void intel_fbdev_initial_config(struct drm_device *dev)
  793. {
  794. }
  795. static inline void intel_fbdev_fini(struct drm_device *dev)
  796. {
  797. }
  798. static inline void intel_fbdev_set_suspend(struct drm_device *dev, int state)
  799. {
  800. }
  801. static inline void intel_fbdev_restore_mode(struct drm_device *dev)
  802. {
  803. }
  804. #endif
  805. /* intel_hdmi.c */
  806. void intel_hdmi_init(struct drm_device *dev, int hdmi_reg, enum port port);
  807. void intel_hdmi_init_connector(struct intel_digital_port *intel_dig_port,
  808. struct intel_connector *intel_connector);
  809. struct intel_hdmi *enc_to_intel_hdmi(struct drm_encoder *encoder);
  810. bool intel_hdmi_compute_config(struct intel_encoder *encoder,
  811. struct intel_crtc_config *pipe_config);
  812. /* intel_lvds.c */
  813. void intel_lvds_init(struct drm_device *dev);
  814. bool intel_is_dual_link_lvds(struct drm_device *dev);
  815. /* intel_modes.c */
  816. int intel_connector_update_modes(struct drm_connector *connector,
  817. struct edid *edid);
  818. int intel_ddc_get_modes(struct drm_connector *c, struct i2c_adapter *adapter);
  819. void intel_attach_force_audio_property(struct drm_connector *connector);
  820. void intel_attach_broadcast_rgb_property(struct drm_connector *connector);
  821. /* intel_overlay.c */
  822. void intel_setup_overlay(struct drm_device *dev);
  823. void intel_cleanup_overlay(struct drm_device *dev);
  824. int intel_overlay_switch_off(struct intel_overlay *overlay);
  825. int intel_overlay_put_image(struct drm_device *dev, void *data,
  826. struct drm_file *file_priv);
  827. int intel_overlay_attrs(struct drm_device *dev, void *data,
  828. struct drm_file *file_priv);
  829. /* intel_panel.c */
  830. int intel_panel_init(struct intel_panel *panel,
  831. struct drm_display_mode *fixed_mode,
  832. struct drm_display_mode *downclock_mode);
  833. void intel_panel_fini(struct intel_panel *panel);
  834. void intel_fixed_panel_mode(const struct drm_display_mode *fixed_mode,
  835. struct drm_display_mode *adjusted_mode);
  836. void intel_pch_panel_fitting(struct intel_crtc *crtc,
  837. struct intel_crtc_config *pipe_config,
  838. int fitting_mode);
  839. void intel_gmch_panel_fitting(struct intel_crtc *crtc,
  840. struct intel_crtc_config *pipe_config,
  841. int fitting_mode);
  842. void intel_panel_set_backlight(struct intel_connector *connector, u32 level,
  843. u32 max);
  844. int intel_panel_setup_backlight(struct drm_connector *connector);
  845. void intel_panel_enable_backlight(struct intel_connector *connector);
  846. void intel_panel_disable_backlight(struct intel_connector *connector);
  847. void intel_panel_destroy_backlight(struct drm_connector *connector);
  848. void intel_panel_init_backlight_funcs(struct drm_device *dev);
  849. enum drm_connector_status intel_panel_detect(struct drm_device *dev);
  850. extern struct drm_display_mode *intel_find_panel_downclock(
  851. struct drm_device *dev,
  852. struct drm_display_mode *fixed_mode,
  853. struct drm_connector *connector);
  854. /* intel_pm.c */
  855. void intel_init_clock_gating(struct drm_device *dev);
  856. void intel_suspend_hw(struct drm_device *dev);
  857. int ilk_wm_max_level(const struct drm_device *dev);
  858. void intel_update_watermarks(struct drm_crtc *crtc);
  859. void intel_update_sprite_watermarks(struct drm_plane *plane,
  860. struct drm_crtc *crtc,
  861. uint32_t sprite_width,
  862. uint32_t sprite_height,
  863. int pixel_size,
  864. bool enabled, bool scaled);
  865. void intel_init_pm(struct drm_device *dev);
  866. void intel_pm_setup(struct drm_device *dev);
  867. bool intel_fbc_enabled(struct drm_device *dev);
  868. void intel_update_fbc(struct drm_device *dev);
  869. void intel_gpu_ips_init(struct drm_i915_private *dev_priv);
  870. void intel_gpu_ips_teardown(void);
  871. int intel_power_domains_init(struct drm_i915_private *);
  872. void intel_power_domains_remove(struct drm_i915_private *);
  873. bool intel_display_power_enabled(struct drm_i915_private *dev_priv,
  874. enum intel_display_power_domain domain);
  875. bool intel_display_power_enabled_unlocked(struct drm_i915_private *dev_priv,
  876. enum intel_display_power_domain domain);
  877. void intel_display_power_get(struct drm_i915_private *dev_priv,
  878. enum intel_display_power_domain domain);
  879. void intel_display_power_put(struct drm_i915_private *dev_priv,
  880. enum intel_display_power_domain domain);
  881. void intel_power_domains_init_hw(struct drm_i915_private *dev_priv);
  882. void intel_init_gt_powersave(struct drm_device *dev);
  883. void intel_cleanup_gt_powersave(struct drm_device *dev);
  884. void intel_enable_gt_powersave(struct drm_device *dev);
  885. void intel_disable_gt_powersave(struct drm_device *dev);
  886. void intel_suspend_gt_powersave(struct drm_device *dev);
  887. void intel_reset_gt_powersave(struct drm_device *dev);
  888. void ironlake_teardown_rc6(struct drm_device *dev);
  889. void gen6_update_ring_freq(struct drm_device *dev);
  890. void gen6_rps_idle(struct drm_i915_private *dev_priv);
  891. void gen6_rps_boost(struct drm_i915_private *dev_priv);
  892. void intel_aux_display_runtime_get(struct drm_i915_private *dev_priv);
  893. void intel_aux_display_runtime_put(struct drm_i915_private *dev_priv);
  894. void intel_runtime_pm_get(struct drm_i915_private *dev_priv);
  895. void intel_runtime_pm_get_noresume(struct drm_i915_private *dev_priv);
  896. void intel_runtime_pm_put(struct drm_i915_private *dev_priv);
  897. void intel_init_runtime_pm(struct drm_i915_private *dev_priv);
  898. void intel_fini_runtime_pm(struct drm_i915_private *dev_priv);
  899. void ilk_wm_get_hw_state(struct drm_device *dev);
  900. /* intel_sdvo.c */
  901. bool intel_sdvo_init(struct drm_device *dev, uint32_t sdvo_reg, bool is_sdvob);
  902. /* intel_sprite.c */
  903. int intel_plane_init(struct drm_device *dev, enum pipe pipe, int plane);
  904. void intel_flush_primary_plane(struct drm_i915_private *dev_priv,
  905. enum plane plane);
  906. void intel_plane_restore(struct drm_plane *plane);
  907. void intel_plane_disable(struct drm_plane *plane);
  908. int intel_sprite_set_colorkey(struct drm_device *dev, void *data,
  909. struct drm_file *file_priv);
  910. int intel_sprite_get_colorkey(struct drm_device *dev, void *data,
  911. struct drm_file *file_priv);
  912. /* intel_tv.c */
  913. void intel_tv_init(struct drm_device *dev);
  914. #endif /* __INTEL_DRV_H__ */