1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Tegra host1x GEM implementation
5 * Copyright (c) 2012-2013, NVIDIA Corporation.
11 #include <linux/host1x.h>
14 #include <drm/drm_gem.h>
16 #define TEGRA_BO_BOTTOM_UP (1 << 0)
18 enum tegra_bo_tiling_mode {
19 TEGRA_BO_TILING_MODE_PITCH,
20 TEGRA_BO_TILING_MODE_TILED,
21 TEGRA_BO_TILING_MODE_BLOCK,
24 enum tegra_bo_sector_layout {
25 TEGRA_BO_SECTOR_LAYOUT_TEGRA,
26 TEGRA_BO_SECTOR_LAYOUT_GPU,
29 struct tegra_bo_tiling {
30 enum tegra_bo_tiling_mode mode;
32 enum tegra_bo_sector_layout sector_layout;
36 * How memory is referenced within a tegra_bo:
38 * Buffer source | Mapping API(*) | Fields
39 * ---------------+-----------------+---------------
40 * Allocated here | DMA API | iova (IOVA mapped to drm->dev), vaddr (CPU VA)
42 * Allocated here | IOMMU API | pages/num_pages (Phys. memory), sgt (Mapped to drm->dev),
43 * | iova/size (Mapped to domain)
45 * Imported | DMA API | dma_buf (Imported dma_buf)
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)
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.
56 struct drm_gem_object gem;
57 struct host1x_bo base;
62 struct dma_buf *dma_buf;
64 struct drm_mm_node *mm;
65 unsigned long num_pages;
67 /* size of IOMMU mapping */
70 struct tegra_bo_tiling tiling;
73 static inline struct tegra_bo *to_tegra_bo(struct drm_gem_object *gem)
75 return container_of(gem, struct tegra_bo, gem);
78 static inline struct tegra_bo *host1x_to_tegra_bo(struct host1x_bo *bo)
80 return container_of(bo, struct tegra_bo, base);
83 struct tegra_bo *tegra_bo_create(struct drm_device *drm, size_t size,
85 struct tegra_bo *tegra_bo_create_with_handle(struct drm_file *file,
86 struct drm_device *drm,
90 void tegra_bo_free_object(struct drm_gem_object *gem);
91 int tegra_bo_dumb_create(struct drm_file *file, struct drm_device *drm,
92 struct drm_mode_create_dumb *args);
94 extern const struct vm_operations_struct tegra_bo_vm_ops;
96 int __tegra_gem_mmap(struct drm_gem_object *gem, struct vm_area_struct *vma);
97 int tegra_drm_mmap(struct file *file, struct vm_area_struct *vma);
99 struct dma_buf *tegra_gem_prime_export(struct drm_gem_object *gem,
101 struct drm_gem_object *tegra_gem_prime_import(struct drm_device *drm,
102 struct dma_buf *buf);
104 struct host1x_bo *tegra_gem_lookup(struct drm_file *file, u32 handle);