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.7 required=3.0 tests=BAYES_00, 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 59776C433DF for ; Fri, 16 Oct 2020 12:49:02 +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 BFE1E207DE for ; Fri, 16 Oct 2020 12:49:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BFE1E207DE Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ravnborg.org 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 278846EDD7; Fri, 16 Oct 2020 12:49:01 +0000 (UTC) Received: from asavdk4.altibox.net (asavdk4.altibox.net [109.247.116.15]) by gabe.freedesktop.org (Postfix) with ESMTPS id 87C5D6E141; Fri, 16 Oct 2020 12:48:59 +0000 (UTC) Received: from ravnborg.org (unknown [188.228.123.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by asavdk4.altibox.net (Postfix) with ESMTPS id 383A2806F9; Fri, 16 Oct 2020 14:48:52 +0200 (CEST) Date: Fri, 16 Oct 2020 14:48:50 +0200 From: Sam Ravnborg To: Thomas Zimmermann Subject: Re: [PATCH v4 10/10] drm/fb_helper: Support framebuffers in I/O memory Message-ID: <20201016124850.GA1174599@ravnborg.org> References: <20201015123806.32416-1-tzimmermann@suse.de> <20201015123806.32416-11-tzimmermann@suse.de> <20201016120347.GB1125266@ravnborg.org> <20201016141942.111e17f3@linux-uq9g> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20201016141942.111e17f3@linux-uq9g> X-CMAE-Score: 0 X-CMAE-Analysis: v=2.3 cv=fu7ymmwf c=1 sm=1 tr=0 a=S6zTFyMACwkrwXSdXUNehg==:117 a=S6zTFyMACwkrwXSdXUNehg==:17 a=8nJEP1OIZ-IA:10 a=7gkXJVJtAAAA:8 a=6Hpfs63HWkxrz3fWGNMA:9 a=w4pgIJ6L-nyCBc2a:21 a=gikFlJ38tUkSyios:21 a=wPNLvfGTeEIA:10 a=qfUslh1TxfEA:10 a=E9Po1WZjFZOl8hwRPBS3:22 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, 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, alyssa.rosenzweig@collabora.com, linux+etnaviv@armlinux.org.uk, spice-devel@lists.freedesktop.org, bskeggs@redhat.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="iso-8859-1" Content-Transfer-Encoding: quoted-printable Errors-To: amd-gfx-bounces@lists.freedesktop.org Sender: "amd-gfx" On Fri, Oct 16, 2020 at 02:19:42PM +0200, Thomas Zimmermann wrote: > Hi > = > On Fri, 16 Oct 2020 14:03:47 +0200 Sam Ravnborg wrote: > = > > Hi Thomas. > > = > > On Thu, Oct 15, 2020 at 02:38:06PM +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 r= sp > > > fb_sys_ of fb_cfb_ functions. > > > = > > > For drivers that employ a shadow buffer, fbdev's blit function retrie= ves > > > 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 r= sp > > > code from both, bochs and fbdev. > > > = > > > v4: > > > * move dma_buf_map changes into separate patch (Daniel) > > > * TODO list: comment on fbdev updates (Daniel) > > > = > > > Signed-off-by: Thomas Zimmermann > > = > > The original workaround fixed it so we could run qemu with the > > -nographic option. > > = > > So I went ahead and tried to run quemu version: > > v5.0.0-1970-g0b100c8e72-dirty. > > And with the BOCHS driver built-in. > > = > > With the following command line: > > qemu-system-sparc64 -m 512 -kernel vmlinux -append console=3DttyS0 -nog= raphic > > = > > Behaviour was the same before and after applying this patch. > > (panic due to VFS: Unable to mount root fs on unknown-block(0,0)) > > So I consider it fixed for real now and not just a workaround. > > = > > I also tested with: > > qemu-system-sparc64 -m 512 -kernel vmlinux -append console=3DttyS0 -ser= ial > > stdio > > = > > and it worked in both cases too. > = > FTR, you booted a kernel and got graphics output. The error is simply that > there was no disk to mount? The short version "Yes". The longer version: With "qemu-system-sparc64 -m 512 -kernel vmlinux -append console=3DttyS0 -serial stdio" I got graphical output - one penguin. With "qemu-system-sparc64 -m 512 -kernel vmlinux -append console=3DttyS0 -nographic" I got no graphical output, as implied by the -nographic option. But the boot continued - where it would panic before when we accessed IO memory as system memory. In both cases I got an error because I had not specified any rootfs, so qemu failed to mount any rootfs. So expected. Sam > = > Best regards > Thomas > = > > = > > All the comments above so future-me have an easier time finding how to > > reproduce. > > = > > Tested-by: Sam Ravnborg > > = > > Sam > > = > > > --- > > > Documentation/gpu/todo.rst | 19 ++- > > > drivers/gpu/drm/bochs/bochs_kms.c | 1 - > > > drivers/gpu/drm/drm_fb_helper.c | 217 ++++++++++++++++++++++++++++= -- > > > include/drm/drm_mode_config.h | 12 -- > > > 4 files changed, 220 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 imple= ment > > > -atomic modesetting and GEM vmap support. Current generic fbdev emula= tion > > > -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 =3D 24; > > > bochs->dev->mode_config.prefer_shadow =3D 0; > > > bochs->dev->mode_config.prefer_shadow_fbdev =3D 1; > > > - bochs->dev->mode_config.fbdev_use_iomem =3D true; > > > bochs->dev->mode_config.quirk_addfb_prefer_host_byte_order =3D > > > true; = > > > bochs->dev->mode_config.funcs =3D &bochs_mode_funcs; > > > diff --git a/drivers/gpu/drm/drm_fb_helper.c > > > b/drivers/gpu/drm/drm_fb_helper.c index 6212cd7cde1d..462b0c130ebb 10= 0644 > > > --- 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 =3D fb_helper->fb; > > > unsigned int cpp =3D fb->format->cpp[0]; > > > size_t offset =3D clip->y1 * fb->pitches[0] + clip->x1 * cpp; > > > void *src =3D fb_helper->fbdev->screen_buffer + offset; > > > - void *dst =3D fb_helper->buffer->map.vaddr + offset; > > > size_t len =3D (clip->x2 - clip->x1) * cpp; > > > unsigned int y; > > > = > > > - for (y =3D 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 =3D clip->y1; y < clip->y2; y++) { > > > + dma_buf_map_memcpy_to(dst, src, len); > > > + dma_buf_map_incr(dst, fb->pitches[0]); > > > src +=3D fb->pitches[0]; > > > - dst +=3D fb->pitches[0]; > > > } > > > } > > > = > > > @@ -417,8 +415,9 @@ static void drm_fb_helper_dirty_work(struct > > > work_struct *work) ret =3D drm_client_buffer_vmap(helper->buffer, &ma= p); > > > 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); > > > @@ -755,6 +754,136 @@ void drm_fb_helper_sys_imageblit(struct fb_info > > > *info, } > > > EXPORT_SYMBOL(drm_fb_helper_sys_imageblit); > > > = > > > +static ssize_t drm_fb_helper_cfb_read(struct fb_info *info, char __u= ser > > > *buf, > > > + size_t count, loff_t *ppos) > > > +{ > > > + unsigned long p =3D *ppos; > > > + u8 *dst; > > > + u8 __iomem *src; > > > + int c, err =3D 0; > > > + unsigned long total_size; > > > + unsigned long alloc_size; > > > + ssize_t ret =3D 0; > > > + > > > + if (info->state !=3D FBINFO_STATE_RUNNING) > > > + return -EPERM; > > > + > > > + total_size =3D info->screen_size; > > > + > > > + if (total_size =3D=3D 0) > > > + total_size =3D info->fix.smem_len; > > > + > > > + if (p >=3D total_size) > > > + return 0; > > > + > > > + if (count >=3D total_size) > > > + count =3D total_size; > > > + > > > + if (count + p > total_size) > > > + count =3D total_size - p; > > > + > > > + src =3D (u8 __iomem *)(info->screen_base + p); > > > + > > > + alloc_size =3D min(count, PAGE_SIZE); > > > + > > > + dst =3D kmalloc(alloc_size, GFP_KERNEL); > > > + if (!dst) > > > + return -ENOMEM; > > > + > > > + while (count) { > > > + c =3D min(count, alloc_size); > > > + > > > + memcpy_fromio(dst, src, c); > > > + if (copy_to_user(buf, dst, c)) { > > > + err =3D -EFAULT; > > > + break; > > > + } > > > + > > > + src +=3D c; > > > + *ppos +=3D c; > > > + buf +=3D c; > > > + ret +=3D c; > > > + count -=3D c; > > > + } > > > + > > > + kfree(dst); > > > + > > > + if (err) > > > + return err; > > > + > > > + return ret; > > > +} > > > + > > > +static ssize_t drm_fb_helper_cfb_write(struct fb_info *info, const c= har > > > __user *buf, > > > + size_t count, loff_t *ppos) > > > +{ > > > + unsigned long p =3D *ppos; > > > + u8 *src; > > > + u8 __iomem *dst; > > > + int c, err =3D 0; > > > + unsigned long total_size; > > > + unsigned long alloc_size; > > > + ssize_t ret =3D 0; > > > + > > > + if (info->state !=3D FBINFO_STATE_RUNNING) > > > + return -EPERM; > > > + > > > + total_size =3D info->screen_size; > > > + > > > + if (total_size =3D=3D 0) > > > + total_size =3D info->fix.smem_len; > > > + > > > + if (p > total_size) > > > + return -EFBIG; > > > + > > > + if (count > total_size) { > > > + err =3D -EFBIG; > > > + count =3D total_size; > > > + } > > > + > > > + if (count + p > total_size) { > > > + /* > > > + * The framebuffer is too small. We do the > > > + * copy operation, but return an error code > > > + * afterwards. Taken from fbdev. > > > + */ > > > + if (!err) > > > + err =3D -ENOSPC; > > > + count =3D total_size - p; > > > + } > > > + > > > + alloc_size =3D min(count, PAGE_SIZE); > > > + > > > + src =3D kmalloc(alloc_size, GFP_KERNEL); > > > + if (!src) > > > + return -ENOMEM; > > > + > > > + dst =3D (u8 __iomem *)(info->screen_base + p); > > > + > > > + while (count) { > > > + c =3D min(count, alloc_size); > > > + > > > + if (copy_from_user(src, buf, c)) { > > > + err =3D -EFAULT; > > > + break; > > > + } > > > + memcpy_toio(dst, src, c); > > > + > > > + dst +=3D c; > > > + *ppos +=3D c; > > > + buf +=3D c; > > > + ret +=3D c; > > > + count -=3D c; > > > + } > > > + > > > + kfree(src); > > > + > > > + if (err) > > > + return err; > > > + > > > + return ret; > > > +} > > > + > > > /** > > > * drm_fb_helper_cfb_fillrect - wrapper around cfb_fillrect > > > * @info: fbdev registered by the helper > > > @@ -2027,6 +2156,66 @@ static int drm_fbdev_fb_mmap(struct fb_info *i= nfo, > > > struct vm_area_struct *vma) return -ENODEV; > > > } > > > = > > > +static ssize_t drm_fbdev_fb_read(struct fb_info *info, char __user *= buf, > > > + size_t count, loff_t *ppos) > > > +{ > > > + struct drm_fb_helper *fb_helper =3D info->par; > > > + struct drm_client_buffer *buffer =3D fb_helper->buffer; > > > + > > > + if (drm_fbdev_use_shadow_fb(fb_helper) || !buffer->map.is_iomem) > > > + return drm_fb_helper_sys_read(info, buf, count, ppos); > > > + else > > > + return drm_fb_helper_cfb_read(info, buf, count, ppos); > > > +} > > > + > > > +static ssize_t drm_fbdev_fb_write(struct fb_info *info, const char > > > __user *buf, > > > + size_t count, loff_t *ppos) > > > +{ > > > + struct drm_fb_helper *fb_helper =3D info->par; > > > + struct drm_client_buffer *buffer =3D fb_helper->buffer; > > > + > > > + if (drm_fbdev_use_shadow_fb(fb_helper) || !buffer->map.is_iomem) > > > + return drm_fb_helper_sys_write(info, buf, count, ppos); > > > + else > > > + return drm_fb_helper_cfb_write(info, buf, count, ppos); > > > +} > > > + > > > +static void drm_fbdev_fb_fillrect(struct fb_info *info, > > > + const struct fb_fillrect *rect) > > > +{ > > > + struct drm_fb_helper *fb_helper =3D info->par; > > > + struct drm_client_buffer *buffer =3D fb_helper->buffer; > > > + > > > + if (drm_fbdev_use_shadow_fb(fb_helper) || !buffer->map.is_iomem) > > > + drm_fb_helper_sys_fillrect(info, rect); > > > + else > > > + drm_fb_helper_cfb_fillrect(info, rect); > > > +} > > > + > > > +static void drm_fbdev_fb_copyarea(struct fb_info *info, > > > + const struct fb_copyarea *area) > > > +{ > > > + struct drm_fb_helper *fb_helper =3D info->par; > > > + struct drm_client_buffer *buffer =3D fb_helper->buffer; > > > + > > > + if (drm_fbdev_use_shadow_fb(fb_helper) || !buffer->map.is_iomem) > > > + drm_fb_helper_sys_copyarea(info, area); > > > + else > > > + drm_fb_helper_cfb_copyarea(info, area); > > > +} > > > + > > > +static void drm_fbdev_fb_imageblit(struct fb_info *info, > > > + const struct fb_image *image) > > > +{ > > > + struct drm_fb_helper *fb_helper =3D info->par; > > > + struct drm_client_buffer *buffer =3D fb_helper->buffer; > > > + > > > + if (drm_fbdev_use_shadow_fb(fb_helper) || !buffer->map.is_iomem) > > > + drm_fb_helper_sys_imageblit(info, image); > > > + else > > > + drm_fb_helper_cfb_imageblit(info, image); > > > +} > > > + > > > static const struct fb_ops drm_fbdev_fb_ops =3D { > > > .owner =3D THIS_MODULE, > > > DRM_FB_HELPER_DEFAULT_OPS, > > > @@ -2034,11 +2223,11 @@ static const struct fb_ops drm_fbdev_fb_ops = =3D { > > > .fb_release =3D drm_fbdev_fb_release, > > > .fb_destroy =3D drm_fbdev_fb_destroy, > > > .fb_mmap =3D drm_fbdev_fb_mmap, > > > - .fb_read =3D drm_fb_helper_sys_read, > > > - .fb_write =3D drm_fb_helper_sys_write, > > > - .fb_fillrect =3D drm_fb_helper_sys_fillrect, > > > - .fb_copyarea =3D drm_fb_helper_sys_copyarea, > > > - .fb_imageblit =3D drm_fb_helper_sys_imageblit, > > > + .fb_read =3D drm_fbdev_fb_read, > > > + .fb_write =3D drm_fbdev_fb_write, > > > + .fb_fillrect =3D drm_fbdev_fb_fillrect, > > > + .fb_copyarea =3D drm_fbdev_fb_copyarea, > > > + .fb_imageblit =3D drm_fbdev_fb_imageblit, > > > }; > > > = > > > static struct fb_deferred_io drm_fbdev_defio =3D { > > > diff --git a/include/drm/drm_mode_config.h b/include/drm/drm_mode_con= fig.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 > = > = > = > -- = > Thomas Zimmermann > Graphics Driver Developer > SUSE Software Solutions Germany GmbH > Maxfeldstr. 5, 90409 N=FCrnberg, Germany > (HRB 36809, AG N=FCrnberg) > Gesch=E4ftsf=FChrer: Felix Imend=F6rffer _______________________________________________ amd-gfx mailing list amd-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/amd-gfx 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 21C4EC433E7 for ; Fri, 16 Oct 2020 12:49:18 +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 5856F207E8 for ; Fri, 16 Oct 2020 12:49:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="A24vWZXQ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5856F207E8 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ravnborg.org 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=eLVmUhKA1ug6TJKMLOY9mscfZicaA0z5TihOYzy0eIE=; b=A24vWZXQsCxHAr/wuOmud9vU/ 3x2lmfP870QSbuPvsndusGbyd8UrA6xPExk4dzNLylzzuhPXxFQtf1UEikTsgUAjlhYRIkQBhirPZ ORXLACCGy/yy1Y5n3zgpCKXF84qsvy9n/VXLcdlG9gQERbC6Ye3bxqPCbhXWBUxlhGMIfHRNZ28qG seyudPOgKQkphJTswkgGlYrczflUdushlryl1pjjfnwMsaFS3br0S3XwRQ0aH5P+ZIqGUxAzpwWpm j1RBBgFwRre7JjSQ+8hs4H17LjPz0GOv0uCUlBFpbWIppP/HX2zA7vhKUcfdghHdDKz42r2KMf2KJ 7cqDhOIwA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kTPAO-0003AU-Eg; Fri, 16 Oct 2020 12:49:04 +0000 Received: from asavdk4.altibox.net ([109.247.116.15]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kTPAK-00039w-Mr; Fri, 16 Oct 2020 12:49:02 +0000 Received: from ravnborg.org (unknown [188.228.123.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by asavdk4.altibox.net (Postfix) with ESMTPS id 383A2806F9; Fri, 16 Oct 2020 14:48:52 +0200 (CEST) Date: Fri, 16 Oct 2020 14:48:50 +0200 From: Sam Ravnborg To: Thomas Zimmermann Subject: Re: [PATCH v4 10/10] drm/fb_helper: Support framebuffers in I/O memory Message-ID: <20201016124850.GA1174599@ravnborg.org> References: <20201015123806.32416-1-tzimmermann@suse.de> <20201015123806.32416-11-tzimmermann@suse.de> <20201016120347.GB1125266@ravnborg.org> <20201016141942.111e17f3@linux-uq9g> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20201016141942.111e17f3@linux-uq9g> X-CMAE-Score: 0 X-CMAE-Analysis: v=2.3 cv=fu7ymmwf c=1 sm=1 tr=0 a=S6zTFyMACwkrwXSdXUNehg==:117 a=S6zTFyMACwkrwXSdXUNehg==:17 a=8nJEP1OIZ-IA:10 a=7gkXJVJtAAAA:8 a=6Hpfs63HWkxrz3fWGNMA:9 a=w4pgIJ6L-nyCBc2a:21 a=gikFlJ38tUkSyios:21 a=wPNLvfGTeEIA:10 a=qfUslh1TxfEA:10 a=E9Po1WZjFZOl8hwRPBS3:22 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201016_084901_105951_B133D327 X-CRM114-Status: GOOD ( 47.35 ) 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, 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, alyssa.rosenzweig@collabora.com, linux+etnaviv@armlinux.org.uk, spice-devel@lists.freedesktop.org, bskeggs@redhat.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="iso-8859-1" Content-Transfer-Encoding: quoted-printable Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org On Fri, Oct 16, 2020 at 02:19:42PM +0200, Thomas Zimmermann wrote: > Hi > = > On Fri, 16 Oct 2020 14:03:47 +0200 Sam Ravnborg wrote: > = > > Hi Thomas. > > = > > On Thu, Oct 15, 2020 at 02:38:06PM +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 r= sp > > > fb_sys_ of fb_cfb_ functions. > > > = > > > For drivers that employ a shadow buffer, fbdev's blit function retrie= ves > > > 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 r= sp > > > code from both, bochs and fbdev. > > > = > > > v4: > > > * move dma_buf_map changes into separate patch (Daniel) > > > * TODO list: comment on fbdev updates (Daniel) > > > = > > > Signed-off-by: Thomas Zimmermann > > = > > The original workaround fixed it so we could run qemu with the > > -nographic option. > > = > > So I went ahead and tried to run quemu version: > > v5.0.0-1970-g0b100c8e72-dirty. > > And with the BOCHS driver built-in. > > = > > With the following command line: > > qemu-system-sparc64 -m 512 -kernel vmlinux -append console=3DttyS0 -nog= raphic > > = > > Behaviour was the same before and after applying this patch. > > (panic due to VFS: Unable to mount root fs on unknown-block(0,0)) > > So I consider it fixed for real now and not just a workaround. > > = > > I also tested with: > > qemu-system-sparc64 -m 512 -kernel vmlinux -append console=3DttyS0 -ser= ial > > stdio > > = > > and it worked in both cases too. > = > FTR, you booted a kernel and got graphics output. The error is simply that > there was no disk to mount? The short version "Yes". The longer version: With "qemu-system-sparc64 -m 512 -kernel vmlinux -append console=3DttyS0 -serial stdio" I got graphical output - one penguin. With "qemu-system-sparc64 -m 512 -kernel vmlinux -append console=3DttyS0 -nographic" I got no graphical output, as implied by the -nographic option. But the boot continued - where it would panic before when we accessed IO memory as system memory. In both cases I got an error because I had not specified any rootfs, so qemu failed to mount any rootfs. So expected. Sam > = > Best regards > Thomas > = > > = > > All the comments above so future-me have an easier time finding how to > > reproduce. > > = > > Tested-by: Sam Ravnborg > > = > > Sam > > = > > > --- > > > Documentation/gpu/todo.rst | 19 ++- > > > drivers/gpu/drm/bochs/bochs_kms.c | 1 - > > > drivers/gpu/drm/drm_fb_helper.c | 217 ++++++++++++++++++++++++++++= -- > > > include/drm/drm_mode_config.h | 12 -- > > > 4 files changed, 220 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 imple= ment > > > -atomic modesetting and GEM vmap support. Current generic fbdev emula= tion > > > -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 =3D 24; > > > bochs->dev->mode_config.prefer_shadow =3D 0; > > > bochs->dev->mode_config.prefer_shadow_fbdev =3D 1; > > > - bochs->dev->mode_config.fbdev_use_iomem =3D true; > > > bochs->dev->mode_config.quirk_addfb_prefer_host_byte_order =3D > > > true; = > > > bochs->dev->mode_config.funcs =3D &bochs_mode_funcs; > > > diff --git a/drivers/gpu/drm/drm_fb_helper.c > > > b/drivers/gpu/drm/drm_fb_helper.c index 6212cd7cde1d..462b0c130ebb 10= 0644 > > > --- 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 =3D fb_helper->fb; > > > unsigned int cpp =3D fb->format->cpp[0]; > > > size_t offset =3D clip->y1 * fb->pitches[0] + clip->x1 * cpp; > > > void *src =3D fb_helper->fbdev->screen_buffer + offset; > > > - void *dst =3D fb_helper->buffer->map.vaddr + offset; > > > size_t len =3D (clip->x2 - clip->x1) * cpp; > > > unsigned int y; > > > = > > > - for (y =3D 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 =3D clip->y1; y < clip->y2; y++) { > > > + dma_buf_map_memcpy_to(dst, src, len); > > > + dma_buf_map_incr(dst, fb->pitches[0]); > > > src +=3D fb->pitches[0]; > > > - dst +=3D fb->pitches[0]; > > > } > > > } > > > = > > > @@ -417,8 +415,9 @@ static void drm_fb_helper_dirty_work(struct > > > work_struct *work) ret =3D drm_client_buffer_vmap(helper->buffer, &ma= p); > > > 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); > > > @@ -755,6 +754,136 @@ void drm_fb_helper_sys_imageblit(struct fb_info > > > *info, } > > > EXPORT_SYMBOL(drm_fb_helper_sys_imageblit); > > > = > > > +static ssize_t drm_fb_helper_cfb_read(struct fb_info *info, char __u= ser > > > *buf, > > > + size_t count, loff_t *ppos) > > > +{ > > > + unsigned long p =3D *ppos; > > > + u8 *dst; > > > + u8 __iomem *src; > > > + int c, err =3D 0; > > > + unsigned long total_size; > > > + unsigned long alloc_size; > > > + ssize_t ret =3D 0; > > > + > > > + if (info->state !=3D FBINFO_STATE_RUNNING) > > > + return -EPERM; > > > + > > > + total_size =3D info->screen_size; > > > + > > > + if (total_size =3D=3D 0) > > > + total_size =3D info->fix.smem_len; > > > + > > > + if (p >=3D total_size) > > > + return 0; > > > + > > > + if (count >=3D total_size) > > > + count =3D total_size; > > > + > > > + if (count + p > total_size) > > > + count =3D total_size - p; > > > + > > > + src =3D (u8 __iomem *)(info->screen_base + p); > > > + > > > + alloc_size =3D min(count, PAGE_SIZE); > > > + > > > + dst =3D kmalloc(alloc_size, GFP_KERNEL); > > > + if (!dst) > > > + return -ENOMEM; > > > + > > > + while (count) { > > > + c =3D min(count, alloc_size); > > > + > > > + memcpy_fromio(dst, src, c); > > > + if (copy_to_user(buf, dst, c)) { > > > + err =3D -EFAULT; > > > + break; > > > + } > > > + > > > + src +=3D c; > > > + *ppos +=3D c; > > > + buf +=3D c; > > > + ret +=3D c; > > > + count -=3D c; > > > + } > > > + > > > + kfree(dst); > > > + > > > + if (err) > > > + return err; > > > + > > > + return ret; > > > +} > > > + > > > +static ssize_t drm_fb_helper_cfb_write(struct fb_info *info, const c= har > > > __user *buf, > > > + size_t count, loff_t *ppos) > > > +{ > > > + unsigned long p =3D *ppos; > > > + u8 *src; > > > + u8 __iomem *dst; > > > + int c, err =3D 0; > > > + unsigned long total_size; > > > + unsigned long alloc_size; > > > + ssize_t ret =3D 0; > > > + > > > + if (info->state !=3D FBINFO_STATE_RUNNING) > > > + return -EPERM; > > > + > > > + total_size =3D info->screen_size; > > > + > > > + if (total_size =3D=3D 0) > > > + total_size =3D info->fix.smem_len; > > > + > > > + if (p > total_size) > > > + return -EFBIG; > > > + > > > + if (count > total_size) { > > > + err =3D -EFBIG; > > > + count =3D total_size; > > > + } > > > + > > > + if (count + p > total_size) { > > > + /* > > > + * The framebuffer is too small. We do the > > > + * copy operation, but return an error code > > > + * afterwards. Taken from fbdev. > > > + */ > > > + if (!err) > > > + err =3D -ENOSPC; > > > + count =3D total_size - p; > > > + } > > > + > > > + alloc_size =3D min(count, PAGE_SIZE); > > > + > > > + src =3D kmalloc(alloc_size, GFP_KERNEL); > > > + if (!src) > > > + return -ENOMEM; > > > + > > > + dst =3D (u8 __iomem *)(info->screen_base + p); > > > + > > > + while (count) { > > > + c =3D min(count, alloc_size); > > > + > > > + if (copy_from_user(src, buf, c)) { > > > + err =3D -EFAULT; > > > + break; > > > + } > > > + memcpy_toio(dst, src, c); > > > + > > > + dst +=3D c; > > > + *ppos +=3D c; > > > + buf +=3D c; > > > + ret +=3D c; > > > + count -=3D c; > > > + } > > > + > > > + kfree(src); > > > + > > > + if (err) > > > + return err; > > > + > > > + return ret; > > > +} > > > + > > > /** > > > * drm_fb_helper_cfb_fillrect - wrapper around cfb_fillrect > > > * @info: fbdev registered by the helper > > > @@ -2027,6 +2156,66 @@ static int drm_fbdev_fb_mmap(struct fb_info *i= nfo, > > > struct vm_area_struct *vma) return -ENODEV; > > > } > > > = > > > +static ssize_t drm_fbdev_fb_read(struct fb_info *info, char __user *= buf, > > > + size_t count, loff_t *ppos) > > > +{ > > > + struct drm_fb_helper *fb_helper =3D info->par; > > > + struct drm_client_buffer *buffer =3D fb_helper->buffer; > > > + > > > + if (drm_fbdev_use_shadow_fb(fb_helper) || !buffer->map.is_iomem) > > > + return drm_fb_helper_sys_read(info, buf, count, ppos); > > > + else > > > + return drm_fb_helper_cfb_read(info, buf, count, ppos); > > > +} > > > + > > > +static ssize_t drm_fbdev_fb_write(struct fb_info *info, const char > > > __user *buf, > > > + size_t count, loff_t *ppos) > > > +{ > > > + struct drm_fb_helper *fb_helper =3D info->par; > > > + struct drm_client_buffer *buffer =3D fb_helper->buffer; > > > + > > > + if (drm_fbdev_use_shadow_fb(fb_helper) || !buffer->map.is_iomem) > > > + return drm_fb_helper_sys_write(info, buf, count, ppos); > > > + else > > > + return drm_fb_helper_cfb_write(info, buf, count, ppos); > > > +} > > > + > > > +static void drm_fbdev_fb_fillrect(struct fb_info *info, > > > + const struct fb_fillrect *rect) > > > +{ > > > + struct drm_fb_helper *fb_helper =3D info->par; > > > + struct drm_client_buffer *buffer =3D fb_helper->buffer; > > > + > > > + if (drm_fbdev_use_shadow_fb(fb_helper) || !buffer->map.is_iomem) > > > + drm_fb_helper_sys_fillrect(info, rect); > > > + else > > > + drm_fb_helper_cfb_fillrect(info, rect); > > > +} > > > + > > > +static void drm_fbdev_fb_copyarea(struct fb_info *info, > > > + const struct fb_copyarea *area) > > > +{ > > > + struct drm_fb_helper *fb_helper =3D info->par; > > > + struct drm_client_buffer *buffer =3D fb_helper->buffer; > > > + > > > + if (drm_fbdev_use_shadow_fb(fb_helper) || !buffer->map.is_iomem) > > > + drm_fb_helper_sys_copyarea(info, area); > > > + else > > > + drm_fb_helper_cfb_copyarea(info, area); > > > +} > > > + > > > +static void drm_fbdev_fb_imageblit(struct fb_info *info, > > > + const struct fb_image *image) > > > +{ > > > + struct drm_fb_helper *fb_helper =3D info->par; > > > + struct drm_client_buffer *buffer =3D fb_helper->buffer; > > > + > > > + if (drm_fbdev_use_shadow_fb(fb_helper) || !buffer->map.is_iomem) > > > + drm_fb_helper_sys_imageblit(info, image); > > > + else > > > + drm_fb_helper_cfb_imageblit(info, image); > > > +} > > > + > > > static const struct fb_ops drm_fbdev_fb_ops =3D { > > > .owner =3D THIS_MODULE, > > > DRM_FB_HELPER_DEFAULT_OPS, > > > @@ -2034,11 +2223,11 @@ static const struct fb_ops drm_fbdev_fb_ops = =3D { > > > .fb_release =3D drm_fbdev_fb_release, > > > .fb_destroy =3D drm_fbdev_fb_destroy, > > > .fb_mmap =3D drm_fbdev_fb_mmap, > > > - .fb_read =3D drm_fb_helper_sys_read, > > > - .fb_write =3D drm_fb_helper_sys_write, > > > - .fb_fillrect =3D drm_fb_helper_sys_fillrect, > > > - .fb_copyarea =3D drm_fb_helper_sys_copyarea, > > > - .fb_imageblit =3D drm_fb_helper_sys_imageblit, > > > + .fb_read =3D drm_fbdev_fb_read, > > > + .fb_write =3D drm_fbdev_fb_write, > > > + .fb_fillrect =3D drm_fbdev_fb_fillrect, > > > + .fb_copyarea =3D drm_fbdev_fb_copyarea, > > > + .fb_imageblit =3D drm_fbdev_fb_imageblit, > > > }; > > > = > > > static struct fb_deferred_io drm_fbdev_defio =3D { > > > diff --git a/include/drm/drm_mode_config.h b/include/drm/drm_mode_con= fig.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 > = > = > = > -- = > Thomas Zimmermann > Graphics Driver Developer > SUSE Software Solutions Germany GmbH > Maxfeldstr. 5, 90409 N=FCrnberg, Germany > (HRB 36809, AG N=FCrnberg) > Gesch=E4ftsf=FChrer: Felix Imend=F6rffer _______________________________________________ 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.7 required=3.0 tests=BAYES_00, 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 15436C43467 for ; Fri, 16 Oct 2020 12:49:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ADBD1207DE for ; Fri, 16 Oct 2020 12:49:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405356AbgJPMtE (ORCPT ); Fri, 16 Oct 2020 08:49:04 -0400 Received: from asavdk4.altibox.net ([109.247.116.15]:36718 "EHLO asavdk4.altibox.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2394663AbgJPMtD (ORCPT ); Fri, 16 Oct 2020 08:49:03 -0400 Received: from ravnborg.org (unknown [188.228.123.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by asavdk4.altibox.net (Postfix) with ESMTPS id 383A2806F9; Fri, 16 Oct 2020 14:48:52 +0200 (CEST) Date: Fri, 16 Oct 2020 14:48:50 +0200 From: Sam Ravnborg To: Thomas Zimmermann Cc: maarten.lankhorst@linux.intel.com, mripard@kernel.org, airlied@linux.ie, daniel@ffwll.ch, 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 v4 10/10] drm/fb_helper: Support framebuffers in I/O memory Message-ID: <20201016124850.GA1174599@ravnborg.org> References: <20201015123806.32416-1-tzimmermann@suse.de> <20201015123806.32416-11-tzimmermann@suse.de> <20201016120347.GB1125266@ravnborg.org> <20201016141942.111e17f3@linux-uq9g> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20201016141942.111e17f3@linux-uq9g> X-CMAE-Score: 0 X-CMAE-Analysis: v=2.3 cv=fu7ymmwf c=1 sm=1 tr=0 a=S6zTFyMACwkrwXSdXUNehg==:117 a=S6zTFyMACwkrwXSdXUNehg==:17 a=8nJEP1OIZ-IA:10 a=7gkXJVJtAAAA:8 a=6Hpfs63HWkxrz3fWGNMA:9 a=w4pgIJ6L-nyCBc2a:21 a=gikFlJ38tUkSyios:21 a=wPNLvfGTeEIA:10 a=qfUslh1TxfEA:10 a=E9Po1WZjFZOl8hwRPBS3:22 Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org On Fri, Oct 16, 2020 at 02:19:42PM +0200, Thomas Zimmermann wrote: > Hi > > On Fri, 16 Oct 2020 14:03:47 +0200 Sam Ravnborg wrote: > > > Hi Thomas. > > > > On Thu, Oct 15, 2020 at 02:38:06PM +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. > > > > > > 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. > > > > > > v4: > > > * move dma_buf_map changes into separate patch (Daniel) > > > * TODO list: comment on fbdev updates (Daniel) > > > > > > Signed-off-by: Thomas Zimmermann > > > > The original workaround fixed it so we could run qemu with the > > -nographic option. > > > > So I went ahead and tried to run quemu version: > > v5.0.0-1970-g0b100c8e72-dirty. > > And with the BOCHS driver built-in. > > > > With the following command line: > > qemu-system-sparc64 -m 512 -kernel vmlinux -append console=ttyS0 -nographic > > > > Behaviour was the same before and after applying this patch. > > (panic due to VFS: Unable to mount root fs on unknown-block(0,0)) > > So I consider it fixed for real now and not just a workaround. > > > > I also tested with: > > qemu-system-sparc64 -m 512 -kernel vmlinux -append console=ttyS0 -serial > > stdio > > > > and it worked in both cases too. > > FTR, you booted a kernel and got graphics output. The error is simply that > there was no disk to mount? The short version "Yes". The longer version: With "qemu-system-sparc64 -m 512 -kernel vmlinux -append console=ttyS0 -serial stdio" I got graphical output - one penguin. With "qemu-system-sparc64 -m 512 -kernel vmlinux -append console=ttyS0 -nographic" I got no graphical output, as implied by the -nographic option. But the boot continued - where it would panic before when we accessed IO memory as system memory. In both cases I got an error because I had not specified any rootfs, so qemu failed to mount any rootfs. So expected. Sam > > Best regards > Thomas > > > > > All the comments above so future-me have an easier time finding how to > > reproduce. > > > > Tested-by: Sam Ravnborg > > > > Sam > > > > > --- > > > Documentation/gpu/todo.rst | 19 ++- > > > drivers/gpu/drm/bochs/bochs_kms.c | 1 - > > > drivers/gpu/drm/drm_fb_helper.c | 217 ++++++++++++++++++++++++++++-- > > > include/drm/drm_mode_config.h | 12 -- > > > 4 files changed, 220 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..462b0c130ebb 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); > > > @@ -755,6 +754,136 @@ void drm_fb_helper_sys_imageblit(struct fb_info > > > *info, } > > > EXPORT_SYMBOL(drm_fb_helper_sys_imageblit); > > > > > > +static ssize_t drm_fb_helper_cfb_read(struct fb_info *info, char __user > > > *buf, > > > + size_t count, loff_t *ppos) > > > +{ > > > + unsigned long p = *ppos; > > > + u8 *dst; > > > + u8 __iomem *src; > > > + int c, err = 0; > > > + unsigned long total_size; > > > + unsigned long alloc_size; > > > + ssize_t ret = 0; > > > + > > > + if (info->state != FBINFO_STATE_RUNNING) > > > + return -EPERM; > > > + > > > + total_size = info->screen_size; > > > + > > > + if (total_size == 0) > > > + total_size = info->fix.smem_len; > > > + > > > + if (p >= total_size) > > > + return 0; > > > + > > > + if (count >= total_size) > > > + count = total_size; > > > + > > > + if (count + p > total_size) > > > + count = total_size - p; > > > + > > > + src = (u8 __iomem *)(info->screen_base + p); > > > + > > > + alloc_size = min(count, PAGE_SIZE); > > > + > > > + dst = kmalloc(alloc_size, GFP_KERNEL); > > > + if (!dst) > > > + return -ENOMEM; > > > + > > > + while (count) { > > > + c = min(count, alloc_size); > > > + > > > + memcpy_fromio(dst, src, c); > > > + if (copy_to_user(buf, dst, c)) { > > > + err = -EFAULT; > > > + break; > > > + } > > > + > > > + src += c; > > > + *ppos += c; > > > + buf += c; > > > + ret += c; > > > + count -= c; > > > + } > > > + > > > + kfree(dst); > > > + > > > + if (err) > > > + return err; > > > + > > > + return ret; > > > +} > > > + > > > +static ssize_t drm_fb_helper_cfb_write(struct fb_info *info, const char > > > __user *buf, > > > + size_t count, loff_t *ppos) > > > +{ > > > + unsigned long p = *ppos; > > > + u8 *src; > > > + u8 __iomem *dst; > > > + int c, err = 0; > > > + unsigned long total_size; > > > + unsigned long alloc_size; > > > + ssize_t ret = 0; > > > + > > > + if (info->state != FBINFO_STATE_RUNNING) > > > + return -EPERM; > > > + > > > + total_size = info->screen_size; > > > + > > > + if (total_size == 0) > > > + total_size = info->fix.smem_len; > > > + > > > + if (p > total_size) > > > + return -EFBIG; > > > + > > > + if (count > total_size) { > > > + err = -EFBIG; > > > + count = total_size; > > > + } > > > + > > > + if (count + p > total_size) { > > > + /* > > > + * The framebuffer is too small. We do the > > > + * copy operation, but return an error code > > > + * afterwards. Taken from fbdev. > > > + */ > > > + if (!err) > > > + err = -ENOSPC; > > > + count = total_size - p; > > > + } > > > + > > > + alloc_size = min(count, PAGE_SIZE); > > > + > > > + src = kmalloc(alloc_size, GFP_KERNEL); > > > + if (!src) > > > + return -ENOMEM; > > > + > > > + dst = (u8 __iomem *)(info->screen_base + p); > > > + > > > + while (count) { > > > + c = min(count, alloc_size); > > > + > > > + if (copy_from_user(src, buf, c)) { > > > + err = -EFAULT; > > > + break; > > > + } > > > + memcpy_toio(dst, src, c); > > > + > > > + dst += c; > > > + *ppos += c; > > > + buf += c; > > > + ret += c; > > > + count -= c; > > > + } > > > + > > > + kfree(src); > > > + > > > + if (err) > > > + return err; > > > + > > > + return ret; > > > +} > > > + > > > /** > > > * drm_fb_helper_cfb_fillrect - wrapper around cfb_fillrect > > > * @info: fbdev registered by the helper > > > @@ -2027,6 +2156,66 @@ static int drm_fbdev_fb_mmap(struct fb_info *info, > > > struct vm_area_struct *vma) return -ENODEV; > > > } > > > > > > +static ssize_t drm_fbdev_fb_read(struct fb_info *info, char __user *buf, > > > + size_t count, loff_t *ppos) > > > +{ > > > + struct drm_fb_helper *fb_helper = info->par; > > > + struct drm_client_buffer *buffer = fb_helper->buffer; > > > + > > > + if (drm_fbdev_use_shadow_fb(fb_helper) || !buffer->map.is_iomem) > > > + return drm_fb_helper_sys_read(info, buf, count, ppos); > > > + else > > > + return drm_fb_helper_cfb_read(info, buf, count, ppos); > > > +} > > > + > > > +static ssize_t drm_fbdev_fb_write(struct fb_info *info, const char > > > __user *buf, > > > + size_t count, loff_t *ppos) > > > +{ > > > + struct drm_fb_helper *fb_helper = info->par; > > > + struct drm_client_buffer *buffer = fb_helper->buffer; > > > + > > > + if (drm_fbdev_use_shadow_fb(fb_helper) || !buffer->map.is_iomem) > > > + return drm_fb_helper_sys_write(info, buf, count, ppos); > > > + else > > > + return drm_fb_helper_cfb_write(info, buf, count, ppos); > > > +} > > > + > > > +static void drm_fbdev_fb_fillrect(struct fb_info *info, > > > + const struct fb_fillrect *rect) > > > +{ > > > + struct drm_fb_helper *fb_helper = info->par; > > > + struct drm_client_buffer *buffer = fb_helper->buffer; > > > + > > > + if (drm_fbdev_use_shadow_fb(fb_helper) || !buffer->map.is_iomem) > > > + drm_fb_helper_sys_fillrect(info, rect); > > > + else > > > + drm_fb_helper_cfb_fillrect(info, rect); > > > +} > > > + > > > +static void drm_fbdev_fb_copyarea(struct fb_info *info, > > > + const struct fb_copyarea *area) > > > +{ > > > + struct drm_fb_helper *fb_helper = info->par; > > > + struct drm_client_buffer *buffer = fb_helper->buffer; > > > + > > > + if (drm_fbdev_use_shadow_fb(fb_helper) || !buffer->map.is_iomem) > > > + drm_fb_helper_sys_copyarea(info, area); > > > + else > > > + drm_fb_helper_cfb_copyarea(info, area); > > > +} > > > + > > > +static void drm_fbdev_fb_imageblit(struct fb_info *info, > > > + const struct fb_image *image) > > > +{ > > > + struct drm_fb_helper *fb_helper = info->par; > > > + struct drm_client_buffer *buffer = fb_helper->buffer; > > > + > > > + if (drm_fbdev_use_shadow_fb(fb_helper) || !buffer->map.is_iomem) > > > + drm_fb_helper_sys_imageblit(info, image); > > > + else > > > + drm_fb_helper_cfb_imageblit(info, image); > > > +} > > > + > > > static const struct fb_ops drm_fbdev_fb_ops = { > > > .owner = THIS_MODULE, > > > DRM_FB_HELPER_DEFAULT_OPS, > > > @@ -2034,11 +2223,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 > > > > -- > Thomas Zimmermann > Graphics Driver Developer > SUSE Software Solutions Germany GmbH > Maxfeldstr. 5, 90409 Nürnberg, Germany > (HRB 36809, AG Nürnberg) > Geschäftsführer: Felix Imendörffer From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sam Ravnborg Subject: Re: [PATCH v4 10/10] drm/fb_helper: Support framebuffers in I/O memory Date: Fri, 16 Oct 2020 14:48:50 +0200 Message-ID: <20201016124850.GA1174599@ravnborg.org> References: <20201015123806.32416-1-tzimmermann@suse.de> <20201015123806.32416-11-tzimmermann@suse.de> <20201016120347.GB1125266@ravnborg.org> <20201016141942.111e17f3@linux-uq9g> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Return-path: Content-Disposition: inline In-Reply-To: <20201016141942.111e17f3@linux-uq9g> 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, 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, alyssa.rosenzweig-ZGY8ohtN/8qB+jHODAdFcQ@public.gmane.org, linux+etnaviv-I+IVW8TIWO2tmTQ+vhA3Yw@public.gmane.org, spice-devel-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org, bskeggs-H+wXaHxf7aLQT0dZR+AlfA@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-cunTk1MwBs9QetFLy7KEmxxBWXNxL4zz@public.gmane.org List-Id: nouveau.vger.kernel.org On Fri, Oct 16, 2020 at 02:19:42PM +0200, Thomas Zimmermann wrote: > Hi > = > On Fri, 16 Oct 2020 14:03:47 +0200 Sam Ravnborg wrote: > = > > Hi Thomas. > > = > > On Thu, Oct 15, 2020 at 02:38:06PM +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 r= sp > > > fb_sys_ of fb_cfb_ functions. > > > = > > > For drivers that employ a shadow buffer, fbdev's blit function retrie= ves > > > 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 r= sp > > > code from both, bochs and fbdev. > > > = > > > v4: > > > * move dma_buf_map changes into separate patch (Daniel) > > > * TODO list: comment on fbdev updates (Daniel) > > > = > > > Signed-off-by: Thomas Zimmermann > > = > > The original workaround fixed it so we could run qemu with the > > -nographic option. > > = > > So I went ahead and tried to run quemu version: > > v5.0.0-1970-g0b100c8e72-dirty. > > And with the BOCHS driver built-in. > > = > > With the following command line: > > qemu-system-sparc64 -m 512 -kernel vmlinux -append console=3DttyS0 -nog= raphic > > = > > Behaviour was the same before and after applying this patch. > > (panic due to VFS: Unable to mount root fs on unknown-block(0,0)) > > So I consider it fixed for real now and not just a workaround. > > = > > I also tested with: > > qemu-system-sparc64 -m 512 -kernel vmlinux -append console=3DttyS0 -ser= ial > > stdio > > = > > and it worked in both cases too. > = > FTR, you booted a kernel and got graphics output. The error is simply that > there was no disk to mount? The short version "Yes". The longer version: With "qemu-system-sparc64 -m 512 -kernel vmlinux -append console=3DttyS0 -serial stdio" I got graphical output - one penguin. With "qemu-system-sparc64 -m 512 -kernel vmlinux -append console=3DttyS0 -nographic" I got no graphical output, as implied by the -nographic option. But the boot continued - where it would panic before when we accessed IO memory as system memory. In both cases I got an error because I had not specified any rootfs, so qemu failed to mount any rootfs. So expected. Sam > = > Best regards > Thomas > = > > = > > All the comments above so future-me have an easier time finding how to > > reproduce. > > = > > Tested-by: Sam Ravnborg > > = > > Sam > > = > > > --- > > > Documentation/gpu/todo.rst | 19 ++- > > > drivers/gpu/drm/bochs/bochs_kms.c | 1 - > > > drivers/gpu/drm/drm_fb_helper.c | 217 ++++++++++++++++++++++++++++= -- > > > include/drm/drm_mode_config.h | 12 -- > > > 4 files changed, 220 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 imple= ment > > > -atomic modesetting and GEM vmap support. Current generic fbdev emula= tion > > > -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 =3D 24; > > > bochs->dev->mode_config.prefer_shadow =3D 0; > > > bochs->dev->mode_config.prefer_shadow_fbdev =3D 1; > > > - bochs->dev->mode_config.fbdev_use_iomem =3D true; > > > bochs->dev->mode_config.quirk_addfb_prefer_host_byte_order =3D > > > true; = > > > bochs->dev->mode_config.funcs =3D &bochs_mode_funcs; > > > diff --git a/drivers/gpu/drm/drm_fb_helper.c > > > b/drivers/gpu/drm/drm_fb_helper.c index 6212cd7cde1d..462b0c130ebb 10= 0644 > > > --- 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 =3D fb_helper->fb; > > > unsigned int cpp =3D fb->format->cpp[0]; > > > size_t offset =3D clip->y1 * fb->pitches[0] + clip->x1 * cpp; > > > void *src =3D fb_helper->fbdev->screen_buffer + offset; > > > - void *dst =3D fb_helper->buffer->map.vaddr + offset; > > > size_t len =3D (clip->x2 - clip->x1) * cpp; > > > unsigned int y; > > > = > > > - for (y =3D 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 =3D clip->y1; y < clip->y2; y++) { > > > + dma_buf_map_memcpy_to(dst, src, len); > > > + dma_buf_map_incr(dst, fb->pitches[0]); > > > src +=3D fb->pitches[0]; > > > - dst +=3D fb->pitches[0]; > > > } > > > } > > > = > > > @@ -417,8 +415,9 @@ static void drm_fb_helper_dirty_work(struct > > > work_struct *work) ret =3D drm_client_buffer_vmap(helper->buffer, &ma= p); > > > 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); > > > @@ -755,6 +754,136 @@ void drm_fb_helper_sys_imageblit(struct fb_info > > > *info, } > > > EXPORT_SYMBOL(drm_fb_helper_sys_imageblit); > > > = > > > +static ssize_t drm_fb_helper_cfb_read(struct fb_info *info, char __u= ser > > > *buf, > > > + size_t count, loff_t *ppos) > > > +{ > > > + unsigned long p =3D *ppos; > > > + u8 *dst; > > > + u8 __iomem *src; > > > + int c, err =3D 0; > > > + unsigned long total_size; > > > + unsigned long alloc_size; > > > + ssize_t ret =3D 0; > > > + > > > + if (info->state !=3D FBINFO_STATE_RUNNING) > > > + return -EPERM; > > > + > > > + total_size =3D info->screen_size; > > > + > > > + if (total_size =3D=3D 0) > > > + total_size =3D info->fix.smem_len; > > > + > > > + if (p >=3D total_size) > > > + return 0; > > > + > > > + if (count >=3D total_size) > > > + count =3D total_size; > > > + > > > + if (count + p > total_size) > > > + count =3D total_size - p; > > > + > > > + src =3D (u8 __iomem *)(info->screen_base + p); > > > + > > > + alloc_size =3D min(count, PAGE_SIZE); > > > + > > > + dst =3D kmalloc(alloc_size, GFP_KERNEL); > > > + if (!dst) > > > + return -ENOMEM; > > > + > > > + while (count) { > > > + c =3D min(count, alloc_size); > > > + > > > + memcpy_fromio(dst, src, c); > > > + if (copy_to_user(buf, dst, c)) { > > > + err =3D -EFAULT; > > > + break; > > > + } > > > + > > > + src +=3D c; > > > + *ppos +=3D c; > > > + buf +=3D c; > > > + ret +=3D c; > > > + count -=3D c; > > > + } > > > + > > > + kfree(dst); > > > + > > > + if (err) > > > + return err; > > > + > > > + return ret; > > > +} > > > + > > > +static ssize_t drm_fb_helper_cfb_write(struct fb_info *info, const c= har > > > __user *buf, > > > + size_t count, loff_t *ppos) > > > +{ > > > + unsigned long p =3D *ppos; > > > + u8 *src; > > > + u8 __iomem *dst; > > > + int c, err =3D 0; > > > + unsigned long total_size; > > > + unsigned long alloc_size; > > > + ssize_t ret =3D 0; > > > + > > > + if (info->state !=3D FBINFO_STATE_RUNNING) > > > + return -EPERM; > > > + > > > + total_size =3D info->screen_size; > > > + > > > + if (total_size =3D=3D 0) > > > + total_size =3D info->fix.smem_len; > > > + > > > + if (p > total_size) > > > + return -EFBIG; > > > + > > > + if (count > total_size) { > > > + err =3D -EFBIG; > > > + count =3D total_size; > > > + } > > > + > > > + if (count + p > total_size) { > > > + /* > > > + * The framebuffer is too small. We do the > > > + * copy operation, but return an error code > > > + * afterwards. Taken from fbdev. > > > + */ > > > + if (!err) > > > + err =3D -ENOSPC; > > > + count =3D total_size - p; > > > + } > > > + > > > + alloc_size =3D min(count, PAGE_SIZE); > > > + > > > + src =3D kmalloc(alloc_size, GFP_KERNEL); > > > + if (!src) > > > + return -ENOMEM; > > > + > > > + dst =3D (u8 __iomem *)(info->screen_base + p); > > > + > > > + while (count) { > > > + c =3D min(count, alloc_size); > > > + > > > + if (copy_from_user(src, buf, c)) { > > > + err =3D -EFAULT; > > > + break; > > > + } > > > + memcpy_toio(dst, src, c); > > > + > > > + dst +=3D c; > > > + *ppos +=3D c; > > > + buf +=3D c; > > > + ret +=3D c; > > > + count -=3D c; > > > + } > > > + > > > + kfree(src); > > > + > > > + if (err) > > > + return err; > > > + > > > + return ret; > > > +} > > > + > > > /** > > > * drm_fb_helper_cfb_fillrect - wrapper around cfb_fillrect > > > * @info: fbdev registered by the helper > > > @@ -2027,6 +2156,66 @@ static int drm_fbdev_fb_mmap(struct fb_info *i= nfo, > > > struct vm_area_struct *vma) return -ENODEV; > > > } > > > = > > > +static ssize_t drm_fbdev_fb_read(struct fb_info *info, char __user *= buf, > > > + size_t count, loff_t *ppos) > > > +{ > > > + struct drm_fb_helper *fb_helper =3D info->par; > > > + struct drm_client_buffer *buffer =3D fb_helper->buffer; > > > + > > > + if (drm_fbdev_use_shadow_fb(fb_helper) || !buffer->map.is_iomem) > > > + return drm_fb_helper_sys_read(info, buf, count, ppos); > > > + else > > > + return drm_fb_helper_cfb_read(info, buf, count, ppos); > > > +} > > > + > > > +static ssize_t drm_fbdev_fb_write(struct fb_info *info, const char > > > __user *buf, > > > + size_t count, loff_t *ppos) > > > +{ > > > + struct drm_fb_helper *fb_helper =3D info->par; > > > + struct drm_client_buffer *buffer =3D fb_helper->buffer; > > > + > > > + if (drm_fbdev_use_shadow_fb(fb_helper) || !buffer->map.is_iomem) > > > + return drm_fb_helper_sys_write(info, buf, count, ppos); > > > + else > > > + return drm_fb_helper_cfb_write(info, buf, count, ppos); > > > +} > > > + > > > +static void drm_fbdev_fb_fillrect(struct fb_info *info, > > > + const struct fb_fillrect *rect) > > > +{ > > > + struct drm_fb_helper *fb_helper =3D info->par; > > > + struct drm_client_buffer *buffer =3D fb_helper->buffer; > > > + > > > + if (drm_fbdev_use_shadow_fb(fb_helper) || !buffer->map.is_iomem) > > > + drm_fb_helper_sys_fillrect(info, rect); > > > + else > > > + drm_fb_helper_cfb_fillrect(info, rect); > > > +} > > > + > > > +static void drm_fbdev_fb_copyarea(struct fb_info *info, > > > + const struct fb_copyarea *area) > > > +{ > > > + struct drm_fb_helper *fb_helper =3D info->par; > > > + struct drm_client_buffer *buffer =3D fb_helper->buffer; > > > + > > > + if (drm_fbdev_use_shadow_fb(fb_helper) || !buffer->map.is_iomem) > > > + drm_fb_helper_sys_copyarea(info, area); > > > + else > > > + drm_fb_helper_cfb_copyarea(info, area); > > > +} > > > + > > > +static void drm_fbdev_fb_imageblit(struct fb_info *info, > > > + const struct fb_image *image) > > > +{ > > > + struct drm_fb_helper *fb_helper =3D info->par; > > > + struct drm_client_buffer *buffer =3D fb_helper->buffer; > > > + > > > + if (drm_fbdev_use_shadow_fb(fb_helper) || !buffer->map.is_iomem) > > > + drm_fb_helper_sys_imageblit(info, image); > > > + else > > > + drm_fb_helper_cfb_imageblit(info, image); > > > +} > > > + > > > static const struct fb_ops drm_fbdev_fb_ops =3D { > > > .owner =3D THIS_MODULE, > > > DRM_FB_HELPER_DEFAULT_OPS, > > > @@ -2034,11 +2223,11 @@ static const struct fb_ops drm_fbdev_fb_ops = =3D { > > > .fb_release =3D drm_fbdev_fb_release, > > > .fb_destroy =3D drm_fbdev_fb_destroy, > > > .fb_mmap =3D drm_fbdev_fb_mmap, > > > - .fb_read =3D drm_fb_helper_sys_read, > > > - .fb_write =3D drm_fb_helper_sys_write, > > > - .fb_fillrect =3D drm_fb_helper_sys_fillrect, > > > - .fb_copyarea =3D drm_fb_helper_sys_copyarea, > > > - .fb_imageblit =3D drm_fb_helper_sys_imageblit, > > > + .fb_read =3D drm_fbdev_fb_read, > > > + .fb_write =3D drm_fbdev_fb_write, > > > + .fb_fillrect =3D drm_fbdev_fb_fillrect, > > > + .fb_copyarea =3D drm_fbdev_fb_copyarea, > > > + .fb_imageblit =3D drm_fbdev_fb_imageblit, > > > }; > > > = > > > static struct fb_deferred_io drm_fbdev_defio =3D { > > > diff --git a/include/drm/drm_mode_config.h b/include/drm/drm_mode_con= fig.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 > = > = > = > -- = > Thomas Zimmermann > Graphics Driver Developer > SUSE Software Solutions Germany GmbH > Maxfeldstr. 5, 90409 N=FCrnberg, Germany > (HRB 36809, AG N=FCrnberg) > Gesch=E4ftsf=FChrer: Felix Imend=F6rffer 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.7 required=3.0 tests=BAYES_00, 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 672CCC433DF for ; Fri, 16 Oct 2020 12:49:21 +0000 (UTC) Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (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 C7C79207DE for ; Fri, 16 Oct 2020 12:49:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C7C79207DE Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ravnborg.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=virtualization-bounces@lists.linux-foundation.org Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 00CFC2E2EB; Fri, 16 Oct 2020 12:49:20 +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 p4Gq3V0FXj0P; Fri, 16 Oct 2020 12:49:05 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by silver.osuosl.org (Postfix) with ESMTP id 32E8B20495; Fri, 16 Oct 2020 12:49:05 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 06DB3C07FF; Fri, 16 Oct 2020 12:49:05 +0000 (UTC) Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 5526CC0051 for ; Fri, 16 Oct 2020 12:49:03 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 3B27088251 for ; Fri, 16 Oct 2020 12:49:03 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id mCPmBBro61TS for ; Fri, 16 Oct 2020 12:49:01 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from asavdk4.altibox.net (asavdk4.altibox.net [109.247.116.15]) by hemlock.osuosl.org (Postfix) with ESMTPS id C224F8824F for ; Fri, 16 Oct 2020 12:49:00 +0000 (UTC) Received: from ravnborg.org (unknown [188.228.123.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by asavdk4.altibox.net (Postfix) with ESMTPS id 383A2806F9; Fri, 16 Oct 2020 14:48:52 +0200 (CEST) Date: Fri, 16 Oct 2020 14:48:50 +0200 From: Sam Ravnborg To: Thomas Zimmermann Subject: Re: [PATCH v4 10/10] drm/fb_helper: Support framebuffers in I/O memory Message-ID: <20201016124850.GA1174599@ravnborg.org> References: <20201015123806.32416-1-tzimmermann@suse.de> <20201015123806.32416-11-tzimmermann@suse.de> <20201016120347.GB1125266@ravnborg.org> <20201016141942.111e17f3@linux-uq9g> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20201016141942.111e17f3@linux-uq9g> X-CMAE-Score: 0 X-CMAE-Analysis: v=2.3 cv=fu7ymmwf c=1 sm=1 tr=0 a=S6zTFyMACwkrwXSdXUNehg==:117 a=S6zTFyMACwkrwXSdXUNehg==:17 a=8nJEP1OIZ-IA:10 a=7gkXJVJtAAAA:8 a=6Hpfs63HWkxrz3fWGNMA:9 a=w4pgIJ6L-nyCBc2a:21 a=gikFlJ38tUkSyios:21 a=wPNLvfGTeEIA:10 a=qfUslh1TxfEA:10 a=E9Po1WZjFZOl8hwRPBS3:22 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, 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, alyssa.rosenzweig@collabora.com, linux+etnaviv@armlinux.org.uk, spice-devel@lists.freedesktop.org, bskeggs@redhat.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="iso-8859-1" Content-Transfer-Encoding: quoted-printable Errors-To: virtualization-bounces@lists.linux-foundation.org Sender: "Virtualization" On Fri, Oct 16, 2020 at 02:19:42PM +0200, Thomas Zimmermann wrote: > Hi > = > On Fri, 16 Oct 2020 14:03:47 +0200 Sam Ravnborg wrote: > = > > Hi Thomas. > > = > > On Thu, Oct 15, 2020 at 02:38:06PM +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 r= sp > > > fb_sys_ of fb_cfb_ functions. > > > = > > > For drivers that employ a shadow buffer, fbdev's blit function retrie= ves > > > 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 r= sp > > > code from both, bochs and fbdev. > > > = > > > v4: > > > * move dma_buf_map changes into separate patch (Daniel) > > > * TODO list: comment on fbdev updates (Daniel) > > > = > > > Signed-off-by: Thomas Zimmermann > > = > > The original workaround fixed it so we could run qemu with the > > -nographic option. > > = > > So I went ahead and tried to run quemu version: > > v5.0.0-1970-g0b100c8e72-dirty. > > And with the BOCHS driver built-in. > > = > > With the following command line: > > qemu-system-sparc64 -m 512 -kernel vmlinux -append console=3DttyS0 -nog= raphic > > = > > Behaviour was the same before and after applying this patch. > > (panic due to VFS: Unable to mount root fs on unknown-block(0,0)) > > So I consider it fixed for real now and not just a workaround. > > = > > I also tested with: > > qemu-system-sparc64 -m 512 -kernel vmlinux -append console=3DttyS0 -ser= ial > > stdio > > = > > and it worked in both cases too. > = > FTR, you booted a kernel and got graphics output. The error is simply that > there was no disk to mount? The short version "Yes". The longer version: With "qemu-system-sparc64 -m 512 -kernel vmlinux -append console=3DttyS0 -serial stdio" I got graphical output - one penguin. With "qemu-system-sparc64 -m 512 -kernel vmlinux -append console=3DttyS0 -nographic" I got no graphical output, as implied by the -nographic option. But the boot continued - where it would panic before when we accessed IO memory as system memory. In both cases I got an error because I had not specified any rootfs, so qemu failed to mount any rootfs. So expected. Sam > = > Best regards > Thomas > = > > = > > All the comments above so future-me have an easier time finding how to > > reproduce. > > = > > Tested-by: Sam Ravnborg > > = > > Sam > > = > > > --- > > > Documentation/gpu/todo.rst | 19 ++- > > > drivers/gpu/drm/bochs/bochs_kms.c | 1 - > > > drivers/gpu/drm/drm_fb_helper.c | 217 ++++++++++++++++++++++++++++= -- > > > include/drm/drm_mode_config.h | 12 -- > > > 4 files changed, 220 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 imple= ment > > > -atomic modesetting and GEM vmap support. Current generic fbdev emula= tion > > > -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 =3D 24; > > > bochs->dev->mode_config.prefer_shadow =3D 0; > > > bochs->dev->mode_config.prefer_shadow_fbdev =3D 1; > > > - bochs->dev->mode_config.fbdev_use_iomem =3D true; > > > bochs->dev->mode_config.quirk_addfb_prefer_host_byte_order =3D > > > true; = > > > bochs->dev->mode_config.funcs =3D &bochs_mode_funcs; > > > diff --git a/drivers/gpu/drm/drm_fb_helper.c > > > b/drivers/gpu/drm/drm_fb_helper.c index 6212cd7cde1d..462b0c130ebb 10= 0644 > > > --- 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 =3D fb_helper->fb; > > > unsigned int cpp =3D fb->format->cpp[0]; > > > size_t offset =3D clip->y1 * fb->pitches[0] + clip->x1 * cpp; > > > void *src =3D fb_helper->fbdev->screen_buffer + offset; > > > - void *dst =3D fb_helper->buffer->map.vaddr + offset; > > > size_t len =3D (clip->x2 - clip->x1) * cpp; > > > unsigned int y; > > > = > > > - for (y =3D 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 =3D clip->y1; y < clip->y2; y++) { > > > + dma_buf_map_memcpy_to(dst, src, len); > > > + dma_buf_map_incr(dst, fb->pitches[0]); > > > src +=3D fb->pitches[0]; > > > - dst +=3D fb->pitches[0]; > > > } > > > } > > > = > > > @@ -417,8 +415,9 @@ static void drm_fb_helper_dirty_work(struct > > > work_struct *work) ret =3D drm_client_buffer_vmap(helper->buffer, &ma= p); > > > 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); > > > @@ -755,6 +754,136 @@ void drm_fb_helper_sys_imageblit(struct fb_info > > > *info, } > > > EXPORT_SYMBOL(drm_fb_helper_sys_imageblit); > > > = > > > +static ssize_t drm_fb_helper_cfb_read(struct fb_info *info, char __u= ser > > > *buf, > > > + size_t count, loff_t *ppos) > > > +{ > > > + unsigned long p =3D *ppos; > > > + u8 *dst; > > > + u8 __iomem *src; > > > + int c, err =3D 0; > > > + unsigned long total_size; > > > + unsigned long alloc_size; > > > + ssize_t ret =3D 0; > > > + > > > + if (info->state !=3D FBINFO_STATE_RUNNING) > > > + return -EPERM; > > > + > > > + total_size =3D info->screen_size; > > > + > > > + if (total_size =3D=3D 0) > > > + total_size =3D info->fix.smem_len; > > > + > > > + if (p >=3D total_size) > > > + return 0; > > > + > > > + if (count >=3D total_size) > > > + count =3D total_size; > > > + > > > + if (count + p > total_size) > > > + count =3D total_size - p; > > > + > > > + src =3D (u8 __iomem *)(info->screen_base + p); > > > + > > > + alloc_size =3D min(count, PAGE_SIZE); > > > + > > > + dst =3D kmalloc(alloc_size, GFP_KERNEL); > > > + if (!dst) > > > + return -ENOMEM; > > > + > > > + while (count) { > > > + c =3D min(count, alloc_size); > > > + > > > + memcpy_fromio(dst, src, c); > > > + if (copy_to_user(buf, dst, c)) { > > > + err =3D -EFAULT; > > > + break; > > > + } > > > + > > > + src +=3D c; > > > + *ppos +=3D c; > > > + buf +=3D c; > > > + ret +=3D c; > > > + count -=3D c; > > > + } > > > + > > > + kfree(dst); > > > + > > > + if (err) > > > + return err; > > > + > > > + return ret; > > > +} > > > + > > > +static ssize_t drm_fb_helper_cfb_write(struct fb_info *info, const c= har > > > __user *buf, > > > + size_t count, loff_t *ppos) > > > +{ > > > + unsigned long p =3D *ppos; > > > + u8 *src; > > > + u8 __iomem *dst; > > > + int c, err =3D 0; > > > + unsigned long total_size; > > > + unsigned long alloc_size; > > > + ssize_t ret =3D 0; > > > + > > > + if (info->state !=3D FBINFO_STATE_RUNNING) > > > + return -EPERM; > > > + > > > + total_size =3D info->screen_size; > > > + > > > + if (total_size =3D=3D 0) > > > + total_size =3D info->fix.smem_len; > > > + > > > + if (p > total_size) > > > + return -EFBIG; > > > + > > > + if (count > total_size) { > > > + err =3D -EFBIG; > > > + count =3D total_size; > > > + } > > > + > > > + if (count + p > total_size) { > > > + /* > > > + * The framebuffer is too small. We do the > > > + * copy operation, but return an error code > > > + * afterwards. Taken from fbdev. > > > + */ > > > + if (!err) > > > + err =3D -ENOSPC; > > > + count =3D total_size - p; > > > + } > > > + > > > + alloc_size =3D min(count, PAGE_SIZE); > > > + > > > + src =3D kmalloc(alloc_size, GFP_KERNEL); > > > + if (!src) > > > + return -ENOMEM; > > > + > > > + dst =3D (u8 __iomem *)(info->screen_base + p); > > > + > > > + while (count) { > > > + c =3D min(count, alloc_size); > > > + > > > + if (copy_from_user(src, buf, c)) { > > > + err =3D -EFAULT; > > > + break; > > > + } > > > + memcpy_toio(dst, src, c); > > > + > > > + dst +=3D c; > > > + *ppos +=3D c; > > > + buf +=3D c; > > > + ret +=3D c; > > > + count -=3D c; > > > + } > > > + > > > + kfree(src); > > > + > > > + if (err) > > > + return err; > > > + > > > + return ret; > > > +} > > > + > > > /** > > > * drm_fb_helper_cfb_fillrect - wrapper around cfb_fillrect > > > * @info: fbdev registered by the helper > > > @@ -2027,6 +2156,66 @@ static int drm_fbdev_fb_mmap(struct fb_info *i= nfo, > > > struct vm_area_struct *vma) return -ENODEV; > > > } > > > = > > > +static ssize_t drm_fbdev_fb_read(struct fb_info *info, char __user *= buf, > > > + size_t count, loff_t *ppos) > > > +{ > > > + struct drm_fb_helper *fb_helper =3D info->par; > > > + struct drm_client_buffer *buffer =3D fb_helper->buffer; > > > + > > > + if (drm_fbdev_use_shadow_fb(fb_helper) || !buffer->map.is_iomem) > > > + return drm_fb_helper_sys_read(info, buf, count, ppos); > > > + else > > > + return drm_fb_helper_cfb_read(info, buf, count, ppos); > > > +} > > > + > > > +static ssize_t drm_fbdev_fb_write(struct fb_info *info, const char > > > __user *buf, > > > + size_t count, loff_t *ppos) > > > +{ > > > + struct drm_fb_helper *fb_helper =3D info->par; > > > + struct drm_client_buffer *buffer =3D fb_helper->buffer; > > > + > > > + if (drm_fbdev_use_shadow_fb(fb_helper) || !buffer->map.is_iomem) > > > + return drm_fb_helper_sys_write(info, buf, count, ppos); > > > + else > > > + return drm_fb_helper_cfb_write(info, buf, count, ppos); > > > +} > > > + > > > +static void drm_fbdev_fb_fillrect(struct fb_info *info, > > > + const struct fb_fillrect *rect) > > > +{ > > > + struct drm_fb_helper *fb_helper =3D info->par; > > > + struct drm_client_buffer *buffer =3D fb_helper->buffer; > > > + > > > + if (drm_fbdev_use_shadow_fb(fb_helper) || !buffer->map.is_iomem) > > > + drm_fb_helper_sys_fillrect(info, rect); > > > + else > > > + drm_fb_helper_cfb_fillrect(info, rect); > > > +} > > > + > > > +static void drm_fbdev_fb_copyarea(struct fb_info *info, > > > + const struct fb_copyarea *area) > > > +{ > > > + struct drm_fb_helper *fb_helper =3D info->par; > > > + struct drm_client_buffer *buffer =3D fb_helper->buffer; > > > + > > > + if (drm_fbdev_use_shadow_fb(fb_helper) || !buffer->map.is_iomem) > > > + drm_fb_helper_sys_copyarea(info, area); > > > + else > > > + drm_fb_helper_cfb_copyarea(info, area); > > > +} > > > + > > > +static void drm_fbdev_fb_imageblit(struct fb_info *info, > > > + const struct fb_image *image) > > > +{ > > > + struct drm_fb_helper *fb_helper =3D info->par; > > > + struct drm_client_buffer *buffer =3D fb_helper->buffer; > > > + > > > + if (drm_fbdev_use_shadow_fb(fb_helper) || !buffer->map.is_iomem) > > > + drm_fb_helper_sys_imageblit(info, image); > > > + else > > > + drm_fb_helper_cfb_imageblit(info, image); > > > +} > > > + > > > static const struct fb_ops drm_fbdev_fb_ops =3D { > > > .owner =3D THIS_MODULE, > > > DRM_FB_HELPER_DEFAULT_OPS, > > > @@ -2034,11 +2223,11 @@ static const struct fb_ops drm_fbdev_fb_ops = =3D { > > > .fb_release =3D drm_fbdev_fb_release, > > > .fb_destroy =3D drm_fbdev_fb_destroy, > > > .fb_mmap =3D drm_fbdev_fb_mmap, > > > - .fb_read =3D drm_fb_helper_sys_read, > > > - .fb_write =3D drm_fb_helper_sys_write, > > > - .fb_fillrect =3D drm_fb_helper_sys_fillrect, > > > - .fb_copyarea =3D drm_fb_helper_sys_copyarea, > > > - .fb_imageblit =3D drm_fb_helper_sys_imageblit, > > > + .fb_read =3D drm_fbdev_fb_read, > > > + .fb_write =3D drm_fbdev_fb_write, > > > + .fb_fillrect =3D drm_fbdev_fb_fillrect, > > > + .fb_copyarea =3D drm_fbdev_fb_copyarea, > > > + .fb_imageblit =3D drm_fbdev_fb_imageblit, > > > }; > > > = > > > static struct fb_deferred_io drm_fbdev_defio =3D { > > > diff --git a/include/drm/drm_mode_config.h b/include/drm/drm_mode_con= fig.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 > = > = > = > -- = > Thomas Zimmermann > Graphics Driver Developer > SUSE Software Solutions Germany GmbH > Maxfeldstr. 5, 90409 N=FCrnberg, Germany > (HRB 36809, AG N=FCrnberg) > Gesch=E4ftsf=FChrer: Felix Imend=F6rffer _______________________________________________ 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.7 required=3.0 tests=BAYES_00, 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 44CD3C433E7 for ; Fri, 16 Oct 2020 12:49:03 +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 A56D9207DE for ; Fri, 16 Oct 2020 12:49:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A56D9207DE Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=ravnborg.org 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 9F6086EDDB; Fri, 16 Oct 2020 12:49:01 +0000 (UTC) Received: from asavdk4.altibox.net (asavdk4.altibox.net [109.247.116.15]) by gabe.freedesktop.org (Postfix) with ESMTPS id 87C5D6E141; Fri, 16 Oct 2020 12:48:59 +0000 (UTC) Received: from ravnborg.org (unknown [188.228.123.71]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by asavdk4.altibox.net (Postfix) with ESMTPS id 383A2806F9; Fri, 16 Oct 2020 14:48:52 +0200 (CEST) Date: Fri, 16 Oct 2020 14:48:50 +0200 From: Sam Ravnborg To: Thomas Zimmermann Subject: Re: [PATCH v4 10/10] drm/fb_helper: Support framebuffers in I/O memory Message-ID: <20201016124850.GA1174599@ravnborg.org> References: <20201015123806.32416-1-tzimmermann@suse.de> <20201015123806.32416-11-tzimmermann@suse.de> <20201016120347.GB1125266@ravnborg.org> <20201016141942.111e17f3@linux-uq9g> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20201016141942.111e17f3@linux-uq9g> X-CMAE-Score: 0 X-CMAE-Analysis: v=2.3 cv=fu7ymmwf c=1 sm=1 tr=0 a=S6zTFyMACwkrwXSdXUNehg==:117 a=S6zTFyMACwkrwXSdXUNehg==:17 a=8nJEP1OIZ-IA:10 a=7gkXJVJtAAAA:8 a=6Hpfs63HWkxrz3fWGNMA:9 a=w4pgIJ6L-nyCBc2a:21 a=gikFlJ38tUkSyios:21 a=wPNLvfGTeEIA:10 a=qfUslh1TxfEA:10 a=E9Po1WZjFZOl8hwRPBS3:22 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, 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, alyssa.rosenzweig@collabora.com, linux+etnaviv@armlinux.org.uk, spice-devel@lists.freedesktop.org, bskeggs@redhat.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="iso-8859-1" Content-Transfer-Encoding: quoted-printable Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" On Fri, Oct 16, 2020 at 02:19:42PM +0200, Thomas Zimmermann wrote: > Hi > = > On Fri, 16 Oct 2020 14:03:47 +0200 Sam Ravnborg wrote: > = > > Hi Thomas. > > = > > On Thu, Oct 15, 2020 at 02:38:06PM +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 r= sp > > > fb_sys_ of fb_cfb_ functions. > > > = > > > For drivers that employ a shadow buffer, fbdev's blit function retrie= ves > > > 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 r= sp > > > code from both, bochs and fbdev. > > > = > > > v4: > > > * move dma_buf_map changes into separate patch (Daniel) > > > * TODO list: comment on fbdev updates (Daniel) > > > = > > > Signed-off-by: Thomas Zimmermann > > = > > The original workaround fixed it so we could run qemu with the > > -nographic option. > > = > > So I went ahead and tried to run quemu version: > > v5.0.0-1970-g0b100c8e72-dirty. > > And with the BOCHS driver built-in. > > = > > With the following command line: > > qemu-system-sparc64 -m 512 -kernel vmlinux -append console=3DttyS0 -nog= raphic > > = > > Behaviour was the same before and after applying this patch. > > (panic due to VFS: Unable to mount root fs on unknown-block(0,0)) > > So I consider it fixed for real now and not just a workaround. > > = > > I also tested with: > > qemu-system-sparc64 -m 512 -kernel vmlinux -append console=3DttyS0 -ser= ial > > stdio > > = > > and it worked in both cases too. > = > FTR, you booted a kernel and got graphics output. The error is simply that > there was no disk to mount? The short version "Yes". The longer version: With "qemu-system-sparc64 -m 512 -kernel vmlinux -append console=3DttyS0 -serial stdio" I got graphical output - one penguin. With "qemu-system-sparc64 -m 512 -kernel vmlinux -append console=3DttyS0 -nographic" I got no graphical output, as implied by the -nographic option. But the boot continued - where it would panic before when we accessed IO memory as system memory. In both cases I got an error because I had not specified any rootfs, so qemu failed to mount any rootfs. So expected. Sam > = > Best regards > Thomas > = > > = > > All the comments above so future-me have an easier time finding how to > > reproduce. > > = > > Tested-by: Sam Ravnborg > > = > > Sam > > = > > > --- > > > Documentation/gpu/todo.rst | 19 ++- > > > drivers/gpu/drm/bochs/bochs_kms.c | 1 - > > > drivers/gpu/drm/drm_fb_helper.c | 217 ++++++++++++++++++++++++++++= -- > > > include/drm/drm_mode_config.h | 12 -- > > > 4 files changed, 220 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 imple= ment > > > -atomic modesetting and GEM vmap support. Current generic fbdev emula= tion > > > -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 =3D 24; > > > bochs->dev->mode_config.prefer_shadow =3D 0; > > > bochs->dev->mode_config.prefer_shadow_fbdev =3D 1; > > > - bochs->dev->mode_config.fbdev_use_iomem =3D true; > > > bochs->dev->mode_config.quirk_addfb_prefer_host_byte_order =3D > > > true; = > > > bochs->dev->mode_config.funcs =3D &bochs_mode_funcs; > > > diff --git a/drivers/gpu/drm/drm_fb_helper.c > > > b/drivers/gpu/drm/drm_fb_helper.c index 6212cd7cde1d..462b0c130ebb 10= 0644 > > > --- 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 =3D fb_helper->fb; > > > unsigned int cpp =3D fb->format->cpp[0]; > > > size_t offset =3D clip->y1 * fb->pitches[0] + clip->x1 * cpp; > > > void *src =3D fb_helper->fbdev->screen_buffer + offset; > > > - void *dst =3D fb_helper->buffer->map.vaddr + offset; > > > size_t len =3D (clip->x2 - clip->x1) * cpp; > > > unsigned int y; > > > = > > > - for (y =3D 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 =3D clip->y1; y < clip->y2; y++) { > > > + dma_buf_map_memcpy_to(dst, src, len); > > > + dma_buf_map_incr(dst, fb->pitches[0]); > > > src +=3D fb->pitches[0]; > > > - dst +=3D fb->pitches[0]; > > > } > > > } > > > = > > > @@ -417,8 +415,9 @@ static void drm_fb_helper_dirty_work(struct > > > work_struct *work) ret =3D drm_client_buffer_vmap(helper->buffer, &ma= p); > > > 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); > > > @@ -755,6 +754,136 @@ void drm_fb_helper_sys_imageblit(struct fb_info > > > *info, } > > > EXPORT_SYMBOL(drm_fb_helper_sys_imageblit); > > > = > > > +static ssize_t drm_fb_helper_cfb_read(struct fb_info *info, char __u= ser > > > *buf, > > > + size_t count, loff_t *ppos) > > > +{ > > > + unsigned long p =3D *ppos; > > > + u8 *dst; > > > + u8 __iomem *src; > > > + int c, err =3D 0; > > > + unsigned long total_size; > > > + unsigned long alloc_size; > > > + ssize_t ret =3D 0; > > > + > > > + if (info->state !=3D FBINFO_STATE_RUNNING) > > > + return -EPERM; > > > + > > > + total_size =3D info->screen_size; > > > + > > > + if (total_size =3D=3D 0) > > > + total_size =3D info->fix.smem_len; > > > + > > > + if (p >=3D total_size) > > > + return 0; > > > + > > > + if (count >=3D total_size) > > > + count =3D total_size; > > > + > > > + if (count + p > total_size) > > > + count =3D total_size - p; > > > + > > > + src =3D (u8 __iomem *)(info->screen_base + p); > > > + > > > + alloc_size =3D min(count, PAGE_SIZE); > > > + > > > + dst =3D kmalloc(alloc_size, GFP_KERNEL); > > > + if (!dst) > > > + return -ENOMEM; > > > + > > > + while (count) { > > > + c =3D min(count, alloc_size); > > > + > > > + memcpy_fromio(dst, src, c); > > > + if (copy_to_user(buf, dst, c)) { > > > + err =3D -EFAULT; > > > + break; > > > + } > > > + > > > + src +=3D c; > > > + *ppos +=3D c; > > > + buf +=3D c; > > > + ret +=3D c; > > > + count -=3D c; > > > + } > > > + > > > + kfree(dst); > > > + > > > + if (err) > > > + return err; > > > + > > > + return ret; > > > +} > > > + > > > +static ssize_t drm_fb_helper_cfb_write(struct fb_info *info, const c= har > > > __user *buf, > > > + size_t count, loff_t *ppos) > > > +{ > > > + unsigned long p =3D *ppos; > > > + u8 *src; > > > + u8 __iomem *dst; > > > + int c, err =3D 0; > > > + unsigned long total_size; > > > + unsigned long alloc_size; > > > + ssize_t ret =3D 0; > > > + > > > + if (info->state !=3D FBINFO_STATE_RUNNING) > > > + return -EPERM; > > > + > > > + total_size =3D info->screen_size; > > > + > > > + if (total_size =3D=3D 0) > > > + total_size =3D info->fix.smem_len; > > > + > > > + if (p > total_size) > > > + return -EFBIG; > > > + > > > + if (count > total_size) { > > > + err =3D -EFBIG; > > > + count =3D total_size; > > > + } > > > + > > > + if (count + p > total_size) { > > > + /* > > > + * The framebuffer is too small. We do the > > > + * copy operation, but return an error code > > > + * afterwards. Taken from fbdev. > > > + */ > > > + if (!err) > > > + err =3D -ENOSPC; > > > + count =3D total_size - p; > > > + } > > > + > > > + alloc_size =3D min(count, PAGE_SIZE); > > > + > > > + src =3D kmalloc(alloc_size, GFP_KERNEL); > > > + if (!src) > > > + return -ENOMEM; > > > + > > > + dst =3D (u8 __iomem *)(info->screen_base + p); > > > + > > > + while (count) { > > > + c =3D min(count, alloc_size); > > > + > > > + if (copy_from_user(src, buf, c)) { > > > + err =3D -EFAULT; > > > + break; > > > + } > > > + memcpy_toio(dst, src, c); > > > + > > > + dst +=3D c; > > > + *ppos +=3D c; > > > + buf +=3D c; > > > + ret +=3D c; > > > + count -=3D c; > > > + } > > > + > > > + kfree(src); > > > + > > > + if (err) > > > + return err; > > > + > > > + return ret; > > > +} > > > + > > > /** > > > * drm_fb_helper_cfb_fillrect - wrapper around cfb_fillrect > > > * @info: fbdev registered by the helper > > > @@ -2027,6 +2156,66 @@ static int drm_fbdev_fb_mmap(struct fb_info *i= nfo, > > > struct vm_area_struct *vma) return -ENODEV; > > > } > > > = > > > +static ssize_t drm_fbdev_fb_read(struct fb_info *info, char __user *= buf, > > > + size_t count, loff_t *ppos) > > > +{ > > > + struct drm_fb_helper *fb_helper =3D info->par; > > > + struct drm_client_buffer *buffer =3D fb_helper->buffer; > > > + > > > + if (drm_fbdev_use_shadow_fb(fb_helper) || !buffer->map.is_iomem) > > > + return drm_fb_helper_sys_read(info, buf, count, ppos); > > > + else > > > + return drm_fb_helper_cfb_read(info, buf, count, ppos); > > > +} > > > + > > > +static ssize_t drm_fbdev_fb_write(struct fb_info *info, const char > > > __user *buf, > > > + size_t count, loff_t *ppos) > > > +{ > > > + struct drm_fb_helper *fb_helper =3D info->par; > > > + struct drm_client_buffer *buffer =3D fb_helper->buffer; > > > + > > > + if (drm_fbdev_use_shadow_fb(fb_helper) || !buffer->map.is_iomem) > > > + return drm_fb_helper_sys_write(info, buf, count, ppos); > > > + else > > > + return drm_fb_helper_cfb_write(info, buf, count, ppos); > > > +} > > > + > > > +static void drm_fbdev_fb_fillrect(struct fb_info *info, > > > + const struct fb_fillrect *rect) > > > +{ > > > + struct drm_fb_helper *fb_helper =3D info->par; > > > + struct drm_client_buffer *buffer =3D fb_helper->buffer; > > > + > > > + if (drm_fbdev_use_shadow_fb(fb_helper) || !buffer->map.is_iomem) > > > + drm_fb_helper_sys_fillrect(info, rect); > > > + else > > > + drm_fb_helper_cfb_fillrect(info, rect); > > > +} > > > + > > > +static void drm_fbdev_fb_copyarea(struct fb_info *info, > > > + const struct fb_copyarea *area) > > > +{ > > > + struct drm_fb_helper *fb_helper =3D info->par; > > > + struct drm_client_buffer *buffer =3D fb_helper->buffer; > > > + > > > + if (drm_fbdev_use_shadow_fb(fb_helper) || !buffer->map.is_iomem) > > > + drm_fb_helper_sys_copyarea(info, area); > > > + else > > > + drm_fb_helper_cfb_copyarea(info, area); > > > +} > > > + > > > +static void drm_fbdev_fb_imageblit(struct fb_info *info, > > > + const struct fb_image *image) > > > +{ > > > + struct drm_fb_helper *fb_helper =3D info->par; > > > + struct drm_client_buffer *buffer =3D fb_helper->buffer; > > > + > > > + if (drm_fbdev_use_shadow_fb(fb_helper) || !buffer->map.is_iomem) > > > + drm_fb_helper_sys_imageblit(info, image); > > > + else > > > + drm_fb_helper_cfb_imageblit(info, image); > > > +} > > > + > > > static const struct fb_ops drm_fbdev_fb_ops =3D { > > > .owner =3D THIS_MODULE, > > > DRM_FB_HELPER_DEFAULT_OPS, > > > @@ -2034,11 +2223,11 @@ static const struct fb_ops drm_fbdev_fb_ops = =3D { > > > .fb_release =3D drm_fbdev_fb_release, > > > .fb_destroy =3D drm_fbdev_fb_destroy, > > > .fb_mmap =3D drm_fbdev_fb_mmap, > > > - .fb_read =3D drm_fb_helper_sys_read, > > > - .fb_write =3D drm_fb_helper_sys_write, > > > - .fb_fillrect =3D drm_fb_helper_sys_fillrect, > > > - .fb_copyarea =3D drm_fb_helper_sys_copyarea, > > > - .fb_imageblit =3D drm_fb_helper_sys_imageblit, > > > + .fb_read =3D drm_fbdev_fb_read, > > > + .fb_write =3D drm_fbdev_fb_write, > > > + .fb_fillrect =3D drm_fbdev_fb_fillrect, > > > + .fb_copyarea =3D drm_fbdev_fb_copyarea, > > > + .fb_imageblit =3D drm_fbdev_fb_imageblit, > > > }; > > > = > > > static struct fb_deferred_io drm_fbdev_defio =3D { > > > diff --git a/include/drm/drm_mode_config.h b/include/drm/drm_mode_con= fig.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 > = > = > = > -- = > Thomas Zimmermann > Graphics Driver Developer > SUSE Software Solutions Germany GmbH > Maxfeldstr. 5, 90409 N=FCrnberg, Germany > (HRB 36809, AG N=FCrnberg) > Gesch=E4ftsf=FChrer: Felix Imend=F6rffer _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel