Linux Audio

Check our new training course

Loading...
v6.8
  1/* SPDX-License-Identifier: GPL-2.0 */
  2/*
  3 * Copyright (C) 2015-2018 Etnaviv Project
 
 
 
 
 
 
 
 
 
 
 
 
  4 */
  5
  6#ifndef __ETNAVIV_DRV_H__
  7#define __ETNAVIV_DRV_H__
  8
  9#include <linux/io.h>
 
 
 
 
 
 
 
 10#include <linux/list.h>
 11#include <linux/mm_types.h>
 12#include <linux/sizes.h>
 13#include <linux/time64.h>
 14#include <linux/types.h>
 15#include <linux/xarray.h>
 16
 17#include <drm/drm_drv.h>
 
 
 18#include <drm/drm_gem.h>
 19#include <drm/etnaviv_drm.h>
 20#include <drm/gpu_scheduler.h>
 21
 22struct etnaviv_cmdbuf;
 23struct etnaviv_gpu;
 24struct etnaviv_mmu;
 25struct etnaviv_gem_object;
 26struct etnaviv_gem_submit;
 27struct etnaviv_iommu_global;
 28
 29#define ETNAVIV_SOFTPIN_START_ADDRESS	SZ_4M /* must be >= SUBALLOC_SIZE */
 30
 31struct etnaviv_file_private {
 32	int id;
 33	struct etnaviv_iommu_context	*mmu;
 34	struct drm_sched_entity		sched_entity[ETNA_MAX_PIPES];
 
 
 35};
 36
 37struct etnaviv_drm_private {
 38	int num_gpus;
 39	struct etnaviv_gpu *gpu[ETNA_MAX_PIPES];
 40	gfp_t shm_gfp_mask;
 41
 42	struct etnaviv_cmdbuf_suballoc *cmdbuf_suballoc;
 43	struct etnaviv_iommu_global *mmu_global;
 44
 45	struct xarray active_contexts;
 46	u32 next_context_id;
 47
 48	/* list of GEM objects: */
 49	struct mutex gem_lock;
 50	struct list_head gem_list;
 
 
 51};
 52
 
 
 
 
 
 
 
 
 53int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data,
 54		struct drm_file *file);
 55
 
 
 56int etnaviv_gem_mmap_offset(struct drm_gem_object *obj, u64 *offset);
 57struct sg_table *etnaviv_gem_prime_get_sg_table(struct drm_gem_object *obj);
 58int etnaviv_gem_prime_vmap(struct drm_gem_object *obj, struct iosys_map *map);
 
 59struct drm_gem_object *etnaviv_gem_prime_import_sg_table(struct drm_device *dev,
 60	struct dma_buf_attachment *attach, struct sg_table *sg);
 61int etnaviv_gem_prime_pin(struct drm_gem_object *obj);
 62void etnaviv_gem_prime_unpin(struct drm_gem_object *obj);
 63void *etnaviv_gem_vmap(struct drm_gem_object *obj);
 64int etnaviv_gem_cpu_prep(struct drm_gem_object *obj, u32 op,
 65		struct drm_etnaviv_timespec *timeout);
 66int etnaviv_gem_cpu_fini(struct drm_gem_object *obj);
 67void etnaviv_gem_free_object(struct drm_gem_object *obj);
 68int etnaviv_gem_new_handle(struct drm_device *dev, struct drm_file *file,
 69		u32 size, u32 flags, u32 *handle);
 
 
 
 
 70int etnaviv_gem_new_userptr(struct drm_device *dev, struct drm_file *file,
 71	uintptr_t ptr, u32 size, u32 flags, u32 *handle);
 72u16 etnaviv_buffer_init(struct etnaviv_gpu *gpu);
 73u16 etnaviv_buffer_config_mmuv2(struct etnaviv_gpu *gpu, u32 mtlb_addr, u32 safe_addr);
 74u16 etnaviv_buffer_config_pta(struct etnaviv_gpu *gpu, unsigned short id);
 75void etnaviv_buffer_end(struct etnaviv_gpu *gpu);
 76void etnaviv_sync_point_queue(struct etnaviv_gpu *gpu, unsigned int event);
 77void etnaviv_buffer_queue(struct etnaviv_gpu *gpu, u32 exec_state,
 78	struct etnaviv_iommu_context *mmu,
 79	unsigned int event, struct etnaviv_cmdbuf *cmdbuf);
 80void etnaviv_validate_init(void);
 81bool etnaviv_cmd_validate_one(struct etnaviv_gpu *gpu,
 82	u32 *stream, unsigned int size,
 83	struct drm_etnaviv_gem_submit_reloc *relocs, unsigned int reloc_size);
 84
 85#ifdef CONFIG_DEBUG_FS
 86void etnaviv_gem_describe_objects(struct etnaviv_drm_private *priv,
 87	struct seq_file *m);
 88#endif
 89
 
 
 
 
 
 90#define DBG(fmt, ...) DRM_DEBUG(fmt"\n", ##__VA_ARGS__)
 91#define VERB(fmt, ...) if (0) DRM_DEBUG(fmt"\n", ##__VA_ARGS__)
 92
 93/*
 94 * Return the storage size of a structure with a variable length array.
 95 * The array is nelem elements of elem_size, where the base structure
 96 * is defined by base.  If the size overflows size_t, return zero.
 97 */
 98static inline size_t size_vstruct(size_t nelem, size_t elem_size, size_t base)
 99{
100	if (elem_size && nelem > (SIZE_MAX - base) / elem_size)
101		return 0;
102	return base + nelem * elem_size;
103}
104
105/*
106 * Etnaviv timeouts are specified wrt CLOCK_MONOTONIC, not jiffies.
107 * We need to calculate the timeout in terms of number of jiffies
108 * between the specified timeout and the current CLOCK_MONOTONIC time.
109 */
110static inline unsigned long etnaviv_timeout_to_jiffies(
111	const struct drm_etnaviv_timespec *timeout)
112{
113	struct timespec64 ts, to = {
114		.tv_sec = timeout->tv_sec,
115		.tv_nsec = timeout->tv_nsec,
116	};
117
118	ktime_get_ts64(&ts);
119
120	/* timeouts before "now" have already expired */
121	if (timespec64_compare(&to, &ts) <= 0)
122		return 0;
 
123
124	ts = timespec64_sub(to, ts);
 
 
 
 
 
 
 
 
 
 
125
126	return timespec64_to_jiffies(&ts);
127}
128
129#endif /* __ETNAVIV_DRV_H__ */
v4.6
 
  1/*
  2 * Copyright (C) 2015 Etnaviv Project
  3 *
  4 * This program is free software; you can redistribute it and/or modify it
  5 * under the terms of the GNU General Public License version 2 as published by
  6 * the Free Software Foundation.
  7 *
  8 * This program is distributed in the hope that it will be useful, but WITHOUT
  9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 10 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 11 * more details.
 12 *
 13 * You should have received a copy of the GNU General Public License along with
 14 * this program.  If not, see <http://www.gnu.org/licenses/>.
 15 */
 16
 17#ifndef __ETNAVIV_DRV_H__
 18#define __ETNAVIV_DRV_H__
 19
 20#include <linux/kernel.h>
 21#include <linux/clk.h>
 22#include <linux/cpufreq.h>
 23#include <linux/module.h>
 24#include <linux/platform_device.h>
 25#include <linux/pm.h>
 26#include <linux/pm_runtime.h>
 27#include <linux/slab.h>
 28#include <linux/list.h>
 29#include <linux/iommu.h>
 
 
 30#include <linux/types.h>
 31#include <linux/sizes.h>
 32
 33#include <drm/drmP.h>
 34#include <drm/drm_crtc_helper.h>
 35#include <drm/drm_fb_helper.h>
 36#include <drm/drm_gem.h>
 37#include <drm/etnaviv_drm.h>
 
 38
 39struct etnaviv_cmdbuf;
 40struct etnaviv_gpu;
 41struct etnaviv_mmu;
 42struct etnaviv_gem_object;
 43struct etnaviv_gem_submit;
 
 
 
 44
 45struct etnaviv_file_private {
 46	/* currently we don't do anything useful with this.. but when
 47	 * per-context address spaces are supported we'd keep track of
 48	 * the context's page-tables here.
 49	 */
 50	int dummy;
 51};
 52
 53struct etnaviv_drm_private {
 54	int num_gpus;
 55	struct etnaviv_gpu *gpu[ETNA_MAX_PIPES];
 
 
 
 
 
 
 
 56
 57	/* list of GEM objects: */
 58	struct mutex gem_lock;
 59	struct list_head gem_list;
 60
 61	struct workqueue_struct *wq;
 62};
 63
 64static inline void etnaviv_queue_work(struct drm_device *dev,
 65	struct work_struct *w)
 66{
 67	struct etnaviv_drm_private *priv = dev->dev_private;
 68
 69	queue_work(priv->wq, w);
 70}
 71
 72int etnaviv_ioctl_gem_submit(struct drm_device *dev, void *data,
 73		struct drm_file *file);
 74
 75int etnaviv_gem_mmap(struct file *filp, struct vm_area_struct *vma);
 76int etnaviv_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf);
 77int etnaviv_gem_mmap_offset(struct drm_gem_object *obj, u64 *offset);
 78struct sg_table *etnaviv_gem_prime_get_sg_table(struct drm_gem_object *obj);
 79void *etnaviv_gem_prime_vmap(struct drm_gem_object *obj);
 80void etnaviv_gem_prime_vunmap(struct drm_gem_object *obj, void *vaddr);
 81struct drm_gem_object *etnaviv_gem_prime_import_sg_table(struct drm_device *dev,
 82	struct dma_buf_attachment *attach, struct sg_table *sg);
 83int etnaviv_gem_prime_pin(struct drm_gem_object *obj);
 84void etnaviv_gem_prime_unpin(struct drm_gem_object *obj);
 85void *etnaviv_gem_vmap(struct drm_gem_object *obj);
 86int etnaviv_gem_cpu_prep(struct drm_gem_object *obj, u32 op,
 87		struct timespec *timeout);
 88int etnaviv_gem_cpu_fini(struct drm_gem_object *obj);
 89void etnaviv_gem_free_object(struct drm_gem_object *obj);
 90int etnaviv_gem_new_handle(struct drm_device *dev, struct drm_file *file,
 91		u32 size, u32 flags, u32 *handle);
 92struct drm_gem_object *etnaviv_gem_new_locked(struct drm_device *dev,
 93		u32 size, u32 flags);
 94struct drm_gem_object *etnaviv_gem_new(struct drm_device *dev,
 95		u32 size, u32 flags);
 96int etnaviv_gem_new_userptr(struct drm_device *dev, struct drm_file *file,
 97	uintptr_t ptr, u32 size, u32 flags, u32 *handle);
 98u16 etnaviv_buffer_init(struct etnaviv_gpu *gpu);
 
 
 99void etnaviv_buffer_end(struct etnaviv_gpu *gpu);
100void etnaviv_buffer_queue(struct etnaviv_gpu *gpu, unsigned int event,
101	struct etnaviv_cmdbuf *cmdbuf);
 
 
102void etnaviv_validate_init(void);
103bool etnaviv_cmd_validate_one(struct etnaviv_gpu *gpu,
104	u32 *stream, unsigned int size,
105	struct drm_etnaviv_gem_submit_reloc *relocs, unsigned int reloc_size);
106
107#ifdef CONFIG_DEBUG_FS
108void etnaviv_gem_describe_objects(struct etnaviv_drm_private *priv,
109	struct seq_file *m);
110#endif
111
112void __iomem *etnaviv_ioremap(struct platform_device *pdev, const char *name,
113		const char *dbgname);
114void etnaviv_writel(u32 data, void __iomem *addr);
115u32 etnaviv_readl(const void __iomem *addr);
116
117#define DBG(fmt, ...) DRM_DEBUG(fmt"\n", ##__VA_ARGS__)
118#define VERB(fmt, ...) if (0) DRM_DEBUG(fmt"\n", ##__VA_ARGS__)
119
120/*
121 * Return the storage size of a structure with a variable length array.
122 * The array is nelem elements of elem_size, where the base structure
123 * is defined by base.  If the size overflows size_t, return zero.
124 */
125static inline size_t size_vstruct(size_t nelem, size_t elem_size, size_t base)
126{
127	if (elem_size && nelem > (SIZE_MAX - base) / elem_size)
128		return 0;
129	return base + nelem * elem_size;
130}
131
132/* returns true if fence a comes after fence b */
133static inline bool fence_after(u32 a, u32 b)
 
 
 
 
 
134{
135	return (s32)(a - b) > 0;
136}
 
 
 
 
137
138static inline bool fence_after_eq(u32 a, u32 b)
139{
140	return (s32)(a - b) >= 0;
141}
142
143static inline unsigned long etnaviv_timeout_to_jiffies(
144	const struct timespec *timeout)
145{
146	unsigned long timeout_jiffies = timespec_to_jiffies(timeout);
147	unsigned long start_jiffies = jiffies;
148	unsigned long remaining_jiffies;
149
150	if (time_after(start_jiffies, timeout_jiffies))
151		remaining_jiffies = 0;
152	else
153		remaining_jiffies = timeout_jiffies - start_jiffies;
154
155	return remaining_jiffies;
156}
157
158#endif /* __ETNAVIV_DRV_H__ */