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 	spinlock_t ctx_lock; /* For add/remove from ctx_list. */
28 	struct list_head ctx_list; /* List of contexts belonging to client. */
29 
30 #ifdef CONFIG_PROC_FS
31 	/**
32 	 * @objects_lock: lock protecting @objects_list
33 	 */
34 	spinlock_t objects_lock;
35 
36 	/**
37 	 * @objects_list: list of objects created by this client
38 	 *
39 	 * Protected by @objects_lock.
40 	 */
41 	struct list_head objects_list;
42 #endif
43 
44 	/**
45 	 * @past_runtime: Accumulation of pphwsp runtimes from closed contexts.
46 	 */
47 	atomic64_t past_runtime[I915_LAST_UABI_ENGINE_CLASS + 1];
48 };
49 
50 static inline struct i915_drm_client *
i915_drm_client_get(struct i915_drm_client * client)51 i915_drm_client_get(struct i915_drm_client *client)
52 {
53 	kref_get(&client->kref);
54 	return client;
55 }
56 
57 void __i915_drm_client_free(struct kref *kref);
58 
i915_drm_client_put(struct i915_drm_client * client)59 static inline void i915_drm_client_put(struct i915_drm_client *client)
60 {
61 	kref_put(&client->kref, __i915_drm_client_free);
62 }
63 
64 struct i915_drm_client *i915_drm_client_alloc(void);
65 
66 void i915_drm_client_fdinfo(struct drm_printer *p, struct drm_file *file);
67 
68 #ifdef CONFIG_PROC_FS
69 void i915_drm_client_add_object(struct i915_drm_client *client,
70 				struct drm_i915_gem_object *obj);
71 void i915_drm_client_remove_object(struct drm_i915_gem_object *obj);
72 void i915_drm_client_add_context_objects(struct i915_drm_client *client,
73 					 struct intel_context *ce);
74 #else
i915_drm_client_add_object(struct i915_drm_client * client,struct drm_i915_gem_object * obj)75 static inline void i915_drm_client_add_object(struct i915_drm_client *client,
76 					      struct drm_i915_gem_object *obj)
77 {
78 }
79 
80 static inline void
i915_drm_client_remove_object(struct drm_i915_gem_object * obj)81 i915_drm_client_remove_object(struct drm_i915_gem_object *obj)
82 {
83 }
84 
85 static inline void
i915_drm_client_add_context_objects(struct i915_drm_client * client,struct intel_context * ce)86 i915_drm_client_add_context_objects(struct i915_drm_client *client,
87 				    struct intel_context *ce)
88 {
89 }
90 #endif
91 
92 #endif /* !__I915_DRM_CLIENT_H__ */
93