]> git.baikalelectronics.ru Git - kernel.git/commitdiff
drm/i915/lmem: add the fake lmem region
authorMatthew Auld <matthew.auld@intel.com>
Wed, 30 Oct 2019 17:33:20 +0000 (17:33 +0000)
committerChris Wilson <chris@chris-wilson.co.uk>
Thu, 31 Oct 2019 20:41:47 +0000 (20:41 +0000)
Intended for upstream testing so that we can still exercise the LMEM
plumbing and !i915_ggtt_has_aperture paths. Smoke tested on Skull Canyon
device. This works by allocating an intel_memory_region for a reserved
portion of system memory, which we treat like LMEM. For the LMEMBAR we
steal the aperture and 1:1 it map to the stolen region.

To enable simply set the i915 modparam fake_lmem_start= on the kernel
cmdline with the start of reserved region(see memmap=). The size of the
region we can use is determined by the size of the mappable aperture, so
the size of reserved region should be >= mappable_end. For now we only
enable for the selftests. Depends on CONFIG_DRM_I915_UNSTABLE being
enabled.

eg. memmap=2G$16G i915.fake_lmem_start=0x400000000

v2: make fake_lmem_start an i915 modparam

Signed-off-by: Matthew Auld <matthew.auld@intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Abdiel Janulgue <abdiel.janulgue@linux.intel.com>
Cc: Arkadiusz Hiler <arkadiusz.hiler@intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Link: https://patchwork.freedesktop.org/patch/msgid/20191030173320.8850-1-matthew.auld@intel.com
drivers/gpu/drm/i915/Kconfig.unstable
drivers/gpu/drm/i915/gem/i915_gem_lmem.c
drivers/gpu/drm/i915/i915_drv.c
drivers/gpu/drm/i915/i915_params.c
drivers/gpu/drm/i915/i915_params.h
drivers/gpu/drm/i915/intel_memory_region.c
drivers/gpu/drm/i915/intel_memory_region.h
drivers/gpu/drm/i915/intel_region_lmem.c
drivers/gpu/drm/i915/intel_region_lmem.h

index cf151a297ed756c2a8028f96a6af73d3d17b18c8..0c2276155c2b6a36443261d23f6e4d26615f429a 100644 (file)
@@ -19,3 +19,11 @@ config DRM_I915_UNSTABLE
          Recommended for driver developers _only_.
 
          If in the slightest bit of doubt, say "N".
+
+config DRM_I915_UNSTABLE_FAKE_LMEM
+       bool "Enable the experimental fake lmem"
+       depends on DRM_I915_UNSTABLE
+       default n
+       help
+         Convert some system memory into a fake local memory region for
+         testing.
index 926f6c940e0dcf4b9d7dba389f2aad0284afef88..0e2bf6b7e143f9a4926af5098fa9c6b815c32fb4 100644 (file)
@@ -24,6 +24,7 @@ i915_gem_object_lmem_io_map_page(struct drm_i915_gem_object *obj,
        resource_size_t offset;
 
        offset = i915_gem_object_get_dma_address(obj, n);
+       offset -= obj->mm.region->region.start;
 
        return io_mapping_map_wc(&obj->mm.region->iomap, offset, PAGE_SIZE);
 }
@@ -35,6 +36,7 @@ i915_gem_object_lmem_io_map_page_atomic(struct drm_i915_gem_object *obj,
        resource_size_t offset;
 
        offset = i915_gem_object_get_dma_address(obj, n);
+       offset -= obj->mm.region->region.start;
 
        return io_mapping_map_atomic_wc(&obj->mm.region->iomap, offset);
 }
@@ -49,6 +51,7 @@ i915_gem_object_lmem_io_map(struct drm_i915_gem_object *obj,
        GEM_BUG_ON(!i915_gem_object_is_contiguous(obj));
 
        offset = i915_gem_object_get_dma_address(obj, n);
+       offset -= obj->mm.region->region.start;
 
        return io_mapping_map_wc(&obj->mm.region->iomap, offset, size);
 }
index 21273b516dbe5dbe2ee1435c1bb767af655576dc..480e2054f628e96dbad89724a17de99fd7bffc2d 100644 (file)
@@ -1483,6 +1483,21 @@ int i915_driver_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
        if (!i915_modparams.nuclear_pageflip && match_info->gen < 5)
                dev_priv->drm.driver_features &= ~DRIVER_ATOMIC;
 
