Linux Audio

Check our new training course

Loading...
v4.6
 
 1/*
 2 * Tegra host1x GEM implementation
 3 *
 4 * Copyright (c) 2012-2013, NVIDIA Corporation.
 5 *
 6 * This program is free software; you can redistribute it and/or modify
 7 * it under the terms of the GNU General Public License version 2 as
 8 * published by the Free Software Foundation.
 9 */
10
11#ifndef __HOST1X_GEM_H
12#define __HOST1X_GEM_H
13
14#include <linux/host1x.h>
15
16#include <drm/drm.h>
17#include <drm/drmP.h>
18#include <drm/drm_gem.h>
19
20#define TEGRA_BO_BOTTOM_UP (1 << 0)
21
22enum tegra_bo_tiling_mode {
23	TEGRA_BO_TILING_MODE_PITCH,
24	TEGRA_BO_TILING_MODE_TILED,
25	TEGRA_BO_TILING_MODE_BLOCK,
26};
27
 
 
 
 
 
28struct tegra_bo_tiling {
29	enum tegra_bo_tiling_mode mode;
30	unsigned long value;
 
31};
32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33struct tegra_bo {
34	struct drm_gem_object gem;
35	struct host1x_bo base;
36	unsigned long flags;
37	struct sg_table *sgt;
38	dma_addr_t paddr;
39	void *vaddr;
 
40
41	struct drm_mm_node *mm;
42	unsigned long num_pages;
43	struct page **pages;
44	/* size of IOMMU mapping */
45	size_t size;
46
47	struct tegra_bo_tiling tiling;
48};
49
50static inline struct tegra_bo *to_tegra_bo(struct drm_gem_object *gem)
51{
52	return container_of(gem, struct tegra_bo, gem);
53}
54
 
 
 
 
 
55struct tegra_bo *tegra_bo_create(struct drm_device *drm, size_t size,
56				 unsigned long flags);
57struct tegra_bo *tegra_bo_create_with_handle(struct drm_file *file,
58					     struct drm_device *drm,
59					     size_t size,
60					     unsigned long flags,
61					     u32 *handle);
62void tegra_bo_free_object(struct drm_gem_object *gem);
63int tegra_bo_dumb_create(struct drm_file *file, struct drm_device *drm,
64			 struct drm_mode_create_dumb *args);
65int tegra_bo_dumb_map_offset(struct drm_file *file, struct drm_device *drm,
66			     u32 handle, u64 *offset);
67
68int tegra_drm_mmap(struct file *file, struct vm_area_struct *vma);
69
70extern const struct vm_operations_struct tegra_bo_vm_ops;
71
72struct dma_buf *tegra_gem_prime_export(struct drm_device *drm,
73				       struct drm_gem_object *gem,
 
 
74				       int flags);
75struct drm_gem_object *tegra_gem_prime_import(struct drm_device *drm,
76					      struct dma_buf *buf);
 
 
77
78#endif
v6.13.7
  1/* SPDX-License-Identifier: GPL-2.0-only */
  2/*
  3 * Tegra host1x GEM implementation
  4 *
  5 * Copyright (c) 2012-2013, NVIDIA Corporation.
 
 
 
 
  6 */
  7
  8#ifndef __HOST1X_GEM_H
  9#define __HOST1X_GEM_H
 10
 11#include <linux/host1x.h>
 12
 13#include <drm/drm.h>
 
 14#include <drm/drm_gem.h>
 15
 16#define TEGRA_BO_BOTTOM_UP (1 << 0)
 17
 18enum tegra_bo_tiling_mode {
 19	TEGRA_BO_TILING_MODE_PITCH,
 20	TEGRA_BO_TILING_MODE_TILED,
 21	TEGRA_BO_TILING_MODE_BLOCK,
 22};
 23
 24enum tegra_bo_sector_layout {
 25	TEGRA_BO_SECTOR_LAYOUT_TEGRA,
 26	TEGRA_BO_SECTOR_LAYOUT_GPU,
 27};
 28
 29struct tegra_bo_tiling {
 30	enum tegra_bo_tiling_mode mode;
 31	unsigned long value;
 32	enum tegra_bo_sector_layout sector_layout;
 33};
 34
 35/*
 36 * How memory is referenced within a tegra_bo:
 37 *
 38 * Buffer source  | Mapping API(*)  | Fields
 39 * ---------------+-----------------+---------------
 40 * Allocated here | DMA API         | iova (IOVA mapped to drm->dev), vaddr (CPU VA)
 41 *
 42 * Allocated here | IOMMU API       | pages/num_pages (Phys. memory), sgt (Mapped to drm->dev),
 43 *                                  | iova/size (Mapped to domain)
 44 *
 45 * Imported       | DMA API         | dma_buf (Imported dma_buf)
 46 *
 47 * Imported       | IOMMU API       | dma_buf (Imported dma_buf),
 48 *                                  | gem->import_attach (Attachment on drm->dev),
 49 *                                  | sgt (Mapped to drm->dev)
 50 *                                  | iova/size (Mapped to domain)
 51 *
 52 * (*) If tegra->domain is set, i.e. TegraDRM IOMMU domain is directly managed through IOMMU API,
 53 *     this is IOMMU API. Otherwise DMA API.
 54 */
 55struct tegra_bo {
 56	struct drm_gem_object gem;
 57	struct host1x_bo base;
 58	unsigned long flags;
 59	struct sg_table *sgt;
 60	dma_addr_t iova;
 61	void *vaddr;
 62	struct dma_buf *dma_buf;
 63
 64	struct drm_mm_node *mm;
 65	unsigned long num_pages;
 66	struct page **pages;
 67	/* size of IOMMU mapping */
 68	size_t size;
 69
 70	struct tegra_bo_tiling tiling;
 71};
 72
 73static inline struct tegra_bo *to_tegra_bo(struct drm_gem_object *gem)
 74{
 75	return container_of(gem, struct tegra_bo, gem);
 76}
 77
 78static inline struct tegra_bo *host1x_to_tegra_bo(struct host1x_bo *bo)
 79{
 80	return container_of(bo, struct tegra_bo, base);
 81}
 82
 83struct tegra_bo *tegra_bo_create(struct drm_device *drm, size_t size,
 84				 unsigned long flags);
 85struct tegra_bo *tegra_bo_create_with_handle(struct drm_file *file,
 86					     struct drm_device *drm,
 87					     size_t size,
 88					     unsigned long flags,
 89					     u32 *handle);
 90void tegra_bo_free_object(struct drm_gem_object *gem);
 91int tegra_bo_dumb_create(struct drm_file *file, struct drm_device *drm,
 92			 struct drm_mode_create_dumb *args);
 
 
 
 
 93
 94extern const struct vm_operations_struct tegra_bo_vm_ops;
 95
 96int __tegra_gem_mmap(struct drm_gem_object *gem, struct vm_area_struct *vma);
 97int tegra_drm_mmap(struct file *file, struct vm_area_struct *vma);
 98
 99struct dma_buf *tegra_gem_prime_export(struct drm_gem_object *gem,
100				       int flags);
101struct drm_gem_object *tegra_gem_prime_import(struct drm_device *drm,
102					      struct dma_buf *buf);
103
104struct host1x_bo *tegra_gem_lookup(struct drm_file *file, u32 handle);
105
106#endif