drm_drv.c 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275
  1. /*
  2. * Created: Fri Jan 19 10:48:35 2001 by faith@acm.org
  3. *
  4. * Copyright 2001 VA Linux Systems, Inc., Sunnyvale, California.
  5. * All Rights Reserved.
  6. *
  7. * Author Rickard E. (Rik) Faith <faith@valinux.com>
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a
  10. * copy of this software and associated documentation files (the "Software"),
  11. * to deal in the Software without restriction, including without limitation
  12. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  13. * and/or sell copies of the Software, and to permit persons to whom the
  14. * Software is furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice (including the next
  17. * paragraph) shall be included in all copies or substantial portions of the
  18. * Software.
  19. *
  20. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  21. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  22. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  23. * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  24. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  25. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  26. * DEALINGS IN THE SOFTWARE.
  27. */
  28. #include <linux/bitops.h>
  29. #include <linux/cgroup_dmem.h>
  30. #include <linux/debugfs.h>
  31. #include <linux/export.h>
  32. #include <linux/fs.h>
  33. #include <linux/module.h>
  34. #include <linux/moduleparam.h>
  35. #include <linux/mount.h>
  36. #include <linux/pseudo_fs.h>
  37. #include <linux/sched.h>
  38. #include <linux/slab.h>
  39. #include <linux/sprintf.h>
  40. #include <linux/srcu.h>
  41. #include <linux/xarray.h>
  42. #include <drm/drm_accel.h>
  43. #include <drm/drm_bridge.h>
  44. #include <drm/drm_cache.h>
  45. #include <drm/drm_client_event.h>
  46. #include <drm/drm_color_mgmt.h>
  47. #include <drm/drm_drv.h>
  48. #include <drm/drm_file.h>
  49. #include <drm/drm_managed.h>
  50. #include <drm/drm_mode_object.h>
  51. #include <drm/drm_panic.h>
  52. #include <drm/drm_print.h>
  53. #include <drm/drm_privacy_screen_machine.h>
  54. #include "drm_crtc_internal.h"
  55. #include "drm_internal.h"
  56. MODULE_AUTHOR("Gareth Hughes, Leif Delgass, José Fonseca, Jon Smirl");
  57. MODULE_DESCRIPTION("DRM shared core routines");
  58. MODULE_LICENSE("GPL and additional rights");
  59. DEFINE_XARRAY_ALLOC(drm_minors_xa);
  60. /*
  61. * If the drm core fails to init for whatever reason,
  62. * we should prevent any drivers from registering with it.
  63. * It's best to check this at drm_dev_init(), as some drivers
  64. * prefer to embed struct drm_device into their own device
  65. * structure and call drm_dev_init() themselves.
  66. */
  67. static bool drm_core_init_complete;
  68. DEFINE_STATIC_SRCU(drm_unplug_srcu);
  69. /*
  70. * DRM Minors
  71. * A DRM device can provide several char-dev interfaces on the DRM-Major. Each
  72. * of them is represented by a drm_minor object. Depending on the capabilities
  73. * of the device-driver, different interfaces are registered.
  74. *
  75. * Minors can be accessed via dev->$minor_name. This pointer is either
  76. * NULL or a valid drm_minor pointer and stays valid as long as the device is
  77. * valid. This means, DRM minors have the same life-time as the underlying
  78. * device. However, this doesn't mean that the minor is active. Minors are
  79. * registered and unregistered dynamically according to device-state.
  80. */
  81. static struct xarray *drm_minor_get_xa(enum drm_minor_type type)
  82. {
  83. if (type == DRM_MINOR_PRIMARY || type == DRM_MINOR_RENDER)
  84. return &drm_minors_xa;
  85. #if IS_ENABLED(CONFIG_DRM_ACCEL)
  86. else if (type == DRM_MINOR_ACCEL)
  87. return &accel_minors_xa;
  88. #endif
  89. else
  90. return ERR_PTR(-EOPNOTSUPP);
  91. }
  92. static struct drm_minor **drm_minor_get_slot(struct drm_device *dev,
  93. enum drm_minor_type type)
  94. {
  95. switch (type) {
  96. case DRM_MINOR_PRIMARY:
  97. return &dev->primary;
  98. case DRM_MINOR_RENDER:
  99. return &dev->render;
  100. case DRM_MINOR_ACCEL:
  101. return &dev->accel;
  102. default:
  103. BUG();
  104. }
  105. }
  106. static void drm_minor_alloc_release(struct drm_device *dev, void *data)
  107. {
  108. struct drm_minor *minor = data;
  109. WARN_ON(dev != minor->dev);
  110. put_device(minor->kdev);
  111. xa_erase(drm_minor_get_xa(minor->type), minor->index);
  112. }
  113. /*
  114. * DRM used to support 64 devices, for backwards compatibility we need to maintain the
  115. * minor allocation scheme where minors 0-63 are primary nodes, 64-127 are control nodes,
  116. * and 128-191 are render nodes.
  117. * After reaching the limit, we're allocating minors dynamically - first-come, first-serve.
  118. * Accel nodes are using a distinct major, so the minors are allocated in continuous 0-MAX
  119. * range.
  120. */
  121. #define DRM_MINOR_LIMIT(t) ({ \
  122. typeof(t) _t = (t); \
  123. _t == DRM_MINOR_ACCEL ? XA_LIMIT(0, ACCEL_MAX_MINORS) : XA_LIMIT(64 * _t, 64 * _t + 63); \
  124. })
  125. #define DRM_EXTENDED_MINOR_LIMIT XA_LIMIT(192, (1 << MINORBITS) - 1)
  126. static int drm_minor_alloc(struct drm_device *dev, enum drm_minor_type type)
  127. {
  128. struct drm_minor *minor;
  129. int r;
  130. minor = drmm_kzalloc(dev, sizeof(*minor), GFP_KERNEL);
  131. if (!minor)
  132. return -ENOMEM;
  133. minor->type = type;
  134. minor->dev = dev;
  135. r = xa_alloc(drm_minor_get_xa(type), &minor->index,
  136. NULL, DRM_MINOR_LIMIT(type), GFP_KERNEL);
  137. if (r == -EBUSY && (type == DRM_MINOR_PRIMARY || type == DRM_MINOR_RENDER))
  138. r = xa_alloc(&drm_minors_xa, &minor->index,
  139. NULL, DRM_EXTENDED_MINOR_LIMIT, GFP_KERNEL);
  140. if (r < 0)
  141. return r;
  142. r = drmm_add_action_or_reset(dev, drm_minor_alloc_release, minor);
  143. if (r)
  144. return r;
  145. minor->kdev = drm_sysfs_minor_alloc(minor);
  146. if (IS_ERR(minor->kdev))
  147. return PTR_ERR(minor->kdev);
  148. *drm_minor_get_slot(dev, type) = minor;
  149. return 0;
  150. }
  151. static int drm_minor_register(struct drm_device *dev, enum drm_minor_type type)
  152. {
  153. struct drm_minor *minor;
  154. void *entry;
  155. int ret;
  156. DRM_DEBUG("\n");
  157. minor = *drm_minor_get_slot(dev, type);
  158. if (!minor)
  159. return 0;
  160. if (minor->type != DRM_MINOR_ACCEL) {
  161. ret = drm_debugfs_register(minor, minor->index);
  162. if (ret) {
  163. DRM_ERROR("DRM: Failed to initialize /sys/kernel/debug/dri.\n");
  164. goto err_debugfs;
  165. }
  166. }
  167. ret = device_add(minor->kdev);
  168. if (ret)
  169. goto err_debugfs;
  170. /* replace NULL with @minor so lookups will succeed from now on */
  171. entry = xa_store(drm_minor_get_xa(type), minor->index, minor, GFP_KERNEL);
  172. if (xa_is_err(entry)) {
  173. ret = xa_err(entry);
  174. goto err_debugfs;
  175. }
  176. WARN_ON(entry);
  177. DRM_DEBUG("new minor registered %d\n", minor->index);
  178. return 0;
  179. err_debugfs:
  180. drm_debugfs_unregister(minor);
  181. return ret;
  182. }
  183. static void drm_minor_unregister(struct drm_device *dev, enum drm_minor_type type)
  184. {
  185. struct drm_minor *minor;
  186. minor = *drm_minor_get_slot(dev, type);
  187. if (!minor || !device_is_registered(minor->kdev))
  188. return;
  189. /* replace @minor with NULL so lookups will fail from now on */
  190. xa_store(drm_minor_get_xa(type), minor->index, NULL, GFP_KERNEL);
  191. device_del(minor->kdev);
  192. dev_set_drvdata(minor->kdev, NULL); /* safety belt */
  193. drm_debugfs_unregister(minor);
  194. }
  195. /*
  196. * Looks up the given minor-ID and returns the respective DRM-minor object. The
  197. * refence-count of the underlying device is increased so you must release this
  198. * object with drm_minor_release().
  199. *
  200. * As long as you hold this minor, it is guaranteed that the object and the
  201. * minor->dev pointer will stay valid! However, the device may get unplugged and
  202. * unregistered while you hold the minor.
  203. */
  204. struct drm_minor *drm_minor_acquire(struct xarray *minor_xa, unsigned int minor_id)
  205. {
  206. struct drm_minor *minor;
  207. xa_lock(minor_xa);
  208. minor = xa_load(minor_xa, minor_id);
  209. if (minor)
  210. drm_dev_get(minor->dev);
  211. xa_unlock(minor_xa);
  212. if (!minor) {
  213. return ERR_PTR(-ENODEV);
  214. } else if (drm_dev_is_unplugged(minor->dev)) {
  215. drm_dev_put(minor->dev);
  216. return ERR_PTR(-ENODEV);
  217. }
  218. return minor;
  219. }
  220. void drm_minor_release(struct drm_minor *minor)
  221. {
  222. drm_dev_put(minor->dev);
  223. }
  224. /**
  225. * DOC: driver instance overview
  226. *
  227. * A device instance for a drm driver is represented by &struct drm_device. This
  228. * is allocated and initialized with devm_drm_dev_alloc(), usually from
  229. * bus-specific ->probe() callbacks implemented by the driver. The driver then
  230. * needs to initialize all the various subsystems for the drm device like memory
  231. * management, vblank handling, modesetting support and initial output
  232. * configuration plus obviously initialize all the corresponding hardware bits.
  233. * Finally when everything is up and running and ready for userspace the device
  234. * instance can be published using drm_dev_register().
  235. *
  236. * There is also deprecated support for initializing device instances using
  237. * bus-specific helpers and the &drm_driver.load callback. But due to
  238. * backwards-compatibility needs the device instance have to be published too
  239. * early, which requires unpretty global locking to make safe and is therefore
  240. * only support for existing drivers not yet converted to the new scheme.
  241. *
  242. * When cleaning up a device instance everything needs to be done in reverse:
  243. * First unpublish the device instance with drm_dev_unregister(). Then clean up
  244. * any other resources allocated at device initialization and drop the driver's
  245. * reference to &drm_device using drm_dev_put().
  246. *
  247. * Note that any allocation or resource which is visible to userspace must be
  248. * released only when the final drm_dev_put() is called, and not when the
  249. * driver is unbound from the underlying physical struct &device. Best to use
  250. * &drm_device managed resources with drmm_add_action(), drmm_kmalloc() and
  251. * related functions.
  252. *
  253. * devres managed resources like devm_kmalloc() can only be used for resources
  254. * directly related to the underlying hardware device, and only used in code
  255. * paths fully protected by drm_dev_enter() and drm_dev_exit().
  256. *
  257. * Display driver example
  258. * ~~~~~~~~~~~~~~~~~~~~~~
  259. *
  260. * The following example shows a typical structure of a DRM display driver.
  261. * The example focus on the probe() function and the other functions that is
  262. * almost always present and serves as a demonstration of devm_drm_dev_alloc().
  263. *
  264. * .. code-block:: c
  265. *
  266. * struct driver_device {
  267. * struct drm_device drm;
  268. * void *userspace_facing;
  269. * struct clk *pclk;
  270. * };
  271. *
  272. * static const struct drm_driver driver_drm_driver = {
  273. * [...]
  274. * };
  275. *
  276. * static int driver_probe(struct platform_device *pdev)
  277. * {
  278. * struct driver_device *priv;
  279. * struct drm_device *drm;
  280. * int ret;
  281. *
  282. * priv = devm_drm_dev_alloc(&pdev->dev, &driver_drm_driver,
  283. * struct driver_device, drm);
  284. * if (IS_ERR(priv))
  285. * return PTR_ERR(priv);
  286. * drm = &priv->drm;
  287. *
  288. * ret = drmm_mode_config_init(drm);
  289. * if (ret)
  290. * return ret;
  291. *
  292. * priv->userspace_facing = drmm_kzalloc(..., GFP_KERNEL);
  293. * if (!priv->userspace_facing)
  294. * return -ENOMEM;
  295. *
  296. * priv->pclk = devm_clk_get(dev, "PCLK");
  297. * if (IS_ERR(priv->pclk))
  298. * return PTR_ERR(priv->pclk);
  299. *
  300. * // Further setup, display pipeline etc
  301. *
  302. * platform_set_drvdata(pdev, drm);
  303. *
  304. * drm_mode_config_reset(drm);
  305. *
  306. * ret = drm_dev_register(drm);
  307. * if (ret)
  308. * return ret;
  309. *
  310. * drm_fbdev_{...}_setup(drm, 32);
  311. *
  312. * return 0;
  313. * }
  314. *
  315. * // This function is called before the devm_ resources are released
  316. * static int driver_remove(struct platform_device *pdev)
  317. * {
  318. * struct drm_device *drm = platform_get_drvdata(pdev);
  319. *
  320. * drm_dev_unregister(drm);
  321. * drm_atomic_helper_shutdown(drm)
  322. *
  323. * return 0;
  324. * }
  325. *
  326. * // This function is called on kernel restart and shutdown
  327. * static void driver_shutdown(struct platform_device *pdev)
  328. * {
  329. * drm_atomic_helper_shutdown(platform_get_drvdata(pdev));
  330. * }
  331. *
  332. * static int __maybe_unused driver_pm_suspend(struct device *dev)
  333. * {
  334. * return drm_mode_config_helper_suspend(dev_get_drvdata(dev));
  335. * }
  336. *
  337. * static int __maybe_unused driver_pm_resume(struct device *dev)
  338. * {
  339. * drm_mode_config_helper_resume(dev_get_drvdata(dev));
  340. *
  341. * return 0;
  342. * }
  343. *
  344. * static const struct dev_pm_ops driver_pm_ops = {
  345. * SET_SYSTEM_SLEEP_PM_OPS(driver_pm_suspend, driver_pm_resume)
  346. * };
  347. *
  348. * static struct platform_driver driver_driver = {
  349. * .driver = {
  350. * [...]
  351. * .pm = &driver_pm_ops,
  352. * },
  353. * .probe = driver_probe,
  354. * .remove = driver_remove,
  355. * .shutdown = driver_shutdown,
  356. * };
  357. * module_platform_driver(driver_driver);
  358. *
  359. * Drivers that want to support device unplugging (USB, DT overlay unload) should
  360. * use drm_dev_unplug() instead of drm_dev_unregister(). The driver must protect
  361. * regions that is accessing device resources to prevent use after they're
  362. * released. This is done using drm_dev_enter() and drm_dev_exit(). There is one
  363. * shortcoming however, drm_dev_unplug() marks the drm_device as unplugged before
  364. * drm_atomic_helper_shutdown() is called. This means that if the disable code
  365. * paths are protected, they will not run on regular driver module unload,
  366. * possibly leaving the hardware enabled.
  367. */
  368. /**
  369. * drm_put_dev - Unregister and release a DRM device
  370. * @dev: DRM device
  371. *
  372. * Called at module unload time or when a PCI device is unplugged.
  373. *
  374. * Cleans up all DRM device, calling drm_lastclose().
  375. *
  376. * Note: Use of this function is deprecated. It will eventually go away
  377. * completely. Please use drm_dev_unregister() and drm_dev_put() explicitly
  378. * instead to make sure that the device isn't userspace accessible any more
  379. * while teardown is in progress, ensuring that userspace can't access an
  380. * inconsistent state.
  381. */
  382. void drm_put_dev(struct drm_device *dev)
  383. {
  384. DRM_DEBUG("\n");
  385. if (!dev) {
  386. DRM_ERROR("cleanup called no dev\n");
  387. return;
  388. }
  389. drm_dev_unregister(dev);
  390. drm_dev_put(dev);
  391. }
  392. EXPORT_SYMBOL(drm_put_dev);
  393. /**
  394. * drm_dev_enter - Enter device critical section
  395. * @dev: DRM device
  396. * @idx: Pointer to index that will be passed to the matching drm_dev_exit()
  397. *
  398. * This function marks and protects the beginning of a section that should not
  399. * be entered after the device has been unplugged. The section end is marked
  400. * with drm_dev_exit(). Calls to this function can be nested.
  401. *
  402. * Returns:
  403. * True if it is OK to enter the section, false otherwise.
  404. */
  405. bool drm_dev_enter(struct drm_device *dev, int *idx)
  406. {
  407. *idx = srcu_read_lock(&drm_unplug_srcu);
  408. if (dev->unplugged) {
  409. srcu_read_unlock(&drm_unplug_srcu, *idx);
  410. return false;
  411. }
  412. return true;
  413. }
  414. EXPORT_SYMBOL(drm_dev_enter);
  415. /**
  416. * drm_dev_exit - Exit device critical section
  417. * @idx: index returned from drm_dev_enter()
  418. *
  419. * This function marks the end of a section that should not be entered after
  420. * the device has been unplugged.
  421. */
  422. void drm_dev_exit(int idx)
  423. {
  424. srcu_read_unlock(&drm_unplug_srcu, idx);
  425. }
  426. EXPORT_SYMBOL(drm_dev_exit);
  427. /**
  428. * drm_dev_unplug - unplug a DRM device
  429. * @dev: DRM device
  430. *
  431. * This unplugs a hotpluggable DRM device, which makes it inaccessible to
  432. * userspace operations. Entry-points can use drm_dev_enter() and
  433. * drm_dev_exit() to protect device resources in a race free manner. This
  434. * essentially unregisters the device like drm_dev_unregister(), but can be
  435. * called while there are still open users of @dev.
  436. */
  437. void drm_dev_unplug(struct drm_device *dev)
  438. {
  439. /*
  440. * After synchronizing any critical read section is guaranteed to see
  441. * the new value of ->unplugged, and any critical section which might
  442. * still have seen the old value of ->unplugged is guaranteed to have
  443. * finished.
  444. */
  445. dev->unplugged = true;
  446. synchronize_srcu(&drm_unplug_srcu);
  447. drm_dev_unregister(dev);
  448. /* Clear all CPU mappings pointing to this device */
  449. unmap_mapping_range(dev->anon_inode->i_mapping, 0, 0, 1);
  450. }
  451. EXPORT_SYMBOL(drm_dev_unplug);
  452. /**
  453. * drm_dev_set_dma_dev - set the DMA device for a DRM device
  454. * @dev: DRM device
  455. * @dma_dev: DMA device or NULL
  456. *
  457. * Sets the DMA device of the given DRM device. Only required if
  458. * the DMA device is different from the DRM device's parent. After
  459. * calling this function, the DRM device holds a reference on
  460. * @dma_dev. Pass NULL to clear the DMA device.
  461. */
  462. void drm_dev_set_dma_dev(struct drm_device *dev, struct device *dma_dev)
  463. {
  464. dma_dev = get_device(dma_dev);
  465. put_device(dev->dma_dev);
  466. dev->dma_dev = dma_dev;
  467. }
  468. EXPORT_SYMBOL(drm_dev_set_dma_dev);
  469. /*
  470. * Available recovery methods for wedged device. To be sent along with device
  471. * wedged uevent.
  472. */
  473. static const char *drm_get_wedge_recovery(unsigned int opt)
  474. {
  475. switch (BIT(opt)) {
  476. case DRM_WEDGE_RECOVERY_NONE:
  477. return "none";
  478. case DRM_WEDGE_RECOVERY_REBIND:
  479. return "rebind";
  480. case DRM_WEDGE_RECOVERY_BUS_RESET:
  481. return "bus-reset";
  482. case DRM_WEDGE_RECOVERY_VENDOR:
  483. return "vendor-specific";
  484. default:
  485. return NULL;
  486. }
  487. }
  488. #define WEDGE_STR_LEN 32
  489. #define PID_STR_LEN 15
  490. #define COMM_STR_LEN (TASK_COMM_LEN + 5)
  491. /**
  492. * drm_dev_wedged_event - generate a device wedged uevent
  493. * @dev: DRM device
  494. * @method: method(s) to be used for recovery
  495. * @info: optional information about the guilty task
  496. *
  497. * This generates a device wedged uevent for the DRM device specified by @dev.
  498. * Recovery @method\(s) of choice will be sent in the uevent environment as
  499. * ``WEDGED=<method1>[,..,<methodN>]`` in order of less to more side-effects.
  500. * If caller is unsure about recovery or @method is unknown (0),
  501. * ``WEDGED=unknown`` will be sent instead.
  502. *
  503. * Refer to "Device Wedging" chapter in Documentation/gpu/drm-uapi.rst for more
  504. * details.
  505. *
  506. * Returns: 0 on success, negative error code otherwise.
  507. */
  508. int drm_dev_wedged_event(struct drm_device *dev, unsigned long method,
  509. struct drm_wedge_task_info *info)
  510. {
  511. char event_string[WEDGE_STR_LEN], pid_string[PID_STR_LEN], comm_string[COMM_STR_LEN];
  512. char *envp[] = { event_string, NULL, NULL, NULL };
  513. const char *recovery = NULL;
  514. unsigned int len, opt;
  515. len = scnprintf(event_string, sizeof(event_string), "%s", "WEDGED=");
  516. for_each_set_bit(opt, &method, BITS_PER_TYPE(method)) {
  517. recovery = drm_get_wedge_recovery(opt);
  518. if (drm_WARN_ONCE(dev, !recovery, "invalid recovery method %u\n", opt))
  519. break;
  520. len += scnprintf(event_string + len, sizeof(event_string) - len, "%s,", recovery);
  521. }
  522. if (recovery)
  523. /* Get rid of trailing comma */
  524. event_string[len - 1] = '\0';
  525. else
  526. /* Caller is unsure about recovery, do the best we can at this point. */
  527. snprintf(event_string, sizeof(event_string), "%s", "WEDGED=unknown");
  528. drm_info(dev, "device wedged, %s\n", method == DRM_WEDGE_RECOVERY_NONE ?
  529. "but recovered through reset" : "needs recovery");
  530. if (info && (info->comm[0] != '\0') && (info->pid >= 0)) {
  531. snprintf(pid_string, sizeof(pid_string), "PID=%u", info->pid);
  532. snprintf(comm_string, sizeof(comm_string), "TASK=%s", info->comm);
  533. envp[1] = pid_string;
  534. envp[2] = comm_string;
  535. }
  536. return kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE, envp);
  537. }
  538. EXPORT_SYMBOL(drm_dev_wedged_event);
  539. /*
  540. * DRM internal mount
  541. * We want to be able to allocate our own "struct address_space" to control
  542. * memory-mappings in VRAM (or stolen RAM, ...). However, core MM does not allow
  543. * stand-alone address_space objects, so we need an underlying inode. As there
  544. * is no way to allocate an independent inode easily, we need a fake internal
  545. * VFS mount-point.
  546. *
  547. * The drm_fs_inode_new() function allocates a new inode, drm_fs_inode_free()
  548. * frees it again. You are allowed to use iget() and iput() to get references to
  549. * the inode. But each drm_fs_inode_new() call must be paired with exactly one
  550. * drm_fs_inode_free() call (which does not have to be the last iput()).
  551. * We use drm_fs_inode_*() to manage our internal VFS mount-point and share it
  552. * between multiple inode-users. You could, technically, call
  553. * iget() + drm_fs_inode_free() directly after alloc and sometime later do an
  554. * iput(), but this way you'd end up with a new vfsmount for each inode.
  555. */
  556. static int drm_fs_cnt;
  557. static struct vfsmount *drm_fs_mnt;
  558. static int drm_fs_init_fs_context(struct fs_context *fc)
  559. {
  560. return init_pseudo(fc, 0x010203ff) ? 0 : -ENOMEM;
  561. }
  562. static struct file_system_type drm_fs_type = {
  563. .name = "drm",
  564. .owner = THIS_MODULE,
  565. .init_fs_context = drm_fs_init_fs_context,
  566. .kill_sb = kill_anon_super,
  567. };
  568. static struct inode *drm_fs_inode_new(void)
  569. {
  570. struct inode *inode;
  571. int r;
  572. r = simple_pin_fs(&drm_fs_type, &drm_fs_mnt, &drm_fs_cnt);
  573. if (r < 0) {
  574. DRM_ERROR("Cannot mount pseudo fs: %d\n", r);
  575. return ERR_PTR(r);
  576. }
  577. inode = alloc_anon_inode(drm_fs_mnt->mnt_sb);
  578. if (IS_ERR(inode))
  579. simple_release_fs(&drm_fs_mnt, &drm_fs_cnt);
  580. return inode;
  581. }
  582. static void drm_fs_inode_free(struct inode *inode)
  583. {
  584. if (inode) {
  585. iput(inode);
  586. simple_release_fs(&drm_fs_mnt, &drm_fs_cnt);
  587. }
  588. }
  589. /**
  590. * DOC: component helper usage recommendations
  591. *
  592. * DRM drivers that drive hardware where a logical device consists of a pile of
  593. * independent hardware blocks are recommended to use the :ref:`component helper
  594. * library<component>`. For consistency and better options for code reuse the
  595. * following guidelines apply:
  596. *
  597. * - The entire device initialization procedure should be run from the
  598. * &component_master_ops.master_bind callback, starting with
  599. * devm_drm_dev_alloc(), then binding all components with
  600. * component_bind_all() and finishing with drm_dev_register().
  601. *
  602. * - The opaque pointer passed to all components through component_bind_all()
  603. * should point at &struct drm_device of the device instance, not some driver
  604. * specific private structure.
  605. *
  606. * - The component helper fills the niche where further standardization of
  607. * interfaces is not practical. When there already is, or will be, a
  608. * standardized interface like &drm_bridge or &drm_panel, providing its own
  609. * functions to find such components at driver load time, like
  610. * drm_of_find_panel_or_bridge(), then the component helper should not be
  611. * used.
  612. */
  613. static void drm_dev_init_release(struct drm_device *dev, void *res)
  614. {
  615. drm_fs_inode_free(dev->anon_inode);
  616. put_device(dev->dma_dev);
  617. dev->dma_dev = NULL;
  618. put_device(dev->dev);
  619. /* Prevent use-after-free in drm_managed_release when debugging is
  620. * enabled. Slightly awkward, but can't really be helped. */
  621. dev->dev = NULL;
  622. mutex_destroy(&dev->master_mutex);
  623. mutex_destroy(&dev->clientlist_mutex);
  624. mutex_destroy(&dev->filelist_mutex);
  625. }
  626. static int drm_dev_init(struct drm_device *dev,
  627. const struct drm_driver *driver,
  628. struct device *parent)
  629. {
  630. struct inode *inode;
  631. int ret;
  632. if (!drm_core_init_complete) {
  633. DRM_ERROR("DRM core is not initialized\n");
  634. return -ENODEV;
  635. }
  636. if (WARN_ON(!parent))
  637. return -EINVAL;
  638. kref_init(&dev->ref);
  639. dev->dev = get_device(parent);
  640. dev->driver = driver;
  641. INIT_LIST_HEAD(&dev->managed.resources);
  642. spin_lock_init(&dev->managed.lock);
  643. /* no per-device feature limits by default */
  644. dev->driver_features = ~0u;
  645. if (drm_core_check_feature(dev, DRIVER_COMPUTE_ACCEL) &&
  646. (drm_core_check_feature(dev, DRIVER_RENDER) ||
  647. drm_core_check_feature(dev, DRIVER_MODESET))) {
  648. DRM_ERROR("DRM driver can't be both a compute acceleration and graphics driver\n");
  649. return -EINVAL;
  650. }
  651. INIT_LIST_HEAD(&dev->filelist);
  652. INIT_LIST_HEAD(&dev->filelist_internal);
  653. INIT_LIST_HEAD(&dev->clientlist);
  654. INIT_LIST_HEAD(&dev->client_sysrq_list);
  655. INIT_LIST_HEAD(&dev->vblank_event_list);
  656. spin_lock_init(&dev->event_lock);
  657. mutex_init(&dev->filelist_mutex);
  658. mutex_init(&dev->clientlist_mutex);
  659. mutex_init(&dev->master_mutex);
  660. raw_spin_lock_init(&dev->mode_config.panic_lock);
  661. ret = drmm_add_action_or_reset(dev, drm_dev_init_release, NULL);
  662. if (ret)
  663. return ret;
  664. inode = drm_fs_inode_new();
  665. if (IS_ERR(inode)) {
  666. ret = PTR_ERR(inode);
  667. DRM_ERROR("Cannot allocate anonymous inode: %d\n", ret);
  668. goto err;
  669. }
  670. dev->anon_inode = inode;
  671. if (drm_core_check_feature(dev, DRIVER_COMPUTE_ACCEL)) {
  672. ret = drm_minor_alloc(dev, DRM_MINOR_ACCEL);
  673. if (ret)
  674. goto err;
  675. } else {
  676. if (drm_core_check_feature(dev, DRIVER_RENDER)) {
  677. ret = drm_minor_alloc(dev, DRM_MINOR_RENDER);
  678. if (ret)
  679. goto err;
  680. }
  681. ret = drm_minor_alloc(dev, DRM_MINOR_PRIMARY);
  682. if (ret)
  683. goto err;
  684. }
  685. if (drm_core_check_feature(dev, DRIVER_GEM)) {
  686. ret = drm_gem_init(dev);
  687. if (ret) {
  688. DRM_ERROR("Cannot initialize graphics execution manager (GEM)\n");
  689. goto err;
  690. }
  691. }
  692. dev->unique = drmm_kstrdup(dev, dev_name(parent), GFP_KERNEL);
  693. if (!dev->unique) {
  694. ret = -ENOMEM;
  695. goto err;
  696. }
  697. drm_debugfs_dev_init(dev);
  698. return 0;
  699. err:
  700. drm_managed_release(dev);
  701. return ret;
  702. }
  703. static void devm_drm_dev_init_release(void *data)
  704. {
  705. drm_dev_put(data);
  706. }
  707. static int devm_drm_dev_init(struct device *parent,
  708. struct drm_device *dev,
  709. const struct drm_driver *driver)
  710. {
  711. int ret;
  712. ret = drm_dev_init(dev, driver, parent);
  713. if (ret)
  714. return ret;
  715. return devm_add_action_or_reset(parent,
  716. devm_drm_dev_init_release, dev);
  717. }
  718. void *__devm_drm_dev_alloc(struct device *parent,
  719. const struct drm_driver *driver,
  720. size_t size, size_t offset)
  721. {
  722. void *container;
  723. struct drm_device *drm;
  724. int ret;
  725. container = kzalloc(size, GFP_KERNEL);
  726. if (!container)
  727. return ERR_PTR(-ENOMEM);
  728. drm = container + offset;
  729. ret = devm_drm_dev_init(parent, drm, driver);
  730. if (ret) {
  731. kfree(container);
  732. return ERR_PTR(ret);
  733. }
  734. drmm_add_final_kfree(drm, container);
  735. return container;
  736. }
  737. EXPORT_SYMBOL(__devm_drm_dev_alloc);
  738. /**
  739. * __drm_dev_alloc - Allocation of a &drm_device instance
  740. * @parent: Parent device object
  741. * @driver: DRM driver
  742. * @size: the size of the struct which contains struct drm_device
  743. * @offset: the offset of the &drm_device within the container.
  744. *
  745. * This should *NOT* be by any drivers, but is a dedicated interface for the
  746. * corresponding Rust abstraction.
  747. *
  748. * This is the same as devm_drm_dev_alloc(), but without the corresponding
  749. * resource management through the parent device, but not the same as
  750. * drm_dev_alloc(), since the latter is the deprecated version, which does not
  751. * support subclassing.
  752. *
  753. * Returns: A pointer to new DRM device, or an ERR_PTR on failure.
  754. */
  755. void *__drm_dev_alloc(struct device *parent,
  756. const struct drm_driver *driver,
  757. size_t size, size_t offset)
  758. {
  759. void *container;
  760. struct drm_device *drm;
  761. int ret;
  762. container = kzalloc(size, GFP_KERNEL);
  763. if (!container)
  764. return ERR_PTR(-ENOMEM);
  765. drm = container + offset;
  766. ret = drm_dev_init(drm, driver, parent);
  767. if (ret) {
  768. kfree(container);
  769. return ERR_PTR(ret);
  770. }
  771. drmm_add_final_kfree(drm, container);
  772. return container;
  773. }
  774. EXPORT_SYMBOL(__drm_dev_alloc);
  775. /**
  776. * drm_dev_alloc - Allocate new DRM device
  777. * @driver: DRM driver to allocate device for
  778. * @parent: Parent device object
  779. *
  780. * This is the deprecated version of devm_drm_dev_alloc(), which does not support
  781. * subclassing through embedding the struct &drm_device in a driver private
  782. * structure, and which does not support automatic cleanup through devres.
  783. *
  784. * RETURNS:
  785. * Pointer to new DRM device, or ERR_PTR on failure.
  786. */
  787. struct drm_device *drm_dev_alloc(const struct drm_driver *driver,
  788. struct device *parent)
  789. {
  790. return __drm_dev_alloc(parent, driver, sizeof(struct drm_device), 0);
  791. }
  792. EXPORT_SYMBOL(drm_dev_alloc);
  793. static void drm_dev_release(struct kref *ref)
  794. {
  795. struct drm_device *dev = container_of(ref, struct drm_device, ref);
  796. /* Just in case register/unregister was never called */
  797. drm_debugfs_dev_fini(dev);
  798. if (dev->driver->release)
  799. dev->driver->release(dev);
  800. drm_managed_release(dev);
  801. kfree(dev->managed.final_kfree);
  802. }
  803. /**
  804. * drm_dev_get - Take reference of a DRM device
  805. * @dev: device to take reference of or NULL
  806. *
  807. * This increases the ref-count of @dev by one. You *must* already own a
  808. * reference when calling this. Use drm_dev_put() to drop this reference
  809. * again.
  810. *
  811. * This function never fails. However, this function does not provide *any*
  812. * guarantee whether the device is alive or running. It only provides a
  813. * reference to the object and the memory associated with it.
  814. */
  815. void drm_dev_get(struct drm_device *dev)
  816. {
  817. if (dev)
  818. kref_get(&dev->ref);
  819. }
  820. EXPORT_SYMBOL(drm_dev_get);
  821. /**
  822. * drm_dev_put - Drop reference of a DRM device
  823. * @dev: device to drop reference of or NULL
  824. *
  825. * This decreases the ref-count of @dev by one. The device is destroyed if the
  826. * ref-count drops to zero.
  827. */
  828. void drm_dev_put(struct drm_device *dev)
  829. {
  830. if (dev)
  831. kref_put(&dev->ref, drm_dev_release);
  832. }
  833. EXPORT_SYMBOL(drm_dev_put);
  834. static void drmm_cg_unregister_region(struct drm_device *dev, void *arg)
  835. {
  836. dmem_cgroup_unregister_region(arg);
  837. }
  838. /**
  839. * drmm_cgroup_register_region - Register a region of a DRM device to cgroups
  840. * @dev: device for region
  841. * @region_name: Region name for registering
  842. * @size: Size of region in bytes
  843. *
  844. * This decreases the ref-count of @dev by one. The device is destroyed if the
  845. * ref-count drops to zero.
  846. */
  847. struct dmem_cgroup_region *drmm_cgroup_register_region(struct drm_device *dev, const char *region_name, u64 size)
  848. {
  849. struct dmem_cgroup_region *region;
  850. int ret;
  851. region = dmem_cgroup_register_region(size, "drm/%s/%s", dev->unique, region_name);
  852. if (IS_ERR_OR_NULL(region))
  853. return region;
  854. ret = drmm_add_action_or_reset(dev, drmm_cg_unregister_region, region);
  855. if (ret)
  856. return ERR_PTR(ret);
  857. return region;
  858. }
  859. EXPORT_SYMBOL_GPL(drmm_cgroup_register_region);
  860. static int create_compat_control_link(struct drm_device *dev)
  861. {
  862. struct drm_minor *minor;
  863. char *name;
  864. int ret;
  865. if (!drm_core_check_feature(dev, DRIVER_MODESET))
  866. return 0;
  867. minor = *drm_minor_get_slot(dev, DRM_MINOR_PRIMARY);
  868. if (!minor)
  869. return 0;
  870. /*
  871. * Some existing userspace out there uses the existing of the controlD*
  872. * sysfs files to figure out whether it's a modeset driver. It only does
  873. * readdir, hence a symlink is sufficient (and the least confusing
  874. * option). Otherwise controlD* is entirely unused.
  875. *
  876. * Old controlD chardev have been allocated in the range
  877. * 64-127.
  878. */
  879. name = kasprintf(GFP_KERNEL, "controlD%d", minor->index + 64);
  880. if (!name)
  881. return -ENOMEM;
  882. ret = sysfs_create_link(minor->kdev->kobj.parent,
  883. &minor->kdev->kobj,
  884. name);
  885. kfree(name);
  886. return ret;
  887. }
  888. static void remove_compat_control_link(struct drm_device *dev)
  889. {
  890. struct drm_minor *minor;
  891. char *name;
  892. if (!drm_core_check_feature(dev, DRIVER_MODESET))
  893. return;
  894. minor = *drm_minor_get_slot(dev, DRM_MINOR_PRIMARY);
  895. if (!minor)
  896. return;
  897. name = kasprintf(GFP_KERNEL, "controlD%d", minor->index + 64);
  898. if (!name)
  899. return;
  900. sysfs_remove_link(minor->kdev->kobj.parent, name);
  901. kfree(name);
  902. }
  903. /**
  904. * drm_dev_register - Register DRM device
  905. * @dev: Device to register
  906. * @flags: Flags passed to the driver's .load() function
  907. *
  908. * Register the DRM device @dev with the system, advertise device to user-space
  909. * and start normal device operation. @dev must be initialized via drm_dev_init()
  910. * previously.
  911. *
  912. * Never call this twice on any device!
  913. *
  914. * NOTE: To ensure backward compatibility with existing drivers method this
  915. * function calls the &drm_driver.load method after registering the device
  916. * nodes, creating race conditions. Usage of the &drm_driver.load methods is
  917. * therefore deprecated, drivers must perform all initialization before calling
  918. * drm_dev_register().
  919. *
  920. * RETURNS:
  921. * 0 on success, negative error code on failure.
  922. */
  923. int drm_dev_register(struct drm_device *dev, unsigned long flags)
  924. {
  925. const struct drm_driver *driver = dev->driver;
  926. int ret;
  927. if (!driver->load)
  928. drm_mode_config_validate(dev);
  929. WARN_ON(!dev->managed.final_kfree);
  930. if (drm_dev_needs_global_mutex(dev))
  931. mutex_lock(&drm_global_mutex);
  932. if (drm_core_check_feature(dev, DRIVER_COMPUTE_ACCEL))
  933. accel_debugfs_register(dev);
  934. else
  935. drm_debugfs_dev_register(dev);
  936. ret = drm_minor_register(dev, DRM_MINOR_RENDER);
  937. if (ret)
  938. goto err_minors;
  939. ret = drm_minor_register(dev, DRM_MINOR_PRIMARY);
  940. if (ret)
  941. goto err_minors;
  942. ret = drm_minor_register(dev, DRM_MINOR_ACCEL);
  943. if (ret)
  944. goto err_minors;
  945. ret = create_compat_control_link(dev);
  946. if (ret)
  947. goto err_minors;
  948. dev->registered = true;
  949. if (driver->load) {
  950. ret = driver->load(dev, flags);
  951. if (ret)
  952. goto err_minors;
  953. }
  954. if (drm_core_check_feature(dev, DRIVER_MODESET)) {
  955. ret = drm_modeset_register_all(dev);
  956. if (ret)
  957. goto err_unload;
  958. }
  959. drm_panic_register(dev);
  960. drm_client_sysrq_register(dev);
  961. DRM_INFO("Initialized %s %d.%d.%d for %s on minor %d\n",
  962. driver->name, driver->major, driver->minor,
  963. driver->patchlevel,
  964. dev->dev ? dev_name(dev->dev) : "virtual device",
  965. dev->primary ? dev->primary->index : dev->accel->index);
  966. goto out_unlock;
  967. err_unload:
  968. if (dev->driver->unload)
  969. dev->driver->unload(dev);
  970. err_minors:
  971. remove_compat_control_link(dev);
  972. drm_minor_unregister(dev, DRM_MINOR_ACCEL);
  973. drm_minor_unregister(dev, DRM_MINOR_PRIMARY);
  974. drm_minor_unregister(dev, DRM_MINOR_RENDER);
  975. out_unlock:
  976. if (drm_dev_needs_global_mutex(dev))
  977. mutex_unlock(&drm_global_mutex);
  978. return ret;
  979. }
  980. EXPORT_SYMBOL(drm_dev_register);
  981. /**
  982. * drm_dev_unregister - Unregister DRM device
  983. * @dev: Device to unregister
  984. *
  985. * Unregister the DRM device from the system. This does the reverse of
  986. * drm_dev_register() but does not deallocate the device. The caller must call
  987. * drm_dev_put() to drop their final reference, unless it is managed with devres
  988. * (as devices allocated with devm_drm_dev_alloc() are), in which case there is
  989. * already an unwind action registered.
  990. *
  991. * A special form of unregistering for hotpluggable devices is drm_dev_unplug(),
  992. * which can be called while there are still open users of @dev.
  993. *
  994. * This should be called first in the device teardown code to make sure
  995. * userspace can't access the device instance any more.
  996. */
  997. void drm_dev_unregister(struct drm_device *dev)
  998. {
  999. dev->registered = false;
  1000. drm_client_sysrq_unregister(dev);
  1001. drm_panic_unregister(dev);
  1002. drm_client_dev_unregister(dev);
  1003. if (drm_core_check_feature(dev, DRIVER_MODESET))
  1004. drm_modeset_unregister_all(dev);
  1005. if (dev->driver->unload)
  1006. dev->driver->unload(dev);
  1007. remove_compat_control_link(dev);
  1008. drm_minor_unregister(dev, DRM_MINOR_ACCEL);
  1009. drm_minor_unregister(dev, DRM_MINOR_PRIMARY);
  1010. drm_minor_unregister(dev, DRM_MINOR_RENDER);
  1011. drm_debugfs_dev_fini(dev);
  1012. }
  1013. EXPORT_SYMBOL(drm_dev_unregister);
  1014. /*
  1015. * DRM Core
  1016. * The DRM core module initializes all global DRM objects and makes them
  1017. * available to drivers. Once setup, drivers can probe their respective
  1018. * devices.
  1019. * Currently, core management includes:
  1020. * - The "DRM-Global" key/value database
  1021. * - Global ID management for connectors
  1022. * - DRM major number allocation
  1023. * - DRM minor management
  1024. * - DRM sysfs class
  1025. * - DRM debugfs root
  1026. *
  1027. * Furthermore, the DRM core provides dynamic char-dev lookups. For each
  1028. * interface registered on a DRM device, you can request minor numbers from DRM
  1029. * core. DRM core takes care of major-number management and char-dev
  1030. * registration. A stub ->open() callback forwards any open() requests to the
  1031. * registered minor.
  1032. */
  1033. static int drm_stub_open(struct inode *inode, struct file *filp)
  1034. {
  1035. const struct file_operations *new_fops;
  1036. struct drm_minor *minor;
  1037. int err;
  1038. DRM_DEBUG("\n");
  1039. minor = drm_minor_acquire(&drm_minors_xa, iminor(inode));
  1040. if (IS_ERR(minor))
  1041. return PTR_ERR(minor);
  1042. new_fops = fops_get(minor->dev->driver->fops);
  1043. if (!new_fops) {
  1044. err = -ENODEV;
  1045. goto out;
  1046. }
  1047. replace_fops(filp, new_fops);
  1048. if (filp->f_op->open)
  1049. err = filp->f_op->open(inode, filp);
  1050. else
  1051. err = 0;
  1052. out:
  1053. drm_minor_release(minor);
  1054. return err;
  1055. }
  1056. static const struct file_operations drm_stub_fops = {
  1057. .owner = THIS_MODULE,
  1058. .open = drm_stub_open,
  1059. .llseek = noop_llseek,
  1060. };
  1061. static void drm_core_exit(void)
  1062. {
  1063. drm_privacy_screen_lookup_exit();
  1064. drm_panic_exit();
  1065. accel_core_exit();
  1066. unregister_chrdev(DRM_MAJOR, "drm");
  1067. drm_debugfs_remove_root();
  1068. drm_sysfs_destroy();
  1069. WARN_ON(!xa_empty(&drm_minors_xa));
  1070. drm_connector_ida_destroy();
  1071. }
  1072. static int __init drm_core_init(void)
  1073. {
  1074. int ret;
  1075. drm_connector_ida_init();
  1076. drm_memcpy_init_early();
  1077. ret = drm_sysfs_init();
  1078. if (ret < 0) {
  1079. DRM_ERROR("Cannot create DRM class: %d\n", ret);
  1080. goto error;
  1081. }
  1082. drm_debugfs_init_root();
  1083. drm_debugfs_bridge_params();
  1084. ret = register_chrdev(DRM_MAJOR, "drm", &drm_stub_fops);
  1085. if (ret < 0)
  1086. goto error;
  1087. ret = accel_core_init();
  1088. if (ret < 0)
  1089. goto error;
  1090. drm_panic_init();
  1091. drm_privacy_screen_lookup_init();
  1092. drm_core_init_complete = true;
  1093. DRM_DEBUG("Initialized\n");
  1094. return 0;
  1095. error:
  1096. drm_core_exit();
  1097. return ret;
  1098. }
  1099. module_init(drm_core_init);
  1100. module_exit(drm_core_exit);