xref: /freebsd/sys/compat/linuxkpi/common/include/linux/debugfs.h (revision 4d846d260e2b9a3d4d0a701462568268cbfe7a5b)
13f6cab07SMatt Macy /*-
2*4d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
33f6cab07SMatt Macy  *
43f6cab07SMatt Macy  * Copyright (c) 2016-2018, Matthew Macy <mmacy@freebsd.org>
53f6cab07SMatt Macy  *
63f6cab07SMatt Macy  * Redistribution and use in source and binary forms, with or without
73f6cab07SMatt Macy  * modification, are permitted provided that the following conditions
83f6cab07SMatt Macy  * are met:
93f6cab07SMatt Macy  * 1. Redistributions of source code must retain the above copyright
103f6cab07SMatt Macy  *    notice, this list of conditions and the following disclaimer.
113f6cab07SMatt Macy  * 2. Redistributions in binary form must reproduce the above copyright
123f6cab07SMatt Macy  *    notice, this list of conditions and the following disclaimer in the
133f6cab07SMatt Macy  *    documentation and/or other materials provided with the distribution.
143f6cab07SMatt Macy  *
153f6cab07SMatt Macy  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
163f6cab07SMatt Macy  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
173f6cab07SMatt Macy  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
183f6cab07SMatt Macy  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
193f6cab07SMatt Macy  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
203f6cab07SMatt Macy  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
213f6cab07SMatt Macy  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
223f6cab07SMatt Macy  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
233f6cab07SMatt Macy  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
243f6cab07SMatt Macy  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
253f6cab07SMatt Macy  * SUCH DAMAGE.
263f6cab07SMatt Macy  *
273f6cab07SMatt Macy  * $FreeBSD$
283f6cab07SMatt Macy  */
293f6cab07SMatt Macy 
30307f78f3SVladimir Kondratyev #ifndef _LINUXKPI_LINUX_DEBUGFS_H_
31307f78f3SVladimir Kondratyev #define _LINUXKPI_LINUX_DEBUGFS_H_
323f6cab07SMatt Macy 
333f6cab07SMatt Macy #include <linux/fs.h>
34f697b943SJake Freeland #include <linux/module.h>
353f6cab07SMatt Macy #include <linux/seq_file.h>
363f6cab07SMatt Macy #include <linux/types.h>
373f6cab07SMatt Macy 
38f697b943SJake Freeland MALLOC_DECLARE(M_DFSINT);
39f697b943SJake Freeland 
40f697b943SJake Freeland struct debugfs_reg32 {
41f697b943SJake Freeland 	char *name;
42f697b943SJake Freeland 	unsigned long offset;
43f697b943SJake Freeland };
44f697b943SJake Freeland 
45f697b943SJake Freeland struct debugfs_regset32 {
46f697b943SJake Freeland 	const struct debugfs_reg32 *regs;
47f697b943SJake Freeland 	int nregs;
48f697b943SJake Freeland };
493f6cab07SMatt Macy 
500fce2dc1SBjoern A. Zeeb struct debugfs_blob_wrapper {
510fce2dc1SBjoern A. Zeeb 	void			*data;
520fce2dc1SBjoern A. Zeeb 	size_t			size;
530fce2dc1SBjoern A. Zeeb };
540fce2dc1SBjoern A. Zeeb 
554dac88cdSJean-Sébastien Pédron static inline bool
564dac88cdSJean-Sébastien Pédron debugfs_initialized(void)
574dac88cdSJean-Sébastien Pédron {
584dac88cdSJean-Sébastien Pédron 
594dac88cdSJean-Sébastien Pédron 	return (true);
604dac88cdSJean-Sébastien Pédron }
614dac88cdSJean-Sébastien Pédron 
623f6cab07SMatt Macy struct dentry *debugfs_create_file(const char *name, umode_t mode,
633f6cab07SMatt Macy     struct dentry *parent, void *data,
643f6cab07SMatt Macy     const struct file_operations *fops);
653f6cab07SMatt Macy 
66a04aa80eSJean-Sébastien Pédron /* TODO: We currently ignore the `file_size` argument. */
67a04aa80eSJean-Sébastien Pédron struct dentry *debugfs_create_file_size(const char *name, umode_t mode,
68a04aa80eSJean-Sébastien Pédron     struct dentry *parent, void *data,
69a04aa80eSJean-Sébastien Pédron     const struct file_operations *fops,
70a04aa80eSJean-Sébastien Pédron     loff_t file_size);
71a04aa80eSJean-Sébastien Pédron 
72f697b943SJake Freeland struct dentry *debugfs_create_file_unsafe(const char *name, umode_t mode,
73f697b943SJake Freeland struct dentry *parent, void *data,
74f697b943SJake Freeland     const struct file_operations *fops);
75f697b943SJake Freeland 
76f697b943SJake Freeland struct dentry *debugfs_create_mode_unsafe(const char *name, umode_t mode,
77f697b943SJake Freeland     struct dentry *parent, void *data,
78f697b943SJake Freeland     const struct file_operations *fops,
79f697b943SJake Freeland     const struct file_operations *fops_ro,
80f697b943SJake Freeland     const struct file_operations *fops_wo);
81f697b943SJake Freeland 
823f6cab07SMatt Macy struct dentry *debugfs_create_dir(const char *name, struct dentry *parent);
833f6cab07SMatt Macy 
843f6cab07SMatt Macy struct dentry *debugfs_create_symlink(const char *name, struct dentry *parent,
853f6cab07SMatt Macy     const char *dest);
863f6cab07SMatt Macy 
87f697b943SJake Freeland void debugfs_remove(struct dentry *dentry);
88f697b943SJake Freeland 
893f6cab07SMatt Macy void debugfs_remove_recursive(struct dentry *dentry);
903f6cab07SMatt Macy 
91f697b943SJake Freeland #define DEFINE_DEBUGFS_ATTRIBUTE(__fops, __get, __set, __fmt) \
92f697b943SJake Freeland 	DEFINE_SIMPLE_ATTRIBUTE(__fops, __get, __set, __fmt)
93f697b943SJake Freeland 
94f697b943SJake Freeland void debugfs_create_bool(const char *name, umode_t mode, struct dentry *parent,
95f697b943SJake Freeland     bool *value);
960fce2dc1SBjoern A. Zeeb void debugfs_create_u8(const char *name, umode_t mode, struct dentry *parent,
970fce2dc1SBjoern A. Zeeb     uint8_t *value);
98976aa07aSJean-Sébastien Pédron void debugfs_create_u16(const char *name, umode_t mode, struct dentry *parent,
99976aa07aSJean-Sébastien Pédron     uint16_t *value);
100976aa07aSJean-Sébastien Pédron void debugfs_create_u32(const char *name, umode_t mode, struct dentry *parent,
101976aa07aSJean-Sébastien Pédron     uint32_t *value);
102976aa07aSJean-Sébastien Pédron void debugfs_create_u64(const char *name, umode_t mode, struct dentry *parent,
103976aa07aSJean-Sébastien Pédron     uint64_t *value);
104976aa07aSJean-Sébastien Pédron void debugfs_create_x8(const char *name, umode_t mode, struct dentry *parent,
105976aa07aSJean-Sébastien Pédron     uint8_t *value);
106976aa07aSJean-Sébastien Pédron void debugfs_create_x16(const char *name, umode_t mode, struct dentry *parent,
107976aa07aSJean-Sébastien Pédron     uint16_t *value);
108976aa07aSJean-Sébastien Pédron void debugfs_create_x32(const char *name, umode_t mode, struct dentry *parent,
109976aa07aSJean-Sébastien Pédron     uint32_t *value);
110976aa07aSJean-Sébastien Pédron void debugfs_create_x64(const char *name, umode_t mode, struct dentry *parent,
111976aa07aSJean-Sébastien Pédron     uint64_t *value);
112f697b943SJake Freeland void debugfs_create_ulong(const char *name, umode_t mode, struct dentry *parent,
113f697b943SJake Freeland     unsigned long *value);
114f2044a30SJean-Sébastien Pédron void debugfs_create_atomic_t(const char *name, umode_t mode, struct dentry *parent,
115f2044a30SJean-Sébastien Pédron     atomic_t *value);
116f697b943SJake Freeland 
1170fce2dc1SBjoern A. Zeeb struct dentry *debugfs_create_blob(const char *name, umode_t mode,
1180fce2dc1SBjoern A. Zeeb     struct dentry *parent, struct debugfs_blob_wrapper *value);
1190fce2dc1SBjoern A. Zeeb 
120f697b943SJake Freeland #endif /* _LINUXKPI_LINUX_DEBUGFS_H_ */
121