2017-02-13 17:15:17 +00:00
/*
* Copyright © 2016 Intel Corporation
*
* Permission is hereby granted , free of charge , to any person obtaining a
* copy of this software and associated documentation files ( the " Software " ) ,
* to deal in the Software without restriction , including without limitation
* the rights to use , copy , modify , merge , publish , distribute , sublicense ,
* and / or sell copies of the Software , and to permit persons to whom the
* Software is furnished to do so , subject to the following conditions :
*
* The above copyright notice and this permission notice ( including the next
* paragraph ) shall be included in all copies or substantial portions of the
* Software .
*
* THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND , EXPRESS OR
* IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY ,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT . IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM , DAMAGES OR OTHER
* LIABILITY , WHETHER IN AN ACTION OF CONTRACT , TORT OR OTHERWISE , ARISING
* FROM , OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE .
*
*/
2017-07-18 18:30:28 +01:00
# include <linux/pm_domain.h>
2017-02-13 17:15:17 +00:00
# include <linux/pm_runtime.h>
2019-06-21 08:07:41 +01:00
# include "gt/intel_gt.h"
2019-10-04 14:40:06 +01:00
# include "gt/intel_gt_requests.h"
2019-04-24 18:48:39 +01:00
# include "gt/mock_engine.h"
2017-02-13 17:15:19 +00:00
# include "mock_request.h"
2017-02-13 17:15:17 +00:00
# include "mock_gem_device.h"
2017-02-13 17:15:18 +00:00
# include "mock_gtt.h"
2017-04-12 10:21:43 +01:00
# include "mock_uncore.h"
2019-10-08 17:01:14 +01:00
# include "mock_region.h"
2017-02-13 17:15:17 +00:00
2019-05-28 10:29:49 +01:00
# include "gem/selftests/mock_context.h"
# include "gem/selftests/mock_gem_object.h"
2017-02-13 17:15:19 +00:00
void mock_device_flush ( struct drm_i915_private * i915 )
{
2019-10-22 10:47:23 +01:00
struct intel_gt * gt = & i915 - > gt ;
2017-02-13 17:15:19 +00:00
struct intel_engine_cs * engine ;
enum intel_engine_id id ;
drm/i915: Invert the GEM wakeref hierarchy
In the current scheme, on submitting a request we take a single global
GEM wakeref, which trickles down to wake up all GT power domains. This
is undesirable as we would like to be able to localise our power
management to the available power domains and to remove the global GEM
operations from the heart of the driver. (The intent there is to push
global GEM decisions to the boundary as used by the GEM user interface.)
Now during request construction, each request is responsible via its
logical context to acquire a wakeref on each power domain it intends to
utilize. Currently, each request takes a wakeref on the engine(s) and
the engines themselves take a chipset wakeref. This gives us a
transition on each engine which we can extend if we want to insert more
powermangement control (such as soft rc6). The global GEM operations
that currently require a struct_mutex are reduced to listening to pm
events from the chipset GT wakeref. As we reduce the struct_mutex
requirement, these listeners should evaporate.
Perhaps the biggest immediate change is that this removes the
struct_mutex requirement around GT power management, allowing us greater
flexibility in request construction. Another important knock-on effect,
is that by tracking engine usage, we can insert a switch back to the
kernel context on that engine immediately, avoiding any extra delay or
inserting global synchronisation barriers. This makes tracking when an
engine and its associated contexts are idle much easier -- important for
when we forgo our assumed execution ordering and need idle barriers to
unpin used contexts. In the process, it means we remove a large chunk of
code whose only purpose was to switch back to the kernel context.
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: Imre Deak <imre.deak@intel.com>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20190424200717.1686-5-chris@chris-wilson.co.uk
2019-04-24 21:07:17 +01:00
do {
2019-10-22 10:47:23 +01:00
for_each_engine ( engine , gt , id )
drm/i915: Invert the GEM wakeref hierarchy
In the current scheme, on submitting a request we take a single global
GEM wakeref, which trickles down to wake up all GT power domains. This
is undesirable as we would like to be able to localise our power
management to the available power domains and to remove the global GEM
operations from the heart of the driver. (The intent there is to push
global GEM decisions to the boundary as used by the GEM user interface.)
Now during request construction, each request is responsible via its
logical context to acquire a wakeref on each power domain it intends to
utilize. Currently, each request takes a wakeref on the engine(s) and
the engines themselves take a chipset wakeref. This gives us a
transition on each engine which we can extend if we want to insert more
powermangement control (such as soft rc6). The global GEM operations
that currently require a struct_mutex are reduced to listening to pm
events from the chipset GT wakeref. As we reduce the struct_mutex
requirement, these listeners should evaporate.
Perhaps the biggest immediate change is that this removes the
struct_mutex requirement around GT power management, allowing us greater
flexibility in request construction. Another important knock-on effect,
is that by tracking engine usage, we can insert a switch back to the
kernel context on that engine immediately, avoiding any extra delay or
inserting global synchronisation barriers. This makes tracking when an
engine and its associated contexts are idle much easier -- important for
when we forgo our assumed execution ordering and need idle barriers to
unpin used contexts. In the process, it means we remove a large chunk of
code whose only purpose was to switch back to the kernel context.
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: Imre Deak <imre.deak@intel.com>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20190424200717.1686-5-chris@chris-wilson.co.uk
2019-04-24 21:07:17 +01:00
mock_engine_flush ( engine ) ;
2019-10-22 10:47:23 +01:00
} while ( intel_gt_retire_requests_timeout ( gt , MAX_SCHEDULE_TIMEOUT ) ) ;
2017-02-13 17:15:19 +00:00
}
2017-02-13 17:15:17 +00:00
static void mock_device_release ( struct drm_device * dev )
{
struct drm_i915_private * i915 = to_i915 ( dev ) ;
2017-02-13 17:15:19 +00:00
struct intel_engine_cs * engine ;
enum intel_engine_id id ;
mock_device_flush ( i915 ) ;
2017-02-13 17:15:17 +00:00
2017-07-18 14:41:24 +01:00
i915_gem_drain_workqueue ( i915 ) ;
2017-02-13 17:15:19 +00:00
2019-10-22 10:47:23 +01:00
for_each_engine ( engine , & i915 - > gt , id )
2017-02-13 17:15:19 +00:00
mock_engine_free ( engine ) ;
2019-10-04 14:40:09 +01:00
i915_gem_driver_release__contexts ( i915 ) ;
2017-02-13 17:15:19 +00:00
2019-06-21 08:08:10 +01:00
intel_timelines_fini ( i915 ) ;
2019-01-28 10:23:56 +00:00
2017-02-13 17:15:19 +00:00
drain_workqueue ( i915 - > wq ) ;
2017-02-13 17:15:17 +00:00
i915_gem_drain_freed_objects ( i915 ) ;
2019-01-21 22:20:49 +00:00
mock_fini_ggtt ( & i915 - > ggtt ) ;
2017-02-13 17:15:19 +00:00
destroy_workqueue ( i915 - > wq ) ;
2019-10-18 10:07:49 +01:00
i915_gem_cleanup_memory_regions ( i915 ) ;
2017-12-09 21:08:35 +00:00
drm_mode_config_cleanup ( & i915 - > drm ) ;
2017-02-13 17:15:17 +00:00
drm_dev_fini ( & i915 - > drm ) ;
put_device ( & i915 - > drm . pdev - > dev ) ;
}
static struct drm_driver mock_driver = {
. name = " mock " ,
. driver_features = DRIVER_GEM ,
. release = mock_device_release ,
. gem_close_object = i915_gem_close_object ,
. gem_free_object_unlocked = i915_gem_free_object ,
} ;
static void release_dev ( struct device * dev )
{
struct pci_dev * pdev = to_pci_dev ( dev ) ;
kfree ( pdev ) ;
}
2017-07-18 18:30:28 +01:00
static int pm_domain_resume ( struct device * dev )
{
return pm_generic_runtime_resume ( dev ) ;
}
static int pm_domain_suspend ( struct device * dev )
{
return pm_generic_runtime_suspend ( dev ) ;
}
static struct dev_pm_domain pm_domain = {
. ops = {
. runtime_suspend = pm_domain_suspend ,
. runtime_resume = pm_domain_resume ,
} ,
} ;
2017-02-13 17:15:17 +00:00
struct drm_i915_private * mock_gem_device ( void )
{
struct drm_i915_private * i915 ;
struct pci_dev * pdev ;
int err ;
pdev = kzalloc ( sizeof ( * pdev ) + sizeof ( * i915 ) , GFP_KERNEL ) ;
if ( ! pdev )
goto err ;
device_initialize ( & pdev - > dev ) ;
2017-05-18 10:46:15 +01:00
pdev - > class = PCI_BASE_CLASS_DISPLAY < < 16 ;
2017-02-13 17:15:17 +00:00
pdev - > dev . release = release_dev ;
dev_set_name ( & pdev - > dev , " mock " ) ;
2019-01-07 18:18:56 +00:00
dma_coerce_mask_and_coherent ( & pdev - > dev , DMA_BIT_MASK ( 64 ) ) ;
2017-02-13 17:15:17 +00:00
2017-10-05 14:07:22 +02:00
# if IS_ENABLED(CONFIG_IOMMU_API) && defined(CONFIG_INTEL_IOMMU)
2017-09-14 17:22:40 +01:00
/* hack to disable iommu for the fake device; force identity mapping */
pdev - > dev . archdata . iommu = ( void * ) - 1 ;
2017-09-18 17:46:52 +01:00
# endif
2017-09-14 17:22:40 +01:00
2019-01-14 14:21:09 +00:00
i915 = ( struct drm_i915_private * ) ( pdev + 1 ) ;
pci_set_drvdata ( pdev , i915 ) ;
2017-07-18 18:30:28 +01:00
dev_pm_domain_set ( & pdev - > dev , & pm_domain ) ;
pm_runtime_enable ( & pdev - > dev ) ;
2017-02-13 17:15:17 +00:00
pm_runtime_dont_use_autosuspend ( & pdev - > dev ) ;
2018-07-06 21:59:47 +01:00
if ( pm_runtime_enabled ( & pdev - > dev ) )
WARN_ON ( pm_runtime_get_sync ( & pdev - > dev ) ) ;
2017-02-13 17:15:17 +00:00
err = drm_dev_init ( & i915 - > drm , & mock_driver , & pdev - > dev ) ;
if ( err ) {
pr_err ( " Failed to initialise mock GEM device: err=%d \n " , err ) ;
goto put_device ;
}
i915 - > drm . pdev = pdev ;
i915 - > drm . dev_private = i915 ;
2019-06-13 16:21:53 -07:00
intel_runtime_pm_init_early ( & i915 - > runtime_pm ) ;
2019-06-13 16:21:49 -07:00
2017-02-13 17:15:18 +00:00
/* Using the global GTT may ask questions about KMS users, so prepare */
drm_mode_config_init ( & i915 - > drm ) ;
2017-02-13 17:15:17 +00:00
mkwrite_device_info ( i915 ) - > gen = - 1 ;
2017-10-06 23:18:16 +01:00
mkwrite_device_info ( i915 ) - > page_sizes =
2017-10-06 23:18:32 +01:00
I915_GTT_PAGE_SIZE_4K |
2017-10-06 23:18:33 +01:00
I915_GTT_PAGE_SIZE_64K |
I915_GTT_PAGE_SIZE_2M ;
2017-10-06 23:18:16 +01:00
2019-10-18 10:07:50 +01:00
mkwrite_device_info ( i915 ) - > memory_regions = REGION_SMEM ;
2019-10-08 15:50:45 +01:00
mock_uncore_init ( & i915 - > uncore , i915 ) ;
2019-10-18 10:07:50 +01:00
2017-11-10 23:24:47 +00:00
i915_gem_init__mm ( i915 ) ;
2019-06-21 08:07:42 +01:00
intel_gt_init_early ( & i915 - > gt , i915 ) ;
drm/i915: Invert the GEM wakeref hierarchy
In the current scheme, on submitting a request we take a single global
GEM wakeref, which trickles down to wake up all GT power domains. This
is undesirable as we would like to be able to localise our power
management to the available power domains and to remove the global GEM
operations from the heart of the driver. (The intent there is to push
global GEM decisions to the boundary as used by the GEM user interface.)
Now during request construction, each request is responsible via its
logical context to acquire a wakeref on each power domain it intends to
utilize. Currently, each request takes a wakeref on the engine(s) and
the engines themselves take a chipset wakeref. This gives us a
transition on each engine which we can extend if we want to insert more
powermangement control (such as soft rc6). The global GEM operations
that currently require a struct_mutex are reduced to listening to pm
events from the chipset GT wakeref. As we reduce the struct_mutex
requirement, these listeners should evaporate.
Perhaps the biggest immediate change is that this removes the
struct_mutex requirement around GT power management, allowing us greater
flexibility in request construction. Another important knock-on effect,
is that by tracking engine usage, we can insert a switch back to the
kernel context on that engine immediately, avoiding any extra delay or
inserting global synchronisation barriers. This makes tracking when an
engine and its associated contexts are idle much easier -- important for
when we forgo our assumed execution ordering and need idle barriers to
unpin used contexts. In the process, it means we remove a large chunk of
code whose only purpose was to switch back to the kernel context.
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: Imre Deak <imre.deak@intel.com>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20190424200717.1686-5-chris@chris-wilson.co.uk
2019-04-24 21:07:17 +01:00
atomic_inc ( & i915 - > gt . wakeref . count ) ; /* disable; no hw support */
2019-09-27 22:17:48 +01:00
i915 - > gt . awake = - ENODEV ;
2017-02-13 17:15:17 +00:00
2017-02-13 17:15:19 +00:00
i915 - > wq = alloc_ordered_workqueue ( " mock " , 0 ) ;
if ( ! i915 - > wq )
2017-12-09 21:08:35 +00:00
goto err_drv ;
2017-02-13 17:15:19 +00:00
2017-06-20 12:05:46 +01:00
mock_init_contexts ( i915 ) ;
2017-02-13 17:15:19 +00:00
2019-06-21 08:08:10 +01:00
intel_timelines_init ( i915 ) ;
2019-01-28 10:23:56 +00:00
2019-01-21 22:20:49 +00:00
mock_init_ggtt ( i915 , & i915 - > ggtt ) ;
2019-10-22 10:58:51 +01:00
i915 - > gt . ggtt = & i915 - > ggtt ;
2017-02-13 17:15:18 +00:00
2019-03-05 18:03:30 +00:00
mkwrite_device_info ( i915 ) - > engine_mask = BIT ( 0 ) ;
2018-05-23 15:23:46 +01:00
2019-03-05 18:03:30 +00:00
i915 - > engine [ RCS0 ] = mock_engine ( i915 , " mock " , RCS0 ) ;
if ( ! i915 - > engine [ RCS0 ] )
2019-04-26 17:33:33 +01:00
goto err_unlock ;
i915 - > kernel_context = mock_context ( i915 , NULL ) ;
if ( ! i915 - > kernel_context )
goto err_engine ;
if ( mock_engine_init ( i915 - > engine [ RCS0 ] ) )
2018-05-23 15:23:46 +01:00
goto err_context ;
2017-02-13 17:15:19 +00:00
2019-08-08 20:45:25 +01:00
intel_engines_driver_register ( i915 ) ;
2018-05-08 22:10:56 +01:00
2019-10-18 10:07:49 +01:00
err = i915_gem_init_memory_regions ( i915 ) ;
if ( err )
goto err_context ;
2017-02-13 17:15:17 +00:00
return i915 ;
2018-05-23 15:23:46 +01:00
err_context :
2019-10-04 14:40:09 +01:00
i915_gem_driver_release__contexts ( i915 ) ;
2019-04-26 17:33:33 +01:00
err_engine :
mock_engine_free ( i915 - > engine [ RCS0 ] ) ;
2018-05-08 22:10:56 +01:00
err_unlock :
2019-06-21 08:08:10 +01:00
intel_timelines_fini ( i915 ) ;
2017-02-13 17:15:19 +00:00
destroy_workqueue ( i915 - > wq ) ;
2017-12-09 21:08:35 +00:00
err_drv :
drm_mode_config_cleanup ( & i915 - > drm ) ;
drm_dev_fini ( & i915 - > drm ) ;
2017-02-13 17:15:17 +00:00
put_device :
put_device ( & pdev - > dev ) ;
err :
return NULL ;
}