From patchwork Mon Sep 5 11:19:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: David Herrmann X-Patchwork-Id: 9313507 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C08BC6075E for ; Mon, 5 Sep 2016 11:19:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B118C28A3A for ; Mon, 5 Sep 2016 11:19:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A0C4928A72; Mon, 5 Sep 2016 11:19:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E6FEA28A3A for ; Mon, 5 Sep 2016 11:19:47 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0AF796E0D1; Mon, 5 Sep 2016 11:19:46 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-lf0-x241.google.com (mail-lf0-x241.google.com [IPv6:2a00:1450:4010:c07::241]) by gabe.freedesktop.org (Postfix) with ESMTPS id B69EB6E0D1 for ; Mon, 5 Sep 2016 11:19:44 +0000 (UTC) Received: by mail-lf0-x241.google.com with SMTP id 29so2303911lfv.1 for ; Mon, 05 Sep 2016 04:19:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=dEL927Qu8/E7KP48Aq5Glf8kAtrkHLIjAJXmB04BjqQ=; b=iAzuw2dpGXq2HBZ14RTfuZbp7E29bNROsbcewO/bUdo+2YkRQXNC64b17bX899Fy4z QXpdxRUF2jfge4pIsq5WrRsuofWnIQ2ozQuTxcBns0mWoRECEuzEIWrc09SPAhm2e9Gp 6HNkxtxFf+21UOpmyw4X1l9twqd4FP8J9NT47hn0IqXzKVKkM56FwE6UmWuJWPm/BBSX aba9cXi5spHak6jf79fl5aWxkwxzFUGoqnL0a19+u8/rQOjK6+70zKBB/CAMyGQvcC37 E0Umeme2VWLradjoFGhhUZnG/MtYMOOCtC6RxJTTvjfz1uYG+cfXIj+r2fejIi15k6H2 rqbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=dEL927Qu8/E7KP48Aq5Glf8kAtrkHLIjAJXmB04BjqQ=; b=dvv14/Vh6nT5EXg1xRg/ZK5ADY+rv4RlNkdgTXz3oBMvydHZZwAhy2Jq6nNeUXFb3+ FtmFbQ03YfF4at69cH4vbIAnBLKHTypqo6zM0Apj8IwPNL6tC/QInbXmWci916xuk6ax FFaeTuK9+5nJpnPF/noQKzcijY8pDQTQzUDG9CD/kjxp1WzKdP7HnrgkuH7E22WYQKks udG7+jbOI8j8PDGHxHAHcwSWFCas2Ce88svW57m6X4RGZNmesPJW+pQRSemdWkyo5k/U DEgKvOINEOR2In6wXf9Eep6JJmUpTsHqPs+w77zsmi7gNPtefO1oJUhjeAUqBMihrJ32 nDyQ== X-Gm-Message-State: AE9vXwPnr/b4+6kN28mjDxonMGuBt2fggnRQBIIOgZnc1PUARjxIq6zkVQJ4AdrKjWt7aCSOzAuJrL39RTYysg== X-Received: by 10.25.21.160 with SMTP id 32mr8313562lfv.1.1473074382961; Mon, 05 Sep 2016 04:19:42 -0700 (PDT) MIME-Version: 1.0 Received: by 10.25.135.130 with HTTP; Mon, 5 Sep 2016 04:19:42 -0700 (PDT) In-Reply-To: References: <20160902082245.7119-1-dh.herrmann@gmail.com> <20160902082245.7119-5-dh.herrmann@gmail.com> From: David Herrmann Date: Mon, 5 Sep 2016 13:19:42 +0200 Message-ID: Subject: Re: [PATCH v5 4/7] video: add generic framebuffer eviction To: =?UTF-8?Q?Noralf_Tr=C3=B8nnes?= Cc: "dri-devel@lists.freedesktop.org" X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Hi On Sat, Sep 3, 2016 at 2:06 PM, Noralf Trønnes wrote: > > Den 02.09.2016 10:22, skrev David Herrmann: >> >> There are several situations where we want hardware handover from an early >> boot GFX driver (e.g., vgacon, vesafb, efifb, simplefb) to a full fletched >> GFX driver (e.g., most DRM drivers). So far, we relied on >> remove_conflicting_framebuffers() to do this for us, however, this had a >> bunch of downsides: >> >> o It only removes conflicting fbdev drivers. It does not drop vgacon, >> early boot console drivers, conflicting DRM drivers, etc. >> >> o It only unloads the fbdev driver, it does not modify the underlying >> device or resources. In case of "screen_info" drivers (e.g., efifb) >> this is fine, since no resources are pinned. However, if the driver >> binds to a platform-device like "simple-framebuffer", we must make >> sure to unregister that device as well. Otherwise, pinned resources >> like IORESOURCE_MEM stay around, triggering WARN_ONs if the following >> driver requests those resources. >> >> o It is only available if CONFIG_FB is selected. >> >> This commit adds a new infrastructure that manages system-framebuffers >> (short: sysfb). The initial commit provides conflict-resolution for >> system-framebuffers. At its core it provides sysfb_evict_conflicts(), >> which implements conflict detection and removal for all known types of >> GFX driver hand-overs. So far, this includes platform-device removal, >> fbdev-firmware-device removal, vgacon removal and VBE detection. To >> further simplify the callers, it also provides helpers to figure out what >> hand-over to do, based on the device the new drivers binds to: >> >> o PCI drivers can use sysfb_evict_conflicts_pci(), which will figure >> out >> the apertures automatically, and does VGA/VBE detection. >> >> o Generic firmware drivers that might be shadowed at any address in >> memory can use sysfb_evict_conflicts_firmware(), basically removing >> *all* firmware framebuffers in effect. >> >> This only adds the generic sysfb helpers. No users are converted, yet. >> >> Signed-off-by: David Herrmann >> --- >> drivers/video/Kconfig | 4 + >> drivers/video/Makefile | 1 + >> drivers/video/sysfb.c | 327 >> +++++++++++++++++++++++++++++++++++++++++++++++++ >> include/linux/sysfb.h | 34 +++++ >> 4 files changed, 366 insertions(+) >> create mode 100644 drivers/video/sysfb.c >> create mode 100644 include/linux/sysfb.h >> >> diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig >> index 3c20af9..56a8294 100644 >> --- a/drivers/video/Kconfig >> +++ b/drivers/video/Kconfig >> @@ -36,6 +36,10 @@ config VIDEOMODE_HELPERS >> config HDMI >> bool >> +config SYSFB >> + bool >> + select DUMMY_CONSOLE if VT >> + >> if VT >> source "drivers/video/console/Kconfig" >> endif >> diff --git a/drivers/video/Makefile b/drivers/video/Makefile >> index 9ad3c17..df7bd75 100644 >> --- a/drivers/video/Makefile >> +++ b/drivers/video/Makefile >> @@ -1,5 +1,6 @@ >> obj-$(CONFIG_VGASTATE) += vgastate.o >> obj-$(CONFIG_HDMI) += hdmi.o >> +obj-$(CONFIG_SYSFB) += sysfb.o >> obj-$(CONFIG_VT) += console/ >> obj-$(CONFIG_LOGO) += logo/ >> diff --git a/drivers/video/sysfb.c b/drivers/video/sysfb.c >> new file mode 100644 >> index 0000000..00585c9 >> --- /dev/null >> +++ b/drivers/video/sysfb.c >> @@ -0,0 +1,327 @@ >> +/* >> + * Copyright (C) 2013-2016 Red Hat, Inc. >> + * >> + * This program is free software; you can redistribute it and/or modify >> it >> + * under the terms of the GNU Lesser General Public License as published >> by the >> + * Free Software Foundation; either version 2.1 of the License, or (at >> your >> + * option) any later version. >> + */ >> + >> +#define pr_fmt(fmt) "sysfb: " fmt >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> +#include >> + >> +static bool sysfb_evict_match_resource(struct sysfb_evict_ctx *ctx, >> + struct resource *mem) >> +{ >> + struct aperture *g; >> + unsigned int i; >> + >> + for (i = 0; i < ctx->ap->count; ++i) { >> + g = &ctx->ap->ranges[i]; >> + >> + if (mem->start == g->base) >> + return true; >> + if (mem->start >= g->base && mem->end < g->base + g->size) >> + return true; >> + if ((ctx->flags & SYSFB_EVICT_VBE) && mem->start == >> 0xA0000) >> + return true; >> + } >> + >> + return false; >> +} >> + >> +static int sysfb_evict_platform_device(struct device *dev, void >> *userdata) >> +{ >> + struct sysfb_evict_ctx *ctx = userdata; >> + struct platform_device *pdev = to_platform_device(dev); >> + struct resource *mem; >> + >> + if (!pdev->name) >> + return 0; >> + >> + if (!strcmp(pdev->name, "simple-framebuffer")) { > > > This doesn't work in my case where the device comes from DT and the name > also contains the address: pdev->name=1e887000.framebuffer > > This is one way of solving it: > > if (!pdev->dev.driver || !pdev->dev.driver->name) > return 0; > > if (!strcmp(pdev->dev.driver->name, "simple-framebuffer")) { Thanks for the hint, but this would skip devices that are not bound. How about the attached hunk? Thanks David diff --git a/drivers/video/sysfb.c b/drivers/video/sysfb.c index 0f039c6..a4ace3f 100644 --- a/drivers/video/sysfb.c +++ b/drivers/video/sysfb.c @@ -50,10 +50,8 @@ static int sysfb_evict_platform_device struct platform_device *pdev = to_platform_device(dev); struct resource *mem; - if (!pdev->name) - return 0; - - if (!strcmp(pdev->name, "simple-framebuffer")) { + if ((pdev->name && !strcmp(pdev->name, "simple-framebuffer")) || + of_device_is_compatible(pdev->dev.of_node, "simple-framebuffer")) { mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!mem) return 0;