drm_framebuffer.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238
  1. /*
  2. * Copyright (c) 2016 Intel Corporation
  3. *
  4. * Permission to use, copy, modify, distribute, and sell this software and its
  5. * documentation for any purpose is hereby granted without fee, provided that
  6. * the above copyright notice appear in all copies and that both that copyright
  7. * notice and this permission notice appear in supporting documentation, and
  8. * that the name of the copyright holders not be used in advertising or
  9. * publicity pertaining to distribution of the software without specific,
  10. * written prior permission. The copyright holders make no representations
  11. * about the suitability of this software for any purpose. It is provided "as
  12. * is" without express or implied warranty.
  13. *
  14. * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  15. * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  16. * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  17. * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  18. * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  19. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  20. * OF THIS SOFTWARE.
  21. */
  22. #include <linux/export.h>
  23. #include <linux/uaccess.h>
  24. #include <drm/drm_atomic.h>
  25. #include <drm/drm_atomic_uapi.h>
  26. #include <drm/drm_auth.h>
  27. #include <drm/drm_debugfs.h>
  28. #include <drm/drm_drv.h>
  29. #include <drm/drm_file.h>
  30. #include <drm/drm_fourcc.h>
  31. #include <drm/drm_framebuffer.h>
  32. #include <drm/drm_gem.h>
  33. #include <drm/drm_print.h>
  34. #include <drm/drm_util.h>
  35. #include "drm_crtc_internal.h"
  36. #include "drm_internal.h"
  37. /**
  38. * DOC: overview
  39. *
  40. * Frame buffers are abstract memory objects that provide a source of pixels to
  41. * scanout to a CRTC. Applications explicitly request the creation of frame
  42. * buffers through the DRM_IOCTL_MODE_ADDFB(2) ioctls and receive an opaque
  43. * handle that can be passed to the KMS CRTC control, plane configuration and
  44. * page flip functions.
  45. *
  46. * Frame buffers rely on the underlying memory manager for allocating backing
  47. * storage. When creating a frame buffer applications pass a memory handle
  48. * (or a list of memory handles for multi-planar formats) through the
  49. * &struct drm_mode_fb_cmd2 argument. For drivers using GEM as their userspace
  50. * buffer management interface this would be a GEM handle. Drivers are however
  51. * free to use their own backing storage object handles, e.g. vmwgfx directly
  52. * exposes special TTM handles to userspace and so expects TTM handles in the
  53. * create ioctl and not GEM handles.
  54. *
  55. * Framebuffers are tracked with &struct drm_framebuffer. They are published
  56. * using drm_framebuffer_init() - after calling that function userspace can use
  57. * and access the framebuffer object. The helper function
  58. * drm_helper_mode_fill_fb_struct() can be used to pre-fill the required
  59. * metadata fields.
  60. *
  61. * The lifetime of a drm framebuffer is controlled with a reference count,
  62. * drivers can grab additional references with drm_framebuffer_get() and drop
  63. * them again with drm_framebuffer_put(). For driver-private framebuffers for
  64. * which the last reference is never dropped (e.g. for the fbdev framebuffer
  65. * when the struct &struct drm_framebuffer is embedded into the fbdev helper
  66. * struct) drivers can manually clean up a framebuffer at module unload time
  67. * with drm_framebuffer_unregister_private(). But doing this is not
  68. * recommended, and it's better to have a normal free-standing &struct
  69. * drm_framebuffer.
  70. */
  71. int drm_framebuffer_check_src_coords(uint32_t src_x, uint32_t src_y,
  72. uint32_t src_w, uint32_t src_h,
  73. const struct drm_framebuffer *fb)
  74. {
  75. unsigned int fb_width, fb_height;
  76. fb_width = fb->width << 16;
  77. fb_height = fb->height << 16;
  78. /* Make sure source coordinates are inside the fb. */
  79. if (src_w > fb_width ||
  80. src_x > fb_width - src_w ||
  81. src_h > fb_height ||
  82. src_y > fb_height - src_h) {
  83. drm_dbg_kms(fb->dev, "Invalid source coordinates "
  84. "%u.%06ux%u.%06u+%u.%06u+%u.%06u (fb %ux%u)\n",
  85. src_w >> 16, ((src_w & 0xffff) * 15625) >> 10,
  86. src_h >> 16, ((src_h & 0xffff) * 15625) >> 10,
  87. src_x >> 16, ((src_x & 0xffff) * 15625) >> 10,
  88. src_y >> 16, ((src_y & 0xffff) * 15625) >> 10,
  89. fb->width, fb->height);
  90. return -ENOSPC;
  91. }
  92. return 0;
  93. }
  94. EXPORT_SYMBOL_FOR_TESTS_ONLY(drm_framebuffer_check_src_coords);
  95. /**
  96. * drm_mode_addfb - add an FB to the graphics configuration
  97. * @dev: drm device for the ioctl
  98. * @or: pointer to request structure
  99. * @file_priv: drm file
  100. *
  101. * Add a new FB to the specified CRTC, given a user request. This is the
  102. * original addfb ioctl which only supported RGB formats.
  103. *
  104. * Called by the user via ioctl, or by an in-kernel client.
  105. *
  106. * Returns:
  107. * Zero on success, negative errno on failure.
  108. */
  109. int drm_mode_addfb(struct drm_device *dev, struct drm_mode_fb_cmd *or,
  110. struct drm_file *file_priv)
  111. {
  112. struct drm_mode_fb_cmd2 r = {};
  113. int ret;
  114. if (!drm_core_check_feature(dev, DRIVER_MODESET))
  115. return -EOPNOTSUPP;
  116. r.pixel_format = drm_driver_legacy_fb_format(dev, or->bpp, or->depth);
  117. if (r.pixel_format == DRM_FORMAT_INVALID) {
  118. drm_dbg_kms(dev, "bad {bpp:%d, depth:%d}\n", or->bpp, or->depth);
  119. return -EINVAL;
  120. }
  121. /* convert to new format and call new ioctl */
  122. r.fb_id = or->fb_id;
  123. r.width = or->width;
  124. r.height = or->height;
  125. r.pitches[0] = or->pitch;
  126. r.handles[0] = or->handle;
  127. ret = drm_mode_addfb2(dev, &r, file_priv);
  128. if (ret)
  129. return ret;
  130. or->fb_id = r.fb_id;
  131. return 0;
  132. }
  133. int drm_mode_addfb_ioctl(struct drm_device *dev,
  134. void *data, struct drm_file *file_priv)
  135. {
  136. return drm_mode_addfb(dev, data, file_priv);
  137. }
  138. static int framebuffer_check(struct drm_device *dev,
  139. const struct drm_format_info *info,
  140. const struct drm_mode_fb_cmd2 *r)
  141. {
  142. int i;
  143. if (r->width == 0) {
  144. drm_dbg_kms(dev, "bad framebuffer width %u\n", r->width);
  145. return -EINVAL;
  146. }
  147. if (r->height == 0) {
  148. drm_dbg_kms(dev, "bad framebuffer height %u\n", r->height);
  149. return -EINVAL;
  150. }
  151. for (i = 0; i < info->num_planes; i++) {
  152. unsigned int width = drm_format_info_plane_width(info, r->width, i);
  153. unsigned int height = drm_format_info_plane_height(info, r->height, i);
  154. unsigned int block_size = info->char_per_block[i];
  155. u64 min_pitch = drm_format_info_min_pitch(info, i, width);
  156. if (!block_size && (r->modifier[i] == DRM_FORMAT_MOD_LINEAR)) {
  157. drm_dbg_kms(dev, "Format requires non-linear modifier for plane %d\n", i);
  158. return -EINVAL;
  159. }
  160. if (!r->handles[i]) {
  161. drm_dbg_kms(dev, "no buffer object handle for plane %d\n", i);
  162. return -EINVAL;
  163. }
  164. if (min_pitch > UINT_MAX)
  165. return -ERANGE;
  166. if ((uint64_t) height * r->pitches[i] + r->offsets[i] > UINT_MAX)
  167. return -ERANGE;
  168. if (block_size && r->pitches[i] < min_pitch) {
  169. drm_dbg_kms(dev, "bad pitch %u for plane %d\n", r->pitches[i], i);
  170. return -EINVAL;
  171. }
  172. if (r->modifier[i] && !(r->flags & DRM_MODE_FB_MODIFIERS)) {
  173. drm_dbg_kms(dev, "bad fb modifier %llu for plane %d\n",
  174. r->modifier[i], i);
  175. return -EINVAL;
  176. }
  177. if (r->flags & DRM_MODE_FB_MODIFIERS &&
  178. r->modifier[i] != r->modifier[0]) {
  179. drm_dbg_kms(dev, "bad fb modifier %llu for plane %d\n",
  180. r->modifier[i], i);
  181. return -EINVAL;
  182. }
  183. /* modifier specific checks: */
  184. switch (r->modifier[i]) {
  185. case DRM_FORMAT_MOD_SAMSUNG_64_32_TILE:
  186. /* NOTE: the pitch restriction may be lifted later if it turns
  187. * out that no hw has this restriction:
  188. */
  189. if (r->pixel_format != DRM_FORMAT_NV12 ||
  190. width % 128 || height % 32 ||
  191. r->pitches[i] % 128) {
  192. drm_dbg_kms(dev, "bad modifier data for plane %d\n", i);
  193. return -EINVAL;
  194. }
  195. break;
  196. default:
  197. break;
  198. }
  199. }
  200. for (i = info->num_planes; i < 4; i++) {
  201. if (r->modifier[i]) {
  202. drm_dbg_kms(dev, "non-zero modifier for unused plane %d\n", i);
  203. return -EINVAL;
  204. }
  205. /* Pre-FB_MODIFIERS userspace didn't clear the structs properly. */
  206. if (!(r->flags & DRM_MODE_FB_MODIFIERS))
  207. continue;
  208. if (r->handles[i]) {
  209. drm_dbg_kms(dev, "buffer object handle for unused plane %d\n", i);
  210. return -EINVAL;
  211. }
  212. if (r->pitches[i]) {
  213. drm_dbg_kms(dev, "non-zero pitch for unused plane %d\n", i);
  214. return -EINVAL;
  215. }
  216. if (r->offsets[i]) {
  217. drm_dbg_kms(dev, "non-zero offset for unused plane %d\n", i);
  218. return -EINVAL;
  219. }
  220. }
  221. return 0;
  222. }
  223. struct drm_framebuffer *
  224. drm_internal_framebuffer_create(struct drm_device *dev,
  225. const struct drm_mode_fb_cmd2 *r,
  226. struct drm_file *file_priv)
  227. {
  228. struct drm_mode_config *config = &dev->mode_config;
  229. const struct drm_format_info *info;
  230. struct drm_framebuffer *fb;
  231. int ret;
  232. if (r->flags & ~(DRM_MODE_FB_INTERLACED | DRM_MODE_FB_MODIFIERS)) {
  233. drm_dbg_kms(dev, "bad framebuffer flags 0x%08x\n", r->flags);
  234. return ERR_PTR(-EINVAL);
  235. }
  236. if ((config->min_width > r->width) || (r->width > config->max_width)) {
  237. drm_dbg_kms(dev, "bad framebuffer width %d, should be >= %d && <= %d\n",
  238. r->width, config->min_width, config->max_width);
  239. return ERR_PTR(-EINVAL);
  240. }
  241. if ((config->min_height > r->height) || (r->height > config->max_height)) {
  242. drm_dbg_kms(dev, "bad framebuffer height %d, should be >= %d && <= %d\n",
  243. r->height, config->min_height, config->max_height);
  244. return ERR_PTR(-EINVAL);
  245. }
  246. if (r->flags & DRM_MODE_FB_MODIFIERS &&
  247. dev->mode_config.fb_modifiers_not_supported) {
  248. drm_dbg_kms(dev, "driver does not support fb modifiers\n");
  249. return ERR_PTR(-EINVAL);
  250. }
  251. /* check if the format is supported at all */
  252. if (!__drm_format_info(r->pixel_format)) {
  253. drm_dbg_kms(dev, "bad framebuffer format %p4cc\n",
  254. &r->pixel_format);
  255. return ERR_PTR(-EINVAL);
  256. }
  257. /* now let the driver pick its own format info */
  258. info = drm_get_format_info(dev, r->pixel_format, r->modifier[0]);
  259. ret = framebuffer_check(dev, info, r);
  260. if (ret)
  261. return ERR_PTR(ret);
  262. fb = dev->mode_config.funcs->fb_create(dev, file_priv, info, r);
  263. if (IS_ERR(fb)) {
  264. drm_dbg_kms(dev, "could not create framebuffer\n");
  265. return fb;
  266. }
  267. return fb;
  268. }
  269. EXPORT_SYMBOL_FOR_TESTS_ONLY(drm_internal_framebuffer_create);
  270. /**
  271. * drm_mode_addfb2 - add an FB to the graphics configuration
  272. * @dev: drm device for the ioctl
  273. * @data: data pointer for the ioctl
  274. * @file_priv: drm file for the ioctl call
  275. *
  276. * Add a new FB to the specified CRTC, given a user request with format. This is
  277. * the 2nd version of the addfb ioctl, which supports multi-planar framebuffers
  278. * and uses fourcc codes as pixel format specifiers.
  279. *
  280. * Called by the user via ioctl.
  281. *
  282. * Returns:
  283. * Zero on success, negative errno on failure.
  284. */
  285. int drm_mode_addfb2(struct drm_device *dev,
  286. void *data, struct drm_file *file_priv)
  287. {
  288. struct drm_mode_fb_cmd2 *r = data;
  289. struct drm_framebuffer *fb;
  290. if (!drm_core_check_feature(dev, DRIVER_MODESET))
  291. return -EOPNOTSUPP;
  292. fb = drm_internal_framebuffer_create(dev, r, file_priv);
  293. if (IS_ERR(fb))
  294. return PTR_ERR(fb);
  295. drm_dbg_kms(dev, "[FB:%d]\n", fb->base.id);
  296. r->fb_id = fb->base.id;
  297. /* Transfer ownership to the filp for reaping on close */
  298. mutex_lock(&file_priv->fbs_lock);
  299. list_add(&fb->filp_head, &file_priv->fbs);
  300. mutex_unlock(&file_priv->fbs_lock);
  301. return 0;
  302. }
  303. int drm_mode_addfb2_ioctl(struct drm_device *dev,
  304. void *data, struct drm_file *file_priv)
  305. {
  306. #ifdef __BIG_ENDIAN
  307. if (!dev->mode_config.quirk_addfb_prefer_host_byte_order) {
  308. /*
  309. * Drivers must set the
  310. * quirk_addfb_prefer_host_byte_order quirk to make
  311. * the drm_mode_addfb() compat code work correctly on
  312. * bigendian machines.
  313. *
  314. * If they don't they interpret pixel_format values
  315. * incorrectly for bug compatibility, which in turn
  316. * implies the ADDFB2 ioctl does not work correctly
  317. * then. So block it to make userspace fallback to
  318. * ADDFB.
  319. */
  320. drm_dbg_kms(dev, "addfb2 broken on bigendian");
  321. return -EOPNOTSUPP;
  322. }
  323. #endif
  324. return drm_mode_addfb2(dev, data, file_priv);
  325. }
  326. struct drm_mode_rmfb_work {
  327. struct work_struct work;
  328. struct list_head fbs;
  329. };
  330. static void drm_mode_rmfb_work_fn(struct work_struct *w)
  331. {
  332. struct drm_mode_rmfb_work *arg = container_of(w, typeof(*arg), work);
  333. while (!list_empty(&arg->fbs)) {
  334. struct drm_framebuffer *fb =
  335. list_first_entry(&arg->fbs, typeof(*fb), filp_head);
  336. drm_dbg_kms(fb->dev,
  337. "Removing [FB:%d] from all active usage due to RMFB ioctl\n",
  338. fb->base.id);
  339. list_del_init(&fb->filp_head);
  340. drm_framebuffer_remove(fb);
  341. }
  342. }
  343. static int drm_mode_closefb(struct drm_framebuffer *fb,
  344. struct drm_file *file_priv)
  345. {
  346. struct drm_framebuffer *fbl;
  347. bool found = false;
  348. mutex_lock(&file_priv->fbs_lock);
  349. list_for_each_entry(fbl, &file_priv->fbs, filp_head)
  350. if (fb == fbl)
  351. found = true;
  352. if (!found) {
  353. mutex_unlock(&file_priv->fbs_lock);
  354. return -ENOENT;
  355. }
  356. list_del_init(&fb->filp_head);
  357. mutex_unlock(&file_priv->fbs_lock);
  358. /* Drop the reference that was stored in the fbs list */
  359. drm_framebuffer_put(fb);
  360. return 0;
  361. }
  362. /**
  363. * drm_mode_rmfb - remove an FB from the configuration
  364. * @dev: drm device
  365. * @fb_id: id of framebuffer to remove
  366. * @file_priv: drm file
  367. *
  368. * Remove the specified FB.
  369. *
  370. * Called by the user via ioctl, or by an in-kernel client.
  371. *
  372. * Returns:
  373. * Zero on success, negative errno on failure.
  374. */
  375. int drm_mode_rmfb(struct drm_device *dev, u32 fb_id,
  376. struct drm_file *file_priv)
  377. {
  378. struct drm_framebuffer *fb;
  379. int ret;
  380. if (!drm_core_check_feature(dev, DRIVER_MODESET))
  381. return -EOPNOTSUPP;
  382. fb = drm_framebuffer_lookup(dev, file_priv, fb_id);
  383. if (!fb)
  384. return -ENOENT;
  385. ret = drm_mode_closefb(fb, file_priv);
  386. if (ret != 0) {
  387. drm_framebuffer_put(fb);
  388. return ret;
  389. }
  390. /*
  391. * drm_framebuffer_remove may fail with -EINTR on pending signals,
  392. * so run this in a separate stack as there's no way to correctly
  393. * handle this after the fb is already removed from the lookup table.
  394. */
  395. if (drm_framebuffer_read_refcount(fb) > 1) {
  396. struct drm_mode_rmfb_work arg;
  397. INIT_WORK_ONSTACK(&arg.work, drm_mode_rmfb_work_fn);
  398. INIT_LIST_HEAD(&arg.fbs);
  399. drm_WARN_ON(dev, !list_empty(&fb->filp_head));
  400. list_add_tail(&fb->filp_head, &arg.fbs);
  401. schedule_work(&arg.work);
  402. flush_work(&arg.work);
  403. destroy_work_on_stack(&arg.work);
  404. } else
  405. drm_framebuffer_put(fb);
  406. return 0;
  407. }
  408. int drm_mode_rmfb_ioctl(struct drm_device *dev,
  409. void *data, struct drm_file *file_priv)
  410. {
  411. uint32_t *fb_id = data;
  412. return drm_mode_rmfb(dev, *fb_id, file_priv);
  413. }
  414. int drm_mode_closefb_ioctl(struct drm_device *dev,
  415. void *data, struct drm_file *file_priv)
  416. {
  417. struct drm_mode_closefb *r = data;
  418. struct drm_framebuffer *fb;
  419. int ret;
  420. if (!drm_core_check_feature(dev, DRIVER_MODESET))
  421. return -EOPNOTSUPP;
  422. if (r->pad)
  423. return -EINVAL;
  424. fb = drm_framebuffer_lookup(dev, file_priv, r->fb_id);
  425. if (!fb)
  426. return -ENOENT;
  427. ret = drm_mode_closefb(fb, file_priv);
  428. drm_framebuffer_put(fb);
  429. return ret;
  430. }
  431. /**
  432. * drm_mode_getfb - get FB info
  433. * @dev: drm device for the ioctl
  434. * @data: data pointer for the ioctl
  435. * @file_priv: drm file for the ioctl call
  436. *
  437. * Lookup the FB given its ID and return info about it.
  438. *
  439. * Called by the user via ioctl.
  440. *
  441. * Returns:
  442. * Zero on success, negative errno on failure.
  443. */
  444. int drm_mode_getfb(struct drm_device *dev,
  445. void *data, struct drm_file *file_priv)
  446. {
  447. struct drm_mode_fb_cmd *r = data;
  448. struct drm_framebuffer *fb;
  449. int ret;
  450. if (!drm_core_check_feature(dev, DRIVER_MODESET))
  451. return -EOPNOTSUPP;
  452. fb = drm_framebuffer_lookup(dev, file_priv, r->fb_id);
  453. if (!fb)
  454. return -ENOENT;
  455. /* Multi-planar framebuffers need getfb2. */
  456. if (fb->format->num_planes > 1) {
  457. ret = -EINVAL;
  458. goto out;
  459. }
  460. if (!fb->funcs->create_handle) {
  461. ret = -ENODEV;
  462. goto out;
  463. }
  464. r->height = fb->height;
  465. r->width = fb->width;
  466. r->depth = fb->format->depth;
  467. r->bpp = drm_format_info_bpp(fb->format, 0);
  468. r->pitch = fb->pitches[0];
  469. /* GET_FB() is an unprivileged ioctl so we must not return a
  470. * buffer-handle to non-master processes! For
  471. * backwards-compatibility reasons, we cannot make GET_FB() privileged,
  472. * so just return an invalid handle for non-masters.
  473. */
  474. if (!drm_is_current_master(file_priv) && !capable(CAP_SYS_ADMIN)) {
  475. r->handle = 0;
  476. ret = 0;
  477. goto out;
  478. }
  479. ret = fb->funcs->create_handle(fb, file_priv, &r->handle);
  480. out:
  481. drm_framebuffer_put(fb);
  482. return ret;
  483. }
  484. /**
  485. * drm_mode_getfb2_ioctl - get extended FB info
  486. * @dev: drm device for the ioctl
  487. * @data: data pointer for the ioctl
  488. * @file_priv: drm file for the ioctl call
  489. *
  490. * Lookup the FB given its ID and return info about it.
  491. *
  492. * Called by the user via ioctl.
  493. *
  494. * Returns:
  495. * Zero on success, negative errno on failure.
  496. */
  497. int drm_mode_getfb2_ioctl(struct drm_device *dev,
  498. void *data, struct drm_file *file_priv)
  499. {
  500. struct drm_mode_fb_cmd2 *r = data;
  501. struct drm_framebuffer *fb;
  502. unsigned int i;
  503. int ret = 0;
  504. if (!drm_core_check_feature(dev, DRIVER_MODESET))
  505. return -EINVAL;
  506. fb = drm_framebuffer_lookup(dev, file_priv, r->fb_id);
  507. if (!fb)
  508. return -ENOENT;
  509. /* For multi-plane framebuffers, we require the driver to place the
  510. * GEM objects directly in the drm_framebuffer. For single-plane
  511. * framebuffers, we can fall back to create_handle.
  512. */
  513. if (!fb->obj[0] &&
  514. (fb->format->num_planes > 1 || !fb->funcs->create_handle)) {
  515. ret = -ENODEV;
  516. goto out;
  517. }
  518. r->height = fb->height;
  519. r->width = fb->width;
  520. r->pixel_format = fb->format->format;
  521. r->flags = 0;
  522. if (!dev->mode_config.fb_modifiers_not_supported)
  523. r->flags |= DRM_MODE_FB_MODIFIERS;
  524. for (i = 0; i < ARRAY_SIZE(r->handles); i++) {
  525. r->handles[i] = 0;
  526. r->pitches[i] = 0;
  527. r->offsets[i] = 0;
  528. r->modifier[i] = 0;
  529. }
  530. for (i = 0; i < fb->format->num_planes; i++) {
  531. r->pitches[i] = fb->pitches[i];
  532. r->offsets[i] = fb->offsets[i];
  533. if (!dev->mode_config.fb_modifiers_not_supported)
  534. r->modifier[i] = fb->modifier;
  535. }
  536. /* GET_FB2() is an unprivileged ioctl so we must not return a
  537. * buffer-handle to non master/root processes! To match GET_FB()
  538. * just return invalid handles (0) for non masters/root
  539. * rather than making GET_FB2() privileged.
  540. */
  541. if (!drm_is_current_master(file_priv) && !capable(CAP_SYS_ADMIN)) {
  542. ret = 0;
  543. goto out;
  544. }
  545. for (i = 0; i < fb->format->num_planes; i++) {
  546. int j;
  547. /* If we reuse the same object for multiple planes, also
  548. * return the same handle.
  549. */
  550. for (j = 0; j < i; j++) {
  551. if (fb->obj[i] == fb->obj[j]) {
  552. r->handles[i] = r->handles[j];
  553. break;
  554. }
  555. }
  556. if (r->handles[i])
  557. continue;
  558. if (fb->obj[i]) {
  559. ret = drm_gem_handle_create(file_priv, fb->obj[i],
  560. &r->handles[i]);
  561. } else {
  562. WARN_ON(i > 0);
  563. ret = fb->funcs->create_handle(fb, file_priv,
  564. &r->handles[i]);
  565. }
  566. if (ret != 0)
  567. goto out;
  568. }
  569. out:
  570. if (ret != 0) {
  571. /* Delete any previously-created handles on failure. */
  572. for (i = 0; i < ARRAY_SIZE(r->handles); i++) {
  573. int j;
  574. if (r->handles[i])
  575. drm_gem_handle_delete(file_priv, r->handles[i]);
  576. /* Zero out any handles identical to the one we just
  577. * deleted.
  578. */
  579. for (j = i + 1; j < ARRAY_SIZE(r->handles); j++) {
  580. if (r->handles[j] == r->handles[i])
  581. r->handles[j] = 0;
  582. }
  583. }
  584. }
  585. drm_framebuffer_put(fb);
  586. return ret;
  587. }
  588. /**
  589. * drm_mode_dirtyfb_ioctl - flush frontbuffer rendering on an FB
  590. * @dev: drm device for the ioctl
  591. * @data: data pointer for the ioctl
  592. * @file_priv: drm file for the ioctl call
  593. *
  594. * Lookup the FB and flush out the damaged area supplied by userspace as a clip
  595. * rectangle list. Generic userspace which does frontbuffer rendering must call
  596. * this ioctl to flush out the changes on manual-update display outputs, e.g.
  597. * usb display-link, mipi manual update panels or edp panel self refresh modes.
  598. *
  599. * Modesetting drivers which always update the frontbuffer do not need to
  600. * implement the corresponding &drm_framebuffer_funcs.dirty callback.
  601. *
  602. * Called by the user via ioctl.
  603. *
  604. * Returns:
  605. * Zero on success, negative errno on failure.
  606. */
  607. int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
  608. void *data, struct drm_file *file_priv)
  609. {
  610. struct drm_clip_rect __user *clips_ptr;
  611. struct drm_clip_rect *clips = NULL;
  612. struct drm_mode_fb_dirty_cmd *r = data;
  613. struct drm_framebuffer *fb;
  614. unsigned flags;
  615. int num_clips;
  616. int ret;
  617. if (!drm_core_check_feature(dev, DRIVER_MODESET))
  618. return -EOPNOTSUPP;
  619. fb = drm_framebuffer_lookup(dev, file_priv, r->fb_id);
  620. if (!fb)
  621. return -ENOENT;
  622. num_clips = r->num_clips;
  623. clips_ptr = (struct drm_clip_rect __user *)(unsigned long)r->clips_ptr;
  624. if (!num_clips != !clips_ptr) {
  625. ret = -EINVAL;
  626. goto out_err1;
  627. }
  628. flags = DRM_MODE_FB_DIRTY_FLAGS & r->flags;
  629. /* If userspace annotates copy, clips must come in pairs */
  630. if (flags & DRM_MODE_FB_DIRTY_ANNOTATE_COPY && (num_clips % 2)) {
  631. ret = -EINVAL;
  632. goto out_err1;
  633. }
  634. if (num_clips && clips_ptr) {
  635. if (num_clips < 0 || num_clips > DRM_MODE_FB_DIRTY_MAX_CLIPS) {
  636. ret = -EINVAL;
  637. goto out_err1;
  638. }
  639. clips = kzalloc_objs(*clips, num_clips);
  640. if (!clips) {
  641. ret = -ENOMEM;
  642. goto out_err1;
  643. }
  644. ret = copy_from_user(clips, clips_ptr,
  645. num_clips * sizeof(*clips));
  646. if (ret) {
  647. ret = -EFAULT;
  648. goto out_err2;
  649. }
  650. }
  651. if (fb->funcs->dirty) {
  652. ret = fb->funcs->dirty(fb, file_priv, flags, r->color,
  653. clips, num_clips);
  654. } else {
  655. ret = -ENOSYS;
  656. }
  657. out_err2:
  658. kfree(clips);
  659. out_err1:
  660. drm_framebuffer_put(fb);
  661. return ret;
  662. }
  663. /**
  664. * drm_fb_release - remove and free the FBs on this file
  665. * @priv: drm file for the ioctl
  666. *
  667. * Destroy all the FBs associated with @filp.
  668. *
  669. * Called by the user via ioctl.
  670. *
  671. * Returns:
  672. * Zero on success, negative errno on failure.
  673. */
  674. void drm_fb_release(struct drm_file *priv)
  675. {
  676. struct drm_framebuffer *fb, *tfb;
  677. struct drm_mode_rmfb_work arg;
  678. INIT_LIST_HEAD(&arg.fbs);
  679. /*
  680. * When the file gets released that means no one else can access the fb
  681. * list any more, so no need to grab fpriv->fbs_lock. And we need to
  682. * avoid upsetting lockdep since the universal cursor code adds a
  683. * framebuffer while holding mutex locks.
  684. *
  685. * Note that a real deadlock between fpriv->fbs_lock and the modeset
  686. * locks is impossible here since no one else but this function can get
  687. * at it any more.
  688. */
  689. list_for_each_entry_safe(fb, tfb, &priv->fbs, filp_head) {
  690. if (drm_framebuffer_read_refcount(fb) > 1) {
  691. list_move_tail(&fb->filp_head, &arg.fbs);
  692. } else {
  693. list_del_init(&fb->filp_head);
  694. /* This drops the fpriv->fbs reference. */
  695. drm_framebuffer_put(fb);
  696. }
  697. }
  698. if (!list_empty(&arg.fbs)) {
  699. INIT_WORK_ONSTACK(&arg.work, drm_mode_rmfb_work_fn);
  700. schedule_work(&arg.work);
  701. flush_work(&arg.work);
  702. destroy_work_on_stack(&arg.work);
  703. }
  704. }
  705. void drm_framebuffer_free(struct kref *kref)
  706. {
  707. struct drm_framebuffer *fb =
  708. container_of(kref, struct drm_framebuffer, base.refcount);
  709. struct drm_device *dev = fb->dev;
  710. drm_WARN_ON(dev, !list_empty(&fb->filp_head));
  711. /*
  712. * The lookup idr holds a weak reference, which has not necessarily been
  713. * removed at this point. Check for that.
  714. */
  715. drm_mode_object_unregister(dev, &fb->base);
  716. fb->funcs->destroy(fb);
  717. }
  718. EXPORT_SYMBOL_FOR_TESTS_ONLY(drm_framebuffer_free);
  719. /**
  720. * drm_framebuffer_init - initialize a framebuffer
  721. * @dev: DRM device
  722. * @fb: framebuffer to be initialized
  723. * @funcs: ... with these functions
  724. *
  725. * Allocates an ID for the framebuffer's parent mode object, sets its mode
  726. * functions & device file and adds it to the master fd list.
  727. *
  728. * IMPORTANT:
  729. * This functions publishes the fb and makes it available for concurrent access
  730. * by other users. Which means by this point the fb _must_ be fully set up -
  731. * since all the fb attributes are invariant over its lifetime, no further
  732. * locking but only correct reference counting is required.
  733. *
  734. * Returns:
  735. * Zero on success, error code on failure.
  736. */
  737. int drm_framebuffer_init(struct drm_device *dev, struct drm_framebuffer *fb,
  738. const struct drm_framebuffer_funcs *funcs)
  739. {
  740. unsigned int i;
  741. int ret;
  742. bool exists;
  743. if (WARN_ON_ONCE(fb->dev != dev || !fb->format))
  744. return -EINVAL;
  745. for (i = 0; i < fb->format->num_planes; i++) {
  746. if (drm_WARN_ON_ONCE(dev, fb->internal_flags & DRM_FRAMEBUFFER_HAS_HANDLE_REF(i)))
  747. fb->internal_flags &= ~DRM_FRAMEBUFFER_HAS_HANDLE_REF(i);
  748. if (fb->obj[i]) {
  749. exists = drm_gem_object_handle_get_if_exists_unlocked(fb->obj[i]);
  750. if (exists)
  751. fb->internal_flags |= DRM_FRAMEBUFFER_HAS_HANDLE_REF(i);
  752. }
  753. }
  754. INIT_LIST_HEAD(&fb->filp_head);
  755. fb->funcs = funcs;
  756. strscpy(fb->comm, current->comm);
  757. ret = __drm_mode_object_add(dev, &fb->base, DRM_MODE_OBJECT_FB,
  758. false, drm_framebuffer_free);
  759. if (ret)
  760. goto err;
  761. mutex_lock(&dev->mode_config.fb_lock);
  762. dev->mode_config.num_fb++;
  763. list_add(&fb->head, &dev->mode_config.fb_list);
  764. mutex_unlock(&dev->mode_config.fb_lock);
  765. drm_mode_object_register(dev, &fb->base);
  766. return 0;
  767. err:
  768. for (i = 0; i < fb->format->num_planes; i++) {
  769. if (fb->internal_flags & DRM_FRAMEBUFFER_HAS_HANDLE_REF(i)) {
  770. drm_gem_object_handle_put_unlocked(fb->obj[i]);
  771. fb->internal_flags &= ~DRM_FRAMEBUFFER_HAS_HANDLE_REF(i);
  772. }
  773. }
  774. return ret;
  775. }
  776. EXPORT_SYMBOL(drm_framebuffer_init);
  777. /**
  778. * drm_framebuffer_lookup - look up a drm framebuffer and grab a reference
  779. * @dev: drm device
  780. * @file_priv: drm file to check for lease against.
  781. * @id: id of the fb object
  782. *
  783. * If successful, this grabs an additional reference to the framebuffer -
  784. * callers need to make sure to eventually unreference the returned framebuffer
  785. * again, using drm_framebuffer_put().
  786. */
  787. struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev,
  788. struct drm_file *file_priv,
  789. uint32_t id)
  790. {
  791. struct drm_mode_object *obj;
  792. struct drm_framebuffer *fb = NULL;
  793. obj = __drm_mode_object_find(dev, file_priv, id, DRM_MODE_OBJECT_FB);
  794. if (obj)
  795. fb = obj_to_fb(obj);
  796. return fb;
  797. }
  798. EXPORT_SYMBOL(drm_framebuffer_lookup);
  799. /**
  800. * drm_framebuffer_unregister_private - unregister a private fb from the lookup idr
  801. * @fb: fb to unregister
  802. *
  803. * Drivers need to call this when cleaning up driver-private framebuffers, e.g.
  804. * those used for fbdev. Note that the caller must hold a reference of its own,
  805. * i.e. the object may not be destroyed through this call (since it'll lead to a
  806. * locking inversion).
  807. *
  808. * NOTE: This function is deprecated. For driver-private framebuffers it is not
  809. * recommended to embed a framebuffer struct info fbdev struct, instead, a
  810. * framebuffer pointer is preferred and drm_framebuffer_put() should be called
  811. * when the framebuffer is to be cleaned up.
  812. */
  813. void drm_framebuffer_unregister_private(struct drm_framebuffer *fb)
  814. {
  815. struct drm_device *dev;
  816. if (!fb)
  817. return;
  818. dev = fb->dev;
  819. /* Mark fb as reaped and drop idr ref. */
  820. drm_mode_object_unregister(dev, &fb->base);
  821. }
  822. EXPORT_SYMBOL(drm_framebuffer_unregister_private);
  823. /**
  824. * drm_framebuffer_cleanup - remove a framebuffer object
  825. * @fb: framebuffer to remove
  826. *
  827. * Cleanup framebuffer. This function is intended to be used from the drivers
  828. * &drm_framebuffer_funcs.destroy callback. It can also be used to clean up
  829. * driver private framebuffers embedded into a larger structure.
  830. *
  831. * Note that this function does not remove the fb from active usage - if it is
  832. * still used anywhere, hilarity can ensue since userspace could call getfb on
  833. * the id and get back -EINVAL. Obviously no concern at driver unload time.
  834. *
  835. * Also, the framebuffer will not be removed from the lookup idr - for
  836. * user-created framebuffers this will happen in the rmfb ioctl. For
  837. * driver-private objects (e.g. for fbdev) drivers need to explicitly call
  838. * drm_framebuffer_unregister_private.
  839. */
  840. void drm_framebuffer_cleanup(struct drm_framebuffer *fb)
  841. {
  842. struct drm_device *dev = fb->dev;
  843. unsigned int i;
  844. for (i = 0; i < fb->format->num_planes; i++) {
  845. if (fb->internal_flags & DRM_FRAMEBUFFER_HAS_HANDLE_REF(i))
  846. drm_gem_object_handle_put_unlocked(fb->obj[i]);
  847. }
  848. mutex_lock(&dev->mode_config.fb_lock);
  849. list_del(&fb->head);
  850. dev->mode_config.num_fb--;
  851. mutex_unlock(&dev->mode_config.fb_lock);
  852. }
  853. EXPORT_SYMBOL(drm_framebuffer_cleanup);
  854. static int atomic_remove_fb(struct drm_framebuffer *fb)
  855. {
  856. struct drm_modeset_acquire_ctx ctx;
  857. struct drm_device *dev = fb->dev;
  858. struct drm_atomic_state *state;
  859. struct drm_plane *plane;
  860. struct drm_connector *conn __maybe_unused;
  861. struct drm_connector_state *conn_state;
  862. int i, ret;
  863. unsigned plane_mask;
  864. bool disable_crtcs = false;
  865. retry_disable:
  866. drm_modeset_acquire_init(&ctx, 0);
  867. state = drm_atomic_state_alloc(dev);
  868. if (!state) {
  869. ret = -ENOMEM;
  870. goto out;
  871. }
  872. state->acquire_ctx = &ctx;
  873. retry:
  874. plane_mask = 0;
  875. ret = drm_modeset_lock_all_ctx(dev, &ctx);
  876. if (ret)
  877. goto unlock;
  878. drm_for_each_plane(plane, dev) {
  879. struct drm_plane_state *plane_state;
  880. if (plane->state->fb != fb)
  881. continue;
  882. drm_dbg_kms(dev,
  883. "Disabling [PLANE:%d:%s] because [FB:%d] is removed\n",
  884. plane->base.id, plane->name, fb->base.id);
  885. plane_state = drm_atomic_get_plane_state(state, plane);
  886. if (IS_ERR(plane_state)) {
  887. ret = PTR_ERR(plane_state);
  888. goto unlock;
  889. }
  890. if (disable_crtcs && plane_state->crtc->primary == plane) {
  891. struct drm_crtc_state *crtc_state;
  892. drm_dbg_kms(dev,
  893. "Disabling [CRTC:%d:%s] because [FB:%d] is removed\n",
  894. plane_state->crtc->base.id,
  895. plane_state->crtc->name, fb->base.id);
  896. crtc_state = drm_atomic_get_new_crtc_state(state, plane_state->crtc);
  897. ret = drm_atomic_add_affected_connectors(state, plane_state->crtc);
  898. if (ret)
  899. goto unlock;
  900. crtc_state->active = false;
  901. ret = drm_atomic_set_mode_for_crtc(crtc_state, NULL);
  902. if (ret)
  903. goto unlock;
  904. }
  905. drm_atomic_set_fb_for_plane(plane_state, NULL);
  906. ret = drm_atomic_set_crtc_for_plane(plane_state, NULL);
  907. if (ret)
  908. goto unlock;
  909. plane_mask |= drm_plane_mask(plane);
  910. }
  911. /* This list is only filled when disable_crtcs is set. */
  912. for_each_new_connector_in_state(state, conn, conn_state, i) {
  913. ret = drm_atomic_set_crtc_for_connector(conn_state, NULL);
  914. if (ret)
  915. goto unlock;
  916. }
  917. if (plane_mask)
  918. ret = drm_atomic_commit(state);
  919. unlock:
  920. if (ret == -EDEADLK) {
  921. drm_atomic_state_clear(state);
  922. drm_modeset_backoff(&ctx);
  923. goto retry;
  924. }
  925. drm_atomic_state_put(state);
  926. out:
  927. drm_modeset_drop_locks(&ctx);
  928. drm_modeset_acquire_fini(&ctx);
  929. if (ret == -EINVAL && !disable_crtcs) {
  930. disable_crtcs = true;
  931. goto retry_disable;
  932. }
  933. return ret;
  934. }
  935. static void legacy_remove_fb(struct drm_framebuffer *fb)
  936. {
  937. struct drm_device *dev = fb->dev;
  938. struct drm_crtc *crtc;
  939. struct drm_plane *plane;
  940. drm_modeset_lock_all(dev);
  941. /* remove from any CRTC */
  942. drm_for_each_crtc(crtc, dev) {
  943. if (crtc->primary->fb == fb) {
  944. drm_dbg_kms(dev,
  945. "Disabling [CRTC:%d:%s] because [FB:%d] is removed\n",
  946. crtc->base.id, crtc->name, fb->base.id);
  947. /* should turn off the crtc */
  948. if (drm_crtc_force_disable(crtc))
  949. DRM_ERROR("failed to reset crtc %p when fb was deleted\n", crtc);
  950. }
  951. }
  952. drm_for_each_plane(plane, dev) {
  953. if (plane->fb == fb) {
  954. drm_dbg_kms(dev,
  955. "Disabling [PLANE:%d:%s] because [FB:%d] is removed\n",
  956. plane->base.id, plane->name, fb->base.id);
  957. drm_plane_force_disable(plane);
  958. }
  959. }
  960. drm_modeset_unlock_all(dev);
  961. }
  962. /**
  963. * drm_framebuffer_remove - remove and unreference a framebuffer object
  964. * @fb: framebuffer to remove
  965. *
  966. * Scans all the CRTCs and planes in @dev's mode_config. If they're
  967. * using @fb, removes it, setting it to NULL. Then drops the reference to the
  968. * passed-in framebuffer. Might take the modeset locks.
  969. *
  970. * Note that this function optimizes the cleanup away if the caller holds the
  971. * last reference to the framebuffer. It is also guaranteed to not take the
  972. * modeset locks in this case.
  973. */
  974. void drm_framebuffer_remove(struct drm_framebuffer *fb)
  975. {
  976. struct drm_device *dev;
  977. if (!fb)
  978. return;
  979. dev = fb->dev;
  980. drm_WARN_ON(dev, !list_empty(&fb->filp_head));
  981. /*
  982. * drm ABI mandates that we remove any deleted framebuffers from active
  983. * usage. But since most sane clients only remove framebuffers they no
  984. * longer need, try to optimize this away.
  985. *
  986. * Since we're holding a reference ourselves, observing a refcount of 1
  987. * means that we're the last holder and can skip it. Also, the refcount
  988. * can never increase from 1 again, so we don't need any barriers or
  989. * locks.
  990. *
  991. * Note that userspace could try to race with use and instate a new
  992. * usage _after_ we've cleared all current ones. End result will be an
  993. * in-use fb with fb-id == 0. Userspace is allowed to shoot its own foot
  994. * in this manner.
  995. */
  996. if (drm_framebuffer_read_refcount(fb) > 1) {
  997. if (drm_drv_uses_atomic_modeset(dev)) {
  998. int ret = atomic_remove_fb(fb);
  999. WARN(ret, "atomic remove_fb failed with %i\n", ret);
  1000. } else
  1001. legacy_remove_fb(fb);
  1002. }
  1003. drm_framebuffer_put(fb);
  1004. }
  1005. EXPORT_SYMBOL(drm_framebuffer_remove);
  1006. void drm_framebuffer_print_info(struct drm_printer *p, unsigned int indent,
  1007. const struct drm_framebuffer *fb)
  1008. {
  1009. unsigned int i;
  1010. drm_printf_indent(p, indent, "allocated by = %s\n", fb->comm);
  1011. drm_printf_indent(p, indent, "refcount=%u\n",
  1012. drm_framebuffer_read_refcount(fb));
  1013. drm_printf_indent(p, indent, "format=%p4cc\n", &fb->format->format);
  1014. drm_printf_indent(p, indent, "modifier=0x%llx\n", fb->modifier);
  1015. drm_printf_indent(p, indent, "size=%ux%u\n", fb->width, fb->height);
  1016. drm_printf_indent(p, indent, "layers:\n");
  1017. for (i = 0; i < fb->format->num_planes; i++) {
  1018. drm_printf_indent(p, indent + 1, "size[%u]=%dx%d\n", i,
  1019. drm_format_info_plane_width(fb->format, fb->width, i),
  1020. drm_format_info_plane_height(fb->format, fb->height, i));
  1021. drm_printf_indent(p, indent + 1, "pitch[%u]=%u\n", i, fb->pitches[i]);
  1022. drm_printf_indent(p, indent + 1, "offset[%u]=%u\n", i, fb->offsets[i]);
  1023. drm_printf_indent(p, indent + 1, "obj[%u]:%s\n", i,
  1024. fb->obj[i] ? "" : "(null)");
  1025. if (fb->obj[i])
  1026. drm_gem_print_info(p, indent + 2, fb->obj[i]);
  1027. }
  1028. }
  1029. #ifdef CONFIG_DEBUG_FS
  1030. static int drm_framebuffer_info(struct seq_file *m, void *data)
  1031. {
  1032. struct drm_debugfs_entry *entry = m->private;
  1033. struct drm_device *dev = entry->dev;
  1034. struct drm_printer p = drm_seq_file_printer(m);
  1035. struct drm_framebuffer *fb;
  1036. mutex_lock(&dev->mode_config.fb_lock);
  1037. drm_for_each_fb(fb, dev) {
  1038. drm_printf(&p, "framebuffer[%u]:\n", fb->base.id);
  1039. drm_framebuffer_print_info(&p, 1, fb);
  1040. }
  1041. mutex_unlock(&dev->mode_config.fb_lock);
  1042. return 0;
  1043. }
  1044. static const struct drm_debugfs_info drm_framebuffer_debugfs_list[] = {
  1045. { "framebuffer", drm_framebuffer_info, 0 },
  1046. };
  1047. void drm_framebuffer_debugfs_init(struct drm_device *dev)
  1048. {
  1049. drm_debugfs_add_files(dev, drm_framebuffer_debugfs_list,
  1050. ARRAY_SIZE(drm_framebuffer_debugfs_list));
  1051. }
  1052. #endif