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=-11.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 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 1C16AC2D0A8 for ; Mon, 28 Sep 2020 09:14:27 +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 A771A21D7F for ; Mon, 28 Sep 2020 09:14:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A771A21D7F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de 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 CB22B8922B; Mon, 28 Sep 2020 09:14:25 +0000 (UTC) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by gabe.freedesktop.org (Postfix) with ESMTPS id 225238922B for ; Mon, 28 Sep 2020 09:14:24 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id C3BF3AC82; Mon, 28 Sep 2020 09:14:22 +0000 (UTC) Subject: Re: [PATCH 8/9] drm: Add infrastructure for platform devices To: Daniel Vetter References: <20200625120011.16168-1-tzimmermann@suse.de> <20200625120011.16168-9-tzimmermann@suse.de> <20200629092741.GR3278063@phenom.ffwll.local> From: Thomas Zimmermann Message-ID: Date: Mon, 28 Sep 2020 11:14:21 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: 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: Geert Uytterhoeven , Dave Airlie , Emil Velikov , dri-devel , Liam Girdwood , Hans de Goede , Mark Brown , Gerd Hoffmann , Sam Ravnborg Content-Type: multipart/mixed; boundary="===============1239023412==" Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --===============1239023412== Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="l3dBBG3bTgnCSRj5x8jUgMgdGdCegvgAb" This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --l3dBBG3bTgnCSRj5x8jUgMgdGdCegvgAb Content-Type: multipart/mixed; boundary="MnPPyDMl9pgERW6Yp8cLyABxkMHKrTtyC"; protected-headers="v1" From: Thomas Zimmermann To: Daniel Vetter Cc: Maarten Lankhorst , Maxime Ripard , Dave Airlie , Gerd Hoffmann , Liam Girdwood , Mark Brown , Rob Herring , Sam Ravnborg , Emil Velikov , =?UTF-8?Q?Noralf_Tr=c3=b8nnes?= , Geert Uytterhoeven , Hans de Goede , dri-devel Message-ID: Subject: Re: [PATCH 8/9] drm: Add infrastructure for platform devices References: <20200625120011.16168-1-tzimmermann@suse.de> <20200625120011.16168-9-tzimmermann@suse.de> <20200629092741.GR3278063@phenom.ffwll.local> In-Reply-To: --MnPPyDMl9pgERW6Yp8cLyABxkMHKrTtyC Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: quoted-printable Hi Am 28.09.20 um 10:50 schrieb Daniel Vetter: > On Mon, Sep 28, 2020 at 10:40 AM Thomas Zimmermann wrote: >> >> Hi >> >> Am 29.06.20 um 11:27 schrieb Daniel Vetter: >>> On Thu, Jun 25, 2020 at 02:00:10PM +0200, Thomas Zimmermann wrote: >>>> Platform devices might operate on firmware framebuffers, such as VES= A or >>>> EFI. Before a native driver for the graphics hardware can take over = the >>>> device, it has to remove any platform driver that operates on the fi= rmware >>>> framebuffer. Platform helpers provide the infrastructure for platfor= m >>>> drivers to acquire firmware framebuffers, and for native drivers to = remove >>>> them lateron. >>>> >>>> It works similar to the related fbdev mechanism. During initializati= on, the >>>> platform driver acquires the firmware framebuffer's I/O memory and p= rovides >>>> a callback to be removed. The native driver later uses this inforamt= ion to >>>> remove any platform driver for it's framebuffer I/O memory. >>>> >>>> The platform helper's removal code is integrated into the existing c= ode for >>>> removing conflicting fraembuffers, so native drivers use it automati= cally. >>>> >>>> Signed-off-by: Thomas Zimmermann >>> >>> I have some ideas for how to do this a notch cleaner in the next patc= h. >>> Maybe best to discuss the actual implmenentation stuff there. >>> >>> Aside from that usual nits: >>> - kerneldoc for these please, pulled into drm-kms.rst. >>> - naming isn't super ocd with drm_platform.c but that prefix not used= , but >>> I also don't have better ideas. >> >> I was never really happy with the naming either. Maybe call it apertur= e >> helpers with drm_aperture_ and CONFIG_DRM_APERTURE_HELPER? >=20 > +1 >=20 >>> - I think the functions from drm_fb_helper.h for removing other >>> framebuffers should be moved here, and function name prefix adjuste= d >>> acoordingly >>> >>> I'm wondering about the locking and deadlock potential here, is lockd= ep >>> all happy with this? >> >> I haven't seen any complains, but I'll double check. >=20 > Might be worth it to cc Greg on this, since the device driver model > has a lot of corner cases to make sure it doesn't get stuck here with > hiararchical drivers/device getting removed while something else is > probing them at the same time. Oh, OK. I'll keep that in mind when sending out v2 of these patches. Best regards Thomas > -Daniel >=20 >> Best regards >> Thomas >> >>> >>> Cheers, Daniel >>> >>>> --- >>>> drivers/gpu/drm/Kconfig | 6 ++ >>>> drivers/gpu/drm/Makefile | 1 + >>>> drivers/gpu/drm/drm_platform.c | 118 ++++++++++++++++++++++++++++++= +++ >>>> include/drm/drm_fb_helper.h | 18 ++++- >>>> include/drm/drm_platform.h | 42 ++++++++++++ >>>> 5 files changed, 184 insertions(+), 1 deletion(-) >>>> create mode 100644 drivers/gpu/drm/drm_platform.c >>>> create mode 100644 include/drm/drm_platform.h >>>> >>>> diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig >>>> index c4fd57d8b717..e9d6892f9d38 100644 >>>> --- a/drivers/gpu/drm/Kconfig >>>> +++ b/drivers/gpu/drm/Kconfig >>>> @@ -229,6 +229,12 @@ config DRM_SCHED >>>> tristate >>>> depends on DRM >>>> >>>> +config DRM_PLATFORM_HELPER >>>> + bool >>>> + depends on DRM >>>> + help >>>> + Helpers for DRM platform devices >>>> + >>>> source "drivers/gpu/drm/i2c/Kconfig" >>>> >>>> source "drivers/gpu/drm/arm/Kconfig" >>>> diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile >>>> index 2c0e5a7e5953..8ceb21d0770a 100644 >>>> --- a/drivers/gpu/drm/Makefile >>>> +++ b/drivers/gpu/drm/Makefile >>>> @@ -32,6 +32,7 @@ drm-$(CONFIG_AGP) +=3D drm_agpsupport.o >>>> drm-$(CONFIG_PCI) +=3D drm_pci.o >>>> drm-$(CONFIG_DEBUG_FS) +=3D drm_debugfs.o drm_debugfs_crc.o >>>> drm-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) +=3D drm_edid_load.o >>>> +drm-$(CONFIG_DRM_PLATFORM_HELPER) +=3D drm_platform.o >>>> >>>> drm_vram_helper-y :=3D drm_gem_vram_helper.o >>>> obj-$(CONFIG_DRM_VRAM_HELPER) +=3D drm_vram_helper.o >>>> diff --git a/drivers/gpu/drm/drm_platform.c b/drivers/gpu/drm/drm_pl= atform.c >>>> new file mode 100644 >>>> index 000000000000..09a2f2a31aa5 >>>> --- /dev/null >>>> +++ b/drivers/gpu/drm/drm_platform.c >>>> @@ -0,0 +1,118 @@ >>>> +// SPDX-License-Identifier: GPL-2.0 OR MIT >>>> + >>>> +#include >>>> +#include >>>> + >>>> +#include >>>> +#include >>>> +#include >>>> + >>>> +static LIST_HEAD(drm_apertures); >>>> + >>>> +static DEFINE_MUTEX(drm_apertures_lock); >>>> + >>>> +static bool overlap(resource_size_t base1, resource_size_t end1, >>>> + resource_size_t base2, resource_size_t end2) >>>> +{ >>>> + return (base1 < end2) && (end1 > base2); >>>> +} >>>> + >>>> +static struct drm_aperture * >>>> +drm_aperture_acquire(struct drm_device *dev, >>>> + resource_size_t base, resource_size_t size, >>>> + const struct drm_aperture_funcs *funcs) >>>> +{ >>>> + size_t end =3D base + size; >>>> + struct list_head *pos; >>>> + struct drm_aperture *ap; >>>> + >>>> + mutex_lock(&drm_apertures_lock); >>>> + >>>> + list_for_each(pos, &drm_apertures) { >>>> + ap =3D container_of(pos, struct drm_aperture, lh); >>>> + if (overlap(base, end, ap->base, ap->base + ap->size)) >>>> + return ERR_PTR(-EBUSY); >>>> + } >>>> + >>>> + ap =3D drmm_kzalloc(dev, sizeof(*ap), GFP_KERNEL); >>>> + if (!ap) >>>> + return ERR_PTR(-ENOMEM); >>>> + >>>> + ap->dev =3D dev; >>>> + ap->base =3D base; >>>> + ap->size =3D size; >>>> + ap->funcs =3D funcs; >>>> + INIT_LIST_HEAD(&ap->lh); >>>> + >>>> + list_add(&ap->lh, &drm_apertures); >>>> + >>>> + mutex_unlock(&drm_apertures_lock); >>>> + >>>> + return ap; >>>> +} >>>> + >>>> +static void drm_aperture_release(struct drm_aperture *ap) >>>> +{ >>>> + bool kicked_out =3D ap->kicked_out; >>>> + >>>> + if (!kicked_out) >>>> + mutex_lock(&drm_apertures_lock); >>>> + >>>> + list_del(&ap->lh); >>>> + if (ap->funcs->release) >>>> + ap->funcs->release(ap); >>>> + >>>> + if (!kicked_out) >>>> + mutex_unlock(&drm_apertures_lock); >>>> +} >>>> + >>>> +static void drm_aperture_acquire_release(struct drm_device *dev, vo= id *ptr) >>>> +{ >>>> + struct drm_aperture *ap =3D ptr; >>>> + >>>> + drm_aperture_release(ap); >>>> +} >>>> + >>>> +struct drm_aperture * >>>> +drmm_aperture_acquire(struct drm_device *dev, >>>> + resource_size_t base, resource_size_t size, >>>> + const struct drm_aperture_funcs *funcs) >>>> +{ >>>> + struct drm_aperture *ap; >>>> + int ret; >>>> + >>>> + ap =3D drm_aperture_acquire(dev, base, size, funcs); >>>> + if (IS_ERR(ap)) >>>> + return ap; >>>> + ret =3D drmm_add_action_or_reset(dev, drm_aperture_acquire_rele= ase, ap); >>>> + if (ret) >>>> + return ERR_PTR(ret); >>>> + >>>> + return ap; >>>> +} >>>> +EXPORT_SYMBOL(drmm_aperture_acquire); >>>> + >>>> +void drm_kickout_apertures_at(resource_size_t base, resource_size_t= size) >>>> +{ >>>> + resource_size_t end =3D base + size; >>>> + struct list_head *pos, *n; >>>> + >>>> + mutex_lock(&drm_apertures_lock); >>>> + >>>> + list_for_each_safe(pos, n, &drm_apertures) { >>>> + struct drm_aperture *ap =3D >>>> + container_of(pos, struct drm_aperture, lh); >>>> + >>>> + if (!overlap(base, end, ap->base, ap->base + ap->size))= >>>> + continue; >>>> + >>>> + ap->kicked_out =3D true; >>>> + if (ap->funcs->kickout) >>>> + ap->funcs->kickout(ap); >>>> + else >>>> + drm_dev_put(ap->dev); >>>> + } >>>> + >>>> + mutex_unlock(&drm_apertures_lock); >>>> +} >>>> +EXPORT_SYMBOL(drm_kickout_apertures_at); >>>> diff --git a/include/drm/drm_fb_helper.h b/include/drm/drm_fb_helper= =2Eh >>>> index 306aa3a60be9..a919b78b1961 100644 >>>> --- a/include/drm/drm_fb_helper.h >>>> +++ b/include/drm/drm_fb_helper.h >>>> @@ -35,7 +35,9 @@ struct drm_fb_helper; >>>> #include >>>> #include >>>> #include >>>> +#include >>>> #include >>>> +#include >>>> #include >>>> >>>> enum mode_set_atomic { >>>> @@ -465,6 +467,11 @@ static inline int >>>> drm_fb_helper_remove_conflicting_framebuffers(struct apertures_stru= ct *a, >>>> const char *name, bool pr= imary) >>>> { >>>> + int i; >>>> + >>>> + for (i =3D 0; i < a->count; ++i) >>>> + drm_kickout_apertures_at(a->ranges[i].base, a->ranges[i= ].size); >>>> + >>>> #if IS_REACHABLE(CONFIG_FB) >>>> return remove_conflicting_framebuffers(a, name, primary); >>>> #else >>>> @@ -487,7 +494,16 @@ static inline int >>>> drm_fb_helper_remove_conflicting_pci_framebuffers(struct pci_dev *p= dev, >>>> const char *name) >>>> { >>>> - int ret =3D 0; >>>> + resource_size_t base, size; >>>> + int bar, ret =3D 0; >>>> + >>>> + for (bar =3D 0; bar < PCI_STD_NUM_BARS; bar++) { >>>> + if (!(pci_resource_flags(pdev, bar) & IORESOURCE_MEM)) >>>> + continue; >>>> + base =3D pci_resource_start(pdev, bar); >>>> + size =3D pci_resource_len(pdev, bar); >>>> + drm_kickout_apertures_at(base, size); >>>> + } >>>> >>>> /* >>>> * WARNING: Apparently we must kick fbdev drivers before vgacon= , >>>> diff --git a/include/drm/drm_platform.h b/include/drm/drm_platform.h= >>>> new file mode 100644 >>>> index 000000000000..475e88ee1fbd >>>> --- /dev/null >>>> +++ b/include/drm/drm_platform.h >>>> @@ -0,0 +1,42 @@ >>>> +// SPDX-License-Identifier: GPL-2.0 OR MIT >>>> + >>>> +#ifndef _DRM_PLATFORM_H_ >>>> +#define _DRM_PLATFORM_H_ >>>> + >>>> +#include >>>> +#include >>>> + >>>> +struct drm_aperture; >>>> +struct drm_device; >>>> + >>>> +struct drm_aperture_funcs { >>>> + void (*kickout)(struct drm_aperture *ap); >>>> + void (*release)(struct drm_aperture *ap); >>>> +}; >>>> + >>>> +struct drm_aperture { >>>> + struct drm_device *dev; >>>> + resource_size_t base; >>>> + resource_size_t size; >>>> + >>>> + const struct drm_aperture_funcs *funcs; >>>> + >>>> + struct list_head lh; >>>> + bool kicked_out; >>>> +}; >>>> + >>>> +struct drm_aperture * >>>> +drmm_aperture_acquire(struct drm_device *dev, >>>> + resource_size_t base, resource_size_t size, >>>> + const struct drm_aperture_funcs *funcs); >>>> + >>>> +#if defined (CONFIG_DRM_PLATFORM_HELPER) >>>> +void drm_kickout_apertures_at(resource_size_t base, resource_size_t= size); >>>> +#else >>>> +static inline void >>>> +drm_kickout_apertures_at(resource_size_t base, resource_size_t size= ) >>>> +{ >>>> +} >>>> +#endif >>>> + >>>> +#endif >>>> -- >>>> 2.27.0 >>>> >>> >> >> -- >> Thomas Zimmermann >> Graphics Driver Developer >> SUSE Software Solutions Germany GmbH >> Maxfeldstr. 5, 90409 N=C3=BCrnberg, Germany >> (HRB 36809, AG N=C3=BCrnberg) >> Gesch=C3=A4ftsf=C3=BChrer: Felix Imend=C3=B6rffer >> >=20 >=20 --=20 Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Maxfeldstr. 5, 90409 N=C3=BCrnberg, Germany (HRB 36809, AG N=C3=BCrnberg) Gesch=C3=A4ftsf=C3=BChrer: Felix Imend=C3=B6rffer --MnPPyDMl9pgERW6Yp8cLyABxkMHKrTtyC-- --l3dBBG3bTgnCSRj5x8jUgMgdGdCegvgAb Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- iQFIBAEBCAAyFiEEchf7rIzpz2NEoWjlaA3BHVMLeiMFAl9xqW0UHHR6aW1tZXJt YW5uQHN1c2UuZGUACgkQaA3BHVMLeiOkfgf8DgDuJMe5SVmq5lS/NhP6Oehl4th0 x26T8WgWObpVUjPtM63A3oYWI133axtmsqDVcgfDE4d4EVLH9lCSBzGN98F7KRn/ wmXlFKOqYHlP3kuv+OgcrvjH7ODMeCL7hsOQVneGSiz2apS5RdSj9PZ7xKN83tT2 Mhn2fXghcT9js0pAovjGZTFteECgO5SrpFYPc7++qKP+PKTBX2O0DZeUiTrfRNdl MF7pVS4jJroQ2gQTNktpmMGQNrcs/fUu/5mlbmtxBxciAlNJw/yZSezIt231m6rV +RHpYQU0P4QIhpqbrpbyllHH0S9HaF5av/Tp+fYCSzbqg7ZRyCJrlYKa5g== =yKkv -----END PGP SIGNATURE----- --l3dBBG3bTgnCSRj5x8jUgMgdGdCegvgAb-- --===============1239023412== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel --===============1239023412==--