diff mbox series

drm/i915/lmem: add the fake lmem region

Message ID 20191029165134.28567-1-matthew.auld@intel.com (mailing list archive)
State New, archived
Headers show
Series drm/i915/lmem: add the fake lmem region | expand

Commit Message

Matthew Auld Oct. 29, 2019, 4:51 p.m. UTC
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>
---
 drivers/gpu/drm/i915/gem/i915_gem_lmem.c   |  3 +
 drivers/gpu/drm/i915/i915_drv.c            | 15 ++++
 drivers/gpu/drm/i915/i915_params.c         |  5 ++
 drivers/gpu/drm/i915/i915_params.h         |  1 +
 drivers/gpu/drm/i915/intel_memory_region.c |  3 +
 drivers/gpu/drm/i915/intel_memory_region.h |  6 ++
 drivers/gpu/drm/i915/intel_region_lmem.c   | 92 ++++++++++++++++++++++
 drivers/gpu/drm/i915/intel_region_lmem.h   |  5 ++
 8 files changed, 130 insertions(+)

Comments

Chris Wilson Oct. 30, 2019, 9:14 a.m. UTC | #1
Quoting Matthew Auld (2019-10-29 16:51:34)
> diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
> index 21273b516dbe..db1736d95651 100644
> --- a/drivers/gpu/drm/i915/i915_drv.c
> +++ b/drivers/gpu/drm/i915/i915_drv.c
> @@ -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.
> +        */
> +       if (IS_ENABLED(CONFIG_DRM_I915_UNSTABLE)) {

The pattern I have in mind for unstable config options was to add

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.

So each is isolated and less likely to cross-contanimate.

> +               if (INTEL_GEN(dev_priv) >= 9 && i915_selftest.live &&

Probably want i915_selftest.live < 0 so that we only enable it for
selftest-and-exit rather than inline selftests that keep the module
loaded afterwards

i915_selftest.live=0 => no tests
i915_selftest.live=-1 => test and exit
i915_selftest.live=1 => test and run userspace

> +                   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));
> +               }
> +       }
> +

> +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));

Ok, as this is unstable and therefore dev-centric I'll let you off
having clear user information.

resource_size_t => %pa

Remember to make BAT happy!
-Chris
Matthew Auld Oct. 30, 2019, 10:22 p.m. UTC | #2
On Tue, 29 Oct 2019 at 16:51, Matthew Auld <matthew.auld@intel.com> wrote:
>
> 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

Hi Arek,

Would you be able to update the fi-skl-lmem kernel cmd line with
s/i915_fake_lmem_start/i915.fake_lmem_start?
Arkadiusz Hiler Oct. 31, 2019, 12:40 p.m. UTC | #3
On Wed, Oct 30, 2019 at 10:22:37PM +0000, Matthew Auld wrote:
> On Tue, 29 Oct 2019 at 16:51, Matthew Auld <matthew.auld@intel.com> wrote:
> >
> > 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
> 
> Hi Arek,
> 
> Would you be able to update the fi-skl-lmem kernel cmd line with
> s/i915_fake_lmem_start/i915.fake_lmem_start?

done
Chris Wilson Oct. 31, 2019, 8:40 p.m. UTC | #4
Quoting Arkadiusz Hiler (2019-10-31 12:40:35)
> On Wed, Oct 30, 2019 at 10:22:37PM +0000, Matthew Auld wrote:
> > On Tue, 29 Oct 2019 at 16:51, Matthew Auld <matthew.auld@intel.com> wrote:
> > >
> > > 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
> > 
> > Hi Arek,
> > 
> > Would you be able to update the fi-skl-lmem kernel cmd line with
> > s/i915_fake_lmem_start/i915.fake_lmem_start?
> 
> done

<6>[  497.897456] [drm] Intel graphics fake LMEM: [mem 0x100000000-0x13fffffff]
<6>[  497.897459] [drm] Intel graphics fake LMEM IO start: 40000000
<6>[  497.897461] [drm] Intel graphics fake LMEM size: 40000000

All present.
-Chris
Matthew Auld Nov. 5, 2019, 1:05 p.m. UTC | #5
On Thu, 31 Oct 2019 at 20:40, Chris Wilson <chris@chris-wilson.co.uk> wrote:
>
> Quoting Arkadiusz Hiler (2019-10-31 12:40:35)
> > On Wed, Oct 30, 2019 at 10:22:37PM +0000, Matthew Auld wrote:
> > > On Tue, 29 Oct 2019 at 16:51, Matthew Auld <matthew.auld@intel.com> wrote:
> > > >
> > > > 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
> > >
> > > Hi Arek,
> > >
> > > Would you be able to update the fi-skl-lmem kernel cmd line with
> > > s/i915_fake_lmem_start/i915.fake_lmem_start?
> >
> > done
>
> <6>[  497.897456] [drm] Intel graphics fake LMEM: [mem 0x100000000-0x13fffffff]
> <6>[  497.897459] [drm] Intel graphics fake LMEM IO start: 40000000
> <6>[  497.897461] [drm] Intel graphics fake LMEM size: 40000000
>
> All present.

Arek,

Could we enable DRM_I915_UNSTABLE_FAKE_LMEM in CI? That should give us
some coverage of the fake local-memory setup on fi-skl-lmem.
Arkadiusz Hiler Nov. 6, 2019, 8:30 a.m. UTC | #6
On Tue, Nov 05, 2019 at 01:05:20PM +0000, Matthew Auld wrote:
> On Thu, 31 Oct 2019 at 20:40, Chris Wilson <chris@chris-wilson.co.uk> wrote:
> >
> > Quoting Arkadiusz Hiler (2019-10-31 12:40:35)
> > > On Wed, Oct 30, 2019 at 10:22:37PM +0000, Matthew Auld wrote:
> > > > On Tue, 29 Oct 2019 at 16:51, Matthew Auld <matthew.auld@intel.com> wrote:
> > > > >
> > > > > 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
> > > >
> > > > Hi Arek,
> > > >
> > > > Would you be able to update the fi-skl-lmem kernel cmd line with
> > > > s/i915_fake_lmem_start/i915.fake_lmem_start?
> > >
> > > done
> >
> > <6>[  497.897456] [drm] Intel graphics fake LMEM: [mem 0x100000000-0x13fffffff]
> > <6>[  497.897459] [drm] Intel graphics fake LMEM IO start: 40000000
> > <6>[  497.897461] [drm] Intel graphics fake LMEM size: 40000000
> >
> > All present.
> 
> Arek,
> 
> Could we enable DRM_I915_UNSTABLE_FAKE_LMEM in CI? That should give us
> some coverage of the fake local-memory setup on fi-skl-lmem.

Hey,

  config DRM_I915_UNSTABLE
	  bool "Enable unstable API for early prototype development"
	  depends on EXPERT
	  depends on STAGING
	  depends on BROKEN # should never be enabled by distros!

  config DRM_I915_UNSTABLE_FAKE_LMEM
	  bool "Enable the experimental fake lmem"
	  depends on DRM_I915_UNSTABLE

AFAIU because of that dependency on CONFIG_BROKEN we cannot just enable
it through .config - we have to edit the value in init/Kconfig[0].

Please push that change to core-for-CI (or other branch that gets
integrated into drm-tip) and then just send a merge request to the
kernel configs the CI is using[1].

[0]: https://lkml.org/lkml/2006/1/6/248
[1]: https://gitlab.freedesktop.org/gfx-ci/i915-infra/tree/master/kconfig
Chris Wilson Nov. 6, 2019, 11:17 a.m. UTC | #7
Quoting Arkadiusz Hiler (2019-11-06 08:30:37)
> On Tue, Nov 05, 2019 at 01:05:20PM +0000, Matthew Auld wrote:
> > On Thu, 31 Oct 2019 at 20:40, Chris Wilson <chris@chris-wilson.co.uk> wrote:
> > >
> > > Quoting Arkadiusz Hiler (2019-10-31 12:40:35)
> > > > On Wed, Oct 30, 2019 at 10:22:37PM +0000, Matthew Auld wrote:
> > > > > On Tue, 29 Oct 2019 at 16:51, Matthew Auld <matthew.auld@intel.com> wrote:
> > > > > >
> > > > > > 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
> > > > >
> > > > > Hi Arek,
> > > > >
> > > > > Would you be able to update the fi-skl-lmem kernel cmd line with
> > > > > s/i915_fake_lmem_start/i915.fake_lmem_start?
> > > >
> > > > done
> > >
> > > <6>[  497.897456] [drm] Intel graphics fake LMEM: [mem 0x100000000-0x13fffffff]
> > > <6>[  497.897459] [drm] Intel graphics fake LMEM IO start: 40000000
> > > <6>[  497.897461] [drm] Intel graphics fake LMEM size: 40000000
> > >
> > > All present.
> > 
> > Arek,
> > 
> > Could we enable DRM_I915_UNSTABLE_FAKE_LMEM in CI? That should give us
> > some coverage of the fake local-memory setup on fi-skl-lmem.
> 
> Hey,
> 
>   config DRM_I915_UNSTABLE
>           bool "Enable unstable API for early prototype development"
>           depends on EXPERT
>           depends on STAGING
>           depends on BROKEN # should never be enabled by distros!
> 
>   config DRM_I915_UNSTABLE_FAKE_LMEM
>           bool "Enable the experimental fake lmem"
>           depends on DRM_I915_UNSTABLE
> 
> AFAIU because of that dependency on CONFIG_BROKEN we cannot just enable
> it through .config - we have to edit the value in init/Kconfig[0].

Before the revert last night, CONFIG_BROKEN was already enabled in
CI. It's now enabled again. The above output was from CI setting up lmem
without extra hackery.
-Chris
Arkadiusz Hiler Nov. 6, 2019, 1:58 p.m. UTC | #8
On Wed, Nov 06, 2019 at 11:17:29AM +0000, Chris Wilson wrote:
> Quoting Arkadiusz Hiler (2019-11-06 08:30:37)
> > On Tue, Nov 05, 2019 at 01:05:20PM +0000, Matthew Auld wrote:
> > > On Thu, 31 Oct 2019 at 20:40, Chris Wilson <chris@chris-wilson.co.uk> wrote:
> > > >
> > > > Quoting Arkadiusz Hiler (2019-10-31 12:40:35)
> > > > > On Wed, Oct 30, 2019 at 10:22:37PM +0000, Matthew Auld wrote:
> > > > > > On Tue, 29 Oct 2019 at 16:51, Matthew Auld <matthew.auld@intel.com> wrote:
> > > > > > >
> > > > > > > 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
> > > > > >
> > > > > > Hi Arek,
> > > > > >
> > > > > > Would you be able to update the fi-skl-lmem kernel cmd line with
> > > > > > s/i915_fake_lmem_start/i915.fake_lmem_start?
> > > > >
> > > > > done
> > > >
> > > > <6>[  497.897456] [drm] Intel graphics fake LMEM: [mem 0x100000000-0x13fffffff]
> > > > <6>[  497.897459] [drm] Intel graphics fake LMEM IO start: 40000000
> > > > <6>[  497.897461] [drm] Intel graphics fake LMEM size: 40000000
> > > >
> > > > All present.
> > > 
> > > Arek,
> > > 
> > > Could we enable DRM_I915_UNSTABLE_FAKE_LMEM in CI? That should give us
> > > some coverage of the fake local-memory setup on fi-skl-lmem.
> > 
> > Hey,
> > 
> >   config DRM_I915_UNSTABLE
> >           bool "Enable unstable API for early prototype development"
> >           depends on EXPERT
> >           depends on STAGING
> >           depends on BROKEN # should never be enabled by distros!
> > 
> >   config DRM_I915_UNSTABLE_FAKE_LMEM
> >           bool "Enable the experimental fake lmem"
> >           depends on DRM_I915_UNSTABLE
> > 
> > AFAIU because of that dependency on CONFIG_BROKEN we cannot just enable
> > it through .config - we have to edit the value in init/Kconfig[0].
> 
> Before the revert last night, CONFIG_BROKEN was already enabled in
> CI. It's now enabled again. The above output was from CI setting up lmem
> without extra hackery.
> -Chris

CI_DRM_7269 should have the DRM_I915_UNSTABLE_FAKE_LMEM enabled.
diff mbox series

Patch

diff --git a/drivers/gpu/drm/i915/gem/i915_gem_lmem.c b/drivers/gpu/drm/i915/gem/i915_gem_lmem.c
index 926f6c940e0d..0e2bf6b7e143 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_lmem.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_lmem.c
@@ -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);
 }
diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
index 21273b516dbe..db1736d95651 100644
--- a/drivers/gpu/drm/i915/i915_drv.c
+++ b/drivers/gpu/drm/i915/i915_drv.c
@@ -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.
+	 */
+	if (IS_ENABLED(CONFIG_DRM_I915_UNSTABLE)) {
+		if (INTEL_GEN(dev_priv) >= 9 && i915_selftest.live &&
+		    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;
diff --git a/drivers/gpu/drm/i915/i915_params.c b/drivers/gpu/drm/i915/i915_params.c
index 3fa79adb2c1c..9db3437fbd14 100644
--- a/drivers/gpu/drm/i915/i915_params.c
+++ b/drivers/gpu/drm/i915/i915_params.c
@@ -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)
+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,
diff --git a/drivers/gpu/drm/i915/i915_params.h b/drivers/gpu/drm/i915/i915_params.h
index a276317ad74b..31b88f297fbc 100644
--- a/drivers/gpu/drm/i915/i915_params.h
+++ b/drivers/gpu/drm/i915/i915_params.h
@@ -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) \
diff --git a/drivers/gpu/drm/i915/intel_memory_region.c b/drivers/gpu/drm/i915/intel_memory_region.c
index a60f77ff58d4..baaeaecc64af 100644
--- a/drivers/gpu/drm/i915/intel_memory_region.c
+++ b/drivers/gpu/drm/i915/intel_memory_region.c
@@ -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)) {
diff --git a/drivers/gpu/drm/i915/intel_memory_region.h b/drivers/gpu/drm/i915/intel_memory_region.h
index 19920c256ede..238722009677 100644
--- a/drivers/gpu/drm/i915/intel_memory_region.h
+++ b/drivers/gpu/drm/i915/intel_memory_region.h
@@ -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;
diff --git a/drivers/gpu/drm/i915/intel_region_lmem.c b/drivers/gpu/drm/i915/intel_region_lmem.c
index 9a351af45ce6..583118095635 100644
--- a/drivers/gpu/drm/i915/intel_region_lmem.c
+++ b/drivers/gpu/drm/i915/intel_region_lmem.c
@@ -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;
+}
diff --git a/drivers/gpu/drm/i915/intel_region_lmem.h b/drivers/gpu/drm/i915/intel_region_lmem.h
index ed2a3bab6443..213def7c7b8a 100644
--- a/drivers/gpu/drm/i915/intel_region_lmem.h
+++ b/drivers/gpu/drm/i915/intel_region_lmem.h
@@ -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 */