+       /*
+        * Check if we support fake LMEM -- for now we only unleash this for
+        * the live selftests(test-and-exit).
+        */
+       if (IS_ENABLED(CONFIG_DRM_I915_UNSTABLE_FAKE_LMEM)) {
+               if (INTEL_GEN(dev_priv) >= 9 && i915_selftest.live < 0 &&
+                   i915_modparams.fake_lmem_start) {
+                       mkwrite_device_info(dev_priv)->memory_regions =
+                               REGION_SMEM | REGION_LMEM | REGION_STOLEN;
+                       mkwrite_device_info(dev_priv)->is_dgfx = true;
+                       GEM_BUG_ON(!HAS_LMEM(dev_priv));
+                       GEM_BUG_ON(!IS_DGFX(dev_priv));
+               }
+       }
+
        ret = pci_enable_device(pdev);
        if (ret)
                goto out_fini;
index 3fa79adb2c1c01ded99920d966e65ce34ebb13fd..1dd1f3652795f16ecf34556aaccdb87d8891a57f 100644 (file)
@@ -179,6 +179,11 @@ i915_param_named(enable_gvt, bool, 0400,
        "Enable support for Intel GVT-g graphics virtualization host support(default:false)");
 #endif
 
+#if IS_ENABLED(CONFIG_DRM_I915_UNSTABLE_FAKE_LMEM)
+i915_param_named_unsafe(fake_lmem_start, ulong, 0600,
+       "Fake LMEM start offset (default: 0)");
+#endif
+
 static __always_inline void _print_param(struct drm_printer *p,
                                         const char *name,
                                         const char *type,
@@ -190,6 +195,8 @@ static __always_inline void _print_param(struct drm_printer *p,
                drm_printf(p, "i915.%s=%d\n", name, *(const int *)x);
        else if (!__builtin_strcmp(type, "unsigned int"))
                drm_printf(p, "i915.%s=%u\n", name, *(const unsigned int *)x);
+       else if (!__builtin_strcmp(type, "unsigned long"))
+               drm_printf(p, "i915.%s=%lu\n", name, *(const unsigned long *)x);
        else if (!__builtin_strcmp(type, "char *"))
                drm_printf(p, "i915.%s=%s\n", name, *(const char **)x);
        else
index a276317ad74b168e4a162852f477cb51cbd7f558..31b88f297fbca88ee78c5ac94d9092b2b85237b1 100644 (file)
@@ -66,6 +66,7 @@ struct drm_printer;
        param(int, fastboot, -1) \
        param(int, enable_dpcd_backlight, 0) \
        param(char *, force_probe, CONFIG_DRM_I915_FORCE_PROBE) \
+       param(unsigned long, fake_lmem_start, 0) \
        /* leave bools at the end to not create holes */ \
        param(bool, alpha_support, IS_ENABLED(CONFIG_DRM_I915_ALPHA_SUPPORT)) \
        param(bool, enable_hangcheck, true) \
index a60f77ff58d403613c9a17aec12df28b9ab1ae9d..baaeaecc64aff00f49091b6a608a84e2e27a34b0 100644 (file)
@@ -228,6 +228,9 @@ int intel_memory_regions_hw_probe(struct drm_i915_private *i915)
                case INTEL_MEMORY_STOLEN:
                        mem = i915_gem_stolen_setup(i915);
                        break;
+               case INTEL_MEMORY_LOCAL:
+                       mem = intel_setup_fake_lmem(i915);
+                       break;
                }
 
                if (IS_ERR(mem)) {
index 19920c256ede58b9a66ffefa49138f8b70e7ce0f..23872200967700ceaf828e97681ae3e2fd7d53ae 100644 (file)
@@ -10,6 +10,7 @@
 #include <linux/ioport.h>
 #include <linux/mutex.h>
 #include <linux/io-mapping.h>
+#include <drm/drm_mm.h>
 
 #include "i915_buddy.h"
 
@@ -71,6 +72,9 @@ struct intel_memory_region {
        struct io_mapping iomap;
        struct resource region;
 
+       /* For fake LMEM */
+       struct drm_mm_node fake_mappable;
+
        struct i915_buddy_mm mm;
        struct mutex mm_lock;
 
@@ -83,6 +87,8 @@ struct intel_memory_region {
        unsigned int instance;
        unsigned int id;
 
+       dma_addr_t remap_addr;
+
        struct {
                struct mutex lock; /* Protects access to objects */
                struct list_head list;
index 9a351af45ce622f77498329f9fefc5bbd90a3517..58311809563580b1475e583e53fd99a09c710320 100644 (file)
@@ -9,9 +9,62 @@
 #include "gem/i915_gem_region.h"
 #include "intel_region_lmem.h"
 
+static int init_fake_lmem_bar(struct intel_memory_region *mem)
+{
+       struct drm_i915_private *i915 = mem->i915;
+       struct i915_ggtt *ggtt = &i915->ggtt;
+       unsigned long n;
+       int ret;
+
+       /* We want to 1:1 map the mappable aperture to our reserved region */
+
+       mem->fake_mappable.start = 0;
+       mem->fake_mappable.size = resource_size(&mem->region);
+       mem->fake_mappable.color = I915_COLOR_UNEVICTABLE;
+
+       ret = drm_mm_reserve_node(&ggtt->vm.mm, &mem->fake_mappable);
+       if (ret)
+               return ret;
+
+       mem->remap_addr = dma_map_resource(&i915->drm.pdev->dev,
+                                          mem->region.start,
+                                          mem->fake_mappable.size,
+                                          PCI_DMA_BIDIRECTIONAL,
+                                          DMA_ATTR_FORCE_CONTIGUOUS);
+       if (dma_mapping_error(&i915->drm.pdev->dev, mem->remap_addr)) {
+               drm_mm_remove_node(&mem->fake_mappable);
+               return -EINVAL;
+       }
+
+       for (n = 0; n < mem->fake_mappable.size >> PAGE_SHIFT; ++n) {
+               ggtt->vm.insert_page(&ggtt->vm,
+                                    mem->remap_addr + (n << PAGE_SHIFT),
+                                    n << PAGE_SHIFT,
+                                    I915_CACHE_NONE, 0);
+       }
+
+       mem->region = (struct resource)DEFINE_RES_MEM(mem->remap_addr,
+                                                     mem->fake_mappable.size);
+
+       return 0;
+}
+
+static void release_fake_lmem_bar(struct intel_memory_region *mem)
+{
+       if (drm_mm_node_allocated(&mem->fake_mappable))
+               drm_mm_remove_node(&mem->fake_mappable);
+
+       dma_unmap_resource(&mem->i915->drm.pdev->dev,
+                          mem->remap_addr,
+                          mem->fake_mappable.size,
+                          PCI_DMA_BIDIRECTIONAL,
+                          DMA_ATTR_FORCE_CONTIGUOUS);
+}
+
 static void
 region_lmem_release(struct intel_memory_region *mem)
 {
+       release_fake_lmem_bar(mem);
        io_mapping_fini(&mem->iomap);
        intel_memory_region_release_buddy(mem);
 }
@@ -21,6 +74,11 @@ region_lmem_init(struct intel_memory_region *mem)
 {
        int ret;
 
+       if (i915_modparams.fake_lmem_start) {
+               ret = init_fake_lmem_bar(mem);
+               GEM_BUG_ON(ret);
+       }
+
        if (!io_mapping_init_wc(&mem->iomap,
                                mem->io_start,
                                resource_size(&mem->region)))
@@ -38,3 +96,37 @@ const struct intel_memory_region_ops intel_region_lmem_ops = {
        .release = region_lmem_release,
        .create_object = __i915_gem_lmem_object_create,
 };
+
+struct intel_memory_region *
+intel_setup_fake_lmem(struct drm_i915_private *i915)
+{
+       struct pci_dev *pdev = i915->drm.pdev;
+       struct intel_memory_region *mem;
+       resource_size_t mappable_end;
+       resource_size_t io_start;
+       resource_size_t start;
+
+       GEM_BUG_ON(i915_ggtt_has_aperture(&i915->ggtt));
+       GEM_BUG_ON(!i915_modparams.fake_lmem_start);
+
+       /* Your mappable aperture belongs to me now! */
+       mappable_end = pci_resource_len(pdev, 2);
+       io_start = pci_resource_start(pdev, 2),
+       start = i915_modparams.fake_lmem_start;
+
+       mem = intel_memory_region_create(i915,
+                                        start,
+                                        mappable_end,
+                                        PAGE_SIZE,
+                                        io_start,
+                                        &intel_region_lmem_ops);
+       if (!IS_ERR(mem)) {
+               DRM_INFO("Intel graphics fake LMEM: %pR\n", &mem->region);
+               DRM_INFO("Intel graphics fake LMEM IO start: %llx\n",
+                        (u64)mem->io_start);
+               DRM_INFO("Intel graphics fake LMEM size: %llx\n",
+                        (u64)resource_size(&mem->region));
+       }
+
+       return mem;
+}
index ed2a3bab644381312a157711fa1a6e16ca03c5a4..213def7c7b8a555bc06fa1269837dd5cfa8a3ade 100644 (file)
@@ -6,6 +6,11 @@
 #ifndef __INTEL_REGION_LMEM_H
 #define __INTEL_REGION_LMEM_H
 
+struct drm_i915_private;
+
 extern const struct intel_memory_region_ops intel_region_lmem_ops;
 
+struct intel_memory_region *
+intel_setup_fake_lmem(struct drm_i915_private *i915);
+
 #endif /* !__INTEL_REGION_LMEM_H */