intel_drv.h 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001
  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. /* Actual register state of the dpll, for shared dpll cross-checking. */
  269. struct intel_dpll_hw_state dpll_hw_state;
  270. int pipe_bpp;
  271. struct intel_link_m_n dp_m_n;
  272. /* m2_n2 for eDP downclock */
  273. struct intel_link_m_n dp_m2_n2;
  274. /*
  275. * Frequence the dpll for the port should run at. Differs from the
  276. * adjusted dotclock e.g. for DP or 12bpc hdmi mode. This is also
  277. * already multiplied by pixel_multiplier.
  278. */
  279. int port_clock;
  280. /* Used by SDVO (and if we ever fix it, HDMI). */
  281. unsigned pixel_multiplier;
  282. /* Panel fitter controls for gen2-gen4 + VLV */
  283. struct {
  284. u32 control;
  285. u32 pgm_ratios;
  286. u32 lvds_border_bits;
  287. } gmch_pfit;
  288. /* Panel fitter placement and size for Ironlake+ */
  289. struct {
  290. u32 pos;
  291. u32 size;
  292. bool enabled;
  293. } pch_pfit;
  294. /* FDI configuration, only valid if has_pch_encoder is set. */
  295. int fdi_lanes;
  296. struct intel_link_m_n fdi_m_n;
  297. bool ips_enabled;
  298. bool double_wide;
  299. };
  300. struct intel_pipe_wm {
  301. struct intel_wm_level wm[5];
  302. uint32_t linetime;
  303. bool fbc_wm_enabled;
  304. bool pipe_enabled;
  305. bool sprites_enabled;
  306. bool sprites_scaled;
  307. };
  308. struct intel_crtc {
  309. struct drm_crtc base;
  310. enum pipe pipe;
  311. enum plane plane;
  312. u8 lut_r[256], lut_g[256], lut_b[256];
  313. /*
  314. * Whether the crtc and the connected output pipeline is active. Implies
  315. * that crtc->enabled is set, i.e. the current mode configuration has
  316. * some outputs connected to this crtc.
  317. */
  318. bool active;
  319. unsigned long enabled_power_domains;
  320. bool primary_enabled; /* is the primary plane (partially) visible? */
  321. bool lowfreq_avail;
  322. struct intel_overlay *overlay;
  323. struct intel_unpin_work *unpin_work;
  324. atomic_t unpin_work_count;
  325. /* Display surface base address adjustement for pageflips. Note that on
  326. * gen4+ this only adjusts up to a tile, offsets within a tile are
  327. * handled in the hw itself (with the TILEOFF register). */
  328. unsigned long dspaddr_offset;
  329. struct drm_i915_gem_object *cursor_bo;
  330. uint32_t cursor_addr;
  331. int16_t cursor_x, cursor_y;
  332. int16_t cursor_width, cursor_height;
  333. uint32_t cursor_cntl;
  334. uint32_t cursor_base;
  335. struct intel_plane_config plane_config;
  336. struct intel_crtc_config config;
  337. struct intel_crtc_config *new_config;
  338. bool new_enabled;
  339. uint32_t ddi_pll_sel;
  340. /* reset counter value when the last flip was submitted */
  341. unsigned int reset_counter;
  342. /* Access to these should be protected by dev_priv->irq_lock. */
  343. bool cpu_fifo_underrun_disabled;
  344. bool pch_fifo_underrun_disabled;
  345. /* per-pipe watermark state */
  346. struct {
  347. /* watermarks currently being used */
  348. struct intel_pipe_wm active;
  349. } wm;
  350. wait_queue_head_t vbl_wait;
  351. int scanline_offset;
  352. };
  353. struct intel_plane_wm_parameters {
  354. uint32_t horiz_pixels;
  355. uint8_t bytes_per_pixel;
  356. bool enabled;
  357. bool scaled;
  358. };
  359. struct intel_plane {
  360. struct drm_plane base;
  361. int plane;
  362. enum pipe pipe;
  363. struct drm_i915_gem_object *obj;
  364. bool can_scale;
  365. int max_downscale;
  366. u32 lut_r[1024], lut_g[1024], lut_b[1024];
  367. int crtc_x, crtc_y;
  368. unsigned int crtc_w, crtc_h;
  369. uint32_t src_x, src_y;
  370. uint32_t src_w, src_h;
  371. /* Since we need to change the watermarks before/after
  372. * enabling/disabling the planes, we need to store the parameters here
  373. * as the other pieces of the struct may not reflect the values we want
  374. * for the watermark calculations. Currently only Haswell uses this.
  375. */
  376. struct intel_plane_wm_parameters wm;
  377. void (*update_plane)(struct drm_plane *plane,
  378. struct drm_crtc *crtc,
  379. struct drm_framebuffer *fb,
  380. struct drm_i915_gem_object *obj,
  381. int crtc_x, int crtc_y,
  382. unsigned int crtc_w, unsigned int crtc_h,
  383. uint32_t x, uint32_t y,
  384. uint32_t src_w, uint32_t src_h);
  385. void (*disable_plane)(struct drm_plane *plane,
  386. struct drm_crtc *crtc);
  387. int (*update_colorkey)(struct drm_plane *plane,
  388. struct drm_intel_sprite_colorkey *key);
  389. void (*get_colorkey)(struct drm_plane *plane,
  390. struct drm_intel_sprite_colorkey *key);
  391. };
  392. struct intel_watermark_params {
  393. unsigned long fifo_size;
  394. unsigned long max_wm;
  395. unsigned long default_wm;
  396. unsigned long guard_size;
  397. unsigned long cacheline_size;
  398. };
  399. struct cxsr_latency {
  400. int is_desktop;
  401. int is_ddr3;
  402. unsigned long fsb_freq;
  403. unsigned long mem_freq;
  404. unsigned long display_sr;
  405. unsigned long display_hpll_disable;
  406. unsigned long cursor_sr;
  407. unsigned long cursor_hpll_disable;
  408. };
  409. #define to_intel_crtc(x) container_of(x, struct intel_crtc, base)
  410. #define to_intel_connector(x) container_of(x, struct intel_connector, base)
  411. #define to_intel_encoder(x) container_of(x, struct intel_encoder, base)
  412. #define to_intel_framebuffer(x) container_of(x, struct intel_framebuffer, base)
  413. #define to_intel_plane(x) container_of(x, struct intel_plane, base)
  414. struct intel_hdmi {
  415. u32 hdmi_reg;
  416. int ddc_bus;
  417. uint32_t color_range;
  418. bool color_range_auto;
  419. bool has_hdmi_sink;
  420. bool has_audio;
  421. enum hdmi_force_audio force_audio;
  422. bool rgb_quant_range_selectable;
  423. void (*write_infoframe)(struct drm_encoder *encoder,
  424. enum hdmi_infoframe_type type,
  425. const void *frame, ssize_t len);
  426. void (*set_infoframes)(struct drm_encoder *encoder,
  427. bool enable,
  428. struct drm_display_mode *adjusted_mode);
  429. };
  430. #define DP_MAX_DOWNSTREAM_PORTS 0x10
  431. /**
  432. * HIGH_RR is the highest eDP panel refresh rate read from EDID
  433. * LOW_RR is the lowest eDP panel refresh rate found from EDID
  434. * parsing for same resolution.
  435. */
  436. enum edp_drrs_refresh_rate_type {
  437. DRRS_HIGH_RR,
  438. DRRS_LOW_RR,
  439. DRRS_MAX_RR, /* RR count */
  440. };
  441. struct intel_dp {
  442. uint32_t output_reg;
  443. uint32_t aux_ch_ctl_reg;
  444. uint32_t DP;
  445. bool has_audio;
  446. enum hdmi_force_audio force_audio;
  447. uint32_t color_range;
  448. bool color_range_auto;
  449. uint8_t link_bw;
  450. uint8_t lane_count;
  451. uint8_t dpcd[DP_RECEIVER_CAP_SIZE];
  452. uint8_t psr_dpcd[EDP_PSR_RECEIVER_CAP_SIZE];
  453. uint8_t downstream_ports[DP_MAX_DOWNSTREAM_PORTS];
  454. struct drm_dp_aux aux;
  455. uint8_t train_set[4];
  456. int panel_power_up_delay;
  457. int panel_power_down_delay;
  458. int panel_power_cycle_delay;
  459. int backlight_on_delay;
  460. int backlight_off_delay;
  461. struct delayed_work panel_vdd_work;
  462. bool want_panel_vdd;
  463. unsigned long last_power_cycle;
  464. unsigned long last_power_on;
  465. unsigned long last_backlight_off;
  466. bool psr_setup_done;
  467. struct notifier_block edp_notifier;
  468. bool use_tps3;
  469. struct intel_connector *attached_connector;
  470. uint32_t (*get_aux_clock_divider)(struct intel_dp *dp, int index);
  471. /*
  472. * This function returns the value we have to program the AUX_CTL
  473. * register with to kick off an AUX transaction.
  474. */
  475. uint32_t (*get_aux_send_ctl)(struct intel_dp *dp,
  476. bool has_aux_irq,
  477. int send_bytes,
  478. uint32_t aux_clock_divider);
  479. struct {
  480. enum drrs_support_type type;
  481. enum edp_drrs_refresh_rate_type refresh_rate_type;
  482. struct mutex mutex;
  483. } drrs_state;
  484. };
  485. struct intel_digital_port {
  486. struct intel_encoder base;
  487. enum port port;
  488. u32 saved_port_bits;
  489. struct intel_dp dp;
  490. struct intel_hdmi hdmi;
  491. };
  492. static inline int
  493. vlv_dport_to_channel(struct intel_digital_port *dport)
  494. {
  495. switch (dport->port) {
  496. case PORT_B:
  497. case PORT_D:
  498. return DPIO_CH0;
  499. case PORT_C:
  500. return DPIO_CH1;
  501. default:
  502. BUG();
  503. }
  504. }
  505. static inline int
  506. vlv_pipe_to_channel(enum pipe pipe)
  507. {
  508. switch (pipe) {
  509. case PIPE_A:
  510. case PIPE_C:
  511. return DPIO_CH0;
  512. case PIPE_B:
  513. return DPIO_CH1;
  514. default:
  515. BUG();
  516. }
  517. }
  518. static inline struct drm_crtc *
  519. intel_get_crtc_for_pipe(struct drm_device *dev, int pipe)
  520. {
  521. struct drm_i915_private *dev_priv = dev->dev_private;
  522. return dev_priv->pipe_to_crtc_mapping[pipe];
  523. }
  524. static inline struct drm_crtc *
  525. intel_get_crtc_for_plane(struct drm_device *dev, int plane)
  526. {
  527. struct drm_i915_private *dev_priv = dev->dev_private;
  528. return dev_priv->plane_to_crtc_mapping[plane];
  529. }
  530. struct intel_unpin_work {
  531. struct work_struct work;
  532. struct drm_crtc *crtc;
  533. struct drm_i915_gem_object *old_fb_obj;
  534. struct drm_i915_gem_object *pending_flip_obj;
  535. struct drm_pending_vblank_event *event;
  536. atomic_t pending;
  537. #define INTEL_FLIP_INACTIVE 0
  538. #define INTEL_FLIP_PENDING 1
  539. #define INTEL_FLIP_COMPLETE 2
  540. u32 flip_count;
  541. u32 gtt_offset;
  542. bool enable_stall_check;
  543. };
  544. struct intel_set_config {
  545. struct drm_encoder **save_connector_encoders;
  546. struct drm_crtc **save_encoder_crtcs;
  547. bool *save_crtc_enabled;
  548. bool fb_changed;
  549. bool mode_changed;
  550. };
  551. struct intel_load_detect_pipe {
  552. struct drm_framebuffer *release_fb;
  553. bool load_detect_temp;
  554. int dpms_mode;
  555. };
  556. static inline struct intel_encoder *
  557. intel_attached_encoder(struct drm_connector *connector)
  558. {
  559. return to_intel_connector(connector)->encoder;
  560. }
  561. static inline struct intel_digital_port *
  562. enc_to_dig_port(struct drm_encoder *encoder)
  563. {
  564. return container_of(encoder, struct intel_digital_port, base.base);
  565. }
  566. static inline struct intel_dp *enc_to_intel_dp(struct drm_encoder *encoder)
  567. {
  568. return &enc_to_dig_port(encoder)->dp;
  569. }
  570. static inline struct intel_digital_port *
  571. dp_to_dig_port(struct intel_dp *intel_dp)
  572. {
  573. return container_of(intel_dp, struct intel_digital_port, dp);
  574. }
  575. static inline struct intel_digital_port *
  576. hdmi_to_dig_port(struct intel_hdmi *intel_hdmi)
  577. {
  578. return container_of(intel_hdmi, struct intel_digital_port, hdmi);
  579. }
  580. /* i915_irq.c */
  581. bool intel_set_cpu_fifo_underrun_reporting(struct drm_device *dev,
  582. enum pipe pipe, bool enable);
  583. bool intel_set_pch_fifo_underrun_reporting(struct drm_device *dev,
  584. enum transcoder pch_transcoder,
  585. bool enable);
  586. void ilk_enable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask);
  587. void ilk_disable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask);
  588. void snb_enable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask);
  589. void snb_disable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask);
  590. void bdw_enable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask);
  591. void bdw_disable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask);
  592. void intel_runtime_pm_disable_interrupts(struct drm_device *dev);
  593. void intel_runtime_pm_restore_interrupts(struct drm_device *dev);
  594. int intel_get_crtc_scanline(struct intel_crtc *crtc);
  595. void i9xx_check_fifo_underruns(struct drm_device *dev);
  596. /* intel_crt.c */
  597. void intel_crt_init(struct drm_device *dev);
  598. /* intel_ddi.c */
  599. void intel_prepare_ddi(struct drm_device *dev);
  600. void hsw_fdi_link_train(struct drm_crtc *crtc);
  601. void intel_ddi_init(struct drm_device *dev, enum port port);
  602. enum port intel_ddi_get_encoder_port(struct intel_encoder *intel_encoder);
  603. bool intel_ddi_get_hw_state(struct intel_encoder *encoder, enum pipe *pipe);
  604. int intel_ddi_get_cdclk_freq(struct drm_i915_private *dev_priv);
  605. void intel_ddi_pll_init(struct drm_device *dev);
  606. void intel_ddi_enable_transcoder_func(struct drm_crtc *crtc);
  607. void intel_ddi_disable_transcoder_func(struct drm_i915_private *dev_priv,
  608. enum transcoder cpu_transcoder);
  609. void intel_ddi_enable_pipe_clock(struct intel_crtc *intel_crtc);
  610. void intel_ddi_disable_pipe_clock(struct intel_crtc *intel_crtc);
  611. void intel_ddi_setup_hw_pll_state(struct drm_device *dev);
  612. bool intel_ddi_pll_select(struct intel_crtc *crtc);
  613. void intel_ddi_pll_enable(struct intel_crtc *crtc);
  614. void intel_ddi_put_crtc_pll(struct drm_crtc *crtc);
  615. void intel_ddi_set_pipe_settings(struct drm_crtc *crtc);
  616. void intel_ddi_prepare_link_retrain(struct drm_encoder *encoder);
  617. bool intel_ddi_connector_get_hw_state(struct intel_connector *intel_connector);
  618. void intel_ddi_fdi_disable(struct drm_crtc *crtc);
  619. void intel_ddi_get_config(struct intel_encoder *encoder,
  620. struct intel_crtc_config *pipe_config);
  621. /* intel_display.c */
  622. const char *intel_output_name(int output);
  623. bool intel_has_pending_fb_unpin(struct drm_device *dev);
  624. int intel_pch_rawclk(struct drm_device *dev);
  625. int valleyview_cur_cdclk(struct drm_i915_private *dev_priv);
  626. void intel_mark_busy(struct drm_device *dev);
  627. void intel_mark_fb_busy(struct drm_i915_gem_object *obj,
  628. struct intel_engine_cs *ring);
  629. void intel_mark_idle(struct drm_device *dev);
  630. void intel_crtc_restore_mode(struct drm_crtc *crtc);
  631. void intel_crtc_update_dpms(struct drm_crtc *crtc);
  632. void intel_encoder_destroy(struct drm_encoder *encoder);
  633. void intel_connector_dpms(struct drm_connector *, int mode);
  634. bool intel_connector_get_hw_state(struct intel_connector *connector);
  635. void intel_modeset_check_state(struct drm_device *dev);
  636. bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
  637. struct intel_digital_port *port);
  638. void intel_connector_attach_encoder(struct intel_connector *connector,
  639. struct intel_encoder *encoder);
  640. struct drm_encoder *intel_best_encoder(struct drm_connector *connector);
  641. struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev,
  642. struct drm_crtc *crtc);
  643. enum pipe intel_get_pipe_from_connector(struct intel_connector *connector);
  644. int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data,
  645. struct drm_file *file_priv);
  646. enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv,
  647. enum pipe pipe);
  648. void intel_wait_for_vblank(struct drm_device *dev, int pipe);
  649. void intel_wait_for_pipe_off(struct drm_device *dev, int pipe);
  650. int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp);
  651. void vlv_wait_port_ready(struct drm_i915_private *dev_priv,
  652. struct intel_digital_port *dport);
  653. bool intel_get_load_detect_pipe(struct drm_connector *connector,
  654. struct drm_display_mode *mode,
  655. struct intel_load_detect_pipe *old,
  656. struct drm_modeset_acquire_ctx *ctx);
  657. void intel_release_load_detect_pipe(struct drm_connector *connector,
  658. struct intel_load_detect_pipe *old,
  659. struct drm_modeset_acquire_ctx *ctx);
  660. int intel_pin_and_fence_fb_obj(struct drm_device *dev,
  661. struct drm_i915_gem_object *obj,
  662. struct intel_engine_cs *pipelined);
  663. void intel_unpin_fb_obj(struct drm_i915_gem_object *obj);
  664. struct drm_framebuffer *
  665. __intel_framebuffer_create(struct drm_device *dev,
  666. struct drm_mode_fb_cmd2 *mode_cmd,
  667. struct drm_i915_gem_object *obj);
  668. void intel_prepare_page_flip(struct drm_device *dev, int plane);
  669. void intel_finish_page_flip(struct drm_device *dev, int pipe);
  670. void intel_finish_page_flip_plane(struct drm_device *dev, int plane);
  671. struct intel_shared_dpll *intel_crtc_to_shared_dpll(struct intel_crtc *crtc);
  672. void assert_shared_dpll(struct drm_i915_private *dev_priv,
  673. struct intel_shared_dpll *pll,
  674. bool state);
  675. #define assert_shared_dpll_enabled(d, p) assert_shared_dpll(d, p, true)
  676. #define assert_shared_dpll_disabled(d, p) assert_shared_dpll(d, p, false)
  677. void assert_pll(struct drm_i915_private *dev_priv,
  678. enum pipe pipe, bool state);
  679. #define assert_pll_enabled(d, p) assert_pll(d, p, true)
  680. #define assert_pll_disabled(d, p) assert_pll(d, p, false)
  681. void assert_fdi_rx_pll(struct drm_i915_private *dev_priv,
  682. enum pipe pipe, bool state);
  683. #define assert_fdi_rx_pll_enabled(d, p) assert_fdi_rx_pll(d, p, true)
  684. #define assert_fdi_rx_pll_disabled(d, p) assert_fdi_rx_pll(d, p, false)
  685. void assert_pipe(struct drm_i915_private *dev_priv, enum pipe pipe, bool state);
  686. #define assert_pipe_enabled(d, p) assert_pipe(d, p, true)
  687. #define assert_pipe_disabled(d, p) assert_pipe(d, p, false)
  688. void intel_write_eld(struct drm_encoder *encoder,
  689. struct drm_display_mode *mode);
  690. unsigned long intel_gen4_compute_page_offset(int *x, int *y,
  691. unsigned int tiling_mode,
  692. unsigned int bpp,
  693. unsigned int pitch);
  694. void intel_display_handle_reset(struct drm_device *dev);
  695. void hsw_enable_pc8(struct drm_i915_private *dev_priv);
  696. void hsw_disable_pc8(struct drm_i915_private *dev_priv);
  697. void intel_dp_get_m_n(struct intel_crtc *crtc,
  698. struct intel_crtc_config *pipe_config);
  699. int intel_dotclock_calculate(int link_freq, const struct intel_link_m_n *m_n);
  700. void
  701. ironlake_check_encoder_dotclock(const struct intel_crtc_config *pipe_config,
  702. int dotclock);
  703. bool intel_crtc_active(struct drm_crtc *crtc);
  704. void hsw_enable_ips(struct intel_crtc *crtc);
  705. void hsw_disable_ips(struct intel_crtc *crtc);
  706. void intel_display_set_init_power(struct drm_i915_private *dev, bool enable);
  707. enum intel_display_power_domain
  708. intel_display_port_power_domain(struct intel_encoder *intel_encoder);
  709. int valleyview_get_vco(struct drm_i915_private *dev_priv);
  710. void intel_mode_from_pipe_config(struct drm_display_mode *mode,
  711. struct intel_crtc_config *pipe_config);
  712. int intel_format_to_fourcc(int format);
  713. void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc);
  714. /* intel_dp.c */
  715. void intel_dp_init(struct drm_device *dev, int output_reg, enum port port);
  716. bool intel_dp_init_connector(struct intel_digital_port *intel_dig_port,
  717. struct intel_connector *intel_connector);
  718. void intel_dp_start_link_train(struct intel_dp *intel_dp);
  719. void intel_dp_complete_link_train(struct intel_dp *intel_dp);
  720. void intel_dp_stop_link_train(struct intel_dp *intel_dp);
  721. void intel_dp_sink_dpms(struct intel_dp *intel_dp, int mode);
  722. void intel_dp_encoder_destroy(struct drm_encoder *encoder);
  723. void intel_dp_check_link_status(struct intel_dp *intel_dp);
  724. int intel_dp_sink_crc(struct intel_dp *intel_dp, u8 *crc);
  725. bool intel_dp_compute_config(struct intel_encoder *encoder,
  726. struct intel_crtc_config *pipe_config);
  727. bool intel_dp_is_edp(struct drm_device *dev, enum port port);
  728. void intel_edp_backlight_on(struct intel_dp *intel_dp);
  729. void intel_edp_backlight_off(struct intel_dp *intel_dp);
  730. void intel_edp_panel_vdd_on(struct intel_dp *intel_dp);
  731. void intel_edp_panel_on(struct intel_dp *intel_dp);
  732. void intel_edp_panel_off(struct intel_dp *intel_dp);
  733. void intel_edp_psr_enable(struct intel_dp *intel_dp);
  734. void intel_edp_psr_disable(struct intel_dp *intel_dp);
  735. void intel_edp_psr_update(struct drm_device *dev);
  736. void intel_dp_set_drrs_state(struct drm_device *dev, int refresh_rate);
  737. /* intel_dsi.c */
  738. bool intel_dsi_init(struct drm_device *dev);
  739. /* intel_dvo.c */
  740. void intel_dvo_init(struct drm_device *dev);
  741. /* legacy fbdev emulation in intel_fbdev.c */
  742. #ifdef CONFIG_DRM_I915_FBDEV
  743. extern int intel_fbdev_init(struct drm_device *dev);
  744. extern void intel_fbdev_initial_config(struct drm_device *dev);
  745. extern void intel_fbdev_fini(struct drm_device *dev);
  746. extern void intel_fbdev_set_suspend(struct drm_device *dev, int state);
  747. extern void intel_fbdev_output_poll_changed(struct drm_device *dev);
  748. extern void intel_fbdev_restore_mode(struct drm_device *dev);
  749. #else
  750. static inline int intel_fbdev_init(struct drm_device *dev)
  751. {
  752. return 0;
  753. }
  754. static inline void intel_fbdev_initial_config(struct drm_device *dev)
  755. {
  756. }
  757. static inline void intel_fbdev_fini(struct drm_device *dev)
  758. {
  759. }
  760. static inline void intel_fbdev_set_suspend(struct drm_device *dev, int state)
  761. {
  762. }
  763. static inline void intel_fbdev_restore_mode(struct drm_device *dev)
  764. {
  765. }
  766. #endif
  767. /* intel_hdmi.c */
  768. void intel_hdmi_init(struct drm_device *dev, int hdmi_reg, enum port port);
  769. void intel_hdmi_init_connector(struct intel_digital_port *intel_dig_port,
  770. struct intel_connector *intel_connector);
  771. struct intel_hdmi *enc_to_intel_hdmi(struct drm_encoder *encoder);
  772. bool intel_hdmi_compute_config(struct intel_encoder *encoder,
  773. struct intel_crtc_config *pipe_config);
  774. /* intel_lvds.c */
  775. void intel_lvds_init(struct drm_device *dev);
  776. bool intel_is_dual_link_lvds(struct drm_device *dev);
  777. /* intel_modes.c */
  778. int intel_connector_update_modes(struct drm_connector *connector,
  779. struct edid *edid);
  780. int intel_ddc_get_modes(struct drm_connector *c, struct i2c_adapter *adapter);
  781. void intel_attach_force_audio_property(struct drm_connector *connector);
  782. void intel_attach_broadcast_rgb_property(struct drm_connector *connector);
  783. /* intel_overlay.c */
  784. void intel_setup_overlay(struct drm_device *dev);
  785. void intel_cleanup_overlay(struct drm_device *dev);
  786. int intel_overlay_switch_off(struct intel_overlay *overlay);
  787. int intel_overlay_put_image(struct drm_device *dev, void *data,
  788. struct drm_file *file_priv);
  789. int intel_overlay_attrs(struct drm_device *dev, void *data,
  790. struct drm_file *file_priv);
  791. /* intel_panel.c */
  792. int intel_panel_init(struct intel_panel *panel,
  793. struct drm_display_mode *fixed_mode,
  794. struct drm_display_mode *downclock_mode);
  795. void intel_panel_fini(struct intel_panel *panel);
  796. void intel_fixed_panel_mode(const struct drm_display_mode *fixed_mode,
  797. struct drm_display_mode *adjusted_mode);
  798. void intel_pch_panel_fitting(struct intel_crtc *crtc,
  799. struct intel_crtc_config *pipe_config,
  800. int fitting_mode);
  801. void intel_gmch_panel_fitting(struct intel_crtc *crtc,
  802. struct intel_crtc_config *pipe_config,
  803. int fitting_mode);
  804. void intel_panel_set_backlight(struct intel_connector *connector, u32 level,
  805. u32 max);
  806. int intel_panel_setup_backlight(struct drm_connector *connector);
  807. void intel_panel_enable_backlight(struct intel_connector *connector);
  808. void intel_panel_disable_backlight(struct intel_connector *connector);
  809. void intel_panel_destroy_backlight(struct drm_connector *connector);
  810. void intel_panel_init_backlight_funcs(struct drm_device *dev);
  811. enum drm_connector_status intel_panel_detect(struct drm_device *dev);
  812. extern struct drm_display_mode *intel_find_panel_downclock(
  813. struct drm_device *dev,
  814. struct drm_display_mode *fixed_mode,
  815. struct drm_connector *connector);
  816. /* intel_pm.c */
  817. void intel_init_clock_gating(struct drm_device *dev);
  818. void intel_suspend_hw(struct drm_device *dev);
  819. int ilk_wm_max_level(const struct drm_device *dev);
  820. void intel_update_watermarks(struct drm_crtc *crtc);
  821. void intel_update_sprite_watermarks(struct drm_plane *plane,
  822. struct drm_crtc *crtc,
  823. uint32_t sprite_width, int pixel_size,
  824. bool enabled, bool scaled);
  825. void intel_init_pm(struct drm_device *dev);
  826. void intel_pm_setup(struct drm_device *dev);
  827. bool intel_fbc_enabled(struct drm_device *dev);
  828. void intel_update_fbc(struct drm_device *dev);
  829. void intel_gpu_ips_init(struct drm_i915_private *dev_priv);
  830. void intel_gpu_ips_teardown(void);
  831. int intel_power_domains_init(struct drm_i915_private *);
  832. void intel_power_domains_remove(struct drm_i915_private *);
  833. bool intel_display_power_enabled(struct drm_i915_private *dev_priv,
  834. enum intel_display_power_domain domain);
  835. bool intel_display_power_enabled_unlocked(struct drm_i915_private *dev_priv,
  836. enum intel_display_power_domain domain);
  837. void intel_display_power_get(struct drm_i915_private *dev_priv,
  838. enum intel_display_power_domain domain);
  839. void intel_display_power_put(struct drm_i915_private *dev_priv,
  840. enum intel_display_power_domain domain);
  841. void intel_power_domains_init_hw(struct drm_i915_private *dev_priv);
  842. void intel_init_gt_powersave(struct drm_device *dev);
  843. void intel_cleanup_gt_powersave(struct drm_device *dev);
  844. void intel_enable_gt_powersave(struct drm_device *dev);
  845. void intel_disable_gt_powersave(struct drm_device *dev);
  846. void intel_reset_gt_powersave(struct drm_device *dev);
  847. void ironlake_teardown_rc6(struct drm_device *dev);
  848. void gen6_update_ring_freq(struct drm_device *dev);
  849. void gen6_rps_idle(struct drm_i915_private *dev_priv);
  850. void gen6_rps_boost(struct drm_i915_private *dev_priv);
  851. void intel_aux_display_runtime_get(struct drm_i915_private *dev_priv);
  852. void intel_aux_display_runtime_put(struct drm_i915_private *dev_priv);
  853. void intel_runtime_pm_get(struct drm_i915_private *dev_priv);
  854. void intel_runtime_pm_get_noresume(struct drm_i915_private *dev_priv);
  855. void intel_runtime_pm_put(struct drm_i915_private *dev_priv);
  856. void intel_init_runtime_pm(struct drm_i915_private *dev_priv);
  857. void intel_fini_runtime_pm(struct drm_i915_private *dev_priv);
  858. void ilk_wm_get_hw_state(struct drm_device *dev);
  859. void __vlv_set_power_well(struct drm_i915_private *dev_priv,
  860. enum punit_power_well power_well_id, bool enable);
  861. /* intel_sdvo.c */
  862. bool intel_sdvo_init(struct drm_device *dev, uint32_t sdvo_reg, bool is_sdvob);
  863. /* intel_sprite.c */
  864. int intel_plane_init(struct drm_device *dev, enum pipe pipe, int plane);
  865. void intel_flush_primary_plane(struct drm_i915_private *dev_priv,
  866. enum plane plane);
  867. void intel_plane_restore(struct drm_plane *plane);
  868. void intel_plane_disable(struct drm_plane *plane);
  869. int intel_sprite_set_colorkey(struct drm_device *dev, void *data,
  870. struct drm_file *file_priv);
  871. int intel_sprite_get_colorkey(struct drm_device *dev, void *data,
  872. struct drm_file *file_priv);
  873. /* intel_tv.c */
  874. void intel_tv_init(struct drm_device *dev);
  875. #endif /* __INTEL_DRV_H__ */