msm_drv.c 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988
  1. /*
  2. * Copyright (c) 2016-2019, 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. struct vblank_work {
  252. struct kthread_work work;
  253. int crtc_id;
  254. bool enable;
  255. struct msm_drm_private *priv;
  256. };
  257. static void vblank_ctrl_worker(struct kthread_work *work)
  258. {
  259. struct vblank_work *cur_work = container_of(work,
  260. struct vblank_work, work);
  261. struct msm_drm_private *priv = cur_work->priv;
  262. struct msm_kms *kms = priv->kms;
  263. if (cur_work->enable)
  264. kms->funcs->enable_vblank(kms, priv->crtcs[cur_work->crtc_id]);
  265. else
  266. kms->funcs->disable_vblank(kms, priv->crtcs[cur_work->crtc_id]);
  267. kfree(cur_work);
  268. }
  269. static int vblank_ctrl_queue_work(struct msm_drm_private *priv,
  270. int crtc_id, bool enable)
  271. {
  272. struct vblank_work *cur_work;
  273. if (!priv || crtc_id >= priv->num_crtcs)
  274. return -EINVAL;
  275. cur_work = kzalloc(sizeof(*cur_work), GFP_ATOMIC);
  276. if (!cur_work)
  277. return -ENOMEM;
  278. kthread_init_work(&cur_work->work, vblank_ctrl_worker);
  279. cur_work->crtc_id = crtc_id;
  280. cur_work->enable = enable;
  281. cur_work->priv = priv;
  282. kthread_queue_work(&priv->disp_thread[crtc_id].worker, &cur_work->work);
  283. return 0;
  284. }
  285. static int msm_drm_uninit(struct device *dev)
  286. {
  287. struct platform_device *pdev = to_platform_device(dev);
  288. struct drm_device *ddev = platform_get_drvdata(pdev);
  289. struct msm_drm_private *priv = ddev->dev_private;
  290. struct msm_kms *kms = priv->kms;
  291. int i;
  292. /* We must cancel and cleanup any pending vblank enable/disable
  293. * work before drm_irq_uninstall() to avoid work re-enabling an
  294. * irq after uninstall has disabled it.
  295. */
  296. flush_workqueue(priv->wq);
  297. destroy_workqueue(priv->wq);
  298. /* clean up display commit/event worker threads */
  299. for (i = 0; i < priv->num_crtcs; i++) {
  300. if (priv->disp_thread[i].thread) {
  301. kthread_flush_worker(&priv->disp_thread[i].worker);
  302. kthread_stop(priv->disp_thread[i].thread);
  303. priv->disp_thread[i].thread = NULL;
  304. }
  305. if (priv->event_thread[i].thread) {
  306. kthread_flush_worker(&priv->event_thread[i].worker);
  307. kthread_stop(priv->event_thread[i].thread);
  308. priv->event_thread[i].thread = NULL;
  309. }
  310. }
  311. drm_kms_helper_poll_fini(ddev);
  312. drm_mode_config_cleanup(ddev);
  313. if (priv->registered) {
  314. drm_dev_unregister(ddev);
  315. priv->registered = false;
  316. }
  317. #ifdef CONFIG_DRM_FBDEV_EMULATION
  318. if (fbdev && priv->fbdev)
  319. msm_fbdev_free(ddev);
  320. #endif
  321. drm_atomic_helper_shutdown(ddev);
  322. drm_mode_config_cleanup(ddev);
  323. pm_runtime_get_sync(dev);
  324. drm_irq_uninstall(ddev);
  325. pm_runtime_put_sync(dev);
  326. if (kms && kms->funcs)
  327. kms->funcs->destroy(kms);
  328. if (priv->vram.paddr) {
  329. unsigned long attrs = DMA_ATTR_NO_KERNEL_MAPPING;
  330. drm_mm_takedown(&priv->vram.mm);
  331. dma_free_attrs(dev, priv->vram.size, NULL,
  332. priv->vram.paddr, attrs);
  333. }
  334. component_unbind_all(dev, ddev);
  335. sde_dbg_destroy();
  336. debugfs_remove_recursive(priv->debug_root);
  337. sde_power_resource_deinit(pdev, &priv->phandle);
  338. msm_mdss_destroy(ddev);
  339. ddev->dev_private = NULL;
  340. kfree(priv);
  341. drm_dev_put(ddev);
  342. return 0;
  343. }
  344. #define KMS_MDP4 4
  345. #define KMS_MDP5 5
  346. #define KMS_SDE 3
  347. static int get_mdp_ver(struct platform_device *pdev)
  348. {
  349. #ifdef CONFIG_OF
  350. static const struct of_device_id match_types[] = { {
  351. .compatible = "qcom,mdss_mdp",
  352. .data = (void *)KMS_MDP5,
  353. },
  354. {
  355. .compatible = "qcom,sde-kms",
  356. .data = (void *)KMS_SDE,
  357. },
  358. {},
  359. };
  360. struct device *dev = &pdev->dev;
  361. const struct of_device_id *match;
  362. match = of_match_node(match_types, dev->of_node);
  363. if (match)
  364. return (int)(unsigned long)match->data;
  365. #endif
  366. return KMS_MDP4;
  367. }
  368. static int msm_init_vram(struct drm_device *dev)
  369. {
  370. struct msm_drm_private *priv = dev->dev_private;
  371. struct device_node *node;
  372. unsigned long size = 0;
  373. int ret = 0;
  374. /* In the device-tree world, we could have a 'memory-region'
  375. * phandle, which gives us a link to our "vram". Allocating
  376. * is all nicely abstracted behind the dma api, but we need
  377. * to know the entire size to allocate it all in one go. There
  378. * are two cases:
  379. * 1) device with no IOMMU, in which case we need exclusive
  380. * access to a VRAM carveout big enough for all gpu
  381. * buffers
  382. * 2) device with IOMMU, but where the bootloader puts up
  383. * a splash screen. In this case, the VRAM carveout
  384. * need only be large enough for fbdev fb. But we need
  385. * exclusive access to the buffer to avoid the kernel
  386. * using those pages for other purposes (which appears
  387. * as corruption on screen before we have a chance to
  388. * load and do initial modeset)
  389. */
  390. node = of_parse_phandle(dev->dev->of_node, "memory-region", 0);
  391. if (node) {
  392. struct resource r;
  393. ret = of_address_to_resource(node, 0, &r);
  394. of_node_put(node);
  395. if (ret)
  396. return ret;
  397. size = r.end - r.start;
  398. DRM_INFO("using VRAM carveout: %lx@%pa\n", size, &r.start);
  399. /* if we have no IOMMU, then we need to use carveout allocator.
  400. * Grab the entire CMA chunk carved out in early startup in
  401. * mach-msm:
  402. */
  403. } else if (!iommu_present(&platform_bus_type)) {
  404. DRM_INFO("using %s VRAM carveout\n", vram);
  405. size = memparse(vram, NULL);
  406. }
  407. if (size) {
  408. unsigned long attrs = 0;
  409. void *p;
  410. priv->vram.size = size;
  411. drm_mm_init(&priv->vram.mm, 0, (size >> PAGE_SHIFT) - 1);
  412. spin_lock_init(&priv->vram.lock);
  413. attrs |= DMA_ATTR_NO_KERNEL_MAPPING;
  414. attrs |= DMA_ATTR_WRITE_COMBINE;
  415. /* note that for no-kernel-mapping, the vaddr returned
  416. * is bogus, but non-null if allocation succeeded:
  417. */
  418. p = dma_alloc_attrs(dev->dev, size,
  419. &priv->vram.paddr, GFP_KERNEL, attrs);
  420. if (!p) {
  421. dev_err(dev->dev, "failed to allocate VRAM\n");
  422. priv->vram.paddr = 0;
  423. return -ENOMEM;
  424. }
  425. dev_info(dev->dev, "VRAM: %08x->%08x\n",
  426. (uint32_t)priv->vram.paddr,
  427. (uint32_t)(priv->vram.paddr + size));
  428. }
  429. return ret;
  430. }
  431. #ifdef CONFIG_OF
  432. static int msm_component_bind_all(struct device *dev,
  433. struct drm_device *drm_dev)
  434. {
  435. int ret;
  436. ret = component_bind_all(dev, drm_dev);
  437. if (ret)
  438. DRM_ERROR("component_bind_all failed: %d\n", ret);
  439. return ret;
  440. }
  441. #else
  442. static int msm_component_bind_all(struct device *dev,
  443. struct drm_device *drm_dev)
  444. {
  445. return 0;
  446. }
  447. #endif
  448. static int msm_drm_display_thread_create(struct sched_param param,
  449. struct msm_drm_private *priv, struct drm_device *ddev,
  450. struct device *dev)
  451. {
  452. int i, ret = 0;
  453. /**
  454. * this priority was found during empiric testing to have appropriate
  455. * realtime scheduling to process display updates and interact with
  456. * other real time and normal priority task
  457. */
  458. param.sched_priority = 16;
  459. for (i = 0; i < priv->num_crtcs; i++) {
  460. /* initialize display thread */
  461. priv->disp_thread[i].crtc_id = priv->crtcs[i]->base.id;
  462. kthread_init_worker(&priv->disp_thread[i].worker);
  463. priv->disp_thread[i].dev = ddev;
  464. priv->disp_thread[i].thread =
  465. kthread_run(kthread_worker_fn,
  466. &priv->disp_thread[i].worker,
  467. "crtc_commit:%d", priv->disp_thread[i].crtc_id);
  468. ret = sched_setscheduler(priv->disp_thread[i].thread,
  469. SCHED_FIFO, &param);
  470. if (ret)
  471. pr_warn("display thread priority update failed: %d\n",
  472. ret);
  473. if (IS_ERR(priv->disp_thread[i].thread)) {
  474. dev_err(dev, "failed to create crtc_commit kthread\n");
  475. priv->disp_thread[i].thread = NULL;
  476. }
  477. /* initialize event thread */
  478. priv->event_thread[i].crtc_id = priv->crtcs[i]->base.id;
  479. kthread_init_worker(&priv->event_thread[i].worker);
  480. priv->event_thread[i].dev = ddev;
  481. priv->event_thread[i].thread =
  482. kthread_run(kthread_worker_fn,
  483. &priv->event_thread[i].worker,
  484. "crtc_event:%d", priv->event_thread[i].crtc_id);
  485. /**
  486. * event thread should also run at same priority as disp_thread
  487. * because it is handling frame_done events. A lower priority
  488. * event thread and higher priority disp_thread can causes
  489. * frame_pending counters beyond 2. This can lead to commit
  490. * failure at crtc commit level.
  491. */
  492. ret = sched_setscheduler(priv->event_thread[i].thread,
  493. SCHED_FIFO, &param);
  494. if (ret)
  495. pr_warn("display event thread priority update failed: %d\n",
  496. ret);
  497. if (IS_ERR(priv->event_thread[i].thread)) {
  498. dev_err(dev, "failed to create crtc_event kthread\n");
  499. priv->event_thread[i].thread = NULL;
  500. }
  501. if ((!priv->disp_thread[i].thread) ||
  502. !priv->event_thread[i].thread) {
  503. /* clean up previously created threads if any */
  504. for ( ; i >= 0; i--) {
  505. if (priv->disp_thread[i].thread) {
  506. kthread_stop(
  507. priv->disp_thread[i].thread);
  508. priv->disp_thread[i].thread = NULL;
  509. }
  510. if (priv->event_thread[i].thread) {
  511. kthread_stop(
  512. priv->event_thread[i].thread);
  513. priv->event_thread[i].thread = NULL;
  514. }
  515. }
  516. return -EINVAL;
  517. }
  518. }
  519. /**
  520. * Since pp interrupt is heavy weight, try to queue the work
  521. * into a dedicated worker thread, so that they dont interrupt
  522. * other important events.
  523. */
  524. kthread_init_worker(&priv->pp_event_worker);
  525. priv->pp_event_thread = kthread_run(kthread_worker_fn,
  526. &priv->pp_event_worker, "pp_event");
  527. ret = sched_setscheduler(priv->pp_event_thread,
  528. SCHED_FIFO, &param);
  529. if (ret)
  530. pr_warn("pp_event thread priority update failed: %d\n",
  531. ret);
  532. if (IS_ERR(priv->pp_event_thread)) {
  533. dev_err(dev, "failed to create pp_event kthread\n");
  534. ret = PTR_ERR(priv->pp_event_thread);
  535. priv->pp_event_thread = NULL;
  536. return ret;
  537. }
  538. return 0;
  539. }
  540. static struct msm_kms *_msm_drm_init_helper(struct msm_drm_private *priv,
  541. struct drm_device *ddev, struct device *dev,
  542. struct platform_device *pdev)
  543. {
  544. int ret;
  545. struct msm_kms *kms;
  546. switch (get_mdp_ver(pdev)) {
  547. case KMS_MDP4:
  548. kms = mdp4_kms_init(ddev);
  549. break;
  550. case KMS_MDP5:
  551. kms = mdp5_kms_init(ddev);
  552. break;
  553. case KMS_SDE:
  554. kms = sde_kms_init(ddev);
  555. break;
  556. default:
  557. kms = ERR_PTR(-ENODEV);
  558. break;
  559. }
  560. if (IS_ERR_OR_NULL(kms)) {
  561. /*
  562. * NOTE: once we have GPU support, having no kms should not
  563. * be considered fatal.. ideally we would still support gpu
  564. * and (for example) use dmabuf/prime to share buffers with
  565. * imx drm driver on iMX5
  566. */
  567. dev_err(dev, "failed to load kms\n");
  568. return kms;
  569. }
  570. priv->kms = kms;
  571. pm_runtime_enable(dev);
  572. /**
  573. * Since kms->funcs->hw_init(kms) might call
  574. * drm_object_property_set_value to initialize some custom
  575. * properties we need to make sure mode_config.funcs are populated
  576. * beforehand to avoid dereferencing an unset value during the
  577. * drm_drv_uses_atomic_modeset check.
  578. */
  579. ddev->mode_config.funcs = &mode_config_funcs;
  580. ret = (kms)->funcs->hw_init(kms);
  581. if (ret) {
  582. dev_err(dev, "kms hw init failed: %d\n", ret);
  583. return ERR_PTR(ret);
  584. }
  585. return kms;
  586. }
  587. static int msm_drm_init(struct device *dev, struct drm_driver *drv)
  588. {
  589. struct platform_device *pdev = to_platform_device(dev);
  590. struct drm_device *ddev;
  591. struct msm_drm_private *priv;
  592. struct msm_kms *kms = NULL;
  593. int ret;
  594. struct sched_param param = { 0 };
  595. struct drm_crtc *crtc;
  596. ddev = drm_dev_alloc(drv, dev);
  597. if (IS_ERR(ddev)) {
  598. dev_err(dev, "failed to allocate drm_device\n");
  599. return PTR_ERR(ddev);
  600. }
  601. drm_mode_config_init(ddev);
  602. platform_set_drvdata(pdev, ddev);
  603. priv = kzalloc(sizeof(*priv), GFP_KERNEL);
  604. if (!priv) {
  605. ret = -ENOMEM;
  606. goto priv_alloc_fail;
  607. }
  608. ddev->dev_private = priv;
  609. priv->dev = ddev;
  610. ret = msm_mdss_init(ddev);
  611. if (ret)
  612. goto mdss_init_fail;
  613. priv->wq = alloc_ordered_workqueue("msm_drm", 0);
  614. init_waitqueue_head(&priv->pending_crtcs_event);
  615. INIT_LIST_HEAD(&priv->client_event_list);
  616. INIT_LIST_HEAD(&priv->inactive_list);
  617. ret = sde_power_resource_init(pdev, &priv->phandle);
  618. if (ret) {
  619. pr_err("sde power resource init failed\n");
  620. goto power_init_fail;
  621. }
  622. ret = sde_dbg_init(&pdev->dev);
  623. if (ret) {
  624. dev_err(dev, "failed to init sde dbg: %d\n", ret);
  625. goto dbg_init_fail;
  626. }
  627. /* Bind all our sub-components: */
  628. ret = msm_component_bind_all(dev, ddev);
  629. if (ret)
  630. goto bind_fail;
  631. ret = msm_init_vram(ddev);
  632. if (ret)
  633. goto fail;
  634. ddev->mode_config.funcs = &mode_config_funcs;
  635. ddev->mode_config.helper_private = &mode_config_helper_funcs;
  636. kms = _msm_drm_init_helper(priv, ddev, dev, pdev);
  637. if (IS_ERR_OR_NULL(kms)) {
  638. dev_err(dev, "msm_drm_init_helper failed\n");
  639. goto fail;
  640. }
  641. ret = msm_drm_display_thread_create(param, priv, ddev, dev);
  642. if (ret) {
  643. dev_err(dev, "msm_drm_display_thread_create failed\n");
  644. goto fail;
  645. }
  646. ret = drm_vblank_init(ddev, priv->num_crtcs);
  647. if (ret < 0) {
  648. dev_err(dev, "failed to initialize vblank\n");
  649. goto fail;
  650. }
  651. drm_for_each_crtc(crtc, ddev)
  652. drm_crtc_vblank_reset(crtc);
  653. if (kms) {
  654. pm_runtime_get_sync(dev);
  655. ret = drm_irq_install(ddev, platform_get_irq(pdev, 0));
  656. pm_runtime_put_sync(dev);
  657. if (ret < 0) {
  658. dev_err(dev, "failed to install IRQ handler\n");
  659. goto fail;
  660. }
  661. }
  662. ret = drm_dev_register(ddev, 0);
  663. if (ret)
  664. goto fail;
  665. priv->registered = true;
  666. drm_mode_config_reset(ddev);
  667. if (kms && kms->funcs && kms->funcs->cont_splash_config) {
  668. ret = kms->funcs->cont_splash_config(kms);
  669. if (ret) {
  670. dev_err(dev, "kms cont_splash config failed.\n");
  671. goto fail;
  672. }
  673. }
  674. #ifdef CONFIG_DRM_FBDEV_EMULATION
  675. if (fbdev)
  676. priv->fbdev = msm_fbdev_init(ddev);
  677. #endif
  678. /* create drm client only when fbdev is not supported */
  679. if (!priv->fbdev) {
  680. ret = drm_client_init(ddev, &kms->client, "kms_client", NULL);
  681. if (ret) {
  682. DRM_ERROR("failed to init kms_client: %d\n", ret);
  683. kms->client.dev = NULL;
  684. goto fail;
  685. }
  686. drm_client_register(&kms->client);
  687. }
  688. priv->debug_root = debugfs_create_dir("debug",
  689. ddev->primary->debugfs_root);
  690. if (IS_ERR_OR_NULL(priv->debug_root)) {
  691. pr_err("debugfs_root create_dir fail, error %ld\n",
  692. PTR_ERR(priv->debug_root));
  693. priv->debug_root = NULL;
  694. goto fail;
  695. }
  696. ret = sde_dbg_debugfs_register(priv->debug_root);
  697. if (ret) {
  698. dev_err(dev, "failed to reg sde dbg debugfs: %d\n", ret);
  699. goto fail;
  700. }
  701. /* perform subdriver post initialization */
  702. if (kms && kms->funcs && kms->funcs->postinit) {
  703. ret = kms->funcs->postinit(kms);
  704. if (ret) {
  705. pr_err("kms post init failed: %d\n", ret);
  706. goto fail;
  707. }
  708. }
  709. drm_kms_helper_poll_init(ddev);
  710. return 0;
  711. fail:
  712. msm_drm_uninit(dev);
  713. return ret;
  714. bind_fail:
  715. sde_dbg_destroy();
  716. dbg_init_fail:
  717. sde_power_resource_deinit(pdev, &priv->phandle);
  718. power_init_fail:
  719. msm_mdss_destroy(ddev);
  720. mdss_init_fail:
  721. kfree(priv);
  722. priv_alloc_fail:
  723. drm_dev_put(ddev);
  724. return ret;
  725. }
  726. /*
  727. * DRM operations:
  728. */
  729. static int context_init(struct drm_device *dev, struct drm_file *file)
  730. {
  731. struct msm_file_private *ctx;
  732. ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
  733. if (!ctx)
  734. return -ENOMEM;
  735. mutex_init(&ctx->power_lock);
  736. file->driver_priv = ctx;
  737. if (dev && dev->dev_private) {
  738. struct msm_drm_private *priv = dev->dev_private;
  739. struct msm_kms *kms;
  740. kms = priv->kms;
  741. if (kms && kms->funcs && kms->funcs->postopen)
  742. kms->funcs->postopen(kms, file);
  743. }
  744. return 0;
  745. }
  746. static int msm_open(struct drm_device *dev, struct drm_file *file)
  747. {
  748. return context_init(dev, file);
  749. }
  750. static void context_close(struct msm_file_private *ctx)
  751. {
  752. kfree(ctx);
  753. }
  754. static void msm_postclose(struct drm_device *dev, struct drm_file *file)
  755. {
  756. struct msm_drm_private *priv = dev->dev_private;
  757. struct msm_file_private *ctx = file->driver_priv;
  758. struct msm_kms *kms = priv->kms;
  759. if (kms && kms->funcs && kms->funcs->postclose)
  760. kms->funcs->postclose(kms, file);
  761. mutex_lock(&dev->struct_mutex);
  762. if (ctx == priv->lastctx)
  763. priv->lastctx = NULL;
  764. mutex_unlock(&dev->struct_mutex);
  765. mutex_lock(&ctx->power_lock);
  766. if (ctx->enable_refcnt) {
  767. SDE_EVT32(ctx->enable_refcnt);
  768. pm_runtime_put_sync(dev->dev);
  769. }
  770. mutex_unlock(&ctx->power_lock);
  771. context_close(ctx);
  772. }
  773. static void msm_lastclose(struct drm_device *dev)
  774. {
  775. struct msm_drm_private *priv = dev->dev_private;
  776. struct msm_kms *kms = priv->kms;
  777. int i, rc;
  778. /* check for splash status before triggering cleanup
  779. * if we end up here with splash status ON i.e before first
  780. * commit then ignore the last close call
  781. */
  782. if (kms && kms->funcs && kms->funcs->check_for_splash
  783. && kms->funcs->check_for_splash(kms))
  784. return;
  785. /*
  786. * clean up vblank disable immediately as this is the last close.
  787. */
  788. for (i = 0; i < dev->num_crtcs; i++) {
  789. struct drm_vblank_crtc *vblank = &dev->vblank[i];
  790. struct timer_list *disable_timer = &vblank->disable_timer;
  791. if (del_timer_sync(disable_timer))
  792. disable_timer->function(disable_timer);
  793. }
  794. /* wait for pending vblank requests to be executed by worker thread */
  795. flush_workqueue(priv->wq);
  796. if (priv->fbdev) {
  797. rc = drm_fb_helper_restore_fbdev_mode_unlocked(priv->fbdev);
  798. if (rc)
  799. DRM_ERROR("restore FBDEV mode failed: %d\n", rc);
  800. } else if (kms->client.dev) {
  801. rc = drm_client_modeset_commit_force(&kms->client);
  802. if (rc)
  803. DRM_ERROR("client modeset commit failed: %d\n", rc);
  804. }
  805. if (kms && kms->funcs && kms->funcs->lastclose)
  806. kms->funcs->lastclose(kms);
  807. }
  808. static irqreturn_t msm_irq(int irq, void *arg)
  809. {
  810. struct drm_device *dev = arg;
  811. struct msm_drm_private *priv = dev->dev_private;
  812. struct msm_kms *kms = priv->kms;
  813. BUG_ON(!kms);
  814. return kms->funcs->irq(kms);
  815. }
  816. static void msm_irq_preinstall(struct drm_device *dev)
  817. {
  818. struct msm_drm_private *priv = dev->dev_private;
  819. struct msm_kms *kms = priv->kms;
  820. BUG_ON(!kms);
  821. kms->funcs->irq_preinstall(kms);
  822. }
  823. static int msm_irq_postinstall(struct drm_device *dev)
  824. {
  825. struct msm_drm_private *priv = dev->dev_private;
  826. struct msm_kms *kms = priv->kms;
  827. BUG_ON(!kms);
  828. if (kms->funcs->irq_postinstall)
  829. return kms->funcs->irq_postinstall(kms);
  830. return 0;
  831. }
  832. static void msm_irq_uninstall(struct drm_device *dev)
  833. {
  834. struct msm_drm_private *priv = dev->dev_private;
  835. struct msm_kms *kms = priv->kms;
  836. BUG_ON(!kms);
  837. kms->funcs->irq_uninstall(kms);
  838. }
  839. static int msm_enable_vblank(struct drm_device *dev, unsigned int pipe)
  840. {
  841. struct msm_drm_private *priv = dev->dev_private;
  842. struct msm_kms *kms = priv->kms;
  843. if (!kms)
  844. return -ENXIO;
  845. DBG("dev=%pK, crtc=%u", dev, pipe);
  846. return vblank_ctrl_queue_work(priv, pipe, true);
  847. }
  848. static void msm_disable_vblank(struct drm_device *dev, unsigned int pipe)
  849. {
  850. struct msm_drm_private *priv = dev->dev_private;
  851. struct msm_kms *kms = priv->kms;
  852. if (!kms)
  853. return;
  854. DBG("dev=%pK, crtc=%u", dev, pipe);
  855. vblank_ctrl_queue_work(priv, pipe, false);
  856. }
  857. /*
  858. * DRM ioctls:
  859. */
  860. static int msm_ioctl_gem_new(struct drm_device *dev, void *data,
  861. struct drm_file *file)
  862. {
  863. struct drm_msm_gem_new *args = data;
  864. if (args->flags & ~MSM_BO_FLAGS) {
  865. DRM_ERROR("invalid flags: %08x\n", args->flags);
  866. return -EINVAL;
  867. }
  868. return msm_gem_new_handle(dev, file, args->size,
  869. args->flags, &args->handle, NULL);
  870. }
  871. static inline ktime_t to_ktime(struct drm_msm_timespec timeout)
  872. {
  873. return ktime_set(timeout.tv_sec, timeout.tv_nsec);
  874. }
  875. static int msm_ioctl_gem_cpu_prep(struct drm_device *dev, void *data,
  876. struct drm_file *file)
  877. {
  878. struct drm_msm_gem_cpu_prep *args = data;
  879. struct drm_gem_object *obj;
  880. ktime_t timeout = to_ktime(args->timeout);
  881. int ret;
  882. if (args->op & ~MSM_PREP_FLAGS) {
  883. DRM_ERROR("invalid op: %08x\n", args->op);
  884. return -EINVAL;
  885. }
  886. obj = drm_gem_object_lookup(file, args->handle);
  887. if (!obj)
  888. return -ENOENT;
  889. ret = msm_gem_cpu_prep(obj, args->op, &timeout);
  890. drm_gem_object_put_unlocked(obj);
  891. return ret;
  892. }
  893. static int msm_ioctl_gem_cpu_fini(struct drm_device *dev, void *data,
  894. struct drm_file *file)
  895. {
  896. struct drm_msm_gem_cpu_fini *args = data;
  897. struct drm_gem_object *obj;
  898. int ret;
  899. obj = drm_gem_object_lookup(file, args->handle);
  900. if (!obj)
  901. return -ENOENT;
  902. ret = msm_gem_cpu_fini(obj);
  903. drm_gem_object_put_unlocked(obj);
  904. return ret;
  905. }
  906. static int msm_ioctl_gem_madvise(struct drm_device *dev, void *data,
  907. struct drm_file *file)
  908. {
  909. struct drm_msm_gem_madvise *args = data;
  910. struct drm_gem_object *obj;
  911. int ret;
  912. switch (args->madv) {
  913. case MSM_MADV_DONTNEED:
  914. case MSM_MADV_WILLNEED:
  915. break;
  916. default:
  917. return -EINVAL;
  918. }
  919. ret = mutex_lock_interruptible(&dev->struct_mutex);
  920. if (ret)
  921. return ret;
  922. obj = drm_gem_object_lookup(file, args->handle);
  923. if (!obj) {
  924. ret = -ENOENT;
  925. goto unlock;
  926. }
  927. ret = msm_gem_madvise(obj, args->madv);
  928. if (ret >= 0) {
  929. args->retained = ret;
  930. ret = 0;
  931. }
  932. drm_gem_object_put(obj);
  933. unlock:
  934. mutex_unlock(&dev->struct_mutex);
  935. return ret;
  936. }
  937. static int msm_drm_object_supports_event(struct drm_device *dev,
  938. struct drm_msm_event_req *req)
  939. {
  940. int ret = -EINVAL;
  941. struct drm_mode_object *arg_obj;
  942. arg_obj = drm_mode_object_find(dev, NULL, req->object_id,
  943. req->object_type);
  944. if (!arg_obj)
  945. return -ENOENT;
  946. switch (arg_obj->type) {
  947. case DRM_MODE_OBJECT_CRTC:
  948. case DRM_MODE_OBJECT_CONNECTOR:
  949. ret = 0;
  950. break;
  951. default:
  952. ret = -EOPNOTSUPP;
  953. break;
  954. }
  955. drm_mode_object_put(arg_obj);
  956. return ret;
  957. }
  958. static int msm_register_event(struct drm_device *dev,
  959. struct drm_msm_event_req *req, struct drm_file *file, bool en)
  960. {
  961. int ret = -EINVAL;
  962. struct msm_drm_private *priv = dev->dev_private;
  963. struct msm_kms *kms = priv->kms;
  964. struct drm_mode_object *arg_obj;
  965. arg_obj = drm_mode_object_find(dev, file, req->object_id,
  966. req->object_type);
  967. if (!arg_obj)
  968. return -ENOENT;
  969. ret = kms->funcs->register_events(kms, arg_obj, req->event, en);
  970. drm_mode_object_put(arg_obj);
  971. return ret;
  972. }
  973. static int msm_event_client_count(struct drm_device *dev,
  974. struct drm_msm_event_req *req_event, bool locked)
  975. {
  976. struct msm_drm_private *priv = dev->dev_private;
  977. unsigned long flag = 0;
  978. struct msm_drm_event *node;
  979. int count = 0;
  980. if (!locked)
  981. spin_lock_irqsave(&dev->event_lock, flag);
  982. list_for_each_entry(node, &priv->client_event_list, base.link) {
  983. if (node->event.type == req_event->event &&
  984. node->info.object_id == req_event->object_id)
  985. count++;
  986. }
  987. if (!locked)
  988. spin_unlock_irqrestore(&dev->event_lock, flag);
  989. return count;
  990. }
  991. static int msm_ioctl_register_event(struct drm_device *dev, void *data,
  992. struct drm_file *file)
  993. {
  994. struct msm_drm_private *priv = dev->dev_private;
  995. struct drm_msm_event_req *req_event = data;
  996. struct msm_drm_event *client, *node;
  997. unsigned long flag = 0;
  998. bool dup_request = false;
  999. int ret = 0, count = 0;
  1000. ret = msm_drm_object_supports_event(dev, req_event);
  1001. if (ret) {
  1002. DRM_ERROR("unsupported event %x object %x object id %d\n",
  1003. req_event->event, req_event->object_type,
  1004. req_event->object_id);
  1005. return ret;
  1006. }
  1007. spin_lock_irqsave(&dev->event_lock, flag);
  1008. list_for_each_entry(node, &priv->client_event_list, base.link) {
  1009. if (node->base.file_priv != file)
  1010. continue;
  1011. if (node->event.type == req_event->event &&
  1012. node->info.object_id == req_event->object_id) {
  1013. DRM_DEBUG("duplicate request for event %x obj id %d\n",
  1014. node->event.type, node->info.object_id);
  1015. dup_request = true;
  1016. break;
  1017. }
  1018. }
  1019. spin_unlock_irqrestore(&dev->event_lock, flag);
  1020. if (dup_request)
  1021. return -EALREADY;
  1022. client = kzalloc(sizeof(*client), GFP_KERNEL);
  1023. if (!client)
  1024. return -ENOMEM;
  1025. client->base.file_priv = file;
  1026. client->base.event = &client->event;
  1027. client->event.type = req_event->event;
  1028. memcpy(&client->info, req_event, sizeof(client->info));
  1029. /* Get the count of clients that have registered for event.
  1030. * Event should be enabled for first client, for subsequent enable
  1031. * calls add to client list and return.
  1032. */
  1033. count = msm_event_client_count(dev, req_event, false);
  1034. /* Add current client to list */
  1035. spin_lock_irqsave(&dev->event_lock, flag);
  1036. list_add_tail(&client->base.link, &priv->client_event_list);
  1037. spin_unlock_irqrestore(&dev->event_lock, flag);
  1038. if (count)
  1039. return 0;
  1040. ret = msm_register_event(dev, req_event, file, true);
  1041. if (ret) {
  1042. DRM_ERROR("failed to enable event %x object %x object id %d\n",
  1043. req_event->event, req_event->object_type,
  1044. req_event->object_id);
  1045. spin_lock_irqsave(&dev->event_lock, flag);
  1046. list_del(&client->base.link);
  1047. spin_unlock_irqrestore(&dev->event_lock, flag);
  1048. kfree(client);
  1049. }
  1050. return ret;
  1051. }
  1052. static int msm_ioctl_deregister_event(struct drm_device *dev, void *data,
  1053. struct drm_file *file)
  1054. {
  1055. struct msm_drm_private *priv = dev->dev_private;
  1056. struct drm_msm_event_req *req_event = data;
  1057. struct msm_drm_event *client = NULL, *node, *temp;
  1058. unsigned long flag = 0;
  1059. int count = 0;
  1060. bool found = false;
  1061. int ret = 0;
  1062. ret = msm_drm_object_supports_event(dev, req_event);
  1063. if (ret) {
  1064. DRM_ERROR("unsupported event %x object %x object id %d\n",
  1065. req_event->event, req_event->object_type,
  1066. req_event->object_id);
  1067. return ret;
  1068. }
  1069. spin_lock_irqsave(&dev->event_lock, flag);
  1070. list_for_each_entry_safe(node, temp, &priv->client_event_list,
  1071. base.link) {
  1072. if (node->event.type == req_event->event &&
  1073. node->info.object_id == req_event->object_id &&
  1074. node->base.file_priv == file) {
  1075. client = node;
  1076. list_del(&client->base.link);
  1077. found = true;
  1078. kfree(client);
  1079. break;
  1080. }
  1081. }
  1082. spin_unlock_irqrestore(&dev->event_lock, flag);
  1083. if (!found)
  1084. return -ENOENT;
  1085. count = msm_event_client_count(dev, req_event, false);
  1086. if (!count)
  1087. ret = msm_register_event(dev, req_event, file, false);
  1088. return ret;
  1089. }
  1090. void msm_mode_object_event_notify(struct drm_mode_object *obj,
  1091. struct drm_device *dev, struct drm_event *event, u8 *payload)
  1092. {
  1093. struct msm_drm_private *priv = NULL;
  1094. unsigned long flags;
  1095. struct msm_drm_event *notify, *node;
  1096. int len = 0, ret;
  1097. if (!obj || !event || !event->length || !payload) {
  1098. DRM_ERROR("err param obj %pK event %pK len %d payload %pK\n",
  1099. obj, event, ((event) ? (event->length) : -1),
  1100. payload);
  1101. return;
  1102. }
  1103. priv = (dev) ? dev->dev_private : NULL;
  1104. if (!dev || !priv) {
  1105. DRM_ERROR("invalid dev %pK priv %pK\n", dev, priv);
  1106. return;
  1107. }
  1108. spin_lock_irqsave(&dev->event_lock, flags);
  1109. list_for_each_entry(node, &priv->client_event_list, base.link) {
  1110. if (node->event.type != event->type ||
  1111. obj->id != node->info.object_id)
  1112. continue;
  1113. len = event->length + sizeof(struct msm_drm_event);
  1114. if (node->base.file_priv->event_space < len) {
  1115. DRM_ERROR("Insufficient space %d for event %x len %d\n",
  1116. node->base.file_priv->event_space, event->type,
  1117. len);
  1118. continue;
  1119. }
  1120. notify = kzalloc(len, GFP_ATOMIC);
  1121. if (!notify)
  1122. continue;
  1123. notify->base.file_priv = node->base.file_priv;
  1124. notify->base.event = &notify->event;
  1125. notify->event.type = node->event.type;
  1126. notify->event.length = event->length +
  1127. sizeof(struct drm_msm_event_resp);
  1128. memcpy(&notify->info, &node->info, sizeof(notify->info));
  1129. memcpy(notify->data, payload, event->length);
  1130. ret = drm_event_reserve_init_locked(dev, node->base.file_priv,
  1131. &notify->base, &notify->event);
  1132. if (ret) {
  1133. kfree(notify);
  1134. continue;
  1135. }
  1136. drm_send_event_locked(dev, &notify->base);
  1137. }
  1138. spin_unlock_irqrestore(&dev->event_lock, flags);
  1139. }
  1140. static int msm_release(struct inode *inode, struct file *filp)
  1141. {
  1142. struct drm_file *file_priv = filp->private_data;
  1143. struct drm_minor *minor = file_priv->minor;
  1144. struct drm_device *dev = minor->dev;
  1145. struct msm_drm_private *priv = dev->dev_private;
  1146. struct msm_drm_event *node, *temp, *tmp_node;
  1147. u32 count;
  1148. unsigned long flags;
  1149. LIST_HEAD(tmp_head);
  1150. spin_lock_irqsave(&dev->event_lock, flags);
  1151. list_for_each_entry_safe(node, temp, &priv->client_event_list,
  1152. base.link) {
  1153. if (node->base.file_priv != file_priv)
  1154. continue;
  1155. list_del(&node->base.link);
  1156. list_add_tail(&node->base.link, &tmp_head);
  1157. }
  1158. spin_unlock_irqrestore(&dev->event_lock, flags);
  1159. list_for_each_entry_safe(node, temp, &tmp_head,
  1160. base.link) {
  1161. list_del(&node->base.link);
  1162. count = msm_event_client_count(dev, &node->info, false);
  1163. list_for_each_entry(tmp_node, &tmp_head, base.link) {
  1164. if (tmp_node->event.type == node->info.event &&
  1165. tmp_node->info.object_id ==
  1166. node->info.object_id)
  1167. count++;
  1168. }
  1169. if (!count)
  1170. msm_register_event(dev, &node->info, file_priv, false);
  1171. kfree(node);
  1172. }
  1173. return drm_release(inode, filp);
  1174. }
  1175. /**
  1176. * msm_ioctl_rmfb2 - remove an FB from the configuration
  1177. * @dev: drm device for the ioctl
  1178. * @data: data pointer for the ioctl
  1179. * @file_priv: drm file for the ioctl call
  1180. *
  1181. * Remove the FB specified by the user.
  1182. *
  1183. * Called by the user via ioctl.
  1184. *
  1185. * Returns:
  1186. * Zero on success, negative errno on failure.
  1187. */
  1188. int msm_ioctl_rmfb2(struct drm_device *dev, void *data,
  1189. struct drm_file *file_priv)
  1190. {
  1191. struct drm_framebuffer *fb = NULL;
  1192. struct drm_framebuffer *fbl = NULL;
  1193. uint32_t *id = data;
  1194. int found = 0;
  1195. if (!drm_core_check_feature(dev, DRIVER_MODESET))
  1196. return -EINVAL;
  1197. fb = drm_framebuffer_lookup(dev, file_priv, *id);
  1198. if (!fb)
  1199. return -ENOENT;
  1200. /* drop extra ref from traversing drm_framebuffer_lookup */
  1201. drm_framebuffer_put(fb);
  1202. mutex_lock(&file_priv->fbs_lock);
  1203. list_for_each_entry(fbl, &file_priv->fbs, filp_head)
  1204. if (fb == fbl)
  1205. found = 1;
  1206. if (!found) {
  1207. mutex_unlock(&file_priv->fbs_lock);
  1208. return -ENOENT;
  1209. }
  1210. list_del_init(&fb->filp_head);
  1211. mutex_unlock(&file_priv->fbs_lock);
  1212. drm_framebuffer_put(fb);
  1213. return 0;
  1214. }
  1215. EXPORT_SYMBOL(msm_ioctl_rmfb2);
  1216. /**
  1217. * msm_ioctl_power_ctrl - enable/disable power vote on MDSS Hw
  1218. * @dev: drm device for the ioctl
  1219. * @data: data pointer for the ioctl
  1220. * @file_priv: drm file for the ioctl call
  1221. *
  1222. */
  1223. int msm_ioctl_power_ctrl(struct drm_device *dev, void *data,
  1224. struct drm_file *file_priv)
  1225. {
  1226. struct msm_file_private *ctx = file_priv->driver_priv;
  1227. struct msm_drm_private *priv;
  1228. struct drm_msm_power_ctrl *power_ctrl = data;
  1229. bool vote_req = false;
  1230. int old_cnt;
  1231. int rc = 0;
  1232. if (unlikely(!power_ctrl)) {
  1233. DRM_ERROR("invalid ioctl data\n");
  1234. return -EINVAL;
  1235. }
  1236. priv = dev->dev_private;
  1237. mutex_lock(&ctx->power_lock);
  1238. old_cnt = ctx->enable_refcnt;
  1239. if (power_ctrl->enable) {
  1240. if (!ctx->enable_refcnt)
  1241. vote_req = true;
  1242. ctx->enable_refcnt++;
  1243. } else if (ctx->enable_refcnt) {
  1244. ctx->enable_refcnt--;
  1245. if (!ctx->enable_refcnt)
  1246. vote_req = true;
  1247. } else {
  1248. pr_err("ignoring, unbalanced disable\n");
  1249. }
  1250. if (vote_req) {
  1251. if (power_ctrl->enable)
  1252. rc = pm_runtime_get_sync(dev->dev);
  1253. else
  1254. pm_runtime_put_sync(dev->dev);
  1255. if (rc < 0)
  1256. ctx->enable_refcnt = old_cnt;
  1257. else
  1258. rc = 0;
  1259. }
  1260. pr_debug("pid %d enable %d, refcnt %d, vote_req %d\n",
  1261. current->pid, power_ctrl->enable, ctx->enable_refcnt,
  1262. vote_req);
  1263. SDE_EVT32(current->pid, power_ctrl->enable, ctx->enable_refcnt,
  1264. vote_req);
  1265. mutex_unlock(&ctx->power_lock);
  1266. return rc;
  1267. }
  1268. static const struct drm_ioctl_desc msm_ioctls[] = {
  1269. DRM_IOCTL_DEF_DRV(MSM_GEM_NEW, msm_ioctl_gem_new, DRM_AUTH|DRM_RENDER_ALLOW),
  1270. DRM_IOCTL_DEF_DRV(MSM_GEM_CPU_PREP, msm_ioctl_gem_cpu_prep, DRM_AUTH|DRM_RENDER_ALLOW),
  1271. DRM_IOCTL_DEF_DRV(MSM_GEM_CPU_FINI, msm_ioctl_gem_cpu_fini, DRM_AUTH|DRM_RENDER_ALLOW),
  1272. DRM_IOCTL_DEF_DRV(MSM_GEM_MADVISE, msm_ioctl_gem_madvise, DRM_AUTH|DRM_RENDER_ALLOW),
  1273. DRM_IOCTL_DEF_DRV(SDE_WB_CONFIG, sde_wb_config, DRM_UNLOCKED|DRM_AUTH),
  1274. DRM_IOCTL_DEF_DRV(MSM_REGISTER_EVENT, msm_ioctl_register_event,
  1275. DRM_UNLOCKED),
  1276. DRM_IOCTL_DEF_DRV(MSM_DEREGISTER_EVENT, msm_ioctl_deregister_event,
  1277. DRM_UNLOCKED),
  1278. DRM_IOCTL_DEF_DRV(MSM_RMFB2, msm_ioctl_rmfb2, DRM_UNLOCKED),
  1279. DRM_IOCTL_DEF_DRV(MSM_POWER_CTRL, msm_ioctl_power_ctrl,
  1280. DRM_RENDER_ALLOW),
  1281. };
  1282. static const struct vm_operations_struct vm_ops = {
  1283. .fault = msm_gem_fault,
  1284. .open = drm_gem_vm_open,
  1285. .close = drm_gem_vm_close,
  1286. };
  1287. static const struct file_operations fops = {
  1288. .owner = THIS_MODULE,
  1289. .open = drm_open,
  1290. .release = msm_release,
  1291. .unlocked_ioctl = drm_ioctl,
  1292. .compat_ioctl = drm_compat_ioctl,
  1293. .poll = drm_poll,
  1294. .read = drm_read,
  1295. .llseek = no_llseek,
  1296. .mmap = msm_gem_mmap,
  1297. };
  1298. static struct drm_driver msm_driver = {
  1299. .driver_features = DRIVER_GEM |
  1300. DRIVER_RENDER |
  1301. DRIVER_ATOMIC |
  1302. DRIVER_MODESET,
  1303. .open = msm_open,
  1304. .postclose = msm_postclose,
  1305. .lastclose = msm_lastclose,
  1306. .irq_handler = msm_irq,
  1307. .irq_preinstall = msm_irq_preinstall,
  1308. .irq_postinstall = msm_irq_postinstall,
  1309. .irq_uninstall = msm_irq_uninstall,
  1310. .enable_vblank = msm_enable_vblank,
  1311. .disable_vblank = msm_disable_vblank,
  1312. .gem_free_object = msm_gem_free_object,
  1313. .gem_vm_ops = &vm_ops,
  1314. .dumb_create = msm_gem_dumb_create,
  1315. .dumb_map_offset = msm_gem_dumb_map_offset,
  1316. .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
  1317. .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
  1318. .gem_prime_export = drm_gem_prime_export,
  1319. .gem_prime_import = msm_gem_prime_import,
  1320. .gem_prime_pin = msm_gem_prime_pin,
  1321. .gem_prime_unpin = msm_gem_prime_unpin,
  1322. .gem_prime_get_sg_table = msm_gem_prime_get_sg_table,
  1323. .gem_prime_import_sg_table = msm_gem_prime_import_sg_table,
  1324. .gem_prime_vmap = msm_gem_prime_vmap,
  1325. .gem_prime_vunmap = msm_gem_prime_vunmap,
  1326. .gem_prime_mmap = msm_gem_prime_mmap,
  1327. .ioctls = msm_ioctls,
  1328. .num_ioctls = ARRAY_SIZE(msm_ioctls),
  1329. .fops = &fops,
  1330. .name = "msm_drm",
  1331. .desc = "MSM Snapdragon DRM",
  1332. .date = "20130625",
  1333. .major = MSM_VERSION_MAJOR,
  1334. .minor = MSM_VERSION_MINOR,
  1335. .patchlevel = MSM_VERSION_PATCHLEVEL,
  1336. };
  1337. #ifdef CONFIG_PM_SLEEP
  1338. static int msm_pm_suspend(struct device *dev)
  1339. {
  1340. struct drm_device *ddev;
  1341. struct msm_drm_private *priv;
  1342. struct msm_kms *kms;
  1343. if (!dev)
  1344. return -EINVAL;
  1345. ddev = dev_get_drvdata(dev);
  1346. if (!ddev || !ddev->dev_private)
  1347. return -EINVAL;
  1348. priv = ddev->dev_private;
  1349. kms = priv->kms;
  1350. if (kms && kms->funcs && kms->funcs->pm_suspend)
  1351. return kms->funcs->pm_suspend(dev);
  1352. /* disable hot-plug polling */
  1353. drm_kms_helper_poll_disable(ddev);
  1354. return 0;
  1355. }
  1356. static int msm_pm_resume(struct device *dev)
  1357. {
  1358. struct drm_device *ddev;
  1359. struct msm_drm_private *priv;
  1360. struct msm_kms *kms;
  1361. if (!dev)
  1362. return -EINVAL;
  1363. ddev = dev_get_drvdata(dev);
  1364. if (!ddev || !ddev->dev_private)
  1365. return -EINVAL;
  1366. priv = ddev->dev_private;
  1367. kms = priv->kms;
  1368. if (kms && kms->funcs && kms->funcs->pm_resume)
  1369. return kms->funcs->pm_resume(dev);
  1370. /* enable hot-plug polling */
  1371. drm_kms_helper_poll_enable(ddev);
  1372. return 0;
  1373. }
  1374. #endif
  1375. #ifdef CONFIG_PM
  1376. static int msm_runtime_suspend(struct device *dev)
  1377. {
  1378. struct drm_device *ddev = dev_get_drvdata(dev);
  1379. struct msm_drm_private *priv = ddev->dev_private;
  1380. DBG("");
  1381. if (priv->mdss)
  1382. msm_mdss_disable(priv->mdss);
  1383. else
  1384. sde_power_resource_enable(&priv->phandle, false);
  1385. return 0;
  1386. }
  1387. static int msm_runtime_resume(struct device *dev)
  1388. {
  1389. struct drm_device *ddev = dev_get_drvdata(dev);
  1390. struct msm_drm_private *priv = ddev->dev_private;
  1391. int ret;
  1392. DBG("");
  1393. if (priv->mdss)
  1394. ret = msm_mdss_enable(priv->mdss);
  1395. else
  1396. ret = sde_power_resource_enable(&priv->phandle, true);
  1397. return ret;
  1398. }
  1399. #endif
  1400. static const struct dev_pm_ops msm_pm_ops = {
  1401. SET_SYSTEM_SLEEP_PM_OPS(msm_pm_suspend, msm_pm_resume)
  1402. SET_RUNTIME_PM_OPS(msm_runtime_suspend, msm_runtime_resume, NULL)
  1403. };
  1404. /*
  1405. * Componentized driver support:
  1406. */
  1407. /*
  1408. * NOTE: duplication of the same code as exynos or imx (or probably any other).
  1409. * so probably some room for some helpers
  1410. */
  1411. static int compare_of(struct device *dev, void *data)
  1412. {
  1413. return dev->of_node == data;
  1414. }
  1415. /*
  1416. * Identify what components need to be added by parsing what remote-endpoints
  1417. * our MDP output ports are connected to. In the case of LVDS on MDP4, there
  1418. * is no external component that we need to add since LVDS is within MDP4
  1419. * itself.
  1420. */
  1421. static int add_components_mdp(struct device *mdp_dev,
  1422. struct component_match **matchptr)
  1423. {
  1424. struct device_node *np = mdp_dev->of_node;
  1425. struct device_node *ep_node;
  1426. struct device *master_dev;
  1427. /*
  1428. * on MDP4 based platforms, the MDP platform device is the component
  1429. * master that adds other display interface components to itself.
  1430. *
  1431. * on MDP5 based platforms, the MDSS platform device is the component
  1432. * master that adds MDP5 and other display interface components to
  1433. * itself.
  1434. */
  1435. if (of_device_is_compatible(np, "qcom,mdp4"))
  1436. master_dev = mdp_dev;
  1437. else
  1438. master_dev = mdp_dev->parent;
  1439. for_each_endpoint_of_node(np, ep_node) {
  1440. struct device_node *intf;
  1441. struct of_endpoint ep;
  1442. int ret;
  1443. ret = of_graph_parse_endpoint(ep_node, &ep);
  1444. if (ret) {
  1445. dev_err(mdp_dev, "unable to parse port endpoint\n");
  1446. of_node_put(ep_node);
  1447. return ret;
  1448. }
  1449. /*
  1450. * The LCDC/LVDS port on MDP4 is a speacial case where the
  1451. * remote-endpoint isn't a component that we need to add
  1452. */
  1453. if (of_device_is_compatible(np, "qcom,mdp4") &&
  1454. ep.port == 0)
  1455. continue;
  1456. /*
  1457. * It's okay if some of the ports don't have a remote endpoint
  1458. * specified. It just means that the port isn't connected to
  1459. * any external interface.
  1460. */
  1461. intf = of_graph_get_remote_port_parent(ep_node);
  1462. if (!intf)
  1463. continue;
  1464. if (of_device_is_available(intf))
  1465. drm_of_component_match_add(master_dev, matchptr,
  1466. compare_of, intf);
  1467. of_node_put(intf);
  1468. }
  1469. return 0;
  1470. }
  1471. static int compare_name_mdp(struct device *dev, void *data)
  1472. {
  1473. return (strnstr(dev_name(dev), "mdp", strlen("mdp")) != NULL);
  1474. }
  1475. static int add_display_components(struct device *dev,
  1476. struct component_match **matchptr)
  1477. {
  1478. struct device *mdp_dev = NULL;
  1479. struct device_node *node;
  1480. int ret;
  1481. if (of_device_is_compatible(dev->of_node, "qcom,sde-kms")) {
  1482. struct device_node *np = dev->of_node;
  1483. unsigned int i;
  1484. for (i = 0; ; i++) {
  1485. node = of_parse_phandle(np, "connectors", i);
  1486. if (!node)
  1487. break;
  1488. component_match_add(dev, matchptr, compare_of, node);
  1489. }
  1490. return 0;
  1491. }
  1492. /*
  1493. * MDP5 based devices don't have a flat hierarchy. There is a top level
  1494. * parent: MDSS, and children: MDP5, DSI, HDMI, eDP etc. Populate the
  1495. * children devices, find the MDP5 node, and then add the interfaces
  1496. * to our components list.
  1497. */
  1498. if (of_device_is_compatible(dev->of_node, "qcom,mdss")) {
  1499. ret = of_platform_populate(dev->of_node, NULL, NULL, dev);
  1500. if (ret) {
  1501. dev_err(dev, "failed to populate children devices\n");
  1502. return ret;
  1503. }
  1504. mdp_dev = device_find_child(dev, NULL, compare_name_mdp);
  1505. if (!mdp_dev) {
  1506. dev_err(dev, "failed to find MDSS MDP node\n");
  1507. of_platform_depopulate(dev);
  1508. return -ENODEV;
  1509. }
  1510. put_device(mdp_dev);
  1511. /* add the MDP component itself */
  1512. component_match_add(dev, matchptr, compare_of,
  1513. mdp_dev->of_node);
  1514. } else {
  1515. /* MDP4 */
  1516. mdp_dev = dev;
  1517. }
  1518. ret = add_components_mdp(mdp_dev, matchptr);
  1519. if (ret)
  1520. of_platform_depopulate(dev);
  1521. return ret;
  1522. }
  1523. struct msm_gem_address_space *
  1524. msm_gem_smmu_address_space_get(struct drm_device *dev,
  1525. unsigned int domain)
  1526. {
  1527. struct msm_drm_private *priv = NULL;
  1528. struct msm_kms *kms;
  1529. const struct msm_kms_funcs *funcs;
  1530. if ((!dev) || (!dev->dev_private))
  1531. return NULL;
  1532. priv = dev->dev_private;
  1533. kms = priv->kms;
  1534. if (!kms)
  1535. return NULL;
  1536. funcs = kms->funcs;
  1537. if ((!funcs) || (!funcs->get_address_space))
  1538. return NULL;
  1539. return funcs->get_address_space(priv->kms, domain);
  1540. }
  1541. int msm_get_mixer_count(struct msm_drm_private *priv,
  1542. const struct drm_display_mode *mode,
  1543. const struct msm_resource_caps_info *res, u32 *num_lm)
  1544. {
  1545. struct msm_kms *kms;
  1546. const struct msm_kms_funcs *funcs;
  1547. if (!priv) {
  1548. DRM_ERROR("invalid drm private struct\n");
  1549. return -EINVAL;
  1550. }
  1551. kms = priv->kms;
  1552. if (!kms) {
  1553. DRM_ERROR("invalid msm kms struct\n");
  1554. return -EINVAL;
  1555. }
  1556. funcs = kms->funcs;
  1557. if (!funcs || !funcs->get_mixer_count) {
  1558. DRM_ERROR("invalid function pointers\n");
  1559. return -EINVAL;
  1560. }
  1561. return funcs->get_mixer_count(priv->kms, mode, res, num_lm);
  1562. }
  1563. static int msm_drm_bind(struct device *dev)
  1564. {
  1565. return msm_drm_init(dev, &msm_driver);
  1566. }
  1567. static void msm_drm_unbind(struct device *dev)
  1568. {
  1569. msm_drm_uninit(dev);
  1570. }
  1571. static const struct component_master_ops msm_drm_ops = {
  1572. .bind = msm_drm_bind,
  1573. .unbind = msm_drm_unbind,
  1574. };
  1575. /*
  1576. * Platform driver:
  1577. */
  1578. static int msm_pdev_probe(struct platform_device *pdev)
  1579. {
  1580. int ret;
  1581. struct component_match *match = NULL;
  1582. ret = add_display_components(&pdev->dev, &match);
  1583. if (ret)
  1584. return ret;
  1585. if (!match)
  1586. return -ENODEV;
  1587. pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
  1588. return component_master_add_with_match(&pdev->dev, &msm_drm_ops, match);
  1589. }
  1590. static int msm_pdev_remove(struct platform_device *pdev)
  1591. {
  1592. component_master_del(&pdev->dev, &msm_drm_ops);
  1593. of_platform_depopulate(&pdev->dev);
  1594. msm_drm_unbind(&pdev->dev);
  1595. component_master_del(&pdev->dev, &msm_drm_ops);
  1596. return 0;
  1597. }
  1598. static void msm_pdev_shutdown(struct platform_device *pdev)
  1599. {
  1600. struct drm_device *ddev = platform_get_drvdata(pdev);
  1601. struct msm_drm_private *priv = NULL;
  1602. if (!ddev) {
  1603. DRM_ERROR("invalid drm device node\n");
  1604. return;
  1605. }
  1606. priv = ddev->dev_private;
  1607. if (!priv) {
  1608. DRM_ERROR("invalid msm drm private node\n");
  1609. return;
  1610. }
  1611. msm_lastclose(ddev);
  1612. /* set this after lastclose to allow kickoff from lastclose */
  1613. priv->shutdown_in_progress = true;
  1614. }
  1615. static const struct of_device_id dt_match[] = {
  1616. { .compatible = "qcom,mdp4", .data = (void *)KMS_MDP4 },
  1617. { .compatible = "qcom,mdss", .data = (void *)KMS_MDP5 },
  1618. { .compatible = "qcom,sde-kms", .data = (void *)KMS_SDE },
  1619. {},
  1620. };
  1621. MODULE_DEVICE_TABLE(of, dt_match);
  1622. static struct platform_driver msm_platform_driver = {
  1623. .probe = msm_pdev_probe,
  1624. .remove = msm_pdev_remove,
  1625. .shutdown = msm_pdev_shutdown,
  1626. .driver = {
  1627. .name = "msm_drm",
  1628. .of_match_table = dt_match,
  1629. .pm = &msm_pm_ops,
  1630. .suppress_bind_attrs = true,
  1631. },
  1632. };
  1633. static int __init msm_drm_register(void)
  1634. {
  1635. if (!modeset)
  1636. return -EINVAL;
  1637. DBG("init");
  1638. msm_smmu_driver_init();
  1639. msm_dsi_register();
  1640. msm_edp_register();
  1641. msm_hdmi_register();
  1642. return platform_driver_register(&msm_platform_driver);
  1643. }
  1644. static void __exit msm_drm_unregister(void)
  1645. {
  1646. DBG("fini");
  1647. platform_driver_unregister(&msm_platform_driver);
  1648. msm_hdmi_unregister();
  1649. msm_edp_unregister();
  1650. msm_dsi_unregister();
  1651. msm_smmu_driver_cleanup();
  1652. }
  1653. module_init(msm_drm_register);
  1654. module_exit(msm_drm_unregister);
  1655. MODULE_AUTHOR("Rob Clark <[email protected]");
  1656. MODULE_DESCRIPTION("MSM DRM Driver");
  1657. MODULE_LICENSE("GPL");