| .. | .. |
|---|
| 24 | 24 | */ |
|---|
| 25 | 25 | |
|---|
| 26 | 26 | #include <linux/debugfs.h> |
|---|
| 27 | +#include <linux/export.h> |
|---|
| 27 | 28 | #include <linux/seq_file.h> |
|---|
| 28 | 29 | #include <linux/slab.h> |
|---|
| 29 | | -#include <linux/export.h> |
|---|
| 30 | | -#include <linux/ctype.h> |
|---|
| 31 | | -#include <linux/syscalls.h> |
|---|
| 30 | +#include <linux/uaccess.h> |
|---|
| 32 | 31 | |
|---|
| 32 | +#include <drm/drm_atomic.h> |
|---|
| 33 | +#include <drm/drm_auth.h> |
|---|
| 33 | 34 | #include <drm/drm_client.h> |
|---|
| 34 | 35 | #include <drm/drm_debugfs.h> |
|---|
| 36 | +#include <drm/drm_device.h> |
|---|
| 37 | +#include <drm/drm_drv.h> |
|---|
| 35 | 38 | #include <drm/drm_edid.h> |
|---|
| 36 | | -#include <drm/drm_atomic.h> |
|---|
| 37 | | -#include <drm/drmP.h> |
|---|
| 39 | +#include <drm/drm_file.h> |
|---|
| 40 | +#include <drm/drm_gem.h> |
|---|
| 38 | 41 | |
|---|
| 39 | | -#include "drm_internal.h" |
|---|
| 40 | 42 | #include "drm_crtc_internal.h" |
|---|
| 43 | +#include "drm_internal.h" |
|---|
| 41 | 44 | |
|---|
| 42 | 45 | #if defined(CONFIG_DEBUG_FS) |
|---|
| 43 | | - |
|---|
| 44 | | -#define DUMP_BUF_PATH "/data/vop_buf" |
|---|
| 45 | 46 | |
|---|
| 46 | 47 | /*************************************************** |
|---|
| 47 | 48 | * Initialization, etc. |
|---|
| 48 | 49 | **************************************************/ |
|---|
| 50 | + |
|---|
| 51 | +static int drm_name_info(struct seq_file *m, void *data) |
|---|
| 52 | +{ |
|---|
| 53 | + struct drm_info_node *node = (struct drm_info_node *) m->private; |
|---|
| 54 | + struct drm_minor *minor = node->minor; |
|---|
| 55 | + struct drm_device *dev = minor->dev; |
|---|
| 56 | + struct drm_master *master; |
|---|
| 57 | + |
|---|
| 58 | + mutex_lock(&dev->master_mutex); |
|---|
| 59 | + master = dev->master; |
|---|
| 60 | + seq_printf(m, "%s", dev->driver->name); |
|---|
| 61 | + if (dev->dev) |
|---|
| 62 | + seq_printf(m, " dev=%s", dev_name(dev->dev)); |
|---|
| 63 | + if (master && master->unique) |
|---|
| 64 | + seq_printf(m, " master=%s", master->unique); |
|---|
| 65 | + if (dev->unique) |
|---|
| 66 | + seq_printf(m, " unique=%s", dev->unique); |
|---|
| 67 | + seq_printf(m, "\n"); |
|---|
| 68 | + mutex_unlock(&dev->master_mutex); |
|---|
| 69 | + |
|---|
| 70 | + return 0; |
|---|
| 71 | +} |
|---|
| 72 | + |
|---|
| 73 | +static int drm_clients_info(struct seq_file *m, void *data) |
|---|
| 74 | +{ |
|---|
| 75 | + struct drm_info_node *node = (struct drm_info_node *) m->private; |
|---|
| 76 | + struct drm_device *dev = node->minor->dev; |
|---|
| 77 | + struct drm_file *priv; |
|---|
| 78 | + kuid_t uid; |
|---|
| 79 | + |
|---|
| 80 | + seq_printf(m, |
|---|
| 81 | + "%20s %5s %3s master a %5s %10s\n", |
|---|
| 82 | + "command", |
|---|
| 83 | + "pid", |
|---|
| 84 | + "dev", |
|---|
| 85 | + "uid", |
|---|
| 86 | + "magic"); |
|---|
| 87 | + |
|---|
| 88 | + /* dev->filelist is sorted youngest first, but we want to present |
|---|
| 89 | + * oldest first (i.e. kernel, servers, clients), so walk backwardss. |
|---|
| 90 | + */ |
|---|
| 91 | + mutex_lock(&dev->filelist_mutex); |
|---|
| 92 | + list_for_each_entry_reverse(priv, &dev->filelist, lhead) { |
|---|
| 93 | + struct task_struct *task; |
|---|
| 94 | + bool is_current_master = drm_is_current_master(priv); |
|---|
| 95 | + |
|---|
| 96 | + rcu_read_lock(); /* locks pid_task()->comm */ |
|---|
| 97 | + task = pid_task(priv->pid, PIDTYPE_PID); |
|---|
| 98 | + uid = task ? __task_cred(task)->euid : GLOBAL_ROOT_UID; |
|---|
| 99 | + seq_printf(m, "%20s %5d %3d %c %c %5d %10u\n", |
|---|
| 100 | + task ? task->comm : "<unknown>", |
|---|
| 101 | + pid_vnr(priv->pid), |
|---|
| 102 | + priv->minor->index, |
|---|
| 103 | + is_current_master ? 'y' : 'n', |
|---|
| 104 | + priv->authenticated ? 'y' : 'n', |
|---|
| 105 | + from_kuid_munged(seq_user_ns(m), uid), |
|---|
| 106 | + priv->magic); |
|---|
| 107 | + rcu_read_unlock(); |
|---|
| 108 | + } |
|---|
| 109 | + mutex_unlock(&dev->filelist_mutex); |
|---|
| 110 | + return 0; |
|---|
| 111 | +} |
|---|
| 112 | + |
|---|
| 113 | +static int drm_gem_one_name_info(int id, void *ptr, void *data) |
|---|
| 114 | +{ |
|---|
| 115 | + struct drm_gem_object *obj = ptr; |
|---|
| 116 | + struct seq_file *m = data; |
|---|
| 117 | + |
|---|
| 118 | + seq_printf(m, "%6d %8zd %7d %8d\n", |
|---|
| 119 | + obj->name, obj->size, |
|---|
| 120 | + obj->handle_count, |
|---|
| 121 | + kref_read(&obj->refcount)); |
|---|
| 122 | + return 0; |
|---|
| 123 | +} |
|---|
| 124 | + |
|---|
| 125 | +static int drm_gem_name_info(struct seq_file *m, void *data) |
|---|
| 126 | +{ |
|---|
| 127 | + struct drm_info_node *node = (struct drm_info_node *) m->private; |
|---|
| 128 | + struct drm_device *dev = node->minor->dev; |
|---|
| 129 | + |
|---|
| 130 | + seq_printf(m, " name size handles refcount\n"); |
|---|
| 131 | + |
|---|
| 132 | + mutex_lock(&dev->object_name_lock); |
|---|
| 133 | + idr_for_each(&dev->object_name_idr, drm_gem_one_name_info, m); |
|---|
| 134 | + mutex_unlock(&dev->object_name_lock); |
|---|
| 135 | + |
|---|
| 136 | + return 0; |
|---|
| 137 | +} |
|---|
| 49 | 138 | |
|---|
| 50 | 139 | static const struct drm_info_list drm_debugfs_list[] = { |
|---|
| 51 | 140 | {"name", drm_name_info, 0}, |
|---|
| .. | .. |
|---|
| 71 | 160 | .release = single_release, |
|---|
| 72 | 161 | }; |
|---|
| 73 | 162 | |
|---|
| 74 | | -#if defined(CONFIG_ROCKCHIP_DRM_DEBUG) |
|---|
| 75 | | -static char *get_format_str(uint32_t format) |
|---|
| 76 | | -{ |
|---|
| 77 | | - switch (format) { |
|---|
| 78 | | - case DRM_FORMAT_XRGB8888: |
|---|
| 79 | | - case DRM_FORMAT_ARGB8888: |
|---|
| 80 | | - case DRM_FORMAT_XBGR8888: |
|---|
| 81 | | - case DRM_FORMAT_ABGR8888: |
|---|
| 82 | | - return "ARGB8888"; |
|---|
| 83 | | - case DRM_FORMAT_RGB888: |
|---|
| 84 | | - case DRM_FORMAT_BGR888: |
|---|
| 85 | | - return "BGR888"; |
|---|
| 86 | | - case DRM_FORMAT_RGB565: |
|---|
| 87 | | - case DRM_FORMAT_BGR565: |
|---|
| 88 | | - return "RGB565"; |
|---|
| 89 | | - case DRM_FORMAT_NV12: |
|---|
| 90 | | - case DRM_FORMAT_NV12_10: |
|---|
| 91 | | - return "YUV420NV12"; |
|---|
| 92 | | - case DRM_FORMAT_NV16: |
|---|
| 93 | | - case DRM_FORMAT_NV16_10: |
|---|
| 94 | | - return "YUV422NV16"; |
|---|
| 95 | | - case DRM_FORMAT_NV24: |
|---|
| 96 | | - case DRM_FORMAT_NV24_10: |
|---|
| 97 | | - return "YUV444NV24"; |
|---|
| 98 | | - case DRM_FORMAT_YUYV: |
|---|
| 99 | | - return "YUYV"; |
|---|
| 100 | | - default: |
|---|
| 101 | | - DRM_ERROR("unsupported format[%08x]\n", format); |
|---|
| 102 | | - return "UNF"; |
|---|
| 103 | | - } |
|---|
| 104 | | -} |
|---|
| 105 | | - |
|---|
| 106 | | -static int get_bpp(uint32_t format) |
|---|
| 107 | | -{ |
|---|
| 108 | | - uint32_t bpp; |
|---|
| 109 | | - |
|---|
| 110 | | - switch (format) { |
|---|
| 111 | | - case DRM_FORMAT_XRGB8888: |
|---|
| 112 | | - case DRM_FORMAT_ARGB8888: |
|---|
| 113 | | - case DRM_FORMAT_XBGR8888: |
|---|
| 114 | | - case DRM_FORMAT_ABGR8888: |
|---|
| 115 | | - bpp = 32; |
|---|
| 116 | | - break; |
|---|
| 117 | | - case DRM_FORMAT_RGB888: |
|---|
| 118 | | - case DRM_FORMAT_BGR888: |
|---|
| 119 | | - case DRM_FORMAT_NV24: |
|---|
| 120 | | - case DRM_FORMAT_NV24_10: |
|---|
| 121 | | - bpp = 24; |
|---|
| 122 | | - break; |
|---|
| 123 | | - case DRM_FORMAT_RGB565: |
|---|
| 124 | | - case DRM_FORMAT_BGR565: |
|---|
| 125 | | - case DRM_FORMAT_NV16: |
|---|
| 126 | | - case DRM_FORMAT_NV16_10: |
|---|
| 127 | | - bpp = 16; |
|---|
| 128 | | - break; |
|---|
| 129 | | - case DRM_FORMAT_NV12: |
|---|
| 130 | | - case DRM_FORMAT_NV12_10: |
|---|
| 131 | | - bpp = 12; |
|---|
| 132 | | - break; |
|---|
| 133 | | - case DRM_FORMAT_YUYV: |
|---|
| 134 | | - bpp = 16; |
|---|
| 135 | | - break; |
|---|
| 136 | | - default: |
|---|
| 137 | | - DRM_ERROR("unsupported format[%08x]\n", format); |
|---|
| 138 | | - bpp = 0; |
|---|
| 139 | | - } |
|---|
| 140 | | - |
|---|
| 141 | | - return bpp; |
|---|
| 142 | | -} |
|---|
| 143 | | - |
|---|
| 144 | | -#define AFBC_HEADER_SIZE 16 |
|---|
| 145 | | -#define AFBC_HDR_ALIGN 64 |
|---|
| 146 | | -#define AFBC_SUPERBLK_PIXELS 256 |
|---|
| 147 | | -#define AFBC_SUPERBLK_ALIGNMENT 128 |
|---|
| 148 | | - |
|---|
| 149 | | -static int get_afbc_size(uint32_t width, uint32_t height, uint32_t bpp) |
|---|
| 150 | | -{ |
|---|
| 151 | | - uint32_t h_alignment = 16; |
|---|
| 152 | | - uint32_t n_blocks; |
|---|
| 153 | | - uint32_t hdr_size; |
|---|
| 154 | | - uint32_t size; |
|---|
| 155 | | - |
|---|
| 156 | | - height = ALIGN(height, h_alignment); |
|---|
| 157 | | - n_blocks = width * height / AFBC_SUPERBLK_PIXELS; |
|---|
| 158 | | - hdr_size = ALIGN(n_blocks * AFBC_HEADER_SIZE, AFBC_HDR_ALIGN); |
|---|
| 159 | | - |
|---|
| 160 | | - size = hdr_size + n_blocks * ALIGN(bpp * AFBC_SUPERBLK_PIXELS / 8, AFBC_SUPERBLK_ALIGNMENT); |
|---|
| 161 | | - |
|---|
| 162 | | - return size; |
|---|
| 163 | | -} |
|---|
| 164 | | - |
|---|
| 165 | | -int vop_plane_dump(struct vop_dump_info *dump_info, int frame_count) |
|---|
| 166 | | -{ |
|---|
| 167 | | - int flags; |
|---|
| 168 | | - int bpp; |
|---|
| 169 | | - int fd; |
|---|
| 170 | | - const char *ptr; |
|---|
| 171 | | - char file_name[100]; |
|---|
| 172 | | - int width; |
|---|
| 173 | | - size_t size; |
|---|
| 174 | | - void *kvaddr; |
|---|
| 175 | | - mm_segment_t old_fs; |
|---|
| 176 | | - u32 format = dump_info->pixel_format; |
|---|
| 177 | | - |
|---|
| 178 | | - bpp = get_bpp(format); |
|---|
| 179 | | - |
|---|
| 180 | | - if (dump_info->yuv_format) { |
|---|
| 181 | | - width = dump_info->pitches; |
|---|
| 182 | | - flags = O_RDWR | O_CREAT | O_APPEND; |
|---|
| 183 | | - snprintf(file_name, 100, "%s/video%d_%d_%s.%s", DUMP_BUF_PATH, |
|---|
| 184 | | - width, dump_info->height, get_format_str(format), |
|---|
| 185 | | - "bin"); |
|---|
| 186 | | - } else { |
|---|
| 187 | | - width = dump_info->pitches * 8 / bpp; |
|---|
| 188 | | - flags = O_RDWR | O_CREAT; |
|---|
| 189 | | - snprintf(file_name, 100, "%s/win%d_area%d_%dx%d_%s%s%d.%s", |
|---|
| 190 | | - DUMP_BUF_PATH, dump_info->win_id, |
|---|
| 191 | | - dump_info->area_id, width, dump_info->height, |
|---|
| 192 | | - get_format_str(format), dump_info->AFBC_flag ? |
|---|
| 193 | | - "_AFBC_" : "_", frame_count, "bin"); |
|---|
| 194 | | - } |
|---|
| 195 | | - kvaddr = vmap(dump_info->pages, dump_info->num_pages, VM_MAP, |
|---|
| 196 | | - pgprot_writecombine(PAGE_KERNEL)); |
|---|
| 197 | | - if (!kvaddr) { |
|---|
| 198 | | - DRM_ERROR("failed to vmap() buffer for %s\n", file_name); |
|---|
| 199 | | - return -ENOMEM; |
|---|
| 200 | | - } |
|---|
| 201 | | - kvaddr += dump_info->offset; |
|---|
| 202 | | - old_fs = get_fs(); |
|---|
| 203 | | - set_fs(KERNEL_DS); |
|---|
| 204 | | - ksys_mkdir(DUMP_BUF_PATH, 0700); |
|---|
| 205 | | - ptr = file_name; |
|---|
| 206 | | - if (dump_info->AFBC_flag) |
|---|
| 207 | | - size = get_afbc_size(width, dump_info->height, bpp); |
|---|
| 208 | | - else |
|---|
| 209 | | - size = width * dump_info->height * bpp >> 3; |
|---|
| 210 | | - fd = ksys_open(ptr, flags, 0644); |
|---|
| 211 | | - if (fd >= 0) { |
|---|
| 212 | | - ksys_write(fd, kvaddr, size); |
|---|
| 213 | | - DRM_INFO("dump file name is:%s\n", file_name); |
|---|
| 214 | | - ksys_close(fd); |
|---|
| 215 | | - } else { |
|---|
| 216 | | - DRM_INFO("write %s failed errno: %d\n", ptr, fd); |
|---|
| 217 | | - } |
|---|
| 218 | | - set_fs(old_fs); |
|---|
| 219 | | - vunmap(kvaddr); |
|---|
| 220 | | - |
|---|
| 221 | | - return 0; |
|---|
| 222 | | -} |
|---|
| 223 | | - |
|---|
| 224 | | -static int vop_dump_show(struct seq_file *m, void *data) |
|---|
| 225 | | -{ |
|---|
| 226 | | - seq_puts(m, " echo dump > dump to dump one frame\n"); |
|---|
| 227 | | - seq_puts(m, " echo dumpon > dump to start vop keep dumping\n"); |
|---|
| 228 | | - seq_puts(m, " echo dumpoff > dump to stop keep dumping\n"); |
|---|
| 229 | | - seq_puts(m, " echo dumpn > dump n is the number of dump times\n"); |
|---|
| 230 | | - seq_puts(m, " dump path is /data/vop_buf\n"); |
|---|
| 231 | | - seq_puts(m, " if fd err = -3 try rm -r /data/vopbuf echo dump1 > dump can fix it\n"); |
|---|
| 232 | | - seq_puts(m, " if fd err = -28 save needed data try rm -r /data/vopbuf\n"); |
|---|
| 233 | | - |
|---|
| 234 | | - return 0; |
|---|
| 235 | | -} |
|---|
| 236 | | - |
|---|
| 237 | | -static int vop_dump_open(struct inode *inode, struct file *file) |
|---|
| 238 | | -{ |
|---|
| 239 | | - struct drm_crtc *crtc = inode->i_private; |
|---|
| 240 | | - |
|---|
| 241 | | - return single_open(file, vop_dump_show, crtc); |
|---|
| 242 | | -} |
|---|
| 243 | | - |
|---|
| 244 | | -static int temp_pow(int sum, int n) |
|---|
| 245 | | -{ |
|---|
| 246 | | - int i; |
|---|
| 247 | | - int temp = sum; |
|---|
| 248 | | - |
|---|
| 249 | | - if (n < 1) |
|---|
| 250 | | - return 1; |
|---|
| 251 | | - for (i = 1; i < n ; i++) |
|---|
| 252 | | - sum *= temp; |
|---|
| 253 | | - return sum; |
|---|
| 254 | | -} |
|---|
| 255 | | - |
|---|
| 256 | | -static ssize_t vop_dump_write(struct file *file, const char __user *ubuf, |
|---|
| 257 | | - size_t len, loff_t *offp) |
|---|
| 258 | | -{ |
|---|
| 259 | | - struct seq_file *m = file->private_data; |
|---|
| 260 | | - struct drm_crtc *crtc = m->private; |
|---|
| 261 | | - char buf[14] = {}; |
|---|
| 262 | | - int dump_times = 0; |
|---|
| 263 | | - struct vop_dump_list *pos, *n; |
|---|
| 264 | | - int i = 0; |
|---|
| 265 | | - |
|---|
| 266 | | - if (!crtc->vop_dump_list_init_flag) |
|---|
| 267 | | - return -EPERM; |
|---|
| 268 | | - if (len > sizeof(buf) - 1) |
|---|
| 269 | | - return -EINVAL; |
|---|
| 270 | | - if (copy_from_user(buf, ubuf, len)) |
|---|
| 271 | | - return -EFAULT; |
|---|
| 272 | | - buf[len - 1] = '\0'; |
|---|
| 273 | | - if (strncmp(buf, "dumpon", 6) == 0) { |
|---|
| 274 | | - crtc->vop_dump_status = DUMP_KEEP; |
|---|
| 275 | | - DRM_INFO("keep dumping\n"); |
|---|
| 276 | | - } else if (strncmp(buf, "dumpoff", 7) == 0) { |
|---|
| 277 | | - crtc->vop_dump_status = DUMP_DISABLE; |
|---|
| 278 | | - DRM_INFO("close keep dumping\n"); |
|---|
| 279 | | - } else if (strncmp(buf, "dump", 4) == 0) { |
|---|
| 280 | | - if (isdigit(buf[4])) { |
|---|
| 281 | | - for (i = 4; i < strlen(buf); i++) { |
|---|
| 282 | | - dump_times += temp_pow(10, (strlen(buf) |
|---|
| 283 | | - - i - 1)) |
|---|
| 284 | | - * (buf[i] - '0'); |
|---|
| 285 | | - } |
|---|
| 286 | | - crtc->vop_dump_times = dump_times; |
|---|
| 287 | | - } else { |
|---|
| 288 | | - list_for_each_entry_safe(pos, n, |
|---|
| 289 | | - &crtc->vop_dump_list_head, |
|---|
| 290 | | - entry) { |
|---|
| 291 | | - vop_plane_dump(&pos->dump_info, |
|---|
| 292 | | - crtc->frame_count); |
|---|
| 293 | | - } |
|---|
| 294 | | - crtc->frame_count++; |
|---|
| 295 | | - } |
|---|
| 296 | | - } else { |
|---|
| 297 | | - return -EINVAL; |
|---|
| 298 | | - } |
|---|
| 299 | | - |
|---|
| 300 | | - return len; |
|---|
| 301 | | -} |
|---|
| 302 | | - |
|---|
| 303 | | -static const struct file_operations drm_vop_dump_fops = { |
|---|
| 304 | | - .owner = THIS_MODULE, |
|---|
| 305 | | - .open = vop_dump_open, |
|---|
| 306 | | - .read = seq_read, |
|---|
| 307 | | - .llseek = seq_lseek, |
|---|
| 308 | | - .release = single_release, |
|---|
| 309 | | - .write = vop_dump_write, |
|---|
| 310 | | -}; |
|---|
| 311 | | - |
|---|
| 312 | | -int drm_debugfs_vop_add(struct drm_crtc *crtc, struct dentry *root) |
|---|
| 313 | | -{ |
|---|
| 314 | | - struct dentry *vop_dump_root; |
|---|
| 315 | | - struct dentry *ent; |
|---|
| 316 | | - |
|---|
| 317 | | - vop_dump_root = debugfs_create_dir("vop_dump", root); |
|---|
| 318 | | - crtc->vop_dump_status = DUMP_DISABLE; |
|---|
| 319 | | - crtc->vop_dump_list_init_flag = false; |
|---|
| 320 | | - crtc->vop_dump_times = 0; |
|---|
| 321 | | - crtc->frame_count = 0; |
|---|
| 322 | | - ent = debugfs_create_file("dump", 0644, vop_dump_root, |
|---|
| 323 | | - crtc, &drm_vop_dump_fops); |
|---|
| 324 | | - if (!ent) { |
|---|
| 325 | | - DRM_ERROR("create vop_plane_dump err\n"); |
|---|
| 326 | | - debugfs_remove_recursive(vop_dump_root); |
|---|
| 327 | | - } |
|---|
| 328 | | - |
|---|
| 329 | | - return 0; |
|---|
| 330 | | -} |
|---|
| 331 | | -#endif |
|---|
| 332 | 163 | |
|---|
| 333 | 164 | /** |
|---|
| 334 | 165 | * drm_debugfs_create_files - Initialize a given set of debugfs files for DRM |
|---|
| .. | .. |
|---|
| 342 | 173 | * &struct drm_info_list in the given root directory. These files will be removed |
|---|
| 343 | 174 | * automatically on drm_debugfs_cleanup(). |
|---|
| 344 | 175 | */ |
|---|
| 345 | | -int drm_debugfs_create_files(const struct drm_info_list *files, int count, |
|---|
| 346 | | - struct dentry *root, struct drm_minor *minor) |
|---|
| 176 | +void drm_debugfs_create_files(const struct drm_info_list *files, int count, |
|---|
| 177 | + struct dentry *root, struct drm_minor *minor) |
|---|
| 347 | 178 | { |
|---|
| 348 | 179 | struct drm_device *dev = minor->dev; |
|---|
| 349 | | - struct dentry *ent; |
|---|
| 350 | 180 | struct drm_info_node *tmp; |
|---|
| 351 | | - int i, ret; |
|---|
| 181 | + int i; |
|---|
| 352 | 182 | |
|---|
| 353 | 183 | for (i = 0; i < count; i++) { |
|---|
| 354 | 184 | u32 features = files[i].driver_features; |
|---|
| 355 | 185 | |
|---|
| 356 | | - if (features != 0 && |
|---|
| 357 | | - (dev->driver->driver_features & features) != features) |
|---|
| 186 | + if (features && !drm_core_check_all_features(dev, features)) |
|---|
| 358 | 187 | continue; |
|---|
| 359 | 188 | |
|---|
| 360 | 189 | tmp = kmalloc(sizeof(struct drm_info_node), GFP_KERNEL); |
|---|
| 361 | | - if (tmp == NULL) { |
|---|
| 362 | | - ret = -1; |
|---|
| 363 | | - goto fail; |
|---|
| 364 | | - } |
|---|
| 365 | | - ent = debugfs_create_file(files[i].name, S_IFREG | S_IRUGO, |
|---|
| 366 | | - root, tmp, &drm_debugfs_fops); |
|---|
| 367 | | - if (!ent) { |
|---|
| 368 | | - DRM_ERROR("Cannot create /sys/kernel/debug/dri/%pd/%s\n", |
|---|
| 369 | | - root, files[i].name); |
|---|
| 370 | | - kfree(tmp); |
|---|
| 371 | | - ret = -1; |
|---|
| 372 | | - goto fail; |
|---|
| 373 | | - } |
|---|
| 190 | + if (tmp == NULL) |
|---|
| 191 | + continue; |
|---|
| 374 | 192 | |
|---|
| 375 | 193 | tmp->minor = minor; |
|---|
| 376 | | - tmp->dent = ent; |
|---|
| 194 | + tmp->dent = debugfs_create_file(files[i].name, |
|---|
| 195 | + S_IFREG | S_IRUGO, root, tmp, |
|---|
| 196 | + &drm_debugfs_fops); |
|---|
| 377 | 197 | tmp->info_ent = &files[i]; |
|---|
| 378 | 198 | |
|---|
| 379 | 199 | mutex_lock(&minor->debugfs_lock); |
|---|
| 380 | 200 | list_add(&tmp->list, &minor->debugfs_list); |
|---|
| 381 | 201 | mutex_unlock(&minor->debugfs_lock); |
|---|
| 382 | 202 | } |
|---|
| 383 | | - return 0; |
|---|
| 384 | | - |
|---|
| 385 | | -fail: |
|---|
| 386 | | - drm_debugfs_remove_files(files, count, minor); |
|---|
| 387 | | - return ret; |
|---|
| 388 | 203 | } |
|---|
| 389 | 204 | EXPORT_SYMBOL(drm_debugfs_create_files); |
|---|
| 390 | 205 | |
|---|
| .. | .. |
|---|
| 393 | 208 | { |
|---|
| 394 | 209 | struct drm_device *dev = minor->dev; |
|---|
| 395 | 210 | char name[64]; |
|---|
| 396 | | - int ret; |
|---|
| 397 | 211 | |
|---|
| 398 | 212 | INIT_LIST_HEAD(&minor->debugfs_list); |
|---|
| 399 | 213 | mutex_init(&minor->debugfs_lock); |
|---|
| 400 | 214 | sprintf(name, "%d", minor_id); |
|---|
| 401 | 215 | minor->debugfs_root = debugfs_create_dir(name, root); |
|---|
| 402 | | - if (!minor->debugfs_root) { |
|---|
| 403 | | - DRM_ERROR("Cannot create /sys/kernel/debug/dri/%s\n", name); |
|---|
| 404 | | - return -1; |
|---|
| 405 | | - } |
|---|
| 406 | 216 | |
|---|
| 407 | | - ret = drm_debugfs_create_files(drm_debugfs_list, DRM_DEBUGFS_ENTRIES, |
|---|
| 408 | | - minor->debugfs_root, minor); |
|---|
| 409 | | - if (ret) { |
|---|
| 410 | | - debugfs_remove(minor->debugfs_root); |
|---|
| 411 | | - minor->debugfs_root = NULL; |
|---|
| 412 | | - DRM_ERROR("Failed to create core drm debugfs files\n"); |
|---|
| 413 | | - return ret; |
|---|
| 414 | | - } |
|---|
| 217 | + drm_debugfs_create_files(drm_debugfs_list, DRM_DEBUGFS_ENTRIES, |
|---|
| 218 | + minor->debugfs_root, minor); |
|---|
| 415 | 219 | |
|---|
| 416 | 220 | if (drm_drv_uses_atomic_modeset(dev)) { |
|---|
| 417 | | - ret = drm_atomic_debugfs_init(minor); |
|---|
| 418 | | - if (ret) { |
|---|
| 419 | | - DRM_ERROR("Failed to create atomic debugfs files\n"); |
|---|
| 420 | | - return ret; |
|---|
| 421 | | - } |
|---|
| 221 | + drm_atomic_debugfs_init(minor); |
|---|
| 422 | 222 | } |
|---|
| 423 | 223 | |
|---|
| 424 | 224 | if (drm_core_check_feature(dev, DRIVER_MODESET)) { |
|---|
| 425 | | - ret = drm_framebuffer_debugfs_init(minor); |
|---|
| 426 | | - if (ret) { |
|---|
| 427 | | - DRM_ERROR("Failed to create framebuffer debugfs file\n"); |
|---|
| 428 | | - return ret; |
|---|
| 429 | | - } |
|---|
| 225 | + drm_framebuffer_debugfs_init(minor); |
|---|
| 430 | 226 | |
|---|
| 431 | | - ret = drm_client_debugfs_init(minor); |
|---|
| 432 | | - if (ret) { |
|---|
| 433 | | - DRM_ERROR("Failed to create client debugfs file\n"); |
|---|
| 434 | | - return ret; |
|---|
| 435 | | - } |
|---|
| 227 | + drm_client_debugfs_init(minor); |
|---|
| 436 | 228 | } |
|---|
| 437 | 229 | |
|---|
| 438 | | - if (dev->driver->debugfs_init) { |
|---|
| 439 | | - ret = dev->driver->debugfs_init(minor); |
|---|
| 440 | | - if (ret) { |
|---|
| 441 | | - DRM_ERROR("DRM: Driver failed to initialize " |
|---|
| 442 | | - "/sys/kernel/debug/dri.\n"); |
|---|
| 443 | | - return ret; |
|---|
| 444 | | - } |
|---|
| 445 | | - } |
|---|
| 230 | + if (dev->driver->debugfs_init) |
|---|
| 231 | + dev->driver->debugfs_init(minor); |
|---|
| 232 | + |
|---|
| 446 | 233 | return 0; |
|---|
| 447 | 234 | } |
|---|
| 448 | 235 | |
|---|
| .. | .. |
|---|
| 483 | 270 | mutex_unlock(&minor->debugfs_lock); |
|---|
| 484 | 271 | } |
|---|
| 485 | 272 | |
|---|
| 486 | | -int drm_debugfs_cleanup(struct drm_minor *minor) |
|---|
| 273 | +void drm_debugfs_cleanup(struct drm_minor *minor) |
|---|
| 487 | 274 | { |
|---|
| 488 | 275 | if (!minor->debugfs_root) |
|---|
| 489 | | - return 0; |
|---|
| 276 | + return; |
|---|
| 490 | 277 | |
|---|
| 491 | 278 | drm_debugfs_remove_all_files(minor); |
|---|
| 492 | 279 | |
|---|
| 493 | 280 | debugfs_remove_recursive(minor->debugfs_root); |
|---|
| 494 | 281 | minor->debugfs_root = NULL; |
|---|
| 495 | | - |
|---|
| 496 | | - return 0; |
|---|
| 497 | 282 | } |
|---|
| 498 | 283 | |
|---|
| 499 | 284 | static int connector_show(struct seq_file *m, void *data) |
|---|
| .. | .. |
|---|
| 592 | 377 | return (ret) ? ret : len; |
|---|
| 593 | 378 | } |
|---|
| 594 | 379 | |
|---|
| 380 | +/* |
|---|
| 381 | + * Returns the min and max vrr vfreq through the connector's debugfs file. |
|---|
| 382 | + * Example usage: cat /sys/kernel/debug/dri/0/DP-1/vrr_range |
|---|
| 383 | + */ |
|---|
| 384 | +static int vrr_range_show(struct seq_file *m, void *data) |
|---|
| 385 | +{ |
|---|
| 386 | + struct drm_connector *connector = m->private; |
|---|
| 387 | + |
|---|
| 388 | + if (connector->status != connector_status_connected) |
|---|
| 389 | + return -ENODEV; |
|---|
| 390 | + |
|---|
| 391 | + seq_printf(m, "Min: %u\n", (u8)connector->display_info.monitor_range.min_vfreq); |
|---|
| 392 | + seq_printf(m, "Max: %u\n", (u8)connector->display_info.monitor_range.max_vfreq); |
|---|
| 393 | + |
|---|
| 394 | + return 0; |
|---|
| 395 | +} |
|---|
| 396 | +DEFINE_SHOW_ATTRIBUTE(vrr_range); |
|---|
| 397 | + |
|---|
| 595 | 398 | static const struct file_operations drm_edid_fops = { |
|---|
| 596 | 399 | .owner = THIS_MODULE, |
|---|
| 597 | 400 | .open = edid_open, |
|---|
| .. | .. |
|---|
| 611 | 414 | .write = connector_write |
|---|
| 612 | 415 | }; |
|---|
| 613 | 416 | |
|---|
| 614 | | -int drm_debugfs_connector_add(struct drm_connector *connector) |
|---|
| 417 | +void drm_debugfs_connector_add(struct drm_connector *connector) |
|---|
| 615 | 418 | { |
|---|
| 616 | 419 | struct drm_minor *minor = connector->dev->primary; |
|---|
| 617 | | - struct dentry *root, *ent; |
|---|
| 420 | + struct dentry *root; |
|---|
| 618 | 421 | |
|---|
| 619 | 422 | if (!minor->debugfs_root) |
|---|
| 620 | | - return -1; |
|---|
| 423 | + return; |
|---|
| 621 | 424 | |
|---|
| 622 | 425 | root = debugfs_create_dir(connector->name, minor->debugfs_root); |
|---|
| 623 | | - if (!root) |
|---|
| 624 | | - return -ENOMEM; |
|---|
| 625 | | - |
|---|
| 626 | 426 | connector->debugfs_entry = root; |
|---|
| 627 | 427 | |
|---|
| 628 | 428 | /* force */ |
|---|
| 629 | | - ent = debugfs_create_file("force", S_IRUGO | S_IWUSR, root, connector, |
|---|
| 630 | | - &drm_connector_fops); |
|---|
| 631 | | - if (!ent) |
|---|
| 632 | | - goto error; |
|---|
| 429 | + debugfs_create_file("force", S_IRUGO | S_IWUSR, root, connector, |
|---|
| 430 | + &drm_connector_fops); |
|---|
| 633 | 431 | |
|---|
| 634 | 432 | /* edid */ |
|---|
| 635 | | - ent = debugfs_create_file("edid_override", S_IRUGO | S_IWUSR, root, |
|---|
| 636 | | - connector, &drm_edid_fops); |
|---|
| 637 | | - if (!ent) |
|---|
| 638 | | - goto error; |
|---|
| 433 | + debugfs_create_file("edid_override", S_IRUGO | S_IWUSR, root, connector, |
|---|
| 434 | + &drm_edid_fops); |
|---|
| 639 | 435 | |
|---|
| 640 | | - return 0; |
|---|
| 641 | | - |
|---|
| 642 | | -error: |
|---|
| 643 | | - debugfs_remove_recursive(connector->debugfs_entry); |
|---|
| 644 | | - connector->debugfs_entry = NULL; |
|---|
| 645 | | - return -ENOMEM; |
|---|
| 436 | + /* vrr range */ |
|---|
| 437 | + debugfs_create_file("vrr_range", S_IRUGO, root, connector, |
|---|
| 438 | + &vrr_range_fops); |
|---|
| 646 | 439 | } |
|---|
| 647 | 440 | |
|---|
| 648 | 441 | void drm_debugfs_connector_remove(struct drm_connector *connector) |
|---|
| .. | .. |
|---|
| 655 | 448 | connector->debugfs_entry = NULL; |
|---|
| 656 | 449 | } |
|---|
| 657 | 450 | |
|---|
| 658 | | -int drm_debugfs_crtc_add(struct drm_crtc *crtc) |
|---|
| 451 | +void drm_debugfs_crtc_add(struct drm_crtc *crtc) |
|---|
| 659 | 452 | { |
|---|
| 660 | 453 | struct drm_minor *minor = crtc->dev->primary; |
|---|
| 661 | 454 | struct dentry *root; |
|---|
| .. | .. |
|---|
| 663 | 456 | |
|---|
| 664 | 457 | name = kasprintf(GFP_KERNEL, "crtc-%d", crtc->index); |
|---|
| 665 | 458 | if (!name) |
|---|
| 666 | | - return -ENOMEM; |
|---|
| 459 | + return; |
|---|
| 667 | 460 | |
|---|
| 668 | 461 | root = debugfs_create_dir(name, minor->debugfs_root); |
|---|
| 669 | 462 | kfree(name); |
|---|
| 670 | | - if (!root) |
|---|
| 671 | | - return -ENOMEM; |
|---|
| 672 | 463 | |
|---|
| 673 | 464 | crtc->debugfs_entry = root; |
|---|
| 674 | 465 | |
|---|
| 675 | | - if (drm_debugfs_crtc_crc_add(crtc)) |
|---|
| 676 | | - goto error; |
|---|
| 677 | | - |
|---|
| 678 | | - return 0; |
|---|
| 679 | | - |
|---|
| 680 | | -error: |
|---|
| 681 | | - drm_debugfs_crtc_remove(crtc); |
|---|
| 682 | | - return -ENOMEM; |
|---|
| 466 | + drm_debugfs_crtc_crc_add(crtc); |
|---|
| 683 | 467 | } |
|---|
| 684 | 468 | |
|---|
| 685 | 469 | void drm_debugfs_crtc_remove(struct drm_crtc *crtc) |
|---|