msm_drv.c 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998
  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_preclose(struct drm_device *dev, struct drm_file *file)
  755. {
  756. struct msm_drm_private *priv = dev->dev_private;
  757. struct msm_kms *kms = priv->kms;
  758. if (kms && kms->funcs && kms->funcs->preclose)
  759. kms->funcs->preclose(kms, file);
  760. }
  761. static void msm_postclose(struct drm_device *dev, struct drm_file *file)
  762. {
  763. struct msm_drm_private *priv = dev->dev_private;
  764. struct msm_file_private *ctx = file->driver_priv;
  765. struct msm_kms *kms = priv->kms;
  766. if (kms && kms->funcs && kms->funcs->postclose)
  767. kms->funcs->postclose(kms, file);
  768. mutex_lock(&dev->struct_mutex);
  769. if (ctx == priv->lastctx)
  770. priv->lastctx = NULL;
  771. mutex_unlock(&dev->struct_mutex);
  772. mutex_lock(&ctx->power_lock);
  773. if (ctx->enable_refcnt) {
  774. SDE_EVT32(ctx->enable_refcnt);
  775. pm_runtime_put_sync(dev->dev);
  776. }
  777. mutex_unlock(&ctx->power_lock);
  778. context_close(ctx);
  779. }
  780. static void msm_lastclose(struct drm_device *dev)
  781. {
  782. struct msm_drm_private *priv = dev->dev_private;
  783. struct msm_kms *kms = priv->kms;
  784. int i, rc;
  785. /* check for splash status before triggering cleanup
  786. * if we end up here with splash status ON i.e before first
  787. * commit then ignore the last close call
  788. */
  789. if (kms && kms->funcs && kms->funcs->check_for_splash
  790. && kms->funcs->check_for_splash(kms))
  791. return;
  792. /*
  793. * clean up vblank disable immediately as this is the last close.
  794. */
  795. for (i = 0; i < dev->num_crtcs; i++) {
  796. struct drm_vblank_crtc *vblank = &dev->vblank[i];
  797. struct timer_list *disable_timer = &vblank->disable_timer;
  798. if (del_timer_sync(disable_timer))
  799. disable_timer->function(disable_timer);
  800. }
  801. /* wait for pending vblank requests to be executed by worker thread */
  802. flush_workqueue(priv->wq);
  803. if (priv->fbdev) {
  804. rc = drm_fb_helper_restore_fbdev_mode_unlocked(priv->fbdev);
  805. if (rc)
  806. DRM_ERROR("restore FBDEV mode failed: %d\n", rc);
  807. } else if (kms->client.dev) {
  808. rc = drm_client_modeset_commit_force(&kms->client);
  809. if (rc)
  810. DRM_ERROR("client modeset commit failed: %d\n", rc);
  811. }
  812. if (kms && kms->funcs && kms->funcs->lastclose)
  813. kms->funcs->lastclose(kms);
  814. }
  815. static irqreturn_t msm_irq(int irq, void *arg)
  816. {
  817. struct drm_device *dev = arg;
  818. struct msm_drm_private *priv = dev->dev_private;
  819. struct msm_kms *kms = priv->kms;
  820. BUG_ON(!kms);
  821. return kms->funcs->irq(kms);
  822. }
  823. static void msm_irq_preinstall(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. kms->funcs->irq_preinstall(kms);
  829. }
  830. static int msm_irq_postinstall(struct drm_device *dev)
  831. {
  832. struct msm_drm_private *priv = dev->dev_private;
  833. struct msm_kms *kms = priv->kms;
  834. BUG_ON(!kms);
  835. if (kms->funcs->irq_postinstall)
  836. return kms->funcs->irq_postinstall(kms);
  837. return 0;
  838. }
  839. static void msm_irq_uninstall(struct drm_device *dev)
  840. {
  841. struct msm_drm_private *priv = dev->dev_private;
  842. struct msm_kms *kms = priv->kms;
  843. BUG_ON(!kms);
  844. kms->funcs->irq_uninstall(kms);
  845. }
  846. static int msm_enable_vblank(struct drm_device *dev, unsigned int pipe)
  847. {
  848. struct msm_drm_private *priv = dev->dev_private;
  849. struct msm_kms *kms = priv->kms;
  850. if (!kms)
  851. return -ENXIO;
  852. DBG("dev=%pK, crtc=%u", dev, pipe);
  853. return vblank_ctrl_queue_work(priv, pipe, true);
  854. }
  855. static void msm_disable_vblank(struct drm_device *dev, unsigned int pipe)
  856. {
  857. struct msm_drm_private *priv = dev->dev_private;
  858. struct msm_kms *kms = priv->kms;
  859. if (!kms)
  860. return;
  861. DBG("dev=%pK, crtc=%u", dev, pipe);
  862. vblank_ctrl_queue_work(priv, pipe, false);
  863. }
  864. /*
  865. * DRM ioctls:
  866. */
  867. static int msm_ioctl_gem_new(struct drm_device *dev, void *data,
  868. struct drm_file *file)
  869. {
  870. struct drm_msm_gem_new *args = data;
  871. if (args->flags & ~MSM_BO_FLAGS) {
  872. DRM_ERROR("invalid flags: %08x\n", args->flags);
  873. return -EINVAL;
  874. }
  875. return msm_gem_new_handle(dev, file, args->size,
  876. args->flags, &args->handle, NULL);
  877. }
  878. static inline ktime_t to_ktime(struct drm_msm_timespec timeout)
  879. {
  880. return ktime_set(timeout.tv_sec, timeout.tv_nsec);
  881. }
  882. static int msm_ioctl_gem_cpu_prep(struct drm_device *dev, void *data,
  883. struct drm_file *file)
  884. {
  885. struct drm_msm_gem_cpu_prep *args = data;
  886. struct drm_gem_object *obj;
  887. ktime_t timeout = to_ktime(args->timeout);
  888. int ret;
  889. if (args->op & ~MSM_PREP_FLAGS) {
  890. DRM_ERROR("invalid op: %08x\n", args->op);
  891. return -EINVAL;
  892. }
  893. obj = drm_gem_object_lookup(file, args->handle);
  894. if (!obj)
  895. return -ENOENT;
  896. ret = msm_gem_cpu_prep(obj, args->op, &timeout);
  897. drm_gem_object_put_unlocked(obj);
  898. return ret;
  899. }
  900. static int msm_ioctl_gem_cpu_fini(struct drm_device *dev, void *data,
  901. struct drm_file *file)
  902. {
  903. struct drm_msm_gem_cpu_fini *args = data;
  904. struct drm_gem_object *obj;
  905. int ret;
  906. obj = drm_gem_object_lookup(file, args->handle);
  907. if (!obj)
  908. return -ENOENT;
  909. ret = msm_gem_cpu_fini(obj);
  910. drm_gem_object_put_unlocked(obj);
  911. return ret;
  912. }
  913. static int msm_ioctl_gem_madvise(struct drm_device *dev, void *data,
  914. struct drm_file *file)
  915. {
  916. struct drm_msm_gem_madvise *args = data;
  917. struct drm_gem_object *obj;
  918. int ret;
  919. switch (args->madv) {
  920. case MSM_MADV_DONTNEED:
  921. case MSM_MADV_WILLNEED:
  922. break;
  923. default:
  924. return -EINVAL;
  925. }
  926. ret = mutex_lock_interruptible(&dev->struct_mutex);
  927. if (ret)
  928. return ret;
  929. obj = drm_gem_object_lookup(file, args->handle);
  930. if (!obj) {
  931. ret = -ENOENT;
  932. goto unlock;
  933. }
  934. ret = msm_gem_madvise(obj, args->madv);
  935. if (ret >= 0) {
  936. args->retained = ret;
  937. ret = 0;
  938. }
  939. drm_gem_object_put(obj);
  940. unlock:
  941. mutex_unlock(&dev->struct_mutex);
  942. return ret;
  943. }
  944. static int msm_drm_object_supports_event(struct drm_device *dev,
  945. struct drm_msm_event_req *req)
  946. {
  947. int ret = -EINVAL;
  948. struct drm_mode_object *arg_obj;
  949. arg_obj = drm_mode_object_find(dev, NULL, req->object_id,
  950. req->object_type);
  951. if (!arg_obj)
  952. return -ENOENT;
  953. switch (arg_obj->type) {
  954. case DRM_MODE_OBJECT_CRTC:
  955. case DRM_MODE_OBJECT_CONNECTOR:
  956. ret = 0;
  957. break;
  958. default:
  959. ret = -EOPNOTSUPP;
  960. break;
  961. }
  962. drm_mode_object_put(arg_obj);
  963. return ret;
  964. }
  965. static int msm_register_event(struct drm_device *dev,
  966. struct drm_msm_event_req *req, struct drm_file *file, bool en)
  967. {
  968. int ret = -EINVAL;
  969. struct msm_drm_private *priv = dev->dev_private;
  970. struct msm_kms *kms = priv->kms;
  971. struct drm_mode_object *arg_obj;
  972. arg_obj = drm_mode_object_find(dev, file, req->object_id,
  973. req->object_type);
  974. if (!arg_obj)
  975. return -ENOENT;
  976. ret = kms->funcs->register_events(kms, arg_obj, req->event, en);
  977. drm_mode_object_put(arg_obj);
  978. return ret;
  979. }
  980. static int msm_event_client_count(struct drm_device *dev,
  981. struct drm_msm_event_req *req_event, bool locked)
  982. {
  983. struct msm_drm_private *priv = dev->dev_private;
  984. unsigned long flag = 0;
  985. struct msm_drm_event *node;
  986. int count = 0;
  987. if (!locked)
  988. spin_lock_irqsave(&dev->event_lock, flag);
  989. list_for_each_entry(node, &priv->client_event_list, base.link) {
  990. if (node->event.type == req_event->event &&
  991. node->info.object_id == req_event->object_id)
  992. count++;
  993. }
  994. if (!locked)
  995. spin_unlock_irqrestore(&dev->event_lock, flag);
  996. return count;
  997. }
  998. static int msm_ioctl_register_event(struct drm_device *dev, void *data,
  999. struct drm_file *file)
  1000. {
  1001. struct msm_drm_private *priv = dev->dev_private;
  1002. struct drm_msm_event_req *req_event = data;
  1003. struct msm_drm_event *client, *node;
  1004. unsigned long flag = 0;
  1005. bool dup_request = false;
  1006. int ret = 0, count = 0;
  1007. ret = msm_drm_object_supports_event(dev, req_event);
  1008. if (ret) {
  1009. DRM_ERROR("unsupported event %x object %x object id %d\n",
  1010. req_event->event, req_event->object_type,
  1011. req_event->object_id);
  1012. return ret;
  1013. }
  1014. spin_lock_irqsave(&dev->event_lock, flag);
  1015. list_for_each_entry(node, &priv->client_event_list, base.link) {
  1016. if (node->base.file_priv != file)
  1017. continue;
  1018. if (node->event.type == req_event->event &&
  1019. node->info.object_id == req_event->object_id) {
  1020. DRM_DEBUG("duplicate request for event %x obj id %d\n",
  1021. node->event.type, node->info.object_id);
  1022. dup_request = true;
  1023. break;
  1024. }
  1025. }
  1026. spin_unlock_irqrestore(&dev->event_lock, flag);
  1027. if (dup_request)
  1028. return -EALREADY;
  1029. client = kzalloc(sizeof(*client), GFP_KERNEL);
  1030. if (!client)
  1031. return -ENOMEM;
  1032. client->base.file_priv = file;
  1033. client->base.event = &client->event;
  1034. client->event.type = req_event->event;
  1035. memcpy(&client->info, req_event, sizeof(client->info));
  1036. /* Get the count of clients that have registered for event.
  1037. * Event should be enabled for first client, for subsequent enable
  1038. * calls add to client list and return.
  1039. */
  1040. count = msm_event_client_count(dev, req_event, false);
  1041. /* Add current client to list */
  1042. spin_lock_irqsave(&dev->event_lock, flag);
  1043. list_add_tail(&client->base.link, &priv->client_event_list);
  1044. spin_unlock_irqrestore(&dev->event_lock, flag);
  1045. if (count)
  1046. return 0;
  1047. ret = msm_register_event(dev, req_event, file, true);
  1048. if (ret) {
  1049. DRM_ERROR("failed to enable event %x object %x object id %d\n",
  1050. req_event->event, req_event->object_type,
  1051. req_event->object_id);
  1052. spin_lock_irqsave(&dev->event_lock, flag);
  1053. list_del(&client->base.link);
  1054. spin_unlock_irqrestore(&dev->event_lock, flag);
  1055. kfree(client);
  1056. }
  1057. return ret;
  1058. }
  1059. static int msm_ioctl_deregister_event(struct drm_device *dev, void *data,
  1060. struct drm_file *file)
  1061. {
  1062. struct msm_drm_private *priv = dev->dev_private;
  1063. struct drm_msm_event_req *req_event = data;
  1064. struct msm_drm_event *client = NULL, *node, *temp;
  1065. unsigned long flag = 0;
  1066. int count = 0;
  1067. bool found = false;
  1068. int ret = 0;
  1069. ret = msm_drm_object_supports_event(dev, req_event);
  1070. if (ret) {
  1071. DRM_ERROR("unsupported event %x object %x object id %d\n",
  1072. req_event->event, req_event->object_type,
  1073. req_event->object_id);
  1074. return ret;
  1075. }
  1076. spin_lock_irqsave(&dev->event_lock, flag);
  1077. list_for_each_entry_safe(node, temp, &priv->client_event_list,
  1078. base.link) {
  1079. if (node->event.type == req_event->event &&
  1080. node->info.object_id == req_event->object_id &&
  1081. node->base.file_priv == file) {
  1082. client = node;
  1083. list_del(&client->base.link);
  1084. found = true;
  1085. kfree(client);
  1086. break;
  1087. }
  1088. }
  1089. spin_unlock_irqrestore(&dev->event_lock, flag);
  1090. if (!found)
  1091. return -ENOENT;
  1092. count = msm_event_client_count(dev, req_event, false);
  1093. if (!count)
  1094. ret = msm_register_event(dev, req_event, file, false);
  1095. return ret;
  1096. }
  1097. void msm_mode_object_event_notify(struct drm_mode_object *obj,
  1098. struct drm_device *dev, struct drm_event *event, u8 *payload)
  1099. {
  1100. struct msm_drm_private *priv = NULL;
  1101. unsigned long flags;
  1102. struct msm_drm_event *notify, *node;
  1103. int len = 0, ret;
  1104. if (!obj || !event || !event->length || !payload) {
  1105. DRM_ERROR("err param obj %pK event %pK len %d payload %pK\n",
  1106. obj, event, ((event) ? (event->length) : -1),
  1107. payload);
  1108. return;
  1109. }
  1110. priv = (dev) ? dev->dev_private : NULL;
  1111. if (!dev || !priv) {
  1112. DRM_ERROR("invalid dev %pK priv %pK\n", dev, priv);
  1113. return;
  1114. }
  1115. spin_lock_irqsave(&dev->event_lock, flags);
  1116. list_for_each_entry(node, &priv->client_event_list, base.link) {
  1117. if (node->event.type != event->type ||
  1118. obj->id != node->info.object_id)
  1119. continue;
  1120. len = event->length + sizeof(struct msm_drm_event);
  1121. if (node->base.file_priv->event_space < len) {
  1122. DRM_ERROR("Insufficient space %d for event %x len %d\n",
  1123. node->base.file_priv->event_space, event->type,
  1124. len);
  1125. continue;
  1126. }
  1127. notify = kzalloc(len, GFP_ATOMIC);
  1128. if (!notify)
  1129. continue;
  1130. notify->base.file_priv = node->base.file_priv;
  1131. notify->base.event = &notify->event;
  1132. notify->event.type = node->event.type;
  1133. notify->event.length = event->length +
  1134. sizeof(struct drm_msm_event_resp);
  1135. memcpy(&notify->info, &node->info, sizeof(notify->info));
  1136. memcpy(notify->data, payload, event->length);
  1137. ret = drm_event_reserve_init_locked(dev, node->base.file_priv,
  1138. &notify->base, &notify->event);
  1139. if (ret) {
  1140. kfree(notify);
  1141. continue;
  1142. }
  1143. drm_send_event_locked(dev, &notify->base);
  1144. }
  1145. spin_unlock_irqrestore(&dev->event_lock, flags);
  1146. }
  1147. static int msm_release(struct inode *inode, struct file *filp)
  1148. {
  1149. struct drm_file *file_priv = filp->private_data;
  1150. struct drm_minor *minor = file_priv->minor;
  1151. struct drm_device *dev = minor->dev;
  1152. struct msm_drm_private *priv = dev->dev_private;
  1153. struct msm_drm_event *node, *temp, *tmp_node;
  1154. u32 count;
  1155. unsigned long flags;
  1156. LIST_HEAD(tmp_head);
  1157. spin_lock_irqsave(&dev->event_lock, flags);
  1158. list_for_each_entry_safe(node, temp, &priv->client_event_list,
  1159. base.link) {
  1160. if (node->base.file_priv != file_priv)
  1161. continue;
  1162. list_del(&node->base.link);
  1163. list_add_tail(&node->base.link, &tmp_head);
  1164. }
  1165. spin_unlock_irqrestore(&dev->event_lock, flags);
  1166. list_for_each_entry_safe(node, temp, &tmp_head,
  1167. base.link) {
  1168. list_del(&node->base.link);
  1169. count = msm_event_client_count(dev, &node->info, false);
  1170. list_for_each_entry(tmp_node, &tmp_head, base.link) {
  1171. if (tmp_node->event.type == node->info.event &&
  1172. tmp_node->info.object_id ==
  1173. node->info.object_id)
  1174. count++;
  1175. }
  1176. if (!count)
  1177. msm_register_event(dev, &node->info, file_priv, false);
  1178. kfree(node);
  1179. }
  1180. return drm_release(inode, filp);
  1181. }
  1182. /**
  1183. * msm_ioctl_rmfb2 - remove an FB from the configuration
  1184. * @dev: drm device for the ioctl
  1185. * @data: data pointer for the ioctl
  1186. * @file_priv: drm file for the ioctl call
  1187. *
  1188. * Remove the FB specified by the user.
  1189. *
  1190. * Called by the user via ioctl.
  1191. *
  1192. * Returns:
  1193. * Zero on success, negative errno on failure.
  1194. */
  1195. int msm_ioctl_rmfb2(struct drm_device *dev, void *data,
  1196. struct drm_file *file_priv)
  1197. {
  1198. struct drm_framebuffer *fb = NULL;
  1199. struct drm_framebuffer *fbl = NULL;
  1200. uint32_t *id = data;
  1201. int found = 0;
  1202. if (!drm_core_check_feature(dev, DRIVER_MODESET))
  1203. return -EINVAL;
  1204. fb = drm_framebuffer_lookup(dev, file_priv, *id);
  1205. if (!fb)
  1206. return -ENOENT;
  1207. /* drop extra ref from traversing drm_framebuffer_lookup */
  1208. drm_framebuffer_put(fb);
  1209. mutex_lock(&file_priv->fbs_lock);
  1210. list_for_each_entry(fbl, &file_priv->fbs, filp_head)
  1211. if (fb == fbl)
  1212. found = 1;
  1213. if (!found) {
  1214. mutex_unlock(&file_priv->fbs_lock);
  1215. return -ENOENT;
  1216. }
  1217. list_del_init(&fb->filp_head);
  1218. mutex_unlock(&file_priv->fbs_lock);
  1219. drm_framebuffer_put(fb);
  1220. return 0;
  1221. }
  1222. EXPORT_SYMBOL(msm_ioctl_rmfb2);
  1223. /**
  1224. * msm_ioctl_power_ctrl - enable/disable power vote on MDSS Hw
  1225. * @dev: drm device for the ioctl
  1226. * @data: data pointer for the ioctl
  1227. * @file_priv: drm file for the ioctl call
  1228. *
  1229. */
  1230. int msm_ioctl_power_ctrl(struct drm_device *dev, void *data,
  1231. struct drm_file *file_priv)
  1232. {
  1233. struct msm_file_private *ctx = file_priv->driver_priv;
  1234. struct msm_drm_private *priv;
  1235. struct drm_msm_power_ctrl *power_ctrl = data;
  1236. bool vote_req = false;
  1237. int old_cnt;
  1238. int rc = 0;
  1239. if (unlikely(!power_ctrl)) {
  1240. DRM_ERROR("invalid ioctl data\n");
  1241. return -EINVAL;
  1242. }
  1243. priv = dev->dev_private;
  1244. mutex_lock(&ctx->power_lock);
  1245. old_cnt = ctx->enable_refcnt;
  1246. if (power_ctrl->enable) {
  1247. if (!ctx->enable_refcnt)
  1248. vote_req = true;
  1249. ctx->enable_refcnt++;
  1250. } else if (ctx->enable_refcnt) {
  1251. ctx->enable_refcnt--;
  1252. if (!ctx->enable_refcnt)
  1253. vote_req = true;
  1254. } else {
  1255. pr_err("ignoring, unbalanced disable\n");
  1256. }
  1257. if (vote_req) {
  1258. if (power_ctrl->enable)
  1259. rc = pm_runtime_get_sync(dev->dev);
  1260. else
  1261. pm_runtime_put_sync(dev->dev);
  1262. if (rc < 0)
  1263. ctx->enable_refcnt = old_cnt;
  1264. else
  1265. rc = 0;
  1266. }
  1267. pr_debug("pid %d enable %d, refcnt %d, vote_req %d\n",
  1268. current->pid, power_ctrl->enable, ctx->enable_refcnt,
  1269. vote_req);
  1270. SDE_EVT32(current->pid, power_ctrl->enable, ctx->enable_refcnt,
  1271. vote_req);
  1272. mutex_unlock(&ctx->power_lock);
  1273. return rc;
  1274. }
  1275. static const struct drm_ioctl_desc msm_ioctls[] = {
  1276. DRM_IOCTL_DEF_DRV(MSM_GEM_NEW, msm_ioctl_gem_new, DRM_AUTH|DRM_RENDER_ALLOW),
  1277. DRM_IOCTL_DEF_DRV(MSM_GEM_CPU_PREP, msm_ioctl_gem_cpu_prep, DRM_AUTH|DRM_RENDER_ALLOW),
  1278. DRM_IOCTL_DEF_DRV(MSM_GEM_CPU_FINI, msm_ioctl_gem_cpu_fini, DRM_AUTH|DRM_RENDER_ALLOW),
  1279. DRM_IOCTL_DEF_DRV(MSM_GEM_MADVISE, msm_ioctl_gem_madvise, DRM_AUTH|DRM_RENDER_ALLOW),
  1280. DRM_IOCTL_DEF_DRV(SDE_WB_CONFIG, sde_wb_config, DRM_UNLOCKED|DRM_AUTH),
  1281. DRM_IOCTL_DEF_DRV(MSM_REGISTER_EVENT, msm_ioctl_register_event,
  1282. DRM_UNLOCKED),
  1283. DRM_IOCTL_DEF_DRV(MSM_DEREGISTER_EVENT, msm_ioctl_deregister_event,
  1284. DRM_UNLOCKED),
  1285. DRM_IOCTL_DEF_DRV(MSM_RMFB2, msm_ioctl_rmfb2, DRM_UNLOCKED),
  1286. DRM_IOCTL_DEF_DRV(MSM_POWER_CTRL, msm_ioctl_power_ctrl,
  1287. DRM_RENDER_ALLOW),
  1288. };
  1289. static const struct vm_operations_struct vm_ops = {
  1290. .fault = msm_gem_fault,
  1291. .open = drm_gem_vm_open,
  1292. .close = drm_gem_vm_close,
  1293. };
  1294. static const struct file_operations fops = {
  1295. .owner = THIS_MODULE,
  1296. .open = drm_open,
  1297. .release = msm_release,
  1298. .unlocked_ioctl = drm_ioctl,
  1299. .compat_ioctl = drm_compat_ioctl,
  1300. .poll = drm_poll,
  1301. .read = drm_read,
  1302. .llseek = no_llseek,
  1303. .mmap = msm_gem_mmap,
  1304. };
  1305. static struct drm_driver msm_driver = {
  1306. .driver_features = DRIVER_GEM |
  1307. DRIVER_RENDER |
  1308. DRIVER_ATOMIC |
  1309. DRIVER_MODESET,
  1310. .open = msm_open,
  1311. .preclose = msm_preclose,
  1312. .postclose = msm_postclose,
  1313. .lastclose = msm_lastclose,
  1314. .irq_handler = msm_irq,
  1315. .irq_preinstall = msm_irq_preinstall,
  1316. .irq_postinstall = msm_irq_postinstall,
  1317. .irq_uninstall = msm_irq_uninstall,
  1318. .enable_vblank = msm_enable_vblank,
  1319. .disable_vblank = msm_disable_vblank,
  1320. .gem_free_object = msm_gem_free_object,
  1321. .gem_vm_ops = &vm_ops,
  1322. .dumb_create = msm_gem_dumb_create,
  1323. .dumb_map_offset = msm_gem_dumb_map_offset,
  1324. .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
  1325. .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
  1326. .gem_prime_export = drm_gem_prime_export,
  1327. .gem_prime_import = msm_gem_prime_import,
  1328. .gem_prime_pin = msm_gem_prime_pin,
  1329. .gem_prime_unpin = msm_gem_prime_unpin,
  1330. .gem_prime_get_sg_table = msm_gem_prime_get_sg_table,
  1331. .gem_prime_import_sg_table = msm_gem_prime_import_sg_table,
  1332. .gem_prime_vmap = msm_gem_prime_vmap,
  1333. .gem_prime_vunmap = msm_gem_prime_vunmap,
  1334. .gem_prime_mmap = msm_gem_prime_mmap,
  1335. .ioctls = msm_ioctls,
  1336. .num_ioctls = ARRAY_SIZE(msm_ioctls),
  1337. .fops = &fops,
  1338. .name = "msm_drm",
  1339. .desc = "MSM Snapdragon DRM",
  1340. .date = "20130625",
  1341. .major = MSM_VERSION_MAJOR,
  1342. .minor = MSM_VERSION_MINOR,
  1343. .patchlevel = MSM_VERSION_PATCHLEVEL,
  1344. };
  1345. #ifdef CONFIG_PM_SLEEP
  1346. static int msm_pm_suspend(struct device *dev)
  1347. {
  1348. struct drm_device *ddev;
  1349. struct msm_drm_private *priv;
  1350. struct msm_kms *kms;
  1351. if (!dev)
  1352. return -EINVAL;
  1353. ddev = dev_get_drvdata(dev);
  1354. if (!ddev || !ddev->dev_private)
  1355. return -EINVAL;
  1356. priv = ddev->dev_private;
  1357. kms = priv->kms;
  1358. if (kms && kms->funcs && kms->funcs->pm_suspend)
  1359. return kms->funcs->pm_suspend(dev);
  1360. /* disable hot-plug polling */
  1361. drm_kms_helper_poll_disable(ddev);
  1362. return 0;
  1363. }
  1364. static int msm_pm_resume(struct device *dev)
  1365. {
  1366. struct drm_device *ddev;
  1367. struct msm_drm_private *priv;
  1368. struct msm_kms *kms;
  1369. if (!dev)
  1370. return -EINVAL;
  1371. ddev = dev_get_drvdata(dev);
  1372. if (!ddev || !ddev->dev_private)
  1373. return -EINVAL;
  1374. priv = ddev->dev_private;
  1375. kms = priv->kms;
  1376. if (kms && kms->funcs && kms->funcs->pm_resume)
  1377. return kms->funcs->pm_resume(dev);
  1378. /* enable hot-plug polling */
  1379. drm_kms_helper_poll_enable(ddev);
  1380. return 0;
  1381. }
  1382. #endif
  1383. #ifdef CONFIG_PM
  1384. static int msm_runtime_suspend(struct device *dev)
  1385. {
  1386. struct drm_device *ddev = dev_get_drvdata(dev);
  1387. struct msm_drm_private *priv = ddev->dev_private;
  1388. DBG("");
  1389. if (priv->mdss)
  1390. msm_mdss_disable(priv->mdss);
  1391. else
  1392. sde_power_resource_enable(&priv->phandle, false);
  1393. return 0;
  1394. }
  1395. static int msm_runtime_resume(struct device *dev)
  1396. {
  1397. struct drm_device *ddev = dev_get_drvdata(dev);
  1398. struct msm_drm_private *priv = ddev->dev_private;
  1399. int ret;
  1400. DBG("");
  1401. if (priv->mdss)
  1402. ret = msm_mdss_enable(priv->mdss);
  1403. else
  1404. ret = sde_power_resource_enable(&priv->phandle, true);
  1405. return ret;
  1406. }
  1407. #endif
  1408. static const struct dev_pm_ops msm_pm_ops = {
  1409. SET_SYSTEM_SLEEP_PM_OPS(msm_pm_suspend, msm_pm_resume)
  1410. SET_RUNTIME_PM_OPS(msm_runtime_suspend, msm_runtime_resume, NULL)
  1411. };
  1412. /*
  1413. * Componentized driver support:
  1414. */
  1415. /*
  1416. * NOTE: duplication of the same code as exynos or imx (or probably any other).
  1417. * so probably some room for some helpers
  1418. */
  1419. static int compare_of(struct device *dev, void *data)
  1420. {
  1421. return dev->of_node == data;
  1422. }
  1423. /*
  1424. * Identify what components need to be added by parsing what remote-endpoints
  1425. * our MDP output ports are connected to. In the case of LVDS on MDP4, there
  1426. * is no external component that we need to add since LVDS is within MDP4
  1427. * itself.
  1428. */
  1429. static int add_components_mdp(struct device *mdp_dev,
  1430. struct component_match **matchptr)
  1431. {
  1432. struct device_node *np = mdp_dev->of_node;
  1433. struct device_node *ep_node;
  1434. struct device *master_dev;
  1435. /*
  1436. * on MDP4 based platforms, the MDP platform device is the component
  1437. * master that adds other display interface components to itself.
  1438. *
  1439. * on MDP5 based platforms, the MDSS platform device is the component
  1440. * master that adds MDP5 and other display interface components to
  1441. * itself.
  1442. */
  1443. if (of_device_is_compatible(np, "qcom,mdp4"))
  1444. master_dev = mdp_dev;
  1445. else
  1446. master_dev = mdp_dev->parent;
  1447. for_each_endpoint_of_node(np, ep_node) {
  1448. struct device_node *intf;
  1449. struct of_endpoint ep;
  1450. int ret;
  1451. ret = of_graph_parse_endpoint(ep_node, &ep);
  1452. if (ret) {
  1453. dev_err(mdp_dev, "unable to parse port endpoint\n");
  1454. of_node_put(ep_node);
  1455. return ret;
  1456. }
  1457. /*
  1458. * The LCDC/LVDS port on MDP4 is a speacial case where the
  1459. * remote-endpoint isn't a component that we need to add
  1460. */
  1461. if (of_device_is_compatible(np, "qcom,mdp4") &&
  1462. ep.port == 0)
  1463. continue;
  1464. /*
  1465. * It's okay if some of the ports don't have a remote endpoint
  1466. * specified. It just means that the port isn't connected to
  1467. * any external interface.
  1468. */
  1469. intf = of_graph_get_remote_port_parent(ep_node);
  1470. if (!intf)
  1471. continue;
  1472. if (of_device_is_available(intf))
  1473. drm_of_component_match_add(master_dev, matchptr,
  1474. compare_of, intf);
  1475. of_node_put(intf);
  1476. }
  1477. return 0;
  1478. }
  1479. static int compare_name_mdp(struct device *dev, void *data)
  1480. {
  1481. return (strnstr(dev_name(dev), "mdp", strlen("mdp")) != NULL);
  1482. }
  1483. static int add_display_components(struct device *dev,
  1484. struct component_match **matchptr)
  1485. {
  1486. struct device *mdp_dev = NULL;
  1487. struct device_node *node;
  1488. int ret;
  1489. if (of_device_is_compatible(dev->of_node, "qcom,sde-kms")) {
  1490. struct device_node *np = dev->of_node;
  1491. unsigned int i;
  1492. for (i = 0; ; i++) {
  1493. node = of_parse_phandle(np, "connectors", i);
  1494. if (!node)
  1495. break;
  1496. component_match_add(dev, matchptr, compare_of, node);
  1497. }
  1498. return 0;
  1499. }
  1500. /*
  1501. * MDP5 based devices don't have a flat hierarchy. There is a top level
  1502. * parent: MDSS, and children: MDP5, DSI, HDMI, eDP etc. Populate the
  1503. * children devices, find the MDP5 node, and then add the interfaces
  1504. * to our components list.
  1505. */
  1506. if (of_device_is_compatible(dev->of_node, "qcom,mdss")) {
  1507. ret = of_platform_populate(dev->of_node, NULL, NULL, dev);
  1508. if (ret) {
  1509. dev_err(dev, "failed to populate children devices\n");
  1510. return ret;
  1511. }
  1512. mdp_dev = device_find_child(dev, NULL, compare_name_mdp);
  1513. if (!mdp_dev) {
  1514. dev_err(dev, "failed to find MDSS MDP node\n");
  1515. of_platform_depopulate(dev);
  1516. return -ENODEV;
  1517. }
  1518. put_device(mdp_dev);
  1519. /* add the MDP component itself */
  1520. component_match_add(dev, matchptr, compare_of,
  1521. mdp_dev->of_node);
  1522. } else {
  1523. /* MDP4 */
  1524. mdp_dev = dev;
  1525. }
  1526. ret = add_components_mdp(mdp_dev, matchptr);
  1527. if (ret)
  1528. of_platform_depopulate(dev);
  1529. return ret;
  1530. }
  1531. struct msm_gem_address_space *
  1532. msm_gem_smmu_address_space_get(struct drm_device *dev,
  1533. unsigned int domain)
  1534. {
  1535. struct msm_drm_private *priv = NULL;
  1536. struct msm_kms *kms;
  1537. const struct msm_kms_funcs *funcs;
  1538. if ((!dev) || (!dev->dev_private))
  1539. return NULL;
  1540. priv = dev->dev_private;
  1541. kms = priv->kms;
  1542. if (!kms)
  1543. return NULL;
  1544. funcs = kms->funcs;
  1545. if ((!funcs) || (!funcs->get_address_space))
  1546. return NULL;
  1547. return funcs->get_address_space(priv->kms, domain);
  1548. }
  1549. int msm_get_mixer_count(struct msm_drm_private *priv,
  1550. const struct drm_display_mode *mode,
  1551. const struct msm_resource_caps_info *res, u32 *num_lm)
  1552. {
  1553. struct msm_kms *kms;
  1554. const struct msm_kms_funcs *funcs;
  1555. if (!priv) {
  1556. DRM_ERROR("invalid drm private struct\n");
  1557. return -EINVAL;
  1558. }
  1559. kms = priv->kms;
  1560. if (!kms) {
  1561. DRM_ERROR("invalid msm kms struct\n");
  1562. return -EINVAL;
  1563. }
  1564. funcs = kms->funcs;
  1565. if (!funcs || !funcs->get_mixer_count) {
  1566. DRM_ERROR("invalid function pointers\n");
  1567. return -EINVAL;
  1568. }
  1569. return funcs->get_mixer_count(priv->kms, mode, res, num_lm);
  1570. }
  1571. static int msm_drm_bind(struct device *dev)
  1572. {
  1573. return msm_drm_init(dev, &msm_driver);
  1574. }
  1575. static void msm_drm_unbind(struct device *dev)
  1576. {
  1577. msm_drm_uninit(dev);
  1578. }
  1579. static const struct component_master_ops msm_drm_ops = {
  1580. .bind = msm_drm_bind,
  1581. .unbind = msm_drm_unbind,
  1582. };
  1583. /*
  1584. * Platform driver:
  1585. */
  1586. static int msm_pdev_probe(struct platform_device *pdev)
  1587. {
  1588. int ret;
  1589. struct component_match *match = NULL;
  1590. ret = add_display_components(&pdev->dev, &match);
  1591. if (ret)
  1592. return ret;
  1593. if (!match)
  1594. return -ENODEV;
  1595. pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
  1596. return component_master_add_with_match(&pdev->dev, &msm_drm_ops, match);
  1597. }
  1598. static int msm_pdev_remove(struct platform_device *pdev)
  1599. {
  1600. component_master_del(&pdev->dev, &msm_drm_ops);
  1601. of_platform_depopulate(&pdev->dev);
  1602. msm_drm_unbind(&pdev->dev);
  1603. component_master_del(&pdev->dev, &msm_drm_ops);
  1604. return 0;
  1605. }
  1606. static void msm_pdev_shutdown(struct platform_device *pdev)
  1607. {
  1608. struct drm_device *ddev = platform_get_drvdata(pdev);
  1609. struct msm_drm_private *priv = NULL;
  1610. if (!ddev) {
  1611. DRM_ERROR("invalid drm device node\n");
  1612. return;
  1613. }
  1614. priv = ddev->dev_private;
  1615. if (!priv) {
  1616. DRM_ERROR("invalid msm drm private node\n");
  1617. return;
  1618. }
  1619. msm_lastclose(ddev);
  1620. /* set this after lastclose to allow kickoff from lastclose */
  1621. priv->shutdown_in_progress = true;
  1622. }
  1623. static const struct of_device_id dt_match[] = {
  1624. { .compatible = "qcom,mdp4", .data = (void *)KMS_MDP4 },
  1625. { .compatible = "qcom,mdss", .data = (void *)KMS_MDP5 },
  1626. { .compatible = "qcom,sde-kms", .data = (void *)KMS_SDE },
  1627. {},
  1628. };
  1629. MODULE_DEVICE_TABLE(of, dt_match);
  1630. static struct platform_driver msm_platform_driver = {
  1631. .probe = msm_pdev_probe,
  1632. .remove = msm_pdev_remove,
  1633. .shutdown = msm_pdev_shutdown,
  1634. .driver = {
  1635. .name = "msm_drm",
  1636. .of_match_table = dt_match,
  1637. .pm = &msm_pm_ops,
  1638. .suppress_bind_attrs = true,
  1639. },
  1640. };
  1641. static int __init msm_drm_register(void)
  1642. {
  1643. if (!modeset)
  1644. return -EINVAL;
  1645. DBG("init");
  1646. msm_smmu_driver_init();
  1647. msm_dsi_register();
  1648. msm_edp_register();
  1649. msm_hdmi_register();
  1650. return platform_driver_register(&msm_platform_driver);
  1651. }
  1652. static void __exit msm_drm_unregister(void)
  1653. {
  1654. DBG("fini");
  1655. platform_driver_unregister(&msm_platform_driver);
  1656. msm_hdmi_unregister();
  1657. msm_edp_unregister();
  1658. msm_dsi_unregister();
  1659. msm_smmu_driver_cleanup();
  1660. }
  1661. module_init(msm_drm_register);
  1662. module_exit(msm_drm_unregister);
  1663. MODULE_AUTHOR("Rob Clark <[email protected]");
  1664. MODULE_DESCRIPTION("MSM DRM Driver");
  1665. MODULE_LICENSE("GPL");