1 // SPDX-License-Identifier: MIT
3 * Copyright © 2019 Intel Corporation
6 #include "gem/i915_gem_region.h"
7 #include "intel_memory_region.h"
9 #include "mock_region.h"
11 static const struct drm_i915_gem_object_ops mock_region_obj_ops
= {
12 .get_pages
= i915_gem_object_get_pages_buddy
,
13 .put_pages
= i915_gem_object_put_pages_buddy
,
14 .release
= i915_gem_object_release_memory_region
,
17 static struct drm_i915_gem_object
*
18 mock_object_create(struct intel_memory_region
*mem
,
22 static struct lock_class_key lock_class
;
23 struct drm_i915_private
*i915
= mem
->i915
;
24 struct drm_i915_gem_object
*obj
;
26 if (size
> BIT(mem
->mm
.max_order
) * mem
->mm
.chunk_size
)
27 return ERR_PTR(-E2BIG
);
29 obj
= i915_gem_object_alloc();
31 return ERR_PTR(-ENOMEM
);
33 drm_gem_private_object_init(&i915
->drm
, &obj
->base
, size
);
34 i915_gem_object_init(obj
, &mock_region_obj_ops
, &lock_class
);
36 obj
->read_domains
= I915_GEM_DOMAIN_CPU
| I915_GEM_DOMAIN_GTT
;
38 i915_gem_object_set_cache_coherency(obj
, I915_CACHE_NONE
);
40 i915_gem_object_init_memory_region(obj
, mem
, flags
);
45 static const struct intel_memory_region_ops mock_region_ops
= {
46 .init
= intel_memory_region_init_buddy
,
47 .release
= intel_memory_region_release_buddy
,
48 .create_object
= mock_object_create
,
51 struct intel_memory_region
*
52 mock_region_create(struct drm_i915_private
*i915
,
53 resource_size_t start
,
55 resource_size_t min_page_size
,
56 resource_size_t io_start
)
58 return intel_memory_region_create(i915
, start
, size
, min_page_size
,
59 io_start
, &mock_region_ops
);