Share TTM code among framebuffer drivers
Subsystems (8)
Thomas Zimmermann
maintainerPATCH 2/15 drm: Add |struct drm_gem_ttm_object| callbacks for |struct ttm_bo_driver|
In reply to Thomas ZimmermannThe provided helpers can be used for the respective callback functions in |struct ttm_bo_driver|.
--- drivers/gpu/drm/drm_gem_ttm_helper.c | 39 ++++++++++++++++++++++++++++ include/drm/drm_gem_ttm_helper.h | 10 +++++++ 2 files changed, 49 insertions(+)
drivers/gpu/drm/drm_gem_ttm_helper.c +39 -0
@@ -365,3 +365,42 @@ bool drm_is_gem_ttm(struct ttm_buffer_object *bo)return (bo->destroy == ttm_buffer_object_destroy); }EXPORT_SYMBOL (drm_is_gem_ttm); + +/* +* Helpers for struct ttm_bo_driver +*/ + +/** +* drm_gem_ttm_bo_driver_evict_flags - \ +Implements struct ttm_bo_driver.evict_flags +*/ +void drm_gem_ttm_bo_driver_evict_flags (struct ttm_buffer_object *bo, +struct ttm_placement *pl) +{ +struct drm_gem_ttm_object *gbo; + +/* TODO: This test used to be performed by drivers, but can +* this actually happen? If so, should we put the check into +* drm_gem_ttm_of_gem()? */ +if (!drm_is_gem_ttm (bo)) +return ; + + gbo =drm_gem_ttm_of_bo (bo); +drm_gem_ttm_placement (gbo,TTM_PL_FLAG_SYSTEM ); + *pl = gbo->placement; +} +EXPORT_SYMBOL (drm_gem_ttm_bo_driver_evict_flags); + +/** +* drm_gem_ttm_bo_driver_verify_access - \ +Implements struct ttm_bo_driver.verify_access +*/ +int drm_gem_ttm_bo_driver_verify_access (struct ttm_buffer_object *bo, +struct file *filp) +{ +struct drm_gem_ttm_object *gbo =drm_gem_ttm_of_bo (bo); + +return drm_vma_node_verify_access (&gbo->gem.vma_node, + filp->private_data); +} +EXPORT_SYMBOL (drm_gem_ttm_bo_driver_verify_access);
include/drm/drm_gem_ttm_helper.h +10 -0
@@ -88,4 +88,14 @@ void drm_gem_ttm_kunmap(struct drm_gem_ttm_object *gbo);bool drm_is_gem_ttm (struct ttm_buffer_object *bo); +/* +* Helpers for struct ttm_bo_driver +*/ + +void drm_gem_ttm_bo_driver_evict_flags (struct ttm_buffer_object *bo, +struct ttm_placement *pl); + +int drm_gem_ttm_bo_driver_verify_access (struct ttm_buffer_object *bo, +struct file *filp); +#endif
Signature · 6 lines
2.21.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Thomas Zimmermann
maintainercover Share TTM code among framebuffer drivers
Several simple framebuffer drivers copy most of the TTM code from each other. The implementation is always the same; except for the name of some data structures.
As recently discussed, this patch set provides generic TTM memory- management code for framebuffers with dedicated video memory. It further converts the respective drivers to the generic code. The shared code is basically the same implementation as the one copied among individual drivers.
The patch set contains two major changes: first, it introduces |struct drm_gem_ttm_object| and helpers. It's a GEM object that is backed by TTM-managed memory. The type's purpose is somewhat similar to |struct drm_gem_{cma, shmem}_object|. Second, the patch set introduces |struct drm_simple_ttm| (for the lack of a better name) and helpers. It's an implementation of a basic TTM-based memory manager.
Both, GEM TTM and Simple TTM, support VRAM and SYSTEM placements. Support for TT could probably be added if necessary. Both can be used independedly from each other if desired by the DRM driver.
Currently ast, bochs, mgag200, vboxvideo and hisilicon/hibmc can use these helpers. Cirrus would also be a candidate, but as it's being rewrtten from scratch, I didn't bother doing the conversion.
Future directions: with these changes, the respective drivers can also share some of their mode-setting or fbdev code. GEM TTM could implement PRIME helpers, which would allow for using the generic fbcon.
The patch set is against a recent drm-tip.
Thomas Zimmermann (15):
drm: Add |struct drm_gem_ttm_object| and helpers drm: Add |struct drm_gem_ttm_object| callbacks for |struct
ttm_bo_driver|
drm: Add |struct drm_gem_ttm_object| callbacks for |struct drm_driver|
drm: Add drm_gem_ttm_fill_create_dumb() to create dumb buffers
drm: Add Simple TTM, a memory manager for dedicated VRAM drm/ast: Convert AST driver to |struct drm_gem_ttm_object| drm/ast: Convert AST driver to Simple TTM
drm/bochs: Convert Bochs driver to |struct drm_gem_ttm_object| drm/bochs: Convert Bochs driver to Simple TTM
drm/mgag200: Convert mgag200 driver to |struct drm_gem_ttm_object| drm/mgag200: Convert mgag200 driver to Simple TTM drm/vboxvideo: Convert vboxvideo driver to |struct drm_gem_ttm_object| drm/vboxvideo: Convert vboxvideo driver to Simple TTM drm/hisilicon: Convert hibmc-drm driver to |struct drm_gem_ttm_object| drm/hisilicon: Convert hibmc-drm driver to Simple TTM
Documentation/gpu/drm-mm.rst | 23 + drivers/gpu/drm/Kconfig | 20 + drivers/gpu/drm/Makefile | 5 + drivers/gpu/drm/ast/Kconfig | 3 +- drivers/gpu/drm/ast/ast_drv.c | 4 +- drivers/gpu/drm/ast/ast_drv.h | 58 +- drivers/gpu/drm/ast/ast_fb.c | 18 +- drivers/gpu/drm/ast/ast_main.c | 74 +-- drivers/gpu/drm/ast/ast_mode.c | 78 +-- drivers/gpu/drm/ast/ast_ttm.c | 290 +--------- drivers/gpu/drm/bochs/Kconfig | 2 + drivers/gpu/drm/bochs/bochs.h | 42 +- drivers/gpu/drm/bochs/bochs_drv.c | 4 +- drivers/gpu/drm/bochs/bochs_kms.c | 18 +- drivers/gpu/drm/bochs/bochs_mm.c | 392 +------------- drivers/gpu/drm/drm_gem_ttm_helper.c | 507 ++++++++++++++++++ drivers/gpu/drm/drm_simple_ttm_helper.c | 191 +++++++ drivers/gpu/drm/drm_ttm_helper_common.c | 6 + drivers/gpu/drm/hisilicon/hibmc/Kconfig | 2 + .../gpu/drm/hisilicon/hibmc/hibmc_drm_de.c | 19 +- .../gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c | 4 +- .../gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h | 28 +- .../gpu/drm/hisilicon/hibmc/hibmc_drm_fbdev.c | 30 +- drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c | 328 +---------- drivers/gpu/drm/mgag200/Kconfig | 2 + drivers/gpu/drm/mgag200/mgag200_cursor.c | 61 ++- drivers/gpu/drm/mgag200/mgag200_drv.c | 4 +- drivers/gpu/drm/mgag200/mgag200_drv.h | 68 +-- drivers/gpu/drm/mgag200/mgag200_fb.c | 18 +- drivers/gpu/drm/mgag200/mgag200_main.c | 84 +-- drivers/gpu/drm/mgag200/mgag200_mode.c | 45 +- drivers/gpu/drm/mgag200/mgag200_ttm.c | 290 +--------- drivers/gpu/drm/vboxvideo/Kconfig | 2 + drivers/gpu/drm/vboxvideo/vbox_drv.c | 5 +- drivers/gpu/drm/vboxvideo/vbox_drv.h | 64 +-- drivers/gpu/drm/vboxvideo/vbox_fb.c | 22 +- drivers/gpu/drm/vboxvideo/vbox_main.c | 70 +-- drivers/gpu/drm/vboxvideo/vbox_mode.c | 36 +- drivers/gpu/drm/vboxvideo/vbox_ttm.c | 344 +----------- include/drm/drm_gem_ttm_helper.h | 119 ++++ include/drm/drm_simple_ttm_helper.h | 74 +++ 41 files changed, 1292 insertions(+), 2162 deletions(-) create mode 100644 drivers/gpu/drm/drm_gem_ttm_helper.c create mode 100644 drivers/gpu/drm/drm_simple_ttm_helper.c create mode 100644 drivers/gpu/drm/drm_ttm_helper_common.c create mode 100644 include/drm/drm_gem_ttm_helper.h create mode 100644 include/drm/drm_simple_ttm_helper.h
--
2.21.0
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Thomas Zimmermann
maintainerPATCH 1/15 drm: Add |struct drm_gem_ttm_object| and helpers
The type |struct drm_gem_ttm_object| implements a TTM buffer object for simple framebuffer devices with dedicated video memory. The BO is either located in VRAM or system memory. The implementation has been created from the respective code in ast, bochs and mgag200. These drivers copy their implementation from each other; except for the names of several data types.
--- Documentation/gpu/drm-mm.rst | 12 + drivers/gpu/drm/Kconfig | 13 + drivers/gpu/drm/Makefile | 4 + drivers/gpu/drm/drm_gem_ttm_helper.c | 367 ++++++++++++++++++++++++ drivers/gpu/drm/drm_ttm_helper_common.c | 6 + include/drm/drm_gem_ttm_helper.h | 91 ++++++ 6 files changed, 493 insertions(+) create mode 100644 drivers/gpu/drm/drm_gem_ttm_helper.c create mode 100644 drivers/gpu/drm/drm_ttm_helper_common.c create mode 100644 include/drm/drm_gem_ttm_helper.h
Documentation/gpu/drm-mm.rst +12 -0
@@ -380,6 +380,18 @@ GEM CMA Helper Functions Reference .. kernel-doc:: drivers/gpu/drm/drm_gem_cma_helper.c :export: +GEM TTM Helper Functions Reference +---------------------------------- + +.. kernel-doc:: drivers/gpu/drm/drm_gem_ttm_helper.c + :doc: overview + +.. kernel-doc:: include/drm/drm_gem_ttm_helper.h + :internal: + +.. kernel-doc:: drivers/gpu/drm/drm_gem_ttm_helper.c + :export: + VMA Offset Manager ==================
drivers/gpu/drm/Kconfig +13 -0
@@ -160,6 +160,12 @@ config DRM_TTM GPU memory types. Will be enabled automatically if a device driver uses it. +config DRM_TTM_HELPER + tristate + depends on DRM && DRM_TTM + help + Helpers for TTM-based memory management + config DRM_GEM_CMA_HELPER bool depends on DRM
@@ -179,6 +185,13 @@ config DRM_GEM_SHMEM_HELPER help Choose this if you need the GEM shmem helper functions +config DRM_GEM_TTM_HELPER + bool + depends on DRM + select DRM_TTM_HELPER + help + Choose this if you need the GEM TTM helper functions + config DRM_VM bool depends on DRM && MMU
drivers/gpu/drm/Makefile +4 -0
@@ -33,6 +33,10 @@ drm-$(CONFIG_AGP) += drm_agpsupport.o drm-$(CONFIG_DEBUG_FS) += drm_debugfs.o drm_debugfs_crc.o drm-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) += drm_edid_load.o +drm_ttm_helper-y := drm_ttm_helper_common.o +drm_ttm_helper-$(CONFIG_DRM_GEM_TTM_HELPER) += drm_gem_ttm_helper.o +obj-$(CONFIG_DRM_TTM_HELPER) += drm_ttm_helper.o + drm_kms_helper-y := drm_crtc_helper.o drm_dp_helper.o drm_dsc.o drm_probe_helper.o \ drm_plane_helper.o drm_dp_mst_topology.o drm_atomic_helper.o \ drm_kms_helper_common.o drm_dp_dual_mode_helper.o \
drivers/gpu/drm/drm_gem_ttm_helper.c new file +367 -0
367 lines not on this page · raw message
drivers/gpu/drm/drm_ttm_helper_common.c new file +6 -0
@@ -0,0 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include <linux/module.h> + +MODULE_DESCRIPTION ("DRM TTM memory-management helpers" ); +MODULE_LICENSE ("GPL" );
include/drm/drm_gem_ttm_helper.h new file +91 -0
91 lines not on this page · raw message
Signature · 6 lines
2.21.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Thomas Zimmermann
maintainerPATCH 3/15 drm: Add |struct drm_gem_ttm_object| callbacks for |struct drm_driver|
In reply to Thomas ZimmermannThe provided helpers can be used for the respective callback functions in |struct drm_driver|.
--- drivers/gpu/drm/drm_gem_ttm_helper.c | 39 ++++++++++++++++++++++++++++ include/drm/drm_gem_ttm_helper.h | 10 +++++++ 2 files changed, 49 insertions(+)
drivers/gpu/drm/drm_gem_ttm_helper.c +39 -0
@@ -404,3 +404,42 @@ int drm_gem_ttm_bo_driver_verify_access(struct ttm_buffer_object *bo, filp->private_data); }EXPORT_SYMBOL (drm_gem_ttm_bo_driver_verify_access); + +/* +* Helpers for struct drm_driver +*/ + +/** +* drm_gem_ttm_driver_gem_free_object_unlocked() - \ +Implements struct drm_driver.gem_free_object_unlocked +*/ +void drm_gem_ttm_driver_gem_free_object_unlocked (struct drm_gem_object *gem) +{ +struct drm_gem_ttm_object *gbo =drm_gem_ttm_of_gem (gem); +drm_gem_ttm_put (gbo); +} +EXPORT_SYMBOL (drm_gem_ttm_driver_gem_free_object_unlocked); + +/** +* drm_gem_ttm_driver_dumb_mmap_offset() - \ +Implements struct drm_driver.dumb_mmap_offset +*/ +int drm_gem_ttm_driver_dumb_mmap_offset (struct drm_file *file, +struct drm_device *dev, +uint32_t handle,uint64_t *offset) +{ +struct drm_gem_object *gem; +struct drm_gem_ttm_object *gbo; + + gem =drm_gem_object_lookup (file, handle); +if (!gem) +return -ENOENT ; + + gbo =drm_gem_ttm_of_gem (gem); + *offset =drm_gem_ttm_mmap_offset (gbo); + +drm_gem_object_put_unlocked (gem); + +return 0 ; +} +EXPORT_SYMBOL (drm_gem_ttm_driver_dumb_mmap_offset);
include/drm/drm_gem_ttm_helper.h +10 -0
@@ -98,4 +98,14 @@ void drm_gem_ttm_bo_driver_evict_flags(struct ttm_buffer_object *bo,int drm_gem_ttm_bo_driver_verify_access (struct ttm_buffer_object *bo,struct file *filp); +/* +* Helpers for struct drm_driver +*/ + +void drm_gem_ttm_driver_gem_free_object_unlocked (struct drm_gem_object *gem); + +int drm_gem_ttm_driver_dumb_mmap_offset (struct drm_file *file, +struct drm_device *dev, +uint32_t handle,uint64_t *offset); +#endif
Signature · 6 lines
2.21.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Thomas Zimmermann
maintainerPATCH 4/15 drm: Add drm_gem_ttm_fill_create_dumb() to create dumb buffers
In reply to Thomas ZimmermannThe helper function drm_gem_ttm_fill_create_dumb() implements most of struct drm_driver.dumb_create() for GEM TTM buffer objects. It's not a full implemenation of the callback, as several driver-specific parameters are still required.
--- drivers/gpu/drm/drm_gem_ttm_helper.c | 62 ++++++++++++++++++++++++++++ include/drm/drm_gem_ttm_helper.h | 8 ++++ 2 files changed, 70 insertions(+)
drivers/gpu/drm/drm_gem_ttm_helper.c +62 -0
@@ -1,6 +1,7 @@/* SPDX-License-Identifier: GPL-2.0-or-later */ #include <drm/drm_gem_ttm_helper.h> +#include <drm/drm_mode.h> #include <drm/ttm/ttm_page_alloc.h> /**
@@ -366,6 +367,67 @@ bool drm_is_gem_ttm(struct ttm_buffer_object *bo) }EXPORT_SYMBOL (drm_is_gem_ttm); +/** +* drm_gem_ttm_fill_create_dumb() - \ +Helper for implementing struct drm_driver.dumb_create +* @file: the DRM file +* @dev: the DRM device +* @bdev: the TTM BO device managing the buffer object +* @pg_align: the buffer's alignment in multiples of the page size +* @interruptible: sleep interruptible if waiting for memory +* @args: the arguments as provided to \ +struct drm_driver.dumb_create +* +* This helper function fills struct drm_mode_create_dumb, which is used +* by struct drm_driver.dumb_create. Implementations of this interface +* should forwards their arguments to this helper; plus the driver-specific +* parameters. +* +* Returns: +* 0 on success, or +* a negative error code otherwise. +*/ +int drm_gem_ttm_fill_create_dumb (struct drm_file *file, +struct drm_device *dev, +struct ttm_bo_device *bdev, +uint32_t pg_align, +bool interruptible, +struct drm_mode_create_dumb *args) +{ +size_t pitch, size; +struct drm_gem_ttm_object *gbo; +int ret; +u32 handle; + + pitch = args->width * ((args->bpp +7 ) /8 ); + size = pitch * args->height; + + size =roundup (size,PAGE_SIZE ); +if (!size) +return -EINVAL ; + + gbo =drm_gem_ttm_create (dev, bdev, size, pg_align, interruptible); +if (IS_ERR (gbo)) +return PTR_ERR (gbo); + + ret =drm_gem_handle_create (file, &gbo->gem, &handle); +if (ret) + goto err_drm_gem_object_put_unlocked; + +drm_gem_object_put_unlocked (&gbo->gem); + + args->pitch = pitch; + args->size = size; + args->handle = handle; + +return 0 ; + +err_drm_gem_object_put_unlocked: +drm_gem_object_put_unlocked (&gbo->gem); +return ret; +} +EXPORT_SYMBOL (drm_gem_ttm_fill_create_dumb); +/* * Helpers for struct ttm_bo_driver */
include/drm/drm_gem_ttm_helper.h +8 -0
@@ -8,6 +8,7 @@#include <drm/ttm/ttm_placement.h> #include <linux/kernel.h> /* for container_of() */ +struct drm_mode_create_dumb ;struct filp ;/*
@@ -88,6 +89,13 @@ void drm_gem_ttm_kunmap(struct drm_gem_ttm_object *gbo);bool drm_is_gem_ttm (struct ttm_buffer_object *bo); +int drm_gem_ttm_fill_create_dumb (struct drm_file *file, +struct drm_device *dev, +struct ttm_bo_device *bdev, +uint32_t pg_align, +bool interruptible, +struct drm_mode_create_dumb *args); +/* * Helpers for struct ttm_bo_driver */
Signature · 6 lines
2.21.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Thomas Zimmermann
maintainerPATCH 5/15 drm: Add Simple TTM, a memory manager for dedicated VRAM
In reply to Thomas ZimmermannThe Simple TTM memory manager is a helper library that manages dedicated video memory of simple framebuffer devices. The implementation is based on the respective code from ast, bochs, and mgag200. These drivers share the exact same implementation execept for type names.
--- Documentation/gpu/drm-mm.rst | 11 ++ drivers/gpu/drm/Kconfig | 7 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/drm_simple_ttm_helper.c | 191 ++++++++++++++++++++++++ include/drm/drm_simple_ttm_helper.h | 74 +++++++++ 5 files changed, 284 insertions(+) create mode 100644 drivers/gpu/drm/drm_simple_ttm_helper.c create mode 100644 include/drm/drm_simple_ttm_helper.h
Documentation/gpu/drm-mm.rst +11 -0
@@ -79,6 +79,17 @@ count for the TTM, which will call your initialization function. See the radeon_ttm.c file for an example of usage. +Simple TTM Helper Functions Reference +------------------------------------- + +.. kernel-doc:: drivers/gpu/drm/drm_simple_ttm_helper.c + :doc: overview + +.. kernel-doc:: include/drm/drm_simple_ttm_helper.h + :internal: + +.. kernel-doc:: drivers/gpu/drm/drm_simple_ttm_helper.c + :export: The Graphics Execution Manager (GEM) ====================================
drivers/gpu/drm/Kconfig +7 -0
@@ -166,6 +166,13 @@ config DRM_TTM_HELPER help Helpers for TTM-based memory management +config DRM_SIMPLE_TTM_HELPER + tristate + depends on DRM && DRM_TTM + select DRM_TTM_HELPER + help + Choose this if you need the Simple TTM helper functions + config DRM_GEM_CMA_HELPER bool depends on DRM
drivers/gpu/drm/Makefile +1 -0
@@ -35,6 +35,7 @@ drm-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) += drm_edid_load.o drm_ttm_helper-y := drm_ttm_helper_common.o drm_ttm_helper-$(CONFIG_DRM_GEM_TTM_HELPER) += drm_gem_ttm_helper.o +drm_ttm_helper-$(CONFIG_DRM_SIMPLE_TTM_HELPER) += drm_simple_ttm_helper.o obj-$(CONFIG_DRM_TTM_HELPER) += drm_ttm_helper.o drm_kms_helper-y := drm_crtc_helper.o drm_dp_helper.o drm_dsc.o drm_probe_helper.o \
drivers/gpu/drm/drm_simple_ttm_helper.c new file +191 -0
191 lines not on this page · raw message
include/drm/drm_simple_ttm_helper.h new file +74 -0
74 lines not on this page · raw message
Signature · 6 lines
2.21.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Thomas Zimmermann
maintainerPATCH 6/15 drm/ast: Convert AST driver to |struct drm_gem_ttm_object|
In reply to Thomas Zimmermann--- drivers/gpu/drm/ast/Kconfig | 2 +- drivers/gpu/drm/ast/ast_drv.c | 4 +- drivers/gpu/drm/ast/ast_drv.h | 52 +--------- drivers/gpu/drm/ast/ast_fb.c | 18 ++-- drivers/gpu/drm/ast/ast_main.c | 74 ++------------ drivers/gpu/drm/ast/ast_mode.c | 78 +++++++++------ drivers/gpu/drm/ast/ast_ttm.c | 172 +-------------------------------- 7 files changed, 70 insertions(+), 330 deletions(-)
drivers/gpu/drm/ast/Kconfig +1 -1
@@ -3,7 +3,7 @@ config DRM_AST depends on DRM && PCI && MMU select DRM_TTM select DRM_KMS_HELPER - select DRM_TTM + select DRM_GEM_TTM_HELPER help Say yes for experimental AST GPU driver. Do not enable this driver without having a working -modesetting,
drivers/gpu/drm/ast/ast_drv.c +2 -2
@@ -228,9 +228,9 @@ static struct drm_driver driver = { .minor = DRIVER_MINOR, .patchlevel = DRIVER_PATCHLEVEL, - .gem_free_object_unlocked = ast_gem_free_object, + .gem_free_object_unlocked = drm_gem_ttm_driver_gem_free_object_unlocked, .dumb_create = ast_dumb_create, - .dumb_map_offset = ast_dumb_mmap_offset, + .dumb_map_offset = drm_gem_ttm_driver_dumb_mmap_offset, };
drivers/gpu/drm/ast/ast_drv.h +1 -51
77 lines not on this page · raw message
drivers/gpu/drm/ast/ast_fb.c +9 -9
@@ -49,7 +49,7 @@ static void ast_dirty_update(struct ast_fbdev *afbdev, {int i;struct drm_gem_object *obj; -struct ast_bo *bo; +struct drm_gem_ttm_object *gbo;int src_offset, dst_offset;int bpp = afbdev->afb.base.format->cpp[0 ];int ret = -EBUSY ;
@@ -59,7 +59,7 @@ static void ast_dirty_update(struct ast_fbdev *afbdev,unsigned long flags; obj = afbdev->afb.obj; - bo =gem_to_ast_bo (obj); + gbo =drm_gem_ttm_of_gem (obj);/* * try and reserve the BO, if we fail with busy
@@ -67,7 +67,7 @@ static void ast_dirty_update(struct ast_fbdev *afbdev,* store up the damage until later. */ if (drm_can_sleep ()) - ret =ast_bo_reserve (bo, true); + ret =drm_gem_ttm_reserve (gbo, true);if (ret) {if (ret != -EBUSY )return ;
@@ -101,11 +101,11 @@ static void ast_dirty_update(struct ast_fbdev *afbdev, afbdev->x2 = afbdev->y2 =0 ;spin_unlock_irqrestore (&afbdev->dirty_lock, flags); -if (!bo->kmap.virtual) { - ret =ttm_bo_kmap (&bo->bo,0 , bo->bo.num_pages, &bo->kmap); +if (!gbo->kmap.virtual) { + ret =ttm_bo_kmap (&gbo->bo,0 , gbo->bo.num_pages, &gbo->kmap);if (ret) {DRM_ERROR ("failed to kmap fb updates\n" ); -ast_bo_unreserve (bo); +drm_gem_ttm_unreserve (gbo);return ; } unmap = true;
@@ -113,13 +113,13 @@ static void ast_dirty_update(struct ast_fbdev *afbdev,for (i = y; i <= y2; i++) {/* assume equal stride for now */ src_offset = dst_offset = i * afbdev->afb.base.pitches[0 ] + (x * bpp); -memcpy_toio (bo->kmap.virtual + src_offset, afbdev->sysram + src_offset, (x2 - x +1 ) * bpp); +memcpy_toio (gbo->kmap.virtual + src_offset, afbdev->sysram + src_offset, (x2 - x +1 ) * bpp); }if (unmap) -ttm_bo_kunmap (&bo->kmap); +ttm_bo_kunmap (&gbo->kmap); -ast_bo_unreserve (bo); +drm_gem_ttm_unreserve (gbo); } static void ast_fillrect(struct fb_info *info,
drivers/gpu/drm/ast/ast_main.c +9 -65
95 lines not on this page · raw message
drivers/gpu/drm/ast/ast_mode.c +46 -32
164 lines not on this page · raw message
drivers/gpu/drm/ast/ast_ttm.c +2 -170
197 lines not on this page · raw message
Signature · 6 lines
2.21.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Thomas Zimmermann
maintainerPATCH 7/15 drm/ast: Convert AST driver to Simple TTM
In reply to Thomas Zimmermann--- drivers/gpu/drm/ast/Kconfig | 1 + drivers/gpu/drm/ast/ast_drv.h | 6 +- drivers/gpu/drm/ast/ast_ttm.c | 120 ++-------------------------------- 3 files changed, 11 insertions(+), 116 deletions(-)
drivers/gpu/drm/ast/Kconfig +1 -0
@@ -4,6 +4,7 @@ config DRM_AST select DRM_TTM select DRM_KMS_HELPER select DRM_GEM_TTM_HELPER + select DRM_SIMPLE_TTM_HELPER help Say yes for experimental AST GPU driver. Do not enable this driver without having a working -modesetting,
drivers/gpu/drm/ast/ast_drv.h +3 -3
@@ -40,6 +40,8 @@#include <drm/drm_gem.h> #include <drm/drm_gem_ttm_helper.h> +#include <drm/drm_simple_ttm_helper.h> +#include <linux/i2c.h> #include <linux/i2c-algo-bit.h>
@@ -104,9 +106,7 @@ struct ast_private {int fb_mtrr; -struct { -struct ttm_bo_device bdev; - } ttm; +struct drm_simple_ttm ttm;struct drm_gem_object *cursor_cache;uint64_t cursor_cache_gpu_addr;
drivers/gpu/drm/ast/ast_ttm.c +7 -113
141 lines not on this page · raw message
Signature · 6 lines
2.21.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Thomas Zimmermann
maintainerPATCH 8/15 drm/bochs: Convert Bochs driver to |struct drm_gem_ttm_object|
In reply to Thomas Zimmermann--- drivers/gpu/drm/bochs/Kconfig | 1 + drivers/gpu/drm/bochs/bochs.h | 34 +--- drivers/gpu/drm/bochs/bochs_drv.c | 4 +- drivers/gpu/drm/bochs/bochs_kms.c | 18 +- drivers/gpu/drm/bochs/bochs_mm.c | 269 +++--------------------------- 5 files changed, 34 insertions(+), 292 deletions(-)
drivers/gpu/drm/bochs/Kconfig +1 -0
@@ -3,6 +3,7 @@ config DRM_BOCHS depends on DRM && PCI && MMU select DRM_KMS_HELPER select DRM_TTM + select DRM_GEM_TTM_HELPER help Choose this option for qemu. If M is selected the module will be called bochs-drm.
drivers/gpu/drm/bochs/bochs.h +1 -33
@@ -9,6 +9,7 @@#include <drm/drm_fb_helper.h> #include <drm/drm_gem.h> +#include <drm/drm_gem_ttm_helper.h> #include <drm/ttm/ttm_bo_driver.h> #include <drm/ttm/ttm_page_alloc.h>
@@ -81,30 +82,6 @@ struct bochs_device { } ttm; }; -struct bochs_bo { -struct ttm_buffer_object bo; -struct ttm_placement placement; -struct ttm_bo_kmap_obj kmap; -struct drm_gem_object gem; -struct ttm_place placements[3 ]; -int pin_count; -}; - -static inline struct bochs_bo *bochs_bo (struct ttm_buffer_object *bo) -{ - return container_of(bo, struct bochs_bo, bo); -} - -static inline struct bochs_bo *gem_to_bochs_bo (struct drm_gem_object *gem) -{ - return container_of(gem, struct bochs_bo, gem); -} - -static inline u64 bochs_bo_mmap_offset (struct bochs_bo *bo) -{ -return drm_vma_node_offset_addr (&bo->bo.vma_node); -} -/* ---------------------------------------------------------------------- */ /* bochs_hw.c */
@@ -124,17 +101,8 @@ int bochs_mm_init(struct bochs_device *bochs);void bochs_mm_fini (struct bochs_device *bochs);int bochs_mmap (struct file *filp,struct vm_area_struct *vma); -int bochs_gem_create (struct drm_device *dev,u32 size,bool iskernel, -struct drm_gem_object **obj); -int bochs_gem_init_object (struct drm_gem_object *obj); -void bochs_gem_free_object (struct drm_gem_object *obj);int bochs_dumb_create (struct drm_file *file,struct drm_device *dev,struct drm_mode_create_dumb *args); -int bochs_dumb_mmap_offset (struct drm_file *file,struct drm_device *dev, -uint32_t handle,uint64_t *offset); - -int bochs_bo_pin (struct bochs_bo *bo,u32 pl_flag); -int bochs_bo_unpin (struct bochs_bo *bo);int bochs_gem_prime_pin (struct drm_gem_object *obj);void bochs_gem_prime_unpin (struct drm_gem_object *obj);
drivers/gpu/drm/bochs/bochs_drv.c +2 -2
@@ -82,9 +82,9 @@ static struct drm_driver bochs_driver = { .date = "20130925", .major = 1, .minor = 0, - .gem_free_object_unlocked = bochs_gem_free_object, + .gem_free_object_unlocked = drm_gem_ttm_driver_gem_free_object_unlocked, .dumb_create = bochs_dumb_create, - .dumb_map_offset = bochs_dumb_mmap_offset, + .dumb_map_offset = drm_gem_ttm_driver_dumb_mmap_offset, .gem_prime_export = drm_gem_prime_export, .gem_prime_import = drm_gem_prime_import,
drivers/gpu/drm/bochs/bochs_kms.c +9 -9
@@ -78,38 +78,38 @@ static void bochs_plane_atomic_update(struct drm_plane *plane, struct drm_plane_state *old_state) {struct bochs_device *bochs = plane->dev->dev_private; -struct bochs_bo *bo; +struct drm_gem_ttm_object *gbo;if (!plane->state->fb)return ; - bo =gem_to_bochs_bo (plane->state->fb->obj[0 ]); + gbo =drm_gem_ttm_of_gem (plane->state->fb->obj[0 ]);bochs_hw_setbase (bochs, plane->state->crtc_x, plane->state->crtc_y, - bo->bo.offset); + gbo->bo.offset);bochs_hw_setformat (bochs, plane->state->fb->format); }static int bochs_plane_prepare_fb (struct drm_plane *plane,struct drm_plane_state *new_state) { -struct bochs_bo *bo; +struct drm_gem_ttm_object *gbo;if (!new_state->fb)return 0 ; - bo =gem_to_bochs_bo (new_state->fb->obj[0 ]); -return bochs_bo_pin (bo,TTM_PL_FLAG_VRAM ); + gbo =drm_gem_ttm_of_gem (new_state->fb->obj[0 ]); +return drm_gem_ttm_pin (gbo,TTM_PL_FLAG_VRAM ); }static void bochs_plane_cleanup_fb (struct drm_plane *plane,struct drm_plane_state *old_state) { -struct bochs_bo *bo; +struct drm_gem_ttm_object *gbo;if (!old_state->fb)return ; - bo =gem_to_bochs_bo (old_state->fb->obj[0 ]); -bochs_bo_unpin (bo); + gbo =drm_gem_ttm_of_gem (old_state->fb->obj[0 ]); +drm_gem_ttm_unpin (gbo); }static const struct drm_plane_helper_funcs bochs_plane_helper_funcs = {
drivers/gpu/drm/bochs/bochs_mm.c +21 -248
343 lines not on this page · raw message
Signature · 6 lines
2.21.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Thomas Zimmermann
maintainerPATCH 9/15 drm/bochs: Convert Bochs driver to Simple TTM
In reply to Thomas Zimmermann--- drivers/gpu/drm/bochs/Kconfig | 1 + drivers/gpu/drm/bochs/bochs.h | 8 +- drivers/gpu/drm/bochs/bochs_mm.c | 125 +++---------------------------- 3 files changed, 14 insertions(+), 120 deletions(-)
drivers/gpu/drm/bochs/Kconfig +1 -0
@@ -4,6 +4,7 @@ config DRM_BOCHS select DRM_KMS_HELPER select DRM_TTM select DRM_GEM_TTM_HELPER + select DRM_SIMPLE_TTM_HELPER help Choose this option for qemu. If M is selected the module will be called bochs-drm.
drivers/gpu/drm/bochs/bochs.h +4 -4
@@ -11,6 +11,8 @@#include <drm/drm_gem.h> #include <drm/drm_gem_ttm_helper.h> +#include <drm/drm_simple_ttm_helper.h> +#include <drm/ttm/ttm_bo_driver.h> #include <drm/ttm/ttm_page_alloc.h>
@@ -76,10 +78,8 @@ struct bochs_device {struct drm_connector connector;/* ttm */ -struct { -struct ttm_bo_device bdev; -bool initialized; - } ttm; +struct drm_simple_ttm ttm; +bool ttm_initialized; };/* ---------------------------------------------------------------------- */
drivers/gpu/drm/bochs/bochs_mm.c +9 -116
147 lines not on this page · raw message
Signature · 6 lines
2.21.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Thomas Zimmermann
maintainerPATCH 10/15 drm/mgag200: Convert mgag200 driver to |struct drm_gem_ttm_object|
In reply to Thomas Zimmermann--- drivers/gpu/drm/mgag200/Kconfig | 1 + drivers/gpu/drm/mgag200/mgag200_cursor.c | 61 ++++---- drivers/gpu/drm/mgag200/mgag200_drv.c | 4 +- drivers/gpu/drm/mgag200/mgag200_drv.h | 62 ++------ drivers/gpu/drm/mgag200/mgag200_fb.c | 18 +-- drivers/gpu/drm/mgag200/mgag200_main.c | 84 +++-------- drivers/gpu/drm/mgag200/mgag200_mode.c | 45 +++--- drivers/gpu/drm/mgag200/mgag200_ttm.c | 172 +---------------------- 8 files changed, 101 insertions(+), 346 deletions(-)
drivers/gpu/drm/mgag200/Kconfig +1 -0
@@ -3,6 +3,7 @@ config DRM_MGAG200 depends on DRM && PCI && MMU select DRM_KMS_HELPER select DRM_TTM + select DRM_GEM_TTM_HELPER help This is a KMS driver for the MGA G200 server chips, it does not support the original MGA G200 or any of the desktop
drivers/gpu/drm/mgag200/mgag200_cursor.c +36 -25
130 lines not on this page · raw message
drivers/gpu/drm/mgag200/mgag200_drv.c +2 -2
@@ -80,9 +80,9 @@ static struct drm_driver driver = { .minor = DRIVER_MINOR, .patchlevel = DRIVER_PATCHLEVEL, - .gem_free_object_unlocked = mgag200_gem_free_object, + .gem_free_object_unlocked = drm_gem_ttm_driver_gem_free_object_unlocked, .dumb_create = mgag200_dumb_create, - .dumb_map_offset = mgag200_dumb_mmap_offset, + .dumb_map_offset = drm_gem_ttm_driver_dumb_mmap_offset, };static struct pci_driver mgag200_pci_driver = {
drivers/gpu/drm/mgag200/mgag200_drv.h +8 -54
101 lines not on this page · raw message
drivers/gpu/drm/mgag200/mgag200_fb.c +9 -9
@@ -23,7 +23,7 @@ static void mga_dirty_update(struct mga_fbdev *mfbdev, {int i;struct drm_gem_object *obj; -struct mgag200_bo *bo; +struct drm_gem_ttm_object *gbo;int src_offset, dst_offset;int bpp = mfbdev->mfb.base.format->cpp[0 ];int ret = -EBUSY ;
@@ -33,7 +33,7 @@ static void mga_dirty_update(struct mga_fbdev *mfbdev,unsigned long flags; obj = mfbdev->mfb.obj; - bo =gem_to_mga_bo (obj); + gbo =drm_gem_ttm_of_gem (obj);/* * try and reserve the BO, if we fail with busy
@@ -41,7 +41,7 @@ static void mga_dirty_update(struct mga_fbdev *mfbdev,* store up the damage until later. */ if (drm_can_sleep ()) - ret =mgag200_bo_reserve (bo, true); + ret =drm_gem_ttm_reserve (gbo, true);if (ret) {if (ret != -EBUSY )return ;
@@ -75,11 +75,11 @@ static void mga_dirty_update(struct mga_fbdev *mfbdev, mfbdev->x2 = mfbdev->y2 =0 ;spin_unlock_irqrestore (&mfbdev->dirty_lock, flags); -if (!bo->kmap.virtual) { - ret =ttm_bo_kmap (&bo->bo,0 , bo->bo.num_pages, &bo->kmap); +if (!gbo->kmap.virtual) { + ret =ttm_bo_kmap (&gbo->bo,0 , gbo->bo.num_pages, &gbo->kmap);if (ret) {DRM_ERROR ("failed to kmap fb updates\n" ); -mgag200_bo_unreserve (bo); +drm_gem_ttm_unreserve (gbo);return ; } unmap = true;
@@ -87,13 +87,13 @@ static void mga_dirty_update(struct mga_fbdev *mfbdev,for (i = y; i <= y2; i++) {/* assume equal stride for now */ src_offset = dst_offset = i * mfbdev->mfb.base.pitches[0 ] + (x * bpp); -memcpy_toio (bo->kmap.virtual + src_offset, mfbdev->sysram + src_offset, (x2 - x +1 ) * bpp); +memcpy_toio (gbo->kmap.virtual + src_offset, mfbdev->sysram + src_offset, (x2 - x +1 ) * bpp); }if (unmap) -ttm_bo_kunmap (&bo->kmap); +ttm_bo_kunmap (&gbo->kmap); -mgag200_bo_unreserve (bo); +drm_gem_ttm_unreserve (gbo); } static void mga_fillrect(struct fb_info *info,
drivers/gpu/drm/mgag200/mgag200_main.c +16 -68
111 lines not on this page · raw message
drivers/gpu/drm/mgag200/mgag200_mode.c +27 -18
87 lines not on this page · raw message
drivers/gpu/drm/mgag200/mgag200_ttm.c +2 -170
197 lines not on this page · raw message
Signature · 6 lines
2.21.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Thomas Zimmermann
maintainerPATCH 11/15 drm/mgag200: Convert mgag200 driver to Simple TTM
In reply to Thomas Zimmermann--- drivers/gpu/drm/mgag200/Kconfig | 1 + drivers/gpu/drm/mgag200/mgag200_drv.h | 6 +- drivers/gpu/drm/mgag200/mgag200_ttm.c | 120 ++------------------------ 3 files changed, 12 insertions(+), 115 deletions(-)
drivers/gpu/drm/mgag200/Kconfig +1 -0
@@ -4,6 +4,7 @@ config DRM_MGAG200 select DRM_KMS_HELPER select DRM_TTM select DRM_GEM_TTM_HELPER + select DRM_SIMPLE_TTM_HELPER help This is a KMS driver for the MGA G200 server chips, it does not support the original MGA G200 or any of the desktop
drivers/gpu/drm/mgag200/mgag200_drv.h +3 -3
@@ -26,6 +26,8 @@#include <drm/drm_gem.h> #include <drm/drm_gem_ttm_helper.h> +#include <drm/drm_simple_ttm_helper.h> +#include <linux/i2c.h> #include <linux/i2c-algo-bit.h>
@@ -212,9 +214,7 @@ struct mga_device {int fb_mtrr; -struct { -struct ttm_bo_device bdev; - } ttm; +struct drm_simple_ttm ttm;/* SE model number stored in reg 0x1e24 */ u32 unique_rev_id;
drivers/gpu/drm/mgag200/mgag200_ttm.c +8 -112
141 lines not on this page · raw message
Signature · 6 lines
2.21.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Thomas Zimmermann
maintainerPATCH 13/15 drm/vboxvideo: Convert vboxvideo driver to Simple TTM
In reply to Thomas Zimmermann--- drivers/gpu/drm/vboxvideo/Kconfig | 1 + drivers/gpu/drm/vboxvideo/vbox_drv.h | 6 +- drivers/gpu/drm/vboxvideo/vbox_ttm.c | 123 ++------------------------- 3 files changed, 12 insertions(+), 118 deletions(-)
drivers/gpu/drm/vboxvideo/Kconfig +1 -0
@@ -4,6 +4,7 @@ config DRM_VBOXVIDEO select DRM_KMS_HELPER select DRM_TTM select DRM_GEM_TTM_HELPER + select DRM_SIMPLE_TTM_HELPER select GENERIC_ALLOCATOR help This is a KMS driver for the virtual Graphics Card used in
drivers/gpu/drm/vboxvideo/vbox_drv.h +3 -3
@@ -20,6 +20,8 @@#include <drm/drm_gem.h> #include <drm/drm_gem_ttm_helper.h> +#include <drm/drm_simple_ttm_helper.h> +#include <drm/ttm/ttm_bo_api.h> #include <drm/ttm/ttm_bo_driver.h> #include <drm/ttm/ttm_placement.h>
@@ -78,9 +80,7 @@ struct vbox_private {int fb_mtrr; -struct { -struct ttm_bo_device bdev; - } ttm; +struct drm_simple_ttm ttm;struct mutex hw_mutex;/* protects modeset and accel/vbva accesses */ struct work_struct hotplug_work;
drivers/gpu/drm/vboxvideo/vbox_ttm.c +8 -115
153 lines not on this page · raw message
Signature · 6 lines
2.21.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Thomas Zimmermann
maintainerPATCH 14/15 drm/hisilicon: Convert hibmc-drm driver to |struct drm_gem_ttm_object|
In reply to Thomas Zimmermann--- drivers/gpu/drm/hisilicon/hibmc/Kconfig | 1 + .../gpu/drm/hisilicon/hibmc/hibmc_drm_de.c | 19 +- .../gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c | 4 +- .../gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h | 25 +-- .../gpu/drm/hisilicon/hibmc/hibmc_drm_fbdev.c | 30 +-- drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c | 210 +----------------- 6 files changed, 42 insertions(+), 247 deletions(-)
drivers/gpu/drm/hisilicon/hibmc/Kconfig +1 -0
@@ -3,6 +3,7 @@ config DRM_HISI_HIBMC depends on DRM && PCI && MMU select DRM_KMS_HELPER select DRM_TTM + select DRM_GEM_TTM_HELPER help Choose this option if you have a Hisilicon Hibmc soc chipset.
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_de.c +12 -7
@@ -96,27 +96,32 @@ static void hibmc_plane_atomic_update(struct drm_plane *plane,struct drm_plane_state *state = plane->state;u32 reg;int ret; -u64 gpu_addr =0 ; +s64 gpu_addr =0 ;unsigned int line_l;struct hibmc_drm_private *priv = plane->dev->dev_private;struct hibmc_framebuffer *hibmc_fb; -struct hibmc_bo *bo; +struct drm_gem_ttm_object *gbo;if (!state->fb)return ; hibmc_fb =to_hibmc_framebuffer (state->fb); - bo =gem_to_hibmc_bo (hibmc_fb->obj); - ret =ttm_bo_reserve (&bo->bo, true, false,NULL ); + gbo =drm_gem_ttm_of_gem (hibmc_fb->obj); + ret =drm_gem_ttm_reserve (gbo, false);if (ret) {DRM_ERROR ("failed to reserve ttm_bo: %d" , ret);return ; } - ret =hibmc_bo_pin (bo,TTM_PL_FLAG_VRAM , &gpu_addr); -ttm_bo_unreserve (&bo->bo); + ret =drm_gem_ttm_pin (gbo,TTM_PL_FLAG_VRAM ); +drm_gem_ttm_unreserve (gbo);if (ret) { -DRM_ERROR ("failed to pin hibmc_bo: %d" , ret); +DRM_ERROR ("failed to pin bo: %d" , ret); +return ; + } + gpu_addr =drm_gem_ttm_vram_offset (gbo); +if (gpu_addr <0 ) { +drm_gem_ttm_unpin (gbo);return ; }
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c +2 -2
@@ -63,9 +63,9 @@ static struct drm_driver hibmc_driver = { .desc = "hibmc drm driver", .major = 1, .minor = 0, - .gem_free_object_unlocked = hibmc_gem_free_object, + .gem_free_object_unlocked = drm_gem_ttm_driver_gem_free_object_unlocked, .dumb_create = hibmc_dumb_create, - .dumb_map_offset = hibmc_dumb_mmap_offset, + .dumb_map_offset = drm_gem_ttm_driver_dumb_mmap_offset, .irq_handler = hibmc_drm_interrupt, };
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h +1 -24
@@ -23,6 +23,7 @@#include <drm/drm_atomic.h> #include <drm/drm_fb_helper.h> #include <drm/drm_gem.h> +#include <drm/drm_gem_ttm_helper.h> #include <drm/ttm/ttm_bo_driver.h> struct hibmc_framebuffer {
@@ -59,25 +60,6 @@ struct hibmc_drm_private {#define to_hibmc_framebuffer (x) container_of(x, struct hibmc_framebuffer, fb) -struct hibmc_bo { -struct ttm_buffer_object bo; -struct ttm_placement placement; -struct ttm_bo_kmap_obj kmap; -struct drm_gem_object gem; -struct ttm_place placements[3 ]; -int pin_count; -}; - -static inline struct hibmc_bo *hibmc_bo (struct ttm_buffer_object *bo) -{ - return container_of(bo, struct hibmc_bo, bo); -} - -static inline struct hibmc_bo *gem_to_hibmc_bo (struct drm_gem_object *gem) -{ - return container_of(gem, struct hibmc_bo, gem); -} -void hibmc_set_power_mode (struct hibmc_drm_private *priv,unsigned int power_mode); void hibmc_set_current_gate(struct hibmc_drm_private *priv,
@@ -97,13 +79,8 @@ hibmc_framebuffer_init(struct drm_device *dev,int hibmc_mm_init (struct hibmc_drm_private *hibmc);void hibmc_mm_fini (struct hibmc_drm_private *hibmc); -int hibmc_bo_pin (struct hibmc_bo *bo,u32 pl_flag,u64 *gpu_addr); -int hibmc_bo_unpin (struct hibmc_bo *bo); -void hibmc_gem_free_object (struct drm_gem_object *obj);int hibmc_dumb_create (struct drm_file *file,struct drm_device *dev,struct drm_mode_create_dumb *args); -int hibmc_dumb_mmap_offset (struct drm_file *file,struct drm_device *dev, -u32 handle,u64 *offset);int hibmc_mmap (struct file *filp,struct vm_area_struct *vma);extern const struct drm_mode_config_funcs hibmc_mode_funcs;
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_fbdev.c +16 -14
@@ -66,7 +66,8 @@ static int hibmc_drm_fb_create(struct drm_fb_helper *helper,int ret1;size_t size;unsigned int bytes_per_pixel; -struct hibmc_bo *bo =NULL ; +struct drm_gem_ttm_object *gbo =NULL ; +void *base; DRM_DEBUG_DRIVER("surface width(%d), height(%d) and bpp(%d)\n", sizes->surface_width, sizes->surface_height,
@@ -88,26 +89,27 @@ static int hibmc_drm_fb_create(struct drm_fb_helper *helper,return -ENOMEM ; } - bo =gem_to_hibmc_bo (gobj); + gbo =drm_gem_ttm_of_gem (gobj); - ret =ttm_bo_reserve (&bo->bo, true, false,NULL ); + ret =drm_gem_ttm_reserve (gbo, false);if (ret) { -DRM_ERROR ("failed to reserve ttm_bo: %d\n" , ret); +DRM_ERROR ("failed to reserve bo: %d\n" , ret); goto out_unref_gem; } - ret =hibmc_bo_pin (bo,TTM_PL_FLAG_VRAM ,NULL ); + ret =drm_gem_ttm_pin (gbo,TTM_PL_FLAG_VRAM );if (ret) {DRM_ERROR ("failed to pin fbcon: %d\n" , ret); goto out_unreserve_ttm_bo; } - ret =ttm_bo_kmap (&bo->bo,0 , bo->bo.num_pages, &bo->kmap); -if (ret) { + base =drm_gem_ttm_kmap (gbo, true); +if (IS_ERR (base)) { + ret =ERR_PTR (base);DRM_ERROR ("failed to kmap fbcon: %d\n" , ret); goto out_unpin_bo; } -ttm_bo_unreserve (&bo->bo); +drm_gem_ttm_unreserve (gbo); info =drm_fb_helper_alloc_fbi (helper);if (IS_ERR (info)) {
@@ -131,24 +133,24 @@ static int hibmc_drm_fb_create(struct drm_fb_helper *helper,drm_fb_helper_fill_info (info, &priv->fbdev->helper, sizes); - info->screen_base = bo->kmap.virtual; + info->screen_base = base; info->screen_size = size; - info->fix.smem_start = bo->bo.mem.bus.offset + bo->bo.mem.bus.base; + info->fix.smem_start = gbo->bo.mem.bus.offset + gbo->bo.mem.bus.base; info->fix.smem_len = size;return 0 ; out_release_fbi: - ret1 =ttm_bo_reserve (&bo->bo, true, false,NULL ); + ret1 =drm_gem_ttm_reserve (gbo, false);if (ret1) {DRM_ERROR ("failed to rsv ttm_bo when release fbi: %d\n" , ret1); goto out_unref_gem; } -ttm_bo_kunmap (&bo->kmap); +drm_gem_ttm_kunmap (gbo); out_unpin_bo: -hibmc_bo_unpin (bo); +drm_gem_ttm_unpin (gbo); out_unreserve_ttm_bo: -ttm_bo_unreserve (&bo->bo); +drm_gem_ttm_unreserve (gbo); out_unref_gem:drm_gem_object_put_unlocked (gobj);
drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c +10 -200
257 lines not on this page · raw message
Signature · 6 lines
2.21.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Thomas Zimmermann
maintainerPATCH 12/15 drm/vboxvideo: Convert vboxvideo driver to |struct drm_gem_ttm_object|
In reply to Thomas ZimmermannThis patch replaces |struct vbox_bo| and its helpers with the generic implementation of |struct drm_gem_ttm_object|. The only change in semantics is that &ttm_bo_driver.verify_access() now does the actual verification.
--- drivers/gpu/drm/vboxvideo/Kconfig | 1 + drivers/gpu/drm/vboxvideo/vbox_drv.c | 5 +- drivers/gpu/drm/vboxvideo/vbox_drv.h | 58 +------ drivers/gpu/drm/vboxvideo/vbox_fb.c | 22 +-- drivers/gpu/drm/vboxvideo/vbox_main.c | 70 +------- drivers/gpu/drm/vboxvideo/vbox_mode.c | 36 +++-- drivers/gpu/drm/vboxvideo/vbox_ttm.c | 223 +------------------------- 7 files changed, 45 insertions(+), 370 deletions(-)
drivers/gpu/drm/vboxvideo/Kconfig +1 -0
@@ -3,6 +3,7 @@ config DRM_VBOXVIDEO depends on DRM && X86 && PCI select DRM_KMS_HELPER select DRM_TTM + select DRM_GEM_TTM_HELPER select GENERIC_ALLOCATOR help This is a KMS driver for the virtual Graphics Card used in
drivers/gpu/drm/vboxvideo/vbox_drv.c +3 -2
@@ -215,9 +215,10 @@ static struct drm_driver driver = { .minor = DRIVER_MINOR, .patchlevel = DRIVER_PATCHLEVEL, - .gem_free_object_unlocked = vbox_gem_free_object, + .gem_free_object_unlocked = + drm_gem_ttm_driver_gem_free_object_unlocked, .dumb_create = vbox_dumb_create, - .dumb_map_offset = vbox_dumb_mmap_offset, + .dumb_map_offset = drm_gem_ttm_driver_dumb_mmap_offset, .prime_handle_to_fd = drm_gem_prime_handle_to_fd, .prime_fd_to_handle = drm_gem_prime_fd_to_handle, .gem_prime_export = drm_gem_prime_export,
drivers/gpu/drm/vboxvideo/vbox_drv.h +1 -57
80 lines not on this page · raw message
drivers/gpu/drm/vboxvideo/vbox_fb.c +11 -11
@@ -51,9 +51,9 @@ int vboxfb_create(struct drm_fb_helper *helper,struct drm_framebuffer *fb;struct fb_info *info;struct drm_gem_object *gobj; -struct vbox_bo *bo; +struct drm_gem_ttm_object *gbo;int size, ret; -u64 gpu_addr; +s64 gpu_addr;u32 pitch; mode_cmd.width = sizes->surface_width;
@@ -75,9 +75,9 @@ int vboxfb_create(struct drm_fb_helper *helper,if (ret)return ret; - bo =gem_to_vbox_bo (gobj); + gbo =drm_gem_ttm_of_gem (gobj); - ret =vbox_bo_pin (bo,TTM_PL_FLAG_VRAM ); + ret =drm_gem_ttm_pin (gbo,TTM_PL_FLAG_VRAM );if (ret)return ret;
@@ -86,7 +86,7 @@ int vboxfb_create(struct drm_fb_helper *helper,return PTR_ERR (info); info->screen_size = size; - info->screen_base = (char __iomem *)vbox_bo_kmap (bo); + info->screen_base = (char __iomem *)drm_gem_ttm_kmap (gbo, true);if (IS_ERR (info->screen_base))return PTR_ERR (info->screen_base);
@@ -104,7 +104,9 @@ int vboxfb_create(struct drm_fb_helper *helper,drm_fb_helper_fill_info (info, helper, sizes); - gpu_addr =vbox_bo_gpu_offset (bo); + gpu_addr =drm_gem_ttm_vram_offset (gbo); +if (gpu_addr <0 ) +return (int )gpu_addr; info->fix.smem_start = info->apertures->ranges[0 ].base + gpu_addr; info->fix.smem_len = vbox->available_vram_size - gpu_addr;
@@ -132,12 +134,10 @@ void vbox_fbdev_fini(struct vbox_private *vbox)drm_fb_helper_unregister_fbi (&vbox->fb_helper);if (afb->obj) { -struct vbox_bo *bo =gem_to_vbox_bo (afb->obj); +struct drm_gem_ttm_object *gbo =drm_gem_ttm_of_gem (afb->obj); -vbox_bo_kunmap (bo); - -if (bo->pin_count) -vbox_bo_unpin (bo); +drm_gem_ttm_kunmap (gbo); +drm_gem_ttm_unpin (gbo);drm_gem_object_put_unlocked (afb->obj); afb->obj =NULL ;
drivers/gpu/drm/vboxvideo/vbox_main.c +8 -62
93 lines not on this page · raw message
drivers/gpu/drm/vboxvideo/vbox_mode.c +19 -17
@@ -173,7 +173,8 @@ static void vbox_crtc_set_base_and_mode(struct drm_crtc *crtc,struct drm_framebuffer *fb, int x, int y) { - struct vbox_bo *bo = gem_to_vbox_bo(to_vbox_framebuffer(fb)->obj); + struct drm_gem_ttm_object *gbo = +drm_gem_ttm_of_gem (to_vbox_framebuffer (fb)->obj);struct vbox_private *vbox = crtc->dev->dev_private;struct vbox_crtc *vbox_crtc =to_vbox_crtc (crtc);bool needs_modeset =drm_atomic_crtc_needs_modeset (crtc->state);
@@ -187,7 +188,7 @@ static void vbox_crtc_set_base_and_mode(struct drm_crtc *crtc, vbox_crtc->x = x; vbox_crtc->y = y; - vbox_crtc->fb_offset =vbox_bo_gpu_offset (bo); + vbox_crtc->fb_offset =drm_gem_ttm_vram_offset (gbo);/* vbox_do_modeset() checks vbox->single_framebuffer so update it now */ if (needs_modeset &&vbox_set_up_input_mapping (vbox)) {
@@ -303,14 +304,14 @@ static void vbox_primary_atomic_disable(struct drm_plane *plane,static int vbox_primary_prepare_fb (struct drm_plane *plane,struct drm_plane_state *new_state) { -struct vbox_bo *bo; +struct drm_gem_ttm_object *gbo;int ret;if (!new_state->fb)return 0 ; - bo =gem_to_vbox_bo (to_vbox_framebuffer (new_state->fb)->obj); - ret =vbox_bo_pin (bo,TTM_PL_FLAG_VRAM ); + gbo =drm_gem_ttm_of_gem (to_vbox_framebuffer (new_state->fb)->obj); + ret =drm_gem_ttm_pin (gbo,TTM_PL_FLAG_VRAM );if (ret)DRM_WARN ("Error %d pinning new fb, out of video mem?\n" , ret);
@@ -320,13 +321,13 @@ static int vbox_primary_prepare_fb(struct drm_plane *plane,static void vbox_primary_cleanup_fb (struct drm_plane *plane,struct drm_plane_state *old_state) { -struct vbox_bo *bo; +struct drm_gem_ttm_object *gbo;if (!old_state->fb)return ; - bo =gem_to_vbox_bo (to_vbox_framebuffer (old_state->fb)->obj); -vbox_bo_unpin (bo); + gbo =drm_gem_ttm_of_gem (to_vbox_framebuffer (old_state->fb)->obj); +drm_gem_ttm_unpin (gbo); } static int vbox_cursor_atomic_check(struct drm_plane *plane,
@@ -386,7 +387,8 @@ static void vbox_cursor_atomic_update(struct drm_plane *plane, container_of(plane->dev, struct vbox_private, ddev);struct vbox_crtc *vbox_crtc =to_vbox_crtc (plane->state->crtc);struct drm_framebuffer *fb = plane->state->fb; -struct vbox_bo *bo =gem_to_vbox_bo (to_vbox_framebuffer (fb)->obj); +struct drm_gem_ttm_object *gbo = +drm_gem_ttm_of_gem (to_vbox_framebuffer (fb)->obj);u32 width = plane->state->crtc_w;u32 height = plane->state->crtc_h;size_t data_size, mask_size;
@@ -405,7 +407,7 @@ static void vbox_cursor_atomic_update(struct drm_plane *plane, vbox_crtc->cursor_enabled = true;/* pinning is done in prepare/cleanup framebuffer */ - src =vbox_bo_kmap (bo); + src =drm_gem_ttm_kmap (gbo, true);if (IS_ERR (src)) {mutex_unlock (&vbox->hw_mutex);DRM_WARN ("Could not kmap cursor bo, skipping update\n" );
@@ -421,7 +423,7 @@ static void vbox_cursor_atomic_update(struct drm_plane *plane, data_size = width * height *4 + mask_size;copy_cursor_image (src, vbox->cursor_data, width, height, mask_size); -vbox_bo_kunmap (bo); +drm_gem_ttm_kunmap (gbo); flags =VBOX_MOUSE_POINTER_VISIBLE |VBOX_MOUSE_POINTER_SHAPE |VBOX_MOUSE_POINTER_ALPHA ;
@@ -461,25 +463,25 @@ static void vbox_cursor_atomic_disable(struct drm_plane *plane,static int vbox_cursor_prepare_fb (struct drm_plane *plane,struct drm_plane_state *new_state) { -struct vbox_bo *bo; +struct drm_gem_ttm_object *gbo;if (!new_state->fb)return 0 ; - bo =gem_to_vbox_bo (to_vbox_framebuffer (new_state->fb)->obj); -return vbox_bo_pin (bo,TTM_PL_FLAG_SYSTEM ); + gbo =drm_gem_ttm_of_gem (to_vbox_framebuffer (new_state->fb)->obj); +return drm_gem_ttm_pin (gbo,TTM_PL_FLAG_SYSTEM ); }static void vbox_cursor_cleanup_fb (struct drm_plane *plane,struct drm_plane_state *old_state) { -struct vbox_bo *bo; +struct drm_gem_ttm_object *gbo;if (!plane->state->fb)return ; - bo =gem_to_vbox_bo (to_vbox_framebuffer (plane->state->fb)->obj); -vbox_bo_unpin (bo); + gbo =drm_gem_ttm_of_gem (to_vbox_framebuffer (plane->state->fb)->obj); +drm_gem_ttm_unpin (gbo); }static const u32 vbox_cursor_plane_formats[] = {
drivers/gpu/drm/vboxvideo/vbox_ttm.c +2 -221
250 lines not on this page · raw message
Signature · 6 lines
2.21.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Thomas Zimmermann
maintainerPATCH 15/15 drm/hisilicon: Convert hibmc-drm driver to Simple TTM
In reply to Thomas Zimmermann--- drivers/gpu/drm/hisilicon/hibmc/Kconfig | 1 + .../gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h | 3 +- drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c | 124 ++---------------- 3 files changed, 13 insertions(+), 115 deletions(-)
drivers/gpu/drm/hisilicon/hibmc/Kconfig +1 -0
@@ -4,6 +4,7 @@ config DRM_HISI_HIBMC select DRM_KMS_HELPER select DRM_TTM select DRM_GEM_TTM_HELPER + select DRM_SIMPLE_TTM_HELPER help Choose this option if you have a Hisilicon Hibmc soc chipset.
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h +2 -1
@@ -24,6 +24,7 @@#include <drm/drm_fb_helper.h> #include <drm/drm_gem.h> #include <drm/drm_gem_ttm_helper.h> +#include <drm/drm_simple_ttm_helper.h> #include <drm/ttm/ttm_bo_driver.h> struct hibmc_framebuffer {
@@ -50,7 +51,7 @@ struct hibmc_drm_private {bool mode_config_initialized;/* ttm */ -struct ttm_bo_device bdev; +struct drm_simple_ttm ttm;bool initialized;/* fbdev */
drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c +10 -114
156 lines not on this page · raw message
Signature · 6 lines
2.21.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Well first problem is I'm not sure if that is a good idea. Essentially we want to get rid of TTM in the long run.
On the other hand this work might aid with that goal, so it might be worth a try.
Second is that this might actually not work of hand. The problem is here:
Review
Quoted 5 lines
(quoted diff) +5
-0+ /* TODO: This test used to be performed by drivers, but can + * this actually happen? If so, should we put the check into + * drm_gem_ttm_of_gem()? */ + if (!drm_is_gem_ttm(bo)) + return;
Yeah, this test is mandatory because TTM on itself can present buffer object which doesn't belong to the driver called.
E.g. we sometimes have BOs which don't belong to the current drivers on a driver specific LRU. A totally brain dead design if you ask me, but that's how it is.
Not 100% sure, but by converting all drivers to use a common GEM_TTM backend you might actually break that test.
I'm not sure if that is actually a problem in the real world, it most likely isn't. But I still won't bet on it without being able to test this.
Regards,
Christian.
Am 08.04.19 um 11:21 schrieb Thomas Zimmermann:
Quoted 91 lines
Several simple framebuffer drivers copy most of the TTM code from each other. The implementation is always the same; except for the name of some data structures.
As recently discussed, this patch set provides generic TTM memory- management code for framebuffers with dedicated video memory. It further converts the respective drivers to the generic code. The shared code is basically the same implementation as the one copied among individual drivers.
The patch set contains two major changes: first, it introduces |struct drm_gem_ttm_object| and helpers. It's a GEM object that is backed by TTM-managed memory. The type's purpose is somewhat similar to |struct drm_gem_{cma, shmem}_object|. Second, the patch set introduces |struct drm_simple_ttm| (for the lack of a better name) and helpers. It's an implementation of a basic TTM-based memory manager.
Both, GEM TTM and Simple TTM, support VRAM and SYSTEM placements. Support for TT could probably be added if necessary. Both can be used independedly from each other if desired by the DRM driver.
Currently ast, bochs, mgag200, vboxvideo and hisilicon/hibmc can use these helpers. Cirrus would also be a candidate, but as it's being rewrtten from scratch, I didn't bother doing the conversion.
Future directions: with these changes, the respective drivers can also share some of their mode-setting or fbdev code. GEM TTM could implement PRIME helpers, which would allow for using the generic fbcon.
The patch set is against a recent drm-tip.
Thomas Zimmermann (15):
drm: Add |struct drm_gem_ttm_object| and helpers drm: Add |struct drm_gem_ttm_object| callbacks for |structttm_bo_driver|
drm: Add |struct drm_gem_ttm_object| callbacks for |struct drm_driver|
drm: Adddrm_gem_ttm_fill_create_dumb()to create dumb buffers
drm: Add Simple TTM, a memory manager for dedicated VRAM drm/ast: Convert AST driver to |struct drm_gem_ttm_object| drm/ast: Convert AST driver to Simple TTM
drm/bochs: Convert Bochs driver to |struct drm_gem_ttm_object| drm/bochs: Convert Bochs driver to Simple TTM
drm/mgag200: Convert mgag200 driver to |struct drm_gem_ttm_object| drm/mgag200: Convert mgag200 driver to Simple TTM drm/vboxvideo: Convert vboxvideo driver to |struct drm_gem_ttm_object| drm/vboxvideo: Convert vboxvideo driver to Simple TTM drm/hisilicon: Convert hibmc-drm driver to |struct drm_gem_ttm_object| drm/hisilicon: Convert hibmc-drm driver to Simple TTMDocumentation/gpu/drm-mm.rst | 23 + drivers/gpu/drm/Kconfig | 20 + drivers/gpu/drm/Makefile | 5 + drivers/gpu/drm/ast/Kconfig | 3 +- drivers/gpu/drm/ast/ast_drv.c | 4 +- drivers/gpu/drm/ast/ast_drv.h | 58 +- drivers/gpu/drm/ast/ast_fb.c | 18 +- drivers/gpu/drm/ast/ast_main.c | 74 +-- drivers/gpu/drm/ast/ast_mode.c | 78 +-- drivers/gpu/drm/ast/ast_ttm.c | 290 +--------- drivers/gpu/drm/bochs/Kconfig | 2 + drivers/gpu/drm/bochs/bochs.h | 42 +- drivers/gpu/drm/bochs/bochs_drv.c | 4 +- drivers/gpu/drm/bochs/bochs_kms.c | 18 +- drivers/gpu/drm/bochs/bochs_mm.c | 392 +------------- drivers/gpu/drm/drm_gem_ttm_helper.c | 507 ++++++++++++++++++ drivers/gpu/drm/drm_simple_ttm_helper.c | 191 +++++++ drivers/gpu/drm/drm_ttm_helper_common.c | 6 + drivers/gpu/drm/hisilicon/hibmc/Kconfig | 2 + .../gpu/drm/hisilicon/hibmc/hibmc_drm_de.c | 19 +- .../gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c | 4 +- .../gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h | 28 +- .../gpu/drm/hisilicon/hibmc/hibmc_drm_fbdev.c | 30 +- drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c | 328 +---------- drivers/gpu/drm/mgag200/Kconfig | 2 + drivers/gpu/drm/mgag200/mgag200_cursor.c | 61 ++- drivers/gpu/drm/mgag200/mgag200_drv.c | 4 +- drivers/gpu/drm/mgag200/mgag200_drv.h | 68 +-- drivers/gpu/drm/mgag200/mgag200_fb.c | 18 +- drivers/gpu/drm/mgag200/mgag200_main.c | 84 +-- drivers/gpu/drm/mgag200/mgag200_mode.c | 45 +- drivers/gpu/drm/mgag200/mgag200_ttm.c | 290 +--------- drivers/gpu/drm/vboxvideo/Kconfig | 2 + drivers/gpu/drm/vboxvideo/vbox_drv.c | 5 +- drivers/gpu/drm/vboxvideo/vbox_drv.h | 64 +-- drivers/gpu/drm/vboxvideo/vbox_fb.c | 22 +- drivers/gpu/drm/vboxvideo/vbox_main.c | 70 +-- drivers/gpu/drm/vboxvideo/vbox_mode.c | 36 +- drivers/gpu/drm/vboxvideo/vbox_ttm.c | 344 +----------- include/drm/drm_gem_ttm_helper.h | 119 ++++ include/drm/drm_simple_ttm_helper.h | 74 +++ 41 files changed, 1292 insertions(+), 2162 deletions(-)
Quoted 9 lines
create mode 100644
drivers/gpu/drm/drm_gem_ttm_helper.ccreate mode 100644drivers/gpu/drm/drm_simple_ttm_helper.ccreate mode 100644drivers/gpu/drm/drm_ttm_helper_common.ccreate mode 100644include/drm/drm_gem_ttm_helper.hcreate mode 100644include/drm/drm_simple_ttm_helper.h--
2.21.0
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Well first problem is I'm not sure if that is a good idea. Essentially we want to get rid of TTM in the long run.
On the other hand this work might aid with that goal, so it might be worth a try.
Second is that this might actually not work of hand. The problem is here:
Review
Quoted 5 lines
(quoted diff) +5
-0+ /* TODO: This test used to be performed by drivers, but can + * this actually happen? If so, should we put the check into + * drm_gem_ttm_of_gem()? */ + if (!drm_is_gem_ttm(bo)) + return;
Yeah, this test is mandatory because TTM on itself can present buffer object which doesn't belong to the driver called.
E.g. we sometimes have BOs which don't belong to the current drivers on a driver specific LRU. A totally brain dead design if you ask me, but that's how it is.
Not 100% sure, but by converting all drivers to use a common GEM_TTM backend you might actually break that test.
I'm not sure if that is actually a problem in the real world, it most likely isn't. But I still won't bet on it without being able to test this.
Regards,
Christian.
Am 08.04.19 um 11:21 schrieb Thomas Zimmermann:
Quoted 91 lines
Several simple framebuffer drivers copy most of the TTM code from each other. The implementation is always the same; except for the name of some data structures.
As recently discussed, this patch set provides generic TTM memory- management code for framebuffers with dedicated video memory. It further converts the respective drivers to the generic code. The shared code is basically the same implementation as the one copied among individual drivers.
The patch set contains two major changes: first, it introduces |struct drm_gem_ttm_object| and helpers. It's a GEM object that is backed by TTM-managed memory. The type's purpose is somewhat similar to |struct drm_gem_{cma, shmem}_object|. Second, the patch set introduces |struct drm_simple_ttm| (for the lack of a better name) and helpers. It's an implementation of a basic TTM-based memory manager.
Both, GEM TTM and Simple TTM, support VRAM and SYSTEM placements. Support for TT could probably be added if necessary. Both can be used independedly from each other if desired by the DRM driver.
Currently ast, bochs, mgag200, vboxvideo and hisilicon/hibmc can use these helpers. Cirrus would also be a candidate, but as it's being rewrtten from scratch, I didn't bother doing the conversion.
Future directions: with these changes, the respective drivers can also share some of their mode-setting or fbdev code. GEM TTM could implement PRIME helpers, which would allow for using the generic fbcon.
The patch set is against a recent drm-tip.
Thomas Zimmermann (15):
drm: Add |struct drm_gem_ttm_object| and helpers drm: Add |struct drm_gem_ttm_object| callbacks for |structttm_bo_driver|
drm: Add |struct drm_gem_ttm_object| callbacks for |struct drm_driver|
drm: Adddrm_gem_ttm_fill_create_dumb()to create dumb buffers
drm: Add Simple TTM, a memory manager for dedicated VRAM drm/ast: Convert AST driver to |struct drm_gem_ttm_object| drm/ast: Convert AST driver to Simple TTM
drm/bochs: Convert Bochs driver to |struct drm_gem_ttm_object| drm/bochs: Convert Bochs driver to Simple TTM
drm/mgag200: Convert mgag200 driver to |struct drm_gem_ttm_object| drm/mgag200: Convert mgag200 driver to Simple TTM drm/vboxvideo: Convert vboxvideo driver to |struct drm_gem_ttm_object| drm/vboxvideo: Convert vboxvideo driver to Simple TTM drm/hisilicon: Convert hibmc-drm driver to |struct drm_gem_ttm_object| drm/hisilicon: Convert hibmc-drm driver to Simple TTMDocumentation/gpu/drm-mm.rst | 23 + drivers/gpu/drm/Kconfig | 20 + drivers/gpu/drm/Makefile | 5 + drivers/gpu/drm/ast/Kconfig | 3 +- drivers/gpu/drm/ast/ast_drv.c | 4 +- drivers/gpu/drm/ast/ast_drv.h | 58 +- drivers/gpu/drm/ast/ast_fb.c | 18 +- drivers/gpu/drm/ast/ast_main.c | 74 +-- drivers/gpu/drm/ast/ast_mode.c | 78 +-- drivers/gpu/drm/ast/ast_ttm.c | 290 +--------- drivers/gpu/drm/bochs/Kconfig | 2 + drivers/gpu/drm/bochs/bochs.h | 42 +- drivers/gpu/drm/bochs/bochs_drv.c | 4 +- drivers/gpu/drm/bochs/bochs_kms.c | 18 +- drivers/gpu/drm/bochs/bochs_mm.c | 392 +------------- drivers/gpu/drm/drm_gem_ttm_helper.c | 507 ++++++++++++++++++ drivers/gpu/drm/drm_simple_ttm_helper.c | 191 +++++++ drivers/gpu/drm/drm_ttm_helper_common.c | 6 + drivers/gpu/drm/hisilicon/hibmc/Kconfig | 2 + .../gpu/drm/hisilicon/hibmc/hibmc_drm_de.c | 19 +- .../gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c | 4 +- .../gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h | 28 +- .../gpu/drm/hisilicon/hibmc/hibmc_drm_fbdev.c | 30 +- drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c | 328 +---------- drivers/gpu/drm/mgag200/Kconfig | 2 + drivers/gpu/drm/mgag200/mgag200_cursor.c | 61 ++- drivers/gpu/drm/mgag200/mgag200_drv.c | 4 +- drivers/gpu/drm/mgag200/mgag200_drv.h | 68 +-- drivers/gpu/drm/mgag200/mgag200_fb.c | 18 +- drivers/gpu/drm/mgag200/mgag200_main.c | 84 +-- drivers/gpu/drm/mgag200/mgag200_mode.c | 45 +- drivers/gpu/drm/mgag200/mgag200_ttm.c | 290 +--------- drivers/gpu/drm/vboxvideo/Kconfig | 2 + drivers/gpu/drm/vboxvideo/vbox_drv.c | 5 +- drivers/gpu/drm/vboxvideo/vbox_drv.h | 64 +-- drivers/gpu/drm/vboxvideo/vbox_fb.c | 22 +- drivers/gpu/drm/vboxvideo/vbox_main.c | 70 +-- drivers/gpu/drm/vboxvideo/vbox_mode.c | 36 +- drivers/gpu/drm/vboxvideo/vbox_ttm.c | 344 +----------- include/drm/drm_gem_ttm_helper.h | 119 ++++ include/drm/drm_simple_ttm_helper.h | 74 +++ 41 files changed, 1292 insertions(+), 2162 deletions(-)
Quoted 9 lines
create mode 100644
drivers/gpu/drm/drm_gem_ttm_helper.ccreate mode 100644drivers/gpu/drm/drm_simple_ttm_helper.ccreate mode 100644drivers/gpu/drm/drm_ttm_helper_common.ccreate mode 100644include/drm/drm_gem_ttm_helper.hcreate mode 100644include/drm/drm_simple_ttm_helper.h--
2.21.0
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Thomas Zimmermann
maintainerHi
Am 08.04.19 um 13:10 schrieb Koenig, Christian:
Quoted 5 lines
Well first problem is I'm not sure if that is a good idea. Essentially we want to get rid of TTM in the long run.
On the other hand this work might aid with that goal, so it might be worth a try.
I see. I'm actually interested in porting some of the fbdev driver code over to DRM. So far, that patch set uses TTM. As there's so much duplicated code among drivers, I was asked to merge some of the code into helpers first.
If not for TTM, what would be the alternative? One VMA manager per memory region per device?
With the patch set applied there are very few TTM calls left in the drivers and some can even be replaced by helpers. Besides the stronger cleanup, maybe we can merge these helpers under a different API name? Something that does not imply a TTM-based implementation? Doing so would ease a later rewrite with non-TTM code. Suggestions?
Quoted 14 lines
Second is that this might actually not work of hand. The problem is here:
Review
Quoted 5 lines
(quoted diff) +5
-0+ /* TODO: This test used to be performed by drivers, but can + * this actually happen? If so, should we put the check into + * drm_gem_ttm_of_gem()? */ + if (!drm_is_gem_ttm(bo)) + return;Yeah, this test is mandatory because TTM on itself can present buffer object which doesn't belong to the driver called.
E.g. we sometimes have BOs which don't belong to the current drivers on a driver specific LRU. A totally brain dead design if you ask me, but that's how it is.
Quoted 5 lines
Not 100% sure, but by converting all drivers to use a common
GEM_TTMbackend you might actually break that test.I'm not sure if that is actually a problem in the real world, it most likely isn't. But I still won't bet on it without being able to test this.
That's for explaining. So this test should best live in driver-specific code.
Best regards
Thomas
Quoted 105 lines
Regards,
Christian.Am 08.04.19 um 11:21 schrieb Thomas Zimmermann:
Quoted 100 lines
Several simple framebuffer drivers copy most of the TTM code from each other. The implementation is always the same; except for the name of some data structures.
As recently discussed, this patch set provides generic TTM memory- management code for framebuffers with dedicated video memory. It further converts the respective drivers to the generic code. The shared code is basically the same implementation as the one copied among individual drivers.
The patch set contains two major changes: first, it introduces |struct drm_gem_ttm_object| and helpers. It's a GEM object that is backed by TTM-managed memory. The type's purpose is somewhat similar to |struct drm_gem_{cma, shmem}_object|. Second, the patch set introduces |struct drm_simple_ttm| (for the lack of a better name) and helpers. It's an implementation of a basic TTM-based memory manager.
Both, GEM TTM and Simple TTM, support VRAM and SYSTEM placements. Support for TT could probably be added if necessary. Both can be used independedly from each other if desired by the DRM driver.
Currently ast, bochs, mgag200, vboxvideo and hisilicon/hibmc can use these helpers. Cirrus would also be a candidate, but as it's being rewrtten from scratch, I didn't bother doing the conversion.
Future directions: with these changes, the respective drivers can also share some of their mode-setting or fbdev code. GEM TTM could implement PRIME helpers, which would allow for using the generic fbcon.
The patch set is against a recent drm-tip.
Thomas Zimmermann (15):
drm: Add |struct drm_gem_ttm_object| and helpers drm: Add |struct drm_gem_ttm_object| callbacks for |structttm_bo_driver|
drm: Add |struct drm_gem_ttm_object| callbacks for |struct drm_driver|
drm: Adddrm_gem_ttm_fill_create_dumb()to create dumb buffers
drm: Add Simple TTM, a memory manager for dedicated VRAM drm/ast: Convert AST driver to |struct drm_gem_ttm_object| drm/ast: Convert AST driver to Simple TTM
drm/bochs: Convert Bochs driver to |struct drm_gem_ttm_object| drm/bochs: Convert Bochs driver to Simple TTM
drm/mgag200: Convert mgag200 driver to |struct drm_gem_ttm_object| drm/mgag200: Convert mgag200 driver to Simple TTM drm/vboxvideo: Convert vboxvideo driver to |struct drm_gem_ttm_object| drm/vboxvideo: Convert vboxvideo driver to Simple TTM drm/hisilicon: Convert hibmc-drm driver to |struct drm_gem_ttm_object| drm/hisilicon: Convert hibmc-drm driver to Simple TTMDocumentation/gpu/drm-mm.rst | 23 + drivers/gpu/drm/Kconfig | 20 + drivers/gpu/drm/Makefile | 5 + drivers/gpu/drm/ast/Kconfig | 3 +- drivers/gpu/drm/ast/ast_drv.c | 4 +- drivers/gpu/drm/ast/ast_drv.h | 58 +- drivers/gpu/drm/ast/ast_fb.c | 18 +- drivers/gpu/drm/ast/ast_main.c | 74 +-- drivers/gpu/drm/ast/ast_mode.c | 78 +-- drivers/gpu/drm/ast/ast_ttm.c | 290 +--------- drivers/gpu/drm/bochs/Kconfig | 2 + drivers/gpu/drm/bochs/bochs.h | 42 +- drivers/gpu/drm/bochs/bochs_drv.c | 4 +- drivers/gpu/drm/bochs/bochs_kms.c | 18 +- drivers/gpu/drm/bochs/bochs_mm.c | 392 +------------- drivers/gpu/drm/drm_gem_ttm_helper.c | 507 ++++++++++++++++++ drivers/gpu/drm/drm_simple_ttm_helper.c | 191 +++++++ drivers/gpu/drm/drm_ttm_helper_common.c | 6 + drivers/gpu/drm/hisilicon/hibmc/Kconfig | 2 + .../gpu/drm/hisilicon/hibmc/hibmc_drm_de.c | 19 +- .../gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c | 4 +- .../gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h | 28 +- .../gpu/drm/hisilicon/hibmc/hibmc_drm_fbdev.c | 30 +- drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c | 328 +---------- drivers/gpu/drm/mgag200/Kconfig | 2 + drivers/gpu/drm/mgag200/mgag200_cursor.c | 61 ++- drivers/gpu/drm/mgag200/mgag200_drv.c | 4 +- drivers/gpu/drm/mgag200/mgag200_drv.h | 68 +-- drivers/gpu/drm/mgag200/mgag200_fb.c | 18 +- drivers/gpu/drm/mgag200/mgag200_main.c | 84 +-- drivers/gpu/drm/mgag200/mgag200_mode.c | 45 +- drivers/gpu/drm/mgag200/mgag200_ttm.c | 290 +--------- drivers/gpu/drm/vboxvideo/Kconfig | 2 + drivers/gpu/drm/vboxvideo/vbox_drv.c | 5 +- drivers/gpu/drm/vboxvideo/vbox_drv.h | 64 +-- drivers/gpu/drm/vboxvideo/vbox_fb.c | 22 +- drivers/gpu/drm/vboxvideo/vbox_main.c | 70 +-- drivers/gpu/drm/vboxvideo/vbox_mode.c | 36 +- drivers/gpu/drm/vboxvideo/vbox_ttm.c | 344 +----------- include/drm/drm_gem_ttm_helper.h | 119 ++++ include/drm/drm_simple_ttm_helper.h | 74 +++ 41 files changed, 1292 insertions(+), 2162 deletions(-)create mode 100644
drivers/gpu/drm/drm_gem_ttm_helper.ccreate mode 100644drivers/gpu/drm/drm_simple_ttm_helper.ccreate mode 100644drivers/gpu/drm/drm_ttm_helper_common.ccreate mode 100644include/drm/drm_gem_ttm_helper.hcreate mode 100644include/drm/drm_simple_ttm_helper.h--
2.21.0
Signature · 5 lines
Thomas Zimmermann Graphics Driver Developer SUSE Linux GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany GF: Felix Imendörffer, Mary Higgins, Sri Rasiah HRB 21284 (AG Nürnberg)
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 12/15] drm/vboxvideo: Convert vboxvideo driver to |struct drm_gem_ttm_object|
In reply to Thomas ZimmermannHi,
Quoted 6 lines · Thomas Zimmermann
This patch replaces |struct vbox_bo| and its helpers with the generic implementation of |struct drm_gem_ttm_object|. The only change in semantics is that
&ttm_bo_driver.verify_access()now does the actual verification.Signed-off-by Thomas Zimmermann <[email protected]>
Nice cleanup, thank you, patch looks good to me:
Regards,
Hans
Quoted 667 lines
--- drivers/gpu/drm/vboxvideo/Kconfig | 1 + drivers/gpu/drm/vboxvideo/vbox_drv.c | 5 +- drivers/gpu/drm/vboxvideo/vbox_drv.h | 58 +------ drivers/gpu/drm/vboxvideo/vbox_fb.c | 22 +-- drivers/gpu/drm/vboxvideo/vbox_main.c | 70 +------- drivers/gpu/drm/vboxvideo/vbox_mode.c | 36 +++-- drivers/gpu/drm/vboxvideo/vbox_ttm.c | 223 +------------------------- 7 files changed, 45 insertions(+), 370 deletions(-)drivers/gpu/drm/vboxvideo/Kconfig +1
-0@@ -3,6 +3,7 @@ config DRM_VBOXVIDEO depends on DRM && X86 && PCI select DRM_KMS_HELPER select DRM_TTM + select DRM_GEM_TTM_HELPER select GENERIC_ALLOCATOR help This is a KMS driver for the virtual Graphics Card used indrivers/gpu/drm/vboxvideo/vbox_drv.c +3
-2@@ -215,9 +215,10 @@ static struct drm_driver driver = { .minor = DRIVER_MINOR, .patchlevel = DRIVER_PATCHLEVEL, - .gem_free_object_unlocked = vbox_gem_free_object, + .gem_free_object_unlocked = + drm_gem_ttm_driver_gem_free_object_unlocked, .dumb_create = vbox_dumb_create, - .dumb_map_offset = vbox_dumb_mmap_offset, + .dumb_map_offset = drm_gem_ttm_driver_dumb_mmap_offset, .prime_handle_to_fd = drm_gem_prime_handle_to_fd, .prime_fd_to_handle = drm_gem_prime_fd_to_handle, .gem_prime_export = drm_gem_prime_export,drivers/gpu/drm/vboxvideo/vbox_drv.h +1
-57@@ -18,6 +18,7 @@#include <drm/drm_encoder.h> #include <drm/drm_fb_helper.h> #include <drm/drm_gem.h> +#include <drm/drm_gem_ttm_helper.h> #include <drm/ttm/ttm_bo_api.h> #include <drm/ttm/ttm_bo_driver.h> @@ -170,73 +171,16 @@ int vboxfb_create(struct drm_fb_helper *helper, struct drm_fb_helper_surface_size *sizes);void vbox_fbdev_fini (struct vbox_private *vbox); -struct vbox_bo { -struct ttm_buffer_object bo; -struct ttm_placement placement; -struct ttm_bo_kmap_obj kmap; -struct drm_gem_object gem; -struct ttm_place placements[3 ]; -int pin_count; -}; - -#define gem_to_vbox_bo (gobj) container_of((gobj), struct vbox_bo, gem) - -static inline struct vbox_bo *vbox_bo (struct ttm_buffer_object *bo) -{ - return container_of(bo, struct vbox_bo, bo); -} - -#define to_vbox_obj (x) container_of(x, struct vbox_gem_object, base) - -static inline u64 vbox_bo_gpu_offset (struct vbox_bo *bo) -{ -return bo->bo.offset; -} -int vbox_dumb_create (struct drm_file *file,struct drm_device *dev,struct drm_mode_create_dumb *args); -void vbox_gem_free_object (struct drm_gem_object *obj); -int vbox_dumb_mmap_offset (struct drm_file *file, -struct drm_device *dev, -u32 handle,u64 *offset); -int vbox_mm_init (struct vbox_private *vbox);void vbox_mm_fini (struct vbox_private *vbox); -int vbox_bo_create (struct vbox_private *vbox,int size,int align, -u32 flags,struct vbox_bo **pvboxbo); -int vbox_gem_create (struct vbox_private *vbox,u32 size,bool iskernel,struct drm_gem_object **obj); - -int vbox_bo_pin (struct vbox_bo *bo,u32 pl_flag); -int vbox_bo_unpin (struct vbox_bo *bo); - -static inline int vbox_bo_reserve (struct vbox_bo *bo,bool no_wait) -{ -int ret; - - ret =ttm_bo_reserve (&bo->bo, true, no_wait,NULL ); -if (ret) { -if (ret != -ERESTARTSYS && ret != -EBUSY ) -DRM_ERROR ("reserve failed %p\n" , bo); -return ret; - } -return 0 ; -} - -static inline void vbox_bo_unreserve (struct vbox_bo *bo) -{ -ttm_bo_unreserve (&bo->bo); -} - -void vbox_ttm_placement (struct vbox_bo *bo,int domain); -int vbox_bo_push_sysram (struct vbox_bo *bo);int vbox_mmap (struct file *filp,struct vm_area_struct *vma); -void *vbox_bo_kmap (struct vbox_bo *bo); -void vbox_bo_kunmap (struct vbox_bo *bo);/* vbox_prime.c */ int vbox_gem_prime_pin (struct drm_gem_object *obj);drivers/gpu/drm/vboxvideo/vbox_fb.c +11
-11@@ -51,9 +51,9 @@ int vboxfb_create(struct drm_fb_helper *helper,struct drm_framebuffer *fb;struct fb_info *info;struct drm_gem_object *gobj; -struct vbox_bo *bo; +struct drm_gem_ttm_object *gbo;int size, ret; -u64 gpu_addr; +s64 gpu_addr;u32 pitch; mode_cmd.width = sizes->surface_width;@@ -75,9 +75,9 @@ int vboxfb_create(struct drm_fb_helper *helper,if (ret)return ret; - bo =gem_to_vbox_bo (gobj); + gbo =drm_gem_ttm_of_gem (gobj); - ret =vbox_bo_pin (bo,TTM_PL_FLAG_VRAM ); + ret =drm_gem_ttm_pin (gbo,TTM_PL_FLAG_VRAM );if (ret)return ret;@@ -86,7 +86,7 @@ int vboxfb_create(struct drm_fb_helper *helper,return PTR_ERR (info); info->screen_size = size; - info->screen_base = (char __iomem *)vbox_bo_kmap (bo); + info->screen_base = (char __iomem *)drm_gem_ttm_kmap (gbo, true);if (IS_ERR (info->screen_base))return PTR_ERR (info->screen_base);@@ -104,7 +104,9 @@ int vboxfb_create(struct drm_fb_helper *helper,drm_fb_helper_fill_info (info, helper, sizes); - gpu_addr =vbox_bo_gpu_offset (bo); + gpu_addr =drm_gem_ttm_vram_offset (gbo); +if (gpu_addr <0 ) +return (int )gpu_addr; info->fix.smem_start = info->apertures->ranges[0 ].base + gpu_addr; info->fix.smem_len = vbox->available_vram_size - gpu_addr;@@ -132,12 +134,10 @@ void vbox_fbdev_fini(struct vbox_private *vbox)drm_fb_helper_unregister_fbi (&vbox->fb_helper);if (afb->obj) { -struct vbox_bo *bo =gem_to_vbox_bo (afb->obj); +struct drm_gem_ttm_object *gbo =drm_gem_ttm_of_gem (afb->obj); -vbox_bo_kunmap (bo); - -if (bo->pin_count) -vbox_bo_unpin (bo); +drm_gem_ttm_kunmap (gbo); +drm_gem_ttm_unpin (gbo);drm_gem_object_put_unlocked (afb->obj); afb->obj =NULL ;drivers/gpu/drm/vboxvideo/vbox_main.c +8
-62@@ -274,7 +274,7 @@ void vbox_hw_fini(struct vbox_private *vbox)int vbox_gem_create (struct vbox_private *vbox,u32 size,bool iskernel,struct drm_gem_object **obj) { -struct vbox_bo *vboxbo; +struct drm_gem_ttm_object *gbo;int ret; *obj =NULL ;@@ -283,14 +283,15 @@ int vbox_gem_create(struct vbox_private *vbox,if (size ==0 )return -EINVAL ; - ret =vbox_bo_create (vbox, size,0 ,0 , &vboxbo); -if (ret) { + gbo =drm_gem_ttm_create (&vbox->ddev, &vbox->ttm.bdev, size,0 , false); +if (IS_ERR (gbo)) { + ret =PTR_ERR (gbo);if (ret != -ERESTARTSYS )DRM_ERROR ("failed to allocate GEM object\n" );return ret; } - *obj = &vboxbo->gem; + *obj = &gbo->gem;return 0 ; }@@ -298,64 +299,9 @@ int vbox_gem_create(struct vbox_private *vbox,int vbox_dumb_create (struct drm_file *file,struct drm_device *dev,struct drm_mode_create_dumb *args) { -struct vbox_private *vbox = - container_of(dev, struct vbox_private, ddev); -struct drm_gem_object *gobj; -u32 handle; -int ret; - - args->pitch = args->width * ((args->bpp +7 ) /8 ); - args->size = args->pitch * args->height; - - ret =vbox_gem_create (vbox, args->size, false, &gobj); -if (ret) -return ret; - - ret =drm_gem_handle_create (file, gobj, &handle); -drm_gem_object_put_unlocked (gobj); -if (ret) -return ret; +struct vbox_private *vbox = dev->dev_private; - args->handle = handle; - -return 0 ; -} - -void vbox_gem_free_object (struct drm_gem_object *obj) -{ -struct vbox_bo *vbox_bo =gem_to_vbox_bo (obj); +return drm_gem_ttm_fill_create_dumb (file, dev, &vbox->ttm.bdev,0 , + false, args); -ttm_bo_put (&vbox_bo->bo); -} - -static inline u64 vbox_bo_mmap_offset (struct vbox_bo *bo) -{ -return drm_vma_node_offset_addr (&bo->bo.vma_node); -} - -int -vbox_dumb_mmap_offset (struct drm_file *file, -struct drm_device *dev, -u32 handle,u64 *offset) -{ -struct drm_gem_object *obj; -int ret; -struct vbox_bo *bo; - -mutex_lock (&dev->struct_mutex); - obj =drm_gem_object_lookup (file, handle); -if (!obj) { - ret = -ENOENT ; - goto out_unlock; - } - - bo =gem_to_vbox_bo (obj); - *offset =vbox_bo_mmap_offset (bo); - -drm_gem_object_put (obj); - ret =0 ; - -out_unlock: -mutex_unlock (&dev->struct_mutex); -return ret; }drivers/gpu/drm/vboxvideo/vbox_mode.c +19
-17@@ -173,7 +173,8 @@ static void vbox_crtc_set_base_and_mode(struct drm_crtc *crtc,struct drm_framebuffer *fb, int x, int y) { - struct vbox_bo *bo = gem_to_vbox_bo(to_vbox_framebuffer(fb)->obj); + struct drm_gem_ttm_object *gbo = +drm_gem_ttm_of_gem (to_vbox_framebuffer (fb)->obj);struct vbox_private *vbox = crtc->dev->dev_private;struct vbox_crtc *vbox_crtc =to_vbox_crtc (crtc);bool needs_modeset =drm_atomic_crtc_needs_modeset (crtc->state);@@ -187,7 +188,7 @@ static void vbox_crtc_set_base_and_mode(struct drm_crtc *crtc, vbox_crtc->x = x; vbox_crtc->y = y; - vbox_crtc->fb_offset =vbox_bo_gpu_offset (bo); + vbox_crtc->fb_offset =drm_gem_ttm_vram_offset (gbo);/* vbox_do_modeset() checks vbox->single_framebuffer so update it now */ if (needs_modeset &&vbox_set_up_input_mapping (vbox)) {@@ -303,14 +304,14 @@ static void vbox_primary_atomic_disable(struct drm_plane *plane,static int vbox_primary_prepare_fb (struct drm_plane *plane,struct drm_plane_state *new_state) { -struct vbox_bo *bo; +struct drm_gem_ttm_object *gbo;int ret;if (!new_state->fb)return 0 ; - bo =gem_to_vbox_bo (to_vbox_framebuffer (new_state->fb)->obj); - ret =vbox_bo_pin (bo,TTM_PL_FLAG_VRAM ); + gbo =drm_gem_ttm_of_gem (to_vbox_framebuffer (new_state->fb)->obj); + ret =drm_gem_ttm_pin (gbo,TTM_PL_FLAG_VRAM );if (ret)DRM_WARN ("Error %d pinning new fb, out of video mem?\n" , ret);@@ -320,13 +321,13 @@ static int vbox_primary_prepare_fb(struct drm_plane *plane,static void vbox_primary_cleanup_fb (struct drm_plane *plane,struct drm_plane_state *old_state) { -struct vbox_bo *bo; +struct drm_gem_ttm_object *gbo;if (!old_state->fb)return ; - bo =gem_to_vbox_bo (to_vbox_framebuffer (old_state->fb)->obj); -vbox_bo_unpin (bo); + gbo =drm_gem_ttm_of_gem (to_vbox_framebuffer (old_state->fb)->obj); +drm_gem_ttm_unpin (gbo); } static int vbox_cursor_atomic_check(struct drm_plane *plane,@@ -386,7 +387,8 @@ static void vbox_cursor_atomic_update(struct drm_plane *plane, container_of(plane->dev, struct vbox_private, ddev);struct vbox_crtc *vbox_crtc =to_vbox_crtc (plane->state->crtc);struct drm_framebuffer *fb = plane->state->fb; -struct vbox_bo *bo =gem_to_vbox_bo (to_vbox_framebuffer (fb)->obj); +struct drm_gem_ttm_object *gbo = +drm_gem_ttm_of_gem (to_vbox_framebuffer (fb)->obj);u32 width = plane->state->crtc_w;u32 height = plane->state->crtc_h;size_t data_size, mask_size;@@ -405,7 +407,7 @@ static void vbox_cursor_atomic_update(struct drm_plane *plane, vbox_crtc->cursor_enabled = true;/* pinning is done in prepare/cleanup framebuffer */ - src =vbox_bo_kmap (bo); + src =drm_gem_ttm_kmap (gbo, true);if (IS_ERR (src)) {mutex_unlock (&vbox->hw_mutex);DRM_WARN ("Could not kmap cursor bo, skipping update\n" );@@ -421,7 +423,7 @@ static void vbox_cursor_atomic_update(struct drm_plane *plane, data_size = width * height *4 + mask_size;copy_cursor_image (src, vbox->cursor_data, width, height, mask_size); -vbox_bo_kunmap (bo); +drm_gem_ttm_kunmap (gbo); flags =VBOX_MOUSE_POINTER_VISIBLE |VBOX_MOUSE_POINTER_SHAPE |VBOX_MOUSE_POINTER_ALPHA ;@@ -461,25 +463,25 @@ static void vbox_cursor_atomic_disable(struct drm_plane *plane,static int vbox_cursor_prepare_fb (struct drm_plane *plane,struct drm_plane_state *new_state) { -struct vbox_bo *bo; +struct drm_gem_ttm_object *gbo;if (!new_state->fb)return 0 ; - bo =gem_to_vbox_bo (to_vbox_framebuffer (new_state->fb)->obj); -return vbox_bo_pin (bo,TTM_PL_FLAG_SYSTEM ); + gbo =drm_gem_ttm_of_gem (to_vbox_framebuffer (new_state->fb)->obj); +return drm_gem_ttm_pin (gbo,TTM_PL_FLAG_SYSTEM ); }static void vbox_cursor_cleanup_fb (struct drm_plane *plane,struct drm_plane_state *old_state) { -struct vbox_bo *bo; +struct drm_gem_ttm_object *gbo;if (!plane->state->fb)return ; - bo =gem_to_vbox_bo (to_vbox_framebuffer (plane->state->fb)->obj); -vbox_bo_unpin (bo); + gbo =drm_gem_ttm_of_gem (to_vbox_framebuffer (plane->state->fb)->obj); +drm_gem_ttm_unpin (gbo); }static const u32 vbox_cursor_plane_formats[] = {drivers/gpu/drm/vboxvideo/vbox_ttm.c +2
-221@@ -16,24 +16,6 @@ static inline struct vbox_private *vbox_bdev(struct ttm_bo_device *bd) return container_of(bd, struct vbox_private, ttm.bdev); } -static void vbox_bo_ttm_destroy (struct ttm_buffer_object *tbo) -{ -struct vbox_bo *bo; - - bo = container_of(tbo, struct vbox_bo, bo); - -drm_gem_object_release (&bo->gem); -kfree (bo); -} - -static bool vbox_ttm_bo_is_vbox_bo (struct ttm_buffer_object *bo) -{ -if (bo->destroy == &vbox_bo_ttm_destroy) -return true; - -return false; -} -static int vbox_bo_init_mem_type (struct ttm_bo_device *bdev,u32 type,struct ttm_mem_type_manager *man)@@ -58,24 +40,6 @@ vbox_bo_init_mem_type(struct ttm_bo_device *bdev, u32 type,return 0 ; } -static void -vbox_bo_evict_flags (struct ttm_buffer_object *bo,struct ttm_placement *pl) -{ -struct vbox_bo *vboxbo =vbox_bo (bo); - -if (!vbox_ttm_bo_is_vbox_bo (bo)) -return ; - -vbox_ttm_placement (vboxbo,TTM_PL_FLAG_SYSTEM ); - *pl = vboxbo->placement; -} - -static int vbox_bo_verify_access (struct ttm_buffer_object *bo, -struct file *filp) -{ -return 0 ; -} -static int vbox_ttm_io_mem_reserve (struct ttm_bo_device *bdev,struct ttm_mem_reg *mem) {@@ -141,8 +105,8 @@ static struct ttm_bo_driver vbox_bo_driver = { .ttm_tt_create = vbox_ttm_tt_create, .init_mem_type = vbox_bo_init_mem_type, .eviction_valuable = ttm_bo_eviction_valuable, - .evict_flags = vbox_bo_evict_flags, - .verify_access = vbox_bo_verify_access, + .evict_flags = drm_gem_ttm_bo_driver_evict_flags, + .verify_access = drm_gem_ttm_bo_driver_verify_access, .io_mem_reserve = &vbox_ttm_io_mem_reserve, .io_mem_free = &vbox_ttm_io_mem_free, };@@ -196,165 +160,6 @@ void vbox_mm_fini(struct vbox_private *vbox)ttm_bo_device_release (&vbox->ttm.bdev); } -void vbox_ttm_placement (struct vbox_bo *bo,int domain) -{ -unsigned int i; -u32 c =0 ; - - bo->placement.placement = bo->placements; - bo->placement.busy_placement = bo->placements; - -if (domain &TTM_PL_FLAG_VRAM ) - bo->placements[c++].flags = -TTM_PL_FLAG_WC |TTM_PL_FLAG_UNCACHED |TTM_PL_FLAG_VRAM ; -if (domain &TTM_PL_FLAG_SYSTEM ) - bo->placements[c++].flags = -TTM_PL_MASK_CACHING |TTM_PL_FLAG_SYSTEM ; -if (!c) - bo->placements[c++].flags = -TTM_PL_MASK_CACHING |TTM_PL_FLAG_SYSTEM ; - - bo->placement.num_placement = c; - bo->placement.num_busy_placement = c; - -for (i =0 ; i < c; ++i) { - bo->placements[i].fpfn =0 ; - bo->placements[i].lpfn =0 ; - } -} - -int vbox_bo_create (struct vbox_private *vbox,int size,int align, -u32 flags,struct vbox_bo **pvboxbo) -{ -struct vbox_bo *vboxbo; -size_t acc_size; -int ret; - - vboxbo =kzalloc (sizeof (*vboxbo),GFP_KERNEL ); -if (!vboxbo) -return -ENOMEM ; - - ret =drm_gem_object_init (&vbox->ddev, &vboxbo->gem, size); -if (ret) - goto err_free_vboxbo; - - vboxbo->bo.bdev = &vbox->ttm.bdev; - -vbox_ttm_placement (vboxbo,TTM_PL_FLAG_VRAM |TTM_PL_FLAG_SYSTEM ); - - acc_size =ttm_bo_dma_acc_size (&vbox->ttm.bdev, size, -sizeof (struct vbox_bo )); - - ret =ttm_bo_init (&vbox->ttm.bdev, &vboxbo->bo, size, - ttm_bo_type_device, &vboxbo->placement, - align >>PAGE_SHIFT , false, acc_size, -NULL ,NULL , vbox_bo_ttm_destroy); -if (ret) - goto err_free_vboxbo; - - *pvboxbo = vboxbo; - -return 0 ; - -err_free_vboxbo: -kfree (vboxbo); -return ret; -} - -int vbox_bo_pin (struct vbox_bo *bo,u32 pl_flag) -{ -struct ttm_operation_ctx ctx = { false, false }; -int i, ret; - -if (bo->pin_count) { - bo->pin_count++; -return 0 ; - } - - ret =vbox_bo_reserve (bo, false); -if (ret) -return ret; - -vbox_ttm_placement (bo, pl_flag); - -for (i =0 ; i < bo->placement.num_placement; i++) - bo->placements[i].flags |=TTM_PL_FLAG_NO_EVICT ; - - ret =ttm_bo_validate (&bo->bo, &bo->placement, &ctx); -if (ret ==0 ) - bo->pin_count =1 ; - -vbox_bo_unreserve (bo); - -return ret; -} - -int vbox_bo_unpin (struct vbox_bo *bo) -{ -struct ttm_operation_ctx ctx = { false, false }; -int i, ret; - -if (!bo->pin_count) { -DRM_ERROR ("unpin bad %p\n" , bo); -return 0 ; - } - bo->pin_count--; -if (bo->pin_count) -return 0 ; - - ret =vbox_bo_reserve (bo, false); -if (ret) { -DRM_ERROR ("Error %d reserving bo, leaving it pinned\n" , ret); -return ret; - } - -for (i =0 ; i < bo->placement.num_placement; i++) - bo->placements[i].flags &= ~TTM_PL_FLAG_NO_EVICT ; - - ret =ttm_bo_validate (&bo->bo, &bo->placement, &ctx); - -vbox_bo_unreserve (bo); - -return ret; -} - -/* -* Move a vbox-owned buffer object to system memory if no one else has it -* pinned. The caller must have pinned it previously, and this call will -* release the caller's pin. -*/ -int vbox_bo_push_sysram (struct vbox_bo *bo) -{ -struct ttm_operation_ctx ctx = { false, false }; -int i, ret; - -if (!bo->pin_count) { -DRM_ERROR ("unpin bad %p\n" , bo); -return 0 ; - } - bo->pin_count--; -if (bo->pin_count) -return 0 ; - -if (bo->kmap.virtual) { -ttm_bo_kunmap (&bo->kmap); - bo->kmap.virtual =NULL ; - } - -vbox_ttm_placement (bo,TTM_PL_FLAG_SYSTEM ); - -for (i =0 ; i < bo->placement.num_placement; i++) - bo->placements[i].flags |=TTM_PL_FLAG_NO_EVICT ; - - ret =ttm_bo_validate (&bo->bo, &bo->placement, &ctx); -if (ret) { -DRM_ERROR ("pushing to VRAM failed\n" ); -return ret; - } - -return 0 ; -} -int vbox_mmap (struct file *filp,struct vm_area_struct *vma) {struct drm_file *file_priv = filp->private_data;@@ -362,27 +167,3 @@ int vbox_mmap(struct file *filp, struct vm_area_struct *vma)return ttm_bo_mmap (filp, vma, &vbox->ttm.bdev); } - -void *vbox_bo_kmap (struct vbox_bo *bo) -{ -int ret; - -if (bo->kmap.virtual) -return bo->kmap.virtual; - - ret =ttm_bo_kmap (&bo->bo,0 , bo->bo.num_pages, &bo->kmap); -if (ret) { -DRM_ERROR ("Error kmapping bo: %d\n" , ret); -return NULL ; - } - -return bo->kmap.virtual; -} - -void vbox_bo_kunmap (struct vbox_bo *bo) -{ -if (bo->kmap.virtual) { -ttm_bo_kunmap (&bo->kmap); - bo->kmap.virtual =NULL ; - } -}
Re: [PATCH 12/15] drm/vboxvideo: Convert vboxvideo driver to |struct drm_gem_ttm_object|
In reply to Thomas ZimmermannHi,
Quoted 6 lines · Thomas Zimmermann
This patch replaces |struct vbox_bo| and its helpers with the generic implementation of |struct drm_gem_ttm_object|. The only change in semantics is that
&ttm_bo_driver.verify_access()now does the actual verification.Signed-off-by Thomas Zimmermann <[email protected]>
Nice cleanup, thank you, patch looks good to me:
Regards,
Hans
Quoted 657 lines
--- drivers/gpu/drm/vboxvideo/Kconfig | 1 + drivers/gpu/drm/vboxvideo/vbox_drv.c | 5 +- drivers/gpu/drm/vboxvideo/vbox_drv.h | 58 +------ drivers/gpu/drm/vboxvideo/vbox_fb.c | 22 +-- drivers/gpu/drm/vboxvideo/vbox_main.c | 70 +------- drivers/gpu/drm/vboxvideo/vbox_mode.c | 36 +++-- drivers/gpu/drm/vboxvideo/vbox_ttm.c | 223 +------------------------- 7 files changed, 45 insertions(+), 370 deletions(-)drivers/gpu/drm/vboxvideo/Kconfig +1
-0@@ -3,6 +3,7 @@ config DRM_VBOXVIDEO depends on DRM && X86 && PCI select DRM_KMS_HELPER select DRM_TTM + select DRM_GEM_TTM_HELPER select GENERIC_ALLOCATOR help This is a KMS driver for the virtual Graphics Card used indrivers/gpu/drm/vboxvideo/vbox_drv.c +3
-2@@ -215,9 +215,10 @@ static struct drm_driver driver = { .minor = DRIVER_MINOR, .patchlevel = DRIVER_PATCHLEVEL, - .gem_free_object_unlocked = vbox_gem_free_object, + .gem_free_object_unlocked = + drm_gem_ttm_driver_gem_free_object_unlocked, .dumb_create = vbox_dumb_create, - .dumb_map_offset = vbox_dumb_mmap_offset, + .dumb_map_offset = drm_gem_ttm_driver_dumb_mmap_offset, .prime_handle_to_fd = drm_gem_prime_handle_to_fd, .prime_fd_to_handle = drm_gem_prime_fd_to_handle, .gem_prime_export = drm_gem_prime_export,drivers/gpu/drm/vboxvideo/vbox_drv.h +1
-57@@ -18,6 +18,7 @@#include <drm/drm_encoder.h> #include <drm/drm_fb_helper.h> #include <drm/drm_gem.h> +#include <drm/drm_gem_ttm_helper.h> #include <drm/ttm/ttm_bo_api.h> #include <drm/ttm/ttm_bo_driver.h> @@ -170,73 +171,16 @@ int vboxfb_create(struct drm_fb_helper *helper, struct drm_fb_helper_surface_size *sizes);void vbox_fbdev_fini (struct vbox_private *vbox); -struct vbox_bo { -struct ttm_buffer_object bo; -struct ttm_placement placement; -struct ttm_bo_kmap_obj kmap; -struct drm_gem_object gem; -struct ttm_place placements[3 ]; -int pin_count; -}; - -#define gem_to_vbox_bo (gobj) container_of((gobj), struct vbox_bo, gem) - -static inline struct vbox_bo *vbox_bo (struct ttm_buffer_object *bo) -{ - return container_of(bo, struct vbox_bo, bo); -} - -#define to_vbox_obj (x) container_of(x, struct vbox_gem_object, base) - -static inline u64 vbox_bo_gpu_offset (struct vbox_bo *bo) -{ -return bo->bo.offset; -} -int vbox_dumb_create (struct drm_file *file,struct drm_device *dev,struct drm_mode_create_dumb *args); -void vbox_gem_free_object (struct drm_gem_object *obj); -int vbox_dumb_mmap_offset (struct drm_file *file, -struct drm_device *dev, -u32 handle,u64 *offset); -int vbox_mm_init (struct vbox_private *vbox);void vbox_mm_fini (struct vbox_private *vbox); -int vbox_bo_create (struct vbox_private *vbox,int size,int align, -u32 flags,struct vbox_bo **pvboxbo); -int vbox_gem_create (struct vbox_private *vbox,u32 size,bool iskernel,struct drm_gem_object **obj); - -int vbox_bo_pin (struct vbox_bo *bo,u32 pl_flag); -int vbox_bo_unpin (struct vbox_bo *bo); - -static inline int vbox_bo_reserve (struct vbox_bo *bo,bool no_wait) -{ -int ret; - - ret =ttm_bo_reserve (&bo->bo, true, no_wait,NULL ); -if (ret) { -if (ret != -ERESTARTSYS && ret != -EBUSY ) -DRM_ERROR ("reserve failed %p\n" , bo); -return ret; - } -return 0 ; -} - -static inline void vbox_bo_unreserve (struct vbox_bo *bo) -{ -ttm_bo_unreserve (&bo->bo); -} - -void vbox_ttm_placement (struct vbox_bo *bo,int domain); -int vbox_bo_push_sysram (struct vbox_bo *bo);int vbox_mmap (struct file *filp,struct vm_area_struct *vma); -void *vbox_bo_kmap (struct vbox_bo *bo); -void vbox_bo_kunmap (struct vbox_bo *bo);/* vbox_prime.c */ int vbox_gem_prime_pin (struct drm_gem_object *obj);drivers/gpu/drm/vboxvideo/vbox_fb.c +11
-11@@ -51,9 +51,9 @@ int vboxfb_create(struct drm_fb_helper *helper,struct drm_framebuffer *fb;struct fb_info *info;struct drm_gem_object *gobj; -struct vbox_bo *bo; +struct drm_gem_ttm_object *gbo;int size, ret; -u64 gpu_addr; +s64 gpu_addr;u32 pitch; mode_cmd.width = sizes->surface_width;@@ -75,9 +75,9 @@ int vboxfb_create(struct drm_fb_helper *helper,if (ret)return ret; - bo =gem_to_vbox_bo (gobj); + gbo =drm_gem_ttm_of_gem (gobj); - ret =vbox_bo_pin (bo,TTM_PL_FLAG_VRAM ); + ret =drm_gem_ttm_pin (gbo,TTM_PL_FLAG_VRAM );if (ret)return ret;@@ -86,7 +86,7 @@ int vboxfb_create(struct drm_fb_helper *helper,return PTR_ERR (info); info->screen_size = size; - info->screen_base = (char __iomem *)vbox_bo_kmap (bo); + info->screen_base = (char __iomem *)drm_gem_ttm_kmap (gbo, true);if (IS_ERR (info->screen_base))return PTR_ERR (info->screen_base);@@ -104,7 +104,9 @@ int vboxfb_create(struct drm_fb_helper *helper,drm_fb_helper_fill_info (info, helper, sizes); - gpu_addr =vbox_bo_gpu_offset (bo); + gpu_addr =drm_gem_ttm_vram_offset (gbo); +if (gpu_addr <0 ) +return (int )gpu_addr; info->fix.smem_start = info->apertures->ranges[0 ].base + gpu_addr; info->fix.smem_len = vbox->available_vram_size - gpu_addr;@@ -132,12 +134,10 @@ void vbox_fbdev_fini(struct vbox_private *vbox)drm_fb_helper_unregister_fbi (&vbox->fb_helper);if (afb->obj) { -struct vbox_bo *bo =gem_to_vbox_bo (afb->obj); +struct drm_gem_ttm_object *gbo =drm_gem_ttm_of_gem (afb->obj); -vbox_bo_kunmap (bo); - -if (bo->pin_count) -vbox_bo_unpin (bo); +drm_gem_ttm_kunmap (gbo); +drm_gem_ttm_unpin (gbo);drm_gem_object_put_unlocked (afb->obj); afb->obj =NULL ;drivers/gpu/drm/vboxvideo/vbox_main.c +8
-62@@ -274,7 +274,7 @@ void vbox_hw_fini(struct vbox_private *vbox)int vbox_gem_create (struct vbox_private *vbox,u32 size,bool iskernel,struct drm_gem_object **obj) { -struct vbox_bo *vboxbo; +struct drm_gem_ttm_object *gbo;int ret; *obj =NULL ;@@ -283,14 +283,15 @@ int vbox_gem_create(struct vbox_private *vbox,if (size ==0 )return -EINVAL ; - ret =vbox_bo_create (vbox, size,0 ,0 , &vboxbo); -if (ret) { + gbo =drm_gem_ttm_create (&vbox->ddev, &vbox->ttm.bdev, size,0 , false); +if (IS_ERR (gbo)) { + ret =PTR_ERR (gbo);if (ret != -ERESTARTSYS )DRM_ERROR ("failed to allocate GEM object\n" );return ret; } - *obj = &vboxbo->gem; + *obj = &gbo->gem;return 0 ; }@@ -298,64 +299,9 @@ int vbox_gem_create(struct vbox_private *vbox,int vbox_dumb_create (struct drm_file *file,struct drm_device *dev,struct drm_mode_create_dumb *args) { -struct vbox_private *vbox = - container_of(dev, struct vbox_private, ddev); -struct drm_gem_object *gobj; -u32 handle; -int ret; - - args->pitch = args->width * ((args->bpp +7 ) /8 ); - args->size = args->pitch * args->height; - - ret =vbox_gem_create (vbox, args->size, false, &gobj); -if (ret) -return ret; - - ret =drm_gem_handle_create (file, gobj, &handle); -drm_gem_object_put_unlocked (gobj); -if (ret) -return ret; +struct vbox_private *vbox = dev->dev_private; - args->handle = handle; - -return 0 ; -} - -void vbox_gem_free_object (struct drm_gem_object *obj) -{ -struct vbox_bo *vbox_bo =gem_to_vbox_bo (obj); +return drm_gem_ttm_fill_create_dumb (file, dev, &vbox->ttm.bdev,0 , + false, args); -ttm_bo_put (&vbox_bo->bo); -} - -static inline u64 vbox_bo_mmap_offset (struct vbox_bo *bo) -{ -return drm_vma_node_offset_addr (&bo->bo.vma_node); -} - -int -vbox_dumb_mmap_offset (struct drm_file *file, -struct drm_device *dev, -u32 handle,u64 *offset) -{ -struct drm_gem_object *obj; -int ret; -struct vbox_bo *bo; - -mutex_lock (&dev->struct_mutex); - obj =drm_gem_object_lookup (file, handle); -if (!obj) { - ret = -ENOENT ; - goto out_unlock; - } - - bo =gem_to_vbox_bo (obj); - *offset =vbox_bo_mmap_offset (bo); - -drm_gem_object_put (obj); - ret =0 ; - -out_unlock: -mutex_unlock (&dev->struct_mutex); -return ret; }drivers/gpu/drm/vboxvideo/vbox_mode.c +19
-17@@ -173,7 +173,8 @@ static void vbox_crtc_set_base_and_mode(struct drm_crtc *crtc,struct drm_framebuffer *fb, int x, int y) { - struct vbox_bo *bo = gem_to_vbox_bo(to_vbox_framebuffer(fb)->obj); + struct drm_gem_ttm_object *gbo = +drm_gem_ttm_of_gem (to_vbox_framebuffer (fb)->obj);struct vbox_private *vbox = crtc->dev->dev_private;struct vbox_crtc *vbox_crtc =to_vbox_crtc (crtc);bool needs_modeset =drm_atomic_crtc_needs_modeset (crtc->state);@@ -187,7 +188,7 @@ static void vbox_crtc_set_base_and_mode(struct drm_crtc *crtc, vbox_crtc->x = x; vbox_crtc->y = y; - vbox_crtc->fb_offset =vbox_bo_gpu_offset (bo); + vbox_crtc->fb_offset =drm_gem_ttm_vram_offset (gbo);/* vbox_do_modeset() checks vbox->single_framebuffer so update it now */ if (needs_modeset &&vbox_set_up_input_mapping (vbox)) {@@ -303,14 +304,14 @@ static void vbox_primary_atomic_disable(struct drm_plane *plane,static int vbox_primary_prepare_fb (struct drm_plane *plane,struct drm_plane_state *new_state) { -struct vbox_bo *bo; +struct drm_gem_ttm_object *gbo;int ret;if (!new_state->fb)return 0 ; - bo =gem_to_vbox_bo (to_vbox_framebuffer (new_state->fb)->obj); - ret =vbox_bo_pin (bo,TTM_PL_FLAG_VRAM ); + gbo =drm_gem_ttm_of_gem (to_vbox_framebuffer (new_state->fb)->obj); + ret =drm_gem_ttm_pin (gbo,TTM_PL_FLAG_VRAM );if (ret)DRM_WARN ("Error %d pinning new fb, out of video mem?\n" , ret);@@ -320,13 +321,13 @@ static int vbox_primary_prepare_fb(struct drm_plane *plane,static void vbox_primary_cleanup_fb (struct drm_plane *plane,struct drm_plane_state *old_state) { -struct vbox_bo *bo; +struct drm_gem_ttm_object *gbo;if (!old_state->fb)return ; - bo =gem_to_vbox_bo (to_vbox_framebuffer (old_state->fb)->obj); -vbox_bo_unpin (bo); + gbo =drm_gem_ttm_of_gem (to_vbox_framebuffer (old_state->fb)->obj); +drm_gem_ttm_unpin (gbo); } static int vbox_cursor_atomic_check(struct drm_plane *plane,@@ -386,7 +387,8 @@ static void vbox_cursor_atomic_update(struct drm_plane *plane, container_of(plane->dev, struct vbox_private, ddev);struct vbox_crtc *vbox_crtc =to_vbox_crtc (plane->state->crtc);struct drm_framebuffer *fb = plane->state->fb; -struct vbox_bo *bo =gem_to_vbox_bo (to_vbox_framebuffer (fb)->obj); +struct drm_gem_ttm_object *gbo = +drm_gem_ttm_of_gem (to_vbox_framebuffer (fb)->obj);u32 width = plane->state->crtc_w;u32 height = plane->state->crtc_h;size_t data_size, mask_size;@@ -405,7 +407,7 @@ static void vbox_cursor_atomic_update(struct drm_plane *plane, vbox_crtc->cursor_enabled = true;/* pinning is done in prepare/cleanup framebuffer */ - src =vbox_bo_kmap (bo); + src =drm_gem_ttm_kmap (gbo, true);if (IS_ERR (src)) {mutex_unlock (&vbox->hw_mutex);DRM_WARN ("Could not kmap cursor bo, skipping update\n" );@@ -421,7 +423,7 @@ static void vbox_cursor_atomic_update(struct drm_plane *plane, data_size = width * height *4 + mask_size;copy_cursor_image (src, vbox->cursor_data, width, height, mask_size); -vbox_bo_kunmap (bo); +drm_gem_ttm_kunmap (gbo); flags =VBOX_MOUSE_POINTER_VISIBLE |VBOX_MOUSE_POINTER_SHAPE |VBOX_MOUSE_POINTER_ALPHA ;@@ -461,25 +463,25 @@ static void vbox_cursor_atomic_disable(struct drm_plane *plane,static int vbox_cursor_prepare_fb (struct drm_plane *plane,struct drm_plane_state *new_state) { -struct vbox_bo *bo; +struct drm_gem_ttm_object *gbo;if (!new_state->fb)return 0 ; - bo =gem_to_vbox_bo (to_vbox_framebuffer (new_state->fb)->obj); -return vbox_bo_pin (bo,TTM_PL_FLAG_SYSTEM ); + gbo =drm_gem_ttm_of_gem (to_vbox_framebuffer (new_state->fb)->obj); +return drm_gem_ttm_pin (gbo,TTM_PL_FLAG_SYSTEM ); }static void vbox_cursor_cleanup_fb (struct drm_plane *plane,struct drm_plane_state *old_state) { -struct vbox_bo *bo; +struct drm_gem_ttm_object *gbo;if (!plane->state->fb)return ; - bo =gem_to_vbox_bo (to_vbox_framebuffer (plane->state->fb)->obj); -vbox_bo_unpin (bo); + gbo =drm_gem_ttm_of_gem (to_vbox_framebuffer (plane->state->fb)->obj); +drm_gem_ttm_unpin (gbo); }static const u32 vbox_cursor_plane_formats[] = {drivers/gpu/drm/vboxvideo/vbox_ttm.c +2
-211@@ -16,24 +16,6 @@ static inline struct vbox_private *vbox_bdev(struct ttm_bo_device *bd) return container_of(bd, struct vbox_private, ttm.bdev); } -static void vbox_bo_ttm_destroy (struct ttm_buffer_object *tbo) -{ -struct vbox_bo *bo; - - bo = container_of(tbo, struct vbox_bo, bo); - -drm_gem_object_release (&bo->gem); -kfree (bo); -} - -static bool vbox_ttm_bo_is_vbox_bo (struct ttm_buffer_object *bo) -{ -if (bo->destroy == &vbox_bo_ttm_destroy) -return true; - -return false; -} -static int vbox_bo_init_mem_type (struct ttm_bo_device *bdev,u32 type,struct ttm_mem_type_manager *man)@@ -58,24 +40,6 @@ vbox_bo_init_mem_type(struct ttm_bo_device *bdev, u32 type,return 0 ; } -static void -vbox_bo_evict_flags (struct ttm_buffer_object *bo,struct ttm_placement *pl) -{ -struct vbox_bo *vboxbo =vbox_bo (bo); - -if (!vbox_ttm_bo_is_vbox_bo (bo)) -return ; - -vbox_ttm_placement (vboxbo,TTM_PL_FLAG_SYSTEM ); - *pl = vboxbo->placement; -} - -static int vbox_bo_verify_access (struct ttm_buffer_object *bo, -struct file *filp) -{ -return 0 ; -} -static int vbox_ttm_io_mem_reserve (struct ttm_bo_device *bdev,struct ttm_mem_reg *mem) {@@ -141,8 +105,8 @@ static struct ttm_bo_driver vbox_bo_driver = { .ttm_tt_create = vbox_ttm_tt_create, .init_mem_type = vbox_bo_init_mem_type, .eviction_valuable = ttm_bo_eviction_valuable, - .evict_flags = vbox_bo_evict_flags, - .verify_access = vbox_bo_verify_access, + .evict_flags = drm_gem_ttm_bo_driver_evict_flags, + .verify_access = drm_gem_ttm_bo_driver_verify_access, .io_mem_reserve = &vbox_ttm_io_mem_reserve, .io_mem_free = &vbox_ttm_io_mem_free, };@@ -196,165 +160,6 @@ void vbox_mm_fini(struct vbox_private *vbox)ttm_bo_device_release (&vbox->ttm.bdev); } -void vbox_ttm_placement (struct vbox_bo *bo,int domain) -{ -unsigned int i; -u32 c =0 ; - - bo->placement.placement = bo->placements; - bo->placement.busy_placement = bo->placements; - -if (domain &TTM_PL_FLAG_VRAM ) - bo->placements[c++].flags = -TTM_PL_FLAG_WC |TTM_PL_FLAG_UNCACHED |TTM_PL_FLAG_VRAM ; -if (domain &TTM_PL_FLAG_SYSTEM ) - bo->placements[c++].flags = -TTM_PL_MASK_CACHING |TTM_PL_FLAG_SYSTEM ; -if (!c) - bo->placements[c++].flags = -TTM_PL_MASK_CACHING |TTM_PL_FLAG_SYSTEM ; - - bo->placement.num_placement = c; - bo->placement.num_busy_placement = c; - -for (i =0 ; i < c; ++i) { - bo->placements[i].fpfn =0 ; - bo->placements[i].lpfn =0 ; - } -} - -int vbox_bo_create (struct vbox_private *vbox,int size,int align, -u32 flags,struct vbox_bo **pvboxbo) -{ -struct vbox_bo *vboxbo; -size_t acc_size; -int ret; - - vboxbo =kzalloc (sizeof (*vboxbo),GFP_KERNEL ); -if (!vboxbo) -return -ENOMEM ; - - ret =drm_gem_object_init (&vbox->ddev, &vboxbo->gem, size); -if (ret) - goto err_free_vboxbo; - - vboxbo->bo.bdev = &vbox->ttm.bdev; - -vbox_ttm_placement (vboxbo,TTM_PL_FLAG_VRAM |TTM_PL_FLAG_SYSTEM ); - - acc_size =ttm_bo_dma_acc_size (&vbox->ttm.bdev, size, -sizeof (struct vbox_bo )); - - ret =ttm_bo_init (&vbox->ttm.bdev, &vboxbo->bo, size, - ttm_bo_type_device, &vboxbo->placement, - align >>PAGE_SHIFT , false, acc_size, -NULL ,NULL , vbox_bo_ttm_destroy); -if (ret) - goto err_free_vboxbo; - - *pvboxbo = vboxbo; - -return 0 ; - -err_free_vboxbo: -kfree (vboxbo); -return ret; -} - -int vbox_bo_pin (struct vbox_bo *bo,u32 pl_flag) -{ -struct ttm_operation_ctx ctx = { false, false }; -int i, ret; - -if (bo->pin_count) { - bo->pin_count++; -return 0 ; - } - - ret =vbox_bo_reserve (bo, false); -if (ret) -return ret; - -vbox_ttm_placement (bo, pl_flag); - -for (i =0 ; i < bo->placement.num_placement; i++) - bo->placements[i].flags |=TTM_PL_FLAG_NO_EVICT ; - - ret =ttm_bo_validate (&bo->bo, &bo->placement, &ctx); -if (ret ==0 ) - bo->pin_count =1 ; - -vbox_bo_unreserve (bo); - -return ret; -} - -int vbox_bo_unpin (struct vbox_bo *bo) -{ -struct ttm_operation_ctx ctx = { false, false }; -int i, ret; - -if (!bo->pin_count) { -DRM_ERROR ("unpin bad %p\n" , bo); -return 0 ; - } - bo->pin_count--; -if (bo->pin_count) -return 0 ; - - ret =vbox_bo_reserve (bo, false); -if (ret) { -DRM_ERROR ("Error %d reserving bo, leaving it pinned\n" , ret); -return ret; - } - -for (i =0 ; i < bo->placement.num_placement; i++) - bo->placements[i].flags &= ~TTM_PL_FLAG_NO_EVICT ; - - ret =ttm_bo_validate (&bo->bo, &bo->placement, &ctx); - -vbox_bo_unreserve (bo); - -return ret; -} - -/* -* Move a vbox-owned buffer object to system memory if no one else has it -* pinned. The caller must have pinned it previously, and this call will -* release the caller's pin. -*/ -int vbox_bo_push_sysram (struct vbox_bo *bo) -{ -struct ttm_operation_ctx ctx = { false, false }; -int i, ret; - -if (!bo->pin_count) { -DRM_ERROR ("unpin bad %p\n" , bo); -return 0 ; - } - bo->pin_count--; -if (bo->pin_count) -return 0 ; - -if (bo->kmap.virtual) { -ttm_bo_kunmap (&bo->kmap); - bo->kmap.virtual =NULL ; - } - -vbox_ttm_placement (bo,TTM_PL_FLAG_SYSTEM ); - -for (i =0 ; i < bo->placement.num_placement; i++) - bo->placements[i].flags |=TTM_PL_FLAG_NO_EVICT ; - - ret =ttm_bo_validate (&bo->bo, &bo->placement, &ctx); -if (ret) { -DRM_ERROR ("pushing to VRAM failed\n" ); -return ret; - } - -return 0 ; -} -int vbox_mmap (struct file *filp,struct vm_area_struct *vma) {struct drm_file *file_priv = filp->private_data;@@ -362,27 +167,3 @@ int vbox_mmap(struct file *filp, struct vm_area_struct *vma)return ttm_bo_mmap (filp, vma, &vbox->ttm.bdev); } - -void *vbox_bo_kmap (struct vbox_bo *bo) -{ -int ret; - -if (bo->kmap.virtual) -return bo->kmap.virtual; - - ret =ttm_bo_kmap (&bo->bo,0 , bo->bo.num_pages, &bo->kmap); -if (ret) { -DRM_ERROR ("Error kmapping bo: %d\n" , ret); -return NULL ; - } -
drivers/gpu/drm/vboxvideo/vbox_ttm.c int vbox_mmap(struct file *filp, struct vm_area_struct *vma) · line 388
Quoted 10 lines
drivers/gpu/drm/vboxvideo/vbox_ttm.c +0
-10-return bo->kmap.virtual; -} - -void vbox_bo_kunmap (struct vbox_bo *bo) -{ -if (bo->kmap.virtual) { -ttm_bo_kunmap (&bo->kmap); - bo->kmap.virtual =NULL ; - } -}
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Re: [PATCH 13/15] drm/vboxvideo: Convert vboxvideo driver to Simple TTM
In reply to Thomas ZimmermannHi,
Quoted 1 line · Thomas Zimmermann
Signed-off-by Thomas Zimmermann <[email protected]>
Patch looks good to me (although perhaps it needs a commit msg):
Regards,
Hans
Quoted 203 lines
--- drivers/gpu/drm/vboxvideo/Kconfig | 1 + drivers/gpu/drm/vboxvideo/vbox_drv.h | 6 +- drivers/gpu/drm/vboxvideo/vbox_ttm.c | 123 ++------------------------- 3 files changed, 12 insertions(+), 118 deletions(-)drivers/gpu/drm/vboxvideo/Kconfig +1
-0@@ -4,6 +4,7 @@ config DRM_VBOXVIDEO select DRM_KMS_HELPER select DRM_TTM select DRM_GEM_TTM_HELPER + select DRM_SIMPLE_TTM_HELPER select GENERIC_ALLOCATOR help This is a KMS driver for the virtual Graphics Card used indrivers/gpu/drm/vboxvideo/vbox_drv.h +3
-3@@ -20,6 +20,8 @@#include <drm/drm_gem.h> #include <drm/drm_gem_ttm_helper.h> +#include <drm/drm_simple_ttm_helper.h> +#include <drm/ttm/ttm_bo_api.h> #include <drm/ttm/ttm_bo_driver.h> #include <drm/ttm/ttm_placement.h> @@ -78,9 +80,7 @@ struct vbox_private {int fb_mtrr; -struct { -struct ttm_bo_device bdev; - } ttm; +struct drm_simple_ttm ttm;struct mutex hw_mutex;/* protects modeset and accel/vbva accesses */ struct work_struct hotplug_work;drivers/gpu/drm/vboxvideo/vbox_ttm.c +8
-115@@ -11,128 +11,25 @@#include <drm/ttm/ttm_page_alloc.h> #include "vbox_drv.h" -static inline struct vbox_private *vbox_bdev (struct ttm_bo_device *bd) -{ - return container_of(bd, struct vbox_private, ttm.bdev); -} - -static int -vbox_bo_init_mem_type (struct ttm_bo_device *bdev,u32 type, -struct ttm_mem_type_manager *man) -{ -switch (type) { -case TTM_PL_SYSTEM : - man->flags =TTM_MEMTYPE_FLAG_MAPPABLE ; - man->available_caching =TTM_PL_MASK_CACHING ; - man->default_caching =TTM_PL_FLAG_CACHED ; -break ; -case TTM_PL_VRAM : - man->func = &ttm_bo_manager_func; - man->flags =TTM_MEMTYPE_FLAG_FIXED |TTM_MEMTYPE_FLAG_MAPPABLE ; - man->available_caching =TTM_PL_FLAG_UNCACHED |TTM_PL_FLAG_WC ; - man->default_caching =TTM_PL_FLAG_WC ; -break ; -default : -DRM_ERROR ("Unsupported memory type %u\n" , (unsigned int )type); -return -EINVAL ; - } - -return 0 ; -} - -static int vbox_ttm_io_mem_reserve (struct ttm_bo_device *bdev, -struct ttm_mem_reg *mem) -{ -struct ttm_mem_type_manager *man = &bdev->man[mem->mem_type]; -struct vbox_private *vbox =vbox_bdev (bdev); - - mem->bus.addr =NULL ; - mem->bus.offset =0 ; - mem->bus.size = mem->num_pages <<PAGE_SHIFT ; - mem->bus.base =0 ; - mem->bus.is_iomem = false; -if (!(man->flags &TTM_MEMTYPE_FLAG_MAPPABLE )) -return -EINVAL ; -switch (mem->mem_type) { -case TTM_PL_SYSTEM : -/* system memory */ -return 0 ; -case TTM_PL_VRAM : - mem->bus.offset = mem->start <<PAGE_SHIFT ; - mem->bus.base =pci_resource_start (vbox->ddev.pdev,0 ); - mem->bus.is_iomem = true; -break ; -default : -return -EINVAL ; - } -return 0 ; -} - -static void vbox_ttm_io_mem_free (struct ttm_bo_device *bdev, -struct ttm_mem_reg *mem) -{ -} - -static void vbox_ttm_backend_destroy (struct ttm_tt *tt) -{ -ttm_tt_fini (tt); -kfree (tt); -} - -static struct ttm_backend_func vbox_tt_backend_func = { - .destroy = &vbox_ttm_backend_destroy, -}; - -static struct ttm_tt *vbox_ttm_tt_create (struct ttm_buffer_object *bo, -u32 page_flags) -{ -struct ttm_tt *tt; - - tt =kzalloc (sizeof (*tt),GFP_KERNEL ); -if (!tt) -return NULL ; - - tt->func = &vbox_tt_backend_func; -if (ttm_tt_init (tt, bo, page_flags)) { -kfree (tt); -return NULL ; - } - -return tt; -} - -static struct ttm_bo_driver vbox_bo_driver = { - .ttm_tt_create = vbox_ttm_tt_create, - .init_mem_type = vbox_bo_init_mem_type, - .eviction_valuable = ttm_bo_eviction_valuable, +static const struct drm_simple_ttm_funcs vbox_simple_ttm_funcs = { .evict_flags = drm_gem_ttm_bo_driver_evict_flags, - .verify_access = drm_gem_ttm_bo_driver_verify_access, - .io_mem_reserve = &vbox_ttm_io_mem_reserve, - .io_mem_free = &vbox_ttm_io_mem_free, + .verify_access = drm_gem_ttm_bo_driver_verify_access };int vbox_mm_init (struct vbox_private *vbox) {int ret;struct drm_device *dev = &vbox->ddev; -struct ttm_bo_device *bdev = &vbox->ttm.bdev; - ret =ttm_bo_device_init (&vbox->ttm.bdev, - &vbox_bo_driver, - dev->anon_inode->i_mapping, - true); + ret =drm_simple_ttm_init (&vbox->ttm, dev, +pci_resource_start (dev->pdev,0 ), + vbox->available_vram_size, + &vbox_simple_ttm_funcs);if (ret) { -DRM_ERROR ("Error initialising bo driver; %d\n" , ret); +DRM_ERROR ("Error initializing Simple TTM; %d\n" , ret);return ret; } - ret =ttm_bo_init_mm (bdev,TTM_PL_VRAM , - vbox->available_vram_size >>PAGE_SHIFT ); -if (ret) { -DRM_ERROR ("Failed ttm VRAM init: %d\n" , ret); - goto err_device_release; - } -#ifdef DRM_MTRR_WC vbox->fb_mtrr = drm_mtrr_add(pci_resource_start(dev->pdev, 0), pci_resource_len(dev->pdev, 0),@@ -142,10 +39,6 @@ int vbox_mm_init(struct vbox_private *vbox) pci_resource_len(dev->pdev, 0));#endif return 0 ; - -err_device_release: -ttm_bo_device_release (&vbox->ttm.bdev); -return ret; }void vbox_mm_fini (struct vbox_private *vbox)@@ -157,7 +50,7 @@ void vbox_mm_fini(struct vbox_private *vbox)#else arch_phys_wc_del (vbox->fb_mtrr);#endif -ttm_bo_device_release (&vbox->ttm.bdev); +drm_simple_ttm_cleanup (&vbox->ttm); }int vbox_mmap (struct file *filp,struct vm_area_struct *vma)
Re: [PATCH 13/15] drm/vboxvideo: Convert vboxvideo driver to Simple TTM
In reply to Thomas ZimmermannHi,
Quoted 1 line · Thomas Zimmermann
Signed-off-by Thomas Zimmermann <[email protected]>
Patch looks good to me (although perhaps it needs a commit msg):
Regards,
Hans
Quoted 195 lines
--- drivers/gpu/drm/vboxvideo/Kconfig | 1 + drivers/gpu/drm/vboxvideo/vbox_drv.h | 6 +- drivers/gpu/drm/vboxvideo/vbox_ttm.c | 123 ++------------------------- 3 files changed, 12 insertions(+), 118 deletions(-)drivers/gpu/drm/vboxvideo/Kconfig +1
-0@@ -4,6 +4,7 @@ config DRM_VBOXVIDEO select DRM_KMS_HELPER select DRM_TTM select DRM_GEM_TTM_HELPER + select DRM_SIMPLE_TTM_HELPER select GENERIC_ALLOCATOR help This is a KMS driver for the virtual Graphics Card used indrivers/gpu/drm/vboxvideo/vbox_drv.h +3
-3@@ -20,6 +20,8 @@#include <drm/drm_gem.h> #include <drm/drm_gem_ttm_helper.h> +#include <drm/drm_simple_ttm_helper.h> +#include <drm/ttm/ttm_bo_api.h> #include <drm/ttm/ttm_bo_driver.h> #include <drm/ttm/ttm_placement.h> @@ -78,9 +80,7 @@ struct vbox_private {int fb_mtrr; -struct { -struct ttm_bo_device bdev; - } ttm; +struct drm_simple_ttm ttm;struct mutex hw_mutex;/* protects modeset and accel/vbva accesses */ struct work_struct hotplug_work;drivers/gpu/drm/vboxvideo/vbox_ttm.c +7
-114@@ -11,128 +11,25 @@#include <drm/ttm/ttm_page_alloc.h> #include "vbox_drv.h" -static inline struct vbox_private *vbox_bdev (struct ttm_bo_device *bd) -{ - return container_of(bd, struct vbox_private, ttm.bdev); -} - -static int -vbox_bo_init_mem_type (struct ttm_bo_device *bdev,u32 type, -struct ttm_mem_type_manager *man) -{ -switch (type) { -case TTM_PL_SYSTEM : - man->flags =TTM_MEMTYPE_FLAG_MAPPABLE ; - man->available_caching =TTM_PL_MASK_CACHING ; - man->default_caching =TTM_PL_FLAG_CACHED ; -break ; -case TTM_PL_VRAM : - man->func = &ttm_bo_manager_func; - man->flags =TTM_MEMTYPE_FLAG_FIXED |TTM_MEMTYPE_FLAG_MAPPABLE ; - man->available_caching =TTM_PL_FLAG_UNCACHED |TTM_PL_FLAG_WC ; - man->default_caching =TTM_PL_FLAG_WC ; -break ; -default : -DRM_ERROR ("Unsupported memory type %u\n" , (unsigned int )type); -return -EINVAL ; - } - -return 0 ; -} - -static int vbox_ttm_io_mem_reserve (struct ttm_bo_device *bdev, -struct ttm_mem_reg *mem) -{ -struct ttm_mem_type_manager *man = &bdev->man[mem->mem_type]; -struct vbox_private *vbox =vbox_bdev (bdev); - - mem->bus.addr =NULL ; - mem->bus.offset =0 ; - mem->bus.size = mem->num_pages <<PAGE_SHIFT ; - mem->bus.base =0 ; - mem->bus.is_iomem = false; -if (!(man->flags &TTM_MEMTYPE_FLAG_MAPPABLE )) -return -EINVAL ; -switch (mem->mem_type) { -case TTM_PL_SYSTEM : -/* system memory */ -return 0 ; -case TTM_PL_VRAM : - mem->bus.offset = mem->start <<PAGE_SHIFT ; - mem->bus.base =pci_resource_start (vbox->ddev.pdev,0 ); - mem->bus.is_iomem = true; -break ; -default : -return -EINVAL ; - } -return 0 ; -} - -static void vbox_ttm_io_mem_free (struct ttm_bo_device *bdev, -struct ttm_mem_reg *mem) -{ -} - -static void vbox_ttm_backend_destroy (struct ttm_tt *tt) -{ -ttm_tt_fini (tt); -kfree (tt); -} - -static struct ttm_backend_func vbox_tt_backend_func = { - .destroy = &vbox_ttm_backend_destroy, -}; - -static struct ttm_tt *vbox_ttm_tt_create (struct ttm_buffer_object *bo, -u32 page_flags) -{ -struct ttm_tt *tt; - - tt =kzalloc (sizeof (*tt),GFP_KERNEL ); -if (!tt) -return NULL ; - - tt->func = &vbox_tt_backend_func; -if (ttm_tt_init (tt, bo, page_flags)) { -kfree (tt); -return NULL ; - } - -return tt; -} - -static struct ttm_bo_driver vbox_bo_driver = { - .ttm_tt_create = vbox_ttm_tt_create, - .init_mem_type = vbox_bo_init_mem_type, - .eviction_valuable = ttm_bo_eviction_valuable, +static const struct drm_simple_ttm_funcs vbox_simple_ttm_funcs = { .evict_flags = drm_gem_ttm_bo_driver_evict_flags, - .verify_access = drm_gem_ttm_bo_driver_verify_access, - .io_mem_reserve = &vbox_ttm_io_mem_reserve, - .io_mem_free = &vbox_ttm_io_mem_free, + .verify_access = drm_gem_ttm_bo_driver_verify_access };int vbox_mm_init (struct vbox_private *vbox) {int ret;struct drm_device *dev = &vbox->ddev; -struct ttm_bo_device *bdev = &vbox->ttm.bdev; - ret =ttm_bo_device_init (&vbox->ttm.bdev, - &vbox_bo_driver, - dev->anon_inode->i_mapping, - true); + ret =drm_simple_ttm_init (&vbox->ttm, dev, +pci_resource_start (dev->pdev,0 ), + vbox->available_vram_size, + &vbox_simple_ttm_funcs);if (ret) { -DRM_ERROR ("Error initialising bo driver; %d\n" , ret); +DRM_ERROR ("Error initializing Simple TTM; %d\n" , ret);return ret; } - ret =ttm_bo_init_mm (bdev,TTM_PL_VRAM , - vbox->available_vram_size >>PAGE_SHIFT ); -if (ret) { -DRM_ERROR ("Failed ttm VRAM init: %d\n" , ret); - goto err_device_release; - } -#ifdef DRM_MTRR_WC vbox->fb_mtrr = drm_mtrr_add(pci_resource_start(dev->pdev, 0), pci_resource_len(dev->pdev, 0),@@ -142,10 +39,6 @@ int vbox_mm_init(struct vbox_private *vbox) pci_resource_len(dev->pdev, 0));#endif return 0 ; - -err_device_release: -ttm_bo_device_release (&vbox->ttm.bdev); -return ret; }void vbox_mm_fini (struct vbox_private *vbox)
drivers/gpu/drm/vboxvideo/vbox_ttm.c void vbox_mm_fini(struct vbox_private *vbox) · line 56
Quoted 8 lines
drivers/gpu/drm/vboxvideo/vbox_ttm.c +1
-1@@ -157,7 +50,7 @@ void vbox_mm_fini(struct vbox_private *vbox)#else arch_phys_wc_del (vbox->fb_mtrr);#endif -ttm_bo_device_release (&vbox->ttm.bdev); +drm_simple_ttm_cleanup (&vbox->ttm); }int vbox_mmap (struct file *filp,struct vm_area_struct *vma)
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Hi,
Quoted 2 lines
If not for TTM, what would be the alternative? One VMA manager per memory region per device?
Depends pretty much on the device.
The cirrus is a display device with only 4 MB of vram. You can't fit much in there. A single 1024x768 @ 24bpp framebuffer needs more 50% of the video memory already. Which is why the cirrus driver (before the rewrite) had to migrate buffers from/to vram on every page flip[1]. Which is one[2] of the reasons why cirrus (after rewrite) doesn't ttm-manage the vram any more. gem objects are managed with the shmem helpers instead and the active framebuffer is blitted to vram.
The qemu stdvga (bochs driver) has 16 MB vram by default and can be configured to have up to 256 MB. Plenty of room even for multiple 4k framebuffers if needed. So for the bochs driver all the ttm bo migration logic is not needed, it could just store everything in vram.
A set of drm_gem_vram_* helpers would do the job for bochs.
I'd expect the same applies to the vbox driver.
Dunno about the other drm drivers and the fbdev drivers you plan to migrate over.
cheers,
Gerd
[1] Note: The page-flip migration logic is present in some of the other drivers too, not sure whenever they actually need that due to being low on vram too or whenever they just copied the old cirrus code ...
[2] The other reason is that this allow to convert formats at blit time, which helps to deal with some cirrus hardware limitations.
Hi,
Quoted 2 lines
If not for TTM, what would be the alternative? One VMA manager per memory region per device?
Depends pretty much on the device.
The cirrus is a display device with only 4 MB of vram. You can't fit much in there. A single 1024x768 @ 24bpp framebuffer needs more 50% of the video memory already. Which is why the cirrus driver (before the rewrite) had to migrate buffers from/to vram on every page flip[1]. Which is one[2] of the reasons why cirrus (after rewrite) doesn't ttm-manage the vram any more. gem objects are managed with the shmem helpers instead and the active framebuffer is blitted to vram.
The qemu stdvga (bochs driver) has 16 MB vram by default and can be configured to have up to 256 MB. Plenty of room even for multiple 4k framebuffers if needed. So for the bochs driver all the ttm bo migration logic is not needed, it could just store everything in vram.
A set of drm_gem_vram_* helpers would do the job for bochs.
I'd expect the same applies to the vbox driver.
Dunno about the other drm drivers and the fbdev drivers you plan to migrate over.
cheers,
Gerd
[1] Note: The page-flip migration logic is present in some of the other drivers too, not sure whenever they actually need that due to being low on vram too or whenever they just copied the old cirrus code ...
[2] The other reason is that this allow to convert formats at blit time, which helps to deal with some cirrus hardware limitations.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Thomas Zimmermann
maintainerRe: [PATCH 13/15] drm/vboxvideo: Convert vboxvideo driver to Simple TTM
In reply to Hans de GoedeHi
Am 09.04.19 um 09:09 schrieb Hans de Goede:
Quoted 6 lines
Hi,
Quoted 1 line · Thomas Zimmermann
Signed-off-by Thomas Zimmermann <[email protected]>Patch looks good to me (although perhaps it needs a commit msg):
OK, thanks. I'll add that message here and to the other patches.
Best regards
Thomas
Quoted 210 lines
Reviewed-by Hans de Goede <[email protected]>Regards,
Hans
Quoted 189 lines
---
drivers/gpu/drm/vboxvideo/Kconfig | 1 +drivers/gpu/drm/vboxvideo/vbox_drv.h| 6 +-drivers/gpu/drm/vboxvideo/vbox_ttm.c| 123 ++-------------------------3 files changed, 12 insertions(+), 118 deletions(-)drivers/gpu/drm/vboxvideo/Kconfig +0
-0@@ -4,6 +4,7 @@ config DRM_VBOXVIDEOselect
DRM_KMS_HELPER
selectDRM_TTM
selectDRM_GEM_TTM_HELPER
+ selectDRM_SIMPLE_TTM_HELPER
selectGENERIC_ALLOCATOR
help
This is a KMS driver for the virtual Graphics Card used indrivers/gpu/drm/vboxvideo/vbox_drv.h +0
-0@@ -20,6 +20,8 @@ #include <drm/drm_gem.h> #include <drm/drm_gem_ttm_helper.h>+#include <
drm/drm_simple_ttm_helper.h>
+
#include <drm/ttm/ttm_bo_api.h>
#include <drm/ttm/ttm_bo_driver.h>
#include <drm/ttm/ttm_placement.h>drivers/gpu/drm/vboxvideo/vbox_drv.h +1
-2@@ -78,9 +80,7 @@ struct vbox_private { int fb_mtrr; - struct { - struct ttm_bo_device bdev; - } ttm; + struct drm_simple_ttm ttm;struct mutex
hw_mutex; /* protects modeset and accel/vbva accesses */
structwork_structhotplug_work;drivers/gpu/drm/vboxvideo/vbox_ttm.c +7
-111@@ -11,128 +11,25 @@ #include <drm/ttm/ttm_page_alloc.h> #include "vbox_drv.h" -static inline struct vbox_private *vbox_bdev(struct ttm_bo_device *bd) -{ - return container_of(bd, struct vbox_private, ttm.bdev); -} - -static int -vbox_bo_init_mem_type (struct ttm_bo_device *bdev,u32 type, - struct ttm_mem_type_manager *man) -{ - switch (type) { - case TTM_PL_SYSTEM: - man->flags = TTM_MEMTYPE_FLAG_MAPPABLE; - man->available_caching = TTM_PL_MASK_CACHING; - man->default_caching = TTM_PL_FLAG_CACHED; - break; - case TTM_PL_VRAM: - man->func = &ttm_bo_manager_func; - man->flags = TTM_MEMTYPE_FLAG_FIXED | TTM_MEMTYPE_FLAG_MAPPABLE; - man->available_caching = TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_WC; - man->default_caching = TTM_PL_FLAG_WC; - break; - default: - DRM_ERROR("Unsupported memory type %u\n", (unsigned int)type); - return -EINVAL; - } - - return 0; -} - -static int vbox_ttm_io_mem_reserve (struct ttm_bo_device *bdev, - struct ttm_mem_reg *mem) -{ - struct ttm_mem_type_manager *man = &bdev->man[mem->mem_type]; - struct vbox_private *vbox = vbox_bdev(bdev); - - mem->bus.addr = NULL; - mem->bus.offset = 0; - mem->bus.size = mem->num_pages << PAGE_SHIFT; - mem->bus.base = 0; - mem->bus.is_iomem = false; - if (!(man->flags & TTM_MEMTYPE_FLAG_MAPPABLE)) - return -EINVAL; - switch (mem->mem_type) { - case TTM_PL_SYSTEM: - /* system memory */ - return 0; - case TTM_PL_VRAM: - mem->bus.offset = mem->start << PAGE_SHIFT; - mem->bus.base = pci_resource_start(vbox->ddev.pdev, 0); - mem->bus.is_iomem = true; - break; - default: - return -EINVAL; - } - return 0; -} - -static void vbox_ttm_io_mem_free (struct ttm_bo_device *bdev, - struct ttm_mem_reg *mem) -{ -} - -static void vbox_ttm_backend_destroy (struct ttm_tt *tt) -{ - ttm_tt_fini(tt); - kfree(tt); -} - -static struct ttm_backend_func vbox_tt_backend_func = { - .destroy = &vbox_ttm_backend_destroy, -}; - -static struct ttm_tt *vbox_ttm_tt_create (struct ttm_buffer_object *bo, - u32 page_flags) -{ - struct ttm_tt *tt; - - tt = kzalloc(sizeof(*tt), GFP_KERNEL); - if (!tt) - return NULL; - - tt->func = &vbox_tt_backend_func; - if (ttm_tt_init(tt, bo, page_flags)) { - kfree(tt); - return NULL; - } - - return tt; -} - -static struct ttm_bo_driver vbox_bo_driver = { - .ttm_tt_create = vbox_ttm_tt_create, - .init_mem_type = vbox_bo_init_mem_type, - .eviction_valuable = ttm_bo_eviction_valuable, +static const struct drm_simple_ttm_funcs vbox_simple_ttm_funcs = { .evict_flags = drm_gem_ttm_bo_driver_evict_flags, - .verify_access = drm_gem_ttm_bo_driver_verify_access, - .io_mem_reserve = &vbox_ttm_io_mem_reserve, - .io_mem_free = &vbox_ttm_io_mem_free, + .verify_access = drm_gem_ttm_bo_driver_verify_access }; int vbox_mm_init(struct vbox_private *vbox) { int ret; struct drm_device *dev = &vbox->ddev; - struct ttm_bo_device *bdev = &vbox->ttm.bdev; - ret = ttm_bo_device_init(&vbox->ttm.bdev, - &vbox_bo_driver, - dev->anon_inode->i_mapping, - true); + ret = drm_simple_ttm_init(&vbox->ttm, dev, + pci_resource_start(dev->pdev, 0), + vbox->available_vram_size, + &vbox_simple_ttm_funcs); if (ret) { - DRM_ERROR("Error initialising bo driver; %d\n", ret); + DRM_ERROR("Error initializing Simple TTM; %d\n", ret); return ret; } - ret = ttm_bo_init_mm(bdev, TTM_PL_VRAM, - vbox->available_vram_size >> PAGE_SHIFT); - if (ret) { - DRM_ERROR("Failed ttm VRAM init: %d\n", ret); - goto err_device_release; - } - #ifdef DRM_MTRR_WC vbox->fb_mtrr = drm_mtrr_add(pci_resource_start(dev->pdev, 0), pci_resource_len(dev->pdev, 0),@@ -142,10 +39,6 @@ int vbox_mm_init(struct vbox_private *vbox) pci_resource_len(dev->pdev, 0)); #endif return 0; - -err_device_release: - ttm_bo_device_release(&vbox->ttm.bdev); - return ret; } void vbox_mm_fini(struct vbox_private *vbox)drivers/gpu/drm/vboxvideo/vbox_ttm.c void vbox_mm_fini(struct vbox_private *vbox) · line 56
Quoted 8 lines
drivers/gpu/drm/vboxvideo/vbox_ttm.c +1
-1@@ -157,7 +50,7 @@ void vbox_mm_fini(struct vbox_private *vbox) #else arch_phys_wc_del(vbox->fb_mtrr); #endif - ttm_bo_device_release(&vbox->ttm.bdev); + drm_simple_ttm_cleanup(&vbox->ttm); } int vbox_mmap(struct file *filp, struct vm_area_struct *vma)_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 5 lines
Thomas Zimmermann Graphics Driver Developer SUSE Linux GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany GF: Felix Imendörffer, Mary Higgins, Sri Rasiah HRB 21284 (AG Nürnberg)
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Dave Airlie
maintainerQuoted 16 lines · On Tue, 9 Apr 2019 at 17:12, [email protected] <[email protected]> wrote:
Hi,
Quoted 2 lines
If not for TTM, what would be the alternative? One VMA manager per memory region per device?
Depends pretty much on the device.
The cirrus is a display device with only 4 MB of vram. You can't fit much in there. A single 1024x768 @ 24bpp framebuffer needs more 50% of the video memory already. Which is why the cirrus driver (before the rewrite) had to migrate buffers from/to vram on every page flip[1]. Which is one[2] of the reasons why cirrus (after rewrite) doesn't ttm-manage the vram any more. gem objects are managed with the shmem helpers instead and the active framebuffer is blitted to vram.
Quoted 4 lines
The qemu stdvga (bochs driver) has 16 MB vram by default and can be configured to have up to 256 MB. Plenty of room even for multiple 4k framebuffers if needed. So for the bochs driver all the ttm bo migration logic is not needed, it could just store everything in vram.
To clarify I assume you mean it doesn't need the migrate each bo logic, but it still needs the when VRAM fills up migrate stuff logic.
Dave.
Thomas Zimmermann
maintainerHi
Am 09.04.19 um 09:12 schrieb [email protected]:
Quoted 15 lines
Hi,
Quoted 2 lines
If not for TTM, what would be the alternative? One VMA manager per memory region per device?
Depends pretty much on the device.
The cirrus is a display device with only 4 MB of vram. You can't fit much in there. A single 1024x768 @ 24bpp framebuffer needs more 50% of the video memory already. Which is why the cirrus driver (before the rewrite) had to migrate buffers from/to vram on every page flip[1]. Which is one[2] of the reasons why cirrus (after rewrite) doesn't ttm-manage the vram any more. gem objects are managed with the shmem helpers instead and the active framebuffer is blitted to vram.
Quoted 6 lines
The qemu stdvga (bochs driver) has 16 MB vram by default and can be configured to have up to 256 MB. Plenty of room even for multiple 4k framebuffers if needed. So for the bochs driver all the ttm bo migration logic is not needed, it could just store everything in vram.
A set of drm_gem_vram_* helpers would do the job for bochs.
Thanks for clarifying. drm_gem_vram_* (and drm_vram_mm for Simple TTM) is probably a better name for the data structures.
Quoted 4 lines
I'd expect the same applies to the vbox driver.
Dunno about the other drm drivers and the fbdev drivers you plan to migrate over.
The AST HW can support up to 512 MiB, but 32-64 MiB seems more realistic for a server. It's similar with mgag200 HW. The old fbdev-supported device are all somewhere in the range between cirrus and bochs. Some drivers would probably benefit from the cirrus approach, some could use VRAM directly.
Best regards
Thomas
Quoted 11 lines
cheers,
Gerd[1] Note: The page-flip migration logic is present in some of the other drivers too, not sure whenever they actually need that due to being low on vram too or whenever they just copied the old cirrus code ...
[2] The other reason is that this allow to convert formats at blit time, which helps to deal with some cirrus hardware limitations.
Signature · 5 lines
Thomas Zimmermann Graphics Driver Developer SUSE Linux GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany GF: Felix Imendörffer, Mary Higgins, Sri Rasiah HRB 21284 (AG Nürnberg)
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Hi,
Quoted 7 lines
Quoted 4 lines
The qemu stdvga (bochs driver) has 16 MB vram by default and can be configured to have up to 256 MB. Plenty of room even for multiple 4k framebuffers if needed. So for the bochs driver all the ttm bo migration logic is not needed, it could just store everything in vram.
To clarify I assume you mean it doesn't need the migrate each bo logic, but it still needs the when VRAM fills up migrate stuff logic.
I think even the "when vram fills up" logic isn't that important. The driver has no acceleration so there is nothing to store beside dumb framebuffers, and the vram size can easily be increased if needed.
cheers,
Gerd
Hi,
Quoted 7 lines
Quoted 4 lines
The qemu stdvga (bochs driver) has 16 MB vram by default and can be configured to have up to 256 MB. Plenty of room even for multiple 4k framebuffers if needed. So for the bochs driver all the ttm bo migration logic is not needed, it could just store everything in vram.
To clarify I assume you mean it doesn't need the migrate each bo logic, but it still needs the when VRAM fills up migrate stuff logic.
I think even the "when vram fills up" logic isn't that important. The driver has no acceleration so there is nothing to store beside dumb framebuffers, and the vram size can easily be increased if needed.
cheers,
Gerd
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Am 09.04.19 um 10:29 schrieb [email protected]:
Quoted 11 lines
Hi,Quoted 6 lines
Quoted 4 lines
The qemu stdvga (bochs driver) has 16 MB vram by default and can be configured to have up to 256 MB. Plenty of room even for multiple 4k framebuffers if needed. So for the bochs driver all the ttm bo migration logic is not needed, it could just store everything in vram.
To clarify I assume you mean it doesn't need the migrate each bo logic, but it still needs the when VRAM fills up migrate stuff logic.
I think even the "when vram fills up" logic isn't that important. The driver has no acceleration so there is nothing to store beside dumb framebuffers, and the vram size can easily be increased if needed.
Yeah, cause in this particular case it is not even real VRAM.
In this case VRAM is backed by system memory which in turn is stolen from the host system isn't it?
So just have enough for a framebuffer and don't place anything else in there.
Regards,
Christian.
Quoted 8 lines
cheers,
Gerd_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Am 08.04.19 um 13:59 schrieb Thomas Zimmermann:
[SNIP]
Quoted 2 lines
If not for TTM, what would be the alternative? One VMA manager per memory region per device?
Since everybody vital seems to be on this mail thread anyway, let's use it a bit for brain storming what a possible replacement for TTM should look like.
Well for simple drivers like qemu/bochs and cirrus the answer is to not use it at all. E.g. VRAM is only used for scanout and unprivileged userspace should not mess with it at all. In this case we don't need dynamic eviction and so also don't need TTM.
That leaves us with the more complex drivers, like radeon, amdgpu, nouveu and maybe some of the ARM based stuff, with vmwgfx being a bit special here.
Now I can summarize the requirements for at least the amdgpu in the following way:
1. We need to be able to allocate memory objects in different locations.
2. We need to be able to move around memory objects between different locations.
3. We need some LRU component which tells us what to evict when memory in a location becomes to tight.
Now for lessons learned we should at least avoid the following design pitfalls:
A) DON'T make it a layered design! Layers are for making cake, not software.
B) DON'T make it a "Eierlegende Wollmilchsau" (German saying). E.g. don't try to solve every single corner cases in one piece of software. Let's make components which solve one specific problem.
C) Pipeline everything! E.g. the hardware we deal with is asynchronous by design. Blocking for the hardware to finish in the common components itself is an absolutely no-go.
If a driver wants to do something synchronous it should wait itself.
Those comments where not really intended for you Thomas, but I had to write them down somewhere :)
Regards,
Christian.
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Quoted 23 lines · Thomas Zimmermann
Hi
Am 09.04.19 um 09:12 schrieb [email protected]:
Quoted 20 lines
Hi,
Quoted 2 lines
If not for TTM, what would be the alternative? One VMA manager per memory region per device?
Depends pretty much on the device.
The cirrus is a display device with only 4 MB of vram. You can't fit much in there. A single 1024x768 @ 24bpp framebuffer needs more 50% of the video memory already. Which is why the cirrus driver (before the rewrite) had to migrate buffers from/to vram on every page flip[1]. Which is one[2] of the reasons why cirrus (after rewrite) doesn't ttm-manage the vram any more. gem objects are managed with the shmem helpers instead and the active framebuffer is blitted to vram.
The qemu stdvga (bochs driver) has 16 MB vram by default and can be configured to have up to 256 MB. Plenty of room even for multiple 4k framebuffers if needed. So for the bochs driver all the ttm bo migration logic is not needed, it could just store everything in vram.
Quoted 4 lines
Quoted 1 line
A set of drm_gem_vram_* helpers would do the job for bochs.
Thanks for clarifying. drm_gem_vram_* (and
drm_vram_mmfor Simple TTM) is probably a better name for the data structures.
+1 on drm_gem_vram_* naming convention - we want to describe what it's for, not how it's implemented.
Quoted 10 lines
Quoted 4 lines
I'd expect the same applies to the vbox driver.
Dunno about the other drm drivers and the fbdev drivers you plan to migrate over.
The AST HW can support up to 512 MiB, but 32-64 MiB seems more realistic for a server. It's similar with mgag200 HW. The old fbdev-supported device are all somewhere in the range between cirrus and bochs. Some drivers would probably benefit from the cirrus approach, some could use VRAM directly.
I think for dumb scanout with vram all we need is:
- pin framebuffers, which potentially moves the underlying bo into vram
- unpin framebuffers (which is just accounting, we don't want to move the bo on every flip!)
- if a pin doesn't find enough space, move one of the unpinned bo still resident in vram out
- no pipelining, no support for dma engines (it's all cpu copies anway)
- a simple drm_mm should be good enough to manage the vram, no need for the ttm style abstraction over how memory is manged
- also just bake in the lru eviction list and algorithm
- probably good to have built-in support for redirecting the mmap between shmem and iomem.
- anything that needs pipelining or copy engines would be out of scope for these helpers
I think for starting points we can go with a copypasted version of the various ttm implementations we already have, and then simplify from there as needed. Or just start fresh if that's too complicated, due to the issue Christian highlighted.
-Daniel
Quoted 22 lines
Best regards
ThomasQuoted 11 lines
cheers,
Gerd[1] Note: The page-flip migration logic is present in some of the other drivers too, not sure whenever they actually need that due to being low on vram too or whenever they just copied the old cirrus code ...
[2] The other reason is that this allow to convert formats at blit time, which helps to deal with some cirrus hardware limitations.
Signature · 5 lines
Thomas Zimmermann Graphics Driver Developer SUSE Linux GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany GF: Felix Imendörffer, Mary Higgins, Sri Rasiah HRB 21284 (AG Nürnberg)
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Quoted 43 lines · Daniel Vetter
Quoted 23 lines · Thomas Zimmermann
Hi
Am 09.04.19 um 09:12 schrieb [email protected]:
Quoted 20 lines
Hi,
Quoted 2 lines
If not for TTM, what would be the alternative? One VMA manager per memory region per device?
Depends pretty much on the device.
The cirrus is a display device with only 4 MB of vram. You can't fit much in there. A single 1024x768 @ 24bpp framebuffer needs more 50% of the video memory already. Which is why the cirrus driver (before the rewrite) had to migrate buffers from/to vram on every page flip[1]. Which is one[2] of the reasons why cirrus (after rewrite) doesn't ttm-manage the vram any more. gem objects are managed with the shmem helpers instead and the active framebuffer is blitted to vram.
The qemu stdvga (bochs driver) has 16 MB vram by default and can be configured to have up to 256 MB. Plenty of room even for multiple 4k framebuffers if needed. So for the bochs driver all the ttm bo migration logic is not needed, it could just store everything in vram.
Quoted 4 lines
Quoted 1 line
A set of drm_gem_vram_* helpers would do the job for bochs.
Thanks for clarifying. drm_gem_vram_* (and
drm_vram_mmfor Simple TTM) is probably a better name for the data structures.+1 on drm_gem_vram_* naming convention - we want to describe what it's for, not how it's implemented.
Quoted 10 lines
Quoted 4 lines
I'd expect the same applies to the vbox driver.
Dunno about the other drm drivers and the fbdev drivers you plan to migrate over.
The AST HW can support up to 512 MiB, but 32-64 MiB seems more realistic for a server. It's similar with mgag200 HW. The old fbdev-supported device are all somewhere in the range between cirrus and bochs. Some drivers would probably benefit from the cirrus approach, some could use VRAM directly.
Quoted 14 lines
I think for dumb scanout with vram all we need is:
- pin framebuffers, which potentially moves the underlying bo into vram
- unpin framebuffers (which is just accounting, we don't want to move the bo on every flip!)
- if a pin doesn't find enough space, move one of the unpinned bo still resident in vram out
- no pipelining, no support for dma engines (it's all cpu copies anway)
- a simpledrm_mmshould be good enough to manage the vram, no need for the ttm style abstraction over how memory is manged
- also just bake in the lru eviction list and algorithm
- probably good to have built-in support for redirecting the mmap between shmem and iomem.
- anything that needs pipelining or copy engines would be out of scope for these helpers
One more:
- Only bother supporting hw that needs contiguous scanout buffers in VRAM. I think hw that has pagetables for scanout (and everything else really) is sufficiently different that cramming them into the same helpers doesn't make much sense: You want to manage your VRAM with a buddy allocator at a page level, plus you need to manage your pagetables, and all is likely very hw specific anyway. Plus I haven't seen such hw that doesn't come with a real gpu attached :-)
-Daniel
Quoted 37 lines
I think for starting points we can go with a copypasted version of the various ttm implementations we already have, and then simplify from there as needed. Or just start fresh if that's too complicated, due to the issue Christian highlighted.
-DanielQuoted 22 lines
Best regards
ThomasQuoted 11 lines
cheers,
Gerd[1] Note: The page-flip migration logic is present in some of the other drivers too, not sure whenever they actually need that due to being low on vram too or whenever they just copied the old cirrus code ...
[2] The other reason is that this allow to convert formats at blit time, which helps to deal with some cirrus hardware limitations.
Signature · 5 lines
Thomas Zimmermann Graphics Driver Developer SUSE Linux GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany GF: Felix Imendörffer, Mary Higgins, Sri Rasiah HRB 21284 (AG Nürnberg)Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Quoted 43 lines · Daniel Vetter
Quoted 23 lines · Thomas Zimmermann
Hi
Am 09.04.19 um 09:12 schrieb [email protected]:
Quoted 20 lines
Hi,
Quoted 2 lines
If not for TTM, what would be the alternative? One VMA manager per memory region per device?
Depends pretty much on the device.
The cirrus is a display device with only 4 MB of vram. You can't fit much in there. A single 1024x768 @ 24bpp framebuffer needs more 50% of the video memory already. Which is why the cirrus driver (before the rewrite) had to migrate buffers from/to vram on every page flip[1]. Which is one[2] of the reasons why cirrus (after rewrite) doesn't ttm-manage the vram any more. gem objects are managed with the shmem helpers instead and the active framebuffer is blitted to vram.
The qemu stdvga (bochs driver) has 16 MB vram by default and can be configured to have up to 256 MB. Plenty of room even for multiple 4k framebuffers if needed. So for the bochs driver all the ttm bo migration logic is not needed, it could just store everything in vram.
Quoted 4 lines
Quoted 1 line
A set of drm_gem_vram_* helpers would do the job for bochs.
Thanks for clarifying. drm_gem_vram_* (and
drm_vram_mmfor Simple TTM) is probably a better name for the data structures.+1 on drm_gem_vram_* naming convention - we want to describe what it's for, not how it's implemented.
Quoted 10 lines
Quoted 4 lines
I'd expect the same applies to the vbox driver.
Dunno about the other drm drivers and the fbdev drivers you plan to migrate over.
The AST HW can support up to 512 MiB, but 32-64 MiB seems more realistic for a server. It's similar with mgag200 HW. The old fbdev-supported device are all somewhere in the range between cirrus and bochs. Some drivers would probably benefit from the cirrus approach, some could use VRAM directly.
Quoted 14 lines
I think for dumb scanout with vram all we need is:
- pin framebuffers, which potentially moves the underlying bo into vram
- unpin framebuffers (which is just accounting, we don't want to move the bo on every flip!)
- if a pin doesn't find enough space, move one of the unpinned bo still resident in vram out
- no pipelining, no support for dma engines (it's all cpu copies anway)
- a simpledrm_mmshould be good enough to manage the vram, no need for the ttm style abstraction over how memory is manged
- also just bake in the lru eviction list and algorithm
- probably good to have built-in support for redirecting the mmap between shmem and iomem.
- anything that needs pipelining or copy engines would be out of scope for these helpers
One more:
- Only bother supporting hw that needs contiguous scanout buffers in VRAM. I think hw that has pagetables for scanout (and everything else really) is sufficiently different that cramming them into the same helpers doesn't make much sense: You want to manage your VRAM with a buddy allocator at a page level, plus you need to manage your pagetables, and all is likely very hw specific anyway. Plus I haven't seen such hw that doesn't come with a real gpu attached :-)
-Daniel
Quoted 37 lines
I think for starting points we can go with a copypasted version of the various ttm implementations we already have, and then simplify from there as needed. Or just start fresh if that's too complicated, due to the issue Christian highlighted.
-DanielQuoted 22 lines
Best regards
ThomasQuoted 11 lines
cheers,
Gerd[1] Note: The page-flip migration logic is present in some of the other drivers too, not sure whenever they actually need that due to being low on vram too or whenever they just copied the old cirrus code ...
[2] The other reason is that this allow to convert formats at blit time, which helps to deal with some cirrus hardware limitations.
Signature · 5 lines
Thomas Zimmermann Graphics Driver Developer SUSE Linux GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany GF: Felix Imendörffer, Mary Higgins, Sri Rasiah HRB 21284 (AG Nürnberg)Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Thomas Zimmermann
maintainerHi
Am 15.04.19 um 17:54 schrieb Daniel Vetter:
Quoted 24 lines · Thomas Zimmermann
Quoted 23 lines
Hi
Am 09.04.19 um 09:12 schrieb [email protected]:
Quoted 20 lines
Hi,
Quoted 2 lines
If not for TTM, what would be the alternative? One VMA manager per memory region per device?
Depends pretty much on the device.
The cirrus is a display device with only 4 MB of vram. You can't fit much in there. A single 1024x768 @ 24bpp framebuffer needs more 50% of the video memory already. Which is why the cirrus driver (before the rewrite) had to migrate buffers from/to vram on every page flip[1]. Which is one[2] of the reasons why cirrus (after rewrite) doesn't ttm-manage the vram any more. gem objects are managed with the shmem helpers instead and the active framebuffer is blitted to vram.
The qemu stdvga (bochs driver) has 16 MB vram by default and can be configured to have up to 256 MB. Plenty of room even for multiple 4k framebuffers if needed. So for the bochs driver all the ttm bo migration logic is not needed, it could just store everything in vram.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
A set of drm_gem_vram_* helpers would do the job for bochs.
Thanks for clarifying. drm_gem_vram_* (and
drm_vram_mmfor Simple TTM) is probably a better name for the data structures.+1 on drm_gem_vram_* naming convention - we want to describe what it's for, not how it's implemented.
OK, great.
Quoted 11 lines
Quoted 10 lines
Quoted 4 lines
I'd expect the same applies to the vbox driver.
Dunno about the other drm drivers and the fbdev drivers you plan to migrate over.
The AST HW can support up to 512 MiB, but 32-64 MiB seems more realistic for a server. It's similar with mgag200 HW. The old fbdev-supported device are all somewhere in the range between cirrus and bochs. Some drivers would probably benefit from the cirrus approach, some could use VRAM directly.
Quoted 6 lines
I think for dumb scanout with vram all we need is:
- pin framebuffers, which potentially moves the underlying bo into vram
- unpin framebuffers (which is just accounting, we don't want to move the bo on every flip!)
- if a pin doesn't find enough space, move one of the unpinned bo still resident in vram out
For dumb buffers, I'd expect userspace to have a working set of only a front and back buffer (plus maybe a third one). This working set has to reside in VRAM for performance reasons; non-WS BOs from other userspace programs don't have to be.
So we could simplify even more: if there's not enough free space in vram, remove all unpinned BO's. This would avoid the need to implement an LRU algorithm or another eviction strategy. Userspace with a WS larger than the absolute VRAM would see degraded performance but otherwise still work.
Best regards
Thomas
Quoted 41 lines
- no pipelining, no support for dma engines (it's all cpu copies anway)
- a simpledrm_mmshould be good enough to manage the vram, no need for the ttm style abstraction over how memory is manged
- also just bake in the lru eviction list and algorithm
- probably good to have built-in support for redirecting the mmap between shmem and iomem.
- anything that needs pipelining or copy engines would be out of scope for these helpersI think for starting points we can go with a copypasted version of the various ttm implementations we already have, and then simplify from there as needed. Or just start fresh if that's too complicated, due to the issue Christian highlighted.
-DanielQuoted 22 lines
Best regards
ThomasQuoted 11 lines
cheers,
Gerd[1] Note: The page-flip migration logic is present in some of the other drivers too, not sure whenever they actually need that due to being low on vram too or whenever they just copied the old cirrus code ...
[2] The other reason is that this allow to convert formats at blit time, which helps to deal with some cirrus hardware limitations.
Signature · 5 lines
Thomas Zimmermann Graphics Driver Developer SUSE Linux GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany GF: Felix Imendörffer, Mary Higgins, Sri Rasiah HRB 21284 (AG Nürnberg)
Signature · 5 lines
Thomas Zimmermann Graphics Driver Developer SUSE Linux GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany GF: Felix Imendörffer, Mary Higgins, Sri Rasiah HRB 21284 (AG Nürnberg)
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 61 lines · Thomas Zimmermann
Hi
Am 15.04.19 um 17:54 schrieb Daniel Vetter:
Quoted 24 lines · Thomas Zimmermann
Quoted 23 lines
Hi
Am 09.04.19 um 09:12 schrieb [email protected]:
Quoted 20 lines
Hi,
Quoted 2 lines
If not for TTM, what would be the alternative? One VMA manager per memory region per device?
Depends pretty much on the device.
The cirrus is a display device with only 4 MB of vram. You can't fit much in there. A single 1024x768 @ 24bpp framebuffer needs more 50% of the video memory already. Which is why the cirrus driver (before the rewrite) had to migrate buffers from/to vram on every page flip[1]. Which is one[2] of the reasons why cirrus (after rewrite) doesn't ttm-manage the vram any more. gem objects are managed with the shmem helpers instead and the active framebuffer is blitted to vram.
The qemu stdvga (bochs driver) has 16 MB vram by default and can be configured to have up to 256 MB. Plenty of room even for multiple 4k framebuffers if needed. So for the bochs driver all the ttm bo migration logic is not needed, it could just store everything in vram.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
A set of drm_gem_vram_* helpers would do the job for bochs.
Thanks for clarifying. drm_gem_vram_* (and
drm_vram_mmfor Simple TTM) is probably a better name for the data structures.+1 on drm_gem_vram_* naming convention - we want to describe what it's for, not how it's implemented.
OK, great.
Quoted 11 lines
Quoted 10 lines
Quoted 4 lines
I'd expect the same applies to the vbox driver.
Dunno about the other drm drivers and the fbdev drivers you plan to migrate over.
The AST HW can support up to 512 MiB, but 32-64 MiB seems more realistic for a server. It's similar with mgag200 HW. The old fbdev-supported device are all somewhere in the range between cirrus and bochs. Some drivers would probably benefit from the cirrus approach, some could use VRAM directly.
Quoted 6 lines
I think for dumb scanout with vram all we need is:
- pin framebuffers, which potentially moves the underlying bo into vram
- unpin framebuffers (which is just accounting, we don't want to move the bo on every flip!)
- if a pin doesn't find enough space, move one of the unpinned bo still resident in vram outFor dumb buffers, I'd expect userspace to have a working set of only a front and back buffer (plus maybe a third one). This working set has to reside in VRAM for performance reasons; non-WS BOs from other userspace programs don't have to be.
Quoted 5 lines
So we could simplify even more: if there's not enough free space in vram, remove all unpinned BO's. This would avoid the need to implement an LRU algorithm or another eviction strategy. Userspace with a WS larger than the absolute VRAM would see degraded performance but otherwise still work.
You still need a list of unpinned bo, and the lru scan algorithm is just a few lines of code more than unpinning everything. Plus it'd be a neat example of the drm_mm scan logic. Given that some folks might think that not having lru evict si a problem and get them to type their own, I'd just add it. But up to you. Plus with ttm you get it no matter what.
-Daniel
Quoted 52 lines
Best regards
ThomasQuoted 9 lines
- no pipelining, no support for dma engines (it's all cpu copies anway)
- a simpledrm_mmshould be good enough to manage the vram, no need for the ttm style abstraction over how memory is manged
- also just bake in the lru eviction list and algorithm
- probably good to have built-in support for redirecting the mmap between shmem and iomem.
- anything that needs pipelining or copy engines would be out of scope for these helpersQuoted 32 lines
I think for starting points we can go with a copypasted version of the various ttm implementations we already have, and then simplify from there as needed. Or just start fresh if that's too complicated, due to the issue Christian highlighted.
-DanielQuoted 22 lines
Best regards
ThomasQuoted 11 lines
cheers,
Gerd[1] Note: The page-flip migration logic is present in some of the other drivers too, not sure whenever they actually need that due to being low on vram too or whenever they just copied the old cirrus code ...
[2] The other reason is that this allow to convert formats at blit time, which helps to deal with some cirrus hardware limitations.
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Linux GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany
GF: Felix Imendörffer, Mary Higgins, Sri Rasiah HRB 21284 (AG Nürnberg)--
Thomas Zimmermann
Graphics Driver Developer
SUSE Linux GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany
GF: Felix Imendörffer, Mary Higgins, Sri Rasiah HRB 21284 (AG Nürnberg)
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch _______________________________________________ Virtualization mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Quoted 61 lines · Thomas Zimmermann
Hi
Am 15.04.19 um 17:54 schrieb Daniel Vetter:
Quoted 24 lines · Thomas Zimmermann
Quoted 23 lines
Hi
Am 09.04.19 um 09:12 schrieb [email protected]:
Quoted 20 lines
Hi,
Quoted 2 lines
If not for TTM, what would be the alternative? One VMA manager per memory region per device?
Depends pretty much on the device.
The cirrus is a display device with only 4 MB of vram. You can't fit much in there. A single 1024x768 @ 24bpp framebuffer needs more 50% of the video memory already. Which is why the cirrus driver (before the rewrite) had to migrate buffers from/to vram on every page flip[1]. Which is one[2] of the reasons why cirrus (after rewrite) doesn't ttm-manage the vram any more. gem objects are managed with the shmem helpers instead and the active framebuffer is blitted to vram.
The qemu stdvga (bochs driver) has 16 MB vram by default and can be configured to have up to 256 MB. Plenty of room even for multiple 4k framebuffers if needed. So for the bochs driver all the ttm bo migration logic is not needed, it could just store everything in vram.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
A set of drm_gem_vram_* helpers would do the job for bochs.
Thanks for clarifying. drm_gem_vram_* (and
drm_vram_mmfor Simple TTM) is probably a better name for the data structures.+1 on drm_gem_vram_* naming convention - we want to describe what it's for, not how it's implemented.
OK, great.
Quoted 11 lines
Quoted 10 lines
Quoted 4 lines
I'd expect the same applies to the vbox driver.
Dunno about the other drm drivers and the fbdev drivers you plan to migrate over.
The AST HW can support up to 512 MiB, but 32-64 MiB seems more realistic for a server. It's similar with mgag200 HW. The old fbdev-supported device are all somewhere in the range between cirrus and bochs. Some drivers would probably benefit from the cirrus approach, some could use VRAM directly.
Quoted 6 lines
I think for dumb scanout with vram all we need is:
- pin framebuffers, which potentially moves the underlying bo into vram
- unpin framebuffers (which is just accounting, we don't want to move the bo on every flip!)
- if a pin doesn't find enough space, move one of the unpinned bo still resident in vram outFor dumb buffers, I'd expect userspace to have a working set of only a front and back buffer (plus maybe a third one). This working set has to reside in VRAM for performance reasons; non-WS BOs from other userspace programs don't have to be.
Quoted 5 lines
So we could simplify even more: if there's not enough free space in vram, remove all unpinned BO's. This would avoid the need to implement an LRU algorithm or another eviction strategy. Userspace with a WS larger than the absolute VRAM would see degraded performance but otherwise still work.
You still need a list of unpinned bo, and the lru scan algorithm is just a few lines of code more than unpinning everything. Plus it'd be a neat example of the drm_mm scan logic. Given that some folks might think that not having lru evict si a problem and get them to type their own, I'd just add it. But up to you. Plus with ttm you get it no matter what.
-Daniel
Quoted 52 lines
Best regards
ThomasQuoted 9 lines
- no pipelining, no support for dma engines (it's all cpu copies anway)
- a simpledrm_mmshould be good enough to manage the vram, no need for the ttm style abstraction over how memory is manged
- also just bake in the lru eviction list and algorithm
- probably good to have built-in support for redirecting the mmap between shmem and iomem.
- anything that needs pipelining or copy engines would be out of scope for these helpersQuoted 32 lines
I think for starting points we can go with a copypasted version of the various ttm implementations we already have, and then simplify from there as needed. Or just start fresh if that's too complicated, due to the issue Christian highlighted.
-DanielQuoted 22 lines
Best regards
ThomasQuoted 11 lines
cheers,
Gerd[1] Note: The page-flip migration logic is present in some of the other drivers too, not sure whenever they actually need that due to being low on vram too or whenever they just copied the old cirrus code ...
[2] The other reason is that this allow to convert formats at blit time, which helps to deal with some cirrus hardware limitations.
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Linux GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany
GF: Felix Imendörffer, Mary Higgins, Sri Rasiah HRB 21284 (AG Nürnberg)--
Thomas Zimmermann
Graphics Driver Developer
SUSE Linux GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany
GF: Felix Imendörffer, Mary Higgins, Sri Rasiah HRB 21284 (AG Nürnberg)
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Am 15.04.19 um 21:17 schrieb Daniel Vetter:
Quoted 34 lines · Thomas Zimmermann
Quoted 28 lines
Hi
Am 15.04.19 um 17:54 schrieb Daniel Vetter:
Quoted 14 lines · Thomas Zimmermann
Quoted 6 lines
Hi
Am 09.04.19 um 09:12 schrieb [email protected]:
[SNIP]Quoted 2 lines
I'd expect the same applies to the vbox driver.
Quoted 7 lines
Quoted 2 lines
Dunno about the other drm drivers and the fbdev drivers you plan to migrate over.
The AST HW can support up to 512 MiB, but 32-64 MiB seems more realistic for a server. It's similar with mgag200 HW. The old fbdev-supported device are all somewhere in the range between cirrus and bochs. Some drivers would probably benefit from the cirrus approach, some could use VRAM directly.
Quoted 6 lines
I think for dumb scanout with vram all we need is:
- pin framebuffers, which potentially moves the underlying bo into vram
- unpin framebuffers (which is just accounting, we don't want to move the bo on every flip!)
- if a pin doesn't find enough space, move one of the unpinned bo still resident in vram outFor dumb buffers, I'd expect userspace to have a working set of only a front and back buffer (plus maybe a third one). This working set has to reside in VRAM for performance reasons; non-WS BOs from other userspace programs don't have to be.
Quoted 5 lines
So we could simplify even more: if there's not enough free space in vram, remove all unpinned BO's. This would avoid the need to implement an LRU algorithm or another eviction strategy. Userspace with a WS larger than the absolute VRAM would see degraded performance but otherwise still work.
Quoted 6 lines
You still need a list of unpinned bo, and the lru scan algorithm is just a few lines of code more than unpinning everything. Plus it'd be a neat example of the
drm_mmscan logic. Given that some folks might think that not having lru evict si a problem and get them to type their own, I'd just add it. But up to you. Plus with ttm you get it no matter what.
Well how about making an drm_lru component which just does the following (and nothing else, please :):
1. Keep a list of objects and a spinlock protecting the list.
2. Offer helpers for adding/deleting/moving stuff from the list.
3. Offer a functionality to do the necessary dance of picking the first entry where we can trylock it's reservation object.
4. Offer bulk move functionality similar to what TTM does at the moment (can be implemented later on).
Regards,
Christian.
Am 15.04.19 um 21:17 schrieb Daniel Vetter:
Quoted 34 lines · Thomas Zimmermann
Quoted 28 lines
Hi
Am 15.04.19 um 17:54 schrieb Daniel Vetter:
Quoted 14 lines · Thomas Zimmermann
Quoted 6 lines
Hi
Am 09.04.19 um 09:12 schrieb [email protected]:
[SNIP]Quoted 2 lines
I'd expect the same applies to the vbox driver.
Quoted 7 lines
Quoted 2 lines
Dunno about the other drm drivers and the fbdev drivers you plan to migrate over.
The AST HW can support up to 512 MiB, but 32-64 MiB seems more realistic for a server. It's similar with mgag200 HW. The old fbdev-supported device are all somewhere in the range between cirrus and bochs. Some drivers would probably benefit from the cirrus approach, some could use VRAM directly.
Quoted 6 lines
I think for dumb scanout with vram all we need is:
- pin framebuffers, which potentially moves the underlying bo into vram
- unpin framebuffers (which is just accounting, we don't want to move the bo on every flip!)
- if a pin doesn't find enough space, move one of the unpinned bo still resident in vram outFor dumb buffers, I'd expect userspace to have a working set of only a front and back buffer (plus maybe a third one). This working set has to reside in VRAM for performance reasons; non-WS BOs from other userspace programs don't have to be.
Quoted 5 lines
So we could simplify even more: if there's not enough free space in vram, remove all unpinned BO's. This would avoid the need to implement an LRU algorithm or another eviction strategy. Userspace with a WS larger than the absolute VRAM would see degraded performance but otherwise still work.
Quoted 6 lines
You still need a list of unpinned bo, and the lru scan algorithm is just a few lines of code more than unpinning everything. Plus it'd be a neat example of the
drm_mmscan logic. Given that some folks might think that not having lru evict si a problem and get them to type their own, I'd just add it. But up to you. Plus with ttm you get it no matter what.
Well how about making an drm_lru component which just does the following (and nothing else, please :):
1. Keep a list of objects and a spinlock protecting the list.
2. Offer helpers for adding/deleting/moving stuff from the list.
3. Offer a functionality to do the necessary dance of picking the first entry where we can trylock it's reservation object.
4. Offer bulk move functionality similar to what TTM does at the moment (can be implemented later on).
Regards,
Christian.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 48 lines · Christian
Am 15.04.19 um 21:17 schrieb Daniel Vetter:
Quoted 34 lines · Thomas Zimmermann
Quoted 28 lines
Hi
Am 15.04.19 um 17:54 schrieb Daniel Vetter:
Quoted 14 lines · Thomas Zimmermann
Quoted 6 lines
Hi
Am 09.04.19 um 09:12 schrieb [email protected]:
[SNIP]Quoted 2 lines
I'd expect the same applies to the vbox driver.
Quoted 7 lines
Quoted 2 lines
Dunno about the other drm drivers and the fbdev drivers you plan to migrate over.
The AST HW can support up to 512 MiB, but 32-64 MiB seems more realistic for a server. It's similar with mgag200 HW. The old fbdev-supported device are all somewhere in the range between cirrus and bochs. Some drivers would probably benefit from the cirrus approach, some could use VRAM directly.
Quoted 6 lines
I think for dumb scanout with vram all we need is:
- pin framebuffers, which potentially moves the underlying bo into vram
- unpin framebuffers (which is just accounting, we don't want to move the bo on every flip!)
- if a pin doesn't find enough space, move one of the unpinned bo still resident in vram outFor dumb buffers, I'd expect userspace to have a working set of only a front and back buffer (plus maybe a third one). This working set has to reside in VRAM for performance reasons; non-WS BOs from other userspace programs don't have to be.
Quoted 5 lines
So we could simplify even more: if there's not enough free space in vram, remove all unpinned BO's. This would avoid the need to implement an LRU algorithm or another eviction strategy. Userspace with a WS larger than the absolute VRAM would see degraded performance but otherwise still work.
Quoted 6 lines
You still need a list of unpinned bo, and the lru scan algorithm is just a few lines of code more than unpinning everything. Plus it'd be a neat example of the
drm_mmscan logic. Given that some folks might think that not having lru evict si a problem and get them to type their own, I'd just add it. But up to you. Plus with ttm you get it no matter what.Well how about making an
drm_lrucomponent which just does the following (and nothing else, please :):1. Keep a list of objects and a spinlock protecting the list.
Quoted 7 lines
2. Offer helpers for adding/deleting/moving stuff from the list.
3. Offer a functionality to do the necessary dance of picking the first entry where we can trylock it's reservation object.
4. Offer bulk move functionality similar to what TTM does at the moment (can be implemented later on).
At a basic level, this is list_head of drm_gem_object. Not sure that's all that useful (outside of the fairly simplistic vram helpers we're discussing here). Reasons for that is that there's a lot of trickery in selecting which is the best object to pick in any given case (e.g. do you want to use drm_mm scanning, or is there a slab of objects you prefer to throw out because that avoids. Given that I'm not sure implementing the entire scanning/drm_lru logic is beneficial.
The magic trylock+kref_get_unless_zero otoh could be worth implementing as a helper, together with a note about how to build your own custom lru algorithm. Same for some bulk/nonblocking movement helpers maybe. Both not really needed for the dumb scanout vram helpers we're discussing here.
-Daniel
-Daniel
--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
Quoted 48 lines · Christian
Am 15.04.19 um 21:17 schrieb Daniel Vetter:
Quoted 34 lines · Thomas Zimmermann
Quoted 28 lines
Hi
Am 15.04.19 um 17:54 schrieb Daniel Vetter:
Quoted 14 lines · Thomas Zimmermann
Quoted 6 lines
Hi
Am 09.04.19 um 09:12 schrieb [email protected]:
[SNIP]Quoted 2 lines
I'd expect the same applies to the vbox driver.
Quoted 7 lines
Quoted 2 lines
Dunno about the other drm drivers and the fbdev drivers you plan to migrate over.
The AST HW can support up to 512 MiB, but 32-64 MiB seems more realistic for a server. It's similar with mgag200 HW. The old fbdev-supported device are all somewhere in the range between cirrus and bochs. Some drivers would probably benefit from the cirrus approach, some could use VRAM directly.
Quoted 6 lines
I think for dumb scanout with vram all we need is:
- pin framebuffers, which potentially moves the underlying bo into vram
- unpin framebuffers (which is just accounting, we don't want to move the bo on every flip!)
- if a pin doesn't find enough space, move one of the unpinned bo still resident in vram outFor dumb buffers, I'd expect userspace to have a working set of only a front and back buffer (plus maybe a third one). This working set has to reside in VRAM for performance reasons; non-WS BOs from other userspace programs don't have to be.
Quoted 5 lines
So we could simplify even more: if there's not enough free space in vram, remove all unpinned BO's. This would avoid the need to implement an LRU algorithm or another eviction strategy. Userspace with a WS larger than the absolute VRAM would see degraded performance but otherwise still work.
Quoted 6 lines
You still need a list of unpinned bo, and the lru scan algorithm is just a few lines of code more than unpinning everything. Plus it'd be a neat example of the
drm_mmscan logic. Given that some folks might think that not having lru evict si a problem and get them to type their own, I'd just add it. But up to you. Plus with ttm you get it no matter what.Well how about making an
drm_lrucomponent which just does the following (and nothing else, please :):1. Keep a list of objects and a spinlock protecting the list.
Quoted 7 lines
2. Offer helpers for adding/deleting/moving stuff from the list.
3. Offer a functionality to do the necessary dance of picking the first entry where we can trylock it's reservation object.
4. Offer bulk move functionality similar to what TTM does at the moment (can be implemented later on).
At a basic level, this is list_head of drm_gem_object. Not sure that's all that useful (outside of the fairly simplistic vram helpers we're discussing here). Reasons for that is that there's a lot of trickery in selecting which is the best object to pick in any given case (e.g. do you want to use drm_mm scanning, or is there a slab of objects you prefer to throw out because that avoids. Given that I'm not sure implementing the entire scanning/drm_lru logic is beneficial.
The magic trylock+kref_get_unless_zero otoh could be worth implementing as a helper, together with a note about how to build your own custom lru algorithm. Same for some bulk/nonblocking movement helpers maybe. Both not really needed for the dumb scanout vram helpers we're discussing here.
-Daniel
-Daniel
--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Am 16.04.19 um 13:03 schrieb Daniel Vetter:
Quoted 63 lines
Quoted 46 lines · Christian
Am 15.04.19 um 21:17 schrieb Daniel Vetter:
Quoted 34 lines · Thomas Zimmermann
Quoted 28 lines
Hi
Am 15.04.19 um 17:54 schrieb Daniel Vetter:
Quoted 14 lines · Thomas Zimmermann
Quoted 6 lines
Hi
Am 09.04.19 um 09:12 schrieb [email protected]:
[SNIP]Quoted 2 lines
I'd expect the same applies to the vbox driver.
Quoted 7 lines
Quoted 2 lines
Dunno about the other drm drivers and the fbdev drivers you plan to migrate over.
The AST HW can support up to 512 MiB, but 32-64 MiB seems more realistic for a server. It's similar with mgag200 HW. The old fbdev-supported device are all somewhere in the range between cirrus and bochs. Some drivers would probably benefit from the cirrus approach, some could use VRAM directly.
Quoted 6 lines
I think for dumb scanout with vram all we need is:
- pin framebuffers, which potentially moves the underlying bo into vram
- unpin framebuffers (which is just accounting, we don't want to move the bo on every flip!)
- if a pin doesn't find enough space, move one of the unpinned bo still resident in vram outFor dumb buffers, I'd expect userspace to have a working set of only a front and back buffer (plus maybe a third one). This working set has to reside in VRAM for performance reasons; non-WS BOs from other userspace programs don't have to be.
Quoted 5 lines
So we could simplify even more: if there's not enough free space in vram, remove all unpinned BO's. This would avoid the need to implement an LRU algorithm or another eviction strategy. Userspace with a WS larger than the absolute VRAM would see degraded performance but otherwise still work.
Quoted 6 lines
You still need a list of unpinned bo, and the lru scan algorithm is just a few lines of code more than unpinning everything. Plus it'd be a neat example of the
drm_mmscan logic. Given that some folks might think that not having lru evict si a problem and get them to type their own, I'd just add it. But up to you. Plus with ttm you get it no matter what.Well how about making an
drm_lrucomponent which just does the following (and nothing else, please :):1. Keep a list of objects and a spinlock protecting the list.
Quoted 7 lines
2. Offer helpers for adding/deleting/moving stuff from the list.
3. Offer a functionality to do the necessary dance of picking the first entry where we can trylock it's reservation object.
4. Offer bulk move functionality similar to what TTM does at the moment (can be implemented later on).
At a basic level, this is
list_headofdrm_gem_object. Not sure that's all that useful (outside of the fairly simplistic vram helpers we're discussing here). Reasons for that is that there's a lot of trickery in selecting which is the best object to pick in any given case (e.g. do you want to usedrm_mmscanning, or is there a slab of objects you prefer to throw out because that avoids. Given that I'm not sure implementing the entire scanning/drm_lru logic is beneficial.
Quoted 5 lines
The magic trylock+kref_get_unless_zero otoh could be worth implementing as a helper, together with a note about how to build your own custom lru algorithm. Same for some bulk/nonblocking movement helpers maybe. Both not really needed for the dumb scanout vram helpers we're discussing here.
Yeah, exactly that's what I wanted to get towards as well.
This magic trylock+kref_get is what needs to be handled correctly by all drivers which implement an LRU.
LRU bulk move is something which is tricky to get right as well, but so far only amdgpu uses it so it only make sense to share when somebody else wants the same approach.
Christian.
Quoted 7 lines
(quoted diff) +0
-3-Daniel -Daniel --Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch