xref: /OK3568_Linux_fs/kernel/drivers/gpu/arm/bifrost/tests/include/kutf/kutf_helpers.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 /*
3  *
4  * (C) COPYRIGHT 2017, 2020-2022 ARM Limited. All rights reserved.
5  *
6  * This program is free software and is provided to you under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation, and any use by you of this program is subject to the terms
9  * of such GNU license.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you can access it online at
18  * http://www.gnu.org/licenses/gpl-2.0.html.
19  *
20  */
21 
22 #ifndef _KERNEL_UTF_HELPERS_H_
23 #define _KERNEL_UTF_HELPERS_H_
24 
25 /* kutf_helpers.h
26  * Test helper functions for the kernel UTF test infrastructure.
27  *
28  * These functions provide methods for enqueuing/dequeuing lines of text sent
29  * by user space. They are used to implement the transfer of "userdata" from
30  * user space to kernel.
31  */
32 
33 #include <kutf/kutf_suite.h>
34 #include <linux/device.h>
35 
36 /**
37  * kutf_helper_pending_input() - Check any pending lines sent by user space
38  * @context:    KUTF context
39  *
40  * Return: true if there are pending lines, otherwise false
41  */
42 bool kutf_helper_pending_input(struct kutf_context *context);
43 
44 /**
45  * kutf_helper_input_dequeue() - Dequeue a line sent by user space
46  * @context:    KUTF context
47  * @str_size:   Pointer to an integer to receive the size of the string
48  *
49  * If no line is available then this function will wait (interruptibly) until
50  * a line is available.
51  *
52  * Return: The line dequeued, ERR_PTR(-EINTR) if interrupted or NULL on end
53  * of data.
54  */
55 char *kutf_helper_input_dequeue(struct kutf_context *context, size_t *str_size);
56 
57 /**
58  * kutf_helper_input_enqueue() - Enqueue a line sent by user space
59  * @context:   KUTF context
60  * @str:       The user space address of the line
61  * @size:      The length in bytes of the string
62  *
63  * This function will use copy_from_user to copy the string out of user space.
64  * The string need not be NULL-terminated (@size should not include the NULL
65  * termination).
66  *
67  * As a special case @str==NULL and @size==0 is valid to mark the end of input,
68  * but callers should use kutf_helper_input_enqueue_end_of_data() instead.
69  *
70  * Return: 0 on success, -EFAULT if the line cannot be copied from user space,
71  * -ENOMEM if out of memory.
72  */
73 int kutf_helper_input_enqueue(struct kutf_context *context,
74 		const char __user *str, size_t size);
75 
76 /**
77  * kutf_helper_input_enqueue_end_of_data() - Signal no more data is to be sent
78  * @context:    KUTF context
79  *
80  * After this function has been called, kutf_helper_input_dequeue() will always
81  * return NULL.
82  */
83 void kutf_helper_input_enqueue_end_of_data(struct kutf_context *context);
84 
85 /**
86  * kutf_helper_ignore_dmesg() - Write message in dmesg to instruct parser
87  *                              to ignore errors, until the counterpart
88  *                              is written to dmesg to stop ignoring errors.
89  * @dev:  Device pointer to write to dmesg using.
90  *
91  * This function writes "Start ignoring dmesg warnings" to dmesg, which
92  * the parser will read and not log any errors. Only to be used in cases where
93  * we expect an error to be produced in dmesg but that we do not want to be
94  * flagged as an error.
95  */
96 void kutf_helper_ignore_dmesg(struct device *dev);
97 
98 /**
99  * kutf_helper_stop_ignoring_dmesg() - Write message in dmesg to instruct parser
100  *                                     to stop ignoring errors.
101  * @dev:  Device pointer to write to dmesg using.
102  *
103  * This function writes "Stop ignoring dmesg warnings" to dmesg, which
104  * the parser will read and continue to log any errors. Counterpart to
105  * kutf_helper_ignore_dmesg().
106  */
107 void kutf_helper_stop_ignoring_dmesg(struct device *dev);
108 
109 #endif	/* _KERNEL_UTF_HELPERS_H_ */
110