xref: /OK3568_Linux_fs/kernel/drivers/gpu/arm/bifrost/tl/mali_kbase_timeline_priv.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 /*
3  *
4  * (C) COPYRIGHT 2019-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 #if !defined(_KBASE_TIMELINE_PRIV_H)
23 #define _KBASE_TIMELINE_PRIV_H
24 
25 #include <mali_kbase.h>
26 #include "mali_kbase_tlstream.h"
27 
28 #if MALI_USE_CSF
29 #include "csf/mali_kbase_csf_tl_reader.h"
30 #include "csf/mali_kbase_csf_trace_buffer.h"
31 #endif
32 
33 #include <linux/timer.h>
34 #include <linux/atomic.h>
35 #include <linux/mutex.h>
36 
37 /* The minimum amount of time timeline must be acquired for before release is
38  * allowed, to prevent DoS attacks.
39  */
40 #define TIMELINE_HYSTERESIS_TIMEOUT_MS ((s64)500)
41 
42 /**
43  * struct kbase_timeline - timeline state structure
44  * @streams:                The timeline streams generated by kernel
45  * @tl_kctx_list:           List of contexts for timeline.
46  * @tl_kctx_list_lock:      Lock to protect @tl_kctx_list.
47  * @autoflush_timer:        Autoflush timer
48  * @autoflush_timer_active: If non-zero autoflush timer is active
49  * @reader_lock:            Reader lock. Only one reader is allowed to
50  *                          have access to the timeline streams at any given time.
51  * @event_queue:            Timeline stream event queue
52  * @bytes_collected:        Number of bytes read by user
53  * @timeline_flags:         Zero, if timeline is disabled. Timeline stream flags
54  *                          otherwise. See kbase_timeline_acquire().
55  * @obj_header_btc:         Remaining bytes to copy for the object stream header
56  * @aux_header_btc:         Remaining bytes to copy for the aux stream header
57  * @last_acquire_time:      The time at which timeline was last acquired.
58  * @csf_tl_reader:          CSFFW timeline reader
59  */
60 struct kbase_timeline {
61 	struct kbase_tlstream streams[TL_STREAM_TYPE_COUNT];
62 	struct list_head  tl_kctx_list;
63 	struct mutex      tl_kctx_list_lock;
64 	struct timer_list autoflush_timer;
65 	atomic_t          autoflush_timer_active;
66 	struct mutex      reader_lock;
67 	wait_queue_head_t event_queue;
68 #if MALI_UNIT_TEST
69 	atomic_t          bytes_collected;
70 #endif /* MALI_UNIT_TEST */
71 	atomic_t         *timeline_flags;
72 	size_t            obj_header_btc;
73 	size_t            aux_header_btc;
74 	ktime_t           last_acquire_time;
75 #if MALI_USE_CSF
76 	struct kbase_csf_tl_reader csf_tl_reader;
77 #endif
78 };
79 
80 void kbase_create_timeline_objects(struct kbase_device *kbdev);
81 
82 /**
83  * kbase_timeline_acquire - acquire timeline for a userspace client.
84  * @kbdev:     An instance of the GPU platform device, allocated from the probe
85  *             method of the driver.
86  * @flags:     Timeline stream flags
87  *
88  * Each timeline instance can be acquired by only one userspace client at a time.
89  *
90  * Return: Zero on success, error number on failure (e.g. if already acquired).
91  */
92 int kbase_timeline_acquire(struct kbase_device *kbdev, u32 flags);
93 
94 /**
95  * kbase_timeline_release - release timeline for a userspace client.
96  * @timeline:     Timeline instance to be stopped. It must be previously acquired
97  *                with kbase_timeline_acquire().
98  *
99  * Releasing the timeline instance allows it to be acquired by another userspace client.
100  */
101 void kbase_timeline_release(struct kbase_timeline *timeline);
102 
103 #endif /* _KBASE_TIMELINE_PRIV_H */
104