Merge tag 'soc-drivers-6.9' of git://git.kernel.org/pub/scm/linux/kernel/git/soc/soc
[linux-block.git] / drivers / gpu / drm / xe / compat-i915-headers / gem / i915_gem_object.h
1 /* SPDX-License-Identifier: MIT */
2 /*
3  * Copyright © 2022 Intel Corporation
4  */
5
6 #ifndef _I915_GEM_OBJECT_H_
7 #define _I915_GEM_OBJECT_H_
8
9 #include <linux/types.h>
10
11 #include "xe_bo.h"
12
13 #define i915_gem_object_is_shmem(obj) (0) /* We don't use shmem */
14
15 static inline dma_addr_t i915_gem_object_get_dma_address(const struct xe_bo *bo, pgoff_t n)
16 {
17         /* Should never be called */
18         WARN_ON(1);
19         return n;
20 }
21
22 static inline bool i915_gem_object_is_tiled(const struct xe_bo *bo)
23 {
24         /* legacy tiling is unused */
25         return false;
26 }
27
28 static inline bool i915_gem_object_is_userptr(const struct xe_bo *bo)
29 {
30         /* legacy tiling is unused */
31         return false;
32 }
33
34 static inline int i915_gem_object_read_from_page(struct xe_bo *bo,
35                                           u32 ofs, u64 *ptr, u32 size)
36 {
37         struct ttm_bo_kmap_obj map;
38         void *src;
39         bool is_iomem;
40         int ret;
41
42         ret = xe_bo_lock(bo, true);
43         if (ret)
44                 return ret;
45
46         ret = ttm_bo_kmap(&bo->ttm, ofs >> PAGE_SHIFT, 1, &map);
47         if (ret)
48                 goto out_unlock;
49
50         ofs &= ~PAGE_MASK;
51         src = ttm_kmap_obj_virtual(&map, &is_iomem);
52         src += ofs;
53         if (is_iomem)
54                 memcpy_fromio(ptr, (void __iomem *)src, size);
55         else
56                 memcpy(ptr, src, size);
57
58         ttm_bo_kunmap(&map);
59 out_unlock:
60         xe_bo_unlock(bo);
61         return ret;
62 }
63
64 #endif