13f6cab07SMatt Macy /*- 24d846d26SWarner 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 28307f78f3SVladimir Kondratyev #ifndef _LINUXKPI_LINUX_DEBUGFS_H_ 29307f78f3SVladimir Kondratyev #define _LINUXKPI_LINUX_DEBUGFS_H_ 303f6cab07SMatt Macy 313f6cab07SMatt Macy #include <linux/fs.h> 32f697b943SJake Freeland #include <linux/module.h> 333f6cab07SMatt Macy #include <linux/seq_file.h> 343f6cab07SMatt Macy #include <linux/types.h> 353f6cab07SMatt Macy 36f697b943SJake Freeland MALLOC_DECLARE(M_DFSINT); 37f697b943SJake Freeland 38f697b943SJake Freeland struct debugfs_reg32 { 39f697b943SJake Freeland char *name; 40f697b943SJake Freeland unsigned long offset; 41f697b943SJake Freeland }; 42f697b943SJake Freeland 43f697b943SJake Freeland struct debugfs_regset32 { 44f697b943SJake Freeland const struct debugfs_reg32 *regs; 45f697b943SJake Freeland int nregs; 46f697b943SJake Freeland }; 473f6cab07SMatt Macy 480fce2dc1SBjoern A. Zeeb struct debugfs_blob_wrapper { 490fce2dc1SBjoern A. Zeeb void *data; 500fce2dc1SBjoern A. Zeeb size_t size; 510fce2dc1SBjoern A. Zeeb }; 520fce2dc1SBjoern A. Zeeb 534dac88cdSJean-Sébastien Pédron static inline bool 544dac88cdSJean-Sébastien Pédron debugfs_initialized(void) 554dac88cdSJean-Sébastien Pédron { 564dac88cdSJean-Sébastien Pédron 574dac88cdSJean-Sébastien Pédron return (true); 584dac88cdSJean-Sébastien Pédron } 594dac88cdSJean-Sébastien Pédron 603f6cab07SMatt Macy struct dentry *debugfs_create_file(const char *name, umode_t mode, 613f6cab07SMatt Macy struct dentry *parent, void *data, 623f6cab07SMatt Macy const struct file_operations *fops); 633f6cab07SMatt Macy 64a04aa80eSJean-Sébastien Pédron /* TODO: We currently ignore the `file_size` argument. */ 65a04aa80eSJean-Sébastien Pédron struct dentry *debugfs_create_file_size(const char *name, umode_t mode, 66a04aa80eSJean-Sébastien Pédron struct dentry *parent, void *data, 67a04aa80eSJean-Sébastien Pédron const struct file_operations *fops, 68a04aa80eSJean-Sébastien Pédron loff_t file_size); 69a04aa80eSJean-Sébastien Pédron 70f697b943SJake Freeland struct dentry *debugfs_create_file_unsafe(const char *name, umode_t mode, 71f697b943SJake Freeland struct dentry *parent, void *data, 72f697b943SJake Freeland const struct file_operations *fops); 73f697b943SJake Freeland 74f697b943SJake Freeland struct dentry *debugfs_create_mode_unsafe(const char *name, umode_t mode, 75f697b943SJake Freeland struct dentry *parent, void *data, 76f697b943SJake Freeland const struct file_operations *fops, 77f697b943SJake Freeland const struct file_operations *fops_ro, 78f697b943SJake Freeland const struct file_operations *fops_wo); 79f697b943SJake Freeland 803f6cab07SMatt Macy struct dentry *debugfs_create_dir(const char *name, struct dentry *parent); 813f6cab07SMatt Macy 823f6cab07SMatt Macy struct dentry *debugfs_create_symlink(const char *name, struct dentry *parent, 833f6cab07SMatt Macy const char *dest); 843f6cab07SMatt Macy 85f697b943SJake Freeland void debugfs_remove(struct dentry *dentry); 86f697b943SJake Freeland 873f6cab07SMatt Macy void debugfs_remove_recursive(struct dentry *dentry); 883f6cab07SMatt Macy 89f697b943SJake Freeland #define DEFINE_DEBUGFS_ATTRIBUTE(__fops, __get, __set, __fmt) \ 90f697b943SJake Freeland DEFINE_SIMPLE_ATTRIBUTE(__fops, __get, __set, __fmt) 91*8c5c5721SVladimir Kondratyev #define DEFINE_DEBUGFS_ATTRIBUTE_SIGNED(__fops, __get, __set, __fmt) \ 92*8c5c5721SVladimir Kondratyev DEFINE_SIMPLE_ATTRIBUTE_SIGNED(__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