18c2ecf20Sopenharmony_ci#ifndef __DRM_DRM_LEGACY_H__
28c2ecf20Sopenharmony_ci#define __DRM_DRM_LEGACY_H__
38c2ecf20Sopenharmony_ci/*
48c2ecf20Sopenharmony_ci * Legacy driver interfaces for the Direct Rendering Manager
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
78c2ecf20Sopenharmony_ci * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
88c2ecf20Sopenharmony_ci * Copyright (c) 2009-2010, Code Aurora Forum.
98c2ecf20Sopenharmony_ci * All rights reserved.
108c2ecf20Sopenharmony_ci * Copyright © 2014 Intel Corporation
118c2ecf20Sopenharmony_ci *   Daniel Vetter <daniel.vetter@ffwll.ch>
128c2ecf20Sopenharmony_ci *
138c2ecf20Sopenharmony_ci * Author: Rickard E. (Rik) Faith <faith@valinux.com>
148c2ecf20Sopenharmony_ci * Author: Gareth Hughes <gareth@valinux.com>
158c2ecf20Sopenharmony_ci *
168c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
178c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
188c2ecf20Sopenharmony_ci * to deal in the Software without restriction, including without limitation
198c2ecf20Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
208c2ecf20Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
218c2ecf20Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
228c2ecf20Sopenharmony_ci *
238c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice (including the next
248c2ecf20Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
258c2ecf20Sopenharmony_ci * Software.
268c2ecf20Sopenharmony_ci *
278c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
288c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
298c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
308c2ecf20Sopenharmony_ci * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
318c2ecf20Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
328c2ecf20Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
338c2ecf20Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE.
348c2ecf20Sopenharmony_ci */
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci#include <drm/drm.h>
378c2ecf20Sopenharmony_ci#include <drm/drm_auth.h>
388c2ecf20Sopenharmony_ci#include <drm/drm_hashtab.h>
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_cistruct drm_device;
418c2ecf20Sopenharmony_cistruct drm_driver;
428c2ecf20Sopenharmony_cistruct file;
438c2ecf20Sopenharmony_cistruct pci_driver;
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci/*
468c2ecf20Sopenharmony_ci * Legacy Support for palateontologic DRM drivers
478c2ecf20Sopenharmony_ci *
488c2ecf20Sopenharmony_ci * If you add a new driver and it uses any of these functions or structures,
498c2ecf20Sopenharmony_ci * you're doing it terribly wrong.
508c2ecf20Sopenharmony_ci */
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci/**
538c2ecf20Sopenharmony_ci * DMA buffer.
548c2ecf20Sopenharmony_ci */
558c2ecf20Sopenharmony_cistruct drm_buf {
568c2ecf20Sopenharmony_ci	int idx;		       /**< Index into master buflist */
578c2ecf20Sopenharmony_ci	int total;		       /**< Buffer size */
588c2ecf20Sopenharmony_ci	int order;		       /**< log-base-2(total) */
598c2ecf20Sopenharmony_ci	int used;		       /**< Amount of buffer in use (for DMA) */
608c2ecf20Sopenharmony_ci	unsigned long offset;	       /**< Byte offset (used internally) */
618c2ecf20Sopenharmony_ci	void *address;		       /**< Address of buffer */
628c2ecf20Sopenharmony_ci	unsigned long bus_address;     /**< Bus address of buffer */
638c2ecf20Sopenharmony_ci	struct drm_buf *next;	       /**< Kernel-only: used for free list */
648c2ecf20Sopenharmony_ci	__volatile__ int waiting;      /**< On kernel DMA queue */
658c2ecf20Sopenharmony_ci	__volatile__ int pending;      /**< On hardware DMA queue */
668c2ecf20Sopenharmony_ci	struct drm_file *file_priv;    /**< Private of holding file descr */
678c2ecf20Sopenharmony_ci	int context;		       /**< Kernel queue for this buffer */
688c2ecf20Sopenharmony_ci	int while_locked;	       /**< Dispatch this buffer while locked */
698c2ecf20Sopenharmony_ci	enum {
708c2ecf20Sopenharmony_ci		DRM_LIST_NONE = 0,
718c2ecf20Sopenharmony_ci		DRM_LIST_FREE = 1,
728c2ecf20Sopenharmony_ci		DRM_LIST_WAIT = 2,
738c2ecf20Sopenharmony_ci		DRM_LIST_PEND = 3,
748c2ecf20Sopenharmony_ci		DRM_LIST_PRIO = 4,
758c2ecf20Sopenharmony_ci		DRM_LIST_RECLAIM = 5
768c2ecf20Sopenharmony_ci	} list;			       /**< Which list we're on */
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci	int dev_priv_size;		 /**< Size of buffer private storage */
798c2ecf20Sopenharmony_ci	void *dev_private;		 /**< Per-buffer private storage */
808c2ecf20Sopenharmony_ci};
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_citypedef struct drm_dma_handle {
838c2ecf20Sopenharmony_ci	dma_addr_t busaddr;
848c2ecf20Sopenharmony_ci	void *vaddr;
858c2ecf20Sopenharmony_ci	size_t size;
868c2ecf20Sopenharmony_ci} drm_dma_handle_t;
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci/**
898c2ecf20Sopenharmony_ci * Buffer entry.  There is one of this for each buffer size order.
908c2ecf20Sopenharmony_ci */
918c2ecf20Sopenharmony_cistruct drm_buf_entry {
928c2ecf20Sopenharmony_ci	int buf_size;			/**< size */
938c2ecf20Sopenharmony_ci	int buf_count;			/**< number of buffers */
948c2ecf20Sopenharmony_ci	struct drm_buf *buflist;		/**< buffer list */
958c2ecf20Sopenharmony_ci	int seg_count;
968c2ecf20Sopenharmony_ci	int page_order;
978c2ecf20Sopenharmony_ci	struct drm_dma_handle **seglist;
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci	int low_mark;			/**< Low water mark */
1008c2ecf20Sopenharmony_ci	int high_mark;			/**< High water mark */
1018c2ecf20Sopenharmony_ci};
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci/**
1048c2ecf20Sopenharmony_ci * DMA data.
1058c2ecf20Sopenharmony_ci */
1068c2ecf20Sopenharmony_cistruct drm_device_dma {
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci	struct drm_buf_entry bufs[DRM_MAX_ORDER + 1];	/**< buffers, grouped by their size order */
1098c2ecf20Sopenharmony_ci	int buf_count;			/**< total number of buffers */
1108c2ecf20Sopenharmony_ci	struct drm_buf **buflist;		/**< Vector of pointers into drm_device_dma::bufs */
1118c2ecf20Sopenharmony_ci	int seg_count;
1128c2ecf20Sopenharmony_ci	int page_count;			/**< number of pages */
1138c2ecf20Sopenharmony_ci	unsigned long *pagelist;	/**< page list */
1148c2ecf20Sopenharmony_ci	unsigned long byte_count;
1158c2ecf20Sopenharmony_ci	enum {
1168c2ecf20Sopenharmony_ci		_DRM_DMA_USE_AGP = 0x01,
1178c2ecf20Sopenharmony_ci		_DRM_DMA_USE_SG = 0x02,
1188c2ecf20Sopenharmony_ci		_DRM_DMA_USE_FB = 0x04,
1198c2ecf20Sopenharmony_ci		_DRM_DMA_USE_PCI_RO = 0x08
1208c2ecf20Sopenharmony_ci	} flags;
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_ci};
1238c2ecf20Sopenharmony_ci
1248c2ecf20Sopenharmony_ci/**
1258c2ecf20Sopenharmony_ci * Scatter-gather memory.
1268c2ecf20Sopenharmony_ci */
1278c2ecf20Sopenharmony_cistruct drm_sg_mem {
1288c2ecf20Sopenharmony_ci	unsigned long handle;
1298c2ecf20Sopenharmony_ci	void *virtual;
1308c2ecf20Sopenharmony_ci	int pages;
1318c2ecf20Sopenharmony_ci	struct page **pagelist;
1328c2ecf20Sopenharmony_ci	dma_addr_t *busaddr;
1338c2ecf20Sopenharmony_ci};
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ci/**
1368c2ecf20Sopenharmony_ci * Kernel side of a mapping
1378c2ecf20Sopenharmony_ci */
1388c2ecf20Sopenharmony_cistruct drm_local_map {
1398c2ecf20Sopenharmony_ci	dma_addr_t offset;	 /**< Requested physical address (0 for SAREA)*/
1408c2ecf20Sopenharmony_ci	unsigned long size;	 /**< Requested physical size (bytes) */
1418c2ecf20Sopenharmony_ci	enum drm_map_type type;	 /**< Type of memory to map */
1428c2ecf20Sopenharmony_ci	enum drm_map_flags flags;	 /**< Flags */
1438c2ecf20Sopenharmony_ci	void *handle;		 /**< User-space: "Handle" to pass to mmap() */
1448c2ecf20Sopenharmony_ci				 /**< Kernel-space: kernel-virtual address */
1458c2ecf20Sopenharmony_ci	int mtrr;		 /**< MTRR slot used */
1468c2ecf20Sopenharmony_ci};
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_citypedef struct drm_local_map drm_local_map_t;
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ci/**
1518c2ecf20Sopenharmony_ci * Mappings list
1528c2ecf20Sopenharmony_ci */
1538c2ecf20Sopenharmony_cistruct drm_map_list {
1548c2ecf20Sopenharmony_ci	struct list_head head;		/**< list head */
1558c2ecf20Sopenharmony_ci	struct drm_hash_item hash;
1568c2ecf20Sopenharmony_ci	struct drm_local_map *map;	/**< mapping */
1578c2ecf20Sopenharmony_ci	uint64_t user_token;
1588c2ecf20Sopenharmony_ci	struct drm_master *master;
1598c2ecf20Sopenharmony_ci};
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_ciint drm_legacy_addmap(struct drm_device *d, resource_size_t offset,
1628c2ecf20Sopenharmony_ci		      unsigned int size, enum drm_map_type type,
1638c2ecf20Sopenharmony_ci		      enum drm_map_flags flags, struct drm_local_map **map_p);
1648c2ecf20Sopenharmony_cistruct drm_local_map *drm_legacy_findmap(struct drm_device *dev, unsigned int token);
1658c2ecf20Sopenharmony_civoid drm_legacy_rmmap(struct drm_device *d, struct drm_local_map *map);
1668c2ecf20Sopenharmony_ciint drm_legacy_rmmap_locked(struct drm_device *d, struct drm_local_map *map);
1678c2ecf20Sopenharmony_cistruct drm_local_map *drm_legacy_getsarea(struct drm_device *dev);
1688c2ecf20Sopenharmony_ciint drm_legacy_mmap(struct file *filp, struct vm_area_struct *vma);
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_ciint drm_legacy_addbufs_agp(struct drm_device *d, struct drm_buf_desc *req);
1718c2ecf20Sopenharmony_ciint drm_legacy_addbufs_pci(struct drm_device *d, struct drm_buf_desc *req);
1728c2ecf20Sopenharmony_ci
1738c2ecf20Sopenharmony_ci/**
1748c2ecf20Sopenharmony_ci * Test that the hardware lock is held by the caller, returning otherwise.
1758c2ecf20Sopenharmony_ci *
1768c2ecf20Sopenharmony_ci * \param dev DRM device.
1778c2ecf20Sopenharmony_ci * \param filp file pointer of the caller.
1788c2ecf20Sopenharmony_ci */
1798c2ecf20Sopenharmony_ci#define LOCK_TEST_WITH_RETURN( dev, _file_priv )				\
1808c2ecf20Sopenharmony_cido {										\
1818c2ecf20Sopenharmony_ci	if (!_DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock) ||	\
1828c2ecf20Sopenharmony_ci	    _file_priv->master->lock.file_priv != _file_priv)	{		\
1838c2ecf20Sopenharmony_ci		DRM_ERROR( "%s called without lock held, held  %d owner %p %p\n",\
1848c2ecf20Sopenharmony_ci			   __func__, _DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock),\
1858c2ecf20Sopenharmony_ci			   _file_priv->master->lock.file_priv, _file_priv);	\
1868c2ecf20Sopenharmony_ci		return -EINVAL;							\
1878c2ecf20Sopenharmony_ci	}									\
1888c2ecf20Sopenharmony_ci} while (0)
1898c2ecf20Sopenharmony_ci
1908c2ecf20Sopenharmony_civoid drm_legacy_idlelock_take(struct drm_lock_data *lock);
1918c2ecf20Sopenharmony_civoid drm_legacy_idlelock_release(struct drm_lock_data *lock);
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_ci/* drm_pci.c */
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_ci#ifdef CONFIG_PCI
1968c2ecf20Sopenharmony_ci
1978c2ecf20Sopenharmony_cistruct drm_dma_handle *drm_pci_alloc(struct drm_device *dev, size_t size,
1988c2ecf20Sopenharmony_ci				     size_t align);
1998c2ecf20Sopenharmony_civoid drm_pci_free(struct drm_device *dev, struct drm_dma_handle *dmah);
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_ciint drm_legacy_pci_init(struct drm_driver *driver, struct pci_driver *pdriver);
2028c2ecf20Sopenharmony_civoid drm_legacy_pci_exit(struct drm_driver *driver, struct pci_driver *pdriver);
2038c2ecf20Sopenharmony_ci
2048c2ecf20Sopenharmony_ci#else
2058c2ecf20Sopenharmony_ci
2068c2ecf20Sopenharmony_cistatic inline struct drm_dma_handle *drm_pci_alloc(struct drm_device *dev,
2078c2ecf20Sopenharmony_ci						   size_t size, size_t align)
2088c2ecf20Sopenharmony_ci{
2098c2ecf20Sopenharmony_ci	return NULL;
2108c2ecf20Sopenharmony_ci}
2118c2ecf20Sopenharmony_ci
2128c2ecf20Sopenharmony_cistatic inline void drm_pci_free(struct drm_device *dev,
2138c2ecf20Sopenharmony_ci				struct drm_dma_handle *dmah)
2148c2ecf20Sopenharmony_ci{
2158c2ecf20Sopenharmony_ci}
2168c2ecf20Sopenharmony_ci
2178c2ecf20Sopenharmony_cistatic inline int drm_legacy_pci_init(struct drm_driver *driver,
2188c2ecf20Sopenharmony_ci				      struct pci_driver *pdriver)
2198c2ecf20Sopenharmony_ci{
2208c2ecf20Sopenharmony_ci	return -EINVAL;
2218c2ecf20Sopenharmony_ci}
2228c2ecf20Sopenharmony_ci
2238c2ecf20Sopenharmony_cistatic inline void drm_legacy_pci_exit(struct drm_driver *driver,
2248c2ecf20Sopenharmony_ci				       struct pci_driver *pdriver)
2258c2ecf20Sopenharmony_ci{
2268c2ecf20Sopenharmony_ci}
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_ci#endif
2298c2ecf20Sopenharmony_ci
2308c2ecf20Sopenharmony_ci/* drm_memory.c */
2318c2ecf20Sopenharmony_civoid drm_legacy_ioremap(struct drm_local_map *map, struct drm_device *dev);
2328c2ecf20Sopenharmony_civoid drm_legacy_ioremap_wc(struct drm_local_map *map, struct drm_device *dev);
2338c2ecf20Sopenharmony_civoid drm_legacy_ioremapfree(struct drm_local_map *map, struct drm_device *dev);
2348c2ecf20Sopenharmony_ci
2358c2ecf20Sopenharmony_ci#endif /* __DRM_DRM_LEGACY_H__ */
236