1 // SPDX-License-Identifier: GPL-2.0-only
3 * Intel MIC Platform Software Stack (MPSS)
5 * Copyright(c) 2015 Intel Corporation.
7 * Intel MIC Coprocessor State Management (COSM) Driver
10 #include <linux/debugfs.h>
11 #include <linux/slab.h>
13 #include "cosm_main.h"
15 /* Debugfs parent dir */
16 static struct dentry
*cosm_dbg
;
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;
33 if (!cdev
|| !cdev
->log_buf_addr
|| !cdev
->log_buf_len
)
36 mutex_lock(&cdev
->cosm_mutex
);
37 switch (cdev
->state
) {
40 case MIC_SHUTTING_DOWN
:
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
);
60 memcpy_fromio(kva
, log_buf_va
, size
);
61 seq_write(s
, kva
, size
);
64 mutex_unlock(&cdev
->cosm_mutex
);
69 DEFINE_SHOW_ATTRIBUTE(log_buf
);
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);
85 DEFINE_SHOW_ATTRIBUTE(force_reset
);
87 void cosm_create_debug_dir(struct cosm_device
*cdev
)
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
,
99 debugfs_create_file("force_reset", 0444, cdev
->dbg_dir
, cdev
,
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
);