xref: /linux/drivers/gpu/drm/i915/i915_drm_client.h (revision e7d759f31ca295d589f7420719c311870bb3166f)
1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Copyright © 2020 Intel Corporation
4  */
5 
6 #ifndef __I915_DRM_CLIENT_H__
7 #define __I915_DRM_CLIENT_H__
8 
9 #include <linux/kref.h>
10 #include <linux/list.h>
11 #include <linux/spinlock.h>
12 
13 #include <uapi/drm/i915_drm.h>
14 
15 #include "i915_file_private.h"
16 #include "gem/i915_gem_object_types.h"
17 #include "gt/intel_context_types.h"
18 
19 #define I915_LAST_UABI_ENGINE_CLASS I915_ENGINE_CLASS_COMPUTE
20 
21 struct drm_file;
22 struct drm_printer;
23 
24 struct i915_drm_client {
25 	struct kref kref;
26 
27 	unsigned int id;
28 
29 	spinlock_t ctx_lock; /* For add/remove from ctx_list. */
30 	struct list_head ctx_list; /* List of contexts belonging to client. */
31 
32 #ifdef CONFIG_PROC_FS
33 	/**
34 	 * @objects_lock: lock protecting @objects_list
35 	 */
36 	spinlock_t objects_lock;
37 
38 	/**
39 	 * @objects_list: list of objects created by this client
40 	 *
41 	 * Protected by @objects_lock.
42 	 */
43 	struct list_head objects_list;
44 #endif
45 
46 	/**
47 	 * @past_runtime: Accumulation of pphwsp runtimes from closed contexts.
48 	 */
49 	atomic64_t past_runtime[I915_LAST_UABI_ENGINE_CLASS + 1];
50 };
51 
52 static inline struct i915_drm_client *
53 i915_drm_client_get(struct i915_drm_client *client)
54 {
55 	kref_get(&client->kref);
56 	return client;
57 }
58 
59 void __i915_drm_client_free(struct kref *kref);
60 
61 static inline void i915_drm_client_put(struct i915_drm_client *client)
62 {
63 	kref_put(&client->kref, __i915_drm_client_free);
64 }
65 
66 struct i915_drm_client *i915_drm_client_alloc(void);
67 
68 void i915_drm_client_fdinfo(struct drm_printer *p, struct drm_file *file);
69 
70 #ifdef CONFIG_PROC_FS
71 void i915_drm_client_add_object(struct i915_drm_client *client,
72 				struct drm_i915_gem_object *obj);
73 void i915_drm_client_remove_object(struct drm_i915_gem_object *obj);
74 void i915_drm_client_add_context_objects(struct i915_drm_client *client,
75 					 struct intel_context *ce);
76 #else
77 static inline void i915_drm_client_add_object(struct i915_drm_client *client,
78 					      struct drm_i915_gem_object *obj)
79 {
80 }
81 
82 static inline void
83 i915_drm_client_remove_object(struct drm_i915_gem_object *obj)
84 {
85 }
86 
87 static inline void
88 i915_drm_client_add_context_objects(struct i915_drm_client *client,
89 				    struct intel_context *ce)
90 {
91 }
92 #endif
93 
94 #endif /* !__I915_DRM_CLIENT_H__ */
95