Commit b908be54 authored by Matthew Auld's avatar Matthew Auld Committed by Chris Wilson

drm/i915: support creating LMEM objects

We currently define LMEM, or local memory, as just another memory
region, like system memory or stolen, which we can expose to userspace
and can be mapped to the CPU via some BAR.
Signed-off-by: default avatarMatthew Auld <matthew.auld@intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Abdiel Janulgue <abdiel.janulgue@linux.intel.com>
Reviewed-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Link: https://patchwork.freedesktop.org/patch/msgid/20191025153728.23689-1-chris@chris-wilson.co.uk
parent 7be8782a
...@@ -120,6 +120,7 @@ gem-y += \ ...@@ -120,6 +120,7 @@ gem-y += \
gem/i915_gem_internal.o \ gem/i915_gem_internal.o \
gem/i915_gem_object.o \ gem/i915_gem_object.o \
gem/i915_gem_object_blt.o \ gem/i915_gem_object_blt.o \
gem/i915_gem_lmem.o \
gem/i915_gem_mman.o \ gem/i915_gem_mman.o \
gem/i915_gem_pages.o \ gem/i915_gem_pages.o \
gem/i915_gem_phys.o \ gem/i915_gem_phys.o \
...@@ -148,6 +149,7 @@ i915-y += \ ...@@ -148,6 +149,7 @@ i915-y += \
i915_scheduler.o \ i915_scheduler.o \
i915_trace_points.o \ i915_trace_points.o \
i915_vma.o \ i915_vma.o \
intel_region_lmem.o \
intel_wopcm.o intel_wopcm.o
# general-purpose microcontroller (GuC) support # general-purpose microcontroller (GuC) support
......
// SPDX-License-Identifier: MIT
/*
* Copyright © 2019 Intel Corporation
*/
#include "intel_memory_region.h"
#include "gem/i915_gem_region.h"
#include "gem/i915_gem_lmem.h"
#include "i915_drv.h"
const struct drm_i915_gem_object_ops i915_gem_lmem_obj_ops = {
.get_pages = i915_gem_object_get_pages_buddy,
.put_pages = i915_gem_object_put_pages_buddy,
.release = i915_gem_object_release_memory_region,
};
bool i915_gem_object_is_lmem(struct drm_i915_gem_object *obj)
{
return obj->ops == &i915_gem_lmem_obj_ops;
}
struct drm_i915_gem_object *
i915_gem_object_create_lmem(struct drm_i915_private *i915,
resource_size_t size,
unsigned int flags)
{
return i915_gem_object_create_region(i915->mm.regions[INTEL_REGION_LMEM],
size, flags);
}
struct drm_i915_gem_object *
__i915_gem_lmem_object_create(struct intel_memory_region *mem,
resource_size_t size,
unsigned int flags)
{
static struct lock_class_key lock_class;
struct drm_i915_private *i915 = mem->i915;
struct drm_i915_gem_object *obj;
if (size > BIT(mem->mm.max_order) * mem->mm.chunk_size)
return ERR_PTR(-E2BIG);
obj = i915_gem_object_alloc();
if (!obj)
return ERR_PTR(-ENOMEM);
drm_gem_private_object_init(&i915->drm, &obj->base, size);
i915_gem_object_init(obj, &i915_gem_lmem_obj_ops, &lock_class);
obj->read_domains = I915_GEM_DOMAIN_WC | I915_GEM_DOMAIN_GTT;
i915_gem_object_set_cache_coherency(obj, I915_CACHE_NONE);
i915_gem_object_init_memory_region(obj, mem, flags);
return obj;
}
/* SPDX-License-Identifier: MIT */
/*
* Copyright © 2019 Intel Corporation
*/
#ifndef __I915_GEM_LMEM_H
#define __I915_GEM_LMEM_H
#include <linux/types.h>
struct drm_i915_private;
struct drm_i915_gem_object;
struct intel_memory_region;
extern const struct drm_i915_gem_object_ops i915_gem_lmem_obj_ops;
bool i915_gem_object_is_lmem(struct drm_i915_gem_object *obj);
struct drm_i915_gem_object *
i915_gem_object_create_lmem(struct drm_i915_private *i915,
resource_size_t size,
unsigned int flags);
struct drm_i915_gem_object *
__i915_gem_lmem_object_create(struct intel_memory_region *mem,
resource_size_t size,
unsigned int flags);
#endif /* !__I915_GEM_LMEM_H */
...@@ -101,6 +101,8 @@ ...@@ -101,6 +101,8 @@
#include "i915_vma.h" #include "i915_vma.h"
#include "i915_irq.h" #include "i915_irq.h"
#include "intel_region_lmem.h"
#include "intel_gvt.h" #include "intel_gvt.h"
/* General customization: /* General customization:
...@@ -1789,6 +1791,7 @@ IS_SUBPLATFORM(const struct drm_i915_private *i915, ...@@ -1789,6 +1791,7 @@ IS_SUBPLATFORM(const struct drm_i915_private *i915,
#define HAS_IPC(dev_priv) (INTEL_INFO(dev_priv)->display.has_ipc) #define HAS_IPC(dev_priv) (INTEL_INFO(dev_priv)->display.has_ipc)
#define HAS_REGION(i915, i) (INTEL_INFO(i915)->memory_regions & (i)) #define HAS_REGION(i915, i) (INTEL_INFO(i915)->memory_regions & (i))
#define HAS_LMEM(i915) HAS_REGION(i915, REGION_LMEM)
#define HAS_GT_UC(dev_priv) (INTEL_INFO(dev_priv)->has_gt_uc) #define HAS_GT_UC(dev_priv) (INTEL_INFO(dev_priv)->has_gt_uc)
......
// SPDX-License-Identifier: MIT
/*
* Copyright © 2019 Intel Corporation
*/
#include "i915_drv.h"
#include "intel_memory_region.h"
#include "gem/i915_gem_lmem.h"
#include "gem/i915_gem_region.h"
#include "intel_region_lmem.h"
const struct intel_memory_region_ops intel_region_lmem_ops = {
.init = intel_memory_region_init_buddy,
.release = intel_memory_region_release_buddy,
.create_object = __i915_gem_lmem_object_create,
};
/* SPDX-License-Identifier: MIT */
/*
* Copyright © 2019 Intel Corporation
*/
#ifndef __INTEL_REGION_LMEM_H
#define __INTEL_REGION_LMEM_H
extern const struct intel_memory_region_ops intel_region_lmem_ops;
#endif /* !__INTEL_REGION_LMEM_H */
...@@ -33,6 +33,7 @@ selftest(gem_contexts, i915_gem_context_live_selftests) ...@@ -33,6 +33,7 @@ selftest(gem_contexts, i915_gem_context_live_selftests)
selftest(blt, i915_gem_object_blt_live_selftests) selftest(blt, i915_gem_object_blt_live_selftests)
selftest(client, i915_gem_client_blt_live_selftests) selftest(client, i915_gem_client_blt_live_selftests)
selftest(reset, intel_reset_live_selftests) selftest(reset, intel_reset_live_selftests)
selftest(memory_region, intel_memory_region_live_selftests)
selftest(hangcheck, intel_hangcheck_live_selftests) selftest(hangcheck, intel_hangcheck_live_selftests)
selftest(execlists, intel_execlists_live_selftests) selftest(execlists, intel_execlists_live_selftests)
selftest(guc, intel_guc_live_selftest) selftest(guc, intel_guc_live_selftest)
......
...@@ -11,8 +11,10 @@ ...@@ -11,8 +11,10 @@
#include "mock_gem_device.h" #include "mock_gem_device.h"
#include "mock_region.h" #include "mock_region.h"
#include "gem/i915_gem_lmem.h"
#include "gem/i915_gem_region.h" #include "gem/i915_gem_region.h"
#include "gem/selftests/mock_context.h" #include "gem/selftests/mock_context.h"
#include "gt/intel_gt.h"
#include "selftests/i915_random.h" #include "selftests/i915_random.h"
static void close_objects(struct intel_memory_region *mem, static void close_objects(struct intel_memory_region *mem,
...@@ -252,6 +254,27 @@ static int igt_mock_contiguous(void *arg) ...@@ -252,6 +254,27 @@ static int igt_mock_contiguous(void *arg)
return err; return err;
} }
static int igt_lmem_create(void *arg)
{
struct drm_i915_private *i915 = arg;
struct drm_i915_gem_object *obj;
int err = 0;
obj = i915_gem_object_create_lmem(i915, PAGE_SIZE, 0);
if (IS_ERR(obj))
return PTR_ERR(obj);
err = i915_gem_object_pin_pages(obj);
if (err)
goto out_put;
i915_gem_object_unpin_pages(obj);
out_put:
i915_gem_object_put(obj);
return err;
}
int intel_memory_region_mock_selftests(void) int intel_memory_region_mock_selftests(void)
{ {
static const struct i915_subtest tests[] = { static const struct i915_subtest tests[] = {
...@@ -280,3 +303,20 @@ int intel_memory_region_mock_selftests(void) ...@@ -280,3 +303,20 @@ int intel_memory_region_mock_selftests(void)
drm_dev_put(&i915->drm); drm_dev_put(&i915->drm);
return err; return err;
} }
int intel_memory_region_live_selftests(struct drm_i915_private *i915)
{
static const struct i915_subtest tests[] = {
SUBTEST(igt_lmem_create),
};
if (!HAS_LMEM(i915)) {
pr_info("device lacks LMEM support, skipping\n");
return 0;
}
if (intel_gt_is_wedged(&i915->gt))
return 0;
return i915_live_subtests(tests, i915);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment