@@ -87,9 +87,55 @@ static int xe_file_open(struct drm_device *dev, struct drm_file *file)
8787 spin_unlock (& xe -> clients .lock );
8888
8989 file -> driver_priv = xef ;
90+ kref_init (& xef -> refcount );
91+
9092 return 0 ;
9193}
9294
95+ static void xe_file_destroy (struct kref * ref )
96+ {
97+ struct xe_file * xef = container_of (ref , struct xe_file , refcount );
98+ struct xe_device * xe = xef -> xe ;
99+
100+ xa_destroy (& xef -> exec_queue .xa );
101+ mutex_destroy (& xef -> exec_queue .lock );
102+ xa_destroy (& xef -> vm .xa );
103+ mutex_destroy (& xef -> vm .lock );
104+
105+ spin_lock (& xe -> clients .lock );
106+ xe -> clients .count -- ;
107+ spin_unlock (& xe -> clients .lock );
108+
109+ xe_drm_client_put (xef -> client );
110+ kfree (xef );
111+ }
112+
113+ /**
114+ * xe_file_get() - Take a reference to the xe file object
115+ * @xef: Pointer to the xe file
116+ *
117+ * Anyone with a pointer to xef must take a reference to the xe file
118+ * object using this call.
119+ *
120+ * Return: xe file pointer
121+ */
122+ struct xe_file * xe_file_get (struct xe_file * xef )
123+ {
124+ kref_get (& xef -> refcount );
125+ return xef ;
126+ }
127+
128+ /**
129+ * xe_file_put() - Drop a reference to the xe file object
130+ * @xef: Pointer to the xe file
131+ *
132+ * Used to drop reference to the xef object
133+ */
134+ void xe_file_put (struct xe_file * xef )
135+ {
136+ kref_put (& xef -> refcount , xe_file_destroy );
137+ }
138+
93139static void xe_file_close (struct drm_device * dev , struct drm_file * file )
94140{
95141 struct xe_device * xe = to_xe_device (dev );
@@ -98,6 +144,8 @@ static void xe_file_close(struct drm_device *dev, struct drm_file *file)
98144 struct xe_exec_queue * q ;
99145 unsigned long idx ;
100146
147+ xe_pm_runtime_get (xe );
148+
101149 /*
102150 * No need for exec_queue.lock here as there is no contention for it
103151 * when FD is closing as IOCTLs presumably can't be modifying the
@@ -108,21 +156,14 @@ static void xe_file_close(struct drm_device *dev, struct drm_file *file)
108156 xe_exec_queue_kill (q );
109157 xe_exec_queue_put (q );
110158 }
111- xa_destroy (& xef -> exec_queue .xa );
112- mutex_destroy (& xef -> exec_queue .lock );
113159 mutex_lock (& xef -> vm .lock );
114160 xa_for_each (& xef -> vm .xa , idx , vm )
115161 xe_vm_close_and_put (vm );
116162 mutex_unlock (& xef -> vm .lock );
117- xa_destroy (& xef -> vm .xa );
118- mutex_destroy (& xef -> vm .lock );
119163
120- spin_lock (& xe -> clients .lock );
121- xe -> clients .count -- ;
122- spin_unlock (& xe -> clients .lock );
164+ xe_file_put (xef );
123165
124- xe_drm_client_put (xef -> client );
125- kfree (xef );
166+ xe_pm_runtime_put (xe );
126167}
127168
128169static const struct drm_ioctl_desc xe_ioctls [] = {
0 commit comments