2 * Intel MIC Platform Software Stack (MPSS)
4 * Copyright(c) 2015 Intel Corporation.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License, version 2, as
8 * published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * The full GNU General Public License is included in this distribution in
16 * the file called "COPYING".
18 * Intel MIC Coprocessor State Management (COSM) Driver
22 #include <linux/debugfs.h>
23 #include <linux/slab.h>
24 #include "cosm_main.h"
26 /* Debugfs parent dir */
27 static struct dentry *cosm_dbg;
30 * cosm_log_buf_show - Display MIC kernel log buffer
32 * log_buf addr/len is read from System.map by user space
33 * and populated in sysfs entries.
35 static int cosm_log_buf_show(struct seq_file *s, void *unused)
37 void __iomem *log_buf_va;
38 int __iomem *log_buf_len_va;
39 struct cosm_device *cdev = s->private;
44 if (!cdev || !cdev->log_buf_addr || !cdev->log_buf_len)
47 mutex_lock(&cdev->cosm_mutex);
48 switch (cdev->state) {
51 case MIC_SHUTTING_DOWN:
58 * Card kernel will never be relocated and any kernel text/data mapping
59 * can be translated to phys address by subtracting __START_KERNEL_map.
61 aper_offset = (u64)cdev->log_buf_len - __START_KERNEL_map;
62 log_buf_len_va = cdev->hw_ops->aper(cdev)->va + aper_offset;
63 aper_offset = (u64)cdev->log_buf_addr - __START_KERNEL_map;
64 log_buf_va = cdev->hw_ops->aper(cdev)->va + aper_offset;
66 size = ioread32(log_buf_len_va);
67 kva = kmalloc(size, GFP_KERNEL);
71 memcpy_fromio(kva, log_buf_va, size);
72 seq_write(s, kva, size);
75 mutex_unlock(&cdev->cosm_mutex);
80 static int cosm_log_buf_open(struct inode *inode, struct file *file)
82 return single_open(file, cosm_log_buf_show, inode->i_private);
85 static const struct file_operations log_buf_ops = {
87 .open = cosm_log_buf_open,
90 .release = single_release
94 * cosm_force_reset_show - Force MIC reset
96 * Invokes the force_reset COSM bus op instead of the standard reset
97 * op in case a force reset of the MIC device is required
99 static int cosm_force_reset_show(struct seq_file *s, void *pos)
101 struct cosm_device *cdev = s->private;
103 cosm_stop(cdev, true);
107 static int cosm_force_reset_debug_open(struct inode *inode, struct file *file)
109 return single_open(file, cosm_force_reset_show, inode->i_private);
112 static const struct file_operations force_reset_ops = {
113 .owner = THIS_MODULE,
114 .open = cosm_force_reset_debug_open,
117 .release = single_release
120 void cosm_create_debug_dir(struct cosm_device *cdev)
127 scnprintf(name, sizeof(name), "mic%d", cdev->index);
128 cdev->dbg_dir = debugfs_create_dir(name, cosm_dbg);
132 debugfs_create_file("log_buf", 0444, cdev->dbg_dir, cdev, &log_buf_ops);
133 debugfs_create_file("force_reset", 0444, cdev->dbg_dir, cdev,
137 void cosm_delete_debug_dir(struct cosm_device *cdev)
142 debugfs_remove_recursive(cdev->dbg_dir);
145 void cosm_init_debugfs(void)
147 cosm_dbg = debugfs_create_dir(KBUILD_MODNAME, NULL);
149 pr_err("can't create debugfs dir\n");
152 void cosm_exit_debugfs(void)
154 debugfs_remove(cosm_dbg);