xref: /linux/drivers/gpu/drm/nouveau/include/nvif/log.h (revision 2c1ed907520c50326b8f604907a8478b27881a2e)
1 /* SPDX-License-Identifier: MIT */
2 /* SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. */
3 
4 #ifndef __NVIF_LOG_H__
5 #define __NVIF_LOG_H__
6 
7 #ifdef CONFIG_DEBUG_FS
8 
9 /**
10  * nvif_log - structure for tracking logging buffers
11  * @entry: an entry in a list of struct nvif_logs
12  * @shutdown: pointer to function to call to clean up
13  *
14  * Structure used to track logging buffers so that they can be cleaned up
15  * when the module exits.
16  *
17  * The @shutdown function is called when the module exits. It should free all
18  * backing resources, such as logging buffers.
19  */
20 struct nvif_log {
21 	struct list_head entry;
22 	void (*shutdown)(struct nvif_log *log);
23 };
24 
25 /**
26  * nvif_logs - linked list of nvif_log objects
27  */
28 struct nvif_logs {
29 	struct list_head head;
30 };
31 
32 #define NVIF_LOGS_DECLARE(logs) \
33 	struct nvif_logs logs = { LIST_HEAD_INIT(logs.head) }
34 
nvif_log_shutdown(struct nvif_logs * logs)35 static inline void nvif_log_shutdown(struct nvif_logs *logs)
36 {
37 	if (!list_empty(&logs->head)) {
38 		struct nvif_log *log, *n;
39 
40 		list_for_each_entry_safe(log, n, &logs->head, entry) {
41 			/* shutdown() should also delete the log entry */
42 			log->shutdown(log);
43 		}
44 	}
45 }
46 
47 extern struct nvif_logs gsp_logs;
48 
49 #endif
50 
51 #endif
52