msm_drv.c 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033
  1. /*
  2. * Copyright (c) 2016-2020, The Linux Foundation. All rights reserved.
  3. * Copyright (C) 2013 Red Hat
  4. * Author: Rob Clark <[email protected]>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published by
  8. * the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along with
  16. * this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /*
  19. * Copyright (c) 2016 Intel Corporation
  20. *
  21. * Permission to use, copy, modify, distribute, and sell this software and its
  22. * documentation for any purpose is hereby granted without fee, provided that
  23. * the above copyright notice appear in all copies and that both that copyright
  24. * notice and this permission notice appear in supporting documentation, and
  25. * that the name of the copyright holders not be used in advertising or
  26. * publicity pertaining to distribution of the software without specific,
  27. * written prior permission. The copyright holders make no representations
  28. * about the suitability of this software for any purpose. It is provided "as
  29. * is" without express or implied warranty.
  30. *
  31. * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  32. * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  33. * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  34. * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  35. * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  36. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  37. * OF THIS SOFTWARE.
  38. */
  39. #include <linux/of_address.h>
  40. #include <linux/kthread.h>
  41. #include <uapi/linux/sched/types.h>
  42. #include <drm/drm_of.h>
  43. #include <drm/drm_probe_helper.h>
  44. #include "msm_drv.h"
  45. #include "msm_gem.h"
  46. #include "msm_kms.h"
  47. #include "msm_mmu.h"
  48. #include "sde_wb.h"
  49. #include "sde_dbg.h"
  50. /*
  51. * MSM driver version:
  52. * - 1.0.0 - initial interface
  53. * - 1.1.0 - adds madvise, and support for submits with > 4 cmd buffers
  54. * - 1.2.0 - adds explicit fence support for submit ioctl
  55. * - 1.3.0 - adds GMEM_BASE + NR_RINGS params, SUBMITQUEUE_NEW +
  56. * SUBMITQUEUE_CLOSE ioctls, and MSM_INFO_IOVA flag for
  57. * MSM_GEM_INFO ioctl.
  58. * - 1.4.0 - softpin, MSM_RELOC_BO_DUMP, and GEM_INFO support to set/get
  59. * GEM object's debug name
  60. */
  61. #define MSM_VERSION_MAJOR 1
  62. #define MSM_VERSION_MINOR 4
  63. #define MSM_VERSION_PATCHLEVEL 0
  64. static void msm_fb_output_poll_changed(struct drm_device *dev)
  65. {
  66. struct msm_drm_private *priv = NULL;
  67. if (!dev) {
  68. DRM_ERROR("output_poll_changed failed, invalid input\n");
  69. return;
  70. }
  71. priv = dev->dev_private;
  72. if (priv->fbdev)
  73. drm_fb_helper_hotplug_event(priv->fbdev);
  74. }
  75. /**
  76. * msm_atomic_helper_check - validate state object
  77. * @dev: DRM device
  78. * @state: the driver state object
  79. *
  80. * This is a wrapper for the drm_atomic_helper_check to check the modeset
  81. * and state checking for planes. Additionally it checks if any secure
  82. * transition(moving CRTC and planes between secure and non-secure states and
  83. * vice versa) is allowed or not. When going to secure state, planes
  84. * with fb_mode as dir translated only can be staged on the CRTC, and only one
  85. * CRTC should be active.
  86. * Also mixing of secure and non-secure is not allowed.
  87. *
  88. * RETURNS
  89. * Zero for success or -errorno.
  90. */
  91. int msm_atomic_check(struct drm_device *dev,
  92. struct drm_atomic_state *state)
  93. {
  94. struct msm_drm_private *priv;
  95. priv = dev->dev_private;
  96. if (priv && priv->kms && priv->kms->funcs &&
  97. priv->kms->funcs->atomic_check)
  98. return priv->kms->funcs->atomic_check(priv->kms, state);
  99. return drm_atomic_helper_check(dev, state);
  100. }
  101. static const struct drm_mode_config_funcs mode_config_funcs = {
  102. .fb_create = msm_framebuffer_create,
  103. .output_poll_changed = msm_fb_output_poll_changed,
  104. .atomic_check = msm_atomic_check,
  105. .atomic_commit = msm_atomic_commit,
  106. .atomic_state_alloc = msm_atomic_state_alloc,
  107. .atomic_state_clear = msm_atomic_state_clear,
  108. .atomic_state_free = msm_atomic_state_free,
  109. };
  110. static const struct drm_mode_config_helper_funcs mode_config_helper_funcs = {
  111. .atomic_commit_tail = msm_atomic_commit_tail,
  112. };
  113. #ifdef CONFIG_DRM_MSM_REGISTER_LOGGING
  114. static bool reglog = false;
  115. MODULE_PARM_DESC(reglog, "Enable register read/write logging");
  116. module_param(reglog, bool, 0600);
  117. #else
  118. #define reglog 0
  119. #endif
  120. #ifdef CONFIG_DRM_FBDEV_EMULATION
  121. static bool fbdev = true;
  122. MODULE_PARM_DESC(fbdev, "Enable fbdev compat layer");
  123. module_param(fbdev, bool, 0600);
  124. #endif
  125. static char *vram = "16m";
  126. MODULE_PARM_DESC(vram, "Configure VRAM size (for devices without IOMMU/GPUMMU)");
  127. module_param(vram, charp, 0);
  128. bool dumpstate = false;
  129. MODULE_PARM_DESC(dumpstate, "Dump KMS state on errors");
  130. module_param(dumpstate, bool, 0600);
  131. static bool modeset = true;
  132. MODULE_PARM_DESC(modeset, "Use kernel modesetting [KMS] (1=on (default), 0=disable)");
  133. module_param(modeset, bool, 0600);
  134. /*
  135. * Util/helpers:
  136. */
  137. int msm_clk_bulk_get(struct device *dev, struct clk_bulk_data **bulk)
  138. {
  139. struct property *prop;
  140. const char *name;
  141. struct clk_bulk_data *local;
  142. int i = 0, ret, count;
  143. count = of_property_count_strings(dev->of_node, "clock-names");
  144. if (count < 1)
  145. return 0;
  146. local = devm_kcalloc(dev, sizeof(struct clk_bulk_data *),
  147. count, GFP_KERNEL);
  148. if (!local)
  149. return -ENOMEM;
  150. of_property_for_each_string(dev->of_node, "clock-names", prop, name) {
  151. local[i].id = devm_kstrdup(dev, name, GFP_KERNEL);
  152. if (!local[i].id) {
  153. devm_kfree(dev, local);
  154. return -ENOMEM;
  155. }
  156. i++;
  157. }
  158. ret = devm_clk_bulk_get(dev, count, local);
  159. if (ret) {
  160. for (i = 0; i < count; i++)
  161. devm_kfree(dev, (void *) local[i].id);
  162. devm_kfree(dev, local);
  163. return ret;
  164. }
  165. *bulk = local;
  166. return count;
  167. }
  168. struct clk *msm_clk_bulk_get_clock(struct clk_bulk_data *bulk, int count,
  169. const char *name)
  170. {
  171. int i;
  172. char n[32];
  173. snprintf(n, sizeof(n), "%s_clk", name);
  174. for (i = 0; bulk && i < count; i++) {
  175. if (!strcmp(bulk[i].id, name) || !strcmp(bulk[i].id, n))
  176. return bulk[i].clk;
  177. }
  178. return NULL;
  179. }
  180. struct clk *msm_clk_get(struct platform_device *pdev, const char *name)
  181. {
  182. struct clk *clk;
  183. char name2[32];
  184. clk = devm_clk_get(&pdev->dev, name);
  185. if (!IS_ERR(clk) || PTR_ERR(clk) == -EPROBE_DEFER)
  186. return clk;
  187. snprintf(name2, sizeof(name2), "%s_clk", name);
  188. clk = devm_clk_get(&pdev->dev, name2);
  189. if (!IS_ERR(clk))
  190. dev_warn(&pdev->dev, "Using legacy clk name binding. Use "
  191. "\"%s\" instead of \"%s\"\n", name, name2);
  192. return clk;
  193. }
  194. void __iomem *msm_ioremap(struct platform_device *pdev, const char *name,
  195. const char *dbgname)
  196. {
  197. struct resource *res;
  198. unsigned long size;
  199. void __iomem *ptr;
  200. if (name)
  201. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, name);
  202. else
  203. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  204. if (!res) {
  205. dev_dbg(&pdev->dev, "failed to get memory resource: %s\n",
  206. name);
  207. return ERR_PTR(-EINVAL);
  208. }
  209. size = resource_size(res);
  210. ptr = devm_ioremap_nocache(&pdev->dev, res->start, size);
  211. if (!ptr) {
  212. dev_err(&pdev->dev, "failed to ioremap: %s\n", name);
  213. return ERR_PTR(-ENOMEM);
  214. }
  215. if (reglog)
  216. dev_dbg(&pdev->dev, "IO:region %s %pK %08lx\n",
  217. dbgname, ptr, size);
  218. return ptr;
  219. }
  220. unsigned long msm_iomap_size(struct platform_device *pdev, const char *name)
  221. {
  222. struct resource *res;
  223. if (name)
  224. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, name);
  225. else
  226. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  227. if (!res) {
  228. dev_dbg(&pdev->dev, "failed to get memory resource: %s\n",
  229. name);
  230. return 0;
  231. }
  232. return resource_size(res);
  233. }
  234. void msm_iounmap(struct platform_device *pdev, void __iomem *addr)
  235. {
  236. devm_iounmap(&pdev->dev, addr);
  237. }
  238. void msm_writel(u32 data, void __iomem *addr)
  239. {
  240. if (reglog)
  241. pr_debug("IO:W %pK %08x\n", addr, data);
  242. writel(data, addr);
  243. }
  244. u32 msm_readl(const void __iomem *addr)
  245. {
  246. u32 val = readl(addr);
  247. if (reglog)
  248. pr_err("IO:R %pK %08x\n", addr, val);
  249. return val;
  250. }
  251. int msm_get_src_bpc(int chroma_format,
  252. int bpc)
  253. {
  254. int src_bpp;
  255. switch (chroma_format) {
  256. case MSM_CHROMA_444:
  257. src_bpp = bpc * 3;
  258. break;
  259. case MSM_CHROMA_422:
  260. src_bpp = bpc * 2;
  261. break;
  262. case MSM_CHROMA_420:
  263. src_bpp = mult_frac(bpc, 3, 2);
  264. break;
  265. default:
  266. src_bpp = bpc * 3;
  267. break;
  268. }
  269. return src_bpp;
  270. }
  271. struct vblank_work {
  272. struct kthread_work work;
  273. int crtc_id;
  274. bool enable;
  275. struct msm_drm_private *priv;
  276. };
  277. static void vblank_ctrl_worker(struct kthread_work *work)
  278. {
  279. struct vblank_work *cur_work = container_of(work,
  280. struct vblank_work, work);
  281. struct msm_drm_private *priv = cur_work->priv;
  282. struct msm_kms *kms = priv->kms;
  283. if (cur_work->enable)
  284. kms->funcs->enable_vblank(kms, priv->crtcs[cur_work->crtc_id]);
  285. else
  286. kms->funcs->disable_vblank(kms, priv->crtcs[cur_work->crtc_id]);
  287. kfree(cur_work);
  288. }
  289. static int vblank_ctrl_queue_work(struct msm_drm_private *priv,
  290. int crtc_id, bool enable)
  291. {
  292. struct vblank_work *cur_work;
  293. if (!priv || crtc_id >= priv->num_crtcs)
  294. return -EINVAL;
  295. cur_work = kzalloc(sizeof(*cur_work), GFP_ATOMIC);
  296. if (!cur_work)
  297. return -ENOMEM;
  298. kthread_init_work(&cur_work->work, vblank_ctrl_worker);
  299. cur_work->crtc_id = crtc_id;
  300. cur_work->enable = enable;
  301. cur_work->priv = priv;
  302. kthread_queue_work(&priv->event_thread[crtc_id].worker,
  303. &cur_work->work);
  304. return 0;
  305. }
  306. static int msm_drm_uninit(struct device *dev)
  307. {
  308. struct platform_device *pdev = to_platform_device(dev);
  309. struct drm_device *ddev = platform_get_drvdata(pdev);
  310. struct msm_drm_private *priv = ddev->dev_private;
  311. struct msm_kms *kms = priv->kms;
  312. int i;
  313. /* We must cancel and cleanup any pending vblank enable/disable
  314. * work before drm_irq_uninstall() to avoid work re-enabling an
  315. * irq after uninstall has disabled it.
  316. */
  317. flush_workqueue(priv->wq);
  318. destroy_workqueue(priv->wq);
  319. /* clean up display commit/event worker threads */
  320. for (i = 0; i < priv->num_crtcs; i++) {
  321. if (priv->disp_thread[i].thread) {
  322. kthread_flush_worker(&priv->disp_thread[i].worker);
  323. kthread_stop(priv->disp_thread[i].thread);
  324. priv->disp_thread[i].thread = NULL;
  325. }
  326. if (priv->event_thread[i].thread) {
  327. kthread_flush_worker(&priv->event_thread[i].worker);
  328. kthread_stop(priv->event_thread[i].thread);
  329. priv->event_thread[i].thread = NULL;
  330. }
  331. }
  332. drm_kms_helper_poll_fini(ddev);
  333. drm_mode_config_cleanup(ddev);
  334. if (priv->registered) {
  335. drm_dev_unregister(ddev);
  336. priv->registered = false;
  337. }
  338. #ifdef CONFIG_DRM_FBDEV_EMULATION
  339. if (fbdev && priv->fbdev)
  340. msm_fbdev_free(ddev);
  341. #endif
  342. drm_atomic_helper_shutdown(ddev);
  343. drm_mode_config_cleanup(ddev);
  344. pm_runtime_get_sync(dev);
  345. drm_irq_uninstall(ddev);
  346. pm_runtime_put_sync(dev);
  347. if (kms && kms->funcs)
  348. kms->funcs->destroy(kms);
  349. if (priv->vram.paddr) {
  350. unsigned long attrs = DMA_ATTR_NO_KERNEL_MAPPING;
  351. drm_mm_takedown(&priv->vram.mm);
  352. dma_free_attrs(dev, priv->vram.size, NULL,
  353. priv->vram.paddr, attrs);
  354. }
  355. component_unbind_all(dev, ddev);
  356. sde_dbg_destroy();
  357. debugfs_remove_recursive(priv->debug_root);
  358. sde_power_resource_deinit(pdev, &priv->phandle);
  359. msm_mdss_destroy(ddev);
  360. ddev->dev_private = NULL;
  361. kfree(priv);
  362. drm_dev_put(ddev);
  363. return 0;
  364. }
  365. #define KMS_MDP4 4
  366. #define KMS_MDP5 5
  367. #define KMS_SDE 3
  368. static int get_mdp_ver(struct platform_device *pdev)
  369. {
  370. #ifdef CONFIG_OF
  371. static const struct of_device_id match_types[] = { {
  372. .compatible = "qcom,mdss_mdp",
  373. .data = (void *)KMS_MDP5,
  374. },
  375. {
  376. .compatible = "qcom,sde-kms",
  377. .data = (void *)KMS_SDE,
  378. },
  379. {},
  380. };
  381. struct device *dev = &pdev->dev;
  382. const struct of_device_id *match;
  383. match = of_match_node(match_types, dev->of_node);
  384. if (match)
  385. return (int)(unsigned long)match->data;
  386. #endif
  387. return KMS_MDP4;
  388. }
  389. static int msm_init_vram(struct drm_device *dev)
  390. {
  391. struct msm_drm_private *priv = dev->dev_private;
  392. struct device_node *node;
  393. unsigned long size = 0;
  394. int ret = 0;
  395. /* In the device-tree world, we could have a 'memory-region'
  396. * phandle, which gives us a link to our "vram". Allocating
  397. * is all nicely abstracted behind the dma api, but we need
  398. * to know the entire size to allocate it all in one go. There
  399. * are two cases:
  400. * 1) device with no IOMMU, in which case we need exclusive
  401. * access to a VRAM carveout big enough for all gpu
  402. * buffers
  403. * 2) device with IOMMU, but where the bootloader puts up
  404. * a splash screen. In this case, the VRAM carveout
  405. * need only be large enough for fbdev fb. But we need
  406. * exclusive access to the buffer to avoid the kernel
  407. * using those pages for other purposes (which appears
  408. * as corruption on screen before we have a chance to
  409. * load and do initial modeset)
  410. */
  411. node = of_parse_phandle(dev->dev->of_node, "memory-region", 0);
  412. if (node) {
  413. struct resource r;
  414. ret = of_address_to_resource(node, 0, &r);
  415. of_node_put(node);
  416. if (ret)
  417. return ret;
  418. size = r.end - r.start;
  419. DRM_INFO("using VRAM carveout: %lx@%pa\n", size, &r.start);
  420. /* if we have no IOMMU, then we need to use carveout allocator.
  421. * Grab the entire CMA chunk carved out in early startup in
  422. * mach-msm:
  423. */
  424. } else if (!iommu_present(&platform_bus_type)) {
  425. DRM_INFO("using %s VRAM carveout\n", vram);
  426. size = memparse(vram, NULL);
  427. }
  428. if (size) {
  429. unsigned long attrs = 0;
  430. void *p;
  431. priv->vram.size = size;
  432. drm_mm_init(&priv->vram.mm, 0, (size >> PAGE_SHIFT) - 1);
  433. spin_lock_init(&priv->vram.lock);
  434. attrs |= DMA_ATTR_NO_KERNEL_MAPPING;
  435. attrs |= DMA_ATTR_WRITE_COMBINE;
  436. /* note that for no-kernel-mapping, the vaddr returned
  437. * is bogus, but non-null if allocation succeeded:
  438. */
  439. p = dma_alloc_attrs(dev->dev, size,
  440. &priv->vram.paddr, GFP_KERNEL, attrs);
  441. if (!p) {
  442. dev_err(dev->dev, "failed to allocate VRAM\n");
  443. priv->vram.paddr = 0;
  444. return -ENOMEM;
  445. }
  446. dev_info(dev->dev, "VRAM: %08x->%08x\n",
  447. (uint32_t)priv->vram.paddr,
  448. (uint32_t)(priv->vram.paddr + size));
  449. }
  450. return ret;
  451. }
  452. #ifdef CONFIG_OF
  453. static int msm_component_bind_all(struct device *dev,
  454. struct drm_device *drm_dev)
  455. {
  456. int ret;
  457. ret = component_bind_all(dev, drm_dev);
  458. if (ret)
  459. DRM_ERROR("component_bind_all failed: %d\n", ret);
  460. return ret;
  461. }
  462. #else
  463. static int msm_component_bind_all(struct device *dev,
  464. struct drm_device *drm_dev)
  465. {
  466. return 0;
  467. }
  468. #endif
  469. static int msm_drm_display_thread_create(struct sched_param param,
  470. struct msm_drm_private *priv, struct drm_device *ddev,
  471. struct device *dev)
  472. {
  473. int i, ret = 0;
  474. /**
  475. * this priority was found during empiric testing to have appropriate
  476. * realtime scheduling to process display updates and interact with
  477. * other real time and normal priority task
  478. */
  479. param.sched_priority = 16;
  480. for (i = 0; i < priv->num_crtcs; i++) {
  481. /* initialize display thread */
  482. priv->disp_thread[i].crtc_id = priv->crtcs[i]->base.id;
  483. kthread_init_worker(&priv->disp_thread[i].worker);
  484. priv->disp_thread[i].dev = ddev;
  485. priv->disp_thread[i].thread =
  486. kthread_run(kthread_worker_fn,
  487. &priv->disp_thread[i].worker,
  488. "crtc_commit:%d", priv->disp_thread[i].crtc_id);
  489. ret = sched_setscheduler(priv->disp_thread[i].thread,
  490. SCHED_FIFO, &param);
  491. if (ret)
  492. pr_warn("display thread priority update failed: %d\n",
  493. ret);
  494. if (IS_ERR(priv->disp_thread[i].thread)) {
  495. dev_err(dev, "failed to create crtc_commit kthread\n");
  496. priv->disp_thread[i].thread = NULL;
  497. }
  498. /* initialize event thread */
  499. priv->event_thread[i].crtc_id = priv->crtcs[i]->base.id;
  500. kthread_init_worker(&priv->event_thread[i].worker);
  501. priv->event_thread[i].dev = ddev;
  502. priv->event_thread[i].thread =
  503. kthread_run(kthread_worker_fn,
  504. &priv->event_thread[i].worker,
  505. "crtc_event:%d", priv->event_thread[i].crtc_id);
  506. /**
  507. * event thread should also run at same priority as disp_thread
  508. * because it is handling frame_done events. A lower priority
  509. * event thread and higher priority disp_thread can causes
  510. * frame_pending counters beyond 2. This can lead to commit
  511. * failure at crtc commit level.
  512. */
  513. ret = sched_setscheduler(priv->event_thread[i].thread,
  514. SCHED_FIFO, &param);
  515. if (ret)
  516. pr_warn("display event thread priority update failed: %d\n",
  517. ret);
  518. if (IS_ERR(priv->event_thread[i].thread)) {
  519. dev_err(dev, "failed to create crtc_event kthread\n");
  520. priv->event_thread[i].thread = NULL;
  521. }
  522. if ((!priv->disp_thread[i].thread) ||
  523. !priv->event_thread[i].thread) {
  524. /* clean up previously created threads if any */
  525. for ( ; i >= 0; i--) {
  526. if (priv->disp_thread[i].thread) {
  527. kthread_stop(
  528. priv->disp_thread[i].thread);
  529. priv->disp_thread[i].thread = NULL;
  530. }
  531. if (priv->event_thread[i].thread) {
  532. kthread_stop(
  533. priv->event_thread[i].thread);
  534. priv->event_thread[i].thread = NULL;
  535. }
  536. }
  537. return -EINVAL;
  538. }
  539. }
  540. /**
  541. * Since pp interrupt is heavy weight, try to queue the work
  542. * into a dedicated worker thread, so that they dont interrupt
  543. * other important events.
  544. */
  545. kthread_init_worker(&priv->pp_event_worker);
  546. priv->pp_event_thread = kthread_run(kthread_worker_fn,
  547. &priv->pp_event_worker, "pp_event");
  548. ret = sched_setscheduler(priv->pp_event_thread,
  549. SCHED_FIFO, &param);
  550. if (ret)
  551. pr_warn("pp_event thread priority update failed: %d\n",
  552. ret);
  553. if (IS_ERR(priv->pp_event_thread)) {
  554. dev_err(dev, "failed to create pp_event kthread\n");
  555. ret = PTR_ERR(priv->pp_event_thread);
  556. priv->pp_event_thread = NULL;
  557. return ret;
  558. }
  559. return 0;
  560. }
  561. static struct msm_kms *_msm_drm_component_init_helper(
  562. struct msm_drm_private *priv,
  563. struct drm_device *ddev, struct device *dev,
  564. struct platform_device *pdev)
  565. {
  566. int ret;
  567. struct msm_kms *kms;
  568. switch (get_mdp_ver(pdev)) {
  569. case KMS_MDP4:
  570. kms = mdp4_kms_init(ddev);
  571. break;
  572. case KMS_MDP5:
  573. kms = mdp5_kms_init(ddev);
  574. break;
  575. case KMS_SDE:
  576. kms = sde_kms_init(ddev);
  577. break;
  578. default:
  579. kms = ERR_PTR(-ENODEV);
  580. break;
  581. }
  582. if (IS_ERR_OR_NULL(kms)) {
  583. /*
  584. * NOTE: once we have GPU support, having no kms should not
  585. * be considered fatal.. ideally we would still support gpu
  586. * and (for example) use dmabuf/prime to share buffers with
  587. * imx drm driver on iMX5
  588. */
  589. dev_err(dev, "failed to load kms\n");
  590. return kms;
  591. }
  592. priv->kms = kms;
  593. pm_runtime_enable(dev);
  594. /**
  595. * Since kms->funcs->hw_init(kms) might call
  596. * drm_object_property_set_value to initialize some custom
  597. * properties we need to make sure mode_config.funcs are populated
  598. * beforehand to avoid dereferencing an unset value during the
  599. * drm_drv_uses_atomic_modeset check.
  600. */
  601. ddev->mode_config.funcs = &mode_config_funcs;
  602. ret = (kms)->funcs->hw_init(kms);
  603. if (ret) {
  604. dev_err(dev, "kms hw init failed: %d\n", ret);
  605. return ERR_PTR(ret);
  606. }
  607. return kms;
  608. }
  609. static int msm_drm_device_init(struct platform_device *pdev,
  610. struct drm_driver *drv)
  611. {
  612. struct device *dev = &pdev->dev;
  613. struct drm_device *ddev;
  614. struct msm_drm_private *priv;
  615. int i, ret;
  616. ddev = drm_dev_alloc(drv, dev);
  617. if (IS_ERR(ddev)) {
  618. dev_err(dev, "failed to allocate drm_device\n");
  619. return PTR_ERR(ddev);
  620. }
  621. drm_mode_config_init(ddev);
  622. platform_set_drvdata(pdev, ddev);
  623. priv = kzalloc(sizeof(*priv), GFP_KERNEL);
  624. if (!priv) {
  625. ret = -ENOMEM;
  626. goto priv_alloc_fail;
  627. }
  628. ddev->dev_private = priv;
  629. priv->dev = ddev;
  630. ret = sde_power_resource_init(pdev, &priv->phandle);
  631. if (ret) {
  632. pr_err("sde power resource init failed\n");
  633. goto power_init_fail;
  634. }
  635. ret = sde_dbg_init(&pdev->dev);
  636. if (ret) {
  637. dev_err(dev, "failed to init sde dbg: %d\n", ret);
  638. goto dbg_init_fail;
  639. }
  640. for (i = 0; i < SDE_POWER_HANDLE_DBUS_ID_MAX; i++)
  641. sde_power_data_bus_set_quota(&priv->phandle, i,
  642. SDE_POWER_HANDLE_CONT_SPLASH_BUS_AB_QUOTA,
  643. SDE_POWER_HANDLE_CONT_SPLASH_BUS_IB_QUOTA);
  644. return ret;
  645. dbg_init_fail:
  646. sde_power_resource_deinit(pdev, &priv->phandle);
  647. power_init_fail:
  648. priv_alloc_fail:
  649. drm_dev_put(ddev);
  650. kfree(priv);
  651. return ret;
  652. }
  653. static int msm_drm_component_init(struct device *dev)
  654. {
  655. struct platform_device *pdev = to_platform_device(dev);
  656. struct drm_device *ddev = platform_get_drvdata(pdev);
  657. struct msm_drm_private *priv = ddev->dev_private;
  658. struct msm_kms *kms = NULL;
  659. int ret;
  660. struct sched_param param = { 0 };
  661. struct drm_crtc *crtc;
  662. ret = msm_mdss_init(ddev);
  663. if (ret)
  664. goto mdss_init_fail;
  665. priv->wq = alloc_ordered_workqueue("msm_drm", 0);
  666. init_waitqueue_head(&priv->pending_crtcs_event);
  667. INIT_LIST_HEAD(&priv->client_event_list);
  668. INIT_LIST_HEAD(&priv->inactive_list);
  669. /* Bind all our sub-components: */
  670. ret = msm_component_bind_all(dev, ddev);
  671. if (ret)
  672. goto bind_fail;
  673. ret = msm_init_vram(ddev);
  674. if (ret)
  675. goto fail;
  676. ddev->mode_config.funcs = &mode_config_funcs;
  677. ddev->mode_config.helper_private = &mode_config_helper_funcs;
  678. kms = _msm_drm_component_init_helper(priv, ddev, dev, pdev);
  679. if (IS_ERR_OR_NULL(kms)) {
  680. dev_err(dev, "msm_drm_component_init_helper failed\n");
  681. goto fail;
  682. }
  683. ret = msm_drm_display_thread_create(param, priv, ddev, dev);
  684. if (ret) {
  685. dev_err(dev, "msm_drm_display_thread_create failed\n");
  686. goto fail;
  687. }
  688. ret = drm_vblank_init(ddev, priv->num_crtcs);
  689. if (ret < 0) {
  690. dev_err(dev, "failed to initialize vblank\n");
  691. goto fail;
  692. }
  693. drm_for_each_crtc(crtc, ddev)
  694. drm_crtc_vblank_reset(crtc);
  695. if (kms) {
  696. pm_runtime_get_sync(dev);
  697. ret = drm_irq_install(ddev, platform_get_irq(pdev, 0));
  698. pm_runtime_put_sync(dev);
  699. if (ret < 0) {
  700. dev_err(dev, "failed to install IRQ handler\n");
  701. goto fail;
  702. }
  703. }
  704. ret = drm_dev_register(ddev, 0);
  705. if (ret)
  706. goto fail;
  707. priv->registered = true;
  708. drm_mode_config_reset(ddev);
  709. if (kms && kms->funcs && kms->funcs->cont_splash_config) {
  710. ret = kms->funcs->cont_splash_config(kms);
  711. if (ret) {
  712. dev_err(dev, "kms cont_splash config failed.\n");
  713. goto fail;
  714. }
  715. }
  716. #ifdef CONFIG_DRM_FBDEV_EMULATION
  717. if (fbdev)
  718. priv->fbdev = msm_fbdev_init(ddev);
  719. #endif
  720. /* create drm client only when fbdev is not supported */
  721. if (!priv->fbdev) {
  722. ret = drm_client_init(ddev, &kms->client, "kms_client", NULL);
  723. if (ret) {
  724. DRM_ERROR("failed to init kms_client: %d\n", ret);
  725. kms->client.dev = NULL;
  726. goto fail;
  727. }
  728. drm_client_register(&kms->client);
  729. }
  730. ret = sde_dbg_debugfs_register(dev);
  731. if (ret) {
  732. dev_err(dev, "failed to reg sde dbg debugfs: %d\n", ret);
  733. goto fail;
  734. }
  735. /* perform subdriver post initialization */
  736. if (kms && kms->funcs && kms->funcs->postinit) {
  737. ret = kms->funcs->postinit(kms);
  738. if (ret) {
  739. pr_err("kms post init failed: %d\n", ret);
  740. goto fail;
  741. }
  742. }
  743. drm_kms_helper_poll_init(ddev);
  744. return 0;
  745. fail:
  746. msm_drm_uninit(dev);
  747. return ret;
  748. bind_fail:
  749. msm_mdss_destroy(ddev);
  750. mdss_init_fail:
  751. sde_dbg_destroy();
  752. sde_power_resource_deinit(pdev, &priv->phandle);
  753. drm_dev_put(ddev);
  754. kfree(priv);
  755. return ret;
  756. }
  757. /*
  758. * DRM operations:
  759. */
  760. static int context_init(struct drm_device *dev, struct drm_file *file)
  761. {
  762. struct msm_file_private *ctx;
  763. ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
  764. if (!ctx)
  765. return -ENOMEM;
  766. mutex_init(&ctx->power_lock);
  767. file->driver_priv = ctx;
  768. if (dev && dev->dev_private) {
  769. struct msm_drm_private *priv = dev->dev_private;
  770. struct msm_kms *kms;
  771. kms = priv->kms;
  772. if (kms && kms->funcs && kms->funcs->postopen)
  773. kms->funcs->postopen(kms, file);
  774. }
  775. return 0;
  776. }
  777. static int msm_open(struct drm_device *dev, struct drm_file *file)
  778. {
  779. return context_init(dev, file);
  780. }
  781. static void context_close(struct msm_file_private *ctx)
  782. {
  783. kfree(ctx);
  784. }
  785. static void msm_postclose(struct drm_device *dev, struct drm_file *file)
  786. {
  787. struct msm_drm_private *priv = dev->dev_private;
  788. struct msm_file_private *ctx = file->driver_priv;
  789. struct msm_kms *kms = priv->kms;
  790. if (kms && kms->funcs && kms->funcs->postclose)
  791. kms->funcs->postclose(kms, file);
  792. mutex_lock(&dev->struct_mutex);
  793. if (ctx == priv->lastctx)
  794. priv->lastctx = NULL;
  795. mutex_unlock(&dev->struct_mutex);
  796. mutex_lock(&ctx->power_lock);
  797. if (ctx->enable_refcnt) {
  798. SDE_EVT32(ctx->enable_refcnt);
  799. pm_runtime_put_sync(dev->dev);
  800. }
  801. mutex_unlock(&ctx->power_lock);
  802. context_close(ctx);
  803. }
  804. static void msm_lastclose(struct drm_device *dev)
  805. {
  806. struct msm_drm_private *priv = dev->dev_private;
  807. struct msm_kms *kms = priv->kms;
  808. int i, rc;
  809. /* check for splash status before triggering cleanup
  810. * if we end up here with splash status ON i.e before first
  811. * commit then ignore the last close call
  812. */
  813. if (kms && kms->funcs && kms->funcs->check_for_splash
  814. && kms->funcs->check_for_splash(kms))
  815. return;
  816. /*
  817. * clean up vblank disable immediately as this is the last close.
  818. */
  819. for (i = 0; i < dev->num_crtcs; i++) {
  820. struct drm_vblank_crtc *vblank = &dev->vblank[i];
  821. struct timer_list *disable_timer = &vblank->disable_timer;
  822. if (del_timer_sync(disable_timer))
  823. disable_timer->function(disable_timer);
  824. }
  825. /* wait for pending vblank requests to be executed by worker thread */
  826. flush_workqueue(priv->wq);
  827. if (priv->fbdev) {
  828. rc = drm_fb_helper_restore_fbdev_mode_unlocked(priv->fbdev);
  829. if (rc)
  830. DRM_ERROR("restore FBDEV mode failed: %d\n", rc);
  831. } else if (kms && kms->client.dev) {
  832. rc = drm_client_modeset_commit_force(&kms->client);
  833. if (rc)
  834. DRM_ERROR("client modeset commit failed: %d\n", rc);
  835. }
  836. if (kms && kms->funcs && kms->funcs->lastclose)
  837. kms->funcs->lastclose(kms);
  838. }
  839. static irqreturn_t msm_irq(int irq, void *arg)
  840. {
  841. struct drm_device *dev = arg;
  842. struct msm_drm_private *priv = dev->dev_private;
  843. struct msm_kms *kms = priv->kms;
  844. BUG_ON(!kms);
  845. return kms->funcs->irq(kms);
  846. }
  847. static void msm_irq_preinstall(struct drm_device *dev)
  848. {
  849. struct msm_drm_private *priv = dev->dev_private;
  850. struct msm_kms *kms = priv->kms;
  851. BUG_ON(!kms);
  852. kms->funcs->irq_preinstall(kms);
  853. }
  854. static int msm_irq_postinstall(struct drm_device *dev)
  855. {
  856. struct msm_drm_private *priv = dev->dev_private;
  857. struct msm_kms *kms = priv->kms;
  858. BUG_ON(!kms);
  859. if (kms->funcs->irq_postinstall)
  860. return kms->funcs->irq_postinstall(kms);
  861. return 0;
  862. }
  863. static void msm_irq_uninstall(struct drm_device *dev)
  864. {
  865. struct msm_drm_private *priv = dev->dev_private;
  866. struct msm_kms *kms = priv->kms;
  867. BUG_ON(!kms);
  868. kms->funcs->irq_uninstall(kms);
  869. }
  870. static int msm_enable_vblank(struct drm_device *dev, unsigned int pipe)
  871. {
  872. struct msm_drm_private *priv = dev->dev_private;
  873. struct msm_kms *kms = priv->kms;
  874. if (!kms)
  875. return -ENXIO;
  876. DBG("dev=%pK, crtc=%u", dev, pipe);
  877. return vblank_ctrl_queue_work(priv, pipe, true);
  878. }
  879. static void msm_disable_vblank(struct drm_device *dev, unsigned int pipe)
  880. {
  881. struct msm_drm_private *priv = dev->dev_private;
  882. struct msm_kms *kms = priv->kms;
  883. if (!kms)
  884. return;
  885. DBG("dev=%pK, crtc=%u", dev, pipe);
  886. vblank_ctrl_queue_work(priv, pipe, false);
  887. }
  888. /*
  889. * DRM ioctls:
  890. */
  891. static int msm_ioctl_gem_new(struct drm_device *dev, void *data,
  892. struct drm_file *file)
  893. {
  894. struct drm_msm_gem_new *args = data;
  895. if (args->flags & ~MSM_BO_FLAGS) {
  896. DRM_ERROR("invalid flags: %08x\n", args->flags);
  897. return -EINVAL;
  898. }
  899. return msm_gem_new_handle(dev, file, args->size,
  900. args->flags, &args->handle, NULL);
  901. }
  902. static inline ktime_t to_ktime(struct drm_msm_timespec timeout)
  903. {
  904. return ktime_set(timeout.tv_sec, timeout.tv_nsec);
  905. }
  906. static int msm_ioctl_gem_cpu_prep(struct drm_device *dev, void *data,
  907. struct drm_file *file)
  908. {
  909. struct drm_msm_gem_cpu_prep *args = data;
  910. struct drm_gem_object *obj;
  911. ktime_t timeout = to_ktime(args->timeout);
  912. int ret;
  913. if (args->op & ~MSM_PREP_FLAGS) {
  914. DRM_ERROR("invalid op: %08x\n", args->op);
  915. return -EINVAL;
  916. }
  917. obj = drm_gem_object_lookup(file, args->handle);
  918. if (!obj)
  919. return -ENOENT;
  920. ret = msm_gem_cpu_prep(obj, args->op, &timeout);
  921. drm_gem_object_put_unlocked(obj);
  922. return ret;
  923. }
  924. static int msm_ioctl_gem_cpu_fini(struct drm_device *dev, void *data,
  925. struct drm_file *file)
  926. {
  927. struct drm_msm_gem_cpu_fini *args = data;
  928. struct drm_gem_object *obj;
  929. int ret;
  930. obj = drm_gem_object_lookup(file, args->handle);
  931. if (!obj)
  932. return -ENOENT;
  933. ret = msm_gem_cpu_fini(obj);
  934. drm_gem_object_put_unlocked(obj);
  935. return ret;
  936. }
  937. static int msm_ioctl_gem_madvise(struct drm_device *dev, void *data,
  938. struct drm_file *file)
  939. {
  940. struct drm_msm_gem_madvise *args = data;
  941. struct drm_gem_object *obj;
  942. int ret;
  943. switch (args->madv) {
  944. case MSM_MADV_DONTNEED:
  945. case MSM_MADV_WILLNEED:
  946. break;
  947. default:
  948. return -EINVAL;
  949. }
  950. ret = mutex_lock_interruptible(&dev->struct_mutex);
  951. if (ret)
  952. return ret;
  953. obj = drm_gem_object_lookup(file, args->handle);
  954. if (!obj) {
  955. ret = -ENOENT;
  956. goto unlock;
  957. }
  958. ret = msm_gem_madvise(obj, args->madv);
  959. if (ret >= 0) {
  960. args->retained = ret;
  961. ret = 0;
  962. }
  963. drm_gem_object_put(obj);
  964. unlock:
  965. mutex_unlock(&dev->struct_mutex);
  966. return ret;
  967. }
  968. static int msm_drm_object_supports_event(struct drm_device *dev,
  969. struct drm_msm_event_req *req)
  970. {
  971. int ret = -EINVAL;
  972. struct drm_mode_object *arg_obj;
  973. arg_obj = drm_mode_object_find(dev, NULL, req->object_id,
  974. req->object_type);
  975. if (!arg_obj)
  976. return -ENOENT;
  977. switch (arg_obj->type) {
  978. case DRM_MODE_OBJECT_CRTC:
  979. case DRM_MODE_OBJECT_CONNECTOR:
  980. ret = 0;
  981. break;
  982. default:
  983. ret = -EOPNOTSUPP;
  984. break;
  985. }
  986. drm_mode_object_put(arg_obj);
  987. return ret;
  988. }
  989. static int msm_register_event(struct drm_device *dev,
  990. struct drm_msm_event_req *req, struct drm_file *file, bool en)
  991. {
  992. int ret = -EINVAL;
  993. struct msm_drm_private *priv = dev->dev_private;
  994. struct msm_kms *kms = priv->kms;
  995. struct drm_mode_object *arg_obj;
  996. arg_obj = drm_mode_object_find(dev, file, req->object_id,
  997. req->object_type);
  998. if (!arg_obj)
  999. return -ENOENT;
  1000. ret = kms->funcs->register_events(kms, arg_obj, req->event, en);
  1001. drm_mode_object_put(arg_obj);
  1002. return ret;
  1003. }
  1004. static int msm_event_client_count(struct drm_device *dev,
  1005. struct drm_msm_event_req *req_event, bool locked)
  1006. {
  1007. struct msm_drm_private *priv = dev->dev_private;
  1008. unsigned long flag = 0;
  1009. struct msm_drm_event *node;
  1010. int count = 0;
  1011. if (!locked)
  1012. spin_lock_irqsave(&dev->event_lock, flag);
  1013. list_for_each_entry(node, &priv->client_event_list, base.link) {
  1014. if (node->event.base.type == req_event->event &&
  1015. node->event.info.object_id == req_event->object_id)
  1016. count++;
  1017. }
  1018. if (!locked)
  1019. spin_unlock_irqrestore(&dev->event_lock, flag);
  1020. return count;
  1021. }
  1022. static int msm_ioctl_register_event(struct drm_device *dev, void *data,
  1023. struct drm_file *file)
  1024. {
  1025. struct msm_drm_private *priv = dev->dev_private;
  1026. struct drm_msm_event_req *req_event = data;
  1027. struct msm_drm_event *client, *node;
  1028. unsigned long flag = 0;
  1029. bool dup_request = false;
  1030. int ret = 0, count = 0;
  1031. ret = msm_drm_object_supports_event(dev, req_event);
  1032. if (ret) {
  1033. DRM_ERROR("unsupported event %x object %x object id %d\n",
  1034. req_event->event, req_event->object_type,
  1035. req_event->object_id);
  1036. return ret;
  1037. }
  1038. spin_lock_irqsave(&dev->event_lock, flag);
  1039. list_for_each_entry(node, &priv->client_event_list, base.link) {
  1040. if (node->base.file_priv != file)
  1041. continue;
  1042. if (node->event.base.type == req_event->event &&
  1043. node->event.info.object_id == req_event->object_id) {
  1044. DRM_DEBUG("duplicate request for event %x obj id %d\n",
  1045. node->event.base.type,
  1046. node->event.info.object_id);
  1047. dup_request = true;
  1048. break;
  1049. }
  1050. }
  1051. spin_unlock_irqrestore(&dev->event_lock, flag);
  1052. if (dup_request)
  1053. return -EALREADY;
  1054. client = kzalloc(sizeof(*client), GFP_KERNEL);
  1055. if (!client)
  1056. return -ENOMEM;
  1057. client->base.file_priv = file;
  1058. client->base.event = &client->event.base;
  1059. client->event.base.type = req_event->event;
  1060. memcpy(&client->event.info, req_event, sizeof(client->event.info));
  1061. /* Get the count of clients that have registered for event.
  1062. * Event should be enabled for first client, for subsequent enable
  1063. * calls add to client list and return.
  1064. */
  1065. count = msm_event_client_count(dev, req_event, false);
  1066. /* Add current client to list */
  1067. spin_lock_irqsave(&dev->event_lock, flag);
  1068. list_add_tail(&client->base.link, &priv->client_event_list);
  1069. spin_unlock_irqrestore(&dev->event_lock, flag);
  1070. if (count)
  1071. return 0;
  1072. ret = msm_register_event(dev, req_event, file, true);
  1073. if (ret) {
  1074. DRM_ERROR("failed to enable event %x object %x object id %d\n",
  1075. req_event->event, req_event->object_type,
  1076. req_event->object_id);
  1077. spin_lock_irqsave(&dev->event_lock, flag);
  1078. list_del(&client->base.link);
  1079. spin_unlock_irqrestore(&dev->event_lock, flag);
  1080. kfree(client);
  1081. }
  1082. return ret;
  1083. }
  1084. static int msm_ioctl_deregister_event(struct drm_device *dev, void *data,
  1085. struct drm_file *file)
  1086. {
  1087. struct msm_drm_private *priv = dev->dev_private;
  1088. struct drm_msm_event_req *req_event = data;
  1089. struct msm_drm_event *client = NULL, *node, *temp;
  1090. unsigned long flag = 0;
  1091. int count = 0;
  1092. bool found = false;
  1093. int ret = 0;
  1094. ret = msm_drm_object_supports_event(dev, req_event);
  1095. if (ret) {
  1096. DRM_ERROR("unsupported event %x object %x object id %d\n",
  1097. req_event->event, req_event->object_type,
  1098. req_event->object_id);
  1099. return ret;
  1100. }
  1101. spin_lock_irqsave(&dev->event_lock, flag);
  1102. list_for_each_entry_safe(node, temp, &priv->client_event_list,
  1103. base.link) {
  1104. if (node->event.base.type == req_event->event &&
  1105. node->event.info.object_id == req_event->object_id &&
  1106. node->base.file_priv == file) {
  1107. client = node;
  1108. list_del(&client->base.link);
  1109. found = true;
  1110. kfree(client);
  1111. break;
  1112. }
  1113. }
  1114. spin_unlock_irqrestore(&dev->event_lock, flag);
  1115. if (!found)
  1116. return -ENOENT;
  1117. count = msm_event_client_count(dev, req_event, false);
  1118. if (!count)
  1119. ret = msm_register_event(dev, req_event, file, false);
  1120. return ret;
  1121. }
  1122. void msm_mode_object_event_notify(struct drm_mode_object *obj,
  1123. struct drm_device *dev, struct drm_event *event, u8 *payload)
  1124. {
  1125. struct msm_drm_private *priv = NULL;
  1126. unsigned long flags;
  1127. struct msm_drm_event *notify, *node;
  1128. int len = 0, ret;
  1129. if (!obj || !event || !event->length || !payload) {
  1130. DRM_ERROR("err param obj %pK event %pK len %d payload %pK\n",
  1131. obj, event, ((event) ? (event->length) : -1),
  1132. payload);
  1133. return;
  1134. }
  1135. priv = (dev) ? dev->dev_private : NULL;
  1136. if (!dev || !priv) {
  1137. DRM_ERROR("invalid dev %pK priv %pK\n", dev, priv);
  1138. return;
  1139. }
  1140. spin_lock_irqsave(&dev->event_lock, flags);
  1141. list_for_each_entry(node, &priv->client_event_list, base.link) {
  1142. if (node->event.base.type != event->type ||
  1143. obj->id != node->event.info.object_id)
  1144. continue;
  1145. len = event->length + sizeof(struct msm_drm_event);
  1146. if (node->base.file_priv->event_space < len) {
  1147. DRM_ERROR("Insufficient space %d for event %x len %d\n",
  1148. node->base.file_priv->event_space, event->type,
  1149. len);
  1150. continue;
  1151. }
  1152. notify = kzalloc(len, GFP_ATOMIC);
  1153. if (!notify)
  1154. continue;
  1155. notify->base.file_priv = node->base.file_priv;
  1156. notify->base.event = &notify->event.base;
  1157. notify->event.base.type = node->event.base.type;
  1158. notify->event.base.length = event->length +
  1159. sizeof(struct drm_msm_event_resp);
  1160. memcpy(&notify->event.info, &node->event.info,
  1161. sizeof(notify->event.info));
  1162. memcpy(notify->event.data, payload, event->length);
  1163. ret = drm_event_reserve_init_locked(dev, node->base.file_priv,
  1164. &notify->base, &notify->event.base);
  1165. if (ret) {
  1166. kfree(notify);
  1167. continue;
  1168. }
  1169. drm_send_event_locked(dev, &notify->base);
  1170. }
  1171. spin_unlock_irqrestore(&dev->event_lock, flags);
  1172. }
  1173. static int msm_release(struct inode *inode, struct file *filp)
  1174. {
  1175. struct drm_file *file_priv = filp->private_data;
  1176. struct drm_minor *minor = file_priv->minor;
  1177. struct drm_device *dev = minor->dev;
  1178. struct msm_drm_private *priv = dev->dev_private;
  1179. struct msm_drm_event *node, *temp, *tmp_node;
  1180. u32 count;
  1181. unsigned long flags;
  1182. LIST_HEAD(tmp_head);
  1183. spin_lock_irqsave(&dev->event_lock, flags);
  1184. list_for_each_entry_safe(node, temp, &priv->client_event_list,
  1185. base.link) {
  1186. if (node->base.file_priv != file_priv)
  1187. continue;
  1188. list_del(&node->base.link);
  1189. list_add_tail(&node->base.link, &tmp_head);
  1190. }
  1191. spin_unlock_irqrestore(&dev->event_lock, flags);
  1192. list_for_each_entry_safe(node, temp, &tmp_head,
  1193. base.link) {
  1194. list_del(&node->base.link);
  1195. count = msm_event_client_count(dev, &node->event.info, false);
  1196. list_for_each_entry(tmp_node, &tmp_head, base.link) {
  1197. if (tmp_node->event.base.type ==
  1198. node->event.info.event &&
  1199. tmp_node->event.info.object_id ==
  1200. node->event.info.object_id)
  1201. count++;
  1202. }
  1203. if (!count)
  1204. msm_register_event(dev, &node->event.info, file_priv,
  1205. false);
  1206. kfree(node);
  1207. }
  1208. return drm_release(inode, filp);
  1209. }
  1210. /**
  1211. * msm_ioctl_rmfb2 - remove an FB from the configuration
  1212. * @dev: drm device for the ioctl
  1213. * @data: data pointer for the ioctl
  1214. * @file_priv: drm file for the ioctl call
  1215. *
  1216. * Remove the FB specified by the user.
  1217. *
  1218. * Called by the user via ioctl.
  1219. *
  1220. * Returns:
  1221. * Zero on success, negative errno on failure.
  1222. */
  1223. int msm_ioctl_rmfb2(struct drm_device *dev, void *data,
  1224. struct drm_file *file_priv)
  1225. {
  1226. struct drm_framebuffer *fb = NULL;
  1227. struct drm_framebuffer *fbl = NULL;
  1228. uint32_t *id = data;
  1229. int found = 0;
  1230. if (!drm_core_check_feature(dev, DRIVER_MODESET))
  1231. return -EINVAL;
  1232. fb = drm_framebuffer_lookup(dev, file_priv, *id);
  1233. if (!fb)
  1234. return -ENOENT;
  1235. /* drop extra ref from traversing drm_framebuffer_lookup */
  1236. drm_framebuffer_put(fb);
  1237. mutex_lock(&file_priv->fbs_lock);
  1238. list_for_each_entry(fbl, &file_priv->fbs, filp_head)
  1239. if (fb == fbl)
  1240. found = 1;
  1241. if (!found) {
  1242. mutex_unlock(&file_priv->fbs_lock);
  1243. return -ENOENT;
  1244. }
  1245. list_del_init(&fb->filp_head);
  1246. mutex_unlock(&file_priv->fbs_lock);
  1247. drm_framebuffer_put(fb);
  1248. return 0;
  1249. }
  1250. EXPORT_SYMBOL(msm_ioctl_rmfb2);
  1251. /**
  1252. * msm_ioctl_power_ctrl - enable/disable power vote on MDSS Hw
  1253. * @dev: drm device for the ioctl
  1254. * @data: data pointer for the ioctl
  1255. * @file_priv: drm file for the ioctl call
  1256. *
  1257. */
  1258. int msm_ioctl_power_ctrl(struct drm_device *dev, void *data,
  1259. struct drm_file *file_priv)
  1260. {
  1261. struct msm_file_private *ctx = file_priv->driver_priv;
  1262. struct msm_drm_private *priv;
  1263. struct drm_msm_power_ctrl *power_ctrl = data;
  1264. bool vote_req = false;
  1265. int old_cnt;
  1266. int rc = 0;
  1267. if (unlikely(!power_ctrl)) {
  1268. DRM_ERROR("invalid ioctl data\n");
  1269. return -EINVAL;
  1270. }
  1271. priv = dev->dev_private;
  1272. mutex_lock(&ctx->power_lock);
  1273. old_cnt = ctx->enable_refcnt;
  1274. if (power_ctrl->enable) {
  1275. if (!ctx->enable_refcnt)
  1276. vote_req = true;
  1277. ctx->enable_refcnt++;
  1278. } else if (ctx->enable_refcnt) {
  1279. ctx->enable_refcnt--;
  1280. if (!ctx->enable_refcnt)
  1281. vote_req = true;
  1282. } else {
  1283. pr_err("ignoring, unbalanced disable\n");
  1284. }
  1285. if (vote_req) {
  1286. if (power_ctrl->enable)
  1287. rc = pm_runtime_get_sync(dev->dev);
  1288. else
  1289. pm_runtime_put_sync(dev->dev);
  1290. if (rc < 0)
  1291. ctx->enable_refcnt = old_cnt;
  1292. else
  1293. rc = 0;
  1294. }
  1295. pr_debug("pid %d enable %d, refcnt %d, vote_req %d\n",
  1296. current->pid, power_ctrl->enable, ctx->enable_refcnt,
  1297. vote_req);
  1298. SDE_EVT32(current->pid, power_ctrl->enable, ctx->enable_refcnt,
  1299. vote_req);
  1300. mutex_unlock(&ctx->power_lock);
  1301. return rc;
  1302. }
  1303. static const struct drm_ioctl_desc msm_ioctls[] = {
  1304. DRM_IOCTL_DEF_DRV(MSM_GEM_NEW, msm_ioctl_gem_new, DRM_AUTH|DRM_RENDER_ALLOW),
  1305. DRM_IOCTL_DEF_DRV(MSM_GEM_CPU_PREP, msm_ioctl_gem_cpu_prep, DRM_AUTH|DRM_RENDER_ALLOW),
  1306. DRM_IOCTL_DEF_DRV(MSM_GEM_CPU_FINI, msm_ioctl_gem_cpu_fini, DRM_AUTH|DRM_RENDER_ALLOW),
  1307. DRM_IOCTL_DEF_DRV(MSM_GEM_MADVISE, msm_ioctl_gem_madvise, DRM_AUTH|DRM_RENDER_ALLOW),
  1308. DRM_IOCTL_DEF_DRV(SDE_WB_CONFIG, sde_wb_config, DRM_UNLOCKED|DRM_AUTH),
  1309. DRM_IOCTL_DEF_DRV(MSM_REGISTER_EVENT, msm_ioctl_register_event,
  1310. DRM_UNLOCKED),
  1311. DRM_IOCTL_DEF_DRV(MSM_DEREGISTER_EVENT, msm_ioctl_deregister_event,
  1312. DRM_UNLOCKED),
  1313. DRM_IOCTL_DEF_DRV(MSM_RMFB2, msm_ioctl_rmfb2, DRM_UNLOCKED),
  1314. DRM_IOCTL_DEF_DRV(MSM_POWER_CTRL, msm_ioctl_power_ctrl,
  1315. DRM_RENDER_ALLOW),
  1316. };
  1317. static const struct vm_operations_struct vm_ops = {
  1318. .fault = msm_gem_fault,
  1319. .open = drm_gem_vm_open,
  1320. .close = drm_gem_vm_close,
  1321. };
  1322. static const struct file_operations fops = {
  1323. .owner = THIS_MODULE,
  1324. .open = drm_open,
  1325. .release = msm_release,
  1326. .unlocked_ioctl = drm_ioctl,
  1327. .compat_ioctl = drm_compat_ioctl,
  1328. .poll = drm_poll,
  1329. .read = drm_read,
  1330. .llseek = no_llseek,
  1331. .mmap = msm_gem_mmap,
  1332. };
  1333. static struct drm_driver msm_driver = {
  1334. .driver_features = DRIVER_GEM |
  1335. DRIVER_RENDER |
  1336. DRIVER_ATOMIC |
  1337. DRIVER_MODESET,
  1338. .open = msm_open,
  1339. .postclose = msm_postclose,
  1340. .lastclose = msm_lastclose,
  1341. .irq_handler = msm_irq,
  1342. .irq_preinstall = msm_irq_preinstall,
  1343. .irq_postinstall = msm_irq_postinstall,
  1344. .irq_uninstall = msm_irq_uninstall,
  1345. .enable_vblank = msm_enable_vblank,
  1346. .disable_vblank = msm_disable_vblank,
  1347. .gem_free_object = msm_gem_free_object,
  1348. .gem_vm_ops = &vm_ops,
  1349. .dumb_create = msm_gem_dumb_create,
  1350. .dumb_map_offset = msm_gem_dumb_map_offset,
  1351. .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
  1352. .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
  1353. .gem_prime_export = drm_gem_prime_export,
  1354. .gem_prime_import = msm_gem_prime_import,
  1355. .gem_prime_pin = msm_gem_prime_pin,
  1356. .gem_prime_unpin = msm_gem_prime_unpin,
  1357. .gem_prime_get_sg_table = msm_gem_prime_get_sg_table,
  1358. .gem_prime_import_sg_table = msm_gem_prime_import_sg_table,
  1359. .gem_prime_vmap = msm_gem_prime_vmap,
  1360. .gem_prime_vunmap = msm_gem_prime_vunmap,
  1361. .gem_prime_mmap = msm_gem_prime_mmap,
  1362. .ioctls = msm_ioctls,
  1363. .num_ioctls = ARRAY_SIZE(msm_ioctls),
  1364. .fops = &fops,
  1365. .name = "msm_drm",
  1366. .desc = "MSM Snapdragon DRM",
  1367. .date = "20130625",
  1368. .major = MSM_VERSION_MAJOR,
  1369. .minor = MSM_VERSION_MINOR,
  1370. .patchlevel = MSM_VERSION_PATCHLEVEL,
  1371. };
  1372. #ifdef CONFIG_PM_SLEEP
  1373. static int msm_pm_suspend(struct device *dev)
  1374. {
  1375. struct drm_device *ddev;
  1376. struct msm_drm_private *priv;
  1377. struct msm_kms *kms;
  1378. if (!dev)
  1379. return -EINVAL;
  1380. ddev = dev_get_drvdata(dev);
  1381. if (!ddev || !ddev->dev_private)
  1382. return -EINVAL;
  1383. priv = ddev->dev_private;
  1384. kms = priv->kms;
  1385. if (kms && kms->funcs && kms->funcs->pm_suspend)
  1386. return kms->funcs->pm_suspend(dev);
  1387. /* disable hot-plug polling */
  1388. drm_kms_helper_poll_disable(ddev);
  1389. return 0;
  1390. }
  1391. static int msm_pm_resume(struct device *dev)
  1392. {
  1393. struct drm_device *ddev;
  1394. struct msm_drm_private *priv;
  1395. struct msm_kms *kms;
  1396. if (!dev)
  1397. return -EINVAL;
  1398. ddev = dev_get_drvdata(dev);
  1399. if (!ddev || !ddev->dev_private)
  1400. return -EINVAL;
  1401. priv = ddev->dev_private;
  1402. kms = priv->kms;
  1403. if (kms && kms->funcs && kms->funcs->pm_resume)
  1404. return kms->funcs->pm_resume(dev);
  1405. /* enable hot-plug polling */
  1406. drm_kms_helper_poll_enable(ddev);
  1407. return 0;
  1408. }
  1409. #endif
  1410. #ifdef CONFIG_PM
  1411. static int msm_runtime_suspend(struct device *dev)
  1412. {
  1413. struct drm_device *ddev = dev_get_drvdata(dev);
  1414. struct msm_drm_private *priv = ddev->dev_private;
  1415. DBG("");
  1416. if (priv->mdss)
  1417. msm_mdss_disable(priv->mdss);
  1418. else
  1419. sde_power_resource_enable(&priv->phandle, false);
  1420. return 0;
  1421. }
  1422. static int msm_runtime_resume(struct device *dev)
  1423. {
  1424. struct drm_device *ddev = dev_get_drvdata(dev);
  1425. struct msm_drm_private *priv = ddev->dev_private;
  1426. int ret;
  1427. DBG("");
  1428. if (priv->mdss)
  1429. ret = msm_mdss_enable(priv->mdss);
  1430. else
  1431. ret = sde_power_resource_enable(&priv->phandle, true);
  1432. return ret;
  1433. }
  1434. #endif
  1435. static const struct dev_pm_ops msm_pm_ops = {
  1436. SET_SYSTEM_SLEEP_PM_OPS(msm_pm_suspend, msm_pm_resume)
  1437. SET_RUNTIME_PM_OPS(msm_runtime_suspend, msm_runtime_resume, NULL)
  1438. };
  1439. /*
  1440. * Componentized driver support:
  1441. */
  1442. /*
  1443. * NOTE: duplication of the same code as exynos or imx (or probably any other).
  1444. * so probably some room for some helpers
  1445. */
  1446. static int compare_of(struct device *dev, void *data)
  1447. {
  1448. return dev->of_node == data;
  1449. }
  1450. /*
  1451. * Identify what components need to be added by parsing what remote-endpoints
  1452. * our MDP output ports are connected to. In the case of LVDS on MDP4, there
  1453. * is no external component that we need to add since LVDS is within MDP4
  1454. * itself.
  1455. */
  1456. static int add_components_mdp(struct device *mdp_dev,
  1457. struct component_match **matchptr)
  1458. {
  1459. struct device_node *np = mdp_dev->of_node;
  1460. struct device_node *ep_node;
  1461. struct device *master_dev;
  1462. /*
  1463. * on MDP4 based platforms, the MDP platform device is the component
  1464. * master that adds other display interface components to itself.
  1465. *
  1466. * on MDP5 based platforms, the MDSS platform device is the component
  1467. * master that adds MDP5 and other display interface components to
  1468. * itself.
  1469. */
  1470. if (of_device_is_compatible(np, "qcom,mdp4"))
  1471. master_dev = mdp_dev;
  1472. else
  1473. master_dev = mdp_dev->parent;
  1474. for_each_endpoint_of_node(np, ep_node) {
  1475. struct device_node *intf;
  1476. struct of_endpoint ep;
  1477. int ret;
  1478. ret = of_graph_parse_endpoint(ep_node, &ep);
  1479. if (ret) {
  1480. dev_err(mdp_dev, "unable to parse port endpoint\n");
  1481. of_node_put(ep_node);
  1482. return ret;
  1483. }
  1484. /*
  1485. * The LCDC/LVDS port on MDP4 is a speacial case where the
  1486. * remote-endpoint isn't a component that we need to add
  1487. */
  1488. if (of_device_is_compatible(np, "qcom,mdp4") &&
  1489. ep.port == 0)
  1490. continue;
  1491. /*
  1492. * It's okay if some of the ports don't have a remote endpoint
  1493. * specified. It just means that the port isn't connected to
  1494. * any external interface.
  1495. */
  1496. intf = of_graph_get_remote_port_parent(ep_node);
  1497. if (!intf)
  1498. continue;
  1499. if (of_device_is_available(intf))
  1500. drm_of_component_match_add(master_dev, matchptr,
  1501. compare_of, intf);
  1502. of_node_put(intf);
  1503. }
  1504. return 0;
  1505. }
  1506. static int compare_name_mdp(struct device *dev, void *data)
  1507. {
  1508. return (strnstr(dev_name(dev), "mdp", strlen("mdp")) != NULL);
  1509. }
  1510. static int add_display_components(struct device *dev,
  1511. struct component_match **matchptr)
  1512. {
  1513. struct device *mdp_dev = NULL;
  1514. struct device_node *node;
  1515. int ret;
  1516. if (of_device_is_compatible(dev->of_node, "qcom,sde-kms")) {
  1517. struct device_node *np = dev->of_node;
  1518. unsigned int i;
  1519. for (i = 0; ; i++) {
  1520. node = of_parse_phandle(np, "connectors", i);
  1521. if (!node)
  1522. break;
  1523. component_match_add(dev, matchptr, compare_of, node);
  1524. }
  1525. return 0;
  1526. }
  1527. /*
  1528. * MDP5 based devices don't have a flat hierarchy. There is a top level
  1529. * parent: MDSS, and children: MDP5, DSI, HDMI, eDP etc. Populate the
  1530. * children devices, find the MDP5 node, and then add the interfaces
  1531. * to our components list.
  1532. */
  1533. if (of_device_is_compatible(dev->of_node, "qcom,mdss")) {
  1534. ret = of_platform_populate(dev->of_node, NULL, NULL, dev);
  1535. if (ret) {
  1536. dev_err(dev, "failed to populate children devices\n");
  1537. return ret;
  1538. }
  1539. mdp_dev = device_find_child(dev, NULL, compare_name_mdp);
  1540. if (!mdp_dev) {
  1541. dev_err(dev, "failed to find MDSS MDP node\n");
  1542. of_platform_depopulate(dev);
  1543. return -ENODEV;
  1544. }
  1545. put_device(mdp_dev);
  1546. /* add the MDP component itself */
  1547. component_match_add(dev, matchptr, compare_of,
  1548. mdp_dev->of_node);
  1549. } else {
  1550. /* MDP4 */
  1551. mdp_dev = dev;
  1552. }
  1553. ret = add_components_mdp(mdp_dev, matchptr);
  1554. if (ret)
  1555. of_platform_depopulate(dev);
  1556. return ret;
  1557. }
  1558. struct msm_gem_address_space *
  1559. msm_gem_smmu_address_space_get(struct drm_device *dev,
  1560. unsigned int domain)
  1561. {
  1562. struct msm_drm_private *priv = NULL;
  1563. struct msm_kms *kms;
  1564. const struct msm_kms_funcs *funcs;
  1565. if ((!dev) || (!dev->dev_private))
  1566. return NULL;
  1567. priv = dev->dev_private;
  1568. kms = priv->kms;
  1569. if (!kms)
  1570. return NULL;
  1571. funcs = kms->funcs;
  1572. if ((!funcs) || (!funcs->get_address_space))
  1573. return NULL;
  1574. return funcs->get_address_space(priv->kms, domain);
  1575. }
  1576. int msm_get_mixer_count(struct msm_drm_private *priv,
  1577. const struct drm_display_mode *mode,
  1578. const struct msm_resource_caps_info *res, u32 *num_lm)
  1579. {
  1580. struct msm_kms *kms;
  1581. const struct msm_kms_funcs *funcs;
  1582. if (!priv) {
  1583. DRM_ERROR("invalid drm private struct\n");
  1584. return -EINVAL;
  1585. }
  1586. kms = priv->kms;
  1587. if (!kms) {
  1588. DRM_ERROR("invalid msm kms struct\n");
  1589. return -EINVAL;
  1590. }
  1591. funcs = kms->funcs;
  1592. if (!funcs || !funcs->get_mixer_count) {
  1593. DRM_ERROR("invalid function pointers\n");
  1594. return -EINVAL;
  1595. }
  1596. return funcs->get_mixer_count(priv->kms, mode, res, num_lm);
  1597. }
  1598. static int msm_drm_bind(struct device *dev)
  1599. {
  1600. return msm_drm_component_init(dev);
  1601. }
  1602. static void msm_drm_unbind(struct device *dev)
  1603. {
  1604. msm_drm_uninit(dev);
  1605. }
  1606. static const struct component_master_ops msm_drm_ops = {
  1607. .bind = msm_drm_bind,
  1608. .unbind = msm_drm_unbind,
  1609. };
  1610. /*
  1611. * Platform driver:
  1612. */
  1613. static int msm_pdev_probe(struct platform_device *pdev)
  1614. {
  1615. int ret;
  1616. struct component_match *match = NULL;
  1617. ret = msm_drm_device_init(pdev, &msm_driver);
  1618. if (ret)
  1619. return ret;
  1620. ret = add_display_components(&pdev->dev, &match);
  1621. if (ret)
  1622. return ret;
  1623. if (!match)
  1624. return -ENODEV;
  1625. pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
  1626. return component_master_add_with_match(&pdev->dev, &msm_drm_ops, match);
  1627. }
  1628. static int msm_pdev_remove(struct platform_device *pdev)
  1629. {
  1630. component_master_del(&pdev->dev, &msm_drm_ops);
  1631. of_platform_depopulate(&pdev->dev);
  1632. msm_drm_unbind(&pdev->dev);
  1633. component_master_del(&pdev->dev, &msm_drm_ops);
  1634. return 0;
  1635. }
  1636. static void msm_pdev_shutdown(struct platform_device *pdev)
  1637. {
  1638. struct drm_device *ddev = platform_get_drvdata(pdev);
  1639. struct msm_drm_private *priv = NULL;
  1640. if (!ddev) {
  1641. DRM_ERROR("invalid drm device node\n");
  1642. return;
  1643. }
  1644. priv = ddev->dev_private;
  1645. if (!priv) {
  1646. DRM_ERROR("invalid msm drm private node\n");
  1647. return;
  1648. }
  1649. msm_lastclose(ddev);
  1650. /* set this after lastclose to allow kickoff from lastclose */
  1651. priv->shutdown_in_progress = true;
  1652. }
  1653. static const struct of_device_id dt_match[] = {
  1654. { .compatible = "qcom,mdp4", .data = (void *)KMS_MDP4 },
  1655. { .compatible = "qcom,mdss", .data = (void *)KMS_MDP5 },
  1656. { .compatible = "qcom,sde-kms", .data = (void *)KMS_SDE },
  1657. {},
  1658. };
  1659. MODULE_DEVICE_TABLE(of, dt_match);
  1660. static struct platform_driver msm_platform_driver = {
  1661. .probe = msm_pdev_probe,
  1662. .remove = msm_pdev_remove,
  1663. .shutdown = msm_pdev_shutdown,
  1664. .driver = {
  1665. .name = "msm_drm",
  1666. .of_match_table = dt_match,
  1667. .pm = &msm_pm_ops,
  1668. .suppress_bind_attrs = true,
  1669. },
  1670. };
  1671. static int __init msm_drm_register(void)
  1672. {
  1673. if (!modeset)
  1674. return -EINVAL;
  1675. DBG("init");
  1676. msm_smmu_driver_init();
  1677. msm_dsi_register();
  1678. msm_edp_register();
  1679. msm_hdmi_register();
  1680. return platform_driver_register(&msm_platform_driver);
  1681. }
  1682. static void __exit msm_drm_unregister(void)
  1683. {
  1684. DBG("fini");
  1685. platform_driver_unregister(&msm_platform_driver);
  1686. msm_hdmi_unregister();
  1687. msm_edp_unregister();
  1688. msm_dsi_unregister();
  1689. msm_smmu_driver_cleanup();
  1690. }
  1691. module_init(msm_drm_register);
  1692. module_exit(msm_drm_unregister);
  1693. MODULE_AUTHOR("Rob Clark <[email protected]");
  1694. MODULE_DESCRIPTION("MSM DRM Driver");
  1695. MODULE_LICENSE("GPL");