From patchwork Tue Mar 26 17:55:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Noralf_Tr=C3=B8nnes?= X-Patchwork-Id: 10871861 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7AB4C922 for ; Tue, 26 Mar 2019 18:04:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 65CC128A71 for ; Tue, 26 Mar 2019 18:04:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5A29528C3D; Tue, 26 Mar 2019 18:04:43 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B5CCE28A71 for ; Tue, 26 Mar 2019 18:04:42 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0583589AAD; Tue, 26 Mar 2019 18:04:42 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from smtp.domeneshop.no (smtp.domeneshop.no [IPv6:2a01:5b40:0:3005::1]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5109D88D18; Tue, 26 Mar 2019 18:04:40 +0000 (UTC) Received: from 211.81-166-168.customer.lyse.net ([81.166.168.211]:46322 helo=localhost.localdomain) by smtp.domeneshop.no with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.84_2) (envelope-from ) id 1h8qIy-0006Mj-9O; Tue, 26 Mar 2019 18:56:08 +0100 From: =?utf-8?q?Noralf_Tr=C3=B8nnes?= To: dri-devel@lists.freedesktop.org Subject: [PATCH 15/16] drm/client: Hack: Add bootsplash example Date: Tue, 26 Mar 2019 18:55:45 +0100 Message-Id: <20190326175546.18126-16-noralf@tronnes.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190326175546.18126-1-noralf@tronnes.org> References: <20190326175546.18126-1-noralf@tronnes.org> MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tronnes.org; s=ds201810; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=WCaILc8La8OaVkYEFHcJJdHeo6lbsbgALm4B4/pLXxg=; b=GZa754AiqHIZSGZKwgWqiefEUfE67NCkb4Dw1QZL0OLIGgNZ9h+DtKAgD7XS+7pZwzbTOlZ7NAE9KmMwtX6cnH47072jUCI0OVE49Ibz/mayCO4yufnGIzW6GugX5uL9wZikr2A6Y0JtO5HBdtlpw3HxtqQZB5AYC8716LqwwMrWrX8uctDuZ/egvtRpdS9iv5uh0075JlEMHLbvFkFeBWcevrF/rPqhDtgz0Ie/lAZGeEN88yCO+hClqRJEeSkm7BqmTSJsS86Uvm28cMav5sR305ORSuN/q4IBx+klkyTbD4P8kt+mfR6haXXVx2eheE2YlKHgIoZynYdBGcukJQ==; X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: intel-gfx@lists.freedesktop.org, mstaudt@suse.de Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP An example to showcase the client API. TODO: A bootsplash client needs a way to tell drm_fb_helper to stay away, otherwise it will chime in on setup and hotplug. Most DRM drivers register fbdev before calling drm_dev_register() (the generic emulation is an exception). This have to be reversed for bootsplash to fend off fbdev. Signed-off-by: Noralf Trønnes --- drivers/gpu/drm/Kconfig | 5 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/drm_bootsplash.c | 216 +++++++++++++++++++++++++++++++ drivers/gpu/drm/drm_client.c | 7 + drivers/gpu/drm/drm_drv.c | 4 + include/drm/drm_client.h | 3 + 6 files changed, 236 insertions(+) create mode 100644 drivers/gpu/drm/drm_bootsplash.c diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig index 5e1bc630b885..a7019c54e2a2 100644 --- a/drivers/gpu/drm/Kconfig +++ b/drivers/gpu/drm/Kconfig @@ -65,6 +65,11 @@ config DRM_DEBUG_SELFTEST If in doubt, say "N". +config DRM_CLIENT_BOOTSPLASH + bool "DRM Bootsplash" + help + DRM Bootsplash + config DRM_KMS_HELPER tristate depends on DRM diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile index e630eccb951c..ac0573023842 100644 --- a/drivers/gpu/drm/Makefile +++ b/drivers/gpu/drm/Makefile @@ -32,6 +32,7 @@ drm-$(CONFIG_OF) += drm_of.o drm-$(CONFIG_AGP) += drm_agpsupport.o drm-$(CONFIG_DEBUG_FS) += drm_debugfs.o drm_debugfs_crc.o drm-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) += drm_edid_load.o +drm-$(CONFIG_DRM_CLIENT_BOOTSPLASH) += drm_bootsplash.o drm_kms_helper-y := drm_crtc_helper.o drm_dp_helper.o drm_dsc.o drm_probe_helper.o \ drm_plane_helper.o drm_dp_mst_topology.o drm_atomic_helper.o \ diff --git a/drivers/gpu/drm/drm_bootsplash.c b/drivers/gpu/drm/drm_bootsplash.c new file mode 100644 index 000000000000..fdc3349a2496 --- /dev/null +++ b/drivers/gpu/drm/drm_bootsplash.c @@ -0,0 +1,216 @@ +/* DRM internal client example */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +// drm_lastclose() +#include "drm_internal.h" + +static bool drm_bootsplash_enabled = true; +module_param_named(bootsplash_enabled, drm_bootsplash_enabled, bool, 0600); +MODULE_PARM_DESC(bootsplash_enabled, "Enable bootsplash client [default=true]"); + +struct drm_bootsplash { + struct drm_client_dev client; + struct mutex lock; + struct work_struct worker; + bool started; + bool stop; +}; + +static bool drm_bootsplash_key_pressed; + +static int drm_bootsplash_keyboard_notifier_call(struct notifier_block *blk, + unsigned long code, void *_param) +{ + /* Any key is good */ + drm_bootsplash_key_pressed = true; + + return NOTIFY_OK; +} + +static struct notifier_block drm_bootsplash_keyboard_notifier_block = { + .notifier_call = drm_bootsplash_keyboard_notifier_call, +}; + +static u32 drm_bootsplash_color_table[3] = { + 0x00ff0000, 0x0000ff00, 0x000000ff, +}; + +/* Draw a box with changing colors */ +static void drm_bootsplash_draw(struct drm_client_buffer *buffer, unsigned int sequence) +{ + unsigned int width = buffer->fb->width; + unsigned int height = buffer->fb->height; + unsigned int x, y; + u32 *pix; + + pix = buffer->vaddr; + pix += ((height / 2) - 50) * width; + pix += (width / 2) - 50; + + for (y = 0; y < 100; y++) { + for (x = 0; x < 100; x++) + *pix++ = drm_bootsplash_color_table[sequence]; + pix += width - 100; + } +} + +static void drm_bootsplash_worker(struct work_struct *work) +{ + struct drm_bootsplash *splash = container_of(work, struct drm_bootsplash, worker); + struct drm_client_dev *client = &splash->client; + struct drm_device *dev = client->dev; + struct drm_client_display *display; + unsigned int buffer_num = 0, sequence = 0, i; + bool stop; + int ret = 0; + + while (!drm_bootsplash_key_pressed) { + mutex_lock(&splash->lock); + stop = splash->stop; + mutex_unlock(&splash->lock); + if (stop) + break; + + buffer_num = !buffer_num; + + mutex_lock(&client->displaylist_mutex); + + ret = -ENOENT; + + i = 0; + drm_client_for_each_display(display, client) { + DRM_DEBUG_KMS("draw: i=%u, buffer_num=%u, sequence=%u\n", i++, buffer_num, sequence); + + drm_bootsplash_draw(display->buffers[buffer_num], sequence); + + ret = drm_client_display_commit_buffer(display, buffer_num); + if (ret == -EBUSY) + break; + + } + mutex_unlock(&client->displaylist_mutex); + + if (ret == -ENOENT || ret == -EBUSY) + break; + + if (++sequence == 3) + sequence = 0; + + msleep(500); + } + + /* Restore fbdev (or other) on key press. */ + /* TODO: Check if it's OK to call drm_lastclose here. */ + if (drm_bootsplash_key_pressed && !splash->stop) + drm_lastclose(dev); + + drm_client_release_displays(client); + + DRM_DEV_DEBUG_KMS(dev->dev, "Bootsplash has stopped (key=%u stop=%u, ret=%d).\n", + drm_bootsplash_key_pressed, splash->stop, ret); +} + +static int drm_bootsplash_client_hotplug(struct drm_client_dev *client) +{ + struct drm_bootsplash *splash = container_of(client, struct drm_bootsplash, client); + int ret; + + if (drm_bootsplash_key_pressed) + return 0; + + mutex_lock(&splash->lock); + + ret = drm_client_probe_displays(client, 2, DRM_FORMAT_XRGB8888); + if (!ret) + ret = -ENOENT; + if (ret < 0) + goto out_unlock; + + /* + * TODO: Deal with rotated panels, might have to sw rotate + if (drm_client_panel_rotation(...)) + */ + + if (!splash->started) { + splash->started = true; + schedule_work(&splash->worker); + } + +out_unlock: + mutex_unlock(&splash->lock); + + return ret; +} + +static void drm_bootsplash_client_unregister(struct drm_client_dev *client) +{ + struct drm_bootsplash *splash = container_of(client, struct drm_bootsplash, client); + + DRM_DEBUG_KMS("%s: IN\n", __func__); + + mutex_lock(&splash->lock); + splash->stop = true; + mutex_unlock(&splash->lock); + + flush_work(&splash->worker); + + drm_client_release(client); + kfree(splash); + + unregister_keyboard_notifier(&drm_bootsplash_keyboard_notifier_block); + + DRM_DEBUG_KMS("%s: OUT\n", __func__); +} + +static const struct drm_client_funcs drm_bootsplash_client_funcs = { + .owner = THIS_MODULE, + .unregister = drm_bootsplash_client_unregister, + .hotplug = drm_bootsplash_client_hotplug, +}; + +void drm_bootsplash_client_register(struct drm_device *dev) +{ + struct drm_bootsplash *splash; + int ret; + + if (!drm_bootsplash_enabled) + return; + + splash = kzalloc(sizeof(*splash), GFP_KERNEL); + if (!splash) + return; + + ret = drm_client_init(dev, &splash->client, "bootsplash", &drm_bootsplash_client_funcs); + if (ret) { + DRM_DEV_ERROR(dev->dev, "Failed to create client, ret=%d\n", ret); + kfree(splash); + return; + } + + /* For this simple example only allow the first */ + drm_bootsplash_enabled = false; + + mutex_init(&splash->lock); + + INIT_WORK(&splash->worker, drm_bootsplash_worker); + + drm_client_add(&splash->client); + + register_keyboard_notifier(&drm_bootsplash_keyboard_notifier_block); + + drm_bootsplash_client_hotplug(&splash->client); +} diff --git a/drivers/gpu/drm/drm_client.c b/drivers/gpu/drm/drm_client.c index ef01a31a9dbe..b7458fac0863 100644 --- a/drivers/gpu/drm/drm_client.c +++ b/drivers/gpu/drm/drm_client.c @@ -170,6 +170,13 @@ void drm_client_release(struct drm_client_dev *client) } EXPORT_SYMBOL(drm_client_release); +void drm_client_dev_register(struct drm_device *dev) +{ +#if CONFIG_DRM_CLIENT_BOOTSPLASH + drm_bootsplash_client_register(dev); +#endif +} + void drm_client_dev_unregister(struct drm_device *dev) { struct drm_client_dev *client, *tmp; diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c index 50d849d1bc6e..fbbb5f998baf 100644 --- a/drivers/gpu/drm/drm_drv.c +++ b/drivers/gpu/drm/drm_drv.c @@ -1018,6 +1018,10 @@ int drm_dev_register(struct drm_device *dev, unsigned long flags) drm_minor_unregister(dev, DRM_MINOR_RENDER); out_unlock: mutex_unlock(&drm_global_mutex); + + if (!ret) + drm_client_dev_register(dev); + return ret; } EXPORT_SYMBOL(drm_dev_register); diff --git a/include/drm/drm_client.h b/include/drm/drm_client.h index ef7a9bd07b3c..cabd3055ba8a 100644 --- a/include/drm/drm_client.h +++ b/include/drm/drm_client.h @@ -130,6 +130,7 @@ int drm_client_init(struct drm_device *dev, struct drm_client_dev *client, void drm_client_release(struct drm_client_dev *client); void drm_client_add(struct drm_client_dev *client); +void drm_client_dev_register(struct drm_device *dev); void drm_client_dev_unregister(struct drm_device *dev); void drm_client_dev_hotplug(struct drm_device *dev); void drm_client_dev_restore(struct drm_device *dev); @@ -251,4 +252,6 @@ int drm_client_display_commit_buffer(struct drm_client_display *display, unsigne int drm_client_debugfs_init(struct drm_minor *minor); +void drm_bootsplash_client_register(struct drm_device *dev); + #endif