File Index
Files and directories
Sign in
FILE

panfrost_gem.h

File preview with syntax highlighting.

linux-6.19.14/drivers/gpu/drm/panfrost/panfrost_gem.h C
  1/* SPDX-License-Identifier: GPL-2.0 */
  2/* Copyright 2019 Linaro, Ltd, Rob Herring <robh@kernel.org> */
  3
  4#ifndef __PANFROST_GEM_H__
  5#define __PANFROST_GEM_H__
  6
  7#include <drm/drm_gem_shmem_helper.h>
  8#include <drm/drm_mm.h>
  9
 10struct panfrost_mmu;
 11struct panfrost_device;
 12
 13#define PANFROST_BO_LABEL_MAXLEN	4096
 14
 15enum panfrost_debugfs_gem_state_flags {
 16	/** @PANFROST_DEBUGFS_GEM_STATE_FLAG_IMPORTED: GEM BO is PRIME imported. */
 17	PANFROST_DEBUGFS_GEM_STATE_FLAG_IMPORTED = BIT(0),
 18
 19	/** @PANFROST_DEBUGFS_GEM_STATE_FLAG_EXPORTED: GEM BO is PRIME exported. */
 20	PANFROST_DEBUGFS_GEM_STATE_FLAG_EXPORTED = BIT(1),
 21
 22	/** @PANFROST_DEBUGFS_GEM_STATE_FLAG_PURGED: GEM BO was reclaimed by the shrinker. */
 23	PANFROST_DEBUGFS_GEM_STATE_FLAG_PURGED = BIT(2),
 24
 25	/**
 26	 * @PANFROST_DEBUGFS_GEM_STATE_FLAG_PURGEABLE: GEM BO pages were marked as no longer
 27	 * needed by UM and can be reclaimed by the shrinker.
 28	 */
 29	PANFROST_DEBUGFS_GEM_STATE_FLAG_PURGEABLE = BIT(3),
 30};
 31
 32/**
 33 * struct panfrost_gem_debugfs - GEM object's DebugFS list information
 34 */
 35struct panfrost_gem_debugfs {
 36	/**
 37	 * @node: Node used to insert the object in the device-wide list of
 38	 * GEM objects, to display information about it through a DebugFS file.
 39	 */
 40	struct list_head node;
 41
 42	/** @creator: Information about the UM process which created the GEM. */
 43	struct {
 44		/** @creator.process_name: Group leader name in owning thread's process */
 45		char process_name[TASK_COMM_LEN];
 46
 47		/** @creator.tgid: PID of the thread's group leader within its process */
 48		pid_t tgid;
 49	} creator;
 50};
 51
 52struct panfrost_gem_object {
 53	struct drm_gem_shmem_object base;
 54	struct sg_table *sgts;
 55
 56	/*
 57	 * Use a list for now. If searching a mapping ever becomes the
 58	 * bottleneck, we should consider using an RB-tree, or even better,
 59	 * let the core store drm_gem_object_mapping entries (where we
 60	 * could place driver specific data) instead of drm_gem_object ones
 61	 * in its drm_file->object_idr table.
 62	 *
 63	 * struct drm_gem_object_mapping {
 64	 *	struct drm_gem_object *obj;
 65	 *	void *driver_priv;
 66	 * };
 67	 */
 68	struct {
 69		struct list_head list;
 70		struct mutex lock;
 71	} mappings;
 72
 73	/*
 74	 * Count the number of jobs referencing this BO so we don't let the
 75	 * shrinker reclaim this object prematurely.
 76	 */
 77	atomic_t gpu_usecount;
 78
 79	/*
 80	 * Object chunk size currently mapped onto physical memory
 81	 */
 82	size_t heap_rss_size;
 83
 84	/**
 85	 * @label: BO tagging fields. The label can be assigned within the
 86	 * driver itself or through a specific IOCTL.
 87	 */
 88	struct {
 89		/**
 90		 * @label.str: Pointer to NULL-terminated string,
 91		 */
 92		const char *str;
 93
 94		/** @lock.str: Protects access to the @label.str field. */
 95		struct mutex lock;
 96	} label;
 97
 98	bool noexec		:1;
 99	bool is_heap		:1;
100
101#ifdef CONFIG_DEBUG_FS
102	struct panfrost_gem_debugfs debugfs;
103#endif
104};
105
106struct panfrost_gem_mapping {
107	struct list_head node;
108	struct kref refcount;
109	struct panfrost_gem_object *obj;
110	struct drm_mm_node mmnode;
111	struct panfrost_mmu *mmu;
112	bool active		:1;
113};
114
115static inline
116struct  panfrost_gem_object *to_panfrost_bo(struct drm_gem_object *obj)
117{
118	return container_of(to_drm_gem_shmem_obj(obj), struct panfrost_gem_object, base);
119}
120
121static inline struct panfrost_gem_mapping *
122drm_mm_node_to_panfrost_mapping(struct drm_mm_node *node)
123{
124	return container_of(node, struct panfrost_gem_mapping, mmnode);
125}
126
127struct drm_gem_object *panfrost_gem_create_object(struct drm_device *dev, size_t size);
128
129struct drm_gem_object *
130panfrost_gem_prime_import_sg_table(struct drm_device *dev,
131				   struct dma_buf_attachment *attach,
132				   struct sg_table *sgt);
133
134struct panfrost_gem_object *
135panfrost_gem_create(struct drm_device *dev, size_t size, u32 flags);
136
137int panfrost_gem_open(struct drm_gem_object *obj, struct drm_file *file_priv);
138void panfrost_gem_close(struct drm_gem_object *obj,
139			struct drm_file *file_priv);
140
141struct panfrost_gem_mapping *
142panfrost_gem_mapping_get(struct panfrost_gem_object *bo,
143			 struct panfrost_file_priv *priv);
144void panfrost_gem_mapping_put(struct panfrost_gem_mapping *mapping);
145void panfrost_gem_teardown_mappings_locked(struct panfrost_gem_object *bo);
146
147int panfrost_gem_shrinker_init(struct drm_device *dev);
148void panfrost_gem_shrinker_cleanup(struct drm_device *dev);
149
150void panfrost_gem_set_label(struct drm_gem_object *obj, const char *label);
151void panfrost_gem_internal_set_label(struct drm_gem_object *obj, const char *label);
152
153#ifdef CONFIG_DEBUG_FS
154void panfrost_gem_debugfs_print_bos(struct panfrost_device *pfdev,
155				    struct seq_file *m);
156#endif
157
158#endif /* __PANFROST_GEM_H__ */
~/ Read-only file preview.