Marcin Slusarz | 33b903e | 2013-02-08 21:42:13 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 Red Hat <bskeggs@redhat.com> |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining |
| 5 | * a copy of this software and associated documentation files (the |
| 6 | * "Software"), to deal in the Software without restriction, including |
| 7 | * without limitation the rights to use, copy, modify, merge, publish, |
| 8 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 9 | * permit persons to whom the Software is furnished to do so, subject to |
| 10 | * the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice (including the |
| 13 | * next paragraph) shall be included in all copies or substantial |
| 14 | * portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 19 | * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE |
| 20 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 21 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 22 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 23 | * |
| 24 | */ |
| 25 | |
| 26 | /* |
| 27 | * Authors: |
| 28 | * Ben Skeggs <bskeggs@redhat.com> |
| 29 | */ |
| 30 | |
Karol Herbst | 1b7ab1a | 2015-07-29 13:44:21 +0200 | [diff] [blame] | 31 | #include <linux/debugfs.h> |
Marcin Slusarz | 33b903e | 2013-02-08 21:42:13 +0100 | [diff] [blame] | 32 | #include "nouveau_debugfs.h" |
| 33 | #include "nouveau_drm.h" |
| 34 | |
| 35 | static int |
| 36 | nouveau_debugfs_vbios_image(struct seq_file *m, void *data) |
| 37 | { |
| 38 | struct drm_info_node *node = (struct drm_info_node *) m->private; |
| 39 | struct nouveau_drm *drm = nouveau_drm(node->minor->dev); |
| 40 | int i; |
| 41 | |
| 42 | for (i = 0; i < drm->vbios.length; i++) |
| 43 | seq_printf(m, "%c", drm->vbios.data[i]); |
| 44 | return 0; |
| 45 | } |
| 46 | |
| 47 | static struct drm_info_list nouveau_debugfs_list[] = { |
| 48 | { "vbios.rom", nouveau_debugfs_vbios_image, 0, NULL }, |
| 49 | }; |
| 50 | #define NOUVEAU_DEBUGFS_ENTRIES ARRAY_SIZE(nouveau_debugfs_list) |
| 51 | |
Karol Herbst | 1b7ab1a | 2015-07-29 13:44:21 +0200 | [diff] [blame] | 52 | static const struct nouveau_debugfs_files { |
| 53 | const char *name; |
| 54 | const struct file_operations *fops; |
| 55 | } nouveau_debugfs_files[] = {}; |
| 56 | |
| 57 | |
| 58 | static int |
| 59 | nouveau_debugfs_create_file(struct drm_minor *minor, |
| 60 | const struct nouveau_debugfs_files *ndf) |
| 61 | { |
| 62 | struct drm_info_node *node; |
| 63 | |
| 64 | node = kmalloc(sizeof(*node), GFP_KERNEL); |
| 65 | if (node == NULL) |
| 66 | return -ENOMEM; |
| 67 | |
| 68 | node->minor = minor; |
| 69 | node->info_ent = (const void *)ndf->fops; |
| 70 | node->dent = debugfs_create_file(ndf->name, S_IRUGO | S_IWUSR, |
| 71 | minor->debugfs_root, node, ndf->fops); |
| 72 | if (!node->dent) { |
| 73 | kfree(node); |
| 74 | return -ENOMEM; |
| 75 | } |
| 76 | |
| 77 | mutex_lock(&minor->debugfs_lock); |
| 78 | list_add(&node->list, &minor->debugfs_list); |
| 79 | mutex_unlock(&minor->debugfs_lock); |
| 80 | return 0; |
| 81 | } |
| 82 | |
Marcin Slusarz | 33b903e | 2013-02-08 21:42:13 +0100 | [diff] [blame] | 83 | int |
Karol Herbst | 56c101a | 2015-07-31 00:35:42 +0200 | [diff] [blame^] | 84 | nouveau_drm_debugfs_init(struct drm_minor *minor) |
Marcin Slusarz | 33b903e | 2013-02-08 21:42:13 +0100 | [diff] [blame] | 85 | { |
Karol Herbst | 1b7ab1a | 2015-07-29 13:44:21 +0200 | [diff] [blame] | 86 | int i, ret; |
| 87 | |
| 88 | for (i = 0; i < ARRAY_SIZE(nouveau_debugfs_files); i++) { |
| 89 | ret = nouveau_debugfs_create_file(minor, |
| 90 | &nouveau_debugfs_files[i]); |
| 91 | |
| 92 | if (ret) |
| 93 | return ret; |
| 94 | } |
| 95 | |
| 96 | return drm_debugfs_create_files(nouveau_debugfs_list, |
| 97 | NOUVEAU_DEBUGFS_ENTRIES, |
| 98 | minor->debugfs_root, minor); |
Marcin Slusarz | 33b903e | 2013-02-08 21:42:13 +0100 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | void |
Karol Herbst | 56c101a | 2015-07-31 00:35:42 +0200 | [diff] [blame^] | 102 | nouveau_drm_debugfs_cleanup(struct drm_minor *minor) |
Marcin Slusarz | 33b903e | 2013-02-08 21:42:13 +0100 | [diff] [blame] | 103 | { |
Karol Herbst | 1b7ab1a | 2015-07-29 13:44:21 +0200 | [diff] [blame] | 104 | int i; |
| 105 | |
Marcin Slusarz | 33b903e | 2013-02-08 21:42:13 +0100 | [diff] [blame] | 106 | drm_debugfs_remove_files(nouveau_debugfs_list, NOUVEAU_DEBUGFS_ENTRIES, |
| 107 | minor); |
Karol Herbst | 1b7ab1a | 2015-07-29 13:44:21 +0200 | [diff] [blame] | 108 | |
| 109 | for (i = 0; i < ARRAY_SIZE(nouveau_debugfs_files); i++) { |
| 110 | drm_debugfs_remove_files((struct drm_info_list *) |
| 111 | nouveau_debugfs_files[i].fops, |
| 112 | 1, minor); |
| 113 | } |
Marcin Slusarz | 33b903e | 2013-02-08 21:42:13 +0100 | [diff] [blame] | 114 | } |