treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / misc / mic / cosm / cosm_debugfs.c
blob68a731fd86deea4993c988a0caf18c0af4aa6341
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Intel MIC Platform Software Stack (MPSS)
5 * Copyright(c) 2015 Intel Corporation.
7 * Intel MIC Coprocessor State Management (COSM) Driver
8 */
10 #include <linux/debugfs.h>
11 #include <linux/slab.h>
12 #include <linux/io.h>
13 #include "cosm_main.h"
15 /* Debugfs parent dir */
16 static struct dentry *cosm_dbg;
18 /**
19 * log_buf_show - Display MIC kernel log buffer
21 * log_buf addr/len is read from System.map by user space
22 * and populated in sysfs entries.
24 static int log_buf_show(struct seq_file *s, void *unused)
26 void __iomem *log_buf_va;
27 int __iomem *log_buf_len_va;
28 struct cosm_device *cdev = s->private;
29 void *kva;
30 int size;
31 u64 aper_offset;
33 if (!cdev || !cdev->log_buf_addr || !cdev->log_buf_len)
34 goto done;
36 mutex_lock(&cdev->cosm_mutex);
37 switch (cdev->state) {
38 case MIC_BOOTING:
39 case MIC_ONLINE:
40 case MIC_SHUTTING_DOWN:
41 break;
42 default:
43 goto unlock;
47 * Card kernel will never be relocated and any kernel text/data mapping
48 * can be translated to phys address by subtracting __START_KERNEL_map.
50 aper_offset = (u64)cdev->log_buf_len - __START_KERNEL_map;
51 log_buf_len_va = cdev->hw_ops->aper(cdev)->va + aper_offset;
52 aper_offset = (u64)cdev->log_buf_addr - __START_KERNEL_map;
53 log_buf_va = cdev->hw_ops->aper(cdev)->va + aper_offset;
55 size = ioread32(log_buf_len_va);
56 kva = kmalloc(size, GFP_KERNEL);
57 if (!kva)
58 goto unlock;
60 memcpy_fromio(kva, log_buf_va, size);
61 seq_write(s, kva, size);
62 kfree(kva);
63 unlock:
64 mutex_unlock(&cdev->cosm_mutex);
65 done:
66 return 0;
69 DEFINE_SHOW_ATTRIBUTE(log_buf);
71 /**
72 * force_reset_show - Force MIC reset
74 * Invokes the force_reset COSM bus op instead of the standard reset
75 * op in case a force reset of the MIC device is required
77 static int force_reset_show(struct seq_file *s, void *pos)
79 struct cosm_device *cdev = s->private;
81 cosm_stop(cdev, true);
82 return 0;
85 DEFINE_SHOW_ATTRIBUTE(force_reset);
87 void cosm_create_debug_dir(struct cosm_device *cdev)
89 char name[16];
91 if (!cosm_dbg)
92 return;
94 scnprintf(name, sizeof(name), "mic%d", cdev->index);
95 cdev->dbg_dir = debugfs_create_dir(name, cosm_dbg);
97 debugfs_create_file("log_buf", 0444, cdev->dbg_dir, cdev,
98 &log_buf_fops);
99 debugfs_create_file("force_reset", 0444, cdev->dbg_dir, cdev,
100 &force_reset_fops);
103 void cosm_delete_debug_dir(struct cosm_device *cdev)
105 debugfs_remove_recursive(cdev->dbg_dir);
108 void cosm_init_debugfs(void)
110 cosm_dbg = debugfs_create_dir(KBUILD_MODNAME, NULL);
113 void cosm_exit_debugfs(void)
115 debugfs_remove(cosm_dbg);