162306a36Sopenharmony_ci#ifndef _DRM_AUTH_H_ 262306a36Sopenharmony_ci#define _DRM_AUTH_H_ 362306a36Sopenharmony_ci 462306a36Sopenharmony_ci/* 562306a36Sopenharmony_ci * Internal Header for the Direct Rendering Manager 662306a36Sopenharmony_ci * 762306a36Sopenharmony_ci * Copyright 2016 Intel Corporation 862306a36Sopenharmony_ci * 962306a36Sopenharmony_ci * Author: Daniel Vetter <daniel.vetter@ffwll.ch> 1062306a36Sopenharmony_ci * 1162306a36Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 1262306a36Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 1362306a36Sopenharmony_ci * to deal in the Software without restriction, including without limitation 1462306a36Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 1562306a36Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 1662306a36Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 1762306a36Sopenharmony_ci * 1862306a36Sopenharmony_ci * The above copyright notice and this permission notice (including the next 1962306a36Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 2062306a36Sopenharmony_ci * Software. 2162306a36Sopenharmony_ci * 2262306a36Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 2362306a36Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 2462306a36Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 2562306a36Sopenharmony_ci * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 2662306a36Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 2762306a36Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 2862306a36Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE. 2962306a36Sopenharmony_ci */ 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ci#include <linux/idr.h> 3262306a36Sopenharmony_ci#include <linux/kref.h> 3362306a36Sopenharmony_ci#include <linux/wait.h> 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_cistruct drm_file; 3662306a36Sopenharmony_cistruct drm_hw_lock; 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ci/* 3962306a36Sopenharmony_ci * Legacy DRI1 locking data structure. Only here instead of in drm_legacy.h for 4062306a36Sopenharmony_ci * include ordering reasons. 4162306a36Sopenharmony_ci * 4262306a36Sopenharmony_ci * DO NOT USE. 4362306a36Sopenharmony_ci */ 4462306a36Sopenharmony_cistruct drm_lock_data { 4562306a36Sopenharmony_ci struct drm_hw_lock *hw_lock; 4662306a36Sopenharmony_ci struct drm_file *file_priv; 4762306a36Sopenharmony_ci wait_queue_head_t lock_queue; 4862306a36Sopenharmony_ci unsigned long lock_time; 4962306a36Sopenharmony_ci spinlock_t spinlock; 5062306a36Sopenharmony_ci uint32_t kernel_waiters; 5162306a36Sopenharmony_ci uint32_t user_waiters; 5262306a36Sopenharmony_ci int idle_has_lock; 5362306a36Sopenharmony_ci}; 5462306a36Sopenharmony_ci 5562306a36Sopenharmony_ci/** 5662306a36Sopenharmony_ci * struct drm_master - drm master structure 5762306a36Sopenharmony_ci * 5862306a36Sopenharmony_ci * @refcount: Refcount for this master object. 5962306a36Sopenharmony_ci * @dev: Link back to the DRM device 6062306a36Sopenharmony_ci * @driver_priv: Pointer to driver-private information. 6162306a36Sopenharmony_ci * 6262306a36Sopenharmony_ci * Note that master structures are only relevant for the legacy/primary device 6362306a36Sopenharmony_ci * nodes, hence there can only be one per device, not one per drm_minor. 6462306a36Sopenharmony_ci */ 6562306a36Sopenharmony_cistruct drm_master { 6662306a36Sopenharmony_ci struct kref refcount; 6762306a36Sopenharmony_ci struct drm_device *dev; 6862306a36Sopenharmony_ci /** 6962306a36Sopenharmony_ci * @unique: Unique identifier: e.g. busid. Protected by 7062306a36Sopenharmony_ci * &drm_device.master_mutex. 7162306a36Sopenharmony_ci */ 7262306a36Sopenharmony_ci char *unique; 7362306a36Sopenharmony_ci /** 7462306a36Sopenharmony_ci * @unique_len: Length of unique field. Protected by 7562306a36Sopenharmony_ci * &drm_device.master_mutex. 7662306a36Sopenharmony_ci */ 7762306a36Sopenharmony_ci int unique_len; 7862306a36Sopenharmony_ci /** 7962306a36Sopenharmony_ci * @magic_map: Map of used authentication tokens. Protected by 8062306a36Sopenharmony_ci * &drm_device.master_mutex. 8162306a36Sopenharmony_ci */ 8262306a36Sopenharmony_ci struct idr magic_map; 8362306a36Sopenharmony_ci void *driver_priv; 8462306a36Sopenharmony_ci 8562306a36Sopenharmony_ci /** 8662306a36Sopenharmony_ci * @lessor: 8762306a36Sopenharmony_ci * 8862306a36Sopenharmony_ci * Lease grantor, only set if this &struct drm_master represents a 8962306a36Sopenharmony_ci * lessee holding a lease of objects from @lessor. Full owners of the 9062306a36Sopenharmony_ci * device have this set to NULL. 9162306a36Sopenharmony_ci * 9262306a36Sopenharmony_ci * The lessor does not change once it's set in drm_lease_create(), and 9362306a36Sopenharmony_ci * each lessee holds a reference to its lessor that it releases upon 9462306a36Sopenharmony_ci * being destroyed in drm_lease_destroy(). 9562306a36Sopenharmony_ci * 9662306a36Sopenharmony_ci * See also the :ref:`section on display resource leasing 9762306a36Sopenharmony_ci * <drm_leasing>`. 9862306a36Sopenharmony_ci */ 9962306a36Sopenharmony_ci struct drm_master *lessor; 10062306a36Sopenharmony_ci 10162306a36Sopenharmony_ci /** 10262306a36Sopenharmony_ci * @lessee_id: 10362306a36Sopenharmony_ci * 10462306a36Sopenharmony_ci * ID for lessees. Owners (i.e. @lessor is NULL) always have ID 0. 10562306a36Sopenharmony_ci * Protected by &drm_device.mode_config's &drm_mode_config.idr_mutex. 10662306a36Sopenharmony_ci */ 10762306a36Sopenharmony_ci int lessee_id; 10862306a36Sopenharmony_ci 10962306a36Sopenharmony_ci /** 11062306a36Sopenharmony_ci * @lessee_list: 11162306a36Sopenharmony_ci * 11262306a36Sopenharmony_ci * List entry of lessees of @lessor, where they are linked to @lessees. 11362306a36Sopenharmony_ci * Not used for owners. Protected by &drm_device.mode_config's 11462306a36Sopenharmony_ci * &drm_mode_config.idr_mutex. 11562306a36Sopenharmony_ci */ 11662306a36Sopenharmony_ci struct list_head lessee_list; 11762306a36Sopenharmony_ci 11862306a36Sopenharmony_ci /** 11962306a36Sopenharmony_ci * @lessees: 12062306a36Sopenharmony_ci * 12162306a36Sopenharmony_ci * List of drm_masters leasing from this one. Protected by 12262306a36Sopenharmony_ci * &drm_device.mode_config's &drm_mode_config.idr_mutex. 12362306a36Sopenharmony_ci * 12462306a36Sopenharmony_ci * This list is empty if no leases have been granted, or if all lessees 12562306a36Sopenharmony_ci * have been destroyed. Since lessors are referenced by all their 12662306a36Sopenharmony_ci * lessees, this master cannot be destroyed unless the list is empty. 12762306a36Sopenharmony_ci */ 12862306a36Sopenharmony_ci struct list_head lessees; 12962306a36Sopenharmony_ci 13062306a36Sopenharmony_ci /** 13162306a36Sopenharmony_ci * @leases: 13262306a36Sopenharmony_ci * 13362306a36Sopenharmony_ci * Objects leased to this drm_master. Protected by 13462306a36Sopenharmony_ci * &drm_device.mode_config's &drm_mode_config.idr_mutex. 13562306a36Sopenharmony_ci * 13662306a36Sopenharmony_ci * Objects are leased all together in drm_lease_create(), and are 13762306a36Sopenharmony_ci * removed all together when the lease is revoked. 13862306a36Sopenharmony_ci */ 13962306a36Sopenharmony_ci struct idr leases; 14062306a36Sopenharmony_ci 14162306a36Sopenharmony_ci /** 14262306a36Sopenharmony_ci * @lessee_idr: 14362306a36Sopenharmony_ci * 14462306a36Sopenharmony_ci * All lessees under this owner (only used where @lessor is NULL). 14562306a36Sopenharmony_ci * Protected by &drm_device.mode_config's &drm_mode_config.idr_mutex. 14662306a36Sopenharmony_ci */ 14762306a36Sopenharmony_ci struct idr lessee_idr; 14862306a36Sopenharmony_ci /* private: */ 14962306a36Sopenharmony_ci#if IS_ENABLED(CONFIG_DRM_LEGACY) 15062306a36Sopenharmony_ci struct drm_lock_data lock; 15162306a36Sopenharmony_ci#endif 15262306a36Sopenharmony_ci}; 15362306a36Sopenharmony_ci 15462306a36Sopenharmony_cistruct drm_master *drm_master_get(struct drm_master *master); 15562306a36Sopenharmony_cistruct drm_master *drm_file_get_master(struct drm_file *file_priv); 15662306a36Sopenharmony_civoid drm_master_put(struct drm_master **master); 15762306a36Sopenharmony_cibool drm_is_current_master(struct drm_file *fpriv); 15862306a36Sopenharmony_ci 15962306a36Sopenharmony_cistruct drm_master *drm_master_create(struct drm_device *dev); 16062306a36Sopenharmony_ci 16162306a36Sopenharmony_ci#endif 162