xref: /linux/drivers/gpu/drm/xe/compat-i915-headers/gem/i915_gem_object.h (revision 0879020a7817e7ce636372c016b4528f541c9f4d)
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) ((obj)->flags & XE_BO_CREATE_SYSTEM_BIT)
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 *virtual;
39 	bool is_iomem;
40 	int ret;
41 
42 	XE_WARN_ON(size != 8);
43 
44 	ret = xe_bo_lock(bo, true);
45 	if (ret)
46 		return ret;
47 
48 	ret = ttm_bo_kmap(&bo->ttm, ofs >> PAGE_SHIFT, 1, &map);
49 	if (ret)
50 		goto out_unlock;
51 
52 	ofs &= ~PAGE_MASK;
53 	virtual = ttm_kmap_obj_virtual(&map, &is_iomem);
54 	if (is_iomem)
55 		*ptr = readq((void __iomem *)(virtual + ofs));
56 	else
57 		*ptr = *(u64 *)(virtual + ofs);
58 
59 	ttm_bo_kunmap(&map);
60 out_unlock:
61 	xe_bo_unlock(bo);
62 	return ret;
63 }
64 
65 #endif
66