Path: blob/master/drivers/gpu/drm/armada/armada_debugfs.c
26481 views
// SPDX-License-Identifier: GPL-2.0-only1/*2* Copyright (C) 2012 Russell King3* Rewritten from the dovefb driver, and Armada510 manuals.4*/56#include <linux/ctype.h>7#include <linux/debugfs.h>8#include <linux/module.h>9#include <linux/seq_file.h>10#include <linux/uaccess.h>1112#include <drm/drm_debugfs.h>13#include <drm/drm_file.h>1415#include "armada_crtc.h"16#include "armada_drm.h"1718static int armada_debugfs_gem_linear_show(struct seq_file *m, void *data)19{20struct drm_info_node *node = m->private;21struct drm_device *dev = node->minor->dev;22struct armada_private *priv = drm_to_armada_dev(dev);23struct drm_printer p = drm_seq_file_printer(m);2425mutex_lock(&priv->linear_lock);26drm_mm_print(&priv->linear, &p);27mutex_unlock(&priv->linear_lock);2829return 0;30}3132static int armada_debugfs_crtc_reg_show(struct seq_file *m, void *data)33{34struct armada_crtc *dcrtc = m->private;35int i;3637for (i = 0x84; i <= 0x1c4; i += 4) {38u32 v = readl_relaxed(dcrtc->base + i);39seq_printf(m, "0x%04x: 0x%08x\n", i, v);40}4142return 0;43}4445static int armada_debugfs_crtc_reg_open(struct inode *inode, struct file *file)46{47return single_open(file, armada_debugfs_crtc_reg_show,48inode->i_private);49}5051static int armada_debugfs_crtc_reg_write(struct file *file,52const char __user *ptr, size_t len, loff_t *off)53{54struct armada_crtc *dcrtc;55unsigned long reg, mask, val;56char buf[32];57int ret;58u32 v;5960if (*off != 0)61return 0;6263if (len > sizeof(buf) - 1)64len = sizeof(buf) - 1;6566ret = strncpy_from_user(buf, ptr, len);67if (ret < 0)68return ret;69buf[len] = '\0';7071if (sscanf(buf, "%lx %lx %lx", ®, &mask, &val) != 3)72return -EINVAL;73if (reg < 0x84 || reg > 0x1c4 || reg & 3)74return -ERANGE;7576dcrtc = ((struct seq_file *)file->private_data)->private;77v = readl(dcrtc->base + reg);78v &= ~mask;79v |= val & mask;80writel(v, dcrtc->base + reg);8182return len;83}8485static const struct file_operations armada_debugfs_crtc_reg_fops = {86.owner = THIS_MODULE,87.open = armada_debugfs_crtc_reg_open,88.read = seq_read,89.write = armada_debugfs_crtc_reg_write,90.llseek = seq_lseek,91.release = single_release,92};9394void armada_drm_crtc_debugfs_init(struct armada_crtc *dcrtc)95{96debugfs_create_file("armada-regs", 0600, dcrtc->crtc.debugfs_entry,97dcrtc, &armada_debugfs_crtc_reg_fops);98}99100static struct drm_info_list armada_debugfs_list[] = {101{ "gem_linear", armada_debugfs_gem_linear_show, 0 },102};103#define ARMADA_DEBUGFS_ENTRIES ARRAY_SIZE(armada_debugfs_list)104105int armada_drm_debugfs_init(struct drm_minor *minor)106{107drm_debugfs_create_files(armada_debugfs_list, ARMADA_DEBUGFS_ENTRIES,108minor->debugfs_root, minor);109110return 0;111}112113114