From patchwork Thu Apr 12 16:12:36 2018 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: 10339017 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 F1D5F602D8 for ; Thu, 12 Apr 2018 16:24:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DB9C326E74 for ; Thu, 12 Apr 2018 16:24:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D03A627165; Thu, 12 Apr 2018 16:24:02 +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 3AD9B26E74 for ; Thu, 12 Apr 2018 16:24:02 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E44D06EAA7; Thu, 12 Apr 2018 16:23:58 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@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 E5BCE6EAA7; Thu, 12 Apr 2018 16:23:56 +0000 (UTC) Received: from 211.81-166-168.customer.lyse.net ([81.166.168.211]:54390 helo=localhost.localdomain) by smtp.domeneshop.no with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_CBC_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1f6eqJ-0002mh-WB; Thu, 12 Apr 2018 18:13:00 +0200 From: =?UTF-8?q?Noralf=20Tr=C3=B8nnes?= To: dri-devel@lists.freedesktop.org Date: Thu, 12 Apr 2018 18:12:36 +0200 Message-Id: <20180412161237.9314-13-noralf@tronnes.org> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180412161237.9314-1-noralf@tronnes.org> References: <20180412161237.9314-1-noralf@tronnes.org> MIME-Version: 1.0 Subject: [Intel-gfx] [RFC v4 24/25] drm/client: Hack: Add bootsplash X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: daniel.vetter@ffwll.ch, intel-gfx@lists.freedesktop.org, =?UTF-8?q?Noralf=20Tr=C3=B8nnes?= , laurent.pinchart@ideasonboard.com, mstaudt@suse.de, dh.herrmann@gmail.com Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP A hack to test the client API. Signed-off-by: Noralf Trønnes --- drivers/gpu/drm/Kconfig | 2 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/client/Kconfig | 9 ++ drivers/gpu/drm/client/drm_bootsplash.c | 248 ++++++++++++++++++++++++++++++++ drivers/gpu/drm/client/internal.h | 19 +++ drivers/gpu/drm/drm_client.c | 4 + 6 files changed, 283 insertions(+) create mode 100644 drivers/gpu/drm/client/Kconfig create mode 100644 drivers/gpu/drm/client/drm_bootsplash.c create mode 100644 drivers/gpu/drm/client/internal.h diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig index 757825ac60df..1328202ce17d 100644 --- a/drivers/gpu/drm/Kconfig +++ b/drivers/gpu/drm/Kconfig @@ -154,6 +154,8 @@ config DRM_SCHED tristate depends on DRM +source "drivers/gpu/drm/client/Kconfig" + 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 d25afa136d8f..388527093f80 100644 --- a/drivers/gpu/drm/Makefile +++ b/drivers/gpu/drm/Makefile @@ -30,6 +30,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) += client/drm_bootsplash.o drm_kms_helper-y := drm_crtc_helper.o drm_dp_helper.o drm_probe_helper.o \ drm_plane_helper.o drm_dp_mst_topology.o drm_atomic_helper.o \ diff --git a/drivers/gpu/drm/client/Kconfig b/drivers/gpu/drm/client/Kconfig new file mode 100644 index 000000000000..6b01f2e51fb3 --- /dev/null +++ b/drivers/gpu/drm/client/Kconfig @@ -0,0 +1,9 @@ +menu "DRM Clients" + depends on DRM + +config DRM_CLIENT_BOOTSPLASH + bool "DRM Bootsplash" + help + DRM Bootsplash + +endmenu diff --git a/drivers/gpu/drm/client/drm_bootsplash.c b/drivers/gpu/drm/client/drm_bootsplash.c new file mode 100644 index 000000000000..bec3105f9b02 --- /dev/null +++ b/drivers/gpu/drm/client/drm_bootsplash.c @@ -0,0 +1,248 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +// drm_lastclose() +#include +#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 drm_client_display *display; + struct drm_client_buffer *buffer[2]; + struct work_struct worker; + 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 x, y; + u32 *pix; + + pix = buffer->vaddr; + pix += ((buffer->height / 2) - 50) * buffer->width; + pix += (buffer->width / 2) - 50; + + for (y = 0; y < 100; y++) { + for (x = 0; x < 100; x++) + *pix++ = drm_bootsplash_color_table[sequence]; + pix += buffer->width - 100; + } +} + +static void drm_bootsplash_worker(struct work_struct *work) +{ + struct drm_bootsplash *splash = container_of(work, struct drm_bootsplash, worker); + struct drm_device *dev = splash->client->dev; + unsigned int i = 0, sequence = 0; + struct drm_framebuffer *fb; + int ret = 0; + + while (!splash->stop && !drm_bootsplash_key_pressed) { + /* Did someone take over, like another in-kernel client, except fbdev? */ + fb = drm_client_display_current_fb(splash->display); + if (splash->buffer[i]->fb != fb && + !(dev->fb_helper && dev->fb_helper->fb == fb)) + break; + + i = !i; + drm_bootsplash_draw(splash->buffer[i], sequence++); + if (sequence == 3) + sequence = 0; + + ret = drm_client_display_commit(splash->display, splash->buffer[i]->fb, NULL); + /* Is userspace in charge or is the device unplugged? */ + if (ret == -EBUSY || ret == -ENODEV) + break; + + 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) + drm_lastclose(dev); + + for (i = 0; i < 2; i++) + drm_client_framebuffer_delete(splash->buffer[i]); + drm_client_display_free(splash->display); + drm_client_remove_defer(splash->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_setup(struct drm_bootsplash *splash) +{ + struct drm_client_dev *client = splash->client; + struct drm_client_buffer *buffer[2]; + struct drm_client_display *display; + int ret, i; + + display = drm_client_find_display(client->dev, 0, 0); + if (IS_ERR(display)) + return PTR_ERR(display); + if (!display) + return -ENOENT; + + if (WARN_ON(!display->mode)) + return -ENOENT; + + for (i = 0; i < 2; i++) { + buffer[i] = drm_client_framebuffer_create(client, display->mode, + DRM_FORMAT_XRGB8888); + if (IS_ERR(buffer[i])) { + ret = PTR_ERR(buffer[i]); + goto err_free_buffer; + } + } + + ret = drm_client_display_commit(display, buffer[0]->fb, display->mode); + if (ret) + goto err_free_buffer; + + splash->display = display; + splash->buffer[0] = buffer[0]; + splash->buffer[1] = buffer[1]; + + schedule_work(&splash->worker); + + return 0; + +err_free_buffer: + for (i--; i >= 0; i--) + drm_client_framebuffer_delete(buffer[i]); + drm_client_display_free(display); + + return ret; +} + +static int drm_bootsplash_client_hotplug(struct drm_client_dev *client) +{ + struct drm_bootsplash *splash = client->private; + int ret = 0; + + if (splash->display) + return 0; + + ret = drm_bootsplash_setup(splash); + if (ret) { + DRM_DEV_DEBUG_KMS(client->dev->dev, "ret=%d\n", ret); + return ret; + } + + return 0; +} + +static int drm_bootsplash_client_remove(struct drm_client_dev *client) +{ + struct drm_bootsplash *splash = client->private; + + /* Don't hook up to any new devices showing up */ + drm_bootsplash_enabled = false; + + splash->stop = true; + flush_work(&splash->worker); + kfree(splash); + + return 0; +} + +static const struct drm_client_funcs drm_bootsplash_client_funcs = { + .name = "bootsplash", + .remove = drm_bootsplash_client_remove, + .hotplug = drm_bootsplash_client_hotplug, +}; + +static int drm_bootsplash_dev_notify(struct notifier_block *nb, + unsigned long action, void *data) +{ + struct drm_device *dev = data; + struct drm_client_dev *client; + struct drm_bootsplash *splash; + + if (!drm_bootsplash_enabled) + return 0; + + splash = kzalloc(sizeof(*splash), GFP_KERNEL); + if (!splash) + return 0; + + client = drm_client_new(dev, &drm_bootsplash_client_funcs); + if (IS_ERR(client)) { + DRM_DEV_ERROR(dev->dev, "Failed to create client, ret=%ld\n", PTR_ERR(client)); + kfree(splash); + return 0; + } + + INIT_WORK(&splash->worker, drm_bootsplash_worker); + + splash->client = client; + client->private = splash; + + /* + * vc4 isn't done with it's setup when drm_dev_register() is called. + * It should have shouldn't it? + * So to keep it from crashing defer setup to hotplug... + */ + if (client->dev->mode_config.max_width) + drm_bootsplash_client_hotplug(client); + + return 0; +} + +static struct notifier_block drm_bootsplash_dev_notifier = { + .notifier_call = drm_bootsplash_dev_notify, +}; + +void drm_bootsplash_register(void) +{ + register_keyboard_notifier(&drm_bootsplash_keyboard_notifier_block); + + if (!drm_bootsplash_enabled) + return; + + drm_dev_register_notifier(&drm_bootsplash_dev_notifier); +} + +void drm_bootsplash_unregister(void) +{ + drm_dev_unregister_notifier(&drm_bootsplash_dev_notifier); + unregister_keyboard_notifier(&drm_bootsplash_keyboard_notifier_block); +} diff --git a/drivers/gpu/drm/client/internal.h b/drivers/gpu/drm/client/internal.h new file mode 100644 index 000000000000..22e2120c493b --- /dev/null +++ b/drivers/gpu/drm/client/internal.h @@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef _DRM_CLIENT_INTERNAL_H_ +#define _DRM_CLIENT_INTERNAL_H_ + +#ifdef CONFIG_DRM_CLIENT_BOOTSPLASH +void drm_bootsplash_register(void); +void drm_bootsplash_unregister(void); +#else +static inline void drm_bootsplash_register(void) +{ +} + +static inline void drm_bootsplash_unregister(void) +{ +} +#endif + +#endif diff --git a/drivers/gpu/drm/drm_client.c b/drivers/gpu/drm/drm_client.c index 760f1795f812..cd8c084c8801 100644 --- a/drivers/gpu/drm/drm_client.c +++ b/drivers/gpu/drm/drm_client.c @@ -24,6 +24,7 @@ #include "drm_crtc_internal.h" #include "drm_internal.h" +#include "client/internal.h" struct drm_client_display_offset { int x, y; @@ -234,10 +235,13 @@ EXPORT_SYMBOL(drm_client_remove_defer); void drm_client_init(void) { + drm_bootsplash_register(); } void drm_client_exit(void) { + drm_bootsplash_unregister(); + flush_work(&drm_client_remove_defer_work); }