intel_display.c 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667
  1. /*
  2. * Copyright © 2006-2007 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  21. * DEALINGS IN THE SOFTWARE.
  22. *
  23. * Authors:
  24. * Eric Anholt <eric@anholt.net>
  25. */
  26. #include <linux/i2c.h>
  27. #include "drmP.h"
  28. #include "intel_drv.h"
  29. #include "i915_drm.h"
  30. #include "i915_drv.h"
  31. #include "drm_crtc_helper.h"
  32. bool intel_pipe_has_type (struct drm_crtc *crtc, int type);
  33. typedef struct {
  34. /* given values */
  35. int n;
  36. int m1, m2;
  37. int p1, p2;
  38. /* derived values */
  39. int dot;
  40. int vco;
  41. int m;
  42. int p;
  43. } intel_clock_t;
  44. typedef struct {
  45. int min, max;
  46. } intel_range_t;
  47. typedef struct {
  48. int dot_limit;
  49. int p2_slow, p2_fast;
  50. } intel_p2_t;
  51. #define INTEL_P2_NUM 2
  52. typedef struct {
  53. intel_range_t dot, vco, n, m, m1, m2, p, p1;
  54. intel_p2_t p2;
  55. } intel_limit_t;
  56. #define I8XX_DOT_MIN 25000
  57. #define I8XX_DOT_MAX 350000
  58. #define I8XX_VCO_MIN 930000
  59. #define I8XX_VCO_MAX 1400000
  60. #define I8XX_N_MIN 3
  61. #define I8XX_N_MAX 16
  62. #define I8XX_M_MIN 96
  63. #define I8XX_M_MAX 140
  64. #define I8XX_M1_MIN 18
  65. #define I8XX_M1_MAX 26
  66. #define I8XX_M2_MIN 6
  67. #define I8XX_M2_MAX 16
  68. #define I8XX_P_MIN 4
  69. #define I8XX_P_MAX 128
  70. #define I8XX_P1_MIN 2
  71. #define I8XX_P1_MAX 33
  72. #define I8XX_P1_LVDS_MIN 1
  73. #define I8XX_P1_LVDS_MAX 6
  74. #define I8XX_P2_SLOW 4
  75. #define I8XX_P2_FAST 2
  76. #define I8XX_P2_LVDS_SLOW 14
  77. #define I8XX_P2_LVDS_FAST 14 /* No fast option */
  78. #define I8XX_P2_SLOW_LIMIT 165000
  79. #define I9XX_DOT_MIN 20000
  80. #define I9XX_DOT_MAX 400000
  81. #define I9XX_VCO_MIN 1400000
  82. #define I9XX_VCO_MAX 2800000
  83. #define I9XX_N_MIN 3
  84. #define I9XX_N_MAX 8
  85. #define I9XX_M_MIN 70
  86. #define I9XX_M_MAX 120
  87. #define I9XX_M1_MIN 10
  88. #define I9XX_M1_MAX 20
  89. #define I9XX_M2_MIN 5
  90. #define I9XX_M2_MAX 9
  91. #define I9XX_P_SDVO_DAC_MIN 5
  92. #define I9XX_P_SDVO_DAC_MAX 80
  93. #define I9XX_P_LVDS_MIN 7
  94. #define I9XX_P_LVDS_MAX 98
  95. #define I9XX_P1_MIN 1
  96. #define I9XX_P1_MAX 8
  97. #define I9XX_P2_SDVO_DAC_SLOW 10
  98. #define I9XX_P2_SDVO_DAC_FAST 5
  99. #define I9XX_P2_SDVO_DAC_SLOW_LIMIT 200000
  100. #define I9XX_P2_LVDS_SLOW 14
  101. #define I9XX_P2_LVDS_FAST 7
  102. #define I9XX_P2_LVDS_SLOW_LIMIT 112000
  103. #define INTEL_LIMIT_I8XX_DVO_DAC 0
  104. #define INTEL_LIMIT_I8XX_LVDS 1
  105. #define INTEL_LIMIT_I9XX_SDVO_DAC 2
  106. #define INTEL_LIMIT_I9XX_LVDS 3
  107. static const intel_limit_t intel_limits[] = {
  108. { /* INTEL_LIMIT_I8XX_DVO_DAC */
  109. .dot = { .min = I8XX_DOT_MIN, .max = I8XX_DOT_MAX },
  110. .vco = { .min = I8XX_VCO_MIN, .max = I8XX_VCO_MAX },
  111. .n = { .min = I8XX_N_MIN, .max = I8XX_N_MAX },
  112. .m = { .min = I8XX_M_MIN, .max = I8XX_M_MAX },
  113. .m1 = { .min = I8XX_M1_MIN, .max = I8XX_M1_MAX },
  114. .m2 = { .min = I8XX_M2_MIN, .max = I8XX_M2_MAX },
  115. .p = { .min = I8XX_P_MIN, .max = I8XX_P_MAX },
  116. .p1 = { .min = I8XX_P1_MIN, .max = I8XX_P1_MAX },
  117. .p2 = { .dot_limit = I8XX_P2_SLOW_LIMIT,
  118. .p2_slow = I8XX_P2_SLOW, .p2_fast = I8XX_P2_FAST },
  119. },
  120. { /* INTEL_LIMIT_I8XX_LVDS */
  121. .dot = { .min = I8XX_DOT_MIN, .max = I8XX_DOT_MAX },
  122. .vco = { .min = I8XX_VCO_MIN, .max = I8XX_VCO_MAX },
  123. .n = { .min = I8XX_N_MIN, .max = I8XX_N_MAX },
  124. .m = { .min = I8XX_M_MIN, .max = I8XX_M_MAX },
  125. .m1 = { .min = I8XX_M1_MIN, .max = I8XX_M1_MAX },
  126. .m2 = { .min = I8XX_M2_MIN, .max = I8XX_M2_MAX },
  127. .p = { .min = I8XX_P_MIN, .max = I8XX_P_MAX },
  128. .p1 = { .min = I8XX_P1_LVDS_MIN, .max = I8XX_P1_LVDS_MAX },
  129. .p2 = { .dot_limit = I8XX_P2_SLOW_LIMIT,
  130. .p2_slow = I8XX_P2_LVDS_SLOW, .p2_fast = I8XX_P2_LVDS_FAST },
  131. },
  132. { /* INTEL_LIMIT_I9XX_SDVO_DAC */
  133. .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX },
  134. .vco = { .min = I9XX_VCO_MIN, .max = I9XX_VCO_MAX },
  135. .n = { .min = I9XX_N_MIN, .max = I9XX_N_MAX },
  136. .m = { .min = I9XX_M_MIN, .max = I9XX_M_MAX },
  137. .m1 = { .min = I9XX_M1_MIN, .max = I9XX_M1_MAX },
  138. .m2 = { .min = I9XX_M2_MIN, .max = I9XX_M2_MAX },
  139. .p = { .min = I9XX_P_SDVO_DAC_MIN, .max = I9XX_P_SDVO_DAC_MAX },
  140. .p1 = { .min = I9XX_P1_MIN, .max = I9XX_P1_MAX },
  141. .p2 = { .dot_limit = I9XX_P2_SDVO_DAC_SLOW_LIMIT,
  142. .p2_slow = I9XX_P2_SDVO_DAC_SLOW, .p2_fast = I9XX_P2_SDVO_DAC_FAST },
  143. },
  144. { /* INTEL_LIMIT_I9XX_LVDS */
  145. .dot = { .min = I9XX_DOT_MIN, .max = I9XX_DOT_MAX },
  146. .vco = { .min = I9XX_VCO_MIN, .max = I9XX_VCO_MAX },
  147. .n = { .min = I9XX_N_MIN, .max = I9XX_N_MAX },
  148. .m = { .min = I9XX_M_MIN, .max = I9XX_M_MAX },
  149. .m1 = { .min = I9XX_M1_MIN, .max = I9XX_M1_MAX },
  150. .m2 = { .min = I9XX_M2_MIN, .max = I9XX_M2_MAX },
  151. .p = { .min = I9XX_P_LVDS_MIN, .max = I9XX_P_LVDS_MAX },
  152. .p1 = { .min = I9XX_P1_MIN, .max = I9XX_P1_MAX },
  153. /* The single-channel range is 25-112Mhz, and dual-channel
  154. * is 80-224Mhz. Prefer single channel as much as possible.
  155. */
  156. .p2 = { .dot_limit = I9XX_P2_LVDS_SLOW_LIMIT,
  157. .p2_slow = I9XX_P2_LVDS_SLOW, .p2_fast = I9XX_P2_LVDS_FAST },
  158. },
  159. };
  160. static const intel_limit_t *intel_limit(struct drm_crtc *crtc)
  161. {
  162. struct drm_device *dev = crtc->dev;
  163. const intel_limit_t *limit;
  164. if (IS_I9XX(dev)) {
  165. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  166. limit = &intel_limits[INTEL_LIMIT_I9XX_LVDS];
  167. else
  168. limit = &intel_limits[INTEL_LIMIT_I9XX_SDVO_DAC];
  169. } else {
  170. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  171. limit = &intel_limits[INTEL_LIMIT_I8XX_LVDS];
  172. else
  173. limit = &intel_limits[INTEL_LIMIT_I8XX_DVO_DAC];
  174. }
  175. return limit;
  176. }
  177. /** Derive the pixel clock for the given refclk and divisors for 8xx chips. */
  178. static void i8xx_clock(int refclk, intel_clock_t *clock)
  179. {
  180. clock->m = 5 * (clock->m1 + 2) + (clock->m2 + 2);
  181. clock->p = clock->p1 * clock->p2;
  182. clock->vco = refclk * clock->m / (clock->n + 2);
  183. clock->dot = clock->vco / clock->p;
  184. }
  185. /** Derive the pixel clock for the given refclk and divisors for 9xx chips. */
  186. static void i9xx_clock(int refclk, intel_clock_t *clock)
  187. {
  188. clock->m = 5 * (clock->m1 + 2) + (clock->m2 + 2);
  189. clock->p = clock->p1 * clock->p2;
  190. clock->vco = refclk * clock->m / (clock->n + 2);
  191. clock->dot = clock->vco / clock->p;
  192. }
  193. static void intel_clock(struct drm_device *dev, int refclk,
  194. intel_clock_t *clock)
  195. {
  196. if (IS_I9XX(dev))
  197. i9xx_clock (refclk, clock);
  198. else
  199. i8xx_clock (refclk, clock);
  200. }
  201. /**
  202. * Returns whether any output on the specified pipe is of the specified type
  203. */
  204. bool intel_pipe_has_type (struct drm_crtc *crtc, int type)
  205. {
  206. struct drm_device *dev = crtc->dev;
  207. struct drm_mode_config *mode_config = &dev->mode_config;
  208. struct drm_connector *l_entry;
  209. list_for_each_entry(l_entry, &mode_config->connector_list, head) {
  210. if (l_entry->encoder &&
  211. l_entry->encoder->crtc == crtc) {
  212. struct intel_output *intel_output = to_intel_output(l_entry);
  213. if (intel_output->type == type)
  214. return true;
  215. }
  216. }
  217. return false;
  218. }
  219. #define INTELPllInvalid(s) { /* ErrorF (s) */; return false; }
  220. /**
  221. * Returns whether the given set of divisors are valid for a given refclk with
  222. * the given connectors.
  223. */
  224. static bool intel_PLL_is_valid(struct drm_crtc *crtc, intel_clock_t *clock)
  225. {
  226. const intel_limit_t *limit = intel_limit (crtc);
  227. if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
  228. INTELPllInvalid ("p1 out of range\n");
  229. if (clock->p < limit->p.min || limit->p.max < clock->p)
  230. INTELPllInvalid ("p out of range\n");
  231. if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2)
  232. INTELPllInvalid ("m2 out of range\n");
  233. if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1)
  234. INTELPllInvalid ("m1 out of range\n");
  235. if (clock->m1 <= clock->m2)
  236. INTELPllInvalid ("m1 <= m2\n");
  237. if (clock->m < limit->m.min || limit->m.max < clock->m)
  238. INTELPllInvalid ("m out of range\n");
  239. if (clock->n < limit->n.min || limit->n.max < clock->n)
  240. INTELPllInvalid ("n out of range\n");
  241. if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
  242. INTELPllInvalid ("vco out of range\n");
  243. /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
  244. * connector, etc., rather than just a single range.
  245. */
  246. if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
  247. INTELPllInvalid ("dot out of range\n");
  248. return true;
  249. }
  250. /**
  251. * Returns a set of divisors for the desired target clock with the given
  252. * refclk, or FALSE. The returned values represent the clock equation:
  253. * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
  254. */
  255. static bool intel_find_best_PLL(struct drm_crtc *crtc, int target,
  256. int refclk, intel_clock_t *best_clock)
  257. {
  258. struct drm_device *dev = crtc->dev;
  259. struct drm_i915_private *dev_priv = dev->dev_private;
  260. intel_clock_t clock;
  261. const intel_limit_t *limit = intel_limit(crtc);
  262. int err = target;
  263. if (IS_I9XX(dev) && intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
  264. (I915_READ(LVDS) & LVDS_PORT_EN) != 0) {
  265. /*
  266. * For LVDS, if the panel is on, just rely on its current
  267. * settings for dual-channel. We haven't figured out how to
  268. * reliably set up different single/dual channel state, if we
  269. * even can.
  270. */
  271. if ((I915_READ(LVDS) & LVDS_CLKB_POWER_MASK) ==
  272. LVDS_CLKB_POWER_UP)
  273. clock.p2 = limit->p2.p2_fast;
  274. else
  275. clock.p2 = limit->p2.p2_slow;
  276. } else {
  277. if (target < limit->p2.dot_limit)
  278. clock.p2 = limit->p2.p2_slow;
  279. else
  280. clock.p2 = limit->p2.p2_fast;
  281. }
  282. memset (best_clock, 0, sizeof (*best_clock));
  283. for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) {
  284. for (clock.m2 = limit->m2.min; clock.m2 < clock.m1 &&
  285. clock.m2 <= limit->m2.max; clock.m2++) {
  286. for (clock.n = limit->n.min; clock.n <= limit->n.max;
  287. clock.n++) {
  288. for (clock.p1 = limit->p1.min;
  289. clock.p1 <= limit->p1.max; clock.p1++) {
  290. int this_err;
  291. intel_clock(dev, refclk, &clock);
  292. if (!intel_PLL_is_valid(crtc, &clock))
  293. continue;
  294. this_err = abs(clock.dot - target);
  295. if (this_err < err) {
  296. *best_clock = clock;
  297. err = this_err;
  298. }
  299. }
  300. }
  301. }
  302. }
  303. return (err != target);
  304. }
  305. void
  306. intel_wait_for_vblank(struct drm_device *dev)
  307. {
  308. /* Wait for 20ms, i.e. one cycle at 50hz. */
  309. udelay(20000);
  310. }
  311. static void
  312. intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
  313. struct drm_framebuffer *old_fb)
  314. {
  315. struct drm_device *dev = crtc->dev;
  316. struct drm_i915_private *dev_priv = dev->dev_private;
  317. struct drm_i915_master_private *master_priv;
  318. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  319. struct intel_framebuffer *intel_fb;
  320. struct drm_i915_gem_object *obj_priv;
  321. struct drm_gem_object *obj;
  322. int pipe = intel_crtc->pipe;
  323. unsigned long Start, Offset;
  324. int dspbase = (pipe == 0 ? DSPAADDR : DSPBADDR);
  325. int dspsurf = (pipe == 0 ? DSPASURF : DSPBSURF);
  326. int dspstride = (pipe == 0) ? DSPASTRIDE : DSPBSTRIDE;
  327. int dspcntr_reg = (pipe == 0) ? DSPACNTR : DSPBCNTR;
  328. u32 dspcntr, alignment;
  329. /* no fb bound */
  330. if (!crtc->fb) {
  331. DRM_DEBUG("No FB bound\n");
  332. return;
  333. }
  334. intel_fb = to_intel_framebuffer(crtc->fb);
  335. obj = intel_fb->obj;
  336. obj_priv = obj->driver_private;
  337. switch (obj_priv->tiling_mode) {
  338. case I915_TILING_NONE:
  339. alignment = 64 * 1024;
  340. break;
  341. case I915_TILING_X:
  342. if (IS_I9XX(dev))
  343. alignment = 1024 * 1024;
  344. else
  345. alignment = 512 * 1024;
  346. break;
  347. case I915_TILING_Y:
  348. /* FIXME: Is this true? */
  349. DRM_ERROR("Y tiled not allowed for scan out buffers\n");
  350. return;
  351. default:
  352. BUG();
  353. }
  354. if (i915_gem_object_pin(intel_fb->obj, alignment))
  355. return;
  356. i915_gem_object_set_to_gtt_domain(intel_fb->obj, 1);
  357. Start = obj_priv->gtt_offset;
  358. Offset = y * crtc->fb->pitch + x * (crtc->fb->bits_per_pixel / 8);
  359. I915_WRITE(dspstride, crtc->fb->pitch);
  360. dspcntr = I915_READ(dspcntr_reg);
  361. /* Mask out pixel format bits in case we change it */
  362. dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;
  363. switch (crtc->fb->bits_per_pixel) {
  364. case 8:
  365. dspcntr |= DISPPLANE_8BPP;
  366. break;
  367. case 16:
  368. if (crtc->fb->depth == 15)
  369. dspcntr |= DISPPLANE_15_16BPP;
  370. else
  371. dspcntr |= DISPPLANE_16BPP;
  372. break;
  373. case 24:
  374. case 32:
  375. dspcntr |= DISPPLANE_32BPP_NO_ALPHA;
  376. break;
  377. default:
  378. DRM_ERROR("Unknown color depth\n");
  379. return;
  380. }
  381. I915_WRITE(dspcntr_reg, dspcntr);
  382. DRM_DEBUG("Writing base %08lX %08lX %d %d\n", Start, Offset, x, y);
  383. if (IS_I965G(dev)) {
  384. I915_WRITE(dspbase, Offset);
  385. I915_READ(dspbase);
  386. I915_WRITE(dspsurf, Start);
  387. I915_READ(dspsurf);
  388. } else {
  389. I915_WRITE(dspbase, Start + Offset);
  390. I915_READ(dspbase);
  391. }
  392. intel_wait_for_vblank(dev);
  393. if (old_fb) {
  394. intel_fb = to_intel_framebuffer(old_fb);
  395. i915_gem_object_unpin(intel_fb->obj);
  396. }
  397. if (!dev->primary->master)
  398. return;
  399. master_priv = dev->primary->master->driver_priv;
  400. if (!master_priv->sarea_priv)
  401. return;
  402. switch (pipe) {
  403. case 0:
  404. master_priv->sarea_priv->pipeA_x = x;
  405. master_priv->sarea_priv->pipeA_y = y;
  406. break;
  407. case 1:
  408. master_priv->sarea_priv->pipeB_x = x;
  409. master_priv->sarea_priv->pipeB_y = y;
  410. break;
  411. default:
  412. DRM_ERROR("Can't update pipe %d in SAREA\n", pipe);
  413. break;
  414. }
  415. }
  416. /**
  417. * Sets the power management mode of the pipe and plane.
  418. *
  419. * This code should probably grow support for turning the cursor off and back
  420. * on appropriately at the same time as we're turning the pipe off/on.
  421. */
  422. static void intel_crtc_dpms(struct drm_crtc *crtc, int mode)
  423. {
  424. struct drm_device *dev = crtc->dev;
  425. struct drm_i915_master_private *master_priv;
  426. struct drm_i915_private *dev_priv = dev->dev_private;
  427. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  428. int pipe = intel_crtc->pipe;
  429. int dpll_reg = (pipe == 0) ? DPLL_A : DPLL_B;
  430. int dspcntr_reg = (pipe == 0) ? DSPACNTR : DSPBCNTR;
  431. int dspbase_reg = (pipe == 0) ? DSPAADDR : DSPBADDR;
  432. int pipeconf_reg = (pipe == 0) ? PIPEACONF : PIPEBCONF;
  433. u32 temp;
  434. bool enabled;
  435. /* XXX: When our outputs are all unaware of DPMS modes other than off
  436. * and on, we should map those modes to DRM_MODE_DPMS_OFF in the CRTC.
  437. */
  438. switch (mode) {
  439. case DRM_MODE_DPMS_ON:
  440. case DRM_MODE_DPMS_STANDBY:
  441. case DRM_MODE_DPMS_SUSPEND:
  442. /* Enable the DPLL */
  443. temp = I915_READ(dpll_reg);
  444. if ((temp & DPLL_VCO_ENABLE) == 0) {
  445. I915_WRITE(dpll_reg, temp);
  446. I915_READ(dpll_reg);
  447. /* Wait for the clocks to stabilize. */
  448. udelay(150);
  449. I915_WRITE(dpll_reg, temp | DPLL_VCO_ENABLE);
  450. I915_READ(dpll_reg);
  451. /* Wait for the clocks to stabilize. */
  452. udelay(150);
  453. I915_WRITE(dpll_reg, temp | DPLL_VCO_ENABLE);
  454. I915_READ(dpll_reg);
  455. /* Wait for the clocks to stabilize. */
  456. udelay(150);
  457. }
  458. /* Enable the pipe */
  459. temp = I915_READ(pipeconf_reg);
  460. if ((temp & PIPEACONF_ENABLE) == 0)
  461. I915_WRITE(pipeconf_reg, temp | PIPEACONF_ENABLE);
  462. /* Enable the plane */
  463. temp = I915_READ(dspcntr_reg);
  464. if ((temp & DISPLAY_PLANE_ENABLE) == 0) {
  465. I915_WRITE(dspcntr_reg, temp | DISPLAY_PLANE_ENABLE);
  466. /* Flush the plane changes */
  467. I915_WRITE(dspbase_reg, I915_READ(dspbase_reg));
  468. }
  469. intel_crtc_load_lut(crtc);
  470. /* Give the overlay scaler a chance to enable if it's on this pipe */
  471. //intel_crtc_dpms_video(crtc, true); TODO
  472. break;
  473. case DRM_MODE_DPMS_OFF:
  474. /* Give the overlay scaler a chance to disable if it's on this pipe */
  475. //intel_crtc_dpms_video(crtc, FALSE); TODO
  476. /* Disable the VGA plane that we never use */
  477. I915_WRITE(VGACNTRL, VGA_DISP_DISABLE);
  478. /* Disable display plane */
  479. temp = I915_READ(dspcntr_reg);
  480. if ((temp & DISPLAY_PLANE_ENABLE) != 0) {
  481. I915_WRITE(dspcntr_reg, temp & ~DISPLAY_PLANE_ENABLE);
  482. /* Flush the plane changes */
  483. I915_WRITE(dspbase_reg, I915_READ(dspbase_reg));
  484. I915_READ(dspbase_reg);
  485. }
  486. if (!IS_I9XX(dev)) {
  487. /* Wait for vblank for the disable to take effect */
  488. intel_wait_for_vblank(dev);
  489. }
  490. /* Next, disable display pipes */
  491. temp = I915_READ(pipeconf_reg);
  492. if ((temp & PIPEACONF_ENABLE) != 0) {
  493. I915_WRITE(pipeconf_reg, temp & ~PIPEACONF_ENABLE);
  494. I915_READ(pipeconf_reg);
  495. }
  496. /* Wait for vblank for the disable to take effect. */
  497. intel_wait_for_vblank(dev);
  498. temp = I915_READ(dpll_reg);
  499. if ((temp & DPLL_VCO_ENABLE) != 0) {
  500. I915_WRITE(dpll_reg, temp & ~DPLL_VCO_ENABLE);
  501. I915_READ(dpll_reg);
  502. }
  503. /* Wait for the clocks to turn off. */
  504. udelay(150);
  505. break;
  506. }
  507. if (!dev->primary->master)
  508. return;
  509. master_priv = dev->primary->master->driver_priv;
  510. if (!master_priv->sarea_priv)
  511. return;
  512. enabled = crtc->enabled && mode != DRM_MODE_DPMS_OFF;
  513. switch (pipe) {
  514. case 0:
  515. master_priv->sarea_priv->pipeA_w = enabled ? crtc->mode.hdisplay : 0;
  516. master_priv->sarea_priv->pipeA_h = enabled ? crtc->mode.vdisplay : 0;
  517. break;
  518. case 1:
  519. master_priv->sarea_priv->pipeB_w = enabled ? crtc->mode.hdisplay : 0;
  520. master_priv->sarea_priv->pipeB_h = enabled ? crtc->mode.vdisplay : 0;
  521. break;
  522. default:
  523. DRM_ERROR("Can't update pipe %d in SAREA\n", pipe);
  524. break;
  525. }
  526. intel_crtc->dpms_mode = mode;
  527. }
  528. static void intel_crtc_prepare (struct drm_crtc *crtc)
  529. {
  530. struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
  531. crtc_funcs->dpms(crtc, DRM_MODE_DPMS_OFF);
  532. }
  533. static void intel_crtc_commit (struct drm_crtc *crtc)
  534. {
  535. struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
  536. crtc_funcs->dpms(crtc, DRM_MODE_DPMS_ON);
  537. }
  538. void intel_encoder_prepare (struct drm_encoder *encoder)
  539. {
  540. struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
  541. /* lvds has its own version of prepare see intel_lvds_prepare */
  542. encoder_funcs->dpms(encoder, DRM_MODE_DPMS_OFF);
  543. }
  544. void intel_encoder_commit (struct drm_encoder *encoder)
  545. {
  546. struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
  547. /* lvds has its own version of commit see intel_lvds_commit */
  548. encoder_funcs->dpms(encoder, DRM_MODE_DPMS_ON);
  549. }
  550. static bool intel_crtc_mode_fixup(struct drm_crtc *crtc,
  551. struct drm_display_mode *mode,
  552. struct drm_display_mode *adjusted_mode)
  553. {
  554. return true;
  555. }
  556. /** Returns the core display clock speed for i830 - i945 */
  557. static int intel_get_core_clock_speed(struct drm_device *dev)
  558. {
  559. /* Core clock values taken from the published datasheets.
  560. * The 830 may go up to 166 Mhz, which we should check.
  561. */
  562. if (IS_I945G(dev))
  563. return 400000;
  564. else if (IS_I915G(dev))
  565. return 333000;
  566. else if (IS_I945GM(dev) || IS_845G(dev))
  567. return 200000;
  568. else if (IS_I915GM(dev)) {
  569. u16 gcfgc = 0;
  570. pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
  571. if (gcfgc & GC_LOW_FREQUENCY_ENABLE)
  572. return 133000;
  573. else {
  574. switch (gcfgc & GC_DISPLAY_CLOCK_MASK) {
  575. case GC_DISPLAY_CLOCK_333_MHZ:
  576. return 333000;
  577. default:
  578. case GC_DISPLAY_CLOCK_190_200_MHZ:
  579. return 190000;
  580. }
  581. }
  582. } else if (IS_I865G(dev))
  583. return 266000;
  584. else if (IS_I855(dev)) {
  585. u16 hpllcc = 0;
  586. /* Assume that the hardware is in the high speed state. This
  587. * should be the default.
  588. */
  589. switch (hpllcc & GC_CLOCK_CONTROL_MASK) {
  590. case GC_CLOCK_133_200:
  591. case GC_CLOCK_100_200:
  592. return 200000;
  593. case GC_CLOCK_166_250:
  594. return 250000;
  595. case GC_CLOCK_100_133:
  596. return 133000;
  597. }
  598. } else /* 852, 830 */
  599. return 133000;
  600. return 0; /* Silence gcc warning */
  601. }
  602. /**
  603. * Return the pipe currently connected to the panel fitter,
  604. * or -1 if the panel fitter is not present or not in use
  605. */
  606. static int intel_panel_fitter_pipe (struct drm_device *dev)
  607. {
  608. struct drm_i915_private *dev_priv = dev->dev_private;
  609. u32 pfit_control;
  610. /* i830 doesn't have a panel fitter */
  611. if (IS_I830(dev))
  612. return -1;
  613. pfit_control = I915_READ(PFIT_CONTROL);
  614. /* See if the panel fitter is in use */
  615. if ((pfit_control & PFIT_ENABLE) == 0)
  616. return -1;
  617. /* 965 can place panel fitter on either pipe */
  618. if (IS_I965G(dev))
  619. return (pfit_control >> 29) & 0x3;
  620. /* older chips can only use pipe 1 */
  621. return 1;
  622. }
  623. static void intel_crtc_mode_set(struct drm_crtc *crtc,
  624. struct drm_display_mode *mode,
  625. struct drm_display_mode *adjusted_mode,
  626. int x, int y,
  627. struct drm_framebuffer *old_fb)
  628. {
  629. struct drm_device *dev = crtc->dev;
  630. struct drm_i915_private *dev_priv = dev->dev_private;
  631. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  632. int pipe = intel_crtc->pipe;
  633. int fp_reg = (pipe == 0) ? FPA0 : FPB0;
  634. int dpll_reg = (pipe == 0) ? DPLL_A : DPLL_B;
  635. int dpll_md_reg = (intel_crtc->pipe == 0) ? DPLL_A_MD : DPLL_B_MD;
  636. int dspcntr_reg = (pipe == 0) ? DSPACNTR : DSPBCNTR;
  637. int pipeconf_reg = (pipe == 0) ? PIPEACONF : PIPEBCONF;
  638. int htot_reg = (pipe == 0) ? HTOTAL_A : HTOTAL_B;
  639. int hblank_reg = (pipe == 0) ? HBLANK_A : HBLANK_B;
  640. int hsync_reg = (pipe == 0) ? HSYNC_A : HSYNC_B;
  641. int vtot_reg = (pipe == 0) ? VTOTAL_A : VTOTAL_B;
  642. int vblank_reg = (pipe == 0) ? VBLANK_A : VBLANK_B;
  643. int vsync_reg = (pipe == 0) ? VSYNC_A : VSYNC_B;
  644. int dspsize_reg = (pipe == 0) ? DSPASIZE : DSPBSIZE;
  645. int dsppos_reg = (pipe == 0) ? DSPAPOS : DSPBPOS;
  646. int pipesrc_reg = (pipe == 0) ? PIPEASRC : PIPEBSRC;
  647. int refclk;
  648. intel_clock_t clock;
  649. u32 dpll = 0, fp = 0, dspcntr, pipeconf;
  650. bool ok, is_sdvo = false, is_dvo = false;
  651. bool is_crt = false, is_lvds = false, is_tv = false;
  652. struct drm_mode_config *mode_config = &dev->mode_config;
  653. struct drm_connector *connector;
  654. drm_vblank_pre_modeset(dev, pipe);
  655. list_for_each_entry(connector, &mode_config->connector_list, head) {
  656. struct intel_output *intel_output = to_intel_output(connector);
  657. if (!connector->encoder || connector->encoder->crtc != crtc)
  658. continue;
  659. switch (intel_output->type) {
  660. case INTEL_OUTPUT_LVDS:
  661. is_lvds = true;
  662. break;
  663. case INTEL_OUTPUT_SDVO:
  664. case INTEL_OUTPUT_HDMI:
  665. is_sdvo = true;
  666. if (intel_output->needs_tv_clock)
  667. is_tv = true;
  668. break;
  669. case INTEL_OUTPUT_DVO:
  670. is_dvo = true;
  671. break;
  672. case INTEL_OUTPUT_TVOUT:
  673. is_tv = true;
  674. break;
  675. case INTEL_OUTPUT_ANALOG:
  676. is_crt = true;
  677. break;
  678. }
  679. }
  680. if (IS_I9XX(dev)) {
  681. refclk = 96000;
  682. } else {
  683. refclk = 48000;
  684. }
  685. ok = intel_find_best_PLL(crtc, adjusted_mode->clock, refclk, &clock);
  686. if (!ok) {
  687. DRM_ERROR("Couldn't find PLL settings for mode!\n");
  688. return;
  689. }
  690. fp = clock.n << 16 | clock.m1 << 8 | clock.m2;
  691. dpll = DPLL_VGA_MODE_DIS;
  692. if (IS_I9XX(dev)) {
  693. if (is_lvds)
  694. dpll |= DPLLB_MODE_LVDS;
  695. else
  696. dpll |= DPLLB_MODE_DAC_SERIAL;
  697. if (is_sdvo) {
  698. dpll |= DPLL_DVO_HIGH_SPEED;
  699. if (IS_I945G(dev) || IS_I945GM(dev)) {
  700. int sdvo_pixel_multiply = adjusted_mode->clock / mode->clock;
  701. dpll |= (sdvo_pixel_multiply - 1) << SDVO_MULTIPLIER_SHIFT_HIRES;
  702. }
  703. }
  704. /* compute bitmask from p1 value */
  705. dpll |= (1 << (clock.p1 - 1)) << 16;
  706. switch (clock.p2) {
  707. case 5:
  708. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
  709. break;
  710. case 7:
  711. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
  712. break;
  713. case 10:
  714. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
  715. break;
  716. case 14:
  717. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
  718. break;
  719. }
  720. if (IS_I965G(dev))
  721. dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
  722. } else {
  723. if (is_lvds) {
  724. dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  725. } else {
  726. if (clock.p1 == 2)
  727. dpll |= PLL_P1_DIVIDE_BY_TWO;
  728. else
  729. dpll |= (clock.p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  730. if (clock.p2 == 4)
  731. dpll |= PLL_P2_DIVIDE_BY_4;
  732. }
  733. }
  734. if (is_tv) {
  735. /* XXX: just matching BIOS for now */
  736. /* dpll |= PLL_REF_INPUT_TVCLKINBC; */
  737. dpll |= 3;
  738. }
  739. else
  740. dpll |= PLL_REF_INPUT_DREFCLK;
  741. /* setup pipeconf */
  742. pipeconf = I915_READ(pipeconf_reg);
  743. /* Set up the display plane register */
  744. dspcntr = DISPPLANE_GAMMA_ENABLE;
  745. if (pipe == 0)
  746. dspcntr |= DISPPLANE_SEL_PIPE_A;
  747. else
  748. dspcntr |= DISPPLANE_SEL_PIPE_B;
  749. if (pipe == 0 && !IS_I965G(dev)) {
  750. /* Enable pixel doubling when the dot clock is > 90% of the (display)
  751. * core speed.
  752. *
  753. * XXX: No double-wide on 915GM pipe B. Is that the only reason for the
  754. * pipe == 0 check?
  755. */
  756. if (mode->clock > intel_get_core_clock_speed(dev) * 9 / 10)
  757. pipeconf |= PIPEACONF_DOUBLE_WIDE;
  758. else
  759. pipeconf &= ~PIPEACONF_DOUBLE_WIDE;
  760. }
  761. dspcntr |= DISPLAY_PLANE_ENABLE;
  762. pipeconf |= PIPEACONF_ENABLE;
  763. dpll |= DPLL_VCO_ENABLE;
  764. /* Disable the panel fitter if it was on our pipe */
  765. if (intel_panel_fitter_pipe(dev) == pipe)
  766. I915_WRITE(PFIT_CONTROL, 0);
  767. DRM_DEBUG("Mode for pipe %c:\n", pipe == 0 ? 'A' : 'B');
  768. drm_mode_debug_printmodeline(mode);
  769. if (dpll & DPLL_VCO_ENABLE) {
  770. I915_WRITE(fp_reg, fp);
  771. I915_WRITE(dpll_reg, dpll & ~DPLL_VCO_ENABLE);
  772. I915_READ(dpll_reg);
  773. udelay(150);
  774. }
  775. /* The LVDS pin pair needs to be on before the DPLLs are enabled.
  776. * This is an exception to the general rule that mode_set doesn't turn
  777. * things on.
  778. */
  779. if (is_lvds) {
  780. u32 lvds = I915_READ(LVDS);
  781. lvds |= LVDS_PORT_EN | LVDS_A0A2_CLKA_POWER_UP | LVDS_PIPEB_SELECT;
  782. /* Set the B0-B3 data pairs corresponding to whether we're going to
  783. * set the DPLLs for dual-channel mode or not.
  784. */
  785. if (clock.p2 == 7)
  786. lvds |= LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP;
  787. else
  788. lvds &= ~(LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP);
  789. /* It would be nice to set 24 vs 18-bit mode (LVDS_A3_POWER_UP)
  790. * appropriately here, but we need to look more thoroughly into how
  791. * panels behave in the two modes.
  792. */
  793. I915_WRITE(LVDS, lvds);
  794. I915_READ(LVDS);
  795. }
  796. I915_WRITE(fp_reg, fp);
  797. I915_WRITE(dpll_reg, dpll);
  798. I915_READ(dpll_reg);
  799. /* Wait for the clocks to stabilize. */
  800. udelay(150);
  801. if (IS_I965G(dev)) {
  802. int sdvo_pixel_multiply = adjusted_mode->clock / mode->clock;
  803. I915_WRITE(dpll_md_reg, (0 << DPLL_MD_UDI_DIVIDER_SHIFT) |
  804. ((sdvo_pixel_multiply - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT));
  805. } else {
  806. /* write it again -- the BIOS does, after all */
  807. I915_WRITE(dpll_reg, dpll);
  808. }
  809. I915_READ(dpll_reg);
  810. /* Wait for the clocks to stabilize. */
  811. udelay(150);
  812. I915_WRITE(htot_reg, (adjusted_mode->crtc_hdisplay - 1) |
  813. ((adjusted_mode->crtc_htotal - 1) << 16));
  814. I915_WRITE(hblank_reg, (adjusted_mode->crtc_hblank_start - 1) |
  815. ((adjusted_mode->crtc_hblank_end - 1) << 16));
  816. I915_WRITE(hsync_reg, (adjusted_mode->crtc_hsync_start - 1) |
  817. ((adjusted_mode->crtc_hsync_end - 1) << 16));
  818. I915_WRITE(vtot_reg, (adjusted_mode->crtc_vdisplay - 1) |
  819. ((adjusted_mode->crtc_vtotal - 1) << 16));
  820. I915_WRITE(vblank_reg, (adjusted_mode->crtc_vblank_start - 1) |
  821. ((adjusted_mode->crtc_vblank_end - 1) << 16));
  822. I915_WRITE(vsync_reg, (adjusted_mode->crtc_vsync_start - 1) |
  823. ((adjusted_mode->crtc_vsync_end - 1) << 16));
  824. /* pipesrc and dspsize control the size that is scaled from, which should
  825. * always be the user's requested size.
  826. */
  827. I915_WRITE(dspsize_reg, ((mode->vdisplay - 1) << 16) | (mode->hdisplay - 1));
  828. I915_WRITE(dsppos_reg, 0);
  829. I915_WRITE(pipesrc_reg, ((mode->hdisplay - 1) << 16) | (mode->vdisplay - 1));
  830. I915_WRITE(pipeconf_reg, pipeconf);
  831. I915_READ(pipeconf_reg);
  832. intel_wait_for_vblank(dev);
  833. I915_WRITE(dspcntr_reg, dspcntr);
  834. /* Flush the plane changes */
  835. intel_pipe_set_base(crtc, x, y, old_fb);
  836. drm_vblank_post_modeset(dev, pipe);
  837. }
  838. /** Loads the palette/gamma unit for the CRTC with the prepared values */
  839. void intel_crtc_load_lut(struct drm_crtc *crtc)
  840. {
  841. struct drm_device *dev = crtc->dev;
  842. struct drm_i915_private *dev_priv = dev->dev_private;
  843. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  844. int palreg = (intel_crtc->pipe == 0) ? PALETTE_A : PALETTE_B;
  845. int i;
  846. /* The clocks have to be on to load the palette. */
  847. if (!crtc->enabled)
  848. return;
  849. for (i = 0; i < 256; i++) {
  850. I915_WRITE(palreg + 4 * i,
  851. (intel_crtc->lut_r[i] << 16) |
  852. (intel_crtc->lut_g[i] << 8) |
  853. intel_crtc->lut_b[i]);
  854. }
  855. }
  856. static int intel_crtc_cursor_set(struct drm_crtc *crtc,
  857. struct drm_file *file_priv,
  858. uint32_t handle,
  859. uint32_t width, uint32_t height)
  860. {
  861. struct drm_device *dev = crtc->dev;
  862. struct drm_i915_private *dev_priv = dev->dev_private;
  863. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  864. struct drm_gem_object *bo;
  865. struct drm_i915_gem_object *obj_priv;
  866. int pipe = intel_crtc->pipe;
  867. uint32_t control = (pipe == 0) ? CURACNTR : CURBCNTR;
  868. uint32_t base = (pipe == 0) ? CURABASE : CURBBASE;
  869. uint32_t temp;
  870. size_t addr;
  871. int ret;
  872. DRM_DEBUG("\n");
  873. /* if we want to turn off the cursor ignore width and height */
  874. if (!handle) {
  875. DRM_DEBUG("cursor off\n");
  876. temp = CURSOR_MODE_DISABLE;
  877. addr = 0;
  878. bo = NULL;
  879. goto finish;
  880. }
  881. /* Currently we only support 64x64 cursors */
  882. if (width != 64 || height != 64) {
  883. DRM_ERROR("we currently only support 64x64 cursors\n");
  884. return -EINVAL;
  885. }
  886. bo = drm_gem_object_lookup(dev, file_priv, handle);
  887. if (!bo)
  888. return -ENOENT;
  889. obj_priv = bo->driver_private;
  890. if (bo->size < width * height * 4) {
  891. DRM_ERROR("buffer is to small\n");
  892. ret = -ENOMEM;
  893. goto fail;
  894. }
  895. /* we only need to pin inside GTT if cursor is non-phy */
  896. if (!dev_priv->cursor_needs_physical) {
  897. ret = i915_gem_object_pin(bo, PAGE_SIZE);
  898. if (ret) {
  899. DRM_ERROR("failed to pin cursor bo\n");
  900. goto fail;
  901. }
  902. addr = obj_priv->gtt_offset;
  903. } else {
  904. ret = i915_gem_attach_phys_object(dev, bo, (pipe == 0) ? I915_GEM_PHYS_CURSOR_0 : I915_GEM_PHYS_CURSOR_1);
  905. if (ret) {
  906. DRM_ERROR("failed to attach phys object\n");
  907. goto fail;
  908. }
  909. addr = obj_priv->phys_obj->handle->busaddr;
  910. }
  911. temp = 0;
  912. /* set the pipe for the cursor */
  913. temp |= (pipe << 28);
  914. temp |= CURSOR_MODE_64_ARGB_AX | MCURSOR_GAMMA_ENABLE;
  915. finish:
  916. I915_WRITE(control, temp);
  917. I915_WRITE(base, addr);
  918. if (intel_crtc->cursor_bo) {
  919. if (dev_priv->cursor_needs_physical) {
  920. if (intel_crtc->cursor_bo != bo)
  921. i915_gem_detach_phys_object(dev, intel_crtc->cursor_bo);
  922. } else
  923. i915_gem_object_unpin(intel_crtc->cursor_bo);
  924. mutex_lock(&dev->struct_mutex);
  925. drm_gem_object_unreference(intel_crtc->cursor_bo);
  926. mutex_unlock(&dev->struct_mutex);
  927. }
  928. intel_crtc->cursor_addr = addr;
  929. intel_crtc->cursor_bo = bo;
  930. return 0;
  931. fail:
  932. mutex_lock(&dev->struct_mutex);
  933. drm_gem_object_unreference(bo);
  934. mutex_unlock(&dev->struct_mutex);
  935. return ret;
  936. }
  937. static int intel_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)
  938. {
  939. struct drm_device *dev = crtc->dev;
  940. struct drm_i915_private *dev_priv = dev->dev_private;
  941. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  942. int pipe = intel_crtc->pipe;
  943. uint32_t temp = 0;
  944. uint32_t adder;
  945. if (x < 0) {
  946. temp |= (CURSOR_POS_SIGN << CURSOR_X_SHIFT);
  947. x = -x;
  948. }
  949. if (y < 0) {
  950. temp |= (CURSOR_POS_SIGN << CURSOR_Y_SHIFT);
  951. y = -y;
  952. }
  953. temp |= ((x & CURSOR_POS_MASK) << CURSOR_X_SHIFT);
  954. temp |= ((y & CURSOR_POS_MASK) << CURSOR_Y_SHIFT);
  955. adder = intel_crtc->cursor_addr;
  956. I915_WRITE((pipe == 0) ? CURAPOS : CURBPOS, temp);
  957. I915_WRITE((pipe == 0) ? CURABASE : CURBBASE, adder);
  958. return 0;
  959. }
  960. /** Sets the color ramps on behalf of RandR */
  961. void intel_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green,
  962. u16 blue, int regno)
  963. {
  964. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  965. intel_crtc->lut_r[regno] = red >> 8;
  966. intel_crtc->lut_g[regno] = green >> 8;
  967. intel_crtc->lut_b[regno] = blue >> 8;
  968. }
  969. static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
  970. u16 *blue, uint32_t size)
  971. {
  972. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  973. int i;
  974. if (size != 256)
  975. return;
  976. for (i = 0; i < 256; i++) {
  977. intel_crtc->lut_r[i] = red[i] >> 8;
  978. intel_crtc->lut_g[i] = green[i] >> 8;
  979. intel_crtc->lut_b[i] = blue[i] >> 8;
  980. }
  981. intel_crtc_load_lut(crtc);
  982. }
  983. /**
  984. * Get a pipe with a simple mode set on it for doing load-based monitor
  985. * detection.
  986. *
  987. * It will be up to the load-detect code to adjust the pipe as appropriate for
  988. * its requirements. The pipe will be connected to no other outputs.
  989. *
  990. * Currently this code will only succeed if there is a pipe with no outputs
  991. * configured for it. In the future, it could choose to temporarily disable
  992. * some outputs to free up a pipe for its use.
  993. *
  994. * \return crtc, or NULL if no pipes are available.
  995. */
  996. /* VESA 640x480x72Hz mode to set on the pipe */
  997. static struct drm_display_mode load_detect_mode = {
  998. DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
  999. 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  1000. };
  1001. struct drm_crtc *intel_get_load_detect_pipe(struct intel_output *intel_output,
  1002. struct drm_display_mode *mode,
  1003. int *dpms_mode)
  1004. {
  1005. struct intel_crtc *intel_crtc;
  1006. struct drm_crtc *possible_crtc;
  1007. struct drm_crtc *supported_crtc =NULL;
  1008. struct drm_encoder *encoder = &intel_output->enc;
  1009. struct drm_crtc *crtc = NULL;
  1010. struct drm_device *dev = encoder->dev;
  1011. struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
  1012. struct drm_crtc_helper_funcs *crtc_funcs;
  1013. int i = -1;
  1014. /*
  1015. * Algorithm gets a little messy:
  1016. * - if the connector already has an assigned crtc, use it (but make
  1017. * sure it's on first)
  1018. * - try to find the first unused crtc that can drive this connector,
  1019. * and use that if we find one
  1020. * - if there are no unused crtcs available, try to use the first
  1021. * one we found that supports the connector
  1022. */
  1023. /* See if we already have a CRTC for this connector */
  1024. if (encoder->crtc) {
  1025. crtc = encoder->crtc;
  1026. /* Make sure the crtc and connector are running */
  1027. intel_crtc = to_intel_crtc(crtc);
  1028. *dpms_mode = intel_crtc->dpms_mode;
  1029. if (intel_crtc->dpms_mode != DRM_MODE_DPMS_ON) {
  1030. crtc_funcs = crtc->helper_private;
  1031. crtc_funcs->dpms(crtc, DRM_MODE_DPMS_ON);
  1032. encoder_funcs->dpms(encoder, DRM_MODE_DPMS_ON);
  1033. }
  1034. return crtc;
  1035. }
  1036. /* Find an unused one (if possible) */
  1037. list_for_each_entry(possible_crtc, &dev->mode_config.crtc_list, head) {
  1038. i++;
  1039. if (!(encoder->possible_crtcs & (1 << i)))
  1040. continue;
  1041. if (!possible_crtc->enabled) {
  1042. crtc = possible_crtc;
  1043. break;
  1044. }
  1045. if (!supported_crtc)
  1046. supported_crtc = possible_crtc;
  1047. }
  1048. /*
  1049. * If we didn't find an unused CRTC, don't use any.
  1050. */
  1051. if (!crtc) {
  1052. return NULL;
  1053. }
  1054. encoder->crtc = crtc;
  1055. intel_output->load_detect_temp = true;
  1056. intel_crtc = to_intel_crtc(crtc);
  1057. *dpms_mode = intel_crtc->dpms_mode;
  1058. if (!crtc->enabled) {
  1059. if (!mode)
  1060. mode = &load_detect_mode;
  1061. drm_crtc_helper_set_mode(crtc, mode, 0, 0, crtc->fb);
  1062. } else {
  1063. if (intel_crtc->dpms_mode != DRM_MODE_DPMS_ON) {
  1064. crtc_funcs = crtc->helper_private;
  1065. crtc_funcs->dpms(crtc, DRM_MODE_DPMS_ON);
  1066. }
  1067. /* Add this connector to the crtc */
  1068. encoder_funcs->mode_set(encoder, &crtc->mode, &crtc->mode);
  1069. encoder_funcs->commit(encoder);
  1070. }
  1071. /* let the connector get through one full cycle before testing */
  1072. intel_wait_for_vblank(dev);
  1073. return crtc;
  1074. }
  1075. void intel_release_load_detect_pipe(struct intel_output *intel_output, int dpms_mode)
  1076. {
  1077. struct drm_encoder *encoder = &intel_output->enc;
  1078. struct drm_device *dev = encoder->dev;
  1079. struct drm_crtc *crtc = encoder->crtc;
  1080. struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private;
  1081. struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private;
  1082. if (intel_output->load_detect_temp) {
  1083. encoder->crtc = NULL;
  1084. intel_output->load_detect_temp = false;
  1085. crtc->enabled = drm_helper_crtc_in_use(crtc);
  1086. drm_helper_disable_unused_functions(dev);
  1087. }
  1088. /* Switch crtc and output back off if necessary */
  1089. if (crtc->enabled && dpms_mode != DRM_MODE_DPMS_ON) {
  1090. if (encoder->crtc == crtc)
  1091. encoder_funcs->dpms(encoder, dpms_mode);
  1092. crtc_funcs->dpms(crtc, dpms_mode);
  1093. }
  1094. }
  1095. /* Returns the clock of the currently programmed mode of the given pipe. */
  1096. static int intel_crtc_clock_get(struct drm_device *dev, struct drm_crtc *crtc)
  1097. {
  1098. struct drm_i915_private *dev_priv = dev->dev_private;
  1099. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1100. int pipe = intel_crtc->pipe;
  1101. u32 dpll = I915_READ((pipe == 0) ? DPLL_A : DPLL_B);
  1102. u32 fp;
  1103. intel_clock_t clock;
  1104. if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
  1105. fp = I915_READ((pipe == 0) ? FPA0 : FPB0);
  1106. else
  1107. fp = I915_READ((pipe == 0) ? FPA1 : FPB1);
  1108. clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
  1109. clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
  1110. clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
  1111. if (IS_I9XX(dev)) {
  1112. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
  1113. DPLL_FPA01_P1_POST_DIV_SHIFT);
  1114. switch (dpll & DPLL_MODE_MASK) {
  1115. case DPLLB_MODE_DAC_SERIAL:
  1116. clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
  1117. 5 : 10;
  1118. break;
  1119. case DPLLB_MODE_LVDS:
  1120. clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
  1121. 7 : 14;
  1122. break;
  1123. default:
  1124. DRM_DEBUG("Unknown DPLL mode %08x in programmed "
  1125. "mode\n", (int)(dpll & DPLL_MODE_MASK));
  1126. return 0;
  1127. }
  1128. /* XXX: Handle the 100Mhz refclk */
  1129. i9xx_clock(96000, &clock);
  1130. } else {
  1131. bool is_lvds = (pipe == 1) && (I915_READ(LVDS) & LVDS_PORT_EN);
  1132. if (is_lvds) {
  1133. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
  1134. DPLL_FPA01_P1_POST_DIV_SHIFT);
  1135. clock.p2 = 14;
  1136. if ((dpll & PLL_REF_INPUT_MASK) ==
  1137. PLLB_REF_INPUT_SPREADSPECTRUMIN) {
  1138. /* XXX: might not be 66MHz */
  1139. i8xx_clock(66000, &clock);
  1140. } else
  1141. i8xx_clock(48000, &clock);
  1142. } else {
  1143. if (dpll & PLL_P1_DIVIDE_BY_TWO)
  1144. clock.p1 = 2;
  1145. else {
  1146. clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
  1147. DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
  1148. }
  1149. if (dpll & PLL_P2_DIVIDE_BY_4)
  1150. clock.p2 = 4;
  1151. else
  1152. clock.p2 = 2;
  1153. i8xx_clock(48000, &clock);
  1154. }
  1155. }
  1156. /* XXX: It would be nice to validate the clocks, but we can't reuse
  1157. * i830PllIsValid() because it relies on the xf86_config connector
  1158. * configuration being accurate, which it isn't necessarily.
  1159. */
  1160. return clock.dot;
  1161. }
  1162. /** Returns the currently programmed mode of the given pipe. */
  1163. struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev,
  1164. struct drm_crtc *crtc)
  1165. {
  1166. struct drm_i915_private *dev_priv = dev->dev_private;
  1167. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1168. int pipe = intel_crtc->pipe;
  1169. struct drm_display_mode *mode;
  1170. int htot = I915_READ((pipe == 0) ? HTOTAL_A : HTOTAL_B);
  1171. int hsync = I915_READ((pipe == 0) ? HSYNC_A : HSYNC_B);
  1172. int vtot = I915_READ((pipe == 0) ? VTOTAL_A : VTOTAL_B);
  1173. int vsync = I915_READ((pipe == 0) ? VSYNC_A : VSYNC_B);
  1174. mode = kzalloc(sizeof(*mode), GFP_KERNEL);
  1175. if (!mode)
  1176. return NULL;
  1177. mode->clock = intel_crtc_clock_get(dev, crtc);
  1178. mode->hdisplay = (htot & 0xffff) + 1;
  1179. mode->htotal = ((htot & 0xffff0000) >> 16) + 1;
  1180. mode->hsync_start = (hsync & 0xffff) + 1;
  1181. mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1;
  1182. mode->vdisplay = (vtot & 0xffff) + 1;
  1183. mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1;
  1184. mode->vsync_start = (vsync & 0xffff) + 1;
  1185. mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1;
  1186. drm_mode_set_name(mode);
  1187. drm_mode_set_crtcinfo(mode, 0);
  1188. return mode;
  1189. }
  1190. static void intel_crtc_destroy(struct drm_crtc *crtc)
  1191. {
  1192. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1193. drm_crtc_cleanup(crtc);
  1194. kfree(intel_crtc);
  1195. }
  1196. static const struct drm_crtc_helper_funcs intel_helper_funcs = {
  1197. .dpms = intel_crtc_dpms,
  1198. .mode_fixup = intel_crtc_mode_fixup,
  1199. .mode_set = intel_crtc_mode_set,
  1200. .mode_set_base = intel_pipe_set_base,
  1201. .prepare = intel_crtc_prepare,
  1202. .commit = intel_crtc_commit,
  1203. };
  1204. static const struct drm_crtc_funcs intel_crtc_funcs = {
  1205. .cursor_set = intel_crtc_cursor_set,
  1206. .cursor_move = intel_crtc_cursor_move,
  1207. .gamma_set = intel_crtc_gamma_set,
  1208. .set_config = drm_crtc_helper_set_config,
  1209. .destroy = intel_crtc_destroy,
  1210. };
  1211. static void intel_crtc_init(struct drm_device *dev, int pipe)
  1212. {
  1213. struct intel_crtc *intel_crtc;
  1214. int i;
  1215. intel_crtc = kzalloc(sizeof(struct intel_crtc) + (INTELFB_CONN_LIMIT * sizeof(struct drm_connector *)), GFP_KERNEL);
  1216. if (intel_crtc == NULL)
  1217. return;
  1218. drm_crtc_init(dev, &intel_crtc->base, &intel_crtc_funcs);
  1219. drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256);
  1220. intel_crtc->pipe = pipe;
  1221. for (i = 0; i < 256; i++) {
  1222. intel_crtc->lut_r[i] = i;
  1223. intel_crtc->lut_g[i] = i;
  1224. intel_crtc->lut_b[i] = i;
  1225. }
  1226. intel_crtc->cursor_addr = 0;
  1227. intel_crtc->dpms_mode = DRM_MODE_DPMS_OFF;
  1228. drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
  1229. intel_crtc->mode_set.crtc = &intel_crtc->base;
  1230. intel_crtc->mode_set.connectors = (struct drm_connector **)(intel_crtc + 1);
  1231. intel_crtc->mode_set.num_connectors = 0;
  1232. if (i915_fbpercrtc) {
  1233. }
  1234. }
  1235. struct drm_crtc *intel_get_crtc_from_pipe(struct drm_device *dev, int pipe)
  1236. {
  1237. struct drm_crtc *crtc = NULL;
  1238. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  1239. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1240. if (intel_crtc->pipe == pipe)
  1241. break;
  1242. }
  1243. return crtc;
  1244. }
  1245. static int intel_connector_clones(struct drm_device *dev, int type_mask)
  1246. {
  1247. int index_mask = 0;
  1248. struct drm_connector *connector;
  1249. int entry = 0;
  1250. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  1251. struct intel_output *intel_output = to_intel_output(connector);
  1252. if (type_mask & (1 << intel_output->type))
  1253. index_mask |= (1 << entry);
  1254. entry++;
  1255. }
  1256. return index_mask;
  1257. }
  1258. static void intel_setup_outputs(struct drm_device *dev)
  1259. {
  1260. struct drm_i915_private *dev_priv = dev->dev_private;
  1261. struct drm_connector *connector;
  1262. intel_crt_init(dev);
  1263. /* Set up integrated LVDS */
  1264. if (IS_MOBILE(dev) && !IS_I830(dev))
  1265. intel_lvds_init(dev);
  1266. if (IS_I9XX(dev)) {
  1267. int found;
  1268. if (I915_READ(SDVOB) & SDVO_DETECTED) {
  1269. found = intel_sdvo_init(dev, SDVOB);
  1270. if (!found && SUPPORTS_INTEGRATED_HDMI(dev))
  1271. intel_hdmi_init(dev, SDVOB);
  1272. }
  1273. if (!IS_G4X(dev) || (I915_READ(SDVOB) & SDVO_DETECTED)) {
  1274. found = intel_sdvo_init(dev, SDVOC);
  1275. if (!found && SUPPORTS_INTEGRATED_HDMI(dev))
  1276. intel_hdmi_init(dev, SDVOC);
  1277. }
  1278. } else
  1279. intel_dvo_init(dev);
  1280. if (IS_I9XX(dev) && IS_MOBILE(dev))
  1281. intel_tv_init(dev);
  1282. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  1283. struct intel_output *intel_output = to_intel_output(connector);
  1284. struct drm_encoder *encoder = &intel_output->enc;
  1285. int crtc_mask = 0, clone_mask = 0;
  1286. /* valid crtcs */
  1287. switch(intel_output->type) {
  1288. case INTEL_OUTPUT_HDMI:
  1289. crtc_mask = ((1 << 0)|
  1290. (1 << 1));
  1291. clone_mask = ((1 << INTEL_OUTPUT_HDMI));
  1292. break;
  1293. case INTEL_OUTPUT_DVO:
  1294. case INTEL_OUTPUT_SDVO:
  1295. crtc_mask = ((1 << 0)|
  1296. (1 << 1));
  1297. clone_mask = ((1 << INTEL_OUTPUT_ANALOG) |
  1298. (1 << INTEL_OUTPUT_DVO) |
  1299. (1 << INTEL_OUTPUT_SDVO));
  1300. break;
  1301. case INTEL_OUTPUT_ANALOG:
  1302. crtc_mask = ((1 << 0)|
  1303. (1 << 1));
  1304. clone_mask = ((1 << INTEL_OUTPUT_ANALOG) |
  1305. (1 << INTEL_OUTPUT_DVO) |
  1306. (1 << INTEL_OUTPUT_SDVO));
  1307. break;
  1308. case INTEL_OUTPUT_LVDS:
  1309. crtc_mask = (1 << 1);
  1310. clone_mask = (1 << INTEL_OUTPUT_LVDS);
  1311. break;
  1312. case INTEL_OUTPUT_TVOUT:
  1313. crtc_mask = ((1 << 0) |
  1314. (1 << 1));
  1315. clone_mask = (1 << INTEL_OUTPUT_TVOUT);
  1316. break;
  1317. }
  1318. encoder->possible_crtcs = crtc_mask;
  1319. encoder->possible_clones = intel_connector_clones(dev, clone_mask);
  1320. }
  1321. }
  1322. static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
  1323. {
  1324. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  1325. struct drm_device *dev = fb->dev;
  1326. if (fb->fbdev)
  1327. intelfb_remove(dev, fb);
  1328. drm_framebuffer_cleanup(fb);
  1329. mutex_lock(&dev->struct_mutex);
  1330. drm_gem_object_unreference(intel_fb->obj);
  1331. mutex_unlock(&dev->struct_mutex);
  1332. kfree(intel_fb);
  1333. }
  1334. static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
  1335. struct drm_file *file_priv,
  1336. unsigned int *handle)
  1337. {
  1338. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  1339. struct drm_gem_object *object = intel_fb->obj;
  1340. return drm_gem_handle_create(file_priv, object, handle);
  1341. }
  1342. static const struct drm_framebuffer_funcs intel_fb_funcs = {
  1343. .destroy = intel_user_framebuffer_destroy,
  1344. .create_handle = intel_user_framebuffer_create_handle,
  1345. };
  1346. int intel_framebuffer_create(struct drm_device *dev,
  1347. struct drm_mode_fb_cmd *mode_cmd,
  1348. struct drm_framebuffer **fb,
  1349. struct drm_gem_object *obj)
  1350. {
  1351. struct intel_framebuffer *intel_fb;
  1352. int ret;
  1353. intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
  1354. if (!intel_fb)
  1355. return -ENOMEM;
  1356. ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs);
  1357. if (ret) {
  1358. DRM_ERROR("framebuffer init failed %d\n", ret);
  1359. return ret;
  1360. }
  1361. drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd);
  1362. intel_fb->obj = obj;
  1363. *fb = &intel_fb->base;
  1364. return 0;
  1365. }
  1366. static struct drm_framebuffer *
  1367. intel_user_framebuffer_create(struct drm_device *dev,
  1368. struct drm_file *filp,
  1369. struct drm_mode_fb_cmd *mode_cmd)
  1370. {
  1371. struct drm_gem_object *obj;
  1372. struct drm_framebuffer *fb;
  1373. int ret;
  1374. obj = drm_gem_object_lookup(dev, filp, mode_cmd->handle);
  1375. if (!obj)
  1376. return NULL;
  1377. ret = intel_framebuffer_create(dev, mode_cmd, &fb, obj);
  1378. if (ret) {
  1379. drm_gem_object_unreference(obj);
  1380. return NULL;
  1381. }
  1382. return fb;
  1383. }
  1384. static const struct drm_mode_config_funcs intel_mode_funcs = {
  1385. .fb_create = intel_user_framebuffer_create,
  1386. .fb_changed = intelfb_probe,
  1387. };
  1388. void intel_modeset_init(struct drm_device *dev)
  1389. {
  1390. int num_pipe;
  1391. int i;
  1392. drm_mode_config_init(dev);
  1393. dev->mode_config.min_width = 0;
  1394. dev->mode_config.min_height = 0;
  1395. dev->mode_config.funcs = (void *)&intel_mode_funcs;
  1396. if (IS_I965G(dev)) {
  1397. dev->mode_config.max_width = 8192;
  1398. dev->mode_config.max_height = 8192;
  1399. } else {
  1400. dev->mode_config.max_width = 2048;
  1401. dev->mode_config.max_height = 2048;
  1402. }
  1403. /* set memory base */
  1404. if (IS_I9XX(dev))
  1405. dev->mode_config.fb_base = pci_resource_start(dev->pdev, 2);
  1406. else
  1407. dev->mode_config.fb_base = pci_resource_start(dev->pdev, 0);
  1408. if (IS_MOBILE(dev) || IS_I9XX(dev))
  1409. num_pipe = 2;
  1410. else
  1411. num_pipe = 1;
  1412. DRM_DEBUG("%d display pipe%s available.\n",
  1413. num_pipe, num_pipe > 1 ? "s" : "");
  1414. for (i = 0; i < num_pipe; i++) {
  1415. intel_crtc_init(dev, i);
  1416. }
  1417. intel_setup_outputs(dev);
  1418. }
  1419. void intel_modeset_cleanup(struct drm_device *dev)
  1420. {
  1421. drm_mode_config_cleanup(dev);
  1422. }
  1423. /* current intel driver doesn't take advantage of encoders
  1424. always give back the encoder for the connector
  1425. */
  1426. struct drm_encoder *intel_best_encoder(struct drm_connector *connector)
  1427. {
  1428. struct intel_output *intel_output = to_intel_output(connector);
  1429. return &intel_output->enc;
  1430. }