162306a36Sopenharmony_ci#ifndef __DRM_LEGACY_H__
262306a36Sopenharmony_ci#define __DRM_LEGACY_H__
362306a36Sopenharmony_ci
462306a36Sopenharmony_ci/*
562306a36Sopenharmony_ci * Copyright (c) 2014 David Herrmann <dh.herrmann@gmail.com>
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
862306a36Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
962306a36Sopenharmony_ci * to deal in the Software without restriction, including without limitation
1062306a36Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
1162306a36Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
1262306a36Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
1362306a36Sopenharmony_ci *
1462306a36Sopenharmony_ci * The above copyright notice and this permission notice shall be included in
1562306a36Sopenharmony_ci * all copies or substantial portions of the Software.
1662306a36Sopenharmony_ci *
1762306a36Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1862306a36Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1962306a36Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
2062306a36Sopenharmony_ci * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
2162306a36Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
2262306a36Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
2362306a36Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE.
2462306a36Sopenharmony_ci */
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci/*
2762306a36Sopenharmony_ci * This file contains legacy interfaces that modern drm drivers
2862306a36Sopenharmony_ci * should no longer be using. They cannot be removed as legacy
2962306a36Sopenharmony_ci * drivers use them, and removing them are API breaks.
3062306a36Sopenharmony_ci */
3162306a36Sopenharmony_ci#include <linux/list.h>
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ci#include <drm/drm.h>
3462306a36Sopenharmony_ci#include <drm/drm_device.h>
3562306a36Sopenharmony_ci#include <drm/drm_legacy.h>
3662306a36Sopenharmony_ci
3762306a36Sopenharmony_cistruct agp_memory;
3862306a36Sopenharmony_cistruct drm_buf_desc;
3962306a36Sopenharmony_cistruct drm_device;
4062306a36Sopenharmony_cistruct drm_file;
4162306a36Sopenharmony_cistruct drm_hash_item;
4262306a36Sopenharmony_cistruct drm_open_hash;
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_ci/*
4562306a36Sopenharmony_ci * Hash-table Support
4662306a36Sopenharmony_ci */
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ci#define drm_hash_entry(_ptr, _type, _member) container_of(_ptr, _type, _member)
4962306a36Sopenharmony_ci
5062306a36Sopenharmony_ci/* drm_hashtab.c */
5162306a36Sopenharmony_ci#if IS_ENABLED(CONFIG_DRM_LEGACY)
5262306a36Sopenharmony_ciint drm_ht_create(struct drm_open_hash *ht, unsigned int order);
5362306a36Sopenharmony_ciint drm_ht_insert_item(struct drm_open_hash *ht, struct drm_hash_item *item);
5462306a36Sopenharmony_ciint drm_ht_just_insert_please(struct drm_open_hash *ht, struct drm_hash_item *item,
5562306a36Sopenharmony_ci			      unsigned long seed, int bits, int shift,
5662306a36Sopenharmony_ci			      unsigned long add);
5762306a36Sopenharmony_ciint drm_ht_find_item(struct drm_open_hash *ht, unsigned long key, struct drm_hash_item **item);
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_civoid drm_ht_verbose_list(struct drm_open_hash *ht, unsigned long key);
6062306a36Sopenharmony_ciint drm_ht_remove_key(struct drm_open_hash *ht, unsigned long key);
6162306a36Sopenharmony_ciint drm_ht_remove_item(struct drm_open_hash *ht, struct drm_hash_item *item);
6262306a36Sopenharmony_civoid drm_ht_remove(struct drm_open_hash *ht);
6362306a36Sopenharmony_ci#endif
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ci/*
6662306a36Sopenharmony_ci * RCU-safe interface
6762306a36Sopenharmony_ci *
6862306a36Sopenharmony_ci * The user of this API needs to make sure that two or more instances of the
6962306a36Sopenharmony_ci * hash table manipulation functions are never run simultaneously.
7062306a36Sopenharmony_ci * The lookup function drm_ht_find_item_rcu may, however, run simultaneously
7162306a36Sopenharmony_ci * with any of the manipulation functions as long as it's called from within
7262306a36Sopenharmony_ci * an RCU read-locked section.
7362306a36Sopenharmony_ci */
7462306a36Sopenharmony_ci#define drm_ht_insert_item_rcu drm_ht_insert_item
7562306a36Sopenharmony_ci#define drm_ht_just_insert_please_rcu drm_ht_just_insert_please
7662306a36Sopenharmony_ci#define drm_ht_remove_key_rcu drm_ht_remove_key
7762306a36Sopenharmony_ci#define drm_ht_remove_item_rcu drm_ht_remove_item
7862306a36Sopenharmony_ci#define drm_ht_find_item_rcu drm_ht_find_item
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_ci/*
8162306a36Sopenharmony_ci * Generic DRM Contexts
8262306a36Sopenharmony_ci */
8362306a36Sopenharmony_ci
8462306a36Sopenharmony_ci#define DRM_KERNEL_CONTEXT		0
8562306a36Sopenharmony_ci#define DRM_RESERVED_CONTEXTS		1
8662306a36Sopenharmony_ci
8762306a36Sopenharmony_ci#if IS_ENABLED(CONFIG_DRM_LEGACY)
8862306a36Sopenharmony_civoid drm_legacy_ctxbitmap_init(struct drm_device *dev);
8962306a36Sopenharmony_civoid drm_legacy_ctxbitmap_cleanup(struct drm_device *dev);
9062306a36Sopenharmony_civoid drm_legacy_ctxbitmap_flush(struct drm_device *dev, struct drm_file *file);
9162306a36Sopenharmony_ci#else
9262306a36Sopenharmony_cistatic inline void drm_legacy_ctxbitmap_init(struct drm_device *dev) {}
9362306a36Sopenharmony_cistatic inline void drm_legacy_ctxbitmap_cleanup(struct drm_device *dev) {}
9462306a36Sopenharmony_cistatic inline void drm_legacy_ctxbitmap_flush(struct drm_device *dev, struct drm_file *file) {}
9562306a36Sopenharmony_ci#endif
9662306a36Sopenharmony_ci
9762306a36Sopenharmony_civoid drm_legacy_ctxbitmap_free(struct drm_device *dev, int ctx_handle);
9862306a36Sopenharmony_ci
9962306a36Sopenharmony_ci#if IS_ENABLED(CONFIG_DRM_LEGACY)
10062306a36Sopenharmony_ciint drm_legacy_resctx(struct drm_device *d, void *v, struct drm_file *f);
10162306a36Sopenharmony_ciint drm_legacy_addctx(struct drm_device *d, void *v, struct drm_file *f);
10262306a36Sopenharmony_ciint drm_legacy_getctx(struct drm_device *d, void *v, struct drm_file *f);
10362306a36Sopenharmony_ciint drm_legacy_switchctx(struct drm_device *d, void *v, struct drm_file *f);
10462306a36Sopenharmony_ciint drm_legacy_newctx(struct drm_device *d, void *v, struct drm_file *f);
10562306a36Sopenharmony_ciint drm_legacy_rmctx(struct drm_device *d, void *v, struct drm_file *f);
10662306a36Sopenharmony_ci
10762306a36Sopenharmony_ciint drm_legacy_setsareactx(struct drm_device *d, void *v, struct drm_file *f);
10862306a36Sopenharmony_ciint drm_legacy_getsareactx(struct drm_device *d, void *v, struct drm_file *f);
10962306a36Sopenharmony_ci#endif
11062306a36Sopenharmony_ci
11162306a36Sopenharmony_ci/*
11262306a36Sopenharmony_ci * Generic Buffer Management
11362306a36Sopenharmony_ci */
11462306a36Sopenharmony_ci
11562306a36Sopenharmony_ci#define DRM_MAP_HASH_OFFSET 0x10000000
11662306a36Sopenharmony_ci
11762306a36Sopenharmony_ci#if IS_ENABLED(CONFIG_DRM_LEGACY)
11862306a36Sopenharmony_cistatic inline int drm_legacy_create_map_hash(struct drm_device *dev)
11962306a36Sopenharmony_ci{
12062306a36Sopenharmony_ci	return drm_ht_create(&dev->map_hash, 12);
12162306a36Sopenharmony_ci}
12262306a36Sopenharmony_ci
12362306a36Sopenharmony_cistatic inline void drm_legacy_remove_map_hash(struct drm_device *dev)
12462306a36Sopenharmony_ci{
12562306a36Sopenharmony_ci	drm_ht_remove(&dev->map_hash);
12662306a36Sopenharmony_ci}
12762306a36Sopenharmony_ci#else
12862306a36Sopenharmony_cistatic inline int drm_legacy_create_map_hash(struct drm_device *dev)
12962306a36Sopenharmony_ci{
13062306a36Sopenharmony_ci	return 0;
13162306a36Sopenharmony_ci}
13262306a36Sopenharmony_ci
13362306a36Sopenharmony_cistatic inline void drm_legacy_remove_map_hash(struct drm_device *dev) {}
13462306a36Sopenharmony_ci#endif
13562306a36Sopenharmony_ci
13662306a36Sopenharmony_ci
13762306a36Sopenharmony_ci#if IS_ENABLED(CONFIG_DRM_LEGACY)
13862306a36Sopenharmony_ciint drm_legacy_getmap_ioctl(struct drm_device *dev, void *data,
13962306a36Sopenharmony_ci			    struct drm_file *file_priv);
14062306a36Sopenharmony_ciint drm_legacy_addmap_ioctl(struct drm_device *d, void *v, struct drm_file *f);
14162306a36Sopenharmony_ciint drm_legacy_rmmap_ioctl(struct drm_device *d, void *v, struct drm_file *f);
14262306a36Sopenharmony_ci
14362306a36Sopenharmony_ciint drm_legacy_addbufs(struct drm_device *d, void *v, struct drm_file *f);
14462306a36Sopenharmony_ciint drm_legacy_infobufs(struct drm_device *d, void *v, struct drm_file *f);
14562306a36Sopenharmony_ciint drm_legacy_markbufs(struct drm_device *d, void *v, struct drm_file *f);
14662306a36Sopenharmony_ciint drm_legacy_freebufs(struct drm_device *d, void *v, struct drm_file *f);
14762306a36Sopenharmony_ciint drm_legacy_mapbufs(struct drm_device *d, void *v, struct drm_file *f);
14862306a36Sopenharmony_ciint drm_legacy_dma_ioctl(struct drm_device *d, void *v, struct drm_file *f);
14962306a36Sopenharmony_ci#endif
15062306a36Sopenharmony_ci
15162306a36Sopenharmony_ciint __drm_legacy_infobufs(struct drm_device *, void *, int *,
15262306a36Sopenharmony_ci			  int (*)(void *, int, struct drm_buf_entry *));
15362306a36Sopenharmony_ciint __drm_legacy_mapbufs(struct drm_device *, void *, int *,
15462306a36Sopenharmony_ci			  void __user **,
15562306a36Sopenharmony_ci			  int (*)(void *, int, unsigned long, struct drm_buf *),
15662306a36Sopenharmony_ci			  struct drm_file *);
15762306a36Sopenharmony_ci
15862306a36Sopenharmony_ci#if IS_ENABLED(CONFIG_DRM_LEGACY)
15962306a36Sopenharmony_civoid drm_legacy_master_rmmaps(struct drm_device *dev,
16062306a36Sopenharmony_ci			      struct drm_master *master);
16162306a36Sopenharmony_civoid drm_legacy_rmmaps(struct drm_device *dev);
16262306a36Sopenharmony_ci#else
16362306a36Sopenharmony_cistatic inline void drm_legacy_master_rmmaps(struct drm_device *dev,
16462306a36Sopenharmony_ci					    struct drm_master *master) {}
16562306a36Sopenharmony_cistatic inline void drm_legacy_rmmaps(struct drm_device *dev) {}
16662306a36Sopenharmony_ci#endif
16762306a36Sopenharmony_ci
16862306a36Sopenharmony_ci#if IS_ENABLED(CONFIG_DRM_LEGACY)
16962306a36Sopenharmony_civoid drm_legacy_vma_flush(struct drm_device *d);
17062306a36Sopenharmony_ci#else
17162306a36Sopenharmony_cistatic inline void drm_legacy_vma_flush(struct drm_device *d)
17262306a36Sopenharmony_ci{
17362306a36Sopenharmony_ci	/* do nothing */
17462306a36Sopenharmony_ci}
17562306a36Sopenharmony_ci#endif
17662306a36Sopenharmony_ci
17762306a36Sopenharmony_ci/*
17862306a36Sopenharmony_ci * AGP Support
17962306a36Sopenharmony_ci */
18062306a36Sopenharmony_ci
18162306a36Sopenharmony_cistruct drm_agp_mem {
18262306a36Sopenharmony_ci	unsigned long handle;
18362306a36Sopenharmony_ci	struct agp_memory *memory;
18462306a36Sopenharmony_ci	unsigned long bound;
18562306a36Sopenharmony_ci	int pages;
18662306a36Sopenharmony_ci	struct list_head head;
18762306a36Sopenharmony_ci};
18862306a36Sopenharmony_ci
18962306a36Sopenharmony_ci/* drm_agpsupport.c */
19062306a36Sopenharmony_ci#if IS_ENABLED(CONFIG_DRM_LEGACY) && IS_ENABLED(CONFIG_AGP)
19162306a36Sopenharmony_civoid drm_legacy_agp_clear(struct drm_device *dev);
19262306a36Sopenharmony_ci
19362306a36Sopenharmony_ciint drm_legacy_agp_acquire_ioctl(struct drm_device *dev, void *data,
19462306a36Sopenharmony_ci				 struct drm_file *file_priv);
19562306a36Sopenharmony_ciint drm_legacy_agp_release_ioctl(struct drm_device *dev, void *data,
19662306a36Sopenharmony_ci				 struct drm_file *file_priv);
19762306a36Sopenharmony_ciint drm_legacy_agp_enable_ioctl(struct drm_device *dev, void *data,
19862306a36Sopenharmony_ci				struct drm_file *file_priv);
19962306a36Sopenharmony_ciint drm_legacy_agp_info_ioctl(struct drm_device *dev, void *data,
20062306a36Sopenharmony_ci			      struct drm_file *file_priv);
20162306a36Sopenharmony_ciint drm_legacy_agp_alloc_ioctl(struct drm_device *dev, void *data,
20262306a36Sopenharmony_ci			       struct drm_file *file_priv);
20362306a36Sopenharmony_ciint drm_legacy_agp_free_ioctl(struct drm_device *dev, void *data,
20462306a36Sopenharmony_ci			      struct drm_file *file_priv);
20562306a36Sopenharmony_ciint drm_legacy_agp_unbind_ioctl(struct drm_device *dev, void *data,
20662306a36Sopenharmony_ci				struct drm_file *file_priv);
20762306a36Sopenharmony_ciint drm_legacy_agp_bind_ioctl(struct drm_device *dev, void *data,
20862306a36Sopenharmony_ci			      struct drm_file *file_priv);
20962306a36Sopenharmony_ci#else
21062306a36Sopenharmony_cistatic inline void drm_legacy_agp_clear(struct drm_device *dev) {}
21162306a36Sopenharmony_ci#endif
21262306a36Sopenharmony_ci
21362306a36Sopenharmony_ci/* drm_lock.c */
21462306a36Sopenharmony_ci#if IS_ENABLED(CONFIG_DRM_LEGACY)
21562306a36Sopenharmony_ciint drm_legacy_lock(struct drm_device *d, void *v, struct drm_file *f);
21662306a36Sopenharmony_ciint drm_legacy_unlock(struct drm_device *d, void *v, struct drm_file *f);
21762306a36Sopenharmony_civoid drm_legacy_lock_release(struct drm_device *dev, struct file *filp);
21862306a36Sopenharmony_ci#else
21962306a36Sopenharmony_cistatic inline void drm_legacy_lock_release(struct drm_device *dev, struct file *filp) {}
22062306a36Sopenharmony_ci#endif
22162306a36Sopenharmony_ci
22262306a36Sopenharmony_ci/* DMA support */
22362306a36Sopenharmony_ci#if IS_ENABLED(CONFIG_DRM_LEGACY)
22462306a36Sopenharmony_ciint drm_legacy_dma_setup(struct drm_device *dev);
22562306a36Sopenharmony_civoid drm_legacy_dma_takedown(struct drm_device *dev);
22662306a36Sopenharmony_ci#else
22762306a36Sopenharmony_cistatic inline int drm_legacy_dma_setup(struct drm_device *dev)
22862306a36Sopenharmony_ci{
22962306a36Sopenharmony_ci	return 0;
23062306a36Sopenharmony_ci}
23162306a36Sopenharmony_ci#endif
23262306a36Sopenharmony_ci
23362306a36Sopenharmony_civoid drm_legacy_free_buffer(struct drm_device *dev,
23462306a36Sopenharmony_ci			    struct drm_buf * buf);
23562306a36Sopenharmony_ci#if IS_ENABLED(CONFIG_DRM_LEGACY)
23662306a36Sopenharmony_civoid drm_legacy_reclaim_buffers(struct drm_device *dev,
23762306a36Sopenharmony_ci				struct drm_file *filp);
23862306a36Sopenharmony_ci#else
23962306a36Sopenharmony_cistatic inline void drm_legacy_reclaim_buffers(struct drm_device *dev,
24062306a36Sopenharmony_ci					      struct drm_file *filp) {}
24162306a36Sopenharmony_ci#endif
24262306a36Sopenharmony_ci
24362306a36Sopenharmony_ci/* Scatter Gather Support */
24462306a36Sopenharmony_ci#if IS_ENABLED(CONFIG_DRM_LEGACY)
24562306a36Sopenharmony_civoid drm_legacy_sg_cleanup(struct drm_device *dev);
24662306a36Sopenharmony_ciint drm_legacy_sg_alloc(struct drm_device *dev, void *data,
24762306a36Sopenharmony_ci			struct drm_file *file_priv);
24862306a36Sopenharmony_ciint drm_legacy_sg_free(struct drm_device *dev, void *data,
24962306a36Sopenharmony_ci		       struct drm_file *file_priv);
25062306a36Sopenharmony_ci#endif
25162306a36Sopenharmony_ci
25262306a36Sopenharmony_ci#if IS_ENABLED(CONFIG_DRM_LEGACY)
25362306a36Sopenharmony_civoid drm_legacy_init_members(struct drm_device *dev);
25462306a36Sopenharmony_civoid drm_legacy_destroy_members(struct drm_device *dev);
25562306a36Sopenharmony_civoid drm_legacy_dev_reinit(struct drm_device *dev);
25662306a36Sopenharmony_ciint drm_legacy_setup(struct drm_device * dev);
25762306a36Sopenharmony_ci#else
25862306a36Sopenharmony_cistatic inline void drm_legacy_init_members(struct drm_device *dev) {}
25962306a36Sopenharmony_cistatic inline void drm_legacy_destroy_members(struct drm_device *dev) {}
26062306a36Sopenharmony_cistatic inline void drm_legacy_dev_reinit(struct drm_device *dev) {}
26162306a36Sopenharmony_cistatic inline int drm_legacy_setup(struct drm_device * dev) { return 0; }
26262306a36Sopenharmony_ci#endif
26362306a36Sopenharmony_ci
26462306a36Sopenharmony_ci#if IS_ENABLED(CONFIG_DRM_LEGACY)
26562306a36Sopenharmony_civoid drm_legacy_lock_master_cleanup(struct drm_device *dev, struct drm_master *master);
26662306a36Sopenharmony_ci#else
26762306a36Sopenharmony_cistatic inline void drm_legacy_lock_master_cleanup(struct drm_device *dev, struct drm_master *master) {}
26862306a36Sopenharmony_ci#endif
26962306a36Sopenharmony_ci
27062306a36Sopenharmony_ci#if IS_ENABLED(CONFIG_DRM_LEGACY)
27162306a36Sopenharmony_civoid drm_master_legacy_init(struct drm_master *master);
27262306a36Sopenharmony_ci#else
27362306a36Sopenharmony_cistatic inline void drm_master_legacy_init(struct drm_master *master) {}
27462306a36Sopenharmony_ci#endif
27562306a36Sopenharmony_ci
27662306a36Sopenharmony_ci/* drm_pci.c */
27762306a36Sopenharmony_ci#if IS_ENABLED(CONFIG_DRM_LEGACY) && IS_ENABLED(CONFIG_PCI)
27862306a36Sopenharmony_ciint drm_legacy_irq_by_busid(struct drm_device *dev, void *data, struct drm_file *file_priv);
27962306a36Sopenharmony_civoid drm_legacy_pci_agp_destroy(struct drm_device *dev);
28062306a36Sopenharmony_ci#else
28162306a36Sopenharmony_cistatic inline int drm_legacy_irq_by_busid(struct drm_device *dev, void *data,
28262306a36Sopenharmony_ci					  struct drm_file *file_priv)
28362306a36Sopenharmony_ci{
28462306a36Sopenharmony_ci	return -EINVAL;
28562306a36Sopenharmony_ci}
28662306a36Sopenharmony_ci
28762306a36Sopenharmony_cistatic inline void drm_legacy_pci_agp_destroy(struct drm_device *dev) {}
28862306a36Sopenharmony_ci#endif
28962306a36Sopenharmony_ci
29062306a36Sopenharmony_ci#endif /* __DRM_LEGACY_H__ */
291