drm_debugfs.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799
  1. /*
  2. * Created: Sun Dec 21 13:08:50 2008 by bgamari@gmail.com
  3. *
  4. * Copyright 2008 Ben Gamari <bgamari@gmail.com>
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the "Software"),
  8. * to deal in the Software without restriction, including without limitation
  9. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  10. * and/or sell copies of the Software, and to permit persons to whom the
  11. * Software is furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice (including the next
  14. * paragraph) shall be included in all copies or substantial portions of the
  15. * Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  20. * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  21. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  22. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  23. * OTHER DEALINGS IN THE SOFTWARE.
  24. */
  25. #include <linux/debugfs.h>
  26. #include <linux/export.h>
  27. #include <linux/seq_file.h>
  28. #include <linux/slab.h>
  29. #include <linux/uaccess.h>
  30. #include <drm/drm_atomic.h>
  31. #include <drm/drm_auth.h>
  32. #include <drm/drm_bridge.h>
  33. #include <drm/drm_client.h>
  34. #include <drm/drm_debugfs.h>
  35. #include <drm/drm_device.h>
  36. #include <drm/drm_drv.h>
  37. #include <drm/drm_edid.h>
  38. #include <drm/drm_file.h>
  39. #include <drm/drm_gem.h>
  40. #include <drm/drm_managed.h>
  41. #include <drm/drm_gpuvm.h>
  42. #include "drm_crtc_internal.h"
  43. #include "drm_internal.h"
  44. /***************************************************
  45. * Initialization, etc.
  46. **************************************************/
  47. static int drm_name_info(struct seq_file *m, void *data)
  48. {
  49. struct drm_debugfs_entry *entry = m->private;
  50. struct drm_device *dev = entry->dev;
  51. struct drm_master *master;
  52. mutex_lock(&dev->master_mutex);
  53. master = dev->master;
  54. seq_printf(m, "%s", dev->driver->name);
  55. if (dev->dev)
  56. seq_printf(m, " dev=%s", dev_name(dev->dev));
  57. if (master && master->unique)
  58. seq_printf(m, " master=%s", master->unique);
  59. if (dev->unique)
  60. seq_printf(m, " unique=%s", dev->unique);
  61. seq_printf(m, "\n");
  62. mutex_unlock(&dev->master_mutex);
  63. return 0;
  64. }
  65. static int drm_clients_info(struct seq_file *m, void *data)
  66. {
  67. struct drm_debugfs_entry *entry = m->private;
  68. struct drm_device *dev = entry->dev;
  69. struct drm_file *priv;
  70. kuid_t uid;
  71. seq_printf(m,
  72. "%20s %5s %3s master a %5s %10s\n",
  73. "command",
  74. "tgid",
  75. "dev",
  76. "uid",
  77. "magic");
  78. /* dev->filelist is sorted youngest first, but we want to present
  79. * oldest first (i.e. kernel, servers, clients), so walk backwardss.
  80. */
  81. mutex_lock(&dev->filelist_mutex);
  82. list_for_each_entry_reverse(priv, &dev->filelist, lhead) {
  83. bool is_current_master = drm_is_current_master(priv);
  84. struct task_struct *task;
  85. struct pid *pid;
  86. rcu_read_lock(); /* Locks priv->pid and pid_task()->comm! */
  87. pid = rcu_dereference(priv->pid);
  88. task = pid_task(pid, PIDTYPE_TGID);
  89. uid = task ? __task_cred(task)->euid : GLOBAL_ROOT_UID;
  90. seq_printf(m, "%20s %5d %3d %c %c %5d %10u\n",
  91. task ? task->comm : "<unknown>",
  92. pid_vnr(pid),
  93. priv->minor->index,
  94. is_current_master ? 'y' : 'n',
  95. priv->authenticated ? 'y' : 'n',
  96. from_kuid_munged(seq_user_ns(m), uid),
  97. priv->magic);
  98. rcu_read_unlock();
  99. }
  100. mutex_unlock(&dev->filelist_mutex);
  101. return 0;
  102. }
  103. static int drm_gem_one_name_info(int id, void *ptr, void *data)
  104. {
  105. struct drm_gem_object *obj = ptr;
  106. struct seq_file *m = data;
  107. seq_printf(m, "%6d %8zd %7d %8d\n",
  108. obj->name, obj->size,
  109. obj->handle_count,
  110. kref_read(&obj->refcount));
  111. return 0;
  112. }
  113. static int drm_gem_name_info(struct seq_file *m, void *data)
  114. {
  115. struct drm_debugfs_entry *entry = m->private;
  116. struct drm_device *dev = entry->dev;
  117. seq_printf(m, " name size handles refcount\n");
  118. mutex_lock(&dev->object_name_lock);
  119. idr_for_each(&dev->object_name_idr, drm_gem_one_name_info, m);
  120. mutex_unlock(&dev->object_name_lock);
  121. return 0;
  122. }
  123. static const struct drm_debugfs_info drm_debugfs_list[] = {
  124. {"name", drm_name_info, 0},
  125. {"clients", drm_clients_info, 0},
  126. {"gem_names", drm_gem_name_info, DRIVER_GEM},
  127. };
  128. #define DRM_DEBUGFS_ENTRIES ARRAY_SIZE(drm_debugfs_list)
  129. static int drm_debugfs_open(struct inode *inode, struct file *file)
  130. {
  131. struct drm_info_node *node = inode->i_private;
  132. if (!device_is_registered(node->minor->kdev))
  133. return -ENODEV;
  134. return single_open(file, node->info_ent->show, node);
  135. }
  136. static int drm_debugfs_entry_open(struct inode *inode, struct file *file)
  137. {
  138. struct drm_debugfs_entry *entry = inode->i_private;
  139. struct drm_debugfs_info *node = &entry->file;
  140. struct drm_minor *minor = entry->dev->primary ?: entry->dev->accel;
  141. if (!device_is_registered(minor->kdev))
  142. return -ENODEV;
  143. return single_open(file, node->show, entry);
  144. }
  145. static const struct file_operations drm_debugfs_entry_fops = {
  146. .owner = THIS_MODULE,
  147. .open = drm_debugfs_entry_open,
  148. .read = seq_read,
  149. .llseek = seq_lseek,
  150. .release = single_release,
  151. };
  152. static const struct file_operations drm_debugfs_fops = {
  153. .owner = THIS_MODULE,
  154. .open = drm_debugfs_open,
  155. .read = seq_read,
  156. .llseek = seq_lseek,
  157. .release = single_release,
  158. };
  159. /**
  160. * drm_debugfs_gpuva_info - dump the given DRM GPU VA space
  161. * @m: pointer to the &seq_file to write
  162. * @gpuvm: the &drm_gpuvm representing the GPU VA space
  163. *
  164. * Dumps the GPU VA mappings of a given DRM GPU VA manager.
  165. *
  166. * For each DRM GPU VA space drivers should call this function from their
  167. * &drm_info_list's show callback.
  168. *
  169. * Returns: 0 on success, -ENODEV if the &gpuvm is not initialized
  170. */
  171. int drm_debugfs_gpuva_info(struct seq_file *m,
  172. struct drm_gpuvm *gpuvm)
  173. {
  174. struct drm_gpuva *va, *kva = &gpuvm->kernel_alloc_node;
  175. if (!gpuvm->name)
  176. return -ENODEV;
  177. seq_printf(m, "DRM GPU VA space (%s) [0x%016llx;0x%016llx]\n",
  178. gpuvm->name, gpuvm->mm_start, gpuvm->mm_start + gpuvm->mm_range);
  179. seq_printf(m, "Kernel reserved node [0x%016llx;0x%016llx]\n",
  180. kva->va.addr, kva->va.addr + kva->va.range);
  181. seq_puts(m, "\n");
  182. seq_puts(m, " VAs | start | range | end | object | object offset\n");
  183. seq_puts(m, "-------------------------------------------------------------------------------------------------------------\n");
  184. drm_gpuvm_for_each_va(va, gpuvm) {
  185. if (unlikely(va == kva))
  186. continue;
  187. seq_printf(m, " | 0x%016llx | 0x%016llx | 0x%016llx | 0x%016llx | 0x%016llx\n",
  188. va->va.addr, va->va.range, va->va.addr + va->va.range,
  189. (u64)(uintptr_t)va->gem.obj, va->gem.offset);
  190. }
  191. return 0;
  192. }
  193. EXPORT_SYMBOL(drm_debugfs_gpuva_info);
  194. /**
  195. * drm_debugfs_create_files - Initialize a given set of debugfs files for DRM
  196. * minor
  197. * @files: The array of files to create
  198. * @count: The number of files given
  199. * @root: DRI debugfs dir entry.
  200. * @minor: device minor number
  201. *
  202. * Create a given set of debugfs files represented by an array of
  203. * &struct drm_info_list in the given root directory. These files will be removed
  204. * automatically on drm_debugfs_dev_fini().
  205. */
  206. void drm_debugfs_create_files(const struct drm_info_list *files, int count,
  207. struct dentry *root, struct drm_minor *minor)
  208. {
  209. struct drm_device *dev = minor->dev;
  210. struct drm_info_node *tmp;
  211. int i;
  212. for (i = 0; i < count; i++) {
  213. u32 features = files[i].driver_features;
  214. if (features && !drm_core_check_all_features(dev, features))
  215. continue;
  216. tmp = drmm_kzalloc(dev, sizeof(*tmp), GFP_KERNEL);
  217. if (tmp == NULL)
  218. continue;
  219. tmp->minor = minor;
  220. tmp->dent = debugfs_create_file(files[i].name,
  221. 0444, root, tmp,
  222. &drm_debugfs_fops);
  223. tmp->info_ent = &files[i];
  224. }
  225. }
  226. EXPORT_SYMBOL(drm_debugfs_create_files);
  227. int drm_debugfs_remove_files(const struct drm_info_list *files, int count,
  228. struct dentry *root, struct drm_minor *minor)
  229. {
  230. int i;
  231. for (i = 0; i < count; i++) {
  232. struct dentry *dent = debugfs_lookup(files[i].name, root);
  233. if (!dent)
  234. continue;
  235. drmm_kfree(minor->dev, d_inode(dent)->i_private);
  236. debugfs_remove(dent);
  237. }
  238. return 0;
  239. }
  240. EXPORT_SYMBOL(drm_debugfs_remove_files);
  241. /**
  242. * drm_debugfs_dev_init - create debugfs directory for the device
  243. * @dev: the device which we want to create the directory for
  244. * @root: the parent directory depending on the device type
  245. *
  246. * Creates the debugfs directory for the device under the given root directory.
  247. */
  248. void drm_debugfs_dev_init(struct drm_device *dev, struct dentry *root)
  249. {
  250. dev->debugfs_root = debugfs_create_dir(dev->unique, root);
  251. }
  252. /**
  253. * drm_debugfs_dev_fini - cleanup debugfs directory
  254. * @dev: the device to cleanup the debugfs stuff
  255. *
  256. * Remove the debugfs directory, might be called multiple times.
  257. */
  258. void drm_debugfs_dev_fini(struct drm_device *dev)
  259. {
  260. debugfs_remove_recursive(dev->debugfs_root);
  261. dev->debugfs_root = NULL;
  262. }
  263. void drm_debugfs_dev_register(struct drm_device *dev)
  264. {
  265. drm_debugfs_add_files(dev, drm_debugfs_list, DRM_DEBUGFS_ENTRIES);
  266. if (drm_core_check_feature(dev, DRIVER_MODESET)) {
  267. drm_framebuffer_debugfs_init(dev);
  268. drm_client_debugfs_init(dev);
  269. }
  270. if (drm_drv_uses_atomic_modeset(dev))
  271. drm_atomic_debugfs_init(dev);
  272. }
  273. int drm_debugfs_register(struct drm_minor *minor, int minor_id,
  274. struct dentry *root)
  275. {
  276. struct drm_device *dev = minor->dev;
  277. char name[64];
  278. sprintf(name, "%d", minor_id);
  279. minor->debugfs_symlink = debugfs_create_symlink(name, root,
  280. dev->unique);
  281. /* TODO: Only for compatibility with drivers */
  282. minor->debugfs_root = dev->debugfs_root;
  283. if (dev->driver->debugfs_init && dev->render != minor)
  284. dev->driver->debugfs_init(minor);
  285. return 0;
  286. }
  287. void drm_debugfs_unregister(struct drm_minor *minor)
  288. {
  289. debugfs_remove(minor->debugfs_symlink);
  290. minor->debugfs_symlink = NULL;
  291. }
  292. /**
  293. * drm_debugfs_add_file - Add a given file to the DRM device debugfs file list
  294. * @dev: drm device for the ioctl
  295. * @name: debugfs file name
  296. * @show: show callback
  297. * @data: driver-private data, should not be device-specific
  298. *
  299. * Add a given file entry to the DRM device debugfs file list to be created on
  300. * drm_debugfs_init.
  301. */
  302. void drm_debugfs_add_file(struct drm_device *dev, const char *name,
  303. int (*show)(struct seq_file*, void*), void *data)
  304. {
  305. struct drm_debugfs_entry *entry = drmm_kzalloc(dev, sizeof(*entry), GFP_KERNEL);
  306. if (!entry)
  307. return;
  308. entry->file.name = name;
  309. entry->file.show = show;
  310. entry->file.data = data;
  311. entry->dev = dev;
  312. debugfs_create_file(name, 0444, dev->debugfs_root, entry,
  313. &drm_debugfs_entry_fops);
  314. }
  315. EXPORT_SYMBOL(drm_debugfs_add_file);
  316. /**
  317. * drm_debugfs_add_files - Add an array of files to the DRM device debugfs file list
  318. * @dev: drm device for the ioctl
  319. * @files: The array of files to create
  320. * @count: The number of files given
  321. *
  322. * Add a given set of debugfs files represented by an array of
  323. * &struct drm_debugfs_info in the DRM device debugfs file list.
  324. */
  325. void drm_debugfs_add_files(struct drm_device *dev, const struct drm_debugfs_info *files, int count)
  326. {
  327. int i;
  328. for (i = 0; i < count; i++)
  329. drm_debugfs_add_file(dev, files[i].name, files[i].show, files[i].data);
  330. }
  331. EXPORT_SYMBOL(drm_debugfs_add_files);
  332. static int connector_show(struct seq_file *m, void *data)
  333. {
  334. struct drm_connector *connector = m->private;
  335. seq_printf(m, "%s\n", drm_get_connector_force_name(connector->force));
  336. return 0;
  337. }
  338. static int connector_open(struct inode *inode, struct file *file)
  339. {
  340. struct drm_connector *dev = inode->i_private;
  341. return single_open(file, connector_show, dev);
  342. }
  343. static ssize_t connector_write(struct file *file, const char __user *ubuf,
  344. size_t len, loff_t *offp)
  345. {
  346. struct seq_file *m = file->private_data;
  347. struct drm_connector *connector = m->private;
  348. char buf[12];
  349. if (len > sizeof(buf) - 1)
  350. return -EINVAL;
  351. if (copy_from_user(buf, ubuf, len))
  352. return -EFAULT;
  353. buf[len] = '\0';
  354. if (sysfs_streq(buf, "on"))
  355. connector->force = DRM_FORCE_ON;
  356. else if (sysfs_streq(buf, "digital"))
  357. connector->force = DRM_FORCE_ON_DIGITAL;
  358. else if (sysfs_streq(buf, "off"))
  359. connector->force = DRM_FORCE_OFF;
  360. else if (sysfs_streq(buf, "unspecified"))
  361. connector->force = DRM_FORCE_UNSPECIFIED;
  362. else
  363. return -EINVAL;
  364. return len;
  365. }
  366. static int edid_show(struct seq_file *m, void *data)
  367. {
  368. return drm_edid_override_show(m->private, m);
  369. }
  370. static int edid_open(struct inode *inode, struct file *file)
  371. {
  372. struct drm_connector *dev = inode->i_private;
  373. return single_open(file, edid_show, dev);
  374. }
  375. static ssize_t edid_write(struct file *file, const char __user *ubuf,
  376. size_t len, loff_t *offp)
  377. {
  378. struct seq_file *m = file->private_data;
  379. struct drm_connector *connector = m->private;
  380. char *buf;
  381. int ret;
  382. buf = memdup_user(ubuf, len);
  383. if (IS_ERR(buf))
  384. return PTR_ERR(buf);
  385. if (len == 5 && !strncmp(buf, "reset", 5))
  386. ret = drm_edid_override_reset(connector);
  387. else
  388. ret = drm_edid_override_set(connector, buf, len);
  389. kfree(buf);
  390. return ret ? ret : len;
  391. }
  392. /*
  393. * Returns the min and max vrr vfreq through the connector's debugfs file.
  394. * Example usage: cat /sys/kernel/debug/dri/0/DP-1/vrr_range
  395. */
  396. static int vrr_range_show(struct seq_file *m, void *data)
  397. {
  398. struct drm_connector *connector = m->private;
  399. if (connector->status != connector_status_connected)
  400. return -ENODEV;
  401. seq_printf(m, "Min: %u\n", connector->display_info.monitor_range.min_vfreq);
  402. seq_printf(m, "Max: %u\n", connector->display_info.monitor_range.max_vfreq);
  403. return 0;
  404. }
  405. DEFINE_SHOW_ATTRIBUTE(vrr_range);
  406. /*
  407. * Returns Connector's max supported bpc through debugfs file.
  408. * Example usage: cat /sys/kernel/debug/dri/0/DP-1/output_bpc
  409. */
  410. static int output_bpc_show(struct seq_file *m, void *data)
  411. {
  412. struct drm_connector *connector = m->private;
  413. if (connector->status != connector_status_connected)
  414. return -ENODEV;
  415. seq_printf(m, "Maximum: %u\n", connector->display_info.bpc);
  416. return 0;
  417. }
  418. DEFINE_SHOW_ATTRIBUTE(output_bpc);
  419. static const struct file_operations drm_edid_fops = {
  420. .owner = THIS_MODULE,
  421. .open = edid_open,
  422. .read = seq_read,
  423. .llseek = seq_lseek,
  424. .release = single_release,
  425. .write = edid_write
  426. };
  427. static const struct file_operations drm_connector_fops = {
  428. .owner = THIS_MODULE,
  429. .open = connector_open,
  430. .read = seq_read,
  431. .llseek = seq_lseek,
  432. .release = single_release,
  433. .write = connector_write
  434. };
  435. static ssize_t
  436. audio_infoframe_read(struct file *filp, char __user *ubuf, size_t count, loff_t *ppos)
  437. {
  438. struct drm_connector_hdmi_infoframe *infoframe;
  439. struct drm_connector *connector;
  440. union hdmi_infoframe *frame;
  441. u8 buf[HDMI_INFOFRAME_SIZE(AUDIO)];
  442. ssize_t len = 0;
  443. connector = filp->private_data;
  444. mutex_lock(&connector->hdmi.infoframes.lock);
  445. infoframe = &connector->hdmi.infoframes.audio;
  446. if (!infoframe->set)
  447. goto out;
  448. frame = &infoframe->data;
  449. len = hdmi_infoframe_pack(frame, buf, sizeof(buf));
  450. if (len < 0)
  451. goto out;
  452. len = simple_read_from_buffer(ubuf, count, ppos, buf, len);
  453. out:
  454. mutex_unlock(&connector->hdmi.infoframes.lock);
  455. return len;
  456. }
  457. static const struct file_operations audio_infoframe_fops = {
  458. .owner = THIS_MODULE,
  459. .open = simple_open,
  460. .read = audio_infoframe_read,
  461. };
  462. static int create_hdmi_audio_infoframe_file(struct drm_connector *connector,
  463. struct dentry *parent)
  464. {
  465. struct dentry *file;
  466. file = debugfs_create_file("audio", 0400, parent, connector, &audio_infoframe_fops);
  467. if (IS_ERR(file))
  468. return PTR_ERR(file);
  469. return 0;
  470. }
  471. #define DEFINE_INFOFRAME_FILE(_f) \
  472. static ssize_t _f##_read_infoframe(struct file *filp, \
  473. char __user *ubuf, \
  474. size_t count, \
  475. loff_t *ppos) \
  476. { \
  477. struct drm_connector_hdmi_infoframe *infoframe; \
  478. struct drm_connector_state *conn_state; \
  479. struct drm_connector *connector; \
  480. union hdmi_infoframe *frame; \
  481. struct drm_device *dev; \
  482. u8 buf[HDMI_INFOFRAME_SIZE(MAX)]; \
  483. ssize_t len = 0; \
  484. \
  485. connector = filp->private_data; \
  486. dev = connector->dev; \
  487. \
  488. drm_modeset_lock(&dev->mode_config.connection_mutex, NULL); \
  489. \
  490. conn_state = connector->state; \
  491. infoframe = &conn_state->hdmi.infoframes._f; \
  492. if (!infoframe->set) \
  493. goto out; \
  494. \
  495. frame = &infoframe->data; \
  496. len = hdmi_infoframe_pack(frame, buf, sizeof(buf)); \
  497. if (len < 0) \
  498. goto out; \
  499. \
  500. len = simple_read_from_buffer(ubuf, count, ppos, buf, len); \
  501. \
  502. out: \
  503. drm_modeset_unlock(&dev->mode_config.connection_mutex); \
  504. return len; \
  505. } \
  506. \
  507. static const struct file_operations _f##_infoframe_fops = { \
  508. .owner = THIS_MODULE, \
  509. .open = simple_open, \
  510. .read = _f##_read_infoframe, \
  511. }; \
  512. \
  513. static int create_hdmi_## _f ## _infoframe_file(struct drm_connector *connector, \
  514. struct dentry *parent) \
  515. { \
  516. struct dentry *file; \
  517. \
  518. file = debugfs_create_file(#_f, 0400, parent, connector, &_f ## _infoframe_fops); \
  519. if (IS_ERR(file)) \
  520. return PTR_ERR(file); \
  521. \
  522. return 0; \
  523. }
  524. DEFINE_INFOFRAME_FILE(avi);
  525. DEFINE_INFOFRAME_FILE(hdmi);
  526. DEFINE_INFOFRAME_FILE(hdr_drm);
  527. DEFINE_INFOFRAME_FILE(spd);
  528. static int create_hdmi_infoframe_files(struct drm_connector *connector,
  529. struct dentry *parent)
  530. {
  531. int ret;
  532. ret = create_hdmi_audio_infoframe_file(connector, parent);
  533. if (ret)
  534. return ret;
  535. ret = create_hdmi_avi_infoframe_file(connector, parent);
  536. if (ret)
  537. return ret;
  538. ret = create_hdmi_hdmi_infoframe_file(connector, parent);
  539. if (ret)
  540. return ret;
  541. ret = create_hdmi_hdr_drm_infoframe_file(connector, parent);
  542. if (ret)
  543. return ret;
  544. ret = create_hdmi_spd_infoframe_file(connector, parent);
  545. if (ret)
  546. return ret;
  547. return 0;
  548. }
  549. static void hdmi_debugfs_add(struct drm_connector *connector)
  550. {
  551. struct dentry *dir;
  552. if (!(connector->connector_type == DRM_MODE_CONNECTOR_HDMIA ||
  553. connector->connector_type == DRM_MODE_CONNECTOR_HDMIB))
  554. return;
  555. dir = debugfs_create_dir("infoframes", connector->debugfs_entry);
  556. if (IS_ERR(dir))
  557. return;
  558. create_hdmi_infoframe_files(connector, dir);
  559. }
  560. void drm_debugfs_connector_add(struct drm_connector *connector)
  561. {
  562. struct drm_device *dev = connector->dev;
  563. struct dentry *root;
  564. if (!dev->debugfs_root)
  565. return;
  566. root = debugfs_create_dir(connector->name, dev->debugfs_root);
  567. connector->debugfs_entry = root;
  568. /* force */
  569. debugfs_create_file("force", 0644, root, connector,
  570. &drm_connector_fops);
  571. /* edid */
  572. debugfs_create_file("edid_override", 0644, root, connector,
  573. &drm_edid_fops);
  574. /* vrr range */
  575. debugfs_create_file("vrr_range", 0444, root, connector,
  576. &vrr_range_fops);
  577. /* max bpc */
  578. debugfs_create_file("output_bpc", 0444, root, connector,
  579. &output_bpc_fops);
  580. hdmi_debugfs_add(connector);
  581. if (connector->funcs->debugfs_init)
  582. connector->funcs->debugfs_init(connector, root);
  583. }
  584. void drm_debugfs_connector_remove(struct drm_connector *connector)
  585. {
  586. if (!connector->debugfs_entry)
  587. return;
  588. debugfs_remove_recursive(connector->debugfs_entry);
  589. connector->debugfs_entry = NULL;
  590. }
  591. void drm_debugfs_crtc_add(struct drm_crtc *crtc)
  592. {
  593. struct drm_device *dev = crtc->dev;
  594. struct dentry *root;
  595. char *name;
  596. name = kasprintf(GFP_KERNEL, "crtc-%d", crtc->index);
  597. if (!name)
  598. return;
  599. root = debugfs_create_dir(name, dev->debugfs_root);
  600. kfree(name);
  601. crtc->debugfs_entry = root;
  602. drm_debugfs_crtc_crc_add(crtc);
  603. }
  604. void drm_debugfs_crtc_remove(struct drm_crtc *crtc)
  605. {
  606. debugfs_remove_recursive(crtc->debugfs_entry);
  607. crtc->debugfs_entry = NULL;
  608. }
  609. static int bridges_show(struct seq_file *m, void *data)
  610. {
  611. struct drm_encoder *encoder = m->private;
  612. struct drm_printer p = drm_seq_file_printer(m);
  613. struct drm_bridge *bridge;
  614. unsigned int idx = 0;
  615. drm_for_each_bridge_in_chain(encoder, bridge) {
  616. drm_printf(&p, "bridge[%u]: %ps\n", idx++, bridge->funcs);
  617. drm_printf(&p, "\ttype: [%d] %s\n",
  618. bridge->type,
  619. drm_get_connector_type_name(bridge->type));
  620. if (bridge->of_node)
  621. drm_printf(&p, "\tOF: %pOFfc\n", bridge->of_node);
  622. drm_printf(&p, "\tops: [0x%x]", bridge->ops);
  623. if (bridge->ops & DRM_BRIDGE_OP_DETECT)
  624. drm_puts(&p, " detect");
  625. if (bridge->ops & DRM_BRIDGE_OP_EDID)
  626. drm_puts(&p, " edid");
  627. if (bridge->ops & DRM_BRIDGE_OP_HPD)
  628. drm_puts(&p, " hpd");
  629. if (bridge->ops & DRM_BRIDGE_OP_MODES)
  630. drm_puts(&p, " modes");
  631. if (bridge->ops & DRM_BRIDGE_OP_HDMI)
  632. drm_puts(&p, " hdmi");
  633. drm_puts(&p, "\n");
  634. }
  635. return 0;
  636. }
  637. DEFINE_SHOW_ATTRIBUTE(bridges);
  638. void drm_debugfs_encoder_add(struct drm_encoder *encoder)
  639. {
  640. struct drm_minor *minor = encoder->dev->primary;
  641. struct dentry *root;
  642. char *name;
  643. name = kasprintf(GFP_KERNEL, "encoder-%d", encoder->index);
  644. if (!name)
  645. return;
  646. root = debugfs_create_dir(name, minor->debugfs_root);
  647. kfree(name);
  648. encoder->debugfs_entry = root;
  649. /* bridges list */
  650. debugfs_create_file("bridges", 0444, root, encoder,
  651. &bridges_fops);
  652. if (encoder->funcs && encoder->funcs->debugfs_init)
  653. encoder->funcs->debugfs_init(encoder, root);
  654. }
  655. void drm_debugfs_encoder_remove(struct drm_encoder *encoder)
  656. {
  657. debugfs_remove_recursive(encoder->debugfs_entry);
  658. encoder->debugfs_entry = NULL;
  659. }