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 .name
= "mock-region",
13 .get_pages
= i915_gem_object_get_pages_buddy
,
14 .put_pages
= i915_gem_object_put_pages_buddy
,
15 .release
= i915_gem_object_release_memory_region
,
18 static struct drm_i915_gem_object
*
19 mock_object_create(struct intel_memory_region
*mem
,
23 static struct lock_class_key lock_class
;
24 struct drm_i915_private
*i915
= mem
->i915
;
25 struct drm_i915_gem_object
*obj
;
27 if (size
> mem
->mm
.size
)
28 return ERR_PTR(-E2BIG
);
30 obj
= i915_gem_object_alloc();
32 return ERR_PTR(-ENOMEM
);
34 drm_gem_private_object_init(&i915
->drm
, &obj
->base
, size
);
35 i915_gem_object_init(obj
, &mock_region_obj_ops
, &lock_class
);
37 obj
->read_domains
= I915_GEM_DOMAIN_CPU
| I915_GEM_DOMAIN_GTT
;
39 i915_gem_object_set_cache_coherency(obj
, I915_CACHE_NONE
);
41 i915_gem_object_init_memory_region(obj
, mem
, flags
);
46 static const struct intel_memory_region_ops mock_region_ops
= {
47 .init
= intel_memory_region_init_buddy
,
48 .release
= intel_memory_region_release_buddy
,
49 .create_object
= mock_object_create
,
52 struct intel_memory_region
*
53 mock_region_create(struct drm_i915_private
*i915
,
54 resource_size_t start
,
56 resource_size_t min_page_size
,
57 resource_size_t io_start
)
59 return intel_memory_region_create(i915
, start
, size
, min_page_size
,
60 io_start
, &mock_region_ops
);