From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 78E53C4363A for ; Thu, 22 Oct 2020 08:08:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 10444223BF for ; Thu, 22 Oct 2020 08:08:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="LpVtkQQE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2894680AbgJVIIH (ORCPT ); Thu, 22 Oct 2020 04:08:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2894371AbgJVIFk (ORCPT ); Thu, 22 Oct 2020 04:05:40 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2298C0613CF for ; Thu, 22 Oct 2020 01:05:39 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id e2so894841wme.1 for ; Thu, 22 Oct 2020 01:05:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=jo9DObZgd9Jq6ZPonfHxKOsM2RbE9S9o0V4+k1CciSY=; b=LpVtkQQEzDhGLYock7xQGko/zoS3bHGVeS2MwITVSQjnbfP4AMhqamrvOtAFmXYrPu M4rdxuuXfajVAiGf91dIAQUVAfjFyk3TE3h9FLC57hbSTRNI8HSEiW7wSnn833mLl3bT qYQcRr7XPtDbhyfcVfQaWMtP5UWNo6sIUEMEs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=jo9DObZgd9Jq6ZPonfHxKOsM2RbE9S9o0V4+k1CciSY=; b=CPy46nzAjYhttDaHj074ZXzjk5kyIHQgj/ZStogjjZeZmtYMLdQsb3HdAw+scKhCNB aUWCBMM2DEwUsQ6uxOg5BUKJQHDdK7lDs6g1OjW0bEQJ+ZA/bWv92+em1Bi6D9YKw6sA O/+YiwIJMu4yrFN2F/XzsOzbE3j5jW9lBlvpQeBuRmgsGJx2OjXTpmEeFc+edIbBOgnJ L6+/B8dJS2bt2eW/umMM3R0wZ/yD7tVh0hfGltlf56/5elBRUvB3XiwfH9rMve2rAWAv jLyeP5hX3Eiujghlu+L0HYBB+B/nh6152dUIS8ggaF3u3dVr8vpzJrixIkqj0QSjkKeo KoVg== X-Gm-Message-State: AOAM530CJ/zr1rVEPJq2cG9N7yvWS1Nn+jqRdyfi/AYqN4qtHugAmOHK hMPDhUsheJm67IjshRyw1fWfPQ== X-Google-Smtp-Source: ABdhPJz1mIaxROQHFnkDMtAkyfocV37SNrA+OnkarpcW450fCaDG5+KffMOrvXq4qfjJmhfMWT0ZNg== X-Received: by 2002:a1c:2cc2:: with SMTP id s185mr1359132wms.77.1603353938320; Thu, 22 Oct 2020 01:05:38 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id 32sm2105875wro.31.2020.10.22.01.05.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Oct 2020 01:05:37 -0700 (PDT) Date: Thu, 22 Oct 2020 10:05:34 +0200 From: Daniel Vetter To: Thomas Zimmermann Cc: maarten.lankhorst@linux.intel.com, mripard@kernel.org, airlied@linux.ie, daniel@ffwll.ch, sam@ravnborg.org, alexander.deucher@amd.com, christian.koenig@amd.com, kraxel@redhat.com, l.stach@pengutronix.de, linux+etnaviv@armlinux.org.uk, christian.gmeiner@gmail.com, inki.dae@samsung.com, jy0922.shim@samsung.com, sw0312.kim@samsung.com, kyungmin.park@samsung.com, kgene@kernel.org, krzk@kernel.org, yuq825@gmail.com, bskeggs@redhat.com, robh@kernel.org, tomeu.vizoso@collabora.com, steven.price@arm.com, alyssa.rosenzweig@collabora.com, hjc@rock-chips.com, heiko@sntech.de, hdegoede@redhat.com, sean@poorly.run, eric@anholt.net, oleksandr_andrushchenko@epam.com, ray.huang@amd.com, sumit.semwal@linaro.org, emil.velikov@collabora.com, luben.tuikov@amd.com, apaneers@amd.com, linus.walleij@linaro.org, melissa.srw@gmail.com, chris@chris-wilson.co.uk, miaoqinglang@huawei.com, dri-devel@lists.freedesktop.org, amd-gfx@lists.freedesktop.org, virtualization@lists.linux-foundation.org, etnaviv@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-samsung-soc@vger.kernel.org, lima@lists.freedesktop.org, nouveau@lists.freedesktop.org, spice-devel@lists.freedesktop.org, linux-rockchip@lists.infradead.org, xen-devel@lists.xenproject.org, linux-media@vger.kernel.org, linaro-mm-sig@lists.linaro.org Subject: Re: [PATCH v5 10/10] drm/fb_helper: Support framebuffers in I/O memory Message-ID: <20201022080534.GT401619@phenom.ffwll.local> References: <20201020122046.31167-1-tzimmermann@suse.de> <20201020122046.31167-11-tzimmermann@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201020122046.31167-11-tzimmermann@suse.de> X-Operating-System: Linux phenom 5.7.0-1-amd64 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org On Tue, Oct 20, 2020 at 02:20:46PM +0200, Thomas Zimmermann wrote: > At least sparc64 requires I/O-specific access to framebuffers. This > patch updates the fbdev console accordingly. > > For drivers with direct access to the framebuffer memory, the callback > functions in struct fb_ops test for the type of memory and call the rsp > fb_sys_ of fb_cfb_ functions. Read and write operations are implemented > internally by DRM's fbdev helper. > > For drivers that employ a shadow buffer, fbdev's blit function retrieves > the framebuffer address as struct dma_buf_map, and uses dma_buf_map > interfaces to access the buffer. > > The bochs driver on sparc64 uses a workaround to flag the framebuffer as > I/O memory and avoid a HW exception. With the introduction of struct > dma_buf_map, this is not required any longer. The patch removes the rsp > code from both, bochs and fbdev. > > v5: > * implement fb_read/fb_write internally (Daniel, Sam) > v4: > * move dma_buf_map changes into separate patch (Daniel) > * TODO list: comment on fbdev updates (Daniel) > > Signed-off-by: Thomas Zimmermann > Tested-by: Sam Ravnborg > --- > Documentation/gpu/todo.rst | 19 ++- > drivers/gpu/drm/bochs/bochs_kms.c | 1 - > drivers/gpu/drm/drm_fb_helper.c | 227 ++++++++++++++++++++++++++++-- > include/drm/drm_mode_config.h | 12 -- > 4 files changed, 230 insertions(+), 29 deletions(-) > > diff --git a/Documentation/gpu/todo.rst b/Documentation/gpu/todo.rst > index 7e6fc3c04add..638b7f704339 100644 > --- a/Documentation/gpu/todo.rst > +++ b/Documentation/gpu/todo.rst > @@ -197,13 +197,28 @@ Convert drivers to use drm_fbdev_generic_setup() > ------------------------------------------------ > > Most drivers can use drm_fbdev_generic_setup(). Driver have to implement > -atomic modesetting and GEM vmap support. Current generic fbdev emulation > -expects the framebuffer in system memory (or system-like memory). > +atomic modesetting and GEM vmap support. Historically, generic fbdev emulation > +expected the framebuffer in system memory or system-like memory. By employing > +struct dma_buf_map, drivers with frambuffers in I/O memory can be supported > +as well. > > Contact: Maintainer of the driver you plan to convert > > Level: Intermediate > > +Reimplement functions in drm_fbdev_fb_ops without fbdev > +------------------------------------------------------- > + > +A number of callback functions in drm_fbdev_fb_ops could benefit from > +being rewritten without dependencies on the fbdev module. Some of the > +helpers could further benefit from using struct dma_buf_map instead of > +raw pointers. > + > +Contact: Thomas Zimmermann , Daniel Vetter > + > +Level: Advanced > + > + > drm_framebuffer_funcs and drm_mode_config_funcs.fb_create cleanup > ----------------------------------------------------------------- > > diff --git a/drivers/gpu/drm/bochs/bochs_kms.c b/drivers/gpu/drm/bochs/bochs_kms.c > index 13d0d04c4457..853081d186d5 100644 > --- a/drivers/gpu/drm/bochs/bochs_kms.c > +++ b/drivers/gpu/drm/bochs/bochs_kms.c > @@ -151,7 +151,6 @@ int bochs_kms_init(struct bochs_device *bochs) > bochs->dev->mode_config.preferred_depth = 24; > bochs->dev->mode_config.prefer_shadow = 0; > bochs->dev->mode_config.prefer_shadow_fbdev = 1; > - bochs->dev->mode_config.fbdev_use_iomem = true; > bochs->dev->mode_config.quirk_addfb_prefer_host_byte_order = true; > > bochs->dev->mode_config.funcs = &bochs_mode_funcs; > diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c > index 6212cd7cde1d..1d3180841778 100644 > --- a/drivers/gpu/drm/drm_fb_helper.c > +++ b/drivers/gpu/drm/drm_fb_helper.c > @@ -372,24 +372,22 @@ static void drm_fb_helper_resume_worker(struct work_struct *work) > } > > static void drm_fb_helper_dirty_blit_real(struct drm_fb_helper *fb_helper, > - struct drm_clip_rect *clip) > + struct drm_clip_rect *clip, > + struct dma_buf_map *dst) > { > struct drm_framebuffer *fb = fb_helper->fb; > unsigned int cpp = fb->format->cpp[0]; > size_t offset = clip->y1 * fb->pitches[0] + clip->x1 * cpp; > void *src = fb_helper->fbdev->screen_buffer + offset; > - void *dst = fb_helper->buffer->map.vaddr + offset; > size_t len = (clip->x2 - clip->x1) * cpp; > unsigned int y; > > - for (y = clip->y1; y < clip->y2; y++) { > - if (!fb_helper->dev->mode_config.fbdev_use_iomem) > - memcpy(dst, src, len); > - else > - memcpy_toio((void __iomem *)dst, src, len); > + dma_buf_map_incr(dst, offset); /* go to first pixel within clip rect */ > > + for (y = clip->y1; y < clip->y2; y++) { > + dma_buf_map_memcpy_to(dst, src, len); > + dma_buf_map_incr(dst, fb->pitches[0]); > src += fb->pitches[0]; > - dst += fb->pitches[0]; > } > } > > @@ -417,8 +415,9 @@ static void drm_fb_helper_dirty_work(struct work_struct *work) > ret = drm_client_buffer_vmap(helper->buffer, &map); > if (ret) > return; > - drm_fb_helper_dirty_blit_real(helper, &clip_copy); > + drm_fb_helper_dirty_blit_real(helper, &clip_copy, &map); > } > + > if (helper->fb->funcs->dirty) > helper->fb->funcs->dirty(helper->fb, NULL, 0, 0, > &clip_copy, 1); > @@ -2027,6 +2026,206 @@ static int drm_fbdev_fb_mmap(struct fb_info *info, struct vm_area_struct *vma) > return -ENODEV; > } > > +static bool drm_fbdev_use_iomem(struct fb_info *info) > +{ > + struct drm_fb_helper *fb_helper = info->par; > + struct drm_client_buffer *buffer = fb_helper->buffer; > + > + return !drm_fbdev_use_shadow_fb(fb_helper) && buffer->map.is_iomem; > +} > + > +static ssize_t fb_read_screen_base(struct fb_info *info, char __user *buf, size_t count, > + loff_t pos) > +{ > + const char __iomem *src = info->screen_base + pos; Maybe a bit much a bikeshed, but I'd write this in terms of drm objects, like the dirty_blit function, using the dma_buf_map (instead of the fb_info parameter). And then instead of screen_base and screen_buffer suffixes give them _mem and _iomem suffixes. Same for write below. Or I'm not quite understanding why we do it like this here - I don't think this code will be used outside of the generic fbdev code, so we can always assume that drm_fb_helper->buffer is set up. The other thing I think we need is some minimal testcases to make sure. The fbtest tool used way back seems to have disappeared, I couldn't find a copy of the source anywhere anymore. With all that: Acked-by: Daniel Vetter Cheers, Daniel > + size_t alloc_size = min(count, PAGE_SIZE); > + ssize_t ret = 0; > + char *tmp; > + > + tmp = kmalloc(alloc_size, GFP_KERNEL); > + if (!tmp) > + return -ENOMEM; > + > + while (count) { > + size_t c = min(count, alloc_size); > + > + memcpy_fromio(tmp, src, c); > + if (copy_to_user(buf, tmp, c)) { > + ret = -EFAULT; > + break; > + } > + > + src += c; > + buf += c; > + ret += c; > + count -= c; > + } > + > + kfree(tmp); > + > + return ret; > +} > + > +static ssize_t fb_read_screen_buffer(struct fb_info *info, char __user *buf, size_t count, > + loff_t pos) > +{ > + const char *src = info->screen_buffer + pos; > + > + if (copy_to_user(buf, src, count)) > + return -EFAULT; > + > + return count; > +} > + > +static ssize_t drm_fbdev_fb_read(struct fb_info *info, char __user *buf, > + size_t count, loff_t *ppos) > +{ > + loff_t pos = *ppos; > + size_t total_size; > + ssize_t ret; > + > + if (info->state != FBINFO_STATE_RUNNING) > + return -EPERM; > + > + if (info->screen_size) > + total_size = info->screen_size; > + else > + total_size = info->fix.smem_len; > + > + if (pos >= total_size) > + return 0; > + if (count >= total_size) > + count = total_size; > + if (total_size - count < pos) > + count = total_size - pos; > + > + if (drm_fbdev_use_iomem(info)) > + ret = fb_read_screen_base(info, buf, count, pos); > + else > + ret = fb_read_screen_buffer(info, buf, count, pos); > + > + if (ret > 0) > + *ppos = ret; > + > + return ret; > +} > + > +static ssize_t fb_write_screen_base(struct fb_info *info, const char __user *buf, size_t count, > + loff_t pos) > +{ > + char __iomem *dst = info->screen_base + pos; > + size_t alloc_size = min(count, PAGE_SIZE); > + ssize_t ret = 0; > + u8 *tmp; > + > + tmp = kmalloc(alloc_size, GFP_KERNEL); > + if (!tmp) > + return -ENOMEM; > + > + while (count) { > + size_t c = min(count, alloc_size); > + > + if (copy_from_user(tmp, buf, c)) { > + ret = -EFAULT; > + break; > + } > + memcpy_toio(dst, tmp, c); > + > + dst += c; > + buf += c; > + ret += c; > + count -= c; > + } > + > + kfree(tmp); > + > + return ret; > +} > + > +static ssize_t fb_write_screen_buffer(struct fb_info *info, const char __user *buf, size_t count, > + loff_t pos) > +{ > + char *dst = info->screen_buffer + pos; > + > + if (copy_from_user(dst, buf, count)) > + return -EFAULT; > + > + return count; > +} > + > +static ssize_t drm_fbdev_fb_write(struct fb_info *info, const char __user *buf, > + size_t count, loff_t *ppos) > +{ > + loff_t pos = *ppos; > + size_t total_size; > + ssize_t ret; > + int err; > + > + if (info->state != FBINFO_STATE_RUNNING) > + return -EPERM; > + > + if (info->screen_size) > + total_size = info->screen_size; > + else > + total_size = info->fix.smem_len; > + > + if (pos > total_size) > + return -EFBIG; > + if (count > total_size) { > + err = -EFBIG; > + count = total_size; > + } > + if (total_size - count < pos) { > + if (!err) > + err = -ENOSPC; > + count = total_size - pos; > + } > + > + /* > + * Copy to framebuffer even if we already logged an error. Emulates > + * the behavior of the original fbdev implementation. > + */ > + if (drm_fbdev_use_iomem(info)) > + ret = fb_write_screen_base(info, buf, count, pos); > + else > + ret = fb_write_screen_buffer(info, buf, count, pos); > + > + if (ret > 0) > + *ppos = ret; > + > + if (err) > + return err; > + > + return ret; > +} > + > +static void drm_fbdev_fb_fillrect(struct fb_info *info, > + const struct fb_fillrect *rect) > +{ > + if (drm_fbdev_use_iomem(info)) > + drm_fb_helper_cfb_fillrect(info, rect); > + else > + drm_fb_helper_sys_fillrect(info, rect); > +} > + > +static void drm_fbdev_fb_copyarea(struct fb_info *info, > + const struct fb_copyarea *area) > +{ > + if (drm_fbdev_use_iomem(info)) > + drm_fb_helper_cfb_copyarea(info, area); > + else > + drm_fb_helper_sys_copyarea(info, area); > +} > + > +static void drm_fbdev_fb_imageblit(struct fb_info *info, > + const struct fb_image *image) > +{ > + if (drm_fbdev_use_iomem(info)) > + drm_fb_helper_cfb_imageblit(info, image); > + else > + drm_fb_helper_sys_imageblit(info, image); > +} > + > static const struct fb_ops drm_fbdev_fb_ops = { > .owner = THIS_MODULE, > DRM_FB_HELPER_DEFAULT_OPS, > @@ -2034,11 +2233,11 @@ static const struct fb_ops drm_fbdev_fb_ops = { > .fb_release = drm_fbdev_fb_release, > .fb_destroy = drm_fbdev_fb_destroy, > .fb_mmap = drm_fbdev_fb_mmap, > - .fb_read = drm_fb_helper_sys_read, > - .fb_write = drm_fb_helper_sys_write, > - .fb_fillrect = drm_fb_helper_sys_fillrect, > - .fb_copyarea = drm_fb_helper_sys_copyarea, > - .fb_imageblit = drm_fb_helper_sys_imageblit, > + .fb_read = drm_fbdev_fb_read, > + .fb_write = drm_fbdev_fb_write, > + .fb_fillrect = drm_fbdev_fb_fillrect, > + .fb_copyarea = drm_fbdev_fb_copyarea, > + .fb_imageblit = drm_fbdev_fb_imageblit, > }; > > static struct fb_deferred_io drm_fbdev_defio = { > diff --git a/include/drm/drm_mode_config.h b/include/drm/drm_mode_config.h > index 5ffbb4ed5b35..ab424ddd7665 100644 > --- a/include/drm/drm_mode_config.h > +++ b/include/drm/drm_mode_config.h > @@ -877,18 +877,6 @@ struct drm_mode_config { > */ > bool prefer_shadow_fbdev; > > - /** > - * @fbdev_use_iomem: > - * > - * Set to true if framebuffer reside in iomem. > - * When set to true memcpy_toio() is used when copying the framebuffer in > - * drm_fb_helper.drm_fb_helper_dirty_blit_real(). > - * > - * FIXME: This should be replaced with a per-mapping is_iomem > - * flag (like ttm does), and then used everywhere in fbdev code. > - */ > - bool fbdev_use_iomem; > - > /** > * @quirk_addfb_prefer_xbgr_30bpp: > * > -- > 2.28.0 > -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch From mboxrd@z Thu Jan 1 00:00:00 1970 From: Daniel Vetter Subject: Re: [PATCH v5 10/10] drm/fb_helper: Support framebuffers in I/O memory Date: Thu, 22 Oct 2020 10:05:34 +0200 Message-ID: <20201022080534.GT401619@phenom.ffwll.local> References: <20201020122046.31167-1-tzimmermann@suse.de> <20201020122046.31167-11-tzimmermann@suse.de> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Content-Disposition: inline In-Reply-To: <20201020122046.31167-11-tzimmermann-l3A5Bk7waGM@public.gmane.org> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: amd-gfx-bounces-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org Sender: "amd-gfx" To: Thomas Zimmermann Cc: luben.tuikov-5C7GfCeVMHo@public.gmane.org, heiko-4mtYJXux2i+zQB+pC5nmwQ@public.gmane.org, airlied-cv59FeDIM0c@public.gmane.org, nouveau-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org, linus.walleij-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org, dri-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org, chris-Y6uKTt2uX1cEflXRtASbqLVCufUGDwFn@public.gmane.org, melissa.srw-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org, eric-WhKQ6XTQaPysTnJN9+BGXg@public.gmane.org, ray.huang-5C7GfCeVMHo@public.gmane.org, kraxel-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org, sam-uyr5N9Q2VtJg9hUCZPvPmw@public.gmane.org, sumit.semwal-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org, emil.velikov-ZGY8ohtN/8qB+jHODAdFcQ@public.gmane.org, robh-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org, linux-samsung-soc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, jy0922.shim-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org, lima-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org, oleksandr_andrushchenko-uRwfk40T5oI@public.gmane.org, krzk-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org, steven.price-5wv7dgnIgG8@public.gmane.org, linux-rockchip-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org, kgene-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org, bskeggs-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org, linux+etnaviv-I+IVW8TIWO2tmTQ+vhA3Yw@public.gmane.org, spice-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org, alyssa.rosenzweig-ZGY8ohtN/8qB+jHODAdFcQ@public.gmane.org, maarten.lankhorst-VuQAYsv1563Yd54FQh9/CA@public.gmane.org, etnaviv-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org, mripard-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org, inki.dae-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org, hdegoede-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org, christian.gmeiner-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org, xen-devel-GuqFBffKawtpuQazS67q72D2FQJk+8+b@public.gmane.org, virtualization@lists List-Id: nouveau.vger.kernel.org On Tue, Oct 20, 2020 at 02:20:46PM +0200, Thomas Zimmermann wrote: > At least sparc64 requires I/O-specific access to framebuffers. This > patch updates the fbdev console accordingly. > > For drivers with direct access to the framebuffer memory, the callback > functions in struct fb_ops test for the type of memory and call the rsp > fb_sys_ of fb_cfb_ functions. Read and write operations are implemented > internally by DRM's fbdev helper. > > For drivers that employ a shadow buffer, fbdev's blit function retrieves > the framebuffer address as struct dma_buf_map, and uses dma_buf_map > interfaces to access the buffer. > > The bochs driver on sparc64 uses a workaround to flag the framebuffer as > I/O memory and avoid a HW exception. With the introduction of struct > dma_buf_map, this is not required any longer. The patch removes the rsp > code from both, bochs and fbdev. > > v5: > * implement fb_read/fb_write internally (Daniel, Sam) > v4: > * move dma_buf_map changes into separate patch (Daniel) > * TODO list: comment on fbdev updates (Daniel) > > Signed-off-by: Thomas Zimmermann > Tested-by: Sam Ravnborg > --- > Documentation/gpu/todo.rst | 19 ++- > drivers/gpu/drm/bochs/bochs_kms.c | 1 - > drivers/gpu/drm/drm_fb_helper.c | 227 ++++++++++++++++++++++++++++-- > include/drm/drm_mode_config.h | 12 -- > 4 files changed, 230 insertions(+), 29 deletions(-) > > diff --git a/Documentation/gpu/todo.rst b/Documentation/gpu/todo.rst > index 7e6fc3c04add..638b7f704339 100644 > --- a/Documentation/gpu/todo.rst > +++ b/Documentation/gpu/todo.rst > @@ -197,13 +197,28 @@ Convert drivers to use drm_fbdev_generic_setup() > ------------------------------------------------ > > Most drivers can use drm_fbdev_generic_setup(). Driver have to implement > -atomic modesetting and GEM vmap support. Current generic fbdev emulation > -expects the framebuffer in system memory (or system-like memory). > +atomic modesetting and GEM vmap support. Historically, generic fbdev emulation > +expected the framebuffer in system memory or system-like memory. By employing > +struct dma_buf_map, drivers with frambuffers in I/O memory can be supported > +as well. > > Contact: Maintainer of the driver you plan to convert > > Level: Intermediate > > +Reimplement functions in drm_fbdev_fb_ops without fbdev > +------------------------------------------------------- > + > +A number of callback functions in drm_fbdev_fb_ops could benefit from > +being rewritten without dependencies on the fbdev module. Some of the > +helpers could further benefit from using struct dma_buf_map instead of > +raw pointers. > + > +Contact: Thomas Zimmermann , Daniel Vetter > + > +Level: Advanced > + > + > drm_framebuffer_funcs and drm_mode_config_funcs.fb_create cleanup > ----------------------------------------------------------------- > > diff --git a/drivers/gpu/drm/bochs/bochs_kms.c b/drivers/gpu/drm/bochs/bochs_kms.c > index 13d0d04c4457..853081d186d5 100644 > --- a/drivers/gpu/drm/bochs/bochs_kms.c > +++ b/drivers/gpu/drm/bochs/bochs_kms.c > @@ -151,7 +151,6 @@ int bochs_kms_init(struct bochs_device *bochs) > bochs->dev->mode_config.preferred_depth = 24; > bochs->dev->mode_config.prefer_shadow = 0; > bochs->dev->mode_config.prefer_shadow_fbdev = 1; > - bochs->dev->mode_config.fbdev_use_iomem = true; > bochs->dev->mode_config.quirk_addfb_prefer_host_byte_order = true; > > bochs->dev->mode_config.funcs = &bochs_mode_funcs; > diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c > index 6212cd7cde1d..1d3180841778 100644 > --- a/drivers/gpu/drm/drm_fb_helper.c > +++ b/drivers/gpu/drm/drm_fb_helper.c > @@ -372,24 +372,22 @@ static void drm_fb_helper_resume_worker(struct work_struct *work) > } > > static void drm_fb_helper_dirty_blit_real(struct drm_fb_helper *fb_helper, > - struct drm_clip_rect *clip) > + struct drm_clip_rect *clip, > + struct dma_buf_map *dst) > { > struct drm_framebuffer *fb = fb_helper->fb; > unsigned int cpp = fb->format->cpp[0]; > size_t offset = clip->y1 * fb->pitches[0] + clip->x1 * cpp; > void *src = fb_helper->fbdev->screen_buffer + offset; > - void *dst = fb_helper->buffer->map.vaddr + offset; > size_t len = (clip->x2 - clip->x1) * cpp; > unsigned int y; > > - for (y = clip->y1; y < clip->y2; y++) { > - if (!fb_helper->dev->mode_config.fbdev_use_iomem) > - memcpy(dst, src, len); > - else > - memcpy_toio((void __iomem *)dst, src, len); > + dma_buf_map_incr(dst, offset); /* go to first pixel within clip rect */ > > + for (y = clip->y1; y < clip->y2; y++) { > + dma_buf_map_memcpy_to(dst, src, len); > + dma_buf_map_incr(dst, fb->pitches[0]); > src += fb->pitches[0]; > - dst += fb->pitches[0]; > } > } > > @@ -417,8 +415,9 @@ static void drm_fb_helper_dirty_work(struct work_struct *work) > ret = drm_client_buffer_vmap(helper->buffer, &map); > if (ret) > return; > - drm_fb_helper_dirty_blit_real(helper, &clip_copy); > + drm_fb_helper_dirty_blit_real(helper, &clip_copy, &map); > } > + > if (helper->fb->funcs->dirty) > helper->fb->funcs->dirty(helper->fb, NULL, 0, 0, > &clip_copy, 1); > @@ -2027,6 +2026,206 @@ static int drm_fbdev_fb_mmap(struct fb_info *info, struct vm_area_struct *vma) > return -ENODEV; > } > > +static bool drm_fbdev_use_iomem(struct fb_info *info) > +{ > + struct drm_fb_helper *fb_helper = info->par; > + struct drm_client_buffer *buffer = fb_helper->buffer; > + > + return !drm_fbdev_use_shadow_fb(fb_helper) && buffer->map.is_iomem; > +} > + > +static ssize_t fb_read_screen_base(struct fb_info *info, char __user *buf, size_t count, > + loff_t pos) > +{ > + const char __iomem *src = info->screen_base + pos; Maybe a bit much a bikeshed, but I'd write this in terms of drm objects, like the dirty_blit function, using the dma_buf_map (instead of the fb_info parameter). And then instead of screen_base and screen_buffer suffixes give them _mem and _iomem suffixes. Same for write below. Or I'm not quite understanding why we do it like this here - I don't think this code will be used outside of the generic fbdev code, so we can always assume that drm_fb_helper->buffer is set up. The other thing I think we need is some minimal testcases to make sure. The fbtest tool used way back seems to have disappeared, I couldn't find a copy of the source anywhere anymore. With all that: Acked-by: Daniel Vetter Cheers, Daniel > + size_t alloc_size = min(count, PAGE_SIZE); > + ssize_t ret = 0; > + char *tmp; > + > + tmp = kmalloc(alloc_size, GFP_KERNEL); > + if (!tmp) > + return -ENOMEM; > + > + while (count) { > + size_t c = min(count, alloc_size); > + > + memcpy_fromio(tmp, src, c); > + if (copy_to_user(buf, tmp, c)) { > + ret = -EFAULT; > + break; > + } > + > + src += c; > + buf += c; > + ret += c; > + count -= c; > + } > + > + kfree(tmp); > + > + return ret; > +} > + > +static ssize_t fb_read_screen_buffer(struct fb_info *info, char __user *buf, size_t count, > + loff_t pos) > +{ > + const char *src = info->screen_buffer + pos; > + > + if (copy_to_user(buf, src, count)) > + return -EFAULT; > + > + return count; > +} > + > +static ssize_t drm_fbdev_fb_read(struct fb_info *info, char __user *buf, > + size_t count, loff_t *ppos) > +{ > + loff_t pos = *ppos; > + size_t total_size; > + ssize_t ret; > + > + if (info->state != FBINFO_STATE_RUNNING) > + return -EPERM; > + > + if (info->screen_size) > + total_size = info->screen_size; > + else > + total_size = info->fix.smem_len; > + > + if (pos >= total_size) > + return 0; > + if (count >= total_size) > + count = total_size; > + if (total_size - count < pos) > + count = total_size - pos; > + > + if (drm_fbdev_use_iomem(info)) > + ret = fb_read_screen_base(info, buf, count, pos); > + else > + ret = fb_read_screen_buffer(info, buf, count, pos); > + > + if (ret > 0) > + *ppos = ret; > + > + return ret; > +} > + > +static ssize_t fb_write_screen_base(struct fb_info *info, const char __user *buf, size_t count, > + loff_t pos) > +{ > + char __iomem *dst = info->screen_base + pos; > + size_t alloc_size = min(count, PAGE_SIZE); > + ssize_t ret = 0; > + u8 *tmp; > + > + tmp = kmalloc(alloc_size, GFP_KERNEL); > + if (!tmp) > + return -ENOMEM; > + > + while (count) { > + size_t c = min(count, alloc_size); > + > + if (copy_from_user(tmp, buf, c)) { > + ret = -EFAULT; > + break; > + } > + memcpy_toio(dst, tmp, c); > + > + dst += c; > + buf += c; > + ret += c; > + count -= c; > + } > + > + kfree(tmp); > + > + return ret; > +} > + > +static ssize_t fb_write_screen_buffer(struct fb_info *info, const char __user *buf, size_t count, > + loff_t pos) > +{ > + char *dst = info->screen_buffer + pos; > + > + if (copy_from_user(dst, buf, count)) > + return -EFAULT; > + > + return count; > +} > + > +static ssize_t drm_fbdev_fb_write(struct fb_info *info, const char __user *buf, > + size_t count, loff_t *ppos) > +{ > + loff_t pos = *ppos; > + size_t total_size; > + ssize_t ret; > + int err; > + > + if (info->state != FBINFO_STATE_RUNNING) > + return -EPERM; > + > + if (info->screen_size) > + total_size = info->screen_size; > + else > + total_size = info->fix.smem_len; > + > + if (pos > total_size) > + return -EFBIG; > + if (count > total_size) { > + err = -EFBIG; > + count = total_size; > + } > + if (total_size - count < pos) { > + if (!err) > + err = -ENOSPC; > + count = total_size - pos; > + } > + > + /* > + * Copy to framebuffer even if we already logged an error. Emulates > + * the behavior of the original fbdev implementation. > + */ > + if (drm_fbdev_use_iomem(info)) > + ret = fb_write_screen_base(info, buf, count, pos); > + else > + ret = fb_write_screen_buffer(info, buf, count, pos); > + > + if (ret > 0) > + *ppos = ret; > + > + if (err) > + return err; > + > + return ret; > +} > + > +static void drm_fbdev_fb_fillrect(struct fb_info *info, > + const struct fb_fillrect *rect) > +{ > + if (drm_fbdev_use_iomem(info)) > + drm_fb_helper_cfb_fillrect(info, rect); > + else > + drm_fb_helper_sys_fillrect(info, rect); > +} > + > +static void drm_fbdev_fb_copyarea(struct fb_info *info, > + const struct fb_copyarea *area) > +{ > + if (drm_fbdev_use_iomem(info)) > + drm_fb_helper_cfb_copyarea(info, area); > + else > + drm_fb_helper_sys_copyarea(info, area); > +} > + > +static void drm_fbdev_fb_imageblit(struct fb_info *info, > + const struct fb_image *image) > +{ > + if (drm_fbdev_use_iomem(info)) > + drm_fb_helper_cfb_imageblit(info, image); > + else > + drm_fb_helper_sys_imageblit(info, image); > +} > + > static const struct fb_ops drm_fbdev_fb_ops = { > .owner = THIS_MODULE, > DRM_FB_HELPER_DEFAULT_OPS, > @@ -2034,11 +2233,11 @@ static const struct fb_ops drm_fbdev_fb_ops = { > .fb_release = drm_fbdev_fb_release, > .fb_destroy = drm_fbdev_fb_destroy, > .fb_mmap = drm_fbdev_fb_mmap, > - .fb_read = drm_fb_helper_sys_read, > - .fb_write = drm_fb_helper_sys_write, > - .fb_fillrect = drm_fb_helper_sys_fillrect, > - .fb_copyarea = drm_fb_helper_sys_copyarea, > - .fb_imageblit = drm_fb_helper_sys_imageblit, > + .fb_read = drm_fbdev_fb_read, > + .fb_write = drm_fbdev_fb_write, > + .fb_fillrect = drm_fbdev_fb_fillrect, > + .fb_copyarea = drm_fbdev_fb_copyarea, > + .fb_imageblit = drm_fbdev_fb_imageblit, > }; > > static struct fb_deferred_io drm_fbdev_defio = { > diff --git a/include/drm/drm_mode_config.h b/include/drm/drm_mode_config.h > index 5ffbb4ed5b35..ab424ddd7665 100644 > --- a/include/drm/drm_mode_config.h > +++ b/include/drm/drm_mode_config.h > @@ -877,18 +877,6 @@ struct drm_mode_config { > */ > bool prefer_shadow_fbdev; > > - /** > - * @fbdev_use_iomem: > - * > - * Set to true if framebuffer reside in iomem. > - * When set to true memcpy_toio() is used when copying the framebuffer in > - * drm_fb_helper.drm_fb_helper_dirty_blit_real(). > - * > - * FIXME: This should be replaced with a per-mapping is_iomem > - * flag (like ttm does), and then used everywhere in fbdev code. > - */ > - bool fbdev_use_iomem; > - > /** > * @quirk_addfb_prefer_xbgr_30bpp: > * > -- > 2.28.0 > -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A6FF4C388F7 for ; Thu, 22 Oct 2020 08:05:49 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 187A422267 for ; Thu, 22 Oct 2020 08:05:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Li4pdd5I"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="LpVtkQQE" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 187A422267 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=aS+PneKAhd2cCMCuQqHezNw7DktPn0pW8+A0OvypWI0=; b=Li4pdd5In0gTrlhmLE2EK2lGr ngUY96wSAOL6LRlrOYENKVrvKzouyCgIG2PUF3oejruObeSmXBjhUND7HhoNpXaVWxadt4lP3Y2uE gwNOPa87ROry9DdhgWjC4hb6BAGikqvMJhz+Wfe5srJ6CWvRSSUve58qB+beXvaMu7AxKqfLBUwH1 Ozuj/9nOB5dGp/ZoiroVlBLTh1nPXxQieF+yP85Ap28BcNOy1UH4TEiR1QEFepIAWpV+vlfwWFz9c Vkeb6jBXoRo6RwyKDHzSjM/t7fERXBR7SbqQ11+Uhm6J0KK2I7tsPdY6oJ8ELsmeRu09w/6ZKrZom 59SJOmxTg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kVVbS-00005n-MZ; Thu, 22 Oct 2020 08:05:42 +0000 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kVVbP-0008WA-JR for linux-rockchip@lists.infradead.org; Thu, 22 Oct 2020 08:05:41 +0000 Received: by mail-wm1-x344.google.com with SMTP id q5so898931wmq.0 for ; Thu, 22 Oct 2020 01:05:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=jo9DObZgd9Jq6ZPonfHxKOsM2RbE9S9o0V4+k1CciSY=; b=LpVtkQQEzDhGLYock7xQGko/zoS3bHGVeS2MwITVSQjnbfP4AMhqamrvOtAFmXYrPu M4rdxuuXfajVAiGf91dIAQUVAfjFyk3TE3h9FLC57hbSTRNI8HSEiW7wSnn833mLl3bT qYQcRr7XPtDbhyfcVfQaWMtP5UWNo6sIUEMEs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=jo9DObZgd9Jq6ZPonfHxKOsM2RbE9S9o0V4+k1CciSY=; b=ZgxLPtBRvkBzwIfmE3el1yXxCf0JTlGb9dWce9FA+Hye6TUkaS/zmGKLFByat7uDnu 2/nY78YYIpSE/ESFNxwCdQL22IMgbMACl0CVVzpU+9Ts2b1y9u4+N/SyvIuQcMCgXnRc q2/1DD+uz7pVTnK5gu3I/GKMzCok8tPGRXS2X9j03BAWdkCSAvS7fIvtH5l8WZbOzTGz nQup2eQWera/hO6v+g61Xv5TtInyrva2b5B7FGVovTwhtTZvvj8qKHaKHRikNTZwVyss PSnyolOKSe3xjnENzdiIx1X6OLObifsMe2o0N8JMsuvXjl7p1kE526lSGr3LsQ0kyJHo sq1g== X-Gm-Message-State: AOAM533x4DnMhEuite/fPmxHVBcbH3emb7cYmA7ZMGyM+95/VutEBVZL w2oBRv4BVHXRjkOM7EGJGJCxGw== X-Google-Smtp-Source: ABdhPJz1mIaxROQHFnkDMtAkyfocV37SNrA+OnkarpcW450fCaDG5+KffMOrvXq4qfjJmhfMWT0ZNg== X-Received: by 2002:a1c:2cc2:: with SMTP id s185mr1359132wms.77.1603353938320; Thu, 22 Oct 2020 01:05:38 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id 32sm2105875wro.31.2020.10.22.01.05.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Oct 2020 01:05:37 -0700 (PDT) Date: Thu, 22 Oct 2020 10:05:34 +0200 From: Daniel Vetter To: Thomas Zimmermann Subject: Re: [PATCH v5 10/10] drm/fb_helper: Support framebuffers in I/O memory Message-ID: <20201022080534.GT401619@phenom.ffwll.local> References: <20201020122046.31167-1-tzimmermann@suse.de> <20201020122046.31167-11-tzimmermann@suse.de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20201020122046.31167-11-tzimmermann@suse.de> X-Operating-System: Linux phenom 5.7.0-1-amd64 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201022_040539_673272_7EE24A52 X-CRM114-Status: GOOD ( 40.84 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: luben.tuikov@amd.com, heiko@sntech.de, airlied@linux.ie, nouveau@lists.freedesktop.org, linus.walleij@linaro.org, dri-devel@lists.freedesktop.org, chris@chris-wilson.co.uk, melissa.srw@gmail.com, eric@anholt.net, ray.huang@amd.com, kraxel@redhat.com, sam@ravnborg.org, sumit.semwal@linaro.org, emil.velikov@collabora.com, robh@kernel.org, linux-samsung-soc@vger.kernel.org, jy0922.shim@samsung.com, lima@lists.freedesktop.org, oleksandr_andrushchenko@epam.com, krzk@kernel.org, steven.price@arm.com, linux-rockchip@lists.infradead.org, kgene@kernel.org, bskeggs@redhat.com, linux+etnaviv@armlinux.org.uk, spice-devel@lists.freedesktop.org, alyssa.rosenzweig@collabora.com, maarten.lankhorst@linux.intel.com, etnaviv@lists.freedesktop.org, mripard@kernel.org, inki.dae@samsung.com, hdegoede@redhat.com, christian.gmeiner@gmail.com, xen-devel@lists.xenproject.org, virtualization@lists.linux-foundation.org, sean@poorly.run, apaneers@amd.com, linux-arm-kernel@lists.infradead.org, linaro-mm-sig@lists.linaro.org, amd-gfx@lists.freedesktop.org, tomeu.vizoso@collabora.com, sw0312.kim@samsung.com, hjc@rock-chips.com, kyungmin.park@samsung.com, miaoqinglang@huawei.com, yuq825@gmail.com, daniel@ffwll.ch, alexander.deucher@amd.com, linux-media@vger.kernel.org, christian.koenig@amd.com, l.stach@pengutronix.de Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org On Tue, Oct 20, 2020 at 02:20:46PM +0200, Thomas Zimmermann wrote: > At least sparc64 requires I/O-specific access to framebuffers. This > patch updates the fbdev console accordingly. > > For drivers with direct access to the framebuffer memory, the callback > functions in struct fb_ops test for the type of memory and call the rsp > fb_sys_ of fb_cfb_ functions. Read and write operations are implemented > internally by DRM's fbdev helper. > > For drivers that employ a shadow buffer, fbdev's blit function retrieves > the framebuffer address as struct dma_buf_map, and uses dma_buf_map > interfaces to access the buffer. > > The bochs driver on sparc64 uses a workaround to flag the framebuffer as > I/O memory and avoid a HW exception. With the introduction of struct > dma_buf_map, this is not required any longer. The patch removes the rsp > code from both, bochs and fbdev. > > v5: > * implement fb_read/fb_write internally (Daniel, Sam) > v4: > * move dma_buf_map changes into separate patch (Daniel) > * TODO list: comment on fbdev updates (Daniel) > > Signed-off-by: Thomas Zimmermann > Tested-by: Sam Ravnborg > --- > Documentation/gpu/todo.rst | 19 ++- > drivers/gpu/drm/bochs/bochs_kms.c | 1 - > drivers/gpu/drm/drm_fb_helper.c | 227 ++++++++++++++++++++++++++++-- > include/drm/drm_mode_config.h | 12 -- > 4 files changed, 230 insertions(+), 29 deletions(-) > > diff --git a/Documentation/gpu/todo.rst b/Documentation/gpu/todo.rst > index 7e6fc3c04add..638b7f704339 100644 > --- a/Documentation/gpu/todo.rst > +++ b/Documentation/gpu/todo.rst > @@ -197,13 +197,28 @@ Convert drivers to use drm_fbdev_generic_setup() > ------------------------------------------------ > > Most drivers can use drm_fbdev_generic_setup(). Driver have to implement > -atomic modesetting and GEM vmap support. Current generic fbdev emulation > -expects the framebuffer in system memory (or system-like memory). > +atomic modesetting and GEM vmap support. Historically, generic fbdev emulation > +expected the framebuffer in system memory or system-like memory. By employing > +struct dma_buf_map, drivers with frambuffers in I/O memory can be supported > +as well. > > Contact: Maintainer of the driver you plan to convert > > Level: Intermediate > > +Reimplement functions in drm_fbdev_fb_ops without fbdev > +------------------------------------------------------- > + > +A number of callback functions in drm_fbdev_fb_ops could benefit from > +being rewritten without dependencies on the fbdev module. Some of the > +helpers could further benefit from using struct dma_buf_map instead of > +raw pointers. > + > +Contact: Thomas Zimmermann , Daniel Vetter > + > +Level: Advanced > + > + > drm_framebuffer_funcs and drm_mode_config_funcs.fb_create cleanup > ----------------------------------------------------------------- > > diff --git a/drivers/gpu/drm/bochs/bochs_kms.c b/drivers/gpu/drm/bochs/bochs_kms.c > index 13d0d04c4457..853081d186d5 100644 > --- a/drivers/gpu/drm/bochs/bochs_kms.c > +++ b/drivers/gpu/drm/bochs/bochs_kms.c > @@ -151,7 +151,6 @@ int bochs_kms_init(struct bochs_device *bochs) > bochs->dev->mode_config.preferred_depth = 24; > bochs->dev->mode_config.prefer_shadow = 0; > bochs->dev->mode_config.prefer_shadow_fbdev = 1; > - bochs->dev->mode_config.fbdev_use_iomem = true; > bochs->dev->mode_config.quirk_addfb_prefer_host_byte_order = true; > > bochs->dev->mode_config.funcs = &bochs_mode_funcs; > diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c > index 6212cd7cde1d..1d3180841778 100644 > --- a/drivers/gpu/drm/drm_fb_helper.c > +++ b/drivers/gpu/drm/drm_fb_helper.c > @@ -372,24 +372,22 @@ static void drm_fb_helper_resume_worker(struct work_struct *work) > } > > static void drm_fb_helper_dirty_blit_real(struct drm_fb_helper *fb_helper, > - struct drm_clip_rect *clip) > + struct drm_clip_rect *clip, > + struct dma_buf_map *dst) > { > struct drm_framebuffer *fb = fb_helper->fb; > unsigned int cpp = fb->format->cpp[0]; > size_t offset = clip->y1 * fb->pitches[0] + clip->x1 * cpp; > void *src = fb_helper->fbdev->screen_buffer + offset; > - void *dst = fb_helper->buffer->map.vaddr + offset; > size_t len = (clip->x2 - clip->x1) * cpp; > unsigned int y; > > - for (y = clip->y1; y < clip->y2; y++) { > - if (!fb_helper->dev->mode_config.fbdev_use_iomem) > - memcpy(dst, src, len); > - else > - memcpy_toio((void __iomem *)dst, src, len); > + dma_buf_map_incr(dst, offset); /* go to first pixel within clip rect */ > > + for (y = clip->y1; y < clip->y2; y++) { > + dma_buf_map_memcpy_to(dst, src, len); > + dma_buf_map_incr(dst, fb->pitches[0]); > src += fb->pitches[0]; > - dst += fb->pitches[0]; > } > } > > @@ -417,8 +415,9 @@ static void drm_fb_helper_dirty_work(struct work_struct *work) > ret = drm_client_buffer_vmap(helper->buffer, &map); > if (ret) > return; > - drm_fb_helper_dirty_blit_real(helper, &clip_copy); > + drm_fb_helper_dirty_blit_real(helper, &clip_copy, &map); > } > + > if (helper->fb->funcs->dirty) > helper->fb->funcs->dirty(helper->fb, NULL, 0, 0, > &clip_copy, 1); > @@ -2027,6 +2026,206 @@ static int drm_fbdev_fb_mmap(struct fb_info *info, struct vm_area_struct *vma) > return -ENODEV; > } > > +static bool drm_fbdev_use_iomem(struct fb_info *info) > +{ > + struct drm_fb_helper *fb_helper = info->par; > + struct drm_client_buffer *buffer = fb_helper->buffer; > + > + return !drm_fbdev_use_shadow_fb(fb_helper) && buffer->map.is_iomem; > +} > + > +static ssize_t fb_read_screen_base(struct fb_info *info, char __user *buf, size_t count, > + loff_t pos) > +{ > + const char __iomem *src = info->screen_base + pos; Maybe a bit much a bikeshed, but I'd write this in terms of drm objects, like the dirty_blit function, using the dma_buf_map (instead of the fb_info parameter). And then instead of screen_base and screen_buffer suffixes give them _mem and _iomem suffixes. Same for write below. Or I'm not quite understanding why we do it like this here - I don't think this code will be used outside of the generic fbdev code, so we can always assume that drm_fb_helper->buffer is set up. The other thing I think we need is some minimal testcases to make sure. The fbtest tool used way back seems to have disappeared, I couldn't find a copy of the source anywhere anymore. With all that: Acked-by: Daniel Vetter Cheers, Daniel > + size_t alloc_size = min(count, PAGE_SIZE); > + ssize_t ret = 0; > + char *tmp; > + > + tmp = kmalloc(alloc_size, GFP_KERNEL); > + if (!tmp) > + return -ENOMEM; > + > + while (count) { > + size_t c = min(count, alloc_size); > + > + memcpy_fromio(tmp, src, c); > + if (copy_to_user(buf, tmp, c)) { > + ret = -EFAULT; > + break; > + } > + > + src += c; > + buf += c; > + ret += c; > + count -= c; > + } > + > + kfree(tmp); > + > + return ret; > +} > + > +static ssize_t fb_read_screen_buffer(struct fb_info *info, char __user *buf, size_t count, > + loff_t pos) > +{ > + const char *src = info->screen_buffer + pos; > + > + if (copy_to_user(buf, src, count)) > + return -EFAULT; > + > + return count; > +} > + > +static ssize_t drm_fbdev_fb_read(struct fb_info *info, char __user *buf, > + size_t count, loff_t *ppos) > +{ > + loff_t pos = *ppos; > + size_t total_size; > + ssize_t ret; > + > + if (info->state != FBINFO_STATE_RUNNING) > + return -EPERM; > + > + if (info->screen_size) > + total_size = info->screen_size; > + else > + total_size = info->fix.smem_len; > + > + if (pos >= total_size) > + return 0; > + if (count >= total_size) > + count = total_size; > + if (total_size - count < pos) > + count = total_size - pos; > + > + if (drm_fbdev_use_iomem(info)) > + ret = fb_read_screen_base(info, buf, count, pos); > + else > + ret = fb_read_screen_buffer(info, buf, count, pos); > + > + if (ret > 0) > + *ppos = ret; > + > + return ret; > +} > + > +static ssize_t fb_write_screen_base(struct fb_info *info, const char __user *buf, size_t count, > + loff_t pos) > +{ > + char __iomem *dst = info->screen_base + pos; > + size_t alloc_size = min(count, PAGE_SIZE); > + ssize_t ret = 0; > + u8 *tmp; > + > + tmp = kmalloc(alloc_size, GFP_KERNEL); > + if (!tmp) > + return -ENOMEM; > + > + while (count) { > + size_t c = min(count, alloc_size); > + > + if (copy_from_user(tmp, buf, c)) { > + ret = -EFAULT; > + break; > + } > + memcpy_toio(dst, tmp, c); > + > + dst += c; > + buf += c; > + ret += c; > + count -= c; > + } > + > + kfree(tmp); > + > + return ret; > +} > + > +static ssize_t fb_write_screen_buffer(struct fb_info *info, const char __user *buf, size_t count, > + loff_t pos) > +{ > + char *dst = info->screen_buffer + pos; > + > + if (copy_from_user(dst, buf, count)) > + return -EFAULT; > + > + return count; > +} > + > +static ssize_t drm_fbdev_fb_write(struct fb_info *info, const char __user *buf, > + size_t count, loff_t *ppos) > +{ > + loff_t pos = *ppos; > + size_t total_size; > + ssize_t ret; > + int err; > + > + if (info->state != FBINFO_STATE_RUNNING) > + return -EPERM; > + > + if (info->screen_size) > + total_size = info->screen_size; > + else > + total_size = info->fix.smem_len; > + > + if (pos > total_size) > + return -EFBIG; > + if (count > total_size) { > + err = -EFBIG; > + count = total_size; > + } > + if (total_size - count < pos) { > + if (!err) > + err = -ENOSPC; > + count = total_size - pos; > + } > + > + /* > + * Copy to framebuffer even if we already logged an error. Emulates > + * the behavior of the original fbdev implementation. > + */ > + if (drm_fbdev_use_iomem(info)) > + ret = fb_write_screen_base(info, buf, count, pos); > + else > + ret = fb_write_screen_buffer(info, buf, count, pos); > + > + if (ret > 0) > + *ppos = ret; > + > + if (err) > + return err; > + > + return ret; > +} > + > +static void drm_fbdev_fb_fillrect(struct fb_info *info, > + const struct fb_fillrect *rect) > +{ > + if (drm_fbdev_use_iomem(info)) > + drm_fb_helper_cfb_fillrect(info, rect); > + else > + drm_fb_helper_sys_fillrect(info, rect); > +} > + > +static void drm_fbdev_fb_copyarea(struct fb_info *info, > + const struct fb_copyarea *area) > +{ > + if (drm_fbdev_use_iomem(info)) > + drm_fb_helper_cfb_copyarea(info, area); > + else > + drm_fb_helper_sys_copyarea(info, area); > +} > + > +static void drm_fbdev_fb_imageblit(struct fb_info *info, > + const struct fb_image *image) > +{ > + if (drm_fbdev_use_iomem(info)) > + drm_fb_helper_cfb_imageblit(info, image); > + else > + drm_fb_helper_sys_imageblit(info, image); > +} > + > static const struct fb_ops drm_fbdev_fb_ops = { > .owner = THIS_MODULE, > DRM_FB_HELPER_DEFAULT_OPS, > @@ -2034,11 +2233,11 @@ static const struct fb_ops drm_fbdev_fb_ops = { > .fb_release = drm_fbdev_fb_release, > .fb_destroy = drm_fbdev_fb_destroy, > .fb_mmap = drm_fbdev_fb_mmap, > - .fb_read = drm_fb_helper_sys_read, > - .fb_write = drm_fb_helper_sys_write, > - .fb_fillrect = drm_fb_helper_sys_fillrect, > - .fb_copyarea = drm_fb_helper_sys_copyarea, > - .fb_imageblit = drm_fb_helper_sys_imageblit, > + .fb_read = drm_fbdev_fb_read, > + .fb_write = drm_fbdev_fb_write, > + .fb_fillrect = drm_fbdev_fb_fillrect, > + .fb_copyarea = drm_fbdev_fb_copyarea, > + .fb_imageblit = drm_fbdev_fb_imageblit, > }; > > static struct fb_deferred_io drm_fbdev_defio = { > diff --git a/include/drm/drm_mode_config.h b/include/drm/drm_mode_config.h > index 5ffbb4ed5b35..ab424ddd7665 100644 > --- a/include/drm/drm_mode_config.h > +++ b/include/drm/drm_mode_config.h > @@ -877,18 +877,6 @@ struct drm_mode_config { > */ > bool prefer_shadow_fbdev; > > - /** > - * @fbdev_use_iomem: > - * > - * Set to true if framebuffer reside in iomem. > - * When set to true memcpy_toio() is used when copying the framebuffer in > - * drm_fb_helper.drm_fb_helper_dirty_blit_real(). > - * > - * FIXME: This should be replaced with a per-mapping is_iomem > - * flag (like ttm does), and then used everywhere in fbdev code. > - */ > - bool fbdev_use_iomem; > - > /** > * @quirk_addfb_prefer_xbgr_30bpp: > * > -- > 2.28.0 > -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ Linux-rockchip mailing list Linux-rockchip@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-rockchip From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0F307C4363A for ; Thu, 22 Oct 2020 08:05:48 +0000 (UTC) Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3009C22267 for ; Thu, 22 Oct 2020 08:05:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="LpVtkQQE" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3009C22267 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=virtualization-bounces@lists.linux-foundation.org Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id A8D7186D36; Thu, 22 Oct 2020 08:05:46 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id cqVUfN-kwOtj; Thu, 22 Oct 2020 08:05:45 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by fraxinus.osuosl.org (Postfix) with ESMTP id 5643986A1D; Thu, 22 Oct 2020 08:05:45 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 20B00C08A1; Thu, 22 Oct 2020 08:05:45 +0000 (UTC) Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id E8584C0052 for ; Thu, 22 Oct 2020 08:05:42 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id D1A8D204B0 for ; Thu, 22 Oct 2020 08:05:42 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id cs6eJ+aRQKRg for ; Thu, 22 Oct 2020 08:05:40 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by silver.osuosl.org (Postfix) with ESMTPS id 39C60204AC for ; Thu, 22 Oct 2020 08:05:40 +0000 (UTC) Received: by mail-wm1-f65.google.com with SMTP id v5so890841wmh.1 for ; Thu, 22 Oct 2020 01:05:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=jo9DObZgd9Jq6ZPonfHxKOsM2RbE9S9o0V4+k1CciSY=; b=LpVtkQQEzDhGLYock7xQGko/zoS3bHGVeS2MwITVSQjnbfP4AMhqamrvOtAFmXYrPu M4rdxuuXfajVAiGf91dIAQUVAfjFyk3TE3h9FLC57hbSTRNI8HSEiW7wSnn833mLl3bT qYQcRr7XPtDbhyfcVfQaWMtP5UWNo6sIUEMEs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=jo9DObZgd9Jq6ZPonfHxKOsM2RbE9S9o0V4+k1CciSY=; b=BBgqqrlCyLEsirlFgVjKsXHNYpJqlPNbt1oPloOW/d74hKCHoUqPWUe34zGa3+zTeg 51SlwRZ1u2jqwWh706RCiaZLxIZkySFgz7uwN4+v++cGGvyIORbjhPq5znnwaE6eGZgJ E3MMKKoir7T9bOKlGPqEqM47S1D0xPiZLWJHBNqQj1t76iTIXQeDd1gK9t9ZCKpOemwW ktvnxRR1uTsG+Z8Gtqt5Faeqd2XbKouOInyle0AKDOa2B6YI/PehHee7kOH5jQLjUHY6 9azFhxpQUjYLXdyR6E/SKOxEeAiKIx8YAYUJik6qepDjaWexf2iZ1hQfVn01IFC2n58R 59VQ== X-Gm-Message-State: AOAM532W1i6y9qXbjInR8FiysIpaYbx+yIGFQ6BwDhYpkty1SMBq0Mn7 eTeLhRP+vYL0y126ch5tQDoCtw== X-Google-Smtp-Source: ABdhPJz1mIaxROQHFnkDMtAkyfocV37SNrA+OnkarpcW450fCaDG5+KffMOrvXq4qfjJmhfMWT0ZNg== X-Received: by 2002:a1c:2cc2:: with SMTP id s185mr1359132wms.77.1603353938320; Thu, 22 Oct 2020 01:05:38 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id 32sm2105875wro.31.2020.10.22.01.05.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Oct 2020 01:05:37 -0700 (PDT) Date: Thu, 22 Oct 2020 10:05:34 +0200 From: Daniel Vetter To: Thomas Zimmermann Subject: Re: [PATCH v5 10/10] drm/fb_helper: Support framebuffers in I/O memory Message-ID: <20201022080534.GT401619@phenom.ffwll.local> References: <20201020122046.31167-1-tzimmermann@suse.de> <20201020122046.31167-11-tzimmermann@suse.de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20201020122046.31167-11-tzimmermann@suse.de> X-Operating-System: Linux phenom 5.7.0-1-amd64 Cc: luben.tuikov@amd.com, heiko@sntech.de, airlied@linux.ie, nouveau@lists.freedesktop.org, linus.walleij@linaro.org, dri-devel@lists.freedesktop.org, chris@chris-wilson.co.uk, melissa.srw@gmail.com, eric@anholt.net, ray.huang@amd.com, sam@ravnborg.org, sumit.semwal@linaro.org, emil.velikov@collabora.com, robh@kernel.org, linux-samsung-soc@vger.kernel.org, jy0922.shim@samsung.com, lima@lists.freedesktop.org, oleksandr_andrushchenko@epam.com, krzk@kernel.org, steven.price@arm.com, linux-rockchip@lists.infradead.org, kgene@kernel.org, bskeggs@redhat.com, linux+etnaviv@armlinux.org.uk, spice-devel@lists.freedesktop.org, alyssa.rosenzweig@collabora.com, maarten.lankhorst@linux.intel.com, etnaviv@lists.freedesktop.org, mripard@kernel.org, inki.dae@samsung.com, hdegoede@redhat.com, christian.gmeiner@gmail.com, xen-devel@lists.xenproject.org, virtualization@lists.linux-foundation.org, sean@poorly.run, apaneers@amd.com, linux-arm-kernel@lists.infradead.org, linaro-mm-sig@lists.linaro.org, amd-gfx@lists.freedesktop.org, tomeu.vizoso@collabora.com, sw0312.kim@samsung.com, hjc@rock-chips.com, kyungmin.park@samsung.com, miaoqinglang@huawei.com, yuq825@gmail.com, daniel@ffwll.ch, alexander.deucher@amd.com, linux-media@vger.kernel.org, christian.koenig@amd.com, l.stach@pengutronix.de X-BeenThere: virtualization@lists.linux-foundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Linux virtualization List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: virtualization-bounces@lists.linux-foundation.org Sender: "Virtualization" On Tue, Oct 20, 2020 at 02:20:46PM +0200, Thomas Zimmermann wrote: > At least sparc64 requires I/O-specific access to framebuffers. This > patch updates the fbdev console accordingly. > > For drivers with direct access to the framebuffer memory, the callback > functions in struct fb_ops test for the type of memory and call the rsp > fb_sys_ of fb_cfb_ functions. Read and write operations are implemented > internally by DRM's fbdev helper. > > For drivers that employ a shadow buffer, fbdev's blit function retrieves > the framebuffer address as struct dma_buf_map, and uses dma_buf_map > interfaces to access the buffer. > > The bochs driver on sparc64 uses a workaround to flag the framebuffer as > I/O memory and avoid a HW exception. With the introduction of struct > dma_buf_map, this is not required any longer. The patch removes the rsp > code from both, bochs and fbdev. > > v5: > * implement fb_read/fb_write internally (Daniel, Sam) > v4: > * move dma_buf_map changes into separate patch (Daniel) > * TODO list: comment on fbdev updates (Daniel) > > Signed-off-by: Thomas Zimmermann > Tested-by: Sam Ravnborg > --- > Documentation/gpu/todo.rst | 19 ++- > drivers/gpu/drm/bochs/bochs_kms.c | 1 - > drivers/gpu/drm/drm_fb_helper.c | 227 ++++++++++++++++++++++++++++-- > include/drm/drm_mode_config.h | 12 -- > 4 files changed, 230 insertions(+), 29 deletions(-) > > diff --git a/Documentation/gpu/todo.rst b/Documentation/gpu/todo.rst > index 7e6fc3c04add..638b7f704339 100644 > --- a/Documentation/gpu/todo.rst > +++ b/Documentation/gpu/todo.rst > @@ -197,13 +197,28 @@ Convert drivers to use drm_fbdev_generic_setup() > ------------------------------------------------ > > Most drivers can use drm_fbdev_generic_setup(). Driver have to implement > -atomic modesetting and GEM vmap support. Current generic fbdev emulation > -expects the framebuffer in system memory (or system-like memory). > +atomic modesetting and GEM vmap support. Historically, generic fbdev emulation > +expected the framebuffer in system memory or system-like memory. By employing > +struct dma_buf_map, drivers with frambuffers in I/O memory can be supported > +as well. > > Contact: Maintainer of the driver you plan to convert > > Level: Intermediate > > +Reimplement functions in drm_fbdev_fb_ops without fbdev > +------------------------------------------------------- > + > +A number of callback functions in drm_fbdev_fb_ops could benefit from > +being rewritten without dependencies on the fbdev module. Some of the > +helpers could further benefit from using struct dma_buf_map instead of > +raw pointers. > + > +Contact: Thomas Zimmermann , Daniel Vetter > + > +Level: Advanced > + > + > drm_framebuffer_funcs and drm_mode_config_funcs.fb_create cleanup > ----------------------------------------------------------------- > > diff --git a/drivers/gpu/drm/bochs/bochs_kms.c b/drivers/gpu/drm/bochs/bochs_kms.c > index 13d0d04c4457..853081d186d5 100644 > --- a/drivers/gpu/drm/bochs/bochs_kms.c > +++ b/drivers/gpu/drm/bochs/bochs_kms.c > @@ -151,7 +151,6 @@ int bochs_kms_init(struct bochs_device *bochs) > bochs->dev->mode_config.preferred_depth = 24; > bochs->dev->mode_config.prefer_shadow = 0; > bochs->dev->mode_config.prefer_shadow_fbdev = 1; > - bochs->dev->mode_config.fbdev_use_iomem = true; > bochs->dev->mode_config.quirk_addfb_prefer_host_byte_order = true; > > bochs->dev->mode_config.funcs = &bochs_mode_funcs; > diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c > index 6212cd7cde1d..1d3180841778 100644 > --- a/drivers/gpu/drm/drm_fb_helper.c > +++ b/drivers/gpu/drm/drm_fb_helper.c > @@ -372,24 +372,22 @@ static void drm_fb_helper_resume_worker(struct work_struct *work) > } > > static void drm_fb_helper_dirty_blit_real(struct drm_fb_helper *fb_helper, > - struct drm_clip_rect *clip) > + struct drm_clip_rect *clip, > + struct dma_buf_map *dst) > { > struct drm_framebuffer *fb = fb_helper->fb; > unsigned int cpp = fb->format->cpp[0]; > size_t offset = clip->y1 * fb->pitches[0] + clip->x1 * cpp; > void *src = fb_helper->fbdev->screen_buffer + offset; > - void *dst = fb_helper->buffer->map.vaddr + offset; > size_t len = (clip->x2 - clip->x1) * cpp; > unsigned int y; > > - for (y = clip->y1; y < clip->y2; y++) { > - if (!fb_helper->dev->mode_config.fbdev_use_iomem) > - memcpy(dst, src, len); > - else > - memcpy_toio((void __iomem *)dst, src, len); > + dma_buf_map_incr(dst, offset); /* go to first pixel within clip rect */ > > + for (y = clip->y1; y < clip->y2; y++) { > + dma_buf_map_memcpy_to(dst, src, len); > + dma_buf_map_incr(dst, fb->pitches[0]); > src += fb->pitches[0]; > - dst += fb->pitches[0]; > } > } > > @@ -417,8 +415,9 @@ static void drm_fb_helper_dirty_work(struct work_struct *work) > ret = drm_client_buffer_vmap(helper->buffer, &map); > if (ret) > return; > - drm_fb_helper_dirty_blit_real(helper, &clip_copy); > + drm_fb_helper_dirty_blit_real(helper, &clip_copy, &map); > } > + > if (helper->fb->funcs->dirty) > helper->fb->funcs->dirty(helper->fb, NULL, 0, 0, > &clip_copy, 1); > @@ -2027,6 +2026,206 @@ static int drm_fbdev_fb_mmap(struct fb_info *info, struct vm_area_struct *vma) > return -ENODEV; > } > > +static bool drm_fbdev_use_iomem(struct fb_info *info) > +{ > + struct drm_fb_helper *fb_helper = info->par; > + struct drm_client_buffer *buffer = fb_helper->buffer; > + > + return !drm_fbdev_use_shadow_fb(fb_helper) && buffer->map.is_iomem; > +} > + > +static ssize_t fb_read_screen_base(struct fb_info *info, char __user *buf, size_t count, > + loff_t pos) > +{ > + const char __iomem *src = info->screen_base + pos; Maybe a bit much a bikeshed, but I'd write this in terms of drm objects, like the dirty_blit function, using the dma_buf_map (instead of the fb_info parameter). And then instead of screen_base and screen_buffer suffixes give them _mem and _iomem suffixes. Same for write below. Or I'm not quite understanding why we do it like this here - I don't think this code will be used outside of the generic fbdev code, so we can always assume that drm_fb_helper->buffer is set up. The other thing I think we need is some minimal testcases to make sure. The fbtest tool used way back seems to have disappeared, I couldn't find a copy of the source anywhere anymore. With all that: Acked-by: Daniel Vetter Cheers, Daniel > + size_t alloc_size = min(count, PAGE_SIZE); > + ssize_t ret = 0; > + char *tmp; > + > + tmp = kmalloc(alloc_size, GFP_KERNEL); > + if (!tmp) > + return -ENOMEM; > + > + while (count) { > + size_t c = min(count, alloc_size); > + > + memcpy_fromio(tmp, src, c); > + if (copy_to_user(buf, tmp, c)) { > + ret = -EFAULT; > + break; > + } > + > + src += c; > + buf += c; > + ret += c; > + count -= c; > + } > + > + kfree(tmp); > + > + return ret; > +} > + > +static ssize_t fb_read_screen_buffer(struct fb_info *info, char __user *buf, size_t count, > + loff_t pos) > +{ > + const char *src = info->screen_buffer + pos; > + > + if (copy_to_user(buf, src, count)) > + return -EFAULT; > + > + return count; > +} > + > +static ssize_t drm_fbdev_fb_read(struct fb_info *info, char __user *buf, > + size_t count, loff_t *ppos) > +{ > + loff_t pos = *ppos; > + size_t total_size; > + ssize_t ret; > + > + if (info->state != FBINFO_STATE_RUNNING) > + return -EPERM; > + > + if (info->screen_size) > + total_size = info->screen_size; > + else > + total_size = info->fix.smem_len; > + > + if (pos >= total_size) > + return 0; > + if (count >= total_size) > + count = total_size; > + if (total_size - count < pos) > + count = total_size - pos; > + > + if (drm_fbdev_use_iomem(info)) > + ret = fb_read_screen_base(info, buf, count, pos); > + else > + ret = fb_read_screen_buffer(info, buf, count, pos); > + > + if (ret > 0) > + *ppos = ret; > + > + return ret; > +} > + > +static ssize_t fb_write_screen_base(struct fb_info *info, const char __user *buf, size_t count, > + loff_t pos) > +{ > + char __iomem *dst = info->screen_base + pos; > + size_t alloc_size = min(count, PAGE_SIZE); > + ssize_t ret = 0; > + u8 *tmp; > + > + tmp = kmalloc(alloc_size, GFP_KERNEL); > + if (!tmp) > + return -ENOMEM; > + > + while (count) { > + size_t c = min(count, alloc_size); > + > + if (copy_from_user(tmp, buf, c)) { > + ret = -EFAULT; > + break; > + } > + memcpy_toio(dst, tmp, c); > + > + dst += c; > + buf += c; > + ret += c; > + count -= c; > + } > + > + kfree(tmp); > + > + return ret; > +} > + > +static ssize_t fb_write_screen_buffer(struct fb_info *info, const char __user *buf, size_t count, > + loff_t pos) > +{ > + char *dst = info->screen_buffer + pos; > + > + if (copy_from_user(dst, buf, count)) > + return -EFAULT; > + > + return count; > +} > + > +static ssize_t drm_fbdev_fb_write(struct fb_info *info, const char __user *buf, > + size_t count, loff_t *ppos) > +{ > + loff_t pos = *ppos; > + size_t total_size; > + ssize_t ret; > + int err; > + > + if (info->state != FBINFO_STATE_RUNNING) > + return -EPERM; > + > + if (info->screen_size) > + total_size = info->screen_size; > + else > + total_size = info->fix.smem_len; > + > + if (pos > total_size) > + return -EFBIG; > + if (count > total_size) { > + err = -EFBIG; > + count = total_size; > + } > + if (total_size - count < pos) { > + if (!err) > + err = -ENOSPC; > + count = total_size - pos; > + } > + > + /* > + * Copy to framebuffer even if we already logged an error. Emulates > + * the behavior of the original fbdev implementation. > + */ > + if (drm_fbdev_use_iomem(info)) > + ret = fb_write_screen_base(info, buf, count, pos); > + else > + ret = fb_write_screen_buffer(info, buf, count, pos); > + > + if (ret > 0) > + *ppos = ret; > + > + if (err) > + return err; > + > + return ret; > +} > + > +static void drm_fbdev_fb_fillrect(struct fb_info *info, > + const struct fb_fillrect *rect) > +{ > + if (drm_fbdev_use_iomem(info)) > + drm_fb_helper_cfb_fillrect(info, rect); > + else > + drm_fb_helper_sys_fillrect(info, rect); > +} > + > +static void drm_fbdev_fb_copyarea(struct fb_info *info, > + const struct fb_copyarea *area) > +{ > + if (drm_fbdev_use_iomem(info)) > + drm_fb_helper_cfb_copyarea(info, area); > + else > + drm_fb_helper_sys_copyarea(info, area); > +} > + > +static void drm_fbdev_fb_imageblit(struct fb_info *info, > + const struct fb_image *image) > +{ > + if (drm_fbdev_use_iomem(info)) > + drm_fb_helper_cfb_imageblit(info, image); > + else > + drm_fb_helper_sys_imageblit(info, image); > +} > + > static const struct fb_ops drm_fbdev_fb_ops = { > .owner = THIS_MODULE, > DRM_FB_HELPER_DEFAULT_OPS, > @@ -2034,11 +2233,11 @@ static const struct fb_ops drm_fbdev_fb_ops = { > .fb_release = drm_fbdev_fb_release, > .fb_destroy = drm_fbdev_fb_destroy, > .fb_mmap = drm_fbdev_fb_mmap, > - .fb_read = drm_fb_helper_sys_read, > - .fb_write = drm_fb_helper_sys_write, > - .fb_fillrect = drm_fb_helper_sys_fillrect, > - .fb_copyarea = drm_fb_helper_sys_copyarea, > - .fb_imageblit = drm_fb_helper_sys_imageblit, > + .fb_read = drm_fbdev_fb_read, > + .fb_write = drm_fbdev_fb_write, > + .fb_fillrect = drm_fbdev_fb_fillrect, > + .fb_copyarea = drm_fbdev_fb_copyarea, > + .fb_imageblit = drm_fbdev_fb_imageblit, > }; > > static struct fb_deferred_io drm_fbdev_defio = { > diff --git a/include/drm/drm_mode_config.h b/include/drm/drm_mode_config.h > index 5ffbb4ed5b35..ab424ddd7665 100644 > --- a/include/drm/drm_mode_config.h > +++ b/include/drm/drm_mode_config.h > @@ -877,18 +877,6 @@ struct drm_mode_config { > */ > bool prefer_shadow_fbdev; > > - /** > - * @fbdev_use_iomem: > - * > - * Set to true if framebuffer reside in iomem. > - * When set to true memcpy_toio() is used when copying the framebuffer in > - * drm_fb_helper.drm_fb_helper_dirty_blit_real(). > - * > - * FIXME: This should be replaced with a per-mapping is_iomem > - * flag (like ttm does), and then used everywhere in fbdev code. > - */ > - bool fbdev_use_iomem; > - > /** > * @quirk_addfb_prefer_xbgr_30bpp: > * > -- > 2.28.0 > -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 18BEFC388F2 for ; Thu, 22 Oct 2020 08:05:45 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 44D1322267 for ; Thu, 22 Oct 2020 08:05:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="LpVtkQQE" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 44D1322267 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 79CC36F53D; Thu, 22 Oct 2020 08:05:41 +0000 (UTC) Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by gabe.freedesktop.org (Postfix) with ESMTPS id C74726F53B for ; Thu, 22 Oct 2020 08:05:39 +0000 (UTC) Received: by mail-wm1-x343.google.com with SMTP id 13so895511wmf.0 for ; Thu, 22 Oct 2020 01:05:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=jo9DObZgd9Jq6ZPonfHxKOsM2RbE9S9o0V4+k1CciSY=; b=LpVtkQQEzDhGLYock7xQGko/zoS3bHGVeS2MwITVSQjnbfP4AMhqamrvOtAFmXYrPu M4rdxuuXfajVAiGf91dIAQUVAfjFyk3TE3h9FLC57hbSTRNI8HSEiW7wSnn833mLl3bT qYQcRr7XPtDbhyfcVfQaWMtP5UWNo6sIUEMEs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=jo9DObZgd9Jq6ZPonfHxKOsM2RbE9S9o0V4+k1CciSY=; b=ca+fLIr+Yl83WJDo6QP5rXu4oCm4I7p2aZ/OiR2g8PjQNKxqlW84OIMRiuu+4ChpI1 shuGaICH7VaEi9gWkAD8YZb3PBL848SCZENHmSM+eN4YyO2A2w66ykr47IpGi7fpIChp 96tYjADtkSrjJmE4Vl/DfNvkt/URJjQCofl0oeedfql3LoL8KHrvjBm9rUb6pZQGursv iZbzhnu3Yq/W/os9+zPJLGJLa6JdUZ0XJbipKnwgVspV85KvnN61sm3jUsgJWFXecsCK D58XjXa6U2FMOmFB2ZeQlsjuoV47yYpfNAB2uNNP3TeulxjR1LrLKSOjQkz1KbQi3iRk UgJw== X-Gm-Message-State: AOAM5326P9ug5G/CjEEXqzPR+c2TgMGHMgR65LmSbuh7em4ZKPccYsKU d0y4KYB3ZKo6DpmMxS7lx5q3wQ== X-Google-Smtp-Source: ABdhPJz1mIaxROQHFnkDMtAkyfocV37SNrA+OnkarpcW450fCaDG5+KffMOrvXq4qfjJmhfMWT0ZNg== X-Received: by 2002:a1c:2cc2:: with SMTP id s185mr1359132wms.77.1603353938320; Thu, 22 Oct 2020 01:05:38 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id 32sm2105875wro.31.2020.10.22.01.05.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Oct 2020 01:05:37 -0700 (PDT) Date: Thu, 22 Oct 2020 10:05:34 +0200 From: Daniel Vetter To: Thomas Zimmermann Subject: Re: [PATCH v5 10/10] drm/fb_helper: Support framebuffers in I/O memory Message-ID: <20201022080534.GT401619@phenom.ffwll.local> References: <20201020122046.31167-1-tzimmermann@suse.de> <20201020122046.31167-11-tzimmermann@suse.de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20201020122046.31167-11-tzimmermann@suse.de> X-Operating-System: Linux phenom 5.7.0-1-amd64 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: luben.tuikov@amd.com, airlied@linux.ie, nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org, chris@chris-wilson.co.uk, melissa.srw@gmail.com, ray.huang@amd.com, kraxel@redhat.com, sam@ravnborg.org, emil.velikov@collabora.com, linux-samsung-soc@vger.kernel.org, jy0922.shim@samsung.com, lima@lists.freedesktop.org, oleksandr_andrushchenko@epam.com, krzk@kernel.org, steven.price@arm.com, linux-rockchip@lists.infradead.org, kgene@kernel.org, bskeggs@redhat.com, linux+etnaviv@armlinux.org.uk, spice-devel@lists.freedesktop.org, alyssa.rosenzweig@collabora.com, etnaviv@lists.freedesktop.org, hdegoede@redhat.com, xen-devel@lists.xenproject.org, virtualization@lists.linux-foundation.org, sean@poorly.run, apaneers@amd.com, linux-arm-kernel@lists.infradead.org, linaro-mm-sig@lists.linaro.org, amd-gfx@lists.freedesktop.org, tomeu.vizoso@collabora.com, sw0312.kim@samsung.com, hjc@rock-chips.com, kyungmin.park@samsung.com, miaoqinglang@huawei.com, yuq825@gmail.com, alexander.deucher@amd.com, linux-media@vger.kernel.org, christian.koenig@amd.com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" On Tue, Oct 20, 2020 at 02:20:46PM +0200, Thomas Zimmermann wrote: > At least sparc64 requires I/O-specific access to framebuffers. This > patch updates the fbdev console accordingly. > > For drivers with direct access to the framebuffer memory, the callback > functions in struct fb_ops test for the type of memory and call the rsp > fb_sys_ of fb_cfb_ functions. Read and write operations are implemented > internally by DRM's fbdev helper. > > For drivers that employ a shadow buffer, fbdev's blit function retrieves > the framebuffer address as struct dma_buf_map, and uses dma_buf_map > interfaces to access the buffer. > > The bochs driver on sparc64 uses a workaround to flag the framebuffer as > I/O memory and avoid a HW exception. With the introduction of struct > dma_buf_map, this is not required any longer. The patch removes the rsp > code from both, bochs and fbdev. > > v5: > * implement fb_read/fb_write internally (Daniel, Sam) > v4: > * move dma_buf_map changes into separate patch (Daniel) > * TODO list: comment on fbdev updates (Daniel) > > Signed-off-by: Thomas Zimmermann > Tested-by: Sam Ravnborg > --- > Documentation/gpu/todo.rst | 19 ++- > drivers/gpu/drm/bochs/bochs_kms.c | 1 - > drivers/gpu/drm/drm_fb_helper.c | 227 ++++++++++++++++++++++++++++-- > include/drm/drm_mode_config.h | 12 -- > 4 files changed, 230 insertions(+), 29 deletions(-) > > diff --git a/Documentation/gpu/todo.rst b/Documentation/gpu/todo.rst > index 7e6fc3c04add..638b7f704339 100644 > --- a/Documentation/gpu/todo.rst > +++ b/Documentation/gpu/todo.rst > @@ -197,13 +197,28 @@ Convert drivers to use drm_fbdev_generic_setup() > ------------------------------------------------ > > Most drivers can use drm_fbdev_generic_setup(). Driver have to implement > -atomic modesetting and GEM vmap support. Current generic fbdev emulation > -expects the framebuffer in system memory (or system-like memory). > +atomic modesetting and GEM vmap support. Historically, generic fbdev emulation > +expected the framebuffer in system memory or system-like memory. By employing > +struct dma_buf_map, drivers with frambuffers in I/O memory can be supported > +as well. > > Contact: Maintainer of the driver you plan to convert > > Level: Intermediate > > +Reimplement functions in drm_fbdev_fb_ops without fbdev > +------------------------------------------------------- > + > +A number of callback functions in drm_fbdev_fb_ops could benefit from > +being rewritten without dependencies on the fbdev module. Some of the > +helpers could further benefit from using struct dma_buf_map instead of > +raw pointers. > + > +Contact: Thomas Zimmermann , Daniel Vetter > + > +Level: Advanced > + > + > drm_framebuffer_funcs and drm_mode_config_funcs.fb_create cleanup > ----------------------------------------------------------------- > > diff --git a/drivers/gpu/drm/bochs/bochs_kms.c b/drivers/gpu/drm/bochs/bochs_kms.c > index 13d0d04c4457..853081d186d5 100644 > --- a/drivers/gpu/drm/bochs/bochs_kms.c > +++ b/drivers/gpu/drm/bochs/bochs_kms.c > @@ -151,7 +151,6 @@ int bochs_kms_init(struct bochs_device *bochs) > bochs->dev->mode_config.preferred_depth = 24; > bochs->dev->mode_config.prefer_shadow = 0; > bochs->dev->mode_config.prefer_shadow_fbdev = 1; > - bochs->dev->mode_config.fbdev_use_iomem = true; > bochs->dev->mode_config.quirk_addfb_prefer_host_byte_order = true; > > bochs->dev->mode_config.funcs = &bochs_mode_funcs; > diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c > index 6212cd7cde1d..1d3180841778 100644 > --- a/drivers/gpu/drm/drm_fb_helper.c > +++ b/drivers/gpu/drm/drm_fb_helper.c > @@ -372,24 +372,22 @@ static void drm_fb_helper_resume_worker(struct work_struct *work) > } > > static void drm_fb_helper_dirty_blit_real(struct drm_fb_helper *fb_helper, > - struct drm_clip_rect *clip) > + struct drm_clip_rect *clip, > + struct dma_buf_map *dst) > { > struct drm_framebuffer *fb = fb_helper->fb; > unsigned int cpp = fb->format->cpp[0]; > size_t offset = clip->y1 * fb->pitches[0] + clip->x1 * cpp; > void *src = fb_helper->fbdev->screen_buffer + offset; > - void *dst = fb_helper->buffer->map.vaddr + offset; > size_t len = (clip->x2 - clip->x1) * cpp; > unsigned int y; > > - for (y = clip->y1; y < clip->y2; y++) { > - if (!fb_helper->dev->mode_config.fbdev_use_iomem) > - memcpy(dst, src, len); > - else > - memcpy_toio((void __iomem *)dst, src, len); > + dma_buf_map_incr(dst, offset); /* go to first pixel within clip rect */ > > + for (y = clip->y1; y < clip->y2; y++) { > + dma_buf_map_memcpy_to(dst, src, len); > + dma_buf_map_incr(dst, fb->pitches[0]); > src += fb->pitches[0]; > - dst += fb->pitches[0]; > } > } > > @@ -417,8 +415,9 @@ static void drm_fb_helper_dirty_work(struct work_struct *work) > ret = drm_client_buffer_vmap(helper->buffer, &map); > if (ret) > return; > - drm_fb_helper_dirty_blit_real(helper, &clip_copy); > + drm_fb_helper_dirty_blit_real(helper, &clip_copy, &map); > } > + > if (helper->fb->funcs->dirty) > helper->fb->funcs->dirty(helper->fb, NULL, 0, 0, > &clip_copy, 1); > @@ -2027,6 +2026,206 @@ static int drm_fbdev_fb_mmap(struct fb_info *info, struct vm_area_struct *vma) > return -ENODEV; > } > > +static bool drm_fbdev_use_iomem(struct fb_info *info) > +{ > + struct drm_fb_helper *fb_helper = info->par; > + struct drm_client_buffer *buffer = fb_helper->buffer; > + > + return !drm_fbdev_use_shadow_fb(fb_helper) && buffer->map.is_iomem; > +} > + > +static ssize_t fb_read_screen_base(struct fb_info *info, char __user *buf, size_t count, > + loff_t pos) > +{ > + const char __iomem *src = info->screen_base + pos; Maybe a bit much a bikeshed, but I'd write this in terms of drm objects, like the dirty_blit function, using the dma_buf_map (instead of the fb_info parameter). And then instead of screen_base and screen_buffer suffixes give them _mem and _iomem suffixes. Same for write below. Or I'm not quite understanding why we do it like this here - I don't think this code will be used outside of the generic fbdev code, so we can always assume that drm_fb_helper->buffer is set up. The other thing I think we need is some minimal testcases to make sure. The fbtest tool used way back seems to have disappeared, I couldn't find a copy of the source anywhere anymore. With all that: Acked-by: Daniel Vetter Cheers, Daniel > + size_t alloc_size = min(count, PAGE_SIZE); > + ssize_t ret = 0; > + char *tmp; > + > + tmp = kmalloc(alloc_size, GFP_KERNEL); > + if (!tmp) > + return -ENOMEM; > + > + while (count) { > + size_t c = min(count, alloc_size); > + > + memcpy_fromio(tmp, src, c); > + if (copy_to_user(buf, tmp, c)) { > + ret = -EFAULT; > + break; > + } > + > + src += c; > + buf += c; > + ret += c; > + count -= c; > + } > + > + kfree(tmp); > + > + return ret; > +} > + > +static ssize_t fb_read_screen_buffer(struct fb_info *info, char __user *buf, size_t count, > + loff_t pos) > +{ > + const char *src = info->screen_buffer + pos; > + > + if (copy_to_user(buf, src, count)) > + return -EFAULT; > + > + return count; > +} > + > +static ssize_t drm_fbdev_fb_read(struct fb_info *info, char __user *buf, > + size_t count, loff_t *ppos) > +{ > + loff_t pos = *ppos; > + size_t total_size; > + ssize_t ret; > + > + if (info->state != FBINFO_STATE_RUNNING) > + return -EPERM; > + > + if (info->screen_size) > + total_size = info->screen_size; > + else > + total_size = info->fix.smem_len; > + > + if (pos >= total_size) > + return 0; > + if (count >= total_size) > + count = total_size; > + if (total_size - count < pos) > + count = total_size - pos; > + > + if (drm_fbdev_use_iomem(info)) > + ret = fb_read_screen_base(info, buf, count, pos); > + else > + ret = fb_read_screen_buffer(info, buf, count, pos); > + > + if (ret > 0) > + *ppos = ret; > + > + return ret; > +} > + > +static ssize_t fb_write_screen_base(struct fb_info *info, const char __user *buf, size_t count, > + loff_t pos) > +{ > + char __iomem *dst = info->screen_base + pos; > + size_t alloc_size = min(count, PAGE_SIZE); > + ssize_t ret = 0; > + u8 *tmp; > + > + tmp = kmalloc(alloc_size, GFP_KERNEL); > + if (!tmp) > + return -ENOMEM; > + > + while (count) { > + size_t c = min(count, alloc_size); > + > + if (copy_from_user(tmp, buf, c)) { > + ret = -EFAULT; > + break; > + } > + memcpy_toio(dst, tmp, c); > + > + dst += c; > + buf += c; > + ret += c; > + count -= c; > + } > + > + kfree(tmp); > + > + return ret; > +} > + > +static ssize_t fb_write_screen_buffer(struct fb_info *info, const char __user *buf, size_t count, > + loff_t pos) > +{ > + char *dst = info->screen_buffer + pos; > + > + if (copy_from_user(dst, buf, count)) > + return -EFAULT; > + > + return count; > +} > + > +static ssize_t drm_fbdev_fb_write(struct fb_info *info, const char __user *buf, > + size_t count, loff_t *ppos) > +{ > + loff_t pos = *ppos; > + size_t total_size; > + ssize_t ret; > + int err; > + > + if (info->state != FBINFO_STATE_RUNNING) > + return -EPERM; > + > + if (info->screen_size) > + total_size = info->screen_size; > + else > + total_size = info->fix.smem_len; > + > + if (pos > total_size) > + return -EFBIG; > + if (count > total_size) { > + err = -EFBIG; > + count = total_size; > + } > + if (total_size - count < pos) { > + if (!err) > + err = -ENOSPC; > + count = total_size - pos; > + } > + > + /* > + * Copy to framebuffer even if we already logged an error. Emulates > + * the behavior of the original fbdev implementation. > + */ > + if (drm_fbdev_use_iomem(info)) > + ret = fb_write_screen_base(info, buf, count, pos); > + else > + ret = fb_write_screen_buffer(info, buf, count, pos); > + > + if (ret > 0) > + *ppos = ret; > + > + if (err) > + return err; > + > + return ret; > +} > + > +static void drm_fbdev_fb_fillrect(struct fb_info *info, > + const struct fb_fillrect *rect) > +{ > + if (drm_fbdev_use_iomem(info)) > + drm_fb_helper_cfb_fillrect(info, rect); > + else > + drm_fb_helper_sys_fillrect(info, rect); > +} > + > +static void drm_fbdev_fb_copyarea(struct fb_info *info, > + const struct fb_copyarea *area) > +{ > + if (drm_fbdev_use_iomem(info)) > + drm_fb_helper_cfb_copyarea(info, area); > + else > + drm_fb_helper_sys_copyarea(info, area); > +} > + > +static void drm_fbdev_fb_imageblit(struct fb_info *info, > + const struct fb_image *image) > +{ > + if (drm_fbdev_use_iomem(info)) > + drm_fb_helper_cfb_imageblit(info, image); > + else > + drm_fb_helper_sys_imageblit(info, image); > +} > + > static const struct fb_ops drm_fbdev_fb_ops = { > .owner = THIS_MODULE, > DRM_FB_HELPER_DEFAULT_OPS, > @@ -2034,11 +2233,11 @@ static const struct fb_ops drm_fbdev_fb_ops = { > .fb_release = drm_fbdev_fb_release, > .fb_destroy = drm_fbdev_fb_destroy, > .fb_mmap = drm_fbdev_fb_mmap, > - .fb_read = drm_fb_helper_sys_read, > - .fb_write = drm_fb_helper_sys_write, > - .fb_fillrect = drm_fb_helper_sys_fillrect, > - .fb_copyarea = drm_fb_helper_sys_copyarea, > - .fb_imageblit = drm_fb_helper_sys_imageblit, > + .fb_read = drm_fbdev_fb_read, > + .fb_write = drm_fbdev_fb_write, > + .fb_fillrect = drm_fbdev_fb_fillrect, > + .fb_copyarea = drm_fbdev_fb_copyarea, > + .fb_imageblit = drm_fbdev_fb_imageblit, > }; > > static struct fb_deferred_io drm_fbdev_defio = { > diff --git a/include/drm/drm_mode_config.h b/include/drm/drm_mode_config.h > index 5ffbb4ed5b35..ab424ddd7665 100644 > --- a/include/drm/drm_mode_config.h > +++ b/include/drm/drm_mode_config.h > @@ -877,18 +877,6 @@ struct drm_mode_config { > */ > bool prefer_shadow_fbdev; > > - /** > - * @fbdev_use_iomem: > - * > - * Set to true if framebuffer reside in iomem. > - * When set to true memcpy_toio() is used when copying the framebuffer in > - * drm_fb_helper.drm_fb_helper_dirty_blit_real(). > - * > - * FIXME: This should be replaced with a per-mapping is_iomem > - * flag (like ttm does), and then used everywhere in fbdev code. > - */ > - bool fbdev_use_iomem; > - > /** > * @quirk_addfb_prefer_xbgr_30bpp: > * > -- > 2.28.0 > -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E2F7C4363A for ; Thu, 22 Oct 2020 08:05:43 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3085F2417D for ; Thu, 22 Oct 2020 08:05:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=ffwll.ch header.i=@ffwll.ch header.b="LpVtkQQE" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3085F2417D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ffwll.ch Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=amd-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6EC956F53B; Thu, 22 Oct 2020 08:05:41 +0000 (UTC) Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by gabe.freedesktop.org (Postfix) with ESMTPS id CD6386F53D for ; Thu, 22 Oct 2020 08:05:39 +0000 (UTC) Received: by mail-wm1-x344.google.com with SMTP id d3so883522wma.4 for ; Thu, 22 Oct 2020 01:05:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ffwll.ch; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=jo9DObZgd9Jq6ZPonfHxKOsM2RbE9S9o0V4+k1CciSY=; b=LpVtkQQEzDhGLYock7xQGko/zoS3bHGVeS2MwITVSQjnbfP4AMhqamrvOtAFmXYrPu M4rdxuuXfajVAiGf91dIAQUVAfjFyk3TE3h9FLC57hbSTRNI8HSEiW7wSnn833mLl3bT qYQcRr7XPtDbhyfcVfQaWMtP5UWNo6sIUEMEs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=jo9DObZgd9Jq6ZPonfHxKOsM2RbE9S9o0V4+k1CciSY=; b=frfjzKyNBDM+7qPedfC6BvONMplkz2KXD6HH9SoHvYBTerWH6aYGiH3sScvkSG+45A RAQGXbHhcrYkVW+YdBksF0r+tHa79yNn/Ui5daTq71x5w7auglNEBWH6nbVaMli5fCX/ Cks8kA8n5YH2nSqE6mM3ms/45YTl17XMi/HLOVezaxBrmb9JoHb1cWp1MX9oikQJYut1 EuiyN2u1n7Ys5WTBQRBmc83Qg6f6JWeBrE6BCjMPE3fRB+jZGUabCTZaR5DRwJZ8dulx t9Q+D9ISWJihqtEWCTziU5P3XqCXoFW43L7g1LVrUaUwgC8upPjtQBzUxwYPxlt2O0Wk 0LMw== X-Gm-Message-State: AOAM532KVEBF1zeRM0bmZ23gOcHWYu6gSLTrHFJnFC8UnharxPwtdh8d LoZavRG6j7Ix4VDgSSTgwW4ESQ== X-Google-Smtp-Source: ABdhPJz1mIaxROQHFnkDMtAkyfocV37SNrA+OnkarpcW450fCaDG5+KffMOrvXq4qfjJmhfMWT0ZNg== X-Received: by 2002:a1c:2cc2:: with SMTP id s185mr1359132wms.77.1603353938320; Thu, 22 Oct 2020 01:05:38 -0700 (PDT) Received: from phenom.ffwll.local ([2a02:168:57f4:0:efd0:b9e5:5ae6:c2fa]) by smtp.gmail.com with ESMTPSA id 32sm2105875wro.31.2020.10.22.01.05.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Oct 2020 01:05:37 -0700 (PDT) Date: Thu, 22 Oct 2020 10:05:34 +0200 From: Daniel Vetter To: Thomas Zimmermann Subject: Re: [PATCH v5 10/10] drm/fb_helper: Support framebuffers in I/O memory Message-ID: <20201022080534.GT401619@phenom.ffwll.local> References: <20201020122046.31167-1-tzimmermann@suse.de> <20201020122046.31167-11-tzimmermann@suse.de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20201020122046.31167-11-tzimmermann@suse.de> X-Operating-System: Linux phenom 5.7.0-1-amd64 X-BeenThere: amd-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion list for AMD gfx List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: luben.tuikov@amd.com, heiko@sntech.de, airlied@linux.ie, nouveau@lists.freedesktop.org, linus.walleij@linaro.org, dri-devel@lists.freedesktop.org, chris@chris-wilson.co.uk, melissa.srw@gmail.com, eric@anholt.net, ray.huang@amd.com, kraxel@redhat.com, sam@ravnborg.org, sumit.semwal@linaro.org, emil.velikov@collabora.com, robh@kernel.org, linux-samsung-soc@vger.kernel.org, jy0922.shim@samsung.com, lima@lists.freedesktop.org, oleksandr_andrushchenko@epam.com, krzk@kernel.org, steven.price@arm.com, linux-rockchip@lists.infradead.org, kgene@kernel.org, bskeggs@redhat.com, linux+etnaviv@armlinux.org.uk, spice-devel@lists.freedesktop.org, alyssa.rosenzweig@collabora.com, maarten.lankhorst@linux.intel.com, etnaviv@lists.freedesktop.org, mripard@kernel.org, inki.dae@samsung.com, hdegoede@redhat.com, christian.gmeiner@gmail.com, xen-devel@lists.xenproject.org, virtualization@lists.linux-foundation.org, sean@poorly.run, apaneers@amd.com, linux-arm-kernel@lists.infradead.org, linaro-mm-sig@lists.linaro.org, amd-gfx@lists.freedesktop.org, tomeu.vizoso@collabora.com, sw0312.kim@samsung.com, hjc@rock-chips.com, kyungmin.park@samsung.com, miaoqinglang@huawei.com, yuq825@gmail.com, daniel@ffwll.ch, alexander.deucher@amd.com, linux-media@vger.kernel.org, christian.koenig@amd.com, l.stach@pengutronix.de Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: amd-gfx-bounces@lists.freedesktop.org Sender: "amd-gfx" On Tue, Oct 20, 2020 at 02:20:46PM +0200, Thomas Zimmermann wrote: > At least sparc64 requires I/O-specific access to framebuffers. This > patch updates the fbdev console accordingly. > > For drivers with direct access to the framebuffer memory, the callback > functions in struct fb_ops test for the type of memory and call the rsp > fb_sys_ of fb_cfb_ functions. Read and write operations are implemented > internally by DRM's fbdev helper. > > For drivers that employ a shadow buffer, fbdev's blit function retrieves > the framebuffer address as struct dma_buf_map, and uses dma_buf_map > interfaces to access the buffer. > > The bochs driver on sparc64 uses a workaround to flag the framebuffer as > I/O memory and avoid a HW exception. With the introduction of struct > dma_buf_map, this is not required any longer. The patch removes the rsp > code from both, bochs and fbdev. > > v5: > * implement fb_read/fb_write internally (Daniel, Sam) > v4: > * move dma_buf_map changes into separate patch (Daniel) > * TODO list: comment on fbdev updates (Daniel) > > Signed-off-by: Thomas Zimmermann > Tested-by: Sam Ravnborg > --- > Documentation/gpu/todo.rst | 19 ++- > drivers/gpu/drm/bochs/bochs_kms.c | 1 - > drivers/gpu/drm/drm_fb_helper.c | 227 ++++++++++++++++++++++++++++-- > include/drm/drm_mode_config.h | 12 -- > 4 files changed, 230 insertions(+), 29 deletions(-) > > diff --git a/Documentation/gpu/todo.rst b/Documentation/gpu/todo.rst > index 7e6fc3c04add..638b7f704339 100644 > --- a/Documentation/gpu/todo.rst > +++ b/Documentation/gpu/todo.rst > @@ -197,13 +197,28 @@ Convert drivers to use drm_fbdev_generic_setup() > ------------------------------------------------ > > Most drivers can use drm_fbdev_generic_setup(). Driver have to implement > -atomic modesetting and GEM vmap support. Current generic fbdev emulation > -expects the framebuffer in system memory (or system-like memory). > +atomic modesetting and GEM vmap support. Historically, generic fbdev emulation > +expected the framebuffer in system memory or system-like memory. By employing > +struct dma_buf_map, drivers with frambuffers in I/O memory can be supported > +as well. > > Contact: Maintainer of the driver you plan to convert > > Level: Intermediate > > +Reimplement functions in drm_fbdev_fb_ops without fbdev > +------------------------------------------------------- > + > +A number of callback functions in drm_fbdev_fb_ops could benefit from > +being rewritten without dependencies on the fbdev module. Some of the > +helpers could further benefit from using struct dma_buf_map instead of > +raw pointers. > + > +Contact: Thomas Zimmermann , Daniel Vetter > + > +Level: Advanced > + > + > drm_framebuffer_funcs and drm_mode_config_funcs.fb_create cleanup > ----------------------------------------------------------------- > > diff --git a/drivers/gpu/drm/bochs/bochs_kms.c b/drivers/gpu/drm/bochs/bochs_kms.c > index 13d0d04c4457..853081d186d5 100644 > --- a/drivers/gpu/drm/bochs/bochs_kms.c > +++ b/drivers/gpu/drm/bochs/bochs_kms.c > @@ -151,7 +151,6 @@ int bochs_kms_init(struct bochs_device *bochs) > bochs->dev->mode_config.preferred_depth = 24; > bochs->dev->mode_config.prefer_shadow = 0; > bochs->dev->mode_config.prefer_shadow_fbdev = 1; > - bochs->dev->mode_config.fbdev_use_iomem = true; > bochs->dev->mode_config.quirk_addfb_prefer_host_byte_order = true; > > bochs->dev->mode_config.funcs = &bochs_mode_funcs; > diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c > index 6212cd7cde1d..1d3180841778 100644 > --- a/drivers/gpu/drm/drm_fb_helper.c > +++ b/drivers/gpu/drm/drm_fb_helper.c > @@ -372,24 +372,22 @@ static void drm_fb_helper_resume_worker(struct work_struct *work) > } > > static void drm_fb_helper_dirty_blit_real(struct drm_fb_helper *fb_helper, > - struct drm_clip_rect *clip) > + struct drm_clip_rect *clip, > + struct dma_buf_map *dst) > { > struct drm_framebuffer *fb = fb_helper->fb; > unsigned int cpp = fb->format->cpp[0]; > size_t offset = clip->y1 * fb->pitches[0] + clip->x1 * cpp; > void *src = fb_helper->fbdev->screen_buffer + offset; > - void *dst = fb_helper->buffer->map.vaddr + offset; > size_t len = (clip->x2 - clip->x1) * cpp; > unsigned int y; > > - for (y = clip->y1; y < clip->y2; y++) { > - if (!fb_helper->dev->mode_config.fbdev_use_iomem) > - memcpy(dst, src, len); > - else > - memcpy_toio((void __iomem *)dst, src, len); > + dma_buf_map_incr(dst, offset); /* go to first pixel within clip rect */ > > + for (y = clip->y1; y < clip->y2; y++) { > + dma_buf_map_memcpy_to(dst, src, len); > + dma_buf_map_incr(dst, fb->pitches[0]); > src += fb->pitches[0]; > - dst += fb->pitches[0]; > } > } > > @@ -417,8 +415,9 @@ static void drm_fb_helper_dirty_work(struct work_struct *work) > ret = drm_client_buffer_vmap(helper->buffer, &map); > if (ret) > return; > - drm_fb_helper_dirty_blit_real(helper, &clip_copy); > + drm_fb_helper_dirty_blit_real(helper, &clip_copy, &map); > } > + > if (helper->fb->funcs->dirty) > helper->fb->funcs->dirty(helper->fb, NULL, 0, 0, > &clip_copy, 1); > @@ -2027,6 +2026,206 @@ static int drm_fbdev_fb_mmap(struct fb_info *info, struct vm_area_struct *vma) > return -ENODEV; > } > > +static bool drm_fbdev_use_iomem(struct fb_info *info) > +{ > + struct drm_fb_helper *fb_helper = info->par; > + struct drm_client_buffer *buffer = fb_helper->buffer; > + > + return !drm_fbdev_use_shadow_fb(fb_helper) && buffer->map.is_iomem; > +} > + > +static ssize_t fb_read_screen_base(struct fb_info *info, char __user *buf, size_t count, > + loff_t pos) > +{ > + const char __iomem *src = info->screen_base + pos; Maybe a bit much a bikeshed, but I'd write this in terms of drm objects, like the dirty_blit function, using the dma_buf_map (instead of the fb_info parameter). And then instead of screen_base and screen_buffer suffixes give them _mem and _iomem suffixes. Same for write below. Or I'm not quite understanding why we do it like this here - I don't think this code will be used outside of the generic fbdev code, so we can always assume that drm_fb_helper->buffer is set up. The other thing I think we need is some minimal testcases to make sure. The fbtest tool used way back seems to have disappeared, I couldn't find a copy of the source anywhere anymore. With all that: Acked-by: Daniel Vetter Cheers, Daniel > + size_t alloc_size = min(count, PAGE_SIZE); > + ssize_t ret = 0; > + char *tmp; > + > + tmp = kmalloc(alloc_size, GFP_KERNEL); > + if (!tmp) > + return -ENOMEM; > + > + while (count) { > + size_t c = min(count, alloc_size); > + > + memcpy_fromio(tmp, src, c); > + if (copy_to_user(buf, tmp, c)) { > + ret = -EFAULT; > + break; > + } > + > + src += c; > + buf += c; > + ret += c; > + count -= c; > + } > + > + kfree(tmp); > + > + return ret; > +} > + > +static ssize_t fb_read_screen_buffer(struct fb_info *info, char __user *buf, size_t count, > + loff_t pos) > +{ > + const char *src = info->screen_buffer + pos; > + > + if (copy_to_user(buf, src, count)) > + return -EFAULT; > + > + return count; > +} > + > +static ssize_t drm_fbdev_fb_read(struct fb_info *info, char __user *buf, > + size_t count, loff_t *ppos) > +{ > + loff_t pos = *ppos; > + size_t total_size; > + ssize_t ret; > + > + if (info->state != FBINFO_STATE_RUNNING) > + return -EPERM; > + > + if (info->screen_size) > + total_size = info->screen_size; > + else > + total_size = info->fix.smem_len; > + > + if (pos >= total_size) > + return 0; > + if (count >= total_size) > + count = total_size; > + if (total_size - count < pos) > + count = total_size - pos; > + > + if (drm_fbdev_use_iomem(info)) > + ret = fb_read_screen_base(info, buf, count, pos); > + else > + ret = fb_read_screen_buffer(info, buf, count, pos); > + > + if (ret > 0) > + *ppos = ret; > + > + return ret; > +} > + > +static ssize_t fb_write_screen_base(struct fb_info *info, const char __user *buf, size_t count, > + loff_t pos) > +{ > + char __iomem *dst = info->screen_base + pos; > + size_t alloc_size = min(count, PAGE_SIZE); > + ssize_t ret = 0; > + u8 *tmp; > + > + tmp = kmalloc(alloc_size, GFP_KERNEL); > + if (!tmp) > + return -ENOMEM; > + > + while (count) { > + size_t c = min(count, alloc_size); > + > + if (copy_from_user(tmp, buf, c)) { > + ret = -EFAULT; > + break; > + } > + memcpy_toio(dst, tmp, c); > + > + dst += c; > + buf += c; > + ret += c; > + count -= c; > + } > + > + kfree(tmp); > + > + return ret; > +} > + > +static ssize_t fb_write_screen_buffer(struct fb_info *info, const char __user *buf, size_t count, > + loff_t pos) > +{ > + char *dst = info->screen_buffer + pos; > + > + if (copy_from_user(dst, buf, count)) > + return -EFAULT; > + > + return count; > +} > + > +static ssize_t drm_fbdev_fb_write(struct fb_info *info, const char __user *buf, > + size_t count, loff_t *ppos) > +{ > + loff_t pos = *ppos; > + size_t total_size; > + ssize_t ret; > + int err; > + > + if (info->state != FBINFO_STATE_RUNNING) > + return -EPERM; > + > + if (info->screen_size) > + total_size = info->screen_size; > + else > + total_size = info->fix.smem_len; > + > + if (pos > total_size) > + return -EFBIG; > + if (count > total_size) { > + err = -EFBIG; > + count = total_size; > + } > + if (total_size - count < pos) { > + if (!err) > + err = -ENOSPC; > + count = total_size - pos; > + } > + > + /* > + * Copy to framebuffer even if we already logged an error. Emulates > + * the behavior of the original fbdev implementation. > + */ > + if (drm_fbdev_use_iomem(info)) > + ret = fb_write_screen_base(info, buf, count, pos); > + else > + ret = fb_write_screen_buffer(info, buf, count, pos); > + > + if (ret > 0) > + *ppos = ret; > + > + if (err) > + return err; > + > + return ret; > +} > + > +static void drm_fbdev_fb_fillrect(struct fb_info *info, > + const struct fb_fillrect *rect) > +{ > + if (drm_fbdev_use_iomem(info)) > + drm_fb_helper_cfb_fillrect(info, rect); > + else > + drm_fb_helper_sys_fillrect(info, rect); > +} > + > +static void drm_fbdev_fb_copyarea(struct fb_info *info, > + const struct fb_copyarea *area) > +{ > + if (drm_fbdev_use_iomem(info)) > + drm_fb_helper_cfb_copyarea(info, area); > + else > + drm_fb_helper_sys_copyarea(info, area); > +} > + > +static void drm_fbdev_fb_imageblit(struct fb_info *info, > + const struct fb_image *image) > +{ > + if (drm_fbdev_use_iomem(info)) > + drm_fb_helper_cfb_imageblit(info, image); > + else > + drm_fb_helper_sys_imageblit(info, image); > +} > + > static const struct fb_ops drm_fbdev_fb_ops = { > .owner = THIS_MODULE, > DRM_FB_HELPER_DEFAULT_OPS, > @@ -2034,11 +2233,11 @@ static const struct fb_ops drm_fbdev_fb_ops = { > .fb_release = drm_fbdev_fb_release, > .fb_destroy = drm_fbdev_fb_destroy, > .fb_mmap = drm_fbdev_fb_mmap, > - .fb_read = drm_fb_helper_sys_read, > - .fb_write = drm_fb_helper_sys_write, > - .fb_fillrect = drm_fb_helper_sys_fillrect, > - .fb_copyarea = drm_fb_helper_sys_copyarea, > - .fb_imageblit = drm_fb_helper_sys_imageblit, > + .fb_read = drm_fbdev_fb_read, > + .fb_write = drm_fbdev_fb_write, > + .fb_fillrect = drm_fbdev_fb_fillrect, > + .fb_copyarea = drm_fbdev_fb_copyarea, > + .fb_imageblit = drm_fbdev_fb_imageblit, > }; > > static struct fb_deferred_io drm_fbdev_defio = { > diff --git a/include/drm/drm_mode_config.h b/include/drm/drm_mode_config.h > index 5ffbb4ed5b35..ab424ddd7665 100644 > --- a/include/drm/drm_mode_config.h > +++ b/include/drm/drm_mode_config.h > @@ -877,18 +877,6 @@ struct drm_mode_config { > */ > bool prefer_shadow_fbdev; > > - /** > - * @fbdev_use_iomem: > - * > - * Set to true if framebuffer reside in iomem. > - * When set to true memcpy_toio() is used when copying the framebuffer in > - * drm_fb_helper.drm_fb_helper_dirty_blit_real(). > - * > - * FIXME: This should be replaced with a per-mapping is_iomem > - * flag (like ttm does), and then used everywhere in fbdev code. > - */ > - bool fbdev_use_iomem; > - > /** > * @quirk_addfb_prefer_xbgr_30bpp: > * > -- > 2.28.0 > -- Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ amd-gfx mailing list amd-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/amd-gfx