1 // SPDX-License-Identifier: GPL-2.0-only
2 /* Copyright(c) 2023 Intel Corporation */
3 
4 #include <linux/debugfs.h>
5 #include "adf_accel_devices.h"
6 #include "adf_cfg.h"
7 #include "adf_common_drv.h"
8 #include "adf_dbgfs.h"
9 
10 /**
11  * adf_dbgfs_init() - add persistent debugfs entries
12  * @accel_dev:  Pointer to acceleration device.
13  *
14  * This function creates debugfs entries that are persistent through a device
15  * state change (from up to down or vice versa).
16  */
17 void adf_dbgfs_init(struct adf_accel_dev *accel_dev)
18 {
19 	char name[ADF_DEVICE_NAME_LENGTH];
20 	void *ret;
21 
22 	/* Create dev top level debugfs entry */
23 	snprintf(name, sizeof(name), "%s%s_%s", ADF_DEVICE_NAME_PREFIX,
24 		 accel_dev->hw_device->dev_class->name,
25 		 pci_name(accel_dev->accel_pci_dev.pci_dev));
26 
27 	ret = debugfs_create_dir(name, NULL);
28 	if (IS_ERR_OR_NULL(ret))
29 		return;
30 
31 	accel_dev->debugfs_dir = ret;
32 
33 	adf_cfg_dev_dbgfs_add(accel_dev);
34 }
35 EXPORT_SYMBOL_GPL(adf_dbgfs_init);
36 
37 /**
38  * adf_dbgfs_exit() - remove persistent debugfs entries
39  * @accel_dev:  Pointer to acceleration device.
40  */
41 void adf_dbgfs_exit(struct adf_accel_dev *accel_dev)
42 {
43 	adf_cfg_dev_dbgfs_rm(accel_dev);
44 	debugfs_remove(accel_dev->debugfs_dir);
45 }
46 EXPORT_SYMBOL_GPL(adf_dbgfs_exit);
47 
48 /**
49  * adf_dbgfs_add() - add non-persistent debugfs entries
50  * @accel_dev:  Pointer to acceleration device.
51  *
52  * This function creates debugfs entries that are not persistent through
53  * a device state change (from up to down or vice versa).
54  */
55 void adf_dbgfs_add(struct adf_accel_dev *accel_dev)
56 {
57 	if (!accel_dev->debugfs_dir)
58 		return;
59 }
60 
61 /**
62  * adf_dbgfs_rm() - remove non-persistent debugfs entries
63  * @accel_dev:  Pointer to acceleration device.
64  */
65 void adf_dbgfs_rm(struct adf_accel_dev *accel_dev)
66 {
67 	if (!accel_dev->debugfs_dir)
68 		return;
69 }
70