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>
25 #include "cosm_main.h"
27 /* Debugfs parent dir */
28 static struct dentry *cosm_dbg;
31 * cosm_log_buf_show - Display MIC kernel log buffer
33 * log_buf addr/len is read from System.map by user space
34 * and populated in sysfs entries.
36 static int cosm_log_buf_show(struct seq_file *s, void *unused)
38 void __iomem *log_buf_va;
39 int __iomem *log_buf_len_va;
40 struct cosm_device *cdev = s->private;
45 if (!cdev || !cdev->log_buf_addr || !cdev->log_buf_len)
48 mutex_lock(&cdev->cosm_mutex);
49 switch (cdev->state) {
52 case MIC_SHUTTING_DOWN:
59 * Card kernel will never be relocated and any kernel text/data mapping
60 * can be translated to phys address by subtracting __START_KERNEL_map.
62 aper_offset = (u64)cdev->log_buf_len - __START_KERNEL_map;
63 log_buf_len_va = cdev->hw_ops->aper(cdev)->va + aper_offset;
64 aper_offset = (u64)cdev->log_buf_addr - __START_KERNEL_map;
65 log_buf_va = cdev->hw_ops->aper(cdev)->va + aper_offset;
67 size = ioread32(log_buf_len_va);
68 kva = kmalloc(size, GFP_KERNEL);
72 memcpy_fromio(kva, log_buf_va, size);
73 seq_write(s, kva, size);
76 mutex_unlock(&cdev->cosm_mutex);
81 static int cosm_log_buf_open(struct inode *inode, struct file *file)
83 return single_open(file, cosm_log_buf_show, inode->i_private);
86 static const struct file_operations log_buf_ops = {
88 .open = cosm_log_buf_open,
91 .release = single_release
95 * cosm_force_reset_show - Force MIC reset
97 * Invokes the force_reset COSM bus op instead of the standard reset
98 * op in case a force reset of the MIC device is required
100 static int cosm_force_reset_show(struct seq_file *s, void *pos)
102 struct cosm_device *cdev = s->private;
104 cosm_stop(cdev, true);
108 static int cosm_force_reset_debug_open(struct inode *inode, struct file *file)
110 return single_open(file, cosm_force_reset_show, inode->i_private);
113 static const struct file_operations force_reset_ops = {
114 .owner = THIS_MODULE,
115 .open = cosm_force_reset_debug_open,
118 .release = single_release
121 void cosm_create_debug_dir(struct cosm_device *cdev)
128 scnprintf(name, sizeof(name), "mic%d", cdev->index);
129 cdev->dbg_dir = debugfs_create_dir(name, cosm_dbg);
133 debugfs_create_file("log_buf", 0444, cdev->dbg_dir, cdev, &log_buf_ops);
134 debugfs_create_file("force_reset", 0444, cdev->dbg_dir, cdev,
138 void cosm_delete_debug_dir(struct cosm_device *cdev)
143 debugfs_remove_recursive(cdev->dbg_dir);
146 void cosm_init_debugfs(void)
148 cosm_dbg = debugfs_create_dir(KBUILD_MODNAME, NULL);
150 pr_err("can't create debugfs dir\n");
153 void cosm_exit_debugfs(void)
155 debugfs_remove(cosm_dbg);