From patchwork Sun Oct 15 16:30:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Noralf_Tr=C3=B8nnes?= X-Patchwork-Id: 10007179 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5785A601E9 for ; Sun, 15 Oct 2017 16:31:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5A99720415 for ; Sun, 15 Oct 2017 16:31:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4F49120453; Sun, 15 Oct 2017 16:31:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3743620415 for ; Sun, 15 Oct 2017 16:31:13 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 449316E221; Sun, 15 Oct 2017 16:31:07 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from smtp.domeneshop.no (smtp.domeneshop.no [IPv6:2a01:5b40:0:3005::1]) by gabe.freedesktop.org (Postfix) with ESMTPS id B5C626E19A for ; Sun, 15 Oct 2017 16:31:05 +0000 (UTC) Received: from 211.81-166-168.customer.lyse.net ([81.166.168.211]:55432 helo=localhost.localdomain) by smtp.domeneshop.no with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_CBC_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1e3lod-0004VL-RJ; Sun, 15 Oct 2017 18:31:03 +0200 From: =?UTF-8?q?Noralf=20Tr=C3=B8nnes?= To: dri-devel@lists.freedesktop.org Subject: [PATCH v2 7/8] drm/tinydrm: Use drm_vmalloc_bo Date: Sun, 15 Oct 2017 18:30:41 +0200 Message-Id: <20171015163042.35017-8-noralf@tronnes.org> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171015163042.35017-1-noralf@tronnes.org> References: <20171015163042.35017-1-noralf@tronnes.org> MIME-Version: 1.0 Cc: daniel.vetter@ffwll.ch, matt@gatt.is, David Lechner X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Use the vmalloc BO helper instead of the cma helper to be able to PRIME import from more drivers. The cma helper can only import physically continuous buffers, but tinydrm only requires the buffer to be virtually continuous. This switch also makes it possible to use the drm_fb_helper_lastclose() helper. Some extra includes were necessary in tinydrm-helpers.c, because it relied on includes in tinydrm.h that are now gone. Cc: David Lechner Signed-off-by: Noralf Trønnes --- drivers/gpu/drm/tinydrm/Kconfig | 2 +- drivers/gpu/drm/tinydrm/core/tinydrm-core.c | 134 +++++-------------------- drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c | 2 + drivers/gpu/drm/tinydrm/mi0283qt.c | 8 +- drivers/gpu/drm/tinydrm/mipi-dbi.c | 31 ++---- drivers/gpu/drm/tinydrm/repaper.c | 21 ++-- drivers/gpu/drm/tinydrm/st7586.c | 14 +-- include/drm/tinydrm/mipi-dbi.h | 2 + include/drm/tinydrm/tinydrm.h | 38 ++----- 9 files changed, 65 insertions(+), 187 deletions(-) diff --git a/drivers/gpu/drm/tinydrm/Kconfig b/drivers/gpu/drm/tinydrm/Kconfig index 2e790e7dced5..d47bcd6c8bfb 100644 --- a/drivers/gpu/drm/tinydrm/Kconfig +++ b/drivers/gpu/drm/tinydrm/Kconfig @@ -2,7 +2,7 @@ menuconfig DRM_TINYDRM tristate "Support for simple displays" depends on DRM select DRM_KMS_HELPER - select DRM_KMS_CMA_HELPER + select DRM_VMALLOC_BO_HELPER select BACKLIGHT_LCD_SUPPORT select BACKLIGHT_CLASS_DEVICE help diff --git a/drivers/gpu/drm/tinydrm/core/tinydrm-core.c b/drivers/gpu/drm/tinydrm/core/tinydrm-core.c index 1a8a57cad431..77c5fd50af7a 100644 --- a/drivers/gpu/drm/tinydrm/core/tinydrm-core.c +++ b/drivers/gpu/drm/tinydrm/core/tinydrm-core.c @@ -10,7 +10,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -22,9 +24,11 @@ * * It is based on &drm_simple_display_pipe coupled with a &drm_connector which * has only one fixed &drm_display_mode. The framebuffers are backed by the - * cma helper and have support for framebuffer flushing (dirty). + * vmalloc BO helper and have support for framebuffer flushing (dirty). * fbdev support is also included. * + * Note: The SPI core is able to create a scatter/gather table from a vmalloc + * buffer when dealing with DMA capable SPI controllers */ /** @@ -35,94 +39,6 @@ * and registers the DRM device using devm_tinydrm_register(). */ -/** - * tinydrm_lastclose - DRM lastclose helper - * @drm: DRM device - * - * This function ensures that fbdev is restored when drm_lastclose() is called - * on the last drm_release(). Drivers can use this as their - * &drm_driver->lastclose callback. - */ -void tinydrm_lastclose(struct drm_device *drm) -{ - struct tinydrm_device *tdev = drm->dev_private; - - DRM_DEBUG_KMS("\n"); - drm_fbdev_cma_restore_mode(tdev->fbdev_cma); -} -EXPORT_SYMBOL(tinydrm_lastclose); - -/** - * tinydrm_gem_cma_prime_import_sg_table - Produce a CMA GEM object from - * another driver's scatter/gather table of pinned pages - * @drm: DRM device to import into - * @attach: DMA-BUF attachment - * @sgt: Scatter/gather table of pinned pages - * - * This function imports a scatter/gather table exported via DMA-BUF by - * another driver using drm_gem_cma_prime_import_sg_table(). It sets the - * kernel virtual address on the CMA object. Drivers should use this as their - * &drm_driver->gem_prime_import_sg_table callback if they need the virtual - * address. tinydrm_gem_cma_free_object() should be used in combination with - * this function. - * - * Returns: - * A pointer to a newly created GEM object or an ERR_PTR-encoded negative - * error code on failure. - */ -struct drm_gem_object * -tinydrm_gem_cma_prime_import_sg_table(struct drm_device *drm, - struct dma_buf_attachment *attach, - struct sg_table *sgt) -{ - struct drm_gem_cma_object *cma_obj; - struct drm_gem_object *obj; - void *vaddr; - - vaddr = dma_buf_vmap(attach->dmabuf); - if (!vaddr) { - DRM_ERROR("Failed to vmap PRIME buffer\n"); - return ERR_PTR(-ENOMEM); - } - - obj = drm_gem_cma_prime_import_sg_table(drm, attach, sgt); - if (IS_ERR(obj)) { - dma_buf_vunmap(attach->dmabuf, vaddr); - return obj; - } - - cma_obj = to_drm_gem_cma_obj(obj); - cma_obj->vaddr = vaddr; - - return obj; -} -EXPORT_SYMBOL(tinydrm_gem_cma_prime_import_sg_table); - -/** - * tinydrm_gem_cma_free_object - Free resources associated with a CMA GEM - * object - * @gem_obj: GEM object to free - * - * This function frees the backing memory of the CMA GEM object, cleans up the - * GEM object state and frees the memory used to store the object itself using - * drm_gem_cma_free_object(). It also handles PRIME buffers which has the kernel - * virtual address set by tinydrm_gem_cma_prime_import_sg_table(). Drivers - * can use this as their &drm_driver->gem_free_object callback. - */ -void tinydrm_gem_cma_free_object(struct drm_gem_object *gem_obj) -{ - if (gem_obj->import_attach) { - struct drm_gem_cma_object *cma_obj; - - cma_obj = to_drm_gem_cma_obj(gem_obj); - dma_buf_vunmap(gem_obj->import_attach->dmabuf, cma_obj->vaddr); - cma_obj->vaddr = NULL; - } - - drm_gem_cma_free_object(gem_obj); -} -EXPORT_SYMBOL_GPL(tinydrm_gem_cma_free_object); - static struct drm_framebuffer * tinydrm_fb_create(struct drm_device *drm, struct drm_file *file_priv, const struct drm_mode_fb_cmd2 *mode_cmd) @@ -211,38 +127,40 @@ int devm_tinydrm_init(struct device *parent, struct tinydrm_device *tdev, } EXPORT_SYMBOL(devm_tinydrm_init); +static int tinydrm_fbdev_probe(struct drm_fb_helper *helper, + struct drm_fb_helper_surface_size *sizes) + +{ + struct tinydrm_device *tdev = helper->dev->dev_private; + + return drm_vmalloc_bo_fbdev_probe(helper, sizes, tdev->fb_funcs); +} + +static const struct drm_fb_helper_funcs tinydrm_fb_helper_funcs = { + .fb_probe = tinydrm_fbdev_probe, +}; + static int tinydrm_register(struct tinydrm_device *tdev) { struct drm_device *drm = tdev->drm; - int bpp = drm->mode_config.preferred_depth; - struct drm_fbdev_cma *fbdev; int ret; - ret = drm_dev_register(tdev->drm, 0); + ret = drm_dev_register(drm, 0); if (ret) return ret; - fbdev = drm_fbdev_cma_init_with_funcs(drm, bpp ? bpp : 32, - drm->mode_config.num_connector, - tdev->fb_funcs); - if (IS_ERR(fbdev)) - DRM_ERROR("Failed to initialize fbdev: %ld\n", PTR_ERR(fbdev)); - else - tdev->fbdev_cma = fbdev; + ret = drm_fb_helper_simple_init(drm, &tinydrm_fb_helper_funcs, 0, 0); + if (ret) + DRM_ERROR("Failed to initialize fbdev: %d\n", ret); return 0; } static void tinydrm_unregister(struct tinydrm_device *tdev) { - struct drm_fbdev_cma *fbdev_cma = tdev->fbdev_cma; - drm_atomic_helper_shutdown(tdev->drm); - /* don't restore fbdev in lastclose, keep pipeline disabled */ - tdev->fbdev_cma = NULL; + drm_fb_helper_simple_fini(tdev->drm); drm_dev_unregister(tdev->drm); - if (fbdev_cma) - drm_fbdev_cma_fini(fbdev_cma); } static void devm_tinydrm_register_release(void *data) @@ -312,10 +230,10 @@ int tinydrm_suspend(struct tinydrm_device *tdev) return -EINVAL; } - drm_fbdev_cma_set_suspend_unlocked(tdev->fbdev_cma, 1); + drm_fb_helper_set_suspend_unlocked(tdev->drm->fbdev, 1); state = drm_atomic_helper_suspend(tdev->drm); if (IS_ERR(state)) { - drm_fbdev_cma_set_suspend_unlocked(tdev->fbdev_cma, 0); + drm_fb_helper_set_suspend_unlocked(tdev->drm->fbdev, 0); return PTR_ERR(state); } @@ -353,7 +271,7 @@ int tinydrm_resume(struct tinydrm_device *tdev) return ret; } - drm_fbdev_cma_set_suspend_unlocked(tdev->fbdev_cma, 0); + drm_fb_helper_set_suspend_unlocked(tdev->drm->fbdev, 0); return 0; } diff --git a/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c b/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c index bd6cce093a85..ee9a8f305b26 100644 --- a/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c +++ b/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c @@ -9,10 +9,12 @@ #include #include +#include #include #include #include +#include #include #include diff --git a/drivers/gpu/drm/tinydrm/mi0283qt.c b/drivers/gpu/drm/tinydrm/mi0283qt.c index 6a83b3093254..19c8ef5cea78 100644 --- a/drivers/gpu/drm/tinydrm/mi0283qt.c +++ b/drivers/gpu/drm/tinydrm/mi0283qt.c @@ -9,6 +9,8 @@ * (at your option) any later version. */ +#include +#include #include #include #include @@ -132,14 +134,14 @@ static const struct drm_display_mode mi0283qt_mode = { TINYDRM_MODE(320, 240, 58, 43), }; -DEFINE_DRM_GEM_CMA_FOPS(mi0283qt_fops); +DEFINE_DRM_VMALLOC_BO_FOPS(mi0283qt_fops); static struct drm_driver mi0283qt_driver = { .driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_PRIME | DRIVER_ATOMIC, .fops = &mi0283qt_fops, - TINYDRM_GEM_DRIVER_OPS, - .lastclose = tinydrm_lastclose, + DRM_VMALLOC_BO_DRIVER_OPS, + .lastclose = drm_fb_helper_lastclose, .debugfs_init = mipi_dbi_debugfs_init, .name = "mi0283qt", .desc = "Multi-Inno MI0283QT", diff --git a/drivers/gpu/drm/tinydrm/mipi-dbi.c b/drivers/gpu/drm/tinydrm/mipi-dbi.c index d43e992ab432..5f9252b05ba2 100644 --- a/drivers/gpu/drm/tinydrm/mipi-dbi.c +++ b/drivers/gpu/drm/tinydrm/mipi-dbi.c @@ -10,6 +10,7 @@ */ #include +#include #include #include #include @@ -157,10 +158,10 @@ EXPORT_SYMBOL(mipi_dbi_command_buf); static int mipi_dbi_buf_copy(void *dst, struct drm_framebuffer *fb, struct drm_clip_rect *clip, bool swap) { - struct drm_gem_cma_object *cma_obj = drm_fb_cma_get_gem_obj(fb, 0); - struct dma_buf_attachment *import_attach = cma_obj->base.import_attach; + struct drm_gem_object *obj = drm_gem_fb_get_obj(fb, 0); + struct dma_buf_attachment *import_attach = obj->import_attach; + void *src = drm_vmalloc_bo_fb_vaddr(fb); struct drm_format_name_buf format_name; - void *src = cma_obj->vaddr; int ret = 0; if (import_attach) { @@ -199,7 +200,6 @@ static int mipi_dbi_fb_dirty(struct drm_framebuffer *fb, struct drm_clip_rect *clips, unsigned int num_clips) { - struct drm_gem_cma_object *cma_obj = drm_fb_cma_get_gem_obj(fb, 0); struct tinydrm_device *tdev = fb->dev->dev_private; struct mipi_dbi *mipi = mipi_dbi_from_tinydrm(tdev); bool swap = mipi->swap_bytes; @@ -230,7 +230,7 @@ static int mipi_dbi_fb_dirty(struct drm_framebuffer *fb, if (ret) goto out_unlock; } else { - tr = cma_obj->vaddr; + tr = drm_vmalloc_bo_fb_vaddr(fb); } mipi_dbi_command(mipi, MIPI_DCS_SET_COLUMN_ADDRESS, @@ -801,31 +801,12 @@ int mipi_dbi_spi_init(struct spi_device *spi, struct mipi_dbi *mipi, { size_t tx_size = tinydrm_spi_max_transfer_size(spi, 0); struct device *dev = &spi->dev; - int ret; if (tx_size < 16) { DRM_ERROR("SPI transmit buffer too small: %zu\n", tx_size); return -EINVAL; } - /* - * Even though it's not the SPI device that does DMA (the master does), - * the dma mask is necessary for the dma_alloc_wc() in - * drm_gem_cma_create(). The dma_addr returned will be a physical - * adddress which might be different from the bus address, but this is - * not a problem since the address will not be used. - * The virtual address is used in the transfer and the SPI core - * re-maps it on the SPI master device using the DMA streaming API - * (spi_map_buf()). - */ - if (!dev->coherent_dma_mask) { - ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32)); - if (ret) { - dev_warn(dev, "Failed to set dma mask %d\n", ret); - return ret; - } - } - mipi->spi = spi; mipi->read_commands = mipi_dbi_dcs_read_commands; @@ -962,7 +943,7 @@ static const struct file_operations mipi_dbi_debugfs_command_fops = { }; static const struct drm_info_list mipi_dbi_debugfs_list[] = { - { "fb", drm_fb_cma_debugfs_show, 0 }, + { "fb", drm_gem_fb_debugfs_show, 0 }, }; /** diff --git a/drivers/gpu/drm/tinydrm/repaper.c b/drivers/gpu/drm/tinydrm/repaper.c index 75740630c410..e449780cfd2e 100644 --- a/drivers/gpu/drm/tinydrm/repaper.c +++ b/drivers/gpu/drm/tinydrm/repaper.c @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -526,10 +527,11 @@ static int repaper_fb_dirty(struct drm_framebuffer *fb, struct drm_clip_rect *clips, unsigned int num_clips) { - struct drm_gem_cma_object *cma_obj = drm_fb_cma_get_gem_obj(fb, 0); - struct dma_buf_attachment *import_attach = cma_obj->base.import_attach; + struct drm_gem_object *obj = drm_gem_fb_get_obj(fb, 0); + struct dma_buf_attachment *import_attach = obj->import_attach; struct tinydrm_device *tdev = fb->dev->dev_private; struct repaper_epd *epd = epd_from_tinydrm(tdev); + void *src = drm_vmalloc_bo_fb_vaddr(fb); struct drm_clip_rect clip; u8 *buf = NULL; int ret = 0; @@ -567,7 +569,7 @@ static int repaper_fb_dirty(struct drm_framebuffer *fb, goto out_unlock; } - tinydrm_xrgb8888_to_gray8(buf, cma_obj->vaddr, fb, &clip); + tinydrm_xrgb8888_to_gray8(buf, src, fb, &clip); if (import_attach) { ret = dma_buf_end_cpu_access(import_attach->dmabuf, @@ -887,13 +889,13 @@ static const struct drm_display_mode repaper_e2271cs021_mode = { static const u8 repaper_e2271cs021_cs[] = { 0x00, 0x00, 0x00, 0x7f, 0xff, 0xfe, 0x00, 0x00 }; -DEFINE_DRM_GEM_CMA_FOPS(repaper_fops); +DEFINE_DRM_VMALLOC_BO_FOPS(repaper_fops); static struct drm_driver repaper_driver = { .driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_PRIME | DRIVER_ATOMIC, .fops = &repaper_fops, - TINYDRM_GEM_DRIVER_OPS, + DRM_VMALLOC_BO_DRIVER_OPS, .name = "repaper", .desc = "Pervasive Displays RePaper e-ink panels", .date = "20170405", @@ -940,15 +942,6 @@ static int repaper_probe(struct spi_device *spi) model = spi_id->driver_data; } - /* The SPI device is used to allocate dma memory */ - if (!dev->coherent_dma_mask) { - ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32)); - if (ret) { - dev_warn(dev, "Failed to set dma mask %d\n", ret); - return ret; - } - } - epd = devm_kzalloc(dev, sizeof(*epd), GFP_KERNEL); if (!epd) return -ENOMEM; diff --git a/drivers/gpu/drm/tinydrm/st7586.c b/drivers/gpu/drm/tinydrm/st7586.c index 0a2c60da5c0e..98657454587d 100644 --- a/drivers/gpu/drm/tinydrm/st7586.c +++ b/drivers/gpu/drm/tinydrm/st7586.c @@ -17,7 +17,9 @@ #include #include