Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2846417lqp; Mon, 25 Mar 2024 10:51:43 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU+iEcowazq2AvIUXdtI3KjPh1fVNAqnqVkTK/82hsey36oUdRsYwS/36RKJ8lISAtPqF5ZdDPESaN6XHS+S8G41NdwL6zzv2giNWJhoQ== X-Google-Smtp-Source: AGHT+IEKZhx1OZ1BVXXtKjejKBC7KqKtExwt5qb/EACbU21DRGvet/y4glXyHflDY301k+hP70FD X-Received: by 2002:a05:6a21:3297:b0:1a3:6a10:fa3e with SMTP id yt23-20020a056a21329700b001a36a10fa3emr7202651pzb.10.1711389102814; Mon, 25 Mar 2024 10:51:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711389102; cv=pass; d=google.com; s=arc-20160816; b=xsBbWw/LH7J8cHcEb0N+OJpmHVHbuXL3eOoNSwptxrSkpHQWRFUyQ0eN/1CchPUTQa p7Ep6d+vyybl9xKxEb/l0XcrdMJPBmHsJnWJOXb5xSbLEGxdHSgotQIKsfbm/qAf+JNp yJ/3SHDisbMCJUVCSr09r+Nrq1FLOkfM+28fri/o9ZbBcMyzzXUZVZifZB0ETUXPankP 0xGo74eosvJJhXvSpEXLpAu0qTrbk01q6ExrVWxd1bdiWI5plQVRJRURoLNi/O+qjqih eIrFDE54mENlfBSwnKP+aRJKjnhYGPCN+/9JvMuj8S1WLNXpS4rk599Q9DpdzQWYZcpm A2jQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=NmqQCwZDH4B3OlLrjyEOlYc7e4QIIPgGHiTR19jxo00=; fh=BZFsLFJthQ2hSwNDctFZiIc/5Er4lPc1VyQ1PSBYvI0=; b=bmM2sGUgHoHJsm5+926O8LiNaXwXgQ2S7VX4lw9YeYJQ2haguhc3mQ1ixp7kPuupDQ kMjZ6QY0xk/bQvp84T0viECv98kN8zhUhA22omQHKhhDmqVIS8NwD4GwdPmiLbTfZYCg JcvFhCJ6zBD64tNqxHWPhbI13bE+r4DPrfuB0tOkzGK6A2+MlPaUD6C/iZKitDDw8IZ4 azEmPh4omxUphv5E0o/Bn4t91uDJIywPqEFAqiJXd0PjY6D5fZfLKNRVJqQA3UMVylfP Edkhz/Bmylqf1gx4sklAdgUUt/H3v/pV7TDNLi8zHjF7dDyEHqNUxEOs/8xWUpci1o7p WgPA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@tuxedocomputers.com header.s=default header.b=AXiJ4fMh; arc=pass (i=1 spf=pass spfdomain=tuxedocomputers.com dkim=pass dkdomain=tuxedocomputers.com dmarc=pass fromdomain=tuxedocomputers.com); spf=pass (google.com: domain of linux-kernel+bounces-117509-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-117509-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=tuxedocomputers.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id u41-20020a056a0009a900b006eaa8f9b018si3167960pfg.241.2024.03.25.10.51.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 10:51:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-117509-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@tuxedocomputers.com header.s=default header.b=AXiJ4fMh; arc=pass (i=1 spf=pass spfdomain=tuxedocomputers.com dkim=pass dkdomain=tuxedocomputers.com dmarc=pass fromdomain=tuxedocomputers.com); spf=pass (google.com: domain of linux-kernel+bounces-117509-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-117509-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=tuxedocomputers.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id B7D18294A43 for ; Mon, 25 Mar 2024 17:43:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 063715C613; Mon, 25 Mar 2024 16:48:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=tuxedocomputers.com header.i=@tuxedocomputers.com header.b="AXiJ4fMh" Received: from mail.tuxedocomputers.com (mail.tuxedocomputers.com [157.90.84.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 24A1D12C7FF; Mon, 25 Mar 2024 16:48:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=157.90.84.7 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711385301; cv=none; b=lfcSMDyFKuyJjh2QByySQ1ZN8maiVLdTx6g7+zq/yuq2GdQlUWZ1yYDaqBzPJjFTEkup5r4Z+44WL/1gDt5FFVMHmwPLisRu1ShCaUj27tQuu6lWqatHv6UkMSJtjJBpHJSfaGrZ5ntWI2UyoI+tHFcp/CkShwjZbYTZ1cXHols= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711385301; c=relaxed/simple; bh=KL58tz4W1eeVJ5Z466IQZHdJakOeRAuqBdvV52pZkTM=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=AZj4OHzNJycrmh7Ywot1MbDDHY7Fva3GCpgBJKO7y3fMkivx+kB1MaSSrNOlTXyshNr3+Z7ziNeF/YlgMwnILZ2xdwoXmQm0VKMGKFc0ZesmnsxZWeCz6yKO/WB/5GokfDWf+pBxS+Gqec2JCiCtjqxqJjAof8HRYsyqr3No4dc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=tuxedocomputers.com; spf=pass smtp.mailfrom=tuxedocomputers.com; dkim=pass (1024-bit key) header.d=tuxedocomputers.com header.i=@tuxedocomputers.com header.b=AXiJ4fMh; arc=none smtp.client-ip=157.90.84.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=tuxedocomputers.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tuxedocomputers.com Received: from [192.168.42.20] (p5de453e6.dip0.t-ipconnect.de [93.228.83.230]) (Authenticated sender: wse@tuxedocomputers.com) by mail.tuxedocomputers.com (Postfix) with ESMTPSA id CD66C2FC005D; Mon, 25 Mar 2024 17:48:07 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxedocomputers.com; s=default; t=1711385289; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NmqQCwZDH4B3OlLrjyEOlYc7e4QIIPgGHiTR19jxo00=; b=AXiJ4fMhH2/ea0CIO4qIrQtdeP2H/daJj0oKmG4209NVgz+UnASp7zDmMsXgijLBATf/wk zMv/55JwfpkJ/ekaAFQGma2Dv1FFw0/wflPF8Hfg2oiKa5bHnVmcx5XIdzsnM4Z3MoFXjd X5fsB01ECUqGGwk19C1k5IUPTfq04Ug= Authentication-Results: mail.tuxedocomputers.com; auth=pass smtp.auth=wse@tuxedocomputers.com smtp.mailfrom=wse@tuxedocomputers.com Message-ID: <870cca8a-1a1b-4d17-874e-a26c30aca2bf@tuxedocomputers.com> Date: Mon, 25 Mar 2024 17:48:07 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: In kernel virtual HID devices (was Future handling of complex RGB devices on Linux v3) Content-Language: en-US To: Benjamin Tissoires , Hans de Goede Cc: Lee Jones , jikos@kernel.org, linux-kernel@vger.kernel.org, Jelle van der Waa , Miguel Ojeda , "dri-devel@lists.freedesktop.org" , linux-input@vger.kernel.org, ojeda@kernel.org, linux-leds@vger.kernel.org, Pavel Machek , Gregor Riepl References: <477d30ee-247e-47e6-bc74-515fd87fdc13@redhat.com> <247b5dcd-fda8-45a7-9896-eabc46568281@tuxedocomputers.com> <825129ea-d389-4c6c-8a23-39f05572e4b4@redhat.com> <1fb08a74-62c7-4d0c-ba5d-648e23082dcb@tuxedocomputers.com> From: Werner Sembach In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Hi Benjamin, Am 25.03.24 um 16:56 schrieb Benjamin Tissoires: > On Mar 25 2024, Hans de Goede wrote: >> +Cc: Bentiss, Jiri >> >> Hi Werner, >> >> On 3/20/24 12:16 PM, Werner Sembach wrote: >>> Hi Hans and the others, >>> >>> Am 22.02.24 um 14:14 schrieb Werner Sembach: >>>> Hi, >>>> >>>> Thanks everyone for the exhaustive feedback. And at least this thread is a good comprehesive reference for the future ^^. >>>> >>>> To recap the hopefully final UAPI for complex RGB lighting devices: >>>> >>>> - By default there is a singular /sys/class/leds/* entry that treats the device as if it was a single zone RGB keyboard backlight with no special effects. >>>> >>>> - There is an accompanying misc device with the sysfs attributes "name", "device_type",  "firmware_version_string", "serial_number" for device identification and "use_leds_uapi" that defaults to 1. >>>> >>>>     - If set to 0 the /sys/class/leds/* entry disappears. The driver should keep the last state the backlight was in active if possible. >>>> >>>>     - If set 1 it appears again. The driver should bring it back to a static 1 zone setting while avoiding flicker if possible. >>>> >>>> - If the device is not controllable by for example hidraw, the misc device might also implement additional ioctls or sysfs attributes to allow a more complex low level control for the keyboard backlight. This is will be a highly vendor specific UAPI. >>> So in the OpenRGB issue thread https://learn.microsoft.com/en-us/windows-hardware/design/component-guidelines/dynamic-lighting-devices aka HID LampArray was mentioned. I did dismiss it because I thought that is only relevant for firmware, but I now stumbled upon the Virtual HID Framework (VHF) https://learn.microsoft.com/en-us/windows-hardware/drivers/hid/virtual-hid-framework--vhf- and now I wonder if an equivalent exists for Linux? A quick search did not yield any results for me. >> Oh, interesting. I did not know about the HID LampArray API. >> >> About your question about virtual HID devices, there is uHID, >> but as the name suggests this allows userspace to emulate a HID >> device. >> >> In your case you want to do the emulation in kernel so that you >> can translate the proprietary WMI calls to something HID LampArray >> compatible. >> >> I guess you could do this by defining your own HID transport driver, >> like how e.g. the i2c-hid code defines 1 i2c-hid parent + 1 HID >> "client" for each device which talks HID over i2c in the machine. >> >> Bentiss, Jiri, do you have any input on this. Would something like >> that be acceptable to you (just based on the concept at least) ? > I just read the thread, and I think I now understand a little bit what > this request is :) > > IMO working with the HID LampArray is the way forward. So I would > suggest to convert any non-HID RGB "LED display" that we are talking > about as a HID LampArray device through `hid_allocate_device()` in the > kernel. Basically what you are suggesting Hans. It's just that you don't > need a formal transport layer, just a child device that happens to be > HID. > > The next question IMO is: do we want the kernel to handle such > machinery? Wouldn't it be simpler to just export the HID device and let > userspace talk to it through hidraw, like what OpenRGB does? That's already part of my plan: The kernels main goal is to give devices a LampArray interface that don't have one already (e.g. because they are no HID devices to begin with). The actual handling of LampArray will happen in userspace. Exception is that maybe it could be useful to implement a small subset of LampArray in a generic leds-subsystem driver for backwards compatibility to userspace applications that only implement that (e.g. UPower). It would treat the whole keyboard as a single led. > > If the kernel already handles the custom protocol into generic HID, the > work for userspace is not too hard because they can deal with a known > protocol and can be cross-platform in their implementation. > > I'm mentioning that cross-platform because SDL used to rely on the > input, LEDs, and other Linux peculiarities and eventually fell back on > using hidraw only because it's way more easier that way. > > The other advantage of LampArray is that according to Microsoft's > document, new devices are going to support it out of the box, so they'll > be supported out of the box directly. > > Most of the time my stance is "do not add new kernel API, you'll regret > it later". So in that case, given that we have a formally approved > standard, I would suggest to use it, and consider it your API. The only new UAPI would be the use_leds_uapi switch to turn on/off the backwards compatibility. The control flow for the whole system would look something like this: - System boots     - Kernel driver initializes keyboard (maybe stops rainbowpuke boot effects, sets brightness to a default value, or initializes a solid color)     - systemd-backlight restores last keyboard backlight brightness     - UPower sees sysfs leds entry and exposes it to DBus for DEs to do keyboard brightness handling - If the user wants more control they (auto-)start OpenRGB     - OpenRGB disables sysfs leds entry via use_leds_uapi to prevent double control of the same device by UPower     - OpenRGB directly interacts with hidraw device via LampArray API to give fine granular control of the backlight     - When OpenRGB closes it should reenable the sysfs leds entry - System shutdown     - Since OpenRGB reenables the sysfs leds entry, systemd-backlight can correctly store a brightness value for next boot Regards, Werner > > Side note to self: I really need to resurrect the hidraw revoke series > so we could export those hidraw node to userspace with uaccess through > logind... > > Cheers, > Benjamin