18c2ecf20Sopenharmony_ci#ifndef _DRM_AUTH_H_
28c2ecf20Sopenharmony_ci#define _DRM_AUTH_H_
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci/*
58c2ecf20Sopenharmony_ci * Internal Header for the Direct Rendering Manager
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Copyright 2016 Intel Corporation
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * Author: Daniel Vetter <daniel.vetter@ffwll.ch>
108c2ecf20Sopenharmony_ci *
118c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
128c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
138c2ecf20Sopenharmony_ci * to deal in the Software without restriction, including without limitation
148c2ecf20Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
158c2ecf20Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
168c2ecf20Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
178c2ecf20Sopenharmony_ci *
188c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice (including the next
198c2ecf20Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
208c2ecf20Sopenharmony_ci * Software.
218c2ecf20Sopenharmony_ci *
228c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
238c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
248c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
258c2ecf20Sopenharmony_ci * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
268c2ecf20Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
278c2ecf20Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
288c2ecf20Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE.
298c2ecf20Sopenharmony_ci */
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci#include <linux/idr.h>
328c2ecf20Sopenharmony_ci#include <linux/kref.h>
338c2ecf20Sopenharmony_ci#include <linux/wait.h>
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_cistruct drm_file;
368c2ecf20Sopenharmony_cistruct drm_hw_lock;
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci/*
398c2ecf20Sopenharmony_ci * Legacy DRI1 locking data structure. Only here instead of in drm_legacy.h for
408c2ecf20Sopenharmony_ci * include ordering reasons.
418c2ecf20Sopenharmony_ci *
428c2ecf20Sopenharmony_ci * DO NOT USE.
438c2ecf20Sopenharmony_ci */
448c2ecf20Sopenharmony_cistruct drm_lock_data {
458c2ecf20Sopenharmony_ci	struct drm_hw_lock *hw_lock;
468c2ecf20Sopenharmony_ci	struct drm_file *file_priv;
478c2ecf20Sopenharmony_ci	wait_queue_head_t lock_queue;
488c2ecf20Sopenharmony_ci	unsigned long lock_time;
498c2ecf20Sopenharmony_ci	spinlock_t spinlock;
508c2ecf20Sopenharmony_ci	uint32_t kernel_waiters;
518c2ecf20Sopenharmony_ci	uint32_t user_waiters;
528c2ecf20Sopenharmony_ci	int idle_has_lock;
538c2ecf20Sopenharmony_ci};
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci/**
568c2ecf20Sopenharmony_ci * struct drm_master - drm master structure
578c2ecf20Sopenharmony_ci *
588c2ecf20Sopenharmony_ci * @refcount: Refcount for this master object.
598c2ecf20Sopenharmony_ci * @dev: Link back to the DRM device
608c2ecf20Sopenharmony_ci * @driver_priv: Pointer to driver-private information.
618c2ecf20Sopenharmony_ci * @lessor: Lease holder
628c2ecf20Sopenharmony_ci * @lessee_id: id for lessees. Owners always have id 0
638c2ecf20Sopenharmony_ci * @lessee_list: other lessees of the same master
648c2ecf20Sopenharmony_ci * @lessees: drm_masters leasing from this one
658c2ecf20Sopenharmony_ci * @leases: Objects leased to this drm_master.
668c2ecf20Sopenharmony_ci * @lessee_idr: All lessees under this owner (only used where lessor == NULL)
678c2ecf20Sopenharmony_ci *
688c2ecf20Sopenharmony_ci * Note that master structures are only relevant for the legacy/primary device
698c2ecf20Sopenharmony_ci * nodes, hence there can only be one per device, not one per drm_minor.
708c2ecf20Sopenharmony_ci */
718c2ecf20Sopenharmony_cistruct drm_master {
728c2ecf20Sopenharmony_ci	struct kref refcount;
738c2ecf20Sopenharmony_ci	struct drm_device *dev;
748c2ecf20Sopenharmony_ci	/**
758c2ecf20Sopenharmony_ci	 * @unique: Unique identifier: e.g. busid. Protected by
768c2ecf20Sopenharmony_ci	 * &drm_device.master_mutex.
778c2ecf20Sopenharmony_ci	 */
788c2ecf20Sopenharmony_ci	char *unique;
798c2ecf20Sopenharmony_ci	/**
808c2ecf20Sopenharmony_ci	 * @unique_len: Length of unique field. Protected by
818c2ecf20Sopenharmony_ci	 * &drm_device.master_mutex.
828c2ecf20Sopenharmony_ci	 */
838c2ecf20Sopenharmony_ci	int unique_len;
848c2ecf20Sopenharmony_ci	/**
858c2ecf20Sopenharmony_ci	 * @magic_map: Map of used authentication tokens. Protected by
868c2ecf20Sopenharmony_ci	 * &drm_device.master_mutex.
878c2ecf20Sopenharmony_ci	 */
888c2ecf20Sopenharmony_ci	struct idr magic_map;
898c2ecf20Sopenharmony_ci	void *driver_priv;
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci	/* Tree of display resource leases, each of which is a drm_master struct
928c2ecf20Sopenharmony_ci	 * All of these get activated simultaneously, so drm_device master points
938c2ecf20Sopenharmony_ci	 * at the top of the tree (for which lessor is NULL). Protected by
948c2ecf20Sopenharmony_ci	 * &drm_device.mode_config.idr_mutex.
958c2ecf20Sopenharmony_ci	 */
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci	struct drm_master *lessor;
988c2ecf20Sopenharmony_ci	int	lessee_id;
998c2ecf20Sopenharmony_ci	struct list_head lessee_list;
1008c2ecf20Sopenharmony_ci	struct list_head lessees;
1018c2ecf20Sopenharmony_ci	struct idr leases;
1028c2ecf20Sopenharmony_ci	struct idr lessee_idr;
1038c2ecf20Sopenharmony_ci	/* private: */
1048c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_DRM_LEGACY)
1058c2ecf20Sopenharmony_ci	struct drm_lock_data lock;
1068c2ecf20Sopenharmony_ci#endif
1078c2ecf20Sopenharmony_ci};
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_cistruct drm_master *drm_master_get(struct drm_master *master);
1108c2ecf20Sopenharmony_cistruct drm_master *drm_file_get_master(struct drm_file *file_priv);
1118c2ecf20Sopenharmony_civoid drm_master_put(struct drm_master **master);
1128c2ecf20Sopenharmony_cibool drm_is_current_master(struct drm_file *fpriv);
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_cistruct drm_master *drm_master_create(struct drm_device *dev);
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ci#endif
117