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
21struct drm_file;
22struct drm_printer;
23
24struct 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
50static inline struct i915_drm_client *
51i915_drm_client_get(struct i915_drm_client *client)
52{
53 kref_get(kref: &client->kref);
54 return client;
55}
56
57void __i915_drm_client_free(struct kref *kref);
58
59static inline void i915_drm_client_put(struct i915_drm_client *client)
60{
61 kref_put(kref: &client->kref, release: __i915_drm_client_free);
62}
63
64struct i915_drm_client *i915_drm_client_alloc(void);
65
66void i915_drm_client_fdinfo(struct drm_printer *p, struct drm_file *file);
67
68#ifdef CONFIG_PROC_FS
69void i915_drm_client_add_object(struct i915_drm_client *client,
70 struct drm_i915_gem_object *obj);
71void i915_drm_client_remove_object(struct drm_i915_gem_object *obj);
72void i915_drm_client_add_context_objects(struct i915_drm_client *client,
73 struct intel_context *ce);
74#else
75static inline void i915_drm_client_add_object(struct i915_drm_client *client,
76 struct drm_i915_gem_object *obj)
77{
78}
79
80static inline void
81i915_drm_client_remove_object(struct drm_i915_gem_object *obj)
82{
83}
84
85static inline void
86i915_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

source code of linux/drivers/gpu/drm/i915/i915_drm_client.h